eve 0.24.4 → 0.24.6

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 (161) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/src/channel/cancel.d.ts +8 -0
  3. package/dist/src/channel/cancel.js +1 -0
  4. package/dist/src/channel/routes.d.ts +25 -4
  5. package/dist/src/channel/session.d.ts +10 -1
  6. package/dist/src/channel/session.js +1 -1
  7. package/dist/src/channel/types.d.ts +21 -0
  8. package/dist/src/chunks/{use-eve-agent-Dwa2j1wE.js → use-eve-agent-6BO9gFVq.js} +61 -6
  9. package/dist/src/chunks/{use-eve-agent-BP9FpQsJ.js → use-eve-agent-B1MJNRE-.js} +61 -6
  10. package/dist/src/cli/commands/build.d.ts +14 -0
  11. package/dist/src/cli/commands/build.js +1 -0
  12. package/dist/src/cli/commands/channels.js +1 -1
  13. package/dist/src/cli/commands/link.d.ts +6 -5
  14. package/dist/src/cli/commands/link.js +1 -1
  15. package/dist/src/cli/run.d.ts +3 -2
  16. package/dist/src/cli/run.js +1 -1
  17. package/dist/src/client/index.d.ts +1 -1
  18. package/dist/src/client/ndjson.js +1 -1
  19. package/dist/src/client/open-stream.d.ts +3 -2
  20. package/dist/src/client/open-stream.js +1 -1
  21. package/dist/src/client/session.d.ts +19 -3
  22. package/dist/src/client/session.js +1 -1
  23. package/dist/src/client/types.d.ts +8 -0
  24. package/dist/src/compiled/.vendor-stamp.json +5 -5
  25. package/dist/src/compiled/@workflow/core/index.js +2 -2
  26. package/dist/src/compiled/@workflow/core/runtime/helpers.d.ts +55 -0
  27. package/dist/src/compiled/@workflow/core/runtime/run-id-time.d.ts +9 -0
  28. package/dist/src/compiled/@workflow/core/runtime/step-executor.d.ts +2 -0
  29. package/dist/src/compiled/@workflow/core/runtime/step-latency.d.ts +70 -4
  30. package/dist/src/compiled/@workflow/core/runtime/suspension-handler.d.ts +10 -1
  31. package/dist/src/compiled/@workflow/core/runtime.js +3 -3
  32. package/dist/src/compiled/@workflow/core/step/context-storage.d.ts +6 -0
  33. package/dist/src/compiled/@workflow/core/telemetry/semantic-conventions.d.ts +25 -0
  34. package/dist/src/compiled/@workflow/core/version.d.ts +1 -1
  35. package/dist/src/compiled/@workflow/core/workflow.js +1 -1
  36. package/dist/src/compiled/@workflow/errors/index.d.ts +16 -0
  37. package/dist/src/compiled/@workflow/errors/index.js +1 -1
  38. package/dist/src/compiled/@workflow/world/attributes.d.ts +7 -0
  39. package/dist/src/compiled/@workflow/world/events.d.ts +16 -0
  40. package/dist/src/compiled/@workflow/world/index.d.ts +1 -1
  41. package/dist/src/compiled/@workflow/world-local/index.js +3 -3
  42. package/dist/src/compiled/@workflow/world-vercel/index.js +16 -16
  43. package/dist/src/compiled/_chunks/workflow/attribute-changes-DXbmITuI.js +20 -0
  44. package/dist/src/compiled/_chunks/workflow/{dist-DpDDcpTl.js → dist-BYo8Gno2.js} +1 -1
  45. package/dist/src/compiled/_chunks/workflow/{dist-Blxnyb7-.js → dist-CSfKNxQW.js} +1 -1
  46. package/dist/src/compiled/_chunks/workflow/resume-hook-DvvgYsRt.js +1 -0
  47. package/dist/src/compiled/_chunks/workflow/run-BdvQmV5a.js +1 -0
  48. package/dist/src/compiled/_chunks/workflow/run-id-BdE0MZz9.js +1 -0
  49. package/dist/src/compiled/_chunks/workflow/sleep-DzxrwWTs.js +1 -0
  50. package/dist/src/evals/assertions/run.d.ts +3 -3
  51. package/dist/src/evals/context.js +1 -1
  52. package/dist/src/evals/index.d.ts +2 -1
  53. package/dist/src/evals/match.d.ts +4 -0
  54. package/dist/src/evals/match.js +1 -1
  55. package/dist/src/evals/runner/derive-run-facts.js +1 -1
  56. package/dist/src/evals/session.d.ts +10 -2
  57. package/dist/src/evals/session.js +1 -1
  58. package/dist/src/evals/target.js +1 -1
  59. package/dist/src/evals/types.d.ts +52 -2
  60. package/dist/src/execution/cancel-descendant-turns-step.d.ts +6 -0
  61. package/dist/src/execution/cancel-descendant-turns-step.js +1 -0
  62. package/dist/src/execution/create-session-step.js +1 -1
  63. package/dist/src/execution/dispatch-runtime-actions-step.js +1 -1
  64. package/dist/src/execution/dispatch-workflow-runtime-actions-step.js +1 -1
  65. package/dist/src/execution/node-step.js +1 -1
  66. package/dist/src/execution/remote-agent-dispatch.d.ts +6 -0
  67. package/dist/src/execution/remote-agent-dispatch.js +1 -1
  68. package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
  69. package/dist/src/execution/subagent-event-proxy-step.js +1 -1
  70. package/dist/src/execution/turn-cancellation-control.d.ts +0 -13
  71. package/dist/src/execution/turn-cancellation-control.js +1 -1
  72. package/dist/src/execution/turn-cancellation-token.d.ts +9 -0
  73. package/dist/src/execution/turn-cancellation-token.js +1 -0
  74. package/dist/src/execution/turn-workflow.js +1 -1
  75. package/dist/src/execution/workflow-runtime.d.ts +3 -1
  76. package/dist/src/execution/workflow-runtime.js +1 -1
  77. package/dist/src/execution/workflow-steps.js +1 -1
  78. package/dist/src/harness/advertised-tools.js +1 -1
  79. package/dist/src/harness/execute-tool.d.ts +0 -1
  80. package/dist/src/harness/runtime-actions.d.ts +16 -12
  81. package/dist/src/harness/runtime-actions.js +1 -1
  82. package/dist/src/internal/application/build-profile.d.ts +64 -0
  83. package/dist/src/internal/application/build-profile.js +1 -0
  84. package/dist/src/internal/application/package.js +1 -1
  85. package/dist/src/internal/authored-module-loader.d.ts +10 -0
  86. package/dist/src/internal/authored-module-loader.js +2 -2
  87. package/dist/src/internal/authored-module-map-loader.js +1 -1
  88. package/dist/src/internal/materialized-authored-modules.d.ts +2 -4
  89. package/dist/src/internal/materialized-authored-modules.js +1 -1
  90. package/dist/src/internal/nitro/dev-runtime-artifacts.js +1 -1
  91. package/dist/src/internal/nitro/host/build-application.js +1 -1
  92. package/dist/src/internal/nitro/host/types.d.ts +2 -0
  93. package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response-from-manifest.js +1 -1
  94. package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response.d.ts +7 -1
  95. package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response.js +1 -1
  96. package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
  97. package/dist/src/internal/nitro/routes/channel-route-context.d.ts +3 -0
  98. package/dist/src/internal/nitro/routes/channel-route-context.js +1 -1
  99. package/dist/src/internal/nitro/routes/runtime-stack.js +1 -1
  100. package/dist/src/internal/nitro/routes/schedule-task.js +1 -1
  101. package/dist/src/protocol/cancel-turn.d.ts +11 -0
  102. package/dist/src/protocol/cancel-turn.js +1 -0
  103. package/dist/src/protocol/routes.d.ts +10 -0
  104. package/dist/src/protocol/routes.js +1 -1
  105. package/dist/src/public/channels/eve.d.ts +2 -1
  106. package/dist/src/public/channels/eve.js +1 -1
  107. package/dist/src/public/channels/index.d.ts +1 -1
  108. package/dist/src/public/channels/linear/api.d.ts +0 -1
  109. package/dist/src/public/channels/linear/api.js +17 -22
  110. package/dist/src/public/channels/linear/linearChannel.js +1 -1
  111. package/dist/src/public/definitions/channel.d.ts +21 -11
  112. package/dist/src/public/next/index.js +1 -1
  113. package/dist/src/public/next/resolve-eve-binary.d.ts +12 -0
  114. package/dist/src/public/next/resolve-eve-binary.js +1 -0
  115. package/dist/src/runtime/agent/mock-model-adapter.js +1 -1
  116. package/dist/src/runtime/framework-tools/agent.d.ts +13 -0
  117. package/dist/src/runtime/framework-tools/agent.js +1 -0
  118. package/dist/src/runtime/framework-tools/index.d.ts +7 -2
  119. package/dist/src/runtime/framework-tools/index.js +1 -1
  120. package/dist/src/runtime/resolve-agent-graph.js +1 -1
  121. package/dist/src/runtime/types.d.ts +2 -1
  122. package/dist/src/setup/boxes/reconcile-host-framework-preset.d.ts +26 -0
  123. package/dist/src/setup/boxes/reconcile-host-framework-preset.js +1 -0
  124. package/dist/src/setup/boxes/resolve-provisioning.js +1 -1
  125. package/dist/src/setup/index.js +1 -1
  126. package/dist/src/setup/scaffold/create/add-to-project.js +1 -1
  127. package/dist/src/setup/scaffold/create/project.js +2 -2
  128. package/dist/src/setup/scaffold/create/web-template.d.ts +1 -1
  129. package/dist/src/setup/scaffold/create/web-template.js +1 -0
  130. package/dist/src/setup/scaffold/index.d.ts +1 -1
  131. package/dist/src/setup/scaffold/index.js +1 -1
  132. package/dist/src/setup/scaffold/update/channels.d.ts +7 -1
  133. package/dist/src/setup/scaffold/update/channels.js +2 -2
  134. package/dist/src/setup/scaffold/update/connections.js +3 -3
  135. package/dist/src/setup/vercel-project-framework.d.ts +12 -0
  136. package/dist/src/setup/vercel-project-framework.js +1 -1
  137. package/dist/src/svelte/index.js +1 -1
  138. package/dist/src/svelte/use-eve-agent.js +1 -1
  139. package/dist/src/vue/index.js +1 -1
  140. package/dist/src/vue/use-eve-agent.js +1 -1
  141. package/docs/channels/custom.mdx +32 -2
  142. package/docs/channels/eve.mdx +11 -1
  143. package/docs/concepts/default-harness.md +2 -0
  144. package/docs/concepts/sessions-runs-and-streaming.md +13 -0
  145. package/docs/evals/assertions.mdx +2 -2
  146. package/docs/evals/cases.mdx +31 -0
  147. package/docs/evals/overview.mdx +1 -1
  148. package/docs/evals/targets.mdx +2 -1
  149. package/docs/guides/client/continuations.mdx +2 -0
  150. package/docs/guides/client/streaming.mdx +17 -1
  151. package/docs/guides/frontend/overview.mdx +4 -2
  152. package/docs/guides/frontend/use-eve-agent-svelte.mdx +2 -2
  153. package/docs/guides/frontend/use-eve-agent-vue.mdx +2 -2
  154. package/docs/guides/remote-agents.md +2 -0
  155. package/docs/reference/cli.md +15 -2
  156. package/docs/subagents.mdx +10 -0
  157. package/package.json +7 -7
  158. package/dist/src/compiled/_chunks/workflow/attribute-changes-MGTOG_uX.js +0 -20
  159. package/dist/src/compiled/_chunks/workflow/resume-hook-DHP5ql3-.js +0 -1
  160. package/dist/src/compiled/_chunks/workflow/run-D8hv1ptT.js +0 -1
  161. package/dist/src/compiled/_chunks/workflow/sleep-uA9pS-PT.js +0 -1
