/** * Shared batch runner — one coherent job result instead of N mini-transcripts. * * Batch design law: * - ONE envelope for the whole batch. tokens/elapsed/residency are at the * envelope level. Per-item entries stay tight: {id, ok, result|error}. * - Stable, caller-provided item ids. Duplicates are rejected up front * so results join back to source inputs cleanly even under retries * and partial failures. * - Partial failure is first-class. A single bad item never explodes * the batch — errors surface per item and ok_count/error_count give * Claude an at-a-glance triage. * - Serial processing. Simpler to reason about (no per-item head-of-line * contention with concurrent single-call users) and the existing * Ollama semaphore already bounds concurrency globally. If throughput * ever matters more than clarity, bounded batch concurrency is a * follow-up, not this commit. * * The per-item shape deliberately omits per-item tokens/elapsed. Adding * them would turn the batch back into a bundle of receipts. The NDJSON * log is the place for per-call accounting. */ import type { GenerateRequest } from "../ollama.js"; import type { Tier } from "../tiers.js"; import type { Envelope } from "../envelope.js"; import { type ErrorShape } from "../errors.js"; import type { RunContext } from "../runContext.js"; export interface BatchItem { /** Caller-provided, stable, unique within the batch. Required. */ id: string; } export interface BatchItemOk { id: string; ok: true; result: R; } export interface BatchItemError { id: string; ok: false; error: { code: ErrorShape["code"]; message: string; hint: string; }; } export type BatchItemEntry = BatchItemOk | BatchItemError; export interface BatchResult { items: BatchItemEntry[]; } export interface RunBatchInput { tool: string; tier: Tier; ctx: RunContext; items: I[]; /** Build the generate request for one item. Runs before the LLM call. */ build: (item: I, tier: Tier, model: string) => GenerateRequest; /** Turn the raw model response into a per-item result. Throw to mark the item failed. */ parse: (raw: string, item: I) => R; /** Optional pre-flight check. Throw with an InternError to fail fast on malformed items without an LLM call. */ preValidate?: (item: I) => void; /** Whether to attempt tier fallback on timeout per item. */ allowFallback?: boolean; /** Override thinking mode on every per-item generate call. See RunToolInput.think. */ think?: boolean; /** * Optional per-call model override (atom tools only — added v2.3.0). * Applies to the initial-tier attempt for EVERY item in the batch. * Fallback retries still resolve their model from the fallback tier. * Propagates to `envelope.model_requested` on the batch envelope. */ modelOverride?: string; /** * R-019 (v2.6.0) — optional per-call tier-budget override in milliseconds. * * Same semantics as the single-call runner's `tierBudgetMsOverride`: * applied uniformly to every tier the cascade visits (initial + fallback) * for EVERY item in the batch. Validated upstream at the schema layer; * trusted here. */ tierBudgetMsOverride?: number; } export declare function runBatch(input: RunBatchInput): Promise>>; //# sourceMappingURL=batch.d.ts.map