@xemahq/ui-kernel 0.11.1 → 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 (234) hide show
  1. package/package.json +1 -2
  2. package/src/index.ts +0 -17
  3. package/src/lib/biome-host/agent-validation.ts +0 -239
  4. package/src/lib/biome-host/biome-builders.ts +0 -112
  5. package/src/lib/biome-host/biome-mode.ts +0 -6
  6. package/src/lib/biome-host/biome-navigation.ts +0 -37
  7. package/src/lib/biome-host/biome-registry.ts +0 -299
  8. package/src/lib/biome-host/biome-scope-hooks.ts +0 -41
  9. package/src/lib/biome-host/biome-scope.tsx +0 -52
  10. package/src/lib/biome-host/biome-scoped-query.ts +0 -134
  11. package/src/lib/biome-host/create-biome-orval-config.ts +0 -82
  12. package/src/lib/biome-host/define-web-biome.spec.ts +0 -221
  13. package/src/lib/biome-host/define-web-biome.ts +0 -222
  14. package/src/lib/biome-host/errors.ts +0 -220
  15. package/src/lib/biome-host/frontend-biome.ts +0 -256
  16. package/src/lib/biome-host/host-bridge.ts +0 -281
  17. package/src/lib/biome-host/host-sources.ts +0 -54
  18. package/src/lib/biome-host/i18n-hooks.ts +0 -51
  19. package/src/lib/biome-host/i18n-port.test.ts +0 -50
  20. package/src/lib/biome-host/i18n-port.ts +0 -96
  21. package/src/lib/biome-host/index.ts +0 -35
  22. package/src/lib/biome-host/realtime-hooks.ts +0 -75
  23. package/src/lib/biome-host/realtime-port.ts +0 -115
  24. package/src/lib/biome-host/session-contributions.ts +0 -296
  25. package/src/lib/biome-host/use-mutation-with-error-toast.ts +0 -90
  26. package/src/lib/biome-host/use-page-state.ts +0 -248
  27. package/src/lib/capabilities/capability-context.ts +0 -25
  28. package/src/lib/capabilities/capability-provider.tsx +0 -73
  29. package/src/lib/capabilities/index.ts +0 -17
  30. package/src/lib/capabilities/types.ts +0 -69
  31. package/src/lib/capabilities/use-capability.ts +0 -79
  32. package/src/lib/contribution-registry/contribution-registry.spec.ts +0 -141
  33. package/src/lib/contribution-registry/contribution-registry.ts +0 -204
  34. package/src/lib/contribution-registry/index.ts +0 -9
  35. package/src/lib/contribution-registry/renderable-registry.ts +0 -142
  36. package/src/lib/system-bus/capability-invoke.ts +0 -92
  37. package/src/lib/system-bus/deeplink.ts +0 -210
  38. package/src/lib/system-bus/enums.ts +0 -86
  39. package/src/lib/system-bus/host-ports.ts +0 -93
  40. package/src/lib/system-bus/index.ts +0 -16
  41. package/src/lib/system-bus/intent-registry.ts +0 -109
  42. package/src/lib/system-bus/intents.ts +0 -113
  43. package/src/lib/system-bus/palette.ts +0 -78
  44. package/src/lib/system-bus/system-bus-builder.ts +0 -159
  45. package/src/lib/system-bus/system-bus.ts +0 -37
  46. package/src/lib/system-bus/windows.ts +0 -51
  47. package/src/offline/id.ts +0 -16
  48. package/src/offline/index.ts +0 -54
  49. package/src/offline/mutation.ts +0 -75
  50. package/src/offline/offline-status-badge.tsx +0 -51
  51. package/src/offline/online-controller.ts +0 -105
  52. package/src/offline/outbox.test.ts +0 -172
  53. package/src/offline/outbox.ts +0 -348
  54. package/src/offline/react-hooks.ts +0 -40
  55. package/src/offline/react.tsx +0 -32
  56. package/src/offline/storage.ts +0 -112
  57. package/src/offline/types.ts +0 -77
  58. package/src/org-db/components/DbResultTable.tsx +0 -176
  59. package/src/org-db/index.ts +0 -1
  60. package/src/pdf/index.ts +0 -11
  61. package/src/registry/index.ts +0 -9
  62. package/src/registry/lib/agent-validation-host.ts +0 -36
  63. package/src/registry/lib/biome-slot.tsx +0 -50
  64. package/src/registry/lib/biomes-enabled-context.ts +0 -20
  65. package/src/registry/lib/extension-points.ts +0 -134
  66. package/src/registry/lib/primitives/SessionEventCard.tsx +0 -164
  67. package/src/registry/lib/primitives/SessionEventTimeline.tsx +0 -95
  68. package/src/registry/lib/primitives/SessionMutationBar.tsx +0 -76
  69. package/src/registry/lib/primitives/SessionTabbedDrawer.tsx +0 -165
  70. package/src/registry/lib/primitives/index.ts +0 -18
  71. package/src/registry/lib/session-context-builder.ts +0 -84
  72. package/src/registry/lib/session-context-provider.tsx +0 -33
  73. package/src/registry/lib/session-context.ts +0 -21
  74. package/src/registry/lib/session-selectors.ts +0 -272
  75. package/src/session/comments/CommentRail.tsx +0 -164
  76. package/src/session/index.ts +0 -3
  77. package/src/session/lib/cn.ts +0 -11
  78. package/src/session/shell/SessionWorkspaceShell.tsx +0 -147
  79. package/src/session-kit/approvals/ApprovalButton.tsx +0 -89
  80. package/src/session-kit/approvals/ApprovalCard.tsx +0 -341
  81. package/src/session-kit/approvals/ApprovalsCenter.tsx +0 -336
  82. package/src/session-kit/approvals/CapabilityApprovalStickyBar.tsx +0 -118
  83. package/src/session-kit/approvals/Obligation.tsx +0 -111
  84. package/src/session-kit/approvals/ScopedBody.tsx +0 -392
  85. package/src/session-kit/approvals/approval-icons.ts +0 -31
  86. package/src/session-kit/approvals/approval-model.ts +0 -204
  87. package/src/session-kit/approvals/index.ts +0 -22
  88. package/src/session-kit/approvals/obligation-display.ts +0 -100
  89. package/src/session-kit/approvals/risk-accent.ts +0 -47
  90. package/src/session-kit/approvals/scope-icons.ts +0 -19
  91. package/src/session-kit/combobox/Combobox.tsx +0 -358
  92. package/src/session-kit/combobox/use-click-outside.ts +0 -21
  93. package/src/session-kit/display/ContextHeader.tsx +0 -148
  94. package/src/session-kit/display/FileDiffCard.tsx +0 -140
  95. package/src/session-kit/display/MD.tsx +0 -162
  96. package/src/session-kit/display/MessageTurn.tsx +0 -157
  97. package/src/session-kit/display/ThinkingPanel.tsx +0 -81
  98. package/src/session-kit/display/TodoChecklist.tsx +0 -120
  99. package/src/session-kit/display/TokenMeter.tsx +0 -89
  100. package/src/session-kit/display/ToolStrip.tsx +0 -278
  101. package/src/session-kit/display/TypingDots.tsx +0 -24
  102. package/src/session-kit/index.ts +0 -44
  103. package/src/session-kit/lib/enums.ts +0 -66
  104. package/src/session-kit/lib/portal-accent.ts +0 -30
  105. package/src/session-kit/lib/status-dot.ts +0 -68
  106. package/src/session-kit/primitives/Avatar.tsx +0 -44
  107. package/src/session-kit/primitives/PortalGlyph.tsx +0 -51
  108. package/src/session-kit/primitives/RiskPill.tsx +0 -95
  109. package/src/session-kit/primitives/ScopeDot.tsx +0 -47
  110. package/src/session-kit/primitives/Segmented.tsx +0 -71
  111. package/src/ui/branding/app-branding-context.ts +0 -20
  112. package/src/ui/branding/app-branding-provider.tsx +0 -123
  113. package/src/ui/branding/sanitize.ts +0 -89
  114. package/src/ui/breakpoints.ts +0 -14
  115. package/src/ui/capture/document-preview.tsx +0 -166
  116. package/src/ui/capture/field-spec-to-zod.test.ts +0 -81
  117. package/src/ui/capture/field-spec-to-zod.ts +0 -174
  118. package/src/ui/capture/field-spec-validate.ts +0 -236
  119. package/src/ui/capture/field-spec.test.ts +0 -49
  120. package/src/ui/capture/field-spec.ts +0 -274
  121. package/src/ui/capture/index.ts +0 -51
  122. package/src/ui/capture/schema-field-input.tsx +0 -620
  123. package/src/ui/capture/schema-form.tsx +0 -149
  124. package/src/ui/capture/submit-values.test.ts +0 -70
  125. package/src/ui/capture/submit-values.ts +0 -63
  126. package/src/ui/capture/use-prefill.ts +0 -186
  127. package/src/ui/capture/use-schema-validation.ts +0 -145
  128. package/src/ui/capture/use-wizard.ts +0 -180
  129. package/src/ui/capture/value-format.ts +0 -32
  130. package/src/ui/capture/wizard.tsx +0 -105
  131. package/src/ui/charts/bar-chart.tsx +0 -139
  132. package/src/ui/charts/chart-frame.tsx +0 -125
  133. package/src/ui/charts/chart-types.ts +0 -52
  134. package/src/ui/charts/chart-utils.ts +0 -190
  135. package/src/ui/charts/charts.test.tsx +0 -204
  136. package/src/ui/charts/donut-chart.tsx +0 -129
  137. package/src/ui/charts/index.ts +0 -27
  138. package/src/ui/charts/line-chart.tsx +0 -202
  139. package/src/ui/charts/sparkline.tsx +0 -109
  140. package/src/ui/chrome/AsyncBoundary.tsx +0 -74
  141. package/src/ui/chrome/EmptyState.tsx +0 -257
  142. package/src/ui/chrome/ErrorCard.tsx +0 -63
  143. package/src/ui/chrome/LoadingState.tsx +0 -61
  144. package/src/ui/chrome/PageHeader.tsx +0 -137
  145. package/src/ui/chrome/RecordCardList.tsx +0 -98
  146. package/src/ui/chrome/StateCard.tsx +0 -150
  147. package/src/ui/chrome/confirm-delete-dialog.tsx +0 -59
  148. package/src/ui/chrome/page-shell.spec.tsx +0 -117
  149. package/src/ui/chrome/page-shell.tsx +0 -221
  150. package/src/ui/chrome/scope-badge.tsx +0 -40
  151. package/src/ui/chrome/status-badge.tsx +0 -79
  152. package/src/ui/cn.ts +0 -32
  153. package/src/ui/design-tokens.ts +0 -372
  154. package/src/ui/hooks/use-debounced-value.ts +0 -16
  155. package/src/ui/hooks/use-is-mobile.ts +0 -28
  156. package/src/ui/index.ts +0 -110
  157. package/src/ui/pdf/pdf-preview.tsx +0 -122
  158. package/src/ui/primitives/alert-dialog.tsx +0 -104
  159. package/src/ui/primitives/async-combobox.tsx +0 -182
  160. package/src/ui/primitives/badge-variants.ts +0 -21
  161. package/src/ui/primitives/badge.tsx +0 -25
  162. package/src/ui/primitives/button-variants.ts +0 -31
  163. package/src/ui/primitives/button.tsx +0 -29
  164. package/src/ui/primitives/card.tsx +0 -43
  165. package/src/ui/primitives/checkbox.tsx +0 -26
  166. package/src/ui/primitives/collapsible.tsx +0 -9
  167. package/src/ui/primitives/dialog.tsx +0 -103
  168. package/src/ui/primitives/dropdown-menu.tsx +0 -179
  169. package/src/ui/primitives/form-stepper.tsx +0 -94
  170. package/src/ui/primitives/form-stepper.types.ts +0 -15
  171. package/src/ui/primitives/input.tsx +0 -22
  172. package/src/ui/primitives/label.tsx +0 -17
  173. package/src/ui/primitives/overflow-tabs.tsx +0 -331
  174. package/src/ui/primitives/popover.tsx +0 -33
  175. package/src/ui/primitives/preview-device-frame.tsx +0 -213
  176. package/src/ui/primitives/radio-group.tsx +0 -36
  177. package/src/ui/primitives/resizable.tsx +0 -67
  178. package/src/ui/primitives/scroll-area.tsx +0 -38
  179. package/src/ui/primitives/select.tsx +0 -143
  180. package/src/ui/primitives/separator.tsx +0 -20
  181. package/src/ui/primitives/sheet.tsx +0 -107
  182. package/src/ui/primitives/skeleton.tsx +0 -99
  183. package/src/ui/primitives/switch.tsx +0 -27
  184. package/src/ui/primitives/table.tsx +0 -72
  185. package/src/ui/primitives/tabs.tsx +0 -53
  186. package/src/ui/primitives/tag-multi-select.tsx +0 -261
  187. package/src/ui/primitives/textarea.tsx +0 -21
  188. package/src/ui/primitives/tooltip.tsx +0 -30
  189. package/src/ui/primitives/url-preview-chrome.tsx +0 -103
  190. package/src/vista/GenericCatalogueSurface.tsx +0 -179
  191. package/src/vista/SurfaceFallbackCard.tsx +0 -109
  192. package/src/vista/VistaPanel.tsx +0 -163
  193. package/src/vista/form-payload.spec.ts +0 -139
  194. package/src/vista/html/CustomUiFrame.spec.tsx +0 -127
  195. package/src/vista/html/CustomUiFrame.tsx +0 -206
  196. package/src/vista/html/custom-ui-frame-bridge.spec.ts +0 -191
  197. package/src/vista/html/custom-ui-frame-bridge.ts +0 -98
  198. package/src/vista/html/custom-ui-frame-contract.ts +0 -88
  199. package/src/vista/html/custom-ui-intents.spec.ts +0 -135
  200. package/src/vista/html/custom-ui-intents.ts +0 -155
  201. package/src/vista/html/custom-ui-srcdoc.spec.ts +0 -151
  202. package/src/vista/html/custom-ui-srcdoc.ts +0 -193
  203. package/src/vista/html/index.ts +0 -13
  204. package/src/vista/index.ts +0 -52
  205. package/src/vista/surface-catalogue.spec.ts +0 -140
  206. package/src/vista/surface-catalogue.ts +0 -90
  207. package/src/vista/surface-icons.ts +0 -57
  208. package/src/vista/surface-registry.ts +0 -56
  209. package/src/vista/surfaces/ChartSurface.tsx +0 -34
  210. package/src/vista/surfaces/FilesSurface.tsx +0 -202
  211. package/src/vista/surfaces/FormSurface.tsx +0 -380
  212. package/src/vista/surfaces/HtmlSurface.tsx +0 -43
  213. package/src/vista/surfaces/TableSurface.tsx +0 -100
  214. package/src/vista/surfaces/UrlSurface.tsx +0 -40
  215. package/src/vista/surfaces/blob-surfaces.tsx +0 -139
  216. package/src/vista/surfaces/elicitation-transport.spec.ts +0 -369
  217. package/src/vista/surfaces/elicitation-transport.ts +0 -367
  218. package/src/vista/surfaces/file-surface-utils.ts +0 -69
  219. package/src/vista/surfaces/index.ts +0 -24
  220. package/src/vista/surfaces/register-surfaces.tsx +0 -139
  221. package/src/vista/surfaces/text-surfaces.tsx +0 -132
  222. package/src/vista/use-vista-tabs.ts +0 -196
  223. package/src/vista/vista-code-renderer-context.ts +0 -16
  224. package/src/vista/vista-code-renderer.tsx +0 -35
  225. package/src/vista/vista-file-context.ts +0 -14
  226. package/src/vista/vista-file-source.tsx +0 -141
  227. package/src/vista/vista-form-context.ts +0 -20
  228. package/src/vista/vista-form-host.tsx +0 -48
  229. package/src/vista/vista-model.ts +0 -137
  230. package/src/vista/vista-open-context.tsx +0 -27
  231. package/src/vista/vista-open-state.ts +0 -11
  232. package/src/vista/vista-payloads.ts +0 -635
  233. package/src/vista/vista-tabs-manifest.ts +0 -138
  234. package/src/vista/vista-tools.ts +0 -232
