open-index/open-npm huggingface dataset:
npm package: @godgpt/core
Description: Core utilities, event system, and SDK factory for GodGPT SDK
Author: GodGPT
Latest version: 0.1.1

# @godgpt/core

Core utilities, event system, and SDK factory for the GodGPT SDK.

## Installation

```bash
npm install @godgpt/core
# or
pnpm add @godgpt/core
# or
yarn add @godgpt/core
```

## Usage

### Creating the SDK

```typescript
import { createSDK } from "@godgpt/core";

const sdk = createSDK({
  debug: true, // Enable debug logging
});

// Initialize the SDK
await sdk.init();
```

### Using Modules

```typescript
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

```typescript
// 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

```typescript
// 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 logging
- `storage` (StorageAdapter): Custom storage adapter

### SDK Methods

- `init()`: Initialize the SDK and all registered modules
- `destroy()`: Destroy the SDK and all modules
- `use(module)`: Register a module
- `get(name)`: Get a registered module by name
- `has(name)`: Check if a module is registered
- `on(event, callback)`: Subscribe to an event
- `off(event, callback)`: Unsubscribe from an event
- `emit(event, ...args)`: Emit an event

## License

MIT