import { AsyncLocalStorage } from "node:async_hooks"; import { z } from "zod"; import type { JsonObject } from "../contracts/json-object.js"; import type { CanonicalJsonCodec } from "../adapters/canonical-json.js"; import type { ToolHandler, ToolDefinition, ToolContext } from "./context.js"; import type { McpToolResult, McpToolReceipt } from "./receipt.js"; import type { WorkspaceRouter, WorkspaceExecutionContext, WorkspaceMode } from "./workspace-router.js"; import type { DaemonJobScheduler } from "./daemon-job-scheduler.js"; import type { DaemonWorkerPool } from "./daemon-worker-pool.js"; import type { RuntimeEventLogger, RuntimeObservabilityState, ToolCallFootprintRegion } from "./runtime-observability.js"; /** Mutable footprint accumulator for the current tool invocation. */ export interface FootprintAccumulator { readonly paths: Set; readonly symbols: Set; readonly regions: ToolCallFootprintRegion[]; } /** Mutable invocation state tracked via AsyncLocalStorage. */ export interface InvocationStore { readonly traceId: string; readonly startedAtMs: number; readonly footprint: FootprintAccumulator; response?: { readonly receipt: McpToolReceipt; readonly tripwireSignals: readonly string[]; }; } /** Dependencies injected by the composition root to build the invocation engine. */ export interface InvocationEngineDeps { readonly sessionId: string; readonly mode: WorkspaceMode; readonly codec: CanonicalJsonCodec; readonly observability: RuntimeObservabilityState; readonly runtimeLogger: RuntimeEventLogger; readonly workspaceRouter: WorkspaceRouter; readonly daemonScheduler: DaemonJobScheduler | null; readonly daemonWorkerPool: DaemonWorkerPool | null; readonly runtimeReady: Promise; } /** Engine returned by createInvocationEngine. */ export interface InvocationEngine { /** The AsyncLocalStorage for execution contexts — needed by the ToolContext builder. */ readonly executionContextStorage: AsyncLocalStorage; /** The AsyncLocalStorage for invocation tracking — needed by respond(). */ readonly invocationStorage: AsyncLocalStorage; /** Monotonically increasing sequence counter (mutable). */ getSeq(): number; incrementSeq(): number; /** Build the respond() function suitable for ToolContext. */ respond: (tool: ToolDefinition["name"], data: JsonObject) => McpToolResult; /** Get the active execution context from AsyncLocalStorage. */ getActiveExecutionContext: () => WorkspaceExecutionContext | null; /** Invoke a tool with full lifecycle (observability, scheduling, repo state). */ invokeTool: (name: string, handler: ToolHandler, args: JsonObject, ctx: ToolContext, schema?: z.ZodObject) => Promise; /** Emit a runtime observability event. */ emitRuntimeEvent: (event: Parameters[0]) => Promise; } /** * Record path/symbol/region observations into the current invocation's footprint. * Safe to call outside an invocation context (silently no-ops). */ export declare function recordFootprint(invocationStorage: AsyncLocalStorage, entry: { readonly paths?: readonly string[]; readonly symbols?: readonly string[]; readonly regions?: readonly ToolCallFootprintRegion[]; }): void; /** * Creates the invocation engine that manages tool execution lifecycle: * - AsyncLocalStorage for execution context and invocation tracking * - Receipt building via respond() * - Tool invocation with observability, daemon scheduling, and worker offloading */ export declare function createInvocationEngine(deps: InvocationEngineDeps): InvocationEngine; //# sourceMappingURL=server-invocation.d.ts.map