import { type TurnExecutionPolicyV1 } from "@opengeni/contracts"; import type { SessionActivityDatabase } from "./database.js"; import * as schema from "./schema.js"; /** * Releasing a turn parked on subscription capacity. * * A capacity wait belongs to its accepted turn, so on its own it outlives both * a model switch (which changes only the chat's future turns) and Pause * (which holds the wait for Resume). When a person or parent switches the * chat's model, or pauses it, they mean the waiting work: a model switch * moves the waiting turn onto the new model and it continues now; Pause * stops the wait, and Resume (or a later model switch) continues the turn. * * The released turn becomes `recovering` on the same logical turn, exactly * as a capacity resume or a paused running turn does, so nothing the model * already saw is replayed differently. */ export declare const CAPACITY_WAIT_RELEASE_KEY = "capacityWaitReleaseV1"; export type CapacityWaitReleaseTrigger = "model_switch" | "session_pause"; type SessionRow = typeof schema.sessions.$inferSelect; type TurnRow = typeof schema.sessionTurns.$inferSelect; /** Whether this session's active turn is one a release applies to now. */ export declare function capacityWaitReleasable(session: Pick, turn: TurnRow, trigger: CapacityWaitReleaseTrigger): boolean; /** * The caller holds the canonical session-event locks for `sessionId` and * `turnId` (and, for Pause, has already committed the control change in this * transaction). Returns the inserted event ids, or null when the turn is not * releasable. */ export declare function releaseCapacityWaitingTurnInTransaction(db: SessionActivityDatabase, input: { accountId: string; workspaceId: string; sessionId: string; turnId: string; trigger: CapacityWaitReleaseTrigger; /** The new model's accepted execution policy (model switch only). */ executionPolicy?: TurnExecutionPolicyV1; now?: Date; }): Promise<{ eventIds: string[]; paused: boolean; } | null>; export {};