Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(web-app): reload a stored data-URL image with the media type it declares
thinhlpgb71891e6b811
diff --git a/web-app/src/lib/__tests__/messages.test.ts b/web-app/src/lib/__tests__/messages.test.tsindex 8018f38db..04fdb7b83 100644--- a/web-app/src/lib/__tests__/messages.test.ts+++ b/web-app/src/lib/__tests__/messages.test.ts@@ -193,6 +193,14 @@ describe('convertThreadMessageToUIMessage', () => {expect(result.parts).toContainEqual({ type: 'file', mediaType: 'image/jpeg', url: 'http://img.png' })})+ it('reloads a data-URL image with the media type the URL declares', () => {+ const url = 'data:image/png;base64,iVBORw0KGgo='+ const result = convertThreadMessageToUIMessage(makeTm({+ role: 'user', content: [{ type: 'image_url', image_url: { url } }],+ }) as any)+ expect(result.parts).toContainEqual({ type: 'file', mediaType: 'image/png', url })+ })+it('converts input_audio content to a file part with audio mediaType', () => {const wav = convertThreadMessageToUIMessage(makeTm({role: 'user',diff --git a/web-app/src/lib/messages.ts b/web-app/src/lib/messages.tsindex 7c70e83d8..aa11189d8 100644--- a/web-app/src/lib/messages.ts+++ b/web-app/src/lib/messages.ts@@ -270,10 +270,15 @@ export function convertThreadMessageToUIMessage(// renders in the reasoning UI instead of inline (see reasoningPartsFromText).parts.push(...reasoningPartsFromText(content.text.value))} else if (content.type === 'image_url' && content.image_url?.url) {+ // The stored record keeps only the url; a data URL names its own type,+ // which a provider that sends base64 with a media type checks against+ // the bytes.+ const url = content.image_url.url+ const declared = /^data:(image\/[a-z0-9.+-]+)[;,]/i.exec(url)?.[1]parts.push({type: 'file',- mediaType: 'image/jpeg',- url: content.image_url.url,+ mediaType: declared?.toLowerCase() ?? 'image/jpeg',+ url,})} else if (content.type === 'input_audio' && content.input_audio?.data) {const fmt = content.input_audio.format