mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 00:03:00 +00:00
feat(coding-agent): add extension compaction helpers
This commit is contained in:
parent
673916f63c
commit
9d3f8117a4
11 changed files with 190 additions and 4 deletions
|
|
@ -33,6 +33,7 @@ import {
|
|||
calculateContextTokens,
|
||||
collectEntriesForBranchSummary,
|
||||
compact,
|
||||
estimateContextTokens,
|
||||
generateBranchSummary,
|
||||
prepareCompaction,
|
||||
shouldCompact,
|
||||
|
|
@ -40,6 +41,7 @@ import {
|
|||
import { exportSessionToHtml, type ToolHtmlRenderer } from "./export-html/index.js";
|
||||
import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
|
||||
import type {
|
||||
ContextUsage,
|
||||
ExtensionRunner,
|
||||
InputSource,
|
||||
SessionBeforeCompactResult,
|
||||
|
|
@ -2250,6 +2252,26 @@ export class AgentSession {
|
|||
};
|
||||
}
|
||||
|
||||
getContextUsage(): ContextUsage | undefined {
|
||||
const model = this.model;
|
||||
if (!model) return undefined;
|
||||
|
||||
const contextWindow = model.contextWindow ?? 0;
|
||||
if (contextWindow <= 0) return undefined;
|
||||
|
||||
const estimate = estimateContextTokens(this.messages);
|
||||
const percent = (estimate.tokens / contextWindow) * 100;
|
||||
|
||||
return {
|
||||
tokens: estimate.tokens,
|
||||
contextWindow,
|
||||
percent,
|
||||
usageTokens: estimate.usageTokens,
|
||||
trailingTokens: estimate.trailingTokens,
|
||||
lastUsageIndex: estimate.lastUsageIndex,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Export session to HTML.
|
||||
* @param outputPath Optional output path (defaults to session directory)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue