@contractspec/lib.example-shared-ui 1.10.1 → 1.12.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 +32 -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 +222 -17
  120. package/.turbo/turbo-build$colon$bundle.log +0 -9
  121. package/dist/index.mjs +0 -3121
@@ -0,0 +1,531 @@
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/EvolutionSidebar.tsx
260
+ import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
261
+ import { Button } 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 EvolutionSidebar({
267
+ templateId,
268
+ expanded = false,
269
+ onToggle,
270
+ onLog,
271
+ onOpenEvolution
272
+ }) {
273
+ const {
274
+ anomalies,
275
+ suggestions,
276
+ loading,
277
+ approveSuggestion,
278
+ rejectSuggestion,
279
+ operationCount
280
+ } = useEvolution(templateId);
281
+ const pendingSuggestions = useMemo2(() => suggestions.filter((s) => s.status === "pending"), [suggestions]);
282
+ const topAnomalies = useMemo2(() => anomalies.sort((a, b) => {
283
+ const severityOrder = { high: 0, medium: 1, low: 2 };
284
+ return severityOrder[a.severity] - severityOrder[b.severity];
285
+ }).slice(0, 3), [anomalies]);
286
+ const handleApprove = useCallback2((id) => {
287
+ approveSuggestion(id);
288
+ onLog?.(`Approved suggestion ${id.slice(0, 8)}`);
289
+ }, [approveSuggestion, onLog]);
290
+ const handleReject = useCallback2((id) => {
291
+ rejectSuggestion(id);
292
+ onLog?.(`Rejected suggestion ${id.slice(0, 8)}`);
293
+ }, [rejectSuggestion, onLog]);
294
+ if (!expanded) {
295
+ return /* @__PURE__ */ jsxDEV("button", {
296
+ onClick: onToggle,
297
+ className: "flex items-center gap-2 rounded-lg border border-violet-500/30 bg-violet-500/10 px-3 py-2 text-sm transition hover:bg-violet-500/20",
298
+ type: "button",
299
+ children: [
300
+ /* @__PURE__ */ jsxDEV("span", {
301
+ children: "\uD83E\uDD16"
302
+ }, undefined, false, undefined, this),
303
+ /* @__PURE__ */ jsxDEV("span", {
304
+ children: "Evolution"
305
+ }, undefined, false, undefined, this),
306
+ pendingSuggestions.length > 0 && /* @__PURE__ */ jsxDEV(Badge, {
307
+ variant: "secondary",
308
+ className: "border-amber-500/30 bg-amber-500/20 text-amber-400",
309
+ children: pendingSuggestions.length
310
+ }, undefined, false, undefined, this),
311
+ anomalies.length > 0 && pendingSuggestions.length === 0 && /* @__PURE__ */ jsxDEV(Badge, {
312
+ variant: "destructive",
313
+ children: anomalies.length
314
+ }, undefined, false, undefined, this)
315
+ ]
316
+ }, undefined, true, undefined, this);
317
+ }
318
+ return /* @__PURE__ */ jsxDEV(Card, {
319
+ className: "w-80 overflow-hidden",
320
+ children: [
321
+ /* @__PURE__ */ jsxDEV("div", {
322
+ className: "flex items-center justify-between border-b border-violet-500/20 bg-violet-500/5 px-3 py-2",
323
+ children: [
324
+ /* @__PURE__ */ jsxDEV("div", {
325
+ className: "flex items-center gap-2",
326
+ children: [
327
+ /* @__PURE__ */ jsxDEV("span", {
328
+ children: "\uD83E\uDD16"
329
+ }, undefined, false, undefined, this),
330
+ /* @__PURE__ */ jsxDEV("span", {
331
+ className: "text-sm font-semibold",
332
+ children: "Evolution"
333
+ }, undefined, false, undefined, this)
334
+ ]
335
+ }, undefined, true, undefined, this),
336
+ /* @__PURE__ */ jsxDEV("div", {
337
+ className: "flex items-center gap-1",
338
+ children: [
339
+ onOpenEvolution && /* @__PURE__ */ jsxDEV(Button, {
340
+ variant: "ghost",
341
+ size: "sm",
342
+ onPress: onOpenEvolution,
343
+ children: "Expand"
344
+ }, undefined, false, undefined, this),
345
+ /* @__PURE__ */ jsxDEV("button", {
346
+ onClick: onToggle,
347
+ className: "text-muted-foreground hover:text-foreground p-1",
348
+ type: "button",
349
+ title: "Collapse",
350
+ children: "✕"
351
+ }, undefined, false, undefined, this)
352
+ ]
353
+ }, undefined, true, undefined, this)
354
+ ]
355
+ }, undefined, true, undefined, this),
356
+ /* @__PURE__ */ jsxDEV("div", {
357
+ className: "max-h-96 overflow-y-auto p-3",
358
+ children: [
359
+ /* @__PURE__ */ jsxDEV("div", {
360
+ className: "mb-3 flex items-center justify-between text-xs",
361
+ children: [
362
+ /* @__PURE__ */ jsxDEV("span", {
363
+ className: "text-muted-foreground",
364
+ children: [
365
+ operationCount,
366
+ " ops tracked"
367
+ ]
368
+ }, undefined, true, undefined, this),
369
+ /* @__PURE__ */ jsxDEV("div", {
370
+ className: "flex items-center gap-2",
371
+ children: [
372
+ anomalies.length > 0 && /* @__PURE__ */ jsxDEV(Badge, {
373
+ variant: "destructive",
374
+ children: [
375
+ anomalies.length,
376
+ " anomalies"
377
+ ]
378
+ }, undefined, true, undefined, this),
379
+ pendingSuggestions.length > 0 && /* @__PURE__ */ jsxDEV(Badge, {
380
+ variant: "secondary",
381
+ className: "border-amber-500/30 bg-amber-500/20 text-amber-400",
382
+ children: [
383
+ pendingSuggestions.length,
384
+ " pending"
385
+ ]
386
+ }, undefined, true, undefined, this)
387
+ ]
388
+ }, undefined, true, undefined, this)
389
+ ]
390
+ }, undefined, true, undefined, this),
391
+ loading && /* @__PURE__ */ jsxDEV("div", {
392
+ className: "text-muted-foreground py-4 text-center text-sm",
393
+ children: "Generating suggestions..."
394
+ }, undefined, false, undefined, this),
395
+ topAnomalies.length > 0 && /* @__PURE__ */ jsxDEV("div", {
396
+ className: "mb-4",
397
+ children: [
398
+ /* @__PURE__ */ jsxDEV("p", {
399
+ className: "mb-2 text-xs font-semibold text-violet-400 uppercase",
400
+ children: "Top Issues"
401
+ }, undefined, false, undefined, this),
402
+ /* @__PURE__ */ jsxDEV("div", {
403
+ className: "space-y-2",
404
+ children: topAnomalies.map((anomaly, index) => /* @__PURE__ */ jsxDEV("div", {
405
+ className: "rounded border border-amber-500/20 bg-amber-500/5 p-2 text-xs",
406
+ children: [
407
+ /* @__PURE__ */ jsxDEV("div", {
408
+ className: "flex items-center gap-2",
409
+ children: [
410
+ /* @__PURE__ */ jsxDEV("span", {
411
+ children: anomaly.severity === "high" ? "\uD83D\uDD34" : anomaly.severity === "medium" ? "\uD83D\uDFE0" : "\uD83D\uDFE1"
412
+ }, undefined, false, undefined, this),
413
+ /* @__PURE__ */ jsxDEV("span", {
414
+ className: "truncate font-medium",
415
+ children: anomaly.operation.name
416
+ }, undefined, false, undefined, this)
417
+ ]
418
+ }, undefined, true, undefined, this),
419
+ /* @__PURE__ */ jsxDEV("p", {
420
+ className: "text-muted-foreground mt-1 truncate",
421
+ children: anomaly.description
422
+ }, undefined, false, undefined, this)
423
+ ]
424
+ }, `${anomaly.operation.name}-${index}`, true, undefined, this))
425
+ }, undefined, false, undefined, this)
426
+ ]
427
+ }, undefined, true, undefined, this),
428
+ pendingSuggestions.length > 0 && /* @__PURE__ */ jsxDEV("div", {
429
+ children: [
430
+ /* @__PURE__ */ jsxDEV("p", {
431
+ className: "mb-2 text-xs font-semibold text-violet-400 uppercase",
432
+ children: "Pending Suggestions"
433
+ }, undefined, false, undefined, this),
434
+ /* @__PURE__ */ jsxDEV("div", {
435
+ className: "space-y-2",
436
+ children: [
437
+ pendingSuggestions.slice(0, 3).map((suggestion) => /* @__PURE__ */ jsxDEV(CompactSuggestionCard, {
438
+ suggestion,
439
+ onApprove: handleApprove,
440
+ onReject: handleReject
441
+ }, suggestion.id, false, undefined, this)),
442
+ pendingSuggestions.length > 3 && /* @__PURE__ */ jsxDEV("p", {
443
+ className: "text-muted-foreground text-center text-xs",
444
+ children: [
445
+ "+",
446
+ pendingSuggestions.length - 3,
447
+ " more suggestions"
448
+ ]
449
+ }, undefined, true, undefined, this)
450
+ ]
451
+ }, undefined, true, undefined, this)
452
+ ]
453
+ }, undefined, true, undefined, this),
454
+ anomalies.length === 0 && pendingSuggestions.length === 0 && !loading && /* @__PURE__ */ jsxDEV("div", {
455
+ className: "text-muted-foreground py-4 text-center text-xs",
456
+ children: "No issues detected. Keep coding!"
457
+ }, undefined, false, undefined, this)
458
+ ]
459
+ }, undefined, true, undefined, this),
460
+ onOpenEvolution && /* @__PURE__ */ jsxDEV("div", {
461
+ className: "border-t border-violet-500/20 p-2",
462
+ children: /* @__PURE__ */ jsxDEV(Button, {
463
+ variant: "ghost",
464
+ size: "sm",
465
+ className: "w-full",
466
+ onPress: onOpenEvolution,
467
+ children: "Open Evolution Dashboard →"
468
+ }, undefined, false, undefined, this)
469
+ }, undefined, false, undefined, this)
470
+ ]
471
+ }, undefined, true, undefined, this);
472
+ }
473
+ function CompactSuggestionCard({
474
+ suggestion,
475
+ onApprove,
476
+ onReject
477
+ }) {
478
+ return /* @__PURE__ */ jsxDEV("div", {
479
+ className: "rounded border border-violet-500/20 bg-violet-500/5 p-2",
480
+ children: [
481
+ /* @__PURE__ */ jsxDEV("div", {
482
+ className: "flex items-start justify-between gap-2",
483
+ children: /* @__PURE__ */ jsxDEV("div", {
484
+ className: "min-w-0 flex-1",
485
+ children: [
486
+ /* @__PURE__ */ jsxDEV("p", {
487
+ className: "truncate text-xs font-medium",
488
+ children: suggestion.proposal.summary
489
+ }, undefined, false, undefined, this),
490
+ /* @__PURE__ */ jsxDEV("div", {
491
+ className: "mt-1 flex items-center gap-2 text-xs",
492
+ children: [
493
+ /* @__PURE__ */ jsxDEV(Badge, {
494
+ variant: "secondary",
495
+ children: suggestion.priority
496
+ }, undefined, false, undefined, this),
497
+ /* @__PURE__ */ jsxDEV("span", {
498
+ className: "text-muted-foreground",
499
+ children: [
500
+ (suggestion.confidence * 100).toFixed(0),
501
+ "%"
502
+ ]
503
+ }, undefined, true, undefined, this)
504
+ ]
505
+ }, undefined, true, undefined, this)
506
+ ]
507
+ }, undefined, true, undefined, this)
508
+ }, undefined, false, undefined, this),
509
+ /* @__PURE__ */ jsxDEV("div", {
510
+ className: "mt-2 flex justify-end gap-1",
511
+ children: [
512
+ /* @__PURE__ */ jsxDEV("button", {
513
+ onClick: () => onReject(suggestion.id),
514
+ className: "rounded px-2 py-0.5 text-xs text-red-400 hover:bg-red-400/10",
515
+ type: "button",
516
+ children: "Reject"
517
+ }, undefined, false, undefined, this),
518
+ /* @__PURE__ */ jsxDEV("button", {
519
+ onClick: () => onApprove(suggestion.id),
520
+ className: "rounded bg-violet-500/20 px-2 py-0.5 text-xs text-violet-400 hover:bg-violet-500/30",
521
+ type: "button",
522
+ children: "Approve"
523
+ }, undefined, false, undefined, this)
524
+ ]
525
+ }, undefined, true, undefined, this)
526
+ ]
527
+ }, undefined, true, undefined, this);
528
+ }
529
+ export {
530
+ EvolutionSidebar
531
+ };
@@ -0,0 +1,62 @@
1
+ // src/lib/runtime-context.tsx
2
+ import { createContext, useContext } from "react";
3
+ "use client";
4
+ var TemplateRuntimeContext = createContext(null);
5
+ function useTemplateRuntime() {
6
+ const context = useContext(TemplateRuntimeContext);
7
+ if (!context) {
8
+ throw new Error("useTemplateRuntime must be used within a TemplateRuntimeProvider");
9
+ }
10
+ return context;
11
+ }
12
+
13
+ // src/LocalDataIndicator.tsx
14
+ import { RefreshCw, Shield } from "lucide-react";
15
+ import { useState } from "react";
16
+ import { jsxDEV } from "react/jsx-dev-runtime";
17
+ "use client";
18
+ function LocalDataIndicator() {
19
+ const { projectId, templateId, template, installer } = useTemplateRuntime();
20
+ const [isResetting, setIsResetting] = useState(false);
21
+ const handleReset = async () => {
22
+ setIsResetting(true);
23
+ try {
24
+ await installer.install(templateId, { projectId });
25
+ } finally {
26
+ setIsResetting(false);
27
+ }
28
+ };
29
+ return /* @__PURE__ */ jsxDEV("div", {
30
+ className: "border-border bg-muted/40 text-muted-foreground inline-flex items-center gap-2 rounded-full border px-3 py-1 text-xs",
31
+ children: [
32
+ /* @__PURE__ */ jsxDEV(Shield, {
33
+ className: "h-3.5 w-3.5 text-violet-400"
34
+ }, undefined, false, undefined, this),
35
+ /* @__PURE__ */ jsxDEV("span", {
36
+ children: [
37
+ "Local runtime ·",
38
+ " ",
39
+ /* @__PURE__ */ jsxDEV("span", {
40
+ className: "text-foreground font-semibold",
41
+ children: template.name
42
+ }, undefined, false, undefined, this)
43
+ ]
44
+ }, undefined, true, undefined, this),
45
+ /* @__PURE__ */ jsxDEV("button", {
46
+ type: "button",
47
+ className: "border-border text-muted-foreground hover:text-foreground inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] font-semibold",
48
+ onClick: handleReset,
49
+ disabled: isResetting,
50
+ children: [
51
+ /* @__PURE__ */ jsxDEV(RefreshCw, {
52
+ className: "h-3 w-3"
53
+ }, undefined, false, undefined, this),
54
+ isResetting ? "Resetting…" : "Reset data"
55
+ ]
56
+ }, undefined, true, undefined, this)
57
+ ]
58
+ }, undefined, true, undefined, this);
59
+ }
60
+ export {
61
+ LocalDataIndicator
62
+ };