@meetopenbot/plugin-sdk 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,52 +10,56 @@ npm install @meetopenbot/plugin-sdk
|
|
|
10
10
|
|
|
11
11
|
## How it Works
|
|
12
12
|
|
|
13
|
-
OpenBot plugins operate on an event-driven architecture powered by [Melony](https://github.com/meetopenbot/melony).
|
|
13
|
+
OpenBot plugins operate on an event-driven architecture powered by [Melony](https://github.com/meetopenbot/melony). Plugin authors work with the OpenBot SDK types and helpers; you do not need to import Melony types in your plugin code.
|
|
14
14
|
|
|
15
|
-
1.
|
|
16
|
-
2.
|
|
17
|
-
3.
|
|
18
|
-
4.
|
|
15
|
+
1. **Registration**: The host loads your plugin and calls the `factory` function with a `PluginContext`.
|
|
16
|
+
2. **Subscription**: Your `factory` function uses the `PluginBuilder` to subscribe to specific events (for example, `agent:invoke`).
|
|
17
|
+
3. **Processing**: When an event occurs, your handler is called. You can perform logic, interact with `storage`, or call external APIs.
|
|
18
|
+
4. **Publication**: Your handler can emit new events back to the bus (for example, `agent:output` or `client:ui:widget`) to communicate with the user or other plugins.
|
|
19
19
|
|
|
20
20
|
## Core Concepts
|
|
21
21
|
|
|
22
22
|
### Plugin
|
|
23
23
|
|
|
24
|
-
A plugin is defined by the `Plugin` interface.
|
|
24
|
+
A plugin is defined by the `Plugin` or `PluginModule` interface. Use `definePlugin` to get full OpenBot typing without annotating Melony types yourself.
|
|
25
25
|
|
|
26
26
|
```typescript
|
|
27
|
-
import {
|
|
27
|
+
import { definePlugin } from '@meetopenbot/plugin-sdk';
|
|
28
28
|
|
|
29
|
-
export
|
|
29
|
+
export default definePlugin({
|
|
30
30
|
id: 'my-plugin',
|
|
31
31
|
name: 'My Plugin',
|
|
32
32
|
description: 'A simple example plugin',
|
|
33
33
|
configSchema: {
|
|
34
34
|
type: 'object',
|
|
35
35
|
properties: {
|
|
36
|
-
apiKey: { type: 'string', description: 'Your API Key', format: 'password' }
|
|
36
|
+
apiKey: { type: 'string', description: 'Your API Key', format: 'password' },
|
|
37
37
|
},
|
|
38
|
-
required: ['apiKey']
|
|
38
|
+
required: ['apiKey'],
|
|
39
39
|
},
|
|
40
40
|
toolDefinitions: {
|
|
41
|
-
|
|
41
|
+
get_weather: {
|
|
42
42
|
description: 'Get the current weather',
|
|
43
43
|
inputSchema: {
|
|
44
44
|
type: 'object',
|
|
45
45
|
properties: {
|
|
46
|
-
location: { type: 'string' }
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
46
|
+
location: { type: 'string' },
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
50
|
},
|
|
51
|
-
factory: (context
|
|
52
|
-
|
|
51
|
+
factory: (context) => (builder) => {
|
|
52
|
+
builder.on('agent:invoke', async function* (event) {
|
|
53
53
|
// Handle events here
|
|
54
|
-
};
|
|
54
|
+
});
|
|
55
55
|
},
|
|
56
|
-
};
|
|
56
|
+
});
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
For community plugins published as npm packages, omit `id` and export a `PluginModule`. The host assigns `id` from the package name.
|
|
60
|
+
|
|
61
|
+
You can also type a plugin object explicitly with `Plugin` or `PluginModule` if you prefer. The `factory` function returns a `PluginFactory`, which registers handlers on the `PluginBuilder` and receives `PluginHandlerContext` in event handlers.
|
|
62
|
+
|
|
59
63
|
### Configuration & Tools
|
|
60
64
|
|
|
61
65
|
- **`configSchema`**: Defines the configuration options for your plugin. The host uses this to validate the configuration provided in `AGENT.md`.
|
|
@@ -95,29 +99,30 @@ Plugins can render interactive UI widgets using the `uiWidget` helper. Supported
|
|
|
95
99
|
This plugin responds to any message with "Hello, World!".
|
|
96
100
|
|
|
97
101
|
```typescript
|
|
98
|
-
import {
|
|
102
|
+
import { definePlugin, shouldHandleInvoke, agentOutput } from '@meetopenbot/plugin-sdk';
|
|
99
103
|
|
|
100
|
-
export
|
|
104
|
+
export default definePlugin({
|
|
101
105
|
id: 'hello-world',
|
|
102
106
|
name: 'Hello World',
|
|
103
107
|
description: 'Responds with Hello World',
|
|
104
108
|
factory: (context) => (builder) => {
|
|
105
|
-
builder.on('agent:invoke', async (event
|
|
109
|
+
builder.on('agent:invoke', async function* (event) {
|
|
106
110
|
if (shouldHandleInvoke(event, context.agentId)) {
|
|
107
|
-
|
|
111
|
+
yield agentOutput({
|
|
108
112
|
agentId: context.agentId,
|
|
109
113
|
content: 'Hello, World!',
|
|
110
114
|
threadId: event.meta?.threadId,
|
|
111
|
-
})
|
|
115
|
+
});
|
|
112
116
|
}
|
|
113
117
|
});
|
|
114
118
|
},
|
|
115
|
-
};
|
|
119
|
+
});
|
|
116
120
|
```
|
|
117
121
|
|
|
118
122
|
## API Reference
|
|
119
123
|
|
|
120
124
|
- [Plugin & Context](./src/plugin.ts)
|
|
125
|
+
- [Runtime Types](./src/runtime.ts)
|
|
121
126
|
- [Events & State](./src/events.ts)
|
|
122
127
|
- [Storage Interface](./src/storage.ts)
|
|
123
128
|
- [UI Widget Specs](./src/ui.ts)
|