diff --git a/open-sse/config/mediaServiceKinds.ts b/open-sse/config/mediaServiceKinds.ts index 22a692c971..77141c7757 100644 --- a/open-sse/config/mediaServiceKinds.ts +++ b/open-sse/config/mediaServiceKinds.ts @@ -13,9 +13,11 @@ * 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. * - * Kinds without a backing registry (imageToText, webSearch, webFetch, llm) are - * still declared explicitly via `serviceKinds` on the provider entry; callers - * union the two sources. + * `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"; @@ -58,7 +60,8 @@ export function getRegistryMediaKinds(providerId: string): RegistryMediaKind[] { /** * Full set of serviceKinds for a provider: the explicitly declared ones (llm, - * web*, imageToText) unioned with the media kinds derived from the registries. + * 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, @@ -66,5 +69,8 @@ export function resolveProviderServiceKinds( ): string[] { const set = new Set(declared ?? []); for (const kind of getRegistryMediaKinds(providerId)) set.add(kind); + if (Object.prototype.hasOwnProperty.call(OCR_PROVIDERS, providerId)) { + set.add("imageToText"); + } return [...set]; } diff --git a/tests/unit/imagetotext-derivation.test.ts b/tests/unit/imagetotext-derivation.test.ts new file mode 100644 index 0000000000..1074d42b7b --- /dev/null +++ b/tests/unit/imagetotext-derivation.test.ts @@ -0,0 +1,14 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { resolveProviderServiceKinds } from "../../open-sse/config/mediaServiceKinds.ts"; + +test("OCR-registry providers derive imageToText without manual declaration", () => { + assert.ok(resolveProviderServiceKinds("mistral", undefined).includes("imageToText")); + assert.ok( + resolveProviderServiceKinds("azure-document-intelligence", undefined).includes("imageToText") + ); +}); + +test("non-OCR providers do not gain imageToText implicitly", () => { + assert.ok(!resolveProviderServiceKinds("groq", undefined).includes("imageToText")); +});