@meetopenbot/openbot 0.1.7 → 0.1.8

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.
@@ -1,3 +1,3 @@
1
- import type { Plugin } from '../types.js';
1
+ import type { Plugin } from "../types.js";
2
2
  export declare const delegationPlugin: Plugin;
3
3
  export default delegationPlugin;
@@ -1,5 +1,5 @@
1
- import { randomUUID } from 'node:crypto';
2
- import { z } from 'zod';
1
+ import { randomUUID } from "node:crypto";
2
+ import { z } from "zod";
3
3
  /**
4
4
  * `delegation` — allows agents to delegate tasks to other agents.
5
5
  *
@@ -9,29 +9,33 @@ import { z } from 'zod';
9
9
  */
10
10
  const delegationToolDefinitions = {
11
11
  delegate_task: {
12
- description: 'Delegate a specific task or question to another specialized agent.',
12
+ description: "Delegate a specific task or question to another specialized agent.",
13
13
  inputSchema: z.object({
14
- agentId: z.string().describe('The ID of the agent to delegate to (e.g., "researcher", "coder").'),
15
- prompt: z.string().describe('The instructions or question for the delegated agent.'),
14
+ agentId: z
15
+ .string()
16
+ .describe('The ID of the agent to delegate to (e.g., "researcher", "coder").'),
17
+ prompt: z
18
+ .string()
19
+ .describe("The instructions or question for the delegated agent."),
16
20
  }),
17
21
  },
18
22
  };
