codex-copilot-dx 1.3.25 → 1.3.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/bin/cli.mjs +2 -2
- package/docs/ARCHITECTURE.md +6 -0
- package/docs/REFERENCE.md +24 -3
- package/package.json +1 -1
- package/src/antigravity-chat-bridge.mjs +2 -1
- package/src/antigravity-handler.mjs +67 -13
- package/src/antigravity-runtime.mjs +7 -2
- package/src/antigravity-usage.mjs +86 -0
- package/src/cli-command-spec.mjs +9 -4
- package/src/cli-management.mjs +25 -5
- package/src/client-versions.mjs +17 -13
- package/src/dashboard/console.js +1 -1
- package/src/dashboard/context.js +8 -4
- package/src/dashboard/flow.js +12 -11
- package/src/dashboard/gemini.js +20 -5
- package/src/dashboard/index.html +10 -9
- package/src/dashboard/language.js +31 -9
- package/src/dashboard/status.js +11 -2
- package/src/dashboard/ui.js +18 -7
- package/src/dashboard/usage.js +35 -19
- package/src/dashboard-api.mjs +19 -6
- package/src/stream-performance.mjs +5 -1
- package/src/terminal-state.mjs +8 -0
- package/src/usage-analysis.mjs +19 -8
- package/src/usage-analytics.mjs +9 -7
- package/src/usage-query.mjs +36 -0
- package/src/usage-store.mjs +4 -3
- package/src/usage.mjs +7 -3
package/src/dashboard-api.mjs
CHANGED
|
@@ -14,9 +14,10 @@ import {
|
|
|
14
14
|
renderTerminalAnimationFrame,
|
|
15
15
|
TERMINAL_ANIMATION_THEMES,
|
|
16
16
|
} from "./terminal-animation.mjs";
|
|
17
|
-
import { cacheReadTokens, summarizeUsageLogs, usageCacheHitRate, usageModelGroups } from "./usage-store.mjs";
|
|
17
|
+
import { cacheReadTokens, summarizeUsageLogs, usageCacheHitRate, usageModelGroups, usageProvider } from "./usage-store.mjs";
|
|
18
18
|
import { createUsageAnalytics } from "./usage-analytics.mjs";
|
|
19
19
|
import { analyzeUsageLogs } from "./usage-analysis.mjs";
|
|
20
|
+
import { createUsageQuery } from "./usage-query.mjs";
|
|
20
21
|
import { readUserSettings, terminalAnimationPreference, writeTerminalAnimationTheme } from "./user-settings.mjs";
|
|
21
22
|
import { settingsPreferencesSnapshot } from "./settings-preferences.mjs";
|
|
22
23
|
|
|
@@ -383,12 +384,15 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
383
384
|
const query = new URL(req.url, "http://localhost").searchParams;
|
|
384
385
|
const provider = query.get("provider") || "";
|
|
385
386
|
if (provider && !isProviderId(provider)) { sendJson(res, 400, { error: "Select a valid provider" });return; }
|
|
387
|
+
let selection;
|
|
388
|
+
try { selection = createUsageQuery({ provider, model: query.get("model") || "", days: query.get("days") || "all", from: query.get("from") || "", to: query.get("to") || "", timeZone: query.get("time_zone") || "UTC" }); }
|
|
389
|
+
catch (error) { sendJson(res, 400, { error: error.message });return; }
|
|
386
390
|
let analytics = null;
|
|
387
391
|
if (query.get("analytics") === "1") {
|
|
388
392
|
try {
|
|
389
393
|
const timeZone = query.get("time_zone") || "UTC";
|
|
390
394
|
if (timeZone.length > 100) throw new Error("Invalid time zone");
|
|
391
|
-
analytics = createUsageAnalytics({ timeZone, qualifyProviders: !provider });
|
|
395
|
+
analytics = createUsageAnalytics({ timeZone, qualifyProviders: !provider, from: selection.filters.from, to: selection.filters.to });
|
|
392
396
|
} catch {
|
|
393
397
|
sendJson(res, 400, { error: "Select a valid usage time zone" });
|
|
394
398
|
return;
|
|
@@ -396,10 +400,19 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
396
400
|
}
|
|
397
401
|
const abort = createRequestAbort(req, res);
|
|
398
402
|
try {
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
+
const filtered = selection.filters.model || selection.filters.from || selection.filters.to;
|
|
404
|
+
const observedModels = new Set();
|
|
405
|
+
const recordFilter = record => {
|
|
406
|
+
if (observedModels.size < 100) observedModels.add(provider ? record.model || "unknown" : `${usageProvider(record)} / ${record.model || "unknown"}`);
|
|
407
|
+
return selection.matches(record);
|
|
408
|
+
};
|
|
409
|
+
const analysis = (analytics || filtered) && !usageSummaryFn
|
|
410
|
+
? await analyzeUsageLogs(undefined, { provider, model: selection.filters.model, from: selection.filters.from, to: selection.filters.to, timeZone: selection.filters.time_zone, signal: abort.signal }) : null;
|
|
411
|
+
const summary = analysis?.summary || await (usageSummaryFn || (options => summarizeUsageLogs(undefined, { ...options, signal: abort.signal })))({ provider,
|
|
412
|
+
...(filtered ? { recordFilter } : {}), ...(analytics ? { onRecord: analytics.record } : {}) });
|
|
413
|
+
const availableModels = analysis?.analytics.models || (observedModels.size ? [...observedModels].sort() : Object.keys(provider ? summary.byModel : summary.bySourceModel || summary.byModel).sort().slice(0, 100));
|
|
414
|
+
if (!abort.signal.aborted) sendJson(res, 200, { source: "local_usage_log", provider: provider || "all", providers: summary.providers, filters: selection.filters, available_models: availableModels,
|
|
415
|
+
...usageTable(summary), ...(analytics ? { analytics: analysis?.analytics || analytics.snapshot() } : {}) });
|
|
403
416
|
} catch {
|
|
404
417
|
if (!abort.signal.aborted) sendJson(res, 500, { error: "Could not read local usage summary" });
|
|
405
418
|
} finally { abort.cleanup(); }
|
|
@@ -4,6 +4,7 @@ import { isProviderId } from "./provider-metadata.mjs";
|
|
|
4
4
|
import { applicationLabel } from "./request-application.mjs";
|
|
5
5
|
import { createContextMetrics } from "./context-metrics.mjs";
|
|
6
6
|
import { createChangeSignal } from "./activity-events.mjs";
|
|
7
|
+
import { redactDiagnosticText } from "./diagnostic-text.mjs";
|
|
7
8
|
|
|
8
9
|
const PERFORMANCE_ROUTES = Object.freeze(["responses", "responses_compact"]);
|
|
9
10
|
const PREPARATION_STAGES = Object.freeze(["admission", "body", "history", "images", "serialization"]);
|
|
@@ -346,8 +347,10 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
|
|
|
346
347
|
observeContext(values) {
|
|
347
348
|
if (finished || !values || typeof values !== "object") return;
|
|
348
349
|
if (Number.isSafeInteger(values.cached_input_tokens) && values.cached_input_tokens >= 0) cachedInput = values.cached_input_tokens;
|
|
349
|
-
for (const key of [...Object.keys(context), "capability_revision", "capability_constraints", "privacy_count", "privacy_ms", "privacy_state", "privacy_pending_bytes", "privacy_new_bytes", "privacy_pending_windows", "privacy_wait_budget_ms", "privacy_error", "privacy_event_type", "privacy_channel_type", "privacy_buffered_bytes", "privacy_terminal_seen", "client_tool_errors_received"]) {
|
|
350
|
+
for (const key of [...Object.keys(context), "requested_model", "usage_state", "capability_revision", "capability_constraints", "privacy_count", "privacy_ms", "privacy_state", "privacy_pending_bytes", "privacy_new_bytes", "privacy_pending_windows", "privacy_wait_budget_ms", "privacy_error", "privacy_event_type", "privacy_channel_type", "privacy_buffered_bytes", "privacy_terminal_seen", "client_tool_errors_received"]) {
|
|
350
351
|
const value = values[key];
|
|
352
|
+
if (key === "requested_model") { if (typeof value === "string" && /^[\w][\w./:@+-]{0,159}$/.test(value) && redactDiagnosticText(value) === value) context[key] = value;continue; }
|
|
353
|
+
if (key === "usage_state") { if (["pending", "reported", "partial", "missing", "unavailable"].includes(value)) context[key] = value;continue; }
|
|
351
354
|
if (key === "privacy_state") { if (["checked", "failed", "cancelled"].includes(value)) context[key] = value;continue; }
|
|
352
355
|
if (["privacy_error", "privacy_event_type", "privacy_channel_type"].includes(key)) {
|
|
353
356
|
if (typeof value === "string" && /^[a-z0-9_.]{1,80}$/.test(value)) context[key] = value;continue;
|
|
@@ -377,6 +380,7 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
|
|
|
377
380
|
},
|
|
378
381
|
finish({ failed: finishFailed = false, aborted = false, statusCode = 0, rejectionReason } = {}) {
|
|
379
382
|
if (finished) return;
|
|
383
|
+
if (context.usage_state === "pending") context.usage_state = "missing";
|
|
380
384
|
if (!sourceStats) assignProvider("unknown");
|
|
381
385
|
finished = true;
|
|
382
386
|
activeTotal--;activeRequests.delete(activeId);
|
package/src/terminal-state.mjs
CHANGED
|
@@ -3,6 +3,14 @@ import { terminalCell } from "./terminal-text.mjs";
|
|
|
3
3
|
const integer = value => Number.isSafeInteger(value) && value >= 0;
|
|
4
4
|
const appIds = { codex_app: "codex", codex_cli: "codex", codex: "codex", claude_app: "claude_app", claude_code: "claude_code", gemini_app: "antigravity" };
|
|
5
5
|
export const TERMINAL_CLIENT_NAMES = Object.freeze({ codex: "Codex", claude_app: "Claude App", claude_code: "Claude Code", gemini: "Antigravity", antigravity: "Antigravity" });
|
|
6
|
+
export function terminalRequestState(row) {
|
|
7
|
+
if (!row.active) return row.state || "unknown";
|
|
8
|
+
if (row.terminal_outcome) return "Finishing";
|
|
9
|
+
if (row.first_output_ms != null) return "Responding";
|
|
10
|
+
if (row.phase === "admission") return "Queued";
|
|
11
|
+
if (row.upstream_attempts > 1) return "Retrying";
|
|
12
|
+
return row.upstream_attempts ? "Waiting upstream" : "Processing input";
|
|
13
|
+
}
|
|
6
14
|
const labels = { configured: "Configured", paused: "Paused", disabled: "Disabled", not_configured: "Not configured", not_installed: "Not installed",
|
|
7
15
|
preserved: "Unchanged", partially_preserved: "Partly unchanged", manual_sync: "Manual sync", default_unavailable: "Default unavailable", configuration_unavailable: "Unreadable", unavailable: "Unavailable" };
|
|
8
16
|
export function terminalUptime(milliseconds) {
|
package/src/usage-analysis.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import { summarizeUsage, summarizeUsageLogs, usageLogPath, usageSummaryVersion, subscribeUsageAppends, usageProvider, mergeUsageSummary } from "./usage-store.mjs";
|
|
4
4
|
import { createUsageAnalytics } from "./usage-analytics.mjs";
|
|
5
5
|
import { createAbortAwareSingleflight } from "./bounded-result-cache.mjs";
|
|
6
|
+
import { createUsageQuery } from "./usage-query.mjs";
|
|
6
7
|
|
|
7
8
|
const MAX_ENTRIES = 2;
|
|
8
9
|
const MAX_BYTES = 2 * 1024 * 1024;
|
|
@@ -56,9 +57,10 @@ function observe() {
|
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
export async function analyzeUsageLogs(filePath = usageLogPath(), { timeZone = "UTC", now = Date.now(), warn = console.error, provider = "", signal } = {}) {
|
|
60
|
+
export async function analyzeUsageLogs(filePath = usageLogPath(), { timeZone = "UTC", now = Date.now(), warn = console.error, provider = "", model = "", days = "all", from = "", to = "", signal } = {}) {
|
|
61
|
+
const selection = createUsageQuery({ provider, model, days, from, to, timeZone, now });
|
|
60
62
|
const zone = new Intl.DateTimeFormat("sv-SE", { timeZone, year: "numeric", month: "2-digit", day: "2-digit" });
|
|
61
|
-
const file = path.resolve(filePath), query = `${file}\0${
|
|
63
|
+
const file = path.resolve(filePath), query = `${file}\0${selection.key}\0${zone.format(new Date(now))}`;
|
|
62
64
|
const version = warn === console.error ? await usageSummaryVersion(file, { settled: false }) : null;
|
|
63
65
|
const collect = async () => {
|
|
64
66
|
const cached = version && cache.get(query);
|
|
@@ -68,25 +70,34 @@ export async function analyzeUsageLogs(filePath = usageLogPath(), { timeZone = "
|
|
|
68
70
|
for (const line of cached.pending) {
|
|
69
71
|
const record = JSON.parse(line);
|
|
70
72
|
if (provider && provider !== usageProvider(record)) continue;
|
|
73
|
+
const label = provider ? record.model || "unknown" : `${usageProvider(record)} / ${record.model || "unknown"}`;
|
|
74
|
+
if (cached.models.size < 100) cached.models.add(label);else if (!cached.models.has(label)) cached.modelsTruncated = true;
|
|
75
|
+
if (!selection.matches(record)) continue;
|
|
71
76
|
const one = summarizeUsage([record]);mergeUsageSummary(cached.summary, one);cached.analytics.record(record, one);
|
|
72
77
|
}
|
|
73
78
|
cached.pending = [];cached.pendingBytes = 0;
|
|
74
|
-
const
|
|
79
|
+
const snapshot = cached.analytics.snapshot();
|
|
80
|
+
const result = { summary: cached.summary, analytics: { ...snapshot, models: [...cached.models].sort(), models_truncated: snapshot.models_truncated || cached.modelsTruncated }, filters: selection.filters };
|
|
75
81
|
cached.bytes = Buffer.byteLength(JSON.stringify(result));
|
|
76
82
|
if (result.analytics.undated_records > 0) cache.delete(query);
|
|
77
83
|
prune();return result;
|
|
78
84
|
}
|
|
79
85
|
cache.delete(query);prune();
|
|
80
|
-
const analytics = createUsageAnalytics({ timeZone, now, qualifyProviders: !provider });
|
|
81
|
-
let warned = false;
|
|
82
|
-
const summary = await summarizeUsageLogs(filePath, { provider, onRecord: analytics.record,
|
|
86
|
+
const analytics = createUsageAnalytics({ timeZone, now, qualifyProviders: !provider, from: selection.filters.from, to: selection.filters.to }), models = new Set();
|
|
87
|
+
let warned = false, modelsTruncated = false;
|
|
88
|
+
const summary = await summarizeUsageLogs(filePath, { provider, onRecord: analytics.record, recordFilter: record => {
|
|
89
|
+
const label = provider ? record.model || "unknown" : `${usageProvider(record)} / ${record.model || "unknown"}`;
|
|
90
|
+
if (models.size < 100) models.add(label);else if (!models.has(label)) modelsTruncated = true;
|
|
91
|
+
return selection.matches(record);
|
|
92
|
+
},
|
|
83
93
|
warn(message) { warned = true;warn(message); } });
|
|
84
|
-
const
|
|
94
|
+
const snapshot = analytics.snapshot();
|
|
95
|
+
const result = { summary, analytics: { ...snapshot, models: [...models].sort(), models_truncated: snapshot.models_truncated || modelsTruncated }, filters: selection.filters };
|
|
85
96
|
const complete = version && await completeLines(file);
|
|
86
97
|
const after = version ? await usageSummaryVersion(file, { settled: false }) : null;
|
|
87
98
|
const bytes = Buffer.byteLength(JSON.stringify(result));
|
|
88
99
|
if (version && complete && after === version && !warned && !result.analytics.undated_records && bytes <= MAX_BYTES) {
|
|
89
|
-
cache.set(query, { file, version, summary, analytics, bytes, pending: [], pendingBytes: 0 });observe();prune();
|
|
100
|
+
cache.set(query, { file, version, summary, analytics, models, modelsTruncated, bytes, pending: [], pendingBytes: 0 });observe();prune();
|
|
90
101
|
}
|
|
91
102
|
return result;
|
|
92
103
|
};
|
package/src/usage-analytics.mjs
CHANGED
|
@@ -5,14 +5,15 @@ const DAYS = 365;
|
|
|
5
5
|
const MAX_MODELS = 100;
|
|
6
6
|
const TOKEN_FIELDS = ["input_tokens", "output_tokens", "total_tokens", "cached_input_tokens", "cache_read_input_tokens", "cache_write_input_tokens", "cache_hit_unknown_requests", "cache_hit_invalid_requests", "cache_hit_known_requests", "cache_hit_input_tokens", "cache_hit_read_tokens"];
|
|
7
7
|
|
|
8
|
-
export function createUsageAnalytics({ timeZone = "UTC", now = Date.now(), qualifyProviders = false } = {}) {
|
|
8
|
+
export function createUsageAnalytics({ timeZone = "UTC", now = Date.now(), qualifyProviders = false, from: rangeFrom = "", to: rangeTo = "" } = {}) {
|
|
9
9
|
const formatter = new Intl.DateTimeFormat("sv-SE", { timeZone, year: "numeric", month: "2-digit", day: "2-digit" });
|
|
10
|
-
const today = formatter.format(new Date(now));
|
|
10
|
+
const today = rangeTo || formatter.format(new Date(now));
|
|
11
11
|
const end = Date.parse(`${today}T00:00:00Z`);
|
|
12
|
-
const start = end - (DAYS - 1) * DAY_MS;
|
|
12
|
+
const start = Math.max(end - (DAYS - 1) * DAY_MS, rangeFrom ? Date.parse(rangeFrom) : -Infinity);
|
|
13
13
|
const from = new Date(start).toISOString().slice(0, 10);
|
|
14
14
|
const dates = new Map();
|
|
15
15
|
const models = new Set();
|
|
16
|
+
const earlier = { requests: 0, byModel: new Map() };
|
|
16
17
|
let first = Infinity;
|
|
17
18
|
let last = -Infinity;
|
|
18
19
|
let undated = 0;
|
|
@@ -38,6 +39,7 @@ export function createUsageAnalytics({ timeZone = "UTC", now = Date.now(), quali
|
|
|
38
39
|
cache_hit_rate: usageCacheHitRate(values),
|
|
39
40
|
cache_hit_known_requests: values.cache_hit_known_requests || 0,
|
|
40
41
|
cache_hit_unknown_requests: values.cache_hit_unknown_requests || 0,
|
|
42
|
+
cache_hit_invalid_requests: values.cache_hit_invalid_requests || 0,
|
|
41
43
|
cache_hit_input_tokens: values.cache_hit_input_tokens ?? null,
|
|
42
44
|
cache_hit_read_tokens: values.cache_hit_read_tokens ?? null,
|
|
43
45
|
cache_hit_rate_partial: values.cache_hit_unknown_requests > 0,
|
|
@@ -52,10 +54,9 @@ export function createUsageAnalytics({ timeZone = "UTC", now = Date.now(), quali
|
|
|
52
54
|
if (!Number.isFinite(timestamp) || timestamp > now) { undated += 1; return; }
|
|
53
55
|
first = Math.min(first, timestamp);
|
|
54
56
|
last = Math.max(last, timestamp);
|
|
55
|
-
if (timestamp < start - 2 * DAY_MS) return;
|
|
56
57
|
const date = formatter.format(new Date(timestamp));
|
|
57
|
-
if (date
|
|
58
|
-
let point = dates.get(date);
|
|
58
|
+
if (date > today) return;
|
|
59
|
+
let point = date < from ? earlier : dates.get(date);
|
|
59
60
|
if (!point) { point = { requests: 0, byModel: new Map() }; dates.set(date, point); }
|
|
60
61
|
add(point, summary.totals);
|
|
61
62
|
const model = String(qualifyProviders ? `${usageProvider(record)} / ${record.model || "unknown"}` : record.model || "unknown").replace(/[\u0000-\u001f\u007f-\u009f]/g, " ").slice(0, 100);
|
|
@@ -66,7 +67,7 @@ export function createUsageAnalytics({ timeZone = "UTC", now = Date.now(), quali
|
|
|
66
67
|
},
|
|
67
68
|
snapshot() {
|
|
68
69
|
const firstDate = Number.isFinite(first) ? formatter.format(new Date(first)) : null;
|
|
69
|
-
const days = Array.from({ length:
|
|
70
|
+
const days = Array.from({ length: Math.floor((end - start) / DAY_MS) + 1 }, (_, index) => {
|
|
70
71
|
const date = new Date(start + index * DAY_MS).toISOString().slice(0, 10);
|
|
71
72
|
const point = dates.get(date);
|
|
72
73
|
return {
|
|
@@ -77,6 +78,7 @@ export function createUsageAnalytics({ timeZone = "UTC", now = Date.now(), quali
|
|
|
77
78
|
};
|
|
78
79
|
});
|
|
79
80
|
return { time_zone: formatter.resolvedOptions().timeZone, from, to: today, first_date: firstDate,
|
|
81
|
+
...(earlier.requests ? { earlier: { date: "earlier", before: from, available: true, ...row(earlier), models: [...earlier.byModel].map(([model, values]) => ({ model, ...row(values) })) } } : {}),
|
|
80
82
|
last_date: Number.isFinite(last) ? formatter.format(new Date(last)) : null,
|
|
81
83
|
undated_records: undated, models_truncated: modelsTruncated, models: [...models].sort(), days };
|
|
82
84
|
},
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { isProviderId } from "./provider-metadata.mjs";
|
|
2
|
+
import { usageProvider } from "./usage-store.mjs";
|
|
3
|
+
|
|
4
|
+
const DAY_MS = 86400000;
|
|
5
|
+
const dateValue = value => /^\d{4}-\d{2}-\d{2}$/.test(value) && Number.isFinite(Date.parse(value))
|
|
6
|
+
&& new Date(value).toISOString().slice(0, 10) === value;
|
|
7
|
+
|
|
8
|
+
export function createUsageQuery({ provider = "", model = "", days = "all", from = "", to = "", timeZone = "UTC", now = Date.now() } = {}) {
|
|
9
|
+
if (typeof provider !== "string" || provider && !isProviderId(provider)) throw new Error("Select a valid usage source");
|
|
10
|
+
if (typeof model !== "string" || model.length > 200 || /[\u0000-\u001f\u007f]/.test(model)) throw new Error("Select a valid usage model");
|
|
11
|
+
if (String(days) !== "all" && (!/^\d+$/.test(String(days)) || Number(days) < 1 || Number(days) > 365)) throw new Error("Usage days must be all or an integer from 1 to 365");
|
|
12
|
+
if (typeof timeZone !== "string" || timeZone.length > 100) throw new Error("Select a valid usage time zone");
|
|
13
|
+
const zone = new Intl.DateTimeFormat("sv-SE", { timeZone, year: "numeric", month: "2-digit", day: "2-digit" });
|
|
14
|
+
const today = zone.format(new Date(now));
|
|
15
|
+
if (typeof from !== "string" || typeof to !== "string" || (from && !dateValue(from)) || (to && !dateValue(to))) throw new Error("Usage dates must use YYYY-MM-DD");
|
|
16
|
+
if ((from || to) && String(days) !== "all") throw new Error("Choose usage days or explicit dates");
|
|
17
|
+
if (String(days) !== "all") {
|
|
18
|
+
to = today;from = new Date(Date.parse(today) - (Number(days) - 1) * DAY_MS).toISOString().slice(0, 10);
|
|
19
|
+
}
|
|
20
|
+
if (from && !to) to = today;
|
|
21
|
+
if (from && to && from > to) throw new Error("Usage start date must not follow its end date");
|
|
22
|
+
const filters = { provider, model, days: String(days), from, to, time_zone: zone.resolvedOptions().timeZone };
|
|
23
|
+
return {
|
|
24
|
+
filters,
|
|
25
|
+
key: JSON.stringify(filters),
|
|
26
|
+
matches(record) {
|
|
27
|
+
if (provider && usageProvider(record) !== provider) return false;
|
|
28
|
+
if (model && model !== record.model && model !== `${usageProvider(record)} / ${record.model || "unknown"}`) return false;
|
|
29
|
+
if (!from && !to) return true;
|
|
30
|
+
const stamp = typeof record.ts === "string" ? Date.parse(record.ts) : NaN;
|
|
31
|
+
if (!Number.isFinite(stamp) || stamp > now) return false;
|
|
32
|
+
const date = zone.format(new Date(stamp));
|
|
33
|
+
return (!from || date >= from) && (!to || date <= to);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
package/src/usage-store.mjs
CHANGED
|
@@ -358,11 +358,12 @@ export function summarizeUsage(records, { provider = "" } = {}) {
|
|
|
358
358
|
return summary;
|
|
359
359
|
}
|
|
360
360
|
|
|
361
|
-
async function summarizeUsageLogFiles(filePath, { warn = console.error, onRecord, provider = "" } = {}) {
|
|
361
|
+
async function summarizeUsageLogFiles(filePath, { warn = console.error, onRecord, recordFilter, provider = "" } = {}) {
|
|
362
362
|
const summary = summarizeUsage([], { provider });
|
|
363
363
|
for (const candidate of [rotatedFilePath(filePath), filePath]) {
|
|
364
364
|
for await (const record of iterateUsageRecords(candidate, { warn })) {
|
|
365
365
|
if (provider && provider !== usageProvider(record)) continue;
|
|
366
|
+
if (recordFilter && !recordFilter(record)) continue;
|
|
366
367
|
const one = summarizeUsage([record]);
|
|
367
368
|
onRecord?.(record, one);
|
|
368
369
|
mergeUsageSummary(summary, one);
|
|
@@ -403,9 +404,9 @@ export async function usageSummaryVersion(filePath, { settled = true } = {}) {
|
|
|
403
404
|
} catch { return null; } // Uncacheable metadata never replaces the normal read/error path.
|
|
404
405
|
}
|
|
405
406
|
|
|
406
|
-
export async function summarizeUsageLogs(filePath = usageLogPath(), { warn = console.error, onRecord, provider = "", signal } = {}) {
|
|
407
|
+
export async function summarizeUsageLogs(filePath = usageLogPath(), { warn = console.error, onRecord, recordFilter, provider = "", signal } = {}) {
|
|
407
408
|
if (provider && !isProviderId(provider)) throw new Error("Usage provider must be a valid provider ID");
|
|
408
|
-
if (onRecord || warn !== console.error) return summarizeUsageLogFiles(filePath, { warn, onRecord, provider });
|
|
409
|
+
if (onRecord || recordFilter || warn !== console.error) return summarizeUsageLogFiles(filePath, { warn, onRecord, recordFilter, provider });
|
|
409
410
|
const fileVersion = await usageSummaryVersion(filePath);
|
|
410
411
|
const version = fileVersion === null ? null : `${fileVersion}\0${provider}`;
|
|
411
412
|
if (version === null) {
|
package/src/usage.mjs
CHANGED
|
@@ -40,10 +40,14 @@ function cacheHitPercent(usage) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
function providerSummaryLines(summary) {
|
|
43
|
-
|
|
43
|
+
const filter = summary.filters, selection = filter ? [
|
|
44
|
+
...(filter.model ? [`Model: ${terminalCell(filter.model)}`] : []),
|
|
45
|
+
...(filter.from || filter.to ? [`Dates: ${filter.from || "earliest"} to ${filter.to || "latest"} (${terminalCell(filter.time_zone)})`] : []),
|
|
46
|
+
] : [];
|
|
47
|
+
if (summary.provider_filter) return [`Provider: ${terminalCell(summary.provider_filter)}`, ...selection];
|
|
44
48
|
const sources = Object.entries(summary.providers || {}).filter(([, count]) => count > 0);
|
|
45
|
-
return sources.some(([id]) => id !== "github")
|
|
46
|
-
? [`Providers: ${sources.map(([id, count]) => `${terminalCell(id)} ${fmt(count)}`).join(" / ")} (combined totals; use --provider to separate)`] : [];
|
|
49
|
+
return [...(sources.some(([id]) => id !== "github")
|
|
50
|
+
? [`Providers: ${sources.map(([id, count]) => `${terminalCell(id)} ${fmt(count)}`).join(" / ")} (combined totals; use --provider to separate)`] : []), ...selection];
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
function formatPlainUsageSummary(summary, filePath, { sanitize = false } = {}) {
|