Elffuss BraidHub

kikocis/continue public

Merge pull request #6668 from continuedev/dallin/pruning-updates

Context limit and pruning updates
Changeset7668a87157661044772c6ddef858ebd250e87e0d28d65c309bb6b2fd4883a2bc
AuthorTomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-07-18 10:37 -07:00
CommitterGitHub <noreply@github.com> · 2025-07-18 10:37 -07:00
Parents74850c9d62af, 86b69ad8aae4

Browse the files at this changeset

18 files changed

modified core/index.d.ts +2 −13
@@ -1712,23 +1712,12 @@
17121712 apiKey?: string;
17131713 }
17141714
1715-export type PruningStatus = "deleted-last-input" | "pruned" | "not-pruned";
1716-
17171715 export interface CompiledMessagesResult {
17181716 compiledChatMessages: ChatMessage[];
1719- pruningStatus: PruningStatus;
1717+ didPrune: boolean;
1718+ contextPercentage: number;
17201719 }
17211720
17221721 export interface MessageOption {
17231722 precompiled: boolean;
17241723 }
1725-
1726-export type WarningMessageLevel = "warning" | "fatal";
1727-
1728-export type WarningCategory = "exceeded-context-length" | "deleted-last-input";
1729-
1730-export interface WarningMessage {
1731- message: string;
1732- level: WarningMessageLevel;
1733- category: WarningCategory;
1734-}
modified core/llm/countTokens.ts +31 −36
@@ -5,7 +5,6 @@
55 CompiledMessagesResult,
66 MessageContent,
77 MessagePart,
8- PruningStatus,
98 Tool,
109 } from "../index.js";
1110 import { autodetectTemplateType } from "./autodetect.js";
@@ -363,9 +362,6 @@
363362 }
364363
365364 const MIN_RESPONSE_TOKENS = 1000;
366-function getMinResponseTokens(maxTokens: number) {
367- return Math.min(MIN_RESPONSE_TOKENS, maxTokens);
368-}
369365
370366 function pruneRawPromptFromTop(
371367 modelName: string,
@@ -425,6 +421,8 @@
425421 supportsImages: boolean;
426422 tools?: Tool[];
427423 }): CompiledMessagesResult {
424+ let didPrune = false;
425+
428426 let msgsCopy: ChatMessage[] = msgs.map((m) => ({ ...m }));
429427
430428 // If images not supported, convert MessagePart[] to string
@@ -446,21 +444,14 @@
446444
447445 msgsCopy = addSpaceToAnyEmptyMessages(msgsCopy);
448446
449- while (msgsCopy.length > 1) {
450- if (isUserOrToolMsg(msgsCopy.at(-1))) {
451- break;
452- }
453- msgsCopy.pop();
454- }
455-
456- // // Extract the tool sequence from the end of the message array
457- // const toolSequence = extractToolSequence(msgsCopy);
447+ // Extract the tool sequence from the end of the message array
448+ const toolSequence = extractToolSequence(msgsCopy);
458449
459- // // Count tokens for all messages in the tool sequence
460- // let lastMessagesTokens = 0;
461- // for (const msg of toolSequence) {
462- // lastMessagesTokens += countChatMessageTokens(modelName, msg);
463- // }
450+ // Count tokens for all messages in the tool sequence
451+ let lastMessagesTokens = 0;
452+ for (const msg of toolSequence) {
453+ lastMessagesTokens += countChatMessageTokens(modelName, msg);
454+ }
464455
465456 // System message
466457 let systemMsgTokens = 0;
@@ -475,7 +466,7 @@
475466 }
476467
477468 const countingSafetyBuffer = getTokenCountingBufferSafety(contextLength);
478- const minOutputTokens = getMinResponseTokens(maxTokens);
469+ const minOutputTokens = Math.min(MIN_RESPONSE_TOKENS, maxTokens);
479470
480471 let inputTokensAvailable = contextLength;
481472
@@ -486,19 +477,19 @@
486477 // Non-negotiable messages
487478 inputTokensAvailable -= toolTokens;
488479 inputTokensAvailable -= systemMsgTokens;
489- // inputTokensAvailable -= lastMessagesTokens;
480+ inputTokensAvailable -= lastMessagesTokens;
490481
491482 // Make sure there's enough context for the non-excludable items
492483 if (inputTokensAvailable < 0) {
493484 throw new Error(
494485 `Not enough context available to include the system message, last user message, and tools.
495- There must be at least ${minOutputTokens} tokens remaining for output.
496- Request had the following token counts:
497- - contextLength: ${contextLength}
498- - counting safety buffer: ${countingSafetyBuffer}
499- - tools: ~${toolTokens}
500- - system message: ~${systemMsgTokens}
501- - max output tokens: ${maxTokens}`,
486+ There must be at least ${minOutputTokens} tokens remaining for output.
487+ Request had the following token counts:
488+ - contextLength: ${contextLength}
489+ - counting safety buffer: ${countingSafetyBuffer}
490+ - tools: ~${toolTokens}
491+ - system message: ~${systemMsgTokens}
492+ - max output tokens: ${maxTokens}`,
502493 );
503494 }
504495
@@ -513,12 +504,10 @@
513504 };
514505 });
515506
516- let pruningStatus: PruningStatus = "not-pruned";
517-
518507 while (historyWithTokens.length > 0 && currentTotal > inputTokensAvailable) {
519508 const message = historyWithTokens.shift()!;
520509 currentTotal -= message.tokens;
521- pruningStatus = "pruned";
510+ didPrune = true;
522511
523512 // At this point make sure no latent tool response without corresponding call
524513 while (historyWithTokens[0]?.role === "tool") {
@@ -527,18 +516,24 @@
527516 }
528517 }
529518
530- if (historyWithTokens.length === 0) {
531- pruningStatus = "deleted-last-input";
532- }
533-
534519 // Now reassemble
535520 const reassembled: ChatMessage[] = [];
536521 if (systemMsg) {
537522 reassembled.push(systemMsg);
538523 }
539524 reassembled.push(...historyWithTokens.map(({ tokens, ...rest }) => rest));
540-
541- return { compiledChatMessages: reassembled, pruningStatus };
525+ reassembled.push(...toolSequence);
526+
527+ const inputTokens =
528+ currentTotal + systemMsgTokens + toolTokens + lastMessagesTokens;
529+ const availableTokens =
530+ contextLength - countingSafetyBuffer - minOutputTokens;
531+ const contextPercentage = inputTokens / availableTokens;
532+ return {
533+ compiledChatMessages: reassembled,
534+ didPrune,
535+ contextPercentage,
536+ };
542537 }
543538
544539 export {
modified core/llm/index.ts +1 −1
@@ -940,7 +940,7 @@
940940 let messages = _messages;
941941
942942 // If not precompiled, compile the chat messages
943- if (!messageOptions || messageOptions.precompiled === false) {
943+ if (!messageOptions?.precompiled) {
944944 const { compiledChatMessages } = compileChatMessages({
945945 modelName: completionOptions.model,
946946 msgs: _messages,
modified gui/src/components/StepContainer/StepContainer.tsx +0 −3
@@ -25,9 +25,6 @@
2525 const historyItemAfterThis = useAppSelector(
2626 (state) => state.session.history[props.index + 1],
2727 );
28- const warningMessage = useAppSelector(
29- (state) => state.session.warningMessage,
30- );
3128 const uiConfig = useAppSelector(selectUIConfig);
3229
3330 // Calculate dimming and indicator state based on latest summary index
added gui/src/components/mainInput/ContextStatus.tsx +77 −0
@@ -0,0 +1,77 @@
1+import { useAppDispatch, useAppSelector } from "../../redux/hooks";
2+import { saveCurrentSession } from "../../redux/thunks/session";
3+import { ToolTip } from "../gui/Tooltip";
4+
5+const ContextStatus = () => {
6+ const dispatch = useAppDispatch();
7+ const contextPercentage = useAppSelector(
8+ (state) => state.session.contextPercentage,
9+ );
10+ const history = useAppSelector((state) => state.session.history);
11+ const percent = Math.round((contextPercentage ?? 0) * 100);
12+ const isPruned = useAppSelector((state) => state.session.isPruned);
13+ if (!isPruned && percent < 60) {
14+ return null;
15+ }
16+
17+ const barColorClass = isPruned
18+ ? "bg-error"
19+ : percent > 80
20+ ? "bg-warning"
21+ : "bg-description";
22+
23+ return (
24+ <div>
25+ <ToolTip
26+ id="context-status"
27+ closeEvents={{
28+ // blur: false,
29+ mouseleave: true,
30+ click: true,
31+ mouseup: false,
32+ }}
33+ clickable
34+ >
35+ <div className="flex flex-col gap-0">
36+ <span className="inline-block">
37+ {`${percent}% of context filled`}
38+ </span>
39+ {isPruned && (
40+ <span className="inline-block">
41+ {`Oldest messages are being removed`}
42+ </span>
43+ )}
44+ {history.length > 0 && (
45+ <div>
46+ <span className="inline-block">Start a</span>{" "}
47+ <span
48+ className="inline-block cursor-pointer underline"
49+ onClick={() => {
50+ void dispatch(
51+ saveCurrentSession({
52+ openNewSession: true,
53+ generateTitle: false,
54+ }),
55+ );
56+ }}
57+ >
58+ New Session
59+ </span>
60+ </div>
61+ )}
62+ </div>
63+ </ToolTip>
64+ <div
65+ data-tooltip-id="context-status"
66+ className="border-description-muted relative h-[14px] w-[7px] rounded-[1px] border-[0.5px] border-solid md:h-[10px] md:w-[5px]"
67+ >
68+ <div
69+ className={`transition-height absolute bottom-0 left-0 w-full duration-300 ease-in-out ${barColorClass}`}
70+ style={{ height: `${percent}%` }}
71+ ></div>
72+ </div>
73+ </div>
74+ );
75+};
76+
77+export default ContextStatus;
modified gui/src/components/mainInput/ContinueInputBox.tsx +0 −19
@@ -10,9 +10,6 @@
1010 import { ToolbarOptions } from "./InputToolbar";
1111 import { Lump } from "./Lump";
1212 import { TipTapEditor } from "./TipTapEditor";
13-import WarningMessageBox from "./WarningMessageBox";
14-import EditConfigAction from "./WarningMessageBox/Actions/EditConfigAction";
15-import NewSessionAction from "./WarningMessageBox/Actions/NewSessionAction";
1613
1714 interface ContinueInputBoxProps {
1815 isLastUserInput: boolean;
@@ -43,9 +40,6 @@
4340
4441 function ContinueInputBox(props: ContinueInputBoxProps) {
4542 const isStreaming = useAppSelector((state) => state.session.isStreaming);
46- const warningMessage = useAppSelector(
47- (state) => state.session.warningMessage,
48- );
4943 const availableSlashCommands = useAppSelector(
5044 selectSlashCommandComboBoxInputs,
5145 );
@@ -125,19 +119,6 @@
125119 />
126120 </div>
127121 )}
128- {props.isLastUserInput &&
129- warningMessage &&
130- (warningMessage.category === "exceeded-context-length" ? (
131- <WarningMessageBox
132- warningMessage={warningMessage}
133- actions={[NewSessionAction]}
134- />
135- ) : (
136- <WarningMessageBox
137- warningMessage={warningMessage}
138- actions={[EditConfigAction]}
139- />
140- ))}
141122 </div>
142123 );
143124 }
added gui/src/components/mainInput/InlineErrorMessage.tsx +48 −0
@@ -0,0 +1,48 @@
1+import { useContext } from "react";
2+import { IdeMessengerContext } from "../../context/IdeMessenger";
3+import { useAppDispatch, useAppSelector } from "../../redux/hooks";
4+import { setInlineErrorMessage } from "../../redux/slices/sessionSlice";
5+
6+export type InlineErrorMessageType = "out-of-context";
7+
8+export default function InlineErrorMessage() {
9+ const dispatch = useAppDispatch();
10+ const ideMessenger = useContext(IdeMessengerContext);
11+ const inlineErrorMessage = useAppSelector(
12+ (state) => state.session.inlineErrorMessage,
13+ );
14+ if (inlineErrorMessage === "out-of-context") {
15+ return (
16+ <div
17+ className={`border-border relative m-2 flex flex-col rounded-md border border-solid bg-transparent p-4`}
18+ >
19+ <p className={`thread-message text-error text-center`}>
20+ {`Message exceeds context limit.`}
21+ </p>
22+ <div className="text-description flex flex-row items-center justify-center gap-1.5 px-3">
23+ <div
24+ className="cursor-pointer text-xs hover:underline"
25+ onClick={() => {
26+ ideMessenger.post("config/openProfile", {
27+ profileId: undefined,
28+ });
29+ }}
30+ >
31+ <span className="xs:flex hidden">Open config</span>
32+ <span className="xs:hidden">Config</span>
33+ </div>
34+ |
35+ <span
36+ className="cursor-pointer text-xs hover:underline"
37+ onClick={() => {
38+ dispatch(setInlineErrorMessage(undefined));
39+ }}
40+ >
41+ Hide
42+ </span>
43+ </div>
44+ </div>
45+ );
46+ }
47+ return null;
48+}
modified gui/src/components/mainInput/InputToolbar.tsx +2 −1
@@ -19,6 +19,7 @@
1919 import { ModeSelect } from "../ModeSelect";
2020 import { Button } from "../ui";
2121 import { useFontSize } from "../ui/font";
22+import ContextStatus from "./ContextStatus";
2223 import HoverItem from "./InputToolbar/HoverItem";
2324
2425 export interface ToolbarOptions {
@@ -170,6 +171,7 @@
170171 fontSize: tinyFont,
171172 }}
172173 >
174+ {!isInEdit && <ContextStatus />}
173175 {!props.toolbarOptions?.hideUseCodebase && !isInEdit && (
174176 <div
175177 className={`${toolsSupported ? "md:flex" : "int:flex"} hover:underline" hidden transition-colors duration-200`}
@@ -209,7 +211,6 @@
209211 </span>
210212 </HoverItem>
211213 )}
212-
213214 <Button
214215 data-tooltip-id="enter-tooltip"
215216 variant={props.isMainInput ? "primary" : "secondary"}
deleted gui/src/components/mainInput/WarningMessageBox/Actions/EditConfigAction.tsx +0 −15
@@ -1,15 +0,0 @@
1-import { useContext } from "react";
2-import { IdeMessengerContext } from "../../../../context/IdeMessenger";
3-export default function EditConfigAction() {
4- const ideMessenger = useContext(IdeMessengerContext);
5- return (
6- <span
7- onClick={() =>
8- ideMessenger.post("config/openProfile", { profileId: undefined })
9- }
10- className="hover:underline"
11- >
12- Open configuration file
13- </span>
14- );
15-}
deleted gui/src/components/mainInput/WarningMessageBox/Actions/NewSessionAction.tsx +0 −10
@@ -1,10 +0,0 @@
1-import { useAppDispatch } from "../../../../redux/hooks";
2-import { newSession } from "../../../../redux/slices/sessionSlice";
3-export default function NewSessionAction() {
4- const dispatch = useAppDispatch();
5- return (
6- <span onClick={() => dispatch(newSession())} className="hover:underline">
7- Start a new session
8- </span>
9- );
10-}
deleted gui/src/components/mainInput/WarningMessageBox/ExpendableBox.tsx +0 −41
@@ -1,41 +0,0 @@
1-import { ReactNode, useEffect, useRef, useState } from "react";
2-export default function ExpendableBox({ children }: { children: ReactNode }) {
3- const [isExpended, setIsExpended] = useState(false);
4- const [showTrigger, setShowTrigger] = useState(true);
5- const expendableDivRef = useRef<HTMLDivElement>(null);
6- const toggleExpendable = () => {
7- setIsExpended((pre) => !pre);
8- };
9-
10- useEffect(() => {
11- if (expendableDivRef.current) {
12- expendableDivRef.current.style.maxHeight = isExpended ? "600px" : "0px";
13- }
14-
15- if (isExpended) {
16- setShowTrigger(false);
17- } else {
18- setTimeout(() => setShowTrigger(true), 200);
19- }
20- }, [isExpended]);
21-
22- return (
23- <div className="flex flex-col">
24- <div
25- onClick={toggleExpendable}
26- className={`h-[9px] w-[9px] self-end ${showTrigger ? "" : "hidden"} bg-warning my-2 mr-4 rounded-lg`}
27- ></div>
28-
29- <div
30- onClick={toggleExpendable}
31- ref={expendableDivRef}
32- style={{
33- transition: "max-height 0.3s ease-in-out",
34- overflowY: "hidden",
35- }}
36- >
37- {children}
38- </div>
39- </div>
40- );
41-}
deleted gui/src/components/mainInput/WarningMessageBox/index.tsx +0 −55
@@ -1,55 +0,0 @@
1-import { WarningMessage } from "core";
2-import { ReactElement } from "react";
3-import ExpendableBox from "./ExpendableBox";
4-
5-function MessageBox({
6- warningMessage,
7- actions,
8-}: {
9- warningMessage: WarningMessage;
10- actions?: (() => ReactElement)[];
11-}) {
12- const warningMessageTextColor =
13- warningMessage.level === "fatal" ? "text-error" : "text-warning";
14- const warningMessageBorderColor =
15- warningMessage.level === "fatal" ? "border-error" : "border-warning";
16- return (
17- <div
18- className={`relative m-2 flex flex-col rounded-md border border-solid ${warningMessageBorderColor} bg-transparent p-4`}
19- >
20- <p className={`thread-message ${warningMessageTextColor}`}>
21- <b>Warning: </b>
22- {`${warningMessage.message}`}
23- </p>
24- {actions && (
25- <div>
26- <p>{`Recommended Action${actions.length > 1 ? "s" : ""}:`}</p>
27- <ul>
28- {actions.map((action, ind) => {
29- return <li key={`warning-action-${ind}`}>{action()}</li>;
30- })}
31- </ul>
32- </div>
33- )}
34- </div>
35- );
36-}
37-
38-export default function WarningMessageBox({
39- warningMessage,
40- actions,
41-}: {
42- warningMessage: WarningMessage;
43- actions?: (() => ReactElement)[];
44-}) {
45- if (warningMessage.category === "exceeded-context-length") {
46- return (
47- <ExpendableBox
48- children={
49- <MessageBox warningMessage={warningMessage} actions={actions} />
50- }
51- />
52- );
53- }
54- return <MessageBox warningMessage={warningMessage} actions={actions} />;
55-}
modified gui/src/components/modelSelection/ModelSelect.tsx +1 −1
@@ -218,7 +218,7 @@
218218 {modelSelectTitle(selectedModel) || "Select model"}
219219 </span>
220220 <ChevronDownIcon
221- className="h-2 w-2 flex-shrink-0 hover:brightness-110"
221+ className="hidden h-2 w-2 flex-shrink-0 hover:brightness-110 min-[200px]:flex"
222222 aria-hidden="true"
223223 />
224224 </ListboxButton>
modified gui/src/context/MockIdeMessenger.ts +2 −1
@@ -86,7 +86,8 @@
8686 },
8787 "llm/compileChat": {
8888 compiledChatMessages: [],
89- pruningStatus: "not-pruned",
89+ didPrune: false,
90+ contextPercentage: 0.5,
9091 },
9192 };
9293
modified gui/src/pages/gui/Chat.tsx +15 −18
@@ -43,6 +43,7 @@
4343 import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util";
4444 import { ToolCallDiv } from "./ToolCallDiv";
4545
46+import InlineErrorMessage from "../../components/mainInput/InlineErrorMessage";
4647 import { cancelStream } from "../../redux/thunks/cancelStream";
4748 import { EmptyChatBody } from "./EmptyChatBody";
4849 import { ExploreDialogWatcher } from "./ExploreDialogWatcher";
@@ -123,9 +124,6 @@
123124 const jetbrains = useMemo(() => {
124125 return isJetBrains();
125126 }, []);
126- const warningMessage = useAppSelector(
127- (state) => state.session.warningMessage,
128- );
129127
130128 useAutoScroll(stepsDivRef, history);
131129
@@ -411,6 +409,7 @@
411409 >
412410 {renderChatHistoryItem(item, index)}
413411 </ErrorBoundary>
412+ {index === history.length - 1 && <InlineErrorMessage />}
414413 </div>
415414 ))}
416415 </StepsDiv>
@@ -432,21 +431,19 @@
432431 <div className="flex flex-row items-center justify-between pb-1 pl-0.5 pr-2">
433432 <div className="xs:inline hidden">
434433 {history.length === 0 && lastSessionId && !isInEdit && (
435- <div className="xs:inline hidden">
436- <NewSessionButton
437- onClick={async () => {
438- await dispatch(
439- loadLastSession({
440- saveCurrentSession: true,
441- }),
442- );
443- }}
444- className="flex items-center gap-2"
445- >
446- <ArrowLeftIcon className="h-3 w-3" />
447- <span className="text-xs">Last Session</span>
448- </NewSessionButton>
449- </div>
434+ <NewSessionButton
435+ onClick={async () => {
436+ await dispatch(
437+ loadLastSession({
438+ saveCurrentSession: true,
439+ }),
440+ );
441+ }}
442+ className="flex items-center gap-2"
443+ >
444+ <ArrowLeftIcon className="h-3 w-3" />
445+ <span className="text-xs">Last Session</span>
446+ </NewSessionButton>
450447 )}
451448 </div>
452449 </div>
modified gui/src/redux/slices/sessionSlice.ts +26 −7
@@ -23,7 +23,6 @@
2323 Tool,
2424 ToolCallDelta,
2525 ToolCallState,
26- WarningMessage,
2726 } from "core";
2827 import { BuiltInToolNames } from "core/tools/builtIn";
2928 import { NEW_SESSION_TITLE } from "core/util/constants";
@@ -34,6 +33,7 @@
3433 import { findUriInDirs, getUriPathBasename } from "core/util/uri";
3534 import { findLastIndex } from "lodash";
3635 import { v4 as uuidv4 } from "uuid";
36+import { type InlineErrorMessageType } from "../../components/mainInput/InlineErrorMessage";
3737 import { toolCallCtxItemToCtxItemWithId } from "../../pages/gui/ToolCallDiv/utils";
3838 import { addToolCallDeltaToState } from "../../util/toolCallState";
3939 import { RootState } from "../store";
@@ -224,8 +224,10 @@
224224 };
225225 newestToolbarPreviewForInput: Record<string, string>;
226226 hasReasoningEnabled?: boolean;
227+ isPruned?: boolean;
228+ contextPercentage?: number;
229+ inlineErrorMessage?: InlineErrorMessageType;
227230 compactionLoading: Record<number, boolean>; // Track compaction loading by message index
228- warningMessage?: WarningMessage;
229231 };
230232
231233 const initialState: SessionState = {
@@ -431,12 +433,17 @@
431433 },
432434 contextItems: [],
433435 });
436+ state.inlineErrorMessage = undefined;
437+ state.isPruned = false;
438+ state.contextPercentage = undefined;
434439 }
435440 },
436441 deleteMessage: (state, action: PayloadAction<number>) => {
437442 // Deletes the current assistant message and the previous user message
438443 state.history.splice(action.payload - 1, 2);
439- state.warningMessage = undefined;
444+ state.inlineErrorMessage = undefined;
445+ state.isPruned = false;
446+ state.contextPercentage = undefined;
440447 },
441448 updateHistoryItemAtIndex: (
442449 state,
@@ -647,6 +654,10 @@
647654 state.isStreaming = false;
648655 state.symbols = {};
649656
657+ state.inlineErrorMessage = undefined;
658+ state.isPruned = false;
659+ state.contextPercentage = undefined;
660+
650661 if (payload) {
651662 state.history = payload.history as any;
652663 state.title = payload.title;
@@ -913,11 +924,17 @@
913924 delete state.compactionLoading[index];
914925 }
915926 },
916- setWarningMessage: (
927+ setInlineErrorMessage: (
917928 state,
918- action: PayloadAction<WarningMessage | undefined>,
929+ action: PayloadAction<SessionState["inlineErrorMessage"]>,
919930 ) => {
920- state.warningMessage = action.payload;
931+ state.inlineErrorMessage = action.payload;
932+ },
933+ setIsPruned: (state, action: PayloadAction<boolean>) => {
934+ state.isPruned = action.payload;
935+ },
936+ setContextPercentage: (state, action: PayloadAction<number>) => {
937+ state.contextPercentage = action.payload;
921938 },
922939 },
923940 selectors: {
@@ -1002,8 +1019,10 @@
10021019 setNewestToolbarPreviewForInput,
10031020 setIsInEdit,
10041021 setHasReasoningEnabled,
1022+ setInlineErrorMessage,
1023+ setIsPruned,
1024+ setContextPercentage,
10051025 setCompactionLoading,
1006- setWarningMessage,
10071026 } = sessionSlice.actions;
10081027
10091028 export const { selectIsGatheringContext } = sessionSlice.selectors;
modified gui/src/redux/thunks/streamNormalInput.ts +16 −27
@@ -11,9 +11,11 @@
1111 addPromptCompletionPair,
1212 setActive,
1313 setAppliedRulesAtIndex,
14+ setContextPercentage,
1415 setInactive,
16+ setInlineErrorMessage,
17+ setIsPruned,
1518 setToolGenerated,
16- setWarningMessage,
1719 streamUpdate,
1820 } from "../slices/sessionSlice";
1921 import { AppThunkDispatch, RootState, ThunkApiType } from "../store";
@@ -184,42 +186,29 @@
184186 );
185187
186188 dispatch(setActive());
187- // Remove the warning message before each compileChat call
188- dispatch(setWarningMessage(undefined));
189+ dispatch(setInlineErrorMessage(undefined));
190+
189191 const precompiledRes = await extra.ideMessenger.request("llm/compileChat", {
190192 messages,
191193 options: completionOptions,
192194 });
193195
194196 if (precompiledRes.status === "error") {
195- throw new Error(precompiledRes.error);
196- }
197-
198- const { compiledChatMessages, pruningStatus } = precompiledRes.content;
199-
200- switch (pruningStatus) {
201- case "pruned":
202- dispatch(
203- setWarningMessage({
204- message: `Chat history exceeds model's context length (${state.config.config.selectedModelByRole.chat?.contextLength} tokens). Old messages will not be included.`,
205- level: "warning",
206- category: "exceeded-context-length",
207- }),
208- );
209- break;
210- case "deleted-last-input":
211- dispatch(
212- setWarningMessage({
213- message:
214- "The provided context items are too large. Please trim the context item to fit the model's context length or increase the model's context length by editing the configuration.",
215- level: "fatal",
216- category: "deleted-last-input",
217- }),
218- );
197+ if (precompiledRes.error.includes("Not enough context")) {
198+ dispatch(setInlineErrorMessage("out-of-context"));
219199 dispatch(setInactive());
220200 return;
201+ } else {
202+ throw new Error(precompiledRes.error);
203+ }
221204 }
222205
206+ const { compiledChatMessages, didPrune, contextPercentage } =
207+ precompiledRes.content;
208+
209+ dispatch(setIsPruned(didPrune));
210+ dispatch(setContextPercentage(contextPercentage));
211+
223212 // Send request and stream response
224213 const streamAborter = state.session.streamAborter;
225214 const gen = extra.ideMessenger.llmStreamChat(
modified packages/shared-release.config.js +1 −1
@@ -25,4 +25,4 @@
2525 "@semantic-release/github",
2626 ],
2727 };
28-}
No newline at the end of the file
28+}