sidekick-shared 0.24.5 → 0.26.0
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/CHANGELOG.md +92 -0
- package/README.md +205 -52
- package/dist/accountChangeSignal.d.ts +3 -0
- package/dist/accountChangeSignal.js +19 -0
- package/dist/accountChanges.d.ts +21 -0
- package/dist/accountChanges.js +170 -0
- package/dist/accountRegistry.d.ts +25 -2
- package/dist/accountRegistry.js +41 -13
- package/dist/accountStatus.d.ts +9 -1
- package/dist/accountStatus.js +3 -3
- package/dist/accounts.d.ts +3 -1
- package/dist/accounts.js +84 -64
- package/dist/aggregation/EventAggregator.d.ts +15 -2
- package/dist/aggregation/EventAggregator.js +54 -9
- package/dist/aggregation/costProvenance.d.ts +14 -0
- package/dist/aggregation/costProvenance.js +35 -0
- package/dist/aggregation/snapshot.d.ts +13 -2
- package/dist/aggregation/snapshot.js +57 -6
- package/dist/aggregation/types.d.ts +30 -1
- package/dist/analytics/compactionLedger.js +15 -5
- package/dist/analytics/qualityScore.js +2 -1
- package/dist/browser.d.ts +19 -4
- package/dist/browser.js +43 -1
- package/dist/codexProfiles.d.ts +3 -1
- package/dist/codexProfiles.js +4 -2
- package/dist/codexQuota.d.ts +2 -0
- package/dist/codexQuota.js +11 -66
- package/dist/codexQuotaWatcher.d.ts +6 -0
- package/dist/codexQuotaWatcher.js +101 -47
- package/dist/failingTools.d.ts +37 -0
- package/dist/failingTools.js +70 -0
- package/dist/formatters/sessionDump.js +13 -7
- package/dist/formatting.d.ts +13 -0
- package/dist/formatting.js +35 -0
- package/dist/historicalStore.d.ts +47 -0
- package/dist/historicalStore.js +312 -0
- package/dist/index.d.ts +67 -23
- package/dist/index.js +138 -26
- package/dist/modelAliases.d.ts +13 -0
- package/dist/modelAliases.js +58 -0
- package/dist/modelCatalog.d.ts +32 -0
- package/dist/modelCatalog.js +145 -0
- package/dist/modelContext.d.ts +36 -3
- package/dist/modelContext.js +109 -34
- package/dist/modelInfo.d.ts +30 -1
- package/dist/modelInfo.js +116 -26
- package/dist/multiProviderQuotaService.d.ts +8 -0
- package/dist/multiProviderQuotaService.js +64 -3
- package/dist/node.d.ts +23 -4
- package/dist/node.js +50 -1
- package/dist/observedContextWindows.d.ts +7 -0
- package/dist/observedContextWindows.js +17 -2
- package/dist/observedSessionCollector.d.ts +72 -6
- package/dist/observedSessionCollector.js +440 -47
- package/dist/parsers/codexHistory.d.ts +4 -2
- package/dist/parsers/codexHistory.js +9 -2
- package/dist/parsers/sessionActivityDetector.d.ts +28 -0
- package/dist/parsers/sessionActivityDetector.js +110 -15
- package/dist/parsers/sessionPathResolver.d.ts +11 -0
- package/dist/parsers/sessionPathResolver.js +13 -10
- package/dist/peakHours.d.ts +34 -3
- package/dist/peakHours.js +92 -7
- package/dist/pricingCatalog.d.ts +7 -0
- package/dist/pricingCatalog.js +8 -5
- package/dist/providerIds.d.ts +11 -0
- package/dist/providerIds.js +9 -0
- package/dist/providerQuota.d.ts +3 -1
- package/dist/providerQuota.js +3 -0
- package/dist/providers/claudeCode.d.ts +10 -1
- package/dist/providers/claudeCode.js +211 -131
- package/dist/providers/codex.d.ts +20 -1
- package/dist/providers/codex.js +308 -244
- package/dist/providers/codexDatabase.d.ts +9 -0
- package/dist/providers/codexDatabase.js +107 -2
- package/dist/providers/detect.d.ts +2 -0
- package/dist/providers/detect.js +29 -24
- package/dist/providers/diagnostics.d.ts +13 -0
- package/dist/providers/diagnostics.js +88 -0
- package/dist/providers/factory.d.ts +20 -0
- package/dist/providers/factory.js +57 -0
- package/dist/providers/openCode.d.ts +22 -1
- package/dist/providers/openCode.js +460 -126
- package/dist/providers/openCodeDatabase.d.ts +10 -0
- package/dist/providers/openCodeDatabase.js +69 -0
- package/dist/providers/rolloutWalker.d.ts +53 -0
- package/dist/providers/rolloutWalker.js +209 -0
- package/dist/providers/types.d.ts +82 -2
- package/dist/providers/types.js +4 -0
- package/dist/quota.d.ts +34 -4
- package/dist/quota.js +37 -9
- package/dist/quotaHistory.d.ts +3 -2
- package/dist/quotaHistory.js +36 -35
- package/dist/quotaPoller.d.ts +13 -1
- package/dist/quotaPoller.js +65 -3
- package/dist/quotaResolver.d.ts +81 -0
- package/dist/quotaResolver.js +213 -0
- package/dist/quotaSnapshots.d.ts +15 -2
- package/dist/quotaSnapshots.js +25 -3
- package/dist/quotaThresholds.d.ts +60 -0
- package/dist/quotaThresholds.js +90 -0
- package/dist/report/htmlReportGenerator.js +10 -4
- package/dist/report/sessionReportInputs.d.ts +23 -0
- package/dist/report/sessionReportInputs.js +34 -0
- package/dist/schemas/accountManager.d.ts +2 -2
- package/dist/schemas/accountManager.js +2 -4
- package/dist/schemas/accountStatus.d.ts +3 -0
- package/dist/schemas/accountStatus.js +1 -0
- package/dist/schemas/index.d.ts +3 -0
- package/dist/schemas/index.js +16 -2
- package/dist/schemas/observedSessionV1.d.ts +27 -26
- package/dist/schemas/observedSessionV1.js +6 -4
- package/dist/schemas/quota.d.ts +141 -2
- package/dist/schemas/quota.js +20 -8
- package/dist/schemas/quotaHistory.d.ts +3 -2
- package/dist/schemas/quotaHistory.js +1 -1
- package/dist/schemas/sessionEvent.d.ts +6 -0
- package/dist/schemas/sessionEvent.js +1 -0
- package/dist/schemas/stateFile.d.ts +198 -0
- package/dist/schemas/stateFile.js +77 -0
- package/dist/schemas/tokenEstimation.d.ts +1 -1
- package/dist/schemas/transcript.js +2 -0
- package/dist/sessionFingerprint.d.ts +25 -0
- package/dist/sessionFingerprint.js +46 -0
- package/dist/sessionMonitor.d.ts +15 -0
- package/dist/sessionMonitor.js +142 -0
- package/dist/sessionPreviews.d.ts +33 -2
- package/dist/sessionPreviews.js +333 -6
- package/dist/sessionStats.d.ts +51 -0
- package/dist/sessionStats.js +166 -0
- package/dist/stateFile.d.ts +113 -0
- package/dist/stateFile.js +160 -0
- package/dist/statusline/claudeStatuslinePayload.d.ts +89 -0
- package/dist/statusline/claudeStatuslinePayload.js +152 -0
- package/dist/statusline/formatter.d.ts +13 -0
- package/dist/statusline/formatter.js +48 -6
- package/dist/statusline/index.d.ts +10 -2
- package/dist/statusline/index.js +19 -1
- package/dist/tokenSummary.d.ts +62 -0
- package/dist/tokenSummary.js +72 -0
- package/dist/transcript.d.ts +5 -0
- package/dist/transcript.js +2 -0
- package/dist/types/observedSessionV1.d.ts +8 -2
- package/dist/types/observedSessionV1.js +88 -25
- package/dist/types/sessionEvent.d.ts +2 -0
- package/dist/usage/billingBlocks.d.ts +85 -0
- package/dist/usage/billingBlocks.js +153 -0
- package/dist/usage/importSessionHistory.d.ts +53 -0
- package/dist/usage/importSessionHistory.js +88 -0
- package/dist/usage/usageEvents.d.ts +92 -0
- package/dist/usage/usageEvents.js +322 -0
- package/dist/usage/usageReports.d.ts +76 -0
- package/dist/usage/usageReports.js +208 -0
- package/dist/watchers/factory.d.ts +6 -0
- package/dist/watchers/factory.js +30 -25
- package/dist/zaiQuotaApi.d.ts +2 -0
- package/dist/zaiQuotaApi.js +2 -0
- package/package.json +22 -1
package/dist/quotaSnapshots.js
CHANGED
|
@@ -39,6 +39,7 @@ const fs = __importStar(require("fs"));
|
|
|
39
39
|
const path = __importStar(require("path"));
|
|
40
40
|
const paths_1 = require("./paths");
|
|
41
41
|
const atomic_1 = require("./writers/atomic");
|
|
42
|
+
const quota_1 = require("./quota");
|
|
42
43
|
const codex_1 = require("./types/codex");
|
|
43
44
|
function getQuotaSnapshotPath() {
|
|
44
45
|
return path.join((0, paths_1.getConfigDir)(), 'quota-snapshots.json');
|
|
@@ -113,11 +114,17 @@ function writeQuotaSnapshot(providerId, accountId, quota) {
|
|
|
113
114
|
const store = readStore();
|
|
114
115
|
const index = store.snapshots.findIndex((item) => item.providerId === providerId && item.accountId === accountId);
|
|
115
116
|
const existingQuota = index >= 0 ? store.snapshots[index].quota : undefined;
|
|
117
|
+
// `ageMs`, `freshness`, `stale`, and `capturedSource` are read-time facts: a
|
|
118
|
+
// sample that came back from `readQuotaSnapshot()` and is written again keeps
|
|
119
|
+
// its original source rather than being stored as `cache`.
|
|
120
|
+
const { capturedSource, ...sample } = quota;
|
|
121
|
+
delete sample.ageMs;
|
|
122
|
+
delete sample.freshness;
|
|
116
123
|
const snapshot = {
|
|
117
|
-
...
|
|
124
|
+
...sample,
|
|
118
125
|
providerId,
|
|
119
126
|
capturedAt: quota.capturedAt ?? new Date().toISOString(),
|
|
120
|
-
source:
|
|
127
|
+
source: sample.source && sample.source !== 'cache' ? sample.source : (capturedSource ?? 'session'),
|
|
121
128
|
stale: false,
|
|
122
129
|
resetCredits: quota.resetCredits ?? (providerId === 'codex' ? existingQuota?.resetCredits : undefined),
|
|
123
130
|
};
|
|
@@ -131,15 +138,30 @@ function writeQuotaSnapshot(providerId, accountId, quota) {
|
|
|
131
138
|
writeStore(store);
|
|
132
139
|
});
|
|
133
140
|
}
|
|
134
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Read the persisted snapshot for one provider/account.
|
|
143
|
+
*
|
|
144
|
+
* `stale: true` and `source: 'cache'` mean "not a live fetch"; the age of the
|
|
145
|
+
* sample is reported separately as `ageMs` and `freshness` so a reader can
|
|
146
|
+
* tell a ten-second-old snapshot from a two-day-old one, and the original
|
|
147
|
+
* origin is kept as `capturedSource` (`statusline`, `session`, or `api`).
|
|
148
|
+
*/
|
|
149
|
+
function readQuotaSnapshot(providerId, accountId, now = new Date()) {
|
|
135
150
|
const store = readStore();
|
|
136
151
|
const snapshot = store.snapshots.find((item) => item.providerId === providerId && item.accountId === accountId);
|
|
137
152
|
if (!snapshot)
|
|
138
153
|
return null;
|
|
154
|
+
const capturedMs = snapshotTimeMs(snapshot.quota);
|
|
155
|
+
const ageMs = capturedMs > 0 ? Math.max(0, now.getTime() - capturedMs) : undefined;
|
|
156
|
+
const storedSource = snapshot.quota.capturedSource ?? snapshot.quota.source;
|
|
157
|
+
const capturedSource = storedSource && storedSource !== 'cache' ? storedSource : undefined;
|
|
139
158
|
return {
|
|
140
159
|
...snapshot.quota,
|
|
141
160
|
providerId,
|
|
142
161
|
source: 'cache',
|
|
162
|
+
...(capturedSource ? { capturedSource } : {}),
|
|
143
163
|
stale: true,
|
|
164
|
+
...(ageMs !== undefined ? { ageMs } : {}),
|
|
165
|
+
freshness: (0, quota_1.classifyQuotaFreshness)(ageMs),
|
|
144
166
|
};
|
|
145
167
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Threshold-crossing detection for subscription quota windows.
|
|
3
|
+
*
|
|
4
|
+
* Pure and host-neutral: the VS Code extension and the CLI dashboard both
|
|
5
|
+
* feed it every quota sample and raise whatever alerts it returns, so a user
|
|
6
|
+
* hears "your five-hour window is at 80%" the same way in both. Alerts fire
|
|
7
|
+
* once per threshold per reset window, on the rising edge; when a window
|
|
8
|
+
* resets the memory resets with it.
|
|
9
|
+
*
|
|
10
|
+
* @module quotaThresholds
|
|
11
|
+
*/
|
|
12
|
+
import type { QuotaState } from './quota';
|
|
13
|
+
export type QuotaThresholdWindow = 'fiveHour' | 'sevenDay';
|
|
14
|
+
export interface QuotaThresholdConfig {
|
|
15
|
+
/** Utilization percentages (0–100) that raise an alert for the five-hour window. */
|
|
16
|
+
fiveHour: readonly number[];
|
|
17
|
+
/** Utilization percentages (0–100) that raise an alert for the seven-day window. */
|
|
18
|
+
sevenDay: readonly number[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Defaults tuned to the two surprises users report: the afternoon five-hour
|
|
22
|
+
* cutoff (warn at 80%, escalate at 95%) and the mid-week weekly cap (90%).
|
|
23
|
+
*/
|
|
24
|
+
export declare const DEFAULT_QUOTA_THRESHOLDS: QuotaThresholdConfig;
|
|
25
|
+
interface WindowMemory {
|
|
26
|
+
resetsAt: string;
|
|
27
|
+
/** Highest threshold already alerted for this reset window (0 = none). */
|
|
28
|
+
level: number;
|
|
29
|
+
}
|
|
30
|
+
/** Opaque per-window state; keep it between samples and pass it back in. */
|
|
31
|
+
export interface QuotaAlertMemory {
|
|
32
|
+
fiveHour?: WindowMemory;
|
|
33
|
+
sevenDay?: WindowMemory;
|
|
34
|
+
}
|
|
35
|
+
export interface QuotaThresholdAlert {
|
|
36
|
+
window: QuotaThresholdWindow;
|
|
37
|
+
/** The threshold that was crossed. */
|
|
38
|
+
threshold: number;
|
|
39
|
+
/** Utilization at the time of the sample. */
|
|
40
|
+
utilization: number;
|
|
41
|
+
/** ISO reset time of the window, when known. */
|
|
42
|
+
resetsAt: string;
|
|
43
|
+
/** Escalation hint: the highest configured threshold is `critical`. */
|
|
44
|
+
severity: 'warning' | 'critical';
|
|
45
|
+
}
|
|
46
|
+
export interface QuotaThresholdEvaluation {
|
|
47
|
+
alerts: QuotaThresholdAlert[];
|
|
48
|
+
memory: QuotaAlertMemory;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Compare a quota sample against the thresholds and the alerts already
|
|
52
|
+
* raised. Unavailable samples produce no alerts and leave the memory alone.
|
|
53
|
+
*/
|
|
54
|
+
export declare function evaluateQuotaThresholds(quota: QuotaState, config?: QuotaThresholdConfig, memory?: QuotaAlertMemory): QuotaThresholdEvaluation;
|
|
55
|
+
/** One-line, reset-aware message: `Claude five-hour window at 82% (resets 14:00)`. */
|
|
56
|
+
export declare function describeQuotaThresholdAlert(alert: QuotaThresholdAlert, options?: {
|
|
57
|
+
providerLabel?: string;
|
|
58
|
+
now?: Date;
|
|
59
|
+
}): string;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Threshold-crossing detection for subscription quota windows.
|
|
4
|
+
*
|
|
5
|
+
* Pure and host-neutral: the VS Code extension and the CLI dashboard both
|
|
6
|
+
* feed it every quota sample and raise whatever alerts it returns, so a user
|
|
7
|
+
* hears "your five-hour window is at 80%" the same way in both. Alerts fire
|
|
8
|
+
* once per threshold per reset window, on the rising edge; when a window
|
|
9
|
+
* resets the memory resets with it.
|
|
10
|
+
*
|
|
11
|
+
* @module quotaThresholds
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.DEFAULT_QUOTA_THRESHOLDS = void 0;
|
|
15
|
+
exports.evaluateQuotaThresholds = evaluateQuotaThresholds;
|
|
16
|
+
exports.describeQuotaThresholdAlert = describeQuotaThresholdAlert;
|
|
17
|
+
/**
|
|
18
|
+
* Defaults tuned to the two surprises users report: the afternoon five-hour
|
|
19
|
+
* cutoff (warn at 80%, escalate at 95%) and the mid-week weekly cap (90%).
|
|
20
|
+
*/
|
|
21
|
+
exports.DEFAULT_QUOTA_THRESHOLDS = {
|
|
22
|
+
fiveHour: [80, 95],
|
|
23
|
+
sevenDay: [90],
|
|
24
|
+
};
|
|
25
|
+
function sanitizeThresholds(values) {
|
|
26
|
+
return [...new Set(values.filter((v) => Number.isFinite(v) && v > 0 && v <= 100))].sort((a, b) => a - b);
|
|
27
|
+
}
|
|
28
|
+
function evaluateWindow(window, quota, thresholds, previous) {
|
|
29
|
+
const sorted = sanitizeThresholds(thresholds);
|
|
30
|
+
const utilization = Number.isFinite(quota.utilization) ? quota.utilization : 0;
|
|
31
|
+
const resetsAt = quota.resetsAt ?? '';
|
|
32
|
+
let level = 0;
|
|
33
|
+
for (const threshold of sorted)
|
|
34
|
+
if (utilization >= threshold)
|
|
35
|
+
level = threshold;
|
|
36
|
+
const previousLevel = previous && previous.resetsAt === resetsAt ? previous.level : 0;
|
|
37
|
+
const memory = { resetsAt, level: Math.max(level, previousLevel) };
|
|
38
|
+
if (level <= previousLevel)
|
|
39
|
+
return { alert: null, memory };
|
|
40
|
+
return {
|
|
41
|
+
alert: {
|
|
42
|
+
window,
|
|
43
|
+
threshold: level,
|
|
44
|
+
utilization,
|
|
45
|
+
resetsAt,
|
|
46
|
+
severity: level >= sorted[sorted.length - 1] ? 'critical' : 'warning',
|
|
47
|
+
},
|
|
48
|
+
memory,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Compare a quota sample against the thresholds and the alerts already
|
|
53
|
+
* raised. Unavailable samples produce no alerts and leave the memory alone.
|
|
54
|
+
*/
|
|
55
|
+
function evaluateQuotaThresholds(quota, config = exports.DEFAULT_QUOTA_THRESHOLDS, memory = {}) {
|
|
56
|
+
if (!quota.available)
|
|
57
|
+
return { alerts: [], memory };
|
|
58
|
+
const fiveHour = evaluateWindow('fiveHour', quota.fiveHour, config.fiveHour, memory.fiveHour);
|
|
59
|
+
const sevenDay = evaluateWindow('sevenDay', quota.sevenDay, config.sevenDay, memory.sevenDay);
|
|
60
|
+
return {
|
|
61
|
+
alerts: [fiveHour.alert, sevenDay.alert].filter((alert) => alert !== null),
|
|
62
|
+
memory: { fiveHour: fiveHour.memory, sevenDay: sevenDay.memory },
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const WINDOW_LABELS = {
|
|
66
|
+
fiveHour: 'five-hour window',
|
|
67
|
+
sevenDay: 'seven-day window',
|
|
68
|
+
};
|
|
69
|
+
function formatResetTime(resetsAt, now) {
|
|
70
|
+
const ms = Date.parse(resetsAt);
|
|
71
|
+
if (!Number.isFinite(ms))
|
|
72
|
+
return null;
|
|
73
|
+
const reset = new Date(ms);
|
|
74
|
+
const sameDay = reset.getFullYear() === now.getFullYear() &&
|
|
75
|
+
reset.getMonth() === now.getMonth() &&
|
|
76
|
+
reset.getDate() === now.getDate();
|
|
77
|
+
return new Intl.DateTimeFormat(undefined, {
|
|
78
|
+
...(sameDay ? {} : { weekday: 'short' }),
|
|
79
|
+
hour: '2-digit',
|
|
80
|
+
minute: '2-digit',
|
|
81
|
+
hour12: false,
|
|
82
|
+
}).format(reset);
|
|
83
|
+
}
|
|
84
|
+
/** One-line, reset-aware message: `Claude five-hour window at 82% (resets 14:00)`. */
|
|
85
|
+
function describeQuotaThresholdAlert(alert, options = {}) {
|
|
86
|
+
const provider = options.providerLabel ?? 'Claude';
|
|
87
|
+
const reset = formatResetTime(alert.resetsAt, options.now ?? new Date());
|
|
88
|
+
const suffix = reset ? ` (resets ${reset})` : '';
|
|
89
|
+
return `${provider} ${WINDOW_LABELS[alert.window]} at ${Math.round(alert.utilization)}%${suffix}`;
|
|
90
|
+
}
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.generateHtmlReport = generateHtmlReport;
|
|
9
|
+
const costProvenance_1 = require("../aggregation/costProvenance");
|
|
10
|
+
const tokenSummary_1 = require("../tokenSummary");
|
|
9
11
|
const htmlHelpers_1 = require("./htmlHelpers");
|
|
10
12
|
const logo_1 = require("./logo");
|
|
11
13
|
/**
|
|
@@ -14,7 +16,7 @@ const logo_1 = require("./logo");
|
|
|
14
16
|
function generateHtmlReport(metrics, transcript, options = {}) {
|
|
15
17
|
const { sessionFileName, includeThinking = true, includeToolDetail = true, theme = 'dark', } = options;
|
|
16
18
|
const duration = (0, htmlHelpers_1.formatDuration)(metrics.sessionStartTime, metrics.lastEventTime);
|
|
17
|
-
const totalTokens =
|
|
19
|
+
const totalTokens = (0, tokenSummary_1.summarizeTokens)(metrics.tokens).total;
|
|
18
20
|
return `<!DOCTYPE html>
|
|
19
21
|
<html lang="en" data-theme="${theme}">
|
|
20
22
|
<head>
|
|
@@ -430,7 +432,7 @@ function generateStatsCards(metrics, totalTokens, duration) {
|
|
|
430
432
|
sub: metrics.sessionStartTime ? (0, htmlHelpers_1.formatTimestamp)(metrics.sessionStartTime) + ' start' : '',
|
|
431
433
|
},
|
|
432
434
|
{
|
|
433
|
-
label:
|
|
435
|
+
label: tokenSummary_1.TOKEN_TOTAL_LABEL,
|
|
434
436
|
value: (0, htmlHelpers_1.fmtTokens)(totalTokens),
|
|
435
437
|
sub: `${(0, htmlHelpers_1.fmtTokens)(metrics.tokens.inputTokens)} in / ${(0, htmlHelpers_1.fmtTokens)(metrics.tokens.outputTokens)} out`,
|
|
436
438
|
},
|
|
@@ -445,8 +447,12 @@ function generateStatsCards(metrics, totalTokens, duration) {
|
|
|
445
447
|
sub: `${metrics.toolStats.length} unique tools`,
|
|
446
448
|
},
|
|
447
449
|
];
|
|
448
|
-
if (metrics.tokens.
|
|
449
|
-
cards.push({
|
|
450
|
+
if (metrics.tokens.costUsd > 0 || metrics.tokens.unpricedCalls > 0) {
|
|
451
|
+
cards.push({
|
|
452
|
+
label: 'Cost',
|
|
453
|
+
value: metrics.tokens.costUsd > 0 ? (0, htmlHelpers_1.fmtCost)(metrics.tokens.costUsd) : '—',
|
|
454
|
+
sub: (0, htmlHelpers_1.escapeHtml)((0, costProvenance_1.describeCostProvenance)(metrics.tokens)),
|
|
455
|
+
});
|
|
450
456
|
}
|
|
451
457
|
return `<div class="container">
|
|
452
458
|
<div class="stats-grid">
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything an HTML session report needs, from one read of the session.
|
|
3
|
+
*
|
|
4
|
+
* `sidekick report`, the CLI dashboard's report action, and the extension used
|
|
5
|
+
* to replay a session through a watcher for metrics and then parse the file a
|
|
6
|
+
* second time for the transcript. This reads the provider's canonical events
|
|
7
|
+
* once and derives both.
|
|
8
|
+
*
|
|
9
|
+
* @module report/sessionReportInputs
|
|
10
|
+
*/
|
|
11
|
+
import type { AggregatedMetrics } from '../aggregation/types';
|
|
12
|
+
import type { SessionProviderBase } from '../providers/types';
|
|
13
|
+
import type { SessionEvent } from '../types/sessionEvent';
|
|
14
|
+
import type { TranscriptEntry } from './types';
|
|
15
|
+
export interface SessionReportInputs {
|
|
16
|
+
sessionPath: string;
|
|
17
|
+
/** Canonical provider events, already flushed. */
|
|
18
|
+
events: SessionEvent[];
|
|
19
|
+
metrics: AggregatedMetrics;
|
|
20
|
+
transcript: TranscriptEntry[];
|
|
21
|
+
}
|
|
22
|
+
/** Read a session once and build the aggregator metrics and report transcript from it. */
|
|
23
|
+
export declare function readSessionReportInputs(provider: SessionProviderBase, sessionPath: string): SessionReportInputs;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Everything an HTML session report needs, from one read of the session.
|
|
4
|
+
*
|
|
5
|
+
* `sidekick report`, the CLI dashboard's report action, and the extension used
|
|
6
|
+
* to replay a session through a watcher for metrics and then parse the file a
|
|
7
|
+
* second time for the transcript. This reads the provider's canonical events
|
|
8
|
+
* once and derives both.
|
|
9
|
+
*
|
|
10
|
+
* @module report/sessionReportInputs
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.readSessionReportInputs = readSessionReportInputs;
|
|
14
|
+
const EventAggregator_1 = require("../aggregation/EventAggregator");
|
|
15
|
+
const sessionStats_1 = require("../sessionStats");
|
|
16
|
+
const transcriptParser_1 = require("./transcriptParser");
|
|
17
|
+
/** Read a session once and build the aggregator metrics and report transcript from it. */
|
|
18
|
+
function readSessionReportInputs(provider, sessionPath) {
|
|
19
|
+
const reader = provider.createReader(sessionPath);
|
|
20
|
+
const events = reader.readAll();
|
|
21
|
+
reader.flush();
|
|
22
|
+
const aggregator = new EventAggregator_1.EventAggregator({
|
|
23
|
+
providerId: provider.id,
|
|
24
|
+
computeContextSize: (0, sessionStats_1.providerContextSizeFn)(provider),
|
|
25
|
+
});
|
|
26
|
+
for (const event of events)
|
|
27
|
+
aggregator.processEvent(event);
|
|
28
|
+
return {
|
|
29
|
+
sessionPath,
|
|
30
|
+
events,
|
|
31
|
+
metrics: aggregator.getMetrics(),
|
|
32
|
+
transcript: (0, transcriptParser_1.parseTranscriptFromEvents)(events),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -63,9 +63,9 @@ export declare const savedAccountProfileSchema: z.ZodObject<{
|
|
|
63
63
|
workspaceId: z.ZodOptional<z.ZodString>;
|
|
64
64
|
planType: z.ZodOptional<z.ZodString>;
|
|
65
65
|
authMode: z.ZodOptional<z.ZodEnum<{
|
|
66
|
+
unknown: "unknown";
|
|
66
67
|
chatgpt: "chatgpt";
|
|
67
68
|
"api-key": "api-key";
|
|
68
|
-
unknown: "unknown";
|
|
69
69
|
}>>;
|
|
70
70
|
}, z.core.$strip>>;
|
|
71
71
|
}, z.core.$strip>;
|
|
@@ -91,9 +91,9 @@ export declare const listAllAccountsResultSchema: z.ZodObject<{
|
|
|
91
91
|
workspaceId: z.ZodOptional<z.ZodString>;
|
|
92
92
|
planType: z.ZodOptional<z.ZodString>;
|
|
93
93
|
authMode: z.ZodOptional<z.ZodEnum<{
|
|
94
|
+
unknown: "unknown";
|
|
94
95
|
chatgpt: "chatgpt";
|
|
95
96
|
"api-key": "api-key";
|
|
96
|
-
unknown: "unknown";
|
|
97
97
|
}>>;
|
|
98
98
|
}, z.core.$strip>>;
|
|
99
99
|
}, z.core.$strip>>;
|
|
@@ -12,11 +12,9 @@
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.listAllAccountsResultSchema = exports.savedAccountProfileSchema = exports.accountEntrySchema = exports.accountLoginStatusSchema = exports.beginAccountLoginResultSchema = exports.accountManagerResultSchema = exports.accountProviderIdSchema = void 0;
|
|
14
14
|
const zod_1 = require("zod");
|
|
15
|
+
const providerIds_1 = require("../providerIds");
|
|
15
16
|
// ── AccountProviderId ──
|
|
16
|
-
exports.accountProviderIdSchema = zod_1.z.enum(
|
|
17
|
-
'claude-code',
|
|
18
|
-
'codex',
|
|
19
|
-
]);
|
|
17
|
+
exports.accountProviderIdSchema = zod_1.z.enum(providerIds_1.ACCOUNT_PROVIDER_IDS);
|
|
20
18
|
// ── AccountManagerResult ──
|
|
21
19
|
exports.accountManagerResultSchema = zod_1.z.object({
|
|
22
20
|
success: zod_1.z.boolean(),
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { z } from 'zod';
|
|
12
12
|
export declare const activeProviderAccountStatusSchema: z.ZodObject<{
|
|
13
13
|
present: z.ZodBoolean;
|
|
14
|
+
accountId: z.ZodOptional<z.ZodString>;
|
|
14
15
|
email: z.ZodOptional<z.ZodString>;
|
|
15
16
|
label: z.ZodOptional<z.ZodString>;
|
|
16
17
|
}, z.core.$strip>;
|
|
@@ -18,11 +19,13 @@ export declare const activeAccountStatusSchema: z.ZodObject<{
|
|
|
18
19
|
ok: z.ZodBoolean;
|
|
19
20
|
claude: z.ZodObject<{
|
|
20
21
|
present: z.ZodBoolean;
|
|
22
|
+
accountId: z.ZodOptional<z.ZodString>;
|
|
21
23
|
email: z.ZodOptional<z.ZodString>;
|
|
22
24
|
label: z.ZodOptional<z.ZodString>;
|
|
23
25
|
}, z.core.$strip>;
|
|
24
26
|
codex: z.ZodObject<{
|
|
25
27
|
present: z.ZodBoolean;
|
|
28
|
+
accountId: z.ZodOptional<z.ZodString>;
|
|
26
29
|
email: z.ZodOptional<z.ZodString>;
|
|
27
30
|
label: z.ZodOptional<z.ZodString>;
|
|
28
31
|
}, z.core.$strip>;
|
|
@@ -15,6 +15,7 @@ const zod_1 = require("zod");
|
|
|
15
15
|
// ── ActiveProviderAccountStatus ──
|
|
16
16
|
exports.activeProviderAccountStatusSchema = zod_1.z.object({
|
|
17
17
|
present: zod_1.z.boolean(),
|
|
18
|
+
accountId: zod_1.z.string().optional(),
|
|
18
19
|
email: zod_1.z.string().optional(),
|
|
19
20
|
label: zod_1.z.string().optional(),
|
|
20
21
|
});
|
package/dist/schemas/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* The mirrored TypeScript interfaces are re-exported as types so this
|
|
11
11
|
* subpath is self-sufficient for boundary-validation modules.
|
|
12
12
|
*/
|
|
13
|
+
export { ACCOUNT_PROVIDER_IDS, QUOTA_PROVIDER_IDS, RUNTIME_QUOTA_PROVIDER_IDS, SESSION_PROVIDER_IDS, } from '../providerIds';
|
|
13
14
|
export { messageUsageSchema, sessionMessageSchema, sessionEventSchema, permissionModeSchema, extractSessionEvents, userSessionEventSchema, assistantSessionEventSchema, summarySessionEventSchema, systemSessionEventSchema, toolUseSessionEventSchema, toolResultSessionEventSchema, } from './sessionEvent';
|
|
14
15
|
export type { MessageUsage, SessionMessage, SessionEvent, PermissionMode, } from '../types/sessionEvent';
|
|
15
16
|
export { normalizedUsageSchema, normalizedUsageCostSchema } from './usageNormalization';
|
|
@@ -35,3 +36,5 @@ export type { AccountProviderId, SavedAccountProfile } from '../accountRegistry'
|
|
|
35
36
|
export type { AccountLoginStatus, BeginAccountLoginResult, ListAllAccountsResult, } from '../accountManager';
|
|
36
37
|
export { assistantTurnEventSchema, assistantTurnEventTypeSchema, assistantTurnNarrationStepSchema, assistantTurnProcessSchema, assistantTurnProcessStepSchema, assistantTurnProjectionSchema, assistantTurnReasoningTimelineItemSchema, assistantTurnSubagentSchema, assistantTurnSubagentStatusSchema, assistantTurnTimelineItemSchema, assistantTurnToolGroupStepSchema, assistantTurnToolRefSchema, } from './assistantTurn';
|
|
37
38
|
export type { AssistantTurnEvent, AssistantTurnEventType, AssistantTurnProcess, AssistantTurnProcessStep, AssistantTurnProjection, AssistantTurnSubagent, AssistantTurnSubagentStatus, AssistantTurnTimelineItem, AssistantTurnToolRef, } from '../turns/assistantTurn';
|
|
39
|
+
export { sidekickStateFileSchema, stateFileAccountSchema, stateFileBillingBlockSchema, stateFileContextSchema, stateFileQuotaSchema, stateFileQuotaWindowSchema, stateFileSessionSchema, stateFileWriterSchema, } from './stateFile';
|
|
40
|
+
export type { SidekickStateFile, StateFileAccount, StateFileBillingBlock, StateFileContext, StateFileQuota, StateFileQuotaWindow, StateFileSession, StateFileWriter, } from '../stateFile';
|
package/dist/schemas/index.js
CHANGED
|
@@ -12,8 +12,13 @@
|
|
|
12
12
|
* subpath is self-sufficient for boundary-validation modules.
|
|
13
13
|
*/
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
exports.assistantTurnToolRefSchema = exports.assistantTurnToolGroupStepSchema = exports.assistantTurnTimelineItemSchema = exports.assistantTurnSubagentStatusSchema = exports.assistantTurnSubagentSchema = exports.assistantTurnReasoningTimelineItemSchema = exports.assistantTurnProjectionSchema = exports.assistantTurnProcessStepSchema = exports.assistantTurnProcessSchema = exports.assistantTurnNarrationStepSchema = exports.assistantTurnEventTypeSchema = exports.assistantTurnEventSchema = exports.listAllAccountsResultSchema = exports.savedAccountProfileSchema = exports.accountEntrySchema = void 0;
|
|
15
|
+
exports.activeAccountStatusSchema = exports.activeProviderAccountStatusSchema = exports.quotaHistoryDailyBucketSchema = exports.quotaHistorySampleSchema = exports.quotaHistoryRuntimeProviderSchema = exports.providerQuotaMapSchema = exports.zaiProviderQuotaStateSchema = exports.codexProviderQuotaStateSchema = exports.claudeProviderQuotaStateSchema = exports.providerQuotaStateSchema = exports.runtimeQuotaProviderSchema = exports.quotaFailureDescriptorSchema = exports.peakHoursStateSchema = exports.codexResetCreditsSnapshotSchema = exports.codexResetCreditSchema = exports.quotaSourceSchema = exports.quotaProviderIdSchema = exports.quotaFailureKindSchema = exports.quotaStateSchema = exports.quotaWindowSchema = exports.sessionEvidenceRefV1Schema = exports.providerSessionAdapterV1Schema = exports.providerCapabilitiesV1Schema = exports.pendingUserRequestV1Schema = exports.observedValueV1Schema = exports.observedAgentSessionV1Schema = exports.observationProvenanceV1Schema = exports.canonicalSessionTranscriptSchema = exports.canonicalTranscriptMessageSchema = exports.canonicalToolCallSchema = exports.canonicalTranscriptBlockSchema = exports.transcriptSourceProvenanceSchema = exports.tokenEstimateSchema = exports.normalizedUsageCostSchema = exports.normalizedUsageSchema = exports.toolResultSessionEventSchema = exports.toolUseSessionEventSchema = exports.systemSessionEventSchema = exports.summarySessionEventSchema = exports.assistantSessionEventSchema = exports.userSessionEventSchema = exports.extractSessionEvents = exports.permissionModeSchema = exports.sessionEventSchema = exports.sessionMessageSchema = exports.messageUsageSchema = exports.SESSION_PROVIDER_IDS = exports.RUNTIME_QUOTA_PROVIDER_IDS = exports.QUOTA_PROVIDER_IDS = exports.ACCOUNT_PROVIDER_IDS = void 0;
|
|
16
|
+
exports.stateFileWriterSchema = exports.stateFileSessionSchema = exports.stateFileQuotaWindowSchema = exports.stateFileQuotaSchema = exports.stateFileContextSchema = exports.stateFileBillingBlockSchema = exports.stateFileAccountSchema = exports.sidekickStateFileSchema = exports.assistantTurnToolRefSchema = exports.assistantTurnToolGroupStepSchema = exports.assistantTurnTimelineItemSchema = exports.assistantTurnSubagentStatusSchema = exports.assistantTurnSubagentSchema = exports.assistantTurnReasoningTimelineItemSchema = exports.assistantTurnProjectionSchema = exports.assistantTurnProcessStepSchema = exports.assistantTurnProcessSchema = exports.assistantTurnNarrationStepSchema = exports.assistantTurnEventTypeSchema = exports.assistantTurnEventSchema = exports.listAllAccountsResultSchema = exports.savedAccountProfileSchema = exports.accountEntrySchema = exports.accountLoginStatusSchema = exports.beginAccountLoginResultSchema = exports.accountManagerResultSchema = exports.accountProviderIdSchema = void 0;
|
|
17
|
+
var providerIds_1 = require("../providerIds");
|
|
18
|
+
Object.defineProperty(exports, "ACCOUNT_PROVIDER_IDS", { enumerable: true, get: function () { return providerIds_1.ACCOUNT_PROVIDER_IDS; } });
|
|
19
|
+
Object.defineProperty(exports, "QUOTA_PROVIDER_IDS", { enumerable: true, get: function () { return providerIds_1.QUOTA_PROVIDER_IDS; } });
|
|
20
|
+
Object.defineProperty(exports, "RUNTIME_QUOTA_PROVIDER_IDS", { enumerable: true, get: function () { return providerIds_1.RUNTIME_QUOTA_PROVIDER_IDS; } });
|
|
21
|
+
Object.defineProperty(exports, "SESSION_PROVIDER_IDS", { enumerable: true, get: function () { return providerIds_1.SESSION_PROVIDER_IDS; } });
|
|
17
22
|
var sessionEvent_1 = require("./sessionEvent");
|
|
18
23
|
Object.defineProperty(exports, "messageUsageSchema", { enumerable: true, get: function () { return sessionEvent_1.messageUsageSchema; } });
|
|
19
24
|
Object.defineProperty(exports, "sessionMessageSchema", { enumerable: true, get: function () { return sessionEvent_1.sessionMessageSchema; } });
|
|
@@ -89,3 +94,12 @@ Object.defineProperty(exports, "assistantTurnSubagentStatusSchema", { enumerable
|
|
|
89
94
|
Object.defineProperty(exports, "assistantTurnTimelineItemSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnTimelineItemSchema; } });
|
|
90
95
|
Object.defineProperty(exports, "assistantTurnToolGroupStepSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnToolGroupStepSchema; } });
|
|
91
96
|
Object.defineProperty(exports, "assistantTurnToolRefSchema", { enumerable: true, get: function () { return assistantTurn_1.assistantTurnToolRefSchema; } });
|
|
97
|
+
var stateFile_1 = require("./stateFile");
|
|
98
|
+
Object.defineProperty(exports, "sidekickStateFileSchema", { enumerable: true, get: function () { return stateFile_1.sidekickStateFileSchema; } });
|
|
99
|
+
Object.defineProperty(exports, "stateFileAccountSchema", { enumerable: true, get: function () { return stateFile_1.stateFileAccountSchema; } });
|
|
100
|
+
Object.defineProperty(exports, "stateFileBillingBlockSchema", { enumerable: true, get: function () { return stateFile_1.stateFileBillingBlockSchema; } });
|
|
101
|
+
Object.defineProperty(exports, "stateFileContextSchema", { enumerable: true, get: function () { return stateFile_1.stateFileContextSchema; } });
|
|
102
|
+
Object.defineProperty(exports, "stateFileQuotaSchema", { enumerable: true, get: function () { return stateFile_1.stateFileQuotaSchema; } });
|
|
103
|
+
Object.defineProperty(exports, "stateFileQuotaWindowSchema", { enumerable: true, get: function () { return stateFile_1.stateFileQuotaWindowSchema; } });
|
|
104
|
+
Object.defineProperty(exports, "stateFileSessionSchema", { enumerable: true, get: function () { return stateFile_1.stateFileSessionSchema; } });
|
|
105
|
+
Object.defineProperty(exports, "stateFileWriterSchema", { enumerable: true, get: function () { return stateFile_1.stateFileWriterSchema; } });
|