@fungi.computer/darkroom 0.9.2 → 0.11.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.
- package/README.md +130 -6
- package/dist/app-media-contracts.d.ts +104 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +1 -0
- package/dist/cloudflare/provider.d.ts +5 -4
- package/dist/cloudflare/provider.js +20 -9
- package/dist/cloudflare/r2-destination.d.ts +50 -0
- package/dist/cloudflare/r2-destination.js +59 -0
- package/dist/cloudflare.d.ts +3 -2
- package/dist/cloudflare.js +1 -0
- package/dist/gateway-models.d.ts +44 -9
- package/dist/gateway-models.js +52 -20
- package/dist/index.d.ts +12 -2
- package/dist/index.js +81 -38
- package/dist/media-binding.d.ts +6 -0
- package/dist/media-content-type.d.ts +5 -0
- package/dist/media-content-type.js +49 -0
- package/dist/media-generation.js +2 -0
- package/dist/media-operation-contract.d.ts +13 -1
- package/dist/media-operation-do.d.ts +6 -0
- package/dist/media-operation-do.js +37 -2
- package/dist/media-operation-owner.d.ts +93 -5
- package/dist/media-operation-owner.js +250 -46
- package/dist/media-operation-storage.d.ts +18 -4
- package/dist/media-operation.js +30 -4
- package/dist/media-path.d.ts +3 -0
- package/dist/media-path.js +7 -0
- package/dist/media-run-lifetime.d.ts +5 -0
- package/dist/media-run-lifetime.js +5 -0
- package/dist/media-written.d.ts +22 -0
- package/dist/media-written.js +20 -0
- package/dist/model-catalog.d.ts +226 -0
- package/dist/model-catalog.js +254 -9
- package/dist/provenance.d.ts +5 -1
- package/dist/provenance.js +2 -1
- package/dist/reference-read.d.ts +24 -0
- package/dist/reference-read.js +26 -0
- package/dist/server.d.ts +58 -2
- package/dist/server.js +49 -5
- package/docs/api/app-media-contracts.md +49 -0
- package/docs/api/browser.md +15 -4
- package/docs/api/cloudflare.md +254 -5
- package/docs/api/index.md +346 -62
- package/docs/api/server.md +524 -66
- package/package.json +2 -2
package/dist/server.js
CHANGED
|
@@ -2,10 +2,13 @@ import { mediaPendingSchema } from "./media-binding.js";
|
|
|
2
2
|
export { estimateMediaModel } from "./cloudflare/provider.js";
|
|
3
3
|
export { mediaPendingSchema, mediaBindingCallSchema, mediaBindingGenerationSchema, mediaImageBindingInputSchema, mediaVideoBindingInputSchema, parseMediaBindingCall, mediaBindingRequest, readMediaBindingReply, } from "./media-binding.js";
|
|
4
4
|
import { Hono } from "hono";
|
|
5
|
+
import { withBillingUnit } from "./model-catalog.js";
|
|
5
6
|
import { z } from "zod";
|
|
6
7
|
import { AppError, describeAppError } from "@fungi.computer/agar/errors";
|
|
7
8
|
import * as Effect from "effect/Effect";
|
|
8
9
|
import * as Result from "effect/Result";
|
|
10
|
+
import { mediaPathSchema } from "./media-path.js";
|
|
11
|
+
export { mediaWrittenDigest, removeMediaIfWritten, } from "./media-written.js";
|
|
9
12
|
import { runMediaGeneration } from "./media-generation.js";
|
|
10
13
|
import { quoteMediaGeneration } from "./media-quote.js";
|
|
11
14
|
import { validateMediaGenerationSettings, listMediaModels, mediaGenerationSettingsSchema, mediaRequestedImageFormatSchema, MediaSettingsError, } from "./index.js";
|
|
@@ -13,6 +16,7 @@ import { mediaResultSchema, } from "./media-operation-contract.js";
|
|
|
13
16
|
import { MediaOutputFormatMismatch, MediaBillingRefusal, MediaExecutionError, MediaSafetyFilterRefusal, } from "./execution-error.js";
|
|
14
17
|
export { createDailyMediaMetering, DailyMediaMeter, } from "./daily-media-meter.js";
|
|
15
18
|
export { MediaBillingRefusal, MediaExecutionError, } from "./execution-error.js";
|
|
19
|
+
export { readHostReference, referenceFilename, } from "./reference-read.js";
|
|
16
20
|
export { mediaUnits } from "./gateway-models.js";
|
|
17
21
|
export { quoteMediaGeneration } from "./media-quote.js";
|
|
18
22
|
export { MediaOperationOwner, mediaOperationDestinationSchema, mediaOperationCoordinatesSchema, mediaOperationStateSchema, mediaImageSchema, mediaOperationResultSchema, } from "./media-operation-owner.js";
|
|
@@ -20,11 +24,7 @@ const identifier = z.lazy(() => z.string().min(1).max(256));
|
|
|
20
24
|
/** Decode relative service generation input. Identity comes from the host. */
|
|
21
25
|
export const mediaRequestSchema = z.strictObject({
|
|
22
26
|
/** Fixed destination or reference file path. */
|
|
23
|
-
path:
|
|
24
|
-
.string()
|
|
25
|
-
.min(1)
|
|
26
|
-
.max(1_024)
|
|
27
|
-
.refine((path) => !path.includes("\0")),
|
|
27
|
+
path: mediaPathSchema,
|
|
28
28
|
/** Requested model, dimensions, prompt and references. */
|
|
29
29
|
settings: mediaGenerationSettingsSchema,
|
|
30
30
|
/** Optional verified image encoding pin. */
|
|
@@ -146,6 +146,48 @@ export async function generateMedia(host, request, signal) {
|
|
|
146
146
|
const result = await Effect.runPromise(Effect.result(runMediaGeneration(host, request, signal)));
|
|
147
147
|
return Result.getOrThrowWith(result, (error) => error);
|
|
148
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* What one generation still retains, by its request id: where its file goes,
|
|
151
|
+
* and the exact provider bytes held for recovery, including bytes a crash left
|
|
152
|
+
* unrecorded. Null once erased. Refuses another namespace.
|
|
153
|
+
*/
|
|
154
|
+
export function retainedMedia(host, requestId) {
|
|
155
|
+
return Promise.resolve(host.operations
|
|
156
|
+
.getByName(`media:${requestId}`)
|
|
157
|
+
.retained(host.scope.namespace, requestId));
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Read back the exact provider bytes a generation retained, before any
|
|
161
|
+
* provenance, so a host can re-save a result whose destination write was lost.
|
|
162
|
+
* Null when erased or nothing was retained. Refuses another namespace.
|
|
163
|
+
*/
|
|
164
|
+
export function readRetainedMedia(host, requestId) {
|
|
165
|
+
return Promise.resolve(host.operations
|
|
166
|
+
.getByName(`media:${requestId}`)
|
|
167
|
+
.readRetained(host.scope.namespace, requestId));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Erase everything a generation retained or could still write: its retained
|
|
171
|
+
* output, reference copies, storage and the destination file (only while it
|
|
172
|
+
* still holds what this operation wrote). Works mid generation: the operation
|
|
173
|
+
* refuses later writes, deletes anything that lands, and its open billing hold
|
|
174
|
+
* is settled at zero units. Call again until `clear` is true; the destination
|
|
175
|
+
* facts are kept for that retry.
|
|
176
|
+
*/
|
|
177
|
+
export async function eraseMediaOperation(host, requestId) {
|
|
178
|
+
const operationId = `media:${requestId}`;
|
|
179
|
+
const erased = await host.operations
|
|
180
|
+
.getByName(operationId)
|
|
181
|
+
.erase(host.scope.namespace, requestId);
|
|
182
|
+
if (erased.abandonedGeneration && host.metering !== "unmetered")
|
|
183
|
+
await host.metering.settle({ operationId, units: 0 });
|
|
184
|
+
const destinationFile = erased.destinationPath === null || erased.writtenSha256 === null
|
|
185
|
+
? null
|
|
186
|
+
: await host.destination.remove(erased.destinationPath, {
|
|
187
|
+
sha256: erased.writtenSha256,
|
|
188
|
+
});
|
|
189
|
+
return { ...erased, destinationFile };
|
|
190
|
+
}
|
|
149
191
|
function outcomeResponse(outcome) {
|
|
150
192
|
if (outcome.kind === "conflict")
|
|
151
193
|
return Response.json({
|
|
@@ -203,6 +245,7 @@ function outcomeResponse(outcome) {
|
|
|
203
245
|
export function createMediaService(host) {
|
|
204
246
|
const app = new Hono();
|
|
205
247
|
app.get("/models", () => Response.json((host.catalogue ?? listMediaModels())
|
|
248
|
+
.map(withBillingUnit)
|
|
206
249
|
.map((model) => host.destination.readReference !== undefined ||
|
|
207
250
|
model.input.maxReferences === 0
|
|
208
251
|
? model
|
|
@@ -232,6 +275,7 @@ export function createMediaService(host) {
|
|
|
232
275
|
path: input.data.path,
|
|
233
276
|
settings: input.data.settings,
|
|
234
277
|
outputFormat: input.data.outputFormat,
|
|
278
|
+
embedPrompt: host.embedPrompt,
|
|
235
279
|
}, context.req.raw.signal).pipe(Effect.match({
|
|
236
280
|
onSuccess: outcomeResponse,
|
|
237
281
|
onFailure: (error) => (error instanceof MediaExecutionError
|
|
@@ -26,7 +26,9 @@ const mediaModelPriceEstimateSchema: ZodObject<{
|
|
|
26
26
|
width: ZodOptional<ZodNumber>;
|
|
27
27
|
height: ZodOptional<ZodNumber>;
|
|
28
28
|
steps: ZodOptional<ZodNumber>;
|
|
29
|
+
guidance: ZodOptional<ZodNumber>;
|
|
29
30
|
durationSeconds: ZodOptional<ZodNumber>;
|
|
31
|
+
targetMegapixels: ZodOptional<ZodNumber>;
|
|
30
32
|
voiceId: ZodOptional<ZodString>;
|
|
31
33
|
resolution: ZodOptional<ZodEnum<{
|
|
32
34
|
p480: "480p";
|
|
@@ -83,7 +85,9 @@ const mediaCatalogModelSchema: ZodReadonly<ZodObject<{
|
|
|
83
85
|
width: ZodOptional<ZodNumber>;
|
|
84
86
|
height: ZodOptional<ZodNumber>;
|
|
85
87
|
steps: ZodOptional<ZodNumber>;
|
|
88
|
+
guidance: ZodOptional<ZodNumber>;
|
|
86
89
|
durationSeconds: ZodOptional<ZodNumber>;
|
|
90
|
+
targetMegapixels: ZodOptional<ZodNumber>;
|
|
87
91
|
voiceId: ZodOptional<ZodString>;
|
|
88
92
|
resolution: ZodOptional<ZodEnum<{
|
|
89
93
|
p480: ...;
|
|
@@ -145,6 +149,7 @@ const mediaCatalogModelSchema: ZodReadonly<ZodObject<{
|
|
|
145
149
|
}>;
|
|
146
150
|
maxSteps: ZodNullable<ZodNumber>;
|
|
147
151
|
defaultSteps: ZodNullable<ZodNumber>;
|
|
152
|
+
guidance: ZodDefault<ZodNullable<ZodReadonly<ZodObject<..., ...>>>>;
|
|
148
153
|
referenceField: ZodNullable<ZodString>;
|
|
149
154
|
maxReferences: ZodNumber;
|
|
150
155
|
referenceDimension: ZodNullable<ZodNumber>;
|
|
@@ -200,6 +205,26 @@ const mediaCatalogModelSchema: ZodReadonly<ZodObject<{
|
|
|
200
205
|
seconds: ZodNullable<ZodReadonly<ZodObject<..., ...>>>;
|
|
201
206
|
milliunitsPerUnit: ZodNumber;
|
|
202
207
|
}, $strict>>>>;
|
|
208
|
+
billingUnit: ZodEnum<{
|
|
209
|
+
image: "image";
|
|
210
|
+
video_second: "video_second";
|
|
211
|
+
audio_second: "audio_second";
|
|
212
|
+
audio_character_block: "audio_character_block";
|
|
213
|
+
}>;
|
|
214
|
+
transform: ZodNullable<ZodLazy<ZodReadonly<ZodObject<{
|
|
215
|
+
operation: ZodEnum<{
|
|
216
|
+
remove_background: "remove_background";
|
|
217
|
+
upscale: "upscale";
|
|
218
|
+
}>;
|
|
219
|
+
source: ZodReadonly<ZodObject<{
|
|
220
|
+
formats: ...;
|
|
221
|
+
maxBytes: ...;
|
|
222
|
+
maxPixels: ...;
|
|
223
|
+
}, $strict>>;
|
|
224
|
+
defaultMegapixels: ZodNullable<ZodNumber>;
|
|
225
|
+
milliunits: ZodNullable<ZodNumber>;
|
|
226
|
+
sizes: ZodReadonly<ZodArray<ZodReadonly<...>>>;
|
|
227
|
+
}, $strict>>>>;
|
|
203
228
|
}, $strict>>;
|
|
204
229
|
```
|
|
205
230
|
|
|
@@ -224,7 +249,9 @@ const mediaModelsSchema: ZodLazy<ZodArray<ZodReadonly<ZodObject<{
|
|
|
224
249
|
width: ZodOptional<...>;
|
|
225
250
|
height: ZodOptional<...>;
|
|
226
251
|
steps: ZodOptional<...>;
|
|
252
|
+
guidance: ZodOptional<...>;
|
|
227
253
|
durationSeconds: ZodOptional<...>;
|
|
254
|
+
targetMegapixels: ZodOptional<...>;
|
|
228
255
|
voiceId: ZodOptional<...>;
|
|
229
256
|
resolution: ZodOptional<...>;
|
|
230
257
|
aspectRatio: ZodOptional<...>;
|
|
@@ -272,6 +299,7 @@ const mediaModelsSchema: ZodLazy<ZodArray<ZodReadonly<ZodObject<{
|
|
|
272
299
|
}>;
|
|
273
300
|
maxSteps: ZodNullable<ZodNumber>;
|
|
274
301
|
defaultSteps: ZodNullable<ZodNumber>;
|
|
302
|
+
guidance: ZodDefault<ZodNullable<...>>;
|
|
275
303
|
referenceField: ZodNullable<ZodString>;
|
|
276
304
|
maxReferences: ZodNumber;
|
|
277
305
|
referenceDimension: ZodNullable<ZodNumber>;
|
|
@@ -306,6 +334,19 @@ const mediaModelsSchema: ZodLazy<ZodArray<ZodReadonly<ZodObject<{
|
|
|
306
334
|
seconds: ZodNullable<...>;
|
|
307
335
|
milliunitsPerUnit: ZodNumber;
|
|
308
336
|
}, $strict>>>>;
|
|
337
|
+
billingUnit: ZodEnum<{
|
|
338
|
+
image: "image";
|
|
339
|
+
video_second: "video_second";
|
|
340
|
+
audio_second: "audio_second";
|
|
341
|
+
audio_character_block: "audio_character_block";
|
|
342
|
+
}>;
|
|
343
|
+
transform: ZodNullable<ZodLazy<ZodReadonly<ZodObject<{
|
|
344
|
+
operation: ZodEnum<...>;
|
|
345
|
+
source: ZodReadonly<...>;
|
|
346
|
+
defaultMegapixels: ZodNullable<...>;
|
|
347
|
+
milliunits: ZodNullable<...>;
|
|
348
|
+
sizes: ZodReadonly<...>;
|
|
349
|
+
}, $strict>>>>;
|
|
309
350
|
}, $strict>>>>;
|
|
310
351
|
```
|
|
311
352
|
|
|
@@ -607,6 +648,7 @@ const appMediaModelsOutcomeSchema: ZodUnion<readonly [ZodLazy<ZodArray<ZodReadon
|
|
|
607
648
|
steps: ...;
|
|
608
649
|
maxSteps: ...;
|
|
609
650
|
defaultSteps: ...;
|
|
651
|
+
guidance: ...;
|
|
610
652
|
referenceField: ...;
|
|
611
653
|
maxReferences: ...;
|
|
612
654
|
referenceDimension: ...;
|
|
@@ -615,6 +657,13 @@ const appMediaModelsOutcomeSchema: ZodUnion<readonly [ZodLazy<ZodArray<ZodReadon
|
|
|
615
657
|
sizes: ZodNullable<ZodReadonly<ZodArray<ZodString>>>;
|
|
616
658
|
video: ZodNullable<ZodLazy<ZodReadonly<ZodObject<..., ...>>>>;
|
|
617
659
|
audio: ZodNullable<ZodLazy<ZodReadonly<ZodObject<..., ...>>>>;
|
|
660
|
+
billingUnit: ZodEnum<{
|
|
661
|
+
image: "image";
|
|
662
|
+
video_second: "video_second";
|
|
663
|
+
audio_second: "audio_second";
|
|
664
|
+
audio_character_block: "audio_character_block";
|
|
665
|
+
}>;
|
|
666
|
+
transform: ZodNullable<ZodLazy<ZodReadonly<ZodObject<..., ...>>>>;
|
|
618
667
|
}, $strict>>>>, ZodUnion<readonly [ZodObject<{
|
|
619
668
|
error: ZodEnum<{
|
|
620
669
|
revoked: "revoked";
|
package/docs/api/browser.md
CHANGED
|
@@ -78,6 +78,17 @@ const mediaFailureSchema: ZodObject<{
|
|
|
78
78
|
Sanitized HTTP refusal emitted by a Media host and decoded at the browser
|
|
79
79
|
boundary.
|
|
80
80
|
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
### backgroundProviderTimeoutMs
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
const backgroundProviderTimeoutMs: number;
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The longest a background provider call runs before it is cut off, safely inside
|
|
90
|
+
the 15-minute alarm wall-clock limit that would kill the call.
|
|
91
|
+
|
|
81
92
|
## Functions
|
|
82
93
|
|
|
83
94
|
### readMediaFailure()
|
|
@@ -90,12 +101,12 @@ function readMediaFailure(
|
|
|
90
101
|
error: string;
|
|
91
102
|
stage:
|
|
92
103
|
| "provider"
|
|
104
|
+
| "operation"
|
|
93
105
|
| "admission"
|
|
94
106
|
| "generation-authorization"
|
|
95
107
|
| "settings"
|
|
96
108
|
| "estimate"
|
|
97
109
|
| "billing"
|
|
98
|
-
| "operation"
|
|
99
110
|
| "normalization"
|
|
100
111
|
| "artifact"
|
|
101
112
|
| "destination-authorization"
|
|
@@ -125,9 +136,9 @@ Read and decode one Media host failure at the browser HTTP boundary.
|
|
|
125
136
|
|
|
126
137
|
#### Returns
|
|
127
138
|
|
|
128
|
-
`Promise`\< \| \{ `error`: `string`; `stage`: \| `"provider"` \| `"
|
|
129
|
-
\| `"
|
|
130
|
-
\| `"
|
|
139
|
+
`Promise`\< \| \{ `error`: `string`; `stage`: \| `"provider"` \| `"operation"`
|
|
140
|
+
\| `"admission"` \| `"generation-authorization"` \| `"settings"` \| `"estimate"`
|
|
141
|
+
\| `"billing"` \| `"normalization"` \| `"artifact"` \|
|
|
131
142
|
`"destination-authorization"` \| `"destination-write"`; `code`: \|
|
|
132
143
|
`"CAPABILITY_DENIED"` \| `"DAILY_LIMIT_REACHED"` \| `"INSUFFICIENT_CREDIT"` \|
|
|
133
144
|
`"HOST_FAILURE"` \| `"INVALID_ARGUMENT"` \| `"MEDIA_PROVIDER_FAILURE"` \|
|
package/docs/api/cloudflare.md
CHANGED
|
@@ -218,15 +218,77 @@ Check host namespace, request identity and inactivity before erasure.
|
|
|
218
218
|
|
|
219
219
|
`ReturnType`\<[`MediaOperationOwner`](server.md#mediaoperationowner)\[`"preflightErasure"`\]\>
|
|
220
220
|
|
|
221
|
+
##### recordWriteIntent()
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
recordWriteIntent(...input): ReturnType<MediaOperationOwner["recordWriteIntent"]>;
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Record the digest of the exact bytes about to be written to the destination,
|
|
228
|
+
before writing them. An erasure then knows which file this operation owns, even
|
|
229
|
+
if the process dies between the write and its record, and refuses the write once
|
|
230
|
+
erased.
|
|
231
|
+
|
|
232
|
+
###### Parameters
|
|
233
|
+
|
|
234
|
+
| Parameter | Type | Description |
|
|
235
|
+
| ---------- | ---------------------- | ----------- |
|
|
236
|
+
| ...`input` | \[`string`, `string`\] | - |
|
|
237
|
+
|
|
238
|
+
###### Returns
|
|
239
|
+
|
|
240
|
+
`ReturnType`\<[`MediaOperationOwner`](server.md#mediaoperationowner)\[`"recordWriteIntent"`\]\>
|
|
241
|
+
|
|
221
242
|
##### erase()
|
|
222
243
|
|
|
223
244
|
```ts
|
|
224
|
-
erase(...input): Promise<
|
|
225
|
-
clear: boolean;
|
|
226
|
-
}>>;
|
|
245
|
+
erase(...input): Promise<MediaErasure>;
|
|
227
246
|
```
|
|
228
247
|
|
|
229
|
-
Erase
|
|
248
|
+
Erase the operation and everything it retained or could still write, even
|
|
249
|
+
mid-generation. Erasure is marked first, so an attempt still running, or a lease
|
|
250
|
+
recovered later, can neither transition nor leave output behind: a write that
|
|
251
|
+
lands after the mark is deleted. The marker is never removed, so a crash cannot
|
|
252
|
+
resurrect the operation. Safe to repeat until `clear`; a repeat after a partial
|
|
253
|
+
failure resumes the cleanup.
|
|
254
|
+
|
|
255
|
+
###### Parameters
|
|
256
|
+
|
|
257
|
+
| Parameter | Type | Description |
|
|
258
|
+
| ---------- | ------------------------------------------------------------------------ | ----------- |
|
|
259
|
+
| ...`input` | \[`string`, `string`, [`MediaErasePolicy`](server.md#mediaerasepolicy)\] | - |
|
|
260
|
+
|
|
261
|
+
###### Returns
|
|
262
|
+
|
|
263
|
+
`Promise`\<[`MediaErasure`](server.md#mediaerasure)\>
|
|
264
|
+
|
|
265
|
+
##### retained()
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
retained(...input): Promise<
|
|
269
|
+
| Readonly<{
|
|
270
|
+
requestId: string;
|
|
271
|
+
state: | "admitted"
|
|
272
|
+
| "estimating"
|
|
273
|
+
| "generating"
|
|
274
|
+
| "writing"
|
|
275
|
+
| "charging"
|
|
276
|
+
| "written"
|
|
277
|
+
| "succeeded"
|
|
278
|
+
| "interrupted";
|
|
279
|
+
destinationPath: string;
|
|
280
|
+
output: | Readonly<{
|
|
281
|
+
bytes: number;
|
|
282
|
+
format: string;
|
|
283
|
+
contentType: string;
|
|
284
|
+
}>
|
|
285
|
+
| null;
|
|
286
|
+
}>
|
|
287
|
+
| null>;
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
List what this operation retains: its destination path and exact provider
|
|
291
|
+
output. Null once erased.
|
|
230
292
|
|
|
231
293
|
###### Parameters
|
|
232
294
|
|
|
@@ -236,7 +298,37 @@ Erase inactive output and local storage, then retain the durable erasure marker.
|
|
|
236
298
|
|
|
237
299
|
###### Returns
|
|
238
300
|
|
|
239
|
-
`Promise
|
|
301
|
+
`Promise`\< \| `Readonly`\<\{ `requestId`: `string`; `state`: \| `"admitted"` \|
|
|
302
|
+
`"estimating"` \| `"generating"` \| `"writing"` \| `"charging"` \| `"written"`
|
|
303
|
+
\| `"succeeded"` \| `"interrupted"`; `destinationPath`: `string`; `output`: \|
|
|
304
|
+
`Readonly`\<\{ `bytes`: `number`; `format`: `string`; `contentType`: `string`;
|
|
305
|
+
\}\> \| `null`; \}\> \| `null`\>
|
|
306
|
+
|
|
307
|
+
##### readRetained()
|
|
308
|
+
|
|
309
|
+
```ts
|
|
310
|
+
readRetained(...input): Promise<
|
|
311
|
+
| Readonly<{
|
|
312
|
+
bytes: Uint8Array;
|
|
313
|
+
format: string;
|
|
314
|
+
}>
|
|
315
|
+
| null>;
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
Read back the exact retained provider bytes, before any provenance, so a host
|
|
319
|
+
can re-save a result whose destination write was lost. Null when erased or
|
|
320
|
+
nothing was retained.
|
|
321
|
+
|
|
322
|
+
###### Parameters
|
|
323
|
+
|
|
324
|
+
| Parameter | Type | Description |
|
|
325
|
+
| ---------- | ---------------------- | ----------- |
|
|
326
|
+
| ...`input` | \[`string`, `string`\] | - |
|
|
327
|
+
|
|
328
|
+
###### Returns
|
|
329
|
+
|
|
330
|
+
`Promise`\< \| `Readonly`\<\{ `bytes`: `Uint8Array`; `format`: `string`; \}\> \|
|
|
331
|
+
`null`\>
|
|
240
332
|
|
|
241
333
|
##### readErasure()
|
|
242
334
|
|
|
@@ -600,6 +692,112 @@ Dispatch to the native Workers AI binding.
|
|
|
600
692
|
|
|
601
693
|
---
|
|
602
694
|
|
|
695
|
+
### MediaR2Bucket
|
|
696
|
+
|
|
697
|
+
```ts
|
|
698
|
+
type MediaR2Bucket = object;
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
The R2 bucket operations a Media destination needs; a native `R2Bucket`
|
|
702
|
+
satisfies it.
|
|
703
|
+
|
|
704
|
+
#### Methods
|
|
705
|
+
|
|
706
|
+
##### get()
|
|
707
|
+
|
|
708
|
+
```ts
|
|
709
|
+
get(key): Promise<
|
|
710
|
+
| Readonly<{
|
|
711
|
+
size: number;
|
|
712
|
+
}> & object
|
|
713
|
+
| null>;
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
Read one object, or null when the key is absent.
|
|
717
|
+
|
|
718
|
+
###### Parameters
|
|
719
|
+
|
|
720
|
+
| Parameter | Type |
|
|
721
|
+
| --------- | -------- |
|
|
722
|
+
| `key` | `string` |
|
|
723
|
+
|
|
724
|
+
###### Returns
|
|
725
|
+
|
|
726
|
+
`Promise`\< \| `Readonly`\<\{ `size`: `number`; \}\> & `object` \| `null`\>
|
|
727
|
+
|
|
728
|
+
##### put()
|
|
729
|
+
|
|
730
|
+
```ts
|
|
731
|
+
put(
|
|
732
|
+
key,
|
|
733
|
+
bytes,
|
|
734
|
+
options
|
|
735
|
+
): Promise<object | null>;
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
Store exact bytes with their MIME type.
|
|
739
|
+
|
|
740
|
+
###### Parameters
|
|
741
|
+
|
|
742
|
+
| Parameter | Type |
|
|
743
|
+
| --------- | --------------------------------------------------------------------------------- |
|
|
744
|
+
| `key` | `string` |
|
|
745
|
+
| `bytes` | `Uint8Array` |
|
|
746
|
+
| `options` | `Readonly`\<\{ `httpMetadata`: `Readonly`\<\{ `contentType`: `string`; \}\>; \}\> |
|
|
747
|
+
|
|
748
|
+
###### Returns
|
|
749
|
+
|
|
750
|
+
`Promise`\<`object` \| `null`\>
|
|
751
|
+
|
|
752
|
+
##### delete()
|
|
753
|
+
|
|
754
|
+
```ts
|
|
755
|
+
delete(key): Promise<void>;
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
Delete one object; absent keys are not an error.
|
|
759
|
+
|
|
760
|
+
###### Parameters
|
|
761
|
+
|
|
762
|
+
| Parameter | Type |
|
|
763
|
+
| --------- | -------- |
|
|
764
|
+
| `key` | `string` |
|
|
765
|
+
|
|
766
|
+
###### Returns
|
|
767
|
+
|
|
768
|
+
`Promise`\<`void`\>
|
|
769
|
+
|
|
770
|
+
---
|
|
771
|
+
|
|
772
|
+
### R2MediaDestinationOptions
|
|
773
|
+
|
|
774
|
+
```ts
|
|
775
|
+
type R2MediaDestinationOptions = Readonly<{
|
|
776
|
+
bucket: MediaR2Bucket;
|
|
777
|
+
destinationId: string;
|
|
778
|
+
fit: ReferenceImageFitter;
|
|
779
|
+
authorize?: (key) => Promise<void> | void;
|
|
780
|
+
}>;
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
Host-owned R2 destination configuration.
|
|
784
|
+
|
|
785
|
+
---
|
|
786
|
+
|
|
787
|
+
### R2MediaDestination
|
|
788
|
+
|
|
789
|
+
```ts
|
|
790
|
+
type R2MediaDestination = MediaServiceHost["destination"] &
|
|
791
|
+
Readonly<{
|
|
792
|
+
readReference: (reference, model) => Promise<MediaReferenceBytes>;
|
|
793
|
+
readAudioReference: (reference) => Promise<Uint8Array>;
|
|
794
|
+
}>;
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
The host destination over an R2 bucket, with both reference readers present.
|
|
798
|
+
|
|
799
|
+
---
|
|
800
|
+
|
|
603
801
|
### MediaImagePort
|
|
604
802
|
|
|
605
803
|
```ts
|
|
@@ -708,6 +906,27 @@ AI Gateway route.
|
|
|
708
906
|
|
|
709
907
|
---
|
|
710
908
|
|
|
909
|
+
### createR2MediaDestination()
|
|
910
|
+
|
|
911
|
+
```ts
|
|
912
|
+
function createR2MediaDestination(options): R2MediaDestination;
|
|
913
|
+
```
|
|
914
|
+
|
|
915
|
+
A Media destination over one R2 bucket: object keys are the paths, validated
|
|
916
|
+
with Darkroom's path schema. Never accepts URLs.
|
|
917
|
+
|
|
918
|
+
#### Parameters
|
|
919
|
+
|
|
920
|
+
| Parameter | Type |
|
|
921
|
+
| --------- | --------------------------------------------------------- |
|
|
922
|
+
| `options` | [`R2MediaDestinationOptions`](#r2mediadestinationoptions) |
|
|
923
|
+
|
|
924
|
+
#### Returns
|
|
925
|
+
|
|
926
|
+
[`R2MediaDestination`](#r2mediadestination)
|
|
927
|
+
|
|
928
|
+
---
|
|
929
|
+
|
|
711
930
|
### createImagesReferenceFitter()
|
|
712
931
|
|
|
713
932
|
```ts
|
|
@@ -776,6 +995,30 @@ Re-exports [MediaOperationOwner](server.md#mediaoperationowner)
|
|
|
776
995
|
|
|
777
996
|
---
|
|
778
997
|
|
|
998
|
+
### MediaErasure
|
|
999
|
+
|
|
1000
|
+
Re-exports [MediaErasure](server.md#mediaerasure)
|
|
1001
|
+
|
|
1002
|
+
---
|
|
1003
|
+
|
|
1004
|
+
### MediaRetained
|
|
1005
|
+
|
|
1006
|
+
Re-exports [MediaRetained](server.md#mediaretained)
|
|
1007
|
+
|
|
1008
|
+
---
|
|
1009
|
+
|
|
1010
|
+
### MediaRetainedBytes
|
|
1011
|
+
|
|
1012
|
+
Re-exports [MediaRetainedBytes](server.md#mediaretainedbytes)
|
|
1013
|
+
|
|
1014
|
+
---
|
|
1015
|
+
|
|
1016
|
+
### MediaErasePolicy
|
|
1017
|
+
|
|
1018
|
+
Re-exports [MediaErasePolicy](server.md#mediaerasepolicy)
|
|
1019
|
+
|
|
1020
|
+
---
|
|
1021
|
+
|
|
779
1022
|
### MediaOperationContext
|
|
780
1023
|
|
|
781
1024
|
Re-exports [MediaOperationContext](server.md#mediaoperationcontext)
|
|
@@ -788,6 +1031,12 @@ Re-exports [MediaOperationStorage](server.md#mediaoperationstorage)
|
|
|
788
1031
|
|
|
789
1032
|
---
|
|
790
1033
|
|
|
1034
|
+
### MediaErasureMarker
|
|
1035
|
+
|
|
1036
|
+
Re-exports [MediaErasureMarker](server.md#mediaerasuremarker)
|
|
1037
|
+
|
|
1038
|
+
---
|
|
1039
|
+
|
|
791
1040
|
### MediaOperationBucket
|
|
792
1041
|
|
|
793
1042
|
Re-exports [MediaOperationBucket](server.md#mediaoperationbucket)
|