@@ -1,6 +1,6 @@
1
1
  import type { HandleMessageStreamEvent } from "#protocol/message.js";
2
2
  import { MessageResponse } from "#client/message-response.js";
3
- import type { ClientRedirectPolicy, SendTurnInput, SessionState, StreamOptions } from "#client/types.js";
3
+ import type { CancelSessionResult, ClientRedirectPolicy, SendTurnInput, SessionState, StreamOptions } from "#client/types.js";
4
4
  /**
5
5
  * Internal interface that a {@link ClientSession} uses to access client-level
6
6
  * configuration without depending on the full {@link Client} class.
@@ -24,8 +24,9 @@ export declare class ClientSession {
24
24
  /** @internal */
25
25
  constructor(context: SessionContext, state: SessionState);
26
26
  /**
27
- * Current session cursor. Always reflects the latest state after each
28
- * completed turn. Serialize this to persist and resume later.
27
+ * Current session cursor. The assigned session ID appears as soon as a send
28
+ * is accepted; the continuation token and stream index advance as its event
29
+ * stream is consumed. Serialize this to persist and resume later.
29
30
  */
30
31
  get state(): SessionState;
31
32
  /**
@@ -36,6 +37,21 @@ export declare class ClientSession {
36
37
  * headers in a single request.
37
38
  */
