Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

refactor(gfs): remove unused provider image capability oracles

Alfredo Lopezad864c84718f
diff --git a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx
index cebc7e2bb..a521a8008 100644
--- a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx
+++ b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx
@@ -2093,7 +2093,7 @@ describe('App deep-link orchestration', () => {
emitDeepLink?.({ id: 1, appRef: 'ns/missing', teamId: 'team-b' })
})
await confirmPendingAppLink()
- await waitFor(() => expect(getSandboxUiLocation).toHaveBeenCalledTimes(1))
+ await waitFor(() => expect(getSandboxUiLocation).toHaveBeenCalledTimes(1), { timeout: 5000 })
// Supersede the handoff: switch to the seeded chat tab. The deactivation effect
// bumps the activation generation AND closes A's embed itself, all while the
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 38ed97aaf..f376de756 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.373",
+ "version": "0.1.374",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.373",
+ "version": "0.1.374",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 4f4971423..01ea2fa1e 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.373",
+ "version": "0.1.374",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/core/adapters/__tests__/failoverLlmPort.test.ts b/mcp-host/src/core/adapters/__tests__/failoverLlmPort.test.ts
index 307992ae6..97402c69e 100644
--- a/mcp-host/src/core/adapters/__tests__/failoverLlmPort.test.ts
+++ b/mcp-host/src/core/adapters/__tests__/failoverLlmPort.test.ts
@@ -260,17 +260,12 @@ describe('FailoverLlmPort — visual destination failover', () => {
)
}
- /** A provider that proves image support for exactly one model, or proves none. */
- function visionProvider(
- providerType: string,
- capability: ImageInputCapability,
- outcome: () => Promise<unknown>
- ) {
+ /** A provider transport whose catalog admission is supplied by visionAdapter. */
+ function visionProvider(providerType: string, outcome: () => Promise<unknown>) {
return {
completeSingleTurn: vi.fn(),
completeSingleTurnWithTools: vi.fn(outcome),
getProviderType: () => providerType,
- getImageInputCapability: vi.fn(() => Promise.resolve(capability)),
classifyError: (err: unknown) => {
if (err instanceof LlmError)
return { code: err.code, retryable: err.retryable, message: err.message }
@@ -303,14 +298,10 @@ describe('FailoverLlmPort — visual destination failover', () => {
}
it('rejects a fallback that cannot prove image input before calling its provider', async () => {
- const primaryProvider = visionProvider(
- 'openrouter',
- supported('openrouter', 'example/vision-model'),
- () => Promise.reject(new LlmError('429', 'openrouter', LlmErrorCode.RateLimited, true))
- )
- const fallbackProvider = visionProvider('openai', { status: 'unknown' }, () =>
- Promise.resolve(okResponse('gpt-5.4'))
+ const primaryProvider = visionProvider('openrouter', () =>
+ Promise.reject(new LlmError('429', 'openrouter', LlmErrorCode.RateLimited, true))
)
+ const fallbackProvider = visionProvider('openai', () => Promise.resolve(okResponse('gpt-5.4')))
const switches: { from: string; to: string; reason: string }[] = []
const engine = new FailoverEngine(policy, { metricInc: labels => switches.push(labels) })
const wrapped = maybeWrapFailover({
@@ -342,13 +333,11 @@ describe('FailoverLlmPort — visual destination failover', () => {
...policy,
fallbacks: [{ provider: 'openrouter', model: 'meta/llama-3.2-11b-vision' }],
}
- const primaryProvider = visionProvider('claude', supported('claude', 'claude-sonnet-4-6'), () =>
+ const primaryProvider = visionProvider('claude', () =>
Promise.reject(new LlmError('402', 'claude', LlmErrorCode.InsufficientQuota, false))
)
- const fallbackProvider = visionProvider(
- 'openrouter',
- supported('openrouter', 'meta/llama-3.2-11b-vision'),
- () => Promise.resolve(okResponse('meta/llama-3.2-11b-vision'))
+ const fallbackProvider = visionProvider('openrouter', () =>
+ Promise.resolve(okResponse('meta/llama-3.2-11b-vision'))
)
let now = 1000
const engine = new FailoverEngine(imagePolicy, { metricInc: () => {}, now: () => now })
diff --git a/mcp-host/src/core/adapters/__tests__/llmPortAdapter.imageInput.test.ts b/mcp-host/src/core/adapters/__tests__/llmPortAdapter.imageInput.test.ts
index bbad6623a..0211cc95b 100644
--- a/mcp-host/src/core/adapters/__tests__/llmPortAdapter.imageInput.test.ts
+++ b/mcp-host/src/core/adapters/__tests__/llmPortAdapter.imageInput.test.ts
@@ -159,10 +159,8 @@ describe('#654 LlmPortAdapter image guard', () => {
expect(messages[0].contentParts[0].type).toBe('image')
})
- it('uses catalog and transport evidence for GFS read admission, not provider metadata', async () => {
+ it('uses catalog and transport evidence for GFS read admission', async () => {
const provider = fakeProvider('openai')
- const providerCapability = vi.fn(async () => ({ status: 'unknown' as const }))
- provider.getImageInputCapability = providerCapability
const adapter = new LlmPortAdapter(
provider,
'new-vision-model',
@@ -180,22 +178,13 @@ describe('#654 LlmPortAdapter image guard', () => {
provider: 'openai',
model: 'new-vision-model',
})
- expect(providerCapability).not.toHaveBeenCalled()
})
- it('does not admit a GFS read from provider metadata when the catalog row is missing', async () => {
+ it('does not admit a GFS read when the catalog row is missing', async () => {
const provider = fakeProvider('openai')
- const providerCapability = vi.fn(async () => ({
- status: 'supported' as const,
- provider: 'openai',
- model: 'gpt-4.1',
- evidence: 'provider metadata',
- }))
- provider.getImageInputCapability = providerCapability
const adapter = new LlmPortAdapter(provider, 'gpt-4.1', 'openai')
await expect(adapter.getImageInputCapability()).resolves.toEqual({ status: 'unknown' })
- expect(providerCapability).not.toHaveBeenCalled()
})
it('admits Codex GFS input only for a present catalog row with a supported transport', async () => {
diff --git a/mcp-host/src/core/adapters/__tests__/llmPortAdapter.test.ts b/mcp-host/src/core/adapters/__tests__/llmPortAdapter.test.ts
index 8ee3ea435..1393f5d9a 100644
--- a/mcp-host/src/core/adapters/__tests__/llmPortAdapter.test.ts
+++ b/mcp-host/src/core/adapters/__tests__/llmPortAdapter.test.ts
@@ -702,12 +702,6 @@ describe('LlmPortAdapter image destination degrade', () => {
}
it('strips unverified image parts and continues the turn', async () => {
- const providerCapability = vi.fn(async () => ({
- status: 'supported' as const,
- provider: 'openai',
- model: 'unknown-model',
- evidence: 'provider metadata',
- }))
const completeSingleTurnWithTools = vi.fn().mockResolvedValue({
content: 'ok',
tool_calls: [],
@@ -719,7 +713,6 @@ describe('LlmPortAdapter image destination degrade', () => {
completeSingleTurn: vi.fn(),
completeSingleTurnWithTools,
getProviderType: () => 'openai' as const,
- getImageInputCapability: providerCapability,
classifyError: vi.fn(),
},
'unknown-model',
@@ -735,7 +728,6 @@ describe('LlmPortAdapter image destination degrade', () => {
).not.toEqual(expect.arrayContaining([expect.objectContaining({ type: 'image' })]))
expect(JSON.stringify(sent)).toContain('not forwarded')
expect(JSON.stringify(sent)).not.toContain('cGl4ZWwtYnl0ZXM=')
- expect(providerCapability).not.toHaveBeenCalled()
})
it('still rejects image parts that left the user visual message', async () => {
diff --git a/mcp-host/src/internalTools/gfsImageInput.integration.test.ts b/mcp-host/src/internalTools/gfsImageInput.integration.test.ts
index fc49309a1..14c828b2e 100644
--- a/mcp-host/src/internalTools/gfsImageInput.integration.test.ts
+++ b/mcp-host/src/internalTools/gfsImageInput.integration.test.ts
@@ -1,6 +1,5 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { createCanvas } from '@napi-rs/canvas'
-import { Readable } from 'node:stream'
import { LlmPortAdapter } from '../core/adapters/llmPortAdapter'
import type { NativeToolConfig } from '../core/interfaces'
import { appendToolResults } from '../core/orchestration/toolUseLoopMessages'
@@ -227,13 +226,12 @@ describe('GFS bytes to actual provider request', () => {
}
)
- it('delivers GFS pixels to a catalog-supported OpenAI model without provider allowlist evidence', async () => {
+ it('delivers GFS pixels to a catalog-supported OpenAI model absent from the old allowlist', async () => {
const client = {
baseURL: 'https://api.openai.com/v1',
chat: { completions: { create: sdkCreate } },
}
const provider = new OpenAIProvider(client as never, 'future-vision-model')
- await expect(provider.getImageInputCapability()).resolves.toEqual({ status: 'unknown' })
const bytes = createCanvas(2, 2).toBuffer('image/png')
const subject = await setup(bytes, {
llm: { provider, model: 'future-vision-model', name: 'openai' },
@@ -252,7 +250,6 @@ describe('GFS bytes to actual provider request', () => {
chat: { completions: { create: sdkCreate } },
}
const provider = new OpenAIProvider(client as never, 'gpt-4.1')
- await expect(provider.getImageInputCapability()).resolves.toMatchObject({ status: 'supported' })
const subject = await setup(createCanvas(2, 2).toBuffer('image/png'), {
catalogState: 'missing',
llm: { provider, model: 'gpt-4.1', name: 'openai' },
@@ -331,28 +328,13 @@ describe('GFS bytes to actual provider request', () => {
async (mime, cache) => {
const targetModel = 'claude-sonnet-4-6'
// Credential-free SDK boundary double. The production provider serializer,
- // raw metadata stream bridge, client/tool registry and loop still execute.
+ // client/tool registry and loop still execute.
const create = vi.fn(async () => ({
content: [{ type: 'text', text: 'Done' }],
stop_reason: 'end_turn',
usage: { input_tokens: 10, output_tokens: 2 },
}))
- const buildRequest = vi.fn(({ path }) => ({
- url: `https://api.anthropic.com${path}`,
- req: { method: 'GET' },
- }))
- const metadata = JSON.stringify({
- type: 'model',
- id: targetModel,
- capabilities: { image_input: { supported: true } },
- })
- const fetchWithTimeout = vi.fn(async () => ({
- status: 200,
- redirected: false,
- // Exercise the SDK's Node body and an injected native-fetch Web body.
- body: cache ? new Response(metadata).body : Readable.from([Buffer.from(metadata)]),
- }))
- const client = { messages: { create }, buildRequest, fetchWithTimeout }
+ const client = { messages: { create } }
const canvas = createCanvas(8, 8)
canvas.getContext('2d').fillRect(1, 1, 4, 4)
const bytes =
@@ -380,8 +362,6 @@ describe('GFS bytes to actual provider request', () => {
: {}),
})
expect(subject.metadataFetch).not.toHaveBeenCalled()
- expect(buildRequest).not.toHaveBeenCalled()
- expect(fetchWithTimeout).not.toHaveBeenCalled()
const request = (create.mock.calls as unknown as Array<[Record<string, any>]>)[0][0]
const blocks = request.messages.flatMap((m: any) =>
Array.isArray(m.content) ? m.content : []
@@ -529,7 +509,6 @@ describe('GFS bytes to actual provider request', () => {
completeSingleTurn: vi.fn(),
completeSingleTurnWithTools,
getProviderType: () => 'openai' as const,
- getImageInputCapability: async () => ({ status: 'unknown' as const }),
classifyError: vi.fn(),
},
'unknown-model',
@@ -644,7 +623,6 @@ describe('GFS bytes to actual provider request', () => {
completeSingleTurn: vi.fn(),
completeSingleTurnWithTools,
getProviderType: () => 'openai' as const,
- getImageInputCapability: async () => ({ status: 'unknown' as const }),
classifyError: vi.fn(),
},
'unknown-model',
diff --git a/mcp-host/src/llm/__tests__/openai.singleTurn.test.ts b/mcp-host/src/llm/__tests__/openai.singleTurn.test.ts
index cf3cce165..7827e34ed 100644
--- a/mcp-host/src/llm/__tests__/openai.singleTurn.test.ts
+++ b/mcp-host/src/llm/__tests__/openai.singleTurn.test.ts
@@ -2,30 +2,6 @@ import { describe, expect, it, vi } from 'vitest'
import { type ChatMessage, FinishReason, type ToolDefinition } from '../../core/types'
import { OpenAIProvider } from '../openai'
-describe('OpenAI image capability binding', () => {
- it('binds the documented capability to the actual SDK endpoint', async () => {
- const client = { ...createMockOpenAIClient(), baseURL: 'https://api.openai.com/v1' }
- const provider = new OpenAIProvider(client as never, 'gpt-4.1')
- await expect(provider.getImageInputCapability()).resolves.toMatchObject({
- status: 'supported',
- provider: 'openai',
- model: 'gpt-4.1',
- })
- client.baseURL = 'https://gateway.example.invalid/v1'
- await expect(provider.getImageInputCapability()).resolves.toEqual({ status: 'unknown' })
- expect(client.chat.completions.create).not.toHaveBeenCalled()
- })
-
- it('honors cancellation before resolving a capability', async () => {
- const client = { ...createMockOpenAIClient(), baseURL: 'https://api.openai.com/v1' }
- const provider = new OpenAIProvider(client as never, 'gpt-4.1')
- await expect(provider.getImageInputCapability(AbortSignal.abort())).rejects.toMatchObject({
- code: 'cancelled',
- })
- expect(client.chat.completions.create).not.toHaveBeenCalled()
- })
-})
-
function createMockOpenAIClient() {
return {
chat: {
diff --git a/mcp-host/src/llm/__tests__/openaiCompatible.classifyError.test.ts b/mcp-host/src/llm/__tests__/openaiCompatible.classifyError.test.ts
index 9bd687233..c2743bd72 100644
--- a/mcp-host/src/llm/__tests__/openaiCompatible.classifyError.test.ts
+++ b/mcp-host/src/llm/__tests__/openaiCompatible.classifyError.test.ts
@@ -16,18 +16,6 @@ const bailian = new OpenAICompatibleProvider(
// lands at `err.error.code`, the level the override reads. Deriving guards
// against the same nesting mismatch that broke the Claude arm.
describe('OpenAICompatibleProvider.classifyError', () => {
- it('does not inherit OpenAI model evidence for a different configured provider', async () => {
- // Construction-only fixture; no authenticated request is made.
- const compatible = new OpenAICompatibleProvider(
- { id: 'zai', baseURL: 'https://api.openai.com/v1', defaultModel: 'gpt-4.1' },
- 'unit-only'
- )
- await expect(compatible.getImageInputCapability()).resolves.toEqual({ status: 'unknown' })
- })
- it('rejects an aborted image capability lookup asynchronously', async () => {
- const lookup = zai.getImageInputCapability(AbortSignal.abort())
- await expect(lookup).rejects.toMatchObject({ code: 'cancelled' })
- })
it('maps z.ai model-not-available codes (1211/1220) to ModelNotAvailable', () => {
for (const code of ['1211', '1220']) {
const c = zai.classifyError(openaiApiError(404, { code, message: 'model not available' }))
diff --git a/mcp-host/src/llm/__tests__/zai.test.ts b/mcp-host/src/llm/__tests__/zai.test.ts
index 3798898de..cf2f9c71f 100644
--- a/mcp-host/src/llm/__tests__/zai.test.ts
+++ b/mcp-host/src/llm/__tests__/zai.test.ts
@@ -26,20 +26,4 @@ describe('ZaiProvider (OpenAICompatibleProvider)', () => {
it("getProviderType returns 'zai'", () => {
expect(makeZai().getProviderType()).toBe('zai')
})
-
- it('reports documented image input for glm-5.3-flash on the Coding Plan endpoint', async () => {
- await expect(makeZai('glm-5.3-flash').getImageInputCapability()).resolves.toEqual({
- status: 'supported',
- provider: 'zai',
- model: 'glm-5.3-flash',
- evidence: 'zai-documented-model-contract',
- })
- })
-
- it('keeps unlisted z.ai models unknown rather than inferring vision', async () => {
- await expect(makeZai('glm-4.7').getImageInputCapability()).resolves.toEqual({
- status: 'unknown',
- })
- await expect(makeZai().getImageInputCapability()).resolves.toEqual({ status: 'unknown' })
- })
})
diff --git a/mcp-host/src/llm/claude.ts b/mcp-host/src/llm/claude.ts
index 7aba12873..41000c594 100644
--- a/mcp-host/src/llm/claude.ts
+++ b/mcp-host/src/llm/claude.ts
@@ -2,7 +2,6 @@
* Anthropic Claude LLM provider with tool/function calling support.
*/
import Anthropic from '@anthropic-ai/sdk'
-import { Readable } from 'node:stream'
import { LlmErrorCode } from '../core/errors'
import type { SystemPromptParts } from '../core/reasoning/systemPrompt'
import {
@@ -18,8 +17,6 @@ import {
ToolDefinition,
} from '../core/types'
import { logger } from '../logger'
-import { createAnthropicImageCapabilityResolver } from '../visualInput/capabilities'
-import { type ImageInputCapability, VISUAL_INPUT_LIMITS } from '../visualInput/policy'
import { assertVisualRequestFits } from '../visualInput/requestPolicy'
import { convertToClaudeMessages, separateSystemMessage } from './claude/messageTranslate'
import { classifyByHttpStatus, classifyUnknown } from './errorClassification'
@@ -29,7 +26,6 @@ import type { ClassifiedError, SingleTurnProvider } from './types'
export class ClaudeProvider implements SingleTurnProvider {
private client: Anthropic
private defaultModel: string
- private readonly imageCapabilityResolver: (signal?: AbortSignal) => Promise<ImageInputCapability>
constructor(apiKeyOrClient: string | Anthropic, defaultModel: string = 'claude-sonnet-4-6') {
if (typeof apiKeyOrClient === 'string') {
@@ -38,52 +34,9 @@ export class ClaudeProvider implements SingleTurnProvider {
this.client = apiKeyOrClient
}
this.defaultModel = defaultModel
- this.imageCapabilityResolver = createAnthropicImageCapabilityResolver(
- defaultModel,
- async (path, signal) => {
- // Use this exact SDK connection/authentication, but consume raw transport
- // before SDK error parsing, which would otherwise read an unbounded body.
- const { url, req } = this.client.buildRequest({ method: 'get', path })
- const controller = new AbortController()
- const abort = () => controller.abort()
- signal.addEventListener('abort', abort, { once: true })
- try {
- signal.throwIfAborted()
- const response = await this.client.fetchWithTimeout(
- url,
- { ...req, signal: undefined, redirect: 'error' },
- VISUAL_INPUT_LIMITS.validationTimeoutMs,
- controller
- )
- if (response.status !== 200)
- logger.warn(
- { provider: 'claude', model: defaultModel, status: response.status },
- 'Model capability lookup failed'
- )
- // SDK 0.32 defaults to node-fetch, while injected fetch implementations
- // may return Web streams. Cancellation of the Node bridge destroys its body.
- const body =
- response.body instanceof Readable
- ? Readable.toWeb(response.body, {
- strategy: {
- highWaterMark: VISUAL_INPUT_LIMITS.metadataBytes,
- size: chunk => chunk.byteLength,
- },
- })
- : response.body
- return { status: response.status, redirected: response.redirected, body }
- } finally {
- signal.removeEventListener('abort', abort)
- }
- }
- )
logger.info({ model: defaultModel }, 'Claude transport initialized')
}
- getImageInputCapability(signal?: AbortSignal): Promise<ImageInputCapability> {
- return this.imageCapabilityResolver(signal)
- }
-
/**
* Get the provider type.
*/
diff --git a/mcp-host/src/llm/openai.ts b/mcp-host/src/llm/openai.ts
index aa588d54f..365907059 100644
--- a/mcp-host/src/llm/openai.ts
+++ b/mcp-host/src/llm/openai.ts
@@ -10,8 +10,6 @@ import {
ToolDefinition,
} from '../core/types'
import { logger } from '../logger'
-import { getDocumentedOpenAIImageCapability } from '../visualInput/documentedCapabilities'
-import { type ImageInputCapability, VisualInputError } from '../visualInput/policy'
import { assertVisualRequestFits } from '../visualInput/requestPolicy'
import { classifyByHttpStatus, classifyUnknown } from './errorClassification'
import type { LlmProvider } from './registryCore'
@@ -31,13 +29,6 @@ export class OpenAIProvider implements SingleTurnProvider {
logger.info({ model: defaultModel }, 'OpenAI transport initialized')
}
- async getImageInputCapability(signal?: AbortSignal): Promise<ImageInputCapability> {
- if (signal?.aborted) throw new VisualInputError('cancelled')
- // OpenAI's Models API does not report modalities. Use the documented
- // contract for this exact model only when this SDK targets the official API.
- return getDocumentedOpenAIImageCapability(this.defaultModel, this.client.baseURL)
- }
-
/**
* Get the provider type.
*/
diff --git a/mcp-host/src/llm/openaiCompatible.ts b/mcp-host/src/llm/openaiCompatible.ts
index 8afc2c858..975d0bddc 100644
--- a/mcp-host/src/llm/openaiCompatible.ts
+++ b/mcp-host/src/llm/openaiCompatible.ts
@@ -38,9 +38,6 @@ import type {
ToolCompletionResponse,
ToolDefinition,
} from '../core/types'
-import { createOpenRouterImageCapabilityResolver } from '../visualInput/capabilities'
-import { getDocumentedZaiImageCapability } from '../visualInput/documentedZaiCapabilities'
-import { type ImageInputCapability, VisualInputError } from '../visualInput/policy'
import { OpenAIProvider } from './openai'
import type { LlmProvider } from './registryCore'
import type { ClassifiedError } from './types'
@@ -82,8 +79,6 @@ const MODEL_NOT_AVAILABLE_CODES = new Set(['1211', '1220', 'ModelNotFound', 'Mod
const BILLING_CODES = new Set(['1113', 'Arrearage'])
export class OpenAICompatibleProvider extends OpenAIProvider {
- private readonly imageCapabilityResolver?: (signal?: AbortSignal) => Promise<ImageInputCapability>
- private readonly selectedModel: string
/** Provider temperature upper bound — 1 for Moonshot, else the [0,2] default. */
private readonly temperatureCeiling: number
/**
@@ -106,37 +101,14 @@ export class OpenAICompatibleProvider extends OpenAIProvider {
// fall through to OpenAIProvider's own default ('gpt-5.4-mini'), and this
// provider would request a non-existent model against its baseURL.
super(new OpenAI({ apiKey, baseURL: cfg.baseURL }), model ?? cfg.defaultModel)
- this.selectedModel = model ?? cfg.defaultModel
this.temperatureCeiling = cfg.id === 'moonshot' ? 1 : 2
this.downgradesRequiredToolChoice = cfg.id === 'moonshot'
- if (cfg.id === 'openrouter') {
- // This protocol publishes model modalities. Other compatible transports
- // do not thereby prove model vision support and remain unknown.
- const metadataBase = cfg.baseURL.replace(/\/+$/, '')
- this.imageCapabilityResolver = createOpenRouterImageCapabilityResolver(
- model ?? cfg.defaultModel,
- (path, signal) =>
- fetch(`${metadataBase}${path}`, {
- headers: { authorization: `Bearer ${apiKey}` },
- redirect: 'error',
- signal,
- })
- )
- }
}
override getProviderType(): LlmProvider {
return this.cfg.id as LlmProvider
}
- override async getImageInputCapability(signal?: AbortSignal): Promise<ImageInputCapability> {
- if (signal?.aborted) throw new VisualInputError('cancelled')
- if (this.cfg.id === 'zai') {
- return Promise.resolve(getDocumentedZaiImageCapability(this.selectedModel, this.cfg.baseURL))
- }
- return this.imageCapabilityResolver?.(signal) ?? Promise.resolve({ status: 'unknown' })
- }
-
/**
* The OpenAI-compatible arm inherits the shared HTTP classifier from the base
* class, but several third parties encode model-availability and billing in a
diff --git a/mcp-host/src/llm/types.ts b/mcp-host/src/llm/types.ts
index ddcfcc79b..3378202a7 100644
--- a/mcp-host/src/llm/types.ts
+++ b/mcp-host/src/llm/types.ts
@@ -21,7 +21,6 @@ import {
ToolCompletionResponse,
ToolDefinition,
} from '../core/types'
-import type { ImageInputCapability } from '../visualInput/policy'
import type { LlmProvider } from './registryCore'
/**
@@ -64,8 +63,6 @@ export interface ClassifiedError {
* Single-turn LLM transport. No loop, no tool execution.
*/
export interface SingleTurnProvider {
- /** Evidence for this provider instance's model, not a provider-name heuristic. */
- getImageInputCapability?(signal?: AbortSignal): Promise<ImageInputCapability>
/** The request contract binds distinct image sources, even when their bytes repeat. */
readonly requiresImageSourceIdentity?: boolean
completeSingleTurn(
diff --git a/mcp-host/src/visualInput/capabilities.test.ts b/mcp-host/src/visualInput/capabilities.test.ts
deleted file mode 100644
index 02875d89e..000000000
--- a/mcp-host/src/visualInput/capabilities.test.ts
+++ /dev/null
@@ -1,758 +0,0 @@
-import { afterEach, describe, expect, it, vi } from 'vitest'
-import {
- ANTHROPIC_CAPABILITY_CACHE_MS,
- ANTHROPIC_METADATA_EVIDENCE,
- ANTHROPIC_PROVIDER,
- type AnthropicMetadataReader,
- type ModelMetadataResponse,
- OPENROUTER_CAPABILITY_CACHE_MS,
- OPENROUTER_METADATA_EVIDENCE,
- OPENROUTER_PROVIDER,
- type OpenRouterMetadataReader,
- createAnthropicImageCapabilityResolver,
- createOpenRouterImageCapabilityResolver,
-} from './capabilities'
-import { VISUAL_INPUT_LIMITS, VisualInputError } from './policy'
-
-const MODEL = 'openai/gpt-4o'
-const MODEL_PATH = '/model/openai/gpt-4o'
-const METADATA_BYTES = VISUAL_INPUT_LIMITS.metadataBytes
-const DEADLINE_MS = VISUAL_INPUT_LIMITS.validationTimeoutMs
-
-afterEach(() => {
- vi.useRealTimers()
- vi.restoreAllMocks()
- vi.unstubAllGlobals()
-})
-
-function metadata(payload: unknown): Response {
- return new Response(JSON.stringify(payload), { status: 200 })
-}
-
-function catalogEntry(id: string, inputModalities: unknown): unknown {
- return { data: { id, architecture: { input_modalities: inputModalities } } }
-}
-
-/** A stream that stays open until the reader cancels it, so cancellation is observable. */
-function trackedStream(chunkBytes = 0): {
- stream: ReadableStream<Uint8Array>
- wasCancelled: () => boolean
-} {
- let cancelled = false
- const stream = new ReadableStream<Uint8Array>({
- start(controller) {
- if (chunkBytes > 0) controller.enqueue(new Uint8Array(chunkBytes))
- },
- cancel() {
- cancelled = true
- },
- })
- return { stream, wasCancelled: () => cancelled }
-}
-
-function deferred<T>(): { promise: Promise<T>; resolve: (value: T) => void } {
- let resolve!: (value: T) => void
- const promise = new Promise<T>(settle => {
- resolve = settle
- })
- return { promise, resolve }
-}
-
-/** Runs after every pending microtask, so an in-flight read is provably started. */
-function flushMicrotasks(): Promise<void> {
- return new Promise(resolve => setImmediate(resolve))
-}
-
-describe('OpenRouter image capability resolver', () => {
- it('requests the exact model path and reports supported with bounded evidence', async () => {
- const fetchSpy = vi.fn()
- vi.stubGlobal('fetch', fetchSpy)
- const readMetadata = vi.fn<OpenRouterMetadataReader>(async () =>
- metadata(catalogEntry(MODEL, ['text', 'image']))
- )
- const resolveCapability = createOpenRouterImageCapabilityResolver(MODEL, readMetadata)
-
- await expect(resolveCapability()).resolves.toEqual({
- status: 'supported',
- provider: 'openrouter',
- model: MODEL,
- evidence: 'openrouter-model-metadata',
- })
-
- expect(readMetadata).toHaveBeenCalledTimes(1)
- expect(readMetadata.mock.calls[0][0]).toBe(MODEL_PATH)
- expect(readMetadata.mock.calls[0][1]).toBeInstanceOf(AbortSignal)
- // The transport receives the path and a per-call signal only: no headers, no key.
- expect(readMetadata.mock.calls[0]).toHaveLength(2)
- expect(OPENROUTER_PROVIDER).toBe('openrouter')
- expect(OPENROUTER_METADATA_EVIDENCE).toBe('openrouter-model-metadata')
- expect(OPENROUTER_CAPABILITY_CACHE_MS).toBe(60_000)
- expect(fetchSpy).not.toHaveBeenCalled()
- })
-
- it('encodes reserved characters in the model path', async () => {
- const model = 'meta-llama/llama-3.2-3b-instruct:free'
- const readMetadata = vi.fn<OpenRouterMetadataReader>(async () =>
- metadata(catalogEntry(model, ['image']))
- )
-
- await expect(
- createOpenRouterImageCapabilityResolver(model, readMetadata)()
- ).resolves.toMatchObject({
- status: 'supported',
- })
- expect(readMetadata.mock.calls[0][0]).toBe('/model/meta-llama/llama-3.2-3b-instruct%3Afree')
- })
-
- it('refuses traversal, empty, and non-segment identifiers without reading metadata', async () => {
- const readMetadata = vi.fn<OpenRouterMetadataReader>(async () =>
- metadata(catalogEntry(MODEL, ['image']))
- )
- const rejected = [
- '../etc/passwd',
- 'a/..',
- '../b',
- '.',
- 'a/b/c',
- 'openai',
- '/gpt-4o',
- 'gpt-4o/',
- 'openai/ bad',
- 'openai/gpt 4o',
- `openai/gpt-4o${String.fromCharCode(0)}`,
- 'openai/gpt-4oü',
- ]
-
- for (const model of rejected) {
- await expect(createOpenRouterImageCapabilityResolver(model, readMetadata)()).resolves.toEqual(
- {
- status: 'unknown',
- }
- )
- }
- expect(readMetadata).not.toHaveBeenCalled()
- })
-
- it('reports an explicit text-only modality list as unsupported and caches it', async () => {
- const readMetadata = vi.fn<OpenRouterMetadataReader>(async () =>
- metadata(catalogEntry(MODEL, ['text']))
- )
- const resolveCapability = createOpenRouterImageCapabilityResolver(MODEL, readMetadata)
-
- await expect(resolveCapability()).resolves.toEqual({ status: 'unsupported' })
- await expect(resolveCapability()).resolves.toEqual({ status: 'unsupported' })
- expect(readMetadata).toHaveBeenCalledTimes(1)
- })
-
- it('treats an alias or a neighbouring id as unknown instead of inferring identity', async () => {
- const readMetadata = vi.fn<OpenRouterMetadataReader>(async () =>
- metadata(catalogEntry('openai/gpt-4o-2024-08-06', ['image']))
- )
-
- await expect(createOpenRouterImageCapabilityResolver(MODEL, readMetadata)()).resolves.toEqual({
- status: 'unknown',
- })
- })
-
- it('returns unknown for missing or malformed catalog entries', async () => {
- const bodies = [
- '',
- 'not json',
- '{}',
- '{"data":null}',
- '{"data":{}}',
- '{"data":{"architecture":{"input_modalities":["image"]}}}',
- '{"data":{"id":"other/model","architecture":{"input_modalities":["image"]}}}',
- `{"data":{"id":"${MODEL}"}}`,
- `{"data":{"id":"${MODEL}","architecture":null}}`,
- `{"data":{"id":"${MODEL}","architecture":{}}}`,
- `{"data":{"id":"${MODEL}","architecture":{"input_modalities":"image"}}}`,
- `{"data":{"id":"${MODEL}","architecture":{"input_modalities":["text",5]}}}`,
- `{"data":{"id":"${MODEL}","architecture":{"input_modalities":[null]}}}`,
- ]
-
- for (const body of bodies) {
- const readMetadata = vi.fn<OpenRouterMetadataReader>(
- async () => new Response(body, { status: 200 })
- )
- await expect(createOpenRouterImageCapabilityResolver(MODEL, readMetadata)()).resolves.toEqual(
- {
- status: 'unknown',
- }
- )
- }
- })
-
- it('returns unknown for a non-200 response or a followed redirect and releases the body', async () => {
- const failed = trackedStream()
- const readFailed = vi.fn<OpenRouterMetadataReader>(
- async () => new Response(failed.stream, { status: 503 })
- )
- await expect(createOpenRouterImageCapabilityResolver(MODEL, readFailed)()).resolves.toEqual({
- status: 'unknown',
- })
- expect(failed.wasCancelled()).toBe(true)
-
- const redirected = trackedStream()
- const redirectedResponse = {
- ok: true,
- status: 200,
- redirected: true,
- body: redirected.stream,
- } as unknown as Response
- const readRedirected = vi.fn<OpenRouterMetadataReader>(async () => redirectedResponse)
- await expect(createOpenRouterImageCapabilityResolver(MODEL, readRedirected)()).resolves.toEqual(
- {
- status: 'unknown',
- }
- )
- expect(redirected.wasCancelled()).toBe(true)
- })
-
- it('returns unknown for a response without a body', async () => {
- const readMetadata = vi.fn<OpenRouterMetadataReader>(
- async () => new Response(null, { status: 200 })
- )
- await expect(createOpenRouterImageCapabilityResolver(MODEL, readMetadata)()).resolves.toEqual({
- status: 'unknown',
- })
- })
-
- it('returns unknown for a body that cannot be read or decoded', async () => {
- const locked = new Response(JSON.stringify(catalogEntry(MODEL, ['image'])), { status: 200 })
- locked.body?.getReader()
- const readLocked = vi.fn<OpenRouterMetadataReader>(async () => locked)
- await expect(createOpenRouterImageCapabilityResolver(MODEL, readLocked)()).resolves.toEqual({
- status: 'unknown',
- })
-
- const invalidUtf8 = Uint8Array.from([0x7b, 0x22, 0xff, 0xfe, 0x22, 0x7d])
- const readInvalid = vi.fn<OpenRouterMetadataReader>(
- async () => new Response(invalidUtf8, { status: 200 })
- )
- await expect(createOpenRouterImageCapabilityResolver(MODEL, readInvalid)()).resolves.toEqual({
- status: 'unknown',
- })
- })
-
- it('caps the metadata body at 64 KiB and cancels an oversized read', async () => {
- const oversized = trackedStream(METADATA_BYTES + 1)
- const readOversized = vi.fn<OpenRouterMetadataReader>(
- async () => new Response(oversized.stream, { status: 200 })
- )
- await expect(createOpenRouterImageCapabilityResolver(MODEL, readOversized)()).resolves.toEqual({
- status: 'unknown',
- })
- expect(oversized.wasCancelled()).toBe(true)
-
- // A complete body of exactly the cap is still read.
- const base = `{"data":{"id":"${MODEL}","architecture":{"input_modalities":["image"]}}}`
- const padded = base.padEnd(METADATA_BYTES, ' ')
- expect(padded.length).toBe(METADATA_BYTES)
- const readAtCap = vi.fn<OpenRouterMetadataReader>(
- async () => new Response(padded, { status: 200 })
- )
- await expect(
- createOpenRouterImageCapabilityResolver(MODEL, readAtCap)()
- ).resolves.toMatchObject({
- status: 'supported',
- })
- })
-
- it('returns unknown when the per-call deadline elapses', async () => {
- vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] })
- let observed: AbortSignal | undefined
- const readMetadata = vi.fn<OpenRouterMetadataReader>((_path, signal) => {
- observed = signal
- return new Promise<Response>(() => undefined)
- })
- const pending = createOpenRouterImageCapabilityResolver(MODEL, readMetadata)()
-
- expect(DEADLINE_MS).toBe(5_000)
- await vi.advanceTimersByTimeAsync(DEADLINE_MS)
- await expect(pending).resolves.toEqual({ status: 'unknown' })
- expect(observed?.aborted).toBe(true)
- })
-
- it('reports cancellation for an aborted caller and aborts its own in-flight read', async () => {
- const controller = new AbortController()
- let observed: AbortSignal | undefined
- const readMetadata = vi.fn<OpenRouterMetadataReader>((_path, signal) => {
- observed = signal
- return new Promise<Response>(() => undefined)
- })
- const pending = createOpenRouterImageCapabilityResolver(MODEL, readMetadata)(controller.signal)
-
- controller.abort()
- const failure: unknown = await pending.then(
- () => undefined,
- (reason: unknown) => reason
- )
- expect(failure).toBeInstanceOf(VisualInputError)
- expect(failure).toMatchObject({ code: 'cancelled' })
- expect(observed?.aborted).toBe(true)
- })
-
- it('fails an already-aborted caller before touching the transport', async () => {
- const controller = new AbortController()
- controller.abort()
- const readMetadata = vi.fn<OpenRouterMetadataReader>(async () =>
- metadata(catalogEntry(MODEL, ['image']))
- )
-
- await expect(
- createOpenRouterImageCapabilityResolver(MODEL, readMetadata)(controller.signal)
- ).rejects.toMatchObject({ code: 'cancelled' })
- expect(readMetadata).not.toHaveBeenCalled()
- })
-
- it('cancels the in-flight body when the caller aborts', async () => {
- const controller = new AbortController()
- const body = trackedStream()
- const readMetadata = vi.fn<OpenRouterMetadataReader>(
- async () => new Response(body.stream, { status: 200 })
- )
- const pending = createOpenRouterImageCapabilityResolver(MODEL, readMetadata)(controller.signal)
-
- await flushMicrotasks()
- controller.abort()
-
- await expect(pending).rejects.toMatchObject({ code: 'cancelled' })
- expect(body.wasCancelled()).toBe(true)
- })
-
- it('does not cancel a concurrent reader when another caller aborts', async () => {
- const controller = new AbortController()
- const pending = deferred<Response>()
- let calls = 0
- const readMetadata = vi.fn<OpenRouterMetadataReader>((_path, signal) => {
- calls += 1
- if (calls > 1) return pending.promise
- return new Promise<Response>((_resolve, reject) => {
- signal.addEventListener('abort', () => reject(new Error('aborted')), { once: true })
- })
- })
- const resolveCapability = createOpenRouterImageCapabilityResolver(MODEL, readMetadata)
- const aborting = resolveCapability(controller.signal)
- const surviving = resolveCapability()
-
- controller.abort()
- await expect(aborting).rejects.toMatchObject({ code: 'cancelled' })
-
- pending.resolve(metadata(catalogEntry(MODEL, ['image'])))
- await expect(surviving).resolves.toMatchObject({ status: 'supported' })
- })
-
- it('gives every call its own signal and never shares the caller signal with the transport', async () => {
- const controller = new AbortController()
- const gate = deferred<void>()
- const signals: AbortSignal[] = []
- const readMetadata = vi.fn<OpenRouterMetadataReader>(async (_path, signal) => {
- signals.push(signal)
- await gate.promise
- return metadata(catalogEntry(MODEL, ['image']))
- })
- const resolveCapability = createOpenRouterImageCapabilityResolver(MODEL, readMetadata)
- const first = resolveCapability(controller.signal)
- const second = resolveCapability(controller.signal)
-
- // Concurrent readers never share an in-flight read.
- expect(readMetadata).toHaveBeenCalledTimes(2)
- expect(signals[0]).not.toBe(controller.signal)
- expect(signals[1]).not.toBe(controller.signal)
- expect(signals[0]).not.toBe(signals[1])
-
- gate.resolve(undefined)
- await expect(first).resolves.toMatchObject({ status: 'supported' })
- await expect(second).resolves.toMatchObject({ status: 'supported' })
- })
-
- it('serves a cached answer for 60 seconds and refreshes afterwards', async () => {
- vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] })
- const readMetadata = vi.fn<OpenRouterMetadataReader>(async () =>
- metadata(catalogEntry(MODEL, ['image']))
- )
- const resolveCapability = createOpenRouterImageCapabilityResolver(MODEL, readMetadata)
-
- await resolveCapability()
- vi.advanceTimersByTime(59_999)
- await resolveCapability()
- expect(readMetadata).toHaveBeenCalledTimes(1)
-
- vi.advanceTimersByTime(1)
- await resolveCapability()
- expect(readMetadata).toHaveBeenCalledTimes(2)
- })
-
- it('never caches an unknown answer', async () => {
- const readMetadata = vi.fn<OpenRouterMetadataReader>(
- async () => new Response(null, { status: 500 })
- )
- const resolveCapability = createOpenRouterImageCapabilityResolver(MODEL, readMetadata)
-
- await expect(resolveCapability()).resolves.toEqual({ status: 'unknown' })
- await expect(resolveCapability()).resolves.toEqual({ status: 'unknown' })
- expect(readMetadata).toHaveBeenCalledTimes(2)
- })
-
- it('binds each resolver to its own model and cache', async () => {
- const readA = vi.fn<OpenRouterMetadataReader>(async () =>
- metadata(catalogEntry('openai/gpt-4o', ['image']))
- )
- const readB = vi.fn<OpenRouterMetadataReader>(async () =>
- metadata(catalogEntry('anthropic/claude-sonnet-4', ['text']))
- )
- const resolveA = createOpenRouterImageCapabilityResolver('openai/gpt-4o', readA)
- const resolveB = createOpenRouterImageCapabilityResolver('anthropic/claude-sonnet-4', readB)
-
- await expect(resolveA()).resolves.toMatchObject({ status: 'supported', model: 'openai/gpt-4o' })
- await expect(resolveB()).resolves.toEqual({ status: 'unsupported' })
- await expect(resolveA()).resolves.toMatchObject({ status: 'supported' })
- expect(readA).toHaveBeenCalledTimes(1)
- expect(readB).toHaveBeenCalledTimes(1)
- expect(readB.mock.calls[0][0]).toBe('/model/anthropic/claude-sonnet-4')
- })
-})
-
-const CLAUDE_MODEL = 'claude-sonnet-4-5'
-const CLAUDE_MODEL_PATH = '/v1/models/claude-sonnet-4-5'
-
-/** The documented `GET /v1/models/{model_id}` body, with a controllable flag. */
-function anthropicModel(id: string, supported: unknown): Response {
- return new Response(
- JSON.stringify({ type: 'model', id, capabilities: { image_input: { supported } } }),
- { status: 200 }
- )
-}
-
-describe('Anthropic image capability resolver', () => {
- it('requests the exact model path and reports supported from the documented flag', async () => {
- const readMetadata = vi.fn<AnthropicMetadataReader>(async () =>
- anthropicModel(CLAUDE_MODEL, true)
- )
- const resolveCapability = createAnthropicImageCapabilityResolver(CLAUDE_MODEL, readMetadata)
-
- await expect(resolveCapability()).resolves.toEqual({
- status: 'supported',
- provider: 'claude',
- model: CLAUDE_MODEL,
- evidence: 'anthropic-model-metadata',
- })
-
- expect(readMetadata).toHaveBeenCalledTimes(1)
- expect(readMetadata.mock.calls[0][0]).toBe(CLAUDE_MODEL_PATH)
- expect(readMetadata.mock.calls[0][1]).toBeInstanceOf(AbortSignal)
- // The transport receives the path and a per-call signal only: no headers, no key.
- expect(readMetadata.mock.calls[0]).toHaveLength(2)
- expect(ANTHROPIC_PROVIDER).toBe('claude')
- expect(ANTHROPIC_METADATA_EVIDENCE).toBe('anthropic-model-metadata')
- expect(ANTHROPIC_CAPABILITY_CACHE_MS).toBe(60_000)
- })
-
- it('accepts an injected structural response, not only a native Response', async () => {
- const payload = JSON.stringify({
- type: 'model',
- id: CLAUDE_MODEL,
- capabilities: { image_input: { supported: true } },
- })
- const bridged: ModelMetadataResponse = {
- status: 200,
- redirected: false,
- body: new ReadableStream<Uint8Array>({
- start(controller) {
- controller.enqueue(new TextEncoder().encode(payload))
- controller.close()
- },
- }),
- }
- const readMetadata = vi.fn<AnthropicMetadataReader>(async () => bridged)
-
- await expect(
- createAnthropicImageCapabilityResolver(CLAUDE_MODEL, readMetadata)()
- ).resolves.toMatchObject({ status: 'supported', model: CLAUDE_MODEL })
- })
-
- it('keeps a reserved-character model id inside one path segment', async () => {
- const model = 'claude-sonnet-4.5?x=1#frag'
- const readMetadata = vi.fn<AnthropicMetadataReader>(async () => anthropicModel(model, true))
-
- await expect(
- createAnthropicImageCapabilityResolver(model, readMetadata)()
- ).resolves.toMatchObject({ status: 'supported' })
-
- const path = readMetadata.mock.calls[0][0]
- expect(path).toBe(`/v1/models/${encodeURIComponent(model)}`)
- expect(path.slice('/v1/models/'.length)).not.toContain('/')
- expect(path).not.toContain('?')
- expect(path).not.toContain('#')
- })
-
- it('encodes a slash in the model id instead of creating another route', async () => {
- const model = 'models/../admin'
- const readMetadata = vi.fn<AnthropicMetadataReader>(async () => anthropicModel(model, true))
-
- await expect(
- createAnthropicImageCapabilityResolver(model, readMetadata)()
- ).resolves.toMatchObject({ status: 'supported' })
-
- const path = readMetadata.mock.calls[0][0]
- expect(path).toBe('/v1/models/models%2F..%2Fadmin')
- // '' , 'v1', 'models', the encoded id: the id never becomes its own segment.
- expect(path.split('/')).toHaveLength(4)
- })
-
- it('refuses empty, dot, and control identifiers without reading metadata', async () => {
- const readMetadata = vi.fn<AnthropicMetadataReader>(async () =>
- anthropicModel(CLAUDE_MODEL, true)
- )
- const rejected = [
- '',
- '.',
- '..',
- ' ..',
- '.. ',
- 'claude sonnet 4',
- 'claude-sonnet-4\t',
- `claude-sonnet-4${String.fromCharCode(0)}`,
- 'claude-sonnet-4ü',
- ]
-
- for (const model of rejected) {
- await expect(createAnthropicImageCapabilityResolver(model, readMetadata)()).resolves.toEqual({
- status: 'unknown',
- })
- }
- expect(readMetadata).not.toHaveBeenCalled()
- })
-
- it('reports an explicit false flag as unsupported and caches it', async () => {
- const readMetadata = vi.fn<AnthropicMetadataReader>(async () =>
- anthropicModel(CLAUDE_MODEL, false)
- )
- const resolveCapability = createAnthropicImageCapabilityResolver(CLAUDE_MODEL, readMetadata)
-
- await expect(resolveCapability()).resolves.toEqual({ status: 'unsupported' })
- await expect(resolveCapability()).resolves.toEqual({ status: 'unsupported' })
- expect(readMetadata).toHaveBeenCalledTimes(1)
- })
-
- it('returns unknown for absent, mismatched, or malformed metadata', async () => {
- const id = JSON.stringify(CLAUDE_MODEL)
- const bodies = [
- '',
- 'not json',
- '{}',
- '[]',
- 'null',
- '{"type":"model"}',
- '{"type":"error","error":{"type":"not_found_error"}}',
- '{"type":"model","id":"claude-opus-4-1","capabilities":{"image_input":{"supported":true}}}',
- `{"id":${id},"capabilities":{"image_input":{"supported":true}}}`,
- `{"type":"model","id":${id}}`,
- `{"type":"model","id":${id},"capabilities":null}`,
- `{"type":"model","id":${id},"capabilities":{}}`,
- `{"type":"model","id":${id},"capabilities":{"image_input":null}}`,
- `{"type":"model","id":${id},"capabilities":{"image_input":{}}}`,
- `{"type":"model","id":${id},"capabilities":{"image_input":{"supported":"true"}}}`,
- `{"type":"model","id":${id},"capabilities":{"image_input":{"supported":null}}}`,
- ]
-
- for (const body of bodies) {
- const readMetadata = vi.fn<AnthropicMetadataReader>(
- async () => new Response(body, { status: 200 })
- )
- await expect(
- createAnthropicImageCapabilityResolver(CLAUDE_MODEL, readMetadata)()
- ).resolves.toEqual({ status: 'unknown' })
- }
- })
-
- it('returns unknown for a non-200 response or a followed redirect and releases the body', async () => {
- const failed = trackedStream()
- const readFailed = vi.fn<AnthropicMetadataReader>(
- async () => new Response(failed.stream, { status: 404 })
- )
- await expect(
- createAnthropicImageCapabilityResolver(CLAUDE_MODEL, readFailed)()
- ).resolves.toEqual({ status: 'unknown' })
- expect(failed.wasCancelled()).toBe(true)
-
- const redirected = trackedStream()
- const readRedirected = vi.fn<AnthropicMetadataReader>(async () => ({
- status: 200,
- redirected: true,
- body: redirected.stream,
- }))
- await expect(
- createAnthropicImageCapabilityResolver(CLAUDE_MODEL, readRedirected)()
- ).resolves.toEqual({ status: 'unknown' })
- expect(redirected.wasCancelled()).toBe(true)
- })
-
- it('caps the metadata body at 64 KiB and cancels an oversized read', async () => {
- const oversized = trackedStream(METADATA_BYTES + 1)
- const readOversized = vi.fn<AnthropicMetadataReader>(
- async () => new Response(oversized.stream, { status: 200 })
- )
- await expect(
- createAnthropicImageCapabilityResolver(CLAUDE_MODEL, readOversized)()
- ).resolves.toEqual({ status: 'unknown' })
- expect(oversized.wasCancelled()).toBe(true)
-
- // A complete body of exactly the cap is still read.
- const base = JSON.stringify({
- type: 'model',
- id: CLAUDE_MODEL,
- capabilities: { image_input: { supported: true } },
- })
- const padded = base.padEnd(METADATA_BYTES, ' ')
- expect(padded.length).toBe(METADATA_BYTES)
- const readAtCap = vi.fn<AnthropicMetadataReader>(
- async () => new Response(padded, { status: 200 })
- )
- await expect(
- createAnthropicImageCapabilityResolver(CLAUDE_MODEL, readAtCap)()
- ).resolves.toMatchObject({ status: 'supported' })
- })
-
- it('returns unknown when the shared per-call deadline elapses', async () => {
- vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] })
- let observed: AbortSignal | undefined
- const readMetadata = vi.fn<AnthropicMetadataReader>((_path, signal) => {
- observed = signal
- return new Promise<ModelMetadataResponse>(() => undefined)
- })
- const pending = createAnthropicImageCapabilityResolver(CLAUDE_MODEL, readMetadata)()
-
- expect(DEADLINE_MS).toBe(5_000)
- await vi.advanceTimersByTimeAsync(DEADLINE_MS)
- await expect(pending).resolves.toEqual({ status: 'unknown' })
- expect(observed?.aborted).toBe(true)
- })
-
- it('reports cancellation for an aborted caller and aborts its in-flight read', async () => {
- const controller = new AbortController()
- let observed: AbortSignal | undefined
- const readMetadata = vi.fn<AnthropicMetadataReader>((_path, signal) => {
- observed = signal
- return new Promise<ModelMetadataResponse>(() => undefined)
- })
- const pending = createAnthropicImageCapabilityResolver(
- CLAUDE_MODEL,
- readMetadata
- )(controller.signal)
-
- controller.abort()
- const failure: unknown = await pending.then(
- () => undefined,
- (reason: unknown) => reason
- )
- expect(failure).toBeInstanceOf(VisualInputError)
- expect(failure).toMatchObject({ code: 'cancelled' })
- expect(observed?.aborted).toBe(true)
- })
-
- it('fails an already-aborted caller before touching the transport', async () => {
- const controller = new AbortController()
- controller.abort()
- const readMetadata = vi.fn<AnthropicMetadataReader>(async () =>
- anthropicModel(CLAUDE_MODEL, true)
- )
-
- await expect(
- createAnthropicImageCapabilityResolver(CLAUDE_MODEL, readMetadata)(controller.signal)
- ).rejects.toMatchObject({ code: 'cancelled' })
- expect(readMetadata).not.toHaveBeenCalled()
- })
-
- it('cancels the in-flight body when the caller aborts', async () => {
- const controller = new AbortController()
- const body = trackedStream()
- const readMetadata = vi.fn<AnthropicMetadataReader>(
- async () => new Response(body.stream, { status: 200 })
- )
- const pending = createAnthropicImageCapabilityResolver(
- CLAUDE_MODEL,
- readMetadata
- )(controller.signal)
-
- await flushMicrotasks()
- controller.abort()
-
- await expect(pending).rejects.toMatchObject({ code: 'cancelled' })
- expect(body.wasCancelled()).toBe(true)
- })
-
- it('gives every call its own signal and never shares the caller signal with the transport', async () => {
- const controller = new AbortController()
- const gate = deferred<void>()
- const signals: AbortSignal[] = []
- const readMetadata = vi.fn<AnthropicMetadataReader>(async (_path, signal) => {
- signals.push(signal)
- await gate.promise
- return anthropicModel(CLAUDE_MODEL, true)
- })
- const resolveCapability = createAnthropicImageCapabilityResolver(CLAUDE_MODEL, readMetadata)
- const first = resolveCapability(controller.signal)
- const second = resolveCapability(controller.signal)
-
- expect(readMetadata).toHaveBeenCalledTimes(2)
- expect(signals[0]).not.toBe(controller.signal)
- expect(signals[1]).not.toBe(controller.signal)
- expect(signals[0]).not.toBe(signals[1])
-
- gate.resolve(undefined)
- await expect(first).resolves.toMatchObject({ status: 'supported' })
- await expect(second).resolves.toMatchObject({ status: 'supported' })
- })
-
- it('serves a cached answer for 60 seconds and refreshes afterwards', async () => {
- vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] })
- const readMetadata = vi.fn<AnthropicMetadataReader>(async () =>
- anthropicModel(CLAUDE_MODEL, true)
- )
- const resolveCapability = createAnthropicImageCapabilityResolver(CLAUDE_MODEL, readMetadata)
-
- await resolveCapability()
- vi.advanceTimersByTime(59_999)
- await resolveCapability()
- expect(readMetadata).toHaveBeenCalledTimes(1)
-
- vi.advanceTimersByTime(1)
- await resolveCapability()
- expect(readMetadata).toHaveBeenCalledTimes(2)
- })
-
- it('never caches an unknown answer', async () => {
- const readMetadata = vi.fn<AnthropicMetadataReader>(
- async () => new Response(null, { status: 500 })
- )
- const resolveCapability = createAnthropicImageCapabilityResolver(CLAUDE_MODEL, readMetadata)
-
- await expect(resolveCapability()).resolves.toEqual({ status: 'unknown' })
- await expect(resolveCapability()).resolves.toEqual({ status: 'unknown' })
- expect(readMetadata).toHaveBeenCalledTimes(2)
- })
-
- it('binds each resolver to its own model and cache', async () => {
- const readA = vi.fn<AnthropicMetadataReader>(async () =>
- anthropicModel('claude-sonnet-4-5', true)
- )
- const readB = vi.fn<AnthropicMetadataReader>(async () =>
- anthropicModel('claude-opus-4-1', false)
- )
- const resolveA = createAnthropicImageCapabilityResolver('claude-sonnet-4-5', readA)
- const resolveB = createAnthropicImageCapabilityResolver('claude-opus-4-1', readB)
-
- await expect(resolveA()).resolves.toMatchObject({
- status: 'supported',
- model: 'claude-sonnet-4-5',
- })
- await expect(resolveB()).resolves.toEqual({ status: 'unsupported' })
- await expect(resolveA()).resolves.toMatchObject({ status: 'supported' })
- expect(readA).toHaveBeenCalledTimes(1)
- expect(readB).toHaveBeenCalledTimes(1)
- expect(readA.mock.calls[0][0]).toBe('/v1/models/claude-sonnet-4-5')
- expect(readB.mock.calls[0][0]).toBe('/v1/models/claude-opus-4-1')
- })
-})
diff --git a/mcp-host/src/visualInput/capabilities.ts b/mcp-host/src/visualInput/capabilities.ts
deleted file mode 100644
index c6122ffdf..000000000
--- a/mcp-host/src/visualInput/capabilities.ts
+++ /dev/null
@@ -1,384 +0,0 @@
-import { type ImageInputCapability, VISUAL_INPUT_LIMITS, VisualInputError } from './policy'
-
-/** The provider name the OpenRouter catalog resolver reports. */
-export const OPENROUTER_PROVIDER = 'openrouter'
-/** Fixed, bounded provenance string; upstream text never reaches this field. */
-export const OPENROUTER_METADATA_EVIDENCE = 'openrouter-model-metadata'
-
-/**
- * The provider name the Anthropic Models API resolver reports. It matches
- * `getProviderType()` on the Claude provider, so an answer carries the same
- * identity the rest of the LLM layer uses.
- */
-export const ANTHROPIC_PROVIDER = 'claude'
-/** Fixed, bounded provenance string; upstream text never reaches this field. */
-export const ANTHROPIC_METADATA_EVIDENCE = 'anthropic-model-metadata'
-
-/** Both catalogs change slowly, so a resolved answer stays reusable for one minute. */
-const CAPABILITY_CACHE_MS = 60_000
-
-export const OPENROUTER_CAPABILITY_CACHE_MS = CAPABILITY_CACHE_MS
-export const ANTHROPIC_CAPABILITY_CACHE_MS = CAPABILITY_CACHE_MS
-
-/**
- * The only parts of one HTTP response this module reads. Native `Response`
- * satisfies it directly, and so does the `{status, redirected, body}` shape a
- * caller builds after bridging a Node stream into a Web stream.
- */
-export interface ModelMetadataResponse {
- readonly status: number
- readonly redirected: boolean
- readonly body: ModelMetadataBody | null
-}
-
-/**
- * The subset of a Web `ReadableStream` this module consumes, declared
- * structurally because the fetch layer's `Response` typings and Node's
- * `Readable.toWeb` bridge do not always resolve to the same `ReadableStream`
- * declaration. A bounded read only needs `getReader()`, `read()`, `cancel()`,
- * and `releaseLock()`.
- */
-export interface ModelMetadataBody {
- getReader(): ModelMetadataBodyReader
- cancel(): Promise<void>
-}
-
-export interface ModelMetadataBodyReader {
- read(): Promise<{ done: boolean; value?: Uint8Array }>
- cancel(): Promise<void>
- releaseLock(): void
-}
-
-/**
- * Fetches one provider-relative metadata path through the caller's authenticated
- * transport, so this module reads no key, no environment variable, and no socket
- * of its own. The caller resolves the provider base; the path is always relative.
- */
-export type MetadataReader = (path: string, signal: AbortSignal) => Promise<ModelMetadataResponse>
-
-/** OpenRouter's `GET /model/{author}/{slug}` reader. */
-export type OpenRouterMetadataReader = MetadataReader
-
-/** Anthropic's `GET /v1/models/{model_id}` reader. */
-export type AnthropicMetadataReader = MetadataReader
-
-const UNKNOWN = Object.freeze({ status: 'unknown' as const })
-const UNSUPPORTED = Object.freeze({ status: 'unsupported' as const })
-const ABORTED = Symbol('image-capability-aborted')
-
-/** The provider-specific half of one resolver: path shape plus documented metadata shape. */
-interface ImageCapabilitySource {
- /** Provider-relative request path for one model id, or undefined when it is not addressable. */
- buildPath(model: string): string | undefined
- /** Reads only the documented model shape; an explicit negative is the sole `unsupported`. */
- parse(metadata: string, model: string): ImageInputCapability
-}
-
-/**
- * Resolves whether one model accepts image input, using only the injected
- * authenticated reader. Every failure mode other than an explicit negative
- * resolves to `unknown`, so a caller that cannot prove support never treats the
- * model as image-capable. Both providers share this engine: one bounded read per
- * uncached call, one absolute per-call deadline, and one private per-resolver cache.
- */
-function createImageCapabilityResolver(
- model: string,
- readMetadata: MetadataReader,
- source: ImageCapabilitySource
-): (signal?: AbortSignal) => Promise<ImageInputCapability> {
- const path = source.buildPath(model)
- let cached: { value: ImageInputCapability; expiresAt: number } | undefined
-
- return async function resolveCapability(callerSignal) {
- if (callerSignal?.aborted) throw new VisualInputError('cancelled')
- if (path === undefined) return UNKNOWN
-
- const now = Date.now()
- if (cached !== undefined && cached.expiresAt > now) return cached.value
-
- const outcome = await resolveWithDeadline(callerSignal, signal =>
- requestCapability(path, readMetadata, signal, metadata => source.parse(metadata, model))
- )
- if (outcome !== ABORTED && outcome.status !== 'unknown') {
- cached = { value: outcome, expiresAt: Date.now() + CAPABILITY_CACHE_MS }
- }
- // A caller that aborted never receives a value, even when one arrived first.
- if (callerSignal?.aborted) throw new VisualInputError('cancelled')
- return outcome === ABORTED ? UNKNOWN : outcome
- }
-}
-
-/**
- * Resolves whether one `author/slug` OpenRouter model accepts image input, using
- * only the injected authenticated reader.
- */
-export function createOpenRouterImageCapabilityResolver(
- model: string,
- readMetadata: OpenRouterMetadataReader
-): (signal?: AbortSignal) => Promise<ImageInputCapability> {
- return createImageCapabilityResolver(model, readMetadata, OPENROUTER_SOURCE)
-}
-
-/**
- * Resolves whether one Anthropic model accepts image input, reading the
- * documented `capabilities.image_input.supported` flag. Vision is never inferred
- * from the model name: an absent, mismatched, or malformed flag is `unknown`, and
- * only an explicit `false` is `unsupported`.
- */
-export function createAnthropicImageCapabilityResolver(
- model: string,
- readMetadata: AnthropicMetadataReader
-): (signal?: AbortSignal) => Promise<ImageInputCapability> {
- return createImageCapabilityResolver(model, readMetadata, ANTHROPIC_SOURCE)
-}
-
-const OPENROUTER_SOURCE: ImageCapabilitySource = {
- buildPath: buildOpenRouterModelPath,
- parse: openRouterCapabilityFromMetadata,
-}
-
-const ANTHROPIC_SOURCE: ImageCapabilitySource = {
- buildPath: buildAnthropicModelPath,
- parse: anthropicCapabilityFromMetadata,
-}
-
-/**
- * OpenRouter model ids are exactly `author/slug`; anything else cannot be
- * requested at all. Each segment must stay a single printable-ASCII token, and
- * `encodeURIComponent` escapes the reserved characters that remain, such as the
- * `:` in `author/model:free`.
- */
-function buildOpenRouterModelPath(model: string): string | undefined {
- const segments = model.split('/')
- if (segments.length !== 2) return undefined
- const [author, slug] = segments
- if (!isSafePathSegment(author) || !isSafePathSegment(slug)) return undefined
- return `/model/${encodeURIComponent(author)}/${encodeURIComponent(slug)}`
-}
-
-/**
- * Anthropic model ids address exactly one resource, `GET /v1/models/{model_id}`.
- * The id must stay a single printable-ASCII token, and `encodeURIComponent`
- * escapes `/`, `?`, `#`, and `%` so they cannot introduce another path, query, or
- * fragment. A bare `.` or `..` is refused before encoding, because dots are
- * unreserved characters that `encodeURIComponent` would otherwise leave intact.
- */
-function buildAnthropicModelPath(model: string): string | undefined {
- if (!isSafePathSegment(model)) return undefined
- return `/v1/models/${encodeURIComponent(model)}`
-}
-
-function isSafePathSegment(segment: string): boolean {
- if (segment.length === 0 || segment === '.' || segment === '..') return false
- for (const character of segment) {
- const code = character.codePointAt(0)
- if (code === undefined || code < 0x21 || code > 0x7e) return false
- }
- return true
-}
-
-/**
- * Composes the caller's abort with one absolute per-call deadline. The transport
- * receives a signal this module owns, never the caller's, so concurrent readers
- * cannot abort each other.
- */
-async function resolveWithDeadline(
- callerSignal: AbortSignal | undefined,
- attempt: (signal: AbortSignal) => Promise<ImageInputCapability>
-): Promise<ImageInputCapability | typeof ABORTED> {
- const controller = new AbortController()
- const onCallerAbort = () => controller.abort()
- callerSignal?.addEventListener('abort', onCallerAbort, { once: true })
- const deadline = setTimeout(() => controller.abort(), VISUAL_INPUT_LIMITS.validationTimeoutMs)
-
- try {
- return await Promise.race([attempt(controller.signal), aborted(controller.signal)])
- } finally {
- clearTimeout(deadline)
- callerSignal?.removeEventListener('abort', onCallerAbort)
- // Retire the local signal, including its race listener. A transport that
- // returns late must observe a closed request and discard its body.
- controller.abort()
- }
-}
-
-/** Settles once the per-call controller aborts, so a stalled read cannot hang a turn. */
-function aborted(signal: AbortSignal): Promise<typeof ABORTED> {
- return new Promise(resolve => {
- if (signal.aborted) {
- resolve(ABORTED)
- return
- }
- signal.addEventListener('abort', () => resolve(ABORTED), { once: true })
- })
-}
-
-async function requestCapability(
- path: string,
- readMetadata: MetadataReader,
- signal: AbortSignal,
- parse: (metadata: string) => ImageInputCapability
-): Promise<ImageInputCapability> {
- try {
- const response = await readMetadata(path, signal)
- if (signal.aborted) {
- cancelQuietly(response.body)
- return UNKNOWN
- }
-
- // A redirect leaves the requested model, and a non-200 carries no catalog entry.
- if (response.status !== 200 || response.redirected) {
- cancelQuietly(response.body)
- return UNKNOWN
- }
-
- const metadata = await readBoundedMetadata(response, signal)
- return metadata === undefined ? UNKNOWN : parse(metadata)
- } catch {
- // An unreadable transport, status, or body cannot prove support: fail closed.
- return UNKNOWN
- }
-}
-
-/**
- * Reads at most `VISUAL_INPUT_LIMITS.metadataBytes` of JSON text before parsing.
- * An oversized, unreadable, or non-UTF-8 body is `undefined` so the caller
- * reports `unknown` instead of parsing a truncated or replaced catalog entry.
- */
-async function readBoundedMetadata(
- response: ModelMetadataResponse,
- signal: AbortSignal
-): Promise<string | undefined> {
- const body = response.body
- if (!body) return undefined
-
- const reader = body.getReader()
- const onAbort = () => cancelQuietly(reader)
- signal.addEventListener('abort', onAbort, { once: true })
-
- const chunks: Uint8Array[] = []
- let received = 0
- try {
- if (signal.aborted) return undefined
- while (true) {
- const { done, value } = await reader.read()
- if (done) break
- if (!value || value.byteLength === 0) continue
- received += value.byteLength
- if (received > VISUAL_INPUT_LIMITS.metadataBytes) {
- cancelQuietly(reader)
- return undefined
- }
- chunks.push(value)
- }
- } catch {
- cancelQuietly(reader)
- return undefined
- } finally {
- signal.removeEventListener('abort', onAbort)
- reader.releaseLock()
- }
-
- if (signal.aborted) return undefined
- return decodeUtf8(chunks, received)
-}
-
-function decodeUtf8(chunks: readonly Uint8Array[], received: number): string | undefined {
- const joined = Buffer.concat(chunks, received)
- try {
- return new TextDecoder('utf-8', { fatal: true }).decode(joined)
- } catch {
- return undefined
- }
-}
-
-/**
- * Parses a metadata body only when it is one JSON object; anything else proves
- * nothing about the requested model.
- */
-function parseJsonObject(metadata: string): Record<string, unknown> | undefined {
- let payload: unknown
- try {
- payload = JSON.parse(metadata)
- } catch {
- return undefined
- }
- if (typeof payload !== 'object' || payload === null) return undefined
- return payload as Record<string, unknown>
-}
-
-/**
- * Reads only OpenRouter's documented catalog shape. Anything absent, mistyped, or
- * describing a different model leaves the answer `unknown`; an explicit modality
- * list without `image` is the single reachable `unsupported`.
- */
-function openRouterCapabilityFromMetadata(metadata: string, model: string): ImageInputCapability {
- const payload = parseJsonObject(metadata)
- if (payload === undefined) return UNKNOWN
-
- const data = payload.data
- if (typeof data !== 'object' || data === null) return UNKNOWN
-
- // An alias or a neighbouring id is not the requested model; never infer identity.
- const entry = data as { id?: unknown; architecture?: unknown }
- if (entry.id !== model) return UNKNOWN
-
- const architecture = entry.architecture
- if (typeof architecture !== 'object' || architecture === null) return UNKNOWN
-
- const modalities = (architecture as { input_modalities?: unknown }).input_modalities
- if (!Array.isArray(modalities) || !modalities.every(value => typeof value === 'string')) {
- return UNKNOWN
- }
- if (!modalities.includes('image')) return UNSUPPORTED
-
- // Frozen because the resolver hands this same instance back from its cache.
- return Object.freeze({
- status: 'supported' as const,
- provider: OPENROUTER_PROVIDER,
- model,
- evidence: OPENROUTER_METADATA_EVIDENCE,
- })
-}
-
-/**
- * Reads only Anthropic's documented `GET /v1/models/{model_id}` shape. A missing
- * or mistyped `type`, a neighbouring id, a malformed capability tree, or a
- * non-boolean flag all prove nothing and stay `unknown`; the flag's boolean value
- * is the only thing that decides. Nothing is inferred from the model name.
- */
-function anthropicCapabilityFromMetadata(metadata: string, model: string): ImageInputCapability {
- const payload = parseJsonObject(metadata)
- if (payload === undefined) return UNKNOWN
-
- // A neighbouring entry, an alias, or an error envelope is not the requested model.
- if (payload.type !== 'model' || payload.id !== model) return UNKNOWN
-
- const capabilities = payload.capabilities
- if (typeof capabilities !== 'object' || capabilities === null) return UNKNOWN
-
- const imageInput = (capabilities as { image_input?: unknown }).image_input
- if (typeof imageInput !== 'object' || imageInput === null) return UNKNOWN
-
- const supported = (imageInput as { supported?: unknown }).supported
- if (typeof supported !== 'boolean') return UNKNOWN
- if (!supported) return UNSUPPORTED
-
- // Frozen because the resolver hands this same instance back from its cache.
- return Object.freeze({
- status: 'supported' as const,
- provider: ANTHROPIC_PROVIDER,
- model,
- evidence: ANTHROPIC_METADATA_EVIDENCE,
- })
-}
-
-/** Releases a body this module refuses to read; an already-consumed body needs nothing. */
-function cancelQuietly(stream: { cancel(): Promise<void> } | null): void {
- if (stream === null) return
- try {
- void stream.cancel().catch(() => undefined)
- } catch {
- // A locked or already-errored stream cannot be cancelled.
- }
-}
diff --git a/mcp-host/src/visualInput/documentedCapabilities.test.ts b/mcp-host/src/visualInput/documentedCapabilities.test.ts
deleted file mode 100644
index 6e215a952..000000000
--- a/mcp-host/src/visualInput/documentedCapabilities.test.ts
+++ /dev/null
@@ -1,187 +0,0 @@
-import { afterEach, describe, expect, it, vi } from 'vitest'
-import {
- DOCUMENTED_OPENAI_IMAGE_MODELS,
- OFFICIAL_OPENAI_BASE_URL,
- OPENAI_DOCUMENTED_EVIDENCE,
- OPENAI_PROVIDER,
- getDocumentedOpenAIImageCapability,
-} from './documentedCapabilities'
-
-const OFFICIAL = OFFICIAL_OPENAI_BASE_URL
-/** The exact default the OpenAI SDK resolves for an absent base URL. */
-const SDK_DEFAULT_BASE_URL = 'https://api.openai.com/v1'
-const DOCUMENTED_MODEL = 'gpt-4.1'
-
-afterEach(() => {
- vi.restoreAllMocks()
- vi.unstubAllGlobals()
-})
-
-function expectSupported(model: string, baseURL: string | undefined): void {
- expect(getDocumentedOpenAIImageCapability(model, baseURL)).toEqual({
- status: 'supported',
- provider: 'openai',
- model,
- evidence: 'openai-documented-model-contract',
- })
-}
-
-function expectUnknown(model: string, baseURL: string | undefined = OFFICIAL): void {
- expect(getDocumentedOpenAIImageCapability(model, baseURL)).toEqual({ status: 'unknown' })
-}
-
-describe('getDocumentedOpenAIImageCapability', () => {
- it('reports the documented contract for every table entry, alias and snapshot alike', () => {
- expect(OPENAI_PROVIDER).toBe('openai')
- expect(OPENAI_DOCUMENTED_EVIDENCE).toBe('openai-documented-model-contract')
- expect(OFFICIAL_OPENAI_BASE_URL).toBe('https://api.openai.com/v1')
- expect(DOCUMENTED_OPENAI_IMAGE_MODELS.length).toBeGreaterThan(0)
-
- for (const entry of DOCUMENTED_OPENAI_IMAGE_MODELS) {
- expectSupported(entry.id, OFFICIAL)
- // The SDK default and the explicit official base must agree.
- expectSupported(entry.id, SDK_DEFAULT_BASE_URL)
- expect(getDocumentedOpenAIImageCapability(entry.id, undefined)).toEqual({ status: 'unknown' })
- for (const snapshot of entry.snapshots) expectSupported(snapshot, OFFICIAL)
- }
- })
-
- it('answers for the model the OpenAI provider actually defaults to', () => {
- expectSupported('gpt-5.4-mini', SDK_DEFAULT_BASE_URL)
- expectSupported('gpt-5.4-mini-2026-03-17', SDK_DEFAULT_BASE_URL)
- })
-
- it('keeps one source of truth per documented id, with no collisions', () => {
- const seen = new Map<string, string>()
- for (const entry of DOCUMENTED_OPENAI_IMAGE_MODELS) {
- expect(entry.source).toBe(`https://developers.openai.com/api/docs/models/${entry.id}`)
- for (const id of [entry.id, ...entry.snapshots]) {
- expect(seen.has(id)).toBe(false)
- seen.set(id, entry.source)
- }
- for (const snapshot of entry.snapshots) {
- // A snapshot of another model must never be reachable through this entry.
- expect(snapshot.startsWith(`${entry.id}-`)).toBe(true)
- }
- }
- // Every documented id the getter accepts is covered by the table above.
- expect([...seen.keys()]).toContain(DOCUMENTED_MODEL)
- })
-
- it('binds the answer to the official endpoint, with one trailing slash at most', () => {
- expectSupported(DOCUMENTED_MODEL, 'https://api.openai.com/v1')
- expectSupported(DOCUMENTED_MODEL, 'https://api.openai.com/v1/')
- // Host names are case-insensitive; the explicit default port is the same origin.
- expectSupported(DOCUMENTED_MODEL, 'https://API.OPENAI.COM/v1')
- expectSupported(DOCUMENTED_MODEL, 'https://api.openai.com:443/v1')
- })
-
- it('returns unknown for every other origin, path, scheme, or credentials', () => {
- const rejected = [
- // Different scheme, host, or port: a different deployment.
- 'http://api.openai.com/v1',
- 'https://api.openai.com.evil.example/v1',
- 'https://api.openai.com.evil.example./v1',
- 'https://evil.example/?next=https://api.openai.com/v1',
- 'https://evil.example/api.openai.com/v1',
- 'https://api.openai.com:8443/v1',
- 'https://api.openai.com./v1',
- // Credentials, query, or fragment change the request target.
- 'https://user:[email protected]/v1',
- 'https://[email protected]/v1',
- 'https://api.openai.com/v1?x=1',
- 'https://api.openai.com/v1#fragment',
- 'https://api.openai.com/v1#@evil.example',
- // Paths that are not the documented base.
- 'https://api.openai.com',
- 'https://api.openai.com/',
- 'https://api.openai.com/v1//',
- 'https://api.openai.com/v1/chat/completions',
- 'https://api.openai.com/v1/models',
- 'https://api.openai.com/v2',
- 'https://api.openai.com/V1',
- // Other documented OpenAI base URLs and gateways.
- 'https://openrouter.ai/api/v1',
- 'https://example.openai.azure.com/openai/deployments/gpt-4.1',
- 'http://127.0.0.1:11434/v1',
- 'https://api.anthropic.com/v1',
- // Not a usable absolute base URL.
- '',
- '/v1',
- 'api.openai.com/v1',
- 'not a url',
- ]
-
- for (const baseURL of rejected) expectUnknown(DOCUMENTED_MODEL, baseURL)
- })
-
- it('never infers support from a prefix, family, or neighbouring id', () => {
- const undocumented = [
- // Same families, ids that are not in the table.
- 'gpt-4',
- 'gpt-4-turbo',
- 'gpt-4.1-preview',
- 'gpt-4.1-2025-04-14x',
- 'gpt-4.1-20250414',
- 'gpt-4o-2024-05-14',
- 'gpt-4o-audio-preview',
- 'gpt-4o-mini-realtime-preview',
- 'gpt-4o-transcribe',
- 'gpt-5-pro',
- 'gpt-5.2-pro',
- 'gpt-5.5-pro',
- 'gpt-5.5',
- 'gpt-5.4-pro',
- 'gpt-5.4-mini-2026-03-17x',
- 'gpt-5.1-codex',
- 'gpt-5.1-codex-max',
- 'gpt-5.3-codex-spark',
- 'gpt-6',
- 'o3',
- 'o4-mini',
- 'text-embedding-3-large',
- 'gpt-image-1',
- 'dall-e-3',
- 'whisper-1',
- 'tts-1',
- // Adjacent or injected spellings of a documented id.
- 'gpt-4.1 ',
- ' gpt-4.1',
- 'gpt-4.1\n',
- 'gpt-4.1\t',
- 'GPT-4.1',
- 'xgpt-4.1',
- 'gpt-4.1/../gpt-4.1',
- 'gpt-4.1%00',
- 'gpt-4.1-2025-04-14.',
- 'gpt-4.1-evil',
- '',
- ' ',
- ]
-
- for (const model of undocumented) expectUnknown(model)
- })
-
- it('does not trim, fold, or otherwise normalize the requested id', () => {
- // The documented id is answered verbatim; the same letters with any added
- // character are a different id and stay unknown.
- expect(getDocumentedOpenAIImageCapability(` ${DOCUMENTED_MODEL}`, OFFICIAL)).toEqual({
- status: 'unknown',
- })
- expect(getDocumentedOpenAIImageCapability(DOCUMENTED_MODEL.toUpperCase(), OFFICIAL)).toEqual({
- status: 'unknown',
- })
- expectSupported(DOCUMENTED_MODEL, OFFICIAL)
- })
-
- it('answers without any network request or credential', () => {
- const fetchSpy = vi.fn()
- vi.stubGlobal('fetch', fetchSpy)
-
- expectSupported(DOCUMENTED_MODEL, OFFICIAL)
- expectUnknown('gpt-4.1-nope')
- expectUnknown(DOCUMENTED_MODEL, 'https://proxy.example/v1')
-
- expect(fetchSpy).not.toHaveBeenCalled()
- })
-})
diff --git a/mcp-host/src/visualInput/documentedCapabilities.ts b/mcp-host/src/visualInput/documentedCapabilities.ts
deleted file mode 100644
index 1bd8ec675..000000000
--- a/mcp-host/src/visualInput/documentedCapabilities.ts
+++ /dev/null
@@ -1,189 +0,0 @@
-/**
- * Documented OpenAI image-input capability, resolved offline.
- *
- * OpenAI's Models API reports an id and an owner but not modalities
- * (https://developers.openai.com/api/reference/cli/resources/models/methods/retrieve),
- * so there is nothing to read back at runtime. Instead this module binds one
- * factual table of published model contracts to the one endpoint those contracts
- * were published for. A model is image-capable only when both hold:
- *
- * 1. the transport targets the official `https://api.openai.com/v1` endpoint, and
- * 2. the exact requested id appears in {@link DOCUMENTED_OPENAI_IMAGE_MODELS}.
- *
- * Everything else is `unknown`. There is no prefix, family, or size heuristic:
- * an id is listed only when a verified page documents `Image: Input only` *and*
- * the id is in scope for this provider's Chat Completions path. Codex variants,
- * Pro variants, audio/realtime models, and every unlisted id therefore stay
- * `unknown`; some of them (for example `gpt-5-pro` and `gpt-5.1-codex`) document
- * image input on their own pages, which on its own is not enough to list them
- * here. The table is a contract with sources, not a catalog: each entry carries
- * the official page it was verified against and the snapshot ids that page
- * lists.
- *
- * This module performs no I/O, reads no key, and never infers capability from a
- * model name. Absence of an entry means "not proven", never "not capable".
- */
-import type { ImageInputCapability } from './policy'
-
-/** The provider identity reported for a supported model. */
-export const OPENAI_PROVIDER = 'openai'
-/**
- * Fixed, bounded provenance string. The model id is echoed back exactly as
- * requested, so a caller can correlate the answer with its own request; the
- * evidence never contains upstream text.
- */
-export const OPENAI_DOCUMENTED_EVIDENCE = 'openai-documented-model-contract'
-/** The only endpoint whose model contracts this table describes. */
-export const OFFICIAL_OPENAI_BASE_URL = 'https://api.openai.com/v1'
-
-/**
- * One verified model contract: the documented model id, the snapshot ids the
- * same page lists for it, and the official page they were read from.
- */
-export interface DocumentedOpenAIImageModel {
- /** Documented model id, accepted verbatim as `model` by the Chat Completions API. */
- readonly id: string
- /** Snapshot ids listed for {@link id} on the same page; empty for pointer aliases. */
- readonly snapshots: readonly string[]
- /** Official page this contract was verified against. */
- readonly source: string
-}
-
-/**
- * Verified on 2026-09-17. Every entry's page documents image input and the
- * snapshot ids listed here. This is provider-local contract data, not a
- * replacement for discovery or the broader capability catalog in #654.
- */
-export const DOCUMENTED_OPENAI_IMAGE_MODELS: readonly DocumentedOpenAIImageModel[] = Object.freeze([
- Object.freeze({
- id: 'gpt-4.1',
- snapshots: Object.freeze(['gpt-4.1-2025-04-14']),
- source: 'https://developers.openai.com/api/docs/models/gpt-4.1',
- }),
- Object.freeze({
- id: 'gpt-4.1-mini',
- snapshots: Object.freeze(['gpt-4.1-mini-2025-04-14']),
- source: 'https://developers.openai.com/api/docs/models/gpt-4.1-mini',
- }),
- Object.freeze({
- id: 'gpt-4.1-nano',
- snapshots: Object.freeze(['gpt-4.1-nano-2025-04-14']),
- source: 'https://developers.openai.com/api/docs/models/gpt-4.1-nano',
- }),
- Object.freeze({
- id: 'gpt-4o',
- snapshots: Object.freeze(['gpt-4o-2024-05-13', 'gpt-4o-2024-08-06', 'gpt-4o-2024-11-20']),
- source: 'https://developers.openai.com/api/docs/models/gpt-4o',
- }),
- Object.freeze({
- id: 'gpt-4o-mini',
- snapshots: Object.freeze(['gpt-4o-mini-2024-07-18']),
- source: 'https://developers.openai.com/api/docs/models/gpt-4o-mini',
- }),
- Object.freeze({
- id: 'gpt-5.4-mini',
- snapshots: Object.freeze(['gpt-5.4-mini-2026-03-17']),
- source: 'https://developers.openai.com/api/docs/models/gpt-5.4-mini',
- }),
- Object.freeze({
- id: 'gpt-5.4',
- snapshots: Object.freeze(['gpt-5.4-2026-03-05']),
- source: 'https://developers.openai.com/api/docs/models/gpt-5.4',
- }),
- Object.freeze({
- id: 'gpt-5.4-nano',
- snapshots: Object.freeze(['gpt-5.4-nano-2026-03-17']),
- source: 'https://developers.openai.com/api/docs/models/gpt-5.4-nano',
- }),
- Object.freeze({
- id: 'gpt-5',
- snapshots: Object.freeze(['gpt-5-2025-08-07']),
- source: 'https://developers.openai.com/api/docs/models/gpt-5',
- }),
- Object.freeze({
- id: 'gpt-5-mini',
- snapshots: Object.freeze(['gpt-5-mini-2025-08-07']),
- source: 'https://developers.openai.com/api/docs/models/gpt-5-mini',
- }),
- Object.freeze({
- id: 'gpt-5-nano',
- snapshots: Object.freeze(['gpt-5-nano-2025-08-07']),
- source: 'https://developers.openai.com/api/docs/models/gpt-5-nano',
- }),
- Object.freeze({
- id: 'gpt-5-chat-latest',
- snapshots: Object.freeze([]),
- source: 'https://developers.openai.com/api/docs/models/gpt-5-chat-latest',
- }),
- Object.freeze({
- id: 'gpt-5.1-chat-latest',
- snapshots: Object.freeze([]),
- source: 'https://developers.openai.com/api/docs/models/gpt-5.1-chat-latest',
- }),
- Object.freeze({
- id: 'gpt-5.2-chat-latest',
- snapshots: Object.freeze([]),
- source: 'https://developers.openai.com/api/docs/models/gpt-5.2-chat-latest',
- }),
- Object.freeze({
- id: 'gpt-5.3-chat-latest',
- snapshots: Object.freeze([]),
- source: 'https://developers.openai.com/api/docs/models/gpt-5.3-chat-latest',
- }),
-])
-
-const UNKNOWN = Object.freeze({ status: 'unknown' as const })
-
-/** Aliases and snapshots share one lookup: both are documented model ids. */
-const DOCUMENTED_MODEL_IDS: ReadonlySet<string> = new Set(
- DOCUMENTED_OPENAI_IMAGE_MODELS.flatMap(entry => [entry.id, ...entry.snapshots])
-)
-
-/**
- * Reads the documented image-input contract for one exact model id. Returns
- * `supported` with the requested id only when the transport targets the official
- * OpenAI endpoint and this module has a verified contract for that id;
- * otherwise `unknown`, so an unproven model is never handed an image.
- */
-export function getDocumentedOpenAIImageCapability(
- model: string,
- baseURL: string | undefined
-): ImageInputCapability {
- if (!targetsOfficialOpenAiEndpoint(baseURL)) return UNKNOWN
- // Exact membership only: no trimming, no case folding, no prefix family.
- if (!DOCUMENTED_MODEL_IDS.has(model)) return UNKNOWN
-
- return Object.freeze({
- status: 'supported' as const,
- provider: OPENAI_PROVIDER,
- model,
- evidence: OPENAI_DOCUMENTED_EVIDENCE,
- })
-}
-
-/**
- * True only for the resolved official `https://api.openai.com/v1` base. This
- * receives the SDK instance's effective URL, not its optional constructor input.
- * An absent endpoint is therefore unverified. Any other origin, path,
- * scheme, port, or a URL carrying userinfo, query, or fragment is a different
- * deployment whose model contracts this table does not describe.
- */
-function targetsOfficialOpenAiEndpoint(baseURL: string | undefined): boolean {
- if (baseURL === undefined) return false
-
- let url: URL
- try {
- url = new URL(baseURL)
- } catch {
- // A relative, empty, or malformed base URL cannot be proven official.
- return false
- }
- if (url.protocol !== 'https:') return false
- if (url.username !== '' || url.password !== '') return false
- if (url.search !== '' || url.hash !== '') return false
- if (url.hostname !== 'api.openai.com') return false
- if (url.port !== '' && url.port !== '443') return false
- // One optional trailing slash is equivalent; `//` and every other path are not.
- const path = url.pathname.endsWith('/') ? url.pathname.slice(0, -1) : url.pathname
- return path === '/v1'
-}
diff --git a/mcp-host/src/visualInput/documentedZaiCapabilities.test.ts b/mcp-host/src/visualInput/documentedZaiCapabilities.test.ts
deleted file mode 100644
index 1aea878bf..000000000
--- a/mcp-host/src/visualInput/documentedZaiCapabilities.test.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-import { describe, expect, it } from 'vitest'
-import {
- DOCUMENTED_ZAI_IMAGE_MODELS,
- OFFICIAL_ZAI_CODING_BASE_URL,
- ZAI_DOCUMENTED_EVIDENCE,
- ZAI_PROVIDER,
- getDocumentedZaiImageCapability,
-} from './documentedZaiCapabilities'
-
-const OFFICIAL = OFFICIAL_ZAI_CODING_BASE_URL
-const DOCUMENTED_MODEL = 'glm-5.3-flash'
-
-function expectSupported(model: string, baseURL: string | undefined): void {
- expect(getDocumentedZaiImageCapability(model, baseURL)).toEqual({
- status: 'supported',
- provider: 'zai',
- model,
- evidence: 'zai-documented-model-contract',
- })
-}
-
-function expectUnknown(model: string, baseURL: string | undefined = OFFICIAL): void {
- expect(getDocumentedZaiImageCapability(model, baseURL)).toEqual({ status: 'unknown' })
-}
-
-describe('getDocumentedZaiImageCapability', () => {
- it('reports the documented contract for every table entry', () => {
- expect(ZAI_PROVIDER).toBe('zai')
- expect(ZAI_DOCUMENTED_EVIDENCE).toBe('zai-documented-model-contract')
- expect(OFFICIAL_ZAI_CODING_BASE_URL).toBe('https://api.z.ai/api/coding/paas/v4')
- expect(DOCUMENTED_ZAI_IMAGE_MODELS.length).toBeGreaterThan(0)
-
- for (const entry of DOCUMENTED_ZAI_IMAGE_MODELS) {
- expectSupported(entry.id, OFFICIAL)
- expectSupported(entry.id, `${OFFICIAL}/`)
- expect(getDocumentedZaiImageCapability(entry.id, undefined)).toEqual({ status: 'unknown' })
- }
- })
-
- it('keeps unlisted GLM ids unknown on the official endpoint', () => {
- expectUnknown('glm-4.7')
- expectUnknown('glm-5.1')
- expectUnknown('glm-5.3')
- expectUnknown(`${DOCUMENTED_MODEL}-preview`)
- })
-
- it('does not infer support from whitespace, case, or family prefixes', () => {
- expectUnknown(` ${DOCUMENTED_MODEL}`)
- expectUnknown(DOCUMENTED_MODEL.toUpperCase())
- expectUnknown(`zai/${DOCUMENTED_MODEL}`)
- })
-
- it('rejects any transport that is not the official Coding Plan endpoint', () => {
- expectUnknown(DOCUMENTED_MODEL, 'https://api.z.ai/api/paas/v4')
- expectUnknown(DOCUMENTED_MODEL, 'https://api.openai.com/v1')
- expectUnknown(DOCUMENTED_MODEL, 'http://api.z.ai/api/coding/paas/v4')
- expectUnknown(DOCUMENTED_MODEL, 'https://user:[email protected]/api/coding/paas/v4')
- expectUnknown(DOCUMENTED_MODEL, 'https://api.z.ai/api/coding/paas/v4?x=1')
- expectUnknown(DOCUMENTED_MODEL, 'https://api.z.ai/api/coding/paas/v4#frag')
- expectUnknown(DOCUMENTED_MODEL, 'not-a-url')
- })
-})
diff --git a/mcp-host/src/visualInput/documentedZaiCapabilities.ts b/mcp-host/src/visualInput/documentedZaiCapabilities.ts
deleted file mode 100644
index c079af0ef..000000000
--- a/mcp-host/src/visualInput/documentedZaiCapabilities.ts
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * Documented z.ai image-input capability, resolved offline.
- *
- * z.ai's OpenAI-compatible Models API does not publish a modalities flag this
- * host can treat as authoritative, so there is nothing to read back at runtime.
- * This module binds one factual table of published model contracts to the one
- * endpoint those contracts were published for. A model is image-capable only
- * when both hold:
- *
- * 1. the transport targets the official GLM Coding Plan endpoint, and
- * 2. the exact requested id appears in {@link DOCUMENTED_ZAI_IMAGE_MODELS}.
- *
- * Everything else is `unknown`. There is no prefix, family, or size heuristic.
- * The table is a contract with sources, not a catalog: each entry carries the
- * official page it was verified against. This is provider-local contract data,
- * not a replacement for discovery or the broader capability catalog in #654.
- *
- * This module performs no I/O, reads no key, and never infers capability from a
- * model name. Absence of an entry means "not proven", never "not capable".
- */
-import type { ImageInputCapability } from './policy'
-
-/** The provider identity reported for a supported model. */
-export const ZAI_PROVIDER = 'zai'
-/**
- * Fixed, bounded provenance string. The model id is echoed back exactly as
- * requested, so a caller can correlate the answer with its own request; the
- * evidence never contains upstream text.
- */
-export const ZAI_DOCUMENTED_EVIDENCE = 'zai-documented-model-contract'
-/** The only endpoint whose model contracts this table describes. */
-export const OFFICIAL_ZAI_CODING_BASE_URL = 'https://api.z.ai/api/coding/paas/v4'
-
-/**
- * One verified model contract: the documented model id and the official page
- * it was read from.
- */
-export interface DocumentedZaiImageModel {
- /** Documented model id accepted verbatim by the Chat Completions API. */
- readonly id: string
- /** Official page this contract was verified against. */
- readonly source: string
-}
-
-/**
- * Verified on 2026-09-17. GLM-5.3-Flash is the first native multimodal model
- * in the GLM-5 series and documents image input via `image_url` content blocks
- * on the GLM Coding Plan.
- */
-export const DOCUMENTED_ZAI_IMAGE_MODELS: readonly DocumentedZaiImageModel[] = Object.freeze([
- Object.freeze({
- id: 'glm-5.3-flash',
- source: 'https://docs.z.ai/guides/vlm/glm-5.3-flash',
- }),
-])
-
-const UNKNOWN = Object.freeze({ status: 'unknown' as const })
-
-const DOCUMENTED_MODEL_IDS: ReadonlySet<string> = new Set(
- DOCUMENTED_ZAI_IMAGE_MODELS.map(entry => entry.id)
-)
-
-/**
- * Reads the documented image-input contract for one exact model id. Returns
- * `supported` with the requested id only when the transport targets the official
- * Coding Plan endpoint and this module has a verified contract for that id;
- * otherwise `unknown`, so an unproven model is never handed an image.
- */
-export function getDocumentedZaiImageCapability(
- model: string,
- baseURL: string | undefined
-): ImageInputCapability {
- if (!targetsOfficialZaiCodingEndpoint(baseURL)) return UNKNOWN
- // Exact membership only: no trimming, no case folding, no prefix family.
- if (!DOCUMENTED_MODEL_IDS.has(model)) return UNKNOWN
-
- return Object.freeze({
- status: 'supported' as const,
- provider: ZAI_PROVIDER,
- model,
- evidence: ZAI_DOCUMENTED_EVIDENCE,
- })
-}
-
-/**
- * True only for the resolved official `https://api.z.ai/api/coding/paas/v4`
- * base. An absent endpoint is unverified. Any other origin, path, scheme, port,
- * or a URL carrying userinfo, query, or fragment is a different deployment
- * whose model contracts this table does not describe.
- */
-function targetsOfficialZaiCodingEndpoint(baseURL: string | undefined): boolean {
- if (baseURL === undefined) return false
-
- let url: URL
- try {
- url = new URL(baseURL)
- } catch {
- return false
- }
- if (url.protocol !== 'https:') return false
- if (url.username !== '' || url.password !== '') return false
- if (url.search !== '' || url.hash !== '') return false
- if (url.hostname !== 'api.z.ai') return false
- if (url.port !== '' && url.port !== '443') return false
- const path = url.pathname.endsWith('/') ? url.pathname.slice(0, -1) : url.pathname
- return path === '/api/coding/paas/v4'
-}