eve 0.37.0 → 0.37.1

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 (215) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/src/channel/routes.d.ts +13 -3
  3. package/dist/src/channel/routes.js +1 -1
  4. package/dist/src/channel/session-callback.js +1 -1
  5. package/dist/src/channel/session.d.ts +2 -1
  6. package/dist/src/channel/session.js +1 -1
  7. package/dist/src/channel/types.d.ts +41 -0
  8. package/dist/src/chunks/{use-eve-agent-CnppTEFk.js → use-eve-agent-Bi5fRxcZ.js} +9 -1
  9. package/dist/src/chunks/{use-eve-agent-COmP-H8R.js → use-eve-agent-DbKUBhl-.js} +9 -1
  10. package/dist/src/cli/commands/init-git.js +1 -1
  11. package/dist/src/cli/commands/init-recovery.d.ts +3 -0
  12. package/dist/src/cli/commands/init-recovery.js +3 -0
  13. package/dist/src/cli/commands/init-target.d.ts +21 -0
  14. package/dist/src/cli/commands/init-target.js +1 -0
  15. package/dist/src/cli/commands/init.js +1 -1
  16. package/dist/src/cli/dev/tui/runner.d.ts +8 -0
  17. package/dist/src/cli/dev/tui/runner.js +1 -1
  18. package/dist/src/cli/dev/tui/subagent-pump.d.ts +27 -22
  19. package/dist/src/cli/dev/tui/subagent-pump.js +1 -1
  20. package/dist/src/cli/dev/tui/terminal-renderer.d.ts +16 -0
  21. package/dist/src/cli/dev/tui/terminal-renderer.js +12 -12
  22. package/dist/src/cli/dev/tui/tool-presentation.js +1 -1
  23. package/dist/src/client/open-stream.d.ts +2 -0
  24. package/dist/src/client/open-stream.js +1 -1
  25. package/dist/src/client/session.js +1 -1
  26. package/dist/src/compiled/.vendor-stamp.json +2 -1
  27. package/dist/src/compiled/@modelcontextprotocol/server/LICENSE +216 -0
  28. package/dist/src/compiled/@modelcontextprotocol/server/index.d.ts +98 -0
  29. package/dist/src/compiled/@modelcontextprotocol/server/index.js +80 -0
  30. package/dist/src/compiler/extension-compatibility.d.ts +10 -10
  31. package/dist/src/compiler/extension-compatibility.js +1 -1
  32. package/dist/src/compiler/manifest.js +1 -1
  33. package/dist/src/compiler/normalize-agent-config.js +1 -1
  34. package/dist/src/compiler/normalize-manifest.js +1 -1
  35. package/dist/src/compiler/normalize-subagent.d.ts +1 -1
  36. package/dist/src/compiler/normalize-subagent.js +1 -1
  37. package/dist/src/context/serialized-dynamic-model-selection.d.ts +2 -0
  38. package/dist/src/context/serialized-dynamic-model-selection.js +1 -0
  39. package/dist/src/execution/agent-handle-dispatch.d.ts +15 -1
  40. package/dist/src/execution/agent-handle-dispatch.js +1 -1
  41. package/dist/src/execution/cancel-descendant-turns-step.js +1 -1
  42. package/dist/src/execution/delegated-parent-notification.d.ts +17 -0
  43. package/dist/src/execution/delegated-parent-notification.js +1 -1
  44. package/dist/src/execution/deliver-payloads.js +1 -1
  45. package/dist/src/execution/dispatch-runtime-actions-shared.d.ts +155 -0
  46. package/dist/src/execution/dispatch-runtime-actions-shared.js +1 -0
  47. package/dist/src/execution/dispatch-runtime-actions-step.d.ts +18 -14
  48. package/dist/src/execution/dispatch-runtime-actions-step.js +1 -1
  49. package/dist/src/execution/dispatch-workflow-runtime-actions-step.d.ts +7 -2
  50. package/dist/src/execution/dispatch-workflow-runtime-actions-step.js +1 -1
  51. package/dist/src/execution/effective-output-schema.d.ts +21 -0
  52. package/dist/src/execution/effective-output-schema.js +1 -0
  53. package/dist/src/execution/eve-workflow-attributes.d.ts +2 -0
  54. package/dist/src/execution/node-step.js +1 -1
  55. package/dist/src/execution/parked-delivery-wait.d.ts +8 -12
  56. package/dist/src/execution/parked-delivery-wait.js +1 -1
  57. package/dist/src/execution/{route-proxied-deliver-step.d.ts → proxied-deliver-step.d.ts} +7 -4
  58. package/dist/src/execution/proxied-deliver-step.js +1 -0
  59. package/dist/src/execution/remote-agent-dispatch.d.ts +32 -0
  60. package/dist/src/execution/remote-agent-dispatch.js +1 -1
  61. package/dist/src/execution/remote-agent-route-url.d.ts +2 -0
  62. package/dist/src/execution/remote-agent-route-url.js +1 -0
  63. package/dist/src/execution/route-child-delivery.d.ts +2 -1
  64. package/dist/src/execution/route-child-delivery.js +1 -1
  65. package/dist/src/execution/session-callback-step.d.ts +11 -0
  66. package/dist/src/execution/session-callback-step.js +1 -1
  67. package/dist/src/execution/session-command-wire.js +1 -1
  68. package/dist/src/execution/session-state-cursor.d.ts +25 -0
  69. package/dist/src/execution/session-state-cursor.js +1 -0
  70. package/dist/src/execution/settle-cancelled-turn-step.d.ts +2 -0
  71. package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
  72. package/dist/src/execution/subagent-event-proxy-step.d.ts +15 -0
  73. package/dist/src/execution/subagent-event-proxy-step.js +1 -1
  74. package/dist/src/execution/subagent-hitl-proxy.d.ts +14 -7
  75. package/dist/src/execution/subagent-hitl-proxy.js +1 -1
  76. package/dist/src/execution/subagent-start-local.d.ts +29 -0
  77. package/dist/src/execution/subagent-start-local.js +1 -0
  78. package/dist/src/execution/subagent-start-remote.d.ts +23 -0
  79. package/dist/src/execution/subagent-start-remote.js +1 -0
  80. package/dist/src/execution/task-event-callback.d.ts +13 -0
  81. package/dist/src/execution/task-event-callback.js +1 -0
  82. package/dist/src/execution/task-input-capability.d.ts +4 -0
  83. package/dist/src/execution/task-input-capability.js +1 -0
  84. package/dist/src/execution/tasks/child/steps.d.ts +46 -0
  85. package/dist/src/execution/tasks/child/steps.js +1 -0
  86. package/dist/src/execution/tasks/child/workflow.d.ts +31 -0
  87. package/dist/src/execution/tasks/child/workflow.js +1 -0
  88. package/dist/src/execution/tasks/parent/agent-identity.d.ts +13 -0
  89. package/dist/src/execution/tasks/parent/agent-identity.js +1 -0
  90. package/dist/src/execution/tasks/parent/agent-views.d.ts +6 -0
  91. package/dist/src/execution/tasks/parent/agent-views.js +1 -0
  92. package/dist/src/execution/tasks/parent/continuation-dispatch.d.ts +37 -0
  93. package/dist/src/execution/tasks/parent/continuation-dispatch.js +1 -0
  94. package/dist/src/execution/tasks/parent/control-shared.d.ts +36 -0
  95. package/dist/src/execution/tasks/parent/control-shared.js +1 -0
  96. package/dist/src/execution/tasks/parent/delegate.d.ts +70 -0
  97. package/dist/src/execution/tasks/parent/delegate.js +1 -0
  98. package/dist/src/execution/tasks/parent/dispatch-task-step.d.ts +19 -0
  99. package/dist/src/execution/tasks/parent/dispatch-task-step.js +1 -0
  100. package/dist/src/execution/tasks/parent/dispatch.d.ts +33 -0
  101. package/dist/src/execution/tasks/parent/dispatch.js +1 -0
  102. package/dist/src/execution/tasks/parent/hitl-proxy-steps.d.ts +29 -0
  103. package/dist/src/execution/tasks/parent/hitl-proxy-steps.js +1 -0
  104. package/dist/src/execution/tasks/parent/run-parent.d.ts +72 -0
  105. package/dist/src/execution/tasks/parent/run-parent.js +1 -0
  106. package/dist/src/execution/tasks/parent/send.d.ts +25 -0
  107. package/dist/src/execution/tasks/parent/send.js +1 -0
  108. package/dist/src/execution/tasks/workflow-target.d.ts +2 -0
  109. package/dist/src/execution/tasks/workflow-target.js +1 -0
  110. package/dist/src/execution/terminate-child-sessions-step.d.ts +1 -0
  111. package/dist/src/execution/terminate-child-sessions-step.js +1 -1
  112. package/dist/src/execution/turn-control-receiver.d.ts +10 -0
  113. package/dist/src/execution/turn-control-receiver.js +1 -1
  114. package/dist/src/execution/turn-dispatch.d.ts +2 -0
  115. package/dist/src/execution/turn-dispatch.js +1 -1
  116. package/dist/src/execution/turn-execution-cursor.d.ts +2 -8
  117. package/dist/src/execution/turn-execution-cursor.js +1 -1
  118. package/dist/src/execution/turn-workflow.js +1 -1
  119. package/dist/src/execution/workflow-callback-url.d.ts +5 -0
  120. package/dist/src/execution/workflow-callback-url.js +1 -1
  121. package/dist/src/execution/workflow-entry.js +1 -1
  122. package/dist/src/execution/workflow-runtime.d.ts +9 -0
  123. package/dist/src/execution/workflow-runtime.js +1 -1
  124. package/dist/src/execution/workflow-steps.d.ts +7 -21
  125. package/dist/src/execution/workflow-steps.js +1 -1
  126. package/dist/src/harness/advertised-tools.js +1 -1
  127. package/dist/src/harness/authorization.js +1 -1
  128. package/dist/src/harness/execute-tool.d.ts +7 -0
  129. package/dist/src/harness/handles/prompt.d.ts +12 -0
  130. package/dist/src/harness/handles/prompt.js +2 -1
  131. package/dist/src/harness/handles/query.js +1 -1
  132. package/dist/src/harness/handles/store.d.ts +9 -2
  133. package/dist/src/harness/handles/store.js +1 -1
  134. package/dist/src/harness/handles/transitions.d.ts +10 -1
  135. package/dist/src/harness/handles/transitions.js +1 -1
  136. package/dist/src/harness/proxy-input-requests.d.ts +21 -4
  137. package/dist/src/harness/proxy-input-requests.js +1 -1
  138. package/dist/src/harness/runtime-actions.d.ts +2 -0
  139. package/dist/src/harness/runtime-actions.js +1 -1
  140. package/dist/src/harness/session-limit-enforcement.js +1 -1
  141. package/dist/src/harness/tool-loop.js +2 -2
  142. package/dist/src/harness/workflow-runtime-action-state.js +1 -1
  143. package/dist/src/internal/application/package.js +1 -1
  144. package/dist/src/internal/authored-definition/core.js +1 -1
  145. package/dist/src/internal/invocation/agent-invocation.d.ts +54 -0
  146. package/dist/src/internal/invocation/agent-invocation.js +1 -0
  147. package/dist/src/internal/invocation/attributes.d.ts +2 -0
  148. package/dist/src/internal/invocation/attributes.js +1 -0
  149. package/dist/src/internal/invocation/metadata.d.ts +9 -0
  150. package/dist/src/internal/invocation/metadata.js +1 -0
  151. package/dist/src/internal/invocation/workflow-execution.d.ts +32 -0
  152. package/dist/src/internal/invocation/workflow-execution.js +1 -0
  153. package/dist/src/internal/mcp/http-security.d.ts +12 -0
  154. package/dist/src/internal/mcp/http-security.js +1 -0
  155. package/dist/src/internal/mcp/protected-resource.d.ts +9 -0
  156. package/dist/src/internal/mcp/protected-resource.js +1 -0
  157. package/dist/src/internal/mcp/streamable-http-server.d.ts +51 -0
  158. package/dist/src/internal/mcp/streamable-http-server.js +1 -0
  159. package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
  160. package/dist/src/internal/nitro/routes/channel-route-context.d.ts +14 -0
  161. package/dist/src/internal/nitro/routes/channel-route-context.js +1 -1
  162. package/dist/src/internal/nitro/routes/runtime-stack.d.ts +2 -0
  163. package/dist/src/internal/nitro/routes/runtime-stack.js +1 -1
  164. package/dist/src/internal/vercel-agent-summary.d.ts +1 -1
  165. package/dist/src/protocol/message.d.ts +28 -0
  166. package/dist/src/protocol/message.js +2 -2
  167. package/dist/src/protocol/routes.d.ts +14 -0
  168. package/dist/src/protocol/routes.js +1 -1
  169. package/dist/src/public/channels/auth.d.ts +36 -0
  170. package/dist/src/public/channels/auth.js +1 -1
  171. package/dist/src/public/channels/eve.js +1 -1
  172. package/dist/src/public/channels/mcp.d.ts +19 -0
  173. package/dist/src/public/channels/mcp.js +1 -0
  174. package/dist/src/public/definitions/channel.d.ts +2 -2
  175. package/dist/src/public/definitions/channel.js +1 -1
  176. package/dist/src/react/use-eve-agent.js +1 -1
  177. package/dist/src/runtime/actions/types.d.ts +9 -0
  178. package/dist/src/runtime/actions/types.js +1 -1
  179. package/dist/src/runtime/agent/bootstrap.js +1 -1
  180. package/dist/src/runtime/connections/authorization-complete-page.js +70 -28
  181. package/dist/src/runtime/framework-channels/index.js +1 -1
  182. package/dist/src/runtime/framework-tools/index.js +1 -1
  183. package/dist/src/runtime/framework-tools/tasks.d.ts +95 -0
  184. package/dist/src/runtime/framework-tools/tasks.js +1 -0
  185. package/dist/src/runtime/prompt/compose.d.ts +1 -0
  186. package/dist/src/runtime/prompt/compose.js +1 -1
  187. package/dist/src/runtime/resolve-agent-graph.js +1 -1
  188. package/dist/src/runtime/resolve-agent.js +1 -1
  189. package/dist/src/runtime/session-callback-route.js +1 -1
  190. package/dist/src/runtime/task-input-response-route.d.ts +5 -0
  191. package/dist/src/runtime/task-input-response-route.js +1 -0
  192. package/dist/src/setup/scaffold/create/add-to-project.js +1 -1
  193. package/dist/src/setup/scaffold/create/project.js +1 -1
  194. package/dist/src/shared/agent-definition.d.ts +7 -0
  195. package/dist/src/svelte/index.js +1 -1
  196. package/dist/src/svelte/use-eve-agent.js +1 -1
  197. package/dist/src/tasks/json.d.ts +88 -0
  198. package/dist/src/tasks/json.js +1 -0
  199. package/dist/src/tasks/session-index.d.ts +48 -0
  200. package/dist/src/tasks/session-index.js +1 -0
  201. package/dist/src/tasks/task-id.d.ts +34 -0
  202. package/dist/src/tasks/task-id.js +1 -0
  203. package/dist/src/tasks/transitions.d.ts +23 -0
  204. package/dist/src/tasks/transitions.js +1 -0
  205. package/dist/src/tasks/types.d.ts +295 -0
  206. package/dist/src/tasks/types.js +1 -0
  207. package/dist/src/tasks/wire.d.ts +26 -0
  208. package/dist/src/tasks/wire.js +1 -0
  209. package/dist/src/vue/index.js +1 -1
  210. package/dist/src/vue/use-eve-agent.js +1 -1
  211. package/docs/channels/eve.mdx +14 -0
  212. package/docs/guides/client/streaming.mdx +1 -1
  213. package/docs/tools/human-in-the-loop.md +3 -1
  214. package/package.json +7 -1
  215. package/dist/src/execution/route-proxied-deliver-step.js +0 -1
