opencode-usage-insights 0.1.3 → 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;
@@ -11,7 +11,7 @@ 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
17
  export declare const SCHEMA_VERSION = 11;
@@ -92,7 +92,7 @@ export declare function openStatsDb(path: string): Database;
92
92
  export declare function openStatsDbReadOnly(path: string): Database;
93
93
  /**
94
94
  * Short-lived write connection for maintenance. The busy timeout is short on
95
- * 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
96
96
  * the user, not hold the recorder's response path for seconds.
97
97
  */
98
98
  export declare function openStatsDbWrite(path: string): Database;
@@ -39,12 +39,22 @@ export type PruneResult = {
39
39
  /** Compaction/title usage records deleted with the steps they belong to. */
40
40
  usage: number;
41
41
  };
42
+ export type WipeResult = PruneResult & {
43
+ /** Session headings, which a wipe removes with the history they describe. */
44
+ sessions: number;
45
+ };
42
46
  /**
43
47
  * Delete recorded usage older than `cutoff`. Steps, their prompts and the
44
48
  * compaction events that explain their cache losses go together: a compaction
45
49
  * that no step references answers nothing.
46
50
  */
47
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;
48
58
  /** Reclaim the space a prune freed. Returns the bytes the database lost. */
49
59
  export declare function vacuum(db: Database, path: string): {
50
60
  before: number;
@@ -234,6 +234,12 @@ export type TurnUsage = {
234
234
  /** Creation time of the prompt that opened the turn, when it was recorded. */
235
235
  promptAt: number | undefined;
236
236
  endAt: number | undefined;
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;
237
243
  /** Time between the previous finished turn's prompt and this turn's prompt. */
238
244
  promptGapMs: number | undefined;
239
245
  providerID: string | undefined;
@@ -0,0 +1,65 @@
1
+ import type { Service, ServiceErrorCode, ServiceOptions } from "./service";
2
+ import type { PriceTable } from "./pricing";
3
+ /**
4
+ * Server-side client for the database worker. It starts the worker lazily,
5
+ * keeps a bounded queue in front of it, and falls back to an in-process
6
+ * service when a worker cannot start (development, unsupported runtime).
7
+ *
8
+ * The worker runs every panel query off the server's event loop. A request
9
+ * that hangs is terminated with the worker and reported as `unavailable`; the
10
+ * next request starts a fresh one.
11
+ */
12
+ export type StatsErrorCode = ServiceErrorCode;
13
+ export declare class StatsError extends Error {
14
+ readonly code: StatsErrorCode;
15
+ constructor(code: StatsErrorCode, message: string);
16
+ }
17
+ export type StatsMethod = "panel" | "turns" | "listCost" | "filters" | "dbInfo" | "prune" | "wipe" | "vacuum" | "backfill";
18
+ export type StatsClientOptions = {
19
+ /** Absolute database path, resolved by the server plugin. */
20
+ dbPath: string;
21
+ /** Options passed to the worker's service. */
22
+ options: Omit<ServiceOptions, "path" | "priceTable">;
23
+ /** Current server catalog for a backfill. */
24
+ priceTable?: (() => PriceTable | undefined) | undefined;
25
+ /** In-process service used when the worker cannot start. */
26
+ fallback: () => Service;
27
+ /** Worker entrypoint override, for tests. */
28
+ workerUrl?: (() => URL | undefined) | undefined;
29
+ /** Timeout overrides, for tests. */
30
+ timeouts?: {
31
+ read?: number;
32
+ maintenance?: number;
33
+ start?: number;
34
+ } | undefined;
35
+ /** Diagnostics sink. */
36
+ log?: ((message: string) => void) | undefined;
37
+ };
38
+ export declare class StatsClient {
39
+ private readonly config;
40
+ private worker;
41
+ private startPromise;
42
+ private starting;
43
+ private startAbort;
44
+ private fallbackService;
45
+ private fallbackMode;
46
+ private stopped;
47
+ private nextID;
48
+ private readonly pending;
49
+ constructor(config: StatsClientOptions);
50
+ /** A request with no caller-side cancellation. */
51
+ request<T>(method: StatsMethod, input: unknown, options?: {
52
+ signal?: AbortSignal | undefined;
53
+ }): Promise<T>;
54
+ stop(): void;
55
+ private callService;
56
+ private ensureWorker;
57
+ private attach;
58
+ private receive;
59
+ private timeoutFor;
60
+ private send;
61
+ private settle;
62
+ private rejectAll;
63
+ private hardReset;
64
+ private useFallback;
65
+ }
@@ -0,0 +1 @@
1
+ export {};