@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,493 @@
1
+ // src/hooks/useWorkflowComposer.ts
2
+ import { useCallback, useEffect, useMemo, useState } from "react";
3
+ "use client";
4
+ function useWorkflowComposer(templateId) {
5
+ const [selectedWorkflow, setSelectedWorkflow] = useState(null);
6
+ const [extensions, setExtensions] = useState([]);
7
+ const [loading, _setLoading] = useState(false);
8
+ const [error, _setError] = useState(null);
9
+ const baseWorkflows = useMemo(() => getTemplateWorkflows(templateId), [templateId]);
10
+ useEffect(() => {
11
+ const firstWorkflow = baseWorkflows[0];
12
+ if (baseWorkflows.length > 0 && !selectedWorkflow && firstWorkflow) {
13
+ setSelectedWorkflow(firstWorkflow.meta.key);
14
+ }
15
+ }, [baseWorkflows, selectedWorkflow]);
16
+ const currentBase = useMemo(() => {
17
+ return baseWorkflows.find((w) => w.meta.key === selectedWorkflow) ?? null;
18
+ }, [baseWorkflows, selectedWorkflow]);
19
+ const compose = useCallback((scope) => {
20
+ if (!currentBase)
21
+ return null;
22
+ const applicableExtensions = extensions.filter((ext) => ext.workflow === currentBase.meta.key).filter((ext) => matchesScope(ext, scope)).sort((a, b) => (a.priority ?? 0) - (b.priority ?? 0));
23
+ if (applicableExtensions.length === 0) {
24
+ return currentBase;
25
+ }
26
+ let composedWorkflow = { ...currentBase, steps: [...currentBase.steps] };
27
+ for (const extension of applicableExtensions) {
28
+ composedWorkflow = applyExtension(composedWorkflow, extension);
29
+ }
30
+ return composedWorkflow;
31
+ }, [currentBase, extensions]);
32
+ const workflow = useMemo(() => compose(), [compose]);
33
+ const selectWorkflow = useCallback((workflowName) => {
34
+ setSelectedWorkflow(workflowName);
35
+ }, []);
36
+ const addExtension = useCallback((extension) => {
37
+ setExtensions((prev) => [...prev, extension]);
38
+ }, []);
39
+ const removeExtension = useCallback((workflowName, index) => {
40
+ setExtensions((prev) => {
41
+ const forWorkflow = prev.filter((e) => e.workflow === workflowName);
42
+ const others = prev.filter((e) => e.workflow !== workflowName);
43
+ forWorkflow.splice(index, 1);
44
+ return [...others, ...forWorkflow];
45
+ });
46
+ }, []);
47
+ const generateSpecCode = useCallback(() => {
48
+ const composed = workflow;
49
+ if (!composed) {
50
+ return "// No workflow selected";
51
+ }
52
+ const stepsCode = composed.steps.map((step) => ` {
53
+ id: '${step.id}',
54
+ name: '${step.name}',
55
+ type: '${step.type}',${step.description ? `
56
+ description: '${step.description}',` : ""}${step.next ? `
57
+ next: ${JSON.stringify(step.next)},` : ""}${step.condition ? `
58
+ condition: '${step.condition}',` : ""}${step.timeout ? `
59
+ timeout: ${step.timeout},` : ""}${step.retries ? `
60
+ retries: ${step.retries},` : ""}${step.onError ? `
61
+ onError: '${step.onError}',` : ""}
62
+ }`).join(`,
63
+ `);
64
+ const extensionsCode = extensions.length > 0 ? `
65
+
66
+ // Extensions applied:
67
+ ${extensions.map((ext) => `// - ${ext.workflow} (priority: ${ext.priority ?? 0})${ext.customSteps?.length ? ` +${ext.customSteps.length} steps` : ""}${ext.hiddenSteps?.length ? ` -${ext.hiddenSteps.length} hidden` : ""}`).join(`
68
+ `)}` : "";
69
+ return `// Workflow Spec: ${composed.meta.key} v${composed.meta.version}
70
+ // Generated from ${templateId} template
71
+ ${extensionsCode}
72
+
73
+ import { workflowSpec } from '@contractspec/lib.contracts/workflow';
74
+
75
+ export const ${toCamelCase(composed.meta.key)}Workflow = workflowSpec({
76
+ meta: {
77
+ key: '${composed.meta.key}',
78
+ version: ${composed.meta.version},${composed.meta.description ? `
79
+ description: '${composed.meta.description}',` : ""}
80
+ },
81
+ start: '${composed.start}',
82
+ steps: [
83
+ ${stepsCode}
84
+ ],${composed.context ? `
85
+ context: ${JSON.stringify(composed.context, null, 2)},` : ""}
86
+ });
87
+ `;
88
+ }, [workflow, extensions, templateId]);
89
+ return {
90
+ workflow,
91
+ baseWorkflows,
92
+ extensions,
93
+ selectWorkflow,
94
+ addExtension,
95
+ removeExtension,
96
+ compose,
97
+ generateSpecCode,
98
+ loading,
99
+ error
100
+ };
101
+ }
102
+ function matchesScope(extension, scope) {
103
+ if (!scope)
104
+ return true;
105
+ if (extension.tenantId && extension.tenantId !== scope.tenantId) {
106
+ return false;
107
+ }
108
+ if (extension.role && extension.role !== scope.role) {
109
+ return false;
110
+ }
111
+ if (extension.device && extension.device !== scope.device) {
112
+ return false;
113
+ }
114
+ return true;
115
+ }
116
+ function applyExtension(workflow, extension) {
117
+ let steps = [...workflow.steps];
118
+ if (extension.hiddenSteps) {
119
+ steps = steps.filter((s) => !extension.hiddenSteps?.includes(s.id));
120
+ }
121
+ if (extension.customSteps) {
122
+ for (const injection of extension.customSteps) {
123
+ const stepToInject = {
124
+ ...injection.inject,
125
+ id: injection.id ?? injection.inject.id
126
+ };
127
+ if (injection.after) {
128
+ const afterIndex = steps.findIndex((s) => s.id === injection.after);
129
+ if (afterIndex !== -1) {
130
+ steps.splice(afterIndex + 1, 0, stepToInject);
131
+ }
132
+ } else if (injection.before) {
133
+ const beforeIndex = steps.findIndex((s) => s.id === injection.before);
134
+ if (beforeIndex !== -1) {
135
+ steps.splice(beforeIndex, 0, stepToInject);
136
+ }
137
+ } else {
138
+ steps.push(stepToInject);
139
+ }
140
+ }
141
+ }
142
+ return { ...workflow, steps };
143
+ }
144
+ function toCamelCase(str) {
145
+ return str.replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase()).replace(/^./, (c) => c.toLowerCase());
146
+ }
147
+ function getTemplateWorkflows(templateId) {
148
+ const templateWorkflows = {
149
+ "crm-pipeline": [
150
+ {
151
+ meta: {
152
+ key: "deal.qualification",
153
+ version: "1.0.0",
154
+ description: "Deal qualification workflow"
155
+ },
156
+ start: "lead-received",
157
+ steps: [
158
+ {
159
+ id: "lead-received",
160
+ name: "Lead Received",
161
+ type: "action",
162
+ description: "New lead enters the pipeline",
163
+ next: "qualify-lead"
164
+ },
165
+ {
166
+ id: "qualify-lead",
167
+ name: "Qualify Lead",
168
+ type: "decision",
169
+ description: "Determine if lead meets qualification criteria",
170
+ next: ["qualified", "disqualified"],
171
+ condition: "lead.score >= threshold"
172
+ },
173
+ {
174
+ id: "qualified",
175
+ name: "Lead Qualified",
176
+ type: "action",
177
+ next: "assign-rep"
178
+ },
179
+ {
180
+ id: "disqualified",
181
+ name: "Lead Disqualified",
182
+ type: "end"
183
+ },
184
+ {
185
+ id: "assign-rep",
186
+ name: "Assign Sales Rep",
187
+ type: "action",
188
+ next: "complete"
189
+ },
190
+ {
191
+ id: "complete",
192
+ name: "Workflow Complete",
193
+ type: "end"
194
+ }
195
+ ]
196
+ },
197
+ {
198
+ meta: {
199
+ key: "deal.closing",
200
+ version: "1.0.0",
201
+ description: "Deal closing workflow"
202
+ },
203
+ start: "proposal-sent",
204
+ steps: [
205
+ {
206
+ id: "proposal-sent",
207
+ name: "Proposal Sent",
208
+ type: "action",
209
+ next: "wait-response"
210
+ },
211
+ {
212
+ id: "wait-response",
213
+ name: "Wait for Response",
214
+ type: "wait",
215
+ timeout: 604800000,
216
+ next: "negotiate",
217
+ onError: "follow-up"
218
+ },
219
+ {
220
+ id: "follow-up",
221
+ name: "Follow Up",
222
+ type: "action",
223
+ next: "wait-response",
224
+ retries: 3
225
+ },
226
+ {
227
+ id: "negotiate",
228
+ name: "Negotiation",
229
+ type: "action",
230
+ next: "finalize"
231
+ },
232
+ {
233
+ id: "finalize",
234
+ name: "Finalize Deal",
235
+ type: "decision",
236
+ next: ["won", "lost"],
237
+ condition: "deal.accepted"
238
+ },
239
+ {
240
+ id: "won",
241
+ name: "Deal Won",
242
+ type: "end"
243
+ },
244
+ {
245
+ id: "lost",
246
+ name: "Deal Lost",
247
+ type: "end"
248
+ }
249
+ ]
250
+ }
251
+ ],
252
+ "saas-boilerplate": [
253
+ {
254
+ meta: {
255
+ key: "user.onboarding",
256
+ version: "1.0.0",
257
+ description: "User onboarding workflow"
258
+ },
259
+ start: "signup",
260
+ steps: [
261
+ {
262
+ id: "signup",
263
+ name: "User Signup",
264
+ type: "action",
265
+ next: "verify-email"
266
+ },
267
+ {
268
+ id: "verify-email",
269
+ name: "Verify Email",
270
+ type: "wait",
271
+ timeout: 86400000,
272
+ next: "profile-setup",
273
+ onError: "resend-verification"
274
+ },
275
+ {
276
+ id: "resend-verification",
277
+ name: "Resend Verification",
278
+ type: "action",
279
+ next: "verify-email",
280
+ retries: 2
281
+ },
282
+ {
283
+ id: "profile-setup",
284
+ name: "Setup Profile",
285
+ type: "action",
286
+ next: "onboarding-tour"
287
+ },
288
+ {
289
+ id: "onboarding-tour",
290
+ name: "Onboarding Tour",
291
+ type: "action",
292
+ next: "complete"
293
+ },
294
+ {
295
+ id: "complete",
296
+ name: "Onboarding Complete",
297
+ type: "end"
298
+ }
299
+ ]
300
+ }
301
+ ],
302
+ "agent-console": [
303
+ {
304
+ meta: {
305
+ key: "agent.execution",
306
+ version: "1.0.0",
307
+ description: "Agent execution workflow"
308
+ },
309
+ start: "receive-task",
310
+ steps: [
311
+ {
312
+ id: "receive-task",
313
+ name: "Receive Task",
314
+ type: "action",
315
+ next: "plan-execution"
316
+ },
317
+ {
318
+ id: "plan-execution",
319
+ name: "Plan Execution",
320
+ type: "action",
321
+ next: "execute-steps"
322
+ },
323
+ {
324
+ id: "execute-steps",
325
+ name: "Execute Steps",
326
+ type: "parallel",
327
+ next: ["tool-call", "observe", "reason"]
328
+ },
329
+ {
330
+ id: "tool-call",
331
+ name: "Tool Call",
332
+ type: "action",
333
+ next: "evaluate"
334
+ },
335
+ {
336
+ id: "observe",
337
+ name: "Observe",
338
+ type: "action",
339
+ next: "evaluate"
340
+ },
341
+ {
342
+ id: "reason",
343
+ name: "Reason",
344
+ type: "action",
345
+ next: "evaluate"
346
+ },
347
+ {
348
+ id: "evaluate",
349
+ name: "Evaluate Result",
350
+ type: "decision",
351
+ condition: "task.isComplete",
352
+ next: ["complete", "execute-steps"]
353
+ },
354
+ {
355
+ id: "complete",
356
+ name: "Task Complete",
357
+ type: "end"
358
+ }
359
+ ]
360
+ }
361
+ ],
362
+ "todos-app": [
363
+ {
364
+ meta: {
365
+ key: "task.lifecycle",
366
+ version: "1.0.0",
367
+ description: "Task lifecycle workflow"
368
+ },
369
+ start: "created",
370
+ steps: [
371
+ {
372
+ id: "created",
373
+ name: "Task Created",
374
+ type: "action",
375
+ next: "in-progress"
376
+ },
377
+ {
378
+ id: "in-progress",
379
+ name: "In Progress",
380
+ type: "action",
381
+ next: "review"
382
+ },
383
+ {
384
+ id: "review",
385
+ name: "Review",
386
+ type: "decision",
387
+ condition: "task.approved",
388
+ next: ["done", "in-progress"]
389
+ },
390
+ {
391
+ id: "done",
392
+ name: "Done",
393
+ type: "end"
394
+ }
395
+ ]
396
+ }
397
+ ],
398
+ "messaging-app": [
399
+ {
400
+ meta: {
401
+ key: "message.delivery",
402
+ version: "1.0.0",
403
+ description: "Message delivery workflow"
404
+ },
405
+ start: "compose",
406
+ steps: [
407
+ {
408
+ id: "compose",
409
+ name: "Compose Message",
410
+ type: "action",
411
+ next: "send"
412
+ },
413
+ {
414
+ id: "send",
415
+ name: "Send Message",
416
+ type: "action",
417
+ next: "deliver"
418
+ },
419
+ {
420
+ id: "deliver",
421
+ name: "Deliver",
422
+ type: "decision",
423
+ condition: "recipient.online",
424
+ next: ["delivered", "queue"]
425
+ },
426
+ {
427
+ id: "queue",
428
+ name: "Queue for Delivery",
429
+ type: "wait",
430
+ next: "deliver"
431
+ },
432
+ {
433
+ id: "delivered",
434
+ name: "Message Delivered",
435
+ type: "action",
436
+ next: "read"
437
+ },
438
+ {
439
+ id: "read",
440
+ name: "Message Read",
441
+ type: "end"
442
+ }
443
+ ]
444
+ }
445
+ ],
446
+ "recipe-app-i18n": [
447
+ {
448
+ meta: {
449
+ key: "recipe.creation",
450
+ version: "1.0.0",
451
+ description: "Recipe creation workflow"
452
+ },
453
+ start: "draft",
454
+ steps: [
455
+ {
456
+ id: "draft",
457
+ name: "Draft Recipe",
458
+ type: "action",
459
+ next: "add-ingredients"
460
+ },
461
+ {
462
+ id: "add-ingredients",
463
+ name: "Add Ingredients",
464
+ type: "action",
465
+ next: "add-steps"
466
+ },
467
+ {
468
+ id: "add-steps",
469
+ name: "Add Steps",
470
+ type: "action",
471
+ next: "review"
472
+ },
473
+ {
474
+ id: "review",
475
+ name: "Review Recipe",
476
+ type: "decision",
477
+ condition: "recipe.isComplete",
478
+ next: ["publish", "draft"]
479
+ },
480
+ {
481
+ id: "publish",
482
+ name: "Publish Recipe",
483
+ type: "end"
484
+ }
485
+ ]
486
+ }
487
+ ]
488
+ };
489
+ return templateWorkflows[templateId] ?? [];
490
+ }
491
+ export {
492
+ useWorkflowComposer
493
+ };