19
23
  export const delegationPlugin = {
20
- id: 'delegation',
21
- name: 'Delegation',
22
- description: 'Allows agents to call upon other agents to solve sub-tasks.',
24
+ id: "delegation",
25
+ name: "Delegation",
26
+ description: "Allows agents to call upon other agents to solve sub-tasks.",
23
27
  toolDefinitions: delegationToolDefinitions,
24
28
  factory: (pluginContext) => (builder) => {
25
29
  // Handle the tool execution
26
- builder.on('action:delegate_task', async function* (event, context) {
30
+ builder.on("action:delegate_task", async function* (event, context) {
27
31
  const delegateEvent = event;
28
32
  // POLICY: Only the 'system' agent can delegate
29
33
  if (context.state.agentId !== pluginContext.host.orchestratorAgentId) {
30
34
  yield {
31
- type: 'action:delegate_task:result',
35
+ type: "action:delegate_task:result",
32
36
  data: {
33
37
  success: false,
34
- error: 'Only the system agent can delegate.'
38
+ error: "Only the system agent can delegate.",
35
39
  },
36
40
  meta: delegateEvent.meta,
37
41
  };
@@ -43,7 +47,7 @@ export const delegationPlugin = {
43
47
  return;
44
48
  const runAgent = pluginContext.host.runAgent;
45
49
  const runId = `dg_${randomUUID()}`;
46
- let lastAgentOutput = '';
50
+ let lastAgentOutput = "";
47
51
  // Queue to bridge the async onEvent callback to this generator
48
52
  const eventQueue = [];
49
53
  let resolveNext = null;
@@ -54,20 +58,19 @@ export const delegationPlugin = {
54
58
  runId,
55
59
  agentId,
56
60
  event: {
57
- type: 'agent:invoke',
61
+ type: "agent:invoke",
58
62
  data: {
59
- role: 'user',
63
+ role: "user",
60
64
  content: prompt,
61
65
  agentId: agentId,
62
66
  },
63
67
  meta: {
68
+ channelId: context.state.channelId,
64
69
  threadId: context.state.threadId,
65
70
  parentAgentId: context.state.agentId,
66
71
  parentToolCallId: toolCallId,
67
72
  },
68
73
  },
69
- channelId: context.state.channelId,
70
- threadId: context.state.threadId,
71
74
  publicBaseUrl: pluginContext.publicBaseUrl,
72
75
  // Child events are re-yielded to the parent harness, which persists them once.
73
76
  persistEvents: false,
@@ -79,10 +82,10 @@ export const delegationPlugin = {
79
82
  ...outEvent.meta,
80
83
  parentAgentId: context.state.agentId,
81
84
  parentToolCallId: toolCallId,
82
- }
85
+ },
83
86
  };
84
87
  eventQueue.push(enrichedEvent);
85
- if (outEvent.type === 'agent:output') {
88
+ if (outEvent.type === "agent:output") {
86
89
  lastAgentOutput = outEvent.data.content;
87
90
  }
88
91
  // Wake up the generator loop if it's waiting
@@ -90,10 +93,12 @@ export const delegationPlugin = {
90
93
  resolveNext();
91
94
  resolveNext = null;
92
95
  }
93
- }
94
- }).catch(error => {
96
+ },
97
+ })
98
+ .catch((error) => {
95
99
  console.error(`[delegation] Error in delegated run ${runId}:`, error);
96
- }).finally(() => {
100
+ })
101
+ .finally(() => {
97
102
  isFinished = true;
98
103
  if (resolveNext) {
99
104
  resolveNext();
@@ -103,7 +108,9 @@ export const delegationPlugin = {
103
108
  // Yield events from the delegated agent as they arrive
104
109
  while (!isFinished || eventQueue.length > 0) {
105
110
  if (eventQueue.length === 0) {
106
- await new Promise(r => { resolveNext = r; });
111
+ await new Promise((r) => {
112
+ resolveNext = r;
113
+ });
107
114
  }
108
115
  while (eventQueue.length > 0) {
109
116
  yield eventQueue.shift();
@@ -113,7 +120,7 @@ export const delegationPlugin = {
113
120
  await runPromise;
114
121
  // Yield the result back to our own LLM runtime.
115
122
  yield {
116
- type: 'action:delegate_task:result',
123
+ type: "action:delegate_task:result",
117
124
  data: {
118
125
  success: true,
119
126
  output: lastAgentOutput,
package/dist/types.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- import type { Plugin as SdkPlugin, PluginContext as SdkPluginContext, OpenBotState as SdkOpenBotState, ToolActionEvent, PluginFactory as SdkPluginFactory, PluginBuilder, PluginHandlerContext, OpenBotEvent } from '@meetopenbot/plugin-sdk';
2
- export { definePlugin } from '@meetopenbot/plugin-sdk';
3
- export type { AgentInvokeEvent, AgentOutputEvent, ConfigSchema, OpenBotEvent, PluginBuilder, PluginFactory, PluginHandlerContext, Storage, ToolDefinition, ToolActionEvent, UIWidgetListItem, UIWidgetResponseEvent, } from '@meetopenbot/plugin-sdk';
4
- export type MemoryScopeAlias = 'global' | 'agent' | 'channel';
1
+ import type { Plugin as SdkPlugin, PluginContext as SdkPluginContext, OpenBotState as SdkOpenBotState, ToolActionEvent, PluginFactory as SdkPluginFactory, PluginBuilder, PluginHandlerContext, OpenBotEvent } from "@meetopenbot/plugin-sdk";
2
+ export { definePlugin } from "@meetopenbot/plugin-sdk";
3
+ export type { AgentInvokeEvent, AgentOutputEvent, ConfigSchema, OpenBotEvent, PluginBuilder, PluginFactory, PluginHandlerContext, Storage, ToolDefinition, ToolActionEvent, UIWidgetListItem, UIWidgetResponseEvent, } from "@meetopenbot/plugin-sdk";
4
+ export type MemoryScopeAlias = "global" | "agent" | "channel";
5
5
  export type DelegateTaskEvent = ToolActionEvent<{
6
6
  agentId: string;
7
7
  prompt: string;
8
8
  }> & {
9
- type: 'action:delegate_task';
9
+ type: "action:delegate_task";
10
10
  };
11
11
  export type RenderWidgetEvent = ToolActionEvent<Record<string, unknown>> & {
12
- type: 'action:render_widget';
12
+ type: "action:render_widget";
13
13
  };
14
14
  /** Runtime state extends the SDK with fields used by the OpenBot agent plugin. */
15
15
  export type OpenBotState = SdkOpenBotState & {
@@ -18,7 +18,7 @@ export type OpenBotState = SdkOpenBotState & {
18
18
  userName?: string;
19
19
  };
20
20
  pendingToolCallIds?: string[];
21
- threadDetails?: SdkOpenBotState['threadDetails'] & {
21
+ threadDetails?: SdkOpenBotState["threadDetails"] & {
22
22
  name?: string;
23
23
  };
24
24
  };
@@ -32,25 +32,24 @@ export type ActionBuilder = {
32
32
  };
33
33
  export declare function asActionBuilder(builder: PluginBuilder): ActionBuilder;
34
34
  export interface PluginHost {
35
+ /** Run context (channelId, threadId) is passed on `event.meta`, not as top-level options. */
35
36
  runAgent: (options: {
36
37
  runId: string;
37
38
  agentId: string;
38
39
  event: OpenBotEvent;
39
- channelId: string;
40
- threadId?: string;
41
40
  persistEvents?: boolean;
42
41
  publicBaseUrl?: string;
43
42
  onEvent: (event: OpenBotEvent, state?: OpenBotState) => Promise<void>;
44
43
  }) => Promise<void>;
45
44
  isCloudSystemAgent: (agentId: string) => boolean;
46
45
  isCloudMode: () => boolean;
47
- parseOpenbotAuthMode: (value: unknown) => 'credits' | 'byok';
46
+ parseOpenbotAuthMode: (value: unknown) => "credits" | "byok";
48
47
  saveConfig: (patch: Record<string, unknown>) => void;
49
48
  getBaseDir: () => string;
50
49
  resolvePath: (p: string) => string;
51
50
  orchestratorAgentId: string;
52
51
  openbotPluginId: string;
53
- defaultCloudAuthMode: 'credits' | 'byok';
52
+ defaultCloudAuthMode: "credits" | "byok";
54
53
  }
55
54
  /** Host context extends the SDK with OpenBot runtime wiring. */
56
55
  export interface PluginContext extends SdkPluginContext {
@@ -58,8 +57,8 @@ export interface PluginContext extends SdkPluginContext {
58
57
  abortSignal?: AbortSignal;
59
58
  host: PluginHost;
60
59
  }
61
- export interface Plugin extends Omit<SdkPlugin, 'factory' | 'configSchema'> {
62
- configSchema?: SdkPlugin['configSchema'] | Record<string, unknown>;
60
+ export interface Plugin extends Omit<SdkPlugin, "factory" | "configSchema"> {
61
+ configSchema?: SdkPlugin["configSchema"] | Record<string, unknown>;
63
62
  factory: (context: PluginContext) => SdkPluginFactory;
64
63
  }
65
64
  /** Type-safe plugin definition for the extended OpenBot host context. */
package/dist/types.js CHANGED
@@ -1,4 +1,4 @@
1
- export { definePlugin } from '@meetopenbot/plugin-sdk';
1
+ export { definePlugin } from "@meetopenbot/plugin-sdk";
2
2
  export function asActionBuilder(builder) {
3
3
  return {
4
4
  on(action, handler) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetopenbot/openbot",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Monolithic OpenBot agent runtime with batteries-included tools.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",