import type { TurnDriveResult } from '@tangle-network/sandbox'; import type { Outcome } from '../sandbox/outcome'; /** The stable identity a Workflow reuses on every retry of one turn. */ export interface DetachedTurnWorkflowIdentity { /** Sandbox session resume key. */ sessionId: string; /** Sandbox completed-turn idempotency key. */ turnId: string; } /** The part of Cloudflare's Workflow event needed by the tick. */ export interface CloudflareWorkflowEventLike { payload: TPayload; } /** A duration accepted by Cloudflare Workflow `step.sleep`. */ export type CloudflareWorkflowSleepDuration = `${number} ${'second' | 'seconds' | 'minute' | 'minutes' | 'hour' | 'hours' | 'day' | 'days' | 'week' | 'weeks' | 'month' | 'months' | 'year' | 'years'}` | number; /** The durable Workflow operations used by the tick. */ export interface CloudflareWorkflowStepLike { do(name: string, callback: (context: unknown) => Promise): Promise; sleep(name: string, duration: CloudflareWorkflowSleepDuration): Promise; } /** The states returned by the Sandbox `driveTurn` primitive. */ export type DetachedTurnDriveState = TurnDriveResult['state']; /** The terminal result passed to product settlement. */ export type DetachedTurnTerminalResult = Exclude; /** A drive call's retryable transport boundary. */ export type DetachedTurnDriveOutcome = Outcome; /** Options for one durable detached-turn Workflow run. */ export interface DetachedTurnWorkflowTickOptions { /** The Workflow event. Its payload must keep the same session and turn ids. */ event: CloudflareWorkflowEventLike; /** Cloudflare's durable step runner. */ step: CloudflareWorkflowStepLike; /** * Run exactly one `driveSandboxTurn`/`box.driveTurn` pass. * * The callback runs inside one `step.do`. A transport failure is thrown from * that step so Cloudflare retries the pass with the same deterministic ids. */ drive: (payload: TPayload) => Promise; /** * Read the completed Sandbox cache/session records and persist the product's * deterministic assistant row. This callback MUST be idempotent because a * Worker can stop after the write and before the Workflow step commits. */ settle: (payload: TPayload, result: DetachedTurnTerminalResult) => Promise; /** Delay between one-tick drive passes. */ pollDelay?: CloudflareWorkflowSleepDuration; /** Stable prefix for the Workflow's drive and wait step names. */ stepName?: string; } /** * Drive one detached Sandbox turn from a Cloudflare Workflow. * * Each drive step makes one prompt admission/status pass and returns promptly. * A running pass sleeps durably before the next pass. The final settlement is * also a step, so replayed Workflow execution never holds a live stream open. */ export declare function runDetachedTurnWorkflowTick(options: DetachedTurnWorkflowTickOptions): Promise;