@jini-ai/integrations 0.4.1 → 0.4.3
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 +13 -0
- package/dist/api-connections/access-token.d.ts +9 -0
- package/dist/api-connections/access-token.js +92 -0
- package/dist/api-connections/account-actions.d.ts +40 -0
- package/dist/api-connections/account-actions.js +110 -0
- package/dist/api-connections/attempt-state.d.ts +28 -0
- package/dist/api-connections/attempt-state.js +73 -0
- package/dist/api-connections/authorization.d.ts +45 -0
- package/dist/api-connections/authorization.js +120 -0
- package/dist/api-connections/deps.d.ts +41 -0
- package/dist/api-connections/deps.js +13 -0
- package/dist/api-connections/descriptor.d.ts +6 -0
- package/dist/api-connections/descriptor.js +111 -0
- package/dist/api-connections/errors.d.ts +23 -0
- package/dist/api-connections/errors.js +24 -0
- package/dist/api-connections/finish-authorization.d.ts +24 -0
- package/dist/api-connections/finish-authorization.js +117 -0
- package/dist/api-connections/index.d.ts +18 -0
- package/dist/api-connections/index.js +10 -0
- package/dist/api-connections/install-credential.d.ts +19 -0
- package/dist/api-connections/install-credential.js +12 -0
- package/dist/api-connections/keys.d.ts +27 -0
- package/dist/api-connections/keys.js +22 -0
- package/dist/api-connections/ports.d.ts +73 -0
- package/dist/api-connections/ports.js +2 -0
- package/dist/api-connections/records.d.ts +27 -0
- package/dist/api-connections/records.js +52 -0
- package/dist/api-connections/request-checks.d.ts +18 -0
- package/dist/api-connections/request-checks.js +67 -0
- package/dist/api-connections/service.d.ts +25 -0
- package/dist/api-connections/service.js +26 -0
- package/dist/api-connections/status.d.ts +28 -0
- package/dist/api-connections/status.js +36 -0
- package/dist/api-connections/token-store/errors.d.ts +20 -0
- package/dist/api-connections/token-store/errors.js +38 -0
- package/dist/api-connections/token-store/index.d.ts +6 -0
- package/dist/api-connections/token-store/index.js +6 -0
- package/dist/api-connections/token-store/record.d.ts +69 -0
- package/dist/api-connections/token-store/record.js +97 -0
- package/dist/api-connections/token-store/vault-token-store.d.ts +26 -0
- package/dist/api-connections/token-store/vault-token-store.js +215 -0
- package/dist/api-connections/types.d.ts +101 -0
- package/dist/api-connections/types.js +9 -0
- package/dist/credentialed-http/auth-schemes.js +8 -4
- package/dist/credentialed-http/credentialed-request.js +47 -77
- package/dist/credentialed-http/response-redaction.d.ts +5 -0
- package/dist/credentialed-http/response-redaction.js +62 -0
- package/dist/media-providers/catalog.d.ts +3 -1
- package/dist/media-providers/catalog.js +3 -1
- package/dist/media-providers/dispatch/async-operation-store.d.ts +31 -0
- package/dist/media-providers/dispatch/async-operation-store.js +75 -37
- package/dist/media-providers/dispatch/builtin-vendors.d.ts +1 -1
- package/dist/media-providers/dispatch/context.js +10 -2
- package/dist/media-providers/dispatch/credentials.d.ts +1 -1
- package/dist/media-providers/dispatch/credentials.js +3 -3
- package/dist/media-providers/dispatch/engine.d.ts +6 -3
- package/dist/media-providers/dispatch/engine.js +102 -109
- package/dist/media-providers/dispatch/index.d.ts +4 -2
- package/dist/media-providers/dispatch/index.js +3 -1
- package/dist/media-providers/dispatch/media-provider-registry.d.ts +62 -0
- package/dist/media-providers/dispatch/media-provider-registry.js +141 -0
- package/dist/media-providers/dispatch/node.d.ts +13 -0
- package/dist/media-providers/dispatch/node.js +24 -0
- package/dist/media-providers/dispatch/openai-compatible.d.ts +1 -1
- package/dist/media-providers/dispatch/openai-compatible.js +90 -87
- package/dist/media-providers/dispatch/operation-runtime.js +116 -89
- package/dist/media-providers/dispatch/outbound.d.ts +8 -4
- package/dist/media-providers/dispatch/outbound.js +27 -26
- package/dist/media-providers/dispatch/providers/aihubmix.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/aihubmix.js +61 -56
- package/dist/media-providers/dispatch/providers/custom-image.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/elevenlabs.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/fishaudio.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/grok.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.js +53 -49
- package/dist/media-providers/dispatch/providers/imagerouter.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/imagerouter.js +11 -24
- package/dist/media-providers/dispatch/providers/minimax.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/nanobanana.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/nanobanana.js +22 -30
- package/dist/media-providers/dispatch/providers/openai.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/openai.js +51 -47
- package/dist/media-providers/dispatch/providers/openrouter.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/openrouter.js +52 -37
- package/dist/media-providers/dispatch/providers/senseaudio.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/senseaudio.js +47 -28
- package/dist/media-providers/dispatch/providers/volcengine.d.ts +1 -1
- package/dist/media-providers/dispatch/response-parsers.js +37 -21
- package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts +35 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.js +13 -32
- package/dist/media-providers/dispatch/ssrf-guard.d.ts +3 -2
- package/dist/media-providers/dispatch/ssrf-guard.js +6 -5
- package/dist/media-providers/dispatch/types.d.ts +76 -2
- package/dist/media-providers/dispatch/vendor-adapter.d.ts +2 -43
- package/dist/media-providers/dispatch/vendor-adapter.js +2 -2
- package/dist/media-providers/dispatch/vendor-registry-core.d.ts +24 -0
- package/dist/media-providers/dispatch/vendor-registry-core.js +34 -0
- package/dist/media-providers/dispatch/vendor-registry.d.ts +10 -36
- package/dist/media-providers/dispatch/vendor-registry.js +14 -42
- package/dist/media-providers/policy.js +25 -17
- package/dist/media-providers/providers.d.ts +39 -0
- package/dist/media-providers/providers.js +50 -18
- package/dist/media-providers/sqlite-driver.adapter.d.ts +4 -0
- package/dist/media-providers/sqlite-driver.adapter.js +5 -0
- package/dist/media-providers/sqlite-task-store.d.ts +50 -2
- package/dist/media-providers/sqlite-task-store.js +20 -84
- package/dist/media-providers/staging.js +77 -58
- package/dist/media-providers/task-lifecycle.d.ts +33 -0
- package/dist/media-providers/task-lifecycle.js +124 -0
- package/dist/media-providers/task-store.js +8 -86
- package/dist/media-providers/ui-defaults.d.ts +10 -0
- package/dist/media-providers/ui-defaults.js +167 -0
- package/dist/media-providers/video-request.js +112 -90
- package/dist/webhooks/delivery.d.ts +14 -0
- package/dist/webhooks/delivery.js +41 -10
- package/dist/webhooks/index.d.ts +1 -0
- package/dist/webhooks/index.js +1 -0
- package/dist/webhooks/ports.d.ts +23 -0
- package/dist/webhooks/subscriptions.d.ts +1 -1
- package/dist/webhooks/subscriptions.js +5 -1
- package/dist/webhooks/worker.d.ts +83 -0
- package/dist/webhooks/worker.js +105 -0
- package/package.json +35 -7
- package/dist/composio/bounded-data.d.ts +0 -36
- package/dist/composio/bounded-data.js +0 -181
- package/dist/composio/catalog.d.ts +0 -147
- package/dist/composio/catalog.js +0 -126
- package/dist/composio/composio-config.d.ts +0 -42
- package/dist/composio/composio-config.js +0 -145
- package/dist/composio/composio-descriptions.d.ts +0 -16
- package/dist/composio/composio-descriptions.js +0 -766
- package/dist/composio/composio.d.ts +0 -364
- package/dist/composio/composio.js +0 -1902
- package/dist/composio/errors.d.ts +0 -15
- package/dist/composio/errors.js +0 -16
- package/dist/composio/file-lock.d.ts +0 -13
- package/dist/composio/file-lock.js +0 -92
- package/dist/composio/index.d.ts +0 -18
- package/dist/composio/index.js +0 -7
- package/dist/composio/json-schema.d.ts +0 -93
- package/dist/composio/json-schema.js +0 -498
- package/dist/composio/output-protection.d.ts +0 -32
- package/dist/composio/output-protection.js +0 -105
- package/dist/composio/service.d.ts +0 -181
- package/dist/composio/service.js +0 -758
|
@@ -95,7 +95,7 @@ const senseAudioTTSAdapter = {
|
|
|
95
95
|
parseResponse: createHexEnvelopeAudioParser({ errorTag: 'senseaudio tts', providerId: 'senseaudio' }),
|
|
96
96
|
};
|
|
97
97
|
export async function renderSenseAudioTTS({ ctx, credentials }) {
|
|
98
|
-
return dispatchVendorRequest({ adapter: senseAudioTTSAdapter, ctx
|
|
98
|
+
return dispatchVendorRequest({ adapter: senseAudioTTSAdapter, ctx, credentials });
|
|
99
99
|
}
|
|
100
100
|
/** SenseAudio's image gateway rejects non-standard pixel sizes with a 400; keep this mapping in sync with any other SenseAudio-image call site a future host adds. */
|
|
101
101
|
function senseAudioImageSize(aspect) {
|
|
@@ -117,7 +117,7 @@ const senseAudioImageAdapter = {
|
|
|
117
117
|
const promptRaw = (ctx.prompt && ctx.prompt.trim()) || 'A high-quality reference image.';
|
|
118
118
|
// SenseAudio rejects prompts over 2000 chars with a 4xx; trim
|
|
119
119
|
// defensively so a verbose caller doesn't dead-end the generation.
|
|
120
|
-
const prompt = promptRaw.
|
|
120
|
+
const prompt = promptRaw.slice(0, SENSEAUDIO_IMAGE_PROMPT_LIMIT);
|
|
121
121
|
const size = senseAudioImageSize(ctx.aspect);
|
|
122
122
|
const reference = ctx.imageRef?.dataUrl;
|
|
123
123
|
const body = {
|
|
@@ -149,31 +149,8 @@ const senseAudioImageAdapter = {
|
|
|
149
149
|
if (!resp.ok) {
|
|
150
150
|
throw new Error(`senseaudio image ${resp.status}: ${truncate(respText, 240)}`);
|
|
151
151
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
data = JSON.parse(respText);
|
|
155
|
-
}
|
|
156
|
-
catch {
|
|
157
|
-
throw new Error(`senseaudio image non-JSON: ${truncate(respText, 200)}`);
|
|
158
|
-
}
|
|
159
|
-
if (data.base_resp && data.base_resp.status_code !== 0) {
|
|
160
|
-
throw new Error(`senseaudio image api error ${data.base_resp.status_code}: ${data.base_resp.status_msg || 'unknown'}`);
|
|
161
|
-
}
|
|
162
|
-
if (typeof data.error_message === 'string' && data.error_message) {
|
|
163
|
-
throw new Error(`senseaudio image api error: ${data.error_message}`);
|
|
164
|
-
}
|
|
165
|
-
const url = typeof data.url === 'string' ? data.url : '';
|
|
166
|
-
if (!url) {
|
|
167
|
-
throw new Error('senseaudio image response missing url');
|
|
168
|
-
}
|
|
169
|
-
const imgResp = await assertAndFetchExternalAsset({ url: url }, { ...ctx, init: withRequestInit(ctx) });
|
|
170
|
-
if (!imgResp.ok) {
|
|
171
|
-
throw new Error(`senseaudio image fetch ${imgResp.status}`);
|
|
172
|
-
}
|
|
173
|
-
const bytes = Buffer.from(await imgResp.arrayBuffer());
|
|
174
|
-
if (bytes.length === 0) {
|
|
175
|
-
throw new Error('senseaudio image fetch returned zero bytes');
|
|
176
|
-
}
|
|
152
|
+
const url = extractSenseAudioImageUrl({ respText });
|
|
153
|
+
const bytes = await downloadSenseAudioImage({ url, ctx });
|
|
177
154
|
return {
|
|
178
155
|
bytes,
|
|
179
156
|
providerNote: `senseaudio/${ctx.wireModel} · ${request.meta.size}${request.meta.hasReference ? ' · i2i' : ''} · ${bytes.length} bytes`,
|
|
@@ -181,8 +158,50 @@ const senseAudioImageAdapter = {
|
|
|
181
158
|
};
|
|
182
159
|
},
|
|
183
160
|
};
|
|
161
|
+
/**
|
|
162
|
+
* Parses an OK image envelope and returns its `url`. Two independent
|
|
163
|
+
* failure-signaling paths are honored in order: a non-zero (or absent)
|
|
164
|
+
* `base_resp.status_code`, then a non-empty `error_message`.
|
|
165
|
+
* @throws Error — non-JSON body, either API-error path, or a missing/non-string url.
|
|
166
|
+
*/
|
|
167
|
+
function extractSenseAudioImageUrl({ respText }) {
|
|
168
|
+
let data;
|
|
169
|
+
try {
|
|
170
|
+
data = JSON.parse(respText);
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
throw new Error(`senseaudio image non-JSON: ${truncate(respText, 200)}`);
|
|
174
|
+
}
|
|
175
|
+
if (data.base_resp && data.base_resp.status_code !== 0) {
|
|
176
|
+
throw new Error(`senseaudio image api error ${data.base_resp.status_code}: ${data.base_resp.status_msg || 'unknown'}`);
|
|
177
|
+
}
|
|
178
|
+
if (typeof data.error_message === 'string' && data.error_message) {
|
|
179
|
+
throw new Error(`senseaudio image api error: ${data.error_message}`);
|
|
180
|
+
}
|
|
181
|
+
if (typeof data.url !== 'string' || !data.url) {
|
|
182
|
+
throw new Error('senseaudio image response missing url');
|
|
183
|
+
}
|
|
184
|
+
return data.url;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Downloads the generated image through the SSRF guard (the url is
|
|
188
|
+
* attacker-controllable inside an otherwise-successful response — see the
|
|
189
|
+
* module doc).
|
|
190
|
+
* @throws Error — the guard refuses the url, the download is not OK, or it is empty.
|
|
191
|
+
*/
|
|
192
|
+
async function downloadSenseAudioImage({ url, ctx }) {
|
|
193
|
+
const imgResp = await assertAndFetchExternalAsset({ url }, { ...ctx, init: withRequestInit(ctx) });
|
|
194
|
+
if (!imgResp.ok) {
|
|
195
|
+
throw new Error(`senseaudio image fetch ${imgResp.status}`);
|
|
196
|
+
}
|
|
197
|
+
const bytes = Buffer.from(await imgResp.arrayBuffer());
|
|
198
|
+
if (bytes.length === 0) {
|
|
199
|
+
throw new Error('senseaudio image fetch returned zero bytes');
|
|
200
|
+
}
|
|
201
|
+
return bytes;
|
|
202
|
+
}
|
|
184
203
|
export async function renderSenseAudioImage({ ctx, credentials }) {
|
|
185
|
-
return dispatchVendorRequest({ adapter: senseAudioImageAdapter, ctx
|
|
204
|
+
return dispatchVendorRequest({ adapter: senseAudioImageAdapter, ctx, credentials });
|
|
186
205
|
}
|
|
187
206
|
/** Explicit composition: importing a renderer never changes another module's registry. */
|
|
188
207
|
export function registerVendorAdapters({ registry }, _optional = {}) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ProviderCredentials, RenderContext, RenderResult } from '../types.js';
|
|
2
|
-
import type { VendorAdapterRegistry } from '../vendor-registry.js';
|
|
2
|
+
import type { VendorAdapterRegistry } from '../vendor-registry-core.js';
|
|
3
3
|
export declare function renderVolcengineImage({ ctx, credentials }: {
|
|
4
4
|
ctx: RenderContext;
|
|
5
5
|
credentials: ProviderCredentials;
|
|
@@ -72,31 +72,15 @@ export function createRawBytesParser(options) {
|
|
|
72
72
|
* https://help.aliyun.com/zh/model-studio/minimax-synchronous-speech-synthesis-api.
|
|
73
73
|
*/
|
|
74
74
|
export function createHexEnvelopeAudioParser(options) {
|
|
75
|
+
const { errorTag } = options;
|
|
75
76
|
return async ({ resp, request }) => {
|
|
76
77
|
const respText = await resp.text();
|
|
77
78
|
if (!resp.ok) {
|
|
78
|
-
throw new Error(`${
|
|
79
|
+
throw new Error(`${errorTag} ${resp.status}: ${truncate(respText, 240)}`);
|
|
79
80
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
throw new Error(`${options.errorTag} non-JSON: ${truncate(respText, 200)}`);
|
|
86
|
-
}
|
|
87
|
-
if (data.base_resp && data.base_resp.status_code !== 0) {
|
|
88
|
-
throw new Error(`${options.errorTag} api error ${data.base_resp.status_code}: ${data.base_resp.status_msg || 'unknown'}`);
|
|
89
|
-
}
|
|
90
|
-
const hex = data.data?.audio;
|
|
91
|
-
if (typeof hex !== 'string' || !hex) {
|
|
92
|
-
throw new Error(`${options.errorTag} response missing data.audio`);
|
|
93
|
-
}
|
|
94
|
-
const bytes = Buffer.from(hex, 'hex');
|
|
95
|
-
if (bytes.length === 0) {
|
|
96
|
-
throw new Error(`${options.errorTag} decoded zero bytes`);
|
|
97
|
-
}
|
|
98
|
-
const audioLength = data.extra_info?.audio_length;
|
|
99
|
-
const seconds = audioLength ? Math.round(audioLength / 100) / 10 : '?';
|
|
81
|
+
const data = parseHexEnvelopeBody({ respText, errorTag });
|
|
82
|
+
const bytes = decodeHexEnvelopeAudio({ data, errorTag });
|
|
83
|
+
const seconds = formatAudioSeconds(data.extra_info?.audio_length);
|
|
100
84
|
return {
|
|
101
85
|
bytes,
|
|
102
86
|
providerNote: `${options.providerId}/${request.meta.wireModel} · ${request.meta.voiceId} · ${seconds}s · ${bytes.length} bytes`,
|
|
@@ -104,4 +88,36 @@ export function createHexEnvelopeAudioParser(options) {
|
|
|
104
88
|
};
|
|
105
89
|
};
|
|
106
90
|
}
|
|
91
|
+
/** Parses an OK hex-envelope body and rejects a non-JSON body or a logical (`base_resp.status_code !== 0`) failure. */
|
|
92
|
+
function parseHexEnvelopeBody(required) {
|
|
93
|
+
const { respText, errorTag } = required;
|
|
94
|
+
let data;
|
|
95
|
+
try {
|
|
96
|
+
data = JSON.parse(respText);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
throw new Error(`${errorTag} non-JSON: ${truncate(respText, 200)}`);
|
|
100
|
+
}
|
|
101
|
+
if (data.base_resp && data.base_resp.status_code !== 0) {
|
|
102
|
+
throw new Error(`${errorTag} api error ${data.base_resp.status_code}: ${data.base_resp.status_msg || 'unknown'}`);
|
|
103
|
+
}
|
|
104
|
+
return data;
|
|
105
|
+
}
|
|
106
|
+
/** Decodes `data.audio` hex into bytes, refusing a missing/non-string/empty payload or one that decodes to zero bytes. */
|
|
107
|
+
function decodeHexEnvelopeAudio(required) {
|
|
108
|
+
const { data, errorTag } = required;
|
|
109
|
+
const hex = data.data?.audio;
|
|
110
|
+
if (typeof hex !== 'string' || !hex) {
|
|
111
|
+
throw new Error(`${errorTag} response missing data.audio`);
|
|
112
|
+
}
|
|
113
|
+
const bytes = Buffer.from(hex, 'hex');
|
|
114
|
+
if (bytes.length === 0) {
|
|
115
|
+
throw new Error(`${errorTag} decoded zero bytes`);
|
|
116
|
+
}
|
|
117
|
+
return bytes;
|
|
118
|
+
}
|
|
119
|
+
/** `audio_length` milliseconds rounded to tenths of a second; `'?'` when absent (or 0), matching both vendors' own formatting. */
|
|
120
|
+
function formatAudioSeconds(audioLength) {
|
|
121
|
+
return audioLength ? Math.round(audioLength / 100) / 10 : '?';
|
|
122
|
+
}
|
|
107
123
|
//# sourceMappingURL=response-parsers.js.map
|
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createSqliteAsyncOperationStore` — the durable `AsyncOperationStore` adapter.
|
|
3
|
+
*
|
|
4
|
+
* `async-operation-store.ts` ships only `createInMemoryAsyncOperationStore`, so a process restart
|
|
5
|
+
* loses every in-flight submit-then-poll operation despite the store's own module doc describing
|
|
6
|
+
* it as the row that makes crash safety "fall out for free" — that guarantee only holds once a
|
|
7
|
+
* real durable adapter exists. This follows `sqlite-task-store.ts`'s established convention in
|
|
8
|
+
* this same package exactly, rather than inventing a parallel one: `new Database(dbPath)`,
|
|
9
|
+
* `db.pragma('journal_mode = WAL')`, `CREATE TABLE IF NOT EXISTS` (idempotent — reopening the same
|
|
10
|
+
* file resumes from whatever was durably committed), `db.transaction()` for atomic multi-statement
|
|
11
|
+
* writes, every public method still `Promise`-returning despite `better-sqlite3` being fully
|
|
12
|
+
* synchronous under the hood, a `close(): Promise<void>` addition beyond the port interface, and
|
|
13
|
+
* `better-sqlite3` dynamically imported (never at module scope) so a consumer wanting only the
|
|
14
|
+
* in-memory reference store never pays for loading the native binary.
|
|
15
|
+
*
|
|
16
|
+
* One deliberate departure from `sqlite-task-store.ts`'s own precedent: that file hand-copies its
|
|
17
|
+
* source port's transition table into a local `ALLOWED_TRANSITIONS` constant. This file instead
|
|
18
|
+
* imports `TERMINAL_STATUSES` and `assertTransition` from `async-operation-store.ts` — a second
|
|
19
|
+
* hand-maintained copy of this store's lease/terminal-status machinery is exactly the kind of
|
|
20
|
+
* mirror that drifts silently the next time the source of truth changes, and this store's lifecycle
|
|
21
|
+
* (five statuses, a `never leaves 'unknown'`/`'succeeded'`/`'failed'` terminal set, lease fencing)
|
|
22
|
+
* is materially more failure-sensitive than `MediaTaskStore`'s.
|
|
23
|
+
*
|
|
24
|
+
* `claimDue` is the one place this adapter is NOT a row-by-row translation of the in-memory
|
|
25
|
+
* reference: it is a single `UPDATE ... WHERE id IN (SELECT ... ORDER BY ... LIMIT ?) RETURNING *`
|
|
26
|
+
* statement — exactly the "single conditional UPDATE ... RETURNING" the in-memory store's own doc
|
|
27
|
+
* comment already promises a durable adapter would be. `RETURNING` needs the bundled
|
|
28
|
+
* `better-sqlite3` to embed SQLite >= 3.35; verified against this repo's pinned version before
|
|
29
|
+
* writing this file.
|
|
30
|
+
*/
|
|
31
|
+
import type { SqliteSyncOpener } from '@jini-ai/db/sqlite';
|
|
1
32
|
import type { AsyncOperationStore } from './async-operation-store.js';
|
|
2
33
|
/** An `AsyncOperationStore` backed by a `better-sqlite3` database, plus a `close()` to release the file handle. */
|
|
3
34
|
export interface SqliteAsyncOperationStore extends AsyncOperationStore {
|
|
@@ -12,7 +43,10 @@ export interface SqliteAsyncOperationStore extends AsyncOperationStore {
|
|
|
12
43
|
* operation exactly as it was left, and `recoverAfterRestart`/`reconcileOnBoot` can then release
|
|
13
44
|
* dead leases and expire blown deadlines.
|
|
14
45
|
*/
|
|
15
|
-
export declare function createSqliteAsyncOperationStore({ dbPath }: {
|
|
46
|
+
export declare function createSqliteAsyncOperationStore({ dbPath, open: injectedOpen }: {
|
|
16
47
|
dbPath: string;
|
|
48
|
+
open?: SqliteSyncOpener;
|
|
49
|
+
}, options?: {
|
|
50
|
+
open?: SqliteSyncOpener;
|
|
17
51
|
}): Promise<SqliteAsyncOperationStore>;
|
|
18
52
|
//# sourceMappingURL=sqlite-async-operation-store.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { loadMediaSqliteOpener } from '../sqlite-driver.adapter.js';
|
|
2
|
+
import { ASYNC_OPERATION_SCHEMA_VERSION, ASYNC_OPERATION_STATUSES, assertValidCreateInput, hydrateAsyncOperationRecord, isFencedOut, mergeAsyncOperationPatch, TERMINAL_STATUSES, } from './async-operation-store.js';
|
|
2
3
|
/**
|
|
3
4
|
* The non-terminal ("live") status values — `ASYNC_OPERATION_STATUSES` minus `TERMINAL_STATUSES`,
|
|
4
5
|
* built once so this file cannot itself drift from either source set. Used as a positive
|
|
@@ -44,9 +45,9 @@ function rowToOperation(row) {
|
|
|
44
45
|
* operation exactly as it was left, and `recoverAfterRestart`/`reconcileOnBoot` can then release
|
|
45
46
|
* dead leases and expire blown deadlines.
|
|
46
47
|
*/
|
|
47
|
-
export async function createSqliteAsyncOperationStore({ dbPath }) {
|
|
48
|
-
const
|
|
49
|
-
const db =
|
|
48
|
+
export async function createSqliteAsyncOperationStore({ dbPath, open: injectedOpen }, options = {}) {
|
|
49
|
+
const open = injectedOpen ?? options.open ?? await loadMediaSqliteOpener({});
|
|
50
|
+
const db = open(dbPath, {});
|
|
50
51
|
db.pragma('journal_mode = WAL');
|
|
51
52
|
db.exec(`
|
|
52
53
|
CREATE TABLE IF NOT EXISTS jini_async_operations (
|
|
@@ -112,23 +113,18 @@ export async function createSqliteAsyncOperationStore({ dbPath }) {
|
|
|
112
113
|
WHERE status IN (${LIVE_PLACEHOLDERS}) AND lease_owner IS NOT NULL AND (lease_expires_at IS NULL OR lease_expires_at <= ?)
|
|
113
114
|
RETURNING *
|
|
114
115
|
`);
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
/** A nullable JSON column: `null`/`undefined` store SQL NULL, anything else its JSON text. */
|
|
117
|
+
function jsonOrNull(value) {
|
|
118
|
+
return value == null ? null : JSON.stringify(value);
|
|
117
119
|
}
|
|
118
120
|
const createTxn = db.transaction((input) => {
|
|
119
121
|
if (getStmt.get(input.id)) {
|
|
120
122
|
throw new Error(`async operation "${input.id}" already exists`);
|
|
121
123
|
}
|
|
122
|
-
|
|
123
|
-
throw new RangeError(`Invalid maxAttempts: ${input.maxAttempts} must be a finite number >= 1`);
|
|
124
|
-
}
|
|
125
|
-
if (!Number.isFinite(input.deadlineAt)) {
|
|
126
|
-
throw new RangeError(`Invalid deadlineAt: ${input.deadlineAt} must be a finite epoch-ms timestamp`);
|
|
127
|
-
}
|
|
128
|
-
assertNoCredentialMaterial({ state: input.state });
|
|
124
|
+
assertValidCreateInput({ input });
|
|
129
125
|
const now = Date.now();
|
|
130
126
|
const status = input.status ?? 'submitted';
|
|
131
|
-
insertStmt.run(input.id, input.providerId, input.routeKey, input.ownerRef, status, 0, input.maxAttempts, input.deadlineAt, input.nextPollAt ?? now,
|
|
127
|
+
insertStmt.run(input.id, input.providerId, input.routeKey, input.ownerRef, status, 0, input.maxAttempts, input.deadlineAt, input.nextPollAt ?? now, jsonOrNull(input.state), ASYNC_OPERATION_SCHEMA_VERSION, now, now);
|
|
132
128
|
return rowToOperation(getStmt.get(input.id));
|
|
133
129
|
});
|
|
134
130
|
const updateTxn = db.transaction((id, patch, options) => {
|
|
@@ -138,25 +134,10 @@ export async function createSqliteAsyncOperationStore({ dbPath }) {
|
|
|
138
134
|
const existing = rowToOperation(existingRow);
|
|
139
135
|
// Fenced exactly like `releaseLease` and the in-memory store: a caller writing against a
|
|
140
136
|
// lease it no longer holds gets the row back unchanged, not an overwrite.
|
|
141
|
-
if (
|
|
137
|
+
if (isFencedOut({ existing, options }))
|
|
142
138
|
return existing;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
assertNoCredentialMaterial({ state: patch.state });
|
|
146
|
-
const status = patch.status ?? existing.status;
|
|
147
|
-
assertTransition(existing.status, status);
|
|
148
|
-
const next = {
|
|
149
|
-
status,
|
|
150
|
-
attempts: patch.attempts ?? existing.attempts,
|
|
151
|
-
nextPollAt: patch.nextPollAt ?? existing.nextPollAt,
|
|
152
|
-
state: 'state' in patch ? (patch.state ?? null) : existing.state,
|
|
153
|
-
result: 'result' in patch ? (patch.result ?? null) : existing.result,
|
|
154
|
-
error: 'error' in patch ? (patch.error ?? null) : existing.error,
|
|
155
|
-
leaseOwner: 'leaseOwner' in patch ? (patch.leaseOwner ?? null) : existing.leaseOwner,
|
|
156
|
-
leaseExpiresAt: 'leaseExpiresAt' in patch ? (patch.leaseExpiresAt ?? null) : existing.leaseExpiresAt,
|
|
157
|
-
updatedAt: Date.now(),
|
|
158
|
-
};
|
|
159
|
-
updateStmt.run(next.status, next.attempts, next.nextPollAt, stateJson(next.state), next.result === null ? null : JSON.stringify(next.result), next.error === null ? null : JSON.stringify(next.error), next.leaseOwner, next.leaseExpiresAt, next.updatedAt, id);
|
|
139
|
+
const next = mergeAsyncOperationPatch({ existing, patch }, { now: Date.now() });
|
|
140
|
+
updateStmt.run(next.status, next.attempts, next.nextPollAt, jsonOrNull(next.state), jsonOrNull(next.result), jsonOrNull(next.error), next.leaseOwner, next.leaseExpiresAt, next.updatedAt, id);
|
|
160
141
|
return rowToOperation(getStmt.get(id));
|
|
161
142
|
});
|
|
162
143
|
const claimDueTxn = db.transaction((options) => {
|
|
@@ -52,12 +52,13 @@ export declare function assertExternalAssetUrl({ rawUrl }: {
|
|
|
52
52
|
* forgotten at a call site); the forced `redirect` is spread last so it
|
|
53
53
|
* overrides any value the caller passed in `init`. Callers keep their own
|
|
54
54
|
* `!resp.ok` HTTP-status handling.
|
|
55
|
-
*
|
|
55
|
+
* `lookup` is retained for source compatibility; DNS configuration belongs on httpClient.
|
|
56
|
+
* @throws URL/policy refusals, a missing client, and DNS/transport failures before unsafe I/O.
|
|
56
57
|
* @complexity O(a + b) for a DNS answers and b bounded decoded asset bytes.
|
|
57
58
|
*/
|
|
58
59
|
export declare function assertAndFetchExternalAsset({ url }: {
|
|
59
60
|
url: string;
|
|
60
|
-
}, { init, lookup, ...outbound }?: MediaOutboundOptions & {
|
|
61
|
+
}, { init, lookup: _lookup, ...outbound }?: MediaOutboundOptions & {
|
|
61
62
|
init?: RequestInit | undefined;
|
|
62
63
|
lookup?: DnsLookupFn | undefined;
|
|
63
64
|
}): Promise<Response>;
|
|
@@ -26,7 +26,7 @@
|
|
|
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. The
|
|
29
|
+
* path and is not ported. The explicit Node adapter defaults to strict asset downloads. Only its
|
|
30
30
|
* `allowPrivateNetwork: true` development capability or a host-supplied
|
|
31
31
|
* policy-enforcing client can change the network policy; a host
|
|
32
32
|
* that wants an operator-configurable internal-host allowlist for its own
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
import { isLoopbackApiHost, isBlockedExternalApiHostname } from '@jini-ai/platform/net';
|
|
41
41
|
import { promises as dnsPromises } from 'node:dns';
|
|
42
42
|
import { FETCH_TIMEOUT_MS } from '@jini-ai/platform/fetch-with-timeout';
|
|
43
|
-
import { defaultMediaOutboundMessages, fetchMediaOutbound } from './outbound.js';
|
|
43
|
+
import { defaultMediaOutboundMessages, fetchMediaOutbound, requireMediaHttpClient } from './outbound.js';
|
|
44
44
|
const defaultDnsLookup = async ({ hostname }) => {
|
|
45
45
|
const result = await dnsPromises.lookup(hostname, { all: true, family: 0 });
|
|
46
46
|
return result.map(({ address, family }) => ({ address, family }));
|
|
@@ -135,10 +135,11 @@ export async function assertExternalAssetUrl({ rawUrl }, { lookup = defaultDnsLo
|
|
|
135
135
|
* forgotten at a call site); the forced `redirect` is spread last so it
|
|
136
136
|
* overrides any value the caller passed in `init`. Callers keep their own
|
|
137
137
|
* `!resp.ok` HTTP-status handling.
|
|
138
|
-
*
|
|
138
|
+
* `lookup` is retained for source compatibility; DNS configuration belongs on httpClient.
|
|
139
|
+
* @throws URL/policy refusals, a missing client, and DNS/transport failures before unsafe I/O.
|
|
139
140
|
* @complexity O(a + b) for a DNS answers and b bounded decoded asset bytes.
|
|
140
141
|
*/
|
|
141
|
-
export async function assertAndFetchExternalAsset({ url }, { init = {}, lookup, ...outbound } = {}) {
|
|
142
|
+
export async function assertAndFetchExternalAsset({ url }, { init = {}, lookup: _lookup, ...outbound } = {}) {
|
|
142
143
|
// Preserve the early URL diagnostic. DNS vetting belongs to the client that pins the socket,
|
|
143
144
|
// not an independent lookup followed by a fetch that resolves the hostname a second time.
|
|
144
145
|
if (outbound.allowPrivateNetwork !== true && outbound.httpClient === undefined) {
|
|
@@ -149,8 +150,8 @@ export async function assertAndFetchExternalAsset({ url }, { init = {}, lookup,
|
|
|
149
150
|
// Downloading an already-generated asset, not waiting on generation — UPLOAD-class (2min).
|
|
150
151
|
return fetchMediaOutbound({ url, timeoutMs: FETCH_TIMEOUT_MS.UPLOAD }, {
|
|
151
152
|
...outbound,
|
|
153
|
+
httpClient: requireMediaHttpClient(outbound),
|
|
152
154
|
init: { ...init, redirect: 'error' },
|
|
153
|
-
...(lookup === undefined ? {} : { dns: { resolve: async ({ hostname }) => (await lookup({ hostname })).map(entry => entry.address) } }),
|
|
154
155
|
});
|
|
155
156
|
}
|
|
156
157
|
//# sourceMappingURL=ssrf-guard.js.map
|
|
@@ -22,8 +22,9 @@ import type { RequiredArgs, OptionalArgs } from '../../args.js';
|
|
|
22
22
|
* filesystem-backed `AttachmentStaging` adapter copies and prunes local
|
|
23
23
|
* attachments; provider dispatch performs network I/O through its transport.
|
|
24
24
|
*/
|
|
25
|
+
import type { HttpClientPort } from '@jini-ai/core/primitives';
|
|
25
26
|
import type { MediaOutboundOptions } from './outbound.js';
|
|
26
|
-
import type { AudioKind, MediaSurface } from '../types.js';
|
|
27
|
+
import type { AudioKind, MediaModel, MediaProvider, MediaSurface } from '../types.js';
|
|
27
28
|
/** 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. */
|
|
28
29
|
export interface ProviderCredentials {
|
|
29
30
|
readonly apiKey?: string;
|
|
@@ -91,7 +92,18 @@ export interface MediaGenerationResult {
|
|
|
91
92
|
/** Non-fatal notices (e.g. a requested `length`/`duration` was clamped to the nearest allowed value). */
|
|
92
93
|
readonly warnings: readonly string[];
|
|
93
94
|
}
|
|
94
|
-
|
|
95
|
+
/** Dispatch only reads routes; the host owns registration and registry lifetime. */
|
|
96
|
+
export interface VendorAdapterLookup {
|
|
97
|
+
get(required: {
|
|
98
|
+
providerId: string;
|
|
99
|
+
routeKey: string;
|
|
100
|
+
}): VendorAdapter<never> | undefined;
|
|
101
|
+
}
|
|
102
|
+
export interface MediaDispatchEngineRequired {
|
|
103
|
+
readonly registry: VendorAdapterLookup;
|
|
104
|
+
readonly httpClient: HttpClientPort;
|
|
105
|
+
}
|
|
106
|
+
export interface MediaDispatchEngineOptions extends Omit<MediaOutboundOptions, 'httpClient'> {
|
|
95
107
|
/** Per-provider credentials, keyed by provider id (see `providers.ts`'s `MEDIA_PROVIDERS` for valid ids). */
|
|
96
108
|
readonly credentials?: Readonly<Record<string, ProviderCredentials>>;
|
|
97
109
|
/**
|
|
@@ -104,6 +116,26 @@ export interface MediaDispatchEngineOptions extends MediaOutboundOptions {
|
|
|
104
116
|
* getting silent placeholders by default.
|
|
105
117
|
*/
|
|
106
118
|
readonly allowStubFallback?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Where model/provider validation reads from. Defaults to the static built-in catalogue
|
|
121
|
+
* (`providers.ts`); pass a `MediaProviderRegistry` (it implements this) so plugin-contributed
|
|
122
|
+
* vendors validate too.
|
|
123
|
+
*/
|
|
124
|
+
readonly catalog?: MediaModelCatalog;
|
|
125
|
+
}
|
|
126
|
+
/** The catalogue reads the engine validates requests against (see `media-provider-registry.ts`). */
|
|
127
|
+
export interface MediaModelCatalog {
|
|
128
|
+
findModel(required: {
|
|
129
|
+
id: string;
|
|
130
|
+
}): MediaModel | null;
|
|
131
|
+
findProvider(required: {
|
|
132
|
+
id: string;
|
|
133
|
+
}): MediaProvider | null;
|
|
134
|
+
modelsForSurface(required: {
|
|
135
|
+
surface: MediaSurface;
|
|
136
|
+
}, optional?: {
|
|
137
|
+
audioKind?: AudioKind | undefined;
|
|
138
|
+
}): readonly MediaModel[];
|
|
107
139
|
}
|
|
108
140
|
export interface MediaDispatchEngine {
|
|
109
141
|
generate(required: RequiredArgs<MediaGenerationRequest>, optional?: OptionalArgs<MediaGenerationRequest>): Promise<MediaGenerationResult>;
|
|
@@ -134,4 +166,46 @@ export interface RenderContext extends MediaOutboundOptions {
|
|
|
134
166
|
readonly speechFormat: MediaSpeechFormat;
|
|
135
167
|
readonly onProgress?: ((message: string) => void) | undefined;
|
|
136
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* One vendor HTTP request, plus any values `buildRequest` computed that
|
|
171
|
+
* `parseResponse` also needs (e.g. a resolved `wireModel`/`voiceId` for
|
|
172
|
+
* building `providerNote`). Kept out of `RenderContext` because these are
|
|
173
|
+
* per-adapter derived values, not universal fields every vendor shares.
|
|
174
|
+
*/
|
|
175
|
+
export interface VendorRequest<Meta = undefined> {
|
|
176
|
+
readonly url: string;
|
|
177
|
+
readonly init: RequestInit;
|
|
178
|
+
readonly meta: Meta;
|
|
179
|
+
}
|
|
180
|
+
export type VendorRequestBuilder<Meta = undefined> = (required: {
|
|
181
|
+
ctx: RenderContext;
|
|
182
|
+
credentials: ProviderCredentials;
|
|
183
|
+
}) => VendorRequest<Meta>;
|
|
184
|
+
/**
|
|
185
|
+
* Turns a `fetch` `Response` into a `RenderResult`, or throws a
|
|
186
|
+
* vendor-tagged `Error` — the "response-parsing + error-mapping" half of a
|
|
187
|
+
* vendor adapter. Receives `ctx`/`request` too since some vendors need a
|
|
188
|
+
* second request (an SSRF-guarded asset download, a Gemini-native
|
|
189
|
+
* redirect) to finish parsing — see vendor-adapter.ts's module comment.
|
|
190
|
+
*/
|
|
191
|
+
export type VendorResponseParser<Meta = undefined> = (required: {
|
|
192
|
+
resp: Response;
|
|
193
|
+
ctx: RenderContext;
|
|
194
|
+
request: VendorRequest<Meta>;
|
|
195
|
+
}) => Promise<RenderResult>;
|
|
196
|
+
/** Validates `credentials` before any network call, throwing a vendor-tagged `Error` when they're unusable (e.g. no API key configured). */
|
|
197
|
+
export type VendorCredentialGuard = (required: {
|
|
198
|
+
credentials: ProviderCredentials;
|
|
199
|
+
}) => void;
|
|
200
|
+
/**
|
|
201
|
+
* A fully-configured vendor: the "auth-scheme" (`requireCredential`),
|
|
202
|
+
* "request-shape" (`buildRequest`), and "response-parsing + error-mapping"
|
|
203
|
+
* (`parseResponse`) a new vendor registers instead of writing a bespoke
|
|
204
|
+
* `render*` function.
|
|
205
|
+
*/
|
|
206
|
+
export interface VendorAdapter<Meta = undefined> {
|
|
207
|
+
readonly requireCredential?: VendorCredentialGuard;
|
|
208
|
+
readonly buildRequest: VendorRequestBuilder<Meta>;
|
|
209
|
+
readonly parseResponse: VendorResponseParser<Meta>;
|
|
210
|
+
}
|
|
137
211
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,46 +1,5 @@
|
|
|
1
|
-
import type { ProviderCredentials, RenderContext, RenderResult } from './types.js';
|
|
2
|
-
|
|
3
|
-
* One vendor HTTP request, plus any values `buildRequest` computed that
|
|
4
|
-
* `parseResponse` also needs (e.g. a resolved `wireModel`/`voiceId` for
|
|
5
|
-
* building `providerNote`). Kept out of `RenderContext` because these are
|
|
6
|
-
* per-adapter derived values, not universal fields every vendor shares.
|
|
7
|
-
*/
|
|
8
|
-
export interface VendorRequest<Meta = undefined> {
|
|
9
|
-
readonly url: string;
|
|
10
|
-
readonly init: RequestInit;
|
|
11
|
-
readonly meta: Meta;
|
|
12
|
-
}
|
|
13
|
-
export type VendorRequestBuilder<Meta = undefined> = (required: {
|
|
14
|
-
ctx: RenderContext;
|
|
15
|
-
credentials: ProviderCredentials;
|
|
16
|
-
}) => VendorRequest<Meta>;
|
|
17
|
-
/**
|
|
18
|
-
* Turns a `fetch` `Response` into a `RenderResult`, or throws a
|
|
19
|
-
* vendor-tagged `Error` — the "response-parsing + error-mapping" half of a
|
|
20
|
-
* vendor adapter. Receives `ctx`/`request` too since some vendors need a
|
|
21
|
-
* second request (an SSRF-guarded asset download, a Gemini-native
|
|
22
|
-
* redirect) to finish parsing — see this module's doc comment.
|
|
23
|
-
*/
|
|
24
|
-
export type VendorResponseParser<Meta = undefined> = (required: {
|
|
25
|
-
resp: Response;
|
|
26
|
-
ctx: RenderContext;
|
|
27
|
-
request: VendorRequest<Meta>;
|
|
28
|
-
}) => Promise<RenderResult>;
|
|
29
|
-
/** Validates `credentials` before any network call, throwing a vendor-tagged `Error` when they're unusable (e.g. no API key configured). */
|
|
30
|
-
export type VendorCredentialGuard = (required: {
|
|
31
|
-
credentials: ProviderCredentials;
|
|
32
|
-
}) => void;
|
|
33
|
-
/**
|
|
34
|
-
* A fully-configured vendor: the "auth-scheme" (`requireCredential`),
|
|
35
|
-
* "request-shape" (`buildRequest`), and "response-parsing + error-mapping"
|
|
36
|
-
* (`parseResponse`) a new vendor registers instead of writing a bespoke
|
|
37
|
-
* `render*` function.
|
|
38
|
-
*/
|
|
39
|
-
export interface VendorAdapter<Meta = undefined> {
|
|
40
|
-
readonly requireCredential?: VendorCredentialGuard;
|
|
41
|
-
readonly buildRequest: VendorRequestBuilder<Meta>;
|
|
42
|
-
readonly parseResponse: VendorResponseParser<Meta>;
|
|
43
|
-
}
|
|
1
|
+
import type { ProviderCredentials, RenderContext, RenderResult, VendorAdapter, VendorCredentialGuard } from './types.js';
|
|
2
|
+
export type { VendorRequest, VendorRequestBuilder, VendorResponseParser, VendorCredentialGuard, VendorAdapter } from './types.js';
|
|
44
3
|
/**
|
|
45
4
|
* The generic dispatch core: `requireCredential` -> `buildRequest` -> one
|
|
46
5
|
* `fetch` -> `parseResponse`. Every migrated vendor's `render*` export is
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* reusable piece.
|
|
28
28
|
*/
|
|
29
29
|
import { FETCH_TIMEOUT_MS } from '@jini-ai/platform/fetch-with-timeout';
|
|
30
|
-
import { fetchMediaOutbound } from './outbound.js';
|
|
30
|
+
import { fetchMediaOutbound, requireMediaHttpClient } from './outbound.js';
|
|
31
31
|
/**
|
|
32
32
|
* The generic dispatch core: `requireCredential` -> `buildRequest` -> one
|
|
33
33
|
* `fetch` -> `parseResponse`. Every migrated vendor's `render*` export is
|
|
@@ -51,7 +51,7 @@ export async function dispatchVendorRequest({ adapter, ctx, credentials }) {
|
|
|
51
51
|
// still applies unchanged; `GENERATE` (10min) matches what those two vendors already picked
|
|
52
52
|
// deliberately for the same reason — media generation genuinely finishes on that order, not in
|
|
53
53
|
// seconds, so anything shorter would abort a legitimately still-generating request.
|
|
54
|
-
const resp = await fetchMediaOutbound({ url: request.url, timeoutMs: FETCH_TIMEOUT_MS.GENERATE }, { ...ctx, init: request.init });
|
|
54
|
+
const resp = await fetchMediaOutbound({ url: request.url, timeoutMs: FETCH_TIMEOUT_MS.GENERATE }, { ...ctx, httpClient: requireMediaHttpClient(ctx), init: request.init });
|
|
55
55
|
return adapter.parseResponse({ resp: resp, ctx: ctx, request: request });
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Host-owned registry mechanics; builtin composition lives in vendor-registry.ts. */
|
|
2
|
+
import type { VendorAdapter, VendorAdapterLookup } from './types.js';
|
|
3
|
+
export declare class VendorAdapterRegistry implements VendorAdapterLookup {
|
|
4
|
+
private readonly table;
|
|
5
|
+
/** Registers `adapter` for `(providerId, routeKey)`. Throws if that pair is already registered — populate each host registry exactly once. */
|
|
6
|
+
register<Meta>({ providerId, routeKey, adapter }: {
|
|
7
|
+
providerId: string;
|
|
8
|
+
routeKey: string;
|
|
9
|
+
adapter: VendorAdapter<Meta>;
|
|
10
|
+
}): void;
|
|
11
|
+
/** Looks up the adapter registered for `(providerId, routeKey)`, or `undefined` if none is registered. */
|
|
12
|
+
get({ providerId, routeKey }: {
|
|
13
|
+
providerId: string;
|
|
14
|
+
routeKey: string;
|
|
15
|
+
}): VendorAdapter<never> | undefined;
|
|
16
|
+
/** Whether an adapter is registered for `(providerId, routeKey)`. */
|
|
17
|
+
has({ providerId, routeKey }: {
|
|
18
|
+
providerId: string;
|
|
19
|
+
routeKey: string;
|
|
20
|
+
}): boolean;
|
|
21
|
+
/** 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. */
|
|
22
|
+
list(): ReadonlyArray<readonly [providerId: string, routeKey: string]>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=vendor-registry-core.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export class VendorAdapterRegistry {
|
|
2
|
+
table = new Map();
|
|
3
|
+
/** Registers `adapter` for `(providerId, routeKey)`. Throws if that pair is already registered — populate each host registry exactly once. */
|
|
4
|
+
register({ providerId, routeKey, adapter }) {
|
|
5
|
+
let bySurface = this.table.get(providerId);
|
|
6
|
+
if (!bySurface) {
|
|
7
|
+
bySurface = new Map();
|
|
8
|
+
this.table.set(providerId, bySurface);
|
|
9
|
+
}
|
|
10
|
+
if (bySurface.has(routeKey)) {
|
|
11
|
+
throw new Error(`a vendor adapter is already registered for "${providerId}" / "${routeKey}"`);
|
|
12
|
+
}
|
|
13
|
+
bySurface.set(routeKey, adapter);
|
|
14
|
+
}
|
|
15
|
+
/** Looks up the adapter registered for `(providerId, routeKey)`, or `undefined` if none is registered. */
|
|
16
|
+
get({ providerId, routeKey }) {
|
|
17
|
+
return this.table.get(providerId)?.get(routeKey);
|
|
18
|
+
}
|
|
19
|
+
/** Whether an adapter is registered for `(providerId, routeKey)`. */
|
|
20
|
+
has({ providerId, routeKey }) {
|
|
21
|
+
return this.table.get(providerId)?.has(routeKey) ?? false;
|
|
22
|
+
}
|
|
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. */
|
|
24
|
+
list() {
|
|
25
|
+
const out = [];
|
|
26
|
+
for (const [providerId, bySurface] of this.table) {
|
|
27
|
+
for (const routeKey of bySurface.keys()) {
|
|
28
|
+
out.push([providerId, routeKey]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=vendor-registry-core.js.map
|