@jini-ai/integrations 0.3.6 → 0.4.1
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 +90 -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 +13 -7
- package/dist/media-providers/capability-registry.js +6 -6
- package/dist/media-providers/dispatch/async-operation-store.d.ts +25 -8
- package/dist/media-providers/dispatch/async-operation-store.js +12 -32
- package/dist/media-providers/dispatch/builtin-vendors.d.ts +6 -0
- package/dist/media-providers/dispatch/builtin-vendors.js +30 -0
- 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 -13
- package/dist/media-providers/dispatch/engine.js +25 -26
- 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 +13 -2
- package/dist/media-providers/dispatch/providers/aihubmix.js +18 -16
- package/dist/media-providers/dispatch/providers/custom-image.d.ts +16 -2
- package/dist/media-providers/dispatch/providers/custom-image.js +12 -9
- package/dist/media-providers/dispatch/providers/elevenlabs.d.ts +13 -2
- package/dist/media-providers/dispatch/providers/elevenlabs.js +16 -14
- package/dist/media-providers/dispatch/providers/fishaudio.d.ts +9 -1
- package/dist/media-providers/dispatch/providers/fishaudio.js +10 -8
- package/dist/media-providers/dispatch/providers/grok.d.ts +16 -3
- package/dist/media-providers/dispatch/providers/grok.js +19 -17
- 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 +17 -3
- package/dist/media-providers/dispatch/providers/imagerouter.js +21 -19
- package/dist/media-providers/dispatch/providers/minimax.d.ts +9 -1
- package/dist/media-providers/dispatch/providers/minimax.js +9 -7
- package/dist/media-providers/dispatch/providers/nanobanana.d.ts +9 -1
- package/dist/media-providers/dispatch/providers/nanobanana.js +10 -8
- package/dist/media-providers/dispatch/providers/openai.d.ts +13 -2
- package/dist/media-providers/dispatch/providers/openai.js +23 -28
- package/dist/media-providers/dispatch/providers/openrouter.d.ts +12 -2
- package/dist/media-providers/dispatch/providers/openrouter.js +14 -12
- package/dist/media-providers/dispatch/providers/senseaudio.d.ts +13 -2
- package/dist/media-providers/dispatch/providers/senseaudio.js +16 -14
- package/dist/media-providers/dispatch/providers/volcengine.d.ts +9 -1
- package/dist/media-providers/dispatch/providers/volcengine.js +11 -9
- 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 +30 -28
- 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 -11
- package/dist/media-providers/dispatch/vendor-registry.js +33 -4
- 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 +35 -15
- 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 +36 -22
- 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
|
@@ -15,25 +15,25 @@ const LIVE_STATUSES = new Set(ASYNC_OPERATION_STATUSES.filter((status) => !TERMI
|
|
|
15
15
|
const LIVE_LIST = [...LIVE_STATUSES];
|
|
16
16
|
const LIVE_PLACEHOLDERS = LIVE_LIST.map(() => '?').join(', ');
|
|
17
17
|
function rowToOperation(row) {
|
|
18
|
-
return hydrateAsyncOperationRecord({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
return hydrateAsyncOperationRecord({ raw: {
|
|
19
|
+
schemaVersion: row.schema_version,
|
|
20
|
+
id: row.id,
|
|
21
|
+
providerId: row.provider_id,
|
|
22
|
+
routeKey: row.route_key,
|
|
23
|
+
ownerRef: row.owner_ref,
|
|
24
|
+
status: row.status,
|
|
25
|
+
attempts: row.attempts,
|
|
26
|
+
maxAttempts: row.max_attempts,
|
|
27
|
+
deadlineAt: row.deadline_at,
|
|
28
|
+
nextPollAt: row.next_poll_at,
|
|
29
|
+
leaseOwner: row.lease_owner,
|
|
30
|
+
leaseExpiresAt: row.lease_expires_at,
|
|
31
|
+
state: row.state === null ? null : JSON.parse(row.state),
|
|
32
|
+
result: row.result === null ? null : JSON.parse(row.result),
|
|
33
|
+
error: row.error === null ? null : JSON.parse(row.error),
|
|
34
|
+
createdAt: row.created_at,
|
|
35
|
+
updatedAt: row.updated_at,
|
|
36
|
+
} });
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* Opens (creating if absent) a `better-sqlite3` database at `dbPath` and returns an
|
|
@@ -44,7 +44,7 @@ function rowToOperation(row) {
|
|
|
44
44
|
* operation exactly as it was left, and `recoverAfterRestart`/`reconcileOnBoot` can then release
|
|
45
45
|
* dead leases and expire blown deadlines.
|
|
46
46
|
*/
|
|
47
|
-
export async function createSqliteAsyncOperationStore(dbPath) {
|
|
47
|
+
export async function createSqliteAsyncOperationStore({ dbPath }) {
|
|
48
48
|
const { default: Database } = await import('better-sqlite3');
|
|
49
49
|
const db = new Database(dbPath);
|
|
50
50
|
db.pragma('journal_mode = WAL');
|
|
@@ -125,7 +125,7 @@ export async function createSqliteAsyncOperationStore(dbPath) {
|
|
|
125
125
|
if (!Number.isFinite(input.deadlineAt)) {
|
|
126
126
|
throw new RangeError(`Invalid deadlineAt: ${input.deadlineAt} must be a finite epoch-ms timestamp`);
|
|
127
127
|
}
|
|
128
|
-
assertNoCredentialMaterial(input.state);
|
|
128
|
+
assertNoCredentialMaterial({ state: input.state });
|
|
129
129
|
const now = Date.now();
|
|
130
130
|
const status = input.status ?? 'submitted';
|
|
131
131
|
insertStmt.run(input.id, input.providerId, input.routeKey, input.ownerRef, status, 0, input.maxAttempts, input.deadlineAt, input.nextPollAt ?? now, stateJson(input.state), ASYNC_OPERATION_SCHEMA_VERSION, now, now);
|
|
@@ -142,7 +142,7 @@ export async function createSqliteAsyncOperationStore(dbPath) {
|
|
|
142
142
|
return existing;
|
|
143
143
|
}
|
|
144
144
|
if ('state' in patch)
|
|
145
|
-
assertNoCredentialMaterial(patch.state);
|
|
145
|
+
assertNoCredentialMaterial({ state: patch.state });
|
|
146
146
|
const status = patch.status ?? existing.status;
|
|
147
147
|
assertTransition(existing.status, status);
|
|
148
148
|
const next = {
|
|
@@ -176,23 +176,25 @@ export async function createSqliteAsyncOperationStore(dbPath) {
|
|
|
176
176
|
return { leasesReleased, deadlineExpired };
|
|
177
177
|
});
|
|
178
178
|
return {
|
|
179
|
-
async create(
|
|
179
|
+
async create(required, optional = {}) {
|
|
180
|
+
const input = { ...required, ...optional };
|
|
180
181
|
return createTxn(input);
|
|
181
182
|
},
|
|
182
|
-
async get(id) {
|
|
183
|
+
async get({ id }) {
|
|
183
184
|
const row = getStmt.get(id);
|
|
184
185
|
return row ? rowToOperation(row) : null;
|
|
185
186
|
},
|
|
186
|
-
async update(id, patch, options) {
|
|
187
|
+
async update({ id, patch }, { options } = {}) {
|
|
187
188
|
return updateTxn(id, patch, options);
|
|
188
189
|
},
|
|
189
|
-
async listByOwner(ownerRef) {
|
|
190
|
+
async listByOwner({ ownerRef }) {
|
|
190
191
|
return listByOwnerStmt.all(ownerRef).map(rowToOperation);
|
|
191
192
|
},
|
|
192
|
-
async claimDue(
|
|
193
|
+
async claimDue(required, optional = {}) {
|
|
194
|
+
const options = { ...required, ...optional };
|
|
193
195
|
return claimDueTxn(options);
|
|
194
196
|
},
|
|
195
|
-
async releaseLease(id, leaseOwner) {
|
|
197
|
+
async releaseLease({ id, leaseOwner }) {
|
|
196
198
|
releaseLeaseStmt.run(Date.now(), id, leaseOwner);
|
|
197
199
|
},
|
|
198
200
|
async reconcileOnBoot(options) {
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
+
import type { MediaOutboundOptions } from './outbound.js';
|
|
1
2
|
export interface DnsLookupAddress {
|
|
2
3
|
readonly address: string;
|
|
3
4
|
readonly family: number;
|
|
4
5
|
}
|
|
5
|
-
export type DnsLookupFn = (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/** The unspecified address, RFC1918/CGNAT/link-local/multicast IPv4 (via `isBlockedIpv4`), unique-local (`fc00::/7`) and link-local (`fe80::/10`) IPv6, and their IPv4-mapped-IPv6 equivalents. */
|
|
9
|
-
export declare function isBlockedExternalApiHostname(hostname: string): boolean;
|
|
6
|
+
export type DnsLookupFn = (required: {
|
|
7
|
+
hostname: string;
|
|
8
|
+
}) => Promise<readonly DnsLookupAddress[]>;
|
|
10
9
|
/**
|
|
11
10
|
* DNS-aware companion to the sync hostname check: resolves the hostname and
|
|
12
11
|
* re-runs the block-list against every address it actually resolves to, so
|
|
13
12
|
* a public DNS name pointing at internal infrastructure
|
|
14
13
|
* (`internal.example.com` -> `10.0.0.5`) can't slip through a hostname-only
|
|
15
|
-
* check. DNS
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* sync check above already rejected the obvious literal-IP cases.
|
|
14
|
+
* check. DNS failures and empty answers fail closed: proceeding would leave
|
|
15
|
+
* the peer unverified. This precheck alone does not pin a connection;
|
|
16
|
+
* `assertAndFetchExternalAsset` uses the canonical guarded client for that.
|
|
19
17
|
*/
|
|
20
|
-
export declare function validateBaseUrlResolved(baseUrl
|
|
18
|
+
export declare function validateBaseUrlResolved({ baseUrl }: {
|
|
19
|
+
baseUrl: string;
|
|
20
|
+
}, { lookup }?: {
|
|
21
|
+
lookup?: DnsLookupFn | undefined;
|
|
22
|
+
}): Promise<{
|
|
21
23
|
ok: true;
|
|
22
24
|
} | {
|
|
23
25
|
ok: false;
|
|
@@ -31,7 +33,11 @@ export declare function validateBaseUrlResolved(baseUrl: string, lookup?: DnsLoo
|
|
|
31
33
|
* misconfigured. Returns a discriminated union so callers don't have to
|
|
32
34
|
* repeat the resolved-validation plumbing.
|
|
33
35
|
*/
|
|
34
|
-
export declare function assertExternalAssetUrl(rawUrl
|
|
36
|
+
export declare function assertExternalAssetUrl({ rawUrl }: {
|
|
37
|
+
rawUrl: string;
|
|
38
|
+
}, { lookup }?: {
|
|
39
|
+
lookup?: DnsLookupFn | undefined;
|
|
40
|
+
}): Promise<{
|
|
35
41
|
ok: true;
|
|
36
42
|
} | {
|
|
37
43
|
ok: false;
|
|
@@ -39,13 +45,20 @@ export declare function assertExternalAssetUrl(rawUrl: string, lookup?: DnsLooku
|
|
|
39
45
|
}>;
|
|
40
46
|
/**
|
|
41
47
|
* Validates an upstream-controlled asset URL and fetches it with the SSRF
|
|
42
|
-
* guard pinned through redirects:
|
|
43
|
-
*
|
|
48
|
+
* guard pinned through redirects: vets and pins the resolved peer with the
|
|
49
|
+
* canonical HTTP client, then forces `redirect: 'error'` so a validated public URL
|
|
44
50
|
* that 302s into loopback/RFC1918/metadata space is rejected before any
|
|
45
51
|
* bytes are read. Throws on a blocked host (so the redirect-bypass can't be
|
|
46
52
|
* forgotten at a call site); the forced `redirect` is spread last so it
|
|
47
53
|
* overrides any value the caller passed in `init`. Callers keep their own
|
|
48
54
|
* `!resp.ok` HTTP-status handling.
|
|
55
|
+
* @throws URL/policy refusals and DNS/transport failures, before unsafe I/O.
|
|
56
|
+
* @complexity O(a + b) for a DNS answers and b bounded decoded asset bytes.
|
|
49
57
|
*/
|
|
50
|
-
export declare function assertAndFetchExternalAsset(url
|
|
58
|
+
export declare function assertAndFetchExternalAsset({ url }: {
|
|
59
|
+
url: string;
|
|
60
|
+
}, { init, lookup, ...outbound }?: MediaOutboundOptions & {
|
|
61
|
+
init?: RequestInit | undefined;
|
|
62
|
+
lookup?: DnsLookupFn | undefined;
|
|
63
|
+
}): Promise<Response>;
|
|
51
64
|
//# sourceMappingURL=ssrf-guard.d.ts.map
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* configured `baseUrl`, which a host operator chose deliberately. Ported
|
|
7
7
|
* near-verbatim from Open Design's `apps/daemon/src/connectionTest.ts`
|
|
8
8
|
* (`assertAndFetchExternalAsset`/`assertExternalAssetUrl`/
|
|
9
|
-
* `validateBaseUrlResolved`) plus the
|
|
9
|
+
* `validateBaseUrlResolved`) plus the canonical platform/net hostname classifiers originally from
|
|
10
10
|
* `packages/contracts/src/api/connectionTest.ts` (`isLoopbackApiHost`/
|
|
11
|
-
* `isBlockedExternalApiHostname`/`validateBaseUrl`) — see `
|
|
11
|
+
* `isBlockedExternalApiHostname`/`validateBaseUrl`) — see `archived provenance ledger`.
|
|
12
12
|
*
|
|
13
13
|
* Scope note: the origin's `validateBaseUrlResolved` also accepts an
|
|
14
14
|
* operator-declared `allowedInternalHosts` allowlist
|
|
@@ -26,96 +26,25 @@
|
|
|
26
26
|
* `allowedInternalHosts` argument is empty/absent (its own first line is
|
|
27
27
|
* `if (!allowedInternalHosts || allowedInternalHosts.length === 0) return
|
|
28
28
|
* false;`) — so the allowlist branch is provably dead code on this call
|
|
29
|
-
* path and is not ported.
|
|
30
|
-
*
|
|
29
|
+
* path and is not ported. The default asset-download path is strict. Only an explicit
|
|
30
|
+
* `allowPrivateNetwork: true` development capability or a host-supplied
|
|
31
|
+
* policy-enforcing client can change the network policy; a host
|
|
31
32
|
* that wants an operator-configurable internal-host allowlist for its own
|
|
32
33
|
* *user-supplied* base URLs (a different feature, not exercised by any
|
|
33
34
|
* vendor ported into this package) would need to build that separately.
|
|
35
|
+
* Shared hostname policy strips IPv6 brackets, case and trailing FQDN dots, recognizes
|
|
36
|
+
* dotted/hex IPv4-mapped forms, and blocks loopback as well as
|
|
37
|
+
* RFC1918/CGNAT/link-local/multicast addresses. Platform's parser validates both hex groups
|
|
38
|
+
* before its non-null assertions; this module no longer maintains another parser copy.
|
|
34
39
|
*/
|
|
40
|
+
import { isLoopbackApiHost, isBlockedExternalApiHostname } from '@jini-ai/platform/net';
|
|
35
41
|
import { promises as dnsPromises } from 'node:dns';
|
|
36
|
-
import { FETCH_TIMEOUT_MS
|
|
37
|
-
|
|
42
|
+
import { FETCH_TIMEOUT_MS } from '@jini-ai/platform/fetch-with-timeout';
|
|
43
|
+
import { defaultMediaOutboundMessages, fetchMediaOutbound } from './outbound.js';
|
|
44
|
+
const defaultDnsLookup = async ({ hostname }) => {
|
|
38
45
|
const result = await dnsPromises.lookup(hostname, { all: true, family: 0 });
|
|
39
46
|
return result.map(({ address, family }) => ({ address, family }));
|
|
40
47
|
};
|
|
41
|
-
/** Strips IPv6 brackets, lowercases, and drops a trailing-dot FQDN suffix (RFC 1034) so `Localhost.`/`[::1]` compare equal to their canonical forms. */
|
|
42
|
-
function normalizeBracketedIpv6(hostname) {
|
|
43
|
-
const stripped = hostname.startsWith('[') && hostname.endsWith(']') ? hostname.slice(1, -1) : hostname;
|
|
44
|
-
return stripped.toLowerCase().replace(/\.+$/, '');
|
|
45
|
-
}
|
|
46
|
-
function parseIpv4(hostname) {
|
|
47
|
-
const parts = hostname.split('.');
|
|
48
|
-
if (parts.length !== 4)
|
|
49
|
-
return null;
|
|
50
|
-
const parsed = parts.map((part) => {
|
|
51
|
-
if (!/^\d{1,3}$/.test(part))
|
|
52
|
-
return null;
|
|
53
|
-
const value = Number(part);
|
|
54
|
-
return value >= 0 && value <= 255 ? value : null;
|
|
55
|
-
});
|
|
56
|
-
if (parsed.some((part) => part === null))
|
|
57
|
-
return null;
|
|
58
|
-
return parsed;
|
|
59
|
-
}
|
|
60
|
-
function isLoopbackIpv4(hostname) {
|
|
61
|
-
const parts = parseIpv4(hostname);
|
|
62
|
-
return Boolean(parts && parts[0] === 127);
|
|
63
|
-
}
|
|
64
|
-
/** `0.0.0.0`, CGNAT (100.64/10), link-local (169.254/16), RFC1918 private ranges, and multicast/reserved (>= 224.0.0.0). */
|
|
65
|
-
function isBlockedIpv4(hostname) {
|
|
66
|
-
const parts = parseIpv4(hostname);
|
|
67
|
-
if (!parts)
|
|
68
|
-
return false;
|
|
69
|
-
const [a, b] = parts;
|
|
70
|
-
return a === 0 || (a === 100 && b >= 64 && b <= 127) || (a === 169 && b === 254) || a === 10 || (a === 192 && b === 168) || (a === 172 && b >= 16 && b <= 31) || a >= 224;
|
|
71
|
-
}
|
|
72
|
-
/** Recovers the dotted-quad IPv4 address from an IPv4-mapped IPv6 literal (`::ffff:a.b.c.d` or `::ffff:HHHH:HHHH`), or `null` if `hostname` isn't one. */
|
|
73
|
-
function ipv4MappedToDotted(hostname) {
|
|
74
|
-
const host = normalizeBracketedIpv6(hostname);
|
|
75
|
-
const mapped = /^::ffff:(.+)$/i.exec(host)?.[1];
|
|
76
|
-
if (!mapped)
|
|
77
|
-
return null;
|
|
78
|
-
if (parseIpv4(mapped.toLowerCase()))
|
|
79
|
-
return mapped.toLowerCase();
|
|
80
|
-
const hexParts = mapped.split(':');
|
|
81
|
-
if (hexParts.length !== 2 || !hexParts.every((part) => /^[0-9a-f]{1,4}$/i.test(part))) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
// hexParts.length === 2 is already proven above, and the `.every(...)`
|
|
85
|
-
// regex above already requires each element to be a non-empty 1-4-digit
|
|
86
|
-
// hex string — so hexParts[0]/[1] can never be `undefined` here despite
|
|
87
|
-
// noUncheckedIndexedAccess's static `string | undefined` type. Asserted
|
|
88
|
-
// rather than re-guarded with a dead runtime check, matching this
|
|
89
|
-
// package's established convention (see `engine.ts`'s `allowed[0]!`).
|
|
90
|
-
const hi = hexParts[0];
|
|
91
|
-
const lo = hexParts[1];
|
|
92
|
-
const value = (Number.parseInt(hi, 16) << 16) | Number.parseInt(lo, 16);
|
|
93
|
-
return [(value >>> 24) & 255, (value >>> 16) & 255, (value >>> 8) & 255, value & 255].join('.');
|
|
94
|
-
}
|
|
95
|
-
/** `localhost`, `::1`, `127.0.0.0/8`, and their IPv4-mapped-IPv6 equivalents — the carve-out for local providers (e.g. Ollama), consulted before the blocklist so loopback is never rejected as "internal". */
|
|
96
|
-
export function isLoopbackApiHost(hostname) {
|
|
97
|
-
const host = normalizeBracketedIpv6(hostname);
|
|
98
|
-
if (host === 'localhost' || host === '::1')
|
|
99
|
-
return true;
|
|
100
|
-
if (isLoopbackIpv4(host))
|
|
101
|
-
return true;
|
|
102
|
-
const mapped = ipv4MappedToDotted(host);
|
|
103
|
-
return Boolean(mapped && isLoopbackIpv4(mapped));
|
|
104
|
-
}
|
|
105
|
-
/** The unspecified address, RFC1918/CGNAT/link-local/multicast IPv4 (via `isBlockedIpv4`), unique-local (`fc00::/7`) and link-local (`fe80::/10`) IPv6, and their IPv4-mapped-IPv6 equivalents. */
|
|
106
|
-
export function isBlockedExternalApiHostname(hostname) {
|
|
107
|
-
const host = normalizeBracketedIpv6(hostname);
|
|
108
|
-
if (host === '::')
|
|
109
|
-
return true;
|
|
110
|
-
if (isBlockedIpv4(host))
|
|
111
|
-
return true;
|
|
112
|
-
if (/^f[cd][0-9a-f]{2}:/i.test(host))
|
|
113
|
-
return true;
|
|
114
|
-
if (/^fe[89ab][0-9a-f]:/i.test(host))
|
|
115
|
-
return true;
|
|
116
|
-
const mapped = ipv4MappedToDotted(host);
|
|
117
|
-
return Boolean(mapped && isBlockedIpv4(mapped));
|
|
118
|
-
}
|
|
119
48
|
/** Whether `hostname` is already a literal IPv4/IPv6 address (as opposed to a DNS name) — skips the DNS-resolve step in `validateBaseUrlResolved` since there's nothing further to resolve. */
|
|
120
49
|
function looksLikeIpLiteral(hostname) {
|
|
121
50
|
const host = hostname.startsWith('[') && hostname.endsWith(']') ? hostname.slice(1, -1) : hostname;
|
|
@@ -131,11 +60,14 @@ function validateBaseUrlSync(baseUrl) {
|
|
|
131
60
|
catch {
|
|
132
61
|
return { ok: false, error: 'Invalid baseUrl', forbidden: false };
|
|
133
62
|
}
|
|
63
|
+
if (parsed.username || parsed.password) {
|
|
64
|
+
return { ok: false, error: defaultMediaOutboundMessages.urlCredentialsBlocked, forbidden: true };
|
|
65
|
+
}
|
|
134
66
|
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
135
67
|
return { ok: false, error: 'Only http/https allowed', forbidden: false };
|
|
136
68
|
}
|
|
137
69
|
const hostname = parsed.hostname.toLowerCase();
|
|
138
|
-
if (
|
|
70
|
+
if (isLoopbackApiHost({ hostname }) || isBlockedExternalApiHostname({ hostname })) {
|
|
139
71
|
return { ok: false, error: 'Internal IPs blocked', forbidden: true };
|
|
140
72
|
}
|
|
141
73
|
return { ok: true, parsed };
|
|
@@ -145,31 +77,30 @@ function validateBaseUrlSync(baseUrl) {
|
|
|
145
77
|
* re-runs the block-list against every address it actually resolves to, so
|
|
146
78
|
* a public DNS name pointing at internal infrastructure
|
|
147
79
|
* (`internal.example.com` -> `10.0.0.5`) can't slip through a hostname-only
|
|
148
|
-
* check. DNS
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* sync check above already rejected the obvious literal-IP cases.
|
|
80
|
+
* check. DNS failures and empty answers fail closed: proceeding would leave
|
|
81
|
+
* the peer unverified. This precheck alone does not pin a connection;
|
|
82
|
+
* `assertAndFetchExternalAsset` uses the canonical guarded client for that.
|
|
152
83
|
*/
|
|
153
|
-
export async function validateBaseUrlResolved(baseUrl, lookup = defaultDnsLookup) {
|
|
84
|
+
export async function validateBaseUrlResolved({ baseUrl }, { lookup = defaultDnsLookup } = {}) {
|
|
154
85
|
const sync = validateBaseUrlSync(baseUrl);
|
|
155
86
|
if (!sync.ok)
|
|
156
87
|
return sync;
|
|
157
88
|
const hostname = sync.parsed.hostname.toLowerCase();
|
|
158
|
-
if (
|
|
89
|
+
if (looksLikeIpLiteral(hostname)) {
|
|
159
90
|
return { ok: true };
|
|
160
91
|
}
|
|
161
92
|
let addresses;
|
|
162
93
|
try {
|
|
163
|
-
addresses = await lookup(hostname);
|
|
94
|
+
addresses = await lookup({ hostname });
|
|
164
95
|
}
|
|
165
96
|
catch {
|
|
166
|
-
return { ok: true };
|
|
97
|
+
return { ok: false, error: defaultMediaOutboundMessages.dnsResolutionFailed, forbidden: true };
|
|
167
98
|
}
|
|
99
|
+
if (addresses.length === 0)
|
|
100
|
+
return { ok: false, error: defaultMediaOutboundMessages.dnsResolutionFailed, forbidden: true };
|
|
168
101
|
for (const addr of addresses) {
|
|
169
102
|
const ip = String(addr.address).toLowerCase();
|
|
170
|
-
if (isLoopbackApiHost(ip))
|
|
171
|
-
continue;
|
|
172
|
-
if (isBlockedExternalApiHostname(ip)) {
|
|
103
|
+
if (isLoopbackApiHost({ hostname: ip }) || isBlockedExternalApiHostname({ hostname: ip })) {
|
|
173
104
|
return { ok: false, error: 'Internal IPs blocked', forbidden: true };
|
|
174
105
|
}
|
|
175
106
|
}
|
|
@@ -182,11 +113,11 @@ export async function validateBaseUrlResolved(baseUrl, lookup = defaultDnsLookup
|
|
|
182
113
|
* misconfigured. Returns a discriminated union so callers don't have to
|
|
183
114
|
* repeat the resolved-validation plumbing.
|
|
184
115
|
*/
|
|
185
|
-
export async function assertExternalAssetUrl(rawUrl, lookup = defaultDnsLookup) {
|
|
116
|
+
export async function assertExternalAssetUrl({ rawUrl }, { lookup = defaultDnsLookup } = {}) {
|
|
186
117
|
if (typeof rawUrl !== 'string' || !rawUrl) {
|
|
187
118
|
return { ok: false, error: 'empty download url' };
|
|
188
119
|
}
|
|
189
|
-
const validated = await validateBaseUrlResolved(rawUrl, lookup);
|
|
120
|
+
const validated = await validateBaseUrlResolved({ baseUrl: rawUrl }, { lookup: lookup });
|
|
190
121
|
if (!validated.ok) {
|
|
191
122
|
return {
|
|
192
123
|
ok: false,
|
|
@@ -197,19 +128,29 @@ export async function assertExternalAssetUrl(rawUrl, lookup = defaultDnsLookup)
|
|
|
197
128
|
}
|
|
198
129
|
/**
|
|
199
130
|
* Validates an upstream-controlled asset URL and fetches it with the SSRF
|
|
200
|
-
* guard pinned through redirects:
|
|
201
|
-
*
|
|
131
|
+
* guard pinned through redirects: vets and pins the resolved peer with the
|
|
132
|
+
* canonical HTTP client, then forces `redirect: 'error'` so a validated public URL
|
|
202
133
|
* that 302s into loopback/RFC1918/metadata space is rejected before any
|
|
203
134
|
* bytes are read. Throws on a blocked host (so the redirect-bypass can't be
|
|
204
135
|
* forgotten at a call site); the forced `redirect` is spread last so it
|
|
205
136
|
* overrides any value the caller passed in `init`. Callers keep their own
|
|
206
137
|
* `!resp.ok` HTTP-status handling.
|
|
138
|
+
* @throws URL/policy refusals and DNS/transport failures, before unsafe I/O.
|
|
139
|
+
* @complexity O(a + b) for a DNS answers and b bounded decoded asset bytes.
|
|
207
140
|
*/
|
|
208
|
-
export async function assertAndFetchExternalAsset(url, init = {}, lookup =
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
141
|
+
export async function assertAndFetchExternalAsset({ url }, { init = {}, lookup, ...outbound } = {}) {
|
|
142
|
+
// Preserve the early URL diagnostic. DNS vetting belongs to the client that pins the socket,
|
|
143
|
+
// not an independent lookup followed by a fetch that resolves the hostname a second time.
|
|
144
|
+
if (outbound.allowPrivateNetwork !== true && outbound.httpClient === undefined) {
|
|
145
|
+
const check = validateBaseUrlSync(url);
|
|
146
|
+
if (!check.ok)
|
|
147
|
+
throw new Error(`blocked download url (${check.error})`);
|
|
148
|
+
}
|
|
212
149
|
// Downloading an already-generated asset, not waiting on generation — UPLOAD-class (2min).
|
|
213
|
-
return
|
|
150
|
+
return fetchMediaOutbound({ url, timeoutMs: FETCH_TIMEOUT_MS.UPLOAD }, {
|
|
151
|
+
...outbound,
|
|
152
|
+
init: { ...init, redirect: 'error' },
|
|
153
|
+
...(lookup === undefined ? {} : { dns: { resolve: async ({ hostname }) => (await lookup({ hostname })).map(entry => entry.address) } }),
|
|
154
|
+
});
|
|
214
155
|
}
|
|
215
156
|
//# sourceMappingURL=ssrf-guard.js.map
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import type { RequiredArgs, OptionalArgs } from '../../args.js';
|
|
1
2
|
import type { RenderContext, RenderResult } from './types.js';
|
|
2
|
-
export declare function renderStub(ctx
|
|
3
|
+
export declare function renderStub({ ctx, providerId, integrated }: {
|
|
4
|
+
ctx: RenderContext;
|
|
5
|
+
providerId: string;
|
|
6
|
+
integrated: boolean;
|
|
7
|
+
}): Promise<RenderResult>;
|
|
3
8
|
/** Renders a labelled placeholder SVG for the image surface (an explicit opt-in alternative to the PNG placeholder). */
|
|
4
|
-
export declare function svgPlaceholder(
|
|
9
|
+
export declare function svgPlaceholder(required: RequiredArgs<RenderContext>, optional?: OptionalArgs<RenderContext>): string;
|
|
5
10
|
//# sourceMappingURL=stub.d.ts.map
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* exercised end-to-end before every vendor integration lands. Ported
|
|
7
7
|
* near-verbatim from Open Design's `apps/daemon/src/media/index.ts`
|
|
8
8
|
* `renderStub`/`svgPlaceholder`/`aspectToBox`/`silentWav` — see
|
|
9
|
-
* `
|
|
9
|
+
* `archived provenance ledger`.
|
|
10
10
|
*/
|
|
11
11
|
import { truncate } from './openai-compatible.js';
|
|
12
|
-
export async function renderStub(ctx, providerId, integrated) {
|
|
12
|
+
export async function renderStub({ ctx, providerId, integrated }) {
|
|
13
13
|
const note = !integrated ? `stub-${ctx.surface} · provider '${providerId}' integration pending` : `stub-${ctx.surface} · model=${ctx.model}`;
|
|
14
14
|
if (ctx.surface === 'image') {
|
|
15
15
|
const png = Buffer.from([
|
|
@@ -52,7 +52,8 @@ export async function renderStub(ctx, providerId, integrated) {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
/** Renders a labelled placeholder SVG for the image surface (an explicit opt-in alternative to the PNG placeholder). */
|
|
55
|
-
export function svgPlaceholder(
|
|
55
|
+
export function svgPlaceholder(required, optional = {}) {
|
|
56
|
+
const ctx = { ...required, ...optional };
|
|
56
57
|
const [w, h] = aspectToBox(ctx.aspect, 800);
|
|
57
58
|
const safe = (s) => String(s || '')
|
|
58
59
|
.replace(/&/g, '&')
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import type { RequiredArgs, OptionalArgs } from '../../args.js';
|
|
1
2
|
/**
|
|
2
3
|
* The media dispatch engine's public types. Generalized from Open Design's
|
|
3
4
|
* `apps/daemon/src/media/index.ts` `generateMedia` — the real multi-vendor
|
|
4
5
|
* REST dispatch engine, not the substrate (`policy.ts`/`staging.ts`/
|
|
5
6
|
* `task-store.ts`/`video-request.ts`/`capability-registry.ts`) already
|
|
6
|
-
* ported. See `
|
|
7
|
+
* ported. See `archived provenance ledger` for the full port record: what's ported in
|
|
7
8
|
* this pass vs explicitly deferred.
|
|
8
9
|
*
|
|
9
|
-
* Boundary redesign vs the origin (not a verbatim lift — see
|
|
10
|
+
* Boundary redesign vs the origin (not a verbatim lift — see archived provenance ledger):
|
|
10
11
|
* the origin resolves an OD `projectId` into a filesystem path and writes
|
|
11
12
|
* generated bytes there directly (`ensureProject`/`sanitizeName`/
|
|
12
13
|
* `mkdir`/write). Jini's kernel has no `Project` concept at all (locked
|
|
@@ -17,9 +18,11 @@
|
|
|
17
18
|
* (`resolveProjectImage`); here the caller resolves any reference image to
|
|
18
19
|
* a data URL before calling, exactly matching the convention `video-
|
|
19
20
|
* request.ts`'s `VideoBuildInput.imageRef` already established for this
|
|
20
|
-
* package —
|
|
21
|
-
*
|
|
21
|
+
* package — generation dispatch performs no filesystem I/O. The separate
|
|
22
|
+
* filesystem-backed `AttachmentStaging` adapter copies and prunes local
|
|
23
|
+
* attachments; provider dispatch performs network I/O through its transport.
|
|
22
24
|
*/
|
|
25
|
+
import type { MediaOutboundOptions } from './outbound.js';
|
|
23
26
|
import type { AudioKind, MediaSurface } from '../types.js';
|
|
24
27
|
/** Per-provider credentials a host resolves however it wants (env vars, a secrets manager, a config file, ...). This engine never reads `process.env` itself — see `resolveProviderCredentialsFromEnv` in `credentials.ts` for an opt-in reference resolver a host may use to build this map. */
|
|
25
28
|
export interface ProviderCredentials {
|
|
@@ -27,9 +30,10 @@ export interface ProviderCredentials {
|
|
|
27
30
|
readonly baseUrl?: string;
|
|
28
31
|
readonly model?: string;
|
|
29
32
|
}
|
|
30
|
-
/**
|
|
33
|
+
/** Legacy fetch dispatcher shape. Network dispatch refuses it because it can replace the
|
|
34
|
+
* DNS-pinned socket; configure pooling/timeouts on the injected guarded `httpClient` instead. */
|
|
31
35
|
export type MediaGenerationRequestInit = Pick<RequestInit, 'dispatcher'>;
|
|
32
|
-
/** A reference image already resolved to a base64 data URL —
|
|
36
|
+
/** A reference image already resolved to a base64 data URL — generation dispatch performs no filesystem I/O (see `video-request.ts`'s `VideoBuildInput.imageRef` for the same convention). The separate filesystem staging adapter may copy local files before dispatch. */
|
|
33
37
|
export interface MediaImageReference {
|
|
34
38
|
readonly dataUrl: string;
|
|
35
39
|
}
|
|
@@ -48,10 +52,10 @@ export interface MediaGenerationRequest {
|
|
|
48
52
|
readonly loop?: boolean;
|
|
49
53
|
/**
|
|
50
54
|
* ElevenLabs SFX's "how closely should generation follow the prompt"
|
|
51
|
-
* dial (0-1).
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
+
* dial (0-1). `buildRenderContext` validates it (see `context.ts`), then
|
|
56
|
+
* the ElevenLabs SFX renderer sends it as `prompt_influence`, clamped
|
|
57
|
+
* to [0, 1] and defaulting to 0.3 when omitted. Context validation and
|
|
58
|
+
* the vendor request body are both directly tested.
|
|
55
59
|
*/
|
|
56
60
|
readonly promptInfluence?: number;
|
|
57
61
|
/** Primary reference image for i2v / image-edit flows. */
|
|
@@ -87,7 +91,7 @@ export interface MediaGenerationResult {
|
|
|
87
91
|
/** Non-fatal notices (e.g. a requested `length`/`duration` was clamped to the nearest allowed value). */
|
|
88
92
|
readonly warnings: readonly string[];
|
|
89
93
|
}
|
|
90
|
-
export interface MediaDispatchEngineOptions {
|
|
94
|
+
export interface MediaDispatchEngineOptions extends MediaOutboundOptions {
|
|
91
95
|
/** Per-provider credentials, keyed by provider id (see `providers.ts`'s `MEDIA_PROVIDERS` for valid ids). */
|
|
92
96
|
readonly credentials?: Readonly<Record<string, ProviderCredentials>>;
|
|
93
97
|
/**
|
|
@@ -102,7 +106,7 @@ export interface MediaDispatchEngineOptions {
|
|
|
102
106
|
readonly allowStubFallback?: boolean;
|
|
103
107
|
}
|
|
104
108
|
export interface MediaDispatchEngine {
|
|
105
|
-
generate(
|
|
109
|
+
generate(required: RequiredArgs<MediaGenerationRequest>, optional?: OptionalArgs<MediaGenerationRequest>): Promise<MediaGenerationResult>;
|
|
106
110
|
}
|
|
107
111
|
/** Internal: the pure shape rendered by `render*` provider functions, before the engine attaches `providerId`/`usedStubFallback`/`warnings`. */
|
|
108
112
|
export interface RenderResult {
|
|
@@ -111,7 +115,7 @@ export interface RenderResult {
|
|
|
111
115
|
readonly suggestedExt?: string;
|
|
112
116
|
}
|
|
113
117
|
/** Internal: per-generation context threaded into every `render*` provider function. */
|
|
114
|
-
export interface RenderContext {
|
|
118
|
+
export interface RenderContext extends MediaOutboundOptions {
|
|
115
119
|
readonly surface: MediaSurface;
|
|
116
120
|
readonly model: string;
|
|
117
121
|
readonly wireModel: string;
|
|
@@ -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
|
}
|