@rubytech/create-maxy-code 0.1.310 → 0.1.312
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/lib/graph-style/dist/index.d.ts +5 -2
- package/payload/platform/lib/graph-style/dist/index.d.ts.map +1 -1
- package/payload/platform/lib/graph-style/dist/index.js +65 -2
- package/payload/platform/lib/graph-style/dist/index.js.map +1 -1
- package/payload/platform/lib/graph-style/src/__tests__/parity.test.ts +218 -0
- package/payload/platform/lib/graph-style/src/index.ts +53 -2
- package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +21 -3
- package/payload/platform/plugins/docs/references/admin-ui.md +20 -2
- package/payload/platform/scripts/check-no-esm-require.mjs +4 -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 +29 -0
- package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/index.js +16 -2
- package/payload/platform/services/claude-session-manager/dist/index.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts +10 -0
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.js +22 -2
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/reseat-ledger.d.ts +49 -0
- package/payload/platform/services/claude-session-manager/dist/reseat-ledger.d.ts.map +1 -0
- package/payload/platform/services/claude-session-manager/dist/reseat-ledger.js +148 -0
- package/payload/platform/services/claude-session-manager/dist/reseat-ledger.js.map +1 -0
- package/payload/platform/services/claude-session-manager/dist/scope-record.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/scope-record.js +35 -53
- package/payload/platform/services/claude-session-manager/dist/scope-record.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/sidecar-store.d.ts +45 -0
- package/payload/platform/services/claude-session-manager/dist/sidecar-store.d.ts.map +1 -0
- package/payload/platform/services/claude-session-manager/dist/sidecar-store.js +118 -0
- package/payload/platform/services/claude-session-manager/dist/sidecar-store.js.map +1 -0
- package/payload/server/public/assets/{AccessGate-BOqUU-za.js → AccessGate-Dh5A79FU.js} +1 -1
- package/payload/server/public/assets/{AdminLoginScreens-WvRuaNIg.js → AdminLoginScreens-B8s2TbT7.js} +1 -1
- package/payload/server/public/assets/AdminShell-Cu1zlb6L.js +1 -0
- package/payload/server/public/assets/{Checkbox-DjM6aYP_.js → Checkbox-B_sOAyv1.js} +1 -1
- package/payload/server/public/assets/OperatorConversations-hm0Gpu_Q.js +1 -0
- package/payload/server/public/assets/{admin-XbVTsU2q.js → admin-gZEndvJT.js} +1 -1
- package/payload/server/public/assets/{audio-attachment-mime-CVxjPN8V.js → audio-attachment-mime-B0b89VnH.js} +1 -1
- package/payload/server/public/assets/brand-BcNavK6q.css +1 -0
- package/payload/server/public/assets/{browser-Ct5Kwlmk.js → browser-BUlB5_MD.js} +1 -1
- package/payload/server/public/assets/chat-BnceaVl7.js +1 -0
- package/payload/server/public/assets/data-3Nl3P5wt.js +1 -0
- package/payload/server/public/assets/{graph-DWT1rhy9.js → graph-DMCKpW6P.js} +2 -2
- package/payload/server/public/assets/graph-labels-AZLGoVy8.js +1 -0
- package/payload/server/public/assets/operator-BF4F7k23.js +1 -0
- package/payload/server/public/assets/page-DQUEst1o.js +1 -0
- package/payload/server/public/assets/{public-owWW-MIA.js → public-G_-UI9nB.js} +1 -1
- package/payload/server/public/assets/{public-next-ClQwtyeC.js → public-next-C8_nExQB.js} +1 -1
- package/payload/server/public/assets/{useSelectionMode-BZsJuUm-.js → useSelectionMode-Bf6Rt-sl.js} +1 -1
- package/payload/server/public/browser.html +6 -6
- package/payload/server/public/chat.html +8 -8
- package/payload/server/public/data.html +5 -5
- package/payload/server/public/graph.html +8 -8
- package/payload/server/public/index.html +8 -8
- package/payload/server/public/operator.html +10 -10
- package/payload/server/public/public-next.html +9 -9
- package/payload/server/public/public.html +7 -7
- package/payload/server/server.js +1007 -458
- package/payload/server/public/assets/AdminShell-DHv6_SZ4.js +0 -1
- package/payload/server/public/assets/OperatorConversations-CDY0jUMb.js +0 -1
- package/payload/server/public/assets/brand-N-Hi3IPA.css +0 -1
- package/payload/server/public/assets/chat-CEde1CLX.js +0 -1
- package/payload/server/public/assets/data-TZOmA1Qg.js +0 -1
- package/payload/server/public/assets/graph-labels-OBadNo54.js +0 -1
- package/payload/server/public/assets/operator-BpzQ9Ezb.js +0 -1
- package/payload/server/public/assets/page-Dts8u8MD.js +0 -1
- /package/payload/server/public/assets/{brand-zL3tAdql.js → brand-BQ_u9UdS.js} +0 -0
|
@@ -11,71 +11,53 @@
|
|
|
11
11
|
// is the same dir boot-seed already scans for pid files; the pid-file name
|
|
12
12
|
// regex (`^[0-9]+\.json$`) never matches a `<uuid>.scope.json`, so there is no
|
|
13
13
|
// collision.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
//
|
|
15
|
+
// Task 902 — the file mechanics (path, atomic write, scan, clear) live in the
|
|
16
|
+
// shared `sidecar-store` helper; this module owns only the record shape and the
|
|
17
|
+
// `[scope-record]` log lines.
|
|
18
|
+
import { createSidecarStore } from './sidecar-store.js';
|
|
19
|
+
const store = createSidecarStore({
|
|
20
|
+
suffix: '.scope.json',
|
|
21
|
+
validate: (raw) => {
|
|
22
|
+
if (!raw || typeof raw !== 'object')
|
|
23
|
+
return null;
|
|
24
|
+
const sid = raw.sessionId;
|
|
25
|
+
const tok = raw.scopeUnitToken;
|
|
26
|
+
if (typeof sid === 'string' && sid.length > 0 && typeof tok === 'string' && tok.length > 0) {
|
|
27
|
+
return { sessionId: sid, scopeUnitToken: tok };
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
17
32
|
export function scopeRecordPath(sessionsDir, sessionId) {
|
|
18
|
-
return
|
|
33
|
+
return store.pathFor(sessionsDir, sessionId);
|
|
19
34
|
}
|
|
20
35
|
export function writeScopeRecord(sessionsDir, sessionId, scopeUnitToken, logger) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const tmp = `${path}.tmp.${process.pid}`;
|
|
24
|
-
const body = JSON.stringify({ sessionId, scopeUnitToken });
|
|
25
|
-
try {
|
|
26
|
-
writeFileSync(tmp, body, 'utf8');
|
|
27
|
-
renameSync(tmp, path);
|
|
36
|
+
const res = store.write(sessionsDir, sessionId, { sessionId, scopeUnitToken });
|
|
37
|
+
if (res.ok) {
|
|
28
38
|
logger(`[scope-record] write sessionId=${sessionId.slice(0, 8)} unitToken=${scopeUnitToken}`);
|
|
29
39
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (existsSync(tmp))
|
|
33
|
-
unlinkSync(tmp);
|
|
34
|
-
}
|
|
35
|
-
catch { /* best-effort */ }
|
|
40
|
+
else {
|
|
41
|
+
const err = res.error;
|
|
36
42
|
logger(`[scope-record] write-failed sessionId=${sessionId.slice(0, 8)} err=${err instanceof Error ? err.message : String(err)}`);
|
|
37
43
|
}
|
|
38
44
|
}
|
|
39
45
|
export function readAllScopeRecords(sessionsDir, logger) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
const out = [];
|
|
48
|
-
for (const entry of entries) {
|
|
49
|
-
if (!entry.isFile() || !SCOPE_FILE_RE.test(entry.name))
|
|
50
|
-
continue;
|
|
51
|
-
let parsed;
|
|
52
|
-
try {
|
|
53
|
-
parsed = JSON.parse(readFileSync(join(sessionsDir, entry.name), 'utf8'));
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
logger(`[scope-record] parse-failed file=${entry.name}`);
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
if (!parsed || typeof parsed !== 'object')
|
|
60
|
-
continue;
|
|
61
|
-
const sid = parsed.sessionId;
|
|
62
|
-
const tok = parsed.scopeUnitToken;
|
|
63
|
-
if (typeof sid === 'string' && sid.length > 0 && typeof tok === 'string' && tok.length > 0) {
|
|
64
|
-
out.push({ sessionId: sid, scopeUnitToken: tok });
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return out;
|
|
46
|
+
// Only JSON-unreadable files log; a parsed-but-wrong-shape file is skipped
|
|
47
|
+
// silently, matching the pre-902 inline scan.
|
|
48
|
+
return store.readAll(sessionsDir, (name, reason) => {
|
|
49
|
+
if (reason === 'unreadable')
|
|
50
|
+
logger(`[scope-record] parse-failed file=${name}`);
|
|
51
|
+
});
|
|
68
52
|
}
|
|
69
53
|
export function removeScopeRecord(sessionsDir, sessionId, logger) {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
unlinkSync(path);
|
|
74
|
-
logger(`[scope-record] remove sessionId=${sessionId.slice(0, 8)}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
54
|
+
const res = store.clear(sessionsDir, sessionId);
|
|
55
|
+
if (!res.ok) {
|
|
56
|
+
const err = res.error;
|
|
78
57
|
logger(`[scope-record] remove-failed sessionId=${sessionId.slice(0, 8)} err=${err instanceof Error ? err.message : String(err)}`);
|
|
79
58
|
}
|
|
59
|
+
else if (res.removed) {
|
|
60
|
+
logger(`[scope-record] remove sessionId=${sessionId.slice(0, 8)}`);
|
|
61
|
+
}
|
|
80
62
|
}
|
|
81
63
|
//# sourceMappingURL=scope-record.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope-record.js","sourceRoot":"","sources":["../src/scope-record.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,gFAAgF;AAChF,2EAA2E;AAC3E,yEAAyE;AACzE,4EAA4E;AAC5E,EAAE;AACF,+EAA+E;AAC/E,2EAA2E;AAC3E,+EAA+E;AAC/E,aAAa;
|
|
1
|
+
{"version":3,"file":"scope-record.js","sourceRoot":"","sources":["../src/scope-record.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,gFAAgF;AAChF,2EAA2E;AAC3E,yEAAyE;AACzE,4EAA4E;AAC5E,EAAE;AACF,+EAA+E;AAC/E,2EAA2E;AAC3E,+EAA+E;AAC/E,aAAa;AACb,EAAE;AACF,8EAA8E;AAC9E,gFAAgF;AAChF,8BAA8B;AAE9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AASvD,MAAM,KAAK,GAAG,kBAAkB,CAAc;IAC5C,MAAM,EAAE,aAAa;IACrB,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE;QAChB,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAA;QAChD,MAAM,GAAG,GAAI,GAA+B,CAAC,SAAS,CAAA;QACtD,MAAM,GAAG,GAAI,GAAoC,CAAC,cAAc,CAAA;QAChE,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3F,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,EAAE,CAAA;QAChD,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAC,CAAA;AAEF,MAAM,UAAU,eAAe,CAAC,WAAmB,EAAE,SAAiB;IACpE,OAAO,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC,CAAA;AAC9C,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,WAAmB,EACnB,SAAiB,EACjB,cAAsB,EACtB,MAAc;IAEd,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC,CAAA;IAC9E,IAAI,GAAG,CAAC,EAAE,EAAE,CAAC;QACX,MAAM,CAAC,kCAAkC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,cAAc,cAAc,EAAE,CAAC,CAAA;IAC/F,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAA;QACrB,MAAM,CAAC,yCAAyC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAClI,CAAC;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,WAAmB,EAAE,MAAc;IACrE,2EAA2E;IAC3E,8CAA8C;IAC9C,OAAO,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE;QACjD,IAAI,MAAM,KAAK,YAAY;YAAE,MAAM,CAAC,oCAAoC,IAAI,EAAE,CAAC,CAAA;IACjF,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,WAAmB,EAAE,SAAiB,EAAE,MAAc;IACtF,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,SAAS,CAAC,CAAA;IAC/C,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAA;QACrB,MAAM,CAAC,0CAA0C,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACnI,CAAC;SAAM,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;QACvB,MAAM,CAAC,mCAAmC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAA;IACpE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Why `readAll` skipped a file that matched the suffix.
|
|
2
|
+
* `'unreadable'` — the file could not be read or did not parse as JSON.
|
|
3
|
+
* `'invalid'` — it parsed but failed the store's `validate`. */
|
|
4
|
+
export type SidecarSkipReason = 'unreadable' | 'invalid';
|
|
5
|
+
export type WriteResult = {
|
|
6
|
+
ok: true;
|
|
7
|
+
} | {
|
|
8
|
+
ok: false;
|
|
9
|
+
error: unknown;
|
|
10
|
+
};
|
|
11
|
+
export type ClearResult = {
|
|
12
|
+
ok: true;
|
|
13
|
+
removed: boolean;
|
|
14
|
+
} | {
|
|
15
|
+
ok: false;
|
|
16
|
+
error: unknown;
|
|
17
|
+
};
|
|
18
|
+
export interface SidecarStore<T> {
|
|
19
|
+
/** `<sessionsDir>/<id><suffix>`. */
|
|
20
|
+
pathFor(sessionsDir: string, id: string): string;
|
|
21
|
+
/** Atomic write of `record` as JSON (no indentation): create the dir, write a
|
|
22
|
+
* `<path>.tmp.<pid>` sibling, then rename it onto the canonical path. On
|
|
23
|
+
* failure the tmp file is removed best-effort and the caught error is
|
|
24
|
+
* returned rather than thrown — the caller owns the success/failure log. */
|
|
25
|
+
write(sessionsDir: string, id: string, record: T): WriteResult;
|
|
26
|
+
/** Read + parse + validate one record. Null when the file is absent,
|
|
27
|
+
* unreadable, not JSON, or fails `validate`. */
|
|
28
|
+
read(sessionsDir: string, id: string): T | null;
|
|
29
|
+
/** Every valid record in `sessionsDir`. Files not matching the suffix are
|
|
30
|
+
* ignored. A matching file that is unreadable/not-JSON fires
|
|
31
|
+
* `onSkip(name, 'unreadable')`; one that parses but fails `validate` fires
|
|
32
|
+
* `onSkip(name, 'invalid')`. A missing directory yields `[]`. */
|
|
33
|
+
readAll(sessionsDir: string, onSkip?: (fileName: string, reason: SidecarSkipReason) => void): T[];
|
|
34
|
+
/** `existsSync` + `unlink`. `{ ok: true, removed: false }` when the file was
|
|
35
|
+
* already absent; `{ ok: false, error }` when the unlink throws. */
|
|
36
|
+
clear(sessionsDir: string, id: string): ClearResult;
|
|
37
|
+
}
|
|
38
|
+
export declare function createSidecarStore<T>(config: {
|
|
39
|
+
/** Filename suffix including the dot(s), e.g. `'.scope.json'`. */
|
|
40
|
+
suffix: string;
|
|
41
|
+
/** Parse-validate one decoded JSON value into a record, or null if it does
|
|
42
|
+
* not match the store's shape. */
|
|
43
|
+
validate: (raw: unknown) => T | null;
|
|
44
|
+
}): SidecarStore<T>;
|
|
45
|
+
//# sourceMappingURL=sidecar-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sidecar-store.d.ts","sourceRoot":"","sources":["../src/sidecar-store.ts"],"names":[],"mappings":"AAgBA;;oEAEoE;AACpE,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG,SAAS,CAAA;AAExD,MAAM,MAAM,WAAW,GAAG;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAA;AACtE,MAAM,MAAM,WAAW,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAA;AAExF,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,oCAAoC;IACpC,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IAChD;;;iFAG6E;IAC7E,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,WAAW,CAAA;IAC9D;qDACiD;IACjD,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAAA;IAC/C;;;sEAGkE;IAClE,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,KAAK,IAAI,GAAG,CAAC,EAAE,CAAA;IACjG;yEACqE;IACrE,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,WAAW,CAAA;CACpD;AAMD,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE;IAC5C,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAA;IACd;uCACmC;IACnC,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,CAAC,GAAG,IAAI,CAAA;CACrC,GAAG,YAAY,CAAC,CAAC,CAAC,CA8FlB"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Task 902 — the one per-session sidecar store that scope-record and
|
|
2
|
+
// reseat-ledger both build on. Each store keeps a `<sessionsDir>/<id><suffix>`
|
|
3
|
+
// JSON file and shares the same mechanics: a path builder, an atomic
|
|
4
|
+
// tmp-write + rename (best-effort tmp cleanup on failure), a suffix-matched
|
|
5
|
+
// directory scan, and an `existsSync` + `unlink` clear. Before this helper the
|
|
6
|
+
// two stores were near-verbatim copies that had already begun to drift in how
|
|
7
|
+
// they scanned the directory; collapsing them puts any future fix to
|
|
8
|
+
// partial-write handling or tmp-file cleanup in one place.
|
|
9
|
+
//
|
|
10
|
+
// The helper does NO logging. It returns results, and each store's thin
|
|
11
|
+
// wrapper owns its own log lines — the two stores log with different prefixes
|
|
12
|
+
// and different per-record detail, so unifying the messages here would change
|
|
13
|
+
// operator-greppable output. The wrappers keep their exact strings.
|
|
14
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
function escapeRegExp(s) {
|
|
17
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
18
|
+
}
|
|
19
|
+
export function createSidecarStore(config) {
|
|
20
|
+
const { suffix, validate } = config;
|
|
21
|
+
const suffixRe = new RegExp(`${escapeRegExp(suffix)}$`);
|
|
22
|
+
function pathFor(sessionsDir, id) {
|
|
23
|
+
return join(sessionsDir, `${id}${suffix}`);
|
|
24
|
+
}
|
|
25
|
+
function write(sessionsDir, id, record) {
|
|
26
|
+
mkdirSync(sessionsDir, { recursive: true });
|
|
27
|
+
const path = pathFor(sessionsDir, id);
|
|
28
|
+
const tmp = `${path}.tmp.${process.pid}`;
|
|
29
|
+
try {
|
|
30
|
+
writeFileSync(tmp, JSON.stringify(record), 'utf8');
|
|
31
|
+
renameSync(tmp, path);
|
|
32
|
+
return { ok: true };
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
try {
|
|
36
|
+
if (existsSync(tmp))
|
|
37
|
+
unlinkSync(tmp);
|
|
38
|
+
}
|
|
39
|
+
catch { /* best-effort */ }
|
|
40
|
+
return { ok: false, error };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function readFileAt(path) {
|
|
44
|
+
let raw;
|
|
45
|
+
try {
|
|
46
|
+
raw = readFileSync(path, 'utf8');
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
return validate(JSON.parse(raw));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function read(sessionsDir, id) {
|
|
59
|
+
return readFileAt(pathFor(sessionsDir, id));
|
|
60
|
+
}
|
|
61
|
+
function readAll(sessionsDir, onSkip) {
|
|
62
|
+
let names;
|
|
63
|
+
try {
|
|
64
|
+
// `withFileTypes` + `isFile` so a sub-directory whose name happens to
|
|
65
|
+
// match the suffix is ignored before any read is attempted — never read
|
|
66
|
+
// as a record, never reported via onSkip.
|
|
67
|
+
names = readdirSync(sessionsDir, { withFileTypes: true })
|
|
68
|
+
.filter((entry) => entry.isFile())
|
|
69
|
+
.map((entry) => entry.name);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
const out = [];
|
|
75
|
+
for (const name of names) {
|
|
76
|
+
if (!suffixRe.test(name))
|
|
77
|
+
continue;
|
|
78
|
+
const path = join(sessionsDir, name);
|
|
79
|
+
let raw;
|
|
80
|
+
try {
|
|
81
|
+
raw = readFileSync(path, 'utf8');
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
onSkip?.(name, 'unreadable');
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
let parsed;
|
|
88
|
+
try {
|
|
89
|
+
parsed = JSON.parse(raw);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
onSkip?.(name, 'unreadable');
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const record = validate(parsed);
|
|
96
|
+
if (record)
|
|
97
|
+
out.push(record);
|
|
98
|
+
else
|
|
99
|
+
onSkip?.(name, 'invalid');
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
function clear(sessionsDir, id) {
|
|
104
|
+
const path = pathFor(sessionsDir, id);
|
|
105
|
+
try {
|
|
106
|
+
if (existsSync(path)) {
|
|
107
|
+
unlinkSync(path);
|
|
108
|
+
return { ok: true, removed: true };
|
|
109
|
+
}
|
|
110
|
+
return { ok: true, removed: false };
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
return { ok: false, error };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return { pathFor, write, read, readAll, clear };
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=sidecar-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sidecar-store.js","sourceRoot":"","sources":["../src/sidecar-store.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,+EAA+E;AAC/E,qEAAqE;AACrE,4EAA4E;AAC5E,+EAA+E;AAC/E,8EAA8E;AAC9E,qEAAqE;AACrE,2DAA2D;AAC3D,EAAE;AACF,wEAAwE;AACxE,8EAA8E;AAC9E,8EAA8E;AAC9E,oEAAoE;AACpE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACjH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AA+BhC,SAAS,YAAY,CAAC,CAAS;IAC7B,OAAO,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAA;AACjD,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAI,MAMrC;IACC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IACnC,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAEvD,SAAS,OAAO,CAAC,WAAmB,EAAE,EAAU;QAC9C,OAAO,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;IAC5C,CAAC;IAED,SAAS,KAAK,CAAC,WAAmB,EAAE,EAAU,EAAE,MAAS;QACvD,SAAS,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;QACrC,MAAM,GAAG,GAAG,GAAG,IAAI,QAAQ,OAAO,CAAC,GAAG,EAAE,CAAA;QACxC,IAAI,CAAC;YACH,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAA;YAClD,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;YACrB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAA;QACrB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC;gBAAC,IAAI,UAAU,CAAC,GAAG,CAAC;oBAAE,UAAU,CAAC,GAAG,CAAC,CAAA;YAAC,CAAC;YAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC;YACxE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;QAC7B,CAAC;IACH,CAAC;IAED,SAAS,UAAU,CAAC,IAAY;QAC9B,IAAI,GAAW,CAAA;QACf,IAAI,CAAC;YACH,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAClC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAA;QACb,CAAC;QACD,IAAI,CAAC;YACH,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;QAClC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IAED,SAAS,IAAI,CAAC,WAAmB,EAAE,EAAU;QAC3C,OAAO,UAAU,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAA;IAC7C,CAAC;IAED,SAAS,OAAO,CACd,WAAmB,EACnB,MAA8D;QAE9D,IAAI,KAAe,CAAA;QACnB,IAAI,CAAC;YACH,sEAAsE;YACtE,wEAAwE;YACxE,0CAA0C;YAC1C,KAAK,GAAG,WAAW,CAAC,WAAW,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;iBACtD,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;iBACjC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAA;QACX,CAAC;QACD,MAAM,GAAG,GAAQ,EAAE,CAAA;QACnB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;gBAAE,SAAQ;YAClC,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;YACpC,IAAI,GAAW,CAAA;YACf,IAAI,CAAC;gBACH,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;YAClC,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;gBAC5B,SAAQ;YACV,CAAC;YACD,IAAI,MAAe,CAAA;YACnB,IAAI,CAAC;gBACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAC1B,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;gBAC5B,SAAQ;YACV,CAAC;YACD,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAA;YAC/B,IAAI,MAAM;gBAAE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;;gBACvB,MAAM,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;QAChC,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,SAAS,KAAK,CAAC,WAAmB,EAAE,EAAU;QAC5C,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;QACrC,IAAI,CAAC;YACH,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrB,UAAU,CAAC,IAAI,CAAC,CAAA;gBAChB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;YACpC,CAAC;YACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;QAC7B,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;AACjD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-CAM3fms7.js";import{o as t,u as n}from"./brand-
|
|
1
|
+
import{o as e}from"./chunk-CAM3fms7.js";import{o as t,u as n}from"./brand-BQ_u9UdS.js";import{r}from"./useSelectionMode-Bf6Rt-sl.js";var i=`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,audio/ogg,audio/opus,audio/mp4,audio/mpeg,audio/webm,audio/wav,.opus,.ogg,.m4a,.mp3,.wav,.webm`,a=new Set(i.split(`,`).filter(e=>!e.startsWith(`.`))),o=50*1024*1024,s=typeof window<`u`&&/^(localhost|127\.0\.0\.1|[a-z0-9-]+\.local)(:|$)/.test(window.location.hostname);function c(){let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function l(){let e=window.location.pathname;if(e.startsWith(`/g/`))return;let t=e.match(/^\/([a-z][a-z0-9-]{2,49})$/);return t?t[1]:void 0}function u(){let e=window.location.pathname.match(/^\/g\/([a-z0-9][a-z0-9-]{0,49})$/);return e?e[1]:void 0}var d=e(n(),1);function f(){let[e,t]=(0,d.useState)(null),[n,r]=(0,d.useState)(null),[i,a]=(0,d.useState)(`loading`),[o,f]=(0,d.useState)(``),[p,m]=(0,d.useState)(null),[h,g]=(0,d.useState)(null),[_,v]=(0,d.useState)(!1),[y,b]=(0,d.useState)(null),x=(0,d.useMemo)(()=>l(),[]),S=(0,d.useMemo)(()=>u(),[]),[C,w]=(0,d.useState)(null),T=(0,d.useRef)(x||``),E=(0,d.useRef)(null),D=(0,d.useRef)(null),O=(0,d.useRef)(!1),k=(0,d.useRef)(null),[A,j]=(0,d.useState)(`request-link`),[M,N]=(0,d.useState)(null),P=(0,d.useRef)(null),F=(0,d.useRef)(null);(0,d.useEffect)(()=>{try{let e=sessionStorage.getItem(`maxy_session`);e&&(F.current=e)}catch{}},[]);let I=(0,d.useCallback)(e=>{E.current=e,t(e);try{sessionStorage.setItem(`maxy_session`,e)}catch{}a(`chat`)},[]),L=(0,d.useCallback)(()=>{E.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}t(null),a(`auth-required`),j(`request-link`)},[]),R=(0,d.useCallback)(async e=>{j(`verifying`);try{let t=T.current,n=await fetch(`/api/access/verify-token`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:e,agentSlug:t})});if(window.history.replaceState({},``,window.location.pathname),n.ok){let e=await n.json().catch(()=>({}));return e?.displayName&&N({displayName:e.displayName,contactValue:``,expiresAt:null,status:`active`}),!0}return j(`verify-failed`),!1}catch{return j(`verify-failed`),!1}},[]),z=(0,d.useCallback)(async()=>{if(E.current)return E.current;if(D.current)return D.current;let e=(async()=>{try{let e=F.current,n=await fetch(`/api/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({session_id:c(),...x?{agent:x}:{},...S?{group_slug:S}:{},...e?{session_key:e}:{}})});if(!n.ok){let e=await n.json().catch(()=>({error:``}));return s&&console.error(`[session] POST /api/session failed: ${n.status} ${n.statusText}`,e),n.status===404?r(e.error||`Agent not found`):n.status===503&&r(e.error||`Service unavailable`),null}let i=await n.json();if(i.auth_required){i.agent_id&&(T.current=i.agent_id),f(i.displayName||``),i.agentImage&&m(i.agentImage),i.agentImageShape&&g(i.agentImageShape),i.showAgentName&&v(i.showAgentName),i.branding&&b(i.branding),a(`auth-required`);let e=new URLSearchParams(window.location.search).get(`token`);return e?await R(e)&&window.location.reload():j(`request-link`),null}E.current=i.session_key,t(i.session_key),i.displayName&&f(i.displayName),i.agentImage&&m(i.agentImage),i.agentImageShape&&g(i.agentImageShape),i.showAgentName&&v(i.showAgentName),i.branding&&b(i.branding),a(`chat`),i.resumed&&i.messages&&(O.current=!0,k.current=i.messages),i.group&&w({groupSlug:i.groupSlug,groupName:i.groupName,participants:i.participants??[]});try{sessionStorage.setItem(`maxy_session`,i.session_key)}catch{}return i.session_key}catch(e){return s&&console.error(`[session] fetch /api/session threw:`,e),r(`Unable to connect. Please check your connection and try again.`),null}finally{D.current=null}})();return D.current=e,e},[x,S,R]);return{sessionId:e,cacheKeyRef:E,sessionError:n,pageState:i,setPageState:a,agentDisplayName:o,agentImage:p,agentImageShape:h,showAgentName:_,agentSlug:x,branding:y,resolvedSlugRef:T,ensureSession:z,startNewSession:(0,d.useCallback)(async()=>{E.current=null,D.current=null,F.current=null,O.current=!1,k.current=null,t(null),r(null);try{sessionStorage.removeItem(`maxy_session`)}catch{}await z()},[z]),enterChat:I,enterGate:L,resumedRef:O,resumeMessagesRef:k,gateState:A,setGateState:j,grantInfo:M,setGrantInfo:N,gateCacheKeyRef:P,groupContext:C,groupSlug:S}}var p=t();function m({gateState:e,setGateState:t,grantInfo:n,resolvedSlugRef:i}){let[a,o]=(0,d.useState)(``),[s,c]=(0,d.useState)(!1),[l,u]=(0,d.useState)(null);async function f(e){e.preventDefault();let n=a.trim().toLowerCase();if(!n){u(`Enter the email you were invited on.`);return}c(!0),u(null);try{let e=await fetch(`/api/access/request-magic-link`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({contactValue:n,agentSlug:i.current})});if(e.status===429){u((await e.json().catch(()=>({})))?.error||`Too many requests. Try again later.`);return}t(`request-sent`)}catch{u(`Could not reach the server. Check your connection and try again.`)}finally{c(!1)}}return(0,p.jsxs)(`div`,{className:`access-gate`,children:[e===`verifying`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`Verifying your link…`}),(0,p.jsx)(`p`,{children:`This takes a moment.`})]}),e===`verify-failed`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`That link did not work`}),(0,p.jsx)(`p`,{children:`It may have expired, already been used, or been for a different agent. You can request a fresh one below.`}),(0,p.jsx)(r,{onClick:()=>{t(`request-link`),u(null)},children:`Request a new link`})]}),e===`request-link`&&(0,p.jsxs)(`form`,{className:`access-gate-form`,onSubmit:f,children:[(0,p.jsx)(`h2`,{children:n?.displayName?`Welcome back, ${n.displayName}`:`Sign in`}),(0,p.jsx)(`p`,{children:`Enter the email you were invited on and we will send you a fresh link.`}),(0,p.jsx)(`label`,{htmlFor:`access-email`,children:`Email`}),(0,p.jsx)(`input`,{id:`access-email`,type:`email`,inputMode:`email`,autoComplete:`email`,value:a,onChange:e=>o(e.target.value),disabled:s}),l&&(0,p.jsx)(`p`,{className:`access-gate-error`,children:l}),(0,p.jsx)(r,{type:`submit`,disabled:s||!a.trim(),children:s?`Sending…`:`Send me a link`})]}),e===`request-sent`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`Check your email`}),(0,p.jsx)(`p`,{children:`If that address is on the invite list, a fresh link is on the way. It expires in 15 minutes.`}),(0,p.jsx)(r,{onClick:()=>{t(`request-link`),o(``),u(null)},children:`Try a different email`})]})]})}export{a,o as i,f as n,s as o,i as r,m as t};
|
package/payload/server/public/assets/{AdminLoginScreens-WvRuaNIg.js → AdminLoginScreens-B8s2TbT7.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-CAM3fms7.js";import{a as t,o as n,t as r,u as i}from"./brand-zL3tAdql.js";import{C as a,_ as o}from"./OperatorConversations-CDY0jUMb.js";import{i as s}from"./admin-types-D2qTXuCg.js";import{s as c}from"./AdminShell-DHv6_SZ4.js";import{r as l}from"./useSelectionMode-BZsJuUm-.js";import{t as u}from"./Checkbox-DjM6aYP_.js";var d=`admin-landing-redirected`,f=`/graph`;function p(e){return e.variant===`operator`?!1:e.appState===`chat`&&!e.alreadyRedirected}var m=e(i(),1);function h(e=`admin`){let[t,n]=(0,m.useState)(`loading`),[r,i]=(0,m.useState)(``),[o,l]=(0,m.useState)(``),[u,h]=(0,m.useState)(``),[g,_]=(0,m.useState)(!1),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),[S,C]=(0,m.useState)(!1),[w,T]=(0,m.useState)(!1),[E,D]=(0,m.useState)(null),[O,k]=(0,m.useState)(null),[A,j]=(0,m.useState)(void 0),[M,N]=(0,m.useState)(null),[P,F]=(0,m.useState)(void 0),[I,L]=(0,m.useState)(null),[ee,R]=(0,m.useState)(null),[z,B]=(0,m.useState)([]),[V,H]=(0,m.useState)(!1),[U,W]=(0,m.useState)(void 0),G=(0,m.useRef)(void 0),[K,q]=(0,m.useState)(!1);(0,m.useEffect)(()=>{typeof window>`u`||fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&q(!0)}).catch(()=>{})},[]);let J=(0,m.useRef)(null),Y=(0,m.useRef)(null);(0,m.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let t=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(t.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!t.ok)return!1;let r=await t.json();D(r.session_key),R(r.sessionId??null),j(r.businessName),N(r.role??null),F(r.userName===void 0?null:r.userName),L(r.avatar??null);let i=s(r.thinkingView);return G.current=i,W(i),n(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function t(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),t(r-1);console.error(`[admin] health check returned ${i.status} after retries`),n(`set-pin`);return}let a=await i.json();if(!a.pin_configured){n(`set-pin`);return}if(!a.claude_authenticated){n(`connect-claude`);return}if(await e())return;n(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),t(r-1);console.error(`[admin] health check failed:`,e),n(`set-pin`)}}t()},[]),(0,m.useEffect)(()=>{t===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&k(e)}).catch(()=>{})},[t]),(0,m.useEffect)(()=>{if(typeof window>`u`)return;let n=!1;try{n=sessionStorage.getItem(d)===`1`}catch{}if(p({appState:t,alreadyRedirected:n,variant:e})){try{sessionStorage.setItem(d,`1`)}catch{}console.info(`[admin-ui] landing-redirect target=${f}`),window.location.replace(f)}},[t,e]);let X=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(t!==`chat`)return;let e=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(e.ok){let t=await e.json();if(t.auth_status===`dead`||t.auth_status===`missing`){n(`connect-claude`);return}}}catch{}if(E)try{let e=await fetch(`/api/admin/session?session_key=${encodeURIComponent(E)}`);if(e.status!==401)return;let t=(await e.clone().json().catch(()=>null))?.code??`unknown-401`;if(t===`remote-auth-required`){a(`heartbeat`,`/api/admin/session`);return}console.warn(`[admin-auth] outcome=heartbeat-detected-expiry code=${t}`),X.current?.()}catch{}},300*1e3);return()=>clearInterval(e)},[t,E]),(0,m.useEffect)(()=>{t===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&n(`enter-pin`)}).catch(()=>{})},[t]);async function Z(e,t){y(!0);try{let r=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...t?{accountId:t}:{}})});if(!r.ok){h((await r.json().catch(()=>({}))).error||`Invalid PIN`);return}let a=await r.json();if(a.accounts&&!a.session_key){console.log(`[admin] account picker shown: userId=${a.userId} accountCount=${a.accounts.length}`),B(a.accounts),n(`account-picker`);return}D(a.session_key),R(a.sessionId??null),j(a.businessName),N(a.role??null),F(a.userName===void 0?null:a.userName),L(a.avatar??null);let o=s(a.thinkingView);if(G.current=o,W(o),t)try{sessionStorage.setItem(`maxy-account-id`,t)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,a.session_key)}catch{}i(``),n(`chat`)}catch(e){console.error(`[admin] connection error:`,e),h(`Could not connect.`)}finally{y(!1),H(!1)}}let Q=(0,m.useCallback)(async e=>{if(e.preventDefault(),v)return;h(``);let t=o.trim();if(!t){h(`Please enter your name.`);return}if(r.length<4){h(`PIN must be at least 4 characters.`);return}let a=r;y(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:a,name:t})});if(!e.ok){let t=await e.json().catch(()=>({}));if(e.status===409){console.log(`[admin] PIN already configured — re-checking health`);try{let e=await fetch(`/api/health`);if(e.ok){let r=await e.json();r.pin_configured&&r.claude_authenticated?n(`enter-pin`):r.pin_configured?n(`connect-claude`):h(t.error||`Failed to set PIN.`)}else n(`enter-pin`)}catch{n(`enter-pin`)}return}h(t.error||`Failed to set PIN.`);return}let r=await fetch(`/api/health`);if((r.ok?await r.json():null)?.claude_authenticated){await Z(a);return}i(``),n(`connect-claude`)}catch(e){console.error(`[admin] connection error:`,e),h(`Could not connect.`)}finally{y(!1)}},[r,v,o]),te=(0,m.useCallback)(async e=>{e.preventDefault(),h(``),await Z(r)},[r]),ne=(0,m.useCallback)(async()=>{T(!0);try{if(!await c())return console.warn(`[admin-ui] claude-disconnect not verified — credentials may persist; staying put`),!1;D(null),N(null),F(void 0),L(null);try{sessionStorage.removeItem(`maxy-admin-session-key`),sessionStorage.removeItem(`maxy-account-id`),sessionStorage.removeItem(d)}catch{}return n(`connect-claude`),!0}finally{T(!1)}},[]),$=(0,m.useCallback)(()=>{D(null),N(null),F(void 0),L(null);try{sessionStorage.removeItem(`maxy-admin-session-key`),sessionStorage.removeItem(`maxy-account-id`),sessionStorage.removeItem(d)}catch{}i(``),h(``),n(`enter-pin`)},[]);return(0,m.useEffect)(()=>{X.current=$},[$]),{appState:t,setAppState:n,pin:r,setPin:i,operatorName:o,setOperatorName:l,pinError:u,setPinError:h,showPin:g,setShowPin:_,pinLoading:v,authPolling:b,setAuthPolling:x,authLoading:S,setAuthLoading:C,disconnecting:w,cacheKey:E,setCacheKey:D,claudeInfo:O,setClaudeInfo:k,businessName:A,role:M,userName:P,userAvatar:I,sessionId:ee,setSessionId:R,accounts:z,accountPickerLoading:V,expandAll:U,setExpandAll:W,expandAllDefaultRef:G,remoteAuthEnabled:K,pinInputRef:J,setPinFormRef:Y,handleSetPin:Q,handleLogin:te,handleAccountSelect:(0,m.useCallback)(async e=>{H(!0),h(``),await Z(r,e)},[r]),handleDisconnect:ne,handleLogout:$,handleChangePin:(0,m.useCallback)(async()=>{if(!r){h(`Enter your current PIN first.`);return}y(!0),h(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:r})});if(!e.ok){h((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}i(``),h(``),n(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),h(e instanceof Error?e.message:String(e))}finally{y(!1)}},[r])}}var g=n();function _({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,m.useRef)([]);function s(e,r){r.key===`Backspace`?(r.preventDefault(),t[e]?n(t.slice(0,e)+t.slice(e+1)):e>0&&(n(t.slice(0,e-1)+t.slice(e)),o.current[e-1]?.focus())):r.key===`ArrowLeft`&&e>0?o.current[e-1]?.focus():r.key===`ArrowRight`&&e<5?o.current[e+1]?.focus():r.key===`Enter`&&(r.preventDefault(),r.currentTarget.form?.requestSubmit())}function c(e,i){let a=i.nativeEvent.data;if(!a||!/^\d$/.test(a))return;let s=t.split(``);for(s[e]=a;s.length<e;)s.push(``);let c=s.join(``).replace(/\D/g,``).slice(0,6);n(c),c.length===6?r?.(c):e<5&&o.current[e+1]?.focus()}function l(e){e.preventDefault();let t=e.clipboardData.getData(`text`).replace(/\D/g,``).slice(0,6);t&&(n(t),t.length===6?r?.(t):o.current[t.length]?.focus())}return(0,g.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,g.jsx)(`input`,{ref:t=>{o.current[r]=t,r===0&&e&&(e.current=t)},type:`text`,inputMode:`numeric`,className:`pin-box${t[r]?` pin-box-filled`:``}`,value:t[r]?i?t[r]:`•`:``,onKeyDown:e=>s(r,e),onInput:e=>c(r,e),onPaste:l,onFocus:e=>e.target.select(),autoFocus:a&&r===0,autoComplete:`off`,maxLength:1,"aria-label":`PIN digit ${r+1}`},r))})}function v(e){let{pin:n,setPin:i,showPin:a,setShowPin:o,pinLoading:s,pinError:c,pinInputRef:d,setPinFormRef:f,onSubmit:p,operatorName:m,setOperatorName:h}=e;return(0,g.jsx)(`div`,{className:`connect-page`,children:(0,g.jsxs)(`div`,{className:`connect-content`,children:[(0,g.jsx)(`img`,{src:t,alt:r.productName,className:`connect-logo connect-logo--maxy`}),!r.logoContainsName&&(0,g.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,r.productName]}),(0,g.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,r.productName,` who you are, then choose a PIN.`]}),(0,g.jsxs)(`form`,{ref:f,onSubmit:p,className:`connect-pin-form`,children:[(0,g.jsxs)(`div`,{className:`pin-input-row`,children:[(0,g.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:m,onChange:e=>h(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,g.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,g.jsxs)(`div`,{className:`pin-input-row`,children:[(0,g.jsx)(_,{inputRef:d,value:n,onChange:i,onComplete:()=>{},showPin:a}),(0,g.jsx)(l,{variant:`send`,type:`submit`,disabled:!n||!m.trim(),loading:s,"aria-label":`Set PIN`,children:(0,g.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,g.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,g.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,g.jsx)(u,{checked:a,onChange:()=>o(e=>!e),label:`Show PIN`})]}),c&&(0,g.jsx)(`p`,{className:`admin-pin-error`,children:c})]})})}function y(e){let{pin:n,setPin:i,showPin:a,setShowPin:o,pinLoading:s,pinError:c,pinInputRef:d,onSubmit:f,onChangePin:p,remoteAuthEnabled:m,onSignOutRemote:h}=e;return(0,g.jsxs)(`div`,{className:`connect-page`,children:[m&&h&&(0,g.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,g.jsxs)(`div`,{className:`connect-content`,children:[(0,g.jsx)(`img`,{src:t,alt:r.productName,className:`connect-logo connect-logo--maxy`}),!r.logoContainsName&&(0,g.jsx)(`h1`,{className:`connect-title`,children:r.productName}),(0,g.jsxs)(`form`,{onSubmit:f,className:`connect-pin-form`,children:[(0,g.jsxs)(`div`,{className:`pin-input-row`,children:[(0,g.jsx)(_,{inputRef:d,value:n,onChange:i,onComplete:()=>{},showPin:a,autoFocus:!0}),(0,g.jsx)(l,{variant:`send`,type:`submit`,disabled:!n,loading:s,children:(0,g.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,g.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,g.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,g.jsxs)(`div`,{className:`pin-options`,children:[(0,g.jsx)(u,{checked:a,onChange:()=>o(e=>!e),label:`Show PIN`}),(0,g.jsx)(l,{type:`button`,variant:`ghost`,onClick:p,children:`Change PIN`})]})]}),c&&(0,g.jsx)(`p`,{className:`admin-pin-error`,children:c})]})]})}function b(e){let{accounts:n,loading:i,error:a,onSelect:s}=e;return(0,g.jsx)(`div`,{className:`connect-page`,children:(0,g.jsxs)(`div`,{className:`connect-content`,children:[(0,g.jsx)(`img`,{src:t,alt:r.productName,className:`connect-logo connect-logo--maxy`}),!r.logoContainsName&&(0,g.jsx)(`h1`,{className:`connect-title`,children:r.productName}),(0,g.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,g.jsx)(`div`,{className:`account-picker-list`,children:n.map(e=>(0,g.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>s(e.accountId),disabled:i,type:`button`,children:[(0,g.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,g.jsx)(`span`,{className:`account-picker-role`,children:e.role}),i&&(0,g.jsx)(o,{className:`account-picker-spinner`,size:16})]},e.accountId))}),a&&(0,g.jsx)(`p`,{className:`admin-pin-error`,children:a})]})})}function x(e){let{authPolling:n,setAuthPolling:i,authLoading:a,setAuthLoading:o,pinError:s,setPinError:c,setAppState:u}=e,[d,f]=(0,m.useState)(!1),[p,h]=(0,m.useState)(!1);async function _(){h(!0),c(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`launch-browser`})})).json();e.launched?f(!0):e.error&&c(e.error)}catch(e){console.error(`[admin] browser launch error:`,e),c(`Could not launch browser.`)}h(!1)}async function v(){o(!0),c(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){i(!0),f(!0),o(!1);for(let e=0;e<120;e++)if(await new Promise(e=>setTimeout(e,2e3)),(await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`wait`})})).json()).authenticated){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),u(`enter-pin`);return}c(`Timed out waiting for sign-in. Try again.`),i(!1)}else e.error&&c(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),c(`Could not start auth flow.`)}o(!1)}async function y(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),i(!1),c(``)}return n||d?(0,g.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,g.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[n?(0,g.jsx)(`button`,{onClick:y,style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Cancel`,children:`✕`}):(0,g.jsx)(`button`,{onClick:()=>f(!1),style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Close browser`,children:`✕`}),(0,g.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,g.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,g.jsx)(`p`,{className:`chat-intro`,children:n?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!n&&(0,g.jsx)(`div`,{style:{marginTop:`12px`},children:(0,g.jsx)(l,{variant:`primary`,onClick:v,disabled:a,children:a?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,g.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,g.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),s&&(0,g.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:s})]}):(0,g.jsx)(`div`,{className:`connect-page`,children:(0,g.jsxs)(`div`,{className:`connect-content`,children:[(0,g.jsxs)(`div`,{className:`connect-logos`,children:[(0,g.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,g.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,g.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,g.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,g.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,g.jsx)(`img`,{src:t,alt:r.productName,className:`connect-logo connect-logo--maxy`}),!r.logoContainsName&&(0,g.jsx)(`span`,{className:`connect-logo-label`,children:r.productName})]})]}),(0,g.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,r.productName]}),(0,g.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,g.jsx)(l,{variant:`primary`,onClick:v,disabled:a,children:a?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,g.jsx)(`p`,{style:{marginTop:`6px`,fontSize:`11px`,color:`#999`,maxWidth:`300px`,textAlign:`center`,lineHeight:`1.4`},children:`First time? You may need to sign into your email and Anthropic account in the browser before connecting.`}),(0,g.jsx)(`button`,{onClick:_,disabled:p,style:{marginTop:`12px`,background:`none`,border:`none`,color:`var(--color-primary, #666)`,fontSize:`13px`,cursor:`pointer`,textDecoration:`underline`,textUnderlineOffset:`3px`},children:p?`Launching…`:`Open browser first`}),s&&(0,g.jsx)(`p`,{className:`admin-pin-error`,children:s})]})})}function S({auth:e}){return e.appState===`loading`?(0,g.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,g.jsx)(v,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`connect-claude`?(0,g.jsx)(x,{authPolling:e.authPolling,setAuthPolling:e.setAuthPolling,authLoading:e.authLoading,setAuthLoading:e.setAuthLoading,pinError:e.pinError,setPinError:e.setPinError,setAppState:e.setAppState}):e.appState===`enter-pin`?(0,g.jsx)(y,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,onSubmit:e.handleLogin,onChangePin:e.handleChangePin,remoteAuthEnabled:e.remoteAuthEnabled,onSignOutRemote:()=>{console.info(`[admin-ui] remote-auth sign-out → /__remote-auth/logout`),window.location.href=`/__remote-auth/logout`}}):e.appState===`account-picker`?(0,g.jsx)(b,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):null}export{h as n,S as t};
|
|
1
|
+
import{o as e}from"./chunk-CAM3fms7.js";import{a as t,o as n,t as r,u as i}from"./brand-BQ_u9UdS.js";import{v as a,w as o}from"./OperatorConversations-hm0Gpu_Q.js";import{i as s}from"./admin-types-D2qTXuCg.js";import{s as c}from"./AdminShell-Cu1zlb6L.js";import{r as l}from"./useSelectionMode-Bf6Rt-sl.js";import{t as u}from"./Checkbox-B_sOAyv1.js";var d=`admin-landing-redirected`,f=`/graph`;function p(e){return e.variant===`operator`?!1:e.appState===`chat`&&!e.alreadyRedirected}var m=e(i(),1);function h(e=`admin`){let[t,n]=(0,m.useState)(`loading`),[r,i]=(0,m.useState)(``),[a,l]=(0,m.useState)(``),[u,h]=(0,m.useState)(``),[g,_]=(0,m.useState)(!1),[v,y]=(0,m.useState)(!1),[b,x]=(0,m.useState)(!1),[S,C]=(0,m.useState)(!1),[w,T]=(0,m.useState)(!1),[E,D]=(0,m.useState)(null),[O,k]=(0,m.useState)(null),[A,j]=(0,m.useState)(void 0),[M,N]=(0,m.useState)(null),[P,F]=(0,m.useState)(void 0),[I,L]=(0,m.useState)(null),[ee,R]=(0,m.useState)(null),[z,B]=(0,m.useState)([]),[V,H]=(0,m.useState)(!1),[U,W]=(0,m.useState)(void 0),G=(0,m.useRef)(void 0),[K,q]=(0,m.useState)(!1);(0,m.useEffect)(()=>{typeof window>`u`||fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&q(!0)}).catch(()=>{})},[]);let J=(0,m.useRef)(null),Y=(0,m.useRef)(null);(0,m.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let t=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(t.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!t.ok)return!1;let r=await t.json();D(r.session_key),R(r.sessionId??null),j(r.businessName),N(r.role??null),F(r.userName===void 0?null:r.userName),L(r.avatar??null);let i=s(r.thinkingView);return G.current=i,W(i),n(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function t(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),t(r-1);console.error(`[admin] health check returned ${i.status} after retries`),n(`set-pin`);return}let a=await i.json();if(!a.pin_configured){n(`set-pin`);return}if(!a.claude_authenticated){n(`connect-claude`);return}if(await e())return;n(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),t(r-1);console.error(`[admin] health check failed:`,e),n(`set-pin`)}}t()},[]),(0,m.useEffect)(()=>{t===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&k(e)}).catch(()=>{})},[t]),(0,m.useEffect)(()=>{if(typeof window>`u`)return;let n=!1;try{n=sessionStorage.getItem(d)===`1`}catch{}if(p({appState:t,alreadyRedirected:n,variant:e})){try{sessionStorage.setItem(d,`1`)}catch{}console.info(`[admin-ui] landing-redirect target=${f}`),window.location.replace(f)}},[t,e]);let X=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(t!==`chat`)return;let e=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(e.ok){let t=await e.json();if(t.auth_status===`dead`||t.auth_status===`missing`){n(`connect-claude`);return}}}catch{}if(E)try{let e=await fetch(`/api/admin/session?session_key=${encodeURIComponent(E)}`);if(e.status!==401)return;let t=(await e.clone().json().catch(()=>null))?.code??`unknown-401`;if(t===`remote-auth-required`){o(`heartbeat`,`/api/admin/session`);return}console.warn(`[admin-auth] outcome=heartbeat-detected-expiry code=${t}`),X.current?.()}catch{}},300*1e3);return()=>clearInterval(e)},[t,E]),(0,m.useEffect)(()=>{t===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&n(`enter-pin`)}).catch(()=>{})},[t]);async function Z(e,t){y(!0);try{let r=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...t?{accountId:t}:{}})});if(!r.ok){h((await r.json().catch(()=>({}))).error||`Invalid PIN`);return}let a=await r.json();if(a.accounts&&!a.session_key){console.log(`[admin] account picker shown: userId=${a.userId} accountCount=${a.accounts.length}`),B(a.accounts),n(`account-picker`);return}D(a.session_key),R(a.sessionId??null),j(a.businessName),N(a.role??null),F(a.userName===void 0?null:a.userName),L(a.avatar??null);let o=s(a.thinkingView);if(G.current=o,W(o),t)try{sessionStorage.setItem(`maxy-account-id`,t)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,a.session_key)}catch{}i(``),n(`chat`)}catch(e){console.error(`[admin] connection error:`,e),h(`Could not connect.`)}finally{y(!1),H(!1)}}let Q=(0,m.useCallback)(async e=>{if(e.preventDefault(),v)return;h(``);let t=a.trim();if(!t){h(`Please enter your name.`);return}if(r.length<4){h(`PIN must be at least 4 characters.`);return}let o=r;y(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:o,name:t})});if(!e.ok){let t=await e.json().catch(()=>({}));if(e.status===409){console.log(`[admin] PIN already configured — re-checking health`);try{let e=await fetch(`/api/health`);if(e.ok){let r=await e.json();r.pin_configured&&r.claude_authenticated?n(`enter-pin`):r.pin_configured?n(`connect-claude`):h(t.error||`Failed to set PIN.`)}else n(`enter-pin`)}catch{n(`enter-pin`)}return}h(t.error||`Failed to set PIN.`);return}let r=await fetch(`/api/health`);if((r.ok?await r.json():null)?.claude_authenticated){await Z(o);return}i(``),n(`connect-claude`)}catch(e){console.error(`[admin] connection error:`,e),h(`Could not connect.`)}finally{y(!1)}},[r,v,a]),te=(0,m.useCallback)(async e=>{e.preventDefault(),h(``),await Z(r)},[r]),ne=(0,m.useCallback)(async()=>{T(!0);try{if(!await c())return console.warn(`[admin-ui] claude-disconnect not verified — credentials may persist; staying put`),!1;D(null),N(null),F(void 0),L(null);try{sessionStorage.removeItem(`maxy-admin-session-key`),sessionStorage.removeItem(`maxy-account-id`),sessionStorage.removeItem(d)}catch{}return n(`connect-claude`),!0}finally{T(!1)}},[]),$=(0,m.useCallback)(()=>{D(null),N(null),F(void 0),L(null);try{sessionStorage.removeItem(`maxy-admin-session-key`),sessionStorage.removeItem(`maxy-account-id`),sessionStorage.removeItem(d)}catch{}i(``),h(``),n(`enter-pin`)},[]);return(0,m.useEffect)(()=>{X.current=$},[$]),{appState:t,setAppState:n,pin:r,setPin:i,operatorName:a,setOperatorName:l,pinError:u,setPinError:h,showPin:g,setShowPin:_,pinLoading:v,authPolling:b,setAuthPolling:x,authLoading:S,setAuthLoading:C,disconnecting:w,cacheKey:E,setCacheKey:D,claudeInfo:O,setClaudeInfo:k,businessName:A,role:M,userName:P,userAvatar:I,sessionId:ee,setSessionId:R,accounts:z,accountPickerLoading:V,expandAll:U,setExpandAll:W,expandAllDefaultRef:G,remoteAuthEnabled:K,pinInputRef:J,setPinFormRef:Y,handleSetPin:Q,handleLogin:te,handleAccountSelect:(0,m.useCallback)(async e=>{H(!0),h(``),await Z(r,e)},[r]),handleDisconnect:ne,handleLogout:$,handleChangePin:(0,m.useCallback)(async()=>{if(!r){h(`Enter your current PIN first.`);return}y(!0),h(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:r})});if(!e.ok){h((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}i(``),h(``),n(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),h(e instanceof Error?e.message:String(e))}finally{y(!1)}},[r])}}var g=n();function _({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,m.useRef)([]);function s(e,r){r.key===`Backspace`?(r.preventDefault(),t[e]?n(t.slice(0,e)+t.slice(e+1)):e>0&&(n(t.slice(0,e-1)+t.slice(e)),o.current[e-1]?.focus())):r.key===`ArrowLeft`&&e>0?o.current[e-1]?.focus():r.key===`ArrowRight`&&e<5?o.current[e+1]?.focus():r.key===`Enter`&&(r.preventDefault(),r.currentTarget.form?.requestSubmit())}function c(e,i){let a=i.nativeEvent.data;if(!a||!/^\d$/.test(a))return;let s=t.split(``);for(s[e]=a;s.length<e;)s.push(``);let c=s.join(``).replace(/\D/g,``).slice(0,6);n(c),c.length===6?r?.(c):e<5&&o.current[e+1]?.focus()}function l(e){e.preventDefault();let t=e.clipboardData.getData(`text`).replace(/\D/g,``).slice(0,6);t&&(n(t),t.length===6?r?.(t):o.current[t.length]?.focus())}return(0,g.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,g.jsx)(`input`,{ref:t=>{o.current[r]=t,r===0&&e&&(e.current=t)},type:`text`,inputMode:`numeric`,className:`pin-box${t[r]?` pin-box-filled`:``}`,value:t[r]?i?t[r]:`•`:``,onKeyDown:e=>s(r,e),onInput:e=>c(r,e),onPaste:l,onFocus:e=>e.target.select(),autoFocus:a&&r===0,autoComplete:`off`,maxLength:1,"aria-label":`PIN digit ${r+1}`},r))})}function v(e){let{pin:n,setPin:i,showPin:a,setShowPin:o,pinLoading:s,pinError:c,pinInputRef:d,setPinFormRef:f,onSubmit:p,operatorName:m,setOperatorName:h}=e;return(0,g.jsx)(`div`,{className:`connect-page`,children:(0,g.jsxs)(`div`,{className:`connect-content`,children:[(0,g.jsx)(`img`,{src:t,alt:r.productName,className:`connect-logo connect-logo--maxy`}),!r.logoContainsName&&(0,g.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,r.productName]}),(0,g.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,r.productName,` who you are, then choose a PIN.`]}),(0,g.jsxs)(`form`,{ref:f,onSubmit:p,className:`connect-pin-form`,children:[(0,g.jsxs)(`div`,{className:`pin-input-row`,children:[(0,g.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:m,onChange:e=>h(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,g.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,g.jsxs)(`div`,{className:`pin-input-row`,children:[(0,g.jsx)(_,{inputRef:d,value:n,onChange:i,onComplete:()=>{},showPin:a}),(0,g.jsx)(l,{variant:`send`,type:`submit`,disabled:!n||!m.trim(),loading:s,"aria-label":`Set PIN`,children:(0,g.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,g.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,g.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,g.jsx)(u,{checked:a,onChange:()=>o(e=>!e),label:`Show PIN`})]}),c&&(0,g.jsx)(`p`,{className:`admin-pin-error`,children:c})]})})}function y(e){let{pin:n,setPin:i,showPin:a,setShowPin:o,pinLoading:s,pinError:c,pinInputRef:d,onSubmit:f,onChangePin:p,remoteAuthEnabled:m,onSignOutRemote:h}=e;return(0,g.jsxs)(`div`,{className:`connect-page`,children:[m&&h&&(0,g.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,g.jsxs)(`div`,{className:`connect-content`,children:[(0,g.jsx)(`img`,{src:t,alt:r.productName,className:`connect-logo connect-logo--maxy`}),!r.logoContainsName&&(0,g.jsx)(`h1`,{className:`connect-title`,children:r.productName}),(0,g.jsxs)(`form`,{onSubmit:f,className:`connect-pin-form`,children:[(0,g.jsxs)(`div`,{className:`pin-input-row`,children:[(0,g.jsx)(_,{inputRef:d,value:n,onChange:i,onComplete:()=>{},showPin:a,autoFocus:!0}),(0,g.jsx)(l,{variant:`send`,type:`submit`,disabled:!n,loading:s,children:(0,g.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,g.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,g.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,g.jsxs)(`div`,{className:`pin-options`,children:[(0,g.jsx)(u,{checked:a,onChange:()=>o(e=>!e),label:`Show PIN`}),(0,g.jsx)(l,{type:`button`,variant:`ghost`,onClick:p,children:`Change PIN`})]})]}),c&&(0,g.jsx)(`p`,{className:`admin-pin-error`,children:c})]})]})}function b(e){let{accounts:n,loading:i,error:o,onSelect:s}=e;return(0,g.jsx)(`div`,{className:`connect-page`,children:(0,g.jsxs)(`div`,{className:`connect-content`,children:[(0,g.jsx)(`img`,{src:t,alt:r.productName,className:`connect-logo connect-logo--maxy`}),!r.logoContainsName&&(0,g.jsx)(`h1`,{className:`connect-title`,children:r.productName}),(0,g.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,g.jsx)(`div`,{className:`account-picker-list`,children:n.map(e=>(0,g.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>s(e.accountId),disabled:i,type:`button`,children:[(0,g.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,g.jsx)(`span`,{className:`account-picker-role`,children:e.role}),i&&(0,g.jsx)(a,{className:`account-picker-spinner`,size:16})]},e.accountId))}),o&&(0,g.jsx)(`p`,{className:`admin-pin-error`,children:o})]})})}function x(e){let{authPolling:n,setAuthPolling:i,authLoading:a,setAuthLoading:o,pinError:s,setPinError:c,setAppState:u}=e,[d,f]=(0,m.useState)(!1),[p,h]=(0,m.useState)(!1);async function _(){h(!0),c(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`launch-browser`})})).json();e.launched?f(!0):e.error&&c(e.error)}catch(e){console.error(`[admin] browser launch error:`,e),c(`Could not launch browser.`)}h(!1)}async function v(){o(!0),c(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){i(!0),f(!0),o(!1);for(let e=0;e<120;e++)if(await new Promise(e=>setTimeout(e,2e3)),(await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`wait`})})).json()).authenticated){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),u(`enter-pin`);return}c(`Timed out waiting for sign-in. Try again.`),i(!1)}else e.error&&c(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),c(`Could not start auth flow.`)}o(!1)}async function y(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),i(!1),c(``)}return n||d?(0,g.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,g.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[n?(0,g.jsx)(`button`,{onClick:y,style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Cancel`,children:`✕`}):(0,g.jsx)(`button`,{onClick:()=>f(!1),style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Close browser`,children:`✕`}),(0,g.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,g.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,g.jsx)(`p`,{className:`chat-intro`,children:n?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!n&&(0,g.jsx)(`div`,{style:{marginTop:`12px`},children:(0,g.jsx)(l,{variant:`primary`,onClick:v,disabled:a,children:a?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,g.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,g.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),s&&(0,g.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:s})]}):(0,g.jsx)(`div`,{className:`connect-page`,children:(0,g.jsxs)(`div`,{className:`connect-content`,children:[(0,g.jsxs)(`div`,{className:`connect-logos`,children:[(0,g.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,g.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,g.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,g.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,g.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,g.jsx)(`img`,{src:t,alt:r.productName,className:`connect-logo connect-logo--maxy`}),!r.logoContainsName&&(0,g.jsx)(`span`,{className:`connect-logo-label`,children:r.productName})]})]}),(0,g.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,r.productName]}),(0,g.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,g.jsx)(l,{variant:`primary`,onClick:v,disabled:a,children:a?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,g.jsx)(`p`,{style:{marginTop:`6px`,fontSize:`11px`,color:`#999`,maxWidth:`300px`,textAlign:`center`,lineHeight:`1.4`},children:`First time? You may need to sign into your email and Anthropic account in the browser before connecting.`}),(0,g.jsx)(`button`,{onClick:_,disabled:p,style:{marginTop:`12px`,background:`none`,border:`none`,color:`var(--color-primary, #666)`,fontSize:`13px`,cursor:`pointer`,textDecoration:`underline`,textUnderlineOffset:`3px`},children:p?`Launching…`:`Open browser first`}),s&&(0,g.jsx)(`p`,{className:`admin-pin-error`,children:s})]})})}function S({auth:e}){return e.appState===`loading`?(0,g.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,g.jsx)(v,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`connect-claude`?(0,g.jsx)(x,{authPolling:e.authPolling,setAuthPolling:e.setAuthPolling,authLoading:e.authLoading,setAuthLoading:e.setAuthLoading,pinError:e.pinError,setPinError:e.setPinError,setAppState:e.setAppState}):e.appState===`enter-pin`?(0,g.jsx)(y,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,onSubmit:e.handleLogin,onChangePin:e.handleChangePin,remoteAuthEnabled:e.remoteAuthEnabled,onSignOutRemote:()=>{console.info(`[admin-ui] remote-auth sign-out → /__remote-auth/logout`),window.location.href=`/__remote-auth/logout`}}):e.appState===`account-picker`?(0,g.jsx)(b,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):null}export{h as n,S as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e}from"./chunk-CAM3fms7.js";import{c as t,o as n,s as r,t as i,u as a}from"./brand-BQ_u9UdS.js";import{_ as o,b as s,c,d as l,g as u,l as d,p as f,s as p,t as m,u as h,x as g}from"./OperatorConversations-hm0Gpu_Q.js";import{i as _,t as v}from"./useSelectionMode-Bf6Rt-sl.js";async function ee(){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 y=t(`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`}]]),b=t(`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`}]]),x=t(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),te=t(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),S=t(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),ne=t(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),C=t(`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`}]]),w=t(`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`}]]),T=t(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),re=t(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),E=t(`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`}]]),D=e(a(),1),O=n(),k=`maxy-shell-side-px`;function A(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function j(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-A());return Math.min(Math.max(e,248),n)}function M(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(k);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 j(t)}catch{}return 264}function N({targetSelector:e=`.platform`}){let t=(0,D.useRef)(null),[n,r]=(0,D.useState)(()=>M()),i=(0,D.useRef)(n);(0,D.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,D.useCallback)(()=>{r(e=>{let t=j(e);return t===e?e:t})},[]);(0,D.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(j(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(k,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=j(264);r(e);try{window.localStorage.removeItem(k)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,O.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}function ie({actions:e,disabled:t,collapsed:n}){let[r,i]=(0,D.useState)(!1),a=(0,D.useRef)(null);return(0,D.useEffect)(()=>{if(!r)return;let e=e=>{e.key===`Escape`&&i(!1)},t=e=>{a.current?.contains(e.target)||i(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`pointerdown`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`pointerdown`,t)}},[r]),(0,D.useEffect)(()=>{n||i(!1)},[n]),n?(0,O.jsxs)(`div`,{className:`conv-actions`,ref:a,children:[(0,O.jsx)(`button`,{type:`button`,className:`conv-action conv-actions-overflow`,onClick:()=>i(e=>!e),disabled:t,"aria-haspopup":`menu`,"aria-expanded":r,"aria-label":`Session actions`,title:`Session actions`,children:(0,O.jsx)(S,{size:12})}),r&&(0,O.jsx)(`div`,{className:`conv-actions-menu`,role:`menu`,children:e.map(e=>(0,O.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),i(!1)},children:[e.icon,(0,O.jsx)(`span`,{children:e.label})]},e.key))})]}):(0,O.jsx)(`div`,{className:`conv-actions`,children:e.map(e=>(0,O.jsx)(`button`,{type:`button`,className:e.danger?`conv-action conv-action-danger`:`conv-action`,onClick:e.onClick,disabled:t,"aria-busy":e.busy,"aria-label":e.label,title:e.title,children:e.icon},e.key))})}var ae=[`whatsapp`,`telegram`];function oe(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 P(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}var se=`auth-refresh-failed`;function ce({error:e,onClose:t}){if(!e)return null;let n=e.reason===se,r=n?`Claude sign-in expired`:`Session didn’t open`,i=n?`Your claude.ai login has expired. Re-authenticate to resume sessions.`:`The session did not bind within 60 seconds, so there is no live conversation to open.`;return(0,O.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,O.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,O.jsxs)(`div`,{className:`claude-info-header`,children:[(0,O.jsx)(`span`,{children:r}),(0,O.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,O.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,O.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,O.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function F(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:s}=e,[c,l]=(0,D.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,O.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,O.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,O.jsxs)(`div`,{className:`claude-info-header`,children:[(0,O.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,O.jsx)(`span`,{children:`Claude Code`}),(0,O.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,O.jsxs)(`div`,{className:`claude-info-section`,children:[(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(g||m||h>0)&&(0,O.jsxs)(`div`,{className:`claude-info-section`,children:[g&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,O.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:g})]}),m&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,O.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(m.utilization*100),`%`]})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:_(m.resetsAt)})]}),m.isUsingOverage&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),h>0&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,O.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,h<.01?h.toFixed(4):h.toFixed(2)]})]})]}),(0,O.jsxs)(`div`,{className:`claude-info-section`,children:[(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:f>0?`${f}%`:`—`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:p>0?P(p):`—`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:oe(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,O.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 v(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}var le=`https://claude.ai/code`,ue=200,de=[500,1e3,1500,2e3,2500,3e3,3e3];function fe(e,t,n){if(e&&n.target)return{kind:`navigate`,url:n.target};let r=n.slug??n.bridgeSessionId??null;if(e&&r)return{kind:`navigate`,url:`${le}/${r}`};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function pe(e){if(!e)return``;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function I(e){let{businessName:t,cacheKey:n,role:a,userName:l,userAvatar:m,onSelectProjects:v,onSelectPeople:ee,onSelectTasks:S,onSelectAgents:k,onCloseMobileDrawer:A,collapsed:j,selectedWhatsappId:M,onSelectWhatsappConversation:N,initialWhatsappSurface:oe=!1}=e,P=f(n),se=i.productName,F=typeof l==`string`?l:l===null?`name unavailable`:t||se,le=(F.trim().charAt(0)||`?`).toUpperCase(),[I,L]=(0,D.useState)(oe?`whatsapp`:`sessions`),[R,ge]=(0,D.useState)([]),[z,_e]=(0,D.useState)(!1),[B,ve]=(0,D.useState)(null),[V,ye]=(0,D.useState)(!1),[H,be]=(0,D.useState)(`file`),[U,W]=(0,D.useState)(null),[xe,G]=(0,D.useState)(null),[K,Se]=(0,D.useState)([]),[q,Ce]=(0,D.useState)(!1),[we,Te]=(0,D.useState)(null),[Ee,De]=(0,D.useState)(!1),[Oe,ke]=(0,D.useState)(!1),[Ae,je]=(0,D.useState)(!1),[Me,Ne]=(0,D.useState)(null),[Pe,Fe]=(0,D.useState)(new Set),[Ie,Le]=(0,D.useState)(new Set),[Re,ze]=(0,D.useState)(new Set),[Be,Ve]=(0,D.useState)(new Set),[He,J]=(0,D.useState)(null),[Ue,Y]=(0,D.useState)(``),[We,Ge]=(0,D.useState)(!1),[X,Ke]=(0,D.useState)(!1),qe=(0,D.useRef)(null),[Je,Ye]=(0,D.useState)(0);(0,D.useEffect)(()=>{let e=qe.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(e=>{let t=e[0]?.contentRect.width??0;Ye(e=>Math.abs(e-t)<1?e:t)});return t.observe(e),()=>t.disconnect()},[I]);let Xe=Je>0&&Je<280,[Ze,Qe]=(0,D.useState)([]),[$e,et]=(0,D.useState)(!1),[tt,nt]=(0,D.useState)(null),[Z,rt]=(0,D.useState)(`whatsapp`),it=(0,D.useCallback)(e=>{if(A(),!n){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=no-cache-key`),W({message:`Session not ready — try again`,failed:!0});return}if(!e.downloadPath){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=not-downloadable`),W({message:`${e.name} can’t be downloaded`,failed:!0});return}console.info(`[admin-ui] artefact-download id=${e.id} root=${e.downloadRoot??`data`} path=${e.downloadPath}`),p(n,e.downloadPath,e.downloadRoot??`data`),W({message:`Downloading ${e.name}`,failed:!1})},[n,A]);(0,D.useEffect)(()=>{if(!U)return;let e=setTimeout(()=>W(null),2500);return()=>clearTimeout(e)},[U]);let at=(0,D.useCallback)(async()=>{if(n){ye(!0),ve(null);try{let e=await P(`/api/admin/sidebar-artefacts`);if(!e.ok)throw Error(`status ${e.status}`);ge((await e.json()).artefacts??[]),_e(!0)}catch(e){let t=e instanceof Error?e.message:String(e);ve(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{ye(!1)}}},[n,P]),Q=(0,D.useCallback)(async()=>{if(!n)return null;De(!0),Te(null);try{let e=await P(`/api/admin/sidebar-sessions`);if(!e.ok)throw Error(`status ${e.status}`);let t=await e.json(),n=t.sessions??[];return Se(n),Ne(t.accountId??null),Ce(!0),n}catch(e){let t=e instanceof Error?e.message:String(e);return Te(`Failed to load sessions: ${t}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${t}`),null}finally{De(!1)}},[n,P]),ot=(0,D.useCallback)(async()=>{if(n){nt(null);try{let e=await P(`/api/whatsapp-reader/conversations`);if(!e.ok)throw Error(`status ${e.status}`);Qe((await e.json()).conversations??[]),et(!0)}catch(e){let t=e instanceof Error?e.message:String(e);nt(`Couldn't load conversations.`),console.error(`[admin-ui] channel-convos fetch failed: ${t}`)}}},[n,P]);(0,D.useEffect)(()=>{!n||q||Q()},[n,q,Q]),(0,D.useEffect)(()=>{if(!n)return;let e=null;return ot(),e=setInterval(()=>{ot()},me),()=>{e!==null&&clearInterval(e)}},[n,ot]);let st=(0,D.useMemo)(()=>{let e=new Map;for(let t of ae)e.set(t,[]);for(let t of Ze)e.get(t.channel)?.push(t);for(let t of ae)console.info(`[admin-ui] sidebar-nav surface=${t} count=${e.get(t).length}`);return e},[Ze]),ct={whatsapp:`WhatsApp`,telegram:`Telegram`,webchat:`Webchat`},lt=()=>{N(null),L(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${z?R.length:0} collapsed=${j}`),at()},$=1.5,ut=()=>{console.info(`[admin-ui] sidebar-refresh surface=artefacts`),at()},dt=()=>{N(null),L(`sessions`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${q?K.length:0} collapsed=${j}`),q||Q()},ft=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions`),Q()},pt=e=>{L(`whatsapp`),rt(e),console.info(`[admin-ui] sidebar-nav surface=${e} count=${st.get(e)?.length??0} collapsed=${j}`)},mt=(0,D.useCallback)(async e=>{if(Ie.has(e.sessionId))return;Le(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await P(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,name:e.title||e.sessionId})}),r=await n.json().catch(()=>({})),i=fe(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`?(A(),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}`),G(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}`),G({sessionId:e.sessionId,reason:r})}finally{Le(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[P,A,Ie]),ht=(0,D.useCallback)(async e=>{let t=e.slice(0,8);for(let n=1;n<=de.length;n++){await new Promise(e=>setTimeout(e,de[n-1]));let r=await Q();if(r&&r.some(t=>t.sessionId===e)){console.info(`[admin-ui] sidebar-new-session-converged sessionId=${t} via=retry attempts=${n}`);return}}console.error(`[admin-ui] sidebar-new-session-converge-timeout sessionId=${t}`)},[Q]),gt=(0,D.useCallback)(async()=>{if(X)return;Ke(!0);let e=window.open(``,`_blank`);try{let t=await P(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}),n=await t.json().catch(()=>({})),r=fe(t.ok,t.status,n);console.info(`[admin-ui] sidebar-new-session-spawned status=${t.status} outcome=${r.kind} slug=${n.slug??n.bridgeSessionId??`none`}`),r.kind===`navigate`?(e?e.location.href=r.url:window.open(r.url,`_blank`),n.sessionId?ht(n.sessionId):console.error(`[admin-ui] sidebar-new-session-converge-skipped reason=no-session-id`)):(e?.close(),console.error(`[admin-ui] sidebar-new-session-failed status=${t.status} reason=${r.reason}`),G(r))}catch(t){e?.close();let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-new-session-failed error=${n}`),G({sessionId:null,reason:n})}finally{Ke(!1)}},[P,X,ht]),_t=(0,D.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Pe.has(t.sessionId)){Fe(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await P(`/api/admin/session-delete`,{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-delete-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),W({message:`Delete failed: ${n.error??`status ${e.status}`}`,failed:!0});return}let n=await e.json();console.info(`[admin-ui] sidebar-session-delete sessionId=${t.sessionId} pidKilled=${n.pidKilled??`?`} deleted=${n.deleted??`?`}`),Se(e=>e.filter(e=>e.sessionId!==t.sessionId)),Q()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${t.sessionId} error=${n}`),W({message:`Delete failed: ${n}`,failed:!0})}finally{Fe(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[P,Pe,Q]),vt=(0,D.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Re.has(t.sessionId)){ze(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await P(`/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`}`),W({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}`),W({message:`Stop failed: ${n}`,failed:!0})}finally{ze(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[P,Re,Q]),yt=(0,D.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!Be.has(t.sessionId)){Ve(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await P(`/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`}`),W({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}`),W({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{Ve(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[P,Be,Q]),bt=(0,D.useCallback)(async e=>{let t=Ue.trim();if(!t){W({message:`Title can’t be empty`,failed:!0});return}if(t.length>ue){W({message:`Title too long (max ${ue})`,failed:!0});return}Ge(!0);try{let n=await P(`/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}`),W({message:`Rename failed: ${r}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=ok`),J(null),Y(``),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}`),W({message:`Rename failed: ${n}`,failed:!0})}finally{Ge(!1)}},[P,Ue,Q]);return(0,O.jsxs)(`aside`,{className:`side`,children:[(0,O.jsx)(`div`,{className:`side-new-session-row`,children:(0,O.jsxs)(`button`,{type:`button`,className:`side-new-session`,onClick:gt,disabled:X,"aria-busy":X,children:[(0,O.jsx)(T,{size:14}),(0,O.jsx)(`span`,{children:X?`Spawning…`:`New session`})]})}),(0,O.jsxs)(`nav`,{className:`side-nav`,children:[(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),ee(),A()},children:[(0,O.jsx)(E,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`People`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),k(),A()},children:[(0,O.jsx)(x,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Agents`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),v(),A()},children:[(0,O.jsx)(te,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Projects`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),S(),A()},children:[(0,O.jsx)(C,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row${I===`artefacts`?` active`:``}`,onClick:lt,children:[(0,O.jsx)(_,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row${I===`sessions`?` active`:``}`,onClick:dt,children:[(0,O.jsx)(ne,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,O.jsx)(`span`,{className:`kbd`})]}),$e&&ae.filter(e=>st.get(e).length>0).map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`nav-row${I===`whatsapp`&&Z===e?` active`:``}`,onClick:()=>pt(e),children:[(0,O.jsx)(d,{channel:e,size:16}),(0,O.jsx)(`span`,{className:`label`,children:ct[e]}),(0,O.jsx)(`span`,{className:`kbd`})]},e)),tt&&(0,O.jsx)(`div`,{className:`nav-row`,style:{color:`var(--text-tertiary)`,cursor:`default`},"aria-disabled":`true`,children:(0,O.jsx)(`span`,{className:`label`,children:tt})})]}),I===`artefacts`&&(0,O.jsxs)(`div`,{className:`side-list`,children:[(0,O.jsxs)(`div`,{className:`group-head`,children:[(0,O.jsx)(`span`,{children:`Artefacts`}),(0,O.jsxs)(`span`,{className:`group-head-meta`,children:[(0,O.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh artefacts`,"aria-label":`Refresh artefacts`,onClick:ut,disabled:V,children:(0,O.jsx)(u,{size:12,className:V?`spinning`:void 0})}),(0,O.jsx)(`span`,{children:V?`…`:String(R.length)})]})]}),B&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:B}),z&&!B&&R.length>0&&(()=>{let e=R.filter(e=>e.kind===`agent-template`).length,t=R.length-e;return(0,O.jsx)(`div`,{className:`artefact-filter-chips`,children:[{key:`all`,label:`All`,count:R.length},{key:`agent`,label:`Agents`,count:e},{key:`file`,label:`Files`,count:t}].map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`artefact-filter-chip${H===e.key?` active`:``}`,onClick:()=>be(e.key),disabled:e.count===0&&e.key!==`all`,children:[e.label,(0,O.jsx)(`span`,{className:`artefact-filter-chip-count`,children:e.count})]},e.key))})})(),z&&!B&&R.length===0&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),R.filter(e=>H===`all`?!0:H===`agent`?e.kind===`agent-template`:e.kind!==`agent-template`).map(e=>{let t=e.kind===`agent-template`,n=t?x:_,r=pe(e.updatedAt),i=e.downloadPath!==null;return(0,O.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>it(e),disabled:!i,style:i?void 0:{cursor:`default`},title:i?`Download ${e.name}`:`${e.name} can’t be downloaded`,children:[(0,O.jsx)(n,{size:14,className:`conv-icon`,"data-kind":t?`agent`:`file`,"aria-label":t?`agent template`:`file`}),(0,O.jsxs)(`span`,{className:`conv-stack`,children:[(0,O.jsx)(`span`,{className:`conv-name-line`,children:(0,O.jsx)(`span`,{className:`conv-name`,children:e.name})}),r&&(0,O.jsx)(`span`,{className:`conv-timestamp`,children:r})]}),i&&(0,O.jsx)(g,{size:12,className:`conv-rc-icon`,"aria-hidden":`true`})]},e.id)})]}),I===`sessions`&&(()=>{let e=K.filter(e=>Oe?!0:!e.isSubagent).filter(e=>Ae?!0:!e.archived),t=K.some(e=>e.isSubagent),n=K.some(e=>e.archived);return(0,O.jsxs)(`div`,{className:`side-list`,ref:qe,children:[(0,O.jsxs)(`div`,{className:`group-head`,children:[(0,O.jsx)(`span`,{children:`Sessions`}),(0,O.jsxs)(`span`,{className:`group-head-meta`,children:[(0,O.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:ft,disabled:Ee,children:(0,O.jsx)(u,{size:12,className:Ee?`spinning`:void 0})}),(0,O.jsx)(`span`,{children:Ee?`…`:String(e.length)})]})]}),Me&&(0,O.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,O.jsx)(`code`,{children:Me})}),(t||n)&&(0,O.jsxs)(`div`,{className:`artefact-filter-chips`,children:[t&&(0,O.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${Oe?` active`:``}`,onClick:()=>ke(e=>!e),title:Oe?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),n&&(0,O.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${Ae?` active`:``}`,onClick:()=>je(e=>!e),title:Ae?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),we&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:we}),q&&!we&&e.length===0&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=pe(e.startedAt),n=Ie.has(e.sessionId),i=Pe.has(e.sessionId),a=Re.has(e.sessionId),c=Be.has(e.sessionId),l=n||i||a||c,u=[{key:`open`,label:`Resume session ${e.title} in claude.ai/code`,title:`Resume in a fresh local Remote Control PTY`,icon:(0,O.jsx)(s,{size:12}),busy:n,onClick:()=>{mt(e)}},{key:`message`,label:`Open session ${e.title} in admin webchat`,title:`Open in admin webchat (/chat) — sending resumes this session`,icon:(0,O.jsx)(w,{size:12}),onClick:()=>{window.location.assign(`/chat?session=${e.sessionId}`)}},...e.live?[{key:`stop`,label:`Stop session ${e.title}`,title:`Stop session process (keeps the conversation, can resume later)`,icon:(0,O.jsx)(re,{size:12}),busy:a,onClick:t=>{vt(t,e)}}]:[],e.archived?{key:`unarchive`,label:`Unarchive session ${e.title}`,title:`Unarchive (move back to the active list)`,icon:(0,O.jsx)(y,{size:12}),busy:c,onClick:t=>{yt(t,e,`unarchive`)}}:{key:`archive`,label:`Archive session ${e.title}`,title:`Archive (hide from the list, keeps the conversation resumable)`,icon:(0,O.jsx)(b,{size:12}),busy:c,onClick:t=>{yt(t,e,`archive`)}},{key:`rename`,label:`Rename session ${e.title}`,title:`Rename this session`,icon:(0,O.jsx)(o,{size:12}),busy:We&&He===e.sessionId,onClick:t=>{t.stopPropagation(),J(e.sessionId),Y(e.personName??e.title)}},{key:`delete`,label:`Delete session ${e.title}`,title:`Delete session (stops the process, removes the conversation)`,icon:(0,O.jsx)(r,{size:12}),danger:!0,busy:i,onClick:t=>{_t(t,e)}}];return(0,O.jsxs)(`div`,{className:`conv conv-with-actions`,children:[(0,O.jsxs)(`div`,{className:`conv-main-static`,children:[(0,O.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"aria-label":e.live?`live session`:`ended session`}),(0,O.jsxs)(`span`,{className:`conv-stack`,children:[(0,O.jsxs)(`span`,{className:`conv-name-line`,children:[e.channel&&(0,O.jsx)(h,{channel:e.channel,size:13}),He===e.sessionId?(0,O.jsx)(`input`,{className:`conv-name conv-name-edit`,autoFocus:!0,value:Ue,disabled:We,"aria-label":`New title for session ${e.title}`,onChange:e=>Y(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),bt(e)):t.key===`Escape`&&(t.preventDefault(),J(null),Y(``))},onBlur:()=>{He===e.sessionId&&!We&&(J(null),Y(``))}}):(0,O.jsx)(`span`,{className:`conv-name`,title:e.personName??e.title,children:e.personName??e.title})]}),(0,O.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,O.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,O.jsxs)(`span`,{children:[` · `,t]})]})]})]}),(0,O.jsx)(ie,{actions:u,disabled:l,collapsed:Xe})]},e.sessionId)})]})})(),I===`whatsapp`&&(0,O.jsxs)(`div`,{className:`side-list`,children:[(0,O.jsxs)(`div`,{className:`group-head`,children:[(0,O.jsx)(`span`,{children:ct[Z]}),(0,O.jsxs)(`span`,{className:`group-head-meta`,children:[(0,O.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh conversations`,"aria-label":`Refresh conversations`,onClick:()=>{ot()},children:(0,O.jsx)(u,{size:12})}),(0,O.jsx)(`span`,{children:String(st.get(Z).length)})]})]}),st.get(Z).map(e=>{let t=pe(e.lastMessageAt);return(0,O.jsxs)(`button`,{type:`button`,className:`conv${M===e.sessionId?` active`:``}`,onClick:()=>{N(e),A()},title:e.title,children:[(0,O.jsx)(d,{channel:e.channel,size:14}),(0,O.jsxs)(`span`,{className:`conv-stack`,children:[(0,O.jsxs)(`span`,{className:`conv-name-line`,children:[(0,O.jsx)(`span`,{className:`conv-name`,children:c(e)}),e.role===`public`&&(0,O.jsx)(`span`,{className:`conv-tag conv-tag-public`,children:`Public`})]}),t&&(0,O.jsx)(`span`,{className:`conv-timestamp`,children:t})]})]},e.sessionId)})]}),(0,O.jsx)(he,{}),(0,O.jsxs)(`div`,{className:`side-foot`,children:[(0,O.jsx)(`div`,{className:`avatar`,children:m?(0,O.jsx)(`img`,{src:m,alt:F}):le}),(0,O.jsxs)(`div`,{className:`who`,children:[(0,O.jsx)(`span`,{className:`name`,children:F}),(0,O.jsx)(`span`,{className:`role`,children:a??`operator`})]})]}),U&&(0,O.jsx)(`div`,{className:`copy-toast${U.failed?` copy-toast-failed`:``}`,role:`status`,children:U.message}),(0,O.jsx)(ce,{error:xe,onClose:()=>G(null)})]})}var L=5e3,me=3e4;function he(){let[e,t]=(0,D.useState)(null);if((0,D.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()},L))}function a(){n!==null&&(clearInterval(n),n=null)}function o(){document.hidden?a():i()}return document.hidden||i(),document.addEventListener(`visibilitychange`,o),()=>{e=!0,a(),document.removeEventListener(`visibilitychange`,o)}},[]),!e||e.platform===`darwin`)return null;let n=e.cpuPct,r=e.memUsedPct,i=n!==null&&n>=.9,a=n!==null&&n>=.98,o=r!==null&&r>=.9,s=r!==null&&r>=.98,c=i||o,l=a||s,u=e=>e===null?`—`:`${Math.round(e*100)}%`,d=e=>{if(e===null)return{width:`0%`,background:`var(--text-tertiary)`};let t=Math.min(1,Math.max(0,e)),n=Math.round(140*(1-t));return{width:`${Math.round(t*100)}%`,background:`hsl(${n}, 65%, 45%)`}},f=[`system-stats`];return c&&f.push(`system-stats--warn`),l&&f.push(`system-stats--crit`),(0,O.jsxs)(`div`,{className:f.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,O.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,O.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),(0,O.jsx)(`div`,{className:`system-stats__bar`,children:(0,O.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(n)})})]}),(0,O.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,O.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]}),(0,O.jsx)(`div`,{className:`system-stats__bar`,children:(0,O.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(r)})})]})]})}var R=`admin-sidebar-collapsed`,ge=`admin-sidebar-drawer-open`;function z(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(R)===`1`}catch{return!1}}function _e(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(R,`1`):window.sessionStorage.removeItem(R)}catch{}}function B(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(ge)===`1`}catch{return!1}}function ve(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(ge,`1`):window.sessionStorage.removeItem(ge)}catch{}}var V=720;function ye(e,t){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?wa=${encodeURIComponent(t.sessionId)}&projectDir=${encodeURIComponent(t.projectDir)}`}}function H(e,t){if(e!==`/`)return null;let n=new URLSearchParams(t),r=n.get(`wa`),i=n.get(`projectDir`);return!r||!i?null:{sessionId:r,projectDir:i,title:``,senderId:null,startedAt:``,channel:`whatsapp`,role:`admin`,operatorName:null,whatsappName:null,lastMessageAt:null,modelGated:!1}}function be(e,t){return t===`operator`&&e===`chat`||e===`dashboard`?`/`:e===`data`?`/data`:e===`graph`?`/graph`:e===`chat`?`/chat`:`/browser`}function U(e){let{cacheKey:t,businessName:n,variant:r=`admin`,onLogout:i,onDisconnect:a,disconnecting:o,userName:s,userAvatar:c,role:u,children:d,footer:f}=e,[p,h]=(0,D.useState)(()=>z()),[g,_]=(0,D.useState)(()=>B()),[v,ee]=(0,D.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: ${V}px)`).matches),[y,b]=(0,D.useState)(()=>typeof window>`u`?null:H(window.location.pathname,window.location.search)),[x]=(0,D.useState)(()=>y!==null);(0,D.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: ${V}px)`),t=e=>ee(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let te=(0,D.useCallback)(e=>{_e(e),h(e)},[]),S=(0,D.useCallback)(e=>{ve(e),_(e)},[]);(0,D.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} variant=${r} sidebar=${r===`operator`?`none`:`present`} collapsed=${p} drawer=${g}`)},[]),(0,D.useEffect)(()=>{typeof window>`u`||!y||(console.info(`[admin-ui] wa-hydrate route=/ sessionId=${y.sessionId.slice(0,8)}`),window.history.replaceState(null,``,`/`))},[]);let ne=(0,D.useCallback)(e=>{if(e===null){b(null);return}let t=typeof window<`u`?window.location.pathname:`/`,n=ye(t,e);console.info(`[admin-ui] wa-open route=${t} via=${n.via} sessionId=${e.sessionId.slice(0,8)}`),n.via===`in-place`?b(e):window.location.href=n.href},[]),C=v?g:!p,w=(0,D.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${V}px)`).matches){let e=g;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),S(!e)}else{let e=p;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),te(!e)}},[p,g,te,S]),T=(0,D.useCallback)(e=>{let t=be(e,r);console.info(`[admin-ui] header-menu-nav target=${e} dest=${t}`),window.location.href=t},[r]),[re,E]=(0,D.useState)(`chat`),[k,A]=(0,D.useState)([]);(0,D.useEffect)(()=>{if(r!==`operator`||!t)return;let e=!1;return fetch(`/api/whatsapp-reader/conversations?session_key=${encodeURIComponent(t)}`).then(e=>e.ok?e.json():{conversations:[]}).then(t=>{e||A(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[r,t]);let j=(0,D.useMemo)(()=>[...new Set(k.map(e=>e.channel))],[k]),M={collapsed:p,mobileDrawerOpen:g,sidebarOpen:C,onToggleSidebar:w,setMobileDrawerOpen:S,selectedWhatsapp:y,onClearWhatsapp:()=>b(null)};return r===`operator`?(0,O.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,O.jsx)(l,{businessName:n,variant:r,onNavigate:T,conversationsCount:k.length,conversationsChannels:j,onOpenConversations:()=>E(`conversations`),onToggleSidebar:w,sidebarOpen:C,onLogout:i,onDisconnect:a,disconnecting:o}),(0,O.jsx)(`div`,{className:`platform platform-operator`,children:re===`conversations`?(0,O.jsx)(m,{conversations:k,sessionKey:t??``,onBack:()=>E(`chat`)}):typeof d==`function`?d(M):d}),f]}):(0,O.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,O.jsx)(l,{businessName:n,variant:r,onNavigate:T,onToggleSidebar:w,sidebarOpen:C,onLogout:i,onDisconnect:a,disconnecting:o}),(0,O.jsxs)(`div`,{className:`platform${g?` menu-open`:``}${p?` sidebar-collapsed`:``}`,"data-artefact":`closed`,children:[(0,O.jsx)(I,{businessName:n,cacheKey:t,role:u??null,userName:s,userAvatar:c??null,onSelectProjects:()=>{window.location.href=`/graph?label=Project`},onSelectPeople:()=>{window.location.href=`/graph?label=Person`},onSelectTasks:()=>{window.location.href=`/graph?label=Task`},onSelectAgents:()=>{window.location.href=`/graph?label=Agent`},onCloseMobileDrawer:()=>S(!1),collapsed:p,mobileDrawerOpen:g,selectedWhatsappId:y?.sessionId??null,onSelectWhatsappConversation:ne,initialWhatsappSurface:x}),!v&&(0,O.jsx)(N,{}),typeof d==`function`?d(M):d]}),g&&(0,O.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>S(!1)}),f]})}export{C as a,T as i,F as n,x as o,E as r,ee as s,U as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./brand-
|
|
1
|
+
import{o as e}from"./brand-BQ_u9UdS.js";var t=e();function n({checked:e,onChange:n,label:r,disabled:i}){return(0,t.jsxs)(`label`,{className:`maxy-checkbox${i?` maxy-checkbox--disabled`:``}`,children:[(0,t.jsx)(`input`,{type:`checkbox`,checked:e,onChange:e=>n(e.target.checked),disabled:i}),(0,t.jsx)(`span`,{className:`maxy-checkbox__box`,children:`✱`}),r&&(0,t.jsx)(`span`,{className:`maxy-checkbox__label`,children:r})]})}export{n as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e}from"./chunk-CAM3fms7.js";import{c as t,i as n,o as r,s as i,t as a,u as o}from"./brand-BQ_u9UdS.js";var s=`maxy-admin-session`,c=typeof BroadcastChannel<`u`;function l(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`rotation`&&typeof t.newKey==`string`&&t.newKey.length>0&&(t.surface===`chat`||t.surface===`graph`||t.surface===`data`||t.surface===`sessions`)&&typeof t.ts==`number`}function u(e){if(!c)return()=>{};let t=new BroadcastChannel(s),n=t=>{if(!l(t.data)){console.warn(`[admin-session-broadcast] outcome=received-malformed payload=${JSON.stringify(t.data)}`);return}e(t.data)};return t.addEventListener(`message`,n),()=>{t.removeEventListener(`message`,n),t.close()}}var d=e(o(),1),f=`maxy-admin-session-key`;function p(e,t){return`${e}${e.includes(`?`)?`&`:`?`}session_key=${encodeURIComponent(t)}`}async function m(e){let t;try{t=await e.clone().json()}catch{return`parse-failed`}if(typeof t!=`object`||!t)return`unknown-401`;let n=t.code;return n===`session-missing`||n===`session-not-registered`||n===`session-expired-age`||n===`grant-expired`||n===`remote-auth-required`?n:`unknown-401`}var h=`maxy-remote-auth-reload-at`,g=6e4;function _(e,t){let n=0;try{n=Number(sessionStorage.getItem(h)??`0`)}catch{}let r=Date.now();if(Number.isFinite(n)&&r-n<g){console.warn(`[admin-auth] outcome=remote-auth-reload-suppressed surface=${e} path=${t}`);return}try{sessionStorage.setItem(h,String(r))}catch{}console.warn(`[admin-auth] outcome=remote-auth-expired-reload surface=${e} path=${t}`),window.location.reload()}function v(){try{return sessionStorage.getItem(f)}catch{return null}}function y(e){let{initialCacheKey:t,surface:n}=e,[r,i]=(0,d.useState)(t),a=(0,d.useRef)(t);(0,d.useEffect)(()=>{a.current=r},[r]),(0,d.useEffect)(()=>{t!==a.current&&(i(t),a.current=t,s(e=>e+1))},[t]);let[o,s]=(0,d.useState)(0);(0,d.useEffect)(()=>u(e=>{let t=a.current.slice(0,8),r=e.newKey.slice(0,8);e.newKey!==a.current&&(console.log(`[admin-session-broadcast] outcome=received oldKey=${t} newKey=${r} surface=${n} senderSurface=${e.surface}`),i(e.newKey),s(e=>e+1))}),[n]);let c=(0,d.useCallback)(()=>{try{sessionStorage.removeItem(f)}catch{}window.location.href=`/`},[]);return{adminFetch:(0,d.useCallback)(async(e,t)=>{let r=a.current,o=p(e,r),l=await fetch(o,t);if(l.status!==401)return l;let u=await m(l);if(u===`remote-auth-required`)return _(n,e),l;if(u===`session-missing`||u!==`session-not-registered`)return console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=${u} surface=${n} path=${e}`),c(),l;let d=v();if(!d||d===r)return console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=session-not-registered-no-fresh-key surface=${n} path=${e}`),c(),l;i(d),a.current=d,s(e=>e+1),console.log(`[useAdminFetch] outcome=retry-after-rotation oldKey=${r.slice(0,8)} newKey=${d.slice(0,8)} surface=${n} path=${e}`);let f=p(e,d),h=await fetch(f,t);if(h.status===401){if(await m(h)===`remote-auth-required`)return _(n,e),h;console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=second-401-after-retry surface=${n} path=${e}`),c()}return h},[c,n]),cacheKey:r,sessionRefetchNonce:o}}var b=t(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),x=t(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),ee=t(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),S=t(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),C=t(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),w=t(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),te=t(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),ne=t(`layout-dashboard`,[[`rect`,{width:`7`,height:`9`,x:`3`,y:`3`,rx:`1`,key:`10lvy0`}],[`rect`,{width:`7`,height:`5`,x:`14`,y:`3`,rx:`1`,key:`16une8`}],[`rect`,{width:`7`,height:`9`,x:`14`,y:`12`,rx:`1`,key:`1hutg5`}],[`rect`,{width:`7`,height:`5`,x:`3`,y:`16`,rx:`1`,key:`ldoo1y`}]]),T=t(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),re=t(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),ie=t(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),E=t(`message-circle`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}]]),ae=t(`messages-square`,[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]),oe=t(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),se=t(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),ce=t(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),D=t(`refresh-cw`,[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]),O=t(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),k=t(`triangle-alert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),le=t(`unplug`,[[`path`,{d:`m19 5 3-3`,key:`yk6iyv`}],[`path`,{d:`m2 22 3-3`,key:`19mgm9`}],[`path`,{d:`M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z`,key:`goz73y`}],[`path`,{d:`M7.5 13.5 10 11`,key:`7xgeeb`}],[`path`,{d:`M10.5 16.5 13 14`,key:`10btkg`}],[`path`,{d:`m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z`,key:`1snsnr`}]]),A=t(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),j=r(),M=(0,d.createContext)(null);function N({cacheKey:e,onSessionExpired:t,surface:n,children:r}){let i=(0,d.useCallback)(async(r,i)=>{if(!e)return fetch(r,i);let a=p(r,e),o=await fetch(a,i);if(o.status!==401)return o;let s=await m(o),c=e.slice(-8);if(s===`remote-auth-required`)return _(n,r),o;if(s===`session-not-registered`){let a=v();if(a&&a!==e){let e=p(r,a),o=await fetch(e,i);return o.status===401?await m(o)===`remote-auth-required`?(_(n,r),o):(console.warn(`[admin-auth] outcome=session-expired-redirect code=second-401-after-retry path=${r} cacheKey=${c} surface=${n}`),t({code:`second-401-after-retry`,path:r}),o):o}}return console.warn(`[admin-auth] outcome=session-expired-redirect code=${s} path=${r} cacheKey=${c} surface=${n}`),t({code:s,path:r}),o},[e,t,n]);return(0,j.jsx)(M.Provider,{value:i,children:r})}function P(){return(0,d.useContext)(M)}function F(e){let t=P();return(0,d.useMemo)(()=>t||(async(t,n)=>fetch(e?p(t,e):t,n)),[t,e])}function I(e){let{businessName:t,variant:r=`admin`,onNavigate:o,conversationsCount:s=0,conversationsChannels:c,onOpenConversations:l,onToggleSidebar:u,sidebarOpen:f,onLogout:p,onDisconnect:m,disconnecting:h}=e,[g,_]=(0,d.useState)(!1),v=(0,d.useRef)(null),y=(0,d.useRef)(null),x=F(null),[S,E]=(0,d.useState)(null),[ce,D]=(0,d.useState)(!1),[k,M]=(0,d.useState)(null),[N,P]=(0,d.useState)(null),[I,L]=(0,d.useState)(!1),[R,z]=(0,d.useState)(null),[B,V]=(0,d.useState)(null),[H,U]=(0,d.useState)(``);(0,d.useEffect)(()=>{U(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,d.useEffect)(()=>{if(!g)return;let e=e=>{v.current&&!v.current.contains(e.target)&&_(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]),(0,d.useEffect)(()=>{if(!g)return;let e=e=>{e.key===`Escape`&&_(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[g]),(0,d.useEffect)(()=>{g&&y.current?.focus()},[g]),(0,d.useEffect)(()=>{if(!g||r!==`admin`)return;let e=!1;return x(`/api/admin/version`).then(e=>e.json()).then(t=>{e||V(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[g,r,x]);let W=(0,d.useCallback)(()=>{_(e=>{let t=!e;return t&&console.info(`[admin-ui] header-menu-open`),t&&r===`operator`&&console.info(`[operator-ui] op=conversations-menu present=${s>0} channels=[${(c??[]).join(`,`)}] count=${s}`),t})},[r,s,c]),G=(0,d.useCallback)(e=>{_(!1),o(e)},[o]),K=(0,d.useCallback)(async()=>{if(S!==null){E(null),P(null);return}D(!0),M(null);try{let e=await x(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);E((await e.json()).agents??[])}catch(e){console.error(`[admin/agents] list failed:`,e),M(e instanceof Error?e.message:String(e)),E([])}finally{D(!1)}},[S,x]),q=(0,d.useCallback)(e=>{P(null),E(t=>t?.filter(t=>t.slug!==e)??null),x(`/api/admin/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(e=>console.error(`[admin/agents] delete failed:`,e))},[x]),J=(0,d.useCallback)(()=>{_(!1),p()},[p]),Y=(0,d.useCallback)(async()=>{z(null),await m()?(L(!1),_(!1)):z(`Disconnect failed — credentials still present. Try again.`)},[m]),X=t||a.productName;return(0,j.jsxs)(`header`,{className:`admin-header`,children:[r===`admin`?(0,j.jsx)(`button`,{type:`button`,className:`admin-sidebar-toggle`,"aria-label":f?`Hide sidebar`:`Show sidebar`,title:f?`Hide sidebar`:`Show sidebar`,"aria-expanded":f,onClick:u,children:f?(0,j.jsx)(oe,{size:20,strokeWidth:1.5}):(0,j.jsx)(se,{size:20,strokeWidth:1.5})}):(0,j.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,j.jsx)(`img`,{src:n,alt:``,className:`chat-logo`})}),r===`admin`?(0,j.jsxs)(`div`,{className:`chat-header-label`,children:[(0,j.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,j.jsx)(`img`,{src:n,alt:``,className:`chat-logo`})}),(0,j.jsx)(`h1`,{className:`chat-tagline`,children:X})]}):(0,j.jsx)(`h1`,{className:`chat-tagline`,children:X}),(0,j.jsxs)(`div`,{className:`chat-burger-wrap`,ref:v,children:[(0,j.jsx)(`button`,{type:`button`,className:`admin-burger`,onClick:W,"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":g,children:(0,j.jsx)(ie,{size:20})}),g&&(0,j.jsxs)(`div`,{className:`admin-menu${r===`operator`?` admin-menu-operator`:``}`,role:`menu`,children:[r===`admin`&&(0,j.jsxs)(`button`,{ref:y,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>G(`dashboard`),children:[(0,j.jsx)(ne,{size:14}),` Dashboard`]}),r===`operator`&&(0,j.jsxs)(`button`,{ref:y,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>G(`chat`),children:[(0,j.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`chat-menu-claude-icon`}),` Chat`]}),r===`operator`&&s>0&&(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>{_(!1),l?.()},children:[(0,j.jsx)(ae,{size:14}),` Conversations`]}),(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>G(`data`),children:[(0,j.jsx)(ee,{size:14}),` Data`]}),r===`admin`&&(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>G(`graph`),children:[(0,j.jsx)(O,{size:14}),` Graph`]}),r===`admin`&&(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>G(`browser`),children:[(0,j.jsx)(w,{size:14}),` Browser`]}),r===`admin`&&(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>G(`chat`),children:[(0,j.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`chat-menu-claude-icon`}),` Chat`]}),r===`admin`&&(0,j.jsx)(`div`,{className:`chat-menu-divider`}),r===`admin`&&(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:K,children:[(0,j.jsx)(C,{size:14}),` Public`,ce&&(0,j.jsx)(T,{size:12,className:`spin`})]}),r===`admin`&&S!==null&&(0,j.jsxs)(`div`,{className:`chat-menu-agents`,children:[k&&(0,j.jsx)(`span`,{className:`chat-menu-agent-error`,children:k}),S.length===0&&!k&&(0,j.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),S.map(e=>(0,j.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,j.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,j.jsxs)(`span`,{className:`agent-text`,children:[(0,j.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,j.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),N===e.slug?(0,j.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,j.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>q(e.slug),children:(0,j.jsx)(b,{size:12})}),(0,j.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>P(null),children:(0,j.jsx)(A,{size:12})})]}):(0,j.jsxs)(`span`,{className:`agent-actions`,children:[(0,j.jsx)(`a`,{href:`${H}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>_(!1),children:(0,j.jsx)(C,{size:12})}),(0,j.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>P(e.slug),children:(0,j.jsx)(i,{size:12})})]})]},e.slug))]}),r===`admin`&&(0,j.jsx)(`div`,{className:`chat-menu-divider`}),r===`admin`&&(0,j.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,j.jsx)(te,{size:14}),(0,j.jsxs)(`span`,{className:`version-installed`,children:[B?`v${B.installed}`:`…`,B&&!B.updateAvailable&&(0,j.jsx)(`span`,{className:`version-uptodate-dot`}),B?.updateAvailable&&(0,j.jsx)(`span`,{className:`version-update-dot`})]})]}),r===`admin`&&(I?(0,j.jsxs)(`div`,{className:`chat-menu-item chat-menu-disconnect`,children:[(0,j.jsx)(`span`,{children:`Disconnect Claude account?`}),(0,j.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,j.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm disconnect`,disabled:h,onClick:Y,children:h?(0,j.jsx)(T,{size:12,className:`spin`}):(0,j.jsx)(b,{size:12})}),(0,j.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel disconnect`,disabled:h,onClick:()=>{L(!1),z(null)},children:(0,j.jsx)(A,{size:12})})]})]}):(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item chat-menu-disconnect`,role:`menuitem`,onClick:()=>{z(null),L(!0)},children:[(0,j.jsx)(le,{size:14}),` Disconnect Claude account`]})),r===`admin`&&R&&(0,j.jsx)(`span`,{className:`chat-menu-agent-error`,children:R}),(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:J,children:[(0,j.jsx)(re,{size:14}),` Log out`]})]})]})]})}var L={whatsapp:{fill:`#25D366`,label:`WhatsApp`,path:`M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.71.306 1.263.489 1.694.625.712.227 1.36.195 1.872.118.571-.085 1.758-.719 2.006-1.413.247-.694.247-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.885-9.885 9.885M20.52 3.449C18.24 1.245 15.24.044 12.045.044 5.463.044.103 5.404.1 11.99c0 2.096.546 4.142 1.588 5.945L0 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.585 0 11.946-5.36 11.949-11.946 0-3.193-1.24-6.19-3.495-8.445`},telegram:{fill:`#229ED9`,label:`Telegram`,path:`M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z`}};function R({channel:e,size:t=16}){let n=L[e];return(0,j.jsx)(`svg`,{width:t,height:t,viewBox:`0 0 24 24`,fill:n.fill,role:`img`,"aria-label":n.label,className:`channel-icon`,children:(0,j.jsx)(`path`,{d:n.path})})}var z={whatsapp:`whatsapp`,telegram:`telegram`};function B({channel:e,size:t=13}){let n=z[e];return n?(0,j.jsx)(R,{channel:n,size:t}):e===`webchat`?(0,j.jsx)(w,{size:t,className:`channel-icon`,role:`img`,"aria-label":`Web chat`,style:{color:`var(--text-tertiary)`}}):(0,j.jsx)(E,{size:t,className:`channel-icon`,role:`img`,"aria-label":e,style:{color:`var(--text-tertiary)`}})}var V=[`whatsapp`,`telegram`,`webchat`],H={whatsapp:`WhatsApp`,telegram:`Telegram`,webchat:`Webchat`};function U(e){return V.map(t=>({channel:t,label:H[t],rows:e.filter(e=>e.channel===t)})).filter(e=>e.rows.length>0)}function W(e){let t=e.operatorName??e.whatsappName;return t?e.senderId?`${t} ${e.senderId}`:t:e.senderId??e.title}function G(e,t,n=`data`){let r=`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`+(n===`data`?``:`&root=${encodeURIComponent(n)}`),i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()}var K={auth_expired:`Your session has expired. Please sign in again.`,claude_down:`Claude is currently experiencing an outage. Please try again in a few minutes.`,claude_overloaded:`Claude is overloaded right now. Please try again shortly.`,model_unavailable:`The selected model is currently unavailable. Switch to a different model from the model picker to continue.`,agent_error:`Something went wrong. Please try again.`},q={auth_expired:`I'm not available right now. Please try again later.`,claude_down:`I'm not available right now. Please try again later.`,claude_overloaded:`I'm not available right now. Please try again shortly.`,model_unavailable:`I'm not available right now. Please try again later.`,agent_error:`I'm not available right now. Please try again later.`};function J(e,t=`admin`){return t===`public`?q[e]:K[e]}function Y(e){return e===`whatsapp`?` · via WhatsApp`:e===`webchat`?` · via web`:``}function X(e,t,n,r=`/api/whatsapp-reader/stream`){let[i,a]=(0,d.useState)([]),[o,s]=(0,d.useState)(`open`);return(0,d.useEffect)(()=>{a([]),s(`open`);let i=`${r}?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,o=new EventSource(i);return o.onopen=()=>{console.info(`[admin-ui] wa-stream onopen sessionId=${e}`),s(`open`)},o.onmessage=e=>{try{a(t=>[...t,JSON.parse(e.data)])}catch{}},o.onerror=()=>{o.readyState===2&&(console.error(`[admin-ui] wa-stream onerror readyState=${o.readyState}`),s(`error`))},()=>o.close()},[e,t,n,r]),{turns:i,status:o}}var Z=e=>{if(!e)return 1/0;let t=new Date(e).getTime();return Number.isNaN(t)?1/0:t};function ue(e,t){let n=[],r=0;return e.forEach((e,t)=>n.push({sort:Z(e.ts),sub:1,ins:r++,item:{kind:`turn`,turn:e,idx:t}})),t.forEach(e=>n.push({sort:Z(e.ts),sub:0,ins:r++,item:{kind:`directive`,entry:e}})),n.sort((e,t)=>e.sort===t.sort?e.sort===1/0?e.ins-t.ins:e.sub-t.sub||e.ins-t.ins:e.sort<t.sort?-1:1).map(e=>e.item)}function de(e,t,n=!0){let[r,i]=(0,d.useState)([]);return(0,d.useEffect)(()=>{if(!n||typeof fetch!=`function`)return;let r=!0,a=`/api/whatsapp-reader/directives?sessionId=${encodeURIComponent(e)}&session_key=${encodeURIComponent(t)}`;return fetch(a).then(e=>e.ok?e.json():{entries:[]}).then(e=>{r&&i(Array.isArray(e.entries)?e.entries:[])}).catch(()=>{r&&i([])}),()=>{r=!1}},[e,t,n]),r}var fe=new Set([`operator-inbound`,`operator-typed`,`agent-reply`,`agent-reply-document`]);function Q(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function pe(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function $({label:e,ts:t}){return(0,j.jsxs)(`div`,{className:`wa-turn-head`,children:[(0,j.jsx)(`span`,{className:`wa-who`,children:e}),(0,j.jsx)(`time`,{className:`wa-time`,children:Q(t)})]})}function me({turn:e}){let[t,n]=(0,d.useState)(!1),r=e.kind===`tool-result`,i=r?`wa-turn wa-turn-result${e.isError?` is-error`:``}`:`wa-turn wa-turn-tool`,a=r?e.isError?`result (error)`:`result`:`↳ ${e.name}`,o=r?e.text:JSON.stringify(e.input,null,2);return(0,j.jsxs)(`div`,{className:i,children:[(0,j.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,j.jsx)(`span`,{className:`wa-chevron`,children:t?`▾`:`▸`}),(0,j.jsx)(`span`,{className:`wa-who`,children:a}),(0,j.jsx)(`time`,{className:`wa-time`,children:Q(e.ts)})]}),t&&(0,j.jsx)(`pre`,{className:`wa-code`,children:o})]})}function he({entry:e,sessionId:t,sessionKey:n}){let[r,i]=(0,d.useState)(!1),[a,o]=(0,d.useState)(null),s=()=>{let s=!r;if(i(s),s&&a===null&&typeof fetch==`function`){let r=`/api/whatsapp-reader/directive?sessionId=${encodeURIComponent(t)}&name=${encodeURIComponent(e.name)}&session_key=${encodeURIComponent(n)}`;fetch(r).then(e=>e.ok?e.text():`(directive unavailable)`).then(o).catch(()=>o(`(directive unavailable)`))}};return(0,j.jsxs)(`div`,{className:`wa-turn wa-turn-directive`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":r,onClick:s,children:[(0,j.jsx)(`span`,{className:`wa-chevron`,children:r?`▾`:`▸`}),(0,j.jsxs)(`span`,{className:`wa-who`,children:[`⚙ directive injected (`,e.len,` B)`]}),(0,j.jsx)(`time`,{className:`wa-time`,children:Q(e.ts)})]}),r&&(0,j.jsx)(`pre`,{className:`wa-code`,children:a??`Loading…`})]})}function ge(e,t){switch(e.kind){case`operator-inbound`:return(0,j.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,j.jsx)($,{label:`Operator${Y(e.source)}`,ts:e.ts}),(0,j.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`operator-typed`:return(0,j.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,j.jsx)($,{label:`Operator (web)`,ts:e.ts}),(0,j.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-text`:return(0,j.jsxs)(`div`,{className:`wa-turn wa-turn-think`,children:[(0,j.jsx)($,{label:`Agent`,ts:e.ts}),(0,j.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-reply`:return(0,j.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,j.jsx)($,{label:`Agent`,ts:e.ts}),(0,j.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-reply-document`:return(0,j.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,j.jsx)($,{label:`Agent`,ts:e.ts}),(0,j.jsxs)(`p`,{className:`wa-doc`,children:[`📎 sent document(s): `,e.files.map(pe).join(`, `)]}),e.caption&&(0,j.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`tool-call`:case`tool-result`:return(0,j.jsx)(me,{turn:e},t);case`agent-error`:return(0,j.jsxs)(`div`,{className:`wa-turn wa-turn-error`,role:`alert`,children:[(0,j.jsx)($,{label:`Agent`,ts:e.ts}),(0,j.jsx)(`p`,{className:`wa-body wa-error-body`,children:J(e.code,`admin`)}),e.code===`agent_error`&&e.raw&&(0,j.jsx)(`pre`,{className:`wa-code`,children:e.raw})]},t)}}function _e(e,t,n){return e.map((e,r)=>e.kind===`turn`?ge(e.turn,r):(0,j.jsx)(he,{entry:e.entry,sessionId:t,sessionKey:n},r))}var ve=`maxy:whatsapp-reader:clean-view`;function ye(e){return e.filter(e=>e.kind===`turn`&&fe.has(e.turn.kind))}function be({sessionId:e,projectDir:t,sessionKey:n,renderItems:r=_e,cleanViewToggle:i=!1,forceDeliveredOnly:a=!1,streamEndpoint:o=`/api/whatsapp-reader/stream`,suppressDirectives:s=!1,tail:c=null}){let{turns:l,status:u}=X(e,t,n,o),f=ue(l,de(e,n,!s)),[p,m]=(0,d.useState)(()=>{if(typeof window>`u`)return!1;try{return window.localStorage.getItem(ve)===`1`}catch{return!1}}),h=()=>m(e=>{let t=!e;try{window.localStorage.setItem(ve,t?`1`:`0`)}catch{}return t}),g=a||i&&p?ye(f):f,_=(0,d.useRef)(null),v=(0,d.useRef)(!0),[y,b]=(0,d.useState)(!0),x=e=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight<=32;v.current=t,b(e=>e===t?e:t)};return(0,d.useLayoutEffect)(()=>{let e=_.current;e&&v.current&&(e.scrollTop=e.scrollHeight)},[l,p,c!=null]),(0,j.jsxs)(`div`,{className:`wa-reader${i?` wa-reader--clean-toggle`:``}`,children:[(0,j.jsx)(`div`,{className:`wa-reader-thread`,ref:_,onScroll:()=>{let e=_.current;e&&x(e)},children:(0,j.jsxs)(`div`,{className:`wa-thread-scroll`,children:[u===`error`&&(0,j.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),l.length===0&&u===`open`&&(0,j.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),r(g,e,n),c]})}),!y&&(0,j.jsx)(`button`,{type:`button`,className:`wa-jump`,onClick:()=>{let e=_.current;e&&(e.scrollTop=e.scrollHeight,v.current=!0,b(!0))},"aria-label":`Jump to latest message`,title:`Jump to latest message`,children:`↓`}),i&&!a&&(0,j.jsxs)(`button`,{type:`button`,className:`wa-clean-toggle${p?` is-active`:``}`,role:`switch`,"aria-checked":p,onClick:h,title:p?`Showing delivered messages only — click to show tool calls, results, and narration`:`Hide tool calls, results, and narration — show delivered messages only`,children:[(0,j.jsx)(`span`,{className:`wa-clean-label`,children:`Messages only`}),(0,j.jsx)(`span`,{className:`wa-switch`,"aria-hidden":`true`,children:(0,j.jsx)(`span`,{className:`wa-switch-thumb`})})]})]})}function xe(e){if(!e)return``;let t=new Date(e).getTime();return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function Se({conversations:e,sessionKey:t,onBack:n}){let[r,i]=(0,d.useState)(null),a=U(e);return r?(0,j.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,j.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>i(null),"aria-label":`Back to conversations`,children:[(0,j.jsx)(x,{size:16}),` Back`]}),(0,j.jsx)(`span`,{className:`op-conv-title`,children:W(r)})]}),(0,j.jsx)(be,{sessionId:r.sessionId,projectDir:r.projectDir,sessionKey:t,forceDeliveredOnly:!0},r.sessionId)]}):(0,j.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,j.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,j.jsx)(x,{size:16}),` Chat`]}),(0,j.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),a.map(e=>(0,j.jsxs)(`div`,{className:`op-conv-group`,children:[(0,j.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,j.jsx)(B,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,j.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{console.info(`[operator-ui] op=reader-open channel=${e.channel} session=${e.sessionId.slice(0,8)} readonly=true`),i(e)},children:[(0,j.jsx)(`span`,{className:`op-conv-name`,children:W(e)}),e.modelGated&&(0,j.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,j.jsx)(k,{size:13})}),(0,j.jsx)(`span`,{className:`op-conv-when`,children:xe(e.lastMessageAt)})]},e.sessionId))]},e.channel))]})}export{b as C,x as S,y as T,ce as _,Y as a,C as b,W as c,I as d,N as f,D as g,O as h,pe as i,R as l,A as m,he as n,J as o,F as p,be as r,G as s,Se as t,B as u,T as v,_ as w,S as x,w as y};
|