@laoyuehanni/dsh-token-usage 0.4.1 → 0.4.2
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 -10
- package/README.zh.md +2 -10
- package/docs/pricing.md +3 -13
- package/lib/client/PricingDialog.d.ts +51 -0
- package/lib/client/PricingDialog.d.ts.map +1 -0
- package/lib/client/PricingDialog.js +127 -0
- package/lib/client/PricingDialog.js.map +1 -0
- package/lib/client/PricingOverviewDialog.d.ts +76 -0
- package/lib/client/PricingOverviewDialog.d.ts.map +1 -0
- package/lib/client/PricingOverviewDialog.js +361 -0
- package/lib/client/PricingOverviewDialog.js.map +1 -0
- package/lib/client/SessionTable.d.ts +39 -0
- package/lib/client/SessionTable.d.ts.map +1 -0
- package/lib/client/SessionTable.js +181 -0
- package/lib/client/SessionTable.js.map +1 -0
- package/lib/client/TokenUsageSection.d.ts +16 -9
- package/lib/client/TokenUsageSection.d.ts.map +1 -1
- package/lib/client/TokenUsageSection.js +66 -128
- package/lib/client/TokenUsageSection.js.map +1 -1
- package/lib/client/index.d.ts +3 -2
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +23 -3
- package/lib/client/index.js.map +1 -1
- package/lib/client/locales.d.ts +25 -0
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client/locales.js +50 -0
- package/lib/client/locales.js.map +1 -1
- package/lib/client.js +1386 -293
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +47 -10
- package/lib/index.js.map +1 -1
- package/lib/migrate.d.ts +3 -2
- package/lib/migrate.d.ts.map +1 -1
- package/lib/migrate.js +4 -2
- package/lib/migrate.js.map +1 -1
- package/lib/pricing.d.ts +29 -23
- package/lib/pricing.d.ts.map +1 -1
- package/lib/pricing.js +38 -50
- package/lib/pricing.js.map +1 -1
- package/lib/rollup.d.ts +7 -1
- package/lib/rollup.d.ts.map +1 -1
- package/lib/rollup.js +15 -0
- package/lib/rollup.js.map +1 -1
- package/lib/session-meta.d.ts +68 -0
- package/lib/session-meta.d.ts.map +1 -0
- package/lib/session-meta.js +174 -0
- package/lib/session-meta.js.map +1 -0
- package/lib/stats-route.d.ts +22 -0
- package/lib/stats-route.d.ts.map +1 -1
- package/lib/stats-route.js +85 -6
- package/lib/stats-route.js.map +1 -1
- package/lib/stats.d.ts +35 -3
- package/lib/stats.d.ts.map +1 -1
- package/lib/stats.js +185 -6
- package/lib/stats.js.map +1 -1
- package/lib/sync-state.d.ts +42 -10
- package/lib/sync-state.d.ts.map +1 -1
- package/lib/sync-state.js +61 -19
- package/lib/sync-state.js.map +1 -1
- package/lib/sync.d.ts +55 -9
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +55 -10
- package/lib/sync.js.map +1 -1
- package/lib/wire.d.ts +114 -10
- package/lib/wire.d.ts.map +1 -1
- package/lib/wire.js +3 -0
- package/lib/wire.js.map +1 -1
- package/package.json +1 -1
package/lib/sync-state.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* One-shot initialization
|
|
3
|
-
* sync
|
|
4
|
-
*
|
|
2
|
+
* One-shot initialization markers: whether the plugin ever completed a
|
|
3
|
+
* history sync (`initializedAt`) and whether a sync has since folded the
|
|
4
|
+
* session metadata (titles, header facts) into `sessions.json`
|
|
5
|
+
* (`metaSyncedAt`). The markers exist only to gate automatic runs; every
|
|
6
|
+
* later sync is the user's decision (the manual command). A missing or
|
|
7
|
+
* malformed marker reads as unmet: the next startup re-runs the gated
|
|
8
|
+
* work, whose dedupe and idempotent upserts make the repetition a no-op.
|
|
5
9
|
*
|
|
6
10
|
* @module token-usage/sync-state
|
|
7
11
|
*/
|
|
@@ -11,26 +15,26 @@ import { consoleLogger } from "./log.js";
|
|
|
11
15
|
const STATE_FILE = 'state.json';
|
|
12
16
|
const TMP_FILE = 'state.json.tmp';
|
|
13
17
|
function isSyncState(value) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
if (typeof value !== 'object' || value === null)
|
|
19
|
+
return false;
|
|
20
|
+
const state = value;
|
|
21
|
+
return typeof state.initializedAt === 'number' && Number.isFinite(state.initializedAt);
|
|
17
22
|
}
|
|
18
23
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* dedupe makes the repetition a no-op.
|
|
24
|
+
* Read the marker file. A missing or malformed file reads as null — the
|
|
25
|
+
* caller treats that as unmet and re-runs the gated work idempotently.
|
|
22
26
|
* @param dir - the data directory holding the marker.
|
|
23
27
|
*/
|
|
24
|
-
export async function
|
|
28
|
+
export async function readSyncState(dir, logger = consoleLogger) {
|
|
25
29
|
let text;
|
|
26
30
|
try {
|
|
27
31
|
text = await readFile(join(dir, STATE_FILE), 'utf8');
|
|
28
32
|
}
|
|
29
33
|
catch (error) {
|
|
30
34
|
if (error.code === 'ENOENT')
|
|
31
|
-
return
|
|
35
|
+
return null;
|
|
32
36
|
logger.error('[token-usage] cannot read state:', error);
|
|
33
|
-
return
|
|
37
|
+
return null;
|
|
34
38
|
}
|
|
35
39
|
let value;
|
|
36
40
|
try {
|
|
@@ -38,20 +42,58 @@ export async function isInitialized(dir, logger = consoleLogger) {
|
|
|
38
42
|
}
|
|
39
43
|
catch {
|
|
40
44
|
// Malformed marker: treat as uninitialized (the sync re-runs idempotently).
|
|
41
|
-
return
|
|
45
|
+
return null;
|
|
42
46
|
}
|
|
43
|
-
return isSyncState(value);
|
|
47
|
+
return isSyncState(value) ? value : null;
|
|
44
48
|
}
|
|
45
49
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
50
|
+
* Whether the first automatic sync already completed. A missing or
|
|
51
|
+
* malformed marker reads as uninitialized: the next startup re-runs the
|
|
52
|
+
* sync, whose dedupe makes the repetition a no-op.
|
|
48
53
|
* @param dir - the data directory holding the marker.
|
|
49
|
-
* @param now - clock source (test seam).
|
|
50
54
|
*/
|
|
51
|
-
export async function
|
|
55
|
+
export async function isInitialized(dir, logger = consoleLogger) {
|
|
56
|
+
return (await readSyncState(dir, logger)) !== null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Persist the marker file atomically (temp file + rename), so a crash
|
|
60
|
+
* mid-write never leaves a torn marker that would misread as settled.
|
|
61
|
+
* Fields absent from `state` are omitted, never null.
|
|
62
|
+
* @param dir - the data directory holding the marker.
|
|
63
|
+
* @param state - the marker contents to write.
|
|
64
|
+
*/
|
|
65
|
+
export async function writeSyncState(dir, state) {
|
|
52
66
|
const target = join(dir, STATE_FILE);
|
|
53
67
|
const tmp = join(dir, TMP_FILE);
|
|
54
|
-
await writeFile(tmp, JSON.stringify(
|
|
68
|
+
await writeFile(tmp, JSON.stringify(state), 'utf8');
|
|
55
69
|
await rename(tmp, target);
|
|
56
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Persist the initialized marker (and, when the caller says the same run
|
|
73
|
+
* folded the metadata, the meta marker alongside it). An existing
|
|
74
|
+
* `metaSyncedAt` survives: the first-sync write must not revoke a backfill
|
|
75
|
+
* an earlier upgrade already completed.
|
|
76
|
+
* @param dir - the data directory holding the marker.
|
|
77
|
+
* @param now - clock source (test seam).
|
|
78
|
+
* @param withMeta - whether this run also folded session metadata.
|
|
79
|
+
*/
|
|
80
|
+
export async function markInitialized(dir, now = () => new Date(), withMeta = false) {
|
|
81
|
+
const existing = await readSyncState(dir);
|
|
82
|
+
await writeSyncState(dir, {
|
|
83
|
+
initializedAt: now().getTime(),
|
|
84
|
+
...(existing?.metaSyncedAt !== undefined
|
|
85
|
+
? { metaSyncedAt: existing.metaSyncedAt }
|
|
86
|
+
: withMeta ? { metaSyncedAt: now().getTime() } : {}),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Stamp the metadata backfill as done, preserving `initializedAt`.
|
|
91
|
+
* @param dir - the data directory holding the marker.
|
|
92
|
+
* @param now - clock source (test seam).
|
|
93
|
+
*/
|
|
94
|
+
export async function markMetaSynced(dir, now = () => new Date()) {
|
|
95
|
+
const existing = await readSyncState(dir);
|
|
96
|
+
const initializedAt = existing?.initializedAt ?? now().getTime();
|
|
97
|
+
await writeSyncState(dir, { initializedAt, metaSyncedAt: now().getTime() });
|
|
98
|
+
}
|
|
57
99
|
//# sourceMappingURL=sync-state.js.map
|
package/lib/sync-state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-state.js","sourceRoot":"","sources":["../src/sync-state.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sync-state.js","sourceRoot":"","sources":["../src/sync-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,aAAa,EAAmB,MAAM,UAAU,CAAA;AAEzD,MAAM,UAAU,GAAG,YAAY,CAAA;AAC/B,MAAM,QAAQ,GAAG,gBAAgB,CAAA;AAajC,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAA;IAC7D,MAAM,KAAK,GAAG,KAAgC,CAAA;IAC9C,OAAO,OAAO,KAAK,CAAC,aAAa,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;AACxF,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,GAAW,EAAE,SAAqB,aAAa;IACjF,IAAI,IAAY,CAAA;IAChB,IAAI,CAAC;QACH,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAA;IACtD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,K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EAAE,CAAC,OAAO,EAAE;QAC9B,GAAG,CAAC,QAAQ,EAAE,YAAY,KAAK,SAAS;YACtC,CAAC,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,YAAY,EAAE;YACzC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvD,CAAC,CAAA;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAW,EAAE,MAAkB,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;IAClF,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,CAAA;IACzC,MAAM,aAAa,GAAG,QAAQ,EAAE,aAAa,IAAI,GAAG,EAAE,CAAC,OAAO,EAAE,CAAA;IAChE,MAAM,cAAc,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;AAC7E,CAAC"}
|
package/lib/sync.d.ts
CHANGED
|
@@ -47,15 +47,41 @@ export interface SyncProgressTick {
|
|
|
47
47
|
* validate; they count as processed for the progress bar. */
|
|
48
48
|
failedSessions: number;
|
|
49
49
|
}
|
|
50
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* The header facts the metadata index captures (the duck-typed projection
|
|
52
|
+
* of the host's `SessionHeader`): the working directory, the subagent
|
|
53
|
+
* classification, and the parent lineage. All three are immutable per
|
|
54
|
+
* session, so one upsert per session per run suffices.
|
|
55
|
+
*/
|
|
56
|
+
export interface SessionHeaderFacts {
|
|
57
|
+
cwd?: string;
|
|
58
|
+
origin?: 'subagent';
|
|
59
|
+
parentSession?: string;
|
|
60
|
+
}
|
|
61
|
+
/** The metadata sink the sync folds identity facts into (duck-typed for
|
|
62
|
+
* tests; the host passes a {@link SessionMetaStore}). */
|
|
63
|
+
export interface SyncMetaSink {
|
|
64
|
+
upsert(id: string, patch: SessionHeaderFacts & {
|
|
65
|
+
title?: string;
|
|
66
|
+
}): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
/** The persistence surface the sync needs (duck-typed for tests). The
|
|
69
|
+
* host's `inspect` returns a `SessionInspection` — `meta` (the immutable
|
|
70
|
+
* session header) rides alongside `events`; older duck types that omit it
|
|
71
|
+
* simply contribute no header facts. */
|
|
51
72
|
export interface SyncPersistence {
|
|
52
73
|
/** Every materialized session, in arbitrary order. */
|
|
53
74
|
list(signal?: AbortSignal): Promise<{
|
|
54
75
|
id: SessionId;
|
|
55
76
|
}[]>;
|
|
56
|
-
/** Immutable logical event log of one session. */
|
|
77
|
+
/** Immutable logical event log of one session, with its header. */
|
|
57
78
|
inspect(id: SessionId, signal?: AbortSignal): Promise<{
|
|
58
79
|
events: readonly SessionEvent[];
|
|
80
|
+
meta?: {
|
|
81
|
+
cwd?: string;
|
|
82
|
+
origin?: 'subagent';
|
|
83
|
+
parentSession?: SessionId;
|
|
84
|
+
};
|
|
59
85
|
}>;
|
|
60
86
|
}
|
|
61
87
|
/** Dependencies of one sync run. */
|
|
@@ -65,11 +91,24 @@ export interface SyncDeps {
|
|
|
65
91
|
/** Whether the sync records `compaction/summary` events (default true,
|
|
66
92
|
* mirroring the `recordCompaction` config). */
|
|
67
93
|
recordCompaction?: boolean;
|
|
94
|
+
/** Metadata sink for the session table's identity fields: the walk folds
|
|
95
|
+
* each session's latest-wins `session/title` text and its immutable
|
|
96
|
+
* header facts (cwd, lineage) into it. Absent → no metadata capture
|
|
97
|
+
* (the usage walk still runs). */
|
|
98
|
+
meta?: SyncMetaSink;
|
|
68
99
|
/** Called once per session whose stored log failed to load or validate
|
|
69
100
|
* (the session is then skipped). The host uses this to log which session
|
|
70
101
|
* and why; aborts raised through `signal` are re-thrown, never reported. */
|
|
71
102
|
onSessionFailure?: (id: SessionId, error: unknown) => void;
|
|
72
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* The latest-wins `session/title` text of one event, or undefined: the
|
|
106
|
+
* event type is host-merged (`dsh-session-title`), so the plugin reads the
|
|
107
|
+
* payload duck-typed and tolerantly — a non-string or empty title is
|
|
108
|
+
* skipped, never fabricated. Exported for the live recorder, which folds
|
|
109
|
+
* the same event into the same index.
|
|
110
|
+
*/
|
|
111
|
+
export declare function titleOfEvent(event: SessionEvent): string | undefined;
|
|
73
112
|
/**
|
|
74
113
|
* Append every missing request row. The log's dedupe set is rebuilt from the
|
|
75
114
|
* data files first, so a second run is a no-op and rows recorded live in a
|
|
@@ -83,13 +122,20 @@ export interface SyncDeps {
|
|
|
83
122
|
*/
|
|
84
123
|
export declare function syncHistory(deps: SyncDeps, onTick?: (tick: SyncProgressTick) => void, signal?: AbortSignal): Promise<SyncResult>;
|
|
85
124
|
/**
|
|
86
|
-
* Run the
|
|
87
|
-
*
|
|
88
|
-
* the
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
125
|
+
* Run the gated automatic work, then persist the markers:
|
|
126
|
+
* - No `initializedAt` — the first-run backfill: one full sync (which also
|
|
127
|
+
* folds the metadata), then both markers land together.
|
|
128
|
+
* - `initializedAt` present, `metaSyncedAt` absent — a pre-session-table
|
|
129
|
+
* install owes exactly one metadata backfill: run the same sync once
|
|
130
|
+
* more (every usage row dedupes to a no-op write; the walk lands the
|
|
131
|
+
* titles and header facts the old build never stored), then stamp
|
|
132
|
+
* `metaSyncedAt`.
|
|
133
|
+
* - Both markers present — nothing to do.
|
|
134
|
+
* A crash before the marker write leaves the marker absent, so the next
|
|
135
|
+
* startup re-runs — a no-op thanks to dedupe and idempotent upserts.
|
|
136
|
+
* @param deps - persistence and the shared log (with the metadata sink).
|
|
137
|
+
* @param dir - the data directory holding the markers.
|
|
138
|
+
* @returns the sync outcome, or null when both markers were already set.
|
|
93
139
|
*/
|
|
94
140
|
export declare function autoSyncIfNeeded(deps: SyncDeps, dir: string): Promise<SyncResult | null>;
|
|
95
141
|
//# sourceMappingURL=sync.d.ts.map
|
package/lib/sync.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAQvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAE9C,+BAA+B;AAC/B,MAAM,WAAW,UAAU;IACzB,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAA;IACf;;6DAEyD;IACzD,cAAc,EAAE,MAAM,CAAA;CACvB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAA;IACjB,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAA;IACb,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAA;IACb,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAA;IACf;iEAC6D;IAC7D,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAQvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAE9C,+BAA+B;AAC/B,MAAM,WAAW,UAAU;IACzB,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAA;IACf;;6DAEyD;IACzD,cAAc,EAAE,MAAM,CAAA;CACvB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;I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YAAY,CAAA;IACnB;;gFAE4E;IAC5E,gBAAgB,CAAC,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CAC3D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAIpE;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,QAAQ,EACd,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,EACzC,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,CAAC,CAmErB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAO9F"}
|
package/lib/sync.js
CHANGED
|
@@ -13,8 +13,21 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @module token-usage/sync
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
16
|
+
import { markInitialized, markMetaSynced, readSyncState } from "./sync-state.js";
|
|
17
17
|
import { modelOfEvent, recordOfEvent } from "./usage-record.js";
|
|
18
|
+
/**
|
|
19
|
+
* The latest-wins `session/title` text of one event, or undefined: the
|
|
20
|
+
* event type is host-merged (`dsh-session-title`), so the plugin reads the
|
|
21
|
+
* payload duck-typed and tolerantly — a non-string or empty title is
|
|
22
|
+
* skipped, never fabricated. Exported for the live recorder, which folds
|
|
23
|
+
* the same event into the same index.
|
|
24
|
+
*/
|
|
25
|
+
export function titleOfEvent(event) {
|
|
26
|
+
if (event.type !== 'session/title')
|
|
27
|
+
return undefined;
|
|
28
|
+
const title = event.data?.title;
|
|
29
|
+
return typeof title === 'string' && title !== '' ? title : undefined;
|
|
30
|
+
}
|
|
18
31
|
/**
|
|
19
32
|
* Append every missing request row. The log's dedupe set is rebuilt from the
|
|
20
33
|
* data files first, so a second run is a no-op and rows recorded live in a
|
|
@@ -59,11 +72,18 @@ export async function syncHistory(deps, onTick, signal) {
|
|
|
59
72
|
// attribute, and turn/end names none, so the walk follows the same
|
|
60
73
|
// request/context + assistant/message events the live recorder does.
|
|
61
74
|
let model = '';
|
|
75
|
+
// Latest-wins title: title events append in seq order, so the LAST one
|
|
76
|
+
// seen is the current title — a rename, an auto-generated title, and a
|
|
77
|
+
// fallback all land as the same append, one fold covers every source.
|
|
78
|
+
let title;
|
|
62
79
|
for (const event of inspection.events) {
|
|
63
80
|
signal?.throwIfAborted();
|
|
64
81
|
const revealed = modelOfEvent(event);
|
|
65
82
|
if (revealed !== undefined)
|
|
66
83
|
model = revealed;
|
|
84
|
+
const revealedTitle = titleOfEvent(event);
|
|
85
|
+
if (revealedTitle !== undefined)
|
|
86
|
+
title = revealedTitle;
|
|
67
87
|
const record = recordOfEvent(event, session.id, model, deps.recordCompaction !== false);
|
|
68
88
|
if (record === null)
|
|
69
89
|
continue;
|
|
@@ -72,25 +92,50 @@ export async function syncHistory(deps, onTick, signal) {
|
|
|
72
92
|
else
|
|
73
93
|
skipped += 1;
|
|
74
94
|
}
|
|
95
|
+
// One metadata upsert per session: the title fold above plus the
|
|
96
|
+
// immutable header facts. The upsert is a no-op when nothing changed,
|
|
97
|
+
// so repeat syncs never rewrite the index.
|
|
98
|
+
if (deps.meta !== undefined) {
|
|
99
|
+
const header = inspection.meta;
|
|
100
|
+
const patch = {
|
|
101
|
+
...(title !== undefined ? { title } : {}),
|
|
102
|
+
...(header?.cwd !== undefined && header.cwd !== '' ? { cwd: header.cwd } : {}),
|
|
103
|
+
...(header?.origin !== undefined ? { origin: header.origin } : {}),
|
|
104
|
+
...(header?.parentSession !== undefined && header.parentSession !== '' ? { parentSession: header.parentSession } : {}),
|
|
105
|
+
};
|
|
106
|
+
if (Object.keys(patch).length > 0)
|
|
107
|
+
await deps.meta.upsert(session.id, patch);
|
|
108
|
+
}
|
|
75
109
|
processed += 1;
|
|
76
110
|
onTick?.({ processed, total, added, skipped, failedSessions });
|
|
77
111
|
}
|
|
78
112
|
return { added, skipped, failedSessions };
|
|
79
113
|
}
|
|
80
114
|
/**
|
|
81
|
-
* Run the
|
|
82
|
-
*
|
|
83
|
-
* the
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
115
|
+
* Run the gated automatic work, then persist the markers:
|
|
116
|
+
* - No `initializedAt` — the first-run backfill: one full sync (which also
|
|
117
|
+
* folds the metadata), then both markers land together.
|
|
118
|
+
* - `initializedAt` present, `metaSyncedAt` absent — a pre-session-table
|
|
119
|
+
* install owes exactly one metadata backfill: run the same sync once
|
|
120
|
+
* more (every usage row dedupes to a no-op write; the walk lands the
|
|
121
|
+
* titles and header facts the old build never stored), then stamp
|
|
122
|
+
* `metaSyncedAt`.
|
|
123
|
+
* - Both markers present — nothing to do.
|
|
124
|
+
* A crash before the marker write leaves the marker absent, so the next
|
|
125
|
+
* startup re-runs — a no-op thanks to dedupe and idempotent upserts.
|
|
126
|
+
* @param deps - persistence and the shared log (with the metadata sink).
|
|
127
|
+
* @param dir - the data directory holding the markers.
|
|
128
|
+
* @returns the sync outcome, or null when both markers were already set.
|
|
88
129
|
*/
|
|
89
130
|
export async function autoSyncIfNeeded(deps, dir) {
|
|
90
|
-
|
|
131
|
+
const state = await readSyncState(dir);
|
|
132
|
+
if (state !== null && state.metaSyncedAt !== undefined)
|
|
91
133
|
return null;
|
|
92
134
|
const result = await syncHistory(deps);
|
|
93
|
-
|
|
135
|
+
if (state === null)
|
|
136
|
+
await markInitialized(dir, undefined, true);
|
|
137
|
+
else
|
|
138
|
+
await markMetaSynced(dir);
|
|
94
139
|
return result;
|
|
95
140
|
}
|
|
96
141
|
//# sourceMappingURL=sync.js.map
|
package/lib/sync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAA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KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAA;IAChE,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,CAAA;AAC3C,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAAc,EAAE,GAAW;IAChE,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,CAAA;IACtC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,YAAY,KAAK,SAAS;QAAE,OAAO,IAAI,CAAA;IACnE,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,CAAA;IACtC,IAAI,KAAK,KAAK,IAAI;QAAE,MAAM,eAAe,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;;QAC1D,MAAM,cAAc,CAAC,GAAG,CAAC,CAAA;IAC9B,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/lib/wire.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ import type { UsageRecord } from './usage-record.ts';
|
|
|
10
10
|
export type { UsageFields, UsageRecord } from './usage-record.ts';
|
|
11
11
|
/** The stats endpoint path, served by the host half's webServer route. */
|
|
12
12
|
export declare const STATS_PATH = "/token-usage/stats";
|
|
13
|
+
/** The pricing-overview endpoint path: the full cloud-mirror model list,
|
|
14
|
+
* filter-free by design — the overview is not a filtered usage view. */
|
|
15
|
+
export declare const PRICING_PATH = "/token-usage/pricing";
|
|
13
16
|
/** How much of the stats payload a consumer asked for. `full` is the
|
|
14
17
|
* settings page's whole CostedSummary; `session` is the usage tab; `chip`
|
|
15
18
|
* is the header strip (totals only). */
|
|
@@ -233,8 +236,7 @@ export interface TimeRule {
|
|
|
233
236
|
/**
|
|
234
237
|
* The full pricing of one model: the base rates plus the rule chain the
|
|
235
238
|
* analyzer resolves per request — time-rule container first, then context
|
|
236
|
-
* tier, then peak slot.
|
|
237
|
-
* overrides replace the model's cloud rules wholesale).
|
|
239
|
+
* tier, then peak slot.
|
|
238
240
|
*/
|
|
239
241
|
export interface ModelRates {
|
|
240
242
|
base: ModelPricing;
|
|
@@ -265,13 +267,39 @@ export declare const UNPRICED_KEY: RateKey;
|
|
|
265
267
|
/** Whether a key is the neutral unpriced one. */
|
|
266
268
|
export declare function isUnpricedKey(key: RateKey): boolean;
|
|
267
269
|
/**
|
|
268
|
-
* The
|
|
269
|
-
* `<data dir>/pricing.ccsa.json` (cloud mirror
|
|
270
|
-
* `<data dir>/pricing.json` (hand-edited flat overrides; see pricing.ts).
|
|
270
|
+
* The pricing table: model id → full rule set, loaded from
|
|
271
|
+
* `<data dir>/pricing.ccsa.json` (the cloud mirror; see pricing.ts).
|
|
271
272
|
* Models absent from the table are unpriced: their cost counts as 0 and they
|
|
272
273
|
* surface in {@link UsageSummary.unpricedModels}.
|
|
273
274
|
*/
|
|
274
275
|
export type PricingTable = Record<string, ModelRates>;
|
|
276
|
+
/**
|
|
277
|
+
* One model row of the pricing overview: the shape the cloud feed carries
|
|
278
|
+
* (modelId + its aliases + its upstream family) plus the full rule set —
|
|
279
|
+
* deliberately NOT flattened through {@link PricingTable}, so the overview
|
|
280
|
+
* shows one row per model with aliases as a footnote instead of one row per
|
|
281
|
+
* alias-key.
|
|
282
|
+
*/
|
|
283
|
+
export interface PricingOverviewModel {
|
|
284
|
+
modelId: string;
|
|
285
|
+
/** The feed's alias list for this model (empty when it carries none). */
|
|
286
|
+
aliases: readonly string[];
|
|
287
|
+
/** The feed's upstream family grouping; absent rows group under `other`. */
|
|
288
|
+
family?: string;
|
|
289
|
+
rules: ModelRates;
|
|
290
|
+
}
|
|
291
|
+
/** The payload served at {@link PRICING_PATH}: every cloud-mirror model row
|
|
292
|
+
* plus the display-currency stamps the settings page converts with (same
|
|
293
|
+
* region source as the stats payload). */
|
|
294
|
+
export interface PricingOverviewPayload {
|
|
295
|
+
models: readonly PricingOverviewModel[];
|
|
296
|
+
/** The display currency the page converts rate figures into. Amounts on
|
|
297
|
+
* the wire (rules rates) remain RMB. */
|
|
298
|
+
currency: DisplayCurrency;
|
|
299
|
+
/** Effective RMB-per-USD rate (feed value, else the built-in default);
|
|
300
|
+
* the divisor when `currency` is USD. */
|
|
301
|
+
usdExchangeRate: number;
|
|
302
|
+
}
|
|
275
303
|
/** One per-day × per-model × per-rate aggregation row. */
|
|
276
304
|
export interface UsageRateRow {
|
|
277
305
|
day: string;
|
|
@@ -279,6 +307,55 @@ export interface UsageRateRow {
|
|
|
279
307
|
rate: RateKey;
|
|
280
308
|
totals: UsageTotals;
|
|
281
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* One per-session × per-day × per-model × per-rate aggregation row: the
|
|
312
|
+
* session dimension the settings page's cross-session table folds from.
|
|
313
|
+
* Every granule pulls its weight — a session usually spans days (the day
|
|
314
|
+
* key keeps a date-filtered row to the window's share), the model key keeps
|
|
315
|
+
* a model-filtered row honest, the rate identity keeps cost re-pricing
|
|
316
|
+
* free, and `lastTime` sorts the table by recent activity. Failure rows
|
|
317
|
+
* (`model === ''`) fold in like every other record: the session dimension
|
|
318
|
+
* keeps the same totals semantics as rateRows, so request counts reconcile.
|
|
319
|
+
*/
|
|
320
|
+
export interface UsageSessionRow {
|
|
321
|
+
sessionId: string;
|
|
322
|
+
day: string;
|
|
323
|
+
model: string;
|
|
324
|
+
rate: RateKey;
|
|
325
|
+
/** Newest record time folded into this cell (max over the fold); the
|
|
326
|
+
* session table's "last active" column. */
|
|
327
|
+
lastTime: number;
|
|
328
|
+
totals: UsageTotals;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* One final row of the settings page's session table: the server-side fold
|
|
332
|
+
* of {@link UsageSessionRow} cells over one top-level session plus its
|
|
333
|
+
* whole subtree, sorted by cost and truncated top-N before it crosses the
|
|
334
|
+
* wire. Subagents never surface as rows of their own — the row's
|
|
335
|
+
* `childCount` badge is their only visibility here. Identity fields ride
|
|
336
|
+
* in the row — the server folds, sorts, and truncates, so the client never
|
|
337
|
+
* reassembles titles or directories.
|
|
338
|
+
*/
|
|
339
|
+
export interface SessionUsageRow {
|
|
340
|
+
sessionId: string;
|
|
341
|
+
/** Log-backed latest-wins title; omitted when no `session/title` event
|
|
342
|
+
* ever landed (the client falls back to a short session id + times). */
|
|
343
|
+
title?: string;
|
|
344
|
+
/** The session header's working directory, verbatim; omitted when the
|
|
345
|
+
* header carried none. The client derives the tail segment and grouping. */
|
|
346
|
+
cwd?: string;
|
|
347
|
+
/** How many descendant sessions folded into this row (the subagent
|
|
348
|
+
* badge); omitted when the subtree holds none. */
|
|
349
|
+
childCount?: number;
|
|
350
|
+
totals: UsageTotals;
|
|
351
|
+
/** Billed cost (¥) over the row's cells under the current table. */
|
|
352
|
+
cost: number;
|
|
353
|
+
/** Start of the local day of the row's earliest cell — the fallback
|
|
354
|
+
* identity's "from" bound (day granularity; titles cover the rest). */
|
|
355
|
+
firstTime: number;
|
|
356
|
+
/** Newest record time in the row (max over every folded cell). */
|
|
357
|
+
lastTime: number;
|
|
358
|
+
}
|
|
282
359
|
/**
|
|
283
360
|
* The token-only aggregation shape: what the aggregation functions produce
|
|
284
361
|
* and the rollup persists. No currency — cost is an additive layer computed
|
|
@@ -299,6 +376,10 @@ export interface TokenSummary {
|
|
|
299
376
|
* lets the route re-aggregate any day range × model filter without
|
|
300
377
|
* rereading files, and re-price history under the current table. */
|
|
301
378
|
rateRows: UsageRateRow[];
|
|
379
|
+
/** Per-session × per-day × per-model × per-rate rows, session then day
|
|
380
|
+
* then model then rate ascending; the settings page's session table folds
|
|
381
|
+
* from these (see {@link UsageSessionRow}). */
|
|
382
|
+
bySession: UsageSessionRow[];
|
|
302
383
|
/** The most recent records, descending by time. */
|
|
303
384
|
recent: UsageRecord[];
|
|
304
385
|
}
|
|
@@ -306,6 +387,13 @@ export interface TokenSummary {
|
|
|
306
387
|
export type CostedModelRow = UsageModelRow & {
|
|
307
388
|
cost: number;
|
|
308
389
|
};
|
|
390
|
+
/** A per-session aggregation cell carrying its billed cost (¥); 0 when the
|
|
391
|
+
* model is unpriced — priced from the same rate identity the per-model cost
|
|
392
|
+
* folds from, so the session table's cost column reconciles with the
|
|
393
|
+
* summary card for free. */
|
|
394
|
+
export type CostedSessionCell = UsageSessionRow & {
|
|
395
|
+
cost: number;
|
|
396
|
+
};
|
|
309
397
|
/** The currency the stats page renders cost figures in. The amounts on the
|
|
310
398
|
* wire stay RMB — this only names the display convention. */
|
|
311
399
|
export type DisplayCurrency = 'CNY' | 'USD';
|
|
@@ -332,30 +420,43 @@ export interface CostedSummary extends TokenSummary {
|
|
|
332
420
|
pricing: PricingTable;
|
|
333
421
|
/** Per-model rows with their billed cost attached. */
|
|
334
422
|
byModel: CostedModelRow[];
|
|
423
|
+
/** Per-session cells with their billed cost attached (see
|
|
424
|
+
* {@link CostedSessionCell}); the route folds these into
|
|
425
|
+
* {@link SessionUsageRow}s for the session table. */
|
|
426
|
+
bySession: CostedSessionCell[];
|
|
335
427
|
}
|
|
336
428
|
/** The full stats payload served at {@link STATS_PATH}. A discriminated
|
|
337
429
|
* union over the two scope modes the route serves:
|
|
338
430
|
* - `'whole'`: the settings page's whole-log read. The `requestSeries`
|
|
339
431
|
* field is absent (the page plots hours/days), so its `TrendChart`
|
|
340
|
-
* falls back to the `byDay` / `byHour` rows.
|
|
432
|
+
* falls back to the `byDay` / `byHour` rows. The session table reads
|
|
433
|
+
* `sessionRows` — the server-side folded, sorted, truncated final
|
|
434
|
+
* rows (always folded over subagent subtrees); the granular
|
|
435
|
+
* `bySession` cells stay behind the route (sending them would only
|
|
436
|
+
* duplicate the fold on the wire).
|
|
341
437
|
* - `'session'`: the conversation view tab's session-scoped read. The
|
|
342
438
|
* `sessionIds` field lists every requested id (the parent + its
|
|
343
439
|
* subagent children when the scope is "tree"), and `requestSeries`
|
|
344
440
|
* is the per-request series the chart plots at request granularity.
|
|
345
441
|
*
|
|
346
|
-
* Both branches share every {@link CostedSummary} field
|
|
442
|
+
* Both branches share every {@link CostedSummary} field except the
|
|
443
|
+
* granular `bySession` (stripped from the wire) plus the
|
|
347
444
|
* display-currency metadata, so a consumer can read `total` /
|
|
348
445
|
* `totalCost` / `pricing` without narrowing first.
|
|
349
446
|
*/
|
|
350
|
-
|
|
447
|
+
type CostedSummaryWire = Omit<CostedSummary, 'bySession'>;
|
|
448
|
+
export type StatsPayload = (CostedSummaryWire & {
|
|
351
449
|
scope: 'whole';
|
|
450
|
+
/** The session table's final rows: folded over subagent subtrees,
|
|
451
|
+
* cost-sorted, top-N truncated, metadata attached. */
|
|
452
|
+
sessionRows: readonly SessionUsageRow[];
|
|
352
453
|
/** The display currency the page converts cost figures into. Amounts on
|
|
353
454
|
* the wire (totalCost, byModel[].cost, pricing rates) remain RMB. */
|
|
354
455
|
currency: DisplayCurrency;
|
|
355
456
|
/** Effective RMB-per-USD rate (feed value, else the built-in default);
|
|
356
457
|
* the divisor when `currency` is USD. */
|
|
357
458
|
usdExchangeRate: number;
|
|
358
|
-
}) | (
|
|
459
|
+
}) | (CostedSummaryWire & {
|
|
359
460
|
scope: 'session';
|
|
360
461
|
/** The session ids aggregated to produce this payload, in URL order. */
|
|
361
462
|
sessionIds: readonly string[];
|
|
@@ -376,9 +477,12 @@ export type StatsPayload = (CostedSummary & {
|
|
|
376
477
|
* either branch without narrowing first. Uses a base cost layer plus the
|
|
377
478
|
* display metadata; for new code, narrow on `StatsPayload` instead.
|
|
378
479
|
*/
|
|
379
|
-
export interface UsageSummary extends CostedSummary {
|
|
480
|
+
export interface UsageSummary extends Omit<CostedSummary, 'bySession'> {
|
|
380
481
|
currency: DisplayCurrency;
|
|
381
482
|
usdExchangeRate: number;
|
|
483
|
+
/** Whole-scope payloads only: the settings page's session table rows
|
|
484
|
+
* (see {@link SessionUsageRow}); absent on session-scoped reads. */
|
|
485
|
+
sessionRows?: readonly SessionUsageRow[];
|
|
382
486
|
requestSeries?: readonly RequestPoint[];
|
|
383
487
|
children?: Readonly<Record<string, ChildUsageSummary>>;
|
|
384
488
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AAM,EAAE,aAAa,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GACnF,CAAC,YAAY,GAAG;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC,CAAA;AAE3C;oDACoD;AACpD,wBAAgB,cAAc,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,WAAW,EAAE,CAE5E"}
|
package/lib/wire.js
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/** The stats endpoint path, served by the host half's webServer route. */
|
|
10
10
|
export const STATS_PATH = '/token-usage/stats';
|
|
11
|
+
/** The pricing-overview endpoint path: the full cloud-mirror model list,
|
|
12
|
+
* filter-free by design — the overview is not a filtered usage view. */
|
|
13
|
+
export const PRICING_PATH = '/token-usage/pricing';
|
|
11
14
|
/** Encode one repeated query key (`sessionId=a&sessionId=b`). Empty list yields ''. */
|
|
12
15
|
export function encodeRepeatedParam(key, values) {
|
|
13
16
|
return values.map(value => `${key}=${encodeURIComponent(value)}`).join('&');
|
package/lib/wire.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,0EAA0E;AAC1E,MAAM,CAAC,MAAM,UAAU,GAAG,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,0EAA0E;AAC1E,MAAM,CAAC,MAAM,UAAU,GAAG,oBAAoB,CAAA;AAE9C;wEACwE;AACxE,MAAM,CAAC,MAAM,YAAY,GAAG,sBAAsB,CAAA;AAOlD,uFAAuF;AACvF,MAAM,UAAU,mBAAmB,CAAC,GAAW,EAAE,MAAyB;IACxE,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,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