reifyui 0.17.0 → 0.18.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/README.md +1 -1
- package/dist/agent-chat.cjs +271 -26
- package/dist/agent-chat.cjs.map +1 -1
- package/dist/agent-chat.d.ts +20 -4
- package/dist/agent-chat.js +5 -1
- package/dist/agent-chat.js.map +1 -1
- package/dist/{chunk-6HGZN2SQ.js → chunk-Y2MBOXQC.js} +269 -24
- package/dist/chunk-Y2MBOXQC.js.map +1 -0
- package/dist/index.cjs +266 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/agent-chat/components.jsx +28 -15
- package/src/agent-chat/index.d.ts +20 -4
- package/src/agent-chat/index.js +2 -2
- package/src/agent-chat/tools.js +177 -11
- package/styles/agent-chat.css +4 -0
- package/dist/chunk-6HGZN2SQ.js.map +0 -1
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reifyui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "The open-source rendering & interaction layer for agentic applications. Stream and render any agent's output as polished, application-native UI — model-agnostic, framework-agnostic, design-system-native. The foundation for building generative-UI and agent products.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// Components take one `props` object and destructure inside, so TypeScript hosts do not infer
|
|
8
8
|
// every optional slot as required (the convention of the rest of the package).
|
|
9
9
|
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
10
|
-
import { describeTool, toolLine, summarizeCalls, resultNote, parseToolArgs } from './tools.js';
|
|
10
|
+
import { describeTool, toolLine, summarizeCalls, resultNote, parseToolArgs, browserElements } from './tools.js';
|
|
11
11
|
import { liveState, segments, latestPlan } from './turn.js';
|
|
12
12
|
import { formatElapsed, formatDuration, formatTokens, useElapsed } from './time.js';
|
|
13
13
|
import { Chevron, IcTerminal, IcDoc, IcScroll, IcSearch, IcGlobe, IcSpawn, IcList, IcSkill, IcPlug, IcTool, IcThink,
|
|
@@ -246,10 +246,15 @@ function StepDetail(props) {
|
|
|
246
246
|
);
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
/**
|
|
249
|
+
/**
|
|
250
|
+
* One call: what it did, to what, how it went; click for its whole input and output. A call the host
|
|
251
|
+
* shows in a place of its own (`openStep` answers a handler for it: a browser step opens the browser
|
|
252
|
+
* beside the conversation) opens there on a click instead, the way a file card opens its file.
|
|
253
|
+
*/
|
|
250
254
|
export function StepRow(props) {
|
|
251
|
-
const { item, labels = DEFAULT_AGENT_LABELS, defaultOpen = false } = props;
|
|
252
|
-
const d = useMemo(() => describeTool(item.name, item.args), [item.name, item.args]);
|
|
255
|
+
const { item, labels = DEFAULT_AGENT_LABELS, defaultOpen = false, element = null, openStep, active = false } = props;
|
|
256
|
+
const d = useMemo(() => describeTool(item.name, item.args, { element }), [item.name, item.args, element]);
|
|
257
|
+
const opener = openStep ? openStep(item, d) || null : null;
|
|
253
258
|
const [open, setOpen] = useState(defaultOpen);
|
|
254
259
|
const uid = useRef(`uac-s-${Math.random().toString(36).slice(2, 9)}`).current;
|
|
255
260
|
const running = item.status === 'running';
|
|
@@ -260,11 +265,12 @@ export function StepRow(props) {
|
|
|
260
265
|
// split "Ran npm test" into the verb (quiet) and the target (ink), when the line is verb + target
|
|
261
266
|
const hasTarget = d.target && line === `${verb} ${d.target}`;
|
|
262
267
|
const note = !running && item.status !== 'failed' ? resultNote(d.kind, item.output) : '';
|
|
263
|
-
const hasDetail = !!(item.args && item.args !== '{}' && item.args !== '""') || item.output !== undefined;
|
|
268
|
+
const hasDetail = !opener && (!!(item.args && item.args !== '{}' && item.args !== '""') || item.output !== undefined);
|
|
264
269
|
return (
|
|
265
|
-
<div className={cls('uac-step', `is-${item.status}
|
|
270
|
+
<div className={cls('uac-step', `is-${item.status}`, opener && 'is-opens', opener && active && 'is-active')} data-kind={d.kind}>
|
|
266
271
|
<button type="button" className="uac-step-h" aria-expanded={hasDetail ? open : undefined} aria-controls={hasDetail ? uid : undefined}
|
|
267
|
-
|
|
272
|
+
aria-current={opener && active ? 'true' : undefined}
|
|
273
|
+
disabled={!opener && !hasDetail} onClick={opener || (() => setOpen((v) => !v))} title={d.targetFull || undefined}>
|
|
268
274
|
<StatusGlyph status={item.status} kind={d.kind} />
|
|
269
275
|
<span className="uac-step-t">
|
|
270
276
|
{hasTarget ? (<><span className="uac-step-v">{verb}</span> <span className={cls('uac-step-o', d.mono && 'is-mono')}>{d.target}</span></>)
|
|
@@ -276,7 +282,7 @@ export function StepRow(props) {
|
|
|
276
282
|
{item.status === 'stopped' ? <span className="uac-step-n">{labels.stoppedCall}</span> : null}
|
|
277
283
|
{running && runMs != null ? <span className="uac-step-time">{formatElapsed(runMs)}</span>
|
|
278
284
|
: tookMs != null && tookMs >= 1000 ? <span className="uac-step-time">{formatDuration(tookMs)}</span> : null}
|
|
279
|
-
{hasDetail ? <span className="uac-chev" aria-hidden="true"><Chevron dir={open ? 'down' : 'right'} size={12} /></span> : null}
|
|
285
|
+
{hasDetail || opener ? <span className="uac-chev" aria-hidden="true"><Chevron dir={open && !opener ? 'down' : 'right'} size={12} /></span> : null}
|
|
280
286
|
</button>
|
|
281
287
|
{item.status === 'failed' && item.output ? <div className="uac-step-err">{firstLine(item.output)}</div> : null}
|
|
282
288
|
{open && hasDetail ? <StepDetail item={item} d={d} labels={labels} id={uid} /> : null}
|
|
@@ -322,14 +328,15 @@ function sumDiff(tools) {
|
|
|
322
328
|
* live line, `[mark] 1m 4s · Running npm test`, and opens to the calls so far.
|
|
323
329
|
*/
|
|
324
330
|
export function WorkGroup(props) {
|
|
325
|
-
const { items, live = false, liveLabel, start = null, mark, motion, labels = DEFAULT_AGENT_LABELS, defaultOpen = false
|
|
331
|
+
const { items, live = false, liveLabel, start = null, mark, motion, labels = DEFAULT_AGENT_LABELS, defaultOpen = false,
|
|
332
|
+
elements = null, openStep, activeStep = null } = props;
|
|
326
333
|
const [open, setOpen] = useState(defaultOpen);
|
|
327
334
|
const uid = useRef(`uac-g-${Math.random().toString(36).slice(2, 9)}`).current;
|
|
328
335
|
const tools = items.filter((x) => x.kind === 'tool');
|
|
329
336
|
const thoughts = items.filter((x) => x.kind === 'thinking');
|
|
330
337
|
const failed = tools.filter((x) => x.status === 'failed').length;
|
|
331
338
|
let summary = '';
|
|
332
|
-
if (tools.length) summary = summarizeCalls(tools);
|
|
339
|
+
if (tools.length) summary = summarizeCalls(elements ? tools.map((t) => ({ name: t.name, args: t.args, element: elements[t.id] })) : tools);
|
|
333
340
|
else if (thoughts.length) {
|
|
334
341
|
const t = thoughts[0];
|
|
335
342
|
const ms = t.startedAt != null && t.endedAt != null ? t.endedAt - t.startedAt : null;
|
|
@@ -341,7 +348,8 @@ export function WorkGroup(props) {
|
|
|
341
348
|
const body = open ? (
|
|
342
349
|
<div className="uac-calls" id={uid}>
|
|
343
350
|
{items.map((it) => (it.kind === 'tool'
|
|
344
|
-
? <StepRow key={it.id} item={it} labels={labels}
|
|
351
|
+
? <StepRow key={it.id} item={it} labels={labels} element={elements ? elements[it.id] || null : null}
|
|
352
|
+
openStep={openStep} active={activeStep != null && activeStep === it.id} />
|
|
345
353
|
: <ThinkingRow key={it.id} item={it} labels={labels} />))}
|
|
346
354
|
</div>
|
|
347
355
|
) : null;
|
|
@@ -496,9 +504,12 @@ export function TurnOutcome(props) {
|
|
|
496
504
|
export function AgentTurnView(props) {
|
|
497
505
|
const {
|
|
498
506
|
turn, renderMarkdown, mark, motion, labels: labelsIn, showUser = true, renderUserFile, userExtra,
|
|
499
|
-
meta, renderFiles, actions, describeIncomplete, liveStart,
|
|
507
|
+
meta, renderFiles, actions, describeIncomplete, liveStart, openStep, activeStep = null,
|
|
500
508
|
} = props;
|
|
501
509
|
const labels = useMemo(() => ({ ...DEFAULT_AGENT_LABELS, ...(labelsIn || {}) }), [labelsIn]);
|
|
510
|
+
// what each browser call acted on, read from the page snapshots before it in this turn
|
|
511
|
+
const items = turn ? turn.items : null;
|
|
512
|
+
const elements = useMemo(() => browserElements(items), [items]);
|
|
502
513
|
if (!turn) return null;
|
|
503
514
|
const running = turn.status === 'running';
|
|
504
515
|
const segs = segments(turn);
|
|
@@ -509,7 +520,7 @@ export function AgentTurnView(props) {
|
|
|
509
520
|
const liveWork = running && lastSeg && lastSeg.type === 'work';
|
|
510
521
|
let liveLabel = labels.thinking;
|
|
511
522
|
if (now) {
|
|
512
|
-
if (now.phase === 'tool' && now.tool) liveLabel = toolLine(describeTool(now.tool.name, now.tool.args), 'running');
|
|
523
|
+
if (now.phase === 'tool' && now.tool) liveLabel = toolLine(describeTool(now.tool.name, now.tool.args, { element: elements[now.tool.id] }), 'running');
|
|
513
524
|
else if (now.phase === 'writing') liveLabel = labels.writing;
|
|
514
525
|
else if (now.phase === 'starting') liveLabel = labels.starting;
|
|
515
526
|
}
|
|
@@ -526,7 +537,8 @@ export function AgentTurnView(props) {
|
|
|
526
537
|
return (
|
|
527
538
|
<React.Fragment key={`w${i}`}>
|
|
528
539
|
{plan ? <TodoCard todos={plan} labels={labels} running /> : null}
|
|
529
|
-
<WorkGroup items={s.items} live liveLabel={liveLabel} start={start} mark={mark} motion={motion} labels={labels}
|
|
540
|
+
<WorkGroup items={s.items} live liveLabel={liveLabel} start={start} mark={mark} motion={motion} labels={labels}
|
|
541
|
+
elements={elements} openStep={openStep} activeStep={activeStep} />
|
|
530
542
|
</React.Fragment>
|
|
531
543
|
);
|
|
532
544
|
}
|
|
@@ -534,7 +546,8 @@ export function AgentTurnView(props) {
|
|
|
534
546
|
return <StreamingText key={s.item.id || `t${i}`} text={s.item.text} render={renderMarkdown}
|
|
535
547
|
active={running && i === lastTextIdx && i === segs.length - 1} />;
|
|
536
548
|
}
|
|
537
|
-
return <WorkGroup key={`w${i}-${s.items[0] && s.items[0].id}`} items={s.items} labels={labels}
|
|
549
|
+
return <WorkGroup key={`w${i}-${s.items[0] && s.items[0].id}`} items={s.items} labels={labels}
|
|
550
|
+
elements={elements} openStep={openStep} activeStep={activeStep} />;
|
|
538
551
|
})}
|
|
539
552
|
{!liveWork && plan ? <TodoCard todos={plan} labels={labels} running={running} /> : null}
|
|
540
553
|
{running && !liveWork ? <WorkingIndicator mark={mark} motion={motion} start={start} label={liveLabel} /> : null}
|
|
@@ -65,10 +65,18 @@ export interface ToolDescription {
|
|
|
65
65
|
diff: { added: number; removed: number } | null;
|
|
66
66
|
todos: TodoEntry[] | null;
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
/** The element a browser call acts on, as a page snapshot named its ref. */
|
|
69
|
+
export interface BrowserElement { role: string; name: string }
|
|
70
|
+
/** `opts.element`: for a browser call, the element its ref names (from browserElements). */
|
|
71
|
+
export function describeTool(name: string, args: unknown, opts?: { element?: BrowserElement | null }): ToolDescription;
|
|
69
72
|
export function toolKind(name: string): ToolKind;
|
|
70
73
|
export function toolLine(d: ToolDescription, state: 'running' | 'done'): string;
|
|
71
|
-
export function summarizeCalls(calls: { name: string; args?: unknown }[]): string;
|
|
74
|
+
export function summarizeCalls(calls: { name: string; args?: unknown; element?: BrowserElement | null }[]): string;
|
|
75
|
+
/** The action a browser tool's name carries ("click" for mcp__plugs__browser_click), '' when the action
|
|
76
|
+
* is an argument (`browser`, `computer`), null when the tool is not a browser's. */
|
|
77
|
+
export function browserActOf(name: string): string | null;
|
|
78
|
+
/** {[call id]: element} for the browser calls whose ref an earlier snapshot in the same turn named. */
|
|
79
|
+
export function browserElements(items: TurnItem[] | null | undefined): Record<string, BrowserElement>;
|
|
72
80
|
export function resultNote(kind: ToolKind, output: unknown): string;
|
|
73
81
|
export function parseToolArgs(args: unknown): Record<string, unknown>;
|
|
74
82
|
export function todosOf(args: Record<string, unknown>): TodoEntry[] | null;
|
|
@@ -110,10 +118,14 @@ export function WorkingIndicator(props: MarkProps & {
|
|
|
110
118
|
export function CopyButton(props: { text: string; labels?: AgentLabels; label?: string }): ReactElement;
|
|
111
119
|
export function DiffBadge(props: { diff: { added: number; removed: number } | null }): ReactElement | null;
|
|
112
120
|
export function LinesBlock(props: { lines: { text: string; cls?: string }[]; limit?: number; labels?: AgentLabels; className?: string; numbered?: boolean }): ReactElement;
|
|
113
|
-
|
|
121
|
+
/** A call the host shows in a place of its own: a handler for the calls it opens (a browser step opens
|
|
122
|
+
* the browser beside the conversation), null for the rest, which unfold to their input and output. */
|
|
123
|
+
export type OpenStep = (item: ToolItem, d: ToolDescription) => (() => void) | null | undefined;
|
|
124
|
+
export function StepRow(props: { item: ToolItem; labels?: AgentLabels; defaultOpen?: boolean; element?: BrowserElement | null;
|
|
125
|
+
openStep?: OpenStep; active?: boolean }): ReactElement;
|
|
114
126
|
export function ThinkingRow(props: { item: ThinkingItem; labels?: AgentLabels }): ReactElement;
|
|
115
127
|
export function WorkGroup(props: MarkProps & { items: (ToolItem | ThinkingItem)[]; live?: boolean; liveLabel?: string; start?: number | null;
|
|
116
|
-
labels?: AgentLabels; defaultOpen?: boolean }): ReactElement | null;
|
|
128
|
+
labels?: AgentLabels; defaultOpen?: boolean; elements?: Record<string, BrowserElement> | null; openStep?: OpenStep; activeStep?: string | null }): ReactElement | null;
|
|
117
129
|
export function TodoCard(props: { todos: TodoEntry[] | null; labels?: AgentLabels; running?: boolean }): ReactElement | null;
|
|
118
130
|
export function StreamingText(props: { text: string; active?: boolean; render?: (text: string) => ReactNode }): ReactElement;
|
|
119
131
|
export function UserBubble(props: { user: TurnUser | null; renderFile?: (f: { name: string; src?: string }, i: number) => ReactNode; extra?: ReactNode }): ReactElement | null;
|
|
@@ -136,6 +148,10 @@ export interface AgentTurnViewProps extends MarkProps {
|
|
|
136
148
|
describeIncomplete?: (i: { reason?: string; detail?: string }) => string;
|
|
137
149
|
/** the epoch ms the live clock counts from, when it is not the turn's own startedAt */
|
|
138
150
|
liveStart?: number | null;
|
|
151
|
+
/** calls the host opens in a place of its own (a browser step opens the browser), instead of unfolding */
|
|
152
|
+
openStep?: OpenStep;
|
|
153
|
+
/** the id of the call the host is showing now: its row stays marked */
|
|
154
|
+
activeStep?: string | null;
|
|
139
155
|
}
|
|
140
156
|
export function AgentTurnView(props: AgentTurnViewProps): ReactElement | null;
|
|
141
157
|
|
package/src/agent-chat/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// the data newTurn, reduceTurn, finish, turnFromEvents, turnFromResponse, turnFromHistory,
|
|
4
4
|
// turnFromMessage, liveState, segments, latestPlan, isTerminal
|
|
5
5
|
// the words describeTool, toolKind, toolLine, summarizeCalls, resultNote, parseToolArgs,
|
|
6
|
-
// todosOf, diffOf, patchStats, commandText
|
|
6
|
+
// todosOf, diffOf, patchStats, commandText, browserActOf, browserElements
|
|
7
7
|
// the clocks formatElapsed, formatDuration, formatTokens, useElapsed, useNow
|
|
8
8
|
// the marks MARK_MOTIONS, MOTIONS, motionFor
|
|
9
9
|
// the views AgentConversation, AgentTurnView, WorkGroup, StepRow, ThinkingRow, TodoCard,
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
export { newTurn, reduceTurn, finish, turnFromEvents, turnFromResponse, turnFromHistory, turnFromMessage,
|
|
18
18
|
liveState, segments, latestPlan, isTerminal } from './turn.js';
|
|
19
19
|
export { describeTool, toolKind, toolLine, summarizeCalls, resultNote, parseToolArgs, todosOf, diffOf, patchStats,
|
|
20
|
-
commandText, baseNameOf, lineCount } from './tools.js';
|
|
20
|
+
commandText, baseNameOf, lineCount, browserActOf, browserElements } from './tools.js';
|
|
21
21
|
export { formatElapsed, formatDuration, formatTokens, useElapsed, useNow } from './time.js';
|
|
22
22
|
export { MARK_MOTIONS, MOTIONS, motionFor } from './marks.js';
|
|
23
23
|
export { AgentConversation, AgentTurnView, WorkGroup, StepRow, ThinkingRow, TodoCard, WorkingIndicator, WorkingMark,
|
package/src/agent-chat/tools.js
CHANGED
|
@@ -57,6 +57,8 @@ const NS = /^(developer|platform|computercontroller|builtin|default|functions|to
|
|
|
57
57
|
export function toolKind(name) {
|
|
58
58
|
const raw = String(name || '').trim();
|
|
59
59
|
if (!raw) return 'tool';
|
|
60
|
+
// a browser's tools read as the browser whichever server carries them (mcp__plugs__browser_click)
|
|
61
|
+
if (browserActOf(raw) !== null) return 'browser';
|
|
60
62
|
if (/^mcp__/i.test(raw)) return 'mcp';
|
|
61
63
|
const n = raw.toLowerCase().replace(NS, '');
|
|
62
64
|
if (KIND_BY_NAME[n]) return KIND_BY_NAME[n];
|
|
@@ -197,6 +199,168 @@ function humanizeName(n) {
|
|
|
197
199
|
.replace(/([a-z])([A-Z])/g, '$1 $2').trim().replace(/^\w/, (c) => c.toUpperCase());
|
|
198
200
|
}
|
|
199
201
|
|
|
202
|
+
// ── the browser ───────────────────────────────────────────────────────────────────────────────────
|
|
203
|
+
// A browser call reads as what it did: "Opened duckduckgo.com", "Clicked the “About” link", "Typed
|
|
204
|
+
// into a field", "Took a screenshot". One table for every vocabulary: a browser plug's tools
|
|
205
|
+
// (browser_navigate, browser_click), Playwright MCP's (browser_take_screenshot, browser_navigate_back),
|
|
206
|
+
// a connected server's copy of either (mcp__plugs__browser_click, plugs.browser_click,
|
|
207
|
+
// plugs__browser_click), and one browser or computer tool that takes an `action`. What was typed is
|
|
208
|
+
// never in the line (it may be a password); the call's input shows it to whoever opens it.
|
|
209
|
+
|
|
210
|
+
// a browser tool inside a connected server's namespace, and a server that is itself a browser
|
|
211
|
+
const NS_BROWSER = /^(?:mcp__.+?__|[a-z0-9_-]+?(?:__|\.))(browser[_\-.].+)$/i;
|
|
212
|
+
const BROWSER_SERVER = /^(?:mcp__)?(?:browser|playwright|puppeteer|browserbase|browser[_-]use|chrome[_-]?devtools)(?:__|\.)(.+)$/i;
|
|
213
|
+
|
|
214
|
+
/** The action a browser tool's name carries ("click" for mcp__plugs__browser_click), '' for a browser
|
|
215
|
+
* tool whose name carries none (`browser`, `computer`: the action is an argument), null for a tool
|
|
216
|
+
* that is not a browser's. */
|
|
217
|
+
export function browserActOf(name) {
|
|
218
|
+
const raw = String(name || '').trim();
|
|
219
|
+
if (!raw) return null;
|
|
220
|
+
const n = raw.toLowerCase().replace(NS, '');
|
|
221
|
+
if (KIND_BY_NAME[n] === 'browser') return n === 'navigate' || n === 'screenshot' ? n : '';
|
|
222
|
+
let m = n.match(/^(?:browser|playwright|computer)[_\-.](.+)$/);
|
|
223
|
+
if (m) return m[1];
|
|
224
|
+
m = raw.match(NS_BROWSER);
|
|
225
|
+
if (m) return m[1].replace(/^browser[_\-.]/i, '').toLowerCase();
|
|
226
|
+
m = raw.match(BROWSER_SERVER);
|
|
227
|
+
if (m) return m[1].replace(/^browser[_\-.]/i, '').toLowerCase();
|
|
228
|
+
if (/[_\-.]browser$/.test(n)) return '';
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const ROLE_NOUN = { link: 'link', button: 'button', submit: 'button', textbox: 'field', searchbox: 'search field',
|
|
233
|
+
combobox: 'list', listbox: 'list', checkbox: 'checkbox', radio: 'option', option: 'option', tab: 'tab',
|
|
234
|
+
menuitem: 'menu item', heading: 'heading', img: 'image', image: 'image', switch: 'switch', slider: 'slider' };
|
|
235
|
+
|
|
236
|
+
function cut(s, max) { const t = str(s).replace(/\s+/g, ' ').trim(); return t.length > max ? `${t.slice(0, max - 1).trimEnd()}…` : t; }
|
|
237
|
+
|
|
238
|
+
/** The element a call acts on, in words: the host's description of it, the snapshot's line for its
|
|
239
|
+
* ref (`element`, from browserElements), or what its selector says it is; '' when nothing says. */
|
|
240
|
+
function elementWords(a, element, act) {
|
|
241
|
+
const desc = str(firstOf(a, ['element', 'element_description', 'description', 'label'])).trim();
|
|
242
|
+
if (desc) return cut(desc, 60);
|
|
243
|
+
if (element && element.role) {
|
|
244
|
+
const noun = ROLE_NOUN[String(element.role).toLowerCase()] || '';
|
|
245
|
+
const name = cut(element.name, 40);
|
|
246
|
+
if (noun && name) return `the “${name}” ${noun}`;
|
|
247
|
+
if (noun) return `a ${noun}`;
|
|
248
|
+
if (name) return `“${name}”`;
|
|
249
|
+
}
|
|
250
|
+
const sel = str(a.selector).trim().toLowerCase();
|
|
251
|
+
if (sel) {
|
|
252
|
+
if (/^a(?=$|[\s.#[:>])|role=["']?link/.test(sel)) return 'a link';
|
|
253
|
+
if (/^button|\[type=["']?submit|role=["']?button/.test(sel)) return 'a button';
|
|
254
|
+
if (/^(input|textarea)|role=["']?(textbox|searchbox)|contenteditable/.test(sel)) return 'a field';
|
|
255
|
+
if (/^select|role=["']?(combobox|listbox)/.test(sel)) return 'a list';
|
|
256
|
+
}
|
|
257
|
+
// a click by its text (some tools find the element that way); typed text is never named
|
|
258
|
+
if (act === 'click') { const t = str(a.text).trim(); if (t) return `“${cut(t, 40)}”`; }
|
|
259
|
+
return '';
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function msWords(ms) { const s = Math.round(Number(ms) / 100) / 10; return s >= 1 ? `${s}s` : `${Math.round(Number(ms))} ms`; }
|
|
263
|
+
|
|
264
|
+
// [actions, running, done, target(args, element, act) -> string, [running, done] when there is no target]
|
|
265
|
+
const BROWSER_ACTS = [
|
|
266
|
+
[/^(navigate|goto|go_to|open|open_url|visit|new_tab|tab_new|browse|go)$/, 'Opening', 'Opened',
|
|
267
|
+
(a) => { const u = str(firstOf(a, ['url', 'href', 'uri', 'link', 'address'])); return u ? shortUrl(u) : ''; }, ['Opening a page', 'Opened a page']],
|
|
268
|
+
[/^(navigate_back|back|go_back|history_back)$/, '', '', null, ['Going back a page', 'Went back a page']],
|
|
269
|
+
[/^(navigate_forward|forward|go_forward)$/, '', '', null, ['Going forward a page', 'Went forward a page']],
|
|
270
|
+
[/^(reload|refresh)$/, '', '', null, ['Reloading the page', 'Reloaded the page']],
|
|
271
|
+
[/^(click|left_click|double_click|right_click|triple_click|middle_click|tap|click_element)$/, 'Clicking', 'Clicked',
|
|
272
|
+
(a, e, act) => elementWords(a, e, act), ['Clicking on the page', 'Clicked on the page']],
|
|
273
|
+
[/^(hover|mouse_move|move_mouse)$/, 'Pointing at', 'Pointed at', (a, e, act) => elementWords(a, e, act), ['Moving the pointer', 'Moved the pointer']],
|
|
274
|
+
[/^(type|fill|input|input_text|type_text|insert_text|fill_form|send_keys_to)$/, 'Typing into', 'Typed into',
|
|
275
|
+
(a, e, act) => elementWords(a, e, act), ['Typing into a field', 'Typed into a field']],
|
|
276
|
+
[/^(select|select_option|choose|select_dropdown_option)$/, 'Choosing an option in', 'Chose an option in',
|
|
277
|
+
(a, e, act) => elementWords(a, e, act), ['Choosing an option', 'Chose an option']],
|
|
278
|
+
[/^(press|press_key|key|keypress|send_keys|hotkey)$/, 'Pressing', 'Pressed',
|
|
279
|
+
(a) => cut(firstOf(a, ['key', 'keys', 'text']), 30), ['Pressing a key', 'Pressed a key']],
|
|
280
|
+
[/^(scroll|scroll_down|scroll_up|wheel|scroll_page)$/, 'Scrolling', 'Scrolled', (a, e, act) => {
|
|
281
|
+
const d = str(firstOf(a, ['direction', 'scroll_direction'])).toLowerCase();
|
|
282
|
+
if (/^(up|down|left|right)$/.test(d)) return d;
|
|
283
|
+
if (/_up$/.test(act)) return 'up';
|
|
284
|
+
if (/_down$/.test(act)) return 'down';
|
|
285
|
+
const dy = Number(firstOf(a, ['pixels', 'delta_y', 'deltaY', 'amount', 'scroll_amount']));
|
|
286
|
+
return Number.isFinite(dy) && dy < 0 ? 'up' : Number.isFinite(dy) && dy > 0 ? 'down' : '';
|
|
287
|
+
}, ['Scrolling the page', 'Scrolled the page']],
|
|
288
|
+
[/^(screenshot|take_screenshot|capture|capture_screenshot)$/, '', '', null, ['Taking a screenshot', 'Took a screenshot'],
|
|
289
|
+
(a) => (a.full_page || a.fullPage ? ['Taking a screenshot of the whole page', 'Took a screenshot of the whole page'] : null)],
|
|
290
|
+
[/^(snapshot|read|read_page|get_page|accessibility_snapshot|page_content|get_content|get_elements|observe)$/, '', '', null, ['Reading the page', 'Read the page']],
|
|
291
|
+
[/^(extract_text|get_text|extract|text|extract_content|get_page_text)$/, '', '', null, ['Reading the page’s text', 'Read the page’s text']],
|
|
292
|
+
[/^(get_url|url|current_url|location|get_title)$/, '', '', null, ['Checking the address', 'Checked the address']],
|
|
293
|
+
[/^(wait|wait_for|wait_for_text|wait_for_selector|sleep)$/, 'Waiting', 'Waited', (a) => {
|
|
294
|
+
const t = str(a.text).trim();
|
|
295
|
+
if (t) return `for “${cut(t, 40)}”`;
|
|
296
|
+
if (str(a.selector).trim()) return 'for the page';
|
|
297
|
+
// milliseconds (the browser plug's `ms`), or seconds (Playwright MCP's `time`)
|
|
298
|
+
const ms = a.ms != null ? Number(a.ms) : a.time != null ? Number(a.time) * 1000 : Number(firstOf(a, ['timeout', 'duration']));
|
|
299
|
+
return Number.isFinite(ms) && ms > 0 ? msWords(ms) : '';
|
|
300
|
+
}, ['Waiting', 'Waited']],
|
|
301
|
+
[/^(tabs|list_tabs|tab_list|get_tabs)$/, '', '', null, ['Listing the tabs', 'Listed the tabs']],
|
|
302
|
+
[/^(switch_tab|tab_select|select_tab|focus_tab|switch_to_tab)$/, '', '', null, ['Switching tabs', 'Switched tabs']],
|
|
303
|
+
[/^(close_tab|tab_close)$/, '', '', null, ['Closing a tab', 'Closed a tab']],
|
|
304
|
+
[/^(close|quit|close_browser)$/, '', '', null, ['Closing the browser', 'Closed the browser']],
|
|
305
|
+
[/^(drag|drag_and_drop|left_click_drag)$/, '', '', null, ['Dragging on the page', 'Dragged on the page']],
|
|
306
|
+
[/^(file_upload|upload|upload_file|set_input_files)$/, '', '', null, ['Uploading a file', 'Uploaded a file']],
|
|
307
|
+
[/^(handle_dialog|dialog|accept_dialog|dismiss_dialog)$/, '', '', null, ['Answering a dialog', 'Answered a dialog']],
|
|
308
|
+
[/^(resize|set_viewport|resize_window)$/, '', '', null, ['Resizing the window', 'Resized the window']],
|
|
309
|
+
[/^(evaluate|run_code|execute_js|eval|execute_script|run_javascript)$/, '', '', null, ['Running a script on the page', 'Ran a script on the page']],
|
|
310
|
+
[/^(console_messages|console|get_console)$/, '', '', null, ['Reading the console', 'Read the console']],
|
|
311
|
+
[/^(network_requests|network|get_network)$/, '', '', null, ['Reading the network requests', 'Read the network requests']],
|
|
312
|
+
[/^(pdf_save|save_pdf|pdf|print_pdf)$/, '', '', null, ['Saving the page as a PDF', 'Saved the page as a PDF']],
|
|
313
|
+
[/^(cursor_position)$/, '', '', null, ['Finding the pointer', 'Found the pointer']],
|
|
314
|
+
[/^(install)$/, '', '', null, ['Installing the browser', 'Installed the browser']],
|
|
315
|
+
];
|
|
316
|
+
|
|
317
|
+
/** A browser call in words: {running, done, target}. `element` is the snapshot's line for the call's
|
|
318
|
+
* ref ({role, name}, from browserElements), when the host has it. Never "a tool". */
|
|
319
|
+
function describeBrowser(name, a, element) {
|
|
320
|
+
const fromName = browserActOf(name) || '';
|
|
321
|
+
const fromArgs = str(firstOf(a, ['action', 'command', 'type'])).trim();
|
|
322
|
+
const act = (fromName && fromName !== 'use' ? fromName : fromArgs || fromName).toLowerCase().replace(/[\s-]+/g, '_');
|
|
323
|
+
const row = BROWSER_ACTS.find((r) => r[0].test(act));
|
|
324
|
+
if (row) {
|
|
325
|
+
const [, running, done, target, bare, special] = row;
|
|
326
|
+
const sp = special ? special(a) : null;
|
|
327
|
+
if (sp) return { running: sp[0], done: sp[1], target: '' };
|
|
328
|
+
const t = target ? target(a, element, act) : '';
|
|
329
|
+
return t ? { running, done, target: t } : { running: bare[0], done: bare[1], target: '' };
|
|
330
|
+
}
|
|
331
|
+
// an action this table does not know: where it went when it says, else the browser plainly
|
|
332
|
+
const u = str(firstOf(a, ['url', 'href', 'uri']));
|
|
333
|
+
return u ? { running: 'Browsing', done: 'Browsed', target: shortUrl(u) } : { running: 'Using the browser', done: 'Used the browser', target: '' };
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* The element each browser call acted on, from the page snapshots earlier in the same turn: the
|
|
338
|
+
* browser plug's lines (`e12 link "About"`) and Playwright MCP's (`- link "About" [ref=e12]`). A
|
|
339
|
+
* snapshot numbers its refs afresh, so a call's ref is read against the latest one before it.
|
|
340
|
+
* Returns {[call id]: {role, name}} for the calls whose ref a snapshot named.
|
|
341
|
+
*/
|
|
342
|
+
export function browserElements(items) {
|
|
343
|
+
const out = {};
|
|
344
|
+
let refs = new Map();
|
|
345
|
+
for (const it of items || []) {
|
|
346
|
+
if (!it || it.kind !== 'tool' || toolKind(it.name) !== 'browser') continue;
|
|
347
|
+
const a = parseToolArgs(it.args);
|
|
348
|
+
const ref = str(firstOf(a, ['ref', 'element_ref'])).trim();
|
|
349
|
+
if (ref && refs.has(ref)) out[it.id] = refs.get(ref);
|
|
350
|
+
const text = str(it.output);
|
|
351
|
+
if (!text) continue;
|
|
352
|
+
const next = new Map();
|
|
353
|
+
for (const ln of text.split('\n')) {
|
|
354
|
+
let m = ln.match(/^\s*(e\d+)\s+([a-z]+)\s+"(.*?)"/i);
|
|
355
|
+
if (m) { next.set(m[1], { role: m[2], name: m[3] }); continue; }
|
|
356
|
+
m = ln.match(/^\s*-\s+([a-z]+)(?:\s+"(.*?)")?[^\n]*\[ref=(e\d+)\]/i);
|
|
357
|
+
if (m) next.set(m[3], { role: m[1], name: m[2] || '' });
|
|
358
|
+
}
|
|
359
|
+
if (next.size) refs = next;
|
|
360
|
+
}
|
|
361
|
+
return out;
|
|
362
|
+
}
|
|
363
|
+
|
|
200
364
|
// [running, done] verbs per kind. The target follows the verb.
|
|
201
365
|
const VERBS = {
|
|
202
366
|
shell: ['Running', 'Ran'], shell_output: ['Reading output of', 'Read output of'],
|
|
@@ -219,15 +383,16 @@ const VERBS = {
|
|
|
219
383
|
* todos, [{text, status}] | null
|
|
220
384
|
* note, a secondary label (an agent's type, a skill)
|
|
221
385
|
* }
|
|
386
|
+
* opts.element: for a browser call, the element its ref names ({role, name}, from browserElements).
|
|
222
387
|
*/
|
|
223
|
-
export function describeTool(name, args) {
|
|
388
|
+
export function describeTool(name, args, opts) {
|
|
224
389
|
const a = parseToolArgs(args);
|
|
225
390
|
let kind = toolKind(name);
|
|
226
391
|
const nm = str(name);
|
|
227
392
|
// One editor tool, several acts (Anthropic's str_replace_editor, Goose's text_editor).
|
|
228
393
|
if (kind === 'edit' && /^(view|read)$/i.test(str(a.command))) kind = 'read';
|
|
229
394
|
if (kind === 'edit' && /^(create|write)$/i.test(str(a.command))) kind = 'write';
|
|
230
|
-
let target = ''; let targetFull = ''; let mono = false; let note = '';
|
|
395
|
+
let target = ''; let targetFull = ''; let mono = false; let note = ''; let browser = null;
|
|
231
396
|
const pathOf = () => firstOf(a, ['file_path', 'path', 'filePath', 'absolute_path', 'target_file', 'filename',
|
|
232
397
|
'file', 'notebook_path', 'paths', 'absolute_paths', 'dir_path', 'directory']);
|
|
233
398
|
switch (kind) {
|
|
@@ -273,11 +438,9 @@ export function describeTool(name, args) {
|
|
|
273
438
|
break;
|
|
274
439
|
case 'skill': target = str(firstOf(a, ['skill', 'name', 'command', 'skill_name'])); mono = true; targetFull = target; break;
|
|
275
440
|
case 'browser': {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
targetFull = target;
|
|
280
|
-
if (/^browser[_\-.]/i.test(nm)) note = humanizeName(nm.replace(/^browser[_\-.]/i, ''));
|
|
441
|
+
browser = describeBrowser(nm, a, opts && opts.element);
|
|
442
|
+
target = browser.target;
|
|
443
|
+
targetFull = str(firstOf(a, ['url', 'href', 'uri'])) || target;
|
|
281
444
|
break;
|
|
282
445
|
}
|
|
283
446
|
case 'mcp': case 'tool': {
|
|
@@ -287,7 +450,7 @@ export function describeTool(name, args) {
|
|
|
287
450
|
}
|
|
288
451
|
default: break;
|
|
289
452
|
}
|
|
290
|
-
const v = VERBS[kind] || VERBS.tool;
|
|
453
|
+
const v = browser ? [browser.running, browser.done] : VERBS[kind] || VERBS.tool;
|
|
291
454
|
return {
|
|
292
455
|
kind, target: target.replace(/\s+/g, ' ').trim(), targetFull, mono, note,
|
|
293
456
|
running: v[0], done: v[1],
|
|
@@ -302,7 +465,10 @@ export function toolLine(d, state) {
|
|
|
302
465
|
if (d.kind === 'todo' || d.kind === 'toolsearch' || d.kind === 'think') return verb;
|
|
303
466
|
if (d.kind === 'shell' && d.target && !d.mono) return d.target; // the agent's own description
|
|
304
467
|
if (d.kind === 'mcp' || d.kind === 'tool') return `${verb} ${d.target || 'a tool'}`;
|
|
305
|
-
|
|
468
|
+
if (d.target) return `${verb} ${d.target}`;
|
|
469
|
+
// no target: the kind's own noun, else the verb alone (a browser's verbs are whole phrases)
|
|
470
|
+
const noun = KIND_NOUN[d.kind];
|
|
471
|
+
return noun ? `${verb} ${noun}` : verb.replace(/\s+(for|of)$/, '');
|
|
306
472
|
}
|
|
307
473
|
const KIND_NOUN = { shell: 'a command', read: 'a file', write: 'a file', edit: 'a file', search: 'code', glob: 'files',
|
|
308
474
|
list: 'a folder', web_search: '', web_fetch: 'a page', agent: '', skill: 'a skill', browser: '', shell_output: 'a command' };
|
|
@@ -331,12 +497,12 @@ const PHRASES = {
|
|
|
331
497
|
|
|
332
498
|
/**
|
|
333
499
|
* One past-tense line for a run of finished calls: "Ran 3 commands, edited app.ts".
|
|
334
|
-
* A single call reads as itself ("Read app.ts"). `calls` are [{name, args}].
|
|
500
|
+
* A single call reads as itself ("Read app.ts"). `calls` are [{name, args, element?}].
|
|
335
501
|
*/
|
|
336
502
|
export function summarizeCalls(calls) {
|
|
337
503
|
const list = (calls || []).filter(Boolean);
|
|
338
504
|
if (!list.length) return '';
|
|
339
|
-
if (list.length === 1) return toolLine(describeTool(list[0].name, list[0].args), 'done');
|
|
505
|
+
if (list.length === 1) return toolLine(describeTool(list[0].name, list[0].args, { element: list[0].element }), 'done');
|
|
340
506
|
const order = []; const count = {};
|
|
341
507
|
for (const c of list) {
|
|
342
508
|
let k = toolKind(c.name);
|
package/styles/agent-chat.css
CHANGED
|
@@ -193,6 +193,10 @@
|
|
|
193
193
|
.uac-step-time { flex: none; font-size: 12px; color: var(--_faint); font-variant-numeric: tabular-nums; }
|
|
194
194
|
.uac-step.is-failed .uac-step-o, .uac-step.is-failed .uac-step-v { color: var(--_fail); }
|
|
195
195
|
.uac-step-err { margin: -2px 0 0; padding: 0 12px 9px 36px; font-family: var(--_mono); font-size: 12px; color: var(--_fail); overflow-wrap: anywhere; }
|
|
196
|
+
/* a call the host opens in a place of its own (openStep): the one it is showing now stays marked */
|
|
197
|
+
.uac-step.is-active > .uac-step-h { background: var(--_hover); }
|
|
198
|
+
.uac-step.is-active .uac-step-v { color: var(--_ink-2); }
|
|
199
|
+
.uac-step.is-active .uac-kind { color: var(--_brand); }
|
|
196
200
|
.uac-kind, .uac-x, .uac-ring, .uac-stopped { flex: none; width: 16px; height: 16px; display: grid; place-items: center; }
|
|
197
201
|
.uac-kind { color: var(--_faint); }
|
|
198
202
|
.uac-kind svg { width: 14px; height: 14px; }
|