@jini-ai/integrations 0.4.2 → 0.6.10
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/CHANGELOG.md +99 -1
- package/README.md +1 -0
- package/dist/api-connections/access-token.d.ts +9 -0
- package/dist/api-connections/access-token.js +92 -0
- package/dist/api-connections/account-actions.d.ts +40 -0
- package/dist/api-connections/account-actions.js +110 -0
- package/dist/api-connections/attempt-state.d.ts +28 -0
- package/dist/api-connections/attempt-state.js +73 -0
- package/dist/api-connections/authorization.d.ts +45 -0
- package/dist/api-connections/authorization.js +120 -0
- package/dist/api-connections/deps.d.ts +41 -0
- package/dist/api-connections/deps.js +13 -0
- package/dist/api-connections/descriptor.d.ts +6 -0
- package/dist/api-connections/descriptor.js +111 -0
- package/dist/api-connections/errors.d.ts +23 -0
- package/dist/api-connections/errors.js +24 -0
- package/dist/api-connections/finish-authorization.d.ts +24 -0
- package/dist/api-connections/finish-authorization.js +117 -0
- package/dist/api-connections/index.d.ts +18 -0
- package/dist/api-connections/index.js +10 -0
- package/dist/api-connections/install-credential.d.ts +19 -0
- package/dist/api-connections/install-credential.js +12 -0
- package/dist/api-connections/keys.d.ts +27 -0
- package/dist/api-connections/keys.js +22 -0
- package/dist/api-connections/ports.d.ts +73 -0
- package/dist/api-connections/ports.js +2 -0
- package/dist/api-connections/records.d.ts +27 -0
- package/dist/api-connections/records.js +52 -0
- package/dist/api-connections/request-checks.d.ts +18 -0
- package/dist/api-connections/request-checks.js +67 -0
- package/dist/api-connections/service.d.ts +25 -0
- package/dist/api-connections/service.js +26 -0
- package/dist/api-connections/status.d.ts +28 -0
- package/dist/api-connections/status.js +36 -0
- package/dist/api-connections/token-store/errors.d.ts +20 -0
- package/dist/api-connections/token-store/errors.js +38 -0
- package/dist/api-connections/token-store/index.d.ts +6 -0
- package/dist/api-connections/token-store/index.js +6 -0
- package/dist/api-connections/token-store/record.d.ts +69 -0
- package/dist/api-connections/token-store/record.js +97 -0
- package/dist/api-connections/token-store/vault-token-store.d.ts +26 -0
- package/dist/api-connections/token-store/vault-token-store.js +215 -0
- package/dist/api-connections/types.d.ts +101 -0
- package/dist/api-connections/types.js +9 -0
- package/dist/credentialed-http/auth-schemes.js +8 -4
- package/dist/credentialed-http/credentialed-request.d.ts +4 -0
- package/dist/credentialed-http/credentialed-request.js +61 -77
- package/dist/credentialed-http/response-redaction.d.ts +15 -0
- package/dist/credentialed-http/response-redaction.js +82 -0
- package/dist/media-providers/catalog.d.ts +3 -1
- package/dist/media-providers/catalog.js +3 -1
- package/dist/media-providers/dispatch/async-operation-store.d.ts +31 -0
- package/dist/media-providers/dispatch/async-operation-store.js +75 -37
- package/dist/media-providers/dispatch/builtin-vendors.d.ts +1 -1
- package/dist/media-providers/dispatch/context.js +10 -2
- package/dist/media-providers/dispatch/engine.d.ts +6 -3
- package/dist/media-providers/dispatch/engine.js +99 -109
- package/dist/media-providers/dispatch/index.d.ts +4 -2
- package/dist/media-providers/dispatch/index.js +3 -1
- package/dist/media-providers/dispatch/media-provider-registry.d.ts +62 -0
- package/dist/media-providers/dispatch/media-provider-registry.js +141 -0
- package/dist/media-providers/dispatch/node.d.ts +13 -0
- package/dist/media-providers/dispatch/node.js +24 -0
- package/dist/media-providers/dispatch/openai-compatible.d.ts +1 -1
- package/dist/media-providers/dispatch/openai-compatible.js +90 -87
- package/dist/media-providers/dispatch/operation-runtime.js +116 -89
- package/dist/media-providers/dispatch/outbound.d.ts +8 -4
- package/dist/media-providers/dispatch/outbound.js +27 -26
- package/dist/media-providers/dispatch/providers/aihubmix.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/aihubmix.js +61 -56
- package/dist/media-providers/dispatch/providers/custom-image.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/elevenlabs.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/fishaudio.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/grok.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.js +53 -49
- package/dist/media-providers/dispatch/providers/imagerouter.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/imagerouter.js +11 -24
- package/dist/media-providers/dispatch/providers/minimax.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/nanobanana.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/nanobanana.js +22 -30
- package/dist/media-providers/dispatch/providers/openai.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/openai.js +51 -47
- package/dist/media-providers/dispatch/providers/openrouter.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/openrouter.js +52 -37
- package/dist/media-providers/dispatch/providers/senseaudio.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/senseaudio.js +47 -28
- package/dist/media-providers/dispatch/providers/volcengine.d.ts +1 -1
- package/dist/media-providers/dispatch/response-parsers.js +37 -21
- package/dist/media-providers/dispatch/sqlite-async-operation-store.js +9 -29
- package/dist/media-providers/dispatch/ssrf-guard.d.ts +3 -2
- package/dist/media-providers/dispatch/ssrf-guard.js +6 -5
- package/dist/media-providers/dispatch/types.d.ts +76 -2
- package/dist/media-providers/dispatch/vendor-adapter.d.ts +2 -43
- package/dist/media-providers/dispatch/vendor-adapter.js +2 -2
- package/dist/media-providers/dispatch/vendor-registry-core.d.ts +24 -0
- package/dist/media-providers/dispatch/vendor-registry-core.js +34 -0
- package/dist/media-providers/dispatch/vendor-registry.d.ts +10 -36
- package/dist/media-providers/dispatch/vendor-registry.js +14 -42
- package/dist/media-providers/policy.js +25 -17
- package/dist/media-providers/providers.d.ts +5 -0
- package/dist/media-providers/providers.js +2 -0
- package/dist/media-providers/sqlite-task-store.js +12 -80
- package/dist/media-providers/staging.js +77 -58
- package/dist/media-providers/task-lifecycle.d.ts +33 -0
- package/dist/media-providers/task-lifecycle.js +124 -0
- package/dist/media-providers/task-store.js +8 -86
- package/dist/media-providers/ui-defaults.d.ts +10 -0
- package/dist/media-providers/ui-defaults.js +167 -0
- package/dist/media-providers/video-request.js +112 -90
- package/dist/saved-requests/definition.d.ts +17 -0
- package/dist/saved-requests/definition.js +84 -0
- package/dist/saved-requests/execute.d.ts +17 -0
- package/dist/saved-requests/execute.js +95 -0
- package/dist/saved-requests/index.d.ts +6 -0
- package/dist/saved-requests/index.js +4 -0
- package/dist/saved-requests/projection.d.ts +9 -0
- package/dist/saved-requests/projection.js +48 -0
- package/dist/saved-requests/schema.d.ts +7 -0
- package/dist/saved-requests/schema.js +73 -0
- package/dist/saved-requests/types.d.ts +58 -0
- package/dist/saved-requests/types.js +2 -0
- package/dist/saved-requests/validation.d.ts +46 -0
- package/dist/saved-requests/validation.js +66 -0
- package/dist/webhooks/delivery.d.ts +14 -0
- package/dist/webhooks/delivery.js +41 -10
- package/dist/webhooks/index.d.ts +1 -0
- package/dist/webhooks/index.js +1 -0
- package/dist/webhooks/ports.d.ts +23 -0
- package/dist/webhooks/worker.d.ts +83 -0
- package/dist/webhooks/worker.js +105 -0
- package/package.json +46 -9
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response redaction for credentialed requests: strips credential-bearing headers and scrubs the
|
|
3
|
+
* injected secrets out of provider text before anything reaches the caller or the model.
|
|
4
|
+
* Module-internal: not re-exported from the credentialed-http barrel.
|
|
5
|
+
*/
|
|
6
|
+
// Echo endpoints and provider cookies must not return credential-bearing headers to the model,
|
|
7
|
+
// even when a value is too short to identify safely by substring matching.
|
|
8
|
+
const FORBIDDEN_RESPONSE_HEADER_NAMES = new Set(["authorization", "proxy-authorization", "set-cookie", "cookie"]);
|
|
9
|
+
// A visible marker explains removal; silently splicing bytes out could alter the response's meaning.
|
|
10
|
+
const REDACTED_MARKER = "[REDACTED]";
|
|
11
|
+
// Very short tokens can match ordinary words ("ab" inside "abacus"); scrubbing would silently
|
|
12
|
+
// mangle unrelated content. The eight-character floor retains normal long API-token responses
|
|
13
|
+
// while withholding pathological ones. Dropping a whole response header needs no such floor.
|
|
14
|
+
const MIN_SAFE_BODY_REDACTION_TOKEN_LENGTH = 8;
|
|
15
|
+
// Withhold the body rather than leak the secret or make unrelated content look like provider output;
|
|
16
|
+
// the request still ran, and the marker lets a caller distinguish display limits from auth failure.
|
|
17
|
+
const BODY_WITHHELD_SHORT_TOKEN_MARKER = "[body withheld: credential too short to redact safely]";
|
|
18
|
+
// Match secrets embedded in diagnostic header values too, not just values equal to a full secret.
|
|
19
|
+
// Whole-header removal has no partial-mangling failure mode and therefore applies at any length.
|
|
20
|
+
export function redactResponseHeaders(headers, secrets) {
|
|
21
|
+
const result = {};
|
|
22
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
23
|
+
if (FORBIDDEN_RESPONSE_HEADER_NAMES.has(key.trim().toLowerCase()))
|
|
24
|
+
continue;
|
|
25
|
+
if (secrets.some((secret) => secret !== "" && value.includes(secret)))
|
|
26
|
+
continue;
|
|
27
|
+
result[key] = value;
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
// Reflecting responses must not send injected credentials back through the model; retain all other
|
|
32
|
+
// provider text instead of replacing the provider's answer with an authentication diagnosis.
|
|
33
|
+
export function redactSecretSubstrings(text, secrets) {
|
|
34
|
+
return secrets.reduce((acc, secret) => (secret === "" ? acc : acc.split(secret).join(REDACTED_MARKER)), text);
|
|
35
|
+
}
|
|
36
|
+
// One-to-three-character suffix matches are too ambiguous to identify a cut-off secret. This
|
|
37
|
+
// four-character partial-tail floor gates a different risk from the full-token length floor above.
|
|
38
|
+
const MIN_SAFE_TRUNCATED_TAIL_PREFIX_LENGTH = 4;
|
|
39
|
+
// A size cap can cut a reflected secret mid-token, so whole-secret replacement alone leaks its
|
|
40
|
+
// prefix. Use the longest matching suffix across all secrets to remove the whole fragment; only
|
|
41
|
+
// truncated bodies qualify, since matching complete bodies could remove innocent trailing text.
|
|
42
|
+
export function redactTruncatedTail(body, secrets) {
|
|
43
|
+
let longestMatch = 0;
|
|
44
|
+
for (const secret of secrets) {
|
|
45
|
+
for (let len = Math.min(secret.length, body.length); len >= MIN_SAFE_TRUNCATED_TAIL_PREFIX_LENGTH; len--) {
|
|
46
|
+
if (body.endsWith(secret.slice(0, len))) {
|
|
47
|
+
longestMatch = Math.max(longestMatch, len);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return longestMatch === 0 ? body : body.slice(0, body.length - longestMatch) + REDACTED_MARKER;
|
|
53
|
+
}
|
|
54
|
+
// Gate on the raw token: a scheme-prefixed header is longer and cannot make a short token safe.
|
|
55
|
+
// The second pass is conditional because a complete response has no cap-cut fragment to repair.
|
|
56
|
+
export function resolveRedactedResponseBody(bodyText, token, secrets, bodyTruncated) {
|
|
57
|
+
if (token.length < MIN_SAFE_BODY_REDACTION_TOKEN_LENGTH)
|
|
58
|
+
return BODY_WITHHELD_SHORT_TOKEN_MARKER;
|
|
59
|
+
const redacted = redactSecretSubstrings(bodyText, secrets);
|
|
60
|
+
return bodyTruncated ? redactTruncatedTail(redacted, secrets) : redacted;
|
|
61
|
+
}
|
|
62
|
+
/** Opt-in JSON release boundary: decode escaped strings before using the same credential-secret
|
|
63
|
+
* owner. Scrubbing only serialized bytes misses a provider echo such as `\u0073ecret-token`.
|
|
64
|
+
* Callers must reject truncated responses first. Malformed JSON or secrets in keys/numbers throw;
|
|
65
|
+
* short tokens withhold the whole body under the existing rule. The reviver visits decoded keys
|
|
66
|
+
* and values at every depth. @complexity O(n * s), bounded body and secrets. */
|
|
67
|
+
export function redactJsonResponseBody({ bodyText, token, secrets }, _options = {}) {
|
|
68
|
+
if (token.length < MIN_SAFE_BODY_REDACTION_TOKEN_LENGTH)
|
|
69
|
+
return BODY_WITHHELD_SHORT_TOKEN_MARKER;
|
|
70
|
+
const decoded = JSON.parse(bodyText, (key, value) => {
|
|
71
|
+
// Refuse rather than rename fields or change numeric types in the provider's data.
|
|
72
|
+
if (secrets.some(secret => secret !== "" && key.includes(secret)))
|
|
73
|
+
throw new TypeError("JSON response key contains a credential");
|
|
74
|
+
if (typeof value === "number" && secrets.some(secret => secret !== "" && String(value).includes(secret)))
|
|
75
|
+
throw new TypeError("JSON response number contains a credential");
|
|
76
|
+
if (typeof value === "string")
|
|
77
|
+
return redactSecretSubstrings(value, secrets);
|
|
78
|
+
return value;
|
|
79
|
+
});
|
|
80
|
+
return JSON.stringify(decoded);
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=response-redaction.js.map
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
* imports nothing at all, so this pair is genuinely dependency-free and safe to mark
|
|
11
11
|
* `"universal"`.
|
|
12
12
|
*
|
|
13
|
-
* The constraint this file encodes: **
|
|
13
|
+
* The constraint this file encodes: **runtime imports stay inside the pure catalog graph.**
|
|
14
|
+
* UI projections import only core types, erased before evaluation; no UI or React dependency exists.
|
|
14
15
|
* Adding anything that reaches `dispatch/`, `staging.ts`, or `sqlite-task-store.ts` silently
|
|
15
16
|
* reintroduces the node dependency for every browser consumer. `__tests__/catalog.test.ts` asserts
|
|
16
17
|
* the import graph stays clean, so that mistake fails a test rather than a downstream bundle.
|
|
17
18
|
*/
|
|
18
19
|
export * from './types.js';
|
|
19
20
|
export * from './providers.js';
|
|
21
|
+
export { DEFAULT_MEDIA_PROVIDER_CATALOG, DEFAULT_PROVIDER_PRESETS } from './ui-defaults.js';
|
|
20
22
|
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
* imports nothing at all, so this pair is genuinely dependency-free and safe to mark
|
|
11
11
|
* `"universal"`.
|
|
12
12
|
*
|
|
13
|
-
* The constraint this file encodes: **
|
|
13
|
+
* The constraint this file encodes: **runtime imports stay inside the pure catalog graph.**
|
|
14
|
+
* UI projections import only core types, erased before evaluation; no UI or React dependency exists.
|
|
14
15
|
* Adding anything that reaches `dispatch/`, `staging.ts`, or `sqlite-task-store.ts` silently
|
|
15
16
|
* reintroduces the node dependency for every browser consumer. `__tests__/catalog.test.ts` asserts
|
|
16
17
|
* the import graph stays clean, so that mistake fails a test rather than a downstream bundle.
|
|
17
18
|
*/
|
|
18
19
|
export * from './types.js';
|
|
19
20
|
export * from './providers.js';
|
|
21
|
+
export { DEFAULT_MEDIA_PROVIDER_CATALOG, DEFAULT_PROVIDER_PRESETS } from './ui-defaults.js';
|
|
20
22
|
//# sourceMappingURL=catalog.js.map
|
|
@@ -211,6 +211,37 @@ export declare function hydrateAsyncOperationRecord({ raw }: {
|
|
|
211
211
|
}): AsyncOperationRecord;
|
|
212
212
|
/** Exported for the same reason as `TERMINAL_STATUSES` — see its doc. */
|
|
213
213
|
export declare function assertTransition(from: AsyncOperationStatus, to: AsyncOperationStatus): void;
|
|
214
|
+
/**
|
|
215
|
+
* Create-time validation shared by every store, in order: `maxAttempts`, `deadlineAt`, then the
|
|
216
|
+
* `state` allowlist. The duplicate-id check stays with each store, which alone knows its storage
|
|
217
|
+
* and runs it first. Exported for the same reason as `TERMINAL_STATUSES` — see its doc.
|
|
218
|
+
* @throws RangeError for a bad bound; `Error` (see `assertNoCredentialMaterial`) for a bad state.
|
|
219
|
+
*/
|
|
220
|
+
export declare function assertValidCreateInput({ input }: {
|
|
221
|
+
input: AsyncOperationCreateInput;
|
|
222
|
+
}): void;
|
|
223
|
+
/**
|
|
224
|
+
* True when a fenced write names a lease owner the row no longer has. Such a write is a no-op that
|
|
225
|
+
* returns the row unchanged — see `AsyncOperationUpdateOptions.leaseOwner`. Exported for the same
|
|
226
|
+
* reason as `TERMINAL_STATUSES`.
|
|
227
|
+
*/
|
|
228
|
+
export declare function isFencedOut({ existing, options }: {
|
|
229
|
+
existing: AsyncOperationRecord;
|
|
230
|
+
options: AsyncOperationUpdateOptions | undefined;
|
|
231
|
+
}): boolean;
|
|
232
|
+
/**
|
|
233
|
+
* The update rule every store applies after its lease fence: reject credential material in a
|
|
234
|
+
* patched `state`, then an illegal status transition, then merge. Returns the next record without
|
|
235
|
+
* copying `state` — the caller decides how to store it. Exported for the same reason as
|
|
236
|
+
* `TERMINAL_STATUSES`.
|
|
237
|
+
* @throws `Error` for credential material; `RangeError` for an illegal transition.
|
|
238
|
+
*/
|
|
239
|
+
export declare function mergeAsyncOperationPatch({ existing, patch }: {
|
|
240
|
+
existing: AsyncOperationRecord;
|
|
241
|
+
patch: AsyncOperationPatch;
|
|
242
|
+
}, { now }: {
|
|
243
|
+
now: number;
|
|
244
|
+
}): AsyncOperationRecord;
|
|
214
245
|
/**
|
|
215
246
|
* Creates the in-memory reference `AsyncOperationStore`. No persistence — a durable adapter
|
|
216
247
|
* implements the same interface; every method here is written so the equivalent SQL is a direct
|
|
@@ -103,7 +103,7 @@ export function assertNoCredentialMaterial({ state }) {
|
|
|
103
103
|
* @complexity O(1).
|
|
104
104
|
*/
|
|
105
105
|
export function hydrateAsyncOperationRecord({ raw }) {
|
|
106
|
-
const stored =
|
|
106
|
+
const stored = numberOr(raw.schemaVersion, 0);
|
|
107
107
|
if (stored > ASYNC_OPERATION_SCHEMA_VERSION) {
|
|
108
108
|
throw new Error(`async operation row was written at schema version ${stored}, newer than this build understands (${ASYNC_OPERATION_SCHEMA_VERSION}) — upgrade rather than risk misreading it`);
|
|
109
109
|
}
|
|
@@ -117,23 +117,31 @@ export function hydrateAsyncOperationRecord({ raw }) {
|
|
|
117
117
|
routeKey: String(raw.routeKey),
|
|
118
118
|
ownerRef: String(raw.ownerRef),
|
|
119
119
|
status: raw.status ?? 'submitted',
|
|
120
|
-
attempts:
|
|
120
|
+
attempts: numberOr(raw.attempts, 0),
|
|
121
121
|
maxAttempts: Number(raw.maxAttempts),
|
|
122
122
|
deadlineAt: Number(raw.deadlineAt),
|
|
123
|
-
nextPollAt:
|
|
123
|
+
nextPollAt: numberOr(raw.nextPollAt, now),
|
|
124
124
|
leaseOwner: raw.leaseOwner ?? null,
|
|
125
125
|
leaseExpiresAt: raw.leaseExpiresAt ?? null,
|
|
126
126
|
state: raw.state ?? null,
|
|
127
127
|
result: raw.result ?? null,
|
|
128
128
|
error: raw.error ?? null,
|
|
129
|
-
createdAt:
|
|
130
|
-
updatedAt:
|
|
129
|
+
createdAt: numberOr(raw.createdAt, now),
|
|
130
|
+
updatedAt: numberOr(raw.updatedAt, now),
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
|
+
/** A persisted number column, or `fallback` when the raw value is absent or not a number. */
|
|
134
|
+
function numberOr(value, fallback) {
|
|
135
|
+
return typeof value === 'number' ? value : fallback;
|
|
136
|
+
}
|
|
137
|
+
/** Deep-copies a `state` handle so no caller-held object aliases a stored row. */
|
|
138
|
+
function cloneState(state) {
|
|
139
|
+
return state === null ? null : structuredClone(state);
|
|
140
|
+
}
|
|
133
141
|
function cloneRecord(row) {
|
|
134
142
|
return {
|
|
135
143
|
...row,
|
|
136
|
-
state:
|
|
144
|
+
state: cloneState(row.state),
|
|
137
145
|
result: row.result === null ? null : { ...row.result },
|
|
138
146
|
error: row.error === null ? null : { ...row.error },
|
|
139
147
|
};
|
|
@@ -147,6 +155,58 @@ export function assertTransition(from, to) {
|
|
|
147
155
|
throw new RangeError(`Invalid async operation transition: "${from}" -> "${to}"`);
|
|
148
156
|
}
|
|
149
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Create-time validation shared by every store, in order: `maxAttempts`, `deadlineAt`, then the
|
|
160
|
+
* `state` allowlist. The duplicate-id check stays with each store, which alone knows its storage
|
|
161
|
+
* and runs it first. Exported for the same reason as `TERMINAL_STATUSES` — see its doc.
|
|
162
|
+
* @throws RangeError for a bad bound; `Error` (see `assertNoCredentialMaterial`) for a bad state.
|
|
163
|
+
*/
|
|
164
|
+
export function assertValidCreateInput({ input }) {
|
|
165
|
+
if (!Number.isFinite(input.maxAttempts) || input.maxAttempts < 1) {
|
|
166
|
+
throw new RangeError(`Invalid maxAttempts: ${input.maxAttempts} must be a finite number >= 1`);
|
|
167
|
+
}
|
|
168
|
+
if (!Number.isFinite(input.deadlineAt)) {
|
|
169
|
+
throw new RangeError(`Invalid deadlineAt: ${input.deadlineAt} must be a finite epoch-ms timestamp`);
|
|
170
|
+
}
|
|
171
|
+
assertNoCredentialMaterial({ state: input.state });
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* True when a fenced write names a lease owner the row no longer has. Such a write is a no-op that
|
|
175
|
+
* returns the row unchanged — see `AsyncOperationUpdateOptions.leaseOwner`. Exported for the same
|
|
176
|
+
* reason as `TERMINAL_STATUSES`.
|
|
177
|
+
*/
|
|
178
|
+
export function isFencedOut({ existing, options }) {
|
|
179
|
+
return options?.leaseOwner !== undefined && existing.leaseOwner !== options.leaseOwner;
|
|
180
|
+
}
|
|
181
|
+
/** A key present in the patch replaces the field (`undefined` clears it to `null`); an absent key keeps it. */
|
|
182
|
+
function patchedNullable({ patch, existing, key }) {
|
|
183
|
+
return key in patch ? (patch[key] ?? null) : existing[key];
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The update rule every store applies after its lease fence: reject credential material in a
|
|
187
|
+
* patched `state`, then an illegal status transition, then merge. Returns the next record without
|
|
188
|
+
* copying `state` — the caller decides how to store it. Exported for the same reason as
|
|
189
|
+
* `TERMINAL_STATUSES`.
|
|
190
|
+
* @throws `Error` for credential material; `RangeError` for an illegal transition.
|
|
191
|
+
*/
|
|
192
|
+
export function mergeAsyncOperationPatch({ existing, patch }, { now }) {
|
|
193
|
+
if ('state' in patch)
|
|
194
|
+
assertNoCredentialMaterial({ state: patch.state });
|
|
195
|
+
const status = patch.status ?? existing.status;
|
|
196
|
+
assertTransition(existing.status, status);
|
|
197
|
+
return {
|
|
198
|
+
...existing,
|
|
199
|
+
status,
|
|
200
|
+
attempts: patch.attempts ?? existing.attempts,
|
|
201
|
+
nextPollAt: patch.nextPollAt ?? existing.nextPollAt,
|
|
202
|
+
state: patchedNullable({ patch, existing, key: 'state' }),
|
|
203
|
+
result: patchedNullable({ patch, existing, key: 'result' }),
|
|
204
|
+
error: patchedNullable({ patch, existing, key: 'error' }),
|
|
205
|
+
leaseOwner: patchedNullable({ patch, existing, key: 'leaseOwner' }),
|
|
206
|
+
leaseExpiresAt: patchedNullable({ patch, existing, key: 'leaseExpiresAt' }),
|
|
207
|
+
updatedAt: now,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
150
210
|
/**
|
|
151
211
|
* Creates the in-memory reference `AsyncOperationStore`. No persistence — a durable adapter
|
|
152
212
|
* implements the same interface; every method here is written so the equivalent SQL is a direct
|
|
@@ -154,20 +214,13 @@ export function assertTransition(from, to) {
|
|
|
154
214
|
*/
|
|
155
215
|
export function createInMemoryAsyncOperationStore() {
|
|
156
216
|
const rows = new Map();
|
|
157
|
-
const requireRow = (id) => rows.get(id);
|
|
158
217
|
return {
|
|
159
218
|
async create(required, optional = {}) {
|
|
160
219
|
const input = { ...required, ...optional };
|
|
161
220
|
if (rows.has(input.id)) {
|
|
162
221
|
throw new Error(`async operation "${input.id}" already exists`);
|
|
163
222
|
}
|
|
164
|
-
|
|
165
|
-
throw new RangeError(`Invalid maxAttempts: ${input.maxAttempts} must be a finite number >= 1`);
|
|
166
|
-
}
|
|
167
|
-
if (!Number.isFinite(input.deadlineAt)) {
|
|
168
|
-
throw new RangeError(`Invalid deadlineAt: ${input.deadlineAt} must be a finite epoch-ms timestamp`);
|
|
169
|
-
}
|
|
170
|
-
assertNoCredentialMaterial({ state: input.state });
|
|
223
|
+
assertValidCreateInput({ input });
|
|
171
224
|
const now = Date.now();
|
|
172
225
|
const row = {
|
|
173
226
|
schemaVersion: ASYNC_OPERATION_SCHEMA_VERSION,
|
|
@@ -182,7 +235,7 @@ export function createInMemoryAsyncOperationStore() {
|
|
|
182
235
|
nextPollAt: input.nextPollAt ?? now,
|
|
183
236
|
leaseOwner: null,
|
|
184
237
|
leaseExpiresAt: null,
|
|
185
|
-
state: input.state
|
|
238
|
+
state: cloneState(input.state ?? null),
|
|
186
239
|
result: null,
|
|
187
240
|
error: null,
|
|
188
241
|
createdAt: now,
|
|
@@ -192,35 +245,20 @@ export function createInMemoryAsyncOperationStore() {
|
|
|
192
245
|
return cloneRecord(row);
|
|
193
246
|
},
|
|
194
247
|
async get({ id }) {
|
|
195
|
-
const row =
|
|
248
|
+
const row = rows.get(id);
|
|
196
249
|
return row ? cloneRecord(row) : null;
|
|
197
250
|
},
|
|
198
251
|
async update({ id, patch }, { options } = {}) {
|
|
199
|
-
const existing =
|
|
252
|
+
const existing = rows.get(id);
|
|
200
253
|
if (!existing)
|
|
201
254
|
return null;
|
|
202
255
|
// Fenced, like releaseLease: a caller writing against a lease it no longer holds gets a
|
|
203
256
|
// no-op, not an overwrite of whoever holds (or now holds none of) it.
|
|
204
|
-
if (
|
|
257
|
+
if (isFencedOut({ existing, options }))
|
|
205
258
|
return cloneRecord(existing);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const status = patch.status ?? existing.status;
|
|
210
|
-
assertTransition(existing.status, status);
|
|
211
|
-
const next = {
|
|
212
|
-
...existing,
|
|
213
|
-
schemaVersion: existing.schemaVersion,
|
|
214
|
-
status,
|
|
215
|
-
attempts: patch.attempts ?? existing.attempts,
|
|
216
|
-
nextPollAt: patch.nextPollAt ?? existing.nextPollAt,
|
|
217
|
-
state: 'state' in patch ? (patch.state == null ? null : structuredClone(patch.state)) : existing.state,
|
|
218
|
-
result: 'result' in patch ? (patch.result ?? null) : existing.result,
|
|
219
|
-
error: 'error' in patch ? (patch.error ?? null) : existing.error,
|
|
220
|
-
leaseOwner: 'leaseOwner' in patch ? (patch.leaseOwner ?? null) : existing.leaseOwner,
|
|
221
|
-
leaseExpiresAt: 'leaseExpiresAt' in patch ? (patch.leaseExpiresAt ?? null) : existing.leaseExpiresAt,
|
|
222
|
-
updatedAt: Date.now(),
|
|
223
|
-
};
|
|
259
|
+
const merged = mergeAsyncOperationPatch({ existing, patch }, { now: Date.now() });
|
|
260
|
+
// Store a private copy of `state` so the caller's patch object never aliases the row.
|
|
261
|
+
const next = { ...merged, state: cloneState(merged.state) };
|
|
224
262
|
rows.set(id, next);
|
|
225
263
|
return cloneRecord(next);
|
|
226
264
|
},
|
|
@@ -258,7 +296,7 @@ export function createInMemoryAsyncOperationStore() {
|
|
|
258
296
|
return claimed;
|
|
259
297
|
},
|
|
260
298
|
async releaseLease({ id, leaseOwner }) {
|
|
261
|
-
const row =
|
|
299
|
+
const row = rows.get(id);
|
|
262
300
|
if (!row)
|
|
263
301
|
return;
|
|
264
302
|
// Fenced: a stale owner's late release must not clear a lease another worker has since
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Built-in registration has one owner and runs on first registry use, never on import. */
|
|
2
|
-
import type { VendorAdapterRegistry } from './vendor-registry.js';
|
|
2
|
+
import type { VendorAdapterRegistry } from './vendor-registry-core.js';
|
|
3
3
|
export declare function registerBuiltinVendorAdapters({ registry }: {
|
|
4
4
|
registry: Pick<VendorAdapterRegistry, 'register'>;
|
|
5
5
|
}, _optional?: Record<string, never>): void;
|
|
@@ -6,6 +6,14 @@ function defaultAspectFor(surface) {
|
|
|
6
6
|
return '16:9';
|
|
7
7
|
return undefined;
|
|
8
8
|
}
|
|
9
|
+
/** Never forward a non-finite number (NaN/Infinity) to a provider. */
|
|
10
|
+
function finiteOrUndefined(value) {
|
|
11
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
12
|
+
}
|
|
13
|
+
/** An explicit `imageRefs` wins; otherwise derive a one-element list from `imageRef`. */
|
|
14
|
+
function resolveImageRefs(request) {
|
|
15
|
+
return request.imageRefs ?? (request.imageRef ? [request.imageRef] : []);
|
|
16
|
+
}
|
|
9
17
|
/**
|
|
10
18
|
* @param request The caller's original request.
|
|
11
19
|
* @param resolvedAudioKind Already resolved by the caller (defaults to `'music'` for an audio surface with no explicit `audioKind`).
|
|
@@ -25,9 +33,9 @@ export function buildRenderContext({ request, resolvedAudioKind, length, duratio
|
|
|
25
33
|
audioKind: resolvedAudioKind,
|
|
26
34
|
language: request.language || '',
|
|
27
35
|
loop: request.loop === true,
|
|
28
|
-
promptInfluence:
|
|
36
|
+
promptInfluence: finiteOrUndefined(request.promptInfluence),
|
|
29
37
|
imageRef: request.imageRef ?? null,
|
|
30
|
-
imageRefs:
|
|
38
|
+
imageRefs: resolveImageRefs(request),
|
|
31
39
|
requestInit: request.requestInit || {},
|
|
32
40
|
speechFormat: resolveSpeechFormat(request.speechFormat),
|
|
33
41
|
onProgress: request.onProgress,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MediaDispatchEngine, MediaDispatchEngineOptions, ProviderCredentials, RenderContext, RenderResult } from './types.js';
|
|
1
|
+
import type { MediaDispatchEngine, MediaDispatchEngineRequired, MediaDispatchEngineOptions, ProviderCredentials, RenderContext, RenderResult } from './types.js';
|
|
2
2
|
export type Renderer = (required: {
|
|
3
3
|
ctx: RenderContext;
|
|
4
4
|
credentials: ProviderCredentials;
|
|
@@ -10,7 +10,7 @@ export type Renderer = (required: {
|
|
|
10
10
|
* constant) specifically so its `providerId`-found/not-found and
|
|
11
11
|
* `routeKey`-found/not-found branches stay directly testable even while
|
|
12
12
|
* the production `ROUTES` table itself is empty (every vendor wired into
|
|
13
|
-
* this engine has migrated onto
|
|
13
|
+
* this engine has migrated onto vendor adapters — see `ROUTES`'s own
|
|
14
14
|
* doc comment above): exercising every branch through `resolveRenderer`
|
|
15
15
|
* end-to-end would otherwise need a real, currently-nonexistent
|
|
16
16
|
* ROUTES-only vendor to hit the "found" side. Same "extract to a
|
|
@@ -18,5 +18,8 @@ export type Renderer = (required: {
|
|
|
18
18
|
* `buildRenderContext` already established for the same reason.
|
|
19
19
|
*/
|
|
20
20
|
export declare function lookupRoute(routes: Readonly<Record<string, Readonly<Record<string, Renderer>>>>, providerId: string, routeKey: string): Renderer | undefined;
|
|
21
|
-
|
|
21
|
+
/** Creates an engine over the host's registry; registration remains live between requests.
|
|
22
|
+
* @returns A generation service; validation, missing routes and provider failures reject generate.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createMediaDispatchEngine({ registry, httpClient }: MediaDispatchEngineRequired, options?: MediaDispatchEngineOptions): MediaDispatchEngine;
|
|
22
25
|
//# sourceMappingURL=engine.d.ts.map
|