@xemahq/ui-kernel 0.11.0 → 0.11.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.
Files changed (237) hide show
  1. package/dist/ui/chrome/page-shell.d.ts +1 -1
  2. package/dist/ui/chrome/page-shell.d.ts.map +1 -1
  3. package/dist/ui/chrome/page-shell.js +9 -4
  4. package/dist/ui/chrome/page-shell.js.map +1 -1
  5. package/package.json +6 -4
  6. package/src/index.ts +0 -17
  7. package/src/lib/biome-host/agent-validation.ts +0 -239
  8. package/src/lib/biome-host/biome-builders.ts +0 -112
  9. package/src/lib/biome-host/biome-mode.ts +0 -6
  10. package/src/lib/biome-host/biome-navigation.ts +0 -37
  11. package/src/lib/biome-host/biome-registry.ts +0 -299
  12. package/src/lib/biome-host/biome-scope-hooks.ts +0 -41
  13. package/src/lib/biome-host/biome-scope.tsx +0 -52
  14. package/src/lib/biome-host/biome-scoped-query.ts +0 -134
  15. package/src/lib/biome-host/create-biome-orval-config.ts +0 -82
  16. package/src/lib/biome-host/define-web-biome.spec.ts +0 -221
  17. package/src/lib/biome-host/define-web-biome.ts +0 -222
  18. package/src/lib/biome-host/errors.ts +0 -220
  19. package/src/lib/biome-host/frontend-biome.ts +0 -256
  20. package/src/lib/biome-host/host-bridge.ts +0 -281
  21. package/src/lib/biome-host/host-sources.ts +0 -54
  22. package/src/lib/biome-host/i18n-hooks.ts +0 -51
  23. package/src/lib/biome-host/i18n-port.test.ts +0 -50
  24. package/src/lib/biome-host/i18n-port.ts +0 -96
  25. package/src/lib/biome-host/index.ts +0 -35
  26. package/src/lib/biome-host/realtime-hooks.ts +0 -75
  27. package/src/lib/biome-host/realtime-port.ts +0 -115
  28. package/src/lib/biome-host/session-contributions.ts +0 -296
  29. package/src/lib/biome-host/use-mutation-with-error-toast.ts +0 -90
  30. package/src/lib/biome-host/use-page-state.ts +0 -248
  31. package/src/lib/capabilities/capability-context.ts +0 -25
  32. package/src/lib/capabilities/capability-provider.tsx +0 -73
  33. package/src/lib/capabilities/index.ts +0 -17
  34. package/src/lib/capabilities/types.ts +0 -69
  35. package/src/lib/capabilities/use-capability.ts +0 -79
  36. package/src/lib/contribution-registry/contribution-registry.spec.ts +0 -141
  37. package/src/lib/contribution-registry/contribution-registry.ts +0 -204
  38. package/src/lib/contribution-registry/index.ts +0 -9
  39. package/src/lib/contribution-registry/renderable-registry.ts +0 -142
  40. package/src/lib/system-bus/capability-invoke.ts +0 -92
  41. package/src/lib/system-bus/deeplink.ts +0 -210
  42. package/src/lib/system-bus/enums.ts +0 -86
  43. package/src/lib/system-bus/host-ports.ts +0 -93
  44. package/src/lib/system-bus/index.ts +0 -16
  45. package/src/lib/system-bus/intent-registry.ts +0 -109
  46. package/src/lib/system-bus/intents.ts +0 -113
  47. package/src/lib/system-bus/palette.ts +0 -78
  48. package/src/lib/system-bus/system-bus-builder.ts +0 -159
  49. package/src/lib/system-bus/system-bus.ts +0 -37
  50. package/src/lib/system-bus/windows.ts +0 -51
  51. package/src/offline/id.ts +0 -16
  52. package/src/offline/index.ts +0 -54
  53. package/src/offline/mutation.ts +0 -75
  54. package/src/offline/offline-status-badge.tsx +0 -51
  55. package/src/offline/online-controller.ts +0 -105
  56. package/src/offline/outbox.test.ts +0 -172
  57. package/src/offline/outbox.ts +0 -348
  58. package/src/offline/react-hooks.ts +0 -40
  59. package/src/offline/react.tsx +0 -32
  60. package/src/offline/storage.ts +0 -112
  61. package/src/offline/types.ts +0 -77
  62. package/src/org-db/components/DbResultTable.tsx +0 -176
  63. package/src/org-db/index.ts +0 -1
  64. package/src/pdf/index.ts +0 -11
  65. package/src/registry/index.ts +0 -9
  66. package/src/registry/lib/agent-validation-host.ts +0 -36
  67. package/src/registry/lib/biome-slot.tsx +0 -50
  68. package/src/registry/lib/biomes-enabled-context.ts +0 -20
  69. package/src/registry/lib/extension-points.ts +0 -134
  70. package/src/registry/lib/primitives/SessionEventCard.tsx +0 -164
  71. package/src/registry/lib/primitives/SessionEventTimeline.tsx +0 -95
  72. package/src/registry/lib/primitives/SessionMutationBar.tsx +0 -76
  73. package/src/registry/lib/primitives/SessionTabbedDrawer.tsx +0 -165
  74. package/src/registry/lib/primitives/index.ts +0 -18
  75. package/src/registry/lib/session-context-builder.ts +0 -84
  76. package/src/registry/lib/session-context-provider.tsx +0 -33
  77. package/src/registry/lib/session-context.ts +0 -21
  78. package/src/registry/lib/session-selectors.ts +0 -272
  79. package/src/session/comments/CommentRail.tsx +0 -164
  80. package/src/session/index.ts +0 -3
  81. package/src/session/lib/cn.ts +0 -11
  82. package/src/session/shell/SessionWorkspaceShell.tsx +0 -147
  83. package/src/session-kit/approvals/ApprovalButton.tsx +0 -89
  84. package/src/session-kit/approvals/ApprovalCard.tsx +0 -341
  85. package/src/session-kit/approvals/ApprovalsCenter.tsx +0 -336
  86. package/src/session-kit/approvals/CapabilityApprovalStickyBar.tsx +0 -118
  87. package/src/session-kit/approvals/Obligation.tsx +0 -111
  88. package/src/session-kit/approvals/ScopedBody.tsx +0 -392
  89. package/src/session-kit/approvals/approval-icons.ts +0 -31
  90. package/src/session-kit/approvals/approval-model.ts +0 -204
  91. package/src/session-kit/approvals/index.ts +0 -22
  92. package/src/session-kit/approvals/obligation-display.ts +0 -100
  93. package/src/session-kit/approvals/risk-accent.ts +0 -47
  94. package/src/session-kit/approvals/scope-icons.ts +0 -19
  95. package/src/session-kit/combobox/Combobox.tsx +0 -358
  96. package/src/session-kit/combobox/use-click-outside.ts +0 -21
  97. package/src/session-kit/display/ContextHeader.tsx +0 -148
  98. package/src/session-kit/display/FileDiffCard.tsx +0 -140
  99. package/src/session-kit/display/MD.tsx +0 -162
  100. package/src/session-kit/display/MessageTurn.tsx +0 -157
  101. package/src/session-kit/display/ThinkingPanel.tsx +0 -81
  102. package/src/session-kit/display/TodoChecklist.tsx +0 -120
  103. package/src/session-kit/display/TokenMeter.tsx +0 -89
  104. package/src/session-kit/display/ToolStrip.tsx +0 -278
  105. package/src/session-kit/display/TypingDots.tsx +0 -24
  106. package/src/session-kit/index.ts +0 -44
  107. package/src/session-kit/lib/enums.ts +0 -66
  108. package/src/session-kit/lib/portal-accent.ts +0 -30
  109. package/src/session-kit/lib/status-dot.ts +0 -68
  110. package/src/session-kit/primitives/Avatar.tsx +0 -44
  111. package/src/session-kit/primitives/PortalGlyph.tsx +0 -51
  112. package/src/session-kit/primitives/RiskPill.tsx +0 -95
  113. package/src/session-kit/primitives/ScopeDot.tsx +0 -47
  114. package/src/session-kit/primitives/Segmented.tsx +0 -71
  115. package/src/ui/branding/app-branding-context.ts +0 -20
  116. package/src/ui/branding/app-branding-provider.tsx +0 -123
  117. package/src/ui/branding/sanitize.ts +0 -89
  118. package/src/ui/breakpoints.ts +0 -14
  119. package/src/ui/capture/document-preview.tsx +0 -166
  120. package/src/ui/capture/field-spec-to-zod.test.ts +0 -81
  121. package/src/ui/capture/field-spec-to-zod.ts +0 -174
  122. package/src/ui/capture/field-spec-validate.ts +0 -236
  123. package/src/ui/capture/field-spec.test.ts +0 -49
  124. package/src/ui/capture/field-spec.ts +0 -274
  125. package/src/ui/capture/index.ts +0 -51
  126. package/src/ui/capture/schema-field-input.tsx +0 -620
  127. package/src/ui/capture/schema-form.tsx +0 -149
  128. package/src/ui/capture/submit-values.test.ts +0 -70
  129. package/src/ui/capture/submit-values.ts +0 -63
  130. package/src/ui/capture/use-prefill.ts +0 -186
  131. package/src/ui/capture/use-schema-validation.ts +0 -145
  132. package/src/ui/capture/use-wizard.ts +0 -180
  133. package/src/ui/capture/value-format.ts +0 -32
  134. package/src/ui/capture/wizard.tsx +0 -105
  135. package/src/ui/charts/bar-chart.tsx +0 -139
  136. package/src/ui/charts/chart-frame.tsx +0 -125
  137. package/src/ui/charts/chart-types.ts +0 -52
  138. package/src/ui/charts/chart-utils.ts +0 -190
  139. package/src/ui/charts/charts.test.tsx +0 -204
  140. package/src/ui/charts/donut-chart.tsx +0 -129
  141. package/src/ui/charts/index.ts +0 -27
  142. package/src/ui/charts/line-chart.tsx +0 -202
  143. package/src/ui/charts/sparkline.tsx +0 -109
  144. package/src/ui/chrome/AsyncBoundary.tsx +0 -74
  145. package/src/ui/chrome/EmptyState.tsx +0 -257
  146. package/src/ui/chrome/ErrorCard.tsx +0 -63
  147. package/src/ui/chrome/LoadingState.tsx +0 -61
  148. package/src/ui/chrome/PageHeader.tsx +0 -137
  149. package/src/ui/chrome/RecordCardList.tsx +0 -98
  150. package/src/ui/chrome/StateCard.tsx +0 -150
  151. package/src/ui/chrome/confirm-delete-dialog.tsx +0 -59
  152. package/src/ui/chrome/page-shell.tsx +0 -189
  153. package/src/ui/chrome/scope-badge.tsx +0 -40
  154. package/src/ui/chrome/status-badge.tsx +0 -79
  155. package/src/ui/cn.ts +0 -32
  156. package/src/ui/design-tokens.ts +0 -372
  157. package/src/ui/hooks/use-debounced-value.ts +0 -16
  158. package/src/ui/hooks/use-is-mobile.ts +0 -28
  159. package/src/ui/index.ts +0 -110
  160. package/src/ui/pdf/pdf-preview.tsx +0 -122
  161. package/src/ui/primitives/alert-dialog.tsx +0 -104
  162. package/src/ui/primitives/async-combobox.tsx +0 -182
  163. package/src/ui/primitives/badge-variants.ts +0 -21
  164. package/src/ui/primitives/badge.tsx +0 -25
  165. package/src/ui/primitives/button-variants.ts +0 -31
  166. package/src/ui/primitives/button.tsx +0 -29
  167. package/src/ui/primitives/card.tsx +0 -43
  168. package/src/ui/primitives/checkbox.tsx +0 -26
  169. package/src/ui/primitives/collapsible.tsx +0 -9
  170. package/src/ui/primitives/dialog.tsx +0 -103
  171. package/src/ui/primitives/dropdown-menu.tsx +0 -179
  172. package/src/ui/primitives/form-stepper.tsx +0 -94
  173. package/src/ui/primitives/form-stepper.types.ts +0 -15
  174. package/src/ui/primitives/input.tsx +0 -22
  175. package/src/ui/primitives/label.tsx +0 -17
  176. package/src/ui/primitives/overflow-tabs.tsx +0 -331
  177. package/src/ui/primitives/popover.tsx +0 -33
  178. package/src/ui/primitives/preview-device-frame.tsx +0 -213
  179. package/src/ui/primitives/radio-group.tsx +0 -36
  180. package/src/ui/primitives/resizable.tsx +0 -67
  181. package/src/ui/primitives/scroll-area.tsx +0 -38
  182. package/src/ui/primitives/select.tsx +0 -143
  183. package/src/ui/primitives/separator.tsx +0 -20
  184. package/src/ui/primitives/sheet.tsx +0 -107
  185. package/src/ui/primitives/skeleton.tsx +0 -99
  186. package/src/ui/primitives/switch.tsx +0 -27
  187. package/src/ui/primitives/table.tsx +0 -72
  188. package/src/ui/primitives/tabs.tsx +0 -53
  189. package/src/ui/primitives/tag-multi-select.tsx +0 -261
  190. package/src/ui/primitives/textarea.tsx +0 -21
  191. package/src/ui/primitives/tooltip.tsx +0 -30
  192. package/src/ui/primitives/url-preview-chrome.tsx +0 -103
  193. package/src/vista/GenericCatalogueSurface.tsx +0 -179
  194. package/src/vista/SurfaceFallbackCard.tsx +0 -109
  195. package/src/vista/VistaPanel.tsx +0 -163
  196. package/src/vista/form-payload.spec.ts +0 -139
  197. package/src/vista/html/CustomUiFrame.spec.tsx +0 -127
  198. package/src/vista/html/CustomUiFrame.tsx +0 -206
  199. package/src/vista/html/custom-ui-frame-bridge.spec.ts +0 -191
  200. package/src/vista/html/custom-ui-frame-bridge.ts +0 -98
  201. package/src/vista/html/custom-ui-frame-contract.ts +0 -88
  202. package/src/vista/html/custom-ui-intents.spec.ts +0 -135
  203. package/src/vista/html/custom-ui-intents.ts +0 -155
  204. package/src/vista/html/custom-ui-srcdoc.spec.ts +0 -151
  205. package/src/vista/html/custom-ui-srcdoc.ts +0 -193
  206. package/src/vista/html/index.ts +0 -13
  207. package/src/vista/index.ts +0 -52
  208. package/src/vista/surface-catalogue.spec.ts +0 -140
  209. package/src/vista/surface-catalogue.ts +0 -90
  210. package/src/vista/surface-icons.ts +0 -57
  211. package/src/vista/surface-registry.ts +0 -56
  212. package/src/vista/surfaces/ChartSurface.tsx +0 -34
  213. package/src/vista/surfaces/FilesSurface.tsx +0 -202
  214. package/src/vista/surfaces/FormSurface.tsx +0 -380
  215. package/src/vista/surfaces/HtmlSurface.tsx +0 -43
  216. package/src/vista/surfaces/TableSurface.tsx +0 -100
  217. package/src/vista/surfaces/UrlSurface.tsx +0 -40
  218. package/src/vista/surfaces/blob-surfaces.tsx +0 -139
  219. package/src/vista/surfaces/elicitation-transport.spec.ts +0 -369
  220. package/src/vista/surfaces/elicitation-transport.ts +0 -367
  221. package/src/vista/surfaces/file-surface-utils.ts +0 -69
  222. package/src/vista/surfaces/index.ts +0 -24
  223. package/src/vista/surfaces/register-surfaces.tsx +0 -139
  224. package/src/vista/surfaces/text-surfaces.tsx +0 -132
  225. package/src/vista/use-vista-tabs.ts +0 -196
  226. package/src/vista/vista-code-renderer-context.ts +0 -16
  227. package/src/vista/vista-code-renderer.tsx +0 -35
  228. package/src/vista/vista-file-context.ts +0 -14
  229. package/src/vista/vista-file-source.tsx +0 -141
  230. package/src/vista/vista-form-context.ts +0 -20
  231. package/src/vista/vista-form-host.tsx +0 -48
  232. package/src/vista/vista-model.ts +0 -137
  233. package/src/vista/vista-open-context.tsx +0 -27
  234. package/src/vista/vista-open-state.ts +0 -11
  235. package/src/vista/vista-payloads.ts +0 -635
  236. package/src/vista/vista-tabs-manifest.ts +0 -138
  237. package/src/vista/vista-tools.ts +0 -232