38
39
  send<TOutput = unknown>(input: SendTurnInput<TOutput>): Promise<MessageResponse<TOutput>>;
40
+ /**
41
+ * Requests cooperative cancellation of this session's active turn.
42
+ *
43
+ * Both `accepted` and `no_active_turn` are successful outcomes. The latter
44
+ * means the active turn settled before the request arrived or the session is
45
+ * already parked. `turnId` limits the request to the turn the caller
46
+ * observed; a stale guard is consumed as a benign no-op. Credentials are
47
+ * resolved immediately before the request.
48
+ *
49
+ * @throws {Error} If this handle has not started or attached to a session.
50
+ * @throws {ClientError} If the cancel route returns a non-successful status.
51
+ */
52
+ cancel(options?: {
53
+ turnId?: string;
54
+ }): Promise<CancelSessionResult>;
39
55
  /**
40
56
  * Opens this session's event stream for the current session ID.
41
57
  *
@@ -1 +1 @@
1
- import{EVE_CREATE_SESSION_ROUTE_PATH,createEveContinueSessionRoutePath}from"#protocol/routes.js";import{ClientError}from"#client/client-error.js";import{advanceSession}from"#client/session-utils.js";import{createClientUrl}from"#client/url.js";import{MessageResponse}from"#client/message-response.js";import{EVE_SESSION_ID_HEADER,isCurrentTurnBoundaryEvent}from"#protocol/message.js";import{normalizeOutputSchemaForRequest}from"#client/output-schema.js";import{isStreamDisconnectError,readNdjsonStream}from"#client/ndjson.js";import{openStreamBody,openStreamIterable}from"#client/open-stream.js";var ClientSession=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get state(){return this.#t}async send(e){let t=normalizeSendTurnInput(e),n=this.#t,{continuationToken:r,sessionId:i}=await this.#n(t,n);return new MessageResponse({continuationToken:r,createStream:()=>this.#r(i,r,n,t),sessionId:i})}stream(e){let t=this.#t.sessionId;if(!t)throw Error(`Session has no session ID. Send a message first.`);return this.#a(t,e)}async#n(n,r){let a=r.sessionId?createEveContinueSessionRoutePath(r.sessionId):EVE_CREATE_SESSION_ROUTE_PATH,s=createClientUrl(this.#e.host,a),c=await this.#e.resolveHeaders(n.headers);c.set(`content-type`,`application/json`);let l=createHandleMessageBody({input:n,outputSchema:normalizeOutputSchemaForRequest(n.outputSchema),session:r});if(l===null)throw Error(`Session.send requires a non-empty message, inputResponses, or both.`);let u=await postTurnWithRetry({body:JSON.stringify(l),headers:c,mustDeliver:(n.inputResponses?.length??0)>0,redirect:this.#e.redirect,signal:n.signal,url:s}),d=await u.json(),f=(typeof d.sessionId==`string`?d.sessionId:void 0)??u.headers.get(EVE_SESSION_ID_HEADER)?.trim()??r.sessionId;if(!f)throw Error(`Message route did not return a session id.`);return{continuationToken:typeof d.continuationToken==`string`?d.continuationToken:void 0,sessionId:f}}async*#r(e,t,n,i){let a=[];try{let t=n.sessionId===e?n.streamIndex:0,r=this.#e.maxReconnectAttempts;for(;;){let n=await this.#i(e,t,i.signal,i.headers),o=!1;try{for await(let e of readNdjsonStream(n))if(a.push(e),t+=1,yield e,isCurrentTurnBoundaryEvent(e)){o=!0;break}}catch(e){if(!isStreamDisconnectError(e))throw e}if(o||i.signal?.aborted||r<=0)break;--r}}finally{this.#t=advanceSession({continuationToken:t,events:a,preserveCompletedSessions:this.#e.preserveCompletedSessions,sessionId:e,session:n})}}async#i(e,t,n,r){return await openStreamBody({host:this.#e.host,resolveHeaders:()=>this.#e.resolveHeaders(r),redirect:this.#e.redirect,sessionId:e,signal:n,startIndex:t})}async*#a(e,t){let n=this.#t,i=t?.startIndex??n.streamIndex,a=[];try{for await(let n of openStreamIterable({host:this.#e.host,maxReconnectAttempts:this.#e.maxReconnectAttempts,resolveHeaders:()=>this.#e.resolveHeaders(),redirect:this.#e.redirect,sessionId:e,signal:t?.signal,startIndex:i}))a.push(n),yield n}finally{i>=0&&(this.#t=advanceSession({continuationToken:n.continuationToken,events:a,preserveCompletedSessions:this.#e.preserveCompletedSessions,session:{...n,sessionId:e,streamIndex:i},sessionId:e}))}}};async function postTurnWithRetry(e){let t=e.mustDeliver?10:1,r,i,a;for(let o=0;o<t;o+=1){let s=await fetch(e.url,{body:e.body,headers:e.headers,method:`POST`,redirect:e.redirect,signal:e.signal??null});if(s.ok)return s;if(r=s.status,i=await s.text(),a=s.headers,!isRetryableDeliveryFailure(s.status,i))throw new ClientError(s.status,i,s.headers);o<t-1&&await sleep(200)}throw new ClientError(r??0,i??`Failed to deliver session turn.`,a)}function isRetryableDeliveryFailure(e,t){return e===500&&/target session was not found/i.test(t)}async function sleep(e){await new Promise(t=>setTimeout(t,e))}function normalizeSendTurnInput(e){return typeof e==`string`?{message:e}:e}function createHandleMessageBody(e){let t={};return e.input.message!==void 0&&(t.message=e.input.message),e.input.inputResponses!==void 0&&e.input.inputResponses.length>0&&(t.inputResponses=e.input.inputResponses),e.input.clientContext!==void 0&&(t.clientContext=e.input.clientContext),e.outputSchema!==void 0&&(t.outputSchema=e.outputSchema),e.session.continuationToken!==void 0&&(t.continuationToken=e.session.continuationToken),Object.keys(t).length===0||e.session.continuationToken===void 0&&t.message===void 0||e.session.continuationToken!==void 0&&t.message===void 0&&t.inputResponses===void 0?null:t}export{ClientSession};
1
+ import{EVE_CREATE_SESSION_ROUTE_PATH,createEveCancelTurnRoutePath,createEveContinueSessionRoutePath}from"#protocol/routes.js";import{ClientError}from"#client/client-error.js";import{advanceSession}from"#client/session-utils.js";import{createClientUrl}from"#client/url.js";import{MessageResponse}from"#client/message-response.js";import{EVE_SESSION_ID_HEADER,isCurrentTurnBoundaryEvent}from"#protocol/message.js";import{normalizeOutputSchemaForRequest}from"#client/output-schema.js";import{isStreamDisconnectError,readNdjsonStream}from"#client/ndjson.js";import{CancelTurnResponseSchema}from"#protocol/cancel-turn.js";import{openStreamBody,openStreamIterable}from"#client/open-stream.js";var ClientSession=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get state(){return this.#t}async send(e){let t=normalizeSendTurnInput(e),n=this.#t,{continuationToken:r,sessionId:i}=await this.#n(t,n);return this.#t===n&&(this.#t={...n,sessionId:i}),new MessageResponse({continuationToken:r,createStream:()=>this.#r(i,r,n,t),sessionId:i})}async cancel(e){let n=this.#t.sessionId;if(!n)throw Error(`Session has no session ID. Send a message first.`);let i=createClientUrl(this.#e.host,createEveCancelTurnRoutePath(n)),o=await this.#e.resolveHeaders();o.set(`content-type`,`application/json`);let s=await fetch(i,withRedirectPolicy({headers:o,method:`POST`,body:e?JSON.stringify(e):void 0},this.#e.redirect)),c=await s.text();if(!s.ok)throw new ClientError(s.status,c,s.headers);let l;try{l=JSON.parse(c)}catch{throw Error(`Cancel route returned invalid JSON (${s.status}).`)}let u=CancelTurnResponseSchema.safeParse(l);if(!u.success||u.data.sessionId!==n)throw Error(`Cancel route returned an invalid response (${s.status}).`);return{sessionId:u.data.sessionId,status:u.data.status}}stream(e){let t=this.#t.sessionId;if(!t)throw Error(`Session has no session ID. Send a message first.`);return this.#a(t,e)}async#n(t,r){let i=r.sessionId?createEveContinueSessionRoutePath(r.sessionId):EVE_CREATE_SESSION_ROUTE_PATH,o=createClientUrl(this.#e.host,i),c=await this.#e.resolveHeaders(t.headers);c.set(`content-type`,`application/json`);let u=createHandleMessageBody({input:t,outputSchema:normalizeOutputSchemaForRequest(t.outputSchema),session:r});if(u===null)throw Error(`Session.send requires a non-empty message, inputResponses, or both.`);let d=await postTurnWithRetry({body:JSON.stringify(u),headers:c,mustDeliver:(t.inputResponses?.length??0)>0,redirect:this.#e.redirect,signal:t.signal,url:o}),f=await d.json(),p=(typeof f.sessionId==`string`?f.sessionId:void 0)??d.headers.get(EVE_SESSION_ID_HEADER)?.trim()??r.sessionId;if(!p)throw Error(`Message route did not return a session id.`);return{continuationToken:typeof f.continuationToken==`string`?f.continuationToken:void 0,sessionId:p}}async*#r(e,t,n,r){let a=[];try{let t=n.sessionId===e?n.streamIndex:0,i=this.#e.maxReconnectAttempts;for(;;){let n=await this.#i(e,t,r.signal,r.headers),o=!1;try{for await(let e of readNdjsonStream(n))if(a.push(e),t+=1,yield e,isCurrentTurnBoundaryEvent(e)){o=!0;break}}catch(e){if(!isStreamDisconnectError(e))throw e}if(o||r.signal?.aborted||i<=0)break;--i}}finally{this.#t=advanceSession({continuationToken:t,events:a,preserveCompletedSessions:this.#e.preserveCompletedSessions,sessionId:e,session:n})}}async#i(e,t,n,r){return await openStreamBody({host:this.#e.host,resolveHeaders:()=>this.#e.resolveHeaders(r),redirect:this.#e.redirect,sessionId:e,signal:n,startIndex:t})}async*#a(e,t){let n=this.#t,r=t?.startIndex??n.streamIndex,a=[];try{for await(let n of openStreamIterable({host:this.#e.host,maxReconnectAttempts:this.#e.maxReconnectAttempts,resolveHeaders:()=>this.#e.resolveHeaders(),redirect:this.#e.redirect,sessionId:e,signal:t?.signal,startIndex:r}))a.push(n),yield n}finally{r>=0&&(this.#t=advanceSession({continuationToken:n.continuationToken,events:a,preserveCompletedSessions:this.#e.preserveCompletedSessions,session:{...n,sessionId:e,streamIndex:r},sessionId:e}))}}};async function postTurnWithRetry(e){let t=e.mustDeliver?10:1,n,i,a;for(let o=0;o<t;o+=1){let s=await fetch(e.url,{body:e.body,headers:e.headers,method:`POST`,redirect:e.redirect,signal:e.signal??null});if(s.ok)return s;if(n=s.status,i=await s.text(),a=s.headers,!isRetryableDeliveryFailure(s.status,i))throw new ClientError(s.status,i,s.headers);o<t-1&&await sleep(200)}throw new ClientError(n??0,i??`Failed to deliver session turn.`,a)}function isRetryableDeliveryFailure(e,t){return e===500&&/target session was not found/i.test(t)}async function sleep(e){await new Promise(t=>setTimeout(t,e))}function normalizeSendTurnInput(e){return typeof e==`string`?{message:e}:e}function createHandleMessageBody(e){let t={};return e.input.message!==void 0&&(t.message=e.input.message),e.input.inputResponses!==void 0&&e.input.inputResponses.length>0&&(t.inputResponses=e.input.inputResponses),e.input.clientContext!==void 0&&(t.clientContext=e.input.clientContext),e.outputSchema!==void 0&&(t.outputSchema=e.outputSchema),e.session.continuationToken!==void 0&&(t.continuationToken=e.session.continuationToken),Object.keys(t).length===0||e.session.continuationToken===void 0&&t.message===void 0||e.session.continuationToken!==void 0&&t.message===void 0&&t.inputResponses===void 0?null:t}function withRedirectPolicy(e,t){return t===void 0?e:{...e,redirect:t}}export{ClientSession};
@@ -1,6 +1,7 @@
1
1
  import type { UserContent } from "ai";
2
2
  import type { StandardJSONSchemaV1 } from "#compiled/@standard-schema/spec/index.js";
3
3
  import type { HandleMessageStreamEvent } from "#protocol/message.js";
4
+ import type { CancelTurnStatus } from "#protocol/cancel-turn.js";
4
5
  import type { InputRequest, InputResponse } from "#runtime/input/types.js";
5
6
  import type { JsonObject } from "#shared/json.js";
6
7
  export type { AgentInfoChannelEntry, AgentInfoChannels, AgentInfoConnectionEntry, AgentInfoDynamicResolverEntry, AgentInfoEntry, AgentInfoFrameworkChannelEntry, AgentInfoFrameworkToolEntry, AgentInfoHookEntry, AgentInfoInstructions, AgentInfoInstructionsEntry, AgentInfoResult, AgentInfoSandboxEntry, AgentInfoScheduleEntry, AgentInfoSkillEntry, AgentInfoSource, AgentInfoSubagentEntry, AgentInfoToolEntry, AgentInfoTools, } from "./agent-info-schema.js";
@@ -147,6 +148,13 @@ export interface StreamOptions {
147
148
  */
