# Plugin Architecture

This directory contains a flexible plugin architecture that allows for both platform-specific and platform-agnostic plugins. The goal is to maintain type safety while promoting code reuse across different platforms.

## Core Components

### Plugin Interfaces

- **BasePluginContext**: The foundation for all plugin contexts, includes logging and configuration.
- **IPluginClient**: A minimal client interface that all platforms should implement.
- **IPluginStateManager**: A minimal state manager interface for plugin operations.
- **GenericPluginContext**: Context for platform-agnostic plugins.
- **PluginContext**: Context specifically for HCS10-based plugins.

### Plugin Implementations

- **BasePlugin**: Abstract base class that implements the core plugin functionality.
- **GenericPlugin**: For platform-agnostic plugins that work across implementations.
- **HCS10Plugin**: For plugins that require HCS10-specific functionality.

## Creating Plugins

### Generic Plugin Example

Generic plugins can be used across different platforms as long as the platform implements the required interfaces:

```typescript
import { GenericPlugin } from '../src/plugins/GenericPlugin';
import { GenericPluginContext } from '../src/plugins/PluginInterface';
import { StructuredTool } from '@langchain/core/tools';
import { DynamicStructuredTool } from '@langchain/core/tools';
import { z } from 'zod';

export class MyGenericPlugin extends GenericPlugin {
  id = 'my-generic-plugin';
  name = 'My Plugin';
  description = 'A cross-platform plugin';
  version = '1.0.0';
  author = 'Your Name';
 
  async initialize(context: GenericPluginContext): Promise<void> {
    await super.initialize(context);
    // Your initialization code
  }

  getTools(): StructuredTool[] {
    return [
      new DynamicStructuredTool({
        name: 'my_tool',
        description: 'Does something useful',
        schema: z.object({
          param: z.string().describe('Parameter description'),
        }),
        func: async ({ param }: { param: string }): Promise<string> => {
          // Tool implementation
          return `Result: ${param}, Network: ${this.context.client.getNetwork()}`;
        },
      }),
    ];
  }
}
```

### HCS10-Specific Plugin Example

For plugins that need the full HCS10 functionality:

```typescript
import { HCS10Plugin } from '../src/plugins/HCS10Plugin';
import { PluginContext } from '../src/plugins/PluginInterface';
import { DynamicStructuredTool } from '@langchain/core/tools';
import { z } from 'zod';

export class MyHCS10Plugin extends HCS10Plugin {
  id = 'my-hcs10-plugin';
  name = 'HCS10 Plugin';
  description = 'An HCS10-specific plugin';
  version = '1.0.0';
  author = 'Your Name';
 
  async initialize(context: PluginContext): Promise<void> {
    await super.initialize(context);
    // Your HCS10-specific initialization
  }

  getTools(): StructuredTool[] {
    return [
      new DynamicStructuredTool({
        name: 'hcs10_specific_tool',
        description: 'Uses HCS10-specific functionality',
        schema: z.object({
          param: z.string().describe('Parameter description'),
        }),
        func: async ({ param }: { param: string }): Promise<string> => {
          // HCS10-specific implementation
          return `HCS10 Result for ${param}`;
        },
      }),
    ];
  }
}
```

## Using in Different Platforms

To integrate this plugin system with other platforms:

1. Implement the `IPluginClient` interface in your platform's client
2. Optionally implement `IPluginStateManager` for state management
3. Create a context factory that provides the appropriate context type
4. Load plugins using the same loading mechanism

This architecture allows reusing generic plugins across platforms while maintaining the ability to create platform-specific plugins when needed.