@rubytech/create-maxy 1.0.666 → 1.0.667

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 CHANGED
@@ -219,11 +219,17 @@ function installSystemDeps() {
219
219
  if (canSudo()) {
220
220
  shell("apt-get", ["update"], { sudo: true });
221
221
  shell("apt-get", ["install", "-y", "curl", "git", "unzip", "jq", "avahi-daemon", "avahi-utils", "poppler-utils", "ffmpeg"], { sudo: true });
222
- // xterm is the fallback terminal-emulator binary for the VNC-rendered
223
- // Terminal surface (Task 627). Always installed to guarantee vnc.sh
224
- // start-terminal has a binary to spawn on Bookworm Pis where
225
- // gnome-terminal is not preinstalled (avoids pulling ~180MB of GNOME).
226
- shell("apt-get", ["install", "-y", "tigervnc-standalone-server", "python3-websockify", "novnc", "xdg-utils", "chromium", "xterm"], { sudo: true });
222
+ // xterm is the *preferred* terminal-emulator binary for the VNC-rendered
223
+ // Terminal surface (Task 632 gnome-terminal is a D-Bus launcher that
224
+ // delegates window creation to the session's gnome-terminal-server,
225
+ // opening windows on the wrong display; xterm has no IPC layer and
226
+ // honours DISPLAY directly). Kept in the apt list unconditionally so
227
+ // vnc.sh's resolve_terminal_bin has a display-safe binary on every
228
+ // supported distro (Ubuntu 24.04 noble/universe, Debian 12 bookworm/main
229
+ // verified). xdotool (Task 632) backs the post-spawn display-membership
230
+ // assertion in vnc.sh check_window_on_display, closing the silent-fail
231
+ // class where PID is alive but no window is mapped on the target display.
232
+ shell("apt-get", ["install", "-y", "tigervnc-standalone-server", "python3-websockify", "novnc", "xdg-utils", "chromium", "xterm", "xdotool"], { sudo: true });
227
233
  shell("apt-get", ["install", "-y", "hostapd", "dnsmasq"], { sudo: true });
228
234
  // tmux backs the admin terminal's persistent named session (Task 591).
229
235
  // ttyd is NOT in Debian Bookworm's apt repo (Task 602) — it ships as a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rubytech/create-maxy",
3
- "version": "1.0.666",
3
+ "version": "1.0.667",
4
4
  "description": "Install Maxy — AI for Productive People",
5
5
  "bin": {
6
6
  "create-maxy": "./dist/index.js"
@@ -270,6 +270,19 @@ ON EACH [k.summary, k.content];
270
270
  // seed, etc.) leave `summary` NULL; the /graph client's pickShortLabel
271
271
  // falls back to `Conv <shortId>` so empty conversations stay
272
272
  // distinguishable from each other.
273
+ //
274
+ // Task 633 — sublabels. Conversations written post-Task-633 carry one
275
+ // of two sublabels alongside `:Conversation`:
276
+ // :AdminConversation — agentType='admin' (operator-facing)
277
+ // :PublicConversation — agentType='public' (customer-facing)
278
+ // Neo4j labels are set-semantic; the sublabel is added at ON CREATE SET
279
+ // time in `ensureConversation` so the node carries both `:Conversation`
280
+ // and the sublabel. No new constraints — the existing
281
+ // conversation_id_unique constraint applies to Conversations regardless
282
+ // of sublabel. The sublabel drives /graph canvas colour resolution and
283
+ // filter popover chips per agentType without schema fragmentation.
284
+ // Pre-Task-633 Conversations stay unlabelled and render in the base
285
+ // :Conversation colour (sublabel backfill is a separate task).
273
286
  // ----------------------------------------------------------
274
287
 
275
288
  CREATE CONSTRAINT conversation_id_unique IF NOT EXISTS
@@ -310,6 +323,17 @@ OPTIONS {
310
323
  // NEXT per message — so a Conversation with N messages has N-1
311
324
  // NEXT edges.
312
325
  //
326
+ // Task 633 — sublabels. Messages written post-Task-633 carry one of
327
+ // two sublabels alongside `:Message`, derived from `role`:
328
+ // :UserMessage — role='user'
329
+ // :AssistantMessage — role='assistant'
330
+ // system/tool role messages (not written by the current persistMessage
331
+ // path) stay on base `:Message` only. The sublabel is set at CREATE
332
+ // time (`CREATE (m:Message:UserMessage { ... })`) so the node carries
333
+ // both labels atomically. No new constraints — `message_id_unique`
334
+ // below applies to any Message node regardless of sublabel. Pre-Task-633
335
+ // Messages stay unlabelled and render in the base :Message colour.
336
+ //
313
337
  // Chain-fork invariant (Task 624): the write path in
314
338
  // platform/ui/app/lib/neo4j-store.ts#persistMessage holds a
315
339
  // per-conversationId async mutex around the Cypher that observes
@@ -86,6 +86,8 @@ Maxy answers relational questions — "list all my people", "how many tasks do I
86
86
 
87
87
  You can also open a visual view of your graph at any time from the burger menu → **Graph**. Click the **Filter** button in the toolbar to open the filter menu — it lists only the node types that actually exist in your graph, one row per type, showing your per-type node count and sorted so the most-connected types sit at the top. Leaf types that only appear inside a parent (messages inside a conversation, sections inside a document) are never filter rows — you reach them by clicking the parent and exploring its neighbourhood. Infrastructural types (`ToolCall`, `WorkflowRun`, `WorkflowStep`, `ReviewAlert`) never appear as filter rows — the first three are execution plumbing, and `ReviewAlert` has its own dedicated surface in admin chat. Active rows render a force-directed map, coloured by label (Person, Service, KnowledgeDocument, Task, …). Click a node to see its properties and explore its neighbourhood; click the **Back** control or empty canvas to return to your filter view with the same rows still selected. Type in the search box to highlight matches; submitting a search also widens the filter to include any node types the hits belong to, so relevant matches render instead of disappearing into a "not in current view" banner. The **×** buttons on the search box and inside the filter menu clear the current search and the current selection respectively — clearing the filter selection does not touch your saved default.
88
88
 
89
+ Conversations and Messages carry role/channel sublabels so you can read the chat topology by colour alone — admin vs public conversations and user vs assistant messages render in distinct shades, and the filter menu splits them into separate rows.
90
+
89
91
  **Save a default view:** once you have the rows you want, click **Set default view** in the filter menu. Next time you open **Graph**, those rows are pre-selected and your data renders immediately. The default is per-admin, per-account — each admin on each account has their own.
90
92
 
91
93
  **Delete a node:** drag it to the trash icon top-right of the canvas. No confirmation — deletes are reversible for 30 days. To restore, toggle **Show trashed** inside the filter menu and click **Restore** on the node, or ask Maxy in chat ("restore the <label> I just deleted").
@@ -72,7 +72,7 @@ The Software Update window mounts the terminal lazily: neither the terminal, its
72
72
 
73
73
  Because the terminal is the only surface, it narrates its own state when something goes wrong. The moment you click Upgrade, the terminal echoes a timestamped `[upgrade] starting at <UTC> — shell+ws+tmux+xterm chain OK` line before the `npx` invocation begins — that single line confirms the WebSocket, tmux session, shell, and xterm renderer are all working end-to-end. If 5 seconds then pass with no output from `npx`, the terminal itself writes a `[terminal] no bytes from upstream in 5s — ws.readyState=…, bytesReceived=…, attempt=…` diagnostic into its own buffer, and repeats that narration every 30 seconds of continued silence. If even that narration never appears within ~10 seconds of click, the xterm renderer or its WebSocket is broken and reloading the admin UI is the fix. On the server side, `~/.maxy/logs/terminal.log` carries a `terminal-proxy-flow` heartbeat every 5 seconds while bytes are moving and every ~30 seconds while idle, with `clientBytes`, `upstreamBytes`, and `idleMs` fields — so a stuck upstream presents as `upstreamBytes` frozen and `idleMs` climbing, directly visible in a `tail -f` without any client-side evidence needed.
74
74
 
75
- The burger menu in the admin chat also includes a standalone **Terminal** entry next to **Browser**, but this surface is intentionally *different* from the upgrade-modal terminal. Clicking it spawns a real GUI terminal emulator (gnome-terminal on desktops that ship it, xterm elsewhere) on the VNC virtual display `:99` via the same `/vnc-viewer.html` iframe that Browser uses. The header Terminal is isomorphic to the header Browser: one pipeline (launch endpoint → display spawn → noVNC iframe), one failure domain — and deliberately decoupled from ttyd. Stopping `maxy-ttyd.service` leaves the header Terminal fully functional; only the in-modal upgrade terminal degrades. Closing the header Terminal overlay (Escape or the `×` button) kills the spawned emulator PID on the Pi via `POST /api/admin/terminal/close`; re-opening launches a fresh shell. Authorisation is inherited from the same `canAccessAdmin()` gate that wraps every `/api/admin/*` route. The launch endpoint logs to `~/.maxy/logs/terminal-launch.log` (script-level spawn/kill events) and to `vnc-boot.log` via `vncLog('ensure-terminal', ...)` (Node-side state machine), mirroring the Browser's `ensure-cdp` observability shape.
75
+ The burger menu in the admin chat also includes a standalone **Terminal** entry next to **Browser**, but this surface is intentionally *different* from the upgrade-modal terminal. Clicking it spawns a real GUI terminal emulator on the VNC virtual display `:99` via the same `/vnc-viewer.html` iframe that Browser uses. The binary is chosen by target display: for the VNC virtual display, **xterm** is preferred because it honours `DISPLAY` directly with no IPC layer; for the native loopback display, **gnome-terminal** is preferred because the login session's `gnome-terminal-server` owns that display. (gnome-terminal cannot be used for the VNC display — it's a D-Bus launcher that delegates window creation to the session's server, and the window would appear on the physical screen instead of inside the admin iframe.) The header Terminal is isomorphic to the header Browser: one pipeline (launch endpoint → display spawn → display-membership assertion → noVNC iframe), one failure domain — and deliberately decoupled from ttyd. Stopping `maxy-ttyd.service` leaves the header Terminal fully functional; only the in-modal upgrade terminal degrades. Closing the header Terminal overlay (Escape or the `×` button) kills the spawned emulator PID on the Pi via `POST /api/admin/terminal/close`; re-opening launches a fresh shell. Authorisation is inherited from the same `canAccessAdmin()` gate that wraps every `/api/admin/*` route. The launch endpoint logs to `~/.maxy/logs/terminal-launch.log` (script-level spawn/kill events, including `windowPresent=true` on success and `self-heal pid=... observed_windows=<n>` when a stale PID is respawned) and to `vnc-boot.log` via `vncLog('ensure-terminal', ...)` (Node-side state machine), mirroring the Browser's `ensure-cdp` observability shape. Any spawn failure surfaces verbatim in the 502 response body — no silent black rectangles.
76
76
 
77
77
  ## AI Content Provenance
78
78
 
@@ -167,10 +167,38 @@ which gnome-terminal; which xterm
167
167
 
168
168
  Most common failures and fixes:
169
169
 
170
- - `[terminal-launch] failed err="no terminal emulator installed"` → run `sudo apt-get install -y xterm` (or re-run the installer, which installs xterm as a dependency).
170
+ - `[terminal-launch] failed err="no terminal emulator installed"` → run `sudo apt-get install -y xterm xdotool` (or re-run the installer, which installs both as dependencies).
171
171
  - `[terminal-launch] failed err="spawn detached but no terminal PID visible within 1s"` → X server on `:99` is wedged. `sudo systemctl --user restart maxy-ui` cycles the VNC stack via `vnc.sh start`.
172
+ - `[terminal-launch] failed err="window absent from target display after spawn" pid=<N> display=:99 observed_windows=0` → the spawned emulator's window landed on the wrong display (Task 632 — almost always a stale gnome-terminal binary on an upgraded install; the fix ships `xterm` as the `:99` default but a stale `resolve_terminal_bin` on an old bundle can still trigger it). Check `which gnome-terminal xterm xdotool` — all three should exist; if not, re-run the installer. Also check `DISPLAY=:99 xdotool search --onlyvisible --class '.'` manually: empty output confirms no window on `:99`; a non-empty result after a fresh click means the window IS there and the check itself is wrong (file an issue).
172
173
  - `ensure-terminal action="escalate-vnc-restart"` followed by `degraded` → `Xtigervnc` itself is not coming up. Check `~/.maxy/logs/vnc-boot.log` for the tigervnc startup lines.
173
174
 
175
+ ## Terminal iframe renders black and cursor vanishes over the canvas
176
+
177
+ **Symptom:** Header-menu Terminal click appears to succeed — no error toast, overlay opens — but the iframe renders uniformly black, keystrokes do not reach any shell, and the mouse cursor disappears the moment it enters the iframe (visible elsewhere in the page).
178
+
179
+ **What it means:** This is the exact symptom class that Task 632 closed. Before 632, `/usr/bin/gnome-terminal` would receive `DISPLAY=:99` but D-Bus-delegate the window-create request to the session's `gnome-terminal-server`, which opens the window on `:0` (the operator's physical screen) instead. The iframe, rendering `:99`, has no window to show — hence the black canvas, dead keystrokes, and null-cursor (noVNC's Cursor pseudo-encoding renders `cursor: none` when the server sends no cursor). If you are seeing this *after* Task 632 shipped, the installer did not run on this device or a stale bundle is in place.
180
+
181
+ Step-by-step diagnosis:
182
+
183
+ ```bash
184
+ # 1. Check terminal-launch.log for the window-absent failure
185
+ sudo grep 'window absent from target display' ~/.maxy/logs/terminal-launch.log | tail -5
186
+
187
+ # 2. Verify the expected binaries are installed
188
+ which xterm xdotool # both must exist — installer adds them
189
+
190
+ # 3. Confirm the VNC display is serving the iframe
191
+ DISPLAY=:99 xdpyinfo >/dev/null 2>&1 && echo "display :99 ok"
192
+ DISPLAY=:99 xdotool search --onlyvisible --class '.' # non-empty means windows ARE on :99
193
+
194
+ # 4. Check which binary resolve_terminal_bin chose
195
+ grep 'cmd=' ~/.maxy/logs/terminal-launch.log | tail -3
196
+ # Expected after Task 632 for remote-origin clicks: cmd="/usr/bin/xterm"
197
+ # If you see: cmd="/usr/bin/gnome-terminal --wait" on :99 → stale bundle, re-run installer
198
+ ```
199
+
200
+ If the failure log shows `window absent from target display`, the fix already ran but spawn still went to the wrong display — re-run the installer (`npx -y @rubytech/create-maxy@latest`) from a shell to pick up the latest `xterm` + `xdotool` preflight. If the failure log shows no recent entries and the iframe is still black, check `ss -ltn '( sport = 6080 or sport = 5900 )'` and `pgrep -af Xtigervnc|websockify` — the symptom might be a VNC-stack regression rather than a terminal-binary mismatch.
201
+
174
202
  The header Terminal is decoupled from `maxy-ttyd.service` by design — stopping that service should *not* break the header Terminal. If the upgrade modal breaks but the header Terminal still works, the problem is isolated to ttyd (see the "Admin Terminal Stuck Disconnected After Upgrade" and "Admin terminal not available" sections above).
175
203
 
176
204
  ## Orphan Account Directory Archived to `.trash/`
@@ -171,7 +171,17 @@ start_chrome_on() {
171
171
  >> "$LOG_FILE" 2>&1 &
172
172
 
173
173
  if wait_for_port 9222; then
174
- log "Chromium ready (${label}) with CDP on :9222"
174
+ # Log-only observability (Task 632): the display-membership invariant is
175
+ # asserted but does NOT gate success here. Chromium does not D-Bus-delegate
176
+ # like gnome-terminal does, so the failure mode is not currently reachable
177
+ # — but making the invariant visible now means future backend swaps (e.g.
178
+ # snap-installed Chromium on Ubuntu with different IPC) surface the drift
179
+ # in vnc-boot.log rather than as a silent-black iframe.
180
+ if check_window_on_display "${target_display}"; then
181
+ log "Chromium ready (${label}) with CDP on :9222 windowPresent=true"
182
+ else
183
+ log "WARNING: Chromium CDP up on :9222 but no window visible on ${target_display} (${label}) — observability-only, not gating (Task 632)"
184
+ fi
175
185
  else
176
186
  log "ERROR: Chromium failed to start on ${target_display} (${label}) — CDP port 9222 not listening (browser-specialist degraded)"
177
187
  fi
@@ -185,33 +195,70 @@ start_chrome() {
185
195
  # Terminal emulator lifecycle (Task 627) — isomorphic to Chromium's.
186
196
  # ---------------------------------------------------------------------------
187
197
 
188
- # Resolve the preferred terminal binary + its required flags. Prefers
189
- # gnome-terminal on desktops that ship it (Ubuntu), falls back to xterm
190
- # (Bookworm minimum). Prints "<bin>\t<flags>" on stdout (tab-separated), or
191
- # exits non-zero with a loud-fail log if neither is installed — matches the
192
- # operator invariant "no ttyd fallback, no silent substitution" from Task 627.
198
+ # Resolve the preferred terminal binary + its required flags. Selection depends
199
+ # on the target display because gnome-terminal is a D-Bus launcher that routes
200
+ # through /usr/libexec/gnome-terminal-server and that server is bound to the
201
+ # operator's login session bus (typically :0 on a GNOME desktop). Calling
202
+ # `DISPLAY=:99 /usr/bin/gnome-terminal` does NOT open a window on :99; the
203
+ # D-Bus request is delegated to the server on :0 and the window appears there
204
+ # instead (Task 632 root cause). xterm is a standalone X client with no IPC
205
+ # layer, so `DISPLAY=:99 xterm` lands on :99 regardless of session state.
193
206
  #
194
- # gnome-terminal needs `--wait` because its /usr/bin/gnome-terminal entry is a
195
- # python D-Bus launcher that forks `/usr/bin/gnome-terminal.real` and would
196
- # otherwise exit seconds after dispatch — leaving our pgrep-based liveness
197
- # probe blind while the actual window (owned by gnome-terminal-server) is
198
- # still on screen. With --wait, both the python wrapper and .real stay alive
199
- # for the duration of the shell session. xterm is a single-process emulator
200
- # and needs no flag.
207
+ # Selection rule:
208
+ # target_display == :99 (VNC virtual) → xterm-first, gnome-terminal fallback
209
+ # target_display == :0 (native login) → gnome-terminal-first, xterm fallback
210
+ # (the session's gnome-terminal-server owns :0, so D-Bus delegation lands
211
+ # on the right display here no bug reachable on loopback)
212
+ #
213
+ # Prints "<bin>\t<flags>" on stdout (tab-separated), or exits non-zero with a
214
+ # loud-fail log if neither is installed — matches the operator invariant
215
+ # "no ttyd fallback, no silent substitution" from Task 627. gnome-terminal
216
+ # retains `--wait` (see Task 627 pgrep-visibility fix). xterm takes no flag.
201
217
  resolve_terminal_bin() {
202
- if [ -x /usr/bin/gnome-terminal ]; then
203
- printf '%s\t%s\n' '/usr/bin/gnome-terminal' '--wait'
204
- return 0
205
- fi
206
- if [ -x /usr/bin/xterm ]; then
207
- printf '%s\t%s\n' '/usr/bin/xterm' ''
208
- return 0
218
+ local target_display="${1:-:99}"
219
+ local xterm_bin='' gnome_bin=''
220
+ [ -x /usr/bin/xterm ] && xterm_bin='/usr/bin/xterm'
221
+ [ -x /usr/bin/gnome-terminal ] && gnome_bin='/usr/bin/gnome-terminal'
222
+
223
+ if [ "$target_display" = ":99" ]; then
224
+ [ -n "$xterm_bin" ] && { printf '%s\t%s\n' "$xterm_bin" ''; return 0; }
225
+ [ -n "$gnome_bin" ] && { printf '%s\t%s\n' "$gnome_bin" '--wait'; return 0; }
226
+ else
227
+ [ -n "$gnome_bin" ] && { printf '%s\t%s\n' "$gnome_bin" '--wait'; return 0; }
228
+ [ -n "$xterm_bin" ] && { printf '%s\t%s\n' "$xterm_bin" ''; return 0; }
209
229
  fi
210
230
  tlog "failed err=\"no terminal emulator installed (expected /usr/bin/gnome-terminal or /usr/bin/xterm)\""
211
231
  log "ERROR: no terminal emulator binary found — install xterm (apt-get install -y xterm)"
212
232
  return 1
213
233
  }
214
234
 
235
+ # Verify that at least one visible window is mapped on $target_display. Closes
236
+ # the "PID visible in pgrep but window is not on target" class of silent fail
237
+ # (Task 632). Uses xdotool's exit code directly — no stdout parsing for
238
+ # control flow (feedback_no_stdout_parsing_for_control_flow.md). `--class '.'`
239
+ # matches WM_CLASS (static for the window's lifetime) instead of WM_NAME
240
+ # (which can be empty in the microseconds between window-create and
241
+ # title-set). Retries 3× at 0.3s to absorb the window-map race.
242
+ #
243
+ # Returns 0 if any visible window appears on the display within ~1s, 1 otherwise.
244
+ check_window_on_display() {
245
+ local target_display="$1"
246
+ for _ in 1 2 3; do
247
+ if DISPLAY="$target_display" xdotool search --onlyvisible --class '.' >/dev/null 2>&1; then
248
+ return 0
249
+ fi
250
+ sleep 0.3
251
+ done
252
+ return 1
253
+ }
254
+
255
+ # Count visible windows on $target_display (diagnostic; used in failure logs).
256
+ # Prints the integer count. Returns 0 on empty display (not an error).
257
+ _count_windows_on_display() {
258
+ local target_display="$1"
259
+ DISPLAY="$target_display" xdotool search --onlyvisible --class '.' 2>/dev/null | wc -l | tr -d ' '
260
+ }
261
+
215
262
  # pgrep pattern that matches operator-launched terminals but NEVER matches
216
263
  # /usr/libexec/gnome-terminal-server (D-Bus service, pre-existing). Matches:
217
264
  # - /usr/bin/gnome-terminal --wait (Ubuntu's python wrapper, invoked with --wait)
@@ -265,19 +312,33 @@ start_terminal_on() {
265
312
  local target_display="$1"
266
313
  local label="$2" # "vnc" | "native"
267
314
 
268
- # Idempotency: if a terminal is already alive, do not spawn another.
269
- # Matches ensureCdp's "CDP up return true" branch. Display-switch is
270
- # the caller's responsibility (ensureTerminal in vnc.ts kills first).
315
+ # Idempotency: if a terminal is already alive, verify its window is actually
316
+ # mapped on $target_display before accepting. The pgrep-based liveness probe
317
+ # cannot distinguish a terminal on :0 (stale from an unclean close, or
318
+ # D-Bus-delegated by a pre-Task-632 gnome-terminal call) from one on :99.
319
+ # Self-heal: if the PID exists but no window appears on the target display,
320
+ # kill the stale emulator and fall through to respawn.
271
321
  if terminal_alive; then
272
322
  local existing_pid
273
323
  existing_pid="$(terminal_pid)"
274
- tlog "already-running pid=${existing_pid} display=${target_display}"
275
- log "Terminal already running pid=${existing_pid} (${label})"
276
- return 0
324
+ if check_window_on_display "$target_display"; then
325
+ tlog "already-running pid=${existing_pid} display=${target_display} windowPresent=true"
326
+ log "Terminal already running pid=${existing_pid} (${label})"
327
+ return 0
328
+ fi
329
+ local observed
330
+ observed="$(_count_windows_on_display "$target_display")"
331
+ tlog "self-heal pid=${existing_pid} display=${target_display} observed_windows=${observed} transport=${label} reason=\"window absent on target, respawning\""
332
+ log "Terminal pid=${existing_pid} alive but no window on ${target_display} — self-healing"
333
+ kill_terminal_emulators
334
+ sleep 0.3
277
335
  fi
278
336
 
279
337
  local resolved bin flags
280
- if ! resolved="$(resolve_terminal_bin)"; then
338
+ if ! resolved="$(resolve_terminal_bin "$target_display")"; then
339
+ # resolve_terminal_bin already echoed the diagnostic via tlog; mirror it
340
+ # to stderr so the Node caller (ensureTerminal) captures the exact string.
341
+ echo "[terminal-launch] failed err=\"no terminal emulator installed\" transport=${label}" >&2
281
342
  return 1
282
343
  fi
283
344
  bin="${resolved%%$'\t'*}"
@@ -296,17 +357,32 @@ start_terminal_on() {
296
357
  DISPLAY="${target_display}" setsid -f "$bin" >> "$TERMINAL_LOG" 2>&1 || true
297
358
  fi
298
359
 
299
- if wait_for_terminal; then
300
- local pid
301
- pid="$(terminal_pid)"
302
- tlog "started pid=${pid} display=${target_display} cmd=\"${bin} ${flags}\" transport=${label}"
303
- log "Terminal ready (${label}) pid=${pid}"
304
- return 0
305
- else
306
- tlog "failed err=\"spawn detached but no terminal PID visible within 1s\" transport=${label} cmd=\"${bin} ${flags}\""
360
+ if ! wait_for_terminal; then
361
+ local diag="failed err=\"spawn detached but no terminal PID visible within 1s\" transport=${label} cmd=\"${bin} ${flags}\""
362
+ tlog "$diag"
363
+ echo "[terminal-launch] $diag" >&2
307
364
  log "ERROR: terminal failed to appear in pgrep within 1s on ${target_display} (${label}) — investigate setsid -f detachment / --wait flag"
308
365
  return 1
309
366
  fi
367
+
368
+ local pid
369
+ pid="$(terminal_pid)"
370
+
371
+ # Post-spawn invariant (Task 632): PID presence is necessary but not
372
+ # sufficient — assert the window actually landed on the target display.
373
+ if ! check_window_on_display "$target_display"; then
374
+ local observed
375
+ observed="$(_count_windows_on_display "$target_display")"
376
+ local diag="failed err=\"window absent from target display after spawn\" pid=${pid} display=${target_display} observed_windows=${observed} transport=${label} cmd=\"${bin} ${flags}\""
377
+ tlog "$diag"
378
+ echo "[terminal-launch] $diag" >&2
379
+ log "ERROR: terminal pid=${pid} spawned but no window on ${target_display} (${label}) — likely D-Bus delegation to another display"
380
+ return 1
381
+ fi
382
+
383
+ tlog "started pid=${pid} display=${target_display} cmd=\"${bin} ${flags}\" transport=${label} windowPresent=true"
384
+ log "Terminal ready (${label}) pid=${pid}"
385
+ return 0
310
386
  }
311
387
 
312
388
  start_terminal() {
@@ -366,7 +442,16 @@ start_chrome_native() {
366
442
  >> "$LOG_FILE" 2>&1 &
367
443
 
368
444
  if wait_for_port 9222; then
369
- log "Chromium ready (native) with CDP on :9222"
445
+ # Log-only observability (Task 632) see start_chrome_on for rationale.
446
+ # On Wayland sessions xdotool cannot inspect the compositor, so this
447
+ # check is x11-only; fall back to unconditional windowPresent=unknown.
448
+ if [ "$NATIVE_SESSION_TYPE" = "x11" ] && check_window_on_display "${NATIVE_DISPLAY}"; then
449
+ log "Chromium ready (native) with CDP on :9222 windowPresent=true"
450
+ elif [ "$NATIVE_SESSION_TYPE" = "wayland" ]; then
451
+ log "Chromium ready (native) with CDP on :9222 windowPresent=unknown (wayland)"
452
+ else
453
+ log "WARNING: Chromium CDP up on :9222 but no window visible on ${NATIVE_DISPLAY} (native) — observability-only, not gating (Task 632)"
454
+ fi
370
455
  else
371
456
  log "ERROR: Chromium failed to start on ${NATIVE_DISPLAY} (native) — CDP port 9222 not listening (browser-specialist degraded)"
372
457
  fi
@@ -46,4 +46,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
46
46
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var a,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||n.return==null||n.return()}finally{if(s)throw a}}}}function I_(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var L_=Up(`DELETE`);function R_(){var e=z_.apply(void 0,arguments);return V_(e),e}function z_(){var e=[...arguments];if(e.length<2)return e[0];var t;if(e.length>2)return z_.apply(void 0,Jp(t=[R_(e[0],e[1])]).call(t,Hp(Yp(e).call(e,2))));var n=e[0],r=e[1];if(n instanceof Date&&r instanceof Date)return n.setTime(r.getTime()),n;var i,a=F_(nm(r));try{for(a.s();!(i=a.n()).done;){var o=i.value;Object.prototype.propertyIsEnumerable.call(r,o)&&(r[o]===L_?delete n[o]:n[o]===null||r[o]===null||typeof n[o]!=`object`||typeof r[o]!=`object`||rm(n[o])||rm(r[o])?n[o]=B_(r[o]):n[o]=z_(n[o],r[o]))}}catch(e){a.e(e)}finally{a.f()}return n}function B_(e){return rm(e)?Kd(e).call(e,(function(e){return B_(e)})):typeof e==`object`&&e?e instanceof Date?new Date(e.getTime()):z_({},e):e}function V_(e){for(var t=0,n=om(e);t<n.length;t++){var r=n[t];e[r]===L_?delete e[r]:typeof e[r]==`object`&&e[r]!==null&&V_(e[r])}}var H_=typeof window<`u`?window.Hammer||P_:function(){return function(){var e=function(){};return{on:e,off:e,destroy:e,emit:e,get:()=>({set:e})}}()};function U_(e){var t,n=this;this._cleanupQueue=[],this.active=!1,this._dom={container:e,overlay:document.createElement(`div`)},this._dom.overlay.classList.add(`vis-overlay`),this._dom.container.appendChild(this._dom.overlay),this._cleanupQueue.push((function(){n._dom.overlay.parentNode.removeChild(n._dom.overlay)}));var r=H_(this._dom.overlay);r.on(`tap`,vd(t=this._onTapOverlay).call(t,this)),this._cleanupQueue.push((function(){r.destroy()}));var i=[`tap`,`doubletap`,`press`,`pinch`,`pan`,`panstart`,`panmove`,`panend`];_m(i).call(i,(function(e){r.on(e,(function(e){e.srcEvent.stopPropagation()}))})),document&&document.body&&(this._onClick=function(t){(function(e,t){for(;e;){if(e===t)return!0;e=e.parentNode}return!1})(t.target,e)||n.deactivate()},document.body.addEventListener(`click`,this._onClick),this._cleanupQueue.push((function(){document.body.removeEventListener(`click`,n._onClick)}))),this._escListener=function(e){(`key`in e?e.key===`Escape`:e.keyCode===27)&&n.deactivate()}}Bh(U_.prototype),U_.current=null,U_.prototype.destroy=function(){var e,t;this.deactivate();var n,r=F_(Dm(e=Jm(t=this._cleanupQueue).call(t,0)).call(e));try{for(r.s();!(n=r.n()).done;)(0,n.value)()}catch(e){r.e(e)}finally{r.f()}},U_.prototype.activate=function(){U_.current&&U_.current.deactivate(),U_.current=this,this.active=!0,this._dom.overlay.style.display=`none`,this._dom.container.classList.add(`vis-active`),this.emit(`change`),this.emit(`activate`),document.body.addEventListener(`keydown`,this._escListener)},U_.prototype.deactivate=function(){this.active=!1,this._dom.overlay.style.display=`block`,this._dom.container.classList.remove(`vis-active`),document.body.removeEventListener(`keydown`,this._escListener),this.emit(`change`),this.emit(`deactivate`)},U_.prototype._onTapOverlay=function(e){this.activate(),e.srcEvent.stopPropagation()};var W_=Hr,G_=Ke,K_=TypeError,q_=function(e){if(W_(e))return e;throw new K_(G_(e)+` is not a constructor`)},J_=L,Y_=p,X_=cd,Z_=q_,Q_=Sn,$_=j,ev=sa,tv=s,nv=N(`Reflect`,`construct`),rv=Object.prototype,iv=[].push,av=tv((function(){function e(){}return!(nv((function(){}),[],e)instanceof e)})),ov=!tv((function(){nv((function(){}))})),sv=av||ov;J_({target:`Reflect`,stat:!0,forced:sv,sham:sv},{construct:function(e,t){Z_(e),Q_(t);var n=arguments.length<3?e:Z_(arguments[2]);if(ov&&!av)return nv(e,t,n);if(e===n){switch(t.length){case 0:return new e;case 1:return new e(t[0]);case 2:return new e(t[0],t[1]);case 3:return new e(t[0],t[1],t[2]);case 4:return new e(t[0],t[1],t[2],t[3])}var r=[null];return Y_(iv,r,t),new(Y_(X_,e,r))}var i=n.prototype,a=ev($_(i)?i:rv),o=Y_(e,a,t);return $_(o)?o:a}});var cv=r(M.Reflect.construct),lv=r(M.Object.getOwnPropertySymbols),uv={exports:{}},dv=L,fv=s,pv=xe,mv=E.f,hv=D;dv({target:`Object`,stat:!0,forced:!hv||fv((function(){mv(1)})),sham:!hv},{getOwnPropertyDescriptor:function(e,t){return mv(pv(e),t)}});var gv=M.Object,_v=uv.exports=function(e,t){return gv.getOwnPropertyDescriptor(e,t)};gv.getOwnPropertyDescriptor.sham&&(_v.sham=!0);var vv=r(uv.exports),yv=tm,bv=xe,xv=E,Sv=hr;L({target:`Object`,stat:!0,sham:!D},{getOwnPropertyDescriptors:function(e){for(var t,n,r=bv(e),i=xv.f,a=yv(r),o={},s=0;a.length>s;)(n=i(r,t=a[s++]))!==void 0&&Sv(o,t,n);return o}});var Cv=r(M.Object.getOwnPropertyDescriptors),wv={exports:{}},Tv=L,Ev=D,Dv=gi.f;Tv({target:`Object`,stat:!0,forced:Object.defineProperties!==Dv,sham:!Ev},{defineProperties:Dv});var Ov=M.Object,kv=wv.exports=function(e,t){return Ov.defineProperties(e,t)};Ov.defineProperties.sham&&(kv.sham=!0);var Av=r(wv.exports),jv=r(Qn);function U(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}var Mv=mh,Nv=r(Mv);L({target:`Object`,stat:!0},{setPrototypeOf:_l});var Pv=M.Object.setPrototypeOf,Fv=r(Pv),Iv=r(_d);function Lv(e,t){var n;return Lv=Fv?Iv(n=Fv).call(n):function(e,t){return e.__proto__=t,e},Lv(e,t)}function Rv(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Nv(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),er(e,`prototype`,{writable:!1}),t&&Lv(e,t)}function zv(e,t){if(t&&(Ku(t)===`object`||typeof t==`function`))return t;if(t!==void 0)throw TypeError(`Derived constructors may only return object or undefined`);return U(e)}var Bv=fh,Vv=r(Bv);function Hv(e){var t;return Hv=Fv?Iv(t=Vv).call(t):function(e){return e.__proto__||Vv(e)},Hv(e)}var Uv={exports:{}},Wv={exports:{}};(function(e){var t=Tu,n=Wu;function r(i){return e.exports=r=typeof t==`function`&&typeof n==`symbol`?function(e){return typeof e}:function(e){return e&&typeof t==`function`&&e.constructor===t&&e!==t.prototype?`symbol`:typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,r(i)}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports})(Wv);var Gv=Wv.exports,Kv=gm,qv=_t,Jv=tm,Yv=E,Xv=_n,Zv=j,Qv=In,$v=Error,ey=v(``.replace),ty=String(new $v(`zxcasd`).stack),ny=/\n\s*at [^:]*:[^\n]*/,ry=ny.test(ty),iy=le,ay=!s((function(){var e=Error(`a`);return!(`stack`in e)||(Object.defineProperty(e,`stack`,iy(1,7)),e.stack!==7)})),oy=In,sy=function(e,t){if(ry&&typeof e==`string`&&!$v.prepareStackTrace)for(;t--;)e=ey(e,ny,``);return e},cy=ay,ly=Error.captureStackTrace,uy=gn,dy=k,fy=Sn,W=Ke,G=bf,py=lr,my=P,hy=Mf,gy=Ef,_y=mf,vy=TypeError,yy=function(e,t){this.stopped=e,this.result=t},by=yy.prototype,xy=function(e,t,n){var r,i,a,o,s,c,l,u=n&&n.that,d=!(!n||!n.AS_ENTRIES),f=!(!n||!n.IS_RECORD),p=!(!n||!n.IS_ITERATOR),m=!(!n||!n.INTERRUPTED),h=uy(t,u),g=function(e){return r&&_y(r,`normal`,e),new yy(!0,e)},_=function(e){return d?(fy(e),m?h(e[0],e[1],g):h(e[0],e[1])):m?h(e,g):h(e)};if(f)r=e.iterator;else if(p)r=e;else{if(!(i=gy(e)))throw new vy(W(e)+` is not iterable`);if(G(i)){for(a=0,o=py(e);o>a;a++)if((s=_(e[a]))&&my(by,s))return s;return new yy(!1)}r=hy(e,i)}for(c=f?e.next:r.next;!(l=dy(c,r)).done;){try{s=_(l.value)}catch(e){_y(r,`throw`,e)}if(typeof s==`object`&&s&&my(by,s))return s}return new yy(!1)},Sy=hi,Cy=L,wy=P,Ty=qc,Ey=_l,Dy=function(e,t,n){for(var r=Jv(t),i=Xv.f,a=Yv.f,o=0;o<r.length;o++){var s=r[o];qv(e,s)||n&&qv(n,s)||i(e,s,a(t,s))}},Oy=sa,ky=In,Ay=le,jy=function(e,t){Zv(t)&&`cause`in t&&Qv(e,`cause`,t.cause)},My=function(e,t,n,r){cy&&(ly?ly(e,t):oy(e,`stack`,sy(n,r)))},Ny=xy,Py=function(e,t){return e===void 0?arguments.length<2?``:t:Sy(e)},Fy=jt(`toStringTag`),Iy=Error,Ly=[].push,Ry=function(e,t){var n,r=wy(zy,this);Ey?n=Ey(new Iy,r?Ty(this):zy):(n=r?this:Oy(zy),ky(n,Fy,`Error`)),t!==void 0&&ky(n,`message`,Py(t)),My(n,Ry,n.stack,1),arguments.length>2&&jy(n,arguments[2]);var i=[];return Ny(e,Ly,{that:i}),ky(n,`errors`,i),n};Ey?Ey(Ry,Iy):Dy(Ry,Iy,{name:!0});var zy=Ry.prototype=Oy(Iy.prototype,{constructor:Ay(1,Ry),message:Ay(1,``),name:Ay(1,`AggregateError`)});Cy({global:!0,constructor:!0,arity:2},{AggregateError:Ry});var By,Vy,Hy,Uy,Wy=N,Gy=Da,Ky=D,qy=jt(`species`),Jy=function(e){var t=Wy(e);Ky&&t&&!t[qy]&&Gy(t,qy,{configurable:!0,get:function(){return this}})},Yy=P,Xy=TypeError,Zy=function(e,t){if(Yy(t,e))return e;throw new Xy(`Incorrect invocation`)},Qy=Sn,$y=q_,eb=he,tb=jt(`species`),nb=function(e,t){var n,r=Qy(e).constructor;return r===void 0||eb(n=Qy(r)[tb])?t:$y(n)},rb=/(?:ipad|iphone|ipod).*applewebkit/i.test(F),ib=o,ab=p,ob=gn,sb=T,cb=_t,lb=s,ub=Wi,db=qs,fb=Gt,pb=xh,mb=rb,hb=Od,gb=ib.setImmediate,_b=ib.clearImmediate,vb=ib.process,yb=ib.Dispatch,bb=ib.Function,xb=ib.MessageChannel,Sb=ib.String,Cb=0,wb={},Tb=`onreadystatechange`;lb((function(){By=ib.location}));var Eb=function(e){if(cb(wb,e)){var t=wb[e];delete wb[e],t()}},Db=function(e){return function(){Eb(e)}},Ob=function(e){Eb(e.data)},kb=function(e){ib.postMessage(Sb(e),By.protocol+`//`+By.host)};gb&&_b||(gb=function(e){pb(arguments.length,1);var t=sb(e)?e:bb(e),n=db(arguments,1);return wb[++Cb]=function(){ab(t,void 0,n)},Vy(Cb),Cb},_b=function(e){delete wb[e]},hb?Vy=function(e){vb.nextTick(Db(e))}:yb&&yb.now?Vy=function(e){yb.now(Db(e))}:xb&&!mb?(Uy=(Hy=new xb).port2,Hy.port1.onmessage=Ob,Vy=ob(Uy.postMessage,Uy)):ib.addEventListener&&sb(ib.postMessage)&&!ib.importScripts&&By&&By.protocol!==`file:`&&!lb(kb)?(Vy=kb,ib.addEventListener(`message`,Ob,!1)):Vy=Tb in fb(`script`)?function(e){ub.appendChild(fb(`script`))[Tb]=function(){ub.removeChild(this),Eb(e)}}:function(e){setTimeout(Db(e),0)});var Ab={set:gb,clear:_b},jb=function(){this.head=null,this.tail=null};jb.prototype={add:function(e){var t={item:e,next:null},n=this.tail;n?n.next=t:this.head=t,this.tail=t},get:function(){var e=this.head;if(e)return(this.head=e.next)===null&&(this.tail=null),e.item}};var Mb,Nb,Pb,Fb,Ib,Lb=jb,Rb=/ipad|iphone|ipod/i.test(F)&&typeof Pebble<`u`,zb=/web0s(?!.*chrome)/i.test(F),Bb=o,Vb=gn,Hb=E.f,Ub=Ab.set,Wb=Lb,Gb=rb,Kb=Rb,qb=zb,Jb=Od,Yb=Bb.MutationObserver||Bb.WebKitMutationObserver,Xb=Bb.document,Zb=Bb.process,Qb=Bb.Promise,$b=Hb(Bb,`queueMicrotask`),ex=$b&&$b.value;if(!ex){var tx=new Wb,nx=function(){var e,t;for(Jb&&(e=Zb.domain)&&e.exit();t=tx.get();)try{t()}catch(e){throw tx.head&&Mb(),e}e&&e.enter()};Gb||Jb||qb||!Yb||!Xb?!Kb&&Qb&&Qb.resolve?((Fb=Qb.resolve(void 0)).constructor=Qb,Ib=Vb(Fb.then,Fb),Mb=function(){Ib(nx)}):Jb?Mb=function(){Zb.nextTick(nx)}:(Ub=Vb(Ub,Bb),Mb=function(){Ub(nx)}):(Nb=!0,Pb=Xb.createTextNode(``),new Yb(nx).observe(Pb,{characterData:!0}),Mb=function(){Pb.data=Nb=!Nb}),ex=function(e){tx.head||Mb(),tx.add(e)}}var rx=ex,ix=function(e){try{return{error:!1,value:e()}}catch(e){return{error:!0,value:e}}},ax=o.Promise,ox=typeof Deno==`object`&&Deno&&typeof Deno.version==`object`,sx=!ox&&!Od&&typeof window==`object`&&typeof document==`object`,cx=o,lx=ax,ux=T,dx=fn,fx=Or,px=jt,mx=sx,hx=ox,gx=Pe,_x=lx&&lx.prototype,vx=px(`species`),yx=!1,bx=ux(cx.PromiseRejectionEvent),xx={CONSTRUCTOR:dx(`Promise`,(function(){var e=fx(lx),t=e!==String(lx);if(!t&&gx===66||!_x.catch||!_x.finally)return!0;if(!gx||gx<51||!/native code/.test(e)){var n=new lx((function(e){e(1)})),r=function(e){e((function(){}),(function(){}))};if((n.constructor={})[vx]=r,!(yx=n.then((function(){}))instanceof r))return!0}return!t&&(mx||hx)&&!bx})),REJECTION_EVENT:bx,SUBCLASSING:yx},Sx={},Cx=Xe,wx=TypeError,Tx=function(e){var t,n;this.promise=new e((function(e,r){if(t!==void 0||n!==void 0)throw new wx(`Bad Promise constructor`);t=e,n=r})),this.resolve=Cx(t),this.reject=Cx(n)};Sx.f=function(e){return new Tx(e)};var Ex,Dx,Ox=L,kx=Od,Ax=o,jx=k,Mx=Ta,Nx=Xa,Px=Jy,Fx=Xe,Ix=T,Lx=j,Rx=Zy,zx=nb,Bx=Ab.set,Vx=rx,Hx=function(e,t){try{arguments.length===1?console.error(e):console.error(e,t)}catch{}},Ux=ix,Wx=Lb,Gx=po,Kx=ax,qx=xx,Jx=Sx,Yx=`Promise`,Xx=qx.CONSTRUCTOR,Zx=qx.REJECTION_EVENT,Qx=Gx.getterFor(Yx),$x=Gx.set,eS=Kx&&Kx.prototype,tS=Kx,nS=eS,rS=Ax.TypeError,iS=Ax.document,aS=Ax.process,oS=Jx.f,sS=oS,cS=!!(iS&&iS.createEvent&&Ax.dispatchEvent),lS=`unhandledrejection`,uS=function(e){var t;return!(!Lx(e)||!Ix(t=e.then))&&t},dS=function(e,t){var n,r,i,a=t.value,o=t.state===1,s=o?e.ok:e.fail,c=e.resolve,l=e.reject,u=e.domain;try{s?(o||(t.rejection===2&&gS(t),t.rejection=1),!0===s?n=a:(u&&u.enter(),n=s(a),u&&(u.exit(),i=!0)),n===e.promise?l(new rS(`Promise-chain cycle`)):(r=uS(n))?jx(r,n,c,l):c(n)):l(a)}catch(e){u&&!i&&u.exit(),l(e)}},fS=function(e,t){e.notified||(e.notified=!0,Vx((function(){for(var n,r=e.reactions;n=r.get();)dS(n,e);e.notified=!1,t&&!e.rejection&&mS(e)})))},pS=function(e,t,n){var r,i;cS?((r=iS.createEvent(`Event`)).promise=t,r.reason=n,r.initEvent(e,!1,!0),Ax.dispatchEvent(r)):r={promise:t,reason:n},!Zx&&(i=Ax[`on`+e])?i(r):e===lS&&Hx(`Unhandled promise rejection`,n)},mS=function(e){jx(Bx,Ax,(function(){var t,n=e.facade,r=e.value;if(hS(e)&&(t=Ux((function(){kx?aS.emit(`unhandledRejection`,r,n):pS(lS,n,r)})),e.rejection=kx||hS(e)?2:1,t.error))throw t.value}))},hS=function(e){return e.rejection!==1&&!e.parent},gS=function(e){jx(Bx,Ax,(function(){var t=e.facade;kx?aS.emit(`rejectionHandled`,t):pS(`rejectionhandled`,t,e.value)}))},_S=function(e,t,n){return function(r){e(t,r,n)}},vS=function(e,t,n){e.done||(e.done=!0,n&&(e=n),e.value=t,e.state=2,fS(e,!0))},yS=function(e,t,n){if(!e.done){e.done=!0,n&&(e=n);try{if(e.facade===t)throw new rS(`Promise can't be resolved itself`);var r=uS(t);r?Vx((function(){var n={done:!1};try{jx(r,t,_S(yS,n,e),_S(vS,n,e))}catch(t){vS(n,t,e)}})):(e.value=t,e.state=1,fS(e,!1))}catch(t){vS({done:!1},t,e)}}};Xx&&(nS=(tS=function(e){Rx(this,nS),Fx(e),jx(Ex,this);var t=Qx(this);try{e(_S(yS,t),_S(vS,t))}catch(e){vS(t,e)}}).prototype,(Ex=function(e){$x(this,{type:Yx,done:!1,notified:!1,parent:!1,reactions:new Wx,rejection:!1,state:0,value:void 0})}).prototype=Mx(nS,`then`,(function(e,t){var n=Qx(this),r=oS(zx(this,tS));return n.parent=!0,r.ok=!Ix(e)||e,r.fail=Ix(t)&&t,r.domain=kx?aS.domain:void 0,n.state===0?n.reactions.add(r):Vx((function(){dS(r,n)})),r.promise})),Dx=function(){var e=new Ex,t=Qx(e);this.promise=e,this.resolve=_S(yS,t),this.reject=_S(vS,t)},Jx.f=oS=function(e){return e===tS||e===void 0?new Dx(e):sS(e)}),Ox({global:!0,constructor:!0,wrap:!0,forced:Xx},{Promise:tS}),Nx(tS,Yx,!1,!0),Px(Yx);var bS=ax,xS=xx.CONSTRUCTOR||!Jf((function(e){bS.all(e).then(void 0,(function(){}))})),SS=k,CS=Xe,wS=Sx,TS=ix,ES=xy;L({target:`Promise`,stat:!0,forced:xS},{all:function(e){var t=this,n=wS.f(t),r=n.resolve,i=n.reject,a=TS((function(){var n=CS(t.resolve),a=[],o=0,s=1;ES(e,(function(e){var c=o++,l=!1;s++,SS(n,t,e).then((function(e){l||(l=!0,a[c]=e,--s||r(a))}),i)})),--s||r(a)}));return a.error&&i(a.value),n.promise}});var DS=L,OS=xx.CONSTRUCTOR;ax&&ax.prototype,DS({target:`Promise`,proto:!0,forced:OS,real:!0},{catch:function(e){return this.then(void 0,e)}});var kS=k,AS=Xe,jS=Sx,MS=ix,NS=xy;L({target:`Promise`,stat:!0,forced:xS},{race:function(e){var t=this,n=jS.f(t),r=n.reject,i=MS((function(){var i=AS(t.resolve);NS(e,(function(e){kS(i,t,e).then(n.resolve,r)}))}));return i.error&&r(i.value),n.promise}});var PS=k,FS=Sx;L({target:`Promise`,stat:!0,forced:xx.CONSTRUCTOR},{reject:function(e){var t=FS.f(this);return PS(t.reject,void 0,e),t.promise}});var IS=Sn,LS=j,RS=Sx,zS=function(e,t){if(IS(e),LS(t)&&t.constructor===e)return t;var n=RS.f(e);return(0,n.resolve)(t),n.promise},BS=L,VS=ax,HS=xx.CONSTRUCTOR,US=zS,K=N(`Promise`),WS=!HS;BS({target:`Promise`,stat:!0,forced:!0},{resolve:function(e){return US(WS&&this===K?VS:this,e)}});var GS=k,KS=Xe,qS=Sx,q=ix,JS=xy;L({target:`Promise`,stat:!0,forced:xS},{allSettled:function(e){var t=this,n=qS.f(t),r=n.resolve,i=n.reject,a=q((function(){var n=KS(t.resolve),i=[],a=0,o=1;JS(e,(function(e){var s=a++,c=!1;o++,GS(n,t,e).then((function(e){c||(c=!0,i[s]={status:`fulfilled`,value:e},--o||r(i))}),(function(e){c||(c=!0,i[s]={status:`rejected`,reason:e},--o||r(i))}))})),--o||r(i)}));return a.error&&i(a.value),n.promise}});var YS=k,J=Xe,XS=N,ZS=Sx,QS=ix,$S=xy,eC=`No one promise resolved`;L({target:`Promise`,stat:!0,forced:xS},{any:function(e){var t=this,n=XS(`AggregateError`),r=ZS.f(t),i=r.resolve,a=r.reject,o=QS((function(){var r=J(t.resolve),o=[],s=0,c=1,l=!1;$S(e,(function(e){var u=s++,d=!1;c++,YS(r,t,e).then((function(e){d||l||(l=!0,i(e))}),(function(e){d||l||(d=!0,o[u]=e,--c||a(new n(o,eC)))}))})),--c||a(new n(o,eC))}));return o.error&&a(o.value),r.promise}});var tC=L,nC=ax,rC=s,iC=N,aC=T,oC=nb,sC=zS,cC=nC&&nC.prototype;tC({target:`Promise`,proto:!0,real:!0,forced:!!nC&&rC((function(){cC.finally.call({then:function(){}},(function(){}))}))},{finally:function(e){var t=oC(this,iC(`Promise`)),n=aC(e);return this.then(n?function(n){return sC(t,e()).then((function(){return n}))}:e,n?function(n){return sC(t,e()).then((function(){throw n}))}:e)}});var lC=M.Promise,uC=Sx;L({target:`Promise`,stat:!0},{withResolvers:function(){var e=uC.f(this);return{promise:e.promise,resolve:e.resolve,reject:e.reject}}});var dC=lC,fC=Sx,pC=ix;L({target:`Promise`,stat:!0,forced:!0},{try:function(e){var t=fC.f(this),n=pC(e);return(n.error?t.reject:t.resolve)(n.value),t.promise}});var mC=dC,hC=Em;(function(e){var t=Gv.default,n=$n,r=Tu,i=Mv,a=Bv,o=Kv,s=hp,c=Pv,l=mC,u=hC,d=Ip;function f(){e.exports=f=function(){return m},e.exports.__esModule=!0,e.exports.default=e.exports;var p,m={},h=Object.prototype,g=h.hasOwnProperty,_=n||function(e,t,n){e[t]=n.value},v=typeof r==`function`?r:{},y=v.iterator||`@@iterator`,b=v.asyncIterator||`@@asyncIterator`,x=v.toStringTag||`@@toStringTag`;function S(e,t,r){return n(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{S({},``)}catch{S=function(e,t,n){return e[t]=n}}function ee(e,t,n,r){var a=i((t&&t.prototype instanceof E?t:E).prototype);return _(a,`_invoke`,{value:se(e,n,new de(r||[]))}),a}function C(e,t,n){try{return{type:`normal`,arg:e.call(t,n)}}catch(e){return{type:`throw`,arg:e}}}m.wrap=ee;var te=`suspendedStart`,ne=`suspendedYield`,w=`executing`,re=`completed`,T={};function E(){}function D(){}function O(){}var ie={};S(ie,y,(function(){return this}));var k=a&&a(a(fe([])));k&&k!==h&&g.call(k,y)&&(ie=k);var A=O.prototype=E.prototype=i(ie);function ae(e){var t;o(t=[`next`,`throw`,`return`]).call(t,(function(t){S(e,t,(function(e){return this._invoke(t,e)}))}))}function oe(e,n){function r(i,a,o,s){var c=C(e[i],e,a);if(c.type!==`throw`){var l=c.arg,u=l.value;return u&&t(u)==`object`&&g.call(u,`__await`)?n.resolve(u.__await).then((function(e){r(`next`,e,o,s)}),(function(e){r(`throw`,e,o,s)})):n.resolve(u).then((function(e){l.value=e,o(l)}),(function(e){return r(`throw`,e,o,s)}))}s(c.arg)}var i;_(this,`_invoke`,{value:function(e,t){function a(){return new n((function(n,i){r(e,t,n,i)}))}return i=i?i.then(a,a):a()}})}function se(e,t,n){var r=te;return function(i,a){if(r===w)throw Error(`Generator is already running`);if(r===re){if(i===`throw`)throw a;return{value:p,done:!0}}for(n.method=i,n.arg=a;;){var o=n.delegate;if(o){var s=ce(o,n);if(s){if(s===T)continue;return s}}if(n.method===`next`)n.sent=n._sent=n.arg;else if(n.method===`throw`){if(r===te)throw r=re,n.arg;n.dispatchException(n.arg)}else n.method===`return`&&n.abrupt(`return`,n.arg);r=w;var c=C(e,t,n);if(c.type===`normal`){if(r=n.done?re:ne,c.arg===T)continue;return{value:c.arg,done:n.done}}c.type===`throw`&&(r=re,n.method=`throw`,n.arg=c.arg)}}}function ce(e,t){var n=t.method,r=e.iterator[n];if(r===p)return t.delegate=null,n===`throw`&&e.iterator.return&&(t.method=`return`,t.arg=p,ce(e,t),t.method===`throw`)||n!==`return`&&(t.method=`throw`,t.arg=TypeError(`The iterator does not provide a '`+n+`' method`)),T;var i=C(r,e.iterator,t.arg);if(i.type===`throw`)return t.method=`throw`,t.arg=i.arg,t.delegate=null,T;var a=i.arg;return a?a.done?(t[e.resultName]=a.value,t.next=e.nextLoc,t.method!==`return`&&(t.method=`next`,t.arg=p),t.delegate=null,T):a:(t.method=`throw`,t.arg=TypeError(`iterator result is not an object`),t.delegate=null,T)}function le(e){var t,n={tryLoc:e[0]};1 in e&&(n.catchLoc=e[1]),2 in e&&(n.finallyLoc=e[2],n.afterLoc=e[3]),s(t=this.tryEntries).call(t,n)}function ue(e){var t=e.completion||{};t.type=`normal`,delete t.arg,e.completion=t}function de(e){this.tryEntries=[{tryLoc:`root`}],o(e).call(e,le,this),this.reset(!0)}function fe(e){if(e||e===``){var n=e[y];if(n)return n.call(e);if(typeof e.next==`function`)return e;if(!isNaN(e.length)){var r=-1,i=function t(){for(;++r<e.length;)if(g.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=p,t.done=!0,t};return i.next=i}}throw TypeError(t(e)+` is not iterable`)}return D.prototype=O,_(A,`constructor`,{value:O,configurable:!0}),_(O,`constructor`,{value:D,configurable:!0}),D.displayName=S(O,x,`GeneratorFunction`),m.isGeneratorFunction=function(e){var t=typeof e==`function`&&e.constructor;return!!t&&(t===D||(t.displayName||t.name)===`GeneratorFunction`)},m.mark=function(e){return c?c(e,O):(e.__proto__=O,S(e,x,`GeneratorFunction`)),e.prototype=i(A),e},m.awrap=function(e){return{__await:e}},ae(oe.prototype),S(oe.prototype,b,(function(){return this})),m.AsyncIterator=oe,m.async=function(e,t,n,r,i){i===void 0&&(i=l);var a=new oe(ee(e,t,n,r),i);return m.isGeneratorFunction(t)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},ae(A),S(A,x,`Generator`),S(A,y,(function(){return this})),S(A,`toString`,(function(){return`[object Generator]`})),m.keys=function(e){var t=Object(e),n=[];for(var r in t)s(n).call(n,r);return u(n).call(n),function e(){for(;n.length;){var r=n.pop();if(r in t)return e.value=r,e.done=!1,e}return e.done=!0,e}},m.values=fe,de.prototype={constructor:de,reset:function(e){var t;if(this.prev=0,this.next=0,this.sent=this._sent=p,this.done=!1,this.delegate=null,this.method=`next`,this.arg=p,o(t=this.tryEntries).call(t,ue),!e)for(var n in this)n.charAt(0)===`t`&&g.call(this,n)&&!isNaN(+d(n).call(n,1))&&(this[n]=p)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if(e.type===`throw`)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(n,r){return a.type=`throw`,a.arg=e,t.next=n,r&&(t.method=`next`,t.arg=p),!!r}for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r],a=i.completion;if(i.tryLoc===`root`)return n(`end`);if(i.tryLoc<=this.prev){var o=g.call(i,`catchLoc`),s=g.call(i,`finallyLoc`);if(o&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(o){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)throw Error(`try statement without catch or finally`);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&g.call(r,`finallyLoc`)&&this.prev<r.finallyLoc){var i=r;break}}i&&(e===`break`||e===`continue`)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method=`next`,this.next=i.finallyLoc,T):this.complete(a)},complete:function(e,t){if(e.type===`throw`)throw e.arg;return e.type===`break`||e.type===`continue`?this.next=e.arg:e.type===`return`?(this.rval=this.arg=e.arg,this.method=`return`,this.next=`end`):e.type===`normal`&&t&&(this.next=t),T},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),ue(n),T}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if(r.type===`throw`){var i=r.arg;ue(n)}return i}}throw Error(`illegal catch attempt`)},delegateYield:function(e,t,n){return this.delegate={iterator:fe(e),resultName:t,nextLoc:n},this.method===`next`&&(this.arg=p),T}},m}e.exports=f,e.exports.__esModule=!0,e.exports.default=e.exports})(Uv);var gC=(0,Uv.exports)(),_C=gC;try{regeneratorRuntime=gC}catch{typeof globalThis==`object`?globalThis.regeneratorRuntime=gC:Function(`r`,`regeneratorRuntime = r`)(gC)}var vC=r(_C),yC={exports:{}},bC=s((function(){if(typeof ArrayBuffer==`function`){var e=new ArrayBuffer(8);Object.isExtensible(e)&&Object.defineProperty(e,`a`,{value:8})}})),xC=s,SC=j,CC=S,wC=bC,TC=Object.isExtensible,EC=xC((function(){TC(1)}))||wC?function(e){return!!SC(e)&&(!wC||CC(e)!==`ArrayBuffer`)&&(!TC||TC(e))}:TC,DC=!s((function(){return Object.isExtensible(Object.preventExtensions({}))})),OC=L,kC=v,AC=Ei,jC=j,MC=_t,NC=_n.f,PC=ca,FC=da,IC=EC,LC=DC,RC=!1,zC=St(`meta`),BC=0,VC=function(e){NC(e,zC,{value:{objectID:`O`+ BC++,weakData:{}}})},HC=yC.exports={enable:function(){HC.enable=function(){},RC=!0;var e=PC.f,t=kC([].splice),n={};n[zC]=1,e(n).length&&(PC.f=function(n){for(var r=e(n),i=0,a=r.length;i<a;i++)if(r[i]===zC){t(r,i,1);break}return r},OC({target:`Object`,stat:!0,forced:!0},{getOwnPropertyNames:FC.f}))},fastKey:function(e,t){if(!jC(e))return typeof e==`symbol`?e:(typeof e==`string`?`S`:`P`)+e;if(!MC(e,zC)){if(!IC(e))return`F`;if(!t)return`E`;VC(e)}return e[zC].objectID},getWeakData:function(e,t){if(!MC(e,zC)){if(!IC(e))return!0;if(!t)return!1;VC(e)}return e[zC].weakData},onFreeze:function(e){return LC&&RC&&IC(e)&&!MC(e,zC)&&VC(e),e}};AC[zC]=!0;var UC=yC.exports,WC=L,GC=o,KC=UC,qC=s,JC=In,YC=xy,XC=Zy,ZC=T,QC=j,$C=he,ew=Xa,tw=_n.f,nw=xo.forEach,rw=D,iw=po.set,aw=po.getterFor,ow=function(e,t,n){var r,i=e.indexOf(`Map`)!==-1,a=e.indexOf(`Weak`)!==-1,o=i?`set`:`add`,s=GC[e],c=s&&s.prototype,l={};if(rw&&ZC(s)&&(a||c.forEach&&!qC((function(){new s().entries().next()})))){var u=(r=t((function(t,n){iw(XC(t,u),{type:e,collection:new s}),$C(n)||YC(n,t[o],{that:t,AS_ENTRIES:i})}))).prototype,d=aw(e);nw([`add`,`clear`,`delete`,`forEach`,`get`,`has`,`set`,`keys`,`values`,`entries`],(function(e){var t=e===`add`||e===`set`;!(e in c)||a&&e===`clear`||JC(u,e,(function(n,r){var i=d(this).collection;if(!t&&a&&!QC(n))return e===`get`&&void 0;var o=i[e](n===0?0:n,r);return t?this:o}))})),a||tw(u,`size`,{configurable:!0,get:function(){return d(this).collection.size}})}else r=n.getConstructor(t,e,i,o),KC.enable();return ew(r,e,!1,!0),l[e]=r,WC({global:!0,forced:!0},l),a||n.setStrong(r,e,i),r},sw=Ta,cw=sa,lw=Da,uw=function(e,t,n){for(var r in t)n&&n.unsafe&&e[r]?e[r]=t[r]:sw(e,r,t[r],n);return e},dw=gn,fw=Zy,pw=he,mw=xy,hw=Pl,gw=Fl,_w=Jy,vw=D,yw=UC.fastKey,bw=po.set,xw=po.getterFor,Sw={getConstructor:function(e,t,n,r){var i=e((function(e,i){fw(e,a),bw(e,{type:t,index:cw(null),first:void 0,last:void 0,size:0}),vw||(e.size=0),pw(i)||mw(i,e[r],{that:e,AS_ENTRIES:n})})),a=i.prototype,o=xw(t),s=function(e,t,n){var r,i,a=o(e),s=c(e,t);return s?s.value=n:(a.last=s={index:i=yw(t,!0),key:t,value:n,previous:r=a.last,next:void 0,removed:!1},a.first||=s,r&&(r.next=s),vw?a.size++:e.size++,i!==`F`&&(a.index[i]=s)),e},c=function(e,t){var n,r=o(e),i=yw(t);if(i!==`F`)return r.index[i];for(n=r.first;n;n=n.next)if(n.key===t)return n};return uw(a,{clear:function(){for(var e=o(this),t=e.index,n=e.first;n;)n.removed=!0,n.previous&&=n.previous.next=void 0,delete t[n.index],n=n.next;e.first=e.last=void 0,vw?e.size=0:this.size=0},delete:function(e){var t=this,n=o(t),r=c(t,e);if(r){var i=r.next,a=r.previous;delete n.index[r.index],r.removed=!0,a&&(a.next=i),i&&(i.previous=a),n.first===r&&(n.first=i),n.last===r&&(n.last=a),vw?n.size--:t.size--}return!!r},forEach:function(e){for(var t,n=o(this),r=dw(e,arguments.length>1?arguments[1]:void 0);t=t?t.next:n.first;)for(r(t.value,t.key,this);t&&t.removed;)t=t.previous},has:function(e){return!!c(this,e)}}),uw(a,n?{get:function(e){var t=c(this,e);return t&&t.value},set:function(e,t){return s(this,e===0?0:e,t)}}:{add:function(e){return s(this,e=e===0?0:e,e)}}),vw&&lw(a,`size`,{configurable:!0,get:function(){return o(this).size}}),i},setStrong:function(e,t,n){var r=t+` Iterator`,i=xw(t),a=xw(r);hw(e,t,(function(e,t){bw(this,{type:r,target:e,state:i(e),kind:t,last:void 0})}),(function(){for(var e=a(this),t=e.kind,n=e.last;n&&n.removed;)n=n.previous;return e.target&&(e.last=n=n?n.next:e.state.first)?gw(t===`keys`?n.key:t===`values`?n.value:[n.key,n.value],!1):(e.target=void 0,gw(void 0,!0))}),n?`entries`:`values`,!n,!0),_w(t)}};ow(`Map`,(function(e){return function(){return e(this,arguments.length?arguments[0]:void 0)}}),Sw);var Cw=r(M.Map),ww=xo.some;L({target:`Array`,proto:!0,forced:!Dd(`some`)},{some:function(e){return ww(this,e,arguments.length>1?arguments[1]:void 0)}});var Tw=fd(`Array`,`some`),Ew=P,Dw=Tw,Ow=Array.prototype,kw=r((function(e){var t=e.some;return e===Ow||Ew(Ow,e)&&t===Ow.some?Dw:t})),Aw=fd(`Array`,`keys`),jw=wr,Mw=_t,Nw=P,Pw=Aw,Fw=Array.prototype,Iw={DOMTokenList:!0,NodeList:!0},Lw=r((function(e){var t=e.keys;return e===Fw||Nw(Fw,e)&&t===Fw.keys||Mw(Iw,jw(e))?Pw:t})),Rw=_a,zw=Math.floor,Bw=function(e,t){var n=e.length,r=zw(n/2);return n<8?Vw(e,t):Hw(e,Bw(Rw(e,0,r),t),Bw(Rw(e,r),t),t)},Vw=function(e,t){for(var n,r,i=e.length,a=1;a<i;){for(r=a,n=e[a];r&&t(e[r-1],n)>0;)e[r]=e[--r];r!==a++&&(e[r]=n)}return e},Hw=function(e,t,n,r){for(var i=t.length,a=n.length,o=0,s=0;o<i||s<a;)e[o+s]=o<i&&s<a?r(t[o],n[s])<=0?t[o++]:n[s++]:o<i?t[o++]:n[s++];return e},Uw=Bw,Ww=F.match(/firefox\/(\d+)/i),Gw=!!Ww&&+Ww[1],Kw=/MSIE|Trident/.test(F),qw=F.match(/AppleWebKit\/(\d+)\./),Jw=!!qw&&+qw[1],Yw=L,Xw=v,Zw=Xe,Qw=mt,$w=lr,eT=Am,tT=hi,nT=s,rT=Uw,iT=Dd,aT=Gw,oT=Kw,sT=Pe,cT=Jw,lT=[],uT=Xw(lT.sort),dT=Xw(lT.push),fT=nT((function(){lT.sort(void 0)})),pT=nT((function(){lT.sort(null)})),mT=iT(`sort`),hT=!nT((function(){if(sT)return sT<70;if(!(aT&&aT>3)){if(oT)return!0;if(cT)return cT<603;var e,t,n,r,i=``;for(e=65;e<76;e++){switch(t=String.fromCharCode(e),e){case 66:case 69:case 70:case 72:n=3;break;case 68:case 71:n=4;break;default:n=2}for(r=0;r<47;r++)lT.push({k:t+r,v:n})}for(lT.sort((function(e,t){return t.v-e.v})),r=0;r<lT.length;r++)t=lT[r].k.charAt(0),i.charAt(i.length-1)!==t&&(i+=t);return i!==`DGBEFHACIJK`}}));Yw({target:`Array`,proto:!0,forced:fT||!pT||!mT||!hT},{sort:function(e){e!==void 0&&Zw(e);var t=Qw(this);if(hT)return e===void 0?uT(t):uT(t,e);var n,r,i=[],a=$w(t);for(r=0;r<a;r++)r in t&&dT(i,t[r]);for(rT(i,function(e){return function(t,n){return n===void 0?-1:t===void 0?1:e===void 0?tT(t)>tT(n)?1:-1:+e(t,n)||0}}(e)),n=$w(i),r=0;r<n;)t[r]=i[r++];for(;r<a;)eT(t,r++);return t}});var gT=fd(`Array`,`sort`),_T=P,vT=gT,yT=Array.prototype,bT=r((function(e){var t=e.sort;return e===yT||_T(yT,e)&&t===yT.sort?vT:t})),xT=fd(`Array`,`values`),ST=wr,CT=_t,wT=P,TT=xT,ET=Array.prototype,DT={DOMTokenList:!0,NodeList:!0},OT=r((function(e){var t=e.values;return e===ET||wT(ET,e)&&t===ET.values||CT(DT,ST(e))?TT:t})),kT=r(Uu),AT=fd(`Array`,`entries`),jT=wr,MT=_t,NT=P,PT=AT,FT=Array.prototype,IT={DOMTokenList:!0,NodeList:!0},LT=r((function(e){var t=e.entries;return e===FT||NT(FT,e)&&t===FT.entries||MT(IT,jT(e))?PT:t}));let RT,zT=new Uint8Array(16);function BT(){if(!RT&&(RT=typeof crypto<`u`&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!RT))throw Error(`crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported`);return RT(zT)}let VT=[];for(let e=0;e<256;++e)VT.push((e+256).toString(16).slice(1));var HT={randomUUID:typeof crypto<`u`&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function UT(e,t,n){if(HT.randomUUID&&!t&&!e)return HT.randomUUID();let r=(e||={}).random||(e.rng||BT)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n||=0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return function(e,t=0){return VT[e[t+0]]+VT[e[t+1]]+VT[e[t+2]]+VT[e[t+3]]+`-`+VT[e[t+4]]+VT[e[t+5]]+`-`+VT[e[t+6]]+VT[e[t+7]]+`-`+VT[e[t+8]]+VT[e[t+9]]+`-`+VT[e[t+10]]+VT[e[t+11]]+VT[e[t+12]]+VT[e[t+13]]+VT[e[t+14]]+VT[e[t+15]]}(r)}function WT(e){return typeof e==`string`||typeof e==`number`}var GT=function(){function e(n){t(this,e),Zu(this,`_queue`,[]),Zu(this,`_timeout`,null),Zu(this,`_extended`,null),this.delay=null,this.max=1/0,this.setOptions(n)}return Xu(e,[{key:`setOptions`,value:function(e){e&&e.delay!==void 0&&(this.delay=e.delay),e&&e.max!==void 0&&(this.max=e.max),this._flushIfNeeded()}},{key:`destroy`,value:function(){if(this.flush(),this._extended){for(var e=this._extended.object,t=this._extended.methods,n=0;n<t.length;n++){var r=t[n];r.original?e[r.name]=r.original:delete e[r.name]}this._extended=null}}},{key:`replace`,value:function(e,t){var n=this,r=e[t];if(!r)throw Error(`Method `+t+` undefined`);e[t]=function(){var e=[...arguments];n.queue({args:e,fn:r,context:this})}}},{key:`queue`,value:function(e){typeof e==`function`?this._queue.push({fn:e}):this._queue.push(e),this._flushIfNeeded()}},{key:`_flushIfNeeded`,value:function(){var e=this;this._queue.length>this.max&&this.flush(),this._timeout!=null&&(clearTimeout(this._timeout),this._timeout=null),this.queue.length>0&&typeof this.delay==`number`&&(this._timeout=H((function(){e.flush()}),this.delay))}},{key:`flush`,value:function(){var e,t;_m(e=Jm(t=this._queue).call(t,0)).call(e,(function(e){e.fn.apply(e.context||e.fn,e.args||[])}))}}],[{key:`extend`,value:function(t,n){var r=new e(n);if(t.flush!==void 0)throw Error(`Target object already has a property flush`);t.flush=function(){r.flush()};var i=[{name:`flush`,original:void 0}];if(n&&n.replace)for(var a=0;a<n.replace.length;a++){var o=n.replace[a];i.push({name:o,original:t[o]}),r.replace(t,o)}return r._extended={object:t,methods:i},r}}]),e}(),KT=function(){function e(){t(this,e),Zu(this,`_subscribers`,{"*":[],add:[],remove:[],update:[]}),Zu(this,`subscribe`,e.prototype.on),Zu(this,`unsubscribe`,e.prototype.off)}return Xu(e,[{key:`_trigger`,value:function(e,t,n){var r,i;if(e===`*`)throw Error(`Cannot trigger event *`);_m(r=Jp(i=[]).call(i,Hp(this._subscribers[e]),Hp(this._subscribers[`*`]))).call(r,(function(r){r(e,t,n??null)}))}},{key:`on`,value:function(e,t){typeof t==`function`&&this._subscribers[e].push(t)}},{key:`off`,value:function(e,t){var n;this._subscribers[e]=Bd(n=this._subscribers[e]).call(n,(function(e){return e!==t}))}}]),e}();ow(`Set`,(function(e){return function(){return e(this,arguments.length?arguments[0]:void 0)}}),Sw);var qT=r(M.Set),JT=r(Mf);function YT(e,t){var n=Up!==void 0&&$f(e)||e[`@@iterator`];if(!n){if(rm(e)||(n=function(e,t){var n;if(e){if(typeof e==`string`)return XT(e,t);var r=Yp(n=Object.prototype.toString.call(e)).call(n,8,-1);if(r===`Object`&&e.constructor&&(r=e.constructor.name),r===`Map`||r===`Set`)return Xf(e);if(r===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return XT(e,t)}}(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
47
47
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var a,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||n.return==null||n.return()}finally{if(s)throw a}}}}function XT(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var ZT=function(e){function n(e){t(this,n),this._pairs=e}return Xu(n,[{key:e,value:vC.mark((function e(){var t,n,r,i,a;return vC.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=YT(this._pairs),e.prev=1,t.s();case 3:if((n=t.n()).done){e.next=9;break}return r=Vp(n.value,2),i=r[0],a=r[1],e.next=7,[i,a];case 7:e.next=3;break;case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(1),t.e(e.t0);case 14:return e.prev=14,t.f(),e.finish(14);case 17:case`end`:return e.stop()}}),e,this,[[1,11,14,17]])}))},{key:`entries`,value:vC.mark((function e(){var t,n,r,i,a;return vC.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=YT(this._pairs),e.prev=1,t.s();case 3:if((n=t.n()).done){e.next=9;break}return r=Vp(n.value,2),i=r[0],a=r[1],e.next=7,[i,a];case 7:e.next=3;break;case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(1),t.e(e.t0);case 14:return e.prev=14,t.f(),e.finish(14);case 17:case`end`:return e.stop()}}),e,this,[[1,11,14,17]])}))},{key:`keys`,value:vC.mark((function e(){var t,n,r,i;return vC.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=YT(this._pairs),e.prev=1,t.s();case 3:if((n=t.n()).done){e.next=9;break}return r=Vp(n.value,1),i=r[0],e.next=7,i;case 7:e.next=3;break;case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(1),t.e(e.t0);case 14:return e.prev=14,t.f(),e.finish(14);case 17:case`end`:return e.stop()}}),e,this,[[1,11,14,17]])}))},{key:`values`,value:vC.mark((function e(){var t,n,r,i;return vC.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=YT(this._pairs),e.prev=1,t.s();case 3:if((n=t.n()).done){e.next=9;break}return r=Vp(n.value,2),i=r[1],e.next=7,i;case 7:e.next=3;break;case 9:e.next=14;break;case 11:e.prev=11,e.t0=e.catch(1),t.e(e.t0);case 14:return e.prev=14,t.f(),e.finish(14);case 17:case`end`:return e.stop()}}),e,this,[[1,11,14,17]])}))},{key:`toIdArray`,value:function(){var e;return Kd(e=Hp(this._pairs)).call(e,(function(e){return e[0]}))}},{key:`toItemArray`,value:function(){var e;return Kd(e=Hp(this._pairs)).call(e,(function(e){return e[1]}))}},{key:`toEntryArray`,value:function(){return Hp(this._pairs)}},{key:`toObjectMap`,value:function(){var e,t=hh(null),n=YT(this._pairs);try{for(n.s();!(e=n.n()).done;){var r=Vp(e.value,2),i=r[0];t[i]=r[1]}}catch(e){n.e(e)}finally{n.f()}return t}},{key:`toMap`,value:function(){return new Cw(this._pairs)}},{key:`toIdSet`,value:function(){return new qT(this.toIdArray())}},{key:`toItemSet`,value:function(){return new qT(this.toItemArray())}},{key:`cache`,value:function(){return new n(Hp(this._pairs))}},{key:`distinct`,value:function(e){var t,n=new qT,r=YT(this._pairs);try{for(r.s();!(t=r.n()).done;){var i=Vp(t.value,2),a=i[0],o=i[1];n.add(e(o,a))}}catch(e){r.e(e)}finally{r.f()}return n}},{key:`filter`,value:function(e){var t=this._pairs;return new n({[kT]:()=>vC.mark((function n(){var r,i,a,o,s;return vC.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:r=YT(t),n.prev=1,r.s();case 3:if((i=r.n()).done){n.next=10;break}if(a=Vp(i.value,2),o=a[0],s=a[1],!e(s,o)){n.next=8;break}return n.next=8,[o,s];case 8:n.next=3;break;case 10:n.next=15;break;case 12:n.prev=12,n.t0=n.catch(1),r.e(n.t0);case 15:return n.prev=15,r.f(),n.finish(15);case 18:case`end`:return n.stop()}}),n,null,[[1,12,15,18]])}))()})}},{key:`forEach`,value:function(e){var t,n=YT(this._pairs);try{for(n.s();!(t=n.n()).done;){var r=Vp(t.value,2),i=r[0];e(r[1],i)}}catch(e){n.e(e)}finally{n.f()}}},{key:`map`,value:function(e){var t=this._pairs;return new n({[kT]:()=>vC.mark((function n(){var r,i,a,o,s;return vC.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:r=YT(t),n.prev=1,r.s();case 3:if((i=r.n()).done){n.next=9;break}return a=Vp(i.value,2),o=a[0],s=a[1],n.next=7,[o,e(s,o)];case 7:n.next=3;break;case 9:n.next=14;break;case 11:n.prev=11,n.t0=n.catch(1),r.e(n.t0);case 14:return n.prev=14,r.f(),n.finish(14);case 17:case`end`:return n.stop()}}),n,null,[[1,11,14,17]])}))()})}},{key:`max`,value:function(e){var t=JT(this._pairs),n=t.next();if(n.done)return null;for(var r=n.value[1],i=e(n.value[1],n.value[0]);!(n=t.next()).done;){var a=Vp(n.value,2),o=a[0],s=a[1],c=e(s,o);c>i&&(i=c,r=s)}return r}},{key:`min`,value:function(e){var t=JT(this._pairs),n=t.next();if(n.done)return null;for(var r=n.value[1],i=e(n.value[1],n.value[0]);!(n=t.next()).done;){var a=Vp(n.value,2),o=a[0],s=a[1],c=e(s,o);c<i&&(i=c,r=s)}return r}},{key:`reduce`,value:function(e,t){var n,r=YT(this._pairs);try{for(r.s();!(n=r.n()).done;){var i=Vp(n.value,2),a=i[0];t=e(t,i[1],a)}}catch(e){r.e(e)}finally{r.f()}return t}},{key:`sort`,value:function(e){var t=this;return new n({[kT]:function(){var n;return JT(bT(n=Hp(t._pairs)).call(n,(function(t,n){var r=Vp(t,2),i=r[0],a=r[1],o=Vp(n,2),s=o[0],c=o[1];return e(a,c,i,s)})))}})}}]),n}(kT);function QT(e,t){var n=om(e);if(lv){var r=lv(e);t&&(r=Bd(r).call(r,(function(t){return vv(e,t).enumerable}))),n.push.apply(n,r)}return n}function $T(e){for(var t=1;t<arguments.length;t++){var n,r,i=arguments[t]==null?{}:arguments[t];t%2?_m(n=QT(Object(i),!0)).call(n,(function(t){Zu(e,t,i[t])})):Cv?Av(e,Cv(i)):_m(r=QT(Object(i))).call(r,(function(t){jv(e,t,vv(i,t))}))}return e}function eE(e,t){var n=Up!==void 0&&$f(e)||e[`@@iterator`];if(!n){if(rm(e)||(n=function(e,t){var n;if(e){if(typeof e==`string`)return tE(e,t);var r=Yp(n=Object.prototype.toString.call(e)).call(n,8,-1);if(r===`Object`&&e.constructor&&(r=e.constructor.name),r===`Map`||r===`Set`)return Xf(e);if(r===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return tE(e,t)}}(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
48
48
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var a,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||n.return==null||n.return()}finally{if(s)throw a}}}}function tE(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function nE(e){var t=function(){if(typeof Reflect>`u`||!cv||cv.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Boolean.prototype.valueOf.call(cv(Boolean,[],(function(){}))),!0}catch{return!1}}();return function(){var n,r=Hv(e);if(t){var i=Hv(this).constructor;n=cv(r,arguments,i)}else n=r.apply(this,arguments);return zv(this,n)}}var rE=function(e){Rv(r,e);var n=nE(r);function r(e,i){var a;return t(this,r),Zu(U(a=n.call(this)),`_queue`,null),e&&!rm(e)&&(i=e,e=[]),a._options=i||{},a._data=new Cw,a.length=0,a._idProp=a._options.fieldId||`id`,e&&e.length&&a.add(e),a.setOptions(i),a}return Xu(r,[{key:`idProp`,get:function(){return this._idProp}},{key:`setOptions`,value:function(e){e&&e.queue!==void 0&&(!1===e.queue?this._queue&&=(this._queue.destroy(),null):(this._queue||=GT.extend(this,{replace:[`add`,`update`,`remove`]}),e.queue&&typeof e.queue==`object`&&this._queue.setOptions(e.queue)))}},{key:`add`,value:function(e,t){var n,r=this,i=[];if(rm(e)){var a=Kd(e).call(e,(function(e){return e[r._idProp]}));if(kw(a).call(a,(function(e){return r._data.has(e)})))throw Error(`A duplicate id was found in the parameter array.`);for(var o=0,s=e.length;o<s;o++)n=this._addItem(e[o]),i.push(n)}else{if(!e||typeof e!=`object`)throw Error(`Unknown dataType`);n=this._addItem(e),i.push(n)}return i.length&&this._trigger(`add`,{items:i},t),i}},{key:`update`,value:function(e,t){var n=this,r=[],i=[],a=[],o=[],s=this._idProp,c=function(e){var t=e[s];if(t!=null&&n._data.has(t)){var c=e,l=ch({},n._data.get(t)),u=n._updateItem(c);i.push(u),o.push(c),a.push(l)}else{var d=n._addItem(e);r.push(d)}};if(rm(e))for(var l=0,u=e.length;l<u;l++)e[l]&&typeof e[l]==`object`?c(e[l]):console.warn(`Ignoring input item, which is not an object at index `+l);else{if(!e||typeof e!=`object`)throw Error(`Unknown dataType`);c(e)}if(r.length&&this._trigger(`add`,{items:r},t),i.length){var d={items:i,oldData:a,data:o};this._trigger(`update`,d,t)}return Jp(r).call(r,i)}},{key:`updateOnly`,value:function(e,t){var n,r=this;rm(e)||(e=[e]);var i=Kd(n=Kd(e).call(e,(function(e){var t=r._data.get(e[r._idProp]);if(t==null)throw Error(`Updating non-existent items is not allowed.`);return{oldData:t,update:e}}))).call(n,(function(e){var t=e.oldData,n=e.update,i=t[r._idProp],a=function(e){for(var t,n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return R_.apply(void 0,Jp(t=[{},e]).call(t,r))}(t,n);return r._data.set(i,a),{id:i,oldData:t,updatedData:a}}));if(i.length){var a={items:Kd(i).call(i,(function(e){return e.id})),oldData:Kd(i).call(i,(function(e){return e.oldData})),data:Kd(i).call(i,(function(e){return e.updatedData}))};return this._trigger(`update`,a,t),a.items}return[]}},{key:`get`,value:function(e,t){var n=void 0,r=void 0,i=void 0;WT(e)?(n=e,i=t):rm(e)?(r=e,i=t):i=e;var a=i&&i.returnType===`Object`?`Object`:`Array`,o=i&&Bd(i),s=[],c=void 0,l=void 0,u=void 0;if(n!=null)(c=this._data.get(n))&&o&&!o(c)&&(c=void 0);else if(r!=null)for(var d=0,f=r.length;d<f;d++)(c=this._data.get(r[d]))==null||o&&!o(c)||s.push(c);else for(var p,m=0,h=(l=Hp(Lw(p=this._data).call(p))).length;m<h;m++)u=l[m],(c=this._data.get(u))==null||o&&!o(c)||s.push(c);if(i&&i.order&&n==null&&this._sort(s,i.order),i&&i.fields){var g=i.fields;if(n!=null&&c!=null)c=this._filterFields(c,g);else for(var _=0,v=s.length;_<v;_++)s[_]=this._filterFields(s[_],g)}if(a==`Object`){for(var y={},b=0,x=s.length;b<x;b++){var S=s[b];y[S[this._idProp]]=S}return y}return n==null?s:c??null}},{key:`getIds`,value:function(e){var t=this._data,n=e&&Bd(e),r=e&&e.order,i=Hp(Lw(t).call(t)),a=[];if(n)if(r){for(var o=[],s=0,c=i.length;s<c;s++){var l=i[s],u=this._data.get(l);u!=null&&n(u)&&o.push(u)}this._sort(o,r);for(var d=0,f=o.length;d<f;d++)a.push(o[d][this._idProp])}else for(var p=0,m=i.length;p<m;p++){var h=i[p],g=this._data.get(h);g!=null&&n(g)&&a.push(g[this._idProp])}else if(r){for(var _=[],v=0,y=i.length;v<y;v++){var b=i[v];_.push(t.get(b))}this._sort(_,r);for(var x=0,S=_.length;x<S;x++)a.push(_[x][this._idProp])}else for(var ee=0,C=i.length;ee<C;ee++){var te=i[ee],ne=t.get(te);ne!=null&&a.push(ne[this._idProp])}return a}},{key:`getDataSet`,value:function(){return this}},{key:`forEach`,value:function(e,t){var n=t&&Bd(t),r=this._data,i=Hp(Lw(r).call(r));if(t&&t.order)for(var a=this.get(t),o=0,s=a.length;o<s;o++){var c=a[o];e(c,c[this._idProp])}else for(var l=0,u=i.length;l<u;l++){var d=i[l],f=this._data.get(d);f==null||n&&!n(f)||e(f,d)}}},{key:`map`,value:function(e,t){for(var n=t&&Bd(t),r=[],i=this._data,a=Hp(Lw(i).call(i)),o=0,s=a.length;o<s;o++){var c=a[o],l=this._data.get(c);l==null||n&&!n(l)||r.push(e(l,c))}return t&&t.order&&this._sort(r,t.order),r}},{key:`_filterFields`,value:function(e,t){var n;return e&&Pd(n=rm(t)?t:om(t)).call(n,(function(t,n){return t[n]=e[n],t}),{})}},{key:`_sort`,value:function(e,t){if(typeof t==`string`){var n=t;bT(e).call(e,(function(e,t){var r=e[n],i=t[n];return r>i?1:r<i?-1:0}))}else{if(typeof t!=`function`)throw TypeError(`Order must be a function or a string`);bT(e).call(e,t)}}},{key:`remove`,value:function(e,t){for(var n=[],r=[],i=rm(e)?e:[e],a=0,o=i.length;a<o;a++){var s=this._remove(i[a]);if(s){var c=s[this._idProp];c!=null&&(n.push(c),r.push(s))}}return n.length&&this._trigger(`remove`,{items:n,oldData:r},t),n}},{key:`_remove`,value:function(e){var t;if(WT(e)?t=e:e&&typeof e==`object`&&(t=e[this._idProp]),t!=null&&this._data.has(t)){var n=this._data.get(t)||null;return this._data.delete(t),--this.length,n}return null}},{key:`clear`,value:function(e){for(var t,n=Hp(Lw(t=this._data).call(t)),r=[],i=0,a=n.length;i<a;i++)r.push(this._data.get(n[i]));return this._data.clear(),this.length=0,this._trigger(`remove`,{items:n,oldData:r},e),n}},{key:`max`,value:function(e){var t,n,r=null,i=null,a=eE(OT(t=this._data).call(t));try{for(a.s();!(n=a.n()).done;){var o=n.value,s=o[e];typeof s==`number`&&(i==null||s>i)&&(r=o,i=s)}}catch(e){a.e(e)}finally{a.f()}return r||null}},{key:`min`,value:function(e){var t,n,r=null,i=null,a=eE(OT(t=this._data).call(t));try{for(a.s();!(n=a.n()).done;){var o=n.value,s=o[e];typeof s==`number`&&(i==null||s<i)&&(r=o,i=s)}}catch(e){a.e(e)}finally{a.f()}return r||null}},{key:`distinct`,value:function(e){for(var t=this._data,n=Hp(Lw(t).call(t)),r=[],i=0,a=0,o=n.length;a<o;a++){for(var s=n[a],c=t.get(s)[e],l=!1,u=0;u<i;u++)if(r[u]==c){l=!0;break}l||c===void 0||(r[i]=c,i++)}return r}},{key:`_addItem`,value:function(e){var t=function(e,t){return e[t]??(e[t]=UT()),e}(e,this._idProp),n=t[this._idProp];if(this._data.has(n))throw Error(`Cannot add item: item with id `+n+` already exists`);return this._data.set(n,t),++this.length,n}},{key:`_updateItem`,value:function(e){var t=e[this._idProp];if(t==null)throw Error(`Cannot update item: item has no id (item: `+vh(e)+`)`);var n=this._data.get(t);if(!n)throw Error(`Cannot update item: no item with id `+t+` found`);return this._data.set(t,$T($T({},n),e)),t}},{key:`stream`,value:function(e){if(e){var t=this._data;return new ZT({[kT]:()=>vC.mark((function n(){var r,i,a,o;return vC.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:r=eE(e),n.prev=1,r.s();case 3:if((i=r.n()).done){n.next=11;break}if(a=i.value,(o=t.get(a))==null){n.next=9;break}return n.next=9,[a,o];case 9:n.next=3;break;case 11:n.next=16;break;case 13:n.prev=13,n.t0=n.catch(1),r.e(n.t0);case 16:return n.prev=16,r.f(),n.finish(16);case 19:case`end`:return n.stop()}}),n,null,[[1,13,16,19]])}))()})}var n;return new ZT({[kT]:vd(n=LT(this._data)).call(n,this._data)})}}]),r}(KT);function iE(e,t){var n=Up!==void 0&&$f(e)||e[`@@iterator`];if(!n){if(rm(e)||(n=function(e,t){var n;if(e){if(typeof e==`string`)return aE(e,t);var r=Yp(n=Object.prototype.toString.call(e)).call(n,8,-1);if(r===`Object`&&e.constructor&&(r=e.constructor.name),r===`Map`||r===`Set`)return Xf(e);if(r===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return aE(e,t)}}(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
49
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var a,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||n.return==null||n.return()}finally{if(s)throw a}}}}function aE(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function oE(e){var t=function(){if(typeof Reflect>`u`||!cv||cv.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Boolean.prototype.valueOf.call(cv(Boolean,[],(function(){}))),!0}catch{return!1}}();return function(){var n,r=Hv(e);if(t){var i=Hv(this).constructor;n=cv(r,arguments,i)}else n=r.apply(this,arguments);return zv(this,n)}}var sE=function(e){Rv(r,e);var n=oE(r);function r(e,i){var a,o;return t(this,r),Zu(U(o=n.call(this)),`length`,0),Zu(U(o),`_ids`,new qT),o._options=i||{},o._listener=vd(a=o._onEvent).call(a,U(o)),o.setData(e),o}return Xu(r,[{key:`idProp`,get:function(){return this.getDataSet().idProp}},{key:`setData`,value:function(e){if(this._data){this._data.off&&this._data.off(`*`,this._listener);var t=this._data.getIds({filter:Bd(this._options)}),n=this._data.get(t);this._ids.clear(),this.length=0,this._trigger(`remove`,{items:t,oldData:n})}if(e!=null){this._data=e;for(var r=this._data.getIds({filter:Bd(this._options)}),i=0,a=r.length;i<a;i++){var o=r[i];this._ids.add(o)}this.length=r.length,this._trigger(`add`,{items:r})}else this._data=new rE;this._data.on&&this._data.on(`*`,this._listener)}},{key:`refresh`,value:function(){for(var e=this._data.getIds({filter:Bd(this._options)}),t=Hp(this._ids),n={},r=[],i=[],a=[],o=0,s=e.length;o<s;o++){var c=e[o];n[c]=!0,this._ids.has(c)||(r.push(c),this._ids.add(c))}for(var l=0,u=t.length;l<u;l++){var d=t[l],f=this._data.get(d);f==null?console.error(`If you see this, report it please.`):n[d]||(i.push(d),a.push(f),this._ids.delete(d))}this.length+=r.length-i.length,r.length&&this._trigger(`add`,{items:r}),i.length&&this._trigger(`remove`,{items:i,oldData:a})}},{key:`get`,value:function(e,t){if(this._data==null)return null;var n,r=null;WT(e)||rm(e)?(r=e,n=t):n=e;var i=ch({},this._options,n),a=Bd(this._options),o=n&&Bd(n);return a&&o&&(i.filter=function(e){return a(e)&&o(e)}),r==null?this._data.get(i):this._data.get(r,i)}},{key:`getIds`,value:function(e){if(this._data.length){var t,n=Bd(this._options),r=e==null?null:Bd(e);return t=r?n?function(e){return n(e)&&r(e)}:r:n,this._data.getIds({filter:t,order:e&&e.order})}return[]}},{key:`forEach`,value:function(e,t){if(this._data){var n,r,i=Bd(this._options),a=t&&Bd(t);r=a?i?function(e){return i(e)&&a(e)}:a:i,_m(n=this._data).call(n,e,{filter:r,order:t&&t.order})}}},{key:`map`,value:function(e,t){if(this._data){var n,r,i=Bd(this._options),a=t&&Bd(t);return r=a?i?function(e){return i(e)&&a(e)}:a:i,Kd(n=this._data).call(n,e,{filter:r,order:t&&t.order})}return[]}},{key:`getDataSet`,value:function(){return this._data.getDataSet()}},{key:`stream`,value:function(e){var t;return this._data.stream(e||{[kT]:vd(t=Lw(this._ids)).call(t,this._ids)})}},{key:`dispose`,value:function(){var e;(e=this._data)!=null&&e.off&&this._data.off(`*`,this._listener);var t,n=`This data view has already been disposed of.`,i={get:function(){throw Error(n)},set:function(){throw Error(n)},configurable:!1},a=iE(nm(r.prototype));try{for(a.s();!(t=a.n()).done;){var o=t.value;jv(this,o,i)}}catch(e){a.e(e)}finally{a.f()}}},{key:`_onEvent`,value:function(e,t,n){if(t&&t.items&&this._data){var r=t.items,i=[],a=[],o=[],s=[],c=[],l=[];switch(e){case`add`:for(var u=0,d=r.length;u<d;u++){var f=r[u];this.get(f)&&(this._ids.add(f),i.push(f))}break;case`update`:for(var p=0,m=r.length;p<m;p++){var h=r[p];this.get(h)?this._ids.has(h)?(a.push(h),c.push(t.data[p]),s.push(t.oldData[p])):(this._ids.add(h),i.push(h)):this._ids.has(h)&&(this._ids.delete(h),o.push(h),l.push(t.oldData[p]))}break;case`remove`:for(var g=0,_=r.length;g<_;g++){var v=r[g];this._ids.has(v)&&(this._ids.delete(v),o.push(v),l.push(t.oldData[g]))}}this.length+=i.length-o.length,i.length&&this._trigger(`add`,{items:i},n),a.length&&this._trigger(`update`,{items:a,oldData:s,data:c},n),o.length&&this._trigger(`remove`,{items:o,oldData:l},n)}}}]),r}(KT);function cE(e,t){return typeof t==`object`&&!!t&&e===t.idProp&&typeof t.add==`function`&&typeof t.clear==`function`&&typeof t.distinct==`function`&&typeof _m(t)==`function`&&typeof t.get==`function`&&typeof t.getDataSet==`function`&&typeof t.getIds==`function`&&typeof t.length==`number`&&typeof Kd(t)==`function`&&typeof t.max==`function`&&typeof t.min==`function`&&typeof t.off==`function`&&typeof t.on==`function`&&typeof t.remove==`function`&&typeof t.setOptions==`function`&&typeof t.stream==`function`&&typeof t.update==`function`&&typeof t.updateOnly==`function`}e.DELETE=L_,e.DataSet=rE,e.DataStream=ZT,e.DataView=sE,e.Queue=GT,e.createNewDataPipeFrom=function(e){return new uf(e)},e.isDataSetLike=cE,e.isDataViewLike=function(e,t){return typeof t==`object`&&!!t&&e===t.idProp&&typeof _m(t)==`function`&&typeof t.get==`function`&&typeof t.getDataSet==`function`&&typeof t.getIds==`function`&&typeof t.length==`number`&&typeof Kd(t)==`function`&&typeof t.off==`function`&&typeof t.on==`function`&&typeof t.stream==`function`&&cE(e,t.getDataSet())}}))}))(),S=b(),ee=n(),C=e(i(),1),te={LocalBusiness:`#2E5090`,Service:`#3A6BB0`,PriceSpecification:`#5B8DD0`,OpeningHoursSpecification:`#7AAFE8`,Person:`#C2410C`,UserProfile:`#EA580C`,Preference:`#F97316`,AdminUser:`#9A3412`,AccessGrant:`#7C2D12`,KnowledgeDocument:`#16A34A`,Section:`#22C55E`,Chunk:`#4ADE80`,DigitalDocument:`#15803D`,CreativeWork:`#86EFAC`,Question:`#A7F3D0`,FAQPage:`#34D399`,DefinedTerm:`#10B981`,Review:`#059669`,ImageObject:`#6EE7B7`,Conversation:`#7C3AED`,Message:`#A78BFA`,ToolCall:`#C4B5FD`,Task:`#DB2777`,Project:`#BE185D`,Event:`#EC4899`,Workflow:`#0891B2`,WorkflowStep:`#06B6D4`,WorkflowRun:`#22D3EE`,StepResult:`#67E8F9`,OnboardingState:`#8B5CF6`,Email:`#65A30D`,EmailAccount:`#84CC16`,ReviewAlert:`#DC2626`};Object.freeze(Object.keys(te));var ne=Object.freeze(new Set([`Chunk`,`GraphPreference`]));Object.freeze(new Set([`ToolCall`,`WorkflowRun`,`WorkflowStep`,`ReviewAlert`]));var w=o(),re=250,T=1200;function E(){let[e,t]=(0,C.useState)(null),[n,r]=(0,C.useState)(!1);return(0,C.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]),n?e?(0,w.jsxs)(`div`,{className:`data-page graph-page`,children:[(0,w.jsxs)(`header`,{className:`data-header`,children:[(0,w.jsxs)(`h1`,{className:`data-title`,children:[(0,w.jsx)(f,{size:18}),` Graph`]}),(0,w.jsx)(D,{})]}),(0,w.jsx)(`main`,{className:`graph-main`,children:(0,w.jsx)(O,{sessionKey:e})})]}):(0,w.jsxs)(`div`,{className:`data-page`,children:[(0,w.jsx)(`header`,{className:`data-header`,children:(0,w.jsxs)(`h1`,{className:`data-title`,children:[(0,w.jsx)(f,{size:18}),` Graph`]})}),(0,w.jsxs)(`div`,{className:`data-empty`,children:[(0,w.jsx)(`p`,{children:`You are not signed in.`}),(0,w.jsxs)(`p`,{children:[`Open the `,(0,w.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,w.jsx)(`div`,{className:`data-page`,children:(0,w.jsxs)(`div`,{className:`data-loading`,children:[(0,w.jsx)(s,{size:18,className:`spin`}),` Loading…`]})})}function D(){let[e,t]=(0,C.useState)(!1),n=(0,C.useRef)(null);(0,C.useEffect)(()=>{if(!e)return;let r=e=>{n.current&&(n.current.contains(e.target)||t(!1))},i=e=>{e.key===`Escape`&&t(!1)};return document.addEventListener(`mousedown`,r),document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`mousedown`,r),document.removeEventListener(`keydown`,i)}},[e]);let r=(0,C.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]);return(0,w.jsxs)(`div`,{className:`chat-burger-wrap`,ref:n,children:[(0,w.jsx)(`button`,{type:`button`,className:`chat-burger`,onClick:()=>t(e=>!e),"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":e,children:(0,w.jsx)(d,{size:20})}),e&&(0,w.jsxs)(`div`,{className:`chat-menu`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),window.location.href=`/`},children:[(0,w.jsx)(p,{size:14}),` Chat`]}),(0,w.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),window.location.href=`/data`},children:[(0,w.jsx)(u,{size:14}),` Data`]}),(0,w.jsx)(`div`,{className:`chat-menu-divider`}),(0,w.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),r()},children:[(0,w.jsx)(c,{size:14}),` Log out`]})]})]})}function O({sessionKey:e}){let t=(0,C.useRef)(null),n=(0,C.useRef)(null),i=(0,C.useRef)(null),a=(0,C.useRef)(null),o=(0,C.useRef)(new Map),c=(0,C.useRef)(null),u=(0,C.useRef)(null),d=(0,C.useRef)(null),f=(0,C.useRef)(null),[p,m]=(0,C.useState)({kind:`filter`,selectedLabels:[],includeTrashed:!1}),[y,b]=(0,C.useState)(!1),[ee,E]=(0,C.useState)(null),[D,O]=(0,C.useState)(null),[oe,ce]=(0,C.useState)(0),[le,ue]=(0,C.useState)(null),[de,fe]=(0,C.useState)(!1),[pe,me]=(0,C.useState)(!1),[he,ge]=(0,C.useState)(null),[_e,ve]=(0,C.useState)(``),[ye,be]=(0,C.useState)(``),[xe,Se]=(0,C.useState)(null),[Ce,j]=(0,C.useState)(null),[M,we]=(0,C.useState)([]),[Te,Ee]=(0,C.useState)({labels:[],includeTrashed:!1}),[De,N]=(0,C.useState)(!1),[P,F]=(0,C.useState)(!1),Oe=(0,C.useRef)(!1),ke=(0,C.useRef)(null),Ae=(0,C.useMemo)(()=>{let e=new Set;for(let t of o.current.values())for(let n of t.labels)e.add(n);return[...e].sort()},[oe]);(0,C.useEffect)(()=>{let t=!1,n=fetch(`/api/admin/graph-labels-in-graph?session_key=${encodeURIComponent(e)}`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).catch(e=>{let t=e instanceof Error?e.message:String(e);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-labels-in-graph`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}return{labels:[]}}),r=fetch(`/api/admin/graph-default-view?session_key=${encodeURIComponent(e)}`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).catch(e=>{let t=e instanceof Error?e.message:String(e);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-default-view`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}return{labels:[],includeTrashed:!1}});return Promise.all([n,r]).then(([e,n])=>{if(t)return;let r=e.labels.filter(e=>!e.childOnly);if(we(r),Ee(n),!Oe.current){Oe.current=!0;let e=new Set(r.map(e=>e.label)),t=n.labels.filter(t=>e.has(t));(t.length>0||n.includeTrashed)&&(f.current={selectedLabels:[...t],includeTrashed:n.includeTrashed},m({kind:`filter`,selectedLabels:t,includeTrashed:n.includeTrashed}))}}),()=>{t=!0}},[e]),(0,C.useEffect)(()=>{if(!De)return;let e=e=>{ke.current&&(ke.current.contains(e.target)||N(!1))},t=e=>{e.key===`Escape`&&N(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[De]);let je=(0,C.useCallback)(()=>{if(i.current)try{i.current.clear()}catch{}if(a.current)try{a.current.clear()}catch{}},[]),Me=(0,C.useCallback)((t,r)=>{ge(null),fetch(`/api/admin/graph-delete?session_key=${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({elementId:t,by:`graph-drag-trash`})}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);ue(null);try{n.current?.unselectAll()}catch{}m(e=>{if(e.kind===`neighbourhood`){let e=f.current??{selectedLabels:[],includeTrashed:!1};return{kind:`filter`,selectedLabels:[...e.selectedLabels],includeTrashed:e.includeTrashed}}return{kind:`filter`,selectedLabels:[...e.selectedLabels],includeTrashed:e.includeTrashed}})}).catch(e=>{let n=e instanceof Error?e.message:String(e);ge(`Failed to delete: ${n}`),me(!0),window.setTimeout(()=>me(!1),T);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-drag-delete`,elementId:t,label:r,msg:n}),keepalive:!0}).catch(()=>{})}catch{}})},[e]);(0,C.useEffect)(()=>{if(p.kind===`filter`&&p.selectedLabels.length===0){c.current?.abort(),c.current=null,b(!1),E(null),O(null),ce(0),o.current=new Map,je();return}let t=window.setTimeout(()=>{c.current?.abort();let t=new AbortController;c.current=t,b(!0),E(null),O(null);let n=k(e,p);fetch(n,{signal:t.signal}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(e.status===413)throw new A(t);if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t.signal.aborted||(o.current=new Map(e.nodes.map(e=>[e.id,e])),ce(e.nodes.length),Ne(e.nodes,e.edges))}).catch(e=>{if(!t.signal.aborted){if(e instanceof A){O(e.body),ce(0),o.current=new Map,je();return}E(e instanceof Error?e.message:String(e))}}).finally(()=>{t.signal.aborted||b(!1)})},re);return()=>{window.clearTimeout(t)}},[e,p,je]),(0,C.useEffect)(()=>()=>{c.current?.abort(),n.current?.destroy(),n.current=null},[]);let Ne=(0,C.useCallback)((e,r)=>{if(!t.current)return;let s=e.map(e=>{let t=e.labels[0]??`Unknown`,n=te[t]??`#94A3B8`;return e.trashed?{id:e.id,label:ae(e),title:se(e),color:{background:`${n}40`,border:n},borderWidth:2,shapeProperties:{borderDashes:[6,4]},group:t}:{id:e.id,label:ae(e),title:se(e),color:n,group:t}}),c=r.map(e=>({id:e.id,from:e.from,to:e.to,label:e.type}));i.current=new x.DataSet(s),a.current=new x.DataSet(c);let l={autoResize:!0,layout:{improvedLayout:!1},physics:{solver:`forceAtlas2Based`,forceAtlas2Based:{gravitationalConstant:-50,springLength:90,springConstant:.08},stabilization:{iterations:200}},nodes:{shape:`dot`,size:14,font:{color:`#1F2937`,size:12,face:`DM Sans, sans-serif`},borderWidth:0},edges:{arrows:{to:{enabled:!0,scaleFactor:.4}},color:{color:`#CBD5E1`,highlight:`#475569`},font:{color:`#64748B`,size:9,face:`DM Sans, sans-serif`,align:`middle`,strokeWidth:0},smooth:{enabled:!0,type:`continuous`,roundness:.4},width:1},interaction:{hover:!0,tooltipDelay:150}};try{n.current?.destroy();let e=new S.Network(t.current,{nodes:i.current,edges:a.current},l);n.current=e,e.on(`selectNode`,e=>{let t=e.nodes[0],n=o.current.get(t);n&&(ue(n),m(e=>{if(n.trashed)return e;if(e.kind===`filter`)return f.current={selectedLabels:[...e.selectedLabels],includeTrashed:e.includeTrashed},{kind:`neighbourhood`,rootElementId:t,rootLabel:n.labels[0]??null};if(e.kind===`neighbourhood`&&e.rootElementId!==t){try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-neighbourhood-pivot`,msg:`from=${e.rootElementId} to=${t} label=${n.labels[0]??`null`}`}),keepalive:!0}).catch(()=>{})}catch{}return{kind:`neighbourhood`,rootElementId:t,rootLabel:n.labels[0]??null}}return e}))}),e.on(`deselectNode`,()=>{ue(null),m(e=>{if(e.kind!==`neighbourhood`)return e;let t=f.current??{selectedLabels:[],includeTrashed:!1};return{kind:`filter`,selectedLabels:[...t.selectedLabels],includeTrashed:t.includeTrashed}})});let r=e=>{let n=t.current,r=u.current;if(!n||!r)return!1;let i=n.getBoundingClientRect(),a=r.getBoundingClientRect(),o=i.left+e.x,s=i.top+e.y;return o>=a.left&&o<=a.right&&s>=a.top&&s<=a.bottom};e.on(`dragStart`,e=>{let t=e.nodes[0];if(!t){d.current=null;return}d.current=t}),e.on(`dragging`,e=>{if(!d.current)return;let t=r(e.pointer.DOM);fe(e=>e===t?e:t)}),e.on(`dragEnd`,e=>{let t=d.current;d.current=null,fe(!1),t&&r(e.pointer.DOM)&&Me(t,o.current.get(t)?.labels[0]??`Unknown`)})}catch(e){let t=e instanceof Error?e.message:String(e);E(`Visualisation failed to load: ${t}`);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-render`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}}},[]);(0,C.useEffect)(()=>{let e=_e.trim();if(!e){be(``),Se(null),j(null),n.current?.unselectAll();return}let t=setTimeout(()=>be(e),300);return()=>clearTimeout(t)},[_e]);let Pe=(0,C.useCallback)(e=>{let t=n.current;if(!t)return;let r=[];for(let t of e)o.current.has(t.nodeId)&&r.push(t.nodeId);r.length>0&&(t.selectNodes(r,!0),t.fit({nodes:r,animation:{duration:400,easingFunction:`easeInOutQuad`}}))},[]);(0,C.useEffect)(()=>{if(!ye)return;let t=!1;j(null);let n=`/api/admin/graph-search?session_key=${encodeURIComponent(e)}&q=${encodeURIComponent(ye)}&limit=20`;return fetch(n).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{if(t)return;Se(e.results),Pe(e.results);let n=new Set;for(let t of e.results)for(let e of t.labels)ne.has(e)||n.add(e);n.size!==0&&m(e=>{if(e.kind!==`filter`)return e;let t=new Set(e.selectedLabels),r=0;for(let e of n)t.has(e)||(t.add(e),r++);return r===0?e:{kind:`filter`,selectedLabels:[...t].sort(),includeTrashed:e.includeTrashed}})}).catch(e=>{t||j(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[ye,e,Pe]);let Fe=(0,C.useMemo)(()=>{if(!xe)return 0;let e=0;for(let t of xe)o.current.has(t.nodeId)||e++;return e},[xe,oe]),Ie=(0,C.useCallback)(e=>{m(t=>{if(t.kind!==`filter`)return{kind:`filter`,selectedLabels:[e],includeTrashed:!1};let n=new Set(t.selectedLabels);return n.has(e)?n.delete(e):n.add(e),{kind:`filter`,selectedLabels:[...n].sort(),includeTrashed:t.includeTrashed}})},[]),Le=(0,C.useCallback)(()=>{m(e=>e.kind===`filter`?{...e,includeTrashed:!e.includeTrashed}:{kind:`filter`,selectedLabels:[],includeTrashed:!0})},[]),Re=(0,C.useCallback)(()=>{ve(``),be(``),Se(null),j(null);try{n.current?.unselectAll()}catch{}},[]),ze=(0,C.useCallback)(()=>{m(e=>(e.kind,{kind:`filter`,selectedLabels:[],includeTrashed:!1}))},[]),Be=(0,C.useCallback)(()=>{ue(null);try{n.current?.unselectAll()}catch{}m(e=>{if(e.kind!==`neighbourhood`)return e;let t=f.current??{selectedLabels:[],includeTrashed:!1};return{kind:`filter`,selectedLabels:[...t.selectedLabels],includeTrashed:t.includeTrashed}})},[]),Ve=(0,C.useCallback)(()=>{if(p.kind!==`filter`)return;let t={labels:[...p.selectedLabels].sort(),includeTrashed:p.includeTrashed};F(!0),fetch(`/api/admin/graph-default-view?session_key=${encodeURIComponent(e)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}).then(async e=>{if(!e.ok){let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));throw Error(t.error??`HTTP ${e.status}`)}Ee(t)}).catch(e=>{let t=e instanceof Error?e.message:String(e);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-default-view-save`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}}).finally(()=>F(!1))},[e,p]),He=(0,C.useCallback)(()=>{ue(null);try{n.current?.unselectAll()}catch{}m(e=>e.kind===`filter`?{kind:`filter`,selectedLabels:[...e.selectedLabels],includeTrashed:e.includeTrashed}:{...e})},[]),Ue=p.kind===`neighbourhood`,We=p.kind===`filter`?p.selectedLabels:[],Ge=p.kind===`filter`?p.includeTrashed:!1,Ke=(0,C.useMemo)(()=>{if(p.kind!==`filter`)return!1;if(Ge!==Te.includeTrashed||We.length!==Te.labels.length)return!0;for(let e=0;e<We.length;e++)if(We[e]!==Te.labels[e])return!0;return!1},[p.kind,Ge,We,Te]);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`graph-toolbar`,children:[(0,w.jsxs)(`div`,{className:`data-search-input graph-search-input`,children:[(0,w.jsx)(l,{size:14}),(0,w.jsx)(`input`,{type:`text`,placeholder:`Search nodes…`,value:_e,onChange:e=>ve(e.target.value),autoComplete:`off`,spellCheck:!1}),ye&&!xe&&!Ce&&(0,w.jsx)(s,{size:14,className:`spin`}),_e.length>0&&(0,w.jsx)(`button`,{type:`button`,className:`graph-search-clear`,onClick:Re,"aria-label":`Clear search`,title:`Clear search`,children:(0,w.jsx)(h,{size:14})})]}),!Ue&&(0,w.jsxs)(`div`,{className:`graph-filter-wrap`,ref:ke,children:[(0,w.jsxs)(`button`,{type:`button`,className:`graph-filter-toggle${De?` is-open`:``}${We.length>0||Ge?` has-selection`:``}`,onClick:()=>N(e=>!e),"aria-haspopup":`true`,"aria-expanded":De,"aria-label":`Filter node types`,children:[(0,w.jsx)(v,{size:14}),(0,w.jsx)(`span`,{children:`Filter`}),We.length>0&&(0,w.jsx)(`span`,{className:`graph-filter-count`,children:We.length})]}),De&&(0,w.jsxs)(`div`,{className:`graph-filter-popover`,role:`dialog`,"aria-label":`Node type filter`,children:[(0,w.jsxs)(`div`,{className:`graph-filter-popover-header`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`graph-toggle-trashed${Ge?` active`:``}`,onClick:Le,"aria-pressed":Ge,title:`Show trashed nodes — restored with Restore button on each node`,children:[(0,w.jsx)(_,{size:14}),` Show trashed`]}),(We.length>0||Ge)&&(0,w.jsx)(`button`,{type:`button`,className:`graph-filter-clear`,onClick:ze,"aria-label":`Clear filter selection`,title:`Clear filter selection`,children:(0,w.jsx)(h,{size:14})})]}),M.length===0&&(0,w.jsx)(`p`,{className:`graph-filter-popover-empty`,children:`No node types in your graph yet.`}),(0,w.jsx)(`div`,{className:`graph-filter-rows`,role:`group`,"aria-label":`Node type filter`,children:M.map(({label:e,nodeCount:t})=>{let n=We.includes(e),r=te[e]??`#94A3B8`;return(0,w.jsxs)(`button`,{type:`button`,className:`graph-filter-row${n?` active`:``}`,onClick:()=>Ie(e),"aria-pressed":n,children:[(0,w.jsx)(`span`,{className:`graph-filter-row-swatch`,style:{backgroundColor:r}}),(0,w.jsx)(`span`,{className:`graph-filter-row-label`,children:e}),(0,w.jsx)(`span`,{className:`graph-filter-row-count`,children:t})]},e)})}),(0,w.jsx)(`div`,{className:`graph-filter-popover-footer`,children:(0,w.jsx)(`button`,{type:`button`,className:`graph-filter-set-default`,onClick:Ve,disabled:!Ke||P,children:P?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(s,{size:12,className:`spin`}),` Saving…`]}):`Set default view`})})]})]}),(0,w.jsxs)(`div`,{className:`graph-meta`,children:[Ue&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`button`,{type:`button`,className:`graph-back-to-filter graph-back-desktop`,onClick:Be,children:`← Back`}),(0,w.jsx)(`button`,{type:`button`,className:`graph-back-to-filter graph-back-mobile`,onClick:Be,"aria-label":`Back`,children:(0,w.jsx)(g,{size:16})})]}),oe>0&&(0,w.jsxs)(`span`,{className:`graph-meta-count`,children:[oe,` node`,oe===1?``:`s`]})]})]}),Ce&&(0,w.jsxs)(`div`,{className:`data-error graph-error-banner`,children:[`Search unavailable: `,Ce]}),xe&&xe.length===0&&!Ce&&(0,w.jsx)(`div`,{className:`graph-search-status`,children:`No matches in your graph.`}),xe&&Fe>0&&(0,w.jsxs)(`div`,{className:`graph-search-status`,children:[Fe,` match`,Fe===1?``:`es`,` not in current view. Adjust your filter or search more specifically.`]}),(0,w.jsxs)(`div`,{className:`graph-canvas-wrap`,children:[y&&(0,w.jsxs)(`div`,{className:`graph-canvas-overlay`,children:[(0,w.jsx)(s,{size:20,className:`spin`}),` Loading your graph…`]}),ee&&!y&&(0,w.jsxs)(`div`,{className:`graph-canvas-overlay graph-canvas-error`,children:[(0,w.jsx)(`p`,{children:ee}),(0,w.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:()=>window.location.reload(),children:`Retry`})]}),D&&!y&&(0,w.jsxs)(`div`,{className:`graph-canvas-overlay graph-canvas-error`,children:[(0,w.jsxs)(`p`,{children:[`Refine your filter — `,(0,w.jsx)(`strong`,{children:D.matched}),` matches exceed the 2000 cap.`]}),(0,w.jsx)(`p`,{className:`graph-canvas-hint`,children:`Pick a more specific label combination, or narrow your brand's data.`})]}),!y&&!ee&&!D&&oe===0&&!Ue&&We.length===0&&(0,w.jsxs)(`div`,{className:`graph-canvas-overlay`,children:[(0,w.jsx)(v,{size:20}),(0,w.jsx)(`p`,{children:`Open Filter to pick a node type and see what's in your graph.`})]}),!y&&!ee&&!D&&oe===0&&!Ue&&We.length>0&&(0,w.jsx)(`div`,{className:`graph-canvas-overlay`,children:(0,w.jsxs)(`p`,{children:[`No `,We.join(`, `),` nodes in your graph yet.`]})}),(0,w.jsx)(`div`,{ref:t,className:`graph-canvas`}),oe>0&&(0,w.jsx)(`div`,{ref:u,className:`graph-trash-drop-zone${de?` is-hover`:``}${pe?` is-error`:``}`,"aria-hidden":`true`,children:(0,w.jsx)(r,{size:18})}),he&&(0,w.jsxs)(`div`,{className:`graph-drag-error-banner`,role:`alert`,children:[(0,w.jsx)(`span`,{children:he}),(0,w.jsx)(`button`,{type:`button`,className:`graph-drag-error-dismiss`,onClick:()=>ge(null),"aria-label":`Dismiss`,children:(0,w.jsx)(h,{size:14})})]})]}),le&&(0,w.jsx)(ie,{node:le,sessionKey:e,onClose:()=>{ue(null);try{n.current?.unselectAll()}catch{}},onRestored:He}),oe>0&&Ae.length>0&&(0,w.jsx)(`div`,{className:`graph-legend`,children:Ae.map(e=>(0,w.jsxs)(`div`,{className:`graph-legend-item`,children:[(0,w.jsx)(`span`,{className:`graph-legend-swatch`,style:{backgroundColor:te[e]??`#94A3B8`}}),(0,w.jsx)(`span`,{children:e})]},e))})]})}function ie({node:e,sessionKey:t,onClose:n,onRestored:r}){let i=Object.entries(e.properties).filter(([,e])=>e!=null),[a,o]=(0,C.useState)(!1),[c,l]=(0,C.useState)(null);(0,C.useEffect)(()=>{o(!1),l(null)},[e.id]);let u=(0,C.useCallback)(()=>{o(!0),l(null),fetch(`/api/admin/graph-restore?session_key=${encodeURIComponent(t)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({elementId:e.id})}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);r()}).catch(e=>{l(e instanceof Error?e.message:String(e)),o(!1)})},[e.id,r,t]);return(0,w.jsxs)(`aside`,{className:`graph-side-panel${e.trashed?` graph-side-panel-trashed`:``}`,children:[(0,w.jsxs)(`header`,{className:`graph-side-header`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsxs)(`div`,{className:`graph-side-labels`,children:[e.labels.join(` · `),e.trashed?` · Trashed`:``]}),(0,w.jsx)(`div`,{className:`graph-side-id`,children:e.id})]}),(0,w.jsx)(`button`,{type:`button`,className:`graph-side-close`,onClick:n,"aria-label":`Close`,children:(0,w.jsx)(h,{size:14})})]}),e.trashed&&(0,w.jsxs)(`dl`,{className:`graph-side-props graph-side-trash-meta`,children:[(0,w.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,w.jsx)(`dt`,{children:`trashedAt`}),(0,w.jsx)(`dd`,{children:ce(e.properties.trashedAt)})]}),(0,w.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,w.jsx)(`dt`,{children:`trashedBy`}),(0,w.jsx)(`dd`,{children:ce(e.properties.trashedBy)})]})]}),(0,w.jsxs)(`dl`,{className:`graph-side-props`,children:[i.length===0&&(0,w.jsx)(`div`,{className:`graph-side-empty`,children:`No properties.`}),i.map(([e,t])=>(0,w.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,w.jsx)(`dt`,{children:e}),(0,w.jsx)(`dd`,{children:ce(t)})]},e))]}),e.trashed&&(0,w.jsxs)(`footer`,{className:`graph-side-footer`,children:[!a&&!c&&(0,w.jsxs)(`button`,{type:`button`,className:`graph-side-restore`,onClick:u,children:[(0,w.jsx)(m,{size:14}),` Restore`]}),a&&(0,w.jsx)(`div`,{className:`graph-delete-confirm`,children:(0,w.jsxs)(`p`,{children:[(0,w.jsx)(s,{size:14,className:`spin`}),` Restoring…`]})}),c&&(0,w.jsxs)(`div`,{className:`graph-delete-confirm graph-delete-confirm-error`,children:[(0,w.jsxs)(`p`,{children:[`Restore failed: `,c]}),(0,w.jsxs)(`div`,{className:`graph-delete-confirm-buttons`,children:[(0,w.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-cancel`,onClick:()=>{l(null)},children:`Close`}),(0,w.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-do`,onClick:u,children:`Retry`})]})]})]})]})}function k(e,t){let n=`/api/admin/graph-subgraph?session_key=${encodeURIComponent(e)}`;return t.kind===`neighbourhood`?`${n}&mode=neighbourhood&elementId=${encodeURIComponent(t.rootElementId)}`:`${n}&mode=default&labels=${encodeURIComponent(t.selectedLabels.join(`,`))}${t.includeTrashed?`&includeTrashed=1`:``}`}var A=class extends Error{body;constructor(e){super(e.error),this.body=e}};function ae(e){let t=e.properties,n=e.labels[0];if(n===`ToolCall`){let e=t.toolName;if(typeof e==`string`&&e.length>0)return e.length>24?e.slice(0,24)+`…`:e}else if(n===`WorkflowRun`){let e=t.startedAt;if(typeof e==`string`&&e.length>0){let t=oe(e);if(t)return t}}else if(n===`WorkflowStep`){let e=t.label;if(typeof e==`string`&&e.length>0)return e.length>24?e.slice(0,24)+`…`:e}for(let e of[`name`,`title`,`summary`,`givenName`,`subject`,`text`]){let n=t[e];if(typeof n==`string`&&n.length>0)return n.length>24?n.slice(0,24)+`…`:n}if(n===`Conversation`){let e=typeof t.conversationId==`string`?t.conversationId:null;if(e)return`Conv ${e.slice(0,8)}`}return n??`…`}function oe(e){let t=/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})/.exec(e);return t?`${t[1]} ${t[2]}`:null}function se(e){return`${e.labels.join(` · `)}\nid: ${e.id}`}function ce(e){if(e==null)return``;if(Array.isArray(e))return e.length>8?`[${e.length} items]`:e.map(String).join(`, `);if(typeof e==`object`)return`year`in e&&`month`in e&&`day`in e&&typeof e.year==`object`?`[unserialised temporal] ${JSON.stringify(e)}`:JSON.stringify(e);let t=String(e);return t.length>400?t.slice(0,400)+`…`:t}(0,ee.createRoot)(document.getElementById(`root`)).render((0,w.jsx)(E,{}));
49
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var a,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||n.return==null||n.return()}finally{if(s)throw a}}}}function aE(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function oE(e){var t=function(){if(typeof Reflect>`u`||!cv||cv.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Boolean.prototype.valueOf.call(cv(Boolean,[],(function(){}))),!0}catch{return!1}}();return function(){var n,r=Hv(e);if(t){var i=Hv(this).constructor;n=cv(r,arguments,i)}else n=r.apply(this,arguments);return zv(this,n)}}var sE=function(e){Rv(r,e);var n=oE(r);function r(e,i){var a,o;return t(this,r),Zu(U(o=n.call(this)),`length`,0),Zu(U(o),`_ids`,new qT),o._options=i||{},o._listener=vd(a=o._onEvent).call(a,U(o)),o.setData(e),o}return Xu(r,[{key:`idProp`,get:function(){return this.getDataSet().idProp}},{key:`setData`,value:function(e){if(this._data){this._data.off&&this._data.off(`*`,this._listener);var t=this._data.getIds({filter:Bd(this._options)}),n=this._data.get(t);this._ids.clear(),this.length=0,this._trigger(`remove`,{items:t,oldData:n})}if(e!=null){this._data=e;for(var r=this._data.getIds({filter:Bd(this._options)}),i=0,a=r.length;i<a;i++){var o=r[i];this._ids.add(o)}this.length=r.length,this._trigger(`add`,{items:r})}else this._data=new rE;this._data.on&&this._data.on(`*`,this._listener)}},{key:`refresh`,value:function(){for(var e=this._data.getIds({filter:Bd(this._options)}),t=Hp(this._ids),n={},r=[],i=[],a=[],o=0,s=e.length;o<s;o++){var c=e[o];n[c]=!0,this._ids.has(c)||(r.push(c),this._ids.add(c))}for(var l=0,u=t.length;l<u;l++){var d=t[l],f=this._data.get(d);f==null?console.error(`If you see this, report it please.`):n[d]||(i.push(d),a.push(f),this._ids.delete(d))}this.length+=r.length-i.length,r.length&&this._trigger(`add`,{items:r}),i.length&&this._trigger(`remove`,{items:i,oldData:a})}},{key:`get`,value:function(e,t){if(this._data==null)return null;var n,r=null;WT(e)||rm(e)?(r=e,n=t):n=e;var i=ch({},this._options,n),a=Bd(this._options),o=n&&Bd(n);return a&&o&&(i.filter=function(e){return a(e)&&o(e)}),r==null?this._data.get(i):this._data.get(r,i)}},{key:`getIds`,value:function(e){if(this._data.length){var t,n=Bd(this._options),r=e==null?null:Bd(e);return t=r?n?function(e){return n(e)&&r(e)}:r:n,this._data.getIds({filter:t,order:e&&e.order})}return[]}},{key:`forEach`,value:function(e,t){if(this._data){var n,r,i=Bd(this._options),a=t&&Bd(t);r=a?i?function(e){return i(e)&&a(e)}:a:i,_m(n=this._data).call(n,e,{filter:r,order:t&&t.order})}}},{key:`map`,value:function(e,t){if(this._data){var n,r,i=Bd(this._options),a=t&&Bd(t);return r=a?i?function(e){return i(e)&&a(e)}:a:i,Kd(n=this._data).call(n,e,{filter:r,order:t&&t.order})}return[]}},{key:`getDataSet`,value:function(){return this._data.getDataSet()}},{key:`stream`,value:function(e){var t;return this._data.stream(e||{[kT]:vd(t=Lw(this._ids)).call(t,this._ids)})}},{key:`dispose`,value:function(){var e;(e=this._data)!=null&&e.off&&this._data.off(`*`,this._listener);var t,n=`This data view has already been disposed of.`,i={get:function(){throw Error(n)},set:function(){throw Error(n)},configurable:!1},a=iE(nm(r.prototype));try{for(a.s();!(t=a.n()).done;){var o=t.value;jv(this,o,i)}}catch(e){a.e(e)}finally{a.f()}}},{key:`_onEvent`,value:function(e,t,n){if(t&&t.items&&this._data){var r=t.items,i=[],a=[],o=[],s=[],c=[],l=[];switch(e){case`add`:for(var u=0,d=r.length;u<d;u++){var f=r[u];this.get(f)&&(this._ids.add(f),i.push(f))}break;case`update`:for(var p=0,m=r.length;p<m;p++){var h=r[p];this.get(h)?this._ids.has(h)?(a.push(h),c.push(t.data[p]),s.push(t.oldData[p])):(this._ids.add(h),i.push(h)):this._ids.has(h)&&(this._ids.delete(h),o.push(h),l.push(t.oldData[p]))}break;case`remove`:for(var g=0,_=r.length;g<_;g++){var v=r[g];this._ids.has(v)&&(this._ids.delete(v),o.push(v),l.push(t.oldData[g]))}}this.length+=i.length-o.length,i.length&&this._trigger(`add`,{items:i},n),a.length&&this._trigger(`update`,{items:a,oldData:s,data:c},n),o.length&&this._trigger(`remove`,{items:o,oldData:l},n)}}}]),r}(KT);function cE(e,t){return typeof t==`object`&&!!t&&e===t.idProp&&typeof t.add==`function`&&typeof t.clear==`function`&&typeof t.distinct==`function`&&typeof _m(t)==`function`&&typeof t.get==`function`&&typeof t.getDataSet==`function`&&typeof t.getIds==`function`&&typeof t.length==`number`&&typeof Kd(t)==`function`&&typeof t.max==`function`&&typeof t.min==`function`&&typeof t.off==`function`&&typeof t.on==`function`&&typeof t.remove==`function`&&typeof t.setOptions==`function`&&typeof t.stream==`function`&&typeof t.update==`function`&&typeof t.updateOnly==`function`}e.DELETE=L_,e.DataSet=rE,e.DataStream=ZT,e.DataView=sE,e.Queue=GT,e.createNewDataPipeFrom=function(e){return new uf(e)},e.isDataSetLike=cE,e.isDataViewLike=function(e,t){return typeof t==`object`&&!!t&&e===t.idProp&&typeof _m(t)==`function`&&typeof t.get==`function`&&typeof t.getDataSet==`function`&&typeof t.getIds==`function`&&typeof t.length==`number`&&typeof Kd(t)==`function`&&typeof t.off==`function`&&typeof t.on==`function`&&typeof t.stream==`function`&&cE(e,t.getDataSet())}}))}))(),S=b(),ee=n(),C=e(i(),1),te={LocalBusiness:`#2E5090`,Service:`#3A6BB0`,PriceSpecification:`#5B8DD0`,OpeningHoursSpecification:`#7AAFE8`,Person:`#C2410C`,UserProfile:`#EA580C`,Preference:`#F97316`,AdminUser:`#9A3412`,AccessGrant:`#7C2D12`,KnowledgeDocument:`#16A34A`,Section:`#22C55E`,Chunk:`#4ADE80`,DigitalDocument:`#15803D`,CreativeWork:`#86EFAC`,Question:`#A7F3D0`,FAQPage:`#34D399`,DefinedTerm:`#10B981`,Review:`#059669`,ImageObject:`#6EE7B7`,Conversation:`#7C3AED`,AdminConversation:`#5B21B6`,PublicConversation:`#A78BFA`,Message:`#A78BFA`,UserMessage:`#F97316`,AssistantMessage:`#8B5CF6`,ToolCall:`#C4B5FD`,Task:`#DB2777`,Project:`#BE185D`,Event:`#EC4899`,Workflow:`#0891B2`,WorkflowStep:`#06B6D4`,WorkflowRun:`#22D3EE`,StepResult:`#67E8F9`,OnboardingState:`#8B5CF6`,Email:`#65A30D`,EmailAccount:`#84CC16`,ReviewAlert:`#DC2626`};Object.freeze(Object.keys(te));var ne=Object.freeze(new Set([`Chunk`,`GraphPreference`]));Object.freeze(new Set([`ToolCall`,`WorkflowRun`,`WorkflowStep`,`ReviewAlert`]));var w=o(),re=250,T=1200;function E(){let[e,t]=(0,C.useState)(null),[n,r]=(0,C.useState)(!1);return(0,C.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]),n?e?(0,w.jsxs)(`div`,{className:`data-page graph-page`,children:[(0,w.jsxs)(`header`,{className:`data-header`,children:[(0,w.jsxs)(`h1`,{className:`data-title`,children:[(0,w.jsx)(f,{size:18}),` Graph`]}),(0,w.jsx)(D,{})]}),(0,w.jsx)(`main`,{className:`graph-main`,children:(0,w.jsx)(O,{sessionKey:e})})]}):(0,w.jsxs)(`div`,{className:`data-page`,children:[(0,w.jsx)(`header`,{className:`data-header`,children:(0,w.jsxs)(`h1`,{className:`data-title`,children:[(0,w.jsx)(f,{size:18}),` Graph`]})}),(0,w.jsxs)(`div`,{className:`data-empty`,children:[(0,w.jsx)(`p`,{children:`You are not signed in.`}),(0,w.jsxs)(`p`,{children:[`Open the `,(0,w.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,w.jsx)(`div`,{className:`data-page`,children:(0,w.jsxs)(`div`,{className:`data-loading`,children:[(0,w.jsx)(s,{size:18,className:`spin`}),` Loading…`]})})}function D(){let[e,t]=(0,C.useState)(!1),n=(0,C.useRef)(null);(0,C.useEffect)(()=>{if(!e)return;let r=e=>{n.current&&(n.current.contains(e.target)||t(!1))},i=e=>{e.key===`Escape`&&t(!1)};return document.addEventListener(`mousedown`,r),document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`mousedown`,r),document.removeEventListener(`keydown`,i)}},[e]);let r=(0,C.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]);return(0,w.jsxs)(`div`,{className:`chat-burger-wrap`,ref:n,children:[(0,w.jsx)(`button`,{type:`button`,className:`chat-burger`,onClick:()=>t(e=>!e),"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":e,children:(0,w.jsx)(d,{size:20})}),e&&(0,w.jsxs)(`div`,{className:`chat-menu`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),window.location.href=`/`},children:[(0,w.jsx)(p,{size:14}),` Chat`]}),(0,w.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),window.location.href=`/data`},children:[(0,w.jsx)(u,{size:14}),` Data`]}),(0,w.jsx)(`div`,{className:`chat-menu-divider`}),(0,w.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),r()},children:[(0,w.jsx)(c,{size:14}),` Log out`]})]})]})}function O({sessionKey:e}){let t=(0,C.useRef)(null),n=(0,C.useRef)(null),i=(0,C.useRef)(null),a=(0,C.useRef)(null),o=(0,C.useRef)(new Map),c=(0,C.useRef)(null),u=(0,C.useRef)(null),d=(0,C.useRef)(null),f=(0,C.useRef)(null),[p,m]=(0,C.useState)({kind:`filter`,selectedLabels:[],includeTrashed:!1}),[y,b]=(0,C.useState)(!1),[ee,E]=(0,C.useState)(null),[D,O]=(0,C.useState)(null),[oe,ce]=(0,C.useState)(0),[le,ue]=(0,C.useState)(null),[de,fe]=(0,C.useState)(!1),[pe,me]=(0,C.useState)(!1),[he,ge]=(0,C.useState)(null),[_e,ve]=(0,C.useState)(``),[ye,be]=(0,C.useState)(``),[xe,Se]=(0,C.useState)(null),[Ce,j]=(0,C.useState)(null),[M,we]=(0,C.useState)([]),[Te,Ee]=(0,C.useState)({labels:[],includeTrashed:!1}),[De,N]=(0,C.useState)(!1),[P,F]=(0,C.useState)(!1),Oe=(0,C.useRef)(!1),ke=(0,C.useRef)(null),Ae=(0,C.useMemo)(()=>{let e=new Set;for(let t of o.current.values())for(let n of t.labels)e.add(n);return[...e].sort()},[oe]);(0,C.useEffect)(()=>{let t=!1,n=fetch(`/api/admin/graph-labels-in-graph?session_key=${encodeURIComponent(e)}`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).catch(e=>{let t=e instanceof Error?e.message:String(e);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-labels-in-graph`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}return{labels:[]}}),r=fetch(`/api/admin/graph-default-view?session_key=${encodeURIComponent(e)}`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).catch(e=>{let t=e instanceof Error?e.message:String(e);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-default-view`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}return{labels:[],includeTrashed:!1}});return Promise.all([n,r]).then(([e,n])=>{if(t)return;let r=new Set([`AdminConversation`,`PublicConversation`,`UserMessage`,`AssistantMessage`]),i=e.labels.filter(e=>!e.childOnly||r.has(e.label)),a=i.some(e=>e.label===`AdminConversation`||e.label===`PublicConversation`),o=i.some(e=>e.label===`UserMessage`||e.label===`AssistantMessage`),s=i.filter(e=>!(e.label===`Conversation`&&a||e.label===`Message`&&o));if(we(s),Ee(n),!Oe.current){Oe.current=!0;let e=new Set(s.map(e=>e.label)),t=n.labels.filter(t=>e.has(t));(t.length>0||n.includeTrashed)&&(f.current={selectedLabels:[...t],includeTrashed:n.includeTrashed},m({kind:`filter`,selectedLabels:t,includeTrashed:n.includeTrashed}))}}),()=>{t=!0}},[e]),(0,C.useEffect)(()=>{if(!De)return;let e=e=>{ke.current&&(ke.current.contains(e.target)||N(!1))},t=e=>{e.key===`Escape`&&N(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[De]);let je=(0,C.useCallback)(()=>{if(i.current)try{i.current.clear()}catch{}if(a.current)try{a.current.clear()}catch{}},[]),Me=(0,C.useCallback)((t,r)=>{ge(null),fetch(`/api/admin/graph-delete?session_key=${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({elementId:t,by:`graph-drag-trash`})}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);ue(null);try{n.current?.unselectAll()}catch{}m(e=>{if(e.kind===`neighbourhood`){let e=f.current??{selectedLabels:[],includeTrashed:!1};return{kind:`filter`,selectedLabels:[...e.selectedLabels],includeTrashed:e.includeTrashed}}return{kind:`filter`,selectedLabels:[...e.selectedLabels],includeTrashed:e.includeTrashed}})}).catch(e=>{let n=e instanceof Error?e.message:String(e);ge(`Failed to delete: ${n}`),me(!0),window.setTimeout(()=>me(!1),T);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-drag-delete`,elementId:t,label:r,msg:n}),keepalive:!0}).catch(()=>{})}catch{}})},[e]);(0,C.useEffect)(()=>{if(p.kind===`filter`&&p.selectedLabels.length===0){c.current?.abort(),c.current=null,b(!1),E(null),O(null),ce(0),o.current=new Map,je();return}let t=window.setTimeout(()=>{c.current?.abort();let t=new AbortController;c.current=t,b(!0),E(null),O(null);let n=k(e,p);fetch(n,{signal:t.signal}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(e.status===413)throw new A(t);if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t.signal.aborted||(o.current=new Map(e.nodes.map(e=>[e.id,e])),ce(e.nodes.length),Ne(e.nodes,e.edges))}).catch(e=>{if(!t.signal.aborted){if(e instanceof A){O(e.body),ce(0),o.current=new Map,je();return}E(e instanceof Error?e.message:String(e))}}).finally(()=>{t.signal.aborted||b(!1)})},re);return()=>{window.clearTimeout(t)}},[e,p,je]),(0,C.useEffect)(()=>()=>{c.current?.abort(),n.current?.destroy(),n.current=null},[]);let Ne=(0,C.useCallback)((e,r)=>{if(!t.current)return;let s=e.map(e=>{let t=e.labels[0]??`Unknown`,n=e.labels.slice(1).map(e=>te[e]).find(e=>e!==void 0)??te[t]??`#94A3B8`;return e.trashed?{id:e.id,label:ae(e),title:se(e),color:{background:`${n}40`,border:n},borderWidth:2,shapeProperties:{borderDashes:[6,4]},group:t}:{id:e.id,label:ae(e),title:se(e),color:n,group:t}}),c=r.map(e=>({id:e.id,from:e.from,to:e.to,label:e.type}));i.current=new x.DataSet(s),a.current=new x.DataSet(c);let l={autoResize:!0,layout:{improvedLayout:!1},physics:{solver:`forceAtlas2Based`,forceAtlas2Based:{gravitationalConstant:-50,springLength:90,springConstant:.08},stabilization:{iterations:200}},nodes:{shape:`dot`,size:14,font:{color:`#1F2937`,size:12,face:`DM Sans, sans-serif`},borderWidth:0},edges:{arrows:{to:{enabled:!0,scaleFactor:.4}},color:{color:`#CBD5E1`,highlight:`#475569`},font:{color:`#64748B`,size:9,face:`DM Sans, sans-serif`,align:`middle`,strokeWidth:0},smooth:{enabled:!0,type:`continuous`,roundness:.4},width:1},interaction:{hover:!0,tooltipDelay:150}};try{n.current?.destroy();let e=new S.Network(t.current,{nodes:i.current,edges:a.current},l);n.current=e,e.on(`selectNode`,e=>{let t=e.nodes[0],n=o.current.get(t);n&&(ue(n),m(e=>{if(n.trashed)return e;if(e.kind===`filter`)return f.current={selectedLabels:[...e.selectedLabels],includeTrashed:e.includeTrashed},{kind:`neighbourhood`,rootElementId:t,rootLabel:n.labels[0]??null};if(e.kind===`neighbourhood`&&e.rootElementId!==t){try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-neighbourhood-pivot`,msg:`from=${e.rootElementId} to=${t} label=${n.labels[0]??`null`}`}),keepalive:!0}).catch(()=>{})}catch{}return{kind:`neighbourhood`,rootElementId:t,rootLabel:n.labels[0]??null}}return e}))}),e.on(`deselectNode`,()=>{ue(null),m(e=>{if(e.kind!==`neighbourhood`)return e;let t=f.current??{selectedLabels:[],includeTrashed:!1};return{kind:`filter`,selectedLabels:[...t.selectedLabels],includeTrashed:t.includeTrashed}})});let r=e=>{let n=t.current,r=u.current;if(!n||!r)return!1;let i=n.getBoundingClientRect(),a=r.getBoundingClientRect(),o=i.left+e.x,s=i.top+e.y;return o>=a.left&&o<=a.right&&s>=a.top&&s<=a.bottom};e.on(`dragStart`,e=>{let t=e.nodes[0];if(!t){d.current=null;return}d.current=t}),e.on(`dragging`,e=>{if(!d.current)return;let t=r(e.pointer.DOM);fe(e=>e===t?e:t)}),e.on(`dragEnd`,e=>{let t=d.current;d.current=null,fe(!1),t&&r(e.pointer.DOM)&&Me(t,o.current.get(t)?.labels[0]??`Unknown`)})}catch(e){let t=e instanceof Error?e.message:String(e);E(`Visualisation failed to load: ${t}`);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-render`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}}},[]);(0,C.useEffect)(()=>{let e=_e.trim();if(!e){be(``),Se(null),j(null),n.current?.unselectAll();return}let t=setTimeout(()=>be(e),300);return()=>clearTimeout(t)},[_e]);let Pe=(0,C.useCallback)(e=>{let t=n.current;if(!t)return;let r=[];for(let t of e)o.current.has(t.nodeId)&&r.push(t.nodeId);r.length>0&&(t.selectNodes(r,!0),t.fit({nodes:r,animation:{duration:400,easingFunction:`easeInOutQuad`}}))},[]);(0,C.useEffect)(()=>{if(!ye)return;let t=!1;j(null);let n=`/api/admin/graph-search?session_key=${encodeURIComponent(e)}&q=${encodeURIComponent(ye)}&limit=20`;return fetch(n).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{if(t)return;Se(e.results),Pe(e.results);let n=new Set;for(let t of e.results)for(let e of t.labels)ne.has(e)||n.add(e);n.size!==0&&m(e=>{if(e.kind!==`filter`)return e;let t=new Set(e.selectedLabels),r=0;for(let e of n)t.has(e)||(t.add(e),r++);return r===0?e:{kind:`filter`,selectedLabels:[...t].sort(),includeTrashed:e.includeTrashed}})}).catch(e=>{t||j(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[ye,e,Pe]);let Fe=(0,C.useMemo)(()=>{if(!xe)return 0;let e=0;for(let t of xe)o.current.has(t.nodeId)||e++;return e},[xe,oe]),Ie=(0,C.useCallback)(e=>{m(t=>{if(t.kind!==`filter`)return{kind:`filter`,selectedLabels:[e],includeTrashed:!1};let n=new Set(t.selectedLabels);return n.has(e)?n.delete(e):n.add(e),{kind:`filter`,selectedLabels:[...n].sort(),includeTrashed:t.includeTrashed}})},[]),Le=(0,C.useCallback)(()=>{m(e=>e.kind===`filter`?{...e,includeTrashed:!e.includeTrashed}:{kind:`filter`,selectedLabels:[],includeTrashed:!0})},[]),Re=(0,C.useCallback)(()=>{ve(``),be(``),Se(null),j(null);try{n.current?.unselectAll()}catch{}},[]),ze=(0,C.useCallback)(()=>{m(e=>(e.kind,{kind:`filter`,selectedLabels:[],includeTrashed:!1}))},[]),Be=(0,C.useCallback)(()=>{ue(null);try{n.current?.unselectAll()}catch{}m(e=>{if(e.kind!==`neighbourhood`)return e;let t=f.current??{selectedLabels:[],includeTrashed:!1};return{kind:`filter`,selectedLabels:[...t.selectedLabels],includeTrashed:t.includeTrashed}})},[]),Ve=(0,C.useCallback)(()=>{if(p.kind!==`filter`)return;let t={labels:[...p.selectedLabels].sort(),includeTrashed:p.includeTrashed};F(!0),fetch(`/api/admin/graph-default-view?session_key=${encodeURIComponent(e)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}).then(async e=>{if(!e.ok){let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));throw Error(t.error??`HTTP ${e.status}`)}Ee(t)}).catch(e=>{let t=e instanceof Error?e.message:String(e);try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`graph-default-view-save`,msg:t}),keepalive:!0}).catch(()=>{})}catch{}}).finally(()=>F(!1))},[e,p]),He=(0,C.useCallback)(()=>{ue(null);try{n.current?.unselectAll()}catch{}m(e=>e.kind===`filter`?{kind:`filter`,selectedLabels:[...e.selectedLabels],includeTrashed:e.includeTrashed}:{...e})},[]),Ue=p.kind===`neighbourhood`,We=p.kind===`filter`?p.selectedLabels:[],Ge=p.kind===`filter`?p.includeTrashed:!1,Ke=(0,C.useMemo)(()=>{if(p.kind!==`filter`)return!1;if(Ge!==Te.includeTrashed||We.length!==Te.labels.length)return!0;for(let e=0;e<We.length;e++)if(We[e]!==Te.labels[e])return!0;return!1},[p.kind,Ge,We,Te]);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`graph-toolbar`,children:[(0,w.jsxs)(`div`,{className:`data-search-input graph-search-input`,children:[(0,w.jsx)(l,{size:14}),(0,w.jsx)(`input`,{type:`text`,placeholder:`Search nodes…`,value:_e,onChange:e=>ve(e.target.value),autoComplete:`off`,spellCheck:!1}),ye&&!xe&&!Ce&&(0,w.jsx)(s,{size:14,className:`spin`}),_e.length>0&&(0,w.jsx)(`button`,{type:`button`,className:`graph-search-clear`,onClick:Re,"aria-label":`Clear search`,title:`Clear search`,children:(0,w.jsx)(h,{size:14})})]}),!Ue&&(0,w.jsxs)(`div`,{className:`graph-filter-wrap`,ref:ke,children:[(0,w.jsxs)(`button`,{type:`button`,className:`graph-filter-toggle${De?` is-open`:``}${We.length>0||Ge?` has-selection`:``}`,onClick:()=>N(e=>!e),"aria-haspopup":`true`,"aria-expanded":De,"aria-label":`Filter node types`,children:[(0,w.jsx)(v,{size:14}),(0,w.jsx)(`span`,{children:`Filter`}),We.length>0&&(0,w.jsx)(`span`,{className:`graph-filter-count`,children:We.length})]}),De&&(0,w.jsxs)(`div`,{className:`graph-filter-popover`,role:`dialog`,"aria-label":`Node type filter`,children:[(0,w.jsxs)(`div`,{className:`graph-filter-popover-header`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`graph-toggle-trashed${Ge?` active`:``}`,onClick:Le,"aria-pressed":Ge,title:`Show trashed nodes — restored with Restore button on each node`,children:[(0,w.jsx)(_,{size:14}),` Show trashed`]}),(We.length>0||Ge)&&(0,w.jsx)(`button`,{type:`button`,className:`graph-filter-clear`,onClick:ze,"aria-label":`Clear filter selection`,title:`Clear filter selection`,children:(0,w.jsx)(h,{size:14})})]}),M.length===0&&(0,w.jsx)(`p`,{className:`graph-filter-popover-empty`,children:`No node types in your graph yet.`}),(0,w.jsx)(`div`,{className:`graph-filter-rows`,role:`group`,"aria-label":`Node type filter`,children:M.map(({label:e,nodeCount:t})=>{let n=We.includes(e),r=te[e]??`#94A3B8`;return(0,w.jsxs)(`button`,{type:`button`,className:`graph-filter-row${n?` active`:``}`,onClick:()=>Ie(e),"aria-pressed":n,children:[(0,w.jsx)(`span`,{className:`graph-filter-row-swatch`,style:{backgroundColor:r}}),(0,w.jsx)(`span`,{className:`graph-filter-row-label`,children:e}),(0,w.jsx)(`span`,{className:`graph-filter-row-count`,children:t})]},e)})}),(0,w.jsx)(`div`,{className:`graph-filter-popover-footer`,children:(0,w.jsx)(`button`,{type:`button`,className:`graph-filter-set-default`,onClick:Ve,disabled:!Ke||P,children:P?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(s,{size:12,className:`spin`}),` Saving…`]}):`Set default view`})})]})]}),(0,w.jsxs)(`div`,{className:`graph-meta`,children:[Ue&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`button`,{type:`button`,className:`graph-back-to-filter graph-back-desktop`,onClick:Be,children:`← Back`}),(0,w.jsx)(`button`,{type:`button`,className:`graph-back-to-filter graph-back-mobile`,onClick:Be,"aria-label":`Back`,children:(0,w.jsx)(g,{size:16})})]}),oe>0&&(0,w.jsxs)(`span`,{className:`graph-meta-count`,children:[oe,` node`,oe===1?``:`s`]})]})]}),Ce&&(0,w.jsxs)(`div`,{className:`data-error graph-error-banner`,children:[`Search unavailable: `,Ce]}),xe&&xe.length===0&&!Ce&&(0,w.jsx)(`div`,{className:`graph-search-status`,children:`No matches in your graph.`}),xe&&Fe>0&&(0,w.jsxs)(`div`,{className:`graph-search-status`,children:[Fe,` match`,Fe===1?``:`es`,` not in current view. Adjust your filter or search more specifically.`]}),(0,w.jsxs)(`div`,{className:`graph-canvas-wrap`,children:[y&&(0,w.jsxs)(`div`,{className:`graph-canvas-overlay`,children:[(0,w.jsx)(s,{size:20,className:`spin`}),` Loading your graph…`]}),ee&&!y&&(0,w.jsxs)(`div`,{className:`graph-canvas-overlay graph-canvas-error`,children:[(0,w.jsx)(`p`,{children:ee}),(0,w.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:()=>window.location.reload(),children:`Retry`})]}),D&&!y&&(0,w.jsxs)(`div`,{className:`graph-canvas-overlay graph-canvas-error`,children:[(0,w.jsxs)(`p`,{children:[`Refine your filter — `,(0,w.jsx)(`strong`,{children:D.matched}),` matches exceed the 2000 cap.`]}),(0,w.jsx)(`p`,{className:`graph-canvas-hint`,children:`Pick a more specific label combination, or narrow your brand's data.`})]}),!y&&!ee&&!D&&oe===0&&!Ue&&We.length===0&&(0,w.jsxs)(`div`,{className:`graph-canvas-overlay`,children:[(0,w.jsx)(v,{size:20}),(0,w.jsx)(`p`,{children:`Open Filter to pick a node type and see what's in your graph.`})]}),!y&&!ee&&!D&&oe===0&&!Ue&&We.length>0&&(0,w.jsx)(`div`,{className:`graph-canvas-overlay`,children:(0,w.jsxs)(`p`,{children:[`No `,We.join(`, `),` nodes in your graph yet.`]})}),(0,w.jsx)(`div`,{ref:t,className:`graph-canvas`}),oe>0&&(0,w.jsx)(`div`,{ref:u,className:`graph-trash-drop-zone${de?` is-hover`:``}${pe?` is-error`:``}`,"aria-hidden":`true`,children:(0,w.jsx)(r,{size:18})}),he&&(0,w.jsxs)(`div`,{className:`graph-drag-error-banner`,role:`alert`,children:[(0,w.jsx)(`span`,{children:he}),(0,w.jsx)(`button`,{type:`button`,className:`graph-drag-error-dismiss`,onClick:()=>ge(null),"aria-label":`Dismiss`,children:(0,w.jsx)(h,{size:14})})]})]}),le&&(0,w.jsx)(ie,{node:le,sessionKey:e,onClose:()=>{ue(null);try{n.current?.unselectAll()}catch{}},onRestored:He}),oe>0&&Ae.length>0&&(0,w.jsx)(`div`,{className:`graph-legend`,children:Ae.map(e=>(0,w.jsxs)(`div`,{className:`graph-legend-item`,children:[(0,w.jsx)(`span`,{className:`graph-legend-swatch`,style:{backgroundColor:te[e]??`#94A3B8`}}),(0,w.jsx)(`span`,{children:e})]},e))})]})}function ie({node:e,sessionKey:t,onClose:n,onRestored:r}){let i=Object.entries(e.properties).filter(([,e])=>e!=null),[a,o]=(0,C.useState)(!1),[c,l]=(0,C.useState)(null);(0,C.useEffect)(()=>{o(!1),l(null)},[e.id]);let u=(0,C.useCallback)(()=>{o(!0),l(null),fetch(`/api/admin/graph-restore?session_key=${encodeURIComponent(t)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({elementId:e.id})}).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);r()}).catch(e=>{l(e instanceof Error?e.message:String(e)),o(!1)})},[e.id,r,t]);return(0,w.jsxs)(`aside`,{className:`graph-side-panel${e.trashed?` graph-side-panel-trashed`:``}`,children:[(0,w.jsxs)(`header`,{className:`graph-side-header`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsxs)(`div`,{className:`graph-side-labels`,children:[e.labels.join(` · `),e.trashed?` · Trashed`:``]}),(0,w.jsx)(`div`,{className:`graph-side-id`,children:e.id})]}),(0,w.jsx)(`button`,{type:`button`,className:`graph-side-close`,onClick:n,"aria-label":`Close`,children:(0,w.jsx)(h,{size:14})})]}),e.trashed&&(0,w.jsxs)(`dl`,{className:`graph-side-props graph-side-trash-meta`,children:[(0,w.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,w.jsx)(`dt`,{children:`trashedAt`}),(0,w.jsx)(`dd`,{children:ce(e.properties.trashedAt)})]}),(0,w.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,w.jsx)(`dt`,{children:`trashedBy`}),(0,w.jsx)(`dd`,{children:ce(e.properties.trashedBy)})]})]}),(0,w.jsxs)(`dl`,{className:`graph-side-props`,children:[i.length===0&&(0,w.jsx)(`div`,{className:`graph-side-empty`,children:`No properties.`}),i.map(([e,t])=>(0,w.jsxs)(`div`,{className:`graph-side-prop`,children:[(0,w.jsx)(`dt`,{children:e}),(0,w.jsx)(`dd`,{children:ce(t)})]},e))]}),e.trashed&&(0,w.jsxs)(`footer`,{className:`graph-side-footer`,children:[!a&&!c&&(0,w.jsxs)(`button`,{type:`button`,className:`graph-side-restore`,onClick:u,children:[(0,w.jsx)(m,{size:14}),` Restore`]}),a&&(0,w.jsx)(`div`,{className:`graph-delete-confirm`,children:(0,w.jsxs)(`p`,{children:[(0,w.jsx)(s,{size:14,className:`spin`}),` Restoring…`]})}),c&&(0,w.jsxs)(`div`,{className:`graph-delete-confirm graph-delete-confirm-error`,children:[(0,w.jsxs)(`p`,{children:[`Restore failed: `,c]}),(0,w.jsxs)(`div`,{className:`graph-delete-confirm-buttons`,children:[(0,w.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-cancel`,onClick:()=>{l(null)},children:`Close`}),(0,w.jsx)(`button`,{type:`button`,className:`graph-delete-confirm-do`,onClick:u,children:`Retry`})]})]})]})]})}function k(e,t){let n=`/api/admin/graph-subgraph?session_key=${encodeURIComponent(e)}`;return t.kind===`neighbourhood`?`${n}&mode=neighbourhood&elementId=${encodeURIComponent(t.rootElementId)}`:`${n}&mode=default&labels=${encodeURIComponent(t.selectedLabels.join(`,`))}${t.includeTrashed?`&includeTrashed=1`:``}`}var A=class extends Error{body;constructor(e){super(e.error),this.body=e}};function ae(e){let t=e.properties,n=e.labels[0];if(n===`ToolCall`){let e=t.toolName;if(typeof e==`string`&&e.length>0)return e.length>24?e.slice(0,24)+`…`:e}else if(n===`WorkflowRun`){let e=t.startedAt;if(typeof e==`string`&&e.length>0){let t=oe(e);if(t)return t}}else if(n===`WorkflowStep`){let e=t.label;if(typeof e==`string`&&e.length>0)return e.length>24?e.slice(0,24)+`…`:e}else if(n===`Message`){let e=typeof t.role==`string`?t.role:``,n=e===`user`?`user`:e===`assistant`?`asst`:e===`system`?`sys`:e===`tool`?`tool`:null,r=typeof t.createdAt==`string`?t.createdAt:``;if(n&&r){let e=oe(r);if(e){let t=new Date().toISOString().slice(0,10);return`${n} ${e.startsWith(t)?e.slice(11):e}`}}}for(let e of[`name`,`title`,`summary`,`givenName`,`subject`,`text`]){let n=t[e];if(typeof n==`string`&&n.length>0)return n.length>24?n.slice(0,24)+`…`:n}if(n===`Conversation`){let e=typeof t.conversationId==`string`?t.conversationId:null;if(e)return`Conv ${e.slice(0,8)}`}return n??`…`}function oe(e){let t=/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})/.exec(e);return t?`${t[1]} ${t[2]}`:null}function se(e){return`${e.labels.join(` · `)}\nid: ${e.id}`}function ce(e){if(e==null)return``;if(Array.isArray(e))return e.length>8?`[${e.length} items]`:e.map(String).join(`, `);if(typeof e==`object`)return`year`in e&&`month`in e&&`day`in e&&typeof e.year==`object`?`[unserialised temporal] ${JSON.stringify(e)}`:JSON.stringify(e);let t=String(e);return t.length>400?t.slice(0,400)+`…`:t}(0,ee.createRoot)(document.getElementById(`root`)).render((0,w.jsx)(E,{}));
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>Graph — Maxy</title>
7
7
  <link rel="icon" href="/favicon.ico">
8
- <script type="module" crossorigin src="/assets/graph-BYaOEZUg.js"></script>
8
+ <script type="module" crossorigin src="/assets/graph-DwWdaLpw.js"></script>
9
9
  <link rel="modulepreload" crossorigin href="/assets/chunk-DD-I1_y5.js">
10
10
  <link rel="modulepreload" crossorigin href="/assets/jsx-runtime-XWiDQoTG.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/share-2-DLjRUEiG.js">
@@ -4679,6 +4679,16 @@ function terminalAlive() {
4679
4679
  });
4680
4680
  return result.status === 0;
4681
4681
  }
4682
+ function extractFailureLine(stderr, signal) {
4683
+ if (signal === "SIGTERM") {
4684
+ return '[terminal-launch] failed err="vnc.sh timed out after 10s \u2014 X server on :99 may be wedged (check Xtigervnc + websockify in vnc-boot.log)"';
4685
+ }
4686
+ const raw2 = (stderr ?? "").trim();
4687
+ if (!raw2) return "Terminal failed to start (no diagnostic captured)";
4688
+ const lines = raw2.split("\n").filter((l) => l.trim().length > 0);
4689
+ const lastFailed = [...lines].reverse().find((l) => l.includes("[terminal-launch] failed"));
4690
+ return (lastFailed ?? lines[lines.length - 1]).trim();
4691
+ }
4682
4692
  async function ensureTerminal(transport = "vnc") {
4683
4693
  const targetSentinel = transport === "native" ? "native" : ":99";
4684
4694
  if (terminalAlive()) {
@@ -4696,8 +4706,17 @@ async function ensureTerminal(transport = "vnc") {
4696
4706
  if (currentTerminalDisplay === null) {
4697
4707
  currentTerminalDisplay = targetSentinel;
4698
4708
  }
4699
- vncLog("ensure-terminal", { action: "already-running", transport });
4700
- return true;
4709
+ const check = spawnSync("bash", [VNC_SCRIPT, transport === "native" ? "start-terminal-native" : "start-terminal"], {
4710
+ stdio: ["ignore", "pipe", "pipe"],
4711
+ timeout: 1e4
4712
+ });
4713
+ if (check.status !== 0) {
4714
+ const errorLine = extractFailureLine(check.stderr?.toString(), check.signal);
4715
+ vncLog("ensure-terminal", { action: "already-running-self-heal-failed", transport, windowPresent: false, err: errorLine });
4716
+ return { ok: false, error: errorLine };
4717
+ }
4718
+ vncLog("ensure-terminal", { action: "already-running", transport, windowPresent: true });
4719
+ return { ok: true };
4701
4720
  }
4702
4721
  }
4703
4722
  const vncCommand = transport === "native" ? "start-terminal-native" : "start-terminal";
@@ -4710,7 +4729,7 @@ async function ensureTerminal(transport = "vnc") {
4710
4729
  if (!vncOk) {
4711
4730
  console.error("[ensureTerminal] Full VNC restart failed \u2014 terminal degraded");
4712
4731
  vncLog("ensure-terminal", { action: "degraded", reason: "vnc-restart-failed", transport });
4713
- return false;
4732
+ return { ok: false, error: "VNC failed to start after recovery attempt" };
4714
4733
  }
4715
4734
  }
4716
4735
  }
@@ -4725,15 +4744,18 @@ async function ensureTerminal(transport = "vnc") {
4725
4744
  }
4726
4745
  console.error(`[ensureTerminal] Launching terminal (${vncCommand}) for transport=${transport}`);
4727
4746
  vncLog("ensure-terminal", { action: `launch-${vncCommand}`, transport });
4728
- try {
4729
- execFileSync("bash", [VNC_SCRIPT, vncCommand], { timeout: 1e4 });
4730
- } catch (err) {
4731
- vncLog("ensure-terminal", { action: "launch-failed", transport, err: err.message });
4732
- return false;
4747
+ const result = spawnSync("bash", [VNC_SCRIPT, vncCommand], {
4748
+ stdio: ["ignore", "pipe", "pipe"],
4749
+ timeout: 1e4
4750
+ });
4751
+ if (result.status !== 0) {
4752
+ const errorLine = extractFailureLine(result.stderr?.toString(), result.signal);
4753
+ vncLog("ensure-terminal", { action: "launch-failed", transport, windowPresent: false, err: errorLine });
4754
+ return { ok: false, error: errorLine };
4733
4755
  }
4734
4756
  currentTerminalDisplay = targetSentinel;
4735
- vncLog("ensure-terminal", { action: "launch-complete", transport, sentinel: targetSentinel });
4736
- return true;
4757
+ vncLog("ensure-terminal", { action: "launch-complete", transport, sentinel: targetSentinel, windowPresent: true });
4758
+ return { ok: true };
4737
4759
  }
4738
4760
  function killTerminal() {
4739
4761
  spawnSync("bash", [VNC_SCRIPT, "kill-terminal"], { stdio: "pipe", timeout: 5e3 });
@@ -4902,11 +4924,13 @@ async function ensureConversation(accountId, agentType, sessionKey, visitorId, a
4902
4924
  if (cached) return cached;
4903
4925
  const conversationId = randomUUID();
4904
4926
  const channel = sessionKey.startsWith("whatsapp:") ? "whatsapp" : sessionKey.startsWith("telegram:") ? "telegram" : "webchat";
4927
+ const conversationSublabel = agentType === "admin" ? "AdminConversation" : "PublicConversation";
4905
4928
  const session = getSession();
4906
4929
  try {
4907
4930
  const result = await session.run(
4908
4931
  `MERGE (c:Conversation {sessionKey: $sessionKey})
4909
4932
  ON CREATE SET
4933
+ c:${conversationSublabel},
4910
4934
  c.conversationId = $conversationId,
4911
4935
  c.accountId = $accountId,
4912
4936
  c.agentType = $agentType,
@@ -4938,7 +4962,7 @@ async function ensureConversation(accountId, agentType, sessionKey, visitorId, a
4938
4962
  const id = result.records[0]?.get("conversationId");
4939
4963
  if (id) {
4940
4964
  cacheConversationId(sessionKey, id);
4941
- console.error(`[session] ${(/* @__PURE__ */ new Date()).toISOString()} conversation attributed: conversationId=${id.slice(0, 8)}\u2026 userId=${userId ?? "none"} ${agentType}/${accountId.slice(0, 8)}\u2026`);
4965
+ console.error(`[session] ${(/* @__PURE__ */ new Date()).toISOString()} conversation attributed: conversationId=${id.slice(0, 8)}\u2026 userId=${userId ?? "none"} ${agentType}/${accountId.slice(0, 8)}\u2026 sublabel=${conversationSublabel}`);
4942
4966
  }
4943
4967
  return id ?? null;
4944
4968
  } catch (err) {
@@ -5313,7 +5337,7 @@ async function persistMessage(conversationId, role, content, accountId, tokens,
5313
5337
  // happens to equal an already-set summary (verbatim retry, short
5314
5338
  // catchphrase) and fooled a post-state equality check.
5315
5339
  WITH c, tail, (c.summary IS NULL AND $role = 'user' AND $summary <> '') AS summarySetThisWrite
5316
- CREATE (m:Message {
5340
+ CREATE (m:Message:${role === "user" ? "UserMessage" : "AssistantMessage"} {
5317
5341
  messageId: $messageId,
5318
5342
  conversationId: $conversationId,
5319
5343
  accountId: $accountId,
@@ -5363,7 +5387,8 @@ async function persistMessage(conversationId, role, content, accountId, tokens,
5363
5387
  const summarySetThisWrite = record.get("summarySetThisWrite") === true;
5364
5388
  const chainLenRaw = record.get("chainLen");
5365
5389
  const chainLen = typeof chainLenRaw === "bigint" ? Number(chainLenRaw) : typeof chainLenRaw?.toNumber === "function" ? chainLenRaw.toNumber() : Number(chainLenRaw ?? 0);
5366
- console.error(`[neo4j-store] append-message conversationId=${conversationId.slice(0, 8)}\u2026 messageId=${messageId.slice(0, 8)}\u2026 prev=${prevMessageId ? prevMessageId.slice(0, 8) + "\u2026" : "null"} chainLen=${chainLen} waited=${waited}`);
5390
+ const messageSublabel = role === "user" ? "UserMessage" : "AssistantMessage";
5391
+ console.error(`[neo4j-store] append-message conversationId=${conversationId.slice(0, 8)}\u2026 messageId=${messageId.slice(0, 8)}\u2026 prev=${prevMessageId ? prevMessageId.slice(0, 8) + "\u2026" : "null"} chainLen=${chainLen} waited=${waited} sublabel=${messageSublabel}`);
5367
5392
  if (summarySetThisWrite) {
5368
5393
  console.error(`[neo4j-store] conversation-summary-set conversationId=${conversationId.slice(0, 8)}\u2026 len=${summary.length}`);
5369
5394
  }
@@ -19890,9 +19915,9 @@ app21.post("/launch", async (c) => {
19890
19915
  return c.json({ ok: false, error: "VNC failed to start" }, 502);
19891
19916
  }
19892
19917
  }
19893
- const terminalOk = await ensureTerminal(transport);
19894
- if (!terminalOk) {
19895
- return c.json({ ok: false, error: "Terminal failed to start" }, 502);
19918
+ const terminalResult = await ensureTerminal(transport);
19919
+ if (!terminalResult.ok) {
19920
+ return c.json({ ok: false, error: terminalResult.error ?? "Terminal failed to start" }, 502);
19896
19921
  }
19897
19922
  return c.json({ ok: true, transport });
19898
19923
  } catch (err) {
@@ -21077,7 +21102,23 @@ var GRAPH_LABEL_COLOURS = {
21077
21102
  ImageObject: "#6EE7B7",
21078
21103
  // Conversational
21079
21104
  Conversation: "#7C3AED",
21105
+ // Task 633 — admin vs public disambiguation on /graph. Darker violet for
21106
+ // admin conversations (the operator-facing side), lighter for public
21107
+ // (customer-facing) so the operator can read chat topology by colour
21108
+ // alone. Both within the Conversation family — the hue shift is subtle
21109
+ // enough to stay legible on adjacent nodes yet distinct enough to be
21110
+ // unmistakable in the popover legend.
21111
+ AdminConversation: "#5B21B6",
21112
+ PublicConversation: "#A78BFA",
21080
21113
  Message: "#A78BFA",
21114
+ // Task 633 — user vs assistant disambiguation on /graph. UserMessage
21115
+ // picks up the Person/Preference orange family cue (the user is a
21116
+ // person); AssistantMessage stays violet-adjacent to reinforce the
21117
+ // AdminConversation cue (both are admin-side). system/tool Messages
21118
+ // (not written by the persist path today; reserved shape) stay on the
21119
+ // base `:Message` colour.
21120
+ UserMessage: "#F97316",
21121
+ AssistantMessage: "#8B5CF6",
21081
21122
  ToolCall: "#C4B5FD",
21082
21123
  // Tasks / projects / events
21083
21124
  Task: "#DB2777",
@@ -21207,7 +21248,8 @@ async function handleDefault(c, accountId) {
21207
21248
  413
21208
21249
  );
21209
21250
  }
21210
- const nodes = result.rawNodes.map(pruneNode);
21251
+ const warnedClasses = /* @__PURE__ */ new Set();
21252
+ const nodes = result.rawNodes.map((n) => pruneNode(n, warnedClasses));
21211
21253
  const edges = result.rawEdges.filter((e) => e && e.id != null);
21212
21254
  const trashedSuffix = includeTrashed ? " includeTrashed=1" : "";
21213
21255
  console.error(
@@ -21250,7 +21292,8 @@ async function handleNeighbourhood(c, accountId) {
21250
21292
  );
21251
21293
  return c.json({ error: "Node not found" }, 404);
21252
21294
  }
21253
- const nodes = rawNodes.map(pruneNode);
21295
+ const warnedClasses = /* @__PURE__ */ new Set();
21296
+ const nodes = rawNodes.map((n) => pruneNode(n, warnedClasses));
21254
21297
  const edges = rawEdges.filter((e) => e && e.id != null);
21255
21298
  console.error(
21256
21299
  `[graph-page] load mode=neighbourhood account=${accountId} elementId=${elementId} nodes=${nodes.length} edges=${edges.length} ms=${elapsed}`
@@ -21351,20 +21394,50 @@ var NEIGHBOURHOOD_CYPHER = `
21351
21394
  [x IN windowNodes | {id: elementId(x), labels: labels(x), properties: properties(x)}] AS nodes,
21352
21395
  [e IN rawEdges WHERE e IS NOT NULL] AS edges
21353
21396
  `;
21354
- function convertNeo4jValue(value) {
21397
+ var KNOWN_DRIVER_CLASS_NAMES = /* @__PURE__ */ new Set([
21398
+ "DateTime",
21399
+ "Date",
21400
+ "LocalDateTime",
21401
+ "LocalTime",
21402
+ "Time",
21403
+ "Duration",
21404
+ "Integer"
21405
+ ]);
21406
+ function convertNeo4jValue(value, warnedClasses) {
21355
21407
  if (neo4j3.isDateTime(value) || neo4j3.isDate(value) || neo4j3.isLocalDateTime(value) || neo4j3.isLocalTime(value) || neo4j3.isTime(value) || neo4j3.isDuration(value)) {
21356
21408
  return value.toString();
21357
21409
  }
21358
21410
  if (neo4j3.isInt(value)) {
21359
21411
  return value.inSafeRange() ? value.toNumber() : value.toString();
21360
21412
  }
21413
+ if (Array.isArray(value)) {
21414
+ return value.map((v) => convertNeo4jValue(v, warnedClasses));
21415
+ }
21416
+ if (value !== null && typeof value === "object" && value.constructor === Object) {
21417
+ const out = {};
21418
+ for (const [k, v] of Object.entries(value)) {
21419
+ out[k] = convertNeo4jValue(v, warnedClasses);
21420
+ }
21421
+ return out;
21422
+ }
21423
+ if (value !== null && typeof value === "object") {
21424
+ const obj = value;
21425
+ const ctorName = obj.constructor?.name ?? "";
21426
+ const declared = obj._isNeo4jDriverType === true;
21427
+ if ((declared || KNOWN_DRIVER_CLASS_NAMES.has(ctorName)) && !warnedClasses.has(ctorName)) {
21428
+ if (process.env.NODE_ENV !== "production") {
21429
+ console.warn(`[graph-page] warn unknown-driver-type class=${ctorName}`);
21430
+ }
21431
+ warnedClasses.add(ctorName);
21432
+ }
21433
+ }
21361
21434
  return value;
21362
21435
  }
21363
- function pruneNode(node) {
21436
+ function pruneNode(node, warnedClasses) {
21364
21437
  const properties = {};
21365
21438
  for (const [key, value] of Object.entries(node.properties ?? {})) {
21366
21439
  if (STRIPPED_PROPERTIES.has(key)) continue;
21367
- properties[key] = convertNeo4jValue(value);
21440
+ properties[key] = convertNeo4jValue(value, warnedClasses);
21368
21441
  }
21369
21442
  const trashed = (node.labels ?? []).includes("Trashed");
21370
21443
  const labels = (node.labels ?? []).filter((l) => l !== "Trashed");
@@ -21580,15 +21653,15 @@ var LABELS_IN_GRAPH_CYPHER = `
21580
21653
  UNWIND keptLabels AS label
21581
21654
  WITH label, n, halfEdges,
21582
21655
  EXISTS {
21583
- MATCH (other)-[]->(n)
21656
+ MATCH (other)-[]-(n)
21584
21657
  WHERE NOT other:Trashed
21585
21658
  AND other.deletedAt IS NULL
21586
21659
  AND NONE(ol IN labels(other) WHERE ol = label)
21587
- } AS hasNonSelfInbound
21660
+ } AS hasNonSelfNeighbour
21588
21661
  WITH label,
21589
21662
  count(DISTINCT n) AS nodeCount,
21590
21663
  sum(halfEdges) AS relDegree,
21591
- count(DISTINCT CASE WHEN hasNonSelfInbound THEN n END) AS qualifyingCount
21664
+ count(DISTINCT CASE WHEN hasNonSelfNeighbour THEN n END) AS qualifyingCount
21592
21665
  RETURN label,
21593
21666
  nodeCount,
21594
21667
  relDegree,