eve 0.78.0 → 0.79.0
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 +14 -0
- package/dist/src/approval/definition.d.ts +42 -0
- package/dist/src/cli/commands/trace-detail.d.ts +2 -2
- package/dist/src/cli/commands/trace-detail.js +1 -1
- package/dist/src/cli/commands/trace.d.ts +1 -1
- package/dist/src/cli/commands/trace.js +1 -1
- package/dist/src/cli/dev/tui/traces/trace-conversation.d.ts +1 -1
- package/dist/src/cli/dev/tui/traces/trace-conversation.js +1 -1
- package/dist/src/cli/dev/tui/traces/trace-store.d.ts +1 -1
- package/dist/src/cli/dev/tui/traces/trace-store.js +1 -1
- package/dist/src/cli/dev/tui/traces/trace-view.d.ts +1 -1
- package/dist/src/cli/dev/tui/traces/trace-view.js +1 -1
- package/dist/src/cli/dev/tui/traces/trace-viewer-state.d.ts +1 -1
- package/dist/src/compiled/.vendor-stamp.json +3 -1
- package/dist/src/compiled/@eve/tracing/adapters/agent-transport.d.ts +8 -0
- package/dist/src/compiled/@eve/tracing/adapters/ai-sdk-payload.d.ts +15 -0
- package/dist/src/compiled/@eve/tracing/adapters/ai-sdk-telemetry.d.ts +14 -0
- package/dist/src/{tracing/agent-span-id-generator.d.ts → compiled/@eve/tracing/adapters/otel-ids.d.ts} +1 -1
- package/dist/src/compiled/@eve/tracing/adapters/otel.d.ts +33 -0
- package/dist/src/{tracing/agent-otel-content.d.ts → compiled/@eve/tracing/adapters/serialization.d.ts} +9 -3
- package/dist/src/compiled/@eve/tracing/agent-tracing.d.ts +84 -0
- package/dist/src/compiled/@eve/tracing/ai-sdk.d.ts +7 -0
- package/dist/src/compiled/@eve/tracing/ai-sdk.js +1 -0
- package/dist/src/compiled/@eve/tracing/capture.d.ts +5 -0
- package/dist/src/compiled/@eve/tracing/core/activation.d.ts +3 -0
- package/dist/src/compiled/@eve/tracing/core/attributes.d.ts +14 -0
- package/dist/src/{tracing/content-attributes.d.ts → compiled/@eve/tracing/core/content-policy.d.ts} +1 -1
- package/dist/src/compiled/@eve/tracing/core/context.d.ts +3 -0
- package/dist/src/compiled/@eve/tracing/core/delegation.d.ts +13 -0
- package/dist/src/compiled/@eve/tracing/core/mcp.d.ts +24 -0
- package/dist/src/compiled/@eve/tracing/core/scopes.d.ts +59 -0
- package/dist/src/compiled/@eve/tracing/core/snapshot.d.ts +7 -0
- package/dist/src/compiled/@eve/tracing/core/span-kinds.d.ts +12 -0
- package/dist/src/compiled/@eve/tracing/core/types.d.ts +292 -0
- package/dist/src/compiled/@eve/tracing/core/writer.d.ts +15 -0
- package/dist/src/compiled/@eve/tracing/delegation.d.ts +2 -0
- package/dist/src/compiled/@eve/tracing/delegation.js +1 -0
- package/dist/src/compiled/@eve/tracing/index.d.ts +6 -0
- package/dist/src/compiled/@eve/tracing/index.js +1 -0
- package/dist/src/compiled/@eve/tracing/operations.d.ts +96 -0
- package/dist/src/compiled/@eve/tracing/otel.d.ts +12 -0
- package/dist/src/compiled/@eve/tracing/otel.js +1 -0
- package/dist/src/compiled/@opentelemetry/api/index.d.ts +4 -0
- package/dist/src/compiled/@workflow/world-vercel/index.js +7 -7
- package/dist/src/compiled/_chunks/workflow/delegation-BqhZ398D.js +1 -0
- package/dist/src/compiled/_chunks/workflow/mcp-CrGp4EC8.js +5 -0
- package/dist/src/compiler/extension-compatibility.d.ts +6 -6
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/context/build-dynamic-tools.js +1 -1
- package/dist/src/context/dynamic-tool-lifecycle.js +1 -1
- package/dist/src/evals/assertions/collector.d.ts +4 -1
- package/dist/src/evals/assertions/collector.js +1 -1
- package/dist/src/evals/context.js +1 -1
- package/dist/src/evals/index.d.ts +1 -1
- package/dist/src/evals/runner/artifacts.js +1 -1
- package/dist/src/evals/runner/reporters/assertion-diagnostics.js +2 -2
- package/dist/src/evals/runner/reporters/assertion-scores.d.ts +11 -2
- package/dist/src/evals/runner/reporters/assertion-scores.js +1 -1
- package/dist/src/evals/runner/reporters/braintrust.js +1 -1
- package/dist/src/evals/runner/reporters/console.js +1 -1
- package/dist/src/evals/runner/reporters/datadog.js +2 -2
- package/dist/src/evals/runner/reporters/junit.js +1 -1
- package/dist/src/evals/runner/verdict.d.ts +2 -2
- package/dist/src/evals/runner/verdict.js +1 -1
- package/dist/src/evals/types.d.ts +22 -6
- package/dist/src/eve-channel/index.js +1 -1
- package/dist/src/eve-channel/stream-headers.d.ts +1 -0
- package/dist/src/eve-channel/stream-headers.js +1 -0
- package/dist/src/execution/agent-sessions/context.d.ts +1 -1
- package/dist/src/execution/agent-sessions/context.js +1 -1
- package/dist/src/execution/agent-sessions/remote.js +1 -1
- package/dist/src/execution/agent-sessions/steps.js +1 -1
- package/dist/src/execution/cancelled-model-call-batch.js +1 -1
- package/dist/src/execution/catalog/connection-entry.js +1 -1
- package/dist/src/execution/dynamic-workflow/tool.js +1 -1
- package/dist/src/execution/eve-workflow-attributes.js +1 -1
- package/dist/src/execution/invoke-tool.d.ts +1 -1
- package/dist/src/execution/invoke-tool.js +1 -1
- package/dist/src/execution/session/turn-step.js +1 -1
- package/dist/src/execution/tools/agent-router-workflow.js +1 -1
- package/dist/src/execution/workflow-runtime.js +1 -1
- package/dist/src/harness/execute-tool.d.ts +2 -2
- package/dist/src/harness/input-extraction.js +1 -1
- package/dist/src/instrumentation/ai-sdk-hook-bridge.js +1 -1
- package/dist/src/instrumentation/dispatch.js +1 -1
- package/dist/src/instrumentation/memory.d.ts +1 -4
- package/dist/src/instrumentation/memory.js +1 -1
- package/dist/src/instrumentation/principal-summary.js +1 -1
- package/dist/src/instrumentation/providers.js +1 -1
- package/dist/src/instrumentation/runtime-context.d.ts +1 -1
- package/dist/src/instrumentation/runtime.d.ts +3 -3
- package/dist/src/instrumentation/runtime.js +1 -1
- package/dist/src/instrumentation/session-init.js +1 -1
- package/dist/src/internal/application/stamped-package-version.js +1 -1
- package/dist/src/internal/authored-definition/approval.d.ts +3 -1
- package/dist/src/internal/authored-definition/approval.js +1 -1
- package/dist/src/internal/authored-definition/schema-backed.js +1 -1
- package/dist/src/internal/logging.js +1 -1
- package/dist/src/internal/nitro/host/local-tracing-runtime-plugin.js +1 -1
- package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
- package/dist/src/internal/nitro/routes/channel-request-instrumentation.d.ts +10 -31
- package/dist/src/internal/nitro/routes/channel-request-instrumentation.js +1 -1
- package/dist/src/internal/nitro/routes/route-invoke-tool.d.ts +1 -1
- package/dist/src/internal/workflow-bundle/dynamic-tool-transform.js +1 -1
- package/dist/src/public/channels/slack/hitl.js +1 -1
- package/dist/src/public/definitions/approval.d.ts +1 -1
- package/dist/src/public/instrumentation/otel.d.ts +2 -2
- package/dist/src/public/instrumentation/otel.js +1 -1
- package/dist/src/public/tools/approval/index.d.ts +1 -1
- package/dist/src/runtime/connections/mcp-tracing.d.ts +10 -18
- package/dist/src/runtime/connections/mcp-tracing.js +1 -1
- package/dist/src/runtime/resolve-tool.js +1 -1
- package/dist/src/runtime/types.d.ts +2 -2
- package/dist/src/self-modification/extension/subagents/agent/tools/inspect_trace.d.ts +12 -12
- package/dist/src/self-modification/extension/subagents/agent/tools/inspect_trace.js +1 -1
- package/dist/src/self-modification/extension/subagents/agent/tools/search_traces.d.ts +1 -1
- package/dist/src/self-modification/extension/subagents/agent/tools/search_traces.js +1 -1
- package/dist/src/self-modification/extension/trace-inspection.d.ts +1 -1
- package/dist/src/self-modification/extension/trace-inspection.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/shared/trace-policy.d.ts +3 -0
- package/dist/src/shared/trace-policy.js +1 -1
- package/dist/src/tools/definition.d.ts +3 -3
- package/dist/src/tools/durable-callbacks.d.ts +5 -3
- package/dist/src/tools/durable-callbacks.js +1 -1
- package/dist/src/tools/dynamic.d.ts +2 -2
- package/dist/src/tools/provided/ask-question-workflow.js +1 -1
- package/dist/src/tools/provided/sleep-workflow.js +1 -1
- package/dist/src/tools/workflow-definition.d.ts +2 -2
- package/dist/src/tracing/eve/agent-approval-instrumentation.d.ts +8 -0
- package/dist/src/tracing/eve/agent-approval-instrumentation.js +1 -0
- package/dist/src/tracing/{agent-channel-delivery-instrumentation.d.ts → eve/agent-channel-delivery-instrumentation.d.ts} +1 -1
- package/dist/src/tracing/{agent-channel-delivery-instrumentation.js → eve/agent-channel-delivery-instrumentation.js} +1 -1
- package/dist/src/tracing/eve/agent-invocation-coordinator.js +1 -0
- package/dist/src/tracing/eve/agent-memory-instrumentation.d.ts +12 -0
- package/dist/src/tracing/eve/agent-memory-instrumentation.js +1 -0
- package/dist/src/tracing/{agent-otel-provider.d.ts → eve/agent-otel-provider.d.ts} +6 -8
- package/dist/src/tracing/eve/agent-otel-provider.js +1 -0
- package/dist/src/tracing/eve/agent-tool-instrumentation.d.ts +44 -0
- package/dist/src/tracing/eve/agent-tool-instrumentation.js +1 -0
- package/dist/src/tracing/{agent-trace-context-store.d.ts → eve/agent-trace-context-store.d.ts} +8 -16
- package/dist/src/tracing/eve/agent-trace-context-store.js +1 -0
- package/dist/src/tracing/eve/agent-trace-context.js +1 -0
- package/dist/src/tracing/eve/agent-trace-state.d.ts +75 -0
- package/dist/src/tracing/{batch-span-processor.d.ts → eve/batch-span-processor.d.ts} +5 -1
- package/dist/src/tracing/eve/batch-span-processor.js +1 -0
- package/dist/src/tracing/{content-span-processor.d.ts → eve/content-span-processor.d.ts} +1 -1
- package/dist/src/tracing/eve/content-span-processor.js +1 -0
- package/dist/src/tracing/eve/delegation.d.ts +20 -0
- package/dist/src/tracing/eve/delegation.js +1 -0
- package/dist/src/tracing/eve/gateway.d.ts +16 -0
- package/dist/src/tracing/eve/gateway.js +1 -0
- package/dist/src/tracing/{install-instrumentation-runtime.d.ts → eve/install-instrumentation-runtime.d.ts} +1 -1
- package/dist/src/tracing/eve/install-instrumentation-runtime.js +1 -0
- package/dist/src/tracing/eve/invoke-tool-span.js +1 -0
- package/dist/src/tracing/eve/mcp.d.ts +29 -0
- package/dist/src/tracing/eve/mcp.js +1 -0
- package/dist/src/tracing/eve/metadata.d.ts +7 -0
- package/dist/src/tracing/eve/metadata.js +1 -0
- package/dist/src/tracing/eve/operation-input.d.ts +30 -0
- package/dist/src/tracing/eve/operation-input.js +1 -0
- package/dist/src/tracing/eve/otel-configuration.d.ts +70 -0
- package/dist/src/tracing/eve/otel-configuration.js +1 -0
- package/dist/src/tracing/{otel-declaration.d.ts → eve/otel-declaration.d.ts} +4 -11
- package/dist/src/tracing/eve/otel-declaration.js +1 -0
- package/dist/src/tracing/{otel-registration.d.ts → eve/otel-registration.d.ts} +12 -5
- package/dist/src/tracing/eve/otel-registration.js +1 -0
- package/dist/src/tracing/eve/policy.d.ts +15 -0
- package/dist/src/tracing/eve/policy.js +1 -0
- package/dist/src/tracing/eve/profile.d.ts +7 -0
- package/dist/src/tracing/eve/profile.js +1 -0
- package/dist/src/tracing/eve/session.d.ts +27 -0
- package/dist/src/tracing/eve/session.js +1 -0
- package/dist/src/tracing/{vercel-runtime-span-exporter.d.ts → eve/vercel-runtime-span-exporter.d.ts} +1 -1
- package/dist/src/tracing/local/agent-trace-span-processor.js +1 -0
- package/dist/src/tracing/local/inspection.d.ts +15 -0
- package/dist/src/tracing/local/inspection.js +1 -0
- package/dist/src/tracing/{local-instrumentation-runtime.d.ts → local/instrumentation-runtime.d.ts} +1 -1
- package/dist/src/tracing/local/instrumentation-runtime.js +1 -0
- package/dist/src/tracing/{local-trace-analysis.d.ts → local/trace-analysis.d.ts} +2 -2
- package/dist/src/tracing/{local-trace-analysis.js → local/trace-analysis.js} +1 -1
- package/dist/src/tracing/{local-trace-operations.d.ts → local/trace-operations.d.ts} +1 -1
- package/dist/src/tracing/{local-trace-query.d.ts → local/trace-query.d.ts} +1 -1
- package/dist/src/tracing/local/trace-reader.js +1 -0
- package/dist/src/tracing/{local-trace-retention.js → local/trace-retention.js} +1 -1
- package/dist/src/tracing/{local-trace-span-processor.js → local/trace-span-processor.js} +1 -1
- package/dist/src/tracing/{local-trace-summary.d.ts → local/trace-summary.d.ts} +1 -1
- package/dist/src/tracing/local/trace-summary.js +1 -0
- package/dist/src/tracing/{local-traces.d.ts → local/traces.d.ts} +1 -1
- package/dist/src/tracing/local/traces.js +1 -0
- package/docs/connections/mcp.mdx +22 -1
- package/docs/evals/assertions.mdx +50 -3
- package/docs/evals/overview.mdx +2 -1
- package/docs/evals/reporters.mdx +3 -1
- package/docs/tools/human-in-the-loop.md +23 -1
- package/package.json +2 -1
- package/dist/src/tracing/agent-approval-instrumentation.d.ts +0 -11
- package/dist/src/tracing/agent-approval-instrumentation.js +0 -1
- package/dist/src/tracing/agent-invocation-coordinator.js +0 -1
- package/dist/src/tracing/agent-memory-instrumentation.d.ts +0 -16
- package/dist/src/tracing/agent-memory-instrumentation.js +0 -1
- package/dist/src/tracing/agent-otel-attributes.d.ts +0 -10
- package/dist/src/tracing/agent-otel-attributes.js +0 -1
- package/dist/src/tracing/agent-otel-content.js +0 -4
- package/dist/src/tracing/agent-otel-provider.js +0 -2
- package/dist/src/tracing/agent-otel-runtime-context.d.ts +0 -36
- package/dist/src/tracing/agent-otel-runtime-context.js +0 -1
- package/dist/src/tracing/agent-otel-session-context.d.ts +0 -22
- package/dist/src/tracing/agent-otel-session-context.js +0 -1
- package/dist/src/tracing/agent-otel-turn-state.d.ts +0 -6
- package/dist/src/tracing/agent-otel-turn-state.js +0 -1
- package/dist/src/tracing/agent-otel-usage.d.ts +0 -10
- package/dist/src/tracing/agent-otel-usage.js +0 -1
- package/dist/src/tracing/agent-span-contract.d.ts +0 -34
- package/dist/src/tracing/agent-span-contract.js +0 -1
- package/dist/src/tracing/agent-span-error.js +0 -1
- package/dist/src/tracing/agent-span-id-generator.js +0 -1
- package/dist/src/tracing/agent-span-naming.d.ts +0 -1
- package/dist/src/tracing/agent-span-naming.js +0 -1
- package/dist/src/tracing/agent-tool-instrumentation.d.ts +0 -40
- package/dist/src/tracing/agent-tool-instrumentation.js +0 -1
- package/dist/src/tracing/agent-tool-span-context.d.ts +0 -16
- package/dist/src/tracing/agent-tool-span-context.js +0 -1
- package/dist/src/tracing/agent-trace-context-codec.d.ts +0 -15
- package/dist/src/tracing/agent-trace-context-codec.js +0 -1
- package/dist/src/tracing/agent-trace-context-store.js +0 -1
- package/dist/src/tracing/agent-trace-context.js +0 -1
- package/dist/src/tracing/agent-trace-span-processor.js +0 -1
- package/dist/src/tracing/agent-trace-state.d.ts +0 -91
- package/dist/src/tracing/batch-span-processor.js +0 -1
- package/dist/src/tracing/bounded-error.d.ts +0 -1
- package/dist/src/tracing/bounded-error.js +0 -1
- package/dist/src/tracing/content-attributes.js +0 -1
- package/dist/src/tracing/content-span-processor.js +0 -1
- package/dist/src/tracing/error-content-context.d.ts +0 -3
- package/dist/src/tracing/error-content-context.js +0 -1
- package/dist/src/tracing/install-instrumentation-runtime.js +0 -1
- package/dist/src/tracing/invoke-tool-span.js +0 -1
- package/dist/src/tracing/local-instrumentation-runtime.js +0 -1
- package/dist/src/tracing/local-trace-reader.js +0 -1
- package/dist/src/tracing/local-trace-summary.js +0 -1
- package/dist/src/tracing/local-traces.js +0 -1
- package/dist/src/tracing/otel-declaration.js +0 -1
- package/dist/src/tracing/otel-registration.js +0 -1
- package/dist/src/tracing/sampled-trace.d.ts +0 -4
- package/dist/src/tracing/sampled-trace.js +0 -1
- package/dist/src/tracing/suppress-tracing.d.ts +0 -2
- package/dist/src/tracing/suppress-tracing.js +0 -1
- package/dist/src/tracing/telemetry-budget.d.ts +0 -3
- package/dist/src/tracing/telemetry-budget.js +0 -1
- /package/dist/src/{tracing/agent-span-error.d.ts → compiled/@eve/tracing/adapters/otel-error.d.ts} +0 -0
- /package/dist/src/tracing/{agent-invocation-coordinator.d.ts → eve/agent-invocation-coordinator.d.ts} +0 -0
- /package/dist/src/tracing/{agent-trace-context.d.ts → eve/agent-trace-context.d.ts} +0 -0
- /package/dist/src/tracing/{agent-trace-state.js → eve/agent-trace-state.js} +0 -0
- /package/dist/src/tracing/{channel-audience-context.d.ts → eve/channel-audience-context.d.ts} +0 -0
- /package/dist/src/tracing/{channel-audience-context.js → eve/channel-audience-context.js} +0 -0
- /package/dist/src/tracing/{conversation-context.d.ts → eve/conversation-context.d.ts} +0 -0
- /package/dist/src/tracing/{conversation-context.js → eve/conversation-context.js} +0 -0
- /package/dist/src/tracing/{invoke-tool-span.d.ts → eve/invoke-tool-span.d.ts} +0 -0
- /package/dist/src/tracing/{span-export-policy.d.ts → eve/span-export-policy.d.ts} +0 -0
- /package/dist/src/tracing/{span-export-policy.js → eve/span-export-policy.js} +0 -0
- /package/dist/src/tracing/{vercel-runtime-span-exporter.js → eve/vercel-runtime-span-exporter.js} +0 -0
- /package/dist/src/tracing/{agent-trace-span-processor.d.ts → local/agent-trace-span-processor.d.ts} +0 -0
- /package/dist/src/tracing/{local-trace-discovery-index.d.ts → local/trace-discovery-index.d.ts} +0 -0
- /package/dist/src/tracing/{local-trace-discovery-index.js → local/trace-discovery-index.js} +0 -0
- /package/dist/src/tracing/{local-trace-operations.js → local/trace-operations.js} +0 -0
- /package/dist/src/tracing/{local-trace-query.js → local/trace-query.js} +0 -0
- /package/dist/src/tracing/{local-trace-reader.d.ts → local/trace-reader.d.ts} +0 -0
- /package/dist/src/tracing/{local-trace-retention.d.ts → local/trace-retention.d.ts} +0 -0
- /package/dist/src/tracing/{local-trace-span-processor.d.ts → local/trace-span-processor.d.ts} +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type McpLifecycle } from "./mcp.js";
|
|
2
|
+
import type { AgentTelemetry, CaptureDecision, ContentSerializer, ExecutionContext, Operation, ScopeData, ScopeIdentity, ScopeRecord, ScopeTerminal, TraceErrorHandler, TraceLink, TraceReference, Usage } from "./types.js";
|
|
3
|
+
export interface ChildOptions {
|
|
4
|
+
readonly links?: readonly TraceLink[];
|
|
5
|
+
readonly startTimeMs?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface LiveOperation extends Operation {
|
|
8
|
+
child(data: ScopeData, key?: string, options?: ChildOptions): Promise<LiveOperation>;
|
|
9
|
+
/** Returns an unsettled child with this identity, without starting one. */
|
|
10
|
+
find(data: ScopeData): LiveOperation | undefined;
|
|
11
|
+
/** Unsettled children, in start order. */
|
|
12
|
+
readonly children: readonly LiveOperation[];
|
|
13
|
+
usage(usage: Usage, key?: string): Promise<void>;
|
|
14
|
+
/** Carries a model call's messages up to its turn: the first input and the latest output. */
|
|
15
|
+
turnContent(content: {
|
|
16
|
+
readonly input?: string;
|
|
17
|
+
readonly output?: string;
|
|
18
|
+
}): void;
|
|
19
|
+
error(error?: unknown, type?: string): void;
|
|
20
|
+
/** Replaces the host context for this operation and its descendants. */
|
|
21
|
+
useContext(context: ExecutionContext): void;
|
|
22
|
+
/** Fills in a deferred operation's details from a later call with the same identity. */
|
|
23
|
+
refine(data: ScopeData, startTimeMs?: number): void;
|
|
24
|
+
/** Lowers capture for this operation and its children, and drops retained content it no longer allows. */
|
|
25
|
+
narrow(capture: CaptureDecision): void;
|
|
26
|
+
/** Completes this operation, or closes the open descendants of a finished one. */
|
|
27
|
+
release(result: ScopeTerminal): Promise<void>;
|
|
28
|
+
/** Finished, with no unfinished descendants. */
|
|
29
|
+
readonly settled: boolean;
|
|
30
|
+
readonly callId?: string;
|
|
31
|
+
readonly mcp: McpLifecycle;
|
|
32
|
+
record(): ScopeRecord;
|
|
33
|
+
}
|
|
34
|
+
export declare function createScopes(input: {
|
|
35
|
+
readonly telemetry: AgentTelemetry;
|
|
36
|
+
readonly serializer: ContentSerializer;
|
|
37
|
+
readonly durable: boolean;
|
|
38
|
+
readonly onError?: TraceErrorHandler;
|
|
39
|
+
}): {
|
|
40
|
+
/** Starts a turn tree. Durable turns reserve their IDs from `key`. */
|
|
41
|
+
start(facts: {
|
|
42
|
+
identity: ScopeIdentity;
|
|
43
|
+
key: string;
|
|
44
|
+
capture: CaptureDecision;
|
|
45
|
+
data: ScopeData;
|
|
46
|
+
parent?: TraceReference;
|
|
47
|
+
reference?: TraceReference;
|
|
48
|
+
startTimeMs?: number;
|
|
49
|
+
links?: readonly TraceLink[];
|
|
50
|
+
context?: ExecutionContext;
|
|
51
|
+
onChange?: () => Promise<void>;
|
|
52
|
+
}): Promise<LiveOperation>;
|
|
53
|
+
/** Rebuilds a tree from a checkpoint, or returns `undefined` for an unusable one. */
|
|
54
|
+
restore(snapshot: unknown, options?: {
|
|
55
|
+
capture?: CaptureDecision;
|
|
56
|
+
context?: ExecutionContext;
|
|
57
|
+
onChange?: () => Promise<void>;
|
|
58
|
+
}): Promise<LiveOperation | undefined>;
|
|
59
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ScopeRecord } from "./types.js";
|
|
2
|
+
import type { ContentSerializer } from "./types.js";
|
|
3
|
+
import type { TraceSnapshot } from "./types.js";
|
|
4
|
+
export declare function boundedSerializer(serializer: ContentSerializer, onError?: import("./types.js").TraceErrorHandler): ContentSerializer;
|
|
5
|
+
export declare function traceSnapshot(value: unknown): TraceSnapshot;
|
|
6
|
+
export declare function validSnapshot(value: unknown, maxBytes?: number, depth?: number): value is ScopeRecord;
|
|
7
|
+
export declare function snapshotRecord(record: ScopeRecord, serializer: ContentSerializer): ScopeRecord;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const invocationName: (name?: string) => string;
|
|
2
|
+
export declare function applyAttributes(span: {
|
|
3
|
+
setAttribute(key: string, value: Exclude<Attributes[string], undefined>): unknown;
|
|
4
|
+
}, attributes: Attributes): void;
|
|
5
|
+
import type { ContentSerializer } from "./types.js";
|
|
6
|
+
import type { ScopeData, ScopeRecord, ScopeTerminal } from "./types.js";
|
|
7
|
+
import type { Attributes, CaptureDecision, PreparedSpan } from "./types.js";
|
|
8
|
+
import type { TraceOperation } from "./writer.js";
|
|
9
|
+
export declare function parentKinds(data: ScopeData): readonly ScopeData["type"][];
|
|
10
|
+
export declare function prepareScope(record: Omit<ScopeRecord, "reference">, serializer: ContentSerializer): PreparedSpan;
|
|
11
|
+
export declare function completeScope(span: TraceOperation, data: ScopeData, result: ScopeTerminal, capture: CaptureDecision, startTimeMs: number, serializer: ContentSerializer): void;
|
|
12
|
+
export declare function capturedScopeData(data: ScopeData, capture: CaptureDecision): ScopeData;
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
export type AttributeValue = string | number | boolean | (string | null | undefined)[] | (number | null | undefined)[] | (boolean | null | undefined)[];
|
|
2
|
+
export type Attributes = Readonly<Record<string, AttributeValue | undefined>>;
|
|
3
|
+
export type TraceJson = null | boolean | number | string | readonly TraceJson[] | {
|
|
4
|
+
readonly [key: string]: TraceJson;
|
|
5
|
+
};
|
|
6
|
+
declare const traceSnapshotBrand: unique symbol;
|
|
7
|
+
export type TraceSnapshot = TraceJson & {
|
|
8
|
+
readonly [traceSnapshotBrand]: true;
|
|
9
|
+
};
|
|
10
|
+
export type SpanType = "activation" | "step" | "model" | "tool" | "approval" | "memory" | "channelRequest" | "mcp";
|
|
11
|
+
export type SpanKind = "INTERNAL" | "CLIENT" | "SERVER" | "PRODUCER" | "CONSUMER";
|
|
12
|
+
/** Host-owned process-local context. Never stored in a checkpoint. */
|
|
13
|
+
export type ExecutionContext = object;
|
|
14
|
+
export interface TraceReference {
|
|
15
|
+
readonly traceId: string;
|
|
16
|
+
readonly spanId: string;
|
|
17
|
+
readonly traceFlags: number;
|
|
18
|
+
readonly isRemote?: boolean;
|
|
19
|
+
readonly tracestate?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface CaptureDecision {
|
|
22
|
+
readonly emit: boolean;
|
|
23
|
+
readonly recordInputs: boolean;
|
|
24
|
+
readonly recordOutputs: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface TraceErrorContext {
|
|
27
|
+
readonly phase: "start" | "serialize" | "complete" | "context" | "restore" | "checkpoint";
|
|
28
|
+
readonly operation?: SpanType;
|
|
29
|
+
readonly reference?: TraceReference;
|
|
30
|
+
}
|
|
31
|
+
export type TraceErrorHandler = (error: unknown, context: TraceErrorContext) => void;
|
|
32
|
+
export interface TraceLink {
|
|
33
|
+
readonly context: TraceReference;
|
|
34
|
+
readonly relationship: string;
|
|
35
|
+
}
|
|
36
|
+
export interface PreparedSpan {
|
|
37
|
+
readonly type: SpanType;
|
|
38
|
+
readonly operationId: string;
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly kind?: SpanKind;
|
|
41
|
+
readonly attributes: Attributes;
|
|
42
|
+
readonly parent?: TraceReference;
|
|
43
|
+
readonly root?: boolean;
|
|
44
|
+
readonly startTimeMs?: number;
|
|
45
|
+
readonly links?: readonly TraceLink[];
|
|
46
|
+
}
|
|
47
|
+
export interface SpanWriter {
|
|
48
|
+
readonly reference: TraceReference;
|
|
49
|
+
setAttribute(key: string, value: AttributeValue): void;
|
|
50
|
+
addEvent(name: string, attributes?: Attributes, timeMs?: number): void;
|
|
51
|
+
fail(error?: unknown, errorType?: string): void;
|
|
52
|
+
setStatus(code: "UNSET" | "OK" | "ERROR"): void;
|
|
53
|
+
end(timeMs?: number): void;
|
|
54
|
+
}
|
|
55
|
+
/** Span output and context propagation used by agent tracing. */
|
|
56
|
+
export interface AgentTelemetry {
|
|
57
|
+
/** Starts a span. A `reference` requests that exact trace and span ID. */
|
|
58
|
+
startSpan(span: PreparedSpan, options?: {
|
|
59
|
+
readonly reference?: TraceReference;
|
|
60
|
+
readonly context?: ExecutionContext;
|
|
61
|
+
}): SpanWriter;
|
|
62
|
+
/** Returns the operation active in the current execution context. */
|
|
63
|
+
active(): ActiveOperation | undefined;
|
|
64
|
+
/** Runs `execute` with `operation` as the active trace context. */
|
|
65
|
+
run<T>(operation: ActiveOperation, execute: () => T, context?: ExecutionContext): T;
|
|
66
|
+
/** Runs `execute` without creating spans. */
|
|
67
|
+
suppressed?<T>(execute: () => T): T;
|
|
68
|
+
/** Decides whether a durable turn's trace is recorded. Defaults to recording. */
|
|
69
|
+
samples?(traceId: string, span: PreparedSpan): boolean;
|
|
70
|
+
/** Derives stable IDs from keys. Present only when `startSpan` honors `reference`. */
|
|
71
|
+
readonly ids?: {
|
|
72
|
+
traceId(key: string): string;
|
|
73
|
+
spanId(key: string): string;
|
|
74
|
+
};
|
|
75
|
+
forceFlush(): Promise<void>;
|
|
76
|
+
shutdown(): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
/** Durable storage for in-flight turns. Values are JSON; keys are chosen by the library. */
|
|
79
|
+
export interface TraceCheckpointer {
|
|
80
|
+
get(key: string): unknown | PromiseLike<unknown>;
|
|
81
|
+
set(key: string, value: TraceSnapshot): void | PromiseLike<void>;
|
|
82
|
+
delete(key: string): void | PromiseLike<void>;
|
|
83
|
+
}
|
|
84
|
+
export interface ActiveOperation {
|
|
85
|
+
readonly type: SpanType;
|
|
86
|
+
readonly reference: TraceReference;
|
|
87
|
+
readonly capture: CaptureDecision;
|
|
88
|
+
readonly mcp?: import("./mcp.js").McpLifecycle;
|
|
89
|
+
}
|
|
90
|
+
export interface MappingContext {
|
|
91
|
+
readonly type: SpanType;
|
|
92
|
+
readonly operationId: string;
|
|
93
|
+
}
|
|
94
|
+
export interface OutputMapping {
|
|
95
|
+
attributes(span: MappingContext, attributes: Attributes): Attributes;
|
|
96
|
+
link(span: MappingContext, link: TraceLink): Attributes;
|
|
97
|
+
}
|
|
98
|
+
export interface RunIdentity {
|
|
99
|
+
readonly conversationId: string;
|
|
100
|
+
readonly runId: string;
|
|
101
|
+
readonly turnId: string;
|
|
102
|
+
}
|
|
103
|
+
export interface FrameworkIdentity {
|
|
104
|
+
readonly name: string;
|
|
105
|
+
readonly version?: string;
|
|
106
|
+
}
|
|
107
|
+
export interface Usage {
|
|
108
|
+
readonly costUsd?: number;
|
|
109
|
+
readonly inputTokens?: number;
|
|
110
|
+
readonly outputTokens?: number;
|
|
111
|
+
readonly inputTokenDetails?: {
|
|
112
|
+
readonly cacheReadTokens?: number;
|
|
113
|
+
readonly cacheWriteTokens?: number;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** `subagent-call` and `remote-agent-call` delegate to another agent. */
|
|
117
|
+
export type ToolKind = string;
|
|
118
|
+
export interface ContentSerializer {
|
|
119
|
+
json(value: unknown): string | undefined;
|
|
120
|
+
text(value: string): string | undefined;
|
|
121
|
+
inputMessages(value: unknown): string | undefined;
|
|
122
|
+
instructions(value: unknown): string | undefined;
|
|
123
|
+
toolDefinitions(value: unknown): string | undefined;
|
|
124
|
+
outputMessages(value: readonly ContentPart[], finishReason: string): string | undefined;
|
|
125
|
+
toolResults(value: readonly Record<string, unknown>[]): string | undefined;
|
|
126
|
+
}
|
|
127
|
+
export interface ModelResult {
|
|
128
|
+
readonly usage: Usage;
|
|
129
|
+
readonly responseId?: string;
|
|
130
|
+
readonly responseModelId?: string;
|
|
131
|
+
readonly finishReason: string;
|
|
132
|
+
readonly content?: readonly ContentPart[];
|
|
133
|
+
}
|
|
134
|
+
export interface ScopeIdentity extends RunIdentity {
|
|
135
|
+
readonly agentName?: string;
|
|
136
|
+
readonly framework?: FrameworkIdentity;
|
|
137
|
+
}
|
|
138
|
+
export interface TurnMetadata {
|
|
139
|
+
readonly attributes?: Attributes;
|
|
140
|
+
readonly sequence: number;
|
|
141
|
+
readonly subagent?: boolean;
|
|
142
|
+
readonly subagentName?: string;
|
|
143
|
+
readonly parentCallId?: string;
|
|
144
|
+
readonly parentRunId?: string;
|
|
145
|
+
readonly channel?: {
|
|
146
|
+
kind?: string;
|
|
147
|
+
origin?: string;
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
export interface StepOptions {
|
|
151
|
+
readonly index: number;
|
|
152
|
+
readonly attempt?: number;
|
|
153
|
+
readonly channel?: {
|
|
154
|
+
kind?: string;
|
|
155
|
+
origin?: string;
|
|
156
|
+
};
|
|
157
|
+
readonly runtimeContext?: Readonly<Record<string, unknown>>;
|
|
158
|
+
}
|
|
159
|
+
export interface ModelOptions {
|
|
160
|
+
readonly provider: string;
|
|
161
|
+
readonly modelId: string;
|
|
162
|
+
readonly messages?: readonly unknown[];
|
|
163
|
+
readonly instructions?: unknown;
|
|
164
|
+
/** Tools offered to the model, recorded as `gen_ai.tool.definitions`. */
|
|
165
|
+
readonly tools?: unknown;
|
|
166
|
+
readonly runtimeContext?: Readonly<Record<string, unknown>>;
|
|
167
|
+
}
|
|
168
|
+
export interface ToolOptions {
|
|
169
|
+
readonly callId: string;
|
|
170
|
+
readonly name: string;
|
|
171
|
+
readonly kind?: ToolKind;
|
|
172
|
+
readonly arguments?: unknown;
|
|
173
|
+
}
|
|
174
|
+
export type ScopeData = {
|
|
175
|
+
readonly type: "activation";
|
|
176
|
+
readonly options: TurnMetadata;
|
|
177
|
+
} | {
|
|
178
|
+
readonly type: "step";
|
|
179
|
+
readonly options: StepOptions;
|
|
180
|
+
} | {
|
|
181
|
+
readonly type: "model";
|
|
182
|
+
readonly options: ModelOptions;
|
|
183
|
+
} | {
|
|
184
|
+
readonly type: "tool";
|
|
185
|
+
readonly options: ToolOptions;
|
|
186
|
+
} | {
|
|
187
|
+
readonly type: "approval";
|
|
188
|
+
readonly options: {
|
|
189
|
+
requestId: string;
|
|
190
|
+
request?: unknown;
|
|
191
|
+
callId: string;
|
|
192
|
+
toolName: string;
|
|
193
|
+
};
|
|
194
|
+
} | {
|
|
195
|
+
readonly type: "memory";
|
|
196
|
+
readonly options: {
|
|
197
|
+
operation: "search_memory" | "upsert_memory";
|
|
198
|
+
phase: string;
|
|
199
|
+
slot: string;
|
|
200
|
+
storeId: string;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
export interface ScopeTerminal {
|
|
204
|
+
readonly outcome?: string;
|
|
205
|
+
/** Ends the operation without recording an outcome, when the host never learned one. */
|
|
206
|
+
readonly outcomeUnknown?: boolean;
|
|
207
|
+
readonly failed?: boolean;
|
|
208
|
+
readonly error?: unknown;
|
|
209
|
+
readonly errorCode?: string;
|
|
210
|
+
readonly output?: unknown;
|
|
211
|
+
readonly response?: unknown;
|
|
212
|
+
readonly usage?: Usage;
|
|
213
|
+
readonly model?: ModelResult;
|
|
214
|
+
readonly recordCount?: number;
|
|
215
|
+
readonly records?: readonly {
|
|
216
|
+
id?: string;
|
|
217
|
+
content: string;
|
|
218
|
+
}[];
|
|
219
|
+
readonly endTimeMs?: number;
|
|
220
|
+
}
|
|
221
|
+
export interface ScopeRecord {
|
|
222
|
+
readonly version?: 1;
|
|
223
|
+
readonly finished?: boolean;
|
|
224
|
+
/** Write token used to detect a checkpoint changed by another process. */
|
|
225
|
+
readonly revision?: string;
|
|
226
|
+
readonly key: string;
|
|
227
|
+
readonly identity: ScopeIdentity;
|
|
228
|
+
readonly data: ScopeData;
|
|
229
|
+
readonly reference: TraceReference;
|
|
230
|
+
readonly parent?: TraceReference;
|
|
231
|
+
readonly attempt?: {
|
|
232
|
+
readonly index: number;
|
|
233
|
+
readonly attempt: number;
|
|
234
|
+
};
|
|
235
|
+
readonly capture: CaptureDecision;
|
|
236
|
+
readonly startTimeMs: number;
|
|
237
|
+
readonly links?: readonly TraceLink[];
|
|
238
|
+
readonly usage?: Usage;
|
|
239
|
+
readonly usageKeys?: readonly string[];
|
|
240
|
+
readonly attributes?: Attributes;
|
|
241
|
+
readonly childSequence?: number;
|
|
242
|
+
readonly children?: readonly ScopeRecord[];
|
|
243
|
+
readonly terminal?: ScopeTerminal;
|
|
244
|
+
}
|
|
245
|
+
export interface Operation {
|
|
246
|
+
child(data: ScopeData, key?: string): Promise<Operation>;
|
|
247
|
+
waitUntil(completion: Promise<void>): void;
|
|
248
|
+
readonly type: ScopeData["type"];
|
|
249
|
+
readonly reference: TraceReference;
|
|
250
|
+
readonly parent?: TraceReference;
|
|
251
|
+
readonly startTimeMs: number;
|
|
252
|
+
readonly capture: CaptureDecision;
|
|
253
|
+
readonly finished: boolean;
|
|
254
|
+
snapshot(): TraceSnapshot;
|
|
255
|
+
run<T>(execute: () => T, ceiling?: CaptureDecision): T;
|
|
256
|
+
attributes(attributes: Attributes): void;
|
|
257
|
+
update(input: {
|
|
258
|
+
attributes?: Attributes;
|
|
259
|
+
links?: readonly TraceLink[];
|
|
260
|
+
}): void;
|
|
261
|
+
complete(result?: ScopeTerminal & {
|
|
262
|
+
errorType?: string;
|
|
263
|
+
result?: ModelResult;
|
|
264
|
+
}): Promise<void>;
|
|
265
|
+
fail(error: unknown): Promise<void>;
|
|
266
|
+
modelCall(input: ModelOptions, key?: string): Promise<Operation>;
|
|
267
|
+
}
|
|
268
|
+
export type ContentPart = {
|
|
269
|
+
readonly type: "text";
|
|
270
|
+
readonly text: string;
|
|
271
|
+
} | {
|
|
272
|
+
readonly type: "reasoning";
|
|
273
|
+
readonly text: string;
|
|
274
|
+
} | {
|
|
275
|
+
readonly type: "tool-call";
|
|
276
|
+
readonly callId: string;
|
|
277
|
+
readonly toolName: string;
|
|
278
|
+
readonly input: unknown;
|
|
279
|
+
} | {
|
|
280
|
+
readonly type: "tool-result";
|
|
281
|
+
readonly callId: string;
|
|
282
|
+
readonly toolName: string;
|
|
283
|
+
readonly input: unknown;
|
|
284
|
+
readonly output: unknown;
|
|
285
|
+
} | {
|
|
286
|
+
readonly type: "tool-error";
|
|
287
|
+
readonly callId: string;
|
|
288
|
+
readonly toolName: string;
|
|
289
|
+
readonly input: unknown;
|
|
290
|
+
readonly error: unknown;
|
|
291
|
+
};
|
|
292
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PreparedSpan, SpanWriter, ExecutionContext, AgentTelemetry, TraceReference, CaptureDecision, TraceErrorHandler } from "./types.js";
|
|
2
|
+
export interface TraceOperation extends SpanWriter {
|
|
3
|
+
readonly capture: CaptureDecision;
|
|
4
|
+
readonly finished: boolean;
|
|
5
|
+
run<T>(execute: () => T): T;
|
|
6
|
+
/** Lowers what the span accepts from now on. */
|
|
7
|
+
narrow(capture: CaptureDecision): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function createSpanWriter(input: {
|
|
10
|
+
telemetry: Pick<AgentTelemetry, "startSpan" | "run" | "suppressed">;
|
|
11
|
+
onError?: TraceErrorHandler;
|
|
12
|
+
}): {
|
|
13
|
+
start: (span: PreparedSpan, capture: CaptureDecision, host?: ExecutionContext, reserved?: TraceReference) => TraceOperation;
|
|
14
|
+
startReserved: (span: PreparedSpan, reference: TraceReference, capture: CaptureDecision, host?: ExecutionContext) => TraceOperation;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"../../_chunks/workflow/delegation-BqhZ398D.js";const n=`x-agent-tracing`,r=new TextEncoder;function i(e,t){return typeof e==`string`&&e.length===t&&/^[a-f0-9]+$/u.test(e)&&!/^0+$/u.test(e)}function a(e,i){return(a,o)=>{let s=t();if(s===void 0)return e(a,o);let c=JSON.stringify(s);if(r.encode(c).length>i)return e(a,o);let l=new Headers(o?.headers??(a instanceof Request?a.headers:void 0));return l.set(n,c),e(a,{...o,headers:l,redirect:`error`})}}function o(t,a,o,s){let c=t.get(n);if(c===null||c.length>s||r.encode(c).length>s)return o();let l,u=(()=>{try{return l=JSON.parse(c),typeof l!=`object`||!l||![l.conversationId,l.parentRunId,l.parentCallId,l.agentName].every(e=>typeof e==`string`&&e.length>0&&e.length<=1024)||!i(l.caller.traceId,32)||!i(l.caller.spanId,16)||![0,1].includes(l.caller.traceFlags)||l.caller.tracestate!==void 0&&(typeof l.caller.tracestate!=`string`||l.caller.tracestate.length>512)||![l.capture.emit,l.capture.recordInputs,l.capture.recordOutputs].every(e=>typeof e==`boolean`)||!a(l)?void 0:l}catch{return}})();if(u===void 0)return o();let d={...u,remote:!0,capture:{emit:u.capture.emit&&u.caller.traceFlags===1,recordInputs:u.capture.emit&&u.caller.traceFlags===1&&u.capture.recordInputs,recordOutputs:u.capture.emit&&u.caller.traceFlags===1&&u.capture.recordOutputs}};return e(d,()=>o(d))}function s(t=(e,t)=>globalThis.fetch(e,t)){let n=8192;return{fetch:a(t,n),transport:e=>a(e,n),receive(e,t,r){return o(e,t,r,n)},resume(t,n){return e(t,()=>n(t))}}}export{s as createAgentDelegationTransport,t as currentAgentHandoff,e as withAgentHandoff};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createAgentTracing, type AgentTracing, type AgentTracingOptions, type AgentMemoryTracing, type TurnInput, type ResumeInput, } from "./agent-tracing.js";
|
|
2
|
+
export { otelTelemetry, type OtelTelemetryOptions } from "./adapters/otel.js";
|
|
3
|
+
export { AgentSpanIdGenerator } from "./adapters/otel-ids.js";
|
|
4
|
+
export type { Operation, TurnOperation, AttemptInput, AttemptOperation, ToolInput, ModelOperation, ToolOperation, ApprovalOperation, MemoryOperation, ModelCallReturn, ModelStreamReturn, } from "./operations.js";
|
|
5
|
+
export type { ActiveOperation, AgentTelemetry, Attributes, CaptureDecision, ContentPart, ContentSerializer, ExecutionContext, MappingContext, OutputMapping, PreparedSpan, SpanWriter, TraceCheckpointer, TraceErrorContext, TraceErrorHandler, TraceLink, TraceReference, TraceSnapshot, Usage, } from "./core/types.js";
|
|
6
|
+
export { currentCapture } from "./capture.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as e,g as t,i as n,l as r,m as i,n as a,o,r as s,s as c,t as l,u,v as d}from"../../_chunks/workflow/mcp-CrGp4EC8.js";import{n as f,t as p}from"../../_chunks/workflow/delegation-BqhZ398D.js";import{createHash as m,randomBytes as h,randomUUID as g}from"node:crypto";var _=class{#e;#t;allocateSpanId(){return y(16)}deriveSpanId(e){return v(e)}deriveTraceId(e){let t=m(`sha256`).update(e).digest(`hex`).slice(0,32);return/^0+$/u.test(t)?`00000000000000000000000000000001`:t}generateSpanId(){let e=this.#e;return e===void 0?y(16):(this.#e=void 0,e)}generateTraceId(){let e=this.#t;return e===void 0?y(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 v(e){let t=m(`sha256`).update(e).digest(`hex`).slice(0,16);return/^0+$/u.test(t)?`0000000000000001`:t}function y(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 b(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 x(e){function n(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=u(r.attributes,i)??r.attributes,c=i.emit?n(()=>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},d=!1;return{reference:l,get capture(){return i},narrow(e){i=t(i,e)},get finished(){return d},setAttribute(e,t){let r=u({[e]:t},i);!d&&(r===void 0||e in r)&&n(()=>c?.setAttribute(e,r===void 0?t:r[e]))},addEvent(e,t,r){d||n(()=>c?.addEvent(e,t===void 0?void 0:u(t,i)??t,r))},fail(e,t){d||n(()=>c?.fail(i.recordOutputs?e:void 0,t??(e instanceof Error?e.name:void 0)))},setStatus(e){d||n(()=>c?.setStatus(e))},end(e){d||(d=!0,n(()=>c?.end(e)))},run(t){return d?t():b(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 S=32768,C=65536;function w(e,t){function n(n,r){try{let t=Reflect.apply(e[n],e,r);return t===void 0||new TextEncoder().encode(t).length>S?void 0:t}catch(e){try{t?.(e,{phase:`serialize`})}catch{}return}}return{json:e=>n(`json`,[e]),text:e=>n(`text`,[e]),inputMessages:e=>n(`inputMessages`,[e]),instructions:e=>n(`instructions`,[e]),toolDefinitions:e=>n(`toolDefinitions`,[e]),outputMessages:(e,t)=>n(`outputMessages`,[e,t]),toolResults:e=>n(`toolResults`,[e])}}function T(e){return new TextEncoder().encode(JSON.stringify({...e,children:void 0})).length}function ee(e){return JSON.parse(JSON.stringify(e))}function E(e,t=C,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=>E(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||T(r)>t)}catch{return!1}}function D(e,t){let n=e.terminal;e={...e,children:e.children?.map(n=>D({...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:u(e.attributes??{},e.capture)??e.attributes};let r=s(e.data,e.capture),i;try{i=t.json(r)}catch{}let a=()=>{let t=s(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:u(e.attributes??{},{recordInputs:!1,recordOutputs:!1})??e.attributes}))};if(i===void 0||new TextEncoder().encode(i).length>S)return a();try{let t=JSON.parse(JSON.stringify({...e,version:1,data:JSON.parse(i)}));return T(t)<=C?t:a()}catch{return a()}}const O=1e4,k={emit:!1,recordInputs:!1,recordOutputs:!1},te=new Set([`activation`,`tool`,`approval`]),ne=new Set([`tool`,`approval`]);function A(e){return encodeURIComponent(String(e))}function j(e){switch(e.type){case`step`:return`step:${A(e.options.index)}:${A(e.options.attempt??0)}`;case`tool`:return`tool:${A(e.options.callId)}`;case`approval`:return`approval:${A(e.options.requestId)}`;default:return}}function M(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 N(e){let i=e.telemetry,d=w(e.serializer,e.onError),p=x({telemetry:i,onError:e.onError}),m=(t,n)=>{try{e.onError?.(t,n)}catch{}};function g(t,n,r,a,o){let s=i.ids;if(e.durable&&s!==void 0&&t.type!==`model`&&t.type!==`memory`){if(t.type===`activation`&&r!==void 0)return{traceId:r.traceId,spanId:s.spanId(n),traceFlags:o.emit?r.traceFlags&1:0};if(t.type===`activation`){let e=s.traceId(n);return{traceId:e,spanId:s.spanId(n),traceFlags:o.emit&&(i.samples?.(e,a)??!0)?1:0}}return r===void 0?void 0:{...r,spanId:s.spanId(n),isRemote:!1}}}async function _(e,t,n,r,i,a,o){try{return await v(e,t,n,r,i,a,o)}catch(t){return m(t,{phase:`start`,operation:n.type,reference:a.reference}),v(e,k,s(n,k),r,i,{...a,sample:!1,reference:{traceId:a.reference?.traceId??r?.reference.traceId??a.parent?.traceId??h(16).toString(`hex`),spanId:a.reference?.spanId??h(8).toString(`hex`),traceFlags:0}},o)}}async function v(h,v,y,x,S,C,w){if(C.terminal?.error!==null&&typeof C.terminal?.error==`object`&&!(C.terminal.error instanceof Error)&&`message`in C.terminal.error&&typeof C.terminal.error.message==`string`){let e=Error(C.terminal.error.message);e.name=C.terminal.errorCode??`Error`,C={...C,terminal:{...C.terminal,error:e}}}let T=C.key,E=C.startTimeMs??Date.now(),N=C.parent??x?.reference;v.emit&&(v=t(v,i.active()?.capture));let P=v,F=s(y,P),I=c({identity:h,data:F,attempt:S,capture:P,key:T,parent:N,startTimeMs:E,links:C.links},d);I={...I,attributes:{...I.attributes,...C.attributes}},F=D({key:T,identity:h,data:F,capture:P,reference:C.reference??{traceId:`0`.repeat(32),spanId:`0`.repeat(16),traceFlags:0},startTimeMs:E},d).data;let L=C.deferred??(e.durable&&te.has(F.type)),R=C.executionContext,z=C.reference??g(y,T,N,I,P);C.sample===!0&&z!==void 0&&(z={...z,traceFlags:z.traceFlags&1&&P.emit&&(N!==void 0||(i.samples?.(z.traceId,I)??!0))?1:0});let B=L?void 0:p.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=s(F,P);let U=C.finished??!1,W=C.terminal,G=new Map,K=new Set,q=C.childSequence??0,J=C.usage,Y=new Set(C.usageKeys??[]),X={},re=F.type===`tool`?F.options.callId:void 0;function Z(){w()}function Q(){return t(P,i.active()?.capture)}async function ie(t,n,r={}){let i=G.get(n);if(e.durable&&i!==void 0&&!i.settled)return i.refine(t,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 o=P;G.size>=O&&(m(Error(`Trace unfinished-child limit reached.`),{phase:`start`,operation:t.type,reference:V}),o=k),t.type===`model`&&B!==void 0&&a(B,{"agent.model.id":t.options.modelId});let s=await _(h,o,t,$,t.type===`step`?{index:t.options.index,attempt:t.options.attempt??0}:S,{key:n,executionContext:R,links:r.links,startTimeMs:r.startTimeMs},w);return(o.emit||G.size<O)&&G.set(n,s),await w(),s}async function ae(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 oe(t){if(K.size>0&&await Promise.allSettled(K),U)return;let r=Q();r.recordOutputs||(t={...t,error:void 0}),W?.failed&&(t={...t,outcome:t.outcome===`completed`?`failed`:t.outcome,failed:!0,error:W.error,errorCode:t.errorCode??W.errorCode}),U=!0,W=t,await ae(t,t.failed===!0||!e.durable),B??=p.start(I,P,R,V);let i=F.type===`activation`&&t.usage===void 0?{...t,usage:J}:t;try{n(B,F,i,{...r,emit:P.emit},E,d)}catch(e){m(e,{phase:`complete`,operation:F.type,reference:V})}if(a(B,X),F.type===`model`&&t.model!==void 0){await x?.usage(t.model.usage,T);let e=t.model.content;if(r.recordOutputs&&P.recordOutputs&&e!==void 0){let n=d.outputMessages(e,t.model.finishReason);n!==void 0&&x?.turnContent({output:n})}}B.end(t.endTimeMs),await w()}let $={waitUntil(e){K.add(e),x?.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=u(e.attributes??{},Q())??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&&a(B,t),Z()},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<E&&(E=t),e.type===`tool`&&F.type===`tool`){let t=F.options;F=s({type:`tool`,options:{...t,kind:t.kind??e.options.kind,arguments:t.arguments??(Q().recordInputs?e.options.arguments:void 0)}},P)}let n=c({identity:h,data:F,attempt:S,capture:P,key:T,parent:N,startTimeMs:E,links:I.links},d),r=Object.fromEntries(Object.entries(n.attributes).filter(([,e])=>e!==void 0));I={...I,name:n.name,kind:n.kind,startTimeMs:E,attributes:{...I.attributes,...r}},Z()},narrow(e){P={...t(P,e),emit:P.emit},F=s(F,P);let n=u(I.attributes,P)??I.attributes;I={...I,attributes:F.type===`activation`?{...n,"agent.trace.content.input":P.recordInputs,"agent.trace.content.output":P.recordOutputs}:n};let r=u(X,P)??X;for(let e of Object.keys(X))e in r||delete X[e];!P.recordOutputs&&W?.error!==void 0&&(W={...W,error:void 0}),B?.narrow(P);for(let e of G.values())e.narrow(P);Z()},async release(t){U?await ae(t,t.failed===!0||!e.durable):await oe(M(t))},record(){return D({version:1,finished:U,terminal:W,usage:J,usageKeys:[...Y],attributes:{...I.attributes,...X},childSequence:q,children:[...G.values()].filter(e=>!e.settled).map(e=>e.record()),key:T,identity:h,data:F,capture:P,reference:V,parent:N,startTimeMs:E,attempt:S,links:I.links},d)},get parent(){return N},get startTimeMs(){return E},child(t,n,r){if(!o(t).includes(F.type))throw Error(`The operation is not permitted in this trace scope.`);let i=n===void 0?(e.durable?j(t):void 0)??`${t.type}:${q++}`:`${t.type}:${A(n)}`;return ie(t,`${T}/${i}`,r)},find(e){let t=j(e),n=t===void 0?void 0:G.get(`${T}/${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:re,get capture(){return P},mcp:l({serializer:d,...P,write(e){let t=u(e,Q())??e;Object.assign(X,t),B!==void 0&&a(B,t)},error(e,t){$.error(e,t)}}),get finished(){return U},get settled(){return U&&[...G.values()].every(e=>e.settled)},run(e,n){if(U)throw Error(`The trace scope has already finished.`);let r=t(t(P,n),i.active()?.capture),a=F.type===`tool`&&(F.options.kind===`subagent-call`||F.options.kind===`remote-agent-call`)?F.options:void 0,o=a===void 0?e:()=>f({caller:V,conversationId:h.conversationId,parentRunId:h.runId,parentCallId:a.callId,agentName:a.name,capture:r},e);return b(i,{type:$.type,reference:V,capture:r,mcp:$.mcp},o,R)},async complete(e=W??{}){U||await oe(M(e))},async usage(e,t){t!==void 0&&Y.has(t)||(t!==void 0&&Y.add(t),B!==void 0&&a(B,r(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 x?.usage(e,t))},turnContent(e){if(F.type!==`activation`)return x?.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(e,t){W={...W,failed:!0,error:Q().recordOutputs?e:void 0,errorCode:t??(e instanceof Error?e.name:void 0)},B!==void 0&&B.fail(W.error,W.errorCode),Z()}};for(let e of C.children??[])G.set(e.key,await _(e.identity,t(e.capture,P),e.data,$,e.attempt,{...e,deferred:!0,executionContext:R},w));!U&&B!==void 0&&F.type===`step`&&B.addEvent(`step.started`,void 0,E);let se=I.attributes[`gen_ai.input.messages`];return!U&&F.type===`model`&&typeof se==`string`&&x?.turnContent({input:se}),$}return{start(e){return _(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,n={}){if(!E(e)){m(Error(`Invalid tracing checkpoint.`),{phase:`restore`});return}return _(e.identity,t(e.capture,n.capture),e.data,void 0,e.attempt,{...e,deferred:!0,executionContext:n.context},n.onChange??(()=>Promise.resolve()))}}}function P(e,t,n){try{e?.(t,{phase:n})}catch{}}function F(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){P(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){P(n,e,`complete`)}}}return r}function I(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)=>I(await e.child(t,r,i),t,n),o=F(async({startTimeMs:e,...t})=>a({type:`tool`,options:t},void 0,{startTimeMs:e}),void 0,n),s=e=>e===void 0?void 0:I(e,e.record().data,n),c=F(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(L(e,t)),attempt:F(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=>F(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){P(n,e,`complete`)}throw e}try{await r.complete({outcome:`completed`,result:i})}catch(e){P(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=>P(n,e,`complete`));return e.waitUntil(a),t.result}catch(e){try{await i.fail(e)}catch(e){P(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:F(async e=>a({type:`approval`,options:{...e,callId:t.options.callId,toolName:t.options.name}}),{outcome:`ignored`},n)}):i}function L(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=L(n,t);if(e!==void 0)return e}}}const R={emit:!0,recordInputs:!1,recordOutputs:!1};function z(n){let r=n.telemetry??e(),i=n.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=(e,t)=>{try{n.onError?.(e,t)}catch{}},o=N({telemetry:r,serializer:n.serializer??d,durable:i!==void 0,onError:n.onError}),s=new Map;function c(e){return i===void 0?`turn:${g()}`:[`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?n:(r.writes++,n=n.then(async()=>{try{if(r.root.settled)s.delete(e),await i.delete(e);else{let t=g();await i.set(e,ee({...r.root.record(),revision:t})),r.revision=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 f(e,t,n,r,a){let s=i===void 0?void 0:await u(e);if(t!==void 0&&(t.writes>0||s?.revision===t.revision))return r!==void 0&&t.root.useContext(r),a!==void 0&&t.root.narrow(a),t;let c,d=l(e,()=>c),f=s===void 0?void 0:await o.restore(s,{capture:a,context:r,onChange:d}),p=f??await n?.(d);if(p!==void 0)return c={root:p,revision:s?.revision,writes:0},f===void 0&&await d(),c}function m(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,n){return i=>{let a=p(),s=t(e.capture??R,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:n,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 _(e){return I(e,{type:`activation`,options:{sequence:0}},n.onError)}async function v(e){let t=c(e.identity);return _((i===void 0?await f(t,void 0,h(e,t),e.context):await m(t,n=>f(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 m(t,n=>f(t,n,void 0,e.context));return n===void 0?void 0:_(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:${g()}`,capture:t.capture??i?.capture??R,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:F(v,void 0,n.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{_ as AgentSpanIdGenerator,z as createAgentTracing,i as currentCapture,e as otelTelemetry};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { LiveOperation } from "./core/scopes.js";
|
|
2
|
+
import type { StepOptions, TraceLink, ScopeData, ScopeTerminal, ModelOptions, ToolOptions, ModelResult, CaptureDecision, Attributes, TraceReference, TraceErrorHandler } from "./core/types.js";
|
|
3
|
+
type Completion = ScopeTerminal & {
|
|
4
|
+
errorType?: string;
|
|
5
|
+
result?: ModelResult;
|
|
6
|
+
};
|
|
7
|
+
export interface Operation {
|
|
8
|
+
readonly type: ScopeData["type"];
|
|
9
|
+
readonly reference: TraceReference;
|
|
10
|
+
readonly parent?: TraceReference;
|
|
11
|
+
readonly startTimeMs: number;
|
|
12
|
+
readonly finished: boolean;
|
|
13
|
+
readonly capture: CaptureDecision;
|
|
14
|
+
run<T>(execute: () => T, ceiling?: CaptureDecision): T;
|
|
15
|
+
attributes(attributes: Attributes): void;
|
|
16
|
+
complete(result?: Completion): Promise<void>;
|
|
17
|
+
fail(error: unknown): Promise<void>;
|
|
18
|
+
/** Records a failure without ending the operation; completion keeps it. */
|
|
19
|
+
recordError(error: unknown, errorType?: string): void;
|
|
20
|
+
}
|
|
21
|
+
export interface WrappedOperation<I, H extends Operation> {
|
|
22
|
+
(input: I): Promise<H>;
|
|
23
|
+
<T>(input: I & {
|
|
24
|
+
describe?: (value: T) => Completion;
|
|
25
|
+
}, execute: (operation: H) => T | PromiseLike<T>): Promise<T>;
|
|
26
|
+
}
|
|
27
|
+
type MemoryInput = Extract<ScopeData, {
|
|
28
|
+
type: "memory";
|
|
29
|
+
}>["options"];
|
|
30
|
+
export interface AttemptInput {
|
|
31
|
+
readonly stepIndex: number;
|
|
32
|
+
readonly attempt: number;
|
|
33
|
+
readonly runtimeContext?: StepOptions["runtimeContext"];
|
|
34
|
+
readonly channel?: StepOptions["channel"];
|
|
35
|
+
readonly links?: readonly TraceLink[];
|
|
36
|
+
}
|
|
37
|
+
export interface TurnOperation extends Operation {
|
|
38
|
+
attempt: WrappedOperation<AttemptInput, AttemptOperation>;
|
|
39
|
+
/** Returns an open attempt without starting one. Durable turns only. */
|
|
40
|
+
findAttempt(input: {
|
|
41
|
+
stepIndex: number;
|
|
42
|
+
attempt: number;
|
|
43
|
+
}): AttemptOperation | undefined;
|
|
44
|
+
/** Returns an open tool call from any attempt of this turn. Durable turns only. */
|
|
45
|
+
findTool(callId: string): ToolOperation | undefined;
|
|
46
|
+
/** Replaces the turn's links before its deferred span is exported. */
|
|
47
|
+
links(links: readonly TraceLink[]): void;
|
|
48
|
+
memory: WrappedOperation<MemoryInput, MemoryOperation>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* One tool call. In a durable turn, calling `tool` again with the same `callId`
|
|
52
|
+
* returns the same call and fills in details it did not have, such as `kind`,
|
|
53
|
+
* `arguments`, or an earlier `startTimeMs`.
|
|
54
|
+
*/
|
|
55
|
+
export interface ToolInput extends ToolOptions {
|
|
56
|
+
readonly startTimeMs?: number;
|
|
57
|
+
}
|
|
58
|
+
export interface AttemptOperation extends Operation {
|
|
59
|
+
tool: WrappedOperation<ToolInput, ToolOperation>;
|
|
60
|
+
callSubAgent: WrappedOperation<{
|
|
61
|
+
callId: string;
|
|
62
|
+
agentName: string;
|
|
63
|
+
}, ToolOperation>;
|
|
64
|
+
callRemoteAgent: WrappedOperation<{
|
|
65
|
+
callId: string;
|
|
66
|
+
agentName: string;
|
|
67
|
+
}, ToolOperation>;
|
|
68
|
+
modelCall(input: ModelOptions, key?: string): Promise<ModelOperation>;
|
|
69
|
+
modelCall<T>(input: ModelOptions, execute: () => ModelCallReturn<T> | PromiseLike<ModelCallReturn<T>>): Promise<T>;
|
|
70
|
+
modelStream<T>(input: ModelOptions, execute: () => ModelStreamReturn<T> | PromiseLike<ModelStreamReturn<T>>): Promise<T>;
|
|
71
|
+
memory: WrappedOperation<MemoryInput, MemoryOperation>;
|
|
72
|
+
}
|
|
73
|
+
export interface ToolOperation extends Operation {
|
|
74
|
+
approval: WrappedOperation<{
|
|
75
|
+
requestId: string;
|
|
76
|
+
request?: unknown;
|
|
77
|
+
}, ApprovalOperation>;
|
|
78
|
+
/** Returns an open approval without starting one. Durable turns only. */
|
|
79
|
+
findApproval(requestId: string): ApprovalOperation | undefined;
|
|
80
|
+
/** A tool call made while this tool runs, such as a connector's nested call. */
|
|
81
|
+
tool: WrappedOperation<ToolInput, ToolOperation>;
|
|
82
|
+
memory: WrappedOperation<MemoryInput, MemoryOperation>;
|
|
83
|
+
}
|
|
84
|
+
export type ModelOperation = Operation;
|
|
85
|
+
export type ApprovalOperation = Operation;
|
|
86
|
+
export type MemoryOperation = Operation;
|
|
87
|
+
export interface ModelCallReturn<T> extends ModelResult {
|
|
88
|
+
readonly result: T;
|
|
89
|
+
}
|
|
90
|
+
export interface ModelStreamReturn<T> {
|
|
91
|
+
readonly result: T;
|
|
92
|
+
readonly completion: PromiseLike<ModelResult>;
|
|
93
|
+
}
|
|
94
|
+
export declare function wrappedOperation<I, H extends Operation>(start: (input: I) => Promise<H>, fallback?: Completion, onError?: TraceErrorHandler): WrappedOperation<I, H>;
|
|
95
|
+
export declare function operationHandle(runtime: LiveOperation, data: ScopeData, onError?: TraceErrorHandler): TurnOperation | AttemptOperation | ToolOperation | Operation;
|
|
96
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenTelemetry plumbing for hosts that run their own spans beside agent
|
|
3
|
+
* tracing: active-operation lookup, capture context, content bounds, and MCP
|
|
4
|
+
* enrichment. Agent tracing itself needs only the package root.
|
|
5
|
+
*/
|
|
6
|
+
export { activeTraceOperation, withErrorContent } from "./adapters/otel.js";
|
|
7
|
+
export { withCapture } from "./capture.js";
|
|
8
|
+
export { boundedPrincipalId, contentAttribute, telemetryByteLength, truncateTelemetryText, CONTENT_ATTRIBUTE_LIMIT, } from "./adapters/serialization.js";
|
|
9
|
+
export { withoutDeclinedContent, type ResolvedContentOptions } from "./core/content-policy.js";
|
|
10
|
+
export { mcpLifecycle, type McpLifecycle, type McpUpdate } from "./core/mcp.js";
|
|
11
|
+
export { invocationName } from "./core/span-kinds.js";
|
|
12
|
+
export { USAGE_FIELDS } from "./core/attributes.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{S as e,_ as t,a as n,b as r,c as i,d as a,h as o,p as s,t as c,u as l,x as u,y as d}from"../../_chunks/workflow/mcp-CrGp4EC8.js";export{t as CONTENT_ATTRIBUTE_LIMIT,i as USAGE_FIELDS,a as activeTraceOperation,d as boundedPrincipalId,r as contentAttribute,n as invocationName,c as mcpLifecycle,u as telemetryByteLength,e as truncateTelemetryText,o as withCapture,s as withErrorContent,l as withoutDeclinedContent};
|