@contractspec/lib.example-shared-ui 6.0.17 → 6.0.19
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 +28 -0
- package/dist/EvolutionDashboard.js +1 -803
- package/dist/EvolutionSidebar.js +1 -531
- package/dist/LocalDataIndicator.js +1 -68
- package/dist/MarkdownView.js +1 -213
- package/dist/OverlayContextProvider.js +1 -202
- package/dist/PersonalizationInsights.js +1 -455
- package/dist/SaveToStudioButton.js +1 -79
- package/dist/SpecDrivenTemplateShell.js +1 -203
- package/dist/SpecEditorPanel.js +17 -364
- package/dist/TemplateShell.js +1 -195
- package/dist/browser/EvolutionDashboard.js +1 -803
- package/dist/browser/EvolutionSidebar.js +1 -531
- package/dist/browser/LocalDataIndicator.js +1 -68
- package/dist/browser/MarkdownView.js +1 -213
- package/dist/browser/OverlayContextProvider.js +1 -202
- package/dist/browser/PersonalizationInsights.js +1 -455
- package/dist/browser/SaveToStudioButton.js +1 -79
- package/dist/browser/SpecDrivenTemplateShell.js +1 -203
- package/dist/browser/SpecEditorPanel.js +17 -364
- package/dist/browser/TemplateShell.js +1 -195
- package/dist/browser/bundles/ExampleTemplateBundle.js +1 -85
- package/dist/browser/bundles/index.js +1 -85
- package/dist/browser/hooks/index.js +40 -1151
- 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 -224
- package/dist/browser/hooks/useWorkflowComposer.js +24 -483
- package/dist/browser/index.js +40 -3122
- package/dist/browser/lib/component-registry.js +1 -48
- package/dist/browser/lib/runtime-context.js +1 -21
- 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 -1151
- 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 -224
- package/dist/hooks/useWorkflowComposer.js +24 -483
- package/dist/index.js +40 -3122
- package/dist/lib/component-registry.js +1 -48
- package/dist/lib/runtime-context.js +1 -21
- 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 -68
- package/dist/node/MarkdownView.js +1 -213
- package/dist/node/OverlayContextProvider.js +1 -202
- package/dist/node/PersonalizationInsights.js +1 -455
- package/dist/node/SaveToStudioButton.js +1 -79
- package/dist/node/SpecDrivenTemplateShell.js +1 -203
- package/dist/node/SpecEditorPanel.js +17 -364
- package/dist/node/TemplateShell.js +1 -195
- package/dist/node/bundles/ExampleTemplateBundle.js +1 -85
- package/dist/node/bundles/index.js +1 -85
- package/dist/node/hooks/index.js +40 -1151
- 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 -224
- package/dist/node/hooks/useWorkflowComposer.js +24 -483
- package/dist/node/index.js +40 -3122
- package/dist/node/lib/component-registry.js +1 -48
- package/dist/node/lib/runtime-context.js +1 -21
- 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 +13 -13
- package/src/lib/component-registry.tsx +2 -1
- package/src/lib/runtime-context.tsx +1 -1
- package/src/lib/singletons.test.ts +19 -22
|
@@ -1,47 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
"use client";
|
|
4
|
-
var TEMPLATE_RUNTIME_CONTEXT_KEY = Symbol.for("@contractspec/lib.example-shared-ui/template-runtime-context");
|
|
5
|
-
function getTemplateRuntimeContextSingleton() {
|
|
6
|
-
const store = globalThis;
|
|
7
|
-
store[TEMPLATE_RUNTIME_CONTEXT_KEY] ??= createContext(null);
|
|
8
|
-
return store[TEMPLATE_RUNTIME_CONTEXT_KEY];
|
|
9
|
-
}
|
|
10
|
-
var TemplateRuntimeContext = getTemplateRuntimeContextSingleton();
|
|
11
|
-
function useTemplateRuntime() {
|
|
12
|
-
const context = useContext(TemplateRuntimeContext);
|
|
13
|
-
if (!context) {
|
|
14
|
-
throw new Error("useTemplateRuntime must be used within a TemplateRuntimeProvider");
|
|
15
|
-
}
|
|
16
|
-
return context;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// src/utils/generateSpecFromTemplate.ts
|
|
20
|
-
function generateSpecFromTemplate(template) {
|
|
21
|
-
const templateId = template?.id ?? "unknown";
|
|
22
|
-
if (!template) {
|
|
23
|
-
return generateDefaultSpec(templateId);
|
|
24
|
-
}
|
|
25
|
-
switch (templateId) {
|
|
26
|
-
case "crm-pipeline":
|
|
27
|
-
return generateCrmPipelineSpec(template.schema.contracts);
|
|
28
|
-
case "saas-boilerplate":
|
|
29
|
-
return generateSaasBoilerplateSpec(template.schema.contracts);
|
|
30
|
-
case "agent-console":
|
|
31
|
-
return generateAgentConsoleSpec(template.schema.contracts);
|
|
32
|
-
case "todos-app":
|
|
33
|
-
return generateTodosSpec(template.schema.contracts);
|
|
34
|
-
case "messaging-app":
|
|
35
|
-
return generateMessagingSpec(template.schema.contracts);
|
|
36
|
-
case "recipe-app-i18n":
|
|
37
|
-
return generateRecipeSpec(template.schema.contracts);
|
|
38
|
-
default:
|
|
39
|
-
return generateDefaultSpec(templateId);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function generateCrmPipelineSpec(contracts) {
|
|
43
|
-
return `// CRM Pipeline Specs
|
|
44
|
-
// 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(", ")}
|
|
45
3
|
|
|
46
4
|
contractSpec("crm.deal.updateStage.v1", {
|
|
47
5
|
goal: "Move a deal to a different pipeline stage",
|
|
@@ -110,11 +68,8 @@ contractSpec("crm.contact.list.v1", {
|
|
|
110
68
|
hasMore: "boolean"
|
|
111
69
|
}
|
|
112
70
|
}
|
|
113
|
-
})
|
|
114
|
-
}
|
|
115
|
-
function generateSaasBoilerplateSpec(contracts) {
|
|
116
|
-
return `// SaaS Boilerplate Specs
|
|
117
|
-
// Contracts: ${contracts.join(", ")}
|
|
71
|
+
});`}function g(h){return`// SaaS Boilerplate Specs
|
|
72
|
+
// Contracts: ${h.join(", ")}
|
|
118
73
|
|
|
119
74
|
contractSpec("saas.project.create.v1", {
|
|
120
75
|
goal: "Create a new project in an organization",
|
|
@@ -177,11 +132,8 @@ contractSpec("saas.settings.update.v1", {
|
|
|
177
132
|
}
|
|
178
133
|
},
|
|
179
134
|
events: ["settings.updated"]
|
|
180
|
-
})
|
|
181
|
-
}
|
|
182
|
-
function generateAgentConsoleSpec(contracts) {
|
|
183
|
-
return `// Agent Console Specs
|
|
184
|
-
// Contracts: ${contracts.join(", ")}
|
|
135
|
+
});`}function i(h){return`// Agent Console Specs
|
|
136
|
+
// Contracts: ${h.join(", ")}
|
|
185
137
|
|
|
186
138
|
contractSpec("agent.run.execute.v1", {
|
|
187
139
|
goal: "Execute an agent run with specified tools",
|
|
@@ -247,11 +199,8 @@ contractSpec("agent.agent.create.v1", {
|
|
|
247
199
|
}
|
|
248
200
|
},
|
|
249
201
|
events: ["agent.created"]
|
|
250
|
-
})
|
|
251
|
-
}
|
|
252
|
-
function generateTodosSpec(contracts) {
|
|
253
|
-
return `// To-dos App Specs
|
|
254
|
-
// Contracts: ${contracts.join(", ")}
|
|
202
|
+
});`}function S(h){return`// To-dos App Specs
|
|
203
|
+
// Contracts: ${h.join(", ")}
|
|
255
204
|
|
|
256
205
|
contractSpec("tasks.board.v1", {
|
|
257
206
|
goal: "Assign and approve craft work",
|
|
@@ -310,11 +259,8 @@ contractSpec("tasks.complete.v1", {
|
|
|
310
259
|
}
|
|
311
260
|
},
|
|
312
261
|
events: ["task.completed"]
|
|
313
|
-
})
|
|
314
|
-
}
|
|
315
|
-
function generateMessagingSpec(contracts) {
|
|
316
|
-
return `// Messaging App Specs
|
|
317
|
-
// Contracts: ${contracts.join(", ")}
|
|
262
|
+
});`}function m(h){return`// Messaging App Specs
|
|
263
|
+
// Contracts: ${h.join(", ")}
|
|
318
264
|
|
|
319
265
|
contractSpec("messaging.send.v1", {
|
|
320
266
|
goal: "Deliver intent-rich updates",
|
|
@@ -367,11 +313,8 @@ contractSpec("messaging.read.v1", {
|
|
|
367
313
|
}
|
|
368
314
|
},
|
|
369
315
|
events: ["message.read"]
|
|
370
|
-
})
|
|
371
|
-
}
|
|
372
|
-
function generateRecipeSpec(contracts) {
|
|
373
|
-
return `// Recipe App (i18n) Specs
|
|
374
|
-
// Contracts: ${contracts.join(", ")}
|
|
316
|
+
});`}function d(h){return`// Recipe App (i18n) Specs
|
|
317
|
+
// Contracts: ${h.join(", ")}
|
|
375
318
|
|
|
376
319
|
contractSpec("recipes.lookup.v1", {
|
|
377
320
|
goal: "Serve bilingual rituals",
|
|
@@ -418,13 +361,10 @@ contractSpec("recipes.favorite.toggle.v1", {
|
|
|
418
361
|
}
|
|
419
362
|
},
|
|
420
363
|
events: ["recipe.favorited", "recipe.unfavorited"]
|
|
421
|
-
})
|
|
422
|
-
}
|
|
423
|
-
function generateDefaultSpec(templateId) {
|
|
424
|
-
return `// ${templateId} Specs
|
|
364
|
+
});`}function M(h){return`// ${h} Specs
|
|
425
365
|
|
|
426
|
-
contractSpec("${
|
|
427
|
-
goal: "Main operation for ${
|
|
366
|
+
contractSpec("${h}.main.v1", {
|
|
367
|
+
goal: "Main operation for ${h}",
|
|
428
368
|
transport: { gql: { query: "main" } },
|
|
429
369
|
io: {
|
|
430
370
|
input: {
|
|
@@ -434,152 +374,5 @@ contractSpec("${templateId}.main.v1", {
|
|
|
434
374
|
result: "unknown"
|
|
435
375
|
}
|
|
436
376
|
}
|
|
437
|
-
})
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// src/hooks/useSpecContent.ts
|
|
441
|
-
import { useCallback, useEffect, useState } from "react";
|
|
442
|
-
"use client";
|
|
443
|
-
var SPEC_STORAGE_KEY = "contractspec-spec-content";
|
|
444
|
-
function useSpecContent(templateId) {
|
|
445
|
-
const { template } = useTemplateRuntime();
|
|
446
|
-
const [content, setContentState] = useState("");
|
|
447
|
-
const [savedContent, setSavedContent] = useState("");
|
|
448
|
-
const [loading, setLoading] = useState(true);
|
|
449
|
-
const [validation, setValidation] = useState(null);
|
|
450
|
-
const [lastSaved, setLastSaved] = useState(null);
|
|
451
|
-
useEffect(() => {
|
|
452
|
-
setLoading(true);
|
|
453
|
-
try {
|
|
454
|
-
const stored = localStorage.getItem(`${SPEC_STORAGE_KEY}-${templateId}`);
|
|
455
|
-
if (stored) {
|
|
456
|
-
const parsed = JSON.parse(stored);
|
|
457
|
-
if (parsed.content) {
|
|
458
|
-
setContentState(parsed.content);
|
|
459
|
-
setSavedContent(parsed.content);
|
|
460
|
-
setLastSaved(parsed.savedAt);
|
|
461
|
-
} else {
|
|
462
|
-
const generated = generateSpecFromTemplate(template);
|
|
463
|
-
setContentState(generated);
|
|
464
|
-
setSavedContent(generated);
|
|
465
|
-
}
|
|
466
|
-
} else {
|
|
467
|
-
const generated = generateSpecFromTemplate(template);
|
|
468
|
-
setContentState(generated);
|
|
469
|
-
setSavedContent(generated);
|
|
470
|
-
}
|
|
471
|
-
} catch {
|
|
472
|
-
const generated = generateSpecFromTemplate(template);
|
|
473
|
-
setContentState(generated);
|
|
474
|
-
setSavedContent(generated);
|
|
475
|
-
}
|
|
476
|
-
setLoading(false);
|
|
477
|
-
}, [templateId]);
|
|
478
|
-
const setContent = useCallback((newContent) => {
|
|
479
|
-
setContentState(newContent);
|
|
480
|
-
setValidation(null);
|
|
481
|
-
}, []);
|
|
482
|
-
const save = useCallback(() => {
|
|
483
|
-
try {
|
|
484
|
-
const savedAt = new Date().toISOString();
|
|
485
|
-
localStorage.setItem(`${SPEC_STORAGE_KEY}-${templateId}`, JSON.stringify({
|
|
486
|
-
content,
|
|
487
|
-
savedAt
|
|
488
|
-
}));
|
|
489
|
-
setSavedContent(content);
|
|
490
|
-
setLastSaved(savedAt);
|
|
491
|
-
} catch {}
|
|
492
|
-
}, [content, templateId]);
|
|
493
|
-
const validate = useCallback(() => {
|
|
494
|
-
const errors = [];
|
|
495
|
-
const lines = content.split(`
|
|
496
|
-
`);
|
|
497
|
-
if (!content.includes("contractSpec(")) {
|
|
498
|
-
errors.push({
|
|
499
|
-
line: 1,
|
|
500
|
-
message: "Spec must contain a contractSpec() definition",
|
|
501
|
-
severity: "error"
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
if (!content.includes("goal:")) {
|
|
505
|
-
errors.push({
|
|
506
|
-
line: 1,
|
|
507
|
-
message: "Spec should have a goal field",
|
|
508
|
-
severity: "warning"
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
if (!content.includes("io:")) {
|
|
512
|
-
errors.push({
|
|
513
|
-
line: 1,
|
|
514
|
-
message: "Spec should define io (input/output)",
|
|
515
|
-
severity: "warning"
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
const openBraces = (content.match(/{/g) ?? []).length;
|
|
519
|
-
const closeBraces = (content.match(/}/g) ?? []).length;
|
|
520
|
-
if (openBraces !== closeBraces) {
|
|
521
|
-
errors.push({
|
|
522
|
-
line: lines.length,
|
|
523
|
-
message: `Unbalanced braces: ${openBraces} opening, ${closeBraces} closing`,
|
|
524
|
-
severity: "error"
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
const openParens = (content.match(/\(/g) ?? []).length;
|
|
528
|
-
const closeParens = (content.match(/\)/g) ?? []).length;
|
|
529
|
-
if (openParens !== closeParens) {
|
|
530
|
-
errors.push({
|
|
531
|
-
line: lines.length,
|
|
532
|
-
message: `Unbalanced parentheses: ${openParens} opening, ${closeParens} closing`,
|
|
533
|
-
severity: "error"
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
lines.forEach((line, index) => {
|
|
537
|
-
const singleQuotes = (line.match(/'/g) ?? []).length;
|
|
538
|
-
const doubleQuotes = (line.match(/"/g) ?? []).length;
|
|
539
|
-
if (singleQuotes % 2 !== 0) {
|
|
540
|
-
errors.push({
|
|
541
|
-
line: index + 1,
|
|
542
|
-
message: "Unclosed single quote",
|
|
543
|
-
severity: "error"
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
if (doubleQuotes % 2 !== 0) {
|
|
547
|
-
errors.push({
|
|
548
|
-
line: index + 1,
|
|
549
|
-
message: "Unclosed double quote",
|
|
550
|
-
severity: "error"
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
const result = {
|
|
555
|
-
valid: errors.filter((e) => e.severity === "error").length === 0,
|
|
556
|
-
errors
|
|
557
|
-
};
|
|
558
|
-
setValidation(result);
|
|
559
|
-
return result;
|
|
560
|
-
}, [content]);
|
|
561
|
-
const reset = useCallback(() => {
|
|
562
|
-
const generated = generateSpecFromTemplate(template);
|
|
563
|
-
setContentState(generated);
|
|
564
|
-
setSavedContent(generated);
|
|
565
|
-
setValidation(null);
|
|
566
|
-
setLastSaved(null);
|
|
567
|
-
try {
|
|
568
|
-
localStorage.removeItem(`${SPEC_STORAGE_KEY}-${templateId}`);
|
|
569
|
-
} catch {}
|
|
570
|
-
}, [templateId]);
|
|
571
|
-
return {
|
|
572
|
-
content,
|
|
573
|
-
loading,
|
|
574
|
-
isDirty: content !== savedContent,
|
|
575
|
-
validation,
|
|
576
|
-
setContent,
|
|
577
|
-
save,
|
|
578
|
-
validate,
|
|
579
|
-
reset,
|
|
580
|
-
lastSaved
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
|
-
export {
|
|
584
|
-
useSpecContent
|
|
585
|
-
};
|
|
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};
|