@xemahq/ui-kernel 0.11.1 → 0.12.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 (257) hide show
  1. package/dist/errors/http-error-status.d.ts +17 -0
  2. package/dist/errors/http-error-status.d.ts.map +1 -0
  3. package/dist/errors/http-error-status.js +59 -0
  4. package/dist/errors/http-error-status.js.map +1 -0
  5. package/dist/errors/index.d.ts +2 -0
  6. package/dist/errors/index.d.ts.map +1 -0
  7. package/dist/errors/index.js +2 -0
  8. package/dist/errors/index.js.map +1 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +1 -0
  12. package/dist/index.js.map +1 -1
  13. package/dist/lib/biome-host/errors.d.ts.map +1 -1
  14. package/dist/lib/biome-host/errors.js +1 -19
  15. package/dist/lib/biome-host/errors.js.map +1 -1
  16. package/dist/offline/index.d.ts.map +1 -1
  17. package/dist/offline/index.js.map +1 -1
  18. package/dist/offline/online-controller.d.ts.map +1 -1
  19. package/dist/offline/online-controller.js +6 -1
  20. package/dist/offline/online-controller.js.map +1 -1
  21. package/dist/offline/outbox.d.ts.map +1 -1
  22. package/dist/offline/outbox.js +2 -24
  23. package/dist/offline/outbox.js.map +1 -1
  24. package/package.json +1 -2
  25. package/src/index.ts +0 -17
  26. package/src/lib/biome-host/agent-validation.ts +0 -239
  27. package/src/lib/biome-host/biome-builders.ts +0 -112
  28. package/src/lib/biome-host/biome-mode.ts +0 -6
  29. package/src/lib/biome-host/biome-navigation.ts +0 -37
  30. package/src/lib/biome-host/biome-registry.ts +0 -299
  31. package/src/lib/biome-host/biome-scope-hooks.ts +0 -41
  32. package/src/lib/biome-host/biome-scope.tsx +0 -52
  33. package/src/lib/biome-host/biome-scoped-query.ts +0 -134
  34. package/src/lib/biome-host/create-biome-orval-config.ts +0 -82
  35. package/src/lib/biome-host/define-web-biome.spec.ts +0 -221
  36. package/src/lib/biome-host/define-web-biome.ts +0 -222
  37. package/src/lib/biome-host/errors.ts +0 -220
  38. package/src/lib/biome-host/frontend-biome.ts +0 -256
  39. package/src/lib/biome-host/host-bridge.ts +0 -281
  40. package/src/lib/biome-host/host-sources.ts +0 -54
  41. package/src/lib/biome-host/i18n-hooks.ts +0 -51
  42. package/src/lib/biome-host/i18n-port.test.ts +0 -50
  43. package/src/lib/biome-host/i18n-port.ts +0 -96
  44. package/src/lib/biome-host/index.ts +0 -35
  45. package/src/lib/biome-host/realtime-hooks.ts +0 -75
  46. package/src/lib/biome-host/realtime-port.ts +0 -115
  47. package/src/lib/biome-host/session-contributions.ts +0 -296
  48. package/src/lib/biome-host/use-mutation-with-error-toast.ts +0 -90
  49. package/src/lib/biome-host/use-page-state.ts +0 -248
  50. package/src/lib/capabilities/capability-context.ts +0 -25
  51. package/src/lib/capabilities/capability-provider.tsx +0 -73
  52. package/src/lib/capabilities/index.ts +0 -17
  53. package/src/lib/capabilities/types.ts +0 -69
  54. package/src/lib/capabilities/use-capability.ts +0 -79
  55. package/src/lib/contribution-registry/contribution-registry.spec.ts +0 -141
  56. package/src/lib/contribution-registry/contribution-registry.ts +0 -204
  57. package/src/lib/contribution-registry/index.ts +0 -9
  58. package/src/lib/contribution-registry/renderable-registry.ts +0 -142
  59. package/src/lib/system-bus/capability-invoke.ts +0 -92
  60. package/src/lib/system-bus/deeplink.ts +0 -210
  61. package/src/lib/system-bus/enums.ts +0 -86
  62. package/src/lib/system-bus/host-ports.ts +0 -93
  63. package/src/lib/system-bus/index.ts +0 -16
  64. package/src/lib/system-bus/intent-registry.ts +0 -109
  65. package/src/lib/system-bus/intents.ts +0 -113
  66. package/src/lib/system-bus/palette.ts +0 -78
  67. package/src/lib/system-bus/system-bus-builder.ts +0 -159
  68. package/src/lib/system-bus/system-bus.ts +0 -37
  69. package/src/lib/system-bus/windows.ts +0 -51
  70. package/src/offline/id.ts +0 -16
  71. package/src/offline/index.ts +0 -54
  72. package/src/offline/mutation.ts +0 -75
  73. package/src/offline/offline-status-badge.tsx +0 -51
  74. package/src/offline/online-controller.ts +0 -105
  75. package/src/offline/outbox.test.ts +0 -172
  76. package/src/offline/outbox.ts +0 -348
  77. package/src/offline/react-hooks.ts +0 -40
  78. package/src/offline/react.tsx +0 -32
  79. package/src/offline/storage.ts +0 -112
  80. package/src/offline/types.ts +0 -77
  81. package/src/org-db/components/DbResultTable.tsx +0 -176
  82. package/src/org-db/index.ts +0 -1
  83. package/src/pdf/index.ts +0 -11
  84. package/src/registry/index.ts +0 -9
  85. package/src/registry/lib/agent-validation-host.ts +0 -36
  86. package/src/registry/lib/biome-slot.tsx +0 -50
  87. package/src/registry/lib/biomes-enabled-context.ts +0 -20
  88. package/src/registry/lib/extension-points.ts +0 -134
  89. package/src/registry/lib/primitives/SessionEventCard.tsx +0 -164
  90. package/src/registry/lib/primitives/SessionEventTimeline.tsx +0 -95
  91. package/src/registry/lib/primitives/SessionMutationBar.tsx +0 -76
  92. package/src/registry/lib/primitives/SessionTabbedDrawer.tsx +0 -165
  93. package/src/registry/lib/primitives/index.ts +0 -18
  94. package/src/registry/lib/session-context-builder.ts +0 -84
  95. package/src/registry/lib/session-context-provider.tsx +0 -33
  96. package/src/registry/lib/session-context.ts +0 -21
  97. package/src/registry/lib/session-selectors.ts +0 -272
  98. package/src/session/comments/CommentRail.tsx +0 -164
  99. package/src/session/index.ts +0 -3
  100. package/src/session/lib/cn.ts +0 -11
  101. package/src/session/shell/SessionWorkspaceShell.tsx +0 -147
  102. package/src/session-kit/approvals/ApprovalButton.tsx +0 -89
  103. package/src/session-kit/approvals/ApprovalCard.tsx +0 -341
  104. package/src/session-kit/approvals/ApprovalsCenter.tsx +0 -336
  105. package/src/session-kit/approvals/CapabilityApprovalStickyBar.tsx +0 -118
  106. package/src/session-kit/approvals/Obligation.tsx +0 -111
  107. package/src/session-kit/approvals/ScopedBody.tsx +0 -392
  108. package/src/session-kit/approvals/approval-icons.ts +0 -31
  109. package/src/session-kit/approvals/approval-model.ts +0 -204
  110. package/src/session-kit/approvals/index.ts +0 -22
  111. package/src/session-kit/approvals/obligation-display.ts +0 -100
  112. package/src/session-kit/approvals/risk-accent.ts +0 -47
  113. package/src/session-kit/approvals/scope-icons.ts +0 -19
  114. package/src/session-kit/combobox/Combobox.tsx +0 -358
  115. package/src/session-kit/combobox/use-click-outside.ts +0 -21
  116. package/src/session-kit/display/ContextHeader.tsx +0 -148
  117. package/src/session-kit/display/FileDiffCard.tsx +0 -140
  118. package/src/session-kit/display/MD.tsx +0 -162
  119. package/src/session-kit/display/MessageTurn.tsx +0 -157
  120. package/src/session-kit/display/ThinkingPanel.tsx +0 -81
  121. package/src/session-kit/display/TodoChecklist.tsx +0 -120
  122. package/src/session-kit/display/TokenMeter.tsx +0 -89
  123. package/src/session-kit/display/ToolStrip.tsx +0 -278
  124. package/src/session-kit/display/TypingDots.tsx +0 -24
  125. package/src/session-kit/index.ts +0 -44
  126. package/src/session-kit/lib/enums.ts +0 -66
  127. package/src/session-kit/lib/portal-accent.ts +0 -30
  128. package/src/session-kit/lib/status-dot.ts +0 -68
  129. package/src/session-kit/primitives/Avatar.tsx +0 -44
  130. package/src/session-kit/primitives/PortalGlyph.tsx +0 -51
  131. package/src/session-kit/primitives/RiskPill.tsx +0 -95
  132. package/src/session-kit/primitives/ScopeDot.tsx +0 -47
  133. package/src/session-kit/primitives/Segmented.tsx +0 -71
  134. package/src/ui/branding/app-branding-context.ts +0 -20
  135. package/src/ui/branding/app-branding-provider.tsx +0 -123
  136. package/src/ui/branding/sanitize.ts +0 -89
  137. package/src/ui/breakpoints.ts +0 -14
  138. package/src/ui/capture/document-preview.tsx +0 -166
  139. package/src/ui/capture/field-spec-to-zod.test.ts +0 -81
  140. package/src/ui/capture/field-spec-to-zod.ts +0 -174
  141. package/src/ui/capture/field-spec-validate.ts +0 -236
  142. package/src/ui/capture/field-spec.test.ts +0 -49
  143. package/src/ui/capture/field-spec.ts +0 -274
  144. package/src/ui/capture/index.ts +0 -51
  145. package/src/ui/capture/schema-field-input.tsx +0 -620
  146. package/src/ui/capture/schema-form.tsx +0 -149
  147. package/src/ui/capture/submit-values.test.ts +0 -70
  148. package/src/ui/capture/submit-values.ts +0 -63
  149. package/src/ui/capture/use-prefill.ts +0 -186
  150. package/src/ui/capture/use-schema-validation.ts +0 -145
  151. package/src/ui/capture/use-wizard.ts +0 -180
  152. package/src/ui/capture/value-format.ts +0 -32
  153. package/src/ui/capture/wizard.tsx +0 -105
  154. package/src/ui/charts/bar-chart.tsx +0 -139
  155. package/src/ui/charts/chart-frame.tsx +0 -125
  156. package/src/ui/charts/chart-types.ts +0 -52
  157. package/src/ui/charts/chart-utils.ts +0 -190
  158. package/src/ui/charts/charts.test.tsx +0 -204
  159. package/src/ui/charts/donut-chart.tsx +0 -129
  160. package/src/ui/charts/index.ts +0 -27
  161. package/src/ui/charts/line-chart.tsx +0 -202
  162. package/src/ui/charts/sparkline.tsx +0 -109
  163. package/src/ui/chrome/AsyncBoundary.tsx +0 -74
  164. package/src/ui/chrome/EmptyState.tsx +0 -257
  165. package/src/ui/chrome/ErrorCard.tsx +0 -63
  166. package/src/ui/chrome/LoadingState.tsx +0 -61
  167. package/src/ui/chrome/PageHeader.tsx +0 -137
  168. package/src/ui/chrome/RecordCardList.tsx +0 -98
  169. package/src/ui/chrome/StateCard.tsx +0 -150
  170. package/src/ui/chrome/confirm-delete-dialog.tsx +0 -59
  171. package/src/ui/chrome/page-shell.spec.tsx +0 -117
  172. package/src/ui/chrome/page-shell.tsx +0 -221
  173. package/src/ui/chrome/scope-badge.tsx +0 -40
  174. package/src/ui/chrome/status-badge.tsx +0 -79
  175. package/src/ui/cn.ts +0 -32
  176. package/src/ui/design-tokens.ts +0 -372
  177. package/src/ui/hooks/use-debounced-value.ts +0 -16
  178. package/src/ui/hooks/use-is-mobile.ts +0 -28
  179. package/src/ui/index.ts +0 -110
  180. package/src/ui/pdf/pdf-preview.tsx +0 -122
  181. package/src/ui/primitives/alert-dialog.tsx +0 -104
  182. package/src/ui/primitives/async-combobox.tsx +0 -182
  183. package/src/ui/primitives/badge-variants.ts +0 -21
  184. package/src/ui/primitives/badge.tsx +0 -25
  185. package/src/ui/primitives/button-variants.ts +0 -31
  186. package/src/ui/primitives/button.tsx +0 -29
  187. package/src/ui/primitives/card.tsx +0 -43
  188. package/src/ui/primitives/checkbox.tsx +0 -26
  189. package/src/ui/primitives/collapsible.tsx +0 -9
  190. package/src/ui/primitives/dialog.tsx +0 -103
  191. package/src/ui/primitives/dropdown-menu.tsx +0 -179
  192. package/src/ui/primitives/form-stepper.tsx +0 -94
  193. package/src/ui/primitives/form-stepper.types.ts +0 -15
  194. package/src/ui/primitives/input.tsx +0 -22
  195. package/src/ui/primitives/label.tsx +0 -17
  196. package/src/ui/primitives/overflow-tabs.tsx +0 -331
  197. package/src/ui/primitives/popover.tsx +0 -33
  198. package/src/ui/primitives/preview-device-frame.tsx +0 -213
  199. package/src/ui/primitives/radio-group.tsx +0 -36
  200. package/src/ui/primitives/resizable.tsx +0 -67
  201. package/src/ui/primitives/scroll-area.tsx +0 -38
  202. package/src/ui/primitives/select.tsx +0 -143
  203. package/src/ui/primitives/separator.tsx +0 -20
  204. package/src/ui/primitives/sheet.tsx +0 -107
  205. package/src/ui/primitives/skeleton.tsx +0 -99
  206. package/src/ui/primitives/switch.tsx +0 -27
  207. package/src/ui/primitives/table.tsx +0 -72
  208. package/src/ui/primitives/tabs.tsx +0 -53
  209. package/src/ui/primitives/tag-multi-select.tsx +0 -261
  210. package/src/ui/primitives/textarea.tsx +0 -21
  211. package/src/ui/primitives/tooltip.tsx +0 -30
  212. package/src/ui/primitives/url-preview-chrome.tsx +0 -103
  213. package/src/vista/GenericCatalogueSurface.tsx +0 -179
  214. package/src/vista/SurfaceFallbackCard.tsx +0 -109
  215. package/src/vista/VistaPanel.tsx +0 -163
  216. package/src/vista/form-payload.spec.ts +0 -139
  217. package/src/vista/html/CustomUiFrame.spec.tsx +0 -127
  218. package/src/vista/html/CustomUiFrame.tsx +0 -206
  219. package/src/vista/html/custom-ui-frame-bridge.spec.ts +0 -191
  220. package/src/vista/html/custom-ui-frame-bridge.ts +0 -98
  221. package/src/vista/html/custom-ui-frame-contract.ts +0 -88
  222. package/src/vista/html/custom-ui-intents.spec.ts +0 -135
  223. package/src/vista/html/custom-ui-intents.ts +0 -155
  224. package/src/vista/html/custom-ui-srcdoc.spec.ts +0 -151
  225. package/src/vista/html/custom-ui-srcdoc.ts +0 -193
  226. package/src/vista/html/index.ts +0 -13
  227. package/src/vista/index.ts +0 -52
  228. package/src/vista/surface-catalogue.spec.ts +0 -140
  229. package/src/vista/surface-catalogue.ts +0 -90
  230. package/src/vista/surface-icons.ts +0 -57
  231. package/src/vista/surface-registry.ts +0 -56
  232. package/src/vista/surfaces/ChartSurface.tsx +0 -34
  233. package/src/vista/surfaces/FilesSurface.tsx +0 -202
  234. package/src/vista/surfaces/FormSurface.tsx +0 -380
  235. package/src/vista/surfaces/HtmlSurface.tsx +0 -43
  236. package/src/vista/surfaces/TableSurface.tsx +0 -100
  237. package/src/vista/surfaces/UrlSurface.tsx +0 -40
  238. package/src/vista/surfaces/blob-surfaces.tsx +0 -139
  239. package/src/vista/surfaces/elicitation-transport.spec.ts +0 -369
  240. package/src/vista/surfaces/elicitation-transport.ts +0 -367
  241. package/src/vista/surfaces/file-surface-utils.ts +0 -69
  242. package/src/vista/surfaces/index.ts +0 -24
  243. package/src/vista/surfaces/register-surfaces.tsx +0 -139
  244. package/src/vista/surfaces/text-surfaces.tsx +0 -132
  245. package/src/vista/use-vista-tabs.ts +0 -196
  246. package/src/vista/vista-code-renderer-context.ts +0 -16
  247. package/src/vista/vista-code-renderer.tsx +0 -35
  248. package/src/vista/vista-file-context.ts +0 -14
  249. package/src/vista/vista-file-source.tsx +0 -141
  250. package/src/vista/vista-form-context.ts +0 -20
  251. package/src/vista/vista-form-host.tsx +0 -48
  252. package/src/vista/vista-model.ts +0 -137
  253. package/src/vista/vista-open-context.tsx +0 -27
  254. package/src/vista/vista-open-state.ts +0 -11
  255. package/src/vista/vista-payloads.ts +0 -635
  256. package/src/vista/vista-tabs-manifest.ts +0 -138
  257. package/src/vista/vista-tools.ts +0 -232
