ctx-mgmt: ctx session management (dev mode only) (#2415)

This commit is contained in:
Lily Delalande
2025-05-02 16:12:56 -04:00
committed by GitHub
parent 2366a3ad01
commit 8ba40bdccc
19 changed files with 710 additions and 118 deletions
+12
View File
@@ -121,6 +121,9 @@ export interface UseMessageStreamHelpers {
/** Add a tool result to a tool call */
addToolResult: ({ toolCallId, result }: { toolCallId: string; result: unknown }) => void;
/** Modify body (session id and/or work dir mid-stream) **/
updateMessageStreamBody?: (newBody: object) => void;
}
/**
@@ -148,6 +151,14 @@ export function useMessageStream({
fallbackData: initialMessages,
});
// expose a way to update the body so we can update the session id when CLE occurs
const updateMessageStreamBody = useCallback((newBody: object) => {
extraMetadataRef.current.body = {
...extraMetadataRef.current.body,
...newBody,
};
}, []);
// Keep the latest messages in a ref
const messagesRef = useRef<Message[]>(messages || []);
useEffect(() => {
@@ -505,5 +516,6 @@ export function useMessageStream({
handleSubmit,
isLoading: isLoading || false,
addToolResult,
updateMessageStreamBody,
};
}