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.
Files changed (98) hide show
  1. package/README.md +15 -16
  2. package/dist/app/agent-ids.js +4 -0
  3. package/dist/app/cli.js +1 -1
  4. package/dist/app/config.js +0 -19
  5. package/dist/app/server.js +8 -14
  6. package/dist/assets/icon.svg +9 -3
  7. package/dist/bus/services.js +78 -132
  8. package/dist/harness/agent-invoke-run.js +44 -0
  9. package/dist/harness/agent-turn.js +99 -0
  10. package/dist/harness/channel-participants.js +40 -0
  11. package/dist/harness/constants.js +2 -0
  12. package/dist/harness/context-meter.js +97 -0
  13. package/dist/harness/context.js +98 -45
  14. package/dist/harness/dispatch.js +144 -0
  15. package/dist/harness/dispatcher.js +45 -156
  16. package/dist/harness/history.js +177 -0
  17. package/dist/harness/index.js +91 -0
  18. package/dist/harness/orchestration.js +88 -0
  19. package/dist/harness/participants.js +22 -0
  20. package/dist/harness/run-harness.js +154 -0
  21. package/dist/harness/run.js +98 -0
  22. package/dist/harness/runtime-factory.js +0 -34
  23. package/dist/harness/runtime.js +57 -0
  24. package/dist/harness/todo-dispatch.js +51 -0
  25. package/dist/harness/todos.js +5 -0
  26. package/dist/harness/turn.js +79 -0
  27. package/dist/plugins/approval/index.js +105 -149
  28. package/dist/plugins/delegation/index.js +119 -32
  29. package/dist/plugins/memory/index.js +103 -14
  30. package/dist/plugins/memory/service.js +152 -0
  31. package/dist/plugins/openbot/context.js +80 -0
  32. package/dist/plugins/openbot/history.js +98 -0
  33. package/dist/plugins/openbot/index.js +31 -0
  34. package/dist/plugins/openbot/runtime.js +317 -0
  35. package/dist/plugins/openbot/system-prompt.js +5 -0
  36. package/dist/plugins/plugin-manager/index.js +105 -0
  37. package/dist/plugins/storage/index.js +573 -0
  38. package/dist/plugins/storage/service.js +1159 -0
  39. package/dist/plugins/storage-tools/index.js +2 -2
  40. package/dist/plugins/thread-namer/index.js +72 -0
  41. package/dist/plugins/thread-naming/generate-title.js +44 -0
  42. package/dist/plugins/thread-naming/index.js +103 -0
  43. package/dist/plugins/threads/index.js +114 -0
  44. package/dist/plugins/todo/index.js +24 -25
  45. package/dist/plugins/ui/index.js +2 -32
  46. package/dist/registry/plugins.js +3 -9
  47. package/dist/services/plugins/domain.js +1 -0
  48. package/dist/services/plugins/plugin-cache.js +9 -0
  49. package/dist/services/plugins/registry.js +110 -0
  50. package/dist/services/plugins/service.js +177 -0
  51. package/dist/services/plugins/types.js +1 -0
  52. package/dist/services/process.js +29 -0
  53. package/dist/services/storage.js +41 -15
  54. package/dist/services/thread-naming.js +81 -0
  55. package/docs/agents.md +16 -10
  56. package/docs/architecture.md +2 -2
  57. package/docs/plugins.md +6 -15
  58. package/docs/templates/AGENT.example.md +7 -13
  59. package/package.json +1 -2
  60. package/src/app/agent-ids.ts +5 -0
  61. package/src/app/cli.ts +1 -1
  62. package/src/app/config.ts +1 -31
  63. package/src/app/server.ts +8 -16
  64. package/src/app/types.ts +70 -190
  65. package/src/assets/icon.svg +9 -3
  66. package/src/harness/index.ts +145 -0
  67. package/src/plugins/approval/index.ts +91 -189
  68. package/src/plugins/delegation/index.ts +136 -39
  69. package/src/plugins/memory/index.ts +112 -15
  70. package/src/{services/memory.ts → plugins/memory/service.ts} +1 -1
  71. package/src/plugins/openbot/context.ts +91 -0
  72. package/src/plugins/openbot/history.ts +107 -0
  73. package/src/plugins/openbot/index.ts +37 -0
  74. package/src/plugins/openbot/runtime.ts +384 -0
  75. package/src/plugins/openbot/system-prompt.ts +7 -0
  76. package/src/plugins/plugin-manager/index.ts +122 -0
  77. package/src/plugins/shell/index.ts +1 -1
  78. package/src/plugins/storage/index.ts +633 -0
  79. package/src/{services/storage.ts → plugins/storage/service.ts} +257 -72
  80. package/src/{bus/types.ts → services/plugins/domain.ts} +20 -7
  81. package/src/services/plugins/plugin-cache.ts +13 -0
  82. package/src/{registry/plugins.ts → services/plugins/registry.ts} +25 -27
  83. package/src/services/{plugins.ts → plugins/service.ts} +96 -2
  84. package/src/{bus/plugin.ts → services/plugins/types.ts} +3 -3
  85. package/src/bus/services.ts +0 -908
  86. package/src/harness/context.ts +0 -356
  87. package/src/harness/dispatcher.ts +0 -379
  88. package/src/harness/mcp.ts +0 -78
  89. package/src/harness/runtime-factory.ts +0 -129
  90. package/src/harness/todo-advance.ts +0 -128
  91. package/src/plugins/ai-sdk/index.ts +0 -41
  92. package/src/plugins/ai-sdk/runtime.ts +0 -468
  93. package/src/plugins/ai-sdk/system-prompt.ts +0 -18
  94. package/src/plugins/mcp/index.ts +0 -128
  95. package/src/plugins/storage-tools/index.ts +0 -90
  96. package/src/plugins/todo/index.ts +0 -64
  97. package/src/plugins/ui/index.ts +0 -227
  98. /package/src/{harness → services}/process.ts +0 -0
