mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 19:04:31 +00:00
feat: surface cached token counts in /status output (openclaw#21248) thanks @vishaltandale00
Verified: - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: vishaltandale00 <9222298+vishaltandale00@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
68
src/config/sessions/cache-fields.test.ts
Normal file
68
src/config/sessions/cache-fields.test.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { SessionEntry } from "./types.js";
|
||||
import { mergeSessionEntry } from "./types.js";
|
||||
|
||||
describe("SessionEntry cache fields", () => {
|
||||
it("supports cacheRead and cacheWrite fields", () => {
|
||||
const entry: SessionEntry = {
|
||||
sessionId: "test-session",
|
||||
updatedAt: Date.now(),
|
||||
cacheRead: 1500,
|
||||
cacheWrite: 300,
|
||||
};
|
||||
|
||||
expect(entry.cacheRead).toBe(1500);
|
||||
expect(entry.cacheWrite).toBe(300);
|
||||
});
|
||||
|
||||
it("merges cache fields properly", () => {
|
||||
const existing: SessionEntry = {
|
||||
sessionId: "test-session",
|
||||
updatedAt: Date.now(),
|
||||
cacheRead: 1000,
|
||||
cacheWrite: 200,
|
||||
totalTokens: 5000,
|
||||
};
|
||||
|
||||
const patch: Partial<SessionEntry> = {
|
||||
cacheRead: 1500,
|
||||
cacheWrite: 300,
|
||||
};
|
||||
|
||||
const merged = mergeSessionEntry(existing, patch);
|
||||
|
||||
expect(merged.cacheRead).toBe(1500);
|
||||
expect(merged.cacheWrite).toBe(300);
|
||||
expect(merged.totalTokens).toBe(5000); // Preserved from existing
|
||||
});
|
||||
|
||||
it("handles undefined cache fields", () => {
|
||||
const entry: SessionEntry = {
|
||||
sessionId: "test-session",
|
||||
updatedAt: Date.now(),
|
||||
totalTokens: 5000,
|
||||
};
|
||||
|
||||
expect(entry.cacheRead).toBeUndefined();
|
||||
expect(entry.cacheWrite).toBeUndefined();
|
||||
});
|
||||
|
||||
it("allows cache fields to be cleared with undefined", () => {
|
||||
const existing: SessionEntry = {
|
||||
sessionId: "test-session",
|
||||
updatedAt: Date.now(),
|
||||
cacheRead: 1000,
|
||||
cacheWrite: 200,
|
||||
};
|
||||
|
||||
const patch: Partial<SessionEntry> = {
|
||||
cacheRead: undefined,
|
||||
cacheWrite: undefined,
|
||||
};
|
||||
|
||||
const merged = mergeSessionEntry(existing, patch);
|
||||
|
||||
expect(merged.cacheRead).toBeUndefined();
|
||||
expect(merged.cacheWrite).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -78,6 +78,8 @@ export type SessionEntry = {
|
||||
* totalTokens as stale/unknown for context-utilization displays.
|
||||
*/
|
||||
totalTokensFresh?: boolean;
|
||||
cacheRead?: number;
|
||||
cacheWrite?: number;
|
||||
modelProvider?: string;
|
||||
model?: string;
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user