Add /compress command to force a compression of the context (#986)

Related to https://b.corp.google.com/issues/423605555 - I figured this might be a simpler solution to start with, while still also being useful on its own even if we do implement that.
This commit is contained in:
Jacob MacDonald
2025-06-13 21:21:40 -07:00
committed by GitHub
parent 1452bb4ca4
commit d5c6bb9740
10 changed files with 267 additions and 43 deletions

View File

@@ -13,6 +13,7 @@ import {
ServerGeminiStreamEvent as GeminiEvent,
ServerGeminiContentEvent as ContentEvent,
ServerGeminiErrorEvent as ErrorEvent,
ServerGeminiChatCompressedEvent,
getErrorMessage,
isNodeError,
MessageSenderType,
@@ -368,11 +369,14 @@ export const useGeminiStream = (
);
const handleChatCompressionEvent = useCallback(
() =>
(eventValue: ServerGeminiChatCompressedEvent['value']) =>
addItem(
{
type: 'info',
text: `IMPORTANT: this conversation approached the input token limit for ${config.getModel()}. We'll send a compressed context to the model for any future messages.`,
text:
`IMPORTANT: This conversation approached the input token limit for ${config.getModel()}. ` +
`A compressed context will be sent for future messages (compressed from: ` +
`${eventValue.originalTokenCount} to ${eventValue.newTokenCount} tokens).`,
},
Date.now(),
),
@@ -406,7 +410,7 @@ export const useGeminiStream = (
handleErrorEvent(event.value, userMessageTimestamp);
break;
case ServerGeminiEventType.ChatCompressed:
handleChatCompressionEvent();
handleChatCompressionEvent(event.value);
break;
case ServerGeminiEventType.UsageMetadata:
addUsage(event.value);