@clinebot/core 0.0.36 → 0.0.37

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 (228) hide show
  1. package/dist/ClineCore.d.ts +312 -3
  2. package/dist/ClineCore.d.ts.map +1 -1
  3. package/dist/account/cline-account-service.d.ts.map +1 -1
  4. package/dist/cron/cron-event-ingress.d.ts +38 -0
  5. package/dist/cron/cron-event-ingress.d.ts.map +1 -0
  6. package/dist/cron/cron-materializer.d.ts +36 -0
  7. package/dist/cron/cron-materializer.d.ts.map +1 -0
  8. package/dist/cron/cron-reconciler.d.ts +62 -0
  9. package/dist/cron/cron-reconciler.d.ts.map +1 -0
  10. package/dist/cron/cron-report-writer.d.ts +41 -0
  11. package/dist/cron/cron-report-writer.d.ts.map +1 -0
  12. package/dist/cron/cron-runner.d.ts +43 -0
  13. package/dist/cron/cron-runner.d.ts.map +1 -0
  14. package/dist/cron/cron-schema.d.ts +3 -0
  15. package/dist/cron/cron-schema.d.ts.map +1 -0
  16. package/dist/cron/cron-service.d.ts +57 -0
  17. package/dist/cron/cron-service.d.ts.map +1 -0
  18. package/dist/cron/cron-spec-parser.d.ts +27 -0
  19. package/dist/cron/cron-spec-parser.d.ts.map +1 -0
  20. package/dist/cron/cron-watcher.d.ts +23 -0
  21. package/dist/cron/cron-watcher.d.ts.map +1 -0
  22. package/dist/cron/scheduler.d.ts +3 -1
  23. package/dist/cron/scheduler.d.ts.map +1 -1
  24. package/dist/cron/sqlite-cron-store.d.ts +230 -0
  25. package/dist/cron/sqlite-cron-store.d.ts.map +1 -0
  26. package/dist/extensions/plugin/plugin-config-loader.d.ts +7 -1
  27. package/dist/extensions/plugin/plugin-config-loader.d.ts.map +1 -1
  28. package/dist/extensions/plugin/plugin-loader.d.ts +10 -6
  29. package/dist/extensions/plugin/plugin-loader.d.ts.map +1 -1
  30. package/dist/extensions/plugin/plugin-sandbox.d.ts +7 -1
  31. package/dist/extensions/plugin/plugin-sandbox.d.ts.map +1 -1
  32. package/dist/extensions/plugin-sandbox-bootstrap.js +236 -275
  33. package/dist/extensions/tools/constants.d.ts +1 -0
  34. package/dist/extensions/tools/constants.d.ts.map +1 -1
  35. package/dist/extensions/tools/definitions.d.ts +2 -3
  36. package/dist/extensions/tools/definitions.d.ts.map +1 -1
  37. package/dist/extensions/tools/executors/editor.d.ts.map +1 -1
  38. package/dist/extensions/tools/helpers.d.ts +1 -0
  39. package/dist/extensions/tools/helpers.d.ts.map +1 -1
  40. package/dist/extensions/tools/index.d.ts +1 -2
  41. package/dist/extensions/tools/index.d.ts.map +1 -1
  42. package/dist/extensions/tools/presets.d.ts +1 -1
  43. package/dist/extensions/tools/schemas.d.ts +25 -3
  44. package/dist/extensions/tools/schemas.d.ts.map +1 -1
  45. package/dist/extensions/tools/team/delegated-agent.d.ts +2 -2
  46. package/dist/extensions/tools/team/delegated-agent.d.ts.map +1 -1
  47. package/dist/extensions/tools/team/multi-agent.d.ts +7 -3
  48. package/dist/extensions/tools/team/multi-agent.d.ts.map +1 -1
  49. package/dist/extensions/tools/team/team-tools.d.ts.map +1 -1
  50. package/dist/extensions/tools/types.d.ts +0 -5
  51. package/dist/extensions/tools/types.d.ts.map +1 -1
  52. package/dist/hooks/hook-bridge.d.ts +118 -0
  53. package/dist/hooks/hook-bridge.d.ts.map +1 -0
  54. package/dist/hooks/hook-file-hooks.d.ts +2 -1
  55. package/dist/hooks/hook-file-hooks.d.ts.map +1 -1
  56. package/dist/hooks/hook-registry.d.ts +16 -0
  57. package/dist/hooks/hook-registry.d.ts.map +1 -0
  58. package/dist/hub/browser-websocket.d.ts.map +1 -1
  59. package/dist/hub/client.d.ts +7 -1
  60. package/dist/hub/client.d.ts.map +1 -1
  61. package/dist/hub/daemon-entry.js +721 -461
  62. package/dist/hub/daemon.d.ts.map +1 -1
  63. package/dist/hub/defaults.d.ts +8 -4
  64. package/dist/hub/defaults.d.ts.map +1 -1
  65. package/dist/hub/index.js +665 -415
  66. package/dist/hub/runtime-handlers.d.ts.map +1 -1
  67. package/dist/hub/server.d.ts +18 -0
  68. package/dist/hub/server.d.ts.map +1 -1
  69. package/dist/hub/session-client.d.ts +3 -0
  70. package/dist/hub/session-client.d.ts.map +1 -1
  71. package/dist/hub/start-shared-server.d.ts.map +1 -1
  72. package/dist/hub/ui-client.d.ts +1 -0
  73. package/dist/hub/ui-client.d.ts.map +1 -1
  74. package/dist/index.d.ts +9 -7
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +756 -467
  77. package/dist/llms/cline-recommended-models.d.ts +20 -0
  78. package/dist/llms/cline-recommended-models.d.ts.map +1 -0
  79. package/dist/llms/handler-factory.d.ts +16 -0
  80. package/dist/llms/handler-factory.d.ts.map +1 -0
  81. package/dist/llms/provider-defaults.d.ts.map +1 -1
  82. package/dist/llms/provider-settings.d.ts +45 -2
  83. package/dist/llms/provider-settings.d.ts.map +1 -1
  84. package/dist/llms/runtime-registry.d.ts.map +1 -1
  85. package/dist/runtime/agent-config-adapter.d.ts +148 -0
  86. package/dist/runtime/agent-config-adapter.d.ts.map +1 -0
  87. package/dist/runtime/agent-runtime-config-builder.d.ts +96 -0
  88. package/dist/runtime/agent-runtime-config-builder.d.ts.map +1 -0
  89. package/dist/runtime/history.d.ts +6 -0
  90. package/dist/runtime/history.d.ts.map +1 -1
  91. package/dist/runtime/host.d.ts.map +1 -1
  92. package/dist/runtime/loop-detection.d.ts +59 -0
  93. package/dist/runtime/loop-detection.d.ts.map +1 -0
  94. package/dist/runtime/mistake-tracker.d.ts +69 -0
  95. package/dist/runtime/mistake-tracker.d.ts.map +1 -0
  96. package/dist/runtime/runtime-builder.d.ts.map +1 -1
  97. package/dist/runtime/runtime-event-adapter.d.ts +102 -0
  98. package/dist/runtime/runtime-event-adapter.d.ts.map +1 -0
  99. package/dist/runtime/runtime-host.d.ts +28 -3
  100. package/dist/runtime/runtime-host.d.ts.map +1 -1
  101. package/dist/runtime/session-runtime-orchestrator.d.ts +261 -0
  102. package/dist/runtime/session-runtime-orchestrator.d.ts.map +1 -0
  103. package/dist/runtime/session-runtime.d.ts +16 -3
  104. package/dist/runtime/session-runtime.d.ts.map +1 -1
  105. package/dist/runtime/user-input-builder.d.ts +24 -0
  106. package/dist/runtime/user-input-builder.d.ts.map +1 -0
  107. package/dist/services/index.js +28 -0
  108. package/dist/services/local-runtime-bootstrap.d.ts.map +1 -1
  109. package/dist/services/plugin-tools.d.ts.map +1 -1
  110. package/dist/services/providers/local-provider-registry.d.ts +197 -21
  111. package/dist/services/providers/local-provider-registry.d.ts.map +1 -1
  112. package/dist/services/providers/local-provider-service.d.ts +3 -1
  113. package/dist/services/providers/local-provider-service.d.ts.map +1 -1
  114. package/dist/services/session-data.d.ts.map +1 -1
  115. package/dist/services/session-telemetry.d.ts +7 -2
  116. package/dist/services/session-telemetry.d.ts.map +1 -1
  117. package/dist/services/storage/file-team-store.d.ts.map +1 -1
  118. package/dist/services/storage/provider-settings-legacy-migration.d.ts.map +1 -1
  119. package/dist/services/storage/provider-settings-manager.d.ts +1 -0
  120. package/dist/services/storage/provider-settings-manager.d.ts.map +1 -1
  121. package/dist/services/storage/sqlite-team-store.d.ts.map +1 -1
  122. package/dist/session/conversation-store.d.ts +30 -0
  123. package/dist/session/conversation-store.d.ts.map +1 -0
  124. package/dist/session/message-builder.d.ts +65 -0
  125. package/dist/session/message-builder.d.ts.map +1 -0
  126. package/dist/session/session-manifest.d.ts +1 -1
  127. package/dist/transports/hub.d.ts +14 -3
  128. package/dist/transports/hub.d.ts.map +1 -1
  129. package/dist/transports/local.d.ts +14 -4
  130. package/dist/transports/local.d.ts.map +1 -1
  131. package/dist/transports/remote.d.ts.map +1 -1
  132. package/dist/types/chat-schema.d.ts +5 -5
  133. package/dist/types/config.d.ts +9 -0
  134. package/dist/types/config.d.ts.map +1 -1
  135. package/dist/types/events.d.ts +7 -6
  136. package/dist/types/events.d.ts.map +1 -1
  137. package/dist/types/provider-settings.d.ts +2 -2
  138. package/dist/types/provider-settings.d.ts.map +1 -1
  139. package/dist/types/session.d.ts +5 -2
  140. package/dist/types/session.d.ts.map +1 -1
  141. package/dist/types.d.ts +4 -4
  142. package/dist/types.d.ts.map +1 -1
  143. package/package.json +4 -4
  144. package/src/ClineCore.ts +691 -6
  145. package/src/account/cline-account-service.ts +44 -6
  146. package/src/cron/cron-event-ingress.ts +357 -0
  147. package/src/cron/cron-materializer.ts +97 -0
  148. package/src/cron/cron-reconciler.ts +241 -0
  149. package/src/cron/cron-report-writer.ts +153 -0
  150. package/src/cron/cron-runner.ts +495 -0
  151. package/src/cron/cron-schema.ts +127 -0
  152. package/src/cron/cron-service.ts +163 -0
  153. package/src/cron/cron-spec-parser.ts +489 -0
  154. package/src/cron/cron-watcher.ts +102 -0
  155. package/src/cron/index.ts +10 -0
  156. package/src/cron/scheduler.ts +141 -6
  157. package/src/cron/sqlite-cron-store.ts +1286 -0
  158. package/src/extensions/plugin/plugin-config-loader.ts +21 -1
  159. package/src/extensions/plugin/plugin-loader.ts +25 -9
  160. package/src/extensions/plugin/plugin-sandbox-bootstrap.ts +151 -1
  161. package/src/extensions/plugin/plugin-sandbox.ts +131 -7
  162. package/src/extensions/tools/constants.ts +2 -0
  163. package/src/extensions/tools/definitions.ts +31 -22
  164. package/src/extensions/tools/executors/editor.ts +4 -3
  165. package/src/extensions/tools/helpers.ts +24 -0
  166. package/src/extensions/tools/index.ts +1 -2
  167. package/src/extensions/tools/presets.ts +1 -1
  168. package/src/extensions/tools/schemas.ts +13 -18
  169. package/src/extensions/tools/team/delegated-agent.ts +8 -3
  170. package/src/extensions/tools/team/multi-agent.ts +135 -19
  171. package/src/extensions/tools/team/team-tools.ts +151 -91
  172. package/src/extensions/tools/types.ts +0 -6
  173. package/src/hooks/hook-bridge.ts +489 -0
  174. package/src/hooks/hook-file-hooks.ts +58 -3
  175. package/src/hooks/hook-registry.ts +257 -0
  176. package/src/hub/browser-websocket.ts +26 -4
  177. package/src/hub/client.ts +72 -13
  178. package/src/hub/daemon-entry.ts +35 -0
  179. package/src/hub/daemon.ts +117 -14
  180. package/src/hub/defaults.ts +39 -12
  181. package/src/hub/runtime-handlers.ts +4 -3
  182. package/src/hub/server.ts +506 -77
  183. package/src/hub/session-client.ts +43 -1
  184. package/src/hub/start-shared-server.ts +3 -0
  185. package/src/hub/ui-client.ts +4 -0
  186. package/src/index.ts +46 -1
  187. package/src/llms/cline-recommended-models.ts +167 -0
  188. package/src/llms/handler-factory.ts +56 -0
  189. package/src/llms/provider-defaults.ts +17 -1
  190. package/src/llms/provider-settings.ts +48 -1
  191. package/src/llms/runtime-registry.ts +1 -0
  192. package/src/runtime/agent-config-adapter.ts +636 -0
  193. package/src/runtime/agent-runtime-config-builder.ts +205 -0
  194. package/src/runtime/error-feedback.ts +142 -0
  195. package/src/runtime/history.ts +137 -0
  196. package/src/runtime/host.ts +22 -0
  197. package/src/runtime/loop-detection.ts +162 -0
  198. package/src/runtime/mistake-tracker.ts +221 -0
  199. package/src/runtime/runtime-builder.ts +61 -5
  200. package/src/runtime/runtime-event-adapter.ts +412 -0
  201. package/src/runtime/runtime-host.ts +45 -1
  202. package/src/runtime/session-runtime-orchestrator.ts +1253 -0
  203. package/src/runtime/session-runtime.ts +16 -2
  204. package/src/runtime/user-input-builder.ts +167 -0
  205. package/src/services/local-runtime-bootstrap.ts +128 -22
  206. package/src/services/plugin-tools.ts +1 -0
  207. package/src/services/providers/local-provider-registry.ts +273 -57
  208. package/src/services/providers/local-provider-service.ts +67 -7
  209. package/src/services/session-data.ts +16 -14
  210. package/src/services/session-telemetry.ts +6 -15
  211. package/src/services/storage/file-team-store.ts +1 -5
  212. package/src/services/storage/provider-settings-legacy-migration.ts +8 -47
  213. package/src/services/storage/provider-settings-manager.ts +16 -1
  214. package/src/services/storage/sqlite-team-store.ts +1 -5
  215. package/src/session/conversation-store.ts +77 -0
  216. package/src/session/message-builder.ts +941 -0
  217. package/src/transports/hub.ts +458 -33
  218. package/src/transports/local.ts +296 -65
  219. package/src/transports/remote.ts +1 -0
  220. package/src/types/config.ts +9 -0
  221. package/src/types/events.ts +8 -6
  222. package/src/types/index.ts +3 -0
  223. package/src/types/provider-settings.ts +8 -1
  224. package/src/types/session.ts +5 -2
  225. package/src/types.ts +15 -1
  226. package/dist/cron/index.d.ts +0 -6
  227. package/dist/cron/index.d.ts.map +0 -1
  228. package/dist/services/telemetry/index.js +0 -28
@@ -1,4 +1,4 @@
1
- import type { AgentResult } from "@clinebot/agents";
1
+ import type { AgentResult } from "@clinebot/shared";
2
2
  import {
3
3
  createTool,
4
4
  TEAM_AWAIT_TIMEOUT_MS,
@@ -11,20 +11,32 @@ import {
11
11
  TeamAwaitRunsInputSchema,
12
12
  type TeamBroadcastInput,
13
13
  TeamBroadcastInputSchema,
14
+ TeamBroadcastToolResultSchema,
14
15
  type TeamCancelRunInput,
15
16
  TeamCancelRunInputSchema,
17
+ TeamCancelRunToolResultSchema,
16
18
  type TeamCleanupInput,
17
19
  TeamCleanupInputSchema,
20
+ TeamCleanupToolResultSchema,
18
21
  type TeamCreateOutcomeInput,
19
22
  TeamCreateOutcomeInputSchema,
23
+ type TeamCreateOutcomeToolResult,
24
+ TeamCreateOutcomeToolResultSchema,
20
25
  type TeamFinalizeOutcomeInput,
21
26
  TeamFinalizeOutcomeInputSchema,
27
+ TeamFinalizeOutcomeToolResultSchema,
22
28
  type TeamListOutcomesInput,
23
29
  TeamListOutcomesInputSchema,
24
30
  type TeamListRunsInput,
25
31
  TeamListRunsInputSchema,
32
+ type TeamMailboxMessageToolResult,
33
+ TeamMailboxMessageToolResultSchema,
26
34
  type TeamMissionLogInput,
27
35
  TeamMissionLogInputSchema,
36
+ TeamMissionLogToolResultSchema,
37
+ TeamOutcomeFragmentToolResultSchema,
38
+ type TeamOutcomeToolResult,
39
+ TeamOutcomeToolResultSchema,
28
40
  type TeamReadMailboxInput,
29
41
  TeamReadMailboxInputSchema,
30
42
  type TeamReviewOutcomeFragmentInput,
@@ -33,19 +45,27 @@ import {
33
45
  type TeamRunResultSummary,
34
46
  type TeamRunTaskInput,
35
47
  TeamRunTaskInputSchema,
48
+ type TeamRunTaskToolResult,
49
+ TeamRunTaskToolResultSchema,
36
50
  type TeamRunToolSummary,
51
+ TeamRunToolSummarySchema,
37
52
  type TeamRuntimeState,
38
53
  type TeamSendMessageInput,
39
54
  TeamSendMessageInputSchema,
55
+ TeamSendMessageToolResultSchema,
40
56
  type TeamShutdownTeammateInput,
41
57
  TeamShutdownTeammateInputSchema,
58
+ TeamSimpleAgentStatusToolResultSchema,
42
59
  type TeamSpawnTeammateInput,
43
60
  TeamSpawnTeammateInputSchema,
44
61
  type TeamStatusInput,
45
62
  TeamStatusInputSchema,
63
+ type TeamStatusToolResult,
64
+ TeamStatusToolResultSchema,
46
65
  type TeamTaskInput,
47
66
  TeamTaskInputSchema,
48
67
  type TeamTaskToolResult,
68
+ TeamTaskToolResultSchema,
49
69
  type TeamTeammateSpec,
50
70
  type Tool,
51
71
  validateWithZod,
@@ -88,6 +108,10 @@ function summarizeRunResult(
88
108
  };
89
109
  }
90
110
 
111
+ function dateToIso(value: Date | undefined): string | undefined {
112
+ return value?.toISOString();
113
+ }
114
+
91
115
  function summarizeRun(run: TeamRunRecord): TeamRunToolSummary {
92
116
  return {
93
117
  id: run.id,
@@ -98,13 +122,13 @@ function summarizeRun(run: TeamRunRecord): TeamRunToolSummary {
98
122
  priority: run.priority,
99
123
  retryCount: run.retryCount,
100
124
  maxRetries: run.maxRetries,
101
- nextAttemptAt: run.nextAttemptAt,
125
+ nextAttemptAt: dateToIso(run.nextAttemptAt),
102
126
  continueConversation: run.continueConversation,
103
- startedAt: run.startedAt,
104
- endedAt: run.endedAt,
127
+ startedAt: run.startedAt.toISOString(),
128
+ endedAt: dateToIso(run.endedAt),
105
129
  leaseOwner: run.leaseOwner,
106
- heartbeatAt: run.heartbeatAt,
107
- lastProgressAt: run.lastProgressAt,
130
+ heartbeatAt: dateToIso(run.heartbeatAt),
131
+ lastProgressAt: dateToIso(run.lastProgressAt),
108
132
  lastProgressMessage: run.lastProgressMessage,
109
133
  currentActivity: run.currentActivity,
110
134
  error: run.error,
@@ -300,7 +324,10 @@ export function createAgentTeamsTools(
300
324
  }),
301
325
  );
302
326
  }
303
- return { agentId: validatedInput.agentId, status: "spawned" };
327
+ return validateWithZod(TeamSimpleAgentStatusToolResultSchema, {
328
+ agentId: validatedInput.agentId,
329
+ status: "spawned",
330
+ });
304
331
  },
305
332
  }) as Tool,
