opencode-usage-insights 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rpc.js ADDED
@@ -0,0 +1,294 @@
1
+ // @bun
2
+ // src/rpc.ts
3
+ import { Rpc } from "@opencode/plugin/rpc";
4
+
5
+ // src/limits.ts
6
+ var MAX_PANEL_WIDTH = 200;
7
+ var MAX_TURNS = 50;
8
+ function clampPanelWidth(value) {
9
+ if (!Number.isFinite(value))
10
+ return 20;
11
+ return Math.min(MAX_PANEL_WIDTH, Math.max(20, Math.round(value)));
12
+ }
13
+ function clampTurnsLimit(value) {
14
+ if (!Number.isFinite(value))
15
+ return 1;
16
+ return Math.min(MAX_TURNS, Math.max(1, Math.round(value)));
17
+ }
18
+
19
+ // src/rpc.ts
20
+ var Tone = { type: "string", enum: ["base", "muted", "warning", "accent"] };
21
+ var PanelRowSchema = {
22
+ type: "object",
23
+ properties: {
24
+ kind: { type: "string", enum: ["model", "session", "period", "provider", "turn", "prune", "wipe"] },
25
+ value: { type: "string", maxLength: 500 },
26
+ variant: { type: "string", maxLength: 200 }
27
+ },
28
+ required: ["kind", "value"],
29
+ additionalProperties: false
30
+ };
31
+ var PanelLineSchema = {
32
+ type: "object",
33
+ properties: {
34
+ text: { type: "string" },
35
+ tone: Tone,
36
+ hint: { type: "boolean" },
37
+ row: PanelRowSchema
38
+ },
39
+ required: ["text"],
40
+ additionalProperties: false
41
+ };
42
+ var PanelSettingsSchema = {
43
+ type: "object",
44
+ properties: {
45
+ view: { type: "string", enum: ["overview", "models", "providers", "cache", "periods", "latency", "sessions", "turns", "db"] },
46
+ range: { type: "string", enum: ["session", "today", "7d", "30d", "all"] },
47
+ sort: { type: "string", maxLength: 40 },
48
+ sortDesc: { type: "boolean" },
49
+ granularity: { type: "string", enum: ["day", "week", "month"] },
50
+ turnsScope: { type: "string", enum: ["session", "all"] },
51
+ modelID: { type: "string", maxLength: 300 },
52
+ providerID: { type: "string", maxLength: 300 }
53
+ },
54
+ required: ["view", "range", "sort", "sortDesc", "granularity", "turnsScope", "modelID", "providerID"],
55
+ additionalProperties: false
56
+ };
57
+ var TableSizeSchema = {
58
+ type: "object",
59
+ properties: {
60
+ name: { type: "string" },
61
+ rows: { type: "number" }
62
+ },
63
+ required: ["name", "rows"],
64
+ additionalProperties: false
65
+ };
66
+ var DbInfoSchema = {
67
+ type: "object",
68
+ properties: {
69
+ path: { type: "string" },
70
+ bytes: { type: "number" },
71
+ walBytes: { type: "number" },
72
+ schemaVersion: { type: "number" },
73
+ tables: { type: "array", items: TableSizeSchema },
74
+ firstAt: { type: "number" },
75
+ lastAt: { type: "number" },
76
+ removable: {
77
+ type: "array",
78
+ items: {
79
+ type: "object",
80
+ properties: { days: { type: "number" }, steps: { type: "number" } },
81
+ required: ["days", "steps"],
82
+ additionalProperties: false
83
+ }
84
+ },
85
+ unpriced: { type: "number" }
86
+ },
87
+ required: ["path", "bytes", "schemaVersion", "tables", "removable", "unpriced"],
88
+ additionalProperties: false
89
+ };
90
+ var FilterOptionSchema = {
91
+ type: "object",
92
+ properties: { value: { type: "string" }, steps: { type: "number" } },
93
+ required: ["value", "steps"],
94
+ additionalProperties: false
95
+ };
96
+ var PruneResultSchema = {
97
+ type: "object",
98
+ properties: {
99
+ steps: { type: "number" },
100
+ prompts: { type: "number" },
101
+ events: { type: "number" },
102
+ usage: { type: "number" }
103
+ },
104
+ required: ["steps", "prompts", "events", "usage"],
105
+ additionalProperties: false
106
+ };
107
+ var WipeResultSchema = {
108
+ type: "object",
109
+ properties: {
110
+ steps: { type: "number" },
111
+ prompts: { type: "number" },
112
+ events: { type: "number" },
113
+ usage: { type: "number" },
114
+ sessions: { type: "number" }
115
+ },
116
+ required: ["steps", "prompts", "events", "usage", "sessions"],
117
+ additionalProperties: false
118
+ };
119
+ var BackfillResultSchema = {
120
+ type: "object",
121
+ properties: {
122
+ candidates: { type: "number" },
123
+ updated: { type: "number" }
124
+ },
125
+ required: ["candidates", "updated"],
126
+ additionalProperties: false
127
+ };
128
+ var VacuumResultSchema = {
129
+ type: "object",
130
+ properties: {
131
+ before: { type: "number" },
132
+ after: { type: "number" },
133
+ freed: { type: "number" }
134
+ },
135
+ required: ["before", "after", "freed"],
136
+ additionalProperties: false
137
+ };
138
+ var NoInput = { type: "object", properties: {}, additionalProperties: false };
139
+ var ErrorSchema = {
140
+ type: "object",
141
+ properties: { message: { type: "string", maxLength: 500 } },
142
+ additionalProperties: false
143
+ };
144
+ var errors = {
145
+ busy: ErrorSchema,
146
+ unavailable: ErrorSchema,
147
+ disabled: ErrorSchema,
148
+ invalid: ErrorSchema
149
+ };
150
+ var UsageInsights = Rpc.define({
151
+ id: "usage-insights",
152
+ methods: {
153
+ panel: {
154
+ input: {
155
+ type: "object",
156
+ properties: {
157
+ sessionID: { type: "string", maxLength: 200 },
158
+ settings: PanelSettingsSchema,
159
+ detail: PanelRowSchema,
160
+ width: { type: "number", minimum: 20, maximum: MAX_PANEL_WIDTH },
161
+ busy: { type: "boolean" }
162
+ },
163
+ required: ["sessionID", "settings", "width"],
164
+ additionalProperties: false
165
+ },
166
+ output: {
167
+ type: "object",
168
+ properties: {
169
+ lines: { type: "array", items: PanelLineSchema },
170
+ database: DbInfoSchema
171
+ },
172
+ required: ["lines"],
173
+ additionalProperties: false
174
+ },
175
+ errors
176
+ },
177
+ turns: {
178
+ input: {
179
+ type: "object",
180
+ properties: {
181
+ sessionID: { type: "string", maxLength: 200 },
182
+ limit: { type: "number", minimum: 1, maximum: MAX_TURNS },
183
+ width: { type: "number", minimum: 20, maximum: 120 }
184
+ },
185
+ required: ["sessionID", "limit", "width"],
186
+ additionalProperties: false
187
+ },
188
+ output: {
189
+ type: "object",
190
+ properties: {
191
+ summary: { type: "array", items: PanelLineSchema },
192
+ history: { type: "array", items: PanelLineSchema }
193
+ },
194
+ required: ["summary", "history"],
195
+ additionalProperties: false
196
+ },
197
+ errors
198
+ },
199
+ listCost: {
200
+ input: {
201
+ type: "object",
202
+ properties: { sessionID: { type: "string", maxLength: 200 } },
203
+ required: ["sessionID"],
204
+ additionalProperties: false
205
+ },
206
+ output: {
207
+ type: "object",
208
+ properties: { cost: { type: "number" } },
209
+ required: ["cost"],
210
+ additionalProperties: false
211
+ },
212
+ errors
213
+ },
214
+ filters: {
215
+ input: NoInput,
216
+ output: {
217
+ type: "object",
218
+ properties: {
219
+ models: { type: "array", items: FilterOptionSchema },
220
+ providers: { type: "array", items: FilterOptionSchema }
221
+ },
222
+ required: ["models", "providers"],
223
+ additionalProperties: false
224
+ },
225
+ errors
226
+ },
227
+ dbInfo: {
228
+ input: NoInput,
229
+ output: DbInfoSchema,
230
+ errors
231
+ },
232
+ prune: {
233
+ input: {
234
+ type: "object",
235
+ properties: {
236
+ days: { type: "number", minimum: 1, maximum: 3650 },
237
+ confirm: { type: "boolean", enum: [true] }
238
+ },
239
+ required: ["days", "confirm"],
240
+ additionalProperties: false
241
+ },
242
+ output: PruneResultSchema,
243
+ errors
244
+ },
245
+ wipe: {
246
+ input: {
247
+ type: "object",
248
+ properties: { confirm: { type: "boolean", enum: [true] } },
249
+ required: ["confirm"],
250
+ additionalProperties: false
251
+ },
252
+ output: WipeResultSchema,
253
+ errors
254
+ },
255
+ vacuum: {
256
+ input: {
257
+ type: "object",
258
+ properties: { confirm: { type: "boolean", enum: [true] } },
259
+ required: ["confirm"],
260
+ additionalProperties: false
261
+ },
262
+ output: VacuumResultSchema,
263
+ errors
264
+ },
265
+ backfill: {
266
+ input: {
267
+ type: "object",
268
+ properties: { confirm: { type: "boolean", enum: [true] } },
269
+ required: ["confirm"],
270
+ additionalProperties: false
271
+ },
272
+ output: BackfillResultSchema,
273
+ errors
274
+ }
275
+ },
276
+ events: {
277
+ recorded: {
278
+ schema: {
279
+ type: "object",
280
+ properties: {
281
+ sessionID: { type: "string", maxLength: 200 },
282
+ at: { type: "number" }
283
+ },
284
+ required: ["at"],
285
+ additionalProperties: false
286
+ }
287
+ }
288
+ }
289
+ });
290
+ export {
291
+ UsageInsights
292
+ };
293
+
294
+ //# debugId=6C681C5E17FF4D6764756E2164756E21
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/rpc.ts", "../src/limits.ts"],
4
+ "sourcesContent": [
5
+ "import { Rpc } from \"@opencode/plugin/rpc\"\nimport { MAX_PANEL_WIDTH, MAX_TURNS } from \"./limits\"\nimport type { LineFormatOptions, PanelLine, PanelRow, PanelSettings } from \"./panel-data\"\nimport type { BackfillResult, DbInfo, PruneResult } from \"./stats/maintenance\"\nimport type { FilterOption } from \"./stats/queries\"\n\n/**\n * The usage-insights RPC contract. One definition is served by the server\n * part and consumed by the TUI and the desktop GUI, so both clients read the\n * same database through the same validated surface.\n *\n * JSON Schema keeps the contract portable: the server does not need a newer\n * `effect` runtime, and a client can be a TUI, an Electron window or a plain\n * HTTP client. TypeScript types are declared next to the schemas and are the\n * only thing imported with `import type`; the schemas are the runtime truth.\n */\n\nexport type PanelInput = {\n sessionID: string\n settings: PanelSettings\n detail?: PanelRow | undefined\n width: number\n busy?: boolean | undefined\n}\n\nexport type PanelOutput = {\n lines: PanelLine[]\n database?: DbInfo | undefined\n}\n\nexport type TurnsInput = {\n sessionID: string\n limit: number\n width: number\n}\n\nexport type TurnsOutput = {\n summary: PanelLine[]\n history: PanelLine[]\n}\n\nexport type ListCostInput = {\n sessionID: string\n}\n\nexport type ListCostOutput = {\n cost: number\n}\n\nexport type FiltersOutput = {\n models: FilterOption[]\n providers: FilterOption[]\n}\n\nexport type PruneInput = {\n days: number\n confirm: true\n}\n\nexport type WipeInput = {\n confirm: true\n}\n\nexport type VacuumInput = {\n confirm: true\n}\n\nexport type BackfillInput = {\n confirm: true\n}\n\nexport type VacuumOutput = {\n before: number\n after: number\n freed: number\n}\n\nexport type RecordedEvent = {\n sessionID?: string | undefined\n at: number\n}\n\nexport type UsageFormat = LineFormatOptions\n\nconst Tone = { type: \"string\", enum: [\"base\", \"muted\", \"warning\", \"accent\"] } as const\n\nconst PanelRowSchema = {\n type: \"object\",\n properties: {\n kind: { type: \"string\", enum: [\"model\", \"session\", \"period\", \"provider\", \"turn\", \"prune\", \"wipe\"] },\n value: { type: \"string\", maxLength: 500 },\n variant: { type: \"string\", maxLength: 200 },\n },\n required: [\"kind\", \"value\"],\n additionalProperties: false,\n} as const\n\nconst PanelLineSchema = {\n type: \"object\",\n properties: {\n text: { type: \"string\" },\n tone: Tone,\n hint: { type: \"boolean\" },\n row: PanelRowSchema,\n },\n required: [\"text\"],\n additionalProperties: false,\n} as const\n\nconst PanelSettingsSchema = {\n type: \"object\",\n properties: {\n view: { type: \"string\", enum: [\"overview\", \"models\", \"providers\", \"cache\", \"periods\", \"latency\", \"sessions\", \"turns\", \"db\"] },\n range: { type: \"string\", enum: [\"session\", \"today\", \"7d\", \"30d\", \"all\"] },\n sort: { type: \"string\", maxLength: 40 },\n sortDesc: { type: \"boolean\" },\n granularity: { type: \"string\", enum: [\"day\", \"week\", \"month\"] },\n turnsScope: { type: \"string\", enum: [\"session\", \"all\"] },\n modelID: { type: \"string\", maxLength: 300 },\n providerID: { type: \"string\", maxLength: 300 },\n },\n required: [\"view\", \"range\", \"sort\", \"sortDesc\", \"granularity\", \"turnsScope\", \"modelID\", \"providerID\"],\n additionalProperties: false,\n} as const\n\nconst TableSizeSchema = {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n rows: { type: \"number\" },\n },\n required: [\"name\", \"rows\"],\n additionalProperties: false,\n} as const\n\nconst DbInfoSchema = {\n type: \"object\",\n properties: {\n path: { type: \"string\" },\n bytes: { type: \"number\" },\n walBytes: { type: \"number\" },\n schemaVersion: { type: \"number\" },\n tables: { type: \"array\", items: TableSizeSchema },\n firstAt: { type: \"number\" },\n lastAt: { type: \"number\" },\n removable: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: { days: { type: \"number\" }, steps: { type: \"number\" } },\n required: [\"days\", \"steps\"],\n additionalProperties: false,\n },\n },\n unpriced: { type: \"number\" },\n },\n required: [\"path\", \"bytes\", \"schemaVersion\", \"tables\", \"removable\", \"unpriced\"],\n additionalProperties: false,\n} as const\n\nconst FilterOptionSchema = {\n type: \"object\",\n properties: { value: { type: \"string\" }, steps: { type: \"number\" } },\n required: [\"value\", \"steps\"],\n additionalProperties: false,\n} as const\n\nconst PruneResultSchema = {\n type: \"object\",\n properties: {\n steps: { type: \"number\" },\n prompts: { type: \"number\" },\n events: { type: \"number\" },\n usage: { type: \"number\" },\n },\n required: [\"steps\", \"prompts\", \"events\", \"usage\"],\n additionalProperties: false,\n} as const\n\nconst WipeResultSchema = {\n type: \"object\",\n properties: {\n steps: { type: \"number\" },\n prompts: { type: \"number\" },\n events: { type: \"number\" },\n usage: { type: \"number\" },\n sessions: { type: \"number\" },\n },\n required: [\"steps\", \"prompts\", \"events\", \"usage\", \"sessions\"],\n additionalProperties: false,\n} as const\n\nconst BackfillResultSchema = {\n type: \"object\",\n properties: {\n candidates: { type: \"number\" },\n updated: { type: \"number\" },\n },\n required: [\"candidates\", \"updated\"],\n additionalProperties: false,\n} as const\n\nconst VacuumResultSchema = {\n type: \"object\",\n properties: {\n before: { type: \"number\" },\n after: { type: \"number\" },\n freed: { type: \"number\" },\n },\n required: [\"before\", \"after\", \"freed\"],\n additionalProperties: false,\n} as const\n\nconst NoInput = { type: \"object\", properties: {}, additionalProperties: false } as const\n\nconst ErrorSchema = {\n type: \"object\",\n properties: { message: { type: \"string\", maxLength: 500 } },\n additionalProperties: false,\n} as const\n\nconst errors = {\n busy: ErrorSchema,\n unavailable: ErrorSchema,\n disabled: ErrorSchema,\n invalid: ErrorSchema,\n} as const\n\nexport const UsageInsights = Rpc.define({\n id: \"usage-insights\",\n methods: {\n panel: {\n input: {\n type: \"object\",\n properties: {\n sessionID: { type: \"string\", maxLength: 200 },\n settings: PanelSettingsSchema,\n detail: PanelRowSchema,\n width: { type: \"number\", minimum: 20, maximum: MAX_PANEL_WIDTH },\n busy: { type: \"boolean\" },\n },\n required: [\"sessionID\", \"settings\", \"width\"],\n additionalProperties: false,\n },\n output: {\n type: \"object\",\n properties: {\n lines: { type: \"array\", items: PanelLineSchema },\n database: DbInfoSchema,\n },\n required: [\"lines\"],\n additionalProperties: false,\n },\n errors,\n },\n turns: {\n input: {\n type: \"object\",\n properties: {\n sessionID: { type: \"string\", maxLength: 200 },\n limit: { type: \"number\", minimum: 1, maximum: MAX_TURNS },\n width: { type: \"number\", minimum: 20, maximum: 120 },\n },\n required: [\"sessionID\", \"limit\", \"width\"],\n additionalProperties: false,\n },\n output: {\n type: \"object\",\n properties: {\n summary: { type: \"array\", items: PanelLineSchema },\n history: { type: \"array\", items: PanelLineSchema },\n },\n required: [\"summary\", \"history\"],\n additionalProperties: false,\n },\n errors,\n },\n listCost: {\n input: {\n type: \"object\",\n properties: { sessionID: { type: \"string\", maxLength: 200 } },\n required: [\"sessionID\"],\n additionalProperties: false,\n },\n output: {\n type: \"object\",\n properties: { cost: { type: \"number\" } },\n required: [\"cost\"],\n additionalProperties: false,\n },\n errors,\n },\n filters: {\n input: NoInput,\n output: {\n type: \"object\",\n properties: {\n models: { type: \"array\", items: FilterOptionSchema },\n providers: { type: \"array\", items: FilterOptionSchema },\n },\n required: [\"models\", \"providers\"],\n additionalProperties: false,\n },\n errors,\n },\n dbInfo: {\n input: NoInput,\n output: DbInfoSchema,\n errors,\n },\n prune: {\n input: {\n type: \"object\",\n properties: {\n days: { type: \"number\", minimum: 1, maximum: 3650 },\n confirm: { type: \"boolean\", enum: [true] },\n },\n required: [\"days\", \"confirm\"],\n additionalProperties: false,\n },\n output: PruneResultSchema,\n errors,\n },\n wipe: {\n input: {\n type: \"object\",\n properties: { confirm: { type: \"boolean\", enum: [true] } },\n required: [\"confirm\"],\n additionalProperties: false,\n },\n output: WipeResultSchema,\n errors,\n },\n vacuum: {\n input: {\n type: \"object\",\n properties: { confirm: { type: \"boolean\", enum: [true] } },\n required: [\"confirm\"],\n additionalProperties: false,\n },\n output: VacuumResultSchema,\n errors,\n },\n backfill: {\n input: {\n type: \"object\",\n properties: { confirm: { type: \"boolean\", enum: [true] } },\n required: [\"confirm\"],\n additionalProperties: false,\n },\n output: BackfillResultSchema,\n errors,\n },\n },\n events: {\n recorded: {\n schema: {\n type: \"object\",\n properties: {\n sessionID: { type: \"string\", maxLength: 200 },\n at: { type: \"number\" },\n },\n required: [\"at\"],\n additionalProperties: false,\n },\n },\n },\n})\n",
6
+ "/**\n * Shared request bounds.\n *\n * The RPC schemas, the clients and the service use the same numbers: a client\n * must clamp before it calls the RPC, because schema validation runs before the\n * service can clamp. These constants keep the three layers from drifting.\n */\n\n/** Widest panel the server formats. */\nexport const MAX_PANEL_WIDTH = 200\n\n/** Most turns the server returns for a history request. */\nexport const MAX_TURNS = 50\n\n/** A finite width within the panel bounds. */\nexport function clampPanelWidth(value: number): number {\n if (!Number.isFinite(value)) return 20\n return Math.min(MAX_PANEL_WIDTH, Math.max(20, Math.round(value)))\n}\n\n/** A finite turn limit within the history bounds. */\nexport function clampTurnsLimit(value: number): number {\n if (!Number.isFinite(value)) return 1\n return Math.min(MAX_TURNS, Math.max(1, Math.round(value)))\n}\n"
7
+ ],
8
+ "mappings": ";;AAAA;;;ACSO,IAAM,kBAAkB;AAGxB,IAAM,YAAY;AAGlB,SAAS,eAAe,CAAC,OAAuB;AAAA,EACrD,IAAI,CAAC,OAAO,SAAS,KAAK;AAAA,IAAG,OAAO;AAAA,EACpC,OAAO,KAAK,IAAI,iBAAiB,KAAK,IAAI,IAAI,KAAK,MAAM,KAAK,CAAC,CAAC;AAAA;AAI3D,SAAS,eAAe,CAAC,OAAuB;AAAA,EACrD,IAAI,CAAC,OAAO,SAAS,KAAK;AAAA,IAAG,OAAO;AAAA,EACpC,OAAO,KAAK,IAAI,WAAW,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC,CAAC;AAAA;;;AD6D3D,IAAM,OAAO,EAAE,MAAM,UAAU,MAAM,CAAC,QAAQ,SAAS,WAAW,QAAQ,EAAE;AAE5E,IAAM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MAAM;AAAA,QACN,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,MAAM,CAAC,IAAI,EAAE,EAAE;AAAA,QACzD,UAAU,CAAC,SAAS;AAAA,QACpB,sBAAsB;AAAA,MACxB;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,IACF;AAAA,IACA,UAAU;AAAA,MACR,OAAO;AAAA,QACL,MAAM;AAAA,QACN,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,MAAM,CAAC,IAAI,EAAE,EAAE;AAAA,QACzD,UAAU,CAAC,SAAS;AAAA,QACpB,sBAAsB;AAAA,MACxB;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EACA,QAAQ;AAAA,IACN,UAAU;AAAA,MACR,QAAQ;AAAA,QACN,MAAM;AAAA,QACN,YAAY;AAAA,UACV,WAAW,EAAE,MAAM,UAAU,WAAW,IAAI;AAAA,UAC5C,IAAI,EAAE,MAAM,SAAS;AAAA,QACvB;AAAA,QACA,UAAU,CAAC,IAAI;AAAA,QACf,sBAAsB;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AACF,CAAC;",
9
+ "debugId": "6C681C5E17FF4D6764756E2164756E21",
10
+ "names": []
11
+ }
@@ -0,0 +1,36 @@
1
+ import type { Database } from "bun:sqlite";
2
+ import { type LineFormatOptions } from "./panel-data";
3
+ import { type PriceTable } from "./pricing";
4
+ import { type BackfillResult, type DbInfo, type PruneResult, type WipeResult } from "./stats/maintenance";
5
+ import type { BackfillInput, FiltersOutput, ListCostInput, ListCostOutput, PanelInput, PanelOutput, PruneInput, TurnsInput, TurnsOutput, VacuumInput, VacuumOutput, WipeInput } from "./rpc";
6
+ export type ServiceErrorCode = "busy" | "unavailable" | "disabled" | "invalid";
7
+ export declare class ServiceError extends Error {
8
+ readonly code: ServiceErrorCode;
9
+ constructor(code: ServiceErrorCode, message: string);
10
+ }
11
+ export type ServiceOptions = {
12
+ /** Database file path, for maintenance and for the `db` view. */
13
+ path: string;
14
+ /** `false` hides list-price estimates and disables the backfill. */
15
+ pricing: boolean;
16
+ /** `false` exposes read methods only. */
17
+ maintenance: boolean;
18
+ /** `false` returns a redacted path instead of the absolute one. */
19
+ exposePaths: boolean;
20
+ /** Formatting options shared by the panel and the turn history. */
21
+ format: LineFormatOptions;
22
+ /** Server-side catalog for the historical backfill. */
23
+ priceTable?: (() => PriceTable | undefined) | undefined;
24
+ };
25
+ export type Service = ReturnType<typeof createService>;
26
+ export declare function createService(db: () => Database, options: ServiceOptions): {
27
+ panel: (input: PanelInput) => PanelOutput;
28
+ turnHistory: (input: TurnsInput) => TurnsOutput;
29
+ listCost: (input: ListCostInput) => ListCostOutput;
30
+ filters: () => FiltersOutput;
31
+ dbInfo: () => DbInfo;
32
+ prune: (input: PruneInput) => PruneResult;
33
+ wipe: (input: WipeInput) => WipeResult;
34
+ compact: (input: VacuumInput) => VacuumOutput;
35
+ backfill: (input: BackfillInput, table?: PriceTable | undefined) => BackfillResult;
36
+ };
package/dist/sidebar.d.ts CHANGED
@@ -1,15 +1,11 @@
1
- /** @jsxImportSource @opentui/solid */
2
- import type { Database } from "bun:sqlite";
3
1
  import type { Context } from "@opencode/plugin/tui/context";
4
- import { type LineFormatOptions } from "./panel-data";
5
2
  /**
6
3
  * Sidebar history: the session's accumulated usage, then the last finished
7
4
  * turns — when and through which provider, the model when it changed, and the
8
- * prompt volumes. Reads the same database, the same buckets and the same
9
- * formatter as the panel and the live line, and refreshes whenever a turn ends.
5
+ * prompt volumes. The lines are formatted by the server's RPC from the same
6
+ * database the panel uses; the sidebar only renders them.
10
7
  */
11
8
  export type TurnsSidebarDeps = {
12
- db: () => Database | undefined;
13
9
  /** Bumped by the TUI when a step or an execution ends. */
14
10
  refresh: () => number;
15
11
  /** How many turns to show. */
@@ -21,5 +17,4 @@ export declare function TurnsSidebar(props: {
21
17
  readonly sessionID: string;
22
18
  readonly ctx: Context;
23
19
  readonly deps: TurnsSidebarDeps;
24
- readonly options?: LineFormatOptions | undefined;
25
20
  }): any;
@@ -19,7 +19,7 @@
19
19
  * `test/reports.test.ts` holds every report to those rules.
20
20
  */
21
21
  import type { Database } from "bun:sqlite";
22
- import { type Filters, type LatencyStats, type Range, type Usage } from "./queries";
22
+ import { type Filters, type LatencyStats, type OtherUsageRow, type Range, type Usage } from "./queries";
23
23
  /** The step's own clock, the expression the `steps_at` index covers. */
24
24
  export declare const STEP_AT = "COALESCE(created_at, recorded_at)";
25
25
  type Options = {
@@ -266,6 +266,8 @@ export type PeriodRow = {
266
266
  sessions: number;
267
267
  usage: Usage;
268
268
  cache: CacheStats;
269
+ /** Compaction/title money included in `usage.cost`, when the period has any. */
270
+ otherCost?: number | undefined;
269
271
  };
270
272
  /** ISO-8601 week number and its Monday, in local time. */
271
273
  export declare function isoWeek(date: Date): {
@@ -273,12 +275,20 @@ export declare function isoWeek(date: Date): {
273
275
  week: number;
274
276
  monday: Date;
275
277
  };
278
+ /** Local end (exclusive) of the period that starts at `at`. */
279
+ export declare function periodEnd(at: number, granularity: PeriodGranularity): number;
276
280
  /** Key, label and local start of the period `at` falls in. */
277
281
  export declare function periodStart(at: number, granularity: PeriodGranularity): {
278
282
  key: string;
279
283
  label: string;
280
284
  start: number;
281
285
  };
282
- /** Totals per local calendar day, week or month, oldest first. */
283
- export declare function periodsOf(rows: readonly StepRow[], granularity: PeriodGranularity): PeriodRow[];
286
+ /**
287
+ * Totals per local calendar day, week or month, oldest first.
288
+ *
289
+ * `otherRows` are the host's non-step usage records (compaction and title
290
+ * generations). Their cost is added to the bucket they fall in, because the
291
+ * session's own total includes it; the token buckets stay step-based.
292
+ */
293
+ export declare function periodsOf(rows: readonly StepRow[], granularity: PeriodGranularity, otherRows?: readonly OtherUsageRow[]): PeriodRow[];
284
294
  export {};
@@ -11,12 +11,12 @@ import { Database } from "bun:sqlite";
11
11
  * - `openStatsDb` writes: schema, migrations and recording (the server).
12
12
  * - `openStatsDbReadOnly` only reads (the TUI), so no view can change the file
13
13
  * and no reader pays for a schema write.
14
- * - `openStatsDbWrite` is a short-lived maintenance connection (prune, vacuum)
14
+ * - `openStatsDbWrite` is a short-lived maintenance connection (prune, wipe, vacuum)
15
15
  * that gives up quickly instead of holding the recorder up.
16
16
  */
17
- export declare const SCHEMA_VERSION = 10;
17
+ export declare const SCHEMA_VERSION = 11;
18
18
  /** Tables carried by `exportNdjson` / `importNdjson`, in import-safe order. */
19
- export declare const TABLES: readonly ["sessions", "prompts", "events", "steps"];
19
+ export declare const TABLES: readonly ["sessions", "prompts", "events", "steps", "usage"];
20
20
  export type TableName = (typeof TABLES)[number];
21
21
  export type StepRecord = {
22
22
  messageID: string;
@@ -57,6 +57,23 @@ export type EventRecord = {
57
57
  at?: number | undefined;
58
58
  data?: unknown;
59
59
  };
60
+ /**
61
+ * Usage with no assistant step behind it (a compaction or a title generation).
62
+ * `id` is the host event ID: it is the primary key, so a replay is ignored
63
+ * instead of counted again.
64
+ */
65
+ export type UsageRecord = {
66
+ id: string;
67
+ sessionID: string;
68
+ source: string;
69
+ at?: number | undefined;
70
+ cost?: number | undefined;
71
+ input?: number | undefined;
72
+ output?: number | undefined;
73
+ reasoning?: number | undefined;
74
+ cacheRead?: number | undefined;
75
+ cacheWrite?: number | undefined;
76
+ };
60
77
  export type SessionRecord = {
61
78
  sessionID: string;
62
79
  parentID?: string | undefined;
@@ -75,7 +92,7 @@ export declare function openStatsDb(path: string): Database;
75
92
  export declare function openStatsDbReadOnly(path: string): Database;
76
93
  /**
77
94
  * Short-lived write connection for maintenance. The busy timeout is short on
78
- * purpose: a prune or a vacuum that cannot take the lock must fail in front of
95
+ * purpose: a prune, wipe or vacuum that cannot take the lock must fail in front of
79
96
  * the user, not hold the recorder's response path for seconds.
80
97
  */
81
98
  export declare function openStatsDbWrite(path: string): Database;
@@ -92,6 +109,12 @@ export declare function openStatsDbWrite(path: string): Database;
92
109
  * absent instead of becoming a grouping key.
93
110
  */
94
111
  export declare function recordStep(db: Database, record: StepRecord): void;
112
+ /**
113
+ * Insert usage that has no assistant step of its own. The host event ID is the
114
+ * primary key: a replayed event is ignored, so the totals never double count a
115
+ * compaction or a title generation delivered more than once.
116
+ */
117
+ export declare function recordUsage(db: Database, record: UsageRecord): void;
95
118
  export declare function recordPrompt(db: Database, record: PromptRecord): void;
96
119
  export declare function recordEvent(db: Database, record: EventRecord): void;
97
120
  export declare function upsertSession(db: Database, record: SessionRecord): void;
@@ -36,6 +36,12 @@ export type PruneResult = {
36
36
  steps: number;
37
37
  prompts: number;
38
38
  events: number;
39
+ /** Compaction/title usage records deleted with the steps they belong to. */
40
+ usage: number;
41
+ };
42
+ export type WipeResult = PruneResult & {
43
+ /** Session headings, which a wipe removes with the history they describe. */
44
+ sessions: number;
39
45
  };
40
46
  /**
41
47
  * Delete recorded usage older than `cutoff`. Steps, their prompts and the
@@ -43,6 +49,12 @@ export type PruneResult = {
43
49
  * that no step references answers nothing.
44
50
  */
45
51
  export declare function pruneOlderThan(db: Database, cutoff: number): PruneResult;
52
+ /**
53
+ * Delete every recorded row, keeping only the schema metadata. Sessions go
54
+ * with the history they describe: a session with no step is a heading no view
55
+ * can explain. Batched like a prune, so the recorder can interleave.
56
+ */
57
+ export declare function wipeAll(db: Database): WipeResult;
46
58
  /** Reclaim the space a prune freed. Returns the bytes the database lost. */
47
59
  export declare function vacuum(db: Database, path: string): {
48
60
  before: number;
@@ -69,6 +69,31 @@ export declare function hasEstimate(usage: Pick<Usage, "listCost">): boolean;
69
69
  * estimate (or a database without the column) answers 0.
70
70
  */
71
71
  export declare function sessionListCost(db: Database, sessionID: string): number;
72
+ /**
73
+ * Money the host reported with no assistant step behind it: a compaction
74
+ * summary or a generated title. It is part of the session's own cost, so the
75
+ * totals that claim to describe a session include it.
76
+ */
77
+ export type OtherUsage = {
78
+ /** Host usage records behind the number. */
79
+ entries: number;
80
+ cost: number;
81
+ };
82
+ export declare const EMPTY_OTHER: OtherUsage;
83
+ /** Non-step usage in the selection. */
84
+ export declare function otherUsage(db: Database, range?: Range | undefined, filters?: Filters | undefined): OtherUsage;
85
+ /** Non-step usage per session, for the session rows. */
86
+ export declare function otherUsageBySession(db: Database, range?: Range | undefined, filters?: Filters | undefined): Map<string, OtherUsage>;
87
+ export type OtherUsageRow = {
88
+ sessionID: string;
89
+ at: number;
90
+ cost: number;
91
+ };
92
+ /**
93
+ * Non-step usage as one row per host record, so calendar buckets can fold it
94
+ * into their periods with the same local-time rule the steps use.
95
+ */
96
+ export declare function otherUsageRows(db: Database, range?: Range | undefined, filters?: Filters | undefined): OtherUsageRow[];
72
97
  export declare const STEP_TIME = "COALESCE(created_at, recorded_at)";
73
98
  /**
74
99
  * The identity of a model *and* its variant, in SQL: `modelKey` says a variant
@@ -96,6 +121,8 @@ export declare function cacheHitRatio(usage: Pick<Usage, "input" | "cached" | "c
96
121
  export type Overview = Usage & {
97
122
  sessions: number;
98
123
  prompts: number;
124
+ /** Compaction/title money included in `cost`, when the range has any. */
125
+ otherCost?: number | undefined;
99
126
  firstAt: number | undefined;
100
127
  lastAt: number | undefined;
101
128
  cacheHitRatio: number | undefined;
@@ -176,6 +203,8 @@ export type SessionUsage = Usage & {
176
203
  providers: string[];
177
204
  models: string[];
178
205
  prompts: number;
206
+ /** Compaction/title money included in `cost`, when the session has any. */
207
+ otherCost?: number | undefined;
179
208
  firstAt: number | undefined;
180
209
  lastAt: number | undefined;
181
210
  cacheHitRatio: number | undefined;
@@ -205,7 +234,13 @@ export type TurnUsage = {
205
234
  /** Creation time of the prompt that opened the turn, when it was recorded. */
206
235
  promptAt: number | undefined;
207
236
  endAt: number | undefined;
208
- /** Time between the previous prompt of the session and this turn's prompt. */
237
+ /**
238
+ * Wall time of the turn's execution: the first step's request to the last
239
+ * step's completion. Tool-call gaps inside the turn are included; time spent
240
+ * queued before the first request is not.
241
+ */
242
+ durationMs: number | undefined;
243
+ /** Time between the previous finished turn's prompt and this turn's prompt. */
209
244
  promptGapMs: number | undefined;
210
245
  providerID: string | undefined;
211
246
  modelID: string | undefined;
@@ -232,10 +267,11 @@ export type TurnUsage = {
232
267
  * before them; a turn whose last step asked for tools is dropped, because it is
233
268
  * still running — the same rule the telemetry line follows.
234
269
  *
235
- * For one session the read is bounded by a window: only the steps at or after
236
- * the `limit`-th newest prompt are loaded, so a session with tens of thousands
237
- * of steps costs the same as a short one. The extra prompt is kept as the
238
- * reference the oldest returned turn measures its gap against.
270
+ * For one session the read is bounded by a window of the newest prompts. The
271
+ * window grows until it holds `limit` finished turns: a prompt can be empty
272
+ * (the host records a synthetic system-reminder next to the user prompt) and
273
+ * the newest turn can still be running, so a fixed one-prompt margin is not
274
+ * enough. `complete` means the window covers every prompt of the session.
239
275
  */
240
276
  export declare function turns(db: Database, options?: {
241
277
  sessionID?: string | undefined;