@oh-my-pi-zen/omp-stats 16.3.6-zen.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.
Files changed (120) hide show
  1. package/CHANGELOG.md +197 -0
  2. package/README.md +82 -0
  3. package/build.ts +95 -0
  4. package/dist/client/index.css +1 -0
  5. package/dist/client/index.html +24 -0
  6. package/dist/client/index.js +257 -0
  7. package/dist/client/styles.css +1656 -0
  8. package/dist/types/aggregator.d.ts +87 -0
  9. package/dist/types/client/App.d.ts +1 -0
  10. package/dist/types/client/api.d.ts +21 -0
  11. package/dist/types/client/app/AppLayout.d.ts +16 -0
  12. package/dist/types/client/app/NavRail.d.ts +7 -0
  13. package/dist/types/client/app/RangeControl.d.ts +7 -0
  14. package/dist/types/client/app/SyncButton.d.ts +14 -0
  15. package/dist/types/client/app/ThemeToggle.d.ts +1 -0
  16. package/dist/types/client/app/TopBar.d.ts +15 -0
  17. package/dist/types/client/app/routes.d.ts +12 -0
  18. package/dist/types/client/components/AgentTokenShare.d.ts +5 -0
  19. package/dist/types/client/components/chart-shared.d.ts +173 -0
  20. package/dist/types/client/components/models-table-shared.d.ts +175 -0
  21. package/dist/types/client/components/range-meta.d.ts +21 -0
  22. package/dist/types/client/data/charts.d.ts +1 -0
  23. package/dist/types/client/data/formatters.d.ts +8 -0
  24. package/dist/types/client/data/useHashRoute.d.ts +8 -0
  25. package/dist/types/client/data/useResource.d.ts +13 -0
  26. package/dist/types/client/data/view-models.d.ts +67 -0
  27. package/dist/types/client/index.d.ts +2 -0
  28. package/dist/types/client/routes/BehaviorRoute.d.ts +7 -0
  29. package/dist/types/client/routes/CostsRoute.d.ts +7 -0
  30. package/dist/types/client/routes/ErrorsRoute.d.ts +8 -0
  31. package/dist/types/client/routes/GainRoute.d.ts +7 -0
  32. package/dist/types/client/routes/ModelsRoute.d.ts +7 -0
  33. package/dist/types/client/routes/OverviewRoute.d.ts +8 -0
  34. package/dist/types/client/routes/ProjectsRoute.d.ts +7 -0
  35. package/dist/types/client/routes/RequestsRoute.d.ts +8 -0
  36. package/dist/types/client/routes/ToolsRoute.d.ts +7 -0
  37. package/dist/types/client/routes/index.d.ts +9 -0
  38. package/dist/types/client/types.d.ts +63 -0
  39. package/dist/types/client/ui/AsyncBoundary.d.ts +12 -0
  40. package/dist/types/client/ui/DataTable.d.ts +17 -0
  41. package/dist/types/client/ui/EmptyState.d.ts +7 -0
  42. package/dist/types/client/ui/ErrorState.d.ts +6 -0
  43. package/dist/types/client/ui/JsonBlock.d.ts +7 -0
  44. package/dist/types/client/ui/MetricCluster.d.ts +5 -0
  45. package/dist/types/client/ui/Panel.d.ts +7 -0
  46. package/dist/types/client/ui/RequestDrawer.d.ts +5 -0
  47. package/dist/types/client/ui/SegmentedControl.d.ts +12 -0
  48. package/dist/types/client/ui/Skeleton.d.ts +8 -0
  49. package/dist/types/client/ui/StatusPill.d.ts +7 -0
  50. package/dist/types/client/ui/index.d.ts +11 -0
  51. package/dist/types/client/useSystemTheme.d.ts +11 -0
  52. package/dist/types/db.d.ts +144 -0
  53. package/dist/types/embedded-client.d.ts +18 -0
  54. package/dist/types/gain-aggregator.d.ts +26 -0
  55. package/dist/types/index.d.ts +7 -0
  56. package/dist/types/parser.d.ts +53 -0
  57. package/dist/types/server.d.ts +7 -0
  58. package/dist/types/shared-types.d.ts +301 -0
  59. package/dist/types/sync-worker.d.ts +31 -0
  60. package/dist/types/types.d.ts +164 -0
  61. package/dist/types/user-metrics.d.ts +72 -0
  62. package/package.json +95 -0
  63. package/src/aggregator.ts +501 -0
  64. package/src/client/App.tsx +109 -0
  65. package/src/client/api.ts +102 -0
  66. package/src/client/app/AppLayout.tsx +93 -0
  67. package/src/client/app/NavRail.tsx +44 -0
  68. package/src/client/app/RangeControl.tsx +39 -0
  69. package/src/client/app/SyncButton.tsx +75 -0
  70. package/src/client/app/ThemeToggle.tsx +37 -0
  71. package/src/client/app/TopBar.tsx +73 -0
  72. package/src/client/app/routes.ts +69 -0
  73. package/src/client/components/AgentTokenShare.tsx +68 -0
  74. package/src/client/components/chart-shared.tsx +257 -0
  75. package/src/client/components/models-table-shared.tsx +255 -0
  76. package/src/client/components/range-meta.ts +73 -0
  77. package/src/client/css.d.ts +1 -0
  78. package/src/client/data/charts.ts +14 -0
  79. package/src/client/data/formatters.ts +45 -0
  80. package/src/client/data/useHashRoute.ts +87 -0
  81. package/src/client/data/useResource.ts +154 -0
  82. package/src/client/data/view-models.ts +251 -0
  83. package/src/client/index.tsx +10 -0
  84. package/src/client/routes/BehaviorRoute.tsx +623 -0
  85. package/src/client/routes/CostsRoute.tsx +234 -0
  86. package/src/client/routes/ErrorsRoute.tsx +118 -0
  87. package/src/client/routes/GainRoute.tsx +226 -0
  88. package/src/client/routes/ModelsRoute.tsx +430 -0
  89. package/src/client/routes/OverviewRoute.tsx +342 -0
  90. package/src/client/routes/ProjectsRoute.tsx +163 -0
  91. package/src/client/routes/RequestsRoute.tsx +123 -0
  92. package/src/client/routes/ToolsRoute.tsx +463 -0
  93. package/src/client/routes/index.ts +9 -0
  94. package/src/client/styles.css +1330 -0
  95. package/src/client/types.ts +80 -0
  96. package/src/client/ui/AsyncBoundary.tsx +54 -0
  97. package/src/client/ui/DataTable.tsx +122 -0
  98. package/src/client/ui/EmptyState.tsx +16 -0
  99. package/src/client/ui/ErrorState.tsx +25 -0
  100. package/src/client/ui/JsonBlock.tsx +75 -0
  101. package/src/client/ui/MetricCluster.tsx +67 -0
  102. package/src/client/ui/Panel.tsx +24 -0
  103. package/src/client/ui/RequestDrawer.tsx +208 -0
  104. package/src/client/ui/SegmentedControl.tsx +36 -0
  105. package/src/client/ui/Skeleton.tsx +17 -0
  106. package/src/client/ui/StatusPill.tsx +15 -0
  107. package/src/client/ui/index.ts +11 -0
  108. package/src/client/useSystemTheme.ts +87 -0
  109. package/src/db.ts +1530 -0
  110. package/src/embedded-client.generated.txt +0 -0
  111. package/src/embedded-client.ts +26 -0
  112. package/src/gain-aggregator.ts +281 -0
  113. package/src/index.ts +194 -0
  114. package/src/parser.ts +450 -0
  115. package/src/server.ts +352 -0
  116. package/src/shared-types.ts +323 -0
  117. package/src/sync-worker.ts +40 -0
  118. package/src/types.ts +171 -0
  119. package/src/user-metrics.ts +685 -0
  120. package/tailwind.config.js +40 -0
