Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(gfs): tighten audited image input contracts
Alfredo Lopez291cfc56f560
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 7920f127f..77595a5ff 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.370",+ "version": "0.1.371","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.370",+ "version": "0.1.371","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex fbb6fd5d6..1e5649454 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.370",+ "version": "0.1.371","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__/llmPortAdapter.test.ts b/mcp-host/src/core/adapters/__tests__/llmPortAdapter.test.tsindex 510589a9c..8ee3ea435 100644--- a/mcp-host/src/core/adapters/__tests__/llmPortAdapter.test.ts+++ b/mcp-host/src/core/adapters/__tests__/llmPortAdapter.test.ts@@ -702,6 +702,12 @@ 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: [],@@ -713,7 +719,7 @@ describe('LlmPortAdapter image destination degrade', () => {completeSingleTurn: vi.fn(),completeSingleTurnWithTools,getProviderType: () => 'openai' as const,- getImageInputCapability: async () => ({ status: 'unknown' as const }),+ getImageInputCapability: providerCapability,classifyError: vi.fn(),},'unknown-model',@@ -729,6 +735,7 @@ 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/gfsClient.ts b/mcp-host/src/internalTools/gfsClient.tsindex 044f43f0d..9db9a98e9 100644--- a/mcp-host/src/internalTools/gfsClient.ts+++ b/mcp-host/src/internalTools/gfsClient.ts@@ -89,12 +89,16 @@ export function createGfscClient(env: GfsRuntimeEnv): GfscWriteClient {path: string,init: RequestInit = {}): Promise<Response> {+ const headers: Record<string, string> = {}+ new Headers(init.headers).forEach((value, key) => {+ headers[key] = value+ })return fetchFn(`${baseUrl}${path}`, {...init,redirect: 'error',headers: {+ ...headers,[AUTH_HEADER]: `${AUTH_SCHEME} ${await accessValue()}`,- ...(init.headers ?? {}),},})}diff --git a/mcp-host/src/llm/__tests__/codexSubscription.test.ts b/mcp-host/src/llm/__tests__/codexSubscription.test.tsindex 491a057d4..e04c5c44c 100644--- a/mcp-host/src/llm/__tests__/codexSubscription.test.ts+++ b/mcp-host/src/llm/__tests__/codexSubscription.test.ts@@ -681,6 +681,44 @@ describe('CodexSubscriptionProvider', () => {})})+ it('lets a catalogued Codex model send an image through the adapter', async () => {+ const wired = deps()+ const provider = new CodexSubscriptionProvider('gpt-5.6-luna', wired as never)+ const adapter = new LlmPortAdapter(+ provider,+ 'gpt-5.6-luna',+ 'codex-subscription',+ undefined,+ undefined,+ undefined,+ undefined,+ undefined,+ () => ({ capability: undefined })+ )++ await adapter.completeWithTools({ messages: userWithImage(), tools: [] })++ expect(wired.authorize).toHaveBeenCalledOnce()+ expect(wired.authorize.mock.calls[0][0].request.messages[0].contentParts[1]).toMatchObject({+ type: 'image',+ data: PNG_2X2_BASE64,+ source: { kind: 'attachment', attachmentId: 'att-1', messageId: 'msg-1' },+ })+ expect(wired.stream).toHaveBeenCalledOnce()+ })++ it('refuses an image before Codex authorization when the catalog row is absent', async () => {+ const wired = deps()+ const provider = new CodexSubscriptionProvider('gpt-5.6-luna', wired as never)+ const adapter = new LlmPortAdapter(provider, 'gpt-5.6-luna', 'codex-subscription')++ await expect(+ adapter.completeWithTools({ messages: userWithImage(), tools: [] })+ ).rejects.toMatchObject({ code: LlmErrorCode.ImageInputUnknown, retryable: false })+ expect(wired.authorize).not.toHaveBeenCalled()+ expect(wired.stream).not.toHaveBeenCalled()+ })+it.each(METHODS)('authorizes an image through %s without a capability gate', async method => {const wired = deps()const provider = new CodexSubscriptionProvider('gpt-5.6-luna', wired as never)diff --git a/mcp-host/src/visualInput/imageValidation.ts b/mcp-host/src/visualInput/imageValidation.tsindex 9cc38ac2b..119f9468b 100644--- a/mcp-host/src/visualInput/imageValidation.ts+++ b/mcp-host/src/visualInput/imageValidation.ts@@ -325,9 +325,8 @@ function inspectJpeg(bytes: Buffer): JpegDetail {let height = -1let sawFrame = falselet sawScan = false- let sawEnd = false- while (!sawEnd) {+ while (true) {if (offset + 1 >= bytes.byteLength) throw new VisualInputError('invalid_image')if (bytes[offset] !== 0xff) throw new VisualInputError('invalid_image')@@ -341,7 +340,6 @@ function inspectJpeg(bytes: Buffer): JpegDetail {if (marker === 0x00) throw new VisualInputError('invalid_image')if (marker === 0xd9) {- sawEnd = truebreak}// Standalone markers carry no length field.@@ -390,7 +388,7 @@ function inspectJpeg(bytes: Buffer): JpegDetail {// A missing EOI is a truncated stream even though the pinned decoder tolerates// it, because the bytes after the last scan are then unverifiable.- if (!sawFrame || !sawScan || !sawEnd) throw new VisualInputError('invalid_image')+ if (!sawFrame || !sawScan) throw new VisualInputError('invalid_image')return { mimeType: 'image/jpeg', width, height }}diff --git a/mcp-host/src/visualInput/requestPolicy.test.ts b/mcp-host/src/visualInput/requestPolicy.test.tsindex c5eaa3656..c472d8ca5 100644--- a/mcp-host/src/visualInput/requestPolicy.test.ts+++ b/mcp-host/src/visualInput/requestPolicy.test.ts@@ -1,7 +1,7 @@import { describe, expect, it } from 'vitest'import type { ChatMessage } from '../core/types'import { VISUAL_INPUT_LIMITS } from './policy'-import { assertVisualRequestFits, degradeUnverifiedImageInput } from './requestPolicy'+import { assertVisualRequestFits } from './requestPolicy'function messages(count: number): ChatMessage[] {return [@@ -44,21 +44,6 @@ describe('last-mile visual request limits', () => {).toThrow('limit_exceeded')})- it('replaces every image part when the destination cannot take them', () => {- const request = messages(2)- expect(degradeUnverifiedImageInput(request)).toBe(true)- expect(request[0].contentParts?.some(part => part.type === 'image')).toBe(false)- expect(- JSON.parse(- request[0].contentParts![0].type === 'text' ? request[0].contentParts![0].text : '{}'- )- ).toMatchObject({- delivery: 'reference_only',- reason: 'image_input_not_verified_for_selected_model',- })- expect(request[0].content).toContain('not verified')- })-it('does not change existing text-only requests', () => {expect(() =>assertVisualRequestFits(diff --git a/mcp-host/src/visualInput/requestPolicy.ts b/mcp-host/src/visualInput/requestPolicy.tsindex 6c5a5be83..3db6d3c67 100644--- a/mcp-host/src/visualInput/requestPolicy.ts+++ b/mcp-host/src/visualInput/requestPolicy.ts@@ -1,38 +1,6 @@-import type { ChatMessage, MessageContentPart } from '../core/types'+import type { ChatMessage } from '../core/types'import { VISUAL_INPUT_LIMITS, VisualInputError } from './policy'-function referenceResource(part: MessageContentPart) {- if (part.type !== 'image' || part.source?.kind !== 'gfs') return undefined- const { kind, drive, resourceId, gfsUri, version, name } = part.source- return { kind, drive, resourceId, gfsUri, version, name }-}--/** Replace image parts with references when the destination cannot take them. */-export function degradeUnverifiedImageInput(messages: ChatMessage[]): boolean {- let changed = false- for (const message of messages) {- if (!message.contentParts?.some(part => part.type === 'image')) continue- changed = true- message.contentParts = message.contentParts.map(part => {- if (part.type !== 'image') return part- const resource = referenceResource(part)- return {- type: 'text' as const,- text: JSON.stringify({- delivery: 'reference_only',- reason: 'image_input_not_verified_for_selected_model',- ...(resource ? { resource } : {}),- }),- }- })- if (message.role === 'user') {- message.content =- 'Image input was not verified for the selected model. Treat the listed resources as references only.'- }- }- return changed-}-export function hasGfsImageInput(messages: readonly ChatMessage[]): boolean {return messages.some(message =>message.contentParts?.some(part => part.type === 'image' && part.source?.kind === 'gfs')