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