@@ -1,202 +0,0 @@
1
- /**
2
- * `SurfaceKind.Files` — the grouped file browser, and the pinned first tab of
3
- * every file-backed Vista panel.
4
- *
5
- * Moved out of the thin session workspace (`WorkspaceFileBrowser` +
6
- * `workspace-model`'s grouping/extension helpers) so the Design-System-Builder
7
- * file tab, the session workspace, and any agent-opened `files` surface draw the
8
- * SAME browser. Grouped by folder with a caption header; each row is a
9
- * colour-coded extension tile + filename + change badges. Clicking a row opens
10
- * the file as its own tab through {@link useVistaOpen}.
11
- */
12
- import { ChevronRight, Folder } from 'lucide-react';
13
-
14
-
15
- import { fileSurface } from '../vista-model';
16
- import { useVistaOpen } from '../vista-open-state';
17
- import { fileExtMeta, groupFilesByFolder } from './file-surface-utils';
18
-
19
- import type { VistaFileEntry, VistaFilesPayload } from '../vista-payloads';
20
- import type { ReactElement } from 'react';
21
-
22
- export function FilesSurface({
23
- files,
24
- }: Readonly<VistaFilesPayload>): ReactElement {
25
- const open = useVistaOpen();
26
- const groups = groupFilesByFolder(files);
27
- if (groups.length === 0) {
28
- return (
29
- <div
30
- style={{
31
- height: '100%',
32
- display: 'grid',
33
- placeItems: 'center',
34
- fontSize: 12.5,
35
- color: 'hsl(var(--ink-4))',
36
- }}
37
- >
38
- No files in the workspace yet.
39
- </div>
40
- );
41
- }
42
- return (
43
- <div style={{ height: '100%', overflowY: 'auto', padding: '14px 12px' }}>
44
- {groups.map((group) => (
45
- <section key={group.dir || 'root'} style={{ marginBottom: 16 }}>
46
- <div
47
- style={{
48
- display: 'flex',
49
- alignItems: 'center',
50
- gap: 6,
51
- padding: '0 8px 8px',
52
- }}
53
- >
54
- <Folder size={12} style={{ color: 'hsl(var(--ink-4))' }} />
55
- <span
56
- className="cap"
57
- style={{ fontSize: 9.5, letterSpacing: '0.07em' }}
58
- >
59
- {group.dir ? group.dir.replaceAll('/', ' / ') : 'Root'}
60
- </span>
61
- </div>
62
- <div style={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
63
- {group.files.map((file) => (
64
- <FileRow
65
- key={file.path}
66
- file={file}
67
- onOpen={
68
- open === null
69
- ? null
70
- : () => {
71
- open(fileSurface(file.path));
72
- }
73
- }
74
- />
75
- ))}
76
- </div>
77
- </section>
78
- ))}
79
- </div>
80
- );
81
- }
82
-
83
- function FileRow({
84
- file,
85
- onOpen,
86
- }: Readonly<{
87
- file: VistaFileEntry;
88
- onOpen: (() => void) | null;
89
- }>): ReactElement {
90
- const name = file.path.split('/').pop() ?? file.path;
91
- const meta = fileExtMeta(name);
92
- const changed = file.add !== undefined || file.del !== undefined;
93
- const body = (
94
- <>
95
- <span
96
- style={{
97
- width: 28,
98
- height: 28,
99
- borderRadius: 8,
100
- flexShrink: 0,
101
- display: 'grid',
102
- placeItems: 'center',
103
- background: `color-mix(in oklch, ${meta.color} 13%, transparent)`,
104
- border: `1px solid color-mix(in oklch, ${meta.color} 26%, transparent)`,
105
- }}
106
- >
107
- <span
108
- className="mono"
109
- style={{
110
- fontSize: 8,
111
- fontWeight: 700,
112
- color: meta.color,
113
- letterSpacing: '0.02em',
114
- }}
115
- >
116
- {meta.tag}
117
- </span>
118
- </span>
119
- <span style={{ flex: 1, minWidth: 0 }}>
120
- <span
121
- style={{
122
- display: 'block',
123
- fontSize: 13,
124
- fontWeight: 500,
125
- color: 'hsl(var(--ink))',
126
- overflow: 'hidden',
127
- textOverflow: 'ellipsis',
128
- whiteSpace: 'nowrap',
129
- }}
130
- >
131
- {name}
132
- </span>
133
- {changed && (
134
- <span
135
- className="mono"
136
- style={{ fontSize: 10, color: 'hsl(var(--ink-4))' }}
137
- >
138
- changed
139
- </span>
140
- )}
141
- </span>
142
- {changed && (
143
- <span style={{ display: 'inline-flex', gap: 6, flexShrink: 0 }}>
144
- {file.add !== undefined && file.add > 0 && (
145
- <span
146
- className="mono"
147
- style={{ fontSize: 10.5, color: 'hsl(var(--success))' }}
148
- >
149
- +{file.add}
150
- </span>
151
- )}
152
- {file.del !== undefined && file.del > 0 && (
153
- <span
154
- className="mono"
155
- style={{
156
- fontSize: 10.5,
157
- color: 'hsl(var(--destructive, var(--danger)))',
158
- }}
159
- >
160
- −{file.del}
161
- </span>
162
- )}
163
- </span>
164
- )}
165
- {onOpen !== null && (
166
- <ChevronRight
167
- size={13}
168
- style={{ color: 'hsl(var(--ink-4))', flexShrink: 0, opacity: 0.6 }}
169
- />
170
- )}
171
- </>
172
- );
173
-
174
- const rowStyle = {
175
- display: 'flex',
176
- alignItems: 'center',
177
- gap: 11,
178
- width: '100%',
179
- padding: '8px 9px',
180
- borderRadius: 9,
181
- textAlign: 'left',
182
- } as const;
183
-
184
- if (onOpen === null) {
185
- return <div style={rowStyle}>{body}</div>;
186
- }
187
- return (
188
- <button
189
- type="button"
190
- onClick={onOpen}
191
- style={{ ...rowStyle, transition: 'background 140ms ease' }}
192
- onMouseEnter={(e) => {
193
- e.currentTarget.style.background = 'hsl(var(--paper-elev))';
194
- }}
195
- onMouseLeave={(e) => {
196
- e.currentTarget.style.background = 'transparent';
197
- }}
198
- >
199
- {body}
200
- </button>
201
- );
202
- }
@@ -1,380 +0,0 @@
1
- /**
2
- * `SurfaceKind.Form` — the secure-elicitation surface (Canopy §8.4).
3
- *
4
- * The agent asks for a credential it must never see. This surface renders the
5
- * connector's ONBOARDING form (or, for `oauth2` / `app_install`, the consent
6
- * link), captures the values in local state, and POSTs them BROWSER → OWNING
7
- * SERVICE with the SUBJECT's own JWT. The agent learns only
8
- * `{ submitted, ref }`.
9
- *
10
- * ── What makes the value unreachable from the agent ─────────────────────────
11
- * • the only outbound channel is `host.onOutcome(VistaFormOutcome)`, whose
12
- * type has three scalar members and no place a value could be assigned;
13
- * • the values live in this component's `useState`; the single reader is
14
- * `submitElicitationFields`, which takes them as a parameter and returns an
15
- * outcome — the values are not reachable from any return or any throw;
16
- * • the payload has NO URL authority. The exact endpoints are derived from
17
- * the trusted elicitation API base URL supplied by `VistaFormHost`;
18
- * • secret fields are DECLARED (`spec.isSecret`) and render write-only; the
19
- * surface holds no cache and no read path repopulates them.
20
- *
21
- * Nothing here is provider-aware. Whether the flow is a field form or an OAuth
22
- * handoff is decided by the payload the owning service produced.
23
- */
24
- import {
25
- AlertTriangle,
26
- CheckCircle2,
27
- ExternalLink,
28
- Loader2,
29
- ShieldCheck,
30
- } from 'lucide-react';
31
- import {
32
- useCallback,
33
- useEffect,
34
- useState,
35
- type ReactElement,
36
- type ReactNode,
37
- } from 'react';
38
-
39
- import {
40
- readElicitationStatus,
41
- resolveTrustedElicitationEndpoints,
42
- resolveTrustedElicitationLaunchUrl,
43
- submitElicitationFields,
44
- VistaFormSubmitError,
45
- } from './elicitation-transport';
46
- import { SchemaForm } from '../../ui/capture/schema-form';
47
- import { captureValuesToStringMap } from '../../ui/capture/submit-values';
48
- import { useSchemaValidation } from '../../ui/capture/use-schema-validation';
49
- import { cn } from '../../ui/cn';
50
- import { Button } from '../../ui/primitives/button';
51
- import { useVistaFormHost, type VistaFormOutcome } from '../vista-form-context';
52
-
53
- import type { CaptureValues } from '../../ui/capture/field-spec';
54
- import type { VistaFormPayload } from '../vista-payloads';
55
-
56
- /** Explicit lifecycle. No implicit "maybe submitted" state. */
57
- enum FormPhase {
58
- Editing = 'editing',
59
- Working = 'working',
60
- Settled = 'settled',
61
- }
62
-
63
- export function FormSurface(payload: Readonly<VistaFormPayload>): ReactElement {
64
- const host = useVistaFormHost();
65
- const [values, setValues] = useState<CaptureValues>({});
66
- const [phase, setPhase] = useState<FormPhase>(FormPhase.Editing);
67
- const [serviceError, setServiceError] = useState<string | null>(null);
68
- const [showFieldErrors, setShowFieldErrors] = useState(false);
69
- const [outcome, setOutcome] = useState<VistaFormOutcome | null>(null);
70
- const { errors, isValid } = useSchemaValidation(payload.fields, values);
71
- let transportConfigurationError: string | null = null;
72
- let launchUrl: string | undefined;
73
- if (host !== null) {
74
- try {
75
- // Validate the trust anchor before retrieving a bearer token or accepting
76
- // a submit action. The transport repeats this check at the fetch boundary.
77
- resolveTrustedElicitationEndpoints(
78
- host.elicitationApiBaseUrl,
79
- payload.ref,
80
- );
81
- if (payload.launch !== undefined) {
82
- launchUrl = resolveTrustedElicitationLaunchUrl(
83
- host.elicitationApiBaseUrl,
84
- payload.launch.path,
85
- );
86
- }
87
- } catch (error) {
88
- transportConfigurationError =
89
- error instanceof Error
90
- ? error.message
91
- : 'The trusted elicitation service is not configured safely.';
92
- }
93
- }
94
-
95
- const settle = useCallback(
96
- (next: VistaFormOutcome): void => {
97
- // The values are dropped the moment the elicitation settles: nothing in
98
- // this component may outlive the submission holding secret material.
99
- setValues({});
100
- setOutcome(next);
101
- setPhase(FormPhase.Settled);
102
- host?.onOutcome(next);
103
- },
104
- [host],
105
- );
106
-
107
- const failed = useCallback((error: unknown): void => {
108
- setServiceError(
109
- error instanceof VistaFormSubmitError || error instanceof Error
110
- ? error.message
111
- : 'The submission could not be completed.',
112
- );
113
- setPhase(FormPhase.Editing);
114
- }, []);
115
-
116
- const handleSubmit = useCallback((): void => {
117
- if (host === null) {
118
- return;
119
- }
120
- setShowFieldErrors(true);
121
- if (!isValid) {
122
- return;
123
- }
124
- setServiceError(null);
125
- setPhase(FormPhase.Working);
126
- // The values object is a PARAMETER here and nowhere else. It is never
127
- // returned, logged, or handed to a callback.
128
- void host
129
- .getAccessToken()
130
- .then((accessToken) =>
131
- submitElicitationFields({
132
- apiBaseUrl: host.elicitationApiBaseUrl,
133
- ref: payload.ref,
134
- accessToken,
135
- fields: captureValuesToStringMap(payload.fields, values),
136
- }),
137
- )
138
- .then(settle, failed);
139
- }, [host, isValid, payload.fields, payload.ref, settle, failed, values]);
140
-
141
- const handleCheckStatus = useCallback((): void => {
142
- if (host === null) {
143
- return;
144
- }
145
- setServiceError(null);
146
- setPhase(FormPhase.Working);
147
- void host
148
- .getAccessToken()
149
- .then((accessToken) =>
150
- readElicitationStatus({
151
- apiBaseUrl: host.elicitationApiBaseUrl,
152
- ref: payload.ref,
153
- accessToken,
154
- }),
155
- )
156
- .then((next) => {
157
- if (next === null) {
158
- setServiceError(
159
- 'Not completed yet — finish the steps in the other window, then check again.',
160
- );
161
- setPhase(FormPhase.Editing);
162
- return;
163
- }
164
- settle(next);
165
- }, failed);
166
- }, [host, payload.ref, settle, failed]);
167
-
168
- // The consent/install window is a separate browsing context, so the only
169
- // signal this tab gets is the user returning to it. Re-checking on focus is
170
- // an event, not a timer — there is no polling loop and no timeout.
171
- const isLaunch = payload.launch !== undefined;
172
- useEffect(() => {
173
- if (!isLaunch || phase === FormPhase.Settled || host === null) {
174
- return;
175
- }
176
- const onFocus = (): void => handleCheckStatus();
177
- const addEventListener: unknown = Reflect.get(globalThis, 'addEventListener');
178
- if (typeof addEventListener !== 'function') {
179
- return;
180
- }
181
- Reflect.apply(addEventListener, globalThis, ['focus', onFocus]);
182
- return () => {
183
- const removeEventListener: unknown = Reflect.get(
184
- globalThis,
185
- 'removeEventListener',
186
- );
187
- if (typeof removeEventListener === 'function') {
188
- Reflect.apply(removeEventListener, globalThis, ['focus', onFocus]);
189
- }
190
- };
191
- // `handleCheckStatus` is stable per (host, payload) and re-subscribing on a
192
- // phase change is intended: a settled surface stops listening.
193
- }, [isLaunch, phase, host, handleCheckStatus]);
194
-
195
- if (host === null) {
196
- return (
197
- <Shell heading={payload.heading} purpose={payload.purpose}>
198
- <Notice tone="error" title="This form cannot be submitted here">
199
- No form host is mounted for this panel, so there is no way to sign the
200
- request as you. Open the request from a surface that provides one.
201
- </Notice>
202
- </Shell>
203
- );
204
- }
205
-
206
- if (transportConfigurationError !== null) {
207
- return (
208
- <Shell heading={payload.heading} purpose={payload.purpose}>
209
- <Notice
210
- tone="error"
211
- title="The secure service is not configured safely"
212
- >
213
- {transportConfigurationError}
214
- </Notice>
215
- </Shell>
216
- );
217
- }
218
-
219
- if (phase === FormPhase.Settled && outcome !== null) {
220
- return (
221
- <Shell heading={payload.heading} purpose={payload.purpose}>
222
- <div className="flex items-start gap-2 rounded-md border border-rule bg-paper-elev p-3">
223
- <CheckCircle2 className="mt-0.5 h-4 w-4 shrink-0 text-primary" />
224
- <div className="space-y-0.5">
225
- <p className="text-body-1 font-medium text-ink">Submitted.</p>
226
- <p className="text-caption text-ink-3">
227
- The value went straight to the service and was never shown to the
228
- agent
229
- {outcome.connectionId === null
230
- ? '.'
231
- : `. Connection ${outcome.connectionId} is ready.`}
232
- </p>
233
- </div>
234
- </div>
235
- </Shell>
236
- );
237
- }
238
-
239
- const working = phase === FormPhase.Working;
240
-
241
- return (
242
- <Shell heading={payload.heading} purpose={payload.purpose}>
243
- {payload.launch !== undefined ? (
244
- <>
245
- {payload.launch.hint !== undefined && (
246
- <p className="text-body-1 text-ink-3">{payload.launch.hint}</p>
247
- )}
248
- <div className="flex flex-wrap items-center gap-2">
249
- <Button
250
- onClick={() => {
251
- // `launchUrl` was derived from the host trust anchor above; the
252
- // payload contributes only a validated same-origin path.
253
- globalThis.open(launchUrl, '_blank', 'noopener,noreferrer');
254
- }}
255
- className="gap-1.5"
256
- disabled={working}
257
- >
258
- <ExternalLink className="h-4 w-4" />
259
- {payload.launch.label}
260
- </Button>
261
- <Button
262
- variant="outline"
263
- onClick={handleCheckStatus}
264
- disabled={working}
265
- >
266
- {working && <Loader2 className="mr-1 h-4 w-4 animate-spin" />}
267
- I&apos;ve finished — check
268
- </Button>
269
- </div>
270
- </>
271
- ) : (
272
- <>
273
- {payload.fields.length === 0 && (
274
- <Notice tone="warn" title="No form fields were declared">
275
- This connector declares no onboarding form. Submitting will ask
276
- the service, which is the authority on whether that is allowed.
277
- </Notice>
278
- )}
279
- <SchemaForm
280
- fields={payload.fields}
281
- values={values}
282
- onChange={setValues}
283
- disabled={working}
284
- {...(showFieldErrors ? { errors } : {})}
285
- />
286
- <div className="flex items-center gap-2">
287
- <Button onClick={handleSubmit} disabled={working}>
288
- {working && <Loader2 className="mr-1 h-4 w-4 animate-spin" />}
289
- {payload.submitLabel ?? 'Submit securely'}
290
- </Button>
291
- </div>
292
- </>
293
- )}
294
-
295
- {serviceError !== null && (
296
- <Notice tone="error" title="The service rejected this">
297
- {serviceError}
298
- </Notice>
299
- )}
300
- </Shell>
301
- );
302
- }
303
-
304
- function Shell({
305
- heading,
306
- purpose,
307
- children,
308
- }: Readonly<{
309
- heading?: string;
310
- purpose: string;
311
- children: ReactNode;
312
- }>): ReactElement {
313
- return (
314
- <div className="h-full overflow-auto">
315
- <div className="mx-auto max-w-2xl space-y-4 p-6">
316
- <div className="space-y-1">
317
- <h2 className="text-subtitle font-semibold text-ink">
318
- {heading ?? 'Secure request'}
319
- </h2>
320
- {purpose.length > 0 && (
321
- <p className="text-body-1 text-ink-2">{purpose}</p>
322
- )}
323
- <p className="flex items-center gap-1.5 text-caption text-ink-3">
324
- <ShieldCheck className="h-3.5 w-3.5" />
325
- Sent straight to the service with your own sign-in. The agent never
326
- sees what you type.
327
- </p>
328
- </div>
329
- {children}
330
- </div>
331
- </div>
332
- );
333
- }
334
-
335
- function Notice({
336
- tone,
337
- title,
338
- children,
339
- }: Readonly<{
340
- tone: 'error' | 'warn';
341
- title: string;
342
- children: ReactNode;
343
- }>): ReactElement {
344
- return (
345
- <div
346
- role="alert"
347
- className={cn(
348
- 'flex items-start gap-2 rounded-md border p-3',
349
- tone === 'error'
350
- ? 'border-destructive/40 bg-destructive/10'
351
- : 'border-rule bg-paper-elev',
352
- )}
353
- >
354
- <AlertTriangle
355
- className={cn(
356
- 'mt-0.5 h-4 w-4 shrink-0',
357
- tone === 'error' ? 'text-destructive' : 'text-ink-3',
358
- )}
359
- />
360
- <div className="space-y-0.5">
361
- <p
362
- className={cn(
363
- 'text-body-1 font-medium',
364
- tone === 'error' ? 'text-destructive' : 'text-ink',
365
- )}
366
- >
367
- {title}
368
- </p>
369
- <p
370
- className={cn(
371
- 'text-body-1',
372
- tone === 'error' ? 'text-destructive/90' : 'text-ink-3',
373
- )}
374
- >
375
- {children}
376
- </p>
377
- </div>
378
- </div>
379
- );
380
- }
@@ -1,43 +0,0 @@
1
- /**
2
- * `SurfaceKind.Html` — the "render anything, safely" surface.
3
- *
4
- * It draws through the promoted {@link CustomUiFrame}: an opaque-origin,
5
- * `allow-scripts`-only sandbox iframe with a `<meta>` CSP of
6
- * `default-src 'none'; script-src <pinned>; style-src 'unsafe-inline';
7
- * base-uri 'none'; form-action 'none'`.
8
- *
9
- * Two forms, one frame:
10
- * • `{ document }` — untrusted, agent-authored HTML. `script-src 'none'`, and
11
- * the frame is mounted with {@link NO_CUSTOM_UI_INTENTS}: it can render, and
12
- * it can do NOTHING else. This is what an agent's `html` tab uses.
13
- * • `{ compiledOutput, integrity }` — a server-compiled, SRI-pinned chunk.
14
- * `script-src '<sha384-…>'` executes exactly those bytes and nothing else.
15
- *
16
- * A surface that wants intents (App Forge's runtime views) mounts
17
- * `CustomUiFrame` directly with its own closed set; the generic `html` TAB
18
- * deliberately grants none — an agent-authored document must not be able to
19
- * drive the host.
20
- */
21
-
22
- import { NO_CUSTOM_UI_INTENTS } from '../html/custom-ui-intents';
23
- import { CustomUiFrame } from '../html/CustomUiFrame';
24
-
25
- import type { VistaHtmlPayload } from '../vista-payloads';
26
- import type { ReactElement } from 'react';
27
-
28
- export function HtmlSurface(payload: VistaHtmlPayload): ReactElement {
29
- const content =
30
- 'document' in payload
31
- ? { document: payload.document }
32
- : { compiledOutput: payload.compiledOutput, integrity: payload.integrity };
33
- const styleCss = 'document' in payload ? undefined : payload.styleCss;
34
- return (
35
- <CustomUiFrame
36
- content={content}
37
- intents={NO_CUSTOM_UI_INTENTS}
38
- title="Rendered view"
39
- className="h-full p-2"
40
- {...(styleCss === undefined ? {} : { styleCss })}
41
- />
42
- );
43
- }