148
149
  readonly signal?: AbortSignal;
149
150
  }
151
+ /** Result of requesting cancellation for a client session's active turn. */
152
+ export interface CancelSessionResult {
153
+ /** Session whose active turn was targeted. */
154
+ readonly sessionId: string;
155
+ /** Both outcomes are successful; `no_active_turn` means there was nothing left to cancel. */
156
+ readonly status: CancelTurnStatus;
157
+ }
150
158
  /**
151
159
  * Aggregated result of one message turn, returned by
152
160
  * {@link MessageResponse.result}.
@@ -28,12 +28,12 @@
28
28
  "@vercel/detect-agent": "1.2.3",
29
29
  "@vercel/oidc": "3.5.0",
30
30
  "@vercel/sandbox": "2.3.0",
31
- "@workflow/core": "5.0.0-beta.34",
32
- "@workflow/errors": "5.0.0-beta.10",
31
+ "@workflow/core": "5.0.0-beta.35",
32
+ "@workflow/errors": "5.0.0-beta.11",
33
33
  "@workflow/serde": "5.0.0-beta.2",
34
- "@workflow/world": "5.0.0-beta.20",
35
- "@workflow/world-local": "5.0.0-beta.28",
36
- "@workflow/world-vercel": "5.0.0-beta.30",
34
+ "@workflow/world": "5.0.0-beta.21",
35
+ "@workflow/world-local": "5.0.0-beta.29",
36
+ "@workflow/world-vercel": "5.0.0-beta.31",
37
37
  "zod": "4.4.3",
38
38
  "zod-validation-error": "5.0.0"
39
39
  },
@@ -1,2 +1,2 @@
1
- import{c as e,i as t}from"../../_chunks/workflow/dist-DpDDcpTl.js";import{An as n,C as r,Cn as i,Dn as a,En as o,Mn as s,R as c,T as l,Tn as u,fn as d,h as f,jn as p,mn as m,pn as h,t as g,z as _}from"../../_chunks/workflow/attribute-changes-MGTOG_uX.js";import"../../_chunks/workflow/dist-Blxnyb7-.js";import{n as v}from"../../_chunks/workflow/resume-hook-DHP5ql3-.js";import{t as y}from"../../_chunks/workflow/sleep-uA9pS-PT.js";function b(e){p(`createHook()`,`https://workflow-sdk.dev/docs/api-reference/workflow/create-hook`,b)}function x(e){p(`createWebhook()`,`https://workflow-sdk.dev/docs/api-reference/workflow/create-webhook`,x)}function S({schema:e}={}){function t(e){p(`defineHook().create()`,`https://workflow-sdk.dev/docs/api-reference/workflow/define-hook`,t)}return{create:t,async resume(t,n){if(!e?.[`~standard`])return await v(t,n);let r=e[`~standard`].validate(n);if(r instanceof Promise&&(r=await r),r.issues){let e=r.issues.map(e=>{let t=e.path?.map(e=>String(typeof e==`object`&&e?e.key:e)).join(`.`);return t?` at "${t}": ${e.message}`:` ${e.message}`});throw Error(`Hook payload did not match the defined schema:\n${e.join(`
2
- `)}`)}return await v(t,r.value)}}}async function C(e,n={}){let r=_.getStore(),a=r?.workflowMetadata?.workflowRunId;if(!a)throw new t(`setAttributes() must be called from a 'use workflow' or 'use step' function. Calling it from plain host code is not supported.`);let o=g(e,n);if(o.length!==0){if(r.runReadyBarrier)try{await r.runReadyBarrier}catch{}await(await i()).events.create(a,{eventType:`attr_set`,specVersion:5,eventData:{changes:o,writer:{type:`step`,stepId:r.stepMetadata.stepId,attempt:r.stepMetadata.attempt},...n.allowReservedAttributes===!0?{allowReservedAttributes:!0}:{}}})}}const w=C;function T(){let e=_.getStore();return e||n(`getStepMetadata()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-step-metadata`,T),e.stepMetadata}function E(){let e=_.getStore();return e||s(`getWorkflowMetadata()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-workflow-metadata`,E),e.workflowMetadata}function D(e={}){let t=_.getStore();t||s(`getWritable()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-writable`,D);let{namespace:n}=e,i=t.workflowMetadata.workflowRunId,p=c(i,n),g=t.writables??=new Map,v=g.get(p);if(v)return v.writable;let y=l(r(globalThis,t.ops,i,t.encryptionKey,!0,t.runReadyBarrier),t.encryptionKey),b=new f(i,p,t.runReadyBarrier),x=u();return t.ops.push(x.promise),o(y.readable,b,x).catch(()=>{}),a(y.writable,x),Object.defineProperty(y.writable,d,{value:p,writable:!1}),Object.defineProperty(y.writable,m,{value:i,writable:!1}),t.workflowDeploymentId&&Object.defineProperty(y.writable,h,{value:t.workflowDeploymentId,writable:!1}),g.set(p,{writable:y.writable,state:x}),y.writable}export{t as FatalError,e as RetryableError,b as createHook,x as createWebhook,S as defineHook,w as experimental_setAttributes,T as getStepMetadata,E as getWorkflowMetadata,D as getWritable,C as setAttributes,y as sleep};
1
+ import{i as e,l as t}from"../../_chunks/workflow/dist-BYo8Gno2.js";import{An as n,B as r,D as i,Dn as a,Fn as o,In as s,Pn as c,T as l,V as u,_ as d,_n as f,gn as p,jn as m,kn as h,t as g,vn as _}from"../../_chunks/workflow/attribute-changes-DXbmITuI.js";import"../../_chunks/workflow/dist-CSfKNxQW.js";import{n as v}from"../../_chunks/workflow/resume-hook-DvvgYsRt.js";import{t as y}from"../../_chunks/workflow/sleep-DzxrwWTs.js";function b(e){o(`createHook()`,`https://workflow-sdk.dev/docs/api-reference/workflow/create-hook`,b)}function x(e){o(`createWebhook()`,`https://workflow-sdk.dev/docs/api-reference/workflow/create-webhook`,x)}function S({schema:e}={}){function t(e){o(`defineHook().create()`,`https://workflow-sdk.dev/docs/api-reference/workflow/define-hook`,t)}return{create:t,async resume(t,n){if(!e?.[`~standard`])return await v(t,n);let r=e[`~standard`].validate(n);if(r instanceof Promise&&(r=await r),r.issues){let e=r.issues.map(e=>{let t=e.path?.map(e=>String(typeof e==`object`&&e?e.key:e)).join(`.`);return t?` at "${t}": ${e.message}`:` ${e.message}`});throw Error(`Hook payload did not match the defined schema:\n${e.join(`
2
+ `)}`)}return await v(t,r.value)}}}async function C(t,n={}){let r=u.getStore(),i=r?.workflowMetadata?.workflowRunId;if(!i)throw new e(`setAttributes() must be called from a 'use workflow' or 'use step' function. Calling it from plain host code is not supported.`);let o=g(t,n);if(o.length!==0){if(r.runReadyBarrier)try{await r.runReadyBarrier}catch{}await(await a()).events.create(i,{eventType:`attr_set`,specVersion:5,eventData:{changes:o,writer:{type:`step`,stepId:r.stepMetadata.stepId,attempt:r.stepMetadata.attempt},...n.allowReservedAttributes===!0?{allowReservedAttributes:!0}:{}}})}}const w=C;function T(){let e=u.getStore();return e||c(`getStepMetadata()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-step-metadata`,T),e.stepMetadata}function E(){let e=u.getStore();return e||s(`getWorkflowMetadata()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-workflow-metadata`,E),e.workflowMetadata}function D(e={}){let t=u.getStore();t||s(`getWritable()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-writable`,D);let{namespace:a}=e,o=t.workflowMetadata.workflowRunId,c=r(o,a),g=t.writables??=new Map,v=g.get(c);if(v)return v.writable;let y=i(l(globalThis,t.ops,o,t.encryptionKey,!0,t.runReadyBarrier),t.encryptionKey),b=new d(o,c,t.runReadyBarrier),x=h();return t.ops.push(x.promise),n(y.readable,b,x).catch(()=>{}),m(y.writable,x),Object.defineProperty(y.writable,p,{value:c,writable:!1}),Object.defineProperty(y.writable,_,{value:o,writable:!1}),t.workflowDeploymentId&&Object.defineProperty(y.writable,f,{value:t.workflowDeploymentId,writable:!1}),g.set(c,{writable:y.writable,state:x}),y.writable}export{e as FatalError,t as RetryableError,b as createHook,x as createWebhook,S as defineHook,w as experimental_setAttributes,T as getStepMetadata,E as getWorkflowMetadata,D as getWritable,C as setAttributes,y as sleep};
@@ -72,6 +72,61 @@ export declare function loadWorkflowRunEvents(runId: string, afterCursor?: strin
72
72
  events: Event[];
73
73
  cursor: string | null;
74
74
  }>;
75
+ /**
76
+ * Maximum number of times a replay-context event creation will reload the
77
+ * event log and retry after the backend rejects it as stale (412). After this
78
+ * many failed reloads the precondition error propagates so the run is
79
+ * re-invoked from the queue with a fresh replay.
80
+ */
81
+ export declare const PRECONDITION_MAX_RELOAD_RETRIES = 2;
82
+ /**
83
+ * A mutable view of the runtime's in-memory event log. `withPreconditionRetry`
84
+ * appends freshly-loaded events to `events` (in place) and advances `cursor`
85
+ * when it reloads, so the caller's loaded snapshot stays current.
86
+ */
87
+ export interface MutableEventLog {
88
+ events: Event[];
89
+ cursor: string | null;
90
+ }
91
+ /**
92
+ * Whether the optimistic-concurrency guard for event creation is enabled
93
+ * (`WORKFLOW_PRECONDITION_GUARD=1`, set where the runtime executes). Off by
94
+ * default: replay-context creates only send a `stateUpdatedAt` snapshot (and
95
+ * can therefore be rejected with 412 by the backend) when it is enabled.
96
+ */
97
+ export declare function isPreconditionGuardEnabled(): boolean;
98
+ /**
99
+ * The `stateUpdatedAt` value to send with a replay-context event creation: the
100
+ * ULID time (epoch ms) of the latest event the runtime has loaded. Events are
101
+ * stored in ascending order, so the last one is the newest. Returns `undefined`
102
+ * when there are no events or the latest id is not a decodable ULID.
103
+ *
104
+ * Granularity: snapshots are epoch-milliseconds, and the backend allows an
105
+ * equal-timestamp snapshot (an up-to-date client must not be rejected). Two
106
+ * out-of-band events landing in the same millisecond where only the first was
107
+ * loaded therefore pass the guard undetected — the guard is best-effort by
108
+ * design, and fails open rather than livelocking.
109
+ */
110
+ export declare function latestEventStateUpdatedAt(events: Event[]): number | undefined;
111
+ /**
112
+ * The `stateUpdatedAt` to attach to a replay-context event creation:
113
+ * the loaded snapshot's ULID time when the precondition guard is enabled,
114
+ * `undefined` (no guard, backend behaves as before) otherwise.
115
+ */
116
+ export declare function stateUpdatedAtForCreate(events: Event[]): number | undefined;
117
+ /**
118
+ * Runs a replay-context event creation with the optimistic-concurrency guard.
119
+ *
120
+ * `op` receives the current `stateUpdatedAt` (the ULID time of the latest
121
+ * loaded event) to pass to `world.events.create`. If the backend rejects the
122
+ * creation as stale (`PreconditionFailedError` / 412), the event log is
123
+ * reloaded to completion from the last cursor, merged into `log` in place, and
124
+ * `op` is retried with the now-newer snapshot — up to
125
+ * `PRECONDITION_MAX_RELOAD_RETRIES` times. If it still fails, the error is
126
+ * rethrown so the run falls back to a queue re-invocation. Non-precondition
127
+ * errors are rethrown immediately.
128
+ */
129
+ export declare function withPreconditionRetry<T>(runId: string, log: MutableEventLog, op: (stateUpdatedAt: number | undefined) => Promise<T>): Promise<T>;
75
130
  /**
76
131
  * Wraps a request/response handler and adds a health check "mode"
77
132
  * based on the presence of a `__health` query parameter.
@@ -2,6 +2,15 @@
2
2
  * Extracts the run's creation timestamp (epoch milliseconds) from a `wrun_`
3
3
  * run ID by decoding the embedded ULID time component.
4
4
  *
5
+ * `@workflow/world-vercel`'s region-tagged run IDs mark an ID as carrying
6
+ * metadata by setting the most-significant bit of the ULID's 48-bit
7
+ * timestamp, which would otherwise skew the decoded time past the year 6400.
8
+ * The tag-bit handling is delegated to the scheme's own codec —
9
+ * `decode()` returns the ULID with the tag bit cleared — so if the tagged
10
+ * layout ever evolves (the scheme carries a 5-bit version field for exactly
11
+ * that), this anchor keeps tracking the codec instead of silently diverging.
12
+ * For untagged input `decode()` is a passthrough.
13
+ *
5
14
  * Returns `undefined` when `runId` is not a decodable `wrun_<ulid>` (e.g. a
6
15
  * legacy/non-ULID id, or a test fixture like `wrun_test`); callers fall back to
7
16
  * an authoritative timestamp from the run snapshot (`createdAt`) in that case.
@@ -8,6 +8,8 @@ export interface StepExecutorParams {
8
8
  workflowDeploymentId?: string;
9
9
  workflowName: string;
10
10
  workflowStartedAt: number;
11
+ /** Root run id of this run's lineage, carried into the step context. */
12
+ rootRunId?: string;
11
13
  stepId: string;
