@rubytech/create-realagent-code 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +31 -0
- package/package.json +1 -1
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.js +1 -1
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/url-capture.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/url-capture.js +23 -24
- package/payload/platform/services/claude-session-manager/dist/url-capture.js.map +1 -1
- package/payload/server/public/assets/{admin-C4dXUYsD.js → admin-BWOb7xGA.js} +1 -1
- package/payload/server/public/index.html +1 -1
package/dist/index.js
CHANGED
|
@@ -1728,6 +1728,37 @@ function deployPayload() {
|
|
|
1728
1728
|
}
|
|
1729
1729
|
writeFileSync(credsMigratedStamp, new Date().toISOString() + "\n");
|
|
1730
1730
|
}
|
|
1731
|
+
// Task 019 — pre-populate the brand `.claude.json` so the manager's
|
|
1732
|
+
// PTY-spawned `claude --verbose --remote-control` boots straight into the
|
|
1733
|
+
// session URL without stopping at the first-run theme picker or the
|
|
1734
|
+
// workspace-trust dialog. Both prompts ate the manager's 30 s url-capture
|
|
1735
|
+
// window on 0.1.6 / 0.1.8 installs (Pi 192.168.88.16 verified). The two
|
|
1736
|
+
// markers required are:
|
|
1737
|
+
// - hasCompletedOnboarding: true (suppresses theme picker)
|
|
1738
|
+
// - projects[$HOME].hasTrustDialogAccepted: true
|
|
1739
|
+
// Existing fields (firstStartTime, oauthAccount, migrationVersion, …) are
|
|
1740
|
+
// preserved so a brand re-install does not clobber state written by claude
|
|
1741
|
+
// during the previous run.
|
|
1742
|
+
const claudeStateFile = join(persistentClaudeDir, ".claude.json");
|
|
1743
|
+
const homeWorkspace = process.env.HOME ?? "/root";
|
|
1744
|
+
let claudeState = {};
|
|
1745
|
+
if (existsSync(claudeStateFile)) {
|
|
1746
|
+
try {
|
|
1747
|
+
claudeState = JSON.parse(readFileSync(claudeStateFile, "utf-8"));
|
|
1748
|
+
}
|
|
1749
|
+
catch {
|
|
1750
|
+
claudeState = {};
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
claudeState.hasCompletedOnboarding = true;
|
|
1754
|
+
claudeState.theme = claudeState.theme ?? "auto";
|
|
1755
|
+
const projects = (claudeState.projects ?? {});
|
|
1756
|
+
const homeEntry = projects[homeWorkspace] ?? {};
|
|
1757
|
+
homeEntry.hasTrustDialogAccepted = true;
|
|
1758
|
+
projects[homeWorkspace] = homeEntry;
|
|
1759
|
+
claudeState.projects = projects;
|
|
1760
|
+
writeFileSync(claudeStateFile, JSON.stringify(claudeState, null, 2) + "\n", { mode: 0o600 });
|
|
1761
|
+
console.log(` [install] claude-state primed: ${claudeStateFile} hasCompletedOnboarding=true trustedWorkspace=${homeWorkspace}`);
|
|
1731
1762
|
// Brand isolation: installer does not read ~/.maxy/, ~/.cloudflared/, or
|
|
1732
1763
|
// ~/.cloudflare/ on non-default brands. These are peer-brand or shared-singleton
|
|
1733
1764
|
// paths (Task 659). Pre-Task-659 installs that need to recover legacy state
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@ export async function spawnClaudeSession(deps, args) {
|
|
|
17
17
|
const start = Date.now();
|
|
18
18
|
let pty;
|
|
19
19
|
try {
|
|
20
|
-
pty = deps.spawnPty(deps.claudeBin, ['--verbose'], {
|
|
20
|
+
pty = deps.spawnPty(deps.claudeBin, ['--verbose', '--remote-control'], {
|
|
21
21
|
...process.env,
|
|
22
22
|
TERM: 'xterm-256color',
|
|
23
23
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pty-spawner.js","sourceRoot":"","sources":["../src/pty-spawner.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,yEAAyE;AACzE,0DAA0D;AAC1D,0EAA0E;AAC1E,2EAA2E;AAC3E,eAAe;AACf,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,iEAAiE;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAyBjD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,IAAe,EAAE,IAAe;IACvE,MAAM,SAAS,GAAG,UAAU,EAAE,CAAA;IAC9B,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAExB,IAAI,GAAc,CAAA;IAClB,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,WAAW,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"pty-spawner.js","sourceRoot":"","sources":["../src/pty-spawner.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,yEAAyE;AACzE,0DAA0D;AAC1D,0EAA0E;AAC1E,2EAA2E;AAC3E,eAAe;AACf,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,iEAAiE;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAyBjD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,IAAe,EAAE,IAAe;IACvE,MAAM,SAAS,GAAG,UAAU,EAAE,CAAA;IAC9B,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAExB,IAAI,GAAc,CAAA;IAClB,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,WAAW,EAAE,kBAAkB,CAAC,EAAE;YACrE,GAAG,OAAO,CAAC,GAAG;YACd,IAAI,EAAE,gBAAgB;SACvB,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,GAAG,GAA4B,CAAA;QACtC,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,kBAAkB,CAAA;QAClF,MAAM,UAAU,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;QAC/C,IAAI,CAAC,MAAM,CAAC,uBAAuB,MAAM,gBAAgB,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;QACtF,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,CAAA;IAC1C,CAAC;IAED,OAAO,MAAM,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,EAAE;QAChD,eAAe,CAAC;YACd,GAAG;YACH,SAAS,EAAE,IAAI,CAAC,mBAAmB;YACnC,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE;gBACb,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;gBACrD,MAAM,OAAO,GAAkB;oBAC7B,SAAS;oBACT,GAAG,EAAE,GAAG,CAAC,GAAG;oBACZ,GAAG;oBACH,SAAS;oBACT,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,SAAS;oBACT,GAAG;oBACH,MAAM,EAAE,KAAK;iBACd,CAAA;gBACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;gBACvB,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE;oBACd,OAAO,CAAC,MAAM,GAAG,IAAI,CAAA;oBACrB,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,CAAC,GAAG,oCAAoC,CAAC,CAAA;gBACtE,CAAC,CAAC,CAAA;gBACF,IAAI,CAAC,MAAM,CACT,aAAa,GAAG,CAAC,GAAG,eAAe,GAAG,cAAc,SAAS,IAAI,SAAS,aAAa,IAAI,CAAC,QAAQ,SAAS,IAAI,CAAC,IAAI,YAAY,IAAI,CAAC,OAAO,eAAe,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAClL,CAAA;gBACD,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;YAChC,CAAC;YACD,SAAS,EAAE,GAAG,EAAE;gBACd,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;gBACnB,IAAI,CAAC,MAAM,CAAC,wDAAwD,CAAC,CAAA;gBACrE,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,qBAAqB,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAA;YACvE,CAAC;SACF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AAQD,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAgB,EAChB,SAAiB;IAEjB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;IACnC,IAAI,CAAC,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;IAC3C,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QAC5B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IACpC,CAAC;IACD,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACrB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QAClC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,IAAI,CAAC,CAAC,CAAC,MAAM;gBAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YACpC,OAAO,EAAE,CAAA;QACX,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;QACpB,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE;YAChB,YAAY,CAAC,KAAK,CAAC,CAAA;YACnB,OAAO,EAAE,CAAA;QACX,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IAC5B,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,sCAAsC,CAAC,CAAA;IACpE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;AACpC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-capture.d.ts","sourceRoot":"","sources":["../src/url-capture.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"url-capture.d.ts","sourceRoot":"","sources":["../src/url-capture.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AASnD,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,SAAS,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IACxC,SAAS,EAAE,MAAM,IAAI,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,iBAAiB,GAAG;IAAE,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,CAwC/E"}
|
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
// URL capture for `claude --verbose`.
|
|
1
|
+
// URL capture for `claude --verbose --remote-control`.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// PTY stream:
|
|
3
|
+
// Claude Code v2.1.142 prints the line:
|
|
5
4
|
//
|
|
6
|
-
// /remote-control is active
|
|
5
|
+
// /remote-control is active
|
|
6
|
+
// <url>
|
|
7
7
|
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
// (verified on Pi 192.168.88.16 with claude --version 2.1.142). Older PRD
|
|
9
|
+
// drafts described a one-line `/remote-control is active · <url>` shape with
|
|
10
|
+
// a U+00B7 middle-dot separator; the regex below accepts both so a future
|
|
11
|
+
// claude release reverting to that form does not break capture.
|
|
12
|
+
//
|
|
13
|
+
// We accumulate onData chunks into a buffer so a multi-byte split across
|
|
14
|
+
// two callbacks still matches. After the first URL is captured, the handler
|
|
15
|
+
// unregisters itself so subsequent PTY bytes flow through unchanged.
|
|
16
|
+
// Matches both:
|
|
17
|
+
// /remote-control is active · https://claude.ai/code/...
|
|
18
|
+
// /remote-control is active\n…ANSI…\nhttps://claude.ai/code/...
|
|
19
|
+
// PTY output is heavily ANSI-escaped, so `[\s\S]*?` tolerates intervening
|
|
20
|
+
// cursor moves, colour codes, and box-draw characters before the URL.
|
|
21
|
+
const URL_PATTERN = /\/remote-control is active[\s\S]*?(https?:\/\/\S+)/;
|
|
14
22
|
export function startUrlCapture(opts) {
|
|
15
23
|
const start = Date.now();
|
|
16
24
|
let buffer = '';
|
|
@@ -28,21 +36,12 @@ export function startUrlCapture(opts) {
|
|
|
28
36
|
if (settled)
|
|
29
37
|
return;
|
|
30
38
|
buffer += data;
|
|
31
|
-
const
|
|
32
|
-
if (idx === -1) {
|
|
33
|
-
// Keep the tail so a split across two chunks still matches.
|
|
34
|
-
const keep = TERMINATOR.length * 4;
|
|
35
|
-
if (buffer.length > keep) {
|
|
36
|
-
buffer = buffer.slice(buffer.length - keep);
|
|
37
|
-
}
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const tail = buffer.slice(idx + TERMINATOR.length);
|
|
41
|
-
const match = tail.match(URL_PATTERN);
|
|
39
|
+
const match = buffer.match(URL_PATTERN);
|
|
42
40
|
if (!match) {
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
buffer
|
|
41
|
+
// Cap the buffer so PTY scroll output does not grow unbounded.
|
|
42
|
+
const keep = 16 * 1024;
|
|
43
|
+
if (buffer.length > keep)
|
|
44
|
+
buffer = buffer.slice(buffer.length - keep);
|
|
46
45
|
return;
|
|
47
46
|
}
|
|
48
47
|
settled = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-capture.js","sourceRoot":"","sources":["../src/url-capture.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"url-capture.js","sourceRoot":"","sources":["../src/url-capture.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,EAAE;AACF,wCAAwC;AACxC,EAAE;AACF,gCAAgC;AAChC,YAAY;AACZ,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,0EAA0E;AAC1E,gEAAgE;AAChE,EAAE;AACF,yEAAyE;AACzE,4EAA4E;AAC5E,qEAAqE;AAIrE,gBAAgB;AAChB,2DAA2D;AAC3D,kEAAkE;AAClE,0EAA0E;AAC1E,sEAAsE;AACtE,MAAM,WAAW,GAAG,oDAAoD,CAAA;AAUxE,MAAM,UAAU,eAAe,CAAC,IAAuB;IACrD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IACxB,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,IAAI,OAAO,GAAG,KAAK,CAAA;IACnB,IAAI,OAAO,GAA+B,IAAI,CAAA;IAE9C,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;QAC9B,IAAI,OAAO;YAAE,OAAM;QACnB,OAAO,GAAG,IAAI,CAAA;QACd,IAAI,OAAO;YAAE,OAAO,CAAC,OAAO,EAAE,CAAA;QAC9B,IAAI,CAAC,SAAS,EAAE,CAAA;IAClB,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;IAElB,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QACjC,IAAI,OAAO;YAAE,OAAM;QACnB,MAAM,IAAI,IAAI,CAAA;QACd,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;QACvC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,+DAA+D;YAC/D,MAAM,IAAI,GAAG,EAAE,GAAG,IAAI,CAAA;YACtB,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI;gBAAE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;YACrE,OAAM;QACR,CAAC;QACD,OAAO,GAAG,IAAI,CAAA;QACd,YAAY,CAAC,OAAO,CAAC,CAAA;QACrB,IAAI,OAAO;YAAE,OAAO,CAAC,OAAO,EAAE,CAAA;QAC9B,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QACpB,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAA;QAC7B,IAAI,CAAC,MAAM,CAAC,oBAAoB,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,GAAG,OAAO,EAAE,EAAE,CAAC,CAAA;QACnE,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IACrB,CAAC,CAAC,CAAA;IAEF,OAAO;QACL,MAAM,EAAE,GAAG,EAAE;YACX,IAAI,OAAO;gBAAE,OAAM;YACnB,OAAO,GAAG,IAAI,CAAA;YACd,YAAY,CAAC,OAAO,CAAC,CAAA;YACrB,IAAI,OAAO;gBAAE,OAAO,CAAC,OAAO,EAAE,CAAA;QAChC,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-DD-I1_y5.js";import{a as t,i as n,n as r,r as i,t as a}from"./jsx-runtime-LncohCxF.js";import{a as o,i as s,o as c,t as l}from"./brand-eKOaukUx.js";import{t as u}from"./loader-circle-DwwVih2K.js";import{n as d,t as f}from"./refresh-cw-Ho-xY4LQ.js";import{t as p}from"./Checkbox-D5bsL5IO.js";var m=n(),h=e(t(),1);new Set(`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,application/zip,application/x-zip-compressed,audio/ogg,audio/opus,audio/mp4,audio/mpeg,audio/webm,audio/wav,.opus,.ogg,.m4a,.mp3,.wav,.webm`.split(`,`).filter(e=>!e.startsWith(`.`)));function g(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}function _(){let[e,t]=(0,h.useState)(`loading`),[n,r]=(0,h.useState)(``),[i,a]=(0,h.useState)(``),[o,s]=(0,h.useState)(``),[c,l]=(0,h.useState)(``),[u,d]=(0,h.useState)(!1),[f,p]=(0,h.useState)(!1),[m,_]=(0,h.useState)(!1),[v,ee]=(0,h.useState)(!1),[te,y]=(0,h.useState)(!1),[ne,b]=(0,h.useState)(null),[re,x]=(0,h.useState)(null),[S,C]=(0,h.useState)(void 0),[w,T]=(0,h.useState)(void 0),[E,D]=(0,h.useState)(null),[O,k]=(0,h.useState)(void 0),[A,j]=(0,h.useState)(null),[M,N]=(0,h.useState)(null),[P,ie]=(0,h.useState)([]),[F,I]=(0,h.useState)(!1),[L,R]=(0,h.useState)(void 0),z=(0,h.useRef)(void 0),[B,ae]=(0,h.useState)(!1);(0,h.useEffect)(()=>{typeof window>`u`||window.location.hostname.startsWith(`admin.`)&&fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&ae(!0)}).catch(()=>{})},[]);let V=(0,h.useRef)(null),oe=(0,h.useRef)(null),H=(0,h.useRef)(null);(0,h.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let n=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(n.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!n.ok)return!1;let r=await n.json();b(r.session_key),N(r.conversationId??null),C(r.onboardingComplete),T(r.businessName),D(r.role??null),k(r.userName===void 0?null:r.userName),j(r.avatar??null);let i=g(r.thinkingView);return z.current=i,R(i),t(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function n(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check returned ${i.status} after retries`),t(`set-pin`);return}let a=await i.json();if(!a.pin_configured){t(`set-pin`);return}if(a.onboarding_complete===!1){t(`onboarding-choice`);return}if(!a.claude_authenticated){t(`connect-claude`);return}if(await e())return;t(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check failed:`,e),t(`set-pin`)}}n()},[]),(0,h.useEffect)(()=>{e===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&x(e)}).catch(()=>{})},[e]),(0,h.useEffect)(()=>{if(e!==`chat`)return;let n=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(!e.ok)return;let n=await e.json();(n.auth_status===`dead`||n.auth_status===`missing`)&&t(`connect-claude`)}catch{}},300*1e3);return()=>clearInterval(n)},[e]),(0,h.useEffect)(()=>{e===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&t(`enter-pin`)}).catch(()=>{})},[e]);async function U(e,n){p(!0);try{let i=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...n?{accountId:n}:{}})});if(!i.ok){l((await i.json().catch(()=>({}))).error||`Invalid PIN`);return}let o=await i.json();if(o.accounts&&!o.session_key){console.log(`[admin] account picker shown: userId=${o.userId} accountCount=${o.accounts.length}`),ie(o.accounts),t(`account-picker`);return}b(o.session_key),N(o.conversationId??null),C(o.onboardingComplete??!0),T(o.businessName),D(o.role??null),k(o.userName===void 0?null:o.userName),j(o.avatar??null);let s=g(o.thinkingView);if(z.current=s,R(s),n)try{sessionStorage.setItem(`maxy-account-id`,n)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,o.session_key)}catch{}r(``),a(``),t(`chat`)}catch(e){console.error(`[admin] connection error:`,e),l(`Could not connect.`)}finally{p(!1),I(!1)}}let W=(0,h.useCallback)(async e=>{if(e.preventDefault(),f)return;l(``);let s=o.trim();if(!s){l(`Please enter your name.`);return}if(n.length<4){l(`PIN must be at least 4 characters.`);return}if(n!==i){l(`PINs do not match.`);return}let c=n;p(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:c,name:s})});if(!e.ok){let n=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?t(`enter-pin`):r.pin_configured?t(`connect-claude`):l(n.error||`Failed to set PIN.`)}else t(`enter-pin`)}catch{t(`enter-pin`)}return}l(n.error||`Failed to set PIN.`);return}let n=await fetch(`/api/health`),i=n.ok?await n.json():null;if(i?.onboarding_complete===!1){r(``),a(``),t(`onboarding-choice`);return}if(i?.claude_authenticated){await U(c);return}r(``),a(``),t(`onboarding-choice`)}catch(e){console.error(`[admin] connection error:`,e),l(`Could not connect.`)}finally{p(!1)}},[n,i,f,o]),G=(0,h.useCallback)(async e=>{e.preventDefault(),l(``),await U(n)},[n]),K=(0,h.useCallback)(async()=>{y(!0);try{await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})}),b(null),D(null),k(void 0),j(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}t(`connect-claude`)}finally{y(!1)}},[]),q=(0,h.useCallback)(()=>{b(null),D(null),k(void 0),j(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}r(``),a(``),l(``),t(`enter-pin`)},[]);return{appState:e,setAppState:t,pin:n,setPin:r,confirmPin:i,setConfirmPin:a,operatorName:o,setOperatorName:s,pinError:c,setPinError:l,showPin:u,setShowPin:d,pinLoading:f,authPolling:m,setAuthPolling:_,authLoading:v,setAuthLoading:ee,disconnecting:te,cacheKey:ne,setCacheKey:b,claudeInfo:re,setClaudeInfo:x,onboardingComplete:S,setOnboardingComplete:C,businessName:w,role:E,userName:O,userAvatar:A,conversationId:M,setConversationId:N,accounts:P,accountPickerLoading:F,expandAll:L,setExpandAll:R,expandAllDefaultRef:z,remoteAuthEnabled:B,pinInputRef:V,confirmPinInputRef:oe,setPinFormRef:H,handleSetPin:W,handleLogin:G,handleAccountSelect:(0,h.useCallback)(async e=>{I(!0),l(``),await U(n,e)},[n]),handleDisconnect:K,handleLogout:q,handleChangePin:(0,h.useCallback)(async()=>{if(!n){l(`Enter your current PIN first.`);return}p(!0),l(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:n})});if(!e.ok){l((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}r(``),a(``),l(``),t(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),l(e instanceof Error?e.message:String(e))}finally{p(!1)}},[n])}}function v(e){let[t,n]=(0,h.useState)([]),[r,i]=(0,h.useState)(!1),[a,o]=(0,h.useState)(null),[s,c]=(0,h.useState)(null),l=(0,h.useCallback)(async t=>{if(e&&!(!t&&s===e)){i(!0),o(null);try{let t=await fetch(`/api/admin/claude-sessions?session_key=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`claude-sessions fetch returned ${t.status}`);let r=await t.json();n(Array.isArray(r)?r:r.sessions??[]),c(e)}catch(e){console.error(`[admin/claude-sessions] fetch failed:`,e),o(e instanceof Error?e.message:String(e))}finally{i(!1)}}},[e,s]);(0,h.useEffect)(()=>{e||(c(null),n([]),o(null))},[e]);let u=(0,h.useCallback)(()=>l(!1),[l]),d=(0,h.useCallback)(()=>l(!0),[l]),f=(0,h.useRef)(d);return(0,h.useEffect)(()=>{f.current=d},[d]),(0,h.useEffect)(()=>{if(!e)return;let t=setInterval(()=>{f.current()},3e3);return()=>clearInterval(t)},[e]),{sessions:t,setSessions:n,loading:r,loaded:s!==null&&s===e,error:a,ensureLoaded:u,refetch:d}}var ee=i(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),te=i(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),y=i(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),ne=i(`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`}]]),b=i(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),re=i(`panel-left-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m16 15-3-3 3-3`,key:`14y99z`}]]),x=i(`panel-left-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]]),S=i(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),C=i(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),w=a();function T({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,h.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,w.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,w.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 E(e){let{pin:t,setPin:n,confirmPin:r,setConfirmPin:i,showPin:a,setShowPin:c,pinLoading:u,pinError:d,pinInputRef:f,confirmPinInputRef:m,setPinFormRef:h,onSubmit:g,operatorName:_,setOperatorName:v}=e;return(0,w.jsx)(`div`,{className:`connect-page`,children:(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsx)(`img`,{src:s,alt:l.productName,className:`connect-logo connect-logo--maxy`}),!l.logoContainsName&&(0,w.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,l.productName]}),(0,w.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,l.productName,` who you are, then choose a PIN.`]}),(0,w.jsxs)(`form`,{ref:h,onSubmit:g,className:`connect-pin-form`,children:[(0,w.jsxs)(`div`,{className:`pin-input-row`,children:[(0,w.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:_,onChange:e=>v(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,w.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,w.jsxs)(`div`,{className:`pin-input-row`,children:[(0,w.jsx)(T,{inputRef:f,value:t,onChange:n,onComplete:()=>m.current?.focus(),showPin:a}),(0,w.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,w.jsxs)(`div`,{className:`pin-input-row`,children:[(0,w.jsx)(T,{inputRef:m,value:r,onChange:i,onComplete:()=>{},showPin:a}),(0,w.jsx)(o,{variant:`send`,type:`submit`,disabled:!t||!r||!_.trim(),loading:u,"aria-label":`Set PIN`,children:(0,w.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,w.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,w.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,w.jsx)(p,{checked:a,onChange:()=>c(e=>!e),label:`Show PIN`})]}),d&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:d})]})})}function D(e){let{pin:t,setPin:n,showPin:r,setShowPin:i,pinLoading:a,pinError:c,pinInputRef:u,onSubmit:d,onChangePin:f,remoteAuthEnabled:m,onSignOutRemote:h}=e;return(0,w.jsxs)(`div`,{className:`connect-page`,children:[m&&h&&(0,w.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsx)(`img`,{src:s,alt:l.productName,className:`connect-logo connect-logo--maxy`}),!l.logoContainsName&&(0,w.jsx)(`h1`,{className:`connect-title`,children:l.productName}),(0,w.jsxs)(`form`,{onSubmit:d,className:`connect-pin-form`,children:[(0,w.jsxs)(`div`,{className:`pin-input-row`,children:[(0,w.jsx)(T,{inputRef:u,value:t,onChange:n,onComplete:()=>{},showPin:r,autoFocus:!0}),(0,w.jsx)(o,{variant:`send`,type:`submit`,disabled:!t,loading:a,children:(0,w.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,w.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,w.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,w.jsxs)(`div`,{className:`pin-options`,children:[(0,w.jsx)(p,{checked:r,onChange:()=>i(e=>!e),label:`Show PIN`}),(0,w.jsx)(o,{type:`button`,variant:`ghost`,onClick:f,children:`Change PIN`})]})]}),c&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:c})]})]})}function O(e){let{accounts:t,loading:n,error:r,onSelect:i}=e;return(0,w.jsx)(`div`,{className:`connect-page`,children:(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsx)(`img`,{src:s,alt:l.productName,className:`connect-logo connect-logo--maxy`}),!l.logoContainsName&&(0,w.jsx)(`h1`,{className:`connect-title`,children:l.productName}),(0,w.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,w.jsx)(`div`,{className:`account-picker-list`,children:t.map(e=>(0,w.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>i(e.accountId),disabled:n,type:`button`,children:[(0,w.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,w.jsx)(`span`,{className:`account-picker-role`,children:e.role}),n&&(0,w.jsx)(u,{className:`account-picker-spinner`,size:16})]},e.accountId))}),r&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:r})]})})}function k(e){let{authPolling:t,setAuthPolling:n,authLoading:r,setAuthLoading:i,pinError:a,setPinError:c,setAppState:u}=e,[d,f]=(0,h.useState)(!1),[p,m]=(0,h.useState)(!1);async function g(){m(!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.`)}m(!1)}async function _(){i(!0),c(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){n(!0),f(!0),i(!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.`),n(!1)}else e.error&&c(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),c(`Could not start auth flow.`)}i(!1)}async function v(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),n(!1),c(``)}return t||d?(0,w.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,w.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[t?(0,w.jsx)(`button`,{onClick:v,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,w.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,w.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,w.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,w.jsx)(`p`,{className:`chat-intro`,children:t?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!t&&(0,w.jsx)(`div`,{style:{marginTop:`12px`},children:(0,w.jsx)(o,{variant:`primary`,onClick:_,disabled:r,children:r?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,w.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,w.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),a&&(0,w.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:a})]}):(0,w.jsxs)(`div`,{className:`connect-page`,children:[(0,w.jsx)(`button`,{onClick:()=>u(`onboarding-choice`),style:{position:`fixed`,top:`16px`,left:`16px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Back to setup choice`,children:`← Back`}),(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsxs)(`div`,{className:`connect-logos`,children:[(0,w.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,w.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,w.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,w.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,w.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,w.jsx)(`img`,{src:s,alt:l.productName,className:`connect-logo connect-logo--maxy`}),!l.logoContainsName&&(0,w.jsx)(`span`,{className:`connect-logo-label`,children:l.productName})]})]}),(0,w.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,l.productName]}),(0,w.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,w.jsx)(o,{variant:`primary`,onClick:_,disabled:r,children:r?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,w.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,w.jsx)(`button`,{onClick:g,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`}),a&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:a})]})]})}function A({setAppState:e,setOnboardingComplete:t}){let[n,r]=(0,h.useState)(!1),[i,a]=(0,h.useState)(``);async function c(n){r(!0),a(``);try{let r=await fetch(`/api/onboarding/skip`,{method:`POST`,headers:n===`minimal`?{"Content-Type":`application/json`}:{},body:n===`minimal`?JSON.stringify({minimal:!0}):void 0});if(!r.ok){a((await r.json().catch(()=>({}))).error||`Failed to apply defaults.`);return}t(!0),e(`connect-claude`)}catch(e){console.error(`[admin] skip onboarding error:`,e),a(`Could not apply defaults.`)}finally{r(!1)}}function u(){e(`connect-claude`)}return(0,w.jsx)(`div`,{className:`connect-page`,children:(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,w.jsx)(`img`,{src:s,alt:l.productName,className:`connect-logo connect-logo--maxy`}),!l.logoContainsName&&(0,w.jsx)(`span`,{className:`connect-logo-label`,children:l.productName})]}),(0,w.jsx)(`h1`,{className:`connect-title`,children:`How would you like to get started?`}),(0,w.jsx)(`p`,{className:`connect-subtitle`,style:{fontSize:`0.8rem`,maxWidth:`320px`},children:`Defaults: core plugins only, auto-detected timezone, concise output style, and a minimal personality. No WiFi or optional plugins. Minimal also skips remote access, public-agent API key, and business profile.`}),(0,w.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`10px`,width:`100%`,maxWidth:`320px`,alignItems:`center`},children:[(0,w.jsx)(o,{variant:`primary`,onClick:()=>c(`default`),disabled:n,children:n?`Applying defaults…`:`Use defaults`}),(0,w.jsx)(`button`,{onClick:u,disabled:n,style:{background:`none`,border:`none`,padding:`8px`,cursor:`pointer`,fontSize:`0.95rem`,color:`var(--text-secondary, #666)`,textDecoration:`none`},children:`Guided setup`}),(0,w.jsx)(`button`,{onClick:()=>c(`minimal`),disabled:n,style:{background:`none`,border:`none`,padding:`8px`,cursor:`pointer`,fontSize:`0.95rem`,color:`var(--text-secondary, #666)`,textDecoration:`none`},children:`Minimal`})]}),(0,w.jsx)(`p`,{className:`connect-subtitle`,style:{marginTop:`12px`},children:`You can change any setting later through conversation.`}),i&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:i})]})})}var j=(()=>null),M=(0,h.forwardRef)(function(e,t){let{businessName:n,cacheKey:i,role:a,userName:o,userAvatar:s,sessions:p,sessionsLoading:m,sessionsError:g,ensureSessionsLoaded:_,refetchSessions:v,onSelectArtefact:T,onSelectProjects:E,onSelectPeople:D,onSelectTasks:O,onSelectAgents:k,onCloseMobileDrawer:A,collapsed:M,onToggleCollapsed:N,mobileDrawerOpen:P,actions:ie,recentsActions:F}=e;(0,h.useEffect)(()=>{_()},[_]);let I=(0,h.useRef)(null),[L,R]=(0,h.useState)(!1),[z,B]=(0,h.useState)(null),ae=l.productName,V=typeof o==`string`?o:o===null?`name unavailable`:n||ae,oe=(V.trim().charAt(0)||`?`).toUpperCase(),H=p,U=H.length,[W,G]=(0,h.useState)(`chat`),[K,q]=(0,h.useState)([]),[J,se]=(0,h.useState)(!1),[Y,ce]=(0,h.useState)(null),[le,ue]=(0,h.useState)(!1);(0,h.useImperativeHandle)(t,()=>({patchArtefact(e,t){q(n=>n.map(n=>n.id===e?{...n,...t}:n))}}),[]);let[X,Z]=(0,h.useState)(!1),Q=(0,h.useRef)(null);(0,h.useEffect)(()=>{if(!X)return;function e(e){Q.current&&!Q.current.contains(e.target)&&Z(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[X]);let de=(0,h.useCallback)(async()=>{if(i){ue(!0),ce(null);try{let e=await fetch(`/api/admin/sidebar-artefacts?session_key=${encodeURIComponent(i)}`);if(!e.ok)throw Error(`status ${e.status}`);q((await e.json()).artefacts??[]),se(!0)}catch(e){let t=e instanceof Error?e.message:String(e);ce(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{ue(!1)}}},[i]),fe=()=>{G(`chat`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${U}`)},pe=()=>{G(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${J?K.length:0} collapsed=${M}`),M&&N(),J||de()},$=M?24:16,me=W===`chat`?`Sessions`:`Artefacts`,he=W===`chat`?m?`…`:String(U):le?`…`:String(K.length),ge=W===`chat`?m:le,_e=()=>{W===`chat`?v():de(),console.info(`[admin-ui] sidebar-refresh surface=${W}`)},ve=(0,h.useCallback)(async()=>{if(!(L||!i)){R(!0),B(null);try{let e=await fetch(`/api/admin/claude-sessions?session_key=${encodeURIComponent(i)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({channel:`browser`})}),t=await e.json();if(!e.ok||!(`sessionId`in t)){B(t.error??`POST returned ${e.status}`);return}console.info(`[admin-ui] sidebar-new-session pid=${t.pid} sessionId=${t.sessionId}`),F.setSessions(e=>[t,...e])}catch(e){let t=e instanceof Error?e.message:String(e);B(t),console.error(`[admin-ui] sidebar-new-session failed:`,t)}finally{R(!1)}}},[i,L,F]),ye=(0,h.useCallback)(async e=>{F.setSessions(t=>t.filter(t=>t.sessionId!==e));try{let t=await fetch(`/api/admin/claude-sessions/${encodeURIComponent(e)}`,{method:`DELETE`});if(!t.ok){let e=await t.text().catch(()=>``);throw Error(`DELETE ${t.status} ${e.slice(0,200)}`)}console.info(`[admin-ui] sidebar-end-session sessionId=${e}`)}catch(e){console.error(`[admin-ui] sidebar-end-session failed:`,e),F.refetch()}},[F]);return(0,w.jsxs)(`aside`,{className:`side`,children:[(0,w.jsx)(`div`,{className:`side-head`,children:(0,w.jsx)(`button`,{className:`icon-btn side-head-toggle`,title:P?`Close sidebar`:M?`Expand sidebar`:`Collapse sidebar`,type:`button`,"aria-label":P?`Close sidebar`:M?`Expand sidebar`:`Collapse sidebar`,onClick:()=>{P?(console.info(`[admin-ui] sidebar-head-toggle action=close-drawer state=closed`),A()):(console.info(`[admin-ui] sidebar-head-toggle action=toggle-collapsed state=${M?`expanded`:`collapsed`}`),N())},children:M?(0,w.jsx)(x,{size:28}):(0,w.jsx)(re,{size:28})})}),(0,w.jsxs)(`nav`,{className:`side-nav`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`nav-row${W===`chat`?` active`:``}`,onClick:fe,children:[(0,w.jsx)(S,{size:$}),(0,w.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),D(),A()},children:[(0,w.jsx)(C,{size:$}),(0,w.jsx)(`span`,{className:`label`,children:`People`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),k(),A()},children:[(0,w.jsx)(ee,{size:$}),(0,w.jsx)(`span`,{className:`label`,children:`Agents`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),E(),A()},children:[(0,w.jsx)(te,{size:$}),(0,w.jsx)(`span`,{className:`label`,children:`Projects`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),O(),A()},children:[(0,w.jsx)(b,{size:$}),(0,w.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row${W===`artefacts`?` active`:``}`,onClick:pe,children:[(0,w.jsx)(c,{size:$}),(0,w.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,w.jsx)(`span`,{className:`kbd`})]})]}),(0,w.jsxs)(`div`,{className:`side-list`,ref:I,children:[(0,w.jsxs)(`div`,{className:`group-head`,children:[(0,w.jsx)(`span`,{children:me}),(0,w.jsxs)(`span`,{className:`group-head-meta`,children:[W===`chat`&&(0,w.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`New session`,"aria-label":`New session`,onClick:()=>void ve(),disabled:L||!i,children:L?(0,w.jsx)(u,{size:12,className:`spinning`}):(0,w.jsx)(d,{size:12})}),(0,w.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh ${me.toLowerCase()}`,"aria-label":`Refresh ${me.toLowerCase()}`,onClick:_e,disabled:ge,children:(0,w.jsx)(f,{size:12,className:ge?`spinning`:void 0})}),(0,w.jsx)(`span`,{children:he})]})]}),z&&W===`chat`&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:z}),W===`chat`&&(0,w.jsxs)(w.Fragment,{children:[g&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:g}),H.map(e=>{let t=e.sessionId.slice(0,8);return(0,w.jsxs)(`div`,{className:`conv`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`conv-name-button`,onClick:()=>{console.info(`[admin-ui] sidebar-open-session sessionId=${e.sessionId}`),window.open(e.url,`_blank`,`noopener,noreferrer`),A()},title:`Open session in a new tab`,children:[(0,w.jsx)(S,{size:12,className:`conv-channel-icon`,"aria-label":`claude session`}),(0,w.jsxs)(`span`,{className:`conv-name`,children:[t,` · pid `,e.pid]})]}),(0,w.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`Open in new tab`,"aria-label":`Open in new tab`,onClick:()=>{console.info(`[admin-ui] sidebar-open-session sessionId=${e.sessionId}`),window.open(e.url,`_blank`,`noopener,noreferrer`)},children:(0,w.jsx)(ne,{size:13})}),(0,w.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`End session`,"aria-label":`End session`,onClick:()=>void ye(e.sessionId),children:(0,w.jsx)(r,{size:13})})]},e.sessionId)})]}),W===`artefacts`&&(0,w.jsxs)(w.Fragment,{children:[Y&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:Y}),J&&!Y&&K.length===0&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),K.map(e=>(0,w.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>{T({docId:e.id,name:e.name,content:e.content,editable:e.editable,mimeType:e.mimeType,skipReason:e.skipReason},`sidebar-artefacts`),A()},children:[(0,w.jsx)(`span`,{className:`conv-name`,children:e.name}),(0,w.jsx)(`span`,{className:`conv-kind`,"data-kind":e.kind===`agent-template`?`agent`:`doc`,children:e.kind===`agent-template`?`agent`:`doc`})]},e.id))]})]}),(0,w.jsxs)(`div`,{className:`side-foot`,ref:Q,children:[(0,w.jsx)(`div`,{className:`avatar`,children:s?(0,w.jsx)(`img`,{src:s,alt:V}):oe}),(0,w.jsxs)(`div`,{className:`who`,children:[(0,w.jsx)(`span`,{className:`name`,children:V}),(0,w.jsx)(`span`,{className:`role`,children:a??`operator`})]}),(0,w.jsx)(`button`,{className:`icon-btn side-foot-actions-trigger`,title:`Conversation actions`,type:`button`,"aria-label":`Conversation actions`,"aria-haspopup":`true`,"aria-expanded":X,onClick:()=>Z(e=>!e),children:(0,w.jsx)(y,{size:$})}),X&&(0,w.jsx)(`div`,{className:`side-foot-actions-popover`,children:(0,w.jsx)(j,{...ie,onAfterAction:()=>Z(!1)})})]})]})});function N(){let e=_(),t=v(e.cacheKey),[n,r]=(0,h.useState)(!1),[i,a]=(0,h.useState)(!1);return e.appState===`loading`?(0,w.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,w.jsx)(E,{pin:e.pin,setPin:e.setPin,confirmPin:e.confirmPin,setConfirmPin:e.setConfirmPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,confirmPinInputRef:e.confirmPinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`onboarding-choice`?(0,w.jsx)(A,{setAppState:e.setAppState,setOnboardingComplete:e.setOnboardingComplete}):e.appState===`connect-claude`?(0,w.jsx)(k,{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,w.jsx)(D,{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:e.handleLogout}):e.appState===`account-picker`?(0,w.jsx)(O,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):(0,w.jsx)(`div`,{className:`platform${i?` menu-open`:``}${n?` sidebar-collapsed`:``}`,children:(0,w.jsx)(M,{businessName:e.businessName,cacheKey:e.cacheKey,role:e.role,userName:e.userName,userAvatar:e.userAvatar,sessions:t.sessions,sessionsLoading:t.loading,sessionsError:t.error,ensureSessionsLoaded:t.ensureLoaded,refetchSessions:t.refetch,onSelectArtefact:e=>{},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:()=>a(!1),collapsed:n,onToggleCollapsed:()=>r(e=>!e),mobileDrawerOpen:i,actions:{},recentsActions:{setSessions:t.setSessions,refetch:t.refetch}})})}(0,m.createRoot)(document.getElementById(`root`)).render((0,w.jsx)(N,{}));
|
|
1
|
+
import{o as e}from"./chunk-DD-I1_y5.js";import{a as t,i as n,n as r,r as i,t as a}from"./jsx-runtime-LncohCxF.js";import{a as o,i as s,o as c,t as l}from"./brand-eKOaukUx.js";import{t as u}from"./loader-circle-DwwVih2K.js";import{n as d,t as f}from"./refresh-cw-Ho-xY4LQ.js";import{t as p}from"./Checkbox-D5bsL5IO.js";var m=n(),h=e(t(),1);new Set(`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,application/zip,application/x-zip-compressed,audio/ogg,audio/opus,audio/mp4,audio/mpeg,audio/webm,audio/wav,.opus,.ogg,.m4a,.mp3,.wav,.webm`.split(`,`).filter(e=>!e.startsWith(`.`)));function g(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}function _(){let[e,t]=(0,h.useState)(`loading`),[n,r]=(0,h.useState)(``),[i,a]=(0,h.useState)(``),[o,s]=(0,h.useState)(``),[c,l]=(0,h.useState)(``),[u,d]=(0,h.useState)(!1),[f,p]=(0,h.useState)(!1),[m,_]=(0,h.useState)(!1),[v,ee]=(0,h.useState)(!1),[te,y]=(0,h.useState)(!1),[ne,b]=(0,h.useState)(null),[re,x]=(0,h.useState)(null),[S,C]=(0,h.useState)(void 0),[w,T]=(0,h.useState)(void 0),[E,D]=(0,h.useState)(null),[O,k]=(0,h.useState)(void 0),[A,j]=(0,h.useState)(null),[M,N]=(0,h.useState)(null),[P,ie]=(0,h.useState)([]),[F,I]=(0,h.useState)(!1),[L,R]=(0,h.useState)(void 0),z=(0,h.useRef)(void 0),[B,ae]=(0,h.useState)(!1);(0,h.useEffect)(()=>{typeof window>`u`||window.location.hostname.startsWith(`admin.`)&&fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&ae(!0)}).catch(()=>{})},[]);let V=(0,h.useRef)(null),oe=(0,h.useRef)(null),H=(0,h.useRef)(null);(0,h.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let n=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(n.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!n.ok)return!1;let r=await n.json();b(r.session_key),N(r.conversationId??null),C(r.onboardingComplete),T(r.businessName),D(r.role??null),k(r.userName===void 0?null:r.userName),j(r.avatar??null);let i=g(r.thinkingView);return z.current=i,R(i),t(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function n(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check returned ${i.status} after retries`),t(`set-pin`);return}let a=await i.json();if(!a.pin_configured){t(`set-pin`);return}if(a.onboarding_complete===!1){t(`onboarding-choice`);return}if(!a.claude_authenticated){t(`connect-claude`);return}if(await e())return;t(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check failed:`,e),t(`set-pin`)}}n()},[]),(0,h.useEffect)(()=>{e===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&x(e)}).catch(()=>{})},[e]),(0,h.useEffect)(()=>{if(e!==`chat`)return;let n=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(!e.ok)return;let n=await e.json();(n.auth_status===`dead`||n.auth_status===`missing`)&&t(`connect-claude`)}catch{}},300*1e3);return()=>clearInterval(n)},[e]),(0,h.useEffect)(()=>{e===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&t(`enter-pin`)}).catch(()=>{})},[e]);async function U(e,n){p(!0);try{let i=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...n?{accountId:n}:{}})});if(!i.ok){l((await i.json().catch(()=>({}))).error||`Invalid PIN`);return}let o=await i.json();if(o.accounts&&!o.session_key){console.log(`[admin] account picker shown: userId=${o.userId} accountCount=${o.accounts.length}`),ie(o.accounts),t(`account-picker`);return}b(o.session_key),N(o.conversationId??null),C(o.onboardingComplete??!0),T(o.businessName),D(o.role??null),k(o.userName===void 0?null:o.userName),j(o.avatar??null);let s=g(o.thinkingView);if(z.current=s,R(s),n)try{sessionStorage.setItem(`maxy-account-id`,n)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,o.session_key)}catch{}r(``),a(``),t(`chat`)}catch(e){console.error(`[admin] connection error:`,e),l(`Could not connect.`)}finally{p(!1),I(!1)}}let W=(0,h.useCallback)(async e=>{if(e.preventDefault(),f)return;l(``);let s=o.trim();if(!s){l(`Please enter your name.`);return}if(n.length<4){l(`PIN must be at least 4 characters.`);return}if(n!==i){l(`PINs do not match.`);return}let c=n;p(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:c,name:s})});if(!e.ok){let n=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?t(`enter-pin`):r.pin_configured?t(`connect-claude`):l(n.error||`Failed to set PIN.`)}else t(`enter-pin`)}catch{t(`enter-pin`)}return}l(n.error||`Failed to set PIN.`);return}let n=await fetch(`/api/health`),i=n.ok?await n.json():null;if(i?.onboarding_complete===!1){r(``),a(``),t(`onboarding-choice`);return}if(i?.claude_authenticated){await U(c);return}r(``),a(``),t(`onboarding-choice`)}catch(e){console.error(`[admin] connection error:`,e),l(`Could not connect.`)}finally{p(!1)}},[n,i,f,o]),G=(0,h.useCallback)(async e=>{e.preventDefault(),l(``),await U(n)},[n]),K=(0,h.useCallback)(async()=>{y(!0);try{await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})}),b(null),D(null),k(void 0),j(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}t(`connect-claude`)}finally{y(!1)}},[]),q=(0,h.useCallback)(()=>{b(null),D(null),k(void 0),j(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}r(``),a(``),l(``),t(`enter-pin`)},[]);return{appState:e,setAppState:t,pin:n,setPin:r,confirmPin:i,setConfirmPin:a,operatorName:o,setOperatorName:s,pinError:c,setPinError:l,showPin:u,setShowPin:d,pinLoading:f,authPolling:m,setAuthPolling:_,authLoading:v,setAuthLoading:ee,disconnecting:te,cacheKey:ne,setCacheKey:b,claudeInfo:re,setClaudeInfo:x,onboardingComplete:S,setOnboardingComplete:C,businessName:w,role:E,userName:O,userAvatar:A,conversationId:M,setConversationId:N,accounts:P,accountPickerLoading:F,expandAll:L,setExpandAll:R,expandAllDefaultRef:z,remoteAuthEnabled:B,pinInputRef:V,confirmPinInputRef:oe,setPinFormRef:H,handleSetPin:W,handleLogin:G,handleAccountSelect:(0,h.useCallback)(async e=>{I(!0),l(``),await U(n,e)},[n]),handleDisconnect:K,handleLogout:q,handleChangePin:(0,h.useCallback)(async()=>{if(!n){l(`Enter your current PIN first.`);return}p(!0),l(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:n})});if(!e.ok){l((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}r(``),a(``),l(``),t(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),l(e instanceof Error?e.message:String(e))}finally{p(!1)}},[n])}}function v(e){let[t,n]=(0,h.useState)([]),[r,i]=(0,h.useState)(!1),[a,o]=(0,h.useState)(null),[s,c]=(0,h.useState)(null),l=(0,h.useCallback)(async t=>{if(e&&!(!t&&s===e)){i(!0),o(null);try{let t=await fetch(`/api/admin/claude-sessions?session_key=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`claude-sessions fetch returned ${t.status}`);let r=await t.json();n(Array.isArray(r)?r:r.sessions??[]),c(e)}catch(e){console.error(`[admin/claude-sessions] fetch failed:`,e),o(e instanceof Error?e.message:String(e))}finally{i(!1)}}},[e,s]);(0,h.useEffect)(()=>{e||(c(null),n([]),o(null))},[e]);let u=(0,h.useCallback)(()=>l(!1),[l]),d=(0,h.useCallback)(()=>l(!0),[l]),f=(0,h.useRef)(d);return(0,h.useEffect)(()=>{f.current=d},[d]),(0,h.useEffect)(()=>{if(!e)return;let t=setInterval(()=>{f.current()},3e3);return()=>clearInterval(t)},[e]),{sessions:t,setSessions:n,loading:r,loaded:s!==null&&s===e,error:a,ensureLoaded:u,refetch:d}}var ee=i(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),te=i(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),y=i(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),ne=i(`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`}]]),b=i(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),re=i(`panel-left-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m16 15-3-3 3-3`,key:`14y99z`}]]),x=i(`panel-left-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]]),S=i(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),C=i(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),w=a();function T({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,h.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,w.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,w.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 E(e){let{pin:t,setPin:n,confirmPin:r,setConfirmPin:i,showPin:a,setShowPin:c,pinLoading:u,pinError:d,pinInputRef:f,confirmPinInputRef:m,setPinFormRef:h,onSubmit:g,operatorName:_,setOperatorName:v}=e;return(0,w.jsx)(`div`,{className:`connect-page`,children:(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsx)(`img`,{src:s,alt:l.productName,className:`connect-logo connect-logo--maxy`}),!l.logoContainsName&&(0,w.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,l.productName]}),(0,w.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,l.productName,` who you are, then choose a PIN.`]}),(0,w.jsxs)(`form`,{ref:h,onSubmit:g,className:`connect-pin-form`,children:[(0,w.jsxs)(`div`,{className:`pin-input-row`,children:[(0,w.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:_,onChange:e=>v(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,w.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,w.jsxs)(`div`,{className:`pin-input-row`,children:[(0,w.jsx)(T,{inputRef:f,value:t,onChange:n,onComplete:()=>m.current?.focus(),showPin:a}),(0,w.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,w.jsxs)(`div`,{className:`pin-input-row`,children:[(0,w.jsx)(T,{inputRef:m,value:r,onChange:i,onComplete:()=>{},showPin:a}),(0,w.jsx)(o,{variant:`send`,type:`submit`,disabled:!t||!r||!_.trim(),loading:u,"aria-label":`Set PIN`,children:(0,w.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,w.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,w.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,w.jsx)(p,{checked:a,onChange:()=>c(e=>!e),label:`Show PIN`})]}),d&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:d})]})})}function D(e){let{pin:t,setPin:n,showPin:r,setShowPin:i,pinLoading:a,pinError:c,pinInputRef:u,onSubmit:d,onChangePin:f,remoteAuthEnabled:m,onSignOutRemote:h}=e;return(0,w.jsxs)(`div`,{className:`connect-page`,children:[m&&h&&(0,w.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsx)(`img`,{src:s,alt:l.productName,className:`connect-logo connect-logo--maxy`}),!l.logoContainsName&&(0,w.jsx)(`h1`,{className:`connect-title`,children:l.productName}),(0,w.jsxs)(`form`,{onSubmit:d,className:`connect-pin-form`,children:[(0,w.jsxs)(`div`,{className:`pin-input-row`,children:[(0,w.jsx)(T,{inputRef:u,value:t,onChange:n,onComplete:()=>{},showPin:r,autoFocus:!0}),(0,w.jsx)(o,{variant:`send`,type:`submit`,disabled:!t,loading:a,children:(0,w.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,w.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,w.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,w.jsxs)(`div`,{className:`pin-options`,children:[(0,w.jsx)(p,{checked:r,onChange:()=>i(e=>!e),label:`Show PIN`}),(0,w.jsx)(o,{type:`button`,variant:`ghost`,onClick:f,children:`Change PIN`})]})]}),c&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:c})]})]})}function O(e){let{accounts:t,loading:n,error:r,onSelect:i}=e;return(0,w.jsx)(`div`,{className:`connect-page`,children:(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsx)(`img`,{src:s,alt:l.productName,className:`connect-logo connect-logo--maxy`}),!l.logoContainsName&&(0,w.jsx)(`h1`,{className:`connect-title`,children:l.productName}),(0,w.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,w.jsx)(`div`,{className:`account-picker-list`,children:t.map(e=>(0,w.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>i(e.accountId),disabled:n,type:`button`,children:[(0,w.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,w.jsx)(`span`,{className:`account-picker-role`,children:e.role}),n&&(0,w.jsx)(u,{className:`account-picker-spinner`,size:16})]},e.accountId))}),r&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:r})]})})}function k(e){let{authPolling:t,setAuthPolling:n,authLoading:r,setAuthLoading:i,pinError:a,setPinError:c,setAppState:u}=e,[d,f]=(0,h.useState)(!1),[p,m]=(0,h.useState)(!1);async function g(){m(!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.`)}m(!1)}async function _(){i(!0),c(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){n(!0),f(!0),i(!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.`),n(!1)}else e.error&&c(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),c(`Could not start auth flow.`)}i(!1)}async function v(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),n(!1),c(``)}return t||d?(0,w.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,w.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[t?(0,w.jsx)(`button`,{onClick:v,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,w.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,w.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,w.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,w.jsx)(`p`,{className:`chat-intro`,children:t?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!t&&(0,w.jsx)(`div`,{style:{marginTop:`12px`},children:(0,w.jsx)(o,{variant:`primary`,onClick:_,disabled:r,children:r?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,w.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,w.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),a&&(0,w.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:a})]}):(0,w.jsxs)(`div`,{className:`connect-page`,children:[(0,w.jsx)(`button`,{onClick:()=>u(`onboarding-choice`),style:{position:`fixed`,top:`16px`,left:`16px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Back to setup choice`,children:`← Back`}),(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsxs)(`div`,{className:`connect-logos`,children:[(0,w.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,w.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,w.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,w.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,w.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,w.jsx)(`img`,{src:s,alt:l.productName,className:`connect-logo connect-logo--maxy`}),!l.logoContainsName&&(0,w.jsx)(`span`,{className:`connect-logo-label`,children:l.productName})]})]}),(0,w.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,l.productName]}),(0,w.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,w.jsx)(o,{variant:`primary`,onClick:_,disabled:r,children:r?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,w.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,w.jsx)(`button`,{onClick:g,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`}),a&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:a})]})]})}function A({setAppState:e,setOnboardingComplete:t}){let[n,r]=(0,h.useState)(!1),[i,a]=(0,h.useState)(``);async function c(n){r(!0),a(``);try{let r=await fetch(`/api/onboarding/skip`,{method:`POST`,headers:n===`minimal`?{"Content-Type":`application/json`}:{},body:n===`minimal`?JSON.stringify({minimal:!0}):void 0});if(!r.ok){a((await r.json().catch(()=>({}))).error||`Failed to apply defaults.`);return}t(!0),e(`connect-claude`)}catch(e){console.error(`[admin] skip onboarding error:`,e),a(`Could not apply defaults.`)}finally{r(!1)}}function u(){e(`connect-claude`)}return(0,w.jsx)(`div`,{className:`connect-page`,children:(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,w.jsx)(`img`,{src:s,alt:l.productName,className:`connect-logo connect-logo--maxy`}),!l.logoContainsName&&(0,w.jsx)(`span`,{className:`connect-logo-label`,children:l.productName})]}),(0,w.jsx)(`h1`,{className:`connect-title`,children:`How would you like to get started?`}),(0,w.jsx)(`p`,{className:`connect-subtitle`,style:{fontSize:`0.8rem`,maxWidth:`320px`},children:`Defaults: core plugins only, auto-detected timezone, concise output style, and a minimal personality. No WiFi or optional plugins. Minimal also skips remote access, public-agent API key, and business profile.`}),(0,w.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`10px`,width:`100%`,maxWidth:`320px`,alignItems:`center`},children:[(0,w.jsx)(o,{variant:`primary`,onClick:()=>c(`default`),disabled:n,children:n?`Applying defaults…`:`Use defaults`}),(0,w.jsx)(`button`,{onClick:u,disabled:n,style:{background:`none`,border:`none`,padding:`8px`,cursor:`pointer`,fontSize:`0.95rem`,color:`var(--text-secondary, #666)`,textDecoration:`none`},children:`Guided setup`}),(0,w.jsx)(`button`,{onClick:()=>c(`minimal`),disabled:n,style:{background:`none`,border:`none`,padding:`8px`,cursor:`pointer`,fontSize:`0.95rem`,color:`var(--text-secondary, #666)`,textDecoration:`none`},children:`Minimal`})]}),(0,w.jsx)(`p`,{className:`connect-subtitle`,style:{marginTop:`12px`},children:`You can change any setting later through conversation.`}),i&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:i})]})})}var j=(()=>null),M=(0,h.forwardRef)(function(e,t){let{businessName:n,cacheKey:i,role:a,userName:o,userAvatar:s,sessions:p,sessionsLoading:m,sessionsError:g,ensureSessionsLoaded:_,refetchSessions:v,onSelectArtefact:T,onSelectProjects:E,onSelectPeople:D,onSelectTasks:O,onSelectAgents:k,onCloseMobileDrawer:A,collapsed:M,onToggleCollapsed:N,mobileDrawerOpen:P,actions:ie,recentsActions:F}=e;(0,h.useEffect)(()=>{_()},[_]);let I=(0,h.useRef)(null),[L,R]=(0,h.useState)(!1),[z,B]=(0,h.useState)(null),ae=l.productName,V=typeof o==`string`?o:o===null?`name unavailable`:n||ae,oe=(V.trim().charAt(0)||`?`).toUpperCase(),H=p,U=H.length,[W,G]=(0,h.useState)(`chat`),[K,q]=(0,h.useState)([]),[J,se]=(0,h.useState)(!1),[Y,ce]=(0,h.useState)(null),[le,ue]=(0,h.useState)(!1);(0,h.useImperativeHandle)(t,()=>({patchArtefact(e,t){q(n=>n.map(n=>n.id===e?{...n,...t}:n))}}),[]);let[X,Z]=(0,h.useState)(!1),Q=(0,h.useRef)(null);(0,h.useEffect)(()=>{if(!X)return;function e(e){Q.current&&!Q.current.contains(e.target)&&Z(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[X]);let de=(0,h.useCallback)(async()=>{if(i){ue(!0),ce(null);try{let e=await fetch(`/api/admin/sidebar-artefacts?session_key=${encodeURIComponent(i)}`);if(!e.ok)throw Error(`status ${e.status}`);q((await e.json()).artefacts??[]),se(!0)}catch(e){let t=e instanceof Error?e.message:String(e);ce(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{ue(!1)}}},[i]),fe=()=>{G(`chat`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${U}`)},pe=()=>{G(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${J?K.length:0} collapsed=${M}`),M&&N(),J||de()},$=M?24:16,me=W===`chat`?`Sessions`:`Artefacts`,he=W===`chat`?m?`…`:String(U):le?`…`:String(K.length),ge=W===`chat`?m:le,_e=()=>{W===`chat`?v():de(),console.info(`[admin-ui] sidebar-refresh surface=${W}`)},ve=(0,h.useCallback)(async()=>{if(!(L||!i)){R(!0),B(null);try{let e=await fetch(`/api/admin/claude-sessions?session_key=${encodeURIComponent(i)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({channel:`browser`})}),t=await e.json();if(!e.ok||!(`sessionId`in t)){B(t.error??`POST returned ${e.status}`);return}console.info(`[admin-ui] sidebar-new-session pid=${t.pid} sessionId=${t.sessionId}`),F.setSessions(e=>[t,...e])}catch(e){let t=e instanceof Error?e.message:String(e);B(t),console.error(`[admin-ui] sidebar-new-session failed:`,t)}finally{R(!1)}}},[i,L,F]),ye=(0,h.useCallback)(async e=>{F.setSessions(t=>t.filter(t=>t.sessionId!==e));try{let t=await fetch(`/api/admin/claude-sessions/${encodeURIComponent(e)}?session_key=${encodeURIComponent(i)}`,{method:`DELETE`});if(!t.ok){let e=await t.text().catch(()=>``);throw Error(`DELETE ${t.status} ${e.slice(0,200)}`)}console.info(`[admin-ui] sidebar-end-session sessionId=${e}`)}catch(e){console.error(`[admin-ui] sidebar-end-session failed:`,e),F.refetch()}},[i,F]);return(0,w.jsxs)(`aside`,{className:`side`,children:[(0,w.jsx)(`div`,{className:`side-head`,children:(0,w.jsx)(`button`,{className:`icon-btn side-head-toggle`,title:P?`Close sidebar`:M?`Expand sidebar`:`Collapse sidebar`,type:`button`,"aria-label":P?`Close sidebar`:M?`Expand sidebar`:`Collapse sidebar`,onClick:()=>{P?(console.info(`[admin-ui] sidebar-head-toggle action=close-drawer state=closed`),A()):(console.info(`[admin-ui] sidebar-head-toggle action=toggle-collapsed state=${M?`expanded`:`collapsed`}`),N())},children:M?(0,w.jsx)(x,{size:28}):(0,w.jsx)(re,{size:28})})}),(0,w.jsxs)(`nav`,{className:`side-nav`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`nav-row${W===`chat`?` active`:``}`,onClick:fe,children:[(0,w.jsx)(S,{size:$}),(0,w.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),D(),A()},children:[(0,w.jsx)(C,{size:$}),(0,w.jsx)(`span`,{className:`label`,children:`People`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),k(),A()},children:[(0,w.jsx)(ee,{size:$}),(0,w.jsx)(`span`,{className:`label`,children:`Agents`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),E(),A()},children:[(0,w.jsx)(te,{size:$}),(0,w.jsx)(`span`,{className:`label`,children:`Projects`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),O(),A()},children:[(0,w.jsx)(b,{size:$}),(0,w.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row${W===`artefacts`?` active`:``}`,onClick:pe,children:[(0,w.jsx)(c,{size:$}),(0,w.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,w.jsx)(`span`,{className:`kbd`})]})]}),(0,w.jsxs)(`div`,{className:`side-list`,ref:I,children:[(0,w.jsxs)(`div`,{className:`group-head`,children:[(0,w.jsx)(`span`,{children:me}),(0,w.jsxs)(`span`,{className:`group-head-meta`,children:[W===`chat`&&(0,w.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`New session`,"aria-label":`New session`,onClick:()=>void ve(),disabled:L||!i,children:L?(0,w.jsx)(u,{size:12,className:`spinning`}):(0,w.jsx)(d,{size:12})}),(0,w.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh ${me.toLowerCase()}`,"aria-label":`Refresh ${me.toLowerCase()}`,onClick:_e,disabled:ge,children:(0,w.jsx)(f,{size:12,className:ge?`spinning`:void 0})}),(0,w.jsx)(`span`,{children:he})]})]}),z&&W===`chat`&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:z}),W===`chat`&&(0,w.jsxs)(w.Fragment,{children:[g&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:g}),H.map(e=>{let t=e.sessionId.slice(0,8);return(0,w.jsxs)(`div`,{className:`conv`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`conv-name-button`,onClick:()=>{console.info(`[admin-ui] sidebar-open-session sessionId=${e.sessionId}`),window.open(e.url,`_blank`,`noopener,noreferrer`),A()},title:`Open session in a new tab`,children:[(0,w.jsx)(S,{size:12,className:`conv-channel-icon`,"aria-label":`claude session`}),(0,w.jsxs)(`span`,{className:`conv-name`,children:[t,` · pid `,e.pid]})]}),(0,w.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`Open in new tab`,"aria-label":`Open in new tab`,onClick:()=>{console.info(`[admin-ui] sidebar-open-session sessionId=${e.sessionId}`),window.open(e.url,`_blank`,`noopener,noreferrer`)},children:(0,w.jsx)(ne,{size:13})}),(0,w.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`End session`,"aria-label":`End session`,onClick:()=>void ye(e.sessionId),children:(0,w.jsx)(r,{size:13})})]},e.sessionId)})]}),W===`artefacts`&&(0,w.jsxs)(w.Fragment,{children:[Y&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:Y}),J&&!Y&&K.length===0&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),K.map(e=>(0,w.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>{T({docId:e.id,name:e.name,content:e.content,editable:e.editable,mimeType:e.mimeType,skipReason:e.skipReason},`sidebar-artefacts`),A()},children:[(0,w.jsx)(`span`,{className:`conv-name`,children:e.name}),(0,w.jsx)(`span`,{className:`conv-kind`,"data-kind":e.kind===`agent-template`?`agent`:`doc`,children:e.kind===`agent-template`?`agent`:`doc`})]},e.id))]})]}),(0,w.jsxs)(`div`,{className:`side-foot`,ref:Q,children:[(0,w.jsx)(`div`,{className:`avatar`,children:s?(0,w.jsx)(`img`,{src:s,alt:V}):oe}),(0,w.jsxs)(`div`,{className:`who`,children:[(0,w.jsx)(`span`,{className:`name`,children:V}),(0,w.jsx)(`span`,{className:`role`,children:a??`operator`})]}),(0,w.jsx)(`button`,{className:`icon-btn side-foot-actions-trigger`,title:`Conversation actions`,type:`button`,"aria-label":`Conversation actions`,"aria-haspopup":`true`,"aria-expanded":X,onClick:()=>Z(e=>!e),children:(0,w.jsx)(y,{size:$})}),X&&(0,w.jsx)(`div`,{className:`side-foot-actions-popover`,children:(0,w.jsx)(j,{...ie,onAfterAction:()=>Z(!1)})})]})]})});function N(){let e=_(),t=v(e.cacheKey),[n,r]=(0,h.useState)(!1),[i,a]=(0,h.useState)(!1);return e.appState===`loading`?(0,w.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,w.jsx)(E,{pin:e.pin,setPin:e.setPin,confirmPin:e.confirmPin,setConfirmPin:e.setConfirmPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,confirmPinInputRef:e.confirmPinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`onboarding-choice`?(0,w.jsx)(A,{setAppState:e.setAppState,setOnboardingComplete:e.setOnboardingComplete}):e.appState===`connect-claude`?(0,w.jsx)(k,{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,w.jsx)(D,{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:e.handleLogout}):e.appState===`account-picker`?(0,w.jsx)(O,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):(0,w.jsx)(`div`,{className:`platform${i?` menu-open`:``}${n?` sidebar-collapsed`:``}`,children:(0,w.jsx)(M,{businessName:e.businessName,cacheKey:e.cacheKey,role:e.role,userName:e.userName,userAvatar:e.userAvatar,sessions:t.sessions,sessionsLoading:t.loading,sessionsError:t.error,ensureSessionsLoaded:t.ensureLoaded,refetchSessions:t.refetch,onSelectArtefact:e=>{},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:()=>a(!1),collapsed:n,onToggleCollapsed:()=>r(e=>!e),mobileDrawerOpen:i,actions:{},recentsActions:{setSessions:t.setSessions,refetch:t.refetch}})})}(0,m.createRoot)(document.getElementById(`root`)).render((0,w.jsx)(N,{}));
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Real Agent</title>
|
|
7
7
|
<link rel="icon" href="/favicon.ico">
|
|
8
|
-
<script type="module" crossorigin src="/assets/admin-
|
|
8
|
+
<script type="module" crossorigin src="/assets/admin-BWOb7xGA.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-DD-I1_y5.js">
|
|
10
10
|
<link rel="modulepreload" crossorigin href="/assets/jsx-runtime-LncohCxF.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/brand-eKOaukUx.js">
|