@meetopenbot/plugin-sdk 0.1.6 → 0.1.7

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 CHANGED
@@ -26,21 +26,25 @@ OpenBot plugins operate as the **agent runtime** on an event-driven architecture
26
26
  A plugin is defined by the `Plugin` or `PluginModule` interface. Use `definePlugin` to get full OpenBot typing.
27
27
 
28
28
  ```typescript
29
- import { definePlugin } from '@meetopenbot/plugin-sdk';
29
+ import { definePlugin } from "@meetopenbot/plugin-sdk";
30
30
 
31
31
  export default definePlugin({
32
- id: 'my-agent',
33
- name: 'My Agent',
34
- description: 'A custom AI agent',
32
+ id: "my-agent",
33
+ name: "My Agent",
34
+ description: "A custom AI agent",
35
35
  configSchema: {
36
- type: 'object',
36
+ type: "object",
37
37
  properties: {
38
- apiKey: { type: 'string', description: 'Your API Key', format: 'password' },
38
+ apiKey: {
39
+ type: "string",
40
+ description: "Your API Key",
41
+ format: "password",
42
+ },
39
43
  },
40
- required: ['apiKey'],
44
+ required: ["apiKey"],
41
45
  },
42
46
  factory: (context) => (builder) => {
43
- builder.on('agent:invoke', async function* (event) {
47
+ builder.on("agent:invoke", async function* (event) {
44
48
  // Handle agent logic here
45
49
  });
46
50
  },
@@ -57,6 +61,81 @@ Plugins communicate via an event bus. Core events include:
57
61
  - `client:ui:widget:response`: Dispatched when a user interacts with a widget (e.g., submits a form or clicks a choice).
58
62
  - `action:<toolName>`: Dispatched when a tool call is requested.
59
63
  - `action:<toolName>:result`: Emitted when a tool handler finishes. Must include `data.output: string` to be fed back to the model.
64
+ - `action:webhook`: Dispatched when a third-party provider POSTs to `/api/webhooks/:provider`.
65
+ - `action:webhook:http-response`: Yield from a webhook handler to control the HTTP response (challenges, acks, errors).
66
+
67
+ ### Inbound webhooks
68
+
69
+ The OpenBot host exposes `POST /api/webhooks/:provider` for third-party integrations (Slack, Linear, GitHub, etc.). The route is intentionally thin: it forwards the request onto the event bus and lets **existing plugins** handle verification, transforms, and HTTP responses.
70
+
71
+ **Host behavior:**
72
+
73
+ 1. Preserves the **raw request body** (base64 in the event) for HMAC signature checks.
74
+ 2. Dispatches `action:webhook` to the `system` agent on the `uncategorized` channel.
75
+ 3. **Awaits** the plugin run and uses the first `action:webhook:http-response` yield as the HTTP reply (defaults to `200 {}`).
76
+ 4. Fans out subsequent events (`agent:invoke`, etc.) over SSE like `/api/publish`.
77
+
78
+ **Plugin responsibilities:**
79
+
80
+ - Filter on `event.data.provider` (matches the `:provider` URL segment).
81
+ - Verify signatures using `event.data.headers` and `decodeWebhookRawBody(event)`.
82
+ - Yield `webhookHttpResponse(...)` for URL challenges, 401s, or custom acks.
83
+ - Transform into normal bus events (typically `agent:invoke`).
84
+
85
+ ```typescript
86
+ import {
87
+ definePlugin,
88
+ decodeWebhookRawBody,
89
+ getWebhookHeader,
90
+ webhookHttpResponse,
91
+ type WebhookEvent,
92
+ } from "@meetopenbot/plugin-sdk";
93
+
94
+ export default definePlugin({
95
+ name: "Slack",
96
+ description: "Inbound Slack Events API webhooks",
97
+ configSchema: {
98
+ type: "object",
99
+ properties: {
100
+ signingSecret: {
101
+ type: "string",
102
+ description: "Slack signing secret",
103
+ format: "password",
104
+ },
105
+ },
106
+ required: ["signingSecret"],
107
+ },
108
+ factory:
109
+ ({ config }) =>
110
+ (builder) => {
111
+ builder.on("action:webhook", async function* (event) {
112
+ const webhook = event as WebhookEvent;
113
+ if (webhook.data.provider !== "slack") return;
114
+
115
+ const rawBody = decodeWebhookRawBody(webhook);
116
+ const payload = JSON.parse(rawBody.toString("utf8"));
117
+
118
+ if (payload.type === "url_verification") {
119
+ yield webhookHttpResponse({
120
+ status: 200,
121
+ body: { challenge: payload.challenge },
122
+ });
123
+ return;
124
+ }
125
+
126
+ // verify signature, then ack + transform...
127
+ yield webhookHttpResponse({ status: 200, body: {} });
128
+ yield {
129
+ type: "agent:invoke",
130
+ data: { role: "user", content: payload.event?.text ?? "" },
131
+ meta: { threadId: payload.event?.thread_ts ?? payload.event?.ts },
132
+ };
133
+ });
134
+ },
135
+ });
136
+ ```
137
+
138
+ Register the plugin on your webhook agent (usually `system`) in `AGENT.md`, then point the provider at `https://<host>/api/webhooks/slack`.
60
139
 