12
14
  stepName: string;
13
15
  encryptionKey?: CryptoKey;
@@ -1,13 +1,21 @@
1
1
  import type { Event } from '#compiled/@workflow/world/index.js';
2
2
  /**
3
- * Client-side latency measurement (TTFS / STSO) threaded from the
3
+ * Client-side latency measurement (TTFS / STSO / RSFS) threaded from the
4
4
  * orchestrator's inline execution path into `executeStep`.
5
5
  *
6
6
  * TTFS (time-to-first-step) measures run creation → the first step's body
7
7
  * beginning to execute. STSO (step-to-step overhead) measures the previous
8
- * step's terminal event → the next step's body beginning to execute. Both are
9
- * attached to the step's terminal event so a backend can emit latency metrics
10
- * from the event write alone, without extra event-log queries.
8
+ * step's terminal event → the next step's body beginning to execute. RSFS
9
+ * (run-started-to-first-step) measures the `run_started` response landing
10
+ * the first step's start POST being issued — a sub-window of TTFS that
11
+ * isolates replay overhead from the run-creation queue hop; `finalSchedulingReplay`
12
+ * is the synchronous workflow-function-execution duration of only the FINAL
13
+ * replay pass within that window (the pass that reached and scheduled the
14
+ * first step) — it is NOT accumulated across earlier pre-first-step passes
15
+ * (see {@link StepLatencyTracking.replayMs}), so it must not be read as "the
16
+ * replay portion of RSFS". All are attached to the step's terminal
17
+ * event so a backend can emit latency metrics from the event write alone,
18
+ * without extra event-log queries.
11
19
  *
12
20
  * Eligibility is decided by the orchestrator (which owns the event log) via
13
21
  * {@link computeStepLatencyTracking}; the final values are computed by
@@ -49,6 +57,36 @@ export interface StepLatencyTracking {
49
57
  stepCount?: number;
50
58
  /** Number of events already in the event log. */