306
333
  );
@@ -327,20 +354,26 @@ export function createAgentTeamsTools(
327
354
  validatedInput.agentId,
328
355
  validatedInput.reason,
329
356
  );
330
- return { agentId: validatedInput.agentId, status: "stopped" };
357
+ return validateWithZod(TeamSimpleAgentStatusToolResultSchema, {
358
+ agentId: validatedInput.agentId,
359
+ status: "stopped",
360
+ });
331
361
  },
332
362
  }) as Tool,
333
363
  );
334
364
 
335
365
  tools.push(
336
- createTool<TeamStatusInput, ReturnType<AgentTeamsRuntime["getSnapshot"]>>({
366
+ createTool<TeamStatusInput, TeamStatusToolResult>({
337
367
  name: "team_status",
338
368
  description:
339
369
  "Return a snapshot of team members, task counts, mailbox, and mission log stats.",
340
370
  inputSchema: zodToJsonSchema(TeamStatusInputSchema),
341
371
  execute: async (input) => {
342
372
  validateWithZod(TeamStatusInputSchema, input);
343
- return options.runtime.getSnapshot();
373
+ return validateWithZod(
374
+ TeamStatusToolResultSchema,
375
+ options.runtime.getSnapshot(),
376
+ );
344
377
  },
345
378
  }) as Tool,
346
379
  );
@@ -376,7 +409,7 @@ export function createAgentTeamsTools(
376
409
  assignee: validatedInput.assignee,
377
410
  createdBy: options.requesterId,
378
411
  });
379
- return {
412
+ return validateWithZod(TeamTaskToolResultSchema, {
380
413
  action: "create",
381
414
  taskId: task.id,
382
415
  status: task.status,
@@ -386,28 +419,28 @@ export function createAgentTeamsTools(
386
419
  note: `Ignored fields for action=create: ${ignoredFields.join(", ")}`,
387
420
  }
388
421
  : {}),
389
- };
422
+ });
390
423
  }
