@rubytech/create-maxy-code 0.1.483 → 0.1.485
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/package.json +1 -1
- package/payload/platform/package-lock.json +271 -1
- package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +28 -21
- package/payload/platform/plugins/cloudflare/mcp/__tests__/template-config.test.ts +26 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/index.html +16 -8
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/portal.css +25 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/portal.js +23 -7
- package/payload/platform/plugins/docs/references/google-guide.md +27 -20
- package/payload/platform/plugins/email/mcp/dist/__tests__/email-draft-send.test.js +76 -2
- package/payload/platform/plugins/email/mcp/dist/__tests__/email-draft-send.test.js.map +1 -1
- package/payload/platform/plugins/email/mcp/dist/lib/imap.d.ts +1 -0
- package/payload/platform/plugins/email/mcp/dist/lib/imap.d.ts.map +1 -1
- package/payload/platform/plugins/email/mcp/dist/lib/imap.js +1 -0
- package/payload/platform/plugins/email/mcp/dist/lib/imap.js.map +1 -1
- package/payload/platform/plugins/email/mcp/dist/tools/email-draft-send.d.ts.map +1 -1
- package/payload/platform/plugins/email/mcp/dist/tools/email-draft-send.js +87 -6
- package/payload/platform/plugins/email/mcp/dist/tools/email-draft-send.js.map +1 -1
- package/payload/platform/plugins/google/.claude-plugin/plugin.json +1 -1
- package/payload/platform/plugins/google/PLUGIN.md +20 -1
- package/payload/platform/plugins/google/mcp/dist/__tests__/account-register.test.js +29 -1
- package/payload/platform/plugins/google/mcp/dist/__tests__/account-register.test.js.map +1 -1
- package/payload/platform/plugins/google/mcp/dist/__tests__/consent-open.test.d.ts +2 -0
- package/payload/platform/plugins/google/mcp/dist/__tests__/consent-open.test.d.ts.map +1 -0
- package/payload/platform/plugins/google/mcp/dist/__tests__/consent-open.test.js +92 -0
- package/payload/platform/plugins/google/mcp/dist/__tests__/consent-open.test.js.map +1 -0
- package/payload/platform/plugins/google/mcp/dist/auth/consent-open.d.ts +61 -0
- package/payload/platform/plugins/google/mcp/dist/auth/consent-open.d.ts.map +1 -0
- package/payload/platform/plugins/google/mcp/dist/auth/consent-open.js +184 -0
- package/payload/platform/plugins/google/mcp/dist/auth/consent-open.js.map +1 -0
- package/payload/platform/plugins/google/mcp/dist/index.js +65 -2
- package/payload/platform/plugins/google/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/google/mcp/dist/tools/account-register.d.ts +14 -0
- package/payload/platform/plugins/google/mcp/dist/tools/account-register.d.ts.map +1 -1
- package/payload/platform/plugins/google/mcp/dist/tools/account-register.js +16 -0
- package/payload/platform/plugins/google/mcp/dist/tools/account-register.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.d.ts +5 -0
- package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.js +18 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/index.js +8 -0
- package/payload/platform/services/claude-session-manager/dist/index.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/subagent-injection-tail.d.ts +13 -0
- package/payload/platform/services/claude-session-manager/dist/subagent-injection-tail.d.ts.map +1 -0
- package/payload/platform/services/claude-session-manager/dist/subagent-injection-tail.js +149 -0
- package/payload/platform/services/claude-session-manager/dist/subagent-injection-tail.js.map +1 -0
- package/payload/platform/services/telegram-channel/dist/instructions.d.ts.map +1 -1
- package/payload/platform/services/telegram-channel/dist/instructions.js +17 -2
- package/payload/platform/services/telegram-channel/dist/instructions.js.map +1 -1
- package/payload/platform/services/webchat-channel/dist/instructions.d.ts.map +1 -1
- package/payload/platform/services/webchat-channel/dist/instructions.js +17 -2
- package/payload/platform/services/webchat-channel/dist/instructions.js.map +1 -1
- package/payload/platform/services/whatsapp-channel/dist/server.d.ts.map +1 -1
- package/payload/platform/services/whatsapp-channel/dist/server.js +16 -2
- package/payload/platform/services/whatsapp-channel/dist/server.js.map +1 -1
- package/payload/server/public/activity.html +6 -6
- package/payload/server/public/assets/{AdminLoginScreens-Jw45pvb2.js → AdminLoginScreens-DF9S5Rca.js} +1 -1
- package/payload/server/public/assets/AdminShell-B0PNDCAb.js +2 -0
- package/payload/server/public/assets/{Checkbox-D7_S2EUI.js → Checkbox-s5X6dso4.js} +1 -1
- package/payload/server/public/assets/activity-BRBsaalV.js +1 -0
- package/payload/server/public/assets/admin-rScqRq-R.js +1 -0
- package/payload/server/public/assets/{bot-GC7iZjtW.js → bot-BVO9Uqr_.js} +1 -1
- package/payload/server/public/assets/{browser-BI-wi3CM.js → browser-BVW4FFii.js} +1 -1
- package/payload/server/public/assets/calendar-CWsD3uLk.js +1 -0
- package/payload/server/public/assets/chat-DKGREuIO.js +1 -0
- package/payload/server/public/assets/chevron-down-m581tl1J.js +1 -0
- package/payload/server/public/assets/chevron-left-BAY0xfmR.js +1 -0
- package/payload/server/public/assets/chevron-right-Dy_REdYZ.js +1 -0
- package/payload/server/public/assets/data-TOWuhMFb.js +1 -0
- package/payload/server/public/assets/{graph-Cl72j3UC.js → graph-BEGs_P2m.js} +3 -3
- package/payload/server/public/assets/{graph-labels-7p-mVi9M.js → graph-labels-Axa04w8A.js} +1 -1
- package/payload/server/public/assets/{maximize-2-HcfeeOdJ.js → maximize-2-yucCepu_.js} +1 -1
- package/payload/server/public/assets/operator-911z_Fy_.js +1 -0
- package/payload/server/public/assets/page-6CZ8R57f.js +1 -0
- package/payload/server/public/assets/{page-DPQS0X5M.js → page-CgSgj8Cy.js} +3 -3
- package/payload/server/public/assets/{public-DAn13pnw.js → public-BzwveFwz.js} +1 -1
- package/payload/server/public/assets/{rotate-ccw-CCbbX5ef.js → rotate-ccw-BH51cf2Q.js} +1 -1
- package/payload/server/public/assets/tasks-21egY7A6.js +1 -0
- package/payload/server/public/assets/{time-entry-format-C-By1MbO.js → time-entry-format-DPdGkp1C.js} +1 -1
- package/payload/server/public/assets/{triangle-alert-BDtoi5R0.js → triangle-alert-DO2rjjfV.js} +1 -1
- package/payload/server/public/assets/useCopyFeedback-HMSM7-Ir.js +1 -0
- package/payload/server/public/assets/useSubAccountSwitcher-2ojOOYNo.css +1 -0
- package/payload/server/public/assets/{useSubAccountSwitcher-sPN6lobE.js → useSubAccountSwitcher-DLvqvfoc.js} +1 -1
- package/payload/server/public/assets/{useVoiceRecorder-DOFBQ2gP.js → useVoiceRecorder-BcukQIza.js} +1 -1
- package/payload/server/public/browser.html +4 -4
- package/payload/server/public/calendar.html +6 -6
- package/payload/server/public/chat.html +13 -13
- package/payload/server/public/data.html +10 -10
- package/payload/server/public/graph.html +11 -11
- package/payload/server/public/index.html +16 -16
- package/payload/server/public/operator.html +15 -15
- package/payload/server/public/public.html +13 -13
- package/payload/server/public/tasks.html +6 -6
- package/payload/server/server.js +128 -33
- package/payload/server/public/assets/AdminShell-DR6AzflZ.js +0 -2
- package/payload/server/public/assets/activity-CKbv3zFM.js +0 -1
- package/payload/server/public/assets/admin-DXUspIjz.js +0 -1
- package/payload/server/public/assets/calendar-DXnv4F7l.js +0 -1
- package/payload/server/public/assets/chat-CAdgaPW1.js +0 -1
- package/payload/server/public/assets/chevron-down-BCLf1wKu.js +0 -1
- package/payload/server/public/assets/chevron-left-BNtL-CjS.js +0 -1
- package/payload/server/public/assets/chevron-right-Bu5hsjy5.js +0 -1
- package/payload/server/public/assets/data-D7cYlorm.js +0 -1
- package/payload/server/public/assets/operator-C0iaGPNT.js +0 -1
- package/payload/server/public/assets/page-DsV3rID5.js +0 -1
- package/payload/server/public/assets/tasks-_Ij9BdOE.js +0 -1
- package/payload/server/public/assets/useCopyFeedback-CfbJc9iN.js +0 -1
- package/payload/server/public/assets/useSubAccountSwitcher-5jQsc23X.css +0 -1
package/payload/server/server.js
CHANGED
|
@@ -4107,7 +4107,8 @@ async function sendPaused(sock, to) {
|
|
|
4107
4107
|
} catch {
|
|
4108
4108
|
}
|
|
4109
4109
|
}
|
|
4110
|
-
async function sendReadReceipt(sock, chatJid, messageIds, participant) {
|
|
4110
|
+
async function sendReadReceipt(sock, chatJid, messageIds, participant, accountId) {
|
|
4111
|
+
const idTag = messageIds[0] ?? "?";
|
|
4111
4112
|
try {
|
|
4112
4113
|
await sock.readMessages([
|
|
4113
4114
|
...messageIds.map((id) => ({
|
|
@@ -4116,7 +4117,13 @@ async function sendReadReceipt(sock, chatJid, messageIds, participant) {
|
|
|
4116
4117
|
participant
|
|
4117
4118
|
}))
|
|
4118
4119
|
]);
|
|
4119
|
-
|
|
4120
|
+
console.error(
|
|
4121
|
+
`[whatsapp:receipt] op=ack account=${accountId ?? "?"} jid=${chatJid} id=${idTag} ok=true`
|
|
4122
|
+
);
|
|
4123
|
+
} catch (err) {
|
|
4124
|
+
console.error(
|
|
4125
|
+
`[whatsapp:receipt] op=ack account=${accountId ?? "?"} jid=${chatJid} id=${idTag} ok=false reason=${String(err).slice(0, 120)}`
|
|
4126
|
+
);
|
|
4120
4127
|
}
|
|
4121
4128
|
}
|
|
4122
4129
|
async function sendMediaMessage(sock, to, media, opts) {
|
|
@@ -6148,7 +6155,7 @@ function monitorInbound(conn) {
|
|
|
6148
6155
|
const sendReceipts = whatsAppConfig.accounts?.[conn.accountId]?.sendReadReceipts ?? whatsAppConfig.sendReadReceipts ?? true;
|
|
6149
6156
|
const sendAppendReceipt = () => {
|
|
6150
6157
|
if (sendReceipts && msgKeyId) {
|
|
6151
|
-
sendReadReceipt(sock2, remoteJid, [msgKeyId], participant);
|
|
6158
|
+
sendReadReceipt(sock2, remoteJid, [msgKeyId], participant, conn.accountId);
|
|
6152
6159
|
}
|
|
6153
6160
|
};
|
|
6154
6161
|
const accepted = appendMediaQueue.schedule(async () => {
|
|
@@ -6200,7 +6207,8 @@ function monitorInbound(conn) {
|
|
|
6200
6207
|
sock,
|
|
6201
6208
|
remoteJid,
|
|
6202
6209
|
[msg.key.id],
|
|
6203
|
-
isGroupJid(remoteJid) ? msg.key.participant ?? void 0 : void 0
|
|
6210
|
+
isGroupJid(remoteJid) ? msg.key.participant ?? void 0 : void 0,
|
|
6211
|
+
conn.accountId
|
|
6204
6212
|
);
|
|
6205
6213
|
}
|
|
6206
6214
|
const decision = evaluateSelfChatCommand({
|
|
@@ -6361,39 +6369,12 @@ async function handleInboundMessage(conn, msg) {
|
|
|
6361
6369
|
console.error(`${TAG17} drop: no text or media account=${conn.accountId} from=${remoteJid}`);
|
|
6362
6370
|
return;
|
|
6363
6371
|
}
|
|
6364
|
-
let mediaResult;
|
|
6365
|
-
if (extracted.mediaType && conn.sock) {
|
|
6366
|
-
const maxMb = whatsAppConfig.mediaMaxMb ?? 50;
|
|
6367
|
-
mediaResult = await downloadInboundMedia(msg, conn.sock, {
|
|
6368
|
-
maxBytes: maxMb * 1024 * 1024
|
|
6369
|
-
});
|
|
6370
|
-
if (!mediaResult) {
|
|
6371
|
-
console.error(`${TAG17} media download returned undefined account=${conn.accountId} type=${extracted.mediaType} from=${remoteJid}`);
|
|
6372
|
-
}
|
|
6373
|
-
}
|
|
6374
6372
|
const isGroup = isGroupJid(remoteJid);
|
|
6375
6373
|
const senderJid = isGroup ? msg.key.participant ?? remoteJid : remoteJid;
|
|
6376
6374
|
const senderPhone = await resolveJidToE164(senderJid, conn.lidMapping) ?? senderJid;
|
|
6377
6375
|
const lidCapture = lidCaptureFor(senderJid, senderPhone);
|
|
6378
6376
|
if (lidCapture) recordLidMapping(lidCapture.numericLid, lidCapture.e164);
|
|
6379
6377
|
const selfPhone = conn.selfPhone ?? "";
|
|
6380
|
-
if (extracted.mediaType === "audio" && mediaResult?.path) {
|
|
6381
|
-
const conversationKey = isGroup ? remoteJid : senderPhone;
|
|
6382
|
-
const debounceKey = `${conn.accountId}:${conversationKey}:${senderPhone}`;
|
|
6383
|
-
let resolvePending;
|
|
6384
|
-
const sttPending = new Promise((resolve39) => {
|
|
6385
|
-
resolvePending = resolve39;
|
|
6386
|
-
});
|
|
6387
|
-
if (conn.debouncer) conn.debouncer.registerPending(debounceKey, sttPending);
|
|
6388
|
-
try {
|
|
6389
|
-
const sttResult = await transcribe(mediaResult.path, mediaResult.mimetype);
|
|
6390
|
-
if (sttResult?.text) {
|
|
6391
|
-
extracted.text = sttResult.text;
|
|
6392
|
-
}
|
|
6393
|
-
} finally {
|
|
6394
|
-
resolvePending();
|
|
6395
|
-
}
|
|
6396
|
-
}
|
|
6397
6378
|
let accessResult;
|
|
6398
6379
|
if (isGroup) {
|
|
6399
6380
|
accessResult = checkGroupAccess({ groupJid: remoteJid });
|
|
@@ -6409,7 +6390,7 @@ async function handleInboundMessage(conn, msg) {
|
|
|
6409
6390
|
});
|
|
6410
6391
|
}
|
|
6411
6392
|
console.error(
|
|
6412
|
-
`${TAG17} inbound account=${conn.accountId} from=${senderPhone} group=${isGroup} access=${accessResult.allowed ? "allowed" : "blocked"}(${accessResult.reason}) agent=${accessResult.agentType}` + (extracted.mediaType ? ` media=${extracted.mediaType}` : "") + (
|
|
6393
|
+
`${TAG17} inbound account=${conn.accountId} from=${senderPhone} group=${isGroup} access=${accessResult.allowed ? "allowed" : "blocked"}(${accessResult.reason}) agent=${accessResult.agentType}` + (extracted.mediaType ? ` media=${extracted.mediaType}` : "") + (extracted.quotedMessage ? ` replyTo=${extracted.quotedMessage.id}` : "")
|
|
6413
6394
|
);
|
|
6414
6395
|
if (!accessResult.allowed && accessResult.reason === "account-manager-unresolved") {
|
|
6415
6396
|
console.error(
|
|
@@ -6431,7 +6412,34 @@ async function handleInboundMessage(conn, msg) {
|
|
|
6431
6412
|
}
|
|
6432
6413
|
const sendReceipts = whatsAppConfig.accounts?.[conn.accountId]?.sendReadReceipts ?? whatsAppConfig.sendReadReceipts ?? true;
|
|
6433
6414
|
if (sendReceipts && msg.key.id) {
|
|
6434
|
-
sendReadReceipt(conn.sock, remoteJid, [msg.key.id], isGroup ? senderJid : void 0);
|
|
6415
|
+
sendReadReceipt(conn.sock, remoteJid, [msg.key.id], isGroup ? senderJid : void 0, conn.accountId);
|
|
6416
|
+
}
|
|
6417
|
+
let mediaResult;
|
|
6418
|
+
if (extracted.mediaType && conn.sock) {
|
|
6419
|
+
const maxMb = whatsAppConfig.mediaMaxMb ?? 50;
|
|
6420
|
+
mediaResult = await downloadInboundMedia(msg, conn.sock, {
|
|
6421
|
+
maxBytes: maxMb * 1024 * 1024
|
|
6422
|
+
});
|
|
6423
|
+
if (!mediaResult) {
|
|
6424
|
+
console.error(`${TAG17} media download returned undefined account=${conn.accountId} type=${extracted.mediaType} from=${remoteJid}`);
|
|
6425
|
+
}
|
|
6426
|
+
}
|
|
6427
|
+
if (extracted.mediaType === "audio" && mediaResult?.path) {
|
|
6428
|
+
const conversationKey = isGroup ? remoteJid : senderPhone;
|
|
6429
|
+
const debounceKey = `${conn.accountId}:${conversationKey}:${senderPhone}`;
|
|
6430
|
+
let resolvePending;
|
|
6431
|
+
const sttPending = new Promise((resolve39) => {
|
|
6432
|
+
resolvePending = resolve39;
|
|
6433
|
+
});
|
|
6434
|
+
if (conn.debouncer) conn.debouncer.registerPending(debounceKey, sttPending);
|
|
6435
|
+
try {
|
|
6436
|
+
const sttResult = await transcribe(mediaResult.path, mediaResult.mimetype);
|
|
6437
|
+
if (sttResult?.text) {
|
|
6438
|
+
extracted.text = sttResult.text;
|
|
6439
|
+
}
|
|
6440
|
+
} finally {
|
|
6441
|
+
resolvePending();
|
|
6442
|
+
}
|
|
6435
6443
|
}
|
|
6436
6444
|
const reply = async (text) => {
|
|
6437
6445
|
if (isGroupJid(remoteJid)) {
|
|
@@ -11232,6 +11240,93 @@ app5.get("/conversations", requireAdminSession, async (c) => {
|
|
|
11232
11240
|
);
|
|
11233
11241
|
return c.json({ conversations: [...sessionConversations, ...allStoreRows] });
|
|
11234
11242
|
});
|
|
11243
|
+
function tagAndMergeInstallConversations(perAccount) {
|
|
11244
|
+
const all = [];
|
|
11245
|
+
for (const { isHouse, rows } of perAccount) {
|
|
11246
|
+
for (const r of rows) all.push({ ...r, isHouse });
|
|
11247
|
+
}
|
|
11248
|
+
return all.sort((x, y) => (y.lastMessageAt ?? "").localeCompare(x.lastMessageAt ?? ""));
|
|
11249
|
+
}
|
|
11250
|
+
app5.get("/conversations-all", requireAdminSession, async (c) => {
|
|
11251
|
+
const cacheKey = c.var.cacheKey;
|
|
11252
|
+
const caller2 = getAccountIdForSession(cacheKey) ?? null;
|
|
11253
|
+
let houseId = null;
|
|
11254
|
+
try {
|
|
11255
|
+
houseId = resolveHouseOrSoleAccountId(ACCOUNTS_DIR);
|
|
11256
|
+
} catch {
|
|
11257
|
+
houseId = null;
|
|
11258
|
+
}
|
|
11259
|
+
if (!caller2 || !houseId || caller2 !== houseId) {
|
|
11260
|
+
console.log(`[wa-reader] op=conversations-all-gate decision=deny caller=${caller2?.slice(0, 8) ?? "null"} house=${houseId?.slice(0, 8) ?? "null"}`);
|
|
11261
|
+
return c.json({ error: "house-only" }, 403);
|
|
11262
|
+
}
|
|
11263
|
+
const cfg = claudeConfigDir();
|
|
11264
|
+
if (!cfg) return c.json({ conversations: [] });
|
|
11265
|
+
const projectsRoot = join19(cfg, "projects");
|
|
11266
|
+
const userTitles = loadUserTitles(ACCOUNTS_DIR ?? null);
|
|
11267
|
+
const validAccounts = listValidAccounts();
|
|
11268
|
+
const validIds = new Set(validAccounts.map((a) => a.accountId));
|
|
11269
|
+
const houseIds = new Set(validAccounts.filter((a) => a.config.role === "house").map((a) => a.accountId));
|
|
11270
|
+
const rawByAccount = /* @__PURE__ */ new Map();
|
|
11271
|
+
for (const { path: path3 } of enumerateJsonls(projectsRoot)) {
|
|
11272
|
+
const sessionId = basename4(path3).replace(/\.jsonl$/, "");
|
|
11273
|
+
const projectDir = dirname5(path3);
|
|
11274
|
+
const meta = readSidecarMeta(join19(projectDir, `${sessionId}.meta.json`));
|
|
11275
|
+
if (!isReaderChannelSession(meta.role, meta.channel)) continue;
|
|
11276
|
+
if (meta.accountId === null || !validIds.has(meta.accountId)) continue;
|
|
11277
|
+
let body = "";
|
|
11278
|
+
try {
|
|
11279
|
+
body = readFileSync19(path3, "utf8");
|
|
11280
|
+
} catch {
|
|
11281
|
+
}
|
|
11282
|
+
const { title } = resolveTitle(body, sessionId, userTitles);
|
|
11283
|
+
const turns = parseTranscript(body.split("\n"));
|
|
11284
|
+
const row = {
|
|
11285
|
+
sessionId,
|
|
11286
|
+
projectDir,
|
|
11287
|
+
title,
|
|
11288
|
+
startedAt: meta.startedAt ?? "",
|
|
11289
|
+
role: meta.role,
|
|
11290
|
+
channel: meta.channel,
|
|
11291
|
+
senderId: meta.senderId,
|
|
11292
|
+
lastMessageAt: lastTurnTs(turns),
|
|
11293
|
+
modelGated: isModelGated(turns),
|
|
11294
|
+
model: lastAssistantModel(body)
|
|
11295
|
+
};
|
|
11296
|
+
const list = rawByAccount.get(meta.accountId) ?? [];
|
|
11297
|
+
list.push(row);
|
|
11298
|
+
rawByAccount.set(meta.accountId, list);
|
|
11299
|
+
}
|
|
11300
|
+
let users = [];
|
|
11301
|
+
try {
|
|
11302
|
+
users = readUsersFile(USERS_FILE) ?? [];
|
|
11303
|
+
} catch (err) {
|
|
11304
|
+
console.error(`[wa-reader] op=users-file-unreadable reason=${err instanceof Error ? err.message : String(err)}`);
|
|
11305
|
+
users = [];
|
|
11306
|
+
}
|
|
11307
|
+
const perAccount = [];
|
|
11308
|
+
for (const account of validAccounts) {
|
|
11309
|
+
const isHouse = houseIds.has(account.accountId);
|
|
11310
|
+
const sessionRows = selectReaderChannelSessions(rawByAccount.get(account.accountId) ?? []).filter((r) => r.channel !== "whatsapp");
|
|
11311
|
+
const admins = account.config.admins ?? [];
|
|
11312
|
+
const distinct = [...new Set(sessionRows.map((r) => r.senderId).filter((s) => !!s))];
|
|
11313
|
+
const resolved = await resolveOperatorNamesBySender(users, admins, distinct);
|
|
11314
|
+
const nameBySender = /* @__PURE__ */ new Map();
|
|
11315
|
+
for (const senderId of distinct) nameBySender.set(senderId, resolved.get(senderId)?.name ?? null);
|
|
11316
|
+
const named = sessionRows.map((r) => ({
|
|
11317
|
+
...r,
|
|
11318
|
+
operatorName: r.senderId ? nameBySender.get(r.senderId) ?? null : null
|
|
11319
|
+
}));
|
|
11320
|
+
const storeRows = buildStoreConversationRows(account.accountId, readConversationSummaries(account.accountId));
|
|
11321
|
+
perAccount.push({ isHouse, rows: [...named, ...storeRows] });
|
|
11322
|
+
}
|
|
11323
|
+
const conversations = tagAndMergeInstallConversations(perAccount);
|
|
11324
|
+
const houseRows = conversations.filter((r) => r.isHouse).length;
|
|
11325
|
+
console.log(
|
|
11326
|
+
`[wa-reader] op=conversations-all accounts=${validAccounts.length} rows=${conversations.length} house=${houseRows} sub=${conversations.length - houseRows}`
|
|
11327
|
+
);
|
|
11328
|
+
return c.json({ conversations });
|
|
11329
|
+
});
|
|
11235
11330
|
function readFrom(path3, from) {
|
|
11236
11331
|
const end = statSync7(path3).size;
|
|
11237
11332
|
if (end <= from) return { buf: Buffer.alloc(0), end: from };
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-TPjIAO9U.js";import{A as t,C as n,D as r,E as i,H as a,I as o,L as s,M as c,N as l,O as u,P as d,S as f,T as p,V as m,_ as h,a as g,b as _,d as v,g as ee,h as y,i as b,j as x,l as S,m as C,n as w,p as te,t as ne,u as re,v as ie,w as ae,x as oe,y as T}from"./useSubAccountSwitcher-sPN6lobE.js";async function se(){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 E=e(a(),1),D=s(),O={sm:14,md:16,lg:18},k={sm:30,md:38,lg:46};function A({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,"aria-pressed":u,style:d,className:f,children:p}){let m=[`btn`,`btn--${e}`,t===`md`?``:`btn--${t}`,a?`btn--full`:``,f].filter(Boolean).join(` `),h=O[t],g={...e===`send`?{width:k[t],height:k[t]}:{},...d},_=Object.keys(g).length>0;return(0,D.jsxs)(`button`,{type:s,className:m,disabled:i||o,onClick:c,"aria-label":l,"aria-pressed":u,style:_?g:void 0,children:[(0,D.jsxs)(`span`,{className:`btn__content`,style:{visibility:i?`hidden`:`visible`},children:[n&&r===`leading`&&(0,D.jsx)(n,{size:h}),p,n&&r===`trailing`&&(0,D.jsx)(n,{size:h})]}),i&&(0,D.jsx)(`span`,{className:`btn__spinner`,children:`✱`})]})}var ce=c(`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`}]]),le=c(`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`}]]),ue=c(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),de=c(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),j=c(`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`}]]),fe=c(`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`}]]),pe=c(`panel-left`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),me=c(`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`}]]);function he({connected:e,onConnectClaude:t}){return e?(0,D.jsxs)(`span`,{className:`claude-status-pill`,"data-connected":`true`,title:`Claude is connected`,children:[(0,D.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,D.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connected`}),(0,D.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--live`,"aria-hidden":`true`})]}):(0,D.jsxs)(`button`,{type:`button`,className:`claude-status-pill claude-status-pill--action`,"data-connected":`false`,onClick:t,title:`Connect Claude`,children:[(0,D.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,D.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connect`}),(0,D.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--down`,"aria-hidden":`true`})]})}function ge(e){return e===`/`||e===``?`Dashboard`:e.startsWith(`/chat`)?`Chat`:e.startsWith(`/tasks`)?`Tasks`:e.startsWith(`/data`)?`Data`:e.startsWith(`/calendar`)?`Calendar`:e.startsWith(`/graph`)?`Graph`:e.startsWith(`/activity`)?`Activity`:e.startsWith(`/browser`)?`Browser`:`Dashboard`}function _e({title:e,sidebarOpen:t,onToggleSidebar:n,claudeConnected:r,onConnectClaude:i}){let a=e??ge(typeof window<`u`?window.location.pathname:`/`),o=r!==void 0&&i!==void 0;return(0,D.jsxs)(`header`,{className:`admin-page-header`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`admin-page-header__toggle`,"aria-label":t?`Hide sidebar`:`Show sidebar`,title:t?`Hide sidebar`:`Show sidebar`,"aria-expanded":t,onClick:n,children:[(0,D.jsx)(pe,{className:`admin-page-header__toggle-desktop`,size:18,strokeWidth:1.75}),(0,D.jsx)(f,{className:`admin-page-header__toggle-mobile`,size:22,strokeWidth:1.75})]}),(0,D.jsx)(`h1`,{className:`admin-page-header__title`,children:a}),o&&(0,D.jsx)(`div`,{className:`admin-page-header__right`,children:(0,D.jsx)(he,{connected:r,onConnectClaude:i})})]})}var ve=[{label:`Home`,href:`/`,Icon:ae,match:e=>e===`/`||e===``},{label:`Chat`,href:`/chat`,Icon:oe,match:e=>e.startsWith(`/chat`)},{label:`Tasks`,href:`/tasks`,Icon:j,match:e=>e.startsWith(`/tasks`)},{label:`Data`,href:`/data`,Icon:u,match:e=>e.startsWith(`/data`)},{label:`Calendar`,href:`/calendar`,Icon:t,match:e=>e.startsWith(`/calendar`)}];function ye(e){let t=ve.find(t=>t.match(e));return t?t.href:`/`}function be(){let e=ye(typeof window<`u`?window.location.pathname:`/`);return(0,D.jsx)(`nav`,{className:`bottom-tab-bar`,"aria-label":`Primary`,children:ve.map(t=>{let n=t.href===e,{Icon:r}=t;return(0,D.jsxs)(`a`,{href:t.href,className:`bottom-tab${n?` is-active`:``}`,"aria-current":n?`page`:void 0,children:[(0,D.jsx)(r,{size:19,strokeWidth:1.75}),(0,D.jsx)(`span`,{className:`bottom-tab__label`,children:t.label})]},t.href)})})}var M=`maxy-shell-side-px`;function xe(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function N(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-xe());return Math.min(Math.max(e,248),n)}function Se(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(M);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 N(t)}catch{}return 264}function Ce({targetSelector:e=`.platform`}){let t=(0,E.useRef)(null),[n,r]=(0,E.useState)(()=>Se()),i=(0,E.useRef)(n);(0,E.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,E.useCallback)(()=>{r(e=>{let t=N(e);return t===e?e:t})},[]);(0,E.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(N(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(M,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=N(264);r(e);try{window.localStorage.removeItem(M)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,D.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var we=m();function Te(e){return Math.max(14,e/2-386)}function Ee(e){return e.left===0&&e.top===0&&e.width===0&&e.height===0}var De={position:`fixed`,visibility:`hidden`};function P({anchorRef:e,onClose:t,className:n,role:r,ariaLabel:i,anchorId:a,children:o}){let s=(0,E.useRef)(null),[c,l]=(0,E.useState)(De),u=(0,E.useRef)(null),d=(0,E.useCallback)(()=>{let t=s.current;if(!t)return;let r=e.current,i=[n,a].filter(Boolean).join(`:`)||`unknown`,o=t.getBoundingClientRect(),c=window.innerWidth,d=window.innerHeight,f=o.width>0&&o.height>0,p=r?r.getBoundingClientRect():null,m=(e,t)=>console.error(`[anchored-popover] op=offscreen id=${i} left=${e} top=${t} w=${o.width} h=${o.height} viewport=${c},${d}`),h=e=>{e!==u.current&&(u.current=e,console.log(e))};if(h(`[anchored-popover] op=anchor id=${i} present=${!!r} rect=${p?`${p.left},${p.top},${p.width},${p.height}`:`none`}`),!p){let e=Math.max(4,c-o.width-Te(c)),t=Math.max(4,d-o.height-14);l({position:`fixed`,left:e,top:t,visibility:`visible`}),h(`[anchored-popover] op=placed id=${i} left=${e} top=${t} w=${o.width} h=${o.height} flipped=false clampedLeft=false clampedRight=false`);return}if(f&&Ee(p)){l(De),m(p.left,p.top);return}let g=p.right-o.width,_=c-o.width-4,v=!1,ee=!1;g>_&&(g=_,v=!0),g<4&&(g=4,ee=!0);let y=d-p.bottom-4,b=p.top-4,x=o.height+8<=y?!1:o.height+8<=b?!0:b>y,S=Math.max(0,x?b:y),C=x?Math.max(4,p.top-Math.min(o.height,S)):p.bottom;l({position:`fixed`,left:g,top:C,maxHeight:S,visibility:`visible`}),h(`[anchored-popover] op=placed id=${i} left=${g} top=${C} w=${o.width} h=${o.height} maxH=${S} flipped=${x} clampedLeft=${ee} clampedRight=${v}`);let w=Math.min(o.height,S);f&&(g+o.width<=0||g>=c||C+w<=0||C>=d)&&m(g,C)},[e,a,n]);return(0,E.useLayoutEffect)(()=>{if(d(),typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>d());return s.current&&e.observe(s.current),()=>e.disconnect()},[d]),(0,E.useEffect)(()=>{let n=e=>{e.key===`Escape`&&t()},r=n=>{let r=n.target;e.current?.contains(r)||s.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,we.createPortal)((0,D.jsx)(`div`,{ref:s,className:n,role:r,"aria-label":i,style:c,children:o}),document.body)}function Oe({actions:e,disabled:t}){let[n,r]=(0,E.useState)(!1),[i,a]=(0,E.useState)(null),o=(0,E.useRef)(null),s=(0,E.useCallback)(()=>{r(!1),a(null)},[]);return(0,D.jsxs)(`div`,{className:`conv-actions`,children:[(0,D.jsx)(`button`,{ref:o,type:`button`,className:`conv-action conv-actions-overflow`,onClick:()=>r(e=>!e),disabled:t,"aria-haspopup":`menu`,"aria-expanded":n,"aria-label":`Session actions`,title:`Session actions`,children:(0,D.jsx)(f,{size:12})}),n&&(0,D.jsx)(P,{anchorRef:o,onClose:s,className:`conv-actions-menu`,role:`menu`,children:e.map(e=>e.panel?(0,D.jsxs)(`div`,{className:`conv-actions-menu-disclosure`,children:[(0,D.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-haspopup":`dialog`,"aria-expanded":i===e.key,disabled:t,onClick:()=>a(t=>t===e.key?null:e.key),children:[e.icon,(0,D.jsx)(`span`,{children:e.menuLabel})]}),i===e.key&&(0,D.jsx)(`div`,{className:`conv-actions-menu-panel`,children:e.panel()})]},e.key):(0,D.jsxs)(`button`,{type:`button`,role:`menuitem`,className:e.danger?`conv-action-danger`:void 0,"aria-busy":e.busy,disabled:t,onClick:t=>{e.onClick?.(t),s()},children:[e.icon,(0,D.jsx)(`span`,{children:e.menuLabel})]},e.key))})]})}var F=`claude-opus-4-8[1m]`,I=`claude-sonnet-5`,L=`claude-haiku-4-5`,R={[F]:`Opus 4.8 (1M context)`,[I]:`Sonnet 5`,[L]:`Haiku 4.5`};function ke(e){return R[e]??e}var Ae=[F,I,L];function z(e){return e.replace(/\[1m\]$/,``)}function je(e){return Ae.find(t=>z(t)===z(e))??e}var B=[`default`,`acceptEdits`,`plan`,`auto`,`bypassPermissions`],V=[`low`,`medium`,`high`,`xhigh`];[...B],[...V],[...V];var Me=[F,I,L],Ne={default:`Ask permissions`,acceptEdits:`Accept edits`,plan:`Plan mode`,auto:`Auto mode`,bypassPermissions:`Bypass permissions`},Pe=B.map(e=>({value:e,label:Ne[e]??e})),Fe={low:`Low`,medium:`Medium`,high:`High`,xhigh:`Highest`},Ie=V.map(e=>({value:e,label:Fe[e]??e}));function H(e){if(e){let t=Me.find(t=>z(t)===z(e));if(t)return t}return F}function Le({row:e,adminFetch:t,onError:r}){let[i,a]=(0,E.useState)(()=>H(e.model)),[o,s]=(0,E.useState)(``),[c,l]=(0,E.useState)(``),[u,d]=(0,E.useState)(!1),f=(0,E.useRef)(!1);(0,E.useEffect)(()=>{a(H(e.model))},[e.model]);let p=async()=>{if(!f.current){f.current=!0,d(!0);try{let n=await t(`/api/admin/session-reseat`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({fromSessionId:e.sessionId,model:i,...o?{permissionMode:o}:{},...c?{effort:c}:{}})});if(!n.ok){r(`Could not reset ${e.title} (status ${n.status})`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} status=${n.status}`),f.current=!1,d(!1);return}let a=await n.json().catch(()=>({}));a.target?window.location.assign(a.target):(r(`Reset of ${e.title} returned no target`),f.current=!1,d(!1))}catch(t){r(`Could not reset ${e.title} (network error)`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} error=${t instanceof Error?t.message:String(t)}`),f.current=!1,d(!1)}}};return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`label`,{className:`reseat-field`,children:[(0,D.jsx)(`span`,{children:`Model`}),(0,D.jsx)(`select`,{"data-kind":`model`,value:i,disabled:u,onChange:e=>a(e.target.value),children:Me.map(e=>(0,D.jsx)(`option`,{value:e,children:ke(e)},e))})]}),(0,D.jsxs)(`label`,{className:`reseat-field`,children:[(0,D.jsx)(`span`,{children:`Mode`}),(0,D.jsxs)(`select`,{"data-kind":`mode`,value:o,disabled:u,onChange:e=>s(e.target.value),children:[(0,D.jsx)(`option`,{value:``,children:`Keep current`}),Pe.map(e=>(0,D.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,D.jsxs)(`label`,{className:`reseat-field`,children:[(0,D.jsx)(`span`,{children:`Effort`}),(0,D.jsxs)(`select`,{"data-kind":`effort`,value:c,disabled:u,onChange:e=>l(e.target.value),children:[(0,D.jsx)(`option`,{value:``,children:`Keep current`}),Ie.map(e=>(0,D.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,D.jsx)(`button`,{type:`button`,className:`reseat-apply`,disabled:u,"aria-busy":u,onClick:()=>void p(),children:u?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(n,{size:12,className:`spin`,"aria-hidden":`true`}),`Resetting…`]}):`Reset`})]})}function Re(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 U(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function ze({target:e,anchorEl:t,onConfirm:n,onCancel:r}){let i=(0,E.useRef)(null);return i.current=t,e?(0,D.jsxs)(P,{anchorRef:i,onClose:r,className:`conv-delete-confirm`,role:`alertdialog`,ariaLabel:`Confirm delete session`,children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsx)(`span`,{children:`Delete this conversation?`}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[(0,D.jsxs)(`div`,{className:`conv-delete-target`,children:[(0,D.jsx)(`span`,{className:`conv-delete-label`,title:e.title,children:e.title||`Untitled session`}),(0,D.jsx)(`code`,{className:`conv-delete-id`,title:e.sessionId,children:e.sessionId.slice(0,8)})]}),(0,D.jsx)(`div`,{style:{marginTop:`8px`},children:`This permanently removes the transcript. It is not moved to Archive and cannot be recovered.`}),e.live&&(0,D.jsx)(`div`,{style:{marginTop:`8px`},children:`This session is running; deleting stops it first.`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,D.jsx)(A,{variant:`danger`,size:`sm`,style:{flex:1},onClick:n,children:`Delete`}),(0,D.jsx)(A,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:r,children:`Cancel`})]})]}):null}function Be({open:e,count:t,liveCount:n,onConfirm:r,onCancel:i}){if(!e)return null;let a=t===1?``:`s`;return(0,D.jsx)(`div`,{className:`claude-info-overlay`,onClick:i,children:(0,D.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Confirm delete sessions`,children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsxs)(`span`,{children:[`Delete `,t,` conversation`,a,`?`]}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:i,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[`This permanently removes `,t,` transcript`,a,`. `,t===1?`It is`:`They are`,` not moved to Archive and cannot be recovered.`,n>0&&(0,D.jsxs)(`div`,{style:{marginTop:`8px`},children:[n,` `,n===1?`is`:`are`,` running and will be stopped first.`]})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,D.jsxs)(A,{variant:`danger`,size:`sm`,style:{flex:1},onClick:r,children:[`Delete `,t]}),(0,D.jsx)(A,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:i,children:`Cancel`})]})]})})}var Ve=`auth-refresh-failed`;function He({error:e,onClose:t}){if(!e)return null;let n=e.reason===Ve,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,D.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,D.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsx)(`span`,{children:r}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,D.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function Ue(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:s}=e,[c,l]=(0,E.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,_=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,D.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,D.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,D.jsx)(`span`,{children:`Claude Code`}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(g||m||h>0)&&(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[g&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,D.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:g})]}),m&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(m.utilization*100),`%`]})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:_(m.resetsAt)})]}),m.isUsingOverage&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),h>0&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,h<.01?h.toFixed(4):h.toFixed(2)]})]})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:f>0?`${f}%`:`—`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:p>0?U(p):`—`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:Re(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.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 w(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}function We({open:e,onConnect:t,onClose:n}){return e?(0,D.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,D.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Claude is not connected`,children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsx)(`span`,{children:`Claude isn’t connected`}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`,display:`flex`,flexDirection:`column`,gap:`10px`},children:[(0,D.jsx)(`span`,{children:`This needs Claude, which is currently disconnected. Connect to continue — the rest of the dashboard stays available either way.`}),(0,D.jsxs)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`},children:[(0,D.jsx)(A,{variant:`primary`,size:`sm`,onClick:t,children:`Connect Claude`}),(0,D.jsx)(`button`,{type:`button`,className:`claude-info-close`,style:{fontSize:`11px`},onClick:n,children:`Not now`})]})]})]})}):null}function Ge(e){let t=Math.round(e/6e4),n=Math.floor(t/60),r=t%60;return`${n}h ${String(r).padStart(2,`0`)}m`}function Ke(e){return e.activeMs.thinking+e.activeMs.messaging+e.activeMs.toolUse}function W(e){return e.toLocaleString(`en-GB`)}function qe(e){return`£${e.toFixed(2)}`}function G(e){let t=[`Day`,`Active`,`Output tokens`,`Input tokens`,`Cache write`,`Cache read`,`Opus 4.8 (GBP)`,`Sonnet 4.6 (GBP)`],n=(e,t)=>[e,Ge(Ke(t)),String(t.tokens.output),String(t.tokens.input),String(t.tokens.cacheWrite),String(t.tokens.cacheRead),t.costGBP.opus.toFixed(2),t.costGBP.sonnet.toFixed(2)];return[t,...e.days.map(e=>n(e.date,e)),n(`TOTAL (${e.days.length} d)`,e.totals)].map(e=>e.join(`,`)).join(`
|
|
2
|
-
`)}function Je({label:e,d:t,bold:n}){let r=n?`th`:`td`;return(0,D.jsxs)(`tr`,{className:n?`usage-total-row`:void 0,children:[(0,D.jsx)(r,{className:`usage-day`,children:e}),(0,D.jsx)(r,{children:Ge(Ke(t))}),(0,D.jsx)(r,{children:W(t.tokens.output)}),(0,D.jsx)(r,{children:W(t.tokens.input)}),(0,D.jsx)(r,{children:W(t.tokens.cacheWrite)}),(0,D.jsx)(r,{children:W(t.tokens.cacheRead)}),(0,D.jsx)(r,{children:qe(t.costGBP.opus)}),(0,D.jsx)(r,{children:qe(t.costGBP.sonnet)})]})}function Ye({show:e,onClose:t,anchorEl:n,sessionId:i,summary:a,loading:o,error:s}){let c=(0,E.useRef)(null);if(c.current=n,!e)return null;let l=!!a&&a.days.length>0;return(0,D.jsxs)(P,{anchorRef:c,onClose:t,className:`usage-popover`,role:`dialog`,ariaLabel:`Session usage and cost`,anchorId:i??void 0,children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsxs)(`span`,{children:[`Usage & cost`,i?` · ${i.slice(0,8)}`:``]}),l&&(0,D.jsx)(`button`,{className:`usage-download`,onClick:()=>{if(!a)return;let e=new Blob([G(a)],{type:`text/csv;charset=utf-8`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`usage-${i?i.slice(0,8):`session`}.csv`,document.body.appendChild(n),n.click(),n.remove(),URL.revokeObjectURL(t)},"aria-label":`Download as CSV`,title:`Download as CSV`,children:(0,D.jsx)(r,{size:14})}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:(0,D.jsx)(C,{size:14})})]}),(0,D.jsxs)(`div`,{className:`claude-info-section usage-body`,children:[o&&(0,D.jsx)(`div`,{className:`usage-note`,children:`Computing usage…`}),!o&&s&&(0,D.jsx)(`div`,{className:`usage-note usage-error`,children:s}),!o&&!s&&a&&a.days.length===0&&(0,D.jsx)(`div`,{className:`usage-note`,children:`No usage recorded for this session yet.`}),!o&&!s&&a&&a.days.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`usage-table-scroll`,children:(0,D.jsxs)(`table`,{className:`usage-table`,children:[(0,D.jsx)(`thead`,{children:(0,D.jsxs)(`tr`,{children:[(0,D.jsx)(`th`,{className:`usage-day`,children:`Day`}),(0,D.jsx)(`th`,{children:`Active`}),(0,D.jsx)(`th`,{children:`Output tok`}),(0,D.jsx)(`th`,{children:`Input tok`}),(0,D.jsx)(`th`,{children:`Cache write`}),(0,D.jsx)(`th`,{children:`Cache read`}),(0,D.jsx)(`th`,{children:`Opus 4.8 (£)`}),(0,D.jsx)(`th`,{children:`Sonnet 4.6 (£)`})]})}),(0,D.jsxs)(`tbody`,{children:[a.days.map(e=>(0,D.jsx)(Je,{label:e.date,d:e},e.date)),(0,D.jsx)(Je,{label:`TOTAL (${a.days.length} d)`,d:a.totals,bold:!0})]})]})}),(0,D.jsxs)(`div`,{className:`usage-note usage-caveats`,children:[`Prices dated `,a.pricing.opusPriceDate,` · £/$ `,a.pricing.usdPerGbp,` · Sonnet tokenizer factor `,a.pricing.tokenizerFactor,`. Idle human-wait dominates the calendar span; cache-read tokens dominate cost; Sonnet is a tokenizer-adjusted estimate.`]})]})]})]})}var K=`https://claude.ai/code`,Xe=200,Ze=[500,1e3,1500,2e3,2500,3e3,3e3];function Qe(e,t,n){if(e&&n.target)return{kind:`navigate`,url:n.target,sameOrigin:!0};let r=n.slug??n.bridgeSessionId??null;if(e&&r)return{kind:`navigate`,url:`${K}/${r}`,sameOrigin:!1};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function $e(e){if(!e)return``;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function et(e){let{businessName:n,cacheKey:r,onConnectClaude:a,role:s,userName:c,userAvatar:f,onSelectProjects:m,onSelectTasks:C,onCloseMobileDrawer:w,collapsed:ne,onSelectData:re,initialDataSurface:se=!1,onLogout:O,onDisconnect:k,disconnecting:A,claudeConnected:pe=!0,subAccounts:he,activeAccountId:ge,switchingAccount:_e,onSwitchAccount:ve,refreshAccounts:ye,onOpenConversations:be}=e,M=te(r),xe=(0,E.useCallback)(e=>({key:`reseat`,label:`Reset session ${e.title} (model, mode, effort)`,menuLabel:`Reset`,title:`Reset — move this session onto a chosen model, mode, and effort`,icon:(0,D.jsx)(me,{size:12}),panel:()=>(0,D.jsx)(Le,{row:e,adminFetch:M,onError:e=>I({message:e,failed:!0})})}),[M]),N=l.productName,Se=n||N,Ce=typeof c==`string`?c:c===null?`name unavailable`:Se,we=(Ce.trim().charAt(0)||`?`).toUpperCase(),[Te,Ee]=(0,E.useState)(se?`data`:`sessions`),[De,P]=(0,E.useState)(!1),[F,I]=(0,E.useState)(null),[L,R]=(0,E.useState)(null),[ke,Ae]=(0,E.useState)(!1),[z,je]=(0,E.useState)([]),[B]=(0,E.useState)(()=>typeof window>`u`?null:new URLSearchParams(window.location.search).get(`session`)),[V,Me]=(0,E.useState)(!1),[Ne,Pe]=(0,E.useState)(null),[Fe,Ie]=(0,E.useState)(!1),[H,Re]=(0,E.useState)(!1),[U,Ve]=(0,E.useState)(!1),[Ue,Ge]=(0,E.useState)(null),[Ke,W]=(0,E.useState)(new Set),qe=(0,E.useRef)(new Map),[G,Je]=(0,E.useState)(!1),[K,et]=(0,E.useState)(new Set),[tt,q]=(0,E.useState)(!1),[J,it]=(0,E.useState)(null),[at,ot]=(0,E.useState)(new Set),[st,ct]=(0,E.useState)(new Set),[lt,ut]=(0,E.useState)(new Set),[Y,X]=(0,E.useState)(null),[dt,Z]=(0,E.useState)(``),[ft,pt]=(0,E.useState)(!1),[mt,ht]=(0,E.useState)(null),[gt,_t]=(0,E.useState)(null),[vt,yt]=(0,E.useState)(!1),[bt,xt]=(0,E.useState)(null),[St,Ct]=(0,E.useState)(!1),wt=(0,E.useRef)(0);(0,E.useEffect)(()=>{if(!F)return;let e=setTimeout(()=>I(null),2500);return()=>clearTimeout(e)},[F]);let Tt=B!=null&&z.some(e=>e.sessionId===B);(0,E.useEffect)(()=>{B==null||!V||console.info(`[sidebar-sessions] op=select-highlight session=${B.slice(0,8)} matched=${Tt}`)},[B,Tt,V]);let Q=(0,E.useCallback)(async()=>{if(!r)return null;let e=++wt.current;Ie(!0),Pe(null);try{let t=await M(`/api/admin/sidebar-sessions`);if(!t.ok)throw Error(`status ${t.status}`);let n=await t.json(),r=n.sessions??[];return e===wt.current?(je(r),Ge(n.accountId??null),Me(!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===wt.current&&Pe(`Failed to load sessions: ${n}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${n}`),null}finally{e===wt.current&&Ie(!1)}},[r,M]);(0,E.useEffect)(()=>{!r||V||Q()},[r,V,Q]),(0,E.useEffect)(()=>{if(!r)return;let e=null;function t(){console.info(`[admin-ui] sidebar-refresh surface=sessions trigger=poll`),Q()}function n(){e===null&&(e=setInterval(t,nt))}function i(){e!==null&&(clearInterval(e),e=null)}function a(){document.hidden?i():(t(),n())}return document.hidden||n(),document.addEventListener(`visibilitychange`,a),()=>{i(),document.removeEventListener(`visibilitychange`,a)}},[r,Q]);let Et=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions trigger=manual`),Q()},Dt=()=>{Ee(`data`),console.info(`[admin-ui] sidebar-nav surface=data collapsed=${ne}`),re(),w()},$=typeof window<`u`&&window.location?.pathname||`/`,Ot=Te===`data`,kt=e=>{w(),window.location.href=e},At=[{key:`dashboard`,label:`Dashboard`,icon:(0,D.jsx)(ae,{size:17,strokeWidth:1.75}),active:$===`/`&&!Ot,onClick:()=>kt(`/`)},{key:`chat`,label:`Chat`,icon:(0,D.jsx)(oe,{size:17,strokeWidth:1.75}),active:$.startsWith(`/chat`),onClick:()=>kt(`/chat`)},{key:`tasks`,label:`Tasks`,icon:(0,D.jsx)(j,{size:17,strokeWidth:1.75}),active:$.startsWith(`/tasks`),onClick:()=>{C(),w()}},{key:`calendar`,label:`Calendar`,icon:(0,D.jsx)(t,{size:17,strokeWidth:1.75}),active:$.startsWith(`/calendar`),onClick:()=>kt(`/calendar`)},{key:`data`,label:`Data`,icon:(0,D.jsx)(u,{size:17,strokeWidth:1.75}),active:Ot,onClick:Dt},{key:`container`,label:o().term,icon:(0,D.jsx)(h,{size:17,strokeWidth:1.75}),active:$.startsWith(`/graph`),onClick:()=>{m(),w()}},{key:`activity`,label:`Activity`,icon:(0,D.jsx)(x,{size:17,strokeWidth:1.75}),active:$.startsWith(`/activity`),onClick:()=>kt(`/activity`)},{key:`browser`,label:`Browser`,icon:(0,D.jsx)(p,{size:17,strokeWidth:1.75}),active:$.startsWith(`/browser`),onClick:()=>kt(`/browser`)}],jt=(0,E.useCallback)(async e=>{if(at.has(e.sessionId))return;ot(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await M(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,name:e.title||e.sessionId,...e.accountId?{targetAccountId:e.accountId}:{}})}),r=await n.json().catch(()=>({})),i=Qe(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`?(w(),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}`),R(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}`),R({sessionId:e.sessionId,reason:r})}finally{ot(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[M,w,at]),Mt=(0,E.useCallback)(async e=>{let t=e.slice(0,8);for(let n=1;n<=Ze.length;n++){await new Promise(e=>setTimeout(e,Ze[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]),Nt=(0,E.useCallback)(async()=>{if(!St){Ct(!0);try{let e=await M(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}),t=await e.json().catch(()=>({})),n=Qe(e.ok,e.status,t);console.info(`[admin-ui] sidebar-new-session-spawned status=${e.status} outcome=${n.kind} slug=${t.slug??t.bridgeSessionId??`none`}`),n.kind===`navigate`?n.sameOrigin?window.location.assign(n.url):(window.open(n.url,`_blank`),t.sessionId?Mt(t.sessionId):console.error(`[admin-ui] sidebar-new-session-converge-skipped reason=no-session-id`)):e.status===503||n.reason===`claude-auth-dead`?(console.info(`[admin-ui] op=llm-action-blocked action=spawn reason=claude-disconnected`),Ae(!0)):(console.error(`[admin-ui] sidebar-new-session-failed status=${e.status} reason=${n.reason}`),R(n))}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-new-session-failed error=${t}`),R({sessionId:null,reason:t})}finally{Ct(!1)}}},[M,St,Mt]),Pt=(0,E.useCallback)((e,t)=>{e.stopPropagation(),it(t)},[]),Ft=(0,E.useCallback)(async(e,t)=>{e.stopPropagation(),ht(t),_t(null),xt(null),yt(!0);try{let e=await M(`/api/admin/session-usage?sessionId=${encodeURIComponent(t.sessionId)}`),n=await e.json().catch(()=>({}));e.ok?_t(n):xt(n.error??`status ${e.status}`)}catch(e){xt(e instanceof Error?e.message:String(e))}finally{yt(!1)}},[M]),It=(0,E.useCallback)(async(e,t={})=>{let n=t.refresh??!0;if(Ke.has(e.sessionId))return!1;W(t=>{let n=new Set(t);return n.add(e.sessionId),n});try{let t=await M(`/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(()=>({}));return console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${e.sessionId} status=${t.status} error=${n.error??`unknown`}`),I({message:`Delete failed: ${n.error??`status ${t.status}`}`,failed:!0}),!1}let r=await t.json();return console.info(`[admin-ui] sidebar-session-delete sessionId=${e.sessionId} live=${e.live} confirmed=true pidKilled=${r.pidKilled??`?`} deleted=${r.deleted??`?`}`),je(t=>t.filter(t=>t.sessionId!==e.sessionId)),n&&Q(),!0}catch(t){let n=t instanceof Error?t.message:String(t);return console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${e.sessionId} error=${n}`),I({message:`Delete failed: ${n}`,failed:!0}),!1}finally{W(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[M,Ke,Q]),Lt=(0,E.useCallback)(e=>{et(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Rt=(0,E.useCallback)(()=>{Je(!1),et(new Set)},[]),zt=(0,E.useCallback)(async()=>{let e=[...K].map(e=>z.find(t=>t.sessionId===e)).filter(e=>!!e),t=e.filter(e=>e.live).length;console.info(`[admin-ui] sidebar-bulk-delete op=start count=${e.length} live=${t}`);let n=(await Promise.all(e.map(e=>It(e,{refresh:!1})))).filter(Boolean).length;console.info(`[admin-ui] sidebar-bulk-delete op=done requested=${e.length} ok=${n} failed=${e.length-n}`),Q(),Rt()},[K,z,It,Q,Rt]),Bt=(0,E.useCallback)(async(e,t)=>{if(e.stopPropagation(),!st.has(t.sessionId)){ct(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await M(`/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`}`),I({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}`),I({message:`Stop failed: ${n}`,failed:!0})}finally{ct(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[M,st,Q]),Vt=(0,E.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!lt.has(t.sessionId)){ut(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await M(`/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`}`),I({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}`),I({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{ut(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[M,lt,Q]),Ht=(0,E.useCallback)(async e=>{let t=dt.trim();if(!t){I({message:`Title can’t be empty`,failed:!0});return}if(t.length>Xe){I({message:`Title too long (max ${Xe})`,failed:!0});return}pt(!0);try{let n=await M(`/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}`),I({message:`Rename failed: ${r}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=ok`),X(null),Z(``),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}`),I({message:`Rename failed: ${n}`,failed:!0})}finally{pt(!1)}},[M,dt,Q]);return(0,D.jsxs)(`aside`,{className:`side`,children:[(0,D.jsxs)(`div`,{className:`side-brand`,children:[(0,D.jsx)(`img`,{className:`side-brand-icon`,src:d,alt:``,"aria-hidden":`true`}),(0,D.jsxs)(`span`,{className:`side-brand-lockup`,children:[(0,D.jsx)(`span`,{className:`side-brand-business`,children:Se}),(0,D.jsx)(`span`,{className:`side-brand-product`,children:l.productName})]})]}),(0,D.jsx)(`nav`,{className:`side-nav`,children:At.map(e=>(0,D.jsxs)(`button`,{type:`button`,className:`admin-row nav-row${e.active?` active`:``}`,"aria-current":e.active?`page`:void 0,onClick:e.onClick,children:[e.icon,(0,D.jsx)(`span`,{className:`label`,children:e.label}),(0,D.jsx)(`span`,{className:`kbd`})]},e.key))}),(()=>{let e=z.filter(e=>H?!0:!e.isSubagent).filter(e=>U?!0:!e.archived),t=z.some(e=>e.isSubagent),n=z.some(e=>e.archived);return(0,D.jsx)(`div`,{className:`side-sessions`,children:(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:`Sessions`}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-select${G?` active`:``}`,"aria-pressed":G,title:G?`Exit select mode`:`Select multiple sessions to delete`,onClick:()=>{Je(e=>!e),et(new Set),X(null),Z(``)},children:`Select`}),(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:Et,disabled:Fe,children:(0,D.jsx)(ie,{size:12,className:Fe?`spinning`:void 0})}),(0,D.jsx)(`span`,{children:Fe?`…`:String(e.length)}),(0,D.jsxs)(`button`,{type:`button`,className:`admin-btn-cta side-sessions-new`,onClick:Nt,disabled:St,"aria-busy":St,children:[(0,D.jsx)(T,{size:13}),(0,D.jsx)(`span`,{children:St?`Spawning…`:`New session`})]})]})]}),G&&(0,D.jsxs)(`div`,{className:`session-select-bar`,children:[(0,D.jsxs)(`span`,{className:`session-select-count`,children:[K.size,` selected`]}),(0,D.jsxs)(`button`,{type:`button`,className:`session-select-delete`,disabled:K.size===0,onClick:()=>q(!0),children:[`Delete `,K.size]}),(0,D.jsx)(`button`,{type:`button`,className:`session-select-cancel`,onClick:Rt,children:`Cancel`})]}),Ue&&(0,D.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,D.jsx)(`code`,{children:Ue})}),(t||n)&&(0,D.jsxs)(`div`,{className:`artefact-filter-chips`,children:[t&&(0,D.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${H?` active`:``}`,"aria-pressed":H,onClick:()=>Re(e=>!e),title:H?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),n&&(0,D.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${U?` active`:``}`,"aria-pressed":U,onClick:()=>Ve(e=>!e),title:U?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),Ne&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:Ne}),V&&!Ne&&e.length===0&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=$e(e.startedAt),n=at.has(e.sessionId),r=Ke.has(e.sessionId),a=st.has(e.sessionId),o=lt.has(e.sessionId),s=n||r||a||o,c=()=>{window.location.assign(`/chat?session=${e.sessionId}`)},l=[{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,D.jsx)(i,{size:12}),busy:n,onClick:()=>{jt(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,D.jsx)(fe,{size:12}),onClick:()=>{c()}},{key:`usage`,label:`Usage and cost for session ${e.title}`,menuLabel:`Usage & cost`,title:`Per-day active time, tokens, and estimated GBP cost`,icon:(0,D.jsx)(de,{size:12}),onClick:t=>{Ft(t,e)}},...e.live?[{key:`stop`,label:`Stop session ${e.title}`,menuLabel:`Stop`,title:`Stop session process (keeps the conversation, can resume later)`,icon:(0,D.jsx)(ee,{size:12}),busy:a,onClick:t=>{Bt(t,e)}}]:[],e.archived?{key:`unarchive`,label:`Unarchive session ${e.title}`,menuLabel:`Unarchive`,title:`Unarchive (move back to the active list)`,icon:(0,D.jsx)(ce,{size:12}),busy:o,onClick:t=>{Vt(t,e,`unarchive`)}}:{key:`archive`,label:`Archive session ${e.title}`,menuLabel:`Archive`,title:`Archive (hide from the list, keeps the conversation resumable)`,icon:(0,D.jsx)(le,{size:12}),busy:o,onClick:t=>{Vt(t,e,`archive`)}},{key:`rename`,label:`Rename session ${e.title}`,menuLabel:`Rename`,title:`Rename this session`,icon:(0,D.jsx)(_,{size:12}),busy:ft&&Y===e.sessionId,onClick:t=>{t.stopPropagation(),X(e.sessionId),Z(e.personName??e.title)}},{key:`delete`,label:`Delete session ${e.title}`,menuLabel:`Delete`,title:`Delete session (stops the process, removes the conversation)`,icon:(0,D.jsx)(y,{size:12}),danger:!0,busy:r,onClick:t=>{Pt(t,e)}},xe({sessionId:e.sessionId,model:e.model??null,title:e.personName??e.title})],u=e.channel===`whatsapp`?` conv-channel-whatsapp`:e.channel===`telegram`?` conv-channel-telegram`:``,d=e.channel===`whatsapp`||e.channel===`telegram`||e.channel===`webchat`,f=g.includes(e.channel??``)&&e.senderId&&e.titleSource===`prefix`?b({operatorName:e.personName??null,whatsappName:e.whatsappName??null,senderId:e.senderId,title:e.title}):e.personName??e.title;return(0,D.jsxs)(`div`,{ref:t=>{let n=qe.current;t?n.set(e.sessionId,t):n.delete(e.sessionId)},className:`conv conv-with-actions${u}${e.sessionId===B?` active`:``}`,children:[(0,D.jsxs)(`div`,{className:`conv-main-static conv-main-clickable`,role:`button`,tabIndex:0,"aria-label":`Open ${f} in webchat`,onClick:()=>{if(Y!==e.sessionId){if(G){Lt(e.sessionId);return}c()}},onKeyDown:t=>{Y!==e.sessionId&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),G?Lt(e.sessionId):c())},children:[G&&(0,D.jsx)(`input`,{type:`checkbox`,className:`conv-select-check`,checked:K.has(e.sessionId),"aria-label":`Select ${f}`,onChange:()=>Lt(e.sessionId),onClick:e=>e.stopPropagation()}),(0,D.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"aria-label":e.live?`live session`:`ended session`}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsxs)(`span`,{className:`conv-name-line`,children:[d&&(0,D.jsx)(S,{channel:e.channel,size:13}),Y===e.sessionId?(0,D.jsx)(`input`,{className:`conv-name conv-name-edit`,autoFocus:!0,onFocus:e=>e.currentTarget.select(),value:dt,disabled:ft,"aria-label":`New title for session ${e.title}`,onChange:e=>Z(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),Ht(e)):t.key===`Escape`&&(t.preventDefault(),X(null),Z(``))},onBlur:()=>{Y===e.sessionId&&!ft&&(X(null),Z(``))}}):(0,D.jsx)(`span`,{className:`conv-name`,title:f,children:f})]}),(0,D.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,D.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,D.jsxs)(`span`,{children:[` · `,t]})]})]})]}),!G&&(0,D.jsx)(Oe,{actions:l,disabled:s})]},e.sessionId)})]})})})(),(0,D.jsxs)(`div`,{className:`side-foot`,children:[(0,D.jsx)(`div`,{className:`avatar`,children:f?(0,D.jsx)(`img`,{src:f,alt:Ce}):we}),(0,D.jsxs)(`div`,{className:`who`,children:[(0,D.jsx)(`span`,{className:`name`,children:Ce}),(0,D.jsx)(rt,{})]}),(0,D.jsx)(`button`,{type:`button`,className:`side-foot-kebab`,"aria-label":`Account menu`,"aria-haspopup":`menu`,"aria-expanded":De,onClick:()=>P(e=>!e),children:(0,D.jsx)(ue,{size:16})}),De&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`side-foot-menu-scrim`,"aria-hidden":`true`,onClick:()=>P(!1)}),(0,D.jsx)(`div`,{className:`side-foot-menu`,role:`menu`,children:(0,D.jsx)(v,{variant:`admin`,onCloseMenu:()=>P(!1),onLogout:O??(()=>{}),onDisconnect:k,disconnecting:A,claudeConnected:pe,onConnectClaude:a,cacheKey:r,subAccounts:he,activeAccountId:ge,switchingAccount:_e,onSwitchAccount:ve,refreshAccounts:ye,onOpenConversations:be})})]})]}),F&&(0,D.jsx)(`div`,{className:`copy-toast${F.failed?` copy-toast-failed`:``}`,role:`status`,children:F.message}),(0,D.jsx)(He,{error:L,onClose:()=>R(null)}),(0,D.jsx)(We,{open:ke,onConnect:()=>{Ae(!1),a?.()},onClose:()=>Ae(!1)}),(0,D.jsx)(ze,{target:J,anchorEl:J?qe.current.get(J.sessionId)??null:null,onCancel:()=>it(null),onConfirm:()=>{let e=J;it(null),e&&It(e)}},J?.sessionId??`none`),(0,D.jsx)(Be,{open:tt,count:K.size,liveCount:z.filter(e=>K.has(e.sessionId)&&e.live).length,onConfirm:()=>{q(!1),zt()},onCancel:()=>q(!1)}),(0,D.jsx)(Ye,{show:mt!==null,onClose:()=>{ht(null),_t(null),xt(null)},anchorEl:mt?qe.current.get(mt.sessionId)??null:null,sessionId:mt?.sessionId??null,summary:gt,loading:vt,error:bt},mt?.sessionId??`none`)]})}var tt=5e3,nt=3e4;function rt(){let[e,t]=(0,E.useState)(null);if((0,E.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()},tt))}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=[`system-stats`];return c&&d.push(`system-stats--warn`),l&&d.push(`system-stats--crit`),(0,D.jsxs)(`span`,{className:d.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,D.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),` · `,(0,D.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]})]})}var q=`admin-sidebar-collapsed`,J=`admin-sidebar-drawer-open`,it=1080;function at(){if(typeof window>`u`)return!1;let e=null;try{e=window.sessionStorage.getItem(q)}catch{e=null}return e===null?typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 721px) and (max-width: ${it}px)`).matches:!1:e===`1`}function ot(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(q,`1`):window.sessionStorage.removeItem(q)}catch{}}function st(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(J)===`1`}catch{return!1}}function ct(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(J,`1`):window.sessionStorage.removeItem(J)}catch{}}function lt(e){let[t,n]=(0,E.useState)(()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(e).matches);return(0,E.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let t=window.matchMedia(e),r=()=>n(t.matches);return r(),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}var ut=720;function Y(e,t){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?wa=${encodeURIComponent(t.remoteJid??``)}&acct=${encodeURIComponent(t.accountId??``)}`}}function X(e){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?data=1`}}function dt(e,t){if(e!==`/`)return null;let n=new URLSearchParams(t),r=n.get(`wa`),i=n.get(`acct`);return!r||!i?null:{sessionId:``,projectDir:``,title:``,senderId:null,startedAt:``,channel:`whatsapp`,role:`public`,operatorName:null,whatsappName:null,lastMessageAt:null,modelGated:!1,model:null,source:`store`,accountId:i,remoteJid:r}}function Z(e,t){return e===`/`?new URLSearchParams(t).has(`data`):!1}function ft(e,t){return t===`operator`&&e===`chat`||e===`dashboard`?`/`:e===`data`?`/data`:e===`graph`?`/graph`:e===`calendar`?`/calendar`:e===`chat`?`/chat`:e===`activity`?`/activity`:`/browser`}function pt(e){let{cacheKey:t,businessName:n,variant:r=`admin`,onLogout:i,onDisconnect:a,disconnecting:s,claudeConnected:c,onConnectClaude:l,userName:u,userAvatar:d,role:f,onOpenConversations:p,children:m,footer:h}=e,{subAccounts:g,activeAccountId:_,switching:v,switchAccount:ee,refreshAccounts:y}=ne(t),[b,x]=(0,E.useState)(!0);(0,E.useEffect)(()=>{if(c!==void 0||r!==`admin`)return;let e=!1,t=async()=>{try{let t=await fetch(`/api/health`);if(!t.ok)return;let n=await t.json();e||x(n.auth_status!==`dead`&&n.auth_status!==`missing`)}catch{}};t();let n=setInterval(t,6e4);return()=>{e=!0,clearInterval(n)}},[c,r]);let S=c??b,C=l??(()=>{window.location.assign(`/?connect=claude`)}),[w,te]=(0,E.useState)(()=>at()),[ie,ae]=(0,E.useState)(!1),oe=(0,E.useRef)(!0);(0,E.useEffect)(()=>{if(oe.current){oe.current=!1;return}ae(!0);let e=setTimeout(()=>ae(!1),260);return()=>clearTimeout(e)},[w]);let[T,se]=(0,E.useState)(()=>st()),O=lt(`(max-width: ${ut}px)`),[k,A]=(0,E.useState)(()=>typeof window>`u`||Z(window.location.pathname,window.location.search)?null:dt(window.location.pathname,window.location.search)),[ce,le]=(0,E.useState)(()=>typeof window>`u`?!1:Z(window.location.pathname,window.location.search)),[ue]=(0,E.useState)(()=>ce),de=(0,E.useCallback)(e=>{ot(e),te(e)},[]),j=(0,E.useCallback)(e=>{ct(e),se(e)},[]);(0,E.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=${w} drawer=${T}`)},[]),(0,E.useEffect)(()=>{typeof window>`u`||!k||(console.info(`[admin-ui] wa-hydrate route=/ remoteJid=${k.remoteJid??``}`),window.history.replaceState(null,``,`/`))},[]),(0,E.useEffect)(()=>{typeof window>`u`||!ce||(console.info(`[admin-ui] data-hydrate route=/`),window.history.replaceState(null,``,`/`))},[]);let fe=(0,E.useCallback)(e=>{if(le(!1),e===null){A(null);return}let t=typeof window<`u`?window.location.pathname:`/`,n=Y(t,e);console.info(`[admin-ui] wa-open route=${t} via=${n.via} sessionId=${e.sessionId.slice(0,8)}`),n.via===`in-place`?A(e):window.location.href=n.href},[]),pe=(0,E.useCallback)(()=>{let e=typeof window<`u`?window.location.pathname:`/`,t=X(e);if(console.info(`[admin-ui] data-open route=${e} via=${t.via}`),t.via===`navigate`){window.location.href=t.href;return}A(null),le(!0)},[]),me=O?T:!w,he=(0,E.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${ut}px)`).matches){let e=T;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),j(!e)}else{let e=w;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),de(!e)}},[w,T,de,j]),ge=(0,E.useCallback)(e=>{let t=ft(e,r);console.info(`[admin-ui] header-menu-nav target=${e} dest=${t}`),window.location.href=t},[r]),ve={collapsed:w,mobileDrawerOpen:T,sidebarOpen:me,onToggleSidebar:he,setMobileDrawerOpen:j,selectedWhatsapp:k,onClearWhatsapp:()=>A(null),onSelectWhatsappConversation:fe,dataOpen:ce};return r===`operator`?(0,D.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,D.jsx)(re,{businessName:n,variant:r,onNavigate:ge,onOpenConversations:p,onToggleSidebar:he,sidebarOpen:me,onLogout:i,onDisconnect:a,disconnecting:s,cacheKey:t,subAccounts:g,activeAccountId:_,switchingAccount:v,onSwitchAccount:ee,refreshAccounts:y}),(0,D.jsx)(`div`,{className:`platform platform-operator`,children:typeof m==`function`?m(ve):m}),h]}):(0,D.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,D.jsxs)(`div`,{className:`platform${T?` menu-open`:``}${!O&&w?` sidebar-collapsed`:``}${ie?` sidebar-animating`:``}`,"data-artefact":`closed`,children:[(0,D.jsx)(et,{businessName:n,cacheKey:t,onConnectClaude:C,role:f??null,userName:u,userAvatar:d??null,onSelectProjects:()=>{window.location.href=`/graph?label=${o().label}`},onSelectTasks:()=>{window.location.href=`/tasks`},onCloseMobileDrawer:()=>j(!1),collapsed:w,mobileDrawerOpen:T,onSelectData:pe,onCloseData:()=>le(!1),initialDataSurface:ue,onLogout:i,onDisconnect:a,disconnecting:s,claudeConnected:S,subAccounts:g,activeAccountId:_,switchingAccount:v,onSwitchAccount:ee,refreshAccounts:y,onOpenConversations:p}),!O&&(0,D.jsx)(Ce,{}),(0,D.jsx)(_e,{sidebarOpen:me,onToggleSidebar:he,claudeConnected:S,onConnectClaude:C}),typeof m==`function`?m(ve):m]}),T&&(0,D.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>j(!1)}),(0,D.jsx)(be,{}),h]})}export{A as _,Ue as a,I as c,me as d,j as f,ce as g,le as h,We as i,je as l,ue as m,lt as n,L as o,de as p,Qe as r,F as s,pt as t,ke as u,se as v};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-TPjIAO9U.js";import{B as t,C as n,H as r,L as i,f as a,j as o,z as s}from"./useSubAccountSwitcher-sPN6lobE.js";import{_ as c,t as l,v as u}from"./AdminShell-DR6AzflZ.js";import{t as d}from"./Checkbox-D7_S2EUI.js";import{t as f}from"./triangle-alert-BDtoi5R0.js";var p=t(),m=e(r(),1),h=i(),g=`—`;function _(e){switch(e){case`waiting`:return`Waiting`;case`never-run`:return`Never run`;case`never-succeeded`:return`Never succeeded`;case`failing`:return`Failing`;case`stalled`:return`Stalled`;case`running`:return`Running`;case`ok`:return`Healthy`}}var v={waiting:`Armed and not due yet. It has no start-up run and its first interval has not elapsed, so it has correctly not fired.`,"never-run":`Its interval has elapsed and it still has not fired once. This is not the same as waiting its turn.`,"never-succeeded":`It has fired, and not one run has finished. The work this loop exists to do has never happened.`,failing:`It worked before and is failing now.`,stalled:`It has not started within three of its own intervals. Something is holding it up.`,running:`A run is in progress right now.`,ok:`The last run finished and the next is due within the interval.`},y=new Set([`never-run`,`never-succeeded`,`failing`,`stalled`]),b=10;function x(e){return e===null||!Number.isFinite(e)?g:`${e.toFixed(1)}%`}function S(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`}function C(e,t){if(e===null)return g;let n=t-e;return n<0?`in ${S(-n)}`:n<6e4?`${Math.round(n/1e3)}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}function w(e,t){if(e===null)return g;let n=e-t;return n>=0?`in ${S(n)}`:`overdue by ${S(-n)}`}function T({loops:e,nowMs:t=Date.now()}){let[n,r]=(0,m.useState)(!1);if(!e)return(0,h.jsxs)(`section`,{className:`activity-loops`,children:[(0,h.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,h.jsx)(`p`,{className:`activity-loops-empty`,children:`Scheduled work could not be read from the server.`})]});let i=e.armed-e.rows.length,a=e.rows.filter(e=>y.has(e.state)),o=e.rows.filter(e=>!y.has(e.state)&&typeof e.cpuPct==`number`&&e.cpuPct>=b),s=n?e.rows:[...a,...o];return(0,h.jsxs)(`section`,{className:`activity-loops`,children:[(0,h.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,h.jsxs)(`p`,{className:`activity-loops-sub`,children:[e.armed,` `,e.armed===1?`loop`:`loops`,` armed`,a.length>0?` · ${a.length} ${a.length===1?`needs`:`need`} attention`:` · all healthy`,o.length>0&&` · ${o.length} using significant processor`,`. `,(0,h.jsx)(`button`,{type:`button`,className:`activity-loops-toggle`,"aria-expanded":n,onClick:()=>r(e=>!e),children:n?`Show less`:`Show all`})]}),typeof e.processPct==`number`&&(0,h.jsxs)(`p`,{className:`activity-loops-cpu`,children:[`Server process at `,e.processPct.toFixed(1),`% of one core`,typeof e.attributedPct==`number`&&(0,h.jsxs)(h.Fragment,{children:[` · these loops explain `,e.attributedPct.toFixed(1),`%`]}),typeof e.unattributedPct==`number`&&e.unattributedPct>=1&&(0,h.jsxs)(h.Fragment,{children:[` · `,(0,h.jsxs)(`strong`,{children:[e.unattributedPct.toFixed(1),`% is not from these loops`]})]})]}),i>0&&(0,h.jsxs)(`p`,{className:`activity-loops-omission`,role:`status`,children:[i,` armed `,i===1?`loop is`:`loops are`,` missing from this list. The server armed `,e.armed,` but sent `,e.rows.length,`.`]}),s.length===0?null:(0,h.jsx)(`div`,{className:`activity-table-scroll`,children:(0,h.jsxs)(`table`,{className:`activity-table`,children:[(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Loop`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`State`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Every`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last run`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last OK`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Took`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`CPU`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Runs`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Produced`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Next due`})]})}),(0,h.jsx)(`tbody`,{children:s.map(e=>(0,h.jsxs)(`tr`,{className:y.has(e.state)?`activity-loop-row activity-loop-unhealthy`:`activity-loop-row`,children:[(0,h.jsx)(`td`,{className:`activity-td`,children:e.name}),(0,h.jsx)(`td`,{className:`activity-td`,title:v[e.state],children:(0,h.jsxs)(`span`,{className:`activity-state`,children:[(0,h.jsx)(`span`,{className:e.state===`ok`?`activity-state-dot is-healthy`:y.has(e.state)?`activity-state-dot is-unhealthy`:`activity-state-dot`,"aria-hidden":`true`}),_(e.state)]})}),(0,h.jsx)(`td`,{className:`activity-td activity-num`,children:S(e.intervalMs)}),(0,h.jsx)(`td`,{className:`activity-td activity-num`,children:C(e.lastStartMs,t)}),(0,h.jsx)(`td`,{className:`activity-td activity-num`,children:C(e.lastSuccessMs,t)}),(0,h.jsx)(`td`,{className:`activity-td activity-num`,children:e.lastDurationMs===null?g:`${e.lastDurationMs} ms`}),(0,h.jsx)(`td`,{className:`activity-td activity-num`,title:e.cpuAttributable?e.detached?`Includes the processor time of the separate process this loop starts.`:void 0:`This loop waits on other work while it runs, so the processor time it uses cannot be separated from the rest of the server.`,children:x(e.cpuPct)}),(0,h.jsxs)(`td`,{className:`activity-td activity-num`,children:[e.successCount,`/`,e.runCount]}),(0,h.jsx)(`td`,{className:`activity-td activity-loop-note`,children:(0,h.jsx)(`span`,{className:`activity-loop-note-text`,title:e.lastError??e.lastNote??void 0,children:e.lastError??e.lastNote??g})}),(0,h.jsx)(`td`,{className:`activity-td activity-num`,children:w(e.nextDueMs,t)})]},e.name))})]})}),(0,h.jsxs)(`dl`,{className:`activity-legend`,children:[(0,h.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,h.jsx)(`dt`,{className:`activity-legend-term`,children:`Runs`}),(0,h.jsx)(`dd`,{className:`activity-legend-def`,children:`Finished runs out of attempted runs since the server started. 0 out of a large number means it has tried many times and never once finished.`})]}),(0,h.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,h.jsx)(`dt`,{className:`activity-legend-term`,children:`CPU`}),(0,h.jsx)(`dd`,{className:`activity-legend-def`,children:`Share of one processor core this loop is using, measured between the last two refreshes. It includes any separate process the loop starts, and can pass 100% because those run alongside each other. A dash means it could not be measured: the loop waits on other work while it runs, so its share cannot be separated from the rest of the server.`})]}),(0,h.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,h.jsx)(`dt`,{className:`activity-legend-term`,children:g}),(0,h.jsx)(`dd`,{className:`activity-legend-def`,children:`Not measured. It does not mean zero.`})]})]})]})}var E=`maxy-admin-session-key`;function D(e){switch(e.costUnavailable){case`metering-failed`:return`Cost could not be calculated: ${e.meteringError??`the transcript could not be read`}`;case`model-not-priced`:return`No published price for this model, so cost cannot be estimated.`;case`no-transcript`:return`This session has no transcript yet, so there is nothing to cost.`;default:return}}var O=[{key:`lastMessageAt`,label:`Last activity`,dir:-1},{key:`activeMsInRange`,label:`Active time`,dir:-1},{key:`costGbp`,label:`Cost`,dir:-1},{key:`accountId`,label:`Account name`,dir:1}],k=[{key:`title`,label:`Session`,help:`The conversation name, or its short id when it has none yet.`},{key:`model`,label:`Model`,help:`The model that answered the most recent turn.`},{key:`status`,label:`Status`,help:`What the process is doing right now.`},{key:`activeMsInRange`,label:`Active`,help:`Time this session spent thinking, writing and running tools inside the selected range. This is worked time, not elapsed time.`},{key:`ageMs`,label:`Age`,help:`How long ago this conversation started. Wall-clock, so it counts every hour nobody was working.`},{key:`lastMessageAt`,label:`Last activity`,help:`The clock time of the most recent message, in your timezone. A date appears once it is not today.`},{key:`turnCount`,label:`Turns`,help:`Messages exchanged. A trailing + means the count is a minimum — the conversation is too long to count exactly.`},{key:`rssKb`,label:`RAM`,help:`Memory held by this session and all its helper processes together.`},{key:`cpuPct`,label:`CPU (avg)`,help:`AVERAGE share of one processor core over the last census interval, up to 60 seconds. It is not a reading of this instant, so a session that answered a turn a minute ago still shows a high figure while sitting quiet now. Can exceed 100% because a session runs many processes at once.`},{key:`tokensInRange`,label:`Tokens`,help:`Total tokens billed inside the selected range, added up across every day in it. A cumulative total, not the size of the conversation the model currently reads back.`},{key:`costGbp`,label:`Cost`,help:`Estimated spend inside the selected range, at published prices for this model.`}],A=[`activeMsInRange`,`lastMessageAt`,`cpuPct`,`tokensInRange`],j={label:`Account`,help:`The business this session belongs to. "untagged" means the session records no account.`};function M(e,t){let n=t?.[e];return n&&n.trim()!==``?n:e.slice(0,8)}var N=`—`;function P(e){if(e===null||!Number.isFinite(e)||e<0)return N;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d ${r%24}h`}function F(e){return e===null||!Number.isFinite(e)?N:`${(e/1024/1024).toFixed(1)} GB`}function I(e,t){if(!e)return N;let n=Date.parse(e);if(!Number.isFinite(n))return N;let r=new Date(n),i=new Date(t),a=`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`;return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()?a:`${r.getDate()} ${r.toLocaleString(`en-GB`,{month:`short`})} ${a}`}function L(e){return e===null||!Number.isFinite(e)?N:`${e.toFixed(1)}%`}function R(e){return e===null||!Number.isFinite(e)?N:e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(2)}M`}function z(e){return e===null||!Number.isFinite(e)?N:`£${e.toFixed(2)}`}function B(e){if(e===null||!Number.isFinite(e)||e<0)return N;let t=Math.floor(e/6e4);return`${Math.floor(t/60)}h ${t%60}m`}function V(e,t,n,r){let i=e[n],a=t[n];if(i===null&&a===null)return 0;if(i===null)return 1;if(a===null)return-1;if(n===`lastMessageAt`){let e=Date.parse(String(i)),t=Date.parse(String(a));return!Number.isFinite(e)&&!Number.isFinite(t)?0:Number.isFinite(e)?Number.isFinite(t)?(e-t)*r:-1:1}return typeof i==`number`&&typeof a==`number`?(i-a)*r:String(i).localeCompare(String(a))*r}function H(e){return e.toISOString().slice(0,10)}function U(e){let t=e.getUTCFullYear(),n=e.getUTCMonth();return{from:H(new Date(Date.UTC(t,n,1))),to:H(new Date(Date.UTC(t,n+1,0)))}}function W(e,t){let n=new Date(`${e}T00:00:00.000Z`);return U(new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+t,1)))}function G(e,t){return{from:H(new Date(t-(e-1)*864e5)),to:H(new Date(t))}}function K(e){return new Date(`${e}T00:00:00.000Z`).toLocaleString(`en-GB`,{month:`long`,year:`numeric`,timeZone:`UTC`})}function q(e){if(e===null)return!1;let t=U(new Date(`${e.from}T00:00:00.000Z`));return t.from===e.from&&t.to===e.to}function J(e,t,n){switch(e){case`title`:return t.title??t.sessionId.slice(0,8);case`model`:return t.model??N;case`status`:return t.status??N;case`activeMsInRange`:return B(t.activeMsInRange);case`ageMs`:return P(t.ageMs);case`lastMessageAt`:return I(t.lastMessageAt,n);case`turnCount`:return t.turnCount===null?N:`${t.turnCount}${t.turnCountCapped?`+`:``}`;case`rssKb`:return F(t.rssKb);case`cpuPct`:return L(t.cpuPct);case`tokensInRange`:return R(t.tokensInRange);case`costGbp`:return z(t.costGbp);default:return N}}function Y({adminFetch:e}){let[t,r]=(0,m.useState)(null),[i,a]=(0,m.useState)(null),[s,l]=(0,m.useState)(!1),[u,p]=(0,m.useState)(`lastMessageAt`),[g,_]=(0,m.useState)(-1),[v,y]=(0,m.useState)(()=>U(new Date)),[b,x]=(0,m.useState)(!0),[S,C]=(0,m.useState)(!0),[w,E]=(0,m.useState)(!1),F=(0,m.useRef)(!1),I=(0,m.useRef)(void 0),L=(0,m.useCallback)(async t=>{if(F.current){I.current=t;return}F.current=!0;try{let n=await e(`/api/admin/activity${t?`?from=${t.from}&to=${t.to}`:``}`);if(n.status===403){a(`This view is available to the house account only.`),l(!0);return}if(!n.ok){a(`The session manager did not answer (status ${n.status}).`),l(!0);return}r(await n.json()),a(null)}catch(e){a(e instanceof Error?e.message:String(e))}finally{l(!0),F.current=!1;let e=I.current;I.current=void 0,e!==void 0&&L(e)}},[e]);(0,m.useEffect)(()=>{L(v);let e=setInterval(()=>void L(v),15e3);return()=>clearInterval(e)},[L,v]);let R=(0,m.useMemo)(()=>t?[...t.rows].sort((e,t)=>V(e,t,u,g)):[],[t,u,g]),z=(0,m.useMemo)(()=>R.filter(e=>e.status===`busy`?b:e.status===`idle`?S:!0),[R,b,S]),B=R.length-z.length;if(!s)return(0,h.jsxs)(`div`,{className:`activity-loading`,children:[(0,h.jsx)(n,{size:18,className:`spin`}),` Loading…`]});if(i)return(0,h.jsx)(`div`,{className:`activity-empty`,children:i});if(!t)return(0,h.jsx)(`div`,{className:`activity-empty`,children:`No response.`});let{accounts:H,census:Y,censusAgeMs:X}=t,Z=Date.now(),Q=H.onDisk!==null&&H.onDisk>H.valid,$=t.range===void 0?v:t.range;return(0,h.jsxs)(`div`,{className:`activity-body`,children:[(0,h.jsxs)(`div`,{className:`activity-head`,children:[(0,h.jsxs)(`span`,{className:`activity-title`,children:[(0,h.jsx)(o,{size:16}),` Live sessions`]}),(0,h.jsxs)(`span`,{className:`activity-meta`,children:[B>0?`${z.length} of ${R.length} live · ${B} hidden`:`${R.length} live`,` · `,H.valid,` accounts`,H.untaggedCount>0?` · ${H.untaggedCount} untagged`:``]})]}),(0,h.jsxs)(`div`,{className:`activity-controls`,children:[(0,h.jsxs)(`div`,{className:`activity-control activity-range`,children:[(0,h.jsx)(c,{variant:`secondary`,size:`sm`,"aria-label":`Previous month`,disabled:!q(v),onClick:()=>y(e=>e&&W(e.from,-1)),children:`‹`}),(0,h.jsx)(`span`,{className:`activity-range-label`,children:v===null?`All time`:q(v)?K(v.from):`${v.from} → ${v.to}`}),(0,h.jsx)(c,{variant:`secondary`,size:`sm`,"aria-label":`Next month`,disabled:!q(v),onClick:()=>y(e=>e&&W(e.from,1)),children:`›`})]}),(0,h.jsxs)(`div`,{className:`activity-control activity-presets`,children:[(0,h.jsx)(c,{variant:`secondary`,size:`sm`,"aria-pressed":v!==null&&q(v)&&v.from===U(new Date).from,onClick:()=>y(U(new Date)),children:`This month`}),(0,h.jsx)(c,{variant:`secondary`,size:`sm`,"aria-pressed":v!==null&&!q(v),onClick:()=>y(G(7,Date.now())),children:`Last 7 days`}),(0,h.jsx)(c,{variant:`secondary`,size:`sm`,"aria-pressed":v===null,onClick:()=>y(null),children:`All time`})]}),(0,h.jsxs)(`div`,{className:`activity-control`,children:[(0,h.jsx)(`label`,{className:`activity-control-label`,htmlFor:`activity-sort`,children:`Sort by`}),(0,h.jsx)(`span`,{className:`activity-select-wrap`,children:(0,h.jsx)(`select`,{id:`activity-sort`,className:`activity-select`,value:u,onChange:e=>{let t=O.find(t=>t.key===e.target.value);t&&(p(t.key),_(t.dir))},children:O.map(e=>(0,h.jsx)(`option`,{value:e.key,children:e.label},e.key))})})]}),(0,h.jsxs)(`div`,{className:`activity-control activity-visibility`,children:[(0,h.jsx)(d,{checked:b,onChange:x,label:`Busy`}),(0,h.jsx)(d,{checked:S,onChange:C,label:`Idle`})]})]}),(0,h.jsxs)(`div`,{className:`activity-range-note`,children:[$===null?`Active time, tokens and cost cover each conversation’s whole history.`:`Active time, tokens and cost cover ${$.from} to ${$.to} (UTC), inclusive.`,t.fullRangeFallback&&(0,h.jsxs)(`strong`,{className:`activity-range-rejected`,children:[` `,`The range was not accepted, so these are all-time figures.`]})]}),(0,h.jsx)(`div`,{className:`activity-census`,children:Y===null?`No census collected yet, so memory and CPU are unavailable.`:`Memory and CPU measured ${P(X)} ago, averaged over the minute before that · ${Y.cpuNull} of ${Y.live} without a CPU reading`}),Q&&(0,h.jsxs)(`div`,{className:`activity-warning`,children:[(0,h.jsx)(f,{size:14}),` `,H.onDisk,` account folders on disk but only`,` `,H.valid,` are readable. Sessions belonging to the rest cannot be attributed.`]}),R.length===0?(0,h.jsx)(`div`,{className:`activity-empty`,children:`No sessions are running.`}):z.length===0?(0,h.jsxs)(`div`,{className:`activity-empty`,children:[`All `,R.length,` running sessions are hidden by the Busy and Idle filters.`]}):(0,h.jsx)(`div`,{className:`activity-grid`,children:z.map(e=>(0,h.jsxs)(`article`,{className:`activity-card`,"data-testid":`activity-card`,"data-session-id":e.sessionId,children:[(0,h.jsx)(`h3`,{className:`activity-card-heading`,title:e.accountId??void 0,children:e.accountId===null?(0,h.jsx)(`span`,{className:`activity-untagged`,title:`This session records no account, so it cannot be attributed to a business.`,children:`untagged`}):M(e.accountId,H.names)}),(0,h.jsx)(`dl`,{className:`activity-card-rows`,children:k.map(t=>(0,h.jsxs)(`div`,{className:`activity-card-row`,children:[(0,h.jsx)(`dt`,{className:`activity-card-label`,"data-testid":`activity-card-label`,title:t.help,children:t.label}),(0,h.jsx)(`dd`,{className:`activity-card-value`,title:t.key===`costGbp`?D(e):void 0,children:J(t.key,e,Z)})]},t.key))})]},e.sessionId))}),R.length>0&&(0,h.jsxs)(`div`,{className:`activity-glossary`,children:[(0,h.jsxs)(`dl`,{className:`activity-legend`,children:[w&&(0,h.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,h.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:j.label}),(0,h.jsx)(`dd`,{className:`activity-legend-def`,children:j.help})]},`heading`),(w?k:k.filter(e=>A.includes(e.key))).map(e=>(0,h.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,h.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:e.label}),(0,h.jsx)(`dd`,{className:`activity-legend-def`,children:e.help})]},e.key)),(0,h.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,h.jsx)(`dt`,{className:`activity-legend-term`,children:N}),(0,h.jsxs)(`dd`,{className:`activity-legend-def`,children:[`Not measured. It does not mean zero — a measured zero is written as a figure, so `,(0,h.jsx)(`em`,{children:`0h 0m`}),` and `,(0,h.jsx)(`em`,{children:`£0.00`}),` are real readings. Hover a dashed value for the reason where one exists.`]})]})]}),(0,h.jsx)(c,{variant:`secondary`,size:`sm`,className:`activity-glossary-toggle`,onClick:()=>E(e=>!e),children:w?`Show fewer`:`Explain every figure`})]}),(0,h.jsx)(T,{loops:t?.loops})]})}function X({cacheKey:e}){let{adminFetch:t}=s({initialCacheKey:e,surface:`activity`});return(0,h.jsx)(Y,{adminFetch:t})}function Z(){let[e,t]=(0,m.useState)(null),[r,i]=(0,m.useState)(!1),[o,s]=(0,m.useState)(void 0),[c,d]=(0,m.useState)(null),[f,p]=(0,m.useState)(null),[g,_]=(0,m.useState)(null),[v,y]=(0,m.useState)(null);(0,m.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(E)}catch{}if(!n){t(null),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(E)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&s(e.businessName),e.sessionId!==void 0&&d(e.sessionId??null),p(e.role??null),_(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let b=(0,m.useCallback)(()=>{try{sessionStorage.removeItem(E)}catch{}window.location.href=`/`},[]),[x,S]=(0,m.useState)(!1),C=(0,m.useCallback)(async()=>{S(!0);try{let e=await u();if(e){try{sessionStorage.removeItem(E)}catch{}window.location.href=`/`}return e}finally{S(!1)}},[]);return r?e?(0,h.jsx)(a,{cacheKey:e,surface:`activity`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=activity`);try{sessionStorage.removeItem(E)}catch{}window.location.href=`/`},children:(0,h.jsx)(l,{cacheKey:e,businessName:o,sessionId:c,onLogout:b,onDisconnect:C,disconnecting:x,userName:g,userAvatar:v,role:f,children:(0,h.jsx)(X,{cacheKey:e})})}):(0,h.jsx)(`div`,{className:`activity-page`,children:(0,h.jsxs)(`div`,{className:`activity-empty`,children:[(0,h.jsx)(`p`,{children:`You are not signed in.`}),(0,h.jsxs)(`p`,{children:[`Open the `,(0,h.jsx)(`a`,{href:`/`,className:`activity-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,h.jsx)(`div`,{className:`activity-page`,children:(0,h.jsxs)(`div`,{className:`activity-loading`,children:[(0,h.jsx)(n,{size:18,className:`spin`}),` Loading…`]})})}(0,p.createRoot)(document.getElementById(`root`)).render((0,h.jsx)(Z,{}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-TPjIAO9U.js";import{B as t,H as n,L as r,T as i,c as a,f as o,g as s,i as c,o as l,p as u}from"./useSubAccountSwitcher-sPN6lobE.js";import{n as d,t as f}from"./AdminLoginScreens-Jw45pvb2.js";import{S as p,s as m}from"./useVoiceRecorder-DOFBQ2gP.js";import{a as h,t as g}from"./AdminShell-DR6AzflZ.js";import"./Checkbox-D7_S2EUI.js";import{i as _,n as v,r as y}from"./page-DsV3rID5.js";import{t as b}from"./bot-GC7iZjtW.js";import{t as x}from"./chevron-down-BCLf1wKu.js";import{t as S}from"./chevron-right-Bu5hsjy5.js";import"./graph-labels-7p-mVi9M.js";var C=t(),w=e(n(),1),T=r();function E({onOpen:e}){return(0,T.jsx)(`footer`,{className:`admin-footer`,children:(0,T.jsxs)(`div`,{className:`powered-by`,role:`button`,tabIndex:0,onClick:e,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},"aria-label":`Powered by Claude Code — show details`,children:[(0,T.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,T.jsx)(`span`,{children:`Powered by Claude Code`})]})})}var D=6e4,O=60*D,k=24*O,A=D,j=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],M=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function N(e){return e<10?`0${e}`:String(e)}function P(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime()}function F(e,t){if(!Number.isFinite(e)||e<=0||!Number.isFinite(t))return`—`;let n=t-e;if(n<-A)return`—`;let r=n<0?0:n;if(r<D)return`just now`;if(r<O)return`${Math.floor(r/D)}m`;if(r<k)return`${Math.floor(r/O)}h`;let i=new Date(t),a=new Date(e),o=Math.round((P(i)-P(a))/k);if(o===1)return`yesterday`;if(o>=2&&o<=6)return M[a.getDay()];let s=N(a.getDate()),c=j[a.getMonth()];return a.getFullYear()===i.getFullYear()?`${s} ${c}`:`${s} ${c} ${a.getFullYear()}`}var I={whatsapp:`WhatsApp`,telegram:`Telegram`,webchat:`Web chat`};function L(e){return e<12?`morning`:e<18?`afternoon`:`evening`}function R(e){return e&&e.trim().split(/\s+/)[0]||`there`}function z(e){if(!e)return`everything is running normally.`;let t=e.cpuPct,n=e.memUsedPct;return t!==null&&t>=.98||n!==null&&n>=.98?`system load is critical.`:t!==null&&t>=.9||n!==null&&n>=.9?`system load is high.`:`everything is running normally.`}function B(e){return e==null?`—`:`${Math.round(e*100)}%`}function V(e){return e.operatorName??e.whatsappName??e.senderId??e.title}function H(e,t){if(!e)return!1;let n=Date.parse(e);if(!Number.isFinite(n))return!1;let r=new Date(n),i=new Date(t);return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()}function U(e){return e?e.replace(/^claude-/,``):null}function W({cacheKey:e,userName:t,onSelectWhatsappConversation:n}){let r=u(e),[o,d]=(0,w.useState)(null),[f,m]=(0,w.useState)(null),[h,g]=(0,w.useState)(null),[_,v]=(0,w.useState)(null),[C,E]=(0,w.useState)(null),[D,O]=(0,w.useState)(null),[k,A]=(0,w.useState)(new Set),j=Date.now();(0,w.useEffect)(()=>{if(!e)return;let t=!1;async function n(e,n,i){try{let a=await r(e);if(!a.ok)throw Error(`status ${a.status}`);let o=await a.json();t||i(n(o))}catch(t){console.error(`[admin-ui] dashboard-fetch-failed url=${e} reason=${t instanceof Error?t.message:String(t)}`)}}return n(`/api/admin/sidebar-sessions`,e=>e.sessions??[],d),n(`/api/whatsapp-reader/conversations`,e=>e.conversations??[],m),n(`/api/admin/system-stats`,e=>e,v),n(`/api/admin/tasks-list`,e=>e,E),n(`/api/admin/sidebar-artefacts`,e=>e.artefacts??[],O),()=>{t=!0}},[e,r]);let M=(0,w.useMemo)(()=>(o??[]).filter(e=>!e.isSubagent),[o]),N=(0,w.useMemo)(()=>M.filter(e=>e.live),[M]),P=(0,w.useMemo)(()=>(f??[]).filter(e=>H(e.lastMessageAt,j)).length,[f,j]),W=C?.open.length??0,G=(0,w.useMemo)(()=>{let e=new Map;for(let t of f??[]){let n=e.get(t.channel)??[];n.push(t),e.set(t.channel,n)}return[...e.entries()].map(([e,t])=>{let n=t.reduce((e,t)=>t.lastMessageAt&&(!e||Date.parse(t.lastMessageAt)>Date.parse(e.lastMessageAt??``))?t:e,null);return{channel:e,count:t.length,preview:n?V(n):``,rows:t}})},[f]),K=(0,w.useCallback)(async e=>{if(!k.has(e)){A(t=>new Set(t).add(e));try{let t=await r(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e})});if(!t.ok){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} status=${t.status}`);return}console.info(`[admin-ui] dashboard-session-stop sessionId=${e}`),d(t=>(t??[]).map(t=>t.sessionId===e?{...t,live:!1}:t))}catch(t){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} reason=${t instanceof Error?t.message:String(t)}`)}finally{A(t=>{let n=new Set(t);return n.delete(e),n})}}},[r,k]),q=(0,w.useCallback)(t=>{if(!e||!t.downloadPath){console.error(`[admin-ui] dashboard-artefact-download-blocked id=${t.id} reason=${e?`not-downloadable`:`no-cache-key`}`);return}y(e,t.downloadPath,t.downloadRoot??`data`)},[e]);return(0,T.jsxs)(`div`,{className:`dashboard-home`,children:[(0,T.jsx)(`p`,{className:`dashboard-greeting`,children:`Good ${L(new Date(j).getHours())}, ${R(t)} — ${z(_)}`}),(0,T.jsxs)(`div`,{className:`dashboard-stats`,children:[(0,T.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,T.jsx)(`span`,{className:`dashboard-stat-label`,children:`Live sessions`}),(0,T.jsx)(`span`,{className:`dashboard-stat-value`,children:N.length}),(0,T.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`of `,M.length,` total`]})]}),(0,T.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,T.jsx)(`span`,{className:`dashboard-stat-label`,children:`Messages today`}),(0,T.jsx)(`span`,{className:`dashboard-stat-value`,children:P})]}),(0,T.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,T.jsx)(`span`,{className:`dashboard-stat-label`,children:`Open tasks`}),(0,T.jsx)(`span`,{className:`dashboard-stat-value`,children:W})]}),(0,T.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,T.jsx)(`span`,{className:`dashboard-stat-label`,children:`Host CPU`}),(0,T.jsx)(`span`,{className:`dashboard-stat-value`,children:B(_?.cpuPct??null)}),(0,T.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`RAM `,B(_?.memUsedPct??null)]})]})]}),(0,T.jsxs)(`div`,{className:`dashboard-columns`,children:[(0,T.jsxs)(`div`,{className:`dashboard-col`,children:[(0,T.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Live now`}),N.length===0?(0,T.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No live sessions right now.`}):N.map(e=>{let t=[e.sessionId.slice(0,8),U(e.model),F(Date.parse(e.startedAt),j)].filter(Boolean).join(` · `);return(0,T.jsxs)(`div`,{className:`admin-card dashboard-live-card`,children:[(0,T.jsx)(`span`,{className:`admin-status-dot is-live`}),(0,T.jsxs)(`div`,{className:`dashboard-live-main`,children:[(0,T.jsx)(`span`,{className:`dashboard-live-name`,children:e.title}),(0,T.jsx)(`span`,{className:`dashboard-live-meta`,children:t})]}),(0,T.jsx)(`a`,{className:`admin-btn-cta dashboard-open-btn`,href:`/chat?session=${encodeURIComponent(e.sessionId)}`,children:`Open`}),(0,T.jsx)(`button`,{type:`button`,className:`dashboard-stop-btn`,"aria-label":`Stop ${e.title}`,disabled:k.has(e.sessionId),onClick:()=>void K(e.sessionId),children:(0,T.jsx)(s,{size:12})})]},e.sessionId)}),(0,T.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Recent artefacts`}),(0,T.jsx)(`div`,{className:`admin-card dashboard-artefacts`,children:(D??[]).length===0?(0,T.jsx)(`div`,{className:`dashboard-empty`,children:`No recent artefacts.`}):(D??[]).slice(0,6).map(e=>(0,T.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-artefact-row`,onClick:()=>q(e),children:[(0,T.jsx)(`span`,{className:`dashboard-artefact-icon`,children:e.kind===`agent-template`?(0,T.jsx)(b,{size:16}):(0,T.jsx)(p,{size:16})}),(0,T.jsx)(`div`,{className:`dashboard-artefact-body`,children:(0,T.jsx)(`span`,{className:`dashboard-artefact-name`,children:e.name})}),(0,T.jsx)(`span`,{className:`dashboard-artefact-time`,children:F(Date.parse(e.updatedAt),j)})]},e.id))})]}),(0,T.jsxs)(`div`,{className:`dashboard-col`,children:[(0,T.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Channels`}),G.length===0?(0,T.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No channel activity.`}):G.map(e=>{let t=h===e.channel;return(0,T.jsxs)(`div`,{className:`admin-card dashboard-channel-card`,children:[(0,T.jsxs)(`button`,{type:`button`,className:`dashboard-channel-head`,"aria-expanded":t,onClick:()=>g(t=>t===e.channel?null:e.channel),children:[(0,T.jsx)(`span`,{className:`dashboard-channel-glyph`,children:e.channel===`whatsapp`||e.channel===`telegram`?(0,T.jsx)(a,{channel:e.channel,size:16}):(0,T.jsx)(i,{size:16})}),(0,T.jsx)(`span`,{className:`dashboard-channel-name`,children:I[e.channel]??e.channel}),(0,T.jsx)(`span`,{className:`dashboard-channel-badge`,children:e.count}),(0,T.jsx)(`span`,{className:`dashboard-channel-chevron`,children:t?(0,T.jsx)(x,{size:14}):(0,T.jsx)(S,{size:14})})]}),t?(0,T.jsx)(`div`,{className:`dashboard-channel-convs`,children:e.rows.map(e=>(0,T.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-channel-conv-row`,onClick:()=>n(e),title:e.title,children:[(0,T.jsx)(`span`,{className:`dashboard-channel-conv-name`,children:c(e)}),e.lastMessageAt&&(0,T.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:F(Date.parse(e.lastMessageAt),j)})]},l(e)))}):e.preview&&(0,T.jsx)(`span`,{className:`dashboard-channel-preview`,children:e.preview})]},e.channel)})]})]})]})}function G(){let e=d(),[t,n]=(0,w.useState)(!1);(0,w.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,w.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);return}let r=Date.now();try{let t=await fetch(`/api/admin/claude-info`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,w.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`chat`?(0,T.jsx)(o,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,T.jsx)(g,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,onDisconnect:e.handleDisconnect,disconnecting:e.disconnecting,claudeConnected:e.claudeConnected,onConnectClaude:()=>e.setAppState(`connect-claude`),userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(E,{onOpen:r}),(0,T.jsx)(h,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,T.jsx)(T.Fragment,{children:t.dataOpen&&e.cacheKey?(0,T.jsx)(v,{cacheKey:e.cacheKey}):t.selectedWhatsapp&&e.cacheKey?t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.remoteJid&&t.selectedWhatsapp.accountId?(0,T.jsx)(_,{accountId:t.selectedWhatsapp.accountId,remoteJid:t.selectedWhatsapp.remoteJid,contactName:c(t.selectedWhatsapp),sessionKey:e.cacheKey},l(t.selectedWhatsapp)):(0,T.jsx)(m,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,forceDeliveredOnly:!0},l(t.selectedWhatsapp)):(0,T.jsx)(W,{cacheKey:e.cacheKey,userName:e.userName,onSelectWhatsappConversation:t.onSelectWhatsappConversation})})})}):(0,T.jsx)(f,{auth:e})}(0,C.createRoot)(document.getElementById(`root`)).render((0,T.jsx)(G,{}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-TPjIAO9U.js";import{B as t,C as n,D as r,E as i,H as a,L as o,M as s,b as c,f as l,h as u,m as d,z as f}from"./useSubAccountSwitcher-sPN6lobE.js";import{t as p,v as m}from"./AdminShell-DR6AzflZ.js";import{t as h}from"./chevron-left-BNtL-CjS.js";import{t as g}from"./chevron-right-Bu5hsjy5.js";var _=s(`calendar`,[[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`4`,rx:`2`,key:`1hopcy`}],[`path`,{d:`M3 10h18`,key:`8toen8`}]]),v=s(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]),y=s(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),b=s(`sticky-note`,[[`path`,{d:`M21 9a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 15 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2z`,key:`1dfntj`}],[`path`,{d:`M15 3v5a1 1 0 0 0 1 1h5`,key:`6s6qgf`}]]),x=s(`user-plus`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]),ee=s(`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`}]]),S=t(),C=e(a(),1);function w(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function T(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function E(e){let t=w(e),n=t.getDay();return T(t,n===0?-6:1-n)}function D(e){let t=E(e);return Array.from({length:7},(e,n)=>T(t,n))}function O(e){let t=E(new Date(e.getFullYear(),e.getMonth(),1));return Array.from({length:42},(e,n)=>T(t,n))}function k(){return Array.from({length:24},(e,t)=>t)}function A(e){let t=e.getFullYear();return Array.from({length:12},(e,n)=>new Date(t,n,1))}function j(e,t){switch(e){case`day`:{let e=w(t);return{from:e,to:T(e,1)}}case`week`:{let e=E(t);return{from:e,to:T(e,7)}}case`month`:{let e=E(new Date(t.getFullYear(),t.getMonth(),1));return{from:e,to:T(e,42)}}case`year`:return{from:new Date(t.getFullYear(),0,1),to:new Date(t.getFullYear()+1,0,1)}}}function M(e,t,n){switch(e){case`day`:return T(t,n);case`week`:return T(t,n*7);case`month`:return new Date(t.getFullYear(),t.getMonth()+n,1);case`year`:return new Date(t.getFullYear()+n,t.getMonth(),1)}}function N(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function P(e,t){return{role:`button`,tabIndex:0,onClick:()=>t(e),onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e))}}}var F=o(),I=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],L=3;function R(e){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}function z({anchor:e,meetings:t,onSelect:n}){let r=O(e),i=e.getMonth(),a=new Date;return(0,F.jsxs)(`div`,{className:`cal-month`,children:[(0,F.jsx)(`div`,{className:`cal-weekday-row`,children:I.map(e=>(0,F.jsx)(`div`,{className:`cal-weekday`,children:e},e))}),(0,F.jsx)(`div`,{className:`cal-month-grid`,children:r.map(e=>{let r=t.filter(t=>N(new Date(t.startsAt),e)).sort((e,t)=>e.startsAt.localeCompare(t.startsAt)),o=e.getMonth()!==i,s=N(e,a);return(0,F.jsxs)(`div`,{className:`cal-cell${o?` cal-cell-out`:``}${s?` cal-cell-today`:``}`,children:[(0,F.jsx)(`div`,{className:`cal-cell-num`,children:e.getDate()}),r.slice(0,L).map(e=>(0,F.jsxs)(`div`,{className:`cal-chip`,title:e.title??`Untitled`,...P(e,n),children:[!e.isAllDay&&(0,F.jsx)(`span`,{className:`cal-chip-time`,children:R(new Date(e.startsAt))}),e.title??`Untitled`]},e.meetingId)),r.length>L&&(0,F.jsxs)(`div`,{className:`cal-more`,children:[`+`,r.length-L,` more`]})]},e.toISOString())})})]})}var B=1440,V=1.8;function H(e){return e.getHours()*60+e.getMinutes()}function U(e){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}function W({day:e,meetings:t,hourHeight:n,onSelect:r}){let i=n*24,a=t.filter(t=>!t.isAllDay&&N(new Date(t.startsAt),e));return(0,F.jsx)(`div`,{className:`cal-day-col`,children:(0,F.jsxs)(`div`,{className:`cal-hours`,style:{height:`${i}px`},children:[Array.from({length:24},(e,t)=>(0,F.jsx)(`div`,{className:`cal-hour-line`,style:{top:`${t*n}px`}},t)),a.map(t=>{let n=new Date(t.startsAt),i=t.endsAt?new Date(t.endsAt):new Date(n.getTime()+30*6e4),a=H(n),o=N(i,e)?H(i):B,s=a/B*100,c=Math.max((o-a)/B*100,V);return(0,F.jsxs)(`div`,{className:`cal-event`,style:{top:`${s}%`,height:`${c}%`},title:t.title??`Untitled`,...P(t,r),children:[(0,F.jsx)(`span`,{className:`cal-event-time`,children:U(n)}),(0,F.jsx)(`span`,{className:`cal-event-title`,children:t.title??`Untitled`})]},t.meetingId)})]})})}var G=44;function K(e){let t=new Date;return t.setHours(e,0,0,0),t.toLocaleTimeString([],{hour:`numeric`})}function q({anchor:e,meetings:t,onSelect:n}){let r=D(e),i=new Date;return(0,F.jsxs)(`div`,{className:`cal-timed`,children:[(0,F.jsxs)(`div`,{className:`cal-day-headrow`,children:[(0,F.jsx)(`div`,{className:`cal-timed-gutter`}),r.map(e=>(0,F.jsxs)(`div`,{className:`cal-day-head${N(e,i)?` cal-day-head-today`:``}`,children:[(0,F.jsx)(`span`,{className:`cal-day-head-name`,children:e.toLocaleDateString([],{weekday:`short`})}),(0,F.jsx)(`span`,{className:`cal-day-head-num`,children:e.getDate()})]},e.toISOString()))]}),(0,F.jsxs)(`div`,{className:`cal-allday-band`,children:[(0,F.jsx)(`div`,{className:`cal-timed-gutter`,children:`All-day`}),r.map(e=>(0,F.jsx)(`div`,{className:`cal-allday-cell`,children:t.filter(t=>t.isAllDay&&N(new Date(t.startsAt),e)).map(e=>(0,F.jsx)(`div`,{className:`cal-allday-chip`,title:e.title??`Untitled`,...P(e,n),children:e.title??`Untitled`},e.meetingId))},e.toISOString()))]}),(0,F.jsxs)(`div`,{className:`cal-timed-cols`,children:[(0,F.jsx)(`div`,{className:`cal-timed-gutter`,children:k().map(e=>(0,F.jsx)(`div`,{className:`cal-hour-label`,style:{height:`${G}px`},children:e===0?``:K(e)},e))}),r.map(e=>(0,F.jsx)(W,{day:e,meetings:t,hourHeight:G,onSelect:n},e.toISOString()))]})]})}var J=52;function Y(e){let t=new Date;return t.setHours(e,0,0,0),t.toLocaleTimeString([],{hour:`numeric`})}function X({anchor:e,meetings:t,onSelect:n}){let r=t.filter(t=>t.isAllDay&&N(new Date(t.startsAt),e));return(0,F.jsxs)(`div`,{className:`cal-timed cal-timed-single`,children:[(0,F.jsxs)(`div`,{className:`cal-allday-band`,children:[(0,F.jsx)(`div`,{className:`cal-timed-gutter`,children:`All-day`}),(0,F.jsx)(`div`,{className:`cal-allday-cell`,children:r.map(e=>(0,F.jsx)(`div`,{className:`cal-allday-chip`,title:e.title??`Untitled`,...P(e,n),children:e.title??`Untitled`},e.meetingId))})]}),(0,F.jsxs)(`div`,{className:`cal-timed-cols`,children:[(0,F.jsx)(`div`,{className:`cal-timed-gutter`,children:k().map(e=>(0,F.jsx)(`div`,{className:`cal-hour-label`,style:{height:`${J}px`},children:e===0?``:Y(e)},e))}),(0,F.jsx)(W,{day:e,meetings:t,hourHeight:J,onSelect:n})]})]})}var Z=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function te(e){return`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function ne({anchor:e,meetings:t,onPickMonth:n}){let r=new Date,i=new Set(t.map(e=>te(new Date(e.startsAt))));return(0,F.jsx)(`div`,{className:`cal-year`,children:(0,F.jsx)(`div`,{className:`cal-year-grid`,children:A(e).map(e=>{let t=O(e),a=e.getMonth();return(0,F.jsxs)(`button`,{type:`button`,className:`cal-mini`,onClick:()=>n(e),title:e.toLocaleDateString([],{month:`long`,year:`numeric`}),children:[(0,F.jsx)(`div`,{className:`cal-mini-title`,children:e.toLocaleDateString([],{month:`long`})}),(0,F.jsx)(`div`,{className:`cal-mini-weekrow`,children:Z.map((e,t)=>(0,F.jsx)(`span`,{className:`cal-mini-weekday`,children:e},t))}),(0,F.jsx)(`div`,{className:`cal-mini-grid`,children:t.map(e=>{let t=e.getMonth()!==a,n=N(e,r),o=!t&&i.has(te(e));return(0,F.jsxs)(`span`,{className:`cal-mini-day${t?` cal-mini-day-out`:``}${n?` cal-mini-day-today`:``}`,children:[e.getDate(),o&&(0,F.jsx)(`span`,{className:`cal-mini-dot`})]},e.toISOString())})})]},a)})})})}var re={meeting:`Meeting`,event:`Event`,task:`Task`};function ie(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function ae(e){return new Date(e).toISOString()}function Q(e){return Math.floor(new Date(e).getTime()/6e4)}function oe(e){let t=new Date(e.startsAt);if(e.isAllDay)return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`});let n=t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`}),r=t.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`});return e.endsAt?`${n} · ${r} – ${new Date(e.endsAt).toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}`:`${n} · ${r}`}function se(e){if(!e)return null;let t=e.match(/filename="([^"]+)"/);return t?t[1]:null}function ce(e,t){return e.email??`${e.name??`unknown`}-${t}`}function le({a:e}){let t=e.name||e.email||`Unknown`,n=e.name&&e.email?e.email:null;return(0,F.jsxs)(`span`,{className:`cal-attendee-lines`,children:[(0,F.jsx)(`span`,{className:`cal-attendee-name`,children:t}),n&&(0,F.jsx)(`span`,{className:`cal-attendee-email`,children:n})]})}function ue({meeting:e,adminFetch:t,onClose:i,onSaved:a,onDeleted:o}){let s=e.kind===`meeting`,[l,f]=(0,C.useState)(!1),[p,m]=(0,C.useState)(!1),[h,g]=(0,C.useState)(!1),[S,w]=(0,C.useState)(!1),[T,E]=(0,C.useState)(null),[D,O]=(0,C.useState)(e),[k,A]=(0,C.useState)(e.title??``),[j,M]=(0,C.useState)(ie(e.startsAt)),[N,P]=(0,C.useState)(e.endsAt?ie(e.endsAt):``),[I,L]=(0,C.useState)(e.location??``),[R,z]=(0,C.useState)(e.privateNote??``),[B,V]=(0,C.useState)(``),[H,U]=(0,C.useState)(``);(0,C.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!S&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[S,i]);let W=(0,C.useCallback)(()=>{let e={},t=k.trim();t!==(D.title??``)&&(e.title=t);let n=ae(j);Q(n)!==Q(D.startsAt)&&(e.startsAt=n);let r=N?ae(N):null;(r===null?D.endsAt!==null:D.endsAt===null||Q(r)!==Q(D.endsAt))&&(e.endsAt=r);let i=I.trim()||null;i!==(D.location??null)&&(e.location=i);let a=R.trim()||null;return a!==(D.privateNote??null)&&(e.privateNote=a),e},[k,j,N,I,R,D]),G=(0,C.useCallback)(async()=>{let n=W();if(Object.keys(n).length===0){f(!1);return}w(!0),E(null);try{let r=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)});if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.json();O(i.meeting),a(i.meeting),f(!1)}catch(e){E(e instanceof Error?e.message:`Save failed`)}finally{w(!1)}},[t,W,e.meetingId,a]),K=(0,C.useCallback)(async()=>{let n=B.trim(),r=H.trim();if(!(!n&&!r)){w(!0),E(null);try{let i=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/attendees`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n||void 0,email:r||void 0})});if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.json();O(o.meeting),a(o.meeting),V(``),U(``)}catch(e){E(e instanceof Error?e.message:`Add failed`)}finally{w(!1)}}},[t,B,H,e.meetingId,a]),q=(0,C.useCallback)(async n=>{let r=n.email?{email:n.email}:{name:n.name};w(!0),E(null);try{let n=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/attendees`,{method:`DELETE`,headers:{"content-type":`application/json`},body:JSON.stringify(r)});if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.json();O(i.meeting),a(i.meeting)}catch(e){E(e instanceof Error?e.message:`Remove failed`)}finally{w(!1)}},[t,e.meetingId,a]),J=(0,C.useCallback)(async()=>{w(!0),E(null);try{let n=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`DELETE`});if(!n.ok)throw Error(`HTTP ${n.status}`);o(e.meetingId)}catch(e){E(e instanceof Error?e.message:`Delete failed`),w(!1)}},[t,e.meetingId,o]),Y=(0,C.useCallback)(async n=>{g(!1),w(!0),E(null);try{let r=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/ics?attendees=${n?`1`:`0`}`);if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.blob(),a=se(r.headers.get(`content-disposition`))??`meeting.ics`,o=URL.createObjectURL(i),s=document.createElement(`a`);s.href=o,s.download=a,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(o)}catch(e){E(e instanceof Error?e.message:`Download failed`)}finally{w(!1)}},[t,e.meetingId]),X=re[e.kind??`meeting`],Z=B.trim().length>0||H.trim().length>0;return(0,F.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{S||i()},children:(0,F.jsxs)(`div`,{className:`cal-modal`,role:`dialog`,"aria-modal":`true`,"aria-label":l?`Edit meeting`:`Meeting detail`,onClick:e=>e.stopPropagation(),children:[(0,F.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,F.jsx)(`span`,{className:`cal-modal-kind`,children:X}),(0,F.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:i,"aria-label":`Close`,autoFocus:!0,disabled:S,children:(0,F.jsx)(d,{size:16})})]}),!l&&(0,F.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,F.jsx)(`div`,{className:`cal-modal-title`,children:D.title??`Untitled`}),(0,F.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,F.jsx)(v,{size:14}),(0,F.jsx)(`span`,{children:oe(D)})]}),D.location&&(0,F.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,F.jsx)(y,{size:14}),(0,F.jsx)(`span`,{children:D.location})]}),D.attendees.length>0&&(0,F.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,F.jsx)(ee,{size:14}),(0,F.jsx)(`div`,{className:`cal-modal-attendees`,children:D.attendees.map((e,t)=>(0,F.jsx)(`div`,{className:`cal-attendee-row`,children:(0,F.jsx)(le,{a:e})},ce(e,t)))})]}),D.privateNote&&(0,F.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,F.jsx)(b,{size:14}),(0,F.jsx)(`span`,{className:`cal-modal-note`,children:D.privateNote})]}),(0,F.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,F.jsx)(_,{size:14}),(0,F.jsx)(`span`,{children:X})]})]}),l&&(0,F.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,F.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,F.jsx)(`span`,{children:`Title`}),(0,F.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),disabled:S})]}),(0,F.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,F.jsx)(`span`,{children:`Start`}),(0,F.jsx)(`input`,{type:`datetime-local`,value:j,onChange:e=>M(e.target.value),disabled:S})]}),(0,F.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,F.jsx)(`span`,{children:`End`}),(0,F.jsx)(`input`,{type:`datetime-local`,value:N,onChange:e=>P(e.target.value),disabled:S})]}),(0,F.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,F.jsx)(`span`,{children:`Location`}),(0,F.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),disabled:S})]}),(0,F.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,F.jsx)(`span`,{children:`Attendees`}),(0,F.jsxs)(`div`,{className:`cal-modal-attendees cal-modal-attendees-edit`,children:[D.attendees.length===0&&(0,F.jsx)(`div`,{className:`cal-attendee-empty`,children:`No attendees yet.`}),D.attendees.map((e,t)=>(0,F.jsxs)(`div`,{className:`cal-attendee-row cal-attendee-row-edit`,children:[(0,F.jsx)(le,{a:e}),(0,F.jsx)(`button`,{type:`button`,className:`cal-attendee-remove`,onClick:()=>q(e),disabled:S,"aria-label":`Remove ${e.name||e.email||`attendee`}`,children:(0,F.jsx)(d,{size:13})})]},ce(e,t)))]}),(0,F.jsxs)(`div`,{className:`cal-attendee-add`,children:[(0,F.jsx)(`input`,{type:`text`,placeholder:`Name`,value:B,onChange:e=>V(e.target.value),disabled:S,"aria-label":`Attendee name`}),(0,F.jsx)(`input`,{type:`email`,placeholder:`Email`,value:H,onChange:e=>U(e.target.value),disabled:S,"aria-label":`Attendee email`}),(0,F.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-attendee-add-btn`,onClick:K,disabled:S||!Z,"aria-label":`Add attendee`,children:S?(0,F.jsx)(n,{size:13,className:`spin`}):(0,F.jsx)(x,{size:13})})]})]}),(0,F.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,F.jsx)(`span`,{children:`Private note`}),(0,F.jsx)(`textarea`,{className:`cal-modal-textarea`,value:R,onChange:e=>z(e.target.value),disabled:S,rows:3,placeholder:`Only you and your team can see this.`})]})]}),T&&(0,F.jsx)(`div`,{className:`cal-modal-error`,children:T}),s&&(0,F.jsxs)(`div`,{className:`cal-modal-actions`,children:[!l&&!p&&!h&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>f(!0),disabled:S,children:[(0,F.jsx)(c,{size:14}),` Edit`]}),(0,F.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>m(!0),disabled:S,children:[(0,F.jsx)(u,{size:14}),` Delete`]}),(0,F.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-download`,onClick:()=>{D.attendees.length>0?g(!0):Y(!1)},disabled:S,children:[S?(0,F.jsx)(n,{size:14,className:`spin`}):(0,F.jsx)(r,{size:14}),` Download`]})]}),h&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Include attendees in the file?`}),(0,F.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:()=>Y(!0),disabled:S,children:[S?(0,F.jsx)(n,{size:14,className:`spin`}):null,` Yes`]}),(0,F.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>Y(!1),disabled:S,children:`No`}),(0,F.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>g(!1),disabled:S,children:`Cancel`})]}),l&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:G,disabled:S,children:[S?(0,F.jsx)(n,{size:14,className:`spin`}):null,` Save`]}),(0,F.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{f(!1),E(null)},disabled:S,children:`Cancel`})]}),p&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this meeting?`}),(0,F.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:J,disabled:S,children:[S?(0,F.jsx)(n,{size:14,className:`spin`}):null,` Delete`]}),(0,F.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>m(!1),disabled:S,children:`Cancel`})]})]})]})})}var $=`maxy-admin-session-key`,de=[`day`,`week`,`month`,`year`];function fe(e,t){switch(e){case`day`:return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`});case`week`:{let{from:e,to:n}=j(`week`,t),r=new Date(n.getTime()-1);return`${e.toLocaleDateString([],{day:`numeric`,month:`short`})} – ${r.toLocaleDateString([],{day:`numeric`,month:`short`,year:`numeric`})}`}case`month`:return t.toLocaleDateString([],{month:`long`,year:`numeric`});case`year`:return String(t.getFullYear())}}function pe(){let[e,t]=(0,C.useState)(null),[r,i]=(0,C.useState)(!1),[a,o]=(0,C.useState)(void 0),[s,c]=(0,C.useState)(null),[u,d]=(0,C.useState)(void 0),[f,h]=(0,C.useState)(null),[g,_]=(0,C.useState)(null);(0,C.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem($)}catch{}if(!n){i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&o(e.businessName),e.sessionId!==void 0&&c(e.sessionId??null),_(e.role??null),d(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let v=(0,C.useCallback)(()=>{try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},[]),[y,b]=(0,C.useState)(!1),x=(0,C.useCallback)(async()=>{b(!0);try{let e=await m();if(e){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`}return e}finally{b(!1)}},[]);return r?e?(0,F.jsx)(l,{cacheKey:e,surface:`calendar`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=calendar`);try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},children:(0,F.jsx)(p,{cacheKey:e,businessName:a,sessionId:s,onLogout:v,onDisconnect:x,disconnecting:y,userName:u,userAvatar:f,role:g,children:(0,F.jsx)(me,{cacheKey:e})})}):(0,F.jsx)(`div`,{className:`cal-page`,children:(0,F.jsxs)(`div`,{className:`cal-empty`,children:[(0,F.jsx)(`p`,{children:`You are not signed in.`}),(0,F.jsxs)(`p`,{children:[`Open the `,(0,F.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,F.jsx)(`div`,{className:`cal-page`,children:(0,F.jsxs)(`div`,{className:`cal-loading`,children:[(0,F.jsx)(n,{size:18,className:`spin`}),` Loading…`]})})}function me({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:r}=f({initialCacheKey:e,surface:`calendar`}),[a,o]=(0,C.useState)(`month`),[s,c]=(0,C.useState)(()=>new Date),[l,u]=(0,C.useState)([]),[d,p]=(0,C.useState)(!1),[m,_]=(0,C.useState)(null),[v,y]=(0,C.useState)(null),[b,x]=(0,C.useState)(null);(0,C.useEffect)(()=>{let e=!1;return t(`/api/admin/calendar/booking-link`).then(async t=>{if(e||!t.ok)return;let n=await t.json();typeof n.bookingDomain==`string`&&n.bookingDomain&&x(n.bookingDomain)}).catch(()=>{}),()=>{e=!0}},[t]),(0,C.useEffect)(()=>{let e=!1,{from:n,to:r}=j(a,s);return p(!0),_(null),t(`/api/admin/calendar/meetings?from=${encodeURIComponent(n.toISOString())}&to=${encodeURIComponent(r.toISOString())}`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();u(Array.isArray(n.meetings)?n.meetings:[])}).catch(t=>{e||(_(t instanceof Error?t.message:`Failed to load`),u([]))}).finally(()=>{e||p(!1)}),()=>{e=!0}},[a,s,r,t]);let ee=(0,C.useCallback)(()=>c(new Date),[]),S=(0,C.useCallback)(()=>c(e=>M(a,e,-1)),[a]),w=(0,C.useCallback)(()=>c(e=>M(a,e,1)),[a]),T=(0,C.useCallback)(e=>{c(e),o(`month`)},[]);(0,C.useEffect)(()=>{y(null)},[a,s]);let E=(0,C.useCallback)(e=>{u(t=>t.map(t=>t.meetingId===e.meetingId?e:t)),y(e)},[]),D=(0,C.useCallback)(e=>{u(t=>t.filter(t=>t.meetingId!==e)),y(null)},[]);return(0,F.jsxs)(`div`,{className:`cal-page`,children:[(0,F.jsxs)(`header`,{className:`cal-header`,children:[(0,F.jsxs)(`div`,{className:`cal-nav`,children:[(0,F.jsx)(`span`,{className:`cal-range-label`,children:fe(a,s)}),(0,F.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:S,"aria-label":`Previous`,children:(0,F.jsx)(h,{size:18})}),(0,F.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:w,"aria-label":`Next`,children:(0,F.jsx)(g,{size:18})}),(0,F.jsx)(`button`,{type:`button`,className:`cal-today-btn`,onClick:ee,children:`Today`}),d&&(0,F.jsx)(n,{size:16,className:`spin`})]}),(0,F.jsx)(`div`,{className:`cal-views`,children:de.map(e=>(0,F.jsx)(`button`,{type:`button`,className:`cal-view-btn${e===a?` cal-view-btn-active`:``}`,onClick:()=>o(e),children:e.charAt(0).toUpperCase()+e.slice(1)},e))}),b&&(0,F.jsxs)(`a`,{className:`cal-booking-link`,href:`https://${b}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,F.jsx)(i,{size:14}),` Booking page`]})]}),(0,F.jsxs)(`div`,{className:`cal-body`,children:[m&&(0,F.jsxs)(`div`,{className:`cal-error`,children:[`Could not load the calendar: `,m]}),a===`day`&&(0,F.jsx)(X,{anchor:s,meetings:l,onSelect:y}),a===`week`&&(0,F.jsx)(q,{anchor:s,meetings:l,onSelect:y}),a===`month`&&(0,F.jsx)(z,{anchor:s,meetings:l,onSelect:y}),a===`year`&&(0,F.jsx)(ne,{anchor:s,meetings:l,onPickMonth:T})]}),v&&(0,F.jsx)(ue,{meeting:v,adminFetch:t,onClose:()=>y(null),onSaved:E,onDeleted:D})]})}(0,S.createRoot)(document.getElementById(`root`)).render((0,F.jsx)(pe,{}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{B as e,L as t}from"./useSubAccountSwitcher-sPN6lobE.js";import"./useVoiceRecorder-DOFBQ2gP.js";import"./AdminShell-DR6AzflZ.js";import{n}from"./page-DPQS0X5M.js";import"./useCopyFeedback-CfbJc9iN.js";var r=e(),i=t();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{M as e}from"./useSubAccountSwitcher-sPN6lobE.js";var t=e(`chevron-down`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]);export{t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{M as e}from"./useSubAccountSwitcher-sPN6lobE.js";var t=e(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]);export{t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{M as e}from"./useSubAccountSwitcher-sPN6lobE.js";var t=e(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]);export{t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{B as e,L as t}from"./useSubAccountSwitcher-sPN6lobE.js";import"./useVoiceRecorder-DOFBQ2gP.js";import{t as n}from"./page-DsV3rID5.js";import"./graph-labels-7p-mVi9M.js";var r=e(),i=t();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-TPjIAO9U.js";import{B as t,H as n,L as r}from"./useSubAccountSwitcher-sPN6lobE.js";import{n as i,t as a}from"./AdminLoginScreens-Jw45pvb2.js";import"./useVoiceRecorder-DOFBQ2gP.js";import"./AdminShell-DR6AzflZ.js";import"./Checkbox-D7_S2EUI.js";import{t as o}from"./page-DPQS0X5M.js";import"./useCopyFeedback-CfbJc9iN.js";var s=t(),c=e(n(),1),l=r();function u(){let e=i(`operator`),t=(0,c.useRef)(null);return(0,c.useEffect)(()=>{e.appState!==`chat`&&t.current!==e.appState&&(t.current=e.appState,console.info(`[operator-ui] op=auth-gate state=${e.appState}`))},[e.appState]),e.appState===`chat`?(0,l.jsx)(o,{variant:`operator`,forceCanonicalSession:window.location.pathname!==`/chat`}):(0,l.jsx)(a,{auth:e})}(0,s.createRoot)(document.getElementById(`root`)).render((0,l.jsx)(u,{}));
|