@godgpt/core
v0.1.1
Published
Core utilities, event system, and SDK factory for GodGPT SDK
Readme
@godgpt/core
Core utilities, event system, and SDK factory for the GodGPT SDK.
Installation
npm install @godgpt/core
# or
pnpm add @godgpt/core
# or
yarn add @godgpt/coreUsage
Creating the SDK
import { createSDK } from "@godgpt/core";
const sdk = createSDK({
debug: true, // Enable debug logging
});
// Initialize the SDK
await sdk.init();Using Modules
import { createSDK, type Module, type SDKContext } from "@godgpt/core";
// Create a custom module
class MyModule implements Module {
readonly name = "myModule";
async init(context: SDKContext): Promise<void> {
console.log("Module initialized!");
}
async destroy(): Promise<void> {
console.log("Module destroyed!");
}
doSomething(): void {
console.log("Doing something...");
}
}
const sdk = createSDK();
const myModule = sdk.use(new MyModule());
await sdk.init();
myModule.doSomething();Event System
// Subscribe to events
const unsubscribe = sdk.on("sdk:ready", () => {
console.log("SDK is ready!");
});
// Emit custom events
sdk.emit("custom:event", { data: "value" });
// Unsubscribe
unsubscribe();Storage
// Store data
await sdk.storage.set("key", { foo: "bar" });
// Retrieve data
const data = await sdk.storage.get<{ foo: string }>("key");
// Remove data
await sdk.storage.remove("key");API Reference
createSDK(config?)
Creates a new SDK instance.
Options:
debug(boolean): Enable debug loggingstorage(StorageAdapter): Custom storage adapter
SDK Methods
init(): Initialize the SDK and all registered modulesdestroy(): Destroy the SDK and all modulesuse(module): Register a moduleget(name): Get a registered module by namehas(name): Check if a module is registeredon(event, callback): Subscribe to an eventoff(event, callback): Unsubscribe from an eventemit(event, ...args): Emit an event
License
MIT
