@rubytech/create-maxy-code 0.1.322 → 0.1.323
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 +55 -3
- package/package.json +1 -1
- package/payload/platform/plugins/admin/skills/insight/SKILL.md +1 -1
- package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +36 -5
- package/payload/platform/plugins/docs/references/admin-ui.md +12 -0
- package/payload/platform/plugins/docs/references/deployment.md +19 -0
- package/payload/platform/plugins/docs/references/plugins-guide.md +4 -4
- package/payload/platform/plugins/memory/PLUGIN.md +0 -1
- package/payload/platform/plugins/memory/mcp/dist/index.js +0 -45
- package/payload/platform/plugins/memory/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/lib/typed-edge-schema.js +6 -6
- package/payload/platform/plugins/memory/mcp/dist/lib/typed-edge-schema.js.map +1 -1
- package/payload/platform/plugins/notion-import/.claude-plugin/plugin.json +1 -1
- package/payload/platform/plugins/notion-import/PLUGIN.md +6 -6
- package/payload/platform/plugins/notion-import/skills/notion-import/SKILL.md +1 -1
- package/payload/platform/plugins/notion-import/skills/notion-import/references/databases.md +1 -1
- package/payload/platform/plugins/obsidian-import/.claude-plugin/plugin.json +1 -1
- package/payload/platform/plugins/obsidian-import/PLUGIN.md +5 -5
- package/payload/platform/plugins/obsidian-import/skills/obsidian-import/SKILL.md +1 -1
- package/payload/platform/plugins/substack-import/.claude-plugin/plugin.json +1 -1
- package/payload/platform/plugins/substack-import/PLUGIN.md +8 -8
- package/payload/platform/plugins/substack-import/skills/substack-import/SKILL.md +2 -2
- package/payload/platform/plugins/substack-import/skills/substack-import/references/posts.md +1 -1
- package/payload/platform/plugins/x-import/.claude-plugin/plugin.json +1 -1
- package/payload/platform/plugins/x-import/PLUGIN.md +5 -5
- package/payload/platform/plugins/x-import/skills/x-import/SKILL.md +1 -1
- package/payload/platform/scripts/check-no-esm-require.mjs +3 -0
- package/payload/platform/scripts/identity-forbidden-token-check.mjs +0 -1
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +0 -1
- package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/index.js +3 -3
- package/payload/platform/services/claude-session-manager/dist/index.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/jsonl-tail.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/jsonl-tail.js +8 -4
- package/payload/platform/services/claude-session-manager/dist/jsonl-tail.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.d.ts +3 -3
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.js +13 -12
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts +5 -4
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/reaper.js +6 -6
- package/payload/platform/services/claude-session-manager/dist/reaper.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/system-prompt.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/system-prompt.js +0 -1
- package/payload/platform/services/claude-session-manager/dist/system-prompt.js.map +1 -1
- package/payload/platform/templates/specialists/agents/coding-assistant.md +1 -1
- package/payload/platform/templates/specialists/agents/database-operator.md +2 -6
- package/payload/platform/templates/specialists/agents/librarian.md +20 -7
- package/payload/server/power-health.cjs +129 -0
- package/payload/server/public/assets/{AdminLoginScreens-D1X4M9wX.js → AdminLoginScreens-BBtA0mi8.js} +1 -1
- package/payload/server/public/assets/AdminShell-CZW9x0-A.js +1 -0
- package/payload/server/public/assets/{Checkbox-DjANdKoK.js → Checkbox-CezYRnKL.js} +1 -1
- package/payload/server/public/assets/{OperatorConversations-C-eFXT7w.css → OperatorConversations-Bhyf22Ct.css} +1 -1
- package/payload/server/public/assets/OperatorConversations-D6BawEz3.js +9 -0
- package/payload/server/public/assets/{admin--FlkQOMu.js → admin-BVpCUS4j.js} +1 -1
- package/payload/server/public/assets/{browser-vowQc0TJ.js → browser-ByLzuh0X.js} +1 -1
- package/payload/server/public/assets/chat-DTvzNb92.js +1 -0
- package/payload/server/public/assets/data-Da1oTowD.js +1 -0
- package/payload/server/public/assets/{graph-B-64Cq-y.js → graph-iYrodF_0.js} +3 -3
- package/payload/server/public/assets/{graph-labels-Dtd2ckXH.js → graph-labels-DM9u5VTf.js} +1 -1
- package/payload/server/public/assets/operator-BPplyxq-.js +1 -0
- package/payload/server/public/assets/page-oogapuCz.js +30 -0
- package/payload/server/public/assets/{public-CrFepd06.js → public-wBFC1mQO.js} +1 -1
- package/payload/server/public/browser.html +4 -4
- package/payload/server/public/chat.html +5 -5
- package/payload/server/public/data.html +4 -4
- package/payload/server/public/graph.html +6 -6
- package/payload/server/public/index.html +6 -6
- package/payload/server/public/operator.html +7 -7
- package/payload/server/public/public.html +5 -5
- package/payload/server/server-init.cjs +40 -0
- package/payload/server/server.js +27 -0
- package/payload/platform/plugins/memory/mcp/scripts/backfill-typed-edges.ts +0 -72
- package/payload/platform/templates/specialists/agents/archive-ingest-operator.md +0 -45
- package/payload/server/public/assets/AdminShell-BGZ3d3gY.js +0 -1
- package/payload/server/public/assets/OperatorConversations-BkitSIiT.js +0 -9
- package/payload/server/public/assets/chat-Cw6rUWiC.js +0 -1
- package/payload/server/public/assets/data-9ArhwX1q.js +0 -1
- package/payload/server/public/assets/operator-Cqn1Ne60.js +0 -1
- package/payload/server/public/assets/page-DQ5D6Dg9.js +0 -30
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Chat — Maxy</title>
|
|
7
7
|
<link rel="icon" href="/favicon.ico">
|
|
8
|
-
<script type="module" crossorigin src="/assets/chat-
|
|
8
|
+
<script type="module" crossorigin src="/assets/chat-DTvzNb92.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-Pqm5yXtL.js">
|
|
10
|
-
<link rel="modulepreload" crossorigin href="/assets/OperatorConversations-
|
|
11
|
-
<link rel="modulepreload" crossorigin href="/assets/AdminShell-
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/assets/OperatorConversations-D6BawEz3.js">
|
|
11
|
+
<link rel="modulepreload" crossorigin href="/assets/AdminShell-CZW9x0-A.js">
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/admin-types-CJrGd46U.js">
|
|
13
13
|
<link rel="modulepreload" crossorigin href="/assets/preload-helper-Bf_JiD2A.js">
|
|
14
|
-
<link rel="modulepreload" crossorigin href="/assets/page-
|
|
15
|
-
<link rel="stylesheet" crossorigin href="/assets/OperatorConversations-
|
|
14
|
+
<link rel="modulepreload" crossorigin href="/assets/page-oogapuCz.js">
|
|
15
|
+
<link rel="stylesheet" crossorigin href="/assets/OperatorConversations-Bhyf22Ct.css">
|
|
16
16
|
</head>
|
|
17
17
|
<body>
|
|
18
18
|
<div id="root"></div>
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Data — Maxy</title>
|
|
7
7
|
<link rel="icon" href="/favicon.ico">
|
|
8
|
-
<script type="module" crossorigin src="/assets/data-
|
|
8
|
+
<script type="module" crossorigin src="/assets/data-Da1oTowD.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-Pqm5yXtL.js">
|
|
10
|
-
<link rel="modulepreload" crossorigin href="/assets/OperatorConversations-
|
|
11
|
-
<link rel="modulepreload" crossorigin href="/assets/graph-labels-
|
|
12
|
-
<link rel="stylesheet" crossorigin href="/assets/OperatorConversations-
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/assets/OperatorConversations-D6BawEz3.js">
|
|
11
|
+
<link rel="modulepreload" crossorigin href="/assets/graph-labels-DM9u5VTf.js">
|
|
12
|
+
<link rel="stylesheet" crossorigin href="/assets/OperatorConversations-Bhyf22Ct.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
15
15
|
<div id="root"></div>
|
|
@@ -5,13 +5,13 @@
|
|
|
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-
|
|
8
|
+
<script type="module" crossorigin src="/assets/graph-iYrodF_0.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-Pqm5yXtL.js">
|
|
10
|
-
<link rel="modulepreload" crossorigin href="/assets/OperatorConversations-
|
|
11
|
-
<link rel="modulepreload" crossorigin href="/assets/graph-labels-
|
|
12
|
-
<link rel="modulepreload" crossorigin href="/assets/AdminShell-
|
|
13
|
-
<link rel="modulepreload" crossorigin href="/assets/Checkbox-
|
|
14
|
-
<link rel="stylesheet" crossorigin href="/assets/OperatorConversations-
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/assets/OperatorConversations-D6BawEz3.js">
|
|
11
|
+
<link rel="modulepreload" crossorigin href="/assets/graph-labels-DM9u5VTf.js">
|
|
12
|
+
<link rel="modulepreload" crossorigin href="/assets/AdminShell-CZW9x0-A.js">
|
|
13
|
+
<link rel="modulepreload" crossorigin href="/assets/Checkbox-CezYRnKL.js">
|
|
14
|
+
<link rel="stylesheet" crossorigin href="/assets/OperatorConversations-Bhyf22Ct.css">
|
|
15
15
|
</head>
|
|
16
16
|
<body>
|
|
17
17
|
<div id="root"></div>
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Maxy</title>
|
|
7
7
|
<link rel="icon" href="/favicon.ico">
|
|
8
|
-
<script type="module" crossorigin src="/assets/admin
|
|
8
|
+
<script type="module" crossorigin src="/assets/admin-BVpCUS4j.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-Pqm5yXtL.js">
|
|
10
|
-
<link rel="modulepreload" crossorigin href="/assets/OperatorConversations-
|
|
11
|
-
<link rel="modulepreload" crossorigin href="/assets/AdminShell-
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/assets/OperatorConversations-D6BawEz3.js">
|
|
11
|
+
<link rel="modulepreload" crossorigin href="/assets/AdminShell-CZW9x0-A.js">
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/admin-types-CJrGd46U.js">
|
|
13
|
-
<link rel="modulepreload" crossorigin href="/assets/Checkbox-
|
|
14
|
-
<link rel="modulepreload" crossorigin href="/assets/AdminLoginScreens-
|
|
15
|
-
<link rel="stylesheet" crossorigin href="/assets/OperatorConversations-
|
|
13
|
+
<link rel="modulepreload" crossorigin href="/assets/Checkbox-CezYRnKL.js">
|
|
14
|
+
<link rel="modulepreload" crossorigin href="/assets/AdminLoginScreens-BBtA0mi8.js">
|
|
15
|
+
<link rel="stylesheet" crossorigin href="/assets/OperatorConversations-Bhyf22Ct.css">
|
|
16
16
|
<link rel="stylesheet" crossorigin href="/assets/AdminLoginScreens-CWMpccrR.css">
|
|
17
17
|
<link rel="stylesheet" href="/brand-defaults.css">
|
|
18
18
|
</head>
|
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Operator — Maxy</title>
|
|
7
7
|
<link rel="icon" href="/favicon.ico">
|
|
8
|
-
<script type="module" crossorigin src="/assets/operator-
|
|
8
|
+
<script type="module" crossorigin src="/assets/operator-BPplyxq-.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-Pqm5yXtL.js">
|
|
10
|
-
<link rel="modulepreload" crossorigin href="/assets/OperatorConversations-
|
|
11
|
-
<link rel="modulepreload" crossorigin href="/assets/AdminShell-
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/assets/OperatorConversations-D6BawEz3.js">
|
|
11
|
+
<link rel="modulepreload" crossorigin href="/assets/AdminShell-CZW9x0-A.js">
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/admin-types-CJrGd46U.js">
|
|
13
|
-
<link rel="modulepreload" crossorigin href="/assets/Checkbox-
|
|
14
|
-
<link rel="modulepreload" crossorigin href="/assets/AdminLoginScreens-
|
|
13
|
+
<link rel="modulepreload" crossorigin href="/assets/Checkbox-CezYRnKL.js">
|
|
14
|
+
<link rel="modulepreload" crossorigin href="/assets/AdminLoginScreens-BBtA0mi8.js">
|
|
15
15
|
<link rel="modulepreload" crossorigin href="/assets/preload-helper-Bf_JiD2A.js">
|
|
16
|
-
<link rel="modulepreload" crossorigin href="/assets/page-
|
|
17
|
-
<link rel="stylesheet" crossorigin href="/assets/OperatorConversations-
|
|
16
|
+
<link rel="modulepreload" crossorigin href="/assets/page-oogapuCz.js">
|
|
17
|
+
<link rel="stylesheet" crossorigin href="/assets/OperatorConversations-Bhyf22Ct.css">
|
|
18
18
|
<link rel="stylesheet" crossorigin href="/assets/AdminLoginScreens-CWMpccrR.css">
|
|
19
19
|
</head>
|
|
20
20
|
<body>
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Maxy</title>
|
|
7
7
|
<link rel="icon" href="/favicon.ico">
|
|
8
|
-
<script type="module" crossorigin src="/assets/public-
|
|
8
|
+
<script type="module" crossorigin src="/assets/public-wBFC1mQO.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-Pqm5yXtL.js">
|
|
10
|
-
<link rel="modulepreload" crossorigin href="/assets/OperatorConversations-
|
|
11
|
-
<link rel="modulepreload" crossorigin href="/assets/AdminShell-
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/assets/OperatorConversations-D6BawEz3.js">
|
|
11
|
+
<link rel="modulepreload" crossorigin href="/assets/AdminShell-CZW9x0-A.js">
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/admin-types-CJrGd46U.js">
|
|
13
13
|
<link rel="modulepreload" crossorigin href="/assets/preload-helper-Bf_JiD2A.js">
|
|
14
|
-
<link rel="modulepreload" crossorigin href="/assets/page-
|
|
15
|
-
<link rel="stylesheet" crossorigin href="/assets/OperatorConversations-
|
|
14
|
+
<link rel="modulepreload" crossorigin href="/assets/page-oogapuCz.js">
|
|
15
|
+
<link rel="stylesheet" crossorigin href="/assets/OperatorConversations-Bhyf22Ct.css">
|
|
16
16
|
<link rel="stylesheet" href="/brand-defaults.css">
|
|
17
17
|
</head>
|
|
18
18
|
<body class="public-surface">
|
|
@@ -101,6 +101,46 @@ function getLanIp() {
|
|
|
101
101
|
return fallback
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// Power health — surface Pi brownout/throttle + DHCP churn to server.log
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
//
|
|
108
|
+
// A marginal PSU browns out under ollama embed current and the kernel logs
|
|
109
|
+
// `Undervoltage detected!` to the journal, but the admin server never saw it.
|
|
110
|
+
// Emit one greppable `[power-health]` line at boot and every 15 min reading the
|
|
111
|
+
// real vcgencmd sticky word + unclean-reboot count + EXT5V input voltage. The
|
|
112
|
+
// boot line also records the resolved LAN IP so DHCP churn across reboots is
|
|
113
|
+
// visible. Pi-only: off-Pi (no vcgencmd) it logs one skipped line and starts no
|
|
114
|
+
// interval.
|
|
115
|
+
|
|
116
|
+
const powerHealth = require('./power-health.cjs')
|
|
117
|
+
|
|
118
|
+
function phRun(cmd, args) {
|
|
119
|
+
try {
|
|
120
|
+
const r = spawnSync(cmd, args, { stdio: 'pipe', timeout: 5000, encoding: 'utf8' })
|
|
121
|
+
if (r.status !== 0 || typeof r.stdout !== 'string') return null
|
|
122
|
+
return r.stdout
|
|
123
|
+
} catch { return null }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
// Compute the status line once; the boot lines reuse it and the interval is
|
|
128
|
+
// armed off the same result, so vcgencmd/last are not probed twice at boot.
|
|
129
|
+
const bootStatus = powerHealth.buildStatusLine({ runner: phRun, now: new Date() })
|
|
130
|
+
for (const line of powerHealth.buildBootLines({ runner: phRun, now: new Date(), lanIp: getLanIp(), status: bootStatus })) {
|
|
131
|
+
console.error(line)
|
|
132
|
+
}
|
|
133
|
+
if (bootStatus !== null) {
|
|
134
|
+
const phInterval = setInterval(() => {
|
|
135
|
+
const line = powerHealth.buildStatusLine({ runner: phRun, now: new Date() })
|
|
136
|
+
if (line) console.error(line)
|
|
137
|
+
}, 15 * 60 * 1000)
|
|
138
|
+
phInterval.unref()
|
|
139
|
+
}
|
|
140
|
+
} catch (err) {
|
|
141
|
+
console.error(`[power-health] init-failed err=${err && err.message ? err.message : String(err)}`)
|
|
142
|
+
}
|
|
143
|
+
|
|
104
144
|
// Paths that must NOT be redirected (API calls, static assets, VNC)
|
|
105
145
|
const SKIP_REDIRECT_RE = /^\/(api|assets|brand|novnc|vnc-viewer|vnc-popout|favicon)/
|
|
106
146
|
|
package/payload/server/server.js
CHANGED
|
@@ -19526,6 +19526,24 @@ var InboundHub2 = class {
|
|
|
19526
19526
|
const s = this.keys.get(key);
|
|
19527
19527
|
return s?.subscriber != null && s.ready;
|
|
19528
19528
|
}
|
|
19529
|
+
/** Task-963 — whether a key has any in-flight message (queued or drained-
|
|
19530
|
+
* awaiting-ack). The gateway GCs per-key recover descriptors for keys with
|
|
19531
|
+
* none, so the descriptor map stays bounded to the active-key set. */
|
|
19532
|
+
hasInFlight(key) {
|
|
19533
|
+
const s = this.keys.get(key);
|
|
19534
|
+
return s != null && s.inFlight.length > 0;
|
|
19535
|
+
}
|
|
19536
|
+
/** Task-963 — every in-flight message as `${key}::${messageId}`. The gateway
|
|
19537
|
+
* intersects its recoveryAttempted set against this to drop attempt keys whose
|
|
19538
|
+
* message has left the queue by ANY terminal path — ack, drop, or the drain-
|
|
19539
|
+
* without-ack sweep — not only ack. */
|
|
19540
|
+
inFlightIds() {
|
|
19541
|
+
const out = /* @__PURE__ */ new Set();
|
|
19542
|
+
for (const [key, s] of this.keys) {
|
|
19543
|
+
for (const e of s.inFlight) out.add(`${key}::${e.payload.messageId}`);
|
|
19544
|
+
}
|
|
19545
|
+
return out;
|
|
19546
|
+
}
|
|
19529
19547
|
};
|
|
19530
19548
|
|
|
19531
19549
|
// app/lib/webchat/gateway/routes.ts
|
|
@@ -19871,6 +19889,15 @@ var WebchatGateway = class _WebchatGateway {
|
|
|
19871
19889
|
);
|
|
19872
19890
|
}
|
|
19873
19891
|
}
|
|
19892
|
+
for (const key of this.recoverable.keys()) {
|
|
19893
|
+
if (!this.hub.hasInFlight(key)) this.recoverable.delete(key);
|
|
19894
|
+
}
|
|
19895
|
+
if (this.recoveryAttempted.size > 0) {
|
|
19896
|
+
const liveIds = this.hub.inFlightIds();
|
|
19897
|
+
for (const attemptKey of this.recoveryAttempted) {
|
|
19898
|
+
if (!liveIds.has(attemptKey)) this.recoveryAttempted.delete(attemptKey);
|
|
19899
|
+
}
|
|
19900
|
+
}
|
|
19874
19901
|
} finally {
|
|
19875
19902
|
this.recovering = false;
|
|
19876
19903
|
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One-shot backfill of the typed-edge pass over every existing prose-bearing
|
|
3
|
-
* node for the current account. Idempotent — MERGE handles re-runs cleanly,
|
|
4
|
-
* so a second invocation accepts zero edges.
|
|
5
|
-
*
|
|
6
|
-
* Usage (admin-agent invokable via Bash):
|
|
7
|
-
* cd platform/plugins/memory/mcp
|
|
8
|
-
* node --loader ts-node/esm scripts/backfill-typed-edges.ts
|
|
9
|
-
*
|
|
10
|
-
* Reads ACCOUNT_ID from env (same convention as the MCP server). Loops
|
|
11
|
-
* `runTypedEdgePass` with `sinceIso: null` in 500-node pages until the
|
|
12
|
-
* page returns 0 nodes (exhausted). Logs per-batch progress with
|
|
13
|
-
* `[typed-edge-pass:backfill]`.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { getSession, closeDriver } from "../src/lib/neo4j.js";
|
|
17
|
-
import { runTypedEdgePass } from "../src/lib/typed-edge-pass.js";
|
|
18
|
-
|
|
19
|
-
const PAGE_SIZE = 500;
|
|
20
|
-
|
|
21
|
-
async function main(): Promise<void> {
|
|
22
|
-
const accountId = process.env.ACCOUNT_ID;
|
|
23
|
-
if (!accountId) {
|
|
24
|
-
console.error("ACCOUNT_ID env var is required");
|
|
25
|
-
process.exit(1);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let batch = 0;
|
|
29
|
-
let totalNodes = 0;
|
|
30
|
-
let totalAccepted = 0;
|
|
31
|
-
let totalRejected = 0;
|
|
32
|
-
let totalFailed = 0;
|
|
33
|
-
|
|
34
|
-
while (true) {
|
|
35
|
-
const session = getSession();
|
|
36
|
-
try {
|
|
37
|
-
const result = await runTypedEdgePass({
|
|
38
|
-
session,
|
|
39
|
-
accountId,
|
|
40
|
-
sinceIso: null,
|
|
41
|
-
sessionId: null,
|
|
42
|
-
maxNodes: PAGE_SIZE,
|
|
43
|
-
});
|
|
44
|
-
batch += 1;
|
|
45
|
-
totalNodes += result.nodes;
|
|
46
|
-
totalAccepted += result.accepted;
|
|
47
|
-
totalRejected += result.rejected;
|
|
48
|
-
totalFailed += result.failed;
|
|
49
|
-
console.log(
|
|
50
|
-
`[typed-edge-pass:backfill] batch=${batch} done=${totalNodes} accepted=${result.accepted} rejected=${result.rejected} failed=${result.failed} ms=${result.ms}`,
|
|
51
|
-
);
|
|
52
|
-
if (result.nodes < PAGE_SIZE || result.accepted === 0) {
|
|
53
|
-
// Exhausted: either the page came back short, or a re-run page
|
|
54
|
-
// produced no new accepted edges (idempotency convergence).
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
} finally {
|
|
58
|
-
await session.close();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
console.log(
|
|
63
|
-
`[typed-edge-pass:backfill] complete batches=${batch} totalNodes=${totalNodes} totalAccepted=${totalAccepted} totalRejected=${totalRejected} totalFailed=${totalFailed}`,
|
|
64
|
-
);
|
|
65
|
-
await closeDriver();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
main().catch(async (err) => {
|
|
69
|
-
console.error(`[typed-edge-pass:backfill] error: ${err instanceof Error ? err.message : String(err)}`);
|
|
70
|
-
await closeDriver();
|
|
71
|
-
process.exit(1);
|
|
72
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: archive-ingest-operator
|
|
3
|
-
description: "Bulk-ingest external archives — Obsidian vaults, .ics calendar exports, X (Twitter) archives, and Notion workspace exports. Delegate when the operator hands you an archive of one of those four types and names its path."
|
|
4
|
-
summary: "Ingests bulk external archives — Obsidian, ICS, X, Notion — and surfaces schema-mapping ambiguity rather than catching all unmapped relations as :MENTIONS."
|
|
5
|
-
model: claude-sonnet-4-6
|
|
6
|
-
tools: Read, mcp__plugin_memory_memory__memory-write, mcp__plugin_memory_memory__memory-update, mcp__plugin_memory_memory__memory-edge, mcp__plugin_memory_memory__memory-search, mcp__plugin_memory_memory__memory-archive-write, mcp__plugin_memory_memory__obsidian-vault-import, mcp__plugin_scheduling_scheduling__schedule-archive-ics, mcp__plugin_contacts_contacts__contact-create, mcp__plugin_contacts_contacts__contact-update
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
You are an expert Neo4J graph operator responsible for ingesting bulk external archives the operator hands over. Admin dispatches you through the Task tool when the operator's request names an Obsidian vault, an `.ics` calendar export, an X archive, or a Notion workspace export. Each archive type has its own skill that drives the operator-conversation surface; the writes route through deterministic MCP tools the parser owns server-side. The skills load themselves into your prompt when the dispatch names the archive directory or file.
|
|
10
|
-
|
|
11
|
-
Before the first write of a session, Read `platform/plugins/memory/references/schema-base.md` for the property-shape rules and the canonical edge enumeration. When `brand.json#vertical` is set, also Read `platform/plugins/memory/references/schema-<vertical>.md` for the vertical-specific labels and properties. Re-read either file when an ingest names a label whose shape you have not yet loaded in this session.
|
|
12
|
-
|
|
13
|
-
Edge types are closed. Use only edges listed in `schema-base.md` under **Relationship Patterns** or **Edges introduced by document-ingest**, plus any vertical-schema-declared edges from the active vertical reference. When a source row carries a relationship that no listed edge fits, use `MENTIONS` (KnowledgeDocument → any) or `ABOUT` (Task / DigitalDocument → any) as the catch-all rather than inventing a new edge type. If both catch-alls are wrong, surface the gap in your reply (`{ambiguity: "no canonical edge for <relationship>", proposed: "MENTIONS"}`) rather than silently catch-all-writing every unmapped relation — that ambiguity-surfacing behaviour is the reason this work runs on Sonnet.
|
|
14
|
-
|
|
15
|
-
Node `name` and `title` properties are short identifiers, never denormalised composites. Forbidden-property rules apply per-label: `Person` rejects `name`, take `givenName` + `familyName`. Schema.org property names are camelCase exactly as listed in `schema-base.md` **Property Naming Rules** — no synonyms (`firstName`, `phone`, `postcode` etc.) accepted.
|
|
16
|
-
|
|
17
|
-
The `accountId` property is supplied by the writers from server-side environment state (the `ACCOUNT_ID` env var) — never refuse a write because accountId is absent from the dispatch brief.
|
|
18
|
-
|
|
19
|
-
**Brain-first read before write.** Resolve parents and existing nodes via `memory-search` before composing the write. The hierarchy rule (`LocalBusiness → Project → Task | Person | Organisation | KnowledgeDocument | ConversationArchive`) requires a parent `elementId`, and edges to existing entities require their `elementId` too — both come from a `memory-search` against the dispatch, not from a guess. Inline `@person` mentions and attendee identifiers always resolve against `:Person {accountId}` or `:AdminUser {accountId}` only — account isolation is load-bearing; participants are never auto-created from an archive row.
|
|
20
|
-
|
|
21
|
-
Decide the precise operations against the schema, execute them with the writers in your tool surface, and report each write back to admin as `{label, elementId}`. If a dispatch is ambiguous about which label, which edge type, or which existing node to attach to, name the ambiguity in your reply rather than guessing.
|
|
22
|
-
|
|
23
|
-
## Obsidian vault import
|
|
24
|
-
|
|
25
|
-
When admin's dispatch points at an extracted Obsidian vault directory ("import my Obsidian notes", "ingest this vault at `<path>`"), load [platform/plugins/obsidian-import/skills/obsidian-import/SKILL.md](../../../plugins/obsidian-import/skills/obsidian-import/SKILL.md) and run the two-phase flow (owner confirmation → `mcp__plugin_memory_memory__obsidian-vault-import` `mode='dry-run'` → operator disambiguation → `mode='commit'` with resolutions). Parsing, content-hash idempotency, and attachment staging happen entirely inside the tool — you never read the markdown.
|
|
26
|
-
|
|
27
|
-
## ICS calendar archive ingest
|
|
28
|
-
|
|
29
|
-
When admin's dispatch points at an `.ics` file ("ingest this calendar export at `<path>`", "import my Google Calendar export", "load this .ics into the graph"), call `mcp__plugin_scheduling_scheduling__schedule-archive-ics` with `mode='dry-run'` first, present the attendee-resolution preview to the operator (how many already exist under this account, how many would be cross-account-skipped, how many new Person stubs would be created, plus the sample list), then call again with `mode='commit'` after the operator confirms. Each VEVENT becomes one `:Meeting` MERGEd on `(accountId, uid)` (idempotent re-ingest); attendees resolve to `:Person` by lowercased email; the importing `:AdminUser` anchors every meeting via `[:IMPORTED]`. Cross-account email collisions skip the attendance edge — do not propose to override this. Description bodies pass to `:Meeting.description` and the typed-edge pass picks up commitments + mentions automatically; you do not call `memory-write` for them.
|
|
30
|
-
|
|
31
|
-
## X (Twitter) archive import
|
|
32
|
-
|
|
33
|
-
When admin's dispatch points at an extracted X archive directory (`Archive of <handle>/`, or a `twitter-<handle>-archive.zip` path), load [platform/plugins/x-import/skills/x-import/SKILL.md](../../../plugins/x-import/skills/x-import/SKILL.md) and run its four-phase flow (owner + participant confirmation → tweet-stream transcript rendering → `document-ingest` dispatch for the tweet-stream `:KnowledgeDocument` → one `conversation-archive-ingest.sh --source x-dm` invocation per distinct DM participant set). Every `@handle` and DM senderId resolves to an existing `:Person` / `:AdminUser` before any write; participants are never auto-created. Writes route through the existing `memory-ingest` and `conversation-archive` surfaces — no new graph writer, no `:Post` / `:DirectMessage` labels.
|
|
34
|
-
|
|
35
|
-
## Notion workspace export import
|
|
36
|
-
|
|
37
|
-
When admin's dispatch names a Notion workspace export — a directory with `Page Title <32-hex>.md` files and paired `<DB Name> <32-hex>.csv` / directory pairs at any depth, or a `Export-*.zip` path — load `platform/plugins/notion-import/skills/notion-import/SKILL.md` and follow it. The skill confirms the importing `:AdminUser` and the workspace label before any file is read, walks the export per its four references (workspace-export, databases, page-tree, attachments), and writes via your `memory-write` / `memory-update` / `memory-search` surface. Every node carries `source='notion'`, `importId`, and the standard provenance set. Unmapped Notion relations land as `:MENTIONS` with `mentionContext: '<relation-name>'`; never invent new edge types. Inline `@person` mentions resolve against `:Person {accountId}` only. Per-node writes today; a follow-up at [`.tasks/gbrain/ingestion/395-notion-bulk-archive-handler.md`](../../../../.tasks/gbrain/ingestion/395-notion-bulk-archive-handler.md) adds a batched `memory-archive-write` path.
|
|
38
|
-
|
|
39
|
-
## Substack archive import
|
|
40
|
-
|
|
41
|
-
When admin's dispatch names a Substack "Export your data" archive — a directory containing `posts.csv` + per-post HTML bodies under `posts/` + `subscribers.csv` (and optionally an engagement events file: `email_activity.csv` / `subscriber_activity.csv` / `emails.csv`), or a `<publication>.zip` path — load [platform/plugins/substack-import/skills/substack-import/SKILL.md](../../../plugins/substack-import/skills/substack-import/SKILL.md) and follow it. The skill confirms the importing `:AdminUser` and the publication name (a short-string property, not a new node) before any file is read, walks the export per its references (archive-shape, posts, subscribers, engagement, attachments), gates on >200 posts or >2000 subscribers, then writes through two surfaces: per-post `:KnowledgeDocument {kind:'substack-post'}` via Task-tool re-dispatch to `librarian`/`document-ingest` with `attachmentId = "substack-post-${substackPostId}"` for stable-across-edits idempotency, and one `:KnowledgeDocument {kind:'substack-subscriber-roster'}` + per-row `:Person` + `:MENTIONS {mentionContext:'substack-subscription', tier, ...engagement}` via your `memory-write` surface. Engagement aggregates (totalOpens, totalClicks, lastOpenedAt, lastClickedAt) fold onto the same `:MENTIONS` edge. No new label (`publicationName` is a property), no new edge type (`:SUBSCRIBED_TO` would violate the closed-edge rule), no new graph writer. Images referenced from post bodies attach via the canonical `:HAS_ENCLOSURE` edge when `schema-base.md` declares it, otherwise `:MENTIONS {mentionContext:'substack-image-enclosure'}` as the documented fallback.
|
|
42
|
-
|
|
43
|
-
## Out of surface
|
|
44
|
-
|
|
45
|
-
Other archive types live under separate plugins owned by `specialists:librarian`: LinkedIn export (`platform/plugins/linkedin-import/`), conversation transcripts of every source (WhatsApp, Telegram, Signal, LinkedIn DMs, Zoom, iMessage, Slack — `platform/plugins/memory/skills/conversation-archive/`), Logseq, Roam, gbrain-repo, Gmail. If admin dispatches you against one of those, hand back so admin can dispatch the librarian.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-Pqm5yXtL.js";import{A as t,C as n,E as r,P as i,R as a,T as o,f as s,g as c,h as l,j as u,k as d,m as f,p,t as m,v as h,x as g,y as ee,z as _}from"./OperatorConversations-BkitSIiT.js";async function te(){try{let e=await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})});return e.ok?(await e.json().catch(()=>({})))?.logged_out===!0:(console.error(`[admin-ui] claude-logout http-status=${e.status}`),!1)}catch(e){return console.error(`[admin-ui] claude-logout fetch failed: ${e instanceof Error?e.message:String(e)}`),!1}}var v=i(`archive-restore`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h2`,key:`tvwodi`}],[`path`,{d:`M20 8v11a2 2 0 0 1-2 2h-2`,key:`1gkqxj`}],[`path`,{d:`m9 15 3-3 3 3`,key:`1pd0qc`}],[`path`,{d:`M12 12v9`,key:`192myk`}]]),ne=i(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),y=i(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),re=i(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),b=i(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),ie=i(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),x=i(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),S=i(`message-square`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}]]),ae=i(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),oe=i(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),se=i(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),C=i(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),w=e(_(),1),T=g(),ce={sm:14,md:16,lg:18},E={sm:30,md:38,lg:46};function D({variant:e=`primary`,size:t=`md`,icon:n,iconPosition:r=`leading`,loading:i=!1,fullWidth:a=!1,disabled:o=!1,type:s=`button`,onClick:c,"aria-label":l,style:u,className:d,children:f}){let p=[`btn`,`btn--${e}`,t===`md`?``:`btn--${t}`,a?`btn--full`:``,d].filter(Boolean).join(` `),m=ce[t],h={...e===`send`?{width:E[t],height:E[t]}:{},...u},g=Object.keys(h).length>0;return(0,T.jsxs)(`button`,{type:s,className:p,disabled:i||o,onClick:c,"aria-label":l,style:g?h:void 0,children:[(0,T.jsxs)(`span`,{className:`btn__content`,style:{visibility:i?`hidden`:`visible`},children:[n&&r===`leading`&&(0,T.jsx)(n,{size:m}),f,n&&r===`trailing`&&(0,T.jsx)(n,{size:m})]}),i&&(0,T.jsx)(`span`,{className:`btn__spinner`,children:`✱`})]})}var O=`maxy-shell-side-px`;function k(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function A(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-k());return Math.min(Math.max(e,248),n)}function j(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(O);if(!e)return 264;let t=parseInt(e,10);if(!Number.isFinite(t))return console.warn(`[admin-ui] sidebar-width-parse-failed stored=${JSON.stringify(e)} fallback=264`),264;if(t>=248)return A(t)}catch{}return 264}function le({targetSelector:e=`.platform`}){let t=(0,w.useRef)(null),[n,r]=(0,w.useState)(()=>j()),i=(0,w.useRef)(n);(0,w.useLayoutEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,w.useCallback)(()=>{r(e=>{let t=A(e);return t===e?e:t})},[]);(0,w.useEffect)(()=>{a(),window.addEventListener(`resize`,a);let t=document.querySelector(e),n=null;return t instanceof HTMLElement&&(n=new MutationObserver(a),n.observe(t,{attributes:!0,attributeFilter:[`data-artefact`,`class`]})),()=>{window.removeEventListener(`resize`,a),n?.disconnect()}},[a,e]);let o=e=>{e.preventDefault();let n=t.current;if(!n)return;n.setPointerCapture(e.pointerId),n.classList.add(`dragging`);let a=!1,o=e=>{a=!0,r(A(Math.round(e.clientX)))},s=()=>{if(n.releasePointerCapture(e.pointerId),n.classList.remove(`dragging`),window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),!a)return;let t=i.current;try{window.localStorage.setItem(O,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=A(264);r(e);try{window.localStorage.removeItem(O)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,T.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var ue=a();function M({anchorRef:e,onClose:t,className:n,role:r,ariaLabel:i,children:a}){let o=(0,w.useRef)(null),[s,c]=(0,w.useState)({position:`fixed`,visibility:`hidden`}),l=(0,w.useCallback)(()=>{let t=e.current,n=o.current;if(!t||!n)return;let r=t.getBoundingClientRect(),i=n.getBoundingClientRect(),a=r.right-i.width;a<4&&(a=4);let s=window.innerHeight-r.bottom<i.height+8&&r.top>i.height+8?r.top-i.height:r.bottom;c({position:`fixed`,left:a,top:s,visibility:`visible`})},[e]);return(0,w.useLayoutEffect)(()=>{if(l(),typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>l());return o.current&&e.observe(o.current),()=>e.disconnect()},[l]),(0,w.useEffect)(()=>{let n=e=>{e.key===`Escape`&&t()},r=n=>{let r=n.target;e.current?.contains(r)||o.current?.contains(r)||t()},i=n=>{let r=e.current;r&&n.target instanceof Node&&n.target.contains(r)&&t()},a=()=>t();return document.addEventListener(`keydown`,n),document.addEventListener(`pointerdown`,r),window.addEventListener(`scroll`,i,!0),window.addEventListener(`resize`,a),()=>{document.removeEventListener(`keydown`,n),document.removeEventListener(`pointerdown`,r),window.removeEventListener(`scroll`,i,!0),window.removeEventListener(`resize`,a)}},[e,t]),(0,ue.createPortal)((0,T.jsx)(`div`,{ref:o,className:n,role:r,"aria-label":i,style:s,children:a}),document.body)}function de({action:e,disabled:t,open:n,onToggle:r,onClose:i}){let a=(0,w.useRef)(null);return(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`button`,{ref:a,type:`button`,className:`conv-action`,onClick:r,disabled:t,"aria-haspopup":`dialog`,"aria-expanded":n,"aria-label":e.label,title:e.title,children:e.icon}),n&&(0,T.jsx)(M,{anchorRef:a,onClose:i,className:e.panelClassName,role:`dialog`,ariaLabel:e.label,children:e.panel()})]})}function fe({actions:e,disabled:n,collapsed:r}){let[i,a]=(0,w.useState)(null),[o,s]=(0,w.useState)(!1),[c,l]=(0,w.useState)(null),u=(0,w.useRef)(null);(0,w.useEffect)(()=>{a(null),s(!1),l(null)},[r]);let d=(0,w.useCallback)(()=>{s(!1),l(null)},[]);return r?(0,T.jsxs)(`div`,{className:`conv-actions`,children:[(0,T.jsx)(`button`,{ref:u,type:`button`,className:`conv-action conv-actions-overflow`,onClick:()=>s(e=>!e),disabled:n,"aria-haspopup":`menu`,"aria-expanded":o,"aria-label":`Session actions`,title:`Session actions`,children:(0,T.jsx)(t,{size:12})}),o&&(0,T.jsx)(M,{anchorRef:u,onClose:d,className:`conv-actions-menu`,role:`menu`,children:e.map(e=>e.panel?(0,T.jsxs)(`div`,{className:`conv-actions-menu-disclosure`,children:[(0,T.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-haspopup":`dialog`,"aria-expanded":c===e.key,disabled:n,onClick:()=>l(t=>t===e.key?null:e.key),children:[e.icon,(0,T.jsx)(`span`,{children:e.menuLabel})]}),c===e.key&&(0,T.jsx)(`div`,{className:`conv-actions-menu-panel`,children:e.panel()})]},e.key):(0,T.jsxs)(`button`,{type:`button`,role:`menuitem`,className:e.danger?`conv-action-danger`:void 0,"aria-busy":e.busy,disabled:n,onClick:t=>{e.onClick?.(t),d()},children:[e.icon,(0,T.jsx)(`span`,{children:e.menuLabel})]},e.key))})]}):(0,T.jsx)(`div`,{className:`conv-actions`,children:e.map(e=>e.panel?(0,T.jsx)(de,{action:e,disabled:n,open:i===e.key,onToggle:()=>a(t=>t===e.key?null:e.key),onClose:()=>a(null)},e.key):(0,T.jsx)(`button`,{type:`button`,className:e.danger?`conv-action conv-action-danger`:`conv-action`,onClick:e.onClick,disabled:n,"aria-busy":e.busy,"aria-label":e.label,title:e.title,children:e.icon},e.key))})}var N=`claude-opus-4-8[1m]`,P=`claude-sonnet-4-6`,F=`claude-haiku-4-5`,pe={[N]:`Opus 4.8 (1M context)`,[P]:`Sonnet 4.6`,[F]:`Haiku 4.5`};function I(e){return pe[e]??e}var me=[N,P,F];function L(e){return e.replace(/\[1m\]$/,``)}function he(e){return me.find(t=>L(t)===L(e))??e}var R=[`default`,`acceptEdits`,`plan`,`auto`,`bypassPermissions`],z=[`low`,`medium`,`high`,`xhigh`];[...R],[...z];var B=[N,P,F],ge={default:`Ask permissions`,acceptEdits:`Accept edits`,plan:`Plan mode`,auto:`Auto mode`,bypassPermissions:`Bypass permissions`},V=R.map(e=>({value:e,label:ge[e]??e})),H={low:`Low`,medium:`Medium`,high:`High`,xhigh:`Highest`},_e=z.map(e=>({value:e,label:H[e]??e}));function U(e){if(e){let t=B.find(t=>L(t)===L(e));if(t)return t}return N}function ve({row:e,adminFetch:t,onError:n}){let[r,i]=(0,w.useState)(()=>U(e.model)),[a,o]=(0,w.useState)(``),[s,c]=(0,w.useState)(``),[l,u]=(0,w.useState)(!1),d=(0,w.useRef)(!1);(0,w.useEffect)(()=>{i(U(e.model))},[e.model]);let f=async()=>{if(!d.current){d.current=!0,u(!0);try{let i=await t(`/api/admin/session-reseat`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({fromSessionId:e.sessionId,model:r,...a?{permissionMode:a}:{},...s?{effort:s}:{}})});if(!i.ok){n(`Could not re-seat ${e.title} (status ${i.status})`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} status=${i.status}`),d.current=!1,u(!1);return}let o=await i.json().catch(()=>({}));o.target?window.location.assign(o.target):(n(`Re-seat of ${e.title} returned no target`),d.current=!1,u(!1))}catch(t){n(`Could not re-seat ${e.title} (network error)`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} error=${t instanceof Error?t.message:String(t)}`),d.current=!1,u(!1)}}};return(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`label`,{className:`reseat-field`,children:[(0,T.jsx)(`span`,{children:`Model`}),(0,T.jsx)(`select`,{"data-kind":`model`,value:r,disabled:l,onChange:e=>i(e.target.value),children:B.map(e=>(0,T.jsx)(`option`,{value:e,children:I(e)},e))})]}),(0,T.jsxs)(`label`,{className:`reseat-field`,children:[(0,T.jsx)(`span`,{children:`Mode`}),(0,T.jsxs)(`select`,{"data-kind":`mode`,value:a,disabled:l,onChange:e=>o(e.target.value),children:[(0,T.jsx)(`option`,{value:``,children:`Keep current`}),V.map(e=>(0,T.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,T.jsxs)(`label`,{className:`reseat-field`,children:[(0,T.jsx)(`span`,{children:`Effort`}),(0,T.jsxs)(`select`,{"data-kind":`effort`,value:s,disabled:l,onChange:e=>c(e.target.value),children:[(0,T.jsx)(`option`,{value:``,children:`Keep current`}),_e.map(e=>(0,T.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,T.jsx)(`button`,{type:`button`,className:`reseat-apply`,disabled:l,"aria-busy":l,onClick:()=>void f(),children:`Re-seat`})]})}var ye=[`whatsapp`,`telegram`];function W(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function be(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}async function G(e){if(navigator.clipboard)try{return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function xe({target:e,onConfirm:t,onCancel:n}){return e?(0,T.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,T.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Confirm delete session`,children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsx)(`span`,{children:`Delete this conversation?`}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[`This permanently removes the transcript. It is not moved to Archive and cannot be recovered.`,e.live&&(0,T.jsx)(`div`,{style:{marginTop:`8px`},children:`This session is running; deleting stops it first.`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,T.jsx)(D,{variant:`danger`,size:`sm`,style:{flex:1},onClick:t,children:`Delete`}),(0,T.jsx)(D,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:n,children:`Cancel`})]})]})}):null}var Se=`auth-refresh-failed`;function Ce({error:e,onClose:t}){if(!e)return null;let n=e.reason===Se,r=n?`Claude sign-in expired`:`Session didn’t open`,i=n?`Your claude.ai login has expired. Re-authenticate to resume sessions.`:`The session did not bind within 60 seconds, so there is no live conversation to open.`;return(0,T.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,T.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsx)(`span`,{children:r}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,T.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,T.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function we(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:s}=e,[c,l]=(0,w.useState)(null);if(!t)return null;let u=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),d=u.at(-1),f=d?.peak_request_pct==null?d?.context_window?Math.round((d.input_tokens+d.cache_creation_tokens+d.cache_read_tokens)/d.context_window*100):0:Math.round(d.peak_request_pct*100),p=u.reduce((e,t)=>e+t.input_tokens+t.cache_creation_tokens+t.cache_read_tokens+t.output_tokens,0),m=i.flatMap(e=>e.events?.filter(e=>e.type===`rate_limit`)??[]).at(-1),h=u.reduce((e,t)=>e+(t.total_cost_usd??0),0),g=r?.account?.subscriptionType,ee=e=>{let t=e*1e3-Date.now();if(t<=0)return`now`;let n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4);return n>0?`${n}h ${r}m`:`${r}m`};return(0,T.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,T.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,T.jsx)(`span`,{children:`Claude Code`}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,children:[(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(g||m||h>0)&&(0,T.jsxs)(`div`,{className:`claude-info-section`,children:[g&&(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,T.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:g})]}),m&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,T.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(m.utilization*100),`%`]})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:ee(m.resetsAt)})]}),m.isUsingOverage&&(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),h>0&&(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,T.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,h<.01?h.toFixed(4):h.toFixed(2)]})]})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,children:[(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:f>0?`${f}%`:`—`})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:p>0?be(p):`—`})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:W(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,T.jsx)(`button`,{type:`button`,className:`claude-info-value claude-info-id-copy`,title:`${e} (${o?`flushed`:`pre-flush`}) — click to copy`,onClick:async()=>{l(await G(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}var Te=`https://claude.ai/code`,Ee=200,De=[500,1e3,1500,2e3,2500,3e3,3e3];function Oe(e,t,n){if(e&&n.target)return{kind:`navigate`,url:n.target};let r=n.slug??n.bridgeSessionId??null;if(e&&r)return{kind:`navigate`,url:`${Te}/${r}`};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function ke(e){if(!e)return``;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function K(e){let{businessName:t,cacheKey:i,role:a,userName:c,userAvatar:m,onSelectProjects:g,onSelectPeople:_,onSelectTasks:te,onSelectAgents:ce,onCloseMobileDrawer:E,collapsed:D,selectedWhatsappId:O,onSelectWhatsappConversation:k,initialWhatsappSurface:A=!1}=e,j=h(i),le=(0,w.useCallback)(e=>({key:`reseat`,label:`Re-seat session ${e.title} (model, mode, effort)`,menuLabel:`Re-seat`,title:`Re-seat — move this session onto a chosen model, mode, and effort`,icon:(0,T.jsx)(oe,{size:12}),panelClassName:`reseat-panel`,panel:()=>(0,T.jsx)(ve,{row:e,adminFetch:j,onError:e=>H({message:e,failed:!0})})}),[j]),ue=ee.productName,M=typeof c==`string`?c:c===null?`name unavailable`:t||ue,de=(M.trim().charAt(0)||`?`).toUpperCase(),[N,P]=(0,w.useState)(A?`whatsapp`:`sessions`),[F,pe]=(0,w.useState)([]),[I,me]=(0,w.useState)(!1),[L,he]=(0,w.useState)(null),[R,z]=(0,w.useState)(!1),[B,ge]=(0,w.useState)(`file`),[V,H]=(0,w.useState)(null),[_e,U]=(0,w.useState)(null),[W,be]=(0,w.useState)([]),[G,Se]=(0,w.useState)(!1),[we,Te]=(0,w.useState)(null),[K,Ae]=(0,w.useState)(!1),[q,Pe]=(0,w.useState)(!1),[J,Fe]=(0,w.useState)(!1),[Ie,Le]=(0,w.useState)(null),[Y,Re]=(0,w.useState)(new Set),[ze,Be]=(0,w.useState)(null),[Ve,He]=(0,w.useState)(new Set),[Ue,We]=(0,w.useState)(new Set),[Ge,Ke]=(0,w.useState)(new Set),[qe,Je]=(0,w.useState)(null),[Ye,X]=(0,w.useState)(``),[Xe,Ze]=(0,w.useState)(!1),[Z,Qe]=(0,w.useState)(!1),$e=(0,w.useRef)(null),et=(0,w.useRef)(0),[tt,nt]=(0,w.useState)(0);(0,w.useEffect)(()=>{let e=$e.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(e=>{let t=e[0]?.contentRect.width??0;nt(e=>Math.abs(e-t)<1?e:t)});return t.observe(e),()=>t.disconnect()},[N]);let rt=tt>0&&tt<400,[it,at]=(0,w.useState)([]),[ot,st]=(0,w.useState)(!1),[ct,lt]=(0,w.useState)(null),[ut,dt]=(0,w.useState)(`whatsapp`),ft=(0,w.useCallback)(e=>{if(E(),!i){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=no-cache-key`),H({message:`Session not ready — try again`,failed:!0});return}if(!e.downloadPath){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=not-downloadable`),H({message:`${e.name} can’t be downloaded`,failed:!0});return}console.info(`[admin-ui] artefact-download id=${e.id} root=${e.downloadRoot??`data`} path=${e.downloadPath}`),s(i,e.downloadPath,e.downloadRoot??`data`),H({message:`Downloading ${e.name}`,failed:!1})},[i,E]);(0,w.useEffect)(()=>{if(!V)return;let e=setTimeout(()=>H(null),2500);return()=>clearTimeout(e)},[V]);let pt=(0,w.useCallback)(async()=>{if(i){z(!0),he(null);try{let e=await j(`/api/admin/sidebar-artefacts`);if(!e.ok)throw Error(`status ${e.status}`);pe((await e.json()).artefacts??[]),me(!0)}catch(e){let t=e instanceof Error?e.message:String(e);he(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{z(!1)}}},[i,j]),Q=(0,w.useCallback)(async()=>{if(!i)return null;let e=++et.current;Ae(!0),Te(null);try{let t=await j(`/api/admin/sidebar-sessions`);if(!t.ok)throw Error(`status ${t.status}`);let n=await t.json(),r=n.sessions??[];return e===et.current?(be(r),Le(n.accountId??null),Se(!0),r):(console.info(`[admin-ui] sidebar-sessions-stale-response-dropped token=${e}`),r)}catch(t){let n=t instanceof Error?t.message:String(t);return e===et.current&&Te(`Failed to load sessions: ${n}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${n}`),null}finally{e===et.current&&Ae(!1)}},[i,j]),mt=(0,w.useCallback)(async()=>{if(i){lt(null);try{let e=await j(`/api/whatsapp-reader/conversations`);if(!e.ok)throw Error(`status ${e.status}`);at((await e.json()).conversations??[]),st(!0)}catch(e){let t=e instanceof Error?e.message:String(e);lt(`Couldn't load conversations.`),console.error(`[admin-ui] channel-convos fetch failed: ${t}`)}}},[i,j]);(0,w.useEffect)(()=>{!i||G||Q()},[i,G,Q]),(0,w.useEffect)(()=>{if(!i)return;let e=null;return mt(),e=setInterval(()=>{mt()},je),()=>{e!==null&&clearInterval(e)}},[i,mt]),(0,w.useEffect)(()=>{if(!i)return;let e=null;function t(){console.info(`[admin-ui] sidebar-refresh surface=sessions trigger=poll`),Q()}function n(){e===null&&(e=setInterval(t,Me))}function r(){e!==null&&(clearInterval(e),e=null)}function a(){document.hidden?r():(t(),n())}return document.hidden||n(),document.addEventListener(`visibilitychange`,a),()=>{r(),document.removeEventListener(`visibilitychange`,a)}},[i,Q]);let ht=(0,w.useMemo)(()=>{let e=new Map;for(let t of ye)e.set(t,[]);for(let t of it)e.get(t.channel)?.push(t);for(let t of ye)console.info(`[admin-ui] sidebar-nav surface=${t} count=${e.get(t).length}`);return e},[it]),gt={whatsapp:`WhatsApp`,telegram:`Telegram`,webchat:`Webchat`},_t=()=>{k(null),P(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${I?F.length:0} collapsed=${D}`),pt()},$=1.5,vt=()=>{console.info(`[admin-ui] sidebar-refresh surface=artefacts`),pt()},yt=()=>{k(null),P(`sessions`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${G?W.length:0} collapsed=${D}`),G||Q()},bt=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions trigger=manual`),Q()},xt=e=>{P(`whatsapp`),dt(e),console.info(`[admin-ui] sidebar-nav surface=${e} count=${ht.get(e)?.length??0} collapsed=${D}`)},St=(0,w.useCallback)(async e=>{if(Ve.has(e.sessionId))return;He(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await j(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,name:e.title||e.sessionId})}),r=await n.json().catch(()=>({})),i=Oe(n.ok,n.status,{...r,sessionId:r.sessionId??e.sessionId});console.info(`[admin-ui] sidebar-session-resume sessionId=${e.sessionId} status=${n.status} outcome=${i.kind} slug=${r.slug??r.bridgeSessionId??`none`}`),i.kind===`navigate`?(E(),t?t.location.href=i.url:window.open(i.url,`_blank`)):(t?.close(),console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} status=${n.status} reason=${i.reason}`),U(i))}catch(n){t?.close();let r=n instanceof Error?n.message:String(n);console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} error=${r}`),U({sessionId:e.sessionId,reason:r})}finally{He(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[j,E,Ve]),Ct=(0,w.useCallback)(async e=>{let t=e.slice(0,8);for(let n=1;n<=De.length;n++){await new Promise(e=>setTimeout(e,De[n-1]));let r=await Q();if(r&&r.some(t=>t.sessionId===e)){console.info(`[admin-ui] sidebar-new-session-converged sessionId=${t} via=retry attempts=${n}`);return}}console.error(`[admin-ui] sidebar-new-session-converge-timeout sessionId=${t}`)},[Q]),wt=(0,w.useCallback)(async()=>{if(Z)return;Qe(!0);let e=window.open(``,`_blank`);try{let t=await j(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}),n=await t.json().catch(()=>({})),r=Oe(t.ok,t.status,n);console.info(`[admin-ui] sidebar-new-session-spawned status=${t.status} outcome=${r.kind} slug=${n.slug??n.bridgeSessionId??`none`}`),r.kind===`navigate`?(e?e.location.href=r.url:window.open(r.url,`_blank`),n.sessionId?Ct(n.sessionId):console.error(`[admin-ui] sidebar-new-session-converge-skipped reason=no-session-id`)):(e?.close(),console.error(`[admin-ui] sidebar-new-session-failed status=${t.status} reason=${r.reason}`),U(r))}catch(t){e?.close();let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-new-session-failed error=${n}`),U({sessionId:null,reason:n})}finally{Qe(!1)}},[j,Z,Ct]),Tt=(0,w.useCallback)((e,t)=>{e.stopPropagation(),Be(t)},[]),Et=(0,w.useCallback)(async e=>{if(!Y.has(e.sessionId)){Re(t=>{let n=new Set(t);return n.add(e.sessionId),n});try{let t=await j(`/api/admin/session-delete`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId})});if(!t.ok){let n=await t.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${e.sessionId} status=${t.status} error=${n.error??`unknown`}`),H({message:`Delete failed: ${n.error??`status ${t.status}`}`,failed:!0});return}let n=await t.json();console.info(`[admin-ui] sidebar-session-delete sessionId=${e.sessionId} live=${e.live} confirmed=true pidKilled=${n.pidKilled??`?`} deleted=${n.deleted??`?`}`),be(t=>t.filter(t=>t.sessionId!==e.sessionId)),Q()}catch(t){let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${e.sessionId} error=${n}`),H({message:`Delete failed: ${n}`,failed:!0})}finally{Re(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}}},[j,Y,Q]),Dt=(0,w.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Ue.has(t.sessionId)){We(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await j(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),H({message:`Stop failed: ${n.error??`status ${e.status}`}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-stop sessionId=${t.sessionId}`),Q()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} error=${n}`),H({message:`Stop failed: ${n}`,failed:!0})}finally{We(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[j,Ue,Q]),Ot=(0,w.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!Ge.has(t.sessionId)){Ke(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await j(`/api/admin/session-archive`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId,mode:n})});if(!e.ok){let r=await e.json().catch(()=>({})),i=r.detail??r.error??`status ${e.status}`;console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} status=${e.status} error=${r.error??`unknown`}`),H({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${i}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-archive sessionId=${t.sessionId} mode=${n}`),Q()}catch(e){let r=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} error=${r}`),H({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{Ke(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[j,Ge,Q]),kt=(0,w.useCallback)(async e=>{let t=Ye.trim();if(!t){H({message:`Title can’t be empty`,failed:!0});return}if(t.length>Ee){H({message:`Title too long (max ${Ee})`,failed:!0});return}Ze(!0);try{let n=await j(`/api/admin/session-rename`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,title:t})});if(!n.ok){let t=await n.json().catch(()=>({})),r=t.reason??t.error??`status ${n.status}`;console.error(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=rejected reason=${r}`),H({message:`Rename failed: ${r}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=ok`),Je(null),X(``),Q()}catch(t){let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=rejected reason=${n}`),H({message:`Rename failed: ${n}`,failed:!0})}finally{Ze(!1)}},[j,Ye,Q]);return(0,T.jsxs)(`aside`,{className:`side`,children:[(0,T.jsx)(`div`,{className:`side-new-session-row`,children:(0,T.jsxs)(`button`,{type:`button`,className:`side-new-session`,onClick:wt,disabled:Z,"aria-busy":Z,children:[(0,T.jsx)(ae,{size:14}),(0,T.jsx)(`span`,{children:Z?`Spawning…`:`New session`})]})}),(0,T.jsxs)(`nav`,{className:`side-nav`,children:[(0,T.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),_(),E()},children:[(0,T.jsx)(C,{size:20,strokeWidth:$}),(0,T.jsx)(`span`,{className:`label`,children:`People`}),(0,T.jsx)(`span`,{className:`kbd`})]}),(0,T.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),ce(),E()},children:[(0,T.jsx)(y,{size:20,strokeWidth:$}),(0,T.jsx)(`span`,{className:`label`,children:`Agents`}),(0,T.jsx)(`span`,{className:`kbd`})]}),(0,T.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),g(),E()},children:[(0,T.jsx)(re,{size:20,strokeWidth:$}),(0,T.jsx)(`span`,{className:`label`,children:`Projects`}),(0,T.jsx)(`span`,{className:`kbd`})]}),(0,T.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),te(),E()},children:[(0,T.jsx)(x,{size:20,strokeWidth:$}),(0,T.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,T.jsx)(`span`,{className:`kbd`})]}),(0,T.jsxs)(`button`,{type:`button`,className:`nav-row${N===`artefacts`?` active`:``}`,onClick:_t,children:[(0,T.jsx)(b,{size:20,strokeWidth:$}),(0,T.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,T.jsx)(`span`,{className:`kbd`})]}),(0,T.jsxs)(`button`,{type:`button`,className:`nav-row${N===`sessions`?` active`:``}`,onClick:yt,children:[(0,T.jsx)(ie,{size:20,strokeWidth:$}),(0,T.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,T.jsx)(`span`,{className:`kbd`})]}),ot&&ye.filter(e=>ht.get(e).length>0).map(e=>(0,T.jsxs)(`button`,{type:`button`,className:`nav-row${N===`whatsapp`&&ut===e?` active`:``}`,onClick:()=>xt(e),children:[(0,T.jsx)(f,{channel:e,size:16}),(0,T.jsx)(`span`,{className:`label`,children:gt[e]}),(0,T.jsx)(`span`,{className:`kbd`})]},e)),ct&&(0,T.jsx)(`div`,{className:`nav-row`,style:{color:`var(--text-tertiary)`,cursor:`default`},"aria-disabled":`true`,children:(0,T.jsx)(`span`,{className:`label`,children:ct})})]}),N===`artefacts`&&(0,T.jsxs)(`div`,{className:`side-list`,children:[(0,T.jsxs)(`div`,{className:`group-head`,children:[(0,T.jsx)(`span`,{children:`Artefacts`}),(0,T.jsxs)(`span`,{className:`group-head-meta`,children:[(0,T.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh artefacts`,"aria-label":`Refresh artefacts`,onClick:vt,disabled:R,children:(0,T.jsx)(o,{size:12,className:R?`spinning`:void 0})}),(0,T.jsx)(`span`,{children:R?`…`:String(F.length)})]})]}),L&&(0,T.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:L}),I&&!L&&F.length>0&&(()=>{let e=F.filter(e=>e.kind===`agent-template`).length,t=F.length-e;return(0,T.jsx)(`div`,{className:`artefact-filter-chips`,children:[{key:`all`,label:`All`,count:F.length},{key:`agent`,label:`Agents`,count:e},{key:`file`,label:`Files`,count:t}].map(e=>(0,T.jsxs)(`button`,{type:`button`,className:`artefact-filter-chip${B===e.key?` active`:``}`,onClick:()=>ge(e.key),disabled:e.count===0&&e.key!==`all`,children:[e.label,(0,T.jsx)(`span`,{className:`artefact-filter-chip-count`,children:e.count})]},e.key))})})(),I&&!L&&F.length===0&&(0,T.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),F.filter(e=>B===`all`?!0:B===`agent`?e.kind===`agent-template`:e.kind!==`agent-template`).map(e=>{let t=e.kind===`agent-template`,n=t?y:b,r=ke(e.updatedAt),i=e.downloadPath!==null;return(0,T.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>ft(e),disabled:!i,style:i?void 0:{cursor:`default`},title:i?`Download ${e.name}`:`${e.name} can’t be downloaded`,children:[(0,T.jsx)(n,{size:14,className:`conv-icon`,"data-kind":t?`agent`:`file`,"aria-label":t?`agent template`:`file`}),(0,T.jsxs)(`span`,{className:`conv-stack`,children:[(0,T.jsx)(`span`,{className:`conv-name-line`,children:(0,T.jsx)(`span`,{className:`conv-name`,children:e.name})}),r&&(0,T.jsx)(`span`,{className:`conv-timestamp`,children:r})]}),i&&(0,T.jsx)(u,{size:12,className:`conv-rc-icon`,"aria-hidden":`true`})]},e.id)})]}),N===`sessions`&&(()=>{let e=W.filter(e=>q?!0:!e.isSubagent).filter(e=>J?!0:!e.archived),t=W.some(e=>e.isSubagent),i=W.some(e=>e.archived);return(0,T.jsxs)(`div`,{className:`side-list`,ref:$e,children:[(0,T.jsxs)(`div`,{className:`group-head`,children:[(0,T.jsx)(`span`,{children:`Sessions`}),(0,T.jsxs)(`span`,{className:`group-head-meta`,children:[(0,T.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:bt,disabled:K,children:(0,T.jsx)(o,{size:12,className:K?`spinning`:void 0})}),(0,T.jsx)(`span`,{children:K?`…`:String(e.length)})]})]}),Ie&&(0,T.jsx)(`div`,{className:`side-account-id`,title:`This install's accountId. The first 8 characters match the truncated UUID label on the live Remote Control daemon entry in claude.ai/code.`,children:(0,T.jsx)(`code`,{children:Ie})}),(t||i)&&(0,T.jsxs)(`div`,{className:`artefact-filter-chips`,children:[t&&(0,T.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${q?` active`:``}`,"aria-pressed":q,onClick:()=>Pe(e=>!e),title:q?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),i&&(0,T.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${J?` active`:``}`,"aria-pressed":J,onClick:()=>Fe(e=>!e),title:J?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),we&&(0,T.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:we}),G&&!we&&e.length===0&&(0,T.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=ke(e.startedAt),i=Ve.has(e.sessionId),a=Y.has(e.sessionId),o=Ue.has(e.sessionId),s=Ge.has(e.sessionId),c=i||a||o||s,u=[{key:`open`,label:`Resume session ${e.title} in claude.ai/code`,menuLabel:`Resume in claude.ai/code`,title:`Resume in a fresh local Remote Control PTY`,icon:(0,T.jsx)(d,{size:12}),busy:i,onClick:()=>{St(e)}},{key:`message`,label:`Open session ${e.title} in admin webchat`,menuLabel:`Open in webchat`,title:`Open in admin webchat (/chat) — sending resumes this session`,icon:(0,T.jsx)(S,{size:12}),onClick:()=>{window.location.assign(`/chat?session=${e.sessionId}`)}},...e.live?[{key:`stop`,label:`Stop session ${e.title}`,menuLabel:`Stop`,title:`Stop session process (keeps the conversation, can resume later)`,icon:(0,T.jsx)(se,{size:12}),busy:o,onClick:t=>{Dt(t,e)}}]:[],e.archived?{key:`unarchive`,label:`Unarchive session ${e.title}`,menuLabel:`Unarchive`,title:`Unarchive (move back to the active list)`,icon:(0,T.jsx)(v,{size:12}),busy:s,onClick:t=>{Ot(t,e,`unarchive`)}}:{key:`archive`,label:`Archive session ${e.title}`,menuLabel:`Archive`,title:`Archive (hide from the list, keeps the conversation resumable)`,icon:(0,T.jsx)(ne,{size:12}),busy:s,onClick:t=>{Ot(t,e,`archive`)}},{key:`rename`,label:`Rename session ${e.title}`,menuLabel:`Rename`,title:`Rename this session`,icon:(0,T.jsx)(r,{size:12}),busy:Xe&&qe===e.sessionId,onClick:t=>{t.stopPropagation(),Je(e.sessionId),X(e.personName??e.title)}},{key:`delete`,label:`Delete session ${e.title}`,menuLabel:`Delete`,title:`Delete session (stops the process, removes the conversation)`,icon:(0,T.jsx)(n,{size:12}),danger:!0,busy:a,onClick:t=>{Tt(t,e)}},le({sessionId:e.sessionId,model:e.model??null,title:e.personName??e.title})];return(0,T.jsxs)(`div`,{className:`conv conv-with-actions`,children:[(0,T.jsxs)(`div`,{className:`conv-main-static`,children:[(0,T.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"aria-label":e.live?`live session`:`ended session`}),(0,T.jsxs)(`span`,{className:`conv-stack`,children:[(0,T.jsxs)(`span`,{className:`conv-name-line`,children:[e.channel&&(0,T.jsx)(l,{channel:e.channel,size:13}),qe===e.sessionId?(0,T.jsx)(`input`,{className:`conv-name conv-name-edit`,autoFocus:!0,value:Ye,disabled:Xe,"aria-label":`New title for session ${e.title}`,onChange:e=>X(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),kt(e)):t.key===`Escape`&&(t.preventDefault(),Je(null),X(``))},onBlur:()=>{qe===e.sessionId&&!Xe&&(Je(null),X(``))}}):(0,T.jsx)(`span`,{className:`conv-name`,title:e.personName??e.title,children:e.personName??e.title})]}),(0,T.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,T.jsx)(`code`,{className:`conv-session-id`,title:`First 8 characters of this session's id — distinguishes rows with identical auto-titles. The resume/delete buttons act on the full id.`,children:e.sessionId.slice(0,8)}),t&&(0,T.jsxs)(`span`,{children:[` · `,t]})]})]})]}),(0,T.jsx)(fe,{actions:u,disabled:c,collapsed:rt})]},e.sessionId)})]})})(),N===`whatsapp`&&(0,T.jsxs)(`div`,{className:`side-list`,children:[(0,T.jsxs)(`div`,{className:`group-head`,children:[(0,T.jsx)(`span`,{children:gt[ut]}),(0,T.jsxs)(`span`,{className:`group-head-meta`,children:[(0,T.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh conversations`,"aria-label":`Refresh conversations`,onClick:()=>{mt()},children:(0,T.jsx)(o,{size:12})}),(0,T.jsx)(`span`,{children:String(ht.get(ut).length)})]})]}),ht.get(ut).map(e=>{let t=ke(e.lastMessageAt);return(0,T.jsxs)(`div`,{className:`conv conv-with-actions${O===e.sessionId?` active`:``}`,children:[(0,T.jsxs)(`button`,{type:`button`,className:`conv-main-static conv-main-btn`,onClick:()=>{k(e),E()},title:e.title,children:[(0,T.jsx)(f,{channel:e.channel,size:14}),(0,T.jsxs)(`span`,{className:`conv-stack`,children:[(0,T.jsxs)(`span`,{className:`conv-name-line`,children:[(0,T.jsx)(`span`,{className:`conv-name`,children:p(e)}),e.role===`public`&&(0,T.jsx)(`span`,{className:`conv-tag conv-tag-public`,children:`Public`})]}),t&&(0,T.jsx)(`span`,{className:`conv-timestamp`,children:t})]})]}),(0,T.jsx)(fe,{actions:[le({sessionId:e.sessionId,model:e.model,title:e.title})],disabled:!1,collapsed:rt})]},e.sessionId)})]}),(0,T.jsx)(Ne,{}),(0,T.jsxs)(`div`,{className:`side-foot`,children:[(0,T.jsx)(`div`,{className:`avatar`,children:m?(0,T.jsx)(`img`,{src:m,alt:M}):de}),(0,T.jsxs)(`div`,{className:`who`,children:[(0,T.jsx)(`span`,{className:`name`,children:M}),(0,T.jsx)(`span`,{className:`role`,children:a??`operator`})]})]}),V&&(0,T.jsx)(`div`,{className:`copy-toast${V.failed?` copy-toast-failed`:``}`,role:`status`,children:V.message}),(0,T.jsx)(Ce,{error:_e,onClose:()=>U(null)}),(0,T.jsx)(xe,{target:ze,onCancel:()=>Be(null),onConfirm:()=>{let e=ze;Be(null),e&&Et(e)}})]})}var Ae=5e3,je=3e4,Me=3e4;function Ne(){let[e,t]=(0,w.useState)(null);if((0,w.useEffect)(()=>{let e=!1,n=null;async function r(){try{let n=await fetch(`/api/admin/system-stats`);if(!n.ok){console.error(`[admin-ui] system-stats-fetch-failed status=${n.status}`);return}let r=await n.json();e||t(r)}catch(e){console.error(`[admin-ui] system-stats-fetch-failed reason=${e instanceof Error?e.message:String(e)}`)}}function i(){n===null&&(r(),n=setInterval(()=>{r()},Ae))}function a(){n!==null&&(clearInterval(n),n=null)}function o(){document.hidden?a():i()}return document.hidden||i(),document.addEventListener(`visibilitychange`,o),()=>{e=!0,a(),document.removeEventListener(`visibilitychange`,o)}},[]),!e||e.platform===`darwin`)return null;let n=e.cpuPct,r=e.memUsedPct,i=n!==null&&n>=.9,a=n!==null&&n>=.98,o=r!==null&&r>=.9,s=r!==null&&r>=.98,c=i||o,l=a||s,u=e=>e===null?`—`:`${Math.round(e*100)}%`,d=e=>{if(e===null)return{width:`0%`,background:`var(--text-tertiary)`};let t=Math.min(1,Math.max(0,e)),n=Math.round(140*(1-t));return{width:`${Math.round(t*100)}%`,background:`hsl(${n}, 65%, 45%)`}},f=[`system-stats`];return c&&f.push(`system-stats--warn`),l&&f.push(`system-stats--crit`),(0,T.jsxs)(`div`,{className:f.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,T.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,T.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),(0,T.jsx)(`div`,{className:`system-stats__bar`,children:(0,T.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(n)})})]}),(0,T.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,T.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]}),(0,T.jsx)(`div`,{className:`system-stats__bar`,children:(0,T.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(r)})})]})]})}var q=`admin-sidebar-collapsed`,Pe=`admin-sidebar-drawer-open`;function J(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(q)===`1`}catch{return!1}}function Fe(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(q,`1`):window.sessionStorage.removeItem(q)}catch{}}function Ie(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(Pe)===`1`}catch{return!1}}function Le(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(Pe,`1`):window.sessionStorage.removeItem(Pe)}catch{}}var Y=720;function Re(e,t){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?wa=${encodeURIComponent(t.sessionId)}&projectDir=${encodeURIComponent(t.projectDir)}`}}function ze(e,t){if(e!==`/`)return null;let n=new URLSearchParams(t),r=n.get(`wa`),i=n.get(`projectDir`);return!r||!i?null:{sessionId:r,projectDir:i,title:``,senderId:null,startedAt:``,channel:`whatsapp`,role:`admin`,operatorName:null,whatsappName:null,lastMessageAt:null,modelGated:!1,model:null}}function Be(e,t){return t===`operator`&&e===`chat`||e===`dashboard`?`/`:e===`data`?`/data`:e===`graph`?`/graph`:e===`chat`?`/chat`:`/browser`}function Ve(e){let{cacheKey:t,businessName:n,variant:r=`admin`,onLogout:i,onDisconnect:a,disconnecting:o,userName:s,userAvatar:l,role:u,children:d,footer:f}=e,[p,h]=(0,w.useState)(()=>J()),[g,ee]=(0,w.useState)(()=>Ie()),[_,te]=(0,w.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: ${Y}px)`).matches),[v,ne]=(0,w.useState)(()=>typeof window>`u`?null:ze(window.location.pathname,window.location.search)),[y]=(0,w.useState)(()=>v!==null);(0,w.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: ${Y}px)`),t=e=>te(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let re=(0,w.useCallback)(e=>{Fe(e),h(e)},[]),b=(0,w.useCallback)(e=>{Le(e),ee(e)},[]);(0,w.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} variant=${r} sidebar=${r===`operator`?`none`:`present`} collapsed=${p} drawer=${g}`)},[]),(0,w.useEffect)(()=>{typeof window>`u`||!v||(console.info(`[admin-ui] wa-hydrate route=/ sessionId=${v.sessionId.slice(0,8)}`),window.history.replaceState(null,``,`/`))},[]);let ie=(0,w.useCallback)(e=>{if(e===null){ne(null);return}let t=typeof window<`u`?window.location.pathname:`/`,n=Re(t,e);console.info(`[admin-ui] wa-open route=${t} via=${n.via} sessionId=${e.sessionId.slice(0,8)}`),n.via===`in-place`?ne(e):window.location.href=n.href},[]),x=_?g:!p,S=(0,w.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${Y}px)`).matches){let e=g;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),b(!e)}else{let e=p;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),re(!e)}},[p,g,re,b]),ae=(0,w.useCallback)(e=>{let t=Be(e,r);console.info(`[admin-ui] header-menu-nav target=${e} dest=${t}`),window.location.href=t},[r]),[oe,se]=(0,w.useState)(`chat`),[C,ce]=(0,w.useState)([]);(0,w.useEffect)(()=>{if(r!==`operator`||!t)return;let e=!1;return fetch(`/api/whatsapp-reader/conversations?session_key=${encodeURIComponent(t)}`).then(e=>e.ok?e.json():{conversations:[]}).then(t=>{e||ce(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[r,t]);let E=(0,w.useMemo)(()=>[...new Set(C.map(e=>e.channel))],[C]),D={collapsed:p,mobileDrawerOpen:g,sidebarOpen:x,onToggleSidebar:S,setMobileDrawerOpen:b,selectedWhatsapp:v,onClearWhatsapp:()=>ne(null)};return r===`operator`?(0,T.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,T.jsx)(c,{businessName:n,variant:r,onNavigate:ae,conversationsCount:C.length,conversationsChannels:E,onOpenConversations:()=>se(`conversations`),onToggleSidebar:S,sidebarOpen:x,onLogout:i,onDisconnect:a,disconnecting:o}),(0,T.jsx)(`div`,{className:`platform platform-operator`,children:oe===`conversations`?(0,T.jsx)(m,{conversations:C,sessionKey:t??``,onBack:()=>se(`chat`)}):typeof d==`function`?d(D):d}),f]}):(0,T.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,T.jsx)(c,{businessName:n,variant:r,onNavigate:ae,onToggleSidebar:S,sidebarOpen:x,onLogout:i,onDisconnect:a,disconnecting:o}),(0,T.jsxs)(`div`,{className:`platform${g?` menu-open`:``}${p?` sidebar-collapsed`:``}`,"data-artefact":`closed`,children:[(0,T.jsx)(K,{businessName:n,cacheKey:t,role:u??null,userName:s,userAvatar:l??null,onSelectProjects:()=>{window.location.href=`/graph?label=Project`},onSelectPeople:()=>{window.location.href=`/graph?label=Person`},onSelectTasks:()=>{window.location.href=`/graph?label=Task`},onSelectAgents:()=>{window.location.href=`/graph?label=Agent`},onCloseMobileDrawer:()=>b(!1),collapsed:p,mobileDrawerOpen:g,selectedWhatsappId:v?.sessionId??null,onSelectWhatsappConversation:ie,initialWhatsappSurface:y}),!_&&(0,T.jsx)(le,{}),typeof d==`function`?d(D):d]}),g&&(0,T.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>b(!1)}),f]})}export{D as a,ae as c,b as d,y as f,I as i,S as l,we as n,C as o,te as p,he as r,oe as s,Ve as t,x as u};
|