Add Codex context compaction support (#990)
This commit is contained in:
@@ -540,7 +540,13 @@ const AgentStreamViewComponent = forwardRef<AgentStreamViewHandle, AgentStreamVi
|
||||
return <TodoListCard items={item.items} />;
|
||||
|
||||
case "compaction":
|
||||
return <CompactionMarker status={item.status} preTokens={item.preTokens} />;
|
||||
return (
|
||||
<CompactionMarker
|
||||
status={item.status}
|
||||
trigger={item.trigger}
|
||||
preTokens={item.preTokens}
|
||||
/>
|
||||
);
|
||||
|
||||
default:
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { getCompactionMarkerLabel } from "./message-compaction-label";
|
||||
|
||||
describe("getCompactionMarkerLabel", () => {
|
||||
it("renders loading, automatic, manual, tokenized, and fallback labels", () => {
|
||||
expect(getCompactionMarkerLabel({ status: "loading" })).toBe("Compacting...");
|
||||
expect(getCompactionMarkerLabel({ status: "completed", trigger: "auto" })).toBe(
|
||||
"Context automatically compacted",
|
||||
);
|
||||
expect(getCompactionMarkerLabel({ status: "completed", trigger: "manual" })).toBe(
|
||||
"Context manually compacted",
|
||||
);
|
||||
expect(getCompactionMarkerLabel({ status: "completed", preTokens: 12_345 })).toBe(
|
||||
"Context compacted (12K tokens)",
|
||||
);
|
||||
expect(getCompactionMarkerLabel({ status: "completed" })).toBe("Context compacted");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
export interface CompactionMarkerLabelInput {
|
||||
status: "loading" | "completed";
|
||||
trigger?: "auto" | "manual";
|
||||
preTokens?: number;
|
||||
}
|
||||
|
||||
export function getCompactionMarkerLabel({
|
||||
status,
|
||||
trigger,
|
||||
preTokens,
|
||||
}: CompactionMarkerLabelInput): string {
|
||||
if (status === "loading") return "Compacting...";
|
||||
if (trigger === "auto") return "Context automatically compacted";
|
||||
if (trigger === "manual") return "Context manually compacted";
|
||||
if (preTokens) return `Context compacted (${Math.round(preTokens / 1000)}K tokens)`;
|
||||
return "Context compacted";
|
||||
}
|
||||
@@ -92,6 +92,7 @@ import {
|
||||
import { PlanCard } from "./plan-card";
|
||||
import { useToolCallSheet } from "./tool-call-sheet";
|
||||
import { ToolCallDetailsContent } from "./tool-call-details";
|
||||
import { getCompactionMarkerLabel } from "./message-compaction-label";
|
||||
import { useAttachmentPreviewUrl } from "@/attachments/use-attachment-preview-url";
|
||||
import { persistAttachmentFromBytes, persistAttachmentFromDataUrl } from "@/attachments/service";
|
||||
import type { DaemonClient } from "@server/client/daemon-client";
|
||||
@@ -1978,6 +1979,7 @@ export const ActivityLog = memo(function ActivityLog({
|
||||
|
||||
interface CompactionMarkerProps {
|
||||
status: "loading" | "completed";
|
||||
trigger?: "auto" | "manual";
|
||||
preTokens?: number;
|
||||
}
|
||||
|
||||
@@ -2008,12 +2010,10 @@ const compactionStylesheet = StyleSheet.create((theme) => ({
|
||||
|
||||
export const CompactionMarker = memo(function CompactionMarker({
|
||||
status,
|
||||
trigger,
|
||||
preTokens,
|
||||
}: CompactionMarkerProps) {
|
||||
let label: string;
|
||||
if (status === "loading") label = "Compacting...";
|
||||
else if (preTokens) label = `Context compacted (${Math.round(preTokens / 1000)}K tokens)`;
|
||||
else label = "Context compacted";
|
||||
const label = getCompactionMarkerLabel({ status, trigger, preTokens });
|
||||
|
||||
return (
|
||||
<View style={compactionStylesheet.container}>
|
||||
|
||||
Reference in New Issue
Block a user