@fungi.computer/darkroom 0.6.0 → 0.7.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 +129 -0
- package/dist/app-media-contracts.d.ts +4 -0
- package/dist/browser-failure.d.ts +2 -0
- package/dist/browser-failure.js +2 -0
- package/dist/cloudflare/provider.js +3 -3
- package/dist/cloudflare/reference-images.d.ts +6 -0
- package/dist/cloudflare/reference-images.js +25 -7
- package/dist/cost-estimate.js +2 -2
- package/dist/daily-media-meter.d.ts +55 -0
- package/dist/daily-media-meter.js +81 -0
- package/dist/execution-error.d.ts +1 -1
- package/dist/gateway-models.d.ts +8 -2
- package/dist/gateway-models.js +24 -7
- package/dist/gateway-wire.d.ts +1 -0
- package/dist/gateway-wire.js +2 -0
- package/dist/index.d.ts +49 -12
- package/dist/index.js +31 -21
- package/dist/media-binding.js +3 -3
- package/dist/media-generation.js +9 -5
- package/dist/media-operation-contract.d.ts +3 -1
- package/dist/media-operation-do.d.ts +13 -2
- package/dist/media-operation-do.js +26 -1
- package/dist/media-operation-owner.d.ts +8 -0
- package/dist/media-operation-owner.js +8 -5
- package/dist/media-operation.js +2 -2
- package/dist/media-quote.d.ts +14 -0
- package/dist/media-quote.js +17 -0
- package/dist/model-catalog.d.ts +435 -4
- package/dist/model-catalog.js +130 -6
- package/dist/reference-image-size.d.ts +4 -3
- package/dist/reference-image-size.js +9 -9
- package/dist/server.d.ts +17 -1
- package/dist/server.js +44 -6
- package/docs/api/app-media-contracts.md +4 -0
- package/docs/api/browser.md +4 -2
- package/docs/api/cloudflare.md +53 -0
- package/docs/api/index.md +461 -54
- package/docs/api/server.md +194 -5
- package/package.json +2 -2
package/docs/api/server.md
CHANGED
|
@@ -10,6 +10,74 @@
|
|
|
10
10
|
|
|
11
11
|
## Classes
|
|
12
12
|
|
|
13
|
+
### DailyMediaMeter
|
|
14
|
+
|
|
15
|
+
A UTC-day total of admitted media cost, kept in one Durable Object's SQLite.
|
|
16
|
+
Every statement runs inside one synchronous transaction, so two concurrent
|
|
17
|
+
admits near the limit are serialized by the object and cannot both pass. Holds
|
|
18
|
+
are keyed by the durable operation id, so a retried admit never counts twice. A
|
|
19
|
+
hold that is never settled stays counted until its day ends.
|
|
20
|
+
|
|
21
|
+
#### Constructors
|
|
22
|
+
|
|
23
|
+
##### Constructor
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
new DailyMediaMeter(storage, now?): DailyMediaMeter;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
###### Parameters
|
|
30
|
+
|
|
31
|
+
| Parameter | Type | Default value |
|
|
32
|
+
| --------- | --------------------------------------------------- | ------------- |
|
|
33
|
+
| `storage` | [`DailyMediaMeterStorage`](#dailymediameterstorage) | `undefined` |
|
|
34
|
+
| `now` | () => `number` | `Date.now` |
|
|
35
|
+
|
|
36
|
+
###### Returns
|
|
37
|
+
|
|
38
|
+
[`DailyMediaMeter`](#dailymediameter)
|
|
39
|
+
|
|
40
|
+
#### Methods
|
|
41
|
+
|
|
42
|
+
##### admit()
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
admit(input): boolean;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Hold `costMilliunits` for this operation unless the day's total would exceed the
|
|
49
|
+
limit.
|
|
50
|
+
|
|
51
|
+
###### Parameters
|
|
52
|
+
|
|
53
|
+
| Parameter | Type |
|
|
54
|
+
| --------- | ----------------------------------------------------------------------------------------------------- |
|
|
55
|
+
| `input` | `Readonly`\<\{ `operationId`: `string`; `costMilliunits`: `number`; `limitMilliunits`: `number`; \}\> |
|
|
56
|
+
|
|
57
|
+
###### Returns
|
|
58
|
+
|
|
59
|
+
`boolean`
|
|
60
|
+
|
|
61
|
+
##### settle()
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
settle(input): void;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Keep the hold when media was delivered; release it when nothing was.
|
|
68
|
+
|
|
69
|
+
###### Parameters
|
|
70
|
+
|
|
71
|
+
| Parameter | Type |
|
|
72
|
+
| --------- | -------------------------------------------------------------------- |
|
|
73
|
+
| `input` | `Readonly`\<\{ `operationId`: `string`; `delivered`: `boolean`; \}\> |
|
|
74
|
+
|
|
75
|
+
###### Returns
|
|
76
|
+
|
|
77
|
+
`void`
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
13
81
|
### MediaExecutionError
|
|
14
82
|
|
|
15
83
|
A bounded stage marker for failures that cross the Media HTTP boundary.
|
|
@@ -802,6 +870,39 @@ Release preparation or refused admission so the same request can retry.
|
|
|
802
870
|
|
|
803
871
|
## Type Aliases
|
|
804
872
|
|
|
873
|
+
### DailyMediaMeterStorage
|
|
874
|
+
|
|
875
|
+
```ts
|
|
876
|
+
type DailyMediaMeterStorage = Readonly<{
|
|
877
|
+
sql: Readonly<{
|
|
878
|
+
exec: (
|
|
879
|
+
query,
|
|
880
|
+
...bindings
|
|
881
|
+
) => Readonly<{
|
|
882
|
+
toArray: () => readonly unknown[];
|
|
883
|
+
}>;
|
|
884
|
+
}>;
|
|
885
|
+
transactionSync: <T>(body) => T;
|
|
886
|
+
}>;
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
The Durable Object storage slice the meter owns tables in.
|
|
890
|
+
|
|
891
|
+
---
|
|
892
|
+
|
|
893
|
+
### DailyMediaMeterPort
|
|
894
|
+
|
|
895
|
+
```ts
|
|
896
|
+
type DailyMediaMeterPort = Readonly<{
|
|
897
|
+
dailyAdmit: (input) => Promise<boolean> | boolean;
|
|
898
|
+
dailySettle: (input) => Promise<void> | void;
|
|
899
|
+
}>;
|
|
900
|
+
```
|
|
901
|
+
|
|
902
|
+
RPC surface of the Durable Object that owns one Oyster's daily media total.
|
|
903
|
+
|
|
904
|
+
---
|
|
905
|
+
|
|
805
906
|
### MediaFailureStage
|
|
806
907
|
|
|
807
908
|
```ts
|
|
@@ -835,7 +936,8 @@ Private cause plus an independently decoded, safe provider diagnostic.
|
|
|
835
936
|
### MediaBillingRefusalCode
|
|
836
937
|
|
|
837
938
|
```ts
|
|
838
|
-
type MediaBillingRefusalCode =
|
|
939
|
+
type MediaBillingRefusalCode =
|
|
940
|
+
"insufficient_credits" | "denied" | "daily_limit_reached";
|
|
839
941
|
```
|
|
840
942
|
|
|
841
943
|
Why the host's billing owner refused to admit a new generation.
|
|
@@ -1086,6 +1188,7 @@ Retained output projection, or a terminal spent format refusal.
|
|
|
1086
1188
|
```ts
|
|
1087
1189
|
type MediaOperationHooks = Readonly<{
|
|
1088
1190
|
namespace?: () => string | null;
|
|
1191
|
+
catalogue?: () => MediaCatalogue;
|
|
1089
1192
|
}>;
|
|
1090
1193
|
```
|
|
1091
1194
|
|
|
@@ -1463,6 +1566,16 @@ Delete the owner-selected object key.
|
|
|
1463
1566
|
|
|
1464
1567
|
---
|
|
1465
1568
|
|
|
1569
|
+
### MediaQuote
|
|
1570
|
+
|
|
1571
|
+
```ts
|
|
1572
|
+
type MediaQuote = Readonly<MediaUnits & object>;
|
|
1573
|
+
```
|
|
1574
|
+
|
|
1575
|
+
The provider cost of one exact generation request, before any billing policy.
|
|
1576
|
+
|
|
1577
|
+
---
|
|
1578
|
+
|
|
1466
1579
|
### MediaScope
|
|
1467
1580
|
|
|
1468
1581
|
```ts
|
|
@@ -1505,6 +1618,14 @@ type MediaServiceHost = Readonly<{
|
|
|
1505
1618
|
readReference?: (reference, model) => Promise<MediaReferenceBytes>;
|
|
1506
1619
|
}>;
|
|
1507
1620
|
onFailure?: (error) => Response | undefined;
|
|
1621
|
+
}> &
|
|
1622
|
+
| Readonly<{
|
|
1623
|
+
catalogue?: undefined;
|
|
1624
|
+
estimate?: undefined;
|
|
1625
|
+
}>
|
|
1626
|
+
| Readonly<{
|
|
1627
|
+
catalogue: MediaCatalogue;
|
|
1628
|
+
estimate: (settings, references) => number;
|
|
1508
1629
|
}> &
|
|
1509
1630
|
| Readonly<{
|
|
1510
1631
|
metering: "unmetered";
|
|
@@ -2021,19 +2142,41 @@ Quote the catalog defaults through the exact estimator used before dispatch.
|
|
|
2021
2142
|
|
|
2022
2143
|
---
|
|
2023
2144
|
|
|
2145
|
+
### createDailyMediaMetering()
|
|
2146
|
+
|
|
2147
|
+
```ts
|
|
2148
|
+
function createDailyMediaMetering(meter, limitMilliunits): MediaMetering;
|
|
2149
|
+
```
|
|
2150
|
+
|
|
2151
|
+
`MediaMetering` that enforces one exact daily limit through the owning object.
|
|
2152
|
+
|
|
2153
|
+
#### Parameters
|
|
2154
|
+
|
|
2155
|
+
| Parameter | Type |
|
|
2156
|
+
| ----------------- | --------------------------------------------- |
|
|
2157
|
+
| `meter` | [`DailyMediaMeterPort`](#dailymediameterport) |
|
|
2158
|
+
| `limitMilliunits` | `number` |
|
|
2159
|
+
|
|
2160
|
+
#### Returns
|
|
2161
|
+
|
|
2162
|
+
[`MediaMetering`](#mediametering)
|
|
2163
|
+
|
|
2164
|
+
---
|
|
2165
|
+
|
|
2024
2166
|
### mediaUnits()
|
|
2025
2167
|
|
|
2026
2168
|
```ts
|
|
2027
|
-
function mediaUnits(settings): MediaUnits;
|
|
2169
|
+
function mediaUnits(settings, catalogue?): MediaUnits;
|
|
2028
2170
|
```
|
|
2029
2171
|
|
|
2030
2172
|
Billing units for validated settings; video bills its requested length.
|
|
2031
2173
|
|
|
2032
2174
|
#### Parameters
|
|
2033
2175
|
|
|
2034
|
-
| Parameter
|
|
2035
|
-
|
|
|
2036
|
-
| `settings`
|
|
2176
|
+
| Parameter | Type | Default value |
|
|
2177
|
+
| ----------- | ------------------------------------------------------------- | ------------- |
|
|
2178
|
+
| `settings` | [`MediaGenerationSettings`](index.md#mediagenerationsettings) | `undefined` |
|
|
2179
|
+
| `catalogue` | [`MediaCatalogue`](index.md#mediacatalogue) | `mediaModels` |
|
|
2037
2180
|
|
|
2038
2181
|
#### Returns
|
|
2039
2182
|
|
|
@@ -2176,6 +2319,52 @@ Decode bounded service replies once for both MEDIA host bindings.
|
|
|
2176
2319
|
|
|
2177
2320
|
---
|
|
2178
2321
|
|
|
2322
|
+
### quoteMediaGeneration()
|
|
2323
|
+
|
|
2324
|
+
```ts
|
|
2325
|
+
function quoteMediaGeneration(
|
|
2326
|
+
raw,
|
|
2327
|
+
references,
|
|
2328
|
+
): Promise<
|
|
2329
|
+
Readonly<
|
|
2330
|
+
Readonly<{
|
|
2331
|
+
unit: "image" | "video_second";
|
|
2332
|
+
units: number;
|
|
2333
|
+
}> &
|
|
2334
|
+
object
|
|
2335
|
+
>
|
|
2336
|
+
>;
|
|
2337
|
+
```
|
|
2338
|
+
|
|
2339
|
+
Quote one exact request: the same settings validation, reference reads,
|
|
2340
|
+
estimator and billing units a generation uses at admission, run without
|
|
2341
|
+
dispatching anything. A host applies its billing policy to this per unit, the
|
|
2342
|
+
way its metering does, so the number matches the charge.
|
|
2343
|
+
|
|
2344
|
+
#### Parameters
|
|
2345
|
+
|
|
2346
|
+
| Parameter | Type | Description |
|
|
2347
|
+
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
2348
|
+
| `raw` | \{ `model`: `string`; `prompt`: `string`; `width`: `number`; `height`: `number`; `steps?`: `number`; `durationSeconds?`: `number`; `resolution?`: `"480p"` \| `"720p"` \| `"768p"` \| `"1080p"` \| `"4k"`; `aspectRatio?`: `"16:9"` \| `"4:3"` \| `"1:1"` \| `"3:4"` \| `"9:16"` \| `"21:9"` \| `"9:21"`; `generateAudio?`: `boolean`; `references?`: `object`[]; \} | - |
|
|
2349
|
+
| `raw.model` | `string` | Provider catalog model identifier. |
|
|
2350
|
+
| `raw.prompt` | `string` | Generation prompt; each model's `maxPromptLength` is enforced on top of this ceiling. |
|
|
2351
|
+
| `raw.width` | `number` | Requested image width or nominal video selector, not decoded MP4 dimensions. |
|
|
2352
|
+
| `raw.height` | `number` | Requested image height or nominal video selector, not decoded MP4 dimensions. |
|
|
2353
|
+
| `raw.steps?` | `number` | Model-specific inference step count. |
|
|
2354
|
+
| `raw.durationSeconds?` | `number` | Requested video length in whole seconds. |
|
|
2355
|
+
| `raw.resolution?` | `"480p"` \| `"720p"` \| `"768p"` \| `"1080p"` \| `"4k"` | Video resolution; must match the nominal width/height selector. |
|
|
2356
|
+
| `raw.aspectRatio?` | `"16:9"` \| `"4:3"` \| `"1:1"` \| `"3:4"` \| `"9:16"` \| `"21:9"` \| `"9:21"` | Video aspect; must match the nominal width/height selector. |
|
|
2357
|
+
| `raw.generateAudio?` | `boolean` | Video audio selection. |
|
|
2358
|
+
| `raw.references?` | `object`[] | Host-authorized reference images. |
|
|
2359
|
+
| `references` | [`MediaReferenceReader`](index.md#mediareferencereader) | - |
|
|
2360
|
+
|
|
2361
|
+
#### Returns
|
|
2362
|
+
|
|
2363
|
+
`Promise`\<`Readonly`\<`Readonly`\<\{ `unit`: `"image"` \| `"video_second"`;
|
|
2364
|
+
`units`: `number`; \}\> & `object`\>\>
|
|
2365
|
+
|
|
2366
|
+
---
|
|
2367
|
+
|
|
2179
2368
|
### generateMedia()
|
|
2180
2369
|
|
|
2181
2370
|
```ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/darkroom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"author": "Levi <levi@technomancy.dev>",
|
|
5
5
|
"description": "Media generation, durable output retention and provenance with host-owned authority and billing",
|
|
6
6
|
"type": "module",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"exifreader": "4.46.0",
|
|
60
60
|
"@fungi.computer/ts-webp": "0.1.6",
|
|
61
61
|
"@xmldom/xmldom": "0.9.12",
|
|
62
|
-
"@fungi.computer/agar": "0.
|
|
62
|
+
"@fungi.computer/agar": "0.13.0",
|
|
63
63
|
"@fungi.computer/capnweb": "0.12.0-fungi.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|