-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.ts
More file actions
65 lines (58 loc) · 1.88 KB
/
plugin.ts
File metadata and controls
65 lines (58 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import type { AgentDetails } from './storage.js';
import type { Storage } from './storage.js';
import type { PluginFactory } from './runtime.js';
/** Plugin reference from AGENT.md frontmatter. */
export interface PluginRef {
id: string;
config?: Record<string, unknown>;
}
/** JSON-schema-like description of per-plugin config in AGENT.md. */
export type ConfigSchema = {
type: 'object';
properties: {
[key: string]: {
type: 'string' | 'number' | 'boolean' | 'integer';
description?: string;
default?: unknown;
enum?: unknown[];
minimum?: number;
maximum?: number;
format?: 'password' | 'url' | 'email';
};
};
required?: string[];
};
/** Tool metadata merged across plugins and exposed to runtime plugins. */
export interface ToolDefinition {
description: string;
inputSchema: unknown;
}
/** Context passed to `factory` when the host wires a plugin onto the bus. */
export interface PluginContext {
agentId: string;
agentDetails: AgentDetails;
config: Record<string, unknown>;
storage: Storage;
tools: Record<string, ToolDefinition>;
}
/**
* Plugin contract expected by the OpenBot host.
* Roles (runtime, tool, middleware) are defined by which events `factory` handles.
*/
export interface Plugin {
id: string;
name: string;
description: string;
image?: string;
configSchema?: ConfigSchema;
toolDefinitions?: Record<string, ToolDefinition>;
factory: (context: PluginContext) => PluginFactory;
}
/** Community plugin module export. The host assigns `id` from the npm package name. */
export type PluginModule = Omit<Plugin, 'id'>;
/** Define a plugin with full OpenBot typing. */
export function definePlugin<T extends PluginModule>(definition: T): T;
export function definePlugin<T extends Plugin>(definition: T): T;
export function definePlugin<T extends Plugin | PluginModule>(definition: T): T {
return definition;
}