@nivaro/react 0.2.56 → 0.3.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.
Files changed (80) hide show
  1. package/dist/components/slots/TasksSlot.js +31 -29
  2. package/dist/full.css +1 -1
  3. package/dist/hooks/useSessionRecorder.js +1 -1
  4. package/dist/index.d.ts +414 -1
  5. package/dist/index.js +767 -716
  6. package/dist/shared/components/ClientChaosToolbar.js +410 -0
  7. package/dist/shared/components/ItemEditForm.js +666 -658
  8. package/dist/shared/components/LoadErrorNote.js +49 -0
  9. package/dist/shared/components/MyWorkView.js +47 -37
  10. package/dist/shared/components/PretendDown.js +258 -0
  11. package/dist/shared/components/ProfileView.js +208 -184
  12. package/dist/shared/components/QueryErrorState.js +16 -0
  13. package/dist/shared/components/ReportView.js +1351 -1338
  14. package/dist/shared/components/WidgetSlot.js +438 -418
  15. package/dist/shared/components/ai/AiPlanCard.js +427 -0
  16. package/dist/shared/components/ai/AiPlanChanges.js +117 -0
  17. package/dist/shared/components/ai/TaskDo.js +1022 -0
  18. package/dist/shared/components/chaos/DeclareIncidentButton.js +72 -0
  19. package/dist/shared/components/chaos/DrillBanner.js +119 -0
  20. package/dist/shared/components/chaos/DrillTag.js +62 -0
  21. package/dist/shared/components/chaos/GameDayStrip.js +61 -0
  22. package/dist/shared/components/chat/ChatAnalyticsView.js +19 -17
  23. package/dist/shared/components/chat/ChatPanel.js +1356 -1317
  24. package/dist/shared/components/chat/HuddleAnalyticsTab.js +198 -0
  25. package/dist/shared/components/chat/RoomHeaderMenu.js +78 -65
  26. package/dist/shared/components/chat/chat-core.js +273 -264
  27. package/dist/shared/components/chat/huddle/HuddleAudioUi.js +397 -0
  28. package/dist/shared/components/chat/huddle/HuddleCallBar.js +296 -0
  29. package/dist/shared/components/chat/huddle/HuddleCallLayer.js +180 -0
  30. package/dist/shared/components/chat/huddle/HuddleCamera.js +124 -0
  31. package/dist/shared/components/chat/huddle/HuddleCollab.js +320 -0
  32. package/dist/shared/components/chat/huddle/HuddleControls.js +82 -121
  33. package/dist/shared/components/chat/huddle/HuddleDraw.js +231 -0
  34. package/dist/shared/components/chat/huddle/HuddleLiveBadge.js +52 -0
  35. package/dist/shared/components/chat/huddle/HuddlePeoplePicker.js +143 -0
  36. package/dist/shared/components/chat/huddle/HuddleScheduleCard.js +190 -0
  37. package/dist/shared/components/chat/huddle/HuddleScheduleForm.js +188 -0
  38. package/dist/shared/components/chat/huddle/HuddleStage.js +184 -89
  39. package/dist/shared/components/chat/huddle/HuddleStageTools.js +197 -0
  40. package/dist/shared/components/chat/huddle/huddle-audio-logic.js +156 -0
  41. package/dist/shared/components/chat/huddle/huddle-audio.js +69 -0
  42. package/dist/shared/components/chat/huddle/huddle-calls.js +129 -0
  43. package/dist/shared/components/chat/huddle/huddle-camera.js +143 -0
  44. package/dist/shared/components/chat/huddle/huddle-collab-store.js +391 -0
  45. package/dist/shared/components/chat/huddle/huddle-device-prefs.js +55 -0
  46. package/dist/shared/components/chat/huddle/huddle-devices.js +99 -0
  47. package/dist/shared/components/chat/huddle/huddle-draw.js +226 -0
  48. package/dist/shared/components/chat/huddle/huddle-follow-bus.js +96 -0
  49. package/dist/shared/components/chat/huddle/huddle-hold.js +62 -0
  50. package/dist/shared/components/chat/huddle/huddle-link-quality.js +159 -0
  51. package/dist/shared/components/chat/huddle/huddle-live.js +82 -0
  52. package/dist/shared/components/chat/huddle/huddle-pip.js +343 -0
  53. package/dist/shared/components/chat/huddle/huddle-quality.js +22 -0
  54. package/dist/shared/components/chat/huddle/huddle-reactions.js +71 -0
  55. package/dist/shared/components/chat/huddle/huddle-ring-refused.js +34 -0
  56. package/dist/shared/components/chat/huddle/huddle-schedule.js +102 -0
  57. package/dist/shared/components/chat/huddle/huddle-sfu.js +176 -0
  58. package/dist/shared/components/chat/huddle/huddle-shortcuts.js +91 -0
  59. package/dist/shared/components/chat/huddle/huddle-speaking.js +100 -0
  60. package/dist/shared/components/chat/huddle/huddle-store.js +431 -157
  61. package/dist/shared/components/chat/huddle/useHuddle.js +46 -38
  62. package/dist/shared/components/chat/huddle/useHuddleAudio.js +35 -0
  63. package/dist/shared/components/client-chaos-gate.js +51 -0
  64. package/dist/shared/components/integrations/console/SignalCard.js +172 -167
  65. package/dist/shared/components/item-edit/GroupSection.js +1 -0
  66. package/dist/shared/components/item-edit/RecordChatActions.js +68 -59
  67. package/dist/shared/components/item-edit/UserChip.js +145 -142
  68. package/dist/shared/components/layout-editor/EditorTopBar.js +108 -105
  69. package/dist/shared/components/layout-editor/LayoutEditor.js +514 -508
  70. package/dist/shared/components/notifications/NotificationAnalyticsView.js +18 -10
  71. package/dist/shared/components/panels/TaskPanel.js +51 -49
  72. package/dist/shared/components/pipeline/PipelineEditorView.js +495 -479
  73. package/dist/shared/components/pipeline/TeamsView.js +184 -169
  74. package/dist/shared/components/support/TicketDetailSheet.js +57 -42
  75. package/dist/shared/lib/client-chaos.js +359 -0
  76. package/dist/shared/lib/load-error.js +26 -0
  77. package/dist/shared/lib/notification-sound.js +25 -16
  78. package/dist/shared/lib/socket-realtime.js +31 -30
  79. package/dist/shared/lib/worker-socket.js +108 -89
  80. package/package.json +2 -1
