@contractspec/lib.example-shared-ui 1.11.0 → 1.13.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 (121) hide show
  1. package/.turbo/turbo-build.log +86 -11
  2. package/.turbo/turbo-prebuild.log +1 -0
  3. package/CHANGELOG.md +27 -0
  4. package/dist/EvolutionDashboard.d.ts +11 -0
  5. package/dist/EvolutionDashboard.d.ts.map +1 -0
  6. package/dist/EvolutionDashboard.js +804 -0
  7. package/dist/EvolutionSidebar.d.ts +19 -0
  8. package/dist/EvolutionSidebar.d.ts.map +1 -0
  9. package/dist/EvolutionSidebar.js +532 -0
  10. package/dist/LocalDataIndicator.d.ts +2 -0
  11. package/dist/LocalDataIndicator.d.ts.map +1 -0
  12. package/dist/LocalDataIndicator.js +63 -0
  13. package/dist/MarkdownView.d.ts +20 -0
  14. package/dist/MarkdownView.d.ts.map +1 -0
  15. package/dist/MarkdownView.js +304 -0
  16. package/dist/OverlayContextProvider.d.ts +79 -0
  17. package/dist/OverlayContextProvider.d.ts.map +1 -0
  18. package/dist/OverlayContextProvider.js +203 -0
  19. package/dist/PersonalizationInsights.d.ts +14 -0
  20. package/dist/PersonalizationInsights.d.ts.map +1 -0
  21. package/dist/PersonalizationInsights.js +456 -0
  22. package/dist/SaveToStudioButton.d.ts +8 -0
  23. package/dist/SaveToStudioButton.d.ts.map +1 -0
  24. package/dist/SaveToStudioButton.js +74 -0
  25. package/dist/SpecEditorPanel.d.ts +23 -0
  26. package/dist/SpecEditorPanel.d.ts.map +1 -0
  27. package/dist/SpecEditorPanel.js +720 -0
  28. package/dist/TemplateShell.d.ts +13 -0
  29. package/dist/TemplateShell.d.ts.map +1 -0
  30. package/dist/TemplateShell.js +190 -0
  31. package/dist/browser/EvolutionDashboard.js +803 -0
  32. package/dist/browser/EvolutionSidebar.js +531 -0
  33. package/dist/browser/LocalDataIndicator.js +62 -0
  34. package/dist/browser/MarkdownView.js +303 -0
  35. package/dist/browser/OverlayContextProvider.js +202 -0
  36. package/dist/browser/PersonalizationInsights.js +455 -0
  37. package/dist/browser/SaveToStudioButton.js +73 -0
  38. package/dist/browser/SpecEditorPanel.js +719 -0
  39. package/dist/browser/TemplateShell.js +189 -0
  40. package/dist/browser/hooks/index.js +1516 -0
  41. package/dist/browser/hooks/useBehaviorTracking.js +157 -0
  42. package/dist/browser/hooks/useEvolution.js +260 -0
  43. package/dist/browser/hooks/useRegistryTemplates.js +31 -0
  44. package/dist/browser/hooks/useSpecContent.js +579 -0
  45. package/dist/browser/hooks/useWorkflowComposer.js +493 -0
  46. package/dist/browser/index.js +3497 -0
  47. package/dist/browser/lib/component-registry.js +42 -0
  48. package/dist/browser/lib/runtime-context.js +15 -0
  49. package/dist/browser/lib/types.js +0 -0
  50. package/dist/browser/overlay-types.js +0 -0
  51. package/dist/browser/utils/fetchPresentationData.js +15 -0
  52. package/dist/browser/utils/generateSpecFromTemplate.js +423 -0
  53. package/dist/browser/utils/index.js +437 -0
  54. package/dist/hooks/index.d.ts +6 -0
  55. package/dist/hooks/index.d.ts.map +1 -0
  56. package/dist/hooks/index.js +1517 -0
  57. package/dist/hooks/useBehaviorTracking.d.ts +56 -0
  58. package/dist/hooks/useBehaviorTracking.d.ts.map +1 -0
  59. package/dist/hooks/useBehaviorTracking.js +158 -0
  60. package/dist/hooks/useEvolution.d.ts +111 -0
  61. package/dist/hooks/useEvolution.d.ts.map +1 -0
  62. package/dist/hooks/useEvolution.js +261 -0
  63. package/dist/hooks/useRegistryTemplates.d.ts +10 -0
  64. package/dist/hooks/useRegistryTemplates.d.ts.map +1 -0
  65. package/dist/hooks/useRegistryTemplates.js +32 -0
  66. package/dist/hooks/useSpecContent.d.ts +41 -0
  67. package/dist/hooks/useSpecContent.d.ts.map +1 -0
  68. package/dist/hooks/useSpecContent.js +580 -0
  69. package/dist/hooks/useWorkflowComposer.d.ts +94 -0
  70. package/dist/hooks/useWorkflowComposer.d.ts.map +1 -0
  71. package/dist/hooks/useWorkflowComposer.js +494 -0
  72. package/dist/index.d.ts +16 -0
  73. package/dist/index.d.ts.map +1 -0
  74. package/dist/index.js +3498 -0
  75. package/dist/lib/component-registry.d.ts +18 -0
  76. package/dist/lib/component-registry.d.ts.map +1 -0
  77. package/dist/lib/component-registry.js +43 -0
  78. package/dist/lib/runtime-context.d.ts +29 -0
  79. package/dist/lib/runtime-context.d.ts.map +1 -0
  80. package/dist/lib/runtime-context.js +16 -0
  81. package/dist/lib/types.d.ts +69 -0
  82. package/dist/lib/types.d.ts.map +1 -0
  83. package/dist/lib/types.js +1 -0
  84. package/dist/node/EvolutionDashboard.js +803 -0
  85. package/dist/node/EvolutionSidebar.js +531 -0
  86. package/dist/node/LocalDataIndicator.js +62 -0
  87. package/dist/node/MarkdownView.js +303 -0
  88. package/dist/node/OverlayContextProvider.js +202 -0
  89. package/dist/node/PersonalizationInsights.js +455 -0
  90. package/dist/node/SaveToStudioButton.js +73 -0
  91. package/dist/node/SpecEditorPanel.js +719 -0
  92. package/dist/node/TemplateShell.js +189 -0
  93. package/dist/node/hooks/index.js +1516 -0
  94. package/dist/node/hooks/useBehaviorTracking.js +157 -0
  95. package/dist/node/hooks/useEvolution.js +260 -0
  96. package/dist/node/hooks/useRegistryTemplates.js +31 -0
  97. package/dist/node/hooks/useSpecContent.js +579 -0
  98. package/dist/node/hooks/useWorkflowComposer.js +493 -0
  99. package/dist/node/index.js +3497 -0
  100. package/dist/node/lib/component-registry.js +42 -0
  101. package/dist/node/lib/runtime-context.js +15 -0
  102. package/dist/node/lib/types.js +0 -0
  103. package/dist/node/overlay-types.js +0 -0
  104. package/dist/node/utils/fetchPresentationData.js +15 -0
  105. package/dist/node/utils/generateSpecFromTemplate.js +423 -0
  106. package/dist/node/utils/index.js +437 -0
  107. package/dist/overlay-types.d.ts +41 -0
  108. package/dist/overlay-types.d.ts.map +1 -0
  109. package/dist/overlay-types.js +1 -0
  110. package/dist/utils/fetchPresentationData.d.ts +34 -0
  111. package/dist/utils/fetchPresentationData.d.ts.map +1 -0
  112. package/dist/utils/fetchPresentationData.js +16 -0
  113. package/dist/utils/generateSpecFromTemplate.d.ts +7 -0
  114. package/dist/utils/generateSpecFromTemplate.d.ts.map +1 -0
  115. package/dist/utils/generateSpecFromTemplate.js +424 -0
  116. package/dist/utils/index.d.ts +3 -0
  117. package/dist/utils/index.d.ts.map +1 -0
  118. package/dist/utils/index.js +438 -0
  119. package/package.json +219 -14
  120. package/.turbo/turbo-build$colon$bundle.log +0 -9
  121. package/dist/index.mjs +0 -3121
