@jini-ai/integrations 0.7.2 → 0.7.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -8
- 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 +16 -18
- 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
|
@@ -35,7 +35,9 @@ export declare const AIHUBMIX_APP_CODE = "DMCY9912";
|
|
|
35
35
|
/** Default base URL assumed when a caller leaves `baseUrl` unset. */
|
|
36
36
|
export declare const AIHUBMIX_DEFAULT_BASE_URL = "https://aihubmix.com/v1";
|
|
37
37
|
/** Outbound header set for an AIHubMix Bearer-authenticated request: `Authorization` plus the `APP-Code` attribution header. */
|
|
38
|
-
export declare function aihubmixHeaders(apiKey
|
|
38
|
+
export declare function aihubmixHeaders({ apiKey }: {
|
|
39
|
+
apiKey: string;
|
|
40
|
+
}, _optional?: Record<string, never>): Record<string, string>;
|
|
39
41
|
/** The `APP-Code` attribution header on its own (no auth) — for routes that carry their own auth header (e.g. Gemini-native's `x-goog-api-key`), spread alongside it so every AIHubMix request still carries `APP-Code`. */
|
|
40
42
|
export declare function aihubmixAppCodeHeader(): Record<string, string>;
|
|
41
43
|
export type AIHubMixProtocol = 'openai' | 'anthropic' | 'gemini';
|
|
@@ -45,11 +47,18 @@ export type AIHubMixProtocol = 'openai' | 'anthropic' | 'gemini';
|
|
|
45
47
|
* fidelity the recommended client pattern is to call each family on its
|
|
46
48
|
* native wire/endpoint rather than the unified OpenAI endpoint.
|
|
47
49
|
*/
|
|
48
|
-
export declare function classifyAIHubMixModel(model
|
|
50
|
+
export declare function classifyAIHubMixModel({ model }: {
|
|
51
|
+
model: string;
|
|
52
|
+
}, _optional?: Record<string, never>): AIHubMixProtocol;
|
|
49
53
|
/** Origin of the configured AIHubMix base URL, falling back to the canonical AIHubMix host on an unparseable input. */
|
|
50
|
-
export declare function aihubmixOriginFromBase(baseUrl
|
|
54
|
+
export declare function aihubmixOriginFromBase({ baseUrl }: {
|
|
55
|
+
baseUrl: string;
|
|
56
|
+
}, _optional?: Record<string, never>): string;
|
|
51
57
|
/** Gemini-native `generateContent` endpoint for an AIHubMix image model. */
|
|
52
|
-
export declare function aihubmixGeminiImageUrl(baseUrl
|
|
58
|
+
export declare function aihubmixGeminiImageUrl({ baseUrl, wireModel }: {
|
|
59
|
+
baseUrl: string;
|
|
60
|
+
wireModel: string;
|
|
61
|
+
}, _optional?: Record<string, never>): string;
|
|
53
62
|
export interface AIHubMixGeminiImageRequest {
|
|
54
63
|
readonly baseUrl: string;
|
|
55
64
|
readonly apiKey: string;
|
|
@@ -67,6 +76,11 @@ export interface AIHubMixGeminiImageRequest {
|
|
|
67
76
|
* (proxy dispatcher, abort signal); throws on a non-OK status or a
|
|
68
77
|
* response without inline image data.
|
|
69
78
|
*/
|
|
70
|
-
export declare function aihubmixGeminiImageBytes(req
|
|
71
|
-
|
|
79
|
+
export declare function aihubmixGeminiImageBytes({ req, doFetch }: {
|
|
80
|
+
req: AIHubMixGeminiImageRequest;
|
|
81
|
+
doFetch: (url: string, init: RequestInit) => Promise<Response>;
|
|
82
|
+
}, _optional?: Record<string, never>): Promise<Buffer>;
|
|
83
|
+
export declare function aihubmixWireModel({ catalogId }: {
|
|
84
|
+
catalogId: string;
|
|
85
|
+
}, _optional?: Record<string, never>): string;
|
|
72
86
|
//# sourceMappingURL=aihubmix-shared.d.ts.map
|
|
@@ -35,7 +35,7 @@ export const AIHUBMIX_APP_CODE = 'DMCY9912';
|
|
|
35
35
|
/** Default base URL assumed when a caller leaves `baseUrl` unset. */
|
|
36
36
|
export const AIHUBMIX_DEFAULT_BASE_URL = 'https://aihubmix.com/v1';
|
|
37
37
|
/** Outbound header set for an AIHubMix Bearer-authenticated request: `Authorization` plus the `APP-Code` attribution header. */
|
|
38
|
-
export function aihubmixHeaders(apiKey) {
|
|
38
|
+
export function aihubmixHeaders({ apiKey }, _optional = {}) {
|
|
39
39
|
return {
|
|
40
40
|
authorization: `Bearer ${apiKey}`,
|
|
41
41
|
'APP-Code': AIHUBMIX_APP_CODE,
|
|
@@ -51,7 +51,7 @@ export function aihubmixAppCodeHeader() {
|
|
|
51
51
|
* fidelity the recommended client pattern is to call each family on its
|
|
52
52
|
* native wire/endpoint rather than the unified OpenAI endpoint.
|
|
53
53
|
*/
|
|
54
|
-
export function classifyAIHubMixModel(model) {
|
|
54
|
+
export function classifyAIHubMixModel({ model }, _optional = {}) {
|
|
55
55
|
const m = (model || '').trim().toLowerCase();
|
|
56
56
|
// Gemini: gemini*/imagen*, excluding -nothink/-search suffixes and any
|
|
57
57
|
// embedding model (those stay on the OpenAI-compatible path).
|
|
@@ -63,7 +63,7 @@ export function classifyAIHubMixModel(model) {
|
|
|
63
63
|
return 'openai';
|
|
64
64
|
}
|
|
65
65
|
/** Origin of the configured AIHubMix base URL, falling back to the canonical AIHubMix host on an unparseable input. */
|
|
66
|
-
export function aihubmixOriginFromBase(baseUrl) {
|
|
66
|
+
export function aihubmixOriginFromBase({ baseUrl }, _optional = {}) {
|
|
67
67
|
try {
|
|
68
68
|
return new URL(baseUrl || AIHUBMIX_DEFAULT_BASE_URL).origin;
|
|
69
69
|
}
|
|
@@ -72,8 +72,8 @@ export function aihubmixOriginFromBase(baseUrl) {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
/** Gemini-native `generateContent` endpoint for an AIHubMix image model. */
|
|
75
|
-
export function aihubmixGeminiImageUrl(baseUrl, wireModel) {
|
|
76
|
-
return `${aihubmixOriginFromBase(baseUrl)}/gemini/v1beta/models/${encodeURIComponent(wireModel)}:generateContent`;
|
|
75
|
+
export function aihubmixGeminiImageUrl({ baseUrl, wireModel }, _optional = {}) {
|
|
76
|
+
return `${aihubmixOriginFromBase({ baseUrl })}/gemini/v1beta/models/${encodeURIComponent(wireModel)}:generateContent`;
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* Generates an image through AIHubMix's Gemini-native `generateContent`
|
|
@@ -84,8 +84,8 @@ export function aihubmixGeminiImageUrl(baseUrl, wireModel) {
|
|
|
84
84
|
* (proxy dispatcher, abort signal); throws on a non-OK status or a
|
|
85
85
|
* response without inline image data.
|
|
86
86
|
*/
|
|
87
|
-
export async function aihubmixGeminiImageBytes(req, doFetch) {
|
|
88
|
-
const url = aihubmixGeminiImageUrl(req.baseUrl, req.wireModel);
|
|
87
|
+
export async function aihubmixGeminiImageBytes({ req, doFetch }, _optional = {}) {
|
|
88
|
+
const url = aihubmixGeminiImageUrl({ baseUrl: req.baseUrl, wireModel: req.wireModel });
|
|
89
89
|
const resp = await doFetch(url, {
|
|
90
90
|
method: 'POST',
|
|
91
91
|
redirect: 'error',
|
|
@@ -125,7 +125,7 @@ const AIHUBMIX_WIRE_MODELS = {
|
|
|
125
125
|
'aihubmix-dall-e-3': 'dall-e-3',
|
|
126
126
|
'aihubmix-tts-1': 'tts-1',
|
|
127
127
|
};
|
|
128
|
-
export function aihubmixWireModel(catalogId) {
|
|
128
|
+
export function aihubmixWireModel({ catalogId }, _optional = {}) {
|
|
129
129
|
return AIHUBMIX_WIRE_MODELS[catalogId] ?? catalogId.replace(/^aihubmix-/, '');
|
|
130
130
|
}
|
|
131
131
|
//# sourceMappingURL=aihubmix-shared.js.map
|
|
@@ -65,11 +65,11 @@ const aihubmixImageAdapter = {
|
|
|
65
65
|
buildRequest({ ctx, credentials }) {
|
|
66
66
|
const apiKey = credentials.apiKey; // requireCredential already validated this.
|
|
67
67
|
const baseUrl = credentials.baseUrl || AIHUBMIX_DEFAULT_BASE_URL;
|
|
68
|
-
const wireModel = aihubmixWireModel(credentials.model || ctx.wireModel);
|
|
69
|
-
if (classifyAIHubMixModel(wireModel) === 'gemini') {
|
|
68
|
+
const wireModel = aihubmixWireModel({ catalogId: credentials.model || ctx.wireModel });
|
|
69
|
+
if (classifyAIHubMixModel({ model: wireModel }) === 'gemini') {
|
|
70
70
|
const aspect = ctx.aspect || '1:1';
|
|
71
71
|
return {
|
|
72
|
-
url: aihubmixGeminiImageUrl(baseUrl, wireModel),
|
|
72
|
+
url: aihubmixGeminiImageUrl({ baseUrl, wireModel }),
|
|
73
73
|
init: withRequestInit(ctx, {
|
|
74
74
|
method: 'POST',
|
|
75
75
|
redirect: 'error',
|
|
@@ -93,7 +93,7 @@ const aihubmixImageAdapter = {
|
|
|
93
93
|
model: wireModel,
|
|
94
94
|
prompt: ctx.prompt || DEFAULT_IMAGE_PROMPT,
|
|
95
95
|
n: 1,
|
|
96
|
-
size: openaiSizeFor(wireModel, ctx.aspect),
|
|
96
|
+
size: openaiSizeFor({ model: wireModel }, { aspect: ctx.aspect }),
|
|
97
97
|
};
|
|
98
98
|
if (wireModel.startsWith('dall-e-')) {
|
|
99
99
|
body.response_format = 'b64_json';
|
|
@@ -103,10 +103,10 @@ const aihubmixImageAdapter = {
|
|
|
103
103
|
body.quality = 'high';
|
|
104
104
|
}
|
|
105
105
|
return {
|
|
106
|
-
url: buildOpenAIImageUrl(baseUrl, false),
|
|
106
|
+
url: buildOpenAIImageUrl({ baseUrl, isAzure: false }),
|
|
107
107
|
init: withRequestInit(ctx, {
|
|
108
108
|
method: 'POST',
|
|
109
|
-
headers: { 'content-type': 'application/json', ...aihubmixHeaders(apiKey) },
|
|
109
|
+
headers: { 'content-type': 'application/json', ...aihubmixHeaders({ apiKey }) },
|
|
110
110
|
body: JSON.stringify(body),
|
|
111
111
|
}),
|
|
112
112
|
meta: { kind: 'openai', wireModel },
|
|
@@ -141,14 +141,14 @@ async function parseGeminiImageResponse({ resp, meta }) {
|
|
|
141
141
|
async function parseOpenAIImageResponse({ resp, ctx, meta }) {
|
|
142
142
|
const text = await resp.text();
|
|
143
143
|
if (!resp.ok) {
|
|
144
|
-
throw new Error(`aihubmix ${resp.status}: ${truncate(text, 240)}`);
|
|
144
|
+
throw new Error(`aihubmix ${resp.status}: ${truncate({ s: text, n: 240 })}`);
|
|
145
145
|
}
|
|
146
146
|
let data;
|
|
147
147
|
try {
|
|
148
148
|
data = JSON.parse(text);
|
|
149
149
|
}
|
|
150
150
|
catch {
|
|
151
|
-
throw new Error(`aihubmix non-JSON response: ${truncate(text, 200)}`);
|
|
151
|
+
throw new Error(`aihubmix non-JSON response: ${truncate({ s: text, n: 200 })}`);
|
|
152
152
|
}
|
|
153
153
|
const entry = Array.isArray(data.data) ? data.data[0] : undefined;
|
|
154
154
|
if (!entry)
|
|
@@ -179,16 +179,16 @@ const aihubmixTTSAdapter = {
|
|
|
179
179
|
buildRequest({ ctx, credentials }) {
|
|
180
180
|
const apiKey = credentials.apiKey; // requireCredential already validated this.
|
|
181
181
|
const baseUrl = credentials.baseUrl || AIHUBMIX_DEFAULT_BASE_URL;
|
|
182
|
-
const wireModel = aihubmixWireModel(credentials.model || ctx.wireModel);
|
|
183
|
-
const format = resolveSpeechFormat(ctx.speechFormat);
|
|
182
|
+
const wireModel = aihubmixWireModel({ catalogId: credentials.model || ctx.wireModel });
|
|
183
|
+
const format = resolveSpeechFormat({ requested: ctx.speechFormat });
|
|
184
184
|
const text = (ctx.prompt && ctx.prompt.trim()) || 'This is a test.';
|
|
185
185
|
const requestedVoice = (ctx.voice && ctx.voice.trim()) || '';
|
|
186
186
|
const voice = requestedVoice && OPENAI_TTS_VOICES.has(requestedVoice) ? requestedVoice : 'alloy';
|
|
187
187
|
return {
|
|
188
|
-
url: buildOpenAISpeechUrl(baseUrl, false),
|
|
188
|
+
url: buildOpenAISpeechUrl({ baseUrl, isAzure: false }),
|
|
189
189
|
init: withRequestInit(ctx, {
|
|
190
190
|
method: 'POST',
|
|
191
|
-
headers: { 'content-type': 'application/json', ...aihubmixHeaders(apiKey) },
|
|
191
|
+
headers: { 'content-type': 'application/json', ...aihubmixHeaders({ apiKey }) },
|
|
192
192
|
body: JSON.stringify({ model: wireModel, input: text, voice, response_format: format }),
|
|
193
193
|
}),
|
|
194
194
|
meta: { wireModel, voice, format },
|
|
@@ -45,18 +45,18 @@ const customImageAdapter = {
|
|
|
45
45
|
if (credentials.apiKey) {
|
|
46
46
|
headers.authorization = `Bearer ${credentials.apiKey}`;
|
|
47
47
|
}
|
|
48
|
-
const size = openaiSizeFor('gpt-image-1', ctx.aspect);
|
|
48
|
+
const size = openaiSizeFor({ model: 'gpt-image-1' }, { aspect: ctx.aspect });
|
|
49
49
|
const body = {
|
|
50
50
|
prompt: ctx.prompt || 'A high-quality reference image.',
|
|
51
51
|
model: wireModel,
|
|
52
52
|
n: 1,
|
|
53
53
|
size,
|
|
54
54
|
};
|
|
55
|
-
let url = buildOpenAIImageUrl(baseUrl, false);
|
|
55
|
+
let url = buildOpenAIImageUrl({ baseUrl, isAzure: false });
|
|
56
56
|
if (ctx.imageRef?.dataUrl) {
|
|
57
57
|
body.response_format = 'b64_json';
|
|
58
58
|
body.images = [{ image_url: ctx.imageRef.dataUrl }];
|
|
59
|
-
url = buildOpenAIImageEditUrl(baseUrl);
|
|
59
|
+
url = buildOpenAIImageEditUrl({ baseUrl });
|
|
60
60
|
}
|
|
61
61
|
return {
|
|
62
62
|
url,
|
|
@@ -69,7 +69,7 @@ const customImageAdapter = {
|
|
|
69
69
|
};
|
|
70
70
|
},
|
|
71
71
|
async parseResponse({ resp, ctx, request }) {
|
|
72
|
-
const data = await parseOpenAICompatibleJson(resp, 'custom image');
|
|
72
|
+
const data = await parseOpenAICompatibleJson({ resp, providerTag: 'custom image' });
|
|
73
73
|
const bytes = await bytesFromOpenAICompatibleData({ data, providerTag: 'custom image' }, ctx);
|
|
74
74
|
return {
|
|
75
75
|
bytes,
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* `PROVIDER_CREDENTIAL_ENV_VARS.fishaudio` already de-branded this to
|
|
23
23
|
* plain `FISH_AUDIO_API_KEY`.
|
|
24
24
|
*/
|
|
25
|
-
import {
|
|
25
|
+
import { jsonPostInit } from '../openai-compatible.js';
|
|
26
26
|
import { createRawBytesParser } from '../response-parsers.js';
|
|
27
27
|
import { dispatchVendorRequest, requireApiKey } from '../vendor-adapter.js';
|
|
28
28
|
const FISHAUDIO_DEFAULT_BASE_URL = 'https://api.fish.audio';
|
|
@@ -57,14 +57,7 @@ const fishAudioTTSAdapter = {
|
|
|
57
57
|
}
|
|
58
58
|
return {
|
|
59
59
|
url: `${baseUrl}/v1/tts`,
|
|
60
|
-
init:
|
|
61
|
-
method: 'POST',
|
|
62
|
-
headers: {
|
|
63
|
-
authorization: `Bearer ${apiKey}`,
|
|
64
|
-
'content-type': 'application/json',
|
|
65
|
-
},
|
|
66
|
-
body: JSON.stringify(body),
|
|
67
|
-
}),
|
|
60
|
+
init: jsonPostInit({ ctx, body }, { apiKey }),
|
|
68
61
|
meta: { wireModel },
|
|
69
62
|
};
|
|
70
63
|
},
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
* `fishaudio.ts`/`openai.ts`'s speech renderer return, so it now shares
|
|
37
37
|
* `response-parsers.ts`'s `createRawBytesParser`.
|
|
38
38
|
*/
|
|
39
|
-
import { buildOpenAIImageUrl, bytesFromOpenAICompatibleData, parseOpenAICompatibleJson, sniffImageExt, standardImageAspectFor as grokAspectFor,
|
|
39
|
+
import { buildOpenAIImageUrl, bytesFromOpenAICompatibleData, parseOpenAICompatibleJson, sniffImageExt, standardImageAspectFor as grokAspectFor, jsonPostInit } from '../openai-compatible.js';
|
|
40
40
|
import { createRawBytesParser } from '../response-parsers.js';
|
|
41
41
|
import { dispatchVendorRequest, requireApiKey } from '../vendor-adapter.js';
|
|
42
42
|
export { grokAspectFor };
|
|
@@ -55,20 +55,13 @@ const grokImageAdapter = {
|
|
|
55
55
|
response_format: 'b64_json',
|
|
56
56
|
};
|
|
57
57
|
return {
|
|
58
|
-
url: buildOpenAIImageUrl(baseUrl, false),
|
|
59
|
-
init:
|
|
60
|
-
method: 'POST',
|
|
61
|
-
headers: {
|
|
62
|
-
authorization: `Bearer ${apiKey}`,
|
|
63
|
-
'content-type': 'application/json',
|
|
64
|
-
},
|
|
65
|
-
body: JSON.stringify(body),
|
|
66
|
-
}),
|
|
58
|
+
url: buildOpenAIImageUrl({ baseUrl, isAzure: false }),
|
|
59
|
+
init: jsonPostInit({ ctx, body }, { apiKey }),
|
|
67
60
|
meta: { wireModel: ctx.wireModel, aspectRatio },
|
|
68
61
|
};
|
|
69
62
|
},
|
|
70
63
|
async parseResponse({ resp, ctx, request }) {
|
|
71
|
-
const data = await parseOpenAICompatibleJson(resp, 'grok image');
|
|
64
|
+
const data = await parseOpenAICompatibleJson({ resp, providerTag: 'grok image' });
|
|
72
65
|
const bytes = await bytesFromOpenAICompatibleData({ data, providerTag: 'grok image' }, ctx);
|
|
73
66
|
return {
|
|
74
67
|
bytes,
|
|
@@ -101,14 +94,7 @@ const xaiTTSAdapter = {
|
|
|
101
94
|
const body = { text, voice_id: voiceId, language };
|
|
102
95
|
return {
|
|
103
96
|
url: `${baseUrl}/tts`,
|
|
104
|
-
init:
|
|
105
|
-
method: 'POST',
|
|
106
|
-
headers: {
|
|
107
|
-
authorization: `Bearer ${apiKey}`,
|
|
108
|
-
'content-type': 'application/json',
|
|
109
|
-
},
|
|
110
|
-
body: JSON.stringify(body),
|
|
111
|
-
}),
|
|
97
|
+
init: jsonPostInit({ ctx, body }, { apiKey }),
|
|
112
98
|
meta: { wireModel: ctx.wireModel, voiceId, language },
|
|
113
99
|
};
|
|
114
100
|
},
|
|
@@ -80,6 +80,25 @@ function retryAfterField(resp) {
|
|
|
80
80
|
const retryAfterMs = retryAfterMsFrom(resp);
|
|
81
81
|
return retryAfterMs !== undefined ? { retryAfterMs } : {};
|
|
82
82
|
}
|
|
83
|
+
/** The generation request for one render; the wire model, size and duration come from the render context. */
|
|
84
|
+
function buildVideoSubmitRequest({ ctx, config, baseUrl }) {
|
|
85
|
+
const meta = videoMetaFor({ ctx, config });
|
|
86
|
+
return {
|
|
87
|
+
url: `${baseUrl}/videos/generations`,
|
|
88
|
+
init: withUnsignedRequestInit({ ctx, init: {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
headers: { 'content-type': 'application/json' },
|
|
91
|
+
body: JSON.stringify({
|
|
92
|
+
prompt: ctx.prompt || 'A short cinematic clip.',
|
|
93
|
+
model: meta.wireModel,
|
|
94
|
+
size: meta.size,
|
|
95
|
+
seconds: meta.seconds,
|
|
96
|
+
response_format: 'b64_json',
|
|
97
|
+
}),
|
|
98
|
+
} }),
|
|
99
|
+
meta,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
83
102
|
/**
|
|
84
103
|
* Builds the ImageRouter video polling adapter for a given endpoint configuration.
|
|
85
104
|
*
|
|
@@ -94,26 +113,9 @@ export function createImageRouterVideoPollingAdapter(_required, config = {}) {
|
|
|
94
113
|
// ImageRouter's generation endpoint accepts no idempotency key, so a submit that may or may
|
|
95
114
|
// not have landed cannot be safely re-issued — a duplicate submit is a duplicate charge.
|
|
96
115
|
submitIsIdempotent: false,
|
|
97
|
-
buildSubmitRequest({ ctx }) {
|
|
98
|
-
const meta = videoMetaFor({ ctx, config });
|
|
99
|
-
return {
|
|
100
|
-
url: `${baseUrl}/videos/generations`,
|
|
101
|
-
init: withUnsignedRequestInit({ ctx, init: {
|
|
102
|
-
method: 'POST',
|
|
103
|
-
headers: { 'content-type': 'application/json' },
|
|
104
|
-
body: JSON.stringify({
|
|
105
|
-
prompt: ctx.prompt || 'A short cinematic clip.',
|
|
106
|
-
model: meta.wireModel,
|
|
107
|
-
size: meta.size,
|
|
108
|
-
seconds: meta.seconds,
|
|
109
|
-
response_format: 'b64_json',
|
|
110
|
-
}),
|
|
111
|
-
} }),
|
|
112
|
-
meta,
|
|
113
|
-
};
|
|
114
|
-
},
|
|
116
|
+
buildSubmitRequest: ({ ctx }) => buildVideoSubmitRequest({ ctx, config, baseUrl }),
|
|
115
117
|
async parseSubmitResponse({ resp, ctx, request }) {
|
|
116
|
-
const data = (await parseOpenAICompatibleJson(resp, 'imagerouter video'));
|
|
118
|
+
const data = (await parseOpenAICompatibleJson({ resp, providerTag: 'imagerouter video' }));
|
|
117
119
|
if (Array.isArray(data.data))
|
|
118
120
|
return completedVideo({ data, ctx, meta: request.meta });
|
|
119
121
|
if (typeof data.id === 'string' && data.id) {
|
|
@@ -134,7 +136,7 @@ export function createImageRouterVideoPollingAdapter(_required, config = {}) {
|
|
|
134
136
|
};
|
|
135
137
|
},
|
|
136
138
|
async parsePollResponse({ resp, ctx }) {
|
|
137
|
-
const data = (await parseOpenAICompatibleJson(resp, 'imagerouter video'));
|
|
139
|
+
const data = (await parseOpenAICompatibleJson({ resp, providerTag: 'imagerouter video' }));
|
|
138
140
|
const failed = failedOutcome(data);
|
|
139
141
|
if (failed)
|
|
140
142
|
return failed;
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* `parseOpenAICompatibleJson`/`bytesFromOpenAICompatibleData` helpers
|
|
17
17
|
* directly, same as before this pass.
|
|
18
18
|
*/
|
|
19
|
-
import { buildOpenAIImageUrl, buildOpenAIVideoUrl, bytesFromOpenAICompatibleData, parseOpenAICompatibleJson, sniffImageExt,
|
|
19
|
+
import { buildOpenAIImageUrl, buildOpenAIVideoUrl, bytesFromOpenAICompatibleData, parseOpenAICompatibleJson, sniffImageExt, jsonPostInit, } from '../openai-compatible.js';
|
|
20
20
|
import { dispatchVendorRequest, requireApiKey } from '../vendor-adapter.js';
|
|
21
21
|
// Maps (not object literals) so an inherited key such as `constructor` can never resolve as an aspect.
|
|
22
22
|
const PORTRAIT_AND_4_3_SIZES = [['9:16', '576x1024'], ['4:3', '1024x768'], ['3:4', '768x1024']];
|
|
@@ -45,20 +45,13 @@ const imageRouterImageAdapter = {
|
|
|
45
45
|
output_format: 'png',
|
|
46
46
|
};
|
|
47
47
|
return {
|
|
48
|
-
url: buildOpenAIImageUrl(baseUrl, false),
|
|
49
|
-
init:
|
|
50
|
-
method: 'POST',
|
|
51
|
-
headers: {
|
|
52
|
-
authorization: `Bearer ${apiKey}`,
|
|
53
|
-
'content-type': 'application/json',
|
|
54
|
-
},
|
|
55
|
-
body: JSON.stringify(body),
|
|
56
|
-
}),
|
|
48
|
+
url: buildOpenAIImageUrl({ baseUrl, isAzure: false }),
|
|
49
|
+
init: jsonPostInit({ ctx, body }, { apiKey }),
|
|
57
50
|
meta: { wireModel, size },
|
|
58
51
|
};
|
|
59
52
|
},
|
|
60
53
|
async parseResponse({ resp, ctx, request }) {
|
|
61
|
-
const data = await parseOpenAICompatibleJson(resp, 'imagerouter image');
|
|
54
|
+
const data = await parseOpenAICompatibleJson({ resp, providerTag: 'imagerouter image' });
|
|
62
55
|
const bytes = await bytesFromOpenAICompatibleData({ data, providerTag: 'imagerouter image' }, ctx);
|
|
63
56
|
return {
|
|
64
57
|
bytes,
|
|
@@ -86,20 +79,13 @@ const imageRouterVideoAdapter = {
|
|
|
86
79
|
response_format: 'b64_json',
|
|
87
80
|
};
|
|
88
81
|
return {
|
|
89
|
-
url: buildOpenAIVideoUrl(baseUrl),
|
|
90
|
-
init:
|
|
91
|
-
method: 'POST',
|
|
92
|
-
headers: {
|
|
93
|
-
authorization: `Bearer ${apiKey}`,
|
|
94
|
-
'content-type': 'application/json',
|
|
95
|
-
},
|
|
96
|
-
body: JSON.stringify(body),
|
|
97
|
-
}),
|
|
82
|
+
url: buildOpenAIVideoUrl({ baseUrl }),
|
|
83
|
+
init: jsonPostInit({ ctx, body }, { apiKey }),
|
|
98
84
|
meta: { wireModel, size, seconds },
|
|
99
85
|
};
|
|
100
86
|
},
|
|
101
87
|
async parseResponse({ resp, ctx, request }) {
|
|
102
|
-
const data = await parseOpenAICompatibleJson(resp, 'imagerouter video');
|
|
88
|
+
const data = await parseOpenAICompatibleJson({ resp, providerTag: 'imagerouter video' });
|
|
103
89
|
const bytes = await bytesFromOpenAICompatibleData({ data, providerTag: 'imagerouter video' }, ctx);
|
|
104
90
|
const { wireModel, size, seconds } = request.meta;
|
|
105
91
|
return {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* `PROVIDER_CREDENTIAL_ENV_VARS.minimax` already de-branded this to plain
|
|
35
35
|
* `MINIMAX_API_KEY`.
|
|
36
36
|
*/
|
|
37
|
-
import {
|
|
37
|
+
import { jsonPostInit } from '../openai-compatible.js';
|
|
38
38
|
import { createHexEnvelopeAudioParser } from '../response-parsers.js';
|
|
39
39
|
import { dispatchVendorRequest, requireApiKey } from '../vendor-adapter.js';
|
|
40
40
|
const MINIMAX_DEFAULT_BASE_URL = 'https://api.minimaxi.chat/v1';
|
|
@@ -75,14 +75,7 @@ const minimaxTTSAdapter = {
|
|
|
75
75
|
};
|
|
76
76
|
return {
|
|
77
77
|
url: `${baseUrl}/t2a_v2`,
|
|
78
|
-
init:
|
|
79
|
-
method: 'POST',
|
|
80
|
-
headers: {
|
|
81
|
-
authorization: `Bearer ${apiKey}`,
|
|
82
|
-
'content-type': 'application/json',
|
|
83
|
-
},
|
|
84
|
-
body: JSON.stringify(body),
|
|
85
|
-
}),
|
|
78
|
+
init: jsonPostInit({ ctx, body }, { apiKey }),
|
|
86
79
|
meta: { wireModel, voiceId },
|
|
87
80
|
};
|
|
88
81
|
},
|
|
@@ -109,14 +109,14 @@ const nanoBananaImageAdapter = {
|
|
|
109
109
|
async parseResponse({ resp, ctx: _ctx, request }) {
|
|
110
110
|
const text = await resp.text();
|
|
111
111
|
if (!resp.ok) {
|
|
112
|
-
throw new Error(`nano-banana image ${resp.status}: ${truncate(text, 240)}`);
|
|
112
|
+
throw new Error(`nano-banana image ${resp.status}: ${truncate({ s: text, n: 240 })}`);
|
|
113
113
|
}
|
|
114
114
|
let data;
|
|
115
115
|
try {
|
|
116
116
|
data = JSON.parse(text);
|
|
117
117
|
}
|
|
118
118
|
catch {
|
|
119
|
-
throw new Error(`nano-banana image non-JSON response: ${truncate(text, 200)}`);
|
|
119
|
+
throw new Error(`nano-banana image non-JSON response: ${truncate({ s: text, n: 200 })}`);
|
|
120
120
|
}
|
|
121
121
|
const bytes = inlineImageBytesFromGenerateContent(data);
|
|
122
122
|
return {
|
|
@@ -66,7 +66,7 @@ const OPENAI_SPEECH_NO_CREDENTIAL_MESSAGE = 'no OpenAI credential — configure
|
|
|
66
66
|
function resolveOpenAITarget({ credentials }) {
|
|
67
67
|
const apiKey = credentials.apiKey; // requireCredential already validated this.
|
|
68
68
|
const rawBase = credentials.baseUrl || OPENAI_DEFAULT_BASE_URL;
|
|
69
|
-
const azure = detectAzureEndpoint(rawBase);
|
|
69
|
+
const azure = detectAzureEndpoint({ baseUrl: rawBase });
|
|
70
70
|
const headers = {
|
|
71
71
|
authorization: `Bearer ${apiKey}`,
|
|
72
72
|
'content-type': 'application/json',
|
|
@@ -98,11 +98,11 @@ const openAIImageAdapter = {
|
|
|
98
98
|
requireCredential: requireApiKey({ message: OPENAI_IMAGE_NO_CREDENTIAL_MESSAGE }),
|
|
99
99
|
buildRequest({ ctx, credentials }) {
|
|
100
100
|
const { rawBase, azure, tag, headers } = resolveOpenAITarget({ credentials });
|
|
101
|
-
const url = buildOpenAIImageUrl(rawBase, azure);
|
|
101
|
+
const url = buildOpenAIImageUrl({ baseUrl: rawBase, isAzure: azure });
|
|
102
102
|
const body = {
|
|
103
103
|
prompt: ctx.prompt || 'A high-quality reference image.',
|
|
104
104
|
n: 1,
|
|
105
|
-
size: openaiSizeFor(ctx.model, ctx.aspect),
|
|
105
|
+
size: openaiSizeFor({ model: ctx.model }, { aspect: ctx.aspect }),
|
|
106
106
|
};
|
|
107
107
|
// For non-Azure calls, include `model` in the body. Azure infers it from
|
|
108
108
|
// the deployment in the path so omitting it keeps payloads compatible
|
|
@@ -136,7 +136,7 @@ const openAIImageAdapter = {
|
|
|
136
136
|
async parseResponse({ resp, ctx, request }) {
|
|
137
137
|
const text = await resp.text();
|
|
138
138
|
if (!resp.ok) {
|
|
139
|
-
throw new Error(`${request.meta.tag} ${resp.status}: ${truncate(text, 240)}`);
|
|
139
|
+
throw new Error(`${request.meta.tag} ${resp.status}: ${truncate({ s: text, n: 240 })}`);
|
|
140
140
|
}
|
|
141
141
|
let data;
|
|
142
142
|
try {
|
|
@@ -145,7 +145,7 @@ const openAIImageAdapter = {
|
|
|
145
145
|
catch {
|
|
146
146
|
// Deliberately not azure-tag-aware — matches the origin exactly, see
|
|
147
147
|
// this module's doc comment for why.
|
|
148
|
-
throw new Error(`openai non-JSON response: ${truncate(text, 200)}`);
|
|
148
|
+
throw new Error(`openai non-JSON response: ${truncate({ s: text, n: 200 })}`);
|
|
149
149
|
}
|
|
150
150
|
const entry = Array.isArray(data.data) ? data.data[0] : null;
|
|
151
151
|
if (!entry)
|
|
@@ -180,7 +180,7 @@ const openAISpeechAdapter = {
|
|
|
180
180
|
requireCredential: requireApiKey({ message: OPENAI_SPEECH_NO_CREDENTIAL_MESSAGE }),
|
|
181
181
|
buildRequest({ ctx, credentials }) {
|
|
182
182
|
const { rawBase, azure, tag, headers } = resolveOpenAITarget({ credentials });
|
|
183
|
-
const url = buildOpenAISpeechUrl(rawBase, azure);
|
|
183
|
+
const url = buildOpenAISpeechUrl({ baseUrl: rawBase, isAzure: azure });
|
|
184
184
|
const format = ctx.speechFormat;
|
|
185
185
|
const text = ctx.prompt?.trim() || 'This is a test.';
|
|
186
186
|
const { voiceId, instructions } = resolveSpeechVoice({ voice: ctx.voice });
|
|
@@ -80,7 +80,7 @@ const openRouterImageAdapter = {
|
|
|
80
80
|
const { wireModel, aspectRatio } = request.meta;
|
|
81
81
|
const text = await resp.text();
|
|
82
82
|
if (!resp.ok) {
|
|
83
|
-
throw new Error(`openrouter image ${resp.status}: ${truncate(text, 240)}`);
|
|
83
|
+
throw new Error(`openrouter image ${resp.status}: ${truncate({ s: text, n: 240 })}`);
|
|
84
84
|
}
|
|
85
85
|
const imageUrl = extractOpenRouterImageUrl({ text, wireModel });
|
|
86
86
|
const bytes = await decodeOpenRouterImage({ imageUrl, ctx });
|
|
@@ -103,15 +103,15 @@ function extractOpenRouterImageUrl({ text, wireModel }) {
|
|
|
103
103
|
data = JSON.parse(text);
|
|
104
104
|
}
|
|
105
105
|
catch {
|
|
106
|
-
throw new Error(`openrouter image non-JSON response: ${truncate(text, 200)}`);
|
|
106
|
+
throw new Error(`openrouter image non-JSON response: ${truncate({ s: text, n: 200 })}`);
|
|
107
107
|
}
|
|
108
108
|
const images = firstChoiceImages({ data });
|
|
109
109
|
if (!Array.isArray(images) || images.length === 0) {
|
|
110
|
-
throw new Error(`openrouter image response contained no images for model ${wireModel}: ${truncate(text, 200)}`);
|
|
110
|
+
throw new Error(`openrouter image response contained no images for model ${wireModel}: ${truncate({ s: text, n: 200 })}`);
|
|
111
111
|
}
|
|
112
112
|
const imageUrl = images[0]?.image_url?.url;
|
|
113
113
|
if (typeof imageUrl !== 'string' || !imageUrl) {
|
|
114
|
-
throw new Error(`openrouter image response missing image_url.url: ${truncate(text, 200)}`);
|
|
114
|
+
throw new Error(`openrouter image response missing image_url.url: ${truncate({ s: text, n: 200 })}`);
|
|
115
115
|
}
|
|
116
116
|
return imageUrl;
|
|
117
117
|
}
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
* `PROVIDER_CREDENTIAL_ENV_VARS.senseaudio` already de-branded this to
|
|
44
44
|
* plain `SENSEAUDIO_API_KEY`.
|
|
45
45
|
*/
|
|
46
|
-
import { truncate, withRequestInit } from '../openai-compatible.js';
|
|
46
|
+
import { truncate, withRequestInit, jsonPostInit } from '../openai-compatible.js';
|
|
47
47
|
import { createHexEnvelopeAudioParser } from '../response-parsers.js';
|
|
48
48
|
import { assertAndFetchExternalAsset } from '../ssrf-guard.js';
|
|
49
49
|
import { dispatchVendorRequest, requireApiKey } from '../vendor-adapter.js';
|
|
@@ -81,14 +81,7 @@ const senseAudioTTSAdapter = {
|
|
|
81
81
|
};
|
|
82
82
|
return {
|
|
83
83
|
url: `${baseUrl}/v1/t2a_v2`,
|
|
84
|
-
init:
|
|
85
|
-
method: 'POST',
|
|
86
|
-
headers: {
|
|
87
|
-
authorization: `Bearer ${apiKey}`,
|
|
88
|
-
'content-type': 'application/json',
|
|
89
|
-
},
|
|
90
|
-
body: JSON.stringify(body),
|
|
91
|
-
}),
|
|
84
|
+
init: jsonPostInit({ ctx, body }, { apiKey }),
|
|
92
85
|
meta: { wireModel, voiceId },
|
|
93
86
|
};
|
|
94
87
|
},
|
|
@@ -133,21 +126,14 @@ const senseAudioImageAdapter = {
|
|
|
133
126
|
}
|
|
134
127
|
return {
|
|
135
128
|
url: `${baseUrl}/v1/image/sync`,
|
|
136
|
-
init:
|
|
137
|
-
method: 'POST',
|
|
138
|
-
headers: {
|
|
139
|
-
authorization: `Bearer ${apiKey}`,
|
|
140
|
-
'content-type': 'application/json',
|
|
141
|
-
},
|
|
142
|
-
body: JSON.stringify(body),
|
|
143
|
-
}),
|
|
129
|
+
init: jsonPostInit({ ctx, body }, { apiKey }),
|
|
144
130
|
meta: { size, hasReference: Boolean(reference) },
|
|
145
131
|
};
|
|
146
132
|
},
|
|
147
133
|
async parseResponse({ resp, ctx, request }) {
|
|
148
134
|
const respText = await resp.text();
|
|
149
135
|
if (!resp.ok) {
|
|
150
|
-
throw new Error(`senseaudio image ${resp.status}: ${truncate(respText, 240)}`);
|
|
136
|
+
throw new Error(`senseaudio image ${resp.status}: ${truncate({ s: respText, n: 240 })}`);
|
|
151
137
|
}
|
|
152
138
|
const url = extractSenseAudioImageUrl({ respText });
|
|
153
139
|
const bytes = await downloadSenseAudioImage({ url, ctx });
|
|
@@ -170,7 +156,7 @@ function extractSenseAudioImageUrl({ respText }) {
|
|
|
170
156
|
data = JSON.parse(respText);
|
|
171
157
|
}
|
|
172
158
|
catch {
|
|
173
|
-
throw new Error(`senseaudio image non-JSON: ${truncate(respText, 200)}`);
|
|
159
|
+
throw new Error(`senseaudio image non-JSON: ${truncate({ s: respText, n: 200 })}`);
|
|
174
160
|
}
|
|
175
161
|
if (data.base_resp && data.base_resp.status_code !== 0) {
|
|
176
162
|
throw new Error(`senseaudio image api error ${data.base_resp.status_code}: ${data.base_resp.status_msg || 'unknown'}`);
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
* `bytesFromOpenAICompatibleData` helpers directly, same as before this
|
|
47
47
|
* pass (see `imagerouter.ts`'s module doc for the identical reasoning).
|
|
48
48
|
*/
|
|
49
|
-
import { buildOpenAIImageUrl, bytesFromOpenAICompatibleData, openaiSizeFor, parseOpenAICompatibleJson,
|
|
49
|
+
import { buildOpenAIImageUrl, bytesFromOpenAICompatibleData, openaiSizeFor, parseOpenAICompatibleJson, jsonPostInit } from '../openai-compatible.js';
|
|
50
50
|
import { dispatchVendorRequest, requireApiKey } from '../vendor-adapter.js';
|
|
51
51
|
const NO_CREDENTIAL_MESSAGE = 'no Volcengine Ark credential — configure an API key or set ARK_API_KEY.';
|
|
52
52
|
const volcengineImageAdapter = {
|
|
@@ -62,23 +62,16 @@ const volcengineImageAdapter = {
|
|
|
62
62
|
// accept different size enums), so it must see the pre-alias catalog
|
|
63
63
|
// model, not the post-alias wire name — matching `openai.ts`'s own
|
|
64
64
|
// `renderOpenAIImage` (which carries the same origin-code comment).
|
|
65
|
-
size: openaiSizeFor(ctx.model, ctx.aspect),
|
|
65
|
+
size: openaiSizeFor({ model: ctx.model }, { aspect: ctx.aspect }),
|
|
66
66
|
};
|
|
67
67
|
return {
|
|
68
|
-
url: buildOpenAIImageUrl(baseUrl, false),
|
|
69
|
-
init:
|
|
70
|
-
method: 'POST',
|
|
71
|
-
headers: {
|
|
72
|
-
authorization: `Bearer ${apiKey}`,
|
|
73
|
-
'content-type': 'application/json',
|
|
74
|
-
},
|
|
75
|
-
body: JSON.stringify(body),
|
|
76
|
-
}),
|
|
68
|
+
url: buildOpenAIImageUrl({ baseUrl, isAzure: false }),
|
|
69
|
+
init: jsonPostInit({ ctx, body }, { apiKey }),
|
|
77
70
|
meta: undefined,
|
|
78
71
|
};
|
|
79
72
|
},
|
|
80
73
|
async parseResponse({ resp, ctx }) {
|
|
81
|
-
const data = await parseOpenAICompatibleJson(resp, 'volcengine image');
|
|
74
|
+
const data = await parseOpenAICompatibleJson({ resp, providerTag: 'volcengine image' });
|
|
82
75
|
const bytes = await bytesFromOpenAICompatibleData({ data, providerTag: 'volcengine image' }, ctx);
|
|
83
76
|
return {
|
|
84
77
|
bytes,
|