@laoyuehanni/dsh-token-usage 0.3.7
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/LICENSE +21 -0
- package/README.md +178 -0
- package/README.zh.md +182 -0
- package/cordis.patch.yml +7 -0
- package/lib/client/CostDeltaFlyLabel.d.ts +8 -0
- package/lib/client/CostDeltaFlyLabel.d.ts.map +1 -0
- package/lib/client/CostDeltaFlyLabel.js +24 -0
- package/lib/client/CostDeltaFlyLabel.js.map +1 -0
- package/lib/client/HitRateText.d.ts +21 -0
- package/lib/client/HitRateText.d.ts.map +1 -0
- package/lib/client/HitRateText.js +16 -0
- package/lib/client/HitRateText.js.map +1 -0
- package/lib/client/QuotaButton.d.ts +70 -0
- package/lib/client/QuotaButton.d.ts.map +1 -0
- package/lib/client/QuotaButton.js +346 -0
- package/lib/client/QuotaButton.js.map +1 -0
- package/lib/client/SessionStatsChip.d.ts +47 -0
- package/lib/client/SessionStatsChip.d.ts.map +1 -0
- package/lib/client/SessionStatsChip.js +141 -0
- package/lib/client/SessionStatsChip.js.map +1 -0
- package/lib/client/StatCard.d.ts +26 -0
- package/lib/client/StatCard.d.ts.map +1 -0
- package/lib/client/StatCard.js +10 -0
- package/lib/client/StatCard.js.map +1 -0
- package/lib/client/TokenUsageCard.d.ts +41 -0
- package/lib/client/TokenUsageCard.d.ts.map +1 -0
- package/lib/client/TokenUsageCard.js +164 -0
- package/lib/client/TokenUsageCard.js.map +1 -0
- package/lib/client/TokenUsageSection.d.ts +32 -0
- package/lib/client/TokenUsageSection.d.ts.map +1 -0
- package/lib/client/TokenUsageSection.js +266 -0
- package/lib/client/TokenUsageSection.js.map +1 -0
- package/lib/client/TrendChart.d.ts +53 -0
- package/lib/client/TrendChart.d.ts.map +1 -0
- package/lib/client/TrendChart.js +141 -0
- package/lib/client/TrendChart.js.map +1 -0
- package/lib/client/UsageView.d.ts +42 -0
- package/lib/client/UsageView.d.ts.map +1 -0
- package/lib/client/UsageView.js +158 -0
- package/lib/client/UsageView.js.map +1 -0
- package/lib/client/async-resource.d.ts +54 -0
- package/lib/client/async-resource.d.ts.map +1 -0
- package/lib/client/async-resource.js +90 -0
- package/lib/client/async-resource.js.map +1 -0
- package/lib/client/card-form.d.ts +171 -0
- package/lib/client/card-form.d.ts.map +1 -0
- package/lib/client/card-form.js +300 -0
- package/lib/client/card-form.js.map +1 -0
- package/lib/client/cost-inflate-motion.d.ts +17 -0
- package/lib/client/cost-inflate-motion.d.ts.map +1 -0
- package/lib/client/cost-inflate-motion.js +61 -0
- package/lib/client/cost-inflate-motion.js.map +1 -0
- package/lib/client/cost-inflate.d.ts +28 -0
- package/lib/client/cost-inflate.d.ts.map +1 -0
- package/lib/client/cost-inflate.js +49 -0
- package/lib/client/cost-inflate.js.map +1 -0
- package/lib/client/day.d.ts +49 -0
- package/lib/client/day.d.ts.map +1 -0
- package/lib/client/day.js +84 -0
- package/lib/client/day.js.map +1 -0
- package/lib/client/format.d.ts +120 -0
- package/lib/client/format.d.ts.map +1 -0
- package/lib/client/format.js +163 -0
- package/lib/client/format.js.map +1 -0
- package/lib/client/index.d.ts +26 -0
- package/lib/client/index.d.ts.map +1 -0
- package/lib/client/index.js +131 -0
- package/lib/client/index.js.map +1 -0
- package/lib/client/locales.d.ts +131 -0
- package/lib/client/locales.d.ts.map +1 -0
- package/lib/client/locales.js +230 -0
- package/lib/client/locales.js.map +1 -0
- package/lib/client/quota-format.d.ts +69 -0
- package/lib/client/quota-format.d.ts.map +1 -0
- package/lib/client/quota-format.js +147 -0
- package/lib/client/quota-format.js.map +1 -0
- package/lib/client/session-stats.d.ts +105 -0
- package/lib/client/session-stats.d.ts.map +1 -0
- package/lib/client/session-stats.js +142 -0
- package/lib/client/session-stats.js.map +1 -0
- package/lib/client/trend-chart/axis.d.ts +21 -0
- package/lib/client/trend-chart/axis.d.ts.map +1 -0
- package/lib/client/trend-chart/axis.js +33 -0
- package/lib/client/trend-chart/axis.js.map +1 -0
- package/lib/client/trend-chart/bucket.d.ts +24 -0
- package/lib/client/trend-chart/bucket.d.ts.map +1 -0
- package/lib/client/trend-chart/bucket.js +28 -0
- package/lib/client/trend-chart/bucket.js.map +1 -0
- package/lib/client/trend-chart/index.d.ts +12 -0
- package/lib/client/trend-chart/index.d.ts.map +1 -0
- package/lib/client/trend-chart/index.js +9 -0
- package/lib/client/trend-chart/index.js.map +1 -0
- package/lib/client/trend-chart/points.d.ts +46 -0
- package/lib/client/trend-chart/points.d.ts.map +1 -0
- package/lib/client/trend-chart/points.js +82 -0
- package/lib/client/trend-chart/points.js.map +1 -0
- package/lib/client/trend-chart/scale.d.ts +47 -0
- package/lib/client/trend-chart/scale.d.ts.map +1 -0
- package/lib/client/trend-chart/scale.js +75 -0
- package/lib/client/trend-chart/scale.js.map +1 -0
- package/lib/client/use-color-scheme.d.ts +18 -0
- package/lib/client/use-color-scheme.d.ts.map +1 -0
- package/lib/client/use-color-scheme.js +37 -0
- package/lib/client/use-color-scheme.js.map +1 -0
- package/lib/client/use-cost-inflate.d.ts +33 -0
- package/lib/client/use-cost-inflate.d.ts.map +1 -0
- package/lib/client/use-cost-inflate.js +108 -0
- package/lib/client/use-cost-inflate.js.map +1 -0
- package/lib/client.js +3892 -0
- package/lib/client.js.map +1 -0
- package/lib/index.d.ts +132 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +599 -0
- package/lib/index.js.map +1 -0
- package/lib/migrate.d.ts +60 -0
- package/lib/migrate.d.ts.map +1 -0
- package/lib/migrate.js +126 -0
- package/lib/migrate.js.map +1 -0
- package/lib/pricing.d.ts +212 -0
- package/lib/pricing.d.ts.map +1 -0
- package/lib/pricing.js +492 -0
- package/lib/pricing.js.map +1 -0
- package/lib/quota/adapters/deepseek-balance.d.ts +18 -0
- package/lib/quota/adapters/deepseek-balance.d.ts.map +1 -0
- package/lib/quota/adapters/deepseek-balance.js +76 -0
- package/lib/quota/adapters/deepseek-balance.js.map +1 -0
- package/lib/quota/adapters/kimi.d.ts +26 -0
- package/lib/quota/adapters/kimi.d.ts.map +1 -0
- package/lib/quota/adapters/kimi.js +91 -0
- package/lib/quota/adapters/kimi.js.map +1 -0
- package/lib/quota/adapters/minimax.d.ts +24 -0
- package/lib/quota/adapters/minimax.d.ts.map +1 -0
- package/lib/quota/adapters/minimax.js +136 -0
- package/lib/quota/adapters/minimax.js.map +1 -0
- package/lib/quota/adapters/opencode-go.d.ts +25 -0
- package/lib/quota/adapters/opencode-go.d.ts.map +1 -0
- package/lib/quota/adapters/opencode-go.js +105 -0
- package/lib/quota/adapters/opencode-go.js.map +1 -0
- package/lib/quota/adapters/openrouter.d.ts +15 -0
- package/lib/quota/adapters/openrouter.d.ts.map +1 -0
- package/lib/quota/adapters/openrouter.js +54 -0
- package/lib/quota/adapters/openrouter.js.map +1 -0
- package/lib/quota/adapters/zhipu.d.ts +38 -0
- package/lib/quota/adapters/zhipu.d.ts.map +1 -0
- package/lib/quota/adapters/zhipu.js +246 -0
- package/lib/quota/adapters/zhipu.js.map +1 -0
- package/lib/quota/credentials.d.ts +79 -0
- package/lib/quota/credentials.d.ts.map +1 -0
- package/lib/quota/credentials.js +130 -0
- package/lib/quota/credentials.js.map +1 -0
- package/lib/quota/http.d.ts +49 -0
- package/lib/quota/http.d.ts.map +1 -0
- package/lib/quota/http.js +114 -0
- package/lib/quota/http.js.map +1 -0
- package/lib/quota/provider-tracking.d.ts +45 -0
- package/lib/quota/provider-tracking.d.ts.map +1 -0
- package/lib/quota/provider-tracking.js +52 -0
- package/lib/quota/provider-tracking.js.map +1 -0
- package/lib/quota/quota-route.d.ts +22 -0
- package/lib/quota/quota-route.d.ts.map +1 -0
- package/lib/quota/quota-route.js +57 -0
- package/lib/quota/quota-route.js.map +1 -0
- package/lib/quota/quota-service.d.ts +54 -0
- package/lib/quota/quota-service.d.ts.map +1 -0
- package/lib/quota/quota-service.js +171 -0
- package/lib/quota/quota-service.js.map +1 -0
- package/lib/quota/registry.d.ts +24 -0
- package/lib/quota/registry.d.ts.map +1 -0
- package/lib/quota/registry.js +38 -0
- package/lib/quota/registry.js.map +1 -0
- package/lib/quota/types.d.ts +79 -0
- package/lib/quota/types.d.ts.map +1 -0
- package/lib/quota/types.js +24 -0
- package/lib/quota/types.js.map +1 -0
- package/lib/record-cache.d.ts +38 -0
- package/lib/record-cache.d.ts.map +1 -0
- package/lib/record-cache.js +143 -0
- package/lib/record-cache.js.map +1 -0
- package/lib/rollup.d.ts +52 -0
- package/lib/rollup.d.ts.map +1 -0
- package/lib/rollup.js +117 -0
- package/lib/rollup.js.map +1 -0
- package/lib/stats-route.d.ts +88 -0
- package/lib/stats-route.d.ts.map +1 -0
- package/lib/stats-route.js +313 -0
- package/lib/stats-route.js.map +1 -0
- package/lib/stats.d.ts +158 -0
- package/lib/stats.d.ts.map +1 -0
- package/lib/stats.js +426 -0
- package/lib/stats.js.map +1 -0
- package/lib/sync-state.d.ts +27 -0
- package/lib/sync-state.d.ts.map +1 -0
- package/lib/sync-state.js +56 -0
- package/lib/sync-state.js.map +1 -0
- package/lib/sync.d.ts +74 -0
- package/lib/sync.d.ts.map +1 -0
- package/lib/sync.js +64 -0
- package/lib/sync.js.map +1 -0
- package/lib/trend-bucket.d.ts +48 -0
- package/lib/trend-bucket.d.ts.map +1 -0
- package/lib/trend-bucket.js +87 -0
- package/lib/trend-bucket.js.map +1 -0
- package/lib/usage-log.d.ts +64 -0
- package/lib/usage-log.d.ts.map +1 -0
- package/lib/usage-log.js +144 -0
- package/lib/usage-log.js.map +1 -0
- package/lib/usage-record.d.ts +59 -0
- package/lib/usage-record.d.ts.map +1 -0
- package/lib/usage-record.js +115 -0
- package/lib/usage-record.js.map +1 -0
- package/lib/wire.d.ts +452 -0
- package/lib/wire.d.ts.map +1 -0
- package/lib/wire.js +144 -0
- package/lib/wire.js.map +1 -0
- package/package.json +100 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Staged form over the `token-usage` settings namespace's fields: the data
|
|
3
|
+
* directory and the mirror region pick.
|
|
4
|
+
*
|
|
5
|
+
* A settings write is a durable, revision-fenced document mutation, so the
|
|
6
|
+
* controls stage what the user picks and commit them only on save: what is on
|
|
7
|
+
* screen is exactly what a save would store. Each field shows its effective
|
|
8
|
+
* value (user layer over composition layer over schema default) and whether
|
|
9
|
+
* the user layer carries it — key presence, not a value comparison, marks an
|
|
10
|
+
* override. The namespace has no secret fields, so there is no write-only
|
|
11
|
+
* control here.
|
|
12
|
+
*
|
|
13
|
+
* Self-contained on purpose: the client bundle-purity rule forbids value
|
|
14
|
+
* imports across plugins, so this package stages and fences its own form
|
|
15
|
+
* (and its own snapshot store) rather than importing the settings section's
|
|
16
|
+
* shared model.
|
|
17
|
+
*
|
|
18
|
+
* @module token-usage/client/card-form
|
|
19
|
+
*/
|
|
20
|
+
import type { SettingsScope } from '@deepseek-ai/dsh-client-runtime/client';
|
|
21
|
+
/** The fields this card edits. */
|
|
22
|
+
export declare const CARD_FIELDS: readonly ["path", "pricingRegion"];
|
|
23
|
+
/** One editable field of the token-usage settings section. */
|
|
24
|
+
export type CardField = typeof CARD_FIELDS[number];
|
|
25
|
+
/** The resolved user-facing section this card edits. */
|
|
26
|
+
export interface SectionValue {
|
|
27
|
+
path?: string;
|
|
28
|
+
pricingRegion?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Live migration progress the card polls after saving a directory change. */
|
|
31
|
+
export interface MigrationView {
|
|
32
|
+
/** Files finished so far. */
|
|
33
|
+
done: number;
|
|
34
|
+
/** Total files this migration touches. */
|
|
35
|
+
total: number;
|
|
36
|
+
/** Phase label for the progress line. */
|
|
37
|
+
phase: 'copying' | 'cleaning';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Minimal observable snapshot source: the stable-reference discipline the
|
|
41
|
+
* shell's stores follow (same snapshot object until the fact moves), with
|
|
42
|
+
* nothing the multi-field form does not use.
|
|
43
|
+
*/
|
|
44
|
+
export interface CardStore {
|
|
45
|
+
/** @returns the current snapshot (stable reference until the next change). */
|
|
46
|
+
getSnapshot(): CardState;
|
|
47
|
+
/** @param listener - invoked after each snapshot change. @returns the disposer. */
|
|
48
|
+
subscribe(listener: () => void): () => void;
|
|
49
|
+
/** @param next - the new snapshot; replaces the reference only on a real change. */
|
|
50
|
+
set(next: CardState): void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Why the Host refused the last save, in a shape the card's locale renders.
|
|
54
|
+
* The settings wire never delivers a refused write's reason (the bound scope
|
|
55
|
+
* recovers silently and resolves), so the form asks the plugin's own guard
|
|
56
|
+
* route and reports the verdict itself.
|
|
57
|
+
*/
|
|
58
|
+
export interface SaveRefusal {
|
|
59
|
+
/** The mid-conversation veto on a directory change. */
|
|
60
|
+
kind: 'sessions-interacting';
|
|
61
|
+
/** Sessions mid-conversation at refusal time, for the notice's number. */
|
|
62
|
+
interactingSessions: number;
|
|
63
|
+
}
|
|
64
|
+
/** What the token-usage settings card renders. */
|
|
65
|
+
export interface CardState {
|
|
66
|
+
/** False while the namespace is not served to this client; the card renders nothing. */
|
|
67
|
+
available: boolean;
|
|
68
|
+
/** Whether the Host document accepts writes. */
|
|
69
|
+
writable: boolean;
|
|
70
|
+
/** Draft text per field ('' marks the inherited/default option). */
|
|
71
|
+
fields: Record<CardField, string>;
|
|
72
|
+
/** Whether saving each field would leave a user-layer entry. */
|
|
73
|
+
overridden: Record<CardField, boolean>;
|
|
74
|
+
/** Whether the form holds an edit that a save would write. */
|
|
75
|
+
dirty: boolean;
|
|
76
|
+
/** Whether a save is crossing the wire. */
|
|
77
|
+
saving: boolean;
|
|
78
|
+
/** Whether the last save did not land as staged; cleared by the next edit or save. */
|
|
79
|
+
failed: boolean;
|
|
80
|
+
/** The Host's refusal of the last save, when the guard named one; cleared
|
|
81
|
+
* by the next edit or save. */
|
|
82
|
+
refusal: SaveRefusal | undefined;
|
|
83
|
+
/** Migration progress while the Host relocates the data directory. */
|
|
84
|
+
migration: MigrationView | undefined;
|
|
85
|
+
}
|
|
86
|
+
/** The form actions the card's slot entry injects. */
|
|
87
|
+
export interface CardActions {
|
|
88
|
+
/** Stage draft text for one field. */
|
|
89
|
+
editField: (field: CardField, text: string) => void;
|
|
90
|
+
/** Stage a clear for one field, so saving lets it re-inherit the composition layer. */
|
|
91
|
+
clearField: (field: CardField) => void;
|
|
92
|
+
/** Write every staged edit, then re-seed from what the Host accepted. */
|
|
93
|
+
save: () => void;
|
|
94
|
+
/** Drop every staged edit. */
|
|
95
|
+
discard: () => void;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Stages the settings edits over the `token-usage` scope.
|
|
99
|
+
*
|
|
100
|
+
* The form publishes through a snapshot store because the slot component
|
|
101
|
+
* reads through a snapshot selector while both the scope and the local drafts
|
|
102
|
+
* change underneath; every projection is rebuilt from the two together. Only
|
|
103
|
+
* fields the user touched are staged, so a save writes a sparse patch and
|
|
104
|
+
* never restates fields it did not see.
|
|
105
|
+
*/
|
|
106
|
+
export declare class CardForm {
|
|
107
|
+
private readonly scope;
|
|
108
|
+
private snapshotValue;
|
|
109
|
+
private readonly listeners;
|
|
110
|
+
private drafts;
|
|
111
|
+
private saving;
|
|
112
|
+
private failed;
|
|
113
|
+
private refusal;
|
|
114
|
+
private migrationView;
|
|
115
|
+
private pollTimer;
|
|
116
|
+
/**
|
|
117
|
+
* @param scope - the bound settings scope for the `token-usage` namespace.
|
|
118
|
+
*/
|
|
119
|
+
constructor(scope: SettingsScope<SectionValue>);
|
|
120
|
+
/** @returns the store the card's component reads through its bound selector. */
|
|
121
|
+
bind(): CardStore;
|
|
122
|
+
/** @returns the edit, clear, save, and discard actions bound to this form. */
|
|
123
|
+
actions(): CardActions;
|
|
124
|
+
/**
|
|
125
|
+
* Write the staged edits, then re-seed from what the Host accepted.
|
|
126
|
+
*
|
|
127
|
+
* The Host is the only authority on acceptance — an empty draft clears the
|
|
128
|
+
* field, anything else stores the trimmed text (so blanking a control and
|
|
129
|
+
* saving is the same gesture as clearing it). A save that did not land keeps
|
|
130
|
+
* its drafts so the user can correct it instead of retyping. A landed save
|
|
131
|
+
* that moved the data directory starts the migration poll: the Host
|
|
132
|
+
* relocates as a two-phase commit and the card shows the file progress
|
|
133
|
+
* until it settles.
|
|
134
|
+
*
|
|
135
|
+
* A staged directory edit is vetted through the plugin's guard route
|
|
136
|
+
* before anything writes, and re-checked when the write did not land: the
|
|
137
|
+
* settings wire swallows a refused write (the bound scope recovers
|
|
138
|
+
* silently), so the guard is the only channel that can name the refusal —
|
|
139
|
+
* otherwise the card could only say "did not land".
|
|
140
|
+
*/
|
|
141
|
+
private save;
|
|
142
|
+
/**
|
|
143
|
+
* Ask the Host's guard route whether saving this directory would be refused
|
|
144
|
+
* right now; a transport failure stays advisory (the write path's own
|
|
145
|
+
* read-back still governs acceptance).
|
|
146
|
+
* @param path - the staged path text ('' for the clear-to-default gesture).
|
|
147
|
+
* @returns the refusal to show, or undefined when the save may proceed.
|
|
148
|
+
*/
|
|
149
|
+
private guard;
|
|
150
|
+
/**
|
|
151
|
+
* Poll the Host's migration endpoint until it answers null (no migration
|
|
152
|
+
* running), publishing each progress step.
|
|
153
|
+
*/
|
|
154
|
+
private pollMigration;
|
|
155
|
+
/** Stop the poll timer; the progress line leaves with the next publish. */
|
|
156
|
+
private stopPolling;
|
|
157
|
+
private snapshot;
|
|
158
|
+
/** The raw user layer narrowed to a record; the wire answer is `unknown`. */
|
|
159
|
+
private userLayer;
|
|
160
|
+
private storedValue;
|
|
161
|
+
private stored;
|
|
162
|
+
/** The resolved (draft-free) text of one field; '' means inherited. */
|
|
163
|
+
private effectiveOf;
|
|
164
|
+
/** The effective (draft-or-resolved) text of one field; '' means inherited. */
|
|
165
|
+
private textOf;
|
|
166
|
+
private project;
|
|
167
|
+
/** Replace the snapshot reference and notify, only when the fact moved. */
|
|
168
|
+
private store;
|
|
169
|
+
private publish;
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=card-form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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AAW;IAOnB,OAAO,CAAC,QAAQ;IAIhB,6EAA6E;IAC7E,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,MAAM;IAKd,uEAAuE;IACvE,OAAO,CAAC,WAAW;IAKnB,+EAA+E;IAC/E,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,OAAO;IA6Bf,2EAA2E;IAC3E,OAAO,CAAC,KAAK;IAMb,OAAO,CAAC,OAAO;CAGhB"}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Staged form over the `token-usage` settings namespace's fields: the data
|
|
3
|
+
* directory and the mirror region pick.
|
|
4
|
+
*
|
|
5
|
+
* A settings write is a durable, revision-fenced document mutation, so the
|
|
6
|
+
* controls stage what the user picks and commit them only on save: what is on
|
|
7
|
+
* screen is exactly what a save would store. Each field shows its effective
|
|
8
|
+
* value (user layer over composition layer over schema default) and whether
|
|
9
|
+
* the user layer carries it — key presence, not a value comparison, marks an
|
|
10
|
+
* override. The namespace has no secret fields, so there is no write-only
|
|
11
|
+
* control here.
|
|
12
|
+
*
|
|
13
|
+
* Self-contained on purpose: the client bundle-purity rule forbids value
|
|
14
|
+
* imports across plugins, so this package stages and fences its own form
|
|
15
|
+
* (and its own snapshot store) rather than importing the settings section's
|
|
16
|
+
* shared model.
|
|
17
|
+
*
|
|
18
|
+
* @module token-usage/client/card-form
|
|
19
|
+
*/
|
|
20
|
+
import { DIR_GUARD_PATH, MIGRATION_PATH } from "../wire.js";
|
|
21
|
+
/** The fields this card edits. */
|
|
22
|
+
export const CARD_FIELDS = ['path', 'pricingRegion'];
|
|
23
|
+
/**
|
|
24
|
+
* Stages the settings edits over the `token-usage` scope.
|
|
25
|
+
*
|
|
26
|
+
* The form publishes through a snapshot store because the slot component
|
|
27
|
+
* reads through a snapshot selector while both the scope and the local drafts
|
|
28
|
+
* change underneath; every projection is rebuilt from the two together. Only
|
|
29
|
+
* fields the user touched are staged, so a save writes a sparse patch and
|
|
30
|
+
* never restates fields it did not see.
|
|
31
|
+
*/
|
|
32
|
+
export class CardForm {
|
|
33
|
+
scope;
|
|
34
|
+
snapshotValue;
|
|
35
|
+
listeners = new Set();
|
|
36
|
+
drafts = {};
|
|
37
|
+
saving = false;
|
|
38
|
+
failed = false;
|
|
39
|
+
refusal;
|
|
40
|
+
migrationView;
|
|
41
|
+
pollTimer;
|
|
42
|
+
/**
|
|
43
|
+
* @param scope - the bound settings scope for the `token-usage` namespace.
|
|
44
|
+
*/
|
|
45
|
+
constructor(scope) {
|
|
46
|
+
this.scope = scope;
|
|
47
|
+
this.snapshotValue = this.project();
|
|
48
|
+
scope.subscribe(() => { this.publish(); });
|
|
49
|
+
// A relocation another surface started (or one left over from a boot)
|
|
50
|
+
// shows its progress here too.
|
|
51
|
+
void this.pollMigration();
|
|
52
|
+
}
|
|
53
|
+
/** @returns the store the card's component reads through its bound selector. */
|
|
54
|
+
bind() {
|
|
55
|
+
return {
|
|
56
|
+
getSnapshot: () => this.snapshotValue,
|
|
57
|
+
subscribe: (listener) => {
|
|
58
|
+
this.listeners.add(listener);
|
|
59
|
+
return () => { this.listeners.delete(listener); };
|
|
60
|
+
},
|
|
61
|
+
set: (next) => { this.store(next); },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** @returns the edit, clear, save, and discard actions bound to this form. */
|
|
65
|
+
actions() {
|
|
66
|
+
return {
|
|
67
|
+
editField: (field, text) => {
|
|
68
|
+
this.drafts[field] = text;
|
|
69
|
+
this.failed = false;
|
|
70
|
+
this.refusal = undefined;
|
|
71
|
+
this.publish();
|
|
72
|
+
},
|
|
73
|
+
clearField: (field) => {
|
|
74
|
+
this.drafts[field] = '';
|
|
75
|
+
this.failed = false;
|
|
76
|
+
this.refusal = undefined;
|
|
77
|
+
this.publish();
|
|
78
|
+
},
|
|
79
|
+
save: () => { void this.save(); },
|
|
80
|
+
discard: () => {
|
|
81
|
+
if (Object.keys(this.drafts).length === 0 && !this.failed)
|
|
82
|
+
return;
|
|
83
|
+
this.drafts = {};
|
|
84
|
+
this.failed = false;
|
|
85
|
+
this.refusal = undefined;
|
|
86
|
+
this.publish();
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Write the staged edits, then re-seed from what the Host accepted.
|
|
92
|
+
*
|
|
93
|
+
* The Host is the only authority on acceptance — an empty draft clears the
|
|
94
|
+
* field, anything else stores the trimmed text (so blanking a control and
|
|
95
|
+
* saving is the same gesture as clearing it). A save that did not land keeps
|
|
96
|
+
* its drafts so the user can correct it instead of retyping. A landed save
|
|
97
|
+
* that moved the data directory starts the migration poll: the Host
|
|
98
|
+
* relocates as a two-phase commit and the card shows the file progress
|
|
99
|
+
* until it settles.
|
|
100
|
+
*
|
|
101
|
+
* A staged directory edit is vetted through the plugin's guard route
|
|
102
|
+
* before anything writes, and re-checked when the write did not land: the
|
|
103
|
+
* settings wire swallows a refused write (the bound scope recovers
|
|
104
|
+
* silently), so the guard is the only channel that can name the refusal —
|
|
105
|
+
* otherwise the card could only say "did not land".
|
|
106
|
+
*/
|
|
107
|
+
async save() {
|
|
108
|
+
const edited = CARD_FIELDS.filter(field => this.drafts[field] !== undefined);
|
|
109
|
+
if (edited.length === 0 || this.saving)
|
|
110
|
+
return;
|
|
111
|
+
// Snapshot the intended writes: a keystroke mid-await must not change what
|
|
112
|
+
// this save commits.
|
|
113
|
+
const intended = edited.map(field => [field, this.drafts[field].trim()]);
|
|
114
|
+
this.saving = true;
|
|
115
|
+
this.failed = false;
|
|
116
|
+
this.refusal = undefined;
|
|
117
|
+
this.publish();
|
|
118
|
+
const pathEdit = intended.find(([field]) => field === 'path');
|
|
119
|
+
if (pathEdit !== undefined) {
|
|
120
|
+
const blocked = await this.guard(pathEdit[1]);
|
|
121
|
+
if (blocked !== undefined) {
|
|
122
|
+
// Refused up front: nothing writes, the drafts stay staged, and the
|
|
123
|
+
// notice says exactly what to end before saving again.
|
|
124
|
+
this.saving = false;
|
|
125
|
+
this.failed = true;
|
|
126
|
+
this.refusal = blocked;
|
|
127
|
+
this.publish();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
let landed = true;
|
|
132
|
+
try {
|
|
133
|
+
for (const [field, text] of intended) {
|
|
134
|
+
if (text === '')
|
|
135
|
+
await this.scope.unset(field);
|
|
136
|
+
else
|
|
137
|
+
await this.scope.set(field, text);
|
|
138
|
+
}
|
|
139
|
+
// Read back: the Host's validators own the constraints no schema
|
|
140
|
+
// expresses, so acceptance is judged from the stored layers.
|
|
141
|
+
for (const [field, text] of intended) {
|
|
142
|
+
if (text === '' ? this.stored(field) : this.storedValue(field) !== text) {
|
|
143
|
+
landed = false;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (_settingsWriteFailure) {
|
|
149
|
+
landed = false;
|
|
150
|
+
}
|
|
151
|
+
// A directory write that did not land is usually the Host's validator
|
|
152
|
+
// refusing between the pre-check and the write (a session started
|
|
153
|
+
// mid-save); ask the guard again so the notice still names it.
|
|
154
|
+
if (!landed && pathEdit !== undefined) {
|
|
155
|
+
const blocked = await this.guard(pathEdit[1]);
|
|
156
|
+
if (blocked !== undefined)
|
|
157
|
+
this.refusal = blocked;
|
|
158
|
+
}
|
|
159
|
+
if (landed) {
|
|
160
|
+
for (const [field, _text] of intended)
|
|
161
|
+
delete this.drafts[field];
|
|
162
|
+
}
|
|
163
|
+
this.saving = false;
|
|
164
|
+
this.failed = !landed;
|
|
165
|
+
if (landed && intended.some(([field]) => field === 'path'))
|
|
166
|
+
void this.pollMigration();
|
|
167
|
+
this.publish();
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Ask the Host's guard route whether saving this directory would be refused
|
|
171
|
+
* right now; a transport failure stays advisory (the write path's own
|
|
172
|
+
* read-back still governs acceptance).
|
|
173
|
+
* @param path - the staged path text ('' for the clear-to-default gesture).
|
|
174
|
+
* @returns the refusal to show, or undefined when the save may proceed.
|
|
175
|
+
*/
|
|
176
|
+
async guard(path) {
|
|
177
|
+
try {
|
|
178
|
+
const response = await fetch(`${DIR_GUARD_PATH}?path=${encodeURIComponent(path)}`);
|
|
179
|
+
if (!response.ok)
|
|
180
|
+
return undefined;
|
|
181
|
+
const body = await response.json();
|
|
182
|
+
if (body.blocked === true && typeof body.interactingSessions === 'number' && body.interactingSessions > 0) {
|
|
183
|
+
return { kind: 'sessions-interacting', interactingSessions: body.interactingSessions };
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch (_guardFailure) {
|
|
187
|
+
// Unreachable guard: proceed to the write and let acceptance speak.
|
|
188
|
+
}
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Poll the Host's migration endpoint until it answers null (no migration
|
|
193
|
+
* running), publishing each progress step.
|
|
194
|
+
*/
|
|
195
|
+
async pollMigration() {
|
|
196
|
+
if (this.pollTimer !== undefined)
|
|
197
|
+
return;
|
|
198
|
+
const tick = async () => {
|
|
199
|
+
let view;
|
|
200
|
+
try {
|
|
201
|
+
const response = await fetch(MIGRATION_PATH);
|
|
202
|
+
if (response.ok) {
|
|
203
|
+
const body = await response.json();
|
|
204
|
+
if (body !== null
|
|
205
|
+
&& (body.phase === 'copying' || body.phase === 'cleaning')
|
|
206
|
+
&& typeof body.done === 'number' && typeof body.total === 'number') {
|
|
207
|
+
view = body;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch (_migrationPollFailure) {
|
|
212
|
+
// The next tick retries; a transient read must not end the poll.
|
|
213
|
+
}
|
|
214
|
+
if (view === undefined && this.migrationView === undefined) {
|
|
215
|
+
this.stopPolling();
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const settled = view === undefined;
|
|
219
|
+
if (settled)
|
|
220
|
+
this.stopPolling();
|
|
221
|
+
this.migrationView = view;
|
|
222
|
+
this.publish();
|
|
223
|
+
};
|
|
224
|
+
await tick();
|
|
225
|
+
if (this.pollTimer === undefined && this.migrationView !== undefined) {
|
|
226
|
+
this.pollTimer = setInterval(() => { void tick(); }, 300);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/** Stop the poll timer; the progress line leaves with the next publish. */
|
|
230
|
+
stopPolling() {
|
|
231
|
+
if (this.pollTimer !== undefined) {
|
|
232
|
+
clearInterval(this.pollTimer);
|
|
233
|
+
this.pollTimer = undefined;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
snapshot() {
|
|
237
|
+
return this.scope.getSnapshot();
|
|
238
|
+
}
|
|
239
|
+
/** The raw user layer narrowed to a record; the wire answer is `unknown`. */
|
|
240
|
+
userLayer() {
|
|
241
|
+
const user = this.snapshot().user;
|
|
242
|
+
return typeof user === 'object' && user !== null ? user : undefined;
|
|
243
|
+
}
|
|
244
|
+
storedValue(field) {
|
|
245
|
+
return this.userLayer()?.[field];
|
|
246
|
+
}
|
|
247
|
+
stored(field) {
|
|
248
|
+
const user = this.userLayer();
|
|
249
|
+
return user !== undefined && Object.hasOwn(user, field);
|
|
250
|
+
}
|
|
251
|
+
/** The resolved (draft-free) text of one field; '' means inherited. */
|
|
252
|
+
effectiveOf(field) {
|
|
253
|
+
const value = this.snapshot().value?.[field];
|
|
254
|
+
return typeof value === 'string' ? value : '';
|
|
255
|
+
}
|
|
256
|
+
/** The effective (draft-or-resolved) text of one field; '' means inherited. */
|
|
257
|
+
textOf(field) {
|
|
258
|
+
return this.drafts[field] ?? this.effectiveOf(field);
|
|
259
|
+
}
|
|
260
|
+
project() {
|
|
261
|
+
const snapshot = this.snapshot();
|
|
262
|
+
const fields = {};
|
|
263
|
+
const overridden = {};
|
|
264
|
+
let dirty = false;
|
|
265
|
+
for (const field of CARD_FIELDS) {
|
|
266
|
+
fields[field] = this.textOf(field);
|
|
267
|
+
// A staged edit answers for itself, so the override badge previews the
|
|
268
|
+
// save rather than reporting a state the pending edit contradicts.
|
|
269
|
+
overridden[field] = this.drafts[field] !== undefined
|
|
270
|
+
? this.drafts[field].trim() !== ''
|
|
271
|
+
: this.stored(field);
|
|
272
|
+
if (this.drafts[field] !== undefined && this.drafts[field] !== this.effectiveOf(field)) {
|
|
273
|
+
dirty = true;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
available: snapshot.status === 'ready',
|
|
278
|
+
writable: snapshot.writable,
|
|
279
|
+
fields,
|
|
280
|
+
overridden,
|
|
281
|
+
dirty,
|
|
282
|
+
saving: this.saving,
|
|
283
|
+
failed: this.failed,
|
|
284
|
+
refusal: this.refusal,
|
|
285
|
+
migration: this.migrationView,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
/** Replace the snapshot reference and notify, only when the fact moved. */
|
|
289
|
+
store(next) {
|
|
290
|
+
if (next === this.snapshotValue)
|
|
291
|
+
return;
|
|
292
|
+
this.snapshotValue = next;
|
|
293
|
+
for (const listener of this.listeners)
|
|
294
|
+
listener();
|
|
295
|
+
}
|
|
296
|
+
publish() {
|
|
297
|
+
this.store(this.project());
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
//# sourceMappingURL=card-form.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card-form.js","sourceRoot":"","sources":["../../src/client/card-form.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3D,kCAAkC;AAClC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,eAAe,CAAU,CAAA;AAmF7D;;;;;;;;GAQG;AACH,MAAM,OAAO,QAAQ;IAaU;IAZrB,aAAa,CAAW;IACf,SAAS,GAAG,IAAI,GAAG,EAAc,CAAA;IAC1C,MAAM,GAAuC,EAAE,CAAA;IAC/C,MAAM,GAAG,KAAK,CAAA;IACd,MAAM,GAAG,KAAK,CAAA;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;QAC3B,IAAI,IAAI,KAAK,IAAI,CAAC,aAAa;YAAE,OAAM;QACvC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA;QACzB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS;YAAE,QAAQ,EAAE,CAAA;IACnD,CAAC;IAEO,OAAO;QACb,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Imperative cost-cell motion (Web Animations API). Avoids CSS `@keyframes`
|
|
3
|
+
* + custom-property bugs in some embedded hosts; runs on the actual DOM node.
|
|
4
|
+
*
|
|
5
|
+
* @module token-usage/client/cost-inflate-motion
|
|
6
|
+
*/
|
|
7
|
+
import type { CostInflateVars } from './cost-inflate.ts';
|
|
8
|
+
/** The user's motion preference: both runners refuse to animate (returning
|
|
9
|
+
* null) when the OS asks for reduced motion. Exported so the chip hook can
|
|
10
|
+
* skip spawning the DOM for flies that would never animate — a static +Δ
|
|
11
|
+
* flash reads as a glitch, not information. */
|
|
12
|
+
export declare function motionAllowed(): boolean;
|
|
13
|
+
/** Scale bounce on the cost figure (`costPop`). */
|
|
14
|
+
export declare function runCostPop(el: HTMLElement, v: CostInflateVars): Animation | null;
|
|
15
|
+
/** +Δ label rise (`deltaRise`). Caller must position the element (absolute). */
|
|
16
|
+
export declare function runDeltaFly(el: HTMLElement, v: CostInflateVars): Animation | null;
|
|
17
|
+
//# sourceMappingURL=cost-inflate-motion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-inflate-motion.d.ts","sourceRoot":"","sources":["../../src/client/cost-inflate-motion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAExD;;;+CAG+C;AAC/C,wBAAgB,aAAa,IAAI,OAAO,CAGvC;AAMD,mDAAmD;AACnD,wBAAgB,UAAU,CAAC,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,eAAe,GAAG,SAAS,GAAG,IAAI,CAuBhF;AAED,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,eAAe,GAAG,SAAS,GAAG,IAAI,CAcjF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Imperative cost-cell motion (Web Animations API). Avoids CSS `@keyframes`
|
|
3
|
+
* + custom-property bugs in some embedded hosts; runs on the actual DOM node.
|
|
4
|
+
*
|
|
5
|
+
* @module token-usage/client/cost-inflate-motion
|
|
6
|
+
*/
|
|
7
|
+
/** The user's motion preference: both runners refuse to animate (returning
|
|
8
|
+
* null) when the OS asks for reduced motion. Exported so the chip hook can
|
|
9
|
+
* skip spawning the DOM for flies that would never animate — a static +Δ
|
|
10
|
+
* flash reads as a glitch, not information. */
|
|
11
|
+
export function motionAllowed() {
|
|
12
|
+
return typeof window.matchMedia !== 'function'
|
|
13
|
+
|| !window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
14
|
+
}
|
|
15
|
+
function waapiAvailable(el) {
|
|
16
|
+
return typeof el.animate === 'function';
|
|
17
|
+
}
|
|
18
|
+
/** Scale bounce on the cost figure (`costPop`). */
|
|
19
|
+
export function runCostPop(el, v) {
|
|
20
|
+
if (!motionAllowed() || !waapiAvailable(el))
|
|
21
|
+
return null;
|
|
22
|
+
const popScale = Number(v.popScale);
|
|
23
|
+
const echo = 1 + (popScale - 1) * 0.28;
|
|
24
|
+
const warnMix = v.warnMix;
|
|
25
|
+
return el.animate([
|
|
26
|
+
{ transform: 'scale(1)', color: 'var(--dsw-alias-label-primary)' },
|
|
27
|
+
{
|
|
28
|
+
transform: `scale(${String(popScale)})`,
|
|
29
|
+
color: `color-mix(in srgb, var(--dsw-alias-state-warn-primary) ${warnMix}, var(--dsw-alias-label-primary))`,
|
|
30
|
+
offset: 0.35,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
transform: `scale(${String(echo)})`,
|
|
34
|
+
color: `color-mix(in srgb, var(--dsw-alias-state-warn-primary) ${warnMix}, var(--dsw-alias-label-primary))`,
|
|
35
|
+
offset: 0.70,
|
|
36
|
+
},
|
|
37
|
+
{ transform: 'scale(1)', color: 'var(--dsw-alias-label-primary)' },
|
|
38
|
+
], {
|
|
39
|
+
duration: v.inflateMs,
|
|
40
|
+
easing: 'cubic-bezier(0.25, 0.85, 0.35, 1)',
|
|
41
|
+
fill: 'both',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** +Δ label rise (`deltaRise`). Caller must position the element (absolute). */
|
|
45
|
+
export function runDeltaFly(el, v) {
|
|
46
|
+
if (!motionAllowed() || !waapiAvailable(el))
|
|
47
|
+
return null;
|
|
48
|
+
return el.animate([
|
|
49
|
+
{ opacity: 0, transform: 'translate(-50%, -20%)' },
|
|
50
|
+
{ opacity: 1, transform: 'translate(-50%, -20%)', offset: 0.15 },
|
|
51
|
+
{
|
|
52
|
+
opacity: 0,
|
|
53
|
+
transform: `translate(calc(-50% + ${v.flyX}), calc(-100% - ${v.flyY}))`,
|
|
54
|
+
},
|
|
55
|
+
], {
|
|
56
|
+
duration: v.inflateMs,
|
|
57
|
+
easing: 'cubic-bezier(0.22, 0.55, 0.25, 1)',
|
|
58
|
+
fill: 'both',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=cost-inflate-motion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-inflate-motion.js","sourceRoot":"","sources":["../../src/client/cost-inflate-motion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;+CAG+C;AAC/C,MAAM,UAAU,aAAa;IAC3B,OAAO,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU;WACzC,CAAC,MAAM,CAAC,UAAU,CAAC,kCAAkC,CAAC,CAAC,OAAO,CAAA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,EAAE,SAAS,EAAE,uBAAuB,EAAE;QAClD,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,EAAE,IAAI,EAAE;QAChE;YACE,OAAO,EAAE,CAAC;YACV,SAAS,EAAE,yBAAyB,CAAC,CAAC,IAAI,mBAAmB,CAAC,CAAC,IAAI,IAAI;SACxE;KACF,EAAE;QACD,QAAQ,EAAE,CAAC,CAAC,SAAS;QACrB,MAAM,EAAE,mCAAmC;QAC3C,IAAI,EAAE,MAAM;KACb,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SessionStatsChip cost-cell inflate animation: per-request intensity from
|
|
3
|
+
* token deltas and parameters for `costPop` / `deltaRise`. Pure functions
|
|
4
|
+
* only — the chip hook owns timers and DOM.
|
|
5
|
+
*
|
|
6
|
+
* @module token-usage/client/cost-inflate
|
|
7
|
+
*/
|
|
8
|
+
import type { UsageTotals } from '../wire.ts';
|
|
9
|
+
/** Clamp to the unit interval. */
|
|
10
|
+
export declare function clamp01(n: number): number;
|
|
11
|
+
/** Token totals of one refresh minus the previous snapshot (non-negative). */
|
|
12
|
+
export declare function deltaTotals(prev: UsageTotals, next: UsageTotals): UsageTotals;
|
|
13
|
+
/**
|
|
14
|
+
* Single-step intensity from the latest request's token delta (not session
|
|
15
|
+
* cumulative hit rate): `I = clamp01(0.55·norm(miss) + 0.45·norm(output))`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function computeIntensityFromDelta(delta: UsageTotals): number;
|
|
18
|
+
/** Parameters driving `costPop` and `deltaRise` for one request step. */
|
|
19
|
+
export interface CostInflateVars {
|
|
20
|
+
inflateMs: number;
|
|
21
|
+
popScale: string;
|
|
22
|
+
warnMix: string;
|
|
23
|
+
flyY: string;
|
|
24
|
+
flyX: string;
|
|
25
|
+
}
|
|
26
|
+
/** Map step intensity I to animation parameters. */
|
|
27
|
+
export declare function animVars(I: number): CostInflateVars;
|
|
28
|
+
//# sourceMappingURL=cost-inflate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-inflate.d.ts","sourceRoot":"","sources":["../../src/client/cost-inflate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAK7C,kCAAkC;AAClC,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,GAAG,WAAW,CAQ7E;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAMpE;AAED,yEAAyE;AACzE,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AAMD,oDAAoD;AACpD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,eAAe,CASnD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SessionStatsChip cost-cell inflate animation: per-request intensity from
|
|
3
|
+
* token deltas and parameters for `costPop` / `deltaRise`. Pure functions
|
|
4
|
+
* only — the chip hook owns timers and DOM.
|
|
5
|
+
*
|
|
6
|
+
* @module token-usage/client/cost-inflate
|
|
7
|
+
*/
|
|
8
|
+
const MISS_RATE_CAP = 0.55;
|
|
9
|
+
const OUT_CAP = 32_000;
|
|
10
|
+
/** Clamp to the unit interval. */
|
|
11
|
+
export function clamp01(n) {
|
|
12
|
+
return Math.max(0, Math.min(1, n));
|
|
13
|
+
}
|
|
14
|
+
/** Token totals of one refresh minus the previous snapshot (non-negative). */
|
|
15
|
+
export function deltaTotals(prev, next) {
|
|
16
|
+
return {
|
|
17
|
+
requests: Math.max(0, next.requests - prev.requests),
|
|
18
|
+
inputTokens: Math.max(0, next.inputTokens - prev.inputTokens),
|
|
19
|
+
outputTokens: Math.max(0, next.outputTokens - prev.outputTokens),
|
|
20
|
+
cacheReadTokens: Math.max(0, next.cacheReadTokens - prev.cacheReadTokens),
|
|
21
|
+
cacheWriteTokens: Math.max(0, next.cacheWriteTokens - prev.cacheWriteTokens),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Single-step intensity from the latest request's token delta (not session
|
|
26
|
+
* cumulative hit rate): `I = clamp01(0.55·norm(miss) + 0.45·norm(output))`.
|
|
27
|
+
*/
|
|
28
|
+
export function computeIntensityFromDelta(delta) {
|
|
29
|
+
const served = delta.inputTokens + delta.cacheReadTokens;
|
|
30
|
+
const hitRate = served > 0 ? delta.cacheReadTokens / served : 0.5;
|
|
31
|
+
const miss = clamp01((1 - hitRate) / MISS_RATE_CAP);
|
|
32
|
+
const out = clamp01(delta.outputTokens / OUT_CAP);
|
|
33
|
+
return clamp01(0.55 * miss + 0.45 * out);
|
|
34
|
+
}
|
|
35
|
+
function lerp(a, b, t) {
|
|
36
|
+
return a + (b - a) * t;
|
|
37
|
+
}
|
|
38
|
+
/** Map step intensity I to animation parameters. */
|
|
39
|
+
export function animVars(I) {
|
|
40
|
+
const inflateMs = Math.round(lerp(1000, 1800, I));
|
|
41
|
+
return {
|
|
42
|
+
inflateMs,
|
|
43
|
+
popScale: lerp(1.08, 1.32, I).toFixed(3),
|
|
44
|
+
warnMix: `${Math.round(lerp(0, 55, I))}%`,
|
|
45
|
+
flyY: `${lerp(22, 38, I).toFixed(1)}px`,
|
|
46
|
+
flyX: `${((Math.random() - 0.5) * 10).toFixed(1)}px`,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=cost-inflate.js.map
|