Repository navigation
fix(grok): show context-window usage in the composer #9206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,12 +55,14 @@ import { | |
| makeAcpPlanUpdatedEvent, | ||
| makeAcpRequestOpenedEvent, | ||
| makeAcpRequestResolvedEvent, | ||
| makeAcpTokenUsageEvent, | ||
| makeAcpToolCallEvent, | ||
| } from "../acp/AcpCoreRuntimeEvents.ts"; | ||
| import { parsePermissionRequest } from "../acp/AcpRuntimeModel.ts"; | ||
| import { makeAcpNativeLoggerFactory } from "../acp/AcpNativeLogging.ts"; | ||
| import { | ||
| applyGrokAcpModelSelection, | ||
| contextWindowFromGrokSessionSetup, | ||
| currentGrokModelIdFromSessionSetup, | ||
| currentGrokReasoningEffortFromSessionSetup, | ||
| makeGrokAcpRuntime, | ||
|
|
@@ -169,6 +171,8 @@ interface GrokSessionContext { | |
| promptResponsesReady: number; | ||
| currentModelId: string | undefined; | ||
| currentReasoningEffort: string | undefined; | ||
| lastContextTokens: number | undefined; | ||
| lastKnownMaxTokens: number | undefined; | ||
| stopped: boolean; | ||
| } | ||
|
|
||
|
|
@@ -314,6 +318,8 @@ function selectAutoApprovedPermissionOption( | |
| ); | ||
| } | ||
|
|
||
| const GROK_DEFAULT_CONTEXT_WINDOW = 500_000; | ||
|
|
||
| function completedStopReasonFromPromptResponse( | ||
| response: EffectAcpSchema.PromptResponse | undefined, | ||
| ): EffectAcpSchema.StopReason | null { | ||
|
|
@@ -1300,6 +1306,11 @@ export function makeGrokAdapter(grokSettings: GrokSettings, options?: GrokAdapte | |
| requestedStartReasoningEffort !== undefined | ||
| ? normalizeGrokReasoningEffort(requestedStartReasoningEffort) | ||
| : currentStartReasoningEffort, | ||
| lastContextTokens: undefined, | ||
| lastKnownMaxTokens: contextWindowFromGrokSessionSetup( | ||
| started.sessionSetupResult, | ||
| boundModelId, | ||
| ), | ||
| stopped: false, | ||
| }; | ||
|
|
||
|
|
@@ -1313,7 +1324,8 @@ export function makeGrokAdapter(grokSettings: GrokSettings, options?: GrokAdapte | |
| if ( | ||
| event._tag === "PlanUpdated" || | ||
| event._tag === "ToolCallUpdated" || | ||
| event._tag === "ContentDelta" | ||
| event._tag === "ContentDelta" || | ||
| event._tag === "UsageUpdated" | ||
| ) { | ||
| yield* logNative(ctx.threadId, "session/update", event.rawPayload); | ||
| } | ||
|
|
@@ -1322,6 +1334,36 @@ export function makeGrokAdapter(grokSettings: GrokSettings, options?: GrokAdapte | |
| return; | ||
| } | ||
|
|
||
| if (event._tag === "UsageUpdated") { | ||
| const usageTurnId = resolveNotificationTurnId(ctx); | ||
| if (usageTurnId !== undefined && ctx.interruptedTurnIds.has(usageTurnId)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium A queued 🤖 Copy this AI Prompt to have your agent fix this: |
||
| return; | ||
| } | ||
| if (ctx.lastContextTokens === event.used) { | ||
|
macroscopeapp[bot] marked this conversation as resolved.
Outdated
|
||
| return; | ||
| } | ||
| ctx.lastContextTokens = event.used; | ||
| if (event.size > 0) { | ||
| ctx.lastKnownMaxTokens = event.size; | ||
| } | ||
| const usageEvent = makeAcpTokenUsageEvent({ | ||
| stamp: yield* makeEventStamp(), | ||
| provider: PROVIDER, | ||
| threadId: ctx.threadId, | ||
| turnId: usageTurnId, | ||
| used: event.used, | ||
| size: | ||
| event.size > 0 | ||
| ? event.size | ||
| : (ctx.lastKnownMaxTokens ?? GROK_DEFAULT_CONTEXT_WINDOW), | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||
| rawPayload: event.rawPayload, | ||
| }); | ||
| if (usageEvent) { | ||
| yield* offerRuntimeEvent(usageEvent); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| const notificationTurnId = resolveNotificationTurnId(ctx); | ||
| if ( | ||
| notificationTurnId === undefined || | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.