Răsfoiți Sursa

fix: 兼容带引号的历史附件引用

samien 2 luni în urmă
părinte
comite
a3f631ba1d

+ 1 - 1
src/client/utils/normalize.ts

@@ -175,7 +175,7 @@ function attachmentMime(name: string): { mimeType: string; kind: ChatAttachment[
 function extractPersistedAttachments(content: string): { content: string; attachments: ChatAttachment[] } {
   const attachments: ChatAttachment[] = []
   const cleaned = content.replace(
-    /\[用户附加\s*(文件|图片|PDF)\s*:\s*([^\]\r\n]+)\]\s*(?:\r?\n)?@file:\s*((?:\\?\/)[^\r\n]+)/g,
+    /\[用户附加\s*(文件|图片|PDF)\s*:\s*([^\]\r\n]+)\]\s*(?:\r?\n)?@file:\s*(`[^`\r\n]+`|'[^'\r\n]+'|"[^"\r\n]+"|(?:\\?\/)[^\r\n]+)/g,
     (_match, _type: string, rawName: string, rawPath: string) => {
       const name = rawName.trim()
       const path = rawPath.trim().replace(/\\\//g, '/').replace(/^[`'"]|[`'"]$/g, '')

+ 21 - 6
tests/client/messageDisplay.test.ts

@@ -6,14 +6,29 @@ describe('displayContentForMessage', () => {
   it('turns persisted user @file markers into attachment cards and removes marker text', () => {
     const message = normalizeChatMessage({
       id: 'user-file', role: 'user', timestamp: 1,
-      content: '刘博士的技术介绍。\n\n[用户附加文件:大模型推理优化报告.docx]\n@file:\\/Users/samien/.hermes/attachments/大模型推理优化报告.docx',
+      content: [
+        '刘博士的技术介绍。',
+        '',
+        '[用户附加文件:大模型推理优化报告.docx]',
+        '@file:\\/Users/samien/.hermes/attachments/大模型推理优化报告.docx',
+        '',
+        '[用户附加文件:MMLU_PRO_多模型协同评测系统_技术报告PPT_(1).pptx]',
+        '@file:`/Users/samien/.hermes/attachments/MMLU_PRO_多模型协同评测系统_技术报告PPT_(1).pptx`',
+      ].join('\n'),
     }, 'session-1', 'default')
     expect(message.content).toBe('刘博士的技术介绍。')
-    expect(message.attachments).toEqual([expect.objectContaining({
-      name: '大模型推理优化报告.docx',
-      path: '/Users/samien/.hermes/attachments/大模型推理优化报告.docx',
-      kind: 'file',
-    })])
+    expect(message.attachments).toEqual([
+      expect.objectContaining({
+        name: '大模型推理优化报告.docx',
+        path: '/Users/samien/.hermes/attachments/大模型推理优化报告.docx',
+        kind: 'file',
+      }),
+      expect.objectContaining({
+        name: 'MMLU_PRO_多模型协同评测系统_技术报告PPT_(1).pptx',
+        path: '/Users/samien/.hermes/attachments/MMLU_PRO_多模型协同评测系统_技术报告PPT_(1).pptx',
+        kind: 'file',
+      }),
+    ])
   })
   it('hides expanded attached context while restoring a missing reference', () => {
     const content = [

+ 1 - 1
tests/fixtures/fake-hermes.mjs

@@ -42,7 +42,7 @@ const sessions = [
 ]
 const messages = [
   { id: 'message-user', role: 'user', content: '请检查今天生成的产物。MEDIA:/brand/AppIcon-1024.png', timestamp: now() - 180 },
-  { id: 'message-user-file', role: 'user', content: '查看附件\n\n[用户附加文件:测试报告.docx]\n@file:/Users/samien/.hermes/attachments/测试报告.docx', timestamp: now() - 179 },
+  { id: 'message-user-file', role: 'user', content: '查看附件\n\n[用户附加文件:测试报告.docx]\n@file:`/Users/samien/.hermes/attachments/测试报告.docx`', timestamp: now() - 179 },
   { id: 'message-thinking-tool', role: 'assistant', content: '', reasoning_content: '先检索文件,再归纳结果。', tool_calls: [{ id: 'tool-thinking', type: 'function', function: { name: 'file_search', arguments: '{"query":"产物"}' } }], timestamp: now() - 177 },
   { id: 'message-tool-call', role: 'assistant', content: '', tool_calls: [{ id: 'tool-1', type: 'function', function: { name: 'file_search', arguments: '{"query":"产物"}' } }], timestamp: now() - 176 },
   { id: 'message-tool', role: 'tool', tool_name: 'file_search', tool_call_id: 'tool-1', summary: '扫描产物目录', result: { path: '/tmp/demo-report.pdf', count: 1 }, timestamp: now() - 175 },