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.
Files changed (141) hide show
  1. package/.prettierrc +8 -0
  2. package/AGENTS.md +68 -0
  3. package/CONTRIBUTING.md +74 -0
  4. package/LICENSE +21 -0
  5. package/README.md +117 -14
  6. package/dist/agents/system.js +106 -0
  7. package/dist/app/cli.js +27 -0
  8. package/dist/app/config.js +64 -0
  9. package/dist/app/server.js +237 -0
  10. package/dist/app/utils.js +35 -0
  11. package/dist/harness/agent-harness.js +45 -0
  12. package/dist/harness/mcp.js +61 -0
  13. package/dist/harness/orchestrator.js +273 -0
  14. package/dist/harness/process.js +7 -0
  15. package/dist/plugins/ai-sdk.js +141 -0
  16. package/dist/plugins/delegation.js +52 -0
  17. package/dist/plugins/mcp.js +140 -0
  18. package/dist/plugins/storage.js +502 -0
  19. package/dist/plugins/ui.js +47 -0
  20. package/dist/registry/plugins.js +73 -0
  21. package/dist/services/storage.js +724 -0
  22. package/docs/README.md +7 -0
  23. package/docs/agents.md +83 -0
  24. package/docs/architecture.md +34 -0
  25. package/docs/plugins.md +77 -0
  26. package/logo-black.png +0 -0
  27. package/{dist/assets/logo.js → logo-black.svg} +24 -24
  28. package/{dist/ui/sidebar.js → logo-white.svg} +23 -88
  29. package/package.json +6 -5
  30. package/src/agents/system.ts +112 -0
  31. package/src/app/cli.ts +38 -0
  32. package/src/app/config.ts +104 -0
  33. package/src/app/server.ts +284 -0
  34. package/src/app/types.ts +476 -0
  35. package/src/app/utils.ts +43 -0
  36. package/src/assets/icon.svg +1 -0
  37. package/src/harness/agent-harness.ts +58 -0
  38. package/src/harness/mcp.ts +78 -0
  39. package/src/harness/orchestrator.ts +342 -0
  40. package/src/harness/process.ts +9 -0
  41. package/src/harness/types.ts +34 -0
  42. package/src/plugins/ai-sdk.ts +197 -0
  43. package/src/plugins/delegation.ts +60 -0
  44. package/src/plugins/mcp.ts +154 -0
  45. package/src/plugins/storage.ts +725 -0
  46. package/src/plugins/ui.ts +57 -0
  47. package/src/registry/plugins.ts +85 -0
  48. package/src/services/storage.ts +957 -0
  49. package/tsconfig.json +18 -0
  50. package/dist/agents/agent-creator.js +0 -74
  51. package/dist/agents/browser-agent.js +0 -31
  52. package/dist/agents/os-agent.js +0 -32
  53. package/dist/agents/planner-agent.js +0 -32
  54. package/dist/agents/topic-agent.js +0 -46
  55. package/dist/architecture/execution-engine.js +0 -151
  56. package/dist/architecture/intent-classifier.js +0 -26
  57. package/dist/architecture/planner.js +0 -106
  58. package/dist/automation-worker.js +0 -121
  59. package/dist/automations.js +0 -52
  60. package/dist/cli.js +0 -279
  61. package/dist/config.js +0 -53
  62. package/dist/core/agents.js +0 -41
  63. package/dist/core/delegation.js +0 -230
  64. package/dist/core/manager.js +0 -96
  65. package/dist/core/plugins.js +0 -74
  66. package/dist/core/router.js +0 -191
  67. package/dist/handlers/init.js +0 -29
  68. package/dist/handlers/session-change.js +0 -21
  69. package/dist/handlers/settings.js +0 -47
  70. package/dist/handlers/tab-change.js +0 -14
  71. package/dist/installers.js +0 -156
  72. package/dist/marketplace.js +0 -80
  73. package/dist/model-catalog.js +0 -132
  74. package/dist/model-defaults.js +0 -25
  75. package/dist/models.js +0 -47
  76. package/dist/open-bot.js +0 -51
  77. package/dist/orchestrator/direct-invocation.js +0 -13
  78. package/dist/orchestrator/events.js +0 -36
  79. package/dist/orchestrator/state.js +0 -54
  80. package/dist/orchestrator.js +0 -422
  81. package/dist/plugins/agent/index.js +0 -81
  82. package/dist/plugins/approval/index.js +0 -100
  83. package/dist/plugins/brain/identity.js +0 -77
  84. package/dist/plugins/brain/index.js +0 -204
  85. package/dist/plugins/brain/memory.js +0 -120
  86. package/dist/plugins/brain/prompt.js +0 -46
  87. package/dist/plugins/brain/types.js +0 -45
  88. package/dist/plugins/brain/ui.js +0 -7
  89. package/dist/plugins/browser/index.js +0 -629
  90. package/dist/plugins/browser/ui.js +0 -13
  91. package/dist/plugins/file-system/index.js +0 -171
  92. package/dist/plugins/file-system/ui.js +0 -6
  93. package/dist/plugins/llm/context-budget.js +0 -139
  94. package/dist/plugins/llm/context-shaping.js +0 -177
  95. package/dist/plugins/llm/index.js +0 -380
  96. package/dist/plugins/memory/index.js +0 -220
  97. package/dist/plugins/memory/memory.js +0 -122
  98. package/dist/plugins/memory/prompt.js +0 -55
  99. package/dist/plugins/memory/types.js +0 -45
  100. package/dist/plugins/meta-agent/index.js +0 -570
  101. package/dist/plugins/meta-agent/ui.js +0 -11
  102. package/dist/plugins/shell/index.js +0 -100
  103. package/dist/plugins/shell/ui.js +0 -6
  104. package/dist/plugins/skills/index.js +0 -286
  105. package/dist/plugins/skills/types.js +0 -50
  106. package/dist/plugins/skills/ui.js +0 -12
  107. package/dist/registry/agent-registry.js +0 -35
  108. package/dist/registry/index.js +0 -2
  109. package/dist/registry/plugin-loader.js +0 -499
  110. package/dist/registry/plugin-registry.js +0 -44
  111. package/dist/registry/ts-agent-loader.js +0 -82
  112. package/dist/registry/yaml-agent-loader.js +0 -246
  113. package/dist/runtime/execution-trace.js +0 -41
  114. package/dist/runtime/intent-routing.js +0 -26
  115. package/dist/runtime/openbot-runtime.js +0 -354
  116. package/dist/server.js +0 -890
  117. package/dist/session.js +0 -179
  118. package/dist/ui/block.js +0 -12
  119. package/dist/ui/header.js +0 -52
  120. package/dist/ui/layout.js +0 -26
  121. package/dist/ui/navigation.js +0 -15
  122. package/dist/ui/settings.js +0 -106
  123. package/dist/ui/skills.js +0 -7
  124. package/dist/ui/thread.js +0 -16
  125. package/dist/ui/widgets/action-list.js +0 -2
  126. package/dist/ui/widgets/approval-card.js +0 -9
  127. package/dist/ui/widgets/code-snippet.js +0 -2
  128. package/dist/ui/widgets/data-block.js +0 -2
  129. package/dist/ui/widgets/data-table.js +0 -2
  130. package/dist/ui/widgets/delegation.js +0 -29
  131. package/dist/ui/widgets/empty-state.js +0 -2
  132. package/dist/ui/widgets/index.js +0 -23
  133. package/dist/ui/widgets/inquiry.js +0 -7
  134. package/dist/ui/widgets/key-value.js +0 -2
  135. package/dist/ui/widgets/progress-step.js +0 -2
  136. package/dist/ui/widgets/resource-card.js +0 -2
  137. package/dist/ui/widgets/status.js +0 -2
  138. package/dist/ui/widgets/todo-list.js +0 -2
  139. package/dist/version.js +0 -62
  140. /package/dist/{types.js → app/types.js} +0 -0
  141. /package/dist/{architecture/contracts.js → harness/types.js} +0 -0