61
140
  ### Output and Communication
62
141
 
@@ -96,18 +175,22 @@ Plugins can render interactive UI widgets using the `uiWidget` helper and handle
96
175
  This agent responds to any message with "Hello, World!".
97
176
 
98
177
  ```typescript
99
- import { definePlugin, shouldHandleInvoke, agentOutput } from '@meetopenbot/plugin-sdk';
178
+ import {
179
+ definePlugin,
180
+ shouldHandleInvoke,
181
+ agentOutput,
182
+ } from "@meetopenbot/plugin-sdk";
100
183
 
101
184
  export default definePlugin({
102
- id: 'hello-world',
103
- name: 'Hello World',
104
- description: 'Responds with Hello World',
185
+ id: "hello-world",
186
+ name: "Hello World",
187
+ description: "Responds with Hello World",
105
188
  factory: (context) => (builder) => {
106
- builder.on('agent:invoke', async function* (event) {
189
+ builder.on("agent:invoke", async function* (event) {
107
190
  if (shouldHandleInvoke(event, context.agentId)) {
108
191
  yield agentOutput({
109
192
  agentId: context.agentId,
110
- content: 'Hello, World!',
193
+ content: "Hello, World!",
111
194
  threadId: event.meta?.threadId,
112
195
  });
113
196
  }
@@ -122,7 +205,7 @@ export default definePlugin({
122
205
  - [Events & State](./src/events.ts)
123
206
  - [Storage Interface](./src/storage.ts)
124
207
  - [UI Widget Specs](./src/ui.ts)
125
- - [Helpers](./src/helpers.ts)
208
+ - [Helpers](./src/helpers.ts) (`decodeWebhookRawBody`, `getWebhookHeader`, `webhookHttpResponse`)
126
209
 
127
210
  ## License
128
211
 
package/dist/events.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { AgentDetails, ChannelDetails, ThreadDetails } from './storage.js';
2
- import type { RenderUIWidgetData } from './ui.js';
1
+ import type { AgentDetails, ChannelDetails, ThreadDetails } from "./storage.js";
2
+ import type { RenderUIWidgetData } from "./ui.js";
3
3
  export type EventMeta = {
4
4
  agentId?: string;
5
5
  threadId?: string;
@@ -12,15 +12,15 @@ export type BaseEvent = {
12
12
  meta?: EventMeta;
13
13
  };
14
14
  export type AgentInvokeEvent = BaseEvent & {
15
- type: 'agent:invoke';
15
+ type: "agent:invoke";
16
16
  data: {
17
- role?: 'user' | 'assistant' | 'system';
17
+ role?: "user" | "assistant" | "system";
18
18
  content: string;
19
19
  agentId?: string;
20
20
  };
21
21
  };
22
22
  export type AgentOutputEvent = BaseEvent & {
23
- type: 'agent:output';
23
+ type: "agent:output";
24
24
  data: {
25
25
  content: string;
26
26
  };
@@ -29,14 +29,14 @@ export type AgentOutputEvent = BaseEvent & {
29
29
  };
30
30
  };
31
31
  export type UIWidgetEvent = BaseEvent & {
32
- type: 'client:ui:widget';
32
+ type: "client:ui:widget";
33
33
  data: RenderUIWidgetData;
34
34
  meta: EventMeta & {
35
35
  agentId: string;
36
36
  };
37
37
  };
38
38
  export type UIWidgetResponseEvent = BaseEvent & {
39
- type: 'client:ui:widget:response';
39
+ type: "client:ui:widget:response";
40
40
  data: {
41
41
  widgetId: string;
42
42
  actionId: string;
@@ -56,26 +56,49 @@ export type ToolResultEvent<TData = unknown> = BaseEvent & {
56
56
  data: TData;
57
57
  meta?: EventMeta;
58
58
  };
59
+ /** Inbound third-party webhook forwarded from `POST /api/webhooks/:provider`. */
60
+ export type WebhookEvent = BaseEvent & {
61
+ type: "action:webhook";
62
+ data: {
63
+ provider: string;
64
+ /** Request body encoded as base64 so plugins can verify HMACs on the raw bytes. */
65
+ rawBody: string;
66
+ headers: Record<string, string | string[] | undefined>;
67
+ query: Record<string, unknown>;
68
+ };
69
+ };
70
+ /**
71
+ * Yield this from a webhook handler to control the HTTP response
72
+ * (URL challenges, signature failures, provider-specific acks).
73
+ */
74
+ export type WebhookHttpResponseEvent = BaseEvent & {
75
+ type: "action:webhook:http-response";
76
+ data: {
77
+ status: number;
78
+ body?: unknown;
79
+ headers?: Record<string, string>;
80
+ };
81
+ };
59
82
  /**
60
83
  * Narrow event union for common plugin authoring paths.
61
84
  * The host bus accepts additional event types at runtime.
62
85
  */
63
- export type PluginEvent = AgentInvokeEvent | AgentOutputEvent | UIWidgetEvent | UIWidgetResponseEvent | ToolActionEvent | ToolResultEvent;
86
+ export type PluginEvent = AgentInvokeEvent | AgentOutputEvent | UIWidgetEvent | UIWidgetResponseEvent | ToolActionEvent | ToolResultEvent | WebhookEvent | WebhookHttpResponseEvent;
64
87
  export type OpenBotEvent = PluginEvent | (BaseEvent & {
65
88
  data?: unknown;
66
89
  });
67
90
  export type ShortTermMessage = {
68
- role: 'system';
91
+ role: "system";
69
92
  content: string;
70
93
  } | {
71
- role: 'user';
94
+ role: "user";
72
95
  content: string;
73
96
  } | {
74
- role: 'assistant';
97
+ role: "assistant";
75
98
  content: string;
76
99
  toolCalls?: unknown[];
77
100
  } | {
78
- role: 'tool';
101
+ role: "tool";
79
102
  content: string;
80
103
  toolCallId: string;
81
104
  toolName: string;
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,KAAK,EAAE,kBAAkB,EAAgB,MAAM,SAAS,CAAC;AAEhE,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG;IACzC,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE;QACJ,IAA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,eAAe,GACf,eAAe,GACf,YAAY,GACZ,wBAAwB,CAAC;AAE7B,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,CAAC,SAAS,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAE1E,MAAM,MAAM,gBAAgB,GACxB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5E,0DAA0D;AAC1D,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;CACxC"}
package/dist/helpers.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { AgentInvokeEvent, AgentOutputEvent, EventMeta, ToolResultEvent, UIWidgetEvent } from './events.js';
2
- import type { RenderUIWidgetData } from './ui.js';
1
+ import type { AgentInvokeEvent, AgentOutputEvent, EventMeta, ToolResultEvent, UIWidgetEvent, WebhookEvent, WebhookHttpResponseEvent } from "./events.js";
2
+ import type { RenderUIWidgetData } from "./ui.js";
3
3
  /** Return true when this agent should handle an `agent:invoke` event. */
4
4
  export declare function shouldHandleInvoke(event: AgentInvokeEvent, agentId: string): boolean;
5
5
  /** Build an `agent:output` event. */
@@ -28,4 +28,14 @@ export declare function withMeta<T extends {
28
28
  }, event: T): T & {
29
29
  meta?: EventMeta;
30
30
  };
31
+ /** Decode `action:webhook` raw body bytes from base64. */
32
+ export declare function decodeWebhookRawBody(event: WebhookEvent): Buffer;
33
+ /** Read a single header value from a webhook event (case-insensitive). */
34
+ export declare function getWebhookHeader(event: WebhookEvent, name: string): string | undefined;
35
+ /** Build an `action:webhook:http-response` event for the host HTTP reply. */
36
+ export declare function webhookHttpResponse(args: {
37
+ status: number;
38
+ body?: unknown;
39
+ headers?: Record<string, string>;
40
+ }): WebhookHttpResponseEvent;
31
41
  //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,eAAe,EACf,aAAa,EACd,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,kBAAkB,EAAG,MAAM,SAAS,CAAC;AAEnD,yEAAyE;AACzE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAGpF;AAED,qCAAqC;AACrC,wBAAgB,WAAW,CAAC,IAAI,EAAE;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB,GAAG,gBAAgB,CAUnB;AAED,+EAA+E;AAC/E,wBAAgB,UAAU,CAAC,KAAK,EAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE;IAAE,IAAI,CAAC,EAAE,SAAS,CAAA;CAAE,EAC7B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B,IAAI,EAAE,KAAK,GACV,eAAe,CAAC,KAAK,CAAC,CAMxB;AAED,wCAAwC;AACxC,wBAAgB,QAAQ,CAAC,IAAI,EAAE;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB,GAAG,aAAa,CAUhB;AAED,oEAAoE;AACpE,wBAAgB,QAAQ,CAAC,CAAC,SAAS;IAAE,IAAI,CAAC,EAAE,SAAS,CAAA;CAAE,EACrD,MAAM,EAAE;IAAE,IAAI,CAAC,EAAE,SAAS,CAAA;CAAE,EAC5B,KAAK,EAAE,CAAC,GACP,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,SAAS,CAAA;CAAE,CAS1B;AAED,0DAA0D;AAC1D,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAEhE;AAED,0EAA0E;AAC1E,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,SAAS,CAKpB;AAED,6EAA6E;AAC7E,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,GAAG,wBAAwB,CAK3B"}
package/dist/helpers.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /** Return true when this agent should handle an `agent:invoke` event. */
2
2
  export function shouldHandleInvoke(event, agentId) {
3
3
  const routedTo = event.data?.agentId;
4
- return !(typeof routedTo === 'string' && routedTo && routedTo !== agentId);
4
+ return !(typeof routedTo === "string" && routedTo && routedTo !== agentId);
5
5
  }
6
6
  /** Build an `agent:output` event. */
7
7
  export function agentOutput(args) {
8
8
  return {
9
- type: 'agent:output',
9
+ type: "agent:output",
10
10
  data: { content: args.content },
11
11
  meta: {
12
12
  ...(args.meta ?? {}),
@@ -26,7 +26,7 @@ export function toolResult(toolName, request, data) {
26
26
  /** Build a `client:ui:widget` event. */
27
27
  export function uiWidget(args) {
28
28
  return {
29
- type: 'client:ui:widget',
29
+ type: "client:ui:widget",
30
30
  data: args.widget,
31
31
  meta: {
32
32
  ...(args.meta ?? {}),
@@ -47,4 +47,23 @@ export function withMeta(source, event) {
47
47
  },
48
48
  };
49
49
  }
50
+ /** Decode `action:webhook` raw body bytes from base64. */
51
+ export function decodeWebhookRawBody(event) {
52
+ return Buffer.from(event.data.rawBody, "base64");
53
+ }
54
+ /** Read a single header value from a webhook event (case-insensitive). */
55
+ export function getWebhookHeader(event, name) {
56
+ const headers = event.data.headers;
57
+ const direct = headers[name] ?? headers[name.toLowerCase()];
58
+ if (Array.isArray(direct))
59
+ return direct[0];
60
+ return typeof direct === "string" ? direct : undefined;
61
+ }
62
+ /** Build an `action:webhook:http-response` event for the host HTTP reply. */
63
+ export function webhookHttpResponse(args) {
64
+ return {
65
+ type: "action:webhook:http-response",
66
+ data: args,
67
+ };
68
+ }
50
69
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AASA,yEAAyE;AACzE,MAAM,UAAU,kBAAkB,CAAC,KAAuB,EAAE,OAAe;IACzE,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC;IACrC,OAAO,CAAC,CAAC,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,IAAI,QAAQ,KAAK,OAAO,CAAC,CAAC;AAC7E,CAAC;AAED,qCAAqC;AACrC,MAAM,UAAU,WAAW,CAAC,IAK3B;IACC,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QAC/B,IAAI,EAAE;YACJ,GA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,CACtB,MAA4B,EAC5B,KAAQ;IAER,IAAI,CAAC,MAAM,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC;IAC/B,OAAO;QACL,GAAG,KAAK;QACR,IAAI,EAAE;YACJ,GAAG,MAAM,CAAC,IAAI;YACd,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;SACtB;KACF,CAAC;AACJ,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,oBAAoB,CAAC,KAAmB;IACtD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACnD,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,gBAAgB,CAC9B,KAAmB,EACnB,IAAY;IAEZ,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;IACnC,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC5D,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;IAC5C,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACzD,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,mBAAmB,CAAC,IAInC;IACC,OAAO;QACL,IAAI,EAAE,8BAA8B;QACpC,IAAI,EAAE,IAAI;KACX,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetopenbot/plugin-sdk",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Types and helpers for building OpenBot plugins on the event bus.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",