Files
openmotion/shared/provider-registry.ts
Heggria bfe83e68a8 Fix OpenDesign sign-in handoff, Free/Go media guidance and Codex discovery (#704)
* Wait for the service's authorization expiry before cancelling OpenDesign sign-in

OpenMotion killed the connector ten minutes after a sign-in started, but the
account service keeps a device authorization open for fifteen minutes and the
connector already waits for that expiry. Killing it early made the connector
cancel an authorization the user was still completing in the browser, so a
sign-in finished in minutes 10-15 failed and had to be repeated.

Keep a 16-minute backstop only, so the service's own expiry decides.

* Open the subscription page in the sign-in browser with an account intent

Manage subscription and Upgrade to Plus were plain links inside Studio. When an
Agent host shows Studio in its own browser, they opened there, while the
connector had signed the user in through the system default browser, so
OpenDesign asked the user to sign in again before upgrading. Nothing checked
that the browser held the same account, so a purchase could land on another
account.

The local service now builds the entry-tagged dashboard address, requests a
one-time account intent with the installation's control key for a confirmed
production sign-in, and opens /login?intentId=... in the system default
browser. The console then confirms the account before continuing to the plan
page. Without an intent the plain dashboard opens; when no browser can be
launched, Studio opens the returned link itself.

* Report Free and Go accounts as not including media whatever their balance

Free and Go plans entitle text models only; account credits never unlock media
models on them. The hint reported not-included only for a non-positive
balance, so a new account with a signup grant or a Go subscriber with its
allowance got unknown. Agents then skipped the Go upgrade guidance and sent a
user who had just bought Go back to the generic setup page.

Free and Go now report not-included regardless of balance; hasBalance is still
returned for balance messages.

* Accept Codex in media discovery and document its image route

Settings lets users pick Codex for images, but openmotion_media_use rejected
provider=codex with invalid_enum, so an Agent following that choice failed to
list Codex models. Discovery (inspect, reference, models) now accepts Codex and
returns a Codex provider guide. Project-direct generate still does not accept
Codex and now says to use openmotion_assets_use with codex:image-generation,
which already supports it.

* Keep a subscription link when the fallback popup is blocked

The fallback opened the subscription page only after the local service
replied, when browsers no longer treat the click as a user gesture.
A blocked popup now leaves a Continue in browser link next to the
button. The standalone button and link keep their content width.
2026-11-19 23:42:51 -08:00

34 lines
2.6 KiB
TypeScript

import presets from './provider-presets.json' with { type: 'json' };
import type { ProviderDefinition } from './provider-directory.ts';
export type ProviderRegistration = ProviderDefinition & {
integration: 'media' | 'compatible' | 'agent' | 'account';
keyEnvironment?: string;
originEnvironment?: string;
catalogueBaseUrl?: string;
reference?: string;
};
const media = {
atlascloud: { label: 'Atlas Cloud', baseUrl: 'https://api.atlascloud.ai', website: 'https://www.atlascloud.ai/console/api-keys', keyEnvironment: 'ATLASCLOUD_API_KEY' },
fal: { label: 'fal.ai', baseUrl: 'https://queue.fal.run', catalogueBaseUrl: 'https://api.fal.ai', website: 'https://fal.ai/dashboard/keys', keyEnvironment: 'FAL_KEY' },
opendesign: { label: 'OpenDesign Cloud', baseUrl: '', website: 'https://open-design.ai/cloud/dashboard', keyEnvironment: 'OPENDESIGN_API_KEY', originEnvironment: 'OPENDESIGN_MEDIA_ORIGIN', baseUrlEditable: true },
wavespeed: { label: 'WaveSpeedAI', baseUrl: 'https://api.wavespeed.ai', website: 'https://wavespeed.ai/accesskey', keyEnvironment: 'WAVESPEED_API_KEY' },
};
export type MediaProviderId = keyof typeof media;
export const mediaProviders = Object.keys(media) as MediaProviderId[];
/** Public metadata only; adapters and login sessions remain service-owned. */
export const providerRegistry: ProviderRegistration[] = [
{ id: 'codex', label: 'Codex', integration: 'agent', protocol: 'agent', category: 'local', kinds: ['image'], baseUrl: '', baseUrlEditable: false, reference: 'codex' },
...mediaProviders.map((id): ProviderRegistration => ({ id, integration: 'media', protocol: 'media', category: 'multimodal', kinds: ['image', 'video', 'audio'],
baseUrlEditable: false, ...media[id], reference: id, docs: `/motion-api/models/providers/${id}/reference` })),
{ id: 'account', label: 'OpenDesign', integration: 'account', protocol: 'account', category: 'account', kinds: ['text', 'image', 'video', 'audio'],
baseUrl: '', baseUrlEditable: false, website: 'https://open-design.ai/cloud', reference: 'account' },
...(presets as ProviderDefinition[]).map((provider): ProviderRegistration => ({ ...provider, integration: 'compatible', baseUrlEditable: true, reference: 'compatible' })),
];
const byId = new Map(providerRegistry.map(provider => [provider.id, provider]));
export function registeredProvider(id: string) { return byId.get(id); }
export function isMediaProvider(id: string): id is MediaProviderId { return registeredProvider(id)?.integration === 'media'; }
export function isGatewayProvider(id: string) { const integration = registeredProvider(id)?.integration; return integration === 'media' || integration === 'agent'; }