51
59
  eventCount?: number;
60
+ /**
61
+ * Epoch ms the `run_started` response was received/parsed by the SDK.
62
+ * Present only when the step qualifies for RSFS — the same eligibility as
63
+ * TTFS (see {@link computeStepLatencyTracking}), plus a recoverable
64
+ * anchor. In turbo mode, `run_started` is backgrounded rather than
65
+ * awaited, so this is stamped at the point the runtime synthesizes the
66
+ * run locally and begins replay instead of at the real response; the
67
+ * first step's start POST is still chained on the real `run_started`
68
+ * promise (see step-executor.ts), so RSFS still ends up measuring the
69
+ * genuine run_started-to-first-step-POST stretch even though the two
70
+ * halves overlap under turbo.
71
+ */
72
+ rsfsAnchorMs?: number;
73
+ /**
74
+ * Wall-clock ms this invocation's synchronous workflow-function replay
75
+ * took: from calling `runWorkflow` to it throwing the suspension that
76
+ * scheduled this batch. Excludes awaited network I/O (the suspension's
77
+ * event commits, the step's own start POST). Present only alongside
78
+ * `rsfsAnchorMs`.
79
+ *
80
+ * This is the FINAL replay pass only — the invocation that reached and
81
+ * scheduled the first step. Valid RSFS paths can replay more than once
82
+ * before the first step (e.g. a workflow-body `setAttributes()` detour
83
+ * replays twice), and a redelivery omits earlier invocations' replay work
84
+ * entirely; this value is not accumulated across those earlier passes.
85
+ * Do not read it as "the replay portion of RSFS" — RSFS
86
+ * ({@link rsfsAnchorMs}) covers the whole run_started-to-first-step
87
+ * window, this covers only the last pass.
88
+ */
89
+ replayMs?: number;
52
90
  /** Whether turbo mode is active for this invocation. */
