@tangle-network/agent-app 0.60.20 → 0.60.22

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.
Files changed (57) hide show
  1. package/dist/agent-profiles/d1.js +3 -3
  2. package/dist/agent-profiles/index.js +3 -3
  3. package/dist/agent-surfaces/cli.js +1 -1
  4. package/dist/agent-surfaces/index.js +1 -1
  5. package/dist/app-auth/index.js +3 -3
  6. package/dist/assistant/index.js +7 -7
  7. package/dist/chat-routes/index.js +7 -7
  8. package/dist/chat-store/index.js +2 -2
  9. package/dist/{chunk-MUZQUS6X.js → chunk-24Y6QVHL.js} +2 -2
  10. package/dist/{chunk-YWNK6OTQ.js → chunk-4DIO2LTR.js} +5 -5
  11. package/dist/{chunk-YWNK6OTQ.js.map → chunk-4DIO2LTR.js.map} +1 -1
  12. package/dist/{chunk-AKC5ZC4R.js → chunk-CN5HNTU6.js} +1 -1
  13. package/dist/{chunk-XPTYP3FP.js → chunk-HWJOTTEI.js} +2 -2
  14. package/dist/{chunk-KXGGCENC.js → chunk-J7TCMW2J.js} +2 -2
  15. package/dist/{chunk-XXUG4FS2.js → chunk-M36GXE2W.js} +3 -3
  16. package/dist/chunk-NV7TNF7V.js +739 -0
  17. package/dist/chunk-NV7TNF7V.js.map +1 -0
  18. package/dist/{chunk-YO6DEA5T.js → chunk-S2G5NAWV.js} +4 -4
  19. package/dist/{chunk-LECWJ33T.js → chunk-T2IESIJ7.js} +2 -2
  20. package/dist/{chunk-HTAFI247.js → chunk-WTGSLW5X.js} +4 -4
  21. package/dist/{chunk-HGKDZQ52.js → chunk-XGPINAHY.js} +9 -5
  22. package/dist/{chunk-HGKDZQ52.js.map → chunk-XGPINAHY.js.map} +1 -1
  23. package/dist/design-canvas-react/index.js +4 -4
  24. package/dist/design-canvas-react/lazy.js +1 -1
  25. package/dist/hub-approvals/index.d.ts +28 -0
  26. package/dist/hub-approvals/index.js +35 -0
  27. package/dist/hub-approvals/index.js.map +1 -0
  28. package/dist/hub-approvals/present.d.ts +26 -0
  29. package/dist/hub-approvals/result.d.ts +22 -0
  30. package/dist/hub-approvals/types.d.ts +192 -0
  31. package/dist/hub-approvals-react/dock.d.ts +40 -0
  32. package/dist/hub-approvals-react/index.d.ts +22 -0
  33. package/dist/hub-approvals-react/index.js +704 -0
  34. package/dist/hub-approvals-react/index.js.map +1 -0
  35. package/dist/hub-approvals-react/list.d.ts +14 -0
  36. package/dist/hub-approvals-react/parts.d.ts +37 -0
  37. package/dist/hub-approvals-react/preview.d.ts +11 -0
  38. package/dist/hub-approvals-react/receipt.d.ts +24 -0
  39. package/dist/hub-approvals-react/row.d.ts +19 -0
  40. package/dist/preset-cloudflare/index.js +2 -2
  41. package/dist/public-consultation/index.js +3 -3
  42. package/dist/sandbox/index.js +4 -4
  43. package/dist/tools/index.js +4 -4
  44. package/dist/web-react/index.js +15 -15
  45. package/dist/work-product/index.js +2 -2
  46. package/dist/workspace-react/companion.d.ts +7 -3
  47. package/dist/workspace-react/index.js +13 -6
  48. package/dist/workspace-react/index.js.map +1 -1
  49. package/package.json +14 -4
  50. /package/dist/{chunk-MUZQUS6X.js.map → chunk-24Y6QVHL.js.map} +0 -0
  51. /package/dist/{chunk-AKC5ZC4R.js.map → chunk-CN5HNTU6.js.map} +0 -0
  52. /package/dist/{chunk-XPTYP3FP.js.map → chunk-HWJOTTEI.js.map} +0 -0
  53. /package/dist/{chunk-KXGGCENC.js.map → chunk-J7TCMW2J.js.map} +0 -0
  54. /package/dist/{chunk-XXUG4FS2.js.map → chunk-M36GXE2W.js.map} +0 -0
  55. /package/dist/{chunk-YO6DEA5T.js.map → chunk-S2G5NAWV.js.map} +0 -0
  56. /package/dist/{chunk-LECWJ33T.js.map → chunk-T2IESIJ7.js.map} +0 -0
  57. /package/dist/{chunk-HTAFI247.js.map → chunk-WTGSLW5X.js.map} +0 -0