package/src/types.ts ADDED
@@ -0,0 +1,171 @@
1
+ import type { AssistantMessage, ServiceTier, ServiceTierByFamily, StopReason, Usage } from "@oh-my-pi-zen/pi-ai";
2
+ import type { AgentType } from "./shared-types";
3
+
4
+ export * from "./shared-types";
5
+
6
+ /**
7
+ * Extracted stats from an assistant message.
8
+ */
9
+ export interface MessageStats {
10
+ /** Database ID */
11
+ id?: number;
12
+ /** Session file path */
13
+ sessionFile: string;
14
+ /** Entry ID within the session */
15
+ entryId: string;
16
+ /** Folder/project path (extracted from session filename) */
17
+ folder: string;
18
+ /** Model ID */
19
+ model: string;
20
+ /** Provider name */
21
+ provider: string;
22
+ /** API type */
23
+ api: string;
24
+ /** Unix timestamp in milliseconds */
25
+ timestamp: number;
26
+ /** Request duration in milliseconds */
27
+ duration: number | null;
28
+ /** Time to first token in milliseconds */
29
+ ttft: number | null;
30
+ /** Stop reason */
31
+ stopReason: StopReason;
32
+ /** Error message if stopReason is error */
33
+ errorMessage: string | null;
34
+ /** Token usage */
35
+ usage: Usage;
36
+ /** Which agent produced this message (main agent, task subagent, advisor) */
37
+ agentType: AgentType;
38
+ }
39
+
40
+ /**
41
+ * Full details of a request, including content.
42
+ */
43
+ export interface RequestDetails extends MessageStats {
44
+ /** The full conversation history or just the last turn. */
45
+ messages: unknown[];
46
+ /** The model's response. */
47
+ output: unknown;
48
+ }
49
+
50
+ /**
51
+ * Session log entry types.
52
+ */
53
+ export interface SessionHeader {
54
+ type: "session";
55
+ version: number;
56
+ id: string;
57
+ timestamp: string;
58
+ cwd: string;
59
+ title?: string;
60
+ }
61
+
62
+ export interface SessionMessageEntry {
63
+ type: "message";
64
+ id: string;
65
+ parentId: string | null;
66
+ timestamp: string;
67
+ message: AssistantMessage | { role: "user" | "toolResult" };
68
+ }
69
+
70
+ export interface SessionServiceTierChangeEntry {
71
+ type: "service_tier_change";
72
+ id: string;
73
+ parentId?: string | null;
74
+ timestamp: string;
75
+ serviceTier: ServiceTierByFamily | ServiceTier | null;
76
+ }
77
+
78
+ export type SessionEntry = SessionHeader | SessionMessageEntry | SessionServiceTierChangeEntry | { type: string };
79
+
80
+ /**
81
+ * Behavioral stats extracted from a single user message.
82
+ */
83
+ export interface UserMessageStats {
84
+ /** Database ID */
85
+ id?: number;
86
+ /** Session file path */
87
+ sessionFile: string;
88
+ /** Entry ID within the session */
89
+ entryId: string;
90
+ /** Folder/project path */
91
+ folder: string;
92
+ /** Unix timestamp in ms */
93
+ timestamp: number;
94
+ /** Model that responded to this user message, if linked */
95
+ model: string | null;
96
+ /** Provider that responded to this user message, if linked */
97
+ provider: string | null;
98
+ /** Total characters of message text */
99
+ chars: number;
100
+ /** Whitespace-delimited word count */
101
+ words: number;
102
+ /** Yelling sentences (> 50% uppercase letters) */
103
+ yelling: number;
104
+ /** Profanity hits */
105
+ profanity: number;
106
+ /** Catch-all upset signal: drama runs + `noooo`/`ughh`/... + `dude` + `..` */
107
+ anguish: number;
108
+ /** Corrective negation ("no", "nope", "thats not what i meant") */
109
+ negation: number;
110
+ /** User repeating themselves ("i meant", "still doesnt work", "like i said") */
111
+ repetition: number;
112
+ /** Second-person reproach ("you didnt", "you broke", "stop X-ing") */
113
+ blame: number;
114
+ }
115
+
116
+ /**
117
+ * Pair emitted by the parser when it sees an assistant message whose
118
+ * `parentId` points to a user message that wasn't parsed in the same pass
119
+ * (e.g. user prompt landed in an earlier incremental sync). The aggregator
120
+ * applies the link to the persisted `user_messages` row so it stops showing
121
+ * up in the "unknown" model bucket.
122
+ */
123
+ export interface UserMessageLink {
124
+ sessionFile: string;
125
+ entryId: string;
126
+ model: string;
127
+ provider: string;
128
+ }
129
+
130
+ /**
131
+ * One tool call extracted from an assistant message's `toolCall` content
132
+ * blocks. `callsInTurn` records how many calls that assistant turn contained
133
+ * so aggregation can split the turn's real provider usage evenly per call.
134
+ */
135
+ export interface ToolCallStats {
136
+ /** Session file path */
137
+ sessionFile: string;
138
+ /** Assistant-message entry ID that emitted the call */
139
+ entryId: string;
140
+ /** Provider-assigned tool call ID (unique within a session) */
141
+ toolCallId: string;
142
+ /** Folder/project path (extracted from session filename) */
143
+ folder: string;
144
+ /** Tool name */
145
+ toolName: string;
146
+ /** Model that emitted the call */
147
+ model: string;
148
+ /** Provider name */
149
+ provider: string;
150
+ /** Assistant-message timestamp (Unix ms) */
151
+ timestamp: number;
152
+ /** Which agent produced the call */
153
+ agentType: AgentType;
154
+ /** Total tool calls in the same assistant turn (>= 1) */
155
+ callsInTurn: number;
156
+ /** Serialized argument characters */
157
+ argsChars: number;
158
+ }
159
+
160
+ /**
161
+ * Result linkage emitted when the parser sees a `toolResult` message entry.
162
+ * Applied as an UPDATE on the persisted tool-call row — results can land in a
163
+ * later incremental sync pass than the call that produced them.
164
+ */
165
+ export interface ToolResultLink {
166
+ sessionFile: string;
167
+ toolCallId: string;
168
+ /** Text characters fed back into context */
169
+ resultChars: number;
170
+ isError: boolean;
171
+ }