reifyui 0.13.9 → 0.15.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,2046 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/agent-chat/index.js
30
+ var agent_chat_exports = {};
31
+ __export(agent_chat_exports, {
32
+ AgentComposer: () => AgentComposer,
33
+ AgentConversation: () => AgentConversation,
34
+ AgentTurnView: () => AgentTurnView,
35
+ CopyButton: () => CopyButton,
36
+ DEFAULT_AGENT_LABELS: () => DEFAULT_AGENT_LABELS,
37
+ DiffBadge: () => DiffBadge,
38
+ LinesBlock: () => LinesBlock,
39
+ MARK_MOTIONS: () => MARK_MOTIONS,
40
+ MOTIONS: () => MOTIONS,
41
+ StepRow: () => StepRow,
42
+ StreamingText: () => StreamingText,
43
+ ThinkingRow: () => ThinkingRow,
44
+ TodoCard: () => TodoCard,
45
+ TurnOutcome: () => TurnOutcome,
46
+ UserBubble: () => UserBubble,
47
+ WorkGroup: () => WorkGroup,
48
+ WorkingIndicator: () => WorkingIndicator,
49
+ WorkingMark: () => WorkingMark,
50
+ baseNameOf: () => baseNameOf,
51
+ commandText: () => commandText,
52
+ describeTool: () => describeTool,
53
+ diffOf: () => diffOf,
54
+ finish: () => finish,
55
+ formatDuration: () => formatDuration,
56
+ formatElapsed: () => formatElapsed,
57
+ formatTokens: () => formatTokens,
58
+ isTerminal: () => isTerminal,
59
+ latestPlan: () => latestPlan,
60
+ lineCount: () => lineCount,
61
+ liveState: () => liveState,
62
+ motionFor: () => motionFor,
63
+ newTurn: () => newTurn,
64
+ parseToolArgs: () => parseToolArgs,
65
+ patchStats: () => patchStats,
66
+ reduceTurn: () => reduceTurn,
67
+ resultNote: () => resultNote,
68
+ segments: () => segments,
69
+ summarizeCalls: () => summarizeCalls,
70
+ todosOf: () => todosOf,
71
+ toolKind: () => toolKind,
72
+ toolLine: () => toolLine,
73
+ turnFromEvents: () => turnFromEvents,
74
+ turnFromHistory: () => turnFromHistory,
75
+ turnFromMessage: () => turnFromMessage,
76
+ turnFromResponse: () => turnFromResponse,
77
+ useElapsed: () => useElapsed,
78
+ useNow: () => useNow,
79
+ useStickToBottom: () => useStickToBottom
80
+ });
81
+ module.exports = __toCommonJS(agent_chat_exports);
82
+
83
+ // src/agent-chat/tools.js
84
+ function parseToolArgs(args) {
85
+ if (args && typeof args === "object") return args;
86
+ if (typeof args !== "string" || !args.trim()) return {};
87
+ try {
88
+ const v = JSON.parse(args);
89
+ return v && typeof v === "object" ? v : { value: v };
90
+ } catch {
91
+ return { _raw: args };
92
+ }
93
+ }
94
+ var KIND_BY_NAME = {};
95
+ function kinds(kind, names) {
96
+ for (const n of names) KIND_BY_NAME[n] = kind;
97
+ }
98
+ kinds("shell", [
99
+ "bash",
100
+ "shell",
101
+ "exec_command",
102
+ "local_shell",
103
+ "run_shell_command",
104
+ "terminal",
105
+ "execute_bash",
106
+ "run_command",
107
+ "command",
108
+ "run_terminal_cmd",
109
+ "execute_command",
110
+ "powershell",
111
+ "cmd",
112
+ "command_execution",
113
+ "exec",
114
+ "run",
115
+ "sh",
116
+ "process"
117
+ ]);
118
+ kinds("shell_output", ["bashoutput", "bash_output", "killshell", "kill_shell", "killbash"]);
119
+ kinds("read", [
120
+ "read",
121
+ "read_file",
122
+ "readfile",
123
+ "view",
124
+ "view_file",
125
+ "cat",
126
+ "read_many_files",
127
+ "notebookread",
128
+ "file_read",
129
+ "open_file",
130
+ "readmanyfiles",
131
+ "read_text_file"
132
+ ]);
133
+ kinds("write", ["write", "write_file", "writefile", "create_file", "file_write", "create", "write_to_file"]);
134
+ kinds("edit", [
135
+ "edit",
136
+ "multiedit",
137
+ "multi_edit",
138
+ "str_replace",
139
+ "str_replace_editor",
140
+ "str_replace_based_edit_tool",
141
+ "replace",
142
+ "apply_patch",
143
+ "patch",
144
+ "edit_file",
145
+ "strreplacefile",
146
+ "notebookedit",
147
+ "text_editor",
148
+ "file_change",
149
+ "search_replace",
150
+ "insert",
151
+ "replace_in_file",
152
+ "editor"
153
+ ]);
154
+ kinds("search", [
155
+ "grep",
156
+ "search_file_content",
157
+ "search_files",
158
+ "rg",
159
+ "ripgrep",
160
+ "codebase_search",
161
+ "search",
162
+ "grep_search",
163
+ "file_grep"
164
+ ]);
165
+ kinds("glob", ["glob", "find_files", "file_search", "find", "glob_files"]);
166
+ kinds("list", ["ls", "list", "list_directory", "list_dir", "listdir", "list_files", "tree"]);
167
+ kinds("web_search", [
168
+ "websearch",
169
+ "web_search",
170
+ "google_web_search",
171
+ "searchweb",
172
+ "search_web",
173
+ "tavily_search",
174
+ "brave_search",
175
+ "web_search_preview",
176
+ "internet_search"
177
+ ]);
178
+ kinds("web_fetch", [
179
+ "webfetch",
180
+ "web_fetch",
181
+ "fetch",
182
+ "fetchurl",
183
+ "fetch_url",
184
+ "web_extract",
185
+ "read_url",
186
+ "browse",
187
+ "url_fetch",
188
+ "http_get",
189
+ "curl"
190
+ ]);
191
+ kinds("agent", [
192
+ "task",
193
+ "agent",
194
+ "delegate_task",
195
+ "spawn_agent",
196
+ "subagent",
197
+ "dispatch_agent",
198
+ "run_agent",
199
+ "launch_agent",
200
+ "call_agent"
201
+ ]);
202
+ kinds("todo", [
203
+ "todowrite",
204
+ "todo_write",
205
+ "todo",
206
+ "todos",
207
+ "update_plan",
208
+ "write_todos",
209
+ "settodolist",
210
+ "set_todo_list",
211
+ "task_tracker",
212
+ "todoread",
213
+ "todo_read",
214
+ "plan",
215
+ "update_todos",
216
+ "manage_todo_list"
217
+ ]);
218
+ kinds("skill", ["skill", "use_skill", "load_skill"]);
219
+ kinds("think", ["think", "sequentialthinking", "sequential_thinking", "reflect"]);
220
+ kinds("toolsearch", ["toolsearch", "tool_search", "load_tools"]);
221
+ kinds("browser", ["browser", "computer", "playwright", "browser_use", "navigate", "screenshot"]);
222
+ var NS = /^(developer|platform|computercontroller|builtin|default|functions|tools?)(__|\.|:)/;
223
+ function toolKind(name) {
224
+ const raw = String(name || "").trim();
225
+ if (!raw) return "tool";
226
+ if (/^mcp__/i.test(raw)) return "mcp";
227
+ const n = raw.toLowerCase().replace(NS, "");
228
+ if (KIND_BY_NAME[n]) return KIND_BY_NAME[n];
229
+ if (/^browser[_\-.]|[_\-.]browser$|^playwright|^computer[_\-.]/.test(n)) return "browser";
230
+ const flat = n.replace(/[^a-z0-9]/g, "");
231
+ if (KIND_BY_NAME[flat]) return KIND_BY_NAME[flat];
232
+ if (/[a-z0-9](\.|__)[a-z0-9]/.test(n)) return "mcp";
233
+ return "tool";
234
+ }
235
+ function str(v) {
236
+ return v == null ? "" : typeof v === "string" ? v : Array.isArray(v) ? v.join(" ") : String(v);
237
+ }
238
+ function firstOf(a, keys) {
239
+ for (const k of keys) {
240
+ const v = a[k];
241
+ if (v != null && v !== "" && !(Array.isArray(v) && !v.length)) return v;
242
+ }
243
+ return void 0;
244
+ }
245
+ function baseNameOf(p) {
246
+ const s = str(p).replace(/[\\/]+$/, "");
247
+ const i = Math.max(s.lastIndexOf("/"), s.lastIndexOf("\\"));
248
+ return i >= 0 ? s.slice(i + 1) : s;
249
+ }
250
+ function commandText(a) {
251
+ let c = firstOf(a, ["command", "cmd", "commands", "script", "code", "input", "args"]);
252
+ if (Array.isArray(c)) {
253
+ if (c.length >= 3 && /(^|\/)(ba|z)?sh$/.test(String(c[0])) && /^-\w*c$/.test(String(c[1]))) c = c.slice(2).join(" ");
254
+ else c = c.join(" ");
255
+ }
256
+ return str(c).trim();
257
+ }
258
+ function lineCount(s) {
259
+ const t = str(s);
260
+ if (!t) return 0;
261
+ const n = t.split("\n").length;
262
+ return t.endsWith("\n") ? n - 1 : n;
263
+ }
264
+ function patchStats(patch) {
265
+ let added = 0;
266
+ let removed = 0;
267
+ for (const ln of str(patch).split("\n")) {
268
+ if (/^(\+\+\+|---|\*\*\*|@@)/.test(ln)) continue;
269
+ if (ln.startsWith("+")) added++;
270
+ else if (ln.startsWith("-")) removed++;
271
+ }
272
+ return { added, removed };
273
+ }
274
+ function patchFiles(patch) {
275
+ const out = [];
276
+ for (const ln of str(patch).split("\n")) {
277
+ const m = ln.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/) || ln.match(/^\+\+\+ (?:b\/)?(.+)$/);
278
+ if (m && m[1] !== "/dev/null" && !out.includes(m[1].trim())) out.push(m[1].trim());
279
+ }
280
+ return out;
281
+ }
282
+ function diffOf(kind, a) {
283
+ if (kind === "write") {
284
+ const body = firstOf(a, ["content", "file_text", "text", "contents", "data"]);
285
+ return body == null ? null : { added: lineCount(body), removed: 0 };
286
+ }
287
+ if (kind !== "edit") return null;
288
+ const cmd = str(a.command).toLowerCase();
289
+ if (cmd === "view" || cmd === "undo_edit") return null;
290
+ if (cmd === "create" || cmd === "write") {
291
+ const body = firstOf(a, ["file_text", "content", "text"]);
292
+ return body == null ? null : { added: lineCount(body), removed: 0 };
293
+ }
294
+ if (Array.isArray(a.edits)) {
295
+ let added = 0;
296
+ let removed = 0;
297
+ for (const e of a.edits) {
298
+ added += lineCount(firstOf(e || {}, ["new_string", "new_str", "newText", "replacement"]) || "");
299
+ removed += lineCount(firstOf(e || {}, ["old_string", "old_str", "oldText", "search"]) || "");
300
+ }
301
+ return { added, removed };
302
+ }
303
+ const neu = firstOf(a, ["new_string", "new_str", "newText", "new_text", "replacement", "replace"]);
304
+ const old = firstOf(a, ["old_string", "old_str", "oldText", "old_text", "search"]);
305
+ if (neu != null || old != null) return { added: lineCount(neu || ""), removed: lineCount(old || "") };
306
+ const patch = firstOf(a, ["patch", "diff", "input", "_raw"]);
307
+ if (typeof patch === "string" && /^(\*\*\* Begin Patch|---|\+\+\+|@@|diff )/m.test(patch)) return patchStats(patch);
308
+ if (Array.isArray(a.changes)) {
309
+ let added = 0;
310
+ let removed = 0;
311
+ let any = false;
312
+ for (const c of a.changes) {
313
+ const d = c && (c.diff || c.unified_diff || c.patch);
314
+ if (typeof d === "string") {
315
+ const s = patchStats(d);
316
+ added += s.added;
317
+ removed += s.removed;
318
+ any = true;
319
+ }
320
+ }
321
+ return any ? { added, removed } : null;
322
+ }
323
+ return null;
324
+ }
325
+ var TODO_STATUS = {
326
+ completed: "completed",
327
+ complete: "completed",
328
+ done: "completed",
329
+ finished: "completed",
330
+ in_progress: "in_progress",
331
+ inprogress: "in_progress",
332
+ active: "in_progress",
333
+ doing: "in_progress",
334
+ running: "in_progress",
335
+ pending: "pending",
336
+ todo: "pending",
337
+ not_started: "pending",
338
+ open: "pending",
339
+ cancelled: "cancelled",
340
+ canceled: "cancelled"
341
+ };
342
+ function todosOf(a) {
343
+ const list = firstOf(a, ["todos", "plan", "items", "tasks", "todo_list", "steps", "task_list"]);
344
+ if (!Array.isArray(list) || !list.length) return null;
345
+ const out = [];
346
+ for (const t of list) {
347
+ if (typeof t === "string") {
348
+ out.push({ text: t, status: "pending" });
349
+ continue;
350
+ }
351
+ if (!t || typeof t !== "object") continue;
352
+ const text = str(firstOf(t, ["content", "step", "title", "text", "description", "task", "name"])).trim();
353
+ if (!text) continue;
354
+ let st = str(firstOf(t, ["status", "state"])).toLowerCase().replace(/[\s-]+/g, "_");
355
+ if (!st && typeof t.done === "boolean") st = t.done ? "completed" : "pending";
356
+ if (!st && typeof t.completed === "boolean") st = t.completed ? "completed" : "pending";
357
+ out.push({ text, status: TODO_STATUS[st] || "pending" });
358
+ }
359
+ return out.length ? out : null;
360
+ }
361
+ function shortUrl(u) {
362
+ const s = str(u);
363
+ try {
364
+ const x = new URL(s);
365
+ return (x.host + (x.pathname === "/" ? "" : x.pathname)).replace(/\/$/, "");
366
+ } catch {
367
+ return s;
368
+ }
369
+ }
370
+ function humanizeName(n) {
371
+ return str(n).replace(/^mcp__/i, "").replace(/__|\./g, " \xB7 ").replace(/[_-]+/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").trim().replace(/^\w/, (c) => c.toUpperCase());
372
+ }
373
+ var VERBS = {
374
+ shell: ["Running", "Ran"],
375
+ shell_output: ["Reading output of", "Read output of"],
376
+ read: ["Reading", "Read"],
377
+ write: ["Writing", "Created"],
378
+ edit: ["Editing", "Edited"],
379
+ search: ["Searching for", "Searched for"],
380
+ glob: ["Finding", "Found"],
381
+ list: ["Listing", "Listed"],
382
+ web_search: ["Searching the web for", "Searched the web for"],
383
+ web_fetch: ["Fetching", "Fetched"],
384
+ agent: ["Running agent", "Ran agent"],
385
+ todo: ["Updating the plan", "Updated the plan"],
386
+ skill: ["Using skill", "Used skill"],
387
+ think: ["Thinking", "Thought"],
388
+ toolsearch: ["Loading tools", "Loaded tools"],
389
+ browser: ["Using the browser", "Used the browser"],
390
+ mcp: ["Using", "Used"],
391
+ tool: ["Using", "Used"]
392
+ };
393
+ function describeTool(name, args) {
394
+ const a = parseToolArgs(args);
395
+ let kind = toolKind(name);
396
+ const nm = str(name);
397
+ if (kind === "edit" && /^(view|read)$/i.test(str(a.command))) kind = "read";
398
+ if (kind === "edit" && /^(create|write)$/i.test(str(a.command))) kind = "write";
399
+ let target = "";
400
+ let targetFull = "";
401
+ let mono = false;
402
+ let note = "";
403
+ const pathOf = () => firstOf(a, [
404
+ "file_path",
405
+ "path",
406
+ "filePath",
407
+ "absolute_path",
408
+ "target_file",
409
+ "filename",
410
+ "file",
411
+ "notebook_path",
412
+ "paths",
413
+ "absolute_paths",
414
+ "dir_path",
415
+ "directory"
416
+ ]);
417
+ switch (kind) {
418
+ case "shell": {
419
+ const desc = str(firstOf(a, ["description", "summary", "title"])).trim();
420
+ const cmd = commandText(a);
421
+ targetFull = cmd || desc;
422
+ if (desc) {
423
+ target = desc;
424
+ note = cmd;
425
+ } else {
426
+ target = cmd;
427
+ mono = !!cmd;
428
+ }
429
+ break;
430
+ }
431
+ case "shell_output":
432
+ target = str(firstOf(a, ["bash_id", "shell_id", "id"]));
433
+ mono = true;
434
+ break;
435
+ case "read":
436
+ case "write":
437
+ case "edit":
438
+ case "list": {
439
+ let p = pathOf();
440
+ if (Array.isArray(p)) p = p.length > 1 ? `${baseNameOf(p[0])} and ${p.length - 1} more` : p[0];
441
+ if (!p && kind === "edit") {
442
+ const files = patchFiles(firstOf(a, ["patch", "input", "_raw"]) || "").concat(Array.isArray(a.changes) ? a.changes.map((c) => c && c.path).filter(Boolean) : []);
443
+ if (files.length) p = files.length > 1 ? `${baseNameOf(files[0])} and ${files.length - 1} more` : files[0];
444
+ }
445
+ targetFull = str(p);
446
+ target = kind === "list" ? str(p) || "." : baseNameOf(p);
447
+ mono = !!target;
448
+ break;
449
+ }
450
+ case "search":
451
+ case "glob": {
452
+ const pat = firstOf(a, ["pattern", "query", "regex", "q", "glob", "search", "text"]);
453
+ const where = firstOf(a, ["path", "dir_path", "directory", "include"]);
454
+ target = str(pat);
455
+ mono = true;
456
+ targetFull = where ? `${str(pat)} in ${str(where)}` : str(pat);
457
+ break;
458
+ }
459
+ case "web_search":
460
+ target = str(firstOf(a, ["query", "q", "search_query", "queries", "search"]));
461
+ targetFull = target;
462
+ break;
463
+ case "web_fetch": {
464
+ const u = firstOf(a, ["url", "urls", "uri", "href", "link"]);
465
+ targetFull = Array.isArray(u) ? u.join(" ") : str(u);
466
+ target = Array.isArray(u) ? `${shortUrl(u[0])}${u.length > 1 ? ` and ${u.length - 1} more` : ""}` : shortUrl(u);
467
+ break;
468
+ }
469
+ case "agent":
470
+ target = str(firstOf(a, ["description", "task", "title", "name", "goal"])) || str(firstOf(a, ["prompt"])).slice(0, 80);
471
+ note = str(firstOf(a, ["subagent_type", "agent", "agent_type", "role"]));
472
+ targetFull = str(firstOf(a, ["prompt", "task", "description"]));
473
+ break;
474
+ case "skill":
475
+ target = str(firstOf(a, ["skill", "name", "command", "skill_name"]));
476
+ mono = true;
477
+ targetFull = target;
478
+ break;
479
+ case "browser": {
480
+ const act = str(firstOf(a, ["action", "command", "type"]));
481
+ const u = str(firstOf(a, ["url", "selector", "text"]));
482
+ target = [act, u ? shortUrl(u) : ""].filter(Boolean).join(" ");
483
+ targetFull = target;
484
+ if (/^browser[_\-.]/i.test(nm)) note = humanizeName(nm.replace(/^browser[_\-.]/i, ""));
485
+ break;
486
+ }
487
+ case "mcp":
488
+ case "tool": {
489
+ target = humanizeName(nm);
490
+ targetFull = nm;
491
+ break;
492
+ }
493
+ default:
494
+ break;
495
+ }
496
+ const v = VERBS[kind] || VERBS.tool;
497
+ return {
498
+ kind,
499
+ target: target.replace(/\s+/g, " ").trim(),
500
+ targetFull,
501
+ mono,
502
+ note,
503
+ running: v[0],
504
+ done: v[1],
505
+ diff: diffOf(kind, a),
506
+ todos: kind === "todo" ? todosOf(a) : null
507
+ };
508
+ }
509
+ function toolLine(d, state) {
510
+ const verb = state === "running" ? d.running : d.done;
511
+ if (d.kind === "todo" || d.kind === "toolsearch" || d.kind === "think") return verb;
512
+ if (d.kind === "shell" && d.target && !d.mono) return d.target;
513
+ if (d.kind === "mcp" || d.kind === "tool") return `${verb} ${d.target || "a tool"}`;
514
+ return d.target ? `${verb} ${d.target}` : `${verb} ${KIND_NOUN[d.kind] || "a tool"}`;
515
+ }
516
+ var KIND_NOUN = {
517
+ shell: "a command",
518
+ read: "a file",
519
+ write: "a file",
520
+ edit: "a file",
521
+ search: "code",
522
+ glob: "files",
523
+ list: "a folder",
524
+ web_search: "",
525
+ web_fetch: "a page",
526
+ agent: "",
527
+ skill: "a skill",
528
+ browser: "",
529
+ shell_output: "a command"
530
+ };
531
+ var PHRASES = {
532
+ shell: (n) => n === 1 ? "ran a command" : `ran ${n} commands`,
533
+ shell_output: (n) => n === 1 ? "checked a command" : `checked ${n} commands`,
534
+ read: (n) => n === 1 ? "read a file" : `read ${n} files`,
535
+ write: (n) => n === 1 ? "created a file" : `created ${n} files`,
536
+ edit: (n) => n === 1 ? "edited a file" : `edited ${n} files`,
537
+ search: (n) => n === 1 ? "searched code" : `searched code ${n} times`,
538
+ glob: () => "found files",
539
+ list: (n) => n === 1 ? "listed a folder" : `listed ${n} folders`,
540
+ web_search: (n) => n === 1 ? "searched the web" : `searched the web ${n} times`,
541
+ web_fetch: (n) => n === 1 ? "fetched a page" : `fetched ${n} pages`,
542
+ agent: (n) => n === 1 ? "ran an agent" : `ran ${n} agents`,
543
+ todo: () => "updated the plan",
544
+ skill: (n) => n === 1 ? "used a skill" : `used ${n} skills`,
545
+ think: () => "thought it through",
546
+ toolsearch: () => "loaded tools",
547
+ browser: () => "used the browser",
548
+ mcp: (n) => n === 1 ? "used a tool" : `used ${n} tools`,
549
+ tool: (n) => n === 1 ? "used a tool" : `used ${n} tools`
550
+ };
551
+ function summarizeCalls(calls) {
552
+ const list = (calls || []).filter(Boolean);
553
+ if (!list.length) return "";
554
+ if (list.length === 1) return toolLine(describeTool(list[0].name, list[0].args), "done");
555
+ const order = [];
556
+ const count = {};
557
+ for (const c of list) {
558
+ let k = toolKind(c.name);
559
+ if (k === "mcp") k = "tool";
560
+ if (!(k in count)) {
561
+ count[k] = 0;
562
+ order.push(k);
563
+ }
564
+ count[k]++;
565
+ }
566
+ const s = order.map((k) => (PHRASES[k] || PHRASES.tool)(count[k])).join(", ");
567
+ return s.charAt(0).toUpperCase() + s.slice(1);
568
+ }
569
+ function resultNote(kind, output) {
570
+ const out = str(output);
571
+ if (!out.trim()) return "";
572
+ const n = lineCount(out.trim());
573
+ if (kind === "read") return n === 1 ? "1 line" : `${n} lines`;
574
+ if (kind === "glob") return n === 1 ? "1 file" : `${n} files`;
575
+ if (kind === "search") return n === 1 ? "1 match" : `${n} matches`;
576
+ return "";
577
+ }
578
+
579
+ // src/agent-chat/turn.js
580
+ var TERMINAL = /* @__PURE__ */ new Set(["done", "failed", "cancelled", "incomplete"]);
581
+ function newTurn(opts = {}) {
582
+ return {
583
+ id: opts.id || null,
584
+ sessionId: opts.sessionId || null,
585
+ status: opts.status || "running",
586
+ user: opts.user ? { text: String(opts.user.text || ""), files: (opts.user.files || []).map((f) => ({ name: f.name, size: f.size, src: f.src })) } : null,
587
+ items: [],
588
+ files: [],
589
+ startedAt: opts.startedAt ?? null,
590
+ endedAt: null,
591
+ elapsedMs: null,
592
+ lastEventAt: null,
593
+ usage: null,
594
+ error: null,
595
+ incomplete: null,
596
+ model: opts.model || null,
597
+ _oi: {}
598
+ // output_index -> item id, to route deltas that name only their index
599
+ };
600
+ }
601
+ function isTerminal(status) {
602
+ return TERMINAL.has(status);
603
+ }
604
+ function mapStatus(s) {
605
+ const v = String(s || "").toLowerCase();
606
+ if (v === "completed" || v === "done" || v === "succeeded") return "done";
607
+ if (v === "cancelled" || v === "canceled") return "cancelled";
608
+ if (v === "incomplete" || v === "max_turns" || v === "timeout" || v === "max_steps") return "incomplete";
609
+ if (v === "failed" || v === "error") return "failed";
610
+ if (v === "running" || v === "in_progress" || v === "queued" || v === "starting") return "running";
611
+ return "done";
612
+ }
613
+ function findIdx(items, pred) {
614
+ for (let i = items.length - 1; i >= 0; i--) if (pred(items[i])) return i;
615
+ return -1;
616
+ }
617
+ function patchItem(turn, i, patch) {
618
+ const items = turn.items.slice();
619
+ items[i] = { ...items[i], ...patch };
620
+ return { ...turn, items };
621
+ }
622
+ function pushItem(turn, item, oi) {
623
+ const t = { ...turn, items: [...turn.items, item] };
624
+ if (oi !== void 0 && oi !== null) t._oi = { ...turn._oi, [oi]: item.id };
625
+ return t;
626
+ }
627
+ function isAgentTool(name) {
628
+ return toolKind(name) === "agent";
629
+ }
630
+ function settleOpenCalls(turn) {
631
+ let changed = false;
632
+ const items = turn.items.map((it) => {
633
+ if (it.kind === "tool" && it.status === "running" && !isAgentTool(it.name)) {
634
+ changed = true;
635
+ return { ...it, status: "done" };
636
+ }
637
+ return it;
638
+ });
639
+ return changed ? { ...turn, items } : turn;
640
+ }
641
+ function closeThinking(turn, at) {
642
+ const i = findIdx(turn.items, (x) => x.kind === "thinking" && x.endedAt == null && x.open);
643
+ if (i < 0) return turn;
644
+ return patchItem(turn, i, { open: false, endedAt: at ?? null });
645
+ }
646
+ function outputFailed(item) {
647
+ if (!item) return false;
648
+ if (item.is_error === true || item.isError === true) return true;
649
+ const s = String(item.status || "").toLowerCase();
650
+ return s === "failed" || s === "error" || s === "incomplete";
651
+ }
652
+ function textOf(v) {
653
+ return v == null ? "" : typeof v === "string" ? v : JSON.stringify(v);
654
+ }
655
+ function idOf(prefix, turn) {
656
+ return `${prefix}_${turn.items.length}`;
657
+ }
658
+ function reduceTurn(turn, ev, at = null) {
659
+ if (!ev || typeof ev !== "object") return turn;
660
+ let t = turn || newTurn();
661
+ const type = String(ev.type || "");
662
+ if (at != null) t = { ...t, lastEventAt: at };
663
+ switch (type) {
664
+ case "harness.turn.started": {
665
+ if (!t.user && ev.user_text) t = { ...t, user: { text: String(ev.user_text), files: [] } };
666
+ return t;
667
+ }
668
+ case "response.created":
669
+ case "response.in_progress":
670
+ case "response.queued": {
671
+ const r = ev.response || {};
672
+ return {
673
+ ...t,
674
+ id: r.id || t.id,
675
+ sessionId: r.metadata && r.metadata.session_id || t.sessionId,
676
+ model: r.model || t.model,
677
+ startedAt: t.startedAt ?? (at ?? (r.created_at ? r.created_at * 1e3 : null))
678
+ };
679
+ }
680
+ case "response.output_item.added":
681
+ case "response.output_item.done": {
682
+ const item = ev.item || {};
683
+ const added = type.endsWith(".added");
684
+ const oi = ev.output_index;
685
+ if (item.type === "reasoning") {
686
+ const i = findIdx(t.items, (x) => x.id === item.id);
687
+ const summary = Array.isArray(item.summary) ? item.summary.map((p) => p && p.text).filter(Boolean).join("\n\n") : "";
688
+ if (i < 0) {
689
+ t = settleOpenCalls(t);
690
+ t = pushItem(t, { kind: "thinking", id: item.id || idOf("rs", t), text: summary, startedAt: at, endedAt: added ? null : at, open: added }, oi);
691
+ return t;
692
+ }
693
+ if (!added) {
694
+ const cur = t.items[i];
695
+ return patchItem(t, i, { open: false, endedAt: cur.endedAt ?? at, text: cur.text || summary });
696
+ }
697
+ return t;
698
+ }
699
+ if (item.type === "message") {
700
+ const i = findIdx(t.items, (x) => x.id === item.id);
701
+ const full = Array.isArray(item.content) ? item.content.map((p) => p && (p.text || p.refusal) || "").join("") : "";
702
+ if (i < 0) {
703
+ t = closeThinking(settleOpenCalls(t), at);
704
+ const last = t.items[t.items.length - 1];
705
+ if (last && last.kind === "text" && !last.closed) {
706
+ t = { ...t, _oi: oi != null ? { ...t._oi, [oi]: last.id } : t._oi };
707
+ if (!added && full && !last.text) t = patchItem(t, t.items.length - 1, { text: full });
708
+ return t;
709
+ }
710
+ return pushItem(t, { kind: "text", id: item.id || idOf("msg", t), text: added ? "" : full }, oi);
711
+ }
712
+ if (!added && full && !t.items[i].text) return patchItem(t, i, { text: full });
713
+ return t;
714
+ }
715
+ if (item.type === "function_call" || item.type === "custom_tool_call" || item.type === "mcp_call") {
716
+ const callId = item.call_id || item.id || idOf("call", t);
717
+ const args = textOf(item.arguments ?? item.input ?? "");
718
+ const i = findIdx(t.items, (x) => x.kind === "tool" && (x.id === callId || x.itemId === item.id));
719
+ if (i >= 0) {
720
+ const cur = t.items[i];
721
+ const patch = {};
722
+ if (args && (!cur.args || cur.args === "{}")) patch.args = args;
723
+ if (item.name && (!cur.name || cur.name === "tool")) patch.name = item.name;
724
+ return Object.keys(patch).length ? patchItem(t, i, patch) : t;
725
+ }
726
+ t = closeThinking(t, at);
727
+ const lastText = findIdx(t.items, (x) => x.kind === "text");
728
+ if (lastText >= 0) t = patchItem(t, lastText, { closed: true });
729
+ return pushItem(t, {
730
+ kind: "tool",
731
+ id: callId,
732
+ itemId: item.id || null,
733
+ name: item.name || "tool",
734
+ args,
735
+ output: void 0,
736
+ status: "running",
737
+ startedAt: at,
738
+ endedAt: null
739
+ }, oi);
740
+ }
741
+ if (item.type === "function_call_output" || item.type === "custom_tool_call_output") {
742
+ const callId = item.call_id || "";
743
+ const i = findIdx(t.items, (x) => x.kind === "tool" && x.id === callId);
744
+ const failed = outputFailed(item);
745
+ const output = textOf(item.output);
746
+ if (i < 0) {
747
+ return pushItem(t, {
748
+ kind: "tool",
749
+ id: callId || idOf("out", t),
750
+ itemId: null,
751
+ name: "tool",
752
+ args: "",
753
+ output,
754
+ status: failed ? "failed" : "done",
755
+ startedAt: null,
756
+ endedAt: at
757
+ });
758
+ }
759
+ const cur = t.items[i];
760
+ if (cur.output !== void 0 && cur.status !== "running") return t;
761
+ return patchItem(t, i, { output, status: failed ? "failed" : "done", endedAt: at });
762
+ }
763
+ return t;
764
+ }
765
+ case "response.reasoning_summary_part.added":
766
+ return t;
767
+ case "response.reasoning_summary_text.delta":
768
+ case "response.reasoning_text.delta": {
769
+ const d = String(ev.delta || "");
770
+ let i = findIdx(t.items, (x) => x.kind === "thinking" && (x.id === ev.item_id || ev.output_index != null && t._oi[ev.output_index] === x.id));
771
+ if (i < 0) i = t.items.length && t.items[t.items.length - 1].kind === "thinking" ? t.items.length - 1 : -1;
772
+ if (i < 0) {
773
+ t = settleOpenCalls(t);
774
+ return pushItem(t, { kind: "thinking", id: ev.item_id || idOf("rs", t), text: d, startedAt: at, endedAt: null, open: true }, ev.output_index);
775
+ }
776
+ const cur = t.items[i];
777
+ return patchItem(t, i, { text: cur.text + d });
778
+ }
779
+ case "response.reasoning_summary_part.done":
780
+ return t;
781
+ case "response.output_text.delta": {
782
+ const d = String(ev.delta || "");
783
+ if (!d) return t;
784
+ let i = findIdx(t.items, (x) => x.kind === "text" && (x.id === ev.item_id || ev.output_index != null && t._oi[ev.output_index] === x.id));
785
+ if (i < 0 && t.items.length && t.items[t.items.length - 1].kind === "text" && !t.items[t.items.length - 1].closed) i = t.items.length - 1;
786
+ if (i < 0) {
787
+ t = closeThinking(settleOpenCalls(t), at);
788
+ return pushItem(t, { kind: "text", id: ev.item_id || idOf("msg", t), text: d }, ev.output_index);
789
+ }
790
+ if (i !== t.items.length - 1) {
791
+ t = closeThinking(settleOpenCalls(t), at);
792
+ }
793
+ return patchItem(t, i, { text: t.items[i].text + d });
794
+ }
795
+ case "response.output_text.done": {
796
+ const i = findIdx(t.items, (x) => x.kind === "text" && x.id === ev.item_id);
797
+ if (i >= 0 && !t.items[i].text && ev.text) return patchItem(t, i, { text: String(ev.text) });
798
+ return t;
799
+ }
800
+ case "response.function_call_arguments.delta": {
801
+ const i = findIdx(t.items, (x) => x.kind === "tool" && (x.itemId === ev.item_id || ev.output_index != null && t._oi[ev.output_index] === x.id));
802
+ if (i < 0) return t;
803
+ return patchItem(t, i, { args: (t.items[i].args || "") + String(ev.delta || "") });
804
+ }
805
+ case "response.function_call_arguments.done": {
806
+ const i = findIdx(t.items, (x) => x.kind === "tool" && (x.itemId === ev.item_id || ev.output_index != null && t._oi[ev.output_index] === x.id));
807
+ if (i < 0) return t;
808
+ return patchItem(t, i, { args: String(ev.arguments ?? t.items[i].args ?? "") });
809
+ }
810
+ case "response.output_text.annotation.added": {
811
+ const a = ev.annotation || {};
812
+ if (a.type !== "container_file_citation") return t;
813
+ const same = (f) => a.file_id ? f.file_id === a.file_id && f.container_id === a.container_id : f.filename === a.filename;
814
+ if (t.files.some(same)) return t;
815
+ return { ...t, files: [...t.files, {
816
+ container_id: a.container_id,
817
+ file_id: a.file_id,
818
+ filename: a.filename,
819
+ ...a.download_url ? { download_url: a.download_url } : {}
820
+ }] };
821
+ }
822
+ case "response.completed":
823
+ case "response.incomplete":
824
+ case "response.failed":
825
+ case "response.cancelled": {
826
+ const r = ev.response || {};
827
+ let status = type === "response.completed" ? "done" : type === "response.incomplete" ? "incomplete" : type === "response.cancelled" ? "cancelled" : mapStatus(r.status || "failed");
828
+ if (type === "response.failed" && (ev.reason === "cancelled" || r.status === "cancelled")) status = "cancelled";
829
+ if (type === "response.failed" && status === "done") status = "failed";
830
+ return finish(t, status, at, r);
831
+ }
832
+ case "error": {
833
+ const msg = String(ev.message || ev.error && ev.error.message || "").trim();
834
+ return msg ? { ...t, error: msg } : t;
835
+ }
836
+ default:
837
+ return t;
838
+ }
839
+ }
840
+ function finish(turn, status, at = null, response = null) {
841
+ const r = response || {};
842
+ const st = isTerminal(status) ? status : mapStatus(status);
843
+ const items = turn.items.map((it) => {
844
+ if (it.kind === "tool" && it.status === "running") return { ...it, status: st === "done" ? "done" : "stopped" };
845
+ if (it.kind === "thinking" && it.open) return { ...it, open: false, endedAt: it.endedAt ?? at };
846
+ return it;
847
+ });
848
+ const inc = r.incomplete_details;
849
+ const err = r.error && (r.error.message || r.error.code);
850
+ return {
851
+ ...turn,
852
+ items,
853
+ status: st,
854
+ endedAt: turn.endedAt ?? at,
855
+ id: r.id || turn.id,
856
+ usage: r.usage || turn.usage,
857
+ model: r.served_model || r.model || turn.model,
858
+ error: turn.error || (st === "failed" && err ? String(err) : turn.error),
859
+ incomplete: st === "incomplete" && inc ? { reason: inc.reason || "", detail: inc.detail || "" } : turn.incomplete
860
+ };
861
+ }
862
+ function turnFromEvents(events, opts = {}) {
863
+ let t = newTurn(opts);
864
+ for (const ev of events || []) t = reduceTurn(t, ev, opts.at ?? null);
865
+ return t;
866
+ }
867
+ function turnFromResponse(resp, opts = {}) {
868
+ const r = resp || {};
869
+ let t = newTurn({ ...opts, id: r.id, model: r.model });
870
+ const events = [];
871
+ (r.output || []).forEach((item, i) => events.push({ type: "response.output_item.done", output_index: i, item }));
872
+ for (const ev of events) t = reduceTurn(t, ev, null);
873
+ const st = mapStatus(r.status);
874
+ if (st === "running") return { ...t, status: "running" };
875
+ const created = r.created_at ? r.created_at * 1e3 : null;
876
+ t = finish(t, st, null, r);
877
+ return { ...t, startedAt: opts.startedAt ?? created, endedAt: opts.endedAt ?? null };
878
+ }
879
+ function turnFromHistory(h) {
880
+ const x = h || {};
881
+ let t = newTurn({ id: x.id, user: x.user || (x.user_files || []).length ? { text: x.user || "", files: x.user_files || [] } : null });
882
+ const items = [];
883
+ (x.tools || []).forEach((c, i) => {
884
+ const out = c.output ?? c.result;
885
+ items.push({
886
+ kind: "tool",
887
+ id: c.call_id || `call_${i}`,
888
+ itemId: null,
889
+ name: c.name || "tool",
890
+ args: textOf(c.arguments ?? ""),
891
+ output: out == null ? void 0 : String(out),
892
+ status: c.is_error ? "failed" : "done",
893
+ startedAt: null,
894
+ endedAt: null,
895
+ truncated: c.output_truncated || null
896
+ });
897
+ });
898
+ if (x.assistant) items.push({ kind: "text", id: `msg_${items.length}`, text: String(x.assistant) });
899
+ const status = mapStatus(x.status);
900
+ t = {
901
+ ...t,
902
+ items,
903
+ files: (x.files || []).slice(),
904
+ status,
905
+ model: x.served_model || x._model || null,
906
+ elapsedMs: typeof x.elapsed === "number" ? Math.round(x.elapsed * 1e3) : null,
907
+ error: x.error || null,
908
+ incomplete: status === "incomplete" && (x.incomplete_reason || x.incomplete_detail) ? { reason: x.incomplete_reason || "", detail: x.incomplete_detail || "" } : null
909
+ };
910
+ if (status === "running") {
911
+ t.items = t.items.map((it) => it.kind === "tool" && it.output === void 0 ? { ...it, status: "running" } : it);
912
+ }
913
+ return t;
914
+ }
915
+ function turnFromMessage(msg, clock = null, user = null) {
916
+ const m = msg || {};
917
+ const status = m.status ? mapStatus(m.status) : "done";
918
+ const byCall = {};
919
+ const thinkingClocks = [];
920
+ if (clock) {
921
+ for (const it of clock.items) {
922
+ if (it.kind === "tool") byCall[it.id] = it;
923
+ else if (it.kind === "thinking") thinkingClocks.push(it);
924
+ }
925
+ }
926
+ const items = [];
927
+ let errText = "";
928
+ let thinkN = 0;
929
+ (m.blocks || []).forEach((b, bi) => {
930
+ if (b.kind === "text") {
931
+ if (b.error) {
932
+ errText = String(b.text || "").replace(/^\s*Error:\s*/, "").trim();
933
+ return;
934
+ }
935
+ if (b.text) items.push({ kind: "text", id: `msg_${bi}`, text: b.text });
936
+ return;
937
+ }
938
+ if (b.kind === "tools") {
939
+ if (b.reasoning) {
940
+ const c = thinkingClocks[thinkN++];
941
+ items.push({
942
+ kind: "thinking",
943
+ id: `rs_${bi}`,
944
+ text: b.reasoning,
945
+ startedAt: c ? c.startedAt : null,
946
+ endedAt: c ? c.endedAt : null,
947
+ open: c ? !!c.open : false
948
+ });
949
+ }
950
+ (b.steps || []).forEach((s, si) => {
951
+ const c = s.callId ? byCall[s.callId] : null;
952
+ const answered = s.result !== void 0;
953
+ let st = c ? c.status : answered ? "done" : status === "running" ? "running" : status === "done" ? "done" : "stopped";
954
+ if (answered && st === "running") st = "done";
955
+ if (st === "running" && status !== "running") st = status === "done" ? "done" : "stopped";
956
+ items.push({
957
+ kind: "tool",
958
+ id: s.callId || `call_${bi}_${si}`,
959
+ itemId: null,
960
+ name: s.name || "tool",
961
+ args: textOf(s.args ?? ""),
962
+ output: answered ? String(s.result) : c ? c.output : void 0,
963
+ status: st,
964
+ startedAt: c ? c.startedAt : null,
965
+ endedAt: c ? c.endedAt : null
966
+ });
967
+ });
968
+ }
969
+ });
970
+ let t = {
971
+ ...newTurn({ user: user || null }),
972
+ id: clock && clock.id || m.id || null,
973
+ status,
974
+ items,
975
+ files: (m.files || []).slice(),
976
+ startedAt: clock ? clock.startedAt : null,
977
+ endedAt: clock ? clock.endedAt : null,
978
+ lastEventAt: clock ? clock.lastEventAt : null,
979
+ usage: clock ? clock.usage : null,
980
+ model: clock && clock.model || null,
981
+ error: errText || clock && clock.error || null,
982
+ elapsedMs: typeof m.elapsed === "number" ? Math.round(m.elapsed * 1e3) : null,
983
+ incomplete: status === "incomplete" && (m.incompleteReason || m.incompleteDetail) ? { reason: m.incompleteReason || "", detail: m.incompleteDetail || "" } : null
984
+ };
985
+ if (status === "running") {
986
+ let lastSpeech = -1;
987
+ t.items.forEach((it, i) => {
988
+ if (it.kind === "text" || it.kind === "thinking") lastSpeech = i;
989
+ });
990
+ t.items = t.items.map((it, i) => it.kind === "tool" && it.status === "running" && i < lastSpeech && !isAgentTool(it.name) ? { ...it, status: "done" } : it);
991
+ }
992
+ return t;
993
+ }
994
+ function liveState(turn) {
995
+ if (!turn || turn.status !== "running") return null;
996
+ const items = turn.items || [];
997
+ for (let i = items.length - 1; i >= 0; i--) {
998
+ const it = items[i];
999
+ if (it.kind === "tool" && it.status === "running") return { phase: "tool", tool: it };
1000
+ if (it.kind === "text" || it.kind === "thinking") break;
1001
+ }
1002
+ const last = items[items.length - 1];
1003
+ if (!last) return { phase: turn.id ? "thinking" : "starting", tool: null };
1004
+ if (last.kind === "thinking") return { phase: "thinking", tool: null };
1005
+ if (last.kind === "text" && !last.closed) return { phase: "writing", tool: null };
1006
+ return { phase: "thinking", tool: null };
1007
+ }
1008
+ function segments(turn) {
1009
+ const out = [];
1010
+ for (const it of turn && turn.items || []) {
1011
+ if (it.kind === "text") {
1012
+ if (!it.text) continue;
1013
+ out.push({ type: "text", item: it });
1014
+ } else {
1015
+ const last = out[out.length - 1];
1016
+ if (last && last.type === "work") last.items.push(it);
1017
+ else out.push({ type: "work", items: [it] });
1018
+ }
1019
+ }
1020
+ return out;
1021
+ }
1022
+ function latestPlan(turn, describe) {
1023
+ const items = turn && turn.items || [];
1024
+ for (let i = items.length - 1; i >= 0; i--) {
1025
+ const it = items[i];
1026
+ if (it.kind !== "tool" || toolKind(it.name) !== "todo") continue;
1027
+ const d = describe(it.name, it.args);
1028
+ if (d.todos && d.todos.length) return d.todos;
1029
+ }
1030
+ return null;
1031
+ }
1032
+
1033
+ // src/agent-chat/time.js
1034
+ var import_react = require("react");
1035
+ function formatElapsed(ms) {
1036
+ if (ms == null || !isFinite(ms) || ms < 0) return "";
1037
+ const s = Math.floor(ms / 1e3);
1038
+ if (s < 60) return `${s}s`;
1039
+ const m = Math.floor(s / 60);
1040
+ if (m < 60) return `${m}m ${s % 60}s`;
1041
+ const h = Math.floor(m / 60);
1042
+ return `${h}h ${m % 60}m`;
1043
+ }
1044
+ function formatDuration(ms) {
1045
+ if (ms == null || !isFinite(ms) || ms < 0) return "";
1046
+ if (ms < 1e3) return `${Math.max(0.1, Math.round(ms / 100) / 10).toFixed(1)}s`;
1047
+ if (ms < 1e4) return `${(Math.round(ms / 100) / 10).toFixed(1)}s`;
1048
+ return formatElapsed(ms);
1049
+ }
1050
+ function formatTokens(n) {
1051
+ if (n == null || !isFinite(n)) return "";
1052
+ if (n < 1e3) return String(Math.round(n));
1053
+ if (n < 1e6) return `${(n / 1e3).toFixed(1).replace(/\.0$/, "")}k`;
1054
+ return `${(Math.round(n / 1e5) / 10).toFixed(1).replace(/\.0$/, "")}M`;
1055
+ }
1056
+ function useNow(on, everyMs = 1e3) {
1057
+ const [now, setNow] = (0, import_react.useState)(() => Date.now());
1058
+ (0, import_react.useEffect)(() => {
1059
+ if (!on) return void 0;
1060
+ setNow(Date.now());
1061
+ let iv = null;
1062
+ const t0 = setTimeout(() => {
1063
+ setNow(Date.now());
1064
+ iv = setInterval(() => setNow(Date.now()), everyMs);
1065
+ }, everyMs - Date.now() % everyMs);
1066
+ return () => {
1067
+ clearTimeout(t0);
1068
+ if (iv) clearInterval(iv);
1069
+ };
1070
+ }, [on, everyMs]);
1071
+ return now;
1072
+ }
1073
+ function useElapsed(start, end = null) {
1074
+ const live = start != null && end == null;
1075
+ const now = useNow(live);
1076
+ if (start == null) return null;
1077
+ return Math.max(0, (end ?? now) - start);
1078
+ }
1079
+
1080
+ // src/agent-chat/marks.js
1081
+ var MARK_MOTIONS = {
1082
+ "claude-code": "bloom",
1083
+ claude: "bloom",
1084
+ anthropic: "bloom",
1085
+ codex: "sheen",
1086
+ openai: "sheen",
1087
+ gemini: "glint",
1088
+ "gemini-cli": "glint",
1089
+ hermes: "flutter",
1090
+ goose: "glide",
1091
+ opencode: "blink",
1092
+ pi: "flip",
1093
+ omp: "flip",
1094
+ dsh: "swim",
1095
+ deepseek: "swim",
1096
+ qwen: "spin",
1097
+ grok: "spin",
1098
+ systemone: "spin",
1099
+ opensquilla: "spin",
1100
+ openhands: "wave",
1101
+ cheetahclaws: "dash",
1102
+ zeroclaw: "scuttle",
1103
+ minimax: "equalize",
1104
+ cline: "bob",
1105
+ agentzero: "bob",
1106
+ qoder: "bob",
1107
+ nanobot: "bob",
1108
+ kimi: "sheen",
1109
+ kilo: "sheen",
1110
+ jcode: "pulse",
1111
+ mimo: "pulse",
1112
+ aider: "pulse"
1113
+ };
1114
+ var MOTIONS = [
1115
+ "bloom",
1116
+ "sheen",
1117
+ "glint",
1118
+ "flutter",
1119
+ "glide",
1120
+ "blink",
1121
+ "flip",
1122
+ "swim",
1123
+ "spin",
1124
+ "wave",
1125
+ "dash",
1126
+ "scuttle",
1127
+ "equalize",
1128
+ "bob",
1129
+ "pulse",
1130
+ "dots"
1131
+ ];
1132
+ function motionFor(base) {
1133
+ const k = String(base || "").toLowerCase().trim();
1134
+ return MARK_MOTIONS[k] || "pulse";
1135
+ }
1136
+
1137
+ // src/agent-chat/components.jsx
1138
+ var import_react3 = __toESM(require("react"), 1);
1139
+
1140
+ // src/components/icons.jsx
1141
+ var import_react2 = __toESM(require("react"), 1);
1142
+ var import_jsx_runtime = require("react/jsx-runtime");
1143
+ function Svg({ children, s = 16 }) {
1144
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1145
+ "svg",
1146
+ {
1147
+ width: s,
1148
+ height: s,
1149
+ viewBox: "0 0 24 24",
1150
+ fill: "none",
1151
+ stroke: "currentColor",
1152
+ strokeWidth: "1.8",
1153
+ strokeLinecap: "round",
1154
+ strokeLinejoin: "round",
1155
+ children
1156
+ }
1157
+ );
1158
+ }
1159
+ function Chevron({ dir, size = 16 }) {
1160
+ const d = dir === "left" ? "M15 18l-6-6 6-6" : dir === "right" ? "M9 18l6-6-6-6" : "M6 9l6 6 6-6";
1161
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1162
+ "svg",
1163
+ {
1164
+ width: size,
1165
+ height: size,
1166
+ viewBox: "0 0 24 24",
1167
+ fill: "none",
1168
+ stroke: "currentColor",
1169
+ strokeWidth: "2",
1170
+ strokeLinecap: "round",
1171
+ strokeLinejoin: "round",
1172
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d })
1173
+ }
1174
+ );
1175
+ }
1176
+ var IcTool = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Svg, { s: 17, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14.7 6.3a4 4 0 0 1-5.4 5.4L4 17v3h3l5.3-5.3a4 4 0 0 1 5.4-5.4l-2.3 2.3-1.7-1.7 2.3-2.3a4 4 0 0 0-1.6 0Z" }) });
1177
+ var IcPlug = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { s: 17, children: [
1178
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9 2v6M15 2v6M6 8h12v3a6 6 0 0 1-12 0z" }),
1179
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 17v5" })
1180
+ ] });
1181
+ var IcSkill = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { s: 17, children: [
1182
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9 18h6M10 22h4" }),
1183
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 2a7 7 0 0 0-4 12.7c.6.5 1 1.3 1 2.1V18h6v-1.2c0-.8.4-1.6 1-2.1A7 7 0 0 0 12 2z" })
1184
+ ] });
1185
+ var IcTerminal = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { s: 17, children: [
1186
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "4", width: "18", height: "16", rx: "2" }),
1187
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M7 9l3 3-3 3M13 15h4" })
1188
+ ] });
1189
+ var IcDoc = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { s: 17, children: [
1190
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z" }),
1191
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14 3v6h6M8 13h8M8 17h6" })
1192
+ ] });
1193
+ var IcList = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Svg, { s: 17, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 6h12M8 12h12M8 18h12M3.5 6h.01M3.5 12h.01M3.5 18h.01" }) });
1194
+ var IcGlobe = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { s: 17, children: [
1195
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "9" }),
1196
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3 12h18M12 3a15 15 0 0 1 0 18a15 15 0 0 1 0-18z" })
1197
+ ] });
1198
+ var IcSearch = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { s: 17, children: [
1199
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "11", cy: "11", r: "7" }),
1200
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m21 21-4.3-4.3" })
1201
+ ] });
1202
+ var IcScroll = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { s: 17, children: [
1203
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 3h10a2 2 0 0 1 2 2v12a3 3 0 0 0 3 3H8a2 2 0 0 1-2-2V3z" }),
1204
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 3a2 2 0 0 0-2 2v2h2M10 8h6M10 12h6" })
1205
+ ] });
1206
+ var IcSpawn = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { s: 17, children: [
1207
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "6", cy: "6", r: "3" }),
1208
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "18", cy: "18", r: "3" }),
1209
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 9v3a3 3 0 0 0 3 3h6" })
1210
+ ] });
1211
+ var IcThink = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Svg, { s: 16, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9.5 2a5.5 5.5 0 0 0-3 10.1V15a2 2 0 0 0 2 2h3a2 2 0 0 0 2-2v-2.9A5.5 5.5 0 0 0 9.5 2zM9 20h4M10 22h2" }) });
1212
+ var IcSend = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Svg, { s: 16, children: [
1213
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 19V5" }),
1214
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M5 12l7-7 7 7" })
1215
+ ] });
1216
+ var IcX = ({ size = 14 }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Svg, { s: size, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M18 6 6 18M6 6l12 12" }) });
1217
+ var IcPaperclip = ({ size = 16 }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Svg, { s: size, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M21.4 11.1 12.2 20.3a5.5 5.5 0 0 1-7.8-7.8l9.2-9.2a3.7 3.7 0 0 1 5.2 5.2l-9.2 9.2a1.8 1.8 0 0 1-2.6-2.6l8.5-8.5" }) });
1218
+
1219
+ // src/agent-chat/components.jsx
1220
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1221
+ var DEFAULT_AGENT_LABELS = {
1222
+ starting: "Starting",
1223
+ thinking: "Thinking",
1224
+ writing: "Writing",
1225
+ tool: "Running a tool",
1226
+ thought: "Thought",
1227
+ thoughtFor: (t) => `Thought for ${t}`,
1228
+ workedFor: (t) => `Worked for ${t}`,
1229
+ worked: "Done",
1230
+ tokens: (n) => `${n} tokens`,
1231
+ stopped: "Stopped",
1232
+ stoppedAfter: (t) => `Stopped after ${t}`,
1233
+ failed: "Failed",
1234
+ failedAfter: (t) => `Failed after ${t}`,
1235
+ incomplete: "Stopped before finishing",
1236
+ input: "Input",
1237
+ output: "Output",
1238
+ noOutput: "No output",
1239
+ copy: "Copy",
1240
+ copied: "Copied",
1241
+ copyFailed: "Select and copy",
1242
+ moreLines: (n) => n === 1 ? "+1 line" : `+${n} lines`,
1243
+ fewerLines: "Show less",
1244
+ failedCalls: (n) => n === 1 ? "1 failed" : `${n} failed`,
1245
+ stoppedCall: "stopped",
1246
+ plan: "Plan",
1247
+ jump: "Jump to latest",
1248
+ send: "Send",
1249
+ stop: "Stop",
1250
+ stopping: "Stopping",
1251
+ attach: "Attach a file",
1252
+ remove: (name) => `Remove ${name}`,
1253
+ working: "Working"
1254
+ };
1255
+ var ANSI = /\u001b\[[0-9;?]*[A-Za-z]/g;
1256
+ function cleanOutput(s) {
1257
+ return String(s ?? "").replace(ANSI, "").replace(/\r\n?/g, "\n");
1258
+ }
1259
+ function pretty(s) {
1260
+ const x = String(s || "").trim();
1261
+ if (!/^[[{]/.test(x)) return null;
1262
+ try {
1263
+ return JSON.stringify(JSON.parse(x), null, 2);
1264
+ } catch {
1265
+ return null;
1266
+ }
1267
+ }
1268
+ function firstLine(s, max = 220) {
1269
+ const l = cleanOutput(s).split("\n").map((x) => x.trim()).find(Boolean) || "";
1270
+ return l.length > max ? `${l.slice(0, max)}\u2026` : l;
1271
+ }
1272
+ function cls(...xs) {
1273
+ return xs.filter(Boolean).join(" ");
1274
+ }
1275
+ function WorkingMark(props) {
1276
+ const { mark, motion, size = 18, still = false } = props;
1277
+ const m = mark ? motion || "pulse" : "dots";
1278
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: cls("uac-mark", still && "is-still"), "data-motion": m, style: { "--uac-mark": `${size}px` }, "aria-hidden": "true", children: [
1279
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-mark-aura" }),
1280
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-mark-in", children: mark || /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1281
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("i", {}),
1282
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("i", {}),
1283
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("i", {})
1284
+ ] }) })
1285
+ ] });
1286
+ }
1287
+ function WorkingIndicator(props) {
1288
+ const { mark, motion, start = null, end = null, label, onToggle, expanded, controls, className, shimmer = true, size } = props;
1289
+ const ms = useElapsed(start, end);
1290
+ const body = /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1291
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(WorkingMark, { mark, motion, size }),
1292
+ ms != null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-elapsed", "aria-hidden": "true", children: formatElapsed(ms) }) : null,
1293
+ ms != null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-sep", "aria-hidden": "true", children: "\xB7" }) : null,
1294
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: cls("uac-verb", shimmer && "uac-shimmer"), "data-text": label, children: label }),
1295
+ onToggle ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-chev", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Chevron, { dir: expanded ? "down" : "right", size: 12 }) }) : null
1296
+ ] });
1297
+ if (onToggle) {
1298
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1299
+ "button",
1300
+ {
1301
+ type: "button",
1302
+ className: cls("uac-working", "is-button", className),
1303
+ "aria-expanded": !!expanded,
1304
+ "aria-controls": controls,
1305
+ onClick: onToggle,
1306
+ children: [
1307
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-sr", role: "status", children: label }),
1308
+ body
1309
+ ]
1310
+ }
1311
+ );
1312
+ }
1313
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: cls("uac-working", className), children: [
1314
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-sr", role: "status", children: label }),
1315
+ body
1316
+ ] });
1317
+ }
1318
+ function CopyButton(props) {
1319
+ const { text, labels = DEFAULT_AGENT_LABELS, label } = props;
1320
+ const [state, setState] = (0, import_react3.useState)("");
1321
+ (0, import_react3.useEffect)(() => {
1322
+ if (!state) return void 0;
1323
+ const t = setTimeout(() => setState(""), 1600);
1324
+ return () => clearTimeout(t);
1325
+ }, [state]);
1326
+ const copy = async (e) => {
1327
+ e.stopPropagation();
1328
+ try {
1329
+ await navigator.clipboard.writeText(String(text ?? ""));
1330
+ setState("ok");
1331
+ } catch {
1332
+ setState("no");
1333
+ }
1334
+ };
1335
+ const said = state === "ok" ? labels.copied : state === "no" ? labels.copyFailed : label || labels.copy;
1336
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", className: cls("uac-copy", state && `is-${state}`), onClick: copy, "aria-label": label ? `${labels.copy} ${label}` : labels.copy, children: [
1337
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { width: "13", height: "13", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.9", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: state === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M5 12l5 5L20 7" }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1338
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { x: "9", y: "9", width: "11", height: "11", rx: "2" }),
1339
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M5 15V6a2 2 0 0 1 2-2h9" })
1340
+ ] }) }),
1341
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: said })
1342
+ ] });
1343
+ }
1344
+ function DiffBadge(props) {
1345
+ const { diff } = props;
1346
+ if (!diff || !diff.added && !diff.removed && diff.added !== 0) return null;
1347
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "uac-diff", "aria-label": `${diff.added} lines added, ${diff.removed} removed`, children: [
1348
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "uac-add", children: [
1349
+ "+",
1350
+ diff.added
1351
+ ] }),
1352
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "uac-del", children: [
1353
+ "\u2212",
1354
+ diff.removed
1355
+ ] })
1356
+ ] });
1357
+ }
1358
+ function LinesBlock(props) {
1359
+ const { lines, limit = 12, labels = DEFAULT_AGENT_LABELS, className, numbered = false } = props;
1360
+ const [all, setAll] = (0, import_react3.useState)(false);
1361
+ const more = Math.max(0, lines.length - limit);
1362
+ const shown = all || !more ? lines : lines.slice(0, limit);
1363
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: cls("uac-lines", className), children: [
1364
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("pre", { children: shown.map((l, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: cls("uac-ln", l.cls), children: [
1365
+ numbered ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-lno", children: i + 1 }) : null,
1366
+ l.text || " "
1367
+ ] }, i)) }),
1368
+ more ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "uac-more", onClick: (e) => {
1369
+ e.stopPropagation();
1370
+ setAll((v) => !v);
1371
+ }, "aria-expanded": all, children: all ? labels.fewerLines : labels.moreLines(more) }) : null
1372
+ ] });
1373
+ }
1374
+ var asLines = (text, c) => String(text ?? "").replace(/\n$/, "").split("\n").map((t) => ({ text: t, cls: c }));
1375
+ var KIND_ICON = {
1376
+ shell: IcTerminal,
1377
+ shell_output: IcTerminal,
1378
+ read: IcScroll,
1379
+ write: IcDoc,
1380
+ edit: IcDoc,
1381
+ search: IcSearch,
1382
+ glob: IcSearch,
1383
+ list: IcList,
1384
+ web_search: IcGlobe,
1385
+ web_fetch: IcGlobe,
1386
+ agent: IcSpawn,
1387
+ todo: IcList,
1388
+ skill: IcSkill,
1389
+ think: IcThink,
1390
+ toolsearch: IcSearch,
1391
+ browser: IcGlobe,
1392
+ mcp: IcPlug,
1393
+ tool: IcTool
1394
+ };
1395
+ function StatusGlyph(props) {
1396
+ const { status, kind } = props;
1397
+ if (status === "running") return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-ring", "aria-hidden": "true" });
1398
+ if (status === "failed") return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-x", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IcX, { size: 13 }) });
1399
+ if (status === "stopped") return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-stopped", "aria-hidden": "true" });
1400
+ const Ic = KIND_ICON[kind] || IcTool;
1401
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-kind", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Ic, {}) });
1402
+ }
1403
+ function inputLines(d, item) {
1404
+ const a = parseToolArgs(item.args);
1405
+ if (d.kind === "shell") {
1406
+ const cmd = d.mono ? d.target : d.note || d.targetFull;
1407
+ const out = asLines(`$ ${cmd || ""}`, "is-cmd");
1408
+ if (!d.mono && d.target) out.unshift({ text: d.target, cls: "is-note" });
1409
+ return { lines: out, copy: cmd };
1410
+ }
1411
+ if ((d.kind === "edit" || d.kind === "write") && d.diff) {
1412
+ const lines = [];
1413
+ const path = d.targetFull;
1414
+ if (path) lines.push({ text: path, cls: "is-path" });
1415
+ const edits = Array.isArray(a.edits) ? a.edits : [a];
1416
+ for (const e of edits) {
1417
+ const old = e.old_string ?? e.old_str ?? e.oldText ?? e.old_text;
1418
+ const neu = e.new_string ?? e.new_str ?? e.newText ?? e.new_text ?? e.content ?? e.file_text ?? e.contents;
1419
+ if (old != null && String(old)) lines.push(...asLines(old, "is-del").map((l) => ({ ...l, text: `- ${l.text}` })));
1420
+ if (neu != null && String(neu)) lines.push(...asLines(neu, "is-add").map((l) => ({ ...l, text: `+ ${l.text}` })));
1421
+ }
1422
+ const patch = a.patch ?? a.input ?? a._raw ?? a.diff;
1423
+ if (lines.length <= (path ? 1 : 0) && typeof patch === "string") {
1424
+ for (const l of patch.split("\n")) lines.push({ text: l, cls: /^\+(?!\+\+)/.test(l) ? "is-add" : /^-(?!--)/.test(l) ? "is-del" : "" });
1425
+ }
1426
+ if (lines.length > (path ? 1 : 0)) return { lines, copy: typeof item.args === "string" ? item.args : JSON.stringify(a, null, 2) };
1427
+ }
1428
+ if (a._raw != null) return { lines: asLines(a._raw), copy: a._raw };
1429
+ const keys = Object.keys(a);
1430
+ const flat = keys.length && keys.every((k) => a[k] == null || typeof a[k] !== "object");
1431
+ if (flat) {
1432
+ const lines = [];
1433
+ for (const k of keys) {
1434
+ const v = a[k] == null ? "" : String(a[k]);
1435
+ const vs = v.split("\n");
1436
+ lines.push({ text: `${k}: ${vs[0]}`, cls: "is-kv" });
1437
+ for (const more of vs.slice(1)) lines.push({ text: ` ${more}`, cls: "is-kv" });
1438
+ }
1439
+ return { lines, copy: typeof item.args === "string" ? item.args : JSON.stringify(a, null, 2) };
1440
+ }
1441
+ const js = keys.length ? JSON.stringify(a, null, 2) : "";
1442
+ return { lines: js ? asLines(js) : [], copy: js };
1443
+ }
1444
+ function StepDetail(props) {
1445
+ const { item, d, labels, id } = props;
1446
+ const input = inputLines(d, item);
1447
+ const out = item.output === void 0 ? null : cleanOutput(item.output);
1448
+ const outPretty = out != null ? pretty(out) || out : null;
1449
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "uac-detail", id, children: [
1450
+ input.lines.length ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("section", { className: "uac-sec", children: [
1451
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("header", { children: [
1452
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: labels.input }),
1453
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CopyButton, { text: input.copy, labels })
1454
+ ] }),
1455
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LinesBlock, { lines: input.lines, limit: d.kind === "write" || d.kind === "edit" ? 24 : 12, labels })
1456
+ ] }) : null,
1457
+ outPretty != null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("section", { className: cls("uac-sec", item.status === "failed" && "is-failed"), children: [
1458
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("header", { children: [
1459
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: labels.output }),
1460
+ outPretty ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CopyButton, { text: outPretty, labels }) : null
1461
+ ] }),
1462
+ outPretty.trim() ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LinesBlock, { lines: asLines(outPretty), labels }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "uac-none", children: labels.noOutput }),
1463
+ item.truncated ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "uac-none", children: `${item.truncated} characters in all` }) : null
1464
+ ] }) : null
1465
+ ] });
1466
+ }
1467
+ function StepRow(props) {
1468
+ const { item, labels = DEFAULT_AGENT_LABELS, defaultOpen = false } = props;
1469
+ const d = (0, import_react3.useMemo)(() => describeTool(item.name, item.args), [item.name, item.args]);
1470
+ const [open, setOpen] = (0, import_react3.useState)(defaultOpen);
1471
+ const uid = (0, import_react3.useRef)(`uac-s-${Math.random().toString(36).slice(2, 9)}`).current;
1472
+ const running = item.status === "running";
1473
+ const runMs = useElapsed(running ? item.startedAt : null, null);
1474
+ const tookMs = !running && item.startedAt != null && item.endedAt != null ? item.endedAt - item.startedAt : null;
1475
+ const line = toolLine(d, running ? "running" : "done");
1476
+ const verb = running ? d.running : d.done;
1477
+ const hasTarget = d.target && line === `${verb} ${d.target}`;
1478
+ const note = !running && item.status !== "failed" ? resultNote(d.kind, item.output) : "";
1479
+ const hasDetail = !!(item.args && item.args !== "{}" && item.args !== '""') || item.output !== void 0;
1480
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: cls("uac-step", `is-${item.status}`), "data-kind": d.kind, children: [
1481
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1482
+ "button",
1483
+ {
1484
+ type: "button",
1485
+ className: "uac-step-h",
1486
+ "aria-expanded": hasDetail ? open : void 0,
1487
+ "aria-controls": hasDetail ? uid : void 0,
1488
+ disabled: !hasDetail,
1489
+ onClick: () => setOpen((v) => !v),
1490
+ title: d.targetFull || void 0,
1491
+ children: [
1492
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StatusGlyph, { status: item.status, kind: d.kind }),
1493
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "uac-step-t", children: [
1494
+ hasTarget ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1495
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-step-v", children: verb }),
1496
+ " ",
1497
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: cls("uac-step-o", d.mono && "is-mono"), children: d.target })
1498
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: cls("uac-step-o", d.kind === "shell" && d.mono && "is-mono"), children: line }),
1499
+ d.note && d.kind === "agent" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-step-n", children: d.note }) : null
1500
+ ] }),
1501
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DiffBadge, { diff: item.status === "failed" ? null : d.diff }),
1502
+ note ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-step-n", children: note }) : null,
1503
+ item.status === "stopped" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-step-n", children: labels.stoppedCall }) : null,
1504
+ running && runMs != null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-step-time", children: formatElapsed(runMs) }) : tookMs != null && tookMs >= 1e3 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-step-time", children: formatDuration(tookMs) }) : null,
1505
+ hasDetail ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-chev", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Chevron, { dir: open ? "down" : "right", size: 12 }) }) : null
1506
+ ]
1507
+ }
1508
+ ),
1509
+ item.status === "failed" && item.output ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-step-err", children: firstLine(item.output) }) : null,
1510
+ open && hasDetail ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StepDetail, { item, d, labels, id: uid }) : null
1511
+ ] });
1512
+ }
1513
+ function ThinkingRow(props) {
1514
+ const { item, labels = DEFAULT_AGENT_LABELS } = props;
1515
+ const [open, setOpen] = (0, import_react3.useState)(false);
1516
+ const uid = (0, import_react3.useRef)(`uac-t-${Math.random().toString(36).slice(2, 9)}`).current;
1517
+ const live = item.open && item.endedAt == null;
1518
+ const ms = !live && item.startedAt != null && item.endedAt != null ? item.endedAt - item.startedAt : null;
1519
+ const label = live ? labels.thinking : ms != null && ms >= 1e3 ? labels.thoughtFor(formatElapsed(ms)) : labels.thought;
1520
+ const has = !!String(item.text || "").trim();
1521
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: cls("uac-step", "is-thought", live && "is-running"), children: [
1522
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1523
+ "button",
1524
+ {
1525
+ type: "button",
1526
+ className: "uac-step-h",
1527
+ "aria-expanded": has ? open : void 0,
1528
+ "aria-controls": has ? uid : void 0,
1529
+ disabled: !has,
1530
+ onClick: () => setOpen((v) => !v),
1531
+ children: [
1532
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-kind", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IcThink, {}) }),
1533
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-step-t", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: cls("uac-step-v", live && "uac-shimmer"), "data-text": label, children: label }) }),
1534
+ has ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-chev", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Chevron, { dir: open ? "down" : "right", size: 12 }) }) : null
1535
+ ]
1536
+ }
1537
+ ),
1538
+ open && has ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-thought", id: uid, children: item.text }) : null
1539
+ ] });
1540
+ }
1541
+ function sumDiff(tools) {
1542
+ let added = 0;
1543
+ let removed = 0;
1544
+ let any = false;
1545
+ for (const t of tools) {
1546
+ if (t.status === "failed") continue;
1547
+ const d = describeTool(t.name, t.args).diff;
1548
+ if (d) {
1549
+ any = true;
1550
+ added += d.added;
1551
+ removed += d.removed;
1552
+ }
1553
+ }
1554
+ return any ? { added, removed } : null;
1555
+ }
1556
+ function WorkGroup(props) {
1557
+ const { items, live = false, liveLabel, start = null, mark, motion, labels = DEFAULT_AGENT_LABELS, defaultOpen = false } = props;
1558
+ const [open, setOpen] = (0, import_react3.useState)(defaultOpen);
1559
+ const uid = (0, import_react3.useRef)(`uac-g-${Math.random().toString(36).slice(2, 9)}`).current;
1560
+ const tools = items.filter((x) => x.kind === "tool");
1561
+ const thoughts = items.filter((x) => x.kind === "thinking");
1562
+ const failed = tools.filter((x) => x.status === "failed").length;
1563
+ let summary = "";
1564
+ if (tools.length) summary = summarizeCalls(tools);
1565
+ else if (thoughts.length) {
1566
+ const t = thoughts[0];
1567
+ const ms = t.startedAt != null && t.endedAt != null ? t.endedAt - t.startedAt : null;
1568
+ summary = ms != null && ms >= 1e3 ? labels.thoughtFor(formatElapsed(ms)) : labels.thought;
1569
+ }
1570
+ const diff = sumDiff(tools);
1571
+ if (!live && !tools.length && !thoughts.some((t) => String(t.text || "").trim())) return null;
1572
+ const body = open ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-calls", id: uid, children: items.map((it) => it.kind === "tool" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StepRow, { item: it, labels }, it.id) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ThinkingRow, { item: it, labels }, it.id)) }) : null;
1573
+ if (live) {
1574
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: cls("uac-group", "is-live", open && "is-open"), children: [
1575
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1576
+ WorkingIndicator,
1577
+ {
1578
+ mark,
1579
+ motion,
1580
+ start,
1581
+ label: liveLabel,
1582
+ onToggle: () => setOpen((v) => !v),
1583
+ expanded: open,
1584
+ controls: uid
1585
+ }
1586
+ ),
1587
+ body
1588
+ ] });
1589
+ }
1590
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: cls("uac-group", open && "is-open", failed && "has-failed"), children: [
1591
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", className: "uac-sum", "aria-expanded": open, "aria-controls": uid, onClick: () => setOpen((v) => !v), children: [
1592
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-sum-t", children: summary }),
1593
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DiffBadge, { diff }),
1594
+ failed ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-fail-n", children: labels.failedCalls(failed) }) : null,
1595
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-chev", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Chevron, { dir: open ? "down" : "right", size: 12 }) })
1596
+ ] }),
1597
+ body
1598
+ ] });
1599
+ }
1600
+ function TodoCard(props) {
1601
+ const { todos, labels = DEFAULT_AGENT_LABELS, running = false } = props;
1602
+ if (!todos || !todos.length) return null;
1603
+ const done = todos.filter((t) => t.status === "completed").length;
1604
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-todo", role: "group", "aria-label": `${labels.plan}: ${done} of ${todos.length} done`, children: todos.map((t, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: cls("uac-todo-i", `is-${t.status}`, !running && t.status === "in_progress" && "is-held"), children: [
1605
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-todo-m", "aria-hidden": "true", children: t.status === "completed" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { width: "10", height: "10", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3.4", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M5 12l5 5L20 7" }) }) : null }),
1606
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-todo-t", children: t.text })
1607
+ ] }, i)) });
1608
+ }
1609
+ var REDUCED = typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
1610
+ function StreamingText(props) {
1611
+ const { text, active, render } = props;
1612
+ const on = !!active && !REDUCED;
1613
+ const [n, setN] = (0, import_react3.useState)(() => text ? text.length : 0);
1614
+ const textRef = (0, import_react3.useRef)(text);
1615
+ textRef.current = text;
1616
+ const acc = (0, import_react3.useRef)(text ? text.length : 0);
1617
+ (0, import_react3.useEffect)(() => {
1618
+ if (!on) {
1619
+ const l = textRef.current ? textRef.current.length : 0;
1620
+ acc.current = l;
1621
+ setN(l);
1622
+ return void 0;
1623
+ }
1624
+ let raf;
1625
+ let prev = null;
1626
+ const tick = (t) => {
1627
+ if (prev == null) prev = t;
1628
+ const dt = Math.min(0.1, (t - prev) / 1e3);
1629
+ prev = t;
1630
+ const len = textRef.current ? textRef.current.length : 0;
1631
+ const gap = len - acc.current;
1632
+ if (gap > 0) {
1633
+ acc.current = Math.min(len, acc.current + Math.max(40, gap / 1.2) * dt);
1634
+ setN(Math.floor(acc.current));
1635
+ } else if (gap < 0) {
1636
+ acc.current = len;
1637
+ setN(len);
1638
+ }
1639
+ raf = requestAnimationFrame(tick);
1640
+ };
1641
+ raf = requestAnimationFrame(tick);
1642
+ return () => cancelAnimationFrame(raf);
1643
+ }, [on]);
1644
+ const shown = on ? String(text || "").slice(0, n) : String(text || "");
1645
+ const rendering = on && n < String(text || "").length;
1646
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: cls("uac-md", on && "is-streaming", rendering && "is-catching-up"), children: render ? render(shown) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-plain", children: shown }) });
1647
+ }
1648
+ function UserBubble(props) {
1649
+ const { user, renderFile, extra } = props;
1650
+ if (!user) return null;
1651
+ const files = user.files || [];
1652
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-user", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "uac-user-b", children: [
1653
+ extra,
1654
+ files.length ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-user-files", children: files.map((f, i) => {
1655
+ if (renderFile) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react3.default.Fragment, { children: renderFile(f, i) }, i);
1656
+ const img = f.src && (/^data:image\//.test(f.src) || /\.(png|jpe?g|gif|webp|svg)$/i.test(f.name || ""));
1657
+ return img ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("img", { className: "uac-user-img", src: f.src, alt: f.name }, i) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "uac-chip", children: [
1658
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IcPaperclip, { size: 12 }),
1659
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: f.name })
1660
+ ] }, i);
1661
+ }) }) : null,
1662
+ user.text ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-user-t", children: user.text }) : null
1663
+ ] }) });
1664
+ }
1665
+ function TurnOutcome(props) {
1666
+ const { turn, labels = DEFAULT_AGENT_LABELS, describeIncomplete } = props;
1667
+ if (!turn || turn.status === "running") return null;
1668
+ const ms = turn.startedAt != null && turn.endedAt != null ? turn.endedAt - turn.startedAt : turn.elapsedMs;
1669
+ const time = ms != null && ms >= 0 ? formatElapsed(ms) : "";
1670
+ const tok = turn.usage && (turn.usage.total_tokens ?? (turn.usage.input_tokens || 0) + (turn.usage.output_tokens || 0));
1671
+ const tokens = tok ? labels.tokens(formatTokens(tok)) : "";
1672
+ if (turn.status === "done") {
1673
+ if (!time && !tokens) return null;
1674
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-outcome", children: [time ? labels.workedFor(time) : labels.worked, tokens].filter(Boolean).join(" \xB7 ") });
1675
+ }
1676
+ if (turn.status === "cancelled") {
1677
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-outcome is-stopped", children: time ? labels.stoppedAfter(time) : labels.stopped });
1678
+ }
1679
+ if (turn.status === "incomplete") {
1680
+ const why = describeIncomplete ? describeIncomplete(turn.incomplete || {}) : turn.incomplete && turn.incomplete.detail || "";
1681
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "uac-outcome is-incomplete", children: [
1682
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
1683
+ labels.incomplete,
1684
+ time ? ` \xB7 ${time}` : ""
1685
+ ] }),
1686
+ why ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "uac-outcome-why", children: why }) : null
1687
+ ] });
1688
+ }
1689
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "uac-outcome is-failed", role: "status", children: [
1690
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: time ? labels.failedAfter(time) : labels.failed }),
1691
+ turn.error ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "uac-outcome-why", children: turn.error }) : null
1692
+ ] });
1693
+ }
1694
+ function AgentTurnView(props) {
1695
+ const {
1696
+ turn,
1697
+ renderMarkdown,
1698
+ mark,
1699
+ motion,
1700
+ labels: labelsIn,
1701
+ showUser = true,
1702
+ renderUserFile,
1703
+ userExtra,
1704
+ meta,
1705
+ renderFiles,
1706
+ actions,
1707
+ describeIncomplete,
1708
+ liveStart
1709
+ } = props;
1710
+ const labels = (0, import_react3.useMemo)(() => ({ ...DEFAULT_AGENT_LABELS, ...labelsIn || {} }), [labelsIn]);
1711
+ if (!turn) return null;
1712
+ const running = turn.status === "running";
1713
+ const segs = segments(turn);
1714
+ const plan = latestPlan(turn, describeTool);
1715
+ const now = liveState(turn);
1716
+ const start = liveStart ?? turn.startedAt;
1717
+ const lastSeg = segs[segs.length - 1];
1718
+ const liveWork = running && lastSeg && lastSeg.type === "work";
1719
+ let liveLabel = labels.thinking;
1720
+ if (now) {
1721
+ if (now.phase === "tool" && now.tool) liveLabel = toolLine(describeTool(now.tool.name, now.tool.args), "running");
1722
+ else if (now.phase === "writing") liveLabel = labels.writing;
1723
+ else if (now.phase === "starting") liveLabel = labels.starting;
1724
+ }
1725
+ const lastTextIdx = (() => {
1726
+ for (let i = segs.length - 1; i >= 0; i--) if (segs[i].type === "text") return i;
1727
+ return -1;
1728
+ })();
1729
+ const files = renderFiles ? renderFiles(turn) : null;
1730
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("article", { className: cls("uac-turn", `is-${turn.status}`), "data-status": turn.status, children: [
1731
+ showUser ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(UserBubble, { user: turn.user, renderFile: renderUserFile, extra: userExtra }) : null,
1732
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "uac-agent", children: [
1733
+ meta ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-meta", children: meta }) : null,
1734
+ segs.map((s, i) => {
1735
+ const isLive = liveWork && i === segs.length - 1;
1736
+ if (isLive) {
1737
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react3.default.Fragment, { children: [
1738
+ plan ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TodoCard, { todos: plan, labels, running: true }) : null,
1739
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(WorkGroup, { items: s.items, live: true, liveLabel, start, mark, motion, labels })
1740
+ ] }, `w${i}`);
1741
+ }
1742
+ if (s.type === "text") {
1743
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1744
+ StreamingText,
1745
+ {
1746
+ text: s.item.text,
1747
+ render: renderMarkdown,
1748
+ active: running && i === lastTextIdx && i === segs.length - 1
1749
+ },
1750
+ s.item.id || `t${i}`
1751
+ );
1752
+ }
1753
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(WorkGroup, { items: s.items, labels }, `w${i}-${s.items[0] && s.items[0].id}`);
1754
+ }),
1755
+ !liveWork && plan ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TodoCard, { todos: plan, labels, running }) : null,
1756
+ running && !liveWork ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(WorkingIndicator, { mark, motion, start, label: liveLabel }) : null,
1757
+ files,
1758
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TurnOutcome, { turn, labels, describeIncomplete }),
1759
+ !running && actions ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-actions", children: actions }) : null
1760
+ ] })
1761
+ ] });
1762
+ }
1763
+ function AgentComposer(props) {
1764
+ const {
1765
+ value,
1766
+ onChange,
1767
+ onSend,
1768
+ onStop,
1769
+ running = false,
1770
+ stopping = false,
1771
+ disabled = false,
1772
+ sendDisabled,
1773
+ placeholder,
1774
+ runningPlaceholder,
1775
+ attachments = [],
1776
+ onRemoveAttachment,
1777
+ onAttachFiles,
1778
+ accept,
1779
+ multiple = false,
1780
+ left,
1781
+ right,
1782
+ footer,
1783
+ inputId,
1784
+ inputRef,
1785
+ autoFocus,
1786
+ maxRows = 10,
1787
+ labels: labelsIn,
1788
+ ariaLabel,
1789
+ className
1790
+ } = props;
1791
+ const labels = { ...DEFAULT_AGENT_LABELS, ...labelsIn || {} };
1792
+ const own = (0, import_react3.useRef)(null);
1793
+ const ta = inputRef || own;
1794
+ const fileIn = (0, import_react3.useRef)(null);
1795
+ const root = (0, import_react3.useRef)(null);
1796
+ const [dropping, setDropping] = (0, import_react3.useState)(false);
1797
+ const grow = (0, import_react3.useCallback)(() => {
1798
+ const el = ta.current;
1799
+ if (!el) return;
1800
+ el.style.height = "auto";
1801
+ const cs = getComputedStyle(el);
1802
+ const lh = parseFloat(cs.lineHeight) || 22;
1803
+ const max = lh * maxRows + (parseFloat(cs.paddingTop) || 0) + (parseFloat(cs.paddingBottom) || 0);
1804
+ el.style.height = `${Math.min(el.scrollHeight, max)}px`;
1805
+ el.style.overflowY = el.scrollHeight > max ? "auto" : "hidden";
1806
+ }, [ta, maxRows]);
1807
+ (0, import_react3.useLayoutEffect)(grow, [value, grow]);
1808
+ const blocked = sendDisabled ?? (!String(value || "").trim() && !attachments.length);
1809
+ const send = () => {
1810
+ if (!running && !disabled && !blocked) onSend && onSend();
1811
+ };
1812
+ const files = (list) => {
1813
+ if (list && list.length && onAttachFiles) onAttachFiles(list);
1814
+ };
1815
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1816
+ "div",
1817
+ {
1818
+ ref: root,
1819
+ className: cls("uac-composer", running && "is-running", dropping && "is-dropping", disabled && "is-disabled", className),
1820
+ onDragOver: onAttachFiles ? (e) => {
1821
+ if (Array.from(e.dataTransfer.types || []).includes("Files")) {
1822
+ e.preventDefault();
1823
+ setDropping(true);
1824
+ }
1825
+ } : void 0,
1826
+ onDragLeave: onAttachFiles ? (e) => {
1827
+ if (!root.current || !root.current.contains(e.relatedTarget)) setDropping(false);
1828
+ } : void 0,
1829
+ onDrop: onAttachFiles ? (e) => {
1830
+ if (e.dataTransfer.files && e.dataTransfer.files.length) {
1831
+ e.preventDefault();
1832
+ setDropping(false);
1833
+ files(e.dataTransfer.files);
1834
+ }
1835
+ } : void 0,
1836
+ children: [
1837
+ attachments.length ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-atts", children: attachments.map((f, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: cls("uac-att", f.status && `is-${f.status}`), children: [
1838
+ f.src && /^(data:image\/|blob:)/.test(f.src) ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("img", { src: f.src, alt: "" }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IcPaperclip, { size: 13 }),
1839
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-att-n", children: f.name }),
1840
+ onRemoveAttachment ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", "aria-label": labels.remove(f.name), onClick: () => onRemoveAttachment(i), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IcX, { size: 12 }) }) : null
1841
+ ] }, f.id || i)) }) : null,
1842
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1843
+ "textarea",
1844
+ {
1845
+ id: inputId,
1846
+ ref: ta,
1847
+ rows: 1,
1848
+ value,
1849
+ autoFocus,
1850
+ disabled,
1851
+ placeholder: running && runningPlaceholder ? runningPlaceholder : placeholder,
1852
+ "aria-label": ariaLabel || placeholder,
1853
+ onChange: (e) => onChange && onChange(e.target.value),
1854
+ onPaste: onAttachFiles ? (e) => {
1855
+ const fl = e.clipboardData && e.clipboardData.files;
1856
+ if (fl && fl.length) {
1857
+ e.preventDefault();
1858
+ files(fl);
1859
+ }
1860
+ } : void 0,
1861
+ onKeyDown: (e) => {
1862
+ if (e.key !== "Enter" || e.shiftKey || e.nativeEvent && e.nativeEvent.isComposing) return;
1863
+ e.preventDefault();
1864
+ send();
1865
+ }
1866
+ }
1867
+ ),
1868
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "uac-composer-row", children: [
1869
+ onAttachFiles ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1870
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1871
+ "button",
1872
+ {
1873
+ type: "button",
1874
+ className: "uac-icon-btn",
1875
+ "aria-label": labels.attach,
1876
+ title: labels.attach,
1877
+ disabled,
1878
+ onClick: () => fileIn.current && fileIn.current.click(),
1879
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.1", strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 5v14M5 12h14" }) })
1880
+ }
1881
+ ),
1882
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1883
+ "input",
1884
+ {
1885
+ ref: fileIn,
1886
+ type: "file",
1887
+ hidden: true,
1888
+ accept,
1889
+ multiple,
1890
+ onChange: (e) => {
1891
+ files(e.target.files);
1892
+ e.target.value = "";
1893
+ }
1894
+ }
1895
+ )
1896
+ ] }) : null,
1897
+ left,
1898
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "uac-composer-sp" }),
1899
+ right,
1900
+ running ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1901
+ "button",
1902
+ {
1903
+ type: "button",
1904
+ className: "uac-send is-stop",
1905
+ "aria-label": stopping ? labels.stopping : labels.stop,
1906
+ title: labels.stop,
1907
+ disabled: stopping || !onStop,
1908
+ onClick: () => onStop && onStop(),
1909
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { viewBox: "0 0 24 24", width: "14", height: "14", fill: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { x: "6", y: "6", width: "12", height: "12", rx: "2.5" }) })
1910
+ }
1911
+ ) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "uac-send", "aria-label": labels.send, title: labels.send, disabled: disabled || blocked, onClick: send, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IcSend, {}) })
1912
+ ] }),
1913
+ footer ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-composer-foot", children: footer }) : null
1914
+ ]
1915
+ }
1916
+ );
1917
+ }
1918
+ function nearestScroller(el) {
1919
+ let n = el && el.parentElement;
1920
+ while (n && n !== document.body && n !== document.documentElement) {
1921
+ const s = getComputedStyle(n);
1922
+ if (/(auto|scroll|overlay)/.test(s.overflowY)) return n;
1923
+ n = n.parentElement;
1924
+ }
1925
+ return null;
1926
+ }
1927
+ function useStickToBottom(contentRef, opts = {}) {
1928
+ const { scroller = null, anchorRef = null, followKey, threshold = 80, enabled = true } = opts;
1929
+ const stick = (0, import_react3.useRef)(true);
1930
+ const [atBottom, setAtBottom] = (0, import_react3.useState)(true);
1931
+ const target = (0, import_react3.useRef)(null);
1932
+ const resolve = (0, import_react3.useCallback)(() => {
1933
+ target.current = scroller || (contentRef.current ? nearestScroller(contentRef.current) : null);
1934
+ return target.current;
1935
+ }, [scroller, contentRef]);
1936
+ const distance = () => {
1937
+ const a = anchorRef && anchorRef.current || contentRef.current;
1938
+ if (!a) return 0;
1939
+ const t = target.current;
1940
+ const viewBottom = t ? t.getBoundingClientRect().top + t.clientHeight : window.innerHeight;
1941
+ return a.getBoundingClientRect().bottom - viewBottom;
1942
+ };
1943
+ const toBottom = (0, import_react3.useCallback)((smooth = false) => {
1944
+ const d = distance();
1945
+ if (Math.abs(d) < 1) return;
1946
+ const behavior = smooth && !REDUCED ? "smooth" : "auto";
1947
+ const t = target.current;
1948
+ if (t) t.scrollBy({ top: d, behavior });
1949
+ else window.scrollBy({ top: d, behavior });
1950
+ }, []);
1951
+ (0, import_react3.useEffect)(() => {
1952
+ if (!enabled) return void 0;
1953
+ const t = resolve();
1954
+ const on = () => {
1955
+ const at = distance() < threshold;
1956
+ stick.current = at;
1957
+ setAtBottom(at);
1958
+ };
1959
+ const el = t || window;
1960
+ el.addEventListener("scroll", on, { passive: true });
1961
+ on();
1962
+ return () => el.removeEventListener("scroll", on);
1963
+ }, [enabled, resolve, threshold]);
1964
+ (0, import_react3.useEffect)(() => {
1965
+ const el = contentRef.current;
1966
+ if (!enabled || !el || typeof ResizeObserver === "undefined") return void 0;
1967
+ let quietUntil = 0;
1968
+ const touched = () => {
1969
+ quietUntil = Date.now() + 600;
1970
+ };
1971
+ el.addEventListener("pointerdown", touched, true);
1972
+ el.addEventListener("keydown", touched, true);
1973
+ const ro = new ResizeObserver(() => {
1974
+ if (!target.current && scroller == null) resolve();
1975
+ if (Date.now() < quietUntil) {
1976
+ stick.current = distance() < threshold;
1977
+ setAtBottom(stick.current);
1978
+ return;
1979
+ }
1980
+ if (stick.current) toBottom(false);
1981
+ });
1982
+ ro.observe(el);
1983
+ return () => {
1984
+ ro.disconnect();
1985
+ el.removeEventListener("pointerdown", touched, true);
1986
+ el.removeEventListener("keydown", touched, true);
1987
+ };
1988
+ }, [enabled, contentRef, toBottom, resolve, scroller, threshold]);
1989
+ (0, import_react3.useEffect)(() => {
1990
+ if (!enabled || followKey === void 0) return;
1991
+ resolve();
1992
+ stick.current = true;
1993
+ setAtBottom(true);
1994
+ toBottom(false);
1995
+ }, [followKey]);
1996
+ return { atBottom, toBottom: () => {
1997
+ stick.current = true;
1998
+ setAtBottom(true);
1999
+ toBottom(true);
2000
+ } };
2001
+ }
2002
+ function AgentConversation(props) {
2003
+ const { children, composer, notice, running = false, mark, motion, mode = "pane", followKey, labels: labelsIn, className, empty } = props;
2004
+ const labels = { ...DEFAULT_AGENT_LABELS, ...labelsIn || {} };
2005
+ const rootRef = (0, import_react3.useRef)(null);
2006
+ const scrollRef = (0, import_react3.useRef)(null);
2007
+ const contentRef = (0, import_react3.useRef)(null);
2008
+ const [scroller, setScroller] = (0, import_react3.useState)(null);
2009
+ (0, import_react3.useLayoutEffect)(() => {
2010
+ if (mode === "pane") setScroller(scrollRef.current);
2011
+ }, [mode]);
2012
+ const { atBottom, toBottom } = useStickToBottom(contentRef, {
2013
+ scroller: mode === "pane" ? scroller : null,
2014
+ followKey,
2015
+ anchorRef: mode === "page" ? rootRef : null,
2016
+ enabled: mode === "page" || !!scroller
2017
+ });
2018
+ (0, import_react3.useLayoutEffect)(() => {
2019
+ if (mode !== "page" || !rootRef.current) return void 0;
2020
+ const set = () => {
2021
+ const r = rootRef.current;
2022
+ if (!r) return;
2023
+ const sc = nearestScroller(r);
2024
+ const rect = r.getBoundingClientRect();
2025
+ const avail = sc ? sc.clientHeight - (rect.top - sc.getBoundingClientRect().top + sc.scrollTop) : window.innerHeight - (rect.top + window.scrollY);
2026
+ r.style.setProperty("--uac-fill", `${Math.max(240, Math.round(avail))}px`);
2027
+ };
2028
+ set();
2029
+ window.addEventListener("resize", set);
2030
+ const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(set) : null;
2031
+ if (ro && rootRef.current.parentElement) ro.observe(rootRef.current.parentElement);
2032
+ return () => {
2033
+ window.removeEventListener("resize", set);
2034
+ if (ro) ro.disconnect();
2035
+ };
2036
+ }, [mode]);
2037
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { ref: rootRef, className: cls("uac-convo", `is-${mode}`, className), children: [
2038
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: scrollRef, className: "uac-scroll", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: contentRef, className: "uac-thread", children: children || empty }) }),
2039
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "uac-dock", children: [
2040
+ !atBottom ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "uac-jump", "aria-label": labels.jump, title: labels.jump, onClick: toBottom, children: running ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(WorkingMark, { mark, motion, size: 16 }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 5v14M5 12l7 7 7-7" }) }) }) : null,
2041
+ notice ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "uac-notice", children: notice }) : null,
2042
+ composer
2043
+ ] })
2044
+ ] });
2045
+ }
2046
+ //# sourceMappingURL=agent-chat.cjs.map