zidane-gui 0.0.1 → 7.0.3

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.
File without changes
@@ -0,0 +1,59 @@
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_OF_CREATED_AT} AS day,
11
+ COALESCE(json_extract(t.data, '$.usage.modelId'), 'unknown') AS model,
12
+ COUNT(*) AS turns,
13
+ SUM(COALESCE(json_extract(t.data, '$.usage.input'), 0)) AS input,
14
+ SUM(COALESCE(json_extract(t.data, '$.usage.output'), 0)) AS output,
15
+ SUM(COALESCE(json_extract(t.data, '$.usage.cacheRead'), 0)) AS cacheRead,
16
+ SUM(COALESCE(json_extract(t.data, '$.usage.cacheCreation'), 0)) AS cacheCreation,
17
+ SUM(COALESCE(json_extract(t.data, '$.usage.cost'), 0)) AS cost
18
+ FROM turns t
19
+ WHERE t.role = 'assistant' AND json_valid(t.data)
20
+ GROUP BY day, model
21
+ HAVING day IS NOT NULL
22
+ ORDER BY day`
23
+ ).all();
24
+ }
25
+ function usageUserDaily(database) {
26
+ return database.prepare(
27
+ `SELECT ${DAY_OF_CREATED_AT} AS day,
28
+ CAST(strftime('%H', json_extract(t.data, '$.createdAt') / 1000, 'unixepoch', 'localtime') AS INTEGER) AS hour,
29
+ COUNT(*) AS messages
30
+ FROM turns t
31
+ WHERE ${PARENT_USER_TURN}
32
+ GROUP BY day, hour
33
+ HAVING day IS NOT NULL
34
+ ORDER BY day`
35
+ ).all();
36
+ }
37
+ function usageSessionDaily(database) {
38
+ return database.prepare(
39
+ `SELECT date(created_at / 1000, 'unixepoch', 'localtime') AS day, COUNT(*) AS sessions
40
+ FROM sessions
41
+ GROUP BY day
42
+ HAVING day IS NOT NULL
43
+ ORDER BY day`
44
+ ).all();
45
+ }
46
+ function runUsageAggregates(database) {
47
+ return {
48
+ assistant: usageAssistantDaily(database),
49
+ user: usageUserDaily(database),
50
+ sessions: usageSessionDaily(database)
51
+ };
52
+ }
53
+ export {
54
+ PARENT_USER_TURN as P,
55
+ usageSessionDaily as a,
56
+ usageUserDaily as b,
57
+ runUsageAggregates as r,
58
+ usageAssistantDaily as u
59
+ };