opencode-usage-insights 0.3.1 → 0.4.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/README.md +66 -542
- package/dist/core.d.ts +15 -1
- package/dist/gui-experimental.cjs +3 -3
- package/dist/index.d.ts +0 -47
- package/dist/index.js +1715 -1195
- package/dist/index.js.map +23 -16
- package/dist/line.d.ts +1 -0
- package/dist/panel-data.d.ts +8 -1
- package/dist/recorder.d.ts +1 -0
- package/dist/rpc.d.ts +4 -4
- package/dist/rpc.js +5 -5
- package/dist/rpc.js.map +3 -3
- package/dist/settings-client.d.ts +29 -0
- package/dist/settings-rpc.d.ts +746 -0
- package/dist/settings.d.ts +114 -0
- package/dist/sidebar.d.ts +3 -3
- package/dist/stats/aggregates.d.ts +15 -3
- package/dist/stats/constants.d.ts +7 -0
- package/dist/stats/db.d.ts +8 -128
- package/dist/stats/legacy.d.ts +25 -0
- package/dist/stats/maintenance.d.ts +1 -1
- package/dist/stats/migrate.d.ts +7 -0
- package/dist/stats/ndjson.d.ts +16 -0
- package/dist/stats/open.d.ts +15 -0
- package/dist/stats/paths.d.ts +5 -4
- package/dist/stats/queries.d.ts +25 -31
- package/dist/stats/records.d.ts +94 -0
- package/dist/stats/schema.d.ts +26 -0
- package/dist/stats-client.d.ts +9 -0
- package/dist/stats-worker.js +577 -352
- package/dist/stats-worker.js.map +17 -12
- package/dist/text.d.ts +2 -0
- package/dist/tui-settings.d.ts +18 -0
- package/dist/tui.d.ts +1 -57
- package/dist/tui.js +954 -144
- package/dist/tui.js.map +17 -13
- package/docs/cli.md +24 -0
- package/docs/configuration.md +108 -0
- package/docs/costs.md +44 -0
- package/docs/demo.md +94 -68
- package/docs/desktop.md +91 -0
- package/docs/images/desktop-overview-annotated.png +0 -0
- package/docs/images/desktop-overview.png +0 -0
- package/docs/images/desktop-settings.png +0 -0
- package/docs/images/desktop-turns-go-annotated.png +0 -0
- package/docs/images/desktop-turns.png +0 -0
- package/docs/images/line.png +0 -0
- package/docs/images/panel-cache.png +0 -0
- package/docs/images/panel-help.png +0 -0
- package/docs/images/panel-latency.png +0 -0
- package/docs/images/panel-overview.png +0 -0
- package/docs/images/panel-providers.png +0 -0
- package/docs/images/sidebar.png +0 -0
- package/docs/internals.md +87 -36
- package/docs/privacy.md +60 -0
- package/docs/tui.md +175 -0
- package/package.json +2 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Database } from "bun:sqlite";
|
|
2
|
+
/**
|
|
3
|
+
* The persisted shape. Kept separate from opening and recording so a migration
|
|
4
|
+
* can read it without pulling in the recorder or the import layer.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SCHEMA_VERSION = 14;
|
|
7
|
+
export declare const SCHEMA = "\nCREATE TABLE IF NOT EXISTS meta (\n key TEXT PRIMARY KEY,\n value TEXT NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS sessions (\n session_id TEXT PRIMARY KEY,\n parent_id TEXT,\n directory TEXT,\n title TEXT,\n started_at INTEGER\n);\n\nCREATE TABLE IF NOT EXISTS prompts (\n session_id TEXT NOT NULL,\n message_id TEXT NOT NULL,\n created_at INTEGER,\n PRIMARY KEY (session_id, message_id)\n);\nCREATE INDEX IF NOT EXISTS prompts_created ON prompts(created_at);\n\nCREATE TABLE IF NOT EXISTS steps (\n message_id TEXT PRIMARY KEY,\n session_id TEXT NOT NULL,\n provider_id TEXT,\n model_id TEXT,\n variant TEXT,\n input_tokens INTEGER NOT NULL DEFAULT 0,\n output_tokens INTEGER NOT NULL DEFAULT 0,\n reasoning_tokens INTEGER NOT NULL DEFAULT 0,\n cache_read INTEGER NOT NULL DEFAULT 0,\n cache_write INTEGER NOT NULL DEFAULT 0,\n cost REAL NOT NULL DEFAULT 0,\n list_cost REAL,\n created_at INTEGER,\n first_token_at INTEGER,\n streamed_at INTEGER,\n completed_at INTEGER,\n finish TEXT,\n recorded_at INTEGER NOT NULL\n);\nCREATE INDEX IF NOT EXISTS steps_session ON steps(session_id, created_at);\nCREATE INDEX IF NOT EXISTS steps_model ON steps(provider_id, model_id, variant);\nCREATE INDEX IF NOT EXISTS steps_completed ON steps(completed_at);\n-- Every range filter and every ordering compares the step's own clock, which\n-- falls back to the recording time for a step that was already in flight when\n-- the plugin loaded. The index has to cover that expression, or every ranged\n-- view is a full table scan.\nCREATE INDEX IF NOT EXISTS steps_at ON steps(COALESCE(created_at, recorded_at));\nCREATE INDEX IF NOT EXISTS steps_session_at ON steps(session_id, COALESCE(created_at, recorded_at));\n\n-- The compaction timeline: when a compaction ended, by host event ID. The\n-- cost and tokens live in the usage table; the payload that used to be copied\n-- here was never read. Only compactions exist in this table by construction.\nCREATE TABLE IF NOT EXISTS compactions (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n session_id TEXT NOT NULL,\n message_id TEXT,\n at INTEGER\n);\nCREATE INDEX IF NOT EXISTS compactions_session ON compactions(session_id, at);\nCREATE INDEX IF NOT EXISTS compactions_at ON compactions(at);\nCREATE UNIQUE INDEX IF NOT EXISTS compactions_message ON compactions(message_id) WHERE message_id IS NOT NULL;\n\n-- Usage the host reports with no assistant step of its own: the compaction\n-- summarisation and the session-title generation. The host publishes it as\n-- session.usage.recorded with a source other than generate, and includes it in\n-- the session's own cost/token totals. Primary key is the host event ID, so a\n-- replayed event never counts twice.\nCREATE TABLE IF NOT EXISTS usage (\n id TEXT PRIMARY KEY,\n session_id TEXT NOT NULL,\n source TEXT NOT NULL,\n at INTEGER,\n cost REAL NOT NULL DEFAULT 0,\n input_tokens INTEGER NOT NULL DEFAULT 0,\n output_tokens INTEGER NOT NULL DEFAULT 0,\n reasoning_tokens INTEGER NOT NULL DEFAULT 0,\n cache_read INTEGER NOT NULL DEFAULT 0,\n cache_write INTEGER NOT NULL DEFAULT 0\n);\nCREATE INDEX IF NOT EXISTS usage_session_at ON usage(session_id, at);\nCREATE INDEX IF NOT EXISTS usage_at ON usage(at);\n";
|
|
8
|
+
/** Tables carried by `exportNdjson` / `importNdjson`, in import-safe order. */
|
|
9
|
+
export declare const TABLES: readonly ["sessions", "prompts", "compactions", "steps", "usage"];
|
|
10
|
+
export type TableName = (typeof TABLES)[number];
|
|
11
|
+
/** Column shape an import has to respect: the type and the NOT NULL rules. */
|
|
12
|
+
export type ImportColumn = {
|
|
13
|
+
name: string;
|
|
14
|
+
/** Declared affinity: `INTEGER`, `REAL`, `TEXT`, `BLOB` or empty. */
|
|
15
|
+
type: string;
|
|
16
|
+
notNull: boolean;
|
|
17
|
+
primaryKey: boolean;
|
|
18
|
+
/** A column with a default may be left out of the import entirely. */
|
|
19
|
+
hasDefault: boolean;
|
|
20
|
+
};
|
|
21
|
+
/** True when the database carries a table, without throwing on an older file. */
|
|
22
|
+
export declare function hasTable(db: Database, name: string): boolean;
|
|
23
|
+
/** Column names of a table, or an empty set when the table does not exist. */
|
|
24
|
+
export declare function columnsOf(db: Database, table: string): Set<string>;
|
|
25
|
+
/** Full column metadata an import has to respect. */
|
|
26
|
+
export declare function tableColumns(db: Database, table: string): ImportColumn[];
|
package/dist/stats-client.d.ts
CHANGED
|
@@ -41,12 +41,21 @@ export declare class StatsClient {
|
|
|
41
41
|
private startPromise;
|
|
42
42
|
private starting;
|
|
43
43
|
private startAbort;
|
|
44
|
+
private abortStart;
|
|
44
45
|
private fallbackService;
|
|
45
46
|
private fallbackMode;
|
|
46
47
|
private stopped;
|
|
47
48
|
private nextID;
|
|
48
49
|
private readonly pending;
|
|
49
50
|
constructor(config: StatsClientOptions);
|
|
51
|
+
/**
|
|
52
|
+
* Apply new service options. A live worker is stopped and restarted on the
|
|
53
|
+
* next request, so a settings change cannot leave a query formatted with the
|
|
54
|
+
* previous labels or still allow a maintenance action the server just
|
|
55
|
+
* disabled. Reads in flight are rejected as `unavailable`; the client
|
|
56
|
+
* retries them on its next refresh.
|
|
57
|
+
*/
|
|
58
|
+
reconfigure(options: Omit<ServiceOptions, "path" | "priceTable">): void;
|
|
50
59
|
/** A request with no caller-side cancellation. */
|
|
51
60
|
request<T>(method: StatsMethod, input: unknown, options?: {
|
|
52
61
|
signal?: AbortSignal | undefined;
|