openbot 0.2.12 → 0.2.14
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/.prettierrc +8 -0
- package/AGENTS.md +68 -0
- package/CONTRIBUTING.md +74 -0
- package/LICENSE +21 -0
- package/README.md +117 -14
- package/dist/agents/system.js +106 -0
- package/dist/app/cli.js +27 -0
- package/dist/app/config.js +64 -0
- package/dist/app/server.js +237 -0
- package/dist/app/utils.js +35 -0
- package/dist/harness/agent-harness.js +45 -0
- package/dist/harness/mcp.js +61 -0
- package/dist/harness/orchestrator.js +273 -0
- package/dist/harness/process.js +7 -0
- package/dist/plugins/ai-sdk.js +141 -0
- package/dist/plugins/delegation.js +52 -0
- package/dist/plugins/mcp.js +140 -0
- package/dist/plugins/storage.js +502 -0
- package/dist/plugins/ui.js +47 -0
- package/dist/registry/plugins.js +73 -0
- package/dist/services/storage.js +724 -0
- package/docs/README.md +7 -0
- package/docs/agents.md +83 -0
- package/docs/architecture.md +34 -0
- package/docs/plugins.md +77 -0
- package/logo-black.png +0 -0
- package/{dist/assets/logo.js → logo-black.svg} +24 -24
- package/{dist/ui/sidebar.js → logo-white.svg} +23 -88
- package/package.json +6 -5
- package/src/agents/system.ts +112 -0
- package/src/app/cli.ts +38 -0
- package/src/app/config.ts +104 -0
- package/src/app/server.ts +284 -0
- package/src/app/types.ts +476 -0
- package/src/app/utils.ts +43 -0
- package/src/assets/icon.svg +1 -0
- package/src/harness/agent-harness.ts +58 -0
- package/src/harness/mcp.ts +78 -0
- package/src/harness/orchestrator.ts +342 -0
- package/src/harness/process.ts +9 -0
- package/src/harness/types.ts +34 -0
- package/src/plugins/ai-sdk.ts +197 -0
- package/src/plugins/delegation.ts +60 -0
- package/src/plugins/mcp.ts +154 -0
- package/src/plugins/storage.ts +725 -0
- package/src/plugins/ui.ts +57 -0
- package/src/registry/plugins.ts +85 -0
- package/src/services/storage.ts +957 -0
- package/tsconfig.json +18 -0
- package/dist/agents/agent-creator.js +0 -74
- package/dist/agents/browser-agent.js +0 -31
- package/dist/agents/os-agent.js +0 -32
- package/dist/agents/planner-agent.js +0 -32
- package/dist/agents/topic-agent.js +0 -46
- package/dist/architecture/execution-engine.js +0 -151
- package/dist/architecture/intent-classifier.js +0 -26
- package/dist/architecture/planner.js +0 -106
- package/dist/automation-worker.js +0 -121
- package/dist/automations.js +0 -52
- package/dist/cli.js +0 -279
- package/dist/config.js +0 -53
- package/dist/core/agents.js +0 -41
- package/dist/core/delegation.js +0 -230
- package/dist/core/manager.js +0 -96
- package/dist/core/plugins.js +0 -74
- package/dist/core/router.js +0 -191
- package/dist/handlers/init.js +0 -29
- package/dist/handlers/session-change.js +0 -21
- package/dist/handlers/settings.js +0 -47
- package/dist/handlers/tab-change.js +0 -14
- package/dist/installers.js +0 -156
- package/dist/marketplace.js +0 -80
- package/dist/model-catalog.js +0 -132
- package/dist/model-defaults.js +0 -25
- package/dist/models.js +0 -47
- package/dist/open-bot.js +0 -51
- package/dist/orchestrator/direct-invocation.js +0 -13
- package/dist/orchestrator/events.js +0 -36
- package/dist/orchestrator/state.js +0 -54
- package/dist/orchestrator.js +0 -422
- package/dist/plugins/agent/index.js +0 -81
- package/dist/plugins/approval/index.js +0 -100
- package/dist/plugins/brain/identity.js +0 -77
- package/dist/plugins/brain/index.js +0 -204
- package/dist/plugins/brain/memory.js +0 -120
- package/dist/plugins/brain/prompt.js +0 -46
- package/dist/plugins/brain/types.js +0 -45
- package/dist/plugins/brain/ui.js +0 -7
- package/dist/plugins/browser/index.js +0 -629
- package/dist/plugins/browser/ui.js +0 -13
- package/dist/plugins/file-system/index.js +0 -171
- package/dist/plugins/file-system/ui.js +0 -6
- package/dist/plugins/llm/context-budget.js +0 -139
- package/dist/plugins/llm/context-shaping.js +0 -177
- package/dist/plugins/llm/index.js +0 -380
- package/dist/plugins/memory/index.js +0 -220
- package/dist/plugins/memory/memory.js +0 -122
- package/dist/plugins/memory/prompt.js +0 -55
- package/dist/plugins/memory/types.js +0 -45
- package/dist/plugins/meta-agent/index.js +0 -570
- package/dist/plugins/meta-agent/ui.js +0 -11
- package/dist/plugins/shell/index.js +0 -100
- package/dist/plugins/shell/ui.js +0 -6
- package/dist/plugins/skills/index.js +0 -286
- package/dist/plugins/skills/types.js +0 -50
- package/dist/plugins/skills/ui.js +0 -12
- package/dist/registry/agent-registry.js +0 -35
- package/dist/registry/index.js +0 -2
- package/dist/registry/plugin-loader.js +0 -499
- package/dist/registry/plugin-registry.js +0 -44
- package/dist/registry/ts-agent-loader.js +0 -82
- package/dist/registry/yaml-agent-loader.js +0 -246
- package/dist/runtime/execution-trace.js +0 -41
- package/dist/runtime/intent-routing.js +0 -26
- package/dist/runtime/openbot-runtime.js +0 -354
- package/dist/server.js +0 -890
- package/dist/session.js +0 -179
- package/dist/ui/block.js +0 -12
- package/dist/ui/header.js +0 -52
- package/dist/ui/layout.js +0 -26
- package/dist/ui/navigation.js +0 -15
- package/dist/ui/settings.js +0 -106
- package/dist/ui/skills.js +0 -7
- package/dist/ui/thread.js +0 -16
- package/dist/ui/widgets/action-list.js +0 -2
- package/dist/ui/widgets/approval-card.js +0 -9
- package/dist/ui/widgets/code-snippet.js +0 -2
- package/dist/ui/widgets/data-block.js +0 -2
- package/dist/ui/widgets/data-table.js +0 -2
- package/dist/ui/widgets/delegation.js +0 -29
- package/dist/ui/widgets/empty-state.js +0 -2
- package/dist/ui/widgets/index.js +0 -23
- package/dist/ui/widgets/inquiry.js +0 -7
- package/dist/ui/widgets/key-value.js +0 -2
- package/dist/ui/widgets/progress-step.js +0 -2
- package/dist/ui/widgets/resource-card.js +0 -2
- package/dist/ui/widgets/status.js +0 -2
- package/dist/ui/widgets/todo-list.js +0 -2
- package/dist/version.js +0 -62
- /package/dist/{types.js → app/types.js} +0 -0
- /package/dist/{architecture/contracts.js → harness/types.js} +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { generateText } from 'ai';
|
|
2
|
+
import { openai } from '@ai-sdk/openai';
|
|
3
|
+
import { anthropic } from '@ai-sdk/anthropic';
|
|
4
|
+
/**
|
|
5
|
+
* Resolves a standardized model string to an AI SDK LanguageModel.
|
|
6
|
+
*/
|
|
7
|
+
function resolveModel(modelString) {
|
|
8
|
+
const [provider, ...rest] = modelString.split('/');
|
|
9
|
+
const modelId = rest.join('/');
|
|
10
|
+
if (!modelId) {
|
|
11
|
+
throw new Error(`Invalid model string: "${modelString}". Expected format: "provider/model-id"`);
|
|
12
|
+
}
|
|
13
|
+
switch (provider) {
|
|
14
|
+
case 'openai':
|
|
15
|
+
return openai(modelId);
|
|
16
|
+
case 'anthropic':
|
|
17
|
+
return anthropic(modelId);
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`Unsupported AI provider: "${provider}"`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function buildSystemPrompt(state, system, context, storage) {
|
|
23
|
+
const sections = [];
|
|
24
|
+
if (state.agentDetails) {
|
|
25
|
+
sections.push(`## AGENT NAME\n${state.agentDetails.name}`);
|
|
26
|
+
sections.push(`## AGENT SPECIFICATION\n${state.agentDetails.instructions}`);
|
|
27
|
+
}
|
|
28
|
+
if (state.channelDetails) {
|
|
29
|
+
sections.push(`## CHANNEL NAME\n${state.channelDetails.name}`);
|
|
30
|
+
sections.push(`## CHANNEL SPECIFICATION\n${state.channelDetails.spec}`);
|
|
31
|
+
// sections.push(`## CHANNEL STATE\n${JSON.stringify(state.channelDetails.state, null, 2)}`);
|
|
32
|
+
if (storage) {
|
|
33
|
+
try {
|
|
34
|
+
const channelEvents = await storage.getEvents({ channelId: state.channelId });
|
|
35
|
+
if (channelEvents.length > 0) {
|
|
36
|
+
const formattedEvents = channelEvents
|
|
37
|
+
.slice(-20)
|
|
38
|
+
.map((e) => `- ${e.type}: ${JSON.stringify(e.data || {})}`)
|
|
39
|
+
.join('\n');
|
|
40
|
+
sections.push(`## CHANNEL RECENT ACTIVITIES (events)\n${formattedEvents}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.warn(`[ai-sdk] Failed to fetch channel events for ${state.channelId}`, error);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (state.threadDetails) {
|
|
49
|
+
sections.push(`## THREAD NAME\n${state.threadDetails.name}`);
|
|
50
|
+
sections.push(`## THREAD SPECIFICATION\n${state.threadDetails.spec}`);
|
|
51
|
+
// sections.push(`## THREAD STATE\n${JSON.stringify(state.threadDetails.state, null, 2)}`);
|
|
52
|
+
if (storage && state.threadId) {
|
|
53
|
+
try {
|
|
54
|
+
const threadEvents = await storage.getEvents({
|
|
55
|
+
channelId: state.channelId,
|
|
56
|
+
threadId: state.threadId,
|
|
57
|
+
});
|
|
58
|
+
if (threadEvents.length > 0) {
|
|
59
|
+
const formattedEvents = threadEvents
|
|
60
|
+
.slice(-20)
|
|
61
|
+
.map((e) => `- ${e.type}: ${JSON.stringify(e.data || {})}`)
|
|
62
|
+
.join('\n');
|
|
63
|
+
sections.push(`## THREAD RECENT ACTIVITIES (events)\n${formattedEvents}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.warn(`[ai-sdk] Failed to fetch thread events for channel ${state.channelId} thread ${state.threadId}`, error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (system && typeof system === 'string') {
|
|
72
|
+
sections.push(`## SYSTEM INSTRUCTIONS\n${system}`);
|
|
73
|
+
}
|
|
74
|
+
if (system && typeof system === 'function' && context) {
|
|
75
|
+
sections.push(await system(context));
|
|
76
|
+
}
|
|
77
|
+
return sections.join('\n\n');
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* AI SDK Plugin for Melony.
|
|
81
|
+
* Automatically handles text events and routes them through an AI SDK using Vercel AI SDK.
|
|
82
|
+
* It can also automatically trigger events based on tool calls.
|
|
83
|
+
*/
|
|
84
|
+
export const aiSdkPlugin = (options) => (builder) => {
|
|
85
|
+
const { model: modelString = 'openai/gpt-4o-mini', system, storage, toolDefinitions = {}, } = options;
|
|
86
|
+
const model = resolveModel(modelString);
|
|
87
|
+
builder.on('agent:invoke', async function* (event, context) {
|
|
88
|
+
// extract threadId if model decides to reply in a thread
|
|
89
|
+
const threadId = event.meta?.threadId || context.state.threadId;
|
|
90
|
+
const systemPrompt = await buildSystemPrompt(context.state, system, context, storage);
|
|
91
|
+
context.state.shortTermMessages = [
|
|
92
|
+
...(context.state.shortTermMessages ?? []),
|
|
93
|
+
{
|
|
94
|
+
role: event.data?.role || 'user',
|
|
95
|
+
content: event?.data?.content || '',
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
const result = await generateText({
|
|
99
|
+
model,
|
|
100
|
+
system: systemPrompt,
|
|
101
|
+
messages: context.state.shortTermMessages,
|
|
102
|
+
tools: toolDefinitions,
|
|
103
|
+
});
|
|
104
|
+
const toolCalls = result.toolCalls ?? [];
|
|
105
|
+
if (toolCalls.length > 0) {
|
|
106
|
+
for (const toolCall of toolCalls) {
|
|
107
|
+
const toolEvent = {
|
|
108
|
+
type: `action:${toolCall.toolName}`,
|
|
109
|
+
data: toolCall.input,
|
|
110
|
+
meta: {
|
|
111
|
+
toolCallId: toolCall.toolCallId,
|
|
112
|
+
agentId: context.state.agentId,
|
|
113
|
+
threadId,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
yield toolEvent;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (result.text) {
|
|
120
|
+
context.state.shortTermMessages = [
|
|
121
|
+
...(context.state.shortTermMessages ?? []),
|
|
122
|
+
{ role: 'assistant', content: result.text },
|
|
123
|
+
];
|
|
124
|
+
yield {
|
|
125
|
+
type: 'agent:output',
|
|
126
|
+
data: {
|
|
127
|
+
content: result.text,
|
|
128
|
+
},
|
|
129
|
+
meta: {
|
|
130
|
+
agentId: context.state.agentId,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
export const plugin = {
|
|
137
|
+
name: 'ai-sdk',
|
|
138
|
+
description: 'Built-in AI SDK plugin',
|
|
139
|
+
kind: 'runtime',
|
|
140
|
+
factory: aiSdkPlugin,
|
|
141
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Delegation Plugin for Melony.
|
|
4
|
+
* Automatically handles delegation events and routes them through the storage service.
|
|
5
|
+
*/
|
|
6
|
+
export const delegationPlugin = () => (builder) => {
|
|
7
|
+
builder.on('action:delegate', async function* (event, context) {
|
|
8
|
+
const { agentId, content } = event.data;
|
|
9
|
+
// 1. Show the delegation in the UI
|
|
10
|
+
yield {
|
|
11
|
+
type: 'agent:output',
|
|
12
|
+
data: {
|
|
13
|
+
content: `Delegating to **${agentId}**: ${content}`,
|
|
14
|
+
},
|
|
15
|
+
meta: {
|
|
16
|
+
...(event.meta || {}),
|
|
17
|
+
agentId: context.state.agentId,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
// 2. Trigger the linear execution loop in orchestratorService
|
|
21
|
+
yield {
|
|
22
|
+
type: 'agent:invoke',
|
|
23
|
+
data: {
|
|
24
|
+
agentId,
|
|
25
|
+
content,
|
|
26
|
+
},
|
|
27
|
+
meta: {
|
|
28
|
+
...(event.meta || {}),
|
|
29
|
+
agentId: context.state.agentId,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
export const delegationToolDefinitions = {
|
|
35
|
+
delegate: {
|
|
36
|
+
description: 'Delegate a task to another agent. The agent will run independently and feed results back to you. Call at most once per step.',
|
|
37
|
+
inputSchema: z.object({
|
|
38
|
+
agentId: z.string().describe('The ID of the agent (e.g. "os", "browser", "tavily").'),
|
|
39
|
+
content: z.string().describe('The message or task for the agent.'),
|
|
40
|
+
}),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
export const plugin = {
|
|
44
|
+
name: 'delegation',
|
|
45
|
+
description: 'Delegation plugin',
|
|
46
|
+
version: '1.0.0',
|
|
47
|
+
author: 'OpenBot',
|
|
48
|
+
license: 'MIT',
|
|
49
|
+
website: 'https://openbot.one',
|
|
50
|
+
factory: delegationPlugin,
|
|
51
|
+
toolDefinitions: delegationToolDefinitions,
|
|
52
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import { mcpService } from '../harness/mcp.js';
|
|
3
|
+
function stringifyResult(value) {
|
|
4
|
+
if (typeof value === 'string') {
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
try {
|
|
8
|
+
return JSON.stringify(value, null, 2);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return String(value);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export const mcpToolDefinitions = {
|
|
15
|
+
mcp_list_tools: {
|
|
16
|
+
description: 'List available tools from a configured MCP server. Use this first before calling tools on an unknown server.',
|
|
17
|
+
inputSchema: z.object({
|
|
18
|
+
serverId: z.string().describe('Configured MCP server id (for example: github, notion, linear).'),
|
|
19
|
+
}),
|
|
20
|
+
},
|
|
21
|
+
mcp_call: {
|
|
22
|
+
description: 'Call a tool on a configured MCP server. Provide tool arguments as a JSON object. Use mcp_list_tools first when uncertain.',
|
|
23
|
+
inputSchema: z.object({
|
|
24
|
+
serverId: z.string().describe('Configured MCP server id.'),
|
|
25
|
+
toolName: z.string().describe('Exact MCP tool name from mcp_list_tools.'),
|
|
26
|
+
args: z.record(z.string(), z.unknown()).default({}).describe('Tool arguments as a JSON object.'),
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
export const mcpPlugin = () => (builder) => {
|
|
31
|
+
builder.on('action:mcp_list_tools', async function* (event, context) {
|
|
32
|
+
const serverId = event.data?.serverId;
|
|
33
|
+
try {
|
|
34
|
+
const tools = await mcpService.listTools(serverId);
|
|
35
|
+
const toolNames = tools.map((tool) => `- ${tool.name}${tool.description ? `: ${tool.description}` : ''}`);
|
|
36
|
+
yield {
|
|
37
|
+
type: 'action:mcp_list_tools:result',
|
|
38
|
+
data: {
|
|
39
|
+
success: true,
|
|
40
|
+
serverId,
|
|
41
|
+
tools,
|
|
42
|
+
},
|
|
43
|
+
meta: event.meta,
|
|
44
|
+
};
|
|
45
|
+
yield {
|
|
46
|
+
type: 'agent:output',
|
|
47
|
+
data: {
|
|
48
|
+
content: toolNames.length > 0
|
|
49
|
+
? `MCP tools available on \`${serverId}\`:\n${toolNames.join('\n')}`
|
|
50
|
+
: `MCP server \`${serverId}\` has no tools.`,
|
|
51
|
+
},
|
|
52
|
+
meta: {
|
|
53
|
+
...(event.meta || {}),
|
|
54
|
+
agentId: context.state.agentId,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
const message = error instanceof Error ? error.message : 'Unknown MCP error';
|
|
60
|
+
yield {
|
|
61
|
+
type: 'action:mcp_list_tools:result',
|
|
62
|
+
data: {
|
|
63
|
+
success: false,
|
|
64
|
+
serverId,
|
|
65
|
+
tools: [],
|
|
66
|
+
error: message,
|
|
67
|
+
},
|
|
68
|
+
meta: event.meta,
|
|
69
|
+
};
|
|
70
|
+
yield {
|
|
71
|
+
type: 'agent:output',
|
|
72
|
+
data: {
|
|
73
|
+
content: `Failed to list MCP tools for \`${serverId}\`: ${message}`,
|
|
74
|
+
},
|
|
75
|
+
meta: {
|
|
76
|
+
...(event.meta || {}),
|
|
77
|
+
agentId: context.state.agentId,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
builder.on('action:mcp_call', async function* (event, context) {
|
|
83
|
+
const serverId = event.data?.serverId;
|
|
84
|
+
const toolName = event.data?.toolName;
|
|
85
|
+
const args = (event.data?.args || {});
|
|
86
|
+
try {
|
|
87
|
+
const result = await mcpService.callTool(serverId, toolName, args);
|
|
88
|
+
const rendered = stringifyResult(result);
|
|
89
|
+
yield {
|
|
90
|
+
type: 'action:mcp_call:result',
|
|
91
|
+
data: {
|
|
92
|
+
success: true,
|
|
93
|
+
serverId,
|
|
94
|
+
toolName,
|
|
95
|
+
result,
|
|
96
|
+
},
|
|
97
|
+
meta: event.meta,
|
|
98
|
+
};
|
|
99
|
+
yield {
|
|
100
|
+
type: 'agent:output',
|
|
101
|
+
data: {
|
|
102
|
+
content: `MCP \`${serverId}.${toolName}\` result:\n\n${rendered}`,
|
|
103
|
+
},
|
|
104
|
+
meta: {
|
|
105
|
+
...(event.meta || {}),
|
|
106
|
+
agentId: context.state.agentId,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
const message = error instanceof Error ? error.message : 'Unknown MCP error';
|
|
112
|
+
yield {
|
|
113
|
+
type: 'action:mcp_call:result',
|
|
114
|
+
data: {
|
|
115
|
+
success: false,
|
|
116
|
+
serverId,
|
|
117
|
+
toolName,
|
|
118
|
+
error: message,
|
|
119
|
+
},
|
|
120
|
+
meta: event.meta,
|
|
121
|
+
};
|
|
122
|
+
yield {
|
|
123
|
+
type: 'agent:output',
|
|
124
|
+
data: {
|
|
125
|
+
content: `MCP call failed for \`${serverId}.${toolName}\`: ${message}`,
|
|
126
|
+
},
|
|
127
|
+
meta: {
|
|
128
|
+
...(event.meta || {}),
|
|
129
|
+
agentId: context.state.agentId,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
export const plugin = {
|
|
136
|
+
name: 'mcp',
|
|
137
|
+
description: 'Basic MCP integration for configured servers',
|
|
138
|
+
factory: mcpPlugin,
|
|
139
|
+
toolDefinitions: mcpToolDefinitions,
|
|
140
|
+
};
|