mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
feat(panel): upgrade consumption rankings, pointer-following breakdown popovers, full session search, sortable steps, and settings backup
This commit is contained in:
@@ -550,6 +550,104 @@ function extractOfflineUserTitle(rawContent) {
|
||||
return firstLine.length > 48 ? `${firstLine.slice(0, 47)}…` : firstLine;
|
||||
}
|
||||
|
||||
const MAX_TITLE_PROBE_CACHE = 2000;
|
||||
const titleProbeCache = new Map();
|
||||
|
||||
function isMeaningfulTitle(rawTitle, cidLower = '') {
|
||||
const clean = String(rawTitle || '').trim();
|
||||
if (!clean) return false;
|
||||
const low = clean.toLowerCase();
|
||||
if (cidLower && (low === cidLower || low === cidLower.slice(0, 8))) return false;
|
||||
if (UUID_RE.test(clean)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function pickFirstMeaningfulTitle(cidLower, candidates = []) {
|
||||
for (const cand of candidates) {
|
||||
if (isMeaningfulTitle(cand, cidLower)) {
|
||||
return String(cand).trim();
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function extractFirstStepTurnTitle(steps) {
|
||||
if (!Array.isArray(steps) || steps.length === 0) return '';
|
||||
for (let i = 0; i < steps.length; i++) {
|
||||
const st = steps[i];
|
||||
if (!st) continue;
|
||||
const raw = st.turnPromptClean || st.turnPrompt || '';
|
||||
if (!raw) continue;
|
||||
const title = extractOfflineUserTitle(raw);
|
||||
if (title) return title;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function readLocalTranscriptHeadTitle(cidLower) {
|
||||
if (!cidLower || !UUID_RE.test(cidLower)) return '';
|
||||
const transcriptPath = findTranscriptPath(cidLower);
|
||||
if (!transcriptPath || !existsSync(transcriptPath)) return '';
|
||||
try {
|
||||
const fd = openSync(transcriptPath, 'r');
|
||||
let chunk = '';
|
||||
try {
|
||||
const buf = Buffer.allocUnsafe(32768);
|
||||
const bytesRead = readSync(fd, buf, 0, buf.length, 0);
|
||||
if (bytesRead > 0) chunk = buf.toString('utf8', 0, bytesRead);
|
||||
} finally {
|
||||
closeSync(fd);
|
||||
}
|
||||
if (!chunk) return '';
|
||||
for (const rawLine of chunk.split(/\r?\n/)) {
|
||||
const trimmed = rawLine.trim();
|
||||
if (!trimmed || !trimmed.startsWith('{')) continue;
|
||||
let parsed = null;
|
||||
try {
|
||||
parsed = JSON.parse(trimmed);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
const upperType = String(parsed?.type || '').toUpperCase();
|
||||
if (
|
||||
upperType === 'USER_INPUT' ||
|
||||
upperType === 'CORTEX_STEP_TYPE_USER_INPUT' ||
|
||||
(parsed?.userInput && typeof parsed.userInput === 'object')
|
||||
) {
|
||||
const title = extractOfflineUserTitle(
|
||||
typeof parsed.content === 'string'
|
||||
? parsed.content
|
||||
: parsed.userInput?.userResponse || ''
|
||||
);
|
||||
if (title) return title;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// 忽略单文件头部读取异常
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function probeLocalFallbackTitle(cidLower, mtimeSig = 0) {
|
||||
if (!cidLower) return '';
|
||||
const sig = Number(mtimeSig) || 0;
|
||||
const cached = titleProbeCache.get(cidLower);
|
||||
if (cached && cached.sig === sig) {
|
||||
return cached.title;
|
||||
}
|
||||
const annTitle = readAnnotationTitleForCascade(cidLower);
|
||||
const resolved = isMeaningfulTitle(annTitle, cidLower)
|
||||
? String(annTitle).trim()
|
||||
: readLocalTranscriptHeadTitle(cidLower);
|
||||
const finalTitle = isMeaningfulTitle(resolved, cidLower) ? String(resolved).trim() : '';
|
||||
if (titleProbeCache.size >= MAX_TITLE_PROBE_CACHE && !titleProbeCache.has(cidLower)) {
|
||||
const oldestKey = titleProbeCache.keys().next().value;
|
||||
if (oldestKey !== undefined) titleProbeCache.delete(oldestKey);
|
||||
}
|
||||
titleProbeCache.set(cidLower, { sig, title: finalTitle });
|
||||
return finalTitle;
|
||||
}
|
||||
|
||||
function hasLocalSqliteDb(diskFiles = []) {
|
||||
return Array.isArray(diskFiles) && diskFiles.some((f) => /\.db$/i.test(String(f || '')));
|
||||
}
|
||||
@@ -1519,7 +1617,7 @@ export async function enumerateAndSyncConversations({
|
||||
const rawConversations = [];
|
||||
for (const [cidLower, cascadeId] of canonicalIdByLower.entries()) {
|
||||
const item = summariesByLower.get(cidLower);
|
||||
const localSum = item ? null : localSummaryByLower.get(cidLower) || null;
|
||||
const localSum = localSummaryByLower.get(cidLower) || null;
|
||||
const cached = getEntry(cascadeId);
|
||||
const diskFiles = diskConvMap.get(cidLower) || [];
|
||||
const sqliteDbInfo = sqliteAvailable ? resolveBestSqliteDbInfo(diskFiles) : null;
|
||||
@@ -1621,11 +1719,13 @@ export async function enumerateAndSyncConversations({
|
||||
rawConversations.push({
|
||||
cascadeId,
|
||||
title:
|
||||
sqParentInfo?.title ||
|
||||
item?.annotations?.title ||
|
||||
item?.summary ||
|
||||
cached?.title ||
|
||||
(isSideQuestion ? '旁路提问' : cascadeId.slice(0, 8)),
|
||||
pickFirstMeaningfulTitle(cidLower, [
|
||||
sqParentInfo?.title,
|
||||
item?.annotations?.title,
|
||||
item?.summary,
|
||||
localSum?.title,
|
||||
cached?.title,
|
||||
]) || (isSideQuestion ? '旁路提问' : cascadeId.slice(0, 8)),
|
||||
stepCount: modelStepCount,
|
||||
rawStepCount: rawSummaryStepCount,
|
||||
status: isKilled ? 'IDLE' : item?.status || '',
|
||||
@@ -1653,10 +1753,11 @@ export async function enumerateAndSyncConversations({
|
||||
rawConversations.push({
|
||||
cascadeId,
|
||||
title:
|
||||
sqParentInfo?.title ||
|
||||
localSum?.title ||
|
||||
cached.title ||
|
||||
(isSideQuestion ? '旁路提问' : cascadeId.slice(0, 8)),
|
||||
pickFirstMeaningfulTitle(cidLower, [
|
||||
sqParentInfo?.title,
|
||||
localSum?.title,
|
||||
cached.title,
|
||||
]) || (isSideQuestion ? '旁路提问' : cascadeId.slice(0, 8)),
|
||||
stepCount: cachedStepCount,
|
||||
rawStepCount: localSum?.stepCount || cached.rawStepCount || cachedStepCount,
|
||||
status: localStatus,
|
||||
@@ -1687,9 +1788,10 @@ export async function enumerateAndSyncConversations({
|
||||
rawConversations.push({
|
||||
cascadeId,
|
||||
title:
|
||||
sqParentInfo?.title ||
|
||||
localSum?.title ||
|
||||
(isSideQuestion ? '旁路提问' : cascadeId.slice(0, 8)),
|
||||
pickFirstMeaningfulTitle(cidLower, [
|
||||
sqParentInfo?.title,
|
||||
localSum?.title,
|
||||
]) || (isSideQuestion ? '旁路提问' : cascadeId.slice(0, 8)),
|
||||
stepCount: 0,
|
||||
rawStepCount: localSum?.stepCount || 0,
|
||||
status: localStatus,
|
||||
@@ -2628,6 +2730,7 @@ export async function enumerateAndSyncConversations({
|
||||
}
|
||||
}
|
||||
|
||||
let titleBackfillDirty = false;
|
||||
for (const rootConv of conversations) {
|
||||
const cid = rootConv.cascadeId.toLowerCase();
|
||||
const rootCached = getEntry(rootConv.cascadeId);
|
||||
@@ -2635,11 +2738,32 @@ export async function enumerateAndSyncConversations({
|
||||
const swarmTitle = String(swarmManifest?.title || rootCached?.swarmMeta?.title || '').trim();
|
||||
if (swarmTitle) {
|
||||
rootConv.swarmTitle = swarmTitle;
|
||||
const curTitle = String(rootConv.title || '').trim();
|
||||
if (!curTitle || curTitle.toLowerCase() === cid.slice(0, 8)) {
|
||||
if (!isMeaningfulTitle(rootConv.title, cid)) {
|
||||
rootConv.title = swarmTitle;
|
||||
}
|
||||
}
|
||||
if (!isMeaningfulTitle(rootConv.title, cid)) {
|
||||
const localSumTitle = localSummaryByLower.get(cid)?.title || '';
|
||||
const stepTurnTitle = extractFirstStepTurnTitle(rootCached?.steps);
|
||||
let recoveredTitle = pickFirstMeaningfulTitle(cid, [
|
||||
localSumTitle,
|
||||
rootCached?.title,
|
||||
stepTurnTitle,
|
||||
]);
|
||||
if (!recoveredTitle && !isRemote) {
|
||||
recoveredTitle = probeLocalFallbackTitle(
|
||||
cid,
|
||||
rootConv.diskMtimeMs || rootConv.lastModifiedMs || 0
|
||||
);
|
||||
}
|
||||
if (recoveredTitle) {
|
||||
rootConv.title = recoveredTitle;
|
||||
if (rootCached && rootCached.title !== recoveredTitle) {
|
||||
setEntry(rootConv.cascadeId, { ...rootCached, title: recoveredTitle });
|
||||
titleBackfillDirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (swarmManifest?.coordinator?.killed || rootConv.killed) {
|
||||
rootConv.status = 'IDLE';
|
||||
rootConv.liveActivity = null;
|
||||
@@ -2760,6 +2884,13 @@ export async function enumerateAndSyncConversations({
|
||||
rootConv.groupLastModifiedMs = Math.max(rootConv.lastModifiedMs || 0, maxSubModMs);
|
||||
}
|
||||
|
||||
if (titleBackfillDirty) {
|
||||
const hasRunningSessions = rawConversations.some(
|
||||
(c) => c.status === 'CASCADE_RUN_STATUS_RUNNING'
|
||||
);
|
||||
persistCacheIfNeeded({ hasRunningSessions });
|
||||
}
|
||||
|
||||
conversations.sort(
|
||||
(a, b) =>
|
||||
(b.groupLastModifiedMs || b.lastModifiedMs || 0) -
|
||||
|
||||
@@ -55,7 +55,7 @@ import {
|
||||
getNextMondayResetIso,
|
||||
} from './usage-aggregator.mjs';
|
||||
|
||||
const MAX_RECENT_CONVERSATIONS = 30;
|
||||
const MAX_RECENT_QUICK_STATS = 30;
|
||||
const MAX_CONVERSATION_ASSEMBLY_CACHE = 8;
|
||||
const MAX_TELEMETRY_SNAPSHOT_ENDPOINTS = 8;
|
||||
const POOL_PRIORITY_ORDER = ['Gemini', 'Argon', 'Carbon', 'Claude & GPT'];
|
||||
@@ -1659,6 +1659,7 @@ export async function buildTelemetryPayloadInternal(
|
||||
weekBucket,
|
||||
quotaWeekBucket,
|
||||
modelBreakdown,
|
||||
topConversations,
|
||||
poolCycleStats,
|
||||
poolsWeeklySummary,
|
||||
} = aggregateMultiWindowUsage({
|
||||
@@ -2091,10 +2092,16 @@ export async function buildTelemetryPayloadInternal(
|
||||
totalConversations: conversations.length,
|
||||
},
|
||||
runningConversations,
|
||||
conversations: conversations.slice(0, MAX_RECENT_CONVERSATIONS).map((c) => {
|
||||
const qStats = getConversationQuickStats(c);
|
||||
conversations: conversations.map((c, idx) => {
|
||||
const rawSubs = Array.isArray(c.subagents) ? c.subagents : [];
|
||||
const runningSubCount = rawSubs.filter((s) => s.status === 'CASCADE_RUN_STATUS_RUNNING').length;
|
||||
const isConvRunning = c.status === 'CASCADE_RUN_STATUS_RUNNING' || runningSubCount > 0;
|
||||
const includeQuickStats =
|
||||
idx < MAX_RECENT_QUICK_STATS ||
|
||||
isConvRunning ||
|
||||
(Boolean(activeCascadeId) &&
|
||||
String(c.cascadeId || '').toLowerCase() === String(activeCascadeId).toLowerCase());
|
||||
const qStats = includeQuickStats ? getConversationQuickStats(c) : null;
|
||||
const cSwarmCount = Number(c.swarmCount ?? rawSubs.filter((s) => s.isSwarmWorker).length);
|
||||
const cSideCount = rawSubs.filter((s) => s.isSideQuestion).length;
|
||||
const cNormalSubCount = Math.max(0, rawSubs.length - cSwarmCount - cSideCount);
|
||||
@@ -2110,16 +2117,20 @@ export async function buildTelemetryPayloadInternal(
|
||||
runningSubagentCount: runningSubCount,
|
||||
totalStepCount: c.totalStepCount || c.stepCount || 0,
|
||||
...(rawSubs.length > 0 ? { memberCascadeIds: rawSubs.map((s) => s.cascadeId) } : {}),
|
||||
isRunning: c.status === 'CASCADE_RUN_STATUS_RUNNING' || runningSubCount > 0,
|
||||
isRunning: isConvRunning,
|
||||
status: c.status,
|
||||
lastModifiedTime: c.lastModifiedTime,
|
||||
lastModifiedMs: c.groupLastModifiedMs || c.lastModifiedMs,
|
||||
modelShort: qStats.modelShort,
|
||||
modelUpstream: qStats.modelUpstream,
|
||||
latestTokPerSec: qStats.latestTokPerSec,
|
||||
contextUsedPct: qStats.contextUsedPct,
|
||||
sessionCostUsd: qStats.sessionCostUsd,
|
||||
sessionUnpricedCalls: qStats.sessionUnpricedCalls,
|
||||
...(qStats
|
||||
? {
|
||||
modelShort: qStats.modelShort,
|
||||
modelUpstream: qStats.modelUpstream,
|
||||
latestTokPerSec: qStats.latestTokPerSec,
|
||||
contextUsedPct: qStats.contextUsedPct,
|
||||
sessionCostUsd: qStats.sessionCostUsd,
|
||||
sessionUnpricedCalls: qStats.sessionUnpricedCalls,
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}),
|
||||
activeConversation: assembledActiveConversation,
|
||||
@@ -2136,6 +2147,7 @@ export async function buildTelemetryPayloadInternal(
|
||||
presets: finalizedPresets,
|
||||
trendSeries,
|
||||
sourcesBreakdown,
|
||||
topConversations: enrichTopConversationTitles(topConversations, conversations),
|
||||
monthlyYear: currentYear,
|
||||
monthlySeries,
|
||||
},
|
||||
@@ -2355,6 +2367,40 @@ function tryBuildFastConversationPayload(requestedConvId, filterOpts = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
function enrichTopConversationTitles(topList, convSummaries) {
|
||||
if (!Array.isArray(topList) || topList.length === 0) return [];
|
||||
const titleMap = new Map();
|
||||
if (Array.isArray(convSummaries)) {
|
||||
for (const c of convSummaries) {
|
||||
const cid = String(c?.cascadeId || '').toLowerCase();
|
||||
const title = String(c?.title || '').trim();
|
||||
if (cid && title && !titleMap.has(cid)) {
|
||||
titleMap.set(cid, title);
|
||||
}
|
||||
if (Array.isArray(c?.subagents)) {
|
||||
for (const sub of c.subagents) {
|
||||
const sid = String(sub?.cascadeId || '').toLowerCase();
|
||||
if (sid && title && !titleMap.has(sid)) {
|
||||
titleMap.set(sid, title);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return topList.map((item) => {
|
||||
if (!item || typeof item !== 'object') return item;
|
||||
const cidLower = String(item.cascadeId || '').toLowerCase();
|
||||
const fallbackTitle = titleMap.get(cidLower) || '';
|
||||
const existingTitle = String(item.title || '').trim();
|
||||
const resolvedTitle = existingTitle || fallbackTitle || (item.cascadeId ? item.cascadeId.slice(0, 8) : '—');
|
||||
return {
|
||||
...item,
|
||||
title: resolvedTitle,
|
||||
canJump: titleMap.has(cidLower),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function tryBuildFastConsumptionPayload(filterOpts = {}) {
|
||||
const endpoint = filterOpts?.endpoint && filterOpts.endpoint.isRemote ? filterOpts.endpoint : null;
|
||||
const snap = resolveValidFastSnapshot(endpoint);
|
||||
@@ -2382,6 +2428,10 @@ function tryBuildFastConsumptionPayload(filterOpts = {}) {
|
||||
account: agg.finalizedSelectedAccount,
|
||||
trendSeries: agg.trendSeries,
|
||||
sourcesBreakdown: agg.sourcesBreakdown,
|
||||
topConversations: enrichTopConversationTitles(
|
||||
agg.topConversations,
|
||||
snap.sessions?.conversations
|
||||
),
|
||||
},
|
||||
modelBreakdown: agg.modelBreakdown,
|
||||
};
|
||||
@@ -2395,13 +2445,23 @@ function tryBuildConsumptionPresetsPayload(filterOpts = {}) {
|
||||
...snap.aggContext,
|
||||
endpoint,
|
||||
});
|
||||
const enrichedRanges = {};
|
||||
for (const [rangeKey, entry] of Object.entries(bundle.ranges || {})) {
|
||||
enrichedRanges[rangeKey] = {
|
||||
...entry,
|
||||
topConversations: enrichTopConversationTitles(
|
||||
entry?.topConversations,
|
||||
snap.sessions?.conversations
|
||||
),
|
||||
};
|
||||
}
|
||||
return {
|
||||
scope: 'consumption-presets',
|
||||
timestamp: new Date().toISOString(),
|
||||
endpoint: snap.basePayload.endpoint,
|
||||
uiBundleVersion: snap.basePayload.uiBundleVersion || computeRuntimeCodeVersion(),
|
||||
usageRevision: bundle.usageRevision,
|
||||
ranges: bundle.ranges,
|
||||
ranges: enrichedRanges,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -532,8 +532,13 @@ function collectUsageEntriesToAggregate(familySet, endpoint = null) {
|
||||
const groupCascadeId = String(
|
||||
entry?.rootConversationId || entry?.parentConversationId || cidLower
|
||||
).toLowerCase();
|
||||
const rootLive = allLiveByLower.get(groupCascadeId);
|
||||
const entryTitle = String(
|
||||
rootLive?.title || entry?.title || extMatch?.title || ''
|
||||
).trim();
|
||||
allEntriesToAggregate.push({
|
||||
cascadeId: groupCascadeId,
|
||||
title: entryTitle,
|
||||
appSource: isRemote ? 'ssh' : entry?.appSource || 'standalone',
|
||||
accountName: entry?.accountName || extMatch?.accountName || '',
|
||||
steps: entry?.steps || [],
|
||||
@@ -548,6 +553,7 @@ function collectUsageEntriesToAggregate(familySet, endpoint = null) {
|
||||
}
|
||||
allEntriesToAggregate.push({
|
||||
cascadeId: extCidLower,
|
||||
title: String(ext.title || liveEntry?.title || '').trim(),
|
||||
appSource: ext.appSource || 'ide',
|
||||
accountName: ext.accountName || liveEntry?.accountName || '',
|
||||
steps: ext.steps || [],
|
||||
@@ -558,6 +564,87 @@ function collectUsageEntriesToAggregate(familySet, endpoint = null) {
|
||||
return allEntriesToAggregate;
|
||||
}
|
||||
|
||||
const MAX_TOP_CONVERSATIONS_LIMIT = 10;
|
||||
|
||||
function accumulateStepIntoConversationMap(
|
||||
perConvMap,
|
||||
entry,
|
||||
srcKey,
|
||||
srcName,
|
||||
stepUsage,
|
||||
tMs,
|
||||
st = null,
|
||||
mInfo = null,
|
||||
stepCost = null
|
||||
) {
|
||||
const cid = String(entry?.cascadeId || '').trim();
|
||||
if (!cid) return;
|
||||
let acc = perConvMap.get(cid);
|
||||
if (!acc) {
|
||||
acc = {
|
||||
cascadeId: cid,
|
||||
title: String(entry?.title || '').trim(),
|
||||
appSource: srcKey,
|
||||
sourceName: srcName,
|
||||
calls: 0,
|
||||
inputTokens: 0,
|
||||
cacheReadTokens: 0,
|
||||
responseTokens: 0,
|
||||
thinkingTokens: 0,
|
||||
totalTokens: 0,
|
||||
costUsd: 0,
|
||||
unpricedCalls: 0,
|
||||
lastTimestampMs: 0,
|
||||
perModelStats: new Map(),
|
||||
};
|
||||
perConvMap.set(cid, acc);
|
||||
}
|
||||
if (!acc.title && entry?.title) {
|
||||
acc.title = String(entry.title).trim();
|
||||
}
|
||||
acc.calls += 1;
|
||||
acc.inputTokens += stepUsage.inTok;
|
||||
acc.cacheReadTokens += stepUsage.cacheTok;
|
||||
acc.responseTokens += stepUsage.respTok;
|
||||
acc.thinkingTokens += stepUsage.thinkTok;
|
||||
acc.totalTokens += stepUsage.stepTotalTokens;
|
||||
acc.costUsd += stepUsage.resolvedCost;
|
||||
acc.unpricedCalls += stepUsage.unpriced;
|
||||
if (tMs > acc.lastTimestampMs) {
|
||||
acc.lastTimestampMs = tMs;
|
||||
}
|
||||
if (st && mInfo) {
|
||||
accumulateStepIntoModelMap(acc.perModelStats, st, mInfo, stepCost);
|
||||
}
|
||||
}
|
||||
|
||||
function finalizeTopConversationsMap(perConvMap, maxItems = MAX_TOP_CONVERSATIONS_LIMIT) {
|
||||
return Array.from(perConvMap.values())
|
||||
.filter((c) => c.totalTokens > 0 || c.calls > 0)
|
||||
.sort((a, b) => b.costUsd - a.costUsd || b.totalTokens - a.totalTokens || b.calls - a.calls)
|
||||
.slice(0, maxItems)
|
||||
.map((c) => {
|
||||
const promptTokens = c.inputTokens + c.cacheReadTokens;
|
||||
return {
|
||||
cascadeId: c.cascadeId,
|
||||
title: c.title,
|
||||
appSource: c.appSource,
|
||||
sourceName: c.sourceName,
|
||||
calls: c.calls,
|
||||
inputTokens: c.inputTokens,
|
||||
cacheReadTokens: c.cacheReadTokens,
|
||||
responseTokens: c.responseTokens,
|
||||
thinkingTokens: c.thinkingTokens,
|
||||
totalTokens: c.totalTokens,
|
||||
costUsd: +c.costUsd.toFixed(6),
|
||||
unpricedCalls: c.unpricedCalls,
|
||||
cacheHitPct: promptTokens > 0 ? +((c.cacheReadTokens / promptTokens) * 100).toFixed(1) : 0,
|
||||
lastTimestampMs: c.lastTimestampMs,
|
||||
models: finalizeModelBreakdownMap(c.perModelStats),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function buildQuotaPoolCycleMap(quotaPoolsMap, nowMs) {
|
||||
const poolCycleBuckets = new Map();
|
||||
if (quotaPoolsMap instanceof Map && quotaPoolsMap.size > 0) {
|
||||
@@ -688,6 +775,8 @@ function buildUsageTrendSeries(
|
||||
inputTokens: 0,
|
||||
cacheReadTokens: 0,
|
||||
outputTokens: 0,
|
||||
thinkingTokens: 0,
|
||||
responseTokens: 0,
|
||||
costUsd: 0,
|
||||
unpricedCalls: 0,
|
||||
calls: 0,
|
||||
@@ -740,6 +829,8 @@ function buildUsageTrendSeries(
|
||||
inputTokens: 0,
|
||||
cacheReadTokens: 0,
|
||||
outputTokens: 0,
|
||||
thinkingTokens: 0,
|
||||
responseTokens: 0,
|
||||
costUsd: 0,
|
||||
unpricedCalls: 0,
|
||||
calls: 0,
|
||||
@@ -781,6 +872,8 @@ function buildUsageTrendSeries(
|
||||
bucket.inputTokens += item.inputTokens || 0;
|
||||
bucket.cacheReadTokens += item.cacheReadTokens || 0;
|
||||
bucket.outputTokens += item.outputTokens || 0;
|
||||
bucket.thinkingTokens += item.thinkingTokens || 0;
|
||||
bucket.responseTokens += item.responseTokens || 0;
|
||||
bucket.costUsd += item.costUsd;
|
||||
bucket.unpricedCalls = (bucket.unpricedCalls || 0) + item.unpricedCalls;
|
||||
bucket.calls += 1;
|
||||
@@ -801,6 +894,11 @@ function buildUsageTrendSeries(
|
||||
upstreamModelCounts: new Map(),
|
||||
family: mInfo.family,
|
||||
calls: 0,
|
||||
inputTokens: 0,
|
||||
cacheReadTokens: 0,
|
||||
outputTokens: 0,
|
||||
thinkingTokens: 0,
|
||||
responseTokens: 0,
|
||||
totalTokens: 0,
|
||||
costUsd: 0,
|
||||
unpricedCalls: 0,
|
||||
@@ -815,6 +913,11 @@ function buildUsageTrendSeries(
|
||||
);
|
||||
}
|
||||
bModel.calls += 1;
|
||||
bModel.inputTokens += item.inputTokens || 0;
|
||||
bModel.cacheReadTokens += item.cacheReadTokens || 0;
|
||||
bModel.outputTokens += item.outputTokens || 0;
|
||||
bModel.thinkingTokens += item.thinkingTokens || 0;
|
||||
bModel.responseTokens += item.responseTokens || 0;
|
||||
bModel.totalTokens += item.tokens;
|
||||
bModel.costUsd += item.costUsd;
|
||||
bModel.unpricedCalls += item.unpricedCalls || 0;
|
||||
@@ -1150,6 +1253,7 @@ export function aggregateMultiWindowUsage({
|
||||
const selectedAccountBucket = accountBuckets[selectedWindow.key] || createUsageBucket();
|
||||
const selectedSessionBucket = sessionBuckets[selectedWindow.key] || createUsageBucket();
|
||||
const perModelStats = new Map();
|
||||
const perConvStats = new Map();
|
||||
const selectedWindowSteps = [];
|
||||
let earliestSelectedStepMs = Infinity;
|
||||
let latestSelectedStepMs = 0;
|
||||
@@ -1401,6 +1505,8 @@ export function aggregateMultiWindowUsage({
|
||||
inputTokens: inTok,
|
||||
cacheReadTokens: cacheTok,
|
||||
outputTokens: outTok,
|
||||
thinkingTokens: thinkTok,
|
||||
responseTokens: respTok,
|
||||
costUsd: resolvedCost,
|
||||
unpricedCalls: unpriced,
|
||||
mInfo,
|
||||
@@ -1433,6 +1539,17 @@ export function aggregateMultiWindowUsage({
|
||||
accumulateStepIntoModelMap(sAgg.perModelStats, st, mInfo, stepCost);
|
||||
|
||||
accumulateStepIntoModelMap(perModelStats, st, mInfo, stepCost);
|
||||
accumulateStepIntoConversationMap(
|
||||
perConvStats,
|
||||
entry,
|
||||
srcKey,
|
||||
srcName,
|
||||
stepUsage,
|
||||
tMs,
|
||||
st,
|
||||
mInfo,
|
||||
stepCost
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1489,6 +1606,7 @@ export function aggregateMultiWindowUsage({
|
||||
const weekBucket = finalizedPresets.week.account;
|
||||
const finalizedQuotaWeekBucket = finalizeUsageBucket(quotaWeekBucket);
|
||||
const modelBreakdown = finalizeModelBreakdownMap(perModelStats);
|
||||
const topConversations = finalizeTopConversationsMap(perConvStats);
|
||||
|
||||
const formatCycleSummary = (b) => {
|
||||
const fin = finalizeUsageBucket(b);
|
||||
@@ -1574,6 +1692,7 @@ export function aggregateMultiWindowUsage({
|
||||
weekBucket,
|
||||
quotaWeekBucket: finalizedQuotaWeekBucket,
|
||||
modelBreakdown,
|
||||
topConversations,
|
||||
poolCycleStats,
|
||||
poolsWeeklySummary,
|
||||
};
|
||||
@@ -1715,6 +1834,7 @@ export function aggregateSelectedWindowUsage({
|
||||
trendSeries: res.trendSeries,
|
||||
sourcesBreakdown: res.sourcesBreakdown,
|
||||
modelBreakdown: res.modelBreakdown,
|
||||
topConversations: res.topConversations || [],
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1755,6 +1875,7 @@ export function aggregateSelectedWindowUsage({
|
||||
const selectedSessionBucket = createUsageBucket();
|
||||
const perModelStats = new Map();
|
||||
const perSourceStats = new Map();
|
||||
const perConvStats = new Map();
|
||||
const selectedWindowSteps = [];
|
||||
let earliestSelectedStepMs = Infinity;
|
||||
let latestSelectedStepMs = 0;
|
||||
@@ -1878,6 +1999,8 @@ export function aggregateSelectedWindowUsage({
|
||||
inputTokens: inTok,
|
||||
cacheReadTokens: cacheTok,
|
||||
outputTokens: outTok,
|
||||
thinkingTokens: thinkTok,
|
||||
responseTokens: respTok,
|
||||
costUsd: resolvedCost,
|
||||
unpricedCalls: unpriced,
|
||||
mInfo,
|
||||
@@ -1910,6 +2033,17 @@ export function aggregateSelectedWindowUsage({
|
||||
accumulateStepIntoModelMap(sAgg.perModelStats, st, mInfo, stepCost);
|
||||
|
||||
accumulateStepIntoModelMap(perModelStats, st, mInfo, stepCost);
|
||||
accumulateStepIntoConversationMap(
|
||||
perConvStats,
|
||||
entry,
|
||||
srcKey,
|
||||
srcName,
|
||||
stepUsage,
|
||||
tMs,
|
||||
st,
|
||||
mInfo,
|
||||
stepCost
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1943,6 +2077,7 @@ export function aggregateSelectedWindowUsage({
|
||||
}))
|
||||
.sort((a, b) => b.totalTokens - a.totalTokens || b.calls - a.calls);
|
||||
const modelBreakdown = finalizeModelBreakdownMap(perModelStats);
|
||||
const topConversations = finalizeTopConversationsMap(perConvStats);
|
||||
|
||||
const sliceResult = {
|
||||
usageRevision: sameSnapshot ? snapshot.revision : usageSnapshotRevisionSeq,
|
||||
@@ -1954,6 +2089,7 @@ export function aggregateSelectedWindowUsage({
|
||||
trendSeries,
|
||||
sourcesBreakdown,
|
||||
modelBreakdown,
|
||||
topConversations,
|
||||
};
|
||||
|
||||
if (sameSnapshot) {
|
||||
@@ -2081,6 +2217,7 @@ export function aggregateConsumptionPresetBundle(params) {
|
||||
trendSeries: agg.trendSeries,
|
||||
sourcesBreakdown: agg.sourcesBreakdown,
|
||||
modelBreakdown: agg.modelBreakdown,
|
||||
topConversations: agg.topConversations || [],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user