@@ -0,0 +1,502 @@
1
+ import { storageService } from '../services/storage.js';
2
+ import z from 'zod';
3
+ export const storageToolDefinitions = {
4
+ create_channel: {
5
+ description: 'Create a new channel. Use this when you think the user intent is completelly different from the current channel and should be split into multiple channels. Before creating, always notify with details and ask for confirmation. If user asks basic questions, no need to create a channel.',
6
+ inputSchema: z.object({
7
+ channelId: z
8
+ .string()
9
+ .describe('Unique channel ID. Example: product-launch, backend-platform, or channel_roadmap.'),
10
+ spec: z
11
+ .string()
12
+ .optional()
13
+ .describe('Optional initial markdown content for the channel spec.'),
14
+ initialState: z
15
+ .record(z.string(), z.unknown())
16
+ .optional()
17
+ .describe('Optional initial state object for the channel.'),
18
+ cwd: z
19
+ .string()
20
+ .optional()
21
+ .describe('Optional initial current working directory for the channel.'),
22
+ }),
23
+ },
24
+ patch_channel_details: {
25
+ description: 'Patch current channel details (state and/or spec).',
26
+ inputSchema: z
27
+ .object({
28
+ state: z
29
+ .record(z.string(), z.unknown())
30
+ .optional()
31
+ .describe('JSON state object for the channel. Use this for structured data like `todos` or metadata.'),
32
+ spec: z
33
+ .string()
34
+ .optional()
35
+ .describe('Markdown content for the channel specification (SPEC.md). Use this for goals and rules.'),
36
+ cwd: z.string().optional().describe('Current working directory for the channel.'),
37
+ })
38
+ .refine((value) => value.state !== undefined || value.spec !== undefined || value.cwd !== undefined, {
39
+ message: 'Provide at least one of state, spec, or cwd.',
40
+ }),
41
+ },
42
+ patch_thread_details: {
43
+ description: 'Patch current thread details (state and/or spec).',
44
+ inputSchema: z
45
+ .object({
46
+ state: z
47
+ .record(z.string(), z.unknown())
48
+ .optional()
49
+ .describe('JSON state object for the thread. Use this for structured data like `todos` or progress tracking.'),
50
+ spec: z
51
+ .string()
52
+ .optional()
53
+ .describe('Markdown content for the thread specification (SPEC.md). Use this for detailed plans and goals.'),
54
+ })
55
+ .refine((value) => value.state !== undefined || value.spec !== undefined, {
56
+ message: 'Provide at least one of state or spec.',
57
+ }),
58
+ },
59
+ };
60
+ export const storagePlugin = (options) => (builder) => {
61
+ const { storage } = options;
62
+ builder.on('action:create_thread', async function* (event, context) {
63
+ // We take threadId from meta so the next agent:invoke event will reply in the same thread.
64
+ const threadId = event.meta?.threadId;
65
+ const channelId = context.state.channelId;
66
+ const { threadTitle, spec, initialState } = event.data;
67
+ if (!threadId) {
68
+ console.warn('[storage] Cannot create thread: meta.threadId is missing');
69
+ return;
70
+ }
71
+ // Override threadId in state to keep subsequent replies in the same thread.
72
+ context.state.threadId = threadId;
73
+ if (channelId) {
74
+ try {
75
+ await storage.createThread({
76
+ channelId,
77
+ threadId,
78
+ threadTitle,
79
+ spec,
80
+ initialState: initialState || {},
81
+ });
82
+ context.state.threadDetails = await storage.getThreadDetails({
83
+ channelId,
84
+ threadId,
85
+ });
86
+ }
87
+ catch (error) {
88
+ console.warn(`[storage] Failed to initialize thread for channel ${channelId} thread ${threadId}`, error);
89
+ }
90
+ }
91
+ yield {
92
+ type: 'action:create_thread:result',
93
+ data: {
94
+ success: true,
95
+ threadId,
96
+ threadTitle,
97
+ },
98
+ meta: {
99
+ threadId,
100
+ },
101
+ };
102
+ });
103
+ builder.on('action:create_channel', async function* (event, context) {
104
+ const { channelId, spec, initialState, cwd } = event.data;
105
+ const rawChannelId = (channelId || '').trim();
106
+ const channelSpec = typeof spec === 'string' ? spec : '';
107
+ if (!rawChannelId) {
108
+ yield {
109
+ type: 'action:create_channel:result',
110
+ data: {
111
+ success: false,
112
+ channelId: '',
113
+ channelUrl: '',
114
+ },
115
+ };
116
+ return;
117
+ }
118
+ const channelUrl = `/channels/${rawChannelId}`;
119
+ try {
120
+ await storage.createChannel({
121
+ channelId: rawChannelId,
122
+ spec: channelSpec,
123
+ initialState: initialState,
124
+ cwd,
125
+ });
126
+ yield {
127
+ type: 'action:create_channel:result',
128
+ data: {
129
+ success: true,
130
+ channelId: rawChannelId,
131
+ channelUrl,
132
+ },
133
+ };
134
+ yield {
135
+ type: 'agent:output',
136
+ data: {
137
+ content: `Created channel \`${rawChannelId}\`.`,
138
+ },
139
+ meta: {
140
+ ...(event.meta || {}),
141
+ agentId: context.state.agentId,
142
+ },
143
+ };
144
+ }
145
+ catch {
146
+ yield {
147
+ type: 'action:create_channel:result',
148
+ data: {
149
+ success: false,
150
+ channelId: rawChannelId,
151
+ channelUrl,
152
+ },
153
+ };
154
+ }
155
+ });
156
+ builder.on('action:storage:get-channels', async function* () {
157
+ const channels = await storage.getChannels();
158
+ yield {
159
+ type: 'action:storage:get-channels-result',
160
+ data: { channels },
161
+ };
162
+ });
163
+ builder.on('action:storage:get-threads', async function* (event) {
164
+ const threads = await storage.getThreads({ channelId: event.data.channelId });
165
+ yield {
166
+ type: 'action:storage:get-threads-result',
167
+ data: { threads },
168
+ };
169
+ });
170
+ builder.on('action:storage:get-channel-details', async function* (_, state) {
171
+ const channelDetails = await storage.getChannelDetails({ channelId: state.state.channelId });
172
+ yield {
173
+ type: 'action:storage:get-channel-details-result',
174
+ data: { channelDetails },
175
+ };
176
+ });
177
+ builder.on('action:storage:get-agents', async function* () {
178
+ const agents = await storage.getAgents();
179
+ yield {
180
+ type: 'action:storage:get-agents-result',
181
+ data: { agents },
182
+ };
183
+ });
184
+ builder.on('action:storage:get-plugins', async function* () {
185
+ const plugins = await storage.getPlugins();
186
+ yield {
187
+ type: 'action:storage:get-plugins-result',
188
+ data: { plugins },
189
+ };
190
+ });
191
+ builder.on('action:storage:get-agent-details', async function* (event, state) {
192
+ const agentDetails = await storage.getAgentDetails({ agentId: event.data.agentId });
193
+ yield {
194
+ type: 'action:storage:get-agent-details-result',
195
+ data: { agentDetails },
196
+ };
197
+ });
198
+ builder.on('action:storage:get-events', async function* (_, state) {
199
+ const events = await storage.getEvents(state.state);
200
+ // Simple: fetching main channel events marks it as read
201
+ if (!state.state.threadId && events.length > 0) {
202
+ const lastId = events[events.length - 1]?.id;
203
+ if (lastId) {
204
+ // We call storageService directly as it's an internal helper now
205
+ await storageService.setLastReadForChannel({
206
+ channelId: state.state.channelId,
207
+ lastReadEventId: lastId,
208
+ });
209
+ }
210
+ }
211
+ yield {
212
+ type: 'action:storage:get-events-result',
213
+ data: { events },
214
+ };
215
+ });
216
+ builder.on('action:storage:get-variables', async function* () {
217
+ const variables = await storage.getVariables();
218
+ const maskedVariables = {};
219
+ for (const [key, val] of Object.entries(variables)) {
220
+ if (typeof val === 'object' && val !== null && val.secret) {
221
+ maskedVariables[key] = '********';
222
+ }
223
+ else {
224
+ maskedVariables[key] = typeof val === 'string' ? val : val.value;
225
+ }
226
+ }
227
+ yield {
228
+ type: 'action:storage:get-variables-result',
229
+ data: { variables: maskedVariables },
230
+ };
231
+ });
232
+ builder.on('action:storage:patch-channel-state', async function* (event, state) {
233
+ try {
234
+ await storage.patchChannelState({
235
+ channelId: state.state.channelId,
236
+ state: event.data.state,
237
+ });
238
+ yield {
239
+ type: 'action:storage:patch-channel-state-result',
240
+ data: { success: true },
241
+ };
242
+ }
243
+ catch (error) {
244
+ yield {
245
+ type: 'action:storage:patch-channel-state-result',
246
+ data: { success: false },
247
+ };
248
+ }
249
+ });
250
+ builder.on('action:storage:patch-thread-state', async function* (event, state) {
251
+ try {
252
+ if (!state.state.threadId) {
253
+ throw new Error('Missing threadId in state for patch-thread-state');
254
+ }
255
+ await storage.patchThreadState({
256
+ channelId: state.state.channelId,
257
+ threadId: state.state.threadId,
258
+ state: event.data.state,
259
+ });
260
+ yield {
261
+ type: 'action:storage:patch-thread-state-result',
262
+ data: { success: true },
263
+ };
264
+ }
265
+ catch (error) {
266
+ yield {
267
+ type: 'action:storage:patch-thread-state-result',
268
+ data: { success: false },
269
+ };
270
+ }
271
+ });
272
+ builder.on('action:patch_channel_details', async function* (event, context) {
273
+ const updatedFields = [];
274
+ try {
275
+ if (event.data.state !== undefined) {
276
+ await storage.patchChannelState({
277
+ channelId: context.state.channelId,
278
+ state: event.data.state,
279
+ });
280
+ updatedFields.push('state');
281
+ }
282
+ if (typeof event.data.spec === 'string') {
283
+ await storage.patchChannelSpec({
284
+ channelId: context.state.channelId,
285
+ spec: event.data.spec,
286
+ });
287
+ updatedFields.push('spec');
288
+ }
289
+ if (typeof event.data.cwd === 'string') {
290
+ await storage.patchChannelState({
291
+ channelId: context.state.channelId,
292
+ state: { cwd: event.data.cwd },
293
+ });
294
+ updatedFields.push('cwd');
295
+ }
296
+ context.state.channelDetails = await storage.getChannelDetails({
297
+ channelId: context.state.channelId,
298
+ });
299
+ yield {
300
+ type: 'action:patch_channel_details:result',
301
+ data: {
302
+ success: true,
303
+ updatedFields,
304
+ },
305
+ };
306
+ }
307
+ catch (error) {
308
+ yield {
309
+ type: 'action:patch_channel_details:result',
310
+ data: {
311
+ success: false,
312
+ updatedFields,
313
+ },
314
+ };
315
+ }
316
+ });
317
+ // Backward-compatible event used by external frontends.
318
+ builder.on('action:update_channel', async function* (event, context) {
319
+ const data = (event.data || {});
320
+ const targetChannelId = (data.channelId || context.state.channelId || '').trim();
321
+ if (!targetChannelId) {
322
+ yield {
323
+ type: 'action:update_channel:result',
324
+ data: {
325
+ success: false,
326
+ channelId: '',
327
+ updatedFields: [],
328
+ },
329
+ };
330
+ return;
331
+ }
332
+ const patch = {};
333
+ const updatedFields = [];
334
+ if (typeof data.name === 'string' && data.name.trim()) {
335
+ patch.name = data.name.trim();
336
+ updatedFields.push('name');
337
+ }
338
+ if (typeof data.cwd === 'string' && data.cwd.trim()) {
339
+ patch.cwd = data.cwd.trim();
340
+ updatedFields.push('cwd');
341
+ }
342
+ try {
343
+ if (updatedFields.length > 0) {
344
+ await storage.patchChannelState({
345
+ channelId: targetChannelId,
346
+ state: patch,
347
+ });
348
+ }
349
+ if (targetChannelId === context.state.channelId) {
350
+ context.state.channelDetails = await storage.getChannelDetails({
351
+ channelId: context.state.channelId,
352
+ });
353
+ }
354
+ yield {
355
+ type: 'action:update_channel:result',
356
+ data: {
357
+ success: true,
358
+ channelId: targetChannelId,
359
+ updatedFields,
360
+ },
361
+ };
362
+ }
363
+ catch {
364
+ yield {
365
+ type: 'action:update_channel:result',
366
+ data: {
367
+ success: false,
368
+ channelId: targetChannelId,
369
+ updatedFields,
370
+ },
371
+ };
372
+ }
373
+ });
374
+ builder.on('action:patch_thread_details', async function* (event, context) {
375
+ const updatedFields = [];
376
+ try {
377
+ if (!context.state.threadId) {
378
+ throw new Error('Missing threadId in state for patch_thread_details');
379
+ }
380
+ if (event.data.state !== undefined) {
381
+ await storage.patchThreadState({
382
+ channelId: context.state.channelId,
383
+ threadId: context.state.threadId,
384
+ state: event.data.state,
385
+ });
386
+ updatedFields.push('state');
387
+ }
388
+ if (typeof event.data.spec === 'string') {
389
+ await storage.patchThreadSpec({
390
+ channelId: context.state.channelId,
391
+ threadId: context.state.threadId,
392
+ spec: event.data.spec,
393
+ });
394
+ updatedFields.push('spec');
395
+ }
396
+ context.state.threadDetails = await storage.getThreadDetails({
397
+ channelId: context.state.channelId,
398
+ threadId: context.state.threadId,
399
+ });
400
+ yield {
401
+ type: 'action:patch_thread_details:result',
402
+ data: {
403
+ success: true,
404
+ updatedFields,
405
+ },
406
+ };
407
+ yield {
408
+ type: 'agent:output',
409
+ data: {
410
+ content: `Thread details updated: ${updatedFields.join(', ')}`,
411
+ },
412
+ meta: {
413
+ agentId: context.state.agentId,
414
+ },
415
+ };
416
+ }
417
+ catch (error) {
418
+ yield {
419
+ type: 'action:patch_thread_details:result',
420
+ data: {
421
+ success: false,
422
+ updatedFields,
423
+ },
424
+ };
425
+ yield {
426
+ type: 'agent:output',
427
+ data: {
428
+ content: `Failed to update thread details: ${error instanceof Error ? error.message : 'Unknown error'}`,
429
+ },
430
+ meta: {
431
+ agentId: context.state.agentId,
432
+ },
433
+ };
434
+ }
435
+ });
436
+ builder.on('action:storage:list-files', async function* (event, context) {
437
+ const channelId = context.state.channelId;
438
+ const subPath = event.data?.path || '';
439
+ try {
440
+ const files = await storage.listFiles({ channelId, path: subPath });
441
+ yield {
442
+ type: 'action:storage:list-files:result',
443
+ data: {
444
+ success: true,
445
+ files,
446
+ },
447
+ };
448
+ }
449
+ catch (error) {
450
+ yield {
451
+ type: 'action:storage:list-files:result',
452
+ data: {
453
+ success: false,
454
+ files: [],
455
+ error: error instanceof Error ? error.message : 'Unknown error',
456
+ },
457
+ };
458
+ }
459
+ });
460
+ builder.on('action:storage:read-file', async function* (event, context) {
461
+ const channelId = context.state.channelId;
462
+ const filePath = event.data?.path;
463
+ if (!filePath) {
464
+ yield {
465
+ type: 'action:storage:read-file:result',
466
+ data: {
467
+ success: false,
468
+ path: '',
469
+ error: 'Path is required',
470
+ },
471
+ };
472
+ return;
473
+ }
474
+ try {
475
+ const content = await storage.readFile({ channelId, path: filePath });
476
+ yield {
477
+ type: 'action:storage:read-file:result',
478
+ data: {
479
+ success: true,
480
+ content,
481
+ path: filePath,
482
+ },
483
+ };
484
+ }
485
+ catch (error) {
486
+ yield {
487
+ type: 'action:storage:read-file:result',
488
+ data: {
489
+ success: false,
490
+ path: filePath,
491
+ error: error instanceof Error ? error.message : 'Unknown error',
492
+ },
493
+ };
494
+ }
495
+ });
496
+ };
497
+ export const plugin = {
498
+ name: 'storage',
499
+ description: 'Built-in storage plugin',
500
+ factory: storagePlugin,
501
+ toolDefinitions: storageToolDefinitions,
502
+ };
@@ -0,0 +1,47 @@
1
+ import z from 'zod';
2
+ /**
3
+ * UI Plugin for Melony.
4
+ * Provides tools for agents to trigger interactive UI widgets.
5
+ */
6
+ export const uiPlugin = () => (builder) => {
7
+ builder.on('action:render_ui_widget', async function* (event, context) {
8
+ const { kind, title, props } = event.data;
9
+ const finalProps = { ...props };
10
+ // Auto-inject todos if it's a todo_list and they aren't provided
11
+ if (kind === 'todo_list' && !finalProps.todos) {
12
+ finalProps.todos = context.state.threadDetails?.state?.todos || [];
13
+ }
14
+ yield {
15
+ type: 'client:ui:widget',
16
+ data: {
17
+ widgetId: `${kind}_${Date.now()}`,
18
+ kind,
19
+ title: title || (kind === 'approval' ? 'Approval Required' : kind === 'todo_list' ? 'Task List' : 'Details Required'),
20
+ props: finalProps,
21
+ },
22
+ meta: event.meta,
23
+ };
24
+ });
25
+ };
26
+ export const uiToolDefinitions = {
27
+ render_ui_widget: {
28
+ description: 'Render an interactive UI widget (approval, todo_list, or form) in the conversation.',
29
+ inputSchema: z.object({
30
+ kind: z.enum(['approval', 'todo_list', 'form']).describe('The type of widget to render.'),
31
+ title: z.string().optional().describe('Optional title for the widget.'),
32
+ props: z.record(z.string(), z.unknown()).describe('Properties for the widget. \n' +
33
+ '- For "approval": { message: string, actionId: string }\n' +
34
+ '- For "todo_list": { title?: string } (Note: current thread todos are auto-injected if not provided)\n' +
35
+ '- For "form": { schema: Array<{ id, label, type, options?, required? }>, submitLabel?: string }'),
36
+ }),
37
+ },
38
+ };
39
+ export const plugin = {
40
+ name: 'ui',
41
+ description: 'UI Widgets plugin',
42
+ version: '1.0.0',
43
+ author: 'OpenBot',
44
+ license: 'MIT',
45
+ factory: uiPlugin,
46
+ toolDefinitions: uiToolDefinitions,
47
+ };
@@ -0,0 +1,73 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { aiSdkPlugin } from '../plugins/ai-sdk.js';
5
+ import { storagePlugin } from '../plugins/storage.js';
6
+ import { storageService } from '../services/storage.js';
7
+ import { DEFAULT_BASE_DIR, loadConfig, resolvePath } from '../app/config.js';
8
+ import { delegationPlugin } from '../plugins/delegation.js';
9
+ import { mcpPlugin } from '../plugins/mcp.js';
10
+ import { uiPlugin } from '../plugins/ui.js';
11
+ let pluginsDir = null;
12
+ const loadedPlugins = new Set();
13
+ /**
14
+ * Initializes the plugins directory.
15
+ */
16
+ export function initPlugins(dir) {
17
+ if (dir) {
18
+ pluginsDir = dir;
19
+ }
20
+ else {
21
+ const config = loadConfig();
22
+ const baseDir = config.baseDir || DEFAULT_BASE_DIR;
23
+ pluginsDir = path.join(resolvePath(baseDir), 'plugins');
24
+ }
25
+ }
26
+ /**
27
+ * Resolves a plugin from its name and config.
28
+ */
29
+ export async function resolvePlugin(pluginName, config = {}) {
30
+ // 1. Built-in plugins
31
+ switch (pluginName) {
32
+ case 'storage':
33
+ return storagePlugin({ storage: storageService, ...config });
34
+ case 'ai-sdk':
35
+ return aiSdkPlugin({
36
+ storage: storageService,
37
+ ...config,
38
+ });
39
+ case 'delegation':
40
+ return delegationPlugin();
41
+ case 'mcp':
42
+ return mcpPlugin();
43
+ case 'ui':
44
+ return uiPlugin();
45
+ }
46
+ // 2. Search for external plugins in the initialized plugins directory
47
+ if (!pluginsDir) {
48
+ initPlugins();
49
+ }
50
+ if (pluginsDir) {
51
+ const pluginDir = path.resolve(pluginsDir, pluginName);
52
+ const distPath = path.join(pluginDir, 'dist', 'index.js');
53
+ if (fs.existsSync(distPath)) {
54
+ try {
55
+ // Dynamic import needs file:// URL for absolute paths
56
+ const module = await import(pathToFileURL(distPath).href);
57
+ const factory = module.plugin.factory;
58
+ if (typeof factory === 'function') {
59
+ if (!loadedPlugins.has(pluginName)) {
60
+ console.log(`[plugins] Loaded community plugin "${pluginName}" from ${distPath}`);
61
+ loadedPlugins.add(pluginName);
62
+ }
63
+ return factory(config);
64
+ }
65
+ }
66
+ catch (e) {
67
+ console.warn(`[plugins] Failed to load plugin "${pluginName}" from ${distPath}:`, e);
68
+ }
69
+ }
70
+ }
71
+ console.warn(`[plugins] Plugin "${pluginName}" not found in registry or external directory.`);
72
+ return null;
73
+ }