@arbor-education/agent-view-frontend 0.2.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.
package/dist/index.js ADDED
@@ -0,0 +1,2169 @@
1
+ import { jsxs as i, jsx as n, Fragment as Xe } from "react/jsx-runtime";
2
+ import { useMemo as U, useRef as Re, useState as _, useEffect as B, useCallback as I, useLayoutEffect as Ze } from "react";
3
+ import M from "classnames";
4
+ import { Heading as he, Icon as E, Dot as Ge, Button as X, Modal as Q, SelectDropdown as et, TextInput as tt, Combobox as Oe, Card as nt } from "@arbor-education/design-system.components";
5
+ import { CHAT_RESPONSE_TYPE_AGENT as Be, CHAT_RESPONSE_TYPE_ERROR as at, ChatPanel as st, CHAT_RESPONSE_TYPE_USER as rt, CHAT_RESPONSE_TYPE_INFO as ot } from "@arbor-education/ask-arbor-chat-panel";
6
+ const v = {
7
+ "generating-a-response": "generating-a-response",
8
+ hitl: "hitl",
9
+ complete: "complete",
10
+ failed: "failed"
11
+ }, b = {
12
+ "generating-a-response": "generating-a-response",
13
+ hitl: "hitl",
14
+ complete: "complete",
15
+ failed: "failed"
16
+ }, T = {
17
+ briefing: "briefing",
18
+ running: "running",
19
+ stopped: "stopped",
20
+ complete: "complete"
21
+ }, Z = {
22
+ agent: "agent",
23
+ user: "user",
24
+ system: "system"
25
+ }, re = {
26
+ MIS_RECORD: "MIS_RECORD",
27
+ FILE: "FILE",
28
+ WORKFLOW: "WORKFLOW",
29
+ LINK: "LINK"
30
+ }, xe = {
31
+ cancelled: "cancelled",
32
+ archived: "archived"
33
+ }, Se = {
34
+ in_progress: "in_progress",
35
+ requires_attention: "requires_attention",
36
+ available: "available"
37
+ }, G = {
38
+ [b.complete]: {
39
+ label: "Complete",
40
+ icon: "circle-check",
41
+ color: "var(--color-semantic-success-600)"
42
+ },
43
+ [b.failed]: {
44
+ label: "Failed",
45
+ icon: "circle-x",
46
+ color: "var(--color-semantic-destructive-600)"
47
+ },
48
+ [b.hitl]: {
49
+ label: "Requires attention",
50
+ icon: "triangle-alert",
51
+ color: "var(--color-semantic-warning-600)"
52
+ },
53
+ [b["generating-a-response"]]: {
54
+ label: "Generating a response",
55
+ icon: "loader",
56
+ color: "var(--color-brand-600)"
57
+ }
58
+ }, we = {
59
+ [v["generating-a-response"]]: {
60
+ status: v["generating-a-response"],
61
+ title: "Active",
62
+ dotColour: "green",
63
+ statusIcon: {
64
+ name: G["generating-a-response"].icon,
65
+ color: G["generating-a-response"].color,
66
+ spin: !0
67
+ }
68
+ },
69
+ [v.hitl]: {
70
+ status: v.hitl,
71
+ title: "Requires attention",
72
+ dotColour: "orange",
73
+ statusIcon: {
74
+ name: G.hitl.icon,
75
+ color: G.hitl.color
76
+ }
77
+ },
78
+ [v.complete]: {
79
+ status: v.complete,
80
+ title: "Complete",
81
+ dotColour: "green",
82
+ dotModifier: "grey-dark",
83
+ statusIcon: {
84
+ name: G.complete.icon,
85
+ color: G.complete.color
86
+ }
87
+ },
88
+ [v.failed]: {
89
+ status: v.failed,
90
+ title: "Failed",
91
+ dotColour: "salmon",
92
+ statusIcon: {
93
+ name: G.failed.icon,
94
+ color: G.failed.color
95
+ }
96
+ }
97
+ }, it = [
98
+ v["generating-a-response"],
99
+ v.hitl
100
+ ], ct = [
101
+ v.complete,
102
+ v.failed
103
+ ], lt = "m4", dt = "1", qe = "msg-opening", be = "Unable to load agent tasks. Please try again.", gt = "Unable to load the resources for this agent", pt = "Something went wrong. Please try again.", ze = "Unable to load agents. Please try again.", oe = "Loading tasks…", Pe = "Loading agents…", ut = "Task", ht = "What recent actions have you taken?", _t = {
104
+ [T.briefing]: "Briefing",
105
+ [T.running]: "Working",
106
+ [T.stopped]: "Stopped",
107
+ [T.complete]: "Complete"
108
+ }, mt = [
109
+ v["generating-a-response"],
110
+ v.hitl,
111
+ v.complete,
112
+ v.failed
113
+ ], ft = {
114
+ [v["generating-a-response"]]: "Agents currently working on tasks for you.",
115
+ [v.hitl]: "Agents that need your input before they can continue.",
116
+ [v.complete]: "Agents that have finished their work.",
117
+ [v.failed]: "Agents that failed or were stopped."
118
+ }, vt = () => /* @__PURE__ */ i(
119
+ "svg",
120
+ {
121
+ className: "agent-view__empty-illustration",
122
+ viewBox: "0 0 360 240",
123
+ xmlns: "http://www.w3.org/2000/svg",
124
+ role: "img",
125
+ "aria-label": "Preview of the agents board layout",
126
+ children: [
127
+ /* @__PURE__ */ n(
128
+ "rect",
129
+ {
130
+ x: "0",
131
+ y: "0",
132
+ width: "360",
133
+ height: "240",
134
+ rx: "12",
135
+ fill: "var(--color-grey-100)"
136
+ }
137
+ ),
138
+ /* @__PURE__ */ n(
139
+ "rect",
140
+ {
141
+ x: "16",
142
+ y: "16",
143
+ width: "100",
144
+ height: "208",
145
+ rx: "8",
146
+ fill: "var(--card-default-color-background)",
147
+ stroke: "var(--card-default-color-border)"
148
+ }
149
+ ),
150
+ /* @__PURE__ */ n(
151
+ "rect",
152
+ {
153
+ x: "130",
154
+ y: "16",
155
+ width: "100",
156
+ height: "208",
157
+ rx: "8",
158
+ fill: "var(--card-default-color-background)",
159
+ stroke: "var(--card-default-color-border)"
160
+ }
161
+ ),
162
+ /* @__PURE__ */ n(
163
+ "rect",
164
+ {
165
+ x: "244",
166
+ y: "16",
167
+ width: "100",
168
+ height: "100",
169
+ rx: "8",
170
+ fill: "var(--card-default-color-background)",
171
+ stroke: "var(--card-default-color-border)"
172
+ }
173
+ ),
174
+ /* @__PURE__ */ n(
175
+ "rect",
176
+ {
177
+ x: "244",
178
+ y: "124",
179
+ width: "100",
180
+ height: "100",
181
+ rx: "8",
182
+ fill: "var(--card-default-color-background)",
183
+ stroke: "var(--card-default-color-border)"
184
+ }
185
+ ),
186
+ /* @__PURE__ */ n(
187
+ "rect",
188
+ {
189
+ x: "28",
190
+ y: "52",
191
+ width: "76",
192
+ height: "36",
193
+ rx: "6",
194
+ fill: "var(--color-grey-050)"
195
+ }
196
+ ),
197
+ /* @__PURE__ */ n(
198
+ "rect",
199
+ {
200
+ x: "28",
201
+ y: "96",
202
+ width: "76",
203
+ height: "36",
204
+ rx: "6",
205
+ fill: "var(--color-grey-050)"
206
+ }
207
+ ),
208
+ /* @__PURE__ */ n(
209
+ "rect",
210
+ {
211
+ x: "142",
212
+ y: "52",
213
+ width: "76",
214
+ height: "36",
215
+ rx: "6",
216
+ fill: "var(--color-semantic-warning-050)"
217
+ }
218
+ ),
219
+ /* @__PURE__ */ n("circle", { cx: "40", cy: "70", r: "4", fill: "var(--color-brand-600)" }),
220
+ /* @__PURE__ */ n("circle", { cx: "40", cy: "114", r: "4", fill: "var(--color-brand-600)" }),
221
+ /* @__PURE__ */ n(
222
+ "circle",
223
+ {
224
+ cx: "154",
225
+ cy: "70",
226
+ r: "4",
227
+ fill: "var(--color-semantic-warning-600)"
228
+ }
229
+ ),
230
+ /* @__PURE__ */ n("circle", { cx: "256", cy: "52", r: "4", fill: "var(--color-grey-400)" }),
231
+ /* @__PURE__ */ n("circle", { cx: "256", cy: "160", r: "4", fill: "var(--color-semantic-destructive-500)" })
232
+ ]
233
+ }
234
+ ), wt = ({ status: e }) => {
235
+ const t = we[e];
236
+ return t.statusIcon ? /* @__PURE__ */ n(
237
+ E,
238
+ {
239
+ name: t.statusIcon.name,
240
+ size: 16,
241
+ color: t.statusIcon.color,
242
+ screenReaderText: t.title
243
+ }
244
+ ) : /* @__PURE__ */ n(Ge, { colour: t.dotColour, label: t.title });
245
+ }, kt = () => /* @__PURE__ */ i(
246
+ "section",
247
+ {
248
+ className: "agent-view__empty",
249
+ "aria-label": "About the agents board",
250
+ children: [
251
+ /* @__PURE__ */ i("div", { className: "agent-view__empty-content", children: [
252
+ /* @__PURE__ */ n(he, { level: 4, children: "Your agents board" }),
253
+ /* @__PURE__ */ n("p", { className: "agent-view__empty-lead", children: "When you start an agent, it appears here so you can track progress at a glance. Agents move between columns as their status changes." }),
254
+ /* @__PURE__ */ n("ul", { className: "agent-view__empty-columns", children: mt.map((e) => {
255
+ const t = we[e];
256
+ return /* @__PURE__ */ i("li", { className: "agent-view__empty-column", children: [
257
+ /* @__PURE__ */ n("span", { className: "agent-view__empty-column-indicator", children: /* @__PURE__ */ n(wt, { status: e }) }),
258
+ /* @__PURE__ */ i("span", { className: "agent-view__empty-column-text", children: [
259
+ /* @__PURE__ */ n("span", { className: "agent-view__empty-column-title", children: t.title }),
260
+ /* @__PURE__ */ n("span", { className: "agent-view__empty-column-description", children: ft[e] })
261
+ ] })
262
+ ] }, e);
263
+ }) }),
264
+ /* @__PURE__ */ i("p", { className: "agent-view__empty-hint", children: [
265
+ "Use ",
266
+ /* @__PURE__ */ n("strong", { children: "Start an agent" }),
267
+ " above to begin."
268
+ ] })
269
+ ] }),
270
+ /* @__PURE__ */ n("div", { className: "agent-view__empty-visual", children: /* @__PURE__ */ n(vt, {}) })
271
+ ]
272
+ }
273
+ ), Nt = (e, t) => ({
274
+ ...e,
275
+ ...t.length > 0 ? { children: t } : {}
276
+ }), Ke = (e) => {
277
+ const t = [], s = [];
278
+ for (const a of e) {
279
+ const r = a.children ? Ke(a.children) : { needsInput: [], tasks: [] };
280
+ if (t.push(...r.needsInput), a.status === b.hitl) {
281
+ t.push({ ...a, children: void 0 });
282
+ continue;
283
+ }
284
+ s.push(Nt(a, r.tasks));
285
+ }
286
+ return { needsInput: t, tasks: s };
287
+ }, yt = (e) => e.map((t, s) => ({ item: t, index: s })).sort((t, s) => {
288
+ const a = t.item.status === b.hitl, r = s.item.status === b.hitl;
289
+ return a !== r ? a ? -1 : 1 : t.index - s.index;
290
+ }).map(({ item: t }) => t), At = ({
291
+ checklist: e
292
+ }) => e.length === 0 ? /* @__PURE__ */ n("p", { className: "agent-view__progress-empty", children: "No tasks to display." }) : /* @__PURE__ */ n(
293
+ "ul",
294
+ {
295
+ className: "agent-view__progress-list",
296
+ "aria-label": "Agent tasks",
297
+ children: yt(e).map((t) => {
298
+ const s = G[t.status];
299
+ return /* @__PURE__ */ i(
300
+ "li",
301
+ {
302
+ className: M(
303
+ "agent-view__progress-item",
304
+ `agent-view__progress-item--${t.status.replace(/_/g, "-")}`
305
+ ),
306
+ children: [
307
+ /* @__PURE__ */ n(
308
+ E,
309
+ {
310
+ name: s.icon,
311
+ size: 16,
312
+ color: s.color,
313
+ screenReaderText: `${s.label}:`,
314
+ className: M({
315
+ "agent-view__progress-icon--spinning": t.status === b["generating-a-response"]
316
+ })
317
+ }
318
+ ),
319
+ /* @__PURE__ */ i("div", { className: "agent-view__progress-item-content", children: [
320
+ /* @__PURE__ */ n("span", { className: "agent-view__progress-label", children: t.task }),
321
+ t.status !== b.complete && /* @__PURE__ */ n(
322
+ "span",
323
+ {
324
+ className: "agent-view__progress-description",
325
+ children: t.description
326
+ }
327
+ )
328
+ ] })
329
+ ]
330
+ },
331
+ t.task
332
+ );
333
+ })
334
+ }
335
+ ), St = ({
336
+ prompts: e,
337
+ classNamePrefix: t = "agent-workspace",
338
+ onSelect: s
339
+ }) => e.length === 0 ? null : /* @__PURE__ */ n("div", { className: `${t}__chips`, children: e.map((a) => /* @__PURE__ */ n(
340
+ "button",
341
+ {
342
+ type: "button",
343
+ className: `${t}__chip`,
344
+ onClick: () => s(a),
345
+ children: a
346
+ },
347
+ a
348
+ )) });
349
+ class bt {
350
+ constructor(t, s) {
351
+ this.connector = t, this.canSend = s.canSend, this.onTurn = s.onTurn, this.onAwaitingChange = s.onAwaitingChange;
352
+ }
353
+ get canRate() {
354
+ return !1;
355
+ }
356
+ get canLoadHistory() {
357
+ return !1;
358
+ }
359
+ get canListInteractions() {
360
+ return !1;
361
+ }
362
+ get canSendNotification() {
363
+ return !1;
364
+ }
365
+ get ratingPopupUrls() {
366
+ return {};
367
+ }
368
+ async sendMessage(t) {
369
+ var s, a;
370
+ if (!this.canSend())
371
+ return null;
372
+ (s = this.onAwaitingChange) == null || s.call(this, !0);
373
+ try {
374
+ const r = await this.connector.sendMessage(t.userMessage);
375
+ return this.onTurn(r), {
376
+ id: r.message.id,
377
+ text: r.message.text,
378
+ type: Be,
379
+ ...r.message.followUpPrompts ? { followUpPrompts: r.message.followUpPrompts } : {}
380
+ };
381
+ } catch {
382
+ return {
383
+ id: `error-${Date.now()}`,
384
+ text: pt,
385
+ type: at
386
+ };
387
+ } finally {
388
+ (a = this.onAwaitingChange) == null || a.call(this, !1);
389
+ }
390
+ }
391
+ async loadHistory(t) {
392
+ return null;
393
+ }
394
+ async listInteractions() {
395
+ return null;
396
+ }
397
+ async rateMessage(t) {
398
+ }
399
+ async sendNotification(t) {
400
+ return !1;
401
+ }
402
+ }
403
+ const Ct = ({
404
+ connector: e,
405
+ phase: t,
406
+ chatHistory: s,
407
+ chatSessionKey: a,
408
+ startQuery: r,
409
+ clarificationMessage: o,
410
+ onTurn: c,
411
+ onAwaitingChange: d,
412
+ onClarificationPrompt: w,
413
+ onDismissClarification: g
414
+ }) => {
415
+ const p = U(
416
+ () => new bt(e, {
417
+ canSend: () => t === T.running,
418
+ onTurn: c,
419
+ onAwaitingChange: d
420
+ }),
421
+ [e, t, c, d]
422
+ ), m = t !== T.running, k = t === T.running;
423
+ return /* @__PURE__ */ i("section", { className: "agent-workspace__panel agent-workspace__panel--chat", "aria-label": "Chat", children: [
424
+ o && /* @__PURE__ */ i(
425
+ "div",
426
+ {
427
+ className: "agent-workspace__clarification",
428
+ role: "region",
429
+ "aria-label": "Agent question",
430
+ children: [
431
+ /* @__PURE__ */ n("p", { className: "agent-workspace__clarification-text", children: o.text }),
432
+ o.followUpPrompts && /* @__PURE__ */ n(
433
+ St,
434
+ {
435
+ prompts: o.followUpPrompts,
436
+ onSelect: w
437
+ }
438
+ ),
439
+ /* @__PURE__ */ n(
440
+ "button",
441
+ {
442
+ type: "button",
443
+ className: "agent-workspace__clarification-dismiss",
444
+ onClick: g,
445
+ children: "Dismiss"
446
+ }
447
+ )
448
+ ]
449
+ }
450
+ ),
451
+ /* @__PURE__ */ n("div", { className: "agent-workspace__ask-arbor", children: /* @__PURE__ */ n(
452
+ st,
453
+ {
454
+ connector: p,
455
+ chatHistory: s,
456
+ startQuery: r,
457
+ lockConversation: m,
458
+ enableUpload: !0,
459
+ speechEnabled: k,
460
+ speechLanguage: "en-GB",
461
+ speechSubmissionDelay: 1e3,
462
+ slashMenuItems: [],
463
+ menuContent: [],
464
+ introHeading: "Message your agent",
465
+ introBody: "Ask questions, share trip details, or paste a link. The agent will update the checklist as it works.",
466
+ placeholder: k ? "Message the agent, paste a link, or attach a file…" : "The agent is not accepting messages."
467
+ },
468
+ a
469
+ ) }),
470
+ t === T.stopped && /* @__PURE__ */ i("div", { className: "agent-workspace__notice", role: "status", children: [
471
+ /* @__PURE__ */ n(E, { name: "circle-alert", size: 16, color: "var(--color-semantic-warning-600)" }),
472
+ /* @__PURE__ */ n("span", { children: "You stopped the agent. Its progress is saved in the checklist on the left." })
473
+ ] }),
474
+ t === T.complete && /* @__PURE__ */ i("div", { className: "agent-workspace__notice", role: "status", children: [
475
+ /* @__PURE__ */ n(E, { name: "party-popper", size: 16, color: "var(--color-semantic-success-600)" }),
476
+ /* @__PURE__ */ n("span", { children: "The agent has finished." })
477
+ ] })
478
+ ] });
479
+ }, We = ({
480
+ item: e,
481
+ depth: t,
482
+ canRequestInput: s,
483
+ onAttentionItemClick: a
484
+ }) => {
485
+ const r = G[e.status], o = e.status.replace(/_/g, "-"), c = e.status === b.hitl && s && a, d = /* @__PURE__ */ i("div", { className: "agent-workspace__task-row", children: [
486
+ /* @__PURE__ */ n(
487
+ E,
488
+ {
489
+ name: r.icon,
490
+ size: 16,
491
+ color: r.color,
492
+ screenReaderText: `${r.label}:`,
493
+ className: M({
494
+ "agent-workspace__task-icon--spinning": e.status === b["generating-a-response"]
495
+ })
496
+ }
497
+ ),
498
+ /* @__PURE__ */ i("div", { className: "agent-workspace__task-content", children: [
499
+ /* @__PURE__ */ n("span", { className: "agent-workspace__task-label", children: e.task }),
500
+ e.status !== b.complete && e.description && /* @__PURE__ */ n("span", { className: "agent-workspace__task-description", children: e.description })
501
+ ] })
502
+ ] });
503
+ return /* @__PURE__ */ i(
504
+ "li",
505
+ {
506
+ className: M("agent-workspace__task", `agent-workspace__task--${o}`, {
507
+ "agent-workspace__task--child": t > 0
508
+ }),
509
+ children: [
510
+ c ? /* @__PURE__ */ n(
511
+ "button",
512
+ {
513
+ type: "button",
514
+ className: "agent-workspace__task-button",
515
+ "aria-label": `Provide input for ${e.task}`,
516
+ onClick: () => a(e),
517
+ children: d
518
+ }
519
+ ) : d,
520
+ e.children && e.children.length > 0 && /* @__PURE__ */ n("ul", { className: "agent-workspace__task-children", children: e.children.map((w) => /* @__PURE__ */ n(
521
+ We,
522
+ {
523
+ item: w,
524
+ depth: t + 1,
525
+ canRequestInput: s,
526
+ onAttentionItemClick: a
527
+ },
528
+ w.task
529
+ )) })
530
+ ]
531
+ }
532
+ );
533
+ }, Le = ({
534
+ items: e,
535
+ ariaLabel: t,
536
+ canRequestInput: s,
537
+ onAttentionItemClick: a
538
+ }) => /* @__PURE__ */ n("ul", { className: "agent-workspace__task-list", "aria-label": t, children: e.map((r) => /* @__PURE__ */ n(
539
+ We,
540
+ {
541
+ item: r,
542
+ depth: 0,
543
+ canRequestInput: s,
544
+ onAttentionItemClick: a
545
+ },
546
+ r.task
547
+ )) }), Tt = ({
548
+ checklist: e,
549
+ isLoading: t,
550
+ error: s,
551
+ phase: a,
552
+ canRequestInput: r,
553
+ onStop: o,
554
+ onAttentionItemClick: c
555
+ }) => {
556
+ const d = U(
557
+ () => e ? Ke(e) : null,
558
+ [e]
559
+ );
560
+ return /* @__PURE__ */ i(
561
+ "section",
562
+ {
563
+ className: "agent-workspace__panel agent-workspace__panel--checklist",
564
+ "aria-label": "Checklist",
565
+ children: [
566
+ /* @__PURE__ */ i("div", { className: "agent-workspace__panel-header", children: [
567
+ /* @__PURE__ */ n(he, { level: 4, children: "Checklist" }),
568
+ a === T.running && /* @__PURE__ */ n(
569
+ X,
570
+ {
571
+ variant: "secondary-destructive",
572
+ size: "S",
573
+ iconLeftName: "circle-x",
574
+ iconLeftScreenReaderText: "Stop",
575
+ onClick: o,
576
+ children: "Stop agent"
577
+ }
578
+ )
579
+ ] }),
580
+ /* @__PURE__ */ i("div", { className: "agent-workspace__panel-body", "aria-live": "polite", children: [
581
+ t && /* @__PURE__ */ i("div", { className: "agent-workspace__loading", children: [
582
+ /* @__PURE__ */ n(
583
+ E,
584
+ {
585
+ name: "loader",
586
+ size: 16,
587
+ color: "var(--color-brand-600)",
588
+ className: "agent-workspace__task-icon--spinning",
589
+ screenReaderText: oe
590
+ }
591
+ ),
592
+ /* @__PURE__ */ n("span", { children: oe })
593
+ ] }),
594
+ !t && s && /* @__PURE__ */ n("p", { className: "agent-workspace__error", role: "alert", children: s }),
595
+ !t && !s && d && /* @__PURE__ */ i(Xe, { children: [
596
+ d.needsInput.length > 0 && /* @__PURE__ */ i("div", { className: "agent-workspace__task-group", children: [
597
+ /* @__PURE__ */ n("p", { className: "agent-workspace__task-group-label", children: "Needs your input" }),
598
+ /* @__PURE__ */ n(
599
+ Le,
600
+ {
601
+ items: d.needsInput,
602
+ ariaLabel: "Tasks needing your input",
603
+ canRequestInput: r,
604
+ onAttentionItemClick: c
605
+ }
606
+ )
607
+ ] }),
608
+ d.tasks.length > 0 && /* @__PURE__ */ i(
609
+ "div",
610
+ {
611
+ className: M("agent-workspace__task-group", {
612
+ "agent-workspace__task-group--following": d.needsInput.length > 0
613
+ }),
614
+ children: [
615
+ d.needsInput.length > 0 && /* @__PURE__ */ n("p", { className: "agent-workspace__task-group-label", children: "Other tasks" }),
616
+ /* @__PURE__ */ n(
617
+ Le,
618
+ {
619
+ items: d.tasks,
620
+ ariaLabel: "Agent tasks",
621
+ canRequestInput: r,
622
+ onAttentionItemClick: c
623
+ }
624
+ )
625
+ ]
626
+ }
627
+ )
628
+ ] }),
629
+ !t && !s && (!d || d.needsInput.length === 0 && d.tasks.length === 0) && /* @__PURE__ */ n("p", { className: "agent-workspace__empty", children: a === T.briefing ? "Tasks will appear here once the agent starts." : "No tasks to display." })
630
+ ] })
631
+ ]
632
+ }
633
+ );
634
+ }, Et = {
635
+ [re.MIS_RECORD]: {
636
+ icon: "table",
637
+ label: "Arbor MIS",
638
+ color: "var(--color-brand-600)"
639
+ },
640
+ [re.FILE]: {
641
+ icon: "file",
642
+ label: "File",
643
+ color: "var(--color-semantic-caution-800)"
644
+ },
645
+ [re.WORKFLOW]: {
646
+ icon: "list-tree",
647
+ label: "Workflow",
648
+ color: "var(--color-semantic-warning-700)"
649
+ },
650
+ [re.LINK]: {
651
+ icon: "link",
652
+ label: "Link",
653
+ color: "var(--color-semantic-info-700)"
654
+ }
655
+ }, It = ({
656
+ resources: e,
657
+ isLoading: t = !1,
658
+ error: s = null
659
+ }) => /* @__PURE__ */ i(
660
+ "section",
661
+ {
662
+ className: "agent-workspace__panel agent-workspace__panel--documents",
663
+ "aria-label": "Resources",
664
+ children: [
665
+ /* @__PURE__ */ i("div", { className: "agent-workspace__panel-header", children: [
666
+ /* @__PURE__ */ n(he, { level: 4, children: "Resources" }),
667
+ /* @__PURE__ */ n("span", { className: "agent-workspace__panel-count", children: e.length })
668
+ ] }),
669
+ /* @__PURE__ */ i("div", { className: "agent-workspace__panel-body", "aria-live": "polite", children: [
670
+ t && /* @__PURE__ */ i("div", { className: "agent-workspace__loading", children: [
671
+ /* @__PURE__ */ n(
672
+ E,
673
+ {
674
+ name: "loader",
675
+ size: 16,
676
+ color: "var(--color-brand-600)",
677
+ className: "agent-workspace__task-icon--spinning",
678
+ screenReaderText: "Loading resources"
679
+ }
680
+ ),
681
+ /* @__PURE__ */ n("span", { children: "Loading resources…" })
682
+ ] }),
683
+ !t && s && /* @__PURE__ */ n("p", { className: "agent-workspace__error", role: "alert", children: s }),
684
+ !t && !s && e.length > 0 && /* @__PURE__ */ n("ul", { className: "agent-workspace__resource-list", "aria-label": "Agent resources", children: e.map((a) => {
685
+ const r = Et[a.type];
686
+ return /* @__PURE__ */ n("li", { className: "agent-workspace__resource", children: /* @__PURE__ */ i(
687
+ "a",
688
+ {
689
+ className: "agent-workspace__resource-card",
690
+ href: a.uri,
691
+ target: "_blank",
692
+ rel: "noreferrer",
693
+ children: [
694
+ /* @__PURE__ */ n(
695
+ "span",
696
+ {
697
+ className: `agent-workspace__resource-icon agent-workspace__resource-icon--${a.type.toLowerCase()}`,
698
+ children: /* @__PURE__ */ n(
699
+ E,
700
+ {
701
+ name: r.icon,
702
+ size: 16,
703
+ color: r.color,
704
+ screenReaderText: `${r.label}:`
705
+ }
706
+ )
707
+ }
708
+ ),
709
+ /* @__PURE__ */ i("span", { className: "agent-workspace__resource-content", children: [
710
+ /* @__PURE__ */ i("span", { className: "agent-workspace__resource-top", children: [
711
+ /* @__PURE__ */ n("span", { className: "agent-workspace__resource-name", children: a.name }),
712
+ /* @__PURE__ */ n(
713
+ "span",
714
+ {
715
+ className: `agent-workspace__resource-badge agent-workspace__resource-badge--${a.type.toLowerCase()}`,
716
+ children: r.label
717
+ }
718
+ )
719
+ ] }),
720
+ a.description && /* @__PURE__ */ n("span", { className: "agent-workspace__resource-description", children: a.description })
721
+ ] }),
722
+ /* @__PURE__ */ n(
723
+ E,
724
+ {
725
+ name: "external-link",
726
+ size: 12,
727
+ color: "var(--color-grey-500)",
728
+ screenReaderText: "Opens in a new tab",
729
+ className: "agent-workspace__resource-open"
730
+ }
731
+ )
732
+ ]
733
+ }
734
+ ) }, `${a.type}-${a.uri}`);
735
+ }) }),
736
+ !t && !s && e.length === 0 && /* @__PURE__ */ n("p", { className: "agent-workspace__empty", children: "No resources yet." })
737
+ ] })
738
+ ]
739
+ }
740
+ ), Rt = [
741
+ "I'll get the details and come back to you",
742
+ "Skip this for now"
743
+ ], Ot = (e) => {
744
+ var s;
745
+ const t = (s = e.prompt) != null && s.trim() ? e.prompt.trim() : `I need a bit more from you on "${e.task}". ${e.description} What can you tell me?`;
746
+ return {
747
+ id: `clarification-${Date.now()}`,
748
+ author: Z.agent,
749
+ text: t,
750
+ followUpPrompts: e.clarificationPrompts ?? Rt
751
+ };
752
+ }, pe = (e) => ({
753
+ id: e.id,
754
+ text: e.text,
755
+ type: e.author === Z.user ? rt : e.author === Z.system ? ot : Be,
756
+ ...e.followUpPrompts ? { followUpPrompts: e.followUpPrompts } : {}
757
+ }), xt = (e, t) => {
758
+ const s = e.hasRunBefore ? t || "This trip" : e.tripName.trim() || "A new trip", a = e.destination ? ` to ${e.destination}` : "", r = e.hasRunBefore ? " It has run before." : "";
759
+ return `${s}${a}.${r}`.trim();
760
+ }, Pt = (e) => {
761
+ switch (e) {
762
+ case v.failed:
763
+ return T.stopped;
764
+ case v.complete:
765
+ return T.complete;
766
+ default:
767
+ return T.running;
768
+ }
769
+ }, Ue = (e, t) => {
770
+ t([pe(e)]);
771
+ }, Lt = ({
772
+ agent: e,
773
+ open: t,
774
+ onClose: s,
775
+ initialBrief: a,
776
+ initialPhase: r,
777
+ initialChecklist: o,
778
+ fetchAgentChecklist: c,
779
+ fetchAgentResources: d,
780
+ connector: w
781
+ }) => {
782
+ const g = Re(w), [p, m] = _(
783
+ r ?? (a ? T.running : Pt(e.status))
784
+ ), [k, x] = _([]), [P, N] = _(0), [D, S] = _(), [H, q] = _(null), [z, ce] = _([]), [ae, ee] = _(!1), [y, C] = _(null), [$, K] = _(
785
+ o ?? null
786
+ ), [J, W] = _(!1), [L, le] = _(null), [Ne, te] = _(!1), [j, ye] = _(!1), [V, Ae] = _(!1), Y = Re(!1);
787
+ B(() => {
788
+ g.current = w;
789
+ }, [w]), B(() => {
790
+ Y.current = !1, x([]), N((u) => u + 1);
791
+ }, [e.invocation_id]), B(() => {
792
+ if (!t || a || Y.current)
793
+ return;
794
+ const u = g.current.bootstrapConversation;
795
+ if (!u) {
796
+ Ue(
797
+ g.current.openingMessage(),
798
+ x
799
+ );
800
+ return;
801
+ }
802
+ Y.current = !0;
803
+ let A = !1;
804
+ return te(!0), (async () => {
805
+ try {
806
+ const se = await u.call(g.current);
807
+ if (A)
808
+ return;
809
+ x(se.map(pe));
810
+ } catch {
811
+ A || Ue(
812
+ g.current.openingMessage(),
813
+ x
814
+ );
815
+ } finally {
816
+ A || te(!1);
817
+ }
818
+ })(), () => {
819
+ A = !0;
820
+ };
821
+ }, [t, a, e.invocation_id, w]);
822
+ const ne = I((u) => {
823
+ u.checklist && K(u.checklist), u.phase && m(u.phase);
824
+ }, []);
825
+ B(() => {
826
+ var u, A;
827
+ !t || a || o && o.length > 0 && ((A = (u = g.current).seedChecklist) == null || A.call(u, o));
828
+ }, [t, a, o]), B(() => {
829
+ if (!t || a || !c)
830
+ return;
831
+ let u = !1;
832
+ return W(!(o != null && o.length)), le(null), (async () => {
833
+ var A, se;
834
+ try {
835
+ const de = await c(e.invocation_id);
836
+ if (u)
837
+ return;
838
+ o != null && o.length || (K(de.checklist), (se = (A = g.current).seedChecklist) == null || se.call(A, de.checklist));
839
+ } catch {
840
+ !u && !(o != null && o.length) && le(be);
841
+ } finally {
842
+ u || W(!1);
843
+ }
844
+ })(), () => {
845
+ u = !0;
846
+ };
847
+ }, [
848
+ t,
849
+ e.invocation_id,
850
+ a,
851
+ o,
852
+ c
853
+ ]), B(() => {
854
+ if (!t || !d)
855
+ return;
856
+ let u = !1;
857
+ return ee(!0), C(null), (async () => {
858
+ try {
859
+ const A = await d(
860
+ e.invocation_id
861
+ );
862
+ u || ce(A);
863
+ } catch {
864
+ u || C(gt);
865
+ } finally {
866
+ u || ee(!1);
867
+ }
868
+ })(), () => {
869
+ u = !0;
870
+ };
871
+ }, [t, e.invocation_id, d]), B(() => {
872
+ if (!t || !a || Y.current)
873
+ return;
874
+ Y.current = !0;
875
+ const u = {
876
+ id: `user-brief-${Date.now()}`,
877
+ author: Z.user,
878
+ text: xt(a, e.invocation_name)
879
+ };
880
+ (async () => {
881
+ const A = await g.current.start(a);
882
+ x([
883
+ pe(g.current.openingMessage()),
884
+ pe(u),
885
+ pe(A.message)
886
+ ]), A.checklist && K(A.checklist), m(A.phase ?? T.running);
887
+ })();
888
+ }, [t, a, e.invocation_name]);
889
+ const _e = I(
890
+ (u) => {
891
+ q(Ot(u));
892
+ },
893
+ []
894
+ ), me = I((u) => {
895
+ q(null), S(u), N((A) => A + 1);
896
+ }, []), fe = I(async () => {
897
+ await g.current.stop(), m(T.stopped);
898
+ }, []), ve = $;
899
+ return /* @__PURE__ */ i(
900
+ Q,
901
+ {
902
+ open: t,
903
+ closeHandler: s,
904
+ hideCloseButton: !0,
905
+ className: "agent-workspace",
906
+ children: [
907
+ /* @__PURE__ */ i(Q.Header, { className: "agent-workspace__header", children: [
908
+ /* @__PURE__ */ i("div", { className: "agent-workspace__header-title", children: [
909
+ /* @__PURE__ */ n(
910
+ "span",
911
+ {
912
+ className: "agent-workspace__header-avatar",
913
+ "aria-hidden": "true",
914
+ children: /* @__PURE__ */ n(E, { name: "ask-arbor", size: 24 })
915
+ }
916
+ ),
917
+ /* @__PURE__ */ n(Q.Title, { children: e.invocation_name }),
918
+ /* @__PURE__ */ n(
919
+ "span",
920
+ {
921
+ className: M(
922
+ "agent-workspace__phase",
923
+ `agent-workspace__phase--${p}`
924
+ ),
925
+ children: _t[p]
926
+ }
927
+ )
928
+ ] }),
929
+ /* @__PURE__ */ i("div", { className: "agent-workspace__header-actions", children: [
930
+ /* @__PURE__ */ n(
931
+ X,
932
+ {
933
+ variant: "tertiary",
934
+ size: "S",
935
+ iconLeftName: "clipboard-list",
936
+ iconLeftScreenReaderText: "Toggle checklist",
937
+ "aria-pressed": !V,
938
+ onClick: () => Ae((u) => !u),
939
+ children: "Checklist"
940
+ }
941
+ ),
942
+ /* @__PURE__ */ n(
943
+ X,
944
+ {
945
+ variant: "tertiary",
946
+ size: "S",
947
+ iconLeftName: "files",
948
+ iconLeftScreenReaderText: "Toggle resources",
949
+ "aria-pressed": !j,
950
+ onClick: () => ye((u) => !u),
951
+ children: "Resources"
952
+ }
953
+ ),
954
+ /* @__PURE__ */ n(
955
+ X,
956
+ {
957
+ variant: "secondary",
958
+ size: "S",
959
+ iconLeftName: "x",
960
+ iconLeftScreenReaderText: "Close",
961
+ onClick: s,
962
+ children: "Close"
963
+ }
964
+ )
965
+ ] })
966
+ ] }),
967
+ /* @__PURE__ */ i(
968
+ Q.Body,
969
+ {
970
+ className: M("agent-workspace__body", {
971
+ "agent-workspace__body--no-left": V,
972
+ "agent-workspace__body--no-right": j
973
+ }),
974
+ children: [
975
+ !V && /* @__PURE__ */ n(
976
+ Tt,
977
+ {
978
+ checklist: ve,
979
+ isLoading: J,
980
+ error: L,
981
+ phase: p,
982
+ canRequestInput: p === T.running && !Ne,
983
+ onStop: () => void fe(),
984
+ onAttentionItemClick: _e
985
+ }
986
+ ),
987
+ /* @__PURE__ */ n(
988
+ Ct,
989
+ {
990
+ connector: g.current,
991
+ phase: p,
992
+ chatHistory: k,
993
+ chatSessionKey: P,
994
+ startQuery: D,
995
+ clarificationMessage: H,
996
+ onTurn: ne,
997
+ onAwaitingChange: te,
998
+ onClarificationPrompt: me,
999
+ onDismissClarification: () => q(null)
1000
+ }
1001
+ ),
1002
+ !j && /* @__PURE__ */ n(
1003
+ It,
1004
+ {
1005
+ resources: z,
1006
+ isLoading: ae,
1007
+ error: y
1008
+ }
1009
+ )
1010
+ ]
1011
+ }
1012
+ )
1013
+ ]
1014
+ }
1015
+ );
1016
+ }, Ut = ({
1017
+ open: e,
1018
+ onClose: t,
1019
+ onStart: s,
1020
+ agentDefinitions: a
1021
+ }) => {
1022
+ const r = a[0], [o, c] = _(
1023
+ r
1024
+ ), [d, w] = _(""), [g, p] = _(!1), [m, k] = _(null), x = [...a].sort((S, H) => S.agent_intent.localeCompare(H.agent_intent)).map((S) => ({
1025
+ value: S.ref,
1026
+ label: S.agent_intent
1027
+ }));
1028
+ B(() => {
1029
+ e && (c(r), w(""), p(!1), k(null));
1030
+ }, [e, r]);
1031
+ const P = o !== void 0 && d.trim().length > 0, N = I(
1032
+ (S) => {
1033
+ const H = a.find(
1034
+ (q) => q.ref === S[0]
1035
+ );
1036
+ H && c(H);
1037
+ },
1038
+ [a]
1039
+ ), D = I(async () => {
1040
+ if (!(!o || !P || g)) {
1041
+ p(!0), k(null);
1042
+ try {
1043
+ await s({ definition: o, invocationName: d.trim() });
1044
+ } catch (S) {
1045
+ k(
1046
+ S instanceof Error ? S.message : "Unable to start the agent."
1047
+ );
1048
+ } finally {
1049
+ p(!1);
1050
+ }
1051
+ }
1052
+ }, [P, o, d, g, s]);
1053
+ return !o || a.length === 0 ? null : /* @__PURE__ */ i(
1054
+ Q,
1055
+ {
1056
+ open: e,
1057
+ closeHandler: t,
1058
+ className: "new-agent",
1059
+ children: [
1060
+ /* @__PURE__ */ n(Q.Header, { className: "new-agent__header", children: /* @__PURE__ */ i("div", { className: "new-agent__header-title", children: [
1061
+ /* @__PURE__ */ n(
1062
+ "span",
1063
+ {
1064
+ className: "new-agent__header-avatar",
1065
+ "aria-hidden": "true",
1066
+ children: /* @__PURE__ */ n(E, { name: "ask-arbor", size: 24 })
1067
+ }
1068
+ ),
1069
+ /* @__PURE__ */ n(Q.Title, { children: "Start an agent" })
1070
+ ] }) }),
1071
+ /* @__PURE__ */ n(Q.Body, { className: "new-agent__body", children: /* @__PURE__ */ i(
1072
+ "form",
1073
+ {
1074
+ className: "new-agent__form",
1075
+ "aria-label": "Start an agent",
1076
+ onSubmit: (S) => {
1077
+ S.preventDefault(), P && !g && D();
1078
+ },
1079
+ children: [
1080
+ /* @__PURE__ */ i("div", { className: "new-agent__type-field", children: [
1081
+ /* @__PURE__ */ n(
1082
+ "label",
1083
+ {
1084
+ className: "new-agent__type-label",
1085
+ htmlFor: "new-agent-type",
1086
+ children: "What would you like your agent to do?"
1087
+ }
1088
+ ),
1089
+ /* @__PURE__ */ n(
1090
+ et,
1091
+ {
1092
+ id: "new-agent-type",
1093
+ placeholder: "Choose an intent",
1094
+ options: x,
1095
+ selectedValues: [o.ref],
1096
+ onSelectionChange: N
1097
+ }
1098
+ ),
1099
+ /* @__PURE__ */ n("p", { className: "new-agent__type-description", children: o.description })
1100
+ ] }),
1101
+ /* @__PURE__ */ i("div", { className: "new-agent__type-field", children: [
1102
+ /* @__PURE__ */ n(
1103
+ "label",
1104
+ {
1105
+ className: "new-agent__type-label",
1106
+ htmlFor: "new-agent-invocation-name",
1107
+ children: "Name"
1108
+ }
1109
+ ),
1110
+ /* @__PURE__ */ n(
1111
+ tt,
1112
+ {
1113
+ id: "new-agent-invocation-name",
1114
+ value: d,
1115
+ placeholder: "e.g. Test with memory3",
1116
+ onChange: (S) => w(S.target.value)
1117
+ }
1118
+ )
1119
+ ] }),
1120
+ m ? /* @__PURE__ */ n("p", { className: "new-agent__error", role: "alert", children: m }) : null,
1121
+ /* @__PURE__ */ n("div", { className: "new-agent__actions", children: /* @__PURE__ */ n(
1122
+ X,
1123
+ {
1124
+ type: "submit",
1125
+ variant: "primary",
1126
+ disabled: !P || g,
1127
+ iconLeftName: g ? "loader" : "sparkles",
1128
+ iconLeftScreenReaderText: g ? "Starting" : void 0,
1129
+ children: g ? "Starting…" : "Start"
1130
+ }
1131
+ ) })
1132
+ ]
1133
+ }
1134
+ ) })
1135
+ ]
1136
+ }
1137
+ );
1138
+ };
1139
+ class ue extends Error {
1140
+ constructor(t, s, a) {
1141
+ super(a ?? `Agent service request failed (${t})`), this.name = "AgentServiceError", this.status = t, this.detail = s;
1142
+ }
1143
+ }
1144
+ const $t = "/api/v1", R = {
1145
+ agentDefinitions: "/agent-definitions",
1146
+ agents: "/agents",
1147
+ tripOptions: "/trip-options",
1148
+ demoDataset: "/demo/dataset"
1149
+ }, O = {
1150
+ GET: "GET",
1151
+ POST: "POST"
1152
+ }, Mt = {
1153
+ error: "error"
1154
+ }, Dt = {
1155
+ user: "user"
1156
+ }, ie = {
1157
+ acceptJson: "application/json",
1158
+ acceptEventStream: "text/event-stream",
1159
+ contentTypeJson: "application/json",
1160
+ arborApplicationUrl: "X-Arbor-Application-Url"
1161
+ }, Ht = /:invocationId\b/g, Ft = (e) => e.trim().replace(/^Bearer\s+/i, ""), Gt = (e) => e.endsWith("/") ? e.slice(0, -1) : e;
1162
+ class Bt {
1163
+ constructor(t) {
1164
+ var a;
1165
+ this.baseUrl = Gt(t.baseUrl);
1166
+ const s = (a = t.token) == null ? void 0 : a.trim();
1167
+ this.token = s ? Ft(s) : void 0, this.customHeaders = t.headers, this.urls = t.urls ?? {}, this.fetchImpl = t.fetch ?? globalThis.fetch.bind(globalThis);
1168
+ }
1169
+ // Replaces the extra headers merged into every subsequent request,
1170
+ // without recreating the client (e.g. an application-URL header that
1171
+ // changes as the user switches institutions).
1172
+ setHeaders(t) {
1173
+ this.customHeaders = t;
1174
+ }
1175
+ async listAgentDefinitions() {
1176
+ return (await this.request(
1177
+ O.GET,
1178
+ this.resolveUrl("agentDefinitions", R.agentDefinitions)
1179
+ )).agent_definitions ?? [];
1180
+ }
1181
+ getAgentDefinition(t) {
1182
+ return this.request(
1183
+ O.GET,
1184
+ this.apiUrl(
1185
+ `${R.agentDefinitions}/${encodeURIComponent(t)}`
1186
+ )
1187
+ );
1188
+ }
1189
+ listTripOptions() {
1190
+ return this.request(
1191
+ O.GET,
1192
+ this.apiUrl(R.tripOptions)
1193
+ );
1194
+ }
1195
+ getDataset() {
1196
+ return this.request(
1197
+ O.GET,
1198
+ this.apiUrl(R.demoDataset)
1199
+ );
1200
+ }
1201
+ setDataset(t) {
1202
+ return this.request(
1203
+ O.POST,
1204
+ this.apiUrl(R.demoDataset),
1205
+ { dataset: t }
1206
+ );
1207
+ }
1208
+ listAgents(t = {}) {
1209
+ const s = new URLSearchParams();
1210
+ t.status && s.set("status", t.status), t.agentDefinitionRef && s.set("agent_definition_ref", t.agentDefinitionRef);
1211
+ const a = s.toString() ? `?${s.toString()}` : "";
1212
+ return this.request(
1213
+ O.GET,
1214
+ `${this.resolveUrl("agents", R.agents)}${a}`
1215
+ );
1216
+ }
1217
+ createAgent(t, s = {}) {
1218
+ var c, d;
1219
+ const a = {
1220
+ agent_definition_ref: t
1221
+ }, r = (c = s.invocationName) == null ? void 0 : c.trim(), o = (d = s.agentIntent) == null ? void 0 : d.trim();
1222
+ return r && (a.invocation_name = r), o && (a.agent_intent = o), this.request(
1223
+ O.POST,
1224
+ this.resolveUrl("agents", R.agents),
1225
+ a
1226
+ );
1227
+ }
1228
+ getAgent(t) {
1229
+ return this.request(
1230
+ O.GET,
1231
+ this.resolveUrl(
1232
+ "agent",
1233
+ `${R.agents}/${encodeURIComponent(t)}`,
1234
+ t
1235
+ )
1236
+ );
1237
+ }
1238
+ getAgentChecklist(t) {
1239
+ return this.request(
1240
+ O.GET,
1241
+ this.resolveUrl(
1242
+ "agentChecklist",
1243
+ `${R.agents}/${encodeURIComponent(t)}/checklist`,
1244
+ t
1245
+ )
1246
+ );
1247
+ }
1248
+ getAgentResources(t) {
1249
+ return this.request(
1250
+ O.GET,
1251
+ this.resolveUrl(
1252
+ "agentResources",
1253
+ `${R.agents}/${encodeURIComponent(t)}/resources`,
1254
+ t
1255
+ )
1256
+ );
1257
+ }
1258
+ getAgentContext(t) {
1259
+ return this.request(
1260
+ O.GET,
1261
+ this.apiUrl(
1262
+ `${R.agents}/${encodeURIComponent(t)}/context`
1263
+ )
1264
+ );
1265
+ }
1266
+ cancelAgent(t) {
1267
+ return this.request(
1268
+ O.POST,
1269
+ this.apiUrl(
1270
+ `${R.agents}/${encodeURIComponent(t)}/cancel`
1271
+ )
1272
+ );
1273
+ }
1274
+ archiveAgent(t) {
1275
+ return this.request(
1276
+ O.POST,
1277
+ this.apiUrl(
1278
+ `${R.agents}/${encodeURIComponent(t)}/archive`
1279
+ )
1280
+ );
1281
+ }
1282
+ // Streams a chat turn. Resolves with the final SSE event; `onEvent` fires
1283
+ // for every event as it arrives.
1284
+ async chat(t, s, a = {}) {
1285
+ const r = await this.fetchImpl(
1286
+ this.resolveUrl(
1287
+ "agentChat",
1288
+ `${R.agents}/${encodeURIComponent(t)}/chat`,
1289
+ t
1290
+ ),
1291
+ {
1292
+ method: O.POST,
1293
+ headers: {
1294
+ ...this.customHeaders,
1295
+ ...this.authHeaders(),
1296
+ Accept: ie.acceptEventStream,
1297
+ "Content-Type": ie.contentTypeJson
1298
+ },
1299
+ body: JSON.stringify(s),
1300
+ signal: a.signal
1301
+ }
1302
+ );
1303
+ if (!r.ok)
1304
+ throw await this.toError(r);
1305
+ if (!r.body)
1306
+ throw new ue(
1307
+ r.status,
1308
+ null,
1309
+ "Chat response contained no stream body"
1310
+ );
1311
+ return this.consumeSse(r.body, a.onEvent);
1312
+ }
1313
+ authHeaders() {
1314
+ return this.token ? { Authorization: `Bearer ${this.token}` } : {};
1315
+ }
1316
+ // Builds a URL from the base url + shared API prefix + route.
1317
+ apiUrl(t) {
1318
+ return `${this.baseUrl}${$t}${t}`;
1319
+ }
1320
+ // Resolves the URL for an operation, preferring a per-operation override
1321
+ // (with `:invocationId` substituted) and falling back to the base url.
1322
+ resolveUrl(t, s, a) {
1323
+ const r = this.urls[t];
1324
+ return r ? a ? r.replace(
1325
+ Ht,
1326
+ encodeURIComponent(a)
1327
+ ) : r : this.apiUrl(s);
1328
+ }
1329
+ async request(t, s, a) {
1330
+ const r = await this.fetchImpl(
1331
+ s,
1332
+ {
1333
+ method: t,
1334
+ headers: {
1335
+ ...this.customHeaders,
1336
+ ...this.authHeaders(),
1337
+ Accept: ie.acceptJson,
1338
+ ...a === void 0 ? {} : { "Content-Type": ie.contentTypeJson }
1339
+ },
1340
+ ...a === void 0 ? {} : { body: JSON.stringify(a) }
1341
+ }
1342
+ );
1343
+ if (!r.ok)
1344
+ throw await this.toError(r);
1345
+ if (r.status !== 204)
1346
+ return await r.json();
1347
+ }
1348
+ async toError(t) {
1349
+ let s = null;
1350
+ try {
1351
+ s = await t.json();
1352
+ } catch {
1353
+ }
1354
+ return new ue(
1355
+ t.status,
1356
+ s,
1357
+ `Agent service request failed (${t.status} ${t.statusText})`
1358
+ );
1359
+ }
1360
+ async consumeSse(t, s) {
1361
+ const a = t.getReader(), r = new TextDecoder();
1362
+ let o = "", c;
1363
+ const d = (w) => {
1364
+ const { event: g, data: p } = qt(w);
1365
+ if (p === null)
1366
+ return;
1367
+ if (g === Mt.error) {
1368
+ const k = $e(p);
1369
+ throw new ue(
1370
+ 502,
1371
+ k,
1372
+ (k == null ? void 0 : k.message) ?? "Chat stream error"
1373
+ );
1374
+ }
1375
+ const m = $e(p);
1376
+ m && (c = m, s == null || s(m));
1377
+ };
1378
+ for (; ; ) {
1379
+ const { done: w, value: g } = await a.read();
1380
+ if (w)
1381
+ break;
1382
+ o += r.decode(g, { stream: !0 });
1383
+ const p = o.split(`
1384
+
1385
+ `);
1386
+ o = p.pop() ?? "";
1387
+ for (const m of p)
1388
+ d(m);
1389
+ }
1390
+ if (o.trim() && d(o), !c)
1391
+ throw new ue(
1392
+ 502,
1393
+ null,
1394
+ "Chat stream ended without any events"
1395
+ );
1396
+ return c;
1397
+ }
1398
+ }
1399
+ const qt = (e) => {
1400
+ let t = null;
1401
+ const s = [];
1402
+ for (const a of e.split(`
1403
+ `)) {
1404
+ const r = a.trimEnd();
1405
+ r.startsWith("event:") ? t = r.slice(6).trim() : r.startsWith("data:") && s.push(r.slice(5).trim());
1406
+ }
1407
+ return {
1408
+ event: t,
1409
+ data: s.length > 0 ? s.join(`
1410
+ `) : null
1411
+ };
1412
+ }, $e = (e) => {
1413
+ try {
1414
+ return JSON.parse(e);
1415
+ } catch {
1416
+ return;
1417
+ }
1418
+ }, zt = {
1419
+ id: qe,
1420
+ author: Z.agent,
1421
+ text: "I'm connected to this agent. Ask me how it's progressing, or send an instruction and I’ll act on it."
1422
+ };
1423
+ let Me = 0;
1424
+ const De = (e) => (Me += 1, `${e}-${Date.now()}-${Me}`), Kt = (e) => {
1425
+ const t = e.destination ? ` to ${e.destination}` : "";
1426
+ return `Let's get started on ${e.tripName.trim() || e.destination.trim() || "this task"}${t}. What will you do first?`;
1427
+ };
1428
+ class Wt {
1429
+ constructor(t, s, a = {}) {
1430
+ this.seededChecklist = [], this.client = t, this.agentId = s, this.opening = a.openingMessage ?? zt, this.model = a.model, this.bootstrapPrompt = a.bootstrapPrompt ?? ht;
1431
+ }
1432
+ openingMessage() {
1433
+ return this.opening;
1434
+ }
1435
+ async bootstrapConversation(t = this.bootstrapPrompt) {
1436
+ const s = t.trim();
1437
+ if (!s)
1438
+ return [this.opening];
1439
+ const a = {
1440
+ id: De("msg-user"),
1441
+ author: Z.user,
1442
+ text: s
1443
+ }, r = await this.exchange(s);
1444
+ return [a, r.message];
1445
+ }
1446
+ async start(t) {
1447
+ return { ...await this.exchange(Kt(t)), phase: T.running };
1448
+ }
1449
+ sendMessage(t) {
1450
+ return this.exchange(t);
1451
+ }
1452
+ async stop() {
1453
+ }
1454
+ seedChecklist(t) {
1455
+ this.seededChecklist = t;
1456
+ }
1457
+ async exchange(t) {
1458
+ var o;
1459
+ const s = [
1460
+ { role: Dt.user, content: t }
1461
+ ], a = await this.client.chat(this.agentId, {
1462
+ messages: s,
1463
+ ...this.chatId ? { chat_id: this.chatId } : {},
1464
+ ...this.model ? { model: this.model } : {},
1465
+ moderation_enabled: !0,
1466
+ meta: {
1467
+ feature_id: "agent_view",
1468
+ source: "agent_view_frontend"
1469
+ }
1470
+ });
1471
+ return this.chatId = a.chat_id, { message: {
1472
+ id: a.event_id || De("msg-agent"),
1473
+ author: Z.agent,
1474
+ text: a.message.content,
1475
+ ...(o = a.follow_up_prompts) != null && o.length ? { followUpPrompts: a.follow_up_prompts } : {}
1476
+ } };
1477
+ }
1478
+ }
1479
+ const Jt = (e, t) => (s) => {
1480
+ var a;
1481
+ return new Wt(e, s.invocation_id, {
1482
+ model: t == null ? void 0 : t.model,
1483
+ bootstrapPrompt: t == null ? void 0 : t.bootstrapPrompt,
1484
+ openingMessage: ((a = t == null ? void 0 : t.resolveOpeningMessage) == null ? void 0 : a.call(t, s)) ?? (t == null ? void 0 : t.openingMessage)
1485
+ });
1486
+ }, jt = (e) => {
1487
+ switch (e) {
1488
+ case xe.cancelled:
1489
+ return v.failed;
1490
+ case xe.archived:
1491
+ return v.complete;
1492
+ case v.hitl:
1493
+ case v.complete:
1494
+ case v.failed:
1495
+ case v["generating-a-response"]:
1496
+ return e;
1497
+ default:
1498
+ return v["generating-a-response"];
1499
+ }
1500
+ }, Vt = (e) => {
1501
+ switch (e) {
1502
+ case Se.requires_attention:
1503
+ return b.hitl;
1504
+ case Se.in_progress:
1505
+ case Se.available:
1506
+ return b["generating-a-response"];
1507
+ case b.failed:
1508
+ case b.complete:
1509
+ case b.hitl:
1510
+ case b["generating-a-response"]:
1511
+ return e;
1512
+ default:
1513
+ return b["generating-a-response"];
1514
+ }
1515
+ }, Yt = (e) => ({
1516
+ ref: e.name,
1517
+ display_name: e.display_name,
1518
+ agent_intent: e.agent_intent ?? e.display_name,
1519
+ description: e.description
1520
+ }), fn = (e) => ({
1521
+ id: e.id,
1522
+ name: e.name,
1523
+ ...e.has_run_before ? { hasRunBefore: e.has_run_before } : {}
1524
+ }), Qt = new Set(Object.values(re)), Xt = (e) => e && Qt.has(e) ? e : re.LINK, Zt = (e) => ({
1525
+ uri: e.uri ?? "",
1526
+ type: Xt(e.type),
1527
+ name: e.name ?? "",
1528
+ description: e.description ?? ""
1529
+ }), en = (e) => (Array.isArray(e) ? e : e.resources ?? []).map(Zt), He = (e) => {
1530
+ var s;
1531
+ const t = e.invocation_id ?? e.id;
1532
+ return {
1533
+ id: e.id,
1534
+ invocation_id: t,
1535
+ agent_definition_ref: e.agent_definition_ref,
1536
+ ...e.agent_intent ? { agent_intent: e.agent_intent } : {},
1537
+ invocation_name: ((s = e.invocation_name) == null ? void 0 : s.trim()) || e.agent_definition_ref,
1538
+ application_id: e.application_id,
1539
+ ...e.application_name ? { application_name: e.application_name } : {},
1540
+ created_by: e.created_by,
1541
+ status: jt(e.status),
1542
+ context_ref: e.context_ref ?? null,
1543
+ checklist_ref: e.checklist_ref ?? null
1544
+ };
1545
+ }, Je = (e) => {
1546
+ var t;
1547
+ return {
1548
+ task: e.task ?? e.name ?? e.label ?? ut,
1549
+ status: Vt(e.status),
1550
+ description: e.description ?? "",
1551
+ ...e.prompt ? { prompt: e.prompt } : {},
1552
+ ...(t = e.follow_up_prompts) != null && t.length ? { clarificationPrompts: e.follow_up_prompts } : {}
1553
+ };
1554
+ }, tn = (e) => Array.isArray(e) ? e : e.checklist_items ?? e.checklist ?? e.items ?? [], nn = (e, t, s) => {
1555
+ var o;
1556
+ const a = !Array.isArray(t) && (t.opening_message || (o = t.opening_follow_up_prompts) != null && o.length) ? t : s, r = a ? ke(a) : void 0;
1557
+ return {
1558
+ invocation_id: e,
1559
+ checklist: tn(t).map(Je),
1560
+ ...r ? { openingMessage: r } : {}
1561
+ };
1562
+ }, vn = (e, t) => {
1563
+ const s = ke(t);
1564
+ return {
1565
+ invocation_id: t.invocation_id ?? e,
1566
+ checklist: (t.checklist_items ?? []).map(Je),
1567
+ ...s ? { openingMessage: s } : {}
1568
+ };
1569
+ }, ke = (e) => {
1570
+ var s, a;
1571
+ const t = (s = e.opening_message) == null ? void 0 : s.trim();
1572
+ if (t)
1573
+ return {
1574
+ id: qe,
1575
+ author: Z.agent,
1576
+ text: t,
1577
+ ...(a = e.opening_follow_up_prompts) != null && a.length ? { followUpPrompts: e.opening_follow_up_prompts } : {}
1578
+ };
1579
+ }, an = (e) => e instanceof ue ? e.message : e instanceof TypeError ? "Network error while contacting the agent service." : e instanceof Error && e.message ? e.message : ze, sn = (e) => {
1580
+ const t = {};
1581
+ for (const s of e) {
1582
+ const a = ke(s);
1583
+ if (!a)
1584
+ continue;
1585
+ const r = s.invocation_id ?? s.id;
1586
+ t[r] = a, t[s.id] = a;
1587
+ }
1588
+ return t;
1589
+ }, rn = (e) => JSON.stringify(e), on = (e) => {
1590
+ const { jwt: t, headers: s, urls: a } = e, r = JSON.stringify(s ?? {}), o = rn(a), c = U(
1591
+ () => {
1592
+ const { baseUrl: y, ...C } = a;
1593
+ return new Bt({
1594
+ baseUrl: y,
1595
+ token: t,
1596
+ headers: s,
1597
+ urls: C
1598
+ });
1599
+ },
1600
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- keyed on serialised config to keep a stable client.
1601
+ [t, o]
1602
+ );
1603
+ Ze(() => {
1604
+ c.setHeaders(s);
1605
+ }, [c, r]);
1606
+ const [d, w] = _([]), [g, p] = _(
1607
+ []
1608
+ ), [m, k] = _({}), [x, P] = _("loading"), [N, D] = _(null), [S, H] = _(0);
1609
+ B(() => {
1610
+ let y = !1;
1611
+ return P("loading"), D(null), (async () => {
1612
+ try {
1613
+ const [C, $] = await Promise.all([
1614
+ c.listAgents(),
1615
+ c.listAgentDefinitions()
1616
+ ]);
1617
+ if (y)
1618
+ return;
1619
+ w(C.map(He)), p($.map(Yt)), k(sn(C)), P("idle");
1620
+ } catch (C) {
1621
+ if (y)
1622
+ return;
1623
+ w([]), p([]), k({}), P("error"), D(an(C));
1624
+ }
1625
+ })(), () => {
1626
+ y = !0;
1627
+ };
1628
+ }, [c, S]);
1629
+ const q = I(() => {
1630
+ H((y) => y + 1);
1631
+ }, []), z = I(
1632
+ async (y) => {
1633
+ const [C, $] = await Promise.all([
1634
+ c.getAgentChecklist(y),
1635
+ c.getAgent(y).catch(() => null)
1636
+ ]);
1637
+ return nn(
1638
+ y,
1639
+ C,
1640
+ $ ?? void 0
1641
+ );
1642
+ },
1643
+ [c]
1644
+ ), ce = I(
1645
+ async (y) => {
1646
+ const C = await c.getAgentResources(y);
1647
+ return en(C);
1648
+ },
1649
+ [c]
1650
+ ), ae = I(
1651
+ async ({
1652
+ definition: y,
1653
+ invocationName: C
1654
+ }) => {
1655
+ const $ = await c.createAgent(y.ref, {
1656
+ invocationName: C
1657
+ }), K = await c.getAgent($.id), J = He(K), W = ke(K);
1658
+ return w((L) => [J, ...L]), W && k((L) => ({
1659
+ ...L,
1660
+ [J.invocation_id]: W,
1661
+ [J.id]: W
1662
+ })), J;
1663
+ },
1664
+ [c]
1665
+ ), ee = U(
1666
+ () => Jt(c, {
1667
+ resolveOpeningMessage: (y) => m[y.invocation_id] ?? m[y.id]
1668
+ }),
1669
+ [c, m]
1670
+ );
1671
+ return {
1672
+ agents: d,
1673
+ agentDefinitions: g,
1674
+ loadState: x,
1675
+ loadError: N,
1676
+ reload: q,
1677
+ fetchAgentChecklist: z,
1678
+ fetchAgentResources: ce,
1679
+ createAgent: ae,
1680
+ chatConnector: ee
1681
+ };
1682
+ }, cn = (e) => e !== void 0 && e.some((t) => t.status === b.hitl), ln = (e, t) => cn(t) ? v.hitl : e.status, dn = ({ column: e, label: t }) => e.statusIcon ? /* @__PURE__ */ n("span", { className: "agent-view__status-indicator", children: /* @__PURE__ */ n(
1683
+ E,
1684
+ {
1685
+ name: e.statusIcon.name,
1686
+ size: 16,
1687
+ color: e.statusIcon.color,
1688
+ className: M({
1689
+ "agent-view__progress-icon--spinning": e.statusIcon.spin
1690
+ }),
1691
+ screenReaderText: t
1692
+ }
1693
+ ) }) : /* @__PURE__ */ n(
1694
+ "span",
1695
+ {
1696
+ className: M("agent-view__dot", {
1697
+ [`agent-view__dot--${e.dotModifier}`]: e.dotModifier
1698
+ }),
1699
+ children: /* @__PURE__ */ n(Ge, { colour: e.dotColour, label: t })
1700
+ }
1701
+ ), gn = ({
1702
+ agent: e,
1703
+ agentName: t,
1704
+ column: s,
1705
+ isExpanded: a,
1706
+ isLoading: r,
1707
+ checklist: o,
1708
+ error: c,
1709
+ onToggle: d,
1710
+ onViewAgent: w
1711
+ }) => {
1712
+ const { id: g, invocation_name: p } = e, m = `agent-card-${g}-header`, k = `agent-card-${g}-progress`;
1713
+ return /* @__PURE__ */ n(
1714
+ "li",
1715
+ {
1716
+ className: M("agent-view__card", {
1717
+ "agent-view__card--expanded": a
1718
+ }),
1719
+ children: /* @__PURE__ */ i(nt, { spacing: "dense", children: [
1720
+ /* @__PURE__ */ n(
1721
+ "button",
1722
+ {
1723
+ type: "button",
1724
+ className: "agent-view__card-toggle",
1725
+ "aria-expanded": a,
1726
+ "aria-controls": k,
1727
+ "aria-label": p,
1728
+ id: m,
1729
+ onClick: () => d(g),
1730
+ children: /* @__PURE__ */ i("div", { className: "agent-view__card-content", children: [
1731
+ /* @__PURE__ */ n(dn, { column: s }),
1732
+ /* @__PURE__ */ n("span", { className: "agent-view__card-invocation-name", children: p }),
1733
+ /* @__PURE__ */ n("span", { className: "agent-view__card-agent-name", children: t }),
1734
+ /* @__PURE__ */ n(
1735
+ E,
1736
+ {
1737
+ name: a ? "chevron-up" : "chevron-down",
1738
+ size: 16,
1739
+ className: "agent-view__card-chevron"
1740
+ }
1741
+ )
1742
+ ] })
1743
+ }
1744
+ ),
1745
+ a && /* @__PURE__ */ i(
1746
+ "div",
1747
+ {
1748
+ id: k,
1749
+ "aria-labelledby": m,
1750
+ className: "agent-view__card-progress",
1751
+ children: [
1752
+ r && /* @__PURE__ */ i("div", { className: "agent-view__progress-loading", "aria-live": "polite", children: [
1753
+ /* @__PURE__ */ n(
1754
+ E,
1755
+ {
1756
+ name: "loader",
1757
+ size: 16,
1758
+ color: "var(--color-brand-600)",
1759
+ className: "agent-view__progress-icon--spinning",
1760
+ screenReaderText: oe
1761
+ }
1762
+ ),
1763
+ /* @__PURE__ */ n("span", { children: oe })
1764
+ ] }),
1765
+ !r && c && /* @__PURE__ */ n("p", { className: "agent-view__progress-error", role: "alert", children: c }),
1766
+ !r && !c && o !== null && /* @__PURE__ */ n(At, { checklist: o }),
1767
+ !r && !c && o === null && /* @__PURE__ */ i("div", { className: "agent-view__progress-loading", "aria-live": "polite", children: [
1768
+ /* @__PURE__ */ n(
1769
+ E,
1770
+ {
1771
+ name: "loader",
1772
+ size: 16,
1773
+ color: "var(--color-brand-600)",
1774
+ className: "agent-view__progress-icon--spinning",
1775
+ screenReaderText: oe
1776
+ }
1777
+ ),
1778
+ /* @__PURE__ */ n("span", { children: oe })
1779
+ ] }),
1780
+ /* @__PURE__ */ n("div", { className: "agent-view__card-actions", children: /* @__PURE__ */ n(
1781
+ X,
1782
+ {
1783
+ variant: "secondary",
1784
+ size: "S",
1785
+ onClick: () => w == null ? void 0 : w(e),
1786
+ children: "View agent"
1787
+ }
1788
+ ) })
1789
+ ]
1790
+ }
1791
+ )
1792
+ ] })
1793
+ }
1794
+ );
1795
+ }, Fe = ({
1796
+ column: e,
1797
+ agents: t,
1798
+ expandedAgentId: s,
1799
+ loadingAgentId: a,
1800
+ checklistByInvocationId: r,
1801
+ errorByAgentId: o,
1802
+ definitionNameByRef: c,
1803
+ onToggleAgent: d,
1804
+ onViewAgent: w,
1805
+ isSplit: g = !1
1806
+ }) => /* @__PURE__ */ i(
1807
+ "section",
1808
+ {
1809
+ className: M("agent-view__column", {
1810
+ "agent-view__column--split": g
1811
+ }),
1812
+ "aria-label": e.title,
1813
+ children: [
1814
+ /* @__PURE__ */ i("div", { className: "agent-view__column-header", children: [
1815
+ /* @__PURE__ */ n(he, { level: 4, children: e.title }),
1816
+ /* @__PURE__ */ n("span", { className: "agent-view__column-count", children: t.length })
1817
+ ] }),
1818
+ /* @__PURE__ */ n("ul", { className: "agent-view__card-list", children: t.map((p) => /* @__PURE__ */ n(
1819
+ gn,
1820
+ {
1821
+ agent: p,
1822
+ agentName: Ce(p, c),
1823
+ column: e,
1824
+ isExpanded: s === p.id,
1825
+ isLoading: a === p.id,
1826
+ checklist: r[p.invocation_id] ?? null,
1827
+ error: o[p.id] ?? null,
1828
+ onToggle: d,
1829
+ onViewAgent: w
1830
+ },
1831
+ p.id
1832
+ )) })
1833
+ ]
1834
+ }
1835
+ ), Ce = (e, t) => t.get(e.agent_definition_ref) ?? e.agent_definition_ref.replace(/_/g, " "), wn = ({
1836
+ jwt: e,
1837
+ headers: t,
1838
+ baseUrl: s,
1839
+ agentDefinitionsUrl: a,
1840
+ agentsUrl: r,
1841
+ agentUrl: o,
1842
+ agentChecklistUrl: c,
1843
+ agentResourcesUrl: d,
1844
+ agentChatUrl: w,
1845
+ institutions: g
1846
+ }) => {
1847
+ var Ie;
1848
+ const p = U(
1849
+ () => ({
1850
+ baseUrl: s,
1851
+ ...a ? { agentDefinitions: a } : {},
1852
+ ...r ? { agents: r } : {},
1853
+ ...o ? { agent: o } : {},
1854
+ ...c ? { agentChecklist: c } : {},
1855
+ ...d ? { agentResources: d } : {},
1856
+ ...w ? { agentChat: w } : {}
1857
+ }),
1858
+ [
1859
+ s,
1860
+ a,
1861
+ r,
1862
+ o,
1863
+ c,
1864
+ d,
1865
+ w
1866
+ ]
1867
+ ), [m, k] = _(null), x = m ? (Ie = g == null ? void 0 : g.find(
1868
+ (l) => l.applicationId === m.application_id
1869
+ )) == null ? void 0 : Ie.applicationUrl : void 0, P = U(() => {
1870
+ const l = { ...t ?? {} };
1871
+ return x ? l[ie.arborApplicationUrl] = x : delete l[ie.arborApplicationUrl], l;
1872
+ }, [t, x]), {
1873
+ agents: N,
1874
+ agentDefinitions: D,
1875
+ loadState: S,
1876
+ loadError: H,
1877
+ reload: q,
1878
+ fetchAgentChecklist: z,
1879
+ fetchAgentResources: ce,
1880
+ createAgent: ae,
1881
+ chatConnector: ee
1882
+ } = on({ jwt: e, headers: P, urls: p }), [y, C] = _(!1), [$, K] = _(null), [J, W] = _(null), [L, le] = _({}), [Ne, te] = _({}), [j, ye] = _([]), [V, Ae] = _([]), Y = U(() => {
1883
+ const l = new Set(N.map((h) => h.application_id)), f = new Map(
1884
+ (g ?? []).map((h) => [h.applicationId, h.name])
1885
+ );
1886
+ return [...l].sort(
1887
+ (h, F) => (f.get(h) ?? h).localeCompare(f.get(F) ?? F)
1888
+ ).map((h) => ({
1889
+ value: h,
1890
+ label: f.get(h) ?? h
1891
+ }));
1892
+ }, [N, g]), ne = U(
1893
+ () => new Map(D.map((l) => [l.ref, l.display_name])),
1894
+ [D]
1895
+ ), _e = U(() => [...new Set(
1896
+ N.map((f) => Ce(f, ne))
1897
+ )].sort((f, h) => f.localeCompare(h)).map((f) => ({
1898
+ value: f,
1899
+ label: f
1900
+ })), [N, ne]), me = U(() => N.filter((l) => !(j.length > 0 && !j.includes(l.application_id) || V.length > 0 && !V.includes(Ce(l, ne)))), [N, ne, V, j]), fe = Y.length > 1, ve = _e.length > 1, u = fe || ve;
1901
+ B(() => {
1902
+ if (N.length === 0)
1903
+ return;
1904
+ let l = !1;
1905
+ return (async () => {
1906
+ const f = await Promise.allSettled(
1907
+ N.map(async (h) => {
1908
+ const F = await z(h.invocation_id);
1909
+ return {
1910
+ agentId: h.id,
1911
+ invocationId: h.invocation_id,
1912
+ checklist: F.checklist
1913
+ };
1914
+ })
1915
+ );
1916
+ l || (le((h) => {
1917
+ const F = { ...h };
1918
+ for (const ge of f)
1919
+ ge.status === "fulfilled" && (F[ge.value.invocationId] = ge.value.checklist);
1920
+ return F;
1921
+ }), te((h) => {
1922
+ const F = { ...h };
1923
+ return f.forEach((ge, Qe) => {
1924
+ ge.status === "rejected" && (F[N[Qe].id] = be);
1925
+ }), F;
1926
+ }));
1927
+ })(), () => {
1928
+ l = !0;
1929
+ };
1930
+ }, [N, z]);
1931
+ const A = I(
1932
+ async (l) => {
1933
+ if (!L[l.invocation_id]) {
1934
+ W(l.id), te((f) => {
1935
+ const h = { ...f };
1936
+ return delete h[l.id], h;
1937
+ });
1938
+ try {
1939
+ const f = await z(l.invocation_id);
1940
+ le((h) => ({
1941
+ ...h,
1942
+ [l.invocation_id]: f.checklist
1943
+ }));
1944
+ } catch {
1945
+ te((f) => ({
1946
+ ...f,
1947
+ [l.id]: be
1948
+ }));
1949
+ } finally {
1950
+ W((f) => f === l.id ? null : f);
1951
+ }
1952
+ }
1953
+ },
1954
+ [z, L]
1955
+ ), se = I(
1956
+ (l) => {
1957
+ if ($ === l) {
1958
+ K(null);
1959
+ return;
1960
+ }
1961
+ const f = N.find(({ id: h }) => h === l);
1962
+ f && (K(l), A(f));
1963
+ },
1964
+ [N, $, A]
1965
+ ), de = U(() => {
1966
+ const l = {};
1967
+ for (const f of me) {
1968
+ const h = ln(
1969
+ f,
1970
+ L[f.invocation_id]
1971
+ );
1972
+ (l[h] ?? (l[h] = [])).push(f);
1973
+ }
1974
+ return l;
1975
+ }, [me, L]), je = I((l) => {
1976
+ k(l);
1977
+ }, []), Ve = I(
1978
+ async (l) => {
1979
+ const f = await ae(l);
1980
+ k(f), C(!1);
1981
+ },
1982
+ [ae]
1983
+ ), Ye = I(() => {
1984
+ k(null);
1985
+ }, []), Te = U(
1986
+ () => m ? ee(m) : void 0,
1987
+ [ee, m]
1988
+ ), Ee = {
1989
+ expandedAgentId: $,
1990
+ loadingAgentId: J,
1991
+ checklistByInvocationId: L,
1992
+ errorByAgentId: Ne,
1993
+ definitionNameByRef: ne,
1994
+ onToggleAgent: se,
1995
+ onViewAgent: je
1996
+ };
1997
+ return /* @__PURE__ */ i("div", { className: "agent-view-frontend agent-view", children: [
1998
+ /* @__PURE__ */ i("div", { className: "agent-view__header", children: [
1999
+ /* @__PURE__ */ n(he, { level: 1, children: "Agents" }),
2000
+ /* @__PURE__ */ n(
2001
+ X,
2002
+ {
2003
+ variant: "primary",
2004
+ size: "S",
2005
+ iconLeftName: "sparkles",
2006
+ iconLeftScreenReaderText: "Start an agent",
2007
+ onClick: () => C(!0),
2008
+ children: "Start an agent"
2009
+ }
2010
+ )
2011
+ ] }),
2012
+ N.length > 0 && u && /* @__PURE__ */ i("div", { className: "agent-view__filters", children: [
2013
+ fe && /* @__PURE__ */ i("div", { className: "agent-view__filter", children: [
2014
+ /* @__PURE__ */ n(
2015
+ "label",
2016
+ {
2017
+ className: "agent-view__filter-label",
2018
+ htmlFor: "agent-view-institution-filter",
2019
+ children: "Institution"
2020
+ }
2021
+ ),
2022
+ /* @__PURE__ */ n(
2023
+ Oe,
2024
+ {
2025
+ id: "agent-view-institution-filter",
2026
+ triggerVariant: "button",
2027
+ multiple: !0,
2028
+ searchType: "substring",
2029
+ placeholder: "All institutions",
2030
+ options: Y,
2031
+ value: j,
2032
+ onValueChange: ye,
2033
+ showSelectionCountBadge: !0,
2034
+ showClearAll: !0,
2035
+ clearAllLabel: "Clear institutions"
2036
+ }
2037
+ )
2038
+ ] }),
2039
+ ve && /* @__PURE__ */ i("div", { className: "agent-view__filter", children: [
2040
+ /* @__PURE__ */ n(
2041
+ "label",
2042
+ {
2043
+ className: "agent-view__filter-label",
2044
+ htmlFor: "agent-view-agent-filter",
2045
+ children: "Agent"
2046
+ }
2047
+ ),
2048
+ /* @__PURE__ */ n(
2049
+ Oe,
2050
+ {
2051
+ id: "agent-view-agent-filter",
2052
+ triggerVariant: "button",
2053
+ multiple: !0,
2054
+ searchType: "substring",
2055
+ placeholder: "All agents",
2056
+ options: _e,
2057
+ value: V,
2058
+ onValueChange: Ae,
2059
+ showSelectionCountBadge: !0,
2060
+ showClearAll: !0,
2061
+ clearAllLabel: "Clear agents"
2062
+ }
2063
+ )
2064
+ ] })
2065
+ ] }),
2066
+ S === "error" ? /* @__PURE__ */ i("div", { className: "agent-view__state agent-view__state--error", role: "alert", children: [
2067
+ /* @__PURE__ */ n(
2068
+ E,
2069
+ {
2070
+ name: "triangle-alert",
2071
+ size: 24,
2072
+ color: "var(--color-semantic-destructive-600)"
2073
+ }
2074
+ ),
2075
+ /* @__PURE__ */ n("p", { className: "agent-view__state-message", children: H ?? ze }),
2076
+ /* @__PURE__ */ n(X, { variant: "secondary", size: "S", onClick: q, children: "Try again" })
2077
+ ] }) : S === "loading" && N.length === 0 ? /* @__PURE__ */ i("div", { className: "agent-view__state", "aria-live": "polite", children: [
2078
+ /* @__PURE__ */ n(
2079
+ E,
2080
+ {
2081
+ name: "loader",
2082
+ size: 24,
2083
+ color: "var(--color-brand-600)",
2084
+ className: "agent-view__progress-icon--spinning",
2085
+ screenReaderText: Pe
2086
+ }
2087
+ ),
2088
+ /* @__PURE__ */ n("p", { className: "agent-view__state-message", children: Pe })
2089
+ ] }) : N.length === 0 ? /* @__PURE__ */ n(kt, {}) : /* @__PURE__ */ i("div", { className: "agent-view__board", children: [
2090
+ it.map((l) => /* @__PURE__ */ n(
2091
+ Fe,
2092
+ {
2093
+ column: we[l],
2094
+ agents: de[l] ?? [],
2095
+ ...Ee
2096
+ },
2097
+ l
2098
+ )),
2099
+ /* @__PURE__ */ n("div", { className: "agent-view__split-column", children: ct.map((l) => /* @__PURE__ */ n(
2100
+ Fe,
2101
+ {
2102
+ column: we[l],
2103
+ agents: de[l] ?? [],
2104
+ isSplit: !0,
2105
+ ...Ee
2106
+ },
2107
+ l
2108
+ )) })
2109
+ ] }),
2110
+ m && Te && /* @__PURE__ */ n(
2111
+ Lt,
2112
+ {
2113
+ agent: m,
2114
+ open: !0,
2115
+ initialChecklist: L[m.invocation_id] ?? null,
2116
+ fetchAgentChecklist: z,
2117
+ fetchAgentResources: ce,
2118
+ onClose: Ye,
2119
+ connector: Te
2120
+ },
2121
+ m.id
2122
+ ),
2123
+ /* @__PURE__ */ n(
2124
+ Ut,
2125
+ {
2126
+ open: y,
2127
+ onClose: () => C(!1),
2128
+ onStart: Ve,
2129
+ agentDefinitions: D
2130
+ }
2131
+ )
2132
+ ] });
2133
+ }, kn = (e, t) => {
2134
+ const s = Date.now(), a = t.trim() || e.agent_intent;
2135
+ return {
2136
+ id: `agent-${s}`,
2137
+ invocation_id: `inv-${s}`,
2138
+ agent_definition_ref: e.ref,
2139
+ agent_intent: e.agent_intent,
2140
+ invocation_name: a,
2141
+ application_id: lt,
2142
+ created_by: dt,
2143
+ status: v["generating-a-response"],
2144
+ context_ref: null,
2145
+ checklist_ref: null
2146
+ };
2147
+ };
2148
+ export {
2149
+ wn as AgentMonitorKanban,
2150
+ Bt as AgentServiceClient,
2151
+ ue as AgentServiceError,
2152
+ Lt as AgentView,
2153
+ Wt as HttpChatConnector,
2154
+ Ut as NewAgentModal,
2155
+ kn as buildAgentFromDefinition,
2156
+ Jt as createHttpChatConnectorFactory,
2157
+ He as mapApiAgent,
2158
+ Yt as mapApiAgentDefinition,
2159
+ jt as mapApiAgentStatus,
2160
+ nn as mapApiChecklistEndpointResponse,
2161
+ Je as mapApiChecklistItem,
2162
+ vn as mapApiChecklistResponse,
2163
+ Vt as mapApiChecklistStatus,
2164
+ ke as mapApiOpeningMessage,
2165
+ Zt as mapApiResource,
2166
+ en as mapApiResourcesEndpointResponse,
2167
+ fn as mapApiTripOption,
2168
+ on as useAgentService
2169
+ };