import { type LanguageModel, type LanguageModelUsage, type ModelMessage, type ProviderMetadata, type TimeoutConfiguration, type Tool, ToolLoopAgent, type ToolLoopAgentSettings, type ToolSet } from 'ai'; import type { z } from 'zod'; import { type EnvInfo } from './env-block.ts'; import { type PromptBlock } from './prompt-blocks.ts'; export declare const SUBMIT_TOOL_NAME = "submit"; export declare function composeSystemPrompt(blocks: readonly PromptBlock[]): string; export declare function composeSystemPrompt(style: string, rolePrefix: string, env: string | EnvInfo): string; export type SubagentStreamEvent = { type: 'text-delta'; text: string; } | { type: 'tool-call'; toolName: string; input: unknown; }; export type SubagentStreamSink = (event: SubagentStreamEvent) => void; export declare const STREAM_INACTIVITY_MS = 120000; export declare const STREAM_GRACE_MS = 30000; export declare const MAX_STREAM_STALL_RETRIES = 1; export type StreamTimer = { expired: Promise; cancel: () => void; }; export type StreamTimerFactory = (ms: number) => StreamTimer; export type StreamWatchdogConfig = { inactivityMs?: number; graceMs?: number; timer?: StreamTimerFactory; }; export type StreamWatchdog = { inactivityMs: number; graceMs: number; timer: StreamTimerFactory; }; export type StreamWatchdogOutcome = 'drained' | 'stalled-active' | 'stalled-grace'; export declare class StreamStallError extends Error { readonly name = "StreamStallError"; } export type SubagentConfig = { model: LanguageModel; tools: TOOLS; systemPrompt: string; submit: Tool; maxSteps?: number; timeout?: TimeoutConfiguration; prepareStep?: ToolLoopAgentSettings['prepareStep']; providerOptions?: ToolLoopAgentSettings['providerOptions']; onStepFinish?: ToolLoopAgentSettings['onStepFinish']; onRetry?: RetryOptions['onRetry']; onStream?: SubagentStreamSink; streamWatchdog?: StreamWatchdogConfig; signal?: AbortSignal; }; export declare function createSubagent(config: SubagentConfig, defaultMaxSteps: number): ToolLoopAgent; export declare function consumeStreamWithWatchdog(stream: AsyncIterable, handlers: { onPart: (part: PART) => void; isFinish: (part: PART) => boolean; abort: () => void; }, watchdog: StreamWatchdog): Promise; export declare class StepTimeoutError extends Error { readonly name = "StepTimeoutError"; } export declare function callWithStepTimeout(call: () => Promise, timeout: TimeoutConfiguration | undefined, retry?: RetryOptions): Promise; export declare function withTimeout(options: T, timeout: TimeoutConfiguration | undefined): T | (T & { timeout: TimeoutConfiguration; }); export declare const DEFAULT_LLM_MAX_RETRIES = 10; export declare function defaultRetryDelayMs(attemptIndex: number): number; export type RetryInfo = { attempt: number; maxAttempts: number; delayMs: number; reason: string; }; export type RetryOptions = { maxRetries?: number; delayMs?: (attemptIndex: number) => number; sleep?: (ms: number) => Promise; isRetryable?: (err: unknown) => boolean; onRetry?: (info: RetryInfo) => void; signal?: AbortSignal; }; export declare function callWithRetry(call: () => Promise, opts?: RetryOptions): Promise; export declare function isRetryableProviderError(err: unknown): boolean; export declare function parseRetryAfterMs(err: unknown): number | undefined; type StepsResult = { steps: ReadonlyArray<{ toolCalls: ReadonlyArray<{ toolName: string; input: unknown; }>; }>; }; export type SubmittedOutput = { ok: true; value: OUTPUT; } | { ok: false; reason: 'no-submission'; } | { ok: false; reason: 'invalid'; issues: readonly z.core.$ZodIssue[]; }; export declare function submittedOutput(result: StepsResult, outputSchema: z.ZodType): SubmittedOutput; export declare function formatSubmitIssues(issues: readonly z.core.$ZodIssue[]): string; export type SchemaRetryOptions = { maxRetries?: number; onUsage?: (usage: LanguageModelUsage, modelId: string | undefined, providerMetadata?: ProviderMetadata, meta?: { latencyMs?: number; retries?: number; }) => void; }; export declare function runWithSchemaRetry(agent: ToolLoopAgent, schema: z.ZodType, prompt: string, options?: SchemaRetryOptions): Promise>; type GenerateResult = Awaited['generate']>>; export type SubagentHandle = { agent: ToolLoopAgent; messages: ModelMessage[]; }; export type SubagentRun = { result: GenerateResult; handle: SubagentHandle; }; export type SubagentRunOptions = { signal?: AbortSignal; }; export declare function runSubagent(agent: ToolLoopAgent, prompt: string, options?: SubagentRunOptions): Promise>; export declare function continueSubagent(handle: SubagentHandle, followUpPrompt: string, options?: SubagentRunOptions): Promise>; export declare function correctiveMessage(failure: { reason: 'no-submission'; } | { reason: 'invalid'; issues: readonly z.core.$ZodIssue[]; }): string; export {};