import type { ComputeBillingItem } from './worker-api-types'; import type { DbLogicalTable, DbSessionOperation } from './db-session'; import type { PlayRowUpdate } from './ctx-types'; import type { PlaySheetContract } from '../plays/static-pipeline'; import type { PlayRunLedgerEvent } from './run-ledger'; import type { WorkReceiptFailureKind } from './work-receipts'; import type { ToolExecutionFailureV1 } from '../tool-execution-error'; import type { DocflowObservationUpsert } from './docflow-observation'; export type RuntimeAppendRunEventsAction = { action: 'append_run_events'; playId: string; events: PlayRunLedgerEvent[]; }; export type RuntimeSheetAction = | { action: 'ensure_sheet'; playName: string; tableNamespace: string; sheetContract?: PlaySheetContract | null; userEmail?: string | null; } | { action: 'create_db_session'; playName: string; target: { tableNamespace: string; logicalTable: DbLogicalTable; }; operations: DbSessionOperation[]; limits?: { maxRows?: number; maxBytes?: number; maxRequests?: number; }; sheetContract?: PlaySheetContract | null; ttlSeconds?: number; userEmail?: string | null; } | { action: 'apply_row_updates'; playName: string; tableNamespace: string; sheetContract?: PlaySheetContract | null; contractSnapshot?: unknown; runId: string; userEmail?: string | null; updates: Array & { runId?: string }>; }; export type RuntimeArtifactAction = | { action: 'create_signed_artifact_url'; storageKey: string; } | { action: 'create_signed_staged_file_url'; file: { storageKey: string }; }; export type RuntimeBillingAction = | { action: 'compute_billing_upsert'; sessionId: string; orgId: string; userId?: string | null; operation: string; workflowId?: string; runId?: string; } | { action: 'compute_billing_record_item'; sessionId: string; orgId: string; userId?: string | null; operation: string; item: ComputeBillingItem; } | { action: 'compute_billing_finalize'; sessionId: string; orgId: string; userId?: string | null; operation: string; status: 'completed' | 'error'; workflowId?: string; runId?: string; maxCreditsPerRun?: number | null; finalItem?: ComputeBillingItem; }; export type RuntimeReceiptAction = | { action: 'get_runtime_step_receipt'; playName: string; runId: string; key: string; } | { action: 'get_runtime_step_receipts'; playName: string; runId: string; keys: string[]; } | { action: 'acquire_runtime_receipt_execution_lock'; playName: string; runId: string; key: string; ownerExecutionId: string; ttlMs: number; } | { action: 'release_runtime_receipt_execution_lock'; playName: string; runId: string; key: string; ownerExecutionId: string; } | { action: 'claim_runtime_step_receipt'; playName: string; runId: string; key: string; leaseId?: string; runAttempt?: number | null; leaseAware?: boolean; reclaimRunning?: boolean; forceRefresh?: boolean; forceFailedRefresh?: boolean; } | { action: 'claim_runtime_step_receipts'; playName: string; runId: string; keys: string[]; leaseIds?: string[]; runAttempt?: number | null; leaseAware?: boolean; reclaimRunning?: boolean; forceRefresh?: boolean; forceFailedRefresh?: boolean; } | { action: 'complete_runtime_step_receipt'; playName: string; runId: string; key: string; runAttempt?: number | null; leaseId?: string | null; output: unknown; } | { action: 'release_runtime_step_receipt'; playName: string; runId: string; key: string; runAttempt?: number | null; leaseId?: string | null; } | { action: 'fail_runtime_step_receipt'; playName: string; runId: string; key: string; runAttempt?: number | null; leaseId?: string | null; error: string; errorPayload?: ToolExecutionFailureV1 | null; failureKind?: WorkReceiptFailureKind | null; } | { action: 'skip_runtime_step_receipt'; playName: string; runId: string; key: string; runAttempt?: number | null; leaseId?: string | null; output?: unknown; } | { action: 'mark_runtime_step_receipt_running'; playName: string; runId: string; key: string; runAttempt?: number | null; leaseId?: string | null; } | { action: 'mark_runtime_step_receipts_running'; playName: string; runId: string; receipts: RuntimeReceiptLease[]; } | { action: 'mark_runtime_step_receipts_queued'; playName: string; runId: string; receipts: RuntimeReceiptLease[]; } | { action: 'complete_runtime_step_receipts'; playName: string; runId: string; receipts: RuntimeReceiptCompletion[]; } | { action: 'fail_runtime_step_receipts'; playName: string; runId: string; receipts: RuntimeReceiptFailure[]; } | { action: 'heartbeat_runtime_step_receipts'; playName: string; runId: string; runAttempt?: number | null; leaseId?: string; leaseIds?: string[]; keys: string[]; } | ({ action: 'observe_docflow_node'; playName: string; } & DocflowObservationUpsert); export type RuntimeReceiptLease = { key: string; runId: string; runAttempt?: number | null; leaseId?: string | null; }; export type RuntimeReceiptCompletion = RuntimeReceiptLease & { output: unknown; }; export type RuntimeReceiptFailure = RuntimeReceiptLease & { error: string; errorPayload?: ToolExecutionFailureV1 | null; failureKind?: WorkReceiptFailureKind | null; }; export type RuntimePlayResolutionAction = { action: 'resolve_play'; playRef: string; }; export type RuntimeResultsAction = { action: 'save_results'; playId: string; userId?: string | null; result: { success: boolean; error?: string; publicResult?: Record | null; maxCreditsPerRun?: number | null; }; }; export type RuntimeApiAction = | RuntimePlayResolutionAction | RuntimeSheetAction | RuntimeArtifactAction | RuntimeAppendRunEventsAction | RuntimeResultsAction | RuntimeBillingAction | RuntimeReceiptAction; export type RuntimeBatchAction = { action: 'batch'; events: RuntimeApiAction[]; }; export const runtimeRunActions = { appendEvents( input: Omit, ): RuntimeAppendRunEventsAction { return { action: 'append_run_events', ...input }; }, } as const; export const runtimeBillingActions = { finalize( input: Omit< Extract, 'action' >, ) { return { action: 'compute_billing_finalize', ...input, } satisfies RuntimeBillingAction; }, } as const;