391
424
  case "list":
392
- return {
425
+ return validateWithZod(TeamTaskToolResultSchema, {
393
426
  action: "list",
394
427
  tasks: options.runtime.listTaskItems({
395
428
  status: validatedInput.status,
396
429
  assignee: validatedInput.assignee,
397
430
  }),
398
- };
431
+ });
399
432
  case "claim": {
400
433
  const task = options.runtime.claimTask(
401
434
  validatedInput.taskId!,
402
435
  options.requesterId,
403
436
  );
404
- return {
437
+ return validateWithZod(TeamTaskToolResultSchema, {
405
438
  action: "claim",
406
439
  taskId: task.id,
407
440
  status: task.status,
408
441
  nextStep:
409
442
  "Task is now in_progress. Execute the work using team_run_task or your own tools, then call team_task with action=complete when done.",
410
- };
443
+ });
411
444
  }
412
445
  case "complete": {
413
446
  const task = options.runtime.completeTask(
@@ -415,11 +448,11 @@ export function createAgentTeamsTools(
415
448
  options.requesterId,
416
449
  validatedInput.summary!,
417
450
  );
418
- return {
451
+ return validateWithZod(TeamTaskToolResultSchema, {
419
452
  action: "complete",
420
453
  taskId: task.id,
421
454
  status: task.status,
422
- };
455
+ });
423
456
  }
424
457
  case "block": {
425
458
  const task = options.runtime.blockTask(
@@ -427,11 +460,11 @@ export function createAgentTeamsTools(
427
460
  options.requesterId,
428
461
  validatedInput.reason!,
429
462
  );
430
- return {
463
+ return validateWithZod(TeamTaskToolResultSchema, {
431
464
  action: "block",
432
465
  taskId: task.id,
433
466
  status: task.status,
434
- };
467
+ });
435
468
  }
436
469
  }
437
470
  },
