@rubytech/create-maxy-code 0.1.312 → 0.1.313

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.
Files changed (67) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/plugins/.claude-plugin/marketplace.json +5 -0
  3. package/payload/platform/plugins/admin/hooks/lib/maxy-mcp-plugins.txt +1 -0
  4. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +37 -3
  5. package/payload/platform/plugins/docs/references/admin-ui.md +2 -2
  6. package/payload/platform/plugins/docs/references/quickbooks.md +29 -0
  7. package/payload/platform/plugins/quickbooks/.claude-plugin/plugin.json +21 -0
  8. package/payload/platform/plugins/quickbooks/PLUGIN.md +91 -0
  9. package/payload/platform/plugins/quickbooks/lib/mcp-spawn-tee/index.js +159 -0
  10. package/payload/platform/plugins/quickbooks/lib/mcp-spawn-tee/package.json +3 -0
  11. package/payload/platform/plugins/quickbooks/mcp/dist/index.d.ts +2 -0
  12. package/payload/platform/plugins/quickbooks/mcp/dist/index.d.ts.map +1 -0
  13. package/payload/platform/plugins/quickbooks/mcp/dist/index.js +218 -0
  14. package/payload/platform/plugins/quickbooks/mcp/dist/index.js.map +1 -0
  15. package/payload/platform/plugins/quickbooks/mcp/dist/lib/oauth.d.ts +37 -0
  16. package/payload/platform/plugins/quickbooks/mcp/dist/lib/oauth.d.ts.map +1 -0
  17. package/payload/platform/plugins/quickbooks/mcp/dist/lib/oauth.js +75 -0
  18. package/payload/platform/plugins/quickbooks/mcp/dist/lib/oauth.js.map +1 -0
  19. package/payload/platform/plugins/quickbooks/mcp/dist/lib/qbo-client.d.ts +39 -0
  20. package/payload/platform/plugins/quickbooks/mcp/dist/lib/qbo-client.d.ts.map +1 -0
  21. package/payload/platform/plugins/quickbooks/mcp/dist/lib/qbo-client.js +178 -0
  22. package/payload/platform/plugins/quickbooks/mcp/dist/lib/qbo-client.js.map +1 -0
  23. package/payload/platform/plugins/quickbooks/mcp/dist/lib/secrets.d.ts +36 -0
  24. package/payload/platform/plugins/quickbooks/mcp/dist/lib/secrets.d.ts.map +1 -0
  25. package/payload/platform/plugins/quickbooks/mcp/dist/lib/secrets.js +107 -0
  26. package/payload/platform/plugins/quickbooks/mcp/dist/lib/secrets.js.map +1 -0
  27. package/payload/platform/plugins/quickbooks/mcp/package.json +19 -0
  28. package/payload/platform/plugins/quickbooks/skills/quickbooks/SKILL.md +37 -0
  29. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
  30. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +16 -0
  31. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
  32. package/payload/server/{chunk-J6WDAWFJ.js → chunk-Q7EWROVN.js} +4 -0
  33. package/payload/server/maxy-edge.js +1 -1
  34. package/payload/server/public/assets/{AccessGate-Dh5A79FU.js → AccessGate-Byskkf47.js} +1 -1
  35. package/payload/server/public/assets/{AdminLoginScreens-B8s2TbT7.js → AdminLoginScreens-DgwQi3HN.js} +1 -1
  36. package/payload/server/public/assets/AdminShell-DQfL2c_L.js +1 -0
  37. package/payload/server/public/assets/{Checkbox-B_sOAyv1.js → Checkbox-C54JSreC.js} +1 -1
  38. package/payload/server/public/assets/OperatorConversations-DulQyF8c.js +1 -0
  39. package/payload/server/public/assets/{admin-gZEndvJT.js → admin-B25rkI9Q.js} +1 -1
  40. package/payload/server/public/assets/{audio-attachment-mime-B0b89VnH.js → audio-attachment-mime-BlwrgPQa.js} +1 -1
  41. package/payload/server/public/assets/{brand-BcNavK6q.css → brand-TWflEl22.css} +1 -1
  42. package/payload/server/public/assets/{browser-BUlB5_MD.js → browser-C9Z5dLlN.js} +1 -1
  43. package/payload/server/public/assets/chat-CGNWDmid.js +1 -0
  44. package/payload/server/public/assets/data-DCQDh0-Y.js +1 -0
  45. package/payload/server/public/assets/{graph-labels-AZLGoVy8.js → graph-labels-BBtL--_M.js} +1 -1
  46. package/payload/server/public/assets/{graph-DMCKpW6P.js → graph-sMzOI71g.js} +2 -2
  47. package/payload/server/public/assets/operator-hI6kJi0I.js +1 -0
  48. package/payload/server/public/assets/page-DbsqlpuX.js +1 -0
  49. package/payload/server/public/assets/{public-G_-UI9nB.js → public-Cs5N4-Az.js} +1 -1
  50. package/payload/server/public/assets/{public-next-C8_nExQB.js → public-next-DoGPYX6T.js} +1 -1
  51. package/payload/server/public/assets/{useSelectionMode-Bf6Rt-sl.js → useSelectionMode-Cs-vtuKI.js} +1 -1
  52. package/payload/server/public/browser.html +6 -6
  53. package/payload/server/public/chat.html +8 -8
  54. package/payload/server/public/data.html +5 -5
  55. package/payload/server/public/graph.html +8 -8
  56. package/payload/server/public/index.html +8 -8
  57. package/payload/server/public/operator.html +10 -10
  58. package/payload/server/public/public-next.html +9 -9
  59. package/payload/server/public/public.html +7 -7
  60. package/payload/server/server.js +600 -491
  61. package/payload/server/public/assets/AdminShell-Cu1zlb6L.js +0 -1
  62. package/payload/server/public/assets/OperatorConversations-hm0Gpu_Q.js +0 -1
  63. package/payload/server/public/assets/chat-BnceaVl7.js +0 -1
  64. package/payload/server/public/assets/data-3Nl3P5wt.js +0 -1
  65. package/payload/server/public/assets/operator-BF4F7k23.js +0 -1
  66. package/payload/server/public/assets/page-DQUEst1o.js +0 -1
  67. /package/payload/server/public/assets/{brand-BQ_u9UdS.js → brand-CYjs10m-.js} +0 -0
