import { Effect } from "effect"; import type * as Cause from "effect/Cause"; import type { Executor, ElicitationResponseMeta, ElicitationHandler, ElicitationContext } from "@executor-js/sdk/core"; import { CodeExecutionError } from "@executor-js/codemode-core"; import type { CodeExecutor, ExecuteResult } from "@executor-js/codemode-core"; import { type ToolDiscoveryProvider } from "./tool-invoker"; export type ExecutionEngineConfig = { readonly executor: Executor; readonly codeExecutor: CodeExecutor; readonly toolDiscoveryProvider?: ToolDiscoveryProvider; }; export type ExecutionResult = { readonly status: "completed"; readonly result: ExecuteResult; } | { readonly status: "paused"; readonly execution: PausedExecution; }; export type PausedExecution = { readonly id: string; readonly elicitationContext: ElicitationContext; }; export type PausedExecutionDeadline = { readonly expiresAt: string; readonly ttlMs: number; }; export type ResumeResponse = { readonly action: "accept" | "decline" | "cancel"; readonly content?: Record; /** The answer's terms — `persist`, when the paused request offered a * choice of scopes and the approver picked one. */ readonly meta?: ElicitationResponseMeta; }; export declare const formatExecuteResult: (result: ExecuteResult) => { text: string; structured: Record; isError: boolean; }; export declare const formatPausedExecution: (paused: PausedExecution, options?: { readonly deadline?: PausedExecutionDeadline; }) => { text: string; structured: Record; }; export declare const formatTtlDuration: (ttlMs: number) => string; export type ExecutionEngine = { /** * Execute code with elicitation handled inline by the provided handler. * Use this when the host supports elicitation (e.g. MCP with elicitation capability). * * Fails with the code executor's typed error `E` (defaults to * `CodeExecutionError`). Runtimes surface their own `Data.TaggedError` * subclass, which flows through here unchanged. */ readonly execute: (code: string, options: { readonly onElicitation: ElicitationHandler; }) => Effect.Effect; /** * Execute code, intercepting the first elicitation as a pause point. * Use this when the host doesn't support inline elicitation. * Returns either a completed result or a paused execution that can be resumed. * * `options.autoApprove` treats the caller as the human in the loop: every * elicitation is accepted inline, so an approval-gated tool runs to * completion instead of pausing. The operator-facing Run/Test panel sets * this because clicking Run IS the approval. `block` policies still fail * before any elicitation, so this never bypasses a hard block. */ readonly executeWithPause: (code: string, options?: { readonly autoApprove?: boolean; }) => Effect.Effect; /** * Resume a paused execution. Returns a completed result, a new pause, or * null if the executionId was not found. */ readonly resume: (executionId: string, response: ResumeResponse) => Effect.Effect; /** * True when the engine remembers that an executionId has already settled, even * if the replayed outcome has rolled out of the bounded resume cache. */ readonly isExecutionSettled?: (executionId: string) => Effect.Effect; /** * Inspect a paused execution without resuming it. Returns null if the id is * unknown or has already been resumed. */ readonly getPausedExecution: (executionId: string) => Effect.Effect; /** Count of executions currently paused awaiting resume. */ readonly pausedExecutionCount: () => Effect.Effect; /** Whether any executions are paused awaiting resume. */ readonly hasPausedExecutions: () => Effect.Effect; /** * Get the dynamic tool description (workflow + namespaces). */ readonly getDescription: Effect.Effect; /** * End this engine's in-flight sandbox fibers and wait for them to unwind. * * `executeWithPause` forks the sandbox as a daemon so a pause can outlive the * caller that observed it. That fiber holds the executor, and so the DB handle * belonging to whichever scope built this engine. A host that builds an engine * per request MUST call this before that scope's connection is closed, or the * fiber outlives the pool it queries. * * Required, not optional: a decorator that wrapped the engine and quietly * dropped this member would silently reopen that race, so the type makes * forwarding it a compile error. */ readonly shutdown: Effect.Effect; }; export declare const createExecutionEngine: (config: ExecutionEngineConfig) => ExecutionEngine; //# sourceMappingURL=engine.d.ts.map