Преглед на файлове

fix(app): restore device attachment picker (#31707)

mridul преди 2 месеца
родител
ревизия
649618c50a

+ 0 - 5
packages/app/src/components/dialog-select-file.tsx

@@ -264,7 +264,6 @@ function createSessionEntries(props: {
 export function DialogSelectFile(props: {
   mode?: DialogSelectFileMode
   onOpenFile?: (path: string) => void
-  onSelectFile?: (path: string) => void
 }) {
   const command = useCommand()
   const language = useLanguage()
@@ -379,10 +378,6 @@ export function DialogSelectFile(props: {
     }
 
     if (!item.path) return
-    if (props.onSelectFile) {
-      props.onSelectFile(item.path)
-      return
-    }
     open(item.path)
   }
 

+ 12 - 29
packages/app/src/components/prompt-input.tsx

@@ -53,7 +53,6 @@ import { usePermission } from "@/context/permission"
 import { useLanguage } from "@/context/language"
 import { usePlatform } from "@/context/platform"
 import { useSettings } from "@/context/settings"
-import { serverAttachmentFile } from "./prompt-input/server-attachment"
 import { useSessionLayout } from "@/pages/session/session-layout"
 import { createSessionTabs } from "@/pages/session/helpers"
 import { createTextFragment, getCursorPosition, setCursorPosition, setRangeEdge } from "./prompt-input/editor-dom"
@@ -473,34 +472,18 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
   const escBlur = () => platform.platform === "desktop" && platform.os === "macos"
 
   const pick = () => {
-    if (server.isLocal()) {
-      pickAttachmentFiles({
-        picker: platform.openAttachmentPickerDialog,
-        directory: () => sdk.directory,
-        fallback: () => fileInputRef?.click(),
-        onFile: addAttachment,
-        onError: (error) =>
-          showToast({
-            variant: "error",
-            title: language.t("common.requestFailed"),
-            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)]))
-          }}
-        />
-      )),
-    )
+    pickAttachmentFiles({
+      picker: platform.openAttachmentPickerDialog,
+      directory: () => sdk.directory,
+      fallback: () => fileInputRef?.click(),
+      onFile: addAttachment,
+      onError: (error) =>
+        showToast({
+          variant: "error",
+          title: language.t("common.requestFailed"),
+          description: error instanceof Error ? error.message : String(error),
+        }),
+    })
   }
 
   const setMode = (mode: "normal" | "shell") => {

+ 0 - 32
packages/app/src/components/prompt-input/server-attachment.test.ts

@@ -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")
-  })
-})

+ 0 - 8
packages/app/src/components/prompt-input/server-attachment.ts

@@ -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 })
-}