eve 1.0.0-rc.3 → 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 -74
- package/NOTICE +24 -0
- package/dist/src/_virtual/_rolldown/runtime.js +1 -1
- package/dist/src/cli/dev/tui/file-content-cache.d.ts +9 -3
- package/dist/src/cli/dev/tui/file-content-cache.js +1 -1
- package/dist/src/cli/dev/tui/transcript.js +1 -1
- 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/index.js +1 -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-C0vwtoWB.js +1 -0
- package/dist/src/compiled/_chunks/workflow/dist-C3TM5_NG.js +45 -0
- package/dist/src/compiled/_chunks/workflow/global-singleton-BNinwFrL.js +1 -0
- 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-CuVMlqdU.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/definitions/builtins.d.ts +2 -3
- package/dist/src/definitions/builtins.js +1 -1
- package/dist/src/definitions/definition.d.ts +0 -1
- package/dist/src/definitions/definition.js +1 -1
- package/dist/src/definitions/instructions.js +1 -1
- package/dist/src/evals/cli/eval-client.d.ts +2 -1
- package/dist/src/evals/cli/eval-client.js +1 -1
- package/dist/src/execution/dynamic-workflow/tool.js +1 -1
- package/dist/src/execution/sandbox/bash.d.ts +3 -2
- package/dist/src/execution/sandbox/bash.js +6 -3
- package/dist/src/execution/sandbox/workspace-root.d.ts +0 -7
- package/dist/src/execution/sandbox/workspace-root.js +1 -1
- package/dist/src/execution/sandbox/write-file.d.ts +9 -0
- package/dist/src/execution/sandbox/write-file.js +1 -1
- package/dist/src/execution/session-inbox/handle.js +1 -1
- package/dist/src/execution/tools/agent-router-workflow.js +1 -1
- package/dist/src/extensions/code/extension/instructions/project.d.ts +2 -0
- package/dist/src/extensions/code/extension/instructions/project.js +1 -0
- package/dist/src/extensions/code/extension/instructions.md +16 -8
- package/dist/src/extensions/code/extension/lib/project-instructions.d.ts +13 -0
- package/dist/src/extensions/code/extension/lib/project-instructions.js +4 -0
- package/dist/src/extensions/code/extension/lib/sandbox.d.ts +2 -2
- package/dist/src/extensions/code/extension/lib/sandbox.js +1 -1
- package/dist/src/extensions/code/extension/lib/tooling.d.ts +0 -12
- package/dist/src/extensions/code/extension/lib/tooling.js +1 -92
- package/dist/src/extensions/git/extension/lib/github-shell.d.ts +5 -3
- package/dist/src/extensions/git/extension/lib/github-shell.js +1 -1
- package/dist/src/framework/sources/registry.js +1 -1
- package/dist/src/harness/compaction/engine.js +1 -1
- package/dist/src/harness/compaction/prompt.d.ts +3 -3
- package/dist/src/harness/compaction/prompt.js +1 -1
- package/dist/src/harness/provider-tools.d.ts +3 -2
- package/dist/src/harness/provider-tools.js +1 -1
- package/dist/src/harness/semantic-errors/rules/model-provider.js +1 -1
- package/dist/src/harness/semantic-errors/signals.d.ts +4 -1
- package/dist/src/harness/semantic-errors/signals.js +1 -1
- package/dist/src/harness/session-machine/cascade.js +1 -1
- package/dist/src/harness/tool-model-output.d.ts +3 -0
- package/dist/src/harness/tool-model-output.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/mcp/published-tools.js +1 -1
- 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/public/tools/edit-file.d.ts +3 -0
- package/dist/src/public/tools/edit-file.js +1 -0
- package/dist/src/runtime/prompt/compose.d.ts +0 -2
- package/dist/src/runtime/prompt/compose.js +2 -3
- package/dist/src/runtime/subagents/workflow.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/shared/web-search.d.ts +2 -2
- package/dist/src/shared/web-search.js +1 -1
- package/dist/src/tools/model-output.d.ts +10 -0
- package/dist/src/tools/model-output.js +1 -1
- package/dist/src/tools/provided/ask-question-workflow.js +1 -1
- package/dist/src/tools/provided/bash.js +3 -3
- package/dist/src/tools/provided/edit-file.d.ts +19 -0
- package/dist/src/tools/provided/edit-file.js +13 -0
- package/dist/src/tools/provided/sleep-workflow.js +1 -1
- package/dist/src/tools/provided/write-file.d.ts +1 -0
- package/dist/src/tools/provided/write-file.js +2 -2
- package/dist/src/tools/schema.d.ts +5 -0
- package/dist/src/tools/schema.js +1 -1
- package/docs/code-extension.mdx +15 -31
- package/docs/concepts/built-in-tools.md +50 -4
- package/docs/concepts/execution-model-and-durability.mdx +1 -1
- package/docs/concepts/security-model.md +1 -1
- package/docs/concepts/sessions-runs-and-streaming.md +2 -0
- package/docs/evals/assertions.mdx +25 -0
- package/docs/evals/targets.mdx +15 -1
- package/docs/extensions/index.md +1 -1
- package/docs/guides/client/index.mdx +1 -1
- package/docs/guides/deployment/index.md +1 -1
- package/docs/guides/deployment/workflow-worlds.md +3 -1
- package/docs/guides/upgrade/agent-files.md +13 -0
- package/docs/reference/cli/index.md +1 -1
- package/docs/reference/typescript-api.md +2 -2
- package/docs/sandbox/index.mdx +1 -1
- package/docs/tools/index.mdx +2 -2
- package/docs/tools/workflows.mdx +6 -2
- package/package.json +10 -23
- package/dist/src/compiled/_chunks/workflow/attribute-changes-D1iAmxwH.js +0 -6
- package/dist/src/compiled/_chunks/workflow/delivery-DfW1k9T2.js +0 -1
- package/dist/src/compiled/_chunks/workflow/dist-BrdA0lMi.js +0 -1
- package/dist/src/compiled/_chunks/workflow/dist-C32arEh7.js +0 -3
- package/dist/src/compiled/_chunks/workflow/dist-zRr5IZEB.js +0 -45
- package/dist/src/compiled/_chunks/workflow/helpers-D0Wn85SG.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-D3rP2sy1.js +0 -1
- package/dist/src/compiled/_chunks/workflow/run-4Zr4Jcrn.js +0 -32
- package/dist/src/compiled/_chunks/workflow/serialization-BEe0I8fg.js +0 -15
- package/dist/src/compiled/_chunks/workflow/sleep-8FShVa1U.js +0 -1
- package/dist/src/compiled/_chunks/workflow/suspension-hooks-DR0uRGOc.js +0 -5
- package/dist/src/compiled/_chunks/workflow/undici-DKqj707r.js +0 -95
- package/dist/src/compiled/_chunks/workflow/wait-until-BmHArYQw.js +0 -1
- package/dist/src/extensions/code/extension/lib/diagnostics.d.ts +0 -32
- package/dist/src/extensions/code/extension/lib/diagnostics.js +0 -6
- package/dist/src/extensions/code/extension/lib/generated-paths.d.ts +0 -19
- package/dist/src/extensions/code/extension/lib/generated-paths.js +0 -2
- package/dist/src/extensions/code/extension/lib/guidelines.d.ts +0 -26
- package/dist/src/extensions/code/extension/lib/guidelines.js +0 -2
- package/dist/src/extensions/code/extension/lib/patch.d.ts +0 -42
- package/dist/src/extensions/code/extension/lib/patch.js +0 -20
- package/dist/src/extensions/code/extension/lib/shell.d.ts +0 -1
- package/dist/src/extensions/code/extension/lib/shell.js +0 -1
- package/dist/src/extensions/code/extension/lib/workspace-root.d.ts +0 -1
- package/dist/src/extensions/code/extension/lib/workspace-root.js +0 -1
- package/dist/src/extensions/code/extension/tools/apply_patch.d.ts +0 -28
- package/dist/src/extensions/code/extension/tools/apply_patch.js +0 -15
- package/dist/src/extensions/code/tools.d.ts +0 -2
- package/dist/src/extensions/code/tools.js +0 -1
- package/dist/src/internal/grep.d.ts +0 -1
- package/dist/src/internal/grep.js +0 -1
- package/dist/src/internal/workspace.d.ts +0 -1
- package/dist/src/internal/workspace.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,82 +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
|
-
- The code extension (`eve/extensions/code`) no longer mounts its `code__grep` tool, which removes about 1.6K characters of tool schema from every model step.
|
|
8
|
-
To keep a structured search tool, run `eve add tool/grep`, which writes `agent/tools/grep.ts` re-exporting `eve/tools/grep`. `eve/extensions/code/tools` still exports the same `grep` definition. Delete an `agent/tools/code__grep.ts` file that exports `disableTool()`, because `eve build` now rejects it with `disables a slot with no lower-precedence source`. An `agent/tools/code__grep.ts` override that spreads `grep` keeps working as your own tool named `code__grep`. ([#5815](https://github.com/vercel/eve/pull/5815))
|
|
9
|
-
- The code extension (`eve/extensions/code`) no longer adds the read-only `code__worker` subagent, and `code()` rejects the `worker` option.
|
|
10
|
-
To migrate, remove `worker` from your `code()` mount and delegate with the built-in `agent` tool. If an `agent/tools/agent.ts` override disables `agent` so delegation goes to `code__worker`, delete the override. A mount that still passes `worker` fails with ``Invalid extension config: eve-code no longer ships a worker subagent; delegate with the built-in `agent` tool and remove the `worker` option.``
|
|
11
|
-
The `code__review` skill starts a fresh-context agent with a no-edit audit brief when one is available and otherwise audits in the current session. The `code__lookup-agent-run` skill and the internal `eve/internal/code/prwatch` export are removed. ([#5800](https://github.com/vercel/eve/pull/5800))
|
|
12
|
-
- A dynamic tool no longer replaces a static tool of the same name: the static tool keeps the name and eve logs an error, as it already did for two dynamic tools with the same name.
|
|
13
|
-
To change a tool for some sessions only, define it only in a dynamic file that returns the usual version to the other sessions.
|
|
14
|
-
Agents whose only tools are dynamic now get the parallel-calls note in their system prompt, and the `$eve.tool_count` span attribute counts the tools offered to the model rather than the tools the agent declares. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
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)
|
|
15
4
|
|
|
16
5
|
## Features
|
|
17
6
|
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
- Slack message hooks can return `status: "deferred"` to keep a message's turn quiet until a tool call finishes, and `guidance` to tell the model how to treat that one message, so an agent can follow a thread and stay silent with `no_reply` when a reply isn't meant for it.
|
|
23
|
-
`status: "deferred"` skips the `received` acknowledgement. Mentions and DMs outside code channels get that acknowledgement before their hook runs, so for them it keeps only the rest of the turn quiet. A message that isn't deferred and joins the turn shows the status again. eve adds `guidance` as a `<guidance>` block inside the message's `<slack_message>` or `<slack_message_edit>` block, after the metadata and before the content. The Slack docs show how to follow threads the agent already serves with `onMessage`.
|
|
24
|
-
Message edits now go through an app's own message hooks. Without an authored `onMessageEdited`, an edit goes to the hook a new message of the same kind would reach: `onDirectMessage`, then `onMessage`, for DMs; `onAppMention`, then `onMessage`, for messages that mention the agent; `onMessage`, then `onAppMention`, in code channels; and `onMessage` for other messages. Without those hooks, the built-in defaults send edits to DMs, code channel messages, and messages that mention the agent before or after the edit, and drop the rest. Edits are always quiet and ignore `status`, and an authored `onEvent` still comes before this default. The new `ctx.edit` is set while a hook decides an edit.
|
|
25
|
-
In 1.0.0-rc.2, an authored `onAppMention`, `onDirectMessage`, or `onMessage` turned off edits unless the app also defined `onMessageEdited`. Those hooks now also run for edits in threads that have a session. If a hook has side effects, such as `ctx.send()`, `ctx.end()`, or a decision model call, return early when `ctx.edit` is set. To keep edits off, define `onMessageEdited` and return `null`. ([#5801](https://github.com/vercel/eve/pull/5801))
|
|
26
|
-
- The provided `bash` tool shows the model its output as plain text instead of JSON, so source code, diffs, and test logs reach the model without escaped newlines and quotes.
|
|
27
|
-
The model reads stdout, then any stderr after a `[stderr]` line, then a final `[exit code: N]` line; for a command still running, its instructions replace the exit code line. The tool's `execute` output, its output schema, and `call.settled` events keep the structured fields. Authored code that reads the conversation, through `ctx.messages` in tools or `ctx.messages()` in dynamic capabilities, sees this text for new `bash` results, and sessions keep the JSON results they already saved. A `bash` tool published over MCP sends the text in `content[0].text`, and its `structuredContent` keeps the structured fields. Wrappers that spread `bash` keep the plain-text view: a wrapper's `execute` that returns a string reaches the model as text, and any other shape as JSON. ([#5822](https://github.com/vercel/eve/pull/5822))
|
|
28
|
-
- `auto()` from `eve/models` and `eve/tools/approval` accept `modelOptions.providerOptions`, and `decide()` accepts `providerOptions`, so decision calls can set options such as AI Gateway's `zeroDataRetention`. ([#5846](https://github.com/vercel/eve/pull/5846))
|
|
29
|
-
- The code extension (`eve/extensions/code`) sends a prompt about a third of its previous size (4,942 to 1,636 characters) that keeps only coding and safety rules, so agents spend fewer tokens on every step.
|
|
30
|
-
The prompt no longer assumes a chat product or sets consumer policy, such as brevity, asking one question, avoiding em dashes, omitting private references, or not rebasing. Agents that relied on those rules should state them in their own `agent/instructions.md`. Agents publish or write to external systems only when the requester asks for it or for an outcome that requires it, such as a pull request. The prompt asks agents to edit files with the editing tool instead of the shell, and no longer names `apply_patch` specifically. The issue and design checklists moved into the `code__investigate` skill. ([#5805](https://github.com/vercel/eve/pull/5805))
|
|
31
|
-
- Update the bundled Workflow runtime to 5.3.0 and create new runs with Workflow spec version 9, which drives each run from one orchestrator.
|
|
32
|
-
Workflow 5.3.0 lets parallel branches advance inline steps without waiting on slower siblings, reuses resolved hooks to skip token lookups on later resumes, and fixes a step that could be created but never run when two executions raced in one process. eve now sets `WORKFLOW_SPEC_VERSION=9` before it creates a world unless `WORKFLOW_SPEC_VERSION` or `WORKFLOW_SEALED_LOG` is already set. Set `WORKFLOW_SPEC_VERSION=8` to keep creating spec 8 runs. Existing runs keep their version. ([#5860](https://github.com/vercel/eve/pull/5860))
|
|
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))
|
|
33
11
|
|
|
34
12
|
## Bug Fixes
|
|
35
13
|
|
|
36
|
-
- Fix
|
|
37
|
-
|
|
38
|
-
-
|
|
39
|
-
|
|
40
|
-
- Every eve build now reads `paths` aliases from the authored package's own `tsconfig.json` or `jsconfig.json`, and an asset import that leaves the authored package fails the build.
|
|
41
|
-
The Nitro host, authored module bundles, and the workflow driver share one resolver. The workflow driver no longer searches parent directories for a config, and an agent directory without its own `package.json` uses the enclosing package's config in every build. Before, only `?raw` asset imports were checked against the package root; now plain imports such as `import notes from "../../notes.txt"` are checked too. If a build fails with "resolves outside package root", move the file into the authored package or into the workspace package that imports it. ([#5879](https://github.com/vercel/eve/pull/5879))
|
|
42
|
-
- Model calls made by `decide()` from `eve/ai`, and so by `auto()` and approval `auto()`, now count toward the session's usage and `limits.sessionUsage`. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
43
|
-
- Inline tool execution now requires permission from eve's approval gate.
|
|
44
|
-
When a person answers the same call more than once, eve uses their latest answer. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
45
|
-
- eve now records which of its catalog tools a session has been offered in the same session state as its other definitions, rather than under a separate context key.
|
|
46
|
-
A session an earlier deployment ran still keeps every catalog tool it was offered. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
47
|
-
- Under `eve dev`, eve now throws if a tool call starts before its approval is accepted, or names a different approval as what cleared it. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
48
|
-
- Compacting a session between turns no longer repeats the last question after its answer, so the next turn's new message follows the summary and recent history instead of an already-answered question. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
49
|
-
- Keep child questions and approvals answerable while a serving task remains active after replying to its original call.
|
|
50
|
-
Upgrading a session whose history was cleared or compacted also restores its dynamic user instructions before the next model call. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
51
|
-
- Fix tool-stub validation for memory-only agents, mounted dynamic connection names, and sandbox skill files when an earlier definition starts offering a colliding skill.
|
|
52
|
-
The chosen model also remains visible to session code across separately bundled runtime modules. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
53
|
-
- Dynamic connection resolvers can exchange names within one evaluation without a transient collision, and namespaced tools and skills retain their full name-length validation. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
54
|
-
- Fix release asset uploads failing with 401 through the git extension's `gh` tool.
|
|
55
|
-
The credential lease now covers `uploads.github.com`, not only `api.github.com` and `github.com`. A 401 there was read as a revoked token and opened a sign-in for a user who was already signed in.
|
|
56
|
-
When Vercel Connect starts an authorization without a sign-in URL or device code, the user-scoped GitHub sign-in now fails with `ConnectionAuthorizationFailedError` instead of opening a sign-in prompt with no link. ([#5852](https://github.com/vercel/eve/pull/5852))
|
|
57
|
-
- A workflow tool's question that reaches the session after its turn was cancelled no longer fails the session: eve drops it, and the next message starts a turn. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
58
|
-
- Memory slots and schedule collections now offer their tools themselves, so agent info no longer lists them as generated dynamic tool files.
|
|
59
|
-
A tool file at `agent/tools/<slot>.ts` or `agent/tools/schedule__<name>.ts` still replaces those tools, and `disableTool()` there still removes them. Sessions and approvals parked across the upgrade keep working. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
60
|
-
- Upgrade Nitro to 3.0.261103-rc, the first Nitro 3 release candidate eve builds on.
|
|
61
|
-
eve now declares Rolldown 1.2.16 itself and hands that copy to Nitro, so a plain npm install builds without relying on another package to provide Rolldown, and Nitro never installs a package into your app on demand. Importing `nitro/storage`, `nitro/kv`, or `nitro/database` from agent code now fails the build with an explanation instead of pulling in storage drivers. A request with a method its path doesn't declare, other than `HEAD`, now gets `405 Method Not Allowed` with an `Allow` header instead of `404`. `eve dev` runs on env-runner 0.3, and a stopped `eve start` server runs Nitro's close hooks and exits on its own.
|
|
62
|
-
Thanks @pi0 for the investigation in #5167. ([#5870](https://github.com/vercel/eve/pull/5870))
|
|
63
|
-
- eve now compiles an agent's dynamic tool, skill, connection, and instructions files, hooks, and memories to one list in the compiled manifest, and runs them as definitions of one shape.
|
|
64
|
-
Rebuild agents after upgrading; authored files don't change. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
65
|
-
- The discovery manifest in `.eve/discovery/agent-discovery-manifest.json` now lists an agent's authored files in one `sources` array, with each file's kind given by its path, instead of one array per kind. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
66
|
-
- Session history now changes in one place, which checks every message as it joins, and under `eve dev` fails a step whose tool results don't follow the calls they answer.
|
|
67
|
-
A turn that fails after the model delivered its structured reply keeps that reply in history instead of an unanswered `eve__reply` call. A compaction whose summary model fails to resolve now appears on the stream as a failed compaction instead of failing the turn before it starts. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
68
|
-
- The model no longer sees an "awaiting approval" note in history after the approval it describes is answered or dropped, because eve now tells each model call about pending approvals from the session's current state instead of writing a note into history when the call parks. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
69
|
-
- eve now renders each model call's system prompt from the current deployment's agent files instead of storing it with the session.
|
|
70
|
-
Session checkpoints move to version 19, without `agent.system`. A deployment from before this change refuses to take over a session this one wrote, so the session stays on the deployment that wrote it, such as after a rollback. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
71
|
-
- A turn's input now joins history before its first model call, so a model call that fails keeps the person's message for the next turn.
|
|
72
|
-
A response the provider filters is the exception: a refusal note replaces its turn's input, so the next turn doesn't send that input again. Completed tool calls and their results stay in history, so the model knows which actions already ran.
|
|
73
|
-
A compaction now opens only once it summarizes or rewrites the history, so `session.compact()` records no change when its model doesn't resolve or the history has nothing to compact. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
74
|
-
- eve's session loop now runs as a kernel that owns every session transition, with no change in behavior. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
75
|
-
- Prevent `gh-signed-commit` from publishing another file's contents for paths that resemble Git stage syntax or silently losing file modes and types.
|
|
76
|
-
The command now reads staged paths literally and rejects additions or updates involving executable files, symlinks, submodules, or mode changes before contacting GitHub. Staged changes remain intact; publish unsupported changes with native Git and a configured signing key. ([#5863](https://github.com/vercel/eve/pull/5863))
|
|
77
|
-
- Ending a stranded session now writes the same checked commit as any other session end.
|
|
78
|
-
A stranded stream that never recorded `session.started`, such as one an older deployment opened, gets it in the commit that ends the session. ([#5638](https://github.com/vercel/eve/pull/5638))
|
|
79
|
-
- Self-hosted eve servers now close their Workflow world on shutdown, so a pending workflow `sleep` or delivery retry no longer holds the process open until the supervisor kills it.
|
|
80
|
-
If closing the world fails or takes longer than 5 seconds, eve logs it and still runs the rest of its shutdown, including sandbox shutdown and the final trace flush. ([#5879](https://github.com/vercel/eve/pull/5879))
|
|
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))
|
|
81
18
|
|
|
82
|
-
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).
|
package/NOTICE
CHANGED
|
@@ -75,3 +75,27 @@ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
75
75
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
76
76
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
77
77
|
SOFTWARE.
|
|
78
|
+
|
|
79
|
+
The edit_file tool is adapted from the edit tool in pi
|
|
80
|
+
(https://github.com/badlogic/pi-mono) under the MIT License.
|
|
81
|
+
|
|
82
|
+
pi
|
|
83
|
+
Copyright (c) 2025 Mario Zechner
|
|
84
|
+
|
|
85
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
86
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
87
|
+
in the Software without restriction, including without limitation the rights
|
|
88
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
89
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
90
|
+
furnished to do so, subject to the following conditions:
|
|
91
|
+
|
|
92
|
+
The above copyright notice and this permission notice shall be included in all
|
|
93
|
+
copies or substantial portions of the Software.
|
|
94
|
+
|
|
95
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
96
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
97
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
98
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
99
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
100
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
101
|
+
SOFTWARE.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"node:module";
|
|
1
|
+
import"node:module";export{};
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* Session-local knowledge of file contents, so the write block can show a
|
|
3
3
|
* real diff without any protocol addition. Two feeds keep it current: every
|
|
4
4
|
* `write_file` input is a full replacement (exact), and every full-file
|
|
5
|
-
* `read_file` result reconstructs to the file's exact lines.
|
|
6
|
-
*
|
|
7
|
-
* unknown prior content renders plain rather than pretending to be a
|
|
5
|
+
* `read_file` result reconstructs to the file's exact lines. An `edit_file`
|
|
6
|
+
* call makes its file unknown. Files touched by `bash` are invisible here — a
|
|
7
|
+
* write over unknown prior content renders plain rather than pretending to be a
|
|
8
|
+
* diff.
|
|
8
9
|
*/
|
|
9
10
|
export declare class FileContentCache {
|
|
10
11
|
#private;
|
|
@@ -19,6 +20,11 @@ export declare class FileContentCache {
|
|
|
19
20
|
content: string;
|
|
20
21
|
callId: string;
|
|
21
22
|
}): string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Marks the content of `path` unknown after a change this cache cannot replay. A write that
|
|
25
|
+
* already rendered keeps returning its previous content when it re-renders.
|
|
26
|
+
*/
|
|
27
|
+
forget(path: string): void;
|
|
22
28
|
/**
|
|
23
29
|
* Forgets everything. A new conversation runs against a fresh session —
|
|
24
30
|
* possibly a fresh sandbox — so stale bases would produce confidently
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const MAX_CACHED_CONTENT_CHARS=2e5;var FileContentCache=class{#e=new Map;observeWrite(e){let t=this.#e.get(e.path);if(t?.writerCallId===e.callId)return t.previous;if(e.content.length>MAX_CACHED_CONTENT_CHARS){this.#e.delete(e.path);return}let n=t?.content,r={content:e.content,writerCallId:e.callId};return n!==void 0&&(r.previous=n),this.#e.set(e.path,r),n}clear(){this.#e.clear()}observeRead(e){let t=readFileResultShape(e);if(t===void 0||t.truncated||t.content.length>MAX_CACHED_CONTENT_CHARS)return;let n=reconstructNumberedLines(t.content);n!==void 0&&n.length===t.totalLines&&this.#e.set(t.path,{content:n.join(`
|
|
1
|
+
const MAX_CACHED_CONTENT_CHARS=2e5;var FileContentCache=class{#e=new Map;observeWrite(e){let t=this.#e.get(e.path);if(t?.writerCallId===e.callId)return t.previous;if(e.content.length>MAX_CACHED_CONTENT_CHARS){this.#e.delete(e.path);return}let n=t?.content,r={content:e.content,writerCallId:e.callId};return n!==void 0&&(r.previous=n),this.#e.set(e.path,r),n}forget(e){let t=this.#e.get(e);if(t?.writerCallId===void 0){this.#e.delete(e);return}let n={writerCallId:t.writerCallId};t.previous!==void 0&&(n.previous=t.previous),this.#e.set(e,n)}clear(){this.#e.clear()}observeRead(e){let t=readFileResultShape(e);if(t===void 0||t.truncated||t.content.length>MAX_CACHED_CONTENT_CHARS)return;let n=reconstructNumberedLines(t.content);n!==void 0&&n.length===t.totalLines&&this.#e.set(t.path,{content:n.join(`
|
|
2
2
|
`)})}};function readFileResultShape(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let{content:t,path:n,totalLines:r,truncated:i}=e;if(typeof t==`string`&&typeof n==`string`&&typeof r==`number`&&typeof i==`boolean`)return{content:t,path:n,totalLines:r,truncated:i}}function reconstructNumberedLines(e){if(e===``)return[];let t=[];for(let[n,r]of e.split(`
|
|
3
3
|
`).entries()){let e=/^(\d+): (.*)$/su.exec(r);if(e===null||Number(e[1])!==n+1)return;t.push(e[2])}return t}export{FileContentCache};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FileContentCache}from"./file-content-cache.js";import{signInLabel,waitingLabel}from"./task-activity.js";import{TaskRecords}from"./task-records.js";import{agentDisplayName,agentTaskLabel,isPanelRoutedTool,readWriteFileInput,toolBaseName}from"./tool-presentation.js";import{activeToolSteps,authorizationTerminalMessage,endLine,firstLine,followUpLine,formatAuthorization,isActive,isToolCallRow,nestedTaskRecord,startLine,subagentSteps,taskCallsById,taskNeedsApproval,toolBlock,toolState,userText,writeExistedFlag}from"./transcript-parts.js";import{activity,callOutputSource}from"#protocol/session-projection/selectors.js";import{sessionTables,snapshotState}from"#protocol/session-projection/session-view.js";import{stripTerminalControls}from"#cli/ui/terminal-text.js";import{agentCallActivity,agentToolSession,taskCalls}from"#client/conversation-state.js";var ConversationTranscript=class{#e=new Map;#t=new FileContentCache;#n=new TaskRecords;#r=new Map;#i=[];#a=new Set;#o=[];reset(){this.#e=new Map,this.#t.clear(),this.#n.clear(),this.#r.clear(),this.#i=[],this.#a.clear(),this.#o=[]}get tasks(){return this.#o}taskLabel(e,t){let n=sessionTables(e.view).tasks[t];if(n===void 0)return;let r=taskCalls(e.view,t),i=r.findLast(e=>e.status!==`settled`)??r.at(-1),a=i===void 0?void 0:this.#n.get(i.callId);return a===void 0?n.kind===`agent`?agentTaskLabel(agentDisplayName(stripTerminalControls(n.name))):stripTerminalControls(n.name):a.kind===`agent`?agentTaskLabel(a.name):a.name}stopWorking(e){let t=[];for(let n of this.#n.values())n.ended||(n.ended=!0,t.push(endLine(n,{outcome:`interrupted`,status:`settled`},void 0,e.dot??`·`)));return this.#o=[],t}project(e,t){let{conversation:n,working:r}=e,i=Date.now(),a=[],o=taskCallsById(n),{toolLabels:s,withdrawn:c}=e.data,l=new Map(e.failures.flatMap(e=>e.turnId===void 0?[]:[[e.turnId,e]])),u=new Map;for(let[e,t]of n.messages.entries()){let n=t.metadata?.turnId;n!==void 0&&u.set(n,e)}let d=new Set,endTurn=(e,n)=>{if(n===void 0||u.get(n)!==e)return!1;let r=l.get(n);return r!==void 0&&(a.push(this.#g(`failure:${n}`,r,t)),d.add(n),!0)};for(let[d,f]of n.messages.entries()){if(f.role===`user`){let e=this.#f(f);e!==void 0&&a.push(e),endTurn(d,f.metadata?.turnId);continue}let p=f.parts.filter(e=>isToolCallRow(e)&&(e.state!==`streaming`||r)&&e.kind!==`control`&&!c(e.callId)&&!o.has(e.callId)&&!isPanelRoutedTool(e.name)),m=new Map(p.map(t=>[t,toolState(t,e.data.view)])),h=activeToolSteps(m);for(let[n,c]of f.parts.entries())if(c.type===`text`||c.type===`reasoning`){let e=this.#p(f,n,t,r);e!==void 0&&a.push(e)}else if(c.type===`interaction`)c.request.signIn!==void 0&&t.connectionAuth!==`hidden`&&a.push(this.#m(c,c.request.signIn));else if(c.type===`tool`){let n=o.get(c.callId);if(n!==void 0){let r=this.#c(c,n.task,s,t,i,e.data.view);r!==void 0&&a.push(r);continue}let r=m.get(c);if(r===void 0||t.tools===`hidden`)continue;let l=s(c.callId);a.push(this.#h(c,r,h.has(c.stepIndex),l,t))}let g=f.metadata?.turnId;endTurn(d,g)||g!==void 0&&!l.has(g)&&u.get(g)===d&&sessionTables(n.view).turns[g]?.outcome===`cancelled`&&a.push(this.#d(`cancelled:${g}`,[],()=>({kind:`notice`,body:`Cancelled.`,live:!1})))}let f=0;for(let n of e.failures){if(n.turnId!==void 0&&d.has(n.turnId))continue;let e=n.turnId===void 0?`failure:session:${f++}`:`failure:${n.turnId}`;a.push(this.#g(e,n,t))}let p=this.#s(a),m=this.#l(e,o,t,i);for(let e of m){let t=p.slice(-8).map(e=>e.id);this.#i.push({block:e,after:t}),this.#a.add(e.id),p.push(e)}return p}#s(e){let t=[...e];for(let{block:e,after:n}of this.#i){let r=t.length;for(let e=n.length-1;e>=0;--e){let i=t.findIndex(t=>t.id===n[e]);if(i!==-1){r=i+1;break}}t.splice(r,0,e)}return t}#c(e,t,n,r,i,a){if(!(t.kind===`agent`?r.subagents!==`hidden`:r.tools!==`hidden`))return;let o=n(e.callId)?.start,s=this.#n.record(e,t,o,i,a);return s.callId===e.callId?this.#d(`task:${s.callId}:start`,[s],()=>startLine(s)):this.#d(`task:${e.callId}:message`,[s],()=>followUpLine(s,e,o))}#l(e,t,n,r){let{conversation:i,working:a}=e,o=Object.values(sessionTables(i.view).turns).at(-1),s=!a&&(e.data.sessionFailed||o?.outcome===`cancelled`||o?.outcome===`failed`),c=[],l=[],u={remaining:128};for(let e of this.#n.values()){if(e.ended)continue;let o=t.get(e.callId)?.task;if(o===void 0)continue;let d=e.callIds.flatMap(e=>{let n=t.get(e)?.call;return n===void 0?[]:[n]}),f=d.at(-1),p=this.#u(e,o,d,i,n,u);if(n.subagents===`full`)for(let e of p.rows)this.#a.has(e.id)||c.push(e);let m=d.every(e=>e.status===`settled`);m&&(e.settledAtMs??=r);let h=m&&p.pending&&a;if(m&&!h||!m&&s){e.ended=!0,c.push(endLine(e,m?{...f,output:callOutputSource(sessionTables(i.view),f.callId)?.output}:{outcome:`interrupted`,status:`settled`},p.tools,n.dot??`·`));continue}let g={callId:e.callId,kind:e.kind,name:e.name,toolName:e.toolName,input:e.input,label:e.label,purpose:e.purpose,children:p.children,omittedTasks:p.omittedTasks,omittedAttention:p.omittedAttention,startedAtMs:e.startedAtMs,childTools:new Map(p.tools.map(e=>[e.id,e]))};p.step!==void 0&&(g.step=p.step),h&&(g.finishing=!0),l.push(g)}return this.#o=l,c}#u(e,t,n,r,i,a,o=0){let s=t.kind===`agent`?agentToolSession(r,t):void 0,c=s===void 0||s.observation.status===`not-followed`?void 0:s.observation.conversation;if(s===void 0||c===void 0)return{tools:[],rows:[],pending:!1};let l=n.flatMap(e=>{let t=agentCallActivity(r,e.callId);return t.status===`unlinked`?[]:t.sessions.filter(e=>e.sessionId===s.sessionId)}),u=s.observation.status===`following`&&l.some(e=>e.deliveries.some(({status:e})=>e!==`settled`)),d=new Set(l.flatMap(e=>e.turns.map(({turnId:e})=>e))),f=!sessionTables(r.view).children[s.sessionId]?.deliveries?.length,p=c.messages.filter(e=>e.role===`assistant`&&e.metadata?.turnId!==void 0&&(f||d.has(e.metadata.turnId))),m=taskCallsById(c),h=[],g=[],_=[],v=new Set,y=0,b=!1,x=0;for(let t of p)for(let n of t.parts){if(x+=1,!isToolCallRow(n)||n.kind===`control`)continue;let t=m.get(n.callId),r=toolState(n,sessionTables(c.view)),s=`subagent:${e.callId}:tool:${n.callId}`,l=this.#d(s,[n,r.status,e.name],()=>{let a=this.#_(n.callId,n,r,i,{isSubagent:t?.task.kind===`agent`});return{...toolBlock(n,r,a),kind:`subagent-tool`,subagentCallId:e.callId,agentName:e.name,depth:1,live:!1}}),u=t?.task.kind===`agent`?i.subagents!==`hidden`:i.tools!==`hidden`;if(t!==void 0&&t.call.status!==`settled`&&u){if(v.has(t.task.taskId))continue;if(v.add(t.task.taskId),o>=8||a.remaining<=0){y+=1,b||=r.status===`approval`||taskNeedsApproval(c,t.task);continue}--a.remaining;let s=`${e.callId}/${n.callId}`,u=this.#r.get(s);u===void 0&&(u=nestedTaskRecord(s,n,t.task,l),this.#r.set(s,u));let d=this.#u(u,t.task,taskCalls(c.view,t.task.taskId).filter(e=>e.status!==`settled`),c,i,a,o+1);_.push({...u,step:d.step,children:d.children,omittedTasks:d.omittedTasks,omittedAttention:d.omittedAttention,childTools:new Map(d.tools.map(e=>[e.id,e]))})}else g.push(l);h.push({order:x,block:l,settled:!isActive(r.status)})}let S=subagentSteps(p);for(let t of S){if(!t.finalized)continue;let n=`subagent:${e.callId}:step:${t.key}`,r=this.#d(n,[t.reasoning,t.message,e.name],()=>{let n={kind:`subagent-step`,subagentCallId:e.callId,agentName:e.name,depth:1,body:t.message,live:!1};return t.reasoning.length>0&&(n.reasoning=t.reasoning),n});h.push({order:t.order,block:r,settled:!0})}let C=h.filter(e=>e.settled).sort((e,t)=>e.order-t.order).map(e=>e.block),w=S.at(-1),T={tools:g,rows:C,children:_,omittedTasks:y,omittedAttention:b,pending:u};return w!==void 0&&(T.step=firstLine(w.message)??`Thinking`),T}#d(e,t,n){let r=this.#e.get(e);if(r!==void 0&&sameKey(r.key,t))return r.block;let i={...n(),id:e};return this.#e.set(e,{key:t,block:i}),i}#f(e){let t=stripTerminalControls(userText(e));if(t.trim().length===0)return;let n=`user:${e.id}`;return this.#d(n,[t],()=>({kind:`user`,body:t,live:!1}))}#p(e,t,n,r){let i=e.parts[t];if(i?.type!==`text`&&i?.type!==`reasoning`||i.type===`reasoning`&&n.reasoning!==`full`)return;let a=stripTerminalControls(i.text).trim();if(a.length===0)return;let o=i.state===`streaming`&&r,s=`${i.type}:${i.id??`${e.id}:${t}`}`;return this.#d(s,[a,o],()=>i.type===`text`?{kind:`assistant`,body:a,live:o}:{kind:`reasoning`,body:a,collapsed:!1,live:o})}#m(e,t){return this.#d(`connection-auth:${e.interactionId}`,[e],()=>{let n=e.outcome??`required`,r=authorizationTerminalMessage(n);return{kind:`connection-auth`,title:`${stripTerminalControls(t.displayName??t.name)} · authorization · ${n}`,...formatAuthorization(e,t,r),preformatted:!0,live:r===void 0}})}#h(e,t,n,r,i){let a=n||isActive(t.status);return this.#d(`tool:${e.callId}`,[e,t.status,a,i.tools,i.subagentNames,r?.start,r?.complete],()=>{let n=this.#_(e.callId,e,t,i,{label:r?.start,completeLabel:r?.complete});return{...toolBlock(e,t,n),kind:`tool`,live:a,expanded:i.tools===`full`}})}#g(e,t,n){let{message:r,hint:i,detail:a}=t;return this.#d(e,[r,i,a],()=>{let e={kind:`error`,title:`Error`,body:stripTerminalControls(r),live:!1};return i!==void 0&&(e.hint=stripTerminalControls(i)),a!==void 0&&(e.detail=n.diagnosticsPath===void 0?stripTerminalControls(a):`details: ${n.diagnosticsPath}`),e})}#_(e,t,n,r,i={}){n.output!==void 0&&this.#t.observeRead(n.output);let a={};(i.isSubagent===!0||r.subagentNames?.includes(toolBaseName(t.name))===!0)&&(a.isSubagent=!0),i.label!==void 0&&(a.label=i.label),i.completeLabel!==void 0&&(a.completeLabel=i.completeLabel);let o=readWriteFileInput(t.name,t.input);if(o!==void 0){let t=this.#t.observeWrite({...o,callId:e});t!==void 0&&(a.previousContent=t);let r=writeExistedFlag(n.output);r!==void 0&&(a.existed=r)}return Object.keys(a).length>0?a:void 0}};function turnActivity(e,t){let n=activity(e.data.view);switch(n.kind){case`calling`:return`Running`;case`compacting`:return`Compacting`;case`waiting-on-tasks`:return waitingLabel(t);case`waiting-on-interaction`:{let e=n.interactions.flatMap(e=>e.request.signIn===void 0?[]:[e.request.signIn]);return e.length>0?signInLabel(e.map(e=>e.displayName??e.name)):`Waiting for input`}default:{let{previews:t}=snapshotState(e.conversation.view);return Object.values(t.parts).some(e=>e.kind===`text`)||Object.keys(t.calls).length>0?`Generating`:`Thinking`}}}function sameKey(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}export{ConversationTranscript,turnActivity};
|
|
1
|
+
import{FileContentCache}from"./file-content-cache.js";import{signInLabel,waitingLabel}from"./task-activity.js";import{TaskRecords}from"./task-records.js";import{agentDisplayName,agentTaskLabel,isPanelRoutedTool,readWriteFileInput,toolBaseName}from"./tool-presentation.js";import{activeToolSteps,authorizationTerminalMessage,endLine,firstLine,followUpLine,formatAuthorization,isActive,isToolCallRow,nestedTaskRecord,startLine,subagentSteps,taskCallsById,taskNeedsApproval,toolBlock,toolState,userText,writeExistedFlag}from"./transcript-parts.js";import{activity,callOutputSource}from"#protocol/session-projection/selectors.js";import{sessionTables,snapshotState}from"#protocol/session-projection/session-view.js";import{stripTerminalControls}from"#cli/ui/terminal-text.js";import{agentCallActivity,agentToolSession,taskCalls}from"#client/conversation-state.js";var ConversationTranscript=class{#e=new Map;#t=new FileContentCache;#n=new TaskRecords;#r=new Map;#i=[];#a=new Set;#o=[];reset(){this.#e=new Map,this.#t.clear(),this.#n.clear(),this.#r.clear(),this.#i=[],this.#a.clear(),this.#o=[]}get tasks(){return this.#o}taskLabel(e,t){let n=sessionTables(e.view).tasks[t];if(n===void 0)return;let r=taskCalls(e.view,t),i=r.findLast(e=>e.status!==`settled`)??r.at(-1),a=i===void 0?void 0:this.#n.get(i.callId);return a===void 0?n.kind===`agent`?agentTaskLabel(agentDisplayName(stripTerminalControls(n.name))):stripTerminalControls(n.name):a.kind===`agent`?agentTaskLabel(a.name):a.name}stopWorking(e){let t=[];for(let n of this.#n.values())n.ended||(n.ended=!0,t.push(endLine(n,{outcome:`interrupted`,status:`settled`},void 0,e.dot??`·`)));return this.#o=[],t}project(e,t){let{conversation:n,working:r}=e,i=Date.now(),a=[],o=taskCallsById(n),{toolLabels:s,withdrawn:c}=e.data,l=new Map(e.failures.flatMap(e=>e.turnId===void 0?[]:[[e.turnId,e]])),u=new Map;for(let[e,t]of n.messages.entries()){let n=t.metadata?.turnId;n!==void 0&&u.set(n,e)}let d=new Set,endTurn=(e,n)=>{if(n===void 0||u.get(n)!==e)return!1;let r=l.get(n);return r!==void 0&&(a.push(this.#g(`failure:${n}`,r,t)),d.add(n),!0)};for(let[d,f]of n.messages.entries()){if(f.role===`user`){let e=this.#f(f);e!==void 0&&a.push(e),endTurn(d,f.metadata?.turnId);continue}let p=f.parts.filter(e=>isToolCallRow(e)&&(e.state!==`streaming`||r)&&e.kind!==`control`&&!c(e.callId)&&!o.has(e.callId)&&!isPanelRoutedTool(e.name)),m=new Map(p.map(t=>[t,toolState(t,e.data.view)])),h=activeToolSteps(m);for(let[n,c]of f.parts.entries())if(c.type===`text`||c.type===`reasoning`){let e=this.#p(f,n,t,r);e!==void 0&&a.push(e)}else if(c.type===`interaction`)c.request.signIn!==void 0&&t.connectionAuth!==`hidden`&&a.push(this.#m(c,c.request.signIn));else if(c.type===`tool`){let n=o.get(c.callId);if(n!==void 0){let r=this.#c(c,n.task,s,t,i,e.data.view);r!==void 0&&a.push(r);continue}let r=m.get(c);if(r===void 0||t.tools===`hidden`)continue;let l=s(c.callId);a.push(this.#h(c,r,h.has(c.stepIndex),l,t))}let g=f.metadata?.turnId;endTurn(d,g)||g!==void 0&&!l.has(g)&&u.get(g)===d&&sessionTables(n.view).turns[g]?.outcome===`cancelled`&&a.push(this.#d(`cancelled:${g}`,[],()=>({kind:`notice`,body:`Cancelled.`,live:!1})))}let f=0;for(let n of e.failures){if(n.turnId!==void 0&&d.has(n.turnId))continue;let e=n.turnId===void 0?`failure:session:${f++}`:`failure:${n.turnId}`;a.push(this.#g(e,n,t))}let p=this.#s(a),m=this.#l(e,o,t,i);for(let e of m){let t=p.slice(-8).map(e=>e.id);this.#i.push({block:e,after:t}),this.#a.add(e.id),p.push(e)}return p}#s(e){let t=[...e];for(let{block:e,after:n}of this.#i){let r=t.length;for(let e=n.length-1;e>=0;--e){let i=t.findIndex(t=>t.id===n[e]);if(i!==-1){r=i+1;break}}t.splice(r,0,e)}return t}#c(e,t,n,r,i,a){if(!(t.kind===`agent`?r.subagents!==`hidden`:r.tools!==`hidden`))return;let o=n(e.callId)?.start,s=this.#n.record(e,t,o,i,a);return s.callId===e.callId?this.#d(`task:${s.callId}:start`,[s],()=>startLine(s)):this.#d(`task:${e.callId}:message`,[s],()=>followUpLine(s,e,o))}#l(e,t,n,r){let{conversation:i,working:a}=e,o=Object.values(sessionTables(i.view).turns).at(-1),s=!a&&(e.data.sessionFailed||o?.outcome===`cancelled`||o?.outcome===`failed`),c=[],l=[],u={remaining:128};for(let e of this.#n.values()){if(e.ended)continue;let o=t.get(e.callId)?.task;if(o===void 0)continue;let d=e.callIds.flatMap(e=>{let n=t.get(e)?.call;return n===void 0?[]:[n]}),f=d.at(-1),p=this.#u(e,o,d,i,n,u);if(n.subagents===`full`)for(let e of p.rows)this.#a.has(e.id)||c.push(e);let m=d.every(e=>e.status===`settled`);m&&(e.settledAtMs??=r);let h=m&&p.pending&&a;if(m&&!h||!m&&s){e.ended=!0,c.push(endLine(e,m?{...f,output:callOutputSource(sessionTables(i.view),f.callId)?.output}:{outcome:`interrupted`,status:`settled`},p.tools,n.dot??`·`));continue}let g={callId:e.callId,kind:e.kind,name:e.name,toolName:e.toolName,input:e.input,label:e.label,purpose:e.purpose,children:p.children,omittedTasks:p.omittedTasks,omittedAttention:p.omittedAttention,startedAtMs:e.startedAtMs,childTools:new Map(p.tools.map(e=>[e.id,e]))};p.step!==void 0&&(g.step=p.step),h&&(g.finishing=!0),l.push(g)}return this.#o=l,c}#u(e,t,n,r,i,a,o=0){let s=t.kind===`agent`?agentToolSession(r,t):void 0,c=s===void 0||s.observation.status===`not-followed`?void 0:s.observation.conversation;if(s===void 0||c===void 0)return{tools:[],rows:[],pending:!1};let l=n.flatMap(e=>{let t=agentCallActivity(r,e.callId);return t.status===`unlinked`?[]:t.sessions.filter(e=>e.sessionId===s.sessionId)}),u=s.observation.status===`following`&&l.some(e=>e.deliveries.some(({status:e})=>e!==`settled`)),d=new Set(l.flatMap(e=>e.turns.map(({turnId:e})=>e))),f=!sessionTables(r.view).children[s.sessionId]?.deliveries?.length,p=c.messages.filter(e=>e.role===`assistant`&&e.metadata?.turnId!==void 0&&(f||d.has(e.metadata.turnId))),m=taskCallsById(c),h=[],g=[],_=[],v=new Set,y=0,b=!1,x=0;for(let t of p)for(let n of t.parts){if(x+=1,!isToolCallRow(n)||n.kind===`control`)continue;let t=m.get(n.callId),r=toolState(n,sessionTables(c.view)),s=`subagent:${e.callId}:tool:${n.callId}`,l=this.#d(s,[n,r.status,e.name],()=>{let a=this.#_(n.callId,n,r,i,{isSubagent:t?.task.kind===`agent`});return{...toolBlock(n,r,a),kind:`subagent-tool`,subagentCallId:e.callId,agentName:e.name,depth:1,live:!1}}),u=t?.task.kind===`agent`?i.subagents!==`hidden`:i.tools!==`hidden`;if(t!==void 0&&t.call.status!==`settled`&&u){if(v.has(t.task.taskId))continue;if(v.add(t.task.taskId),o>=8||a.remaining<=0){y+=1,b||=r.status===`approval`||taskNeedsApproval(c,t.task);continue}--a.remaining;let s=`${e.callId}/${n.callId}`,u=this.#r.get(s);u===void 0&&(u=nestedTaskRecord(s,n,t.task,l),this.#r.set(s,u));let d=this.#u(u,t.task,taskCalls(c.view,t.task.taskId).filter(e=>e.status!==`settled`),c,i,a,o+1);_.push({...u,step:d.step,children:d.children,omittedTasks:d.omittedTasks,omittedAttention:d.omittedAttention,childTools:new Map(d.tools.map(e=>[e.id,e]))})}else g.push(l);h.push({order:x,block:l,settled:!isActive(r.status)})}let S=subagentSteps(p);for(let t of S){if(!t.finalized)continue;let n=`subagent:${e.callId}:step:${t.key}`,r=this.#d(n,[t.reasoning,t.message,e.name],()=>{let n={kind:`subagent-step`,subagentCallId:e.callId,agentName:e.name,depth:1,body:t.message,live:!1};return t.reasoning.length>0&&(n.reasoning=t.reasoning),n});h.push({order:t.order,block:r,settled:!0})}let C=h.filter(e=>e.settled).sort((e,t)=>e.order-t.order).map(e=>e.block),w=S.at(-1),T={tools:g,rows:C,children:_,omittedTasks:y,omittedAttention:b,pending:u};return w!==void 0&&(T.step=firstLine(w.message)??`Thinking`),T}#d(e,t,n){let r=this.#e.get(e);if(r!==void 0&&sameKey(r.key,t))return r.block;let i={...n(),id:e};return this.#e.set(e,{key:t,block:i}),i}#f(e){let t=stripTerminalControls(userText(e));if(t.trim().length===0)return;let n=`user:${e.id}`;return this.#d(n,[t],()=>({kind:`user`,body:t,live:!1}))}#p(e,t,n,r){let i=e.parts[t];if(i?.type!==`text`&&i?.type!==`reasoning`||i.type===`reasoning`&&n.reasoning!==`full`)return;let a=stripTerminalControls(i.text).trim();if(a.length===0)return;let o=i.state===`streaming`&&r,s=`${i.type}:${i.id??`${e.id}:${t}`}`;return this.#d(s,[a,o],()=>i.type===`text`?{kind:`assistant`,body:a,live:o}:{kind:`reasoning`,body:a,collapsed:!1,live:o})}#m(e,t){return this.#d(`connection-auth:${e.interactionId}`,[e],()=>{let n=e.outcome??`required`,r=authorizationTerminalMessage(n);return{kind:`connection-auth`,title:`${stripTerminalControls(t.displayName??t.name)} · authorization · ${n}`,...formatAuthorization(e,t,r),preformatted:!0,live:r===void 0}})}#h(e,t,n,r,i){let a=n||isActive(t.status);return this.#d(`tool:${e.callId}`,[e,t.status,a,i.tools,i.subagentNames,r?.start,r?.complete],()=>{let n=this.#_(e.callId,e,t,i,{label:r?.start,completeLabel:r?.complete});return{...toolBlock(e,t,n),kind:`tool`,live:a,expanded:i.tools===`full`}})}#g(e,t,n){let{message:r,hint:i,detail:a}=t;return this.#d(e,[r,i,a],()=>{let e={kind:`error`,title:`Error`,body:stripTerminalControls(r),live:!1};return i!==void 0&&(e.hint=stripTerminalControls(i)),a!==void 0&&(e.detail=n.diagnosticsPath===void 0?stripTerminalControls(a):`details: ${n.diagnosticsPath}`),e})}#_(e,t,n,r,i={}){if(n.output!==void 0&&this.#t.observeRead(n.output),toolBaseName(t.name)===`edit_file`)for(let e of[pathField(t.input),pathField(n.output)])e!==void 0&&this.#t.forget(e);let a={};(i.isSubagent===!0||r.subagentNames?.includes(toolBaseName(t.name))===!0)&&(a.isSubagent=!0),i.label!==void 0&&(a.label=i.label),i.completeLabel!==void 0&&(a.completeLabel=i.completeLabel);let o=readWriteFileInput(t.name,t.input);if(o!==void 0){let t=this.#t.observeWrite({...o,callId:e});t!==void 0&&(a.previousContent=t);let r=writeExistedFlag(n.output);r!==void 0&&(a.existed=r)}return Object.keys(a).length>0?a:void 0}};function pathField(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e.path;return typeof t==`string`&&t.length>0?t:void 0}function turnActivity(e,t){let n=activity(e.data.view);switch(n.kind){case`calling`:return`Running`;case`compacting`:return`Compacting`;case`waiting-on-tasks`:return waitingLabel(t);case`waiting-on-interaction`:{let e=n.interactions.flatMap(e=>e.request.signIn===void 0?[]:[e.request.signIn]);return e.length>0?signInLabel(e.map(e=>e.displayName??e.name)):`Waiting for input`}default:{let{previews:t}=snapshotState(e.conversation.view);return Object.values(t.parts).some(e=>e.kind===`text`)||Object.keys(t.calls).length>0?`Generating`:`Thinking`}}}function sameKey(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}export{ConversationTranscript,turnActivity};
|
|
@@ -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
|