Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
21 changes: 21 additions & 0 deletions src/api/message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
25 changes: 17 additions & 8 deletions src/api/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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://'))
}

Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand Down
19 changes: 16 additions & 3 deletions src/features/chat/InputBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 5 additions & 1 deletion src/features/chat/InputBoxAttachments.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ 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
}) => (
<div data-testid="attachment-count">
{attachments.length}
{attachments.map(attachment => (
<span key={attachment.id} data-testid="attachment-meta">
{`${attachment.url ?? ''}|${attachment.uploadStatus ?? ''}|${attachment.progress ?? ''}`}
{attachment.pathOnly ? '|pathOnly' : ''}
</span>
))}
{attachments
Expand Down Expand Up @@ -303,6 +304,9 @@ describe('InputBox attachment handling', () => {
// 项目外的文件用绝对路径做引用;整条链路不碰上传
expect(uploadAttachmentMock).not.toHaveBeenCalled()
expect(screen.getByTestId('attachment-count')).toHaveTextContent('1')
// 引用只写路径(对齐官方 composer 的 path 部件):不进 prompt.files[],
// 服务端就不会把整份文件读进内存,也不会撞上 20MB 上限
expect(screen.getByTestId('attachment-meta')).toHaveTextContent('|pathOnly')
})

it('选中的是模型支持的媒体(图片)→ 内联,不占用 @,也不上传', async () => {
Expand Down
23 changes: 23 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,29 @@ body {
stroke: currentColor;
}

/* 长公式横向滚动(手机窄屏必需)
*
* KaTeX 的 display 公式是 nowrap,超宽时会直接溢出容器被裁掉,末尾看不见。
* 这里把容器改成横向滚动:
* - 不溢出时靠 `margin-inline: auto` 保持居中(跟 KaTeX 默认 text-align 一致)
* - 溢出时 margin 归零、内容左对齐,滚动条能从公式开头一直拖到结尾
* 不能直接用 `justify-content: center`:溢出时左端会跑到不可滚动的负区域里。
* 只作用于块级公式,行内公式仍按正常行内流换行。
*
* 滚动条不写样式:原生滚动条全局隐藏,overlayScrollbar.ts 会扫描
* `overflow-x: auto` 且真的溢出的容器,自动挂 `.os-thumb-x`(表格、代码块同款)。 */
.markdown-content .katex-display {
display: flex;
overflow-x: auto;
overflow-y: hidden;
overscroll-behavior-x: contain;
padding-block: 0.125rem;
}

.markdown-content .katex-display > .katex {
margin-inline: auto;
}

/* Streaming Markdown is rendered in stable/live chunks. Without this, Tailwind
* first:/last: margin utilities run per chunk root and make adjacent blocks too tight.
* Use DOM position (:first-child/:last-child) so settled blocks need no isFirst/isLast props. */
Expand Down
Loading