@@ -0,0 +1,803 @@
1
+ // src/hooks/useEvolution.ts
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
+ "use client";
4
+ var EVOLUTION_STORAGE_KEY = "contractspec-evolution-data";
5
+ function useEvolution(templateId) {
6
+ const [usageStats, setUsageStats] = useState([]);
7
+ const [anomalies, setAnomalies] = useState([]);
8
+ const [suggestions, setSuggestions] = useState([]);
9
+ const [hints, setHints] = useState([]);
10
+ const [loading, setLoading] = useState(false);
11
+ const metricsRef = useRef([]);
12
+ const [operationCount, setOperationCount] = useState(0);
13
+ useEffect(() => {
14
+ try {
15
+ const stored = localStorage.getItem(`${EVOLUTION_STORAGE_KEY}-${templateId}`);
16
+ if (stored) {
17
+ const data = JSON.parse(stored);
18
+ setSuggestions(data.suggestions.map((s) => ({
19
+ ...s,
20
+ createdAt: new Date(s.createdAt)
21
+ })));
22
+ }
23
+ } catch {}
24
+ }, [templateId]);
25
+ useEffect(() => {
26
+ try {
27
+ localStorage.setItem(`${EVOLUTION_STORAGE_KEY}-${templateId}`, JSON.stringify({ suggestions }));
28
+ } catch {}
29
+ }, [suggestions, templateId]);
30
+ const trackOperation = useCallback((operationName, durationMs, success, errorCode) => {
31
+ const sample = {
32
+ operation: {
33
+ name: operationName,
34
+ version: "1.0.0",
35
+ tenantId: "sandbox"
36
+ },
37
+ durationMs,
38
+ success,
39
+ timestamp: new Date,
40
+ errorCode
41
+ };
42
+ metricsRef.current.push(sample);
43
+ setOperationCount((prev) => prev + 1);
44
+ }, []);
45
+ const analyzeUsage = useCallback(() => {
46
+ const samples = metricsRef.current;
47
+ if (samples.length < 5)
48
+ return;
49
+ const groups = new Map;
50
+ for (const sample of samples) {
51
+ const key = `${sample.operation.name}.v${sample.operation.version}`;
52
+ const arr = groups.get(key) ?? [];
53
+ arr.push(sample);
54
+ groups.set(key, arr);
55
+ }
56
+ const stats = [];
57
+ const detectedAnomalies = [];
58
+ groups.forEach((opSamples) => {
59
+ if (opSamples.length < 3)
60
+ return;
61
+ const durations = opSamples.map((s) => s.durationMs).sort((a, b) => a - b);
62
+ const errors = opSamples.filter((s) => !s.success);
63
+ const totalCalls = opSamples.length;
64
+ const errorRate = errors.length / totalCalls;
65
+ const averageLatencyMs = durations.reduce((sum, value) => sum + value, 0) / totalCalls;
66
+ const timestamps = opSamples.map((s) => s.timestamp.getTime());
67
+ const firstSample = opSamples[0];
68
+ if (!firstSample)
69
+ return;
70
+ const stat = {
71
+ operation: firstSample.operation,
72
+ totalCalls,
73
+ successRate: 1 - errorRate,
74
+ errorRate,
75
+ averageLatencyMs,
76
+ p95LatencyMs: percentile(durations, 0.95),
77
+ p99LatencyMs: percentile(durations, 0.99),
78
+ maxLatencyMs: Math.max(...durations),
79
+ lastSeenAt: new Date(Math.max(...timestamps)),
80
+ windowStart: new Date(Math.min(...timestamps)),
81
+ windowEnd: new Date(Math.max(...timestamps)),
82
+ topErrors: errors.reduce((acc, s) => {
83
+ if (s.errorCode) {
84
+ acc[s.errorCode] = (acc[s.errorCode] ?? 0) + 1;
85
+ }
86
+ return acc;
87
+ }, {})
88
+ };
89
+ stats.push(stat);
90
+ if (errorRate > 0.1) {
91
+ detectedAnomalies.push({
92
+ operation: stat.operation,
93
+ severity: errorRate > 0.3 ? "high" : errorRate > 0.2 ? "medium" : "low",
94
+ metric: "error-rate",
95
+ description: `Error rate ${(errorRate * 100).toFixed(1)}% exceeds threshold`,
96
+ detectedAt: new Date,
97
+ threshold: 0.1,
98
+ observedValue: errorRate
99
+ });
100
+ }
101
+ if (stat.p99LatencyMs > 500) {
102
+ detectedAnomalies.push({
103
+ operation: stat.operation,
104
+ severity: stat.p99LatencyMs > 1000 ? "high" : stat.p99LatencyMs > 750 ? "medium" : "low",
105
+ metric: "latency",
106
+ description: `P99 latency ${stat.p99LatencyMs.toFixed(0)}ms exceeds threshold`,
107
+ detectedAt: new Date,
108
+ threshold: 500,
109
+ observedValue: stat.p99LatencyMs
110
+ });
111
+ }
112
+ });
113
+ setUsageStats(stats);
114
+ setAnomalies(detectedAnomalies);
115
+ const newHints = detectedAnomalies.map((anomaly) => ({
116
+ operation: anomaly.operation,
117
+ category: anomaly.metric === "latency" ? "performance" : "error-handling",
118
+ summary: anomaly.metric === "latency" ? "Latency regression detected" : "Error spike detected",
119
+ justification: anomaly.description,
120
+ recommendedActions: anomaly.metric === "latency" ? [
121
+ "Add caching layer",
122
+ "Optimize database queries",
123
+ "Consider pagination"
124
+ ] : [
125
+ "Add retry logic",
126
+ "Improve error handling",
127
+ "Add circuit breaker"
128
+ ]
129
+ }));
130
+ setHints(newHints);
131
+ }, []);
132
+ const generateSuggestions = useCallback(async () => {
133
+ if (anomalies.length === 0)
134
+ return;
135
+ setLoading(true);
136
+ await new Promise((resolve) => setTimeout(resolve, 800));
137
+ const newSuggestions = anomalies.map((anomaly) => ({
138
+ id: `suggestion-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
139
+ intent: {
140
+ id: `intent-${anomaly.operation.name}`,
141
+ type: anomaly.metric === "latency" ? "latency-regression" : anomaly.metric === "error-rate" ? "error-spike" : "throughput-drop",
142
+ description: anomaly.description,
143
+ operation: anomaly.operation,
144
+ confidence: {
145
+ score: anomaly.severity === "high" ? 0.9 : anomaly.severity === "medium" ? 0.7 : 0.5,
146
+ sampleSize: usageStats.find((s) => s.operation.name === anomaly.operation.name)?.totalCalls ?? 0
147
+ }
148
+ },
149
+ target: anomaly.operation,
150
+ proposal: {
151
+ summary: generateSuggestionSummary(anomaly),
152
+ rationale: generateSuggestionRationale(anomaly),
153
+ changeType: anomaly.metric === "error-rate" ? "policy-update" : "revision",
154
+ recommendedActions: generateRecommendedActions(anomaly)
155
+ },
156
+ confidence: anomaly.severity === "high" ? 0.85 : anomaly.severity === "medium" ? 0.7 : 0.55,
157
+ createdAt: new Date,
158
+ createdBy: "ai-evolution-agent",
159
+ status: "pending",
160
+ priority: anomaly.severity
161
+ }));
162
+ setSuggestions((prev) => [...prev, ...newSuggestions]);
163
+ setLoading(false);
164
+ }, [anomalies, usageStats]);
165
+ const approveSuggestion = useCallback((id, _notes) => {
166
+ setSuggestions((prev) => prev.map((s) => s.id === id ? { ...s, status: "approved" } : s));
167
+ }, []);
168
+ const rejectSuggestion = useCallback((id, _notes) => {
169
+ setSuggestions((prev) => prev.map((s) => s.id === id ? { ...s, status: "rejected" } : s));
170
+ }, []);
171
+ const clear = useCallback(() => {
172
+ metricsRef.current = [];
173
+ setOperationCount(0);
174
+ setUsageStats([]);
175
+ setAnomalies([]);
176
+ setSuggestions([]);
177
+ setHints([]);
178
+ localStorage.removeItem(`${EVOLUTION_STORAGE_KEY}-${templateId}`);
179
+ }, [templateId]);
180
+ return useMemo(() => ({
181
+ usageStats,
182
+ anomalies,
183
+ suggestions,
184
+ hints,
185
+ loading,
186
+ trackOperation,
187
+ analyzeUsage,
188
+ generateSuggestions,
189
+ approveSuggestion,
190
+ rejectSuggestion,
191
+ clear,
192
+ operationCount
193
+ }), [
194
+ usageStats,
195
+ anomalies,
196
+ suggestions,
197
+ hints,
198
+ loading,
199
+ trackOperation,
200
+ analyzeUsage,
201
+ generateSuggestions,
202
+ approveSuggestion,
203
+ rejectSuggestion,
204
+ clear,
205
+ operationCount
206
+ ]);
207
+ }
208
+ function percentile(values, p) {
209
+ if (!values.length)
210
+ return 0;
211
+ if (values.length === 1)
212
+ return values[0] ?? 0;
213
+ const idx = Math.min(values.length - 1, Math.floor(p * values.length));
214
+ return values[idx] ?? 0;
215
+ }
216
+ function generateSuggestionSummary(anomaly) {
217
+ if (anomaly.metric === "latency") {
218
+ return `Add caching and pagination to ${anomaly.operation.name} to reduce latency`;
219
+ }
220
+ if (anomaly.metric === "error-rate") {
221
+ return `Add retry policy and circuit breaker to ${anomaly.operation.name}`;
222
+ }
223
+ return `Optimize ${anomaly.operation.name} for improved throughput`;
224
+ }
225
+ function generateSuggestionRationale(anomaly) {
226
+ if (anomaly.metric === "latency") {
227
+ return `The operation ${anomaly.operation.name} is experiencing P99 latency of ${anomaly.observedValue?.toFixed(0)}ms, which is above the recommended threshold of ${anomaly.threshold}ms. This can impact user experience and downstream operations.`;
228
+ }
229
+ if (anomaly.metric === "error-rate") {
230
+ return `The error rate for ${anomaly.operation.name} is ${((anomaly.observedValue ?? 0) * 100).toFixed(1)}%, indicating potential issues with input validation, external dependencies, or resource limits.`;
231
+ }
232
+ return `Throughput for ${anomaly.operation.name} has dropped significantly, suggesting potential bottlenecks or reduced demand that should be investigated.`;
233
+ }
234
+ function generateRecommendedActions(anomaly) {
235
+ if (anomaly.metric === "latency") {
236
+ return [
237
+ "Add response caching for frequently accessed data",
238
+ "Implement pagination for large result sets",
239
+ "Optimize database queries with proper indexing",
240
+ "Consider adding a GraphQL DataLoader for batching"
241
+ ];
242
+ }
243
+ if (anomaly.metric === "error-rate") {
244
+ return [
245
+ "Add input validation at the contract level",
246
+ "Implement retry policy with exponential backoff",
247
+ "Add circuit breaker for external dependencies",
248
+ "Enhance error logging for better debugging"
249
+ ];
250
+ }
251
+ return [
252
+ "Review resource allocation and scaling policies",
253
+ "Check for upstream routing or load balancer issues",
254
+ "Validate feature flag configurations",
255
+ "Monitor dependency health metrics"
256
+ ];
257
+ }
258
+
259
+ // src/EvolutionDashboard.tsx
260
+ import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
261
+ import { Button, LoaderBlock } from "@contractspec/lib.design-system";
262
+ import { Card } from "@contractspec/lib.ui-kit-web/ui/card";
263
+ import { Badge } from "@contractspec/lib.ui-kit-web/ui/badge";
264
+ import { jsxDEV } from "react/jsx-dev-runtime";
265
+ "use client";
266
+ function EvolutionDashboard({
267
+ templateId,
268
+ onLog
269
+ }) {
270
+ const {
271
+ usageStats,
272
+ anomalies,
273
+ suggestions,
274
+ hints,
275
+ loading,
276
+ trackOperation,
277
+ analyzeUsage,
278
+ generateSuggestions,
279
+ approveSuggestion,
280
+ rejectSuggestion,
281
+ clear,
282
+ operationCount
283
+ } = useEvolution(templateId);
284
+ const handleSimulateOperations = useCallback2(() => {
285
+ const operations = [
286
+ { name: `${templateId}.list`, duration: 150, success: true },
287
+ { name: `${templateId}.list`, duration: 180, success: true },
288
+ { name: `${templateId}.create`, duration: 350, success: true },
289
+ {
290
+ name: `${templateId}.create`,
291
+ duration: 420,
292
+ success: false,
293
+ error: "VALIDATION_ERROR"
294
+ },
295
+ { name: `${templateId}.list`, duration: 200, success: true },
296
+ { name: `${templateId}.get`, duration: 80, success: true },
297
+ { name: `${templateId}.update`, duration: 280, success: true },
298
+ { name: `${templateId}.list`, duration: 950, success: true },
299
+ {
300
+ name: `${templateId}.delete`,
301
+ duration: 150,
302
+ success: false,
303
+ error: "NOT_FOUND"
304
+ },
305
+ { name: `${templateId}.create`, duration: 380, success: true }
306
+ ];
307
+ for (const op of operations) {
308
+ trackOperation(op.name, op.duration, op.success, op.error);
309
+ }
310
+ onLog?.(`Simulated ${operations.length} operations`);
311
+ setTimeout(() => {
312
+ analyzeUsage();
313
+ onLog?.("Analysis complete");
314
+ }, 100);
315
+ }, [templateId, trackOperation, analyzeUsage, onLog]);
316
+ const handleGenerateSuggestions = useCallback2(async () => {
317
+ await generateSuggestions();
318
+ onLog?.("AI suggestions generated");
319
+ }, [generateSuggestions, onLog]);
320
+ const handleApproveSuggestion = useCallback2((id) => {
321
+ approveSuggestion(id);
322
+ onLog?.(`Suggestion ${id.slice(0, 8)} approved`);
323
+ }, [approveSuggestion, onLog]);
324
+ const handleRejectSuggestion = useCallback2((id) => {
325
+ rejectSuggestion(id);
326
+ onLog?.(`Suggestion ${id.slice(0, 8)} rejected`);
327
+ }, [rejectSuggestion, onLog]);
328
+ const handleClear = useCallback2(() => {
329
+ clear();
330
+ onLog?.("Evolution data cleared");
331
+ }, [clear, onLog]);
332
+ const pendingSuggestions = useMemo2(() => suggestions.filter((s) => s.status === "pending"), [suggestions]);
333
+ return /* @__PURE__ */ jsxDEV("div", {
334
+ className: "space-y-6",
335
+ children: [
336
+ /* @__PURE__ */ jsxDEV("div", {
337
+ className: "flex items-center justify-between",
338
+ children: [
339
+ /* @__PURE__ */ jsxDEV("div", {
340
+ children: [
341
+ /* @__PURE__ */ jsxDEV("h2", {
342
+ className: "text-xl font-semibold",
343
+ children: "AI Evolution Engine"
344
+ }, undefined, false, undefined, this),
345
+ /* @__PURE__ */ jsxDEV("p", {
346
+ className: "text-muted-foreground text-sm",
347
+ children: "Analyze usage patterns and get AI-powered suggestions"
348
+ }, undefined, false, undefined, this)
349
+ ]
350
+ }, undefined, true, undefined, this),
351
+ /* @__PURE__ */ jsxDEV("div", {
352
+ className: "flex items-center gap-2",
353
+ children: [
354
+ /* @__PURE__ */ jsxDEV(Badge, {
355
+ variant: "secondary",
356
+ children: [
357
+ operationCount,
358
+ " ops tracked"
359
+ ]
360
+ }, undefined, true, undefined, this),
361
+ /* @__PURE__ */ jsxDEV(Button, {
362
+ variant: "ghost",
363
+ size: "sm",
364
+ onPress: handleClear,
365
+ children: "Clear"
366
+ }, undefined, false, undefined, this)
367
+ ]
368
+ }, undefined, true, undefined, this)
369
+ ]
370
+ }, undefined, true, undefined, this),
371
+ /* @__PURE__ */ jsxDEV(Card, {
372
+ className: "p-4",
373
+ children: [
374
+ /* @__PURE__ */ jsxDEV("div", {
375
+ className: "flex flex-wrap items-center gap-3",
376
+ children: [
377
+ /* @__PURE__ */ jsxDEV(Button, {
378
+ variant: "default",
379
+ size: "sm",
380
+ onPress: handleSimulateOperations,
381
+ children: "Simulate Operations"
382
+ }, undefined, false, undefined, this),
383
+ /* @__PURE__ */ jsxDEV(Button, {
384
+ variant: "outline",
385
+ size: "sm",
386
+ onPress: analyzeUsage,
387
+ disabled: operationCount < 5,
388
+ children: "Analyze Usage"
389
+ }, undefined, false, undefined, this),
390
+ /* @__PURE__ */ jsxDEV(Button, {
391
+ variant: "outline",
392
+ size: "sm",
393
+ onPress: handleGenerateSuggestions,
394
+ disabled: anomalies.length === 0 || loading,
395
+ children: loading ? "Generating..." : "Generate AI Suggestions"
396
+ }, undefined, false, undefined, this)
397
+ ]
398
+ }, undefined, true, undefined, this),
399
+ /* @__PURE__ */ jsxDEV("p", {
400
+ className: "text-muted-foreground mt-2 text-xs",
401
+ children: "Simulate sandbox operations, analyze patterns, and generate AI improvement suggestions."
402
+ }, undefined, false, undefined, this)
403
+ ]
404
+ }, undefined, true, undefined, this),
405
+ loading && /* @__PURE__ */ jsxDEV(LoaderBlock, {
406
+ label: "Generating AI suggestions..."
407
+ }, undefined, false, undefined, this),
408
+ usageStats.length > 0 && /* @__PURE__ */ jsxDEV(Card, {
409
+ className: "p-4",
410
+ children: [
411
+ /* @__PURE__ */ jsxDEV("h3", {
412
+ className: "mb-3 font-semibold",
413
+ children: "Usage Statistics"
414
+ }, undefined, false, undefined, this),
415
+ /* @__PURE__ */ jsxDEV("div", {
416
+ className: "grid gap-3 md:grid-cols-2 lg:grid-cols-3",
417
+ children: usageStats.map((stat) => /* @__PURE__ */ jsxDEV(UsageStatCard, {
418
+ stat
419
+ }, stat.operation.name, false, undefined, this))
420
+ }, undefined, false, undefined, this)
421
+ ]
422
+ }, undefined, true, undefined, this),
423
+ anomalies.length > 0 && /* @__PURE__ */ jsxDEV(Card, {
424
+ className: "p-4",
425
+ children: [
426
+ /* @__PURE__ */ jsxDEV("div", {
427
+ className: "mb-3 flex items-center justify-between",
428
+ children: [
429
+ /* @__PURE__ */ jsxDEV("h3", {
430
+ className: "font-semibold",
431
+ children: "Detected Anomalies"
432
+ }, undefined, false, undefined, this),
433
+ /* @__PURE__ */ jsxDEV(Badge, {
434
+ variant: "secondary",
435
+ className: "border-amber-500/30 bg-amber-500/20 text-amber-400",
436
+ children: [
437
+ anomalies.length,
438
+ " issues"
439
+ ]
440
+ }, undefined, true, undefined, this)
441
+ ]
442
+ }, undefined, true, undefined, this),
443
+ /* @__PURE__ */ jsxDEV("div", {
444
+ className: "space-y-2",
445
+ children: anomalies.map((anomaly, index) => /* @__PURE__ */ jsxDEV(AnomalyCard, {
446
+ anomaly
447
+ }, `${anomaly.operation.name}-${index}`, false, undefined, this))
448
+ }, undefined, false, undefined, this)
449
+ ]
450
+ }, undefined, true, undefined, this),
451
+ suggestions.length > 0 && /* @__PURE__ */ jsxDEV(Card, {
452
+ className: "p-4",
453
+ children: [
454
+ /* @__PURE__ */ jsxDEV("div", {
455
+ className: "mb-3 flex items-center justify-between",
456
+ children: [
457
+ /* @__PURE__ */ jsxDEV("h3", {
458
+ className: "font-semibold",
459
+ children: "AI Suggestions"
460
+ }, undefined, false, undefined, this),
461
+ /* @__PURE__ */ jsxDEV("div", {
462
+ className: "flex items-center gap-2",
463
+ children: pendingSuggestions.length > 0 && /* @__PURE__ */ jsxDEV(Badge, {
464
+ variant: "secondary",
465
+ className: "border-amber-500/30 bg-amber-500/20 text-amber-400",
466
+ children: [
467
+ pendingSuggestions.length,
468
+ " pending"
469
+ ]
470
+ }, undefined, true, undefined, this)
471
+ }, undefined, false, undefined, this)
472
+ ]
473
+ }, undefined, true, undefined, this),
474
+ /* @__PURE__ */ jsxDEV("div", {
475
+ className: "space-y-3",
476
+ children: suggestions.map((suggestion) => /* @__PURE__ */ jsxDEV(SuggestionCard, {
477
+ suggestion,
478
+ onApprove: handleApproveSuggestion,
479
+ onReject: handleRejectSuggestion
480
+ }, suggestion.id, false, undefined, this))
481
+ }, undefined, false, undefined, this)
482
+ ]
483
+ }, undefined, true, undefined, this),
484
+ hints.length > 0 && /* @__PURE__ */ jsxDEV(Card, {
485
+ className: "p-4",
486
+ children: [
487
+ /* @__PURE__ */ jsxDEV("h3", {
488
+ className: "mb-3 font-semibold",
489
+ children: "Optimization Hints"
490
+ }, undefined, false, undefined, this),
491
+ /* @__PURE__ */ jsxDEV("div", {
492
+ className: "space-y-2",
493
+ children: hints.map((hint, index) => /* @__PURE__ */ jsxDEV(HintCard, {
494
+ hint
495
+ }, `${hint.operation.name}-${index}`, false, undefined, this))
496
+ }, undefined, false, undefined, this)
497
+ ]
498
+ }, undefined, true, undefined, this),
499
+ usageStats.length === 0 && anomalies.length === 0 && suggestions.length === 0 && /* @__PURE__ */ jsxDEV(Card, {
500
+ className: "p-8 text-center",
501
+ children: /* @__PURE__ */ jsxDEV("p", {
502
+ className: "text-muted-foreground",
503
+ children: 'Click "Simulate Operations" to generate sample data for analysis.'
504
+ }, undefined, false, undefined, this)
505
+ }, undefined, false, undefined, this)
506
+ ]
507
+ }, undefined, true, undefined, this);
508
+ }
509
+ function UsageStatCard({ stat }) {
510
+ return /* @__PURE__ */ jsxDEV("div", {
511
+ className: "rounded-lg border border-violet-500/20 bg-violet-500/5 p-3",
512
+ children: [
513
+ /* @__PURE__ */ jsxDEV("div", {
514
+ className: "mb-2 flex items-center justify-between",
515
+ children: [
516
+ /* @__PURE__ */ jsxDEV("span", {
517
+ className: "font-mono text-sm font-medium",
518
+ children: stat.operation.name
519
+ }, undefined, false, undefined, this),
520
+ /* @__PURE__ */ jsxDEV(Badge, {
521
+ variant: stat.errorRate > 0.1 ? "destructive" : "default",
522
+ className: stat.errorRate > 0.1 ? "" : "border-green-500/30 bg-green-500/20 text-green-400",
523
+ children: [
524
+ ((1 - stat.errorRate) * 100).toFixed(0),
525
+ "% success"
526
+ ]
527
+ }, undefined, true, undefined, this)
528
+ ]
529
+ }, undefined, true, undefined, this),
530
+ /* @__PURE__ */ jsxDEV("div", {
531
+ className: "grid grid-cols-2 gap-2 text-xs",
532
+ children: [
533
+ /* @__PURE__ */ jsxDEV("div", {
534
+ children: [
535
+ /* @__PURE__ */ jsxDEV("span", {
536
+ className: "text-muted-foreground",
537
+ children: "Total Calls:"
538
+ }, undefined, false, undefined, this),
539
+ " ",
540
+ /* @__PURE__ */ jsxDEV("span", {
541
+ className: "font-medium",
542
+ children: stat.totalCalls
543
+ }, undefined, false, undefined, this)
544
+ ]
545
+ }, undefined, true, undefined, this),
546
+ /* @__PURE__ */ jsxDEV("div", {
547
+ children: [
548
+ /* @__PURE__ */ jsxDEV("span", {
549
+ className: "text-muted-foreground",
550
+ children: "Avg Latency:"
551
+ }, undefined, false, undefined, this),
552
+ " ",
553
+ /* @__PURE__ */ jsxDEV("span", {
554
+ className: "font-medium",
555
+ children: [
556
+ stat.averageLatencyMs.toFixed(0),
557
+ "ms"
558
+ ]
559
+ }, undefined, true, undefined, this)
560
+ ]
561
+ }, undefined, true, undefined, this),
562
+ /* @__PURE__ */ jsxDEV("div", {
563
+ children: [
564
+ /* @__PURE__ */ jsxDEV("span", {
565
+ className: "text-muted-foreground",
566
+ children: "P95:"
567
+ }, undefined, false, undefined, this),
568
+ " ",
569
+ /* @__PURE__ */ jsxDEV("span", {
570
+ className: "font-medium",
571
+ children: [
572
+ stat.p95LatencyMs.toFixed(0),
573
+ "ms"
574
+ ]
575
+ }, undefined, true, undefined, this)
576
+ ]
577
+ }, undefined, true, undefined, this),
578
+ /* @__PURE__ */ jsxDEV("div", {
579
+ children: [
580
+ /* @__PURE__ */ jsxDEV("span", {
581
+ className: "text-muted-foreground",
582
+ children: "P99:"
583
+ }, undefined, false, undefined, this),
584
+ " ",
585
+ /* @__PURE__ */ jsxDEV("span", {
586
+ className: "font-medium",
587
+ children: [
588
+ stat.p99LatencyMs.toFixed(0),
589
+ "ms"
590
+ ]
591
+ }, undefined, true, undefined, this)
592
+ ]
593
+ }, undefined, true, undefined, this)
594
+ ]
595
+ }, undefined, true, undefined, this)
596
+ ]
597
+ }, undefined, true, undefined, this);
598
+ }
599
+ function AnomalyCard({ anomaly }) {
600
+ const severityColors = {
601
+ low: "text-amber-400",
602
+ medium: "text-orange-400",
603
+ high: "text-red-400"
604
+ };
605
+ return /* @__PURE__ */ jsxDEV("div", {
606
+ className: "flex items-center justify-between rounded-lg border border-amber-500/30 bg-amber-500/5 p-3",
607
+ children: [
608
+ /* @__PURE__ */ jsxDEV("div", {
609
+ className: "flex items-center gap-3",
610
+ children: [
611
+ /* @__PURE__ */ jsxDEV("span", {
612
+ className: `text-lg ${severityColors[anomaly.severity]}`,
613
+ title: `${anomaly.severity} severity`,
614
+ children: anomaly.severity === "high" ? "\uD83D\uDD34" : anomaly.severity === "medium" ? "\uD83D\uDFE0" : "\uD83D\uDFE1"
615
+ }, undefined, false, undefined, this),
616
+ /* @__PURE__ */ jsxDEV("div", {
617
+ children: [
618
+ /* @__PURE__ */ jsxDEV("p", {
619
+ className: "text-sm font-medium",
620
+ children: anomaly.description
621
+ }, undefined, false, undefined, this),
622
+ /* @__PURE__ */ jsxDEV("p", {
623
+ className: "text-muted-foreground text-xs",
624
+ children: [
625
+ anomaly.operation.name,
626
+ " • ",
627
+ anomaly.metric
628
+ ]
629
+ }, undefined, true, undefined, this)
630
+ ]
631
+ }, undefined, true, undefined, this)
632
+ ]
633
+ }, undefined, true, undefined, this),
634
+ /* @__PURE__ */ jsxDEV(Badge, {
635
+ variant: anomaly.severity === "high" ? "destructive" : "secondary",
636
+ className: anomaly.severity === "medium" ? "border-amber-500/30 bg-amber-500/20 text-amber-400" : "",
637
+ children: anomaly.severity
638
+ }, undefined, false, undefined, this)
639
+ ]
640
+ }, undefined, true, undefined, this);
641
+ }
642
+ function SuggestionCard({
643
+ suggestion,
644
+ onApprove,
645
+ onReject
646
+ }) {
647
+ const getStatusStyles = (status) => {
648
+ switch (status) {
649
+ case "pending":
650
+ return {
651
+ variant: "secondary",
652
+ className: "bg-amber-500/20 text-amber-400 border-amber-500/30"
653
+ };
654
+ case "approved":
655
+ return {
656
+ variant: "default",
657
+ className: "bg-green-500/20 text-green-400 border-green-500/30"
658
+ };
659
+ case "rejected":
660
+ return { variant: "destructive", className: "" };
661
+ default:
662
+ return { variant: "secondary", className: "" };
663
+ }
664
+ };
665
+ const statusStyle = getStatusStyles(suggestion.status);
666
+ return /* @__PURE__ */ jsxDEV("div", {
667
+ className: "rounded-lg border border-violet-500/30 bg-violet-500/5 p-4",
668
+ children: [
669
+ /* @__PURE__ */ jsxDEV("div", {
670
+ className: "mb-2 flex items-start justify-between",
671
+ children: [
672
+ /* @__PURE__ */ jsxDEV("div", {
673
+ className: "flex-1",
674
+ children: [
675
+ /* @__PURE__ */ jsxDEV("div", {
676
+ className: "flex items-center gap-2",
677
+ children: [
678
+ /* @__PURE__ */ jsxDEV("span", {
679
+ className: "text-lg",
680
+ children: suggestion.intent.type === "latency-regression" ? "⚡" : suggestion.intent.type === "error-spike" ? "\uD83D\uDD25" : "\uD83D\uDCC9"
681
+ }, undefined, false, undefined, this),
682
+ /* @__PURE__ */ jsxDEV("h4", {
683
+ className: "font-medium",
684
+ children: suggestion.proposal.summary
685
+ }, undefined, false, undefined, this)
686
+ ]
687
+ }, undefined, true, undefined, this),
688
+ /* @__PURE__ */ jsxDEV("p", {
689
+ className: "text-muted-foreground mt-1 text-sm",
690
+ children: suggestion.proposal.rationale
691
+ }, undefined, false, undefined, this)
692
+ ]
693
+ }, undefined, true, undefined, this),
694
+ /* @__PURE__ */ jsxDEV(Badge, {
695
+ variant: statusStyle.variant,
696
+ className: statusStyle.className,
697
+ children: suggestion.status
698
+ }, undefined, false, undefined, this)
699
+ ]
700
+ }, undefined, true, undefined, this),
701
+ suggestion.proposal.recommendedActions && suggestion.proposal.recommendedActions.length > 0 && /* @__PURE__ */ jsxDEV("div", {
702
+ className: "mt-3",
703
+ children: [
704
+ /* @__PURE__ */ jsxDEV("p", {
705
+ className: "mb-1 text-xs font-semibold text-violet-400 uppercase",
706
+ children: "Recommended Actions"
707
+ }, undefined, false, undefined, this),
708
+ /* @__PURE__ */ jsxDEV("ul", {
709
+ className: "list-inside list-disc space-y-1 text-xs",
710
+ children: suggestion.proposal.recommendedActions.slice(0, 3).map((action, i) => /* @__PURE__ */ jsxDEV("li", {
711
+ children: action
712
+ }, i, false, undefined, this))
713
+ }, undefined, false, undefined, this)
714
+ ]
715
+ }, undefined, true, undefined, this),
716
+ /* @__PURE__ */ jsxDEV("div", {
717
+ className: "mt-3 flex items-center justify-between",
718
+ children: [
719
+ /* @__PURE__ */ jsxDEV("div", {
720
+ className: "flex items-center gap-2 text-xs",
721
+ children: [
722
+ /* @__PURE__ */ jsxDEV("span", {
723
+ className: "text-muted-foreground",
724
+ children: [
725
+ "Confidence: ",
726
+ (suggestion.confidence * 100).toFixed(0),
727
+ "%"
728
+ ]
729
+ }, undefined, true, undefined, this),
730
+ /* @__PURE__ */ jsxDEV("span", {
731
+ className: "text-muted-foreground",
732
+ children: "•"
733
+ }, undefined, false, undefined, this),
734
+ /* @__PURE__ */ jsxDEV(Badge, {
735
+ variant: "secondary",
736
+ children: suggestion.priority
737
+ }, undefined, false, undefined, this)
738
+ ]
739
+ }, undefined, true, undefined, this),
740
+ suggestion.status === "pending" && /* @__PURE__ */ jsxDEV("div", {
741
+ className: "flex items-center gap-2",
742
+ children: [
743
+ /* @__PURE__ */ jsxDEV(Button, {
744
+ variant: "outline",
745
+ size: "sm",
746
+ onPress: () => onReject(suggestion.id),
747
+ children: "Reject"
748
+ }, undefined, false, undefined, this),
749
+ /* @__PURE__ */ jsxDEV(Button, {
750
+ variant: "default",
751
+ size: "sm",
752
+ onPress: () => onApprove(suggestion.id),
753
+ children: "Approve"
754
+ }, undefined, false, undefined, this)
755
+ ]
756
+ }, undefined, true, undefined, this)
757
+ ]
758
+ }, undefined, true, undefined, this)
759
+ ]
760
+ }, undefined, true, undefined, this);
761
+ }
762
+ function HintCard({ hint }) {
763
+ const categoryIcons = {
764
+ schema: "\uD83D\uDCD0",
765
+ policy: "\uD83D\uDD12",
766
+ performance: "⚡",
767
+ "error-handling": "\uD83D\uDEE1️"
768
+ };
769
+ return /* @__PURE__ */ jsxDEV("div", {
770
+ className: "rounded-lg border border-blue-500/20 bg-blue-500/5 p-3",
771
+ children: /* @__PURE__ */ jsxDEV("div", {
772
+ className: "flex items-start gap-3",
773
+ children: [
774
+ /* @__PURE__ */ jsxDEV("span", {
775
+ className: "text-lg",
776
+ children: categoryIcons[hint.category]
777
+ }, undefined, false, undefined, this),
778
+ /* @__PURE__ */ jsxDEV("div", {
779
+ className: "flex-1",
780
+ children: [
781
+ /* @__PURE__ */ jsxDEV("p", {
782
+ className: "font-medium",
783
+ children: hint.summary
784
+ }, undefined, false, undefined, this),
785
+ /* @__PURE__ */ jsxDEV("p", {
786
+ className: "text-muted-foreground mt-1 text-xs",
787
+ children: hint.justification
788
+ }, undefined, false, undefined, this),
789
+ hint.recommendedActions.length > 0 && /* @__PURE__ */ jsxDEV("ul", {
790
+ className: "mt-2 list-inside list-disc text-xs",
791
+ children: hint.recommendedActions.slice(0, 2).map((action, i) => /* @__PURE__ */ jsxDEV("li", {
792
+ children: action
793
+ }, i, false, undefined, this))
794
+ }, undefined, false, undefined, this)
795
+ ]
796
+ }, undefined, true, undefined, this)
797
+ ]
798
+ }, undefined, true, undefined, this)
799
+ }, undefined, false, undefined, this);
800
+ }
801
+ export {
802
+ EvolutionDashboard
803
+ };