53
91
  turbo: boolean;
54
92
  }
@@ -58,6 +96,15 @@ export interface StepLatencyEventData {
58
96
  stso?: number;
59
97
  stepCount?: number;
60
98
  eventCount?: number;
99
+ /** Client-measured run_started → first step's start POST, ms. */
100
+ rsfs?: number;
101
+ /**
102
+ * Client-measured wall-clock ms of the FINAL replay pass that scheduled
103
+ * the first step (see {@link StepLatencyTracking.replayMs}) — not
104
+ * accumulated across earlier pre-first-step passes, so it must not be
105
+ * read as "the replay portion of `rsfs`".
106
+ */
107
+ finalSchedulingReplay?: number;
61
108
  optimizations?: string[];
62
109
  }
63
110
  /**
@@ -82,6 +129,19 @@ export declare function computeStepLatencyTracking(params: {
82
129
  invocationStartedClean: boolean;
83
130
  /** Epoch ms of run creation, if recoverable. Absent disqualifies TTFS. */
84
131
  runCreatedAtMs: number | undefined;
132
+ /**
133
+ * Epoch ms the `run_started` response was received/parsed by the SDK (or,
134
+ * under turbo, the instant the run was synthesized locally — see
135
+ * {@link StepLatencyTracking.rsfsAnchorMs}). Absent disqualifies RSFS.
136
+ */
137
+ runStartedReceivedAtMs: number | undefined;
138
+ /**
139
+ * Wall-clock ms this suspension's `runWorkflow` call spent executing
140
+ * synchronously before throwing — the FINAL replay pass only, not
141
+ * accumulated across earlier passes. See
142
+ * {@link StepLatencyTracking.replayMs}.
143
+ */
144
+ replayMs: number;
85
145
  /** See {@link StepLatencyTracking.preStepBlockingMs}. */