@@ -1 +1 @@
1
- import{createInputRequestedEvent}from"#protocol/message.js";import{emitTurnEpilogue,getHarnessEmissionState,setHarnessEmissionState}from"#harness/emission.js";import{getProxyInputRequests,toProxyInputRequestEntries}from"#harness/proxy-input-requests.js";import{SESSION_LIMIT_STOP_OPTION_ID}from"#harness/session-limit-continuation.js";async function emitProxiedInputRequest(i){await i.emit(createInputRequestedEvent({requests:i.hookPayload.event.requests,sequence:i.hookPayload.event.sequence,stepIndex:i.hookPayload.event.stepIndex,turnId:i.hookPayload.event.turnId}));let o=i.session;if(i.mode===`conversation`){let e=getHarnessEmissionState(i.session.state),a=await emitTurnEpilogue(i.emit,e,i.mode);o=setHarnessEmissionState(i.session,a)}return{entries:toProxyInputRequestEntries(i.hookPayload),session:o}}function routeDeliverPayload(e){let t=getProxyInputRequests(e.state),n=e.payload.inputResponses??[],r=new Map,a=[],s;for(let e of n){let n=t.get(e.requestId);if(n===void 0){a.push(e);continue}n.kind===`session-limit`&&e.optionId===SESSION_LIMIT_STOP_OPTION_ID&&(s={kind:`cancel-turn`});let i=r.get(n.childContinuationToken);i===void 0?r.set(n.childContinuationToken,{responses:[e],routes:[n]}):(i.responses.push(e),i.routes.push(n))}let c=[...r.entries()].map(([e,n])=>{let r=new Set(n.responses.map(e=>e.requestId)),i=new Set(r);for(let a of n.routes)if(a.batch!==void 0&&batchResolves({batch:a.batch,childContinuationToken:e,entries:t,responseIds:r}))for(let e of a.batch.requestIds)i.add(e);return{childContinuationToken:e,payload:{inputResponses:n.responses},retireRequestIds:[...i]}}),l={};for(let[t,n]of Object.entries(e.payload))t===`inputResponses`||n===void 0||(l[t]=n);return a.length>0&&(l.inputResponses=a),{forChildren:c,forSelf:Object.keys(l).length>0?l:void 0,parentAction:s}}function batchResolves(e){return e.batch.approvalRequestIds.length===0||e.batch.approvalRequestIds.every(t=>{let n=e.entries.get(t);return n===void 0||!sameBatch(n,e)||e.responseIds.has(t)})}function sameBatch(e,t){return e.childContinuationToken===t.childContinuationToken&&e.batch?.requestIds.length===t.batch.requestIds.length&&e.batch.requestIds.every((e,n)=>e===t.batch.requestIds[n])}export{emitProxiedInputRequest,routeDeliverPayload};
1
+ import{createInputRequestedEvent}from"#protocol/message.js";import{emitTurnEpilogue,getHarnessEmissionState,setHarnessEmissionState}from"#harness/emission.js";import{getProxyInputRequests,toProxyInputRequestEntries}from"#harness/proxy-input-requests.js";import{SESSION_LIMIT_STOP_OPTION_ID}from"#harness/session-limit-continuation.js";async function emitProxiedInputRequest(i){await i.emit(createInputRequestedEvent({requests:i.hookPayload.event.requests,sequence:i.hookPayload.event.sequence,stepIndex:i.hookPayload.event.stepIndex,turnId:i.hookPayload.event.turnId}));let o=i.session;if(i.mode===`conversation`){let e=getHarnessEmissionState(i.session.state),a=await emitTurnEpilogue(i.emit,e,i.mode);o=setHarnessEmissionState(i.session,a)}return{entries:toProxyInputRequestEntries(i.hookPayload),session:o}}function routeDeliverPayload(e){let t=getProxyInputRequests(e.state),n=e.payload.inputResponses??[],r=new Map,a=[],s;for(let i of n){let n=t.get(i.requestId);if(n===void 0||e.allowRoute?.(i.requestId,n)===!1){a.push(i);continue}n.kind===`session-limit`&&i.optionId===SESSION_LIMIT_STOP_OPTION_ID&&(s={kind:`cancel-turn`});let c=n.taskId===void 0?n.childContinuationToken:`${n.childContinuationToken}\0${n.childResponseUrl??`local`}\0${n.taskId}`,l=r.get(c);l===void 0?r.set(c,{childContinuationToken:n.childContinuationToken,parentRequestIds:[i.requestId],responses:[toChildInputResponse(i,n)],routes:[n],...n.childResponseUrl!==void 0&&{childResponseUrl:n.childResponseUrl},...n.taskId!==void 0&&{taskId:n.taskId}}):(l.parentRequestIds.push(i.requestId),l.responses.push(toChildInputResponse(i,n)),l.routes.push(n))}let c=[...r.values()].map(({childContinuationToken:e,childResponseUrl:n,parentRequestIds:r,responses:i,routes:a,taskId:o})=>{let s=new Set(r),c=new Set(s);for(let n of a)if(n.batch!==void 0&&batchResolves({batch:n.batch,childContinuationToken:e,entries:t,responseIds:s}))for(let e of n.batch.requestIds)c.add(e);return{childContinuationToken:e,payload:{inputResponses:i},retireRequestIds:[...c],...n!==void 0&&{childResponseUrl:n},...o!==void 0&&{taskId:o}}}),l={};for(let[t,n]of Object.entries(e.payload))t===`inputResponses`||n===void 0||(l[t]=n);return a.length>0&&(l.inputResponses=a),{forChildren:c,forSelf:Object.keys(l).length>0?l:void 0,parentAction:s}}function batchResolves(e){return e.batch.approvalRequestIds.length===0||e.batch.approvalRequestIds.every(t=>{let n=e.entries.get(t);return n===void 0||!sameBatch(n,e)||e.responseIds.has(t)})}function sameBatch(e,t){return e.childContinuationToken===t.childContinuationToken&&e.batch?.requestIds.length===t.batch.requestIds.length&&e.batch.requestIds.every((e,n)=>e===t.batch.requestIds[n])}function toChildInputResponse(e,t){return t.childRequestId===void 0?e:{...e,requestId:t.childRequestId}}export{emitProxiedInputRequest,routeDeliverPayload};
@@ -0,0 +1,29 @@
1
+ import type { DispatchOutcome, RuntimeSession } from "#execution/agent-handle-dispatch.js";
2
+ import { buildSubagentRunInput, type SubagentInputSource } from "#execution/subagent-tool.js";
3
+ import { createWorkflowRuntime } from "#execution/workflow-runtime.js";
4
+ import type { RuntimeSubagentCallActionRequest } from "#runtime/actions/types.js";
5
+ import type { CompiledBundle } from "#runtime/sessions/runtime-context-keys.js";
6
+ type DynamicSubagentAgentConfig = Parameters<typeof createWorkflowRuntime>[0]["dynamicSubagentAgentConfig"];
7
+ /** Starts one local subagent after dispatch planning has selected its target. */
8
+ export declare function startLocalSubagent(input: {
9
+ readonly action: RuntimeSubagentCallActionRequest;
10
+ readonly auth: Parameters<typeof buildSubagentRunInput>[0]["auth"];
11
+ readonly batchEvent: {
12
+ readonly sequence: number;
13
+ readonly turnId: string;
14
+ };
15
+ readonly bundle: CompiledBundle;
16
+ readonly capabilities: Parameters<typeof buildSubagentRunInput>[0]["capabilities"];
17
+ readonly channelMetadata: Parameters<typeof buildSubagentRunInput>[0]["channelMetadata"];
18
+ readonly currentSession: RuntimeSession;
19
+ readonly dynamicSubagentAgentConfig?: DynamicSubagentAgentConfig;
20
+ readonly fanoutSize: number;
21
+ readonly initiatorAuth: Parameters<typeof buildSubagentRunInput>[0]["initiatorAuth"];
22
+ readonly parentContinuationToken: string | undefined;
23
+ readonly parentTraceContext: Parameters<typeof buildSubagentRunInput>[0]["parentTraceContext"];
24
+ readonly persistentSessions: boolean;
25
+ readonly session: RuntimeSession;
26
+ readonly source: SubagentInputSource;
27
+ readonly taskOwned: boolean;
28
+ }): Promise<DispatchOutcome>;
29
+ export {};
@@ -0,0 +1 @@
1
+ import{createLogger,logError}from"#internal/logging.js";import{isRuntimeSessionOwnershipConflictError}from"#execution/runtime-errors.js";import{toErrorMessage}from"#shared/errors.js";import{SUBAGENT_START_FAILED}from"#harness/agent-handle-errors.js";import{confirmAgentStarted,confirmTaskAgentAddress,prepareAgentStart,rejectAgentEffect}from"#harness/handles/transitions.js";import{createWorkflowRuntime}from"#execution/workflow-runtime.js";import{buildSubagentRunInput}from"#execution/subagent-tool.js";import{mintStartOperation}from"#execution/dispatch-start-operation.js";const log=createLogger(`execution.subagent-start-local`);async function startLocalSubagent(e){let{action:t,source:n}=e,r=createWorkflowRuntime({compiledArtifactsSource:e.bundle.compiledArtifactsSource,dynamicSubagentAgentConfig:e.dynamicSubagentAgentConfig,nodeId:t.nodeId}),{childContinuationToken:i,runInput:a}=buildSubagentRunInput({action:t,auth:e.auth,batchEvent:e.batchEvent,capabilities:e.capabilities,channelMetadata:e.channelMetadata,fanoutSize:e.fanoutSize,initiatorAuth:e.initiatorAuth,parentContinuationToken:e.parentContinuationToken,parentTraceContext:e.parentTraceContext,persistentSessions:e.persistentSessions,session:e.session,source:n}),o=n.type===`runtime`?`agent/self`:`agent/local`,{identity:s,operation:c}=mintStartOperation({callId:t.callId,name:t.subagentName,nodeId:t.nodeId,parentSessionId:e.session.sessionId,parentTurnId:e.batchEvent.turnId}),l=prepareAgentStart(e.currentSession,{identity:s,operation:c,target:{continuationToken:i,kind:o}}),u;try{u=(await r.createSession(a)).sessionId}catch(e){if(!isRuntimeSessionOwnershipConflictError(e))return logError(log,`local subagent start failed`,e,{callId:t.callId,nodeId:t.nodeId,subagentName:t.subagentName}),{kind:`error`,result:{callId:t.callId,isError:!0,kind:`subagent-result`,origin:`dispatch`,output:{code:SUBAGENT_START_FAILED,message:toErrorMessage(e)},subagentName:t.subagentName},session:rejectAgentEffect(l,{disposition:`dead`,operationId:c.id})};u=e.ownerSessionId}let d={continuationToken:i,kind:o,sessionId:u};return{address:d,callId:t.callId,kind:`called`,name:t.name,session:e.taskOwned?confirmTaskAgentAddress(l,{address:d,operationId:c.id}):confirmAgentStarted(l,{address:d,operationId:c.id}),toolName:t.subagentName}}export{startLocalSubagent};
@@ -0,0 +1,23 @@
1
+ import type { DispatchOutcome, RuntimeSession } from "#execution/agent-handle-dispatch.js";
2
+ import { resolveRemoteAgentForAction, startRemoteAgentSession } from "#execution/remote-agent-dispatch.js";
3
+ import type { RuntimeRemoteAgentCallActionRequest } from "#runtime/actions/types.js";
4
+ import type { CompiledBundle } from "#runtime/sessions/runtime-context-keys.js";
5
+ /** Starts one remote subagent after dispatch planning has selected its target. */
6
+ export declare function startRemoteSubagent(input: {
7
+ readonly action: RuntimeRemoteAgentCallActionRequest;
8
+ readonly auth: Parameters<typeof startRemoteAgentSession>[0]["auth"];
9
+ readonly batchEvent: {
10
+ readonly sequence: number;
11
+ readonly turnId: string;
12
+ };
13
+ readonly bundle: CompiledBundle;
14
+ readonly callbackBaseUrl: string | undefined;
15
+ readonly currentSession: RuntimeSession;
16
+ readonly dynamicRemoteAgent?: NonNullable<Parameters<typeof resolveRemoteAgentForAction>[0]["dynamicRemoteAgent"]>;
17
+ readonly initiatorAuth: Parameters<typeof startRemoteAgentSession>[0]["initiatorAuth"];
18
+ readonly parentContinuationToken: string | undefined;
19
+ readonly parentTraceContext: Parameters<typeof startRemoteAgentSession>[0]["parentTraceContext"];
20
+ readonly persistentSessions: boolean;
21
+ readonly session: RuntimeSession;
22
+ readonly taskOwned: boolean;
23
+ }): Promise<DispatchOutcome>;
@@ -0,0 +1 @@
1
+ import{createLogger,logError}from"#internal/logging.js";import{resolveRemoteAgentForAction,startRemoteAgentSession}from"#execution/remote-agent-dispatch.js";import{confirmAgentStarted,confirmTaskAgentAddress,prepareAgentStart,rejectAgentEffect}from"#harness/handles/transitions.js";import{createRemoteAgentStartFailureResult}from"#execution/dispatch-action-failures.js";import{mintStartOperation}from"#execution/dispatch-start-operation.js";const log=createLogger(`execution.subagent-start-remote`);async function startRemoteSubagent(e){let{action:r}=e,i,a;try{if(e.callbackBaseUrl===void 0)throw Error(`Cannot dispatch remote agent without a callback base URL.`);i=e.callbackBaseUrl,a=resolveRemoteAgentForAction({dynamicRemoteAgent:e.dynamicRemoteAgent,nodeId:r.nodeId,remoteAgentName:r.remoteAgentName,registry:e.bundle.subagentRegistry.subagentsByNodeId})}catch(n){return logError(log,`remote agent start failed`,n,{remoteAgentName:r.remoteAgentName,nodeId:r.nodeId,callId:r.callId}),{kind:`error`,result:createRemoteAgentStartFailureResult({action:r,error:n}),session:e.currentSession}}let{identity:o,operation:s}=mintStartOperation({callId:r.callId,name:r.remoteAgentName,nodeId:r.nodeId,parentSessionId:e.session.sessionId,parentTurnId:e.batchEvent.turnId}),c=prepareAgentStart(e.currentSession,{identity:o,operation:s,target:{callbackBaseUrl:i,kind:`agent/remote`,url:a.url}});try{let t=await startRemoteAgentSession({action:r,auth:e.auth,callbackBaseUrl:i,callbackToken:e.parentContinuationToken,initiatorAuth:e.initiatorAuth,operationId:s.id,parentTraceContext:e.parentTraceContext,persistentSessions:e.persistentSessions,remote:a,session:e.session}),n={callbackBaseUrl:i,kind:`agent/remote`,sessionId:t.sessionId,url:a.url};return{address:n,callId:r.callId,kind:`called`,name:r.name,session:e.taskOwned?confirmTaskAgentAddress(c,{address:n,operationId:s.id}):confirmAgentStarted(c,{address:n,operationId:s.id}),toolName:r.remoteAgentName}}catch(e){return logError(log,`remote agent start failed`,e,{remoteAgentName:r.remoteAgentName,nodeId:r.nodeId,callId:r.callId}),{kind:`error`,result:createRemoteAgentStartFailureResult({action:r,error:e}),session:rejectAgentEffect(c,{disposition:`dead`,operationId:s.id})}}}export{startRemoteSubagent};
@@ -0,0 +1,13 @@
1
+ import type { ContextContainer } from "#context/container.js";
2
+ import type { UnstampedMessageStreamEvent } from "#protocol/message.js";
3
+ /**
4
+ * Forwards one task child's blocking transition to its parent's session
5
+ * callback.
6
+ *
7
+ * Task children report HITL and authorization transitions to the parent's
8
+ * task run before local emission, so the run can block/unblock the task
9
+ * under one durable decision. A session without a callback capability
10
+ * (non-delegated runs) is a no-op, as is any event outside the three
11
+ * blocking transitions.
12
+ */
13
+ export declare function forwardTaskEventToSessionCallback(ctx: ContextContainer, event: UnstampedMessageStreamEvent): Promise<void>;
@@ -0,0 +1 @@
1
+ import{ContinuationTokenKey,SessionCallbackKey,SessionIdKey}from"#context/keys.js";import{fireTaskEventCallbackStep}from"#execution/session-callback-step.js";async function forwardTaskEventToSessionCallback(e,t){let n=e.get(SessionCallbackKey);n!==void 0&&(t.type!==`input.requested`&&t.type!==`authorization.required`&&t.type!==`authorization.completed`||await fireTaskEventCallbackStep({callback:n,childContinuationToken:e.require(ContinuationTokenKey),childSessionId:e.require(SessionIdKey),event:t}))}export{forwardTaskEventToSessionCallback};
@@ -0,0 +1,4 @@
1
+ /** Narrows one private create-once session token to task-input delivery only. */
2
+ export declare function createTaskInputCapabilityToken(operationToken: string): string;
3
+ /** Resolves a task-input capability to the create-once session hook it may address. */
4
+ export declare function readTaskInputTargetToken(capabilityToken: string): string | undefined;
@@ -0,0 +1 @@
1
+ const OPERATION_TOKEN_PREFIX=`eve:eve:op:`,TASK_INPUT_TOKEN_PREFIX=`eve:task-input:`,TOKEN_DIGEST=/^[a-f0-9]{32}$/;function createTaskInputCapabilityToken(n){let r=readTokenDigest(n,OPERATION_TOKEN_PREFIX);if(r===void 0)throw Error(`Remote task input requires an eve create-once session capability.`);return`${TASK_INPUT_TOKEN_PREFIX}${r}`}function readTaskInputTargetToken(n){let r=readTokenDigest(n,TASK_INPUT_TOKEN_PREFIX);return r===void 0?void 0:`${OPERATION_TOKEN_PREFIX}${r}`}function readTokenDigest(e,t){if(!e.startsWith(t))return;let r=e.slice(t.length);return TOKEN_DIGEST.test(r)?r:void 0}export{createTaskInputCapabilityToken,readTaskInputTargetToken};
@@ -0,0 +1,46 @@
1
+ import { type TaskInboundAnswerInput, type TaskInboundAuthorizationEvent, type TaskInboundInputRequest, type TaskView } from "#tasks/types.js";
2
+ /**
3
+ * Appends one full task view to the owning task run's `eve.task`
4
+ * stream. Only the task run workflow calls this, which is what makes
5
+ * the run the single writer readers can trust without re-validating.
6
+ */
7
+ export declare function appendTaskViewStep(input: {
8
+ readonly view: TaskView;
9
+ }): Promise<void>;
10
+ /** Re-emits a task-owned child authorization event through the parent channel. */
11
+ export declare function wakeTaskAuthorizationParentStep(input: {
12
+ readonly request: TaskInboundAuthorizationEvent;
13
+ readonly taskId: string;
14
+ readonly token: string;
15
+ }): Promise<void>;
16
+ /**
17
+ * Wakes the parent session with a framework task notification.
18
+ *
19
+ * Rides the ordinary session delivery path: a parked parent starts a
20
+ * turn carrying this message, while an active turn observes it at the
21
+ * next safe boundary through the driver's normal delivery routing. A
22
+ * parent whose session already ended is a tolerated no-op.
23
+ */
24
+ export declare function wakeTaskParentStep(input: {
25
+ readonly token: string;
26
+ readonly view: TaskView;
27
+ }): Promise<void>;
28
+ /** Sends an exact local-task HITL batch to the parent's pre-model router. */
29
+ export declare function wakeTaskInputRequestParentStep(input: {
30
+ readonly request: TaskInboundInputRequest;
31
+ readonly taskId: string;
32
+ readonly token: string;
33
+ }): Promise<void>;
34
+ /**
35
+ * Forwards answered input to the blocked child.
36
+ *
37
+ * The task run performs this itself so the child unblocks and the
38
+ * view leaves `input_required` under one durable decision. Returns
39
+ * `unreachable` when the child hook is already gone, which leaves the
40
+ * outstanding batch untouched rather than reporting a task as working
41
+ * when nothing received the answer.
42
+ */
43
+ export declare function deliverTaskInputResponsesStep(input: {
44
+ readonly answer: TaskInboundAnswerInput;
45
+ readonly requestIds: readonly string[];
46
+ }): Promise<"delivered" | "unreachable">;
@@ -0,0 +1 @@
1
+ import{createLogger}from"#internal/logging.js";import{resumeHook}from"#internal/workflow/runtime.js";import{getWritable}from"#compiled/@workflow/core/index.js";import{isTaskWorkflowTargetGone}from"#execution/tasks/workflow-target.js";import{TASK_VIEW_STREAM_NAMESPACE,isTerminalTaskStatus,taskAuthorizationRequestId}from"#tasks/types.js";const log=createLogger(`execution.tasks.run`);async function appendTaskViewStep(e){"use step";let t=getWritable({namespace:TASK_VIEW_STREAM_NAMESPACE}).getWriter();try{await t.write(e.view)}finally{t.releaseLock()}}async function wakeTaskAuthorizationParentStep(e){"use step";let n={callId:e.request.callId,childSessionId:e.request.childSessionId,event:e.request.event,kind:`subagent-authorization-event`,subagentName:e.request.subagentName},r=e.request.event.data,i={task:{authorizationEvents:[{hookPayload:n,taskId:e.taskId}]}};e.request.event.type===`authorization.required`&&(i.message=`Background task ${e.taskId} needs authorization.`);let a={kind:`send`,payload:i,taskDeliveryId:`${e.taskId}:authorization:${e.request.event.type}:${r.turnId}:${r.stepIndex}:${r.sequence}:${taskAuthorizationRequestId(e.request.event)}`};try{await resumeHook(e.token,a)}catch(e){if(isTaskWorkflowTargetGone(e))return;throw e}}async function wakeTaskParentStep(e){"use step";let n={message:formatTaskNotification(e.view)};isTerminalTaskStatus(e.view.status)&&(n.task={views:[e.view]});let r={kind:`send`,payload:n,taskDeliveryId:`${e.view.taskId}:ready:${e.view.status}`};try{await resumeHook(e.token,r)}catch(t){if(isTaskWorkflowTargetGone(t)){log.warn(`task wake target is gone; the parent session already ended`,{status:e.view.status,taskId:e.view.taskId});return}throw t}}async function wakeTaskInputRequestParentStep(e){"use step";let n={kind:`send`,payload:{task:{inputRequests:[{hookPayload:e.request,taskId:e.taskId}]}},taskDeliveryId:`${e.taskId}:input:${e.request.event.turnId}:${e.request.event.stepIndex}:${e.request.event.sequence}`};try{await resumeHook(e.token,n)}catch(e){if(isTaskWorkflowTargetGone(e))return;throw e}}async function deliverTaskInputResponsesStep(e){"use step";let n=new Set(e.requestIds),r={auth:e.answer.auth,kind:`send`,payload:{inputResponses:e.answer.inputResponses.filter(e=>n.has(e.requestId))},taskDeliveryId:`${e.answer.taskId}:${[...e.requestIds].sort().join(`,`)}`};try{if(e.answer.childResponseUrl!==void 0){let t=await fetch(e.answer.childResponseUrl,{body:JSON.stringify({inputResponses:r.payload.inputResponses}),headers:{"content-type":`application/json`},method:`POST`,redirect:`error`});if(t.status===404)return`unreachable`;if(!t.ok)throw Error(`Remote task input delivery failed with HTTP ${t.status}.`)}else await resumeHook(e.answer.childContinuationToken,r);return`delivered`}catch(t){if(isTaskWorkflowTargetGone(t))return log.warn(`task input answer target is gone; the child turn already ended`,{taskId:e.answer.taskId}),`unreachable`;throw t}}function formatTaskNotification(e){let t=`Background task ${e.taskId} (${e.metadata.name})`;return e.status===`input_required`?`${t} needs input. Use task_peek to inspect the outstanding requests.`:`${t} is ${e.status}. Use task_peek to read its output.`}export{appendTaskViewStep,deliverTaskInputResponsesStep,wakeTaskAuthorizationParentStep,wakeTaskInputRequestParentStep,wakeTaskParentStep};
@@ -0,0 +1,31 @@
1
+ import { type TaskView } from "#tasks/types.js";
2
+ /** Input for one durable task run. */
3
+ export interface TaskRunWorkflowInput {
4
+ /** Private task inbox token; a routing credential, never model-visible. */
5
+ readonly taskInboxToken: string;
6
+ /** The creation view, normally `working`. */
7
+ readonly initialView: TaskView;
8
+ /** Parent session delivery token used to wake the task's owning parent. */
9
+ readonly parentContinuationToken: string;
10
+ }
11
+ /**
12
+ * The durable task run: single writer for one task's lifecycle.
13
+ *
14
+ * Consumes commands and child wire payloads over its private hook,
15
+ * applies the pure transition function, and appends a full `TaskView`
16
+ * per accepted command to its `eve.task` run stream. Competing
17
+ * completion, cancellation, and input transitions serialize here;
18
+ * rejected commands (for example a late child result after `cancelled`)
19
+ * change nothing.
20
+ *
21
+ * Wake policy: a transition into a ready status — terminal or
22
+ * `input_required` — delivers a framework notification to the parent
23
+ * session. A parked parent starts a turn; an active turn observes the
24
+ * delivery at its next safe boundary. Nothing else wakes the parent.
25
+ *
26
+ * The run ends when the task reaches a terminal status. Its view
27
+ * stream stays readable, so terminal tasks remain peekable; the
28
+ * disposed hook makes any later command fail loudly instead of queueing
29
+ * against a finished task.
30
+ */
31
+ export declare function taskRunWorkflow(input: TaskRunWorkflowInput): Promise<void>;
@@ -0,0 +1 @@
1
+ import{createHook}from"#compiled/@workflow/core/index.js";import{claimHookOwnership,disposeHook,isHookConflictError}from"#execution/hook-ownership.js";import{isReadyTaskStatus,isTerminalTaskStatus,readTaskInputRequestId,readTaskUsage}from"#tasks/types.js";import{appendTaskViewStep,deliverTaskInputResponsesStep,wakeTaskAuthorizationParentStep,wakeTaskInputRequestParentStep,wakeTaskParentStep}from"#execution/tasks/child/steps.js";import{applyTaskTransition}from"#tasks/transitions.js";import{translateTaskInboundPayload}from"#tasks/wire.js";function isTaskRunFinished(e,t){return!isTerminalTaskStatus(e.status)||!t?!1:e.status!==`cancelled`||e.executor?.lifecycle===`terminal`}async function taskRunWorkflow(i){"use workflow";let a=createHook({token:i.taskInboxToken}),o=a[Symbol.asyncIterator](),s=!1;try{try{await claimHookOwnership(a),s=!0}catch(e){if(isHookConflictError(e))return;throw e}let e=i.initialView,n,c=[],l=!1;for(await appendTaskViewStep({view:e});!isTaskRunFinished(e,l);){let t=await o.next();if(t.done===!0)return;let r=t.value.kind===`subagent-authorization-event`?{...t.value,kind:`authorization-event`}:t.value;if(r.kind===`authorization-event`&&(r.event.type===`approval.candidate`||r.event.type===`approval.settled`))continue;let a=r.kind===`task-command`&&r.command.kind===`ready`,s=r.kind===`task-command`&&r.command.kind===`reject-dispatch`;(a||s)&&(l=!0),r.kind===`subagent-input-request`&&(n=r),r.kind===`authorization-event`&&c.push(r);let u=e.status===`cancelled`&&r.kind===`runtime-action-result`,d=r.kind===`input-response`,f;if(u)f={kind:`settle-executor`,usage:readTaskUsage(r.results[0]?.outcome?.usageDelta)};else if(d){if(e.status!==`input_required`)continue;f=await resolveAnsweredCommand(e,r)}else f=translateTaskInboundPayload(r);if(f===void 0)continue;if(a&&isTerminalTaskStatus(e.status)){await wakeTaskParentStep({token:i.parentContinuationToken,view:e});continue}let p=applyTaskTransition(e,f);if(p.outcome!==`accepted`)continue;let m=!isTerminalTaskStatus(e.status)&&isTerminalTaskStatus(p.view.status),h=!isReadyTaskStatus(e.status)&&isReadyTaskStatus(p.view.status);e=p.view,await appendTaskViewStep({view:e});let g=l&&!m?c:[];for(let t of g)await wakeTaskAuthorizationParentStep({request:t,taskId:e.taskId,token:i.parentContinuationToken});(m||g.length>0)&&(c=[]),n!==void 0&&l&&e.status===`input_required`?(await wakeTaskInputRequestParentStep({request:n,taskId:e.taskId,token:i.parentContinuationToken}),n=void 0):!s&&g.length===0&&l&&(m||h&&n===void 0)&&await wakeTaskParentStep({token:i.parentContinuationToken,view:e}),e.status!==`input_required`&&(n=void 0)}}finally{s&&await disposeHook(a)}}async function resolveAnsweredCommand(e,t){if(t.taskId!==e.taskId)return;let n=new Set(e.inputRequests.flatMap(e=>{let t=readTaskInputRequestId(e);return t===void 0?[]:[t]})),r=t.inputResponses.map(e=>e.requestId).filter(e=>n.has(e));return r.length===0?void 0:await deliverTaskInputResponsesStep({answer:t,requestIds:r})===`delivered`?{kind:`answered`,requestIds:r}:void 0}export{taskRunWorkflow};
@@ -0,0 +1,13 @@
1
+ import type { RuntimeAgentHandleAction } from "#execution/agent-handle-dispatch.js";
2
+ /** Resolves the persistent agent identity attached to one delegated task. */
3
+ export declare function describeTaskAgent(input: {
4
+ readonly action: RuntimeAgentHandleAction;
5
+ readonly agentId?: string;
6
+ readonly parentSessionId: string;
7
+ readonly parentTurnId: string;
8
+ }): {
9
+ readonly agentId: string;
10
+ readonly callId: string;
11
+ readonly mode: "local" | "remote";
12
+ readonly name: string;
13
+ };
@@ -0,0 +1 @@
1
+ import{mintStartOperation}from"#execution/dispatch-start-operation.js";function describeTaskAgent(e){let{action:t}=e,n=t.kind===`remote-agent-call`?t.remoteAgentName:t.subagentName;return{agentId:e.agentId??mintStartOperation({callId:t.callId,name:n,nodeId:t.nodeId,parentSessionId:e.parentSessionId,parentTurnId:e.parentTurnId}).identity.id,callId:t.callId,mode:t.kind===`remote-agent-call`?`remote`:`local`,name:n}}export{describeTaskAgent};
@@ -0,0 +1,6 @@
1
+ import type { HarnessSession } from "#harness/types.js";
2
+ import { type AgentView } from "#harness/handles/prompt.js";
3
+ /** Derives model-visible task-agent availability from authoritative task views. */
4
+ export declare function readTaskAgentViews(session: HarnessSession): Promise<readonly AgentView[]>;
5
+ /** Appends the changed task-agent projection before the next model call. */
6
+ export declare function appendTaskAgentAnnouncement(session: HarnessSession): Promise<HarnessSession>;
@@ -0,0 +1 @@
1
+ import{formatAgentStatus,getAgentHandleStore}from"#harness/handles/store.js";import{getSessionTaskIndex}from"#tasks/session-index.js";import{resolveAgentsAnnouncement}from"#harness/handles/prompt.js";import{readTaskViews}from"#execution/tasks/parent/control-shared.js";async function readTaskAgentViews(r){let a=(getAgentHandleStore(r.state)?.handles??[]).filter(e=>e.phase===`addressed`);if(a.length===0)return[];let o=await readTaskViews(getSessionTaskIndex(r.state)),s=new Map;for(let e of o){let t=s.get(e.metadata.agentId)??[];s.set(e.metadata.agentId,[...t,e])}return a.map(t=>{let n=s.get(t.identity.id)??[],r=n.filter(e=>e.status===`working`||e.status===`input_required`);if(r.length>1)throw Error(`Agent "${t.identity.id}" has more than one nonterminal task.`);let i=r[0];if(i!==void 0){let e=i.status===`input_required`?`input_required`:`working`;return{availability:`busy`,id:t.identity.id,name:t.identity.name,taskId:i.taskId,taskStatus:e}}let a=n.at(-1);return{availability:`available`,id:t.identity.id,name:t.identity.name,statusLine:a?.lastOutput===void 0?void 0:formatAgentStatus(a.lastOutput.data)}})}async function appendTaskAgentAnnouncement(e){let n=resolveAgentsAnnouncement({agentViews:await readTaskAgentViews(e),messages:e.history,store:getAgentHandleStore(e.state)});return n===void 0?e:{...e,history:[...e.history,{content:n,role:`user`}]}}export{appendTaskAgentAnnouncement,readTaskAgentViews};
@@ -0,0 +1,37 @@
1
+ import { type DispatchOutcome, type RuntimeAgentHandleAction, type RuntimeSession } from "#execution/agent-handle-dispatch.js";
2
+ import { settleDelegatedDispatch, type DelegatedTask } from "#execution/tasks/parent/delegate.js";
3
+ import { describeTaskAgent } from "#execution/tasks/parent/agent-identity.js";
4
+ import type { RuntimeSubagentDispatchFailure } from "#runtime/actions/types.js";
5
+ export type PersistedContinuationTask = Awaited<ReturnType<typeof settleDelegatedDispatch>>;
6
+ /** Describes task identity from the stored address when continuing an agent. */
7
+ export declare function describeTaskDispatch(input: {
8
+ readonly action: RuntimeAgentHandleAction;
9
+ readonly agentId: string | undefined;
10
+ readonly parentSessionId: string;
11
+ readonly parentTurnId: string;
12
+ readonly session: RuntimeSession;
13
+ }): ReturnType<typeof describeTaskAgent>;
14
+ export declare function checkTaskContinuationAvailability(input: {
15
+ readonly action: RuntimeAgentHandleAction;
16
+ readonly agentId: string;
17
+ readonly parentStepIndex: number;
18
+ readonly parentTurnId: string;
19
+ readonly session: RuntimeSession;
20
+ }): Promise<RuntimeSubagentDispatchFailure | undefined>;
21
+ /**
22
+ * Persists the task's ownership and routing entry in the parent session's
23
+ * `eve.tasks` index and creates its parked tool-call receipt before dispatch.
24
+ */
25
+ export declare function persistContinuationTaskInParentSession(input: {
26
+ readonly action: RuntimeAgentHandleAction;
27
+ readonly agentId: string;
28
+ readonly delegated: DelegatedTask;
29
+ readonly session: RuntimeSession;
30
+ }): Promise<PersistedContinuationTask | undefined>;
31
+ export declare function settleTaskDispatchError(input: {
32
+ readonly delegated: DelegatedTask;
33
+ readonly outcome: Extract<DispatchOutcome, {
34
+ readonly kind: "error";
35
+ }>;
36
+ readonly persisted: PersistedContinuationTask | undefined;
37
+ }): Promise<RuntimeSubagentDispatchFailure>;
@@ -0,0 +1 @@
1
+ import{AGENT_BUSY}from"#harness/agent-handle-errors.js";import{createAgentErrorResult}from"#execution/agent-handle-dispatch.js";import{findActiveTaskForAgent,findTaskAgentAddress}from"#execution/tasks/parent/control-shared.js";import{failDelegatedDispatch,rejectDelegatedDispatch,settleDelegatedDispatch}from"#execution/tasks/parent/delegate.js";import{describeTaskAgent}from"#execution/tasks/parent/agent-identity.js";function describeTaskDispatch(e){let t=describeTaskAgent(e),n=e.agentId===void 0?void 0:findTaskAgentAddress(e.session,e.agentId);return n===void 0?t:{...t,mode:n.address.kind===`agent/remote`?`remote`:`local`}}async function checkTaskContinuationAvailability(r){let i=await findActiveTaskForAgent(r.session,r.agentId,r.parentTurnId,r.parentStepIndex);return i===void 0?void 0:createAgentErrorResult({action:r.action,code:AGENT_BUSY,message:`Agent "${r.agentId}" is busy with task "${i.view.taskId}" (${i.view.status}).`})}async function persistContinuationTaskInParentSession(e){let t=findTaskAgentAddress(e.session,e.agentId);if(t!==void 0)return settleDelegatedDispatch({callId:e.action.callId,session:e.session,subagentName:t.identity.name,task:e.delegated})}async function settleTaskDispatchError(e){return e.persisted!==void 0&&e.outcome.deliveryAmbiguous===!0||await(e.persisted===void 0?rejectDelegatedDispatch:failDelegatedDispatch)({error:e.outcome.result.output,task:e.delegated}),e.persisted===void 0?e.outcome.result:{...e.outcome.result,output:attachTaskId(e.outcome.result.output,e.delegated.taskId)}}function attachTaskId(e,t){return typeof e==`object`&&e&&!Array.isArray(e)?{...e,taskId:t}:{error:e,taskId:t}}export{checkTaskContinuationAvailability,describeTaskDispatch,persistContinuationTaskInParentSession,settleTaskDispatchError};
@@ -0,0 +1,36 @@
1
+ import type { RuntimeSession } from "#execution/agent-handle-dispatch.js";
2
+ import { type AgentHandle } from "#harness/handles/store.js";
3
+ import type { RuntimeActionResult, RuntimeToolCallActionRequest } from "#runtime/actions/types.js";
4
+ import { type SessionTaskIndexEntry } from "#tasks/session-index.js";
5
+ import type { TaskView } from "#tasks/types.js";
6
+ /**
7
+ * Result and lookup helpers shared by the task-control executors
8
+ * (`task_peek`/`task_cancel` in the dispatch module,
9
+ * `task_send` in its own).
10
+ */
11
+ /** Resolves owned index entries, or the ids this session does not own. */
12
+ export declare function lookupTaskEntries(session: RuntimeSession, taskIds: readonly string[]): {
13
+ readonly entries: SessionTaskIndexEntry[];
14
+ readonly kind: "found";
15
+ } | {
16
+ readonly kind: "unknown";
17
+ readonly unknown: string[];
18
+ };
19
+ /** Reads the latest view of every entry, defaulting to `working`. */
20
+ export declare function readTaskViews(entries: readonly SessionTaskIndexEntry[]): Promise<TaskView[]>;
21
+ export declare function readTaskView(entry: SessionTaskIndexEntry): Promise<TaskView>;
22
+ /** Finds the persistent address record for one task-owned agent. */
23
+ export declare function findTaskAgentAddress(session: RuntimeSession, agentId: string): Extract<AgentHandle, {
24
+ phase: "addressed";
25
+ }> | undefined;
26
+ /** Returns the one nonterminal task owning an agent, if any. */
27
+ export declare function findActiveTaskForAgent(session: RuntimeSession, agentId: string, parentTurnId?: string, parentStepIndex?: number): Promise<{
28
+ readonly entry: SessionTaskIndexEntry;
29
+ readonly view: TaskView;
30
+ } | undefined>;
31
+ /** One successful task-control result carrying full task views. */
32
+ export declare function createTaskViewsResult(action: RuntimeToolCallActionRequest, views: readonly TaskView[]): RuntimeActionResult;
33
+ /** One task-control error the model can act on. */
34
+ export declare function createTaskControlError(action: RuntimeToolCallActionRequest, message: string): RuntimeActionResult;
35
+ /** The ownership error for ids outside this session's task index. */
36
+ export declare function createUnknownTasksError(action: RuntimeToolCallActionRequest, unknown: readonly string[]): RuntimeActionResult;
@@ -0,0 +1 @@
1
+ import{getAgentHandleStore}from"#harness/handles/store.js";import{readLatestTaskView}from"#execution/tasks/parent/run-parent.js";import{findSessionTaskEntry,getSessionTaskIndex}from"#tasks/session-index.js";import{isTaskWorkflowTargetGone}from"#execution/tasks/workflow-target.js";import{taskViewsToJson}from"#tasks/json.js";function lookupTaskEntries(e,t){let r=[],i=[];for(let a of t){let t=findSessionTaskEntry(e.state,a);t===void 0?i.push(a):r.push(t)}return i.length>0?{kind:`unknown`,unknown:i}:{entries:r,kind:`found`}}async function readTaskViews(e){return Promise.all(e.map(readTaskView))}async function readTaskView(e){try{return await readLatestTaskView({taskRunId:e.taskRunId})??createPendingTaskView(e)}catch(t){if(isTaskWorkflowTargetGone(t)&&e.terminalView!==void 0)return e.terminalView;throw t}}function createPendingTaskView(e){return{metadata:e.metadata,status:`working`,taskId:e.taskId}}function findTaskAgentAddress(t,n){return(getAgentHandleStore(t.state)?.handles??[]).find(e=>e.phase===`addressed`&&e.identity.id===n)}async function findActiveTaskForAgent(e,t,n,i){let a=getSessionTaskIndex(e.state).filter(e=>e.metadata.agentId===t),o=await readTaskViews(a);return a.flatMap((e,t)=>{let r=o[t];return r!==void 0&&(e.createdByTurnId===n&&e.createdByStepIndex===i||r.status===`working`||r.status===`input_required`)?[{entry:e,view:r}]:[]})[0]}function createTaskViewsResult(e,t){return{callId:e.callId,kind:`tool-result`,output:taskViewsToJson(t),toolName:e.toolName}}function createTaskControlError(e,t){return{callId:e.callId,isError:!0,kind:`tool-result`,output:{message:t},toolName:e.toolName}}function createUnknownTasksError(e,t){return createTaskControlError(e,`Unknown task ids: ${t.join(`, `)}. Tasks belong to the session that created them.`)}export{createTaskControlError,createTaskViewsResult,createUnknownTasksError,findActiveTaskForAgent,findTaskAgentAddress,lookupTaskEntries,readTaskView,readTaskViews};
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Delegation policy for the subagent dispatch path: derives task identity,
3
+ * builds metadata and the parked-tool-call receipt, records the session
4
+ * index, and defines failure semantics for an unacknowledged dispatch.
5
+ * Task-run transport (start/command/view) lives in `run-parent.ts`, which
6
+ * this module composes and which other non-delegation callers share.
7
+ */
8
+ import type { RuntimeSession } from "#execution/agent-handle-dispatch.js";
9
+ import type { RuntimeSubagentChildResult } from "#runtime/actions/types.js";
10
+ import type { JsonValue } from "#shared/json.js";
11
+ import { type TaskMetadata } from "#tasks/types.js";
12
+ /** A prepared delegated task: identity plus its started durable run. */
13
+ export interface DelegatedTask {
14
+ readonly taskInboxToken: string;
15
+ readonly createdByStepIndex?: number;
16
+ readonly createdByTurnId: string;
17
+ readonly metadata: TaskMetadata;
18
+ readonly operationId: string;
19
+ readonly taskId: string;
20
+ readonly taskRunId: string;
21
+ }
22
+ /**
23
+ * Creates the durable task record for one delegated subagent call,
24
+ * before the child dispatch side effect. The task must exist first so
25
+ * a fast child always finds a live command hook; a duplicate replay
26
+ * re-derives the same token and the loser exits on the hook claim.
27
+ */
28
+ export declare function beginDelegatedTask(input: {
29
+ readonly agentId: string;
30
+ readonly callId: string;
31
+ readonly mode: "local" | "remote";
32
+ readonly name: string;
33
+ readonly parentSessionId: string;
34
+ readonly parentStepIndex?: number;
35
+ readonly parentTurnId: string;
36
+ readonly session: RuntimeSession;
37
+ }): Promise<DelegatedTask>;
38
+ /**
39
+ * Settles a delegated dispatch that acknowledged a child: persists the task
40
+ * in the session index and returns the receipt that resolves the originating
41
+ * tool call. Agent identity and routing remain in the persistent address
42
+ * record; task state owns execution availability.
43
+ */
44
+ export declare function settleDelegatedDispatch(input: {
45
+ readonly callId: string;
46
+ readonly session: RuntimeSession;
47
+ readonly subagentName: string;
48
+ readonly task: DelegatedTask;
49
+ }): Promise<{
50
+ readonly receipt: RuntimeSubagentChildResult;
51
+ readonly session: RuntimeSession;
52
+ }>;
53
+ /** Releases task events only after the parent session index committed. */
54
+ export declare function acknowledgeDelegatedTasksStep(input: {
55
+ readonly tasks: readonly {
56
+ readonly taskInboxToken: string;
57
+ readonly taskId: string;
58
+ readonly taskRunId: string;
59
+ }[];
60
+ }): Promise<void>;
61
+ /** Fails an indexed task whose child dispatch was definitively rejected. */
62
+ export declare function failDelegatedDispatch(input: {
63
+ readonly error: JsonValue;
64
+ readonly task: DelegatedTask;
65
+ }): Promise<void>;
66
+ /** Silently terminates a task whose child dispatch failed before parent indexing. */
67
+ export declare function rejectDelegatedDispatch(input: {
68
+ readonly error: JsonValue;
69
+ readonly task: DelegatedTask;
70
+ }): Promise<void>;
@@ -0,0 +1 @@
1
+ import{sessionCommandHookToken}from"#execution/session-command-token.js";import{deriveAgentOperationId}from"#harness/handles/operation-id.js";import{deriveTaskId,deriveTaskInboxToken}from"#tasks/task-id.js";import{readLatestTaskView,sendTaskCommand,sendTaskCommandToOwner,startTaskRun,waitForTaskCommandOwner}from"#execution/tasks/parent/run-parent.js";import{recordSessionTask}from"#tasks/session-index.js";import{isTerminalTaskStatus}from"#tasks/types.js";async function beginDelegatedTask(n){let r=deriveTaskId({callId:n.callId,parentSessionId:n.parentSessionId,parentTurnId:n.parentTurnId}),i=deriveTaskInboxToken({parentContinuationToken:n.session.continuationToken,taskId:r}),a=deriveAgentOperationId({callId:n.callId,parentSessionId:n.parentSessionId,parentTurnId:n.parentTurnId}),o={agentId:n.agentId,kind:`subagent`,mode:n.mode,name:n.name};await startTaskRun({taskInboxToken:i,initialView:{metadata:o,status:`working`,taskId:r},parentContinuationToken:sessionCommandHookToken(n.session.sessionId)});let s=await waitForTaskCommandOwner({taskInboxToken:i});return{taskInboxToken:i,createdByStepIndex:n.parentStepIndex??0,createdByTurnId:n.parentTurnId,metadata:o,operationId:a,taskId:r,taskRunId:s.runId}}async function settleDelegatedDispatch(e){let t={agentId:e.task.metadata.agentId,status:`working`,taskId:e.task.taskId};return{receipt:{backgroundTask:{status:t.status,taskId:t.taskId},callId:e.callId,kind:`subagent-result`,origin:`child`,outcome:{kind:`parked`,result:{kind:`succeeded`,output:`Delegated as background task ${e.task.taskId} (working).`},usageDelta:{cacheReadTokens:0,cacheWriteTokens:0,inputTokens:0,outputTokens:0}},output:t,subagentName:e.subagentName},session:recordSessionTask(e.session,{taskInboxToken:e.task.taskInboxToken,createdByStepIndex:e.task.createdByStepIndex,createdByTurnId:e.task.createdByTurnId,metadata:e.task.metadata,operationId:e.task.operationId,taskId:e.task.taskId,taskRunId:e.task.taskRunId})}}async function acknowledgeDelegatedTasksStep(e){"use step";for(let t of e.tasks){if(await sendTaskCommandToOwner({command:{kind:`ready`},taskInboxToken:t.taskInboxToken,retryUnreachable:{attempts:20,delayMs:250}})!==void 0)continue;let e=await readLatestTaskView({taskRunId:t.taskRunId});if(!(e!==void 0&&isTerminalTaskStatus(e.status)))throw Error(`Task run "${t.taskId}" did not accept its readiness command.`)}}async function failDelegatedDispatch(e){await sendTaskCommand({command:{data:e.error,kind:`fail`},taskInboxToken:e.task.taskInboxToken,retryUnreachable:{attempts:20,delayMs:250}})}async function rejectDelegatedDispatch(e){await sendTaskCommand({command:{data:e.error,kind:`reject-dispatch`},taskInboxToken:e.task.taskInboxToken,retryUnreachable:{attempts:20,delayMs:250}})}export{acknowledgeDelegatedTasksStep,beginDelegatedTask,failDelegatedDispatch,rejectDelegatedDispatch,settleDelegatedDispatch};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Task-mode sibling of `dispatchRuntimeActionsStep`, selected by the turn
3
+ * workflow when the agent enables `experimental.tasks`.
4
+ *
5
+ * Same plan → dispatch → emit skeleton, but every delegation is wrapped in
6
+ * the durable task lifecycle: the task record and its inbox token
7
+ * exist *before* the child dispatch side effect (`beginDelegatedTask`),
8
+ * continuations pass the availability check and enter the parent session's
9
+ * task index first, and the task settles against the dispatch outcome.
10
+ * Children report through their task's inbox token rather than the
11
+ * parent turn inbox, and every start dispatches a conversation-mode
12
+ * (persistent) child so the background task stays resumable.
13
+ *
14
+ * Task-control calls (`task_peek` / `task_cancel` / `task_send`) execute
15
+ * inline in this step, which holds the session ownership index and world
16
+ * access they need.
17
+ */
18
+ import { type RuntimeActionDispatchInput, type RuntimeActionDispatchResult } from "#execution/dispatch-runtime-actions-shared.js";
19
+ export declare function dispatchTaskStep(input: RuntimeActionDispatchInput): Promise<RuntimeActionDispatchResult>;
@@ -0,0 +1 @@
1
+ import{createDurableSessionState}from"#execution/durable-session-store.js";import{dispatchToTaskAgentAddress}from"#execution/agent-handle-dispatch.js";import{executeTaskControlAction}from"#execution/tasks/parent/dispatch.js";import{createAgentContinuationBundle}from"#execution/agent-continuation-bundle.js";import{emitSubagentCalled,prepareRuntimeActionDispatch,startSubagent}from"#execution/dispatch-runtime-actions-shared.js";import{beginDelegatedTask,settleDelegatedDispatch}from"#execution/tasks/parent/delegate.js";import{checkTaskContinuationAvailability,describeTaskDispatch,persistContinuationTaskInParentSession,settleTaskDispatchError}from"#execution/tasks/parent/continuation-dispatch.js";async function dispatchTaskStep(r){"use step";let i=await prepareRuntimeActionDispatch({serializedContext:r.serializedContext,sessionState:r.sessionState,taskControls:!0});if(i===void 0)return{results:[],sessionState:r.sessionState,pendingTasks:[]};let{batch:a,bundle:o,session:s}=i,c=r.parentWritable.getWriter(),l=s,u=[],d=[];try{for(let e of i.plan){if(e.kind===`reject`){u.push(e.result);continue}if(e.kind===`task-control`){let t=await executeTaskControlAction({action:e.action,bundle:o,parentStepIndex:a.event.stepIndex,parentTurnId:a.event.turnId,session:l});l=t.session,t.pendingTask!==void 0&&d.push(t.pendingTask),u.push(t.result);continue}if(e.kind===`resume`){let t=await checkTaskContinuationAvailability({action:e.action,agentId:e.agentId,parentStepIndex:a.event.stepIndex,parentTurnId:a.event.turnId,session:l});if(t!==void 0){u.push(t);continue}}let n=await beginDelegatedTask({...describeTaskDispatch({action:e.kind===`resume`?e.action:e.target.action,agentId:e.kind===`resume`?e.agentId:void 0,parentSessionId:s.sessionId,parentTurnId:a.event.turnId,session:l}),parentSessionId:s.sessionId,parentStepIndex:a.event.stepIndex,parentTurnId:a.event.turnId,session:l}),f;e.kind===`resume`&&(f=await persistContinuationTaskInParentSession({action:e.action,agentId:e.agentId,delegated:n,session:l}),l=f?.session??l);let p;switch(e.kind){case`resume`:p=await dispatchToTaskAgentAddress({action:e.action,agentId:e.agentId,bundle:createAgentContinuationBundle({action:e.action,bundle:o,dynamicRemoteAgent:e.dynamicRemoteAgent}),currentSession:l,parentToken:n.taskInboxToken});break;case`start`:p=await startSubagent({auth:i.auth,batchEvent:a.event,bundle:o,callbackBaseUrl:r.callbackBaseUrl,capabilities:i.capabilities,channelMetadata:i.channelMetadata,currentSession:l,fanoutSize:i.fanoutSize,initiatorAuth:i.initiatorAuth,parentContinuationToken:n.taskInboxToken,parentTraceContext:i.parentTraceContext,persistentSessions:!0,serializedContext:i.serializedContext,session:s,taskOwned:!0,target:e.target});break}if(l=p.session,p.kind===`error`){u.push(await settleTaskDispatchError({delegated:n,outcome:p,persisted:f})),f!==void 0&&d.push(n);continue}if(f!==void 0)u.push(f.receipt);else{let e=await settleDelegatedDispatch({callId:p.callId,session:l,subagentName:p.toolName,task:n});l=e.session,u.push(e.receipt)}d.push(n),await emitSubagentCalled({adapter:i.adapter,adapterCtx:i.adapterCtx,batchEvent:a.event,entry:e,outcome:p,sessionId:s.sessionId,writer:c})}}finally{c.releaseLock()}return{results:u,sessionState:l===s?r.sessionState:createDurableSessionState({session:l}),pendingTasks:d}}export{dispatchTaskStep};
@@ -0,0 +1,33 @@
1
+ import type { RuntimeSession } from "#execution/agent-handle-dispatch.js";
2
+ import type { DelegatedTask } from "#execution/tasks/parent/delegate.js";
3
+ import type { RuntimeActionRequest, RuntimeActionResult, RuntimeToolCallActionRequest } from "#runtime/actions/types.js";
4
+ import type { CompiledBundle } from "#runtime/sessions/runtime-context-keys.js";
5
+ import type { SessionTaskIndexEntry } from "#tasks/session-index.js";
6
+ import { type TaskView } from "#tasks/types.js";
7
+ /** True for `task_peek` / `task_cancel` / `task_send` calls. */
8
+ export declare function isTaskControlAction(action: RuntimeActionRequest): action is RuntimeToolCallActionRequest;
9
+ /**
10
+ * Executes one task-control call inside the dispatch step, which holds
11
+ * the durable session state (ownership index) and world access the
12
+ * tools need.
13
+ *
14
+ * Returns the (possibly updated) session: `task_send` follow-ups record
15
+ * new tasks and settle the continued agent handle.
16
+ */
17
+ export declare function executeTaskControlAction(input: {
18
+ readonly action: RuntimeToolCallActionRequest;
19
+ readonly bundle: CompiledBundle;
20
+ readonly parentStepIndex?: number;
21
+ readonly parentTurnId: string;
22
+ readonly session: RuntimeSession;
23
+ }): Promise<{
24
+ readonly result: RuntimeActionResult;
25
+ readonly session: RuntimeSession;
26
+ readonly pendingTask?: DelegatedTask;
27
+ }>;
28
+ /** Commits task cancellation, then propagates it to the addressed executor. */
29
+ export declare function cancelOwnedTask(input: {
30
+ readonly bundle: CompiledBundle;
31
+ readonly entry: SessionTaskIndexEntry;
32
+ readonly session: RuntimeSession;
33
+ }): Promise<TaskView>;
@@ -0,0 +1 @@
1
+ import{createLogger,logError}from"#internal/logging.js";import{cancelRemoteAgentTurn,resolveRemoteAgentForAction}from"#execution/remote-agent-dispatch.js";import{requestWorkflowTurnCancellation}from"#execution/workflow-runtime.js";import{TASK_CANCEL_TOOL_NAME,TASK_CONTROL_TOOL_NAMES,TASK_PEEK_TOOL_NAME,TASK_SEND_TOOL_NAME}from"#runtime/framework-tools/tasks.js";import{sendTaskCommand}from"#execution/tasks/parent/run-parent.js";import{isTerminalTaskStatus}from"#tasks/types.js";import{createTaskControlError,createTaskViewsResult,createUnknownTasksError,findTaskAgentAddress,lookupTaskEntries,readTaskView,readTaskViews}from"#execution/tasks/parent/control-shared.js";import{executeTaskSend}from"#execution/tasks/parent/send.js";const log=createLogger(`execution.tasks.dispatch`);function isTaskControlAction(e){return e.kind===`tool-call`&&TASK_CONTROL_TOOL_NAMES.has(e.toolName)}async function executeTaskControlAction(e){let{action:t,session:n}=e;if(t.toolName===TASK_SEND_TOOL_NAME)return executeTaskSend(e);let r=readTaskIds(t.input);if(r===void 0||r.length===0)return{result:createTaskControlError(t,"Provide a non-empty `taskIds` array."),session:n};let i=lookupTaskEntries(n,r);if(i.kind===`unknown`)return{result:createUnknownTasksError(t,i.unknown),session:n};let o=i.entries;switch(t.toolName){case TASK_PEEK_TOOL_NAME:return{result:createTaskViewsResult(t,await readTaskViews(o)),session:n};case TASK_CANCEL_TOOL_NAME:{let r=[];for(let t of o)r.push(await cancelOwnedTask({bundle:e.bundle,entry:t,session:n}));return{result:createTaskViewsResult(t,r),session:n}}default:return{result:createTaskControlError(t,`Unsupported task control "${t.toolName}".`),session:n}}}async function cancelOwnedTask(e){let{entry:t}=e,n=await sendTaskCommand({command:{kind:`cancel`},taskInboxToken:t.taskInboxToken}),r=await readTaskView(t);for(let e=0;e<10&&!isTerminalTaskStatus(r.status);e+=1)await new Promise(e=>setTimeout(e,250)),r=await readTaskView(t);if(!isTerminalTaskStatus(r.status))throw Error(`Task "${t.taskId}" did not commit cancellation before timeout.`);let i=r;return i.status===`cancelled`&&n===`delivered`&&await propagateTaskCancel({bundle:e.bundle,session:e.session,view:i}),i}async function propagateTaskCancel(e){let a=findTaskAgentAddress(e.session,e.view.metadata.agentId);if(a===void 0)return;let o=a.address.sessionId,s=e.view.executor?.childTurnId;if(!(e.view.executor?.childSessionId!==void 0&&e.view.executor.childSessionId!==o))try{if(a.address.kind===`agent/remote`){let t=resolveRemoteAgentForAction({nodeId:a.identity.nodeId,remoteAgentName:a.identity.name,registry:e.bundle.subagentRegistry.subagentsByNodeId}),i={remote:{...t,url:a.address.url},sessionId:o,taskId:e.view.taskId};s!==void 0&&(i.turnId=s),(await cancelRemoteAgentTurn(i)).status===`no_active_turn`&&await cancelRemoteAgentTurn({remote:{...t,url:a.address.url},sessionId:o,taskId:e.view.taskId});return}let t={sessionId:o,taskId:e.view.taskId};s!==void 0&&(t.turnId=s),(await requestWorkflowTurnCancellation(t)).status===`no_active_turn`&&await requestWorkflowTurnCancellation({sessionId:o,taskId:e.view.taskId})}catch(n){logError(log,`task cancel propagation failed; the child may run to completion`,n,{childSessionId:o,taskId:e.view.taskId})}}function readTaskIds(e){let t=e.taskIds;if(Array.isArray(t))return t.filter(e=>typeof e==`string`&&e.trim()!==``)}export{cancelOwnedTask,executeTaskControlAction,isTaskControlAction};
@@ -0,0 +1,29 @@
1
+ import type { SubagentInputRequestHookPayload } from "#channel/types.js";
2
+ import type { SubagentAuthorizationEventHookPayload } from "#channel/types.js";
3
+ import { type DurableSessionState } from "#execution/durable-session-store.js";
4
+ import { type TaskView } from "#tasks/types.js";
5
+ /** Validates and durably records one task-owned child HITL route batch. */
6
+ export declare function recordTaskInputRequestStep(input: {
7
+ readonly hookPayload: SubagentInputRequestHookPayload;
8
+ readonly serializedContext: Record<string, unknown>;
9
+ readonly sessionState: DurableSessionState;
10
+ readonly taskId: string;
11
+ }): Promise<{
12
+ readonly accepted: false;
13
+ readonly sessionState: DurableSessionState;
14
+ } | {
15
+ readonly accepted: true;
16
+ readonly hookPayload: SubagentInputRequestHookPayload;
17
+ readonly sessionState: DurableSessionState;
18
+ }>;
19
+ /** Validates that one task authorization event came from its owned child address. */
20
+ export declare function acceptTaskAuthorizationEventStep(input: {
21
+ readonly hookPayload: SubagentAuthorizationEventHookPayload;
22
+ readonly sessionState: DurableSessionState;
23
+ readonly taskId: string;
24
+ }): Promise<boolean>;
25
+ /** Caches terminal task views before their workflow runs can expire. */
26
+ export declare function recordTerminalTaskViewsStep(input: {
27
+ readonly sessionState: DurableSessionState;
28
+ readonly views: readonly TaskView[];
29
+ }): Promise<DurableSessionState>;
@@ -0,0 +1 @@
1
+ import{createEveTaskInputRoutePath}from"#protocol/routes.js";import{isInputRequest}from"#runtime/input/types.js";import{getAgentHandleStore}from"#harness/handles/store.js";import{removeTaskAgentAddressFromState}from"#harness/handles/transitions.js";import{createRemoteTaskInputCallbackUrl}from"#execution/workflow-callback-url.js";import{readDurableSession}from"#execution/durable-session-store.js";import{createTaskInputRequestId,toProxyInputRequestEntries,upsertProxyInputRequestState}from"#harness/proxy-input-requests.js";import{readLatestTaskView}from"#execution/tasks/parent/run-parent.js";import{cacheTerminalTaskView,findSessionTaskEntry}from"#tasks/session-index.js";import{isTerminalTaskStatus}from"#tasks/types.js";import{createTaskInputCapabilityToken}from"#execution/task-input-capability.js";async function recordTaskInputRequestStep(r){"use step";let a=await readDurableSession(r.sessionState),o=findSessionTaskEntry(a.state,r.taskId),s=(getAgentHandleStore(a.state)?.handles??[]).find(e=>e.phase===`addressed`&&e.identity.id===o?.metadata.agentId);if(o===void 0||s?.phase!==`addressed`||s.address.sessionId!==r.hookPayload.childSessionId)return{accepted:!1,sessionState:r.sessionState};let c=await readLatestTaskView({taskRunId:o.taskRunId}),l=r.hookPayload.event.requests.map(e=>e.requestId),u=c?.inputRequests?.map(e=>typeof e==`object`&&e&&!Array.isArray(e)?Reflect.get(e,`requestId`):void 0)??[];if(c?.status!==`input_required`||!r.hookPayload.event.requests.every(isInputRequest)||c.metadata.mode!==(s.address.kind===`agent/remote`?`remote`:`local`)||c.metadata.agentId!==o.metadata.agentId||c.executor?.childSessionId!==r.hookPayload.childSessionId||new Set(l).size!==l.length||l.length!==u.length||l.some((e,t)=>e!==u[t]))return{accepted:!1,sessionState:r.sessionState};let d=namespaceTaskInputRequests(r.hookPayload,r.taskId),f=toProxyInputRequestEntries(d,r.taskId).map(([e,t],n)=>{let i=r.hookPayload.event.requests[n].requestId;return[e,{...t,childRequestId:i}]});if(s.address.kind===`agent/remote`){let t=createRemoteTaskInputCallbackUrl(s.address.url,createEveTaskInputRoutePath(createTaskInputCapabilityToken(r.hookPayload.childContinuationToken)));f=f.map(([e,n])=>[e,{...n,childResponseUrl:t}])}let p=upsertProxyInputRequestState({entries:f,forChildContinuationToken:r.hookPayload.childContinuationToken,state:a.state});return{accepted:!0,hookPayload:d,sessionState:{...r.sessionState,hasProxyInputRequests:!0,snapshot:{session:{...a,state:p},version:r.sessionState.version}}}}function namespaceTaskInputRequests(e,t){return{...e,event:{...e.event,requests:e.event.requests.map(e=>({...e,requestId:createTaskInputRequestId(t,e.requestId)}))}}}async function acceptTaskAuthorizationEventStep(e){"use step";let t=await readDurableSession(e.sessionState),r=findSessionTaskEntry(t.state,e.taskId);if(r===void 0)return!1;let i=(getAgentHandleStore(t.state)?.handles??[]).find(e=>e.phase===`addressed`&&e.identity.id===r.metadata.agentId);if(i?.phase!==`addressed`||i.address.sessionId!==e.hookPayload.childSessionId)return!1;let a=await readLatestTaskView({taskRunId:r.taskRunId});return a!==void 0&&!isTerminalTaskStatus(a.status)&&a.executor?.childSessionId===e.hookPayload.childSessionId&&a.metadata.agentId===r.metadata.agentId}async function recordTerminalTaskViewsStep(e){"use step";let t=await readDurableSession(e.sessionState),n=t.state;for(let t of e.views)n=cacheTerminalTaskView(n,t),t.executor?.lifecycle===`terminal`&&(n=removeTaskAgentAddressFromState(n,t.metadata.agentId));return n===t.state?e.sessionState:{...e.sessionState,snapshot:{session:{...t,state:n},version:e.sessionState.version}}}export{acceptTaskAuthorizationEventStep,recordTaskInputRequestStep,recordTerminalTaskViewsStep};
@@ -0,0 +1,72 @@
1
+ import type { TaskRunWorkflowInput } from "#execution/tasks/child/workflow.js";
2
+ import { type TaskCommand, type TaskRunInboundPayload, type TaskView } from "#tasks/types.js";
3
+ /**
4
+ * Node-side controls for durable task runs — the generic transport layer.
5
+ * This module only speaks `TaskCommand`/`TaskView`; it knows nothing about
6
+ * subagents, receipts, or the session index. Caller-specific policy (e.g.
7
+ * subagent delegation in `delegate.ts`) composes these primitives.
8
+ *
9
+ * Every export must be called from inside a `"use step"` body; none of
10
+ * these are steps themselves so dispatch and tool steps can compose them
11
+ * inside one durable boundary.
12
+ */
13
+ /** Starts the durable run owning one task's lifecycle. */
14
+ export declare function startTaskRun(input: TaskRunWorkflowInput): Promise<void>;
15
+ /** Resolves the task run that won ownership of one replay-stable command token. */
16
+ export declare function waitForTaskCommandOwner(input: {
17
+ readonly taskInboxToken: string;
18
+ }): Promise<{
19
+ readonly runId: string;
20
+ }>;
21
+ /**
22
+ * Submits one command to a task run.
23
+ *
24
+ * `unreachable` means the hook is not resumable — either the run
25
+ * already finished and disposed it (the task is terminal; read the
26
+ * final view) or, right after creation, the freshly started run has
27
+ * not registered it yet. Senders racing that startup window pass
28
+ * `retryUnreachable`; senders addressing an established task treat
29
+ * `unreachable` as the terminal signal.
30
+ */
31
+ export declare function sendTaskCommand(input: {
32
+ readonly command: TaskCommand;
33
+ readonly taskInboxToken: string;
34
+ readonly retryUnreachable?: {
35
+ readonly attempts: number;
36
+ readonly delayMs: number;
37
+ };
38
+ }): Promise<"delivered" | "unreachable">;
39
+ /** Delivers one command and returns the accepting task workflow's run id. */
40
+ export declare function sendTaskCommandToOwner(input: {
41
+ readonly command: TaskCommand;
42
+ readonly taskInboxToken: string;
43
+ readonly retryUnreachable?: {
44
+ readonly attempts: number;
45
+ readonly delayMs: number;
46
+ };
47
+ }): Promise<{
48
+ readonly runId: string;
49
+ } | undefined>;
50
+ /**
51
+ * Hands one non-command inbound payload to a task run.
52
+ *
53
+ * Used for payloads the run must act on before it may record them —
54
+ * today only answered input batches, which it forwards to the child
55
+ * first. `unreachable` means the task already finished and disposed its
56
+ * hook, so the payload is stale by definition.
57
+ */
58
+ export declare function sendTaskInboundPayload(input: {
59
+ readonly taskInboxToken: string;
60
+ readonly payload: TaskRunInboundPayload;
61
+ }): Promise<"delivered" | "unreachable">;
62
+ /**
63
+ * Reads the latest view a task run has published, or `undefined`
64
+ * when the run has not committed its first view yet (the caller
65
+ * already holds the creation receipt, which is `working`).
66
+ *
67
+ * Views are trusted without re-validation: the task run is the
68
+ * single writer and every write passed the transition function.
69
+ */
70
+ export declare function readLatestTaskView(input: {
71
+ readonly taskRunId: string;
72
+ }): Promise<TaskView | undefined>;
@@ -0,0 +1 @@
1
+ import{startWorkflowPreferLatest,taskRunWorkflowReference,waitForCommandHookOwner}from"#execution/workflow-runtime.js";import{getRun,resumeHook}from"#internal/workflow/runtime.js";import{isTaskWorkflowTargetGone}from"#execution/tasks/workflow-target.js";import{TASK_VIEW_STREAM_NAMESPACE}from"#tasks/types.js";const TASK_VIEW_READ_TIMEOUT_MS=1e4;async function startTaskRun(n){await startWorkflowPreferLatest(taskRunWorkflowReference,[n])}async function waitForTaskCommandOwner(e){return await waitForCommandHookOwner(e.taskInboxToken)}async function sendTaskCommand(e){return await sendTaskCommandToOwner(e)===void 0?`unreachable`:`delivered`}async function sendTaskCommandToOwner(e){let t={command:e.command,kind:`task-command`},n=Math.max(1,e.retryUnreachable?.attempts??1);for(let r=0;;r+=1)try{let n=await resumeHook(e.taskInboxToken,t);if(typeof n!=`object`||!n||!(`runId`in n)||typeof n.runId!=`string`)throw Error(`Task inbox hook "${e.taskInboxToken}" returned no owner run id.`);return{runId:n.runId}}catch(t){if(!isTaskWorkflowTargetGone(t))throw t;if(r+1>=n)return;await new Promise(t=>setTimeout(t,e.retryUnreachable?.delayMs??250))}}async function sendTaskInboundPayload(e){try{return await resumeHook(e.taskInboxToken,e.payload),`delivered`}catch(e){if(!isTaskWorkflowTargetGone(e))throw e;return`unreachable`}}async function readLatestTaskView(e){let t=getRun(e.taskRunId).getReadable({namespace:TASK_VIEW_STREAM_NAMESPACE,startIndex:-1}),n=await t.getTailIndex(),i=t.getReader();try{return n<0?void 0:await readWithTimeout(i,`latest task view`)}finally{await i.cancel(`eve task view read complete`).catch(()=>{}),i.releaseLock()}}async function readWithTimeout(e,t){let n;try{let r=await Promise.race([e.read().then(e=>({kind:`read`,read:e})),new Promise(e=>{n=setTimeout(()=>e({kind:`timeout`}),TASK_VIEW_READ_TIMEOUT_MS)})]);if(r.kind===`timeout`)throw Error(`Timed out reading ${t} after ${TASK_VIEW_READ_TIMEOUT_MS}ms.`);return r.read.done?void 0:r.read.value}finally{n!==void 0&&clearTimeout(n)}}export{readLatestTaskView,sendTaskCommand,sendTaskCommandToOwner,sendTaskInboundPayload,startTaskRun,waitForTaskCommandOwner};