eve 1.0.0-rc.4 → 1.0.0-rc.5
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.
- package/CHANGELOG.md +11 -22
- package/dist/src/compiled/.vendor-stamp.json +7 -7
- package/dist/src/compiled/@vercel/agent-runs/core/content-policy.d.ts +8 -0
- package/dist/src/compiled/@vercel/agent-runs/index.js +2 -1
- package/dist/src/compiled/@vercel/agent-runs/otel.js +1 -1
- package/dist/src/compiled/@workflow/core/create-hook.d.ts +15 -0
- package/dist/src/compiled/@workflow/core/events-consumer.d.ts +1 -1
- package/dist/src/compiled/@workflow/core/index.js +2 -2
- package/dist/src/compiled/@workflow/core/private.d.ts +2 -2
- package/dist/src/compiled/@workflow/core/private.js +1 -1
- package/dist/src/compiled/@workflow/core/runtime/after-terminal-write.d.ts +33 -0
- package/dist/src/compiled/@workflow/core/runtime/child-run-completion-notify.d.ts +36 -0
- package/dist/src/compiled/@workflow/core/runtime/child-run-completion.d.ts +45 -0
- package/dist/src/compiled/@workflow/core/runtime/delivery.d.ts +5 -2
- package/dist/src/compiled/@workflow/core/runtime/helpers.d.ts +9 -1
- package/dist/src/compiled/@workflow/core/runtime/helpers.js +1 -1
- package/dist/src/compiled/@workflow/core/runtime/out-of-band-observation.d.ts +6 -0
- package/dist/src/compiled/@workflow/core/runtime/quickjs-runtime.d.ts +5 -2
- package/dist/src/compiled/@workflow/core/runtime/resume-hook.d.ts +9 -1
- package/dist/src/compiled/@workflow/core/runtime/run.d.ts +25 -2
- package/dist/src/compiled/@workflow/core/runtime/runs.d.ts +1 -1
- package/dist/src/compiled/@workflow/core/runtime/start-hook-binding.d.ts +2 -2
- package/dist/src/compiled/@workflow/core/runtime/start-hook-delivery.d.ts +3 -3
- package/dist/src/compiled/@workflow/core/runtime/start-hook-holder.d.ts +1 -1
- package/dist/src/compiled/@workflow/core/runtime/start.d.ts +5 -5
- package/dist/src/compiled/@workflow/core/runtime.js +1 -1
- package/dist/src/compiled/@workflow/core/serialization/types.d.ts +1 -1
- package/dist/src/compiled/@workflow/core/serialization.js +1 -1
- package/dist/src/compiled/@workflow/core/telemetry/semantic-conventions.d.ts +9 -9
- package/dist/src/compiled/@workflow/core/version.d.ts +1 -1
- package/dist/src/compiled/@workflow/core/workflow.js +1 -1
- package/dist/src/compiled/@workflow/errors/ansi.d.ts +57 -0
- package/dist/src/compiled/@workflow/errors/ansi.js +8 -0
- package/dist/src/compiled/@workflow/errors/index.js +3 -1
- package/dist/src/compiled/@workflow/world-local/index.d.ts +1 -0
- package/dist/src/compiled/@workflow/world-local/index.js +5 -5
- package/dist/src/compiled/@workflow/world-vercel/index.js +1 -1
- package/dist/src/compiled/_chunks/workflow/attribute-changes-CZ1IbpSN.js +6 -0
- package/dist/src/compiled/_chunks/workflow/delivery-DpGLtB6b.js +1 -0
- package/dist/src/compiled/_chunks/workflow/{dist-BSEKQ8u2.js → dist-C3TM5_NG.js} +18 -18
- package/dist/src/compiled/_chunks/workflow/helpers-DWfdYiCu.js +1 -0
- package/dist/src/compiled/_chunks/workflow/mcp-CbNv8aLf.js +5 -0
- package/dist/src/compiled/_chunks/workflow/private-D07opN0n.js +1 -0
- package/dist/src/compiled/_chunks/workflow/resume-hook-ZanR4XtL.js +1 -0
- package/dist/src/compiled/_chunks/workflow/run-D_ZgaSHx.js +34 -0
- package/dist/src/compiled/_chunks/workflow/serialization-BsJ0NayH.js +12 -0
- package/dist/src/compiled/_chunks/workflow/signal-exit-DlWTrAfZ.js +95 -0
- package/dist/src/compiled/_chunks/workflow/sleep-C8DQfwTV.js +1 -0
- package/dist/src/compiled/_chunks/workflow/suspension-hooks-B4vCJhLa.js +3 -0
- package/dist/src/compiled/_chunks/workflow/{token-CAXqMDzD.js → token-DJ4jrYrW.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{token-BgwBCNd5.js → token-DVg7xSMC.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{token-util-BIUPjVKe.js → token-util-6qJrYbu1.js} +1 -1
- package/dist/src/execution/dynamic-workflow/tool.js +1 -1
- package/dist/src/execution/tools/agent-router-workflow.js +1 -1
- package/dist/src/internal/application/compiled-artifacts.d.ts +5 -0
- package/dist/src/internal/application/compiled-artifacts.js +1 -1
- package/dist/src/internal/application/stamped-package-version.js +1 -1
- package/dist/src/internal/authored-asset-import-plugin.d.ts +2 -0
- package/dist/src/internal/authored-asset-import-plugin.js +1 -1
- package/dist/src/internal/authored-module-loader.d.ts +5 -1
- package/dist/src/internal/authored-module-loader.js +1 -1
- package/dist/src/internal/authored-package-boundary.d.ts +15 -0
- package/dist/src/internal/authored-package-boundary.js +1 -1
- package/dist/src/internal/authored-package-tsconfig-paths.d.ts +2 -0
- package/dist/src/internal/authored-package-tsconfig-paths.js +1 -1
- package/dist/src/internal/authored-relative-extension-resolver.d.ts +2 -0
- package/dist/src/internal/authored-relative-extension-resolver.js +1 -1
- package/dist/src/internal/authored-runtime-modules.d.ts +4 -0
- package/dist/src/internal/authored-runtime-modules.js +1 -1
- package/dist/src/internal/bundler/authored-plugins.d.ts +6 -0
- package/dist/src/internal/bundler/authored-plugins.js +1 -1
- package/dist/src/internal/host-traced-dependencies.d.ts +16 -0
- package/dist/src/internal/host-traced-dependencies.js +1 -0
- package/dist/src/internal/installed-packages.d.ts +14 -0
- package/dist/src/internal/installed-packages.js +1 -0
- package/dist/src/internal/nitro/host/create-host-nitro.js +1 -1
- package/dist/src/internal/nitro/host/externals-policy.js +1 -1
- package/dist/src/internal/nitro/host/host-plugins.d.ts +2 -0
- package/dist/src/internal/nitro/host/host-plugins.js +1 -1
- package/dist/src/internal/workflow/development-world-server.js +1 -1
- package/dist/src/internal/workflow/local-world-delivery-auth.js +1 -1
- package/dist/src/internal/workflow/local-world-recovery.d.ts +23 -0
- package/dist/src/internal/workflow/local-world-recovery.js +1 -0
- package/dist/src/internal/workflow-bundle/workflow-core-shim.d.ts +3 -7
- package/dist/src/internal/workflow-bundle/workflow-core-shim.js +1 -1
- package/dist/src/runtime/subagents/workflow.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/tools/provided/ask-question-workflow.js +1 -1
- package/dist/src/tools/provided/sleep-workflow.js +1 -1
- package/docs/guides/deployment/workflow-worlds.md +3 -1
- package/docs/reference/cli/index.md +1 -1
- package/docs/tools/workflows.mdx +6 -2
- package/package.json +5 -5
- package/dist/src/compiled/_chunks/workflow/attribute-changes-AOnel6r3.js +0 -6
- package/dist/src/compiled/_chunks/workflow/delivery-DS_fO4NK.js +0 -1
- package/dist/src/compiled/_chunks/workflow/dist-C32arEh7.js +0 -3
- package/dist/src/compiled/_chunks/workflow/helpers-9AgMPjGd.js +0 -1
- package/dist/src/compiled/_chunks/workflow/mcp-DyzJqSIB.js +0 -5
- package/dist/src/compiled/_chunks/workflow/private-CPx_GgTs.js +0 -1
- package/dist/src/compiled/_chunks/workflow/resume-hook-XRKdnxa4.js +0 -1
- package/dist/src/compiled/_chunks/workflow/run-CfkXT03M.js +0 -32
- package/dist/src/compiled/_chunks/workflow/serialization-bMKNKGL1.js +0 -15
- package/dist/src/compiled/_chunks/workflow/sleep-rBxEVIeO.js +0 -1
- package/dist/src/compiled/_chunks/workflow/suspension-hooks-RNPAbmnS.js +0 -5
- package/dist/src/compiled/_chunks/workflow/undici-DKqj707r.js +0 -95
- package/dist/src/compiled/_chunks/workflow/wait-until-RI3P9oYt.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,30 +1,19 @@
|
|
|
1
|
-
# eve 1.0.0-rc.
|
|
1
|
+
# eve 1.0.0-rc.5
|
|
2
2
|
|
|
3
|
-
Released 2026-11-
|
|
4
|
-
|
|
5
|
-
## Breaking Changes
|
|
6
|
-
|
|
7
|
-
- Every agent now gets a default `edit_file` tool, the code extension drops `code__apply_patch`, and `bash` results and eve's system prompt now match pi's.
|
|
8
|
-
`edit_file`, exported from `eve/tools/edit_file`, edits one sandbox file with exact text replacements matched the same way as pi's `edit` tool. The model sends `path` and a list of `{ oldText, newText }` edits, each matched once against the original file, with a fallback that ignores trailing whitespace and normalizes smart quotes, dashes, and special spaces. Files that are not valid UTF-8 are rejected rather than rewritten, and a file keeps its mode, such as its executable bit, on sandboxes that write files with a default mode. Remove it with `defaultTools: false` or an `agent/tools/edit_file.ts` that exports `disableTool()`; an authored `agent/tools/edit_file.ts` replaces it.
|
|
9
|
-
`edit_file` changes existing files without `write_file`. If you disabled or wrapped `write_file` to limit writes, or gate `write_file` in an approval policy, do the same for `edit_file`. `write_file` can also overwrite a file the session read and then changed with `edit_file`, without another `read_file` call. A change made by anything else since the read still requires one.
|
|
10
|
-
The code extension (`eve/extensions/code`) no longer mounts `code__apply_patch`, and the `eve/extensions/code/tools` entry point is removed. Import `grep` from `eve/tools/grep` instead of `eve/extensions/code/tools`. Move an override of the old tool, whether `agent/tools/code__apply_patch.ts` or `agent/extensions/code/tools/apply_patch.ts`, to `agent/tools/edit_file.ts` and spread `editFile` from `eve/tools/edit_file`. `edit_file` takes `path` and `edits` instead of a patch, so a wrapper that reads `input.patch` needs updating. A `code__apply_patch.ts` file that exports `disableTool()` fails `eve build` with `disables a slot with no lower-precedence source`; to keep agents from editing, export `disableTool()` from `agent/tools/edit_file.ts` instead.
|
|
11
|
-
`installCodeTooling()` no longer installs TypeScript or the post-edit diagnostics worker, and `CODE_TOOLING_REVALIDATION_KEY` changed, so sandbox templates keyed on it rebuild once.
|
|
12
|
-
The code extension adds the workspace root's `AGENTS.md`, or `CLAUDE.md` when there is none, to the conversation, and its coding instructions now follow pi's tool guidance. The extension reads the file once per session, with one sandbox command on the first turn, which starts the sandbox. A file over 64,000 bytes is cut off with a note that tells the model where to read the rest.
|
|
13
|
-
A successful `bash` command shows only its output, or `(no output)`, and a command that exits non-zero ends with `[exit code: N]` and reaches the model as an error result. `bash` waits 60 seconds by default before it leaves a command running in the background, and a truncated `stdout` or `stderr` now names a file in the sandbox that holds its full output.
|
|
14
|
-
`toolOutput.errorText(value)` from `eve/tools`, or a `{ type: "error-text", value }` literal, lets any tool's `toModelOutput` show the model a failure while the call still completes, so channels and hooks get the full output on `call.settled`. The MCP channel returns such a result as its text with `isError: true`.
|
|
15
|
-
eve no longer adds a "Tool execution" note about parallel tool calls to every agent's system prompt. Tool calls in one response still run in parallel. Without the note, Sonnet 5.5 solved a concurrency task in 93% of replayed eve-code runs instead of 75%, matching how pi, which runs tool calls in parallel without telling the model, performs.
|
|
16
|
-
Thanks @badlogic for pi, whose MIT-licensed `edit` tool `edit_file` adapts. ([#5892](https://github.com/vercel/eve/pull/5892))
|
|
3
|
+
Released 2026-11-05 · [Compare with 1.0.0-rc.4](https://github.com/vercel/eve/compare/eve%401.0.0-rc.4...eve%401.0.0-rc.5)
|
|
17
4
|
|
|
18
5
|
## Features
|
|
19
6
|
|
|
20
|
-
-
|
|
21
|
-
|
|
7
|
+
- Deployed agents start faster and use less memory, because hosted builds now include each installed package once instead of once per instrumentation file and once more for the agent's modules.
|
|
8
|
+
Before, when instrumentation files imported the same packages as the agent, every one of those packages shipped, loaded, and ran more than once on each cold start. In one production agent with five instrumentation files, the workflow route's bundle dropped from 34 MB to 22 MB and its cold start from about 2.6 s to about 1.8 s. ([#5943](https://github.com/vercel/eve/pull/5943))
|
|
9
|
+
- Update the bundled Workflow runtime to 5.4.0.
|
|
10
|
+
Workflow 5.4.0 resumes a parent run once when a child run finishes instead of polling in a step, honors abort signals when waiting for a run to finish on the Vercel World, and recovers Hook token claims left by a crashed process right away on the local World instead of after 30 seconds. ([#5944](https://github.com/vercel/eve/pull/5944))
|
|
22
11
|
|
|
23
12
|
## Bug Fixes
|
|
24
13
|
|
|
25
|
-
- Fix
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
|
|
14
|
+
- Fix local-world sessions that stalled after `eve start` or `eve dev --resume` restarted mid-turn: a turn waiting on a timer, such as `sleep`, now wakes on time, and a step that was running when the previous process stopped runs again right away instead of after about 14 minutes.
|
|
15
|
+
The timer fix applies to spec 9 runs, which eve now creates by default. The step fix applies to spec 8 runs, including every session created before eve moved to spec 9. For those runs, the interrupted attempt counts toward the step's retries, so a workflow tool step with `maxRetries: 0` that was running when the process stopped fails on restart instead of running again. Run one process per `.eve/.workflow-data` directory: recovery treats steps started before it booted as abandoned. ([#5873](https://github.com/vercel/eve/pull/5873))
|
|
16
|
+
- Fix workflow hook ownership checks and preserve workflow error types and retry timing.
|
|
17
|
+
`hook.getConflict()` now returns the existing owner's run ID inside workflow bodies. `FatalError` and `RetryableError` caught from steps retain their class identity, and workflow-created `RetryableError` values honor `retryAfter`. ([#5937](https://github.com/vercel/eve/pull/5937))
|
|
29
18
|
|
|
30
|
-
For an upgrade across multiple releases, review each version between the installed and target versions in the [target version's changelog](https://raw.githubusercontent.com/vercel/eve/refs/tags/eve%401.0.0-rc.
|
|
19
|
+
For an upgrade across multiple releases, review each version between the installed and target versions in the [target version's changelog](https://raw.githubusercontent.com/vercel/eve/refs/tags/eve%401.0.0-rc.5/packages/eve/CHANGELOG.md).
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"moduleFingerprints": {
|
|
3
3
|
"@eve/catalog": "db73624902ce0b7d60bd87892bfc7c48c946eddf576ba079a8f3b58f0b0733f1",
|
|
4
4
|
"just-secrets": "1ce67d437d0bb06df02e4e99180a3c5f5edf0010314010226e97b96d462bba5d",
|
|
5
|
-
"@vercel/agent-runs": "
|
|
6
|
-
"@workflow/world-local": "
|
|
5
|
+
"@vercel/agent-runs": "5a007e099d42765e38168abe5514adad7f3d873f08020016afa0b74d35391066",
|
|
6
|
+
"@workflow/world-local": "37afac934e42a46ce529bcfc2dd7a00cd24bc8340dda50940bcdc48357772f39"
|
|
7
7
|
},
|
|
8
8
|
"moduleVersions": {
|
|
9
9
|
"@agentclientprotocol/sdk": "1.3.0",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@shadcn/registry": "0.1.3",
|
|
43
43
|
"@standard-schema/spec": "1.1.0",
|
|
44
44
|
"turndown": "7.2.4",
|
|
45
|
-
"@vercel/agent-runs": "1.0.0-rc.
|
|
45
|
+
"@vercel/agent-runs": "1.0.0-rc.2",
|
|
46
46
|
"@vercel/blob": "2.8.0",
|
|
47
47
|
"@vercel/connect": "2.7.0",
|
|
48
48
|
"@vercel/detect-agent": "1.2.3",
|
|
@@ -52,16 +52,16 @@
|
|
|
52
52
|
"@vercel/sandbox": "3.9.0",
|
|
53
53
|
"@vercel/sdk": "1.28.8",
|
|
54
54
|
"@vercel/schedules": "0.0.0-alpha.19",
|
|
55
|
-
"@workflow/core": "5.
|
|
55
|
+
"@workflow/core": "5.4.0",
|
|
56
56
|
"@workflow/errors": "5.1.0",
|
|
57
57
|
"@workflow/serde": "5.0.0",
|
|
58
58
|
"@workflow/world": "5.1.0",
|
|
59
|
-
"@workflow/world-local": "5.2.
|
|
60
|
-
"@workflow/world-vercel": "5.
|
|
59
|
+
"@workflow/world-local": "5.2.1",
|
|
60
|
+
"@workflow/world-vercel": "5.4.0",
|
|
61
61
|
"zod": "4.5.4",
|
|
62
62
|
"zod-validation-error": "5.0.0"
|
|
63
63
|
},
|
|
64
|
-
"scriptHash": "
|
|
64
|
+
"scriptHash": "48d1488056c204611afadca171259dbfc548db8f22d343ff2fed7290544ab2dd",
|
|
65
65
|
"toolVersions": {
|
|
66
66
|
"env-runner>crossws": "0.4.17",
|
|
67
67
|
"env-runner>srvx": "1.0.8",
|
|
@@ -17,6 +17,14 @@ export interface ResolvedContentOptions {
|
|
|
17
17
|
readonly recordInputs: boolean;
|
|
18
18
|
readonly recordOutputs: boolean;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Re-applies the capture-policy attributes that a size-based content strip
|
|
22
|
+
* must not rewrite. Dropping content to fit a checkpoint budget is not the
|
|
23
|
+
* destination declining it, so `agent.trace.content.input` and
|
|
24
|
+
* `agent.trace.content.output` keep the record's real decision; otherwise a
|
|
25
|
+
* restored turn would report "omitted" although capture was on.
|
|
26
|
+
*/
|
|
27
|
+
export declare function preservingCapturePolicy(attributes: Readonly<Record<string, unknown>>, original: Readonly<Record<string, unknown>>): Record<string, unknown>;
|
|
20
28
|
/**
|
|
21
29
|
* The attributes with the declined content removed, or `undefined` when there
|
|
22
30
|
* was none to remove.
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{b as e,f as t,g as n,i as r,l as i,m as a,n as o,o as s,r as c,s as l,t as u,u as d,v as f}from"../../_chunks/workflow/mcp-DyzJqSIB.js";import{n as p,t as m}from"../../_chunks/workflow/delegation-i2O_jNNn.js";import{createHash as h,randomBytes as g,randomUUID as _}from"node:crypto";var v=class{#e;#t;allocateSpanId(){return b(16)}deriveSpanId(e){return y(e)}deriveTraceId(e){let t=h(`sha256`).update(e).digest(`hex`).slice(0,32);return/^0+$/u.test(t)?`00000000000000000000000000000001`:t}generateSpanId(){let e=this.#e;return e===void 0?b(16):(this.#e=void 0,e)}generateTraceId(){let e=this.#t;return e===void 0?b(32):(this.#t=void 0,e)}withSpanId(e,t){this.#e=e;try{return t()}finally{this.#e=void 0}}withTraceId(e,t){this.#t=e;try{return t()}finally{this.#t=void 0}}};function y(e){let t=h(`sha256`).update(e).digest(`hex`).slice(0,16);return/^0+$/u.test(t)?`0000000000000001`:t}function b(e){let t;do{t=``;for(let n=0;n<e;n+=1)t+=`0123456789abcdef`[Math.trunc(Math.random()*16)]}while(!/[1-9a-f]/u.test(t));return t}function x(e,t,n,r){let i=!1;try{return e.run(t,()=>(i=!0,n()),r)}catch(t){if(i)throw t;if(e.suppressed!==void 0)try{return e.suppressed(()=>(i=!0,n()))}catch(e){if(i)throw e}return n()}}function S(e){function t(t,n=`complete`,r){try{return t()}catch(t){try{e.onError?.(t,{phase:n,reference:r})}catch{}return}}function r(r,i,a,o){let s=d(r.attributes,i)??r.attributes,c=i.emit?t(()=>e.telemetry.startSpan({...r,attributes:s},{reference:o,context:a}),`start`,o):void 0,l=c?.reference??{traceId:`0`.repeat(32),spanId:`0`.repeat(16),traceFlags:0},u=!1;return{reference:l,get capture(){return i},narrow(e){i=n(i,e)},get finished(){return u},setAttribute(e,n){let r=d({[e]:n},i);!u&&(r===void 0||e in r)&&t(()=>c?.setAttribute(e,r===void 0?n:r[e]))},addEvent(e,n,r){u||t(()=>c?.addEvent(e,n===void 0?void 0:d(n,i)??n,r))},fail(e,n){u||t(()=>c?.fail(i.recordOutputs?e:void 0,n??(e instanceof Error?e.name:void 0)))},setStatus(e){u||t(()=>c?.setStatus(e))},end(e){u||(u=!0,t(()=>c?.end(e)))},run(t){return u?t():x(e.telemetry,{type:r.type,reference:l,capture:i},t,a)}}}return{start:r,startReserved:(e,t,n,i)=>r(e,n,i,t)}}const C=32768,w=65536;function T(e,t){function n(t,n){return r(()=>Reflect.apply(e[t],e,n))}function r(e){try{let t=e();return t===void 0||new TextEncoder().encode(t).length>C?void 0:t}catch(e){try{t?.(e,{phase:`serialize`})}catch{}return}}return{json:e=>n(`json`,[e]),text:e=>n(`text`,[e]),inputMessages:t=>{let n=0,i=r(()=>{let r=e.inputMessages(t);return n=r?.omitted??0,r?.json});return i===void 0?void 0:{json:i,omitted:n}},instructions:e=>n(`instructions`,[e]),toolDefinitions:e=>n(`toolDefinitions`,[e]),outputMessages:(e,t)=>n(`outputMessages`,[e,t]),toolResults:e=>n(`toolResults`,[e])}}function E(e){return new TextEncoder().encode(JSON.stringify({...e,children:void 0})).length}function ee(e){return JSON.parse(JSON.stringify(e))}function D(e,t=w,n=0){try{if(n>16||typeof e!=`object`||!e)return!1;let r=e;if(r.children!==void 0&&(!Array.isArray(r.children)||r.children.length>1e4||!r.children.every(e=>D(e,t,n+1)))||r.version!==1||r.finished!==void 0&&typeof r.finished!=`boolean`||r.childSequence!==void 0&&(!Number.isSafeInteger(r.childSequence)||r.childSequence<0)||typeof r.key!=`string`||typeof r.startTimeMs!=`number`||!Number.isFinite(r.startTimeMs)||r.reference.traceFlags!==0&&r.reference.traceFlags!==1||r.reference.tracestate!==void 0&&(typeof r.reference.tracestate!=`string`||r.reference.tracestate.length>512)||r.parent!==void 0&&(!/^[a-f0-9]{32}$/u.test(r.parent.traceId)||!/^[a-f0-9]{16}$/u.test(r.parent.spanId))||![r.identity.conversationId,r.identity.runId,r.identity.turnId].every(e=>typeof e==`string`))return!1;let i=r.data.options;return!(!{activation:[],step:[],model:[`provider`,`modelId`],tool:[`callId`,`name`],approval:[`requestId`,`callId`,`toolName`],memory:[`operation`,`phase`,`slot`,`storeId`]}[r.data.type].every(e=>typeof i[e]==`string`)||r.data.type===`activation`&&!Number.isSafeInteger(i.sequence)||r.data.type===`step`&&!Number.isSafeInteger(i.index)||r.data.type===`memory`&&i.operation!==`search_memory`&&i.operation!==`upsert_memory`||!/^[a-f0-9]{32}$/u.test(r.reference.traceId)||!/^[a-f0-9]{16}$/u.test(r.reference.spanId)||typeof r.reference.traceFlags!=`number`||![r.capture.emit,r.capture.recordInputs,r.capture.recordOutputs].every(e=>typeof e==`boolean`)||![`activation`,`step`,`model`,`tool`,`approval`,`memory`].includes(r.data.type)||typeof r.data.options!=`object`||r.data.options===null||E(r)>t)}catch{return!1}}function O(e,t){let n=e.terminal;e={...e,children:e.children?.map(n=>O({...n,capture:{emit:n.capture.emit&&e.capture.emit,recordInputs:n.capture.recordInputs&&e.capture.recordInputs,recordOutputs:n.capture.recordOutputs&&e.capture.recordOutputs}},t))},e={...e,terminal:n===void 0||e.finished?void 0:{...n,errorCode:n.errorCode??(n.error instanceof Error?n.error.name:void 0),error:e.capture.recordOutputs?n.error instanceof Error?{name:n.error.name,message:t.text(n.error.message)}:n.error:void 0,output:e.capture.recordOutputs?n.output:void 0,response:e.capture.recordOutputs?n.response:void 0,records:e.capture.recordInputs?n.records:void 0,model:n.model===void 0?void 0:{...n.model,content:e.capture.recordOutputs?n.model.content:void 0}}},e={...e,attributes:d(e.attributes??{},e.capture)??e.attributes};let r=c(e.data,e.capture),i;try{i=t.json(r)}catch{}let a=()=>{let t=c(r,{emit:e.capture.emit,recordInputs:!1,recordOutputs:!1});return t.type===`step`&&(t={...t,options:{...t.options,runtimeContext:void 0}}),t.type===`model`&&(t={...t,options:{...t.options,runtimeContext:void 0}}),JSON.parse(JSON.stringify({...e,version:1,data:t,terminal:e.terminal===void 0?void 0:{outcome:e.terminal.outcome,failed:e.terminal.failed,errorCode:e.terminal.errorCode,usage:e.terminal.usage},attributes:d(e.attributes??{},{recordInputs:!1,recordOutputs:!1})??e.attributes}))};if(i===void 0||new TextEncoder().encode(i).length>C)return a();try{let t=JSON.parse(JSON.stringify({...e,version:1,data:JSON.parse(i)}));return E(t)<=w?t:a()}catch{return a()}}const k=1e4,A={emit:!1,recordInputs:!1,recordOutputs:!1},te=new Set([`activation`,`tool`,`approval`]),ne=new Set([`tool`,`approval`]);function j(e){return encodeURIComponent(String(e))}function re(e){switch(e.type){case`step`:return`step:${j(e.options.index)}:${j(e.options.attempt??0)}`;case`tool`:return`tool:${j(e.options.callId)}`;case`approval`:return`approval:${j(e.options.requestId)}`;default:return}}function ie(e){let t=e.failed||e.outcome===`failed`;return{...e,model:`result`in e?e.result:e.model,failed:t,errorCode:`errorType`in e?e.errorType:e.errorCode}}function M(t){let a=t.telemetry,f=T(t.serializer,t.onError),m=S({telemetry:a,onError:t.onError}),h=(e,n)=>{try{t.onError?.(e,n)}catch{}};function _(e){let t=f.json(e);try{return t===void 0?void 0:JSON.parse(t)}catch{return}}function v(e,n,r,i,o){let s=a.ids;if(t.durable&&s!==void 0&&e.type!==`model`&&e.type!==`memory`){if(e.type===`activation`&&r!==void 0)return{traceId:r.traceId,spanId:s.spanId(n),traceFlags:o.emit?r.traceFlags&1:0};if(e.type===`activation`){let e=s.traceId(n);return{traceId:e,spanId:s.spanId(n),traceFlags:o.emit&&(a.samples?.(e,i)??!0)?1:0}}return r===void 0?void 0:{...r,spanId:s.spanId(n),isRemote:!1}}}async function y(e,t,n,r,i,a,o){try{return await b(e,t,n,r,i,a,o)}catch(t){return h(t,{phase:`start`,operation:n.type,reference:a.reference}),b(e,A,c(n,A),r,i,{...a,sample:!1,reference:{traceId:a.reference?.traceId??r?.reference.traceId??a.parent?.traceId??g(16).toString(`hex`),spanId:a.reference?.spanId??g(8).toString(`hex`),traceFlags:0}},o)}}async function b(g,b,S,C,w,T,E){if(T.terminal?.error!==null&&typeof T.terminal?.error==`object`&&!(T.terminal.error instanceof Error)&&`message`in T.terminal.error&&typeof T.terminal.error.message==`string`){let e=Error(T.terminal.error.message);e.name=T.terminal.errorCode??`Error`,T={...T,terminal:{...T.terminal,error:e}}}let D=T.key,M=T.startTimeMs??Date.now(),N=T.parent??C?.reference;b.emit&&(b=n(b,a.active()?.capture));let P=b,F=c(S,P),I=l({identity:g,data:F,attempt:w,capture:P,key:D,parent:N,startTimeMs:M,links:T.links},f);I={...I,attributes:{...I.attributes,...T.attributes}},F=O({key:D,identity:g,data:F,capture:P,reference:T.reference??{traceId:`0`.repeat(32),spanId:`0`.repeat(16),traceFlags:0},startTimeMs:M},f).data;let L=T.deferred??(t.durable&&te.has(F.type)),R=T.executionContext,z=T.reference??v(S,D,N,I,P);T.sample===!0&&z!==void 0&&(z={...z,traceFlags:z.traceFlags&1&&P.emit&&(N!==void 0||(a.samples?.(z.traceId,I)??!0))?1:0});let B=L?void 0:m.start(I,P,R,z),V=z??B?.reference;if(V===void 0)throw Error(`A deferred trace scope requires a reserved reference.`);let H=!!(V.traceFlags&1);P={emit:P.emit&&H,recordInputs:P.emit&&H&&P.recordInputs,recordOutputs:P.emit&&H&&P.recordOutputs},F=c(F,P);let U=T.finished??!1,W=T.terminal,G=new Map,K=new Set,ae=T.childSequence??0,q=T.usage,J=new Set(T.usageKeys??[]),Y={},oe=F.type===`tool`?F.options.callId:void 0;function X(){E()}function Z(){return n(P,a.active()?.capture)}async function se(e,n,r={}){let i=G.get(n);if(t.durable&&i!==void 0&&!i.settled)return i.refine(e,r.startTimeMs),i;if(U)throw Error(`The operation is not permitted in this trace scope.`);for(let[e,t]of G)t.settled&&G.delete(e);let a=P;G.size>=k&&(h(Error(`Trace unfinished-child limit reached.`),{phase:`start`,operation:e.type,reference:V}),a=A),e.type===`model`&&B!==void 0&&o(B,{"agent.model.id":e.options.modelId});let s=await y(g,a,e,$,e.type===`step`?{index:e.options.index,attempt:e.options.attempt??0}:w,{key:n,executionContext:R,links:r.links,startTimeMs:r.startTimeMs},E);return(a.emit||G.size<k)&&G.set(n,s),await E(),s}async function Q(e,t){let n=F.type===`step`||F.type===`activation`;for(let r of G.values())!t&&n&&ne.has(r.type)||await r.release({failed:e.failed,error:e.error,outcome:`abandoned`})}async function ce(e){if(K.size>0&&await Promise.allSettled(K),U)return;let n=Z();n.recordOutputs||(e={...e,error:void 0}),W?.failed&&(e={...e,outcome:e.outcome===`completed`?`failed`:e.outcome,failed:!0,error:W.error,errorCode:e.errorCode??W.errorCode}),U=!0,W=e,await Q(e,e.failed===!0||!t.durable),B??=m.start(I,P,R,V);let i=F.type===`activation`&&e.usage===void 0?{...e,usage:q}:e;try{r(B,F,i,{...n,emit:P.emit},M,f)}catch(e){h(e,{phase:`complete`,operation:F.type,reference:V})}if(o(B,Y),F.type===`model`&&e.model!==void 0){await C?.usage(e.model.usage,D);let t=e.model.content;if(n.recordOutputs&&P.recordOutputs&&t!==void 0){let n=f.outputMessages(t,e.model.finishReason);n!==void 0&&C?.turnContent({output:n})}}B.end(e.endTimeMs),await E()}let $={waitUntil(e){K.add(e),C?.waitUntil(e),e.then(()=>K.delete(e),()=>K.delete(e))},snapshot:()=>ee($.record()),attributes:e=>$.update({attributes:e}),modelCall:(e,t)=>$.child({type:`model`,options:e},t),fail(e){return $.error(e),$.complete({outcome:`failed`,failed:!0})},update(e){if(U)return;let t=d(e.attributes??{},Z())??e.attributes;F.type===`activation`&&(F={...F,options:{...F.options,attributes:{...F.options.attributes,...t}}}),I={...I,attributes:{...I.attributes,...t},links:e.links??I.links},B!==void 0&&o(B,t),X()},useContext(e){R=e;for(let t of G.values())t.useContext(e)},refine(e,t){if(U||B!==void 0)return;if(t!==void 0&&t<M&&(M=t),e.type===`tool`&&F.type===`tool`){let t=F.options;F=c({type:`tool`,options:{...t,kind:t.kind??e.options.kind,arguments:t.arguments??(Z().recordInputs?_(e.options.arguments):void 0)}},P)}let n=l({identity:g,data:F,attempt:w,capture:P,key:D,parent:N,startTimeMs:M,links:I.links},f),r=Object.fromEntries(Object.entries(n.attributes).filter(([,e])=>e!==void 0));I={...I,name:n.name,kind:n.kind,startTimeMs:M,attributes:{...I.attributes,...r}},X()},narrow(e){P={...n(P,e),emit:P.emit},F=c(F,P);let t=d(I.attributes,P)??I.attributes;I={...I,attributes:F.type===`activation`?{...t,"agent.trace.content.input":P.recordInputs,"agent.trace.content.output":P.recordOutputs}:t};let r=d(Y,P)??Y;for(let e of Object.keys(Y))e in r||delete Y[e];!P.recordOutputs&&W?.error!==void 0&&(W={...W,error:void 0}),B?.narrow(P);for(let e of G.values())e.narrow(P);X()},async release(e){U?await Q(e,e.failed===!0||!t.durable):await ce(ie(e))},record(){return O({version:1,finished:U,terminal:W,usage:q,usageKeys:[...J],attributes:{...I.attributes,...Y},childSequence:ae,children:[...G.values()].filter(e=>!e.settled).map(e=>e.record()),key:D,identity:g,data:F,capture:P,reference:V,parent:N,startTimeMs:M,attempt:w,links:I.links},f)},get parent(){return N},get startTimeMs(){return M},child(e,n,r){if(!s(e).includes(F.type))throw Error(`The operation is not permitted in this trace scope.`);let i=n===void 0?(t.durable?re(e):void 0)??`${e.type}:${ae++}`:`${e.type}:${j(n)}`;return se(e,`${D}/${i}`,r)},find(e){let t=re(e),n=t===void 0?void 0:G.get(`${D}/${t}`);return n===void 0||n.settled?void 0:n},get children(){return[...G.values()].filter(e=>!e.settled)},type:F.type,reference:V,callId:oe,get capture(){return P},mcp:u({serializer:f,...P,write(e){let t=d(e,Z())??e;Object.assign(Y,t),B!==void 0&&o(B,t)},error(e,t){$.error(e,t)}}),get finished(){return U},get settled(){return U&&[...G.values()].every(e=>e.settled)},run(e,t){if(U)throw Error(`The trace scope has already finished.`);let r=n(n(P,t),a.active()?.capture),i=F.type===`tool`&&(F.options.kind===`subagent-call`||F.options.kind===`remote-agent-call`)?F.options:void 0,o=i===void 0?e:()=>p({caller:V,conversationId:g.conversationId,parentRunId:g.runId,parentCallId:i.callId,agentName:i.name,capture:r},e);return x(a,{type:$.type,reference:V,capture:r,mcp:$.mcp},o,R)},async complete(e=W??{}){U||await ce(ie(e))},async usage(e,t){t!==void 0&&J.has(t)||(t!==void 0&&J.add(t),B!==void 0&&o(B,i(e)),q={inputTokens:e.inputTokens===void 0?q?.inputTokens:(q?.inputTokens??0)+e.inputTokens,outputTokens:e.outputTokens===void 0?q?.outputTokens:(q?.outputTokens??0)+e.outputTokens,costUsd:e.costUsd===void 0?q?.costUsd:(q?.costUsd??0)+e.costUsd},await C?.usage(e,t))},turnContent(e){if(F.type!==`activation`)return C?.turnContent(e);if(U)return;let t={};e.input!==void 0&&I.attributes[`gen_ai.input.messages`]===void 0&&(t[`gen_ai.input.messages`]=e.input),e.output!==void 0&&(t[`gen_ai.output.messages`]=e.output),Object.keys(t).length>0&&$.update({attributes:t})},error(t,n){W={...W,failed:!0,error:Z().recordOutputs?t instanceof Error?e(t):_(t):void 0,errorCode:n??(t instanceof Error?t.name:void 0)},B!==void 0&&B.fail(W.error,W.errorCode),X()}};for(let e of T.children??[])G.set(e.key,await y(e.identity,n(e.capture,P),e.data,$,e.attempt,{...e,deferred:!0,executionContext:R},E));!U&&B!==void 0&&F.type===`step`&&B.addEvent(`step.started`,void 0,M);let le=I.attributes[`gen_ai.input.messages`];return!U&&F.type===`model`&&typeof le==`string`&&C?.turnContent({input:le}),$}return{start(e){return y(e.identity,e.capture,e.data,void 0,void 0,{key:e.key,parent:e.parent,reference:e.reference,sample:e.reference!==void 0&&e.data.type===`activation`,startTimeMs:e.startTimeMs,links:e.links,executionContext:e.context},e.onChange??(()=>Promise.resolve()))},async restore(e,t={}){if(!D(e))h(Error(`Invalid tracing checkpoint.`),{phase:`restore`});else return y(e.identity,n(e.capture,t.capture),e.data,void 0,e.attempt,{...e,deferred:!0,executionContext:t.context},t.onChange??(()=>Promise.resolve()))}}}function N(e,t,n){try{e?.(t,{phase:n})}catch{}}function P(e,t={outcome:`completed`},n){async function r(r,i){if(i===void 0)return e(r);let a=await e(r),o=t;try{let e=await a.run(()=>i(a));try{o=r.describe?.(e)??t}catch(e){N(n,e,`complete`)}return e}catch(e){throw o={outcome:`failed`,errorType:e instanceof Error?e.name:`_OTHER`,error:e},e}finally{try{await a.complete(o)}catch(e){N(n,e,`complete`)}}}return r}function F(e,t,n){let r=t=>Object.defineProperties(t,{finished:{get:()=>e.finished},capture:{get:()=>e.capture},parent:{get:()=>e.parent}}),i={type:e.type,reference:e.reference,get startTimeMs(){return e.startTimeMs},get parent(){return e.parent},get finished(){return e.finished},get capture(){return e.capture},run:(t,n)=>e.run(t,n),attributes:t=>e.attributes(t),complete:t=>e.complete(t),fail:t=>e.fail(t),recordError:(t,n)=>e.error(t,n)},a=async(t,r,i)=>F(await e.child(t,r,i),t,n),o=P(async({startTimeMs:e,...t})=>a({type:`tool`,options:t},void 0,{startTimeMs:e}),void 0,n),s=e=>e===void 0?void 0:F(e,e.record().data,n),c=P(async e=>a({type:`memory`,options:e}),void 0,n);if(t.type===`activation`)return r({...i,memory:c,links:t=>e.update({links:t}),findAttempt:t=>s(e.find({type:`step`,options:{index:t.stepIndex,attempt:t.attempt}})),findTool:t=>s(I(e,t)),attempt:P(async e=>a({type:`step`,options:{index:e.stepIndex,attempt:e.attempt,runtimeContext:e.runtimeContext,channel:e.channel}},void 0,{links:e.links}),void 0,n)});if(t.type===`step`){let t=e=>P(async t=>a({type:`tool`,options:{callId:t.callId,name:t.agentName,kind:e}}),void 0,n),s=(e,t)=>a({type:`model`,options:e},t);async function l(e,t){if(typeof t!=`function`)return s(e,t);let r=await s(e),i;try{i=await r.run(t)}catch(e){try{await r.fail(e)}catch(e){N(n,e,`complete`)}throw e}try{await r.complete({outcome:`completed`,result:i})}catch(e){N(n,e,`complete`)}return i.result}return r({...i,memory:c,tool:o,callSubAgent:t(`subagent-call`),callRemoteAgent:t(`remote-agent-call`),modelCall:l,async modelStream(t,r){let i=await s(t);try{let t=await i.run(r),a=Promise.resolve(t.completion).then(e=>i.complete({outcome:`completed`,result:e}),e=>i.fail(e)).catch(e=>N(n,e,`complete`));return e.waitUntil(a),t.result}catch(e){try{await i.fail(e)}catch(e){N(n,e,`complete`)}throw e}}})}return t.type===`tool`?r({...i,memory:c,tool:o,findApproval:n=>s(e.find({type:`approval`,options:{requestId:n,callId:t.options.callId,toolName:t.options.name}})),approval:P(async e=>a({type:`approval`,options:{...e,callId:t.options.callId,toolName:t.options.name}}),{outcome:`ignored`},n)}):i}function I(e,t){for(let n of e.children){if(n.type===`tool`&&n.callId===t)return n;if(n.type===`step`||n.type===`tool`){let e=I(n,t);if(e!==void 0)return e}}}const L={emit:!0,recordInputs:!1,recordOutputs:!1};function R(e){let r=e.telemetry??t(),i=e.checkpointer;if(i!==void 0&&r.ids===void 0)throw Error(`Durable agent tracing needs stable span IDs. Pass the AgentSpanIdGenerator installed on your tracer provider to otelTelemetry({ idGenerator }).`);let a=(t,n)=>{try{e.onError?.(t,n)}catch{}},o=M({telemetry:r,serializer:e.serializer??f,durable:i!==void 0,onError:e.onError}),s=new Map;function c(e){return i===void 0?`turn:${_()}`:[`turn`,e.runId,e.turnId].map(encodeURIComponent).join(`:`)}function l(e,t){let n=Promise.resolve();return()=>{let r=t();return i===void 0||r===void 0||r.retired||(r.writes++,n=n.then(async()=>{try{if(r.root.settled)s.delete(e),await i.delete(e);else{let t=_();await i.set(e,ee({...r.root.record(),revision:t})),r.revision=t,r.revisions.size<1e4&&r.revisions.add(t)}}catch(e){a(e,{phase:`checkpoint`,operation:`activation`})}finally{r.writes--}})),n}}async function u(e){try{return await i.get(e)}catch(e){a(e,{phase:`restore`,operation:`activation`});return}}async function d(e,t,r,a,s){let c=m()?.capture;s=s===void 0?c:n(s,c);let d=i===void 0?void 0:await u(e),f=d?.revision;if(t!==void 0&&(t.writes>0||f===t.revision||f!==void 0&&t.revisions.has(f)))return a!==void 0&&t.root.useContext(a),s!==void 0&&t.root.narrow(s),t;t!==void 0&&(t.retired=!0);let p,h=l(e,()=>p),g=d===void 0?void 0:await o.restore(d,{capture:s,context:a,onChange:h}),_=g??await r?.(h);if(_!==void 0)return p={root:_,revision:f,revisions:new Set(f===void 0?[]:[f]),retired:!1,writes:0},g===void 0&&await h(),p}function p(e,t){let n=s.get(e),r=(async()=>t(n===void 0?void 0:await n.catch(()=>void 0)))();return s.set(e,r),r.then(t=>{(t===void 0||t.root.settled)&&s.delete(e)},()=>s.delete(e)),s.size>1e3&&s.delete(s.keys().next().value),r}function h(e,t){return i=>{let a=m(),s=n(e.capture??L,a?.capture),c=a!==void 0&&e.sequence===0,l=e.parent??(c&&a?.remote!==!0?a?.caller:void 0),u=[...c&&a?.remote===!0?[{relationship:`agent.dispatch`,context:a.caller}]:[],...e.links??[]];return o.start({identity:{...e.identity,conversationId:a?.conversationId??e.identity.conversationId,agentName:e.agentName,framework:e.framework},key:t,capture:s,parent:l,reference:r.ids===void 0?void 0:e.reference,startTimeMs:e.startTimeMs,data:{type:`activation`,options:{sequence:e.sequence,attributes:e.attributes,channel:e.channel,subagent:a!==void 0||e.lineage!==void 0,subagentName:a?.agentName??e.lineage?.agentName,parentRunId:a?.parentRunId??e.lineage?.parentRunId,parentCallId:a?.parentCallId??e.lineage?.parentCallId}},links:u.length===0?void 0:u,context:e.context,onChange:i})}}function g(t){return F(t,{type:`activation`,options:{sequence:0}},e.onError)}async function v(e){let t=c(e.identity);return g((i===void 0?await d(t,void 0,h(e,t),e.context):await p(t,n=>d(t,n,h(e,t),e.context,e.capture))).root)}async function y(e){if(i===void 0)return;let t=c(e.identity),n=await p(t,n=>d(t,n,void 0,e.context));return n===void 0?void 0:g(n.root)}async function b(e){try{await e()}catch(e){a(e,{phase:`complete`})}}async function x(e,t,n){let i=r.active(),s=await o.start({identity:t.identity,key:`memory:${_()}`,capture:t.capture??i?.capture??L,parent:t.parent??i?.reference,context:t.context,data:{type:`memory`,options:{operation:e,phase:t.phase,slot:t.slot,storeId:t.storeId}}}),c;try{c=await s.run(n)}catch(e){throw await s.fail(e).catch(e=>a(e,{phase:`complete`})),e}return await s.complete({outcome:`completed`,...t.describe?.(c)}).catch(e=>a(e,{phase:`complete`})),c}return{turn:P(v,void 0,e.onError),resume:y,memory:{search:(e,t)=>x(`search_memory`,e,t),write:(e,t)=>x(`upsert_memory`,e,t)},forceFlush:()=>b(()=>r.forceFlush()),shutdown:()=>b(()=>r.shutdown())}}export{v as AgentSpanIdGenerator,R as createAgentRun,a as currentCapture,t as otelTelemetry};
|
|
1
|
+
import{_ as e,d as t,h as n,i as r,l as i,n as a,o,p as s,r as c,s as l,t as u,u as d,x as f,y as p}from"../../_chunks/workflow/mcp-CbNv8aLf.js";import{n as m,t as h}from"../../_chunks/workflow/delegation-i2O_jNNn.js";import{createHash as g,randomBytes as _,randomUUID as v}from"node:crypto";var y=class{#e;#t;allocateSpanId(){return x(16)}deriveSpanId(e){return b(e)}deriveTraceId(e){let t=g(`sha256`).update(e).digest(`hex`).slice(0,32);return/^0+$/u.test(t)?`00000000000000000000000000000001`:t}generateSpanId(){let e=this.#e;return e===void 0?x(16):(this.#e=void 0,e)}generateTraceId(){let e=this.#t;return e===void 0?x(32):(this.#t=void 0,e)}withSpanId(e,t){this.#e=e;try{return t()}finally{this.#e=void 0}}withTraceId(e,t){this.#t=e;try{return t()}finally{this.#t=void 0}}};function b(e){let t=g(`sha256`).update(e).digest(`hex`).slice(0,16);return/^0+$/u.test(t)?`0000000000000001`:t}function x(e){let t;do{t=``;for(let n=0;n<e;n+=1)t+=`0123456789abcdef`[Math.trunc(Math.random()*16)]}while(!/[1-9a-f]/u.test(t));return t}function S(e,t,n,r){let i=!1;try{return e.run(t,()=>(i=!0,n()),r)}catch(t){if(i)throw t;if(e.suppressed!==void 0)try{return e.suppressed(()=>(i=!0,n()))}catch(e){if(i)throw e}return n()}}function C(n){function r(e,t=`complete`,r){try{return e()}catch(e){try{n.onError?.(e,{phase:t,reference:r})}catch{}return}}function i(i,a,o,s){let c=t(i.attributes,a)??i.attributes,l=a.emit?r(()=>n.telemetry.startSpan({...i,attributes:c},{reference:s,context:o}),`start`,s):void 0,u=l?.reference??{traceId:`0`.repeat(32),spanId:`0`.repeat(16),traceFlags:0},d=!1;return{reference:u,get capture(){return a},narrow(t){a=e(a,t)},get finished(){return d},setAttribute(e,n){let i=t({[e]:n},a);!d&&(i===void 0||e in i)&&r(()=>l?.setAttribute(e,i===void 0?n:i[e]))},addEvent(e,n,i){d||r(()=>l?.addEvent(e,n===void 0?void 0:t(n,a)??n,i))},fail(e,t){d||r(()=>l?.fail(a.recordOutputs?e:void 0,t??(e instanceof Error?e.name:void 0)))},setStatus(e){d||r(()=>l?.setStatus(e))},end(e){d||(d=!0,r(()=>l?.end(e)))},run(e){return d?e():S(n.telemetry,{type:i.type,reference:u,capture:a},e,o)}}}return{start:i,startReserved:(e,t,n,r)=>i(e,n,r,t)}}const w=262144,T=524288,E=[`gen_ai.input.messages`,`gen_ai.output.messages`],D=new TextEncoder;function O(e){return D.encode(e).length}function k(e){if(!Array.isArray(e))return``;let t=``;for(let n of e){if(typeof n!=`object`||!n)continue;let e=n;e.type===`text`&&typeof e.content==`string`&&(t+=(t.length===0?``:`
|
|
2
|
+
`)+e.content)}return t}function A(e,t){if(t<=0)return;if(O(e)<=t)return e;let n;try{n=JSON.parse(e)}catch{return}if(!Array.isArray(n)||n.length===0)return;let r=n.at(-1);if(typeof r!=`object`||!r)return;let i=r;if(typeof i.role!=`string`)return;let a=k(i.parts),o=typeof i.kind==`string`?{kind:i.kind,role:i.role}:{role:i.role},s=e=>JSON.stringify([{...o,parts:[{content:`${a.slice(0,e)}… [truncated]`,type:`text`}]}]),c,l=1,u=a.length;for(;l<=u;){let e=Math.floor((l+u)/2),n=s(e);O(n)<=t?(c=n,l=e+1):u=e-1}if(c!==void 0)return c;let d=s(0);return O(d)<=t?d:void 0}function j(e,t,n){let r=e;for(let e of E){let i=t[e];if(typeof i!=`string`)continue;let a={...r};delete a[e];let o={...n,attributes:a},s=Math.min(w-O(JSON.stringify(o.data)),T-N(o));for(;s>0;){let t=A(i,s);if(t===void 0)break;let a={...r,[e]:t};if(N({...n,attributes:a})<=T){r=a;break}s=Math.floor(s/2)}}return r}function M(e,t){function n(t,n){return r(()=>Reflect.apply(e[t],e,n))}function r(e){try{let t=e();return t===void 0||new TextEncoder().encode(t).length>w?void 0:t}catch(e){try{t?.(e,{phase:`serialize`})}catch{}return}}return{json:e=>n(`json`,[e]),text:e=>n(`text`,[e]),inputMessages:t=>{let n=0,i=r(()=>{let r=e.inputMessages(t);return n=r?.omitted??0,r?.json});return i===void 0?void 0:{json:i,omitted:n}},instructions:e=>n(`instructions`,[e]),toolDefinitions:e=>n(`toolDefinitions`,[e]),outputMessages:(e,t)=>n(`outputMessages`,[e,t]),toolResults:e=>n(`toolResults`,[e])}}function N(e){return new TextEncoder().encode(JSON.stringify({...e,children:void 0})).length}function ee(e){return JSON.parse(JSON.stringify(e))}function P(e,t=T,n=0){try{if(n>16||typeof e!=`object`||!e)return!1;let r=e;if(r.children!==void 0&&(!Array.isArray(r.children)||r.children.length>1e4||!r.children.every(e=>P(e,t,n+1)))||r.version!==1||r.finished!==void 0&&typeof r.finished!=`boolean`||r.childSequence!==void 0&&(!Number.isSafeInteger(r.childSequence)||r.childSequence<0)||typeof r.key!=`string`||typeof r.startTimeMs!=`number`||!Number.isFinite(r.startTimeMs)||r.reference.traceFlags!==0&&r.reference.traceFlags!==1||r.reference.tracestate!==void 0&&(typeof r.reference.tracestate!=`string`||r.reference.tracestate.length>512)||r.parent!==void 0&&(!/^[a-f0-9]{32}$/u.test(r.parent.traceId)||!/^[a-f0-9]{16}$/u.test(r.parent.spanId))||![r.identity.conversationId,r.identity.runId,r.identity.turnId].every(e=>typeof e==`string`))return!1;let i=r.data.options;return!(!{activation:[],step:[],model:[`provider`,`modelId`],tool:[`callId`,`name`],approval:[`requestId`,`callId`,`toolName`],memory:[`operation`,`phase`,`slot`,`storeId`]}[r.data.type].every(e=>typeof i[e]==`string`)||r.data.type===`activation`&&!Number.isSafeInteger(i.sequence)||r.data.type===`step`&&!Number.isSafeInteger(i.index)||r.data.type===`memory`&&i.operation!==`search_memory`&&i.operation!==`upsert_memory`||!/^[a-f0-9]{32}$/u.test(r.reference.traceId)||!/^[a-f0-9]{16}$/u.test(r.reference.spanId)||typeof r.reference.traceFlags!=`number`||![r.capture.emit,r.capture.recordInputs,r.capture.recordOutputs].every(e=>typeof e==`boolean`)||![`activation`,`step`,`model`,`tool`,`approval`,`memory`].includes(r.data.type)||typeof r.data.options!=`object`||r.data.options===null||N(r)>t)}catch{return!1}}function F(e,n){let r=e.terminal;e={...e,children:e.children?.map(t=>F({...t,capture:{emit:t.capture.emit&&e.capture.emit,recordInputs:t.capture.recordInputs&&e.capture.recordInputs,recordOutputs:t.capture.recordOutputs&&e.capture.recordOutputs}},n))},e={...e,terminal:r===void 0||e.finished?void 0:{...r,errorCode:r.errorCode??(r.error instanceof Error?r.error.name:void 0),error:e.capture.recordOutputs?r.error instanceof Error?{name:r.error.name,message:n.text(r.error.message)}:r.error:void 0,output:e.capture.recordOutputs?r.output:void 0,response:e.capture.recordOutputs?r.response:void 0,records:e.capture.recordInputs?r.records:void 0,model:r.model===void 0?void 0:{...r.model,content:e.capture.recordOutputs?r.model.content:void 0}}},e={...e,attributes:t(e.attributes??{},e.capture)??e.attributes};let i=c(e.data,e.capture),a;try{a=n.json(i)}catch{}let o=()=>{let n={emit:e.capture.emit,recordInputs:!1,recordOutputs:!1},r=c(i,n);r.type===`step`&&(r={...r,options:{...r.options,runtimeContext:void 0}}),r.type===`model`&&(r={...r,options:{...r.options,runtimeContext:void 0}});let a=e.attributes??{},o=j(d(t(a,n)??{},a),a,{...e,version:1,data:r});return JSON.parse(JSON.stringify({...e,version:1,data:r,terminal:e.terminal===void 0?void 0:{outcome:e.terminal.outcome,failed:e.terminal.failed,errorCode:e.terminal.errorCode,usage:e.terminal.usage},attributes:o}))};if(a===void 0||new TextEncoder().encode(a).length>w)return o();try{let t=JSON.parse(JSON.stringify({...e,version:1,data:JSON.parse(a)}));return N(t)<=T?t:o()}catch{return o()}}const te=1e4,I={emit:!1,recordInputs:!1,recordOutputs:!1},ne=new Set([`activation`,`tool`,`approval`]),re=new Set([`tool`,`approval`]);function L(e){return encodeURIComponent(String(e))}function R(e){switch(e.type){case`step`:return`step:${L(e.options.index)}:${L(e.options.attempt??0)}`;case`tool`:return`tool:${L(e.options.callId)}`;case`approval`:return`approval:${L(e.options.requestId)}`;default:return}}function z(e){let t=e.failed||e.outcome===`failed`;return{...e,model:`result`in e?e.result:e.model,failed:t,errorCode:`errorType`in e?e.errorType:e.errorCode}}function B(n){let s=n.telemetry,d=M(n.serializer,n.onError),p=C({telemetry:s,onError:n.onError}),h=(e,t)=>{try{n.onError?.(e,t)}catch{}};function g(e){let t=d.json(e);try{return t===void 0?void 0:JSON.parse(t)}catch{return}}function v(e,t,r,i,a){let o=s.ids;if(n.durable&&o!==void 0&&e.type!==`model`&&e.type!==`memory`){if(e.type===`activation`&&r!==void 0)return{traceId:r.traceId,spanId:o.spanId(t),traceFlags:a.emit?r.traceFlags&1:0};if(e.type===`activation`){let e=o.traceId(t);return{traceId:e,spanId:o.spanId(t),traceFlags:a.emit&&(s.samples?.(e,i)??!0)?1:0}}return r===void 0?void 0:{...r,spanId:o.spanId(t),isRemote:!1}}}async function y(e,t,n,r,i,a,o){try{return await b(e,t,n,r,i,a,o)}catch(t){return h(t,{phase:`start`,operation:n.type,reference:a.reference}),b(e,I,c(n,I),r,i,{...a,sample:!1,reference:{traceId:a.reference?.traceId??r?.reference.traceId??a.parent?.traceId??_(16).toString(`hex`),spanId:a.reference?.spanId??_(8).toString(`hex`),traceFlags:0}},o)}}async function b(_,b,x,C,w,T,E){if(T.terminal?.error!==null&&typeof T.terminal?.error==`object`&&!(T.terminal.error instanceof Error)&&`message`in T.terminal.error&&typeof T.terminal.error.message==`string`){let e=Error(T.terminal.error.message);e.name=T.terminal.errorCode??`Error`,T={...T,terminal:{...T.terminal,error:e}}}let D=T.key,O=T.startTimeMs??Date.now(),k=T.parent??C?.reference;b.emit&&(b=e(b,s.active()?.capture));let A=b,j=c(x,A),M=l({identity:_,data:j,attempt:w,capture:A,key:D,parent:k,startTimeMs:O,links:T.links},d);M={...M,attributes:{...M.attributes,...T.attributes}},j=F({key:D,identity:_,data:j,capture:A,reference:T.reference??{traceId:`0`.repeat(32),spanId:`0`.repeat(16),traceFlags:0},startTimeMs:O},d).data;let N=T.deferred??(n.durable&&ne.has(j.type)),P=T.executionContext,B=T.reference??v(x,D,k,M,A);T.sample===!0&&B!==void 0&&(B={...B,traceFlags:B.traceFlags&1&&A.emit&&(k!==void 0||(s.samples?.(B.traceId,M)??!0))?1:0});let V=N?void 0:p.start(M,A,P,B),H=B??V?.reference;if(H===void 0)throw Error(`A deferred trace scope requires a reserved reference.`);let U=!!(H.traceFlags&1);A={emit:A.emit&&U,recordInputs:A.emit&&U&&A.recordInputs,recordOutputs:A.emit&&U&&A.recordOutputs},j=c(j,A);let W=T.finished??!1,G=T.terminal,K=new Map,q=new Set,ie=T.childSequence??0,J=T.usage,Y=new Set(T.usageKeys??[]),X={},ae=j.type===`tool`?j.options.callId:void 0;function Z(){E()}function Q(){return e(A,s.active()?.capture)}async function oe(e,t,r={}){let i=K.get(t);if(n.durable&&i!==void 0&&!i.settled)return i.refine(e,r.startTimeMs),i;if(W)throw Error(`The operation is not permitted in this trace scope.`);for(let[e,t]of K)t.settled&&K.delete(e);let o=A;K.size>=te&&(h(Error(`Trace unfinished-child limit reached.`),{phase:`start`,operation:e.type,reference:H}),o=I),e.type===`model`&&V!==void 0&&a(V,{"agent.model.id":e.options.modelId});let s=await y(_,o,e,$,e.type===`step`?{index:e.options.index,attempt:e.options.attempt??0}:w,{key:t,executionContext:P,links:r.links,startTimeMs:r.startTimeMs},E);return(o.emit||K.size<te)&&K.set(t,s),await E(),s}async function se(e,t){let n=j.type===`step`||j.type===`activation`;for(let r of K.values())!t&&n&&re.has(r.type)||await r.release({failed:e.failed,error:e.error,outcome:`abandoned`})}async function ce(e){if(q.size>0&&await Promise.allSettled(q),W)return;let t=Q();t.recordOutputs||(e={...e,error:void 0}),G?.failed&&(e={...e,outcome:e.outcome===`completed`?`failed`:e.outcome,failed:!0,error:G.error,errorCode:e.errorCode??G.errorCode}),W=!0,G=e,await se(e,e.failed===!0||!n.durable),V??=p.start(M,A,P,H);let i=j.type===`activation`&&e.usage===void 0?{...e,usage:J}:e;try{r(V,j,i,{...t,emit:A.emit},O,d)}catch(e){h(e,{phase:`complete`,operation:j.type,reference:H})}if(a(V,X),j.type===`model`&&e.model!==void 0){await C?.usage(e.model.usage,D);let n=e.model.content;if(t.recordOutputs&&A.recordOutputs&&n!==void 0){let t=d.outputMessages(n,e.model.finishReason);t!==void 0&&C?.turnContent({output:t})}}V.end(e.endTimeMs),await E()}let $={waitUntil(e){q.add(e),C?.waitUntil(e),e.then(()=>q.delete(e),()=>q.delete(e))},snapshot:()=>ee($.record()),attributes:e=>$.update({attributes:e}),modelCall:(e,t)=>$.child({type:`model`,options:e},t),fail(e){return $.error(e),$.complete({outcome:`failed`,failed:!0})},update(e){if(W)return;let n=t(e.attributes??{},Q())??e.attributes;j.type===`activation`&&(j={...j,options:{...j.options,attributes:{...j.options.attributes,...n}}}),M={...M,attributes:{...M.attributes,...n},links:e.links??M.links},V!==void 0&&a(V,n),Z()},useContext(e){P=e;for(let t of K.values())t.useContext(e)},refine(e,t){if(W||V!==void 0)return;if(t!==void 0&&t<O&&(O=t),e.type===`tool`&&j.type===`tool`){let t=j.options;j=c({type:`tool`,options:{...t,kind:t.kind??e.options.kind,arguments:t.arguments??(Q().recordInputs?g(e.options.arguments):void 0)}},A)}let n=l({identity:_,data:j,attempt:w,capture:A,key:D,parent:k,startTimeMs:O,links:M.links},d),r=Object.fromEntries(Object.entries(n.attributes).filter(([,e])=>e!==void 0));M={...M,name:n.name,kind:n.kind,startTimeMs:O,attributes:{...M.attributes,...r}},Z()},narrow(n){A={...e(A,n),emit:A.emit},j=c(j,A);let r=t(M.attributes,A)??M.attributes;M={...M,attributes:j.type===`activation`?{...r,"agent.trace.content.input":A.recordInputs,"agent.trace.content.output":A.recordOutputs}:r};let i=t(X,A)??X;for(let e of Object.keys(X))e in i||delete X[e];!A.recordOutputs&&G?.error!==void 0&&(G={...G,error:void 0}),V?.narrow(A);for(let e of K.values())e.narrow(A);Z()},async release(e){W?await se(e,e.failed===!0||!n.durable):await ce(z(e))},record(){return F({version:1,finished:W,terminal:G,usage:J,usageKeys:[...Y],attributes:{...M.attributes,...X},childSequence:ie,children:[...K.values()].filter(e=>!e.settled).map(e=>e.record()),key:D,identity:_,data:j,capture:A,reference:H,parent:k,startTimeMs:O,attempt:w,links:M.links},d)},get parent(){return k},get startTimeMs(){return O},child(e,t,r){if(!o(e).includes(j.type))throw Error(`The operation is not permitted in this trace scope.`);let i=t===void 0?(n.durable?R(e):void 0)??`${e.type}:${ie++}`:`${e.type}:${L(t)}`;return oe(e,`${D}/${i}`,r)},find(e){let t=R(e),n=t===void 0?void 0:K.get(`${D}/${t}`);return n===void 0||n.settled?void 0:n},get children(){return[...K.values()].filter(e=>!e.settled)},type:j.type,reference:H,callId:ae,get capture(){return A},mcp:u({serializer:d,...A,write(e){let n=t(e,Q())??e;Object.assign(X,n),V!==void 0&&a(V,n)},error(e,t){$.error(e,t)}}),get finished(){return W},get settled(){return W&&[...K.values()].every(e=>e.settled)},run(t,n){if(W)throw Error(`The trace scope has already finished.`);let r=e(e(A,n),s.active()?.capture),i=j.type===`tool`&&(j.options.kind===`subagent-call`||j.options.kind===`remote-agent-call`)?j.options:void 0,a=i===void 0?t:()=>m({caller:H,conversationId:_.conversationId,parentRunId:_.runId,parentCallId:i.callId,agentName:i.name,capture:r},t);return S(s,{type:$.type,reference:H,capture:r,mcp:$.mcp},a,P)},async complete(e=G??{}){W||await ce(z(e))},async usage(e,t){t!==void 0&&Y.has(t)||(t!==void 0&&Y.add(t),V!==void 0&&a(V,i(e)),J={inputTokens:e.inputTokens===void 0?J?.inputTokens:(J?.inputTokens??0)+e.inputTokens,outputTokens:e.outputTokens===void 0?J?.outputTokens:(J?.outputTokens??0)+e.outputTokens,costUsd:e.costUsd===void 0?J?.costUsd:(J?.costUsd??0)+e.costUsd},await C?.usage(e,t))},turnContent(e){if(j.type!==`activation`)return C?.turnContent(e);if(W)return;let t={};e.input!==void 0&&M.attributes[`gen_ai.input.messages`]===void 0&&(t[`gen_ai.input.messages`]=e.input),e.output!==void 0&&(t[`gen_ai.output.messages`]=e.output),Object.keys(t).length>0&&$.update({attributes:t})},error(e,t){G={...G,failed:!0,error:Q().recordOutputs?e instanceof Error?f(e):g(e):void 0,errorCode:t??(e instanceof Error?e.name:void 0)},V!==void 0&&V.fail(G.error,G.errorCode),Z()}};for(let t of T.children??[])K.set(t.key,await y(t.identity,e(t.capture,A),t.data,$,t.attempt,{...t,deferred:!0,executionContext:P},E));!W&&V!==void 0&&j.type===`step`&&V.addEvent(`step.started`,void 0,O);let le=M.attributes[`gen_ai.input.messages`];return!W&&j.type===`model`&&typeof le==`string`&&C?.turnContent({input:le}),$}return{start(e){return y(e.identity,e.capture,e.data,void 0,void 0,{key:e.key,parent:e.parent,reference:e.reference,sample:e.reference!==void 0&&e.data.type===`activation`,startTimeMs:e.startTimeMs,links:e.links,executionContext:e.context},e.onChange??(()=>Promise.resolve()))},async restore(t,n={}){if(!P(t))h(Error(`Invalid tracing checkpoint.`),{phase:`restore`});else return y(t.identity,e(t.capture,n.capture),t.data,void 0,t.attempt,{...t,deferred:!0,executionContext:n.context},n.onChange??(()=>Promise.resolve()))}}}function V(e,t,n){try{e?.(t,{phase:n})}catch{}}function H(e,t={outcome:`completed`},n){async function r(r,i){if(i===void 0)return e(r);let a=await e(r),o=t;try{let e=await a.run(()=>i(a));try{o=r.describe?.(e)??t}catch(e){V(n,e,`complete`)}return e}catch(e){throw o={outcome:`failed`,errorType:e instanceof Error?e.name:`_OTHER`,error:e},e}finally{try{await a.complete(o)}catch(e){V(n,e,`complete`)}}}return r}function U(e,t,n){let r=t=>Object.defineProperties(t,{finished:{get:()=>e.finished},capture:{get:()=>e.capture},parent:{get:()=>e.parent}}),i={type:e.type,reference:e.reference,get startTimeMs(){return e.startTimeMs},get parent(){return e.parent},get finished(){return e.finished},get capture(){return e.capture},run:(t,n)=>e.run(t,n),attributes:t=>e.attributes(t),complete:t=>e.complete(t),fail:t=>e.fail(t),recordError:(t,n)=>e.error(t,n)},a=async(t,r,i)=>U(await e.child(t,r,i),t,n),o=H(async({startTimeMs:e,...t})=>a({type:`tool`,options:t},void 0,{startTimeMs:e}),void 0,n),s=e=>e===void 0?void 0:U(e,e.record().data,n),c=H(async e=>a({type:`memory`,options:e}),void 0,n);if(t.type===`activation`)return r({...i,memory:c,links:t=>e.update({links:t}),findAttempt:t=>s(e.find({type:`step`,options:{index:t.stepIndex,attempt:t.attempt}})),findTool:t=>s(W(e,t)),attempt:H(async e=>a({type:`step`,options:{index:e.stepIndex,attempt:e.attempt,runtimeContext:e.runtimeContext,channel:e.channel}},void 0,{links:e.links}),void 0,n)});if(t.type===`step`){let t=e=>H(async t=>a({type:`tool`,options:{callId:t.callId,name:t.agentName,kind:e}}),void 0,n),s=(e,t)=>a({type:`model`,options:e},t);async function l(e,t){if(typeof t!=`function`)return s(e,t);let r=await s(e),i;try{i=await r.run(t)}catch(e){try{await r.fail(e)}catch(e){V(n,e,`complete`)}throw e}try{await r.complete({outcome:`completed`,result:i})}catch(e){V(n,e,`complete`)}return i.result}return r({...i,memory:c,tool:o,callSubAgent:t(`subagent-call`),callRemoteAgent:t(`remote-agent-call`),modelCall:l,async modelStream(t,r){let i=await s(t);try{let t=await i.run(r),a=Promise.resolve(t.completion).then(e=>i.complete({outcome:`completed`,result:e}),e=>i.fail(e)).catch(e=>V(n,e,`complete`));return e.waitUntil(a),t.result}catch(e){try{await i.fail(e)}catch(e){V(n,e,`complete`)}throw e}}})}return t.type===`tool`?r({...i,memory:c,tool:o,findApproval:n=>s(e.find({type:`approval`,options:{requestId:n,callId:t.options.callId,toolName:t.options.name}})),approval:H(async e=>a({type:`approval`,options:{...e,callId:t.options.callId,toolName:t.options.name}}),{outcome:`ignored`},n)}):i}function W(e,t){for(let n of e.children){if(n.type===`tool`&&n.callId===t)return n;if(n.type===`step`||n.type===`tool`){let e=W(n,t);if(e!==void 0)return e}}}const G={emit:!0,recordInputs:!1,recordOutputs:!1};function K(t){let n=t.telemetry??s(),r=t.checkpointer;if(r!==void 0&&n.ids===void 0)throw Error(`Durable agent tracing needs stable span IDs. Pass the AgentSpanIdGenerator installed on your tracer provider to otelTelemetry({ idGenerator }).`);let i=(e,n)=>{try{t.onError?.(e,n)}catch{}},a=B({telemetry:n,serializer:t.serializer??p,durable:r!==void 0,onError:t.onError}),o=new Map;function c(e){return r===void 0?`turn:${v()}`:[`turn`,e.runId,e.turnId].map(encodeURIComponent).join(`:`)}function l(e,t){let n=Promise.resolve();return()=>{let a=t();return r===void 0||a===void 0||a.retired||(a.writes++,n=n.then(async()=>{try{if(a.root.settled)o.delete(e),await r.delete(e);else{let t=v();await r.set(e,ee({...a.root.record(),revision:t})),a.revision=t,a.revisions.size<1e4&&a.revisions.add(t)}}catch(e){i(e,{phase:`checkpoint`,operation:`activation`})}finally{a.writes--}})),n}}async function u(e){try{return await r.get(e)}catch(e){i(e,{phase:`restore`,operation:`activation`});return}}async function d(t,n,i,o,s){let c=h()?.capture;s=s===void 0?c:e(s,c);let d=r===void 0?void 0:await u(t),f=d?.revision;if(n!==void 0&&(n.writes>0||f===n.revision||f!==void 0&&n.revisions.has(f)))return o!==void 0&&n.root.useContext(o),s!==void 0&&n.root.narrow(s),n;n!==void 0&&(n.retired=!0);let p,m=l(t,()=>p),g=d===void 0?void 0:await a.restore(d,{capture:s,context:o,onChange:m}),_=g??await i?.(m);if(_!==void 0)return p={root:_,revision:f,revisions:new Set(f===void 0?[]:[f]),retired:!1,writes:0},g===void 0&&await m(),p}function f(e,t){let n=o.get(e),r=(async()=>t(n===void 0?void 0:await n.catch(()=>void 0)))();return o.set(e,r),r.then(t=>{(t===void 0||t.root.settled)&&o.delete(e)},()=>o.delete(e)),o.size>1e3&&o.delete(o.keys().next().value),r}function m(t,r){return i=>{let o=h(),s=e(t.capture??G,o?.capture),c=o!==void 0&&t.sequence===0,l=t.parent??(c&&o?.remote!==!0?o?.caller:void 0),u=[...c&&o?.remote===!0?[{relationship:`agent.dispatch`,context:o.caller}]:[],...t.links??[]];return a.start({identity:{...t.identity,conversationId:o?.conversationId??t.identity.conversationId,agentName:t.agentName,framework:t.framework},key:r,capture:s,parent:l,reference:n.ids===void 0?void 0:t.reference,startTimeMs:t.startTimeMs,data:{type:`activation`,options:{sequence:t.sequence,attributes:t.attributes,channel:t.channel,subagent:o!==void 0||t.lineage!==void 0,subagentName:o?.agentName??t.lineage?.agentName,parentRunId:o?.parentRunId??t.lineage?.parentRunId,parentCallId:o?.parentCallId??t.lineage?.parentCallId}},links:u.length===0?void 0:u,context:t.context,onChange:i})}}function g(e){return U(e,{type:`activation`,options:{sequence:0}},t.onError)}async function _(e){let t=c(e.identity);return g((r===void 0?await d(t,void 0,m(e,t),e.context):await f(t,n=>d(t,n,m(e,t),e.context,e.capture))).root)}async function y(e){if(r===void 0)return;let t=c(e.identity),n=await f(t,n=>d(t,n,void 0,e.context));return n===void 0?void 0:g(n.root)}async function b(e){try{await e()}catch(e){i(e,{phase:`complete`})}}async function x(e,t,r){let o=n.active(),s=await a.start({identity:t.identity,key:`memory:${v()}`,capture:t.capture??o?.capture??G,parent:t.parent??o?.reference,context:t.context,data:{type:`memory`,options:{operation:e,phase:t.phase,slot:t.slot,storeId:t.storeId}}}),c;try{c=await s.run(r)}catch(e){throw await s.fail(e).catch(e=>i(e,{phase:`complete`})),e}return await s.complete({outcome:`completed`,...t.describe?.(c)}).catch(e=>i(e,{phase:`complete`})),c}return{turn:H(_,void 0,t.onError),resume:y,memory:{search:(e,t)=>x(`search_memory`,e,t),write:(e,t)=>x(`upsert_memory`,e,t)},forceFlush:()=>b(()=>n.forceFlush()),shutdown:()=>b(()=>n.shutdown())}}export{y as AgentSpanIdGenerator,K as createAgentRun,n as currentCapture,s as otelTelemetry};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{v as CONTENT_ATTRIBUTE_LIMIT,c as USAGE_FIELDS,f as activeTraceOperation,b as boundedPrincipalId,S as contentAttribute,a as invocationName,t as mcpLifecycle,C as telemetryByteLength,w as truncateTelemetryText,g as withCapture,m as withErrorContent,d as withoutDeclinedContent}from"../../_chunks/workflow/mcp-CbNv8aLf.js";
|
|
@@ -99,6 +99,21 @@ export interface Webhook<T extends Request> extends Hook<T> {
|
|
|
99
99
|
*/
|
|
100
100
|
url: string;
|
|
101
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Options accepted by the orchestrator's `createHook` for hooks the SDK
|
|
104
|
+
* itself creates (the `AbortController` signal hook, the child-run completion
|
|
105
|
+
* hook). Deliberately not part of the public {@link HookOptions}.
|
|
106
|
+
*
|
|
107
|
+
* A system hook is an ordinary hook (same tokens, conflicts, resumes and
|
|
108
|
+
* disposal) that is recorded with `isSystem: true`, so observability can
|
|
109
|
+
* label it and the runtime can treat it as written by another run: its
|
|
110
|
+
* resumes come from outside this run's replay.
|
|
111
|
+
*
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
114
|
+
export interface SystemHookOptions extends HookOptions {
|
|
115
|
+
isSystem?: boolean;
|
|
116
|
+
}
|
|
102
117
|
export interface HookOptions {
|
|
103
118
|
/**
|
|
104
119
|
* Unique token that is used to associate with the hook.
|
|
@@ -92,7 +92,7 @@ export interface EventsConsumerOptions {
|
|
|
92
92
|
isDeliveryIdle: () => boolean;
|
|
93
93
|
/**
|
|
94
94
|
* The run's start Hook id (`startHookId(runId)`), for a run started with
|
|
95
|
-
* `start(workflow, args, {
|
|
95
|
+
* `start(workflow, args, { experimental_hook })`. That Hook exists from the run's
|
|
96
96
|
* admission, so payloads can be resumed into it before the body calls
|
|
97
97
|
* `createHook` (even before `run_started`), and another run can force-claim
|
|
98
98
|
* it before then too.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e,
|
|
2
|
-
`)}`)}return await
|
|
1
|
+
import{a as e,i as t,r as n,t as r}from"../../_chunks/workflow/attribute-changes-CZ1IbpSN.js";import{l as i,n as a}from"../../_chunks/workflow/resume-hook-ZanR4XtL.js";import{Di as o,Ei as s,Jr as c,Oi as l,Si as u,T as d,Ti as f,X as p,Z as m,bi as h,gi as g,i as _,pi as v,x as y,xi as b,yi as x}from"../../_chunks/workflow/serialization-BsJ0NayH.js";import{t as S}from"../../_chunks/workflow/sleep-C8DQfwTV.js";import{FatalError as C,FatalError as w,RetryableError as T}from"#compiled/@workflow/errors/index.js";function E(e){t(`createHook()`,`https://workflow-sdk.dev/docs/api-reference/workflow/create-hook`,E)}function D(e){t(`createWebhook()`,`https://workflow-sdk.dev/docs/api-reference/workflow/create-webhook`,D)}function O({schema:e}={}){function n(e){t(`defineHook().create()`,`https://workflow-sdk.dev/docs/api-reference/workflow/define-hook`,n)}return{create:n,async resume(t,n){if(!e?.[`~standard`])return await a(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 a(t,r.value)}}}async function k(e,t={}){let n=m.getStore(),a=n?.workflowMetadata?.workflowRunId;if(!a)throw new w(`setAttributes() must be called from a 'use workflow' or 'use step' function. Calling it from plain host code is not supported.`);let o={type:`step`,stepId:n.stepMetadata.stepId,attempt:n.stepMetadata.attempt},s=r(e,t,o);s.length!==0&&(n.runReadyBarrier&&await n.runReadyBarrier,await(await g()).events.create(a,{eventType:`attr_set`,specVersion:i(n.runSpecVersion),eventData:{changes:s,writer:o,...t.allowReservedAttributes===!0?{allowReservedAttributes:!0}:{}}},{inBand:!1}))}function A(){let e=m.getStore();return e||n(`getStepMetadata()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-step-metadata`,A),e.stepMetadata}function j(){let t=m.getStore();return t||e(`getWorkflowMetadata()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-workflow-metadata`,j),t.workflowMetadata}function M(t={}){let n=m.getStore();n||e(`getWritable()`,`https://workflow-sdk.dev/docs/api-reference/workflow/get-writable`,M);let{namespace:r}=t,i=n.workflowMetadata.workflowRunId,a=p(i,r);n.writables??=new Map;let g=n.writables,S=g.get(a);if(S)return S.writable;let C=x();C.deferReleaseSettlement=n.streamStates!==void 0;let w=d(y(globalThis,n.ops,i,n.encryptionKey,!0,n.runReadyBarrier),n.encryptionKey),T=new _(i,a,n.runReadyBarrier);n.streamStates??=[],n.streamStates.push(C),n.ops.push(C.promise),h(w.readable,T,C).catch(()=>{});let E=u(w.writable,C);return b(E,C),Object.defineProperty(E,f,{value:a,writable:!1}),Object.defineProperty(E,l,{value:i,writable:!1}),n.workflowDeploymentId&&Object.defineProperty(E,s,{value:n.workflowDeploymentId,writable:!1}),c(n.encryptionKey)&&Object.defineProperty(E,o,{value:v(n.encryptionKey.keyPair.publicKey),writable:!1}),g.set(a,{writable:E,state:C}),E}export{C as FatalError,T as RetryableError,E as createHook,D as createWebhook,O as defineHook,A as getStepMetadata,j as getWorkflowMetadata,M as getWritable,k as setAttributes,S as sleep};
|
|
@@ -30,7 +30,7 @@ export interface WorkflowOrchestratorContext {
|
|
|
30
30
|
encryptionKey: PayloadKey | undefined;
|
|
31
31
|
worldCapabilities?: WorldCapabilities;
|
|
32
32
|
/**
|
|
33
|
-
* The run's start Hook (`start(workflow, args, {
|
|
33
|
+
* The run's start Hook (`start(workflow, args, { experimental_hook })`), fixed when the
|
|
34
34
|
* session is created; `undefined` for a run started without one. The first
|
|
35
35
|
* `createHook({ token })` with this token binds to `hookId` (setting
|
|
36
36
|
* `bound`) instead of minting an id and writing `hook_created`: the
|
|
@@ -39,7 +39,7 @@ export interface WorkflowOrchestratorContext {
|
|
|
39
39
|
startHook?: {
|
|
40
40
|
token: string;
|
|
41
41
|
hookId: string;
|
|
42
|
-
/** `start({
|
|
42
|
+
/** `start({ experimental_hook })`'s retention deadline, when one was set. */
|
|
43
43
|
tokenRetentionUntil?: Date;
|
|
44
44
|
bound: boolean;
|
|
45
45
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{t as awaitEarlierDeliveries,n as getStepFunction,r as hasParkedCommittedDelivery,i as isDeliveryIdle,a as registerDeliveryBarrier,o as registerStepFunction,s as scheduleWhenIdle,c as scheduleWorkflowSuspension}from"../../_chunks/workflow/private-
|
|
1
|
+
export{t as awaitEarlierDeliveries,n as getStepFunction,r as hasParkedCommittedDelivery,i as isDeliveryIdle,a as registerDeliveryBarrier,o as registerStepFunction,s as scheduleWhenIdle,c as scheduleWorkflowSuspension}from"../../_chunks/workflow/private-D07opN0n.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { WorkflowRunWithoutData, World } from '#compiled/@workflow/world/index.js';
|
|
2
|
+
import type { PayloadKey } from '../serialization/encryption.js';
|
|
3
|
+
/**
|
|
4
|
+
* What every writer of a run's terminal event owes once the World recorded
|
|
5
|
+
* it: the run's lifecycle hooks, and the completion hook of the parent that
|
|
6
|
+
* started it, which may be suspended waiting on this run.
|
|
7
|
+
*
|
|
8
|
+
* Terminal events are written from many places (each engine's completion and
|
|
9
|
+
* failure paths, fatal setup errors, max deliveries, replay timeout,
|
|
10
|
+
* deployment mismatch, cancellation), so these are the only entry points: a
|
|
11
|
+
* new terminal path that calls one of them cannot dispatch the lifecycle
|
|
12
|
+
* hooks and forget the parent. `after-terminal-write.test.ts` fails on a
|
|
13
|
+
* direct `dispatchRun*Hooks` call anywhere else.
|
|
14
|
+
*
|
|
15
|
+
* Call them only after the write succeeded: a parent that finds no
|
|
16
|
+
* notification reads the child after registering its hook, and that read
|
|
17
|
+
* must see the terminal event. None of them throws.
|
|
18
|
+
*/
|
|
19
|
+
/** The run as the caller has it (preferred, no read), or just its id. */
|
|
20
|
+
type TerminalRun = Pick<WorkflowRunWithoutData, 'runId' | 'executionContext'> | string;
|
|
21
|
+
/** After a `run_completed` write. */
|
|
22
|
+
export declare function afterRunCompleted(world: World, run: TerminalRun, workflowName: string): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* After a `run_failed` write.
|
|
25
|
+
*
|
|
26
|
+
* @param error - The serialized error payload stored by the terminal write.
|
|
27
|
+
* @param errorCode - The classification written to the event's `errorCode`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function afterRunFailed(world: World, run: TerminalRun, workflowName: string, error: unknown, encryptionKey: PayloadKey | undefined, errorCode: string): Promise<void>;
|
|
30
|
+
/** After a `run_cancelled` write. Cancellation has no lifecycle hooks. */
|
|
31
|
+
export declare function afterRunCancelled(world: World, run: TerminalRun): Promise<void>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=after-terminal-write.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { WorkflowRunWithoutData, World } from '#compiled/@workflow/world/index.js';
|
|
2
|
+
import { type ChildRunCompletionPayload } from './child-run-completion.js';
|
|
3
|
+
/**
|
|
4
|
+
* Whether runs started from a workflow are stamped so their parent can await
|
|
5
|
+
* them through the child-run completion hook. On by default; an explicit
|
|
6
|
+
* `WORKFLOW_CHILD_RUN_COMPLETION_HOOK=0` (or `false`) stops new runs from
|
|
7
|
+
* being stamped, so their parents fall back to polling `returnValue` inside
|
|
8
|
+
* a step. Runs already stamped keep notifying their parents either way.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function isChildRunCompletionHookEnabled(): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The parent whose completion hook a run resumes when it finishes, or
|
|
15
|
+
* `undefined` for a run that was not started from a workflow.
|
|
16
|
+
*/
|
|
17
|
+
export declare function completionParentRunId(executionContext: Record<string, unknown> | undefined): string | undefined;
|
|
18
|
+
type NotifiableRun = Pick<WorkflowRunWithoutData, 'runId' | 'executionContext'>;
|
|
19
|
+
/**
|
|
20
|
+
* Resumes the completion hook of the parent that started `run`, if any, with
|
|
21
|
+
* `{ runId, status }`; all of a parent's children share that one hook. Call
|
|
22
|
+
* it after the run's terminal event is written: the parent reads the run
|
|
23
|
+
* after registering its hook, so a resume that finds no hook is only safe
|
|
24
|
+
* once that read would see the run as finished.
|
|
25
|
+
*
|
|
26
|
+
* Accepts the run itself when the caller already has it loaded, or its id
|
|
27
|
+
* (read here, metadata only) on paths that do not.
|
|
28
|
+
*
|
|
29
|
+
* Never throws. A hook that does not exist is the common case (the parent
|
|
30
|
+
* has not awaited the child yet, never will, or already finished) and is not
|
|
31
|
+
* an error. Transient World failures are retried with backoff; anything that
|
|
32
|
+
* still fails is logged.
|
|
33
|
+
*/
|
|
34
|
+
export declare function notifyParentOfRunCompletion(world: World, run: NotifiableRun | string, status: ChildRunCompletionPayload['status']): Promise<void>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=child-run-completion-notify.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefix of a parent's child-run completion token. The token is the parent's
|
|
3
|
+
* run id behind this prefix, which is globally unique, so a child computes it
|
|
4
|
+
* from the parent id it was stamped with.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CHILD_RUN_COMPLETION_TOKEN_PREFIX = "wkf_child_run_completion:";
|
|
7
|
+
/**
|
|
8
|
+
* The `executionContext` key `start()` stamps on a child with the run id of
|
|
9
|
+
* the parent that may await it through the completion hook.
|
|
10
|
+
*/
|
|
11
|
+
export declare const CHILD_RUN_COMPLETION_CONTEXT_KEY = "completionParentRunId";
|
|
12
|
+
/**
|
|
13
|
+
* Version of the completion-hook protocol a deployment implements: whether
|
|
14
|
+
* it resumes {@link childRunCompletionToken} for runs stamped with
|
|
15
|
+
* {@link CHILD_RUN_COMPLETION_CONTEXT_KEY}. Advertised on the health check so
|
|
16
|
+
* a cross-deployment `start()` only stamps a run whose executing deployment
|
|
17
|
+
* honors it.
|
|
18
|
+
*/
|
|
19
|
+
export declare const CHILD_RUN_COMPLETION_VERSION = 1;
|
|
20
|
+
/** The payload a finished child resumes its parent's completion hook with. */
|
|
21
|
+
export interface ChildRunCompletionPayload {
|
|
22
|
+
runId: string;
|
|
23
|
+
status: 'completed' | 'failed' | 'cancelled';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Delay of the n-th safety-net re-check of pending children: 5 minutes after
|
|
27
|
+
* the parent starts waiting, then doubling, capped at 6 hours. A check costs
|
|
28
|
+
* one sleep and one step, so a child that runs for a day costs its parent
|
|
29
|
+
* about a dozen of each, and a lost notification is noticed within one
|
|
30
|
+
* interval.
|
|
31
|
+
*/
|
|
32
|
+
export declare function safetyCheckDelayMs(index: number): number;
|
|
33
|
+
export declare function childRunCompletionToken(parentRunId: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* When called inside the workflow VM of the run that started `childRunId`,
|
|
36
|
+
* waits for the child through the parent's completion hook and returns its
|
|
37
|
+
* return value. Returns `undefined` everywhere else (host code, steps, a
|
|
38
|
+
* workflow that was handed someone else's `Run`), where the caller polls.
|
|
39
|
+
*
|
|
40
|
+
* `readValue` is the child's return-value step (it polls until the child is
|
|
41
|
+
* terminal, so it is only called once the child is known to be done), and
|
|
42
|
+
* `readFinished` the step that reports which of a batch of runs finished.
|
|
43
|
+
*/
|
|
44
|
+
export declare function awaitChildRunCompletion<T>(childRunId: string, parentRunId: string | undefined, readValue: () => Promise<T>, readFinished: (runIds: string[]) => Promise<string[]>): Promise<T> | undefined;
|
|
45
|
+
//# sourceMappingURL=child-run-completion.d.ts.map
|
|
@@ -100,9 +100,12 @@ export interface Orchestrator {
|
|
|
100
100
|
* Writes the `run_failed` that ends a run past its max queue deliveries.
|
|
101
101
|
* Resolves `'superseded'` when the in-band fence refused the write, which
|
|
102
102
|
* does not prove another orchestrator is running; the caller has the queue
|
|
103
|
-
* redeliver the message to retry it. Otherwise
|
|
103
|
+
* redeliver the message to retry it. Otherwise resolves the run the write
|
|
104
|
+
* returned (when the World returned one), or throws what the World threw.
|
|
104
105
|
*/
|
|
105
|
-
writeMaxDeliveriesFailure(world: World, runId: string, eventData: RunFailedEventRequest['eventData'], requestId: string | undefined): Promise<
|
|
106
|
+
writeMaxDeliveriesFailure(world: World, runId: string, eventData: RunFailedEventRequest['eventData'], requestId: string | undefined): Promise<{
|
|
107
|
+
run: WorkflowRun | undefined;
|
|
108
|
+
} | 'superseded'>;
|
|
106
109
|
/** Runs one delivery of the run's queue message. */
|
|
107
110
|
runDelivery(delivery: WorkflowDelivery): Promise<DeliveryResult>;
|
|
108
111
|
}
|
|
@@ -54,6 +54,14 @@ export interface HealthCheckResult {
|
|
|
54
54
|
* which fails that gate closed.
|
|
55
55
|
*/
|
|
56
56
|
hookResumeInputVersion?: number;
|
|
57
|
+
/**
|
|
58
|
+
* The responding deployment's `CHILD_RUN_COMPLETION_VERSION`: whether a run
|
|
59
|
+
* it executes resumes its parent's child-run completion hook when it
|
|
60
|
+
* finishes. A cross-deployment `start()` from a workflow stamps the child to
|
|
61
|
+
* resume that hook only when the target advertises it. Omitted when the
|
|
62
|
+
* responding deployment predates the hook, so its parents poll instead.
|
|
63
|
+
*/
|
|
64
|
+
childRunCompletionVersion?: number;
|
|
57
65
|
/**
|
|
58
66
|
* The format the responding deployment answered in, set whenever it
|
|
59
67
|
* answered: `'text'` for the plain-text reply of deployments that predate
|
|
@@ -70,7 +78,7 @@ export interface HealthCheckResult {
|
|
|
70
78
|
/**
|
|
71
79
|
* The responding deployment's `World.capabilities`, so a cross-deployment
|
|
72
80
|
* `start()` can check that the World which will execute the run supports a
|
|
73
|
-
* feature before relying on it (`start({
|
|
81
|
+
* feature before relying on it (`start({ experimental_hook })` checks
|
|
74
82
|
* `atomicStartHook`). Parsed tolerantly: an unknown capability is dropped
|
|
75
83
|
* and a malformed one reads as unsupported, so a peer on a different SDK
|
|
76
84
|
* version can only ever lose a feature, never its health. Omitted when the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{t as DYNAMIC_WORKFLOW_VERSION,n as REPLAY_RESOLVE_DATA,r as SLOT_GAP_RECHECK_ATTEMPTS,i as SLOT_GAP_RECHECK_BASE_DELAY_MS,a as absorbSkippedSlotReport,o as appendEventLog,s as appendUniqueEvents,c as findEventSlotGap,l as getQueueOverhead,u as getWorkflowQueueName,d as handleHealthCheckMessage,f as healthCheck,p as insertEventByEventId,m as isQueueSendFailure,h as isSlotGapCheckEnabled,g as loadWorkflowRunEvents,_ as maxEventSlot,v as memoizeEncryptionKey,y as mergeReportedEvents,b as parseHealthCheckPayload,x as preconditionEventDelta,S as queueMessage,C as queueMessages,w as resolveRunEncryptionKey,T as rootRunIdFrom,E as runDispatchContext,D as settleEventSlotGap,O as slotSnapshotParams,k as stepDispatchIdempotencyKey,A as withHealthCheck,j as withReplayDelta}from"../../../_chunks/workflow/helpers-
|
|
1
|
+
export{t as DYNAMIC_WORKFLOW_VERSION,n as REPLAY_RESOLVE_DATA,r as SLOT_GAP_RECHECK_ATTEMPTS,i as SLOT_GAP_RECHECK_BASE_DELAY_MS,a as absorbSkippedSlotReport,o as appendEventLog,s as appendUniqueEvents,c as findEventSlotGap,l as getQueueOverhead,u as getWorkflowQueueName,d as handleHealthCheckMessage,f as healthCheck,p as insertEventByEventId,m as isQueueSendFailure,h as isSlotGapCheckEnabled,g as loadWorkflowRunEvents,_ as maxEventSlot,v as memoizeEncryptionKey,y as mergeReportedEvents,b as parseHealthCheckPayload,x as preconditionEventDelta,S as queueMessage,C as queueMessages,w as resolveRunEncryptionKey,T as rootRunIdFrom,E as runDispatchContext,D as settleEventSlotGap,O as slotSnapshotParams,k as stepDispatchIdempotencyKey,A as withHealthCheck,j as withReplayDelta}from"../../../_chunks/workflow/helpers-DWfdYiCu.js";
|
|
@@ -135,6 +135,12 @@ export interface OutOfBandObservation {
|
|
|
135
135
|
unknownHookCount: number;
|
|
136
136
|
/** Open `AbortController` system hooks: always path-changing. */
|
|
137
137
|
abortSignalHookCount: number;
|
|
138
|
+
/**
|
|
139
|
+
* Open SDK-internal hooks of any kind (`AbortController` signals and the
|
|
140
|
+
* child-run completion hook): always path-changing. A superset of
|
|
141
|
+
* {@link abortSignalHookCount}.
|
|
142
|
+
*/
|
|
143
|
+
systemHookCount: number;
|
|
138
144
|
/**
|
|
139
145
|
* Pending steps this invocation does not execute itself. Their terminal
|
|
140
146
|
* events come from another executor, and their awaiters cannot be seen, so
|
|
@@ -84,10 +84,13 @@ export interface PendingHook {
|
|
|
84
84
|
*/
|
|
85
85
|
startHook?: true;
|
|
86
86
|
/**
|
|
87
|
-
* True for internal
|
|
88
|
-
*
|
|
87
|
+
* True for SDK-internal hooks (the AbortController hook, the child-run
|
|
88
|
+
* completion hook). Recorded on `hook_created`; such hooks are resumed by
|
|
89
|
+
* writers outside this run, and need not be created at terminal drain.
|
|
89
90
|
*/
|
|
90
91
|
isSystem?: boolean;
|
|
92
|
+
/** True for an AbortController's hook (VM-only; not recorded). */
|
|
93
|
+
isAbortSignal?: boolean;
|
|
91
94
|
/**
|
|
92
95
|
* Set when the workflow called AbortController.abort() during this
|
|
93
96
|
* invocation. The host must record the abort: create a hook_received
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Hook as WorldHook } from '#compiled/@workflow/world/index.js';
|
|
1
|
+
import { type World, type Hook as WorldHook } from '#compiled/@workflow/world/index.js';
|
|
2
2
|
import { type PayloadKey } from '../serialization.js';
|
|
3
3
|
/**
|
|
4
4
|
* A hook record with its serialized `metadata` omitted: everything a resume
|
|
@@ -119,6 +119,14 @@ export type ResumedHook = Hook & {
|
|
|
119
119
|
* ```
|
|
120
120
|
*/
|
|
121
121
|
export declare function resumeHook<T = any>(tokenOrHook: string | ResumableHook, payload: T, encryptionKeyOverride?: PayloadKey): Promise<ResumedHook>;
|
|
122
|
+
/**
|
|
123
|
+
* {@link resumeHook} against an explicit World rather than the process's
|
|
124
|
+
* configured one, for SDK internals that act on a World they were handed
|
|
125
|
+
* (e.g. `cancelRun(world, …)` resuming a parent's child-run completion hook).
|
|
126
|
+
*
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
export declare function resumeHookOnWorld<T = any>(world: World, token: string, payload: T): Promise<ResumedHook>;
|
|
122
130
|
/**
|
|
123
131
|
* Resumes a webhook by sending a {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | Request}
|
|
124
132
|
* object to a hook identified by its token.
|
|
@@ -93,12 +93,14 @@ export interface WorkflowRunWritableStreamOptions {
|
|
|
93
93
|
export declare class Run<TResult> {
|
|
94
94
|
#private;
|
|
95
95
|
static [WORKFLOW_SERIALIZE](instance: Run<unknown>): {
|
|
96
|
+
parentRunId?: string | undefined;
|
|
96
97
|
runId: string;
|
|
97
98
|
resilientStart: boolean;
|
|
98
99
|
};
|
|
99
100
|
static [WORKFLOW_DESERIALIZE](data: {
|
|
100
101
|
runId: string;
|
|
101
102
|
resilientStart?: boolean;
|
|
103
|
+
parentRunId?: string;
|
|
102
104
|
}): Run<unknown>;
|
|
103
105
|
/**
|
|
104
106
|
* The ID of the workflow run.
|
|
@@ -106,6 +108,7 @@ export declare class Run<TResult> {
|
|
|
106
108
|
runId: string;
|
|
107
109
|
constructor(runId: string, opts?: {
|
|
108
110
|
resilientStart?: boolean;
|
|
111
|
+
parentRunId?: string;
|
|
109
112
|
});
|
|
110
113
|
/**
|
|
111
114
|
* Interrupts pending `sleep()` calls, resuming the workflow early.
|
|
@@ -135,10 +138,30 @@ export declare class Run<TResult> {
|
|
|
135
138
|
*/
|
|
136
139
|
get status(): Promise<WorkflowRunStatus>;
|
|
137
140
|
/**
|
|
138
|
-
* The return value of the workflow run.
|
|
139
|
-
*
|
|
141
|
+
* The return value of the workflow run, once it completes. Rejects with
|
|
142
|
+
* `WorkflowRunFailedError` or `WorkflowRunCancelledError` if the run fails
|
|
143
|
+
* or is cancelled.
|
|
144
|
+
*
|
|
145
|
+
* Inside the workflow that started this run, the parent suspends on a system
|
|
146
|
+
* hook the run resumes when it finishes, so waiting costs no compute and
|
|
147
|
+
* resumes as soon as the run is done. Everywhere else (host code, steps,
|
|
148
|
+
* a workflow handed another run's handle) it polls until the run finishes.
|
|
140
149
|
*/
|
|
141
150
|
get returnValue(): Promise<TResult>;
|
|
151
|
+
/**
|
|
152
|
+
* The step behind {@link returnValue}: polls until the run is terminal.
|
|
153
|
+
* Use `returnValue` instead.
|
|
154
|
+
* @internal
|
|
155
|
+
*/
|
|
156
|
+
readReturnValue(): Promise<TResult>;
|
|
157
|
+
/**
|
|
158
|
+
* Which of `runIds` have finished (completed, failed, or cancelled), in one
|
|
159
|
+
* step: the batched status read behind the child-run completion hook. A run
|
|
160
|
+
* that cannot be found is reported as finished, so the caller's
|
|
161
|
+
* `returnValue` read surfaces the not-found (or retries a resilient start).
|
|
162
|
+
* @internal
|
|
163
|
+
*/
|
|
164
|
+
static readFinishedRunIds(runIds: string[]): Promise<string[]>;
|
|
142
165
|
/**
|
|
143
166
|
* The name of the workflow.
|
|
144
167
|
*/
|
|
@@ -89,7 +89,7 @@ export declare function wakeRunAfterOutOfBandWrite(world: World, run: Pick<Workf
|
|
|
89
89
|
* Cancel a workflow run.
|
|
90
90
|
*
|
|
91
91
|
* A run that does not exist (yet) is still cancelled through the World: a
|
|
92
|
-
* `start({
|
|
92
|
+
* `start({ experimental_hook })` candidate that was admitted but never created a run (the
|
|
93
93
|
* recovery `WorkflowStartError` points at) is fenced by it, so no copy of it
|
|
94
94
|
* can create the run any more. Otherwise the World answers not found, which
|
|
95
95
|
* is thrown as `WorkflowRunNotFoundError`.
|