@steerable/agent-ui 0.12.7 → 0.13.1

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.
@@ -0,0 +1,133 @@
1
+ /**
2
+ * `<UiSurfaceCard />`
3
+ *
4
+ * Compact in-stream summary card for a declarative `UiSurfacePayload` (wireframe W1).
5
+ * Summarizes steps, row counts, and bound `$source` keys without flooding the chat
6
+ * stream, and opens or focuses `<UiSurfaceWorkbench />` while sharing live draft state.
7
+ */
8
+ import * as React from 'react';
9
+ import type { UiSurfacePayload } from '@steerable/agent-protocol';
10
+ import {
11
+ getUiSurfaceDraft,
12
+ subscribeUiSurfaceDraft,
13
+ } from './ui-surface-draft.js';
14
+
15
+ export interface UiSurfaceCardProps {
16
+ payload: UiSurfacePayload;
17
+ chatId?: string;
18
+ onOpenWorkbench?: (surface: UiSurfacePayload) => void;
19
+ className?: string;
20
+ openWorkbenchLabel?: React.ReactNode;
21
+ }
22
+
23
+ export const UiSurfaceCard: React.FC<UiSurfaceCardProps> = ({
24
+ payload,
25
+ chatId,
26
+ onOpenWorkbench,
27
+ className = '',
28
+ openWorkbenchLabel = 'Open in workbench →',
29
+ }) => {
30
+ const [, forceRender] = React.useReducer((n: number) => n + 1, 0);
31
+ React.useEffect(
32
+ () => subscribeUiSurfaceDraft(chatId, payload.surfaceId, forceRender),
33
+ [chatId, payload.surfaceId],
34
+ );
35
+ const draft = getUiSurfaceDraft(chatId, payload.surfaceId);
36
+
37
+ const stepComponent = payload.components.find((c) => c.kind === 'steps');
38
+ const tableComponent = payload.components.find((c) => c.kind === 'table');
39
+ const resolvedRows = React.useMemo(() => {
40
+ if (!tableComponent) return [];
41
+ if (
42
+ tableComponent.dataKey &&
43
+ payload.resolvedData &&
44
+ Array.isArray(payload.resolvedData[tableComponent.dataKey])
45
+ ) {
46
+ return payload.resolvedData[tableComponent.dataKey] as Record<string, unknown>[];
47
+ }
48
+ return Array.isArray(tableComponent.rows) ? tableComponent.rows : [];
49
+ }, [tableComponent, payload.resolvedData]);
50
+
51
+ const sourceNames = React.useMemo(() => {
52
+ const out: string[] = [];
53
+ if (payload.data && typeof payload.data === 'object') {
54
+ for (const val of Object.values(payload.data)) {
55
+ if (val && typeof val === 'object' && typeof (val as { $source?: unknown }).$source === 'string') {
56
+ out.push((val as { $source: string }).$source);
57
+ }
58
+ }
59
+ }
60
+ return out;
61
+ }, [payload.data]);
62
+
63
+ return (
64
+ <div
65
+ data-testid="ui-surface-card"
66
+ data-surface-id={payload.surfaceId}
67
+ className={`rounded-xl border border-slate-200 bg-slate-50/70 p-3.5 text-xs dark:border-slate-800 dark:bg-slate-900/50 ${className}`.trim()}
68
+ >
69
+ <div className="flex flex-wrap items-center justify-between gap-2">
70
+ <div className="flex items-center gap-2">
71
+ <span className="font-semibold text-slate-900 dark:text-slate-100">
72
+ {payload.title}
73
+ </span>
74
+ <span className="rounded bg-slate-200/80 px-1.5 py-0.5 font-mono text-[11px] text-slate-700 dark:bg-slate-800 dark:text-slate-300">
75
+ v{payload.revision}
76
+ </span>
77
+ {draft.selectedRowIds.length > 0 ? (
78
+ <span
79
+ data-testid="ui-surface-card-draft-count"
80
+ className="rounded bg-blue-500/15 px-1.5 py-0.5 text-[11px] font-medium text-blue-700 dark:text-blue-300"
81
+ >
82
+ {draft.selectedRowIds.length} selected
83
+ </span>
84
+ ) : null}
85
+ </div>
86
+ {onOpenWorkbench ? (
87
+ <button
88
+ type="button"
89
+ data-testid="ui-surface-open-workbench"
90
+ onClick={() => onOpenWorkbench(payload)}
91
+ className="rounded-lg border border-slate-300 bg-white px-2.5 py-1 text-xs font-medium text-slate-800 hover:bg-slate-100 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-100"
92
+ >
93
+ {openWorkbenchLabel}
94
+ </button>
95
+ ) : null}
96
+ </div>
97
+
98
+ {payload.subtitle ? (
99
+ <p className="mt-1 text-slate-600 dark:text-slate-400">{payload.subtitle}</p>
100
+ ) : null}
101
+
102
+ {stepComponent && Array.isArray(stepComponent.steps) && stepComponent.steps.length > 0 ? (
103
+ <div className="mt-2 flex flex-wrap items-center gap-2 text-[11px] text-slate-700 dark:text-slate-300">
104
+ {stepComponent.steps.map((step, idx) => {
105
+ const mark =
106
+ step.status === 'completed'
107
+ ? '✓'
108
+ : step.status === 'active'
109
+ ? '●'
110
+ : step.status === 'failed'
111
+ ? '✗'
112
+ : '○';
113
+ return (
114
+ <span key={step.id} className="inline-flex items-center gap-1">
115
+ {idx > 0 ? <span className="text-slate-400">→</span> : null}
116
+ <span>
117
+ {step.label} {mark}
118
+ </span>
119
+ </span>
120
+ );
121
+ })}
122
+ </div>
123
+ ) : null}
124
+
125
+ <div className="mt-2 flex flex-wrap items-center gap-3 text-[11px] text-slate-500 dark:text-slate-400">
126
+ {tableComponent ? <span>{resolvedRows.length} rows</span> : null}
127
+ {sourceNames.length > 0 ? (
128
+ <span>Source: {sourceNames.join(', ')}</span>
129
+ ) : null}
130
+ </div>
131
+ </div>
132
+ );
133
+ };
@@ -0,0 +1,523 @@
1
+ /**
2
+ * `<UiSurfaceWorkbench />`
3
+ *
4
+ * Declarative structured business workbench (v1) supporting the 6 closed component
5
+ * kinds (`table`, `detail-card`, `form`, `steps`, `kv-diff`, `artifact-card`).
6
+ *
7
+ * Security & data integrity invariants:
8
+ * - Zero `dangerouslySetInnerHTML` or raw HTML rendering; all values render as React text nodes.
9
+ * - Row selection submits ONLY `selectedRowIds` + `expectedRevision` + `sourceHashes` + `commandId`;
10
+ * authoritative row values stay on the server and are re-verified via `$source` hashes.
11
+ * - When the server responds with `409 UI_STALE`, renders a prominent warning banner (wireframe W3)
12
+ * and allows refreshing data while preserving non-conflicting draft edits and highlighting changed cells.
13
+ */
14
+ import * as React from 'react';
15
+ import type { UiSurfacePayload } from '@steerable/agent-protocol';
16
+ import {
17
+ getUiSurfaceDraft,
18
+ patchUiSurfaceDraft,
19
+ subscribeUiSurfaceDraft,
20
+ } from './ui-surface-draft.js';
21
+
22
+ export interface UiSurfaceActionDispatchRequest {
23
+ readonly surfaceId: string;
24
+ readonly actionId: string;
25
+ readonly commandId: string;
26
+ readonly expectedRevision: number;
27
+ readonly sourceHashes: Readonly<Record<string, string>>;
28
+ readonly selectedRowIds: readonly string[];
29
+ readonly formValues: Readonly<Record<string, string | number | boolean>>;
30
+ readonly kvDiffOverrides: Readonly<Record<string, string>>;
31
+ readonly note?: string;
32
+ }
33
+
34
+ export interface UiSurfaceWorkbenchProps {
35
+ payload: UiSurfacePayload;
36
+ chatId?: string;
37
+ staleBannerKeys?: readonly string[];
38
+ isBusy?: boolean;
39
+ onDispatchAction?: (req: UiSurfaceActionDispatchRequest) => void | Promise<void>;
40
+ onRefreshSurface?: (surfaceId: string) => void | Promise<void>;
41
+ className?: string;
42
+ }
43
+
44
+ type SurfaceComponent = UiSurfacePayload['components'][number];
45
+
46
+ function createCommandId(surfaceId: string, actionId: string): string {
47
+ const rand = Math.random().toString(36).slice(2, 10);
48
+ return `cmd_${surfaceId}_${actionId}_${Date.now()}_${rand}`;
49
+ }
50
+
51
+ function resolveTableRows(
52
+ comp: SurfaceComponent,
53
+ resolvedData: Record<string, unknown> | undefined,
54
+ ): Record<string, unknown>[] {
55
+ if (comp.dataKey && resolvedData && Array.isArray(resolvedData[comp.dataKey])) {
56
+ return resolvedData[comp.dataKey] as Record<string, unknown>[];
57
+ }
58
+ return Array.isArray(comp.rows) ? (comp.rows as Record<string, unknown>[]) : [];
59
+ }
60
+
61
+ function formatCellValue(value: unknown): string {
62
+ if (value === null || value === undefined) return '—';
63
+ if (typeof value === 'string') return value;
64
+ if (typeof value === 'number' || typeof value === 'boolean') return String(value);
65
+ return JSON.stringify(value);
66
+ }
67
+
68
+ export const UiSurfaceWorkbench: React.FC<UiSurfaceWorkbenchProps> = ({
69
+ payload,
70
+ chatId,
71
+ staleBannerKeys,
72
+ isBusy = false,
73
+ onDispatchAction,
74
+ onRefreshSurface,
75
+ className = '',
76
+ }) => {
77
+ const [, forceRender] = React.useReducer((n: number) => n + 1, 0);
78
+ React.useEffect(
79
+ () => subscribeUiSurfaceDraft(chatId, payload.surfaceId, forceRender),
80
+ [chatId, payload.surfaceId],
81
+ );
82
+ const draft = getUiSurfaceDraft(chatId, payload.surfaceId);
83
+
84
+ // Track previous cell values across revisions so refreshed cells flash yellow for 2s
85
+ const prevRowSnapshotsRef = React.useRef<Map<string, string>>(new Map());
86
+ const [changedCellKeys, setChangedCellKeys] = React.useState<Set<string>>(new Set());
87
+
88
+ React.useEffect(() => {
89
+ const nextSnapshots = new Map<string, string>();
90
+ const newlyChanged = new Set<string>();
91
+ for (const comp of payload.components) {
92
+ if (comp.kind !== 'table') continue;
93
+ const idField = comp.rowIdField || 'id';
94
+ const rows = resolveTableRows(comp, payload.resolvedData);
95
+ for (const row of rows) {
96
+ const rowId = String(row[idField] ?? '');
97
+ if (!rowId) continue;
98
+ for (const [colKey, cellVal] of Object.entries(row)) {
99
+ const snapKey = `${comp.id}::${rowId}::${colKey}`;
100
+ const serialized = formatCellValue(cellVal);
101
+ nextSnapshots.set(snapKey, serialized);
102
+ const prev = prevRowSnapshotsRef.current.get(snapKey);
103
+ if (prev !== undefined && prev !== serialized) {
104
+ newlyChanged.add(snapKey);
105
+ }
106
+ }
107
+ }
108
+ }
109
+ prevRowSnapshotsRef.current = nextSnapshots;
110
+ if (newlyChanged.size > 0) {
111
+ setChangedCellKeys(newlyChanged);
112
+ const timer = setTimeout(() => setChangedCellKeys(new Set()), 2000);
113
+ return () => clearTimeout(timer);
114
+ }
115
+ return undefined;
116
+ }, [payload.revision, payload.components, payload.resolvedData]);
117
+
118
+ const effectiveStaleKeys =
119
+ staleBannerKeys && staleBannerKeys.length > 0
120
+ ? staleBannerKeys
121
+ : payload.staleKeys ?? [];
122
+
123
+ const toggleRow = (rowId: string) => {
124
+ const set = new Set(draft.selectedRowIds);
125
+ if (set.has(rowId)) {
126
+ set.delete(rowId);
127
+ } else {
128
+ set.add(rowId);
129
+ }
130
+ patchUiSurfaceDraft(chatId, payload.surfaceId, {
131
+ selectedRowIds: [...set],
132
+ });
133
+ };
134
+
135
+ const handleActionClick = (action: NonNullable<UiSurfacePayload['actions']>[number]) => {
136
+ if (isBusy || !onDispatchAction) return;
137
+ if (action.requiresSelection && draft.selectedRowIds.length === 0) return;
138
+ const commandId = createCommandId(payload.surfaceId, action.id);
139
+ const trimmedNote = draft.note.trim();
140
+ void onDispatchAction({
141
+ surfaceId: payload.surfaceId,
142
+ actionId: action.id,
143
+ commandId,
144
+ expectedRevision: payload.revision,
145
+ sourceHashes: payload.sourceHashes ?? {},
146
+ selectedRowIds: draft.selectedRowIds,
147
+ formValues: draft.formValues,
148
+ kvDiffOverrides: draft.kvDiffOverrides,
149
+ ...(trimmedNote ? { note: trimmedNote } : {}),
150
+ });
151
+ };
152
+
153
+ return (
154
+ <div
155
+ data-testid="ui-surface-workbench"
156
+ data-surface-id={payload.surfaceId}
157
+ data-revision={payload.revision}
158
+ className={`flex flex-col gap-4 rounded-xl border border-slate-200 bg-white p-4 text-xs dark:border-slate-800 dark:bg-slate-950 ${className}`.trim()}
159
+ >
160
+ {/* Header */}
161
+ <div className="flex flex-wrap items-center justify-between gap-2 border-b border-slate-200 pb-3 dark:border-slate-800">
162
+ <div>
163
+ <h3 className="text-sm font-semibold text-slate-900 dark:text-slate-100">
164
+ {payload.title}
165
+ </h3>
166
+ {payload.subtitle ? (
167
+ <p className="mt-0.5 text-xs text-slate-500 dark:text-slate-400">
168
+ {payload.subtitle}
169
+ </p>
170
+ ) : null}
171
+ </div>
172
+ <span className="rounded bg-slate-100 px-2 py-0.5 font-mono text-[11px] text-slate-600 dark:bg-slate-900 dark:text-slate-300">
173
+ Synced · v{payload.revision}
174
+ </span>
175
+ </div>
176
+
177
+ {/* W3: 409 UI_STALE banner */}
178
+ {effectiveStaleKeys.length > 0 ? (
179
+ <div
180
+ role="alert"
181
+ data-testid="ui-surface-stale-banner"
182
+ className="flex flex-wrap items-center justify-between gap-3 rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2.5 text-amber-950 dark:text-amber-200"
183
+ >
184
+ <span>
185
+ ⚠ Underlying business data changed ({effectiveStaleKeys.join(', ')}). This submission
186
+ was safely blocked before any changes were written.
187
+ </span>
188
+ {onRefreshSurface ? (
189
+ <button
190
+ type="button"
191
+ data-testid="ui-surface-refresh-btn"
192
+ disabled={isBusy}
193
+ onClick={() => void onRefreshSurface(payload.surfaceId)}
194
+ className="rounded-md bg-amber-600 px-2.5 py-1 text-xs font-medium text-white hover:bg-amber-700 disabled:opacity-50"
195
+ >
196
+ Refresh latest data
197
+ </button>
198
+ ) : null}
199
+ </div>
200
+ ) : null}
201
+
202
+ {/* Closed 6-component renderer */}
203
+ <div className="space-y-4">
204
+ {payload.components.map((comp) => {
205
+ switch (comp.kind) {
206
+ case 'steps': {
207
+ const steps = Array.isArray(comp.steps) ? comp.steps : [];
208
+ return (
209
+ <div key={comp.id} data-testid={`surface-steps-${comp.id}`} className="flex flex-wrap items-center gap-3">
210
+ {steps.map((step, index) => (
211
+ <div key={step.id} className="flex items-center gap-1.5">
212
+ {index > 0 ? <span className="text-slate-400">───</span> : null}
213
+ <span
214
+ className={`rounded-full px-2 py-0.5 font-medium ${
215
+ step.status === 'completed'
216
+ ? 'bg-emerald-500/15 text-emerald-700 dark:text-emerald-300'
217
+ : step.status === 'active'
218
+ ? 'bg-blue-500/15 text-blue-700 dark:text-blue-300'
219
+ : step.status === 'failed'
220
+ ? 'bg-rose-500/15 text-rose-700 dark:text-rose-300'
221
+ : 'bg-slate-100 text-slate-500 dark:bg-slate-900'
222
+ }`}
223
+ >
224
+ {step.label}
225
+ </span>
226
+ </div>
227
+ ))}
228
+ </div>
229
+ );
230
+ }
231
+
232
+ case 'table': {
233
+ const rows = resolveTableRows(comp, payload.resolvedData);
234
+ const columns = Array.isArray(comp.columns) ? comp.columns : [];
235
+ const idField = comp.rowIdField || 'id';
236
+ const selectable = comp.selectable !== false;
237
+ return (
238
+ <div key={comp.id} data-testid={`surface-table-${comp.id}`} className="space-y-1.5">
239
+ {comp.title ? (
240
+ <div className="flex items-center justify-between font-medium text-slate-800 dark:text-slate-200">
241
+ <span>{comp.title}</span>
242
+ {selectable ? (
243
+ <span className="text-[11px] text-slate-500">
244
+ Selected {draft.selectedRowIds.length} / {rows.length}
245
+ </span>
246
+ ) : null}
247
+ </div>
248
+ ) : null}
249
+ <div className="overflow-x-auto rounded-lg border border-slate-200 dark:border-slate-800">
250
+ <table className="w-full border-collapse text-left text-xs">
251
+ <thead className="bg-slate-50 text-slate-600 dark:bg-slate-900 dark:text-slate-400">
252
+ <tr>
253
+ {selectable ? <th className="w-8 px-2.5 py-2" aria-label="Select row" /> : null}
254
+ {columns.map((col) => (
255
+ <th key={col.key} className="px-2.5 py-2 font-medium">
256
+ {col.label}
257
+ </th>
258
+ ))}
259
+ </tr>
260
+ </thead>
261
+ <tbody className="divide-y divide-slate-200 dark:divide-slate-800">
262
+ {rows.map((row, idx) => {
263
+ const rowId = String(row[idField] ?? idx);
264
+ const checked = draft.selectedRowIds.includes(rowId);
265
+ return (
266
+ <tr key={rowId} data-row-id={rowId}>
267
+ {selectable ? (
268
+ <td className="px-2.5 py-2">
269
+ <input
270
+ type="checkbox"
271
+ checked={checked}
272
+ onChange={() => toggleRow(rowId)}
273
+ data-testid={`surface-row-check-${rowId}`}
274
+ aria-label={`Select row ${rowId}`}
275
+ />
276
+ </td>
277
+ ) : null}
278
+ {columns.map((col) => {
279
+ const snapKey = `${comp.id}::${rowId}::${col.key}`;
280
+ const highlighted = changedCellKeys.has(snapKey);
281
+ return (
282
+ <td
283
+ key={col.key}
284
+ data-highlighted={highlighted ? 'true' : undefined}
285
+ className={`px-2.5 py-2 transition-colors ${
286
+ highlighted ? 'bg-amber-200/60 dark:bg-amber-500/30' : ''
287
+ }`}
288
+ >
289
+ {formatCellValue(row[col.key])}
290
+ </td>
291
+ );
292
+ })}
293
+ </tr>
294
+ );
295
+ })}
296
+ </tbody>
297
+ </table>
298
+ </div>
299
+ </div>
300
+ );
301
+ }
302
+
303
+ case 'detail-card': {
304
+ const fields = Array.isArray(comp.fields) ? comp.fields : [];
305
+ return (
306
+ <div
307
+ key={comp.id}
308
+ data-testid={`surface-detail-${comp.id}`}
309
+ className="rounded-lg border border-slate-200 p-3 dark:border-slate-800"
310
+ >
311
+ {comp.title ? (
312
+ <div className="mb-2 font-medium text-slate-800 dark:text-slate-200">
313
+ {comp.title}
314
+ </div>
315
+ ) : null}
316
+ <dl className="grid grid-cols-2 gap-2">
317
+ {fields.map((field) => (
318
+ <div key={field.key}>
319
+ <dt className="text-[11px] text-slate-500">{field.label}</dt>
320
+ <dd className="font-medium text-slate-900 dark:text-slate-100">
321
+ {formatCellValue(field.value)}
322
+ </dd>
323
+ </div>
324
+ ))}
325
+ </dl>
326
+ </div>
327
+ );
328
+ }
329
+
330
+ case 'form': {
331
+ const fields = Array.isArray(comp.fields) ? comp.fields : [];
332
+ return (
333
+ <div key={comp.id} data-testid={`surface-form-${comp.id}`} className="space-y-2.5">
334
+ {comp.title ? (
335
+ <div className="font-medium text-slate-800 dark:text-slate-200">
336
+ {comp.title}
337
+ </div>
338
+ ) : null}
339
+ {fields.map((field) => {
340
+ const val =
341
+ draft.formValues[field.key] ??
342
+ (typeof field.value === 'string' ||
343
+ typeof field.value === 'number' ||
344
+ typeof field.value === 'boolean'
345
+ ? field.value
346
+ : '');
347
+ return (
348
+ <label key={field.key} className="block space-y-1">
349
+ <span className="text-[11px] font-medium text-slate-700 dark:text-slate-300">
350
+ {field.label}
351
+ </span>
352
+ {field.type === 'select' && Array.isArray(field.options) ? (
353
+ <select
354
+ value={String(val)}
355
+ onChange={(e) =>
356
+ patchUiSurfaceDraft(chatId, payload.surfaceId, {
357
+ formValues: { [field.key]: e.target.value },
358
+ })
359
+ }
360
+ data-testid={`surface-form-input-${field.key}`}
361
+ className="w-full rounded-lg border border-slate-300 bg-white px-2.5 py-1.5 text-xs dark:border-slate-700 dark:bg-slate-900"
362
+ >
363
+ {field.options.map((opt) => (
364
+ <option key={opt} value={opt}>
365
+ {opt}
366
+ </option>
367
+ ))}
368
+ </select>
369
+ ) : (
370
+ <input
371
+ type={field.type === 'number' ? 'number' : 'text'}
372
+ value={String(val)}
373
+ onChange={(e) =>
374
+ patchUiSurfaceDraft(chatId, payload.surfaceId, {
375
+ formValues: {
376
+ [field.key]:
377
+ field.type === 'number'
378
+ ? Number(e.target.value)
379
+ : e.target.value,
380
+ },
381
+ })
382
+ }
383
+ data-testid={`surface-form-input-${field.key}`}
384
+ className="w-full rounded-lg border border-slate-300 bg-white px-2.5 py-1.5 text-xs dark:border-slate-700 dark:bg-slate-900"
385
+ />
386
+ )}
387
+ </label>
388
+ );
389
+ })}
390
+ </div>
391
+ );
392
+ }
393
+
394
+ case 'kv-diff': {
395
+ const diffs = Array.isArray(comp.diffs) ? comp.diffs : [];
396
+ return (
397
+ <div key={comp.id} data-testid={`surface-kvdiff-${comp.id}`} className="space-y-2">
398
+ {comp.title ? (
399
+ <div className="font-medium text-slate-800 dark:text-slate-200">
400
+ {comp.title}
401
+ </div>
402
+ ) : null}
403
+ {diffs.map((item) => {
404
+ const afterVal =
405
+ draft.kvDiffOverrides[item.key] ?? formatCellValue(item.after);
406
+ return (
407
+ <div
408
+ key={item.key}
409
+ className="flex flex-wrap items-center gap-2 rounded-lg border border-slate-200 p-2 dark:border-slate-800"
410
+ >
411
+ <span className="font-mono text-[11px] text-slate-500">
412
+ {item.label || item.key}:
413
+ </span>
414
+ <span className="line-through text-rose-600 dark:text-rose-400">
415
+ {formatCellValue(item.before)}
416
+ </span>
417
+ <span className="text-slate-400">→</span>
418
+ <input
419
+ type="text"
420
+ value={afterVal}
421
+ onChange={(e) =>
422
+ patchUiSurfaceDraft(chatId, payload.surfaceId, {
423
+ kvDiffOverrides: { [item.key]: e.target.value },
424
+ })
425
+ }
426
+ aria-label={`Replacement value for ${item.label || item.key}`}
427
+ data-testid={`surface-kvdiff-input-${item.key}`}
428
+ className="min-w-[10rem] flex-1 rounded border border-slate-300 bg-white px-2 py-1 text-xs dark:border-slate-700 dark:bg-slate-900"
429
+ />
430
+ </div>
431
+ );
432
+ })}
433
+ </div>
434
+ );
435
+ }
436
+
437
+ case 'artifact-card': {
438
+ const art = comp.artifact ?? {};
439
+ return (
440
+ <div
441
+ key={comp.id}
442
+ data-testid={`surface-artifact-${comp.id}`}
443
+ className="flex items-center justify-between gap-2 rounded-lg border border-slate-200 p-3 dark:border-slate-800"
444
+ >
445
+ <div>
446
+ <div className="font-medium text-slate-900 dark:text-slate-100">
447
+ {art.name || comp.title || 'Deliverable artifact'}
448
+ </div>
449
+ {art.sha256 ? (
450
+ <div className="font-mono text-[11px] text-slate-500">
451
+ SHA-256: {art.sha256.slice(0, 16)}…
452
+ </div>
453
+ ) : null}
454
+ </div>
455
+ {art.downloadUrl ? (
456
+ <a
457
+ href={art.downloadUrl}
458
+ className="rounded-md border border-slate-300 px-2.5 py-1 text-xs font-medium hover:bg-slate-50 dark:border-slate-700"
459
+ >
460
+ Download
461
+ </a>
462
+ ) : null}
463
+ </div>
464
+ );
465
+ }
466
+
467
+ default:
468
+ return null;
469
+ }
470
+ })}
471
+ </div>
472
+
473
+ {/* Operator review note + action buttons */}
474
+ {Array.isArray(payload.actions) && payload.actions.length > 0 ? (
475
+ <div className="space-y-2.5 border-t border-slate-200 pt-3 dark:border-slate-800">
476
+ <input
477
+ type="text"
478
+ value={draft.note}
479
+ onChange={(e) =>
480
+ patchUiSurfaceDraft(chatId, payload.surfaceId, { note: e.target.value })
481
+ }
482
+ placeholder="Optional review note"
483
+ aria-label="Optional review note"
484
+ data-testid="ui-surface-note-input"
485
+ className="w-full rounded-lg border border-slate-300 bg-white px-2.5 py-1.5 text-xs dark:border-slate-700 dark:bg-slate-900"
486
+ />
487
+ <div className="flex flex-wrap items-center justify-between gap-2">
488
+ <span className="text-[11px] text-slate-500">
489
+ {draft.selectedRowIds.length > 0
490
+ ? `${draft.selectedRowIds.length} selected`
491
+ : 'Ready'}
492
+ </span>
493
+ <div className="flex flex-wrap items-center gap-2">
494
+ {payload.actions.map((action) => {
495
+ const disabled =
496
+ isBusy ||
497
+ Boolean(action.requiresSelection && draft.selectedRowIds.length === 0);
498
+ return (
499
+ <button
500
+ key={action.id}
501
+ type="button"
502
+ disabled={disabled}
503
+ onClick={() => handleActionClick(action)}
504
+ data-testid={`ui-surface-action-${action.id}`}
505
+ className={`rounded-lg px-3 py-1.5 text-xs font-medium transition disabled:opacity-50 ${
506
+ action.variant === 'danger'
507
+ ? 'bg-rose-600 text-white hover:bg-rose-700'
508
+ : action.variant === 'secondary'
509
+ ? 'border border-slate-300 bg-white text-slate-800 hover:bg-slate-50 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100'
510
+ : 'bg-slate-900 text-white hover:bg-slate-800 dark:bg-slate-100 dark:text-slate-900'
511
+ }`}
512
+ >
513
+ {action.label}
514
+ </button>
515
+ );
516
+ })}
517
+ </div>
518
+ </div>
519
+ </div>
520
+ ) : null}
521
+ </div>
522
+ );
523
+ };
@@ -58,3 +58,36 @@ export type { ActionSegmentCardProps } from './ActionSegmentCard.js';
58
58
 
