@contractspec/lib.surface-runtime 0.2.3 → 0.3.2
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/dist/adapters/ai-sdk-stub.js +1 -6
- package/dist/adapters/blocknote-stub.js +3 -8
- package/dist/adapters/dnd-kit-adapter.js +6 -11
- package/dist/adapters/dnd-kit-stub.js +1 -6
- package/dist/adapters/floating-ui-stub.js +4 -9
- package/dist/adapters/index.js +7 -176
- package/dist/adapters/interfaces.js +0 -1
- package/dist/adapters/motion-stub.js +2 -7
- package/dist/adapters/resizable-panels-stub.js +7 -12
- package/dist/browser/adapters/ai-sdk-stub.js +1 -5
- package/dist/browser/adapters/blocknote-stub.js +3 -7
- package/dist/browser/adapters/dnd-kit-adapter.js +6 -10
- package/dist/browser/adapters/dnd-kit-stub.js +1 -5
- package/dist/browser/adapters/floating-ui-stub.js +4 -8
- package/dist/browser/adapters/index.js +7 -175
- package/dist/browser/adapters/motion-stub.js +2 -6
- package/dist/browser/adapters/resizable-panels-stub.js +5 -9
- package/dist/browser/evals/golden-harness.js +4 -825
- package/dist/browser/examples/pm-workbench.bundle.js +2 -316
- package/dist/browser/i18n/catalogs/en.js +1 -5
- package/dist/browser/i18n/catalogs/es.js +1 -5
- package/dist/browser/i18n/catalogs/fr.js +1 -5
- package/dist/browser/i18n/catalogs/index.js +3 -133
- package/dist/browser/i18n/index.js +3 -168
- package/dist/browser/i18n/keys.js +1 -5
- package/dist/browser/i18n/messages.js +6 -137
- package/dist/browser/index.js +4 -2466
- package/dist/browser/react/BundleProvider.js +12 -19
- package/dist/browser/react/BundleRenderer.js +19 -662
- package/dist/browser/react/OverlayConflictResolver.js +12 -180
- package/dist/browser/react/PatchProposalCard.js +9 -177
- package/dist/browser/react/RegionRenderer.js +14 -60
- package/dist/browser/react/SlotRenderer.js +15 -58
- package/dist/browser/react/WidgetPalette.js +6 -10
- package/dist/browser/react/index.js +14 -790
- package/dist/browser/runtime/apply-surface-patch.js +3 -208
- package/dist/browser/runtime/audit-events.js +8 -19
- package/dist/browser/runtime/build-context.js +2 -6
- package/dist/browser/runtime/extension-registry.js +3 -9
- package/dist/browser/runtime/field-renderer-registry.js +5 -11
- package/dist/browser/runtime/index.js +54 -1487
- package/dist/browser/runtime/overlay-alignment.js +8 -19
- package/dist/browser/runtime/overlay-signer.js +2 -7
- package/dist/browser/runtime/override-store.js +3 -9
- package/dist/browser/runtime/planner-prompt.js +2 -6
- package/dist/browser/runtime/planner-tools.js +3 -9
- package/dist/browser/runtime/policy-eval.js +3 -135
- package/dist/browser/runtime/preference-adapter.js +2 -62
- package/dist/browser/runtime/resolve-bundle.js +10 -447
- package/dist/browser/runtime/resolve-preferences.js +3 -7
- package/dist/browser/runtime/rollback.js +2 -325
- package/dist/browser/runtime/widget-registry.js +1 -5
- package/dist/browser/spec/define-module-bundle.js +2 -67
- package/dist/browser/spec/index.js +9 -317
- package/dist/browser/spec/validate-bundle.js +3 -8
- package/dist/browser/spec/validate-surface-patch.js +5 -11
- package/dist/browser/telemetry/index.js +4 -16
- package/dist/browser/telemetry/surface-metrics.js +7 -16
- package/dist/evals/golden-context.js +0 -1
- package/dist/evals/golden-harness.js +4 -826
- package/dist/examples/pm-workbench.bundle.js +2 -317
- package/dist/i18n/catalogs/en.js +1 -6
- package/dist/i18n/catalogs/es.js +1 -6
- package/dist/i18n/catalogs/fr.js +1 -6
- package/dist/i18n/catalogs/index.js +3 -134
- package/dist/i18n/index.js +3 -169
- package/dist/i18n/keys.js +1 -6
- package/dist/i18n/messages.js +6 -138
- package/dist/index.js +4 -2467
- package/dist/node/adapters/ai-sdk-stub.js +1 -5
- package/dist/node/adapters/blocknote-stub.js +3 -7
- package/dist/node/adapters/dnd-kit-adapter.js +6 -10
- package/dist/node/adapters/dnd-kit-stub.js +1 -5
- package/dist/node/adapters/floating-ui-stub.js +4 -8
- package/dist/node/adapters/index.js +7 -175
- package/dist/node/adapters/motion-stub.js +2 -6
- package/dist/node/adapters/resizable-panels-stub.js +5 -9
- package/dist/node/evals/golden-harness.js +4 -825
- package/dist/node/examples/pm-workbench.bundle.js +2 -316
- package/dist/node/i18n/catalogs/en.js +1 -5
- package/dist/node/i18n/catalogs/es.js +1 -5
- package/dist/node/i18n/catalogs/fr.js +1 -5
- package/dist/node/i18n/catalogs/index.js +3 -133
- package/dist/node/i18n/index.js +3 -168
- package/dist/node/i18n/keys.js +1 -5
- package/dist/node/i18n/messages.js +6 -137
- package/dist/node/index.js +4 -2466
- package/dist/node/react/BundleProvider.js +12 -19
- package/dist/node/react/BundleRenderer.js +19 -662
- package/dist/node/react/OverlayConflictResolver.js +12 -180
- package/dist/node/react/PatchProposalCard.js +9 -177
- package/dist/node/react/RegionRenderer.js +14 -60
- package/dist/node/react/SlotRenderer.js +15 -58
- package/dist/node/react/WidgetPalette.js +6 -10
- package/dist/node/react/index.js +14 -790
- package/dist/node/runtime/apply-surface-patch.js +3 -208
- package/dist/node/runtime/audit-events.js +8 -19
- package/dist/node/runtime/build-context.js +2 -6
- package/dist/node/runtime/extension-registry.js +3 -9
- package/dist/node/runtime/field-renderer-registry.js +5 -11
- package/dist/node/runtime/index.js +54 -1487
- package/dist/node/runtime/overlay-alignment.js +8 -19
- package/dist/node/runtime/overlay-signer.js +2 -7
- package/dist/node/runtime/override-store.js +3 -9
- package/dist/node/runtime/planner-prompt.js +2 -6
- package/dist/node/runtime/planner-tools.js +3 -9
- package/dist/node/runtime/policy-eval.js +3 -135
- package/dist/node/runtime/preference-adapter.js +2 -62
- package/dist/node/runtime/resolve-bundle.js +10 -447
- package/dist/node/runtime/resolve-preferences.js +3 -7
- package/dist/node/runtime/rollback.js +2 -325
- package/dist/node/runtime/widget-registry.js +1 -5
- package/dist/node/spec/define-module-bundle.js +2 -67
- package/dist/node/spec/index.js +9 -317
- package/dist/node/spec/validate-bundle.js +3 -8
- package/dist/node/spec/validate-surface-patch.js +5 -11
- package/dist/node/telemetry/index.js +4 -16
- package/dist/node/telemetry/surface-metrics.js +7 -16
- package/dist/react/BundleProvider.js +12 -20
- package/dist/react/BundleRenderer.d.ts +3 -1
- package/dist/react/BundleRenderer.js +19 -663
- package/dist/react/OverlayConflictResolver.js +12 -181
- package/dist/react/PatchProposalCard.js +9 -178
- package/dist/react/RegionRenderer.js +14 -61
- package/dist/react/SlotRenderer.js +15 -59
- package/dist/react/WidgetPalette.js +6 -11
- package/dist/react/index.js +14 -791
- package/dist/runtime/apply-surface-patch.js +3 -209
- package/dist/runtime/audit-events.js +8 -20
- package/dist/runtime/build-context.js +2 -7
- package/dist/runtime/extension-registry.js +3 -10
- package/dist/runtime/field-renderer-registry.js +9 -16
- package/dist/runtime/index.js +54 -1488
- package/dist/runtime/overlay-alignment.js +8 -20
- package/dist/runtime/overlay-signer.js +2 -8
- package/dist/runtime/override-store.js +3 -10
- package/dist/runtime/planner-prompt.js +11 -9
- package/dist/runtime/planner-tools.js +4 -11
- package/dist/runtime/policy-eval.js +3 -136
- package/dist/runtime/preference-adapter.js +2 -63
- package/dist/runtime/resolve-bundle.js +10 -448
- package/dist/runtime/resolve-preferences.js +3 -8
- package/dist/runtime/rollback.js +2 -326
- package/dist/runtime/widget-registry.js +1 -6
- package/dist/spec/define-module-bundle.js +2 -68
- package/dist/spec/index.js +9 -318
- package/dist/spec/types.js +0 -1
- package/dist/spec/validate-bundle.js +3 -9
- package/dist/spec/validate-surface-patch.js +5 -12
- package/dist/spec/verification-snapshot-types.js +0 -1
- package/dist/telemetry/index.js +4 -17
- package/dist/telemetry/surface-metrics.js +7 -17
- package/package.json +7 -7
package/dist/spec/index.js
CHANGED
|
@@ -1,320 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var VALID_OPS = [
|
|
4
|
-
"insert-node",
|
|
5
|
-
"replace-node",
|
|
6
|
-
"remove-node",
|
|
7
|
-
"move-node",
|
|
8
|
-
"resize-panel",
|
|
9
|
-
"set-layout",
|
|
10
|
-
"reveal-field",
|
|
11
|
-
"hide-field",
|
|
12
|
-
"promote-action",
|
|
13
|
-
"set-focus"
|
|
14
|
-
];
|
|
15
|
-
var VALID_NODE_KINDS = [
|
|
16
|
-
"metric-strip",
|
|
17
|
-
"data-view",
|
|
18
|
-
"entity-card",
|
|
19
|
-
"entity-header",
|
|
20
|
-
"entity-summary",
|
|
21
|
-
"entity-section",
|
|
22
|
-
"entity-field",
|
|
23
|
-
"entity-activity",
|
|
24
|
-
"entity-relations",
|
|
25
|
-
"entity-timeline",
|
|
26
|
-
"entity-comments",
|
|
27
|
-
"entity-attachments",
|
|
28
|
-
"entity-view-switcher",
|
|
29
|
-
"entity-automation-panel",
|
|
30
|
-
"rich-doc",
|
|
31
|
-
"chat-thread",
|
|
32
|
-
"assistant-panel",
|
|
33
|
-
"action-bar",
|
|
34
|
-
"timeline",
|
|
35
|
-
"board",
|
|
36
|
-
"table",
|
|
37
|
-
"calendar",
|
|
38
|
-
"form",
|
|
39
|
-
"chart",
|
|
40
|
-
"relation-graph",
|
|
41
|
-
"custom-widget"
|
|
42
|
-
];
|
|
43
|
-
function validateSurfaceNode(node, path) {
|
|
44
|
-
if (!node.nodeId || typeof node.nodeId !== "string") {
|
|
45
|
-
throw new Error(`${path}: nodeId must be a non-empty string`);
|
|
46
|
-
}
|
|
47
|
-
if (!node.kind || !VALID_NODE_KINDS.includes(node.kind)) {
|
|
48
|
-
throw new Error(`${path}: kind must be one of ${VALID_NODE_KINDS.join(", ")}`);
|
|
49
|
-
}
|
|
50
|
-
if (node.children) {
|
|
51
|
-
for (let i = 0;i < node.children.length; i++) {
|
|
52
|
-
const child = node.children[i];
|
|
53
|
-
if (child)
|
|
54
|
-
validateSurfaceNode(child, `${path}.children[${i}]`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function validateSurfacePatchOp(op, index) {
|
|
59
|
-
const path = `ops[${index}]`;
|
|
60
|
-
if (!op || typeof op !== "object" || !("op" in op)) {
|
|
61
|
-
throw new Error(`${path}: must be an object with op field`);
|
|
62
|
-
}
|
|
63
|
-
const opType = op.op;
|
|
64
|
-
if (!VALID_OPS.includes(opType)) {
|
|
65
|
-
throw new Error(`${path}: op must be one of ${VALID_OPS.join(", ")}`);
|
|
66
|
-
}
|
|
67
|
-
switch (op.op) {
|
|
68
|
-
case "insert-node":
|
|
69
|
-
if (!op.slotId || typeof op.slotId !== "string") {
|
|
70
|
-
throw new Error(`${path}: insert-node requires slotId string`);
|
|
71
|
-
}
|
|
72
|
-
if (!op.node) {
|
|
73
|
-
throw new Error(`${path}: insert-node requires node`);
|
|
74
|
-
}
|
|
75
|
-
validateSurfaceNode(op.node, `${path}.node`);
|
|
76
|
-
if (op.index !== undefined && typeof op.index !== "number") {
|
|
77
|
-
throw new Error(`${path}: insert-node index must be number if present`);
|
|
78
|
-
}
|
|
79
|
-
break;
|
|
80
|
-
case "replace-node":
|
|
81
|
-
if (!op.nodeId || typeof op.nodeId !== "string") {
|
|
82
|
-
throw new Error(`${path}: replace-node requires nodeId string`);
|
|
83
|
-
}
|
|
84
|
-
if (!op.node) {
|
|
85
|
-
throw new Error(`${path}: replace-node requires node`);
|
|
86
|
-
}
|
|
87
|
-
validateSurfaceNode(op.node, `${path}.node`);
|
|
88
|
-
break;
|
|
89
|
-
case "remove-node":
|
|
90
|
-
if (!op.nodeId || typeof op.nodeId !== "string") {
|
|
91
|
-
throw new Error(`${path}: remove-node requires nodeId string`);
|
|
92
|
-
}
|
|
93
|
-
break;
|
|
94
|
-
case "move-node":
|
|
95
|
-
if (!op.nodeId || typeof op.nodeId !== "string") {
|
|
96
|
-
throw new Error(`${path}: move-node requires nodeId string`);
|
|
97
|
-
}
|
|
98
|
-
if (!op.toSlotId || typeof op.toSlotId !== "string") {
|
|
99
|
-
throw new Error(`${path}: move-node requires toSlotId string`);
|
|
100
|
-
}
|
|
101
|
-
if (op.index !== undefined && typeof op.index !== "number") {
|
|
102
|
-
throw new Error(`${path}: move-node index must be number if present`);
|
|
103
|
-
}
|
|
104
|
-
break;
|
|
105
|
-
case "resize-panel":
|
|
106
|
-
if (!op.persistKey || typeof op.persistKey !== "string") {
|
|
107
|
-
throw new Error(`${path}: resize-panel requires persistKey string`);
|
|
108
|
-
}
|
|
109
|
-
if (!Array.isArray(op.sizes) || op.sizes.some((s) => typeof s !== "number")) {
|
|
110
|
-
throw new Error(`${path}: resize-panel requires sizes number[]`);
|
|
111
|
-
}
|
|
112
|
-
break;
|
|
113
|
-
case "set-layout":
|
|
114
|
-
if (!op.layoutId || typeof op.layoutId !== "string") {
|
|
115
|
-
throw new Error(`${path}: set-layout requires layoutId string`);
|
|
116
|
-
}
|
|
117
|
-
break;
|
|
118
|
-
case "reveal-field":
|
|
119
|
-
case "hide-field":
|
|
120
|
-
if (!op.fieldId || typeof op.fieldId !== "string") {
|
|
121
|
-
throw new Error(`${path}: ${op.op} requires fieldId string`);
|
|
122
|
-
}
|
|
123
|
-
break;
|
|
124
|
-
case "promote-action": {
|
|
125
|
-
if (!op.actionId || typeof op.actionId !== "string") {
|
|
126
|
-
throw new Error(`${path}: promote-action requires actionId string`);
|
|
127
|
-
}
|
|
128
|
-
const validPlacements = ["header", "inline", "context", "assistant"];
|
|
129
|
-
if (!op.placement || !validPlacements.includes(op.placement)) {
|
|
130
|
-
throw new Error(`${path}: promote-action placement must be one of ${validPlacements.join(", ")}`);
|
|
131
|
-
}
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
case "set-focus":
|
|
135
|
-
if (!op.targetId || typeof op.targetId !== "string") {
|
|
136
|
-
throw new Error(`${path}: set-focus requires targetId string`);
|
|
137
|
-
}
|
|
138
|
-
break;
|
|
139
|
-
default:
|
|
140
|
-
throw new Error(`${path}: unknown op "${opType}"`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function validateSurfacePatch(ops) {
|
|
144
|
-
if (!Array.isArray(ops)) {
|
|
145
|
-
throw new Error("Patch ops must be an array");
|
|
146
|
-
}
|
|
147
|
-
for (let i = 0;i < ops.length; i++) {
|
|
148
|
-
const op = ops[i];
|
|
149
|
-
if (op)
|
|
150
|
-
validateSurfacePatchOp(op, i);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
function validateSurfaceNodeAgainstKinds(node, allowedKinds, path) {
|
|
154
|
-
if (!allowedKinds.includes(node.kind)) {
|
|
155
|
-
throw new Error(`${path}: kind "${node.kind}" not in allowed list [${allowedKinds.join(", ")}]`);
|
|
156
|
-
}
|
|
157
|
-
if (node.children) {
|
|
158
|
-
for (let i = 0;i < node.children.length; i++) {
|
|
159
|
-
const child = node.children[i];
|
|
160
|
-
if (child)
|
|
161
|
-
validateSurfaceNodeAgainstKinds(child, allowedKinds, `${path}.children[${i}]`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
function validatePatchProposal(ops, constraints) {
|
|
166
|
-
if (!Array.isArray(ops)) {
|
|
167
|
-
throw new Error("Patch ops must be an array");
|
|
168
|
-
}
|
|
169
|
-
const { allowedOps, allowedSlots, allowedNodeKinds } = constraints;
|
|
170
|
-
for (let i = 0;i < ops.length; i++) {
|
|
171
|
-
const op = ops[i];
|
|
172
|
-
if (!op)
|
|
173
|
-
continue;
|
|
174
|
-
const path = `ops[${i}]`;
|
|
175
|
-
if (!allowedOps.includes(op.op)) {
|
|
176
|
-
throw new Error(`${path}: op "${op.op}" not in allowed list [${allowedOps.join(", ")}]`);
|
|
177
|
-
}
|
|
178
|
-
switch (op.op) {
|
|
179
|
-
case "insert-node":
|
|
180
|
-
if (!allowedSlots.includes(op.slotId)) {
|
|
181
|
-
throw new Error(`${path}: slotId "${op.slotId}" not in allowed slots [${allowedSlots.join(", ")}]`);
|
|
182
|
-
}
|
|
183
|
-
if (op.node) {
|
|
184
|
-
validateSurfaceNodeAgainstKinds(op.node, allowedNodeKinds, `${path}.node`);
|
|
185
|
-
}
|
|
186
|
-
break;
|
|
187
|
-
case "move-node":
|
|
188
|
-
if (!allowedSlots.includes(op.toSlotId)) {
|
|
189
|
-
throw new Error(`${path}: toSlotId "${op.toSlotId}" not in allowed slots [${allowedSlots.join(", ")}]`);
|
|
190
|
-
}
|
|
191
|
-
break;
|
|
192
|
-
case "replace-node":
|
|
193
|
-
if (op.node) {
|
|
194
|
-
validateSurfaceNodeAgainstKinds(op.node, allowedNodeKinds, `${path}.node`);
|
|
195
|
-
}
|
|
196
|
-
break;
|
|
197
|
-
default:
|
|
198
|
-
break;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
validateSurfacePatch(ops);
|
|
202
|
-
}
|
|
203
|
-
// src/spec/validate-bundle.ts
|
|
204
|
-
var KNOWN_NODE_KIND_RENDERERS = new Set([
|
|
205
|
-
"entity-section",
|
|
206
|
-
"entity-field",
|
|
207
|
-
"action-bar",
|
|
208
|
-
"table",
|
|
209
|
-
"timeline",
|
|
210
|
-
"rich-doc",
|
|
211
|
-
"chat-thread",
|
|
212
|
-
"assistant-panel",
|
|
213
|
-
"entity-card",
|
|
214
|
-
"entity-header",
|
|
215
|
-
"entity-summary",
|
|
216
|
-
"entity-activity",
|
|
217
|
-
"entity-relations",
|
|
218
|
-
"relation-graph",
|
|
219
|
-
"custom-widget"
|
|
220
|
-
]);
|
|
221
|
-
function collectSlotIdsFromRegion(node) {
|
|
222
|
-
const ids = [];
|
|
223
|
-
if (node.type === "slot") {
|
|
224
|
-
ids.push(node.slotId);
|
|
225
|
-
}
|
|
226
|
-
if (node.type === "panel-group" || node.type === "stack") {
|
|
227
|
-
for (const child of node.children) {
|
|
228
|
-
ids.push(...collectSlotIdsFromRegion(child));
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
if (node.type === "tabs") {
|
|
232
|
-
for (const tab of node.tabs) {
|
|
233
|
-
ids.push(...collectSlotIdsFromRegion(tab.child));
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
if (node.type === "floating") {
|
|
237
|
-
ids.push(node.anchorSlotId);
|
|
238
|
-
ids.push(...collectSlotIdsFromRegion(node.child));
|
|
239
|
-
}
|
|
240
|
-
return ids;
|
|
241
|
-
}
|
|
242
|
-
function validateLayoutSlots(surface) {
|
|
243
|
-
const declaredSlotIds = new Set(surface.slots.map((s) => s.slotId));
|
|
244
|
-
for (const layout of surface.layouts) {
|
|
245
|
-
const layoutSlotIds = collectSlotIdsFromRegion(layout.root);
|
|
246
|
-
for (const slotId of layoutSlotIds) {
|
|
247
|
-
if (!declaredSlotIds.has(slotId)) {
|
|
248
|
-
throw new Error(`Surface "${surface.surfaceId}" layout "${layout.layoutId}" references undeclared slot "${slotId}". Declared slots: ${[...declaredSlotIds].join(", ")}`);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
function validateBundleNodeKinds(surface) {
|
|
254
|
-
const warnings = [];
|
|
255
|
-
for (const slot of surface.slots) {
|
|
256
|
-
for (const kind of slot.accepts) {
|
|
257
|
-
if (!KNOWN_NODE_KIND_RENDERERS.has(kind)) {
|
|
258
|
-
warnings.push(`Surface "${surface.surfaceId}" slot "${slot.slotId}" accepts "${kind}" which has no dedicated renderer (generic fallback used)`);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return { warnings };
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// src/spec/define-module-bundle.ts
|
|
266
|
-
function defineModuleBundle(spec) {
|
|
267
|
-
if (!spec.meta?.key || !spec.meta?.version || !spec.meta?.title) {
|
|
268
|
-
throw new Error("ModuleBundleSpec must have meta.key, meta.version, and meta.title");
|
|
269
|
-
}
|
|
270
|
-
if (!spec.routes?.length) {
|
|
271
|
-
throw new Error("ModuleBundleSpec must have at least one route");
|
|
272
|
-
}
|
|
273
|
-
if (!spec.surfaces || Object.keys(spec.surfaces).length === 0) {
|
|
274
|
-
throw new Error("ModuleBundleSpec must have at least one surface");
|
|
275
|
-
}
|
|
276
|
-
if (spec.entities) {
|
|
277
|
-
if (!spec.entities.entityTypes || typeof spec.entities.entityTypes !== "object") {
|
|
278
|
-
throw new Error("ModuleBundleSpec.entities must have entityTypes object when present");
|
|
279
|
-
}
|
|
280
|
-
if (!spec.entities.fieldKinds || typeof spec.entities.fieldKinds !== "object") {
|
|
281
|
-
throw new Error("ModuleBundleSpec.entities must have fieldKinds object when present");
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
const REQUIRED_DIMENSIONS = [
|
|
285
|
-
"guidance",
|
|
286
|
-
"density",
|
|
287
|
-
"dataDepth",
|
|
288
|
-
"control",
|
|
289
|
-
"media",
|
|
290
|
-
"pace",
|
|
291
|
-
"narrative"
|
|
292
|
-
];
|
|
293
|
-
const MIN_DESCRIPTION_LENGTH = 10;
|
|
294
|
-
for (const surface of Object.values(spec.surfaces)) {
|
|
295
|
-
if (!surface.verification?.dimensions) {
|
|
296
|
-
throw new Error(`Surface "${surface.surfaceId}" must have verification.dimensions for all 7 preference dimensions`);
|
|
297
|
-
}
|
|
298
|
-
const dims = surface.verification.dimensions;
|
|
299
|
-
for (const d of REQUIRED_DIMENSIONS) {
|
|
300
|
-
const val = dims[d];
|
|
301
|
-
if (!val || typeof val !== "string") {
|
|
302
|
-
throw new Error(`Surface "${surface.surfaceId}" verification.dimensions.${d} must be a non-empty string`);
|
|
303
|
-
}
|
|
304
|
-
const trimmed = val.trim();
|
|
305
|
-
if (trimmed.length < MIN_DESCRIPTION_LENGTH) {
|
|
306
|
-
throw new Error(`Surface "${surface.surfaceId}" verification.dimensions.${d} must be at least ${MIN_DESCRIPTION_LENGTH} characters (got ${trimmed.length})`);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
validateLayoutSlots(surface);
|
|
310
|
-
}
|
|
311
|
-
return spec;
|
|
312
|
-
}
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export { defineModuleBundle } from "./define-module-bundle";
|
|
313
3
|
export {
|
|
314
|
-
validateSurfacePatchOp,
|
|
315
|
-
validateSurfacePatch,
|
|
316
|
-
validatePatchProposal,
|
|
317
4
|
validateLayoutSlots,
|
|
318
|
-
validateBundleNodeKinds
|
|
319
|
-
|
|
320
|
-
|
|
5
|
+
validateBundleNodeKinds
|
|
6
|
+
} from "./validate-bundle";
|
|
7
|
+
export {
|
|
8
|
+
validateSurfacePatch,
|
|
9
|
+
validateSurfacePatchOp,
|
|
10
|
+
validatePatchProposal
|
|
11
|
+
} from "./validate-surface-patch";
|
package/dist/spec/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// src/spec/validate-bundle.ts
|
|
3
|
-
var KNOWN_NODE_KIND_RENDERERS = new Set([
|
|
1
|
+
const KNOWN_NODE_KIND_RENDERERS = new Set([
|
|
4
2
|
"entity-section",
|
|
5
3
|
"entity-field",
|
|
6
4
|
"action-bar",
|
|
@@ -38,7 +36,7 @@ function collectSlotIdsFromRegion(node) {
|
|
|
38
36
|
}
|
|
39
37
|
return ids;
|
|
40
38
|
}
|
|
41
|
-
function validateLayoutSlots(surface) {
|
|
39
|
+
export function validateLayoutSlots(surface) {
|
|
42
40
|
const declaredSlotIds = new Set(surface.slots.map((s) => s.slotId));
|
|
43
41
|
for (const layout of surface.layouts) {
|
|
44
42
|
const layoutSlotIds = collectSlotIdsFromRegion(layout.root);
|
|
@@ -49,7 +47,7 @@ function validateLayoutSlots(surface) {
|
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
|
-
function validateBundleNodeKinds(surface) {
|
|
50
|
+
export function validateBundleNodeKinds(surface) {
|
|
53
51
|
const warnings = [];
|
|
54
52
|
for (const slot of surface.slots) {
|
|
55
53
|
for (const kind of slot.accepts) {
|
|
@@ -60,7 +58,3 @@ function validateBundleNodeKinds(surface) {
|
|
|
60
58
|
}
|
|
61
59
|
return { warnings };
|
|
62
60
|
}
|
|
63
|
-
export {
|
|
64
|
-
validateLayoutSlots,
|
|
65
|
-
validateBundleNodeKinds
|
|
66
|
-
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// src/spec/validate-surface-patch.ts
|
|
3
|
-
var VALID_OPS = [
|
|
1
|
+
const VALID_OPS = [
|
|
4
2
|
"insert-node",
|
|
5
3
|
"replace-node",
|
|
6
4
|
"remove-node",
|
|
@@ -12,7 +10,7 @@ var VALID_OPS = [
|
|
|
12
10
|
"promote-action",
|
|
13
11
|
"set-focus"
|
|
14
12
|
];
|
|
15
|
-
|
|
13
|
+
const VALID_NODE_KINDS = [
|
|
16
14
|
"metric-strip",
|
|
17
15
|
"data-view",
|
|
18
16
|
"entity-card",
|
|
@@ -55,7 +53,7 @@ function validateSurfaceNode(node, path) {
|
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
|
-
function validateSurfacePatchOp(op, index) {
|
|
56
|
+
export function validateSurfacePatchOp(op, index) {
|
|
59
57
|
const path = `ops[${index}]`;
|
|
60
58
|
if (!op || typeof op !== "object" || !("op" in op)) {
|
|
61
59
|
throw new Error(`${path}: must be an object with op field`);
|
|
@@ -140,7 +138,7 @@ function validateSurfacePatchOp(op, index) {
|
|
|
140
138
|
throw new Error(`${path}: unknown op "${opType}"`);
|
|
141
139
|
}
|
|
142
140
|
}
|
|
143
|
-
function validateSurfacePatch(ops) {
|
|
141
|
+
export function validateSurfacePatch(ops) {
|
|
144
142
|
if (!Array.isArray(ops)) {
|
|
145
143
|
throw new Error("Patch ops must be an array");
|
|
146
144
|
}
|
|
@@ -162,7 +160,7 @@ function validateSurfaceNodeAgainstKinds(node, allowedKinds, path) {
|
|
|
162
160
|
}
|
|
163
161
|
}
|
|
164
162
|
}
|
|
165
|
-
function validatePatchProposal(ops, constraints) {
|
|
163
|
+
export function validatePatchProposal(ops, constraints) {
|
|
166
164
|
if (!Array.isArray(ops)) {
|
|
167
165
|
throw new Error("Patch ops must be an array");
|
|
168
166
|
}
|
|
@@ -200,8 +198,3 @@ function validatePatchProposal(ops, constraints) {
|
|
|
200
198
|
}
|
|
201
199
|
validateSurfacePatch(ops);
|
|
202
200
|
}
|
|
203
|
-
export {
|
|
204
|
-
validateSurfacePatchOp,
|
|
205
|
-
validateSurfacePatch,
|
|
206
|
-
validatePatchProposal
|
|
207
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// @bun
|
package/dist/telemetry/index.js
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// src/telemetry/surface-metrics.ts
|
|
3
|
-
import {
|
|
4
|
-
createCounter,
|
|
5
|
-
createHistogram
|
|
6
|
-
} from "@contractspec/lib.observability/metrics";
|
|
7
|
-
var METER_NAME = "@contractspec/lib.surface-runtime";
|
|
8
|
-
var resolutionDurationMs = createHistogram("bundle_surface_resolution_duration_ms", "Time to resolve bundle spec to surface plan in milliseconds", METER_NAME);
|
|
9
|
-
var patchAcceptanceCounter = createCounter("bundle_surface_patch_acceptance_total", "Total AI patch proposals accepted by user", METER_NAME);
|
|
10
|
-
var patchRejectionCounter = createCounter("bundle_surface_patch_rejection_total", "Total AI patch proposals rejected by user", METER_NAME);
|
|
11
|
-
var policyDenialCounter = createCounter("bundle_surface_policy_denial_total", "Total policy denials (actions denied by policy)", METER_NAME);
|
|
12
|
-
var surfaceFallbackCounter = createCounter("bundle_surface_fallback_total", "Total surface or layout fallbacks during resolution", METER_NAME);
|
|
13
|
-
var missingRendererCounter = createCounter("bundle_surface_renderer_missing_total", "Total slots with no renderer for requested node kind", METER_NAME);
|
|
14
1
|
export {
|
|
15
|
-
surfaceFallbackCounter,
|
|
16
2
|
resolutionDurationMs,
|
|
17
|
-
policyDenialCounter,
|
|
18
|
-
patchRejectionCounter,
|
|
19
3
|
patchAcceptanceCounter,
|
|
4
|
+
patchRejectionCounter,
|
|
5
|
+
policyDenialCounter,
|
|
6
|
+
surfaceFallbackCounter,
|
|
20
7
|
missingRendererCounter
|
|
21
|
-
};
|
|
8
|
+
} from "./surface-metrics";
|
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// src/telemetry/surface-metrics.ts
|
|
3
1
|
import {
|
|
4
2
|
createCounter,
|
|
5
3
|
createHistogram
|
|
6
4
|
} from "@contractspec/lib.observability/metrics";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
surfaceFallbackCounter,
|
|
16
|
-
resolutionDurationMs,
|
|
17
|
-
policyDenialCounter,
|
|
18
|
-
patchRejectionCounter,
|
|
19
|
-
patchAcceptanceCounter,
|
|
20
|
-
missingRendererCounter
|
|
21
|
-
};
|
|
5
|
+
const METER_NAME = "@contractspec/lib.surface-runtime";
|
|
6
|
+
export const resolutionDurationMs = createHistogram("bundle_surface_resolution_duration_ms", "Time to resolve bundle spec to surface plan in milliseconds", METER_NAME);
|
|
7
|
+
export const patchAcceptanceCounter = createCounter("bundle_surface_patch_acceptance_total", "Total AI patch proposals accepted by user", METER_NAME);
|
|
8
|
+
export const patchRejectionCounter = createCounter("bundle_surface_patch_rejection_total", "Total AI patch proposals rejected by user", METER_NAME);
|
|
9
|
+
export const policyDenialCounter = createCounter("bundle_surface_policy_denial_total", "Total policy denials (actions denied by policy)", METER_NAME);
|
|
10
|
+
export const surfaceFallbackCounter = createCounter("bundle_surface_fallback_total", "Total surface or layout fallbacks during resolution", METER_NAME);
|
|
11
|
+
export const missingRendererCounter = createCounter("bundle_surface_renderer_missing_total", "Total slots with no renderer for requested node kind", METER_NAME);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contractspec/lib.surface-runtime",
|
|
3
|
-
"version": "0.2
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "AI-native surface specs and web runtime for adaptive ContractSpec surfaces",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contractspec",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
22
22
|
"publish:pkg:canary": "bun publish:pkg --tag canary",
|
|
23
23
|
"build": "bun run prebuild && bun run build:bundle && bun run build:types",
|
|
24
|
-
"build:bundle": "contractspec-bun-build transpile",
|
|
24
|
+
"build:bundle": "contractspec-bun-build transpile && node scripts/fix-use-client-directive.mjs",
|
|
25
25
|
"build:types": "contractspec-bun-build types",
|
|
26
26
|
"dev": "contractspec-bun-build dev",
|
|
27
27
|
"clean": "rimraf dist .turbo",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"typecheck": "tsc --noEmit"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@contractspec/lib.contracts-spec": "3.
|
|
39
|
-
"@contractspec/lib.overlay-engine": "3.
|
|
40
|
-
"@contractspec/lib.observability": "3.
|
|
38
|
+
"@contractspec/lib.contracts-spec": "3.5.2",
|
|
39
|
+
"@contractspec/lib.overlay-engine": "3.5.2",
|
|
40
|
+
"@contractspec/lib.observability": "3.5.2",
|
|
41
41
|
"zod": "^4.3.5"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
@@ -57,10 +57,10 @@
|
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@contractspec/tool.typescript": "3.
|
|
60
|
+
"@contractspec/tool.typescript": "3.5.2",
|
|
61
61
|
"@dnd-kit/core": "^6.3.1",
|
|
62
62
|
"typescript": "^5.9.3",
|
|
63
|
-
"@contractspec/tool.bun": "3.
|
|
63
|
+
"@contractspec/tool.bun": "3.5.2"
|
|
64
64
|
},
|
|
65
65
|
"exports": {
|
|
66
66
|
".": {
|