mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
479 lines
13 KiB
JavaScript
479 lines
13 KiB
JavaScript
/**
|
|
* @fileoverview Realistic Simulated Telemetry Builder (`structurePreviewMock.js`)
|
|
* for `SettingsStructureTab` real-UI live previews.
|
|
* Exercises all 13 capsule metrics, 8 overview metrics, 10 context channels + subagents,
|
|
* multi-pool quotas, live running task + subagent, and 12 step table columns.
|
|
*/
|
|
|
|
import { t } from '../../i18n/index.js';
|
|
|
|
export function buildStructurePreviewTelemetry(baseSettings = {}, draftOverrides = {}) {
|
|
const anchorMinMs = Math.floor(Date.now() / 60000) * 60000;
|
|
const reset5hIso = new Date(anchorMinMs + (2 * 60 + 42) * 60000).toISOString();
|
|
const resetWkIso = new Date(anchorMinMs + (4 * 24 * 60 + 180) * 60000).toISOString();
|
|
const resetClaude5hIso = new Date(anchorMinMs + (1 * 60 + 18) * 60000).toISOString();
|
|
|
|
const mergedSettings = {
|
|
...(baseSettings && typeof baseSettings === 'object' ? baseSettings : {}),
|
|
...draftOverrides,
|
|
};
|
|
|
|
const sessionTitle = t('settings.mock.sessionTitle');
|
|
const subRole = t('settings.mock.subRole');
|
|
const promptLatest = t('settings.mock.turnPromptLatest');
|
|
const promptPrev = t('settings.mock.turnPromptPrev');
|
|
|
|
const mainContext = {
|
|
totalTokens: 142800,
|
|
limitTokens: 256000,
|
|
compactionLimitTokens: 256000,
|
|
compactionUsedTokens: 142800,
|
|
usedPct: 55.8,
|
|
messagesTokens: 119660,
|
|
toolResultsTokens: 86400,
|
|
assistantTokens: 24200,
|
|
systemToolsTokens: 11800,
|
|
checkpointTokens: 7600,
|
|
systemPromptTokens: 5800,
|
|
skillsTokens: 3100,
|
|
userRulesTokens: 1900,
|
|
userInputTokens: 1120,
|
|
mcpToolsTokens: 540,
|
|
subagentTokens: 340,
|
|
};
|
|
|
|
const subContext = {
|
|
totalTokens: 72704,
|
|
limitTokens: 256000,
|
|
compactionLimitTokens: 256000,
|
|
compactionUsedTokens: 72704,
|
|
usedPct: 28.4,
|
|
messagesTokens: 63704,
|
|
toolResultsTokens: 51200,
|
|
assistantTokens: 11400,
|
|
systemToolsTokens: 5600,
|
|
systemPromptTokens: 3400,
|
|
userInputTokens: 1104,
|
|
checkpointTokens: 0,
|
|
skillsTokens: 0,
|
|
userRulesTokens: 0,
|
|
mcpToolsTokens: 0,
|
|
subagentTokens: 0,
|
|
};
|
|
|
|
const mockSteps = [
|
|
{
|
|
stepIndex: 24,
|
|
agentCascadeId: 'mock-main',
|
|
agentId: 'main',
|
|
agentIndex: 0,
|
|
isSubagent: false,
|
|
agentBadge: '主',
|
|
agentLabel: t('fmt.mainAgent'),
|
|
modelLabel: 'Gemini 4 Carbon (High)',
|
|
modelShort: 'carbon-4-high',
|
|
rawModel: 'MODEL_PLACEHOLDER_M37',
|
|
modelUpstream: 'gemini-4-carbon-high',
|
|
upstreamModel: 'gemini-4-carbon-high',
|
|
tokPerSec: 68.4,
|
|
ttftSec: 1.15,
|
|
totalDurationSec: 12.6,
|
|
streamDurationSec: 11.45,
|
|
contextTokens: 142800,
|
|
inputTokens: 7800,
|
|
cacheReadTokens: 133580,
|
|
outputTokens: 1420,
|
|
thinkingTokens: 860,
|
|
responseTokens: 560,
|
|
cacheHitPct: 94.5,
|
|
costUsd: 0.042,
|
|
inCostUsd: 0.0156,
|
|
cacheCostUsd: 0.0134,
|
|
outCostUsd: 0.0142,
|
|
createdAtMs: anchorMinMs - 14_000,
|
|
turnIndex: 2,
|
|
rootTurnIndex: 2,
|
|
isTurnStart: false,
|
|
isRootTurnStart: false,
|
|
isLatestTurn: true,
|
|
isRootLatestTurn: true,
|
|
turnPrompt: promptLatest,
|
|
rootTurnPrompt: promptLatest,
|
|
},
|
|
{
|
|
stepIndex: 8,
|
|
agentCascadeId: 'mock-sub-1',
|
|
agentId: 'sub-1',
|
|
agentIndex: 1,
|
|
isSubagent: true,
|
|
agentBadge: '子1',
|
|
agentRole: subRole,
|
|
agentLabel: subRole,
|
|
modelLabel: 'Gemini 3.8 Flash',
|
|
modelShort: 'flash-3.8',
|
|
rawModel: 'MODEL_PLACEHOLDER_M42',
|
|
modelUpstream: 'gemini-3.8-flash-n',
|
|
upstreamModel: 'gemini-3.8-flash-n',
|
|
tokPerSec: 96.2,
|
|
ttftSec: 0.68,
|
|
totalDurationSec: 5.4,
|
|
streamDurationSec: 4.72,
|
|
contextTokens: 72704,
|
|
inputTokens: 8600,
|
|
cacheReadTokens: 63400,
|
|
outputTokens: 704,
|
|
thinkingTokens: 240,
|
|
responseTokens: 464,
|
|
cacheHitPct: 88.1,
|
|
costUsd: 0.009,
|
|
inCostUsd: 0.0065,
|
|
cacheCostUsd: 0.0005,
|
|
outCostUsd: 0.0026,
|
|
createdAtMs: anchorMinMs - 42_000,
|
|
turnIndex: 1,
|
|
rootTurnIndex: 2,
|
|
isTurnStart: true,
|
|
isRootTurnStart: false,
|
|
isLatestTurn: true,
|
|
isRootLatestTurn: true,
|
|
turnPrompt: promptLatest,
|
|
rootTurnPrompt: promptLatest,
|
|
},
|
|
{
|
|
stepIndex: 22,
|
|
agentCascadeId: 'mock-main',
|
|
agentId: 'main',
|
|
agentIndex: 0,
|
|
isSubagent: false,
|
|
agentBadge: '主',
|
|
agentLabel: t('fmt.mainAgent'),
|
|
isCompactionStep: true,
|
|
modelLabel: 'Gemini 4 Carbon (High) [自动压缩]',
|
|
modelShort: 'carbon-4-high·压缩',
|
|
rawModel: 'MODEL_PLACEHOLDER_M37',
|
|
modelUpstream: 'gemini-4-carbon-high·压缩',
|
|
upstreamModel: 'gemini-4-carbon-high',
|
|
tokPerSec: 46.5,
|
|
ttftSec: 3.4,
|
|
totalDurationSec: 15.8,
|
|
streamDurationSec: 12.4,
|
|
contextTokens: 128400,
|
|
inputTokens: 49200,
|
|
cacheReadTokens: 78100,
|
|
outputTokens: 1100,
|
|
thinkingTokens: 720,
|
|
responseTokens: 380,
|
|
cacheHitPct: 61.4,
|
|
costUsd: 0.068,
|
|
inCostUsd: 0.0492,
|
|
cacheCostUsd: 0.0078,
|
|
outCostUsd: 0.011,
|
|
createdAtMs: anchorMinMs - 88_000,
|
|
turnIndex: 2,
|
|
rootTurnIndex: 2,
|
|
isTurnStart: true,
|
|
isRootTurnStart: true,
|
|
isLatestTurn: true,
|
|
isRootLatestTurn: true,
|
|
turnPrompt: promptLatest,
|
|
rootTurnPrompt: promptLatest,
|
|
},
|
|
{
|
|
stepIndex: 19,
|
|
agentCascadeId: 'mock-main',
|
|
agentId: 'main',
|
|
agentIndex: 0,
|
|
isSubagent: false,
|
|
agentBadge: '主',
|
|
agentLabel: t('fmt.mainAgent'),
|
|
modelKey: 'MODEL_PLACEHOLDER_M667',
|
|
modelLabel: 'Gemini Pro Orchestrator (Carbon)',
|
|
modelShort: 'orchestrator-carbon',
|
|
rawModel: 'MODEL_PLACEHOLDER_M667',
|
|
modelUpstream: 'gemini-pro-orchestrator',
|
|
upstreamModel: 'gemini-pro-orchestrator',
|
|
tokPerSec: 17.8,
|
|
ttftSec: 19.4,
|
|
totalDurationSec: 31.2,
|
|
streamDurationSec: 11.8,
|
|
contextTokens: 96200,
|
|
inputTokens: 95400,
|
|
cacheReadTokens: 0,
|
|
outputTokens: 800,
|
|
thinkingTokens: 540,
|
|
responseTokens: 260,
|
|
cacheHitPct: 0,
|
|
costUsd: 0.198,
|
|
inCostUsd: 0.19,
|
|
cacheCostUsd: 0,
|
|
outCostUsd: 0.008,
|
|
createdAtMs: anchorMinMs - 215_000,
|
|
turnIndex: 1,
|
|
rootTurnIndex: 1,
|
|
isTurnStart: true,
|
|
isRootTurnStart: true,
|
|
isLatestTurn: false,
|
|
isRootLatestTurn: false,
|
|
turnPrompt: promptPrev,
|
|
rootTurnPrompt: promptPrev,
|
|
},
|
|
];
|
|
|
|
const mainAgent = {
|
|
agentId: 'main',
|
|
cascadeId: 'mock-main',
|
|
isMain: true,
|
|
index: 0,
|
|
badgeText: '主',
|
|
role: t('fmt.mainAgent'),
|
|
isRunning: true,
|
|
stepCount: 16,
|
|
speedSampleCount: 15,
|
|
speedSummary: { sampleCount: 15, excludedCount: 1 },
|
|
latestTokPerSec: 68.4,
|
|
avgTokPerSec: 54.8,
|
|
latestTtftSec: 1.15,
|
|
avgTtftSec: 1.62,
|
|
ttftSummary: { avgSec: 1.62, sampleCount: 15 },
|
|
latestStepCostUsd: 0.042,
|
|
sessionCostUsd: 1.16,
|
|
latestCacheHitPct: 94.5,
|
|
sessionCacheHitPct: 89.2,
|
|
latestPromptTokens: 141380,
|
|
inputTokens: 152400,
|
|
cacheReadTokens: 1260000,
|
|
outputTokens: 22100,
|
|
totalTokens: 1434500,
|
|
latestModelLabel: 'Gemini 4 Carbon (High)',
|
|
latestModelShort: 'carbon-4-high',
|
|
latestRawModel: 'MODEL_PLACEHOLDER_M37',
|
|
latestUpstreamModel: 'gemini-4-carbon-high',
|
|
activeModelLabel: 'Gemini 4 Carbon (High)',
|
|
activeModelShort: 'carbon-4-high',
|
|
activeModelUpstream: 'gemini-4-carbon-high',
|
|
sessionUnpricedCalls: 0,
|
|
modelBreakdown: [
|
|
{
|
|
modelKey: 'MODEL_PLACEHOLDER_M37',
|
|
modelShort: 'carbon-4-high',
|
|
modelLabel: 'Gemini 4 Carbon (High)',
|
|
modelUpstream: 'gemini-4-carbon-high',
|
|
upstreamModel: 'gemini-4-carbon-high',
|
|
calls: 16,
|
|
inputTokens: 152400,
|
|
cacheReadTokens: 1260000,
|
|
outputTokens: 22100,
|
|
thinkingTokens: 14200,
|
|
totalTokens: 1434500,
|
|
costUsd: 1.16,
|
|
sharePct: 100,
|
|
},
|
|
],
|
|
context: mainContext,
|
|
recentSteps: mockSteps.filter((s) => !s.isSubagent),
|
|
};
|
|
|
|
const subAgent1 = {
|
|
agentId: 'sub-1',
|
|
cascadeId: 'mock-sub-1',
|
|
isMain: false,
|
|
agentKind: 'subagent',
|
|
agentOrdinal: 1,
|
|
index: 1,
|
|
badgeText: '子1',
|
|
shortLabel: `${t('fmt.subAgent')} #1`,
|
|
role: subRole,
|
|
isRunning: false,
|
|
stepCount: 8,
|
|
speedSampleCount: 8,
|
|
speedSummary: { sampleCount: 8, excludedCount: 0 },
|
|
latestTokPerSec: 96.2,
|
|
avgTokPerSec: 88.5,
|
|
latestTtftSec: 0.68,
|
|
avgTtftSec: 0.82,
|
|
ttftSummary: { avgSec: 0.82, sampleCount: 8 },
|
|
latestStepCostUsd: 0.009,
|
|
sessionCostUsd: 0.12,
|
|
latestCacheHitPct: 88.1,
|
|
sessionCacheHitPct: 86.4,
|
|
latestPromptTokens: 72000,
|
|
inputTokens: 34000,
|
|
cacheReadTokens: 280000,
|
|
outputTokens: 6300,
|
|
totalTokens: 320300,
|
|
latestModelLabel: 'Gemini 3.8 Flash',
|
|
latestModelShort: 'flash-3.8',
|
|
latestRawModel: 'MODEL_PLACEHOLDER_M42',
|
|
latestUpstreamModel: 'gemini-3.8-flash-n',
|
|
activeModelLabel: 'Gemini 3.8 Flash',
|
|
activeModelShort: 'flash-3.8',
|
|
activeModelUpstream: 'gemini-3.8-flash-n',
|
|
sessionUnpricedCalls: 0,
|
|
modelBreakdown: [
|
|
{
|
|
modelKey: 'MODEL_PLACEHOLDER_M42',
|
|
modelShort: 'flash-3.8',
|
|
modelLabel: 'Gemini 3.8 Flash',
|
|
modelUpstream: 'gemini-3.8-flash-n',
|
|
upstreamModel: 'gemini-3.8-flash-n',
|
|
calls: 8,
|
|
inputTokens: 34000,
|
|
cacheReadTokens: 280000,
|
|
outputTokens: 6300,
|
|
thinkingTokens: 2100,
|
|
totalTokens: 320300,
|
|
costUsd: 0.12,
|
|
sharePct: 100,
|
|
},
|
|
],
|
|
context: subContext,
|
|
recentSteps: mockSteps.filter((s) => s.isSubagent),
|
|
};
|
|
|
|
const aggregated = {
|
|
...mainAgent,
|
|
agentId: 'all',
|
|
isMain: false,
|
|
agentKind: 'all',
|
|
agentOrdinal: 0,
|
|
badgeText: t('header.scopeAllShort'),
|
|
activeAgentId: 'sub-1',
|
|
activeAgentKind: 'subagent',
|
|
activeAgentOrdinal: 1,
|
|
stepCount: 24,
|
|
speedSampleCount: 23,
|
|
speedSummary: { sampleCount: 23, excludedCount: 1 },
|
|
avgTokPerSec: 59.6,
|
|
avgTtftSec: 1.38,
|
|
ttftSummary: { avgSec: 1.38, sampleCount: 23 },
|
|
sessionCostUsd: 1.28,
|
|
sessionUnpricedCalls: 0,
|
|
sessionCacheHitPct: 88.9,
|
|
inputTokens: 186400,
|
|
cacheReadTokens: 1540000,
|
|
outputTokens: 28400,
|
|
totalTokens: 1754800,
|
|
activeAgentBadge: '子1',
|
|
modelBreakdown: [...mainAgent.modelBreakdown, ...subAgent1.modelBreakdown],
|
|
recentSteps: mockSteps,
|
|
};
|
|
|
|
return {
|
|
settings: mergedSettings,
|
|
account: {
|
|
tierName: 'Google AI Ultra',
|
|
planName: 'Pro',
|
|
aiCredits: 0,
|
|
},
|
|
quotas: {
|
|
meta: {
|
|
hasOfficialData: true,
|
|
isStale: false,
|
|
refreshFailed: false,
|
|
},
|
|
activePool: {
|
|
family: 'Gemini',
|
|
poolKey: 'Gemini',
|
|
poolLabel: 'Gemini',
|
|
usedPct: 36,
|
|
remainingPct: 64,
|
|
resetTime: reset5hIso,
|
|
weeklyUsedPct: 48,
|
|
weeklyRemainingPct: 52,
|
|
weeklyResetTime: resetWkIso,
|
|
},
|
|
pools: [
|
|
{
|
|
poolKey: 'Gemini',
|
|
poolLabel: 'Gemini',
|
|
family: 'Gemini',
|
|
usedPct: 36,
|
|
remainingPct: 64,
|
|
reservedPct: 1.0,
|
|
reservedLeaseCount: 1,
|
|
resetTime: reset5hIso,
|
|
weeklyUsedPct: 48,
|
|
weeklyRemainingPct: 52,
|
|
weeklyReservedPct: 0.5,
|
|
weeklyReservedLeaseCount: 1,
|
|
weeklyResetTime: resetWkIso,
|
|
cycle5h: { tokens: 1754800, costUsd: 1.28, calls: 24 },
|
|
cycleWeekly: { tokens: 14200000, costUsd: 11.4, calls: 186 },
|
|
},
|
|
{
|
|
poolKey: 'Claude & GPT',
|
|
poolLabel: 'Claude & GPT',
|
|
family: 'Claude & GPT',
|
|
usedPct: 68,
|
|
remainingPct: 32,
|
|
resetTime: resetClaude5hIso,
|
|
weeklyUsedPct: 41,
|
|
weeklyRemainingPct: 59,
|
|
weeklyResetTime: resetWkIso,
|
|
cycle5h: { tokens: 620000, costUsd: 2.15, calls: 11 },
|
|
cycleWeekly: { tokens: 5800000, costUsd: 18.6, calls: 92 },
|
|
},
|
|
],
|
|
weekly: {
|
|
isOfficial: true,
|
|
usedPct: 48,
|
|
remainingPct: 52,
|
|
resetTime: resetWkIso,
|
|
tokens: 20000000,
|
|
costUsd: 30.0,
|
|
calls: 278,
|
|
},
|
|
},
|
|
runningConversations: [
|
|
{
|
|
cascadeId: 'mock-preview-conv',
|
|
title: sessionTitle,
|
|
isCurrentSelected: true,
|
|
isMainRunning: true,
|
|
isRunning: true,
|
|
subagentCount: 1,
|
|
runningSubagentCount: 0,
|
|
latestTokPerSec: 68.4,
|
|
contextUsedPct: 55.8,
|
|
mainActivity: {
|
|
phase: 'generating',
|
|
label: t('live.generating'),
|
|
stepProgress: '#24',
|
|
detail: 'src/auth/tokenRefresh.ts',
|
|
startedAtMs: Date.now() - 8000,
|
|
signature: 'mock-preview:24',
|
|
},
|
|
subagents: [
|
|
{
|
|
cascadeId: 'mock-sub-1',
|
|
index: 1,
|
|
badgeText: '子1',
|
|
shortLabel: `${t('fmt.subAgent')} #1`,
|
|
role: subRole,
|
|
isRunning: false,
|
|
stepCount: 8,
|
|
lastModifiedMs: anchorMinMs - 42_000,
|
|
liveActivity: {
|
|
phase: 'done',
|
|
label: t('live.done'),
|
|
detail: '',
|
|
stepProgress: '',
|
|
startedAtMs: anchorMinMs - 42_000,
|
|
signature: 'mock-sub-1:8',
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
activeConversation: {
|
|
...mainAgent,
|
|
cascadeId: 'mock-preview-conv',
|
|
title: sessionTitle,
|
|
hasSubagents: true,
|
|
agents: [mainAgent, subAgent1],
|
|
aggregated,
|
|
recentSteps: mockSteps,
|
|
},
|
|
};
|
|
}
|