@@ -1,141 +0,0 @@
1
- /**
2
- * Guards the shared closed+open contribution registry core — the ONE
3
- * implementation behind the ChatWidget, biome output-renderer, reply-variant
4
- * and Vista-surface planes. Every property the hand-written copies had must
5
- * survive the extraction.
6
- *
7
- * Runs under the host-web vitest mirror (this package carries no vitest dep).
8
- */
9
- import { describe, expect, it, vi } from 'vitest';
10
-
11
- import {
12
- ContributionFallbackReason,
13
- DuplicateContributionPolicy,
14
- createContributionRegistry,
15
- createRenderableContributionRegistry,
16
- } from './index';
17
-
18
- function makeRegistry(): ReturnType<typeof createContributionRegistry<string>> {
19
- return createContributionRegistry<string>({
20
- name: 'test',
21
- reservedKinds: ['plan', 'diff'],
22
- });
23
- }
24
-
25
- describe('createContributionRegistry', () => {
26
- it('resolves first-party before open, and lists both', () => {
27
- const registry = makeRegistry();
28
- registry.registerFirstParty('plan', 'builtin-plan');
29
- registry.register('acme:gantt', 'acme-gantt');
30
- expect(registry.get('plan')).toBe('builtin-plan');
31
- expect(registry.get('acme:gantt')).toBe('acme-gantt');
32
- expect(registry.has('nope')).toBe(false);
33
- expect(registry.list()).toEqual(['acme:gantt', 'plan']);
34
- expect(registry.listOpen()).toEqual(['acme:gantt']);
35
- expect([...registry.entries().keys()].sort()).toEqual(['acme:gantt', 'plan']);
36
- });
37
-
38
- it('refuses to let the open set claim a reserved first-party kind', () => {
39
- const registry = makeRegistry();
40
- expect(registry.isReserved('diff')).toBe(true);
41
- expect(() => registry.register('diff', 'hijack')).toThrow(/reserved/);
42
- // The namespaced form is fine.
43
- expect(() => registry.register('acme:diff', 'ok')).not.toThrow();
44
- });
45
-
46
- it('is idempotent for the identical entry and throws for a different one', () => {
47
- const registry = makeRegistry();
48
- registry.register('acme:gantt', 'entry');
49
- expect(() => registry.register('acme:gantt', 'entry')).not.toThrow();
50
- expect(() => registry.register('acme:gantt', 'other')).toThrow(
51
- /already registered/,
52
- );
53
- registry.registerFirstParty('plan', 'builtin');
54
- expect(() => registry.registerFirstParty('plan', 'builtin')).not.toThrow();
55
- expect(() => registry.registerFirstParty('plan', 'other')).toThrow(
56
- /already registered/,
57
- );
58
- });
59
-
60
- it('resets only the OPEN set', () => {
61
- const registry = makeRegistry();
62
- registry.registerFirstParty('plan', 'builtin');
63
- registry.register('acme:gantt', 'entry');
64
- registry.__resetOpenForTests();
65
- expect(registry.list()).toEqual(['plan']);
66
- });
67
-
68
- it('reports — never swallows — a duplicate under FirstWins', () => {
69
- const onDuplicate = vi.fn();
70
- const registry = createContributionRegistry<string>({
71
- name: 'overlay',
72
- duplicatePolicy: DuplicateContributionPolicy.FirstWins,
73
- onDuplicate,
74
- });
75
- registry.register('k', 'first');
76
- registry.register('k', 'second');
77
- expect(registry.get('k')).toBe('first');
78
- expect(onDuplicate).toHaveBeenCalledWith('k', 'first', 'second');
79
- });
80
-
81
- it('refuses FirstWins without a reporter', () => {
82
- expect(() =>
83
- createContributionRegistry<string>({
84
- name: 'overlay',
85
- duplicatePolicy: DuplicateContributionPolicy.FirstWins,
86
- }),
87
- ).toThrow(/onDuplicate/);
88
- });
89
- });
90
-
91
- describe('createRenderableContributionRegistry', () => {
92
- const registry = createRenderableContributionRegistry<string>({
93
- name: 'renderable',
94
- reservedKinds: ['plan'],
95
- });
96
- registry.registerFirstParty<{ label: string }>('plan', {
97
- version: 2,
98
- validate: (payload) =>
99
- typeof payload === 'object' &&
100
- payload !== null &&
101
- typeof (payload as { label?: unknown }).label === 'string'
102
- ? (payload as { label: string })
103
- : null,
104
- render: (payload) => `plan:${payload.label}`,
105
- });
106
-
107
- it('renders a matching envelope', () => {
108
- const resolution = registry.resolve({
109
- kind: 'plan',
110
- version: 1,
111
- payload: { label: 'ship it' },
112
- });
113
- expect(resolution).toEqual({
114
- matched: true,
115
- kind: 'plan',
116
- version: 2,
117
- rendered: 'plan:ship it',
118
- });
119
- });
120
-
121
- it('never throws — it returns a typed reason instead', () => {
122
- expect(
123
- registry.resolve({ kind: 'nope', version: 1, payload: {} }),
124
- ).toMatchObject({
125
- matched: false,
126
- reason: ContributionFallbackReason.UnknownKind,
127
- });
128
- expect(
129
- registry.resolve({ kind: 'plan', version: 99, payload: {} }),
130
- ).toMatchObject({
131
- matched: false,
132
- reason: ContributionFallbackReason.UnsupportedVersion,
133
- });
134
- expect(
135
- registry.resolve({ kind: 'plan', version: 1, payload: { label: 7 } }),
136
- ).toMatchObject({
137
- matched: false,
138
- reason: ContributionFallbackReason.InvalidPayload,
139
- });
140
- });
141
- });
@@ -1,204 +0,0 @@
1
- /**
2
- * `createContributionRegistry` — the ONE two-layer closed+open registry core
3
- * the Xema frontend uses everywhere a biome may contribute into a set the
4
- * platform also ships a closed first-party version of.
5
- *
6
- * Before this module the exact same bookkeeping was hand-written four times
7
- * (in-chat widgets, biome output renderers, open reply variants, and — next —
8
- * Vista surfaces), each with slightly different guards. This is that core,
9
- * extracted once (reuse register U1).
10
- *
11
- * ── The two layers ──────────────────────────────────────────────────────────
12
- * • a CLOSED first-party set, registered at module load and keyed by a
13
- * platform enum value;
14
- * • an OPEN biome set, registered at runtime (a biome registers from its
15
- * `FrontendBiome.init()` hook) and keyed by a namespaced `<biomeId>:<kind>`
16
- * slug.
17
- *
18
- * ── The invariants (all fail-loud, none silent) ─────────────────────────────
19
- * • RESERVED KINDS. Every first-party kind is reserved: `register()` throws
20
- * if a biome tries to claim one. The open set can never shadow the closed
21
- * one.
22
- * • DUPLICATE GUARD. Registering the EXACT same entry object twice is a
23
- * no-op (this is what tolerates React Fast Refresh / a double-invoked
24
- * `init()`); registering a DIFFERENT entry for a kind that is already
25
- * taken is an error — two biomes cannot silently shadow each other.
26
- * • The one exception is {@link DuplicateContributionPolicy.FirstWins}, for
27
- * registries rebuilt on a hot path where a throw would crash a render
28
- * (the biome output-renderer overlay). It is NOT a silent fallback: an
29
- * `onDuplicate` reporter is REQUIRED, and the registry factory throws at
30
- * construction if it is missing.
31
- *
32
- * Resolution itself lives in the caller (or in `renderable-registry.ts` for the
33
- * versioned + payload-validated flavour) and NEVER throws.
34
- */
35
-
36
- /** What to do when a DIFFERENT entry is registered for an already-taken kind. */
37
- export enum DuplicateContributionPolicy {
38
- /**
39
- * Throw. The default, and correct for every registry whose registrations
40
- * happen once at module load or once per biome `init()`.
41
- */
42
- Throw = 'throw',
43
- /**
44
- * Keep the first registration and report the loser through `onDuplicate`.
45
- * For registries REBUILT on a hot path (e.g. per render) where throwing
46
- * would take down the UI. Requires `onDuplicate` — there is no silent mode.
47
- */
48
- FirstWins = 'first-wins',
49
- }
50
-
51
- /** Options for {@link createContributionRegistry}. */
52
- export interface ContributionRegistryOptions<TEntry> {
53
- /** Registry name, used verbatim in every thrown message. */
54
- readonly name: string;
55
- /**
56
- * The CLOSED first-party kinds. Reserved: `register()` refuses them so a
57
- * biome can never shadow a platform kind. Typically `Object.values(SomeEnum)`.
58
- */
59
- readonly reservedKinds?: Iterable<string>;
60
- /** Duplicate handling. Defaults to {@link DuplicateContributionPolicy.Throw}. */
61
- readonly duplicatePolicy?: DuplicateContributionPolicy;
62
- /**
63
- * Reporter for a rejected duplicate under
64
- * {@link DuplicateContributionPolicy.FirstWins}. REQUIRED under that policy.
65
- */
66
- readonly onDuplicate?: (
67
- kind: string,
68
- existing: TEntry,
69
- rejected: TEntry,
70
- ) => void;
71
- }
72
-
73
- /** The two-layer registry surface. */
74
- export interface ContributionRegistry<TEntry> {
75
- /** Registry name (diagnostics). */
76
- readonly name: string;
77
- /**
78
- * Register a FIRST-PARTY entry for a closed platform kind. Called once per
79
- * kind at module load.
80
- */
81
- registerFirstParty(kind: string, entry: TEntry): void;
82
- /**
83
- * OPEN seam: register a biome entry under its namespaced `<biomeId>:<kind>`
84
- * slug. Throws when the slug is a reserved first-party kind.
85
- */
86
- register(kind: string, entry: TEntry): void;
87
- /** True when SOME entry (first-party or biome) is registered for the kind. */
88
- has(kind: string): boolean;
89
- /** The entry for a kind — first-party wins — or `undefined`. */
90
- get(kind: string): TEntry | undefined;
91
- /** True when the kind belongs to the closed first-party set. */
92
- isReserved(kind: string): boolean;
93
- /** Every registered kind (sorted) — diagnostics + tests. */
94
- list(): readonly string[];
95
- /** Only the OPEN (biome-contributed) kinds (sorted). */
96
- listOpen(): readonly string[];
97
- /** Flattened `kind -> entry` view, first-party wins. Diagnostics + overlays. */
98
- entries(): ReadonlyMap<string, TEntry>;
99
- /** Test-only: clear the OPEN set (the first-party set stays). */
100
- __resetOpenForTests(): void;
101
- }
102
-
103
- export function createContributionRegistry<TEntry>(
104
- options: ContributionRegistryOptions<TEntry>,
105
- ): ContributionRegistry<TEntry> {
106
- const {
107
- name,
108
- reservedKinds,
109
- duplicatePolicy = DuplicateContributionPolicy.Throw,
110
- onDuplicate,
111
- } = options;
112
-
113
- if (
114
- duplicatePolicy === DuplicateContributionPolicy.FirstWins &&
115
- onDuplicate === undefined
116
- ) {
117
- throw new Error(
118
- `${name} registry: DuplicateContributionPolicy.FirstWins requires an ` +
119
- `'onDuplicate' reporter — a dropped contribution must never be silent.`,
120
- );
121
- }
122
-
123
- const reserved = new Set<string>(reservedKinds ?? []);
124
- const firstParty = new Map<string, TEntry>();
125
- const open = new Map<string, TEntry>();
126
-
127
- /**
128
- * Idempotent for the IDENTICAL entry (Fast Refresh / double-invoked
129
- * `init()`); an error for a DIFFERENT one. Returns whether the entry landed.
130
- */
131
- function put(target: Map<string, TEntry>, kind: string, entry: TEntry): void {
132
- const existing = target.get(kind);
133
- if (existing === undefined) {
134
- target.set(kind, entry);
135
- return;
136
- }
137
- if (existing === entry) {
138
- return;
139
- }
140
- if (duplicatePolicy === DuplicateContributionPolicy.FirstWins) {
141
- // `onDuplicate` is guaranteed present under this policy (checked above).
142
- (onDuplicate as (k: string, e: TEntry, r: TEntry) => void)(
143
- kind,
144
- existing,
145
- entry,
146
- );
147
- return;
148
- }
149
- throw new Error(
150
- `${name} registry: a DIFFERENT entry is already registered for kind ` +
151
- `'${kind}'. Two contributors cannot claim the same slug.`,
152
- );
153
- }
154
-
155
- return {
156
- name,
157
-
158
- registerFirstParty(kind: string, entry: TEntry): void {
159
- put(firstParty, kind, entry);
160
- },
161
-
162
- register(kind: string, entry: TEntry): void {
163
- if (reserved.has(kind)) {
164
- throw new Error(
165
- `${name} registry: '${kind}' is a reserved first-party kind and ` +
166
- `cannot be overridden by a biome. Use a namespaced ` +
167
- `'<biomeId>:${kind}' slug.`,
168
- );
169
- }
170
- put(open, kind, entry);
171
- },
172
-
173
- has(kind: string): boolean {
174
- return firstParty.has(kind) || open.has(kind);
175
- },
176
-
177
- get(kind: string): TEntry | undefined {
178
- return firstParty.get(kind) ?? open.get(kind);
179
- },
180
-
181
- isReserved(kind: string): boolean {
182
- return reserved.has(kind);
183
- },
184
-
185
- list(): readonly string[] {
186
- return [...firstParty.keys(), ...open.keys()].sort();
187
- },
188
-
189
- listOpen(): readonly string[] {
190
- return [...open.keys()].sort();
191
- },
192
-
193
- entries(): ReadonlyMap<string, TEntry> {
194
- // First-party last so it wins on a key present in both (which `register`
195
- // already forbids for reserved kinds, but `entries()` must not depend on
196
- // that to be correct).
197
- return new Map<string, TEntry>([...open, ...firstParty]);
198
- },
199
-
200
- __resetOpenForTests(): void {
201
- open.clear();
202
- },
203
- };
204
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * The shared two-layer (closed first-party + open biome) contribution registry
3
- * core, and its versioned/validated renderable flavour.
4
- *
5
- * One implementation, four consumers: in-chat ChatWidgets, biome output
6
- * renderers, open reply variants, and Vista surfaces.
7
- */
8
- export * from './contribution-registry';
9
- export * from './renderable-registry';
@@ -1,142 +0,0 @@
1
- /**
2
- * The RENDERABLE flavour of {@link createContributionRegistry}: a two-layer
3
- * closed+open registry whose entries are versioned renderers with a narrowing
4
- * payload validator, plus the fail-safe resolution every such plane needs.
5
- *
6
- * This is the shape the in-chat ChatWidget plane and the Vista render plane
7
- * both want: an envelope `{ kind, version, payload }` arrives from an agent,
8
- * and the frontend must turn it into something drawable WITHOUT ever throwing
9
- * and WITHOUT ever silently drawing a coerced half-widget. Resolution returns a
10
- * typed reason instead, which the caller renders as a safe fallback card.
11
- */
12
- import {
13
- createContributionRegistry,
14
- type ContributionRegistry,
15
- type ContributionRegistryOptions,
16
- } from './contribution-registry';
17
-
18
- /**
19
- * Why an envelope fell back to the safe card. Populated on the resolution so
20
- * the Studio debugger (and dev logs) can see WHY — mirrors the Model Resolution
21
- * Matrix's `ResolvedModelDecision`. Closed set.
22
- */
23
- export enum ContributionFallbackReason {
24
- UnknownKind = 'unknown-kind',
25
- InvalidPayload = 'invalid-payload',
26
- UnsupportedVersion = 'unsupported-version',
27
- }
28
-
29
- /** The minimum an agent-emitted envelope must carry to be resolvable. */
30
- export interface ContributionEnvelope {
31
- readonly kind: string;
32
- readonly version: number;
33
- readonly payload: unknown;
34
- }
35
-
36
- /**
37
- * A versioned renderer. `validate` narrows the wire payload to the renderer's
38
- * own type (returning `null` routes to the fallback with `InvalidPayload`) and
39
- * MUST NOT throw; `render` draws from the narrowed payload.
40
- */
41
- export interface RenderableContributionEntry<TRendered, TPayload = unknown> {
42
- /** Highest schema version this renderer supports. */
43
- readonly version: number;
44
- /** Narrowing validator. Returns the typed payload, or `null`. MUST NOT throw. */
45
- validate(payload: unknown): TPayload | null;
46
- /** Draw from the narrowed payload. */
47
- render(payload: TPayload): TRendered;
48
- }
49
-
50
- /** The outcome of resolving an envelope — inspectable for the Studio debugger. */
51
- export type RenderableResolution<TRendered> =
52
- | {
53
- readonly matched: true;
54
- readonly kind: string;
55
- readonly version: number;
56
- readonly rendered: TRendered;
57
- }
58
- | {
59
- readonly matched: false;
60
- readonly kind: string;
61
- readonly reason: ContributionFallbackReason;
62
- };
63
-
64
- /** A {@link ContributionRegistry} of versioned renderers, plus `resolve`. */
65
- export interface RenderableContributionRegistry<TRendered>
66
- extends Omit<
67
- ContributionRegistry<RenderableContributionEntry<TRendered>>,
68
- 'registerFirstParty' | 'register'
69
- > {
70
- registerFirstParty<TPayload>(
71
- kind: string,
72
- entry: RenderableContributionEntry<TRendered, TPayload>,
73
- ): void;
74
- register<TPayload>(
75
- kind: string,
76
- entry: RenderableContributionEntry<TRendered, TPayload>,
77
- ): void;
78
- /**
79
- * Resolve an envelope. Pure + deterministic so it can run in render, and it
80
- * NEVER throws — an unknown kind, a payload the entry rejects, or a `version`
81
- * newer than the entry supports ALL yield `matched: false` with a typed
82
- * reason the caller renders as the safe fallback card.
83
- */
84
- resolve(envelope: ContributionEnvelope): RenderableResolution<TRendered>;
85
- }
86
-
87
- export function createRenderableContributionRegistry<TRendered>(
88
- options: ContributionRegistryOptions<RenderableContributionEntry<TRendered>>,
89
- ): RenderableContributionRegistry<TRendered> {
90
- const registry =
91
- createContributionRegistry<RenderableContributionEntry<TRendered>>(options);
92
-
93
- return {
94
- ...registry,
95
-
96
- registerFirstParty<TPayload>(
97
- kind: string,
98
- entry: RenderableContributionEntry<TRendered, TPayload>,
99
- ): void {
100
- registry.registerFirstParty(kind, entry);
101
- },
102
-
103
- register<TPayload>(
104
- kind: string,
105
- entry: RenderableContributionEntry<TRendered, TPayload>,
106
- ): void {
107
- registry.register(kind, entry);
108
- },
109
-
110
- resolve(envelope: ContributionEnvelope): RenderableResolution<TRendered> {
111
- const entry = registry.get(envelope.kind);
112
- if (entry === undefined) {
113
- return {
114
- matched: false,
115
- kind: envelope.kind,
116
- reason: ContributionFallbackReason.UnknownKind,
117
- };
118
- }
119
- if (envelope.version > entry.version) {
120
- return {
121
- matched: false,
122
- kind: envelope.kind,
123
- reason: ContributionFallbackReason.UnsupportedVersion,
124
- };
125
- }
126
- const narrowed = entry.validate(envelope.payload);
127
- if (narrowed === null) {
128
- return {
129
- matched: false,
130
- kind: envelope.kind,
131
- reason: ContributionFallbackReason.InvalidPayload,
132
- };
133
- }
134
- return {
135
- matched: true,
136
- kind: envelope.kind,
137
- version: entry.version,
138
- rendered: entry.render(narrowed),
139
- };
140
- },
141
- };
142
- }
@@ -1,92 +0,0 @@
1
- import type { CapabilityRef } from '@xemahq/kernel-contracts/capability';
2
- import type { SpaceRef } from '@xemahq/kernel-contracts/space';
3
-
4
- /**
5
- * Orchestration metadata the SystemBus carries on every
6
- * `capability.invoke` so the backend capability-router can build its
7
- * `ExecutionContext` envelope and record who invoked what, from where,
8
- * in which space, against which environment.
9
- *
10
- * **This is pure orchestration data. The SystemBus NEVER inspects it to
11
- * decide allow/deny.** The backend capability-router is the single
12
- * authority on auth / tenancy / policy / audit. The SystemBus's only job
13
- * is to faithfully relay this metadata to the router and pass the result
14
- * back; it adds no authorization of its own.
15
- *
16
- * The fields map 1:1 onto the gateway's per-invocation envelope:
17
- * - `sourceBiomeId` → `ExecutionContext.biome.id`
18
- * - `targetCapabilityRef` → `ExecutionContext.capability.ref`
19
- * - `spaceRef` → `ExecutionContext.space`
20
- * - `environmentId` → `ExecutionContext.environment.id`
21
- * - `actorId` → `ExecutionContext.subject` (the host resolves the
22
- * full SubjectRef from the actor's session).
23
- */
24
- export interface CapabilityInvokeMeta {
25
- /** Biome that originated the invocation (for provenance + audit). */
26
- readonly sourceBiomeId: string;
27
- /** The capability being invoked. Mirrors the `ref` argument; carried
28
- * explicitly so the metadata is self-describing in audit records. */
29
- readonly targetCapabilityRef: CapabilityRef;
30
- /** The space (5/7-tier scope) the invocation runs in. */
31
- readonly spaceRef: SpaceRef;
32
- /** Canonical `environment:<slug>` ref of the active execution environment. */
33
- readonly environmentId: string;
34
- /** The acting subject's id (user / agent / app). The host expands this
35
- * into the full `SubjectRef` server-side; the SystemBus only carries
36
- * the id, never a credential. */
37
- readonly actorId: string;
38
- }
39
-
40
- /**
41
- * Result of a `capability.invoke`. Mirrors the capability-router's
42
- * `InvokeMetaToolResponseDto` wire shape (`output? / auditId /
43
- * obligations`) without importing the generated client — the kernel
44
- * contract stays framework- and transport-agnostic.
45
- *
46
- * `output` is `undefined` on denial / approval-required outcomes; the
47
- * caller MUST treat its absence explicitly (fetch the structured denial
48
- * via `auditId`) rather than assume success. `auditId` is ALWAYS
49
- * populated, including on denial — this is the audit anchor.
50
- */
51
- export interface CapabilityInvokeResult<TOutput = unknown> {
52
- /** Capability output payload. Omitted on denial / approval-required. */
53
- readonly output?: TOutput;
54
- /** Audit entry id. Always populated, including on denial. */
55
- readonly auditId: string;
56
- /**
57
- * Closed-set policy obligations the caller must honour locally
58
- * (e.g. `redact-secrets`, `max-cost-usd`). Sourced verbatim from the
59
- * router response. The string union is left open at the contract layer
60
- * because the obligation enum is owned by `@xemahq/kernel-contracts/policy`;
61
- * the host maps these to the typed enum when it honours them.
62
- */
63
- readonly obligations: readonly string[];
64
- }
65
-
66
- /**
67
- * The `capability.invoke` surface of the SystemBus.
68
- *
69
- * `invoke()` routes the call to the host's capability-router client. The
70
- * backend enforces auth / tenancy / policy / audit; the SystemBus adds
71
- * NONE of those — it is pure orchestration. A non-2xx transport failure
72
- * rejects the returned promise (fail-fast); a *policy denial* resolves
73
- * with `output === undefined` + a populated `auditId` (the router's
74
- * structured outcome), so denial is observable, never silently swallowed.
75
- */
76
- export interface CapabilityBus {
77
- /**
78
- * Invoke a capability through the backend router.
79
- *
80
- * @param ref The capability to invoke (`<domain>:<resource>.<verb>@<major>`).
81
- * @param input The capability input payload (validated server-side
82
- * against the descriptor's `inputSchema`).
83
- * @param meta Orchestration metadata for the `ExecutionContext`.
84
- * The host fills `targetCapabilityRef` from `ref` if the
85
- * caller omits it; all other fields are required.
86
- */
87
- invoke<TInput = unknown, TOutput = unknown>(
88
- ref: CapabilityRef,
89
- input: TInput,
90
- meta: CapabilityInvokeMeta,
91
- ): Promise<CapabilityInvokeResult<TOutput>>;
92
- }