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