@@ -440,20 +473,11 @@ export function createAgentTeamsTools(
440
473
 
441
474
  // Track in-flight sync runs per agent for dedup
442
475
  // (Claude sometimes emits duplicate tool_use blocks in a single response;
443
- // we execute the first and return an informative "duplicate ignored" to the rest)
444
- const pendingSyncRuns = new Set<string>();
476
+ // duplicate sync calls should await the first dispatched run)
477
+ const pendingSyncRuns = new Map<string, Promise<TeamRunTaskToolResult>>();
445
478
 
446
479
  tools.push(
447
- createTool<
448
- TeamRunTaskInput,
449
- {
450
- agentId: string;
451
- mode: "sync" | "async";
452
- runId?: string;
453
- text?: string;
454
- iterations?: number;
455
- }
456
- >({
480
+ createTool<TeamRunTaskInput, TeamRunTaskToolResult>({
457
481
  name: "team_run_task",
458
482
  description:
459
483
  "Route a delegated task to a teammate. Choose sync (wait) or async (run in background).",
@@ -471,42 +495,51 @@ export function createAgentTeamsTools(
471
495
  validatedInput.continueConversation || undefined,
472
496
  },
473
497
  );
474
- return {
498
+ return validateWithZod(TeamRunTaskToolResultSchema, {
475
499
  agentId: validatedInput.agentId,
476
500
  mode: "async",
501
+ status: "queued",
502
+ dispatched: true,
503
+ message: `Task dispatched to ${validatedInput.agentId} and queued as ${run.id}.`,
477
504
  runId: run.id,
478
- };
505
+ });
479
506
  }
480
507
 
481
- /// Deduplication guard: reject a duplicate sync call for the same agent
482
- // that was already dispatched in this same parallel tool-call batch.
483
- if (pendingSyncRuns.has(validatedInput.agentId)) {
484
- throw new Error(
485
- `Duplicate team_run_task call detected for agent "${validatedInput.agentId}". ` +
486
- `Only one call per agent is allowed per turn. Discard this duplicate result.`,
487
- );
488
- }
489
- pendingSyncRuns.add(validatedInput.agentId);
490
- try {
491
- const result = await options.runtime.routeToTeammate(
492
- validatedInput.agentId,
493
- validatedInput.task,
494
- {
495
- taskId: validatedInput.taskId || undefined,
496
- fromAgentId: options.requesterId,
497
- continueConversation:
498
- validatedInput.continueConversation || undefined,
499
- },
500
- );
501
- return {
502
- agentId: validatedInput.agentId,
503
- mode: "sync",
504
- text: result.text,
505
- iterations: result.iterations,
506
- };
507
- } finally {
508
- pendingSyncRuns.delete(validatedInput.agentId);
508
+ // Deduplication guard: collapse a duplicate sync call for the same
509
+ // agent onto the first in-flight dispatch in this parallel tool-call batch.
510
+ const pendingRun = pendingSyncRuns.get(validatedInput.agentId);
511
+ if (pendingRun) {
512
+ const result = await pendingRun;
513
+ return validateWithZod(TeamRunTaskToolResultSchema, {
514
+ ...result,
515
+ status: "joined",
516
+ deduped: true,
517
+ message: `Task for ${validatedInput.agentId} was already dispatched in this tool batch; joined the existing in-flight run.`,
518
+ });
509
519
  }
520
+ const runPromise = options.runtime
521
+ .routeToTeammate(validatedInput.agentId, validatedInput.task, {
522
+ taskId: validatedInput.taskId || undefined,
523
+ fromAgentId: options.requesterId,
524
+ continueConversation:
525
+ validatedInput.continueConversation || undefined,
526
+ })
527
+ .then((result) =>
528
+ validateWithZod(TeamRunTaskToolResultSchema, {
529
+ agentId: validatedInput.agentId,
530
+ mode: "sync" as const,
531
+ status: "running" as const,
532
+ dispatched: true,
533
+ message: `Task dispatched to ${validatedInput.agentId} and completed in sync mode.`,
534
+ text: result.text,
535
+ iterations: result.iterations,
536
+ }),
537
+ )
538
+ .finally(() => {
539
+ pendingSyncRuns.delete(validatedInput.agentId);
540
+ });
541
+ pendingSyncRuns.set(validatedInput.agentId, runPromise);
542
+ return await runPromise;
510
543
  },
511
544
  }) as Tool,
512
545
  );
@@ -522,7 +555,10 @@ export function createAgentTeamsTools(
522
555
  validatedInput.runId,
523
556
  validatedInput.reason,
524
557
  );
525
- return { runId: run.id, status: run.status };
558
+ return validateWithZod(TeamCancelRunToolResultSchema, {
559
+ runId: run.id,
560
+ status: run.status,
561
+ });
526
562
  },
