fix(web): send workspace-relative notebook paths from the chat panel (#8)

The app passes notebook paths relative to notebooks/, but the chat
protocol uses workspace paths (notebooks/...). Every message sent while a
notebook was open was rejected as invalid, and "Open notebook" links on
Claude's edits loaded a non-existent path. ChatPanel now converts at its
boundary in both directions.
This commit is contained in:
Florian Schmidt
2026-11-16 10:23:05 +01:00
parent 63458dd3e4
commit 488f992bd3
2 changed files with 6 additions and 5 deletions
+3 -2
View File
@@ -11,6 +11,7 @@ export interface ChatSocket {
const connectChat = (): ChatSocket => new WebSocket(`${location.protocol === "https:" ? "wss:" : "ws:"}//${location.host}/api/chat`);
type Message = { role: "user" | "assistant" | "tool"; text: string; path?: string };
/** notebookPath and openNotebook use app paths (relative to notebooks/); the chat wire uses workspace paths. */
export function ChatPanel({ notebookPath, openNotebook, openTerminal, connect = connectChat }: {
notebookPath?: string; openNotebook(path: string): void; openTerminal(): void; connect?: () => ChatSocket;
}) {
@@ -77,7 +78,7 @@ export function ChatPanel({ notebookPath, openNotebook, openTerminal, connect =
<div className="chat-messages" role="log" aria-label="Chat messages" aria-live="polite">
{!messages.length && <p>{selected ? "Continue this conversation. Earlier messages are retained by the Claude CLI; this view shows messages from this browser session." : "Ask Claude to create or edit a notebook. Do not send secrets."}</p>}
{messages.map((m, i) => <div key={i} className={`chat-message ${m.role}`}>
{m.role === "tool" ? <small>{m.text} {m.path && <button onClick={() => openNotebook(m.path!)}>Open notebook</button>}</small> : <><strong>{m.role === "user" ? "You" : "Claude"}</strong><ReactMarkdown>{m.text}</ReactMarkdown></>}
{m.role === "tool" ? <small>{m.text} {m.path && <button onClick={() => openNotebook(m.path!.replace(/^notebooks\//, ""))}>Open notebook</button>}</small> : <><strong>{m.role === "user" ? "You" : "Claude"}</strong><ReactMarkdown>{m.text}</ReactMarkdown></>}
</div>)}<div ref={end} />
</div>
{error && <p role="alert">{error}</p>}
@@ -86,7 +87,7 @@ export function ChatPanel({ notebookPath, openNotebook, openTerminal, connect =
{!messages.length && <div className="actions">{["Create a notebook that…", "Add a check that…"].map(prompt => <button key={prompt} onClick={() => setText(prompt)}>{prompt}</button>)}</div>}
<form onSubmit={e => { e.preventDefault(); if (!ready || busy || !text.trim()) return;
setMessages(previous => [...previous, { role: "user", text }]); setBusy(true); setError(""); setLogin(false); setSummary("");
send({ type: "send", conversationId: selectedRef.current || undefined, message: text, notebookPath, allowShell }); setText("");
send({ type: "send", conversationId: selectedRef.current || undefined, message: text, notebookPath: notebookPath && `notebooks/${notebookPath}`, allowShell }); setText("");
}}>
<label>Message<textarea value={text} onChange={e => setText(e.target.value)} maxLength={32000} required rows={3} /></label>
<label className="chat-shell"><input type="checkbox" checked={allowShell} disabled={busy} onChange={e => setAllowShell(e.target.checked)} />Allow Claude to run shell commands on the ShellBook server</label>