openbot 0.2.13 → 0.3.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 (80) hide show
  1. package/dist/agents/openbot/index.js +76 -0
  2. package/dist/agents/openbot/middleware/approval.js +132 -0
  3. package/dist/agents/openbot/runtime.js +289 -0
  4. package/dist/agents/openbot/system-prompt.js +32 -0
  5. package/dist/agents/openbot/tools/delegation.js +78 -0
  6. package/dist/agents/openbot/tools/mcp.js +99 -0
  7. package/dist/agents/openbot/tools/shell.js +91 -0
  8. package/dist/agents/openbot/tools/storage.js +75 -0
  9. package/dist/agents/openbot/tools/ui.js +176 -0
  10. package/dist/agents/system.js +20 -93
  11. package/dist/app/cli.js +1 -1
  12. package/dist/app/config.js +4 -1
  13. package/dist/app/server.js +15 -8
  14. package/dist/bus/agent-package.js +1 -0
  15. package/dist/bus/plugin.js +1 -0
  16. package/dist/bus/services.js +600 -0
  17. package/dist/bus/types.js +1 -0
  18. package/dist/harness/context.js +131 -0
  19. package/dist/harness/event-normalizer.js +59 -0
  20. package/dist/harness/orchestrator.js +27 -227
  21. package/dist/harness/process.js +25 -3
  22. package/dist/harness/queue-processor.js +227 -0
  23. package/dist/harness/runtime-factory.js +103 -0
  24. package/dist/plugins/ai-sdk/index.js +37 -0
  25. package/dist/plugins/ai-sdk/runtime.js +330 -0
  26. package/dist/plugins/ai-sdk/system-prompt.js +3 -0
  27. package/dist/plugins/ai-sdk.js +277 -87
  28. package/dist/plugins/approval/index.js +159 -0
  29. package/dist/plugins/approval.js +163 -0
  30. package/dist/plugins/delegation/index.js +79 -0
  31. package/dist/plugins/delegation.js +67 -11
  32. package/dist/plugins/mcp/index.js +108 -0
  33. package/dist/plugins/shell/index.js +99 -0
  34. package/dist/plugins/shell.js +123 -0
  35. package/dist/plugins/storage-tools/index.js +85 -0
  36. package/dist/plugins/storage.js +240 -5
  37. package/dist/plugins/ui/index.js +184 -0
  38. package/dist/plugins/ui.js +185 -21
  39. package/dist/registry/agents.js +138 -0
  40. package/dist/registry/plugins.js +91 -50
  41. package/dist/services/agent-packages.js +103 -0
  42. package/dist/services/plugins.js +98 -0
  43. package/dist/services/storage.js +360 -94
  44. package/docs/agents.md +39 -66
  45. package/docs/architecture.md +1 -1
  46. package/docs/plugins.md +70 -58
  47. package/docs/templates/AGENT.example.md +57 -0
  48. package/package.json +3 -2
  49. package/src/app/cli.ts +1 -1
  50. package/src/app/config.ts +14 -4
  51. package/src/app/server.ts +23 -10
  52. package/src/app/types.ts +385 -16
  53. package/src/assets/icon.svg +4 -1
  54. package/src/bus/plugin.ts +67 -0
  55. package/src/bus/services.ts +666 -0
  56. package/src/bus/types.ts +147 -0
  57. package/src/harness/context.ts +160 -0
  58. package/src/harness/event-normalizer.ts +82 -0
  59. package/src/harness/orchestrator.ts +35 -273
  60. package/src/harness/process.ts +28 -4
  61. package/src/harness/queue-processor.ts +309 -0
  62. package/src/harness/runtime-factory.ts +125 -0
  63. package/src/plugins/ai-sdk/index.ts +44 -0
  64. package/src/plugins/ai-sdk/runtime.ts +410 -0
  65. package/src/plugins/ai-sdk/system-prompt.ts +4 -0
  66. package/src/plugins/approval/index.ts +228 -0
  67. package/src/plugins/delegation/index.ts +94 -0
  68. package/src/plugins/mcp/index.ts +128 -0
  69. package/src/plugins/shell/index.ts +123 -0
  70. package/src/plugins/storage-tools/index.ts +101 -0
  71. package/src/plugins/ui/index.ts +227 -0
  72. package/src/registry/plugins.ts +106 -55
  73. package/src/services/plugins.ts +133 -0
  74. package/src/services/storage.ts +465 -137
  75. package/src/agents/system.ts +0 -112
  76. package/src/plugins/ai-sdk.ts +0 -197
  77. package/src/plugins/delegation.ts +0 -60
  78. package/src/plugins/mcp.ts +0 -154
  79. package/src/plugins/storage.ts +0 -725
  80. package/src/plugins/ui.ts +0 -57
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,600 @@
1
+ import { DEFAULT_MARKETPLACE_REGISTRY_URL, loadConfig } from '../app/config.js';
2
+ import { storageService } from '../services/storage.js';
3
+ import { pluginService } from '../services/plugins.js';
4
+ const DEFAULT_MARKETPLACE_AGENTS = [
5
+ {
6
+ id: 'researcher',
7
+ name: 'Researcher',
8
+ description: 'Specialized in web research and information synthesis.',
9
+ instructions: 'You are a research assistant. Use available tools to find information.',
10
+ plugins: [
11
+ { id: 'ai-sdk', config: { model: 'openai/gpt-4o' } },
12
+ { id: 'mcp' },
13
+ { id: 'shell' },
14
+ ],
15
+ },
16
+ {
17
+ id: 'coder',
18
+ name: 'Coder',
19
+ description: 'Expert in multiple programming languages and software architecture.',
20
+ instructions: 'You are an expert software engineer. Help the user with coding tasks.',
21
+ plugins: [{ id: 'claude-code' }],
22
+ },
23
+ ];
24
+ function isRecord(value) {
25
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
26
+ }
27
+ /**
28
+ * Parses JSON from a remote registry file. Supports either
29
+ * `{ "agents": [ ... ] }` or a top-level array.
30
+ */
31
+ export function parseMarketplaceRegistryJson(data) {
32
+ const rawAgents = Array.isArray(data) ? data : isRecord(data) && Array.isArray(data.agents) ? data.agents : null;
33
+ if (!Array.isArray(rawAgents)) {
34
+ throw new Error('Registry JSON must be an array or an object with an "agents" array');
35
+ }
36
+ return rawAgents.map((item, i) => {
37
+ if (!isRecord(item)) {
38
+ throw new Error(`agents[${i}]: expected object`);
39
+ }
40
+ const id = item.id;
41
+ const name = item.name;
42
+ const description = item.description;
43
+ const instructions = item.instructions;
44
+ const pluginsRaw = item.plugins;
45
+ if (typeof id !== 'string' || !id)
46
+ throw new Error(`agents[${i}].id must be a non-empty string`);
47
+ if (typeof name !== 'string')
48
+ throw new Error(`agents[${i}].name must be a string`);
49
+ if (typeof description !== 'string')
50
+ throw new Error(`agents[${i}].description must be a string`);
51
+ if (typeof instructions !== 'string') {
52
+ throw new Error(`agents[${i}].instructions must be a string`);
53
+ }
54
+ if (!Array.isArray(pluginsRaw))
55
+ throw new Error(`agents[${i}].plugins must be an array`);
56
+ const plugins = pluginsRaw.map((p, j) => {
57
+ if (!isRecord(p) || typeof p.id !== 'string' || !p.id) {
58
+ throw new Error(`agents[${i}].plugins[${j}]: expected { "id": string, "config"?: object }`);
59
+ }
60
+ const ref = { id: p.id };
61
+ if (p.config !== undefined) {
62
+ if (!isRecord(p.config))
63
+ throw new Error(`agents[${i}].plugins[${j}].config must be an object`);
64
+ ref.config = p.config;
65
+ }
66
+ return ref;
67
+ });
68
+ const listing = { id, name, description, instructions, plugins };
69
+ if (item.image !== undefined) {
70
+ if (typeof item.image !== 'string')
71
+ throw new Error(`agents[${i}].image must be a string`);
72
+ listing.image = item.image;
73
+ }
74
+ return listing;
75
+ });
76
+ }
77
+ async function fetchMarketplaceAgentsFromUrl(url) {
78
+ const res = await fetch(url, {
79
+ headers: { Accept: 'application/json' },
80
+ signal: AbortSignal.timeout(15000),
81
+ });
82
+ if (!res.ok) {
83
+ throw new Error(`Registry HTTP ${res.status} ${res.statusText}`);
84
+ }
85
+ const json = await res.json();
86
+ return parseMarketplaceRegistryJson(json);
87
+ }
88
+ export const busServicesPlugin = (options) => (builder) => {
89
+ const { storage } = options;
90
+ builder.on('action:create_thread', async function* (event, context) {
91
+ const threadId = event.meta?.threadId;
92
+ const channelId = context.state.channelId;
93
+ const { threadTitle, spec, initialState } = event.data;
94
+ if (!threadId) {
95
+ console.warn('[bus] Cannot create thread: meta.threadId is missing');
96
+ return;
97
+ }
98
+ context.state.threadId = threadId;
99
+ if (channelId) {
100
+ try {
101
+ await storage.createThread({
102
+ channelId,
103
+ threadId,
104
+ threadTitle,
105
+ spec,
106
+ initialState: initialState || {},
107
+ });
108
+ context.state.threadDetails = await storage.getThreadDetails({
109
+ channelId,
110
+ threadId,
111
+ });
112
+ }
113
+ catch (error) {
114
+ console.warn(`[bus] Failed to initialize thread for channel ${channelId} thread ${threadId}`, error);
115
+ }
116
+ }
117
+ yield {
118
+ type: 'action:create_thread:result',
119
+ data: { success: true, threadId, threadTitle },
120
+ meta: { threadId },
121
+ };
122
+ });
123
+ builder.on('action:create_channel', async function* (event, context) {
124
+ const { channelId, spec, initialState, cwd } = event.data;
125
+ const rawChannelId = (channelId || '').trim();
126
+ const channelSpec = typeof spec === 'string' ? spec : '';
127
+ if (!rawChannelId) {
128
+ yield {
129
+ type: 'action:create_channel:result',
130
+ data: { success: false, channelId: '', channelUrl: '' },
131
+ };
132
+ return;
133
+ }
134
+ const channelUrl = `/channels/${rawChannelId}`;
135
+ try {
136
+ await storage.createChannel({
137
+ channelId: rawChannelId,
138
+ spec: channelSpec,
139
+ initialState: initialState,
140
+ cwd,
141
+ });
142
+ yield {
143
+ type: 'action:create_channel:result',
144
+ data: { success: true, channelId: rawChannelId, channelUrl },
145
+ };
146
+ yield {
147
+ type: 'agent:output',
148
+ data: { content: `Created channel \`${rawChannelId}\`.` },
149
+ meta: {
150
+ ...(event.meta || {}),
151
+ agentId: context.state.agentId,
152
+ },
153
+ };
154
+ }
155
+ catch {
156
+ yield {
157
+ type: 'action:create_channel:result',
158
+ data: { success: false, channelId: rawChannelId, channelUrl },
159
+ };
160
+ }
161
+ });
162
+ builder.on('action:update_channel', async function* (event, context) {
163
+ const data = (event.data || {});
164
+ const targetChannelId = (data.channelId || context.state.channelId || '').trim();
165
+ if (!targetChannelId) {
166
+ yield {
167
+ type: 'action:update_channel:result',
168
+ data: { success: false, channelId: '', updatedFields: [] },
169
+ };
170
+ return;
171
+ }
172
+ const patch = {};
173
+ const updatedFields = [];
174
+ if (typeof data.name === 'string' && data.name.trim()) {
175
+ patch.name = data.name.trim();
176
+ updatedFields.push('name');
177
+ }
178
+ if (typeof data.cwd === 'string' && data.cwd.trim()) {
179
+ patch.cwd = data.cwd.trim();
180
+ updatedFields.push('cwd');
181
+ }
182
+ try {
183
+ if (updatedFields.length > 0) {
184
+ await storage.patchChannelState({ channelId: targetChannelId, state: patch });
185
+ }
186
+ if (targetChannelId === context.state.channelId) {
187
+ context.state.channelDetails = await storage.getChannelDetails({
188
+ channelId: context.state.channelId,
189
+ });
190
+ }
191
+ yield {
192
+ type: 'action:update_channel:result',
193
+ data: { success: true, channelId: targetChannelId, updatedFields },
194
+ };
195
+ }
196
+ catch {
197
+ yield {
198
+ type: 'action:update_channel:result',
199
+ data: { success: false, channelId: targetChannelId, updatedFields },
200
+ };
201
+ }
202
+ });
203
+ builder.on('action:patch_channel_details', async function* (event, context) {
204
+ const updatedFields = [];
205
+ try {
206
+ if (event.data.state !== undefined) {
207
+ await storage.patchChannelState({
208
+ channelId: context.state.channelId,
209
+ state: event.data.state,
210
+ });
211
+ updatedFields.push('state');
212
+ }
213
+ if (typeof event.data.spec === 'string') {
214
+ await storage.patchChannelSpec({
215
+ channelId: context.state.channelId,
216
+ spec: event.data.spec,
217
+ });
218
+ updatedFields.push('spec');
219
+ }
220
+ if (typeof event.data.cwd === 'string') {
221
+ await storage.patchChannelState({
222
+ channelId: context.state.channelId,
223
+ state: { cwd: event.data.cwd },
224
+ });
225
+ updatedFields.push('cwd');
226
+ }
227
+ context.state.channelDetails = await storage.getChannelDetails({
228
+ channelId: context.state.channelId,
229
+ });
230
+ yield {
231
+ type: 'action:patch_channel_details:result',
232
+ data: { success: true, updatedFields },
233
+ };
234
+ }
235
+ catch {
236
+ yield {
237
+ type: 'action:patch_channel_details:result',
238
+ data: { success: false, updatedFields },
239
+ };
240
+ }
241
+ });
242
+ builder.on('action:patch_thread_details', async function* (event, context) {
243
+ const updatedFields = [];
244
+ try {
245
+ if (!context.state.threadId) {
246
+ throw new Error('Missing threadId in state for patch_thread_details');
247
+ }
248
+ if (event.data.state !== undefined) {
249
+ await storage.patchThreadState({
250
+ channelId: context.state.channelId,
251
+ threadId: context.state.threadId,
252
+ state: event.data.state,
253
+ });
254
+ updatedFields.push('state');
255
+ }
256
+ if (typeof event.data.spec === 'string') {
257
+ await storage.patchThreadSpec({
258
+ channelId: context.state.channelId,
259
+ threadId: context.state.threadId,
260
+ spec: event.data.spec,
261
+ });
262
+ updatedFields.push('spec');
263
+ }
264
+ context.state.threadDetails = await storage.getThreadDetails({
265
+ channelId: context.state.channelId,
266
+ threadId: context.state.threadId,
267
+ });
268
+ yield {
269
+ type: 'action:patch_thread_details:result',
270
+ data: { success: true, updatedFields },
271
+ };
272
+ }
273
+ catch {
274
+ yield {
275
+ type: 'action:patch_thread_details:result',
276
+ data: { success: false, updatedFields },
277
+ };
278
+ }
279
+ });
280
+ builder.on('action:storage:get-channels', async function* () {
281
+ const channels = await storage.getChannels();
282
+ yield { type: 'action:storage:get-channels-result', data: { channels } };
283
+ });
284
+ builder.on('action:storage:get-threads', async function* (event) {
285
+ const threads = await storage.getThreads({ channelId: event.data.channelId });
286
+ yield { type: 'action:storage:get-threads-result', data: { threads } };
287
+ });
288
+ builder.on('action:storage:get-channel-details', async function* (_, state) {
289
+ const channelDetails = await storage.getChannelDetails({
290
+ channelId: state.state.channelId,
291
+ });
292
+ yield { type: 'action:storage:get-channel-details-result', data: { channelDetails } };
293
+ });
294
+ builder.on('action:storage:get-thread-details', async function* (_, state) {
295
+ const threadId = state.state.threadId;
296
+ const threadDetails = threadId
297
+ ? await storage.getThreadDetails({ channelId: state.state.channelId, threadId })
298
+ : null;
299
+ yield { type: 'action:storage:get-thread-details-result', data: { threadDetails } };
300
+ });
301
+ builder.on('action:storage:get-agents', async function* () {
302
+ const agents = await storage.getAgents();
303
+ yield { type: 'action:storage:get-agents-result', data: { agents } };
304
+ });
305
+ builder.on('action:storage:get-plugins', async function* () {
306
+ const plugins = await storage.getPlugins();
307
+ yield { type: 'action:storage:get-plugins-result', data: { plugins } };
308
+ });
309
+ builder.on('action:storage:get-agent-details', async function* (event) {
310
+ try {
311
+ const agentDetails = await storage.getAgentDetails({ agentId: event.data.agentId });
312
+ yield { type: 'action:storage:get-agent-details-result', data: { agentDetails } };
313
+ }
314
+ catch (error) {
315
+ console.error(`[bus] Failed to get agent details for ${event.data.agentId}`, error);
316
+ yield {
317
+ type: 'action:storage:get-agent-details-result',
318
+ data: {
319
+ agentDetails: null,
320
+ error: error instanceof Error ? error.message : 'Unknown error',
321
+ },
322
+ };
323
+ }
324
+ });
325
+ builder.on('action:storage:create-agent', async function* (event) {
326
+ try {
327
+ const { agentId, name, description, instructions, plugins } = event.data;
328
+ await storage.createAgent({ agentId, name, description, instructions, plugins });
329
+ yield { type: 'action:storage:create-agent-result', data: { success: true } };
330
+ }
331
+ catch (error) {
332
+ yield {
333
+ type: 'action:storage:create-agent-result',
334
+ data: {
335
+ success: false,
336
+ error: error instanceof Error ? error.message : 'Unknown error',
337
+ },
338
+ };
339
+ }
340
+ });
341
+ builder.on('action:storage:update-agent', async function* (event) {
342
+ try {
343
+ const { agentId, name, description, instructions, plugins } = event.data;
344
+ await storage.updateAgent({ agentId, name, description, instructions, plugins });
345
+ yield { type: 'action:storage:update-agent-result', data: { success: true } };
346
+ }
347
+ catch (error) {
348
+ yield {
349
+ type: 'action:storage:update-agent-result',
350
+ data: {
351
+ success: false,
352
+ error: error instanceof Error ? error.message : 'Unknown error',
353
+ },
354
+ };
355
+ }
356
+ });
357
+ builder.on('action:storage:delete-agent', async function* (event) {
358
+ try {
359
+ await storage.deleteAgent({ agentId: event.data.agentId });
360
+ yield { type: 'action:storage:delete-agent-result', data: { success: true } };
361
+ }
362
+ catch (error) {
363
+ yield {
364
+ type: 'action:storage:delete-agent-result',
365
+ data: {
366
+ success: false,
367
+ error: error instanceof Error ? error.message : 'Unknown error',
368
+ },
369
+ };
370
+ }
371
+ });
372
+ builder.on('action:storage:get-events', async function* (_, state) {
373
+ const events = await storage.getEvents(state.state);
374
+ if (!state.state.threadId && events.length > 0) {
375
+ const lastId = events[events.length - 1]?.id;
376
+ if (lastId) {
377
+ await storageService.setLastReadForChannel({
378
+ channelId: state.state.channelId,
379
+ lastReadEventId: lastId,
380
+ });
381
+ }
382
+ }
383
+ yield { type: 'action:storage:get-events-result', data: { events } };
384
+ });
385
+ builder.on('action:storage:get-variables', async function* () {
386
+ const variables = await storage.getVariables();
387
+ const masked = {};
388
+ for (const [key, val] of Object.entries(variables)) {
389
+ if (typeof val === 'object' && val !== null && val.secret) {
390
+ masked[key] = '********';
391
+ }
392
+ else {
393
+ masked[key] = typeof val === 'string' ? val : val.value;
394
+ }
395
+ }
396
+ yield {
397
+ type: 'action:storage:get-variables-result',
398
+ data: { variables: masked },
399
+ };
400
+ });
401
+ builder.on('action:storage:create-variable', async function* (event) {
402
+ try {
403
+ const { key, value, secret } = event.data;
404
+ await storage.createVariable({ key, value, secret });
405
+ yield { type: 'action:storage:create-variable-result', data: { success: true } };
406
+ }
407
+ catch (error) {
408
+ yield {
409
+ type: 'action:storage:create-variable-result',
410
+ data: {
411
+ success: false,
412
+ error: error instanceof Error ? error.message : 'Unknown error',
413
+ },
414
+ };
415
+ }
416
+ });
417
+ builder.on('action:storage:delete-variable', async function* (event) {
418
+ try {
419
+ await storage.deleteVariable({ key: event.data.key });
420
+ yield { type: 'action:storage:delete-variable-result', data: { success: true } };
421
+ }
422
+ catch (error) {
423
+ yield {
424
+ type: 'action:storage:delete-variable-result',
425
+ data: {
426
+ success: false,
427
+ error: error instanceof Error ? error.message : 'Unknown error',
428
+ },
429
+ };
430
+ }
431
+ });
432
+ builder.on('action:storage:patch-channel-state', async function* (event, state) {
433
+ try {
434
+ await storage.patchChannelState({
435
+ channelId: state.state.channelId,
436
+ state: event.data.state,
437
+ });
438
+ yield { type: 'action:storage:patch-channel-state-result', data: { success: true } };
439
+ }
440
+ catch {
441
+ yield { type: 'action:storage:patch-channel-state-result', data: { success: false } };
442
+ }
443
+ });
444
+ builder.on('action:storage:patch-thread-state', async function* (event, state) {
445
+ try {
446
+ if (!state.state.threadId) {
447
+ throw new Error('Missing threadId in state for patch-thread-state');
448
+ }
449
+ await storage.patchThreadState({
450
+ channelId: state.state.channelId,
451
+ threadId: state.state.threadId,
452
+ state: event.data.state,
453
+ });
454
+ yield { type: 'action:storage:patch-thread-state-result', data: { success: true } };
455
+ }
456
+ catch {
457
+ yield { type: 'action:storage:patch-thread-state-result', data: { success: false } };
458
+ }
459
+ });
460
+ builder.on('action:storage:list-files', async function* (event, context) {
461
+ const channelId = context.state.channelId;
462
+ const subPath = event.data?.path || '';
463
+ try {
464
+ const files = await storage.listFiles({ channelId, path: subPath });
465
+ yield {
466
+ type: 'action:storage:list-files:result',
467
+ data: { success: true, files },
468
+ };
469
+ }
470
+ catch (error) {
471
+ yield {
472
+ type: 'action:storage:list-files:result',
473
+ data: {
474
+ success: false,
475
+ files: [],
476
+ error: error instanceof Error ? error.message : 'Unknown error',
477
+ },
478
+ };
479
+ }
480
+ });
481
+ builder.on('action:storage:read-file', async function* (event, context) {
482
+ const channelId = context.state.channelId;
483
+ const filePath = event.data?.path;
484
+ if (!filePath) {
485
+ yield {
486
+ type: 'action:storage:read-file:result',
487
+ data: { success: false, path: '', error: 'Path is required' },
488
+ };
489
+ return;
490
+ }
491
+ try {
492
+ const content = await storage.readFile({ channelId, path: filePath });
493
+ yield {
494
+ type: 'action:storage:read-file:result',
495
+ data: { success: true, content, path: filePath },
496
+ };
497
+ }
498
+ catch (error) {
499
+ yield {
500
+ type: 'action:storage:read-file:result',
501
+ data: {
502
+ success: false,
503
+ path: filePath,
504
+ error: error instanceof Error ? error.message : 'Unknown error',
505
+ },
506
+ };
507
+ }
508
+ });
509
+ builder.on('action:plugin:install', async function* (event) {
510
+ try {
511
+ const { name, version } = event.data;
512
+ const result = await pluginService.install({ packageName: name, version });
513
+ yield {
514
+ type: 'action:plugin:install:result',
515
+ data: { success: true, plugin: result },
516
+ };
517
+ }
518
+ catch (error) {
519
+ yield {
520
+ type: 'action:plugin:install:result',
521
+ data: { success: false, error: error.message },
522
+ };
523
+ }
524
+ });
525
+ builder.on('action:plugin:uninstall', async function* (event) {
526
+ try {
527
+ await pluginService.uninstall(event.data.id);
528
+ yield { type: 'action:plugin:uninstall:result', data: { success: true } };
529
+ }
530
+ catch (error) {
531
+ yield {
532
+ type: 'action:plugin:uninstall:result',
533
+ data: { success: false, error: error.message },
534
+ };
535
+ }
536
+ });
537
+ builder.on('action:marketplace:list', async function* () {
538
+ const { marketplaceRegistryUrl } = loadConfig();
539
+ const registryUrl = marketplaceRegistryUrl?.trim() || DEFAULT_MARKETPLACE_REGISTRY_URL;
540
+ let agents = DEFAULT_MARKETPLACE_AGENTS;
541
+ try {
542
+ agents = await fetchMarketplaceAgentsFromUrl(registryUrl);
543
+ }
544
+ catch (err) {
545
+ console.warn(`[bus] marketplace registry fetch failed (${registryUrl}), using built-in list:`, err instanceof Error ? err.message : err);
546
+ }
547
+ yield {
548
+ type: 'action:marketplace:list:result',
549
+ data: { success: true, agents },
550
+ };
551
+ });
552
+ builder.on('action:agent:install', async function* (event) {
553
+ try {
554
+ const { agentId, name, description, instructions, plugins } = event.data;
555
+ // Ensure each plugin is available locally. Built-in ids resolve
556
+ // immediately; npm-name ids are fetched on demand.
557
+ for (const ref of plugins) {
558
+ const installed = await pluginService.isInstalled(ref.id);
559
+ if (!installed && ref.id.includes('/') === false && ref.id.includes('-plugin-') === false) {
560
+ // Treat ids without a hyphen+slash signature as built-ins; skip install.
561
+ continue;
562
+ }
563
+ if (!installed) {
564
+ try {
565
+ await pluginService.install({ packageName: ref.id });
566
+ }
567
+ catch (err) {
568
+ console.warn(`[bus] Failed to pre-install plugin ${ref.id}`, err);
569
+ }
570
+ }
571
+ }
572
+ await storage.createAgent({
573
+ agentId,
574
+ name,
575
+ description,
576
+ instructions,
577
+ plugins,
578
+ });
579
+ yield {
580
+ type: 'action:agent:install:result',
581
+ data: { success: true, agentId },
582
+ };
583
+ yield {
584
+ type: 'agent:output',
585
+ data: { content: `Successfully installed agent **${name}** (${agentId}) from marketplace.` },
586
+ meta: { agentId: 'system' },
587
+ };
588
+ }
589
+ catch (error) {
590
+ yield {
591
+ type: 'action:agent:install:result',
592
+ data: {
593
+ success: false,
594
+ agentId: event.data.agentId,
595
+ error: error instanceof Error ? error.message : 'Unknown error',
596
+ },
597
+ };
598
+ }
599
+ });
600
+ };
@@ -0,0 +1 @@
1
+ export {};