import type { FileAsset, FileUploadStatus } from "@opengeni/contracts"; import type { Database } from "./database.js"; /** A route's residency claim (never evidence), as `usage_events.processing_residency` stores it. */ type UsageEventProcessingResidency = { geography: string; deploymentType: string; regions: readonly string[]; }; export type GeneratedImageSourceStrategy = "native_hosted" | "provider_adapter"; export type GeneratedImageArtifactStatus = "pending" | "ready"; export type ImageGenerationOperationStatus = "prepared" | "provider_started" | "completed" | "outcome_unknown" | "retention_failed"; export type ImageGenerationCreditState = "not_applicable" | "pending" | "debited"; export type ImageGenerationCreditRefusalCode = "insufficient_credits" | "allowance_exhausted"; /** * Opengeni credits refused a priced image before any provider request. The * message is plain enough to show the person as-is. */ export declare class ImageGenerationCreditError extends Error { readonly code: ImageGenerationCreditRefusalCode; constructor(message?: string, code?: ImageGenerationCreditRefusalCode); } export type ImageGenerationOperation = { id: string; accountId: string; workspaceId: string; sessionId: string | null; turnId: string | null; attemptId: string | null; operationKey: string; toolCallId: string; providerId: string; providerBindingHash: string; modelId: string; requestDigest: string; expectedArtifactId: string; status: ImageGenerationOperationStatus; pricedCostMicros: number; creditState: ImageGenerationCreditState; /** * The turn's canonical chat model, frozen with the price. Plan and trial * grants that cover that model pay for the image as they pay for the chat. */ creditUsageModelId: string | null; providerStartedAt: Date | null; completedAt: Date | null; lastError: string | null; createdAt: Date; updatedAt: Date; }; export type GeneratedImageArtifact = { artifactId: string; accountId: string; workspaceId: string; sessionId: string | null; turnId: string | null; attemptId: string | null; uploadId: string | null; settlementKey: string; toolCallId: string; sourceStrategy: GeneratedImageSourceStrategy; providerId: string; providerBindingHash: string; providerItemId: string | null; status: GeneratedImageArtifactStatus; mediaType: string; sizeBytes: number; sha256: string; width: number; height: number; sandboxPath: string; readyAt: Date | null; lastError: string | null; createdAt: Date; updatedAt: Date; uploadStatus: FileUploadStatus | null; file: FileAsset; }; export type PrepareGeneratedImageArtifactInput = { artifactId: string; uploadId: string; accountId: string; workspaceId: string; sessionId: string; turnId: string; attemptId: string; settlementKey: string; toolCallId: string; sourceStrategy: GeneratedImageSourceStrategy; providerId: string; providerBindingHash: string; providerItemId: string | null; mediaType: string; sizeBytes: number; sha256: string; width: number; height: number; sandboxPath: string; filename: string; safeFilename: string; bucket: string; objectKey: string; uploadExpiresAt: Date; }; export type PrepareImageGenerationOperationInput = Omit & { /** Opengeni-credit customer price; zero or omitted when credits do not fund it. */ pricedCostMicros?: number; /** The turn's canonical chat model whose plan and trial grants may pay. */ creditUsageModelId?: string; }; export declare function prepareImageGenerationOperation(db: Database, input: PrepareImageGenerationOperationInput): Promise<{ operation: ImageGenerationOperation; created: boolean; }>; export declare function getImageGenerationOperation(db: Database, workspaceId: string, operationId: string): Promise; export declare function beginImageGenerationOperation(db: Database, input: { accountId: string; workspaceId: string; operationId: string; operationKey: string; providerBindingHash: string; expectedArtifactId: string; }): Promise<{ operation: ImageGenerationOperation; started: boolean; }>; /** * Return a paid-operation row to its retryable prepared state when a durable * provider-dispatch fence rejected before any provider request was admitted. * This is intentionally narrower than outcome reconciliation: a caller must * prove the provider boundary was never crossed, or that the provider refused * the request outright without doing paid work, before using this transition. */ export declare function resetImageGenerationOperationBeforeProviderDispatch(db: Database, input: { accountId: string; workspaceId: string; operationId: string; operationKey: string; error: string; }): Promise; export declare function markImageGenerationOperationOutcomeUnknown(db: Database, input: { accountId: string; workspaceId: string; operationId: string; operationKey: string; error: string; }): Promise; /** Provider completed, but its bytes could not be durably retained. Never replay the paid call. */ export declare function markImageGenerationOperationRetentionFailed(db: Database, input: { accountId: string; workspaceId: string; operationId: string; operationKey: string; error: string; }): Promise; export declare function completeImageGenerationOperation(db: Database, input: { accountId: string; workspaceId: string; operationId: string; operationKey: string; /** Where the image route processed the request, recorded on its usage event. */ processingResidency?: UsageEventProcessingResidency; }): Promise; /** * Reserve one deterministic file/upload/correlation triple. Concurrent retries * converge on the same identities and must agree on every immutable byte fact. */ export declare function prepareGeneratedImageArtifact(db: Database, input: PrepareGeneratedImageArtifactInput): Promise<{ artifact: GeneratedImageArtifact; created: boolean; }>; export declare function getGeneratedImageArtifact(db: Database, workspaceId: string, artifactId: string): Promise; /** Metadata only. Callers must separately prove file read authority for every id. */ export declare function getGeneratedImageArtifacts(db: Database, workspaceId: string, artifactIds: readonly string[]): Promise; export declare function settleGeneratedImageArtifactReady(db: Database, input: { accountId: string; workspaceId: string; artifactId: string; settlementKey: string; /** * The adapter operation that produced this image. It completes, and a * priced image is debited, in the same transaction that makes the image * ready, so no crash can leave a delivered image uncharged. */ operation?: { operationId: string; operationKey: string; }; }): Promise; export declare function recordGeneratedImageArtifactError(db: Database, input: { accountId: string; workspaceId: string; artifactId: string; settlementKey: string; error: string; }): Promise; export declare function listReadyGeneratedImageArtifactsForSession(db: Database, workspaceId: string, sessionId: string): Promise; export {};