@@ -0,0 +1,427 @@
1
+ import { jsxs as r, jsx as a, Fragment as C } from "react/jsx-runtime";
2
+ import { ListChecks as G, Filter as K, Loader2 as N, Clock as I, RotateCcw as Q, Check as V, X as Z, SkipForward as ee, Ban as te, CircleDashed as ae } from "lucide-react";
3
+ import { useState as k, useRef as E, useEffect as _, useCallback as re } from "react";
4
+ import { useOptionalNivaroClient as ne } from "../../context.js";
5
+ import { get as se, post as de } from "../../lib/commands.js";
6
+ import { cn as d } from "../../lib/utils.js";
7
+ import { Button as u } from "../ui/button.js";
8
+ import { AiPlanChanges as le } from "./AiPlanChanges.js";
9
+ const ie = 3e3;
10
+ function ce(n) {
11
+ return (n == null ? void 0 : n.message) || "The request failed";
12
+ }
13
+ function oe({ status: n }) {
14
+ const l = "h-3.5 w-3.5 shrink-0";
15
+ return n === "running" ? /* @__PURE__ */ a(N, { className: d(l, "animate-spin text-nvr-cyan") }) : n === "done" ? /* @__PURE__ */ a(V, { className: d(l, "text-emerald-600 dark:text-emerald-400") }) : n === "failed" ? /* @__PURE__ */ a(Z, { className: d(l, "text-rose-600 dark:text-rose-400") }) : n === "skipped" ? /* @__PURE__ */ a(ee, { className: d(l, "text-amber-600 dark:text-amber-400") }) : n === "cancelled" ? /* @__PURE__ */ a(te, { className: d(l, "text-muted-foreground") }) : /* @__PURE__ */ a(ae, { className: d(l, "text-muted-foreground") });
16
+ }
17
+ function pe(n) {
18
+ const l = new Date(n);
19
+ return Number.isNaN(l.getTime()) ? n : l.toLocaleString(void 0, {
20
+ weekday: "short",
21
+ month: "short",
22
+ day: "numeric",
23
+ hour: "numeric",
24
+ minute: "2-digit"
25
+ });
26
+ }
27
+ function me() {
28
+ const n = new Date(Date.now() + 36e5);
29
+ n.setMinutes(Math.ceil(n.getMinutes() / 15) * 15, 0, 0);
30
+ const l = (S) => String(S).padStart(2, "0");
31
+ return `${n.getFullYear()}-${l(n.getMonth() + 1)}-${l(n.getDate())}T${l(n.getHours())}:${l(n.getMinutes())}`;
32
+ }
33
+ function ue(n) {
34
+ return n == null || n === "" ? "—" : typeof n == "object" ? JSON.stringify(n) : String(n);
35
+ }
36
+ const he = {
37
+ amber: {
38
+ box: "rounded-lg border border-amber-200 bg-amber-50/60 p-3 dark:border-amber-800 dark:bg-amber-900/10",
39
+ icon: "text-amber-700 dark:text-amber-300",
40
+ title: "text-amber-900 dark:text-amber-200",
41
+ impact: "text-amber-900/90 dark:text-amber-200/90",
42
+ progress: "text-amber-800/80 dark:text-amber-300/80",
43
+ step: "border-amber-200/70 bg-white/70 dark:border-amber-800/60 dark:bg-card",
44
+ status: "text-amber-800 dark:text-amber-300",
45
+ link: "text-amber-800 dark:text-amber-300",
46
+ stepTitle: "truncate"
47
+ },
48
+ quiet: {
49
+ box: "",
50
+ icon: "text-slate-400",
51
+ title: "text-foreground",
52
+ impact: "text-muted-foreground",
53
+ progress: "text-muted-foreground",
54
+ step: "border-slate-200 bg-white dark:border-border dark:bg-card",
55
+ status: "text-muted-foreground",
56
+ link: "text-nvr-navy dark:text-nvr-cyan",
57
+ stepTitle: "break-words"
58
+ }
59
+ };
60
+ function ye({
61
+ plan: n,
62
+ subscribe: l,
63
+ className: S,
64
+ beforeSteps: J,
65
+ stepExtra: $,
66
+ extraActions: R,
67
+ runDisabled: D,
68
+ onPlan: O,
69
+ quiet: M,
70
+ stepChanges: T
71
+ }) {
72
+ var B;
73
+ const c = he[M ? "quiet" : "amber"], o = ne(), [t, j] = k(n), [i, q] = k(null), [F, P] = k(null), [b, w] = k(null), [U, W] = k(!1), x = n.plan_id, v = E(0), y = E(O);
74
+ y.current = O, _(() => {
75
+ var e;
76
+ (e = y.current) == null || e.call(y, t);
77
+ }, [t]);
78
+ const f = re(async () => {
79
+ if (!o) return;
80
+ const e = Date.now();
81
+ v.current = e;
82
+ try {
83
+ const s = await o.request(se(`/ai/plans/${encodeURIComponent(x)}`));
84
+ v.current === e && (s != null && s.data) && j(s.data);
85
+ } catch {
86
+ }
87
+ }, [o, x]);
88
+ _(() => {
89
+ f();
90
+ }, [f]), _(() => {
91
+ if (l)
92
+ return l("ai:plan", (e) => {
93
+ if (String(e.plan_id ?? "").toUpperCase() !== x.toUpperCase()) return;
94
+ const s = e.plan;
95
+ s != null && s.steps && (v.current = Date.now(), j(s));
96
+ });
97
+ }, [l, x]), _(() => {
98
+ if (t.status !== "running") return;
99
+ const e = setInterval(() => void f(), ie);
100
+ return () => clearInterval(e);
101
+ }, [t.status, f]);
102
+ const h = async (e, s) => {
103
+ if (!(!o || i)) {
104
+ q(e), P(null);
105
+ try {
106
+ const p = await o.request(
107
+ de(`/ai/plans/${encodeURIComponent(x)}/${e}`, s)
108
+ );
109
+ p != null && p.data && (v.current = Date.now(), j(p.data), e === "schedule" && w(null));
110
+ } catch (p) {
111
+ P(ce(p)), f();
112
+ } finally {
113
+ q(null);
114
+ }
115
+ }
116
+ }, z = t.steps.filter((e) => e.state.status === "done").length, g = t.steps.filter((e) => e.state.status === "skipped").length, L = t.status === "proposed" || t.status === "paused", X = t.steps.filter((e) => e.state.status === "pending").length;
117
+ return /* @__PURE__ */ r("div", { className: d("mt-2", c.box, S), "data-ai-plan": t.status, children: [
118
+ /* @__PURE__ */ r("div", { className: "flex items-start gap-2", children: [
119
+ /* @__PURE__ */ a(G, { className: d("mt-0.5 h-4 w-4 shrink-0", c.icon) }),
120
+ /* @__PURE__ */ r("div", { className: "min-w-0 flex-1", children: [
121
+ /* @__PURE__ */ r("p", { className: d("text-[12.5px] font-semibold", c.title), children: [
122
+ t.status === "proposed" ? "Proposed plan: " : "Plan: ",
123
+ t.title
124
+ ] }),
125
+ ((B = t.impact) == null ? void 0 : B.summary) && /* @__PURE__ */ a("p", { className: d("text-[11.5px]", c.impact), "data-ai-plan-impact": !0, children: t.impact.summary }),
126
+ /* @__PURE__ */ r("p", { className: d("text-[11px]", c.progress), "data-ai-plan-progress": !0, children: [
127
+ t.steps.length,
128
+ " step",
129
+ t.steps.length === 1 ? "" : "s",
130
+ z + g > 0 ? ` · ${z} done` : "",
131
+ g > 0 ? ` · ${g} skipped` : "",
132
+ t.records_changed > 0 ? ` · ${t.records_changed} record${t.records_changed === 1 ? "" : "s"} changed` : ""
133
+ ] })
134
+ ] })
135
+ ] }),
136
+ t.held && (t.status === "proposed" || t.status === "paused") && /* @__PURE__ */ r(
137
+ "p",
138
+ {
139
+ className: "mt-2 rounded-md border border-amber-300 bg-white/70 px-2.5 py-1.5 text-[11.5px] text-amber-900 dark:border-amber-700 dark:bg-card dark:text-amber-200",
140
+ "data-ai-plan-held": !0,
141
+ children: [
142
+ "Did not run at its scheduled time — ",
143
+ t.held.reason,
144
+ ". The steps below are re-checked; approve again to run."
145
+ ]
146
+ }
147
+ ),
148
+ J,
149
+ /* @__PURE__ */ a("ol", { className: "mt-2 space-y-1.5", children: t.steps.map((e) => {
150
+ var A;
151
+ const s = e.preview ?? {}, p = s.changes && typeof s.changes == "object" ? s.changes : null, H = T == null ? void 0 : T(e);
152
+ return /* @__PURE__ */ r(
153
+ "li",
154
+ {
155
+ className: d("rounded-md border px-2.5 py-1.5", c.step),
156
+ "data-ai-plan-step": e.state.status,
157
+ children: [
158
+ /* @__PURE__ */ r("div", { className: "flex items-center gap-1.5", children: [
159
+ /* @__PURE__ */ a(oe, { status: e.state.status }),
160
+ /* @__PURE__ */ r("span", { className: "text-[11px] font-medium tabular-nums text-muted-foreground", children: [
161
+ e.n,
162
+ "."
163
+ ] }),
164
+ /* @__PURE__ */ a(
165
+ "span",
166
+ {
167
+ className: d("min-w-0 flex-1 text-[12.5px] text-foreground", c.stepTitle),
168
+ children: e.title
169
+ }
170
+ ),
171
+ /* @__PURE__ */ a("span", { className: "shrink-0 rounded bg-muted px-1.5 py-px text-[10px] text-muted-foreground", children: e.kind_label })
172
+ ] }),
173
+ e.condition && /* @__PURE__ */ r("p", { className: "mt-0.5 flex items-center gap-1 pl-5 text-[11px] text-muted-foreground", children: [
174
+ /* @__PURE__ */ a(K, { className: "h-3 w-3" }),
175
+ " ",
176
+ e.condition
177
+ ] }),
178
+ e.preview_changed && /* @__PURE__ */ a("p", { className: "mt-0.5 pl-5 text-[11px] font-medium text-amber-700 dark:text-amber-300", children: "Re-checked — this step changed since it was proposed." }),
179
+ H,
180
+ H === void 0 && p && Object.keys(p).length > 0 && /* @__PURE__ */ a("div", { className: "mt-0.5 space-y-px pl-5", children: Object.entries(p).slice(0, 6).map(([m, Y]) => /* @__PURE__ */ r(
181
+ "p",
182
+ {
183
+ className: "truncate text-[11px] text-slate-700 dark:text-slate-300",
184
+ children: [
185
+ /* @__PURE__ */ a("span", { className: "text-muted-foreground", children: m }),
186
+ " → ",
187
+ ue(Y)
188
+ ]
189
+ },
190
+ m
191
+ )) }),
192
+ s.recipients && s.recipients.length > 0 && /* @__PURE__ */ r("p", { className: "mt-0.5 truncate pl-5 text-[11px] text-muted-foreground", children: [
193
+ "To ",
194
+ s.recipients.map((m) => m.name).join(", "),
195
+ (s.count ?? 0) > s.recipients.length ? ` +${(s.count ?? 0) - s.recipients.length} more` : ""
196
+ ] }),
197
+ s.sample && s.sample.length > 0 && e.kind !== "create_task" && /* @__PURE__ */ r("p", { className: "mt-0.5 truncate pl-5 text-[11px] text-muted-foreground", children: [
198
+ "e.g.",
199
+ " ",
200
+ s.sample.slice(0, 4).map((m) => m.label).join(" · "),
201
+ (s.count ?? 0) > 4 ? ` +${(s.count ?? 0) - 4} more` : ""
202
+ ] }),
203
+ e.state.status === "done" && e.state.records_changed > 0 && /* @__PURE__ */ r("p", { className: "mt-0.5 pl-5 text-[11px] text-emerald-700 dark:text-emerald-400", children: [
204
+ e.state.records_changed,
205
+ " record",
206
+ e.state.records_changed === 1 ? "" : "s",
207
+ " changed"
208
+ ] }),
209
+ e.state.status === "skipped" && e.state.skip_reason && /* @__PURE__ */ r("p", { className: "mt-0.5 pl-5 text-[11px] text-amber-700 dark:text-amber-300", children: [
210
+ "Skipped — ",
211
+ e.state.skip_reason
212
+ ] }),
213
+ e.state.status !== "skipped" && (((A = e.state.skipped_records) == null ? void 0 : A.length) ?? 0) > 0 && /* @__PURE__ */ r("p", { className: "mt-0.5 pl-5 text-[11px] text-amber-700 dark:text-amber-300", children: [
214
+ "Left out ",
215
+ e.state.skipped_records.length,
216
+ ":",
217
+ " ",
218
+ e.state.skipped_records.slice(0, 3).map((m) => `${m.label ?? m.id} (${m.reason})`).join("; ")
219
+ ] }),
220
+ e.state.status === "failed" && e.state.error && /* @__PURE__ */ a("p", { className: "mt-0.5 pl-5 text-[11px] text-rose-700 dark:text-rose-400", children: e.state.error }),
221
+ $ == null ? void 0 : $(e, t)
222
+ ]
223
+ },
224
+ e.id
225
+ );
226
+ }) }),
227
+ U && /* @__PURE__ */ a(le, { planId: x, title: t.title }),
228
+ F && /* @__PURE__ */ a("p", { className: "mt-2 text-[11.5px] text-rose-700 dark:text-rose-400", children: F }),
229
+ b != null && L && /* @__PURE__ */ r("div", { className: "mt-2 flex flex-wrap items-center gap-2", "data-ai-plan-later": !0, children: [
230
+ /* @__PURE__ */ a("span", { className: d("text-[11.5px]", c.title), children: "Run at" }),
231
+ /* @__PURE__ */ a(
232
+ "input",
233
+ {
234
+ type: "datetime-local",
235
+ value: b,
236
+ onChange: (e) => w(e.target.value),
237
+ "aria-label": "Run at",
238
+ className: d(
239
+ "h-7 rounded-md border bg-white px-2 text-[12px] text-foreground dark:bg-card",
240
+ M ? "border-slate-200 dark:border-border" : "border-amber-300 dark:border-amber-700"
241
+ )
242
+ }
243
+ ),
244
+ /* @__PURE__ */ r(
245
+ u,
246
+ {
247
+ size: "sm",
248
+ className: "h-7 bg-nvr-cyan text-white hover:bg-nvr-cyan/90",
249
+ disabled: !!i || !b,
250
+ onClick: () => h("schedule", { run_at: new Date(b).toISOString() }),
251
+ children: [
252
+ i === "schedule" ? /* @__PURE__ */ a(N, { className: "h-3 w-3 animate-spin" }) : null,
253
+ "Approve for then"
254
+ ]
255
+ }
256
+ ),
257
+ /* @__PURE__ */ a(u, { size: "sm", variant: "ghost", className: "h-7", onClick: () => w(null), children: "Cancel" }),
258
+ /* @__PURE__ */ a("span", { className: "w-full text-[11px] text-muted-foreground", children: "Each step is re-checked first; if the records changed, it waits for you to approve again." })
259
+ ] }),
260
+ /* @__PURE__ */ r("div", { className: "mt-2 flex flex-wrap items-center gap-2", children: [
261
+ L && o && D && /* @__PURE__ */ r(
262
+ "span",
263
+ {
264
+ className: d("flex items-center gap-1.5 text-[12px]", c.status),
265
+ "data-ai-plan-run-withheld": !0,
266
+ children: [
267
+ /* @__PURE__ */ a(I, { className: "h-3 w-3" }),
268
+ D
269
+ ]
270
+ }
271
+ ),
272
+ L && o && !D && /* @__PURE__ */ r(C, { children: [
273
+ /* @__PURE__ */ r(
274
+ u,
275
+ {
276
+ size: "sm",
277
+ className: "h-7 bg-nvr-cyan text-white hover:bg-nvr-cyan/90",
278
+ disabled: !!i,
279
+ onClick: () => h("run", { mode: "all" }),
280
+ "data-ai-plan-run": "all",
281
+ children: [
282
+ i === "run" ? /* @__PURE__ */ a(N, { className: "h-3 w-3 animate-spin" }) : null,
283
+ t.status === "paused" ? "Run the rest" : "Approve & run all"
284
+ ]
285
+ }
286
+ ),
287
+ X > 1 && /* @__PURE__ */ a(
288
+ u,
289
+ {
290
+ size: "sm",
291
+ variant: "outline",
292
+ className: "h-7",
293
+ disabled: !!i,
294
+ onClick: () => h("run", { mode: "next" }),
295
+ "data-ai-plan-run": "next",
296
+ children: "Run next step"
297
+ }
298
+ ),
299
+ b == null && /* @__PURE__ */ r(
300
+ u,
301
+ {
302
+ size: "sm",
303
+ variant: "outline",
304
+ className: "h-7",
305
+ disabled: !!i,
306
+ onClick: () => w(me()),
307
+ "data-ai-plan-run": "later",
308
+ children: [
309
+ /* @__PURE__ */ a(I, { className: "h-3 w-3" }),
310
+ "Run later…"
311
+ ]
312
+ }
313
+ ),
314
+ /* @__PURE__ */ a(
315
+ u,
316
+ {
317
+ size: "sm",
318
+ variant: "ghost",
319
+ className: "h-7",
320
+ disabled: !!i,
321
+ onClick: () => h("cancel"),
322
+ children: "Discard"
323
+ }
324
+ )
325
+ ] }),
326
+ t.status === "scheduled" && /* @__PURE__ */ r(C, { children: [
327
+ /* @__PURE__ */ r(
328
+ "span",
329
+ {
330
+ className: d("flex items-center gap-1.5 text-[12px]", c.status),
331
+ "data-ai-plan-scheduled": !0,
332
+ children: [
333
+ /* @__PURE__ */ a(I, { className: "h-3 w-3" }),
334
+ "Approved to run ",
335
+ t.schedule ? pe(t.schedule.run_at) : "later"
336
+ ]
337
+ }
338
+ ),
339
+ o && /* @__PURE__ */ a(
340
+ u,
341
+ {
342
+ size: "sm",
343
+ variant: "ghost",
344
+ className: "h-7",
345
+ disabled: !!i,
346
+ onClick: () => h("unschedule"),
347
+ children: "Cancel schedule"
348
+ }
349
+ )
350
+ ] }),
351
+ t.status === "running" && /* @__PURE__ */ r(C, { children: [
352
+ /* @__PURE__ */ r("span", { className: d("flex items-center gap-1.5 text-[12px]", c.status), children: [
353
+ /* @__PURE__ */ a(N, { className: "h-3 w-3 animate-spin" }),
354
+ " Running…"
355
+ ] }),
356
+ o && /* @__PURE__ */ a(
357
+ u,
358
+ {
359
+ size: "sm",
360
+ variant: "outline",
361
+ className: "h-7",
362
+ disabled: !!i,
363
+ onClick: () => h("cancel"),
364
+ "data-tip": "Stop before the next step",
365
+ children: "Stop"
366
+ }
367
+ )
368
+ ] }),
369
+ t.status === "failed" && o && /* @__PURE__ */ r(C, { children: [
370
+ /* @__PURE__ */ r(
371
+ u,
372
+ {
373
+ size: "sm",
374
+ variant: "outline",
375
+ className: "h-7",
376
+ disabled: !!i,
377
+ onClick: () => h("retry"),
378
+ "data-ai-plan-retry": !0,
379
+ "data-tip": "Re-check the failed and remaining steps, then run them again",
380
+ children: [
381
+ i === "retry" ? /* @__PURE__ */ a(N, { className: "h-3 w-3 animate-spin" }) : /* @__PURE__ */ a(Q, { className: "h-3 w-3" }),
382
+ "Re-check and retry"
383
+ ]
384
+ }
385
+ ),
386
+ /* @__PURE__ */ a(
387
+ u,
388
+ {
389
+ size: "sm",
390
+ variant: "ghost",
391
+ className: "h-7",
392
+ disabled: !!i,
393
+ onClick: () => h("cancel"),
394
+ children: "Discard the rest"
395
+ }
396
+ )
397
+ ] }),
398
+ t.status === "executed" && /* @__PURE__ */ r("span", { className: "text-[12px] font-medium text-emerald-700 dark:text-emerald-400", children: [
399
+ "Done — ",
400
+ t.records_changed,
401
+ " record",
402
+ t.records_changed === 1 ? "" : "s",
403
+ " changed",
404
+ g > 0 ? `, ${g} step${g === 1 ? "" : "s"} skipped` : ""
405
+ ] }),
406
+ t.status === "rejected" && /* @__PURE__ */ a("span", { className: "text-[12px] text-muted-foreground", children: z > 0 ? "Stopped — the remaining steps did not run." : "Discarded — nothing changed." }),
407
+ t.status === "expired" && /* @__PURE__ */ a("span", { className: "text-[12px] text-muted-foreground", children: "Expired — ask again." }),
408
+ R == null ? void 0 : R(t),
409
+ o && t.impact !== void 0 && /* @__PURE__ */ a(
410
+ "button",
411
+ {
412
+ type: "button",
413
+ className: d(
414
+ "ml-auto text-[11.5px] font-medium underline-offset-2 hover:underline",
415
+ c.link
416
+ ),
417
+ onClick: () => W((e) => !e),
418
+ "data-ai-plan-changes-toggle": !0,
419
+ children: U ? "Hide changes" : "What changes"
420
+ }
421
+ )
422
+ ] })
423
+ ] });
424
+ }
425
+ export {
426
+ ye as AiPlanCard
427
+ };
@@ -0,0 +1,117 @@
1
+ import { jsxs as l, jsx as t } from "react/jsx-runtime";
2
+ import { Loader2 as f, Download as L } from "lucide-react";
3
+ import { useState as s, useEffect as R } from "react";
4
+ import { useOptionalNivaroClient as S, useApiFetchConfig as v } from "../../context.js";
5
+ import { get as E } from "../../lib/commands.js";
6
+ import { cn as g } from "../../lib/utils.js";
7
+ const p = 100;
8
+ function b(o) {
9
+ return o == null || o === "" ? "—" : typeof o == "object" ? JSON.stringify(o) : String(o);
10
+ }
11
+ function F({
12
+ planId: o,
13
+ title: N,
14
+ className: y
15
+ }) {
16
+ const c = S(), i = v(), [a, w] = s(null), [$, k] = s(!1), [m, u] = s(null), [h, x] = s(!1);
17
+ R(() => {
18
+ if (!c) return;
19
+ let e = !0;
20
+ return c.request(
21
+ E(
22
+ `/ai/plans/${encodeURIComponent(o)}/changes`
23
+ )
24
+ ).then((n) => {
25
+ var d, r;
26
+ e && (w(((d = n == null ? void 0 : n.data) == null ? void 0 : d.rows) ?? []), k(!!((r = n == null ? void 0 : n.data) != null && r.truncated)));
27
+ }).catch((n) => e && u((n == null ? void 0 : n.message) || "Could not load the changes")), () => {
28
+ e = !1;
29
+ };
30
+ }, [c, o]);
31
+ const C = async () => {
32
+ x(!0);
33
+ try {
34
+ const e = await fetch(
35
+ `${i.apiBase}/ai/plans/${encodeURIComponent(o)}/changes.xlsx`,
36
+ { headers: i.authHeaders, credentials: i.credentials }
37
+ );
38
+ if (!e.ok) throw new Error(await e.text());
39
+ const n = await e.blob(), d = URL.createObjectURL(n), r = document.createElement("a");
40
+ r.href = d, r.download = `${N.replace(/[^A-Za-z0-9 _-]+/g, "").trim() || "plan"} - changes.xlsx`, r.click(), URL.revokeObjectURL(d);
41
+ } catch {
42
+ u("The download failed");
43
+ } finally {
44
+ x(!1);
45
+ }
46
+ };
47
+ return /* @__PURE__ */ l(
48
+ "div",
49
+ {
50
+ className: g(
51
+ "mt-2 rounded-md border border-amber-200/70 bg-white/70 dark:border-amber-800/60 dark:bg-card",
52
+ y
53
+ ),
54
+ "data-ai-plan-changes": !0,
55
+ children: [
56
+ /* @__PURE__ */ l("div", { className: "flex items-center gap-2 border-b border-amber-200/70 px-2.5 py-1.5 dark:border-amber-800/60", children: [
57
+ /* @__PURE__ */ t("span", { className: "text-[11.5px] font-medium text-foreground", children: a == null ? "Changes" : `${a.length.toLocaleString()} field change${a.length === 1 ? "" : "s"}${$ ? "+" : ""}` }),
58
+ /* @__PURE__ */ l(
59
+ "button",
60
+ {
61
+ type: "button",
62
+ disabled: h || !(a != null && a.length),
63
+ onClick: () => void C(),
64
+ className: "ml-auto flex items-center gap-1 text-[11.5px] text-muted-foreground hover:text-foreground disabled:opacity-40",
65
+ children: [
66
+ h ? /* @__PURE__ */ t(f, { className: "h-3 w-3 animate-spin" }) : /* @__PURE__ */ t(L, { className: "h-3 w-3" }),
67
+ "Excel"
68
+ ]
69
+ }
70
+ )
71
+ ] }),
72
+ m && /* @__PURE__ */ t("p", { className: "px-2.5 py-1.5 text-[11.5px] text-rose-700 dark:text-rose-400", children: m }),
73
+ a == null && !m && /* @__PURE__ */ l("p", { className: "flex items-center gap-1.5 px-2.5 py-1.5 text-[11.5px] text-muted-foreground", children: [
74
+ /* @__PURE__ */ t(f, { className: "h-3 w-3 animate-spin" }),
75
+ " Loading…"
76
+ ] }),
77
+ a != null && a.length === 0 && /* @__PURE__ */ t("p", { className: "px-2.5 py-1.5 text-[11.5px] text-muted-foreground", children: "No field changes — this plan only sends, posts or runs things." }),
78
+ a != null && a.length > 0 && /* @__PURE__ */ l("div", { className: "max-h-72 overflow-auto", children: [
79
+ /* @__PURE__ */ l("table", { className: "w-full text-[11.5px]", children: [
80
+ /* @__PURE__ */ t("thead", { className: "sticky top-0 bg-muted text-left text-muted-foreground", children: /* @__PURE__ */ l("tr", { children: [
81
+ /* @__PURE__ */ t("th", { className: "px-2 py-1 font-medium", children: "Step" }),
82
+ /* @__PURE__ */ t("th", { className: "px-2 py-1 font-medium", children: "Record" }),
83
+ /* @__PURE__ */ t("th", { className: "px-2 py-1 font-medium", children: "Field" }),
84
+ /* @__PURE__ */ t("th", { className: "px-2 py-1 font-medium", children: "Old" }),
85
+ /* @__PURE__ */ t("th", { className: "px-2 py-1 font-medium", children: "New" })
86
+ ] }) }),
87
+ /* @__PURE__ */ t("tbody", { children: a.slice(0, p).map((e) => /* @__PURE__ */ l(
88
+ "tr",
89
+ {
90
+ className: g(
91
+ "border-t border-border",
92
+ e.status === "undone" && "text-muted-foreground line-through"
93
+ ),
94
+ children: [
95
+ /* @__PURE__ */ t("td", { className: "px-2 py-1 tabular-nums text-muted-foreground", children: e.step }),
96
+ /* @__PURE__ */ t("td", { className: "max-w-[160px] truncate px-2 py-1", children: e.label }),
97
+ /* @__PURE__ */ t("td", { className: "px-2 py-1 font-mono text-[11px]", children: e.field }),
98
+ /* @__PURE__ */ t("td", { className: "max-w-[160px] truncate px-2 py-1 text-muted-foreground", children: b(e.from) }),
99
+ /* @__PURE__ */ t("td", { className: "max-w-[160px] truncate px-2 py-1", children: b(e.to) })
100
+ ]
101
+ },
102
+ `${e.step}-${e.collection}-${e.id ?? "new"}-${e.field}`
103
+ )) })
104
+ ] }),
105
+ a.length > p && /* @__PURE__ */ l("p", { className: "border-t border-border px-2.5 py-1.5 text-[11px] text-muted-foreground", children: [
106
+ "+",
107
+ (a.length - p).toLocaleString(),
108
+ " more — download Excel for every row."
109
+ ] })
110
+ ] })
111
+ ]
112
+ }
113
+ );
114
+ }
115
+ export {
116
+ F as AiPlanChanges
117
+ };