Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🏷️ fix: Drop a File Name Removed Through the UI Parts View (#17184)
Marco Berettaf5c7bc6b541f
diff --git a/e2e/specs/mock/scenarios/parts.spec.ts b/e2e/specs/mock/scenarios/parts.spec.tsindex f6da16160f..dc9505561e 100644--- a/e2e/specs/mock/scenarios/parts.spec.ts+++ b/e2e/specs/mock/scenarios/parts.spec.ts@@ -10,8 +10,10 @@ import {NEW_CHAT_PATH,replyPrompt,thinkPrompt,+ uploadViaUnifiedButton,replyText,thinkText,+ uniqueName,fetchJson,} from '../helpers';@@ -100,6 +102,43 @@ test.describe('UI parts view of persisted messages', () => {expect(assistant.parts[reasoning]).toMatchObject({ text: thinkText(label) });});+ test('drops an attachment name removed through the view @scenario:attachment-name-removed-through-the-view-is-dropped', async ({+ page,+ }) => {+ test.setTimeout(90_000);+ const label = uniqueLabel('parts-file');+ const fileName = `${uniqueName('parts-doc')}.md`;+ await page.goto(NEW_CHAT_PATH, { timeout: 10_000 });+ await selectMockEndpoint(page, MOCK_ENDPOINTS[1]);+ const upload = await uploadViaUnifiedButton(page, {+ name: fileName,+ mimeType: 'text/markdown',+ content: '# Parts view\n',+ });+ expect(upload.ok()).toBeTruthy();+ await expect(page.getByRole('button', { name: fileName })).toBeVisible({ timeout: 15_000 });+ const response = await sendMessageAndWaitForCompletion(page, replyPrompt(label));+ expect(response.ok()).toBeTruthy();++ const messages = await readPersistedMessages(page);+ const views = viewAndRestore(messages);+ const index = messages.findIndex((message) => message.isCreatedByUser);+ const stored = messages[index];+ const storedFile = stored.files?.find((file) => file.filename === fileName);+ if (!storedFile) {+ throw new Error('Persisted attachment missing');+ }++ const parts = views[index].parts.map((part) =>+ part.type === 'file' && part.filename === fileName ? { ...part, filename: undefined } : part,+ );+ const restored = fromUIMessage({ ...views[index], parts }, stored).files?.find(+ (file) => file.file_id === storedFile.file_id,+ );+ expect(restored).not.toHaveProperty('filename');+ expect(restored).toEqual({ ...storedFile, filename: undefined });+ });+test.describe('with an MCP tool turn', () => {test.skip(({ isMobile }) => isMobile === true, 'composer MCP picker is desktop-only');diff --git a/packages/data-provider/src/parts.spec.ts b/packages/data-provider/src/parts.spec.tsindex 6abe45da8b..c1b7c15eff 100644--- a/packages/data-provider/src/parts.spec.ts+++ b/packages/data-provider/src/parts.spec.ts@@ -836,6 +836,55 @@ describe('parts', () => {]);});+ it('removes the stored filename when the attachment view drops it', () => {+ const stored = {+ file_id: 'a',+ filepath: '/files/a.pdf',+ filename: 'a.pdf',+ type: 'application/pdf',+ };+ const { filename: _filename, ...unnamed } = stored;+ const message = createMessage({ isCreatedByUser: true, text: 'File', files: [stored] });+ const view = toUIMessage(message);+ const parts = view.parts.map((part) => {+ if (part.type !== 'file') {+ return part;+ }+ const { filename: _dropped, ...rest } = part;+ return rest;+ });++ expect(fromUIMessage({ ...view, parts }, message).files).toStrictEqual([unnamed]);+ expect(fromUIMessage(view, message)).toStrictEqual(message);+ });++ it('removes the stored image file name when the view drops it', () => {+ const part = samples[ContentTypes.IMAGE_FILE] as TMessageContentParts;+ const { filename: _dropped, ...edited } = toUIPart(part) as Extract<+ UIMessagePart,+ { type: 'file' }+ >;++ const restored = fromUIPart(edited) as Extract<+ TMessageContentParts,+ { type: ContentTypes.IMAGE_FILE }+ >;+ expect(restored.image_file).not.toHaveProperty('filename');+ expect(fromUIPart(toUIPart(part) as UIMessagePart)).toStrictEqual(part);+ });++ it('keeps an empty stored attachment filename the view never showed', () => {+ const stored = {+ file_id: 'a',+ filepath: '/files/a.pdf',+ filename: '',+ type: 'application/pdf',+ };+ const message = createMessage({ isCreatedByUser: true, text: 'File', files: [stored] });++ expect(fromUIMessage(toUIMessage(message), message).files).toStrictEqual([stored]);+ });+it('keeps an explicit null parent instead of the stored one', () => {const message = createMessage({text: 'Hi',diff --git a/packages/data-provider/src/parts.ts b/packages/data-provider/src/parts.tsindex 84b715eded..13f0c1ee9c 100644--- a/packages/data-provider/src/parts.ts+++ b/packages/data-provider/src/parts.ts@@ -673,6 +673,8 @@ const applyFileEdits = <F extends Partial<TFile>>(}if (part.filename !== undefined && part.filename !== file.filename) {edited.filename = part.filename;+ } else if (part.filename === undefined && file.filename) {+ delete edited.filename;}if (part.mediaType !== (file.type || fallbackType)) {edited.type = part.mediaType;