@jini-ai/integrations 0.7.2 → 0.7.3-next.2
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 +2 -2
- package/README.md +1 -0
- package/dist/api-connections/access-token.js +4 -4
- package/dist/api-connections/account-actions.d.ts +10 -4
- package/dist/api-connections/account-actions.js +13 -13
- package/dist/api-connections/attempt-state.d.ts +11 -5
- package/dist/api-connections/attempt-state.js +4 -4
- package/dist/api-connections/authorization.d.ts +7 -3
- package/dist/api-connections/authorization.js +18 -18
- package/dist/api-connections/finish-authorization.d.ts +8 -4
- package/dist/api-connections/finish-authorization.js +9 -9
- package/dist/api-connections/host.d.ts +30 -32
- package/dist/api-connections/host.js +232 -205
- package/dist/api-connections/hosted-mcp/contracts.d.ts +1 -1
- package/dist/api-connections/hosted-mcp/oauth-row-writes.d.ts +50 -0
- package/dist/api-connections/hosted-mcp/oauth-row-writes.js +38 -0
- package/dist/api-connections/hosted-mcp/shared-sign-in.d.ts +40 -40
- package/dist/api-connections/hosted-mcp/shared-sign-in.js +98 -22
- package/dist/api-connections/hosted-mcp/sign-in-configuration.d.ts +29 -0
- package/dist/api-connections/hosted-mcp/sign-in-configuration.js +127 -0
- package/dist/api-connections/hosted-mcp/sign-in-discovery.d.ts +72 -0
- package/dist/api-connections/hosted-mcp/sign-in-discovery.js +131 -0
- package/dist/api-connections/hosted-mcp/sign-in-flow.d.ts +42 -0
- package/dist/api-connections/hosted-mcp/sign-in-flow.js +50 -0
- package/dist/api-connections/hosted-mcp/sign-in-provider.d.ts +103 -0
- package/dist/api-connections/hosted-mcp/sign-in-provider.js +142 -0
- package/dist/api-connections/hosted-mcp/sign-in-status.d.ts +19 -0
- package/dist/api-connections/hosted-mcp/sign-in-status.js +143 -0
- package/dist/api-connections/hosted-mcp/sign-in.d.ts +2 -9
- package/dist/api-connections/hosted-mcp/sign-in.js +219 -770
- package/dist/api-connections/index.js +1 -1
- package/dist/api-connections/install-credential.d.ts +4 -2
- package/dist/api-connections/install-credential.js +7 -7
- package/dist/api-connections/records.d.ts +17 -5
- package/dist/api-connections/records.js +5 -5
- package/dist/api-connections/request-checks.d.ts +29 -9
- package/dist/api-connections/request-checks.js +13 -13
- package/dist/api-connections/service.d.ts +1 -1
- package/dist/api-connections/service.js +6 -6
- package/dist/api-connections/status.d.ts +3 -1
- package/dist/api-connections/status.js +3 -3
- package/dist/api-connections/token-store/errors.d.ts +3 -1
- package/dist/api-connections/token-store/errors.js +1 -1
- package/dist/api-connections/token-store/vault-token-store.js +186 -173
- package/dist/args.d.ts +4 -1
- package/dist/args.js +1 -1
- package/dist/credentialed-http/credentialed-request.d.ts +5 -5
- package/dist/credentialed-http/credentialed-request.js +8 -8
- package/dist/credentialed-http/response-redaction.d.ts +18 -4
- package/dist/credentialed-http/response-redaction.js +7 -7
- package/dist/credentialed-http/sets/vault-repo.js +5 -1
- package/dist/credentialed-http/tools/credential-copy-tool.js +20 -15
- package/dist/credentialed-http/tools/tool-registrations.js +272 -249
- package/dist/media-providers/catalog.d.ts +1 -0
- package/dist/media-providers/catalog.js +1 -0
- package/dist/media-providers/dispatch/async-operation-store.d.ts +6 -4
- package/dist/media-providers/dispatch/async-operation-store.js +100 -88
- package/dist/media-providers/dispatch/context.js +1 -1
- package/dist/media-providers/dispatch/engine.d.ts +5 -1
- package/dist/media-providers/dispatch/engine.js +2 -2
- package/dist/media-providers/dispatch/index.d.ts +1 -1
- package/dist/media-providers/dispatch/index.js +1 -1
- package/dist/media-providers/dispatch/node.d.ts +1 -1
- package/dist/media-providers/dispatch/node.js +1 -1
- package/dist/media-providers/dispatch/openai-compatible.d.ts +50 -11
- package/dist/media-providers/dispatch/openai-compatible.js +21 -17
- package/dist/media-providers/dispatch/operation-runtime.js +18 -18
- package/dist/media-providers/dispatch/outbound.d.ts +2 -2
- package/dist/media-providers/dispatch/outbound.js +1 -1
- package/dist/media-providers/dispatch/polling-adapter.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts +20 -6
- package/dist/media-providers/dispatch/providers/aihubmix-shared.js +8 -8
- package/dist/media-providers/dispatch/providers/aihubmix.js +12 -12
- package/dist/media-providers/dispatch/providers/custom-image.js +4 -4
- package/dist/media-providers/dispatch/providers/fishaudio.js +2 -9
- package/dist/media-providers/dispatch/providers/grok.js +5 -19
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.js +22 -20
- package/dist/media-providers/dispatch/providers/imagerouter.js +7 -21
- package/dist/media-providers/dispatch/providers/minimax.js +2 -9
- package/dist/media-providers/dispatch/providers/nanobanana.js +2 -2
- package/dist/media-providers/dispatch/providers/openai.js +6 -6
- package/dist/media-providers/dispatch/providers/openrouter.js +4 -4
- package/dist/media-providers/dispatch/providers/senseaudio.js +5 -19
- package/dist/media-providers/dispatch/providers/volcengine.js +5 -12
- package/dist/media-providers/dispatch/response-parsers.js +3 -3
- package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts +1 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.js +31 -5
- package/dist/media-providers/dispatch/ssrf-guard.js +5 -12
- package/dist/media-providers/dispatch/stub.js +2 -2
- package/dist/media-providers/dispatch/vendor-adapter.js +2 -2
- package/dist/media-providers/image-model-ids.d.ts +36 -0
- package/dist/media-providers/image-model-ids.js +24 -0
- package/dist/media-providers/sqlite-driver.adapter.d.ts +1 -1
- package/dist/media-providers/sqlite-task-store.d.ts +2 -2
- package/dist/media-providers/sqlite-task-store.js +31 -4
- package/dist/media-providers/task-lifecycle.d.ts +17 -4
- package/dist/media-providers/task-lifecycle.js +4 -4
- package/dist/media-providers/task-store.js +28 -24
- package/dist/media-providers/ui-defaults.d.ts +7 -0
- package/dist/media-providers/ui-defaults.js +11 -17
- package/dist/saved-requests/types.d.ts +1 -1
- package/dist/webhooks/delivery.js +31 -27
- package/dist/webhooks/ports.d.ts +4 -1
- package/dist/webhooks/subscriptions.d.ts +7 -2
- package/dist/webhooks/subscriptions.js +30 -37
- package/dist/webhooks/tools/agent-tools.d.ts +82 -0
- package/dist/webhooks/tools/agent-tools.js +120 -0
- package/dist/webhooks/tools/index.d.ts +7 -0
- package/dist/webhooks/tools/index.js +5 -0
- package/dist/webhooks/tools/tool-handlers.d.ts +22 -0
- package/dist/webhooks/tools/tool-handlers.js +154 -0
- package/dist/webhooks/tools/tool-handlers.types.d.ts +64 -0
- package/dist/webhooks/tools/tool-handlers.types.js +2 -0
- package/dist/webhooks/tools/tool-registrations.d.ts +35 -0
- package/dist/webhooks/tools/tool-registrations.js +95 -0
- package/dist/webhooks/tools/tool-views.d.ts +62 -0
- package/dist/webhooks/tools/tool-views.js +50 -0
- package/dist/webhooks/types.d.ts +2 -0
- package/dist/webhooks/worker.d.ts +7 -4
- package/dist/webhooks/worker.js +22 -20
- package/package.json +17 -19
- 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
|
@@ -147,7 +147,7 @@ function cloneRecord(row) {
|
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
149
|
/** Exported for the same reason as `TERMINAL_STATUSES` — see its doc. */
|
|
150
|
-
export function assertTransition(from, to) {
|
|
150
|
+
export function assertTransition({ from, to }, _optional = {}) {
|
|
151
151
|
if (!ALLOWED_TRANSITIONS[from]) {
|
|
152
152
|
throw new RangeError(`Invalid async operation status: "${from}"`);
|
|
153
153
|
}
|
|
@@ -189,11 +189,11 @@ function patchedNullable({ patch, existing, key }) {
|
|
|
189
189
|
* `TERMINAL_STATUSES`.
|
|
190
190
|
* @throws `Error` for credential material; `RangeError` for an illegal transition.
|
|
191
191
|
*/
|
|
192
|
-
export function mergeAsyncOperationPatch({ existing, patch },
|
|
192
|
+
export function mergeAsyncOperationPatch({ existing, patch, now }, _optional = {}) {
|
|
193
193
|
if ('state' in patch)
|
|
194
194
|
assertNoCredentialMaterial({ state: patch.state });
|
|
195
195
|
const status = patch.status ?? existing.status;
|
|
196
|
-
assertTransition(existing.status, status);
|
|
196
|
+
assertTransition({ from: existing.status, to: status });
|
|
197
197
|
return {
|
|
198
198
|
...existing,
|
|
199
199
|
status,
|
|
@@ -207,6 +207,98 @@ export function mergeAsyncOperationPatch({ existing, patch }, { now }) {
|
|
|
207
207
|
updatedAt: now,
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
|
+
function createRow({ input, now }) {
|
|
211
|
+
return {
|
|
212
|
+
schemaVersion: ASYNC_OPERATION_SCHEMA_VERSION,
|
|
213
|
+
id: input.id,
|
|
214
|
+
providerId: input.providerId,
|
|
215
|
+
routeKey: input.routeKey,
|
|
216
|
+
ownerRef: input.ownerRef,
|
|
217
|
+
status: input.status ?? 'submitted',
|
|
218
|
+
attempts: 0,
|
|
219
|
+
maxAttempts: input.maxAttempts,
|
|
220
|
+
deadlineAt: input.deadlineAt,
|
|
221
|
+
nextPollAt: input.nextPollAt ?? now,
|
|
222
|
+
leaseOwner: null,
|
|
223
|
+
leaseExpiresAt: null,
|
|
224
|
+
state: cloneState(input.state ?? null),
|
|
225
|
+
result: null,
|
|
226
|
+
error: null,
|
|
227
|
+
createdAt: now,
|
|
228
|
+
updatedAt: now,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function createOperation({ rows, required, optional }) {
|
|
232
|
+
const input = { ...required, ...optional };
|
|
233
|
+
if (rows.has(input.id)) {
|
|
234
|
+
throw new Error(`async operation "${input.id}" already exists`);
|
|
235
|
+
}
|
|
236
|
+
assertValidCreateInput({ input });
|
|
237
|
+
const row = createRow({ input, now: Date.now() });
|
|
238
|
+
rows.set(row.id, row);
|
|
239
|
+
return cloneRecord(row);
|
|
240
|
+
}
|
|
241
|
+
function updateOperation({ rows, id, patch, options }) {
|
|
242
|
+
const existing = rows.get(id);
|
|
243
|
+
if (!existing)
|
|
244
|
+
return null;
|
|
245
|
+
// Fenced, like releaseLease: a caller writing against a lease it no longer holds gets a
|
|
246
|
+
// no-op, not an overwrite of whoever holds (or now holds none of) it.
|
|
247
|
+
if (isFencedOut({ existing, options }))
|
|
248
|
+
return cloneRecord(existing);
|
|
249
|
+
const merged = mergeAsyncOperationPatch({ existing, patch, now: Date.now() });
|
|
250
|
+
// Store a private copy of `state` so the caller's patch object never aliases the row.
|
|
251
|
+
const next = { ...merged, state: cloneState(merged.state) };
|
|
252
|
+
rows.set(id, next);
|
|
253
|
+
return cloneRecord(next);
|
|
254
|
+
}
|
|
255
|
+
function claimDueOperations(rows, options) {
|
|
256
|
+
const { now, leaseOwner, leaseMs } = options;
|
|
257
|
+
const limit = options.limit ?? 10;
|
|
258
|
+
const claimed = [];
|
|
259
|
+
// A live lease held by anyone (including this worker's previous tick) blocks the claim;
|
|
260
|
+
// an expired one does not, which is what makes a dead worker's rows recoverable.
|
|
261
|
+
const blocked = (row) => TERMINAL_STATUSES.has(row.status) || row.nextPollAt > now || (row.leaseExpiresAt !== null && row.leaseExpiresAt > now);
|
|
262
|
+
for (const row of [...rows.values()].sort((a, b) => a.nextPollAt - b.nextPollAt).filter((each) => !blocked(each))) {
|
|
263
|
+
if (claimed.length >= limit)
|
|
264
|
+
break;
|
|
265
|
+
const leased = {
|
|
266
|
+
...row,
|
|
267
|
+
leaseOwner,
|
|
268
|
+
leaseExpiresAt: now + leaseMs,
|
|
269
|
+
updatedAt: now,
|
|
270
|
+
};
|
|
271
|
+
rows.set(row.id, leased);
|
|
272
|
+
claimed.push(cloneRecord(leased));
|
|
273
|
+
}
|
|
274
|
+
return claimed;
|
|
275
|
+
}
|
|
276
|
+
function reconcileOperationsOnBoot(rows, { now }) {
|
|
277
|
+
let leasesReleased = 0;
|
|
278
|
+
let deadlineExpired = 0;
|
|
279
|
+
for (const row of [...rows.values()].filter((each) => !TERMINAL_STATUSES.has(each.status))) {
|
|
280
|
+
if (row.deadlineAt <= now) {
|
|
281
|
+
rows.set(row.id, {
|
|
282
|
+
...row,
|
|
283
|
+
status: 'unknown',
|
|
284
|
+
leaseOwner: null,
|
|
285
|
+
leaseExpiresAt: null,
|
|
286
|
+
error: {
|
|
287
|
+
message: 'async operation passed its absolute deadline while unattended — vendor-side effect is undetermined',
|
|
288
|
+
code: 'DEADLINE_EXPIRED',
|
|
289
|
+
},
|
|
290
|
+
updatedAt: now,
|
|
291
|
+
});
|
|
292
|
+
deadlineExpired += 1;
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (row.leaseOwner !== null && (row.leaseExpiresAt === null || row.leaseExpiresAt <= now)) {
|
|
296
|
+
rows.set(row.id, { ...row, leaseOwner: null, leaseExpiresAt: null, updatedAt: now });
|
|
297
|
+
leasesReleased += 1;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return { leasesReleased, deadlineExpired };
|
|
301
|
+
}
|
|
210
302
|
/**
|
|
211
303
|
* Creates the in-memory reference `AsyncOperationStore`. No persistence — a durable adapter
|
|
212
304
|
* implements the same interface; every method here is written so the equivalent SQL is a direct
|
|
@@ -216,51 +308,14 @@ export function createInMemoryAsyncOperationStore() {
|
|
|
216
308
|
const rows = new Map();
|
|
217
309
|
return {
|
|
218
310
|
async create(required, optional = {}) {
|
|
219
|
-
|
|
220
|
-
if (rows.has(input.id)) {
|
|
221
|
-
throw new Error(`async operation "${input.id}" already exists`);
|
|
222
|
-
}
|
|
223
|
-
assertValidCreateInput({ input });
|
|
224
|
-
const now = Date.now();
|
|
225
|
-
const row = {
|
|
226
|
-
schemaVersion: ASYNC_OPERATION_SCHEMA_VERSION,
|
|
227
|
-
id: input.id,
|
|
228
|
-
providerId: input.providerId,
|
|
229
|
-
routeKey: input.routeKey,
|
|
230
|
-
ownerRef: input.ownerRef,
|
|
231
|
-
status: input.status ?? 'submitted',
|
|
232
|
-
attempts: 0,
|
|
233
|
-
maxAttempts: input.maxAttempts,
|
|
234
|
-
deadlineAt: input.deadlineAt,
|
|
235
|
-
nextPollAt: input.nextPollAt ?? now,
|
|
236
|
-
leaseOwner: null,
|
|
237
|
-
leaseExpiresAt: null,
|
|
238
|
-
state: cloneState(input.state ?? null),
|
|
239
|
-
result: null,
|
|
240
|
-
error: null,
|
|
241
|
-
createdAt: now,
|
|
242
|
-
updatedAt: now,
|
|
243
|
-
};
|
|
244
|
-
rows.set(row.id, row);
|
|
245
|
-
return cloneRecord(row);
|
|
311
|
+
return createOperation({ rows, required, optional });
|
|
246
312
|
},
|
|
247
313
|
async get({ id }) {
|
|
248
314
|
const row = rows.get(id);
|
|
249
315
|
return row ? cloneRecord(row) : null;
|
|
250
316
|
},
|
|
251
|
-
async update(
|
|
252
|
-
|
|
253
|
-
if (!existing)
|
|
254
|
-
return null;
|
|
255
|
-
// Fenced, like releaseLease: a caller writing against a lease it no longer holds gets a
|
|
256
|
-
// no-op, not an overwrite of whoever holds (or now holds none of) it.
|
|
257
|
-
if (isFencedOut({ existing, options }))
|
|
258
|
-
return cloneRecord(existing);
|
|
259
|
-
const merged = mergeAsyncOperationPatch({ existing, patch }, { now: Date.now() });
|
|
260
|
-
// Store a private copy of `state` so the caller's patch object never aliases the row.
|
|
261
|
-
const next = { ...merged, state: cloneState(merged.state) };
|
|
262
|
-
rows.set(id, next);
|
|
263
|
-
return cloneRecord(next);
|
|
317
|
+
async update(required, { options } = {}) {
|
|
318
|
+
return updateOperation({ rows, ...required, options });
|
|
264
319
|
},
|
|
265
320
|
async listByOwner({ ownerRef }) {
|
|
266
321
|
return [...rows.values()]
|
|
@@ -269,26 +324,7 @@ export function createInMemoryAsyncOperationStore() {
|
|
|
269
324
|
.map(cloneRecord);
|
|
270
325
|
},
|
|
271
326
|
async claimDue(required, optional = {}) {
|
|
272
|
-
|
|
273
|
-
const { now, leaseOwner, leaseMs } = options;
|
|
274
|
-
const limit = options.limit ?? 10;
|
|
275
|
-
const claimed = [];
|
|
276
|
-
// A live lease held by anyone (including this worker's previous tick) blocks the claim;
|
|
277
|
-
// an expired one does not, which is what makes a dead worker's rows recoverable.
|
|
278
|
-
const blocked = (row) => TERMINAL_STATUSES.has(row.status) || row.nextPollAt > now || (row.leaseExpiresAt !== null && row.leaseExpiresAt > now);
|
|
279
|
-
for (const row of [...rows.values()].sort((a, b) => a.nextPollAt - b.nextPollAt).filter((each) => !blocked(each))) {
|
|
280
|
-
if (claimed.length >= limit)
|
|
281
|
-
break;
|
|
282
|
-
const leased = {
|
|
283
|
-
...row,
|
|
284
|
-
leaseOwner,
|
|
285
|
-
leaseExpiresAt: now + leaseMs,
|
|
286
|
-
updatedAt: now,
|
|
287
|
-
};
|
|
288
|
-
rows.set(row.id, leased);
|
|
289
|
-
claimed.push(cloneRecord(leased));
|
|
290
|
-
}
|
|
291
|
-
return claimed;
|
|
327
|
+
return claimDueOperations(rows, { ...required, ...optional });
|
|
292
328
|
},
|
|
293
329
|
async releaseLease({ id, leaseOwner }) {
|
|
294
330
|
const row = rows.get(id);
|
|
@@ -301,31 +337,7 @@ export function createInMemoryAsyncOperationStore() {
|
|
|
301
337
|
rows.set(id, { ...row, leaseOwner: null, leaseExpiresAt: null, updatedAt: Date.now() });
|
|
302
338
|
},
|
|
303
339
|
async reconcileOnBoot(options) {
|
|
304
|
-
|
|
305
|
-
let leasesReleased = 0;
|
|
306
|
-
let deadlineExpired = 0;
|
|
307
|
-
for (const row of [...rows.values()].filter((each) => !TERMINAL_STATUSES.has(each.status))) {
|
|
308
|
-
if (row.deadlineAt <= now) {
|
|
309
|
-
rows.set(row.id, {
|
|
310
|
-
...row,
|
|
311
|
-
status: 'unknown',
|
|
312
|
-
leaseOwner: null,
|
|
313
|
-
leaseExpiresAt: null,
|
|
314
|
-
error: {
|
|
315
|
-
message: 'async operation passed its absolute deadline while unattended — vendor-side effect is undetermined',
|
|
316
|
-
code: 'DEADLINE_EXPIRED',
|
|
317
|
-
},
|
|
318
|
-
updatedAt: now,
|
|
319
|
-
});
|
|
320
|
-
deadlineExpired += 1;
|
|
321
|
-
continue;
|
|
322
|
-
}
|
|
323
|
-
if (row.leaseOwner !== null && (row.leaseExpiresAt === null || row.leaseExpiresAt <= now)) {
|
|
324
|
-
rows.set(row.id, { ...row, leaseOwner: null, leaseExpiresAt: null, updatedAt: now });
|
|
325
|
-
leasesReleased += 1;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
return { leasesReleased, deadlineExpired };
|
|
340
|
+
return reconcileOperationsOnBoot(rows, options);
|
|
329
341
|
},
|
|
330
342
|
};
|
|
331
343
|
}
|
|
@@ -37,7 +37,7 @@ export function buildRenderContext({ request, resolvedAudioKind, length, duratio
|
|
|
37
37
|
imageRef: request.imageRef ?? null,
|
|
38
38
|
imageRefs: resolveImageRefs(request),
|
|
39
39
|
requestInit: request.requestInit || {},
|
|
40
|
-
speechFormat: resolveSpeechFormat(request.speechFormat),
|
|
40
|
+
speechFormat: resolveSpeechFormat({ requested: request.speechFormat }),
|
|
41
41
|
onProgress: request.onProgress,
|
|
42
42
|
};
|
|
43
43
|
}
|
|
@@ -17,7 +17,11 @@ export type Renderer = (required: {
|
|
|
17
17
|
* directly-testable pure function" pattern `context.ts`'s
|
|
18
18
|
* `buildRenderContext` already established for the same reason.
|
|
19
19
|
*/
|
|
20
|
-
export declare function lookupRoute(routes
|
|
20
|
+
export declare function lookupRoute({ routes, providerId, routeKey }: {
|
|
21
|
+
routes: Readonly<Record<string, Readonly<Record<string, Renderer>>>>;
|
|
22
|
+
providerId: string;
|
|
23
|
+
routeKey: string;
|
|
24
|
+
}, _optional?: Record<string, never>): Renderer | undefined;
|
|
21
25
|
/** Creates an engine over the host's registry; registration remains live between requests.
|
|
22
26
|
* @returns A generation service; validation, missing routes and provider failures reject generate.
|
|
23
27
|
*/
|
|
@@ -82,7 +82,7 @@ function routeKeyFor(surface, audioKind) {
|
|
|
82
82
|
* directly-testable pure function" pattern `context.ts`'s
|
|
83
83
|
* `buildRenderContext` already established for the same reason.
|
|
84
84
|
*/
|
|
85
|
-
export function lookupRoute(routes, providerId, routeKey) {
|
|
85
|
+
export function lookupRoute({ routes, providerId, routeKey }, _optional = {}) {
|
|
86
86
|
return routes[providerId]?.[routeKey];
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
@@ -95,7 +95,7 @@ function resolveRenderer({ registry, providerId, routeKey }) {
|
|
|
95
95
|
if (adapter) {
|
|
96
96
|
return ({ ctx, credentials }) => dispatchVendorRequest({ adapter, ctx, credentials });
|
|
97
97
|
}
|
|
98
|
-
return lookupRoute(ROUTES, providerId, routeKey);
|
|
98
|
+
return lookupRoute({ routes: ROUTES, providerId, routeKey });
|
|
99
99
|
}
|
|
100
100
|
/** Creates an engine over the host's registry; registration remains live between requests.
|
|
101
101
|
* @returns A generation service; validation, missing routes and provider failures reject generate.
|
|
@@ -15,7 +15,7 @@ export { renderSenseAudioImage, renderSenseAudioTTS } from './providers/senseaud
|
|
|
15
15
|
export { renderVolcengineImage } from './providers/volcengine.js';
|
|
16
16
|
export { renderStub, svgPlaceholder } from './stub.js';
|
|
17
17
|
export { assertAndFetchExternalAsset, assertExternalAssetUrl, validateBaseUrlResolved } from './ssrf-guard.js';
|
|
18
|
-
export { isBlockedExternalApiHostname, isLoopbackApiHost } from '@jini-ai/
|
|
18
|
+
export { isBlockedExternalApiHostname, isLoopbackApiHost } from '@jini-ai/core/net';
|
|
19
19
|
export type { DnsLookupAddress, DnsLookupFn } from './ssrf-guard.js';
|
|
20
20
|
export type { MediaDispatchEngine, MediaDispatchEngineOptions, MediaDispatchEngineRequired, VendorAdapterLookup, MediaGenerationRequest, MediaGenerationRequestInit, MediaGenerationResult, MediaImageReference, MediaModelCatalog, MediaSpeechFormat, ProviderCredentials, } from './types.js';
|
|
21
21
|
export { dispatchVendorRequest, requireApiKey } from './vendor-adapter.js';
|
|
@@ -15,7 +15,7 @@ export { renderSenseAudioImage, renderSenseAudioTTS } from './providers/senseaud
|
|
|
15
15
|
export { renderVolcengineImage } from './providers/volcengine.js';
|
|
16
16
|
export { renderStub, svgPlaceholder } from './stub.js';
|
|
17
17
|
export { assertAndFetchExternalAsset, assertExternalAssetUrl, validateBaseUrlResolved } from './ssrf-guard.js';
|
|
18
|
-
export { isBlockedExternalApiHostname, isLoopbackApiHost } from '@jini-ai/
|
|
18
|
+
export { isBlockedExternalApiHostname, isLoopbackApiHost } from '@jini-ai/core/net';
|
|
19
19
|
// The generic vendor-adapter dispatch engine (added 2026-07-21) — see
|
|
20
20
|
// `vendor-adapter.ts`'s module doc and `archived provenance ledger` for the design and
|
|
21
21
|
// which vendors are registered onto it.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Explicit Node adapter entry. Hosts construct this once and inject it into media services. */
|
|
2
2
|
import type { HttpClientPort } from '@jini-ai/core/primitives';
|
|
3
|
-
import type { DnsResolver } from '@jini-ai/
|
|
3
|
+
import type { DnsResolver } from '@jini-ai/core/contracts/runtime';
|
|
4
4
|
export interface NodeMediaHttpClientOptions {
|
|
5
5
|
readonly allowPrivateNetwork?: boolean;
|
|
6
6
|
readonly dns?: DnsResolver;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FETCH_TIMEOUT_MS } from '@jini-ai/
|
|
1
|
+
import { FETCH_TIMEOUT_MS } from '@jini-ai/core/net';
|
|
2
2
|
import { createHttpClient, createNodeGuardedHttpPorts } from '@jini-ai/platform/http/guarded';
|
|
3
3
|
/** The default policy client: public http(s) peers only unless the caller explicitly opts into
|
|
4
4
|
* private-network development, never following redirects.
|
|
@@ -3,7 +3,9 @@ import type { MediaGenerationRequestInit, MediaSpeechFormat, RenderContext } fro
|
|
|
3
3
|
/** OpenAI's recognized `/audio/speech` voice ids — shared by every vendor whose TTS wire shape matches OpenAI's (OpenAI itself, AIHubMix). A requested voice outside this set is treated by callers as free-form speaking-style instructions rather than a voice id (see `openai.ts`'s `renderOpenAISpeech`). */
|
|
4
4
|
export declare const OPENAI_TTS_VOICES: ReadonlySet<string>;
|
|
5
5
|
/** Validates a caller-requested speech format, defaulting to `'mp3'` for anything unrecognized. */
|
|
6
|
-
export declare function resolveSpeechFormat(requested
|
|
6
|
+
export declare function resolveSpeechFormat({ requested }: {
|
|
7
|
+
requested: MediaSpeechFormat | undefined;
|
|
8
|
+
}, _optional?: Record<string, never>): MediaSpeechFormat;
|
|
7
9
|
/**
|
|
8
10
|
* OpenRouter normalizes aspect ratios across the providers it fronts;
|
|
9
11
|
* `providers.ts`'s `MEDIA_ASPECTS` are all natively supported. xAI's Imagine
|
|
@@ -19,9 +21,20 @@ export declare function standardImageAspectFor({ aspect }: {
|
|
|
19
21
|
aspect: string | undefined;
|
|
20
22
|
}, _options?: Record<string, never>): string;
|
|
21
23
|
/** Truncates a string for inclusion in an error message, appending an ellipsis when truncated. */
|
|
22
|
-
export declare function truncate(s
|
|
24
|
+
export declare function truncate({ s, n }: {
|
|
25
|
+
s: unknown;
|
|
26
|
+
n: number;
|
|
27
|
+
}, _optional?: Record<string, never>): string;
|
|
23
28
|
/** Merges a per-request `requestInit` (e.g. a caller-supplied `dispatcher`) under an explicit `init`, so per-call overrides win. */
|
|
24
29
|
export declare function withRequestInit(ctx: Pick<RenderContext, 'requestInit'>, init?: RequestInit): RequestInit;
|
|
30
|
+
/** `withRequestInit` for the common JSON POST: bearer auth when `apiKey` is given, JSON content type, serialized `body`. */
|
|
31
|
+
export declare function jsonPostInit({ ctx, body }: {
|
|
32
|
+
ctx: Pick<RenderContext, 'requestInit'>;
|
|
33
|
+
body: unknown;
|
|
34
|
+
}, { apiKey, headers }?: {
|
|
35
|
+
apiKey?: string;
|
|
36
|
+
headers?: Readonly<Record<string, string>>;
|
|
37
|
+
}): RequestInit;
|
|
25
38
|
/** Sniffs an image byte buffer's format from its magic bytes (jpg/png/webp), defaulting to `.png`. */
|
|
26
39
|
export declare function sniffImageExt(bytes: Buffer): string;
|
|
27
40
|
export declare const AZURE_DEFAULT_API_VERSION = "2024-02-01";
|
|
@@ -37,23 +50,49 @@ export declare const AZURE_DEFAULT_API_VERSION = "2024-02-01";
|
|
|
37
50
|
* https://api.openai.com/v1
|
|
38
51
|
* http://localhost:8080/v1
|
|
39
52
|
*/
|
|
40
|
-
export declare function detectAzureEndpoint(baseUrl
|
|
53
|
+
export declare function detectAzureEndpoint({ baseUrl }: {
|
|
54
|
+
baseUrl: string;
|
|
55
|
+
}, _optional?: Record<string, never>): boolean;
|
|
41
56
|
/** Rewrites a pathname to end in `/{endpoint}/generations` or (images only) `/images/edits`, preserving any other path prefix. */
|
|
42
|
-
export declare function normalizeOpenAICompatiblePath(pathname
|
|
57
|
+
export declare function normalizeOpenAICompatiblePath({ pathname, endpoint, mode }: {
|
|
58
|
+
pathname: string;
|
|
59
|
+
endpoint: 'images' | 'videos';
|
|
60
|
+
mode: 'generations' | 'edits';
|
|
61
|
+
}, _optional?: Record<string, never>): string;
|
|
43
62
|
/** Builds the full `/{endpoint}/generations` URL, preserving any user-supplied query string. */
|
|
44
|
-
export declare function buildOpenAICompatibleGenerationUrl(baseUrl
|
|
63
|
+
export declare function buildOpenAICompatibleGenerationUrl({ baseUrl, endpoint }: {
|
|
64
|
+
baseUrl: string;
|
|
65
|
+
endpoint: 'images' | 'videos';
|
|
66
|
+
}, _optional?: Record<string, never>): string;
|
|
45
67
|
/** Builds the `/images/generations` URL, appending the default Azure `api-version` when the caller didn't supply one. */
|
|
46
|
-
export declare function buildOpenAIImageUrl(baseUrl
|
|
68
|
+
export declare function buildOpenAIImageUrl({ baseUrl, isAzure }: {
|
|
69
|
+
baseUrl: string;
|
|
70
|
+
isAzure: boolean;
|
|
71
|
+
}, _optional?: Record<string, never>): string;
|
|
47
72
|
/** Builds the `/images/edits` URL (used when a reference image is present). */
|
|
48
|
-
export declare function buildOpenAIImageEditUrl(baseUrl
|
|
73
|
+
export declare function buildOpenAIImageEditUrl({ baseUrl }: {
|
|
74
|
+
baseUrl: string;
|
|
75
|
+
}, _optional?: Record<string, never>): string;
|
|
49
76
|
/** Builds the `/videos/generations` URL. */
|
|
50
|
-
export declare function buildOpenAIVideoUrl(baseUrl
|
|
77
|
+
export declare function buildOpenAIVideoUrl({ baseUrl }: {
|
|
78
|
+
baseUrl: string;
|
|
79
|
+
}, _optional?: Record<string, never>): string;
|
|
51
80
|
/** Picks an image `size` string tuned to the model family + requested aspect ratio, defaulting to the `1024x1024` square. */
|
|
52
|
-
export declare function openaiSizeFor(model
|
|
81
|
+
export declare function openaiSizeFor({ model }: {
|
|
82
|
+
model: string;
|
|
83
|
+
}, { aspect }?: {
|
|
84
|
+
aspect?: string | undefined;
|
|
85
|
+
}): string;
|
|
53
86
|
/** Builds the `/audio/speech` URL, appending the default Azure `api-version` when the caller didn't supply one. */
|
|
54
|
-
export declare function buildOpenAISpeechUrl(baseUrl
|
|
87
|
+
export declare function buildOpenAISpeechUrl({ baseUrl, isAzure }: {
|
|
88
|
+
baseUrl: string;
|
|
89
|
+
isAzure: boolean;
|
|
90
|
+
}, _optional?: Record<string, never>): string;
|
|
55
91
|
/** Parses an OpenAI-compatible JSON response, throwing a clear, provider-tagged error on a non-OK status or non-JSON body. */
|
|
56
|
-
export declare function parseOpenAICompatibleJson(resp
|
|
92
|
+
export declare function parseOpenAICompatibleJson({ resp, providerTag }: {
|
|
93
|
+
resp: Response;
|
|
94
|
+
providerTag: string;
|
|
95
|
+
}, _optional?: Record<string, never>): Promise<unknown>;
|
|
57
96
|
/** Extracts generated bytes from an OpenAI-compatible `{ data: [{ b64_json | url }] }` response.
|
|
58
97
|
* Provider URLs remain untrusted: the outbound client vets DNS, pins peers and refuses redirects.
|
|
59
98
|
* @throws Invalid provider data, policy/transport errors or unsuccessful asset status.
|
|
@@ -12,7 +12,7 @@ const VALID_SPEECH_FORMATS = new Set(['mp3', 'wav', 'flac', 'aac', 'opus']);
|
|
|
12
12
|
/** OpenAI's recognized `/audio/speech` voice ids — shared by every vendor whose TTS wire shape matches OpenAI's (OpenAI itself, AIHubMix). A requested voice outside this set is treated by callers as free-form speaking-style instructions rather than a voice id (see `openai.ts`'s `renderOpenAISpeech`). */
|
|
13
13
|
export const OPENAI_TTS_VOICES = new Set(['alloy', 'ash', 'ballad', 'coral', 'echo', 'fable', 'onyx', 'nova', 'sage', 'shimmer', 'verse']);
|
|
14
14
|
/** Validates a caller-requested speech format, defaulting to `'mp3'` for anything unrecognized. */
|
|
15
|
-
export function resolveSpeechFormat(requested) {
|
|
15
|
+
export function resolveSpeechFormat({ requested }, _optional = {}) {
|
|
16
16
|
return requested && VALID_SPEECH_FORMATS.has(requested) ? requested : 'mp3';
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
@@ -40,7 +40,7 @@ export function standardImageAspectFor({ aspect }, _options = {}) {
|
|
|
40
40
|
return '16:9';
|
|
41
41
|
}
|
|
42
42
|
/** Truncates a string for inclusion in an error message, appending an ellipsis when truncated. */
|
|
43
|
-
export function truncate(s, n) {
|
|
43
|
+
export function truncate({ s, n }, _optional = {}) {
|
|
44
44
|
const v = String(s || '');
|
|
45
45
|
if (v.length <= n)
|
|
46
46
|
return v;
|
|
@@ -53,6 +53,10 @@ export function withRequestInit(ctx, init = {}) {
|
|
|
53
53
|
...init,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
+
/** `withRequestInit` for the common JSON POST: bearer auth when `apiKey` is given, JSON content type, serialized `body`. */
|
|
57
|
+
export function jsonPostInit({ ctx, body }, { apiKey, headers = {} } = {}) {
|
|
58
|
+
return withRequestInit(ctx, { method: 'POST', headers: { ...(apiKey === undefined ? {} : { authorization: `Bearer ${apiKey}` }), 'content-type': 'application/json', ...headers }, body: JSON.stringify(body) });
|
|
59
|
+
}
|
|
56
60
|
// PNG (`89 50 4E 47`, min 8 bytes) has no entry: it is also the default, so
|
|
57
61
|
// matching it explicitly could never change the result.
|
|
58
62
|
const IMAGE_SIGNATURES = [
|
|
@@ -85,7 +89,7 @@ export const AZURE_DEFAULT_API_VERSION = '2024-02-01';
|
|
|
85
89
|
* https://api.openai.com/v1
|
|
86
90
|
* http://localhost:8080/v1
|
|
87
91
|
*/
|
|
88
|
-
export function detectAzureEndpoint(baseUrl) {
|
|
92
|
+
export function detectAzureEndpoint({ baseUrl }, _optional = {}) {
|
|
89
93
|
if (typeof baseUrl !== 'string' || !baseUrl)
|
|
90
94
|
return false;
|
|
91
95
|
if (/\.azure\.com\b/i.test(baseUrl))
|
|
@@ -95,7 +99,7 @@ export function detectAzureEndpoint(baseUrl) {
|
|
|
95
99
|
return false;
|
|
96
100
|
}
|
|
97
101
|
/** Rewrites a pathname to end in `/{endpoint}/generations` or (images only) `/images/edits`, preserving any other path prefix. */
|
|
98
|
-
export function normalizeOpenAICompatiblePath(pathname, endpoint, mode) {
|
|
102
|
+
export function normalizeOpenAICompatiblePath({ pathname, endpoint, mode }, _optional = {}) {
|
|
99
103
|
const strippedPath = trimCharsEnd({ text: pathname, chars: '/' });
|
|
100
104
|
const generationsSuffix = `/${endpoint}/generations`;
|
|
101
105
|
if (endpoint === 'videos') {
|
|
@@ -114,9 +118,9 @@ function buildOpenAICompatibleUrl(baseUrl, endpoint, mode) {
|
|
|
114
118
|
parsed = new URL(baseUrl);
|
|
115
119
|
}
|
|
116
120
|
catch {
|
|
117
|
-
return normalizeOpenAICompatiblePath(baseUrl, endpoint, mode);
|
|
121
|
+
return normalizeOpenAICompatiblePath({ pathname: baseUrl, endpoint, mode });
|
|
118
122
|
}
|
|
119
|
-
parsed.pathname = normalizeOpenAICompatiblePath(parsed.pathname, endpoint, mode);
|
|
123
|
+
parsed.pathname = normalizeOpenAICompatiblePath({ pathname: parsed.pathname, endpoint, mode });
|
|
120
124
|
return parsed.toString();
|
|
121
125
|
}
|
|
122
126
|
/** Appends the default Azure `api-version` when the endpoint is Azure and the caller didn't supply one. */
|
|
@@ -126,12 +130,12 @@ function applyDefaultAzureApiVersion(parsed, isAzure) {
|
|
|
126
130
|
}
|
|
127
131
|
}
|
|
128
132
|
/** Builds the full `/{endpoint}/generations` URL, preserving any user-supplied query string. */
|
|
129
|
-
export function buildOpenAICompatibleGenerationUrl(baseUrl, endpoint) {
|
|
133
|
+
export function buildOpenAICompatibleGenerationUrl({ baseUrl, endpoint }, _optional = {}) {
|
|
130
134
|
return buildOpenAICompatibleUrl(baseUrl, endpoint, 'generations');
|
|
131
135
|
}
|
|
132
136
|
/** Builds the `/images/generations` URL, appending the default Azure `api-version` when the caller didn't supply one. */
|
|
133
|
-
export function buildOpenAIImageUrl(baseUrl, isAzure) {
|
|
134
|
-
const url = buildOpenAICompatibleGenerationUrl(baseUrl, 'images');
|
|
137
|
+
export function buildOpenAIImageUrl({ baseUrl, isAzure }, _optional = {}) {
|
|
138
|
+
const url = buildOpenAICompatibleGenerationUrl({ baseUrl, endpoint: 'images' });
|
|
135
139
|
let parsed;
|
|
136
140
|
try {
|
|
137
141
|
parsed = new URL(url);
|
|
@@ -145,12 +149,12 @@ export function buildOpenAIImageUrl(baseUrl, isAzure) {
|
|
|
145
149
|
return parsed.toString();
|
|
146
150
|
}
|
|
147
151
|
/** Builds the `/images/edits` URL (used when a reference image is present). */
|
|
148
|
-
export function buildOpenAIImageEditUrl(baseUrl) {
|
|
152
|
+
export function buildOpenAIImageEditUrl({ baseUrl }, _optional = {}) {
|
|
149
153
|
return buildOpenAICompatibleUrl(baseUrl, 'images', 'edits');
|
|
150
154
|
}
|
|
151
155
|
/** Builds the `/videos/generations` URL. */
|
|
152
|
-
export function buildOpenAIVideoUrl(baseUrl) {
|
|
153
|
-
return buildOpenAICompatibleGenerationUrl(baseUrl, 'videos');
|
|
156
|
+
export function buildOpenAIVideoUrl({ baseUrl }, _optional = {}) {
|
|
157
|
+
return buildOpenAICompatibleGenerationUrl({ baseUrl, endpoint: 'videos' });
|
|
154
158
|
}
|
|
155
159
|
// gpt-image-1.5 / gpt-image-2 accept arbitrary sizes up to 4096; concrete
|
|
156
160
|
// sizes tuned to common aspects are picked so the API never negotiates
|
|
@@ -175,11 +179,11 @@ function sizeTableFor(model) {
|
|
|
175
179
|
return SQUARE_ONLY_SIZES;
|
|
176
180
|
}
|
|
177
181
|
/** Picks an image `size` string tuned to the model family + requested aspect ratio, defaulting to the `1024x1024` square. */
|
|
178
|
-
export function openaiSizeFor(model, aspect) {
|
|
182
|
+
export function openaiSizeFor({ model }, { aspect } = {}) {
|
|
179
183
|
return sizeTableFor(model).get(aspect ?? '') ?? '1024x1024';
|
|
180
184
|
}
|
|
181
185
|
/** Builds the `/audio/speech` URL, appending the default Azure `api-version` when the caller didn't supply one. */
|
|
182
|
-
export function buildOpenAISpeechUrl(baseUrl, isAzure) {
|
|
186
|
+
export function buildOpenAISpeechUrl({ baseUrl, isAzure }, _optional = {}) {
|
|
183
187
|
let parsed;
|
|
184
188
|
try {
|
|
185
189
|
parsed = new URL(baseUrl);
|
|
@@ -193,16 +197,16 @@ export function buildOpenAISpeechUrl(baseUrl, isAzure) {
|
|
|
193
197
|
return parsed.toString();
|
|
194
198
|
}
|
|
195
199
|
/** Parses an OpenAI-compatible JSON response, throwing a clear, provider-tagged error on a non-OK status or non-JSON body. */
|
|
196
|
-
export async function parseOpenAICompatibleJson(resp, providerTag) {
|
|
200
|
+
export async function parseOpenAICompatibleJson({ resp, providerTag }, _optional = {}) {
|
|
197
201
|
const text = await resp.text();
|
|
198
202
|
if (!resp.ok) {
|
|
199
|
-
throw new Error(`${providerTag} ${resp.status}: ${truncate(text, 240)}`);
|
|
203
|
+
throw new Error(`${providerTag} ${resp.status}: ${truncate({ s: text, n: 240 })}`);
|
|
200
204
|
}
|
|
201
205
|
try {
|
|
202
206
|
return JSON.parse(text);
|
|
203
207
|
}
|
|
204
208
|
catch {
|
|
205
|
-
throw new Error(`${providerTag} non-JSON response: ${truncate(text, 200)}`);
|
|
209
|
+
throw new Error(`${providerTag} non-JSON response: ${truncate({ s: text, n: 200 })}`);
|
|
206
210
|
}
|
|
207
211
|
}
|
|
208
212
|
/** Extracts generated bytes from an OpenAI-compatible `{ data: [{ b64_json | url }] }` response.
|
|
@@ -24,7 +24,7 @@ import { partitionArgs } from '../../args.js';
|
|
|
24
24
|
* queue it already runs — this package performs no I/O of its own beyond the vendor calls it is
|
|
25
25
|
* handed a guarded `httpClient` for, a standing invariant across `@jini-ai/integrations/media-providers`.
|
|
26
26
|
*/
|
|
27
|
-
import { FETCH_TIMEOUT_MS } from '@jini-ai/
|
|
27
|
+
import { FETCH_TIMEOUT_MS } from '@jini-ai/core/net';
|
|
28
28
|
import { fetchMediaOutbound, requireMediaHttpClient } from './outbound.js';
|
|
29
29
|
/** Interactive budget for the inline attempt. Deliberately NOT `FETCH_TIMEOUT_MS.GENERATE` (10min) — that is the backstop for the *request*, this is the ceiling on making a human wait. */
|
|
30
30
|
export const DEFAULT_GRACE_MS = 4_000;
|
|
@@ -51,7 +51,7 @@ function toOperationError(error) {
|
|
|
51
51
|
}
|
|
52
52
|
async function performSigned(deps, request, timeoutMs) {
|
|
53
53
|
const signed = await deps.signer({ request: request });
|
|
54
|
-
return fetchMediaOutbound({ url: signed.url, timeoutMs
|
|
54
|
+
return fetchMediaOutbound({ url: signed.url, timeoutMs, httpClient: requireMediaHttpClient(deps) }, { ...deps, init: signed.init });
|
|
55
55
|
}
|
|
56
56
|
/** Thread only the outbound capability into parsers; stores and signers remain runtime-private.
|
|
57
57
|
* Both callers parse a response that `performSigned` just fetched through the client, so the client
|
|
@@ -116,15 +116,15 @@ export async function startOperation(required, optional = {}) {
|
|
|
116
116
|
const startedAt = now();
|
|
117
117
|
const operationId = newId();
|
|
118
118
|
// Before any HTTP call — this ordering IS the crash-safety mechanism.
|
|
119
|
-
await deps.store.create(...partitionArgs({
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
119
|
+
await deps.store.create(...partitionArgs({ value: {
|
|
120
|
+
id: operationId,
|
|
121
|
+
providerId: params.providerId,
|
|
122
|
+
routeKey: params.routeKey,
|
|
123
|
+
ownerRef: params.ownerRef,
|
|
124
|
+
maxAttempts: params.maxAttempts ?? DEFAULT_MAX_ATTEMPTS,
|
|
125
|
+
deadlineAt: startedAt + (params.deadlineMs ?? DEFAULT_DEADLINE_MS),
|
|
126
|
+
nextPollAt: startedAt,
|
|
127
|
+
}, requiredKeys: ["id", "providerId", "routeKey", "ownerRef", "maxAttempts", "deadlineAt"] }));
|
|
128
128
|
const settle = (async () => {
|
|
129
129
|
const submitted = await submitAndParse(deps, params);
|
|
130
130
|
if (!submitted.ok) {
|
|
@@ -185,12 +185,12 @@ export async function pollDueOperations(required, optional = {}) {
|
|
|
185
185
|
const deps = { ...required, ...optional };
|
|
186
186
|
const params = { ...required, ...optional };
|
|
187
187
|
const now = deps.clock ?? Date.now;
|
|
188
|
-
const claimed = await deps.store.claimDue(...partitionArgs({
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
188
|
+
const claimed = await deps.store.claimDue(...partitionArgs({ value: {
|
|
189
|
+
now: now(),
|
|
190
|
+
leaseOwner: params.leaseOwner,
|
|
191
|
+
leaseMs: params.leaseMs,
|
|
192
|
+
...(params.limit !== undefined ? { limit: params.limit } : {}),
|
|
193
|
+
}, requiredKeys: ["now", "leaseOwner", "leaseMs"] }));
|
|
194
194
|
const tally = { completed: 0, failed: 0, pending: 0, unknown: 0 };
|
|
195
195
|
for (const row of claimed) {
|
|
196
196
|
tally[await advanceClaimedRow({ row, deps, params, now })] += 1;
|
|
@@ -348,7 +348,7 @@ export async function recoverAfterRestart(required, optional = {}) {
|
|
|
348
348
|
*/
|
|
349
349
|
async function collectSubmitted(store) {
|
|
350
350
|
const seen = new Map();
|
|
351
|
-
for (const row of await store.claimDue(...partitionArgs({ now: Number.MAX_SAFE_INTEGER, leaseOwner: RECOVERY_LEASE_OWNER, leaseMs: 0, limit: Number.MAX_SAFE_INTEGER }, ["now", "leaseOwner", "leaseMs"]))) {
|
|
351
|
+
for (const row of await store.claimDue(...partitionArgs({ value: { now: Number.MAX_SAFE_INTEGER, leaseOwner: RECOVERY_LEASE_OWNER, leaseMs: 0, limit: Number.MAX_SAFE_INTEGER }, requiredKeys: ["now", "leaseOwner", "leaseMs"] }))) {
|
|
352
352
|
if (row.status === 'submitted')
|
|
353
353
|
seen.set(row.id, row);
|
|
354
354
|
await store.releaseLease({ id: row.id, leaseOwner: RECOVERY_LEASE_OWNER });
|
|
@@ -21,11 +21,11 @@ export declare const defaultMediaOutboundMessages: {
|
|
|
21
21
|
* @throws Policy refusals, DNS/transport failures, unsupported bodies or methods.
|
|
22
22
|
* @complexity O(h + b) for h headers and b bounded decoded response bytes.
|
|
23
23
|
*/
|
|
24
|
-
export declare function fetchMediaOutbound({ url, timeoutMs }: {
|
|
24
|
+
export declare function fetchMediaOutbound({ url, timeoutMs, httpClient }: {
|
|
25
25
|
url: string;
|
|
26
26
|
timeoutMs: number;
|
|
27
|
-
}, { init, httpClient, outboundMessages }: MediaOutboundOptions & {
|
|
28
27
|
httpClient: HttpClientPort;
|
|
28
|
+
}, { init, outboundMessages }?: Omit<MediaOutboundOptions, 'httpClient'> & {
|
|
29
29
|
init?: RequestInit;
|
|
30
30
|
}): Promise<Response>;
|
|
31
31
|
/** Resolve the trusted client on legacy context carriers without constructing a fallback.
|
|
@@ -12,7 +12,7 @@ export const defaultMediaOutboundMessages = {
|
|
|
12
12
|
* @throws Policy refusals, DNS/transport failures, unsupported bodies or methods.
|
|
13
13
|
* @complexity O(h + b) for h headers and b bounded decoded response bytes.
|
|
14
14
|
*/
|
|
15
|
-
export async function fetchMediaOutbound({ url, timeoutMs }, { init = {},
|
|
15
|
+
export async function fetchMediaOutbound({ url, timeoutMs, httpClient }, { init = {}, outboundMessages } = {}) {
|
|
16
16
|
const messages = { ...defaultMediaOutboundMessages, ...outboundMessages };
|
|
17
17
|
// Every wire refusal happens before any I/O starts.
|
|
18
18
|
const { method, body } = validateMediaWireRequest({ init, messages });
|
|
@@ -84,7 +84,7 @@ export interface PollingVendorAdapter<Meta = undefined> {
|
|
|
84
84
|
* own `build*` to that same adapter's `parse*` — so erasing it here is sound, unlike the `never`
|
|
85
85
|
* that `VendorAdapterRegistry` uses (which is only sound because every caller re-casts).
|
|
86
86
|
*/
|
|
87
|
-
export type AnyPollingVendorAdapter = PollingVendorAdapter<
|
|
87
|
+
export type AnyPollingVendorAdapter = PollingVendorAdapter<unknown>;
|
|
88
88
|
/** A signed request, ready to hand to `fetch`. */
|
|
89
89
|
export interface SignedVendorRequest {
|
|
90
90
|
readonly url: string;
|