@contractspec/lib.example-shared-ui 1.11.0 → 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 +14 -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,579 @@
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/utils/generateSpecFromTemplate.ts
14
+ function generateSpecFromTemplate(template) {
15
+ const templateId = template?.id ?? "unknown";
16
+ if (!template) {
17
+ return generateDefaultSpec(templateId);
18
+ }
19
+ switch (templateId) {
20
+ case "crm-pipeline":
21
+ return generateCrmPipelineSpec(template.schema.contracts);
22
+ case "saas-boilerplate":
23
+ return generateSaasBoilerplateSpec(template.schema.contracts);
24
+ case "agent-console":
25
+ return generateAgentConsoleSpec(template.schema.contracts);
26
+ case "todos-app":
27
+ return generateTodosSpec(template.schema.contracts);
28
+ case "messaging-app":
29
+ return generateMessagingSpec(template.schema.contracts);
30
+ case "recipe-app-i18n":
31
+ return generateRecipeSpec(template.schema.contracts);
32
+ default:
33
+ return generateDefaultSpec(templateId);
34
+ }
35
+ }
36
+ function generateCrmPipelineSpec(contracts) {
37
+ return `// CRM Pipeline Specs
38
+ // Contracts: ${contracts.join(", ")}
39
+
40
+ contractSpec("crm.deal.updateStage.v1", {
41
+ goal: "Move a deal to a different pipeline stage",
42
+ transport: { gql: { mutation: "updateDealStage" } },
43
+ io: {
44
+ input: {
45
+ dealId: "string",
46
+ stageId: "string",
47
+ notes: "string?"
48
+ },
49
+ output: {
50
+ deal: {
51
+ id: "string",
52
+ stage: "string",
53
+ probability: "number",
54
+ value: "number"
55
+ }
56
+ }
57
+ },
58
+ events: ["deal.stage.changed"],
59
+ policy: { auth: "user", rbac: "org:sales" }
60
+ });
61
+
62
+ contractSpec("crm.deal.create.v1", {
63
+ goal: "Create a new deal in the pipeline",
64
+ transport: { gql: { mutation: "createDeal" } },
65
+ io: {
66
+ input: {
67
+ title: "string",
68
+ value: "number",
69
+ contactId: "string",
70
+ stageId: "string",
71
+ ownerId: "string?"
72
+ },
73
+ output: {
74
+ deal: {
75
+ id: "string",
76
+ title: "string",
77
+ value: "number",
78
+ stage: "string",
79
+ createdAt: "ISO8601"
80
+ }
81
+ }
82
+ },
83
+ events: ["deal.created"]
84
+ });
85
+
86
+ contractSpec("crm.contact.list.v1", {
87
+ goal: "List contacts with filtering and pagination",
88
+ transport: { gql: { query: "listContacts" } },
89
+ io: {
90
+ input: {
91
+ filter: {
92
+ search: "string?",
93
+ companyId: "string?",
94
+ tags: "string[]?"
95
+ },
96
+ pagination: {
97
+ page: "number",
98
+ limit: "number"
99
+ }
100
+ },
101
+ output: {
102
+ contacts: "array<Contact>",
103
+ total: "number",
104
+ hasMore: "boolean"
105
+ }
106
+ }
107
+ });`;
108
+ }
109
+ function generateSaasBoilerplateSpec(contracts) {
110
+ return `// SaaS Boilerplate Specs
111
+ // Contracts: ${contracts.join(", ")}
112
+
113
+ contractSpec("saas.project.create.v1", {
114
+ goal: "Create a new project in an organization",
115
+ transport: { gql: { mutation: "createProject" } },
116
+ io: {
117
+ input: {
118
+ orgId: "string",
119
+ name: "string",
120
+ description: "string?"
121
+ },
122
+ output: {
123
+ project: {
124
+ id: "string",
125
+ name: "string",
126
+ description: "string?",
127
+ createdAt: "ISO8601"
128
+ }
129
+ }
130
+ },
131
+ policy: { auth: "user", rbac: "org:member" }
132
+ });
133
+
134
+ contractSpec("saas.billing.recordUsage.v1", {
135
+ goal: "Record usage for billing purposes",
136
+ transport: { gql: { mutation: "recordUsage" } },
137
+ io: {
138
+ input: {
139
+ orgId: "string",
140
+ metric: "enum<'api_calls'|'storage_gb'|'seats'>",
141
+ quantity: "number",
142
+ timestamp: "ISO8601?"
143
+ },
144
+ output: {
145
+ usage: {
146
+ id: "string",
147
+ metric: "string",
148
+ quantity: "number",
149
+ recordedAt: "ISO8601"
150
+ }
151
+ }
152
+ },
153
+ events: ["billing.usage.recorded"]
154
+ });
155
+
156
+ contractSpec("saas.settings.update.v1", {
157
+ goal: "Update organization or user settings",
158
+ transport: { gql: { mutation: "updateSettings" } },
159
+ io: {
160
+ input: {
161
+ scope: "enum<'org'|'user'>",
162
+ targetId: "string",
163
+ settings: "Record<string, unknown>"
164
+ },
165
+ output: {
166
+ settings: {
167
+ scope: "string",
168
+ values: "Record<string, unknown>",
169
+ updatedAt: "ISO8601"
170
+ }
171
+ }
172
+ },
173
+ events: ["settings.updated"]
174
+ });`;
175
+ }
176
+ function generateAgentConsoleSpec(contracts) {
177
+ return `// Agent Console Specs
178
+ // Contracts: ${contracts.join(", ")}
179
+
180
+ contractSpec("agent.run.execute.v1", {
181
+ goal: "Execute an agent run with specified tools",
182
+ transport: { gql: { mutation: "executeAgentRun" } },
183
+ io: {
184
+ input: {
185
+ agentId: "string",
186
+ input: "string",
187
+ tools: "string[]?",
188
+ maxSteps: "number?"
189
+ },
190
+ output: {
191
+ runId: "string",
192
+ status: "enum<'running'|'completed'|'failed'>",
193
+ steps: "number"
194
+ }
195
+ },
196
+ events: ["run.started", "run.completed", "run.failed"]
197
+ });
198
+
199
+ contractSpec("agent.tool.create.v1", {
200
+ goal: "Register a new tool in the tool registry",
201
+ transport: { gql: { mutation: "createTool" } },
202
+ io: {
203
+ input: {
204
+ name: "string",
205
+ description: "string",
206
+ category: "enum<'code'|'data'|'api'|'file'|'custom'>",
207
+ schema: "JSONSchema",
208
+ handler: "string"
209
+ },
210
+ output: {
211
+ tool: {
212
+ id: "string",
213
+ name: "string",
214
+ category: "string",
215
+ createdAt: "ISO8601"
216
+ }
217
+ }
218
+ },
219
+ events: ["tool.created"]
220
+ });
221
+
222
+ contractSpec("agent.agent.create.v1", {
223
+ goal: "Create a new AI agent configuration",
224
+ transport: { gql: { mutation: "createAgent" } },
225
+ io: {
226
+ input: {
227
+ name: "string",
228
+ description: "string",
229
+ model: "string",
230
+ systemPrompt: "string?",
231
+ tools: "string[]?"
232
+ },
233
+ output: {
234
+ agent: {
235
+ id: "string",
236
+ name: "string",
237
+ model: "string",
238
+ toolCount: "number",
239
+ createdAt: "ISO8601"
240
+ }
241
+ }
242
+ },
243
+ events: ["agent.created"]
244
+ });`;
245
+ }
246
+ function generateTodosSpec(contracts) {
247
+ return `// To-dos App Specs
248
+ // Contracts: ${contracts.join(", ")}
249
+
250
+ contractSpec("tasks.board.v1", {
251
+ goal: "Assign and approve craft work",
252
+ transport: { gql: { field: "tasksBoard" } },
253
+ io: {
254
+ input: {
255
+ tenantId: "string",
256
+ assignee: "string?",
257
+ status: "enum<'pending'|'in_progress'|'completed'>?"
258
+ },
259
+ output: {
260
+ tasks: "array<Task>",
261
+ summary: {
262
+ total: "number",
263
+ completed: "number",
264
+ overdue: "number"
265
+ }
266
+ }
267
+ }
268
+ });
269
+
270
+ contractSpec("tasks.create.v1", {
271
+ goal: "Create a new task",
272
+ transport: { gql: { mutation: "createTask" } },
273
+ io: {
274
+ input: {
275
+ title: "string",
276
+ description: "string?",
277
+ assignee: "string?",
278
+ priority: "enum<'low'|'medium'|'high'>",
279
+ dueDate: "ISO8601?"
280
+ },
281
+ output: {
282
+ task: {
283
+ id: "string",
284
+ title: "string",
285
+ status: "string",
286
+ createdAt: "ISO8601"
287
+ }
288
+ }
289
+ },
290
+ events: ["task.created"]
291
+ });
292
+
293
+ contractSpec("tasks.complete.v1", {
294
+ goal: "Mark a task as completed",
295
+ transport: { gql: { mutation: "completeTask" } },
296
+ io: {
297
+ input: { taskId: "string" },
298
+ output: {
299
+ task: {
300
+ id: "string",
301
+ status: "string",
302
+ completedAt: "ISO8601"
303
+ }
304
+ }
305
+ },
306
+ events: ["task.completed"]
307
+ });`;
308
+ }
309
+ function generateMessagingSpec(contracts) {
310
+ return `// Messaging App Specs
311
+ // Contracts: ${contracts.join(", ")}
312
+
313
+ contractSpec("messaging.send.v1", {
314
+ goal: "Deliver intent-rich updates",
315
+ io: {
316
+ input: {
317
+ conversationId: "string",
318
+ body: "richtext",
319
+ attachments: "array<Attachment>?"
320
+ },
321
+ output: {
322
+ messageId: "string",
323
+ deliveredAt: "ISO8601"
324
+ }
325
+ },
326
+ events: ["message.sent", "message.delivered"]
327
+ });
328
+
329
+ contractSpec("messaging.conversation.create.v1", {
330
+ goal: "Start a new conversation",
331
+ transport: { gql: { mutation: "createConversation" } },
332
+ io: {
333
+ input: {
334
+ participants: "string[]",
335
+ title: "string?",
336
+ type: "enum<'direct'|'group'>"
337
+ },
338
+ output: {
339
+ conversation: {
340
+ id: "string",
341
+ title: "string?",
342
+ participantCount: "number",
343
+ createdAt: "ISO8601"
344
+ }
345
+ }
346
+ },
347
+ events: ["conversation.created"]
348
+ });
349
+
350
+ contractSpec("messaging.read.v1", {
351
+ goal: "Mark messages as read",
352
+ transport: { gql: { mutation: "markRead" } },
353
+ io: {
354
+ input: {
355
+ conversationId: "string",
356
+ messageIds: "string[]"
357
+ },
358
+ output: {
359
+ readCount: "number",
360
+ readAt: "ISO8601"
361
+ }
362
+ },
363
+ events: ["message.read"]
364
+ });`;
365
+ }
366
+ function generateRecipeSpec(contracts) {
367
+ return `// Recipe App (i18n) Specs
368
+ // Contracts: ${contracts.join(", ")}
369
+
370
+ contractSpec("recipes.lookup.v1", {
371
+ goal: "Serve bilingual rituals",
372
+ io: {
373
+ input: {
374
+ locale: "enum<'EN'|'FR'>",
375
+ slug: "string"
376
+ },
377
+ output: {
378
+ title: "string",
379
+ content: "markdown",
380
+ ingredients: "array<Ingredient>",
381
+ instructions: "array<Instruction>"
382
+ }
383
+ }
384
+ });
385
+
386
+ contractSpec("recipes.list.v1", {
387
+ goal: "Browse recipes with filtering",
388
+ transport: { gql: { query: "listRecipes" } },
389
+ io: {
390
+ input: {
391
+ locale: "enum<'EN'|'FR'>",
392
+ category: "string?",
393
+ search: "string?",
394
+ favorites: "boolean?"
395
+ },
396
+ output: {
397
+ recipes: "array<RecipeSummary>",
398
+ categories: "array<Category>",
399
+ total: "number"
400
+ }
401
+ }
402
+ });
403
+
404
+ contractSpec("recipes.favorite.toggle.v1", {
405
+ goal: "Toggle recipe favorite status",
406
+ transport: { gql: { mutation: "toggleFavorite" } },
407
+ io: {
408
+ input: { recipeId: "string" },
409
+ output: {
410
+ isFavorite: "boolean",
411
+ totalFavorites: "number"
412
+ }
413
+ },
414
+ events: ["recipe.favorited", "recipe.unfavorited"]
415
+ });`;
416
+ }
417
+ function generateDefaultSpec(templateId) {
418
+ return `// ${templateId} Specs
419
+
420
+ contractSpec("${templateId}.main.v1", {
421
+ goal: "Main operation for ${templateId}",
422
+ transport: { gql: { query: "main" } },
423
+ io: {
424
+ input: {
425
+ id: "string"
426
+ },
427
+ output: {
428
+ result: "unknown"
429
+ }
430
+ }
431
+ });`;
432
+ }
433
+
434
+ // src/hooks/useSpecContent.ts
435
+ import { useCallback, useEffect, useState } from "react";
436
+ "use client";
437
+ var SPEC_STORAGE_KEY = "contractspec-spec-content";
438
+ function useSpecContent(templateId) {
439
+ const { template } = useTemplateRuntime();
440
+ const [content, setContentState] = useState("");
441
+ const [savedContent, setSavedContent] = useState("");
442
+ const [loading, setLoading] = useState(true);
443
+ const [validation, setValidation] = useState(null);
444
+ const [lastSaved, setLastSaved] = useState(null);
445
+ useEffect(() => {
446
+ setLoading(true);
447
+ try {
448
+ const stored = localStorage.getItem(`${SPEC_STORAGE_KEY}-${templateId}`);
449
+ if (stored) {
450
+ const parsed = JSON.parse(stored);
451
+ if (parsed.content) {
452
+ setContentState(parsed.content);
453
+ setSavedContent(parsed.content);
454
+ setLastSaved(parsed.savedAt);
455
+ } else {
456
+ const generated = generateSpecFromTemplate(template);
457
+ setContentState(generated);
458
+ setSavedContent(generated);
459
+ }
460
+ } else {
461
+ const generated = generateSpecFromTemplate(template);
462
+ setContentState(generated);
463
+ setSavedContent(generated);
464
+ }
465
+ } catch {
466
+ const generated = generateSpecFromTemplate(template);
467
+ setContentState(generated);
468
+ setSavedContent(generated);
469
+ }
470
+ setLoading(false);
471
+ }, [templateId]);
472
+ const setContent = useCallback((newContent) => {
473
+ setContentState(newContent);
474
+ setValidation(null);
475
+ }, []);
476
+ const save = useCallback(() => {
477
+ try {
478
+ const savedAt = new Date().toISOString();
479
+ localStorage.setItem(`${SPEC_STORAGE_KEY}-${templateId}`, JSON.stringify({
480
+ content,
481
+ savedAt
482
+ }));
483
+ setSavedContent(content);
484
+ setLastSaved(savedAt);
485
+ } catch {}
486
+ }, [content, templateId]);
487
+ const validate = useCallback(() => {
488
+ const errors = [];
489
+ const lines = content.split(`
490
+ `);
491
+ if (!content.includes("contractSpec(")) {
492
+ errors.push({
493
+ line: 1,
494
+ message: "Spec must contain a contractSpec() definition",
495
+ severity: "error"
496
+ });
497
+ }
498
+ if (!content.includes("goal:")) {
499
+ errors.push({
500
+ line: 1,
501
+ message: "Spec should have a goal field",
502
+ severity: "warning"
503
+ });
504
+ }
505
+ if (!content.includes("io:")) {
506
+ errors.push({
507
+ line: 1,
508
+ message: "Spec should define io (input/output)",
509
+ severity: "warning"
510
+ });
511
+ }
512
+ const openBraces = (content.match(/{/g) ?? []).length;
513
+ const closeBraces = (content.match(/}/g) ?? []).length;
514
+ if (openBraces !== closeBraces) {
515
+ errors.push({
516
+ line: lines.length,
517
+ message: `Unbalanced braces: ${openBraces} opening, ${closeBraces} closing`,
518
+ severity: "error"
519
+ });
520
+ }
521
+ const openParens = (content.match(/\(/g) ?? []).length;
522
+ const closeParens = (content.match(/\)/g) ?? []).length;
523
+ if (openParens !== closeParens) {
524
+ errors.push({
525
+ line: lines.length,
526
+ message: `Unbalanced parentheses: ${openParens} opening, ${closeParens} closing`,
527
+ severity: "error"
528
+ });
529
+ }
530
+ lines.forEach((line, index) => {
531
+ const singleQuotes = (line.match(/'/g) ?? []).length;
532
+ const doubleQuotes = (line.match(/"/g) ?? []).length;
533
+ if (singleQuotes % 2 !== 0) {
534
+ errors.push({
535
+ line: index + 1,
536
+ message: "Unclosed single quote",
537
+ severity: "error"
538
+ });
539
+ }
540
+ if (doubleQuotes % 2 !== 0) {
541
+ errors.push({
542
+ line: index + 1,
543
+ message: "Unclosed double quote",
544
+ severity: "error"
545
+ });
546
+ }
547
+ });
548
+ const result = {
549
+ valid: errors.filter((e) => e.severity === "error").length === 0,
550
+ errors
551
+ };
552
+ setValidation(result);
553
+ return result;
554
+ }, [content]);
555
+ const reset = useCallback(() => {
556
+ const generated = generateSpecFromTemplate(template);
557
+ setContentState(generated);
558
+ setSavedContent(generated);
559
+ setValidation(null);
560
+ setLastSaved(null);
561
+ try {
562
+ localStorage.removeItem(`${SPEC_STORAGE_KEY}-${templateId}`);
563
+ } catch {}
564
+ }, [templateId]);
565
+ return {
566
+ content,
567
+ loading,
568
+ isDirty: content !== savedContent,
569
+ validation,
570
+ setContent,
571
+ save,
572
+ validate,
573
+ reset,
574
+ lastSaved
575
+ };
576
+ }
577
+ export {
578
+ useSpecContent
579
+ };