import type { MappedItem, ProcessInstance, ProcessProject, ProcessTurnTerminalLifecycleStatus, TurnId } from "@leitwerk-dev/domain"; import type { LlmTurnDefinition } from "./define-process.js"; import type { Codec, ProcessTurnOutcomeEvent } from "./extension-api.js"; /** @public */ type MaybePromise = T | Promise; /** Maximum length of a mapped item key. @internal */ export declare const MAPPED_ITEM_KEY_MAX_LENGTH = 200; /** Maximum length of a mapped item label. @internal */ export declare const MAPPED_ITEM_LABEL_MAX_LENGTH = 200; /** Maximum number of items frozen by one mapped run. @internal */ export declare const MAPPED_ITEM_MAX_COUNT = 500; /** Graph trigger used by a mapped turn's collection route. @internal */ export declare const MAPPED_COLLECT_TRIGGER: "collect"; /** @internal */ export declare function mappedCollectTrigger(branchId?: string): string; /** Durable snapshot of process data available to mapped-turn server callbacks. @public */ export interface MappedTurnServerContext { /** @public */ readonly process: ProcessInstance; /** @internal */ readonly projects: readonly ProcessProject[]; /** @public */ readonly params: TParams; /** @public */ readonly state: TState; } /** Active item of a mapped LLM turn, as delivered to one worker turn. @public */ export interface MappedTurnItemContext { /** Frozen, codec-validated item value. @public */ readonly item: TItem; /** Stable key unique within the run. @public */ readonly itemKey: string; /** Short plain-text label shown to operators. @public */ readonly itemLabel: string; /** Zero-based position in the frozen order. @public */ readonly itemIndex: number; /** Number of frozen items in the run. @public */ readonly itemCount: number; } /** Serialized active item carried by worker payloads and turn records. @internal */ export interface MappedTurnIteration extends MappedTurnItemContext { /** @internal */ readonly runId: string; } /** @public */ export interface MappedItemInput { /** @public */ readonly item: TItem; /** @public */ readonly index: number; } /** @public */ export interface MappedSnapshotInput { /** @public */ readonly params: TParams; /** @public */ readonly state: TState; /** @public */ readonly items: readonly TItem[]; } /** Context passed to a mapped outcome's `yield` callback. @public */ export interface MappedOutcomeContext extends MappedTurnServerContext, MappedTurnItemContext { } /** @public */ export interface MappedYieldInput { /** @public */ readonly ctx: MappedOutcomeContext; /** @public */ readonly event: ProcessTurnOutcomeEvent; } /** @public */ export type MappedItemYield = (input: MappedYieldInput) => MaybePromise; /** @public */ export type MappedCollect = (ctx: MappedTurnServerContext, orderedResults: readonly TResult[]) => MaybePromise; /** Route applied once, after collection. @internal */ export type MappedCollectRouting = { /** @internal */ kind: "static"; /** @internal */ to?: TurnId; /** @internal */ lifecycleStatus?: ProcessTurnTerminalLifecycleStatus; } | { /** @internal */ kind: "branches"; /** @internal */ branches: Readonly>; /** @internal */ choose(ctx: MappedTurnServerContext): MaybePromise; }; /** * Durable sequential iteration of one LLM turn over frozen items. Items run one * at a time; each item yields a typed result, and business state and routing * change once, when all results are collected. * @public */ export interface MappedLlmTurnSpec { /** Evaluated once when the turn is entered. @public */ items(ctx: MappedTurnServerContext): readonly unknown[] | null | undefined; /** @public */ itemCodec: Codec; /** @public */ resultCodec: Codec; /** @public */ key(input: MappedItemInput): string; /** Defaults to the item key. @public */ label?(input: MappedItemInput): string; /** Applied in the freezing transaction, before any item starts. @public */ stateAfterSnapshot?(input: MappedSnapshotInput): TState; /** @internal */ yields: Readonly>>; /** @internal */ collect: MappedCollect; /** @internal */ routing: MappedCollectRouting; } /** @internal */ export type FrozenMappedItem = Pick; /** @internal */ export interface MappedFreezeResult { /** @internal */ items: FrozenMappedItem[]; /** State to persist in the freezing transaction, when `stateAfterSnapshot` is declared. @internal */ state?: TState; } /** @internal */ export interface MappedCollectResult { /** @internal */ state: TState; /** @internal */ route: { /** @internal */ trigger: string; /** @internal */ nextTurnId?: TurnId; /** @internal */ lifecycleStatus?: ProcessTurnTerminalLifecycleStatus; }; } /** @internal */ export declare function validateMappedTurn(turnId: string, turnDef: LlmTurnDefinition): string[]; /** Evaluates, validates, and serializes the items of a mapped turn. @internal */ export declare function freezeMappedItems(turnId: TurnId, spec: MappedLlmTurnSpec, ctx: MappedTurnServerContext): MappedFreezeResult; /** Maps one item outcome to its serialized, codec-validated result. @internal */ export declare function yieldMappedItemResult(input: { /** @internal */ turnId: TurnId; /** @internal */ spec: MappedLlmTurnSpec; /** @internal */ ctx: MappedTurnServerContext; /** @internal */ iteration: MappedTurnIteration; /** @internal */ event: ProcessTurnOutcomeEvent; }): Promise; /** Collects ordered results once and resolves the turn's single business route. @internal */ export declare function collectMappedResults(input: { /** @internal */ turnId: TurnId; /** @internal */ spec: MappedLlmTurnSpec; /** @internal */ ctx: MappedTurnServerContext; /** Serialized results in frozen item order. @internal */ resultJsons: readonly string[]; }): Promise>; export {}; //# sourceMappingURL=mapped-turn.d.ts.map