527
563
  }) as Tool,
528
564
  );
@@ -534,9 +570,12 @@ export function createAgentTeamsTools(
534
570
  "List teammate runs started with team_run_task in async mode, including live activity/progress fields when available.",
535
571
  inputSchema: zodToJsonSchema(TeamListRunsInputSchema),
536
572
  execute: async (input) =>
537
- options.runtime
538
- .listRuns(validateWithZod(TeamListRunsInputSchema, input))
539
- .map(summarizeRun),
573
+ validateWithZod(
574
+ TeamRunToolSummarySchema.array(),
575
+ options.runtime
576
+ .listRuns(validateWithZod(TeamListRunsInputSchema, input))
577
+ .map(summarizeRun),
578
+ ),
540
579
  }) as Tool,
541
580
  );
542
581
 
@@ -552,7 +591,7 @@ export function createAgentTeamsTools(
552
591
  if (validatedInput.runId) {
553
592
  const run = await options.runtime.awaitRun(validatedInput.runId);
554
593
  assertAwaitedRunSucceeded(run);
555
- return summarizeRun(run);
594
+ return validateWithZod(TeamRunToolSummarySchema, summarizeRun(run));
556
595
  }
557
596
  const runs = await options.runtime.awaitAllRuns();
558
597
  const failedRuns = runs.filter((run) =>
@@ -569,7 +608,10 @@ export function createAgentTeamsTools(
569
608
  `One or more runs did not complete successfully: ${details}`,
570
609
  );
571
610
  }
572
- return runs.map(summarizeRun);
611
+ return validateWithZod(
612
+ TeamRunToolSummarySchema.array(),
613
+ runs.map(summarizeRun),
614
+ );
573
615
  },
