Changesets · Branches · Tags · Compare
| Changeset | 7668a87157661044772c6ddef858ebd250e87e0d28d65c309bb6b2fd4883a2bc |
|---|---|
| Author | Tomasz Stefaniak <tomasz.p.stefaniak@gmail.com> · 2025-07-18 10:37 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-18 10:37 -07:00 |
| Parents | 74850c9d62af, 86b69ad8aae4 |
18 files changed
modified core/index.d.ts +2 −13
| @@ -1712,23 +1712,12 @@ | ||
| 1712 | 1712 | apiKey?: string; |
| 1713 | 1713 | } |
| 1714 | 1714 | |
| 1715 | -export type PruningStatus = "deleted-last-input" | "pruned" | "not-pruned"; | |
| 1716 | - | |
| 1717 | 1715 | export interface CompiledMessagesResult { |
| 1718 | 1716 | compiledChatMessages: ChatMessage[]; |
| 1719 | - pruningStatus: PruningStatus; | |
| 1717 | + didPrune: boolean; | |
| 1718 | + contextPercentage: number; | |
| 1720 | 1719 | } |
| 1721 | 1720 | |
| 1722 | 1721 | export interface MessageOption { |
| 1723 | 1722 | precompiled: boolean; |
| 1724 | 1723 | } |
| 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 @@ | ||
| 5 | 5 | CompiledMessagesResult, |
| 6 | 6 | MessageContent, |
| 7 | 7 | MessagePart, |
| 8 | - PruningStatus, | |
| 9 | 8 | Tool, |
| 10 | 9 | } from "../index.js"; |
| 11 | 10 | import { autodetectTemplateType } from "./autodetect.js"; |
| @@ -363,9 +362,6 @@ | ||
| 363 | 362 | } |
| 364 | 363 | |
| 365 | 364 | const MIN_RESPONSE_TOKENS = 1000; |
| 366 | -function getMinResponseTokens(maxTokens: number) { | |
| 367 | - return Math.min(MIN_RESPONSE_TOKENS, maxTokens); | |
| 368 | -} | |
| 369 | 365 | |
| 370 | 366 | function pruneRawPromptFromTop( |
| 371 | 367 | modelName: string, |
| @@ -425,6 +421,8 @@ | ||
| 425 | 421 | supportsImages: boolean; |
| 426 | 422 | tools?: Tool[]; |
| 427 | 423 | }): CompiledMessagesResult { |
| 424 | + let didPrune = false; | |
| 425 | + | |
| 428 | 426 | let msgsCopy: ChatMessage[] = msgs.map((m) => ({ ...m })); |
| 429 | 427 | |
| 430 | 428 | // If images not supported, convert MessagePart[] to string |
| @@ -446,21 +444,14 @@ | ||
| 446 | 444 | |
| 447 | 445 | msgsCopy = addSpaceToAnyEmptyMessages(msgsCopy); |
| 448 | 446 | |
| 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); | |
| 458 | 449 | |
| 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 | + } | |
| 464 | 455 | |
| 465 | 456 | // System message |
| 466 | 457 | let systemMsgTokens = 0; |
| @@ -475,7 +466,7 @@ | ||
| 475 | 466 | } |
| 476 | 467 | |
| 477 | 468 | const countingSafetyBuffer = getTokenCountingBufferSafety(contextLength); |
| 478 | - const minOutputTokens = getMinResponseTokens(maxTokens); | |
| 469 | + const minOutputTokens = Math.min(MIN_RESPONSE_TOKENS, maxTokens); | |
| 479 | 470 | |
| 480 | 471 | let inputTokensAvailable = contextLength; |
| 481 | 472 | |
| @@ -486,19 +477,19 @@ | ||
| 486 | 477 | // Non-negotiable messages |
| 487 | 478 | inputTokensAvailable -= toolTokens; |
| 488 | 479 | inputTokensAvailable -= systemMsgTokens; |
| 489 | - // inputTokensAvailable -= lastMessagesTokens; | |
| 480 | + inputTokensAvailable -= lastMessagesTokens; | |
| 490 | 481 | |
| 491 | 482 | // Make sure there's enough context for the non-excludable items |
| 492 | 483 | if (inputTokensAvailable < 0) { |
| 493 | 484 | throw new Error( |
| 494 | 485 | `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}`, | |
| 502 | 493 | ); |
| 503 | 494 | } |
| 504 | 495 | |
| @@ -513,12 +504,10 @@ | ||
| 513 | 504 | }; |
| 514 | 505 | }); |
| 515 | 506 | |
| 516 | - let pruningStatus: PruningStatus = "not-pruned"; | |
| 517 | - | |
| 518 | 507 | while (historyWithTokens.length > 0 && currentTotal > inputTokensAvailable) { |
| 519 | 508 | const message = historyWithTokens.shift()!; |
| 520 | 509 | currentTotal -= message.tokens; |
| 521 | - pruningStatus = "pruned"; | |
| 510 | + didPrune = true; | |
| 522 | 511 | |
| 523 | 512 | // At this point make sure no latent tool response without corresponding call |
| 524 | 513 | while (historyWithTokens[0]?.role === "tool") { |
| @@ -527,18 +516,24 @@ | ||
| 527 | 516 | } |
| 528 | 517 | } |
| 529 | 518 | |
| 530 | - if (historyWithTokens.length === 0) { | |
| 531 | - pruningStatus = "deleted-last-input"; | |
| 532 | - } | |
| 533 | - | |
| 534 | 519 | // Now reassemble |
| 535 | 520 | const reassembled: ChatMessage[] = []; |
| 536 | 521 | if (systemMsg) { |
| 537 | 522 | reassembled.push(systemMsg); |
| 538 | 523 | } |
| 539 | 524 | 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 | + }; | |
| 542 | 537 | } |
| 543 | 538 | |
| 544 | 539 | export { |
modified core/llm/index.ts +1 −1
| @@ -940,7 +940,7 @@ | ||
| 940 | 940 | let messages = _messages; |
| 941 | 941 | |
| 942 | 942 | // If not precompiled, compile the chat messages |
| 943 | - if (!messageOptions || messageOptions.precompiled === false) { | |
| 943 | + if (!messageOptions?.precompiled) { | |
| 944 | 944 | const { compiledChatMessages } = compileChatMessages({ |
| 945 | 945 | modelName: completionOptions.model, |
| 946 | 946 | msgs: _messages, |
modified gui/src/components/StepContainer/StepContainer.tsx +0 −3
| @@ -25,9 +25,6 @@ | ||
| 25 | 25 | const historyItemAfterThis = useAppSelector( |
| 26 | 26 | (state) => state.session.history[props.index + 1], |
| 27 | 27 | ); |
| 28 | - const warningMessage = useAppSelector( | |
| 29 | - (state) => state.session.warningMessage, | |
| 30 | - ); | |
| 31 | 28 | const uiConfig = useAppSelector(selectUIConfig); |
| 32 | 29 | |
| 33 | 30 | // 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 @@ | ||
| 10 | 10 | import { ToolbarOptions } from "./InputToolbar"; |
| 11 | 11 | import { Lump } from "./Lump"; |
| 12 | 12 | import { TipTapEditor } from "./TipTapEditor"; |
| 13 | -import WarningMessageBox from "./WarningMessageBox"; | |
| 14 | -import EditConfigAction from "./WarningMessageBox/Actions/EditConfigAction"; | |
| 15 | -import NewSessionAction from "./WarningMessageBox/Actions/NewSessionAction"; | |
| 16 | 13 | |
| 17 | 14 | interface ContinueInputBoxProps { |
| 18 | 15 | isLastUserInput: boolean; |
| @@ -43,9 +40,6 @@ | ||
| 43 | 40 | |
| 44 | 41 | function ContinueInputBox(props: ContinueInputBoxProps) { |
| 45 | 42 | const isStreaming = useAppSelector((state) => state.session.isStreaming); |
| 46 | - const warningMessage = useAppSelector( | |
| 47 | - (state) => state.session.warningMessage, | |
| 48 | - ); | |
| 49 | 43 | const availableSlashCommands = useAppSelector( |
| 50 | 44 | selectSlashCommandComboBoxInputs, |
| 51 | 45 | ); |
| @@ -125,19 +119,6 @@ | ||
| 125 | 119 | /> |
| 126 | 120 | </div> |
| 127 | 121 | )} |
| 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 | - ))} | |
| 141 | 122 | </div> |
| 142 | 123 | ); |
| 143 | 124 | } |
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 @@ | ||
| 19 | 19 | import { ModeSelect } from "../ModeSelect"; |
| 20 | 20 | import { Button } from "../ui"; |
| 21 | 21 | import { useFontSize } from "../ui/font"; |
| 22 | +import ContextStatus from "./ContextStatus"; | |
| 22 | 23 | import HoverItem from "./InputToolbar/HoverItem"; |
| 23 | 24 | |
| 24 | 25 | export interface ToolbarOptions { |
| @@ -170,6 +171,7 @@ | ||
| 170 | 171 | fontSize: tinyFont, |
| 171 | 172 | }} |
| 172 | 173 | > |
| 174 | + {!isInEdit && <ContextStatus />} | |
| 173 | 175 | {!props.toolbarOptions?.hideUseCodebase && !isInEdit && ( |
| 174 | 176 | <div |
| 175 | 177 | className={`${toolsSupported ? "md:flex" : "int:flex"} hover:underline" hidden transition-colors duration-200`} |
| @@ -209,7 +211,6 @@ | ||
| 209 | 211 | </span> |
| 210 | 212 | </HoverItem> |
| 211 | 213 | )} |
| 212 | - | |
| 213 | 214 | <Button |
| 214 | 215 | data-tooltip-id="enter-tooltip" |
| 215 | 216 | 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 @@ | ||
| 218 | 218 | {modelSelectTitle(selectedModel) || "Select model"} |
| 219 | 219 | </span> |
| 220 | 220 | <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" | |
| 222 | 222 | aria-hidden="true" |
| 223 | 223 | /> |
| 224 | 224 | </ListboxButton> |
modified gui/src/context/MockIdeMessenger.ts +2 −1
| @@ -86,7 +86,8 @@ | ||
| 86 | 86 | }, |
| 87 | 87 | "llm/compileChat": { |
| 88 | 88 | compiledChatMessages: [], |
| 89 | - pruningStatus: "not-pruned", | |
| 89 | + didPrune: false, | |
| 90 | + contextPercentage: 0.5, | |
| 90 | 91 | }, |
| 91 | 92 | }; |
| 92 | 93 |
modified gui/src/pages/gui/Chat.tsx +15 −18
| @@ -43,6 +43,7 @@ | ||
| 43 | 43 | import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util"; |
| 44 | 44 | import { ToolCallDiv } from "./ToolCallDiv"; |
| 45 | 45 | |
| 46 | +import InlineErrorMessage from "../../components/mainInput/InlineErrorMessage"; | |
| 46 | 47 | import { cancelStream } from "../../redux/thunks/cancelStream"; |
| 47 | 48 | import { EmptyChatBody } from "./EmptyChatBody"; |
| 48 | 49 | import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; |
| @@ -123,9 +124,6 @@ | ||
| 123 | 124 | const jetbrains = useMemo(() => { |
| 124 | 125 | return isJetBrains(); |
| 125 | 126 | }, []); |
| 126 | - const warningMessage = useAppSelector( | |
| 127 | - (state) => state.session.warningMessage, | |
| 128 | - ); | |
| 129 | 127 | |
| 130 | 128 | useAutoScroll(stepsDivRef, history); |
| 131 | 129 | |
| @@ -411,6 +409,7 @@ | ||
| 411 | 409 | > |
| 412 | 410 | {renderChatHistoryItem(item, index)} |
| 413 | 411 | </ErrorBoundary> |
| 412 | + {index === history.length - 1 && <InlineErrorMessage />} | |
| 414 | 413 | </div> |
| 415 | 414 | ))} |
| 416 | 415 | </StepsDiv> |
| @@ -432,21 +431,19 @@ | ||
| 432 | 431 | <div className="flex flex-row items-center justify-between pb-1 pl-0.5 pr-2"> |
| 433 | 432 | <div className="xs:inline hidden"> |
| 434 | 433 | {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> | |
| 450 | 447 | )} |
| 451 | 448 | </div> |
| 452 | 449 | </div> |
modified gui/src/redux/slices/sessionSlice.ts +26 −7
| @@ -23,7 +23,6 @@ | ||
| 23 | 23 | Tool, |
| 24 | 24 | ToolCallDelta, |
| 25 | 25 | ToolCallState, |
| 26 | - WarningMessage, | |
| 27 | 26 | } from "core"; |
| 28 | 27 | import { BuiltInToolNames } from "core/tools/builtIn"; |
| 29 | 28 | import { NEW_SESSION_TITLE } from "core/util/constants"; |
| @@ -34,6 +33,7 @@ | ||
| 34 | 33 | import { findUriInDirs, getUriPathBasename } from "core/util/uri"; |
| 35 | 34 | import { findLastIndex } from "lodash"; |
| 36 | 35 | import { v4 as uuidv4 } from "uuid"; |
| 36 | +import { type InlineErrorMessageType } from "../../components/mainInput/InlineErrorMessage"; | |
| 37 | 37 | import { toolCallCtxItemToCtxItemWithId } from "../../pages/gui/ToolCallDiv/utils"; |
| 38 | 38 | import { addToolCallDeltaToState } from "../../util/toolCallState"; |
| 39 | 39 | import { RootState } from "../store"; |
| @@ -224,8 +224,10 @@ | ||
| 224 | 224 | }; |
| 225 | 225 | newestToolbarPreviewForInput: Record<string, string>; |
| 226 | 226 | hasReasoningEnabled?: boolean; |
| 227 | + isPruned?: boolean; | |
| 228 | + contextPercentage?: number; | |
| 229 | + inlineErrorMessage?: InlineErrorMessageType; | |
| 227 | 230 | compactionLoading: Record<number, boolean>; // Track compaction loading by message index |
| 228 | - warningMessage?: WarningMessage; | |
| 229 | 231 | }; |
| 230 | 232 | |
| 231 | 233 | const initialState: SessionState = { |
| @@ -431,12 +433,17 @@ | ||
| 431 | 433 | }, |
| 432 | 434 | contextItems: [], |
| 433 | 435 | }); |
| 436 | + state.inlineErrorMessage = undefined; | |
| 437 | + state.isPruned = false; | |
| 438 | + state.contextPercentage = undefined; | |
| 434 | 439 | } |
| 435 | 440 | }, |
| 436 | 441 | deleteMessage: (state, action: PayloadAction<number>) => { |
| 437 | 442 | // Deletes the current assistant message and the previous user message |
| 438 | 443 | state.history.splice(action.payload - 1, 2); |
| 439 | - state.warningMessage = undefined; | |
| 444 | + state.inlineErrorMessage = undefined; | |
| 445 | + state.isPruned = false; | |
| 446 | + state.contextPercentage = undefined; | |
| 440 | 447 | }, |
| 441 | 448 | updateHistoryItemAtIndex: ( |
| 442 | 449 | state, |
| @@ -647,6 +654,10 @@ | ||
| 647 | 654 | state.isStreaming = false; |
| 648 | 655 | state.symbols = {}; |
| 649 | 656 | |
| 657 | + state.inlineErrorMessage = undefined; | |
| 658 | + state.isPruned = false; | |
| 659 | + state.contextPercentage = undefined; | |
| 660 | + | |
| 650 | 661 | if (payload) { |
| 651 | 662 | state.history = payload.history as any; |
| 652 | 663 | state.title = payload.title; |
| @@ -913,11 +924,17 @@ | ||
| 913 | 924 | delete state.compactionLoading[index]; |
| 914 | 925 | } |
| 915 | 926 | }, |
| 916 | - setWarningMessage: ( | |
| 927 | + setInlineErrorMessage: ( | |
| 917 | 928 | state, |
| 918 | - action: PayloadAction<WarningMessage | undefined>, | |
| 929 | + action: PayloadAction<SessionState["inlineErrorMessage"]>, | |
| 919 | 930 | ) => { |
| 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; | |
| 921 | 938 | }, |
| 922 | 939 | }, |
| 923 | 940 | selectors: { |
| @@ -1002,8 +1019,10 @@ | ||
| 1002 | 1019 | setNewestToolbarPreviewForInput, |
| 1003 | 1020 | setIsInEdit, |
| 1004 | 1021 | setHasReasoningEnabled, |
| 1022 | + setInlineErrorMessage, | |
| 1023 | + setIsPruned, | |
| 1024 | + setContextPercentage, | |
| 1005 | 1025 | setCompactionLoading, |
| 1006 | - setWarningMessage, | |
| 1007 | 1026 | } = sessionSlice.actions; |
| 1008 | 1027 | |
| 1009 | 1028 | export const { selectIsGatheringContext } = sessionSlice.selectors; |
modified gui/src/redux/thunks/streamNormalInput.ts +16 −27
| @@ -11,9 +11,11 @@ | ||
| 11 | 11 | addPromptCompletionPair, |
| 12 | 12 | setActive, |
| 13 | 13 | setAppliedRulesAtIndex, |
| 14 | + setContextPercentage, | |
| 14 | 15 | setInactive, |
| 16 | + setInlineErrorMessage, | |
| 17 | + setIsPruned, | |
| 15 | 18 | setToolGenerated, |
| 16 | - setWarningMessage, | |
| 17 | 19 | streamUpdate, |
| 18 | 20 | } from "../slices/sessionSlice"; |
| 19 | 21 | import { AppThunkDispatch, RootState, ThunkApiType } from "../store"; |
| @@ -184,42 +186,29 @@ | ||
| 184 | 186 | ); |
| 185 | 187 | |
| 186 | 188 | dispatch(setActive()); |
| 187 | - // Remove the warning message before each compileChat call | |
| 188 | - dispatch(setWarningMessage(undefined)); | |
| 189 | + dispatch(setInlineErrorMessage(undefined)); | |
| 190 | + | |
| 189 | 191 | const precompiledRes = await extra.ideMessenger.request("llm/compileChat", { |
| 190 | 192 | messages, |
| 191 | 193 | options: completionOptions, |
| 192 | 194 | }); |
| 193 | 195 | |
| 194 | 196 | 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")); | |
| 219 | 199 | dispatch(setInactive()); |
| 220 | 200 | return; |
| 201 | + } else { | |
| 202 | + throw new Error(precompiledRes.error); | |
| 203 | + } | |
| 221 | 204 | } |
| 222 | 205 | |
| 206 | + const { compiledChatMessages, didPrune, contextPercentage } = | |
| 207 | + precompiledRes.content; | |
| 208 | + | |
| 209 | + dispatch(setIsPruned(didPrune)); | |
| 210 | + dispatch(setContextPercentage(contextPercentage)); | |
| 211 | + | |
| 223 | 212 | // Send request and stream response |
| 224 | 213 | const streamAborter = state.session.streamAborter; |
| 225 | 214 | const gen = extra.ideMessenger.llmStreamChat( |
modified packages/shared-release.config.js +1 −1
| @@ -25,4 +25,4 @@ | ||
| 25 | 25 | "@semantic-release/github", |
| 26 | 26 | ], |
| 27 | 27 | }; |
| 28 | -} | |
| No newline at the end of the file | ||
| 28 | +} |