experiment: better web picker using @pierre/tree (#31208)

This commit is contained in:
Luke Parker 2026-06-16 17:43:23 +02:00 committed by GitHub
commit 88f5b9a90e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 1297 additions and 211 deletions

View file

@ -33,6 +33,7 @@ type PromptAttachmentsInput = {
focusEditor: () => void
addPart: (part: ContentPart) => boolean
readClipboardImage?: () => Promise<File | null>
getPathForFile?: (file: File) => string
}
export function createPromptAttachments(input: PromptAttachmentsInput) {
@ -63,6 +64,7 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
type: "image",
id: uuid(),
filename: file.name,
sourcePath: input.getPathForFile?.(file) || undefined,
mime,
dataUrl: url,
}

View file

@ -75,6 +75,31 @@ describe("buildRequestParts", () => {
expect(files.map((part) => (part.type === "file" ? part.filename : ""))).toEqual(["a.png", "b.pdf"])
})
test("preserves an external attachment source path for the model", () => {
const result = buildRequestParts({
prompt: [],
context: [],
images: [
{
type: "image",
id: "img_external",
filename: "opencode.global.dat",
sourcePath: "C:\\Users\\Luke\\AppData\\Roaming\\ai.opencode.desktop.beta\\opencode.global.dat",
mime: "text/plain",
dataUrl: "data:text/plain;base64,AAA",
},
],
text: "inspect this",
messageID: "msg_external",
sessionID: "ses_external",
sessionDirectory: "C:\\Repos\\sst\\opencode",
})
expect(result.requestParts.find((part) => part.type === "file")?.filename).toBe(
"C:\\Users\\Luke\\AppData\\Roaming\\ai.opencode.desktop.beta\\opencode.global.dat",
)
})
test("deduplicates context files when prompt already includes same path", () => {
const prompt: Prompt = [{ type: "file", path: "src/foo.ts", content: "@src/foo.ts", start: 0, end: 11 }]

View file

@ -188,7 +188,7 @@ export function buildRequestParts(input: BuildRequestPartsInput) {
type: "file",
mime: attachment.mime,
url: attachment.dataUrl,
filename: attachment.filename,
filename: attachment.sourcePath ?? attachment.filename,
} satisfies PromptRequestPart
})