@robota-sdk/agent-web-ui 3.0.0-beta.64

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,648 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ import ReactMarkdown from "react-markdown";
3
+ import remarkGfm from "remark-gfm";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/client/ws-session-client.ts
6
+ const RECONNECT_DELAY_MS = 2e3;
7
+ const MAX_RECONNECT_ATTEMPTS = 10;
8
+ function createWsSessionClient(url, callbacks) {
9
+ let ws = null;
10
+ let currentStatus = "disconnected";
11
+ let reconnectTimer = null;
12
+ let reconnectAttempts = 0;
13
+ let intentionalDisconnect = false;
14
+ function setStatus(s) {
15
+ currentStatus = s;
16
+ callbacks.onStatusChange(s);
17
+ }
18
+ function scheduleReconnect() {
19
+ if (intentionalDisconnect || reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) return;
20
+ reconnectTimer = setTimeout(() => {
21
+ reconnectAttempts++;
22
+ doConnect();
23
+ }, RECONNECT_DELAY_MS);
24
+ }
25
+ function doConnect() {
26
+ setStatus("connecting");
27
+ ws = new WebSocket(url);
28
+ ws.onopen = () => {
29
+ reconnectAttempts = 0;
30
+ setStatus("connected");
31
+ send({ type: "get-messages" });
32
+ };
33
+ ws.onmessage = (event) => {
34
+ const data = event.data;
35
+ if (typeof data !== "string") return;
36
+ const msg = JSON.parse(data);
37
+ callbacks.onMessage(msg);
38
+ };
39
+ ws.onclose = () => {
40
+ ws = null;
41
+ if (!intentionalDisconnect) {
42
+ setStatus("disconnected");
43
+ scheduleReconnect();
44
+ } else setStatus("disconnected");
45
+ };
46
+ ws.onerror = () => {
47
+ setStatus("error");
48
+ };
49
+ }
50
+ function connect() {
51
+ intentionalDisconnect = false;
52
+ if (reconnectTimer !== null) {
53
+ clearTimeout(reconnectTimer);
54
+ reconnectTimer = null;
55
+ }
56
+ doConnect();
57
+ }
58
+ function disconnect() {
59
+ intentionalDisconnect = true;
60
+ if (reconnectTimer !== null) {
61
+ clearTimeout(reconnectTimer);
62
+ reconnectTimer = null;
63
+ }
64
+ ws?.close();
65
+ ws = null;
66
+ setStatus("disconnected");
67
+ }
68
+ function send(msg) {
69
+ if (ws?.readyState === WebSocket.OPEN) ws.send(JSON.stringify(msg));
70
+ }
71
+ return {
72
+ connect,
73
+ disconnect,
74
+ send,
75
+ status: () => currentStatus
76
+ };
77
+ }
78
+ //#endregion
79
+ //#region src/hooks/useWsSession.ts
80
+ /**
81
+ * React hook that connects to an agent-cli sidecar WebSocket and
82
+ * reconstructs conversation state from TServerMessage events.
83
+ */
84
+ let msgCounter = 0;
85
+ function nextId() {
86
+ return `msg_${++msgCounter}_${Date.now()}`;
87
+ }
88
+ function useWsSession(url) {
89
+ const [status, setStatus] = useState("disconnected");
90
+ const [messages, setMessages] = useState([]);
91
+ const [activeTools, setActiveTools] = useState([]);
92
+ const [streamingText, setStreamingText] = useState("");
93
+ const [isThinking, setIsThinking] = useState(false);
94
+ const [executionWorkspace, setExecutionWorkspace] = useState(null);
95
+ const clientRef = useRef(null);
96
+ const streamingIdRef = useRef(null);
97
+ const streamingTextRef = useRef("");
98
+ const handleMessage = useCallback((msg) => {
99
+ switch (msg.type) {
100
+ case "messages":
101
+ setMessages(msg.messages.flatMap((m) => {
102
+ if (m.role !== "user" && m.role !== "assistant") return [];
103
+ const content = m.content ?? "";
104
+ return [{
105
+ id: nextId(),
106
+ role: m.role,
107
+ content
108
+ }];
109
+ }));
110
+ break;
111
+ case "user_message":
112
+ setMessages((prev) => [...prev, {
113
+ id: nextId(),
114
+ role: "user",
115
+ content: msg.content
116
+ }]);
117
+ break;
118
+ case "text_delta":
119
+ setStreamingText((prev) => {
120
+ const next = prev + msg.delta;
121
+ streamingTextRef.current = next;
122
+ if (streamingIdRef.current === null) streamingIdRef.current = nextId();
123
+ return next;
124
+ });
125
+ break;
126
+ case "thinking":
127
+ setIsThinking(msg.isThinking);
128
+ break;
129
+ case "tool_start": {
130
+ const { state } = msg;
131
+ const toolId = nextId();
132
+ setActiveTools((prev) => [...prev, {
133
+ id: toolId,
134
+ name: state.toolName,
135
+ status: "running",
136
+ input: state.firstArg
137
+ }]);
138
+ break;
139
+ }
140
+ case "tool_end": {
141
+ const { state } = msg;
142
+ setActiveTools((prev) => prev.map((t) => t.name === state.toolName && t.status === "running" ? {
143
+ ...t,
144
+ status: state.isRunning ? "running" : "done",
145
+ result: state.result
146
+ } : t));
147
+ break;
148
+ }
149
+ case "execution_workspace_event":
150
+ setExecutionWorkspace(msg.snapshot);
151
+ break;
152
+ case "complete":
153
+ case "interrupted": {
154
+ const finalText = streamingTextRef.current;
155
+ const sid = streamingIdRef.current;
156
+ streamingTextRef.current = "";
157
+ streamingIdRef.current = null;
158
+ setStreamingText("");
159
+ setIsThinking(false);
160
+ setActiveTools([]);
161
+ if (finalText) setMessages((prev) => [...prev, {
162
+ id: sid ?? nextId(),
163
+ role: "assistant",
164
+ content: finalText
165
+ }]);
166
+ break;
167
+ }
168
+ }
169
+ }, []);
170
+ const send = useCallback((msg) => {
171
+ clientRef.current?.send(msg);
172
+ }, []);
173
+ useEffect(() => {
174
+ const client = createWsSessionClient(url, {
175
+ onMessage: handleMessage,
176
+ onStatusChange: setStatus
177
+ });
178
+ clientRef.current = client;
179
+ client.connect();
180
+ return () => {
181
+ client.disconnect();
182
+ clientRef.current = null;
183
+ };
184
+ }, [url, handleMessage]);
185
+ return {
186
+ status,
187
+ messages,
188
+ activeTools,
189
+ streamingText,
190
+ isThinking,
191
+ executionWorkspace,
192
+ send
193
+ };
194
+ }
195
+ //#endregion
196
+ //#region src/components/ConversationView.tsx
197
+ function AgentMarkdown({ children }) {
198
+ return /* @__PURE__ */ jsx(ReactMarkdown, {
199
+ remarkPlugins: [remarkGfm],
200
+ components: {
201
+ h1: ({ children: c }) => /* @__PURE__ */ jsx("h1", {
202
+ className: "text-base font-bold mt-4 mb-2 text-foreground border-b border-border/50 pb-1.5",
203
+ children: c
204
+ }),
205
+ h2: ({ children: c }) => /* @__PURE__ */ jsx("h2", {
206
+ className: "text-sm font-semibold mt-3 mb-1.5 text-foreground",
207
+ children: c
208
+ }),
209
+ h3: ({ children: c }) => /* @__PURE__ */ jsx("h3", {
210
+ className: "text-sm font-medium mt-2 mb-1 text-muted-foreground",
211
+ children: c
212
+ }),
213
+ p: ({ children: c }) => /* @__PURE__ */ jsx("p", {
214
+ className: "mb-2 last:mb-0 leading-relaxed text-sm",
215
+ children: c
216
+ }),
217
+ pre: ({ children: c }) => /* @__PURE__ */ jsx("pre", {
218
+ className: "bg-black/30 border border-border/40 rounded-lg p-3 my-2 overflow-x-auto text-xs font-mono leading-relaxed",
219
+ children: c
220
+ }),
221
+ code: ({ className, children: c }) => {
222
+ return Boolean(className) ? /* @__PURE__ */ jsx("code", {
223
+ className: `font-mono leading-relaxed ${className ?? ""}`,
224
+ children: c
225
+ }) : /* @__PURE__ */ jsx("code", {
226
+ className: "font-mono text-[11px] bg-black/25 px-1.5 py-0.5 rounded text-amber-300/80 border border-border/30",
227
+ children: c
228
+ });
229
+ },
230
+ ul: ({ children: c }) => /* @__PURE__ */ jsx("ul", {
231
+ className: "list-disc list-outside ml-4 mb-2 space-y-0.5 text-sm",
232
+ children: c
233
+ }),
234
+ ol: ({ children: c }) => /* @__PURE__ */ jsx("ol", {
235
+ className: "list-decimal list-outside ml-4 mb-2 space-y-0.5 text-sm",
236
+ children: c
237
+ }),
238
+ li: ({ children: c }) => /* @__PURE__ */ jsx("li", {
239
+ className: "leading-relaxed",
240
+ children: c
241
+ }),
242
+ strong: ({ children: c }) => /* @__PURE__ */ jsx("strong", {
243
+ className: "font-semibold text-foreground",
244
+ children: c
245
+ }),
246
+ em: ({ children: c }) => /* @__PURE__ */ jsx("em", {
247
+ className: "italic text-muted-foreground/80",
248
+ children: c
249
+ }),
250
+ a: ({ href, children: c }) => /* @__PURE__ */ jsx("a", {
251
+ href,
252
+ className: "text-primary underline underline-offset-2 hover:opacity-75 transition-opacity",
253
+ target: "_blank",
254
+ rel: "noopener noreferrer",
255
+ children: c
256
+ }),
257
+ table: ({ children: c }) => /* @__PURE__ */ jsx("div", {
258
+ className: "overflow-x-auto my-2 rounded-lg border border-border/50",
259
+ children: /* @__PURE__ */ jsx("table", {
260
+ className: "w-full text-xs border-collapse",
261
+ children: c
262
+ })
263
+ }),
264
+ thead: ({ children: c }) => /* @__PURE__ */ jsx("thead", {
265
+ className: "bg-muted/40",
266
+ children: c
267
+ }),
268
+ th: ({ children: c }) => /* @__PURE__ */ jsx("th", {
269
+ className: "px-3 py-2 text-left font-medium text-muted-foreground border-b border-border/50 text-[11px] tracking-wide",
270
+ children: c
271
+ }),
272
+ td: ({ children: c }) => /* @__PURE__ */ jsx("td", {
273
+ className: "px-3 py-2 border-b border-border/30 text-xs last-of-type:border-0",
274
+ children: c
275
+ }),
276
+ blockquote: ({ children: c }) => /* @__PURE__ */ jsx("blockquote", {
277
+ className: "border-l-2 border-primary/40 pl-3 my-2 text-muted-foreground text-sm italic",
278
+ children: c
279
+ }),
280
+ hr: () => /* @__PURE__ */ jsx("hr", { className: "border-border/50 my-3" })
281
+ },
282
+ children
283
+ });
284
+ }
285
+ function UserBlock({ content }) {
286
+ return /* @__PURE__ */ jsxs("div", {
287
+ className: "flex flex-col gap-1",
288
+ children: [/* @__PURE__ */ jsx("span", {
289
+ className: "text-[10px] font-mono tracking-[0.14em] uppercase text-primary/50 px-1",
290
+ children: "You"
291
+ }), /* @__PURE__ */ jsx("div", {
292
+ className: "rounded-xl border border-primary/20 bg-primary/8 px-4 py-3 text-sm leading-relaxed text-foreground",
293
+ children: content
294
+ })]
295
+ });
296
+ }
297
+ function AgentBlock({ content, isStreaming = false }) {
298
+ return /* @__PURE__ */ jsxs("div", {
299
+ className: "flex flex-col gap-1",
300
+ children: [/* @__PURE__ */ jsx("span", {
301
+ className: "text-[10px] font-mono tracking-[0.14em] uppercase text-muted-foreground/50 px-1",
302
+ children: "Agent"
303
+ }), /* @__PURE__ */ jsxs("div", {
304
+ className: "rounded-xl border border-border/60 bg-card px-4 py-3 text-card-foreground",
305
+ children: [/* @__PURE__ */ jsx(AgentMarkdown, { children: content }), isStreaming && /* @__PURE__ */ jsx("span", { className: "inline-block w-[2px] h-[14px] bg-primary/60 ml-0.5 align-middle animate-pulse" })]
306
+ })]
307
+ });
308
+ }
309
+ function ToolCard({ tool }) {
310
+ const running = tool.status === "running";
311
+ return /* @__PURE__ */ jsxs("div", {
312
+ className: `flex items-center gap-2.5 rounded-lg border px-3.5 py-2 text-[11px] font-mono transition-colors ${running ? "bg-amber-500/5 border-amber-500/20 text-amber-300/80" : "bg-emerald-500/5 border-emerald-500/20 text-emerald-300/80"}`,
313
+ children: [
314
+ /* @__PURE__ */ jsx("span", { className: `h-1.5 w-1.5 rounded-full flex-shrink-0 ${running ? "bg-amber-400 animate-pulse" : "bg-emerald-400"}` }),
315
+ /* @__PURE__ */ jsx("span", {
316
+ className: "opacity-50",
317
+ children: running ? "▶" : "✓"
318
+ }),
319
+ /* @__PURE__ */ jsx("span", {
320
+ className: "font-medium tracking-wide",
321
+ children: tool.name
322
+ }),
323
+ typeof tool.input === "string" && tool.input && /* @__PURE__ */ jsx("span", {
324
+ className: "opacity-35 truncate max-w-[200px] text-[10px]",
325
+ children: tool.input
326
+ }),
327
+ /* @__PURE__ */ jsx("span", {
328
+ className: "ml-auto opacity-35 text-[10px]",
329
+ children: running ? "running…" : "done"
330
+ })
331
+ ]
332
+ });
333
+ }
334
+ function ThinkingIndicator() {
335
+ return /* @__PURE__ */ jsxs("div", {
336
+ className: "flex items-center gap-2.5 px-1",
337
+ children: [/* @__PURE__ */ jsx("span", {
338
+ className: "text-[10px] font-mono tracking-[0.14em] uppercase text-muted-foreground/50",
339
+ children: "Agent"
340
+ }), /* @__PURE__ */ jsx("div", {
341
+ className: "flex gap-1 items-center",
342
+ children: [
343
+ 0,
344
+ 1,
345
+ 2
346
+ ].map((i) => /* @__PURE__ */ jsx("span", {
347
+ className: "w-1.5 h-1.5 rounded-full bg-emerald-400/60 animate-bounce",
348
+ style: { animationDelay: `${i * 150}ms` }
349
+ }, i))
350
+ })]
351
+ });
352
+ }
353
+ function ConversationView({ messages, activeTools, streamingText, isThinking }) {
354
+ const bottomRef = useRef(null);
355
+ useEffect(() => {
356
+ bottomRef.current?.scrollIntoView({ behavior: "smooth" });
357
+ }, [
358
+ messages.length,
359
+ streamingText,
360
+ isThinking,
361
+ activeTools.length
362
+ ]);
363
+ return /* @__PURE__ */ jsxs("div", {
364
+ className: "flex flex-col gap-3 p-4 overflow-y-auto h-full",
365
+ children: [
366
+ messages.length === 0 && !isThinking && activeTools.length === 0 && !streamingText && /* @__PURE__ */ jsx("div", {
367
+ className: "flex h-full items-center justify-center",
368
+ children: /* @__PURE__ */ jsx("p", {
369
+ className: "text-xs font-mono text-muted-foreground/50 tracking-widest uppercase",
370
+ children: "No messages yet"
371
+ })
372
+ }),
373
+ messages.map((msg) => msg.role === "user" ? /* @__PURE__ */ jsx(UserBlock, { content: msg.content }, msg.id) : /* @__PURE__ */ jsx(AgentBlock, { content: msg.content }, msg.id)),
374
+ isThinking && !streamingText && /* @__PURE__ */ jsx(ThinkingIndicator, {}),
375
+ activeTools.map((tool) => /* @__PURE__ */ jsx(ToolCard, { tool }, tool.id)),
376
+ streamingText && /* @__PURE__ */ jsx(AgentBlock, {
377
+ content: streamingText,
378
+ isStreaming: true
379
+ }),
380
+ /* @__PURE__ */ jsx("div", { ref: bottomRef })
381
+ ]
382
+ });
383
+ }
384
+ //#endregion
385
+ //#region src/components/AgentActivityPanel.tsx
386
+ function AgentActivityPanel({ tasks, className }) {
387
+ const runningCount = tasks.filter((t) => t.status === "running").length;
388
+ return /* @__PURE__ */ jsxs("div", {
389
+ className: `flex flex-col overflow-hidden bg-card/10 ${className ?? ""}`,
390
+ children: [/* @__PURE__ */ jsxs("div", {
391
+ className: "px-3 py-2 border-b border-border/50 flex items-center gap-2 flex-shrink-0",
392
+ children: [
393
+ runningCount > 0 ? /* @__PURE__ */ jsxs("span", {
394
+ className: "relative flex h-1.5 w-1.5 flex-shrink-0",
395
+ children: [/* @__PURE__ */ jsx("span", { className: "animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-60" }), /* @__PURE__ */ jsx("span", { className: "relative inline-flex h-1.5 w-1.5 rounded-full bg-amber-500" })]
396
+ }) : /* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 rounded-full bg-zinc-600 flex-shrink-0" }),
397
+ /* @__PURE__ */ jsx("span", {
398
+ className: "text-[10px] font-mono font-semibold tracking-[0.14em] uppercase text-muted-foreground",
399
+ children: "Agents"
400
+ }),
401
+ runningCount > 0 && /* @__PURE__ */ jsxs("span", {
402
+ className: "ml-auto text-[10px] font-mono text-amber-400/70 tabular-nums",
403
+ children: [runningCount, " running"]
404
+ })
405
+ ]
406
+ }), /* @__PURE__ */ jsx("div", {
407
+ className: "flex-1 overflow-y-auto px-2 py-2 space-y-1.5",
408
+ children: tasks.map((entry) => /* @__PURE__ */ jsx(AgentCard, { entry }, entry.id))
409
+ })]
410
+ });
411
+ }
412
+ function AgentCard({ entry }) {
413
+ const tokens = getStatusTokens(entry.status, entry.attention);
414
+ return /* @__PURE__ */ jsxs("div", {
415
+ className: `relative rounded-md overflow-hidden border transition-opacity duration-500 ${tokens.cardCls} ${entry.status === "completed" ? "opacity-40" : ""}`,
416
+ children: [/* @__PURE__ */ jsx("div", { className: `absolute left-0 top-0 bottom-0 w-0.5 ${tokens.barCls}` }), /* @__PURE__ */ jsxs("div", {
417
+ className: "pl-3.5 pr-3 py-2",
418
+ children: [
419
+ /* @__PURE__ */ jsxs("div", {
420
+ className: "flex items-center gap-2",
421
+ children: [
422
+ /* @__PURE__ */ jsx(StatusDot, {
423
+ status: entry.status,
424
+ attention: entry.attention
425
+ }),
426
+ /* @__PURE__ */ jsx("span", {
427
+ className: "text-[11px] font-mono font-medium text-foreground/90 truncate flex-1 leading-none",
428
+ children: entry.title
429
+ }),
430
+ /* @__PURE__ */ jsx(AttentionTag, {
431
+ attention: entry.attention,
432
+ status: entry.status
433
+ })
434
+ ]
435
+ }),
436
+ entry.currentAction && /* @__PURE__ */ jsx("p", {
437
+ className: "text-[10px] text-foreground/50 leading-snug mt-1.5 truncate",
438
+ children: entry.currentAction
439
+ }),
440
+ entry.preview && /* @__PURE__ */ jsxs("p", {
441
+ className: "text-[10px] font-mono text-muted-foreground/40 leading-snug mt-0.5 truncate",
442
+ children: [
443
+ "“",
444
+ entry.preview,
445
+ "”"
446
+ ]
447
+ })
448
+ ]
449
+ })]
450
+ });
451
+ }
452
+ function StatusDot({ status, attention }) {
453
+ if (attention === "permission" || status === "waiting_permission") return /* @__PURE__ */ jsxs("span", {
454
+ className: "relative flex h-1.5 w-1.5 flex-shrink-0",
455
+ children: [/* @__PURE__ */ jsx("span", { className: "animate-ping absolute inline-flex h-full w-full rounded-full bg-rose-400 opacity-70" }), /* @__PURE__ */ jsx("span", { className: "relative inline-flex h-1.5 w-1.5 rounded-full bg-rose-500" })]
456
+ });
457
+ if (attention === "failed" || status === "failed") return /* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 rounded-full bg-rose-500 flex-shrink-0" });
458
+ if (status === "running") return /* @__PURE__ */ jsxs("span", {
459
+ className: "relative flex h-1.5 w-1.5 flex-shrink-0",
460
+ children: [/* @__PURE__ */ jsx("span", { className: "animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-55" }), /* @__PURE__ */ jsx("span", { className: "relative inline-flex h-1.5 w-1.5 rounded-full bg-amber-400" })]
461
+ });
462
+ if (status === "completed") return /* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 rounded-full bg-emerald-400/60 flex-shrink-0" });
463
+ return /* @__PURE__ */ jsx("span", { className: "h-1.5 w-1.5 rounded-full bg-zinc-600 flex-shrink-0" });
464
+ }
465
+ function AttentionTag({ attention, status }) {
466
+ if (attention === "permission" || status === "waiting_permission") return /* @__PURE__ */ jsx("span", {
467
+ className: "text-[9px] font-mono text-rose-400 bg-rose-500/10 border border-rose-500/25 px-1.5 py-px rounded flex-shrink-0",
468
+ children: "perm"
469
+ });
470
+ if (attention === "failed" || status === "failed") return /* @__PURE__ */ jsx("span", {
471
+ className: "text-[9px] font-mono text-rose-400 bg-rose-500/10 border border-rose-500/25 px-1.5 py-px rounded flex-shrink-0",
472
+ children: "err"
473
+ });
474
+ if (status === "completed") return /* @__PURE__ */ jsx("span", {
475
+ className: "text-[9px] font-mono text-emerald-400/50 flex-shrink-0",
476
+ children: "done"
477
+ });
478
+ if (status === "queued") return /* @__PURE__ */ jsx("span", {
479
+ className: "text-[9px] font-mono text-zinc-500 flex-shrink-0",
480
+ children: "queued"
481
+ });
482
+ return null;
483
+ }
484
+ function getStatusTokens(status, attention) {
485
+ if (attention === "permission" || status === "waiting_permission") return {
486
+ cardCls: "border-rose-500/40 bg-rose-950/10",
487
+ barCls: "bg-rose-400"
488
+ };
489
+ if (attention === "failed" || status === "failed") return {
490
+ cardCls: "border-rose-500/30 bg-rose-950/15",
491
+ barCls: "bg-rose-500"
492
+ };
493
+ if (status === "running") return {
494
+ cardCls: "border-amber-500/20 bg-card/30",
495
+ barCls: "bg-amber-400"
496
+ };
497
+ if (status === "completed") return {
498
+ cardCls: "border-border/20 bg-card/20",
499
+ barCls: "bg-emerald-400/50"
500
+ };
501
+ return {
502
+ cardCls: "border-border/30 bg-card/25",
503
+ barCls: "bg-zinc-600/50"
504
+ };
505
+ }
506
+ //#endregion
507
+ //#region src/components/SessionMonitor.tsx
508
+ const STATUS_CONFIG = {
509
+ connected: {
510
+ label: "Connected",
511
+ dot: "bg-emerald-400",
512
+ text: "text-emerald-400",
513
+ glow: "shadow-[0_0_7px_1px_rgba(52,211,153,0.55)]"
514
+ },
515
+ connecting: {
516
+ label: "Connecting…",
517
+ dot: "bg-amber-400 animate-pulse",
518
+ text: "text-amber-400",
519
+ glow: ""
520
+ },
521
+ disconnected: {
522
+ label: "Disconnected",
523
+ dot: "bg-zinc-600",
524
+ text: "text-zinc-500",
525
+ glow: ""
526
+ },
527
+ error: {
528
+ label: "Error",
529
+ dot: "bg-rose-500",
530
+ text: "text-rose-400",
531
+ glow: ""
532
+ }
533
+ };
534
+ function SessionMonitor({ wsUrl, className }) {
535
+ const [url, setUrl] = useState(wsUrl);
536
+ const [inputUrl, setInputUrl] = useState(wsUrl);
537
+ const { status, messages, activeTools, streamingText, isThinking, executionWorkspace, send } = useWsSession(url);
538
+ const cfg = STATUS_CONFIG[status] ?? STATUS_CONFIG.disconnected;
539
+ const backgroundTasks = executionWorkspace?.entries.filter((e) => e.kind === "background_task" && e.visibility !== "collapsed") ?? [];
540
+ const hasAgents = backgroundTasks.length > 0;
541
+ return /* @__PURE__ */ jsxs("div", {
542
+ className: `flex flex-col h-full overflow-hidden bg-background ${className ?? ""}`,
543
+ children: [/* @__PURE__ */ jsxs("div", {
544
+ className: "flex items-center gap-3 border-b border-border/50 px-4 py-2.5 bg-card/30 flex-shrink-0",
545
+ children: [/* @__PURE__ */ jsxs("div", {
546
+ className: "flex items-center gap-2.5",
547
+ children: [
548
+ /* @__PURE__ */ jsx("span", { className: `h-2 w-2 rounded-full flex-shrink-0 ${cfg.dot} ${cfg.glow}` }),
549
+ /* @__PURE__ */ jsx("span", {
550
+ className: "text-[11px] font-mono font-semibold tracking-[0.14em] uppercase text-foreground/70",
551
+ children: "CLI Monitor"
552
+ }),
553
+ /* @__PURE__ */ jsx("span", {
554
+ className: "text-border/60 font-mono text-xs",
555
+ children: "·"
556
+ }),
557
+ /* @__PURE__ */ jsx("span", {
558
+ className: `text-[11px] font-mono ${cfg.text}`,
559
+ children: cfg.label
560
+ })
561
+ ]
562
+ }), /* @__PURE__ */ jsxs("div", {
563
+ className: "ml-auto flex items-center gap-2",
564
+ children: [/* @__PURE__ */ jsx("input", {
565
+ className: "h-7 rounded-lg border border-border/60 bg-background/60 px-2.5 text-[11px] font-mono text-foreground/70 placeholder:text-muted-foreground/35 focus:outline-none focus:border-primary/50 focus:ring-1 focus:ring-primary/15 w-52 transition-all",
566
+ value: inputUrl,
567
+ onChange: (e) => setInputUrl(e.target.value),
568
+ onKeyDown: (e) => {
569
+ if (e.key === "Enter") setUrl(inputUrl);
570
+ },
571
+ placeholder: "ws://localhost:7070"
572
+ }), /* @__PURE__ */ jsx("button", {
573
+ className: "h-7 rounded-lg border border-border/60 px-3 text-[11px] font-mono text-muted-foreground hover:text-foreground hover:border-primary/40 hover:bg-primary/5 transition-all",
574
+ onClick: () => setUrl(inputUrl),
575
+ children: "Connect"
576
+ })]
577
+ })]
578
+ }), /* @__PURE__ */ jsxs("div", {
579
+ className: "flex flex-1 overflow-hidden",
580
+ children: [/* @__PURE__ */ jsxs("div", {
581
+ className: `flex flex-col overflow-hidden min-w-0 ${hasAgents ? "flex-[2]" : "flex-1"}`,
582
+ children: [/* @__PURE__ */ jsx("div", {
583
+ className: "flex-1 overflow-hidden",
584
+ children: status === "disconnected" || status === "connecting" ? /* @__PURE__ */ jsx("div", {
585
+ className: "flex h-full items-center justify-center",
586
+ children: /* @__PURE__ */ jsxs("div", {
587
+ className: "flex flex-col items-center gap-3 text-center px-8",
588
+ children: [/* @__PURE__ */ jsx("div", {
589
+ className: "h-9 w-9 rounded-full border border-border/50 flex items-center justify-center",
590
+ children: /* @__PURE__ */ jsx("span", { className: `h-2.5 w-2.5 rounded-full ${cfg.dot}` })
591
+ }), /* @__PURE__ */ jsx("p", {
592
+ className: "text-xs font-mono text-muted-foreground max-w-[260px] leading-relaxed",
593
+ children: status === "connecting" ? `Connecting to ${url}…` : `Run robota to start the CLI (WS transport starts automatically).`
594
+ })]
595
+ })
596
+ }) : /* @__PURE__ */ jsx(ConversationView, {
597
+ messages,
598
+ activeTools,
599
+ streamingText,
600
+ isThinking
601
+ })
602
+ }), /* @__PURE__ */ jsx(SessionInput, {
603
+ enabled: status === "connected",
604
+ onSubmit: (prompt) => send({
605
+ type: "submit",
606
+ prompt
607
+ })
608
+ })]
609
+ }), hasAgents && /* @__PURE__ */ jsx(AgentActivityPanel, {
610
+ tasks: backgroundTasks,
611
+ className: "flex-1 border-l border-border/50"
612
+ })]
613
+ })]
614
+ });
615
+ }
616
+ function SessionInput({ enabled, onSubmit }) {
617
+ const [value, setValue] = useState("");
618
+ const handleSubmit = () => {
619
+ const trimmed = value.trim();
620
+ if (!trimmed) return;
621
+ onSubmit(trimmed);
622
+ setValue("");
623
+ };
624
+ return /* @__PURE__ */ jsxs("div", {
625
+ className: "border-t border-border/50 px-3 py-2.5 flex gap-2 items-end bg-card/20 flex-shrink-0",
626
+ children: [/* @__PURE__ */ jsx("textarea", {
627
+ className: "flex-1 resize-none rounded-xl border border-border/60 bg-background/50 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground/35 focus:outline-none focus:border-primary/45 focus:ring-1 focus:ring-primary/15 min-h-[36px] max-h-[120px] transition-all font-[inherit] leading-relaxed",
628
+ rows: 1,
629
+ placeholder: enabled ? "Send a message…" : "Connect to send messages",
630
+ disabled: !enabled,
631
+ value,
632
+ onChange: (e) => setValue(e.target.value),
633
+ onKeyDown: (e) => {
634
+ if (e.key === "Enter" && !e.shiftKey) {
635
+ e.preventDefault();
636
+ handleSubmit();
637
+ }
638
+ }
639
+ }), /* @__PURE__ */ jsx("button", {
640
+ className: "h-9 rounded-xl border border-border/60 px-3.5 text-[11px] font-mono text-muted-foreground hover:text-foreground hover:border-primary/40 hover:bg-primary/5 transition-all disabled:opacity-25 disabled:cursor-not-allowed",
641
+ disabled: !enabled || !value.trim(),
642
+ onClick: handleSubmit,
643
+ children: "Send"
644
+ })]
645
+ });
646
+ }
647
+ //#endregion
648
+ export { ConversationView, SessionMonitor, useWsSession };