durable-actors-observer 0.1.0

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,1863 @@
1
+ import * as e from "react";
2
+ import { useEffect as t, useId as n, useMemo as r, useRef as i, useState as a } from "react";
3
+ import { Box as o, Calendar as s, ChevronDown as c, ChevronDownIcon as l, ChevronLeftIcon as u, ChevronRightIcon as d, CircleHelp as f, Pause as p, Play as m, RefreshCw as h, Search as g, Unplug as _, X as v } from "lucide-react";
4
+ import { Slot as y } from "@radix-ui/react-slot";
5
+ import { cva as b } from "class-variance-authority";
6
+ import { clsx as x } from "clsx";
7
+ import { extendTailwindMerge as S } from "tailwind-merge";
8
+ import { Fragment as C, jsx as w, jsxs as T } from "react/jsx-runtime";
9
+ import { DayPicker as E, getDefaultClassNames as D } from "react-day-picker";
10
+ import * as O from "@radix-ui/react-popover";
11
+ import * as k from "@radix-ui/react-dialog";
12
+ import { createParser as A } from "eventsource-parser";
13
+ //#region src/lib/utils.ts
14
+ var j = S({ prefix: "la" });
15
+ function M(...e) {
16
+ return j(x(e));
17
+ }
18
+ //#endregion
19
+ //#region src/components/ui/button.tsx
20
+ var N = b("la:inline-flex la:shrink-0 la:items-center la:justify-center la:gap-2 la:whitespace-nowrap la:rounded-md la:text-sm la:font-medium la:outline-none la:transition-[background-color,border-color,color,box-shadow,transform] la:duration-150 la:ease-out la:active:translate-y-px la:disabled:pointer-events-none la:disabled:translate-y-0 la:disabled:opacity-45 la:focus-visible:ring-2 la:focus-visible:ring-ring la:focus-visible:ring-offset-2 la:focus-visible:ring-offset-background la:aria-invalid:border-destructive la:aria-invalid:ring-destructive/25 la:[&_svg]:pointer-events-none la:[&_svg]:shrink-0 la:[&_svg:not([class*='size-'])]:size-4", {
21
+ variants: {
22
+ variant: {
23
+ default: "la:bg-primary la:text-primary-foreground la:shadow-[var(--shadow-control)] la:hover:bg-primary/88",
24
+ destructive: "la:bg-destructive la:text-white la:hover:bg-destructive/90 la:focus-visible:ring-destructive/20 la:dark:focus-visible:ring-destructive/40 la:dark:bg-destructive/60",
25
+ outline: "la:border la:border-input la:bg-card la:hover:border-foreground/20 la:hover:bg-accent la:hover:text-accent-foreground la:dark:bg-card",
26
+ secondary: "la:bg-secondary la:text-secondary-foreground la:hover:bg-secondary/80",
27
+ ghost: "la:bg-transparent la:hover:bg-accent la:hover:text-accent-foreground la:dark:hover:bg-accent/50",
28
+ link: "la:bg-transparent la:text-primary la:underline-offset-4 la:hover:underline"
29
+ },
30
+ size: {
31
+ default: "la:h-9 la:px-4 la:py-2 la:max-md:min-h-11 la:has-[>svg]:px-3",
32
+ sm: "la:h-8 la:gap-1.5 la:px-3 la:max-md:min-h-11 la:has-[>svg]:px-2.5",
33
+ lg: "la:h-10 la:px-5 la:max-md:min-h-11 la:has-[>svg]:px-4",
34
+ icon: "la:size-9 la:max-md:size-11",
35
+ "icon-sm": "la:size-8 la:max-md:size-11",
36
+ "icon-lg": "la:size-10 la:max-md:size-11"
37
+ }
38
+ },
39
+ defaultVariants: {
40
+ variant: "default",
41
+ size: "default"
42
+ }
43
+ });
44
+ function P({ className: e, variant: t, size: n, asChild: r = !1, ...i }) {
45
+ return /* @__PURE__ */ w(r ? y : "button", {
46
+ "data-slot": "button",
47
+ className: M(N({
48
+ variant: t,
49
+ size: n,
50
+ className: e
51
+ })),
52
+ ...i
53
+ });
54
+ }
55
+ //#endregion
56
+ //#region src/components/ui/calendar.tsx
57
+ function ee({ className: e, classNames: t, showOutsideDays: n = !0, captionLayout: r = "label", buttonVariant: i = "ghost", formatters: a, components: o, ...s }) {
58
+ let c = D();
59
+ return /* @__PURE__ */ w(E, {
60
+ showOutsideDays: n,
61
+ className: M("la:group/calendar la:bg-background la:p-3 la:[--cell-size:--spacing(8)] la:[[data-slot=card-content]_&]:bg-transparent la:[[data-slot=popover-content]_&]:bg-transparent", e),
62
+ captionLayout: r,
63
+ formatters: {
64
+ formatMonthDropdown: (e) => e.toLocaleString("default", { month: "short" }),
65
+ ...a
66
+ },
67
+ classNames: {
68
+ root: M("la:w-fit", c.root),
69
+ months: M("la:relative la:flex la:flex-col la:gap-4 la:md:flex-row", c.months),
70
+ month: M("la:flex la:w-full la:flex-col la:gap-4", c.month),
71
+ nav: M("la:absolute la:inset-x-0 la:top-0 la:flex la:w-full la:items-center la:justify-between la:gap-1", c.nav),
72
+ button_previous: M(N({ variant: i }), "la:size-(--cell-size) la:p-0 la:select-none la:aria-disabled:opacity-50", c.button_previous),
73
+ button_next: M(N({ variant: i }), "la:size-(--cell-size) la:p-0 la:select-none la:aria-disabled:opacity-50", c.button_next),
74
+ month_caption: M("la:flex la:h-(--cell-size) la:w-full la:items-center la:justify-center la:px-(--cell-size)", c.month_caption),
75
+ dropdowns: M("la:flex la:h-(--cell-size) la:w-full la:items-center la:justify-center la:gap-1.5 la:text-sm la:font-medium", c.dropdowns),
76
+ dropdown_root: M("la:relative la:rounded-md la:border la:border-input la:shadow-xs la:has-focus:border-ring la:has-focus:ring-[3px] la:has-focus:ring-ring/50", c.dropdown_root),
77
+ dropdown: M("la:absolute la:inset-0 la:bg-popover la:opacity-0", c.dropdown),
78
+ caption_label: M("la:font-medium la:select-none", r === "label" ? "la:text-sm" : "la:flex la:h-8 la:items-center la:gap-1 la:rounded-md la:pr-1 la:pl-2 la:text-sm la:[&>svg]:size-3.5 la:[&>svg]:text-muted-foreground", c.caption_label),
79
+ month_grid: M("la:w-full la:border-collapse", c.month_grid),
80
+ weekdays: M("la:flex", c.weekdays),
81
+ weekday: M("la:flex-1 la:rounded-md la:text-[0.8rem] la:font-normal la:text-muted-foreground la:select-none", c.weekday),
82
+ week: M("la:mt-2 la:flex la:w-full", c.week),
83
+ week_number_header: M("la:w-(--cell-size) la:select-none", c.week_number_header),
84
+ week_number: M("la:text-[0.8rem] la:text-muted-foreground la:select-none", c.week_number),
85
+ day: M("la:group/day la:relative la:aspect-square la:h-full la:w-full la:p-0 la:text-center la:select-none la:[&:last-child[data-selected=true]_button]:rounded-r-md", s.showWeekNumber ? "la:[&:nth-child(2)[data-selected=true]_button]:rounded-l-md" : "la:[&:first-child[data-selected=true]_button]:rounded-l-md", c.day),
86
+ range_start: M("la:rounded-l-md la:bg-accent", c.range_start),
87
+ range_middle: M("la:rounded-none", c.range_middle),
88
+ range_end: M("la:rounded-r-md la:bg-accent", c.range_end),
89
+ today: M("la:rounded-md la:bg-accent la:text-accent-foreground la:data-[selected=true]:rounded-none", c.today),
90
+ outside: M("la:text-muted-foreground la:aria-selected:text-muted-foreground", c.outside),
91
+ disabled: M("la:text-muted-foreground la:opacity-50", c.disabled),
92
+ hidden: M("la:invisible", c.hidden),
93
+ ...t
94
+ },
95
+ components: {
96
+ Root: ({ className: e, rootRef: t, ...n }) => /* @__PURE__ */ w("div", {
97
+ "data-slot": "calendar",
98
+ ref: t,
99
+ className: M(e),
100
+ ...n
101
+ }),
102
+ Chevron: ({ className: e, orientation: t, ...n }) => w(t === "left" ? u : t === "right" ? d : l, {
103
+ className: M("la:size-4", e),
104
+ ...n
105
+ }),
106
+ DayButton: te,
107
+ WeekNumber: ({ children: e, ...t }) => /* @__PURE__ */ w("td", {
108
+ ...t,
109
+ children: /* @__PURE__ */ w("div", {
110
+ className: "la:flex la:size-(--cell-size) la:items-center la:justify-center la:text-center",
111
+ children: e
112
+ })
113
+ }),
114
+ ...o
115
+ },
116
+ ...s
117
+ });
118
+ }
119
+ function te({ className: t, day: n, modifiers: r, ...i }) {
120
+ let a = D(), o = e.useRef(null);
121
+ return e.useEffect(() => {
122
+ r.focused && o.current?.focus();
123
+ }, [r.focused]), /* @__PURE__ */ w(P, {
124
+ ref: o,
125
+ variant: "ghost",
126
+ size: "icon",
127
+ "data-day": n.date.toLocaleDateString(),
128
+ "data-selected-single": r.selected && !r.range_start && !r.range_end && !r.range_middle,
129
+ "data-range-start": r.range_start,
130
+ "data-range-end": r.range_end,
131
+ "data-range-middle": r.range_middle,
132
+ className: M("la:flex la:aspect-square la:size-auto la:w-full la:min-w-(--cell-size) la:flex-col la:gap-1 la:leading-none la:font-normal la:group-data-[focused=true]/day:relative la:group-data-[focused=true]/day:z-10 la:group-data-[focused=true]/day:border-ring la:group-data-[focused=true]/day:ring-[3px] la:group-data-[focused=true]/day:ring-ring/50 la:data-[range-end=true]:rounded-md la:data-[range-end=true]:rounded-r-md la:data-[range-end=true]:bg-primary la:data-[range-end=true]:text-primary-foreground la:data-[range-middle=true]:rounded-none la:data-[range-middle=true]:bg-accent la:data-[range-middle=true]:text-accent-foreground la:data-[range-start=true]:rounded-md la:data-[range-start=true]:rounded-l-md la:data-[range-start=true]:bg-primary la:data-[range-start=true]:text-primary-foreground la:data-[selected-single=true]:bg-primary la:data-[selected-single=true]:text-primary-foreground la:dark:hover:text-accent-foreground la:[&>span]:text-xs la:[&>span]:opacity-70", a.day, t),
133
+ ...i
134
+ });
135
+ }
136
+ //#endregion
137
+ //#region src/components/ui/input.tsx
138
+ function F({ className: e, type: t, ...n }) {
139
+ return /* @__PURE__ */ w("input", {
140
+ type: t,
141
+ "data-slot": "input",
142
+ className: M("la:flex la:h-9 la:w-full la:min-w-0 la:rounded-md la:border la:border-input la:bg-card la:px-3 la:py-1 la:text-sm la:text-foreground la:outline-none la:transition-colors la:placeholder:text-muted-foreground la:focus-visible:border-ring la:focus-visible:ring-2 la:focus-visible:ring-ring/20 la:disabled:cursor-not-allowed la:disabled:opacity-50 la:max-md:min-h-11", e),
143
+ ...n
144
+ });
145
+ }
146
+ //#endregion
147
+ //#region src/components/ui/popover.tsx
148
+ function ne({ ...e }) {
149
+ return /* @__PURE__ */ w(O.Root, {
150
+ "data-slot": "popover",
151
+ ...e
152
+ });
153
+ }
154
+ function re({ ...e }) {
155
+ return /* @__PURE__ */ w(O.Trigger, {
156
+ "data-slot": "popover-trigger",
157
+ ...e
158
+ });
159
+ }
160
+ function ie({ className: e, align: t = "center", sideOffset: n = 4, ...r }) {
161
+ return /* @__PURE__ */ w(O.Portal, { children: /* @__PURE__ */ w(O.Content, {
162
+ "data-slot": "popover-content",
163
+ align: t,
164
+ sideOffset: n,
165
+ className: M("la:z-50 la:w-72 la:origin-(--radix-popover-content-transform-origin) la:rounded-md la:border la:bg-popover la:p-4 la:text-popover-foreground la:shadow-md la:outline-hidden", e),
166
+ ...r
167
+ }) });
168
+ }
169
+ //#endregion
170
+ //#region src/time-range.ts
171
+ var ae = [
172
+ {
173
+ minutes: 5,
174
+ label: "Last 5 minutes"
175
+ },
176
+ {
177
+ minutes: 15,
178
+ label: "Last 15 minutes"
179
+ },
180
+ {
181
+ minutes: 60,
182
+ label: "Last hour"
183
+ },
184
+ {
185
+ minutes: 360,
186
+ label: "Last 6 hours"
187
+ },
188
+ {
189
+ minutes: 1440,
190
+ label: "Last 24 hours"
191
+ },
192
+ {
193
+ minutes: 10080,
194
+ label: "Last 7 days"
195
+ }
196
+ ], I = {
197
+ kind: "relative",
198
+ minutes: 60
199
+ };
200
+ function L(e, t) {
201
+ switch (e.kind) {
202
+ case "relative": return { fromMs: Math.floor((t - e.minutes * 6e4) / 6e4) * 6e4 };
203
+ case "absolute": return {
204
+ fromMs: e.fromMs,
205
+ toMs: e.toMs
206
+ };
207
+ case "all": return {};
208
+ }
209
+ }
210
+ function R(e) {
211
+ switch (e.kind) {
212
+ case "relative": return ae.find((t) => t.minutes === e.minutes)?.label ?? `Last ${e.minutes} minutes`;
213
+ case "absolute": return `${se(e.fromMs, e.toMs)} – ${se(e.toMs, e.fromMs)}`;
214
+ case "all": return "All retained";
215
+ }
216
+ }
217
+ function z(e) {
218
+ switch (e.kind) {
219
+ case "relative": return `in the ${R(e).toLocaleLowerCase()}`;
220
+ case "absolute": return `between ${R(e)}`;
221
+ case "all": return "in retained history";
222
+ }
223
+ }
224
+ function oe(e, t) {
225
+ return e.kind === t.kind && (e.kind !== "relative" || e.minutes === t.minutes) && (e.kind !== "absolute" || e.fromMs === t.fromMs && e.toMs === t.toMs);
226
+ }
227
+ function se(e, t) {
228
+ let n = new Date(e), r = n.toDateString() === new Date(t).toDateString(), i = n.toLocaleTimeString([], {
229
+ hour: "2-digit",
230
+ minute: "2-digit",
231
+ hour12: !1
232
+ });
233
+ return r && e > t ? i : `${n.toLocaleDateString([], {
234
+ month: "short",
235
+ day: "numeric"
236
+ })} ${i}`;
237
+ }
238
+ //#endregion
239
+ //#region src/TimeRangePicker.tsx
240
+ function B({ value: e, onChange: t, allowAll: n = !0, className: r, align: i = "end" }) {
241
+ let [o, l] = a(!1), [u, d] = a(() => le(e)), [f, p] = a(!1), m = (e) => {
242
+ t(e), l(!1);
243
+ };
244
+ return /* @__PURE__ */ T(ne, {
245
+ open: o,
246
+ onOpenChange: (t) => {
247
+ t && (d(le(e)), p(!1)), l(t);
248
+ },
249
+ children: [/* @__PURE__ */ w(re, {
250
+ asChild: !0,
251
+ children: /* @__PURE__ */ T(P, {
252
+ type: "button",
253
+ variant: "outline",
254
+ className: r,
255
+ "aria-label": `Time range: ${R(e)}`,
256
+ children: [
257
+ /* @__PURE__ */ w(s, { "aria-hidden": "true" }),
258
+ /* @__PURE__ */ w("span", {
259
+ className: "la:truncate la:tabular-nums",
260
+ children: R(e)
261
+ }),
262
+ /* @__PURE__ */ w(c, {
263
+ "aria-hidden": "true",
264
+ className: "la:text-muted-foreground"
265
+ })
266
+ ]
267
+ })
268
+ }), /* @__PURE__ */ T(ie, {
269
+ align: i,
270
+ "aria-label": "Time range",
271
+ className: "la:flex la:w-auto la:p-0 la:text-sm",
272
+ children: [/* @__PURE__ */ T("div", {
273
+ className: "la:flex la:flex-col la:gap-0.5 la:border-r la:p-2",
274
+ role: "group",
275
+ "aria-label": "Preset ranges",
276
+ children: [ae.map((t) => /* @__PURE__ */ w(ce, {
277
+ label: t.label,
278
+ selected: oe(e, {
279
+ kind: "relative",
280
+ minutes: t.minutes
281
+ }),
282
+ onSelect: () => m({
283
+ kind: "relative",
284
+ minutes: t.minutes
285
+ })
286
+ }, t.minutes)), n && /* @__PURE__ */ w(ce, {
287
+ label: "All retained",
288
+ selected: e.kind === "all",
289
+ onSelect: () => m({ kind: "all" })
290
+ })]
291
+ }), /* @__PURE__ */ T("form", {
292
+ className: "la:flex la:w-[22rem] la:flex-col",
293
+ "aria-label": "Custom range",
294
+ onSubmit: (e) => {
295
+ e.preventDefault();
296
+ let t = ue(u);
297
+ if (!t) {
298
+ p(!0);
299
+ return;
300
+ }
301
+ p(!1), m(t);
302
+ },
303
+ children: [
304
+ /* @__PURE__ */ w(ee, {
305
+ mode: "range",
306
+ numberOfMonths: 1,
307
+ defaultMonth: u.dates?.to ?? u.dates?.from,
308
+ selected: u.dates,
309
+ onSelect: (e) => d((t) => ({
310
+ ...t,
311
+ dates: e
312
+ })),
313
+ disabled: { after: /* @__PURE__ */ new Date() }
314
+ }),
315
+ /* @__PURE__ */ T("div", {
316
+ className: "la:flex la:items-end la:gap-2 la:border-t la:px-3 la:py-3",
317
+ children: [
318
+ /* @__PURE__ */ T("label", {
319
+ className: "la:grid la:gap-1 la:text-xs la:text-muted-foreground",
320
+ children: ["From", /* @__PURE__ */ w(F, {
321
+ type: "time",
322
+ name: "from",
323
+ required: !0,
324
+ className: "la:h-8 la:w-24 la:tabular-nums",
325
+ value: u.fromTime,
326
+ onChange: (e) => d({
327
+ ...u,
328
+ fromTime: e.target.value
329
+ }),
330
+ "aria-invalid": f || void 0
331
+ })]
332
+ }),
333
+ /* @__PURE__ */ T("label", {
334
+ className: "la:grid la:gap-1 la:text-xs la:text-muted-foreground",
335
+ children: ["To", /* @__PURE__ */ w(F, {
336
+ type: "time",
337
+ name: "to",
338
+ required: !0,
339
+ className: "la:h-8 la:w-24 la:tabular-nums",
340
+ value: u.toTime,
341
+ onChange: (e) => d({
342
+ ...u,
343
+ toTime: e.target.value
344
+ }),
345
+ "aria-invalid": f || void 0
346
+ })]
347
+ }),
348
+ /* @__PURE__ */ w(P, {
349
+ type: "submit",
350
+ variant: "outline",
351
+ size: "sm",
352
+ className: "la:ml-auto",
353
+ disabled: !u.dates?.from,
354
+ children: "Apply range"
355
+ })
356
+ ]
357
+ }),
358
+ f && /* @__PURE__ */ w("p", {
359
+ className: "la:px-3 la:pb-3 la:text-xs la:text-danger",
360
+ role: "alert",
361
+ children: "From must be before To."
362
+ })
363
+ ]
364
+ })]
365
+ })]
366
+ });
367
+ }
368
+ function ce({ label: e, selected: t, onSelect: n }) {
369
+ return /* @__PURE__ */ w(P, {
370
+ type: "button",
371
+ variant: t ? "secondary" : "ghost",
372
+ size: "sm",
373
+ className: "la:justify-start la:font-normal la:aria-pressed:font-semibold",
374
+ "aria-pressed": t,
375
+ onClick: n,
376
+ children: e
377
+ });
378
+ }
379
+ function le(e) {
380
+ let t = Date.now(), n = L(e, t), r = new Date(n.fromMs ?? t - 36e5), i = new Date(n.toMs ?? t);
381
+ return {
382
+ dates: {
383
+ from: de(r),
384
+ to: de(i)
385
+ },
386
+ fromTime: fe(r),
387
+ toTime: fe(i)
388
+ };
389
+ }
390
+ function ue(e) {
391
+ let t = e.dates?.from, n = e.dates?.to ?? t;
392
+ if (!t || !n) return null;
393
+ let r = pe(t, e.fromTime), i = pe(n, e.toTime);
394
+ return Number.isFinite(r) && Number.isFinite(i) && r < i ? {
395
+ kind: "absolute",
396
+ fromMs: r,
397
+ toMs: i
398
+ } : null;
399
+ }
400
+ function de(e) {
401
+ return new Date(e.getFullYear(), e.getMonth(), e.getDate());
402
+ }
403
+ function fe(e) {
404
+ return `${String(e.getHours()).padStart(2, "0")}:${String(e.getMinutes()).padStart(2, "0")}`;
405
+ }
406
+ function pe(e, t) {
407
+ let [n, r] = t.split(":").map(Number);
408
+ return new Date(e.getFullYear(), e.getMonth(), e.getDate(), n ?? 0, r ?? 0).getTime();
409
+ }
410
+ //#endregion
411
+ //#region src/components/ui/badge.tsx
412
+ var me = b("la:inline-flex la:items-center la:justify-center la:gap-1.5 la:rounded-md la:border la:px-2 la:py-0.5 la:text-xs la:font-medium la:whitespace-nowrap", {
413
+ variants: { variant: {
414
+ default: "la:border-transparent la:bg-muted la:text-muted-foreground",
415
+ outline: "la:border-border la:text-muted-foreground"
416
+ } },
417
+ defaultVariants: { variant: "default" }
418
+ });
419
+ function V({ className: e, variant: t, ...n }) {
420
+ return /* @__PURE__ */ w("span", {
421
+ "data-slot": "badge",
422
+ className: M(me({ variant: t }), e),
423
+ ...n
424
+ });
425
+ }
426
+ //#endregion
427
+ //#region src/components/ui/sheet.tsx
428
+ var he = k.Root, ge = k.Title, _e = k.Description;
429
+ function ve({ className: e, children: t, container: n, ...r }) {
430
+ return /* @__PURE__ */ T(k.Portal, {
431
+ container: n,
432
+ children: [/* @__PURE__ */ w(k.Overlay, { className: "la-sheet-overlay" }), /* @__PURE__ */ T(k.Content, {
433
+ "data-slot": "sheet-content",
434
+ className: M("la-observer la-sheet", e),
435
+ ...r,
436
+ children: [t, /* @__PURE__ */ w(k.Close, {
437
+ asChild: !0,
438
+ children: /* @__PURE__ */ w(P, {
439
+ className: "la-sheet-close",
440
+ variant: "ghost",
441
+ size: "icon",
442
+ "aria-label": "Close",
443
+ children: /* @__PURE__ */ w(v, { "aria-hidden": "true" })
444
+ })
445
+ })]
446
+ })]
447
+ });
448
+ }
449
+ //#endregion
450
+ //#region src/components/ui/table.tsx
451
+ function H({ className: e, ...t }) {
452
+ return /* @__PURE__ */ w("div", {
453
+ "data-slot": "table-container",
454
+ className: "la:relative la:w-full la:overflow-x-auto",
455
+ children: /* @__PURE__ */ w("table", {
456
+ "data-slot": "table",
457
+ className: M("la:w-full la:caption-bottom la:text-sm la:tabular-nums", e),
458
+ ...t
459
+ })
460
+ });
461
+ }
462
+ function U({ className: e, ...t }) {
463
+ return /* @__PURE__ */ w("thead", {
464
+ "data-slot": "table-header",
465
+ className: M("la:[&_tr]:border-b", e),
466
+ ...t
467
+ });
468
+ }
469
+ function W({ className: e, ...t }) {
470
+ return /* @__PURE__ */ w("tbody", {
471
+ "data-slot": "table-body",
472
+ className: M("la:[&_tr:last-child]:border-0", e),
473
+ ...t
474
+ });
475
+ }
476
+ function G({ className: e, ...t }) {
477
+ return /* @__PURE__ */ w("tr", {
478
+ "data-slot": "table-row",
479
+ className: M("la:border-b la:transition-colors la:duration-150 la:hover:bg-muted/60 la:data-[state=selected]:bg-muted", e),
480
+ ...t
481
+ });
482
+ }
483
+ function K({ className: e, ...t }) {
484
+ return /* @__PURE__ */ w("th", {
485
+ "data-slot": "table-head",
486
+ className: M("la:h-10 la:whitespace-nowrap la:px-3 la:text-left la:align-middle la:text-xs la:font-medium la:text-muted-foreground la:[&:has([role=checkbox])]:pr-0 la:[&>[role=checkbox]]:translate-y-[2px]", e),
487
+ ...t
488
+ });
489
+ }
490
+ function q({ className: e, ...t }) {
491
+ return /* @__PURE__ */ w("td", {
492
+ "data-slot": "table-cell",
493
+ className: M("la:whitespace-nowrap la:px-3 la:py-2.5 la:align-middle la:[&:has([role=checkbox])]:pr-0 la:[&>[role=checkbox]]:translate-y-[2px]", e),
494
+ ...t
495
+ });
496
+ }
497
+ //#endregion
498
+ //#region src/observer-hooks.ts
499
+ function ye(e) {
500
+ let [n, r] = a(0), [i, o] = a(), [s, c] = a(!0), [l, u] = a(!1);
501
+ return t(() => {
502
+ let t = new AbortController(), n, r = 1e3;
503
+ return u(!1), c(!0), a(), () => {
504
+ t.abort(), clearTimeout(n);
505
+ };
506
+ function i(n) {
507
+ t.signal.aborted || (o({
508
+ client: e,
509
+ inventory: n,
510
+ updatedAt: Date.now()
511
+ }), u(!1), c(!1), r = 1e3);
512
+ }
513
+ async function a() {
514
+ try {
515
+ if (e.watchActors) {
516
+ if (await e.watchActors(i, t.signal), !t.signal.aborted) throw Error("Stream ended");
517
+ } else c(!0), i(await e.listActors(t.signal));
518
+ } catch {
519
+ t.signal.aborted || u(!0);
520
+ } finally {
521
+ t.signal.aborted || (c(!1), n = setTimeout(a, e.watchActors ? r : 5e3), r = Math.min(r * 2, 1e4));
522
+ }
523
+ }
524
+ }, [e, n]), {
525
+ updatedAt: i?.client === e ? i.updatedAt : void 0,
526
+ inventory: i?.client === e ? i.inventory : void 0,
527
+ loading: s,
528
+ failed: l,
529
+ retry: () => r((e) => e + 1)
530
+ };
531
+ }
532
+ function be(e, n = !0) {
533
+ let [r, i] = a(), [o, s] = a(!1), [c, l] = a(0);
534
+ return t(() => i(void 0), [e]), t(() => {
535
+ if (!n) return;
536
+ let t, r = new AbortController(), a, o = 1e3;
537
+ async function c() {
538
+ try {
539
+ if (!e.watchRequests) throw Error("Request traces unavailable");
540
+ if (await e.watchRequests((e) => {
541
+ r.signal.aborted || (t = e.resumeCursor, i((t) => xe(t, e)), s(!1), o = 1e3);
542
+ }, r.signal, t), !r.signal.aborted) throw Error("Request stream disconnected");
543
+ } catch {
544
+ r.signal.aborted || s(!0);
545
+ } finally {
546
+ r.signal.aborted || (a = setTimeout(c, o), o = Math.min(o * 2, 1e4));
547
+ }
548
+ }
549
+ return s(!1), c(), () => {
550
+ r.abort(), clearTimeout(a);
551
+ };
552
+ }, [
553
+ e,
554
+ c,
555
+ n
556
+ ]), {
557
+ page: r,
558
+ failed: o,
559
+ retry: () => l((e) => e + 1)
560
+ };
561
+ }
562
+ function xe(e, t) {
563
+ let n = new Map((e?.epoch === t.epoch && !t.reset ? e.records : []).map((e) => [e.eventId ?? e.sequence, e]));
564
+ for (let e of t.records) n.set(e.eventId ?? e.sequence, e);
565
+ return {
566
+ ...t,
567
+ reset: t.reset || e?.epoch === t.epoch && e.reset,
568
+ records: [...n.values()].sort((e, t) => t.sequence - e.sequence).slice(0, t.capacity)
569
+ };
570
+ }
571
+ function Se(e, n, r, o = 1e4) {
572
+ let s = n && e.query ? JSON.stringify(n) : void 0, c = i(r);
573
+ c.current = r;
574
+ let [l, u] = a(0), [d, f] = a(), [p, m] = a(!1), [h, g] = a(!1);
575
+ t(() => {
576
+ if (!s) return;
577
+ let t = new AbortController(), n;
578
+ return m(!1), g(!0), r(), () => {
579
+ t.abort(), clearTimeout(n);
580
+ };
581
+ async function r() {
582
+ try {
583
+ let n = c.current(await e.query(JSON.parse(s), t.signal));
584
+ if (t.signal.aborted) return;
585
+ f({
586
+ client: e.query,
587
+ key: s,
588
+ value: n,
589
+ updatedAt: Date.now()
590
+ }), m(!1);
591
+ } catch {
592
+ t.signal.aborted || m(!0);
593
+ } finally {
594
+ t.signal.aborted || (g(!1), n = setTimeout(r, o));
595
+ }
596
+ }
597
+ }, [
598
+ e,
599
+ s,
600
+ l,
601
+ o
602
+ ]);
603
+ let _ = d && d.client === e.query && d.key === s ? d : void 0;
604
+ return {
605
+ supported: !!e.query,
606
+ value: _?.value,
607
+ updatedAt: _?.updatedAt,
608
+ loading: h,
609
+ failed: p,
610
+ retry: () => u((e) => e + 1)
611
+ };
612
+ }
613
+ //#endregion
614
+ //#region src/client.ts
615
+ var Ce = class {
616
+ baseUrl;
617
+ request;
618
+ constructor(e = "/api/observe", t = globalThis.fetch.bind(globalThis)) {
619
+ this.baseUrl = e, this.request = t;
620
+ }
621
+ async listActors(e) {
622
+ let t = await this.get("actors", e);
623
+ if (!we(t)) throw Error("Invalid actor inventory response.");
624
+ return t;
625
+ }
626
+ async watchActors(e, t) {
627
+ return this.watch("events", "inventory", we, e, t);
628
+ }
629
+ async watchRequests(e, t, n) {
630
+ let r = n ? `?${new URLSearchParams({ after: n })}` : "";
631
+ return this.watch(`requests/events${r}`, "requests", De, e, t);
632
+ }
633
+ async query(e, t) {
634
+ let n = await this.request(`${this.baseUrl.replace(/\/$/u, "")}/query`, {
635
+ method: "POST",
636
+ credentials: "same-origin",
637
+ redirect: "error",
638
+ signal: t,
639
+ headers: {
640
+ "content-type": "application/json",
641
+ accept: "application/json"
642
+ },
643
+ body: JSON.stringify(e)
644
+ });
645
+ if (!n.ok) throw Error(`Observability query failed (HTTP ${n.status}).`);
646
+ let r = await n.json();
647
+ if (!r || typeof r != "object" || !("rows" in r) || !Array.isArray(r.rows) || r.rows.length > 500 || !("truncated" in r) || typeof r.truncated != "boolean" || !r.rows.every((e) => e && typeof e == "object" && !Array.isArray(e) && Object.values(e).every((e) => e === null || [
648
+ "string",
649
+ "boolean",
650
+ "number"
651
+ ].includes(typeof e)))) throw Error("Invalid SQL query response");
652
+ return r;
653
+ }
654
+ async watch(e, t, n, r, i) {
655
+ let a = await this.request(`${this.baseUrl.replace(/\/$/u, "")}/${e}`, {
656
+ signal: i,
657
+ credentials: "same-origin",
658
+ redirect: "error",
659
+ headers: { accept: "text/event-stream" }
660
+ });
661
+ if (!a.ok || !a.headers.get("content-type")?.startsWith("text/event-stream") || !a.body) throw await a.body?.cancel(), Error("Live inventory is unavailable");
662
+ let o = a.body.getReader(), s = new TextDecoder(), c = A({ onEvent(e) {
663
+ if (i.aborted) return;
664
+ if (e.event === "error") throw Error("Live inventory is unavailable");
665
+ if (e.event !== t) return;
666
+ let a = JSON.parse(e.data);
667
+ if (!n(a)) throw Error("Invalid observer response");
668
+ r(a);
669
+ } }), l = () => {
670
+ o.cancel().catch(() => {});
671
+ };
672
+ i.addEventListener("abort", l, { once: !0 });
673
+ try {
674
+ for (; !i.aborted;) {
675
+ let { value: e, done: t } = await o.read();
676
+ if (t) break;
677
+ c.feed(s.decode(e, { stream: !0 }));
678
+ }
679
+ if (!i.aborted) throw Error("Live inventory disconnected");
680
+ } finally {
681
+ i.removeEventListener("abort", l), await o.cancel().catch(() => {}), o.releaseLock();
682
+ }
683
+ }
684
+ async checkConnection(e) {
685
+ let t = await this.get("connection", e);
686
+ if (!t || typeof t != "object" || !("connected" in t) || t.connected !== !0) throw Error("Invalid connection response.");
687
+ }
688
+ async get(e, t) {
689
+ let n = await this.request(`${this.baseUrl.replace(/\/$/u, "")}/${e}`, {
690
+ method: "GET",
691
+ credentials: "same-origin",
692
+ redirect: "error",
693
+ signal: t,
694
+ headers: { accept: "application/json" }
695
+ });
696
+ if (!n.ok) throw Error(`Connection check failed (HTTP ${n.status}).`);
697
+ return n.json();
698
+ }
699
+ };
700
+ function we(e) {
701
+ return !e || typeof e != "object" || !("actors" in e) || !Array.isArray(e.actors) ? !1 : e.actors.every((e) => e && typeof e.actorName == "string" && [
702
+ e.live,
703
+ e.dormant,
704
+ e.unknown
705
+ ].every((e) => Number.isSafeInteger(e) && e >= 0) && Array.isArray(e.instances) && e.instances.every(Te));
706
+ }
707
+ function Te(e) {
708
+ return !!e && typeof e == "object" && "actorId" in e && typeof e.actorId == "string" && "status" in e && [
709
+ "live",
710
+ "dormant",
711
+ "unknown"
712
+ ].includes(String(e.status)) && "connections" in e && Array.isArray(e.connections) && e.connections.every(Ee) && (!("waiting" in e) || e.waiting == null || Array.isArray(e.waiting) && e.waiting.every((e) => !!e && typeof e == "object" && typeof e.id == "string" && typeof e.operation == "string"));
713
+ }
714
+ function Ee(e) {
715
+ return !!e && typeof e == "object" && "id" in e && typeof e.id == "string" && "metadata" in e;
716
+ }
717
+ function De(e) {
718
+ if (!e || typeof e != "object") return !1;
719
+ let t = e;
720
+ return typeof t.epoch == "string" && [
721
+ t.cursor,
722
+ t.capacity,
723
+ t.evicted,
724
+ t.dropped
725
+ ].every(J) && (t.persistenceFailed === void 0 || typeof t.persistenceFailed == "boolean") && (t.nextCursor == null || typeof t.nextCursor == "string") && (t.resumeCursor === void 0 || typeof t.resumeCursor == "string") && (t.reset === void 0 || typeof t.reset == "boolean") && t.capacity > 0 && t.capacity <= 500 && Array.isArray(t.records) && t.records.length <= t.capacity && t.records.every((e) => Oe(e) && e.sequence <= t.cursor);
726
+ }
727
+ function J(e) {
728
+ return Number.isSafeInteger(e) && Number(e) >= 0;
729
+ }
730
+ function Oe(e) {
731
+ if (!e || typeof e != "object") return !1;
732
+ let t = e;
733
+ return [
734
+ t.requestId,
735
+ t.hostId,
736
+ t.sessionId,
737
+ t.actorName,
738
+ t.actorId,
739
+ t.operation
740
+ ].every((e) => typeof e == "string") && (t.eventId === void 0 || typeof t.eventId == "string" && t.eventId.length > 0) && J(t.sequence) && J(t.startedAtMs) && t.startedAtMs <= 864e13 && ["method", "websocket"].includes(t.kind) && [
741
+ "completed",
742
+ "failed",
743
+ "rejected",
744
+ "rerouted",
745
+ "interrupted"
746
+ ].includes(t.outcome) && (t.connectionId === null || typeof t.connectionId == "string") && Number.isFinite(t.durationMs) && t.durationMs >= 0 && (t.queueWaitMs === null || Number.isFinite(t.queueWaitMs) && t.queueWaitMs >= 0 && t.queueWaitMs <= t.durationMs);
747
+ }
748
+ //#endregion
749
+ //#region src/request-sql.ts
750
+ var Y = 100;
751
+ function ke(e, t) {
752
+ let n = [], r = [];
753
+ for (let [t, i, a] of [
754
+ [
755
+ "started_at_ms",
756
+ ">=",
757
+ e.fromMs
758
+ ],
759
+ [
760
+ "started_at_ms",
761
+ "<=",
762
+ e.toMs
763
+ ],
764
+ [
765
+ "actor_name",
766
+ "=",
767
+ e.actorName
768
+ ],
769
+ [
770
+ "actor_id",
771
+ "=",
772
+ e.actorId
773
+ ],
774
+ [
775
+ "outcome",
776
+ "=",
777
+ e.outcome
778
+ ]
779
+ ]) a !== void 0 && (n.push(`${t} ${i} ?`), r.push(a));
780
+ if (t) {
781
+ let e = JSON.parse(t);
782
+ n.push("sequence <= ?", "(started_at_ms, sequence) < (?, ?)"), r.push(e.watermark, e.time, e.sequence);
783
+ }
784
+ return {
785
+ sql: `SELECT h.generation, h.watermark, h.pruned, h.total, r.sequence, r.event
786
+ FROM request_history h LEFT JOIN (
787
+ SELECT sequence, event, started_at_ms FROM request_events
788
+ ${n.length ? `WHERE ${n.join(" AND ")}` : ""}
789
+ ORDER BY started_at_ms DESC, sequence DESC LIMIT 101
790
+ ) r ON 1 = 1
791
+ ORDER BY r.started_at_ms DESC, r.sequence DESC`,
792
+ params: r
793
+ };
794
+ }
795
+ function Ae(e, t) {
796
+ if (e.truncated) throw Error("History query exceeded the server result limit");
797
+ let n = e.rows[0];
798
+ if (!n || typeof n.generation != "string" || ![
799
+ n.watermark,
800
+ n.pruned,
801
+ n.total
802
+ ].every((e) => Number.isSafeInteger(e) && Number(e) >= 0)) throw Error("Invalid history metadata");
803
+ let r = t ? JSON.parse(t) : void 0, i = e.rows.filter((e) => e.sequence !== null).map((e) => {
804
+ if (typeof e.event != "string") throw Error("Invalid saved event");
805
+ let t = {
806
+ ...JSON.parse(e.event),
807
+ sequence: e.sequence
808
+ };
809
+ if (!Oe(t)) throw Error("Invalid saved event");
810
+ return t;
811
+ }), a = i.length > Y;
812
+ i.length = Math.min(i.length, Y);
813
+ let o = i.at(-1), s = r?.watermark ?? Number(n.watermark);
814
+ return {
815
+ epoch: n.generation,
816
+ cursor: Number(n.watermark),
817
+ capacity: Y,
818
+ dropped: 0,
819
+ evicted: 0,
820
+ records: i,
821
+ reset: !!r && (r.generation !== n.generation || r.pruned < Number(n.pruned)),
822
+ nextCursor: a && o ? JSON.stringify({
823
+ watermark: s,
824
+ sequence: o.sequence,
825
+ time: o.startedAtMs,
826
+ generation: n.generation,
827
+ pruned: Number(n.pruned)
828
+ }) : null
829
+ };
830
+ }
831
+ //#endregion
832
+ //#region src/request-history.ts
833
+ function je(e, n) {
834
+ let [r, o] = a(), [s, c] = a(!1), [l, u] = a(!1), d = i(() => {});
835
+ return t(() => {
836
+ if (o(void 0), u(!1), c(!1), !n) return;
837
+ let t = new AbortController(), r = !1;
838
+ d.current = (e) => {
839
+ r || t.signal.aborted || (r = !0, c(!0), u(!1), i(e));
840
+ };
841
+ async function i(i) {
842
+ try {
843
+ if (!e.query) throw Error("History is unavailable");
844
+ let r = Ae(await e.query(ke(n, i), t.signal), i);
845
+ if (t.signal.aborted) return;
846
+ o((e) => {
847
+ if (!i || !e || e.epoch !== r.epoch) return r;
848
+ let t = new Map(e.records.map((e) => [e.eventId ?? e.sequence, e]));
849
+ for (let e of r.records) t.set(e.eventId ?? e.sequence, e);
850
+ return {
851
+ ...r,
852
+ reset: e.reset || r.reset,
853
+ records: [...t.values()]
854
+ };
855
+ });
856
+ } catch {
857
+ t.signal.aborted || u(!0);
858
+ } finally {
859
+ r = !1, t.signal.aborted || c(!1);
860
+ }
861
+ }
862
+ return d.current(), () => t.abort();
863
+ }, [e, n]), {
864
+ page: r,
865
+ loading: s,
866
+ failed: l,
867
+ loadOlder: () => d.current(r?.nextCursor ?? void 0),
868
+ retry: () => d.current(r?.nextCursor ?? void 0)
869
+ };
870
+ }
871
+ //#endregion
872
+ //#region src/RequestObserver.tsx
873
+ function Me({ client: e, actor: n, timeRange: o, onTimeRangeChange: s }) {
874
+ let [c, l] = a(), [u, d] = a(I), f = o ?? u, g = s ?? d, _ = je(e, r(() => c ? {
875
+ ...c,
876
+ ...n,
877
+ ...L(f, Date.now())
878
+ } : void 0, [
879
+ c,
880
+ n?.actorName,
881
+ n?.actorId,
882
+ f
883
+ ])), { page: v, failed: y, retry: b } = be(e), [x, S] = a(), [E, D] = a(), O = i(null), k = i(null), A = n ? "h3" : "h1", j = c ? _.page : x ?? v, M = v ?? _.page, N = (j?.records ?? []).filter((e) => !n || e.actorName === n.actorName && e.actorId === n.actorId);
884
+ return t(() => {
885
+ S(void 0), l(void 0);
886
+ }, [
887
+ e,
888
+ n?.actorName,
889
+ n?.actorId
890
+ ]), t(() => D(void 0), [
891
+ e,
892
+ v?.epoch,
893
+ c,
894
+ n?.actorName,
895
+ n?.actorId
896
+ ]), /* @__PURE__ */ T("section", {
897
+ ref: O,
898
+ className: "la-observer la-requests",
899
+ "aria-label": "Request observer",
900
+ children: [
901
+ /* @__PURE__ */ T("div", {
902
+ className: "la-observer-toolbar",
903
+ children: [/* @__PURE__ */ T("div", { children: [/* @__PURE__ */ w(A, { children: "Requests" }), /* @__PURE__ */ w("p", { children: n ? "Method calls and WebSocket events for this instance." : "Method calls and WebSocket events, with time spent waiting and processing." })] }), /* @__PURE__ */ T("div", {
904
+ className: "la-request-actions",
905
+ children: [e.query && /* @__PURE__ */ T(C, { children: [/* @__PURE__ */ w(P, {
906
+ variant: c ? "outline" : "secondary",
907
+ "aria-pressed": !c,
908
+ onClick: () => {
909
+ l(void 0), S(void 0);
910
+ },
911
+ children: "Live"
912
+ }), /* @__PURE__ */ w(P, {
913
+ variant: c ? "secondary" : "outline",
914
+ "aria-pressed": !!c,
915
+ onClick: () => {
916
+ c || l({});
917
+ },
918
+ children: "History"
919
+ })] }), !c && /* @__PURE__ */ T(C, { children: [/* @__PURE__ */ T(P, {
920
+ variant: "outline",
921
+ disabled: !j,
922
+ onClick: () => S(x ? void 0 : v),
923
+ children: [w(x ? m : p, { "aria-hidden": "true" }), x ? "Resume" : "Pause"]
924
+ }), y && /* @__PURE__ */ T(P, {
925
+ variant: "outline",
926
+ onClick: b,
927
+ children: [/* @__PURE__ */ w(h, { "aria-hidden": "true" }), "Retry"]
928
+ })] })]
929
+ })]
930
+ }),
931
+ c && /* @__PURE__ */ w(Ne, {
932
+ query: c,
933
+ range: f,
934
+ onRangeChange: g,
935
+ loading: _.loading,
936
+ onSearch: l,
937
+ scoped: !!n
938
+ }),
939
+ c && _.failed && /* @__PURE__ */ T("div", {
940
+ className: "la-observer-error",
941
+ role: "alert",
942
+ children: [
943
+ "Request history unavailable.",
944
+ " ",
945
+ /* @__PURE__ */ w(P, {
946
+ variant: "outline",
947
+ onClick: _.retry,
948
+ children: "Retry history"
949
+ })
950
+ ]
951
+ }),
952
+ !c && y && /* @__PURE__ */ T("div", {
953
+ className: "la-observer-error",
954
+ role: "alert",
955
+ children: ["Request stream disconnected. Reconnecting… ", v ? "Showing the last received requests." : "Check your connection and runtime version."]
956
+ }),
957
+ !!M?.dropped && /* @__PURE__ */ T("div", {
958
+ className: "la-observer-error",
959
+ role: "alert",
960
+ children: [M.dropped.toLocaleString(), " request traces were not delivered. This history is incomplete."]
961
+ }),
962
+ M?.persistenceFailed && /* @__PURE__ */ w("div", {
963
+ className: "la-observer-error",
964
+ role: "alert",
965
+ children: "Some request events could not be saved. This history may be incomplete."
966
+ }),
967
+ j?.reset && /* @__PURE__ */ w("div", {
968
+ className: "la-observer-error",
969
+ role: "alert",
970
+ children: "Some older events are no longer retained. Showing available history."
971
+ }),
972
+ /* @__PURE__ */ T("div", {
973
+ className: "la-observer-table-frame",
974
+ children: [/* @__PURE__ */ T(H, {
975
+ "aria-label": c ? "Saved requests" : "Recent requests",
976
+ className: "la-request-table",
977
+ children: [/* @__PURE__ */ w(U, { children: /* @__PURE__ */ T(G, { children: [
978
+ /* @__PURE__ */ w(K, {
979
+ scope: "col",
980
+ children: "Time"
981
+ }),
982
+ /* @__PURE__ */ w(K, {
983
+ scope: "col",
984
+ children: "Request"
985
+ }),
986
+ /* @__PURE__ */ w(K, {
987
+ scope: "col",
988
+ children: "Instance"
989
+ }),
990
+ /* @__PURE__ */ w(K, {
991
+ scope: "col",
992
+ children: "Transport"
993
+ }),
994
+ /* @__PURE__ */ w(K, {
995
+ scope: "col",
996
+ children: "Outcome"
997
+ }),
998
+ /* @__PURE__ */ w(K, {
999
+ scope: "col",
1000
+ children: "Total"
1001
+ }),
1002
+ /* @__PURE__ */ w(K, {
1003
+ scope: "col",
1004
+ children: "Queue wait"
1005
+ }),
1006
+ /* @__PURE__ */ w(K, {
1007
+ scope: "col",
1008
+ children: /* @__PURE__ */ w("span", {
1009
+ className: "la:sr-only",
1010
+ children: "Details"
1011
+ })
1012
+ })
1013
+ ] }) }), /* @__PURE__ */ w(W, { children: N.map((e) => /* @__PURE__ */ T(G, {
1014
+ className: "la-clickable-row",
1015
+ "data-state": E === e ? "selected" : void 0,
1016
+ onClick: (t) => {
1017
+ k.current = t.currentTarget.querySelector("button"), D(e);
1018
+ },
1019
+ children: [
1020
+ /* @__PURE__ */ w(q, { children: /* @__PURE__ */ w("time", {
1021
+ dateTime: new Date(e.startedAtMs).toISOString(),
1022
+ title: new Date(e.startedAtMs).toLocaleString(),
1023
+ children: c ? new Date(e.startedAtMs).toLocaleString([], { hour12: !1 }) : new Date(e.startedAtMs).toLocaleTimeString([], { hour12: !1 })
1024
+ }) }),
1025
+ /* @__PURE__ */ w(q, { children: /* @__PURE__ */ w("span", {
1026
+ className: "la-request-operation",
1027
+ title: e.operation,
1028
+ children: e.operation
1029
+ }) }),
1030
+ /* @__PURE__ */ w(q, { children: /* @__PURE__ */ T("span", {
1031
+ className: "la-request-actor",
1032
+ title: `${e.actorName} / ${e.actorId}`,
1033
+ children: [
1034
+ e.actorName,
1035
+ " / ",
1036
+ e.actorId
1037
+ ]
1038
+ }) }),
1039
+ /* @__PURE__ */ w(q, { children: e.kind === "method" ? "Method" : "WebSocket" }),
1040
+ /* @__PURE__ */ w(q, { children: /* @__PURE__ */ w(V, {
1041
+ variant: "outline",
1042
+ className: `la-request-outcome-${e.outcome}`,
1043
+ children: e.outcome[0].toUpperCase() + e.outcome.slice(1)
1044
+ }) }),
1045
+ /* @__PURE__ */ w(q, { children: X(e.durationMs) }),
1046
+ /* @__PURE__ */ w(q, { children: e.queueWaitMs === null ? /* @__PURE__ */ w("span", {
1047
+ title: "Request did not begin processing",
1048
+ children: "—"
1049
+ }) : X(e.queueWaitMs) }),
1050
+ /* @__PURE__ */ w(q, { children: /* @__PURE__ */ w(P, {
1051
+ variant: "ghost",
1052
+ size: "sm",
1053
+ "aria-label": `Inspect ${e.operation} request`,
1054
+ "aria-haspopup": "dialog",
1055
+ children: "Details"
1056
+ }) })
1057
+ ]
1058
+ }, e.eventId ?? `${j.epoch}-${e.sequence}`)) })]
1059
+ }), !N.length && /* @__PURE__ */ T("div", {
1060
+ className: "la-request-empty",
1061
+ role: "status",
1062
+ children: [/* @__PURE__ */ w("strong", { children: c ? _.loading ? "Loading history…" : _.failed ? "History unavailable" : "No saved requests in this range" : j ? "No requests yet" : y ? "Requests unavailable" : "Connecting to requests…" }), /* @__PURE__ */ w("p", { children: c ? "Try a wider time range or fewer filters. Local history retains the latest 10,000 events." : "Call an actor method or send a WebSocket message to see its timings." })]
1063
+ })]
1064
+ }),
1065
+ c && j?.nextCursor && /* @__PURE__ */ w(P, {
1066
+ className: "la-request-load-older",
1067
+ variant: "outline",
1068
+ disabled: _.loading,
1069
+ onClick: _.loadOlder,
1070
+ children: _.loading ? "Loading…" : "Load older"
1071
+ }),
1072
+ /* @__PURE__ */ T("div", {
1073
+ className: "la-observer-footnote",
1074
+ children: [/* @__PURE__ */ T("span", {
1075
+ className: "la-observer-refresh-status",
1076
+ children: [!c && /* @__PURE__ */ w("span", { className: `la-observer-dot ${y ? "la-observer-dot-unknown" : "la-observer-dot-live"}` }), c ? "Saved history" : x ? "Display paused · collection continues" : y ? "Reconnecting…" : v ? "Live updates" : "Connecting…"]
1077
+ }), /* @__PURE__ */ w("span", { children: c ? `${N.length.toLocaleString()} saved requests shown` : n ? `${N.length} matching requests from the latest ${j?.capacity ?? 500} on this control plane.` : `Latest ${j?.capacity ?? 500} requests on this control plane.` })]
1078
+ }),
1079
+ !c && !!j?.evicted && /* @__PURE__ */ T("p", {
1080
+ className: "la-request-note",
1081
+ children: [j.evicted.toLocaleString(), " older records have left this history window."]
1082
+ }),
1083
+ /* @__PURE__ */ w("p", {
1084
+ className: "la-request-note",
1085
+ children: "Total includes queue wait, actor processing, and persistence. Queue wait includes the WebSocket message queue. Timings exclude the caller’s network round trip."
1086
+ }),
1087
+ /* @__PURE__ */ w(he, {
1088
+ open: !!E,
1089
+ onOpenChange: (e) => {
1090
+ e || D(void 0);
1091
+ },
1092
+ children: /* @__PURE__ */ T(ve, {
1093
+ container: O.current,
1094
+ onCloseAutoFocus: (e) => {
1095
+ e.preventDefault(), k.current?.focus();
1096
+ },
1097
+ children: [
1098
+ /* @__PURE__ */ w(ge, { children: "Request details" }),
1099
+ /* @__PURE__ */ w(_e, { children: "Full identifiers and timings for this request." }),
1100
+ E && /* @__PURE__ */ w(Pe, { record: E })
1101
+ ]
1102
+ })
1103
+ })
1104
+ ]
1105
+ });
1106
+ }
1107
+ function Ne({ query: e, range: t, onRangeChange: n, loading: r, onSearch: i, scoped: a }) {
1108
+ return /* @__PURE__ */ T("form", {
1109
+ className: "la-request-history-filters",
1110
+ onSubmit: (e) => {
1111
+ e.preventDefault();
1112
+ let t = new FormData(e.currentTarget);
1113
+ i({
1114
+ actorId: String(t.get("actorId") || "").trim() || void 0,
1115
+ outcome: String(t.get("outcome") || "") || void 0
1116
+ });
1117
+ },
1118
+ children: [
1119
+ /* @__PURE__ */ T("div", {
1120
+ className: "la-request-history-range",
1121
+ children: [/* @__PURE__ */ w("span", { children: "Time range" }), /* @__PURE__ */ w(B, {
1122
+ value: t,
1123
+ onChange: n,
1124
+ align: "start"
1125
+ })]
1126
+ }),
1127
+ !a && /* @__PURE__ */ T("label", { children: ["Actor ID", /* @__PURE__ */ w(F, {
1128
+ name: "actorId",
1129
+ placeholder: "All actors",
1130
+ maxLength: 256,
1131
+ defaultValue: e.actorId
1132
+ })] }),
1133
+ /* @__PURE__ */ T("label", { children: ["Outcome", /* @__PURE__ */ T("select", {
1134
+ className: "la-observer-select",
1135
+ name: "outcome",
1136
+ defaultValue: e.outcome ?? "",
1137
+ children: [/* @__PURE__ */ w("option", {
1138
+ value: "",
1139
+ children: "All outcomes"
1140
+ }), [
1141
+ "completed",
1142
+ "failed",
1143
+ "rejected",
1144
+ "rerouted",
1145
+ "interrupted"
1146
+ ].map((e) => /* @__PURE__ */ w("option", {
1147
+ value: e,
1148
+ children: e[0].toUpperCase() + e.slice(1)
1149
+ }, e))]
1150
+ })] }),
1151
+ /* @__PURE__ */ w(P, {
1152
+ type: "submit",
1153
+ variant: "outline",
1154
+ disabled: r,
1155
+ children: "Search"
1156
+ })
1157
+ ]
1158
+ });
1159
+ }
1160
+ function Pe({ record: e }) {
1161
+ let t = {
1162
+ Operation: e.operation,
1163
+ "Actor class": e.actorName,
1164
+ "Instance ID": e.actorId,
1165
+ "Request ID": e.requestId,
1166
+ Time: new Date(e.startedAtMs).toLocaleString(),
1167
+ Transport: e.kind === "method" ? "Method" : "WebSocket",
1168
+ Outcome: e.outcome,
1169
+ Total: X(e.durationMs),
1170
+ "Queue wait": e.queueWaitMs === null ? "Did not begin processing" : X(e.queueWaitMs),
1171
+ Host: e.hostId,
1172
+ ...e.connectionId ? { Connection: e.connectionId } : {}
1173
+ };
1174
+ return /* @__PURE__ */ w("dl", {
1175
+ className: "la-request-details",
1176
+ children: Object.entries(t).map(([e, t]) => /* @__PURE__ */ T("div", { children: [/* @__PURE__ */ w("dt", { children: e }), /* @__PURE__ */ w("dd", { children: t })] }, e))
1177
+ });
1178
+ }
1179
+ function X(e) {
1180
+ return e >= 1e3 ? `${(e / 1e3).toLocaleString(void 0, { maximumFractionDigits: 2 })} s` : `${e.toLocaleString(void 0, { maximumFractionDigits: 1 })} ms`;
1181
+ }
1182
+ //#endregion
1183
+ //#region src/queue-wait.ts
1184
+ function Fe(e, t) {
1185
+ let n = ["queue_wait_ms IS NOT NULL", "outcome <> 'rerouted'"], r = [];
1186
+ return e.fromMs !== void 0 && (n.push("started_at_ms >= ?"), r.push(e.fromMs)), e.toMs !== void 0 && (n.push("started_at_ms <= ?"), r.push(e.toMs)), t !== void 0 && (n.push("actor_name = ?"), r.push(t)), {
1187
+ sql: `SELECT actor_name, actor_id, COUNT(*) AS admitted, AVG(queue_wait_ms) AS average_ms, MAX(queue_wait_ms) AS max_ms
1188
+ FROM request_events
1189
+ WHERE ${n.join(" AND ")}
1190
+ GROUP BY actor_name, actor_id
1191
+ ORDER BY admitted DESC, actor_name, actor_id
1192
+ LIMIT 500`,
1193
+ params: r
1194
+ };
1195
+ }
1196
+ function Ie(e) {
1197
+ return e.rows.map((e) => {
1198
+ let t = {
1199
+ actorName: e.actor_name,
1200
+ actorId: e.actor_id,
1201
+ admitted: e.admitted,
1202
+ averageMs: e.average_ms,
1203
+ maxMs: e.max_ms
1204
+ };
1205
+ if (typeof t.actorName != "string" || typeof t.actorId != "string" || !Number.isSafeInteger(t.admitted) || Number(t.admitted) <= 0 || ![t.averageMs, t.maxMs].every((e) => typeof e == "number" && Number.isFinite(e) && e >= 0)) throw Error("Invalid queue wait row");
1206
+ return t;
1207
+ });
1208
+ }
1209
+ function Le(e) {
1210
+ return Q(e, () => "all").get("all") ?? null;
1211
+ }
1212
+ function Re(e) {
1213
+ return Q(e, (e) => e.actorName);
1214
+ }
1215
+ function ze(e, t) {
1216
+ return Q(e.filter((e) => e.actorName === t), (e) => e.actorId);
1217
+ }
1218
+ function Z(e) {
1219
+ return e === void 0 ? "—" : e >= 1e3 ? `${(e / 1e3).toLocaleString(void 0, { maximumFractionDigits: 2 })} s` : `${e.toLocaleString(void 0, { maximumFractionDigits: 1 })} ms`;
1220
+ }
1221
+ function Q(e, t) {
1222
+ let n = /* @__PURE__ */ new Map();
1223
+ for (let r of e) {
1224
+ let e = n.get(t(r)) ?? {
1225
+ admitted: 0,
1226
+ averageMs: 0,
1227
+ maxMs: 0
1228
+ }, i = e.admitted + r.admitted;
1229
+ n.set(t(r), {
1230
+ admitted: i,
1231
+ averageMs: (e.averageMs * e.admitted + r.averageMs * r.admitted) / i,
1232
+ maxMs: Math.max(e.maxMs, r.maxMs)
1233
+ });
1234
+ }
1235
+ return n;
1236
+ }
1237
+ //#endregion
1238
+ //#region src/queue-wait-history.ts
1239
+ function Be(e, t, n) {
1240
+ let r = Se(e, Fe(t, n), Ie);
1241
+ return {
1242
+ supported: r.supported,
1243
+ rows: r.value,
1244
+ failed: r.failed
1245
+ };
1246
+ }
1247
+ //#endregion
1248
+ //#region src/ActorObserver.tsx
1249
+ function Ve({ client: e, className: r = "", initialActorName: o, navigation: s, timeRange: c, onTimeRangeChange: l }) {
1250
+ let { inventory: u, loading: d, failed: p, retry: m } = ye(e), [g, _] = a(I), v = c ?? g, y = l ?? _, [b, x] = a(o), S = s ? s.actorName : b, E = s ? s.onSelectActor : x, [D, O] = a(""), k = i(null), A = i(o), j = n(), M = u?.actors.find((e) => e.actorName === S), N = Be(e, L(v, Date.now()), S), ee = N.rows && Re(N.rows), te = N.rows && S !== void 0 ? ze(N.rows, S) : void 0, F = N.supported && N.rows ? Le(N.rows) : void 0;
1251
+ return t(() => {
1252
+ x(o), O("");
1253
+ }, [e, o]), t(() => {
1254
+ A.current !== S && k.current?.focus(), A.current = S;
1255
+ }, [S]), /* @__PURE__ */ T("section", {
1256
+ className: `la-observer ${r}`,
1257
+ "aria-label": "Actor observer",
1258
+ children: [
1259
+ S !== void 0 && /* @__PURE__ */ T("nav", {
1260
+ className: "la-observer-breadcrumb",
1261
+ "aria-label": "Breadcrumb",
1262
+ children: [
1263
+ /* @__PURE__ */ w(P, {
1264
+ variant: "link",
1265
+ type: "button",
1266
+ "aria-label": "Back to actors",
1267
+ onClick: () => E(void 0),
1268
+ children: "Actors"
1269
+ }),
1270
+ /* @__PURE__ */ w("span", {
1271
+ "aria-hidden": "true",
1272
+ children: "/"
1273
+ }),
1274
+ /* @__PURE__ */ w("span", {
1275
+ "aria-current": "page",
1276
+ children: S
1277
+ })
1278
+ ]
1279
+ }),
1280
+ /* @__PURE__ */ T("div", {
1281
+ className: "la-observer-toolbar",
1282
+ children: [/* @__PURE__ */ T("div", { children: [/* @__PURE__ */ w("div", {
1283
+ className: "la-observer-title",
1284
+ children: /* @__PURE__ */ w("h1", {
1285
+ ref: k,
1286
+ tabIndex: -1,
1287
+ children: S ?? "Actors"
1288
+ })
1289
+ }), /* @__PURE__ */ w("p", { children: S === void 0 ? "Inspect instances, residency, and connections." : "Inspect this actor class’s instances, residency, and connections." })] }), /* @__PURE__ */ T("div", {
1290
+ className: "la-observer-actions",
1291
+ children: [N.supported && /* @__PURE__ */ w(B, {
1292
+ value: v,
1293
+ onChange: y
1294
+ }), /* @__PURE__ */ T(P, {
1295
+ variant: "outline",
1296
+ type: "button",
1297
+ disabled: d,
1298
+ onClick: m,
1299
+ children: [/* @__PURE__ */ w(h, {
1300
+ "aria-hidden": "true",
1301
+ className: d ? "la-observer-spin" : void 0
1302
+ }), d ? "Refreshing…" : p ? "Try again" : "Refresh"]
1303
+ })]
1304
+ })]
1305
+ }),
1306
+ p && /* @__PURE__ */ T("div", {
1307
+ className: "la-observer-error",
1308
+ role: "alert",
1309
+ children: [/* @__PURE__ */ w(f, { "aria-hidden": "true" }), /* @__PURE__ */ w("p", { children: u ? "Could not refresh. These counts may be out of date." : "Could not load actors. Check your connection and access, then try again." })]
1310
+ }),
1311
+ !u && !p && /* @__PURE__ */ w(He, {}),
1312
+ u && /* @__PURE__ */ T(C, { children: [S === void 0 ? /* @__PURE__ */ T(C, { children: [/* @__PURE__ */ w(Ue, {
1313
+ inventory: u,
1314
+ queueWait: N.supported ? F ?? null : void 0,
1315
+ range: v
1316
+ }), u.actors.length ? /* @__PURE__ */ w(We, {
1317
+ inventory: u,
1318
+ query: D,
1319
+ onQueryChange: O,
1320
+ onSelectActor: E,
1321
+ waits: N.supported ? ee : void 0
1322
+ }) : /* @__PURE__ */ w($, {
1323
+ title: "No actors yet",
1324
+ description: "Deploy your actor classes to see them here. Instance counts appear as actors are used."
1325
+ })] }) : M ? /* @__PURE__ */ T(C, { children: [/* @__PURE__ */ w(Ue, {
1326
+ inventory: { actors: [M] },
1327
+ actorName: S,
1328
+ queueWait: N.supported ? F ?? null : void 0,
1329
+ range: v
1330
+ }), /* @__PURE__ */ w(Ge, {
1331
+ client: e,
1332
+ id: j,
1333
+ actorName: S,
1334
+ instances: M.instances,
1335
+ waits: N.supported ? te : void 0,
1336
+ range: v
1337
+ }, S)] }) : /* @__PURE__ */ w($, {
1338
+ title: "Actor class unavailable",
1339
+ description: "This actor class is no longer in the latest inventory. Return to Actors to see available classes."
1340
+ }), /* @__PURE__ */ T("div", {
1341
+ className: "la-observer-footnote",
1342
+ children: [/* @__PURE__ */ T("span", {
1343
+ className: "la-observer-refresh-status",
1344
+ children: [/* @__PURE__ */ w("span", { className: `la-observer-dot ${p ? "la-observer-dot-unknown" : e.watchActors ? "la-observer-dot-live" : ""}` }), p ? "Reconnecting…" : e.watchActors ? "Live updates" : "Auto-refresh every 5s"]
1345
+ }), /* @__PURE__ */ w("span", { children: e.watchActors ? "Changes stream from the control plane." : "Counts follow the latest host heartbeat." })]
1346
+ })] })
1347
+ ]
1348
+ });
1349
+ }
1350
+ function He() {
1351
+ return /* @__PURE__ */ T("div", {
1352
+ className: "la-observer-skeleton",
1353
+ role: "status",
1354
+ "aria-label": "Loading actors",
1355
+ children: [
1356
+ /* @__PURE__ */ w("span", {
1357
+ className: "la:sr-only",
1358
+ children: "Loading actors…"
1359
+ }),
1360
+ /* @__PURE__ */ w("div", {}),
1361
+ /* @__PURE__ */ w("div", {}),
1362
+ /* @__PURE__ */ w("div", {})
1363
+ ]
1364
+ });
1365
+ }
1366
+ function Ue({ inventory: e, actorName: t, queueWait: n, range: r }) {
1367
+ let i = e.actors.reduce((e, t) => ({
1368
+ live: e.live + t.live,
1369
+ dormant: e.dormant + t.dormant,
1370
+ unknown: e.unknown + t.unknown
1371
+ }), {
1372
+ live: 0,
1373
+ dormant: 0,
1374
+ unknown: 0
1375
+ });
1376
+ return /* @__PURE__ */ T("dl", {
1377
+ className: "la-observer-summary",
1378
+ children: [
1379
+ /* @__PURE__ */ T("div", { children: [
1380
+ /* @__PURE__ */ w("dt", { children: "Total instances" }),
1381
+ /* @__PURE__ */ w("dd", {
1382
+ "aria-label": "Total instances",
1383
+ children: (i.live + i.dormant + i.unknown).toLocaleString()
1384
+ }),
1385
+ /* @__PURE__ */ w("p", { children: t === void 0 ? `${e.actors.length} actor ${e.actors.length === 1 ? "type" : "types"}` : "In this actor class" })
1386
+ ] }),
1387
+ /* @__PURE__ */ T("div", { children: [
1388
+ /* @__PURE__ */ T("dt", { children: [/* @__PURE__ */ w("span", { className: "la-observer-dot la-observer-dot-live" }), "Live"] }),
1389
+ /* @__PURE__ */ w("dd", {
1390
+ "aria-label": "Live instances",
1391
+ children: i.live.toLocaleString()
1392
+ }),
1393
+ /* @__PURE__ */ w("p", { children: "Loaded in memory" })
1394
+ ] }),
1395
+ /* @__PURE__ */ T("div", { children: [
1396
+ /* @__PURE__ */ T("dt", { children: [/* @__PURE__ */ w("span", { className: "la-observer-dot" }), "Dormant"] }),
1397
+ /* @__PURE__ */ w("dd", {
1398
+ "aria-label": "Dormant instances",
1399
+ children: i.dormant.toLocaleString()
1400
+ }),
1401
+ /* @__PURE__ */ w("p", { children: "Currently unloaded" })
1402
+ ] }),
1403
+ i.unknown > 0 && /* @__PURE__ */ T("div", { children: [
1404
+ /* @__PURE__ */ T("dt", { children: [/* @__PURE__ */ w("span", { className: "la-observer-dot la-observer-dot-unknown" }), "Unknown"] }),
1405
+ /* @__PURE__ */ w("dd", {
1406
+ "aria-label": "Unknown instances",
1407
+ children: i.unknown.toLocaleString()
1408
+ }),
1409
+ /* @__PURE__ */ w("p", { children: "Awaiting host report" })
1410
+ ] }),
1411
+ n !== void 0 && /* @__PURE__ */ T("div", {
1412
+ className: "la-observer-queue-wait",
1413
+ children: [
1414
+ /* @__PURE__ */ w("dt", { children: "Avg queue wait" }),
1415
+ /* @__PURE__ */ w("dd", {
1416
+ "aria-label": "Average queue wait",
1417
+ children: Z(n?.averageMs)
1418
+ }),
1419
+ /* @__PURE__ */ w("p", { children: n ? `Max ${Z(n.maxMs)} · ${n.admitted.toLocaleString()} admitted ${z(r)}` : `No admitted requests ${z(r)}` })
1420
+ ]
1421
+ })
1422
+ ]
1423
+ });
1424
+ }
1425
+ function We({ inventory: e, query: t, onQueryChange: n, onSelectActor: r, waits: i }) {
1426
+ let a = e.actors.some((e) => e.unknown > 0), s = e.actors.filter((e) => Qe(e.actorName, t)).sort((e, t) => Number(t.live > 0) - Number(e.live > 0));
1427
+ return /* @__PURE__ */ T(C, { children: [
1428
+ /* @__PURE__ */ T("div", {
1429
+ className: "la-observer-list-toolbar",
1430
+ children: [/* @__PURE__ */ T("h2", { children: ["Actor names ", /* @__PURE__ */ w(V, { children: e.actors.length })] }), /* @__PURE__ */ w(Ze, {
1431
+ label: "Search actors",
1432
+ placeholder: "Search actors…",
1433
+ value: t,
1434
+ onChange: n
1435
+ })]
1436
+ }),
1437
+ /* @__PURE__ */ w("div", {
1438
+ className: "la-observer-table-frame",
1439
+ children: s.length ? /* @__PURE__ */ T(H, {
1440
+ "aria-label": "Actor instance counts",
1441
+ className: "la-observer-table",
1442
+ children: [/* @__PURE__ */ w(U, { children: /* @__PURE__ */ T(G, { children: [
1443
+ /* @__PURE__ */ w(K, {
1444
+ scope: "col",
1445
+ children: "Actor"
1446
+ }),
1447
+ /* @__PURE__ */ w(K, {
1448
+ scope: "col",
1449
+ children: "Live"
1450
+ }),
1451
+ /* @__PURE__ */ w(K, {
1452
+ scope: "col",
1453
+ children: "Dormant"
1454
+ }),
1455
+ a && /* @__PURE__ */ w(K, {
1456
+ scope: "col",
1457
+ children: "Unknown"
1458
+ }),
1459
+ /* @__PURE__ */ w(K, {
1460
+ scope: "col",
1461
+ children: "Total"
1462
+ }),
1463
+ i && /* @__PURE__ */ w(K, {
1464
+ scope: "col",
1465
+ className: "la-observer-wait-cell",
1466
+ children: "Avg queue wait"
1467
+ })
1468
+ ] }) }), /* @__PURE__ */ w(W, { children: s.map((e) => /* @__PURE__ */ T(G, {
1469
+ className: "la-clickable-row",
1470
+ onClick: () => r(e.actorName),
1471
+ children: [
1472
+ /* @__PURE__ */ w(q, {
1473
+ className: "la-observer-name",
1474
+ children: /* @__PURE__ */ T(P, {
1475
+ variant: "ghost",
1476
+ type: "button",
1477
+ className: "la-observer-actor-button la-observer-class-button",
1478
+ children: [/* @__PURE__ */ w(o, {
1479
+ className: "la-observer-type-icon",
1480
+ "aria-hidden": "true"
1481
+ }), /* @__PURE__ */ w("span", { children: e.actorName })]
1482
+ })
1483
+ }),
1484
+ /* @__PURE__ */ w(q, { children: /* @__PURE__ */ w("span", {
1485
+ className: e.live > 0 ? "la-observer-live" : void 0,
1486
+ children: e.live.toLocaleString()
1487
+ }) }),
1488
+ /* @__PURE__ */ w(q, { children: e.dormant.toLocaleString() }),
1489
+ a && /* @__PURE__ */ w(q, { children: e.unknown.toLocaleString() }),
1490
+ /* @__PURE__ */ w(q, { children: (e.live + e.dormant + e.unknown).toLocaleString() }),
1491
+ i && /* @__PURE__ */ w(q, {
1492
+ className: "la-observer-wait-cell",
1493
+ children: /* @__PURE__ */ w(Ke, { stats: i.get(e.actorName) })
1494
+ })
1495
+ ]
1496
+ }, e.actorName)) })]
1497
+ }) : /* @__PURE__ */ w($, {
1498
+ title: "No matching actors",
1499
+ description: "Try a different actor name.",
1500
+ action: "Clear search",
1501
+ onReset: () => n("")
1502
+ })
1503
+ }),
1504
+ a && /* @__PURE__ */ T("p", {
1505
+ className: "la-observer-unknown",
1506
+ children: [/* @__PURE__ */ w(f, { "aria-hidden": "true" }), "Some hosts have not reported which instances are loaded. Their counts are shown as unknown."]
1507
+ })
1508
+ ] });
1509
+ }
1510
+ function Ge({ client: e, id: n, actorName: r, instances: o, waits: s, range: c }) {
1511
+ let [l, u] = a(""), [d, f] = a("all"), [p, m] = a(), h = `${n}-connections`, g = o.filter((e) => Qe(e.actorId, l) && (d === "all" || e.status === d));
1512
+ g.sort((e, t) => Number(t.status === "live") - Number(e.status === "live"));
1513
+ let _ = o.find((e) => e.actorId === p), v = i(null);
1514
+ return t(() => {
1515
+ v.current?.focus();
1516
+ }, [p]), p === void 0 ? /* @__PURE__ */ T("section", {
1517
+ id: n,
1518
+ className: "la-observer-instances",
1519
+ "aria-labelledby": `${n}-heading`,
1520
+ children: [/* @__PURE__ */ w("div", {
1521
+ className: "la-observer-instances-heading",
1522
+ children: /* @__PURE__ */ T("div", { children: [/* @__PURE__ */ T("h2", {
1523
+ ref: v,
1524
+ tabIndex: -1,
1525
+ id: `${n}-heading`,
1526
+ children: [
1527
+ r,
1528
+ " instances ",
1529
+ /* @__PURE__ */ w(V, {
1530
+ "aria-hidden": "true",
1531
+ children: o.length.toLocaleString()
1532
+ })
1533
+ ]
1534
+ }), /* @__PURE__ */ w("p", { children: "Select an instance to inspect its waiting line, requests, and WebSocket connections." })] })
1535
+ }), o.length ? /* @__PURE__ */ T(C, { children: [
1536
+ /* @__PURE__ */ T("div", {
1537
+ className: "la-observer-filters",
1538
+ children: [/* @__PURE__ */ w(Ze, {
1539
+ label: "Search instances",
1540
+ placeholder: "Search instance IDs…",
1541
+ value: l,
1542
+ onChange: u
1543
+ }), /* @__PURE__ */ T("select", {
1544
+ className: "la-observer-select",
1545
+ "aria-label": "Instance state",
1546
+ value: d,
1547
+ onChange: (e) => f(e.target.value),
1548
+ children: [
1549
+ /* @__PURE__ */ w("option", {
1550
+ value: "all",
1551
+ children: "All states"
1552
+ }),
1553
+ /* @__PURE__ */ w("option", {
1554
+ value: "live",
1555
+ children: "Live"
1556
+ }),
1557
+ /* @__PURE__ */ w("option", {
1558
+ value: "dormant",
1559
+ children: "Dormant"
1560
+ }),
1561
+ /* @__PURE__ */ w("option", {
1562
+ value: "unknown",
1563
+ children: "Unknown"
1564
+ })
1565
+ ]
1566
+ })]
1567
+ }),
1568
+ /* @__PURE__ */ w("div", {
1569
+ className: "la-observer-table-frame",
1570
+ children: g.length ? /* @__PURE__ */ T(H, {
1571
+ "aria-label": `${r} instances`,
1572
+ className: "la-observer-instance-table",
1573
+ children: [/* @__PURE__ */ w(U, { children: /* @__PURE__ */ T(G, { children: [
1574
+ /* @__PURE__ */ w(K, {
1575
+ scope: "col",
1576
+ children: "Instance"
1577
+ }),
1578
+ /* @__PURE__ */ w(K, {
1579
+ scope: "col",
1580
+ children: "State"
1581
+ }),
1582
+ /* @__PURE__ */ w(K, {
1583
+ scope: "col",
1584
+ children: "Connections"
1585
+ }),
1586
+ s && /* @__PURE__ */ w(K, {
1587
+ scope: "col",
1588
+ className: "la-observer-wait-cell",
1589
+ children: "Avg queue wait"
1590
+ }),
1591
+ /* @__PURE__ */ w(K, {
1592
+ scope: "col",
1593
+ className: "la-observer-waiting-cell",
1594
+ children: "Waiting"
1595
+ })
1596
+ ] }) }), /* @__PURE__ */ w(W, { children: g.map((e) => /* @__PURE__ */ T(G, {
1597
+ className: "la-clickable-row",
1598
+ onClick: () => m(e.actorId),
1599
+ children: [
1600
+ /* @__PURE__ */ w(q, {
1601
+ className: "la-observer-instance-id",
1602
+ children: /* @__PURE__ */ w(P, {
1603
+ variant: "ghost",
1604
+ type: "button",
1605
+ className: "la-observer-actor-button",
1606
+ children: /* @__PURE__ */ w("span", { children: e.actorId })
1607
+ })
1608
+ }),
1609
+ /* @__PURE__ */ w(q, { children: /* @__PURE__ */ T(V, {
1610
+ variant: "outline",
1611
+ className: `la-observer-status-${e.status}`,
1612
+ children: [/* @__PURE__ */ w("span", { className: `la-observer-dot la-observer-dot-${e.status}` }), $e(e.status)]
1613
+ }) }),
1614
+ /* @__PURE__ */ w(q, { children: e.connections.length.toLocaleString() }),
1615
+ s && /* @__PURE__ */ w(q, {
1616
+ className: "la-observer-wait-cell",
1617
+ children: /* @__PURE__ */ w(Ke, { stats: s.get(e.actorId) })
1618
+ }),
1619
+ /* @__PURE__ */ w(q, {
1620
+ className: "la-observer-waiting-cell",
1621
+ children: /* @__PURE__ */ w(Ye, {
1622
+ waiting: e.waiting,
1623
+ compact: !0
1624
+ })
1625
+ })
1626
+ ]
1627
+ }, e.actorId)) })]
1628
+ }) : /* @__PURE__ */ w($, {
1629
+ title: "No matching instances",
1630
+ description: "Try another instance ID or state.",
1631
+ action: "Clear filters",
1632
+ onReset: () => {
1633
+ u(""), f("all");
1634
+ }
1635
+ })
1636
+ }),
1637
+ /* @__PURE__ */ w("p", {
1638
+ className: "la-observer-connection-note",
1639
+ children: "Connections are active WebSocket connections, not unique people."
1640
+ })
1641
+ ] }) : /* @__PURE__ */ T("p", {
1642
+ className: "la-observer-instance-empty",
1643
+ role: "status",
1644
+ children: [
1645
+ "No ",
1646
+ r,
1647
+ " instances have been created yet."
1648
+ ]
1649
+ })]
1650
+ }) : /* @__PURE__ */ T("section", {
1651
+ className: "la-observer-instance-detail",
1652
+ "aria-label": `${r} / ${p}`,
1653
+ children: [
1654
+ /* @__PURE__ */ w(P, {
1655
+ variant: "link",
1656
+ "aria-label": "Back to instances",
1657
+ onClick: () => m(void 0),
1658
+ children: "Back to instances"
1659
+ }),
1660
+ /* @__PURE__ */ T("div", {
1661
+ className: "la-observer-instance-heading",
1662
+ children: [/* @__PURE__ */ w("h2", {
1663
+ ref: v,
1664
+ tabIndex: -1,
1665
+ children: p
1666
+ }), _ && /* @__PURE__ */ w(V, {
1667
+ variant: "outline",
1668
+ className: `la-observer-status-${_.status}`,
1669
+ children: $e(_.status)
1670
+ })]
1671
+ }),
1672
+ !_ && /* @__PURE__ */ w("p", {
1673
+ role: "status",
1674
+ children: "This instance is no longer in the current inventory. Its retained requests are still available below."
1675
+ }),
1676
+ s && /* @__PURE__ */ w(qe, {
1677
+ stats: s.get(p),
1678
+ range: c
1679
+ }),
1680
+ _ && /* @__PURE__ */ w(Je, { waiting: _.waiting }),
1681
+ e.watchRequests || e.query ? /* @__PURE__ */ w(Me, {
1682
+ client: e,
1683
+ actor: {
1684
+ actorName: r,
1685
+ actorId: p
1686
+ },
1687
+ timeRange: c
1688
+ }, p) : /* @__PURE__ */ T("section", { children: [/* @__PURE__ */ w("h3", { children: "Requests" }), /* @__PURE__ */ w("p", { children: "Request timings are unavailable for this connection." })] }),
1689
+ _ && /* @__PURE__ */ w(Xe, {
1690
+ id: h,
1691
+ actorId: _.actorId,
1692
+ connections: _.connections
1693
+ })
1694
+ ]
1695
+ });
1696
+ }
1697
+ function Ke({ stats: e }) {
1698
+ return e ? /* @__PURE__ */ T("span", {
1699
+ className: "la-observer-wait",
1700
+ title: `Average of ${e.admitted.toLocaleString()} admitted requests in the selected time range; longest wait ${Z(e.maxMs)}`,
1701
+ children: [Z(e.averageMs), /* @__PURE__ */ T("small", { children: ["max ", Z(e.maxMs)] })]
1702
+ }) : /* @__PURE__ */ w("span", {
1703
+ title: "No admitted requests in the selected time range",
1704
+ children: "—"
1705
+ });
1706
+ }
1707
+ function qe({ stats: e, range: t }) {
1708
+ return /* @__PURE__ */ T("section", {
1709
+ className: "la-observer-queue-wait-detail",
1710
+ "aria-label": "Queue wait",
1711
+ children: [
1712
+ /* @__PURE__ */ w("h3", { children: "Queue wait" }),
1713
+ /* @__PURE__ */ w("p", { children: e ? `Time requests spent waiting to enter this actor ${z(t)}.` : `No requests were admitted to this actor ${z(t)}.` }),
1714
+ e && /* @__PURE__ */ T("dl", {
1715
+ className: "la-observer-summary la-observer-summary-compact",
1716
+ children: [
1717
+ /* @__PURE__ */ T("div", { children: [
1718
+ /* @__PURE__ */ w("dt", { children: "Average" }),
1719
+ /* @__PURE__ */ w("dd", {
1720
+ "aria-label": "Average queue wait",
1721
+ children: Z(e.averageMs)
1722
+ }),
1723
+ /* @__PURE__ */ w("p", { children: "Per admitted request" })
1724
+ ] }),
1725
+ /* @__PURE__ */ T("div", { children: [
1726
+ /* @__PURE__ */ w("dt", { children: "Longest" }),
1727
+ /* @__PURE__ */ w("dd", {
1728
+ "aria-label": "Longest queue wait",
1729
+ children: Z(e.maxMs)
1730
+ }),
1731
+ /* @__PURE__ */ w("p", { children: "Single request" })
1732
+ ] }),
1733
+ /* @__PURE__ */ T("div", { children: [
1734
+ /* @__PURE__ */ w("dt", { children: "Admitted" }),
1735
+ /* @__PURE__ */ w("dd", {
1736
+ "aria-label": "Admitted requests",
1737
+ children: e.admitted.toLocaleString()
1738
+ }),
1739
+ /* @__PURE__ */ w("p", { children: "Requests that entered the actor" })
1740
+ ] })
1741
+ ]
1742
+ })
1743
+ ]
1744
+ });
1745
+ }
1746
+ function Je({ waiting: e }) {
1747
+ return /* @__PURE__ */ T("section", {
1748
+ className: "la-observer-waiting",
1749
+ "aria-label": "Waiting requests",
1750
+ children: [
1751
+ /* @__PURE__ */ T("h3", { children: ["Waiting requests", e != null && ` (${e.length})`] }),
1752
+ /* @__PURE__ */ w("p", { children: e == null ? "This host has not reported its waiting line." : e.length ? "Next to run first. Operations leave this line when they start." : "No requests waiting." }),
1753
+ !!e?.length && /* @__PURE__ */ w(Ye, { waiting: e })
1754
+ ]
1755
+ });
1756
+ }
1757
+ function Ye({ waiting: e, compact: t = !1 }) {
1758
+ if (e == null) return /* @__PURE__ */ w("span", {
1759
+ title: "Queue reporting is unavailable",
1760
+ children: "Unavailable"
1761
+ });
1762
+ if (!e.length) return /* @__PURE__ */ w("span", {
1763
+ className: "la-observer-queue-empty",
1764
+ children: "None"
1765
+ });
1766
+ let n = t ? e.slice(0, 3) : e;
1767
+ return /* @__PURE__ */ T("ol", {
1768
+ className: `la-observer-queue${t ? " la-observer-queue-compact" : ""}`,
1769
+ "aria-label": `${e.length} waiting requests, next to run first`,
1770
+ children: [n.map((e, n) => /* @__PURE__ */ w("li", { children: /* @__PURE__ */ T(V, {
1771
+ variant: "outline",
1772
+ className: "la-observer-queue-bubble",
1773
+ title: e.operation,
1774
+ children: [!t && /* @__PURE__ */ w("span", {
1775
+ className: "la-observer-queue-position",
1776
+ children: n + 1
1777
+ }), /* @__PURE__ */ w("span", {
1778
+ className: "la-observer-queue-operation",
1779
+ children: e.operation
1780
+ })]
1781
+ }) }, e.id)), t && e.length > n.length && /* @__PURE__ */ w("li", { children: /* @__PURE__ */ T(V, {
1782
+ "aria-label": `${e.length - n.length} more waiting requests`,
1783
+ children: ["+", e.length - n.length]
1784
+ }) })]
1785
+ });
1786
+ }
1787
+ function Xe({ id: e, actorId: t, connections: n }) {
1788
+ return /* @__PURE__ */ T("section", {
1789
+ id: e,
1790
+ className: "la-observer-connections",
1791
+ "aria-labelledby": `${e}-heading`,
1792
+ children: [/* @__PURE__ */ w("div", {
1793
+ className: "la-observer-instances-heading",
1794
+ children: /* @__PURE__ */ T("div", { children: [/* @__PURE__ */ T("h3", {
1795
+ id: `${e}-heading`,
1796
+ children: [
1797
+ t,
1798
+ " WebSockets ",
1799
+ /* @__PURE__ */ w(V, {
1800
+ "aria-hidden": "true",
1801
+ children: n.length.toLocaleString()
1802
+ })
1803
+ ]
1804
+ }), /* @__PURE__ */ w("p", { children: `${n.length.toLocaleString()} active ${n.length === 1 ? "connection" : "connections"}` })] })
1805
+ }), n.length ? /* @__PURE__ */ w("div", {
1806
+ className: "la-observer-table-frame",
1807
+ children: /* @__PURE__ */ T(H, {
1808
+ "aria-label": `${t} WebSocket connections`,
1809
+ className: "la-observer-connection-table",
1810
+ children: [/* @__PURE__ */ w(U, { children: /* @__PURE__ */ T(G, { children: [/* @__PURE__ */ w(K, {
1811
+ scope: "col",
1812
+ children: "Socket"
1813
+ }), /* @__PURE__ */ w(K, {
1814
+ scope: "col",
1815
+ children: "Metadata"
1816
+ })] }) }), /* @__PURE__ */ w(W, { children: n.map((e) => /* @__PURE__ */ T(G, { children: [/* @__PURE__ */ w(q, {
1817
+ className: "la-observer-socket-id",
1818
+ children: e.id
1819
+ }), /* @__PURE__ */ w(q, { children: /* @__PURE__ */ w("pre", { children: JSON.stringify(e.metadata, null, 2) }) })] }, e.id)) })]
1820
+ })
1821
+ }) : /* @__PURE__ */ T("div", {
1822
+ className: "la-observer-no-connections",
1823
+ role: "status",
1824
+ children: [/* @__PURE__ */ w(_, { "aria-hidden": "true" }), /* @__PURE__ */ w("p", { children: "No active WebSocket connections." })]
1825
+ })]
1826
+ });
1827
+ }
1828
+ function Ze({ label: e, placeholder: t, value: n, onChange: r }) {
1829
+ return /* @__PURE__ */ T("div", {
1830
+ className: "la-observer-search",
1831
+ children: [/* @__PURE__ */ w(g, { "aria-hidden": "true" }), /* @__PURE__ */ w(F, {
1832
+ type: "search",
1833
+ "aria-label": e,
1834
+ placeholder: t,
1835
+ value: n,
1836
+ onInput: (e) => r(e.currentTarget.value)
1837
+ })]
1838
+ });
1839
+ }
1840
+ function $({ title: e, description: t, action: n, onReset: r }) {
1841
+ return /* @__PURE__ */ T("div", {
1842
+ className: "la-observer-empty",
1843
+ children: [
1844
+ /* @__PURE__ */ w(g, { "aria-hidden": "true" }),
1845
+ /* @__PURE__ */ w("h3", { children: e }),
1846
+ /* @__PURE__ */ w("p", { children: t }),
1847
+ n && /* @__PURE__ */ w(P, {
1848
+ type: "button",
1849
+ variant: "outline",
1850
+ onClick: r,
1851
+ children: n
1852
+ })
1853
+ ]
1854
+ });
1855
+ }
1856
+ function Qe(e, t) {
1857
+ return e.toLocaleLowerCase().includes(t.trim().toLocaleLowerCase());
1858
+ }
1859
+ function $e(e) {
1860
+ return e[0].toUpperCase() + e.slice(1);
1861
+ }
1862
+ //#endregion
1863
+ export { Ve as ActorObserver, Ce as HttpObserverClient, Me as RequestObserver, B as TimeRangePicker, I as defaultTimeRange, R as rangeLabel, L as resolveRange };