@mistriwork/agent-ui 0.0.0-stage → 1.4.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.
package/dist/tools.js ADDED
@@ -0,0 +1,172 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Agent inspection, terminal, and control primitives for `@mistriwork/agent-ui`:
4
+ * - `<ToolCallInspector>`: filterable tool call execution inspector
5
+ * - `<TerminalOutput>` + `parseAnsiLine`: safe ANSI SGR streaming console
6
+ * - `<ModeSwitcher>`: compact agent mode selector (`Ask` / `Plan` / `Agent` / `Review`)
7
+ * - `<ModelPicker>`: compact model / ACP provider selector
8
+ */
9
+ import { useEffect, useMemo, useRef, useState } from 'react';
10
+ import { Badge, Button, EmptyState, SegmentedControl, Select, StatusDot, TextField } from '@mistriwork/mistri/ui';
11
+ import './workbench.css';
12
+ function callTone(status) {
13
+ if (status === 'completed')
14
+ return 'good';
15
+ if (status === 'failed')
16
+ return 'critical';
17
+ return 'info';
18
+ }
19
+ export function ToolCallInspector({ calls, selectedId, onSelect, title = 'Tool calls', empty, className }) {
20
+ const [filter, setFilter] = useState('all');
21
+ const visible = useMemo(() => {
22
+ if (filter === 'all')
23
+ return calls;
24
+ return calls.filter((c) => c.status === filter);
25
+ }, [calls, filter]);
26
+ return (_jsxs("section", { className: className ? `aui-tool-inspector ${className}` : 'aui-tool-inspector', "aria-label": title, children: [_jsxs("header", { className: "aui-tool-inspector-head", children: [_jsxs("span", { className: "aui-approval-queue-title", children: [_jsx("span", { children: title }), _jsx(Badge, { tone: "neutral", children: String(calls.length) })] }), _jsx(SegmentedControl, { ariaLabel: "Filter tool calls", size: "sm", value: filter, onValueChange: (next) => setFilter(next), options: [
27
+ { value: 'all', label: 'All' },
28
+ { value: 'running', label: 'Running' },
29
+ { value: 'completed', label: 'Done' },
30
+ { value: 'failed', label: 'Failed' },
31
+ ] })] }), visible.length === 0 ? ((empty ?? _jsx(EmptyState, { compact: true, title: "No tool calls" }))) : (_jsx("div", { className: "aui-tool-inspector-list", children: visible.map((call) => (_jsxs("details", { className: "aui-tool-card", open: selectedId === call.id || call.status === 'failed', onToggle: (e) => {
32
+ if (e.currentTarget.open)
33
+ onSelect?.(call.id);
34
+ }, children: [_jsxs("summary", { className: "aui-tool-card-summary", children: [_jsx(StatusDot, { tone: callTone(call.status), pulse: call.status === 'running' }), _jsx("span", { children: call.label ?? call.name }), _jsx(Badge, { tone: callTone(call.status), children: call.status }), call.durationMs !== undefined ? _jsx("span", { className: "kit-agent-msg-meta", children: `${call.durationMs}ms` }) : null] }), _jsxs("div", { className: "aui-tool-card-body", children: [call.input ? (_jsxs("div", { children: [_jsx("div", { className: "aui-tool-section-label", children: "Input" }), _jsx("pre", { className: "kit-agent-code", children: _jsx("code", { children: JSON.stringify(call.input, null, 2) }) })] })) : null, call.error ? (_jsxs("div", { children: [_jsx("div", { className: "aui-tool-section-label", children: "Error" }), _jsx("pre", { className: "kit-agent-code", children: _jsx("code", { children: call.error }) })] })) : null, call.output ? (_jsxs("div", { children: [_jsx("div", { className: "aui-tool-section-label", children: "Output" }), _jsx("pre", { className: "kit-agent-code", children: _jsx("code", { children: call.output }) })] })) : null] })] }, call.id))) }))] }));
35
+ }
36
+ const ANSI_FG_CLASS = {
37
+ 30: 'aui-ansi-muted',
38
+ 31: 'aui-ansi-red',
39
+ 32: 'aui-ansi-green',
40
+ 33: 'aui-ansi-yellow',
41
+ 34: 'aui-ansi-blue',
42
+ 35: 'aui-ansi-magenta',
43
+ 36: 'aui-ansi-cyan',
44
+ 90: 'aui-ansi-muted',
45
+ 91: 'aui-ansi-red',
46
+ 92: 'aui-ansi-green',
47
+ 93: 'aui-ansi-yellow',
48
+ 94: 'aui-ansi-blue',
49
+ 95: 'aui-ansi-magenta',
50
+ 96: 'aui-ansi-cyan',
51
+ };
52
+ const ANSI_ESC = String.fromCharCode(0x1b);
53
+ const ANSI_SGR_RE = new RegExp(`${ANSI_ESC}\\[([0-9;]*)m`, 'g');
54
+ /** Parse ANSI SGR escape sequences into safe styled text segments (no raw HTML injection). */
55
+ export function parseAnsiLine(line) {
56
+ const segments = [];
57
+ let bold = false;
58
+ let dim = false;
59
+ let italic = false;
60
+ let underline = false;
61
+ let fg;
62
+ const classes = () => {
63
+ const out = [];
64
+ if (bold)
65
+ out.push('aui-ansi-bold');
66
+ if (dim)
67
+ out.push('aui-ansi-dim');
68
+ if (italic)
69
+ out.push('aui-ansi-italic');
70
+ if (underline)
71
+ out.push('aui-ansi-underline');
72
+ if (fg)
73
+ out.push(fg);
74
+ return out.length > 0 ? out.join(' ') : undefined;
75
+ };
76
+ let last = 0;
77
+ for (const match of line.matchAll(ANSI_SGR_RE)) {
78
+ const idx = match.index ?? 0;
79
+ if (idx > last) {
80
+ segments.push({ text: line.slice(last, idx), className: classes() });
81
+ }
82
+ const rawCodes = match[1] ?? '0';
83
+ const codes = rawCodes === '' ? [0] : rawCodes.split(';').map((n) => Number(n));
84
+ for (const code of codes) {
85
+ if (code === 0) {
86
+ bold = false;
87
+ dim = false;
88
+ italic = false;
89
+ underline = false;
90
+ fg = undefined;
91
+ }
92
+ else if (code === 1) {
93
+ bold = true;
94
+ }
95
+ else if (code === 2) {
96
+ dim = true;
97
+ }
98
+ else if (code === 3) {
99
+ italic = true;
100
+ }
101
+ else if (code === 4) {
102
+ underline = true;
103
+ }
104
+ else if (code === 22) {
105
+ bold = false;
106
+ dim = false;
107
+ }
108
+ else if (code === 23) {
109
+ italic = false;
110
+ }
111
+ else if (code === 24) {
112
+ underline = false;
113
+ }
114
+ else if (code === 39) {
115
+ fg = undefined;
116
+ }
117
+ else if (ANSI_FG_CLASS[code]) {
118
+ fg = ANSI_FG_CLASS[code];
119
+ }
120
+ }
121
+ last = idx + match[0].length;
122
+ }
123
+ if (last < line.length) {
124
+ segments.push({ text: line.slice(last), className: classes() });
125
+ }
126
+ return segments;
127
+ }
128
+ export function TerminalOutput({ text, lines, title = 'Terminal', running = false, searchable = false, autoFollow = true, defaultWrap = true, onClear, className, }) {
129
+ const [wrap, setWrap] = useState(defaultWrap);
130
+ const [query, setQuery] = useState('');
131
+ const bodyRef = useRef(null);
132
+ const allLines = useMemo(() => {
133
+ if (lines)
134
+ return lines;
135
+ if (!text)
136
+ return [];
137
+ return text.split('\n');
138
+ }, [lines, text]);
139
+ const filteredLines = useMemo(() => {
140
+ const q = query.trim().toLowerCase();
141
+ if (!q)
142
+ return allLines;
143
+ return allLines.filter((line) => line.replace(ANSI_SGR_RE, '').toLowerCase().includes(q));
144
+ }, [allLines, query]);
145
+ useEffect(() => {
146
+ if (!autoFollow || !bodyRef.current)
147
+ return;
148
+ bodyRef.current.scrollTop = bodyRef.current.scrollHeight;
149
+ }, [autoFollow, filteredLines.length]);
150
+ return (_jsxs("section", { className: className ? `aui-terminal ${className}` : 'aui-terminal', "aria-label": title, children: [_jsxs("header", { className: "aui-terminal-head", children: [_jsxs("span", { className: "aui-terminal-title", children: [_jsx(StatusDot, { tone: running ? 'info' : 'neutral', pulse: running }), _jsx("span", { children: title }), running ? _jsx(Badge, { tone: "info", children: "Running" }) : null] }), _jsxs("div", { className: "aui-terminal-controls", children: [searchable ? (_jsx(TextField, { label: "Filter output", labelHidden: true, reserve: false, value: query, onValueChange: (next) => setQuery(next), placeholder: "Filter logs\u2026" })) : null, _jsx(Button, { size: "sm", variant: "ghost", onClick: () => setWrap((w) => !w), children: wrap ? 'No wrap' : 'Wrap' }), onClear ? (_jsx(Button, { size: "sm", variant: "ghost", onClick: onClear, children: "Clear" })) : null] })] }), _jsx("pre", { ref: bodyRef, className: "aui-terminal-body", "data-wrap": wrap ? 'true' : 'false', children: filteredLines.map((line, lineIdx) => (_jsx("div", { children: parseAnsiLine(line).map((seg, segIdx) => seg.className ? (_jsx("span", { className: seg.className, children: seg.text }, segIdx)) : (_jsx("span", { children: seg.text }, segIdx))) }, lineIdx))) })] }));
151
+ }
152
+ const DEFAULT_MODES = [
153
+ { value: 'ask', label: 'Ask' },
154
+ { value: 'plan', label: 'Plan' },
155
+ { value: 'agent', label: 'Agent' },
156
+ { value: 'review', label: 'Review' },
157
+ ];
158
+ export function ModeSwitcher({ value, onValueChange, options, ariaLabel = 'Agent mode', disabled = false, className, }) {
159
+ const resolved = (options ?? DEFAULT_MODES);
160
+ return (_jsx(SegmentedControl, { ariaLabel: ariaLabel, size: "sm", value: value, onValueChange: onValueChange, disabled: disabled, className: className, options: resolved.map((opt) => ({
161
+ value: opt.value,
162
+ label: opt.label,
163
+ ...(opt.disabled !== undefined ? { disabled: opt.disabled } : {}),
164
+ })) }));
165
+ }
166
+ export function ModelPicker({ value, onValueChange, models, ariaLabel = 'Model', placeholder = 'Select model', disabled = false, className, }) {
167
+ return (_jsx(Select, { ariaLabel: ariaLabel, size: "sm", reserve: false, value: value, onValueChange: (next) => onValueChange(next), placeholder: placeholder, disabled: disabled, className: className, options: models.map((m) => ({
168
+ value: m.id,
169
+ label: m.provider ? `${m.label} · ${m.provider}` : m.label,
170
+ ...(m.disabled !== undefined ? { disabled: m.disabled } : {}),
171
+ })) }));
172
+ }