@fungi.computer/darkroom 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +315 -2
  3. package/dist/app-media-contracts.d.ts +499 -0
  4. package/dist/app-media-contracts.js +96 -0
  5. package/dist/browser-failure.d.ts +40 -0
  6. package/dist/browser-failure.js +39 -0
  7. package/dist/browser.d.ts +2 -0
  8. package/dist/browser.js +1 -0
  9. package/dist/cloudflare/provider.d.ts +13 -0
  10. package/dist/cloudflare/provider.js +140 -0
  11. package/dist/cloudflare/reference-images.d.ts +42 -0
  12. package/dist/cloudflare/reference-images.js +102 -0
  13. package/dist/cloudflare.d.ts +6 -0
  14. package/dist/cloudflare.js +4 -0
  15. package/dist/cost-estimate.d.ts +22 -0
  16. package/dist/cost-estimate.js +76 -0
  17. package/dist/effect.d.ts +2 -0
  18. package/dist/effect.js +2 -0
  19. package/dist/execution-error.d.ts +54 -0
  20. package/dist/execution-error.js +62 -0
  21. package/dist/failure.d.ts +2 -0
  22. package/dist/failure.js +8 -0
  23. package/dist/gateway-models.d.ts +23 -0
  24. package/dist/gateway-models.js +77 -0
  25. package/dist/gateway-wire.d.ts +16 -0
  26. package/dist/gateway-wire.js +22 -0
  27. package/dist/index.d.ts +361 -0
  28. package/dist/index.js +607 -0
  29. package/dist/media-binding.d.ts +291 -0
  30. package/dist/media-binding.js +149 -0
  31. package/dist/media-generation.d.ts +10 -0
  32. package/dist/media-generation.js +110 -0
  33. package/dist/media-operation-contract.d.ts +104 -0
  34. package/dist/media-operation-contract.js +29 -0
  35. package/dist/media-operation-do.d.ts +55 -0
  36. package/dist/media-operation-do.js +105 -0
  37. package/dist/media-operation-owner.d.ts +301 -0
  38. package/dist/media-operation-owner.js +903 -0
  39. package/dist/media-operation-storage.d.ts +81 -0
  40. package/dist/media-operation-storage.js +1 -0
  41. package/dist/media-operation.d.ts +33 -0
  42. package/dist/media-operation.js +230 -0
  43. package/dist/model-catalog.d.ts +456 -0
  44. package/dist/model-catalog.js +565 -0
  45. package/dist/neurons.d.ts +4 -0
  46. package/dist/neurons.js +4 -0
  47. package/dist/provenance-bytes.d.ts +3 -0
  48. package/dist/provenance-bytes.js +15 -0
  49. package/dist/provenance-export.d.ts +23 -0
  50. package/dist/provenance-export.js +103 -0
  51. package/dist/provenance-jpeg.d.ts +3 -0
  52. package/dist/provenance-jpeg.js +76 -0
  53. package/dist/provenance-png.d.ts +1 -0
  54. package/dist/provenance-png.js +21 -0
  55. package/dist/provenance-xmp.d.ts +2 -0
  56. package/dist/provenance-xmp.js +54 -0
  57. package/dist/provenance.d.ts +20 -0
  58. package/dist/provenance.js +58 -0
  59. package/dist/server.d.ts +158 -0
  60. package/dist/server.js +207 -0
  61. package/dist/video-providers/index.d.ts +14 -0
  62. package/dist/video-providers/index.js +14 -0
  63. package/dist/video-providers/minimax.d.ts +25 -0
  64. package/dist/video-providers/minimax.js +63 -0
  65. package/dist/video-providers/reference-encoding.d.ts +4 -0
  66. package/dist/video-providers/reference-encoding.js +11 -0
  67. package/dist/video-providers/types.d.ts +28 -0
  68. package/dist/video-providers/types.js +1 -0
  69. package/dist/video-providers/unified.d.ts +18 -0
  70. package/dist/video-providers/unified.js +52 -0
  71. package/docs/api/README.md +16 -0
  72. package/docs/api/app-media-contracts.md +507 -0
  73. package/docs/api/browser.md +126 -0
  74. package/docs/api/cloudflare.md +678 -0
  75. package/docs/api/effect.md +39 -0
  76. package/docs/api/index.md +1775 -0
  77. package/docs/api/modules.md +19 -0
  78. package/docs/api/provenance-export.md +114 -0
  79. package/docs/api/server.md +1672 -0
  80. package/package.json +110 -3
