@jini-ai/integrations 0.3.5 → 0.4.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/CHANGELOG.md +84 -0
- package/README.md +72 -24
- package/dist/args.d.ts +8 -0
- package/dist/args.js +10 -0
- package/dist/argument-error.d.ts +9 -0
- package/dist/argument-error.js +7 -0
- package/dist/credentialed-http/auth-schemes.d.ts +29 -0
- package/dist/credentialed-http/auth-schemes.js +60 -0
- package/dist/credentialed-http/credentialed-request.d.ts +132 -0
- package/dist/credentialed-http/credentialed-request.js +365 -0
- package/dist/credentialed-http/index.d.ts +4 -0
- package/dist/credentialed-http/index.js +4 -0
- package/dist/credentialed-http/ports.d.ts +42 -0
- package/dist/credentialed-http/ports.js +2 -0
- package/dist/media-providers/capability-registry.d.ts +12 -4
- package/dist/media-providers/capability-registry.js +6 -6
- package/dist/media-providers/dispatch/async-operation-store.d.ts +33 -8
- package/dist/media-providers/dispatch/async-operation-store.js +20 -32
- package/dist/media-providers/dispatch/context.d.ts +7 -2
- package/dist/media-providers/dispatch/context.js +1 -1
- package/dist/media-providers/dispatch/credentials.d.ts +4 -1
- package/dist/media-providers/dispatch/credentials.js +1 -1
- package/dist/media-providers/dispatch/engine.d.ts +5 -2
- package/dist/media-providers/dispatch/engine.js +23 -15
- package/dist/media-providers/dispatch/index.d.ts +4 -1
- package/dist/media-providers/dispatch/index.js +4 -2
- package/dist/media-providers/dispatch/openai-compatible.d.ts +12 -2
- package/dist/media-providers/dispatch/openai-compatible.js +9 -5
- package/dist/media-providers/dispatch/operation-runtime.d.ts +16 -8
- package/dist/media-providers/dispatch/operation-runtime.js +93 -76
- package/dist/media-providers/dispatch/outbound.d.ts +31 -0
- package/dist/media-providers/dispatch/outbound.js +54 -0
- package/dist/media-providers/dispatch/polling-adapter.d.ts +26 -8
- package/dist/media-providers/dispatch/polling-adapter.js +2 -2
- package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts +2 -2
- package/dist/media-providers/dispatch/providers/aihubmix-shared.js +2 -2
- package/dist/media-providers/dispatch/providers/aihubmix.d.ts +8 -2
- package/dist/media-providers/dispatch/providers/aihubmix.js +15 -15
- package/dist/media-providers/dispatch/providers/custom-image.d.ts +11 -2
- package/dist/media-providers/dispatch/providers/custom-image.js +9 -8
- package/dist/media-providers/dispatch/providers/elevenlabs.d.ts +8 -2
- package/dist/media-providers/dispatch/providers/elevenlabs.js +13 -13
- package/dist/media-providers/dispatch/providers/fishaudio.d.ts +4 -1
- package/dist/media-providers/dispatch/providers/fishaudio.js +7 -7
- package/dist/media-providers/dispatch/providers/grok.d.ts +11 -3
- package/dist/media-providers/dispatch/providers/grok.js +16 -16
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.js +23 -22
- package/dist/media-providers/dispatch/providers/imagerouter.d.ts +12 -3
- package/dist/media-providers/dispatch/providers/imagerouter.js +18 -18
- package/dist/media-providers/dispatch/providers/minimax.d.ts +4 -1
- package/dist/media-providers/dispatch/providers/minimax.js +6 -6
- package/dist/media-providers/dispatch/providers/nanobanana.d.ts +4 -1
- package/dist/media-providers/dispatch/providers/nanobanana.js +7 -7
- package/dist/media-providers/dispatch/providers/openai.d.ts +8 -2
- package/dist/media-providers/dispatch/providers/openai.js +20 -27
- package/dist/media-providers/dispatch/providers/openrouter.d.ts +7 -2
- package/dist/media-providers/dispatch/providers/openrouter.js +11 -11
- package/dist/media-providers/dispatch/providers/senseaudio.d.ts +8 -2
- package/dist/media-providers/dispatch/providers/senseaudio.js +13 -13
- package/dist/media-providers/dispatch/providers/volcengine.d.ts +4 -1
- package/dist/media-providers/dispatch/providers/volcengine.js +8 -8
- package/dist/media-providers/dispatch/response-parsers.d.ts +21 -7
- package/dist/media-providers/dispatch/response-parsers.js +15 -11
- package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts +3 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.js +53 -39
- package/dist/media-providers/dispatch/ssrf-guard.d.ts +27 -14
- package/dist/media-providers/dispatch/ssrf-guard.js +46 -105
- package/dist/media-providers/dispatch/stub.d.ts +7 -2
- package/dist/media-providers/dispatch/stub.js +4 -3
- package/dist/media-providers/dispatch/types.d.ts +17 -13
- package/dist/media-providers/dispatch/vendor-adapter.d.ts +22 -5
- package/dist/media-providers/dispatch/vendor-adapter.js +13 -10
- package/dist/media-providers/dispatch/vendor-registry.d.ts +14 -4
- package/dist/media-providers/dispatch/vendor-registry.js +3 -3
- package/dist/media-providers/index.d.ts +1 -1
- package/dist/media-providers/index.js +1 -1
- package/dist/media-providers/policy.d.ts +3 -2
- package/dist/media-providers/policy.js +4 -2
- package/dist/media-providers/providers.d.ts +12 -4
- package/dist/media-providers/providers.js +3 -3
- package/dist/media-providers/staging.d.ts +8 -2
- package/dist/media-providers/staging.js +13 -4
- package/dist/media-providers/task-store.d.ts +2 -2
- package/dist/media-providers/task-store.js +2 -2
- package/dist/media-providers/tokens.js +3 -3
- package/dist/media-providers/types.d.ts +4 -4
- package/dist/media-providers/types.js +1 -1
- package/dist/media-providers/video-request.d.ts +32 -9
- package/dist/media-providers/video-request.js +15 -15
- package/dist/webhooks/delivery.d.ts +76 -0
- package/dist/webhooks/delivery.js +222 -0
- package/dist/webhooks/index.d.ts +7 -0
- package/dist/webhooks/index.js +7 -0
- package/dist/webhooks/ports.d.ts +113 -0
- package/dist/webhooks/ports.js +2 -0
- package/dist/webhooks/signing.d.ts +38 -0
- package/dist/webhooks/signing.js +83 -0
- package/dist/webhooks/signing.keyring.d.ts +8 -0
- package/dist/webhooks/signing.keyring.js +18 -0
- package/dist/webhooks/subscriptions.d.ts +78 -0
- package/dist/webhooks/subscriptions.js +139 -0
- package/dist/webhooks/types.d.ts +103 -0
- package/dist/webhooks/types.js +2 -0
- package/package.json +29 -18
- package/dist/composio/bounded-data.d.ts.map +0 -1
- package/dist/composio/bounded-data.js.map +0 -1
- package/dist/composio/catalog.d.ts.map +0 -1
- package/dist/composio/catalog.js.map +0 -1
- package/dist/composio/composio-config.d.ts.map +0 -1
- package/dist/composio/composio-config.js.map +0 -1
- package/dist/composio/composio-descriptions.d.ts.map +0 -1
- package/dist/composio/composio-descriptions.js.map +0 -1
- package/dist/composio/composio.d.ts.map +0 -1
- package/dist/composio/composio.js.map +0 -1
- package/dist/composio/errors.d.ts.map +0 -1
- package/dist/composio/errors.js.map +0 -1
- package/dist/composio/file-lock.d.ts.map +0 -1
- package/dist/composio/file-lock.js.map +0 -1
- package/dist/composio/index.d.ts.map +0 -1
- package/dist/composio/index.js.map +0 -1
- package/dist/composio/json-schema.d.ts.map +0 -1
- package/dist/composio/json-schema.js.map +0 -1
- package/dist/composio/output-protection.d.ts.map +0 -1
- package/dist/composio/output-protection.js.map +0 -1
- package/dist/composio/service.d.ts.map +0 -1
- package/dist/composio/service.js.map +0 -1
- package/dist/media-providers/capability-registry.d.ts.map +0 -1
- package/dist/media-providers/capability-registry.js.map +0 -1
- package/dist/media-providers/catalog.d.ts.map +0 -1
- package/dist/media-providers/catalog.js.map +0 -1
- package/dist/media-providers/dispatch/async-operation-store.d.ts.map +0 -1
- package/dist/media-providers/dispatch/async-operation-store.js.map +0 -1
- package/dist/media-providers/dispatch/context.d.ts.map +0 -1
- package/dist/media-providers/dispatch/context.js.map +0 -1
- package/dist/media-providers/dispatch/credentials.d.ts.map +0 -1
- package/dist/media-providers/dispatch/credentials.js.map +0 -1
- package/dist/media-providers/dispatch/engine.d.ts.map +0 -1
- package/dist/media-providers/dispatch/engine.js.map +0 -1
- package/dist/media-providers/dispatch/index.d.ts.map +0 -1
- package/dist/media-providers/dispatch/index.js.map +0 -1
- package/dist/media-providers/dispatch/openai-compatible.d.ts.map +0 -1
- package/dist/media-providers/dispatch/openai-compatible.js.map +0 -1
- package/dist/media-providers/dispatch/operation-runtime.d.ts.map +0 -1
- package/dist/media-providers/dispatch/operation-runtime.js.map +0 -1
- package/dist/media-providers/dispatch/polling-adapter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/polling-adapter.js.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix-shared.js.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix.js.map +0 -1
- package/dist/media-providers/dispatch/providers/custom-image.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/custom-image.js.map +0 -1
- package/dist/media-providers/dispatch/providers/elevenlabs.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/elevenlabs.js.map +0 -1
- package/dist/media-providers/dispatch/providers/fishaudio.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/fishaudio.js.map +0 -1
- package/dist/media-providers/dispatch/providers/grok.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/grok.js.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.js.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter.js.map +0 -1
- package/dist/media-providers/dispatch/providers/minimax.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/minimax.js.map +0 -1
- package/dist/media-providers/dispatch/providers/nanobanana.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/nanobanana.js.map +0 -1
- package/dist/media-providers/dispatch/providers/openai.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/openai.js.map +0 -1
- package/dist/media-providers/dispatch/providers/openrouter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/openrouter.js.map +0 -1
- package/dist/media-providers/dispatch/providers/senseaudio.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/senseaudio.js.map +0 -1
- package/dist/media-providers/dispatch/providers/volcengine.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/volcengine.js.map +0 -1
- package/dist/media-providers/dispatch/response-parsers.d.ts.map +0 -1
- package/dist/media-providers/dispatch/response-parsers.js.map +0 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts.map +0 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.js.map +0 -1
- package/dist/media-providers/dispatch/ssrf-guard.d.ts.map +0 -1
- package/dist/media-providers/dispatch/ssrf-guard.js.map +0 -1
- package/dist/media-providers/dispatch/stub.d.ts.map +0 -1
- package/dist/media-providers/dispatch/stub.js.map +0 -1
- package/dist/media-providers/dispatch/types.d.ts.map +0 -1
- package/dist/media-providers/dispatch/types.js.map +0 -1
- package/dist/media-providers/dispatch/vendor-adapter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/vendor-adapter.js.map +0 -1
- package/dist/media-providers/dispatch/vendor-registry.d.ts.map +0 -1
- package/dist/media-providers/dispatch/vendor-registry.js.map +0 -1
- package/dist/media-providers/index.d.ts.map +0 -1
- package/dist/media-providers/index.js.map +0 -1
- package/dist/media-providers/policy.d.ts.map +0 -1
- package/dist/media-providers/policy.js.map +0 -1
- package/dist/media-providers/providers.d.ts.map +0 -1
- package/dist/media-providers/providers.js.map +0 -1
- package/dist/media-providers/seed.d.ts.map +0 -1
- package/dist/media-providers/seed.js.map +0 -1
- package/dist/media-providers/sqlite-task-store.d.ts.map +0 -1
- package/dist/media-providers/sqlite-task-store.js.map +0 -1
- package/dist/media-providers/staging.d.ts.map +0 -1
- package/dist/media-providers/staging.js.map +0 -1
- package/dist/media-providers/task-store.d.ts.map +0 -1
- package/dist/media-providers/task-store.js.map +0 -1
- package/dist/media-providers/tokens.d.ts.map +0 -1
- package/dist/media-providers/tokens.js.map +0 -1
- package/dist/media-providers/types.d.ts.map +0 -1
- package/dist/media-providers/types.js.map +0 -1
- package/dist/media-providers/video-request.d.ts.map +0 -1
- package/dist/media-providers/video-request.js.map +0 -1
|
@@ -10,7 +10,10 @@ export interface VendorRequest<Meta = undefined> {
|
|
|
10
10
|
readonly init: RequestInit;
|
|
11
11
|
readonly meta: Meta;
|
|
12
12
|
}
|
|
13
|
-
export type VendorRequestBuilder<Meta = undefined> = (
|
|
13
|
+
export type VendorRequestBuilder<Meta = undefined> = (required: {
|
|
14
|
+
ctx: RenderContext;
|
|
15
|
+
credentials: ProviderCredentials;
|
|
16
|
+
}) => VendorRequest<Meta>;
|
|
14
17
|
/**
|
|
15
18
|
* Turns a `fetch` `Response` into a `RenderResult`, or throws a
|
|
16
19
|
* vendor-tagged `Error` — the "response-parsing + error-mapping" half of a
|
|
@@ -18,9 +21,15 @@ export type VendorRequestBuilder<Meta = undefined> = (ctx: RenderContext, creden
|
|
|
18
21
|
* second request (an SSRF-guarded asset download, a Gemini-native
|
|
19
22
|
* redirect) to finish parsing — see this module's doc comment.
|
|
20
23
|
*/
|
|
21
|
-
export type VendorResponseParser<Meta = undefined> = (
|
|
24
|
+
export type VendorResponseParser<Meta = undefined> = (required: {
|
|
25
|
+
resp: Response;
|
|
26
|
+
ctx: RenderContext;
|
|
27
|
+
request: VendorRequest<Meta>;
|
|
28
|
+
}) => Promise<RenderResult>;
|
|
22
29
|
/** Validates `credentials` before any network call, throwing a vendor-tagged `Error` when they're unusable (e.g. no API key configured). */
|
|
23
|
-
export type VendorCredentialGuard = (
|
|
30
|
+
export type VendorCredentialGuard = (required: {
|
|
31
|
+
credentials: ProviderCredentials;
|
|
32
|
+
}) => void;
|
|
24
33
|
/**
|
|
25
34
|
* A fully-configured vendor: the "auth-scheme" (`requireCredential`),
|
|
26
35
|
* "request-shape" (`buildRequest`), and "response-parsing + error-mapping"
|
|
@@ -41,8 +50,14 @@ export interface VendorAdapter<Meta = undefined> {
|
|
|
41
50
|
* unlike `fetch` itself, an HTTP error status is not a rejected `Promise`,
|
|
42
51
|
* so mapping a bad status into a thrown `Error` is each adapter's own job,
|
|
43
52
|
* exactly like every hand-written `render*` function already did.
|
|
53
|
+
* The guarded outbound client vets and pins the peer and refuses all redirects.
|
|
54
|
+
* @complexity O(b) plus one network round trip, for b bounded request/response bytes.
|
|
44
55
|
*/
|
|
45
|
-
export declare function dispatchVendorRequest<Meta = undefined>(adapter
|
|
56
|
+
export declare function dispatchVendorRequest<Meta = undefined>({ adapter, ctx, credentials }: {
|
|
57
|
+
adapter: VendorAdapter<Meta>;
|
|
58
|
+
ctx: RenderContext;
|
|
59
|
+
credentials: ProviderCredentials;
|
|
60
|
+
}): Promise<RenderResult>;
|
|
46
61
|
/**
|
|
47
62
|
* Reference `requireCredential` guard: throws `message` when
|
|
48
63
|
* `credentials.apiKey` is unset. Covers every ported vendor's own
|
|
@@ -50,5 +65,7 @@ export declare function dispatchVendorRequest<Meta = undefined>(adapter: VendorA
|
|
|
50
65
|
* `if (!credentials.apiKey) throw new Error(...)` line with only the
|
|
51
66
|
* message text differing.
|
|
52
67
|
*/
|
|
53
|
-
export declare function requireApiKey(message
|
|
68
|
+
export declare function requireApiKey({ message }: {
|
|
69
|
+
message: string;
|
|
70
|
+
}): VendorCredentialGuard;
|
|
54
71
|
//# sourceMappingURL=vendor-adapter.d.ts.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The generic vendor-adapter dispatch core — the mechanism every registered
|
|
3
3
|
* media vendor's HTTP round trip runs through: validate credentials, build a
|
|
4
4
|
* request, perform exactly one `fetch`, then hand the response to a
|
|
5
|
-
* vendor-supplied parser. This is the piece `
|
|
5
|
+
* vendor-supplied parser. This is the piece `archived provenance ledger`'s 2026-07-21
|
|
6
6
|
* dispatch-engine entry flagged as missing ("the actual multi-provider REST
|
|
7
7
|
* dispatch engine and durable task adapter" — each vendor was "essentially
|
|
8
8
|
* its own hand-written function, not a generalized system that can register
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
* `response-parsers.ts`'s `createHexEnvelopeAudioParser` for the shared,
|
|
27
27
|
* reusable piece.
|
|
28
28
|
*/
|
|
29
|
-
import { FETCH_TIMEOUT_MS
|
|
29
|
+
import { FETCH_TIMEOUT_MS } from '@jini-ai/platform/fetch-with-timeout';
|
|
30
|
+
import { fetchMediaOutbound } from './outbound.js';
|
|
30
31
|
/**
|
|
31
32
|
* The generic dispatch core: `requireCredential` -> `buildRequest` -> one
|
|
32
33
|
* `fetch` -> `parseResponse`. Every migrated vendor's `render*` export is
|
|
@@ -36,20 +37,22 @@ import { FETCH_TIMEOUT_MS, fetchWithTimeout } from '@jini-ai/platform';
|
|
|
36
37
|
* unlike `fetch` itself, an HTTP error status is not a rejected `Promise`,
|
|
37
38
|
* so mapping a bad status into a thrown `Error` is each adapter's own job,
|
|
38
39
|
* exactly like every hand-written `render*` function already did.
|
|
40
|
+
* The guarded outbound client vets and pins the peer and refuses all redirects.
|
|
41
|
+
* @complexity O(b) plus one network round trip, for b bounded request/response bytes.
|
|
39
42
|
*/
|
|
40
|
-
export async function dispatchVendorRequest(adapter, ctx, credentials) {
|
|
41
|
-
adapter.requireCredential?.(credentials);
|
|
42
|
-
const request = adapter.buildRequest(ctx, credentials);
|
|
43
|
+
export async function dispatchVendorRequest({ adapter, ctx, credentials }) {
|
|
44
|
+
adapter.requireCredential?.({ credentials: credentials });
|
|
45
|
+
const request = adapter.buildRequest({ ctx: ctx, credentials: credentials });
|
|
43
46
|
// Backstop, not an override: as of 2026-08-16 only 2 of 13 registered vendors
|
|
44
47
|
// (providers/openai.ts, providers/openrouter.ts) set their own `request.init.signal`; the other
|
|
45
48
|
// 11 set none at all (Finding 2 of the 2026-08-16 failure-mode audit — a stalled vendor endpoint
|
|
46
|
-
// hung this call forever, nothing to alert on).
|
|
49
|
+
// hung this call forever, nothing to alert on). The guarded client combines any signal a vendor
|
|
47
50
|
// DOES already set with this one via `AbortSignal.any`, so a more specific per-vendor timeout
|
|
48
51
|
// still applies unchanged; `GENERATE` (10min) matches what those two vendors already picked
|
|
49
52
|
// deliberately for the same reason — media generation genuinely finishes on that order, not in
|
|
50
53
|
// seconds, so anything shorter would abort a legitimately still-generating request.
|
|
51
|
-
const resp = await
|
|
52
|
-
return adapter.parseResponse(resp, ctx, request);
|
|
54
|
+
const resp = await fetchMediaOutbound({ url: request.url, timeoutMs: FETCH_TIMEOUT_MS.GENERATE }, { ...ctx, init: request.init });
|
|
55
|
+
return adapter.parseResponse({ resp: resp, ctx: ctx, request: request });
|
|
53
56
|
}
|
|
54
57
|
/**
|
|
55
58
|
* Reference `requireCredential` guard: throws `message` when
|
|
@@ -58,8 +61,8 @@ export async function dispatchVendorRequest(adapter, ctx, credentials) {
|
|
|
58
61
|
* `if (!credentials.apiKey) throw new Error(...)` line with only the
|
|
59
62
|
* message text differing.
|
|
60
63
|
*/
|
|
61
|
-
export function requireApiKey(message) {
|
|
62
|
-
return (credentials) => {
|
|
64
|
+
export function requireApiKey({ message }) {
|
|
65
|
+
return ({ credentials }) => {
|
|
63
66
|
if (!credentials.apiKey) {
|
|
64
67
|
throw new Error(message);
|
|
65
68
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* (`'image'`, `'video'`, `'audio:speech'`, ...). `engine.ts` consults this
|
|
8
8
|
* registry first when resolving a renderer, falling back to the static
|
|
9
9
|
* `ROUTES` table for vendors not yet migrated onto the generic engine — see
|
|
10
|
-
* `
|
|
10
|
+
* `archived provenance ledger`'s 2026-07-21 dispatch-engine-generalization section for
|
|
11
11
|
* exactly which vendors are registered here today, and why the rest
|
|
12
12
|
* legitimately aren't (yet).
|
|
13
13
|
*/
|
|
@@ -15,11 +15,21 @@ import type { VendorAdapter } from './vendor-adapter.js';
|
|
|
15
15
|
export declare class VendorAdapterRegistry {
|
|
16
16
|
private readonly table;
|
|
17
17
|
/** Registers `adapter` for `(providerId, routeKey)`. Throws if that pair is already registered — a vendor module should register each of its (provider, surface) pairs exactly once, at module load. */
|
|
18
|
-
register<Meta>(providerId
|
|
18
|
+
register<Meta>({ providerId, routeKey, adapter }: {
|
|
19
|
+
providerId: string;
|
|
20
|
+
routeKey: string;
|
|
21
|
+
adapter: VendorAdapter<Meta>;
|
|
22
|
+
}): void;
|
|
19
23
|
/** Looks up the adapter registered for `(providerId, routeKey)`, or `undefined` if none is registered. */
|
|
20
|
-
get(providerId
|
|
24
|
+
get({ providerId, routeKey }: {
|
|
25
|
+
providerId: string;
|
|
26
|
+
routeKey: string;
|
|
27
|
+
}): VendorAdapter<never> | undefined;
|
|
21
28
|
/** Whether an adapter is registered for `(providerId, routeKey)`. */
|
|
22
|
-
has(providerId
|
|
29
|
+
has({ providerId, routeKey }: {
|
|
30
|
+
providerId: string;
|
|
31
|
+
routeKey: string;
|
|
32
|
+
}): boolean;
|
|
23
33
|
/** Every `(providerId, routeKey)` pair currently registered — used by tests (and any diagnostics a host wants) to enumerate exactly which vendors run through the generic engine. */
|
|
24
34
|
list(): ReadonlyArray<readonly [providerId: string, routeKey: string]>;
|
|
25
35
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export class VendorAdapterRegistry {
|
|
2
2
|
table = new Map();
|
|
3
3
|
/** Registers `adapter` for `(providerId, routeKey)`. Throws if that pair is already registered — a vendor module should register each of its (provider, surface) pairs exactly once, at module load. */
|
|
4
|
-
register(providerId, routeKey, adapter) {
|
|
4
|
+
register({ providerId, routeKey, adapter }) {
|
|
5
5
|
let bySurface = this.table.get(providerId);
|
|
6
6
|
if (!bySurface) {
|
|
7
7
|
bySurface = new Map();
|
|
@@ -13,11 +13,11 @@ export class VendorAdapterRegistry {
|
|
|
13
13
|
bySurface.set(routeKey, adapter);
|
|
14
14
|
}
|
|
15
15
|
/** Looks up the adapter registered for `(providerId, routeKey)`, or `undefined` if none is registered. */
|
|
16
|
-
get(providerId, routeKey) {
|
|
16
|
+
get({ providerId, routeKey }) {
|
|
17
17
|
return this.table.get(providerId)?.get(routeKey);
|
|
18
18
|
}
|
|
19
19
|
/** Whether an adapter is registered for `(providerId, routeKey)`. */
|
|
20
|
-
has(providerId, routeKey) {
|
|
20
|
+
has({ providerId, routeKey }) {
|
|
21
21
|
return this.table.get(providerId)?.has(routeKey) ?? false;
|
|
22
22
|
}
|
|
23
23
|
/** Every `(providerId, routeKey)` pair currently registered — used by tests (and any diagnostics a host wants) to enumerate exactly which vendors run through the generic engine. */
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* async task-tracking port, a host-injected policy port, a generic
|
|
6
6
|
* attachment-staging port, and (as of the dispatch engine) a real
|
|
7
7
|
* multi-vendor REST dispatch engine covering an initial vendor slice — see
|
|
8
|
-
* `
|
|
8
|
+
* `archived provenance ledger` for full provenance, exactly which vendors are ported vs
|
|
9
9
|
* deferred, and this package's not-yet-locked status.
|
|
10
10
|
*/
|
|
11
11
|
export * from './types.js';
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* async task-tracking port, a host-injected policy port, a generic
|
|
6
6
|
* attachment-staging port, and (as of the dispatch engine) a real
|
|
7
7
|
* multi-vendor REST dispatch engine covering an initial vendor slice — see
|
|
8
|
-
* `
|
|
8
|
+
* `archived provenance ledger` for full provenance, exactly which vendors are ported vs
|
|
9
9
|
* deferred, and this package's not-yet-locked status.
|
|
10
10
|
*/
|
|
11
11
|
export * from './types.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RequiredArgs, OptionalArgs } from '../args.js';
|
|
1
2
|
/**
|
|
2
3
|
* `MediaPolicy` — a host-injected gate on media generation. Generalized from
|
|
3
4
|
* OD's `apps/daemon/src/media/policy.ts`, which is a thin wrapper
|
|
@@ -37,7 +38,7 @@ export declare const DEFAULT_MEDIA_EXECUTION_POLICY: MediaExecutionPolicy;
|
|
|
37
38
|
* dispatching generation and honors a non-null denial.
|
|
38
39
|
*/
|
|
39
40
|
export interface MediaPolicy {
|
|
40
|
-
evaluate(
|
|
41
|
+
evaluate(required: RequiredArgs<MediaPolicyTarget>, optional?: OptionalArgs<MediaPolicyTarget>): MediaPolicyDenial | null;
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
44
|
* Reference `MediaPolicy`: an enabled/disabled + surface/model allowlist
|
|
@@ -45,5 +46,5 @@ export interface MediaPolicy {
|
|
|
45
46
|
* missing/empty `allowedSurfaces`/`allowedModels` means "no restriction on
|
|
46
47
|
* that dimension" (matches the origin's `Array.isArray(...) && length > 0` guard).
|
|
47
48
|
*/
|
|
48
|
-
export declare function createAllowlistMediaPolicy(
|
|
49
|
+
export declare function createAllowlistMediaPolicy(_required: Record<string, never>, optional?: Partial<MediaExecutionPolicy>): MediaPolicy;
|
|
49
50
|
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -10,9 +10,11 @@ export const DEFAULT_MEDIA_EXECUTION_POLICY = { mode: 'disabled' };
|
|
|
10
10
|
* missing/empty `allowedSurfaces`/`allowedModels` means "no restriction on
|
|
11
11
|
* that dimension" (matches the origin's `Array.isArray(...) && length > 0` guard).
|
|
12
12
|
*/
|
|
13
|
-
export function createAllowlistMediaPolicy(
|
|
13
|
+
export function createAllowlistMediaPolicy(_required, optional = {}) {
|
|
14
|
+
const policy = { ...DEFAULT_MEDIA_EXECUTION_POLICY, ...optional };
|
|
14
15
|
return {
|
|
15
|
-
evaluate(
|
|
16
|
+
evaluate(required, optional = {}) {
|
|
17
|
+
const target = { ...required, ...optional };
|
|
16
18
|
if (policy.mode === 'disabled') {
|
|
17
19
|
return { code: 'MEDIA_EXECUTION_DISABLED', message: 'media generation is disabled for this run' };
|
|
18
20
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* `apps/daemon/src/media/models.ts`; every provider id/label/hint here names
|
|
5
5
|
* a real third-party vendor (OpenAI, Fal.ai, ElevenLabs, ...), not an OD
|
|
6
6
|
* concept, so per the AGENTS.md boundary rule (no product-identity strings)
|
|
7
|
-
* it ports as data. See `
|
|
7
|
+
* it ports as data. See `archived provenance ledger` for exactly what was dropped.
|
|
8
8
|
*/
|
|
9
9
|
import type { AudioKind, MediaModel, MediaProvider, MediaSurface } from './types.js';
|
|
10
10
|
export declare const MEDIA_PROVIDERS: readonly MediaProvider[];
|
|
@@ -15,11 +15,19 @@ export declare const MEDIA_ASPECTS: readonly string[];
|
|
|
15
15
|
export declare const VIDEO_LENGTHS_SEC: readonly number[];
|
|
16
16
|
export declare const AUDIO_DURATIONS_SEC: readonly number[];
|
|
17
17
|
/** Finds a model by id across every surface (image, video, and all three audio kinds). */
|
|
18
|
-
export declare function findMediaModel(id
|
|
18
|
+
export declare function findMediaModel({ id }: {
|
|
19
|
+
id: string;
|
|
20
|
+
}): MediaModel | null;
|
|
19
21
|
/** Finds a provider by id in `MEDIA_PROVIDERS`. */
|
|
20
|
-
export declare function findProvider(id
|
|
22
|
+
export declare function findProvider({ id }: {
|
|
23
|
+
id: string;
|
|
24
|
+
}): MediaProvider | null;
|
|
21
25
|
/** Returns the model list for a surface; `audioKind` selects which audio sub-list (defaults to `'music'`). */
|
|
22
|
-
export declare function modelsForSurface(surface
|
|
26
|
+
export declare function modelsForSurface({ surface }: {
|
|
27
|
+
surface: MediaSurface;
|
|
28
|
+
}, { audioKind }?: {
|
|
29
|
+
audioKind?: AudioKind | undefined;
|
|
30
|
+
}): readonly MediaModel[];
|
|
23
31
|
/**
|
|
24
32
|
* Standard (non-product-scoped) credential env var names each provider's own
|
|
25
33
|
* SDK/docs recognize, in priority order. De-branded from OD's
|
|
@@ -140,7 +140,7 @@ export const MEDIA_ASPECTS = ['1:1', '16:9', '9:16', '4:3', '3:4'];
|
|
|
140
140
|
export const VIDEO_LENGTHS_SEC = [3, 5, 8, 10, 15, 30];
|
|
141
141
|
export const AUDIO_DURATIONS_SEC = [5, 10, 15, 30, 60, 120];
|
|
142
142
|
/** Finds a model by id across every surface (image, video, and all three audio kinds). */
|
|
143
|
-
export function findMediaModel(id) {
|
|
143
|
+
export function findMediaModel({ id }) {
|
|
144
144
|
const all = [
|
|
145
145
|
...IMAGE_MODELS,
|
|
146
146
|
...VIDEO_MODELS,
|
|
@@ -151,11 +151,11 @@ export function findMediaModel(id) {
|
|
|
151
151
|
return all.find((m) => m.id === id) ?? null;
|
|
152
152
|
}
|
|
153
153
|
/** Finds a provider by id in `MEDIA_PROVIDERS`. */
|
|
154
|
-
export function findProvider(id) {
|
|
154
|
+
export function findProvider({ id }) {
|
|
155
155
|
return MEDIA_PROVIDERS.find((p) => p.id === id) ?? null;
|
|
156
156
|
}
|
|
157
157
|
/** Returns the model list for a surface; `audioKind` selects which audio sub-list (defaults to `'music'`). */
|
|
158
|
-
export function modelsForSurface(surface, audioKind) {
|
|
158
|
+
export function modelsForSurface({ surface }, { audioKind } = {}) {
|
|
159
159
|
if (surface === 'image')
|
|
160
160
|
return IMAGE_MODELS;
|
|
161
161
|
if (surface === 'video')
|
|
@@ -22,8 +22,14 @@ export interface AttachmentStagingOptions {
|
|
|
22
22
|
* prunes staged files older than `maxAgeMs` on each call.
|
|
23
23
|
*/
|
|
24
24
|
export interface AttachmentStaging {
|
|
25
|
-
stage(
|
|
25
|
+
stage(required: {
|
|
26
|
+
imagePaths: readonly string[];
|
|
27
|
+
}, optional?: {
|
|
28
|
+
uploadRoot?: string | null | undefined;
|
|
29
|
+
}): Promise<string[]>;
|
|
26
30
|
}
|
|
27
31
|
/** Creates a filesystem-backed `AttachmentStaging` rooted at `cwd`. */
|
|
28
|
-
export declare function createFsAttachmentStaging(cwd
|
|
32
|
+
export declare function createFsAttachmentStaging({ cwd }: {
|
|
33
|
+
cwd: string;
|
|
34
|
+
}, options?: AttachmentStagingOptions): AttachmentStaging;
|
|
29
35
|
//# sourceMappingURL=staging.d.ts.map
|
|
@@ -16,6 +16,10 @@ const DEFAULT_STAGING_DIRNAME = '.media-attachments';
|
|
|
16
16
|
const DEFAULT_MAX_AGE_MS = 24 * 60 * 60 * 1000;
|
|
17
17
|
const DEFAULT_MAX_ITEMS = 50;
|
|
18
18
|
const DEFAULT_MAX_BYTES_PER_FILE = 100 * 1024 * 1024;
|
|
19
|
+
// Authorization failures must escape the advisory-file catch below; otherwise
|
|
20
|
+
// a missing containment boundary looks like an ordinary missing attachment.
|
|
21
|
+
class MissingUploadRootError extends Error {
|
|
22
|
+
}
|
|
19
23
|
function isWithinRoot(root, candidate) {
|
|
20
24
|
const relativePath = path.relative(root, candidate);
|
|
21
25
|
return relativePath === '' || (relativePath.length > 0 && !relativePath.startsWith('..') && !path.isAbsolute(relativePath));
|
|
@@ -55,7 +59,7 @@ async function pruneStagedAttachments(stagingDir, maxAgeMs) {
|
|
|
55
59
|
}));
|
|
56
60
|
}
|
|
57
61
|
/** Creates a filesystem-backed `AttachmentStaging` rooted at `cwd`. */
|
|
58
|
-
export function createFsAttachmentStaging(cwd, options = {}) {
|
|
62
|
+
export function createFsAttachmentStaging({ cwd }, options = {}) {
|
|
59
63
|
const stagingDirName = options.stagingDirName ?? DEFAULT_STAGING_DIRNAME;
|
|
60
64
|
assertSafeStagingDirName(stagingDirName);
|
|
61
65
|
const maxAgeMs = options.maxAgeMs ?? DEFAULT_MAX_AGE_MS;
|
|
@@ -64,7 +68,7 @@ export function createFsAttachmentStaging(cwd, options = {}) {
|
|
|
64
68
|
const root = path.resolve(cwd);
|
|
65
69
|
const stagingDir = path.join(root, stagingDirName);
|
|
66
70
|
return {
|
|
67
|
-
async stage(imagePaths, uploadRoot) {
|
|
71
|
+
async stage({ imagePaths }, { uploadRoot } = {}) {
|
|
68
72
|
if (!Array.isArray(imagePaths) || imagePaths.length === 0)
|
|
69
73
|
return [];
|
|
70
74
|
if (imagePaths.length > maxItems) {
|
|
@@ -121,7 +125,10 @@ export function createFsAttachmentStaging(cwd, options = {}) {
|
|
|
121
125
|
}
|
|
122
126
|
// Outside cwd: this is the "copy an external file into staging"
|
|
123
127
|
// path, which requires an authorized uploadRoot — deny by default.
|
|
124
|
-
if (uploadRootReal == null
|
|
128
|
+
if (uploadRootReal == null) {
|
|
129
|
+
throw new MissingUploadRootError('attachment staging: files outside cwd require an uploadRoot');
|
|
130
|
+
}
|
|
131
|
+
if (!isWithinRoot(uploadRootReal, real))
|
|
125
132
|
continue;
|
|
126
133
|
if (stat.size > maxBytesPerFile)
|
|
127
134
|
continue;
|
|
@@ -130,7 +137,9 @@ export function createFsAttachmentStaging(cwd, options = {}) {
|
|
|
130
137
|
await fs.promises.copyFile(real, destination);
|
|
131
138
|
staged.push(destination);
|
|
132
139
|
}
|
|
133
|
-
catch {
|
|
140
|
+
catch (error) {
|
|
141
|
+
if (error instanceof MissingUploadRootError)
|
|
142
|
+
throw error;
|
|
134
143
|
// Ignore malformed or missing files; attachments are advisory input.
|
|
135
144
|
}
|
|
136
145
|
}
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* (queued → running → done|failed|interrupted, boot-time reconciliation of
|
|
12
12
|
* orphaned in-flight tasks, TTL-based terminal-task pruning) without a SQL
|
|
13
13
|
* schema or an OD project reference. A durable adapter (a future
|
|
14
|
-
* `@jini-ai/sqlite` addition) implements the same interface — see
|
|
15
|
-
* `
|
|
14
|
+
* `@jini-ai/sqlite-chat` addition) implements the same interface — see
|
|
15
|
+
* `archived provenance ledger`.
|
|
16
16
|
*/
|
|
17
17
|
export type MediaTaskStatus = 'queued' | 'running' | 'done' | 'failed' | 'interrupted';
|
|
18
18
|
export interface MediaTaskError {
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* (queued → running → done|failed|interrupted, boot-time reconciliation of
|
|
12
12
|
* orphaned in-flight tasks, TTL-based terminal-task pruning) without a SQL
|
|
13
13
|
* schema or an OD project reference. A durable adapter (a future
|
|
14
|
-
* `@jini-ai/sqlite` addition) implements the same interface — see
|
|
15
|
-
* `
|
|
14
|
+
* `@jini-ai/sqlite-chat` addition) implements the same interface — see
|
|
15
|
+
* `archived provenance ledger`.
|
|
16
16
|
*/
|
|
17
17
|
const VALID_STATUSES = new Set([
|
|
18
18
|
'queued',
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* in this codebase's actual precedent).
|
|
8
8
|
*/
|
|
9
9
|
import { token } from '@jini-ai/core';
|
|
10
|
-
export const CapabilityRegistryToken = token('jini.media.capabilityRegistry');
|
|
11
|
-
export const MediaTaskStoreToken = token('jini.media.taskStore');
|
|
12
|
-
export const MediaPolicyToken = token('jini.media.policy');
|
|
10
|
+
export const CapabilityRegistryToken = token({ id: 'jini.media.capabilityRegistry' });
|
|
11
|
+
export const MediaTaskStoreToken = token({ id: 'jini.media.taskStore' });
|
|
12
|
+
export const MediaPolicyToken = token({ id: 'jini.media.policy' });
|
|
13
13
|
//# sourceMappingURL=tokens.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Ported from OD's `apps/daemon/src/media/models.ts` (catalogue
|
|
6
6
|
* shape) and `apps/daemon/src/media-adapters/types.ts` (capability +
|
|
7
|
-
* request-builder shape) — see `
|
|
7
|
+
* request-builder shape) — see `archived provenance ledger` for the full provenance.
|
|
8
8
|
* Neither origin file carries any OD domain noun; this is a product-neutral
|
|
9
9
|
* multi-vendor media-generation type system, not an OD concept.
|
|
10
10
|
*/
|
|
@@ -44,14 +44,14 @@ export interface MediaModel {
|
|
|
44
44
|
readonly label: string;
|
|
45
45
|
readonly hint: string;
|
|
46
46
|
readonly provider: string;
|
|
47
|
-
/** Capability tags, e.g. `t2i`/`i2i`/`inpaint`/`t2v`/`i2v`/`tts`. Open-ended by design — see `
|
|
47
|
+
/** Capability tags, e.g. `t2i`/`i2i`/`inpaint`/`t2v`/`i2v`/`tts`. Open-ended by design — see `archived provenance ledger`. */
|
|
48
48
|
readonly caps: readonly string[];
|
|
49
49
|
readonly default?: boolean;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Request-shape family, keyed off the resolved upstream model name. Each
|
|
53
53
|
* family is a distinct wire shape a real vendor gateway expects — see
|
|
54
|
-
* `video-request.ts` for the branching logic and `
|
|
54
|
+
* `video-request.ts` for the branching logic and `archived provenance ledger` for the
|
|
55
55
|
* vendor-verification notes this was ported with.
|
|
56
56
|
*/
|
|
57
57
|
export type MediaFamily = 'seedance' | 'wan' | 'veo' | 'generic';
|
|
@@ -67,7 +67,7 @@ export interface ExtraBodyParamDef {
|
|
|
67
67
|
* Per-model capability description — the data a `CapabilityRegistry` holds.
|
|
68
68
|
* Field names deliberately align with OpenRouter's `GET /api/v1/videos/models`
|
|
69
69
|
* shape so a future remote-fetched catalogue is a data-source swap, not a
|
|
70
|
-
* reshape (see `
|
|
70
|
+
* reshape (see `archived provenance ledger`).
|
|
71
71
|
*/
|
|
72
72
|
export interface ModelCapability {
|
|
73
73
|
/** Catalogue id (vendor-aggregator prefixes stripped — see `normalizeModelId`). */
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Ported from OD's `apps/daemon/src/media/models.ts` (catalogue
|
|
6
6
|
* shape) and `apps/daemon/src/media-adapters/types.ts` (capability +
|
|
7
|
-
* request-builder shape) — see `
|
|
7
|
+
* request-builder shape) — see `archived provenance ledger` for the full provenance.
|
|
8
8
|
* Neither origin file carries any OD domain noun; this is a product-neutral
|
|
9
9
|
* multi-vendor media-generation type system, not an OD concept.
|
|
10
10
|
*/
|
|
@@ -14,21 +14,31 @@
|
|
|
14
14
|
* `seconds` MUST be a number and the only size hint is `size`.
|
|
15
15
|
* • `generic` (Sora and similar) — flat JSON with `seconds` as a string.
|
|
16
16
|
*
|
|
17
|
-
* See `
|
|
17
|
+
* See `archived provenance ledger` for the vendor-verification notes each snapping
|
|
18
18
|
* function was ported with — they encode real, tested API quirks, not
|
|
19
19
|
* arbitrary defaults.
|
|
20
20
|
*/
|
|
21
21
|
import type { BuiltVideoRequest, MediaFamily, ModelCapability, NormalizedVideoResponse, VideoBuildInput } from './types.js';
|
|
22
22
|
/** Resolves the upstream model name: the i2v variant when a reference image is present. */
|
|
23
|
-
export declare function resolveWireModel(cap
|
|
23
|
+
export declare function resolveWireModel({ cap, hasReference }: {
|
|
24
|
+
cap: ModelCapability;
|
|
25
|
+
hasReference: boolean;
|
|
26
|
+
}): string;
|
|
24
27
|
/** Derives the request family from the resolved upstream model name (or an explicit `cap.family` override). */
|
|
25
|
-
export declare function deriveVideoFamily(wireModel
|
|
28
|
+
export declare function deriveVideoFamily({ wireModel }: {
|
|
29
|
+
wireModel: string;
|
|
30
|
+
}, { cap }?: {
|
|
31
|
+
cap?: ModelCapability | undefined;
|
|
32
|
+
}): MediaFamily;
|
|
26
33
|
/**
|
|
27
34
|
* Snaps a requested duration to the model's allowed set (e.g. Veo 4/6/8, wan
|
|
28
35
|
* 5/10). Falls back to a 3-12 clamp when the model declares no constraint.
|
|
29
36
|
* Ties prefer the shorter value (array order wins on an exact tie distance).
|
|
30
37
|
*/
|
|
31
|
-
export declare function snapDuration(cap
|
|
38
|
+
export declare function snapDuration({ cap, requested }: {
|
|
39
|
+
cap: ModelCapability;
|
|
40
|
+
requested: number | undefined;
|
|
41
|
+
}): number;
|
|
32
42
|
/**
|
|
33
43
|
* Seedance and wan accept resolution only as a quality token
|
|
34
44
|
* (`480p`/`720p`/`1080p`), never a `WxH` pixel string. Normalizes whichever
|
|
@@ -36,27 +46,40 @@ export declare function snapDuration(cap: ModelCapability, requested: number | u
|
|
|
36
46
|
* (720→720p, 1080→1080p, ...); defaults to `720p` when nothing usable is
|
|
37
47
|
* supplied. (The `wan` family upper-cases the result itself.)
|
|
38
48
|
*/
|
|
39
|
-
export declare function snapResolutionToken(resolution
|
|
49
|
+
export declare function snapResolutionToken({ resolution, size }: {
|
|
50
|
+
resolution: string | undefined;
|
|
51
|
+
size: string | undefined;
|
|
52
|
+
}): string;
|
|
40
53
|
/**
|
|
41
54
|
* Veo (via the verified gateway's Gemini predictLongRunning shim) only
|
|
42
55
|
* accepts a handful of `size` values — anything mapping outside 720p/1080p
|
|
43
56
|
* (e.g. a 1:1 `1024x1024`) 400s. Snaps to the nearest valid Veo size by
|
|
44
57
|
* orientation; defaults to landscape 720p.
|
|
45
58
|
*/
|
|
46
|
-
export declare function snapVeoSize(size
|
|
59
|
+
export declare function snapVeoSize({ size }: {
|
|
60
|
+
size: string | undefined;
|
|
61
|
+
}): string;
|
|
47
62
|
/**
|
|
48
63
|
* Snaps a requested `size` to the model's declared `supportedSizes` by
|
|
49
64
|
* orientation (portrait matches portrait, else landscape). Returns the size
|
|
50
65
|
* unchanged when the model declares no constraint; falls back to the first
|
|
51
66
|
* supported size when the input is missing/unparseable.
|
|
52
67
|
*/
|
|
53
|
-
export declare function snapSizeToSupported(size
|
|
68
|
+
export declare function snapSizeToSupported({ size, supported }: {
|
|
69
|
+
size: string | undefined;
|
|
70
|
+
supported: readonly string[] | undefined;
|
|
71
|
+
}): string | undefined;
|
|
54
72
|
/**
|
|
55
73
|
* Builds the upstream video request body for a model. Pure: no fetch, no
|
|
56
74
|
* auth. Caller: `POST \`${baseUrl}${pathSuffix}\`` with auth headers +
|
|
57
75
|
* `JSON.stringify(body)`.
|
|
58
76
|
*/
|
|
59
|
-
export declare function buildVideoRequest(cap
|
|
77
|
+
export declare function buildVideoRequest({ cap, input }: {
|
|
78
|
+
cap: ModelCapability;
|
|
79
|
+
input: VideoBuildInput;
|
|
80
|
+
}): BuiltVideoRequest;
|
|
60
81
|
/** Best-effort normalization of an async-submit / poll response across vendor families. */
|
|
61
|
-
export declare function normalizeVideoResponse(raw
|
|
82
|
+
export declare function normalizeVideoResponse({ raw }: {
|
|
83
|
+
raw: unknown;
|
|
84
|
+
}): NormalizedVideoResponse;
|
|
62
85
|
//# sourceMappingURL=video-request.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** Resolves the upstream model name: the i2v variant when a reference image is present. */
|
|
2
|
-
export function resolveWireModel(cap, hasReference) {
|
|
2
|
+
export function resolveWireModel({ cap, hasReference }) {
|
|
3
3
|
return hasReference && cap.apiModelI2V ? cap.apiModelI2V : cap.apiModel;
|
|
4
4
|
}
|
|
5
5
|
/** Derives the request family from the resolved upstream model name (or an explicit `cap.family` override). */
|
|
6
|
-
export function deriveVideoFamily(wireModel, cap) {
|
|
6
|
+
export function deriveVideoFamily({ wireModel }, { cap } = {}) {
|
|
7
7
|
if (cap?.family)
|
|
8
8
|
return cap.family;
|
|
9
9
|
const m = wireModel.toLowerCase();
|
|
@@ -20,7 +20,7 @@ export function deriveVideoFamily(wireModel, cap) {
|
|
|
20
20
|
* 5/10). Falls back to a 3-12 clamp when the model declares no constraint.
|
|
21
21
|
* Ties prefer the shorter value (array order wins on an exact tie distance).
|
|
22
22
|
*/
|
|
23
|
-
export function snapDuration(cap, requested) {
|
|
23
|
+
export function snapDuration({ cap, requested }) {
|
|
24
24
|
const req = Number.isFinite(requested) ? requested : 5;
|
|
25
25
|
const allowed = cap.supportedDurations;
|
|
26
26
|
if (!allowed || allowed.length === 0) {
|
|
@@ -35,7 +35,7 @@ export function snapDuration(cap, requested) {
|
|
|
35
35
|
* (720→720p, 1080→1080p, ...); defaults to `720p` when nothing usable is
|
|
36
36
|
* supplied. (The `wan` family upper-cases the result itself.)
|
|
37
37
|
*/
|
|
38
|
-
export function snapResolutionToken(resolution, size) {
|
|
38
|
+
export function snapResolutionToken({ resolution, size }) {
|
|
39
39
|
const token = (resolution || '').trim().toLowerCase();
|
|
40
40
|
if (/^(480|720|1080)p$/.test(token))
|
|
41
41
|
return token;
|
|
@@ -57,7 +57,7 @@ const VEO_VALID_SIZES = new Set(['1280x720', '720x1280', '1920x1080', '1080x1920
|
|
|
57
57
|
* (e.g. a 1:1 `1024x1024`) 400s. Snaps to the nearest valid Veo size by
|
|
58
58
|
* orientation; defaults to landscape 720p.
|
|
59
59
|
*/
|
|
60
|
-
export function snapVeoSize(size) {
|
|
60
|
+
export function snapVeoSize({ size }) {
|
|
61
61
|
const s = (size || '').trim().toLowerCase().replace('×', 'x');
|
|
62
62
|
if (VEO_VALID_SIZES.has(s))
|
|
63
63
|
return s;
|
|
@@ -72,7 +72,7 @@ export function snapVeoSize(size) {
|
|
|
72
72
|
* unchanged when the model declares no constraint; falls back to the first
|
|
73
73
|
* supported size when the input is missing/unparseable.
|
|
74
74
|
*/
|
|
75
|
-
export function snapSizeToSupported(size, supported) {
|
|
75
|
+
export function snapSizeToSupported({ size, supported }) {
|
|
76
76
|
if (!supported || supported.length === 0)
|
|
77
77
|
return size;
|
|
78
78
|
const norm = (v) => v.trim().toLowerCase().replace('×', 'x');
|
|
@@ -120,11 +120,11 @@ function buildSeedanceContent(input) {
|
|
|
120
120
|
* auth. Caller: `POST \`${baseUrl}${pathSuffix}\`` with auth headers +
|
|
121
121
|
* `JSON.stringify(body)`.
|
|
122
122
|
*/
|
|
123
|
-
export function buildVideoRequest(cap, input) {
|
|
123
|
+
export function buildVideoRequest({ cap, input }) {
|
|
124
124
|
const hasReference = Boolean(input.imageRef?.dataUrl);
|
|
125
|
-
const wireModel = resolveWireModel(cap, hasReference);
|
|
126
|
-
const family = deriveVideoFamily(wireModel, cap);
|
|
127
|
-
const seconds = snapDuration(cap, input.durationSeconds);
|
|
125
|
+
const wireModel = resolveWireModel({ cap: cap, hasReference: hasReference });
|
|
126
|
+
const family = deriveVideoFamily({ wireModel: wireModel }, { cap: cap });
|
|
127
|
+
const seconds = snapDuration({ cap: cap, requested: input.durationSeconds });
|
|
128
128
|
let body;
|
|
129
129
|
if (family === 'seedance') {
|
|
130
130
|
body = {
|
|
@@ -132,7 +132,7 @@ export function buildVideoRequest(cap, input) {
|
|
|
132
132
|
prompt: input.prompt,
|
|
133
133
|
duration: seconds,
|
|
134
134
|
content: buildSeedanceContent(input),
|
|
135
|
-
resolution: snapResolutionToken(input.resolution, input.size),
|
|
135
|
+
resolution: snapResolutionToken({ resolution: input.resolution, size: input.size }),
|
|
136
136
|
};
|
|
137
137
|
if (input.aspectRatio)
|
|
138
138
|
body.ratio = input.aspectRatio;
|
|
@@ -147,7 +147,7 @@ export function buildVideoRequest(cap, input) {
|
|
|
147
147
|
wanInput.media = [{ type: 'first_frame', url: input.imageRef.dataUrl }];
|
|
148
148
|
}
|
|
149
149
|
const parameters = {
|
|
150
|
-
resolution: snapResolutionToken(input.resolution, input.size).toUpperCase(),
|
|
150
|
+
resolution: snapResolutionToken({ resolution: input.resolution, size: input.size }).toUpperCase(),
|
|
151
151
|
duration: seconds,
|
|
152
152
|
prompt_extend: true,
|
|
153
153
|
watermark: false,
|
|
@@ -163,7 +163,7 @@ export function buildVideoRequest(cap, input) {
|
|
|
163
163
|
model: wireModel,
|
|
164
164
|
prompt: input.prompt,
|
|
165
165
|
seconds,
|
|
166
|
-
size: snapVeoSize(input.size),
|
|
166
|
+
size: snapVeoSize({ size: input.size }),
|
|
167
167
|
};
|
|
168
168
|
if (typeof input.generateAudio === 'boolean')
|
|
169
169
|
body.generate_audio = input.generateAudio;
|
|
@@ -176,7 +176,7 @@ export function buildVideoRequest(cap, input) {
|
|
|
176
176
|
prompt: input.prompt,
|
|
177
177
|
seconds: String(seconds),
|
|
178
178
|
};
|
|
179
|
-
const genericSize = snapSizeToSupported(input.size, cap.supportedSizes);
|
|
179
|
+
const genericSize = snapSizeToSupported({ size: input.size, supported: cap.supportedSizes });
|
|
180
180
|
if (genericSize)
|
|
181
181
|
body.size = genericSize;
|
|
182
182
|
if (input.resolution)
|
|
@@ -192,7 +192,7 @@ export function buildVideoRequest(cap, input) {
|
|
|
192
192
|
return { wireModel, family, pathSuffix: '/videos', contentType: 'application/json', body, hasReference };
|
|
193
193
|
}
|
|
194
194
|
/** Best-effort normalization of an async-submit / poll response across vendor families. */
|
|
195
|
-
export function normalizeVideoResponse(raw) {
|
|
195
|
+
export function normalizeVideoResponse({ raw }) {
|
|
196
196
|
const d = (raw ?? {});
|
|
197
197
|
const data = d.data;
|
|
198
198
|
const dataArray = Array.isArray(d.data) ? d.data : undefined;
|