@jini-ai/integrations 0.3.5 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +84 -0
- package/README.md +72 -24
- package/dist/args.d.ts +8 -0
- package/dist/args.js +10 -0
- package/dist/argument-error.d.ts +9 -0
- package/dist/argument-error.js +7 -0
- package/dist/credentialed-http/auth-schemes.d.ts +29 -0
- package/dist/credentialed-http/auth-schemes.js +60 -0
- package/dist/credentialed-http/credentialed-request.d.ts +132 -0
- package/dist/credentialed-http/credentialed-request.js +365 -0
- package/dist/credentialed-http/index.d.ts +4 -0
- package/dist/credentialed-http/index.js +4 -0
- package/dist/credentialed-http/ports.d.ts +42 -0
- package/dist/credentialed-http/ports.js +2 -0
- package/dist/media-providers/capability-registry.d.ts +12 -4
- package/dist/media-providers/capability-registry.js +6 -6
- package/dist/media-providers/dispatch/async-operation-store.d.ts +33 -8
- package/dist/media-providers/dispatch/async-operation-store.js +20 -32
- package/dist/media-providers/dispatch/context.d.ts +7 -2
- package/dist/media-providers/dispatch/context.js +1 -1
- package/dist/media-providers/dispatch/credentials.d.ts +4 -1
- package/dist/media-providers/dispatch/credentials.js +1 -1
- package/dist/media-providers/dispatch/engine.d.ts +5 -2
- package/dist/media-providers/dispatch/engine.js +23 -15
- package/dist/media-providers/dispatch/index.d.ts +4 -1
- package/dist/media-providers/dispatch/index.js +4 -2
- package/dist/media-providers/dispatch/openai-compatible.d.ts +12 -2
- package/dist/media-providers/dispatch/openai-compatible.js +9 -5
- package/dist/media-providers/dispatch/operation-runtime.d.ts +16 -8
- package/dist/media-providers/dispatch/operation-runtime.js +93 -76
- package/dist/media-providers/dispatch/outbound.d.ts +31 -0
- package/dist/media-providers/dispatch/outbound.js +54 -0
- package/dist/media-providers/dispatch/polling-adapter.d.ts +26 -8
- package/dist/media-providers/dispatch/polling-adapter.js +2 -2
- package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts +2 -2
- package/dist/media-providers/dispatch/providers/aihubmix-shared.js +2 -2
- package/dist/media-providers/dispatch/providers/aihubmix.d.ts +8 -2
- package/dist/media-providers/dispatch/providers/aihubmix.js +15 -15
- package/dist/media-providers/dispatch/providers/custom-image.d.ts +11 -2
- package/dist/media-providers/dispatch/providers/custom-image.js +9 -8
- package/dist/media-providers/dispatch/providers/elevenlabs.d.ts +8 -2
- package/dist/media-providers/dispatch/providers/elevenlabs.js +13 -13
- package/dist/media-providers/dispatch/providers/fishaudio.d.ts +4 -1
- package/dist/media-providers/dispatch/providers/fishaudio.js +7 -7
- package/dist/media-providers/dispatch/providers/grok.d.ts +11 -3
- package/dist/media-providers/dispatch/providers/grok.js +16 -16
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.js +23 -22
- package/dist/media-providers/dispatch/providers/imagerouter.d.ts +12 -3
- package/dist/media-providers/dispatch/providers/imagerouter.js +18 -18
- package/dist/media-providers/dispatch/providers/minimax.d.ts +4 -1
- package/dist/media-providers/dispatch/providers/minimax.js +6 -6
- package/dist/media-providers/dispatch/providers/nanobanana.d.ts +4 -1
- package/dist/media-providers/dispatch/providers/nanobanana.js +7 -7
- package/dist/media-providers/dispatch/providers/openai.d.ts +8 -2
- package/dist/media-providers/dispatch/providers/openai.js +20 -27
- package/dist/media-providers/dispatch/providers/openrouter.d.ts +7 -2
- package/dist/media-providers/dispatch/providers/openrouter.js +11 -11
- package/dist/media-providers/dispatch/providers/senseaudio.d.ts +8 -2
- package/dist/media-providers/dispatch/providers/senseaudio.js +13 -13
- package/dist/media-providers/dispatch/providers/volcengine.d.ts +4 -1
- package/dist/media-providers/dispatch/providers/volcengine.js +8 -8
- package/dist/media-providers/dispatch/response-parsers.d.ts +21 -7
- package/dist/media-providers/dispatch/response-parsers.js +15 -11
- package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts +3 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.js +53 -39
- package/dist/media-providers/dispatch/ssrf-guard.d.ts +27 -14
- package/dist/media-providers/dispatch/ssrf-guard.js +46 -105
- package/dist/media-providers/dispatch/stub.d.ts +7 -2
- package/dist/media-providers/dispatch/stub.js +4 -3
- package/dist/media-providers/dispatch/types.d.ts +17 -13
- package/dist/media-providers/dispatch/vendor-adapter.d.ts +22 -5
- package/dist/media-providers/dispatch/vendor-adapter.js +13 -10
- package/dist/media-providers/dispatch/vendor-registry.d.ts +14 -4
- package/dist/media-providers/dispatch/vendor-registry.js +3 -3
- package/dist/media-providers/index.d.ts +1 -1
- package/dist/media-providers/index.js +1 -1
- package/dist/media-providers/policy.d.ts +3 -2
- package/dist/media-providers/policy.js +4 -2
- package/dist/media-providers/providers.d.ts +12 -4
- package/dist/media-providers/providers.js +3 -3
- package/dist/media-providers/staging.d.ts +8 -2
- package/dist/media-providers/staging.js +13 -4
- package/dist/media-providers/task-store.d.ts +2 -2
- package/dist/media-providers/task-store.js +2 -2
- package/dist/media-providers/tokens.js +3 -3
- package/dist/media-providers/types.d.ts +4 -4
- package/dist/media-providers/types.js +1 -1
- package/dist/media-providers/video-request.d.ts +32 -9
- package/dist/media-providers/video-request.js +15 -15
- package/dist/webhooks/delivery.d.ts +76 -0
- package/dist/webhooks/delivery.js +222 -0
- package/dist/webhooks/index.d.ts +7 -0
- package/dist/webhooks/index.js +7 -0
- package/dist/webhooks/ports.d.ts +113 -0
- package/dist/webhooks/ports.js +2 -0
- package/dist/webhooks/signing.d.ts +38 -0
- package/dist/webhooks/signing.js +83 -0
- package/dist/webhooks/signing.keyring.d.ts +8 -0
- package/dist/webhooks/signing.keyring.js +18 -0
- package/dist/webhooks/subscriptions.d.ts +78 -0
- package/dist/webhooks/subscriptions.js +139 -0
- package/dist/webhooks/types.d.ts +103 -0
- package/dist/webhooks/types.js +2 -0
- package/package.json +29 -18
- package/dist/composio/bounded-data.d.ts.map +0 -1
- package/dist/composio/bounded-data.js.map +0 -1
- package/dist/composio/catalog.d.ts.map +0 -1
- package/dist/composio/catalog.js.map +0 -1
- package/dist/composio/composio-config.d.ts.map +0 -1
- package/dist/composio/composio-config.js.map +0 -1
- package/dist/composio/composio-descriptions.d.ts.map +0 -1
- package/dist/composio/composio-descriptions.js.map +0 -1
- package/dist/composio/composio.d.ts.map +0 -1
- package/dist/composio/composio.js.map +0 -1
- package/dist/composio/errors.d.ts.map +0 -1
- package/dist/composio/errors.js.map +0 -1
- package/dist/composio/file-lock.d.ts.map +0 -1
- package/dist/composio/file-lock.js.map +0 -1
- package/dist/composio/index.d.ts.map +0 -1
- package/dist/composio/index.js.map +0 -1
- package/dist/composio/json-schema.d.ts.map +0 -1
- package/dist/composio/json-schema.js.map +0 -1
- package/dist/composio/output-protection.d.ts.map +0 -1
- package/dist/composio/output-protection.js.map +0 -1
- package/dist/composio/service.d.ts.map +0 -1
- package/dist/composio/service.js.map +0 -1
- package/dist/media-providers/capability-registry.d.ts.map +0 -1
- package/dist/media-providers/capability-registry.js.map +0 -1
- package/dist/media-providers/catalog.d.ts.map +0 -1
- package/dist/media-providers/catalog.js.map +0 -1
- package/dist/media-providers/dispatch/async-operation-store.d.ts.map +0 -1
- package/dist/media-providers/dispatch/async-operation-store.js.map +0 -1
- package/dist/media-providers/dispatch/context.d.ts.map +0 -1
- package/dist/media-providers/dispatch/context.js.map +0 -1
- package/dist/media-providers/dispatch/credentials.d.ts.map +0 -1
- package/dist/media-providers/dispatch/credentials.js.map +0 -1
- package/dist/media-providers/dispatch/engine.d.ts.map +0 -1
- package/dist/media-providers/dispatch/engine.js.map +0 -1
- package/dist/media-providers/dispatch/index.d.ts.map +0 -1
- package/dist/media-providers/dispatch/index.js.map +0 -1
- package/dist/media-providers/dispatch/openai-compatible.d.ts.map +0 -1
- package/dist/media-providers/dispatch/openai-compatible.js.map +0 -1
- package/dist/media-providers/dispatch/operation-runtime.d.ts.map +0 -1
- package/dist/media-providers/dispatch/operation-runtime.js.map +0 -1
- package/dist/media-providers/dispatch/polling-adapter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/polling-adapter.js.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix-shared.js.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix.js.map +0 -1
- package/dist/media-providers/dispatch/providers/custom-image.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/custom-image.js.map +0 -1
- package/dist/media-providers/dispatch/providers/elevenlabs.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/elevenlabs.js.map +0 -1
- package/dist/media-providers/dispatch/providers/fishaudio.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/fishaudio.js.map +0 -1
- package/dist/media-providers/dispatch/providers/grok.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/grok.js.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.js.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter.js.map +0 -1
- package/dist/media-providers/dispatch/providers/minimax.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/minimax.js.map +0 -1
- package/dist/media-providers/dispatch/providers/nanobanana.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/nanobanana.js.map +0 -1
- package/dist/media-providers/dispatch/providers/openai.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/openai.js.map +0 -1
- package/dist/media-providers/dispatch/providers/openrouter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/openrouter.js.map +0 -1
- package/dist/media-providers/dispatch/providers/senseaudio.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/senseaudio.js.map +0 -1
- package/dist/media-providers/dispatch/providers/volcengine.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/volcengine.js.map +0 -1
- package/dist/media-providers/dispatch/response-parsers.d.ts.map +0 -1
- package/dist/media-providers/dispatch/response-parsers.js.map +0 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts.map +0 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.js.map +0 -1
- package/dist/media-providers/dispatch/ssrf-guard.d.ts.map +0 -1
- package/dist/media-providers/dispatch/ssrf-guard.js.map +0 -1
- package/dist/media-providers/dispatch/stub.d.ts.map +0 -1
- package/dist/media-providers/dispatch/stub.js.map +0 -1
- package/dist/media-providers/dispatch/types.d.ts.map +0 -1
- package/dist/media-providers/dispatch/types.js.map +0 -1
- package/dist/media-providers/dispatch/vendor-adapter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/vendor-adapter.js.map +0 -1
- package/dist/media-providers/dispatch/vendor-registry.d.ts.map +0 -1
- package/dist/media-providers/dispatch/vendor-registry.js.map +0 -1
- package/dist/media-providers/index.d.ts.map +0 -1
- package/dist/media-providers/index.js.map +0 -1
- package/dist/media-providers/policy.d.ts.map +0 -1
- package/dist/media-providers/policy.js.map +0 -1
- package/dist/media-providers/providers.d.ts.map +0 -1
- package/dist/media-providers/providers.js.map +0 -1
- package/dist/media-providers/seed.d.ts.map +0 -1
- package/dist/media-providers/seed.js.map +0 -1
- package/dist/media-providers/sqlite-task-store.d.ts.map +0 -1
- package/dist/media-providers/sqlite-task-store.js.map +0 -1
- package/dist/media-providers/staging.d.ts.map +0 -1
- package/dist/media-providers/staging.js.map +0 -1
- package/dist/media-providers/task-store.d.ts.map +0 -1
- package/dist/media-providers/task-store.js.map +0 -1
- package/dist/media-providers/tokens.d.ts.map +0 -1
- package/dist/media-providers/tokens.js.map +0 -1
- package/dist/media-providers/types.d.ts.map +0 -1
- package/dist/media-providers/types.js.map +0 -1
- package/dist/media-providers/video-request.d.ts.map +0 -1
- package/dist/media-providers/video-request.js.map +0 -1
|
@@ -1,27 +1,39 @@
|
|
|
1
|
-
import { ASYNC_OPERATION_SCHEMA_VERSION, assertNoCredentialMaterial, assertTransition, hydrateAsyncOperationRecord, TERMINAL_STATUSES, } from './async-operation-store.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { ASYNC_OPERATION_SCHEMA_VERSION, ASYNC_OPERATION_STATUSES, assertNoCredentialMaterial, assertTransition, hydrateAsyncOperationRecord, TERMINAL_STATUSES, } from './async-operation-store.js';
|
|
2
|
+
/**
|
|
3
|
+
* The non-terminal ("live") status values — `ASYNC_OPERATION_STATUSES` minus `TERMINAL_STATUSES`,
|
|
4
|
+
* built once so this file cannot itself drift from either source set. Used as a positive
|
|
5
|
+
* `status IN (?, ?)` predicate in place of `status NOT IN (?, ?, ?)` in the claim and reconcile
|
|
6
|
+
* queries below: `NOT IN` on `idx_jini_async_operations_claim`'s leading column is not sargable —
|
|
7
|
+
* confirmed via `EXPLAIN QUERY PLAN` against this repo's pinned `better-sqlite3`, `NOT IN` produces
|
|
8
|
+
* `SCAN jini_async_operations` while `IN` produces `SEARCH ... USING INDEX
|
|
9
|
+
* idx_jini_async_operations_claim (status=? AND next_poll_at<?)` — because a b-tree index can be
|
|
10
|
+
* walked to find rows a positive predicate matches, but not to skip rows a negated one excludes.
|
|
11
|
+
* Without this, the index created for exactly this query is dead weight and every poll cycle scans
|
|
12
|
+
* the whole table.
|
|
13
|
+
*/
|
|
14
|
+
const LIVE_STATUSES = new Set(ASYNC_OPERATION_STATUSES.filter((status) => !TERMINAL_STATUSES.has(status)));
|
|
15
|
+
const LIVE_LIST = [...LIVE_STATUSES];
|
|
16
|
+
const LIVE_PLACEHOLDERS = LIVE_LIST.map(() => '?').join(', ');
|
|
5
17
|
function rowToOperation(row) {
|
|
6
|
-
return hydrateAsyncOperationRecord({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
} });
|
|
25
37
|
}
|
|
26
38
|
/**
|
|
27
39
|
* Opens (creating if absent) a `better-sqlite3` database at `dbPath` and returns an
|
|
@@ -32,7 +44,7 @@ function rowToOperation(row) {
|
|
|
32
44
|
* operation exactly as it was left, and `recoverAfterRestart`/`reconcileOnBoot` can then release
|
|
33
45
|
* dead leases and expire blown deadlines.
|
|
34
46
|
*/
|
|
35
|
-
export async function createSqliteAsyncOperationStore(dbPath) {
|
|
47
|
+
export async function createSqliteAsyncOperationStore({ dbPath }) {
|
|
36
48
|
const { default: Database } = await import('better-sqlite3');
|
|
37
49
|
const db = new Database(dbPath);
|
|
38
50
|
db.pragma('journal_mode = WAL');
|
|
@@ -73,14 +85,14 @@ export async function createSqliteAsyncOperationStore(dbPath) {
|
|
|
73
85
|
`);
|
|
74
86
|
const listByOwnerStmt = db.prepare('SELECT * FROM jini_async_operations WHERE owner_ref = ? ORDER BY created_at ASC');
|
|
75
87
|
const releaseLeaseStmt = db.prepare('UPDATE jini_async_operations SET lease_owner = NULL, lease_expires_at = NULL, updated_at = ? WHERE id = ? AND lease_owner = ?');
|
|
76
|
-
// Variadic bind params (a `now`/`limit` mix plus a spread of `
|
|
88
|
+
// Variadic bind params (a `now`/`limit` mix plus a spread of `LIVE_LIST`) don't fit a fixed
|
|
77
89
|
// tuple type — `better-sqlite3`'s `Statement` defaults to `unknown[]` when left unspecified.
|
|
78
90
|
const claimDueStmt = db.prepare(`
|
|
79
91
|
UPDATE jini_async_operations
|
|
80
92
|
SET lease_owner = ?, lease_expires_at = ?, updated_at = ?
|
|
81
93
|
WHERE id IN (
|
|
82
94
|
SELECT id FROM jini_async_operations
|
|
83
|
-
WHERE status
|
|
95
|
+
WHERE status IN (${LIVE_PLACEHOLDERS})
|
|
84
96
|
AND next_poll_at <= ?
|
|
85
97
|
AND (lease_expires_at IS NULL OR lease_expires_at <= ?)
|
|
86
98
|
ORDER BY next_poll_at ASC
|
|
@@ -91,13 +103,13 @@ export async function createSqliteAsyncOperationStore(dbPath) {
|
|
|
91
103
|
const deadlineExpireStmt = db.prepare(`
|
|
92
104
|
UPDATE jini_async_operations
|
|
93
105
|
SET status = 'unknown', lease_owner = NULL, lease_expires_at = NULL, error = ?, updated_at = ?
|
|
94
|
-
WHERE status
|
|
106
|
+
WHERE status IN (${LIVE_PLACEHOLDERS}) AND deadline_at <= ?
|
|
95
107
|
RETURNING *
|
|
96
108
|
`);
|
|
97
109
|
const releaseDeadLeasesStmt = db.prepare(`
|
|
98
110
|
UPDATE jini_async_operations
|
|
99
111
|
SET lease_owner = NULL, lease_expires_at = NULL, updated_at = ?
|
|
100
|
-
WHERE status
|
|
112
|
+
WHERE status IN (${LIVE_PLACEHOLDERS}) AND lease_owner IS NOT NULL AND (lease_expires_at IS NULL OR lease_expires_at <= ?)
|
|
101
113
|
RETURNING *
|
|
102
114
|
`);
|
|
103
115
|
function stateJson(state) {
|
|
@@ -113,7 +125,7 @@ export async function createSqliteAsyncOperationStore(dbPath) {
|
|
|
113
125
|
if (!Number.isFinite(input.deadlineAt)) {
|
|
114
126
|
throw new RangeError(`Invalid deadlineAt: ${input.deadlineAt} must be a finite epoch-ms timestamp`);
|
|
115
127
|
}
|
|
116
|
-
assertNoCredentialMaterial(input.state);
|
|
128
|
+
assertNoCredentialMaterial({ state: input.state });
|
|
117
129
|
const now = Date.now();
|
|
118
130
|
const status = input.status ?? 'submitted';
|
|
119
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);
|
|
@@ -130,7 +142,7 @@ export async function createSqliteAsyncOperationStore(dbPath) {
|
|
|
130
142
|
return existing;
|
|
131
143
|
}
|
|
132
144
|
if ('state' in patch)
|
|
133
|
-
assertNoCredentialMaterial(patch.state);
|
|
145
|
+
assertNoCredentialMaterial({ state: patch.state });
|
|
134
146
|
const status = patch.status ?? existing.status;
|
|
135
147
|
assertTransition(existing.status, status);
|
|
136
148
|
const next = {
|
|
@@ -150,7 +162,7 @@ export async function createSqliteAsyncOperationStore(dbPath) {
|
|
|
150
162
|
const claimDueTxn = db.transaction((options) => {
|
|
151
163
|
const { now, leaseOwner, leaseMs } = options;
|
|
152
164
|
const limit = options.limit ?? 10;
|
|
153
|
-
const rows = claimDueStmt.all(leaseOwner, now + leaseMs, now, ...
|
|
165
|
+
const rows = claimDueStmt.all(leaseOwner, now + leaseMs, now, ...LIVE_LIST, now, now, limit);
|
|
154
166
|
return rows.map(rowToOperation);
|
|
155
167
|
});
|
|
156
168
|
const reconcileTxn = db.transaction((options) => {
|
|
@@ -159,28 +171,30 @@ export async function createSqliteAsyncOperationStore(dbPath) {
|
|
|
159
171
|
message: 'async operation passed its absolute deadline while unattended — vendor-side effect is undetermined',
|
|
160
172
|
code: 'DEADLINE_EXPIRED',
|
|
161
173
|
});
|
|
162
|
-
const deadlineExpired = deadlineExpireStmt.all(deadlineExpiredError, now, ...
|
|
163
|
-
const leasesReleased = releaseDeadLeasesStmt.all(now, ...
|
|
174
|
+
const deadlineExpired = deadlineExpireStmt.all(deadlineExpiredError, now, ...LIVE_LIST, now).length;
|
|
175
|
+
const leasesReleased = releaseDeadLeasesStmt.all(now, ...LIVE_LIST, now).length;
|
|
164
176
|
return { leasesReleased, deadlineExpired };
|
|
165
177
|
});
|
|
166
178
|
return {
|
|
167
|
-
async create(
|
|
179
|
+
async create(required, optional = {}) {
|
|
180
|
+
const input = { ...required, ...optional };
|
|
168
181
|
return createTxn(input);
|
|
169
182
|
},
|
|
170
|
-
async get(id) {
|
|
183
|
+
async get({ id }) {
|
|
171
184
|
const row = getStmt.get(id);
|
|
172
185
|
return row ? rowToOperation(row) : null;
|
|
173
186
|
},
|
|
174
|
-
async update(id, patch, options) {
|
|
187
|
+
async update({ id, patch }, { options } = {}) {
|
|
175
188
|
return updateTxn(id, patch, options);
|
|
176
189
|
},
|
|
177
|
-
async listByOwner(ownerRef) {
|
|
190
|
+
async listByOwner({ ownerRef }) {
|
|
178
191
|
return listByOwnerStmt.all(ownerRef).map(rowToOperation);
|
|
179
192
|
},
|
|
180
|
-
async claimDue(
|
|
193
|
+
async claimDue(required, optional = {}) {
|
|
194
|
+
const options = { ...required, ...optional };
|
|
181
195
|
return claimDueTxn(options);
|
|
182
196
|
},
|
|
183
|
-
async releaseLease(id, leaseOwner) {
|
|
197
|
+
async releaseLease({ id, leaseOwner }) {
|
|
184
198
|
releaseLeaseStmt.run(Date.now(), id, leaseOwner);
|
|
185
199
|
},
|
|
186
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;
|