zidane-gui 8.1.0 → 8.2.1
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 +31 -25
- package/out/main/chunks/history-pager-Bd5PUapJ.js +191 -0
- package/out/main/chunks/{remote-hosts-CdVisI0d.js → remote-hosts-DlvE2ELX.js} +2 -1
- package/out/main/chunks/usage-sql-C2Tg1u44.js +81 -0
- package/out/main/history-worker.js +20 -0
- package/out/main/index.js +7382 -7649
- package/out/main/lsp-host.js +591 -109
- package/out/main/usage-worker.js +1 -1
- package/out/preload/index.mjs +34 -4
- package/out/renderer/assets/{ghostty-web-92tSV0lR.js → ghostty-web-BCAZYtuA.js} +1 -1
- package/out/renderer/assets/{index-u9t9fsPc.css → index-CBxNp5Xb.css} +1393 -85
- package/out/renderer/assets/{index-DlEFfgBI.js → index-CPTV1As9.js} +23186 -13992
- package/out/renderer/index.html +2 -2
- package/package.json +9 -3
- package/scripts/app-installer.mjs +4 -9
- package/scripts/postinstall.mjs +1 -2
- package/out/main/chunks/usage-sql-CqAEudo_.js +0 -58
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<img src="resources/icon.png" alt="Zizou" width="500" />
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Zidane Desktop is the Electron app of `zidane`. It is a chat shell for the zidane agent, with a session sidebar, a transcript, a composer and side panels.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -12,11 +12,12 @@ Standalone Electron app. It is a Claude Code-style chat shell that uses `zidane`
|
|
|
12
12
|
npm install -g zidane-gui
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
the launcher is `~/Applications/Zidane.app`
|
|
17
|
-
Launchpad). On Linux it is a `.desktop` entry. If you
|
|
18
|
-
`--ignore-scripts` or as root, run `zidane-gui install-app` as
|
|
19
|
-
user.
|
|
15
|
+
On macOS and Linux, a global install also adds a launcher app through the
|
|
16
|
+
postinstall script. On macOS the launcher is `~/Applications/Zidane.app`
|
|
17
|
+
(Spotlight, Raycast, Launchpad). On Linux it is a `.desktop` entry. If you
|
|
18
|
+
installed with `--ignore-scripts` or as root, run `zidane-gui install-app` as
|
|
19
|
+
your regular user. Run `zidane-gui` with no argument to start the app from a
|
|
20
|
+
terminal.
|
|
20
21
|
|
|
21
22
|
To uninstall, remove the launcher app before you remove the package. npm 7
|
|
22
23
|
and later does not run `preuninstall` scripts. So if you remove the package
|
|
@@ -29,25 +30,30 @@ npm uninstall -g zidane-gui
|
|
|
29
30
|
|
|
30
31
|
## Dev
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
bun
|
|
35
|
-
|
|
33
|
+
`gui/` is not a member of the root bun workspaces. It has its own `bun.lock`, and it compiles `@zidane/ui` from `ui/` source.
|
|
34
|
+
|
|
35
|
+
1. Run `bun install` at the monorepo root.
|
|
36
|
+
2. Run `bun install` in `gui/`. Its postinstall script links `gui/node_modules/zidane` to the repo root.
|
|
37
|
+
3. Run `bun install` in `ui/`.
|
|
38
|
+
4. Run `bun --cwd=gui run dev`. The script builds the root `dist/` first, then starts electron-vite.
|
|
36
39
|
|
|
37
|
-
The renderer runs on `http://localhost:21200`. Electron loads it into the window
|
|
40
|
+
The renderer dev server runs on `http://localhost:21200`. Electron loads it into the window.
|
|
38
41
|
|
|
39
42
|
## Scripts
|
|
40
43
|
|
|
41
44
|
Run these from `gui/`, or run `bun --cwd=gui run <script>` from the root.
|
|
42
45
|
|
|
43
|
-
- `bun run dev` starts the electron-vite dev server with HMR.
|
|
46
|
+
- `bun run dev` builds the root `dist/`, then starts the electron-vite dev server with HMR.
|
|
44
47
|
- `bun run build` bundles main, preload and renderer into `out/`.
|
|
45
48
|
- `bun run start` previews a built bundle (`electron-vite preview`).
|
|
46
|
-
- `bun run typecheck` runs `
|
|
47
|
-
- `bun run
|
|
49
|
+
- `bun run typecheck` builds the root `dist/`, then runs `bun check` on the node and web projects.
|
|
50
|
+
- `bun run typecheck:tsc` runs `tsc --noEmit` on the node and web projects.
|
|
51
|
+
- `bun run format` formats the package with Prettier. `bun run format:check` only checks, as CI does.
|
|
52
|
+
- `bun run test` builds the root `dist/` (the `pretest` script), then runs the vitest unit suite in `src/` and `scripts/`.
|
|
48
53
|
- `bun run test:watch` runs vitest in watch mode.
|
|
49
54
|
- `bun run test:e2e` runs Playwright end-to-end tests. It runs `build` first.
|
|
50
|
-
- `bun run test:visual` runs the Playwright visual regression suite.
|
|
55
|
+
- `bun run test:visual` runs the Playwright visual regression suite. It runs `build` first.
|
|
56
|
+
- `bun run package` builds a macOS arm64 app with electron-builder.
|
|
51
57
|
|
|
52
58
|
## Stack
|
|
53
59
|
|
|
@@ -56,21 +62,21 @@ Run these from `gui/`, or run `bun --cwd=gui run <script>` from the root.
|
|
|
56
62
|
- TipTap 3 for the chatbox editor
|
|
57
63
|
- Shiki 4 for syntax highlighting
|
|
58
64
|
- `react-markdown` 10 and `remark-gfm` for transcript rendering
|
|
59
|
-
-
|
|
65
|
+
- `@pierre/diffs` and `@pierre/trees` for the code view, the diffs and the file tree
|
|
66
|
+
- `@tahul/ghostty-web` for the terminal
|
|
67
|
+
- `motion` for animation
|
|
60
68
|
- TypeScript 6
|
|
61
|
-
- SQLite through Electron's built-in `node:sqlite` (no native modules),
|
|
62
|
-
- Numbered SQL migrations in `migrations/` applied
|
|
63
|
-
- Vitest 4 for unit tests
|
|
69
|
+
- SQLite through Electron's built-in `node:sqlite` (no native modules). Sessions live in `<dataDir>/sessions.db` (`~/.zidane/sessions.db` outside XDG), the same file as the TUI. The app's own state (the last folder, the sidebar's views, the app icon) and pending approvals live in `app.getPath('userData')/zidane-gui.db`. Settings live in `state.json`, shared with the TUI.
|
|
70
|
+
- Numbered SQL migrations in `migrations/` for `zidane-gui.db`, applied when the app first opens it
|
|
71
|
+
- Vitest 4 for unit tests. The default environment is node. A `.test.tsx` file opts into jsdom with `// @vitest-environment jsdom`.
|
|
64
72
|
|
|
65
73
|
## Notes
|
|
66
74
|
|
|
67
|
-
- `vite` is held at v7
|
|
75
|
+
- `vite` is held at v7 because `electron-vite` 5 does not support Vite 8.
|
|
68
76
|
- `@vitejs/plugin-react` is held at v5 for the same reason. v6 requires Vite 8.
|
|
69
|
-
- This package lives in the `
|
|
77
|
+
- This package lives in the `gui/` folder of the `zidane` monorepo. `gui/node_modules/zidane` is a symlink to the repo root, so the app uses the root `dist/`. The `dev`, `typecheck` and `test` scripts rebuild it.
|
|
70
78
|
- There are no native modules. SQLite is Electron's built-in `node:sqlite`, so there is no ABI rebuild step. `trustedDependencies` (`electron`, `esbuild`) lets bun run their build scripts.
|
|
71
79
|
|
|
72
|
-
##
|
|
80
|
+
## Docs
|
|
73
81
|
|
|
74
|
-
|
|
75
|
-
- Flat sidebar of chats sorted by `updated_at DESC`, rename and delete inline
|
|
76
|
-
- Chatbox in the center. Chat result rendering is intentionally deferred.
|
|
82
|
+
The user guide is in `website/content/docs/desktop*.mdx` (the Desktop app pages of the docs site). Coding agents read `CLAUDE.md` in this folder.
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { Worker } from "node:worker_threads";
|
|
4
|
+
import { createReadonlySqliteSessionStore } from "zidane";
|
|
5
|
+
import { createTranscriptReplayCache, transcriptPage, LOAD_EVENTS_MAX_PAGE_TURNS, HISTORY_WORKER_KILL_SWITCH, createWorkerRpcClient, WorkerRequestError, WorkerUnavailableError } from "zidane/ipc";
|
|
6
|
+
import { replayTurns } from "zidane/chat";
|
|
7
|
+
import __cjs_mod__ from "node:module";
|
|
8
|
+
const __filename = import.meta.filename;
|
|
9
|
+
const __dirname = import.meta.dirname;
|
|
10
|
+
const require2 = __cjs_mod__.createRequire(import.meta.url);
|
|
11
|
+
function settleRuns(runs, live) {
|
|
12
|
+
if (live) return runs;
|
|
13
|
+
return runs.map(
|
|
14
|
+
(run) => run.status === "running" ? { ...run, status: "aborted", endedAt: run.endedAt ?? run.startedAt } : run
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
function tailPageTurns(boundaries, prompts, min, max) {
|
|
18
|
+
let seen = 0;
|
|
19
|
+
let start = 0;
|
|
20
|
+
for (let i = boundaries.length - 1; i >= 0; i -= 1) {
|
|
21
|
+
if (!boundaries[i]) continue;
|
|
22
|
+
seen += 1;
|
|
23
|
+
if (seen === prompts) {
|
|
24
|
+
start = i;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return Math.min(Math.max(boundaries.length - start, min), max);
|
|
29
|
+
}
|
|
30
|
+
function createTranscriptPager(options = {}) {
|
|
31
|
+
const pageTurns = options.pageTurns ?? 200;
|
|
32
|
+
const tailPrompts = options.tailPrompts ?? 10;
|
|
33
|
+
const tailMinTurns = options.tailMinTurns ?? pageTurns;
|
|
34
|
+
const tailMaxTurns = options.tailMaxTurns ?? 1e3;
|
|
35
|
+
const cache = createTranscriptReplayCache({
|
|
36
|
+
maxSessions: options.maxSessions ?? 4,
|
|
37
|
+
maxBytes: options.maxBytes ?? 160 * 1024 * 1024,
|
|
38
|
+
replay: options.replay ?? replayTurns
|
|
39
|
+
});
|
|
40
|
+
const replayFor = async (id, source, request) => {
|
|
41
|
+
const { live } = request;
|
|
42
|
+
const cached = cache.cached(id);
|
|
43
|
+
if (live && request.before !== null && cached?.version.endsWith("|live") && request.before <= cached.boundaries.length) {
|
|
44
|
+
if (!request.prewarm) cache.cached(id, true);
|
|
45
|
+
return cached;
|
|
46
|
+
}
|
|
47
|
+
const replay = await cache.replay(source.store, id, {
|
|
48
|
+
// The settled runs depend on `live`, so it is part of what was replayed.
|
|
49
|
+
variant: live ? "|live" : "|idle",
|
|
50
|
+
load: () => {
|
|
51
|
+
const data = source.load(id);
|
|
52
|
+
return data && { ...data, runs: settleRuns(data.runs, live) };
|
|
53
|
+
},
|
|
54
|
+
...request.prewarm ? { background: true } : {}
|
|
55
|
+
});
|
|
56
|
+
if (!replay) cache.forget(id);
|
|
57
|
+
return replay;
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
async page(id, source, request) {
|
|
61
|
+
const entry = await replayFor(id, source, request);
|
|
62
|
+
if (!entry) return null;
|
|
63
|
+
const limit = request.before === null ? tailPageTurns(entry.boundaries, tailPrompts, tailMinTurns, tailMaxTurns) : pageTurns;
|
|
64
|
+
const { from, to, cursor } = transcriptPage(
|
|
65
|
+
entry.boundaries,
|
|
66
|
+
{ limit, ...request.before !== null ? { before: request.before } : {} },
|
|
67
|
+
entry.cuts
|
|
68
|
+
);
|
|
69
|
+
const seqs = entry.seqs;
|
|
70
|
+
const turnSeqs = [];
|
|
71
|
+
for (let i = from; i < to; i += 1) {
|
|
72
|
+
const turnId = entry.turnIds[i];
|
|
73
|
+
if (typeof turnId === "string") turnSeqs.push([turnId, seqs[i]]);
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
events: entry.events.slice(entry.turnStarts[from], entry.turnStarts[to]),
|
|
77
|
+
...cursor !== void 0 ? { cursor } : {},
|
|
78
|
+
...to > from ? { seqRange: { from: seqs[from], to: seqs[to - 1] } } : {},
|
|
79
|
+
turnSeqs
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
forget: (id) => cache.forget(id),
|
|
83
|
+
size: () => cache.sizes().entries
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function parseRow(data) {
|
|
87
|
+
try {
|
|
88
|
+
return JSON.parse(data);
|
|
89
|
+
} catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function parseRows(rows) {
|
|
94
|
+
return rows.flatMap((r) => {
|
|
95
|
+
const parsed = parseRow(r.data);
|
|
96
|
+
return parsed === null ? [] : [parsed];
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function sessionExistsOn(driver, id) {
|
|
100
|
+
return driver.prepare("SELECT 1 FROM sessions WHERE id = ?").get(id) !== void 0;
|
|
101
|
+
}
|
|
102
|
+
function readRuns(driver, id) {
|
|
103
|
+
return parseRows(
|
|
104
|
+
driver.prepare("SELECT data FROM runs WHERE session_id = ? ORDER BY started_at, run_id").all(id)
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
function readTranscript(driver, id) {
|
|
108
|
+
if (!sessionExistsOn(driver, id)) return null;
|
|
109
|
+
const rows = driver.prepare("SELECT seq, data FROM turns WHERE session_id = ? ORDER BY seq").all(id);
|
|
110
|
+
const turns = [];
|
|
111
|
+
const seqs = [];
|
|
112
|
+
const turnSeqs = /* @__PURE__ */ new Map();
|
|
113
|
+
for (const row of rows) {
|
|
114
|
+
const turn = parseRow(row.data);
|
|
115
|
+
if (!turn) continue;
|
|
116
|
+
turns.push(turn);
|
|
117
|
+
seqs.push(row.seq);
|
|
118
|
+
if (typeof turn.id === "string" && !turnSeqs.has(turn.id)) turnSeqs.set(turn.id, row.seq);
|
|
119
|
+
}
|
|
120
|
+
return { data: { turns, seqs, runs: readRuns(driver, id) }, turnSeqs };
|
|
121
|
+
}
|
|
122
|
+
const EVENTS_PAGE_TURNS = 200;
|
|
123
|
+
const HISTORY_PAGER_OPTIONS = {
|
|
124
|
+
pageTurns: EVENTS_PAGE_TURNS,
|
|
125
|
+
// The tail page reaches back to the user's 10th-last prompt (one long run
|
|
126
|
+
// folds into a single row: 200 turns could show one exchange), within the
|
|
127
|
+
// protocol's page ceiling.
|
|
128
|
+
tailPrompts: 10,
|
|
129
|
+
tailMinTurns: EVENTS_PAGE_TURNS,
|
|
130
|
+
tailMaxTurns: LOAD_EVENTS_MAX_PAGE_TURNS
|
|
131
|
+
};
|
|
132
|
+
function createHistoryPageHandler(driver, options = HISTORY_PAGER_OPTIONS) {
|
|
133
|
+
const pager = createTranscriptPager(options);
|
|
134
|
+
const source = {
|
|
135
|
+
store: createReadonlySqliteSessionStore(driver),
|
|
136
|
+
load: (id) => readTranscript(driver, id)?.data ?? null
|
|
137
|
+
};
|
|
138
|
+
return ({ sessionId, ...request }) => pager.page(sessionId, source, request);
|
|
139
|
+
}
|
|
140
|
+
function spawnHistoryWorker() {
|
|
141
|
+
const file = join(__dirname, "history-worker.js");
|
|
142
|
+
if (!existsSync(file)) throw new Error(`history worker: no ${file}`);
|
|
143
|
+
return new Worker(file);
|
|
144
|
+
}
|
|
145
|
+
const debugFallback = process.env.ZIDANE_DEBUG ? (error) => console.error("[gui] history page fell back to the main thread:", error) : () => {
|
|
146
|
+
};
|
|
147
|
+
function createLocalHistoryPager(deps) {
|
|
148
|
+
const options = deps.options ?? HISTORY_PAGER_OPTIONS;
|
|
149
|
+
let inThread = null;
|
|
150
|
+
let client = null;
|
|
151
|
+
let closed = false;
|
|
152
|
+
const local = (sessionId, request) => {
|
|
153
|
+
inThread ??= createTranscriptPager(options);
|
|
154
|
+
return inThread.page(sessionId, deps.source, request);
|
|
155
|
+
};
|
|
156
|
+
return {
|
|
157
|
+
async page(sessionId, request) {
|
|
158
|
+
if (closed || process.env[HISTORY_WORKER_KILL_SWITCH] === "1") return local(sessionId, request);
|
|
159
|
+
await deps.pendingWrites();
|
|
160
|
+
if (closed) return local(sessionId, request);
|
|
161
|
+
client ??= createWorkerRpcClient({
|
|
162
|
+
name: "history worker",
|
|
163
|
+
create: deps.create ?? spawnHistoryWorker,
|
|
164
|
+
init: { dbPath: deps.dbPath() }
|
|
165
|
+
});
|
|
166
|
+
try {
|
|
167
|
+
return await client.request({ sessionId, ...request });
|
|
168
|
+
} catch (err) {
|
|
169
|
+
if (err instanceof WorkerRequestError) throw new Error(err.message);
|
|
170
|
+
if (!(err instanceof WorkerUnavailableError)) throw err;
|
|
171
|
+
debugFallback(err);
|
|
172
|
+
}
|
|
173
|
+
return local(sessionId, request);
|
|
174
|
+
},
|
|
175
|
+
close() {
|
|
176
|
+
closed = true;
|
|
177
|
+
client?.close();
|
|
178
|
+
client = null;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
export {
|
|
183
|
+
EVENTS_PAGE_TURNS as E,
|
|
184
|
+
parseRow as a,
|
|
185
|
+
readTranscript as b,
|
|
186
|
+
createHistoryPageHandler as c,
|
|
187
|
+
createLocalHistoryPager as d,
|
|
188
|
+
parseRows as p,
|
|
189
|
+
readRuns as r,
|
|
190
|
+
sessionExistsOn as s
|
|
191
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createSyncEngine, startWsSavedHosts } from "zidane/ipc/remote";
|
|
1
|
+
import { trustSystemCertificates, createSyncEngine, startWsSavedHosts } from "zidane/ipc/remote";
|
|
2
2
|
function savedHostsDirectory(directory) {
|
|
3
3
|
return {
|
|
4
4
|
saved: () => directory.servers().map((host) => ({ key: host.id, url: host.url })),
|
|
@@ -29,6 +29,7 @@ function savedHostsDirectory(directory) {
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
function startRemoteHosts(options) {
|
|
32
|
+
trustSystemCertificates();
|
|
32
33
|
const { onSignal, onConnected } = options;
|
|
33
34
|
const sync = options.sync ? createSyncEngine({ dataDir: options.dataDir, ...options.sync() }) : null;
|
|
34
35
|
const offSync = sync?.subscribe(() => options.onSyncChanged?.(null));
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const PARENT_USER_TURN = `t.role = 'user' AND json_valid(t.data) AND NOT EXISTS (
|
|
2
|
+
SELECT 1 FROM runs r
|
|
3
|
+
WHERE r.session_id = t.session_id
|
|
4
|
+
AND r.run_id = json_extract(t.data, '$.runId')
|
|
5
|
+
AND (json_extract(r.data, '$.depth') > 0 OR json_extract(r.data, '$.parentRunId') IS NOT NULL)
|
|
6
|
+
)`;
|
|
7
|
+
const DAY_OF_CREATED_AT = "date(json_extract(t.data, '$.createdAt') / 1000, 'unixepoch', 'localtime')";
|
|
8
|
+
function usageAssistantDaily(database) {
|
|
9
|
+
return database.prepare(
|
|
10
|
+
`SELECT day, model,
|
|
11
|
+
SUM(turns) AS turns,
|
|
12
|
+
SUM(input) AS input,
|
|
13
|
+
SUM(output) AS output,
|
|
14
|
+
SUM(cacheRead) AS cacheRead,
|
|
15
|
+
SUM(cacheCreation) AS cacheCreation,
|
|
16
|
+
SUM(cost) AS cost
|
|
17
|
+
FROM (
|
|
18
|
+
SELECT ${DAY_OF_CREATED_AT} AS day,
|
|
19
|
+
COALESCE(json_extract(t.data, '$.usage.modelId'), 'unknown') AS model,
|
|
20
|
+
1 AS turns,
|
|
21
|
+
COALESCE(json_extract(t.data, '$.usage.input'), 0) AS input,
|
|
22
|
+
COALESCE(json_extract(t.data, '$.usage.output'), 0) AS output,
|
|
23
|
+
COALESCE(json_extract(t.data, '$.usage.cacheRead'), 0) AS cacheRead,
|
|
24
|
+
COALESCE(json_extract(t.data, '$.usage.cacheCreation'), 0) AS cacheCreation,
|
|
25
|
+
COALESCE(json_extract(t.data, '$.usage.cost'), 0) AS cost
|
|
26
|
+
FROM turns t
|
|
27
|
+
WHERE t.role = 'assistant' AND json_valid(t.data)
|
|
28
|
+
UNION ALL
|
|
29
|
+
SELECT ${DAY_OF_CREATED_AT} AS day,
|
|
30
|
+
COALESCE(json_extract(b.value, '$.usage.modelId'), json_extract(b.value, '$.model'), 'unknown') AS model,
|
|
31
|
+
0 AS turns,
|
|
32
|
+
COALESCE(json_extract(b.value, '$.usage.input'), 0) AS input,
|
|
33
|
+
COALESCE(json_extract(b.value, '$.usage.output'), 0) AS output,
|
|
34
|
+
COALESCE(json_extract(b.value, '$.usage.cacheRead'), 0) AS cacheRead,
|
|
35
|
+
COALESCE(json_extract(b.value, '$.usage.cacheCreation'), 0) AS cacheCreation,
|
|
36
|
+
COALESCE(json_extract(b.value, '$.usage.cost'), 0) AS cost
|
|
37
|
+
FROM turns t,
|
|
38
|
+
json_each(CASE WHEN json_valid(t.data) THEN t.data ELSE '{}' END, '$.content') b
|
|
39
|
+
WHERE t.role = 'user'
|
|
40
|
+
AND instr(t.data, 'compact-summary') > 0
|
|
41
|
+
AND json_extract(b.value, '$.type') = 'compact-summary'
|
|
42
|
+
)
|
|
43
|
+
GROUP BY day, model
|
|
44
|
+
HAVING day IS NOT NULL
|
|
45
|
+
ORDER BY day`
|
|
46
|
+
).all();
|
|
47
|
+
}
|
|
48
|
+
function usageUserDaily(database) {
|
|
49
|
+
return database.prepare(
|
|
50
|
+
`SELECT ${DAY_OF_CREATED_AT} AS day,
|
|
51
|
+
CAST(strftime('%H', json_extract(t.data, '$.createdAt') / 1000, 'unixepoch', 'localtime') AS INTEGER) AS hour,
|
|
52
|
+
COUNT(*) AS messages
|
|
53
|
+
FROM turns t
|
|
54
|
+
WHERE ${PARENT_USER_TURN}
|
|
55
|
+
GROUP BY day, hour
|
|
56
|
+
HAVING day IS NOT NULL
|
|
57
|
+
ORDER BY day`
|
|
58
|
+
).all();
|
|
59
|
+
}
|
|
60
|
+
function usageSessionDaily(database) {
|
|
61
|
+
return database.prepare(
|
|
62
|
+
`SELECT date(created_at / 1000, 'unixepoch', 'localtime') AS day, COUNT(*) AS sessions
|
|
63
|
+
FROM sessions
|
|
64
|
+
GROUP BY day
|
|
65
|
+
HAVING day IS NOT NULL
|
|
66
|
+
ORDER BY day`
|
|
67
|
+
).all();
|
|
68
|
+
}
|
|
69
|
+
function runUsageAggregates(database) {
|
|
70
|
+
return {
|
|
71
|
+
assistant: usageAssistantDaily(database),
|
|
72
|
+
user: usageUserDaily(database),
|
|
73
|
+
sessions: usageSessionDaily(database)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
usageUserDaily as a,
|
|
78
|
+
usageSessionDaily as b,
|
|
79
|
+
runUsageAggregates as r,
|
|
80
|
+
usageAssistantDaily as u
|
|
81
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DatabaseSync } from "node:sqlite";
|
|
2
|
+
import { createSqliteDriver } from "zidane";
|
|
3
|
+
import { serveWorkerRpc } from "zidane/ipc";
|
|
4
|
+
import { c as createHistoryPageHandler } from "./chunks/history-pager-Bd5PUapJ.js";
|
|
5
|
+
import "node:fs";
|
|
6
|
+
import "node:path";
|
|
7
|
+
import "node:worker_threads";
|
|
8
|
+
import "zidane/chat";
|
|
9
|
+
let handle = null;
|
|
10
|
+
void serveWorkerRpc({
|
|
11
|
+
init({ dbPath }) {
|
|
12
|
+
const db = new DatabaseSync(dbPath, { readOnly: true });
|
|
13
|
+
db.exec("PRAGMA busy_timeout = 5000");
|
|
14
|
+
handle = createHistoryPageHandler(createSqliteDriver(db));
|
|
15
|
+
},
|
|
16
|
+
handle(request) {
|
|
17
|
+
if (!handle) throw new Error("history worker: no database open");
|
|
18
|
+
return handle(request);
|
|
19
|
+
}
|
|
20
|
+
});
|