import type { Message } from '../../types/messages.js'; import type { AgentToolCall } from '../create-agent.js'; /** * What the middleware share. Every count here is read from the transcript rather than kept in * memory, so it survives a restart, a resumed approval, and a second process, and two threads never * share one. */ /** * The current turn: every message after the latest user message. One `invoke()` is one turn; a run * that resumes after an approval is the same turn. */ export declare function turnOf(messages: readonly Message[]): readonly Message[]; /** Model calls made in the current turn: its assistant messages. */ export declare function modelCallsInTurn(messages: readonly Message[]): number; /** * Where a call sits among the current turn's calls to the same tool, from 1. Calls the model made in * parallel are ordered as the model listed them, so the position never depends on which finished * first. */ export declare function callPosition(messages: readonly Message[], call: Pick): number; /** A message's text: the string, or its text parts joined. */ export declare function textOf(content: Message['content']): string; /** How long to wait between attempts. */ export interface RetryBackoff { /** The wait before the second attempt, in milliseconds. Defaults to 500. */ initialMs?: number; /** The longest wait, in milliseconds. Defaults to 10,000. */ maxMs?: number; /** What each wait is multiplied by. Defaults to 2. */ factor?: number; /** Spreads each wait between half and all of it, so runs that failed together retry apart. Defaults to true. */ jitter?: boolean; } /** The wait before attempt `attempt + 1`, after `attempt` failed. */ export declare function backoffDelay(attempt: number, backoff?: RetryBackoff): number; /** Waits, or rejects with the signal's reason as soon as it aborts. */ export declare function sleep(ms: number, signal?: AbortSignal): Promise; /** True for a cancellation: never worth retrying or falling back from. */ export declare function isCancellation(error: unknown, signal?: AbortSignal): boolean; /** A short, stable hash of a text: cyrb53 as 8 hex digits. Not a security boundary. */ export declare function shortHash(text: string): string;