@@ -0,0 +1,704 @@
1
+ import {
2
+ HUB_APPROVAL_ACTIVE_PHASES,
3
+ HUB_APPROVAL_OPEN_PHASES,
4
+ HUB_APPROVAL_PHASE_LABELS,
5
+ formatMinorAmount,
6
+ formatWhen,
7
+ hubActionReceipt,
8
+ presentHubAction
9
+ } from "../chunk-NV7TNF7V.js";
10
+
11
+ // src/hub-approvals-react/dock.tsx
12
+ import { useEffect, useMemo, useRef, useState as useState2 } from "react";
13
+ import { Check, ChevronDown, ChevronLeft, ChevronRight as ChevronRight2, ExternalLink, Loader2, X } from "lucide-react";
14
+ import { Button as Button2, Label, RadioGroup, RadioGroupItem } from "@tangle-network/ui/primitives";
15
+
16
+ // src/hub-approvals-react/parts.tsx
17
+ import { useState } from "react";
18
+ import { ChevronRight } from "lucide-react";
19
+ import { ProviderIcon } from "@tangle-network/sandbox-ui/integrations";
20
+ import { Button, StatusPill } from "@tangle-network/ui/primitives";
21
+ import { jsx, jsxs } from "react/jsx-runtime";
22
+ var PHASE_TONES = {
23
+ waiting: "warning",
24
+ blocked: "warning",
25
+ queued: "running",
26
+ running: "running",
27
+ done: "success",
28
+ failed: "danger",
29
+ denied: "neutral",
30
+ expired: "neutral"
31
+ };
32
+ function HubApprovalPhasePill({ phase, label }) {
33
+ return /* @__PURE__ */ jsx(StatusPill, { tone: PHASE_TONES[phase], size: "md", className: "shrink-0 whitespace-nowrap", children: label ?? HUB_APPROVAL_PHASE_LABELS[phase] });
34
+ }
35
+ function HubProviderMark({ providerId, name, size = 28 }) {
36
+ const inner = Math.round(size * 0.64);
37
+ return /* @__PURE__ */ jsx(
38
+ "span",
39
+ {
40
+ className: "flex shrink-0 items-center justify-center rounded-lg border border-border bg-background",
41
+ style: { width: size, height: size },
42
+ children: /* @__PURE__ */ jsx(ProviderIcon, { id: providerId, displayName: name, size: inner, className: "rounded-sm" })
43
+ }
44
+ );
45
+ }
46
+ function HubRawDetails({ sections }) {
47
+ const [open, setOpen] = useState(false);
48
+ const shown = sections.filter((section) => section.value !== void 0 && section.value !== null && section.value !== "");
49
+ if (shown.length === 0) return null;
50
+ return /* @__PURE__ */ jsxs("div", { children: [
51
+ /* @__PURE__ */ jsxs(
52
+ Button,
53
+ {
54
+ variant: "bare",
55
+ "aria-expanded": open,
56
+ onClick: () => setOpen((value) => !value),
57
+ className: "inline-flex min-h-8 items-center gap-1 rounded-md text-sm font-medium text-muted-foreground hover:text-foreground",
58
+ children: [
59
+ /* @__PURE__ */ jsx(ChevronRight, { "aria-hidden": true, className: `size-4 transition-transform ${open ? "rotate-90" : ""}` }),
60
+ "Details"
61
+ ]
62
+ }
63
+ ),
64
+ open && /* @__PURE__ */ jsx("div", { className: "mt-2 space-y-3", children: shown.map((section) => /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
65
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-muted-foreground", children: section.label }),
66
+ /* @__PURE__ */ jsx("pre", { className: "max-h-64 overflow-auto whitespace-pre-wrap break-all rounded-lg border border-border bg-muted/40 p-3 font-mono text-sm leading-5 text-foreground", children: typeof section.value === "string" ? section.value : JSON.stringify(section.value, null, 2) })
67
+ ] }, section.label)) })
68
+ ] });
69
+ }
70
+ function HubFieldList({ fields }) {
71
+ if (fields.length === 0) return null;
72
+ return /* @__PURE__ */ jsx("dl", { className: "flex flex-wrap gap-x-6 gap-y-2 text-sm", children: fields.map((field) => /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 max-w-full items-baseline gap-2", children: [
73
+ /* @__PURE__ */ jsx("dt", { className: "shrink-0 text-muted-foreground", children: field.label }),
74
+ /* @__PURE__ */ jsx("dd", { className: `min-w-0 truncate text-foreground ${field.mono ? "font-mono" : ""}`, title: field.value, children: field.href ? /* @__PURE__ */ jsx("a", { href: field.href, target: "_blank", rel: "noreferrer", className: "text-[var(--accent-text)] underline-offset-2 hover:underline", children: field.value }) : field.value })
75
+ ] }, `${field.label}:${field.value}`)) });
76
+ }
77
+ function Chip({ children, mono }) {
78
+ return /* @__PURE__ */ jsx("span", { className: `inline-flex max-w-full items-center truncate rounded-md border border-border bg-muted/50 px-1.5 py-0.5 text-sm text-foreground ${mono ? "font-mono" : ""}`, children });
79
+ }
80
+ function closesIn(expiresAt, now = Date.now()) {
81
+ if (!expiresAt) return null;
82
+ const minutes = Math.ceil((Date.parse(expiresAt) - now) / 6e4);
83
+ if (!Number.isFinite(minutes) || minutes <= 0) return null;
84
+ return minutes >= 120 ? `closes in ${Math.round(minutes / 60)} h` : `closes in ${minutes} min`;
85
+ }
86
+ function relativeTime(at, now = Date.now()) {
87
+ if (!at) return null;
88
+ const then = Date.parse(at);
89
+ if (!Number.isFinite(then)) return null;
90
+ const minutes = Math.round((now - then) / 6e4);
91
+ if (minutes < 1) return "just now";
92
+ if (minutes < 60) return `${minutes} min ago`;
93
+ if (minutes < 24 * 60) return `${Math.round(minutes / 60)} h ago`;
94
+ return new Date(then).toLocaleDateString(void 0, { month: "short", day: "numeric" });
95
+ }
96
+
97
+ // src/hub-approvals-react/preview.tsx
98
+ import { ArrowRight, CalendarDays, GitBranch, GitCommitHorizontal, GitPullRequest, MapPin, Phone, Users } from "lucide-react";
99
+ import { ApprovalDiffSummary } from "@tangle-network/ui/run";
100
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
101
+ function plainText(body, html) {
102
+ if (!html) return body;
103
+ return body.replace(/<(script|style)[\s\S]*?<\/\1>/gi, "").replace(/<br\s*\/?>/gi, "\n").replace(/<\/(p|div|li|h[1-6]|tr)>/gi, "\n").replace(/<[^>]+>/g, "").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/\n{3,}/g, "\n\n").trim();
104
+ }
105
+ function initial(name) {
106
+ return (name?.trim().replace(/^@/, "").charAt(0) || "?").toUpperCase();
107
+ }
108
+ function Panel({ children, className = "" }) {
109
+ return /* @__PURE__ */ jsx2("div", { className: `rounded-lg border border-border bg-background ${className}`, children });
110
+ }
111
+ function PullRequestPreview({ preview }) {
112
+ return /* @__PURE__ */ jsxs2("div", { className: "space-y-3", children: [
113
+ /* @__PURE__ */ jsxs2(Panel, { className: "px-3 py-3", children: [
114
+ /* @__PURE__ */ jsxs2("div", { className: "flex flex-wrap items-center gap-2 text-sm text-muted-foreground", children: [
115
+ /* @__PURE__ */ jsx2(GitPullRequest, { "aria-hidden": true, className: "size-4 shrink-0" }),
116
+ preview.repository && /* @__PURE__ */ jsx2("span", { className: "font-medium text-foreground", children: preview.repository }),
117
+ preview.head && preview.base && /* @__PURE__ */ jsxs2("span", { className: "flex min-w-0 flex-wrap items-center gap-1.5", children: [
118
+ /* @__PURE__ */ jsx2(Chip, { mono: true, children: preview.head }),
119
+ /* @__PURE__ */ jsx2(ArrowRight, { "aria-label": "into", className: "size-4 shrink-0" }),
120
+ /* @__PURE__ */ jsx2(Chip, { mono: true, children: preview.base })
121
+ ] }),
122
+ preview.draft && /* @__PURE__ */ jsx2("span", { className: "rounded-md border border-border px-1.5 py-0.5 text-sm text-muted-foreground", children: "Draft" })
123
+ ] }),
124
+ preview.title && /* @__PURE__ */ jsx2("p", { className: "mt-2 text-base font-semibold leading-6 text-foreground", children: preview.title }),
125
+ preview.body && /* @__PURE__ */ jsx2("p", { className: "mt-1 line-clamp-3 whitespace-pre-line text-sm leading-6 text-muted-foreground sm:line-clamp-4", children: preview.body })
126
+ ] }),
127
+ preview.files.length > 0 && /* @__PURE__ */ jsx2(ApprovalDiffSummary, { files: preview.files })
128
+ ] });
129
+ }
130
+ function EmailPreview({ preview, account }) {
131
+ const rows = [
132
+ ...account ? [["From", account]] : [],
133
+ ...preview.to.length ? [["To", preview.to.join(", ")]] : [],
134
+ ...preview.cc.length ? [["Cc", preview.cc.join(", ")]] : [],
135
+ ...preview.bcc.length ? [["Bcc", preview.bcc.join(", ")]] : []
136
+ ];
137
+ const body = preview.body ? plainText(preview.body, preview.html) : "";
138
+ return /* @__PURE__ */ jsxs2(Panel, { className: "overflow-hidden", children: [
139
+ /* @__PURE__ */ jsxs2("dl", { className: "grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 border-b border-border px-3 py-2.5 text-sm", children: [
140
+ rows.map(([label, value]) => /* @__PURE__ */ jsxs2("div", { className: "contents", children: [
141
+ /* @__PURE__ */ jsx2("dt", { className: "text-muted-foreground", children: label }),
142
+ /* @__PURE__ */ jsx2("dd", { className: "break-words text-foreground", children: value })
143
+ ] }, label)),
144
+ preview.subject && /* @__PURE__ */ jsxs2("div", { className: "contents", children: [
145
+ /* @__PURE__ */ jsx2("dt", { className: "text-muted-foreground", children: "Subject" }),
146
+ /* @__PURE__ */ jsx2("dd", { className: "break-words font-semibold text-foreground", children: preview.subject })
147
+ ] }),
148
+ preview.reply && !preview.subject && /* @__PURE__ */ jsxs2("div", { className: "contents", children: [
149
+ /* @__PURE__ */ jsx2("dt", { className: "text-muted-foreground", children: "Reply" }),
150
+ /* @__PURE__ */ jsx2("dd", { className: "text-foreground", children: "In the existing conversation" })
151
+ ] })
152
+ ] }),
153
+ body && /* @__PURE__ */ jsx2("div", { className: "max-h-60 overflow-y-auto whitespace-pre-wrap break-words px-3 py-3 text-sm leading-6 text-foreground", children: body })
154
+ ] });
155
+ }
156
+ function PostPreview({ preview, account }) {
157
+ if (preview.channel === "slack") {
158
+ return /* @__PURE__ */ jsxs2(Panel, { className: "px-3 py-3", children: [
159
+ /* @__PURE__ */ jsx2("p", { className: "text-sm font-semibold text-foreground", children: preview.where ?? "Slack" }),
160
+ /* @__PURE__ */ jsxs2("div", { className: "mt-2 flex gap-3", children: [
161
+ /* @__PURE__ */ jsx2("span", { className: "flex size-9 shrink-0 items-center justify-center rounded-md bg-muted text-sm font-semibold text-foreground", children: initial(account) }),
162
+ /* @__PURE__ */ jsxs2("div", { className: "min-w-0", children: [
163
+ /* @__PURE__ */ jsx2("p", { className: "text-sm font-semibold text-foreground", children: account ?? "Your account" }),
164
+ /* @__PURE__ */ jsx2("p", { className: "whitespace-pre-wrap break-words text-sm leading-6 text-foreground", children: preview.text })
165
+ ] })
166
+ ] })
167
+ ] });
168
+ }
169
+ const x = preview.channel === "x";
170
+ const length = [...preview.text].length;
171
+ return /* @__PURE__ */ jsxs2(Panel, { className: "px-4 py-3", children: [
172
+ /* @__PURE__ */ jsxs2("div", { className: "flex gap-3", children: [
173
+ /* @__PURE__ */ jsx2("span", { className: `flex size-10 shrink-0 items-center justify-center rounded-full text-base font-semibold ${x ? "bg-foreground text-background" : "bg-[#0a66c2] text-white"}`, children: initial(account) }),
174
+ /* @__PURE__ */ jsxs2("div", { className: "min-w-0 flex-1", children: [
175
+ /* @__PURE__ */ jsxs2("p", { className: "flex flex-wrap items-baseline gap-x-1.5 text-sm", children: [
176
+ /* @__PURE__ */ jsx2("span", { className: "font-semibold text-foreground", children: account ?? "Your account" }),
177
+ /* @__PURE__ */ jsx2("span", { className: "text-muted-foreground", children: x ? "\xB7 now" : "\xB7 Post \xB7 Anyone" })
178
+ ] }),
179
+ /* @__PURE__ */ jsx2("p", { className: `mt-1 whitespace-pre-wrap break-words text-foreground ${x ? "text-base leading-6" : "text-sm leading-6"}`, children: preview.text }),
180
+ preview.link && /* @__PURE__ */ jsx2("div", { className: "mt-3 overflow-hidden rounded-lg border border-border", children: /* @__PURE__ */ jsxs2("div", { className: "px-3 py-2", children: [
181
+ /* @__PURE__ */ jsx2("p", { className: "truncate text-sm text-muted-foreground", children: preview.link.url.replace(/^https?:\/\//, "") }),
182
+ preview.link.title && /* @__PURE__ */ jsx2("p", { className: "truncate text-sm font-semibold text-foreground", children: preview.link.title }),
183
+ preview.link.description && /* @__PURE__ */ jsx2("p", { className: "line-clamp-2 text-sm text-muted-foreground", children: preview.link.description })
184
+ ] }) })
185
+ ] })
186
+ ] }),
187
+ x && /* @__PURE__ */ jsxs2("p", { className: `mt-2 text-right text-sm tabular-nums ${length > 280 ? "text-[var(--surface-danger-text)]" : "text-muted-foreground"}`, children: [
188
+ length,
189
+ " / 280"
190
+ ] })
191
+ ] });
192
+ }
193
+ function PaymentPreview({ preview }) {
194
+ return /* @__PURE__ */ jsxs2(Panel, { className: "px-4 py-3", children: [
195
+ /* @__PURE__ */ jsx2("p", { className: "text-sm text-muted-foreground", children: preview.label.charAt(0).toUpperCase() + preview.label.slice(1) }),
196
+ preview.amount !== void 0 && /* @__PURE__ */ jsx2("p", { className: "mt-0.5 text-2xl font-semibold tabular-nums text-foreground", children: formatMinorAmount(preview.amount, preview.currency) }),
197
+ /* @__PURE__ */ jsxs2("div", { className: "mt-2 space-y-1 text-sm", children: [
198
+ preview.customer && /* @__PURE__ */ jsxs2("p", { className: "text-muted-foreground", children: [
199
+ "Customer ",
200
+ /* @__PURE__ */ jsx2("span", { className: `text-foreground ${preview.customer.startsWith("cus_") ? "font-mono" : ""}`, children: preview.customer })
201
+ ] }),
202
+ preview.description && /* @__PURE__ */ jsx2("p", { className: "text-foreground", children: preview.description })
203
+ ] })
204
+ ] });
205
+ }
206
+ function SpeechPreview({ preview }) {
207
+ return /* @__PURE__ */ jsxs2(Panel, { className: "px-4 py-3", children: [
208
+ /* @__PURE__ */ jsx2("blockquote", { className: "border-l-2 border-[var(--accent-text)] pl-3 text-base leading-7 text-foreground", children: preview.text }),
209
+ (preview.voice || preview.seconds) && /* @__PURE__ */ jsxs2("div", { className: "mt-3 flex flex-wrap gap-2", children: [
210
+ preview.voice && /* @__PURE__ */ jsxs2(Chip, { children: [
211
+ "Voice: ",
212
+ preview.voice
213
+ ] }),
214
+ preview.seconds && /* @__PURE__ */ jsxs2(Chip, { children: [
215
+ "About ",
216
+ preview.seconds,
217
+ " s"
218
+ ] })
219
+ ] })
220
+ ] });
221
+ }
222
+ function CallPreview({ preview }) {
223
+ return /* @__PURE__ */ jsxs2(Panel, { className: "flex gap-3 px-4 py-3", children: [
224
+ /* @__PURE__ */ jsx2("span", { className: "flex size-10 shrink-0 items-center justify-center rounded-full bg-muted", children: /* @__PURE__ */ jsx2(Phone, { "aria-hidden": true, className: "size-5 text-foreground" }) }),
225
+ /* @__PURE__ */ jsxs2("div", { className: "min-w-0 space-y-1 text-sm", children: [
226
+ /* @__PURE__ */ jsx2("p", { className: "text-base font-semibold tabular-nums text-foreground", children: preview.to ?? "Unknown number" }),
227
+ preview.from && /* @__PURE__ */ jsxs2("p", { className: "text-muted-foreground", children: [
228
+ "From ",
229
+ /* @__PURE__ */ jsx2("span", { className: "tabular-nums text-foreground", children: preview.from })
230
+ ] }),
231
+ preview.purpose && /* @__PURE__ */ jsx2("p", { className: "leading-6 text-foreground", children: preview.purpose })
232
+ ] })
233
+ ] });
234
+ }
235
+ function EventPreview({ preview }) {
236
+ const start = preview.start ? new Date(preview.start) : null;
237
+ const valid = start && !Number.isNaN(start.getTime());
238
+ return /* @__PURE__ */ jsxs2(Panel, { className: "flex gap-4 px-4 py-3", children: [
239
+ /* @__PURE__ */ jsxs2("div", { className: "flex w-14 shrink-0 flex-col items-center overflow-hidden rounded-lg border border-border text-center", children: [
240
+ /* @__PURE__ */ jsx2("span", { className: "w-full bg-[var(--surface-danger-bg)] py-0.5 text-sm font-semibold uppercase text-[var(--surface-danger-text)]", children: valid ? start.toLocaleDateString(void 0, { month: "short" }) : /* @__PURE__ */ jsx2(CalendarDays, { "aria-hidden": true, className: "mx-auto size-4" }) }),
241
+ /* @__PURE__ */ jsx2("span", { className: "py-1 text-xl font-semibold tabular-nums text-foreground", children: valid ? start.getDate() : "\u2013" })
242
+ ] }),
243
+ /* @__PURE__ */ jsxs2("div", { className: "min-w-0 space-y-1 text-sm", children: [
244
+ /* @__PURE__ */ jsx2("p", { className: "text-base font-semibold text-foreground", children: preview.title ?? "Untitled event" }),
245
+ preview.start && /* @__PURE__ */ jsx2("p", { className: "text-foreground", children: formatWhen(preview.start, preview.end) }),
246
+ preview.location && /* @__PURE__ */ jsxs2("p", { className: "flex items-center gap-1.5 text-muted-foreground", children: [
247
+ /* @__PURE__ */ jsx2(MapPin, { "aria-hidden": true, className: "size-4 shrink-0" }),
248
+ preview.location
249
+ ] }),
250
+ preview.attendees.length > 0 && /* @__PURE__ */ jsxs2("p", { className: "flex items-start gap-1.5 text-muted-foreground", children: [
251
+ /* @__PURE__ */ jsx2(Users, { "aria-hidden": true, className: "mt-0.5 size-4 shrink-0" }),
252
+ /* @__PURE__ */ jsx2("span", { className: "break-words", children: preview.attendees.join(", ") })
253
+ ] }),
254
+ preview.description && /* @__PURE__ */ jsx2("p", { className: "line-clamp-3 leading-6 text-foreground", children: preview.description })
255
+ ] })
256
+ ] });
257
+ }
258
+ function HubActionPreviewView({ preview, account }) {
259
+ switch (preview.kind) {
260
+ case "pull-request":
261
+ return /* @__PURE__ */ jsx2(PullRequestPreview, { preview });
262
+ case "files":
263
+ return preview.files.length > 0 ? /* @__PURE__ */ jsx2(ApprovalDiffSummary, { files: preview.files }) : null;
264
+ case "commit":
265
+ return /* @__PURE__ */ jsxs2(Panel, { className: "px-3 py-3", children: [
266
+ /* @__PURE__ */ jsxs2("p", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: [
267
+ /* @__PURE__ */ jsx2(GitCommitHorizontal, { "aria-hidden": true, className: "size-4 shrink-0" }),
268
+ preview.repository ?? "Commit"
269
+ ] }),
270
+ preview.message && /* @__PURE__ */ jsx2("p", { className: "mt-2 whitespace-pre-line text-sm leading-6 text-foreground", children: preview.message }),
271
+ /* @__PURE__ */ jsx2("div", { className: "mt-2", children: /* @__PURE__ */ jsx2(HubFieldList, { fields: [
272
+ ...preview.tree ? [{ label: "Tree", value: preview.tree.slice(0, 7), mono: true }] : [],
273
+ ...preview.parents.map((parent) => ({ label: "Parent", value: parent.slice(0, 7), mono: true }))
274
+ ] }) })
275
+ ] });
276
+ case "branch":
277
+ return /* @__PURE__ */ jsxs2(Panel, { className: "flex flex-wrap items-center gap-2 px-3 py-3 text-sm", children: [
278
+ /* @__PURE__ */ jsx2(GitBranch, { "aria-hidden": true, className: "size-4 shrink-0 text-muted-foreground" }),
279
+ preview.branch && /* @__PURE__ */ jsx2(Chip, { mono: true, children: preview.branch }),
280
+ preview.sha && /* @__PURE__ */ jsxs2("span", { className: "text-muted-foreground", children: [
281
+ "at ",
282
+ /* @__PURE__ */ jsx2("span", { className: "font-mono text-foreground", children: preview.sha.slice(0, 7) })
283
+ ] })
284
+ ] });
285
+ case "issue":
286
+ return /* @__PURE__ */ jsxs2(Panel, { className: "px-3 py-3", children: [
287
+ preview.verdict && /* @__PURE__ */ jsx2("p", { className: "text-sm font-medium capitalize text-foreground", children: preview.verdict }),
288
+ preview.title && /* @__PURE__ */ jsx2("p", { className: "text-base font-semibold leading-6 text-foreground", children: preview.title }),
289
+ preview.body && /* @__PURE__ */ jsx2("p", { className: "mt-1 line-clamp-6 whitespace-pre-line text-sm leading-6 text-foreground", children: preview.body })
290
+ ] });
291
+ case "email":
292
+ return /* @__PURE__ */ jsx2(EmailPreview, { preview, account });
293
+ case "post":
294
+ return /* @__PURE__ */ jsx2(PostPreview, { preview, account });
295
+ case "payment":
296
+ return /* @__PURE__ */ jsx2(PaymentPreview, { preview });
297
+ case "speech":
298
+ return /* @__PURE__ */ jsx2(SpeechPreview, { preview });
299
+ case "call":
300
+ return /* @__PURE__ */ jsx2(CallPreview, { preview });
301
+ case "event":
302
+ return /* @__PURE__ */ jsx2(EventPreview, { preview });
303
+ case "fields":
304
+ return preview.fields.length > 0 ? /* @__PURE__ */ jsx2(Panel, { className: "px-3 py-3", children: /* @__PURE__ */ jsx2(HubFieldList, { fields: preview.fields }) }) : null;
305
+ }
306
+ }
307
+
308
+ // src/hub-approvals-react/dock.tsx
309
+ import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
310
+ var DONE_VISIBLE_MS = 6e3;
311
+ function useNow(intervalMs) {
312
+ const [now, setNow] = useState2(() => Date.now());
313
+ useEffect(() => {
314
+ const timer = setInterval(() => setNow(Date.now()), intervalMs);
315
+ return () => clearInterval(timer);
316
+ }, [intervalMs]);
317
+ return now;
318
+ }
319
+ function Progress({ item }) {
320
+ const provider = presentHubAction(item).provider.name;
321
+ if (item.phase === "queued" || item.phase === "running") {
322
+ return /* @__PURE__ */ jsxs3("p", { role: "status", className: "flex items-center gap-2 text-sm font-medium text-foreground", children: [
323
+ /* @__PURE__ */ jsx3(Loader2, { "aria-hidden": true, className: "size-4 animate-spin text-[var(--surface-info-text)]" }),
324
+ item.phase === "queued" ? "Approved. It runs when the agent\u2019s turn finishes\u2026" : `Running on ${provider}\u2026`
325
+ ] });
326
+ }
327
+ if (item.phase === "done") {
328
+ const receipt = hubActionReceipt(item);
329
+ return /* @__PURE__ */ jsxs3("p", { role: "status", className: "flex min-w-0 items-center gap-2 text-sm font-medium text-foreground", children: [
330
+ /* @__PURE__ */ jsx3(Check, { "aria-hidden": true, className: "size-4 shrink-0 text-[var(--surface-success-text)]" }),
331
+ receipt.href ? /* @__PURE__ */ jsxs3("a", { href: receipt.href, target: "_blank", rel: "noreferrer", className: "inline-flex min-w-0 items-center gap-1 hover:underline", children: [
332
+ /* @__PURE__ */ jsx3("span", { className: "truncate", children: receipt.title }),
333
+ /* @__PURE__ */ jsx3(ExternalLink, { "aria-hidden": true, className: "size-4 shrink-0 text-muted-foreground" })
334
+ ] }) : /* @__PURE__ */ jsx3("span", { className: "truncate", children: receipt.title })
335
+ ] });
336
+ }
337
+ if (item.phase === "failed") {
338
+ return /* @__PURE__ */ jsxs3("p", { role: "alert", className: "break-words text-sm text-[var(--surface-danger-text)]", children: [
339
+ hubActionReceipt(item).title,
340
+ item.error ? `: ${item.error}` : "."
341
+ ] });
342
+ }
343
+ return null;
344
+ }
345
+ function HubApprovalDock({ items, onDecide, permissions, onOpen, focusId, className = "" }) {
346
+ const now = useNow(3e4);
347
+ const watched = useRef(/* @__PURE__ */ new Map());
348
+ const [settled, setSettled] = useState2({});
349
+ const [dismissed, setDismissed] = useState2(/* @__PURE__ */ new Set());
350
+ const [submitting, setSubmitting] = useState2(null);
351
+ const [error, setError] = useState2(null);
352
+ const [activeId, setActiveId] = useState2(null);
353
+ const [collapsed, setCollapsed] = useState2(false);
354
+ const [permissionsOpen, setPermissionsOpen] = useState2(false);
355
+ const [scope, setScope] = useState2(null);
356
+ useEffect(() => {
357
+ const finishedNow = {};
358
+ for (const item of items) {
359
+ const before = watched.current.get(item.id);
360
+ const wasLive = before !== void 0 && (HUB_APPROVAL_OPEN_PHASES.has(before) || HUB_APPROVAL_ACTIVE_PHASES.has(before));
361
+ if (wasLive && (item.phase === "done" || item.phase === "failed")) finishedNow[item.id] = Date.now();
362
+ watched.current.set(item.id, item.phase);
363
+ }
364
+ if (Object.keys(finishedNow).length > 0) setSettled((current) => ({ ...current, ...finishedNow }));
365
+ }, [items]);
366
+ useEffect(() => {
367
+ const doneIds = Object.entries(settled).filter(([id]) => items.find((item) => item.id === id)?.phase === "done");
368
+ if (doneIds.length === 0) return;
369
+ const oldest = Math.min(...doneIds.map(([, at]) => at));
370
+ const timer = setTimeout(() => {
371
+ const cutoff = Date.now() - DONE_VISIBLE_MS;
372
+ setSettled((current) => Object.fromEntries(Object.entries(current).filter(([id, at]) => at > cutoff || items.find((item) => item.id === id)?.phase !== "done")));
373
+ }, Math.max(0, oldest + DONE_VISIBLE_MS - Date.now()));
374
+ return () => clearTimeout(timer);
375
+ }, [settled, items]);
376
+ const queue = useMemo(() => items.filter((item) => !dismissed.has(item.id) && (HUB_APPROVAL_OPEN_PHASES.has(item.phase) || HUB_APPROVAL_ACTIVE_PHASES.has(item.phase) || item.id in settled || submitting?.id === item.id)), [items, dismissed, settled, submitting]);
377
+ useEffect(() => {
378
+ if (focusId && queue.some((item) => item.id === focusId)) {
379
+ setActiveId(focusId);
380
+ setCollapsed(false);
381
+ }
382
+ }, [focusId, queue]);
383
+ const activeIndex = Math.max(0, queue.findIndex((item) => item.id === activeId));
384
+ const active = queue[activeIndex];
385
+ useEffect(() => {
386
+ if (!active || activeId === active.id) return;
387
+ setActiveId(active.id);
388
+ }, [active, activeId]);
389
+ useEffect(() => {
390
+ setPermissionsOpen(false);
391
+ setScope(null);
392
+ }, [active?.id]);
393
+ if (!active) return null;
394
+ const presentation = presentHubAction(active);
395
+ const waitingCount = queue.filter((item) => HUB_APPROVAL_OPEN_PHASES.has(item.phase)).length;
396
+ const choices = permissions?.(active) ?? null;
397
+ const scopes = choices && "scopes" in choices ? choices.scopes : [];
398
+ const chosenScope = scope ?? scopes[0]?.id ?? null;
399
+ const busy = submitting?.id === active.id;
400
+ const decidable = active.phase === "waiting" && !busy;
401
+ const closing = active.phase === "waiting" ? closesIn(active.expiresAt, now) : null;
402
+ const subtitle = [presentation.provider.name, active.account ? `as ${active.account}` : null, closing].filter(Boolean).join(" \xB7 ");
403
+ async function decide(decision, label) {
404
+ if (!active || submitting) return;
405
+ setSubmitting({ id: active.id, label });
406
+ setError(null);
407
+ try {
408
+ await onDecide(active, decision);
409
+ } catch (cause) {
410
+ setError({ id: active.id, message: cause instanceof Error ? cause.message : "The decision did not go through. Try again." });
411
+ } finally {
412
+ setSubmitting(null);
413
+ }
414
+ }
415
+ const step = (delta) => {
416
+ const next = queue[(activeIndex + delta + queue.length) % queue.length];
417
+ if (next) setActiveId(next.id);
418
+ };
419
+ return /* @__PURE__ */ jsxs3(
420
+ "section",
421
+ {
422
+ "aria-label": "Waiting for your approval",
423
+ "data-hub-approval-dock": active.id,
424
+ className: `overflow-hidden rounded-2xl border border-[var(--surface-warning-border)] bg-card shadow-md ${className}`,
425
+ children: [
426
+ /* @__PURE__ */ jsxs3("div", { className: "flex items-start gap-3 px-4 pt-3", children: [
427
+ /* @__PURE__ */ jsx3(HubProviderMark, { providerId: presentation.provider.id, name: presentation.provider.name, size: 32 }),
428
+ /* @__PURE__ */ jsxs3("div", { className: "min-w-0 flex-1", children: [
429
+ /* @__PURE__ */ jsx3("h3", { className: "line-clamp-2 break-words text-base font-semibold leading-6 text-foreground", title: presentation.title, children: presentation.title }),
430
+ /* @__PURE__ */ jsx3("p", { className: "truncate text-sm text-muted-foreground", children: subtitle })
431
+ ] }),
432
+ /* @__PURE__ */ jsxs3("div", { className: "flex shrink-0 items-center gap-1", children: [
433
+ queue.length > 1 && /* @__PURE__ */ jsxs3(Fragment, { children: [
434
+ /* @__PURE__ */ jsx3(Button2, { variant: "ghost", size: "icon-sm", "aria-label": "Previous request", onClick: () => step(-1), children: /* @__PURE__ */ jsx3(ChevronLeft, {}) }),
435
+ /* @__PURE__ */ jsxs3("span", { className: "min-w-14 text-center text-sm tabular-nums text-muted-foreground", "aria-live": "polite", children: [
436
+ activeIndex + 1,
437
+ " of ",
438
+ queue.length
439
+ ] }),
440
+ /* @__PURE__ */ jsx3(Button2, { variant: "ghost", size: "icon-sm", "aria-label": "Next request", onClick: () => step(1), children: /* @__PURE__ */ jsx3(ChevronRight2, {}) })
441
+ ] }),
442
+ /* @__PURE__ */ jsx3(
443
+ Button2,
444
+ {
445
+ variant: "ghost",
446
+ size: "icon-sm",
447
+ "aria-label": collapsed ? "Show the request" : "Hide the preview",
448
+ "aria-expanded": !collapsed,
449
+ onClick: () => setCollapsed((value) => !value),
450
+ children: /* @__PURE__ */ jsx3(ChevronDown, { className: `transition-transform ${collapsed ? "-rotate-90" : ""}` })
451
+ }
452
+ )
453
+ ] })
454
+ ] }),
455
+ !collapsed && /* @__PURE__ */ jsxs3("div", { className: "max-h-64 space-y-3 overflow-y-auto px-4 pt-3 sm:max-h-96", children: [
456
+ active.bundle?.steps && active.bundle.steps.length > 0 && /* @__PURE__ */ jsx3("ol", { className: "space-y-1 text-sm", "aria-label": "Steps this approval covers", children: active.bundle.steps.map((stepItem, index) => /* @__PURE__ */ jsxs3("li", { className: `flex items-center gap-2 ${stepItem.state === "current" ? "font-medium text-foreground" : "text-muted-foreground"}`, children: [
457
+ /* @__PURE__ */ jsx3("span", { className: `flex size-5 shrink-0 items-center justify-center rounded-full border text-sm tabular-nums ${stepItem.state === "done" ? "border-transparent bg-[var(--surface-success-bg)] text-[var(--surface-success-text)]" : "border-border"}`, children: stepItem.state === "done" ? /* @__PURE__ */ jsx3(Check, { "aria-hidden": true, className: "size-3.5" }) : index + 1 }),
458
+ stepItem.label
459
+ ] }, index)) }),
460
+ /* @__PURE__ */ jsx3(HubActionPreviewView, { preview: presentation.preview, account: active.account }),
461
+ /* @__PURE__ */ jsx3(HubRawDetails, { sections: [{ label: "Call", value: { action: active.actionPath, input: active.input } }] })
462
+ ] }),
463
+ /* @__PURE__ */ jsxs3("div", { className: "space-y-3 px-4 pb-4 pt-3", children: [
464
+ busy && submitting && !HUB_APPROVAL_ACTIVE_PHASES.has(active.phase) && active.phase === "waiting" && /* @__PURE__ */ jsxs3("p", { role: "status", className: "flex items-center gap-2 text-sm font-medium text-foreground", children: [
465
+ /* @__PURE__ */ jsx3(Loader2, { "aria-hidden": true, className: "size-4 animate-spin text-[var(--surface-info-text)]" }),
466
+ submitting.label
467
+ ] }),
468
+ /* @__PURE__ */ jsx3(Progress, { item: active }),
469
+ error?.id === active.id && /* @__PURE__ */ jsx3("p", { role: "alert", className: "text-sm text-[var(--surface-danger-text)]", children: error.message }),
470
+ active.phase === "blocked" && /* @__PURE__ */ jsx3("p", { className: "text-sm text-muted-foreground", children: "The workspace owner approves this request." }),
471
+ decidable && permissionsOpen && scopes.length > 0 && /* @__PURE__ */ jsxs3("fieldset", { className: "space-y-2 rounded-xl border border-border bg-muted/30 px-3 py-3", children: [
472
+ /* @__PURE__ */ jsx3("legend", { className: "sr-only", children: "Standing permission" }),
473
+ scopes.length > 1 && /* @__PURE__ */ jsx3(
474
+ RadioGroup,
475
+ {
476
+ "aria-label": "What the permission covers",
477
+ value: chosenScope ?? void 0,
478
+ onValueChange: setScope,
479
+ className: "gap-1.5",
480
+ children: scopes.map((option) => /* @__PURE__ */ jsxs3("div", { className: "flex min-h-8 items-center gap-2", children: [
481
+ /* @__PURE__ */ jsx3(RadioGroupItem, { id: `hub-scope-${active.id}-${option.id}`, value: option.id }),
482
+ /* @__PURE__ */ jsx3(Label, { htmlFor: `hub-scope-${active.id}-${option.id}`, className: "cursor-pointer text-sm font-normal text-foreground", children: option.label })
483
+ ] }, option.id))
484
+ }
485
+ ),
486
+ scopes.length === 1 && /* @__PURE__ */ jsx3("p", { className: "text-sm text-foreground", children: scopes[0]?.label }),
487
+ /* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap gap-2", children: [
488
+ /* @__PURE__ */ jsx3(Button2, { variant: "outline", onClick: () => chosenScope && void decide({ kind: "allow", duration: "24h", scope: chosenScope }, "Approving and allowing for 24 hours\u2026"), children: "Approve and allow for 24 hours" }),
489
+ /* @__PURE__ */ jsx3(Button2, { variant: "outline", onClick: () => chosenScope && void decide({ kind: "allow", duration: "always", scope: chosenScope }, "Approving and allowing from now on\u2026"), children: "Approve and always allow" })
490
+ ] })
491
+ ] }),
492
+ /* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap items-center gap-2", children: [
493
+ decidable && /* @__PURE__ */ jsxs3(Fragment, { children: [
494
+ /* @__PURE__ */ jsx3(Button2, { onClick: () => void decide({ kind: "approve" }, "Approving\u2026"), children: "Approve" }),
495
+ /* @__PURE__ */ jsx3(Button2, { variant: "outline", onClick: () => void decide({ kind: "deny" }, "Denying\u2026"), children: "Deny" }),
496
+ scopes.length > 0 && /* @__PURE__ */ jsx3(Button2, { variant: "ghost", "aria-expanded": permissionsOpen, onClick: () => setPermissionsOpen((value) => !value), children: permissionsOpen ? "Fewer options" : "Allow future calls\u2026" })
497
+ ] }),
498
+ active.phase === "failed" && /* @__PURE__ */ jsxs3(Button2, { variant: "outline", onClick: () => setDismissed((current) => /* @__PURE__ */ new Set([...current, active.id])), children: [
499
+ /* @__PURE__ */ jsx3(X, { "aria-hidden": true }),
500
+ " Dismiss"
501
+ ] }),
502
+ /* @__PURE__ */ jsx3("span", { className: "flex-1" }),
503
+ decidable && choices && "never" in choices && /* @__PURE__ */ jsx3("span", { className: "text-sm text-muted-foreground", children: choices.never }),
504
+ onOpen && /* @__PURE__ */ jsx3(Button2, { variant: "ghost", onClick: () => onOpen(active), children: "View in chat" })
505
+ ] }),
506
+ waitingCount > 0 && queue.length > 1 && active.phase !== "waiting" && /* @__PURE__ */ jsx3("p", { className: "text-sm text-muted-foreground", children: waitingCount === 1 ? "1 more request is waiting." : `${waitingCount} more requests are waiting.` })
507
+ ] })
508
+ ]
509
+ }
510
+ );
511
+ }
512
+
513
+ // src/hub-approvals-react/list.tsx
514
+ import { useEffect as useEffect2, useState as useState3 } from "react";
515
+ import { ChevronRight as ChevronRight3, ShieldCheck } from "lucide-react";
516
+ import { Button as Button3 } from "@tangle-network/ui/primitives";
517
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
518
+ var GROUPS = [
519
+ { id: "waiting", label: "Waiting", phases: ["waiting", "blocked"] },
520
+ { id: "running", label: "Running", phases: ["queued", "running"] },
521
+ { id: "failed", label: "Failed", phases: ["failed"] },
522
+ { id: "done", label: "Done", phases: ["done"] },
523
+ { id: "closed", label: "Denied or expired", phases: ["denied", "expired"] }
524
+ ];
525
+ function HubApprovalsList({ items, onSelect, selectedId, className = "" }) {
526
+ const [now, setNow] = useState3(() => Date.now());
527
+ useEffect2(() => {
528
+ const timer = setInterval(() => setNow(Date.now()), 3e4);
529
+ return () => clearInterval(timer);
530
+ }, []);
531
+ const waiting = items.filter((item) => item.phase === "waiting" || item.phase === "blocked").length;
532
+ const groups = GROUPS.map((group) => ({ ...group, items: items.filter((item) => group.phases.includes(item.phase)).slice().reverse() })).filter((group) => group.items.length > 0);
533
+ return /* @__PURE__ */ jsxs4("div", { className: `flex h-full min-h-0 flex-col ${className}`, children: [
534
+ /* @__PURE__ */ jsxs4("div", { className: "shrink-0 border-b border-border px-4 py-3", children: [
535
+ /* @__PURE__ */ jsx4("h2", { className: "text-base font-semibold text-foreground", children: "Approvals" }),
536
+ /* @__PURE__ */ jsx4("p", { className: "text-sm text-muted-foreground", "aria-live": "polite", children: waiting === 0 ? "Nothing is waiting for you" : waiting === 1 ? "1 request is waiting" : `${waiting} requests are waiting` })
537
+ ] }),
538
+ groups.length === 0 ? /* @__PURE__ */ jsxs4("div", { className: "flex flex-1 flex-col items-center justify-center gap-2 px-6 py-10 text-center", children: [
539
+ /* @__PURE__ */ jsx4("span", { className: "flex size-10 items-center justify-center rounded-xl bg-muted", children: /* @__PURE__ */ jsx4(ShieldCheck, { "aria-hidden": true, className: "size-5 text-muted-foreground" }) }),
540
+ /* @__PURE__ */ jsx4("p", { className: "text-sm font-medium text-foreground", children: "No approvals in this conversation" }),
541
+ /* @__PURE__ */ jsx4("p", { className: "text-sm text-muted-foreground", children: "Requests to act on your connected accounts appear here." })
542
+ ] }) : /* @__PURE__ */ jsx4("div", { className: "min-h-0 flex-1 space-y-5 overflow-y-auto px-2 py-3", children: groups.map((group) => /* @__PURE__ */ jsxs4("section", { "aria-label": group.label, children: [
543
+ /* @__PURE__ */ jsxs4("h3", { className: "px-2 pb-1 text-sm font-medium text-muted-foreground", children: [
544
+ group.label,
545
+ " ",
546
+ /* @__PURE__ */ jsxs4("span", { className: "tabular-nums", children: [
547
+ "\xB7 ",
548
+ group.items.length
549
+ ] })
550
+ ] }),
551
+ /* @__PURE__ */ jsx4("ul", { className: "space-y-1", children: group.items.map((item) => {
552
+ const presentation = presentHubAction(item);
553
+ const title = item.phase === "done" ? hubActionReceipt(item).title : presentation.title;
554
+ const when = item.phase === "waiting" ? closesIn(item.expiresAt, now) ?? relativeTime(item.requestedAt, now) : relativeTime(item.requestedAt, now);
555
+ const detail = [presentation.provider.name, item.account, when].filter(Boolean).join(" \xB7 ");
556
+ const selected = selectedId === item.id;
557
+ return /* @__PURE__ */ jsx4("li", { children: /* @__PURE__ */ jsxs4(
558
+ Button3,
559
+ {
560
+ variant: "bare",
561
+ onClick: () => onSelect?.(item),
562
+ "aria-current": selected ? "true" : void 0,
563
+ className: `flex w-full items-start gap-3 rounded-lg px-2 py-2.5 text-left transition-colors hover:bg-muted ${selected ? "bg-muted" : ""}`,
564
+ children: [
565
+ /* @__PURE__ */ jsx4(HubProviderMark, { providerId: presentation.provider.id, name: presentation.provider.name, size: 28 }),
566
+ /* @__PURE__ */ jsxs4("span", { className: "min-w-0 flex-1", children: [
567
+ /* @__PURE__ */ jsx4("span", { className: "line-clamp-2 text-sm font-medium leading-5 text-foreground", children: title }),
568
+ /* @__PURE__ */ jsx4("span", { className: "mt-0.5 block truncate text-sm text-muted-foreground", children: detail })
569
+ ] }),
570
+ /* @__PURE__ */ jsxs4("span", { className: "flex shrink-0 items-center gap-1", children: [
571
+ /* @__PURE__ */ jsx4(HubApprovalPhasePill, { phase: item.phase, label: item.phase === "waiting" ? "Waiting" : item.phase === "blocked" ? "Owner" : void 0 }),
572
+ /* @__PURE__ */ jsx4(ChevronRight3, { "aria-hidden": true, className: "size-4 text-muted-foreground" })
573
+ ] })
574
+ ]
575
+ }
576
+ ) }, item.id);
577
+ }) })
578
+ ] }, group.id)) })
579
+ ] });
580
+ }
581
+
582
+ // src/hub-approvals-react/row.tsx
583
+ import { useEffect as useEffect3, useRef as useRef2, useState as useState5 } from "react";
584
+ import { ChevronDown as ChevronDown2 } from "lucide-react";
585
+ import { Button as Button4 } from "@tangle-network/ui/primitives";
586
+
587
+ // src/hub-approvals-react/receipt.tsx
588
+ import { useState as useState4 } from "react";
589
+ import { ExternalLink as ExternalLink2 } from "lucide-react";
590
+ import { ApprovalDiffSummary as ApprovalDiffSummary2 } from "@tangle-network/ui/run";
591
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
592
+ function AudioPlayer({ src }) {
593
+ const [failed, setFailed] = useState4(false);
594
+ if (failed) return /* @__PURE__ */ jsx5("p", { className: "text-sm text-muted-foreground", children: "The audio link has expired. Ask the agent for a new one." });
595
+ return /* @__PURE__ */ jsx5("audio", { controls: true, preload: "metadata", src, onError: () => setFailed(true), className: "h-10 w-full" });
596
+ }
597
+ function HubActionReceiptCard({ item, className = "" }) {
598
+ const receipt = hubActionReceipt(item);
599
+ const presentation = presentHubAction(item);
600
+ const subtitle = [receipt.provider.name, item.account ? `as ${item.account}` : null, presentation.target && !receipt.title.includes(presentation.target) ? presentation.target : null].filter(Boolean).join(" \xB7 ");
601
+ const phase = item.phase;
602
+ return /* @__PURE__ */ jsxs5("article", { "aria-label": receipt.title, className: `rounded-xl border border-border bg-card px-4 py-3 shadow-sm ${className}`, children: [
603
+ /* @__PURE__ */ jsxs5("div", { className: "flex items-start gap-3", children: [
604
+ /* @__PURE__ */ jsx5(HubProviderMark, { providerId: receipt.provider.id, name: receipt.provider.name }),
605
+ /* @__PURE__ */ jsxs5("div", { className: "min-w-0 flex-1", children: [
606
+ /* @__PURE__ */ jsx5("p", { className: "text-base font-semibold leading-6 text-foreground", children: receipt.href ? /* @__PURE__ */ jsxs5("a", { href: receipt.href, target: "_blank", rel: "noreferrer", className: "inline-flex max-w-full items-center gap-1.5 hover:underline", children: [
607
+ /* @__PURE__ */ jsx5("span", { className: "truncate", children: receipt.title }),
608
+ /* @__PURE__ */ jsx5(ExternalLink2, { "aria-hidden": true, className: "size-4 shrink-0 text-muted-foreground" })
609
+ ] }) : /* @__PURE__ */ jsx5("span", { className: "break-words", children: receipt.title }) }),
610
+ subtitle && /* @__PURE__ */ jsx5("p", { className: "truncate text-sm text-muted-foreground", children: subtitle })
611
+ ] }),
612
+ /* @__PURE__ */ jsx5(HubApprovalPhasePill, { phase })
613
+ ] }),
614
+ (receipt.fields.length > 0 || receipt.media || receipt.files || receipt.error) && /* @__PURE__ */ jsxs5("div", { className: "mt-3 space-y-3", children: [
615
+ /* @__PURE__ */ jsx5(HubFieldList, { fields: receipt.fields }),
616
+ receipt.media && /* @__PURE__ */ jsx5(AudioPlayer, { src: receipt.media.src }),
617
+ receipt.files && /* @__PURE__ */ jsx5(ApprovalDiffSummary2, { files: receipt.files }),
618
+ receipt.error && /* @__PURE__ */ jsx5("p", { className: "break-words rounded-lg border border-[var(--surface-danger-border)] bg-[var(--surface-danger-bg)] px-3 py-2 text-sm text-[var(--surface-danger-text)]", children: receipt.error })
619
+ ] }),
620
+ (item.grant || item.autoApproved) && /* @__PURE__ */ jsx5("p", { className: "mt-3 text-sm text-muted-foreground", children: item.autoApproved ?? `Allowed ${item.grant?.expiresAt ? "for 24 hours" : "from now on"}: ${item.grant?.scope}` }),
621
+ /* @__PURE__ */ jsx5("div", { className: "mt-2", children: /* @__PURE__ */ jsx5(HubRawDetails, { sections: [
622
+ { label: "Call", value: { action: item.actionPath, input: item.input } },
623
+ { label: "Result", value: item.result }
624
+ ] }) })
625
+ ] });
626
+ }
627
+ function HubApprovalReceipts({ items, message, at }) {
628
+ const decided = items.filter((item) => item.phase !== "waiting" && item.phase !== "blocked");
629
+ const count = (phases) => decided.filter((item) => phases.includes(item.phase)).length;
630
+ const actions = (n) => n === 1 ? "1 action" : `${n} actions`;
631
+ const approved = count(["queued", "running", "done", "failed"]);
632
+ const denied = count(["denied"]);
633
+ const expired = count(["expired"]);
634
+ const verbs = [approved ? `approved ${actions(approved)}` : null, denied ? `denied ${actions(denied)}` : null].filter(Boolean);
635
+ const summary = verbs.length ? `You ${verbs.join(" and ")}${expired ? `; ${actions(expired)} expired` : ""}` : expired ? `${actions(expired)} expired` : "Your decisions";
636
+ const when = at ? new Date(at) : null;
637
+ return /* @__PURE__ */ jsxs5("section", { "aria-label": "Approval results", className: "space-y-2", children: [
638
+ /* @__PURE__ */ jsxs5("p", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: [
639
+ /* @__PURE__ */ jsx5("span", { children: summary }),
640
+ when && !Number.isNaN(when.getTime()) && /* @__PURE__ */ jsxs5("time", { dateTime: when.toISOString(), children: [
641
+ "\xB7 ",
642
+ when.toLocaleTimeString(void 0, { hour: "numeric", minute: "2-digit" })
643
+ ] })
644
+ ] }),
645
+ decided.map((item) => /* @__PURE__ */ jsx5(HubActionReceiptCard, { item }, item.id)),
646
+ message && /* @__PURE__ */ jsx5(HubRawDetails, { sections: [{ label: "Message sent to the agent", value: message }] })
647
+ ] });
648
+ }
649
+
650
+ // src/hub-approvals-react/row.tsx
651
+ import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
652
+ function HubApprovalRow({ item, expanded: controlled, onExpandedChange, onReview, actions }) {
653
+ const [own, setOwn] = useState5(false);
654
+ const expanded = controlled ?? own;
655
+ const ref = useRef2(null);
656
+ const presentation = presentHubAction(item);
657
+ const title = item.phase === "done" ? hubActionReceipt(item).title : presentation.title;
658
+ useEffect3(() => {
659
+ if (controlled) ref.current?.scrollIntoView({ block: "center", behavior: "smooth" });
660
+ }, [controlled]);
661
+ const toggle = () => {
662
+ setOwn(!expanded);
663
+ onExpandedChange?.(!expanded);
664
+ };
665
+ return /* @__PURE__ */ jsxs6("div", { ref, "data-hub-approval-row": item.id, className: `rounded-xl border bg-card ${expanded ? "border-border shadow-sm" : "border-border/80"}`, children: [
666
+ /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-3 px-3 py-2", children: [
667
+ /* @__PURE__ */ jsxs6(
668
+ Button4,
669
+ {
670
+ variant: "bare",
671
+ "aria-expanded": expanded,
672
+ onClick: toggle,
673
+ className: "flex min-h-9 min-w-0 flex-1 items-center gap-3 rounded-md text-left",
674
+ children: [
675
+ /* @__PURE__ */ jsx6(HubProviderMark, { providerId: presentation.provider.id, name: presentation.provider.name, size: 24 }),
676
+ /* @__PURE__ */ jsx6("span", { className: "min-w-0 flex-1 truncate text-sm font-medium text-foreground", children: title }),
677
+ /* @__PURE__ */ jsx6(HubApprovalPhasePill, { phase: item.phase }),
678
+ /* @__PURE__ */ jsx6(ChevronDown2, { "aria-hidden": true, className: `size-4 shrink-0 text-muted-foreground transition-transform ${expanded ? "rotate-180" : ""}` })
679
+ ]
680
+ }
681
+ ),
682
+ item.phase === "waiting" && onReview && /* @__PURE__ */ jsx6(Button4, { variant: "outline", onClick: () => onReview(item), children: "Review" })
683
+ ] }),
684
+ expanded && /* @__PURE__ */ jsxs6("div", { className: "space-y-3 border-t border-border px-3 pb-3 pt-3", children: [
685
+ item.phase === "done" || item.phase === "failed" ? /* @__PURE__ */ jsx6(HubActionReceiptCard, { item, className: "border-0 px-0 py-0 shadow-none" }) : /* @__PURE__ */ jsxs6(Fragment2, { children: [
686
+ /* @__PURE__ */ jsx6(HubActionPreviewView, { preview: presentation.preview, account: item.account }),
687
+ /* @__PURE__ */ jsx6(HubRawDetails, { sections: [{ label: "Call", value: { action: item.actionPath, input: item.input } }] })
688
+ ] }),
689
+ actions
690
+ ] }),
691
+ !expanded && actions && (item.phase === "expired" || item.phase === "failed") && /* @__PURE__ */ jsx6("div", { className: "border-t border-border px-3 py-2", children: actions })
692
+ ] });
693
+ }
694
+ export {
695
+ HubActionPreviewView,
696
+ HubActionReceiptCard,
697
+ HubApprovalDock,
698
+ HubApprovalPhasePill,
699
+ HubApprovalReceipts,
700
+ HubApprovalRow,
701
+ HubApprovalsList,
702
+ HubProviderMark
703
+ };
704
+ //# sourceMappingURL=index.js.map