574
616
  }) as Tool,
575
617
  );
@@ -591,7 +633,10 @@ export function createAgentTeamsTools(
591
633
  validatedInput.body,
592
634
  validatedInput.taskId ?? undefined,
593
635
  );
594
- return { id: message.id, toAgentId: message.toAgentId };
636
+ return validateWithZod(TeamSendMessageToolResultSchema, {
637
+ id: message.id,
638
+ toAgentId: message.toAgentId,
639
+ });
595
640
  },
596
641
  }) as Tool,
597
642
  );
@@ -611,16 +656,15 @@ export function createAgentTeamsTools(
611
656
  taskId: validatedInput.taskId ?? undefined,
612
657
  },
613
658
  );
614
- return { delivered: messages.length };
659
+ return validateWithZod(TeamBroadcastToolResultSchema, {
660
+ delivered: messages.length,
661
+ });
615
662
  },
616
663
  }) as Tool,
617
664
  );
618
665
 
619
666
  tools.push(
620
- createTool<
621
- TeamReadMailboxInput,
622
- ReturnType<AgentTeamsRuntime["listMailbox"]>
623
- >({
667
+ createTool<TeamReadMailboxInput, TeamMailboxMessageToolResult[]>({
624
668
  name: "team_read_mailbox",
625
669
  description: "Read the current agent mailbox.",
626
670
  inputSchema: zodToJsonSchema(TeamReadMailboxInputSchema),
@@ -629,10 +673,13 @@ export function createAgentTeamsTools(
629
673
  TeamReadMailboxInputSchema,
630
674
  input,
631
675
  );
632
- return options.runtime.listMailbox(options.requesterId, {
633
- unreadOnly: validatedInput.unreadOnly,
634
- markRead: true,
635
- });
676
+ return validateWithZod(
677
+ TeamMailboxMessageToolResultSchema.array(),
678
+ options.runtime.listMailbox(options.requesterId, {
679
+ unreadOnly: validatedInput.unreadOnly,
680
+ markRead: true,
681
+ }),
682
+ );
636
683
  },
637
684
  }) as Tool,
638
685
  );
@@ -657,7 +704,9 @@ export function createAgentTeamsTools(
657
704
  : undefined,
658
705
  nextAction: validatedInput.nextAction || undefined,
659
706
  });
