opencode-quota-gui 1.3.0 → 1.3.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 +34 -20
- package/dist/bin/opencode-quota-gui.js +0 -0
- package/dist/contracts/build-identity.js +1 -1
- package/dist/contracts/card-order.d.ts +2 -0
- package/dist/contracts/card-order.js +2 -2
- package/dist/contracts/card-visibility.d.ts +2 -1
- package/dist/contracts/card-visibility.js +2 -1
- package/dist/contracts/dashboard.d.ts +95 -6
- package/dist/contracts/dashboard.js +10 -0
- package/dist/contracts/dto-guards.d.ts +4 -0
- package/dist/contracts/dto-guards.js +31 -7
- package/dist/contracts/guards.js +3 -1
- package/dist/contracts/identity.d.ts +37 -5
- package/dist/contracts/identity.js +43 -0
- package/dist/contracts/openai-quota.d.ts +3 -0
- package/dist/contracts/openai-quota.js +3 -0
- package/dist/contracts/provider-auto-resume.d.ts +9 -0
- package/dist/contracts/provider-auto-resume.js +24 -0
- package/dist/contracts/provider-failure.d.ts +22 -0
- package/dist/contracts/provider-failure.js +25 -1
- package/dist/contracts/row-order.d.ts +13 -0
- package/dist/contracts/row-order.js +34 -0
- package/dist/contracts/row-visibility.d.ts +53 -0
- package/dist/contracts/row-visibility.js +130 -0
- package/dist/data/modelsdev-pricing.min.json +1 -1
- package/dist/data/modelsdev-temporal.min.json +60 -634
- package/dist/gui/aggregation.d.ts +29 -1
- package/dist/gui/aggregation.js +157 -4
- package/dist/gui/analytics-bridge.d.ts +8 -9
- package/dist/gui/analytics-bridge.js +197 -54
- package/dist/gui/analytics-engine.d.ts +7 -15
- package/dist/gui/analytics-engine.js +246 -106
- package/dist/gui/analytics-model.d.ts +7 -0
- package/dist/gui/analytics-model.js +75 -9
- package/dist/gui/analytics-pricing-upkeep.d.ts +21 -0
- package/dist/gui/analytics-pricing-upkeep.js +23 -0
- package/dist/gui/analytics-protocol.d.ts +17 -7
- package/dist/gui/analytics-protocol.js +1 -0
- package/dist/gui/analytics-service.d.ts +10 -0
- package/dist/gui/analytics-service.js +30 -9
- package/dist/gui/analytics-state.d.ts +30 -5
- package/dist/gui/analytics-state.js +46 -7
- package/dist/gui/analytics-worker-runtime.d.ts +5 -0
- package/dist/gui/analytics-worker-runtime.js +9 -1
- package/dist/gui/analytics-worker.js +11 -0
- package/dist/gui/config.d.ts +3 -3
- package/dist/gui/config.js +77 -7
- package/dist/gui/identity.d.ts +6 -20
- package/dist/gui/identity.js +6 -54
- package/dist/gui/lifecycle.d.ts +5 -3
- package/dist/gui/lifecycle.js +3 -3
- package/dist/gui/primary-quota-windows.js +67 -44
- package/dist/gui/provider-cards.d.ts +20 -8
- package/dist/gui/provider-cards.js +42 -55
- package/dist/gui/quota-notification-detector.d.ts +29 -6
- package/dist/gui/quota-notification-detector.js +136 -47
- package/dist/gui/quota-notification-observer.d.ts +3 -4
- package/dist/gui/quota-notification-observer.js +73 -20
- package/dist/gui/quota-observation.d.ts +4 -0
- package/dist/gui/quota-observation.js +18 -0
- package/dist/gui/rpc.d.ts +2 -0
- package/dist/gui/rpc.js +14 -3
- package/dist/gui/server.js +17 -3
- package/dist/gui/snapshot-service.d.ts +3 -15
- package/dist/gui/snapshot-service.js +281 -23
- package/dist/gui/sources.js +179 -64
- package/dist/gui/temporal-status.d.ts +3 -2
- package/dist/gui/temporal-status.js +10 -6
- package/dist/gui-experimental.cjs +230 -225
- package/dist/lib/accounting-format.d.ts +8 -0
- package/dist/lib/accounting-format.js +20 -2
- package/dist/lib/alibaba-coding-plan-cli.d.ts +79 -0
- package/dist/lib/alibaba-coding-plan-cli.js +539 -0
- package/dist/lib/anthropic-api-auth.d.ts +7 -0
- package/dist/lib/anthropic-api-auth.js +27 -0
- package/dist/lib/anthropic-api-rate-limits.d.ts +47 -0
- package/dist/lib/anthropic-api-rate-limits.js +92 -0
- package/dist/lib/anthropic-auth.d.ts +2 -3
- package/dist/lib/anthropic-auth.js +2 -3
- package/dist/lib/anthropic-oauth-throttle.d.ts +76 -0
- package/dist/lib/anthropic-oauth-throttle.js +379 -0
- package/dist/lib/anthropic.d.ts +68 -14
- package/dist/lib/anthropic.js +1016 -363
- package/dist/lib/api-key-retry-after.d.ts +7 -0
- package/dist/lib/api-key-retry-after.js +62 -0
- package/dist/lib/atomic-json.d.ts +2 -0
- package/dist/lib/atomic-json.js +1 -0
- package/dist/lib/cache-observer-ingestion.d.ts +90 -0
- package/dist/lib/cache-observer-ingestion.js +1008 -0
- package/dist/lib/cache-observer.d.ts +141 -0
- package/dist/lib/cache-observer.js +323 -0
- package/dist/lib/canonical-config-lock.d.ts +9 -0
- package/dist/lib/canonical-config-lock.js +36 -0
- package/dist/lib/chutes.js +62 -51
- package/dist/lib/claude-agent-transcript-ttl.d.ts +48 -0
- package/dist/lib/claude-agent-transcript-ttl.js +154 -0
- package/dist/lib/claude-agent-ttl-tracker.d.ts +21 -0
- package/dist/lib/claude-agent-ttl-tracker.js +152 -0
- package/dist/lib/cli-show.d.ts +5 -0
- package/dist/lib/cli-show.js +21 -8
- package/dist/lib/cli-status.js +3 -6
- package/dist/lib/config-write-target.d.ts +1 -1
- package/dist/lib/config-write-target.js +5 -2
- package/dist/lib/config.d.ts +2 -1
- package/dist/lib/config.js +257 -4
- package/dist/lib/copilot.js +171 -86
- package/dist/lib/dashboard-visibility.d.ts +5 -0
- package/dist/lib/dashboard-visibility.js +11 -10
- package/dist/lib/dashboard-web-policy.d.ts +4 -4
- package/dist/lib/dashboard-web-policy.js +2 -2
- package/dist/lib/deepseek.js +25 -13
- package/dist/lib/display-sanitize.js +2 -0
- package/dist/lib/entries.d.ts +33 -1
- package/dist/lib/entries.js +6 -0
- package/dist/lib/glm-coding-plan.js +98 -74
- package/dist/lib/google-agy.js +90 -12
- package/dist/lib/google-gemini-cli.js +84 -11
- package/dist/lib/grouped-entry-normalization.js +1 -1
- package/dist/lib/http.d.ts +4 -0
- package/dist/lib/http.js +16 -2
- package/dist/lib/init-installer.js +5 -3
- package/dist/lib/kilo.js +37 -18
- package/dist/lib/kimi.js +35 -18
- package/dist/lib/maintainer-announcements.js +2 -2
- package/dist/lib/mimo.d.ts +2 -0
- package/dist/lib/mimo.js +36 -0
- package/dist/lib/modelsdev-pricing.d.ts +74 -2
- package/dist/lib/modelsdev-pricing.js +457 -63
- package/dist/lib/modelsdev-temporal.d.ts +6 -0
- package/dist/lib/modelsdev-temporal.js +16 -2
- package/dist/lib/nanogpt.d.ts +1 -0
- package/dist/lib/nanogpt.js +26 -3
- package/dist/lib/ollama-cloud.d.ts +1 -1
- package/dist/lib/ollama-cloud.js +48 -35
- package/dist/lib/openai.js +84 -38
- package/dist/lib/opencode-auth-sqlite.d.ts +2 -2
- package/dist/lib/opencode-auth-sqlite.js +2 -2
- package/dist/lib/opencode-config-editor.d.ts +1 -0
- package/dist/lib/opencode-config-editor.js +6 -1
- package/dist/lib/opencode-config-providers.js +2 -2
- package/dist/lib/opencode-go.js +29 -2
- package/dist/lib/opencode-storage.d.ts +20 -0
- package/dist/lib/opencode-storage.js +89 -2
- package/dist/lib/opencode-version-core.d.ts +30 -0
- package/dist/lib/opencode-version-core.js +59 -0
- package/dist/lib/opencode-version.d.ts +2 -22
- package/dist/lib/opencode-version.js +4 -48
- package/dist/lib/opencode-warming-refresh.d.ts +19 -0
- package/dist/lib/opencode-warming-refresh.js +95 -0
- package/dist/lib/opencode-zen.d.ts +3 -0
- package/dist/lib/opencode-zen.js +71 -5
- package/dist/lib/provider-add.js +5 -2
- package/dist/lib/provider-metadata.d.ts +11 -3
- package/dist/lib/provider-metadata.js +20 -2
- package/dist/lib/provider-registration.d.ts +358 -9
- package/dist/lib/provider-registration.js +423 -30
- package/dist/lib/quota-auto-resume.d.ts +74 -0
- package/dist/lib/quota-auto-resume.js +539 -0
- package/dist/lib/quota-command-format.js +23 -10
- package/dist/lib/quota-exhaustion-projection.d.ts +11 -0
- package/dist/lib/quota-exhaustion-projection.js +25 -0
- package/dist/lib/quota-identity.d.ts +64 -0
- package/dist/lib/quota-identity.js +111 -0
- package/dist/lib/quota-providers-remote.d.ts +2 -1
- package/dist/lib/quota-providers-remote.js +59 -3
- package/dist/lib/quota-providers.d.ts +1 -1
- package/dist/lib/quota-providers.js +14 -37
- package/dist/lib/quota-render-data.d.ts +6 -0
- package/dist/lib/quota-render-data.js +45 -19
- package/dist/lib/quota-reset-notifications.js +11 -155
- package/dist/lib/quota-retry-wait.d.ts +106 -5
- package/dist/lib/quota-retry-wait.js +301 -34
- package/dist/lib/quota-runtime-context.js +1 -0
- package/dist/lib/quota-state-codec.d.ts +2 -0
- package/dist/lib/quota-state-codec.js +31 -2
- package/dist/lib/quota-state.d.ts +8 -2
- package/dist/lib/quota-state.js +253 -47
- package/dist/lib/quota-stats.d.ts +26 -0
- package/dist/lib/quota-stats.js +40 -1
- package/dist/lib/quota-status.js +3 -51
- package/dist/lib/quota-surface-data.js +18 -3
- package/dist/lib/quota-telemetry.js +2 -2
- package/dist/lib/resolved-auth-identity.d.ts +19 -0
- package/dist/lib/resolved-auth-identity.js +44 -0
- package/dist/lib/scoped-update.d.ts +1 -1
- package/dist/lib/state-file-lock.d.ts +26 -0
- package/dist/lib/state-file-lock.js +205 -0
- package/dist/lib/synthetic.js +65 -54
- package/dist/lib/toast-format-grouped.js +7 -4
- package/dist/lib/tui-compact-format.js +29 -16
- package/dist/lib/types.d.ts +51 -1
- package/dist/lib/types.js +17 -1
- package/dist/lib/xai.js +48 -22
- package/dist/plugin.js +328 -14
- package/dist/provider-logos/NOTICE.md +1 -1
- package/dist/provider-logos/OPENCODE-NOTICE.md +4 -3
- package/dist/providers/alibaba-coding-plan.js +125 -104
- package/dist/providers/alibaba-token-plan.js +9 -5
- package/dist/providers/anthropic.d.ts +16 -3
- package/dist/providers/anthropic.js +172 -220
- package/dist/providers/cache-policies.d.ts +11 -4
- package/dist/providers/cache-policies.js +19 -13
- package/dist/providers/chutes.js +2 -0
- package/dist/providers/claude-agent.d.ts +19 -0
- package/dist/providers/claude-agent.js +215 -0
- package/dist/providers/copilot.js +7 -4
- package/dist/providers/glm-coding-plan-provider.d.ts +1 -0
- package/dist/providers/glm-coding-plan-provider.js +30 -23
- package/dist/providers/google-account-format.js +1 -0
- package/dist/providers/google-agy.d.ts +6 -5
- package/dist/providers/google-agy.js +43 -15
- package/dist/providers/google-gemini-cli.js +1 -0
- package/dist/providers/kilo.js +1 -0
- package/dist/providers/kimi-code.js +2 -0
- package/dist/providers/mimo.js +1 -0
- package/dist/providers/nanogpt.js +1 -0
- package/dist/providers/ollama-cloud.js +10 -0
- package/dist/providers/openai.js +24 -23
- package/dist/providers/opencode-go.js +10 -6
- package/dist/providers/opencode-zen.js +3 -1
- package/dist/providers/openrouter.js +1 -0
- package/dist/providers/quota-providers.js +16 -5
- package/dist/providers/registry.js +2 -0
- package/dist/providers/result-helpers.d.ts +6 -2
- package/dist/providers/result-helpers.js +7 -1
- package/dist/providers/synthetic.js +4 -0
- package/dist/providers/xai.js +9 -8
- package/dist/rpc.d.ts +129 -8
- package/dist/rpc.js +219 -14
- package/dist/ui/assets/{index-cDd9jUVY.css → index-6_g1FHs-.css} +1 -1
- package/dist/ui/assets/index-sZnGUuML.js +10 -0
- package/dist/ui/assets/{popover-BGkgv9s0.js → popover-C4ZLYe9E.js} +1 -1
- package/dist/ui/assets/providers/claude-agent.svg +3 -0
- package/dist/ui/index.html +2 -2
- package/package.json +45 -46
- package/dist/lib/alibaba-coding-plan-local-quota.d.ts +0 -47
- package/dist/lib/alibaba-coding-plan-local-quota.js +0 -146
- package/dist/ui/assets/index-DLHeXYff.js +0 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProjectActivityRow, ProjectSnapshot, SessionSnapshot, Usage } from "../contracts/dashboard.js";
|
|
1
|
+
import type { CostedTokens, ProjectActivityRow, ProjectSnapshot, SessionSnapshot, Usage } from "../contracts/dashboard.js";
|
|
2
2
|
import { type RangeKey } from "../contracts/ranges.js";
|
|
3
3
|
import { type OpenCodeCompactionMarker, type OpenCodeProjectInfo, type OpenCodeRawAssistantRow, type OpenCodeSessionInfo } from "../lib/opencode-storage.js";
|
|
4
4
|
/**
|
|
@@ -27,13 +27,39 @@ export declare class AnalyticsNotFoundError extends Error {
|
|
|
27
27
|
readonly resourceId: string;
|
|
28
28
|
constructor(resource: "project" | "session", resourceId: string);
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* One user-role message position. `replyMessageIds` is the explicit
|
|
32
|
+
* assistant-`parentID` linkage when the stored message JSON records it.
|
|
33
|
+
*/
|
|
34
|
+
export interface InputMessagePosition {
|
|
35
|
+
sessionId: string;
|
|
36
|
+
atMs: number;
|
|
37
|
+
messageId: string;
|
|
38
|
+
replyMessageIds?: readonly string[];
|
|
39
|
+
}
|
|
30
40
|
/** The raw dataset one P3 source read hands to the factory. */
|
|
31
41
|
export interface UsageAnalyticsDataset {
|
|
32
42
|
sessions: Record<string, OpenCodeSessionInfo>;
|
|
33
43
|
projects: Record<string, OpenCodeProjectInfo>;
|
|
34
44
|
messages: OpenCodeRawAssistantRow[];
|
|
35
45
|
compactions: OpenCodeCompactionMarker[];
|
|
46
|
+
/**
|
|
47
|
+
* Completed assistant rows the usage view excluded (zero-token). They are not
|
|
48
|
+
* steps, but the session DTO records where they sit so gaps never bridge them.
|
|
49
|
+
*/
|
|
50
|
+
excluded?: Array<{
|
|
51
|
+
sessionId: string;
|
|
52
|
+
atMs: number;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* User-role message positions per session (scoped read, ids and times only).
|
|
56
|
+
* The session DTO marks the first assistant step after one; prompt text is
|
|
57
|
+
* never read or carried.
|
|
58
|
+
*/
|
|
59
|
+
userMessages?: InputMessagePosition[];
|
|
36
60
|
}
|
|
61
|
+
/** Where a message sits in its session's sequence: creation time, else completion time. */
|
|
62
|
+
export declare function messagePositionMs(row: Pick<OpenCodeRawAssistantRow, "createdAtMs" | "completedAtMs">): number;
|
|
37
63
|
export interface HomeAnalytics {
|
|
38
64
|
usage: Usage;
|
|
39
65
|
projects: ProjectActivityRow[];
|
|
@@ -47,6 +73,8 @@ export interface UsageAnalytics {
|
|
|
47
73
|
export interface UsageAnalyticsOptions {
|
|
48
74
|
timeZone?: string;
|
|
49
75
|
}
|
|
76
|
+
/** Shared recorded-cost provenance fields; omitted when no fallback contributed. */
|
|
77
|
+
export declare function recordedCostFields(costUsd: number, tokens: number): Partial<Pick<CostedTokens, "recordedCostUsd" | "recordedCostTokens">>;
|
|
50
78
|
/**
|
|
51
79
|
* The one P3 analytics factory: pure Node/in-memory over a raw dataset.
|
|
52
80
|
* Reading the database, config, or user state is the caller's job.
|
package/dist/gui/aggregation.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { sumTokenStack } from "../contracts/guards.js";
|
|
2
2
|
import { planRangeBuckets, rangeBucketUnit, rangeWindow, } from "../contracts/ranges.js";
|
|
3
3
|
import { rawAssistantRowFingerprint, } from "../lib/opencode-storage.js";
|
|
4
|
-
import {
|
|
4
|
+
import { priceTokenBucketsWithRecordedCost } from "../lib/quota-stats.js";
|
|
5
5
|
import { selectForkOwnerCandidates } from "../lib/usage-ownership.js";
|
|
6
6
|
/**
|
|
7
7
|
* Pure, in-memory GUI analytics over the raw P1 reads (design spec §6,
|
|
@@ -38,6 +38,12 @@ export class AnalyticsNotFoundError extends Error {
|
|
|
38
38
|
this.name = "AnalyticsNotFoundError";
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
/** Where a message sits in its session's sequence: creation time, else completion time. */
|
|
42
|
+
export function messagePositionMs(row) {
|
|
43
|
+
return row.createdAtMs > 0 && Number.isFinite(row.createdAtMs)
|
|
44
|
+
? row.createdAtMs
|
|
45
|
+
: row.completedAtMs;
|
|
46
|
+
}
|
|
41
47
|
// ---------------------------------------------------------------------------
|
|
42
48
|
// Small deterministic helpers
|
|
43
49
|
// ---------------------------------------------------------------------------
|
|
@@ -110,6 +116,8 @@ function createAccumulator() {
|
|
|
110
116
|
pricedAny: false,
|
|
111
117
|
unpricedTokens: 0,
|
|
112
118
|
unknownTokens: 0,
|
|
119
|
+
recordedCostUsd: 0,
|
|
120
|
+
recordedCostTokens: 0,
|
|
113
121
|
};
|
|
114
122
|
}
|
|
115
123
|
function cloneAccumulator(accumulator) {
|
|
@@ -125,6 +133,8 @@ function mergeAccumulator(target, source) {
|
|
|
125
133
|
target.pricedAny = target.pricedAny || source.pricedAny;
|
|
126
134
|
target.unpricedTokens += source.unpricedTokens;
|
|
127
135
|
target.unknownTokens += source.unknownTokens;
|
|
136
|
+
target.recordedCostUsd += source.recordedCostUsd;
|
|
137
|
+
target.recordedCostTokens += source.recordedCostTokens;
|
|
128
138
|
}
|
|
129
139
|
function finalizeAccumulator(accumulator) {
|
|
130
140
|
const stack = {
|
|
@@ -140,8 +150,13 @@ function finalizeAccumulator(accumulator) {
|
|
|
140
150
|
apiEquivalentCostUsd: accumulator.pricedAny ? accumulator.costUsd : null,
|
|
141
151
|
unpricedTokens: accumulator.unpricedTokens,
|
|
142
152
|
unknownTokens: accumulator.unknownTokens,
|
|
153
|
+
...recordedCostFields(accumulator.recordedCostUsd, accumulator.recordedCostTokens),
|
|
143
154
|
};
|
|
144
155
|
}
|
|
156
|
+
/** Shared recorded-cost provenance fields; omitted when no fallback contributed. */
|
|
157
|
+
export function recordedCostFields(costUsd, tokens) {
|
|
158
|
+
return costUsd > 0 ? { recordedCostUsd: costUsd, recordedCostTokens: tokens } : {};
|
|
159
|
+
}
|
|
145
160
|
/**
|
|
146
161
|
* Add one physical row to an accumulator using the existing pricing resolver,
|
|
147
162
|
* per-message cost calculation, and unpriced/unknown classification. Tokens
|
|
@@ -155,10 +170,11 @@ function addRawStep(accumulator, row, pricingCache) {
|
|
|
155
170
|
accumulator.cacheWrite += tokens.cache_write;
|
|
156
171
|
accumulator.output += tokens.output;
|
|
157
172
|
accumulator.reasoning += tokens.reasoning;
|
|
158
|
-
const outcome =
|
|
173
|
+
const outcome = priceTokenBucketsWithRecordedCost({
|
|
159
174
|
providerID: row.providerID,
|
|
160
175
|
modelID: row.modelID,
|
|
161
176
|
tokens,
|
|
177
|
+
recordedCostUsd: row.cost,
|
|
162
178
|
// A completed physical row is priced at its own assistant completion
|
|
163
179
|
// instant; never infer a timestamp from a range boundary or wall clock.
|
|
164
180
|
atMs: row.completedAtMs,
|
|
@@ -175,6 +191,13 @@ function addRawStep(accumulator, row, pricingCache) {
|
|
|
175
191
|
accumulator.costUsd += outcome.costUsd;
|
|
176
192
|
return;
|
|
177
193
|
}
|
|
194
|
+
if (outcome.status === "recorded_cost") {
|
|
195
|
+
accumulator.pricedAny = true;
|
|
196
|
+
accumulator.costUsd += outcome.costUsd;
|
|
197
|
+
accumulator.recordedCostUsd += outcome.costUsd;
|
|
198
|
+
accumulator.recordedCostTokens += outcome.recordedTokens;
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
178
201
|
const total = totalBucketTokens(tokens);
|
|
179
202
|
if (outcome.status === "unpriced") {
|
|
180
203
|
accumulator.unpricedTokens += total;
|
|
@@ -612,6 +635,112 @@ function sessionAgent(session, ownSteps) {
|
|
|
612
635
|
}
|
|
613
636
|
return latest?.row.agent?.trim();
|
|
614
637
|
}
|
|
638
|
+
/**
|
|
639
|
+
* Identity actually recorded for one invocation. OpenCode stores the effort as
|
|
640
|
+
* `model.variant`; `default` is its "no explicit effort" value, so neither it
|
|
641
|
+
* nor an empty string is shown as an effort.
|
|
642
|
+
*/
|
|
643
|
+
function modelIdentityOf(row) {
|
|
644
|
+
if (!row.providerID || !row.modelID)
|
|
645
|
+
return undefined;
|
|
646
|
+
const identity = { providerId: row.providerID, modelId: row.modelID };
|
|
647
|
+
const effort = row.variant?.trim();
|
|
648
|
+
if (effort && effort !== "default")
|
|
649
|
+
identity.effort = effort;
|
|
650
|
+
return identity;
|
|
651
|
+
}
|
|
652
|
+
function identityKey(identity) {
|
|
653
|
+
return JSON.stringify([identity.providerId, identity.modelId, identity.effort ?? null]);
|
|
654
|
+
}
|
|
655
|
+
/** Distinct identities of one session's own steps, most recently used first. */
|
|
656
|
+
function sessionModelIdentities(ownSteps) {
|
|
657
|
+
const lastUse = new Map();
|
|
658
|
+
for (const step of ownSteps) {
|
|
659
|
+
const identity = modelIdentityOf(step.row);
|
|
660
|
+
if (!identity)
|
|
661
|
+
continue;
|
|
662
|
+
const key = identityKey(identity);
|
|
663
|
+
const known = lastUse.get(key);
|
|
664
|
+
if (known === undefined ||
|
|
665
|
+
step.timeMs > known.step.timeMs ||
|
|
666
|
+
(step.timeMs === known.step.timeMs &&
|
|
667
|
+
compareIds(step.row.messageID, known.step.row.messageID) > 0)) {
|
|
668
|
+
lastUse.set(key, { identity, step });
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return [...lastUse.values()]
|
|
672
|
+
.sort((a, b) => b.step.timeMs - a.step.timeMs || compareIds(b.step.row.messageID, a.step.row.messageID))
|
|
673
|
+
.map((entry) => entry.identity);
|
|
674
|
+
}
|
|
675
|
+
/** Creation time when recorded, else the step's completion position. */
|
|
676
|
+
function stepStartMs(step) {
|
|
677
|
+
return step.createdAtMs !== undefined && step.createdAtMs > 0 ? step.createdAtMs : step.atMs;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Marks each focus-session step that is the first assistant reply after a
|
|
681
|
+
* user-role message. Positions only; prompt text never enters the DTO.
|
|
682
|
+
*
|
|
683
|
+
* Completion time cannot answer this: a reply that was already running when
|
|
684
|
+
* the input arrived completes after it. Explicit assistant `parentID` linkage
|
|
685
|
+
* is authoritative. Without it, a step only qualifies when its recorded
|
|
686
|
+
* creation time is strictly after the input; equal or missing creation times
|
|
687
|
+
* stay unmarked because their order cannot be proven.
|
|
688
|
+
*/
|
|
689
|
+
function markInputMarkers(steps, sessionId, userMessages) {
|
|
690
|
+
const messages = userMessages
|
|
691
|
+
.filter((message) => message.sessionId === sessionId)
|
|
692
|
+
.sort((a, b) => a.atMs - b.atMs || compareIds(a.messageId, b.messageId));
|
|
693
|
+
if (messages.length === 0)
|
|
694
|
+
return;
|
|
695
|
+
const focusSteps = steps.filter((step) => step.sessionId === sessionId);
|
|
696
|
+
if (focusSteps.length === 0)
|
|
697
|
+
return;
|
|
698
|
+
const byMessageId = new Map();
|
|
699
|
+
for (const step of focusSteps) {
|
|
700
|
+
if (!byMessageId.has(step.messageId))
|
|
701
|
+
byMessageId.set(step.messageId, step);
|
|
702
|
+
}
|
|
703
|
+
const linkedMessages = new Set();
|
|
704
|
+
for (const message of messages) {
|
|
705
|
+
const replyIds = message.replyMessageIds;
|
|
706
|
+
if (replyIds === undefined || replyIds.length === 0)
|
|
707
|
+
continue;
|
|
708
|
+
// The stored linkage is authoritative even when the linked reply is not a
|
|
709
|
+
// charted step (fork-owned elsewhere, zero-token, descendant): never fall
|
|
710
|
+
// back to timing for a prompt whose reply is known.
|
|
711
|
+
linkedMessages.add(message.messageId);
|
|
712
|
+
let reply;
|
|
713
|
+
for (const replyId of replyIds) {
|
|
714
|
+
const candidate = byMessageId.get(replyId);
|
|
715
|
+
if (candidate === undefined)
|
|
716
|
+
continue;
|
|
717
|
+
if (reply === undefined || stepStartMs(candidate) < stepStartMs(reply))
|
|
718
|
+
reply = candidate;
|
|
719
|
+
}
|
|
720
|
+
if (reply !== undefined)
|
|
721
|
+
reply.inputMarker = true;
|
|
722
|
+
}
|
|
723
|
+
const byCreation = focusSteps
|
|
724
|
+
.filter((step) => step.createdAtMs !== undefined && step.createdAtMs > 0 && Number.isFinite(step.createdAtMs))
|
|
725
|
+
.sort((a, b) => (a.createdAtMs ?? 0) - (b.createdAtMs ?? 0) || compareIds(a.messageId, b.messageId));
|
|
726
|
+
if (byCreation.length === 0)
|
|
727
|
+
return;
|
|
728
|
+
let cursor = 0;
|
|
729
|
+
for (const message of messages) {
|
|
730
|
+
if (linkedMessages.has(message.messageId))
|
|
731
|
+
continue;
|
|
732
|
+
while (cursor < byCreation.length && (byCreation[cursor].createdAtMs ?? 0) < message.atMs) {
|
|
733
|
+
cursor += 1;
|
|
734
|
+
}
|
|
735
|
+
const step = byCreation[cursor];
|
|
736
|
+
if (step === undefined)
|
|
737
|
+
break;
|
|
738
|
+
// Equal creation times cannot prove the reply started after the input.
|
|
739
|
+
if ((step.createdAtMs ?? 0) === message.atMs)
|
|
740
|
+
continue;
|
|
741
|
+
step.inputMarker = true;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
615
744
|
function buildSessionSnapshot(model, sessionId, timeZone) {
|
|
616
745
|
const focus = model.dataset.sessions[sessionId];
|
|
617
746
|
if (!focus)
|
|
@@ -689,7 +818,11 @@ function buildSessionSnapshot(model, sessionId, timeZone) {
|
|
|
689
818
|
stepCount: ownSteps.length,
|
|
690
819
|
subtreeNodeCount: subtreeNodeCounts.get(id),
|
|
691
820
|
latestActivityAtMs: subtreeLatest.get(id),
|
|
821
|
+
models: sessionModelIdentities(ownSteps),
|
|
692
822
|
};
|
|
823
|
+
const cacheUnknownSteps = ownSteps.filter((step) => step.row.cacheReadMissing || step.row.cacheWriteMissing).length;
|
|
824
|
+
if (cacheUnknownSteps > 0)
|
|
825
|
+
node.cacheUnknownSteps = cacheUnknownSteps;
|
|
693
826
|
if (session.parentID !== undefined)
|
|
694
827
|
node.parentId = session.parentID;
|
|
695
828
|
const agent = sessionAgent(session, ownSteps);
|
|
@@ -720,11 +853,18 @@ function buildSessionSnapshot(model, sessionId, timeZone) {
|
|
|
720
853
|
contextTokens: stack.input + stack.cacheRead + stack.cacheWrite,
|
|
721
854
|
totalTokens: sumTokenStack(stack),
|
|
722
855
|
};
|
|
723
|
-
|
|
724
|
-
|
|
856
|
+
const identity = modelIdentityOf(row);
|
|
857
|
+
if (identity)
|
|
858
|
+
step.model = identity;
|
|
859
|
+
if (row.createdAtMs > 0 && Number.isFinite(row.createdAtMs)) {
|
|
860
|
+
step.createdAtMs = row.createdAtMs;
|
|
725
861
|
}
|
|
726
862
|
if (row.agent)
|
|
727
863
|
step.agent = row.agent;
|
|
864
|
+
if (row.cacheReadMissing)
|
|
865
|
+
step.cacheReadUnknown = true;
|
|
866
|
+
if (row.cacheWriteMissing)
|
|
867
|
+
step.cacheWriteUnknown = true;
|
|
728
868
|
steps.push(step);
|
|
729
869
|
}
|
|
730
870
|
}
|
|
@@ -736,6 +876,7 @@ function buildSessionSnapshot(model, sessionId, timeZone) {
|
|
|
736
876
|
return byMessage;
|
|
737
877
|
return compareIds(a.sessionId, b.sessionId);
|
|
738
878
|
});
|
|
879
|
+
markInputMarkers(steps, sessionId, model.dataset.userMessages ?? []);
|
|
739
880
|
const treeTotals = createAccumulator();
|
|
740
881
|
for (const node of order)
|
|
741
882
|
mergeAccumulator(treeTotals, ownAccumulators.get(node.id));
|
|
@@ -768,7 +909,19 @@ function buildSessionSnapshot(model, sessionId, timeZone) {
|
|
|
768
909
|
breadcrumbs.reverse();
|
|
769
910
|
breadcrumbs.push({ sessionId, title: sessionTitle(focus), isFocus: true });
|
|
770
911
|
const focusSteps = model.ownedBySession.get(sessionId) ?? [];
|
|
912
|
+
// Focus-session completed messages that are not steps: excluded zero-token
|
|
913
|
+
// rows and fork copies owned elsewhere. Gap metrics must not bridge them.
|
|
914
|
+
const focusStepIds = new Set(focusSteps.map((step) => step.row.messageID));
|
|
915
|
+
const unobservedAtMs = [
|
|
916
|
+
...(model.dataset.excluded ?? [])
|
|
917
|
+
.filter((entry) => entry.sessionId === sessionId)
|
|
918
|
+
.map((entry) => entry.atMs),
|
|
919
|
+
...model.dataset.messages
|
|
920
|
+
.filter((row) => row.sessionID === sessionId && !focusStepIds.has(row.messageID))
|
|
921
|
+
.map(messagePositionMs),
|
|
922
|
+
].sort((a, b) => a - b);
|
|
771
923
|
return {
|
|
924
|
+
...(unobservedAtMs.length > 0 ? { unobservedAtMs } : {}),
|
|
772
925
|
focusSessionId: sessionId,
|
|
773
926
|
timeZone,
|
|
774
927
|
projectId: focusProjectId,
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* the heap.
|
|
10
10
|
*/
|
|
11
11
|
import type { AnalyticsTransport } from "./analytics-protocol.js";
|
|
12
|
+
import { ANALYTICS_DEFAULT_REQUEST_TIMEOUT_MS } from "./analytics-protocol.js";
|
|
12
13
|
import { type GuiLogger } from "./log.js";
|
|
13
14
|
export interface AnalyticsWorkerLike {
|
|
14
15
|
postMessage(message: unknown): void;
|
|
@@ -31,16 +32,14 @@ export interface AnalyticsBridgeOptions {
|
|
|
31
32
|
retryBaseMs?: number;
|
|
32
33
|
/** Stop retrying after this many consecutive failures (default 5). */
|
|
33
34
|
maxRecoveryAttempts?: number;
|
|
35
|
+
/**
|
|
36
|
+
* How long an idle worker is kept warm before it is retired (default 0 =
|
|
37
|
+
* retire as soon as the queue drains). A short grace avoids re-loading the
|
|
38
|
+
* compact index and re-hydrating the model across rapid tab switches.
|
|
39
|
+
*/
|
|
40
|
+
idleRetireMs?: number;
|
|
34
41
|
}
|
|
35
|
-
|
|
36
|
-
* Cold 7d/30d/lifetime analytics catch-up reads the full source store and can
|
|
37
|
-
* legitimately take tens of seconds on a slow local disk; a foreground request
|
|
38
|
-
* queued behind one can add its own scoped read. The old 90 s budget retired
|
|
39
|
-
* healthy workers mid-read on measured sources. Keep a finite budget above the
|
|
40
|
-
* measured worst request (112.9 s on the reported source), so genuinely stuck
|
|
41
|
-
* workers are still retired and recovered on the next request.
|
|
42
|
-
*/
|
|
43
|
-
export declare const ANALYTICS_DEFAULT_REQUEST_TIMEOUT_MS = 180000;
|
|
42
|
+
export { ANALYTICS_DEFAULT_REQUEST_TIMEOUT_MS };
|
|
44
43
|
/** Pure mapping for the optional Node worker heap limit. */
|
|
45
44
|
export declare function workerResourceLimits(limitMb: number | undefined): {
|
|
46
45
|
maxOldGenerationSizeMb: number;
|