@steerable/agent-ui 0.12.8 → 0.14.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.
@@ -0,0 +1,53 @@
1
+ /**
2
+ * `<FactChainDrawer />`
3
+ *
4
+ * Read-only execution provenance & deliverable evidence drawer (wireframes W6 & W7).
5
+ * Displays only authoritative ledger facts:
6
+ * - `requestNode`: model, `policyDigest`, attachment hashes — or honest `status: 'gap'` notice.
7
+ * - `toolNodes`: real executed / `outcome_unknown` tool records — or explicit `no_tool_evidence`
8
+ * notice when the assistant answered from model parameters alone (never quoting prose as evidence).
9
+ * - `deliverableNode`: verifier results, `snapshotSha256`, live workspace drift warning
10
+ * (`'unchanged' | 'modified' | 'deleted'`), and immutable snapshot download URL.
11
+ */
12
+ import * as React from 'react';
13
+ export interface FactChainRequestNode {
14
+ readonly status: 'recorded' | 'gap';
15
+ readonly model?: string;
16
+ readonly policyDigest?: string;
17
+ readonly systemPromptSummary?: string;
18
+ readonly attachmentHashes?: readonly string[];
19
+ readonly gapReason?: string;
20
+ }
21
+ export interface FactChainToolNode {
22
+ readonly id: string;
23
+ readonly toolName: string;
24
+ readonly argsSummary: string;
25
+ readonly status: 'executed' | 'outcome_unknown' | 'failed';
26
+ readonly durationMs?: number;
27
+ }
28
+ export interface FactChainDeliverableNode {
29
+ readonly id: string;
30
+ readonly fileName: string;
31
+ readonly filePath: string;
32
+ readonly verificationStatus: 'verified' | 'warnings' | 'failed' | 'unverified';
33
+ readonly verifierSummary?: string | null;
34
+ readonly snapshotSha256: string;
35
+ readonly workspaceState: 'unchanged' | 'modified' | 'deleted';
36
+ readonly snapshotDownloadUrl?: string | null;
37
+ }
38
+ export interface FactChainGraph {
39
+ readonly chatId: string;
40
+ readonly targetKind: 'message' | 'tool' | 'deliverable';
41
+ readonly targetId: string;
42
+ readonly requestNode: FactChainRequestNode;
43
+ readonly evidenceStatus: 'recorded' | 'no_tool_evidence' | 'gap';
44
+ readonly toolNodes: readonly FactChainToolNode[];
45
+ readonly deliverableNode?: FactChainDeliverableNode | null;
46
+ }
47
+ export interface FactChainDrawerProps {
48
+ graph: FactChainGraph | null;
49
+ open: boolean;
50
+ onClose?: () => void;
51
+ className?: string;
52
+ }
53
+ export declare const FactChainDrawer: React.FC<FactChainDrawerProps>;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ export const FactChainDrawer = ({ graph, open, onClose, className = '', }) => {
3
+ if (!open || !graph)
4
+ return null;
5
+ const deliv = graph.deliverableNode;
6
+ return (_jsxs("aside", { "aria-label": "Fact Chain", "data-testid": "fact-chain-drawer", className: `flex flex-col gap-4 rounded-xl border border-slate-200 bg-white p-4 text-xs shadow-lg dark:border-slate-800 dark:bg-slate-950 ${className}`.trim(), children: [_jsxs("div", { className: "flex items-center justify-between border-b border-slate-200 pb-2.5 dark:border-slate-800", children: [_jsx("span", { className: "text-sm font-semibold text-slate-900 dark:text-slate-100", children: "Execution evidence chain (Fact Chain)" }), onClose ? (_jsx("button", { type: "button", onClick: onClose, "data-testid": "fact-chain-close", className: "rounded px-2 py-1 text-xs text-slate-500 hover:bg-slate-100 dark:hover:bg-slate-900", children: "Close" })) : null] }), deliv && deliv.workspaceState !== 'unchanged' ? (_jsxs("div", { role: "alert", "data-testid": "fact-chain-workspace-drift", className: "rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-amber-950 dark:text-amber-200", children: ["\u26A0 Workspace file was ", deliv.workspaceState, " after verification. The immutable snapshot link below still serves the exact bytes that passed verification."] })) : null, _jsxs("section", { className: "space-y-1 rounded-lg border border-slate-200 p-3 dark:border-slate-800", children: [_jsx("div", { className: "font-semibold text-slate-800 dark:text-slate-200", children: "1. Request snapshot" }), graph.requestNode.status === 'gap' ? (_jsxs("p", { "data-testid": "fact-chain-request-gap", className: "text-amber-700 dark:text-amber-300", children: ["Missing record (", graph.requestNode.gapReason || 'imported_without_request_snapshot', ")"] })) : (_jsxs("div", { className: "space-y-1 text-slate-600 dark:text-slate-400", children: [graph.requestNode.model ? _jsxs("div", { children: ["Model: ", graph.requestNode.model] }) : null, graph.requestNode.policyDigest ? (_jsxs("div", { className: "font-mono", children: ["Policy digest: ", graph.requestNode.policyDigest] })) : null, graph.requestNode.attachmentHashes &&
7
+ graph.requestNode.attachmentHashes.length > 0 ? (_jsxs("div", { className: "font-mono", children: ["Input SHA-256: ", graph.requestNode.attachmentHashes.join(', ')] })) : null] }))] }), _jsxs("section", { className: "space-y-2 rounded-lg border border-slate-200 p-3 dark:border-slate-800", children: [_jsx("div", { className: "font-semibold text-slate-800 dark:text-slate-200", children: "2. Tool execution receipts" }), graph.evidenceStatus === 'no_tool_evidence' || graph.toolNodes.length === 0 ? (_jsx("p", { "data-testid": "fact-chain-no-tool-evidence", className: "text-slate-500", children: "No tool evidence recorded for this response (generated without tool calls)." })) : (_jsx("ul", { className: "space-y-1.5", children: graph.toolNodes.map((node) => (_jsxs("li", { "data-testid": `fact-chain-tool-${node.id}`, className: "rounded border border-slate-100 bg-slate-50/70 p-2 dark:border-slate-800 dark:bg-slate-900/50", children: [_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx("span", { className: "font-mono font-medium", children: node.toolName }), _jsx("span", { className: `rounded px-1.5 py-0.5 text-[10px] font-medium ${node.status === 'executed'
8
+ ? 'bg-emerald-500/15 text-emerald-700 dark:text-emerald-300'
9
+ : node.status === 'outcome_unknown'
10
+ ? 'bg-amber-500/20 text-amber-800 dark:text-amber-200'
11
+ : 'bg-rose-500/15 text-rose-700 dark:text-rose-300'}`, children: node.status })] }), node.argsSummary ? (_jsx("div", { className: "mt-1 truncate font-mono text-[11px] text-slate-500", children: node.argsSummary })) : null] }, node.id))) }))] }), deliv ? (_jsxs("section", { "data-testid": "fact-chain-deliverable", className: "space-y-1.5 rounded-lg border border-slate-200 p-3 dark:border-slate-800", children: [_jsx("div", { className: "font-semibold text-slate-800 dark:text-slate-200", children: "3. Verified deliverable snapshot" }), _jsxs("div", { className: "font-medium text-slate-900 dark:text-slate-100", children: [deliv.fileName, " (", deliv.verificationStatus, ")"] }), deliv.verifierSummary ? (_jsx("div", { className: "text-slate-600 dark:text-slate-400", children: deliv.verifierSummary })) : null, _jsxs("div", { className: "font-mono text-[11px] text-slate-500", children: ["Snapshot SHA-256: ", deliv.snapshotSha256] }), deliv.snapshotDownloadUrl ? (_jsx("a", { href: deliv.snapshotDownloadUrl, "data-testid": "fact-chain-download-snapshot", className: "inline-block rounded-md bg-slate-900 px-2.5 py-1 text-xs font-medium text-white hover:bg-slate-800 dark:bg-slate-100 dark:text-slate-900", children: "Download verified snapshot" })) : null] })) : null] }));
12
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * `<OutcomeReconcileCard />`
3
+ *
4
+ * Amber stop-and-reconcile card rendered when a non-idempotent (`idempotent: false`)
5
+ * tool call times out, disconnects, or fails after crossing the dispatch boundary
6
+ * (`outcomeUnknown: true`).
7
+ *
8
+ * Neither reconciliation button re-executes the original tool:
9
+ * - `confirmed_not_executed` releases the session lock so a subsequent turn may try again;
10
+ * - `confirmed_succeeded` records external completion in the ledger and keeps duplicate calls blocked.
11
+ */
12
+ import * as React from 'react';
13
+ import type { OutcomeReconcilePayload } from '@steerable/agent-protocol';
14
+ export type OutcomeReconcileDecision = 'confirmed_succeeded' | 'confirmed_not_executed';
15
+ export interface OutcomeReconcileCardProps {
16
+ payload: OutcomeReconcilePayload;
17
+ isSubmitting?: boolean;
18
+ onReconcile?: (decision: {
19
+ reconciliationId: string;
20
+ resolution: OutcomeReconcileDecision;
21
+ note?: string;
22
+ }) => void;
23
+ className?: string;
24
+ titleLabel?: React.ReactNode;
25
+ descriptionLabel?: React.ReactNode;
26
+ confirmNotExecutedLabel?: React.ReactNode;
27
+ confirmSucceededLabel?: React.ReactNode;
28
+ notePlaceholder?: string;
29
+ }
30
+ export declare const OutcomeReconcileCard: React.FC<OutcomeReconcileCardProps>;
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * `<OutcomeReconcileCard />`
4
+ *
5
+ * Amber stop-and-reconcile card rendered when a non-idempotent (`idempotent: false`)
6
+ * tool call times out, disconnects, or fails after crossing the dispatch boundary
7
+ * (`outcomeUnknown: true`).
8
+ *
9
+ * Neither reconciliation button re-executes the original tool:
10
+ * - `confirmed_not_executed` releases the session lock so a subsequent turn may try again;
11
+ * - `confirmed_succeeded` records external completion in the ledger and keeps duplicate calls blocked.
12
+ */
13
+ import * as React from 'react';
14
+ export const OutcomeReconcileCard = ({ payload, isSubmitting = false, onReconcile, className = '', titleLabel = 'External execution outcome unknown · automatic retry paused', descriptionLabel, confirmNotExecutedLabel = 'Confirm not executed, release lock', confirmSucceededLabel = 'Confirm executed externally', notePlaceholder = 'Optional operator verification note', }) => {
15
+ const [note, setNote] = React.useState('');
16
+ const isPending = payload.status === 'pending';
17
+ const handleDecision = (resolution) => {
18
+ if (!isPending || isSubmitting || !onReconcile)
19
+ return;
20
+ const trimmed = note.trim();
21
+ onReconcile({
22
+ reconciliationId: payload.reconciliationId,
23
+ resolution,
24
+ ...(trimmed ? { note: trimmed } : {}),
25
+ });
26
+ };
27
+ return (_jsxs("div", { "data-testid": "outcome-reconcile-card", "data-status": payload.status, className: `rounded-xl border border-amber-500/40 bg-amber-500/10 p-4 text-sm ${className}`.trim(), children: [_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsxs("div", { className: "flex items-center gap-2 font-medium text-amber-800 dark:text-amber-300", children: [_jsx("span", { "aria-hidden": "true", children: "\u26A0" }), _jsx("span", { children: titleLabel })] }), _jsx("span", { className: "rounded bg-amber-500/20 px-2 py-0.5 font-mono text-xs text-amber-900 dark:text-amber-200", children: payload.reconciliationId })] }), _jsx("p", { className: "mt-2 text-xs leading-relaxed text-amber-900/90 dark:text-amber-100/90", children: descriptionLabel ?? (_jsxs(_Fragment, { children: ["Tool ", _jsx("code", { className: "rounded bg-amber-500/20 px-1 py-0.5 font-mono", children: payload.toolName }), ' ', "did not return a definitive receipt", payload.errorDetail ? ` (${payload.errorDetail})` : '', ". To prevent duplicate side effects, further calls to this tool are locked until you verify its external state."] })) }), payload.argsPreview ? (_jsx("pre", { className: "mt-2 max-h-28 overflow-auto rounded-lg border border-amber-500/20 bg-black/5 p-2 font-mono text-xs dark:bg-white/5", children: payload.argsPreview })) : null, isPending ? (_jsxs("div", { className: "mt-3 space-y-2.5", children: [_jsx("input", { type: "text", value: note, onChange: (e) => setNote(e.target.value), disabled: isSubmitting, placeholder: notePlaceholder, "aria-label": notePlaceholder, className: "w-full rounded-lg border border-amber-500/30 bg-white/80 px-2.5 py-1.5 text-xs outline-none focus:border-amber-600 dark:bg-black/30" }), _jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsx("button", { type: "button", disabled: isSubmitting, onClick: () => handleDecision('confirmed_not_executed'), "data-testid": "reconcile-not-executed", className: "rounded-lg border border-amber-600/40 bg-white/70 px-3 py-1.5 text-xs font-medium text-amber-900 hover:bg-white disabled:opacity-50 dark:bg-black/30 dark:text-amber-200", children: confirmNotExecutedLabel }), _jsx("button", { type: "button", disabled: isSubmitting, onClick: () => handleDecision('confirmed_succeeded'), "data-testid": "reconcile-confirmed-succeeded", className: "rounded-lg bg-amber-600 px-3 py-1.5 text-xs font-medium text-white hover:bg-amber-700 disabled:opacity-50", children: confirmSucceededLabel })] })] })) : (_jsxs("div", { "data-testid": "reconcile-resolved-summary", className: "mt-3 rounded-lg border border-amber-500/25 bg-white/50 px-3 py-2 text-xs text-amber-950 dark:bg-black/20 dark:text-amber-100", children: [_jsx("span", { className: "font-medium", children: payload.status === 'confirmed_executed'
28
+ ? 'Confirmed executed externally (duplicate calls stay blocked)'
29
+ : 'Confirmed not executed (re-invocation lock released)' }), payload.resolutionNote ? _jsxs("span", { children: [" \u2014 ", payload.resolutionNote] }) : null] }))] }));
30
+ };
@@ -0,0 +1,17 @@
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
+ export interface UiSurfaceCardProps {
11
+ payload: UiSurfacePayload;
12
+ chatId?: string;
13
+ onOpenWorkbench?: (surface: UiSurfacePayload) => void;
14
+ className?: string;
15
+ openWorkbenchLabel?: React.ReactNode;
16
+ }
17
+ export declare const UiSurfaceCard: React.FC<UiSurfaceCardProps>;
@@ -0,0 +1,48 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * `<UiSurfaceCard />`
4
+ *
5
+ * Compact in-stream summary card for a declarative `UiSurfacePayload` (wireframe W1).
6
+ * Summarizes steps, row counts, and bound `$source` keys without flooding the chat
7
+ * stream, and opens or focuses `<UiSurfaceWorkbench />` while sharing live draft state.
8
+ */
9
+ import * as React from 'react';
10
+ import { getUiSurfaceDraft, subscribeUiSurfaceDraft, } from './ui-surface-draft.js';
11
+ export const UiSurfaceCard = ({ payload, chatId, onOpenWorkbench, className = '', openWorkbenchLabel = 'Open in workbench →', }) => {
12
+ const [, forceRender] = React.useReducer((n) => n + 1, 0);
13
+ React.useEffect(() => subscribeUiSurfaceDraft(chatId, payload.surfaceId, forceRender), [chatId, payload.surfaceId]);
14
+ const draft = getUiSurfaceDraft(chatId, payload.surfaceId);
15
+ const stepComponent = payload.components.find((c) => c.kind === 'steps');
16
+ const tableComponent = payload.components.find((c) => c.kind === 'table');
17
+ const resolvedRows = React.useMemo(() => {
18
+ if (!tableComponent)
19
+ return [];
20
+ if (tableComponent.dataKey &&
21
+ payload.resolvedData &&
22
+ Array.isArray(payload.resolvedData[tableComponent.dataKey])) {
23
+ return payload.resolvedData[tableComponent.dataKey];
24
+ }
25
+ return Array.isArray(tableComponent.rows) ? tableComponent.rows : [];
26
+ }, [tableComponent, payload.resolvedData]);
27
+ const sourceNames = React.useMemo(() => {
28
+ const out = [];
29
+ if (payload.data && typeof payload.data === 'object') {
30
+ for (const val of Object.values(payload.data)) {
31
+ if (val && typeof val === 'object' && typeof val.$source === 'string') {
32
+ out.push(val.$source);
33
+ }
34
+ }
35
+ }
36
+ return out;
37
+ }, [payload.data]);
38
+ return (_jsxs("div", { "data-testid": "ui-surface-card", "data-surface-id": payload.surfaceId, 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(), children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "font-semibold text-slate-900 dark:text-slate-100", children: payload.title }), _jsxs("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", children: ["v", payload.revision] }), draft.selectedRowIds.length > 0 ? (_jsxs("span", { "data-testid": "ui-surface-card-draft-count", className: "rounded bg-blue-500/15 px-1.5 py-0.5 text-[11px] font-medium text-blue-700 dark:text-blue-300", children: [draft.selectedRowIds.length, " selected"] })) : null] }), onOpenWorkbench ? (_jsx("button", { type: "button", "data-testid": "ui-surface-open-workbench", onClick: () => onOpenWorkbench(payload), 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", children: openWorkbenchLabel })) : null] }), payload.subtitle ? (_jsx("p", { className: "mt-1 text-slate-600 dark:text-slate-400", children: payload.subtitle })) : null, stepComponent && Array.isArray(stepComponent.steps) && stepComponent.steps.length > 0 ? (_jsx("div", { className: "mt-2 flex flex-wrap items-center gap-2 text-[11px] text-slate-700 dark:text-slate-300", children: stepComponent.steps.map((step, idx) => {
39
+ const mark = step.status === 'completed'
40
+ ? '✓'
41
+ : step.status === 'active'
42
+ ? '●'
43
+ : step.status === 'failed'
44
+ ? '✗'
45
+ : '○';
46
+ return (_jsxs("span", { className: "inline-flex items-center gap-1", children: [idx > 0 ? _jsx("span", { className: "text-slate-400", children: "\u2192" }) : null, _jsxs("span", { children: [step.label, " ", mark] })] }, step.id));
47
+ }) })) : null, _jsxs("div", { className: "mt-2 flex flex-wrap items-center gap-3 text-[11px] text-slate-500 dark:text-slate-400", children: [tableComponent ? _jsxs("span", { children: [resolvedRows.length, " rows"] }) : null, sourceNames.length > 0 ? (_jsxs("span", { children: ["Source: ", sourceNames.join(', ')] })) : null] })] }));
48
+ };
@@ -0,0 +1,36 @@
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
+ export interface UiSurfaceActionDispatchRequest {
17
+ readonly surfaceId: string;
18
+ readonly actionId: string;
19
+ readonly commandId: string;
20
+ readonly expectedRevision: number;
21
+ readonly sourceHashes: Readonly<Record<string, string>>;
22
+ readonly selectedRowIds: readonly string[];
23
+ readonly formValues: Readonly<Record<string, string | number | boolean>>;
24
+ readonly kvDiffOverrides: Readonly<Record<string, string>>;
25
+ readonly note?: string;
26
+ }
27
+ export interface UiSurfaceWorkbenchProps {
28
+ payload: UiSurfacePayload;
29
+ chatId?: string;
30
+ staleBannerKeys?: readonly string[];
31
+ isBusy?: boolean;
32
+ onDispatchAction?: (req: UiSurfaceActionDispatchRequest) => void | Promise<void>;
33
+ onRefreshSurface?: (surfaceId: string) => void | Promise<void>;
34
+ className?: string;
35
+ }
36
+ export declare const UiSurfaceWorkbench: React.FC<UiSurfaceWorkbenchProps>;
@@ -0,0 +1,186 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * `<UiSurfaceWorkbench />`
4
+ *
5
+ * Declarative structured business workbench (v1) supporting the 6 closed component
6
+ * kinds (`table`, `detail-card`, `form`, `steps`, `kv-diff`, `artifact-card`).
7
+ *
8
+ * Security & data integrity invariants:
9
+ * - Zero `dangerouslySetInnerHTML` or raw HTML rendering; all values render as React text nodes.
10
+ * - Row selection submits ONLY `selectedRowIds` + `expectedRevision` + `sourceHashes` + `commandId`;
11
+ * authoritative row values stay on the server and are re-verified via `$source` hashes.
12
+ * - When the server responds with `409 UI_STALE`, renders a prominent warning banner (wireframe W3)
13
+ * and allows refreshing data while preserving non-conflicting draft edits and highlighting changed cells.
14
+ */
15
+ import * as React from 'react';
16
+ import { getUiSurfaceDraft, patchUiSurfaceDraft, subscribeUiSurfaceDraft, } from './ui-surface-draft.js';
17
+ function createCommandId(surfaceId, actionId) {
18
+ const rand = Math.random().toString(36).slice(2, 10);
19
+ return `cmd_${surfaceId}_${actionId}_${Date.now()}_${rand}`;
20
+ }
21
+ function resolveTableRows(comp, resolvedData) {
22
+ if (comp.dataKey && resolvedData && Array.isArray(resolvedData[comp.dataKey])) {
23
+ return resolvedData[comp.dataKey];
24
+ }
25
+ return Array.isArray(comp.rows) ? comp.rows : [];
26
+ }
27
+ function formatCellValue(value) {
28
+ if (value === null || value === undefined)
29
+ return '—';
30
+ if (typeof value === 'string')
31
+ return value;
32
+ if (typeof value === 'number' || typeof value === 'boolean')
33
+ return String(value);
34
+ return JSON.stringify(value);
35
+ }
36
+ export const UiSurfaceWorkbench = ({ payload, chatId, staleBannerKeys, isBusy = false, onDispatchAction, onRefreshSurface, className = '', }) => {
37
+ const [, forceRender] = React.useReducer((n) => n + 1, 0);
38
+ React.useEffect(() => subscribeUiSurfaceDraft(chatId, payload.surfaceId, forceRender), [chatId, payload.surfaceId]);
39
+ const draft = getUiSurfaceDraft(chatId, payload.surfaceId);
40
+ // Track previous cell values across revisions so refreshed cells flash yellow for 2s
41
+ const prevRowSnapshotsRef = React.useRef(new Map());
42
+ const [changedCellKeys, setChangedCellKeys] = React.useState(new Set());
43
+ React.useEffect(() => {
44
+ const nextSnapshots = new Map();
45
+ const newlyChanged = new Set();
46
+ for (const comp of payload.components) {
47
+ if (comp.kind !== 'table')
48
+ continue;
49
+ const idField = comp.rowIdField || 'id';
50
+ const rows = resolveTableRows(comp, payload.resolvedData);
51
+ for (const row of rows) {
52
+ const rowId = String(row[idField] ?? '');
53
+ if (!rowId)
54
+ continue;
55
+ for (const [colKey, cellVal] of Object.entries(row)) {
56
+ const snapKey = `${comp.id}::${rowId}::${colKey}`;
57
+ const serialized = formatCellValue(cellVal);
58
+ nextSnapshots.set(snapKey, serialized);
59
+ const prev = prevRowSnapshotsRef.current.get(snapKey);
60
+ if (prev !== undefined && prev !== serialized) {
61
+ newlyChanged.add(snapKey);
62
+ }
63
+ }
64
+ }
65
+ }
66
+ prevRowSnapshotsRef.current = nextSnapshots;
67
+ if (newlyChanged.size > 0) {
68
+ setChangedCellKeys(newlyChanged);
69
+ const timer = setTimeout(() => setChangedCellKeys(new Set()), 2000);
70
+ return () => clearTimeout(timer);
71
+ }
72
+ return undefined;
73
+ }, [payload.revision, payload.components, payload.resolvedData]);
74
+ const effectiveStaleKeys = staleBannerKeys && staleBannerKeys.length > 0
75
+ ? staleBannerKeys
76
+ : payload.staleKeys ?? [];
77
+ const toggleRow = (rowId) => {
78
+ const set = new Set(draft.selectedRowIds);
79
+ if (set.has(rowId)) {
80
+ set.delete(rowId);
81
+ }
82
+ else {
83
+ set.add(rowId);
84
+ }
85
+ patchUiSurfaceDraft(chatId, payload.surfaceId, {
86
+ selectedRowIds: [...set],
87
+ });
88
+ };
89
+ const handleActionClick = (action) => {
90
+ if (isBusy || !onDispatchAction)
91
+ return;
92
+ if (action.requiresSelection && draft.selectedRowIds.length === 0)
93
+ return;
94
+ const commandId = createCommandId(payload.surfaceId, action.id);
95
+ const trimmedNote = draft.note.trim();
96
+ void onDispatchAction({
97
+ surfaceId: payload.surfaceId,
98
+ actionId: action.id,
99
+ commandId,
100
+ expectedRevision: payload.revision,
101
+ sourceHashes: payload.sourceHashes ?? {},
102
+ selectedRowIds: draft.selectedRowIds,
103
+ formValues: draft.formValues,
104
+ kvDiffOverrides: draft.kvDiffOverrides,
105
+ ...(trimmedNote ? { note: trimmedNote } : {}),
106
+ });
107
+ };
108
+ return (_jsxs("div", { "data-testid": "ui-surface-workbench", "data-surface-id": payload.surfaceId, "data-revision": payload.revision, 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(), children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2 border-b border-slate-200 pb-3 dark:border-slate-800", children: [_jsxs("div", { children: [_jsx("h3", { className: "text-sm font-semibold text-slate-900 dark:text-slate-100", children: payload.title }), payload.subtitle ? (_jsx("p", { className: "mt-0.5 text-xs text-slate-500 dark:text-slate-400", children: payload.subtitle })) : null] }), _jsxs("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", children: ["Synced \u00B7 v", payload.revision] })] }), effectiveStaleKeys.length > 0 ? (_jsxs("div", { role: "alert", "data-testid": "ui-surface-stale-banner", 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", children: [_jsxs("span", { children: ["\u26A0 Underlying business data changed (", effectiveStaleKeys.join(', '), "). This submission was safely blocked before any changes were written."] }), onRefreshSurface ? (_jsx("button", { type: "button", "data-testid": "ui-surface-refresh-btn", disabled: isBusy, onClick: () => void onRefreshSurface(payload.surfaceId), className: "rounded-md bg-amber-600 px-2.5 py-1 text-xs font-medium text-white hover:bg-amber-700 disabled:opacity-50", children: "Refresh latest data" })) : null] })) : null, _jsx("div", { className: "space-y-4", children: payload.components.map((comp) => {
109
+ switch (comp.kind) {
110
+ case 'steps': {
111
+ const steps = Array.isArray(comp.steps) ? comp.steps : [];
112
+ return (_jsx("div", { "data-testid": `surface-steps-${comp.id}`, className: "flex flex-wrap items-center gap-3", children: steps.map((step, index) => (_jsxs("div", { className: "flex items-center gap-1.5", children: [index > 0 ? _jsx("span", { className: "text-slate-400", children: "\u2500\u2500\u2500" }) : null, _jsx("span", { className: `rounded-full px-2 py-0.5 font-medium ${step.status === 'completed'
113
+ ? 'bg-emerald-500/15 text-emerald-700 dark:text-emerald-300'
114
+ : step.status === 'active'
115
+ ? 'bg-blue-500/15 text-blue-700 dark:text-blue-300'
116
+ : step.status === 'failed'
117
+ ? 'bg-rose-500/15 text-rose-700 dark:text-rose-300'
118
+ : 'bg-slate-100 text-slate-500 dark:bg-slate-900'}`, children: step.label })] }, step.id))) }, comp.id));
119
+ }
120
+ case 'table': {
121
+ const rows = resolveTableRows(comp, payload.resolvedData);
122
+ const columns = Array.isArray(comp.columns) ? comp.columns : [];
123
+ const idField = comp.rowIdField || 'id';
124
+ const selectable = comp.selectable !== false;
125
+ return (_jsxs("div", { "data-testid": `surface-table-${comp.id}`, className: "space-y-1.5", children: [comp.title ? (_jsxs("div", { className: "flex items-center justify-between font-medium text-slate-800 dark:text-slate-200", children: [_jsx("span", { children: comp.title }), selectable ? (_jsxs("span", { className: "text-[11px] text-slate-500", children: ["Selected ", draft.selectedRowIds.length, " / ", rows.length] })) : null] })) : null, _jsx("div", { className: "overflow-x-auto rounded-lg border border-slate-200 dark:border-slate-800", children: _jsxs("table", { className: "w-full border-collapse text-left text-xs", children: [_jsx("thead", { className: "bg-slate-50 text-slate-600 dark:bg-slate-900 dark:text-slate-400", children: _jsxs("tr", { children: [selectable ? _jsx("th", { className: "w-8 px-2.5 py-2", "aria-label": "Select row" }) : null, columns.map((col) => (_jsx("th", { className: "px-2.5 py-2 font-medium", children: col.label }, col.key)))] }) }), _jsx("tbody", { className: "divide-y divide-slate-200 dark:divide-slate-800", children: rows.map((row, idx) => {
126
+ const rowId = String(row[idField] ?? idx);
127
+ const checked = draft.selectedRowIds.includes(rowId);
128
+ return (_jsxs("tr", { "data-row-id": rowId, children: [selectable ? (_jsx("td", { className: "px-2.5 py-2", children: _jsx("input", { type: "checkbox", checked: checked, onChange: () => toggleRow(rowId), "data-testid": `surface-row-check-${rowId}`, "aria-label": `Select row ${rowId}` }) })) : null, columns.map((col) => {
129
+ const snapKey = `${comp.id}::${rowId}::${col.key}`;
130
+ const highlighted = changedCellKeys.has(snapKey);
131
+ return (_jsx("td", { "data-highlighted": highlighted ? 'true' : undefined, className: `px-2.5 py-2 transition-colors ${highlighted ? 'bg-amber-200/60 dark:bg-amber-500/30' : ''}`, children: formatCellValue(row[col.key]) }, col.key));
132
+ })] }, rowId));
133
+ }) })] }) })] }, comp.id));
134
+ }
135
+ case 'detail-card': {
136
+ const fields = Array.isArray(comp.fields) ? comp.fields : [];
137
+ return (_jsxs("div", { "data-testid": `surface-detail-${comp.id}`, className: "rounded-lg border border-slate-200 p-3 dark:border-slate-800", children: [comp.title ? (_jsx("div", { className: "mb-2 font-medium text-slate-800 dark:text-slate-200", children: comp.title })) : null, _jsx("dl", { className: "grid grid-cols-2 gap-2", children: fields.map((field) => (_jsxs("div", { children: [_jsx("dt", { className: "text-[11px] text-slate-500", children: field.label }), _jsx("dd", { className: "font-medium text-slate-900 dark:text-slate-100", children: formatCellValue(field.value) })] }, field.key))) })] }, comp.id));
138
+ }
139
+ case 'form': {
140
+ const fields = Array.isArray(comp.fields) ? comp.fields : [];
141
+ return (_jsxs("div", { "data-testid": `surface-form-${comp.id}`, className: "space-y-2.5", children: [comp.title ? (_jsx("div", { className: "font-medium text-slate-800 dark:text-slate-200", children: comp.title })) : null, fields.map((field) => {
142
+ const val = draft.formValues[field.key] ??
143
+ (typeof field.value === 'string' ||
144
+ typeof field.value === 'number' ||
145
+ typeof field.value === 'boolean'
146
+ ? field.value
147
+ : '');
148
+ return (_jsxs("label", { className: "block space-y-1", children: [_jsx("span", { className: "text-[11px] font-medium text-slate-700 dark:text-slate-300", children: field.label }), field.type === 'select' && Array.isArray(field.options) ? (_jsx("select", { value: String(val), onChange: (e) => patchUiSurfaceDraft(chatId, payload.surfaceId, {
149
+ formValues: { [field.key]: e.target.value },
150
+ }), "data-testid": `surface-form-input-${field.key}`, 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", children: field.options.map((opt) => (_jsx("option", { value: opt, children: opt }, opt))) })) : (_jsx("input", { type: field.type === 'number' ? 'number' : 'text', value: String(val), onChange: (e) => patchUiSurfaceDraft(chatId, payload.surfaceId, {
151
+ formValues: {
152
+ [field.key]: field.type === 'number'
153
+ ? Number(e.target.value)
154
+ : e.target.value,
155
+ },
156
+ }), "data-testid": `surface-form-input-${field.key}`, 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" }))] }, field.key));
157
+ })] }, comp.id));
158
+ }
159
+ case 'kv-diff': {
160
+ const diffs = Array.isArray(comp.diffs) ? comp.diffs : [];
161
+ return (_jsxs("div", { "data-testid": `surface-kvdiff-${comp.id}`, className: "space-y-2", children: [comp.title ? (_jsx("div", { className: "font-medium text-slate-800 dark:text-slate-200", children: comp.title })) : null, diffs.map((item) => {
162
+ const afterVal = draft.kvDiffOverrides[item.key] ?? formatCellValue(item.after);
163
+ return (_jsxs("div", { className: "flex flex-wrap items-center gap-2 rounded-lg border border-slate-200 p-2 dark:border-slate-800", children: [_jsxs("span", { className: "font-mono text-[11px] text-slate-500", children: [item.label || item.key, ":"] }), _jsx("span", { className: "line-through text-rose-600 dark:text-rose-400", children: formatCellValue(item.before) }), _jsx("span", { className: "text-slate-400", children: "\u2192" }), _jsx("input", { type: "text", value: afterVal, onChange: (e) => patchUiSurfaceDraft(chatId, payload.surfaceId, {
164
+ kvDiffOverrides: { [item.key]: e.target.value },
165
+ }), "aria-label": `Replacement value for ${item.label || item.key}`, "data-testid": `surface-kvdiff-input-${item.key}`, 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" })] }, item.key));
166
+ })] }, comp.id));
167
+ }
168
+ case 'artifact-card': {
169
+ const art = comp.artifact ?? {};
170
+ return (_jsxs("div", { "data-testid": `surface-artifact-${comp.id}`, className: "flex items-center justify-between gap-2 rounded-lg border border-slate-200 p-3 dark:border-slate-800", children: [_jsxs("div", { children: [_jsx("div", { className: "font-medium text-slate-900 dark:text-slate-100", children: art.name || comp.title || 'Deliverable artifact' }), art.sha256 ? (_jsxs("div", { className: "font-mono text-[11px] text-slate-500", children: ["SHA-256: ", art.sha256.slice(0, 16), "\u2026"] })) : null] }), art.downloadUrl ? (_jsx("a", { href: art.downloadUrl, className: "rounded-md border border-slate-300 px-2.5 py-1 text-xs font-medium hover:bg-slate-50 dark:border-slate-700", children: "Download" })) : null] }, comp.id));
171
+ }
172
+ default:
173
+ return null;
174
+ }
175
+ }) }), Array.isArray(payload.actions) && payload.actions.length > 0 ? (_jsxs("div", { className: "space-y-2.5 border-t border-slate-200 pt-3 dark:border-slate-800", children: [_jsx("input", { type: "text", value: draft.note, onChange: (e) => patchUiSurfaceDraft(chatId, payload.surfaceId, { note: e.target.value }), placeholder: "Optional review note", "aria-label": "Optional review note", "data-testid": "ui-surface-note-input", 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" }), _jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsx("span", { className: "text-[11px] text-slate-500", children: draft.selectedRowIds.length > 0
176
+ ? `${draft.selectedRowIds.length} selected`
177
+ : 'Ready' }), _jsx("div", { className: "flex flex-wrap items-center gap-2", children: payload.actions.map((action) => {
178
+ const disabled = isBusy ||
179
+ Boolean(action.requiresSelection && draft.selectedRowIds.length === 0);
180
+ return (_jsx("button", { type: "button", disabled: disabled, onClick: () => handleActionClick(action), "data-testid": `ui-surface-action-${action.id}`, className: `rounded-lg px-3 py-1.5 text-xs font-medium transition disabled:opacity-50 ${action.variant === 'danger'
181
+ ? 'bg-rose-600 text-white hover:bg-rose-700'
182
+ : action.variant === 'secondary'
183
+ ? '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'
184
+ : 'bg-slate-900 text-white hover:bg-slate-800 dark:bg-slate-100 dark:text-slate-900'}`, children: action.label }, action.id));
185
+ }) })] })] })) : null] }));
186
+ };
@@ -36,3 +36,13 @@ export { ActionSegmentCard } from './ActionSegmentCard.js';
36
36
  export type { ActionSegmentCardProps } from './ActionSegmentCard.js';
37
37
  export { ToolExecutionCard } from './ToolExecutionCard.js';
38
38
  export type { ToolExecutionCardProps } from './ToolExecutionCard.js';
39
+ export { OutcomeReconcileCard } from './OutcomeReconcileCard.js';
40
+ export type { OutcomeReconcileCardProps, OutcomeReconcileDecision, } from './OutcomeReconcileCard.js';
41
+ export { getUiSurfaceDraft, patchUiSurfaceDraft, clearUiSurfaceDraft, subscribeUiSurfaceDraft, resetAllUiSurfaceDraftsForTests, } from './ui-surface-draft.js';
42
+ export type { UiSurfaceDraftState } from './ui-surface-draft.js';
43
+ export { UiSurfaceCard } from './UiSurfaceCard.js';
44
+ export type { UiSurfaceCardProps } from './UiSurfaceCard.js';
45
+ export { UiSurfaceWorkbench } from './UiSurfaceWorkbench.js';
46
+ export type { UiSurfaceWorkbenchProps, UiSurfaceActionDispatchRequest, } from './UiSurfaceWorkbench.js';
47
+ export { FactChainDrawer } from './FactChainDrawer.js';
48
+ export type { FactChainDrawerProps, FactChainGraph, FactChainRequestNode, FactChainToolNode, FactChainDeliverableNode, } from './FactChainDrawer.js';
@@ -24,3 +24,8 @@ export { SearchSourcesCard } from './SearchSourcesCard.js';
24
24
  export { SummaryMessageCard } from './SummaryMessageCard.js';
25
25
  export { ActionSegmentCard } from './ActionSegmentCard.js';
26
26
  export { ToolExecutionCard } from './ToolExecutionCard.js';
27
+ export { OutcomeReconcileCard } from './OutcomeReconcileCard.js';
28
+ export { getUiSurfaceDraft, patchUiSurfaceDraft, clearUiSurfaceDraft, subscribeUiSurfaceDraft, resetAllUiSurfaceDraftsForTests, } from './ui-surface-draft.js';
29
+ export { UiSurfaceCard } from './UiSurfaceCard.js';
30
+ export { UiSurfaceWorkbench } from './UiSurfaceWorkbench.js';
31
+ export { FactChainDrawer } from './FactChainDrawer.js';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Session-scoped draft state shared between `<UiSurfaceCard />` (inline) and
3
+ * `<UiSurfaceWorkbench />` (right-panel workbench) so collapsing or switching
4
+ * workbench tabs never discards user row selections, form edits, or notes.
5
+ */
6
+ export interface UiSurfaceDraftState {
7
+ readonly selectedRowIds: readonly string[];
8
+ readonly formValues: Readonly<Record<string, string | number | boolean>>;
9
+ readonly kvDiffOverrides: Readonly<Record<string, string>>;
10
+ readonly note: string;
11
+ }
12
+ export declare function getUiSurfaceDraft(chatId: string | undefined, surfaceId: string): UiSurfaceDraftState;
13
+ export declare function patchUiSurfaceDraft(chatId: string | undefined, surfaceId: string, patch: Partial<UiSurfaceDraftState>): UiSurfaceDraftState;
14
+ export declare function clearUiSurfaceDraft(chatId: string | undefined, surfaceId: string): void;
15
+ export declare function resetAllUiSurfaceDraftsForTests(): void;
16
+ export declare function subscribeUiSurfaceDraft(chatId: string | undefined, surfaceId: string, listener: () => void): () => void;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Session-scoped draft state shared between `<UiSurfaceCard />` (inline) and
3
+ * `<UiSurfaceWorkbench />` (right-panel workbench) so collapsing or switching
4
+ * workbench tabs never discards user row selections, form edits, or notes.
5
+ */
6
+ const EMPTY_DRAFT = Object.freeze({
7
+ selectedRowIds: [],
8
+ formValues: {},
9
+ kvDiffOverrides: {},
10
+ note: '',
11
+ });
12
+ const drafts = new Map();
13
+ const listeners = new Map();
14
+ function makeKey(chatId, surfaceId) {
15
+ return `${chatId || 'default'}::${surfaceId}`;
16
+ }
17
+ export function getUiSurfaceDraft(chatId, surfaceId) {
18
+ return drafts.get(makeKey(chatId, surfaceId)) ?? EMPTY_DRAFT;
19
+ }
20
+ export function patchUiSurfaceDraft(chatId, surfaceId, patch) {
21
+ const key = makeKey(chatId, surfaceId);
22
+ const prev = drafts.get(key) ?? EMPTY_DRAFT;
23
+ const next = {
24
+ selectedRowIds: patch.selectedRowIds ?? prev.selectedRowIds,
25
+ formValues: patch.formValues
26
+ ? { ...prev.formValues, ...patch.formValues }
27
+ : prev.formValues,
28
+ kvDiffOverrides: patch.kvDiffOverrides
29
+ ? { ...prev.kvDiffOverrides, ...patch.kvDiffOverrides }
30
+ : prev.kvDiffOverrides,
31
+ note: patch.note !== undefined ? patch.note : prev.note,
32
+ };
33
+ drafts.set(key, next);
34
+ const subs = listeners.get(key);
35
+ if (subs) {
36
+ for (const fn of subs)
37
+ fn();
38
+ }
39
+ return next;
40
+ }
41
+ export function clearUiSurfaceDraft(chatId, surfaceId) {
42
+ const key = makeKey(chatId, surfaceId);
43
+ drafts.delete(key);
44
+ const subs = listeners.get(key);
45
+ if (subs) {
46
+ for (const fn of subs)
47
+ fn();
48
+ }
49
+ }
50
+ export function resetAllUiSurfaceDraftsForTests() {
51
+ drafts.clear();
52
+ listeners.clear();
53
+ }
54
+ export function subscribeUiSurfaceDraft(chatId, surfaceId, listener) {
55
+ const key = makeKey(chatId, surfaceId);
56
+ let set = listeners.get(key);
57
+ if (!set) {
58
+ set = new Set();
59
+ listeners.set(key, set);
60
+ }
61
+ set.add(listener);
62
+ return () => {
63
+ set?.delete(listener);
64
+ if (set && set.size === 0)
65
+ listeners.delete(key);
66
+ };
67
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerable/agent-ui",
3
- "version": "0.12.8",
3
+ "version": "0.14.0",
4
4
  "description": "Steerable framework Tier 4 — headless React hooks (useAgentSession, useChatStream, useToolCallStatus) and Tailwind-themed components (ChatPanel, MessageList, OrchestrationPlanCard, ToolCallRenderer, SSEStreamView) for embedding Steerable agents in any React app.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://steerableframework.com/storybook/",
@@ -57,7 +57,7 @@
57
57
  "README.md"
58
58
  ],
59
59
  "dependencies": {
60
- "@steerable/agent-protocol": "0.12.8"
60
+ "@steerable/agent-protocol": "0.14.0"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "react": ">=18.0.0",