@tom2012/cc-web 2026.4.19-d → 2026.4.19-f

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 (45) hide show
  1. package/README.md +1 -1
  2. package/backend/dist/adapters/claude-adapter.d.ts.map +1 -1
  3. package/backend/dist/adapters/claude-adapter.js +8 -1
  4. package/backend/dist/adapters/claude-adapter.js.map +1 -1
  5. package/backend/dist/approval-manager.d.ts +56 -0
  6. package/backend/dist/approval-manager.d.ts.map +1 -0
  7. package/backend/dist/approval-manager.js +164 -0
  8. package/backend/dist/approval-manager.js.map +1 -0
  9. package/backend/dist/hooks-manager.d.ts.map +1 -1
  10. package/backend/dist/hooks-manager.js +5 -1
  11. package/backend/dist/hooks-manager.js.map +1 -1
  12. package/backend/dist/index.d.ts.map +1 -1
  13. package/backend/dist/index.js +37 -1
  14. package/backend/dist/index.js.map +1 -1
  15. package/backend/dist/routes/approval.d.ts +3 -0
  16. package/backend/dist/routes/approval.d.ts.map +1 -0
  17. package/backend/dist/routes/approval.js +110 -0
  18. package/backend/dist/routes/approval.js.map +1 -0
  19. package/bin/ccweb-approval-hook.js +164 -0
  20. package/frontend/dist/assets/{GraphPreview-C5CcQObB.js → GraphPreview-RMEusMG8.js} +1 -1
  21. package/frontend/dist/assets/{MobilePage-6cREwmBa.js → MobilePage-DI2GWmXu.js} +4 -4
  22. package/frontend/dist/assets/{OfficePreview--1oOT9ZU.js → OfficePreview-DhG_GTdh.js} +2 -2
  23. package/frontend/dist/assets/{PlanPanel-CdSWGxcV.js → PlanPanel-CtCHWYx-.js} +2 -2
  24. package/frontend/dist/assets/{ProjectPage-Cf4g2qQ-.js → ProjectPage-BOF7_R1T.js} +6 -5
  25. package/frontend/dist/assets/SettingsPage-B9cZ9ykt.js +13 -0
  26. package/frontend/dist/assets/{ShareViewPage-kZMLxzcO.js → ShareViewPage-CxcUvORy.js} +1 -1
  27. package/frontend/dist/assets/{SkillHubPage-D2ndKohD.js → SkillHubPage-DhLUhSs2.js} +2 -2
  28. package/frontend/dist/assets/{bot-DvJ1HJ6o.js → bot-C3RUjsqW.js} +1 -1
  29. package/frontend/dist/assets/{chevron-down-DPoGo9Zk.js → chevron-down-DmsFFh73.js} +1 -1
  30. package/frontend/dist/assets/{chevron-up-BTJoI0tp.js → chevron-up-BCADZN87.js} +1 -1
  31. package/frontend/dist/assets/index-BYbgF__N.js +7 -0
  32. package/frontend/dist/assets/{index-CSDDVTf8.js → index-Bo1P_QVB.js} +8 -8
  33. package/frontend/dist/assets/index-Ccjr2Crc.css +1 -0
  34. package/frontend/dist/assets/{index-D1Xu7j2q.js → index-eg0a81dE.js} +1 -1
  35. package/frontend/dist/assets/{jszip.min-B5bWTUER.js → jszip.min-CoiRZgCR.js} +1 -1
  36. package/frontend/dist/assets/{matter-BiBUyTZL.js → matter-D6f5Kom-.js} +1 -1
  37. package/frontend/dist/assets/{maximize-2-2QtBGqNT.js → maximize-2-CAmCtjHc.js} +1 -1
  38. package/frontend/dist/assets/{one-light-CYgSBsrf.js → one-light-C34ikLD_.js} +1 -1
  39. package/frontend/dist/assets/{search-DhudjqqR.js → search-D-xImURd.js} +1 -1
  40. package/frontend/dist/assets/{user-B0_zs2Ff.js → user-BtMw83sS.js} +1 -1
  41. package/frontend/dist/index.html +2 -2
  42. package/package.json +1 -1
  43. package/frontend/dist/assets/SettingsPage-aitdnrNZ.js +0 -13
  44. package/frontend/dist/assets/index-CSO7BFUu.css +0 -1
  45. package/frontend/dist/assets/save-d1zUSkQ5.js +0 -7
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const express_1 = require("express");
4
+ const approval_manager_1 = require("../approval-manager");
5
+ const auth_1 = require("../auth");
6
+ const config_1 = require("../config");
7
+ function canDecideApproval(projectId, username) {
8
+ if ((0, config_1.isAdminUser)(username))
9
+ return true;
10
+ const project = (0, config_1.getProject)(projectId);
11
+ if (!project)
12
+ return false;
13
+ if ((0, config_1.isProjectOwner)(project, username))
14
+ return true;
15
+ const share = project.shares?.find((s) => s.username === username);
16
+ return share?.permission === 'edit';
17
+ }
18
+ const router = (0, express_1.Router)();
19
+ // Hook-facing timeout. Chain: settings.json timeout=120s → hook script 112s → backend 110s.
20
+ // Backend must resolve first so the hook always gets a clean HTTP response; 10s cushion.
21
+ const HOOK_TIMEOUT_MS = 110000;
22
+ /** Only accept hook requests from localhost loopback. */
23
+ function isLoopback(req) {
24
+ const addr = req.socket.remoteAddress || '';
25
+ return addr === '127.0.0.1' || addr === '::1' || addr === '::ffff:127.0.0.1';
26
+ }
27
+ function badSignature(req, payload) {
28
+ const sig = (req.header('x-ccweb-signature') || '').trim();
29
+ if (!sig)
30
+ return true;
31
+ return !approval_manager_1.approvalManager.verify(payload, sig);
32
+ }
33
+ /**
34
+ * POST /api/hooks/approval-request
35
+ * Called by ccweb-approval-hook.js. Blocks until the user decides or timeout.
36
+ * Auth: loopback + HMAC signature of the raw JSON body.
37
+ */
38
+ router.post('/hooks/approval-request', async (req, res) => {
39
+ if (!isLoopback(req)) {
40
+ res.status(403).json({ error: 'loopback only' });
41
+ return;
42
+ }
43
+ // Require exact raw bytes — never fall back to JSON.stringify (would silently mismatch HMAC).
44
+ const rawBuf = req.rawBody;
45
+ if (!rawBuf) {
46
+ res.status(400).json({ error: 'raw body missing' });
47
+ return;
48
+ }
49
+ const raw = rawBuf.toString('utf-8');
50
+ if (badSignature(req, raw)) {
51
+ res.status(401).json({ error: 'bad signature' });
52
+ return;
53
+ }
54
+ const { projectId, toolUseId, toolName, toolInput, sessionId } = (req.body ?? {});
55
+ if (!projectId || !toolUseId || !toolName) {
56
+ res.status(400).json({ error: 'projectId, toolUseId, toolName required' });
57
+ return;
58
+ }
59
+ // If the hook's TCP connection drops before we resolve, cancel the pending
60
+ // entry so it doesn't keep showing in the UI and doesn't fire a timeout.
61
+ let responded = false;
62
+ req.on('close', () => {
63
+ if (!responded)
64
+ approval_manager_1.approvalManager.cancel(projectId, toolUseId, 'client disconnected');
65
+ });
66
+ const decision = await approval_manager_1.approvalManager.register({ projectId, toolUseId, toolName, toolInput, sessionId: sessionId ?? '', createdAt: Date.now() }, HOOK_TIMEOUT_MS);
67
+ responded = true;
68
+ if (req.destroyed)
69
+ return;
70
+ res.json(decision);
71
+ });
72
+ /**
73
+ * POST /api/approval/:requestId/decide
74
+ * Called by the frontend when user clicks Allow/Deny.
75
+ * Auth: JWT (applied at router mount level).
76
+ * :requestId format is `projectId:toolUseId`.
77
+ */
78
+ router.post('/approval/:projectId/:toolUseId/decide', auth_1.authMiddleware, (req, res) => {
79
+ const { projectId, toolUseId } = req.params;
80
+ if (!canDecideApproval(projectId, req.user?.username)) {
81
+ res.status(403).json({ error: 'view-only collaborators cannot decide approvals' });
82
+ return;
83
+ }
84
+ const { behavior, message } = (req.body ?? {});
85
+ if (behavior !== 'allow' && behavior !== 'deny') {
86
+ res.status(400).json({ error: 'behavior must be allow or deny' });
87
+ return;
88
+ }
89
+ const ok = approval_manager_1.approvalManager.decide(projectId, toolUseId, { behavior, message });
90
+ if (!ok) {
91
+ res.status(404).json({ error: 'request not found or already resolved' });
92
+ return;
93
+ }
94
+ res.json({ ok: true });
95
+ });
96
+ /**
97
+ * GET /api/approval/:projectId/pending
98
+ * Returns pending approvals for a project (for overlay reconnect).
99
+ */
100
+ router.get('/approval/:projectId/pending', auth_1.authMiddleware, (req, res) => {
101
+ const { projectId } = req.params;
102
+ if (!canDecideApproval(projectId, req.user?.username)) {
103
+ // view-only users shouldn't see tool inputs either
104
+ res.json({ pending: [] });
105
+ return;
106
+ }
107
+ res.json({ pending: approval_manager_1.approvalManager.listPending(projectId) });
108
+ });
109
+ exports.default = router;
110
+ //# sourceMappingURL=approval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval.js","sourceRoot":"","sources":["../../src/routes/approval.ts"],"names":[],"mappings":";;AAAA,qCAAoD;AACpD,0DAA6E;AAC7E,kCAAsD;AACtD,sCAAoE;AAEpE,SAAS,iBAAiB,CAAC,SAAiB,EAAE,QAA4B;IACxE,IAAI,IAAA,oBAAW,EAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IACvC,MAAM,OAAO,GAAG,IAAA,mBAAU,EAAC,SAAS,CAAC,CAAC;IACtC,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3B,IAAI,IAAA,uBAAc,EAAC,OAAO,EAAE,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IACnD,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;IACnE,OAAO,KAAK,EAAE,UAAU,KAAK,MAAM,CAAC;AACtC,CAAC;AAED,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAC;AAExB,4FAA4F;AAC5F,yFAAyF;AACzF,MAAM,eAAe,GAAG,MAAO,CAAC;AAEhC,yDAAyD;AACzD,SAAS,UAAU,CAAC,GAAY;IAC9B,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,aAAa,IAAI,EAAE,CAAC;IAC5C,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,kBAAkB,CAAC;AAC/E,CAAC;AAED,SAAS,YAAY,CAAC,GAAY,EAAE,OAAe;IACjD,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC3D,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IACtB,OAAO,CAAC,kCAAe,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,IAAI,CAAC,yBAAyB,EAAE,KAAK,EAAE,GAAY,EAAE,GAAa,EAAiB,EAAE;IAC1F,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC;QAAC,OAAO;IAAC,CAAC;IAEnF,8FAA8F;IAC9F,MAAM,MAAM,GAAI,GAAuC,CAAC,OAAO,CAAC;IAChE,IAAI,CAAC,MAAM,EAAE,CAAC;QAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,kBAAkB,EAAE,CAAC,CAAC;QAAC,OAAO;IAAC,CAAC;IAC7E,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACrC,IAAI,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;QAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC;QAAC,OAAO;IAAC,CAAC;IAEzF,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAE/E,CAAC;IACF,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC1C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,yCAAyC,EAAE,CAAC,CAAC;QAC3E,OAAO;IACT,CAAC;IAED,2EAA2E;IAC3E,yEAAyE;IACzE,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;QACnB,IAAI,CAAC,SAAS;YAAE,kCAAe,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,qBAAqB,CAAC,CAAC;IACtF,CAAC,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAqB,MAAM,kCAAe,CAAC,QAAQ,CAC/D,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,EAChG,eAAe,CAChB,CAAC;IAEF,SAAS,GAAG,IAAI,CAAC;IACjB,IAAI,GAAG,CAAC,SAAS;QAAE,OAAO;IAC1B,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACrB,CAAC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,IAAI,CAAC,wCAAwC,EAAE,qBAAc,EAAE,CAAC,GAAgB,EAAE,GAAa,EAAQ,EAAE;IAC9G,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;IAC5C,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;QACtD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,iDAAiD,EAAE,CAAC,CAAC;QACnF,OAAO;IACT,CAAC;IACD,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAA4C,CAAC;IAC1F,IAAI,QAAQ,KAAK,OAAO,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;QAChD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,gCAAgC,EAAE,CAAC,CAAC;QAClE,OAAO;IACT,CAAC;IACD,MAAM,EAAE,GAAG,kCAAe,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IAC/E,IAAI,CAAC,EAAE,EAAE,CAAC;QAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,uCAAuC,EAAE,CAAC,CAAC;QAAC,OAAO;IAAC,CAAC;IAC9F,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AACzB,CAAC,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,GAAG,CAAC,8BAA8B,EAAE,qBAAc,EAAE,CAAC,GAAgB,EAAE,GAAa,EAAQ,EAAE;IACnG,MAAM,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;IACjC,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;QACtD,mDAAmD;QACnD,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;QAC1B,OAAO;IACT,CAAC;IACD,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,kCAAe,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;AAChE,CAAC,CAAC,CAAC;AAEH,kBAAe,MAAM,CAAC"}
@@ -0,0 +1,164 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * ccweb PermissionRequest hook
4
+ *
5
+ * Reads stdin JSON (Claude Code PermissionRequest hook payload), POSTs a signed
6
+ * request to ccweb backend (127.0.0.1 only), waits for the user's decision, and
7
+ * writes the canonical PermissionRequest hook output to stdout.
8
+ *
9
+ * Fails CLOSED: any error (network, timeout, bad secret, backend down) → deny.
10
+ * User can still approve in the terminal TUI if they disable this hook.
11
+ */
12
+
13
+ 'use strict';
14
+
15
+ const crypto = require('crypto');
16
+ const fs = require('fs');
17
+ const path = require('path');
18
+ const os = require('os');
19
+ const http = require('http');
20
+
21
+ const PORT_FILE = path.join(os.homedir(), '.ccweb', 'port');
22
+ const SECRET_FILE = path.join(os.homedir(), '.ccweb', 'approval-secret');
23
+ const PROJECTS_FILE = path.join(os.homedir(), '.ccweb', 'projects.json');
24
+ const REQUEST_TIMEOUT_MS = 112_000; // Sits between backend (110s) and settings.json ceiling (120s)
25
+
26
+ function failClosed(reason) {
27
+ // Explicit deny: used for backend-reachable errors where we don't want to
28
+ // silently let the TUI proceed (e.g. bad stdin, HMAC failure).
29
+ process.stdout.write(JSON.stringify({
30
+ hookSpecificOutput: {
31
+ hookEventName: 'PermissionRequest',
32
+ decision: { behavior: 'deny' },
33
+ message: `ccweb: ${reason}`,
34
+ },
35
+ }));
36
+ process.exit(0);
37
+ }
38
+
39
+ function passThroughToTui() {
40
+ // Empty output = Claude Code proceeds with its normal permission prompt.
41
+ // Used when ccweb isn't running / project isn't managed / config missing —
42
+ // i.e. situations where we should NOT interfere.
43
+ process.stdout.write('{}');
44
+ process.exit(0);
45
+ }
46
+
47
+ function readStdin() {
48
+ return new Promise((resolve) => {
49
+ let buf = '';
50
+ process.stdin.setEncoding('utf-8');
51
+ process.stdin.on('data', (chunk) => { buf += chunk; });
52
+ process.stdin.on('end', () => resolve(buf));
53
+ setTimeout(() => resolve(buf), 5000).unref(); // safety
54
+ });
55
+ }
56
+
57
+ function readFileSyncOrNull(p) {
58
+ try { return fs.readFileSync(p, 'utf-8'); } catch { return null; }
59
+ }
60
+
61
+ function resolveProjectId(cwd) {
62
+ const raw = readFileSyncOrNull(PROJECTS_FILE);
63
+ if (!raw) return null;
64
+ let projects;
65
+ try { projects = JSON.parse(raw); } catch { return null; }
66
+ if (!Array.isArray(projects)) return null;
67
+ // Exact folderPath match first; then prefix match (sub-directory of a registered project)
68
+ let best = null;
69
+ for (const p of projects) {
70
+ if (!p || !p.folderPath || !p.id) continue;
71
+ if (p.folderPath === cwd) return p.id;
72
+ if (cwd.startsWith(p.folderPath + path.sep) && (!best || p.folderPath.length > best.folderPath.length)) {
73
+ best = p;
74
+ }
75
+ }
76
+ return best ? best.id : null;
77
+ }
78
+
79
+ function postJson({ port, path: urlPath, body, signature }) {
80
+ return new Promise((resolve, reject) => {
81
+ const payload = Buffer.from(body, 'utf-8');
82
+ const opts = {
83
+ host: '127.0.0.1',
84
+ port,
85
+ path: urlPath,
86
+ method: 'POST',
87
+ headers: {
88
+ 'content-type': 'application/json',
89
+ 'content-length': payload.length,
90
+ 'x-ccweb-signature': signature,
91
+ },
92
+ timeout: REQUEST_TIMEOUT_MS,
93
+ };
94
+ const req = http.request(opts, (res) => {
95
+ let data = '';
96
+ res.setEncoding('utf-8');
97
+ res.on('data', (c) => { data += c; });
98
+ res.on('end', () => {
99
+ if (res.statusCode !== 200) { reject(new Error(`HTTP ${res.statusCode}: ${data.slice(0, 200)}`)); return; }
100
+ try { resolve(JSON.parse(data)); } catch (e) { reject(new Error(`Bad JSON from ccweb: ${e.message}`)); }
101
+ });
102
+ });
103
+ req.on('error', reject);
104
+ req.on('timeout', () => { req.destroy(new Error('backend request timeout')); });
105
+ req.write(payload);
106
+ req.end();
107
+ });
108
+ }
109
+
110
+ (async () => {
111
+ let input;
112
+ try {
113
+ const raw = await readStdin();
114
+ input = raw ? JSON.parse(raw) : {};
115
+ } catch (e) {
116
+ failClosed(`bad stdin: ${e.message}`);
117
+ return;
118
+ }
119
+
120
+ const toolUseId = input.tool_use_id || input.toolUseId;
121
+ const toolName = input.tool_name || input.toolName;
122
+ const toolInput = input.tool_input || input.toolInput || {};
123
+ const sessionId = input.session_id || input.sessionId || '';
124
+ const cwd = input.cwd || process.cwd();
125
+
126
+ if (!toolUseId || !toolName) { failClosed('missing tool_use_id or tool_name'); return; }
127
+
128
+ const projectId = resolveProjectId(cwd);
129
+ if (!projectId) { passThroughToTui(); return; } // not a ccweb project
130
+
131
+ const portStr = (readFileSyncOrNull(PORT_FILE) || '').trim();
132
+ const port = parseInt(portStr, 10);
133
+ if (!port) { passThroughToTui(); return; } // ccweb not running
134
+
135
+ const secret = (readFileSyncOrNull(SECRET_FILE) || '').trim();
136
+ if (!secret) { passThroughToTui(); return; } // no config yet
137
+
138
+ const body = JSON.stringify({ projectId, toolUseId, toolName, toolInput, sessionId });
139
+ const signature = crypto.createHmac('sha256', secret).update(body).digest('hex');
140
+
141
+ let decision;
142
+ try {
143
+ decision = await postJson({ port, path: '/api/hooks/approval-request', body, signature });
144
+ } catch (e) {
145
+ // Backend was supposed to be there but request failed — fall back to TUI
146
+ // rather than deny, since denying would block Claude on a transient blip.
147
+ passThroughToTui();
148
+ return;
149
+ }
150
+
151
+ const behavior = decision && decision.behavior === 'allow' ? 'allow' : 'deny';
152
+ const message = decision && typeof decision.message === 'string' ? decision.message : undefined;
153
+
154
+ // Per Claude Code hook spec, `message` is a sibling of `decision`, not nested inside it.
155
+ const out = {
156
+ hookSpecificOutput: {
157
+ hookEventName: 'PermissionRequest',
158
+ decision: { behavior },
159
+ ...(message ? { message } : {}),
160
+ },
161
+ };
162
+ process.stdout.write(JSON.stringify(out));
163
+ process.exit(0);
164
+ })().catch((err) => { failClosed(`unexpected: ${err && err.message || err}`); });
@@ -1,2 +1,2 @@
1
- import{r as e,a as t,j as n,am as i,B as r,k as o}from"./index-CSDDVTf8.js";import{Z as a,a as s}from"./ProjectPage-Cf4g2qQ-.js";import{M as l}from"./maximize-2-2QtBGqNT.js";import"./purify.es-CgRAQgUo.js";import"./one-light-CYgSBsrf.js";import"./save-d1zUSkQ5.js";import"./chevron-down-DPoGo9Zk.js";import"./bot-DvJ1HJ6o.js";import"./user-B0_zs2Ff.js";import"./search-DhudjqqR.js";import"./chevron-up-BTJoI0tp.js";
1
+ import{r as e,a as t,j as n,ap as i,B as r,m as o}from"./index-Bo1P_QVB.js";import{Z as a,a as s}from"./ProjectPage-BOF7_R1T.js";import{M as l}from"./maximize-2-CAmCtjHc.js";import"./purify.es-CgRAQgUo.js";import"./one-light-C34ikLD_.js";import"./index-BYbgF__N.js";import"./chevron-down-DmsFFh73.js";import"./bot-C3RUjsqW.js";import"./user-BtMw83sS.js";import"./search-D-xImURd.js";import"./chevron-up-BCADZN87.js";
2
2
  /*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT */function c(e){return null==e}var u={isNothing:c,isObject:function(e){return"object"==typeof e&&null!==e},toArray:function(e){return Array.isArray(e)?e:c(e)?[]:[e]},repeat:function(e,t){var n,i="";for(n=0;n<t;n+=1)i+=e;return i},isNegativeZero:function(e){return 0===e&&Number.NEGATIVE_INFINITY===1/e},extend:function(e,t){var n,i,r,o;if(t)for(n=0,i=(o=Object.keys(t)).length;n<i;n+=1)e[r=o[n]]=t[r];return e}};function p(e,t){var n="",i=e.reason||"(unknown reason)";return e.mark?(e.mark.name&&(n+='in "'+e.mark.name+'" '),n+="("+(e.mark.line+1)+":"+(e.mark.column+1)+")",!t&&e.mark.snippet&&(n+="\n\n"+e.mark.snippet),i+" "+n):i}function f(e,t){Error.call(this),this.name="YAMLException",this.reason=e,this.mark=t,this.message=p(this,!1),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack||""}f.prototype=Object.create(Error.prototype),f.prototype.constructor=f,f.prototype.toString=function(e){return this.name+": "+p(this,e)};var h=f;function d(e,t,n,i,r){var o="",a="",s=Math.floor(r/2)-1;return i-t>s&&(t=i-s+(o=" ... ").length),n-i>s&&(n=i+s-(a=" ...").length),{str:o+e.slice(t,n).replace(/\t/g,"→")+a,pos:i-t+o.length}}function m(e,t){return u.repeat(" ",t-e.length)+e}var g=function(e,t){if(t=Object.create(t||null),!e.buffer)return null;t.maxLength||(t.maxLength=79),"number"!=typeof t.indent&&(t.indent=1),"number"!=typeof t.linesBefore&&(t.linesBefore=3),"number"!=typeof t.linesAfter&&(t.linesAfter=2);for(var n,i=/\r?\n|\r|\0/g,r=[0],o=[],a=-1;n=i.exec(e.buffer);)o.push(n.index),r.push(n.index+n[0].length),e.position<=n.index&&a<0&&(a=r.length-2);a<0&&(a=r.length-1);var s,l,c="",p=Math.min(e.line+t.linesAfter,o.length).toString().length,f=t.maxLength-(t.indent+p+3);for(s=1;s<=t.linesBefore&&!(a-s<0);s++)l=d(e.buffer,r[a-s],o[a-s],e.position-(r[a]-r[a-s]),f),c=u.repeat(" ",t.indent)+m((e.line-s+1).toString(),p)+" | "+l.str+"\n"+c;for(l=d(e.buffer,r[a],o[a],e.position,f),c+=u.repeat(" ",t.indent)+m((e.line+1).toString(),p)+" | "+l.str+"\n",c+=u.repeat("-",t.indent+p+3+l.pos)+"^\n",s=1;s<=t.linesAfter&&!(a+s>=o.length);s++)l=d(e.buffer,r[a+s],o[a+s],e.position-(r[a]-r[a+s]),f),c+=u.repeat(" ",t.indent)+m((e.line+s+1).toString(),p)+" | "+l.str+"\n";return c.replace(/\n$/,"")},b=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],y=["scalar","sequence","mapping"];var x=function(e,t){var n,i;if(t=t||{},Object.keys(t).forEach(function(t){if(-1===b.indexOf(t))throw new h('Unknown option "'+t+'" is met in definition of "'+e+'" YAML type.')}),this.options=t,this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(e){return e},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=(n=t.styleAliases||null,i={},null!==n&&Object.keys(n).forEach(function(e){n[e].forEach(function(t){i[String(t)]=e})}),i),-1===y.indexOf(this.kind))throw new h('Unknown kind "'+this.kind+'" is specified for "'+e+'" YAML type.')};function A(e,t){var n=[];return e[t].forEach(function(e){var t=n.length;n.forEach(function(n,i){n.tag===e.tag&&n.kind===e.kind&&n.multi===e.multi&&(t=i)}),n[t]=e}),n}function v(e){return this.extend(e)}v.prototype.extend=function(e){var t=[],n=[];if(e instanceof x)n.push(e);else if(Array.isArray(e))n=n.concat(e);else{if(!e||!Array.isArray(e.implicit)&&!Array.isArray(e.explicit))throw new h("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");e.implicit&&(t=t.concat(e.implicit)),e.explicit&&(n=n.concat(e.explicit))}t.forEach(function(e){if(!(e instanceof x))throw new h("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(e.loadKind&&"scalar"!==e.loadKind)throw new h("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");if(e.multi)throw new h("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.")}),n.forEach(function(e){if(!(e instanceof x))throw new h("Specified list of YAML types (or a single Type object) contains a non-Type object.")});var i=Object.create(v.prototype);return i.implicit=(this.implicit||[]).concat(t),i.explicit=(this.explicit||[]).concat(n),i.compiledImplicit=A(i,"implicit"),i.compiledExplicit=A(i,"explicit"),i.compiledTypeMap=function(){var e,t,n={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}};function i(e){e.multi?(n.multi[e.kind].push(e),n.multi.fallback.push(e)):n[e.kind][e.tag]=n.fallback[e.tag]=e}for(e=0,t=arguments.length;e<t;e+=1)arguments[e].forEach(i);return n}(i.compiledImplicit,i.compiledExplicit),i};var k=new v({explicit:[new x("tag:yaml.org,2002:str",{kind:"scalar",construct:function(e){return null!==e?e:""}}),new x("tag:yaml.org,2002:seq",{kind:"sequence",construct:function(e){return null!==e?e:[]}}),new x("tag:yaml.org,2002:map",{kind:"mapping",construct:function(e){return null!==e?e:{}}})]});var w=new x("tag:yaml.org,2002:null",{kind:"scalar",resolve:function(e){if(null===e)return!0;var t=e.length;return 1===t&&"~"===e||4===t&&("null"===e||"Null"===e||"NULL"===e)},construct:function(){return null},predicate:function(e){return null===e},represent:{canonical:function(){return"~"},lowercase:function(){return"null"},uppercase:function(){return"NULL"},camelcase:function(){return"Null"},empty:function(){return""}},defaultStyle:"lowercase"});var C=new x("tag:yaml.org,2002:bool",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t=e.length;return 4===t&&("true"===e||"True"===e||"TRUE"===e)||5===t&&("false"===e||"False"===e||"FALSE"===e)},construct:function(e){return"true"===e||"True"===e||"TRUE"===e},predicate:function(e){return"[object Boolean]"===Object.prototype.toString.call(e)},represent:{lowercase:function(e){return e?"true":"false"},uppercase:function(e){return e?"TRUE":"FALSE"},camelcase:function(e){return e?"True":"False"}},defaultStyle:"lowercase"});function j(e){return 48<=e&&e<=57||65<=e&&e<=70||97<=e&&e<=102}function I(e){return 48<=e&&e<=55}function N(e){return 48<=e&&e<=57}var S=new x("tag:yaml.org,2002:int",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,n=e.length,i=0,r=!1;if(!n)return!1;if("-"!==(t=e[i])&&"+"!==t||(t=e[++i]),"0"===t){if(i+1===n)return!0;if("b"===(t=e[++i])){for(i++;i<n;i++)if("_"!==(t=e[i])){if("0"!==t&&"1"!==t)return!1;r=!0}return r&&"_"!==t}if("x"===t){for(i++;i<n;i++)if("_"!==(t=e[i])){if(!j(e.charCodeAt(i)))return!1;r=!0}return r&&"_"!==t}if("o"===t){for(i++;i<n;i++)if("_"!==(t=e[i])){if(!I(e.charCodeAt(i)))return!1;r=!0}return r&&"_"!==t}}if("_"===t)return!1;for(;i<n;i++)if("_"!==(t=e[i])){if(!N(e.charCodeAt(i)))return!1;r=!0}return!(!r||"_"===t)},construct:function(e){var t,n=e,i=1;if(-1!==n.indexOf("_")&&(n=n.replace(/_/g,"")),"-"!==(t=n[0])&&"+"!==t||("-"===t&&(i=-1),t=(n=n.slice(1))[0]),"0"===n)return 0;if("0"===t){if("b"===n[1])return i*parseInt(n.slice(2),2);if("x"===n[1])return i*parseInt(n.slice(2),16);if("o"===n[1])return i*parseInt(n.slice(2),8)}return i*parseInt(n,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&e%1==0&&!u.isNegativeZero(e)},represent:{binary:function(e){return e>=0?"0b"+e.toString(2):"-0b"+e.toString(2).slice(1)},octal:function(e){return e>=0?"0o"+e.toString(8):"-0o"+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?"0x"+e.toString(16).toUpperCase():"-0x"+e.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),M=new RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");var O=/^[-+]?[0-9]+e/;var T=new x("tag:yaml.org,2002:float",{kind:"scalar",resolve:function(e){return null!==e&&!(!M.test(e)||"_"===e[e.length-1])},construct:function(e){var t,n;return n="-"===(t=e.replace(/_/g,"").toLowerCase())[0]?-1:1,"+-".indexOf(t[0])>=0&&(t=t.slice(1)),".inf"===t?1===n?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:".nan"===t?NaN:n*parseFloat(t,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&(e%1!=0||u.isNegativeZero(e))},represent:function(e,t){var n;if(isNaN(e))switch(t){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(t){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(t){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(u.isNegativeZero(e))return"-0.0";return n=e.toString(10),O.test(n)?n.replace("e",".e"):n},defaultStyle:"lowercase"}),E=k.extend({implicit:[w,C,S,T]}),L=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),F=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");var _=new x("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:function(e){return null!==e&&(null!==L.exec(e)||null!==F.exec(e))},construct:function(e){var t,n,i,r,o,a,s,l,c=0,u=null;if(null===(t=L.exec(e))&&(t=F.exec(e)),null===t)throw new Error("Date resolve error");if(n=+t[1],i=+t[2]-1,r=+t[3],!t[4])return new Date(Date.UTC(n,i,r));if(o=+t[4],a=+t[5],s=+t[6],t[7]){for(c=t[7].slice(0,3);c.length<3;)c+="0";c=+c}return t[9]&&(u=6e4*(60*+t[10]+ +(t[11]||0)),"-"===t[9]&&(u=-u)),l=new Date(Date.UTC(n,i,r,o,a,s,c)),u&&l.setTime(l.getTime()-u),l},instanceOf:Date,represent:function(e){return e.toISOString()}});var $=new x("tag:yaml.org,2002:merge",{kind:"scalar",resolve:function(e){return"<<"===e||null===e}}),Y="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";var D=new x("tag:yaml.org,2002:binary",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,n,i=0,r=e.length,o=Y;for(n=0;n<r;n++)if(!((t=o.indexOf(e.charAt(n)))>64)){if(t<0)return!1;i+=6}return i%8==0},construct:function(e){var t,n,i=e.replace(/[\r\n=]/g,""),r=i.length,o=Y,a=0,s=[];for(t=0;t<r;t++)t%4==0&&t&&(s.push(a>>16&255),s.push(a>>8&255),s.push(255&a)),a=a<<6|o.indexOf(i.charAt(t));return 0===(n=r%4*6)?(s.push(a>>16&255),s.push(a>>8&255),s.push(255&a)):18===n?(s.push(a>>10&255),s.push(a>>2&255)):12===n&&s.push(a>>4&255),new Uint8Array(s)},predicate:function(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)},represent:function(e){var t,n,i="",r=0,o=e.length,a=Y;for(t=0;t<o;t++)t%3==0&&t&&(i+=a[r>>18&63],i+=a[r>>12&63],i+=a[r>>6&63],i+=a[63&r]),r=(r<<8)+e[t];return 0===(n=o%3)?(i+=a[r>>18&63],i+=a[r>>12&63],i+=a[r>>6&63],i+=a[63&r]):2===n?(i+=a[r>>10&63],i+=a[r>>4&63],i+=a[r<<2&63],i+=a[64]):1===n&&(i+=a[r>>2&63],i+=a[r<<4&63],i+=a[64],i+=a[64]),i}}),U=Object.prototype.hasOwnProperty,q=Object.prototype.toString;var B=new x("tag:yaml.org,2002:omap",{kind:"sequence",resolve:function(e){if(null===e)return!0;var t,n,i,r,o,a=[],s=e;for(t=0,n=s.length;t<n;t+=1){if(i=s[t],o=!1,"[object Object]"!==q.call(i))return!1;for(r in i)if(U.call(i,r)){if(o)return!1;o=!0}if(!o)return!1;if(-1!==a.indexOf(r))return!1;a.push(r)}return!0},construct:function(e){return null!==e?e:[]}}),R=Object.prototype.toString;var z=new x("tag:yaml.org,2002:pairs",{kind:"sequence",resolve:function(e){if(null===e)return!0;var t,n,i,r,o,a=e;for(o=new Array(a.length),t=0,n=a.length;t<n;t+=1){if(i=a[t],"[object Object]"!==R.call(i))return!1;if(1!==(r=Object.keys(i)).length)return!1;o[t]=[r[0],i[r[0]]]}return!0},construct:function(e){if(null===e)return[];var t,n,i,r,o,a=e;for(o=new Array(a.length),t=0,n=a.length;t<n;t+=1)i=a[t],r=Object.keys(i),o[t]=[r[0],i[r[0]]];return o}}),W=Object.prototype.hasOwnProperty;var P=new x("tag:yaml.org,2002:set",{kind:"mapping",resolve:function(e){if(null===e)return!0;var t,n=e;for(t in n)if(W.call(n,t)&&null!==n[t])return!1;return!0},construct:function(e){return null!==e?e:{}}}),G=E.extend({implicit:[_,$],explicit:[D,B,z,P]}),Z=Object.prototype.hasOwnProperty,V=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/,X=/[\x85\u2028\u2029]/,H=/[,\[\]\{\}]/,K=/^(?:!|!!|![a-z\-]+!)$/i,J=/^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;function Q(e){return Object.prototype.toString.call(e)}function ee(e){return 10===e||13===e}function te(e){return 9===e||32===e}function ne(e){return 9===e||32===e||10===e||13===e}function ie(e){return 44===e||91===e||93===e||123===e||125===e}function re(e){var t;return 48<=e&&e<=57?e-48:97<=(t=32|e)&&t<=102?t-97+10:-1}function oe(e){return 120===e?2:117===e?4:85===e?8:0}function ae(e){return 48<=e&&e<=57?e-48:-1}function se(e){return 48===e?"\0":97===e?"":98===e?"\b":116===e||9===e?"\t":110===e?"\n":118===e?"\v":102===e?"\f":114===e?"\r":101===e?"":32===e?" ":34===e?'"':47===e?"/":92===e?"\\":78===e?"…":95===e?" ":76===e?"\u2028":80===e?"\u2029":""}function le(e){return e<=65535?String.fromCharCode(e):String.fromCharCode(55296+(e-65536>>10),56320+(e-65536&1023))}function ce(e,t,n){"__proto__"===t?Object.defineProperty(e,t,{configurable:!0,enumerable:!0,writable:!0,value:n}):e[t]=n}for(var ue=new Array(256),pe=new Array(256),fe=0;fe<256;fe++)ue[fe]=se(fe)?1:0,pe[fe]=se(fe);function he(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||G,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function de(e,t){var n={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return n.snippet=g(n),new h(t,n)}function me(e,t){throw de(e,t)}function ge(e,t){e.onWarning&&e.onWarning.call(null,de(e,t))}var be={YAML:function(e,t,n){var i,r,o;null!==e.version&&me(e,"duplication of %YAML directive"),1!==n.length&&me(e,"YAML directive accepts exactly one argument"),null===(i=/^([0-9]+)\.([0-9]+)$/.exec(n[0]))&&me(e,"ill-formed argument of the YAML directive"),r=parseInt(i[1],10),o=parseInt(i[2],10),1!==r&&me(e,"unacceptable YAML version of the document"),e.version=n[0],e.checkLineBreaks=o<2,1!==o&&2!==o&&ge(e,"unsupported YAML version of the document")},TAG:function(e,t,n){var i,r;2!==n.length&&me(e,"TAG directive accepts exactly two arguments"),i=n[0],r=n[1],K.test(i)||me(e,"ill-formed tag handle (first argument) of the TAG directive"),Z.call(e.tagMap,i)&&me(e,'there is a previously declared suffix for "'+i+'" tag handle'),J.test(r)||me(e,"ill-formed tag prefix (second argument) of the TAG directive");try{r=decodeURIComponent(r)}catch(o){me(e,"tag prefix is malformed: "+r)}e.tagMap[i]=r}};function ye(e,t,n,i){var r,o,a,s;if(t<n){if(s=e.input.slice(t,n),i)for(r=0,o=s.length;r<o;r+=1)9===(a=s.charCodeAt(r))||32<=a&&a<=1114111||me(e,"expected valid JSON character");else V.test(s)&&me(e,"the stream contains non-printable characters");e.result+=s}}function xe(e,t,n,i){var r,o,a,s;for(u.isObject(n)||me(e,"cannot merge mappings; the provided source object is unacceptable"),a=0,s=(r=Object.keys(n)).length;a<s;a+=1)o=r[a],Z.call(t,o)||(ce(t,o,n[o]),i[o]=!0)}function Ae(e,t,n,i,r,o,a,s,l){var c,u;if(Array.isArray(r))for(c=0,u=(r=Array.prototype.slice.call(r)).length;c<u;c+=1)Array.isArray(r[c])&&me(e,"nested arrays are not supported inside keys"),"object"==typeof r&&"[object Object]"===Q(r[c])&&(r[c]="[object Object]");if("object"==typeof r&&"[object Object]"===Q(r)&&(r="[object Object]"),r=String(r),null===t&&(t={}),"tag:yaml.org,2002:merge"===i)if(Array.isArray(o))for(c=0,u=o.length;c<u;c+=1)xe(e,t,o[c],n);else xe(e,t,o,n);else e.json||Z.call(n,r)||!Z.call(t,r)||(e.line=a||e.line,e.lineStart=s||e.lineStart,e.position=l||e.position,me(e,"duplicated mapping key")),ce(t,r,o),delete n[r];return t}function ve(e){var t;10===(t=e.input.charCodeAt(e.position))?e.position++:13===t?(e.position++,10===e.input.charCodeAt(e.position)&&e.position++):me(e,"a line break is expected"),e.line+=1,e.lineStart=e.position,e.firstTabInLine=-1}function ke(e,t,n){for(var i=0,r=e.input.charCodeAt(e.position);0!==r;){for(;te(r);)9===r&&-1===e.firstTabInLine&&(e.firstTabInLine=e.position),r=e.input.charCodeAt(++e.position);if(t&&35===r)do{r=e.input.charCodeAt(++e.position)}while(10!==r&&13!==r&&0!==r);if(!ee(r))break;for(ve(e),r=e.input.charCodeAt(e.position),i++,e.lineIndent=0;32===r;)e.lineIndent++,r=e.input.charCodeAt(++e.position)}return-1!==n&&0!==i&&e.lineIndent<n&&ge(e,"deficient indentation"),i}function we(e){var t,n=e.position;return!(45!==(t=e.input.charCodeAt(n))&&46!==t||t!==e.input.charCodeAt(n+1)||t!==e.input.charCodeAt(n+2)||(n+=3,0!==(t=e.input.charCodeAt(n))&&!ne(t)))}function Ce(e,t){1===t?e.result+=" ":t>1&&(e.result+=u.repeat("\n",t-1))}function je(e,t){var n,i,r=e.tag,o=e.anchor,a=[],s=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=a),i=e.input.charCodeAt(e.position);0!==i&&(-1!==e.firstTabInLine&&(e.position=e.firstTabInLine,me(e,"tab characters must not be used in indentation")),45===i)&&ne(e.input.charCodeAt(e.position+1));)if(s=!0,e.position++,ke(e,!0,-1)&&e.lineIndent<=t)a.push(null),i=e.input.charCodeAt(e.position);else if(n=e.line,Se(e,t,3,!1,!0),a.push(e.result),ke(e,!0,-1),i=e.input.charCodeAt(e.position),(e.line===n||e.lineIndent>t)&&0!==i)me(e,"bad indentation of a sequence entry");else if(e.lineIndent<t)break;return!!s&&(e.tag=r,e.anchor=o,e.kind="sequence",e.result=a,!0)}function Ie(e){var t,n,i,r,o=!1,a=!1;if(33!==(r=e.input.charCodeAt(e.position)))return!1;if(null!==e.tag&&me(e,"duplication of a tag property"),60===(r=e.input.charCodeAt(++e.position))?(o=!0,r=e.input.charCodeAt(++e.position)):33===r?(a=!0,n="!!",r=e.input.charCodeAt(++e.position)):n="!",t=e.position,o){do{r=e.input.charCodeAt(++e.position)}while(0!==r&&62!==r);e.position<e.length?(i=e.input.slice(t,e.position),r=e.input.charCodeAt(++e.position)):me(e,"unexpected end of the stream within a verbatim tag")}else{for(;0!==r&&!ne(r);)33===r&&(a?me(e,"tag suffix cannot contain exclamation marks"):(n=e.input.slice(t-1,e.position+1),K.test(n)||me(e,"named tag handle cannot contain such characters"),a=!0,t=e.position+1)),r=e.input.charCodeAt(++e.position);i=e.input.slice(t,e.position),H.test(i)&&me(e,"tag suffix cannot contain flow indicator characters")}i&&!J.test(i)&&me(e,"tag name cannot contain such characters: "+i);try{i=decodeURIComponent(i)}catch(s){me(e,"tag name is malformed: "+i)}return o?e.tag=i:Z.call(e.tagMap,n)?e.tag=e.tagMap[n]+i:"!"===n?e.tag="!"+i:"!!"===n?e.tag="tag:yaml.org,2002:"+i:me(e,'undeclared tag handle "'+n+'"'),!0}function Ne(e){var t,n;if(38!==(n=e.input.charCodeAt(e.position)))return!1;for(null!==e.anchor&&me(e,"duplication of an anchor property"),n=e.input.charCodeAt(++e.position),t=e.position;0!==n&&!ne(n)&&!ie(n);)n=e.input.charCodeAt(++e.position);return e.position===t&&me(e,"name of an anchor node must contain at least one character"),e.anchor=e.input.slice(t,e.position),!0}function Se(e,t,n,i,r){var o,a,s,l,c,p,f,h,d,m=1,g=!1,b=!1;if(null!==e.listener&&e.listener("open",e),e.tag=null,e.anchor=null,e.kind=null,e.result=null,o=a=s=4===n||3===n,i&&ke(e,!0,-1)&&(g=!0,e.lineIndent>t?m=1:e.lineIndent===t?m=0:e.lineIndent<t&&(m=-1)),1===m)for(;Ie(e)||Ne(e);)ke(e,!0,-1)?(g=!0,s=o,e.lineIndent>t?m=1:e.lineIndent===t?m=0:e.lineIndent<t&&(m=-1)):s=!1;if(s&&(s=g||r),1!==m&&4!==n||(h=1===n||2===n?t:t+1,d=e.position-e.lineStart,1===m?s&&(je(e,d)||function(e,t,n){var i,r,o,a,s,l,c,u=e.tag,p=e.anchor,f={},h=Object.create(null),d=null,m=null,g=null,b=!1,y=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=f),c=e.input.charCodeAt(e.position);0!==c;){if(b||-1===e.firstTabInLine||(e.position=e.firstTabInLine,me(e,"tab characters must not be used in indentation")),i=e.input.charCodeAt(e.position+1),o=e.line,63!==c&&58!==c||!ne(i)){if(a=e.line,s=e.lineStart,l=e.position,!Se(e,n,2,!1,!0))break;if(e.line===o){for(c=e.input.charCodeAt(e.position);te(c);)c=e.input.charCodeAt(++e.position);if(58===c)ne(c=e.input.charCodeAt(++e.position))||me(e,"a whitespace character is expected after the key-value separator within a block mapping"),b&&(Ae(e,f,h,d,m,null,a,s,l),d=m=g=null),y=!0,b=!1,r=!1,d=e.tag,m=e.result;else{if(!y)return e.tag=u,e.anchor=p,!0;me(e,"can not read an implicit mapping pair; a colon is missed")}}else{if(!y)return e.tag=u,e.anchor=p,!0;me(e,"can not read a block mapping entry; a multiline key may not be an implicit key")}}else 63===c?(b&&(Ae(e,f,h,d,m,null,a,s,l),d=m=g=null),y=!0,b=!0,r=!0):b?(b=!1,r=!0):me(e,"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line"),e.position+=1,c=i;if((e.line===o||e.lineIndent>t)&&(b&&(a=e.line,s=e.lineStart,l=e.position),Se(e,t,4,!0,r)&&(b?m=e.result:g=e.result),b||(Ae(e,f,h,d,m,g,a,s,l),d=m=g=null),ke(e,!0,-1),c=e.input.charCodeAt(e.position)),(e.line===o||e.lineIndent>t)&&0!==c)me(e,"bad indentation of a mapping entry");else if(e.lineIndent<t)break}return b&&Ae(e,f,h,d,m,null,a,s,l),y&&(e.tag=u,e.anchor=p,e.kind="mapping",e.result=f),y}(e,d,h))||function(e,t){var n,i,r,o,a,s,l,c,u,p,f,h,d=!0,m=e.tag,g=e.anchor,b=Object.create(null);if(91===(h=e.input.charCodeAt(e.position)))a=93,c=!1,o=[];else{if(123!==h)return!1;a=125,c=!0,o={}}for(null!==e.anchor&&(e.anchorMap[e.anchor]=o),h=e.input.charCodeAt(++e.position);0!==h;){if(ke(e,!0,t),(h=e.input.charCodeAt(e.position))===a)return e.position++,e.tag=m,e.anchor=g,e.kind=c?"mapping":"sequence",e.result=o,!0;d?44===h&&me(e,"expected the node content, but found ','"):me(e,"missed comma between flow collection entries"),f=null,s=l=!1,63===h&&ne(e.input.charCodeAt(e.position+1))&&(s=l=!0,e.position++,ke(e,!0,t)),n=e.line,i=e.lineStart,r=e.position,Se(e,t,1,!1,!0),p=e.tag,u=e.result,ke(e,!0,t),h=e.input.charCodeAt(e.position),!l&&e.line!==n||58!==h||(s=!0,h=e.input.charCodeAt(++e.position),ke(e,!0,t),Se(e,t,1,!1,!0),f=e.result),c?Ae(e,o,b,p,u,f,n,i,r):s?o.push(Ae(e,null,b,p,u,f,n,i,r)):o.push(u),ke(e,!0,t),44===(h=e.input.charCodeAt(e.position))?(d=!0,h=e.input.charCodeAt(++e.position)):d=!1}me(e,"unexpected end of the stream within a flow collection")}(e,h)?b=!0:(a&&function(e,t){var n,i,r,o,a=1,s=!1,l=!1,c=t,p=0,f=!1;if(124===(o=e.input.charCodeAt(e.position)))i=!1;else{if(62!==o)return!1;i=!0}for(e.kind="scalar",e.result="";0!==o;)if(43===(o=e.input.charCodeAt(++e.position))||45===o)1===a?a=43===o?3:2:me(e,"repeat of a chomping mode identifier");else{if(!((r=ae(o))>=0))break;0===r?me(e,"bad explicit indentation width of a block scalar; it cannot be less than one"):l?me(e,"repeat of an indentation width identifier"):(c=t+r-1,l=!0)}if(te(o)){do{o=e.input.charCodeAt(++e.position)}while(te(o));if(35===o)do{o=e.input.charCodeAt(++e.position)}while(!ee(o)&&0!==o)}for(;0!==o;){for(ve(e),e.lineIndent=0,o=e.input.charCodeAt(e.position);(!l||e.lineIndent<c)&&32===o;)e.lineIndent++,o=e.input.charCodeAt(++e.position);if(!l&&e.lineIndent>c&&(c=e.lineIndent),ee(o))p++;else{if(e.lineIndent<c){3===a?e.result+=u.repeat("\n",s?1+p:p):1===a&&s&&(e.result+="\n");break}for(i?te(o)?(f=!0,e.result+=u.repeat("\n",s?1+p:p)):f?(f=!1,e.result+=u.repeat("\n",p+1)):0===p?s&&(e.result+=" "):e.result+=u.repeat("\n",p):e.result+=u.repeat("\n",s?1+p:p),s=!0,l=!0,p=0,n=e.position;!ee(o)&&0!==o;)o=e.input.charCodeAt(++e.position);ye(e,n,e.position,!1)}}return!0}(e,h)||function(e,t){var n,i,r;if(39!==(n=e.input.charCodeAt(e.position)))return!1;for(e.kind="scalar",e.result="",e.position++,i=r=e.position;0!==(n=e.input.charCodeAt(e.position));)if(39===n){if(ye(e,i,e.position,!0),39!==(n=e.input.charCodeAt(++e.position)))return!0;i=e.position,e.position++,r=e.position}else ee(n)?(ye(e,i,r,!0),Ce(e,ke(e,!1,t)),i=r=e.position):e.position===e.lineStart&&we(e)?me(e,"unexpected end of the document within a single quoted scalar"):(e.position++,r=e.position);me(e,"unexpected end of the stream within a single quoted scalar")}(e,h)||function(e,t){var n,i,r,o,a,s;if(34!==(s=e.input.charCodeAt(e.position)))return!1;for(e.kind="scalar",e.result="",e.position++,n=i=e.position;0!==(s=e.input.charCodeAt(e.position));){if(34===s)return ye(e,n,e.position,!0),e.position++,!0;if(92===s){if(ye(e,n,e.position,!0),ee(s=e.input.charCodeAt(++e.position)))ke(e,!1,t);else if(s<256&&ue[s])e.result+=pe[s],e.position++;else if((a=oe(s))>0){for(r=a,o=0;r>0;r--)(a=re(s=e.input.charCodeAt(++e.position)))>=0?o=(o<<4)+a:me(e,"expected hexadecimal character");e.result+=le(o),e.position++}else me(e,"unknown escape sequence");n=i=e.position}else ee(s)?(ye(e,n,i,!0),Ce(e,ke(e,!1,t)),n=i=e.position):e.position===e.lineStart&&we(e)?me(e,"unexpected end of the document within a double quoted scalar"):(e.position++,i=e.position)}me(e,"unexpected end of the stream within a double quoted scalar")}(e,h)?b=!0:!function(e){var t,n,i;if(42!==(i=e.input.charCodeAt(e.position)))return!1;for(i=e.input.charCodeAt(++e.position),t=e.position;0!==i&&!ne(i)&&!ie(i);)i=e.input.charCodeAt(++e.position);return e.position===t&&me(e,"name of an alias node must contain at least one character"),n=e.input.slice(t,e.position),Z.call(e.anchorMap,n)||me(e,'unidentified alias "'+n+'"'),e.result=e.anchorMap[n],ke(e,!0,-1),!0}(e)?function(e,t,n){var i,r,o,a,s,l,c,u,p=e.kind,f=e.result;if(ne(u=e.input.charCodeAt(e.position))||ie(u)||35===u||38===u||42===u||33===u||124===u||62===u||39===u||34===u||37===u||64===u||96===u)return!1;if((63===u||45===u)&&(ne(i=e.input.charCodeAt(e.position+1))||n&&ie(i)))return!1;for(e.kind="scalar",e.result="",r=o=e.position,a=!1;0!==u;){if(58===u){if(ne(i=e.input.charCodeAt(e.position+1))||n&&ie(i))break}else if(35===u){if(ne(e.input.charCodeAt(e.position-1)))break}else{if(e.position===e.lineStart&&we(e)||n&&ie(u))break;if(ee(u)){if(s=e.line,l=e.lineStart,c=e.lineIndent,ke(e,!1,-1),e.lineIndent>=t){a=!0,u=e.input.charCodeAt(e.position);continue}e.position=o,e.line=s,e.lineStart=l,e.lineIndent=c;break}}a&&(ye(e,r,o,!1),Ce(e,e.line-s),r=o=e.position,a=!1),te(u)||(o=e.position+1),u=e.input.charCodeAt(++e.position)}return ye(e,r,o,!1),!!e.result||(e.kind=p,e.result=f,!1)}(e,h,1===n)&&(b=!0,null===e.tag&&(e.tag="?")):(b=!0,null===e.tag&&null===e.anchor||me(e,"alias node should not have any properties")),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):0===m&&(b=s&&je(e,d))),null===e.tag)null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);else if("?"===e.tag){for(null!==e.result&&"scalar"!==e.kind&&me(e,'unacceptable node kind for !<?> tag; it should be "scalar", not "'+e.kind+'"'),l=0,c=e.implicitTypes.length;l<c;l+=1)if((f=e.implicitTypes[l]).resolve(e.result)){e.result=f.construct(e.result),e.tag=f.tag,null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);break}}else if("!"!==e.tag){if(Z.call(e.typeMap[e.kind||"fallback"],e.tag))f=e.typeMap[e.kind||"fallback"][e.tag];else for(f=null,l=0,c=(p=e.typeMap.multi[e.kind||"fallback"]).length;l<c;l+=1)if(e.tag.slice(0,p[l].tag.length)===p[l].tag){f=p[l];break}f||me(e,"unknown tag !<"+e.tag+">"),null!==e.result&&f.kind!==e.kind&&me(e,"unacceptable node kind for !<"+e.tag+'> tag; it should be "'+f.kind+'", not "'+e.kind+'"'),f.resolve(e.result,e.tag)?(e.result=f.construct(e.result,e.tag),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):me(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")}return null!==e.listener&&e.listener("close",e),null!==e.tag||null!==e.anchor||b}function Me(e){var t,n,i,r,o=e.position,a=!1;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);0!==(r=e.input.charCodeAt(e.position))&&(ke(e,!0,-1),r=e.input.charCodeAt(e.position),!(e.lineIndent>0||37!==r));){for(a=!0,r=e.input.charCodeAt(++e.position),t=e.position;0!==r&&!ne(r);)r=e.input.charCodeAt(++e.position);for(i=[],(n=e.input.slice(t,e.position)).length<1&&me(e,"directive name must not be less than one character in length");0!==r;){for(;te(r);)r=e.input.charCodeAt(++e.position);if(35===r){do{r=e.input.charCodeAt(++e.position)}while(0!==r&&!ee(r));break}if(ee(r))break;for(t=e.position;0!==r&&!ne(r);)r=e.input.charCodeAt(++e.position);i.push(e.input.slice(t,e.position))}0!==r&&ve(e),Z.call(be,n)?be[n](e,n,i):ge(e,'unknown document directive "'+n+'"')}ke(e,!0,-1),0===e.lineIndent&&45===e.input.charCodeAt(e.position)&&45===e.input.charCodeAt(e.position+1)&&45===e.input.charCodeAt(e.position+2)?(e.position+=3,ke(e,!0,-1)):a&&me(e,"directives end mark is expected"),Se(e,e.lineIndent-1,4,!1,!0),ke(e,!0,-1),e.checkLineBreaks&&X.test(e.input.slice(o,e.position))&&ge(e,"non-ASCII line breaks are interpreted as content"),e.documents.push(e.result),e.position===e.lineStart&&we(e)?46===e.input.charCodeAt(e.position)&&(e.position+=3,ke(e,!0,-1)):e.position<e.length-1&&me(e,"end of the stream or a document separator is expected")}var Oe={load:function(e,t){var n=function(e,t){t=t||{},0!==(e=String(e)).length&&(10!==e.charCodeAt(e.length-1)&&13!==e.charCodeAt(e.length-1)&&(e+="\n"),65279===e.charCodeAt(0)&&(e=e.slice(1)));var n=new he(e,t),i=e.indexOf("\0");for(-1!==i&&(n.position=i,me(n,"null byte is not allowed in input")),n.input+="\0";32===n.input.charCodeAt(n.position);)n.lineIndent+=1,n.position+=1;for(;n.position<n.length-1;)Me(n);return n.documents}(e,t);if(0!==n.length){if(1===n.length)return n[0];throw new h("expected a single document in the stream, but found more")}}}.load;function Te(e){var t;const n=e.pages||[],i=e.relations||[];if(0===n.length)return{nodes:[],edges:[]};const r=new Map,o=new Map;for(const h of n)r.set(h.id,[]),o.set(h.id,0);for(const h of i)null==(t=r.get(h.from))||t.push(h.to),o.set(h.to,(o.get(h.to)||0)+1);const a=new Map,s=[];for(const h of n)0===(o.get(h.id)||0)&&(s.push(h.id),a.set(h.id,0));let l=0;for(;s.length>0;){const e=s.shift(),t=a.get(e)||0;for(const n of r.get(e)||[]){const e=t+1;e>(a.get(n)||0)&&(a.set(n,e),e>l&&(l=e));const i=(o.get(n)||1)-1;o.set(n,i),i<=0&&s.push(n)}}for(const h of n)a.has(h.id)||a.set(h.id,l+1);const c=new Map;for(const h of n){const e=a.get(h.id)||0;c.has(e)||c.set(e,[]),c.get(e).push(h.id)}const u=[],p=new Map(n.map(e=>[e.id,e]));for(const[h,d]of c){const e=-(160*d.length+60*(d.length-1))/2;d.forEach((t,n)=>{const i=p.get(t);u.push({id:t,title:(null==i?void 0:i.title)||t,x:e+220*n+80,y:130*h,layer:h})})}const f=i.map(e=>({from:e.from,to:e.to,label:e.label}));return{nodes:u,edges:f}}const Ee=["#3b82f6","#8b5cf6","#ec4899","#f59e0b","#10b981","#06b6d4","#f97316","#6366f1"];function Le({folderPath:c}){const[u,p]=e.useState(null),[f,h]=e.useState(!0),[d,m]=e.useState(null),[g,b]=e.useState(1),[y,x]=e.useState({x:0,y:0}),A=e.useRef(!1),v=e.useRef({x:0,y:0}),[,k]=e.useState(0),w=e.useRef(null),C=e.useRef(null),j=`${c}/.notebook/graph.yaml`,I=e.useCallback(async()=>{h(!0),m(null);try{const e=await t(j);if(!e.content)return m("graph.yaml is empty"),void p(null);const n=Oe(e.content);p(n),b(1),x({x:0,y:0})}catch{m("Cannot read .notebook/graph.yaml"),p(null)}finally{h(!1)}},[j]);e.useEffect(()=>{I()},[I]);const N=e.useCallback(e=>{e.preventDefault();const t=e.deltaY>0?-.1:.1;b(e=>Math.max(.2,Math.min(3,e+t)))},[]),S=e.useCallback(e=>{0===e.button&&(A.current=!0,k(e=>e+1),x(t=>(v.current={x:e.clientX-t.x,y:e.clientY-t.y},t)))},[]),M=e.useCallback(e=>{A.current&&x({x:e.clientX-v.current.x,y:e.clientY-v.current.y})},[]),O=e.useCallback(()=>{A.current=!1,k(e=>e+1)},[]),T=e.useCallback(()=>{if(!u||!C.current)return;const{nodes:e}=Te(u);if(0===e.length)return;const t=Math.min(...e.map(e=>e.x))-100,n=Math.max(...e.map(e=>e.x))+100,i=Math.min(...e.map(e=>e.y))-40,r=Math.max(...e.map(e=>e.y))+60,o=n-t,a=r-i,s=C.current.clientWidth,l=C.current.clientHeight,c=.9*Math.min(s/o,l/a,1.5);b(c),x({x:s/2-(t+n)/2*c,y:l/2-(i+r)/2*c})},[u]),{nodes:E,edges:L}=e.useMemo(()=>u?Te(u):{nodes:[],edges:[]},[u]),F=e.useMemo(()=>new Map(E.map(e=>[e.id,e])),[E]);return e.useEffect(()=>{if(u&&!f){const e=setTimeout(T,50);return()=>clearTimeout(e)}},[u,f,T]),f?n.jsx("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:n.jsx(i,{className:"h-5 w-5 animate-spin"})}):d||!u?n.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-muted-foreground text-sm px-4 text-center",children:[n.jsx("p",{children:d||"No graph data"}),n.jsxs(r,{variant:"ghost",size:"sm",onClick:()=>{I()},children:[n.jsx(o,{className:"h-3 w-3 mr-1"})," Retry"]})]}):n.jsxs("div",{className:"flex flex-col h-full",children:[n.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 border-b shrink-0",children:[n.jsxs("span",{className:"text-xs text-muted-foreground mr-auto",children:[E.length," pages, ",L.length," relations"]}),n.jsx(r,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>b(e=>Math.min(3,e+.2)),children:n.jsx(a,{className:"h-3 w-3"})}),n.jsx(r,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>b(e=>Math.max(.2,e-.2)),children:n.jsx(s,{className:"h-3 w-3"})}),n.jsx(r,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:T,children:n.jsx(l,{className:"h-3 w-3"})}),n.jsx(r,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>{I()},children:n.jsx(o,{className:"h-3 w-3"})})]}),n.jsx("div",{ref:C,className:"flex-1 overflow-hidden cursor-grab active:cursor-grabbing bg-muted/30",onWheel:N,onMouseDown:S,onMouseMove:M,onMouseUp:O,onMouseLeave:O,children:n.jsxs("svg",{ref:w,width:"100%",height:"100%",style:{userSelect:"none"},children:[n.jsx("defs",{children:n.jsx("marker",{id:"arrowhead",viewBox:"0 0 10 7",refX:"10",refY:"3.5",markerWidth:"8",markerHeight:"6",orient:"auto",children:n.jsx("polygon",{points:"0 0, 10 3.5, 0 7",className:"fill-muted-foreground/60"})})}),n.jsxs("g",{transform:`translate(${y.x}, ${y.y}) scale(${g})`,children:[L.map((e,t)=>{const i=F.get(e.from),r=F.get(e.to);if(!i||!r)return null;const o=i.y+20,a=r.y-20,s=(o+a)/2;return n.jsxs("g",{children:[n.jsx("path",{d:`M ${i.x} ${o} C ${i.x} ${s}, ${r.x} ${s}, ${r.x} ${a}`,fill:"none",className:"stroke-muted-foreground/40",strokeWidth:1.5,markerEnd:"url(#arrowhead)"}),e.label&&n.jsx("text",{x:(i.x+r.x)/2,y:s-4,textAnchor:"middle",className:"fill-muted-foreground/60",fontSize:9,children:e.label})]},`edge-${t}`)}),E.map(e=>{const t=Ee[e.layer%Ee.length];return n.jsxs("g",{transform:`translate(${e.x-70}, ${e.y-18})`,children:[n.jsx("rect",{width:140,height:36,rx:8,fill:t,fillOpacity:.15,stroke:t,strokeWidth:1.5}),n.jsx("text",{x:70,y:19,textAnchor:"middle",dominantBaseline:"middle",className:"fill-foreground",fontSize:11,fontWeight:500,children:e.title.length>14?e.title.slice(0,13)+"…":e.title})]},e.id)})]})]})})]})}export{Le as GraphPreview};
@@ -1,14 +1,14 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/OfficePreview--1oOT9ZU.js","assets/index-CSDDVTf8.js","assets/index-CSO7BFUu.css","assets/purify.es-CgRAQgUo.js"])))=>i.map(i=>d[i]);
2
- import{c as e,ah as t,aA as s,r as n,bg as r,j as a,k as l,b as o,bh as c,a0 as i,$ as d,Q as u,U as x,t as m,au as h,bi as p,ao as f,ai as g,u as j,a as b,g as v,D as y,am as N,e as w,R as k,_ as C,i as S,X as _,n as z,bj as M,bk as P,C as T,A as E,o as $}from"./index-CSDDVTf8.js";import{C as I}from"./chevron-up-BTJoI0tp.js";import{M as D,a as R,S as A,r as O,b as L,h as U,o as B,c as F,I as H,F as q}from"./one-light-CYgSBsrf.js";import{C as W}from"./chevron-down-DPoGo9Zk.js";
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/OfficePreview-DhG_GTdh.js","assets/index-Bo1P_QVB.js","assets/index-Ccjr2Crc.css","assets/purify.es-CgRAQgUo.js"])))=>i.map(i=>d[i]);
2
+ import{c as e,ak as t,aM as s,r as n,bl as r,j as a,m as l,b as o,bm as c,a3 as i,a2 as d,W as u,Y as x,t as m,aG as h,bn as p,ar as f,al as g,u as j,a as b,g as v,D as y,ap as N,e as w,R as k,_ as C,l as S,X as _,q as z,bo as M,bp as P,C as T,A as E,v as I}from"./index-Bo1P_QVB.js";import{C as $}from"./chevron-up-BCADZN87.js";import{M as D,a as R,S as O,r as A,b as L,h as B,o as U,c as q,I as F,F as H}from"./one-light-C34ikLD_.js";import{C as W}from"./chevron-down-DmsFFh73.js";
3
3
  /**
4
4
  * @license lucide-react v0.309.0 - ISC
5
5
  *
6
6
  * This source code is licensed under the ISC license.
7
7
  * See the LICENSE file in the root directory of this source tree.
8
- */const K=e("Bookmark",[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}]]),V=e("FileCode",[["path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z",key:"1nnpy2"}],["polyline",{points:"14 2 14 8 20 8",key:"1ew0cm"}],["path",{d:"m10 13-2 2 2 2",key:"17smn8"}],["path",{d:"m14 17 2-2-2-2",key:"14mezr"}]]),G=e("FileJson",[["path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z",key:"1nnpy2"}],["polyline",{points:"14 2 14 8 20 8",key:"1ew0cm"}],["path",{d:"M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"1oajmo"}],["path",{d:"M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"mpwhp6"}]]),J=e("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"}]]),Q=e("Menu",[["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}],["line",{x1:"4",x2:"20",y1:"6",y2:"6",key:"1owob3"}],["line",{x1:"4",x2:"20",y1:"18",y2:"18",key:"yk5zj1"}]]),X=window.matchMedia("(pointer: coarse)").matches&&window.innerWidth<768;
8
+ */const K=e("Bookmark",[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}]]),V=e("FileCode",[["path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z",key:"1nnpy2"}],["polyline",{points:"14 2 14 8 20 8",key:"1ew0cm"}],["path",{d:"m10 13-2 2 2 2",key:"17smn8"}],["path",{d:"m14 17 2-2-2-2",key:"14mezr"}]]),G=e("FileJson",[["path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z",key:"1nnpy2"}],["polyline",{points:"14 2 14 8 20 8",key:"1ew0cm"}],["path",{d:"M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"1oajmo"}],["path",{d:"M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"mpwhp6"}]]),J=e("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"}]]),Y=e("Menu",[["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}],["line",{x1:"4",x2:"20",y1:"6",y2:"6",key:"1owob3"}],["line",{x1:"4",x2:"20",y1:"18",y2:"18",key:"yk5zj1"}]]),Q=window.matchMedia("(pointer: coarse)").matches&&window.innerWidth<768;
9
9
  /**
10
10
  * @license lucide-react v0.309.0 - ISC
11
11
  *
12
12
  * This source code is licensed under the ISC license.
13
13
  * See the LICENSE file in the root directory of this source tree.
14
- */function Y({onSelectProject:e}){const i=t(),{projects:d,fetchProjects:u,hasFetched:x,loading:m}=s(),[h,p]=n.useState(new Map),[f,g]=n.useState(new Set),[j,b]=n.useState(!1);n.useEffect(()=>{u()},[u]);const v=n.useCallback(e=>{e.status&&p(t=>{const s=new Map(t);return s.set(e.projectId,e.status),s}),void 0!==e.active&&g(t=>{const s=new Set(t);return e.active?s.add(e.projectId):s.delete(e.projectId),s})},[]);r({onActivityUpdate:v});const y=d.filter(e=>!e.archived);return a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsxs("div",{className:"flex items-center gap-3 px-4 h-12 border-b border-border shrink-0",children:[a.jsx("span",{className:"font-semibold text-base flex-1",children:"CC Web"}),a.jsx("button",{onClick:()=>{(async()=>{b(!0);try{await u()}finally{b(!1)}})()},className:"text-muted-foreground active:text-foreground",disabled:j,children:a.jsx(l,{className:o("h-4 w-4",j&&"animate-spin")})}),!X&&a.jsx("button",{onClick:()=>i("/"),className:"text-muted-foreground active:text-foreground",title:"桌面模式",children:a.jsx(c,{className:"h-4 w-4"})})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3",children:[m&&!x&&a.jsx("div",{className:"text-center text-muted-foreground text-sm py-12",children:"加载中..."}),x&&0===y.length&&a.jsx("div",{className:"text-center text-muted-foreground text-sm py-12",children:"暂无项目"}),a.jsx("div",{className:"grid grid-cols-2 gap-2",children:y.map(t=>{var s;const n="running"===(s=t,h.get(s.id)??s.status??"stopped"),r=f.has(t.id),l=a.jsxs("button",{onClick:()=>e(t.id),className:o("w-full text-left rounded-lg border bg-card p-2.5 active:bg-accent transition-colors",r?"border-transparent":"border-border"),children:[a.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[a.jsx("span",{className:o("w-2 h-2 rounded-full shrink-0",n?"bg-green-500":"bg-zinc-400")}),a.jsx("span",{className:"font-medium text-sm truncate flex-1",children:t.name})]}),a.jsx("div",{className:"text-[10px] text-muted-foreground font-mono truncate",children:t.cliTool??"claude"})]});return a.jsx("div",{className:r?"card-active-glow rounded-lg":void 0,children:l},t.id)})})]})]})}function Z({project:e,onBack:t,onOpenPanel:s,onContextUpdate:r}){const[l,c]=n.useState("running"===e.status?"live":"stopped"),[j,b]=n.useState([]),[v,y]=n.useState(""),N=n.useRef(null),w=n.useRef(null),k=n.useRef(null),C=n.useRef(!1),S=n.useRef([]),_=n.useRef(null),z=n.useRef(0),M=n.useRef([]),[P,T]=n.useState([]),[E,$]=n.useState(!1),O=n.useMemo(()=>[...P,...j],[P,j]),[L,U]=n.useState([]),[B,F]=n.useState([]),[H,q]=n.useState(null);n.useEffect(()=>{i().then(U).catch(()=>{}),d(e.id).then(F).catch(()=>{})},[e.id]);const V=n.useRef(0);V.current=j.length;const G=n.useCallback(async()=>{try{const t=await u(e.id,1);if(0===t.length)return;const s=(await x(e.id,t[0].id,"latest","user")).content.split(/(?=^## [UA]\d+)/m).filter(Boolean),n=[];for(const e of s){const t=e.match(/^## ([UA])(\d+).*\n/);if(!t)continue;const s="U"===t[1]?"user":"assistant",r=e.slice(t[0].length).trim();r&&n.push({role:s,content:r,ts:""})}0===V.current&&(M.current=n,T(n.slice(-20)),$(n.length>20))}catch{m.error("加载对话历史失败")}},[e.id]),X=n.useCallback(()=>{const e=M.current;if(0===e.length)return;const t=P.length,s=Math.min(t+20,e.length),n=N.current,r=(null==n?void 0:n.scrollHeight)??0;T(e.slice(-s)),$(s<e.length),requestAnimationFrame(()=>{if(n){const e=n.scrollHeight;n.scrollTop+=e-r}})},[P.length]);n.useEffect(()=>{"stopped"===l&&G()},[l,G]),n.useEffect(()=>{if("live"!==l)return void(C.current=!1);const e=setTimeout(()=>{C.current||G()},3e3);return()=>clearTimeout(e)},[l,G]),n.useEffect(()=>{"running"!==e.status||"stopped"!==l&&"error"!==l?"stopped"===e.status&&"live"===l&&c("stopped"):(b([]),c("live"))},[e.status]);const Y=n.useRef(null),Z=n.useCallback(()=>{Y.current&&(clearTimeout(Y.current.timer),Y.current=null)},[]);n.useEffect(()=>()=>Z(),[Z]);const ee=n.useCallback(e=>{C.current=!0;const t=h(e.blocks);if(t.trim()){if(Z(),"user"===e.role){const e=S.current.indexOf(t.trim());if(-1!==e)return void S.current.splice(e,1)}b(s=>[...s,{role:e.role,content:t,ts:e.timestamp}].slice(-50))}},[Z]),te=n.useCallback(e=>{"stopped"===e&&c("stopped")},[]),{sendInput:se}=p({projectId:e.id,enabled:"live"===l||"waking"===l,onChatMessage:ee,onStatusChange:te,onContextUpdate:r});n.useEffect(()=>{if("live"===l&&k.current){const e=k.current;k.current=null,se(e+"\r")}},[l,se]);const ne=n.useRef(0);n.useEffect(()=>{var e;null==(e=N.current)||e.scrollTo({top:N.current.scrollHeight,behavior:"smooth"})},[j]),n.useEffect(()=>{var e;0===ne.current&&P.length>0&&(null==(e=N.current)||e.scrollTo({top:N.current.scrollHeight})),ne.current=P.length},[P]),n.useEffect(()=>()=>{_.current&&clearTimeout(_.current)},[]);const re=n.useCallback(t=>{if(S.current.push(t),S.current.length>10&&S.current.shift(),b(e=>[...e,{role:"user",content:t,ts:(new Date).toISOString()}].slice(-50)),"live"===l||"waking"===l){se(t+"\r"),Z();const e=3,s=t=>{if(t>=e)return;const n=setTimeout(()=>{se("\r"),s(t+1)},3e3);Y.current={timer:n,attempts:t}};s(0)}else if("stopped"===l||"error"===l){k.current=t;const s=++z.current;c("waking"),f(e.id).then(()=>{s===z.current&&(_.current&&clearTimeout(_.current),c("live"))}).catch(e=>{s===z.current&&(m.error(`启动失败: ${e instanceof Error?e.message:String(e)}`),c("error"),k.current=null)}),_.current=setTimeout(()=>{s===z.current&&k.current&&(m.error("启动超时(10s)"),c("error"),k.current=null)},1e4)}},[l,e.id,se]),ae=n.useCallback(()=>{const e=v.trim();e&&(y(""),w.current&&(w.current.style.height="auto"),re(e))},[v,re]),le=n.useCallback(e=>{q(null),re(e)},[re]),oe="live"===l,ce="waking"===l;return a.jsxs("div",{className:"flex flex-col h-full bg-background",children:[a.jsxs("div",{className:"flex items-center gap-2 px-3 h-12 border-b border-border shrink-0",children:[a.jsx("button",{onClick:t,className:"text-muted-foreground active:text-foreground p-1",children:a.jsx(g,{className:"h-5 w-5"})}),a.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[a.jsx("span",{className:"font-medium text-sm truncate",children:e.name}),a.jsx("span",{className:o("w-2 h-2 rounded-full shrink-0",oe?"bg-green-500":ce?"bg-yellow-400 animate-pulse":"bg-zinc-400")})]}),a.jsx("button",{onClick:s,className:"text-muted-foreground active:text-foreground p-1",children:a.jsx(Q,{className:"h-5 w-5"})})]}),a.jsxs("div",{ref:N,className:"flex-1 overflow-y-auto px-3 py-3 space-y-3 min-h-0",children:[E&&a.jsx("div",{className:"flex justify-center pb-1",children:a.jsxs("button",{onClick:X,className:"flex items-center gap-1 px-3 py-1.5 rounded-full text-xs text-muted-foreground border border-border active:bg-accent transition-colors",children:[a.jsx(I,{className:"h-3 w-3"}),"加载更早消息"]})}),O.map((e,t)=>{const s="user"===e.role;return a.jsx("div",{className:o("flex",s?"justify-end":"justify-start"),children:a.jsx("div",{className:o("max-w-[85%] rounded-xl px-3 py-2 break-words text-sm leading-relaxed",s?"bg-blue-500/15 text-foreground border border-blue-500/20 rounded-br-sm whitespace-pre-wrap":"bg-secondary text-secondary-foreground border border-border rounded-bl-sm"),children:s?e.content:a.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none text-inherit [&_pre]:overflow-x-auto [&_pre]:max-w-full [&_pre]:text-xs [&_pre]:my-1 [&_pre]:p-2 [&_pre]:rounded [&_p]:my-1 [&_ul]:my-1 [&_ol]:my-1 [&_h1]:text-base [&_h2]:text-sm [&_h3]:text-sm [&_hr]:my-2 [&_code]:text-xs [&_code]:px-1 [&_code]:rounded [&_table]:text-xs [&_a]:text-blue-400",children:a.jsx(D,{remarkPlugins:[R],children:e.content})})})},`${e.role}-${e.ts||t}-${t}`)}),0===O.length&&"stopped"===l&&a.jsx("div",{className:"flex items-center justify-center h-full text-muted-foreground/40 text-sm",children:"暂无对话记录"}),ce&&a.jsx("div",{className:"flex items-center justify-center py-4 text-yellow-400 text-sm animate-pulse",children:"启动中..."})]}),H&&a.jsx("div",{className:"border-t border-border max-h-48 overflow-y-auto shrink-0",children:a.jsxs("div",{className:"px-3 py-2 space-y-1",children:[("global"===H?L:B).map(e=>a.jsxs("button",{onClick:()=>le(e.command),disabled:ce,className:o("w-full text-left rounded-md px-2.5 py-2 text-sm active:bg-accent transition-colors border border-border/50",ce&&"opacity-50 cursor-not-allowed"),children:[a.jsx("div",{className:"font-medium text-xs",children:e.label}),a.jsx("div",{className:"text-[11px] text-muted-foreground font-mono truncate",children:e.command})]},e.id)),0===("global"===H?L:B).length&&a.jsx("div",{className:"text-center text-muted-foreground text-xs py-3",children:"暂无快捷命令"})]})}),(L.length>0||B.length>0)&&a.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 border-t border-border shrink-0",children:[a.jsxs("button",{onClick:()=>q(e=>"global"===e?null:"global"),className:o("flex items-center gap-1 px-2 py-1 rounded-md text-xs transition-colors","global"===H?"bg-blue-500/15 text-blue-500":"text-muted-foreground active:bg-accent"),children:[a.jsx(J,{className:"h-3 w-3"}),"全局","global"===H&&a.jsx(W,{className:"h-3 w-3"})]}),a.jsxs("button",{onClick:()=>q(e=>"project"===e?null:"project"),className:o("flex items-center gap-1 px-2 py-1 rounded-md text-xs transition-colors","project"===H?"bg-blue-500/15 text-blue-500":"text-muted-foreground active:bg-accent"),children:[a.jsx(K,{className:"h-3 w-3"}),"项目","project"===H&&a.jsx(W,{className:"h-3 w-3"})]})]}),a.jsx("div",{className:"border-t border-border px-3 py-2 shrink-0",style:{paddingBottom:"max(0.5rem, env(safe-area-inset-bottom))"},children:a.jsxs("div",{className:"flex items-end gap-2",children:[a.jsx("textarea",{ref:w,value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),ae())},disabled:ce,placeholder:ce?"启动中...":"stopped"===l?"输入消息(自动启动)...":"输入消息...",rows:1,className:o("flex-1 resize-none rounded-lg border border-input bg-transparent px-3 py-2 text-sm outline-none","focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50","max-h-32 overflow-y-auto",ce&&"opacity-50 cursor-not-allowed"),style:{minHeight:"2.5rem"},onInput:e=>{const t=e.currentTarget;t.style.height="auto",t.style.height=Math.min(t.scrollHeight,128)+"px"}}),a.jsx("button",{onClick:ae,disabled:ce||!v.trim(),className:o("shrink-0 p-2 rounded-lg transition-colors",v.trim()?"text-blue-500 active:bg-blue-500/10":"text-muted-foreground/30"),children:a.jsx(A,{className:"h-5 w-5"})})]})})]})}const ee=k.lazy(()=>C(()=>import("./OfficePreview--1oOT9ZU.js"),__vite__mapDeps([0,1,2,3])).then(e=>({default:e.OfficePreview}))),te=new Set(["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]),se=new Set(["docx","xlsx","xls","pptx"]),ne={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",kt:"kotlin",swift:"swift",c:"c",cpp:"cpp",h:"c",cs:"csharp",php:"php",sh:"bash",bash:"bash",zsh:"bash",yaml:"yaml",yml:"yaml",json:"json",toml:"toml",html:"html",htm:"html",xml:"xml",svg:"xml",css:"css",scss:"scss",less:"less",sql:"sql",graphql:"graphql",gql:"graphql",dockerfile:"docker",makefile:"makefile",r:"r",lua:"lua",dart:"dart",zig:"zig"};function re(e){return e.split("/").pop()??e}function ae({filePath:e,onBack:t}){const[s,r]=n.useState(null),[l,o]=n.useState(!0),[c,i]=n.useState(null),{resolved:d}=j(),u=function(e){const t=e.split("/").pop()??"",s=t.toLowerCase();if("dockerfile"===s)return"dockerfile";if("makefile"===s)return"makefile";const n=t.lastIndexOf(".");return n>=0?t.slice(n+1).toLowerCase():""}(e),x=te.has(u),m=se.has(u),h=ne[u],p="dark"===d;n.useEffect(()=>{x||m?o(!1):(o(!0),i(null),b(e).then(r).catch(e=>i(e instanceof Error?e.message:"Failed to load")).finally(()=>o(!1)))},[e,x,m]);const f=w(e),k=n.useMemo(()=>{const e=v();return e?`${f}&token=${encodeURIComponent(e)}`:f},[f]),C=n.useMemo(()=>x?`${k}&t=${Date.now()}`:"",[k,x]);return a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsxs("div",{className:"flex items-center gap-2 px-3 h-12 border-b border-border shrink-0",children:[a.jsx("button",{onClick:t,className:"text-muted-foreground active:text-foreground p-1",children:a.jsx(g,{className:"h-5 w-5"})}),a.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:re(e)}),a.jsx("a",{href:k,download:!0,className:"text-muted-foreground active:text-foreground p-1",onClick:e=>e.stopPropagation(),children:a.jsx(y,{className:"h-4 w-4"})})]}),a.jsxs("div",{className:"flex-1 overflow-auto min-h-0",children:[l&&a.jsx("div",{className:"flex items-center justify-center py-12",children:a.jsx(N,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),c&&a.jsx("div",{className:"text-center text-destructive text-sm py-12 px-4",children:c}),x&&a.jsx("div",{className:"flex items-center justify-center p-4 h-full",children:a.jsx("img",{src:C,alt:re(e),className:"max-w-full max-h-full object-contain rounded",style:{touchAction:"pinch-zoom"}})}),m&&a.jsx(n.Suspense,{fallback:a.jsx("div",{className:"flex items-center justify-center py-12",children:a.jsx(N,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),children:a.jsx(ee,{filePath:e,ext:u,zoom:100})}),s&&(s.binary||s.tooLarge)&&a.jsxs("div",{className:"text-center py-12 px-4 space-y-3",children:[a.jsxs("p",{className:"text-muted-foreground text-sm",children:[s.binary?"二进制文件":"文件过大",s.size>0&&` (${S=s.size,S<1024?`${S} B`:S<1048576?`${(S/1024).toFixed(1)} KB`:`${(S/1048576).toFixed(1)} MB`})`]}),a.jsxs("a",{href:k,download:!0,className:"inline-flex items-center gap-1.5 text-sm text-blue-500 active:text-blue-400",children:[a.jsx(y,{className:"h-4 w-4"}),"下载文件"]})]}),s&&!s.binary&&!s.tooLarge&&null!=s.content&&a.jsxs(a.Fragment,{children:["md"===u&&a.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none px-4 py-3",children:a.jsx(D,{remarkPlugins:[R,L],rehypePlugins:[O],children:s.content})}),"md"!==u&&h&&a.jsx(U,{language:h,style:p?B:F,customStyle:{margin:0,fontSize:"12px",borderRadius:0},showLineNumbers:!0,children:s.content}),"md"!==u&&!h&&a.jsx("pre",{className:"p-4 text-xs font-mono whitespace-pre-wrap break-words",children:s.content})]})]})]});var S}const le=new Set(["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]),oe=new Set(["js","jsx","ts","tsx","py","rb","go","rs","java","c","cpp","h","swift","kt","cs","php","sh","bash","zsh","r","lua","dart","zig","css","scss","less","html","htm","xml","sql"]),ce=new Set(["json","yaml","yml","toml","csv","tsv"]);function ie({entry:e}){if("dir"===e.type)return a.jsx(z,{className:"h-8 w-8 text-blue-400"});const t=function(e){const t=e.lastIndexOf(".");return t>=0?e.slice(t+1).toLowerCase():""}(e.name);return le.has(t)?a.jsx(H,{className:"h-8 w-8 text-emerald-400"}):oe.has(t)?a.jsx(V,{className:"h-8 w-8 text-orange-400"}):ce.has(t)?a.jsx(G,{className:"h-8 w-8 text-yellow-400"}):"md"===t?a.jsx(q,{className:"h-8 w-8 text-sky-400"}):a.jsx(M,{className:"h-8 w-8 text-muted-foreground"})}function de({rootPath:e,onClose:t}){const[s,r]=n.useState(e),[l,o]=n.useState([]),[c,i]=n.useState(!0),[d,u]=n.useState(null),x=n.useCallback(async e=>{i(!0);try{const t=[...(await S(e)).entries].sort((e,t)=>e.type!==t.type?"dir"===e.type?-1:1:e.name.localeCompare(t.name));o(t),r(e)}catch{o([])}finally{i(!1)}},[]);n.useEffect(()=>{x(e)},[e,x]);const m=s!==e,h=s.startsWith(e)?s.slice(e.length)||"/":s;return d?a.jsx(ae,{filePath:d,onBack:()=>u(null)}):a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsxs("div",{className:"flex items-center gap-2 px-3 h-12 border-b border-border shrink-0",children:[a.jsx("button",{onClick:t,className:"text-muted-foreground active:text-foreground p-1",children:a.jsx(_,{className:"h-5 w-5"})}),a.jsxs("div",{className:"flex items-center gap-1 flex-1 min-w-0 text-sm",children:[m&&a.jsx("button",{onClick:()=>{if(s===e)return;const t=s.replace(/\/[^/]+$/,"")||"/";t.startsWith(e)&&x(t)},className:"text-muted-foreground active:text-foreground p-0.5 shrink-0",children:a.jsx(g,{className:"h-4 w-4"})}),a.jsx("span",{className:"truncate text-muted-foreground font-mono text-xs",children:h})]})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3",children:[c&&a.jsx("div",{className:"flex items-center justify-center py-12",children:a.jsx(N,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),!c&&0===l.length&&a.jsx("div",{className:"text-center text-muted-foreground text-sm py-12",children:"空目录"}),!c&&a.jsx("div",{className:"grid grid-cols-3 gap-1",children:l.map(e=>a.jsxs("button",{onClick:()=>(e=>{"dir"===e.type?x(e.path):u(e.path)})(e),className:"flex flex-col items-center gap-1 p-2 rounded-lg active:bg-accent transition-colors",children:[a.jsx(ie,{entry:e}),a.jsx("span",{className:"text-[11px] text-center leading-tight w-full line-clamp-2 break-all",children:e.name})]},e.path))})]})]})}function ue(e){return e<50?"text-green-400":e<80?"text-yellow-400":"text-red-400"}function xe(e){return e<50?"bg-green-500":e<80?"bg-yellow-500":"bg-red-500"}function me({projectName:e,cliTool:t,folderPath:s,contextData:r,onClose:c}){const[i,d]=n.useState(new Set(["context","usage","files"])),[u,x]=n.useState(null),[m,h]=n.useState(!1),p=e=>{d(t=>{const s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})};n.useEffect(()=>{h(!0),P(t).then(x).catch(()=>x(null)).finally(()=>h(!1))},[t]);const f=r?Math.round(r.usedPercentage):null;return a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsxs("div",{className:"flex items-center gap-2 px-3 h-12 border-b border-border shrink-0",children:[a.jsx("button",{onClick:c,className:"text-muted-foreground active:text-foreground p-1",children:a.jsx(_,{className:"h-5 w-5"})}),a.jsx("span",{className:"flex-1 font-medium text-sm truncate",children:e})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto",children:[a.jsxs("button",{onClick:()=>p("context"),className:"w-full flex items-center gap-2 px-4 py-2.5 border-b border-border/50 active:bg-accent",children:[i.has("context")?a.jsx(W,{className:"h-3.5 w-3.5 text-muted-foreground"}):a.jsx(T,{className:"h-3.5 w-3.5 text-muted-foreground"}),a.jsx("span",{className:"text-sm font-medium",children:"上下文"}),null!==f&&a.jsxs("span",{className:o("text-xs font-mono ml-auto",ue(f)),children:[f,"%"]})]}),i.has("context")&&a.jsx("div",{className:"px-4 py-3 border-b border-border/50",children:null!==f&&r?a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:"flex-1 h-2 bg-secondary rounded-full overflow-hidden",children:a.jsx("div",{className:o("h-full rounded-full transition-all",xe(f)),style:{width:`${Math.min(f,100)}%`}})}),a.jsxs("span",{className:o("text-xs font-mono w-10 text-right",ue(f)),children:[f,"%"]})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-[11px] text-muted-foreground",children:[a.jsx("span",{children:"窗口大小"}),a.jsx("span",{className:"text-right font-mono",children:r.contextWindowSize>=1e6?`${(r.contextWindowSize/1e6).toFixed(1)}M`:`${Math.round(r.contextWindowSize/1e3)}K`}),a.jsx("span",{children:"输入 tokens"}),a.jsx("span",{className:"text-right font-mono",children:r.inputTokens.toLocaleString()}),a.jsx("span",{children:"输出 tokens"}),a.jsx("span",{className:"text-right font-mono",children:r.outputTokens.toLocaleString()})]})]}):a.jsx("div",{className:"text-xs text-muted-foreground/50 text-center py-2",children:"暂无数据"})}),a.jsxs("div",{className:"w-full flex items-center gap-2 px-4 py-2.5 border-b border-border/50 cursor-pointer",role:"button",tabIndex:0,onClick:()=>p("usage"),onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||p("usage")},children:[i.has("usage")?a.jsx(W,{className:"h-3.5 w-3.5 text-muted-foreground"}):a.jsx(T,{className:"h-3.5 w-3.5 text-muted-foreground"}),a.jsx("span",{className:"text-sm font-medium",children:"用量"}),a.jsx("button",{onClick:e=>{e.stopPropagation(),(async()=>{h(!0);try{const{refreshUsage:e}=await C(async()=>{const{refreshUsage:e}=await import("./index-CSDDVTf8.js").then(e=>e.bw);return{refreshUsage:e}},__vite__mapDeps([1,2]));x(await e(t))}catch{}finally{h(!1)}})()},className:"ml-auto text-muted-foreground active:text-foreground",children:a.jsx(l,{className:o("h-3 w-3",m&&"animate-spin")})})]}),i.has("usage")&&a.jsx("div",{className:"px-4 py-3 border-b border-border/50",children:u?a.jsxs("div",{className:"space-y-2",children:[u.planName&&a.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["Plan: ",a.jsx("span",{className:"font-medium text-foreground",children:u.planName})]}),a.jsx(he,{label:"5h",bucket:u.fiveHour}),a.jsx(he,{label:"7d",bucket:u.sevenDay}),u.sevenDaySonnet&&a.jsx(he,{label:"7d Sonnet",bucket:u.sevenDaySonnet}),u.sevenDayOpus&&a.jsx(he,{label:"7d Opus",bucket:u.sevenDayOpus}),!u.fiveHour&&!u.sevenDay&&a.jsx("div",{className:"text-xs text-muted-foreground/50 text-center",children:"暂无数据"})]}):a.jsx("div",{className:"text-xs text-muted-foreground/50 text-center py-2",children:m?"加载中...":"暂无数据"})}),a.jsxs("button",{onClick:()=>p("files"),className:"w-full flex items-center gap-2 px-4 py-2.5 border-b border-border/50 active:bg-accent",children:[i.has("files")?a.jsx(W,{className:"h-3.5 w-3.5 text-muted-foreground"}):a.jsx(T,{className:"h-3.5 w-3.5 text-muted-foreground"}),a.jsx("span",{className:"text-sm font-medium",children:"文件"})]}),i.has("files")&&a.jsx("div",{className:"h-[60vh]",children:a.jsx(de,{rootPath:s,onClose:()=>p("files")})})]})]})}function he({label:e,bucket:t}){if(!t||void 0===t.utilization)return null;const s=t.utilization,n=function(e){if(!e)return"";const t=new Date(e).getTime()-Date.now();if(t<=0)return"即将重置";const s=Math.floor(t/36e5),n=Math.floor(t%36e5/6e4);return s>0?`${s}h${n}m`:`${n}m`}(t.resetAt);return a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-xs text-muted-foreground w-16",children:e}),a.jsx("div",{className:"flex-1 h-1.5 bg-secondary rounded-full overflow-hidden",children:a.jsx("div",{className:o("h-full rounded-full",xe(s)),style:{width:`${Math.min(s,100)}%`}})}),a.jsxs("span",{className:o("text-xs font-mono w-8 text-right",ue(s)),children:[s,"%"]}),n&&a.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:n})]})}function pe(){n.useEffect(()=>{const e=document.querySelector('meta[name="viewport"]');if(!e)return;const t=e.getAttribute("content")??"";return e.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"),()=>{e.setAttribute("content",t)}},[]);const[e,t]=n.useState({screen:"list"}),[r,l]=n.useState(null),o=s(e=>e.projects),c=n.useCallback(e=>{t({screen:"chat",projectId:e}),l(null)},[]),i=n.useCallback(e=>{t({screen:"panel",projectId:e})},[]),d=n.useCallback(()=>{t(e=>"panel"===e.screen?{screen:"chat",projectId:e.projectId}:{screen:"list"})},[]),u="list"!==e.screen?o.find(t=>t.id===e.projectId):void 0;return a.jsxs("div",{className:"fixed inset-0 bg-background overflow-hidden",children:[a.jsxs(E,{mode:"wait",children:["list"===e.screen&&a.jsx($.div,{className:"absolute inset-0",initial:{opacity:0},animate:{opacity:1},exit:{x:"-30%",opacity:0},transition:{duration:.2},style:{paddingTop:"env(safe-area-inset-top)"},children:a.jsx(Y,{onSelectProject:c})},"list"),"chat"===e.screen&&u&&a.jsx($.div,{className:"absolute inset-0",initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{type:"tween",duration:.25},style:{paddingTop:"env(safe-area-inset-top)"},children:a.jsx(Z,{project:u,onBack:d,onOpenPanel:()=>i(e.projectId),onContextUpdate:l})},`chat-${e.projectId}`)]}),a.jsx(E,{children:"panel"===e.screen&&u&&a.jsx($.div,{className:"absolute inset-0 z-50 bg-background",initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{type:"tween",duration:.25},style:{paddingTop:"env(safe-area-inset-top)"},children:a.jsx(me,{projectName:u.name,cliTool:u.cliTool??"claude",folderPath:u.folderPath,contextData:r,onClose:d})},"panel")})]})}export{pe as MobilePage};
14
+ */function X({onSelectProject:e}){const i=t(),{projects:d,fetchProjects:u,hasFetched:x,loading:m}=s(),[h,p]=n.useState(new Map),[f,g]=n.useState(new Set),[j,b]=n.useState(!1);n.useEffect(()=>{u()},[u]);const v=n.useCallback(e=>{e.status&&p(t=>{const s=new Map(t);return s.set(e.projectId,e.status),s}),void 0!==e.active&&g(t=>{const s=new Set(t);return e.active?s.add(e.projectId):s.delete(e.projectId),s})},[]);r({onActivityUpdate:v});const y=d.filter(e=>!e.archived);return a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsxs("div",{className:"flex items-center gap-3 px-4 h-12 border-b border-border shrink-0",children:[a.jsx("span",{className:"font-semibold text-base flex-1",children:"CC Web"}),a.jsx("button",{onClick:()=>{(async()=>{b(!0);try{await u()}finally{b(!1)}})()},className:"text-muted-foreground active:text-foreground",disabled:j,children:a.jsx(l,{className:o("h-4 w-4",j&&"animate-spin")})}),!Q&&a.jsx("button",{onClick:()=>i("/"),className:"text-muted-foreground active:text-foreground",title:"桌面模式",children:a.jsx(c,{className:"h-4 w-4"})})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3",children:[m&&!x&&a.jsx("div",{className:"text-center text-muted-foreground text-sm py-12",children:"加载中..."}),x&&0===y.length&&a.jsx("div",{className:"text-center text-muted-foreground text-sm py-12",children:"暂无项目"}),a.jsx("div",{className:"grid grid-cols-2 gap-2",children:y.map(t=>{var s;const n="running"===(s=t,h.get(s.id)??s.status??"stopped"),r=f.has(t.id),l=a.jsxs("button",{onClick:()=>e(t.id),className:o("w-full text-left rounded-lg border bg-card p-2.5 active:bg-accent transition-colors",r?"border-transparent":"border-border"),children:[a.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[a.jsx("span",{className:o("w-2 h-2 rounded-full shrink-0",n?"bg-green-500":"bg-zinc-400")}),a.jsx("span",{className:"font-medium text-sm truncate flex-1",children:t.name})]}),a.jsx("div",{className:"text-[10px] text-muted-foreground font-mono truncate",children:t.cliTool??"claude"})]});return a.jsx("div",{className:r?"card-active-glow rounded-lg":void 0,children:l},t.id)})})]})]})}function Z({project:e,onBack:t,onOpenPanel:s,onContextUpdate:r}){const[l,c]=n.useState("running"===e.status?"live":"stopped"),[j,b]=n.useState([]),[v,y]=n.useState(""),N=n.useRef(null),w=n.useRef(null),k=n.useRef(null),C=n.useRef(!1),S=n.useRef([]),_=n.useRef(null),z=n.useRef(0),M=n.useRef([]),[P,T]=n.useState([]),[E,I]=n.useState(!1),A=n.useMemo(()=>[...P,...j],[P,j]),[L,B]=n.useState([]),[U,q]=n.useState([]),[F,H]=n.useState(null);n.useEffect(()=>{i().then(B).catch(()=>{}),d(e.id).then(q).catch(()=>{})},[e.id]);const V=n.useRef(0);V.current=j.length;const G=n.useCallback(async()=>{try{const t=await u(e.id,1);if(0===t.length)return;const s=(await x(e.id,t[0].id,"latest","user")).content.split(/(?=^## [UA]\d+)/m).filter(Boolean),n=[];for(const e of s){const t=e.match(/^## ([UA])(\d+).*\n/);if(!t)continue;const s="U"===t[1]?"user":"assistant",r=e.slice(t[0].length).trim();r&&n.push({role:s,content:r,ts:""})}0===V.current&&(M.current=n,T(n.slice(-20)),I(n.length>20))}catch{m.error("加载对话历史失败")}},[e.id]),Q=n.useCallback(()=>{const e=M.current;if(0===e.length)return;const t=P.length,s=Math.min(t+20,e.length),n=N.current,r=(null==n?void 0:n.scrollHeight)??0;T(e.slice(-s)),I(s<e.length),requestAnimationFrame(()=>{if(n){const e=n.scrollHeight;n.scrollTop+=e-r}})},[P.length]);n.useEffect(()=>{"stopped"===l&&G()},[l,G]),n.useEffect(()=>{if("live"!==l)return void(C.current=!1);const e=setTimeout(()=>{C.current||G()},3e3);return()=>clearTimeout(e)},[l,G]),n.useEffect(()=>{"running"!==e.status||"stopped"!==l&&"error"!==l?"stopped"===e.status&&"live"===l&&c("stopped"):(b([]),c("live"))},[e.status]);const X=n.useRef(null),Z=n.useCallback(()=>{X.current&&(clearTimeout(X.current.timer),X.current=null)},[]);n.useEffect(()=>()=>Z(),[Z]);const ee=n.useCallback(e=>{C.current=!0;const t=h(e.blocks);if(t.trim()){if(Z(),"user"===e.role){const e=S.current.indexOf(t.trim());if(-1!==e)return void S.current.splice(e,1)}b(s=>[...s,{role:e.role,content:t,ts:e.timestamp}].slice(-50))}},[Z]),te=n.useCallback(e=>{"stopped"===e&&c("stopped")},[]),{sendInput:se}=p({projectId:e.id,enabled:"live"===l||"waking"===l,onChatMessage:ee,onStatusChange:te,onContextUpdate:r});n.useEffect(()=>{if("live"===l&&k.current){const e=k.current;k.current=null,se(e+"\r")}},[l,se]);const ne=n.useRef(0);n.useEffect(()=>{var e;null==(e=N.current)||e.scrollTo({top:N.current.scrollHeight,behavior:"smooth"})},[j]),n.useEffect(()=>{var e;0===ne.current&&P.length>0&&(null==(e=N.current)||e.scrollTo({top:N.current.scrollHeight})),ne.current=P.length},[P]),n.useEffect(()=>()=>{_.current&&clearTimeout(_.current)},[]);const re=n.useCallback(t=>{if(S.current.push(t),S.current.length>10&&S.current.shift(),b(e=>[...e,{role:"user",content:t,ts:(new Date).toISOString()}].slice(-50)),"live"===l||"waking"===l){se(t+"\r"),Z();const e=3,s=t=>{if(t>=e)return;const n=setTimeout(()=>{se("\r"),s(t+1)},3e3);X.current={timer:n,attempts:t}};s(0)}else if("stopped"===l||"error"===l){k.current=t;const s=++z.current;c("waking"),f(e.id).then(()=>{s===z.current&&(_.current&&clearTimeout(_.current),c("live"))}).catch(e=>{s===z.current&&(m.error(`启动失败: ${e instanceof Error?e.message:String(e)}`),c("error"),k.current=null)}),_.current=setTimeout(()=>{s===z.current&&k.current&&(m.error("启动超时(10s)"),c("error"),k.current=null)},1e4)}},[l,e.id,se]),ae=n.useCallback(()=>{const e=v.trim();e&&(y(""),w.current&&(w.current.style.height="auto"),re(e))},[v,re]),le=n.useCallback(e=>{H(null),re(e)},[re]),oe="live"===l,ce="waking"===l;return a.jsxs("div",{className:"flex flex-col h-full bg-background",children:[a.jsxs("div",{className:"flex items-center gap-2 px-3 h-12 border-b border-border shrink-0",children:[a.jsx("button",{onClick:t,className:"text-muted-foreground active:text-foreground p-1",children:a.jsx(g,{className:"h-5 w-5"})}),a.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[a.jsx("span",{className:"font-medium text-sm truncate",children:e.name}),a.jsx("span",{className:o("w-2 h-2 rounded-full shrink-0",oe?"bg-green-500":ce?"bg-yellow-400 animate-pulse":"bg-zinc-400")})]}),a.jsx("button",{onClick:s,className:"text-muted-foreground active:text-foreground p-1",children:a.jsx(Y,{className:"h-5 w-5"})})]}),a.jsxs("div",{ref:N,className:"flex-1 overflow-y-auto px-3 py-3 space-y-3 min-h-0",children:[E&&a.jsx("div",{className:"flex justify-center pb-1",children:a.jsxs("button",{onClick:Q,className:"flex items-center gap-1 px-3 py-1.5 rounded-full text-xs text-muted-foreground border border-border active:bg-accent transition-colors",children:[a.jsx($,{className:"h-3 w-3"}),"加载更早消息"]})}),A.map((e,t)=>{const s="user"===e.role;return a.jsx("div",{className:o("flex",s?"justify-end":"justify-start"),children:a.jsx("div",{className:o("max-w-[85%] rounded-xl px-3 py-2 break-words text-sm leading-relaxed",s?"bg-blue-500/15 text-foreground border border-blue-500/20 rounded-br-sm whitespace-pre-wrap":"bg-secondary text-secondary-foreground border border-border rounded-bl-sm"),children:s?e.content:a.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none text-inherit [&_pre]:overflow-x-auto [&_pre]:max-w-full [&_pre]:text-xs [&_pre]:my-1 [&_pre]:p-2 [&_pre]:rounded [&_p]:my-1 [&_ul]:my-1 [&_ol]:my-1 [&_h1]:text-base [&_h2]:text-sm [&_h3]:text-sm [&_hr]:my-2 [&_code]:text-xs [&_code]:px-1 [&_code]:rounded [&_table]:text-xs [&_a]:text-blue-400",children:a.jsx(D,{remarkPlugins:[R],children:e.content})})})},`${e.role}-${e.ts||t}-${t}`)}),0===A.length&&"stopped"===l&&a.jsx("div",{className:"flex items-center justify-center h-full text-muted-foreground/40 text-sm",children:"暂无对话记录"}),ce&&a.jsx("div",{className:"flex items-center justify-center py-4 text-yellow-400 text-sm animate-pulse",children:"启动中..."})]}),F&&a.jsx("div",{className:"border-t border-border max-h-48 overflow-y-auto shrink-0",children:a.jsxs("div",{className:"px-3 py-2 space-y-1",children:[("global"===F?L:U).map(e=>a.jsxs("button",{onClick:()=>le(e.command),disabled:ce,className:o("w-full text-left rounded-md px-2.5 py-2 text-sm active:bg-accent transition-colors border border-border/50",ce&&"opacity-50 cursor-not-allowed"),children:[a.jsx("div",{className:"font-medium text-xs",children:e.label}),a.jsx("div",{className:"text-[11px] text-muted-foreground font-mono truncate",children:e.command})]},e.id)),0===("global"===F?L:U).length&&a.jsx("div",{className:"text-center text-muted-foreground text-xs py-3",children:"暂无快捷命令"})]})}),(L.length>0||U.length>0)&&a.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 border-t border-border shrink-0",children:[a.jsxs("button",{onClick:()=>H(e=>"global"===e?null:"global"),className:o("flex items-center gap-1 px-2 py-1 rounded-md text-xs transition-colors","global"===F?"bg-blue-500/15 text-blue-500":"text-muted-foreground active:bg-accent"),children:[a.jsx(J,{className:"h-3 w-3"}),"全局","global"===F&&a.jsx(W,{className:"h-3 w-3"})]}),a.jsxs("button",{onClick:()=>H(e=>"project"===e?null:"project"),className:o("flex items-center gap-1 px-2 py-1 rounded-md text-xs transition-colors","project"===F?"bg-blue-500/15 text-blue-500":"text-muted-foreground active:bg-accent"),children:[a.jsx(K,{className:"h-3 w-3"}),"项目","project"===F&&a.jsx(W,{className:"h-3 w-3"})]})]}),a.jsx("div",{className:"border-t border-border px-3 py-2 shrink-0",style:{paddingBottom:"max(0.5rem, env(safe-area-inset-bottom))"},children:a.jsxs("div",{className:"flex items-end gap-2",children:[a.jsx("textarea",{ref:w,value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),ae())},disabled:ce,placeholder:ce?"启动中...":"stopped"===l?"输入消息(自动启动)...":"输入消息...",rows:1,className:o("flex-1 resize-none rounded-lg border border-input bg-transparent px-3 py-2 text-sm outline-none","focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50","max-h-32 overflow-y-auto",ce&&"opacity-50 cursor-not-allowed"),style:{minHeight:"2.5rem"},onInput:e=>{const t=e.currentTarget;t.style.height="auto",t.style.height=Math.min(t.scrollHeight,128)+"px"}}),a.jsx("button",{onClick:ae,disabled:ce||!v.trim(),className:o("shrink-0 p-2 rounded-lg transition-colors",v.trim()?"text-blue-500 active:bg-blue-500/10":"text-muted-foreground/30"),children:a.jsx(O,{className:"h-5 w-5"})})]})})]})}const ee=k.lazy(()=>C(()=>import("./OfficePreview-DhG_GTdh.js"),__vite__mapDeps([0,1,2,3])).then(e=>({default:e.OfficePreview}))),te=new Set(["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]),se=new Set(["docx","xlsx","xls","pptx"]),ne={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",kt:"kotlin",swift:"swift",c:"c",cpp:"cpp",h:"c",cs:"csharp",php:"php",sh:"bash",bash:"bash",zsh:"bash",yaml:"yaml",yml:"yaml",json:"json",toml:"toml",html:"html",htm:"html",xml:"xml",svg:"xml",css:"css",scss:"scss",less:"less",sql:"sql",graphql:"graphql",gql:"graphql",dockerfile:"docker",makefile:"makefile",r:"r",lua:"lua",dart:"dart",zig:"zig"};function re(e){return e.split("/").pop()??e}function ae({filePath:e,onBack:t}){const[s,r]=n.useState(null),[l,o]=n.useState(!0),[c,i]=n.useState(null),{resolved:d}=j(),u=function(e){const t=e.split("/").pop()??"",s=t.toLowerCase();if("dockerfile"===s)return"dockerfile";if("makefile"===s)return"makefile";const n=t.lastIndexOf(".");return n>=0?t.slice(n+1).toLowerCase():""}(e),x=te.has(u),m=se.has(u),h=ne[u],p="dark"===d;n.useEffect(()=>{x||m?o(!1):(o(!0),i(null),b(e).then(r).catch(e=>i(e instanceof Error?e.message:"Failed to load")).finally(()=>o(!1)))},[e,x,m]);const f=w(e),k=n.useMemo(()=>{const e=v();return e?`${f}&token=${encodeURIComponent(e)}`:f},[f]),C=n.useMemo(()=>x?`${k}&t=${Date.now()}`:"",[k,x]);return a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsxs("div",{className:"flex items-center gap-2 px-3 h-12 border-b border-border shrink-0",children:[a.jsx("button",{onClick:t,className:"text-muted-foreground active:text-foreground p-1",children:a.jsx(g,{className:"h-5 w-5"})}),a.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:re(e)}),a.jsx("a",{href:k,download:!0,className:"text-muted-foreground active:text-foreground p-1",onClick:e=>e.stopPropagation(),children:a.jsx(y,{className:"h-4 w-4"})})]}),a.jsxs("div",{className:"flex-1 overflow-auto min-h-0",children:[l&&a.jsx("div",{className:"flex items-center justify-center py-12",children:a.jsx(N,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),c&&a.jsx("div",{className:"text-center text-destructive text-sm py-12 px-4",children:c}),x&&a.jsx("div",{className:"flex items-center justify-center p-4 h-full",children:a.jsx("img",{src:C,alt:re(e),className:"max-w-full max-h-full object-contain rounded",style:{touchAction:"pinch-zoom"}})}),m&&a.jsx(n.Suspense,{fallback:a.jsx("div",{className:"flex items-center justify-center py-12",children:a.jsx(N,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),children:a.jsx(ee,{filePath:e,ext:u,zoom:100})}),s&&(s.binary||s.tooLarge)&&a.jsxs("div",{className:"text-center py-12 px-4 space-y-3",children:[a.jsxs("p",{className:"text-muted-foreground text-sm",children:[s.binary?"二进制文件":"文件过大",s.size>0&&` (${S=s.size,S<1024?`${S} B`:S<1048576?`${(S/1024).toFixed(1)} KB`:`${(S/1048576).toFixed(1)} MB`})`]}),a.jsxs("a",{href:k,download:!0,className:"inline-flex items-center gap-1.5 text-sm text-blue-500 active:text-blue-400",children:[a.jsx(y,{className:"h-4 w-4"}),"下载文件"]})]}),s&&!s.binary&&!s.tooLarge&&null!=s.content&&a.jsxs(a.Fragment,{children:["md"===u&&a.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none px-4 py-3",children:a.jsx(D,{remarkPlugins:[R,L],rehypePlugins:[A],children:s.content})}),"md"!==u&&h&&a.jsx(B,{language:h,style:p?U:q,customStyle:{margin:0,fontSize:"12px",borderRadius:0},showLineNumbers:!0,children:s.content}),"md"!==u&&!h&&a.jsx("pre",{className:"p-4 text-xs font-mono whitespace-pre-wrap break-words",children:s.content})]})]})]});var S}const le=new Set(["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]),oe=new Set(["js","jsx","ts","tsx","py","rb","go","rs","java","c","cpp","h","swift","kt","cs","php","sh","bash","zsh","r","lua","dart","zig","css","scss","less","html","htm","xml","sql"]),ce=new Set(["json","yaml","yml","toml","csv","tsv"]);function ie({entry:e}){if("dir"===e.type)return a.jsx(z,{className:"h-8 w-8 text-blue-400"});const t=function(e){const t=e.lastIndexOf(".");return t>=0?e.slice(t+1).toLowerCase():""}(e.name);return le.has(t)?a.jsx(F,{className:"h-8 w-8 text-emerald-400"}):oe.has(t)?a.jsx(V,{className:"h-8 w-8 text-orange-400"}):ce.has(t)?a.jsx(G,{className:"h-8 w-8 text-yellow-400"}):"md"===t?a.jsx(H,{className:"h-8 w-8 text-sky-400"}):a.jsx(M,{className:"h-8 w-8 text-muted-foreground"})}function de({rootPath:e,onClose:t}){const[s,r]=n.useState(e),[l,o]=n.useState([]),[c,i]=n.useState(!0),[d,u]=n.useState(null),x=n.useCallback(async e=>{i(!0);try{const t=[...(await S(e)).entries].sort((e,t)=>e.type!==t.type?"dir"===e.type?-1:1:e.name.localeCompare(t.name));o(t),r(e)}catch{o([])}finally{i(!1)}},[]);n.useEffect(()=>{x(e)},[e,x]);const m=s!==e,h=s.startsWith(e)?s.slice(e.length)||"/":s;return d?a.jsx(ae,{filePath:d,onBack:()=>u(null)}):a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsxs("div",{className:"flex items-center gap-2 px-3 h-12 border-b border-border shrink-0",children:[a.jsx("button",{onClick:t,className:"text-muted-foreground active:text-foreground p-1",children:a.jsx(_,{className:"h-5 w-5"})}),a.jsxs("div",{className:"flex items-center gap-1 flex-1 min-w-0 text-sm",children:[m&&a.jsx("button",{onClick:()=>{if(s===e)return;const t=s.replace(/\/[^/]+$/,"")||"/";t.startsWith(e)&&x(t)},className:"text-muted-foreground active:text-foreground p-0.5 shrink-0",children:a.jsx(g,{className:"h-4 w-4"})}),a.jsx("span",{className:"truncate text-muted-foreground font-mono text-xs",children:h})]})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3",children:[c&&a.jsx("div",{className:"flex items-center justify-center py-12",children:a.jsx(N,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),!c&&0===l.length&&a.jsx("div",{className:"text-center text-muted-foreground text-sm py-12",children:"空目录"}),!c&&a.jsx("div",{className:"grid grid-cols-3 gap-1",children:l.map(e=>a.jsxs("button",{onClick:()=>(e=>{"dir"===e.type?x(e.path):u(e.path)})(e),className:"flex flex-col items-center gap-1 p-2 rounded-lg active:bg-accent transition-colors",children:[a.jsx(ie,{entry:e}),a.jsx("span",{className:"text-[11px] text-center leading-tight w-full line-clamp-2 break-all",children:e.name})]},e.path))})]})]})}function ue(e){return e<50?"text-green-400":e<80?"text-yellow-400":"text-red-400"}function xe(e){return e<50?"bg-green-500":e<80?"bg-yellow-500":"bg-red-500"}function me({projectName:e,cliTool:t,folderPath:s,contextData:r,onClose:c}){const[i,d]=n.useState(new Set(["context","usage","files"])),[u,x]=n.useState(null),[m,h]=n.useState(!1),p=e=>{d(t=>{const s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})};n.useEffect(()=>{h(!0),P(t).then(x).catch(()=>x(null)).finally(()=>h(!1))},[t]);const f=r?Math.round(r.usedPercentage):null;return a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsxs("div",{className:"flex items-center gap-2 px-3 h-12 border-b border-border shrink-0",children:[a.jsx("button",{onClick:c,className:"text-muted-foreground active:text-foreground p-1",children:a.jsx(_,{className:"h-5 w-5"})}),a.jsx("span",{className:"flex-1 font-medium text-sm truncate",children:e})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto",children:[a.jsxs("button",{onClick:()=>p("context"),className:"w-full flex items-center gap-2 px-4 py-2.5 border-b border-border/50 active:bg-accent",children:[i.has("context")?a.jsx(W,{className:"h-3.5 w-3.5 text-muted-foreground"}):a.jsx(T,{className:"h-3.5 w-3.5 text-muted-foreground"}),a.jsx("span",{className:"text-sm font-medium",children:"上下文"}),null!==f&&a.jsxs("span",{className:o("text-xs font-mono ml-auto",ue(f)),children:[f,"%"]})]}),i.has("context")&&a.jsx("div",{className:"px-4 py-3 border-b border-border/50",children:null!==f&&r?a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:"flex-1 h-2 bg-secondary rounded-full overflow-hidden",children:a.jsx("div",{className:o("h-full rounded-full transition-all",xe(f)),style:{width:`${Math.min(f,100)}%`}})}),a.jsxs("span",{className:o("text-xs font-mono w-10 text-right",ue(f)),children:[f,"%"]})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-[11px] text-muted-foreground",children:[a.jsx("span",{children:"窗口大小"}),a.jsx("span",{className:"text-right font-mono",children:r.contextWindowSize>=1e6?`${(r.contextWindowSize/1e6).toFixed(1)}M`:`${Math.round(r.contextWindowSize/1e3)}K`}),a.jsx("span",{children:"输入 tokens"}),a.jsx("span",{className:"text-right font-mono",children:r.inputTokens.toLocaleString()}),a.jsx("span",{children:"输出 tokens"}),a.jsx("span",{className:"text-right font-mono",children:r.outputTokens.toLocaleString()})]})]}):a.jsx("div",{className:"text-xs text-muted-foreground/50 text-center py-2",children:"暂无数据"})}),a.jsxs("div",{className:"w-full flex items-center gap-2 px-4 py-2.5 border-b border-border/50 cursor-pointer",role:"button",tabIndex:0,onClick:()=>p("usage"),onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||p("usage")},children:[i.has("usage")?a.jsx(W,{className:"h-3.5 w-3.5 text-muted-foreground"}):a.jsx(T,{className:"h-3.5 w-3.5 text-muted-foreground"}),a.jsx("span",{className:"text-sm font-medium",children:"用量"}),a.jsx("button",{onClick:e=>{e.stopPropagation(),(async()=>{h(!0);try{const{refreshUsage:e}=await C(async()=>{const{refreshUsage:e}=await import("./index-Bo1P_QVB.js").then(e=>e.bB);return{refreshUsage:e}},__vite__mapDeps([1,2]));x(await e(t))}catch{}finally{h(!1)}})()},className:"ml-auto text-muted-foreground active:text-foreground",children:a.jsx(l,{className:o("h-3 w-3",m&&"animate-spin")})})]}),i.has("usage")&&a.jsx("div",{className:"px-4 py-3 border-b border-border/50",children:u?a.jsxs("div",{className:"space-y-2",children:[u.planName&&a.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["Plan: ",a.jsx("span",{className:"font-medium text-foreground",children:u.planName})]}),a.jsx(he,{label:"5h",bucket:u.fiveHour}),a.jsx(he,{label:"7d",bucket:u.sevenDay}),u.sevenDaySonnet&&a.jsx(he,{label:"7d Sonnet",bucket:u.sevenDaySonnet}),u.sevenDayOpus&&a.jsx(he,{label:"7d Opus",bucket:u.sevenDayOpus}),!u.fiveHour&&!u.sevenDay&&a.jsx("div",{className:"text-xs text-muted-foreground/50 text-center",children:"暂无数据"})]}):a.jsx("div",{className:"text-xs text-muted-foreground/50 text-center py-2",children:m?"加载中...":"暂无数据"})}),a.jsxs("button",{onClick:()=>p("files"),className:"w-full flex items-center gap-2 px-4 py-2.5 border-b border-border/50 active:bg-accent",children:[i.has("files")?a.jsx(W,{className:"h-3.5 w-3.5 text-muted-foreground"}):a.jsx(T,{className:"h-3.5 w-3.5 text-muted-foreground"}),a.jsx("span",{className:"text-sm font-medium",children:"文件"})]}),i.has("files")&&a.jsx("div",{className:"h-[60vh]",children:a.jsx(de,{rootPath:s,onClose:()=>p("files")})})]})]})}function he({label:e,bucket:t}){if(!t||void 0===t.utilization)return null;const s=t.utilization,n=function(e){if(!e)return"";const t=new Date(e).getTime()-Date.now();if(t<=0)return"即将重置";const s=Math.floor(t/36e5),n=Math.floor(t%36e5/6e4);return s>0?`${s}h${n}m`:`${n}m`}(t.resetAt);return a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-xs text-muted-foreground w-16",children:e}),a.jsx("div",{className:"flex-1 h-1.5 bg-secondary rounded-full overflow-hidden",children:a.jsx("div",{className:o("h-full rounded-full",xe(s)),style:{width:`${Math.min(s,100)}%`}})}),a.jsxs("span",{className:o("text-xs font-mono w-8 text-right",ue(s)),children:[s,"%"]}),n&&a.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:n})]})}function pe(){n.useEffect(()=>{const e=document.querySelector('meta[name="viewport"]');if(!e)return;const t=e.getAttribute("content")??"";return e.setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"),()=>{e.setAttribute("content",t)}},[]);const[e,t]=n.useState({screen:"list"}),[r,l]=n.useState(null),o=s(e=>e.projects),c=n.useCallback(e=>{t({screen:"chat",projectId:e}),l(null)},[]),i=n.useCallback(e=>{t({screen:"panel",projectId:e})},[]),d=n.useCallback(()=>{t(e=>"panel"===e.screen?{screen:"chat",projectId:e.projectId}:{screen:"list"})},[]),u="list"!==e.screen?o.find(t=>t.id===e.projectId):void 0;return a.jsxs("div",{className:"fixed inset-0 bg-background overflow-hidden",children:[a.jsxs(E,{mode:"wait",children:["list"===e.screen&&a.jsx(I.div,{className:"absolute inset-0",initial:{opacity:0},animate:{opacity:1},exit:{x:"-30%",opacity:0},transition:{duration:.2},style:{paddingTop:"env(safe-area-inset-top)"},children:a.jsx(X,{onSelectProject:c})},"list"),"chat"===e.screen&&u&&a.jsx(I.div,{className:"absolute inset-0",initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{type:"tween",duration:.25},style:{paddingTop:"env(safe-area-inset-top)"},children:a.jsx(Z,{project:u,onBack:d,onOpenPanel:()=>i(e.projectId),onContextUpdate:l})},`chat-${e.projectId}`)]}),a.jsx(E,{children:"panel"===e.screen&&u&&a.jsx(I.div,{className:"absolute inset-0 z-50 bg-background",initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{type:"tween",duration:.25},style:{paddingTop:"env(safe-area-inset-top)"},children:a.jsx(me,{projectName:u.name,cliTool:u.cliTool??"claude",folderPath:u.folderPath,contextData:r,onClose:d})},"panel")})]})}export{pe as MobilePage};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-D1Xu7j2q.js","assets/index-CSDDVTf8.js","assets/index-CSO7BFUu.css","assets/jszip.min-B5bWTUER.js"])))=>i.map(i=>d[i]);
2
- import{j as e,r as t,_ as s,g as r,e as a}from"./index-CSDDVTf8.js";import{p as n}from"./purify.es-CgRAQgUo.js";async function l(e){let t=a(e);const s=r();s&&(t+=`${t.includes("?")?"&":"?"}token=${encodeURIComponent(s)}`);const n=await fetch(t);if(!n.ok)throw new Error(`Failed to fetch file: ${n.status}`);return n.arrayBuffer()}function o({filePath:r,zoom:a}){const[o,i]=t.useState(""),[d,c]=t.useState(null),[x,u]=t.useState(!0);return t.useEffect(()=>{let e=!1;return u(!0),c(null),(async()=>{try{const t=await s(()=>import("./index-D1Xu7j2q.js").then(e=>e.i),__vite__mapDeps([0,1,2,3])),a=await l(r),n=await t.convertToHtml({arrayBuffer:a});e||i(n.value)}catch(t){e||c(t instanceof Error?t.message:"Failed to render docx")}finally{e||u(!1)}})(),()=>{e=!0}},[r]),x?e.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"加载 Word 文档中..."}):d?e.jsx("p",{className:"text-sm text-destructive p-4",children:d}):e.jsx("div",{className:"p-6 prose dark:prose-invert max-w-none",style:{fontSize:12*a/100+"px"},dangerouslySetInnerHTML:{__html:n.sanitize(o)}})}function i({filePath:r,zoom:a}){var o;const[i,d]=t.useState([]),[c,x]=t.useState(0),[u,m]=t.useState(null),[p,f]=t.useState(!0);return t.useEffect(()=>{let e=!1;return f(!0),m(null),(async()=>{try{const t=await s(()=>import("./xlsx-DfDjAMCE.js"),[]),a=await l(r),n=t.read(a,{type:"array"}),o=n.SheetNames.map(e=>({name:e,html:t.utils.sheet_to_html(n.Sheets[e],{editable:!1})}));e||(d(o),x(0))}catch(t){e||m(t instanceof Error?t.message:"Failed to render xlsx")}finally{e||f(!1)}})(),()=>{e=!0}},[r]),p?e.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"加载 Excel 文件中..."}):u?e.jsx("p",{className:"text-sm text-destructive p-4",children:u}):0===i.length?e.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"空文件"}):e.jsxs("div",{className:"flex flex-col h-full",children:[i.length>1&&e.jsx("div",{className:"flex gap-0.5 px-3 py-1.5 border-b border-border bg-muted/30 flex-shrink-0 overflow-x-auto",children:i.map((t,s)=>e.jsx("button",{onClick:()=>x(s),className:"px-3 py-1 text-xs rounded-t transition-colors whitespace-nowrap "+(s===c?"bg-background text-foreground border border-b-0 border-border":"text-muted-foreground hover:text-foreground"),children:t.name},s))}),e.jsx("div",{className:"flex-1 overflow-auto p-2 xlsx-preview",style:{fontSize:12*a/100+"px"},dangerouslySetInnerHTML:{__html:n.sanitize((null==(o=i[c])?void 0:o.html)??"")}}),e.jsx("style",{children:"\n .xlsx-preview table { border-collapse: collapse; width: auto; min-width: 100%; }\n .xlsx-preview td, .xlsx-preview th {\n border: 1px solid hsl(var(--border));\n padding: 4px 8px;\n text-align: left;\n white-space: nowrap;\n font-size: inherit;\n }\n .xlsx-preview th { background: hsl(var(--muted)); font-weight: 600; }\n .xlsx-preview tr:hover td { background: hsl(var(--accent) / 0.3); }\n "})]})}function d({filePath:r,zoom:a}){const[n,o]=t.useState([]),[i,d]=t.useState(null),[c,x]=t.useState(!0);return t.useEffect(()=>{let e=!1;return x(!0),d(null),(async()=>{try{const t=await l(r),a=await async function(e){const{default:t}=await s(async()=>{const{default:e}=await import("./jszip.min-B5bWTUER.js").then(e=>e.j);return{default:e}},__vite__mapDeps([3,1,2])),r=await t.loadAsync(e),a=[],n=Object.keys(r.files).filter(e=>/^ppt\/slides\/slide\d+\.xml$/i.test(e)).sort((e,t)=>{var s,r;return parseInt((null==(s=e.match(/slide(\d+)/))?void 0:s[1])??"0")-parseInt((null==(r=t.match(/slide(\d+)/))?void 0:r[1])??"0")});for(let s=0;s<n.length;s++){const e=await r.file(n[s]).async("text"),t=[],l=/<a:t[^>]*>([\s\S]*?)<\/a:t>/g;let o;for(;null!==(o=l.exec(e));){const e=o[1].replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').trim();e&&t.push(e)}a.push({index:s+1,texts:t})}return a}(t);e||o(a)}catch(t){e||d(t instanceof Error?t.message:"Failed to render pptx")}finally{e||x(!1)}})(),()=>{e=!0}},[r]),c?e.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"加载 PPT 文件中..."}):i?e.jsx("p",{className:"text-sm text-destructive p-4",children:i}):0===n.length?e.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"空文件"}):e.jsx("div",{className:"p-4 space-y-4",style:{fontSize:12*a/100+"px"},children:n.map(t=>e.jsxs("div",{className:"border border-border rounded-lg p-5 bg-muted/20",children:[e.jsxs("div",{className:"text-xs text-muted-foreground mb-2 font-medium",children:["Slide ",t.index]}),t.texts.length>0?e.jsx("div",{className:"space-y-1.5",children:t.texts.map((t,s)=>e.jsx("p",{className:"text-foreground leading-relaxed",style:{fontSize:"inherit"},children:t},s))}):e.jsx("p",{className:"text-muted-foreground text-sm italic",children:"(无文本内容)"})]},t.index))})}const c=new Set(["docx","xlsx","xls","pptx"]);function x({filePath:t,ext:s,zoom:r}){return"docx"===s?e.jsx(o,{filePath:t,zoom:r}):"xlsx"===s||"xls"===s?e.jsx(i,{filePath:t,zoom:r}):"pptx"===s?e.jsx(d,{filePath:t,zoom:r}):null}export{c as OFFICE_EXTS,x as OfficePreview};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-eg0a81dE.js","assets/index-Bo1P_QVB.js","assets/index-Ccjr2Crc.css","assets/jszip.min-CoiRZgCR.js"])))=>i.map(i=>d[i]);
2
+ import{j as e,r as t,_ as s,g as r,e as a}from"./index-Bo1P_QVB.js";import{p as n}from"./purify.es-CgRAQgUo.js";async function l(e){let t=a(e);const s=r();s&&(t+=`${t.includes("?")?"&":"?"}token=${encodeURIComponent(s)}`);const n=await fetch(t);if(!n.ok)throw new Error(`Failed to fetch file: ${n.status}`);return n.arrayBuffer()}function o({filePath:r,zoom:a}){const[o,i]=t.useState(""),[d,c]=t.useState(null),[x,u]=t.useState(!0);return t.useEffect(()=>{let e=!1;return u(!0),c(null),(async()=>{try{const t=await s(()=>import("./index-eg0a81dE.js").then(e=>e.i),__vite__mapDeps([0,1,2,3])),a=await l(r),n=await t.convertToHtml({arrayBuffer:a});e||i(n.value)}catch(t){e||c(t instanceof Error?t.message:"Failed to render docx")}finally{e||u(!1)}})(),()=>{e=!0}},[r]),x?e.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"加载 Word 文档中..."}):d?e.jsx("p",{className:"text-sm text-destructive p-4",children:d}):e.jsx("div",{className:"p-6 prose dark:prose-invert max-w-none",style:{fontSize:12*a/100+"px"},dangerouslySetInnerHTML:{__html:n.sanitize(o)}})}function i({filePath:r,zoom:a}){var o;const[i,d]=t.useState([]),[c,x]=t.useState(0),[u,m]=t.useState(null),[p,f]=t.useState(!0);return t.useEffect(()=>{let e=!1;return f(!0),m(null),(async()=>{try{const t=await s(()=>import("./xlsx-DfDjAMCE.js"),[]),a=await l(r),n=t.read(a,{type:"array"}),o=n.SheetNames.map(e=>({name:e,html:t.utils.sheet_to_html(n.Sheets[e],{editable:!1})}));e||(d(o),x(0))}catch(t){e||m(t instanceof Error?t.message:"Failed to render xlsx")}finally{e||f(!1)}})(),()=>{e=!0}},[r]),p?e.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"加载 Excel 文件中..."}):u?e.jsx("p",{className:"text-sm text-destructive p-4",children:u}):0===i.length?e.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"空文件"}):e.jsxs("div",{className:"flex flex-col h-full",children:[i.length>1&&e.jsx("div",{className:"flex gap-0.5 px-3 py-1.5 border-b border-border bg-muted/30 flex-shrink-0 overflow-x-auto",children:i.map((t,s)=>e.jsx("button",{onClick:()=>x(s),className:"px-3 py-1 text-xs rounded-t transition-colors whitespace-nowrap "+(s===c?"bg-background text-foreground border border-b-0 border-border":"text-muted-foreground hover:text-foreground"),children:t.name},s))}),e.jsx("div",{className:"flex-1 overflow-auto p-2 xlsx-preview",style:{fontSize:12*a/100+"px"},dangerouslySetInnerHTML:{__html:n.sanitize((null==(o=i[c])?void 0:o.html)??"")}}),e.jsx("style",{children:"\n .xlsx-preview table { border-collapse: collapse; width: auto; min-width: 100%; }\n .xlsx-preview td, .xlsx-preview th {\n border: 1px solid hsl(var(--border));\n padding: 4px 8px;\n text-align: left;\n white-space: nowrap;\n font-size: inherit;\n }\n .xlsx-preview th { background: hsl(var(--muted)); font-weight: 600; }\n .xlsx-preview tr:hover td { background: hsl(var(--accent) / 0.3); }\n "})]})}function d({filePath:r,zoom:a}){const[n,o]=t.useState([]),[i,d]=t.useState(null),[c,x]=t.useState(!0);return t.useEffect(()=>{let e=!1;return x(!0),d(null),(async()=>{try{const t=await l(r),a=await async function(e){const{default:t}=await s(async()=>{const{default:e}=await import("./jszip.min-CoiRZgCR.js").then(e=>e.j);return{default:e}},__vite__mapDeps([3,1,2])),r=await t.loadAsync(e),a=[],n=Object.keys(r.files).filter(e=>/^ppt\/slides\/slide\d+\.xml$/i.test(e)).sort((e,t)=>{var s,r;return parseInt((null==(s=e.match(/slide(\d+)/))?void 0:s[1])??"0")-parseInt((null==(r=t.match(/slide(\d+)/))?void 0:r[1])??"0")});for(let s=0;s<n.length;s++){const e=await r.file(n[s]).async("text"),t=[],l=/<a:t[^>]*>([\s\S]*?)<\/a:t>/g;let o;for(;null!==(o=l.exec(e));){const e=o[1].replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').trim();e&&t.push(e)}a.push({index:s+1,texts:t})}return a}(t);e||o(a)}catch(t){e||d(t instanceof Error?t.message:"Failed to render pptx")}finally{e||x(!1)}})(),()=>{e=!0}},[r]),c?e.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"加载 PPT 文件中..."}):i?e.jsx("p",{className:"text-sm text-destructive p-4",children:i}):0===n.length?e.jsx("p",{className:"text-sm text-muted-foreground p-4",children:"空文件"}):e.jsx("div",{className:"p-4 space-y-4",style:{fontSize:12*a/100+"px"},children:n.map(t=>e.jsxs("div",{className:"border border-border rounded-lg p-5 bg-muted/20",children:[e.jsxs("div",{className:"text-xs text-muted-foreground mb-2 font-medium",children:["Slide ",t.index]}),t.texts.length>0?e.jsx("div",{className:"space-y-1.5",children:t.texts.map((t,s)=>e.jsx("p",{className:"text-foreground leading-relaxed",style:{fontSize:"inherit"},children:t},s))}):e.jsx("p",{className:"text-muted-foreground text-sm italic",children:"(无文本内容)"})]},t.index))})}const c=new Set(["docx","xlsx","xls","pptx"]);function x({filePath:t,ext:s,zoom:r}){return"docx"===s?e.jsx(o,{filePath:t,zoom:r}):"xlsx"===s||"xls"===s?e.jsx(i,{filePath:t,zoom:r}):"pptx"===s?e.jsx(d,{filePath:t,zoom:r}):null}export{c as OFFICE_EXTS,x as OfficePreview};