@tangle-network/sandbox-ui 7.0.0 → 7.0.1

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,957 @@
1
+ import { i as e } from "./rolldown-runtime-CwxnZyOB.js";
2
+ import { $ as t, A as n, C as r, D as i, Dt as a, E as o, Et as s, F as c, L as l, M as u, P as d, S as ee, T as te, Wt as f, _ as p, a as m, at as h, b as g, d as ne, f as _, g as re, h as ie, i as v, j as y, k as b, l as x, lt as S, n as C, p as ae, pt as oe, r as w, s as T, st as E, t as se, u as ce, ut as le, v as ue, w as de, x as D, y as fe, z as pe, zt as O } from "./latest-events-CMbdBLcT-uhVN4JLh.js";
3
+ // node_modules/.pnpm/@tangle-network+charts@4.0.15_@tangle-network+brand@1.31.3_react@19.3.1__@tangle-networ_73d1ae3d4127e224bdd384365224d35e/node_modules/@tangle-network/charts/dist/AgentGraphCanvas-xHVW-YRV.js
4
+ var k = O(), A = /* @__PURE__ */ e(f(), 1), j = {
5
+ name: "book-open",
6
+ size: 24,
7
+ node: [["path", {
8
+ d: "M12 5v16",
9
+ key: "1f6ucr"
10
+ }], ["path", {
11
+ d: "M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z",
12
+ key: "1fyvmf"
13
+ }]]
14
+ };
15
+ j.node;
16
+ var me = g(j), M = {
17
+ name: "brain",
18
+ size: 24,
19
+ node: [
20
+ ["path", {
21
+ d: "M12 18V5",
22
+ key: "adv99a"
23
+ }],
24
+ ["path", {
25
+ d: "M15 13a4.17 4.17 0 01-3-4 4.17 4.17 0 01-3 4",
26
+ key: "5nuw1p"
27
+ }],
28
+ ["path", {
29
+ d: "M17.707 6.294A3 3 0 1012 5a3 3 0 10-5.707 1.294",
30
+ key: "18ldcf"
31
+ }],
32
+ ["path", {
33
+ d: "M17.996 5.125a4 4 0 012.526 5.77",
34
+ key: "1sdu8q"
35
+ }],
36
+ ["path", {
37
+ d: "M18 18a4 4 0 002-7.465",
38
+ key: "7xqqvr"
39
+ }],
40
+ ["path", {
41
+ d: "M19.967 17.482a4 4 0 11-7.967.517 4 4 0 11-7.967-.517",
42
+ key: "t46ysz"
43
+ }],
44
+ ["path", {
45
+ d: "M6 18a4 4 0 01-2-7.465",
46
+ key: "1y2m15"
47
+ }],
48
+ ["path", {
49
+ d: "M6.004 5.125a4 4 0 00-2.526 5.77",
50
+ key: "3cw1ss"
51
+ }]
52
+ ]
53
+ };
54
+ M.node;
55
+ var N = g(M), P = {
56
+ name: "flask-conical",
57
+ size: 24,
58
+ node: [
59
+ ["path", {
60
+ d: "M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2",
61
+ key: "18mbvz"
62
+ }],
63
+ ["path", {
64
+ d: "M6.453 15h11.094",
65
+ key: "3shlmq"
66
+ }],
67
+ ["path", {
68
+ d: "M8.5 2h7",
69
+ key: "csnxdl"
70
+ }]
71
+ ]
72
+ };
73
+ P.node;
74
+ var he = g(P), F = {
75
+ name: "hammer",
76
+ size: 24,
77
+ node: [
78
+ ["path", {
79
+ d: "m15 12-9.373 9.373a1 1 0 0 1-3.001-3L12 9",
80
+ key: "1hayfq"
81
+ }],
82
+ ["path", {
83
+ d: "m18 15 4-4",
84
+ key: "16gjal"
85
+ }],
86
+ ["path", {
87
+ d: "m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172v-.344a2 2 0 0 0-.586-1.414l-1.657-1.657A6 6 0 0 0 12.516 3H9l1.243 1.243A6 6 0 0 1 12 8.485V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5",
88
+ key: "15ts47"
89
+ }]
90
+ ]
91
+ };
92
+ F.node;
93
+ var I = g(F), L = {
94
+ name: "hourglass",
95
+ size: 24,
96
+ node: [
97
+ ["path", {
98
+ d: "M5 22h14",
99
+ key: "ehvnwv"
100
+ }],
101
+ ["path", {
102
+ d: "M5 2h14",
103
+ key: "pdyrp9"
104
+ }],
105
+ ["path", {
106
+ d: "M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22",
107
+ key: "1d314k"
108
+ }],
109
+ ["path", {
110
+ d: "M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2",
111
+ key: "1vvvr6"
112
+ }]
113
+ ]
114
+ };
115
+ L.node;
116
+ var ge = g(L), R = {
117
+ name: "message-square",
118
+ size: 24,
119
+ node: [["path", {
120
+ d: "M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",
121
+ key: "18887p"
122
+ }]]
123
+ };
124
+ R.node;
125
+ var z = g(R), B = {
126
+ name: "pen-line",
127
+ size: 24,
128
+ node: [["path", {
129
+ d: "M13 21h8",
130
+ key: "1jsn5i"
131
+ }], ["path", {
132
+ d: "M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",
133
+ key: "1a8usu"
134
+ }]],
135
+ aliases: ["edit-3"]
136
+ };
137
+ B.node;
138
+ var V = g(B), H = {
139
+ name: "repeat",
140
+ size: 24,
141
+ node: [
142
+ ["path", {
143
+ d: "m17 2 4 4-4 4",
144
+ key: "nntrym"
145
+ }],
146
+ ["path", {
147
+ d: "M3 11v-1a4 4 0 0 1 4-4h14",
148
+ key: "84bu3i"
149
+ }],
150
+ ["path", {
151
+ d: "m7 22-4-4 4-4",
152
+ key: "1wqhfi"
153
+ }],
154
+ ["path", {
155
+ d: "M21 13v1a4 4 0 0 1-4 4H3",
156
+ key: "1rx37r"
157
+ }]
158
+ ]
159
+ };
160
+ H.node;
161
+ var _e = g(H), U = {
162
+ name: "rotate-ccw",
163
+ size: 24,
164
+ node: [["path", {
165
+ d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",
166
+ key: "1357e3"
167
+ }], ["path", {
168
+ d: "M3 3v5h5",
169
+ key: "1xhq8a"
170
+ }]]
171
+ };
172
+ U.node;
173
+ var W = g(U), G = {
174
+ name: "scan-search",
175
+ size: 24,
176
+ node: [
177
+ ["path", {
178
+ d: "M3 7V5a2 2 0 0 1 2-2h2",
179
+ key: "aa7l1z"
180
+ }],
181
+ ["path", {
182
+ d: "M17 3h2a2 2 0 0 1 2 2v2",
183
+ key: "4qcy5o"
184
+ }],
185
+ ["path", {
186
+ d: "M21 17v2a2 2 0 0 1-2 2h-2",
187
+ key: "6vwrx8"
188
+ }],
189
+ ["path", {
190
+ d: "M7 21H5a2 2 0 0 1-2-2v-2",
191
+ key: "ioqczr"
192
+ }],
193
+ ["circle", {
194
+ cx: "12",
195
+ cy: "12",
196
+ r: "3",
197
+ key: "1v7zrd"
198
+ }],
199
+ ["path", {
200
+ d: "m16 16-1.9-1.9",
201
+ key: "1dq9hf"
202
+ }]
203
+ ]
204
+ };
205
+ G.node;
206
+ var ve = g(G), ye = {
207
+ name: "test-tubes",
208
+ size: 24,
209
+ node: [
210
+ ["path", {
211
+ d: "M9 2v17.5A2.5 2.5 0 0 1 6.5 22A2.5 2.5 0 0 1 4 19.5V2",
212
+ key: "1hjrqt"
213
+ }],
214
+ ["path", {
215
+ d: "M20 2v17.5a2.5 2.5 0 0 1-2.5 2.5a2.5 2.5 0 0 1-2.5-2.5V2",
216
+ key: "16lc8n"
217
+ }],
218
+ ["path", {
219
+ d: "M3 2h7",
220
+ key: "7s29d5"
221
+ }],
222
+ ["path", {
223
+ d: "M14 2h7",
224
+ key: "7sicin"
225
+ }],
226
+ ["path", {
227
+ d: "M9 16H4",
228
+ key: "1bfye3"
229
+ }],
230
+ ["path", {
231
+ d: "M20 16h-5",
232
+ key: "ddnjpe"
233
+ }]
234
+ ]
235
+ };
236
+ ye.node;
237
+ var K = g(ye), q = {
238
+ thinking: {
239
+ label: "Thinking",
240
+ icon: N
241
+ },
242
+ reading: {
243
+ label: "Reading",
244
+ icon: me
245
+ },
246
+ building: {
247
+ label: "Building",
248
+ icon: I
249
+ },
250
+ proving: {
251
+ label: "Proving",
252
+ icon: he
253
+ },
254
+ writing: {
255
+ label: "Writing",
256
+ icon: V
257
+ },
258
+ waiting: {
259
+ label: "Waiting",
260
+ icon: ge
261
+ },
262
+ restarting: {
263
+ label: "Restarting",
264
+ icon: W
265
+ },
266
+ testing: {
267
+ label: "Testing",
268
+ icon: K
269
+ },
270
+ messaging: {
271
+ label: "Messaging",
272
+ icon: z
273
+ },
274
+ reviewing: {
275
+ label: "Reviewing",
276
+ icon: ve
277
+ },
278
+ looping: {
279
+ label: "Looping",
280
+ icon: _e
281
+ }
282
+ };
283
+ function J({ agent: e }) {
284
+ let t = e.activity && q[e.activity], n = e.activityCalibrated === !1;
285
+ return t ? /* @__PURE__ */ (0, k.jsxs)("span", {
286
+ className: "ag-live-activity",
287
+ "data-calibrated": n ? "false" : void 0,
288
+ "data-serious": !n && e.activity === "looping" ? "" : void 0,
289
+ title: `${t.label}${n ? " · uncalibrated classifier" : ""}`,
290
+ children: [
291
+ /* @__PURE__ */ (0, k.jsx)(t.icon, {
292
+ size: 12,
293
+ strokeWidth: 1.75,
294
+ "aria-hidden": !0
295
+ }),
296
+ t.label,
297
+ n && /* @__PURE__ */ (0, k.jsx)("small", {
298
+ className: "ag-live-badge",
299
+ children: "uncalibrated"
300
+ })
301
+ ]
302
+ }) : null;
303
+ }
304
+ function be({ agent: e, selected: r, direction: i = "TB", now: a, handles: o = !1, onOpen: s, parentLabel: c, renderEventIcon: l }) {
305
+ let u = oe(a), te = (0, A.useRef)(null);
306
+ S(te, e.status);
307
+ let f = e.status === "failed", m = f || e.status === "done" || e.status === "stopped", h = pe(e, u), g = p(e.status), ne = [e.model ? t(e.model) : void 0, e.effort].filter(Boolean).join(" · "), _ = (e.events ?? []).slice(-1), v = ee(e.costUsd), y = [
308
+ v,
309
+ e.startedAt == null ? void 0 : `${d(e.startedAt, u, !1)} elapsed`,
310
+ Number.isFinite(e.commits) ? `${e.commits} ${e.commits === 1 ? "commit" : "commits"}` : void 0
311
+ ].filter(Boolean).join(" · "), C = f ? D(e) : m ? e.result ?? void 0 : e.turn ?? void 0;
312
+ return /* @__PURE__ */ (0, k.jsxs)("div", {
313
+ className: "ag-live-slot",
314
+ children: [o && /* @__PURE__ */ (0, k.jsx)(x, { direction: i }), /* @__PURE__ */ (0, k.jsxs)("div", {
315
+ ref: te,
316
+ className: `ag-live-card${m ? " ag-live-chip" : ""}`,
317
+ "data-status": e.status,
318
+ "data-sparse": _.length === 0 || void 0,
319
+ "data-activity": h ? "quiet" : e.activity ?? void 0,
320
+ "data-selected": r || void 0,
321
+ title: re(e),
322
+ style: {
323
+ boxShadow: b,
324
+ ...fe(e.status),
325
+ ...r ? n : {},
326
+ "--ag-status": g.color
327
+ },
328
+ children: [
329
+ /* @__PURE__ */ (0, k.jsxs)("div", {
330
+ className: "ag-live-head",
331
+ children: [
332
+ /* @__PURE__ */ (0, k.jsx)("span", {
333
+ className: "ag-live-glyph",
334
+ title: h?.label ?? g.label,
335
+ children: /* @__PURE__ */ (0, k.jsx)(ae, {
336
+ status: e.status,
337
+ size: 14
338
+ })
339
+ }),
340
+ /* @__PURE__ */ (0, k.jsxs)("span", {
341
+ className: "ag-live-name",
342
+ children: [c && /* @__PURE__ */ (0, k.jsxs)("span", {
343
+ className: "ag-parent-label",
344
+ children: [c, " / "]
345
+ }), e.label]
346
+ }),
347
+ m ? v && /* @__PURE__ */ (0, k.jsx)("span", {
348
+ className: "ag-live-chip-cost",
349
+ title: "Cost",
350
+ children: v
351
+ }) : h && /* @__PURE__ */ (0, k.jsx)("span", {
352
+ className: "ag-live-quiet",
353
+ children: h.label
354
+ })
355
+ ]
356
+ }),
357
+ !m && (ne || y) && /* @__PURE__ */ (0, k.jsx)("span", {
358
+ className: "ag-live-meta",
359
+ title: [ne, y].filter(Boolean).join(" · "),
360
+ children: [ne, y].filter(Boolean).join(" · ")
361
+ }),
362
+ (C || !m) && /* @__PURE__ */ (0, k.jsxs)("div", {
363
+ className: "ag-live-thinking-row",
364
+ children: [
365
+ C && /* @__PURE__ */ (0, k.jsx)("p", {
366
+ className: `ag-live-thinking${f ? " ag-live-failure" : ""}`,
367
+ title: C,
368
+ children: E(C)
369
+ }),
370
+ !m && /* @__PURE__ */ (0, k.jsx)(J, { agent: e }),
371
+ e.status === "needs-you" && /* @__PURE__ */ (0, k.jsx)("button", {
372
+ type: "button",
373
+ className: "ag-live-respond nodrag nopan",
374
+ disabled: !s,
375
+ title: s ? void 0 : "Responses unavailable in this view",
376
+ onClick: (e) => {
377
+ e.stopPropagation(), s?.();
378
+ },
379
+ children: "Respond"
380
+ })
381
+ ]
382
+ }),
383
+ !m && _.length > 0 && /* @__PURE__ */ (0, k.jsx)("ol", {
384
+ className: "ag-live-events",
385
+ "aria-label": "Latest events",
386
+ children: _.map((e) => /* @__PURE__ */ (0, k.jsxs)("li", {
387
+ title: e.label,
388
+ children: [
389
+ l?.(e) ?? /* @__PURE__ */ (0, k.jsx)(ie, {
390
+ size: 12,
391
+ strokeWidth: 1.75,
392
+ "aria-hidden": !0
393
+ }),
394
+ /* @__PURE__ */ (0, k.jsx)("span", {
395
+ className: "ag-live-event-label",
396
+ children: E(e.label)
397
+ }),
398
+ /* @__PURE__ */ (0, k.jsx)("time", {
399
+ className: "ag-live-event-at",
400
+ dateTime: Number.isFinite(e.at) ? new Date(e.at).toISOString() : void 0,
401
+ children: d(e.at, u)
402
+ })
403
+ ]
404
+ }, e.id))
405
+ })
406
+ ]
407
+ })]
408
+ });
409
+ }
410
+ function xe({ data: e }) {
411
+ return /* @__PURE__ */ (0, k.jsx)(be, {
412
+ ...e,
413
+ handles: !0
414
+ });
415
+ }
416
+ var Se = {
417
+ agent: w,
418
+ liveAgent: xe,
419
+ agentFrame: m
420
+ }, Ce = { agentMessage: T }, Y = 16, X = 24, we = .8;
421
+ function Te() {
422
+ let [e, t] = (0, A.useState)(null), n = (0, A.useRef)(null);
423
+ return [e, (0, A.useCallback)((e) => {
424
+ if (n.current?.disconnect(), n.current = null, !e || typeof ResizeObserver > "u") return;
425
+ let r = e.querySelector(".ag-graph-viewport") ?? e, i = () => {
426
+ let e = r.getBoundingClientRect();
427
+ e.width !== 0 && e.height !== 0 && t((t) => t && Math.abs(t.width - e.width) < 1 && Math.abs(t.height - e.height) < 1 ? t : {
428
+ width: e.width,
429
+ height: e.height
430
+ });
431
+ };
432
+ n.current = new ResizeObserver(i), n.current.observe(r), i();
433
+ }, [])];
434
+ }
435
+ function Ee(e, t, n) {
436
+ let r = e.getInternalNode(n), i = t?.querySelector(".ag-graph-viewport")?.getBoundingClientRect(), a = r?.measured.width ?? r?.width, o = r?.measured.height ?? r?.height;
437
+ if (!r || !i || !a || !o) return;
438
+ let s = e.getViewport(), c = r.internals.positionAbsolute, l = s.zoom, u = Math.max(Y - c.x * l, Math.min(i.width - Y - (c.x + a) * l, s.x)), d = Math.max(Y - c.y * l, Math.min(i.height - Y - (c.y + o) * l, s.y));
439
+ (u !== s.x || d !== s.y || l !== s.zoom) && e.setViewport({
440
+ x: u,
441
+ y: d,
442
+ zoom: l
443
+ });
444
+ }
445
+ function De({ nodes: e, edges: t, selectedId: n, onSelect: a, direction: c = "TB", className: d, emptyState: ee, live: f = !1, renderEventIcon: m, showLatestEvents: g = !0, now: ie }) {
446
+ let b = f ? ce : se, x = oe(ie), S = le(), w = (0, A.useId)(), T = (0, A.useRef)(null), E = (0, A.useRef)(!1), [D, fe] = (0, A.useState)(null), O = () => fe(null), [j, me] = (0, A.useState)(/* @__PURE__ */ new Set()), [M, N] = (0, A.useState)(0), [P, he] = (0, A.useState)(null), F = (0, A.useRef)(null), I = (0, A.useMemo)(() => D && y(D.anchor, F.current?.querySelector(".ag-graph-viewport") ?? null), [D]), [L, ge] = Te(), R = l(F, e.length > 0), z = L !== null && L.width < 600, B = ue(e, t), V = (0, A.useRef)(B);
447
+ V.current.key !== B.key && (V.current = B);
448
+ let H = V.current, _e = `${c}:${f}:${H.key}`, U = (0, A.useRef)(null);
449
+ L && !z && U.current?.key !== _e && (U.current = {
450
+ key: _e,
451
+ columns: Math.max(1, Math.min(6, Math.floor((L.width - 32 - (!f && c === "LR" ? b.width + 70 : 0)) / (b.width + 10))))
452
+ });
453
+ let W = U.current?.columns ?? 1, G = JSON.stringify([
454
+ c,
455
+ f,
456
+ H.key,
457
+ W,
458
+ [...j]
459
+ ]), [ve, ye] = (0, A.useState)(null);
460
+ (0, A.useEffect)(() => {
461
+ if (z) return;
462
+ let e = !0;
463
+ return (async () => {
464
+ let t = await r(H, c, W, b, j, f);
465
+ for (let e = W - 1; e >= 2 && L && t.width * we > L.width - 32; e--) t = await r(H, c, e, b, j, f);
466
+ e && ye({
467
+ key: G,
468
+ layout: t
469
+ });
470
+ })(), () => {
471
+ e = !1;
472
+ };
473
+ }, [G, z]);
474
+ let K = ve?.key === G ? ve.layout : null;
475
+ (0, A.useEffect)(() => {
476
+ let e = n && H.groupOf.get(n);
477
+ e && me((t) => {
478
+ if (!t.has(e)) return t;
479
+ let n = new Set(t);
480
+ return n.delete(e), n;
481
+ });
482
+ }, [n, H.key]);
483
+ let q = (0, A.useMemo)(() => new Map(e.map((e) => [e.id, e])), [e]), J = (0, A.useRef)(null), xe = (0, A.useMemo)(() => {
484
+ if (!K) return [];
485
+ let e = K.frames.map((e) => ({
486
+ id: e.group.id,
487
+ type: "agentFrame",
488
+ position: {
489
+ x: e.x,
490
+ y: e.y
491
+ },
492
+ width: e.width,
493
+ height: e.height,
494
+ measured: J.current?.getInternalNode(e.group.id)?.measured,
495
+ zIndex: -1,
496
+ selectable: !1,
497
+ focusable: !1,
498
+ draggable: !1,
499
+ data: {
500
+ frame: e,
501
+ direction: c,
502
+ groupParents: f,
503
+ label: q.get(e.group.parentId)?.label ?? "Agent",
504
+ onToggle: () => {
505
+ !e.collapsed && n && e.group.memberIds.includes(n) && a?.(e.group.parentId), me((t) => {
506
+ let n = new Set(t);
507
+ return n.has(e.group.id) ? n.delete(e.group.id) : n.add(e.group.id), n;
508
+ });
509
+ }
510
+ }
511
+ })), t = [];
512
+ for (let e of H.agentIds) {
513
+ let r = q.get(e), i = K.positions.get(e);
514
+ if (!r || !i) continue;
515
+ let o = n === e, s = f && K.frames.find((t) => t.group.parentId === e), l = s ? s.width - 64 : b.width, u = s ? 64 : b.height, d = J.current?.getInternalNode(e)?.measured;
516
+ t.push({
517
+ id: e,
518
+ type: f ? "liveAgent" : "agent",
519
+ position: i,
520
+ width: l,
521
+ height: u,
522
+ measured: d?.width === l && d.height === u ? d : void 0,
523
+ className: `${C}${s ? " ag-frame-owner" : ""}`,
524
+ draggable: !1,
525
+ ariaRole: "button",
526
+ ariaLabel: re(r),
527
+ domAttributes: {
528
+ "aria-pressed": o,
529
+ "aria-describedby": D?.id === e ? w : void 0
530
+ },
531
+ data: {
532
+ agent: r,
533
+ selected: o,
534
+ direction: c,
535
+ now: x,
536
+ onOpen: a ? () => a(r.id) : void 0,
537
+ renderEventIcon: m
538
+ }
539
+ });
540
+ }
541
+ return [...e, ...t];
542
+ }, [
543
+ K,
544
+ H,
545
+ q,
546
+ n,
547
+ c,
548
+ f,
549
+ b,
550
+ x,
551
+ a,
552
+ m,
553
+ D
554
+ ]), De = (0, A.useMemo)(() => {
555
+ if (!K) return [];
556
+ let e = [], r = /* @__PURE__ */ new Set();
557
+ for (let t of H.spawns) {
558
+ let n = f && H.groups.find((e) => e.parentId === t.from)?.id || t.from, i = H.groupOf.get(t.to) ?? t.to;
559
+ if (n === i) continue;
560
+ let a = `spawn:${n}:${i}`;
561
+ r.has(a) || (r.add(a), e.push({
562
+ id: a,
563
+ source: n,
564
+ target: i,
565
+ type: "smoothstep",
566
+ pathOptions: { borderRadius: 14 },
567
+ selectable: !1,
568
+ focusable: !1,
569
+ style: {
570
+ stroke: u(void 0),
571
+ strokeWidth: 1.5
572
+ }
573
+ }));
574
+ }
575
+ let a = new Set(K.positions.keys()), o = /* @__PURE__ */ new Map();
576
+ for (let e of t) {
577
+ if (e.kind === "spawn" || e.from === e.to || !a.has(e.from) || !a.has(e.to) || ![n, D?.id].some((t) => t === e.from || t === e.to)) continue;
578
+ let t = `${e.kind}:${e.from}:${e.to}`, r = o.get(t), s = (r?.data?.count ?? 0) + Math.max(1, e.count ?? 1), c = _[e.kind] ?? _.message;
579
+ o.set(t, {
580
+ id: t,
581
+ source: e.from,
582
+ target: e.to,
583
+ type: "agentMessage",
584
+ selectable: !1,
585
+ focusable: !1,
586
+ zIndex: 0,
587
+ markerEnd: {
588
+ type: i.ArrowClosed,
589
+ width: 12,
590
+ height: 12,
591
+ color: c
592
+ },
593
+ ariaLabel: `${e.kind === "delegation" ? "Delegation" : "Message"} from ${q.get(e.from)?.label ?? e.from} to ${q.get(e.to)?.label ?? e.to}${s > 1 ? `, ${s} times` : ""}`,
594
+ data: {
595
+ kind: e.kind,
596
+ count: s,
597
+ label: e.label ?? r?.data?.label
598
+ }
599
+ });
600
+ }
601
+ return [...e, ...o.values()];
602
+ }, [
603
+ K,
604
+ H,
605
+ t,
606
+ q,
607
+ n,
608
+ D
609
+ ]), [ke, Ae] = (0, A.useState)(!1), [je, Me] = (0, A.useState)(!1), Ne = (0, A.useRef)(n);
610
+ Ne.current = n;
611
+ let Pe = (0, A.useRef)(null);
612
+ (0, A.useEffect)(() => {
613
+ z && (J.current = null, Ae(!1), Me(!1), Pe.current = null);
614
+ }, [z]);
615
+ let Fe = K ? `${G}:${K.columns}` : null, Ie = `${c}:${H.key}`, Le = K && L ? Math.max(.02, Math.min(1, (L.width - 32) / K.width, (L.height - 32) / K.height)) : .2;
616
+ (0, A.useEffect)(() => {
617
+ let e = J.current;
618
+ if (!ke || !e || !Fe || !L) return;
619
+ let t = Pe.current !== Ie, n = !t;
620
+ if (n && !Ne.current) return;
621
+ let r = Pe.current !== null && t && S;
622
+ Pe.current = Ie;
623
+ let i = requestAnimationFrame(() => {
624
+ n ? Ee(e, F.current, Ne.current) : e.fitView({
625
+ padding: `${Y}px`,
626
+ minZoom: Math.max(Le, we),
627
+ maxZoom: 1,
628
+ duration: r ? h("--duration-base", F.current) : 0
629
+ }), Me(!0);
630
+ });
631
+ return () => cancelAnimationFrame(i);
632
+ }, [
633
+ ke,
634
+ Fe,
635
+ Ie,
636
+ L,
637
+ Le,
638
+ S,
639
+ n
640
+ ]);
641
+ let Z = (0, A.useCallback)((e) => {
642
+ q.has(e) && (a?.(e), F.current?.querySelector(`[data-agent-id="${CSS.escape(e)}"]`)?.scrollIntoView({ block: "nearest" }));
643
+ }, [q, a]), Re = (0, A.useCallback)((e, t) => Z(t.id), [Z]), ze = (0, A.useCallback)((e) => {
644
+ if (!(e.target instanceof HTMLElement)) return;
645
+ let t = e.target.closest(".react-flow__node")?.getAttribute("data-id");
646
+ if (!t || !q.has(t)) return;
647
+ if (e.key === "Escape") {
648
+ e.preventDefault(), e.stopPropagation(), F.current?.focus();
649
+ return;
650
+ }
651
+ if (!e.target.classList.contains("react-flow__node")) return;
652
+ if (e.key === "Enter" || e.key === " ") {
653
+ e.preventDefault(), e.stopPropagation(), Z(t);
654
+ return;
655
+ }
656
+ let n = K?.positions.get(t), r = {
657
+ ArrowLeft: [-1, 0],
658
+ ArrowRight: [1, 0],
659
+ ArrowUp: [0, -1],
660
+ ArrowDown: [0, 1]
661
+ }[e.key], i = e.key === "Home" ? H.agentIds[0] : n && r ? [...K?.positions ?? []].filter(([e, i]) => q.has(e) && e !== t && (i.x - n.x) * r[0] + (i.y - n.y) * r[1] > 0).sort((e, t) => Math.hypot(e[1].x - n.x, e[1].y - n.y) - Math.hypot(t[1].x - n.x, t[1].y - n.y))[0]?.[0] : null;
662
+ if (!i) return;
663
+ e.preventDefault(), e.stopPropagation();
664
+ let a = K?.positions.get(i), o = J.current?.getInternalNode(i)?.measured;
665
+ a && J.current?.setCenter(a.x + (o?.width ?? b.width) / 2, a.y + (o?.height ?? b.height) / 2, { zoom: 1 });
666
+ let s = () => F.current?.querySelector(`.react-flow__node[data-id="${CSS.escape(i)}"]`), c = s();
667
+ c ? c.focus() : requestAnimationFrame(() => requestAnimationFrame(() => s()?.focus()));
668
+ }, [
669
+ q,
670
+ Z,
671
+ K,
672
+ H,
673
+ b,
674
+ S
675
+ ]), Be = (e) => e.status === "needs-you" ? 0 : e.status === "failed" ? 1 : pe(e, x) ? 2 : e.status === "waiting" ? 3 : e.status === "running" ? 4 : 5, Q = new Map(t.filter((e) => e.kind === "spawn").map((e) => [e.to, e.from])), Ve = (e) => {
676
+ let t = /* @__PURE__ */ new Set([e]), n = 0;
677
+ for (; Q.has(e) && !t.has(Q.get(e));) e = Q.get(e), t.add(e), n++;
678
+ return n;
679
+ }, He = (0, A.useRef)([]), Ue = new Set(He.current);
680
+ He.current = [...He.current.filter((e) => q.has(e)), ...e.filter((e) => !Ue.has(e.id)).sort((e, t) => Be(e) - Be(t)).map((e) => e.id)];
681
+ let We = He.current.map((e) => q.get(e));
682
+ (0, A.useEffect)(() => {
683
+ let e = We.findIndex((e) => e.id === n);
684
+ e >= 0 && N(Math.floor(e / X));
685
+ }, [n]), (0, A.useEffect)(() => {
686
+ if (!z || !n) return;
687
+ let e = requestAnimationFrame(() => F.current?.querySelector(`[data-agent-id="${CSS.escape(n)}"]`)?.scrollIntoView({ block: "nearest" }));
688
+ return () => cancelAnimationFrame(e);
689
+ }, [
690
+ n,
691
+ M,
692
+ z
693
+ ]);
694
+ let $ = Math.min(M * X, Math.max(0, Math.ceil(e.length / X) - 1) * X), Ge = [
695
+ "needs-you",
696
+ "failed",
697
+ "quiet"
698
+ ].map((t) => ({
699
+ status: t,
700
+ count: e.filter((e) => t === "quiet" ? pe(e, x) : e.status === t).length
701
+ })).filter((e) => e.count), Ke = /* @__PURE__ */ (0, k.jsxs)("div", {
702
+ className: "flex min-h-10 shrink-0 flex-wrap items-center gap-x-3 gap-y-1 px-3 py-1 text-xs text-muted-foreground",
703
+ "aria-label": "Run status",
704
+ children: [/* @__PURE__ */ (0, k.jsxs)("span", {
705
+ className: "shrink-0 whitespace-nowrap",
706
+ children: [e.length, " agents"]
707
+ }), Ge.map((e) => /* @__PURE__ */ (0, k.jsxs)("button", {
708
+ type: "button",
709
+ "aria-pressed": P === e.status,
710
+ className: "ag-status-button rounded-full border border-border px-2 py-1",
711
+ style: { color: e.status === "quiet" ? "var(--surface-warning-text)" : p(e.status).color },
712
+ onClick: () => he((t) => t === e.status ? null : e.status),
713
+ children: [
714
+ /* @__PURE__ */ (0, k.jsx)(ae, {
715
+ status: e.status === "quiet" ? "waiting" : e.status,
716
+ size: 14
717
+ }),
718
+ e.count,
719
+ " ",
720
+ e.status === "needs-you" ? "need you" : e.status
721
+ ]
722
+ }, e.status))]
723
+ });
724
+ return e.length === 0 ? /* @__PURE__ */ (0, k.jsx)("div", {
725
+ className: `agent-graph flex items-center justify-center rounded-lg border border-border border-dashed p-4 text-center text-muted-foreground text-xs ${d ?? ""}`,
726
+ children: ee ?? "No agents yet"
727
+ }) : /* @__PURE__ */ (0, k.jsx)(s, {
728
+ anchor: I?.anchor,
729
+ open: !!D,
730
+ onOpenChange: (e) => {
731
+ e || O();
732
+ },
733
+ children: /* @__PURE__ */ (0, k.jsxs)("div", {
734
+ ref: (e) => {
735
+ F.current = e, ge(e);
736
+ },
737
+ className: `agent-graph ag-live${f ? "" : " ag-topology"} relative flex flex-col ${d ?? ""}`,
738
+ tabIndex: -1,
739
+ onKeyDownCapture: (e) => {
740
+ e.target instanceof HTMLElement && e.target.closest("[data-agent-metrics]") || (e.key === "Tab" && !e.shiftKey && D ? (e.preventDefault(), document.getElementById(w)?.focus()) : (e.key === "Escape" && O(), ze(e)));
741
+ },
742
+ onFocusCapture: (e) => {
743
+ if (!(e.target instanceof HTMLElement) || E.current || e.target.closest("[data-agent-metrics]")) return;
744
+ if (!e.target.matches(":focus-visible")) {
745
+ O();
746
+ return;
747
+ }
748
+ let t = e.target.closest(".react-flow__node, [data-agent-id]"), n = t?.dataset.id ?? t?.dataset.agentId;
749
+ T.current = t ?? null, fe(n && q.has(n) ? {
750
+ id: n,
751
+ anchor: t
752
+ } : null);
753
+ },
754
+ onBlurCapture: (e) => {
755
+ !e.currentTarget.contains(e.relatedTarget) && e.relatedTarget?.id !== w && O();
756
+ },
757
+ "data-layout": z ? "list" : K && je ? "ready" : "pending",
758
+ "data-highlight": P ?? void 0,
759
+ "data-columns": K?.columns,
760
+ children: [
761
+ Ke,
762
+ g && f && /* @__PURE__ */ (0, k.jsx)(ne, {
763
+ agents: e,
764
+ now: ie,
765
+ live: f,
766
+ selectedId: n,
767
+ onSelect: a ? Z : void 0
768
+ }),
769
+ z ? /* @__PURE__ */ (0, k.jsxs)("ul", {
770
+ className: "ag-graph-viewport ag-phone-list overflow-auto",
771
+ "aria-label": "Agents by attention",
772
+ children: [We.slice($, $ + X).map((e) => /* @__PURE__ */ (0, k.jsx)("li", {
773
+ style: { "--depth": Ve(e.id) },
774
+ children: /* @__PURE__ */ (0, k.jsx)("div", {
775
+ role: "button",
776
+ tabIndex: 0,
777
+ "aria-pressed": n === e.id,
778
+ "aria-label": re(e),
779
+ "data-agent-id": e.id,
780
+ className: "ag-phone-select",
781
+ onClick: () => Z(e.id),
782
+ onKeyDown: (t) => {
783
+ (t.key === "Enter" || t.key === " ") && t.target === t.currentTarget && (t.preventDefault(), Z(e.id));
784
+ },
785
+ children: f ? /* @__PURE__ */ (0, k.jsx)(be, {
786
+ agent: e,
787
+ parentLabel: q.get(Q.get(e.id) ?? "")?.label,
788
+ selected: n === e.id,
789
+ now: x,
790
+ renderEventIcon: m,
791
+ onOpen: a ? () => Z(e.id) : void 0
792
+ }) : /* @__PURE__ */ (0, k.jsx)(v, {
793
+ agent: e,
794
+ parentLabel: q.get(Q.get(e.id) ?? "")?.label,
795
+ selected: n === e.id,
796
+ now: x,
797
+ direction: c,
798
+ onOpen: a ? () => Z(e.id) : void 0
799
+ })
800
+ })
801
+ }, e.id)), e.length > X && /* @__PURE__ */ (0, k.jsxs)("li", {
802
+ className: "flex items-center justify-between gap-2 border-t border-border pt-3 text-sm",
803
+ "aria-label": "Agent pages",
804
+ children: [
805
+ /* @__PURE__ */ (0, k.jsx)("button", {
806
+ type: "button",
807
+ className: "rounded px-2 py-1 hover:bg-muted disabled:opacity-40 focus-visible:outline",
808
+ disabled: !$,
809
+ onClick: () => {
810
+ N((e) => e - 1), F.current?.querySelector(".ag-phone-list")?.scrollTo({ top: 0 });
811
+ },
812
+ children: "Previous"
813
+ }),
814
+ /* @__PURE__ */ (0, k.jsxs)("span", { children: [
815
+ $ + 1,
816
+ "–",
817
+ Math.min(e.length, $ + X),
818
+ " of ",
819
+ e.length
820
+ ] }),
821
+ /* @__PURE__ */ (0, k.jsx)("button", {
822
+ type: "button",
823
+ className: "rounded px-2 py-1 hover:bg-muted disabled:opacity-40 focus-visible:outline",
824
+ disabled: $ + X >= e.length,
825
+ onClick: () => {
826
+ N((e) => e + 1), F.current?.querySelector(".ag-phone-list")?.scrollTo({ top: 0 });
827
+ },
828
+ children: "Next"
829
+ })
830
+ ]
831
+ })]
832
+ }) : /* @__PURE__ */ (0, k.jsx)("div", {
833
+ className: "ag-graph-viewport min-h-0 flex-1",
834
+ style: { opacity: +!!je },
835
+ children: /* @__PURE__ */ (0, k.jsxs)(o, {
836
+ nodes: xe,
837
+ edges: De,
838
+ nodeTypes: Se,
839
+ edgeTypes: Ce,
840
+ colorMode: R,
841
+ onInit: (e) => {
842
+ J.current = e, Ae(!0);
843
+ },
844
+ onNodeClick: Re,
845
+ onNodeMouseEnter: (e, t) => {
846
+ T.current = e.target.closest(".react-flow__node"), T.current && fe({
847
+ id: t.id,
848
+ anchor: T.current
849
+ });
850
+ },
851
+ proOptions: { hideAttribution: !0 },
852
+ onlyRenderVisibleElements: !0,
853
+ nodesDraggable: !1,
854
+ nodesConnectable: !1,
855
+ elementsSelectable: !1,
856
+ nodesFocusable: !0,
857
+ edgesFocusable: !1,
858
+ deleteKeyCode: null,
859
+ panOnScroll: !0,
860
+ zoomOnScroll: !1,
861
+ zoomOnPinch: !0,
862
+ zoomOnDoubleClick: !1,
863
+ panOnDrag: !0,
864
+ minZoom: Le,
865
+ maxZoom: 1.75,
866
+ "aria-label": "Agent topology",
867
+ children: [/* @__PURE__ */ (0, k.jsx)(de, {
868
+ bgColor: "var(--bg-root)",
869
+ gap: 16,
870
+ size: 1,
871
+ color: "hsl(var(--foreground) / 0.06)"
872
+ }), /* @__PURE__ */ (0, k.jsx)(te, {
873
+ showInteractive: !1,
874
+ position: "bottom-right",
875
+ fitViewOptions: {
876
+ padding: `${Y}px`,
877
+ minZoom: Le,
878
+ maxZoom: 1
879
+ }
880
+ })]
881
+ })
882
+ }),
883
+ D && I && q.has(D.id) && /* @__PURE__ */ (0, k.jsx)(Oe, {
884
+ container: F.current,
885
+ place: I,
886
+ mode: R,
887
+ id: w,
888
+ agent: q.get(D.id),
889
+ onClose: () => {
890
+ O(), E.current = !0, T.current?.focus({ preventScroll: !0 }), E.current = !1;
891
+ }
892
+ })
893
+ ]
894
+ })
895
+ });
896
+ }
897
+ function Oe({ container: e, place: n, mode: r, id: i, agent: o, onClose: s }) {
898
+ let l = [
899
+ o.model ? t(o.model) : void 0,
900
+ ee(o.costUsd),
901
+ c(o.tokens)
902
+ ].filter(Boolean).join(" · "), u = o.status === "failed" ? D(o) : void 0, d = u ? void 0 : o.turn ?? o.events?.at(-1)?.label;
903
+ return /* @__PURE__ */ (0, k.jsxs)(a, {
904
+ container: e,
905
+ side: n.side,
906
+ align: n.align,
907
+ sideOffset: 0,
908
+ avoidCollisions: !1,
909
+ id: i,
910
+ "data-agent-metrics": !0,
911
+ role: "tooltip",
912
+ tabIndex: 0,
913
+ onWheel: (e) => e.stopPropagation(),
914
+ onEscapeKeyDown: (e) => {
915
+ e.preventDefault(), s();
916
+ },
917
+ className: `${r} rounded-xl border border-border bg-card px-3 py-2 text-sm text-foreground shadow-xl`,
918
+ style: {
919
+ colorScheme: r,
920
+ width: "min(320px, calc(100vw - 24px))"
921
+ },
922
+ children: [
923
+ /* @__PURE__ */ (0, k.jsxs)("div", {
924
+ className: "flex items-center gap-2",
925
+ children: [
926
+ /* @__PURE__ */ (0, k.jsx)("span", {
927
+ className: "flex shrink-0",
928
+ style: { color: p(o.status).color },
929
+ children: /* @__PURE__ */ (0, k.jsx)(ae, {
930
+ status: o.status,
931
+ size: 14
932
+ })
933
+ }),
934
+ /* @__PURE__ */ (0, k.jsx)("strong", {
935
+ className: "min-w-0 flex-1 truncate",
936
+ children: o.label
937
+ }),
938
+ /* @__PURE__ */ (0, k.jsx)("span", {
939
+ className: "sr-only",
940
+ children: p(o.status).label
941
+ })
942
+ ]
943
+ }),
944
+ l && /* @__PURE__ */ (0, k.jsx)("p", {
945
+ className: "m-0 truncate text-[13px] text-muted-foreground",
946
+ children: l
947
+ }),
948
+ (u || d) && /* @__PURE__ */ (0, k.jsx)("p", {
949
+ className: "m-0 truncate text-[13px]",
950
+ style: u ? { color: p("failed").color } : { color: "hsl(var(--muted-foreground))" },
951
+ title: u ?? d,
952
+ children: E(u ?? d)
953
+ })
954
+ ]
955
+ });
956
+ }
957
+ export { De as AgentGraphCanvas };