@@ -0,0 +1,107 @@
1
+ // QuickBooks Online per-account secret store.
2
+ //
3
+ // Plain 0600 JSON, NOT the encrypted outlook TokenStore. Two processes read and
4
+ // write this store: the MCP tool server (this package) and the UI server's
5
+ // callback route (platform/ui/server/routes/quickbooks.ts). They never import
6
+ // across the build-tree boundary — they agree on the on-disk shape defined here
7
+ // and in the callback route. Plain JSON keeps that contract trivially shareable;
8
+ // the secrets/ dir is brand-isolated and delete-protected (admin/files.ts), the
9
+ // same protection the cloudflare token store relies on.
10
+ import { mkdirSync, readFileSync, writeFileSync, existsSync, rmSync, } from "node:fs";
11
+ import { resolve, join } from "node:path";
12
+ /** A consent state nonce: URL-safe characters only, never a path fragment. */
13
+ const STATE_RE = /^[A-Za-z0-9_-]+$/;
14
+ function accountsDir(platformRoot) {
15
+ return resolve(platformRoot, "..", "data/accounts");
16
+ }
17
+ export function accountSecretsDir(platformRoot, accountId) {
18
+ return join(accountsDir(platformRoot), accountId, "secrets");
19
+ }
20
+ function storePath(platformRoot, accountId) {
21
+ return join(accountSecretsDir(platformRoot, accountId), "quickbooks.json");
22
+ }
23
+ function pendingDir(platformRoot, accountId) {
24
+ return join(accountSecretsDir(platformRoot, accountId), "quickbooks-pending");
25
+ }
26
+ function pendingPath(platformRoot, accountId, state) {
27
+ if (!STATE_RE.test(state)) {
28
+ throw new Error(`invalid consent state nonce: ${JSON.stringify(state)}`);
29
+ }
30
+ return join(pendingDir(platformRoot, accountId), `${state}.json`);
31
+ }
32
+ export function readStore(platformRoot, accountId) {
33
+ const file = storePath(platformRoot, accountId);
34
+ if (!existsSync(file))
35
+ return null;
36
+ try {
37
+ return JSON.parse(readFileSync(file, "utf-8"));
38
+ }
39
+ catch {
40
+ return null;
41
+ }
42
+ }
43
+ function writeStore(platformRoot, accountId, store) {
44
+ const dir = accountSecretsDir(platformRoot, accountId);
45
+ mkdirSync(dir, { recursive: true });
46
+ writeFileSync(storePath(platformRoot, accountId), JSON.stringify(store, null, 2), {
47
+ mode: 0o600,
48
+ });
49
+ }
50
+ export function setCredentials(platformRoot, accountId, creds) {
51
+ const prev = readStore(platformRoot, accountId);
52
+ writeStore(platformRoot, accountId, {
53
+ clientId: creds.clientId,
54
+ clientSecret: creds.clientSecret,
55
+ environment: creds.environment,
56
+ connections: prev?.connections ?? {},
57
+ });
58
+ }
59
+ export function upsertConnection(platformRoot, accountId, realmId, conn) {
60
+ const store = readStore(platformRoot, accountId);
61
+ if (!store) {
62
+ throw new Error("cannot store a connection before credentials are set");
63
+ }
64
+ store.connections[realmId] = conn;
65
+ writeStore(platformRoot, accountId, store);
66
+ }
67
+ export function removeConnection(platformRoot, accountId, realmId) {
68
+ const store = readStore(platformRoot, accountId);
69
+ if (!store)
70
+ return;
71
+ delete store.connections[realmId];
72
+ writeStore(platformRoot, accountId, store);
73
+ }
74
+ export function writePending(platformRoot, accountId, pending) {
75
+ const file = pendingPath(platformRoot, accountId, pending.state);
76
+ mkdirSync(pendingDir(platformRoot, accountId), { recursive: true });
77
+ writeFileSync(file, JSON.stringify(pending, null, 2), { mode: 0o600 });
78
+ }
79
+ export function readPending(platformRoot, accountId, state) {
80
+ let file;
81
+ try {
82
+ file = pendingPath(platformRoot, accountId, state);
83
+ }
84
+ catch {
85
+ return null;
86
+ }
87
+ if (!existsSync(file))
88
+ return null;
89
+ try {
90
+ return JSON.parse(readFileSync(file, "utf-8"));
91
+ }
92
+ catch {
93
+ return null;
94
+ }
95
+ }
96
+ export function deletePending(platformRoot, accountId, state) {
97
+ let file;
98
+ try {
99
+ file = pendingPath(platformRoot, accountId, state);
100
+ }
101
+ catch {
102
+ return;
103
+ }
104
+ if (existsSync(file))
105
+ rmSync(file);
106
+ }
107
+ //# sourceMappingURL=secrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../src/lib/secrets.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@maxy/quickbooks",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "start": "node dist/index.js"
10
+ },
11
+ "dependencies": {
12
+ "@modelcontextprotocol/sdk": "^1.12.1",
13
+ "zod": "^3.24.0"
14
+ },
15
+ "devDependencies": {
16
+ "typescript": "^5.7.0",
17
+ "@types/node": "^22.0.0"
18
+ }
19
+ }
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: quickbooks
3
+ description: Connect QuickBooks Online and work with the books. Use when the operator wants to link QuickBooks, read invoices/customers/bills/reports, or create and update accounting records. Covers the one-time Intuit app registration and per-company consent relay, then the agent-driven read/write surface.
4
+ ---
5
+
6
+ # QuickBooks Online connector
7
+
8
+ QuickBooks Online lives in Intuit's cloud. Maxy never owns the OAuth app — the operator brings their own Intuit app, and a human consents per company. After that, reads and writes are yours.
9
+
10
+ Success is: the operator's credentials are stored, at least one company shows up under `quickbooks-connections`, and a `quickbooks-query` returns that company's data.
11
+
12
+ ## The two human steps (relay these — never click for them)
13
+
14
+ **1. Register an Intuit app.** The operator (not the agent) does this once at https://developer.intuit.com. They create an app, enable the Accounting scope, and copy its **client ID** and **client secret**. In the app's Keys & OAuth settings they add a **Redirect URI** that must be exactly the brand's public site URL followed by `/api/quickbooks/callback` (for example `https://app.<brand-domain>/api/quickbooks/callback`). Intuit rejects `localhost` for production, which is why the callback rides the public host. For a first run, the sandbox keys (free, up to five sandbox companies) are the right starting point.
15
+
16
+ **2. Consent per company.** You generate the consent link with `quickbooks-authorize-url`; a human opens it, signs into Intuit, and authorizes one company. Intuit redirects their browser back to the callback, which stores the refresh token. Repeat per company for the accountant case (one Intuit app can hold many company grants).
17
+
18
+ ## Procedure
19
+
20
+ 1. Once the operator has the client ID and secret, store them: `quickbooks-credentials-set` with `environment` set to `sandbox` or `production`.
21
+ 2. Generate the consent link: `quickbooks-authorize-url` with `redirectUri` set to the **exact** registered redirect URI. Hand the returned URL to a human. The link is valid 15 minutes.
22
+ 3. After they authorize, confirm with `quickbooks-connections` — the company's `realmId` should appear.
23
+ 4. Read and write against that `realmId`.
24
+
25
+ ## Working with the books
26
+
27
+ - **Read anything** with `quickbooks-query`, e.g. `SELECT * FROM Invoice WHERE TxnDate > '2026-01-01'`, `SELECT * FROM Customer`, `SELECT * FROM Bill MAXRESULTS 50`.
28
+ - **Reports** with `quickbooks-report`, e.g. `ProfitAndLoss` with `{ start_date, end_date }`, or `BalanceSheet`.
29
+ - **Write** with the entity tools (`quickbooks-invoice-create`, `quickbooks-customer-create`, `quickbooks-bill-create`, `quickbooks-payment-create`) or the generic `quickbooks-entity-create` for anything else. Updates require the record's current `Id` and `SyncToken` in the body (read it back first with a query).
30
+
31
+ ## Keeping connections healthy
32
+
33
+ A refresh token dies silently after about 100 days of inactivity or if the operator revokes it. Run `quickbooks-token-audit` periodically; `alive=false` means that company needs the consent relay run again before it is used. Reads are metered (a free monthly allowance) and writes are free — prefer a targeted query over pulling everything.
34
+
35
+ ## What stays the operator's job
36
+
37
+ Moving an Intuit app from sandbox to production requires Intuit's production security assessment. That is the operator's responsibility and is not automated here.
@@ -1 +1 @@
1
- {"version":3,"file":"canonical-tool-names.generated.d.ts","sourceRoot":"","sources":["../src/canonical-tool-names.generated.ts"],"names":[],"mappings":"AAQA,+EAA+E;AAC/E,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAiB7C,CAAA;AAED,gEAAgE;AAChE,eAAO,MAAM,yBAAyB,EAAE,SAAS,MAAM,EAkLtD,CAAA"}
1
+ {"version":3,"file":"canonical-tool-names.generated.d.ts","sourceRoot":"","sources":["../src/canonical-tool-names.generated.ts"],"names":[],"mappings":"AAQA,+EAA+E;AAC/E,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAkB7C,CAAA;AAED,gEAAgE;AAChE,eAAO,MAAM,yBAAyB,EAAE,SAAS,MAAM,EAiMtD,CAAA"}
@@ -16,6 +16,7 @@ export const MAXY_MCP_PLUGINS = [
16
16
  "graph-viewer",
17
17
  "memory",
18
18
  "outlook",
19
+ "quickbooks",
19
20
  "replicate",
20
21
  "scheduling",
21
22
  "telegram",
@@ -155,6 +156,21 @@ export const CANONICAL_MAXY_TOOL_NAMES = [
155
156
  "mcp__plugin_outlook_outlook__outlook-mail-list",
156
157
  "mcp__plugin_outlook_outlook__outlook-mail-search",
157
158
  "mcp__plugin_outlook_outlook__outlook-mailbox-info",
159
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-authorize-url",
160
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-bill-create",
161
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-connections",
162
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-credentials-set",
163
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-customer-create",
164
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-customer-update",
165
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-disconnect",
166
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-entity-create",
167
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-entity-update",
168
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-invoice-create",
169
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-invoice-update",
170
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-payment-create",
171
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-query",
172
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-report",
173
+ "mcp__plugin_quickbooks_quickbooks__quickbooks-token-audit",
158
174
  "mcp__plugin_replicate_replicate__image-generate",
159
175
  "mcp__plugin_replicate_replicate__replicate-key-store",
160
176
  "mcp__plugin_replicate_replicate__replicate-key-verify",
@@ -1 +1 @@
1
- {"version":3,"file":"canonical-tool-names.generated.js","sourceRoot":"","sources":["../src/canonical-tool-names.generated.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"canonical-tool-names.generated.js","sourceRoot":"","sources":["../src/canonical-tool-names.generated.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,kEAAkE;AAClE,yDAAyD;AACzD,kFAAkF;AAClF,EAAE;AACF,yEAAyE;AACzE,6DAA6D;AAE7D,+EAA+E;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAsB;IACjD,OAAO;IACP,KAAK;IACL,SAAS;IACT,UAAU;IACV,OAAO;IACP,OAAO;IACP,cAAc;IACd,QAAQ;IACR,SAAS;IACT,YAAY;IACZ,WAAW;IACX,YAAY;IACZ,UAAU;IACV,SAAS;IACT,UAAU;IACV,MAAM;IACN,WAAW;CACZ,CAAA;AAED,gEAAgE;AAChE,MAAM,CAAC,MAAM,yBAAyB,GAAsB;IAC1D,yCAAyC;IACzC,yCAAyC;IACzC,yCAAyC;IACzC,sCAAsC;IACtC,yCAAyC;IACzC,wCAAwC;IACxC,oCAAoC;IACpC,qCAAqC;IACrC,uCAAuC;IACvC,2CAA2C;IAC3C,4CAA4C;IAC5C,qCAAqC;IACrC,yCAAyC;IACzC,4CAA4C;IAC5C,oCAAoC;IACpC,sCAAsC;IACtC,0CAA0C;IAC1C,uCAAuC;IACvC,sCAAsC;IACtC,sDAAsD;IACtD,mDAAmD;IACnD,6CAA6C;IAC7C,wCAAwC;IACxC,yCAAyC;IACzC,qCAAqC;IACrC,uCAAuC;IACvC,sCAAsC;IACtC,wCAAwC;IACxC,+BAA+B;IAC/B,qCAAqC;IACrC,sCAAsC;IACtC,yCAAyC;IACzC,4CAA4C;IAC5C,uDAAuD;IACvD,+CAA+C;IAC/C,2CAA2C;IAC3C,gDAAgD;IAChD,oDAAoD;IACpD,4CAA4C;IAC5C,+CAA+C;IAC/C,+CAA+C;IAC/C,gDAAgD;IAChD,6CAA6C;IAC7C,6CAA6C;IAC7C,iDAAiD;IACjD,oDAAoD;IACpD,+CAA+C;IAC/C,2CAA2C;IAC3C,2CAA2C;IAC3C,+CAA+C;IAC/C,+CAA+C;IAC/C,+CAA+C;IAC/C,8CAA8C;IAC9C,+CAA+C;IAC/C,6CAA6C;IAC7C,+CAA+C;IAC/C,+CAA+C;IAC/C,6CAA6C;IAC7C,6CAA6C;IAC7C,sCAAsC;IACtC,2CAA2C;IAC3C,2CAA2C;IAC3C,sCAAsC;IACtC,4CAA4C;IAC5C,uCAAuC;IACvC,4CAA4C;IAC5C,8CAA8C;IAC9C,qCAAqC;IACrC,sCAAsC;IACtC,uCAAuC;IACvC,qCAAqC;IACrC,sCAAsC;IACtC,uCAAuC;IACvC,qDAAqD;IACrD,sDAAsD;IACtD,uDAAuD;IACvD,wDAAwD;IACxD,iEAAiE;IACjE,kEAAkE;IAClE,6DAA6D;IAC7D,8CAA8C;IAC9C,wDAAwD;IACxD,gDAAgD;IAChD,qDAAqD;IACrD,sDAAsD;IACtD,wDAAwD;IACxD,wCAAwC;IACxC,wCAAwC;IACxC,iDAAiD;IACjD,wDAAwD;IACxD,0DAA0D;IAC1D,0CAA0C;IAC1C,6CAA6C;IAC7C,wCAAwC;IACxC,mDAAmD;IACnD,+CAA+C;IAC/C,mDAAmD;IACnD,0CAA0C;IAC1C,kDAAkD;IAClD,8CAA8C;IAC9C,oDAAoD;IACpD,kDAAkD;IAClD,+CAA+C;IAC/C,mDAAmD;IACnD,2CAA2C;IAC3C,qDAAqD;IACrD,+CAA+C;IAC/C,sDAAsD;IACtD,gDAAgD;IAChD,2CAA2C;IAC3C,gDAAgD;IAChD,0CAA0C;IAC1C,mDAAmD;IACnD,0CAA0C;IAC1C,kDAAkD;IAClD,yCAAyC;IACzC,kDAAkD;IAClD,2CAA2C;IAC3C,yCAAyC;IACzC,2CAA2C;IAC3C,4CAA4C;IAC5C,mDAAmD;IACnD,uDAAuD;IACvD,qDAAqD;IACrD,oDAAoD;IACpD,oDAAoD;IACpD,gDAAgD;IAChD,kDAAkD;IAClD,mDAAmD;IACnD,6DAA6D;IAC7D,2DAA2D;IAC3D,2DAA2D;IAC3D,+DAA+D;IAC/D,+DAA+D;IAC/D,+DAA+D;IAC/D,0DAA0D;IAC1D,6DAA6D;IAC7D,6DAA6D;IAC7D,8DAA8D;IAC9D,8DAA8D;IAC9D,8DAA8D;IAC9D,qDAAqD;IACrD,sDAAsD;IACtD,2DAA2D;IAC3D,iDAAiD;IACjD,sDAAsD;IACtD,uDAAuD;IACvD,yDAAyD;IACzD,oDAAoD;IACpD,mDAAmD;IACnD,wDAAwD;IACxD,iDAAiD;IACjD,wDAAwD;IACxD,kDAAkD;IAClD,oDAAoD;IACpD,iDAAiD;IACjD,wCAAwC;IACxC,gDAAgD;IAChD,0DAA0D;IAC1D,sCAAsC;IACtC,kDAAkD;IAClD,gDAAgD;IAChD,kEAAkE;IAClE,uDAAuD;IACvD,oDAAoD;IACpD,oDAAoD;IACpD,qDAAqD;IACrD,oDAAoD;IACpD,kDAAkD;IAClD,gDAAgD;IAChD,yCAAyC;IACzC,uCAAuC;IACvC,oCAAoC;IACpC,qCAAqC;IACrC,uCAAuC;IACvC,qCAAqC;IACrC,qCAAqC;IACrC,sCAAsC;IACtC,oCAAoC;IACpC,iCAAiC;IACjC,kCAAkC;IAClC,mCAAmC;IACnC,oCAAoC;IACpC,oCAAoC;IACpC,kDAAkD;IAClD,kDAAkD;IAClD,mDAAmD;IACnD,+CAA+C;IAC/C,gDAAgD;IAChD,gDAAgD;IAChD,kDAAkD;IAClD,oDAAoD;CACrD,CAAA"}
@@ -3550,6 +3550,10 @@ var PUBLIC_ALLOWED_PREFIXES = [
3550
3550
  "/api/health",
3551
3551
  "/api/group/",
3552
3552
  "/api/telegram/",
3553
+ // QuickBooks OAuth consent callback. Intuit redirects the operator's browser
3554
+ // here with no admin cookie; the route authenticates by validating the OAuth
3555
+ // `state` nonce, not the remote-auth gate (same model as /api/telegram/).
3556
+ "/api/quickbooks/",
3553
3557
  "/assets/",
3554
3558
  "/brand/",
3555
3559
  "/agent-assets/",
@@ -16,7 +16,7 @@ import {
16
16
  sanitizeClientCorrId,
17
17
  vncLog,
18
18
  websockifyLog
19
- } from "./chunk-J6WDAWFJ.js";
19
+ } from "./chunk-Q7EWROVN.js";
20
20
  import "./chunk-PFF6I7KP.js";
21
21
 
22
22
  // server/edge.ts
@@ -1 +1 @@
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};
1
+ import{o as e}from"./chunk-CAM3fms7.js";import{o as t,u as n}from"./brand-CYjs10m-.js";import{r}from"./useSelectionMode-Cs-vtuKI.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};
@@ -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-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};
1
+ import{o as e}from"./chunk-CAM3fms7.js";import{a as t,o as n,t as r,u as i}from"./brand-CYjs10m-.js";import{T as a,y as o}from"./OperatorConversations-DulQyF8c.js";import{i as s}from"./admin-types-D2qTXuCg.js";import{s as c}from"./AdminShell-DQfL2c_L.js";import{r as l}from"./useSelectionMode-Cs-vtuKI.js";import{t as u}from"./Checkbox-C54JSreC.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};
@@ -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-CYjs10m-.js";import{S as o,_ as s,c,d as l,f as u,l as d,m as f,t as p,u as m,v as h,x as g}from"./OperatorConversations-DulQyF8c.js";import{i as _,t as v}from"./useSelectionMode-Cs-vtuKI.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.menuLabel})]},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:u,userAvatar:p,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 u==`string`?u:u===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<400,[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}`),c(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)(m,{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)(s,{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)(o,{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)(s,{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),o=Be.has(e.sessionId),s=n||i||a||o,c=[{key:`open`,label:`Resume session ${e.title} in claude.ai/code`,menuLabel:`Resume in claude.ai/code`,title:`Resume in a fresh local Remote Control PTY`,icon:(0,O.jsx)(g,{size:12}),busy:n,onClick:()=>{mt(e)}},{key:`message`,label:`Open session ${e.title} in admin webchat`,menuLabel:`Open in webchat`,title:`Open in admin webchat (/chat) — sending resumes this session`,icon:(0,O.jsx)(w,{size:12}),onClick:()=>{window.location.assign(`/chat?session=${e.sessionId}`)}},...e.live?[{key:`stop`,label:`Stop session ${e.title}`,menuLabel:`Stop`,title:`Stop session process (keeps the conversation, can resume later)`,icon:(0,O.jsx)(re,{size:12}),busy:a,onClick:t=>{vt(t,e)}}]:[],e.archived?{key:`unarchive`,label:`Unarchive session ${e.title}`,menuLabel:`Unarchive`,title:`Unarchive (move back to the active list)`,icon:(0,O.jsx)(y,{size:12}),busy:o,onClick:t=>{yt(t,e,`unarchive`)}}:{key:`archive`,label:`Archive session ${e.title}`,menuLabel:`Archive`,title:`Archive (hide from the list, keeps the conversation resumable)`,icon:(0,O.jsx)(b,{size:12}),busy:o,onClick:t=>{yt(t,e,`archive`)}},{key:`rename`,label:`Rename session ${e.title}`,menuLabel:`Rename`,title:`Rename this session`,icon:(0,O.jsx)(h,{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}`,menuLabel:`Delete`,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)(l,{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:c,disabled:s,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)(s,{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)(m,{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:d(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:p?(0,O.jsx)(`img`,{src:p,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:l,children:d,footer:f}=e,[m,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=${m} 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:!m,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=m;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),te(!e)}},[m,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:m,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)(u,{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)(p,{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)(u,{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`:``}${m?` sidebar-collapsed`:``}`,"data-artefact":`closed`,children:[(0,O.jsx)(I,{businessName:n,cacheKey:t,role:l??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:m,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-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};
1
+ import{o as e}from"./brand-CYjs10m-.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-CYjs10m-.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`}]]),S=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`}]]),C=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`}]]),w=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`}]]),T=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`}]]),ee=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`}]]),te=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`}]]),E=t(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),ne=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`}]]),re=t(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),D=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`}]]),ie=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`}]]),ae=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`}]]),oe=t(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),se=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`}]]),O=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`}]]),k=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`}]]),A=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`}]]),ce=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`}]]),j=t(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),M=r(),N=(0,d.createContext)(null);function P({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,M.jsx)(N.Provider,{value:i,children:r})}function F(){return(0,d.useContext)(N)}function I(e){let t=F();return(0,d.useMemo)(()=>t||(async(t,n)=>fetch(e?p(t,e):t,n)),[t,e])}function L(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=I(null),[C,D]=(0,d.useState)(null),[se,O]=(0,d.useState)(!1),[A,N]=(0,d.useState)(null),[P,F]=(0,d.useState)(null),[L,R]=(0,d.useState)(!1),[z,B]=(0,d.useState)(null),[V,H]=(0,d.useState)(null),[U,W]=(0,d.useState)(``);(0,d.useEffect)(()=>{W(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||H(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[g,r,x]);let G=(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]),K=(0,d.useCallback)(e=>{_(!1),o(e)},[o]),q=(0,d.useCallback)(async()=>{if(C!==null){D(null),F(null);return}O(!0),N(null);try{let e=await x(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);D((await e.json()).agents??[])}catch(e){console.error(`[admin/agents] list failed:`,e),N(e instanceof Error?e.message:String(e)),D([])}finally{O(!1)}},[C,x]),J=(0,d.useCallback)(e=>{F(null),D(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]),Y=(0,d.useCallback)(()=>{_(!1),p()},[p]),X=(0,d.useCallback)(async()=>{B(null),await m()?(R(!1),_(!1)):B(`Disconnect failed — credentials still present. Try again.`)},[m]),Z=t||a.productName;return(0,M.jsxs)(`header`,{className:`admin-header`,children:[r===`admin`?(0,M.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,M.jsx)(ae,{size:20,strokeWidth:1.5}):(0,M.jsx)(oe,{size:20,strokeWidth:1.5})}):(0,M.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,M.jsx)(`img`,{src:n,alt:``,className:`chat-logo`})}),r===`admin`?(0,M.jsxs)(`div`,{className:`chat-header-label`,children:[(0,M.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,M.jsx)(`img`,{src:n,alt:``,className:`chat-logo`})}),(0,M.jsx)(`h1`,{className:`chat-tagline`,children:Z})]}):(0,M.jsx)(`h1`,{className:`chat-tagline`,children:Z}),(0,M.jsxs)(`div`,{className:`chat-burger-wrap`,ref:v,children:[(0,M.jsx)(`button`,{type:`button`,className:`admin-burger`,onClick:G,"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":g,children:(0,M.jsx)(re,{size:20})}),g&&(0,M.jsxs)(`div`,{className:`admin-menu${r===`operator`?` admin-menu-operator`:``}`,role:`menu`,children:[r===`admin`&&(0,M.jsxs)(`button`,{ref:y,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>K(`dashboard`),children:[(0,M.jsx)(te,{size:14}),` Dashboard`]}),r===`operator`&&(0,M.jsxs)(`button`,{ref:y,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>K(`chat`),children:[(0,M.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`chat-menu-claude-icon`}),` Chat`]}),r===`operator`&&s>0&&(0,M.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>{_(!1),l?.()},children:[(0,M.jsx)(ie,{size:14}),` Conversations`]}),(0,M.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>K(`data`),children:[(0,M.jsx)(S,{size:14}),` Data`]}),r===`admin`&&(0,M.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>K(`graph`),children:[(0,M.jsx)(k,{size:14}),` Graph`]}),r===`admin`&&(0,M.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>K(`browser`),children:[(0,M.jsx)(T,{size:14}),` Browser`]}),r===`admin`&&(0,M.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>K(`chat`),children:[(0,M.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`chat-menu-claude-icon`}),` Chat`]}),r===`admin`&&(0,M.jsx)(`div`,{className:`chat-menu-divider`}),r===`admin`&&(0,M.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:q,children:[(0,M.jsx)(w,{size:14}),` Public`,se&&(0,M.jsx)(E,{size:12,className:`spin`})]}),r===`admin`&&C!==null&&(0,M.jsxs)(`div`,{className:`chat-menu-agents`,children:[A&&(0,M.jsx)(`span`,{className:`chat-menu-agent-error`,children:A}),C.length===0&&!A&&(0,M.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),C.map(e=>(0,M.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,M.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,M.jsxs)(`span`,{className:`agent-text`,children:[(0,M.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,M.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),P===e.slug?(0,M.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,M.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>J(e.slug),children:(0,M.jsx)(b,{size:12})}),(0,M.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>F(null),children:(0,M.jsx)(j,{size:12})})]}):(0,M.jsxs)(`span`,{className:`agent-actions`,children:[(0,M.jsx)(`a`,{href:`${U}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>_(!1),children:(0,M.jsx)(w,{size:12})}),(0,M.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>F(e.slug),children:(0,M.jsx)(i,{size:12})})]})]},e.slug))]}),r===`admin`&&(0,M.jsx)(`div`,{className:`chat-menu-divider`}),r===`admin`&&(0,M.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,M.jsx)(ee,{size:14}),(0,M.jsxs)(`span`,{className:`version-installed`,children:[V?`v${V.installed}`:`…`,V&&!V.updateAvailable&&(0,M.jsx)(`span`,{className:`version-uptodate-dot`}),V?.updateAvailable&&(0,M.jsx)(`span`,{className:`version-update-dot`})]})]}),r===`admin`&&(L?(0,M.jsxs)(`div`,{className:`chat-menu-item chat-menu-disconnect`,children:[(0,M.jsx)(`span`,{children:`Disconnect Claude account?`}),(0,M.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,M.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm disconnect`,disabled:h,onClick:X,children:h?(0,M.jsx)(E,{size:12,className:`spin`}):(0,M.jsx)(b,{size:12})}),(0,M.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel disconnect`,disabled:h,onClick:()=>{R(!1),B(null)},children:(0,M.jsx)(j,{size:12})})]})]}):(0,M.jsxs)(`button`,{type:`button`,className:`chat-menu-item chat-menu-disconnect`,role:`menuitem`,onClick:()=>{B(null),R(!0)},children:[(0,M.jsx)(ce,{size:14}),` Disconnect Claude account`]})),r===`admin`&&z&&(0,M.jsx)(`span`,{className:`chat-menu-agent-error`,children:z}),(0,M.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:Y,children:[(0,M.jsx)(ne,{size:14}),` Log out`]})]})]})]})}var R={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 z({channel:e,size:t=16}){let n=R[e];return(0,M.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,M.jsx)(`path`,{d:n.path})})}var B={whatsapp:`whatsapp`,telegram:`telegram`};function V({channel:e,size:t=13}){let n=B[e];return n?(0,M.jsx)(z,{channel:n,size:t}):e===`webchat`?(0,M.jsx)(T,{size:t,className:`channel-icon`,role:`img`,"aria-label":`Web chat`,style:{color:`var(--text-tertiary)`}}):(0,M.jsx)(D,{size:t,className:`channel-icon`,role:`img`,"aria-label":e,style:{color:`var(--text-tertiary)`}})}var H=[`whatsapp`,`telegram`,`webchat`],U={whatsapp:`WhatsApp`,telegram:`Telegram`,webchat:`Webchat`};function W(e){return H.map(t=>({channel:t,label:U[t],rows:e.filter(e=>e.channel===t)})).filter(e=>e.rows.length>0)}function G(e){let t=e.operatorName??e.whatsappName;return t?e.senderId?`${t} ${e.senderId}`:t:e.senderId??e.title}function K(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 q={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.`},J={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 Y(e,t=`admin`){return t===`public`?J[e]:q[e]}function X(e){return e===`whatsapp`?` · via WhatsApp`:e===`webchat`?` · via web`:``}function Z(e,t,n,r=`/api/whatsapp-reader/stream`,i=e){let[a,o]=(0,d.useState)([]),[s,c]=(0,d.useState)(`open`),l=(0,d.useRef)([]);return(0,d.useEffect)(()=>{l.current=a},[a]),(0,d.useEffect)(()=>{o([]),l.current=[]},[i,t,n,r]),(0,d.useEffect)(()=>{c(`open`);let i=l.current.slice(),a=i.map(le),s=0,u=i.length>0,d=`${r}?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,f=new EventSource(d);return f.onopen=()=>{console.info(`[admin-ui] wa-stream onopen sessionId=${e}`),c(`open`)},f.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(u){if(s<a.length&&le(t)===a[s]){s+=1;return}u=!1}o(e=>[...e,t])},f.onerror=()=>{f.readyState===2&&(console.error(`[admin-ui] wa-stream onerror readyState=${f.readyState}`),c(`error`))},()=>f.close()},[e,t,n,r,i]),{turns:a,status:s}}function le(e){return JSON.stringify(e)}var ue=e=>{if(!e)return 1/0;let t=new Date(e).getTime();return Number.isNaN(t)?1/0:t};function de(e,t){let n=[],r=0;return e.forEach((e,t)=>n.push({sort:ue(e.ts),sub:1,ins:r++,item:{kind:`turn`,turn:e,idx:t}})),t.forEach(e=>n.push({sort:ue(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 fe(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 pe=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 me(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function $({label:e,ts:t}){return(0,M.jsxs)(`div`,{className:`wa-turn-head`,children:[(0,M.jsx)(`span`,{className:`wa-who`,children:e}),(0,M.jsx)(`time`,{className:`wa-time`,children:Q(t)})]})}function he({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,M.jsxs)(`div`,{className:i,children:[(0,M.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,M.jsx)(`span`,{className:`wa-chevron`,children:t?`▾`:`▸`}),(0,M.jsx)(`span`,{className:`wa-who`,children:a}),(0,M.jsx)(`time`,{className:`wa-time`,children:Q(e.ts)})]}),t&&(0,M.jsx)(`pre`,{className:`wa-code`,children:o})]})}function ge({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,M.jsxs)(`div`,{className:`wa-turn wa-turn-directive`,children:[(0,M.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":r,onClick:s,children:[(0,M.jsx)(`span`,{className:`wa-chevron`,children:r?`▾`:`▸`}),(0,M.jsxs)(`span`,{className:`wa-who`,children:[`⚙ directive injected (`,e.len,` B)`]}),(0,M.jsx)(`time`,{className:`wa-time`,children:Q(e.ts)})]}),r&&(0,M.jsx)(`pre`,{className:`wa-code`,children:a??`Loading…`})]})}function _e(e,t){switch(e.kind){case`operator-inbound`:return(0,M.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,M.jsx)($,{label:`Operator${X(e.source)}`,ts:e.ts}),(0,M.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`operator-typed`:return(0,M.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,M.jsx)($,{label:`Operator (web)`,ts:e.ts}),(0,M.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-text`:return(0,M.jsxs)(`div`,{className:`wa-turn wa-turn-think`,children:[(0,M.jsx)($,{label:`Agent`,ts:e.ts}),(0,M.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-reply`:return(0,M.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,M.jsx)($,{label:`Agent`,ts:e.ts}),(0,M.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-reply-document`:return(0,M.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,M.jsx)($,{label:`Agent`,ts:e.ts}),(0,M.jsxs)(`p`,{className:`wa-doc`,children:[`📎 sent document(s): `,e.files.map(me).join(`, `)]}),e.caption&&(0,M.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`tool-call`:case`tool-result`:return(0,M.jsx)(he,{turn:e},t);case`agent-error`:return(0,M.jsxs)(`div`,{className:`wa-turn wa-turn-error`,role:`alert`,children:[(0,M.jsx)($,{label:`Agent`,ts:e.ts}),(0,M.jsx)(`p`,{className:`wa-body wa-error-body`,children:Y(e.code,`admin`)}),e.code===`agent_error`&&e.raw&&(0,M.jsx)(`pre`,{className:`wa-code`,children:e.raw})]},t)}}function ve(e,t,n){return e.map((e,r)=>e.kind===`turn`?_e(e.turn,r):(0,M.jsx)(ge,{entry:e.entry,sessionId:t,sessionKey:n},r))}var ye=`maxy:whatsapp-reader:clean-view`;function be(e){return e.filter(e=>e.kind===`turn`&&pe.has(e.turn.kind))}function xe({sessionId:e,projectDir:t,sessionKey:n,renderItems:r=ve,cleanViewToggle:i=!1,forceDeliveredOnly:a=!1,streamEndpoint:o=`/api/whatsapp-reader/stream`,suppressDirectives:s=!1,tail:c=null,resetKey:l}){let{turns:u,status:f}=Z(e,t,n,o,l),p=de(u,fe(e,n,!s)),[m,h]=(0,d.useState)(()=>{if(typeof window>`u`)return!1;try{return window.localStorage.getItem(ye)===`1`}catch{return!1}}),g=()=>h(e=>{let t=!e;try{window.localStorage.setItem(ye,t?`1`:`0`)}catch{}return t}),_=a||i&&m?be(p):p,v=(0,d.useRef)(null),y=(0,d.useRef)(!0),[b,x]=(0,d.useState)(!0),S=e=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight<=32;y.current=t,x(e=>e===t?e:t)};return(0,d.useLayoutEffect)(()=>{let e=v.current;e&&y.current&&(e.scrollTop=e.scrollHeight)},[u,m,c!=null]),(0,M.jsxs)(`div`,{className:`wa-reader${i?` wa-reader--clean-toggle`:``}`,children:[(0,M.jsx)(`div`,{className:`wa-reader-thread`,ref:v,onScroll:()=>{let e=v.current;e&&S(e)},children:(0,M.jsxs)(`div`,{className:`wa-thread-scroll`,children:[f===`error`&&(0,M.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),u.length===0&&f===`open`&&(0,M.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),r(_,e,n),c]})}),!b&&(0,M.jsx)(`button`,{type:`button`,className:`wa-jump`,onClick:()=>{let e=v.current;e&&(e.scrollTop=e.scrollHeight,y.current=!0,x(!0))},"aria-label":`Jump to latest message`,title:`Jump to latest message`,children:`↓`}),i&&!a&&(0,M.jsxs)(`button`,{type:`button`,className:`wa-clean-toggle${m?` is-active`:``}`,role:`switch`,"aria-checked":m,onClick:g,title:m?`Showing delivered messages only — click to show tool calls, results, and narration`:`Hide tool calls, results, and narration — show delivered messages only`,children:[(0,M.jsx)(`span`,{className:`wa-clean-label`,children:`Messages only`}),(0,M.jsx)(`span`,{className:`wa-switch`,"aria-hidden":`true`,children:(0,M.jsx)(`span`,{className:`wa-switch-thumb`})})]})]})}function Se(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 Ce({conversations:e,sessionKey:t,onBack:n}){let[r,i]=(0,d.useState)(null),a=W(e);return r?(0,M.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,M.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,M.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>i(null),"aria-label":`Back to conversations`,children:[(0,M.jsx)(x,{size:16}),` Back`]}),(0,M.jsx)(`span`,{className:`op-conv-title`,children:G(r)})]}),(0,M.jsx)(xe,{sessionId:r.sessionId,projectDir:r.projectDir,sessionKey:t,forceDeliveredOnly:!0},r.sessionId)]}):(0,M.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,M.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,M.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,M.jsx)(x,{size:16}),` Chat`]}),(0,M.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),a.map(e=>(0,M.jsxs)(`div`,{className:`op-conv-group`,children:[(0,M.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,M.jsx)(V,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,M.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,M.jsx)(`span`,{className:`op-conv-name`,children:G(e)}),e.modelGated&&(0,M.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,M.jsx)(A,{size:13})}),(0,M.jsx)(`span`,{className:`op-conv-when`,children:Se(e.lastMessageAt)})]},e.sessionId))]},e.channel))]})}export{x as C,y as E,C as S,_ as T,O as _,Q as a,T as b,K as c,V as d,L as f,k as g,j as h,me as i,G as l,I as m,ge as n,X as o,P as p,xe as r,Y as s,Ce as t,z as u,se as v,b as w,w as x,E as y};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CAM3fms7.js";import{l as t,o as n,u as r}from"./brand-BQ_u9UdS.js";import{f as i,r as a}from"./OperatorConversations-hm0Gpu_Q.js";import{n as o,t as s}from"./AdminLoginScreens-B8s2TbT7.js";import"./admin-types-D2qTXuCg.js";import{n as c,t as l}from"./AdminShell-Cu1zlb6L.js";import"./useSelectionMode-Bf6Rt-sl.js";import"./Checkbox-B_sOAyv1.js";var u=t(),d=e(r(),1),f=n();function p({onOpen:e}){return(0,f.jsx)(`footer`,{className:`admin-footer`,children:(0,f.jsxs)(`div`,{className:`powered-by`,role:`button`,tabIndex:0,onClick:e,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},"aria-label":`Powered by Claude Code — show details`,children:[(0,f.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,f.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function m(){let e=o(),[t,n]=(0,d.useState)(!1);(0,d.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,d.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);return}let r=Date.now();try{let t=await fetch(`/api/admin/claude-info`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),u=(0,d.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`chat`?(0,f.jsx)(i,{cacheKey:e.cacheKey,onSessionExpired:u,surface:`chat`,children:(0,f.jsx)(l,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,onDisconnect:e.handleDisconnect,disconnecting:e.disconnecting,userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(p,{onOpen:r}),(0,f.jsx)(c,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,f.jsx)(f.Fragment,{children:t.selectedWhatsapp&&e.cacheKey?(0,f.jsx)(a,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,cleanViewToggle:!0},t.selectedWhatsapp.sessionId):(0,f.jsx)(`main`,{})})})}):(0,f.jsx)(s,{auth:e})}(0,u.createRoot)(document.getElementById(`root`)).render((0,f.jsx)(m,{}));
1
+ import{o as e}from"./chunk-CAM3fms7.js";import{l as t,o as n,u as r}from"./brand-CYjs10m-.js";import{p as i,r as a}from"./OperatorConversations-DulQyF8c.js";import{n as o,t as s}from"./AdminLoginScreens-DgwQi3HN.js";import"./admin-types-D2qTXuCg.js";import{n as c,t as l}from"./AdminShell-DQfL2c_L.js";import"./useSelectionMode-Cs-vtuKI.js";import"./Checkbox-C54JSreC.js";var u=t(),d=e(r(),1),f=n();function p({onOpen:e}){return(0,f.jsx)(`footer`,{className:`admin-footer`,children:(0,f.jsxs)(`div`,{className:`powered-by`,role:`button`,tabIndex:0,onClick:e,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},"aria-label":`Powered by Claude Code — show details`,children:[(0,f.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,f.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function m(){let e=o(),[t,n]=(0,d.useState)(!1);(0,d.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,d.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);return}let r=Date.now();try{let t=await fetch(`/api/admin/claude-info`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),u=(0,d.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`chat`?(0,f.jsx)(i,{cacheKey:e.cacheKey,onSessionExpired:u,surface:`chat`,children:(0,f.jsx)(l,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,onDisconnect:e.handleDisconnect,disconnecting:e.disconnecting,userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(p,{onOpen:r}),(0,f.jsx)(c,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,f.jsx)(f.Fragment,{children:t.selectedWhatsapp&&e.cacheKey?(0,f.jsx)(a,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,cleanViewToggle:!0},t.selectedWhatsapp.sessionId):(0,f.jsx)(`main`,{})})})}):(0,f.jsx)(s,{auth:e})}(0,u.createRoot)(document.getElementById(`root`)).render((0,f.jsx)(m,{}));