From b46c3f2a26b06b2fe7459b082def635654756094 Mon Sep 17 00:00:00 2001
From: Adam <2363879+adamdotdevin@users.noreply.github.com>
Date: Fri, 7 Nov 2025 13:54:49 -0600
Subject: fix(desktop): prompt input issues (wip)

---
 packages/desktop/src/components/prompt-input.tsx | 36 +++++++++++-------------
 1 file changed, 16 insertions(+), 20 deletions(-)

(limited to 'packages/desktop/src/components/prompt-input.tsx')

diff --git a/packages/desktop/src/components/prompt-input.tsx b/packages/desktop/src/components/prompt-input.tsx
index 15bc54c49..5ae56f827 100644
--- a/packages/desktop/src/components/prompt-input.tsx
+++ b/packages/desktop/src/components/prompt-input.tsx
@@ -174,10 +174,8 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
 
   const addPart = (part: ContentPart) => {
     const cursorPosition = getCursorPosition(editorRef)
-    const rawText = session.prompt
-      .current()
-      .map((p) => p.content)
-      .join("")
+    const prompt = session.prompt.current()
+    const rawText = prompt.map((p) => p.content).join("")
     const textBeforeCursor = rawText.substring(0, cursorPosition)
     const atMatch = textBeforeCursor.match(/@(\S*)$/)
 
@@ -203,7 +201,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
       parts: nextParts,
       inserted,
       cursorPositionAfter,
-    } = session.prompt.current().reduce(
+    } = prompt.reduce(
       (acc, item) => {
         if (acc.inserted) {
           acc.parts.push({ ...item, start: acc.runningIndex, end: acc.runningIndex + item.content.length })
@@ -262,7 +260,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
     )
 
     if (!inserted) {
-      const baseParts = session.prompt.current().filter((item) => !(item.type === "text" && item.content === ""))
+      const baseParts = prompt.filter((item) => !(item.type === "text" && item.content === ""))
       const runningIndex = baseParts.reduce((sum, p) => sum + p.content.length, 0)
       const appendedAcc = { parts: [...baseParts] as ContentPart[], runningIndex }
       if (part.type === "text") {
@@ -316,10 +314,8 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
 
   const handleSubmit = async (event: Event) => {
     event.preventDefault()
-    const text = session.prompt
-      .current()
-      .map((part) => part.content)
-      .join("")
+    const prompt = session.prompt.current()
+    const text = prompt.map((part) => part.content).join("")
     if (text.trim().length === 0) {
       if (session.working()) abort()
       return
@@ -329,19 +325,17 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
     if (!existing) {
       const created = await sdk.client.session.create()
       existing = created.data ?? undefined
+      if (existing) navigate(`/session/${existing.id}`)
     }
     if (!existing) return
 
-    navigate(`/session/${existing.id}`)
-    if (!session.id) {
-      // session.layout.setOpenedTabs(
-      // session.layout.copyTabs("", session.id)
-    }
-    session.layout.setActiveTab(undefined)
-    session.messages.setActive(undefined)
-    const toAbsolutePath = (path: string) => (path.startsWith("/") ? path : sync.absolute(path))
+    // if (!session.id) {
+    // session.layout.setOpenedTabs(
+    // session.layout.copyTabs("", session.id)
+    // }
 
-    const attachments = session.prompt.current().filter((part) => part.type === "file")
+    const toAbsolutePath = (path: string) => (path.startsWith("/") ? path : sync.absolute(path))
+    const attachments = prompt.filter((part) => part.type === "file")
 
     // const activeFile = local.context.active()
     // if (activeFile) {
@@ -382,9 +376,11 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
       }
     })
 
+    session.layout.setActiveTab(undefined)
+    session.messages.setActive(undefined)
     session.prompt.set(DEFAULT_PROMPT, 0)
 
-    await sdk.client.session.prompt({
+    sdk.client.session.prompt({
       path: { id: existing.id },
       body: {
         agent: local.agent.current()!.name,
-- 
cgit v1.2.3

