Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(chat): inline an attachment once per request, not once per turn (#9022) (#9358)
James Dam80ff060ad2a9
diff --git a/web-app/src/lib/__tests__/custom-chat-transport-class.test.ts b/web-app/src/lib/__tests__/custom-chat-transport-class.test.tsindex 0a07949de..5f9965018 100644--- a/web-app/src/lib/__tests__/custom-chat-transport-class.test.ts+++ b/web-app/src/lib/__tests__/custom-chat-transport-class.test.ts@@ -1,4 +1,5 @@import { describe, expect, it, vi, beforeEach } from 'vitest'+import type { UIMessage } from '@ai-sdk/react'import { CustomChatTransport, normalizeToolInputSchema } from '../custom-chat-transport'// Mock all the heavy dependencies@@ -120,6 +121,29 @@ describe('CustomChatTransport', () => {expect(result[0].parts[0].text).toContain('hello world')})+ it('does not mutate reused messages when mapping inline file content', () => {+ const messages = [+ {+ id: 'user-1',+ role: 'user',+ parts: [{ type: 'text', text: 'Check this' }],+ metadata: {+ inline_file_contents: [{ name: 'file.txt', content: 'hello world' }],+ },+ },+ ] as UIMessage[]++ // The chat passes the same message objects on every turn (#9022), so each+ // mapping must inline the file exactly once.+ for (let turn = 0; turn < 3; turn++) {+ const mapped = transport.mapUserInlineAttachments(messages)+ expect(mapped[0].parts).toEqual([+ { type: 'text', text: 'Check this\n\nFile: file.txt\nhello world' },+ ])+ }+ expect(messages[0].parts).toEqual([{ type: 'text', text: 'Check this' }])+ })+it('mapUserInlineAttachments ignores entries without content', () => {const messages = [{diff --git a/web-app/src/lib/custom-chat-transport.ts b/web-app/src/lib/custom-chat-transport.tsindex 823a740f9..e9a1c059c 100644--- a/web-app/src/lib/custom-chat-transport.ts+++ b/web-app/src/lib/custom-chat-transport.ts@@ -1885,7 +1885,7 @@ export class CustomChatTransport implements ChatTransport<UIMessage> {}return part})- message.parts = parts+ return { ...message, parts }}}}