fix(app): preserve inline file mentions (#38663)

This commit is contained in:
Brendan Allan 2026-07-24 18:28:09 +08:00 committed by GitHub
commit b62806683e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 98 additions and 22 deletions

View file

@ -21,7 +21,7 @@ describe("message-file", () => {
expect(attached(file())).toBe(false)
})
test("treats only non-attachment source ranges as inline references", () => {
test("keeps data-backed file mentions inline", () => {
expect(
inline(
file({
@ -34,18 +34,16 @@ describe("message-file", () => {
),
).toBe(true)
expect(
inline(
file({
url: "data:text/plain;base64,SGVsbG8=",
source: {
type: "file",
path: "/repo/README.txt",
text: { value: "@README.txt", start: 0, end: 11 },
},
}),
),
).toBe(false)
const mentioned = file({
url: "data:text/plain;base64,SGVsbG8=",
source: {
type: "file",
path: "/repo/README.txt",
text: { value: "@README.txt", start: 0, end: 11 },
},
})
expect(inline(mentioned)).toBe(true)
expect(attached(mentioned)).toBe(false)
})
test("separates image and file attachment kinds", () => {

View file

@ -3,11 +3,10 @@ import { getFilename } from "@opencode-ai/core/util/path"
import type { FilePart } from "@opencode-ai/sdk/v2"
export function attached(part: FilePart) {
return part.url.startsWith("data:")
return part.url.startsWith("data:") && !inline(part)
}
export function inline(part: FilePart) {
if (attached(part)) return false
return part.source?.text?.start !== undefined && part.source?.text?.end !== undefined
}