opencode-usage-insights 0.1.0 → 0.1.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 +189 -66
- package/dist/core.d.ts +38 -31
- package/dist/index.d.ts +10 -3
- package/dist/index.js +207 -257
- package/dist/index.js.map +10 -10
- package/dist/line.d.ts +20 -7
- package/dist/panel-build.d.ts +5 -1
- package/dist/panel-data.d.ts +36 -23
- package/dist/panel.d.ts +8 -0
- package/dist/pricing.d.ts +72 -0
- package/dist/recorder.d.ts +10 -17
- package/dist/sidebar.d.ts +3 -3
- package/dist/stats/aggregates.d.ts +39 -37
- package/dist/stats/db.d.ts +17 -18
- package/dist/stats/maintenance.d.ts +17 -0
- package/dist/stats/queries.d.ts +25 -30
- package/dist/text.d.ts +5 -8
- package/dist/tui.d.ts +11 -10
- package/dist/tui.js +583 -428
- package/dist/tui.js.map +16 -15
- package/package.json +2 -2
- package/dist/endpoint.d.ts +0 -46
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Database } from "bun:sqlite";
|
|
2
|
+
import type { PriceRef, PriceTokens } from "../pricing";
|
|
2
3
|
import { type TableName } from "./db";
|
|
3
4
|
/**
|
|
4
5
|
* Database maintenance: what the file holds, how much of it is worth keeping,
|
|
@@ -27,6 +28,8 @@ export type DbInfo = {
|
|
|
27
28
|
days: number;
|
|
28
29
|
steps: number;
|
|
29
30
|
}>;
|
|
31
|
+
/** Steps at $0 with a model identity and no list-price estimate yet. */
|
|
32
|
+
unpriced: number;
|
|
30
33
|
};
|
|
31
34
|
export declare function dbInfo(db: Database, path: string, now?: number): DbInfo;
|
|
32
35
|
export type PruneResult = {
|
|
@@ -46,4 +49,18 @@ export declare function vacuum(db: Database, path: string): {
|
|
|
46
49
|
after: number;
|
|
47
50
|
freed: number;
|
|
48
51
|
};
|
|
52
|
+
/** True when the database carries the list-price column. */
|
|
53
|
+
export declare function hasListCost(db: Database): boolean;
|
|
54
|
+
export type BackfillResult = {
|
|
55
|
+
/** Steps that matched the `cost = 0 AND list_cost IS NULL` condition. */
|
|
56
|
+
candidates: number;
|
|
57
|
+
/** Steps a price was known for and written. */
|
|
58
|
+
updated: number;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Price historical steps the host recorded at $0. The price is today's catalog,
|
|
62
|
+
* not the one in force when the step ran, so this is explicitly user-triggered.
|
|
63
|
+
* A step whose model has no price is left NULL for a later run.
|
|
64
|
+
*/
|
|
65
|
+
export declare function backfillListCost(db: Database, price: (ref: PriceRef, tokens: PriceTokens) => number | undefined): BackfillResult;
|
|
49
66
|
export type { TableName };
|
package/dist/stats/queries.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type Range = {
|
|
|
18
18
|
to?: number | undefined;
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
|
-
* Panel filters. They narrow every aggregation to one model, one
|
|
21
|
+
* Panel filters. They narrow every aggregation to one model, one provider or
|
|
22
22
|
* one session, and are applied with the same `WHERE` builder the range uses so
|
|
23
23
|
* a filtered view and a drill-down agree.
|
|
24
24
|
*/
|
|
@@ -32,11 +32,12 @@ export type Filters = {
|
|
|
32
32
|
*/
|
|
33
33
|
modelKey?: string | undefined;
|
|
34
34
|
/**
|
|
35
|
-
* The
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* The provider the model ran through, as OpenCode configured it
|
|
36
|
+
* (`opencode-go`, `deepseek`, `deepinfra`). It is the identity every view
|
|
37
|
+
* groups by: a gateway may re-route the request, but the upstream that
|
|
38
|
+
* actually ran it is not observable.
|
|
38
39
|
*/
|
|
39
|
-
|
|
40
|
+
provider?: string | undefined;
|
|
40
41
|
/**
|
|
41
42
|
* One session, exactly. Used by the `session` range and by the overview's
|
|
42
43
|
* "this session" block, which must not pick up the steps of every other
|
|
@@ -52,7 +53,22 @@ export type Usage = {
|
|
|
52
53
|
output: number;
|
|
53
54
|
reasoning: number;
|
|
54
55
|
cost: number;
|
|
56
|
+
/** List-price estimate for steps the host reported as costing nothing. */
|
|
57
|
+
listCost: number;
|
|
55
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* What the selection costs: charged money plus the list-price estimate of the
|
|
61
|
+
* steps the host reported as free. Display code marks the estimated part.
|
|
62
|
+
*/
|
|
63
|
+
export declare function spend(usage: Pick<Usage, "cost" | "listCost">): number;
|
|
64
|
+
/** True when at least one step in the aggregate is an estimate. */
|
|
65
|
+
export declare function hasEstimate(usage: Pick<Usage, "listCost">): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* The list-price estimate of one session, from the steps the plugin recorded.
|
|
68
|
+
* The live line uses it for the `sess` segment; a session with no recorded
|
|
69
|
+
* estimate (or a database without the column) answers 0.
|
|
70
|
+
*/
|
|
71
|
+
export declare function sessionListCost(db: Database, sessionID: string): number;
|
|
56
72
|
export declare const STEP_TIME = "COALESCE(created_at, recorded_at)";
|
|
57
73
|
/**
|
|
58
74
|
* The identity of a model *and* its variant, in SQL: `modelKey` says a variant
|
|
@@ -93,8 +109,6 @@ export type Overview = Usage & {
|
|
|
93
109
|
export declare function overview(db: Database, range?: Range, filters?: Filters): Overview;
|
|
94
110
|
export type ProviderUsage = Usage & {
|
|
95
111
|
providerID: string;
|
|
96
|
-
/** Gateway routing endpoints that served the requests. */
|
|
97
|
-
routers: string[];
|
|
98
112
|
firstAt: number | undefined;
|
|
99
113
|
lastAt: number | undefined;
|
|
100
114
|
};
|
|
@@ -106,8 +120,8 @@ export type ModelUsage = {
|
|
|
106
120
|
};
|
|
107
121
|
/**
|
|
108
122
|
* Usage per model, each with the providers that served it. This is the view
|
|
109
|
-
* that answers "which
|
|
110
|
-
*
|
|
123
|
+
* that answers "through which provider is this model actually coming, over the
|
|
124
|
+
* selected period".
|
|
111
125
|
*/
|
|
112
126
|
export declare function models(db: Database, range?: Range, filters?: Filters): ModelUsage[];
|
|
113
127
|
export type TimelineBucket = {
|
|
@@ -196,9 +210,6 @@ export type TurnUsage = {
|
|
|
196
210
|
providerID: string | undefined;
|
|
197
211
|
modelID: string | undefined;
|
|
198
212
|
variant: string | undefined;
|
|
199
|
-
router: string | undefined;
|
|
200
|
-
/** The displayed identity differs from the previous turn of the session. */
|
|
201
|
-
routerChanged: boolean;
|
|
202
213
|
providerChanged: boolean;
|
|
203
214
|
modelChanged: boolean;
|
|
204
215
|
steps: number;
|
|
@@ -232,28 +243,12 @@ export declare function turns(db: Database, options?: {
|
|
|
232
243
|
filters?: Filters | undefined;
|
|
233
244
|
limit?: number | undefined;
|
|
234
245
|
}): TurnUsage[];
|
|
235
|
-
/**
|
|
236
|
-
* Routing endpoint of the newest step recorded before `at`. The TUI compares
|
|
237
|
-
* it with the endpoint of the turn it is about to render, because the same
|
|
238
|
-
* provider and model can be routed to a different endpoint per request.
|
|
239
|
-
*/
|
|
240
|
-
export declare function routerBefore(db: Database, sessionID: string, at: number | undefined): string | undefined;
|
|
241
|
-
/**
|
|
242
|
-
* Routing endpoint of one turn: the newest endpoint the recorder stored for
|
|
243
|
-
* the given steps of a session. The TUI reads this for the telemetry line
|
|
244
|
-
* because the line renders from the TUI process while the recorder (the server
|
|
245
|
-
* process) is still writing the step that just finished. Scoped to the turn's
|
|
246
|
-
* own steps on purpose: the same provider and model can be routed to a
|
|
247
|
-
* different endpoint per request, so the newest endpoint of the session is not
|
|
248
|
-
* necessarily the one that served the turn being rendered.
|
|
249
|
-
*/
|
|
250
|
-
export declare function routerForSteps(db: Database, sessionID: string, messageIDs: readonly string[]): string | undefined;
|
|
251
246
|
export type FilterOption = {
|
|
252
247
|
value: string;
|
|
253
248
|
steps: number;
|
|
254
249
|
};
|
|
255
|
-
/** Distinct models and
|
|
250
|
+
/** Distinct models and providers, most used first. */
|
|
256
251
|
export declare function filterOptions(db: Database): {
|
|
257
252
|
models: FilterOption[];
|
|
258
|
-
|
|
253
|
+
providers: FilterOption[];
|
|
259
254
|
};
|
package/dist/text.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Text hygiene for everything that reaches a terminal.
|
|
3
3
|
*
|
|
4
|
-
* Some of what the plugin displays is not written by the user: a
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* is stored or drawn.
|
|
4
|
+
* Some of what the plugin displays is not written by the user: a model writes
|
|
5
|
+
* a session title, an NDJSON export can come from anywhere. A control
|
|
6
|
+
* character in any of those is interpreted by the terminal that renders it
|
|
7
|
+
* (title changes, cursor moves, colours), so every such string is stripped of
|
|
8
|
+
* control characters before it is stored or drawn.
|
|
10
9
|
*
|
|
11
10
|
* The rule is deliberately blunt: drop C0 controls, DEL and the C1 block, keep
|
|
12
11
|
* everything else (the text is otherwise arbitrary Unicode), and cap the
|
|
@@ -24,5 +23,3 @@ export declare function sanitizeText(value: string, limit?: number): string;
|
|
|
24
23
|
/** `sanitizeText` without the layout, for a stored label: trimmed as well. */
|
|
25
24
|
export declare function sanitizeLabel(value: string, limit?: number): string;
|
|
26
25
|
export declare function isToken(value: string, limit?: number): boolean;
|
|
27
|
-
/** The lowercase form of a token identity, so the same endpoint groups once. */
|
|
28
|
-
export declare function normalizeToken(value: string, limit?: number): string | undefined;
|
package/dist/tui.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
/** @jsxImportSource @opentui/solid */
|
|
2
2
|
import { Plugin } from "@opencode/plugin/tui";
|
|
3
|
-
import { type LineFields, type
|
|
3
|
+
import { type LineFields, type LineLabels, type TurnStats, type TurnTotalsView } from "./core";
|
|
4
4
|
import { type PanelView, type RangeKey } from "./panel-data";
|
|
5
5
|
/**
|
|
6
6
|
* TUI side of the plugin. Two contributions:
|
|
7
7
|
*
|
|
8
8
|
* - `session.composer.top`: one telemetry line after every turn with the end
|
|
9
|
-
* time, the delta since the previous prompt, the
|
|
10
|
-
* turn and session token totals, and cache warnings.
|
|
9
|
+
* time, the delta since the previous prompt, the provider and model that ran
|
|
10
|
+
* it, turn and session token totals, and cache warnings.
|
|
11
11
|
* - `session.panel` + the `/stats` slash command: the statistics panel over
|
|
12
12
|
* the database written by the server entry.
|
|
13
13
|
*
|
|
14
|
-
* The
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* The line is computed from the host's transcript alone; the database is opened
|
|
15
|
+
* lazily for the panel and the sidebar, read-only in spirit: the TUI never
|
|
16
|
+
* writes usage. When the database cannot be opened, the line still works and
|
|
17
|
+
* the panel explains itself.
|
|
17
18
|
*/
|
|
18
19
|
export type Options = {
|
|
19
20
|
/** Turn the TUI side off: no line and no panel. */
|
|
@@ -21,11 +22,11 @@ export type Options = {
|
|
|
21
22
|
/** SQLite database path override; must match the server entry. */
|
|
22
23
|
db?: string | undefined;
|
|
23
24
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
25
|
+
* List-price estimates for steps the host reports as costing nothing.
|
|
26
|
+
* `off` hides them on the line, in the panel and in the sidebar, and
|
|
27
|
+
* disables the historical backfill. Defaults to `auto`.
|
|
27
28
|
*/
|
|
28
|
-
|
|
29
|
+
pricing?: "auto" | "off" | undefined;
|
|
29
30
|
/**
|
|
30
31
|
* How the turn segment counts prompt usage: `latest` (default) shows the
|
|
31
32
|
* prompt size the turn ended with, `sum` adds every step of the turn.
|