@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.
Files changed (232) hide show
  1. package/README.md +164 -0
  2. package/dist/adapters/ai-sdk-stub.d.ts +5 -0
  3. package/dist/adapters/ai-sdk-stub.js +13 -0
  4. package/dist/adapters/blocknote-stub.d.ts +6 -0
  5. package/dist/adapters/blocknote-stub.js +31 -0
  6. package/dist/adapters/dnd-kit-adapter.d.ts +13 -0
  7. package/dist/adapters/dnd-kit-adapter.js +44 -0
  8. package/dist/adapters/dnd-kit-stub.d.ts +6 -0
  9. package/dist/adapters/dnd-kit-stub.js +8 -0
  10. package/dist/adapters/floating-ui-stub.d.ts +6 -0
  11. package/dist/adapters/floating-ui-stub.js +19 -0
  12. package/dist/adapters/index.d.ts +11 -0
  13. package/dist/adapters/index.js +176 -0
  14. package/dist/adapters/interfaces.d.ts +75 -0
  15. package/dist/adapters/interfaces.js +1 -0
  16. package/dist/adapters/motion-stub.d.ts +7 -0
  17. package/dist/adapters/motion-stub.js +27 -0
  18. package/dist/adapters/motion-stub.test.d.ts +1 -0
  19. package/dist/adapters/resizable-panels-stub.d.ts +6 -0
  20. package/dist/adapters/resizable-panels-stub.js +46 -0
  21. package/dist/adapters/resizable-panels-stub.test.d.ts +1 -0
  22. package/dist/browser/adapters/ai-sdk-stub.js +12 -0
  23. package/dist/browser/adapters/blocknote-stub.js +30 -0
  24. package/dist/browser/adapters/dnd-kit-adapter.js +43 -0
  25. package/dist/browser/adapters/dnd-kit-stub.js +7 -0
  26. package/dist/browser/adapters/floating-ui-stub.js +18 -0
  27. package/dist/browser/adapters/index.js +175 -0
  28. package/dist/browser/adapters/interfaces.js +0 -0
  29. package/dist/browser/adapters/motion-stub.js +26 -0
  30. package/dist/browser/adapters/resizable-panels-stub.js +45 -0
  31. package/dist/browser/evals/golden-context.js +0 -0
  32. package/dist/browser/evals/golden-harness.js +848 -0
  33. package/dist/browser/examples/pm-workbench.bundle.js +476 -0
  34. package/dist/browser/i18n/catalogs/en.js +71 -0
  35. package/dist/browser/i18n/catalogs/es.js +32 -0
  36. package/dist/browser/i18n/catalogs/fr.js +32 -0
  37. package/dist/browser/i18n/catalogs/index.js +133 -0
  38. package/dist/browser/i18n/index.js +173 -0
  39. package/dist/browser/i18n/keys.js +19 -0
  40. package/dist/browser/i18n/messages.js +143 -0
  41. package/dist/browser/index.js +2466 -0
  42. package/dist/browser/react/BundleProvider.js +47 -0
  43. package/dist/browser/react/BundleRenderer.js +726 -0
  44. package/dist/browser/react/OverlayConflictResolver.js +255 -0
  45. package/dist/browser/react/PatchProposalCard.js +255 -0
  46. package/dist/browser/react/RegionRenderer.js +128 -0
  47. package/dist/browser/react/SlotRenderer.js +118 -0
  48. package/dist/browser/react/WidgetPalette.js +59 -0
  49. package/dist/browser/react/index.js +792 -0
  50. package/dist/browser/runtime/apply-surface-patch.js +322 -0
  51. package/dist/browser/runtime/audit-events.js +137 -0
  52. package/dist/browser/runtime/build-context.js +55 -0
  53. package/dist/browser/runtime/extension-registry.js +58 -0
  54. package/dist/browser/runtime/field-renderer-registry.js +145 -0
  55. package/dist/browser/runtime/index.js +1496 -0
  56. package/dist/browser/runtime/overlay-alignment.js +83 -0
  57. package/dist/browser/runtime/overlay-signer.js +15 -0
  58. package/dist/browser/runtime/override-store.js +52 -0
  59. package/dist/browser/runtime/planner-prompt.js +67 -0
  60. package/dist/browser/runtime/planner-tools.js +77 -0
  61. package/dist/browser/runtime/policy-eval.js +155 -0
  62. package/dist/browser/runtime/preference-adapter.js +67 -0
  63. package/dist/browser/runtime/resolve-bundle.js +767 -0
  64. package/dist/browser/runtime/resolve-preferences.js +59 -0
  65. package/dist/browser/runtime/rollback.js +347 -0
  66. package/dist/browser/runtime/widget-registry.js +36 -0
  67. package/dist/browser/spec/define-module-bundle.js +113 -0
  68. package/dist/browser/spec/index.js +319 -0
  69. package/dist/browser/spec/types.js +0 -0
  70. package/dist/browser/spec/validate-bundle.js +65 -0
  71. package/dist/browser/spec/validate-surface-patch.js +206 -0
  72. package/dist/browser/spec/verification-snapshot-types.js +0 -0
  73. package/dist/browser/telemetry/index.js +20 -0
  74. package/dist/browser/telemetry/surface-metrics.js +20 -0
  75. package/dist/evals/golden-context.d.ts +24 -0
  76. package/dist/evals/golden-context.js +1 -0
  77. package/dist/evals/golden-harness.d.ts +29 -0
  78. package/dist/evals/golden-harness.js +849 -0
  79. package/dist/evals/golden-harness.test.d.ts +1 -0
  80. package/dist/examples/pm-workbench.bundle.d.ts +177 -0
  81. package/dist/examples/pm-workbench.bundle.js +477 -0
  82. package/dist/i18n/catalogs/en.d.ts +1 -0
  83. package/dist/i18n/catalogs/en.js +72 -0
  84. package/dist/i18n/catalogs/es.d.ts +1 -0
  85. package/dist/i18n/catalogs/es.js +33 -0
  86. package/dist/i18n/catalogs/fr.d.ts +1 -0
  87. package/dist/i18n/catalogs/fr.js +33 -0
  88. package/dist/i18n/catalogs/index.d.ts +3 -0
  89. package/dist/i18n/catalogs/index.js +134 -0
  90. package/dist/i18n/index.d.ts +5 -0
  91. package/dist/i18n/index.js +174 -0
  92. package/dist/i18n/keys.d.ts +20 -0
  93. package/dist/i18n/keys.js +20 -0
  94. package/dist/i18n/messages.d.ts +5 -0
  95. package/dist/i18n/messages.js +144 -0
  96. package/dist/index.d.ts +4 -0
  97. package/dist/index.js +2467 -0
  98. package/dist/node/adapters/ai-sdk-stub.js +12 -0
  99. package/dist/node/adapters/blocknote-stub.js +30 -0
  100. package/dist/node/adapters/dnd-kit-adapter.js +43 -0
  101. package/dist/node/adapters/dnd-kit-stub.js +7 -0
  102. package/dist/node/adapters/floating-ui-stub.js +18 -0
  103. package/dist/node/adapters/index.js +175 -0
  104. package/dist/node/adapters/interfaces.js +0 -0
  105. package/dist/node/adapters/motion-stub.js +26 -0
  106. package/dist/node/adapters/resizable-panels-stub.js +45 -0
  107. package/dist/node/evals/golden-context.js +0 -0
  108. package/dist/node/evals/golden-harness.js +848 -0
  109. package/dist/node/examples/pm-workbench.bundle.js +476 -0
  110. package/dist/node/i18n/catalogs/en.js +71 -0
  111. package/dist/node/i18n/catalogs/es.js +32 -0
  112. package/dist/node/i18n/catalogs/fr.js +32 -0
  113. package/dist/node/i18n/catalogs/index.js +133 -0
  114. package/dist/node/i18n/index.js +173 -0
  115. package/dist/node/i18n/keys.js +19 -0
  116. package/dist/node/i18n/messages.js +143 -0
  117. package/dist/node/index.js +2466 -0
  118. package/dist/node/react/BundleProvider.js +47 -0
  119. package/dist/node/react/BundleRenderer.js +726 -0
  120. package/dist/node/react/OverlayConflictResolver.js +255 -0
  121. package/dist/node/react/PatchProposalCard.js +255 -0
  122. package/dist/node/react/RegionRenderer.js +128 -0
  123. package/dist/node/react/SlotRenderer.js +118 -0
  124. package/dist/node/react/WidgetPalette.js +59 -0
  125. package/dist/node/react/index.js +792 -0
  126. package/dist/node/runtime/apply-surface-patch.js +322 -0
  127. package/dist/node/runtime/audit-events.js +137 -0
  128. package/dist/node/runtime/build-context.js +55 -0
  129. package/dist/node/runtime/extension-registry.js +58 -0
  130. package/dist/node/runtime/field-renderer-registry.js +145 -0
  131. package/dist/node/runtime/index.js +1496 -0
  132. package/dist/node/runtime/overlay-alignment.js +83 -0
  133. package/dist/node/runtime/overlay-signer.js +15 -0
  134. package/dist/node/runtime/override-store.js +52 -0
  135. package/dist/node/runtime/planner-prompt.js +67 -0
  136. package/dist/node/runtime/planner-tools.js +77 -0
  137. package/dist/node/runtime/policy-eval.js +155 -0
  138. package/dist/node/runtime/preference-adapter.js +67 -0
  139. package/dist/node/runtime/resolve-bundle.js +767 -0
  140. package/dist/node/runtime/resolve-preferences.js +59 -0
  141. package/dist/node/runtime/rollback.js +347 -0
  142. package/dist/node/runtime/widget-registry.js +36 -0
  143. package/dist/node/spec/define-module-bundle.js +113 -0
  144. package/dist/node/spec/index.js +319 -0
  145. package/dist/node/spec/types.js +0 -0
  146. package/dist/node/spec/validate-bundle.js +65 -0
  147. package/dist/node/spec/validate-surface-patch.js +206 -0
  148. package/dist/node/spec/verification-snapshot-types.js +0 -0
  149. package/dist/node/telemetry/index.js +20 -0
  150. package/dist/node/telemetry/surface-metrics.js +20 -0
  151. package/dist/react/BundleProvider.d.ts +13 -0
  152. package/dist/react/BundleProvider.js +48 -0
  153. package/dist/react/BundleRenderer.d.ts +22 -0
  154. package/dist/react/BundleRenderer.js +727 -0
  155. package/dist/react/OverlayConflictResolver.d.ts +15 -0
  156. package/dist/react/OverlayConflictResolver.js +256 -0
  157. package/dist/react/PatchProposalCard.d.ts +13 -0
  158. package/dist/react/PatchProposalCard.js +256 -0
  159. package/dist/react/RegionRenderer.d.ts +13 -0
  160. package/dist/react/RegionRenderer.js +129 -0
  161. package/dist/react/SlotRenderer.d.ts +13 -0
  162. package/dist/react/SlotRenderer.js +119 -0
  163. package/dist/react/WidgetPalette.d.ts +12 -0
  164. package/dist/react/WidgetPalette.js +60 -0
  165. package/dist/react/index.d.ts +7 -0
  166. package/dist/react/index.js +793 -0
  167. package/dist/runtime/apply-surface-patch.d.ts +15 -0
  168. package/dist/runtime/apply-surface-patch.js +323 -0
  169. package/dist/runtime/apply-surface-patch.test.d.ts +1 -0
  170. package/dist/runtime/audit-events.d.ts +70 -0
  171. package/dist/runtime/audit-events.js +138 -0
  172. package/dist/runtime/audit-events.test.d.ts +1 -0
  173. package/dist/runtime/build-context.d.ts +9 -0
  174. package/dist/runtime/build-context.js +56 -0
  175. package/dist/runtime/extension-registry.d.ts +39 -0
  176. package/dist/runtime/extension-registry.js +59 -0
  177. package/dist/runtime/field-renderer-registry.d.ts +23 -0
  178. package/dist/runtime/field-renderer-registry.js +146 -0
  179. package/dist/runtime/field-renderer-registry.test.d.ts +1 -0
  180. package/dist/runtime/index.d.ts +16 -0
  181. package/dist/runtime/index.js +1497 -0
  182. package/dist/runtime/overlay-alignment.d.ts +49 -0
  183. package/dist/runtime/overlay-alignment.js +84 -0
  184. package/dist/runtime/overlay-alignment.test.d.ts +1 -0
  185. package/dist/runtime/overlay-signer.d.ts +15 -0
  186. package/dist/runtime/overlay-signer.js +16 -0
  187. package/dist/runtime/override-store.d.ts +44 -0
  188. package/dist/runtime/override-store.js +53 -0
  189. package/dist/runtime/override-store.test.d.ts +1 -0
  190. package/dist/runtime/planner-prompt.d.ts +39 -0
  191. package/dist/runtime/planner-prompt.js +68 -0
  192. package/dist/runtime/planner-prompt.test.d.ts +1 -0
  193. package/dist/runtime/planner-tools.d.ts +106 -0
  194. package/dist/runtime/planner-tools.js +78 -0
  195. package/dist/runtime/planner-tools.test.d.ts +1 -0
  196. package/dist/runtime/policy-eval.d.ts +23 -0
  197. package/dist/runtime/policy-eval.js +156 -0
  198. package/dist/runtime/preference-adapter.d.ts +6 -0
  199. package/dist/runtime/preference-adapter.js +68 -0
  200. package/dist/runtime/resolve-bundle.d.ts +68 -0
  201. package/dist/runtime/resolve-bundle.js +768 -0
  202. package/dist/runtime/resolve-bundle.test.d.ts +1 -0
  203. package/dist/runtime/resolve-preferences.d.ts +9 -0
  204. package/dist/runtime/resolve-preferences.js +60 -0
  205. package/dist/runtime/resolve-preferences.test.d.ts +1 -0
  206. package/dist/runtime/rollback.d.ts +21 -0
  207. package/dist/runtime/rollback.js +348 -0
  208. package/dist/runtime/rollback.test.d.ts +1 -0
  209. package/dist/runtime/widget-registry.d.ts +26 -0
  210. package/dist/runtime/widget-registry.js +37 -0
  211. package/dist/runtime/widget-registry.test.d.ts +1 -0
  212. package/dist/spec/define-module-bundle.d.ts +17 -0
  213. package/dist/spec/define-module-bundle.js +114 -0
  214. package/dist/spec/define-module-bundle.test.d.ts +1 -0
  215. package/dist/spec/index.d.ts +5 -0
  216. package/dist/spec/index.js +320 -0
  217. package/dist/spec/types.d.ts +494 -0
  218. package/dist/spec/types.js +1 -0
  219. package/dist/spec/validate-bundle.d.ts +23 -0
  220. package/dist/spec/validate-bundle.js +66 -0
  221. package/dist/spec/validate-bundle.test.d.ts +1 -0
  222. package/dist/spec/validate-surface-patch.d.ts +39 -0
  223. package/dist/spec/validate-surface-patch.js +207 -0
  224. package/dist/spec/validate-surface-patch.test.d.ts +1 -0
  225. package/dist/spec/verification-snapshot-types.d.ts +23 -0
  226. package/dist/spec/verification-snapshot-types.js +1 -0
  227. package/dist/spec/verification-snapshot.test.d.ts +5 -0
  228. package/dist/telemetry/index.d.ts +5 -0
  229. package/dist/telemetry/index.js +21 -0
  230. package/dist/telemetry/surface-metrics.d.ts +17 -0
  231. package/dist/telemetry/surface-metrics.js +21 -0
  232. package/package.json +920 -0