86
146
  preStepBlockingMs: number;
87
147
  /**
@@ -122,6 +182,12 @@ export declare function computeStepLatencyEventData(params: {
122
182
  tracking: StepLatencyTracking | undefined;
123
183
  /** `Date.now()` taken immediately before user step code began executing. */
124
184
  stepCodeStartedAtMs: number;
185
+ /**
186
+ * `Date.now()` taken immediately before the first step's start POST
187
+ * (`step_started`) was issued. Present only for the lazy inline steps RSFS
188
+ * cares about; see the call sites in step-executor.ts.
189
+ */
190
+ stepStartPostSentAtMs: number | undefined;
125
191
  attempt: number;
126
192
  /** Whether this step was started lazily (no separate step_created write). */
127
193
  lazyStepStart: boolean;
@@ -1,12 +1,21 @@
1
1
  import type { Span } from '#compiled/@opentelemetry/api/index.js';
2
2
  import { type SerializedData, type WorkflowRun, type World } from '#compiled/@workflow/world/index.js';
3
3
  import type { StepInvocationQueueItem, WorkflowSuspension } from '../global.js';
4
+ import { type MutableEventLog } from './helpers.js';
4
5
  export interface SuspensionHandlerParams {
5
6
  suspension: WorkflowSuspension;
6
7
  world: World;
7
8
  run: WorkflowRun;
8
9
  span?: Span;
9
10
  requestId?: string;
11
+ /**
12
+ * The runtime's loaded event log. Each event creation is sent with this
13
+ * snapshot's `stateUpdatedAt` and, if the backend rejects it as stale (412),
14
+ * the log is reloaded in place and the create is retried — see
15
+ * `withPreconditionRetry`. Guarding per-create (rather than the whole
16
+ * suspension) ensures a retry never re-issues an already-created event.
17
+ */
18
+ eventLog?: MutableEventLog;
10
19
  /**
11
20
  * Turbo mode only: a promise that resolves once the backgrounded
12
21
  * `run_started` has landed (the run exists). When present, every world write
@@ -94,5 +103,5 @@ export interface SuspensionHandlerResult {
94
103
  * 1. Hooks are processed first to prevent race conditions with webhook receivers
95
104
  * 2. Step events and wait events are created in parallel
96
105
  */
97
- export declare function handleSuspension({ suspension, world, run, span, requestId, runReadyBarrier, }: SuspensionHandlerParams): Promise<SuspensionHandlerResult>;
106
+ export declare function handleSuspension({ suspension, world, run, span, requestId, eventLog, runReadyBarrier, }: SuspensionHandlerParams): Promise<SuspensionHandlerResult>;
98
107
  //# sourceMappingURL=suspension-handler.d.ts.map