package/README.md CHANGED
@@ -18,7 +18,8 @@ OpenBot is a local-first harness for running AI agents. It is built around a sma
18
18
 
19
19
  - Runs a local agent server.
20
20
  - Stores channels, threads, agents, plugins, config, and variables under `~/.openbot`.
21
- - Ships with a built-in `system` agent named Lolly.
21
+ - Ships with a built-in `system` agent named OpenBot (orchestrator, includes the LLM runtime).
22
+ - Ships with a built-in `state` agent for deterministic, non-LLM handling (e.g. `/api/state` defaults).
22
23
  - Loads custom agents from `~/.openbot/agents/<agent-id>/AGENT.md`.
23
24
  - Loads shared plugins from `~/.openbot/plugins`.
24
25
  - Streams events to clients with Server-Sent Events.
@@ -50,15 +51,17 @@ npm run dev
50
51
  OpenBot intentionally keeps the public API small:
51
52
 
52
53
  - `GET /api/events` opens an SSE stream for a channel or thread.
53
- - `POST /api/publish` publishes an event into the harness.
54
- - `GET /api/state` runs an event and returns the resulting events without opening a stream.
54
+ - `POST /api/publish` publishes an event into the harness (defaults to the built-in `system` agent with the OpenBot / LLM runtime).
55
+ - `GET /api/state` runs an event and returns the resulting events without opening a stream (defaults to the built-in `state` agent: storage-oriented plugins, no LLM).
56
+
57
+ You can override the agent with `agentId` (header, query, or body where applicable).
55
58
 
56
59
  Example:
57
60
 
58
61
  ```bash
59
62
  curl -X POST http://localhost:4132/api/publish \
60
63
  -H "content-type: application/json" \
61
- -d '{"type":"user:input","data":{"content":"hello"}}'
64
+ -d '{"type":"agent:invoke","data":{"role":"user","content":"hello"}}'
62
65
  ```
63
66
 
64
67
  Useful context can be passed as headers, query params, or body fields:
