Elffuss BraidHub

kikocis/continue public

fix: cn auto compact if necessary before LLM api call (#7865)

Changesetb3de9ab5c28c976bf51883f1e1b60810d8cb0d1951f8ed2d7a41ee194f05585f
AuthorTing-Wai <40179554+tingwai@users.noreply.github.com> · 2025-09-19 21:56 -07:00
CommitterGitHub <noreply@github.com> · 2025-09-19 21:56 -07:00
Parents00059b20c148

Browse the files at this changeset

1 file changed

modified extensions/cli/src/stream/streamChatResponse.ts +25 −0
@@ -358,6 +358,31 @@
358358 }
359359 logger.debug("Starting conversation iteration");
360360
361+ // Pre-API auto-compaction checkpoint
362+ const { wasCompacted: preCompacted, chatHistory: preCompactHistory } =
363+ await handleAutoCompaction(chatHistory, model, llmApi, {
364+ isHeadless,
365+ callbacks: {
366+ onSystemMessage: callbacks?.onSystemMessage,
367+ onContent: callbacks?.onContent,
368+ },
369+ });
370+
371+ if (preCompacted) {
372+ logger.debug("Pre-API compaction occurred, updating chat history");
373+ // Update chat history after pre-compaction
374+ const chatHistorySvc2 = services.chatHistory;
375+ if (
376+ typeof chatHistorySvc2?.isReady === "function" &&
377+ chatHistorySvc2.isReady()
378+ ) {
379+ chatHistorySvc2.setHistory(preCompactHistory);
380+ chatHistory = chatHistorySvc2.getHistory();
381+ } else {
382+ chatHistory = [...preCompactHistory];
383+ }
384+ }
385+
361386 // Recompute tools on each iteration to handle mode changes during streaming
362387 const tools = await getAllTools();
363388