@@ -1,100 +0,0 @@
1
- /**
2
- * `SurfaceKind.Table` — generic columns + rows, the universal "show me
3
- * structured records" surface.
4
- *
5
- * Presentation only: no sorting model, no paging, no cell semantics. A cell
6
- * value that is not a primitive is JSON-serialised rather than dropped, so a
7
- * nested value is visible instead of silently blank.
8
- */
9
- import type { VistaTablePayload } from '../vista-payloads';
10
- import type { ReactElement } from 'react';
11
-
12
- function cellText(value: unknown): string {
13
- if (value === null || value === undefined) {
14
- return '';
15
- }
16
- if (typeof value === 'object') {
17
- try {
18
- return JSON.stringify(value);
19
- } catch {
20
- return String(value);
21
- }
22
- }
23
- return String(value);
24
- }
25
-
26
- export function TableSurface({
27
- columns,
28
- rows,
29
- }: Readonly<VistaTablePayload>): ReactElement {
30
- return (
31
- <div style={{ height: '100%', overflow: 'auto' }}>
32
- <table
33
- style={{
34
- width: '100%',
35
- borderCollapse: 'collapse',
36
- fontSize: 12.5,
37
- }}
38
- >
39
- <thead>
40
- <tr>
41
- {columns.map((column) => (
42
- <th
43
- key={column}
44
- style={{
45
- position: 'sticky',
46
- top: 0,
47
- textAlign: 'left',
48
- padding: '8px 12px',
49
- background: 'hsl(var(--paper-elev))',
50
- borderBottom: '1px solid hsl(var(--rule))',
51
- color: 'hsl(var(--ink-3))',
52
- fontWeight: 600,
53
- whiteSpace: 'nowrap',
54
- }}
55
- >
56
- {column}
57
- </th>
58
- ))}
59
- </tr>
60
- </thead>
61
- <tbody>
62
- {rows.map((row, rowIndex) => (
63
- <tr
64
- // Rows carry no identity in the generic contract; position is the
65
- // only stable key available.
66
-
67
- key={rowIndex}
68
- >
69
- {columns.map((column, columnIndex) => (
70
- <td
71
- key={column}
72
- style={{
73
- padding: '7px 12px',
74
- borderBottom: '1px solid hsl(var(--rule) / 0.6)',
75
- color: 'hsl(var(--ink-2))',
76
- verticalAlign: 'top',
77
- }}
78
- >
79
- {cellText(row[columnIndex])}
80
- </td>
81
- ))}
82
- </tr>
83
- ))}
84
- </tbody>
85
- </table>
86
- {rows.length === 0 && (
87
- <div
88
- style={{
89
- padding: 24,
90
- textAlign: 'center',
91
- fontSize: 12.5,
92
- color: 'hsl(var(--ink-4))',
93
- }}
94
- >
95
- No rows.
96
- </div>
97
- )}
98
- </div>
99
- );
100
- }
@@ -1,40 +0,0 @@
1
- /**
2
- * `SurfaceKind.Url` — a live external URL inside mock browser chrome.
3
- *
4
- * The chrome (traffic lights + address bar + reload) is `UrlPreviewChrome`,
5
- * lifted out of the thin session workspace; the device bezel is the shared
6
- * `PreviewDeviceFrame`. The frame itself is `sandbox="allow-scripts
7
- * allow-forms"` and NEVER `allow-same-origin`: a previewed app runs in its own
8
- * opaque origin and cannot reach the host's DOM, cookies or tokens.
9
- */
10
-
11
- import { PreviewDeviceFrame } from '../../ui/primitives/preview-device-frame';
12
- import { UrlPreviewChrome } from '../../ui/primitives/url-preview-chrome';
13
-
14
- import type { VistaUrlPayload } from '../vista-payloads';
15
- import type { ReactElement } from 'react';
16
-
17
- export function UrlSurface({
18
- url,
19
- device = 'desktop',
20
- reloadNonce,
21
- }: Readonly<VistaUrlPayload>): ReactElement {
22
- return (
23
- <UrlPreviewChrome url={url}>
24
- <PreviewDeviceFrame device={device}>
25
- <iframe
26
- // Remounting on a nonce change is how a reload is requested without
27
- // reaching into the frame (which we cannot do: it is cross-origin).
28
- key={`${url}::${device}::${reloadNonce ?? 0}`}
29
- title={`Preview of ${url}`}
30
- src={url}
31
- // NEVER add allow-same-origin — it would dissolve the origin boundary
32
- // between the previewed app and the host.
33
- sandbox="allow-scripts allow-forms"
34
- loading="lazy"
35
- style={{ height: '100%', width: '100%', border: 0 }}
36
- />
37
- </PreviewDeviceFrame>
38
- </UrlPreviewChrome>
39
- );
40
- }
@@ -1,139 +0,0 @@
1
- /**
2
- * The binary-bodied first-party surfaces: `image`, `media`, `pdf`.
3
- *
4
- * Each accepts an already-resolved `url` OR a workspace `path` resolved through
5
- * the host {@link VistaFileSource}.
6
- *
7
- * SECURITY — `pdf`: the bytes are frequently UNTRUSTED (user uploads,
8
- * agent-produced artifacts). The PDF is painted onto a `<canvas>` by pdf.js
9
- * (the shared `PdfPreview`) — NO iframe, NO script execution — never embedded
10
- * in the browser's own viewer. `PdfPreview` is lazy-imported so pdf.js
11
- * (~1.9 MB) stays out of any bundle that never opens a PDF; that dynamic import
12
- * is the whole point of the `@xemahq/ui-kernel/pdf` subpath.
13
- */
14
- import { Suspense, lazy, type ReactElement, type ReactNode } from 'react';
15
-
16
- import { VistaFileUrl } from '../vista-file-source';
17
-
18
- import type { VistaBlobPayload } from '../vista-payloads';
19
-
20
- const PdfPreview = lazy(() =>
21
- import('../../pdf').then((m) => ({ default: m.PdfPreview })),
22
- );
23
-
24
- /** Render from an inline url, or resolve the path first. */
25
- function BlobBody({
26
- payload,
27
- render,
28
- }: Readonly<{
29
- payload: VistaBlobPayload;
30
- render: (url: string) => ReactNode;
31
- }>): ReactElement {
32
- if (payload.url !== undefined) {
33
- return <>{render(payload.url)}</>;
34
- }
35
- // `validateBlobPayload` guarantees exactly one of url/path.
36
- return <VistaFileUrl path={payload.path as string} render={render} />;
37
- }
38
-
39
- export function ImageSurface(payload: VistaBlobPayload): ReactElement {
40
- return (
41
- <BlobBody
42
- payload={payload}
43
- render={(url) => (
44
- <div
45
- style={{
46
- height: '100%',
47
- display: 'grid',
48
- placeItems: 'center',
49
- padding: 16,
50
- overflow: 'auto',
51
- }}
52
- >
53
- <img
54
- src={url}
55
- alt={payload.alt ?? 'Preview'}
56
- style={{
57
- maxWidth: '100%',
58
- maxHeight: '100%',
59
- objectFit: 'contain',
60
- }}
61
- />
62
- </div>
63
- )}
64
- />
65
- );
66
- }
67
-
68
- export function PdfSurface(payload: VistaBlobPayload): ReactElement {
69
- return (
70
- <BlobBody
71
- payload={payload}
72
- render={(url) => (
73
- <Suspense
74
- fallback={
75
- <div
76
- style={{
77
- height: '100%',
78
- display: 'grid',
79
- placeItems: 'center',
80
- fontSize: 12.5,
81
- color: 'hsl(var(--ink-4))',
82
- }}
83
- >
84
- Loading viewer…
85
- </div>
86
- }
87
- >
88
- <PdfPreview
89
- url={url}
90
- title={payload.alt ?? 'PDF preview'}
91
- className="h-full w-full"
92
- />
93
- </Suspense>
94
- )}
95
- />
96
- );
97
- }
98
-
99
- /**
100
- * `media` — audio or video, chosen by `contentType`. The type is REQUIRED by the
101
- * payload validator for this kind (see the registration): guessing between an
102
- * `<audio>` and a `<video>` element from a URL would be a heuristic that fails
103
- * on extension-less URLs.
104
- */
105
- export function MediaSurface(payload: VistaBlobPayload): ReactElement {
106
- const isAudio = (payload.contentType ?? '').startsWith('audio/');
107
- return (
108
- <BlobBody
109
- payload={payload}
110
- render={(url) => (
111
- <div
112
- style={{
113
- height: '100%',
114
- display: 'grid',
115
- placeItems: 'center',
116
- padding: 16,
117
- background: 'hsl(var(--paper-sunk))',
118
- }}
119
- >
120
- {isAudio ? (
121
- // eslint-disable-next-line jsx-a11y/media-has-caption
122
- <audio
123
- src={url}
124
- controls
125
- style={{ width: '100%', maxWidth: 520 }}
126
- />
127
- ) : (
128
- // eslint-disable-next-line jsx-a11y/media-has-caption
129
- <video
130
- src={url}
131
- controls
132
- style={{ maxWidth: '100%', maxHeight: '100%' }}
133
- />
134
- )}
135
- </div>
136
- )}
137
- />
138
- );
139
- }
@@ -1,369 +0,0 @@
1
- /**
2
- * Guards the secure-elicitation transport — the ONE place a captured field
3
- * value is read out of the `form` surface.
4
- *
5
- * These are the load-bearing proofs of Canopy §8.4: the value goes browser →
6
- * service and the only thing that comes back out is `{ submitted, ref,
7
- * connectionId }`. Runs under the host-web vitest mirror (this package carries
8
- * no vitest dep).
9
- */
10
- import { afterEach, describe, expect, it, vi } from 'vitest';
11
-
12
- import {
13
- extractServiceMessage,
14
- readElicitationStatus,
15
- resolveTrustedElicitationEndpoints,
16
- resolveTrustedElicitationLaunchUrl,
17
- submitElicitationFields,
18
- VistaFormSubmitError,
19
- VistaFormTransportConfigError,
20
- } from './elicitation-transport';
21
-
22
- const SERVICE_ORIGIN = 'https://connector-gateway.example.test';
23
- const API_BASE_URL = `${SERVICE_ORIGIN}/credential-elicitations`;
24
- const SUBMIT_URL = `${SERVICE_ORIGIN}/credential-elicitations/ref-1/submit`;
25
- const STATUS_URL = `${SERVICE_ORIGIN}/credential-elicitations/ref-1`;
26
- const SECRET = 'sk-live-DO-NOT-LEAK';
27
-
28
- function jsonResponse(status: number, body: unknown): Response {
29
- return new Response(JSON.stringify(body), {
30
- status,
31
- headers: { 'content-type': 'application/json' },
32
- });
33
- }
34
-
35
- function stubFetch(response: Response): ReturnType<typeof vi.fn> {
36
- const fetchMock = vi.fn().mockResolvedValue(response);
37
- vi.stubGlobal('fetch', fetchMock);
38
- return fetchMock;
39
- }
40
-
41
- afterEach(() => {
42
- vi.unstubAllGlobals();
43
- vi.restoreAllMocks();
44
- });
45
-
46
- describe('trusted elicitation endpoint resolution', () => {
47
- it('derives exact status and submit paths from the host trust anchor', () => {
48
- expect(resolveTrustedElicitationEndpoints(API_BASE_URL, 'ref-1')).toEqual({
49
- statusUrl: STATUS_URL,
50
- submitUrl: SUBMIT_URL,
51
- });
52
- });
53
-
54
- it.each([
55
- ['relative', '/credential-elicitations'],
56
- ['network-path', '//evil.example/credential-elicitations'],
57
- ['scheme confusion', 'javascript:https://trusted.example'],
58
- [
59
- 'authority confusion',
60
- 'https://trusted.example@evil.example/credential-elicitations',
61
- ],
62
- [
63
- 'query',
64
- 'https://trusted.example/credential-elicitations?next=https://evil.example',
65
- ],
66
- [
67
- 'fragment',
68
- 'https://trusted.example/credential-elicitations#https://evil.example',
69
- ],
70
- [
71
- 'path traversal',
72
- 'https://trusted.example/credential-elicitations/../evil',
73
- ],
74
- [
75
- 'encoded path traversal',
76
- 'https://trusted.example/credential-elicitations/%2e%2e/evil',
77
- ],
78
- ])('rejects %s base URL input', (_label, apiBaseUrl) => {
79
- expect(() =>
80
- resolveTrustedElicitationEndpoints(apiBaseUrl, 'ref-1'),
81
- ).toThrow(VistaFormTransportConfigError);
82
- });
83
-
84
- it('requires HTTPS for a non-local service', () => {
85
- expect(() =>
86
- resolveTrustedElicitationEndpoints(
87
- 'http://api.example.test/credential-elicitations',
88
- 'ref-1',
89
- 'http://host.example.test:8080',
90
- ),
91
- ).toThrow(/Insecure elicitation HTTP/);
92
- });
93
-
94
- it('permits explicit loopback and same-host HTTP development', () => {
95
- expect(
96
- resolveTrustedElicitationEndpoints(
97
- 'http://localhost:3010/credential-elicitations',
98
- 'ref-1',
99
- 'http://localhost:8080',
100
- ).statusUrl,
101
- ).toBe('http://localhost:3010/credential-elicitations/ref-1');
102
- expect(
103
- resolveTrustedElicitationEndpoints(
104
- 'http://192.168.1.20:3010/credential-elicitations',
105
- 'ref-1',
106
- 'http://192.168.1.20:8080',
107
- ).statusUrl,
108
- ).toBe('http://192.168.1.20:3010/credential-elicitations/ref-1');
109
- });
110
-
111
- it.each(['.', '..', '../steal', 'a/b', '%2e%2e', 'réf'])(
112
- 'rejects unsafe ref %s before URL construction',
113
- (ref) => {
114
- expect(() =>
115
- resolveTrustedElicitationEndpoints(API_BASE_URL, ref),
116
- ).toThrow(VistaFormTransportConfigError);
117
- },
118
- );
119
-
120
- it('keeps launch paths on the trusted origin and rejects authority/traversal', () => {
121
- expect(
122
- resolveTrustedElicitationLaunchUrl(
123
- API_BASE_URL,
124
- '/oauth/acme/authorize?flow=1',
125
- ),
126
- ).toBe(`${SERVICE_ORIGIN}/oauth/acme/authorize?flow=1`);
127
-
128
- for (const path of [
129
- 'https://evil.example/steal',
130
- '//evil.example/steal',
131
- '/oauth/../steal',
132
- '/oauth/%2e%2e/steal',
133
- '/oauth\\..\\steal',
134
- '/oauth/start#https://evil.example',
135
- ]) {
136
- expect(() =>
137
- resolveTrustedElicitationLaunchUrl(API_BASE_URL, path),
138
- ).toThrow(VistaFormTransportConfigError);
139
- }
140
- });
141
-
142
- it('does not call fetch when the trusted base or ref is invalid', async () => {
143
- const fetchMock = vi.fn();
144
- vi.stubGlobal('fetch', fetchMock);
145
- await expect(
146
- submitElicitationFields({
147
- apiBaseUrl:
148
- 'https://trusted.example@evil.example/credential-elicitations',
149
- ref: '../steal',
150
- accessToken: 'user-jwt',
151
- fields: { apiKey: SECRET },
152
- }),
153
- ).rejects.toBeInstanceOf(VistaFormTransportConfigError);
154
- expect(fetchMock).not.toHaveBeenCalled();
155
- });
156
- });
157
-
158
- describe('submitElicitationFields', () => {
159
- it('POSTs to the SERVICE origin directly — not a host-relative path', async () => {
160
- const fetchMock = stubFetch(
161
- jsonResponse(201, {
162
- data: { submitted: true, ref: 'ref-1', connectionId: 'conn-9' },
163
- }),
164
- );
165
-
166
- await submitElicitationFields({
167
- apiBaseUrl: API_BASE_URL,
168
- ref: 'ref-1',
169
- accessToken: 'user-jwt',
170
- fields: { apiKey: SECRET },
171
- });
172
-
173
- expect(fetchMock).toHaveBeenCalledTimes(1);
174
- const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit];
175
- expect(url).toBe(SUBMIT_URL);
176
- expect(new URL(url).origin).toBe(SERVICE_ORIGIN);
177
- expect(init.method).toBe('POST');
178
- expect(init.redirect).toBe('error');
179
- // The SUBJECT's own bearer — not a service token, not the agent's.
180
- expect((init.headers as Record<string, string>).Authorization).toBe(
181
- 'Bearer user-jwt',
182
- );
183
- });
184
-
185
- it('never hands a secret back to the caller, even when the service echoes it', async () => {
186
- stubFetch(
187
- jsonResponse(201, {
188
- data: {
189
- submitted: true,
190
- ref: 'ref-1',
191
- connectionId: 'conn-9',
192
- // A hostile / careless service echoing the submission back.
193
- fields: { apiKey: SECRET },
194
- credentials: { apiKey: SECRET },
195
- },
196
- }),
197
- );
198
-
199
- const outcome = await submitElicitationFields({
200
- apiBaseUrl: API_BASE_URL,
201
- ref: 'ref-1',
202
- accessToken: 'user-jwt',
203
- fields: { apiKey: SECRET },
204
- });
205
-
206
- // The outcome is a FRESH object with exactly three keys.
207
- expect(Object.keys(outcome).sort()).toEqual([
208
- 'connectionId',
209
- 'ref',
210
- 'submitted',
211
- ]);
212
- expect(outcome).toEqual({
213
- submitted: true,
214
- ref: 'ref-1',
215
- connectionId: 'conn-9',
216
- });
217
- expect(JSON.stringify(outcome)).not.toContain(SECRET);
218
- expect(JSON.stringify(outcome)).not.toContain('apiKey');
219
- });
220
-
221
- it('round-trips a NON-secret field to the service body', async () => {
222
- const fetchMock = stubFetch(
223
- jsonResponse(201, {
224
- data: { submitted: true, ref: 'ref-1', connectionId: 'conn-9' },
225
- }),
226
- );
227
-
228
- await submitElicitationFields({
229
- apiBaseUrl: API_BASE_URL,
230
- ref: 'ref-1',
231
- accessToken: 'user-jwt',
232
- fields: { baseUrl: 'https://acme.example.com', apiKey: SECRET },
233
- });
234
-
235
- const [, init] = fetchMock.mock.calls[0] as [string, RequestInit];
236
- expect(JSON.parse(init.body as string)).toEqual({
237
- fields: { baseUrl: 'https://acme.example.com', apiKey: SECRET },
238
- });
239
- });
240
-
241
- it('accepts a flat (un-enveloped) response body', async () => {
242
- stubFetch(
243
- jsonResponse(200, {
244
- submitted: true,
245
- ref: 'ref-1',
246
- connectionId: 'conn-2',
247
- }),
248
- );
249
- await expect(
250
- submitElicitationFields({
251
- apiBaseUrl: API_BASE_URL,
252
- ref: 'ref-1',
253
- accessToken: 't',
254
- fields: {},
255
- }),
256
- ).resolves.toEqual({
257
- submitted: true,
258
- ref: 'ref-1',
259
- connectionId: 'conn-2',
260
- });
261
- });
262
-
263
- it("surfaces the backend's empty-schema 400 as a usable message", async () => {
264
- stubFetch(
265
- jsonResponse(400, {
266
- statusCode: 400,
267
- message:
268
- 'No credential form is declared for a connection to "ACME" — there is nothing to validate ' +
269
- 'the submitted values against, so they cannot be stored.',
270
- }),
271
- );
272
-
273
- // An empty field schema submits an empty map; the SERVICE is the authority.
274
- const promise = submitElicitationFields({
275
- apiBaseUrl: API_BASE_URL,
276
- ref: 'ref-1',
277
- accessToken: 'user-jwt',
278
- fields: {},
279
- });
280
-
281
- await expect(promise).rejects.toBeInstanceOf(VistaFormSubmitError);
282
- await expect(promise).rejects.toThrow(/No credential form is declared/);
283
- });
284
-
285
- it('refuses a 2xx that does not report the elicitation as submitted', async () => {
286
- stubFetch(jsonResponse(200, { data: { ref: 'ref-1' } }));
287
- await expect(
288
- submitElicitationFields({
289
- apiBaseUrl: API_BASE_URL,
290
- ref: 'ref-1',
291
- accessToken: 't',
292
- fields: {},
293
- }),
294
- ).rejects.toThrow(/did not report the elicitation as submitted/);
295
- });
296
- });
297
-
298
- describe('readElicitationStatus', () => {
299
- it('returns null while pending — an explicit "not yet", never a guess', async () => {
300
- stubFetch(
301
- jsonResponse(200, {
302
- data: { ref: 'ref-1', status: 'pending', connectionId: null },
303
- }),
304
- );
305
- await expect(
306
- readElicitationStatus({
307
- apiBaseUrl: API_BASE_URL,
308
- ref: 'ref-1',
309
- accessToken: 't',
310
- }),
311
- ).resolves.toBeNull();
312
- });
313
-
314
- it('settles on the service-reported submitted status', async () => {
315
- stubFetch(
316
- jsonResponse(200, {
317
- data: { ref: 'ref-1', status: 'submitted', connectionId: 'conn-3' },
318
- }),
319
- );
320
- await expect(
321
- readElicitationStatus({
322
- apiBaseUrl: API_BASE_URL,
323
- ref: 'ref-1',
324
- accessToken: 't',
325
- }),
326
- ).resolves.toEqual({
327
- submitted: true,
328
- ref: 'ref-1',
329
- connectionId: 'conn-3',
330
- });
331
- });
332
-
333
- it('GETs the service origin with the subject bearer', async () => {
334
- const fetchMock = stubFetch(
335
- jsonResponse(200, { data: { ref: 'ref-1', status: 'pending' } }),
336
- );
337
- await readElicitationStatus({
338
- apiBaseUrl: API_BASE_URL,
339
- ref: 'ref-1',
340
- accessToken: 'user-jwt',
341
- });
342
- const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit];
343
- expect(new URL(url).origin).toBe(SERVICE_ORIGIN);
344
- expect(init.method).toBe('GET');
345
- expect(init.redirect).toBe('error');
346
- expect((init.headers as Record<string, string>).Authorization).toBe(
347
- 'Bearer user-jwt',
348
- );
349
- });
350
- });
351
-
352
- describe('extractServiceMessage', () => {
353
- it('reads a string message, a message array, and a nested error message', () => {
354
- expect(extractServiceMessage({ message: 'nope' }, 400)).toBe('nope');
355
- expect(extractServiceMessage({ message: ['a', 'b'] }, 400)).toBe('a b');
356
- expect(extractServiceMessage({ error: { message: 'deep' } }, 400)).toBe(
357
- 'deep',
358
- );
359
- });
360
-
361
- it('never yields an empty string', () => {
362
- expect(extractServiceMessage(null, 503)).toBe(
363
- 'The service rejected the submission (HTTP 503).',
364
- );
365
- expect(extractServiceMessage({ message: '' }, 500)).toBe(
366
- 'The service rejected the submission (HTTP 500).',
367
- );
368
- });
369
- });