@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.
Files changed (209) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +72 -24
  3. package/dist/args.d.ts +8 -0
  4. package/dist/args.js +10 -0
  5. package/dist/argument-error.d.ts +9 -0
  6. package/dist/argument-error.js +7 -0
  7. package/dist/credentialed-http/auth-schemes.d.ts +29 -0
  8. package/dist/credentialed-http/auth-schemes.js +60 -0
  9. package/dist/credentialed-http/credentialed-request.d.ts +132 -0
  10. package/dist/credentialed-http/credentialed-request.js +365 -0
  11. package/dist/credentialed-http/index.d.ts +4 -0
  12. package/dist/credentialed-http/index.js +4 -0
  13. package/dist/credentialed-http/ports.d.ts +42 -0
  14. package/dist/credentialed-http/ports.js +2 -0
  15. package/dist/media-providers/capability-registry.d.ts +12 -4
  16. package/dist/media-providers/capability-registry.js +6 -6
  17. package/dist/media-providers/dispatch/async-operation-store.d.ts +33 -8
  18. package/dist/media-providers/dispatch/async-operation-store.js +20 -32
  19. package/dist/media-providers/dispatch/context.d.ts +7 -2
  20. package/dist/media-providers/dispatch/context.js +1 -1
  21. package/dist/media-providers/dispatch/credentials.d.ts +4 -1
  22. package/dist/media-providers/dispatch/credentials.js +1 -1
  23. package/dist/media-providers/dispatch/engine.d.ts +5 -2
  24. package/dist/media-providers/dispatch/engine.js +23 -15
  25. package/dist/media-providers/dispatch/index.d.ts +4 -1
  26. package/dist/media-providers/dispatch/index.js +4 -2
  27. package/dist/media-providers/dispatch/openai-compatible.d.ts +12 -2
  28. package/dist/media-providers/dispatch/openai-compatible.js +9 -5
  29. package/dist/media-providers/dispatch/operation-runtime.d.ts +16 -8
  30. package/dist/media-providers/dispatch/operation-runtime.js +93 -76
  31. package/dist/media-providers/dispatch/outbound.d.ts +31 -0
  32. package/dist/media-providers/dispatch/outbound.js +54 -0
  33. package/dist/media-providers/dispatch/polling-adapter.d.ts +26 -8
  34. package/dist/media-providers/dispatch/polling-adapter.js +2 -2
  35. package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts +2 -2
  36. package/dist/media-providers/dispatch/providers/aihubmix-shared.js +2 -2
  37. package/dist/media-providers/dispatch/providers/aihubmix.d.ts +8 -2
  38. package/dist/media-providers/dispatch/providers/aihubmix.js +15 -15
  39. package/dist/media-providers/dispatch/providers/custom-image.d.ts +11 -2
  40. package/dist/media-providers/dispatch/providers/custom-image.js +9 -8
  41. package/dist/media-providers/dispatch/providers/elevenlabs.d.ts +8 -2
  42. package/dist/media-providers/dispatch/providers/elevenlabs.js +13 -13
  43. package/dist/media-providers/dispatch/providers/fishaudio.d.ts +4 -1
  44. package/dist/media-providers/dispatch/providers/fishaudio.js +7 -7
  45. package/dist/media-providers/dispatch/providers/grok.d.ts +11 -3
  46. package/dist/media-providers/dispatch/providers/grok.js +16 -16
  47. package/dist/media-providers/dispatch/providers/imagerouter-video-async.d.ts +1 -1
  48. package/dist/media-providers/dispatch/providers/imagerouter-video-async.js +23 -22
  49. package/dist/media-providers/dispatch/providers/imagerouter.d.ts +12 -3
  50. package/dist/media-providers/dispatch/providers/imagerouter.js +18 -18
  51. package/dist/media-providers/dispatch/providers/minimax.d.ts +4 -1
  52. package/dist/media-providers/dispatch/providers/minimax.js +6 -6
  53. package/dist/media-providers/dispatch/providers/nanobanana.d.ts +4 -1
  54. package/dist/media-providers/dispatch/providers/nanobanana.js +7 -7
  55. package/dist/media-providers/dispatch/providers/openai.d.ts +8 -2
  56. package/dist/media-providers/dispatch/providers/openai.js +20 -27
  57. package/dist/media-providers/dispatch/providers/openrouter.d.ts +7 -2
  58. package/dist/media-providers/dispatch/providers/openrouter.js +11 -11
  59. package/dist/media-providers/dispatch/providers/senseaudio.d.ts +8 -2
  60. package/dist/media-providers/dispatch/providers/senseaudio.js +13 -13
  61. package/dist/media-providers/dispatch/providers/volcengine.d.ts +4 -1
  62. package/dist/media-providers/dispatch/providers/volcengine.js +8 -8
  63. package/dist/media-providers/dispatch/response-parsers.d.ts +21 -7
  64. package/dist/media-providers/dispatch/response-parsers.js +15 -11
  65. package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts +3 -1
  66. package/dist/media-providers/dispatch/sqlite-async-operation-store.js +53 -39
  67. package/dist/media-providers/dispatch/ssrf-guard.d.ts +27 -14
  68. package/dist/media-providers/dispatch/ssrf-guard.js +46 -105
  69. package/dist/media-providers/dispatch/stub.d.ts +7 -2
  70. package/dist/media-providers/dispatch/stub.js +4 -3
  71. package/dist/media-providers/dispatch/types.d.ts +17 -13
  72. package/dist/media-providers/dispatch/vendor-adapter.d.ts +22 -5
  73. package/dist/media-providers/dispatch/vendor-adapter.js +13 -10
  74. package/dist/media-providers/dispatch/vendor-registry.d.ts +14 -4
  75. package/dist/media-providers/dispatch/vendor-registry.js +3 -3
  76. package/dist/media-providers/index.d.ts +1 -1
  77. package/dist/media-providers/index.js +1 -1
  78. package/dist/media-providers/policy.d.ts +3 -2
  79. package/dist/media-providers/policy.js +4 -2
  80. package/dist/media-providers/providers.d.ts +12 -4
  81. package/dist/media-providers/providers.js +3 -3
  82. package/dist/media-providers/staging.d.ts +8 -2
  83. package/dist/media-providers/staging.js +13 -4
  84. package/dist/media-providers/task-store.d.ts +2 -2
  85. package/dist/media-providers/task-store.js +2 -2
  86. package/dist/media-providers/tokens.js +3 -3
  87. package/dist/media-providers/types.d.ts +4 -4
  88. package/dist/media-providers/types.js +1 -1
  89. package/dist/media-providers/video-request.d.ts +32 -9
  90. package/dist/media-providers/video-request.js +15 -15
  91. package/dist/webhooks/delivery.d.ts +76 -0
  92. package/dist/webhooks/delivery.js +222 -0
  93. package/dist/webhooks/index.d.ts +7 -0
  94. package/dist/webhooks/index.js +7 -0
  95. package/dist/webhooks/ports.d.ts +113 -0
  96. package/dist/webhooks/ports.js +2 -0
  97. package/dist/webhooks/signing.d.ts +38 -0
  98. package/dist/webhooks/signing.js +83 -0
  99. package/dist/webhooks/signing.keyring.d.ts +8 -0
  100. package/dist/webhooks/signing.keyring.js +18 -0
  101. package/dist/webhooks/subscriptions.d.ts +78 -0
  102. package/dist/webhooks/subscriptions.js +139 -0
  103. package/dist/webhooks/types.d.ts +103 -0
  104. package/dist/webhooks/types.js +2 -0
  105. package/package.json +29 -18
  106. package/dist/composio/bounded-data.d.ts.map +0 -1
  107. package/dist/composio/bounded-data.js.map +0 -1
  108. package/dist/composio/catalog.d.ts.map +0 -1
  109. package/dist/composio/catalog.js.map +0 -1
  110. package/dist/composio/composio-config.d.ts.map +0 -1
  111. package/dist/composio/composio-config.js.map +0 -1
  112. package/dist/composio/composio-descriptions.d.ts.map +0 -1
  113. package/dist/composio/composio-descriptions.js.map +0 -1
  114. package/dist/composio/composio.d.ts.map +0 -1
  115. package/dist/composio/composio.js.map +0 -1
  116. package/dist/composio/errors.d.ts.map +0 -1
  117. package/dist/composio/errors.js.map +0 -1
  118. package/dist/composio/file-lock.d.ts.map +0 -1
  119. package/dist/composio/file-lock.js.map +0 -1
  120. package/dist/composio/index.d.ts.map +0 -1
  121. package/dist/composio/index.js.map +0 -1
  122. package/dist/composio/json-schema.d.ts.map +0 -1
  123. package/dist/composio/json-schema.js.map +0 -1
  124. package/dist/composio/output-protection.d.ts.map +0 -1
  125. package/dist/composio/output-protection.js.map +0 -1
  126. package/dist/composio/service.d.ts.map +0 -1
  127. package/dist/composio/service.js.map +0 -1
  128. package/dist/media-providers/capability-registry.d.ts.map +0 -1
  129. package/dist/media-providers/capability-registry.js.map +0 -1
  130. package/dist/media-providers/catalog.d.ts.map +0 -1
  131. package/dist/media-providers/catalog.js.map +0 -1
  132. package/dist/media-providers/dispatch/async-operation-store.d.ts.map +0 -1
  133. package/dist/media-providers/dispatch/async-operation-store.js.map +0 -1
  134. package/dist/media-providers/dispatch/context.d.ts.map +0 -1
  135. package/dist/media-providers/dispatch/context.js.map +0 -1
  136. package/dist/media-providers/dispatch/credentials.d.ts.map +0 -1
  137. package/dist/media-providers/dispatch/credentials.js.map +0 -1
  138. package/dist/media-providers/dispatch/engine.d.ts.map +0 -1
  139. package/dist/media-providers/dispatch/engine.js.map +0 -1
  140. package/dist/media-providers/dispatch/index.d.ts.map +0 -1
  141. package/dist/media-providers/dispatch/index.js.map +0 -1
  142. package/dist/media-providers/dispatch/openai-compatible.d.ts.map +0 -1
  143. package/dist/media-providers/dispatch/openai-compatible.js.map +0 -1
  144. package/dist/media-providers/dispatch/operation-runtime.d.ts.map +0 -1
  145. package/dist/media-providers/dispatch/operation-runtime.js.map +0 -1
  146. package/dist/media-providers/dispatch/polling-adapter.d.ts.map +0 -1
  147. package/dist/media-providers/dispatch/polling-adapter.js.map +0 -1
  148. package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts.map +0 -1
  149. package/dist/media-providers/dispatch/providers/aihubmix-shared.js.map +0 -1
  150. package/dist/media-providers/dispatch/providers/aihubmix.d.ts.map +0 -1
  151. package/dist/media-providers/dispatch/providers/aihubmix.js.map +0 -1
  152. package/dist/media-providers/dispatch/providers/custom-image.d.ts.map +0 -1
  153. package/dist/media-providers/dispatch/providers/custom-image.js.map +0 -1
  154. package/dist/media-providers/dispatch/providers/elevenlabs.d.ts.map +0 -1
  155. package/dist/media-providers/dispatch/providers/elevenlabs.js.map +0 -1
  156. package/dist/media-providers/dispatch/providers/fishaudio.d.ts.map +0 -1
  157. package/dist/media-providers/dispatch/providers/fishaudio.js.map +0 -1
  158. package/dist/media-providers/dispatch/providers/grok.d.ts.map +0 -1
  159. package/dist/media-providers/dispatch/providers/grok.js.map +0 -1
  160. package/dist/media-providers/dispatch/providers/imagerouter-video-async.d.ts.map +0 -1
  161. package/dist/media-providers/dispatch/providers/imagerouter-video-async.js.map +0 -1
  162. package/dist/media-providers/dispatch/providers/imagerouter.d.ts.map +0 -1
  163. package/dist/media-providers/dispatch/providers/imagerouter.js.map +0 -1
  164. package/dist/media-providers/dispatch/providers/minimax.d.ts.map +0 -1
  165. package/dist/media-providers/dispatch/providers/minimax.js.map +0 -1
  166. package/dist/media-providers/dispatch/providers/nanobanana.d.ts.map +0 -1
  167. package/dist/media-providers/dispatch/providers/nanobanana.js.map +0 -1
  168. package/dist/media-providers/dispatch/providers/openai.d.ts.map +0 -1
  169. package/dist/media-providers/dispatch/providers/openai.js.map +0 -1
  170. package/dist/media-providers/dispatch/providers/openrouter.d.ts.map +0 -1
  171. package/dist/media-providers/dispatch/providers/openrouter.js.map +0 -1
  172. package/dist/media-providers/dispatch/providers/senseaudio.d.ts.map +0 -1
  173. package/dist/media-providers/dispatch/providers/senseaudio.js.map +0 -1
  174. package/dist/media-providers/dispatch/providers/volcengine.d.ts.map +0 -1
  175. package/dist/media-providers/dispatch/providers/volcengine.js.map +0 -1
  176. package/dist/media-providers/dispatch/response-parsers.d.ts.map +0 -1
  177. package/dist/media-providers/dispatch/response-parsers.js.map +0 -1
  178. package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts.map +0 -1
  179. package/dist/media-providers/dispatch/sqlite-async-operation-store.js.map +0 -1
  180. package/dist/media-providers/dispatch/ssrf-guard.d.ts.map +0 -1
  181. package/dist/media-providers/dispatch/ssrf-guard.js.map +0 -1
  182. package/dist/media-providers/dispatch/stub.d.ts.map +0 -1
  183. package/dist/media-providers/dispatch/stub.js.map +0 -1
  184. package/dist/media-providers/dispatch/types.d.ts.map +0 -1
  185. package/dist/media-providers/dispatch/types.js.map +0 -1
  186. package/dist/media-providers/dispatch/vendor-adapter.d.ts.map +0 -1
  187. package/dist/media-providers/dispatch/vendor-adapter.js.map +0 -1
  188. package/dist/media-providers/dispatch/vendor-registry.d.ts.map +0 -1
  189. package/dist/media-providers/dispatch/vendor-registry.js.map +0 -1
  190. package/dist/media-providers/index.d.ts.map +0 -1
  191. package/dist/media-providers/index.js.map +0 -1
  192. package/dist/media-providers/policy.d.ts.map +0 -1
  193. package/dist/media-providers/policy.js.map +0 -1
  194. package/dist/media-providers/providers.d.ts.map +0 -1
  195. package/dist/media-providers/providers.js.map +0 -1
  196. package/dist/media-providers/seed.d.ts.map +0 -1
  197. package/dist/media-providers/seed.js.map +0 -1
  198. package/dist/media-providers/sqlite-task-store.d.ts.map +0 -1
  199. package/dist/media-providers/sqlite-task-store.js.map +0 -1
  200. package/dist/media-providers/staging.d.ts.map +0 -1
  201. package/dist/media-providers/staging.js.map +0 -1
  202. package/dist/media-providers/task-store.d.ts.map +0 -1
  203. package/dist/media-providers/task-store.js.map +0 -1
  204. package/dist/media-providers/tokens.d.ts.map +0 -1
  205. package/dist/media-providers/tokens.js.map +0 -1
  206. package/dist/media-providers/types.d.ts.map +0 -1
  207. package/dist/media-providers/types.js.map +0 -1
  208. package/dist/media-providers/video-request.d.ts.map +0 -1
  209. 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> = (ctx: RenderContext, credentials: ProviderCredentials) => VendorRequest<Meta>;
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> = (resp: Response, ctx: RenderContext, request: VendorRequest<Meta>) => Promise<RenderResult>;
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 = (credentials: ProviderCredentials) => void;
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: VendorAdapter<Meta>, ctx: RenderContext, credentials: ProviderCredentials): Promise<RenderResult>;
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: string): VendorCredentialGuard;
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 `source-map.md`'s 2026-07-21
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, fetchWithTimeout } from '@jini-ai/platform';
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). `fetchWithTimeout` combines any signal a vendor
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 fetchWithTimeout(request.url, request.init, { timeoutMs: FETCH_TIMEOUT_MS.GENERATE });
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
- * `source-map.md`'s 2026-07-21 dispatch-engine-generalization section for
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: string, routeKey: string, adapter: VendorAdapter<Meta>): void;
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: string, routeKey: string): VendorAdapter<never> | undefined;
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: string, routeKey: string): boolean;
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
- * `source-map.md` for full provenance, exactly which vendors are ported vs
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
- * `source-map.md` for full provenance, exactly which vendors are ported vs
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(target: MediaPolicyTarget): MediaPolicyDenial | null;
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(policy?: MediaExecutionPolicy): MediaPolicy;
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(policy = DEFAULT_MEDIA_EXECUTION_POLICY) {
13
+ export function createAllowlistMediaPolicy(_required, optional = {}) {
14
+ const policy = { ...DEFAULT_MEDIA_EXECUTION_POLICY, ...optional };
14
15
  return {
15
- evaluate(target) {
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 `source-map.md` for exactly what was dropped.
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: string): MediaModel | null;
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: string): MediaProvider | null;
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: MediaSurface, audioKind?: AudioKind): readonly MediaModel[];
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(imagePaths: readonly string[], uploadRoot?: string | null): Promise<string[]>;
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: string, options?: AttachmentStagingOptions): AttachmentStaging;
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 || !isWithinRoot(uploadRootReal, real))
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
- * `source-map.md`.
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
- * `source-map.md`.
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 `source-map.md` for the full provenance.
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 `source-map.md`. */
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 `source-map.md` for the
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 `source-map.md`).
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 `source-map.md` for the full provenance.
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 `source-map.md` for the vendor-verification notes each snapping
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: ModelCapability, hasReference: boolean): string;
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: string, cap?: ModelCapability): MediaFamily;
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: ModelCapability, requested: number | undefined): number;
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: string | undefined, size: string | undefined): string;
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: string | undefined): string;
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: string | undefined, supported: readonly string[] | undefined): string | undefined;
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: ModelCapability, input: VideoBuildInput): BuiltVideoRequest;
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: unknown): NormalizedVideoResponse;
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;