@fungi.computer/darkroom 0.11.1 → 0.11.2
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/dist/daily-media-meter.d.ts +5 -0
- package/dist/daily-media-meter.js +29 -9
- package/dist/server.js +6 -1
- package/package.json +2 -2
|
@@ -51,5 +51,10 @@ export declare class DailyMediaMeter {
|
|
|
51
51
|
delivered: boolean;
|
|
52
52
|
}>): void;
|
|
53
53
|
}
|
|
54
|
+
/** Which daily-meter RPC failed; its original cause stays private. */
|
|
55
|
+
export declare class DailyMediaMeterError extends Error {
|
|
56
|
+
readonly operation: "admit" | "settle";
|
|
57
|
+
constructor(operation: "admit" | "settle", options: ErrorOptions);
|
|
58
|
+
}
|
|
54
59
|
/** `MediaMetering` that enforces one exact daily limit through the owning object. */
|
|
55
60
|
export declare function createDailyMediaMetering(meter: DailyMediaMeterPort, limitMilliunits: number): MediaMetering;
|
|
@@ -58,24 +58,44 @@ export class DailyMediaMeter {
|
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
/** Which daily-meter RPC failed; its original cause stays private. */
|
|
62
|
+
export class DailyMediaMeterError extends Error {
|
|
63
|
+
operation;
|
|
64
|
+
constructor(operation, options) {
|
|
65
|
+
super(`Daily media meter ${operation} failed`, options);
|
|
66
|
+
this.operation = operation;
|
|
67
|
+
this.name = "DailyMediaMeterError";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
61
70
|
/** `MediaMetering` that enforces one exact daily limit through the owning object. */
|
|
62
71
|
export function createDailyMediaMetering(meter, limitMilliunits) {
|
|
63
72
|
return {
|
|
64
73
|
admit: async (input) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
let admitted;
|
|
75
|
+
try {
|
|
76
|
+
admitted = await meter.dailyAdmit({
|
|
77
|
+
operationId: input.operationId,
|
|
78
|
+
costMilliunits: input.providerCostMilliunits,
|
|
79
|
+
limitMilliunits,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch (cause) {
|
|
83
|
+
throw new DailyMediaMeterError("admit", { cause });
|
|
84
|
+
}
|
|
70
85
|
if (!admitted)
|
|
71
86
|
throw new MediaBillingRefusal("daily_limit_reached");
|
|
72
87
|
return { priceMilliunits: input.providerCostMilliunits };
|
|
73
88
|
},
|
|
74
89
|
settle: async (input) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
90
|
+
try {
|
|
91
|
+
await meter.dailySettle({
|
|
92
|
+
operationId: input.operationId,
|
|
93
|
+
delivered: input.units > 0,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch (cause) {
|
|
97
|
+
throw new DailyMediaMeterError("settle", { cause });
|
|
98
|
+
}
|
|
79
99
|
},
|
|
80
100
|
};
|
|
81
101
|
}
|
package/dist/server.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DailyMediaMeterError } from "./daily-media-meter.js";
|
|
1
2
|
import { mediaPendingSchema } from "./media-binding.js";
|
|
2
3
|
export { estimateMediaModel } from "./cloudflare/provider.js";
|
|
3
4
|
export { mediaPendingSchema, mediaBindingCallSchema, mediaBindingGenerationSchema, mediaImageBindingInputSchema, mediaVideoBindingInputSchema, parseMediaBindingCall, mediaBindingRequest, readMediaBindingReply, } from "./media-binding.js";
|
|
@@ -125,7 +126,11 @@ function failure(error, refusalMessages) {
|
|
|
125
126
|
"destination-authorization": "Media destination permission could not be checked; try again.",
|
|
126
127
|
"destination-write": "Media generated an image but could not save it; retry this request to save the retained result.",
|
|
127
128
|
estimate: "Media could not prepare the image inputs or estimate their cost; check the reference files and retry.",
|
|
128
|
-
billing:
|
|
129
|
+
billing: error.cause instanceof DailyMediaMeterError
|
|
130
|
+
? error.cause.operation === "admit"
|
|
131
|
+
? "Couldn't check today's spending limit. Try again."
|
|
132
|
+
: "Couldn't record this generation's spending. Retry this request."
|
|
133
|
+
: "Media billing is unavailable; retry this request.",
|
|
129
134
|
normalization: "Media provider returned an unusable image; start a new request only after checking provider status.",
|
|
130
135
|
artifact: "Media generated output could not be retained or read; try again.",
|
|
131
136
|
operation: "Media operation is unresolved; try again.",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/darkroom",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
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",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"exifreader": "4.46.0",
|
|
61
61
|
"@fungi.computer/ts-webp": "0.1.6",
|
|
62
62
|
"@xmldom/xmldom": "0.9.12",
|
|
63
|
-
"@fungi.computer/agar": "0.18.
|
|
63
|
+
"@fungi.computer/agar": "0.18.2",
|
|
64
64
|
"@fungi.computer/capnweb": "0.12.0-fungi.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|