@@ -0,0 +1,726 @@
1
+ // src/adapters/blocknote-stub.tsx
2
+ import { jsxDEV } from "react/jsx-dev-runtime";
3
+ var blocknoteAdapterStub = {
4
+ supportsNode(_kind) {
5
+ return false;
6
+ },
7
+ createSchema(_registry) {
8
+ return {};
9
+ },
10
+ renderNode(node, _ctx) {
11
+ return /* @__PURE__ */ jsxDEV("div", {
12
+ "data-blocknote-stub": true,
13
+ "data-node-id": node.nodeId,
14
+ children: node.title ?? node.kind
15
+ }, undefined, false, undefined, this);
16
+ },
17
+ async serialize(node) {
18
+ return { nodeId: node.nodeId, kind: node.kind };
19
+ },
20
+ async deserialize(input) {
21
+ const o = input;
22
+ return {
23
+ nodeId: o?.nodeId ?? "stub",
24
+ kind: o?.kind ?? "custom-widget"
25
+ };
26
+ }
27
+ };
28
+
29
+ // src/adapters/motion-stub.ts
30
+ var PACE_TOKENS = {
31
+ deliberate: {
32
+ durationMs: 300,
33
+ enableEntrance: true,
34
+ layout: true
35
+ },
36
+ balanced: {
37
+ durationMs: 150,
38
+ enableEntrance: true,
39
+ layout: true
40
+ },
41
+ rapid: {
42
+ durationMs: 50,
43
+ enableEntrance: false,
44
+ layout: false
45
+ }
46
+ };
47
+ var motionAdapterStub = {
48
+ getTokens(pace) {
49
+ return PACE_TOKENS[pace] ?? PACE_TOKENS.balanced;
50
+ }
51
+ };
52
+
53
+ // src/adapters/resizable-panels-stub.tsx
54
+ import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
55
+ var LAYOUT_STORAGE_KEY = "surface-runtime:panel-layout:";
56
+ var resizablePanelsAdapterStub = {
57
+ renderPanelGroup(region, ctx, renderChild) {
58
+ const direction = region.direction === "horizontal" ? "row" : "column";
59
+ return /* @__PURE__ */ jsxDEV2("div", {
60
+ "data-panel-group": true,
61
+ "data-persist-key": region.persistKey,
62
+ style: {
63
+ display: "flex",
64
+ flexDirection: direction,
65
+ flex: 1,
66
+ minHeight: 0
67
+ },
68
+ children: region.children.map((child, i) => /* @__PURE__ */ jsxDEV2("div", {
69
+ style: { flex: 1, minWidth: 0, minHeight: 0 },
70
+ children: renderChild(child, ctx)
71
+ }, i, false, undefined, this))
72
+ }, undefined, false, undefined, this);
73
+ },
74
+ async restoreLayout(persistKey) {
75
+ if (typeof localStorage === "undefined")
76
+ return null;
77
+ try {
78
+ const raw = localStorage.getItem(LAYOUT_STORAGE_KEY + persistKey);
79
+ if (!raw)
80
+ return null;
81
+ const parsed = JSON.parse(raw);
82
+ return Array.isArray(parsed) ? parsed : null;
83
+ } catch {
84
+ return null;
85
+ }
86
+ },
87
+ async saveLayout(persistKey, sizes) {
88
+ if (typeof localStorage === "undefined")
89
+ return;
90
+ try {
91
+ localStorage.setItem(LAYOUT_STORAGE_KEY + persistKey, JSON.stringify(sizes));
92
+ } catch {}
93
+ }
94
+ };
95
+
96
+ // src/telemetry/surface-metrics.ts
97
+ import {
98
+ createCounter,
99
+ createHistogram
100
+ } from "@contractspec/lib.observability/metrics";
101
+ var METER_NAME = "@contractspec/lib.surface-runtime";
102
+ var resolutionDurationMs = createHistogram("bundle_surface_resolution_duration_ms", "Time to resolve bundle spec to surface plan in milliseconds", METER_NAME);
103
+ var patchAcceptanceCounter = createCounter("bundle_surface_patch_acceptance_total", "Total AI patch proposals accepted by user", METER_NAME);
104
+ var patchRejectionCounter = createCounter("bundle_surface_patch_rejection_total", "Total AI patch proposals rejected by user", METER_NAME);
105
+ var policyDenialCounter = createCounter("bundle_surface_policy_denial_total", "Total policy denials (actions denied by policy)", METER_NAME);
106
+ var surfaceFallbackCounter = createCounter("bundle_surface_fallback_total", "Total surface or layout fallbacks during resolution", METER_NAME);
107
+ var missingRendererCounter = createCounter("bundle_surface_renderer_missing_total", "Total slots with no renderer for requested node kind", METER_NAME);
108
+
109
+ // src/i18n/catalogs/en.ts
110
+ import { defineTranslation } from "@contractspec/lib.contracts-spec/translations";
111
+ var enMessages = defineTranslation({
112
+ meta: {
113
+ key: "surface-runtime.messages",
114
+ version: "1.0.0",
115
+ domain: "surface-runtime",
116
+ description: "User-facing strings for surface-runtime UI components",
117
+ owners: ["platform"],
118
+ stability: "experimental"
119
+ },
120
+ locale: "en",
121
+ fallback: "en",
122
+ messages: {
123
+ "overlay.conflicts.title": {
124
+ value: "Overlay conflicts",
125
+ description: "Title for overlay conflict resolution banner"
126
+ },
127
+ "overlay.conflicts.keepScope": {
128
+ value: "Keep {scope}",
129
+ description: "Button to keep overlay from scope A or B"
130
+ },
131
+ "patch.accept": {
132
+ value: "Accept",
133
+ description: "Accept patch proposal button"
134
+ },
135
+ "patch.reject": {
136
+ value: "Reject",
137
+ description: "Reject patch proposal button"
138
+ },
139
+ "patch.addWidget": {
140
+ value: "Add {title} to {slot}",
141
+ description: "Insert node proposal summary"
142
+ },
143
+ "patch.removeItem": {
144
+ value: "Remove item",
145
+ description: "Remove node proposal summary"
146
+ },
147
+ "patch.switchLayout": {
148
+ value: "Switch to {layoutId} layout",
149
+ description: "Set layout proposal summary"
150
+ },
151
+ "patch.showField": {
152
+ value: "Show field {fieldId}",
153
+ description: "Reveal field proposal summary"
154
+ },
155
+ "patch.hideField": {
156
+ value: "Hide field {fieldId}",
157
+ description: "Hide field proposal summary"
158
+ },
159
+ "patch.moveTo": {
160
+ value: "Move to {slot}",
161
+ description: "Move node proposal summary"
162
+ },
163
+ "patch.replaceItem": {
164
+ value: "Replace item",
165
+ description: "Replace node proposal summary"
166
+ },
167
+ "patch.promote": {
168
+ value: "Promote {actionId}",
169
+ description: "Promote action proposal summary"
170
+ },
171
+ "patch.changes": {
172
+ value: "{count} changes",
173
+ description: "Multiple patch ops summary"
174
+ }
175
+ }
176
+ });
177
+
178
+ // src/i18n/catalogs/es.ts
179
+ import { defineTranslation as defineTranslation2 } from "@contractspec/lib.contracts-spec/translations";
180
+ var esMessages = defineTranslation2({
181
+ meta: {
182
+ key: "surface-runtime.messages",
183
+ version: "1.0.0",
184
+ domain: "surface-runtime",
185
+ description: "User-facing strings for surface-runtime UI components",
186
+ owners: ["platform"],
187
+ stability: "experimental"
188
+ },
189
+ locale: "es",
190
+ fallback: "en",
191
+ messages: {
192
+ "overlay.conflicts.title": { value: "Conflictos de superposición" },
193
+ "overlay.conflicts.keepScope": { value: "Mantener {scope}" },
194
+ "patch.accept": { value: "Aceptar" },
195
+ "patch.reject": { value: "Rechazar" },
196
+ "patch.addWidget": { value: "Añadir {title} a {slot}" },
197
+ "patch.removeItem": { value: "Eliminar elemento" },
198
+ "patch.switchLayout": { value: "Cambiar a disposición {layoutId}" },
199
+ "patch.showField": { value: "Mostrar campo {fieldId}" },
200
+ "patch.hideField": { value: "Ocultar campo {fieldId}" },
201
+ "patch.moveTo": { value: "Mover a {slot}" },
202
+ "patch.replaceItem": { value: "Reemplazar elemento" },
203
+ "patch.promote": { value: "Promover {actionId}" },
204
+ "patch.changes": { value: "{count} cambios" }
205
+ }
206
+ });
207
+
208
+ // src/i18n/catalogs/fr.ts
209
+ import { defineTranslation as defineTranslation3 } from "@contractspec/lib.contracts-spec/translations";
210
+ var frMessages = defineTranslation3({
211
+ meta: {
212
+ key: "surface-runtime.messages",
213
+ version: "1.0.0",
214
+ domain: "surface-runtime",
215
+ description: "User-facing strings for surface-runtime UI components",
216
+ owners: ["platform"],
217
+ stability: "experimental"
218
+ },
219
+ locale: "fr",
220
+ fallback: "en",
221
+ messages: {
222
+ "overlay.conflicts.title": { value: "Conflits de superposition" },
223
+ "overlay.conflicts.keepScope": { value: "Conserver {scope}" },
224
+ "patch.accept": { value: "Accepter" },
225
+ "patch.reject": { value: "Rejeter" },
226
+ "patch.addWidget": { value: "Ajouter {title} à {slot}" },
227
+ "patch.removeItem": { value: "Supprimer l'élément" },
228
+ "patch.switchLayout": { value: "Passer à la disposition {layoutId}" },
229
+ "patch.showField": { value: "Afficher le champ {fieldId}" },
230
+ "patch.hideField": { value: "Masquer le champ {fieldId}" },
231
+ "patch.moveTo": { value: "Déplacer vers {slot}" },
232
+ "patch.replaceItem": { value: "Remplacer l'élément" },
233
+ "patch.promote": { value: "Promouvoir {actionId}" },
234
+ "patch.changes": { value: "{count} modifications" }
235
+ }
236
+ });
237
+
238
+ // src/i18n/messages.ts
239
+ import {
240
+ createI18nFactory
241
+ } from "@contractspec/lib.contracts-spec/translations";
242
+ var factory = createI18nFactory({
243
+ specKey: "surface-runtime.messages",
244
+ catalogs: [enMessages, frMessages, esMessages]
245
+ });
246
+ var createSurfaceI18n = factory.create;
247
+ var getDefaultSurfaceI18n = factory.getDefault;
248
+
249
+ // src/i18n/keys.ts
250
+ var SURFACE_KEYS = {
251
+ "overlay.conflicts.title": "overlay.conflicts.title",
252
+ "overlay.conflicts.keepScope": "overlay.conflicts.keepScope",
253
+ "patch.accept": "patch.accept",
254
+ "patch.reject": "patch.reject",
255
+ "patch.addWidget": "patch.addWidget",
256
+ "patch.removeItem": "patch.removeItem",
257
+ "patch.switchLayout": "patch.switchLayout",
258
+ "patch.showField": "patch.showField",
259
+ "patch.hideField": "patch.hideField",
260
+ "patch.moveTo": "patch.moveTo",
261
+ "patch.replaceItem": "patch.replaceItem",
262
+ "patch.promote": "patch.promote",
263
+ "patch.changes": "patch.changes"
264
+ };
265
+
266
+ // src/i18n/index.ts
267
+ import {
268
+ resolveLocale,
269
+ isSupportedLocale,
270
+ DEFAULT_LOCALE,
271
+ SUPPORTED_LOCALES
272
+ } from "@contractspec/lib.contracts-spec/translations";
273
+
274
+ // src/react/BundleProvider.tsx
275
+ import { createContext, useContext } from "react";
276
+ import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
277
+ "use client";
278
+ var BundlePlanContext = createContext(null);
279
+ var PreferencesContext = createContext(null);
280
+ var EditingContext = createContext(false);
281
+ function BundleProvider({
282
+ plan,
283
+ children,
284
+ isEditing = false
285
+ }) {
286
+ const preferences = plan.adaptation.appliedDimensions;
287
+ return /* @__PURE__ */ jsxDEV3(BundlePlanContext.Provider, {
288
+ value: plan,
289
+ children: /* @__PURE__ */ jsxDEV3(PreferencesContext.Provider, {
290
+ value: preferences,
291
+ children: /* @__PURE__ */ jsxDEV3(EditingContext.Provider, {
292
+ value: isEditing,
293
+ children
294
+ }, undefined, false, undefined, this)
295
+ }, undefined, false, undefined, this)
296
+ }, undefined, false, undefined, this);
297
+ }
298
+ function useIsEditing() {
299
+ return useContext(EditingContext);
300
+ }
301
+ function useBundlePlan() {
302
+ const value = useContext(BundlePlanContext);
303
+ if (!value) {
304
+ throw new Error("useBundlePlan must be used inside BundleProvider.");
305
+ }
306
+ return value;
307
+ }
308
+ function useBundlePreferences() {
309
+ const value = useContext(PreferencesContext);
310
+ if (!value) {
311
+ throw new Error("useBundlePreferences must be used inside BundleProvider.");
312
+ }
313
+ return value;
314
+ }
315
+
316
+ // src/react/RegionRenderer.tsx
317
+ import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
318
+ function RegionRenderer({
319
+ region,
320
+ ctx,
321
+ renderSlot
322
+ }) {
323
+ const renderChild = (child, childCtx) => /* @__PURE__ */ jsxDEV4(RegionRenderer, {
324
+ region: child,
325
+ ctx: childCtx,
326
+ renderSlot
327
+ }, undefined, false, undefined, this);
328
+ switch (region.type) {
329
+ case "panel-group":
330
+ return resizablePanelsAdapterStub.renderPanelGroup(region, ctx, renderChild);
331
+ case "stack": {
332
+ const direction = region.direction === "horizontal" ? "row" : "column";
333
+ const gapMap = {
334
+ none: 0,
335
+ xs: 4,
336
+ sm: 8,
337
+ md: 16,
338
+ lg: 24
339
+ };
340
+ const gap = gapMap[region.gap ?? "md"];
341
+ return /* @__PURE__ */ jsxDEV4("div", {
342
+ "data-region": "stack",
343
+ style: {
344
+ display: "flex",
345
+ flexDirection: direction,
346
+ gap,
347
+ flex: 1,
348
+ minHeight: 0
349
+ },
350
+ children: region.children.map((child, i) => /* @__PURE__ */ jsxDEV4("div", {
351
+ style: { flex: 1, minWidth: 0, minHeight: 0 },
352
+ children: /* @__PURE__ */ jsxDEV4(RegionRenderer, {
353
+ region: child,
354
+ ctx,
355
+ renderSlot
356
+ }, undefined, false, undefined, this)
357
+ }, i, false, undefined, this))
358
+ }, undefined, false, undefined, this);
359
+ }
360
+ case "tabs":
361
+ return /* @__PURE__ */ jsxDEV4("div", {
362
+ "data-region": "tabs",
363
+ children: [
364
+ /* @__PURE__ */ jsxDEV4("div", {
365
+ role: "tablist",
366
+ children: region.tabs.map((t) => /* @__PURE__ */ jsxDEV4("button", {
367
+ type: "button",
368
+ role: "tab",
369
+ children: t.title
370
+ }, t.key, false, undefined, this))
371
+ }, undefined, false, undefined, this),
372
+ region.tabs[0] && /* @__PURE__ */ jsxDEV4(RegionRenderer, {
373
+ region: region.tabs[0].child,
374
+ ctx,
375
+ renderSlot
376
+ }, undefined, false, undefined, this)
377
+ ]
378
+ }, undefined, true, undefined, this);
379
+ case "slot":
380
+ return /* @__PURE__ */ jsxDEV4("div", {
381
+ "data-slot": region.slotId,
382
+ children: renderSlot(region.slotId, ctx)
383
+ }, undefined, false, undefined, this);
384
+ case "floating":
385
+ return /* @__PURE__ */ jsxDEV4("div", {
386
+ "data-floating": true,
387
+ "data-anchor": region.anchorSlotId,
388
+ children: /* @__PURE__ */ jsxDEV4(RegionRenderer, {
389
+ region: region.child,
390
+ ctx,
391
+ renderSlot
392
+ }, undefined, false, undefined, this)
393
+ }, undefined, false, undefined, this);
394
+ default:
395
+ return null;
396
+ }
397
+ }
398
+
399
+ // src/react/SlotRenderer.tsx
400
+ import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
401
+ function SlotRenderer({ slotId, ctx, nodes }) {
402
+ if (nodes.length === 0) {
403
+ return /* @__PURE__ */ jsxDEV5("div", {
404
+ "data-slot-placeholder": true,
405
+ "data-slot-id": slotId
406
+ }, undefined, false, undefined, this);
407
+ }
408
+ return /* @__PURE__ */ jsxDEV5("div", {
409
+ "data-slot": slotId,
410
+ children: nodes.map((node) => /* @__PURE__ */ jsxDEV5(SlotNodeRenderer, {
411
+ node,
412
+ ctx,
413
+ slotId
414
+ }, node.nodeId, false, undefined, this))
415
+ }, undefined, false, undefined, this);
416
+ }
417
+ function SlotNodeRenderer({
418
+ node,
419
+ ctx,
420
+ slotId
421
+ }) {
422
+ if (blocknoteAdapterStub.supportsNode(node.kind)) {
423
+ return blocknoteAdapterStub.renderNode(node, ctx);
424
+ }
425
+ if (node.kind === "entity-section") {
426
+ return /* @__PURE__ */ jsxDEV5("section", {
427
+ "data-node-id": node.nodeId,
428
+ "data-kind": "entity-section",
429
+ children: [
430
+ /* @__PURE__ */ jsxDEV5("header", {
431
+ "data-entity-section-header": true,
432
+ children: node.title ?? "Section"
433
+ }, undefined, false, undefined, this),
434
+ /* @__PURE__ */ jsxDEV5("div", {
435
+ "data-entity-section-content": true,
436
+ children: node.children?.map((child) => child ? /* @__PURE__ */ jsxDEV5(SlotNodeRenderer, {
437
+ node: child,
438
+ ctx,
439
+ slotId
440
+ }, child.nodeId, false, undefined, this) : null)
441
+ }, undefined, false, undefined, this)
442
+ ]
443
+ }, undefined, true, undefined, this);
444
+ }
445
+ if (node.kind === "entity-field") {
446
+ const fieldId = node.sourceBinding?.fieldId;
447
+ return /* @__PURE__ */ jsxDEV5("div", {
448
+ "data-node-id": node.nodeId,
449
+ "data-kind": "entity-field",
450
+ "data-field-id": fieldId,
451
+ children: [
452
+ /* @__PURE__ */ jsxDEV5("span", {
453
+ "data-entity-field-label": true,
454
+ children: node.title ?? fieldId ?? "Field"
455
+ }, undefined, false, undefined, this),
456
+ /* @__PURE__ */ jsxDEV5("span", {
457
+ "data-entity-field-value": true
458
+ }, undefined, false, undefined, this)
459
+ ]
460
+ }, undefined, true, undefined, this);
461
+ }
462
+ missingRendererCounter.add(1, {
463
+ nodeKind: node.kind,
464
+ slotId
465
+ });
466
+ return /* @__PURE__ */ jsxDEV5("div", {
467
+ "data-node-id": node.nodeId,
468
+ "data-kind": node.kind,
469
+ "data-renderer-missing": true,
470
+ children: node.title ?? node.kind
471
+ }, undefined, false, undefined, this);
472
+ }
473
+
474
+ // src/react/PatchProposalCard.tsx
475
+ import { useMemo } from "react";
476
+ import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
477
+ "use client";
478
+ function PatchProposalCard({
479
+ proposal,
480
+ onAccept,
481
+ onReject,
482
+ locale
483
+ }) {
484
+ const i18n = useMemo(() => createSurfaceI18n(locale), [locale]);
485
+ const firstOp = proposal.ops[0];
486
+ const summary = proposal.ops.length === 1 && firstOp ? describeOp(firstOp, i18n) : i18n.t("patch.changes", { count: proposal.ops.length });
487
+ return /* @__PURE__ */ jsxDEV6("div", {
488
+ "data-proposal-id": proposal.proposalId,
489
+ style: {
490
+ padding: "12px",
491
+ border: "1px solid var(--border, #e5e7eb)",
492
+ borderRadius: "8px",
493
+ marginBottom: "8px",
494
+ backgroundColor: "var(--muted, #f9fafb)"
495
+ },
496
+ children: [
497
+ /* @__PURE__ */ jsxDEV6("div", {
498
+ style: { marginBottom: "8px", fontSize: "14px" },
499
+ children: summary
500
+ }, undefined, false, undefined, this),
501
+ /* @__PURE__ */ jsxDEV6("div", {
502
+ style: { display: "flex", gap: "8px" },
503
+ children: [
504
+ /* @__PURE__ */ jsxDEV6("button", {
505
+ type: "button",
506
+ onClick: () => onAccept(proposal.proposalId),
507
+ style: {
508
+ padding: "4px 12px",
509
+ fontSize: "13px",
510
+ borderRadius: "4px",
511
+ border: "none",
512
+ backgroundColor: "var(--primary, #3b82f6)",
513
+ color: "white",
514
+ cursor: "pointer"
515
+ },
516
+ children: i18n.t("patch.accept")
517
+ }, undefined, false, undefined, this),
518
+ /* @__PURE__ */ jsxDEV6("button", {
519
+ type: "button",
520
+ onClick: () => onReject(proposal.proposalId),
521
+ style: {
522
+ padding: "4px 12px",
523
+ fontSize: "13px",
524
+ borderRadius: "4px",
525
+ border: "1px solid var(--border, #e5e7eb)",
526
+ backgroundColor: "transparent",
527
+ cursor: "pointer"
528
+ },
529
+ children: i18n.t("patch.reject")
530
+ }, undefined, false, undefined, this)
531
+ ]
532
+ }, undefined, true, undefined, this)
533
+ ]
534
+ }, undefined, true, undefined, this);
535
+ }
536
+ function describeOp(op, i18n) {
537
+ switch (op.op) {
538
+ case "insert-node":
539
+ return i18n.t("patch.addWidget", {
540
+ title: op.node?.title ?? op.node?.kind ?? "widget",
541
+ slot: op.slotId ?? "slot"
542
+ });
543
+ case "remove-node":
544
+ return i18n.t("patch.removeItem");
545
+ case "set-layout":
546
+ return i18n.t("patch.switchLayout", { layoutId: op.layoutId });
547
+ case "reveal-field":
548
+ return i18n.t("patch.showField", { fieldId: op.fieldId });
549
+ case "hide-field":
550
+ return i18n.t("patch.hideField", { fieldId: op.fieldId });
551
+ case "move-node":
552
+ return i18n.t("patch.moveTo", { slot: op.toSlotId ?? "slot" });
553
+ case "replace-node":
554
+ return i18n.t("patch.replaceItem");
555
+ case "promote-action":
556
+ return i18n.t("patch.promote", { actionId: op.actionId });
557
+ default:
558
+ return `${op.op}`;
559
+ }
560
+ }
561
+
562
+ // src/react/OverlayConflictResolver.tsx
563
+ import { useMemo as useMemo2 } from "react";
564
+ import { jsxDEV as jsxDEV7 } from "react/jsx-dev-runtime";
565
+ "use client";
566
+ function OverlayConflictResolver({
567
+ conflicts,
568
+ onResolve,
569
+ locale
570
+ }) {
571
+ const i18n = useMemo2(() => createSurfaceI18n(locale), [locale]);
572
+ return /* @__PURE__ */ jsxDEV7("div", {
573
+ "data-overlay-conflicts": true,
574
+ style: {
575
+ padding: "12px",
576
+ marginBottom: "12px",
577
+ border: "1px solid var(--destructive, #ef4444)",
578
+ borderRadius: "8px",
579
+ backgroundColor: "var(--destructive/10, #fef2f2)"
580
+ },
581
+ children: [
582
+ /* @__PURE__ */ jsxDEV7("div", {
583
+ style: {
584
+ fontSize: "14px",
585
+ fontWeight: 600,
586
+ marginBottom: "8px",
587
+ color: "var(--destructive, #ef4444)"
588
+ },
589
+ children: i18n.t("overlay.conflicts.title")
590
+ }, undefined, false, undefined, this),
591
+ conflicts.map((c) => /* @__PURE__ */ jsxDEV7("div", {
592
+ style: {
593
+ padding: "8px",
594
+ marginBottom: "8px",
595
+ backgroundColor: "white",
596
+ borderRadius: "4px",
597
+ fontSize: "13px"
598
+ },
599
+ children: [
600
+ /* @__PURE__ */ jsxDEV7("span", {
601
+ children: c.targetKey
602
+ }, undefined, false, undefined, this),
603
+ /* @__PURE__ */ jsxDEV7("span", {
604
+ style: { margin: "0 8px", color: "#9ca3af" },
605
+ children: [
606
+ "(",
607
+ c.scopeA,
608
+ " vs ",
609
+ c.scopeB,
610
+ ")"
611
+ ]
612
+ }, undefined, true, undefined, this),
613
+ /* @__PURE__ */ jsxDEV7("div", {
614
+ style: { marginTop: "8px", display: "flex", gap: "8px" },
615
+ children: [
616
+ /* @__PURE__ */ jsxDEV7("button", {
617
+ type: "button",
618
+ onClick: () => onResolve({ targetKey: c.targetKey, chosenScope: "A" }),
619
+ style: {
620
+ padding: "4px 12px",
621
+ fontSize: "12px",
622
+ borderRadius: "4px",
623
+ border: "1px solid #e5e7eb",
624
+ backgroundColor: "white",
625
+ cursor: "pointer"
626
+ },
627
+ children: i18n.t("overlay.conflicts.keepScope", { scope: c.scopeA })
628
+ }, undefined, false, undefined, this),
629
+ /* @__PURE__ */ jsxDEV7("button", {
630
+ type: "button",
631
+ onClick: () => onResolve({ targetKey: c.targetKey, chosenScope: "B" }),
632
+ style: {
633
+ padding: "4px 12px",
634
+ fontSize: "12px",
635
+ borderRadius: "4px",
636
+ border: "1px solid #e5e7eb",
637
+ backgroundColor: "white",
638
+ cursor: "pointer"
639
+ },
640
+ children: i18n.t("overlay.conflicts.keepScope", { scope: c.scopeB })
641
+ }, undefined, false, undefined, this)
642
+ ]
643
+ }, undefined, true, undefined, this)
644
+ ]
645
+ }, `${c.targetKey}-${c.overlayIdA}-${c.overlayIdB}`, true, undefined, this))
646
+ ]
647
+ }, undefined, true, undefined, this);
648
+ }
649
+
650
+ // src/react/BundleRenderer.tsx
651
+ import { jsxDEV as jsxDEV8, Fragment } from "react/jsx-dev-runtime";
652
+ "use client";
653
+ function BundleRenderer({
654
+ assistantSlotId,
655
+ assistantSlotContent,
656
+ onPatchAccept,
657
+ onPatchReject,
658
+ onOverlayConflictResolve
659
+ } = {}) {
660
+ const plan = useBundlePlan();
661
+ const motionTokens = motionAdapterStub.getTokens(plan.adaptation.appliedDimensions.pace);
662
+ const ctx = {
663
+ plan,
664
+ bindings: plan.bindings,
665
+ preferences: plan.adaptation.appliedDimensions
666
+ };
667
+ const proposals = plan.ai?.proposals?.filter((p) => p.approvalState === "proposed");
668
+ const locale = plan.locale;
669
+ const renderSlot = (slotId, slotCtx) => {
670
+ if (assistantSlotId && slotId === assistantSlotId) {
671
+ return /* @__PURE__ */ jsxDEV8(Fragment, {
672
+ children: [
673
+ proposals && proposals.length > 0 && onPatchAccept && onPatchReject && /* @__PURE__ */ jsxDEV8("div", {
674
+ style: { marginBottom: "12px" },
675
+ children: proposals.map((p) => /* @__PURE__ */ jsxDEV8(PatchProposalCard, {
676
+ proposal: p,
677
+ onAccept: onPatchAccept,
678
+ onReject: onPatchReject,
679
+ locale
680
+ }, p.proposalId, false, undefined, this))
681
+ }, undefined, false, undefined, this),
682
+ assistantSlotContent
683
+ ]
684
+ }, undefined, true, undefined, this);
685
+ }
686
+ const nodes = getNodesForSlot(plan.nodes, slotId);
687
+ return /* @__PURE__ */ jsxDEV8(SlotRenderer, {
688
+ slotId,
689
+ ctx: slotCtx,
690
+ nodes
691
+ }, undefined, false, undefined, this);
692
+ };
693
+ const conflicts = plan.overlayConflicts ?? [];
694
+ return /* @__PURE__ */ jsxDEV8("div", {
695
+ "data-bundle-key": plan.bundleKey,
696
+ "data-surface-id": plan.surfaceId,
697
+ "data-layout-id": plan.layoutId,
698
+ style: {
699
+ display: "flex",
700
+ flexDirection: "column",
701
+ height: "100%",
702
+ minHeight: 0,
703
+ transition: motionTokens.layout ? `all ${motionTokens.durationMs}ms ease` : undefined
704
+ },
705
+ children: [
706
+ conflicts.length > 0 && onOverlayConflictResolve && /* @__PURE__ */ jsxDEV8(OverlayConflictResolver, {
707
+ conflicts,
708
+ onResolve: onOverlayConflictResolve,
709
+ locale
710
+ }, undefined, false, undefined, this),
711
+ /* @__PURE__ */ jsxDEV8(RegionRenderer, {
712
+ region: plan.layoutRoot,
713
+ ctx,
714
+ renderSlot
715
+ }, undefined, false, undefined, this)
716
+ ]
717
+ }, undefined, true, undefined, this);
718
+ }
719
+ function getNodesForSlot(nodes, slotId) {
720
+ if (slotId === "primary")
721
+ return nodes;
722
+ return [];
723
+ }
724
+ export {
725
+ BundleRenderer
726
+ };