fix(app): restore device attachment picker (#31707)
This commit is contained in:
@@ -264,7 +264,6 @@ function createSessionEntries(props: {
|
|||||||
export function DialogSelectFile(props: {
|
export function DialogSelectFile(props: {
|
||||||
mode?: DialogSelectFileMode
|
mode?: DialogSelectFileMode
|
||||||
onOpenFile?: (path: string) => void
|
onOpenFile?: (path: string) => void
|
||||||
onSelectFile?: (path: string) => void
|
|
||||||
}) {
|
}) {
|
||||||
const command = useCommand()
|
const command = useCommand()
|
||||||
const language = useLanguage()
|
const language = useLanguage()
|
||||||
@@ -379,10 +378,6 @@ export function DialogSelectFile(props: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!item.path) return
|
if (!item.path) return
|
||||||
if (props.onSelectFile) {
|
|
||||||
props.onSelectFile(item.path)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
open(item.path)
|
open(item.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ import { usePermission } from "@/context/permission"
|
|||||||
import { useLanguage } from "@/context/language"
|
import { useLanguage } from "@/context/language"
|
||||||
import { usePlatform } from "@/context/platform"
|
import { usePlatform } from "@/context/platform"
|
||||||
import { useSettings } from "@/context/settings"
|
import { useSettings } from "@/context/settings"
|
||||||
import { serverAttachmentFile } from "./prompt-input/server-attachment"
|
|
||||||
import { useSessionLayout } from "@/pages/session/session-layout"
|
import { useSessionLayout } from "@/pages/session/session-layout"
|
||||||
import { createSessionTabs } from "@/pages/session/helpers"
|
import { createSessionTabs } from "@/pages/session/helpers"
|
||||||
import { createTextFragment, getCursorPosition, setCursorPosition, setRangeEdge } from "./prompt-input/editor-dom"
|
import { createTextFragment, getCursorPosition, setCursorPosition, setRangeEdge } from "./prompt-input/editor-dom"
|
||||||
@@ -473,7 +472,6 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
|
|||||||
const escBlur = () => platform.platform === "desktop" && platform.os === "macos"
|
const escBlur = () => platform.platform === "desktop" && platform.os === "macos"
|
||||||
|
|
||||||
const pick = () => {
|
const pick = () => {
|
||||||
if (server.isLocal()) {
|
|
||||||
pickAttachmentFiles({
|
pickAttachmentFiles({
|
||||||
picker: platform.openAttachmentPickerDialog,
|
picker: platform.openAttachmentPickerDialog,
|
||||||
directory: () => sdk.directory,
|
directory: () => sdk.directory,
|
||||||
@@ -486,21 +484,6 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
|
|||||||
description: error instanceof Error ? error.message : String(error),
|
description: error instanceof Error ? error.message : String(error),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
|
||||||
void import("@/components/dialog-select-file").then((module) =>
|
|
||||||
dialog.show(() => (
|
|
||||||
<module.DialogSelectFile
|
|
||||||
mode="files"
|
|
||||||
onSelectFile={(path) => {
|
|
||||||
void sdk.client.v2.fs
|
|
||||||
.read({ path })
|
|
||||||
.then((response) => response.data?.data)
|
|
||||||
.then((data) => data && addAttachments([serverAttachmentFile(path, data)]))
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const setMode = (mode: "normal" | "shell") => {
|
const setMode = (mode: "normal" | "shell") => {
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
import { describe, expect, test } from "bun:test"
|
|
||||||
import { serverAttachmentFile } from "./server-attachment"
|
|
||||||
|
|
||||||
describe("serverAttachmentFile", () => {
|
|
||||||
test("creates a file from server text content", async () => {
|
|
||||||
const file = serverAttachmentFile("docs/readme.txt", {
|
|
||||||
uri: "file:///docs/readme.txt",
|
|
||||||
name: "readme.txt",
|
|
||||||
content: "hello",
|
|
||||||
encoding: "utf8",
|
|
||||||
mime: "text/plain",
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(file.name).toBe("readme.txt")
|
|
||||||
expect(file.type).toBe("text/plain")
|
|
||||||
expect(await file.text()).toBe("hello")
|
|
||||||
})
|
|
||||||
|
|
||||||
test("creates a file from server base64 content", async () => {
|
|
||||||
const file = serverAttachmentFile("images/pixel.png", {
|
|
||||||
uri: "file:///images/pixel.png",
|
|
||||||
name: "pixel.png",
|
|
||||||
content: "aGVsbG8=",
|
|
||||||
encoding: "base64",
|
|
||||||
mime: "image/png",
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(file.name).toBe("pixel.png")
|
|
||||||
expect(file.type).toBe("image/png")
|
|
||||||
expect(await file.text()).toBe("hello")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
import { getFilename } from "@opencode-ai/core/util/path"
|
|
||||||
import type { FileSystemContent } from "@opencode-ai/sdk/v2"
|
|
||||||
|
|
||||||
export function serverAttachmentFile(path: string, data: FileSystemContent) {
|
|
||||||
const content =
|
|
||||||
data.encoding === "utf8" ? data.content : Uint8Array.from(atob(data.content), (char) => char.charCodeAt(0))
|
|
||||||
return new File([content], getFilename(path), { type: data.mime })
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user