Files
OmniRoute/open-sse/config/mediaServiceKinds.ts
Diego Rodrigues de Sa e Souza fa0b0effbe feat(providers): derive imageToText from the OCR registry + chutes dots.ocr seed (#10400)
* feat(ocr): transformation layer on ocrRegistry (Mistral shape canonical)

* feat(ocr): Azure Document Intelligence provider (prebuilt-read, analyze+poll)

* feat(ocr): generic dispatch with per-provider transformation and DI poll loop

* test(ocr): align sanitized-500 assert with HR#12 error sanitization

The test's own title ("returns a sanitized 500") describes the new
behavior mandated by HR#12 (never leak err.message in a response body).
The old regex asserted the pre-sanitization leak (`OCR request failed:
socket closed`) as expected output, which contradicted its own title
and the sanitization this task intentionally introduced in
open-sse/handlers/ocr.ts. Scoped to this single assertion only.

* fix(ocr): fail fast on non-ok poll responses instead of misleading 504

pollOcrOperation now checks pollRes.ok and returns a sanitized 502
immediately (logging the upstream status via console.error) instead of
looping until the 30-attempt cap and surfacing a misleading timeout for
what was actually an auth/upstream error during polling.

* feat(ocr): route/docs for multi-provider /v1/ocr

- Route: map the connection's providerSpecificData.baseUrl onto
  credentials.baseUrl (resolveOcrCredentials) so azure-document-intelligence
  connections resolve their endpoint the same way every other custom-endpoint
  provider does (src/lib/providers/validation/*); previously handleOcr only
  saw a baseUrl when a caller set it directly, so the DB-backed Azure
  connection endpoint was never forwarded.
- v1OcrSchema.model is already a free-form string, no schema change needed.
- Docs: add the /v1/ocr provider table + example + Azure poll-flow note to
  API_REFERENCE.md, and describe the provider/model prefix + async poll
  behavior in openapi.yaml.
- Test: tests/unit/ocr-route-contract.test.ts covers getAllOcrModels/
  parseOcrModel for both providers and resolveOcrCredentials's mapping.

* feat(providers): derive imageToText serviceKind from the OCR registry

* feat(providers): chutes imageToText (dots.ocr seed)

* chore(quality): rebaseline gateways.ts file-size for imageToText serviceKinds

Same rebaseline as #10275 (frozen 1250 -> 1252): this branch adds the chutes
serviceKinds declaration, the second of the two data lines.

* chore(quality): rebaseline deadExports for the OCR/image-to-text series

---------

Co-authored-by: Xiangzhe <bakryun0718@proton.me>
2026-08-14 14:26:08 -03:00

77 lines
3.3 KiB
TypeScript

/**
* Media serviceKinds — derived from the backend registries.
*
* The dashboard's `/dashboard/media-providers/[kind]` pages list a provider
* under a media kind when the provider supports it. Historically this relied on
* a hand-maintained `serviceKinds` array on every provider in providers.ts,
* which had drifted badly: ~48 providers were wired into the audio/video/music/
* image/embedding registries (backend works) but declared no `serviceKinds`, so
* they never appeared in the UI.
*
* This module makes the registries the single source of truth: a provider that
* appears as a key in a media registry supports that kind, full stop. The UI
* derives membership from here instead of duplicating it by hand, so adding a
* provider to a registry automatically surfaces it — no second edit, no drift.
*
* `imageToText` is additionally derived from `OCR_PROVIDERS` (see
* `resolveProviderServiceKinds`): a provider registered in the OCR registry gets
* `imageToText` for free, no manual `serviceKinds` edit needed. Kinds without any
* backing registry (webSearch, webFetch, llm) are still declared explicitly via
* `serviceKinds` on the provider entry; callers union declared + derived sources.
*/
import { AUDIO_TRANSCRIPTION_PROVIDERS, AUDIO_SPEECH_PROVIDERS } from "./audioRegistry.ts";
import { VIDEO_PROVIDERS } from "./videoRegistry.ts";
import { MUSIC_PROVIDERS } from "./musicRegistry.ts";
import { IMAGE_PROVIDERS } from "./imageRegistry.ts";
import { EMBEDDING_PROVIDERS } from "./embeddingRegistry.ts";
import { OCR_PROVIDERS } from "./ocrRegistry.ts";
/** Media kinds whose provider membership is defined by a backend registry. */
export const MEDIA_KIND_REGISTRIES = {
stt: AUDIO_TRANSCRIPTION_PROVIDERS,
tts: AUDIO_SPEECH_PROVIDERS,
video: VIDEO_PROVIDERS,
music: MUSIC_PROVIDERS,
image: IMAGE_PROVIDERS,
embedding: EMBEDDING_PROVIDERS,
ocr: OCR_PROVIDERS,
} as const satisfies Record<string, Record<string, unknown>>;
export type RegistryMediaKind = keyof typeof MEDIA_KIND_REGISTRIES;
export const REGISTRY_MEDIA_KINDS: readonly RegistryMediaKind[] = Object.freeze(
Object.keys(MEDIA_KIND_REGISTRIES) as RegistryMediaKind[]
);
/**
* Media serviceKinds a provider supports, derived from the backend registries.
* Returns the kinds (e.g. `["tts","video","music"]`) for which `providerId`
* appears as a registry key. Empty array if the provider serves no media.
*/
export function getRegistryMediaKinds(providerId: string): RegistryMediaKind[] {
const kinds: RegistryMediaKind[] = [];
for (const kind of REGISTRY_MEDIA_KINDS) {
if (Object.prototype.hasOwnProperty.call(MEDIA_KIND_REGISTRIES[kind], providerId)) {
kinds.push(kind);
}
}
return kinds;
}
/**
* Full set of serviceKinds for a provider: the explicitly declared ones (llm,
* web*, imageToText) unioned with the media kinds derived from the registries,
* plus `imageToText` derived from the OCR registry when not already declared.
*/
export function resolveProviderServiceKinds(
providerId: string,
declared: readonly string[] | undefined
): string[] {
const set = new Set<string>(declared ?? []);
for (const kind of getRegistryMediaKinds(providerId)) set.add(kind);
if (Object.prototype.hasOwnProperty.call(OCR_PROVIDERS, providerId)) {
set.add("imageToText");
}
return [...set];
}