@contractspec/lib.example-shared-ui 6.0.16 → 6.0.18
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.
- package/.turbo/turbo-build.log +81 -81
- package/CHANGELOG.md +32 -0
- package/dist/EvolutionDashboard.js +1 -803
- package/dist/EvolutionSidebar.js +1 -531
- package/dist/LocalDataIndicator.js +1 -62
- package/dist/MarkdownView.js +1 -207
- package/dist/OverlayContextProvider.js +1 -202
- package/dist/PersonalizationInsights.js +1 -455
- package/dist/SaveToStudioButton.js +1 -73
- package/dist/SpecDrivenTemplateShell.js +1 -197
- package/dist/SpecEditorPanel.js +17 -358
- package/dist/TemplateShell.js +1 -189
- package/dist/browser/EvolutionDashboard.js +1 -803
- package/dist/browser/EvolutionSidebar.js +1 -531
- package/dist/browser/LocalDataIndicator.js +1 -62
- package/dist/browser/MarkdownView.js +1 -207
- package/dist/browser/OverlayContextProvider.js +1 -202
- package/dist/browser/PersonalizationInsights.js +1 -455
- package/dist/browser/SaveToStudioButton.js +1 -73
- package/dist/browser/SpecDrivenTemplateShell.js +1 -197
- package/dist/browser/SpecEditorPanel.js +17 -358
- package/dist/browser/TemplateShell.js +1 -189
- package/dist/browser/bundles/ExampleTemplateBundle.js +1 -85
- package/dist/browser/bundles/index.js +1 -85
- package/dist/browser/hooks/index.js +40 -1145
- package/dist/browser/hooks/useBehaviorTracking.js +1 -157
- package/dist/browser/hooks/useEvolution.js +1 -260
- package/dist/browser/hooks/useRegistryTemplates.js +1 -31
- package/dist/browser/hooks/useSpecContent.js +17 -218
- package/dist/browser/hooks/useWorkflowComposer.js +24 -483
- package/dist/browser/index.js +40 -3110
- package/dist/browser/lib/component-registry.js +1 -42
- package/dist/browser/lib/runtime-context.js +1 -15
- package/dist/browser/markdown/formatPresentationName.js +1 -9
- package/dist/browser/markdown/useMarkdownPresentation.js +1 -65
- package/dist/browser/utils/fetchPresentationData.js +1 -15
- package/dist/browser/utils/generateSpecFromTemplate.js +16 -62
- package/dist/browser/utils/index.js +16 -76
- package/dist/bundles/ExampleTemplateBundle.js +1 -85
- package/dist/bundles/index.js +1 -85
- package/dist/hooks/index.js +40 -1145
- package/dist/hooks/useBehaviorTracking.js +1 -157
- package/dist/hooks/useEvolution.js +1 -260
- package/dist/hooks/useRegistryTemplates.js +1 -31
- package/dist/hooks/useSpecContent.js +17 -218
- package/dist/hooks/useWorkflowComposer.js +24 -483
- package/dist/index.js +40 -3110
- package/dist/lib/component-registry.js +1 -42
- package/dist/lib/runtime-context.d.ts +2 -1
- package/dist/lib/runtime-context.js +1 -15
- package/dist/lib/singletons.test.d.ts +1 -0
- package/dist/markdown/formatPresentationName.js +1 -9
- package/dist/markdown/useMarkdownPresentation.js +1 -65
- package/dist/node/EvolutionDashboard.js +1 -803
- package/dist/node/EvolutionSidebar.js +1 -531
- package/dist/node/LocalDataIndicator.js +1 -62
- package/dist/node/MarkdownView.js +1 -207
- package/dist/node/OverlayContextProvider.js +1 -202
- package/dist/node/PersonalizationInsights.js +1 -455
- package/dist/node/SaveToStudioButton.js +1 -73
- package/dist/node/SpecDrivenTemplateShell.js +1 -197
- package/dist/node/SpecEditorPanel.js +17 -358
- package/dist/node/TemplateShell.js +1 -189
- package/dist/node/bundles/ExampleTemplateBundle.js +1 -85
- package/dist/node/bundles/index.js +1 -85
- package/dist/node/hooks/index.js +40 -1145
- package/dist/node/hooks/useBehaviorTracking.js +1 -157
- package/dist/node/hooks/useEvolution.js +1 -260
- package/dist/node/hooks/useRegistryTemplates.js +1 -31
- package/dist/node/hooks/useSpecContent.js +17 -218
- package/dist/node/hooks/useWorkflowComposer.js +24 -483
- package/dist/node/index.js +40 -3110
- package/dist/node/lib/component-registry.js +1 -42
- package/dist/node/lib/runtime-context.js +1 -15
- package/dist/node/markdown/formatPresentationName.js +1 -9
- package/dist/node/markdown/useMarkdownPresentation.js +1 -65
- package/dist/node/utils/fetchPresentationData.js +1 -15
- package/dist/node/utils/generateSpecFromTemplate.js +16 -62
- package/dist/node/utils/index.js +16 -76
- package/dist/utils/fetchPresentationData.js +1 -15
- package/dist/utils/generateSpecFromTemplate.js +16 -62
- package/dist/utils/index.js +16 -76
- package/package.json +14 -14
- package/src/lib/component-registry.tsx +16 -1
- package/src/lib/runtime-context.tsx +17 -3
- package/src/lib/singletons.test.ts +51 -0
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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(", ")}
|
|
1
|
+
import{createContext as E,useContext as T}from"react";var F=Symbol.for("@contractspec/lib.example-shared-ui/template-runtime-context");function I(){let h=globalThis;return h[F]??=E(null),h[F]}var u=I();function K(){let h=T(u);if(!h)throw Error("useTemplateRuntime must be used within a TemplateRuntimeProvider");return h}function Z(h){let z=h?.id??"unknown";if(!h)return M(z);switch(z){case"crm-pipeline":return C(h.schema.contracts);case"saas-boilerplate":return g(h.schema.contracts);case"agent-console":return i(h.schema.contracts);case"todos-app":return S(h.schema.contracts);case"messaging-app":return m(h.schema.contracts);case"recipe-app-i18n":return d(h.schema.contracts);default:return M(z)}}function C(h){return`// CRM Pipeline Specs
|
|
2
|
+
// Contracts: ${h.join(", ")}
|
|
39
3
|
|
|
40
4
|
contractSpec("crm.deal.updateStage.v1", {
|
|
41
5
|
goal: "Move a deal to a different pipeline stage",
|
|
@@ -104,11 +68,8 @@ contractSpec("crm.contact.list.v1", {
|
|
|
104
68
|
hasMore: "boolean"
|
|
105
69
|
}
|
|
106
70
|
}
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
function generateSaasBoilerplateSpec(contracts) {
|
|
110
|
-
return `// SaaS Boilerplate Specs
|
|
111
|
-
// Contracts: ${contracts.join(", ")}
|
|
71
|
+
});`}function g(h){return`// SaaS Boilerplate Specs
|
|
72
|
+
// Contracts: ${h.join(", ")}
|
|
112
73
|
|
|
113
74
|
contractSpec("saas.project.create.v1", {
|
|
114
75
|
goal: "Create a new project in an organization",
|
|
@@ -171,11 +132,8 @@ contractSpec("saas.settings.update.v1", {
|
|
|
171
132
|
}
|
|
172
133
|
},
|
|
173
134
|
events: ["settings.updated"]
|
|
174
|
-
})
|
|
175
|
-
}
|
|
176
|
-
function generateAgentConsoleSpec(contracts) {
|
|
177
|
-
return `// Agent Console Specs
|
|
178
|
-
// Contracts: ${contracts.join(", ")}
|
|
135
|
+
});`}function i(h){return`// Agent Console Specs
|
|
136
|
+
// Contracts: ${h.join(", ")}
|
|
179
137
|
|
|
180
138
|
contractSpec("agent.run.execute.v1", {
|
|
181
139
|
goal: "Execute an agent run with specified tools",
|
|
@@ -241,11 +199,8 @@ contractSpec("agent.agent.create.v1", {
|
|
|
241
199
|
}
|
|
242
200
|
},
|
|
243
201
|
events: ["agent.created"]
|
|
244
|
-
})
|
|
245
|
-
}
|
|
246
|
-
function generateTodosSpec(contracts) {
|
|
247
|
-
return `// To-dos App Specs
|
|
248
|
-
// Contracts: ${contracts.join(", ")}
|
|
202
|
+
});`}function S(h){return`// To-dos App Specs
|
|
203
|
+
// Contracts: ${h.join(", ")}
|
|
249
204
|
|
|
250
205
|
contractSpec("tasks.board.v1", {
|
|
251
206
|
goal: "Assign and approve craft work",
|
|
@@ -304,11 +259,8 @@ contractSpec("tasks.complete.v1", {
|
|
|
304
259
|
}
|
|
305
260
|
},
|
|
306
261
|
events: ["task.completed"]
|
|
307
|
-
})
|
|
308
|
-
}
|
|
309
|
-
function generateMessagingSpec(contracts) {
|
|
310
|
-
return `// Messaging App Specs
|
|
311
|
-
// Contracts: ${contracts.join(", ")}
|
|
262
|
+
});`}function m(h){return`// Messaging App Specs
|
|
263
|
+
// Contracts: ${h.join(", ")}
|
|
312
264
|
|
|
313
265
|
contractSpec("messaging.send.v1", {
|
|
314
266
|
goal: "Deliver intent-rich updates",
|
|
@@ -361,11 +313,8 @@ contractSpec("messaging.read.v1", {
|
|
|
361
313
|
}
|
|
362
314
|
},
|
|
363
315
|
events: ["message.read"]
|
|
364
|
-
})
|
|
365
|
-
}
|
|
366
|
-
function generateRecipeSpec(contracts) {
|
|
367
|
-
return `// Recipe App (i18n) Specs
|
|
368
|
-
// Contracts: ${contracts.join(", ")}
|
|
316
|
+
});`}function d(h){return`// Recipe App (i18n) Specs
|
|
317
|
+
// Contracts: ${h.join(", ")}
|
|
369
318
|
|
|
370
319
|
contractSpec("recipes.lookup.v1", {
|
|
371
320
|
goal: "Serve bilingual rituals",
|
|
@@ -412,13 +361,10 @@ contractSpec("recipes.favorite.toggle.v1", {
|
|
|
412
361
|
}
|
|
413
362
|
},
|
|
414
363
|
events: ["recipe.favorited", "recipe.unfavorited"]
|
|
415
|
-
})
|
|
416
|
-
}
|
|
417
|
-
function generateDefaultSpec(templateId) {
|
|
418
|
-
return `// ${templateId} Specs
|
|
364
|
+
});`}function M(h){return`// ${h} Specs
|
|
419
365
|
|
|
420
|
-
contractSpec("${
|
|
421
|
-
goal: "Main operation for ${
|
|
366
|
+
contractSpec("${h}.main.v1", {
|
|
367
|
+
goal: "Main operation for ${h}",
|
|
422
368
|
transport: { gql: { query: "main" } },
|
|
423
369
|
io: {
|
|
424
370
|
input: {
|
|
@@ -428,152 +374,5 @@ contractSpec("${templateId}.main.v1", {
|
|
|
428
374
|
result: "unknown"
|
|
429
375
|
}
|
|
430
376
|
}
|
|
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
|
-
};
|
|
377
|
+
});`}import{useCallback as U,useEffect as c,useState as $}from"react";var D="contractspec-spec-content";function a(h){let{template:z}=K(),[q,H]=$(""),[O,J]=$(""),[Y,G]=$(!0),[f,X]=$(null),[L,w]=$(null);c(()=>{G(!0);try{let j=localStorage.getItem(`${D}-${h}`);if(j){let y=JSON.parse(j);if(y.content)H(y.content),J(y.content),w(y.savedAt);else{let W=Z(z);H(W),J(W)}}else{let y=Z(z);H(y),J(y)}}catch{let j=Z(z);H(j),J(j)}G(!1)},[h]);let x=U((j)=>{H(j),X(null)},[]),A=U(()=>{try{let j=new Date().toISOString();localStorage.setItem(`${D}-${h}`,JSON.stringify({content:q,savedAt:j})),J(q),w(j)}catch{}},[q,h]),R=U(()=>{let j=[],y=q.split(`
|
|
378
|
+
`);if(!q.includes("contractSpec("))j.push({line:1,message:"Spec must contain a contractSpec() definition",severity:"error"});if(!q.includes("goal:"))j.push({line:1,message:"Spec should have a goal field",severity:"warning"});if(!q.includes("io:"))j.push({line:1,message:"Spec should define io (input/output)",severity:"warning"});let W=(q.match(/{/g)??[]).length,V=(q.match(/}/g)??[]).length;if(W!==V)j.push({line:y.length,message:`Unbalanced braces: ${W} opening, ${V} closing`,severity:"error"});let N=(q.match(/\(/g)??[]).length,b=(q.match(/\)/g)??[]).length;if(N!==b)j.push({line:y.length,message:`Unbalanced parentheses: ${N} opening, ${b} closing`,severity:"error"});y.forEach((Q,B)=>{let _=(Q.match(/'/g)??[]).length,v=(Q.match(/"/g)??[]).length;if(_%2!==0)j.push({line:B+1,message:"Unclosed single quote",severity:"error"});if(v%2!==0)j.push({line:B+1,message:"Unclosed double quote",severity:"error"})});let k={valid:j.filter((Q)=>Q.severity==="error").length===0,errors:j};return X(k),k},[q]),P=U(()=>{let j=Z(z);H(j),J(j),X(null),w(null);try{localStorage.removeItem(`${D}-${h}`)}catch{}},[h]);return{content:q,loading:Y,isDirty:q!==O,validation:f,setContent:x,save:A,validate:R,reset:P,lastSaved:L}}export{a as useSpecContent};
|