59
59
  export { ToolExecutionCard } from './ToolExecutionCard.js';
60
60
  export type { ToolExecutionCardProps } from './ToolExecutionCard.js';
61
+
62
+ export { OutcomeReconcileCard } from './OutcomeReconcileCard.js';
63
+ export type {
64
+ OutcomeReconcileCardProps,
65
+ OutcomeReconcileDecision,
66
+ } from './OutcomeReconcileCard.js';
67
+
68
+ export {
69
+ getUiSurfaceDraft,
70
+ patchUiSurfaceDraft,
71
+ clearUiSurfaceDraft,
72
+ subscribeUiSurfaceDraft,
73
+ resetAllUiSurfaceDraftsForTests,
74
+ } from './ui-surface-draft.js';
75
+ export type { UiSurfaceDraftState } from './ui-surface-draft.js';
76
+
77
+ export { UiSurfaceCard } from './UiSurfaceCard.js';
78
+ export type { UiSurfaceCardProps } from './UiSurfaceCard.js';
79
+
80
+ export { UiSurfaceWorkbench } from './UiSurfaceWorkbench.js';
81
+ export type {
82
+ UiSurfaceWorkbenchProps,
83
+ UiSurfaceActionDispatchRequest,
84
+ } from './UiSurfaceWorkbench.js';
85
+
86
+ export { FactChainDrawer } from './FactChainDrawer.js';
87
+ export type {
88
+ FactChainDrawerProps,
89
+ FactChainGraph,
90
+ FactChainRequestNode,
91
+ FactChainToolNode,
92
+ FactChainDeliverableNode,
93
+ } from './FactChainDrawer.js';