@kb-labs/studio-app 0.6.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.
Files changed (168) hide show
  1. package/.env.example +10 -0
  2. package/README.md +74 -0
  3. package/UI-KIT-COMPONENTS.md +783 -0
  4. package/UI-KIT-PLAN.md +326 -0
  5. package/eslint-rules/no-direct-antd-import.js +151 -0
  6. package/eslint.config.ts +27 -0
  7. package/index.html +17 -0
  8. package/package.json +72 -0
  9. package/postcss.config.js +7 -0
  10. package/public/favicon.ico +0 -0
  11. package/public/favicon.svg +7 -0
  12. package/rspack.config.mjs +118 -0
  13. package/src/App.tsx +46 -0
  14. package/src/components/devtools/devtools-log-feed.module.css +165 -0
  15. package/src/components/devtools/devtools-log-feed.tsx +300 -0
  16. package/src/components/devtools/devtools-panel.module.css +121 -0
  17. package/src/components/devtools/devtools-panel.tsx +115 -0
  18. package/src/components/empty-state.tsx +28 -0
  19. package/src/components/error-boundary.tsx +210 -0
  20. package/src/components/health-banner.module.css +103 -0
  21. package/src/components/health-banner.tsx +134 -0
  22. package/src/components/health-indicator.tsx +12 -0
  23. package/src/components/page-header.tsx +49 -0
  24. package/src/components/page-transition.tsx +24 -0
  25. package/src/components/role-switcher.tsx +148 -0
  26. package/src/components/run-badge.tsx +13 -0
  27. package/src/components/ui/icons.tsx +509 -0
  28. package/src/components/ui/index.ts +25 -0
  29. package/src/components/ui/kb-config-provider.tsx +130 -0
  30. package/src/components/ui/kb-header.module.css +51 -0
  31. package/src/components/ui/kb-header.tsx +112 -0
  32. package/src/components/ui/kb-notification-bell.module.css +103 -0
  33. package/src/components/ui/kb-notification-bell.tsx +199 -0
  34. package/src/components/ui/kb-page-layout.tsx +66 -0
  35. package/src/components/ui/kb-quick-search.module.css +86 -0
  36. package/src/components/ui/kb-quick-search.tsx +196 -0
  37. package/src/components/ui/kb-sidebar.module.css +47 -0
  38. package/src/components/ui/kb-sidebar.tsx +196 -0
  39. package/src/components/ui/kb-stat-card.module.css +21 -0
  40. package/src/components/ui/kb-stat-card.tsx +22 -0
  41. package/src/components/ui/kb-stat-grid.tsx +22 -0
  42. package/src/components/ui/kb-status-bar.module.css +49 -0
  43. package/src/components/ui/kb-status-bar.tsx +145 -0
  44. package/src/components/ui/kb-system-health-indicator.tsx +229 -0
  45. package/src/components/ui/kb-theme-toggle.tsx +42 -0
  46. package/src/components/ui/theme-adapter.ts +812 -0
  47. package/src/components/ui/theme-transition-overlay.tsx +70 -0
  48. package/src/components/ui/utils.ts +6 -0
  49. package/src/components/widget-error-boundary.tsx +172 -0
  50. package/src/config/env.ts +5 -0
  51. package/src/config/feature-flags.ts +482 -0
  52. package/src/config/studio.config.schema.ts +88 -0
  53. package/src/config/studio.config.ts +84 -0
  54. package/src/env.d.ts +23 -0
  55. package/src/hooks/use-command-palette.ts +6 -0
  56. package/src/hooks/use-devtools-store.ts +25 -0
  57. package/src/hooks/use-feature-flags.ts +101 -0
  58. package/src/index.css +10 -0
  59. package/src/layouts/dashboard-grid.tsx +122 -0
  60. package/src/layouts/index.ts +12 -0
  61. package/src/layouts/two-pane.tsx +134 -0
  62. package/src/main.tsx +15 -0
  63. package/src/modules/analytics/components/analytics-daily-stats-chart.tsx +257 -0
  64. package/src/modules/analytics/components/analytics-date-range-picker.tsx +121 -0
  65. package/src/modules/analytics/pages/analytics-cache-page.tsx +285 -0
  66. package/src/modules/analytics/pages/analytics-embeddings-page.tsx +274 -0
  67. package/src/modules/analytics/pages/analytics-events-page.tsx +425 -0
  68. package/src/modules/analytics/pages/analytics-llm-page.tsx +434 -0
  69. package/src/modules/analytics/pages/analytics-overview-page.tsx +336 -0
  70. package/src/modules/analytics/pages/analytics-page.tsx +20 -0
  71. package/src/modules/analytics/pages/analytics-storage-page.tsx +344 -0
  72. package/src/modules/analytics/pages/analytics-vectorstore-page.tsx +279 -0
  73. package/src/modules/analytics/routes/index.tsx +133 -0
  74. package/src/modules/analytics/utils/formatters.test.ts +148 -0
  75. package/src/modules/analytics/utils/formatters.ts +100 -0
  76. package/src/modules/auth/pages/login-page.module.css +113 -0
  77. package/src/modules/auth/pages/login-page.tsx +80 -0
  78. package/src/modules/auth/routes/index.tsx +24 -0
  79. package/src/modules/dashboard/components/ActivityTimelineWidget.tsx +199 -0
  80. package/src/modules/dashboard/components/AiInsightsWidget.tsx +358 -0
  81. package/src/modules/dashboard/components/AnimatedMetricCard.css +88 -0
  82. package/src/modules/dashboard/components/AnimatedMetricCard.tsx +125 -0
  83. package/src/modules/dashboard/components/HeroMetricCard.css +114 -0
  84. package/src/modules/dashboard/components/HeroMetricCard.tsx +152 -0
  85. package/src/modules/dashboard/components/HeroMetricsWidget.tsx +146 -0
  86. package/src/modules/dashboard/components/SystemResourcesWidget.tsx +197 -0
  87. package/src/modules/dashboard/components/dashboard-empty.tsx +22 -0
  88. package/src/modules/dashboard/components/dashboard-kpis-widget.tsx +59 -0
  89. package/src/modules/dashboard/components/dashboard-kpis.tsx +13 -0
  90. package/src/modules/dashboard/components/dashboard-latency-percentiles-widget.tsx +85 -0
  91. package/src/modules/dashboard/components/dashboard-metrics-widget.tsx +78 -0
  92. package/src/modules/dashboard/components/dashboard-plugins-widget.tsx +67 -0
  93. package/src/modules/dashboard/components/dashboard-requests-widget.tsx +62 -0
  94. package/src/modules/dashboard/layouts/dashboard-layout.tsx +16 -0
  95. package/src/modules/dashboard/pages/ai-insights-page.tsx +563 -0
  96. package/src/modules/dashboard/pages/dashboard-animations.css +317 -0
  97. package/src/modules/dashboard/pages/dashboard-page.tsx +13 -0
  98. package/src/modules/dashboard/routes/index.tsx +70 -0
  99. package/src/modules/observability/pages/devkit-page.tsx +263 -0
  100. package/src/modules/observability/pages/incident-detail-page.tsx +571 -0
  101. package/src/modules/observability/pages/incidents-page.tsx +370 -0
  102. package/src/modules/observability/pages/log-detail-page.tsx +508 -0
  103. package/src/modules/observability/pages/logs-page.tsx +1129 -0
  104. package/src/modules/observability/pages/prometheus-metrics-page.tsx +486 -0
  105. package/src/modules/observability/pages/state-broker-page.tsx +229 -0
  106. package/src/modules/observability/pages/system-events-page.tsx +255 -0
  107. package/src/modules/observability/routes/index.tsx +133 -0
  108. package/src/modules/plugins/components/marketplace-card.tsx +153 -0
  109. package/src/modules/plugins/components/plugin-ai-assistant-modal.tsx +374 -0
  110. package/src/modules/plugins/components/plugin-card.tsx +136 -0
  111. package/src/modules/plugins/components/plugin-detail/capabilities-summary.tsx +101 -0
  112. package/src/modules/plugins/components/plugin-detail/cli-commands-table.tsx +101 -0
  113. package/src/modules/plugins/components/plugin-detail/index.ts +7 -0
  114. package/src/modules/plugins/components/plugin-detail/jobs-table.tsx +64 -0
  115. package/src/modules/plugins/components/plugin-detail/permissions/env-permissions.tsx +30 -0
  116. package/src/modules/plugins/components/plugin-detail/permissions/filesystem-permissions.tsx +68 -0
  117. package/src/modules/plugins/components/plugin-detail/permissions/index.ts +6 -0
  118. package/src/modules/plugins/components/plugin-detail/permissions/network-permissions.tsx +43 -0
  119. package/src/modules/plugins/components/plugin-detail/permissions/platform-services.tsx +242 -0
  120. package/src/modules/plugins/components/plugin-detail/permissions/resource-quotas.tsx +96 -0
  121. package/src/modules/plugins/components/plugin-detail/permissions/shell-permissions.tsx +55 -0
  122. package/src/modules/plugins/components/plugin-detail/permissions-view.tsx +47 -0
  123. package/src/modules/plugins/components/plugin-detail/plugin-header.tsx +169 -0
  124. package/src/modules/plugins/components/plugin-detail/rest-routes-table.tsx +159 -0
  125. package/src/modules/plugins/components/plugin-detail/workflows-table.tsx +40 -0
  126. package/src/modules/plugins/components/plugin-grid.tsx +20 -0
  127. package/src/modules/plugins/components/plugin-table.tsx +178 -0
  128. package/src/modules/plugins/pages/marketplace-page.tsx +200 -0
  129. package/src/modules/plugins/pages/plugin-detail-page.tsx +1145 -0
  130. package/src/modules/plugins/routes/index.tsx +48 -0
  131. package/src/modules/plugins/utils/index.ts +1 -0
  132. package/src/modules/plugins/utils/schema-helpers.ts +21 -0
  133. package/src/modules/settings/components/api-routes-viewer.tsx +415 -0
  134. package/src/modules/settings/components/appearance-settings.tsx +200 -0
  135. package/src/modules/settings/components/configuration-settings.tsx +321 -0
  136. package/src/modules/settings/components/data-privacy-settings.tsx +111 -0
  137. package/src/modules/settings/components/experimental-settings.tsx +243 -0
  138. package/src/modules/settings/components/navigation-settings.tsx +198 -0
  139. package/src/modules/settings/components/notifications-settings.tsx +40 -0
  140. package/src/modules/settings/pages/settings-page.tsx +298 -0
  141. package/src/modules/settings/routes/index.tsx +47 -0
  142. package/src/pages/README-assistant.md +91 -0
  143. package/src/pages/login-page.tsx +177 -0
  144. package/src/pages/not-found-page.tsx +85 -0
  145. package/src/providers/auth-provider.tsx +40 -0
  146. package/src/providers/command-palette-provider.tsx +193 -0
  147. package/src/providers/data-sources-provider.tsx +27 -0
  148. package/src/providers/devtools-provider.tsx +72 -0
  149. package/src/providers/navigation-items-provider.tsx +38 -0
  150. package/src/providers/registry-v2-provider.tsx +93 -0
  151. package/src/providers/settings-provider.tsx +158 -0
  152. package/src/router.tsx +302 -0
  153. package/src/routes/helpers.tsx +25 -0
  154. package/src/routes/plugin-page-v2.tsx +52 -0
  155. package/src/routes/types.ts +18 -0
  156. package/src/styles/antd-overrides.css +211 -0
  157. package/src/styles/base.css +190 -0
  158. package/src/styles/settings.css +75 -0
  159. package/src/styles/variables.css +94 -0
  160. package/src/utils/analytics.ts +183 -0
  161. package/src/utils/apply-navigation-categories.ts +83 -0
  162. package/src/utils/commands.ts +252 -0
  163. package/src/utils/export.ts +174 -0
  164. package/src/utils/format-date.ts +166 -0
  165. package/src/utils/logger.ts +110 -0
  166. package/tailwind.config.ts +13 -0
  167. package/tsconfig.json +13 -0
  168. package/vitest-setup.ts +1 -0
