From 94210ac0a1b0bb142e02f5056238c79b002417d8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 8 Sep 2026 15:53:05 +0200 Subject: [PATCH] feat: attach images to clinical search with strict validation and multimodal routing --- docs/CLINICAL_ASSISTANT.md | 11 + public/components/assistant.html | 3 + public/css/assistant.css | 8 + public/js/assistant/api.js | 16 + public/js/clinicalAssistant.js | 95 +++++- src/routes/clinicalAssistant.js | 17 +- src/utils/ai.js | 35 +- src/utils/clinicalConversation.js | 44 ++- test/assistant-image-attachments.test.js | 411 +++++++++++++++++++++++ 9 files changed, 630 insertions(+), 10 deletions(-) create mode 100644 test/assistant-image-attachments.test.js diff --git a/docs/CLINICAL_ASSISTANT.md b/docs/CLINICAL_ASSISTANT.md index 497e888..9b09f9f 100644 --- a/docs/CLINICAL_ASSISTANT.md +++ b/docs/CLINICAL_ASSISTANT.md @@ -72,6 +72,16 @@ show me the image/figure Clinical answer response caching is intentionally disabled. Redis can support prompt suggestions and operational metadata, but final answers should be generated from current retrieval context. +## Image Attachments + +Users can attach up to 4 images (PNG, JPEG, WebP) to an outgoing clinical question. Attachments are **input-only**: + +- They are validated client-side and authoritatively on the server (MIME allowlist, canonical base64, ≤ 5 MiB per image, ≤ 4 images, ≤ 10 MiB decoded total). Invalid input is rejected with 400 before any retrieval or provider call. +- They are sent **only** with the outgoing clinical question, never with handoff summaries, image generation, saved chats, downloads or transcripts. +- The conversation budget counts text only: images are excluded from the UTF-16 code-unit count. The server still validates every request. +- Only OpenAI-compatible providers (LiteLLM, OpenRouter, Azure) receive them as multimodal content parts (`text` + `image_url` data URIs) on the latest user message; the system/retrieval/history structure is unchanged. Legacy direct adapters (Bedrock/Vertex) refuse with a clear 400 before contacting the provider. +- Attachments clear on a successful send and on New chat; a rejected send keeps them for correction. + ## Settings Important settings include: @@ -93,5 +103,6 @@ Add or update tests when changing: - named-source provenance behavior, - table rendering, - image intent routing, +- image attachment validation and multimodal payload shape, - MCP result normalization, - model discovery or settings behavior. diff --git a/public/components/assistant.html b/public/components/assistant.html index 0efc363..b3a2a6c 100644 --- a/public/components/assistant.html +++ b/public/components/assistant.html @@ -44,8 +44,11 @@

Loading conversation limit; history and draft are counted in UTF-16 code units. The server validates each request.

+