chat: send cwd on every message instead of reading it back from session metadata
Simpler + more efficient than the previous per-turn GET /session: the client already has the selected cwd, so it now sends it on every message (it's constant for a session). The server uses msg.cwd directly for OpenCode's per-turn working-directory system prompt, and still tags the cwd at creation for listing. Drops the getSession round-trip. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -26,9 +26,21 @@ type UseEmbeddableChatParams = {
|
||||
};
|
||||
|
||||
export function useEmbeddableChat(params: UseEmbeddableChatParams, onMessageComplete?: () => void) {
|
||||
const { initialMessage, defaultInput = '', promptPrefix, cwd, sandboxed, autoSend = false, chat: externalChat } = params;
|
||||
const {
|
||||
initialMessage,
|
||||
defaultInput = '',
|
||||
promptPrefix,
|
||||
cwd,
|
||||
sandboxed,
|
||||
autoSend = false,
|
||||
chat: externalChat,
|
||||
} = params;
|
||||
|
||||
const internalChat = useChat(params.sessionId, params.initialModel, { replaceUrl: params.replaceUrl ?? false, context: params.context, contextId: params.contextId });
|
||||
const internalChat = useChat(params.sessionId, params.initialModel, {
|
||||
replaceUrl: params.replaceUrl ?? false,
|
||||
context: params.context,
|
||||
contextId: params.contextId,
|
||||
});
|
||||
const chat = externalChat ?? internalChat;
|
||||
|
||||
const {
|
||||
@@ -90,13 +102,14 @@ export function useEmbeddableChat(params: UseEmbeddableChatParams, onMessageComp
|
||||
let prompt = promptPrefix ? `${promptPrefix}\n\n${text}` : text;
|
||||
if (prefix) prompt = `${prefix}${prompt}`;
|
||||
|
||||
const cwdForFirst = !sessionId ? cwd : undefined;
|
||||
// Send the cwd on every message (not just the first): OpenCode rebuilds its working-directory
|
||||
// system prompt each turn, so it needs the cwd every time. It stays constant for a session.
|
||||
const displayText = promptPrefix ? text : undefined;
|
||||
sendPrompt(
|
||||
prompt,
|
||||
!sessionId && ids.length > 0 ? ids : undefined,
|
||||
images.length > 0 ? images : undefined,
|
||||
cwdForFirst,
|
||||
cwd,
|
||||
undefined,
|
||||
sandboxed,
|
||||
thinkingLevel,
|
||||
@@ -149,7 +162,10 @@ export function useEmbeddableChat(params: UseEmbeddableChatParams, onMessageComp
|
||||
rafId = requestAnimationFrame(resizeTextarea);
|
||||
});
|
||||
observer.observe(textarea);
|
||||
return () => { observer.disconnect(); cancelAnimationFrame(rafId); };
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
cancelAnimationFrame(rafId);
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Auto-scroll to bottom on new messages
|
||||
|
||||
Reference in New Issue
Block a user