openbot 0.3.5 → 0.4.0
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 +15 -16
- package/dist/app/agent-ids.js +4 -0
- package/dist/app/cli.js +1 -1
- package/dist/app/config.js +0 -19
- package/dist/app/server.js +8 -14
- package/dist/assets/icon.svg +9 -3
- package/dist/bus/services.js +78 -132
- package/dist/harness/agent-invoke-run.js +44 -0
- package/dist/harness/agent-turn.js +99 -0
- package/dist/harness/channel-participants.js +40 -0
- package/dist/harness/constants.js +2 -0
- package/dist/harness/context-meter.js +97 -0
- package/dist/harness/context.js +98 -45
- package/dist/harness/dispatch.js +144 -0
- package/dist/harness/dispatcher.js +45 -156
- package/dist/harness/history.js +177 -0
- package/dist/harness/index.js +91 -0
- package/dist/harness/orchestration.js +88 -0
- package/dist/harness/participants.js +22 -0
- package/dist/harness/run-harness.js +154 -0
- package/dist/harness/run.js +98 -0
- package/dist/harness/runtime-factory.js +0 -34
- package/dist/harness/runtime.js +57 -0
- package/dist/harness/todo-dispatch.js +51 -0
- package/dist/harness/todos.js +5 -0
- package/dist/harness/turn.js +79 -0
- package/dist/plugins/approval/index.js +105 -149
- package/dist/plugins/delegation/index.js +119 -32
- package/dist/plugins/memory/index.js +103 -14
- package/dist/plugins/memory/service.js +152 -0
- package/dist/plugins/openbot/context.js +80 -0
- package/dist/plugins/openbot/history.js +98 -0
- package/dist/plugins/openbot/index.js +31 -0
- package/dist/plugins/openbot/runtime.js +317 -0
- package/dist/plugins/openbot/system-prompt.js +5 -0
- package/dist/plugins/plugin-manager/index.js +105 -0
- package/dist/plugins/storage/index.js +573 -0
- package/dist/plugins/storage/service.js +1159 -0
- package/dist/plugins/storage-tools/index.js +2 -2
- package/dist/plugins/thread-namer/index.js +72 -0
- package/dist/plugins/thread-naming/generate-title.js +44 -0
- package/dist/plugins/thread-naming/index.js +103 -0
- package/dist/plugins/threads/index.js +114 -0
- package/dist/plugins/todo/index.js +24 -25
- package/dist/plugins/ui/index.js +2 -32
- package/dist/registry/plugins.js +3 -9
- package/dist/services/plugins/domain.js +1 -0
- package/dist/services/plugins/plugin-cache.js +9 -0
- package/dist/services/plugins/registry.js +110 -0
- package/dist/services/plugins/service.js +177 -0
- package/dist/services/plugins/types.js +1 -0
- package/dist/services/process.js +29 -0
- package/dist/services/storage.js +41 -15
- package/dist/services/thread-naming.js +81 -0
- package/docs/agents.md +16 -10
- package/docs/architecture.md +2 -2
- package/docs/plugins.md +6 -15
- package/docs/templates/AGENT.example.md +7 -13
- package/package.json +1 -2
- package/src/app/agent-ids.ts +5 -0
- package/src/app/cli.ts +1 -1
- package/src/app/config.ts +1 -31
- package/src/app/server.ts +8 -16
- package/src/app/types.ts +70 -190
- package/src/assets/icon.svg +9 -3
- package/src/harness/index.ts +145 -0
- package/src/plugins/approval/index.ts +91 -189
- package/src/plugins/delegation/index.ts +136 -39
- package/src/plugins/memory/index.ts +112 -15
- package/src/{services/memory.ts → plugins/memory/service.ts} +1 -1
- package/src/plugins/openbot/context.ts +91 -0
- package/src/plugins/openbot/history.ts +107 -0
- package/src/plugins/openbot/index.ts +37 -0
- package/src/plugins/openbot/runtime.ts +384 -0
- package/src/plugins/openbot/system-prompt.ts +7 -0
- package/src/plugins/plugin-manager/index.ts +122 -0
- package/src/plugins/shell/index.ts +1 -1
- package/src/plugins/storage/index.ts +633 -0
- package/src/{services/storage.ts → plugins/storage/service.ts} +257 -72
- package/src/{bus/types.ts → services/plugins/domain.ts} +20 -7
- package/src/services/plugins/plugin-cache.ts +13 -0
- package/src/{registry/plugins.ts → services/plugins/registry.ts} +25 -27
- package/src/services/{plugins.ts → plugins/service.ts} +96 -2
- package/src/{bus/plugin.ts → services/plugins/types.ts} +3 -3
- package/src/bus/services.ts +0 -908
- package/src/harness/context.ts +0 -356
- package/src/harness/dispatcher.ts +0 -379
- package/src/harness/mcp.ts +0 -78
- package/src/harness/runtime-factory.ts +0 -129
- package/src/harness/todo-advance.ts +0 -128
- package/src/plugins/ai-sdk/index.ts +0 -41
- package/src/plugins/ai-sdk/runtime.ts +0 -468
- package/src/plugins/ai-sdk/system-prompt.ts +0 -18
- package/src/plugins/mcp/index.ts +0 -128
- package/src/plugins/storage-tools/index.ts +0 -90
- package/src/plugins/todo/index.ts +0 -64
- package/src/plugins/ui/index.ts +0 -227
- /package/src/{harness → services}/process.ts +0 -0
package/src/app/server.ts
CHANGED
|
@@ -10,10 +10,9 @@ const pkg = require('../../package.json');
|
|
|
10
10
|
import { generateId } from 'melony';
|
|
11
11
|
import { DEFAULT_BASE_DIR, loadConfig, resolvePath } from '../app/config.js';
|
|
12
12
|
import { ActiveRunsSnapshotEvent, OpenBotEvent, OpenBotState } from './types.js';
|
|
13
|
-
import { processService } from '../
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { initPlugins } from '../registry/plugins.js';
|
|
13
|
+
import { processService } from '../services/process.js';
|
|
14
|
+
import { runAgent, STATE_AGENT_ID, ORCHESTRATOR_AGENT_ID } from '../harness/index.js';
|
|
15
|
+
import { initPlugins } from '../services/plugins/registry.js';
|
|
17
16
|
import { ensureEventId, openBotEventFromQuery } from './utils.js';
|
|
18
17
|
|
|
19
18
|
type Bucket = { channelId: string; threadId?: string; activeCount: number; agentIds: Set<string> };
|
|
@@ -212,8 +211,6 @@ export async function startServer(options: ServerOptions = {}) {
|
|
|
212
211
|
}
|
|
213
212
|
|
|
214
213
|
const onEvent = async (chunk: OpenBotEvent, state?: OpenBotState) => {
|
|
215
|
-
ensureEventId(chunk);
|
|
216
|
-
|
|
217
214
|
const targetChannelId = state?.channelId || channelId;
|
|
218
215
|
const targetThreadId = state?.threadId || threadId;
|
|
219
216
|
const targetClientKey = getClientKey(targetChannelId, targetThreadId);
|
|
@@ -234,12 +231,6 @@ export async function startServer(options: ServerOptions = {}) {
|
|
|
234
231
|
);
|
|
235
232
|
}
|
|
236
233
|
|
|
237
|
-
await storageService.storeEvent({
|
|
238
|
-
channelId: targetChannelId,
|
|
239
|
-
threadId: targetThreadId,
|
|
240
|
-
event: chunk,
|
|
241
|
-
});
|
|
242
|
-
|
|
243
234
|
sendToClientKey(targetClientKey, chunk);
|
|
244
235
|
|
|
245
236
|
if (
|
|
@@ -254,9 +245,9 @@ export async function startServer(options: ServerOptions = {}) {
|
|
|
254
245
|
try {
|
|
255
246
|
ensureEventId(event);
|
|
256
247
|
|
|
257
|
-
await
|
|
248
|
+
await runAgent({
|
|
258
249
|
runId,
|
|
259
|
-
agentId: agentId ||
|
|
250
|
+
agentId: agentId || ORCHESTRATOR_AGENT_ID,
|
|
260
251
|
event,
|
|
261
252
|
channelId,
|
|
262
253
|
threadId,
|
|
@@ -295,12 +286,13 @@ export async function startServer(options: ServerOptions = {}) {
|
|
|
295
286
|
try {
|
|
296
287
|
ensureEventId(event);
|
|
297
288
|
|
|
298
|
-
await
|
|
289
|
+
await runAgent({
|
|
299
290
|
runId,
|
|
300
|
-
agentId: agentId ||
|
|
291
|
+
agentId: agentId || STATE_AGENT_ID,
|
|
301
292
|
event,
|
|
302
293
|
channelId,
|
|
303
294
|
threadId,
|
|
295
|
+
persistEvents: false,
|
|
304
296
|
onEvent,
|
|
305
297
|
});
|
|
306
298
|
res.json({ events });
|
package/src/app/types.ts
CHANGED
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
PluginDescriptor,
|
|
7
7
|
Thread,
|
|
8
8
|
ThreadDetails,
|
|
9
|
-
} from '../
|
|
10
|
-
import type { PluginRef } from '../
|
|
11
|
-
import type { MemoryRecord } from '../
|
|
9
|
+
} from '../services/plugins/domain.js';
|
|
10
|
+
import type { PluginRef } from '../services/plugins/types.js';
|
|
11
|
+
import type { MemoryRecord } from '../plugins/memory/service.js';
|
|
12
12
|
|
|
13
13
|
export interface OpenBotState {
|
|
14
14
|
agentId: string;
|
|
@@ -19,15 +19,10 @@ export interface OpenBotState {
|
|
|
19
19
|
channelDetails?: ChannelDetails;
|
|
20
20
|
threadDetails?: ThreadDetails;
|
|
21
21
|
triggerEvent?: OpenBotEvent;
|
|
22
|
-
|
|
22
|
+
/** Active model string (e.g. `openai/gpt-4o-mini`). */
|
|
23
|
+
model?: string;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
export type ShortTermMessage =
|
|
26
|
-
| { role: 'system'; content: string }
|
|
27
|
-
| { role: 'user'; content: string }
|
|
28
|
-
| { role: 'assistant'; content: string; toolCalls?: any[] }
|
|
29
|
-
| { role: 'tool'; content: string; toolCallId: string; toolName: string };
|
|
30
|
-
|
|
31
26
|
export type BaseEvent = {
|
|
32
27
|
id?: string;
|
|
33
28
|
type: string;
|
|
@@ -144,6 +139,7 @@ export type CreateAgentEvent = BaseEvent & {
|
|
|
144
139
|
name: string;
|
|
145
140
|
description?: string;
|
|
146
141
|
image?: string;
|
|
142
|
+
hidden?: boolean;
|
|
147
143
|
instructions: string;
|
|
148
144
|
plugins: PluginRef[];
|
|
149
145
|
};
|
|
@@ -164,6 +160,7 @@ export type UpdateAgentEvent = BaseEvent & {
|
|
|
164
160
|
name?: string;
|
|
165
161
|
description?: string;
|
|
166
162
|
image?: string;
|
|
163
|
+
hidden?: boolean;
|
|
167
164
|
instructions?: string;
|
|
168
165
|
plugins?: PluginRef[];
|
|
169
166
|
};
|
|
@@ -277,6 +274,8 @@ export type PatchChannelDetailsEvent = BaseEvent & {
|
|
|
277
274
|
state?: Record<string, unknown>;
|
|
278
275
|
spec?: string;
|
|
279
276
|
cwd?: string;
|
|
277
|
+
/** When set, replaces `state.json` `participants` (merged after `state` if both are sent). */
|
|
278
|
+
participants?: string[];
|
|
280
279
|
};
|
|
281
280
|
};
|
|
282
281
|
|
|
@@ -284,7 +283,7 @@ export type PatchChannelDetailsResultEvent = BaseEvent & {
|
|
|
284
283
|
type: 'action:patch_channel_details:result';
|
|
285
284
|
data: {
|
|
286
285
|
success: boolean;
|
|
287
|
-
updatedFields: ('state' | 'spec' | 'cwd')[];
|
|
286
|
+
updatedFields: ('state' | 'spec' | 'cwd' | 'participants')[];
|
|
288
287
|
};
|
|
289
288
|
};
|
|
290
289
|
|
|
@@ -441,6 +440,8 @@ export type CreateChannelEvent = BaseEvent & {
|
|
|
441
440
|
spec?: string;
|
|
442
441
|
initialState?: Record<string, unknown>;
|
|
443
442
|
cwd?: string;
|
|
443
|
+
/** Initial channel agent ids; written into `state.json` (overrides `initialState.participants` if both are set). */
|
|
444
|
+
participants?: string[];
|
|
444
445
|
};
|
|
445
446
|
meta?: {
|
|
446
447
|
toolCallId?: string;
|
|
@@ -464,6 +465,8 @@ export type UpdateChannelEvent = BaseEvent & {
|
|
|
464
465
|
channelId?: string;
|
|
465
466
|
name?: string;
|
|
466
467
|
cwd?: string;
|
|
468
|
+
/** Replaces the channel participant list when provided. */
|
|
469
|
+
participants?: string[];
|
|
467
470
|
};
|
|
468
471
|
};
|
|
469
472
|
|
|
@@ -503,12 +506,26 @@ export type UIWidgetListItem = {
|
|
|
503
506
|
metadata?: Record<string, unknown>;
|
|
504
507
|
};
|
|
505
508
|
|
|
509
|
+
export type UIMediaItem = {
|
|
510
|
+
type: 'image' | 'video' | 'audio' | 'file';
|
|
511
|
+
url: string;
|
|
512
|
+
title?: string;
|
|
513
|
+
alt?: string;
|
|
514
|
+
thumbnailUrl?: string;
|
|
515
|
+
metadata?: Record<string, unknown>;
|
|
516
|
+
};
|
|
517
|
+
|
|
506
518
|
export type UIWidgetBase = {
|
|
507
519
|
widgetId: string;
|
|
508
520
|
title?: string;
|
|
509
521
|
description?: string;
|
|
510
|
-
|
|
522
|
+
/** Optional hero media for the widget */
|
|
523
|
+
media?: UIMediaItem;
|
|
524
|
+
/** Optional actions for the widget */
|
|
525
|
+
actions?: UIWidgetAction[];
|
|
511
526
|
state?: 'open' | 'submitted' | 'cancelled' | 'error';
|
|
527
|
+
display?: 'expanded' | 'collapsed';
|
|
528
|
+
size?: 'small' | 'medium' | 'large' | 'full';
|
|
512
529
|
metadata?: Record<string, unknown>;
|
|
513
530
|
};
|
|
514
531
|
|
|
@@ -537,19 +554,6 @@ export type UIListWidget = UIWidgetBase & {
|
|
|
537
554
|
|
|
538
555
|
export type UIWidgetSpec = UIMessageWidget | UIChoiceWidget | UIFormWidget | UIListWidget;
|
|
539
556
|
|
|
540
|
-
export type RenderUIWidgetData =
|
|
541
|
-
| (Omit<UIMessageWidget, 'widgetId'> & { widgetId?: string })
|
|
542
|
-
| (Omit<UIChoiceWidget, 'widgetId'> & { widgetId?: string })
|
|
543
|
-
| (Omit<UIFormWidget, 'widgetId'> & { widgetId?: string })
|
|
544
|
-
| (Omit<UIListWidget, 'widgetId'> & { widgetId?: string })
|
|
545
|
-
| {
|
|
546
|
-
kind: 'approval' | 'todo_list';
|
|
547
|
-
widgetId?: string;
|
|
548
|
-
title?: string;
|
|
549
|
-
props?: Record<string, unknown>;
|
|
550
|
-
metadata?: Record<string, unknown>;
|
|
551
|
-
};
|
|
552
|
-
|
|
553
557
|
export type UIWidgetEvent = BaseEvent & {
|
|
554
558
|
type: 'client:ui:widget';
|
|
555
559
|
data: UIWidgetSpec;
|
|
@@ -559,11 +563,6 @@ export type UIWidgetEvent = BaseEvent & {
|
|
|
559
563
|
};
|
|
560
564
|
};
|
|
561
565
|
|
|
562
|
-
export type RenderUIWidgetEvent = BaseEvent & {
|
|
563
|
-
type: 'action:render_ui_widget';
|
|
564
|
-
data: RenderUIWidgetData;
|
|
565
|
-
};
|
|
566
|
-
|
|
567
566
|
export type UIWidgetResponseEvent = BaseEvent & {
|
|
568
567
|
type: 'client:ui:widget:response';
|
|
569
568
|
data: {
|
|
@@ -574,80 +573,6 @@ export type UIWidgetResponseEvent = BaseEvent & {
|
|
|
574
573
|
};
|
|
575
574
|
};
|
|
576
575
|
|
|
577
|
-
export type HandoffEvent = BaseEvent & {
|
|
578
|
-
type: 'action:handoff';
|
|
579
|
-
data: {
|
|
580
|
-
agentId: string;
|
|
581
|
-
content: string;
|
|
582
|
-
};
|
|
583
|
-
meta?: {
|
|
584
|
-
toolCallId?: string;
|
|
585
|
-
[key: string]: any;
|
|
586
|
-
};
|
|
587
|
-
};
|
|
588
|
-
|
|
589
|
-
export type HandoffResultEvent = BaseEvent & {
|
|
590
|
-
type: 'action:handoff:result';
|
|
591
|
-
data: {
|
|
592
|
-
success: boolean;
|
|
593
|
-
agentId: string;
|
|
594
|
-
accepted: boolean;
|
|
595
|
-
};
|
|
596
|
-
meta: {
|
|
597
|
-
toolCallId: string;
|
|
598
|
-
agentId: string;
|
|
599
|
-
threadId?: string;
|
|
600
|
-
[key: string]: any;
|
|
601
|
-
};
|
|
602
|
-
};
|
|
603
|
-
|
|
604
|
-
/** Internal routing: handoff plugin → orchestrator only (not stored or broadcast). */
|
|
605
|
-
export type HandoffRequestEvent = BaseEvent & {
|
|
606
|
-
type: 'handoff:request';
|
|
607
|
-
data: {
|
|
608
|
-
agentId: string;
|
|
609
|
-
content: string;
|
|
610
|
-
};
|
|
611
|
-
meta?: Record<string, unknown>;
|
|
612
|
-
};
|
|
613
|
-
|
|
614
|
-
export type MCPListToolsEvent = BaseEvent & {
|
|
615
|
-
type: 'action:mcp_list_tools';
|
|
616
|
-
data: {
|
|
617
|
-
serverId: string;
|
|
618
|
-
};
|
|
619
|
-
};
|
|
620
|
-
|
|
621
|
-
export type MCPListToolsResultEvent = BaseEvent & {
|
|
622
|
-
type: 'action:mcp_list_tools:result';
|
|
623
|
-
data: {
|
|
624
|
-
success: boolean;
|
|
625
|
-
serverId: string;
|
|
626
|
-
tools: Array<{ name: string; description?: string; inputSchema?: unknown }>;
|
|
627
|
-
error?: string;
|
|
628
|
-
};
|
|
629
|
-
};
|
|
630
|
-
|
|
631
|
-
export type MCPCallEvent = BaseEvent & {
|
|
632
|
-
type: 'action:mcp_call';
|
|
633
|
-
data: {
|
|
634
|
-
serverId: string;
|
|
635
|
-
toolName: string;
|
|
636
|
-
args?: Record<string, unknown>;
|
|
637
|
-
};
|
|
638
|
-
};
|
|
639
|
-
|
|
640
|
-
export type MCPCallResultEvent = BaseEvent & {
|
|
641
|
-
type: 'action:mcp_call:result';
|
|
642
|
-
data: {
|
|
643
|
-
success: boolean;
|
|
644
|
-
serverId: string;
|
|
645
|
-
toolName: string;
|
|
646
|
-
result?: unknown;
|
|
647
|
-
error?: string;
|
|
648
|
-
};
|
|
649
|
-
};
|
|
650
|
-
|
|
651
576
|
export type ShellExecEvent = BaseEvent & {
|
|
652
577
|
type: 'action:shell_exec';
|
|
653
578
|
data: {
|
|
@@ -677,18 +602,6 @@ export type ShellExecResultEvent = BaseEvent & {
|
|
|
677
602
|
};
|
|
678
603
|
};
|
|
679
604
|
|
|
680
|
-
export type UserInputEvent = BaseEvent & {
|
|
681
|
-
type: 'user:input';
|
|
682
|
-
data: {
|
|
683
|
-
content: string;
|
|
684
|
-
};
|
|
685
|
-
meta?: {
|
|
686
|
-
userId?: string;
|
|
687
|
-
userName?: string;
|
|
688
|
-
userAvatarUrl?: string;
|
|
689
|
-
};
|
|
690
|
-
};
|
|
691
|
-
|
|
692
605
|
export type InstallPluginEvent = BaseEvent & {
|
|
693
606
|
type: 'action:plugin:install';
|
|
694
607
|
data: {
|
|
@@ -764,6 +677,25 @@ export type InstallAgentResultEvent = BaseEvent & {
|
|
|
764
677
|
|
|
765
678
|
export type MemoryScopeAlias = 'global' | 'agent' | 'channel';
|
|
766
679
|
|
|
680
|
+
export interface Usage {
|
|
681
|
+
promptTokens: number;
|
|
682
|
+
completionTokens: number;
|
|
683
|
+
totalTokens: number;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
export type AgentUsageEvent = BaseEvent & {
|
|
687
|
+
type: 'agent:usage';
|
|
688
|
+
data: {
|
|
689
|
+
usage: Usage;
|
|
690
|
+
model?: string;
|
|
691
|
+
};
|
|
692
|
+
meta: {
|
|
693
|
+
agentId: string;
|
|
694
|
+
threadId?: string;
|
|
695
|
+
runId?: string;
|
|
696
|
+
};
|
|
697
|
+
};
|
|
698
|
+
|
|
767
699
|
export type RememberEvent = BaseEvent & {
|
|
768
700
|
type: 'action:remember';
|
|
769
701
|
data: {
|
|
@@ -815,83 +747,41 @@ export type ForgetResultEvent = BaseEvent & {
|
|
|
815
747
|
};
|
|
816
748
|
};
|
|
817
749
|
|
|
818
|
-
export type
|
|
819
|
-
|
|
820
|
-
/**
|
|
821
|
-
* A single unit of work tracked in thread state. Todos are owned by the
|
|
822
|
-
* system (bus services); agents can only mutate them by calling the
|
|
823
|
-
* `todo_write` / `todo_update` tools so every change is observable on the
|
|
824
|
-
* event stream and audit-friendly.
|
|
825
|
-
*/
|
|
826
|
-
export interface TodoItem {
|
|
827
|
-
id: string;
|
|
828
|
-
content: string;
|
|
829
|
-
status: TodoStatus;
|
|
830
|
-
/** Optional agent id responsible for this item — drives autonomous handoffs. */
|
|
831
|
-
assignee?: string;
|
|
832
|
-
/** Agent id that created the todo (or "system"). */
|
|
833
|
-
createdBy: string;
|
|
834
|
-
createdAt: number;
|
|
835
|
-
updatedAt: number;
|
|
836
|
-
/**
|
|
837
|
-
* Captured final reply when this item reaches `done` (last `agent:output`
|
|
838
|
-
* from the assignee for that run). Lets downstream agents rely on thread
|
|
839
|
-
* state instead of merged short-term messages.
|
|
840
|
-
*/
|
|
841
|
-
result?: string;
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
export type TodoWriteInput = {
|
|
845
|
-
id?: string;
|
|
846
|
-
content: string;
|
|
847
|
-
status?: TodoStatus;
|
|
848
|
-
assignee?: string;
|
|
849
|
-
};
|
|
850
|
-
|
|
851
|
-
export type TodoWriteEvent = BaseEvent & {
|
|
852
|
-
type: 'action:todo_write';
|
|
750
|
+
export type DelegateTaskEvent = BaseEvent & {
|
|
751
|
+
type: 'action:delegate_task';
|
|
853
752
|
data: {
|
|
854
|
-
|
|
753
|
+
agentId: string;
|
|
754
|
+
prompt: string;
|
|
855
755
|
};
|
|
856
|
-
meta?: { toolCallId?: string; agentId?: string; threadId?: string };
|
|
857
756
|
};
|
|
858
757
|
|
|
859
|
-
export type
|
|
860
|
-
type: 'action:
|
|
758
|
+
export type DelegateTaskResultEvent = BaseEvent & {
|
|
759
|
+
type: 'action:delegate_task:result';
|
|
861
760
|
data: {
|
|
862
761
|
success: boolean;
|
|
863
|
-
|
|
762
|
+
output?: string;
|
|
864
763
|
error?: string;
|
|
865
764
|
};
|
|
866
|
-
meta?: { toolCallId?: string; agentId?: string; threadId?: string };
|
|
867
765
|
};
|
|
868
766
|
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
};
|
|
877
|
-
meta?: { toolCallId?: string; agentId?: string; threadId?: string };
|
|
878
|
-
};
|
|
767
|
+
/**
|
|
768
|
+
* Internal message representation to decouple harness history from specific AI SDKs.
|
|
769
|
+
*/
|
|
770
|
+
export type OpenBotMessage =
|
|
771
|
+
| { role: 'user'; content: string | OpenBotMessagePart[] }
|
|
772
|
+
| { role: 'assistant'; content: string | OpenBotMessagePart[] }
|
|
773
|
+
| { role: 'system'; content: string }
|
|
774
|
+
| { role: 'tool'; content: OpenBotMessagePart[] };
|
|
879
775
|
|
|
880
|
-
export type
|
|
881
|
-
type: '
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
todo?: TodoItem;
|
|
885
|
-
todos: TodoItem[];
|
|
886
|
-
error?: string;
|
|
887
|
-
};
|
|
888
|
-
meta?: { toolCallId?: string; agentId?: string; threadId?: string };
|
|
889
|
-
};
|
|
776
|
+
export type OpenBotMessagePart =
|
|
777
|
+
| { type: 'text'; text: string }
|
|
778
|
+
| { type: 'tool-call'; toolCallId: string; toolName: string; input: any }
|
|
779
|
+
| { type: 'tool-result'; toolCallId: string; toolName: string; output: any };
|
|
890
780
|
|
|
891
781
|
export type OpenBotEvent =
|
|
892
|
-
| UserInputEvent
|
|
893
782
|
| AgentInvokeEvent
|
|
894
783
|
| AgentOutputEvent
|
|
784
|
+
| AgentUsageEvent
|
|
895
785
|
| AgentRunStartEvent
|
|
896
786
|
| AgentRunEndEvent
|
|
897
787
|
| AgentRunStoppedEvent
|
|
@@ -946,15 +836,7 @@ export type OpenBotEvent =
|
|
|
946
836
|
| UpdateChannelEvent
|
|
947
837
|
| UpdateChannelResultEvent
|
|
948
838
|
| UIWidgetEvent
|
|
949
|
-
| RenderUIWidgetEvent
|
|
950
839
|
| UIWidgetResponseEvent
|
|
951
|
-
| HandoffEvent
|
|
952
|
-
| HandoffResultEvent
|
|
953
|
-
| HandoffRequestEvent
|
|
954
|
-
| MCPListToolsEvent
|
|
955
|
-
| MCPListToolsResultEvent
|
|
956
|
-
| MCPCallEvent
|
|
957
|
-
| MCPCallResultEvent
|
|
958
840
|
| ShellExecEvent
|
|
959
841
|
| ShellExecResultEvent
|
|
960
842
|
| InstallPluginEvent
|
|
@@ -971,7 +853,5 @@ export type OpenBotEvent =
|
|
|
971
853
|
| RecallResultEvent
|
|
972
854
|
| ForgetEvent
|
|
973
855
|
| ForgetResultEvent
|
|
974
|
-
|
|
|
975
|
-
|
|
|
976
|
-
| TodoUpdateEvent
|
|
977
|
-
| TodoUpdateResultEvent;
|
|
856
|
+
| DelegateTaskEvent
|
|
857
|
+
| DelegateTaskResultEvent;
|
package/src/assets/icon.svg
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
<svg width="60.2" height="58.1" viewBox="
|
|
2
|
-
<
|
|
3
|
-
|
|
1
|
+
<svg width="60.2" height="58.1" viewBox="272.584 370.297 64.635 62.51" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<style>
|
|
3
|
+
.mark { fill: #000000; }
|
|
4
|
+
@media (prefers-color-scheme: dark) {
|
|
5
|
+
.mark { fill: #ffffff; }
|
|
6
|
+
}
|
|
7
|
+
</style>
|
|
8
|
+
<path class="mark" fill="#000000" d="M301.841 380.896C302.069 380.893 302.297 380.889 302.531 380.885C304.636 380.853 306.741 380.836 308.845 380.822C310.26 380.813 311.675 380.8 313.09 380.775C314.456 380.752 315.822 380.739 317.189 380.735C317.71 380.731 318.231 380.724 318.752 380.712C322.824 380.626 322.824 380.626 323.909 381.43C324.315 382.025 324.561 382.569 324.8 383.246C324.965 383.518 325.13 383.789 325.301 384.068C325.519 384.445 325.519 384.445 325.741 384.83C325.909 385.118 326.077 385.407 326.249 385.704C326.336 385.854 326.423 386.004 326.513 386.159C328.304 389.25 330.137 392.314 332.004 395.361C332.482 396.144 332.957 396.929 333.431 397.715C333.631 398.035 333.631 398.035 333.835 398.361C334.546 399.544 334.969 400.367 334.7 401.777C334.24 402.838 333.683 403.834 333.113 404.839C332.867 405.285 332.621 405.73 332.375 406.176C332.125 406.626 331.874 407.075 331.622 407.525C330.952 408.724 330.296 409.931 329.639 411.137C329.518 411.359 329.397 411.58 329.272 411.807C328.303 413.581 327.349 415.362 326.398 417.144C324.53 420.642 322.621 424.107 320.611 427.525C320.282 428.088 319.962 428.655 319.644 429.224C319.215 429.954 319.215 429.954 318.708 430.462C317.978 430.557 317.978 430.557 317.185 430.462C316.049 429.578 315.42 428.258 314.71 427.035C313.685 425.291 312.637 423.6 311.454 421.96C311.024 421.203 310.906 420.668 310.838 419.8C311.092 419.081 311.092 419.081 311.491 418.343C311.707 417.937 311.707 417.937 311.927 417.522C312.081 417.242 312.235 416.963 312.393 416.675C312.615 416.26 312.615 416.26 312.841 415.836C314.003 413.671 314.003 413.671 314.549 412.797C315.269 411.676 315.269 411.676 315.308 410.387C314.801 409.466 314.268 408.575 313.694 407.695C313.466 407.335 313.238 406.976 313.011 406.616C312.845 406.353 312.845 406.353 312.676 406.085C312.247 405.402 311.829 404.713 311.425 404.014C311.304 403.806 311.183 403.598 311.058 403.384C310.786 402.65 310.848 402.26 311.092 401.523C311.6 401.015 311.6 401.015 312.57 400.967C312.988 400.97 313.407 400.975 313.826 400.982C314.281 400.981 314.737 400.981 315.192 400.98C315.911 400.98 316.629 400.984 317.348 400.995C318.041 401.005 318.733 401.002 319.427 400.998C319.641 401.004 319.854 401.011 320.075 401.017C320.695 401.007 321.171 400.974 321.754 400.762C322.329 400.154 322.665 399.481 323.023 398.731C323.171 398.49 323.318 398.248 323.47 398C323.899 397.287 324.326 396.573 324.752 395.859C324.904 395.608 325.056 395.357 325.212 395.099C325.355 394.859 325.498 394.618 325.646 394.371C325.841 394.045 325.841 394.045 326.04 393.713C326.38 393.138 326.38 393.138 326.323 392.385C326.167 392.384 326.011 392.383 325.85 392.383C322.054 392.368 318.257 392.349 314.461 392.325C312.625 392.313 310.789 392.303 308.953 392.297C307.352 392.291 305.752 392.282 304.152 392.271C303.305 392.265 302.458 392.26 301.61 392.258C300.664 392.256 299.719 392.249 298.773 392.241C298.351 392.241 298.351 392.241 297.921 392.242C297.663 392.238 297.406 392.235 297.14 392.232C296.916 392.231 296.693 392.23 296.462 392.228C295.73 392.109 295.379 391.879 294.846 391.369C294.591 389.978 295.187 388.999 295.837 387.818C295.938 387.63 296.038 387.441 296.142 387.246C296.464 386.646 296.789 386.049 297.115 385.451C297.333 385.045 297.551 384.638 297.769 384.231C299.545 380.925 299.545 380.925 301.841 380.896Z"/>
|
|
9
|
+
<path class="mark" fill="#000000" d="M291.476 372.547C292.795 373.009 293.243 374.055 293.942 375.218C294.23 375.684 294.519 376.15 294.807 376.615C294.945 376.84 295.082 377.065 295.223 377.297C295.544 377.813 295.875 378.314 296.225 378.811C296.388 379.044 296.551 379.277 296.718 379.518C296.856 379.711 296.994 379.903 297.137 380.102C297.492 380.97 297.407 381.615 297.131 382.485C296.704 383.459 296.209 384.39 295.703 385.325C295.497 385.714 295.497 385.714 295.287 386.111C294.44 387.702 293.559 389.255 292.565 390.759C292.217 391.585 292.351 392.026 292.562 392.892C292.955 393.665 292.955 393.665 293.466 394.431C293.555 394.572 293.644 394.713 293.736 394.858C294.019 395.304 294.305 395.748 294.592 396.192C294.971 396.778 295.346 397.365 295.719 397.953C295.886 398.212 296.053 398.471 296.225 398.738C296.646 399.535 296.848 400.115 296.877 401.015C296.559 401.435 296.559 401.435 296.115 401.777C295.364 401.849 294.663 401.877 293.911 401.871C293.467 401.876 293.023 401.88 292.579 401.885C291.879 401.887 291.18 401.888 290.48 401.888C289.804 401.888 289.129 401.895 288.453 401.903C288.244 401.901 288.036 401.899 287.82 401.897C286.637 401.91 286.637 401.91 285.616 402.466C284.844 403.543 284.229 404.69 283.598 405.854C283.455 406.11 283.312 406.365 283.165 406.628C283.031 406.873 282.897 407.118 282.76 407.371C282.637 407.594 282.515 407.818 282.389 408.048C282.071 408.656 282.071 408.656 282.408 409.392C282.559 409.393 282.71 409.394 282.865 409.395C286.539 409.416 290.213 409.439 293.886 409.465C295.663 409.478 297.439 409.49 299.216 409.499C300.929 409.509 302.642 409.521 304.356 409.534C305.011 409.539 305.665 409.543 306.32 409.546C307.235 409.55 308.15 409.557 309.064 409.565C309.473 409.566 309.473 409.566 309.89 409.567C310.139 409.57 310.388 409.573 310.644 409.576C310.861 409.577 311.077 409.578 311.3 409.58C311.854 409.646 311.854 409.646 312.615 410.154C312.797 411.581 312.41 412.577 311.745 413.808C311.656 413.979 311.567 414.15 311.475 414.326C311.288 414.685 311.099 415.042 310.908 415.399C310.616 415.946 310.329 416.495 310.042 417.045C309.859 417.394 309.676 417.743 309.492 418.092C309.363 418.337 309.363 418.337 309.231 418.588C308.881 419.242 308.574 419.78 308.046 420.308C307.364 420.361 306.707 420.382 306.024 420.382C305.815 420.383 305.606 420.385 305.391 420.387C304.698 420.392 304.005 420.392 303.312 420.393C302.832 420.395 302.351 420.396 301.871 420.398C300.862 420.401 299.854 420.402 298.845 420.402C297.552 420.402 296.259 420.409 294.966 420.417C293.973 420.423 292.98 420.424 291.987 420.424C291.51 420.424 291.034 420.427 290.557 420.431C289.89 420.436 289.224 420.434 288.557 420.431C288.36 420.434 288.163 420.437 287.959 420.44C287.061 420.429 286.569 420.386 285.852 419.824C285.47 419.314 285.137 418.817 284.831 418.259C284.718 418.056 284.605 417.852 284.488 417.643C284.367 417.423 284.246 417.203 284.121 416.976C282.907 414.808 281.638 412.679 280.329 410.566C280.156 410.286 279.982 410.006 279.803 409.717C279.469 409.176 279.134 408.636 278.799 408.096C277.871 406.592 276.959 405.077 276.062 403.554C275.968 403.409 275.874 403.264 275.777 403.114C275.143 402.097 274.834 401.442 275.046 400.254C275.425 399.337 275.889 398.475 276.363 397.604C276.568 397.22 276.568 397.22 276.777 396.828C278.005 394.541 279.284 392.283 280.569 390.029C282.224 387.119 283.868 384.197 285.327 381.184C289.509 372.654 289.509 372.654 291.476 372.547Z"/>
|
|
4
10
|
</svg>
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { melony } from 'melony';
|
|
2
|
+
import { OpenBotEvent, OpenBotState } from '../app/types.js';
|
|
3
|
+
import { ensureEventId } from '../app/utils.js';
|
|
4
|
+
import { storageService } from '../plugins/storage/service.js';
|
|
5
|
+
import { STATE_AGENT_ID, ORCHESTRATOR_AGENT_ID } from '../app/agent-ids.js';
|
|
6
|
+
import { resolvePlugin } from '../services/plugins/registry.js';
|
|
7
|
+
import { ToolDefinition } from '../services/plugins/types.js';
|
|
8
|
+
|
|
9
|
+
export { STATE_AGENT_ID, ORCHESTRATOR_AGENT_ID };
|
|
10
|
+
|
|
11
|
+
export interface RunAgentOptions {
|
|
12
|
+
runId: string;
|
|
13
|
+
agentId: string;
|
|
14
|
+
event: OpenBotEvent;
|
|
15
|
+
channelId: string;
|
|
16
|
+
threadId?: string;
|
|
17
|
+
persistEvents?: boolean;
|
|
18
|
+
onEvent: (event: OpenBotEvent, state?: OpenBotState) => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function emitEvent(
|
|
22
|
+
chunk: OpenBotEvent,
|
|
23
|
+
state: OpenBotState | undefined,
|
|
24
|
+
{
|
|
25
|
+
persistEvents,
|
|
26
|
+
channelId,
|
|
27
|
+
threadId,
|
|
28
|
+
onEvent,
|
|
29
|
+
parentAgentId,
|
|
30
|
+
parentToolCallId,
|
|
31
|
+
}: {
|
|
32
|
+
persistEvents: boolean;
|
|
33
|
+
channelId: string;
|
|
34
|
+
threadId?: string;
|
|
35
|
+
onEvent: RunAgentOptions['onEvent'];
|
|
36
|
+
parentAgentId?: string;
|
|
37
|
+
parentToolCallId?: string;
|
|
38
|
+
},
|
|
39
|
+
): Promise<void> {
|
|
40
|
+
ensureEventId(chunk);
|
|
41
|
+
|
|
42
|
+
// Enrich event with parent metadata if not already present
|
|
43
|
+
if (parentAgentId || parentToolCallId) {
|
|
44
|
+
chunk.meta = {
|
|
45
|
+
...chunk.meta,
|
|
46
|
+
parentAgentId: chunk.meta?.parentAgentId || parentAgentId,
|
|
47
|
+
parentToolCallId: chunk.meta?.parentToolCallId || parentToolCallId,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (persistEvents) {
|
|
52
|
+
await storageService.storeEvent({
|
|
53
|
+
channelId: state?.channelId || channelId,
|
|
54
|
+
threadId: state?.threadId || threadId,
|
|
55
|
+
event: chunk,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await onEvent(chunk, state);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Runs a single agent turn.
|
|
64
|
+
* Fire and forget.
|
|
65
|
+
*/
|
|
66
|
+
export async function runAgent(options: RunAgentOptions): Promise<void> {
|
|
67
|
+
const { runId, agentId, event, channelId, threadId, onEvent } = options;
|
|
68
|
+
const persistEvents = options.persistEvents !== false;
|
|
69
|
+
|
|
70
|
+
const parentAgentId = event.meta?.parentAgentId;
|
|
71
|
+
const parentToolCallId = event.meta?.parentToolCallId;
|
|
72
|
+
|
|
73
|
+
const agentDetails = await storageService.getAgentDetails({ agentId });
|
|
74
|
+
|
|
75
|
+
const state = await storageService.getOpenBotState({
|
|
76
|
+
runId,
|
|
77
|
+
agentId,
|
|
78
|
+
channelId,
|
|
79
|
+
threadId,
|
|
80
|
+
event,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
await emitEvent(
|
|
84
|
+
{
|
|
85
|
+
type: 'agent:run:start',
|
|
86
|
+
data: { runId, agentId, channelId, threadId },
|
|
87
|
+
} as OpenBotEvent,
|
|
88
|
+
state,
|
|
89
|
+
{ persistEvents, channelId, threadId, onEvent, parentAgentId, parentToolCallId },
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const pluginRefs = agentDetails.pluginRefs ?? [];
|
|
94
|
+
const tools: Record<string, ToolDefinition> = {};
|
|
95
|
+
|
|
96
|
+
for (const ref of pluginRefs) {
|
|
97
|
+
const plugin = await resolvePlugin(ref.id);
|
|
98
|
+
if (plugin?.toolDefinitions) {
|
|
99
|
+
Object.assign(tools, plugin.toolDefinitions);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const builder = melony<OpenBotState, OpenBotEvent>().initialState(state);
|
|
104
|
+
|
|
105
|
+
for (const ref of pluginRefs) {
|
|
106
|
+
const plugin = await resolvePlugin(ref.id);
|
|
107
|
+
if (!plugin) continue;
|
|
108
|
+
|
|
109
|
+
builder.use(
|
|
110
|
+
plugin.factory({
|
|
111
|
+
agentId,
|
|
112
|
+
agentDetails,
|
|
113
|
+
config: ref.config ?? {},
|
|
114
|
+
storage: storageService,
|
|
115
|
+
tools,
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const runtime = builder.build();
|
|
121
|
+
const generator = runtime.run(event, { runId, state });
|
|
122
|
+
|
|
123
|
+
for await (const outputEvent of generator) {
|
|
124
|
+
await emitEvent(outputEvent, state, {
|
|
125
|
+
persistEvents,
|
|
126
|
+
channelId,
|
|
127
|
+
threadId,
|
|
128
|
+
onEvent,
|
|
129
|
+
parentAgentId,
|
|
130
|
+
parentToolCallId,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error(`[harness] Error running agent ${agentId}:`, error);
|
|
135
|
+
} finally {
|
|
136
|
+
await emitEvent(
|
|
137
|
+
{
|
|
138
|
+
type: 'agent:run:end',
|
|
139
|
+
data: { runId, agentId, channelId, threadId },
|
|
140
|
+
} as OpenBotEvent,
|
|
141
|
+
state,
|
|
142
|
+
{ persistEvents, channelId, threadId, onEvent, parentAgentId, parentToolCallId },
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|