660
- return { id: entry.id };
707
+ return validateWithZod(TeamMissionLogToolResultSchema, {
708
+ id: entry.id,
709
+ });
661
710
  },
662
711
  }) as Tool,
663
712
  );
@@ -674,13 +723,15 @@ export function createAgentTeamsTools(
674
723
  throw new Error("Only the lead agent can run cleanup.");
675
724
  }
676
725
  options.runtime.cleanup();
677
- return { status: "cleaned" };
726
+ return validateWithZod(TeamCleanupToolResultSchema, {
727
+ status: "cleaned",
728
+ });
678
729
  },
679
730
  }) as Tool,
680
731
  );
681
732
 
682
733
  tools.push(
683
- createTool<TeamCreateOutcomeInput, { outcomeId: string; status: string }>({
734
+ createTool<TeamCreateOutcomeInput, TeamCreateOutcomeToolResult>({
684
735
  name: "team_create_outcome",
685
736
  description: "Create a converged team outcome.",
686
737
  inputSchema: zodToJsonSchema(TeamCreateOutcomeInputSchema),
@@ -694,11 +745,11 @@ export function createAgentTeamsTools(
694
745
  requiredSections: validatedInput.requiredSections,
695
746
  createdBy: options.requesterId,
696
747
  });
697
- return {
748
+ return validateWithZod(TeamCreateOutcomeToolResultSchema, {
698
749
  outcomeId: outcome.id,
699
750
  status: outcome.status,
700
751
  requiredSections: outcome.requiredSections,
701
- };
752
+ });
702
753
  },
703
754
  }) as Tool,
704
755
  );
@@ -723,7 +774,10 @@ export function createAgentTeamsTools(
723
774
  sourceRunId: validatedInput.sourceRunId || undefined,
724
775
  content: validatedInput.content,
725
776
  });
726
- return { fragmentId: fragment.id, status: fragment.status };
777
+ return validateWithZod(TeamOutcomeFragmentToolResultSchema, {
778
+ fragmentId: fragment.id,
779
+ status: fragment.status,
780
+ });
727
781
  },
728
782
  }) as Tool,
729
783
  );
@@ -746,7 +800,10 @@ export function createAgentTeamsTools(
746
800
  reviewedBy: options.requesterId,
747
801
  approved: validatedInput.approved,
748
802
  });
749
- return { fragmentId: fragment.id, status: fragment.status };
803
+ return validateWithZod(TeamOutcomeFragmentToolResultSchema, {
804
+ fragmentId: fragment.id,
805
+ status: fragment.status,
806
+ });
750
807
  },
751
808
  }) as Tool,
752
809
  );
@@ -765,23 +822,26 @@ export function createAgentTeamsTools(
765
822
  const outcome = options.runtime.finalizeOutcome(
766
823
  validatedInput.outcomeId,
767
824
  );
768
- return { outcomeId: outcome.id, status: outcome.status };
825
+ return validateWithZod(TeamFinalizeOutcomeToolResultSchema, {
826
+ outcomeId: outcome.id,
827
+ status: outcome.status,
828
+ });
769
829
  },
770
830
  },
771
831
  ) as Tool,
772
832
  );
773
833
 
774
834
  tools.push(
775
- createTool<
776
- TeamListOutcomesInput,
777
- ReturnType<AgentTeamsRuntime["listOutcomes"]>
778
- >({
835
+ createTool<TeamListOutcomesInput, TeamOutcomeToolResult[]>({
779
836
  name: "team_list_outcomes",
780
837
  description: "List team outcomes.",
781
838
  inputSchema: zodToJsonSchema(TeamListOutcomesInputSchema),
782
839
  execute: async (input) => {
783
840
  validateWithZod(TeamListOutcomesInputSchema, input);
784
- return options.runtime.listOutcomes();
841
+ return validateWithZod(
842
+ TeamOutcomeToolResultSchema.array(),
843
+ options.runtime.listOutcomes(),
844
+ );
785
845
  },
786
846
  }) as Tool,
787
847
  );
@@ -335,12 +335,6 @@ export interface DefaultToolsConfig {
335
335
  */
336
336
  skillsTimeoutMs?: number;
337
337
 
338
- /**
339
- * Timeout for ask_followup_question operations in milliseconds
340
- * @default 15000
341
- */
342
- askQuestionTimeoutMs?: number;
343
-
344
338
  /**
345
339
  * Timeout for submit_and_exit operations in milliseconds
346
340
  * @default 15000