import type { TelemetryOptions } from "ai"; import type { InstrumentationAttemptScope, InstrumentationContextRunner, InstrumentationHooks, InstrumentationSessionStartedEvent, InstrumentationTraceContext, InstrumentationTraceSeed, InstrumentationTurnStartedEvent } from "#instrumentation/lifecycle.js"; import { type BuildTelemetryRuntimeContextInput } from "#instrumentation/runtime-context.js"; import { type CreateInstrumentationHandleEventInput } from "#instrumentation/native-events.js"; import type { ResolvedInputBatch } from "#harness/input-request-resolution.js"; import type { HandleEventFn } from "#harness/types.js"; import { type ChannelDeliveryStartInstrumentation, type ChannelDeliveryTerminalInstrumentation } from "#instrumentation/channel-delivery.js"; import { type PrepareTurnTraceContextInput } from "#instrumentation/prepare-trace-context.js"; import type { RuntimeTraceContext } from "#protocol/message.js"; import type { OtelHarnessSettings, RuntimeContextResolver } from "#tracing/otel-declaration.js"; import { AgentSpanIdGenerator } from "#tracing/agent-span-id-generator.js"; import { type ContextContainer } from "#context/container.js"; import { type MemoryInstrumentation } from "#instrumentation/memory.js"; import type { AgentSamplingOperation } from "#tracing/agent-span-contract.js"; import { getInstrumentationRuntime, registerInstrumentationRuntime } from "#instrumentation/runtime-global.js"; import { initializeSessionInstrumentation } from "#instrumentation/session-init.js"; export { getInstrumentationRuntime, registerInstrumentationRuntime }; export { initializeSessionInstrumentation }; import type { TASK_CANCEL_TOOL_NAME, TASK_WAIT_TOOL_NAME } from "#protocol/task-tools.js"; interface InstrumentedStepSession { readonly sessionId: string; readonly state?: Readonly>; } export interface InstrumentationStepScope { readonly createHandleEvent: (input: Omit) => HandleEventFn | undefined; readonly prepareAttempt: (input: { readonly isFrameworkTool?: (name: string) => boolean; readonly attemptIndex: number; readonly runtimeContext?: Readonly>; readonly stepIndex: number; readonly turnId: string; }) => PreparedInstrumentationAttempt; readonly preparePreamble: (input: Omit) => Promise; readonly publishInputResolutions: (input: { readonly batch: ResolvedInputBatch; readonly sessionId: string; }) => Promise; readonly recordError: (error: unknown) => void; readonly resolveRuntimeContext: (input: Omit) => Record | undefined; readonly session: TSession; readonly setTurnId: (turnId: string) => void; readonly telemetry: () => TelemetryOptions | undefined; readonly traceContext?: InstrumentationTraceContext; } export interface PreparedInstrumentationAttempt { readonly complete: () => Promise; readonly fail: (error: unknown) => Promise; readonly scope: InstrumentationAttemptScope; readonly telemetry: TelemetryOptions | undefined; } export type InstrumentationAttempt = InstrumentationAttemptScope; export interface BoundInstrumentationSession { readonly traceSessionId: string; readonly agentName: string; readonly rootSessionId: string; readonly sessionId: string; } /** Process-wide runtime consumed by every harness execution surface. */ export interface InstrumentationRuntime { readonly forceFlush: () => Promise; readonly hooks: InstrumentationHooks; readonly idGenerator?: AgentSpanIdGenerator; readonly memoryOperations?: boolean; readonly ownsAgentSpans?: boolean; readonly prepareSessionTrace?: (event: InstrumentationSessionStartedEvent) => Promise; readonly prepareTurnTrace?: (event: InstrumentationTurnStartedEvent) => Promise; otelSettings: OtelHarnessSettings | undefined; readonly runtimeContextResolvers?: readonly RuntimeContextResolver[]; readonly runInContext: InstrumentationContextRunner; /** Whether the installed OTel sampler would record a trace with this id. */ readonly samplesTrace?: (traceId: string, operation?: AgentSamplingOperation) => boolean; readonly shutdown: () => Promise; } /** Worker-bound instrumentation operations consumed by one session execution. */ export interface SessionInstrumentation { readonly installAiSdkWarningLogger: () => void; readonly runStep: (input: { readonly environment: string; readonly eveVersion: string; readonly hasInput: boolean; readonly session: TSession; }, execute: (scope: InstrumentationStepScope) => Promise) => Promise; } export interface ExecutionInstrumentation { readonly instrumentTaskToolCall: (input: { readonly callId: string; readonly toolName: typeof TASK_WAIT_TOOL_NAME | typeof TASK_CANCEL_TOOL_NAME; readonly startedAtMs: number; readonly completedAtMs: number; readonly input: unknown; readonly output?: unknown; readonly failed?: boolean; }) => Promise; readonly createHandleEvent: (input: { readonly handleEvent?: HandleEventFn; readonly turnId?: string; }) => HandleEventFn | undefined; readonly flush: () => Promise; readonly instrumentChannelDelivery: (input: Omit | Omit) => Promise; readonly memory?: MemoryInstrumentation; readonly prepareExecution: () => SessionInstrumentation; readonly preparePreamble: InstrumentationStepScope["preparePreamble"]; } export declare function bindInstrumentationRuntime(runtime: InstrumentationRuntime | undefined, ctx: ContextContainer, boundInput: Omit): ExecutionInstrumentation | undefined; export declare function bindSessionInstrumentation(input: { readonly agentName: string; readonly ctx: ContextContainer; readonly rootSessionId: string; readonly sessionId: string; }): ExecutionInstrumentation | undefined;