@@ -76,8 +79,7 @@ OpenBot reads config from `~/.openbot/config.json`.
76
79
  {
77
80
  "port": 4132,
78
81
  "baseDir": "~/.openbot",
79
- "model": "openai/gpt-4o-mini",
80
- "mcpServers": []
82
+ "model": "openai/gpt-4o-mini"
81
83
  }
82
84
  ```
83
85
 
@@ -91,12 +93,11 @@ The built-in `system` agent is always available. Add a custom agent by creating
91
93
  ---
92
94
  name: Researcher
93
95
  description: Helps collect and summarize information.
94
- runtime:
95
- name: ai-sdk
96
- config:
97
- model: openai/gpt-4o-mini
98
96
  plugins:
99
- - name: storage
97
+ - id: openbot
98
+ config:
99
+ model: openai/gpt-4o-mini
100
+ - id: storage
100
101
  ---
101
102
 
102
103
  You are a careful research assistant.
@@ -109,18 +110,16 @@ Agents are discovered from disk when the server starts.
109
110
 
110
111
  Built-in plugins include:
111
112
 
112
- - `storage`
113
+ - `storage-tools`
113
114
  - `delegation`
114
- - `mcp`
115
- - `ui`
116
- - `ai-sdk`
115
+ - `openbot`
117
116
 
118
117
  Shared plugins can be placed in `~/.openbot/plugins` and referenced by agents.
119
118
 
120
119
  ## Project Layout
121
120
 
122
121
  - `src/app`: CLI, server, event types, and app config.
123
- - `src/harness`: orchestration, process, and MCP runtime helpers.
122
+ - `src/harness`: orchestration and process helpers.
124
123
  - `src/plugins`: built-in plugin implementations.
125
124
  - `src/services`: local storage service.
126
125
  - `src/registry`: plugin registry.
@@ -0,0 +1,4 @@
1
+ /** Built-in orchestrator agent id. Optional `agents/system/AGENT.md` overrides code defaults. */
2
+ export const ORCHESTRATOR_AGENT_ID = 'system';
3
+ /** Built-in infra agent for deterministic `/api/state` and marketplace/plugin lifecycle; optional AGENT.md overlay. */
4
+ export const STATE_AGENT_ID = 'state';
package/dist/app/cli.js CHANGED
@@ -16,7 +16,7 @@ function checkNodeVersion() {
16
16
  }
17
17
  }
18
18
  checkNodeVersion();
19
- program.name('openbot').description('OpenBot CLI').version('0.3.4');
19
+ program.name('openbot').description('OpenBot CLI').version('0.4.0');
20
20
  program
21
21
  .command('start')
22
22
  .description('Start the OpenBot harness')
@@ -46,22 +46,3 @@ export function loadVariables() {
46
46
  }
47
47
  return { version: 1, variables: [] };
48
48
  }
49
- export const DEFAULT_AGENT_MD = `---
50
- description: A specialized AI agent
51
- ---
52
-
53
- # Agent Profile
54
-
55
- You are a specialized AI agent within the OpenBot system.
56
- Your role is defined by your configuration and the tools you have access to.
57
-
58
- ## Persona
59
- - Helpful and precise
60
- - Focused on my specific domain
61
- - Professional in all interactions
62
- `;
63
- export const DEFAULT_USER_MD = `# About Me
64
-
65
- <!-- OpenBot reads this file to understand who you are and how you like to work. -->
66
- <!-- Edit it here or just chat — agents can update it with the "remember" tool. -->
67
- `;
@@ -9,10 +9,9 @@ const require = createRequire(import.meta.url);
9
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
- import { processService } from '../harness/process.js';
13
- import { storageService } from '../services/storage.js';
14
- import { dispatch } from '../harness/dispatcher.js';
15
- import { initPlugins } from '../registry/plugins.js';
12
+ import { processService } from '../services/process.js';
13
+ import { runAgent, STATE_AGENT_ID, ORCHESTRATOR_AGENT_ID } from '../harness/index.js';
14
+ import { initPlugins } from '../services/plugins/registry.js';
16
15
  import { ensureEventId, openBotEventFromQuery } from './utils.js';
17
16
  export async function startServer(options = {}) {
18
17
  const publishEventSchema = z
@@ -171,7 +170,6 @@ export async function startServer(options = {}) {
171
170
  return;
172
171
  }
173
172
  const onEvent = async (chunk, state) => {
174
- ensureEventId(chunk);
175
173
  const targetChannelId = state?.channelId || channelId;
176
174
  const targetThreadId = state?.threadId || threadId;
177
175
  const targetClientKey = getClientKey(targetChannelId, targetThreadId);
@@ -186,11 +184,6 @@ export async function startServer(options = {}) {
186
184
  else if (chunk.type === 'agent:run:end') {
187
185
  activeRuns.delete(getRunKey(chunk.data.runId, chunk.data.agentId, chunk.data.channelId, chunk.data.threadId));
188
186
  }
189
- await storageService.storeEvent({
190
- channelId: targetChannelId,
191
- threadId: targetThreadId,
192
- event: chunk,
193
- });
194
187
  sendToClientKey(targetClientKey, chunk);
195
188
  if (chunk.type === 'agent:run:start' ||
196
189
  chunk.type === 'agent:run:end' ||
@@ -200,9 +193,9 @@ export async function startServer(options = {}) {
200
193
  };
201
194
  try {
202
195
  ensureEventId(event);
203
- await dispatch({
196
+ await runAgent({
204
197
  runId,
205
- agentId: agentId || 'system',
198
+ agentId: agentId || ORCHESTRATOR_AGENT_ID,
206
199
  event,
207
200
  channelId,
208
201
  threadId,
@@ -238,12 +231,13 @@ export async function startServer(options = {}) {
238
231
  };
239
232
  try {
240
233
  ensureEventId(event);
241
- await dispatch({
234
+ await runAgent({
242
235
  runId,
243
- agentId: agentId || 'system',
236
+ agentId: agentId || STATE_AGENT_ID,
244
237
  event,
245
238
  channelId,
246
239
  threadId,
240
+ persistEvents: false,
247
241
  onEvent,
248
242
  });
249
243
  res.json({ events });
@@ -1,4 +1,10 @@
1
- <svg width="60.2" height="58.1" viewBox="262.8 360.5 84.2 82.1" fill="#9333EA" xmlns="http://www.w3.org/2000/svg">
2
- <path 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" fill="#9333EA"/>
3
- <path 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" fill="#9333EA"/>
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>
@@ -1,25 +1,6 @@
1
1
  import { DEFAULT_MARKETPLACE_REGISTRY_URL, loadConfig } from '../app/config.js';
2
2
  import { storageService } from '../services/storage.js';
3
3
  import { pluginService } from '../services/plugins.js';
4
- const readTodos = (state) => {
5
- const raw = state.threadDetails?.state?.todos;
6
- return Array.isArray(raw) ? raw : [];
7
- };
8
- let todoCounter = 0;
9
- const newTodoId = (now, idx) => `todo_${now.toString(36)}_${(todoCounter++).toString(36)}_${idx}`;
10
- async function persistTodos(storage, state, todos) {
11
- if (!state.threadId)
12
- throw new Error('No active thread');
13
- await storage.patchThreadState({
14
- channelId: state.channelId,
15
- threadId: state.threadId,
16
- state: { todos },
17
- });
18
- state.threadDetails = await storage.getThreadDetails({
19
- channelId: state.channelId,
20
- threadId: state.threadId,
21
- });
22
- }
23
4
  /**
24
5
  * Resolve a scope alias to a concrete scope string. Aliases let tools accept
25
6
  * `agent`/`channel`/`global` without knowing the active ids; the bus rewrites
@@ -44,26 +25,7 @@ function resolveMemoryScopeFilter(alias, state) {
44
25
  }
45
26
  return [resolveMemoryScope(alias, state)];
46
27
  }
47
- const DEFAULT_MARKETPLACE_AGENTS = [
48
- {
49
- id: 'researcher',
50
- name: 'Researcher',
51
- description: 'Specialized in web research and information synthesis.',
52
- instructions: 'You are a research assistant. Use available tools to find information.',
53
- plugins: [
54
- { id: 'ai-sdk', config: { model: 'openai/gpt-4o' } },
55
- { id: 'mcp' },
56
- { id: 'shell' },
57
- ],
58
- },
59
- {
60
- id: 'coder',
61
- name: 'Coder',
62
- description: 'Expert in multiple programming languages and software architecture.',
63
- instructions: 'You are an expert software engineer. Help the user with coding tasks.',
64
- plugins: [{ id: 'claude-code' }],
65
- },
66
- ];
28
+ const DEFAULT_MARKETPLACE_AGENTS = [];
67
29
  function isRecord(value) {
68
30
  return typeof value === 'object' && value !== null && !Array.isArray(value);
69
31
  }
@@ -163,7 +125,7 @@ export const busServicesPlugin = (options) => (builder) => {
163
125
  };
164
126
  });
165
127
  builder.on('action:create_channel', async function* (event, context) {
166
- const { channelId, spec, initialState, cwd } = event.data;
128
+ const { channelId, spec, initialState, cwd, participants } = event.data;
167
129
  const rawChannelId = (channelId || '').trim();
168
130
  const channelSpec = typeof spec === 'string' ? spec : '';
169
131
  const resultMeta = { ...(event.meta || {}), agentId: context.state.agentId };
@@ -176,11 +138,21 @@ export const busServicesPlugin = (options) => (builder) => {
176
138
  return;
177
139
  }
178
140
  const channelUrl = `/channels/${rawChannelId}`;
141
+ const mergedInitial = { ...(initialState || {}) };
142
+ if (participants !== undefined) {
143
+ const normalized = Array.isArray(participants)
144
+ ? participants
145
+ .filter((x) => typeof x === 'string')
146
+ .map((s) => s.trim())
147
+ .filter(Boolean)
148
+ : [];
149
+ mergedInitial.participants = normalized;
150
+ }
179
151
  try {
180
152
  await storage.createChannel({
181
153
  channelId: rawChannelId,
182
154
  spec: channelSpec,
183
- initialState: initialState,
155
+ initialState: mergedInitial,
184
156
  cwd,
185
157
  });
186
158
  yield {
@@ -224,6 +196,18 @@ export const busServicesPlugin = (options) => (builder) => {
224
196
  patch.cwd = data.cwd.trim();
225
197
  updatedFields.push('cwd');
226
198
  }
199
+ if (data.participants !== undefined) {
200
+ if (Array.isArray(data.participants)) {
201
+ patch.participants = data.participants
202
+ .filter((x) => typeof x === 'string')
203
+ .map((s) => s.trim())
204
+ .filter(Boolean);
205
+ }
206
+ else {
207
+ patch.participants = [];
208
+ }
209
+ updatedFields.push('participants');
210
+ }
227
211
  try {
228
212
  if (updatedFields.length > 0) {
229
213
  await storage.patchChannelState({ channelId: targetChannelId, state: patch });
@@ -250,31 +234,54 @@ export const busServicesPlugin = (options) => (builder) => {
250
234
  builder.on('action:patch_channel_details', async function* (event, context) {
251
235
  const updatedFields = [];
252
236
  const resultMeta = { ...(event.meta || {}), agentId: context.state.agentId };
237
+ const data = (event.data || {});
253
238
  try {
254
- if (event.data.state !== undefined) {
239
+ if (data.state !== undefined) {
255
240
  await storage.patchChannelState({
256
241
  channelId: context.state.channelId,
257
- state: event.data.state,
242
+ state: data.state,
258
243
  });
259
244
  updatedFields.push('state');
260
245
  }
261
- if (typeof event.data.spec === 'string') {
246
+ if (typeof data.spec === 'string') {
262
247
  await storage.patchChannelSpec({
263
248
  channelId: context.state.channelId,
264
- spec: event.data.spec,
249
+ spec: data.spec,
265
250
  });
266
251
  updatedFields.push('spec');
267
252
  }
268
- if (typeof event.data.cwd === 'string') {
253
+ if (typeof data.cwd === 'string') {
269
254
  await storage.patchChannelState({
270
255
  channelId: context.state.channelId,
271
- state: { cwd: event.data.cwd },
256
+ state: { cwd: data.cwd },
272
257
  });
273
258
  updatedFields.push('cwd');
274
259
  }
260
+ if (data.participants !== undefined) {
261
+ const normalized = Array.isArray(data.participants)
262
+ ? data.participants
263
+ .filter((x) => typeof x === 'string')
264
+ .map((s) => s.trim())
265
+ .filter(Boolean)
266
+ : [];
267
+ await storage.patchChannelState({
268
+ channelId: context.state.channelId,
269
+ state: { participants: normalized },
270
+ });
271
+ updatedFields.push('participants');
272
+ }
275
273
  context.state.channelDetails = await storage.getChannelDetails({
276
274
  channelId: context.state.channelId,
277
275
  });
276
+ yield {
277
+ type: "client:ui:widget",
278
+ data: {
279
+ kind: "message",
280
+ title: "Channel details updated.",
281
+ body: "The channel details have been updated.",
282
+ },
283
+ meta: resultMeta,
284
+ };
278
285
  yield {
279
286
  type: 'action:patch_channel_details:result',
280
287
  data: { success: true, updatedFields },
@@ -322,91 +329,30 @@ export const busServicesPlugin = (options) => (builder) => {
322
329
  };
323
330
  }
324
331
  });
325
- builder.on('action:todo_write', async function* (event, context) {
326
- const resultMeta = { ...(event.meta || {}), agentId: context.state.agentId };
327
- try {
328
- if (!context.state.threadId) {
329
- throw new Error('todo_write requires an active thread');
330
- }
331
- const existing = readTodos(context.state);
332
- const byId = new Map(existing.map((t) => [t.id, t]));
333
- const now = Date.now();
334
- const author = context.state.agentId || 'system';
335
- const inputs = event.data.todos || [];
336
- const next = inputs.map((raw, idx) => {
337
- const prior = raw.id ? byId.get(raw.id) : undefined;
338
- return {
339
- id: prior?.id || raw.id || newTodoId(now, idx),
340
- content: raw.content,
341
- status: raw.status || prior?.status || 'pending',
342
- assignee: raw.assignee ?? prior?.assignee,
343
- createdBy: prior?.createdBy || author,
344
- createdAt: prior?.createdAt || now,
345
- updatedAt: now,
346
- ...(prior?.result !== undefined ? { result: prior.result } : {}),
347
- };
348
- });
349
- await persistTodos(storage, context.state, next);
350
- yield {
351
- type: 'action:todo_write:result',
352
- data: { success: true, todos: next },
353
- meta: resultMeta,
354
- };
355
- }
356
- catch (error) {
357
- yield {
358
- type: 'action:todo_write:result',
359
- data: {
360
- success: false,
361
- todos: readTodos(context.state),
362
- error: error instanceof Error ? error.message : 'Unknown error',
363
- },
364
- meta: resultMeta,
365
- };
366
- }
367
- });
368
- builder.on('action:todo_update', async function* (event, context) {
369
- const resultMeta = { ...(event.meta || {}), agentId: context.state.agentId };
370
- const patch = event.data;
371
- try {
372
- if (!context.state.threadId) {
373
- throw new Error('todo_update requires an active thread');
374
- }
375
- const existing = readTodos(context.state);
376
- const idx = existing.findIndex((t) => t.id === patch.id);
377
- if (idx === -1) {
378
- throw new Error(`Todo "${patch.id}" not found`);
379
- }
380
- const now = Date.now();
381
- const updated = {
382
- ...existing[idx],
383
- ...(patch.content !== undefined ? { content: patch.content } : {}),
384
- ...(patch.status !== undefined ? { status: patch.status } : {}),
385
- ...(patch.assignee !== undefined
386
- ? { assignee: patch.assignee === '' ? undefined : patch.assignee }
387
- : {}),
388
- updatedAt: now,
389
- };
390
- const next = [...existing];
391
- next[idx] = updated;
392
- await persistTodos(storage, context.state, next);
393
- yield {
394
- type: 'action:todo_update:result',
395
- data: { success: true, todo: updated, todos: next },
396
- meta: resultMeta,
397
- };
398
- }
399
- catch (error) {
400
- yield {
401
- type: 'action:todo_update:result',
402
- data: {
403
- success: false,
404
- todos: readTodos(context.state),
405
- error: error instanceof Error ? error.message : 'Unknown error',
406
- },
407
- meta: resultMeta,
408
- };
409
- }
332
+ builder.on('agent:usage', async function* (event, context) {
333
+ const { usage } = event.data;
334
+ if (!context.state.threadId)
335
+ return;
336
+ const currentState = context.state.threadDetails?.state || {};
337
+ const currentUsage = currentState.usage || {
338
+ promptTokens: 0,
339
+ completionTokens: 0,
340
+ totalTokens: 0,
341
+ };
342
+ const nextUsage = {
343
+ promptTokens: (currentUsage.promptTokens || 0) + usage.promptTokens,
344
+ completionTokens: (currentUsage.completionTokens || 0) + usage.completionTokens,
345
+ totalTokens: (currentUsage.totalTokens || 0) + usage.totalTokens,
346
+ };
347
+ await storage.patchThreadState({
348
+ channelId: context.state.channelId,
349
+ threadId: context.state.threadId,
350
+ state: { usage: nextUsage },
351
+ });
352
+ context.state.threadDetails = await storage.getThreadDetails({
353
+ channelId: context.state.channelId,
354
+ threadId: context.state.threadId,
355
+ });
410
356
  });
411
357
  builder.on('action:storage:get-channels', async function* () {
412
358
  const channels = await storage.getChannels();
@@ -0,0 +1,44 @@
1
+ import { createAgentRuntime } from './runtime-factory.js';
2
+ /**
3
+ * Shared `runtime.run(agent:invoke)` loop: tags chunks with `agentId`, skips echo of the
4
+ * trigger event, optionally polls for stop, tracks last `agent:output` text.
5
+ *
6
+ * Does not emit `agent:run:start` / `agent:run:end` — callers bracket those.
7
+ */
8
+ export async function* streamTaggedAgentInvokeRuntime(options) {
9
+ const { target, event, state, pollInterrupt } = options;
10
+ const { runId, agentId } = target;
11
+ let lastAgentOutput;
12
+ const runtime = await createAgentRuntime(state);
13
+ for await (const chunk of runtime.run(event, { state, runId })) {
14
+ const interrupt = pollInterrupt?.();
15
+ if (interrupt) {
16
+ yield interrupt;
17
+ break;
18
+ }
19
+ if (chunk.id === event.id && chunk.type === event.type)
20
+ continue;
21
+ if (chunk.type === 'agent:output' &&
22
+ chunk.meta?.agentId === agentId) {
23
+ const content = chunk.data?.content;
24
+ if (typeof content === 'string' && content.trim()) {
25
+ lastAgentOutput = content.trim();
26
+ }
27
+ }
28
+ chunk.meta = { ...chunk.meta, agentId };
29
+ yield chunk;
30
+ }
31
+ return { lastAgentOutput };
32
+ }
33
+ /**
34
+ * Drive {@link streamTaggedAgentInvokeRuntime} with a callback per chunk (dispatcher path).
35
+ */
36
+ export async function consumeAgentInvokeStream(options, onChunk) {
37
+ const gen = streamTaggedAgentInvokeRuntime(options);
38
+ let step = await gen.next();
39
+ while (!step.done) {
40
+ await onChunk(step.value);
41
+ step = await gen.next();
42
+ }
43
+ return step.value;
44
+ }
@@ -0,0 +1,99 @@
1
+ import { ensureEventId } from '../app/utils.js';
2
+ import { storageService } from '../services/storage.js';
3
+ import { createAgentRuntime } from './runtime-factory.js';
4
+ const TODO_RESULT_MAX_CHARS = 12000;
5
+ const readThreadState = (state) => state.threadDetails?.state ?? {};
6
+ const readTodos = (state) => {
7
+ const raw = readThreadState(state).todos;
8
+ return Array.isArray(raw) ? raw : [];
9
+ };
10
+ function truncateTodoResult(text, maxChars = TODO_RESULT_MAX_CHARS) {
11
+ const trimmed = text.trim();
12
+ if (!trimmed)
13
+ return undefined;
14
+ if (trimmed.length <= maxChars)
15
+ return trimmed;
16
+ return `${trimmed.slice(0, maxChars)}\n…[truncated]`;
17
+ }
18
+ function resolveTodoIdForWorker(todos, workerId, delegationTodoId) {
19
+ if (delegationTodoId && todos.some((t) => t.id === delegationTodoId)) {
20
+ return delegationTodoId;
21
+ }
22
+ const inProgress = todos.find((t) => t.status === 'in_progress' && t.assignee === workerId);
23
+ if (inProgress)
24
+ return inProgress.id;
25
+ const assigned = todos.find((t) => (t.status === 'pending' || t.status === 'in_progress') && t.assignee === workerId);
26
+ return assigned?.id;
27
+ }
28
+ export async function recordWorkerTodoResult(state, workerId, output, delegationTodoId) {
29
+ if (!state.threadId)
30
+ return;
31
+ const result = truncateTodoResult(output ?? '');
32
+ if (!result)
33
+ return;
34
+ const todos = readTodos(state);
35
+ if (todos.length === 0)
36
+ return;
37
+ const todoId = resolveTodoIdForWorker(todos, workerId, delegationTodoId);
38
+ if (!todoId)
39
+ return;
40
+ const prior = todos.find((t) => t.id === todoId);
41
+ if (prior?.result === result)
42
+ return;
43
+ const now = Date.now();
44
+ const next = todos.map((t) => (t.id === todoId ? { ...t, result, updatedAt: now } : t));
45
+ await storageService.patchThreadState({
46
+ channelId: state.channelId,
47
+ threadId: state.threadId,
48
+ state: { todos: next },
49
+ });
50
+ }
51
+ export function makeInternalInvoke(content, threadId) {
52
+ return ensureEventId({
53
+ type: 'agent:invoke',
54
+ data: { role: 'user', content },
55
+ meta: { threadId, internal: true },
56
+ });
57
+ }
58
+ /**
59
+ * Run one agent turn (no dispatcher chaining). Yields all runtime events for
60
+ * persistence/streaming; returns the last non-empty `agent:output` text.
61
+ */
62
+ export async function* runAgentTurn(options) {
63
+ const { runId, channelId, threadId, agentId, event, delegationTodoId } = options;
64
+ const target = { runId, agentId, channelId, threadId };
65
+ let state;
66
+ try {
67
+ state = await storageService.getOpenBotState({ ...target, event });
68
+ }
69
+ catch (error) {
70
+ if (error.code === 'AGENT_NOT_FOUND') {
71
+ return undefined;
72
+ }
73
+ throw error;
74
+ }
75
+ yield { type: 'agent:run:start', data: { ...target } };
76
+ let lastAgentOutput;
77
+ try {
78
+ const runtime = await createAgentRuntime(state);
79
+ for await (const chunk of runtime.run(event, { state, runId })) {
80
+ if (chunk.id === event.id && chunk.type === event.type)
81
+ continue;
82
+ if (chunk.type === 'agent:output' &&
83
+ chunk.meta?.agentId === agentId) {
84
+ const content = chunk.data?.content;
85
+ if (typeof content === 'string' && content.trim()) {
86
+ lastAgentOutput = content.trim();
87
+ }
88
+ }
89
+ chunk.meta = { ...chunk.meta, agentId };
90
+ yield chunk;
91
+ }
92
+ }
93
+ finally {
94
+ const stateAfterRun = await storageService.getOpenBotState({ ...target, event });
95
+ yield { type: 'agent:run:end', data: { ...target } };
96
+ await recordWorkerTodoResult(stateAfterRun, agentId, lastAgentOutput, delegationTodoId);
97
+ }
98
+ return lastAgentOutput;
99
+ }