@@ -0,0 +1,336 @@
1
+ import { UIRow, UICol, UIStatistic, UIAlert, UISpace, useUITheme } from '@kb-labs/studio-ui-kit';
2
+ import {
3
+ ThunderboltOutlined,
4
+ DatabaseOutlined,
5
+ CloudOutlined,
6
+ RocketOutlined,
7
+ RobotOutlined,
8
+ FileTextOutlined,
9
+ SaveOutlined,
10
+ ArrowRightOutlined,
11
+ DollarOutlined,
12
+ } from '@ant-design/icons';
13
+ import { UIText, UITitle, UICard, UIPage, UIPageHeader } from '@kb-labs/studio-ui-kit';
14
+ import {
15
+ useAnalyticsStats,
16
+ useAdaptersLLMUsage,
17
+ useAdaptersEmbeddingsUsage,
18
+ useAdaptersVectorStoreUsage,
19
+ useAdaptersCacheUsage,
20
+ useAdaptersStorageUsage,
21
+ } from '@kb-labs/studio-data-client';
22
+ import { useDataSources } from '../../../providers/data-sources-provider';
23
+ import { useNavigate } from 'react-router-dom';
24
+
25
+
26
+ /**
27
+ * Analytics Overview Page
28
+ *
29
+ * High-level dashboard showing metrics across all platform adapters:
30
+ * - Total events tracked
31
+ * - Adapter health status
32
+ * - Quick links to detailed views (LLM, Cache, Events, etc.)
33
+ */
34
+ export function AnalyticsOverviewPage() {
35
+ const { token } = useUITheme();
36
+ const sources = useDataSources();
37
+ const navigate = useNavigate();
38
+
39
+ const {
40
+ data: statsData,
41
+ isLoading: statsLoading,
42
+ error: statsError,
43
+ isError: isStatsError,
44
+ } = useAnalyticsStats(sources.analytics);
45
+
46
+ // Fetch all adapter stats
47
+ const { data: llmStats } = useAdaptersLLMUsage(sources.adapters);
48
+ const { data: embeddingsStats } = useAdaptersEmbeddingsUsage(sources.adapters);
49
+ const { data: vectorstoreStats } = useAdaptersVectorStoreUsage(sources.adapters);
50
+ const { data: cacheStats } = useAdaptersCacheUsage(sources.adapters);
51
+ const { data: storageStats } = useAdaptersStorageUsage(sources.adapters);
52
+
53
+ // Check if analytics is not configured
54
+ const analyticsNotConfigured =
55
+ isStatsError &&
56
+ statsError instanceof Error &&
57
+ statsError.message.includes('not support');
58
+
59
+ if (analyticsNotConfigured) {
60
+ return (
61
+ <UIPage>
62
+ <UIPageHeader
63
+ title="Analytics"
64
+ description="Platform-wide analytics and adapter metrics"
65
+ />
66
+ <UIAlert
67
+ message="Analytics Not Configured"
68
+ description="Analytics adapter is not configured. Configure an analytics adapter in kb.config.json to track events and metrics."
69
+ variant="info"
70
+ showIcon
71
+ style={{ marginTop: 16 }}
72
+ />
73
+ </UIPage>
74
+ );
75
+ }
76
+
77
+ if (isStatsError) {
78
+ return (
79
+ <UIPage>
80
+ <UIPageHeader title="Analytics" description="Platform-wide analytics" />
81
+ <UIAlert
82
+ message="Failed to Load Analytics"
83
+ description={statsError?.message || 'Unknown error occurred'}
84
+ variant="error"
85
+ showIcon
86
+ style={{ marginTop: 16 }}
87
+ />
88
+ </UIPage>
89
+ );
90
+ }
91
+
92
+ return (
93
+ <UIPage width="full">
94
+ <UIPageHeader
95
+ title="Analytics Overview"
96
+ description="High-level metrics across all platform adapters"
97
+ />
98
+
99
+ <div style={{ marginTop: 24 }}>
100
+ {/* Overview Stats */}
101
+ <UIRow gutter={[16, 16]}>
102
+ <UICol xs={24} sm={12} lg={6}>
103
+ <UICard>
104
+ <UIStatistic
105
+ title="Total Events"
106
+ value={statsData?.totalEvents ?? 0}
107
+ loading={statsLoading}
108
+ prefix={<ThunderboltOutlined />}
109
+ valueStyle={{ color: 'var(--info)' }}
110
+ />
111
+ </UICard>
112
+ </UICol>
113
+ <UICol xs={24} sm={12} lg={6}>
114
+ <UICard>
115
+ <UIStatistic
116
+ title="Event Types"
117
+ value={statsData ? Object.keys(statsData.byType).length : 0}
118
+ loading={statsLoading}
119
+ prefix={<DatabaseOutlined />}
120
+ valueStyle={{ color: 'var(--success)' }}
121
+ />
122
+ </UICard>
123
+ </UICol>
124
+ <UICol xs={24} sm={12} lg={6}>
125
+ <UICard>
126
+ <UIStatistic
127
+ title="Sources"
128
+ value={statsData ? Object.keys(statsData.bySource).length : 0}
129
+ loading={statsLoading}
130
+ prefix={<CloudOutlined />}
131
+ valueStyle={{ color: 'var(--link)' }}
132
+ />
133
+ </UICard>
134
+ </UICol>
135
+ <UICol xs={24} sm={12} lg={6}>
136
+ <UICard>
137
+ <UIStatistic
138
+ title="Actors"
139
+ value={statsData ? Object.keys(statsData.byActor).length : 0}
140
+ loading={statsLoading}
141
+ prefix={<RocketOutlined />}
142
+ valueStyle={{ color: 'var(--warning)' }}
143
+ />
144
+ </UICard>
145
+ </UICol>
146
+ </UIRow>
147
+
148
+ {/* Platform Adapters */}
149
+ <div style={{ marginTop: 32 }}>
150
+ <UITitle level={4}>Platform Adapters</UITitle>
151
+ <UIRow gutter={[16, 16]} style={{ marginTop: 16 }}>
152
+ {/* LLM Adapter */}
153
+ <UICol xs={24} md={12} lg={8}>
154
+ <UICard
155
+ hoverable
156
+ onClick={() => navigate('/analytics/llm')}
157
+ style={{ cursor: 'pointer' }}
158
+ >
159
+ <UISpace direction="vertical" style={{ width: '100%' }} size="large">
160
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
161
+ <UISpace>
162
+ <RobotOutlined style={{ fontSize: 24, color: 'var(--info)' }} />
163
+ <UIText weight="semibold" style={{ fontSize: 16 }}>LLM Usage</UIText>
164
+ </UISpace>
165
+ <ArrowRightOutlined style={{ color: token.colorTextTertiary }} />
166
+ </div>
167
+ <UIRow gutter={16}>
168
+ <UICol span={12}>
169
+ <UIStatistic
170
+ title="Requests"
171
+ value={llmStats?.totalRequests ?? 0}
172
+ valueStyle={{ fontSize: 20 }}
173
+ />
174
+ </UICol>
175
+ <UICol span={12}>
176
+ <UIStatistic
177
+ title="Cost"
178
+ value={llmStats?.totalCost ?? 0}
179
+ prefix={<DollarOutlined />}
180
+ precision={2}
181
+ valueStyle={{ fontSize: 20 }}
182
+ />
183
+ </UICol>
184
+ </UIRow>
185
+ </UISpace>
186
+ </UICard>
187
+ </UICol>
188
+
189
+ {/* Embeddings Adapter */}
190
+ <UICol xs={24} md={12} lg={8}>
191
+ <UICard
192
+ hoverable
193
+ onClick={() => navigate('/analytics/embeddings')}
194
+ style={{ cursor: 'pointer' }}
195
+ >
196
+ <UISpace direction="vertical" style={{ width: '100%' }} size="large">
197
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
198
+ <UISpace>
199
+ <FileTextOutlined style={{ fontSize: 24, color: 'var(--success)' }} />
200
+ <UIText weight="semibold" style={{ fontSize: 16 }}>Embeddings</UIText>
201
+ </UISpace>
202
+ <ArrowRightOutlined style={{ color: token.colorTextTertiary }} />
203
+ </div>
204
+ <UIRow gutter={16}>
205
+ <UICol span={12}>
206
+ <UIStatistic
207
+ title="Requests"
208
+ value={embeddingsStats?.totalRequests ?? 0}
209
+ valueStyle={{ fontSize: 20 }}
210
+ />
211
+ </UICol>
212
+ <UICol span={12}>
213
+ <UIStatistic
214
+ title="Text Chars"
215
+ value={embeddingsStats?.totalTextLength ?? 0}
216
+ valueStyle={{ fontSize: 20 }}
217
+ />
218
+ </UICol>
219
+ </UIRow>
220
+ </UISpace>
221
+ </UICard>
222
+ </UICol>
223
+
224
+ {/* VectorStore Adapter */}
225
+ <UICol xs={24} md={12} lg={8}>
226
+ <UICard
227
+ hoverable
228
+ onClick={() => navigate('/analytics/vectorstore')}
229
+ style={{ cursor: 'pointer' }}
230
+ >
231
+ <UISpace direction="vertical" style={{ width: '100%' }} size="large">
232
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
233
+ <UISpace>
234
+ <DatabaseOutlined style={{ fontSize: 24, color: 'var(--link)' }} />
235
+ <UIText weight="semibold" style={{ fontSize: 16 }}>VectorStore</UIText>
236
+ </UISpace>
237
+ <ArrowRightOutlined style={{ color: token.colorTextTertiary }} />
238
+ </div>
239
+ <UIRow gutter={16}>
240
+ <UICol span={12}>
241
+ <UIStatistic
242
+ title="Searches"
243
+ value={vectorstoreStats?.searchQueries ?? 0}
244
+ valueStyle={{ fontSize: 20 }}
245
+ />
246
+ </UICol>
247
+ <UICol span={12}>
248
+ <UIStatistic
249
+ title="Avg Score"
250
+ value={vectorstoreStats?.avgSearchScore ?? 0}
251
+ precision={2}
252
+ valueStyle={{ fontSize: 20 }}
253
+ />
254
+ </UICol>
255
+ </UIRow>
256
+ </UISpace>
257
+ </UICard>
258
+ </UICol>
259
+
260
+ {/* Cache Adapter */}
261
+ <UICol xs={24} md={12} lg={8}>
262
+ <UICard
263
+ hoverable
264
+ onClick={() => navigate('/analytics/cache')}
265
+ style={{ cursor: 'pointer' }}
266
+ >
267
+ <UISpace direction="vertical" style={{ width: '100%' }} size="large">
268
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
269
+ <UISpace>
270
+ <ThunderboltOutlined style={{ fontSize: 24, color: 'var(--warning)' }} />
271
+ <UIText weight="semibold" style={{ fontSize: 16 }}>Cache</UIText>
272
+ </UISpace>
273
+ <ArrowRightOutlined style={{ color: token.colorTextTertiary }} />
274
+ </div>
275
+ <UIRow gutter={16}>
276
+ <UICol span={12}>
277
+ <UIStatistic
278
+ title="Hit Rate"
279
+ value={cacheStats?.hitRate ?? 0}
280
+ suffix="%"
281
+ precision={1}
282
+ valueStyle={{ fontSize: 20, color: cacheStats && cacheStats.hitRate >= 80 ? 'var(--success)' : 'var(--info)' }}
283
+ />
284
+ </UICol>
285
+ <UICol span={12}>
286
+ <UIStatistic
287
+ title="Total Gets"
288
+ value={cacheStats?.totalGets ?? 0}
289
+ valueStyle={{ fontSize: 20 }}
290
+ />
291
+ </UICol>
292
+ </UIRow>
293
+ </UISpace>
294
+ </UICard>
295
+ </UICol>
296
+
297
+ {/* Storage Adapter */}
298
+ <UICol xs={24} md={12} lg={8}>
299
+ <UICard
300
+ hoverable
301
+ onClick={() => navigate('/analytics/storage')}
302
+ style={{ cursor: 'pointer' }}
303
+ >
304
+ <UISpace direction="vertical" style={{ width: '100%' }} size="large">
305
+ <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
306
+ <UISpace>
307
+ <SaveOutlined style={{ fontSize: 24, color: 'var(--error)' }} />
308
+ <UIText weight="semibold" style={{ fontSize: 16 }}>Storage</UIText>
309
+ </UISpace>
310
+ <ArrowRightOutlined style={{ color: token.colorTextTertiary }} />
311
+ </div>
312
+ <UIRow gutter={16}>
313
+ <UICol span={12}>
314
+ <UIStatistic
315
+ title="Reads"
316
+ value={storageStats?.readOperations ?? 0}
317
+ valueStyle={{ fontSize: 20 }}
318
+ />
319
+ </UICol>
320
+ <UICol span={12}>
321
+ <UIStatistic
322
+ title="Writes"
323
+ value={storageStats?.writeOperations ?? 0}
324
+ valueStyle={{ fontSize: 20 }}
325
+ />
326
+ </UICol>
327
+ </UIRow>
328
+ </UISpace>
329
+ </UICard>
330
+ </UICol>
331
+ </UIRow>
332
+ </div>
333
+ </div>
334
+ </UIPage>
335
+ );
336
+ }
@@ -0,0 +1,20 @@
1
+ import { EmptyState } from '@/components/empty-state';
2
+ import { BarChart3 } from 'lucide-react';
3
+ import { UIPage, UIPageHeader } from '@kb-labs/studio-ui-kit';
4
+
5
+ export function AnalyticsPage() {
6
+ return (
7
+ <UIPage width="full">
8
+ <UIPageHeader
9
+ title="Analytics"
10
+ description="Event metrics and performance charts"
11
+ />
12
+ <EmptyState
13
+ icon={<BarChart3 size={32} />}
14
+ title="Coming Soon"
15
+ description="Event metrics and performance charts will appear here."
16
+ />
17
+ </UIPage>
18
+ );
19
+ }
20
+
@@ -0,0 +1,344 @@
1
+ import { useState } from 'react';
2
+ import { UIRow, UICol, UIStatistic, UIAlert } from '@kb-labs/studio-ui-kit';
3
+ import {
4
+ FileOutlined,
5
+ UploadOutlined,
6
+ DownloadOutlined,
7
+ DeleteOutlined,
8
+ ClockCircleOutlined,
9
+ DatabaseOutlined,
10
+ } from '@ant-design/icons';
11
+ import { UIText, UIStatisticsChart, UICard, UIPage, UIPageHeader } from '@kb-labs/studio-ui-kit';
12
+ import { useAdaptersStorageUsage, useAdaptersStorageDailyStats } from '@kb-labs/studio-data-client';
13
+ import { useDataSources } from '../../../providers/data-sources-provider';
14
+ import { AnalyticsDateRangePicker, type DateRangeValue } from '../components/analytics-date-range-picker';
15
+ import dayjs from 'dayjs';
16
+
17
+
18
+ /**
19
+ * Analytics Storage Usage Page
20
+ *
21
+ * Displays storage usage statistics:
22
+ * - Read/write/delete operations
23
+ * - Bandwidth usage tracking
24
+ * - Performance metrics
25
+ */
26
+ export function AnalyticsStoragePage() {
27
+ const sources = useDataSources();
28
+
29
+ // Date range state (default: last 30 days)
30
+ const [dateRange, setDateRange] = useState<DateRangeValue>([
31
+ dayjs().subtract(30, 'days'),
32
+ dayjs(),
33
+ ]);
34
+
35
+ const {
36
+ data: stats,
37
+ isLoading,
38
+ error,
39
+ isError,
40
+ } = useAdaptersStorageUsage(sources.adapters, {
41
+ from: dateRange[0].toISOString(),
42
+ to: dateRange[1].toISOString(),
43
+ });
44
+
45
+ const {
46
+ data: dailyStats,
47
+ isLoading: dailyStatsLoading,
48
+ } = useAdaptersStorageDailyStats(sources.adapters, {
49
+ from: dateRange[0].toISOString(),
50
+ to: dateRange[1].toISOString(),
51
+ });
52
+
53
+ // Check if analytics is not implemented
54
+ const analyticsNotImplemented =
55
+ isError &&
56
+ error instanceof Error &&
57
+ (error.message.includes('not support') || error.message.includes('not implement'));
58
+
59
+ if (analyticsNotImplemented) {
60
+ return (
61
+ <UIPage>
62
+ <UIPageHeader
63
+ title="Storage Usage"
64
+ description="Track storage operations and bandwidth usage"
65
+ />
66
+ <UIAlert
67
+ message="Analytics Not Available"
68
+ description="Analytics adapter does not support reading events. Configure an analytics adapter in kb.config.json that implements getEvents()."
69
+ variant="info"
70
+ showIcon
71
+ style={{ marginTop: 16 }}
72
+ />
73
+ </UIPage>
74
+ );
75
+ }
76
+
77
+ if (isError) {
78
+ return (
79
+ <UIPage>
80
+ <UIPageHeader title="Storage Usage" description="Storage usage analytics" />
81
+ <UIAlert
82
+ message="Failed to Load Storage Usage"
83
+ description={error?.message || 'Unknown error occurred'}
84
+ variant="error"
85
+ showIcon
86
+ style={{ marginTop: 16 }}
87
+ />
88
+ </UIPage>
89
+ );
90
+ }
91
+
92
+ // Format helpers
93
+ const _formatNumber = (num: number) => num.toLocaleString();
94
+ const formatSize = (bytes: number) => {
95
+ if (bytes < 1024) {return `${bytes} B`;}
96
+ if (bytes < 1024 * 1024) {return `${(bytes / 1024).toFixed(2)} KB`;}
97
+ if (bytes < 1024 * 1024 * 1024) {return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;}
98
+ return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
99
+ };
100
+ const _formatDuration = (ms: number) => (ms < 1000 ? `${ms.toFixed(1)}ms` : `${(ms / 1000).toFixed(2)}s`);
101
+
102
+ const totalOperations = stats
103
+ ? stats.readOperations + stats.writeOperations + stats.deleteOperations
104
+ : 0;
105
+
106
+ const readPercentage = stats && totalOperations > 0
107
+ ? ((stats.readOperations / totalOperations) * 100).toFixed(1)
108
+ : 0;
109
+
110
+ const writePercentage = stats && totalOperations > 0
111
+ ? ((stats.writeOperations / totalOperations) * 100).toFixed(1)
112
+ : 0;
113
+
114
+ return (
115
+ <UIPage width="full">
116
+ <UIPageHeader
117
+ title="Storage Usage Analytics"
118
+ description="Track storage operations, bandwidth usage, and file I/O performance"
119
+ actions={
120
+ <AnalyticsDateRangePicker
121
+ value={dateRange}
122
+ onChange={setDateRange}
123
+ />
124
+ }
125
+ />
126
+
127
+ <div style={{ marginTop: 24 }}>
128
+ {/* Operations Overview */}
129
+ <UIRow gutter={[16, 16]}>
130
+ <UICol xs={24} sm={12} lg={6}>
131
+ <UICard>
132
+ <UIStatistic
133
+ title="Read Operations"
134
+ value={stats?.readOperations ?? 0}
135
+ prefix={<DownloadOutlined />}
136
+ loading={isLoading}
137
+ valueStyle={{ color: 'var(--info)' }}
138
+ />
139
+ </UICard>
140
+ </UICol>
141
+ <UICol xs={24} sm={12} lg={6}>
142
+ <UICard>
143
+ <UIStatistic
144
+ title="Write Operations"
145
+ value={stats?.writeOperations ?? 0}
146
+ prefix={<UploadOutlined />}
147
+ loading={isLoading}
148
+ valueStyle={{ color: 'var(--success)' }}
149
+ />
150
+ </UICard>
151
+ </UICol>
152
+ <UICol xs={24} sm={12} lg={6}>
153
+ <UICard>
154
+ <UIStatistic
155
+ title="Delete Operations"
156
+ value={stats?.deleteOperations ?? 0}
157
+ prefix={<DeleteOutlined />}
158
+ loading={isLoading}
159
+ valueStyle={{ color: 'var(--error)' }}
160
+ />
161
+ </UICard>
162
+ </UICol>
163
+ <UICol xs={24} sm={12} lg={6}>
164
+ <UICard>
165
+ <UIStatistic
166
+ title="Total Operations"
167
+ value={totalOperations}
168
+ prefix={<FileOutlined />}
169
+ loading={isLoading}
170
+ valueStyle={{ color: 'var(--link)' }}
171
+ />
172
+ </UICard>
173
+ </UICol>
174
+ </UIRow>
175
+
176
+ {/* Bandwidth Usage */}
177
+ <UIRow gutter={[16, 16]} style={{ marginTop: 16 }}>
178
+ <UICol xs={24} lg={12}>
179
+ <UICard title="Bandwidth Usage">
180
+ <UIRow gutter={[16, 16]}>
181
+ <UICol span={12}>
182
+ <UIStatistic
183
+ title="Total Read"
184
+ value={formatSize(stats?.totalBytesRead ?? 0)}
185
+ prefix={<DownloadOutlined />}
186
+ loading={isLoading}
187
+ valueStyle={{ color: 'var(--info)' }}
188
+ />
189
+ </UICol>
190
+ <UICol span={12}>
191
+ <UIStatistic
192
+ title="Total Written"
193
+ value={formatSize(stats?.totalBytesWritten ?? 0)}
194
+ prefix={<UploadOutlined />}
195
+ loading={isLoading}
196
+ valueStyle={{ color: 'var(--success)' }}
197
+ />
198
+ </UICol>
199
+ </UIRow>
200
+ <div style={{ marginTop: 16 }}>
201
+ <UIStatistic
202
+ title="Total Bandwidth"
203
+ value={formatSize((stats?.totalBytesRead ?? 0) + (stats?.totalBytesWritten ?? 0))}
204
+ prefix={<DatabaseOutlined />}
205
+ loading={isLoading}
206
+ valueStyle={{ color: 'var(--link)' }}
207
+ />
208
+ </div>
209
+ </UICard>
210
+ </UICol>
211
+ <UICol xs={24} lg={12}>
212
+ <UICard title="Performance Metrics">
213
+ <UIRow gutter={[16, 16]}>
214
+ <UICol span={12}>
215
+ <UIStatistic
216
+ title="Avg Read Duration"
217
+ value={stats?.avgReadDuration ?? 0}
218
+ prefix={<ClockCircleOutlined />}
219
+ suffix="ms"
220
+ precision={1}
221
+ loading={isLoading}
222
+ />
223
+ </UICol>
224
+ <UICol span={12}>
225
+ <UIStatistic
226
+ title="Avg Write Duration"
227
+ value={stats?.avgWriteDuration ?? 0}
228
+ prefix={<ClockCircleOutlined />}
229
+ suffix="ms"
230
+ precision={1}
231
+ loading={isLoading}
232
+ />
233
+ </UICol>
234
+ </UIRow>
235
+ </UICard>
236
+ </UICol>
237
+ </UIRow>
238
+
239
+ {/* Operation Statistics */}
240
+ {stats && totalOperations > 0 && (
241
+ <UICard title="Operation Statistics" style={{ marginTop: 16 }}>
242
+ <UIRow gutter={[16, 16]}>
243
+ <UICol xs={24} sm={8}>
244
+ <UIStatistic
245
+ title="Read Ratio"
246
+ value={Number(readPercentage)}
247
+ suffix="%"
248
+ precision={1}
249
+ loading={isLoading}
250
+ valueStyle={{ color: 'var(--info)' }}
251
+ />
252
+ <UIText color="secondary" style={{ fontSize: 12 }}>
253
+ {readPercentage}% of total operations
254
+ </UIText>
255
+ </UICol>
256
+ <UICol xs={24} sm={8}>
257
+ <UIStatistic
258
+ title="Write Ratio"
259
+ value={Number(writePercentage)}
260
+ suffix="%"
261
+ precision={1}
262
+ loading={isLoading}
263
+ valueStyle={{ color: 'var(--success)' }}
264
+ />
265
+ <UIText color="secondary" style={{ fontSize: 12 }}>
266
+ {writePercentage}% of total operations
267
+ </UIText>
268
+ </UICol>
269
+ <UICol xs={24} sm={8}>
270
+ <UIStatistic
271
+ title="Avg Read Size"
272
+ value={formatSize(stats.totalBytesRead / Math.max(stats.readOperations, 1))}
273
+ loading={isLoading}
274
+ />
275
+ <UIText color="secondary" style={{ fontSize: 12 }}>
276
+ Per read operation
277
+ </UIText>
278
+ </UICol>
279
+ </UIRow>
280
+ <UIRow gutter={[16, 16]} style={{ marginTop: 16 }}>
281
+ <UICol xs={24} sm={8}>
282
+ <UIStatistic
283
+ title="Avg Write Size"
284
+ value={formatSize(stats.totalBytesWritten / Math.max(stats.writeOperations, 1))}
285
+ loading={isLoading}
286
+ />
287
+ <UIText color="secondary" style={{ fontSize: 12 }}>
288
+ Per write operation
289
+ </UIText>
290
+ </UICol>
291
+ <UICol xs={24} sm={8}>
292
+ <UIStatistic
293
+ title="Read Throughput"
294
+ value={
295
+ stats.avgReadDuration > 0
296
+ ? formatSize((stats.totalBytesRead / Math.max(stats.readOperations, 1)) / (stats.avgReadDuration / 1000))
297
+ : '0 B'
298
+ }
299
+ suffix="/s"
300
+ loading={isLoading}
301
+ valueStyle={{ color: 'var(--info)' }}
302
+ />
303
+ </UICol>
304
+ <UICol xs={24} sm={8}>
305
+ <UIStatistic
306
+ title="Write Throughput"
307
+ value={
308
+ stats.avgWriteDuration > 0
309
+ ? formatSize((stats.totalBytesWritten / Math.max(stats.writeOperations, 1)) / (stats.avgWriteDuration / 1000))
310
+ : '0 B'
311
+ }
312
+ suffix="/s"
313
+ loading={isLoading}
314
+ valueStyle={{ color: 'var(--success)' }}
315
+ />
316
+ </UICol>
317
+ </UIRow>
318
+ </UICard>
319
+ )}
320
+
321
+ {/* Daily Usage Chart */}
322
+ <UIStatisticsChart
323
+ data={dailyStats}
324
+ loading={dailyStatsLoading}
325
+ title="Daily Storage Activity"
326
+ metrics={[
327
+ {
328
+ key: 'totalBytesRead',
329
+ label: 'Bytes Read (MB)',
330
+ transform: (v) => Math.floor(v / (1024 * 1024)),
331
+ format: (v) => `${v} MB`,
332
+ },
333
+ {
334
+ key: 'totalBytesWritten',
335
+ label: 'Bytes Written (MB)',
336
+ transform: (v) => Math.floor(v / (1024 * 1024)),
337
+ format: (v) => `${v} MB`,
338
+ },
339
+ ]}
340
+ />
341
+ </div>
342
+ </UIPage>
343
+ );
344
+ }