@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,197 +1 @@
|
|
|
1
|
-
|
|
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/LocalDataIndicator.tsx
|
|
14
|
-
import { RefreshCw, Shield } from "lucide-react";
|
|
15
|
-
import { useState } from "react";
|
|
16
|
-
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
17
|
-
"use client";
|
|
18
|
-
function LocalDataIndicator() {
|
|
19
|
-
const { projectId, templateId, template, installer } = useTemplateRuntime();
|
|
20
|
-
const [isResetting, setIsResetting] = useState(false);
|
|
21
|
-
const handleReset = async () => {
|
|
22
|
-
setIsResetting(true);
|
|
23
|
-
try {
|
|
24
|
-
await installer.install(templateId, { projectId });
|
|
25
|
-
} finally {
|
|
26
|
-
setIsResetting(false);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
return /* @__PURE__ */ jsxDEV("div", {
|
|
30
|
-
className: "inline-flex items-center gap-2 rounded-full border border-border bg-muted/40 px-3 py-1 text-muted-foreground text-xs",
|
|
31
|
-
children: [
|
|
32
|
-
/* @__PURE__ */ jsxDEV(Shield, {
|
|
33
|
-
className: "h-3.5 w-3.5 text-violet-400"
|
|
34
|
-
}, undefined, false, undefined, this),
|
|
35
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
36
|
-
children: [
|
|
37
|
-
"Local runtime ·",
|
|
38
|
-
" ",
|
|
39
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
40
|
-
className: "font-semibold text-foreground",
|
|
41
|
-
children: template.name
|
|
42
|
-
}, undefined, false, undefined, this)
|
|
43
|
-
]
|
|
44
|
-
}, undefined, true, undefined, this),
|
|
45
|
-
/* @__PURE__ */ jsxDEV("button", {
|
|
46
|
-
type: "button",
|
|
47
|
-
className: "inline-flex items-center gap-1 rounded-full border border-border px-2 py-0.5 font-semibold text-[11px] text-muted-foreground hover:text-foreground",
|
|
48
|
-
onClick: handleReset,
|
|
49
|
-
disabled: isResetting,
|
|
50
|
-
children: [
|
|
51
|
-
/* @__PURE__ */ jsxDEV(RefreshCw, {
|
|
52
|
-
className: "h-3 w-3"
|
|
53
|
-
}, undefined, false, undefined, this),
|
|
54
|
-
isResetting ? "Resetting…" : "Reset data"
|
|
55
|
-
]
|
|
56
|
-
}, undefined, true, undefined, this)
|
|
57
|
-
]
|
|
58
|
-
}, undefined, true, undefined, this);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// src/SaveToStudioButton.tsx
|
|
62
|
-
import { Sparkles } from "lucide-react";
|
|
63
|
-
import { useState as useState2 } from "react";
|
|
64
|
-
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
65
|
-
"use client";
|
|
66
|
-
function SaveToStudioButton({
|
|
67
|
-
organizationId = "demo-org",
|
|
68
|
-
projectName,
|
|
69
|
-
endpoint,
|
|
70
|
-
token
|
|
71
|
-
}) {
|
|
72
|
-
const { installer, templateId, template } = useTemplateRuntime();
|
|
73
|
-
const [status, setStatus] = useState2("idle");
|
|
74
|
-
const [error, setError] = useState2(null);
|
|
75
|
-
const handleSave = async () => {
|
|
76
|
-
setStatus("saving");
|
|
77
|
-
setError(null);
|
|
78
|
-
try {
|
|
79
|
-
await installer.saveToStudio({
|
|
80
|
-
templateId,
|
|
81
|
-
projectName: projectName ?? `${template.name} demo`,
|
|
82
|
-
organizationId,
|
|
83
|
-
endpoint,
|
|
84
|
-
token
|
|
85
|
-
});
|
|
86
|
-
setStatus("saved");
|
|
87
|
-
setTimeout(() => setStatus("idle"), 3000);
|
|
88
|
-
} catch (err) {
|
|
89
|
-
setStatus("error");
|
|
90
|
-
setError(err instanceof Error ? err.message : "Unknown error");
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
return /* @__PURE__ */ jsxDEV2("div", {
|
|
94
|
-
className: "flex flex-col items-end gap-1",
|
|
95
|
-
children: [
|
|
96
|
-
/* @__PURE__ */ jsxDEV2("button", {
|
|
97
|
-
type: "button",
|
|
98
|
-
className: "btn-primary inline-flex items-center gap-2 text-sm",
|
|
99
|
-
onClick: handleSave,
|
|
100
|
-
disabled: status === "saving",
|
|
101
|
-
children: [
|
|
102
|
-
/* @__PURE__ */ jsxDEV2(Sparkles, {
|
|
103
|
-
className: "h-4 w-4"
|
|
104
|
-
}, undefined, false, undefined, this),
|
|
105
|
-
status === "saving" ? "Publishing…" : "Save to Studio"
|
|
106
|
-
]
|
|
107
|
-
}, undefined, true, undefined, this),
|
|
108
|
-
status === "error" && error ? /* @__PURE__ */ jsxDEV2("p", {
|
|
109
|
-
className: "text-destructive text-xs",
|
|
110
|
-
children: error
|
|
111
|
-
}, undefined, false, undefined, this) : null,
|
|
112
|
-
status === "saved" ? /* @__PURE__ */ jsxDEV2("p", {
|
|
113
|
-
className: "text-emerald-400 text-xs",
|
|
114
|
-
children: "Template sent to Studio."
|
|
115
|
-
}, undefined, false, undefined, this) : null
|
|
116
|
-
]
|
|
117
|
-
}, undefined, true, undefined, this);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// src/SpecDrivenTemplateShell.tsx
|
|
121
|
-
import {
|
|
122
|
-
BundleProvider,
|
|
123
|
-
BundleRenderer
|
|
124
|
-
} from "@contractspec/lib.surface-runtime/react";
|
|
125
|
-
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
126
|
-
function SpecDrivenTemplateShell({
|
|
127
|
-
plan,
|
|
128
|
-
title,
|
|
129
|
-
description,
|
|
130
|
-
sidebar,
|
|
131
|
-
actions,
|
|
132
|
-
showSaveAction = true,
|
|
133
|
-
saveProps,
|
|
134
|
-
children
|
|
135
|
-
}) {
|
|
136
|
-
const headerContent = /* @__PURE__ */ jsxDEV3("header", {
|
|
137
|
-
className: "rounded-2xl border border-border bg-card p-6 shadow-sm",
|
|
138
|
-
children: [
|
|
139
|
-
/* @__PURE__ */ jsxDEV3("div", {
|
|
140
|
-
className: "flex flex-wrap items-center justify-between gap-4",
|
|
141
|
-
children: [
|
|
142
|
-
/* @__PURE__ */ jsxDEV3("div", {
|
|
143
|
-
children: [
|
|
144
|
-
/* @__PURE__ */ jsxDEV3("p", {
|
|
145
|
-
className: "font-semibold text-muted-foreground text-sm uppercase tracking-wide",
|
|
146
|
-
children: "ContractSpec Templates"
|
|
147
|
-
}, undefined, false, undefined, this),
|
|
148
|
-
/* @__PURE__ */ jsxDEV3("h1", {
|
|
149
|
-
className: "font-bold text-3xl",
|
|
150
|
-
children: title
|
|
151
|
-
}, undefined, false, undefined, this),
|
|
152
|
-
description ? /* @__PURE__ */ jsxDEV3("p", {
|
|
153
|
-
className: "mt-2 max-w-2xl text-muted-foreground text-sm",
|
|
154
|
-
children: description
|
|
155
|
-
}, undefined, false, undefined, this) : null
|
|
156
|
-
]
|
|
157
|
-
}, undefined, true, undefined, this),
|
|
158
|
-
/* @__PURE__ */ jsxDEV3("div", {
|
|
159
|
-
className: "flex flex-col items-end gap-2",
|
|
160
|
-
children: [
|
|
161
|
-
/* @__PURE__ */ jsxDEV3(LocalDataIndicator, {}, undefined, false, undefined, this),
|
|
162
|
-
showSaveAction ? /* @__PURE__ */ jsxDEV3(SaveToStudioButton, {
|
|
163
|
-
...saveProps
|
|
164
|
-
}, undefined, false, undefined, this) : null
|
|
165
|
-
]
|
|
166
|
-
}, undefined, true, undefined, this)
|
|
167
|
-
]
|
|
168
|
-
}, undefined, true, undefined, this),
|
|
169
|
-
actions ? /* @__PURE__ */ jsxDEV3("div", {
|
|
170
|
-
className: "mt-4",
|
|
171
|
-
children: actions
|
|
172
|
-
}, undefined, false, undefined, this) : null
|
|
173
|
-
]
|
|
174
|
-
}, undefined, true, undefined, this);
|
|
175
|
-
const slotContent = {
|
|
176
|
-
header: headerContent,
|
|
177
|
-
primary: /* @__PURE__ */ jsxDEV3("main", {
|
|
178
|
-
className: "space-y-4 p-2",
|
|
179
|
-
children
|
|
180
|
-
}, undefined, false, undefined, this)
|
|
181
|
-
};
|
|
182
|
-
if (sidebar != null) {
|
|
183
|
-
slotContent.sidebar = /* @__PURE__ */ jsxDEV3("aside", {
|
|
184
|
-
className: "rounded-2xl border border-border bg-card p-4",
|
|
185
|
-
children: sidebar
|
|
186
|
-
}, undefined, false, undefined, this);
|
|
187
|
-
}
|
|
188
|
-
return /* @__PURE__ */ jsxDEV3(BundleProvider, {
|
|
189
|
-
plan,
|
|
190
|
-
children: /* @__PURE__ */ jsxDEV3(BundleRenderer, {
|
|
191
|
-
slotContent
|
|
192
|
-
}, undefined, false, undefined, this)
|
|
193
|
-
}, undefined, false, undefined, this);
|
|
194
|
-
}
|
|
195
|
-
export {
|
|
196
|
-
SpecDrivenTemplateShell
|
|
197
|
-
};
|
|
1
|
+
import{createContext as w,useContext as R}from"react";var y=Symbol.for("@contractspec/lib.example-shared-ui/template-runtime-context");function I(){let e=globalThis;return e[y]??=w(null),e[y]}var z=I();function p(){let e=R(z);if(!e)throw Error("useTemplateRuntime must be used within a TemplateRuntimeProvider");return e}import{RefreshCw as $,Shield as q}from"lucide-react";import{useState as F}from"react";import{jsx as f,jsxs as g}from"react/jsx-runtime";function S(){let{projectId:e,templateId:m,template:a,installer:o}=p(),[r,n]=F(!1),i=async()=>{n(!0);try{await o.install(m,{projectId:e})}finally{n(!1)}};return g("div",{className:"inline-flex items-center gap-2 rounded-full border border-border bg-muted/40 px-3 py-1 text-muted-foreground text-xs",children:[f(q,{className:"h-3.5 w-3.5 text-violet-400"}),g("span",{children:["Local runtime ·"," ",f("span",{className:"font-semibold text-foreground",children:a.name})]}),g("button",{type:"button",className:"inline-flex items-center gap-1 rounded-full border border-border px-2 py-0.5 font-semibold text-[11px] text-muted-foreground hover:text-foreground",onClick:i,disabled:r,children:[f($,{className:"h-3 w-3"}),r?"Resetting…":"Reset data"]})]})}import{Sparkles as G}from"lucide-react";import{useState as N}from"react";import{jsx as b,jsxs as h}from"react/jsx-runtime";function k({organizationId:e="demo-org",projectName:m,endpoint:a,token:o}){let{installer:r,templateId:n,template:i}=p(),[l,d]=N("idle"),[u,c]=N(null);return h("div",{className:"flex flex-col items-end gap-1",children:[h("button",{type:"button",className:"btn-primary inline-flex items-center gap-2 text-sm",onClick:async()=>{d("saving"),c(null);try{await r.saveToStudio({templateId:n,projectName:m??`${i.name} demo`,organizationId:e,endpoint:a,token:o}),d("saved"),setTimeout(()=>d("idle"),3000)}catch(v){d("error"),c(v instanceof Error?v.message:"Unknown error")}},disabled:l==="saving",children:[b(G,{className:"h-4 w-4"}),l==="saving"?"Publishing…":"Save to Studio"]}),l==="error"&&u?b("p",{className:"text-destructive text-xs",children:u}):null,l==="saved"?b("p",{className:"text-emerald-400 text-xs",children:"Template sent to Studio."}):null]})}import{BundleProvider as H,BundleRenderer as J}from"@contractspec/lib.surface-runtime/react";import{jsx as t,jsxs as s}from"react/jsx-runtime";function x({plan:e,title:m,description:a,sidebar:o,actions:r,showSaveAction:n=!0,saveProps:i,children:l}){let u={header:s("header",{className:"rounded-2xl border border-border bg-card p-6 shadow-sm",children:[s("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[s("div",{children:[t("p",{className:"font-semibold text-muted-foreground text-sm uppercase tracking-wide",children:"ContractSpec Templates"}),t("h1",{className:"font-bold text-3xl",children:m}),a?t("p",{className:"mt-2 max-w-2xl text-muted-foreground text-sm",children:a}):null]}),s("div",{className:"flex flex-col items-end gap-2",children:[t(S,{}),n?t(k,{...i}):null]})]}),r?t("div",{className:"mt-4",children:r}):null]}),primary:t("main",{className:"space-y-4 p-2",children:l})};if(o!=null)u.sidebar=t("aside",{className:"rounded-2xl border border-border bg-card p-4",children:o});return t(H,{plan:e,children:t(J,{slotContent:u})})}export{x as SpecDrivenTemplateShell};
|
|
@@ -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 g,useContext as i}from"react";var L=Symbol.for("@contractspec/lib.example-shared-ui/template-runtime-context");function m(){let q=globalThis;return q[L]??=g(null),q[L]}var c=m();function x(){let q=i(c);if(!q)throw Error("useTemplateRuntime must be used within a TemplateRuntimeProvider");return q}function F(q){let Z=q?.id??"unknown";if(!q)return I(Z);switch(Z){case"crm-pipeline":return p(q.schema.contracts);case"saas-boilerplate":return d(q.schema.contracts);case"agent-console":return l(q.schema.contracts);case"todos-app":return r(q.schema.contracts);case"messaging-app":return s(q.schema.contracts);case"recipe-app-i18n":return o(q.schema.contracts);default:return I(Z)}}function p(q){return`// CRM Pipeline Specs
|
|
2
|
+
// Contracts: ${q.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 d(q){return`// SaaS Boilerplate Specs
|
|
72
|
+
// Contracts: ${q.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 l(q){return`// Agent Console Specs
|
|
136
|
+
// Contracts: ${q.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 r(q){return`// To-dos App Specs
|
|
203
|
+
// Contracts: ${q.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 s(q){return`// Messaging App Specs
|
|
263
|
+
// Contracts: ${q.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 o(q){return`// Recipe App (i18n) Specs
|
|
317
|
+
// Contracts: ${q.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 I(q){return`// ${q} Specs
|
|
419
365
|
|
|
420
|
-
contractSpec("${
|
|
421
|
-
goal: "Main operation for ${
|
|
366
|
+
contractSpec("${q}.main.v1", {
|
|
367
|
+
goal: "Main operation for ${q}",
|
|
422
368
|
transport: { gql: { query: "main" } },
|
|
423
369
|
io: {
|
|
424
370
|
input: {
|
|
@@ -428,292 +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
|
-
|
|
578
|
-
// src/SpecEditorPanel.tsx
|
|
579
|
-
import { Button, LoaderBlock } from "@contractspec/lib.design-system";
|
|
580
|
-
import { Badge } from "@contractspec/lib.ui-kit-web/ui/badge";
|
|
581
|
-
import { useCallback as useCallback2, useEffect as useEffect2 } from "react";
|
|
582
|
-
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
583
|
-
"use client";
|
|
584
|
-
function SpecEditorPanel({
|
|
585
|
-
templateId,
|
|
586
|
-
SpecEditor,
|
|
587
|
-
onLog
|
|
588
|
-
}) {
|
|
589
|
-
const {
|
|
590
|
-
content,
|
|
591
|
-
loading,
|
|
592
|
-
isDirty,
|
|
593
|
-
validation,
|
|
594
|
-
setContent,
|
|
595
|
-
save,
|
|
596
|
-
validate,
|
|
597
|
-
reset,
|
|
598
|
-
lastSaved
|
|
599
|
-
} = useSpecContent(templateId);
|
|
600
|
-
useEffect2(() => {
|
|
601
|
-
if (!loading && content) {
|
|
602
|
-
onLog?.(`Spec loaded for ${templateId}`);
|
|
603
|
-
}
|
|
604
|
-
}, [loading, content, templateId, onLog]);
|
|
605
|
-
const handleSave = useCallback2(() => {
|
|
606
|
-
save();
|
|
607
|
-
onLog?.("Spec saved locally");
|
|
608
|
-
}, [save, onLog]);
|
|
609
|
-
const handleValidate = useCallback2(() => {
|
|
610
|
-
const result = validate();
|
|
611
|
-
if (result.valid) {
|
|
612
|
-
onLog?.("Spec validation passed");
|
|
613
|
-
} else {
|
|
614
|
-
const errorCount = result.errors.filter((e) => e.severity === "error").length;
|
|
615
|
-
const warnCount = result.errors.filter((e) => e.severity === "warning").length;
|
|
616
|
-
onLog?.(`Spec validation: ${errorCount} errors, ${warnCount} warnings`);
|
|
617
|
-
}
|
|
618
|
-
}, [validate, onLog]);
|
|
619
|
-
const handleReset = useCallback2(() => {
|
|
620
|
-
reset();
|
|
621
|
-
onLog?.("Spec reset to template defaults");
|
|
622
|
-
}, [reset, onLog]);
|
|
623
|
-
if (loading) {
|
|
624
|
-
return /* @__PURE__ */ jsxDEV(LoaderBlock, {
|
|
625
|
-
label: "Loading spec..."
|
|
626
|
-
}, undefined, false, undefined, this);
|
|
627
|
-
}
|
|
628
|
-
return /* @__PURE__ */ jsxDEV("div", {
|
|
629
|
-
className: "space-y-4",
|
|
630
|
-
children: [
|
|
631
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
632
|
-
className: "flex items-center justify-between",
|
|
633
|
-
children: [
|
|
634
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
635
|
-
className: "flex items-center gap-2",
|
|
636
|
-
children: [
|
|
637
|
-
/* @__PURE__ */ jsxDEV(Button, {
|
|
638
|
-
variant: "default",
|
|
639
|
-
size: "sm",
|
|
640
|
-
onClick: handleSave,
|
|
641
|
-
children: "Save"
|
|
642
|
-
}, undefined, false, undefined, this),
|
|
643
|
-
/* @__PURE__ */ jsxDEV(Button, {
|
|
644
|
-
variant: "outline",
|
|
645
|
-
size: "sm",
|
|
646
|
-
onClick: handleValidate,
|
|
647
|
-
children: "Validate"
|
|
648
|
-
}, undefined, false, undefined, this),
|
|
649
|
-
isDirty && /* @__PURE__ */ jsxDEV(Badge, {
|
|
650
|
-
variant: "secondary",
|
|
651
|
-
className: "border-amber-500/30 bg-amber-500/20 text-amber-400",
|
|
652
|
-
children: "Unsaved changes"
|
|
653
|
-
}, undefined, false, undefined, this),
|
|
654
|
-
validation && /* @__PURE__ */ jsxDEV(Badge, {
|
|
655
|
-
variant: validation.valid ? "default" : "destructive",
|
|
656
|
-
className: validation.valid ? "border-green-500/30 bg-green-500/20 text-green-400" : "",
|
|
657
|
-
children: validation.valid ? "Valid" : `${validation.errors.filter((e) => e.severity === "error").length} errors`
|
|
658
|
-
}, undefined, false, undefined, this)
|
|
659
|
-
]
|
|
660
|
-
}, undefined, true, undefined, this),
|
|
661
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
662
|
-
className: "flex items-center gap-2",
|
|
663
|
-
children: [
|
|
664
|
-
lastSaved && /* @__PURE__ */ jsxDEV("span", {
|
|
665
|
-
className: "text-muted-foreground text-xs",
|
|
666
|
-
children: [
|
|
667
|
-
"Last saved: ",
|
|
668
|
-
new Date(lastSaved).toLocaleTimeString()
|
|
669
|
-
]
|
|
670
|
-
}, undefined, true, undefined, this),
|
|
671
|
-
/* @__PURE__ */ jsxDEV(Button, {
|
|
672
|
-
variant: "ghost",
|
|
673
|
-
size: "sm",
|
|
674
|
-
onPress: handleReset,
|
|
675
|
-
children: "Reset"
|
|
676
|
-
}, undefined, false, undefined, this)
|
|
677
|
-
]
|
|
678
|
-
}, undefined, true, undefined, this)
|
|
679
|
-
]
|
|
680
|
-
}, undefined, true, undefined, this),
|
|
681
|
-
validation && validation.errors.length > 0 && /* @__PURE__ */ jsxDEV("div", {
|
|
682
|
-
className: "rounded-lg border border-amber-500/50 bg-amber-500/10 p-3",
|
|
683
|
-
children: [
|
|
684
|
-
/* @__PURE__ */ jsxDEV("p", {
|
|
685
|
-
className: "mb-2 font-semibold text-amber-400 text-xs uppercase",
|
|
686
|
-
children: "Validation Issues"
|
|
687
|
-
}, undefined, false, undefined, this),
|
|
688
|
-
/* @__PURE__ */ jsxDEV("ul", {
|
|
689
|
-
className: "space-y-1",
|
|
690
|
-
children: validation.errors.map((error, index) => /* @__PURE__ */ jsxDEV("li", {
|
|
691
|
-
className: `text-xs ${error.severity === "error" ? "text-red-400" : "text-amber-400"}`,
|
|
692
|
-
children: [
|
|
693
|
-
"Line ",
|
|
694
|
-
error.line,
|
|
695
|
-
": ",
|
|
696
|
-
error.message
|
|
697
|
-
]
|
|
698
|
-
}, `${error.line}-${error.message}-${index}`, true, undefined, this))
|
|
699
|
-
}, undefined, false, undefined, this)
|
|
700
|
-
]
|
|
701
|
-
}, undefined, true, undefined, this),
|
|
702
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
703
|
-
className: "rounded-2xl border border-border bg-card p-4",
|
|
704
|
-
children: /* @__PURE__ */ jsxDEV(SpecEditor, {
|
|
705
|
-
projectId: "sandbox",
|
|
706
|
-
type: "CAPABILITY",
|
|
707
|
-
content,
|
|
708
|
-
onChange: setContent,
|
|
709
|
-
metadata: { template: templateId },
|
|
710
|
-
onSave: handleSave,
|
|
711
|
-
onValidate: handleValidate
|
|
712
|
-
}, undefined, false, undefined, this)
|
|
713
|
-
}, undefined, false, undefined, this)
|
|
714
|
-
]
|
|
715
|
-
}, undefined, true, undefined, this);
|
|
716
|
-
}
|
|
717
|
-
export {
|
|
718
|
-
SpecEditorPanel
|
|
719
|
-
};
|
|
377
|
+
});`}import{useCallback as A,useEffect as n,useState as K}from"react";var R="contractspec-spec-content";function v(q){let{template:Z}=x(),[H,$]=K(""),[w,X]=K(""),[y,M]=K(!0),[O,D]=K(null),[V,N]=K(null);n(()=>{M(!0);try{let z=localStorage.getItem(`${R}-${q}`);if(z){let W=JSON.parse(z);if(W.content)$(W.content),X(W.content),N(W.savedAt);else{let U=F(Z);$(U),X(U)}}else{let W=F(Z);$(W),X(W)}}catch{let z=F(Z);$(z),X(z)}M(!1)},[q]);let Y=A((z)=>{$(z),D(null)},[]),h=A(()=>{try{let z=new Date().toISOString();localStorage.setItem(`${R}-${q}`,JSON.stringify({content:H,savedAt:z})),X(H),N(z)}catch{}},[H,q]),P=A(()=>{let z=[],W=H.split(`
|
|
378
|
+
`);if(!H.includes("contractSpec("))z.push({line:1,message:"Spec must contain a contractSpec() definition",severity:"error"});if(!H.includes("goal:"))z.push({line:1,message:"Spec should have a goal field",severity:"warning"});if(!H.includes("io:"))z.push({line:1,message:"Spec should define io (input/output)",severity:"warning"});let U=(H.match(/{/g)??[]).length,B=(H.match(/}/g)??[]).length;if(U!==B)z.push({line:W.length,message:`Unbalanced braces: ${U} opening, ${B} closing`,severity:"error"});let _=(H.match(/\(/g)??[]).length,j=(H.match(/\)/g)??[]).length;if(_!==j)z.push({line:W.length,message:`Unbalanced parentheses: ${_} opening, ${j} closing`,severity:"error"});W.forEach((f,E)=>{let u=(f.match(/'/g)??[]).length,S=(f.match(/"/g)??[]).length;if(u%2!==0)z.push({line:E+1,message:"Unclosed single quote",severity:"error"});if(S%2!==0)z.push({line:E+1,message:"Unclosed double quote",severity:"error"})});let T={valid:z.filter((f)=>f.severity==="error").length===0,errors:z};return D(T),T},[H]),J=A(()=>{let z=F(Z);$(z),X(z),D(null),N(null);try{localStorage.removeItem(`${R}-${q}`)}catch{}},[q]);return{content:H,loading:y,isDirty:H!==w,validation:O,setContent:Y,save:h,validate:P,reset:J,lastSaved:V}}import{Button as b,LoaderBlock as a}from"@contractspec/lib.design-system";import{Badge as C}from"@contractspec/lib.ui-kit-web/ui/badge";import{useCallback as k,useEffect as t}from"react";import{jsx as Q,jsxs as G}from"react/jsx-runtime";function Xq({templateId:q,SpecEditor:Z,onLog:H}){let{content:$,loading:w,isDirty:X,validation:y,setContent:M,save:O,validate:D,reset:V,lastSaved:N}=v(q);t(()=>{if(!w&&$)H?.(`Spec loaded for ${q}`)},[w,$,q,H]);let Y=k(()=>{O(),H?.("Spec saved locally")},[O,H]),h=k(()=>{let J=D();if(J.valid)H?.("Spec validation passed");else{let z=J.errors.filter((U)=>U.severity==="error").length,W=J.errors.filter((U)=>U.severity==="warning").length;H?.(`Spec validation: ${z} errors, ${W} warnings`)}},[D,H]),P=k(()=>{V(),H?.("Spec reset to template defaults")},[V,H]);if(w)return Q(a,{label:"Loading spec..."});return G("div",{className:"space-y-4",children:[G("div",{className:"flex items-center justify-between",children:[G("div",{className:"flex items-center gap-2",children:[Q(b,{variant:"default",size:"sm",onClick:Y,children:"Save"}),Q(b,{variant:"outline",size:"sm",onClick:h,children:"Validate"}),X&&Q(C,{variant:"secondary",className:"border-amber-500/30 bg-amber-500/20 text-amber-400",children:"Unsaved changes"}),y&&Q(C,{variant:y.valid?"default":"destructive",className:y.valid?"border-green-500/30 bg-green-500/20 text-green-400":"",children:y.valid?"Valid":`${y.errors.filter((J)=>J.severity==="error").length} errors`})]}),G("div",{className:"flex items-center gap-2",children:[N&&G("span",{className:"text-muted-foreground text-xs",children:["Last saved: ",new Date(N).toLocaleTimeString()]}),Q(b,{variant:"ghost",size:"sm",onPress:P,children:"Reset"})]})]}),y&&y.errors.length>0&&G("div",{className:"rounded-lg border border-amber-500/50 bg-amber-500/10 p-3",children:[Q("p",{className:"mb-2 font-semibold text-amber-400 text-xs uppercase",children:"Validation Issues"}),Q("ul",{className:"space-y-1",children:y.errors.map((J,z)=>G("li",{className:`text-xs ${J.severity==="error"?"text-red-400":"text-amber-400"}`,children:["Line ",J.line,": ",J.message]},`${J.line}-${J.message}-${z}`))})]}),Q("div",{className:"rounded-2xl border border-border bg-card p-4",children:Q(Z,{projectId:"sandbox",type:"CAPABILITY",content:$,onChange:M,metadata:{template:q},onSave:Y,onValidate:h})})]})}export{Xq as SpecEditorPanel};
|