@jini-ai/integrations 0.4.2 → 0.6.10
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 +99 -1
- package/README.md +1 -0
- package/dist/api-connections/access-token.d.ts +9 -0
- package/dist/api-connections/access-token.js +92 -0
- package/dist/api-connections/account-actions.d.ts +40 -0
- package/dist/api-connections/account-actions.js +110 -0
- package/dist/api-connections/attempt-state.d.ts +28 -0
- package/dist/api-connections/attempt-state.js +73 -0
- package/dist/api-connections/authorization.d.ts +45 -0
- package/dist/api-connections/authorization.js +120 -0
- package/dist/api-connections/deps.d.ts +41 -0
- package/dist/api-connections/deps.js +13 -0
- package/dist/api-connections/descriptor.d.ts +6 -0
- package/dist/api-connections/descriptor.js +111 -0
- package/dist/api-connections/errors.d.ts +23 -0
- package/dist/api-connections/errors.js +24 -0
- package/dist/api-connections/finish-authorization.d.ts +24 -0
- package/dist/api-connections/finish-authorization.js +117 -0
- package/dist/api-connections/index.d.ts +18 -0
- package/dist/api-connections/index.js +10 -0
- package/dist/api-connections/install-credential.d.ts +19 -0
- package/dist/api-connections/install-credential.js +12 -0
- package/dist/api-connections/keys.d.ts +27 -0
- package/dist/api-connections/keys.js +22 -0
- package/dist/api-connections/ports.d.ts +73 -0
- package/dist/api-connections/ports.js +2 -0
- package/dist/api-connections/records.d.ts +27 -0
- package/dist/api-connections/records.js +52 -0
- package/dist/api-connections/request-checks.d.ts +18 -0
- package/dist/api-connections/request-checks.js +67 -0
- package/dist/api-connections/service.d.ts +25 -0
- package/dist/api-connections/service.js +26 -0
- package/dist/api-connections/status.d.ts +28 -0
- package/dist/api-connections/status.js +36 -0
- package/dist/api-connections/token-store/errors.d.ts +20 -0
- package/dist/api-connections/token-store/errors.js +38 -0
- package/dist/api-connections/token-store/index.d.ts +6 -0
- package/dist/api-connections/token-store/index.js +6 -0
- package/dist/api-connections/token-store/record.d.ts +69 -0
- package/dist/api-connections/token-store/record.js +97 -0
- package/dist/api-connections/token-store/vault-token-store.d.ts +26 -0
- package/dist/api-connections/token-store/vault-token-store.js +215 -0
- package/dist/api-connections/types.d.ts +101 -0
- package/dist/api-connections/types.js +9 -0
- package/dist/credentialed-http/auth-schemes.js +8 -4
- package/dist/credentialed-http/credentialed-request.d.ts +4 -0
- package/dist/credentialed-http/credentialed-request.js +61 -77
- package/dist/credentialed-http/response-redaction.d.ts +15 -0
- package/dist/credentialed-http/response-redaction.js +82 -0
- package/dist/media-providers/catalog.d.ts +3 -1
- package/dist/media-providers/catalog.js +3 -1
- package/dist/media-providers/dispatch/async-operation-store.d.ts +31 -0
- package/dist/media-providers/dispatch/async-operation-store.js +75 -37
- package/dist/media-providers/dispatch/builtin-vendors.d.ts +1 -1
- package/dist/media-providers/dispatch/context.js +10 -2
- package/dist/media-providers/dispatch/engine.d.ts +6 -3
- package/dist/media-providers/dispatch/engine.js +99 -109
- package/dist/media-providers/dispatch/index.d.ts +4 -2
- package/dist/media-providers/dispatch/index.js +3 -1
- package/dist/media-providers/dispatch/media-provider-registry.d.ts +62 -0
- package/dist/media-providers/dispatch/media-provider-registry.js +141 -0
- package/dist/media-providers/dispatch/node.d.ts +13 -0
- package/dist/media-providers/dispatch/node.js +24 -0
- package/dist/media-providers/dispatch/openai-compatible.d.ts +1 -1
- package/dist/media-providers/dispatch/openai-compatible.js +90 -87
- package/dist/media-providers/dispatch/operation-runtime.js +116 -89
- package/dist/media-providers/dispatch/outbound.d.ts +8 -4
- package/dist/media-providers/dispatch/outbound.js +27 -26
- package/dist/media-providers/dispatch/providers/aihubmix.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/aihubmix.js +61 -56
- package/dist/media-providers/dispatch/providers/custom-image.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/elevenlabs.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/fishaudio.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/grok.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.js +53 -49
- package/dist/media-providers/dispatch/providers/imagerouter.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/imagerouter.js +11 -24
- package/dist/media-providers/dispatch/providers/minimax.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/nanobanana.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/nanobanana.js +22 -30
- package/dist/media-providers/dispatch/providers/openai.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/openai.js +51 -47
- package/dist/media-providers/dispatch/providers/openrouter.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/openrouter.js +52 -37
- package/dist/media-providers/dispatch/providers/senseaudio.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/senseaudio.js +47 -28
- package/dist/media-providers/dispatch/providers/volcengine.d.ts +1 -1
- package/dist/media-providers/dispatch/response-parsers.js +37 -21
- package/dist/media-providers/dispatch/sqlite-async-operation-store.js +9 -29
- package/dist/media-providers/dispatch/ssrf-guard.d.ts +3 -2
- package/dist/media-providers/dispatch/ssrf-guard.js +6 -5
- package/dist/media-providers/dispatch/types.d.ts +76 -2
- package/dist/media-providers/dispatch/vendor-adapter.d.ts +2 -43
- package/dist/media-providers/dispatch/vendor-adapter.js +2 -2
- package/dist/media-providers/dispatch/vendor-registry-core.d.ts +24 -0
- package/dist/media-providers/dispatch/vendor-registry-core.js +34 -0
- package/dist/media-providers/dispatch/vendor-registry.d.ts +10 -36
- package/dist/media-providers/dispatch/vendor-registry.js +14 -42
- package/dist/media-providers/policy.js +25 -17
- package/dist/media-providers/providers.d.ts +5 -0
- package/dist/media-providers/providers.js +2 -0
- package/dist/media-providers/sqlite-task-store.js +12 -80
- package/dist/media-providers/staging.js +77 -58
- package/dist/media-providers/task-lifecycle.d.ts +33 -0
- package/dist/media-providers/task-lifecycle.js +124 -0
- package/dist/media-providers/task-store.js +8 -86
- package/dist/media-providers/ui-defaults.d.ts +10 -0
- package/dist/media-providers/ui-defaults.js +167 -0
- package/dist/media-providers/video-request.js +112 -90
- package/dist/saved-requests/definition.d.ts +17 -0
- package/dist/saved-requests/definition.js +84 -0
- package/dist/saved-requests/execute.d.ts +17 -0
- package/dist/saved-requests/execute.js +95 -0
- package/dist/saved-requests/index.d.ts +6 -0
- package/dist/saved-requests/index.js +4 -0
- package/dist/saved-requests/projection.d.ts +9 -0
- package/dist/saved-requests/projection.js +48 -0
- package/dist/saved-requests/schema.d.ts +7 -0
- package/dist/saved-requests/schema.js +73 -0
- package/dist/saved-requests/types.d.ts +58 -0
- package/dist/saved-requests/types.js +2 -0
- package/dist/saved-requests/validation.d.ts +46 -0
- package/dist/saved-requests/validation.js +66 -0
- package/dist/webhooks/delivery.d.ts +14 -0
- package/dist/webhooks/delivery.js +41 -10
- package/dist/webhooks/index.d.ts +1 -0
- package/dist/webhooks/index.js +1 -0
- package/dist/webhooks/ports.d.ts +23 -0
- package/dist/webhooks/worker.d.ts +83 -0
- package/dist/webhooks/worker.js +105 -0
- package/package.json +46 -9
|
@@ -22,8 +22,9 @@ import type { RequiredArgs, OptionalArgs } from '../../args.js';
|
|
|
22
22
|
* filesystem-backed `AttachmentStaging` adapter copies and prunes local
|
|
23
23
|
* attachments; provider dispatch performs network I/O through its transport.
|
|
24
24
|
*/
|
|
25
|
+
import type { HttpClientPort } from '@jini-ai/core/primitives';
|
|
25
26
|
import type { MediaOutboundOptions } from './outbound.js';
|
|
26
|
-
import type { AudioKind, MediaSurface } from '../types.js';
|
|
27
|
+
import type { AudioKind, MediaModel, MediaProvider, MediaSurface } from '../types.js';
|
|
27
28
|
/** Per-provider credentials a host resolves however it wants (env vars, a secrets manager, a config file, ...). This engine never reads `process.env` itself — see `resolveProviderCredentialsFromEnv` in `credentials.ts` for an opt-in reference resolver a host may use to build this map. */
|
|
28
29
|
export interface ProviderCredentials {
|
|
29
30
|
readonly apiKey?: string;
|
|
@@ -91,7 +92,18 @@ export interface MediaGenerationResult {
|
|
|
91
92
|
/** Non-fatal notices (e.g. a requested `length`/`duration` was clamped to the nearest allowed value). */
|
|
92
93
|
readonly warnings: readonly string[];
|
|
93
94
|
}
|
|
94
|
-
|
|
95
|
+
/** Dispatch only reads routes; the host owns registration and registry lifetime. */
|
|
96
|
+
export interface VendorAdapterLookup {
|
|
97
|
+
get(required: {
|
|
98
|
+
providerId: string;
|
|
99
|
+
routeKey: string;
|
|
100
|
+
}): VendorAdapter<never> | undefined;
|
|
101
|
+
}
|
|
102
|
+
export interface MediaDispatchEngineRequired {
|
|
103
|
+
readonly registry: VendorAdapterLookup;
|
|
104
|
+
readonly httpClient: HttpClientPort;
|
|
105
|
+
}
|
|
106
|
+
export interface MediaDispatchEngineOptions extends Omit<MediaOutboundOptions, 'httpClient'> {
|
|
95
107
|
/** Per-provider credentials, keyed by provider id (see `providers.ts`'s `MEDIA_PROVIDERS` for valid ids). */
|
|
96
108
|
readonly credentials?: Readonly<Record<string, ProviderCredentials>>;
|
|
97
109
|
/**
|
|
@@ -104,6 +116,26 @@ export interface MediaDispatchEngineOptions extends MediaOutboundOptions {
|
|
|
104
116
|
* getting silent placeholders by default.
|
|
105
117
|
*/
|
|
106
118
|
readonly allowStubFallback?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Where model/provider validation reads from. Defaults to the static built-in catalogue
|
|
121
|
+
* (`providers.ts`); pass a `MediaProviderRegistry` (it implements this) so plugin-contributed
|
|
122
|
+
* vendors validate too.
|
|
123
|
+
*/
|
|
124
|
+
readonly catalog?: MediaModelCatalog;
|
|
125
|
+
}
|
|
126
|
+
/** The catalogue reads the engine validates requests against (see `media-provider-registry.ts`). */
|
|
127
|
+
export interface MediaModelCatalog {
|
|
128
|
+
findModel(required: {
|
|
129
|
+
id: string;
|
|
130
|
+
}): MediaModel | null;
|
|
131
|
+
findProvider(required: {
|
|
132
|
+
id: string;
|
|
133
|
+
}): MediaProvider | null;
|
|
134
|
+
modelsForSurface(required: {
|
|
135
|
+
surface: MediaSurface;
|
|
136
|
+
}, optional?: {
|
|
137
|
+
audioKind?: AudioKind | undefined;
|
|
138
|
+
}): readonly MediaModel[];
|
|
107
139
|
}
|
|
108
140
|
export interface MediaDispatchEngine {
|
|
109
141
|
generate(required: RequiredArgs<MediaGenerationRequest>, optional?: OptionalArgs<MediaGenerationRequest>): Promise<MediaGenerationResult>;
|
|
@@ -134,4 +166,46 @@ export interface RenderContext extends MediaOutboundOptions {
|
|
|
134
166
|
readonly speechFormat: MediaSpeechFormat;
|
|
135
167
|
readonly onProgress?: ((message: string) => void) | undefined;
|
|
136
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* One vendor HTTP request, plus any values `buildRequest` computed that
|
|
171
|
+
* `parseResponse` also needs (e.g. a resolved `wireModel`/`voiceId` for
|
|
172
|
+
* building `providerNote`). Kept out of `RenderContext` because these are
|
|
173
|
+
* per-adapter derived values, not universal fields every vendor shares.
|
|
174
|
+
*/
|
|
175
|
+
export interface VendorRequest<Meta = undefined> {
|
|
176
|
+
readonly url: string;
|
|
177
|
+
readonly init: RequestInit;
|
|
178
|
+
readonly meta: Meta;
|
|
179
|
+
}
|
|
180
|
+
export type VendorRequestBuilder<Meta = undefined> = (required: {
|
|
181
|
+
ctx: RenderContext;
|
|
182
|
+
credentials: ProviderCredentials;
|
|
183
|
+
}) => VendorRequest<Meta>;
|
|
184
|
+
/**
|
|
185
|
+
* Turns a `fetch` `Response` into a `RenderResult`, or throws a
|
|
186
|
+
* vendor-tagged `Error` — the "response-parsing + error-mapping" half of a
|
|
187
|
+
* vendor adapter. Receives `ctx`/`request` too since some vendors need a
|
|
188
|
+
* second request (an SSRF-guarded asset download, a Gemini-native
|
|
189
|
+
* redirect) to finish parsing — see vendor-adapter.ts's module comment.
|
|
190
|
+
*/
|
|
191
|
+
export type VendorResponseParser<Meta = undefined> = (required: {
|
|
192
|
+
resp: Response;
|
|
193
|
+
ctx: RenderContext;
|
|
194
|
+
request: VendorRequest<Meta>;
|
|
195
|
+
}) => Promise<RenderResult>;
|
|
196
|
+
/** Validates `credentials` before any network call, throwing a vendor-tagged `Error` when they're unusable (e.g. no API key configured). */
|
|
197
|
+
export type VendorCredentialGuard = (required: {
|
|
198
|
+
credentials: ProviderCredentials;
|
|
199
|
+
}) => void;
|
|
200
|
+
/**
|
|
201
|
+
* A fully-configured vendor: the "auth-scheme" (`requireCredential`),
|
|
202
|
+
* "request-shape" (`buildRequest`), and "response-parsing + error-mapping"
|
|
203
|
+
* (`parseResponse`) a new vendor registers instead of writing a bespoke
|
|
204
|
+
* `render*` function.
|
|
205
|
+
*/
|
|
206
|
+
export interface VendorAdapter<Meta = undefined> {
|
|
207
|
+
readonly requireCredential?: VendorCredentialGuard;
|
|
208
|
+
readonly buildRequest: VendorRequestBuilder<Meta>;
|
|
209
|
+
readonly parseResponse: VendorResponseParser<Meta>;
|
|
210
|
+
}
|
|
137
211
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,46 +1,5 @@
|
|
|
1
|
-
import type { ProviderCredentials, RenderContext, RenderResult } from './types.js';
|
|
2
|
-
|
|
3
|
-
* One vendor HTTP request, plus any values `buildRequest` computed that
|
|
4
|
-
* `parseResponse` also needs (e.g. a resolved `wireModel`/`voiceId` for
|
|
5
|
-
* building `providerNote`). Kept out of `RenderContext` because these are
|
|
6
|
-
* per-adapter derived values, not universal fields every vendor shares.
|
|
7
|
-
*/
|
|
8
|
-
export interface VendorRequest<Meta = undefined> {
|
|
9
|
-
readonly url: string;
|
|
10
|
-
readonly init: RequestInit;
|
|
11
|
-
readonly meta: Meta;
|
|
12
|
-
}
|
|
13
|
-
export type VendorRequestBuilder<Meta = undefined> = (required: {
|
|
14
|
-
ctx: RenderContext;
|
|
15
|
-
credentials: ProviderCredentials;
|
|
16
|
-
}) => VendorRequest<Meta>;
|
|
17
|
-
/**
|
|
18
|
-
* Turns a `fetch` `Response` into a `RenderResult`, or throws a
|
|
19
|
-
* vendor-tagged `Error` — the "response-parsing + error-mapping" half of a
|
|
20
|
-
* vendor adapter. Receives `ctx`/`request` too since some vendors need a
|
|
21
|
-
* second request (an SSRF-guarded asset download, a Gemini-native
|
|
22
|
-
* redirect) to finish parsing — see this module's doc comment.
|
|
23
|
-
*/
|
|
24
|
-
export type VendorResponseParser<Meta = undefined> = (required: {
|
|
25
|
-
resp: Response;
|
|
26
|
-
ctx: RenderContext;
|
|
27
|
-
request: VendorRequest<Meta>;
|
|
28
|
-
}) => Promise<RenderResult>;
|
|
29
|
-
/** Validates `credentials` before any network call, throwing a vendor-tagged `Error` when they're unusable (e.g. no API key configured). */
|
|
30
|
-
export type VendorCredentialGuard = (required: {
|
|
31
|
-
credentials: ProviderCredentials;
|
|
32
|
-
}) => void;
|
|
33
|
-
/**
|
|
34
|
-
* A fully-configured vendor: the "auth-scheme" (`requireCredential`),
|
|
35
|
-
* "request-shape" (`buildRequest`), and "response-parsing + error-mapping"
|
|
36
|
-
* (`parseResponse`) a new vendor registers instead of writing a bespoke
|
|
37
|
-
* `render*` function.
|
|
38
|
-
*/
|
|
39
|
-
export interface VendorAdapter<Meta = undefined> {
|
|
40
|
-
readonly requireCredential?: VendorCredentialGuard;
|
|
41
|
-
readonly buildRequest: VendorRequestBuilder<Meta>;
|
|
42
|
-
readonly parseResponse: VendorResponseParser<Meta>;
|
|
43
|
-
}
|
|
1
|
+
import type { ProviderCredentials, RenderContext, RenderResult, VendorAdapter, VendorCredentialGuard } from './types.js';
|
|
2
|
+
export type { VendorRequest, VendorRequestBuilder, VendorResponseParser, VendorCredentialGuard, VendorAdapter } from './types.js';
|
|
44
3
|
/**
|
|
45
4
|
* The generic dispatch core: `requireCredential` -> `buildRequest` -> one
|
|
46
5
|
* `fetch` -> `parseResponse`. Every migrated vendor's `render*` export is
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* reusable piece.
|
|
28
28
|
*/
|
|
29
29
|
import { FETCH_TIMEOUT_MS } from '@jini-ai/platform/fetch-with-timeout';
|
|
30
|
-
import { fetchMediaOutbound } from './outbound.js';
|
|
30
|
+
import { fetchMediaOutbound, requireMediaHttpClient } from './outbound.js';
|
|
31
31
|
/**
|
|
32
32
|
* The generic dispatch core: `requireCredential` -> `buildRequest` -> one
|
|
33
33
|
* `fetch` -> `parseResponse`. Every migrated vendor's `render*` export is
|
|
@@ -51,7 +51,7 @@ export async function dispatchVendorRequest({ adapter, ctx, credentials }) {
|
|
|
51
51
|
// still applies unchanged; `GENERATE` (10min) matches what those two vendors already picked
|
|
52
52
|
// deliberately for the same reason — media generation genuinely finishes on that order, not in
|
|
53
53
|
// seconds, so anything shorter would abort a legitimately still-generating request.
|
|
54
|
-
const resp = await fetchMediaOutbound({ url: request.url, timeoutMs: FETCH_TIMEOUT_MS.GENERATE }, { ...ctx, init: request.init });
|
|
54
|
+
const resp = await fetchMediaOutbound({ url: request.url, timeoutMs: FETCH_TIMEOUT_MS.GENERATE }, { ...ctx, httpClient: requireMediaHttpClient(ctx), init: request.init });
|
|
55
55
|
return adapter.parseResponse({ resp: resp, ctx: ctx, request: request });
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Host-owned registry mechanics; builtin composition lives in vendor-registry.ts. */
|
|
2
|
+
import type { VendorAdapter, VendorAdapterLookup } from './types.js';
|
|
3
|
+
export declare class VendorAdapterRegistry implements VendorAdapterLookup {
|
|
4
|
+
private readonly table;
|
|
5
|
+
/** Registers `adapter` for `(providerId, routeKey)`. Throws if that pair is already registered — populate each host registry exactly once. */
|
|
6
|
+
register<Meta>({ providerId, routeKey, adapter }: {
|
|
7
|
+
providerId: string;
|
|
8
|
+
routeKey: string;
|
|
9
|
+
adapter: VendorAdapter<Meta>;
|
|
10
|
+
}): void;
|
|
11
|
+
/** Looks up the adapter registered for `(providerId, routeKey)`, or `undefined` if none is registered. */
|
|
12
|
+
get({ providerId, routeKey }: {
|
|
13
|
+
providerId: string;
|
|
14
|
+
routeKey: string;
|
|
15
|
+
}): VendorAdapter<never> | undefined;
|
|
16
|
+
/** Whether an adapter is registered for `(providerId, routeKey)`. */
|
|
17
|
+
has({ providerId, routeKey }: {
|
|
18
|
+
providerId: string;
|
|
19
|
+
routeKey: string;
|
|
20
|
+
}): boolean;
|
|
21
|
+
/** Every `(providerId, routeKey)` pair currently registered — used by tests (and any diagnostics a host wants) to enumerate exactly which vendors run through the generic engine. */
|
|
22
|
+
list(): ReadonlyArray<readonly [providerId: string, routeKey: string]>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=vendor-registry-core.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export class VendorAdapterRegistry {
|
|
2
|
+
table = new Map();
|
|
3
|
+
/** Registers `adapter` for `(providerId, routeKey)`. Throws if that pair is already registered — populate each host registry exactly once. */
|
|
4
|
+
register({ providerId, routeKey, adapter }) {
|
|
5
|
+
let bySurface = this.table.get(providerId);
|
|
6
|
+
if (!bySurface) {
|
|
7
|
+
bySurface = new Map();
|
|
8
|
+
this.table.set(providerId, bySurface);
|
|
9
|
+
}
|
|
10
|
+
if (bySurface.has(routeKey)) {
|
|
11
|
+
throw new Error(`a vendor adapter is already registered for "${providerId}" / "${routeKey}"`);
|
|
12
|
+
}
|
|
13
|
+
bySurface.set(routeKey, adapter);
|
|
14
|
+
}
|
|
15
|
+
/** Looks up the adapter registered for `(providerId, routeKey)`, or `undefined` if none is registered. */
|
|
16
|
+
get({ providerId, routeKey }) {
|
|
17
|
+
return this.table.get(providerId)?.get(routeKey);
|
|
18
|
+
}
|
|
19
|
+
/** Whether an adapter is registered for `(providerId, routeKey)`. */
|
|
20
|
+
has({ providerId, routeKey }) {
|
|
21
|
+
return this.table.get(providerId)?.has(routeKey) ?? false;
|
|
22
|
+
}
|
|
23
|
+
/** Every `(providerId, routeKey)` pair currently registered — used by tests (and any diagnostics a host wants) to enumerate exactly which vendors run through the generic engine. */
|
|
24
|
+
list() {
|
|
25
|
+
const out = [];
|
|
26
|
+
for (const [providerId, bySurface] of this.table) {
|
|
27
|
+
for (const routeKey of bySurface.keys()) {
|
|
28
|
+
out.push([providerId, routeKey]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=vendor-registry-core.js.map
|
|
@@ -1,39 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* at a hand-written render function. A migrated vendor registers its
|
|
5
|
-
* `VendorAdapter` here, keyed by `(providerId, routeKey)` — the same
|
|
6
|
-
* `routeKey` shape `engine.ts`'s internal `routeKeyFor` already produces
|
|
7
|
-
* (`'image'`, `'video'`, `'audio:speech'`, ...). `engine.ts` consults this
|
|
8
|
-
* registry first when resolving a renderer, falling back to the static
|
|
9
|
-
* `ROUTES` table for vendors not yet migrated onto the generic engine — see
|
|
10
|
-
* `archived provenance ledger`'s 2026-07-21 dispatch-engine-generalization section for
|
|
11
|
-
* exactly which vendors are registered here today, and why the rest
|
|
12
|
-
* legitimately aren't (yet).
|
|
13
|
-
*/
|
|
14
|
-
import type { VendorAdapter } from './vendor-adapter.js';
|
|
15
|
-
export declare class VendorAdapterRegistry {
|
|
16
|
-
private readonly table;
|
|
17
|
-
/** Registers `adapter` for `(providerId, routeKey)`. Throws if that pair is already registered — a vendor module should register each of its (provider, surface) pairs exactly once, at module load. */
|
|
18
|
-
register<Meta>({ providerId, routeKey, adapter }: {
|
|
19
|
-
providerId: string;
|
|
20
|
-
routeKey: string;
|
|
21
|
-
adapter: VendorAdapter<Meta>;
|
|
22
|
-
}): void;
|
|
23
|
-
/** Looks up the adapter registered for `(providerId, routeKey)`, or `undefined` if none is registered. */
|
|
24
|
-
get({ providerId, routeKey }: {
|
|
25
|
-
providerId: string;
|
|
26
|
-
routeKey: string;
|
|
27
|
-
}): VendorAdapter<never> | undefined;
|
|
28
|
-
/** Whether an adapter is registered for `(providerId, routeKey)`. */
|
|
29
|
-
has({ providerId, routeKey }: {
|
|
30
|
-
providerId: string;
|
|
31
|
-
routeKey: string;
|
|
32
|
-
}): boolean;
|
|
33
|
-
/** Every `(providerId, routeKey)` pair currently registered — used by tests (and any diagnostics a host wants) to enumerate exactly which vendors run through the generic engine. */
|
|
34
|
-
list(): ReadonlyArray<readonly [providerId: string, routeKey: string]>;
|
|
35
|
-
}
|
|
36
|
-
/** Creates a fresh, empty registry — mainly useful for tests that want isolation from the shared `mediaVendorRegistry` singleton. */
|
|
1
|
+
import { VendorAdapterRegistry } from './vendor-registry-core.js';
|
|
2
|
+
export { VendorAdapterRegistry } from './vendor-registry-core.js';
|
|
3
|
+
/** Creates a fresh, empty registry for host-owned registrations. */
|
|
37
4
|
export declare function createVendorAdapterRegistry(): VendorAdapterRegistry;
|
|
5
|
+
/** Creates a fresh registry populated by the existing builtin-registration owner.
|
|
6
|
+
* @deprecated Adapters only, no catalogue: plugin vendors cannot validate through it. Build one
|
|
7
|
+
* `createMediaProviderRegistry()` at composition and pass it as `registry` and `catalog`.
|
|
8
|
+
* @returns An independent registry; duplicate route registration still throws.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createBuiltinVendorAdapterRegistry(_required?: Record<string, never>, _options?: Record<string, never>): VendorAdapterRegistry;
|
|
11
|
+
/** @deprecated Build one createMediaProviderRegistry() per host composition and inject it instead. */
|
|
38
12
|
export declare const mediaVendorRegistry: VendorAdapterRegistry;
|
|
39
13
|
//# sourceMappingURL=vendor-registry.d.ts.map
|
|
@@ -1,50 +1,21 @@
|
|
|
1
|
+
import { VendorAdapterRegistry } from './vendor-registry-core.js';
|
|
2
|
+
export { VendorAdapterRegistry } from './vendor-registry-core.js';
|
|
1
3
|
import { registerBuiltinVendorAdapters } from './builtin-vendors.js';
|
|
2
|
-
|
|
3
|
-
table = new Map();
|
|
4
|
-
/** Registers `adapter` for `(providerId, routeKey)`. Throws if that pair is already registered — a vendor module should register each of its (provider, surface) pairs exactly once, at module load. */
|
|
5
|
-
register({ providerId, routeKey, adapter }) {
|
|
6
|
-
let bySurface = this.table.get(providerId);
|
|
7
|
-
if (!bySurface) {
|
|
8
|
-
bySurface = new Map();
|
|
9
|
-
this.table.set(providerId, bySurface);
|
|
10
|
-
}
|
|
11
|
-
if (bySurface.has(routeKey)) {
|
|
12
|
-
throw new Error(`a vendor adapter is already registered for "${providerId}" / "${routeKey}"`);
|
|
13
|
-
}
|
|
14
|
-
bySurface.set(routeKey, adapter);
|
|
15
|
-
}
|
|
16
|
-
/** Looks up the adapter registered for `(providerId, routeKey)`, or `undefined` if none is registered. */
|
|
17
|
-
get({ providerId, routeKey }) {
|
|
18
|
-
return this.table.get(providerId)?.get(routeKey);
|
|
19
|
-
}
|
|
20
|
-
/** Whether an adapter is registered for `(providerId, routeKey)`. */
|
|
21
|
-
has({ providerId, routeKey }) {
|
|
22
|
-
return this.table.get(providerId)?.has(routeKey) ?? false;
|
|
23
|
-
}
|
|
24
|
-
/** Every `(providerId, routeKey)` pair currently registered — used by tests (and any diagnostics a host wants) to enumerate exactly which vendors run through the generic engine. */
|
|
25
|
-
list() {
|
|
26
|
-
const out = [];
|
|
27
|
-
for (const [providerId, bySurface] of this.table) {
|
|
28
|
-
for (const routeKey of bySurface.keys()) {
|
|
29
|
-
out.push([providerId, routeKey]);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return out;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/** Creates a fresh, empty registry — mainly useful for tests that want isolation from the shared `mediaVendorRegistry` singleton. */
|
|
4
|
+
/** Creates a fresh, empty registry for host-owned registrations. */
|
|
36
5
|
export function createVendorAdapterRegistry() {
|
|
37
6
|
return new VendorAdapterRegistry();
|
|
38
7
|
}
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* own vendor adapters without touching this module's set) can still call
|
|
44
|
-
* `createVendorAdapterRegistry()` directly instead of using this singleton.
|
|
8
|
+
/** Creates a fresh registry populated by the existing builtin-registration owner.
|
|
9
|
+
* @deprecated Adapters only, no catalogue: plugin vendors cannot validate through it. Build one
|
|
10
|
+
* `createMediaProviderRegistry()` at composition and pass it as `registry` and `catalog`.
|
|
11
|
+
* @returns An independent registry; duplicate route registration still throws.
|
|
45
12
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
13
|
+
export function createBuiltinVendorAdapterRegistry(_required = {}, _options = {}) {
|
|
14
|
+
const registry = createVendorAdapterRegistry();
|
|
15
|
+
registerBuiltinVendorAdapters({ registry });
|
|
16
|
+
return registry;
|
|
17
|
+
}
|
|
18
|
+
// Preserve lazy singleton contents for existing callers; engines never consult it.
|
|
48
19
|
class BuiltinVendorAdapterRegistry extends VendorAdapterRegistry {
|
|
49
20
|
initialized = false;
|
|
50
21
|
initialize() {
|
|
@@ -71,5 +42,6 @@ class BuiltinVendorAdapterRegistry extends VendorAdapterRegistry {
|
|
|
71
42
|
return super.list();
|
|
72
43
|
}
|
|
73
44
|
}
|
|
45
|
+
/** @deprecated Build one createMediaProviderRegistry() per host composition and inject it instead. */
|
|
74
46
|
export const mediaVendorRegistry = new BuiltinVendorAdapterRegistry();
|
|
75
47
|
//# sourceMappingURL=vendor-registry.js.map
|
|
@@ -4,6 +4,30 @@
|
|
|
4
4
|
// not passing a policy at all — media generation is a real-money, costly
|
|
5
5
|
// capability, not something that should be on by default.
|
|
6
6
|
export const DEFAULT_MEDIA_EXECUTION_POLICY = { mode: 'disabled' };
|
|
7
|
+
/** A missing or empty allowlist means "no restriction on that dimension". */
|
|
8
|
+
function isRestricted(allowlist) {
|
|
9
|
+
return allowlist !== undefined && allowlist.length > 0;
|
|
10
|
+
}
|
|
11
|
+
function surfaceDenial(policy, surface) {
|
|
12
|
+
if (!isRestricted(policy.allowedSurfaces) || policy.allowedSurfaces.includes(surface))
|
|
13
|
+
return null;
|
|
14
|
+
return { code: 'MEDIA_SURFACE_DENIED', message: `media surface "${surface}" is not allowed for this run` };
|
|
15
|
+
}
|
|
16
|
+
function modelDenial(policy, model) {
|
|
17
|
+
// SEC-RB-010: a model allowlist must not be bypassable by omitting the
|
|
18
|
+
// model field. If the host restricted models at all, an unspecified
|
|
19
|
+
// (or blank-after-normalization) model can't be verified against that
|
|
20
|
+
// allowlist and must be denied, not silently waved through.
|
|
21
|
+
const normalizedModel = model?.trim();
|
|
22
|
+
if (!isRestricted(policy.allowedModels))
|
|
23
|
+
return null;
|
|
24
|
+
if (normalizedModel && policy.allowedModels.includes(normalizedModel))
|
|
25
|
+
return null;
|
|
26
|
+
return {
|
|
27
|
+
code: 'MEDIA_MODEL_DENIED',
|
|
28
|
+
message: `media model ${normalizedModel ? `"${normalizedModel}"` : '(none specified)'} is not allowed for this run`,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
7
31
|
/**
|
|
8
32
|
* Reference `MediaPolicy`: an enabled/disabled + surface/model allowlist
|
|
9
33
|
* gate, ported verbatim from the origin's `mediaExecutionPolicyDenial`. A
|
|
@@ -18,23 +42,7 @@ export function createAllowlistMediaPolicy(_required, optional = {}) {
|
|
|
18
42
|
if (policy.mode === 'disabled') {
|
|
19
43
|
return { code: 'MEDIA_EXECUTION_DISABLED', message: 'media generation is disabled for this run' };
|
|
20
44
|
}
|
|
21
|
-
|
|
22
|
-
return { code: 'MEDIA_SURFACE_DENIED', message: `media surface "${target.surface}" is not allowed for this run` };
|
|
23
|
-
}
|
|
24
|
-
// SEC-RB-010: a model allowlist must not be bypassable by omitting the
|
|
25
|
-
// model field. If the host restricted models at all, an unspecified
|
|
26
|
-
// (or blank-after-normalization) model can't be verified against that
|
|
27
|
-
// allowlist and must be denied, not silently waved through.
|
|
28
|
-
const normalizedModel = target.model?.trim();
|
|
29
|
-
if (policy.allowedModels && policy.allowedModels.length > 0) {
|
|
30
|
-
if (!normalizedModel || !policy.allowedModels.includes(normalizedModel)) {
|
|
31
|
-
return {
|
|
32
|
-
code: 'MEDIA_MODEL_DENIED',
|
|
33
|
-
message: `media model ${normalizedModel ? `"${normalizedModel}"` : '(none specified)'} is not allowed for this run`,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
45
|
+
return surfaceDenial(policy, target.surface) ?? modelDenial(policy, target.model);
|
|
38
46
|
},
|
|
39
47
|
};
|
|
40
48
|
}
|
|
@@ -41,6 +41,11 @@ export declare function canonicalMediaProviderId({ id }: {
|
|
|
41
41
|
export declare function normalizeMediaProviderMap<T>({ providers }: {
|
|
42
42
|
providers: Readonly<Record<string, T>>;
|
|
43
43
|
}, _optional?: Record<string, never>): Record<string, T>;
|
|
44
|
+
/** Host-injected UI policy; reuse the catalog's existing identity and normalization owner. */
|
|
45
|
+
export declare const mediaProviderCatalogPolicy: {
|
|
46
|
+
canonicalMediaProviderId: typeof canonicalMediaProviderId;
|
|
47
|
+
normalizeMediaProviderMap: typeof normalizeMediaProviderMap;
|
|
48
|
+
};
|
|
44
49
|
export declare const MEDIA_PROVIDERS: readonly MediaProvider[];
|
|
45
50
|
export declare const IMAGE_MODELS: readonly MediaModel[];
|
|
46
51
|
export declare const VIDEO_MODELS: readonly MediaModel[];
|
|
@@ -28,6 +28,8 @@ export function normalizeMediaProviderMap({ providers }, _optional = {}) {
|
|
|
28
28
|
...entries.filter(([id]) => canonicalMediaProviderId({ id }) === id),
|
|
29
29
|
]);
|
|
30
30
|
}
|
|
31
|
+
/** Host-injected UI policy; reuse the catalog's existing identity and normalization owner. */
|
|
32
|
+
export const mediaProviderCatalogPolicy = { canonicalMediaProviderId, normalizeMediaProviderMap };
|
|
31
33
|
export const MEDIA_PROVIDERS = [
|
|
32
34
|
{ id: 'openai', label: 'OpenAI', hint: 'gpt-image-2 / dall-e-3', integrated: true, defaultBaseUrl: VENDOR_API_BASE_URLS.openai },
|
|
33
35
|
{ id: 'volcengine', label: 'Volcengine Ark (Doubao)', hint: 'Seedance 2.0 / Seedream', integrated: true, defaultBaseUrl: VENDOR_API_BASE_URLS.volcengine },
|
|
@@ -1,30 +1,9 @@
|
|
|
1
1
|
import { loadMediaSqliteOpener } from './sqlite-driver.adapter.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
'interrupted',
|
|
8
|
-
]);
|
|
9
|
-
const TERMINAL_STATUSES = new Set(['done', 'failed', 'interrupted']);
|
|
10
|
-
// Mirrors task-store.ts's own ALLOWED_TRANSITIONS exactly (CR-013: enum
|
|
11
|
-
// membership alone doesn't prove a transition is legal, e.g. done -> running).
|
|
12
|
-
const ALLOWED_TRANSITIONS = {
|
|
13
|
-
queued: new Set(['queued', 'running', 'done', 'failed', 'interrupted']),
|
|
14
|
-
running: new Set(['running', 'done', 'failed', 'interrupted']),
|
|
15
|
-
done: new Set(['done']),
|
|
16
|
-
failed: new Set(['failed']),
|
|
17
|
-
interrupted: new Set(['interrupted']),
|
|
18
|
-
};
|
|
19
|
-
const INTERRUPTED_ERROR = {
|
|
20
|
-
message: 'media task interrupted by daemon restart',
|
|
21
|
-
code: 'DAEMON_RESTART',
|
|
22
|
-
};
|
|
23
|
-
function assertValidStatus(status) {
|
|
24
|
-
if (!VALID_STATUSES.has(status)) {
|
|
25
|
-
throw new RangeError(`Invalid media task status: "${status}"`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
2
|
+
// Shared with task-store.ts's in-memory adapter (task-lifecycle.ts), so the
|
|
3
|
+
// two cannot drift: CR-013's transition graph (enum membership alone doesn't
|
|
4
|
+
// prove a transition is legal, e.g. done -> running), duplicate-free status
|
|
5
|
+
// sets, and the create/patch/reconcile row arithmetic all live there once.
|
|
6
|
+
import { applyTaskPatch, assertValidTerminalTtl, buildNewTask, reconcileAction } from './task-lifecycle.js';
|
|
28
7
|
/**
|
|
29
8
|
* Reconstructs a `MediaTask` from a stored row. `surface`/`model` are
|
|
30
9
|
* conditionally spread — matching `task-store.ts`'s own in-memory adapter,
|
|
@@ -129,24 +108,7 @@ export async function createSqliteMediaTaskStore(required, options = {}) {
|
|
|
129
108
|
if (getStmt.get(input.id)) {
|
|
130
109
|
throw new Error(`media task "${input.id}" already exists`);
|
|
131
110
|
}
|
|
132
|
-
const
|
|
133
|
-
assertValidStatus(status);
|
|
134
|
-
const now = Date.now();
|
|
135
|
-
const startedAt = input.startedAt ?? now;
|
|
136
|
-
const task = {
|
|
137
|
-
id: input.id,
|
|
138
|
-
ownerRef: input.ownerRef,
|
|
139
|
-
status,
|
|
140
|
-
progress: input.progress ? [...input.progress] : [],
|
|
141
|
-
file: input.file == null ? null : structuredClone(input.file),
|
|
142
|
-
error: input.error == null ? null : { ...input.error },
|
|
143
|
-
startedAt,
|
|
144
|
-
endedAt: null,
|
|
145
|
-
createdAt: now,
|
|
146
|
-
updatedAt: now,
|
|
147
|
-
...(input.surface !== undefined ? { surface: input.surface } : {}),
|
|
148
|
-
...(input.model !== undefined ? { model: input.model } : {}),
|
|
149
|
-
};
|
|
111
|
+
const task = buildNewTask(input, Date.now());
|
|
150
112
|
writeRow(task, true);
|
|
151
113
|
return task;
|
|
152
114
|
});
|
|
@@ -154,28 +116,7 @@ export async function createSqliteMediaTaskStore(required, options = {}) {
|
|
|
154
116
|
const row = getStmt.get(id);
|
|
155
117
|
if (!row)
|
|
156
118
|
return null;
|
|
157
|
-
const
|
|
158
|
-
const status = patch.status ?? existing.status;
|
|
159
|
-
assertValidStatus(status);
|
|
160
|
-
if (!ALLOWED_TRANSITIONS[existing.status].has(status)) {
|
|
161
|
-
throw new RangeError(`Invalid media task transition: "${existing.status}" -> "${status}"`);
|
|
162
|
-
}
|
|
163
|
-
const surface = 'surface' in patch ? (patch.surface ?? undefined) : existing.surface;
|
|
164
|
-
const model = 'model' in patch ? (patch.model ?? undefined) : existing.model;
|
|
165
|
-
const next = {
|
|
166
|
-
id: existing.id,
|
|
167
|
-
ownerRef: existing.ownerRef,
|
|
168
|
-
status,
|
|
169
|
-
progress: patch.progress ? [...patch.progress] : existing.progress,
|
|
170
|
-
file: 'file' in patch ? (patch.file == null ? null : structuredClone(patch.file)) : existing.file,
|
|
171
|
-
error: 'error' in patch ? (patch.error == null ? null : { ...patch.error }) : existing.error,
|
|
172
|
-
startedAt: existing.startedAt,
|
|
173
|
-
endedAt: 'endedAt' in patch ? (patch.endedAt ?? null) : existing.endedAt,
|
|
174
|
-
createdAt: existing.createdAt,
|
|
175
|
-
updatedAt: Date.now(),
|
|
176
|
-
...(surface !== undefined ? { surface } : {}),
|
|
177
|
-
...(model !== undefined ? { model } : {}),
|
|
178
|
-
};
|
|
119
|
+
const next = applyTaskPatch(rowToTask(row), patch, Date.now());
|
|
179
120
|
writeRow(next, false);
|
|
180
121
|
return next;
|
|
181
122
|
});
|
|
@@ -186,19 +127,12 @@ export async function createSqliteMediaTaskStore(required, options = {}) {
|
|
|
186
127
|
let deleted = 0;
|
|
187
128
|
for (const row of selectAllStmt.all()) {
|
|
188
129
|
const task = rowToTask(row);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
status: 'interrupted',
|
|
193
|
-
error: INTERRUPTED_ERROR,
|
|
194
|
-
endedAt: task.endedAt ?? now,
|
|
195
|
-
updatedAt: now,
|
|
196
|
-
};
|
|
197
|
-
writeRow(next, false);
|
|
130
|
+
const action = reconcileAction(task, now, cutoff);
|
|
131
|
+
if (action.kind === 'interrupt') {
|
|
132
|
+
writeRow(action.next, false);
|
|
198
133
|
interrupted += 1;
|
|
199
|
-
continue;
|
|
200
134
|
}
|
|
201
|
-
if (
|
|
135
|
+
else if (action.kind === 'delete') {
|
|
202
136
|
deleteStmt.run(task.id);
|
|
203
137
|
deleted += 1;
|
|
204
138
|
}
|
|
@@ -225,9 +159,7 @@ export async function createSqliteMediaTaskStore(required, options = {}) {
|
|
|
225
159
|
deleteStmt.run(id);
|
|
226
160
|
},
|
|
227
161
|
async reconcileOnBoot(options) {
|
|
228
|
-
|
|
229
|
-
throw new RangeError(`Invalid terminalTtlMs: ${options.terminalTtlMs} must be a non-negative finite number`);
|
|
230
|
-
}
|
|
162
|
+
assertValidTerminalTtl(options.terminalTtlMs);
|
|
231
163
|
return reconcileTxn(options);
|
|
232
164
|
},
|
|
233
165
|
async close() {
|