Просмотр исходного кода

wip(desktop): handle more errors

Adam 1 месяц назад
Родитель
Сommit
c523ca4127

+ 4 - 0
packages/app/src/components/header.tsx

@@ -188,6 +188,10 @@ export function Header(props: {
                               shareURL = await globalSDK.client.session
                                 .share({ sessionID: session.id, directory: currentDirectory() })
                                 .then((r) => r.data?.share?.url)
+                                .catch((e) => {
+                                  console.error("Failed to share session", e)
+                                  return undefined
+                                })
                             }
                             return shareURL
                           },

+ 37 - 23
packages/app/src/components/prompt-input.tsx

@@ -643,9 +643,11 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
   }
 
   const abort = () =>
-    sdk.client.session.abort({
-      sessionID: params.id!,
-    })
+    sdk.client.session
+      .abort({
+        sessionID: params.id!,
+      })
+      .catch(() => {})
 
   const addToHistory = (prompt: Prompt, mode: "normal" | "shell") => {
     const text = prompt
@@ -883,12 +885,16 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
     const agent = local.agent.current()!.name
 
     if (isShellMode) {
-      sdk.client.session.shell({
-        sessionID: existing.id,
-        agent,
-        model,
-        command: text,
-      })
+      sdk.client.session
+        .shell({
+          sessionID: existing.id,
+          agent,
+          model,
+          command: text,
+        })
+        .catch((e) => {
+          console.error("Failed to send shell command", e)
+        })
       return
     }
 
@@ -897,13 +903,17 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
       const commandName = cmdName.slice(1)
       const customCommand = sync.data.command.find((c) => c.name === commandName)
       if (customCommand) {
-        sdk.client.session.command({
-          sessionID: existing.id,
-          command: commandName,
-          arguments: args.join(" "),
-          agent,
-          model: `${model.providerID}/${model.modelID}`,
-        })
+        sdk.client.session
+          .command({
+            sessionID: existing.id,
+            command: commandName,
+            arguments: args.join(" "),
+            agent,
+            model: `${model.providerID}/${model.modelID}`,
+          })
+          .catch((e) => {
+            console.error("Failed to send command", e)
+          })
         return
       }
     }
@@ -929,13 +939,17 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
       model,
     })
 
-    sdk.client.session.prompt({
-      sessionID: existing.id,
-      agent,
-      model,
-      messageID,
-      parts: requestParts,
-    })
+    sdk.client.session
+      .prompt({
+        sessionID: existing.id,
+        agent,
+        model,
+        messageID,
+        parts: requestParts,
+      })
+      .catch((e) => {
+        console.error("Failed to send prompt", e)
+      })
   }
 
   return (

+ 18 - 14
packages/app/src/components/terminal.tsx

@@ -82,13 +82,15 @@ export const Terminal = (props: TerminalProps) => {
     window.addEventListener("resize", handleResize)
     term.onResize(async (size) => {
       if (ws && ws.readyState === WebSocket.OPEN) {
-        await sdk.client.pty.update({
-          ptyID: local.pty.id,
-          size: {
-            cols: size.cols,
-            rows: size.rows,
-          },
-        })
+        await sdk.client.pty
+          .update({
+            ptyID: local.pty.id,
+            size: {
+              cols: size.cols,
+              rows: size.rows,
+            },
+          })
+          .catch(() => {})
       }
     })
     term.onData((data) => {
@@ -106,13 +108,15 @@ export const Terminal = (props: TerminalProps) => {
     // })
     ws.addEventListener("open", () => {
       console.log("WebSocket connected")
-      sdk.client.pty.update({
-        ptyID: local.pty.id,
-        size: {
-          cols: term.cols,
-          rows: term.rows,
-        },
-      })
+      sdk.client.pty
+        .update({
+          ptyID: local.pty.id,
+          size: {
+            cols: term.cols,
+            rows: term.rows,
+          },
+        })
+        .catch(() => {})
     })
     ws.addEventListener("message", (event) => {
       term.write(event.data)

+ 38 - 22
packages/app/src/context/terminal.tsx

@@ -36,35 +36,49 @@ export const { use: useTerminal, provider: TerminalProvider } = createSimpleCont
       all: createMemo(() => Object.values(store.all)),
       active: createMemo(() => store.active),
       new() {
-        sdk.client.pty.create({ title: `Terminal ${store.all.length + 1}` }).then((pty) => {
-          const id = pty.data?.id
-          if (!id) return
-          setStore("all", [
-            ...store.all,
-            {
-              id,
-              title: pty.data?.title ?? "Terminal",
-            },
-          ])
-          setStore("active", id)
-        })
+        sdk.client.pty
+          .create({ title: `Terminal ${store.all.length + 1}` })
+          .then((pty) => {
+            const id = pty.data?.id
+            if (!id) return
+            setStore("all", [
+              ...store.all,
+              {
+                id,
+                title: pty.data?.title ?? "Terminal",
+              },
+            ])
+            setStore("active", id)
+          })
+          .catch((e) => {
+            console.error("Failed to create terminal", e)
+          })
       },
       update(pty: Partial<LocalPTY> & { id: string }) {
         setStore("all", (x) => x.map((x) => (x.id === pty.id ? { ...x, ...pty } : x)))
-        sdk.client.pty.update({
-          ptyID: pty.id,
-          title: pty.title,
-          size: pty.cols && pty.rows ? { rows: pty.rows, cols: pty.cols } : undefined,
-        })
+        sdk.client.pty
+          .update({
+            ptyID: pty.id,
+            title: pty.title,
+            size: pty.cols && pty.rows ? { rows: pty.rows, cols: pty.cols } : undefined,
+          })
+          .catch((e) => {
+            console.error("Failed to update terminal", e)
+          })
       },
       async clone(id: string) {
         const index = store.all.findIndex((x) => x.id === id)
         const pty = store.all[index]
         if (!pty) return
-        const clone = await sdk.client.pty.create({
-          title: pty.title,
-        })
-        if (!clone.data) return
+        const clone = await sdk.client.pty
+          .create({
+            title: pty.title,
+          })
+          .catch((e) => {
+            console.error("Failed to clone terminal", e)
+            return undefined
+          })
+        if (!clone?.data) return
         setStore("all", index, {
           ...pty,
           ...clone.data,
@@ -88,7 +102,9 @@ export const { use: useTerminal, provider: TerminalProvider } = createSimpleCont
             setStore("active", previous?.id)
           }
         })
-        await sdk.client.pty.remove({ ptyID: id })
+        await sdk.client.pty.remove({ ptyID: id }).catch((e) => {
+          console.error("Failed to close terminal", e)
+        })
       },
       move(id: string, to: number) {
         const index = store.all.findIndex((f) => f.id === id)

+ 3 - 0
packages/desktop/vite.config.ts

@@ -10,6 +10,9 @@ export default defineConfig({
   //
   // 1. prevent Vite from obscuring rust errors
   clearScreen: false,
+  build: {
+    sourcemap: true,
+  },
   // 2. tauri expects a fixed port, fail if that port is not available
   server: {
     port: 1420,