import { L as ProviderApiError, Rn as AgentSessionRef, gr as Harness } from "../index-DJ6CHaMc.js"; import { r as RunMetadata } from "../resources-B6ZjmsZN.js"; import "../seams-DiYeIR45.js"; import { LanguageModel } from "ai"; //#region src/steps/agents/shared/runner.d.ts /** * A harness ready to run in a worktree, from {@link createAgentRunner}. Pass `model` to the AI * SDK's `generateText`, read the session reference from its result with `sessionFrom`, and call * `close` when the call is done. * * @group Agent runner */ interface AgentRunner { /** The live provider model, with jigs' policy already applied. */ model: LanguageModel; /** The session reference in a `generateText` result, for a later step to resume. */ sessionFrom(result: { providerMetadata?: Record> | null | undefined; }): AgentSessionRef | undefined; /** Release the worktree lock and stop what the harness started. Safe to call twice. */ close(): Promise; } /** * Where {@link createAgentRunner} runs a harness, and the session it resumes. * * @group Agent runner */ interface AgentRunnerOptions { /** The worktree the agent works in. */ cwd: string; /** The run the step belongs to: `getWorkflowMetadata()` inside the step. */ run: RunMetadata; /** A session reference from an earlier call to resume. */ resume?: AgentSessionRef | undefined; } /** * Open a Codex harness inside a factory's own step, the way the built-in agent step does: the * environment allowlist with the factory's `agents.env`, the request and just-in-time checks, the * worktree lock, and Codex's private home and app server. The returned `model` is the live * provider, ready for `generateText`. * * @remarks * Call it inside a `"use step"` function, never in a workflow. The step can hand the provider a * function, such as a tool-approval hook or a logger, because a step runs where functions are * allowed; pass it through the AI SDK call. * * It throws `JitCheckError` when a just-in-time check fails, and {@link AgentSessionError} when * `resume` names a session this harness cannot resume. Claude Code and Pi have no AI SDK provider * model, so their descriptors throw: run them with `runAgent`. * * It reads the run's status before opening the harness and watches it until `close`. It throws * a fatal error instead of opening on a cancelled run, and once the run is cancelled every * provider call through `model` is aborted and fails with that fatal error. * * @example * ```ts * import type { AgentSessionRef, Harness } from "@jigs-ai/jigs"; * import { createAgentRunner } from "@jigs-ai/jigs/steps"; * import { generateText } from "ai"; * import { getWorkflowMetadata } from "workflow"; * * export async function runWithTemperature(request: { * harness: Harness; * cwd: string; * prompt: string; * resume?: AgentSessionRef | undefined; * }) { * "use step"; * const runner = await createAgentRunner(request.harness, { * cwd: request.cwd, * run: getWorkflowMetadata(), * resume: request.resume, * }); * try { * const result = await generateText({ model: runner.model, prompt: request.prompt, temperature: 0 }); * return { text: result.text, session: runner.sessionFrom(result) }; * } finally { * await runner.close(); * } * } * ``` * * @group Agent runner */ declare function createAgentRunner(harness: Harness, options: AgentRunnerOptions): Promise; //#endregion //#region src/steps/agents/shared/session-error.d.ts /** * A durable agent session is missing or cannot be resumed by this harness. * * @group Errors */ declare class AgentSessionError extends Error { readonly name = "AgentSessionError"; } //#endregion export { type AgentRunner, type AgentRunnerOptions, AgentSessionError, ProviderApiError, type RunMetadata, createAgentRunner };