Files
openmotion/gateway/compatible.ts
Tom Huang 61ee4787c8 Unify Home navigation, provider settings, and local Agent selection (#393)
* Unify Studio navigation, provider settings, and local Agent workflows

* Serve the public provider notice from the editor file handler

The provider icon set added by this branch publishes
packages/design-system/providers/NOTICE.md through publicDesignFiles, but
serveEditorFile rejected .md because its MIME table only knew application
assets. The distribution regression test requests every public design file
and got 404 for the notice, so the attribution file was unreachable in the
editor package.

Map .md like the existing application server does (text/plain, UTF-8) so
the published notice is served with its bytes intact.

Generated-By: looper 0.16.2 (runner=fixer, agent=pi)

* Include the provider icon manifest in the bundled adapter fixture

export-adapters.ts and the bundled runtime import
packages/design-system/index.js, which now also imports provider-icons.js to
publish the provider artwork. The adapter fixture copied every runtime file
the export reads except that new module, so the bundled launch failed with
ERR_MODULE_NOT_FOUND for provider-icons.js in the distribution regression
job.

Copy the icon manifest into the fixture alongside index.js, matching the
runtime distribution list that already ships it.

Generated-By: looper 0.16.2 (runner=fixer, agent=pi)

---------

Co-authored-by: pftom <pftom@pftomdeMacBook-Pro.local>
Co-authored-by: 罗高 <luogao@users.noreply.github.com>
2026-11-15 11:56:47 +08:00

30 lines
2.0 KiB
TypeScript

import type { ProviderAdapter } from './providers.ts';
import { apiJson, publicProviderFetch, ProviderError } from './network.ts';
/** Explicit OpenAI-compatible image/speech operations; never guesses a video protocol. */
export const compatibleProvider: ProviderAdapter = {
async generate(job, context) {
if (!context.baseUrl) throw new Error('Provider API URL is required');
const fetcher = context.fetcher === fetch ? publicProviderFetch : context.fetcher;
const headers = { Authorization: `Bearer ${context.key}`, 'Content-Type': 'application/json' };
const parameters = { ...job.model.defaults, ...job.parameters };
await context.progress('submitting');
if (job.modality === 'audio') {
if (typeof parameters.voice !== 'string' || !parameters.voice.trim()) throw new Error('Choose a voice in parameters.voice');
const response = await fetcher(context.baseUrl + '/audio/speech', { method: 'POST', headers, redirect: 'error', signal: context.signal,
body: JSON.stringify({ ...parameters, model: job.model.modelId, input: job.prompt }) });
if (!response.ok) throw new ProviderError(`Provider HTTP ${response.status}`, response.status);
return [Buffer.from(await response.arrayBuffer())];
}
if (job.modality !== 'image') throw new Error('This compatible provider supports image generation and speech only');
const result = await apiJson(fetcher, context.baseUrl + '/images/generations', { method: 'POST', headers, signal: context.signal,
body: JSON.stringify({ ...parameters, model: job.model.modelId, prompt: job.prompt }) });
if (!Array.isArray(result.data) || !result.data.length) throw new Error('Provider returned no images');
return result.data.slice(0, 8).map((image: { b64_json?: string; url?: string }) => {
if (typeof image.b64_json === 'string') return Buffer.from(image.b64_json, 'base64');
if (typeof image.url === 'string') return image.url;
throw new Error('Provider returned an unsupported image response');
});
},
};