mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 14:01:06 +00:00
fix: update footer state when rendering initial messages on resume/continue
This commit is contained in:
parent
4019acf1f0
commit
97ac82312f
4 changed files with 125 additions and 16 deletions
File diff suppressed because one or more lines are too long
|
|
@ -36,10 +36,22 @@ export class FooterComponent {
|
|||
}
|
||||
}
|
||||
|
||||
// Calculate total tokens and % of context window
|
||||
const totalTokens = totalInput + totalOutput;
|
||||
// Get last assistant message for context percentage calculation
|
||||
const lastAssistantMessage = this.state.messages
|
||||
.slice()
|
||||
.reverse()
|
||||
.find((m) => m.role === "assistant") as AssistantMessage | undefined;
|
||||
|
||||
// Calculate context percentage from last message (input + output + cacheRead + cacheWrite)
|
||||
const contextTokens = lastAssistantMessage
|
||||
? lastAssistantMessage.usage.input +
|
||||
lastAssistantMessage.usage.output +
|
||||
lastAssistantMessage.usage.cacheRead +
|
||||
lastAssistantMessage.usage.cacheWrite
|
||||
: 0;
|
||||
const contextWindow = this.state.model.contextWindow;
|
||||
const contextPercent = contextWindow > 0 ? ((totalTokens / contextWindow) * 100).toFixed(1) : "0.0";
|
||||
const contextPercent =
|
||||
contextWindow > 0 ? `${((contextTokens / contextWindow) * 100).toFixed(1)}% (${contextWindow})` : "0.0%";
|
||||
|
||||
// Format token counts (similar to web-ui)
|
||||
const formatTokens = (count: number): string => {
|
||||
|
|
|
|||
|
|
@ -351,6 +351,9 @@ export class TuiRenderer {
|
|||
// Reset first user message flag for initial render
|
||||
this.isFirstUserMessage = true;
|
||||
|
||||
// Update footer with loaded state
|
||||
this.footer.updateState(state);
|
||||
|
||||
// Render messages
|
||||
for (let i = 0; i < state.messages.length; i++) {
|
||||
const message = state.messages[i];
|
||||
|
|
|
|||
|
|
@ -265,10 +265,10 @@ export class Editor implements Component {
|
|||
// Get text and substitute paste markers with actual content
|
||||
let result = this.state.lines.join("\n").trim();
|
||||
|
||||
// Replace all [paste #N +xxx lines] markers with actual paste content
|
||||
// Replace all [paste #N +xxx lines] or [paste #N xxx chars] markers with actual paste content
|
||||
for (const [pasteId, pasteContent] of this.pastes) {
|
||||
// Match both old format [paste #N] and new format [paste #N +xxx lines]
|
||||
const markerRegex = new RegExp(`\\[paste #${pasteId}( \\+\\d+ lines)?\\]`, "g");
|
||||
// Match formats: [paste #N], [paste #N +xxx lines], or [paste #N xxx chars]
|
||||
const markerRegex = new RegExp(`\\[paste #${pasteId}( (\\+\\d+ lines|\\d+ chars))?\\]`, "g");
|
||||
result = result.replace(markerRegex, pasteContent);
|
||||
}
|
||||
|
||||
|
|
@ -466,15 +466,19 @@ export class Editor implements Component {
|
|||
// Split into lines
|
||||
const pastedLines = filteredText.split("\n");
|
||||
|
||||
// Check if this is a large paste (> 10 lines)
|
||||
if (pastedLines.length > 10) {
|
||||
// Check if this is a large paste (> 10 lines or > 1000 characters)
|
||||
const totalChars = filteredText.length;
|
||||
if (pastedLines.length > 10 || totalChars > 1000) {
|
||||
// Store the paste and insert a marker
|
||||
this.pasteCounter++;
|
||||
const pasteId = this.pasteCounter;
|
||||
this.pastes.set(pasteId, filteredText);
|
||||
|
||||
// Insert marker like "[paste #1 +123 lines]"
|
||||
const marker = `[paste #${pasteId} +${pastedLines.length} lines]`;
|
||||
// Insert marker like "[paste #1 +123 lines]" or "[paste #1 1234 chars]"
|
||||
const marker =
|
||||
pastedLines.length > 10
|
||||
? `[paste #${pasteId} +${pastedLines.length} lines]`
|
||||
: `[paste #${pasteId} ${totalChars} chars]`;
|
||||
for (const char of marker) {
|
||||
this.insertCharacter(char);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue