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.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Shared request bounds.
3
+ *
4
+ * The RPC schemas, the clients and the service use the same numbers: a client
5
+ * must clamp before it calls the RPC, because schema validation runs before the
6
+ * service can clamp. These constants keep the three layers from drifting.
7
+ */
8
+ /** Widest panel the server formats. */
9
+ export declare const MAX_PANEL_WIDTH = 200;
10
+ /** Most turns the server returns for a history request. */
11
+ export declare const MAX_TURNS = 50;
12
+ /** A finite width within the panel bounds. */
13
+ export declare function clampPanelWidth(value: number): number;
14
+ /** A finite turn limit within the history bounds. */
15
+ export declare function clampTurnsLimit(value: number): number;
@@ -35,10 +35,6 @@ export type PanelRequest = {
35
35
  width: number;
36
36
  };
37
37
  /** Sorting options per view; the first is the default. */
38
- export declare const SORT_KEYS: Partial<Record<PanelView, readonly string[]>>;
39
- export declare function sortKeys(view: PanelView): readonly string[];
40
- export declare function defaultSort(view: PanelView): string;
41
- export declare function nextSort(view: PanelView, current: string, step: number): string;
42
38
  export declare function detailLabel(row: PanelRow): string;
43
39
  /** Build the panel lines for the request. Never throws: a failure is a line. */
44
40
  export declare function buildPanel(request: PanelRequest): PanelLine[];
@@ -18,7 +18,7 @@ export type Granularity = (typeof GRANULARITIES)[number];
18
18
  export type PanelTone = "base" | "muted" | "warning" | "accent";
19
19
  /** What a selectable line stands for; Enter drills into it. */
20
20
  export type PanelRow = {
21
- kind: "model" | "session" | "period" | "provider" | "turn" | "prune";
21
+ kind: "model" | "session" | "period" | "provider" | "turn" | "prune" | "wipe";
22
22
  value: string;
23
23
  variant?: string | undefined;
24
24
  };
@@ -26,7 +26,14 @@ export type PanelLine = {
26
26
  text: string;
27
27
  tone?: PanelTone;
28
28
  row?: PanelRow | undefined;
29
+ /** TUI-only key hint; the desktop GUI filters these lines out. */
30
+ hint?: boolean | undefined;
29
31
  };
32
+ /** Sorting options per view; the first is the default. */
33
+ export declare const SORT_KEYS: Partial<Record<PanelView, readonly string[]>>;
34
+ export declare function sortKeys(view: PanelView): readonly string[];
35
+ export declare function defaultSort(view: PanelView): string;
36
+ export declare function nextSort(view: PanelView, current: string, step: number): string;
30
37
  /** The views and ranges, as the command and the panel header understand them. */
31
38
  export declare function parseArgs(input: string | undefined): {
32
39
  view?: PanelView;
@@ -212,7 +219,8 @@ export declare function turnsLines(rows: readonly TurnUsage[], width: number, op
212
219
  export declare function sessionSummaryLines(usage: Overview, budget?: number, estimates?: boolean): PanelLine[];
213
220
  /**
214
221
  * The sidebar history: a compact block per turn — when and through which
215
- * provider, then the prompt volumes, then the cache hit, the rate and the cost.
222
+ * provider and how long it took, then the prompt volumes, then the cache hit,
223
+ * the rate and the cost.
216
224
  *
217
225
  * The model gets a line of its own at both ends of the block and on every turn
218
226
  * that changed it. The ends matter because the reader cannot tell whether a
package/dist/panel.d.ts CHANGED
@@ -1,8 +1,5 @@
1
- /** @jsxImportSource @opentui/solid */
2
- import type { Database } from "bun:sqlite";
3
1
  import type { Context, PanelInput } from "@opencode/plugin/tui/context";
4
- import { type LineFormatOptions, type PanelSettings } from "./panel-data";
5
- import { type BackfillResult } from "./stats/maintenance";
2
+ import { type PanelSettings } from "./panel-data";
6
3
  /**
7
4
  * The `/usage` panel. One read-only view over the stats database at a time,
8
5
  * driven entirely from the keyboard: a cursor over the selectable lines,
@@ -13,22 +10,6 @@ import { type BackfillResult } from "./stats/maintenance";
13
10
  * component registers — the prompt is not involved.
14
11
  */
15
12
  export type PanelDeps = {
16
- /** Lazily opened stats database; undefined when it cannot be opened. */
17
- db: () => Database | undefined;
18
- /** Where that database lives, for the `db` view. */
19
- dbPath: () => string;
20
- /**
21
- * Short-lived write connection for maintenance (prune, compact). The panel
22
- * itself only reads; opening a writer on demand is what keeps a read from
23
- * ever taking the recorder's lock. Undefined when the write cannot be made.
24
- */
25
- withWrite?: (<Value>(run: (db: Database) => Value) => Value | undefined) | undefined;
26
- /** Price the historical $0 steps that have no estimate yet. */
27
- backfill?: (() => BackfillResult | undefined) | undefined;
28
- /** Injectable clock, for tests. */
29
- now: () => number;
30
- /** Creation time of a session, used by the `session` range. */
31
- sessionStart: (sessionID: string) => number | undefined;
32
13
  /** Bumped by the TUI when a step or an execution ends, so views re-read. */
33
14
  refresh?: (() => number) | undefined;
34
15
  /**
@@ -43,5 +24,5 @@ export declare function Panel(props: {
43
24
  readonly deps: PanelDeps;
44
25
  readonly settings: PanelSettings;
45
26
  readonly update: (mutation: (draft: PanelSettings) => void) => void;
46
- readonly format?: LineFormatOptions | undefined;
27
+ readonly maintenance?: boolean | undefined;
47
28
  }): any;
@@ -0,0 +1,24 @@
1
+ import type { OpenCodeClient } from "@opencode/client";
2
+ import { type BackfillInput, type FiltersOutput, type ListCostInput, type ListCostOutput, type PanelInput, type PanelOutput, type PruneInput, type RecordedEvent, type TurnsInput, type TurnsOutput, type VacuumInput, type VacuumOutput, type WipeInput } from "./rpc";
3
+ import type { BackfillResult, PruneResult, WipeResult } from "./stats/maintenance";
4
+ /**
5
+ * Typed client for the usage RPC, shared by the TUI and the desktop GUI. The
6
+ * contract uses JSON Schema, so the generated client returns `unknown`; this
7
+ * wrapper is the one place the plugin casts it back to the declared types.
8
+ */
9
+ export type UsageLocation = {
10
+ directory?: string | undefined;
11
+ };
12
+ export type UsageApi = ReturnType<typeof usageApi>;
13
+ export declare function usageApi(client: OpenCodeClient, location?: UsageLocation | undefined): {
14
+ panel: (input: PanelInput, signal?: AbortSignal) => Promise<PanelOutput>;
15
+ turns: (input: TurnsInput, signal?: AbortSignal) => Promise<TurnsOutput>;
16
+ listCost: (input: ListCostInput, signal?: AbortSignal) => Promise<ListCostOutput>;
17
+ filters: (signal?: AbortSignal) => Promise<FiltersOutput>;
18
+ dbInfo: (signal?: AbortSignal) => Promise<import("./stats/maintenance").DbInfo>;
19
+ prune: (input: PruneInput, signal?: AbortSignal) => Promise<PruneResult>;
20
+ wipe: (input: WipeInput, signal?: AbortSignal) => Promise<WipeResult>;
21
+ vacuum: (input: VacuumInput, signal?: AbortSignal) => Promise<VacuumOutput>;
22
+ backfill: (input: BackfillInput, signal?: AbortSignal) => Promise<BackfillResult>;
23
+ onRecorded: (handler: (event: RecordedEvent) => void, signal?: AbortSignal) => () => void;
24
+ };