import { type GeneratedVideoFacts, type MediaGenerationResult, type VideoGenerationFundingSource, type VideoGenerationPolicy as VideoGenerationPolicyValue } from "@opengeni/contracts"; import type { Database } from "./database.js"; import * as schema from "./schema.js"; export declare const ACTIVE_VIDEO_GENERATION_STATUSES: readonly ["preparing", "prepared", "accepted", "submission_uncertain", "provider_started", "retaining"]; export type VideoGenerationOperation = typeof schema.videoGenerationOperations.$inferSelect; export type VideoGenerationReference = typeof schema.videoGenerationReferences.$inferSelect; export type GeneratedVideoArtifact = typeof schema.generatedVideoArtifacts.$inferSelect; export type VideoGenerationOperationWithReferences = VideoGenerationOperation & { references: VideoGenerationReference[]; }; export declare class VideoGenerationConflictError extends Error { constructor(message: string); } export declare class VideoGenerationCapacityError extends Error { /** Too many videos in progress at once, or no storage left for another. */ readonly limit: "concurrency" | "storage"; constructor(message: string, /** Too many videos in progress at once, or no storage left for another. */ limit: "concurrency" | "storage"); } export declare class VideoGenerationCreditError extends Error { constructor(message?: string); } export declare function getWorkspaceVideoGenerationPolicy(db: Database, workspaceId: string): Promise; export declare function updateWorkspaceVideoGenerationPolicy(db: Database, input: { accountId: string; workspaceId: string; subjectId: string; expectedRevision: number; fundingSource: VideoGenerationFundingSource; enabledModelIds: string[]; defaultModelId: string | null; }): Promise; export type AdmitVideoGenerationOperationInput = { id: string; accountId: string; workspaceId: string; sessionId: string; turnId: string; attemptId: string; toolCallId: string; admissionKey: string; requestDigest: string; promptDigest: string; requestEncrypted: string; modelId: string; sourceMode: string; capabilityRevision: string; policyRevision: number; fundingSource: VideoGenerationFundingSource; pricedCostMicros: number; connectionId: string | null; credentialVersion: number; credentialEncrypted: string; providerIdempotencyKey: string; expectedArtifactId: string; expectedFileId: string; reservedBytes?: number; workspaceQuotaBytes: number; maxConcurrentPerWorkspace: number; recoveryDeadlineAt: Date; references: Array<{ ordinal: number; role: string; contentType: string; sizeBytes: number; sha256: string; stagingObjectKey: string; grantExpiresAt?: Date | null; cleanupAfter: Date; }>; }; export declare function admitVideoGenerationOperation(db: Database, input: AdmitVideoGenerationOperationInput): Promise<{ operation: VideoGenerationOperation; created: boolean; }>; /** * Seal a reference-bearing operation only after every immutable staging object * has been uploaded and independently verified by the worker. The source * sandbox path is intentionally not stored, so a failed preparation can only * be retried by the same logical tool call while its sandbox still exists. */ export declare function markVideoGenerationPrepared(db: Database, input: OperationMutationInput): Promise; /** Final authorization fence. Call only after the accepted function output is durable. */ export declare function markVideoGenerationAccepted(db: Database, input: { accountId: string; workspaceId: string; operationId: string; requestDigest: string; }): Promise; /** * Transactional half of acceptance. The pending function result and this * transition must commit together: the provider reconciler never observes an * accepted operation whose model-visible `accepted` receipt was lost. */ export declare function markVideoGenerationAcceptedInTransaction(tx: Database, input: { workspaceId: string; operation: VideoGenerationOperation; toolCallId?: string; }): Promise; export declare function cancelVideoGenerationBeforeSubmit(db: Database, input: { accountId: string; workspaceId: string; operationId: string; requestDigest: string; reason: string; }): Promise; /** * Turn-interruption half of pre-submit cancellation. It runs under the same * session/turn transaction that closes unresolved tool calls, so an accepted * receipt can never race a cancellation of its operation. */ export declare function cancelUnacceptedVideoGenerationsForToolCallsInTransaction(tx: Database, input: { workspaceId: string; sessionId: string; turnId: string; toolCallIds: readonly string[]; reason: string; now: Date; }): Promise; export declare function claimVideoGenerationOperations(db: Database, input: { owner: string; leaseSeconds: number; limit: number; }): Promise>; export declare function getVideoGenerationOperation(db: Database, workspaceId: string, operationId: string): Promise; export declare function markVideoGenerationSubmissionUncertain(db: Database, input: OperationMutationInput & { nextReconcileAt: Date; error: string; }): Promise; /** * Freeze the exact provider start body before issuing the request. If the * worker disappears after this transaction, recovery replays the same body * and idempotency key rather than reminting URLs or changing request bytes. */ export declare function markVideoGenerationSubmissionIntent(db: Database, input: OperationMutationInput & { encryptedProviderRequest: string; providerRequestExpiresAt: Date; nextReconcileAt: Date; }): Promise; export declare function markVideoGenerationProviderStarted(db: Database, input: OperationMutationInput & { providerJobId: string; nextReconcileAt: Date; }): Promise; export declare function rescheduleVideoGenerationOperation(db: Database, input: OperationMutationInput & { owner?: string; nextReconcileAt: Date; error?: string; }): Promise; export declare function markVideoGenerationRetaining(db: Database, input: OperationMutationInput): Promise; export declare function settleVideoGenerationFailure(db: Database, input: OperationMutationInput & { status: "provider_failed" | "retention_failed" | "outcome_unknown"; publicReason: string; privateError?: string; }): Promise; export type SettleVideoGenerationReadyInput = OperationMutationInput & { fileId: string; bucket: string; objectKey: string; sizeBytes: number; sha256: string; facts: GeneratedVideoFacts; }; export declare function settleVideoGenerationReady(db: Database, input: SettleVideoGenerationReadyInput): Promise<{ operation: VideoGenerationOperation; artifact: GeneratedVideoArtifact; }>; export declare function getGeneratedVideoArtifact(db: Database, workspaceId: string, artifactId: string): Promise<{ artifact: GeneratedVideoArtifact; file: typeof schema.files.$inferSelect; } | null>; export declare function listSessionGeneratedVideoArtifacts(db: Database, workspaceId: string, sessionId: string): Promise>; /** * Record one staging object as erased only after the object-store delete has * succeeded. Deleting first is safe because object deletion is idempotent; a * crash before this CAS simply repeats the same delete on recovery. */ export declare function markVideoGenerationReferenceCleaned(db: Database, input: { accountId: string; workspaceId: string; operationId: string; ordinal: number; stagingObjectKey: string; }): Promise; export declare function markVideoGenerationTerminalUpdate(db: Database, input: { accountId: string; workspaceId: string; operationId: string; state: "leased" | "delivered" | "suppressed"; updateId?: string; }): Promise; export declare function markVideoGenerationTerminalUpdateInTransaction(tx: Database, input: { workspaceId: string; operationId: string; state: "leased" | "delivered" | "suppressed"; updateId?: string; }): Promise; export declare function mediaGenerationResultForOperation(input: { operation: VideoGenerationOperation; readyReceipt?: Extract["receipt"]; }): MediaGenerationResult; /** Build the compact public/model terminal envelope from durable canonical rows. */ export declare function mediaGenerationResultForStoredOperation(db: Database, operation: VideoGenerationOperation): Promise; /** * The terminal result of a stored operation, read by a background service * for the chat that requested it. An Only-me chat and its rows are visible to * its owner alone, so the service reads on that owner's behalf; the * operation's private file owner keeps an Only-me file readable. */ export declare function mediaGenerationResultForReconciledOperation(db: Database, operation: VideoGenerationOperation, serviceSubjectId: string): Promise; export declare function getVideoGenerationOperationSummary(db: Database, workspaceId: string, operationId: string): Promise; type OperationMutationInput = { accountId: string; workspaceId: string; operationId: string; requestDigest: string; }; export {};