diff --git a/CHANGELOG.md b/CHANGELOG.md index be8de0c0..6d068038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [v1.0.11] - 2026-11-02 + +- fix(markdown): 长公式支持横向滚动 (44800bdd) +- fix(attachment): 本机路径引用只写路径,不再整份读进 prompt.files[] (983bb028) + ## [v1.0.10] - 2026-10-26 - chore: bump version to 0.7.24 (3cc22e8c) diff --git a/package-lock.json b/package-lock.json index 5bf567d6..2eb0406d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "opencodeui", - "version": "1.0.10", + "version": "1.0.11", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "opencodeui", - "version": "1.0.10", + "version": "1.0.11", "hasInstallScript": true, "license": "GPL-3.0-only", "dependencies": { diff --git a/package.json b/package.json index fc5bd9b3..22b8c296 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "opencodeui", - "version": "1.0.10", + "version": "1.0.11", "description": "A third-party web frontend for OpenCode", "license": "GPL-3.0-only", "type": "module", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 19df3a7d..32515f58 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2725,7 +2725,7 @@ dependencies = [ [[package]] name = "opencodeui" -version = "1.0.10" +version = "1.0.11" dependencies = [ "futures-util", "log", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 504f4020..f7a90d9e 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "opencodeui" -version = "1.0.10" +version = "1.0.11" description = "OpenCode UI - Tauri Mobile App" authors = ["lehhair"] license = "GPL-3.0-only" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 46229e6e..888fa85a 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "../node_modules/@tauri-apps/cli/config.schema.json", "productName": "OpenCode", - "version": "1.0.10", + "version": "1.0.11", "identifier": "com.opencodeui.app", "build": { "frontendDist": "../dist", diff --git a/src/api/message.test.ts b/src/api/message.test.ts index 09b797c9..8c56fd6c 100644 --- a/src/api/message.test.ts +++ b/src/api/message.test.ts @@ -299,6 +299,27 @@ describe('sendMessage — 路径型附件的文本引用', () => { expect(payload.metadata?.attachments).toBeUndefined() }) + it('带 mention 的附件被从文本删掉后仍补路径(pathOnly 只能靠文本可见)', async () => { + await sendMessage({ + ...baseParams(), + text: '看下这个', + attachments: [ + { + id: 'a1', + type: 'file', + displayName: 'foo.ts', + url: 'file:///proj/src/foo.ts', + pathOnly: true, + textRange: { value: '@src/foo.ts', start: 0, end: 11 }, + }, + ] as never, + }) + + const payload = lastPromptPayload() + expect(payload.files).toBeUndefined() + expect(payload.text).toBe('看下这个\nAttached file: `/proj/src/foo.ts`') + }) + it('revert 回填的文本里已有同一引用时不重复追加', async () => { const path = '/tmp/opencode/uploads/u1/report.zip' await sendMessage({ diff --git a/src/api/message.ts b/src/api/message.ts index d82d1648..5492ce1e 100644 --- a/src/api/message.ts +++ b/src/api/message.ts @@ -273,14 +273,20 @@ export function fileUrlToAbsolutePath(url: string): string | undefined { } /** - * 路径型附件:`file://` 引用且**不带 mention**。 + * 路径型附件:`file://` 引用。 * - * 带 mention 的附件(`@` 提及、侧边栏拖入)路径已经在文本里,再补一行 - * 路径引用纯属噪声——官方也是这么区分的(path 部件 vs file 部件)。 + * 带 mention 的附件(`@` 提及、拖入)路径已经在文本里,不再补一行引用 + * ——官方也是这么区分的(path 部件 vs file 部件)。 + * + * 但 pathOnly 附件不会进 `prompt.files[]`,文本是模型看到它的唯一途径。 + * 如果用户把 `@path` 那段删掉了(chip 还在),这里必须补回去, + * 否则模型完全看不到这个附件。 */ -export function isPathReferenceAttachment(attachment: Attachment): boolean { +export function isPathReferenceAttachment(attachment: Attachment, text?: string): boolean { if (attachment.type !== 'file') return false - if (attachment.textRange) return false + if (attachment.textRange) { + return text !== undefined && !text.includes(attachment.textRange.value) + } return Boolean(attachment.url?.startsWith('file://')) } @@ -291,11 +297,14 @@ export function attachmentReferencePath(attachment: Attachment): string | undefi } /** 收集路径引用(去重、保序) */ -export function buildAttachmentReferences(attachments: Attachment[]): PromptAttachmentReference[] { +export function buildAttachmentReferences( + attachments: Attachment[], + text?: string, +): PromptAttachmentReference[] { const references: PromptAttachmentReference[] = [] for (const attachment of attachments) { - if (!isPathReferenceAttachment(attachment)) continue + if (!isPathReferenceAttachment(attachment, text)) continue const path = attachmentReferencePath(attachment) if (!path) continue @@ -384,7 +393,7 @@ function buildPromptInput( const { files, agents, skills } = buildPromptParts(params.attachments) // 路径型附件额外把绝对路径写进文本(官方 request.ts:173-182 同款): // files[].uri 只让服务端读到字节,模型能否看到取决于 mime(见文件顶部说明)。 - const attachmentReferences = buildAttachmentReferences(params.attachments) + const attachmentReferences = buildAttachmentReferences(params.attachments, params.text) return { sessionID, diff --git a/src/features/chat/InputBox.tsx b/src/features/chat/InputBox.tsx index 20192033..1b9150a3 100644 --- a/src/features/chat/InputBox.tsx +++ b/src/features/chat/InputBox.tsx @@ -1246,6 +1246,9 @@ function InputBoxComponent({ mime: item.type === 'reference' ? 'application/x-directory' : item.type !== 'agent' ? 'text/plain' : undefined, agentName: item.type === 'agent' ? item.displayName : undefined, skillId: item.type === 'skill' ? item.value : undefined, + // 物理路径引用只写路径(官方 composer 的 path 部件):`@path` 已在文本里, + // 进 prompt.files[] 只会让服务端把整份文件读进内存,还撞 20MB 上限。 + ...(attachType === 'file' || attachType === 'folder' ? { pathOnly: true } : {}), textRange: { value: mentionText, start: mentionStartIndex, @@ -1474,9 +1477,15 @@ function InputBoxComponent({ } }, []) - // 将拖入的文件信息插入为 @mention 附件 + /** + * 将拖入的文件信息插入为 @mention 附件。 + * + * `pathOnly`:只把路径写进 prompt 文本,不进 `prompt.files[]`。外部拖入的本机 + * 文件走这条(对齐官方 composer 的 `path` 部件):服务端不必把整份文件读进内存、 + * 也不会撞上 20MB 上限,模型按需用工具读。侧边栏内部拖拽仍传 files[]。 + */ const insertDraggedFiles = useCallback( - (fileInfos: DraggedFileInfo[]) => { + (fileInfos: DraggedFileInfo[], options: { pathOnly?: boolean } = {}) => { if (fileInfos.length === 0) return const currentText = textareaRef.current?.value ?? text @@ -1508,6 +1517,7 @@ function InputBoxComponent({ relativePath, url: toFileUrl(fileInfo.absolute), mime: fileInfo.type === 'file' ? 'text/plain' : undefined, + ...(options.pathOnly ? { pathOnly: true } : {}), textRange: { value: mentionText, start, @@ -1737,7 +1747,10 @@ function InputBoxComponent({ setAttachments(prev => [...prev, ...uploadAttachments]) } - insertDraggedFiles(mentionFiles) + // 外部拖入的本机文件只作路径引用(官方 composer 的 `path` 部件): + // 路径已经在 prompt 文本里,再进 files[] 会让服务端把整份文件读进内存, + // 超过 20MB 还会让整条 prompt 以 AttachmentError 失败。 + insertDraggedFiles(mentionFiles, { pathOnly: true }) } catch (err) { console.warn('[InputBox] Failed to process dropped paths:', err) } diff --git a/src/features/chat/InputBoxAttachments.test.tsx b/src/features/chat/InputBoxAttachments.test.tsx index 8298d22f..edba96e1 100644 --- a/src/features/chat/InputBoxAttachments.test.tsx +++ b/src/features/chat/InputBoxAttachments.test.tsx @@ -39,7 +39,7 @@ vi.mock('../attachment', () => ({ attachments, onRetry, }: { - attachments: Array<{ id: string; url?: string; uploadStatus?: string; progress?: number }> + attachments: Array<{ id: string; url?: string; uploadStatus?: string; progress?: number; pathOnly?: boolean }> onRetry?: (id: string) => void }) => (