@@ -0,0 +1,29 @@
1
+ import * as z from "zod";
2
+ /** Decode a completed generation, destination path and estimated or settled price. */
3
+ export const mediaResultSchema = z.strictObject({
4
+ /** Output byte length. */
5
+ bytes: z.number().int().positive(),
6
+ /** Admitted price in milliunits, where 1 cent is 1,000 milliunits. */
7
+ costMilliunits: z.number().int().nonnegative(),
8
+ /** Fixed destination or reference file path. */
9
+ path: z.string().min(1).max(1_024),
10
+ /** Actual output encoding. */
11
+ format: z.enum({
12
+ /** PNG image encoding. */
13
+ png: "png",
14
+ /** JPEG image encoding. */
15
+ jpeg: "jpeg",
16
+ /** GIF image encoding. */
17
+ gif: "gif",
18
+ /** WebP image encoding. */
19
+ webp: "webp",
20
+ /** MP4 video encoding. */
21
+ mp4: "mp4",
22
+ }),
23
+ /** Requested image height or nominal video selector, not decoded MP4 dimensions. */
24
+ height: z.number().int().positive(),
25
+ /** Provider catalog model identifier. */
26
+ model: z.string().min(1).max(256),
27
+ /** Requested image width or nominal video selector, not decoded MP4 dimensions. */
28
+ width: z.number().int().positive(),
29
+ });
@@ -0,0 +1,55 @@
1
+ import { DurableObject } from "cloudflare:workers";
2
+ import { type MediaAiPort } from "./cloudflare/provider.js";
3
+ import type { MediaProvider } from "./index.js";
4
+ import { MediaOperationOwner, type MediaOperationEnvironment } from "./media-operation-owner.js";
5
+ export type { MediaOperationRequest, MediaOperationCoordinates, MediaOperationEnvironment, } from "./media-operation-owner.js";
6
+ /** Retention storage and native background provider bindings for the operation DO. */
7
+ export type MediaOperationCloudflareEnvironment = MediaOperationEnvironment & Readonly<{
8
+ /** Workers AI binding for alarm-driven generation. */
9
+ AI?: MediaAiPort;
10
+ /** Optional AI Gateway route for background calls. */
11
+ AI_GATEWAY_ID?: string;
12
+ }>;
13
+ /** Cloudflare lifecycle and RPC surface around the durable media owner. */
14
+ export declare class MediaOperationDO extends DurableObject<MediaOperationCloudflareEnvironment> {
15
+ protected readonly owner: MediaOperationOwner;
16
+ constructor(ctx: DurableObjectState, env: MediaOperationCloudflareEnvironment);
17
+ /** A host may pin the namespace through its own local lifecycle facts. */
18
+ protected retainedNamespace(): string | null;
19
+ /** Hosts may supply their own provider for background generation. */
20
+ protected mediaProvider(): MediaProvider | undefined;
21
+ /** {@inheritDoc MediaOperationOwner.read} */
22
+ read(...input: Parameters<MediaOperationOwner["read"]>): ReturnType<MediaOperationOwner["read"]>;
23
+ /** {@inheritDoc MediaOperationOwner.preflightErasure} */
24
+ preflightErasure(...input: Parameters<MediaOperationOwner["preflightErasure"]>): ReturnType<MediaOperationOwner["preflightErasure"]>;
25
+ /** {@inheritDoc MediaOperationOwner.erase} */
26
+ erase(...input: Parameters<MediaOperationOwner["erase"]>): ReturnType<MediaOperationOwner["erase"]>;
27
+ /** {@inheritDoc MediaOperationOwner.readErasure} */
28
+ readErasure(...input: Parameters<MediaOperationOwner["readErasure"]>): ReturnType<MediaOperationOwner["readErasure"]>;
29
+ /** {@inheritDoc MediaOperationOwner.admit} */
30
+ admit(...input: Parameters<MediaOperationOwner["admit"]>): ReturnType<MediaOperationOwner["admit"]>;
31
+ /** {@inheritDoc MediaOperationOwner.claim} */
32
+ claim(...input: Parameters<MediaOperationOwner["claim"]>): ReturnType<MediaOperationOwner["claim"]>;
33
+ /** {@inheritDoc MediaOperationOwner.recordEstimate} */
34
+ recordEstimate(...input: Parameters<MediaOperationOwner["recordEstimate"]>): ReturnType<MediaOperationOwner["recordEstimate"]>;
35
+ /** {@inheritDoc MediaOperationOwner.dispatchInBackground} */
36
+ dispatchInBackground(...input: Parameters<MediaOperationOwner["dispatchInBackground"]>): ReturnType<MediaOperationOwner["dispatchInBackground"]>;
37
+ /** {@inheritDoc MediaOperationOwner.alarm} */
38
+ alarm(...input: Parameters<MediaOperationOwner["alarm"]>): ReturnType<MediaOperationOwner["alarm"]>;
39
+ /** {@inheritDoc MediaOperationOwner.interruptGeneration} */
40
+ interruptGeneration(...input: Parameters<MediaOperationOwner["interruptGeneration"]>): ReturnType<MediaOperationOwner["interruptGeneration"]>;
41
+ /** {@inheritDoc MediaOperationOwner.recordGenerated} */
42
+ recordGenerated(...input: Parameters<MediaOperationOwner["recordGenerated"]>): ReturnType<MediaOperationOwner["recordGenerated"]>;
43
+ /** {@inheritDoc MediaOperationOwner.readGenerated} */
44
+ readGenerated(...input: Parameters<MediaOperationOwner["readGenerated"]>): ReturnType<MediaOperationOwner["readGenerated"]>;
45
+ /** {@inheritDoc MediaOperationOwner.releaseWrite} */
46
+ releaseWrite(...input: Parameters<MediaOperationOwner["releaseWrite"]>): ReturnType<MediaOperationOwner["releaseWrite"]>;
47
+ /** {@inheritDoc MediaOperationOwner.recordWritten} */
48
+ recordWritten(...input: Parameters<MediaOperationOwner["recordWritten"]>): ReturnType<MediaOperationOwner["recordWritten"]>;
49
+ /** {@inheritDoc MediaOperationOwner.recordWrittenWithoutSettlement} */
50
+ recordWrittenWithoutSettlement(...input: Parameters<MediaOperationOwner["recordWrittenWithoutSettlement"]>): ReturnType<MediaOperationOwner["recordWrittenWithoutSettlement"]>;
51
+ /** {@inheritDoc MediaOperationOwner.recordSucceeded} */
52
+ recordSucceeded(...input: Parameters<MediaOperationOwner["recordSucceeded"]>): ReturnType<MediaOperationOwner["recordSucceeded"]>;
53
+ /** {@inheritDoc MediaOperationOwner.releaseEstimate} */
54
+ releaseEstimate(...input: Parameters<MediaOperationOwner["releaseEstimate"]>): ReturnType<MediaOperationOwner["releaseEstimate"]>;
55
+ }
@@ -0,0 +1,105 @@
1
+ import { DurableObject } from "cloudflare:workers";
2
+ import { createWorkersAiMediaProvider, } from "./cloudflare/provider.js";
3
+ import { MediaOperationOwner, } from "./media-operation-owner.js";
4
+ /** Cloudflare lifecycle and RPC surface around the durable media owner. */
5
+ export class MediaOperationDO extends DurableObject {
6
+ owner;
7
+ constructor(ctx, env) {
8
+ super(ctx, env);
9
+ this.owner = new MediaOperationOwner({
10
+ id: { name: ctx.id.name },
11
+ blockConcurrencyWhile: (body) => ctx.blockConcurrencyWhile(body),
12
+ storage: {
13
+ sql: ctx.storage.sql,
14
+ transactionSync: (body) => ctx.storage.transactionSync(body),
15
+ isErased: async () => (await ctx.storage.get("botanical:erased")) === true,
16
+ markErased: () => ctx.storage.put("botanical:erased", true),
17
+ listKeys: async () => [...(await ctx.storage.list()).keys()],
18
+ deleteAlarm: () => ctx.storage.deleteAlarm(),
19
+ deleteAll: () => ctx.storage.deleteAll(),
20
+ getAlarm: () => ctx.storage.getAlarm(),
21
+ setAlarm: (timestamp) => ctx.storage.setAlarm(timestamp),
22
+ },
23
+ }, env, () => this.mediaProvider(), { namespace: () => this.retainedNamespace() });
24
+ }
25
+ /** A host may pin the namespace through its own local lifecycle facts. */
26
+ retainedNamespace() {
27
+ return null;
28
+ }
29
+ /** Hosts may supply their own provider for background generation. */
30
+ mediaProvider() {
31
+ if (this.env.AI === undefined)
32
+ return undefined;
33
+ return createWorkersAiMediaProvider(this.env.AI, this.env.AI_GATEWAY_ID === undefined
34
+ ? undefined
35
+ : { gateway: { id: this.env.AI_GATEWAY_ID } });
36
+ }
37
+ /** {@inheritDoc MediaOperationOwner.read} */
38
+ read(...input) {
39
+ return this.owner.read(...input);
40
+ }
41
+ /** {@inheritDoc MediaOperationOwner.preflightErasure} */
42
+ preflightErasure(...input) {
43
+ return this.owner.preflightErasure(...input);
44
+ }
45
+ /** {@inheritDoc MediaOperationOwner.erase} */
46
+ erase(...input) {
47
+ return this.owner.erase(...input);
48
+ }
49
+ /** {@inheritDoc MediaOperationOwner.readErasure} */
50
+ readErasure(...input) {
51
+ return this.owner.readErasure(...input);
52
+ }
53
+ /** {@inheritDoc MediaOperationOwner.admit} */
54
+ admit(...input) {
55
+ return this.owner.admit(...input);
56
+ }
57
+ /** {@inheritDoc MediaOperationOwner.claim} */
58
+ claim(...input) {
59
+ return this.owner.claim(...input);
60
+ }
61
+ /** {@inheritDoc MediaOperationOwner.recordEstimate} */
62
+ recordEstimate(...input) {
63
+ return this.owner.recordEstimate(...input);
64
+ }
65
+ /** {@inheritDoc MediaOperationOwner.dispatchInBackground} */
66
+ dispatchInBackground(...input) {
67
+ return this.owner.dispatchInBackground(...input);
68
+ }
69
+ /** {@inheritDoc MediaOperationOwner.alarm} */
70
+ alarm(...input) {
71
+ return this.owner.alarm(...input);
72
+ }
73
+ /** {@inheritDoc MediaOperationOwner.interruptGeneration} */
74
+ interruptGeneration(...input) {
75
+ return this.owner.interruptGeneration(...input);
76
+ }
77
+ /** {@inheritDoc MediaOperationOwner.recordGenerated} */
78
+ recordGenerated(...input) {
79
+ return this.owner.recordGenerated(...input);
80
+ }
81
+ /** {@inheritDoc MediaOperationOwner.readGenerated} */
82
+ readGenerated(...input) {
83
+ return this.owner.readGenerated(...input);
84
+ }
85
+ /** {@inheritDoc MediaOperationOwner.releaseWrite} */
86
+ releaseWrite(...input) {
87
+ return this.owner.releaseWrite(...input);
88
+ }
89
+ /** {@inheritDoc MediaOperationOwner.recordWritten} */
90
+ recordWritten(...input) {
91
+ return this.owner.recordWritten(...input);
92
+ }
93
+ /** {@inheritDoc MediaOperationOwner.recordWrittenWithoutSettlement} */
94
+ recordWrittenWithoutSettlement(...input) {
95
+ return this.owner.recordWrittenWithoutSettlement(...input);
96
+ }
97
+ /** {@inheritDoc MediaOperationOwner.recordSucceeded} */
98
+ recordSucceeded(...input) {
99
+ return this.owner.recordSucceeded(...input);
100
+ }
101
+ /** {@inheritDoc MediaOperationOwner.releaseEstimate} */
102
+ releaseEstimate(...input) {
103
+ return this.owner.releaseEstimate(...input);
104
+ }
105
+ }
@@ -0,0 +1,301 @@
1
+ import { type MediaGenerationSettings } from "./index.js";
2
+ import { z } from "zod";
3
+ import type { MediaOperationContext, MediaOperationBucket } from "./media-operation-storage.js";
4
+ import type { MediaProvider, MediaReferenceBytes } from "./index.js";
5
+ /** Fixed generation destination captured before provider dispatch. */
6
+ export declare const mediaOperationDestinationSchema: z.ZodLazy<z.ZodObject<{
7
+ computerId: z.ZodString;
8
+ path: z.ZodString;
9
+ outputFormat: z.ZodOptional<z.ZodEnum<{
10
+ readonly png: "png";
11
+ readonly jpeg: "jpeg";
12
+ readonly webp: "webp";
13
+ }>>;
14
+ }, z.core.$strict>>;
15
+ /** Normalized generation and its fixed destination, captured for exact replay. */
16
+ export type MediaOperationRequest = MediaGenerationSettings & z.output<typeof mediaOperationDestinationSchema>;
17
+ /** Decode host namespace and owner identity. */
18
+ export declare const mediaOperationCoordinatesSchema: z.ZodObject<{
19
+ namespace: z.ZodString;
20
+ owner: z.ZodString;
21
+ }, z.core.$strict>;
22
+ /** Host-owned namespace and owner identity for one durable operation. */
23
+ export type MediaOperationCoordinates = z.output<typeof mediaOperationCoordinatesSchema>;
24
+ /** Decode durable generation, save and settlement states. */
25
+ export declare const mediaOperationStateSchema: z.ZodEnum<{
26
+ /** Host identity and input captured. */
27
+ readonly admitted: "admitted";
28
+ /** Exclusive input preparation lease. */
29
+ readonly estimating: "estimating";
30
+ /** Provider dispatch admitted; output not yet retained. */
31
+ readonly generating: "generating";
32
+ /** Generated output retained; destination save in progress. */
33
+ readonly writing: "writing";
34
+ /** Destination committed; idempotent host settlement pending. */
35
+ readonly charging: "charging";
36
+ /** Unmetered generation and destination write completed with a quote. */
37
+ readonly written: "written";
38
+ /** Generation and settlement completed. */
39
+ readonly succeeded: "succeeded";
40
+ /** Provider execution ended without a reusable output. */
41
+ readonly interrupted: "interrupted";
42
+ }>;
43
+ /** Durable generation, save and settlement states. */
44
+ export type MediaOperationState = z.output<typeof mediaOperationStateSchema>;
45
+ /** Decode retained or saved output size and encoding. */
46
+ export declare const mediaImageSchema: z.ZodLazy<z.ZodObject<{
47
+ bytes: z.ZodNumber;
48
+ format: z.ZodString;
49
+ }, z.core.$strict>>;
50
+ /** Byte length and encoding of generated or saved output. */
51
+ export type MediaImage = z.output<typeof mediaImageSchema>;
52
+ /** Decode the settled receipt, including the host-admitted customer price. */
53
+ export declare const mediaOperationResultSchema: z.ZodLazy<z.ZodObject<{
54
+ generationId: z.ZodString;
55
+ bytes: z.ZodNumber;
56
+ format: z.ZodString;
57
+ costMilliunits: z.ZodNumber;
58
+ }, z.core.$strict>>;
59
+ /** Settled generation receipt with the host-admitted customer price. */
60
+ export type MediaOperationResult = z.output<typeof mediaOperationResultSchema>;
61
+ /** The only operation shape safe to return outside the owner. */
62
+ export type MediaOperationProjection = Readonly<{
63
+ /** Durable object name identifying this operation. */
64
+ operationId: string;
65
+ /** Retry identity chosen by the caller. */
66
+ requestId: string;
67
+ /** Host isolation namespace. */
68
+ namespace: string;
69
+ /** Host owner within the namespace. */
70
+ owner: string;
71
+ /** Current durable lifecycle state. */
72
+ state: MediaOperationState;
73
+ /** Terminal format mismatch after provider execution. */
74
+ spentFailure: "output_format_mismatch" | null;
75
+ /** Definitive provider refusal with no delivered or billable output. */
76
+ providerRefusal: "safety_filter_refused" | null;
77
+ /** Pinned host price or unmetered quote. */
78
+ estimatedCostMilliunits: number | null;
79
+ /** Retained or saved image metadata. */
80
+ image: MediaImage | null;
81
+ /** Settled receipt when generation and billing completed. */
82
+ result: MediaOperationResult | null;
83
+ /** Admission timestamp in milliseconds since the epoch. */
84
+ createdAt: number;
85
+ /** Last transition timestamp in milliseconds since the epoch. */
86
+ updatedAt: number;
87
+ }>;
88
+ /** An admission or claim decision with a safe operation projection. */
89
+ export type MediaOperationDecision = Readonly<{
90
+ /** Admission or claim outcome. */
91
+ kind: "admitted" | "conflict" | "replayed" | "claimed" | "pending" | "succeeded" | "interrupted";
92
+ /** Safe persisted projection for this decision. */
93
+ operation: MediaOperationProjection;
94
+ /** Exclusive dispatch or save lease when claimed. */
95
+ leaseId?: string;
96
+ }>;
97
+ /** Scoped inactivity observation made before destructive erasure. */
98
+ export type MediaErasurePreflight = Readonly<{
99
+ /** Namespace supplied by the host's resource roster. */
100
+ namespace: string;
101
+ /** Named operation request supplied by that roster. */
102
+ requestId: string;
103
+ /** Whether durable erasure has already completed. */
104
+ erased: boolean;
105
+ }>;
106
+ /** Evidence that retained output, SQL and alarms were erased. */
107
+ export type MediaErasureReadback = Readonly<{
108
+ /** True only after all local data and retained output are absent. */
109
+ clear: boolean;
110
+ }>;
111
+ /** Retained output projection, or a terminal spent format refusal. */
112
+ export type MediaRetentionResult = MediaOperationProjection | Readonly<{
113
+ /** Provider execution finished with an unusable pinned format. */
114
+ kind: "refused";
115
+ /** Stable mismatch reason recorded before settlement. */
116
+ code: "output_format_mismatch";
117
+ }>;
118
+ /** Optional host facts that pin a namespace before operation admission. */
119
+ export type MediaOperationHooks = Readonly<{
120
+ /** Read the namespace already owned by host-local facts, or null when unbound. */
121
+ namespace?: () => string | null;
122
+ }>;
123
+ /** Retained-output storage supplied by the host. */
124
+ export type MediaOperationEnvironment = Readonly<{
125
+ /** Bucket retaining exact output and background reference bytes. */
126
+ APP_ARTIFACTS: MediaOperationBucket;
127
+ }>;
128
+ /** Own exact replay, dispatch leases, retained output and save recovery in SQL and object storage. */
129
+ export declare class MediaOperationOwner {
130
+ private readonly ctx;
131
+ private readonly env;
132
+ private readonly provider?;
133
+ private readonly hooks;
134
+ private erased;
135
+ private readonly leaseMs;
136
+ /**
137
+ * A background (video) generation holds its lease past the 15-minute alarm
138
+ * wall-clock limit, so a live alarm is never mistaken for a lost one.
139
+ */
140
+ private readonly backgroundLeaseMs;
141
+ private initialized;
142
+ /**
143
+ * The host supplies the provider for background alarm generations.
144
+ */
145
+ protected mediaProvider(): MediaProvider | undefined;
146
+ constructor(ctx: MediaOperationContext, env: MediaOperationEnvironment, provider?: (() => MediaProvider | undefined) | undefined, hooks?: MediaOperationHooks);
147
+ private ensureSchema;
148
+ private decodeJson;
149
+ private decode;
150
+ private project;
151
+ private readRecord;
152
+ /** Read the safe persisted operation projection, or null before admission or after erasure. */
153
+ read(): MediaOperationProjection | null;
154
+ /** Check host namespace, request identity and inactivity before erasure. */
155
+ preflightErasure(namespace: string, requestId: string): MediaErasurePreflight;
156
+ /** Erase inactive output and local storage, then retain the durable erasure marker. */
157
+ erase(namespace: string, requestId: string): Promise<Readonly<{
158
+ /** True only after all local data and retained output are absent. */
159
+ clear: boolean;
160
+ }>>;
161
+ /** Read back empty SQL, alarm and retained output with the durable erasure marker. */
162
+ readErasure(): Promise<MediaErasureReadback>;
163
+ private erasureOutputKey;
164
+ private requireRecord;
165
+ private update;
166
+ private transition;
167
+ /** Capture immutable host identity and input, replaying exact requests and refusing changed input. */
168
+ admit(actorUserId: string, coordinatesInput: MediaOperationCoordinates, requestId: string, input: MediaOperationRequest): MediaOperationDecision;
169
+ /** Claim a safe dispatch or save lease, recovering retained output without redispatching inference. */
170
+ claim(): Promise<MediaOperationDecision>;
171
+ /** Pin the admitted price and begin the generation lease. */
172
+ recordEstimate(leaseId: string, costMilliunits: number): Readonly<{
173
+ /** Durable object name identifying this operation. */
174
+ operationId: string;
175
+ /** Retry identity chosen by the caller. */
176
+ requestId: string;
177
+ /** Host isolation namespace. */
178
+ namespace: string;
179
+ /** Host owner within the namespace. */
180
+ owner: string;
181
+ /** Current durable lifecycle state. */
182
+ state: MediaOperationState;
183
+ /** Terminal format mismatch after provider execution. */
184
+ spentFailure: "output_format_mismatch" | null;
185
+ /** Definitive provider refusal with no delivered or billable output. */
186
+ providerRefusal: "safety_filter_refused" | null;
187
+ /** Pinned host price or unmetered quote. */
188
+ estimatedCostMilliunits: number | null;
189
+ /** Retained or saved image metadata. */
190
+ image: MediaImage | null;
191
+ /** Settled receipt when generation and billing completed. */
192
+ result: MediaOperationResult | null;
193
+ /** Admission timestamp in milliseconds since the epoch. */
194
+ createdAt: number;
195
+ /** Last transition timestamp in milliseconds since the epoch. */
196
+ updatedAt: number;
197
+ }>;
198
+ /**
199
+ * Hand a long (video) generation to this owner's alarm. The caller's request
200
+ * returns at once; the alarm dispatches the provider exactly once, retains
201
+ * the output, and releases the lease so a later retry saves and charges it.
202
+ */
203
+ dispatchInBackground(leaseId: string, references: readonly MediaReferenceBytes[]): Promise<MediaOperationProjection>;
204
+ /** Run a background generation once; a retried alarm never redispatches. */
205
+ alarm(): Promise<void>;
206
+ /** An aborted in-flight provider call is terminal for this request ID. */
207
+ interruptGeneration(leaseId: string, refusalInput?: NonNullable<MediaOperationProjection["providerRefusal"]>): MediaOperationProjection;
208
+ /** Retain immutable provider output before making the save state visible. */
209
+ recordGenerated(leaseId: string, bytes: Uint8Array, formatInput: string): Promise<MediaRetentionResult>;
210
+ /** Read exact retained bytes under the current save lease. */
211
+ readGenerated(leaseId: string): Promise<Uint8Array>;
212
+ /** A fixed-path exact-byte save is safe to retry without repeating generation. */
213
+ releaseWrite(leaseId: string): MediaOperationProjection;
214
+ /** Record a destination write and move to idempotent settlement. */
215
+ recordWritten(leaseId: string, receipt: string, written: MediaImage): Readonly<{
216
+ /** Durable object name identifying this operation. */
217
+ operationId: string;
218
+ /** Retry identity chosen by the caller. */
219
+ requestId: string;
220
+ /** Host isolation namespace. */
221
+ namespace: string;
222
+ /** Host owner within the namespace. */
223
+ owner: string;
224
+ /** Current durable lifecycle state. */
225
+ state: MediaOperationState;
226
+ /** Terminal format mismatch after provider execution. */
227
+ spentFailure: "output_format_mismatch" | null;
228
+ /** Definitive provider refusal with no delivered or billable output. */
229
+ providerRefusal: "safety_filter_refused" | null;
230
+ /** Pinned host price or unmetered quote. */
231
+ estimatedCostMilliunits: number | null;
232
+ /** Retained or saved image metadata. */
233
+ image: MediaImage | null;
234
+ /** Settled receipt when generation and billing completed. */
235
+ result: MediaOperationResult | null;
236
+ /** Admission timestamp in milliseconds since the epoch. */
237
+ createdAt: number;
238
+ /** Last transition timestamp in milliseconds since the epoch. */
239
+ updatedAt: number;
240
+ }>;
241
+ /**
242
+ * Persist a completed Computer write without claiming billing success.
243
+ * A lost receipt may replay the exact retained bytes to the captured path;
244
+ * it never repeats provider generation.
245
+ */
246
+ recordWrittenWithoutSettlement(leaseId: string, receipt: string, written: MediaImage): Readonly<{
247
+ /** Durable object name identifying this operation. */
248
+ operationId: string;
249
+ /** Retry identity chosen by the caller. */
250
+ requestId: string;
251
+ /** Host isolation namespace. */
252
+ namespace: string;
253
+ /** Host owner within the namespace. */
254
+ owner: string;
255
+ /** Current durable lifecycle state. */
256
+ state: MediaOperationState;
257
+ /** Terminal format mismatch after provider execution. */
258
+ spentFailure: "output_format_mismatch" | null;
259
+ /** Definitive provider refusal with no delivered or billable output. */
260
+ providerRefusal: "safety_filter_refused" | null;
261
+ /** Pinned host price or unmetered quote. */
262
+ estimatedCostMilliunits: number | null;
263
+ /** Retained or saved image metadata. */
264
+ image: MediaImage | null;
265
+ /** Settled receipt when generation and billing completed. */
266
+ result: MediaOperationResult | null;
267
+ /** Admission timestamp in milliseconds since the epoch. */
268
+ createdAt: number;
269
+ /** Last transition timestamp in milliseconds since the epoch. */
270
+ updatedAt: number;
271
+ }>;
272
+ /** Commit the settled receipt after verifying the saved output and admitted price. */
273
+ recordSucceeded(leaseId: string, resultInput: MediaOperationResult): Readonly<{
274
+ /** Durable object name identifying this operation. */
275
+ operationId: string;
276
+ /** Retry identity chosen by the caller. */
277
+ requestId: string;
278
+ /** Host isolation namespace. */
279
+ namespace: string;
280
+ /** Host owner within the namespace. */
281
+ owner: string;
282
+ /** Current durable lifecycle state. */
283
+ state: MediaOperationState;
284
+ /** Terminal format mismatch after provider execution. */
285
+ spentFailure: "output_format_mismatch" | null;
286
+ /** Definitive provider refusal with no delivered or billable output. */
287
+ providerRefusal: "safety_filter_refused" | null;
288
+ /** Pinned host price or unmetered quote. */
289
+ estimatedCostMilliunits: number | null;
290
+ /** Retained or saved image metadata. */
291
+ image: MediaImage | null;
292
+ /** Settled receipt when generation and billing completed. */
293
+ result: MediaOperationResult | null;
294
+ /** Admission timestamp in milliseconds since the epoch. */
295
+ createdAt: number;
296
+ /** Last transition timestamp in milliseconds since the epoch. */
297
+ updatedAt: number;
298
+ }>;
299
+ /** Release preparation or refused admission so the same request can retry. */
300
+ releaseEstimate(leaseId: string): MediaOperationProjection;
301
+ }