@clagentic/console 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CREDITS.md +3 -0
- package/LICENSE +21 -0
- package/README.md +250 -0
- package/bin/cli.js +2812 -0
- package/lib/agents-favorites.js +164 -0
- package/lib/agents.js +282 -0
- package/lib/ask-user-mcp-server.js +120 -0
- package/lib/browser-mcp-server.js +484 -0
- package/lib/build-user-env.js +63 -0
- package/lib/certs/fullchain.pem +47 -0
- package/lib/certs/privkey.pem +5 -0
- package/lib/cli-sessions.js +265 -0
- package/lib/codex-defaults.js +18 -0
- package/lib/config.js +332 -0
- package/lib/crisis-safety.js +60 -0
- package/lib/daemon-projects.js +164 -0
- package/lib/daemon.js +1602 -0
- package/lib/dm.js +128 -0
- package/lib/ipc.js +125 -0
- package/lib/ipv4-only.js +39 -0
- package/lib/mcp-local.js +385 -0
- package/lib/notes.js +141 -0
- package/lib/os-users.js +529 -0
- package/lib/pages.js +1325 -0
- package/lib/project-connection.js +302 -0
- package/lib/project-external-trigger.js +236 -0
- package/lib/project-file-watch.js +120 -0
- package/lib/project-filesystem.js +528 -0
- package/lib/project-http.js +753 -0
- package/lib/project-image.js +95 -0
- package/lib/project-knowledge.js +88 -0
- package/lib/project-loop.js +1304 -0
- package/lib/project-mcp.js +374 -0
- package/lib/project-memory.js +39 -0
- package/lib/project-notifications.js +262 -0
- package/lib/project-sessions.js +1581 -0
- package/lib/project-user-mention.js +193 -0
- package/lib/project-user-message.js +628 -0
- package/lib/project.js +1303 -0
- package/lib/public/app.js +1031 -0
- package/lib/public/apple-touch-icon.png +0 -0
- package/lib/public/claude-code-avatar.png +0 -0
- package/lib/public/codex-avatar.png +0 -0
- package/lib/public/console-icon.png +0 -0
- package/lib/public/css/admin.css +736 -0
- package/lib/public/css/agent-picker.css +119 -0
- package/lib/public/css/base.css +235 -0
- package/lib/public/css/channel-layout.css +441 -0
- package/lib/public/css/command-palette.css +559 -0
- package/lib/public/css/debate.css +1609 -0
- package/lib/public/css/diff.css +139 -0
- package/lib/public/css/filebrowser.css +1976 -0
- package/lib/public/css/highlight.css +144 -0
- package/lib/public/css/home-hub.css +545 -0
- package/lib/public/css/icon-strip.css +1856 -0
- package/lib/public/css/input.css +1349 -0
- package/lib/public/css/loop.css +1248 -0
- package/lib/public/css/mention.css +317 -0
- package/lib/public/css/menus.css +857 -0
- package/lib/public/css/messages.css +1833 -0
- package/lib/public/css/mobile-nav.css +1332 -0
- package/lib/public/css/notifications-center.css +296 -0
- package/lib/public/css/overlays.css +1273 -0
- package/lib/public/css/playbook.css +264 -0
- package/lib/public/css/profile.css +397 -0
- package/lib/public/css/rewind.css +671 -0
- package/lib/public/css/scheduler-modal.css +1495 -0
- package/lib/public/css/scheduler.css +1420 -0
- package/lib/public/css/server-settings.css +909 -0
- package/lib/public/css/session-search.css +159 -0
- package/lib/public/css/sidebar.css +2012 -0
- package/lib/public/css/skills.css +789 -0
- package/lib/public/css/sticky-notes.css +854 -0
- package/lib/public/css/stt.css +155 -0
- package/lib/public/css/title-bar.css +674 -0
- package/lib/public/css/tooltip.css +67 -0
- package/lib/public/css/user-settings.css +702 -0
- package/lib/public/emoji-data.json +1 -0
- package/lib/public/favicon-banded-32.png +0 -0
- package/lib/public/favicon-banded.png +0 -0
- package/lib/public/favicon-dark.svg +32 -0
- package/lib/public/favicon.svg +32 -0
- package/lib/public/icon-192.png +0 -0
- package/lib/public/icon-512.png +0 -0
- package/lib/public/icon-banded-76.png +0 -0
- package/lib/public/icon-banded-96.png +0 -0
- package/lib/public/icon-mono.svg +25 -0
- package/lib/public/icons/email/gmail.svg +7 -0
- package/lib/public/icons/email/outlook.svg +35 -0
- package/lib/public/icons/email/yahoo.svg +1 -0
- package/lib/public/index.html +1946 -0
- package/lib/public/manifest.json +27 -0
- package/lib/public/markdown-worker.js +43 -0
- package/lib/public/marked.min.js +6 -0
- package/lib/public/modules/admin.js +954 -0
- package/lib/public/modules/agent-picker.js +429 -0
- package/lib/public/modules/app-connection.js +216 -0
- package/lib/public/modules/app-cursors.js +492 -0
- package/lib/public/modules/app-dm.js +265 -0
- package/lib/public/modules/app-favicon.js +231 -0
- package/lib/public/modules/app-header.js +242 -0
- package/lib/public/modules/app-home-hub.js +432 -0
- package/lib/public/modules/app-loop-ui.js +691 -0
- package/lib/public/modules/app-loop-wizard.js +439 -0
- package/lib/public/modules/app-messages.js +1415 -0
- package/lib/public/modules/app-misc.js +463 -0
- package/lib/public/modules/app-notifications.js +651 -0
- package/lib/public/modules/app-panels.js +1061 -0
- package/lib/public/modules/app-projects.js +875 -0
- package/lib/public/modules/app-rate-limit.js +529 -0
- package/lib/public/modules/app-rendering.js +739 -0
- package/lib/public/modules/app-skills-install.js +285 -0
- package/lib/public/modules/avatar.js +36 -0
- package/lib/public/modules/command-palette.js +491 -0
- package/lib/public/modules/console-logo.js +162 -0
- package/lib/public/modules/context-sources.js +365 -0
- package/lib/public/modules/diff.js +412 -0
- package/lib/public/modules/dom-refs.js +21 -0
- package/lib/public/modules/emoji-picker.js +222 -0
- package/lib/public/modules/events.js +21 -0
- package/lib/public/modules/filebrowser.js +1966 -0
- package/lib/public/modules/fileicons.js +172 -0
- package/lib/public/modules/icons.js +80 -0
- package/lib/public/modules/input.js +1102 -0
- package/lib/public/modules/longpress.js +74 -0
- package/lib/public/modules/markdown.js +486 -0
- package/lib/public/modules/mcp-ui.js +295 -0
- package/lib/public/modules/mention.js +1093 -0
- package/lib/public/modules/notifications.js +613 -0
- package/lib/public/modules/playbook.js +578 -0
- package/lib/public/modules/profile.js +594 -0
- package/lib/public/modules/project-settings.js +849 -0
- package/lib/public/modules/project-switcher.js +375 -0
- package/lib/public/modules/qrcode.js +87 -0
- package/lib/public/modules/rewind.js +381 -0
- package/lib/public/modules/scheduler-config.js +1611 -0
- package/lib/public/modules/scheduler-history.js +131 -0
- package/lib/public/modules/scheduler.js +1689 -0
- package/lib/public/modules/server-settings.js +842 -0
- package/lib/public/modules/session-search.js +456 -0
- package/lib/public/modules/settings-defaults.js +253 -0
- package/lib/public/modules/sidebar-mobile.js +1425 -0
- package/lib/public/modules/sidebar-projects.js +2022 -0
- package/lib/public/modules/sidebar-sessions.js +1548 -0
- package/lib/public/modules/sidebar-users.js +449 -0
- package/lib/public/modules/sidebar.js +348 -0
- package/lib/public/modules/skills.js +793 -0
- package/lib/public/modules/state.js +3 -0
- package/lib/public/modules/sticky-notes.js +1221 -0
- package/lib/public/modules/store.js +34 -0
- package/lib/public/modules/stt.js +266 -0
- package/lib/public/modules/terminal.js +987 -0
- package/lib/public/modules/theme.js +812 -0
- package/lib/public/modules/tool-palette.js +562 -0
- package/lib/public/modules/tools.js +2285 -0
- package/lib/public/modules/tooltip.js +150 -0
- package/lib/public/modules/user-settings.js +544 -0
- package/lib/public/modules/utils.js +56 -0
- package/lib/public/modules/ws-ref.js +26 -0
- package/lib/public/style.css +34 -0
- package/lib/public/sw.js +159 -0
- package/lib/push.js +149 -0
- package/lib/scheduler.js +471 -0
- package/lib/sdk-bridge.js +1792 -0
- package/lib/sdk-message-processor.js +740 -0
- package/lib/sdk-message-queue.js +42 -0
- package/lib/sdk-skill-discovery.js +131 -0
- package/lib/sdk-worker.js +677 -0
- package/lib/server-admin.js +712 -0
- package/lib/server-auth.js +737 -0
- package/lib/server-dm.js +170 -0
- package/lib/server-palette.js +104 -0
- package/lib/server-settings.js +553 -0
- package/lib/server-skills.js +280 -0
- package/lib/server.js +1390 -0
- package/lib/session-search.js +693 -0
- package/lib/sessions.js +946 -0
- package/lib/smtp.js +221 -0
- package/lib/terminal-manager.js +219 -0
- package/lib/terminal.js +39 -0
- package/lib/themes/ayu-light.json +9 -0
- package/lib/themes/catppuccin-latte.json +9 -0
- package/lib/themes/catppuccin-mocha.json +9 -0
- package/lib/themes/clagentic-dark.json +10 -0
- package/lib/themes/clagentic-light.json +10 -0
- package/lib/themes/dracula.json +9 -0
- package/lib/themes/everforest-light.json +9 -0
- package/lib/themes/everforest.json +9 -0
- package/lib/themes/github-light.json +9 -0
- package/lib/themes/gruvbox-dark.json +9 -0
- package/lib/themes/gruvbox-light.json +9 -0
- package/lib/themes/monokai.json +9 -0
- package/lib/themes/nord-light.json +9 -0
- package/lib/themes/nord.json +9 -0
- package/lib/themes/one-dark.json +9 -0
- package/lib/themes/one-light.json +9 -0
- package/lib/themes/rose-pine-dawn.json +9 -0
- package/lib/themes/rose-pine.json +9 -0
- package/lib/themes/solarized-dark.json +9 -0
- package/lib/themes/solarized-light.json +9 -0
- package/lib/themes/tokyo-night-light.json +9 -0
- package/lib/themes/tokyo-night.json +9 -0
- package/lib/updater.js +124 -0
- package/lib/user-presence.js +92 -0
- package/lib/users-auth.js +146 -0
- package/lib/users-permissions.js +118 -0
- package/lib/users-preferences.js +254 -0
- package/lib/users.js +465 -0
- package/lib/utils.js +64 -0
- package/lib/worktree.js +134 -0
- package/lib/ws-schema.js +464 -0
- package/lib/yoke/adapters/claude-worker.js +759 -0
- package/lib/yoke/adapters/claude.js +1599 -0
- package/lib/yoke/adapters/codex.js +1559 -0
- package/lib/yoke/codex-app-server.js +352 -0
- package/lib/yoke/index.js +319 -0
- package/lib/yoke/instructions.js +61 -0
- package/lib/yoke/interface.js +98 -0
- package/lib/yoke/mcp-bridge-server.js +302 -0
- package/lib/yoke/package.json +7 -0
- package/package.json +72 -0
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
var fs = require("fs");
|
|
2
|
+
var path = require("path");
|
|
3
|
+
|
|
4
|
+
function attachSettings(ctx) {
|
|
5
|
+
var users = ctx.users;
|
|
6
|
+
var getMultiUserFromReq = ctx.getMultiUserFromReq;
|
|
7
|
+
var projects = ctx.projects;
|
|
8
|
+
var opts = ctx.opts;
|
|
9
|
+
var CONFIG_DIR = ctx.CONFIG_DIR;
|
|
10
|
+
|
|
11
|
+
var profilePath = path.join(CONFIG_DIR, "profile.json");
|
|
12
|
+
|
|
13
|
+
function handleRequest(req, res, fullUrl) {
|
|
14
|
+
// GET /api/profile
|
|
15
|
+
if (req.method === "GET" && fullUrl === "/api/profile") {
|
|
16
|
+
if (users.isMultiUser()) {
|
|
17
|
+
var mu = getMultiUserFromReq(req);
|
|
18
|
+
if (!mu) {
|
|
19
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
20
|
+
res.end('{"error":"unauthorized"}');
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
var profile = mu.profile || { name: "", lang: "en-US", avatarColor: "#7c3aed", avatarStyle: "thumbs", avatarSeed: "", avatarCustom: "" };
|
|
24
|
+
profile.username = mu.username;
|
|
25
|
+
profile.userId = mu.id;
|
|
26
|
+
profile.role = mu.role;
|
|
27
|
+
profile.pinEnabled = !!mu.pinHash;
|
|
28
|
+
profile.autoContinueOnRateLimit = !!mu.autoContinueOnRateLimit;
|
|
29
|
+
profile.chatLayout = mu.chatLayout || "channel";
|
|
30
|
+
profile.themeMode = mu.themeMode || null;
|
|
31
|
+
profile.themeBrand = mu.themeBrand || null;
|
|
32
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
33
|
+
res.end(JSON.stringify(profile));
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
var profile = { name: "", lang: "en-US", avatarColor: "#7c3aed", avatarStyle: "thumbs", avatarSeed: "", avatarCustom: "" };
|
|
37
|
+
try {
|
|
38
|
+
var raw = fs.readFileSync(profilePath, "utf8");
|
|
39
|
+
var saved = JSON.parse(raw);
|
|
40
|
+
if (saved.name !== undefined) profile.name = saved.name;
|
|
41
|
+
if (saved.lang) profile.lang = saved.lang;
|
|
42
|
+
if (saved.avatarColor) profile.avatarColor = saved.avatarColor;
|
|
43
|
+
if (saved.avatarStyle) profile.avatarStyle = saved.avatarStyle;
|
|
44
|
+
if (saved.avatarSeed) profile.avatarSeed = saved.avatarSeed;
|
|
45
|
+
if (saved.avatarCustom) profile.avatarCustom = saved.avatarCustom;
|
|
46
|
+
} catch (e) { /* file doesn't exist yet */ }
|
|
47
|
+
// Single-user settings from daemon config
|
|
48
|
+
if (typeof opts.onGetDaemonConfig === "function") {
|
|
49
|
+
var dc = opts.onGetDaemonConfig();
|
|
50
|
+
profile.autoContinueOnRateLimit = !!dc.autoContinueOnRateLimit;
|
|
51
|
+
profile.chatLayout = dc.chatLayout || "channel";
|
|
52
|
+
profile.themeMode = dc.themeMode || null;
|
|
53
|
+
profile.themeBrand = dc.themeBrand || null;
|
|
54
|
+
}
|
|
55
|
+
// Check if custom avatar file exists
|
|
56
|
+
try {
|
|
57
|
+
var avatarFiles = fs.readdirSync(path.join(CONFIG_DIR, "avatars"));
|
|
58
|
+
for (var afi = 0; afi < avatarFiles.length; afi++) {
|
|
59
|
+
if (avatarFiles[afi].startsWith("default.")) {
|
|
60
|
+
profile.avatarCustom = "/api/avatar/default?v=" + fs.statSync(path.join(CONFIG_DIR, "avatars", avatarFiles[afi])).mtimeMs;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} catch (e) {}
|
|
65
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
66
|
+
res.end(JSON.stringify(profile));
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// PUT /api/profile
|
|
71
|
+
if (req.method === "PUT" && fullUrl === "/api/profile") {
|
|
72
|
+
var body = "";
|
|
73
|
+
req.on("data", function (chunk) { body += chunk; });
|
|
74
|
+
req.on("end", function () {
|
|
75
|
+
try {
|
|
76
|
+
var data = JSON.parse(body);
|
|
77
|
+
var profile = {};
|
|
78
|
+
if (typeof data.name === "string") profile.name = data.name.substring(0, 50);
|
|
79
|
+
if (typeof data.lang === "string") profile.lang = data.lang.substring(0, 10);
|
|
80
|
+
if (typeof data.avatarColor === "string" && /^#[0-9a-fA-F]{6}$/.test(data.avatarColor)) {
|
|
81
|
+
profile.avatarColor = data.avatarColor;
|
|
82
|
+
}
|
|
83
|
+
if (typeof data.avatarStyle === "string") profile.avatarStyle = data.avatarStyle.substring(0, 30);
|
|
84
|
+
if (typeof data.avatarSeed === "string") profile.avatarSeed = data.avatarSeed.substring(0, 30);
|
|
85
|
+
if (typeof data.avatarCustom === "string") profile.avatarCustom = data.avatarCustom;
|
|
86
|
+
if (data.avatarCustom === null || data.avatarCustom === "") profile.avatarCustom = undefined;
|
|
87
|
+
if (users.isMultiUser()) {
|
|
88
|
+
var mu = getMultiUserFromReq(req);
|
|
89
|
+
if (!mu) {
|
|
90
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
91
|
+
res.end('{"error":"unauthorized"}');
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
users.updateUserProfile(mu.id, profile);
|
|
95
|
+
// Broadcast updated avatar/presence to all projects
|
|
96
|
+
projects.forEach(function (pCtx) {
|
|
97
|
+
pCtx.refreshUserProfile(mu.id);
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
fs.writeFileSync(profilePath, JSON.stringify(profile, null, 2), "utf8");
|
|
101
|
+
if (process.platform !== "win32") {
|
|
102
|
+
try { fs.chmodSync(profilePath, 0o600); } catch (chmodErr) {}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
106
|
+
res.end(JSON.stringify(profile));
|
|
107
|
+
} catch (e) {
|
|
108
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
109
|
+
res.end(JSON.stringify({ error: "Invalid request" }));
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Upload custom avatar image
|
|
116
|
+
if (req.method === "POST" && fullUrl === "/api/avatar") {
|
|
117
|
+
var chunks = [];
|
|
118
|
+
var totalSize = 0;
|
|
119
|
+
var maxSize = 2 * 1024 * 1024; // 2MB
|
|
120
|
+
req.on("data", function (chunk) {
|
|
121
|
+
totalSize += chunk.length;
|
|
122
|
+
if (totalSize <= maxSize) chunks.push(chunk);
|
|
123
|
+
});
|
|
124
|
+
req.on("end", function () {
|
|
125
|
+
if (totalSize > maxSize) {
|
|
126
|
+
res.writeHead(413, { "Content-Type": "application/json" });
|
|
127
|
+
res.end('{"error":"File too large (max 2MB)"}');
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
var raw = Buffer.concat(chunks);
|
|
131
|
+
// Detect content type from magic bytes
|
|
132
|
+
var ct = null;
|
|
133
|
+
if (raw[0] === 0xFF && raw[1] === 0xD8) ct = "image/jpeg";
|
|
134
|
+
else if (raw[0] === 0x89 && raw[1] === 0x50) ct = "image/png";
|
|
135
|
+
else if (raw[0] === 0x47 && raw[1] === 0x49) ct = "image/gif";
|
|
136
|
+
else if (raw[0] === 0x52 && raw[1] === 0x49) ct = "image/webp";
|
|
137
|
+
if (!ct) {
|
|
138
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
139
|
+
res.end('{"error":"Unsupported image format"}');
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
var ext = ct.split("/")[1] === "jpeg" ? "jpg" : ct.split("/")[1];
|
|
143
|
+
var avatarDir = path.join(CONFIG_DIR, "avatars");
|
|
144
|
+
fs.mkdirSync(avatarDir, { recursive: true });
|
|
145
|
+
|
|
146
|
+
var userId = "default";
|
|
147
|
+
if (users.isMultiUser()) {
|
|
148
|
+
var mu = getMultiUserFromReq(req);
|
|
149
|
+
if (!mu) {
|
|
150
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
151
|
+
res.end('{"error":"unauthorized"}');
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
userId = mu.id;
|
|
155
|
+
}
|
|
156
|
+
var filename = userId + "." + ext;
|
|
157
|
+
// Remove old avatar files for this user
|
|
158
|
+
try {
|
|
159
|
+
var existing = fs.readdirSync(avatarDir);
|
|
160
|
+
for (var ei = 0; ei < existing.length; ei++) {
|
|
161
|
+
if (existing[ei].startsWith(userId + ".")) {
|
|
162
|
+
fs.unlinkSync(path.join(avatarDir, existing[ei]));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
} catch (e) {}
|
|
166
|
+
var avatarFilePath = path.join(avatarDir, filename);
|
|
167
|
+
fs.writeFileSync(avatarFilePath, raw);
|
|
168
|
+
try { fs.chmodSync(avatarFilePath, 0o644); } catch (e) {}
|
|
169
|
+
try { fs.chmodSync(avatarDir, 0o755); } catch (e) {}
|
|
170
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
171
|
+
res.end(JSON.stringify({ ok: true, avatar: "/api/avatar/" + userId + "?v=" + Date.now() }));
|
|
172
|
+
});
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Serve custom avatar image
|
|
177
|
+
if (req.method === "GET" && fullUrl.startsWith("/api/avatar/")) {
|
|
178
|
+
var avatarUserId = fullUrl.split("/api/avatar/")[1].split("?")[0];
|
|
179
|
+
var avatarDir = path.join(CONFIG_DIR, "avatars");
|
|
180
|
+
try {
|
|
181
|
+
var files = fs.readdirSync(avatarDir);
|
|
182
|
+
var match = null;
|
|
183
|
+
for (var fi = 0; fi < files.length; fi++) {
|
|
184
|
+
if (files[fi].startsWith(avatarUserId + ".")) {
|
|
185
|
+
match = files[fi];
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (match) {
|
|
190
|
+
var ext = match.split(".").pop();
|
|
191
|
+
var ctMap = { jpg: "image/jpeg", png: "image/png", gif: "image/gif", webp: "image/webp" };
|
|
192
|
+
res.writeHead(200, {
|
|
193
|
+
"Content-Type": ctMap[ext] || "application/octet-stream",
|
|
194
|
+
"Cache-Control": "public, max-age=31536000, immutable",
|
|
195
|
+
});
|
|
196
|
+
res.end(fs.readFileSync(path.join(avatarDir, match)));
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
} catch (e) {}
|
|
200
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
201
|
+
res.end('{"error":"not found"}');
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Change own PIN (multi-user mode)
|
|
206
|
+
if (req.method === "PUT" && fullUrl === "/api/user/pin") {
|
|
207
|
+
if (!users.isMultiUser()) {
|
|
208
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
209
|
+
res.end('{"error":"Not found"}');
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
var mu = getMultiUserFromReq(req);
|
|
213
|
+
if (!mu) {
|
|
214
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
215
|
+
res.end('{"error":"unauthorized"}');
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
var body = "";
|
|
219
|
+
req.on("data", function (chunk) { body += chunk; });
|
|
220
|
+
req.on("end", function () {
|
|
221
|
+
try {
|
|
222
|
+
var data = JSON.parse(body);
|
|
223
|
+
if (!data.newPin || typeof data.newPin !== "string" || !/^\d{6}$/.test(data.newPin)) {
|
|
224
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
225
|
+
res.end('{"error":"PIN must be exactly 6 digits"}');
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
// Forced PIN change after temporary PIN login: skip currentPin
|
|
229
|
+
// verification. The user authenticated with the temp PIN to
|
|
230
|
+
// establish this session, so requiring them to re-enter it adds
|
|
231
|
+
// friction without security benefit. The session cookie is the
|
|
232
|
+
// proof of possession.
|
|
233
|
+
if (mu.pinHash && !mu.mustChangePin) {
|
|
234
|
+
if (!data.currentPin || typeof data.currentPin !== "string" || !/^\d{6}$/.test(data.currentPin)) {
|
|
235
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
236
|
+
res.end('{"error":"Current PIN is required"}');
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (mu.pinHash !== users.hashPin(data.currentPin)) {
|
|
240
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
241
|
+
res.end('{"error":"Current PIN is incorrect"}');
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
var result = users.updateUserPin(mu.id, data.newPin);
|
|
246
|
+
if (result.error) {
|
|
247
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
248
|
+
res.end(JSON.stringify({ error: result.error }));
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
252
|
+
res.end('{"ok":true}');
|
|
253
|
+
} catch (e) {
|
|
254
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
255
|
+
res.end('{"error":"Invalid request"}');
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// PUT /api/user/auto-continue
|
|
262
|
+
if (req.method === "PUT" && fullUrl === "/api/user/auto-continue") {
|
|
263
|
+
var isMultiUser = users.isMultiUser();
|
|
264
|
+
var mu = getMultiUserFromReq(req);
|
|
265
|
+
if (!isMultiUser) {
|
|
266
|
+
// Single-user: use daemon config fallback
|
|
267
|
+
var body = "";
|
|
268
|
+
req.on("data", function (chunk) { body += chunk; });
|
|
269
|
+
req.on("end", function () {
|
|
270
|
+
try {
|
|
271
|
+
var data = JSON.parse(body);
|
|
272
|
+
if (typeof opts.onSetAutoContinue === "function") {
|
|
273
|
+
opts.onSetAutoContinue(!!data.enabled);
|
|
274
|
+
}
|
|
275
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
276
|
+
res.end(JSON.stringify({ ok: true, autoContinueOnRateLimit: !!data.enabled }));
|
|
277
|
+
} catch (e) {
|
|
278
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
279
|
+
res.end('{"error":"Invalid request"}');
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
if (!mu) {
|
|
285
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
286
|
+
res.end('{"error":"unauthorized"}');
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
var body = "";
|
|
290
|
+
req.on("data", function (chunk) { body += chunk; });
|
|
291
|
+
req.on("end", function () {
|
|
292
|
+
try {
|
|
293
|
+
var data = JSON.parse(body);
|
|
294
|
+
var result = users.setAutoContinue(mu.id, !!data.enabled);
|
|
295
|
+
if (result.error) {
|
|
296
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
297
|
+
res.end(JSON.stringify({ error: result.error }));
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
301
|
+
res.end(JSON.stringify({ ok: true, autoContinueOnRateLimit: result.autoContinueOnRateLimit }));
|
|
302
|
+
} catch (e) {
|
|
303
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
304
|
+
res.end('{"error":"Invalid request"}');
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// PUT /api/user/chat-layout
|
|
311
|
+
if (req.method === "PUT" && fullUrl === "/api/user/chat-layout") {
|
|
312
|
+
var isMultiUser = users.isMultiUser();
|
|
313
|
+
var mu = getMultiUserFromReq(req);
|
|
314
|
+
if (!isMultiUser) {
|
|
315
|
+
// Single-user: save to daemon config
|
|
316
|
+
var body = "";
|
|
317
|
+
req.on("data", function (chunk) { body += chunk; });
|
|
318
|
+
req.on("end", function () {
|
|
319
|
+
try {
|
|
320
|
+
var data = JSON.parse(body);
|
|
321
|
+
var val = (data.layout === "bubble") ? "bubble" : "channel";
|
|
322
|
+
if (typeof opts.onSetChatLayout === "function") {
|
|
323
|
+
opts.onSetChatLayout(val);
|
|
324
|
+
}
|
|
325
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
326
|
+
res.end(JSON.stringify({ ok: true, chatLayout: val }));
|
|
327
|
+
} catch (e) {
|
|
328
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
329
|
+
res.end('{"error":"Invalid request"}');
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
if (!mu) {
|
|
335
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
336
|
+
res.end('{"error":"unauthorized"}');
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
var body = "";
|
|
340
|
+
req.on("data", function (chunk) { body += chunk; });
|
|
341
|
+
req.on("end", function () {
|
|
342
|
+
try {
|
|
343
|
+
var data = JSON.parse(body);
|
|
344
|
+
var result = users.setChatLayout(mu.id, data.layout);
|
|
345
|
+
if (result.error) {
|
|
346
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
347
|
+
res.end(JSON.stringify({ error: result.error }));
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
351
|
+
res.end(JSON.stringify({ ok: true, chatLayout: result.chatLayout }));
|
|
352
|
+
} catch (e) {
|
|
353
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
354
|
+
res.end('{"error":"Invalid request"}');
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// PUT /api/user/theme-mode
|
|
361
|
+
if (req.method === "PUT" && fullUrl === "/api/user/theme-mode") {
|
|
362
|
+
var isMultiUser = users.isMultiUser();
|
|
363
|
+
var mu = getMultiUserFromReq(req);
|
|
364
|
+
var body = "";
|
|
365
|
+
req.on("data", function (chunk) { body += chunk; });
|
|
366
|
+
req.on("end", function () {
|
|
367
|
+
try {
|
|
368
|
+
var data = JSON.parse(body);
|
|
369
|
+
var mode = (data.themeMode === "light" || data.themeMode === "dark") ? data.themeMode : null;
|
|
370
|
+
if (!isMultiUser) {
|
|
371
|
+
if (typeof opts.onSetThemeMode === "function") {
|
|
372
|
+
opts.onSetThemeMode(mode);
|
|
373
|
+
}
|
|
374
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
375
|
+
res.end(JSON.stringify({ ok: true, themeMode: mode }));
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
if (!mu) {
|
|
379
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
380
|
+
res.end('{"error":"unauthorized"}');
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
var result = users.setThemeMode(mu.id, mode);
|
|
384
|
+
if (result.error) {
|
|
385
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
386
|
+
res.end(JSON.stringify({ error: result.error }));
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
390
|
+
res.end(JSON.stringify({ ok: true, themeMode: result.themeMode }));
|
|
391
|
+
} catch (e) {
|
|
392
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
393
|
+
res.end('{"error":"Invalid request"}');
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
return true;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// PUT /api/user/theme-brand
|
|
400
|
+
if (req.method === "PUT" && fullUrl === "/api/user/theme-brand") {
|
|
401
|
+
var isMultiUser = users.isMultiUser();
|
|
402
|
+
var mu = getMultiUserFromReq(req);
|
|
403
|
+
var body = "";
|
|
404
|
+
req.on("data", function (chunk) { body += chunk; });
|
|
405
|
+
req.on("end", function () {
|
|
406
|
+
try {
|
|
407
|
+
var data = JSON.parse(body);
|
|
408
|
+
var brand = (data.themeBrand === "classic" || data.themeBrand === "clagentic") ? data.themeBrand : null;
|
|
409
|
+
if (!isMultiUser) {
|
|
410
|
+
if (typeof opts.onSetThemeBrand === "function") {
|
|
411
|
+
opts.onSetThemeBrand(brand);
|
|
412
|
+
}
|
|
413
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
414
|
+
res.end(JSON.stringify({ ok: true, themeBrand: brand }));
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (!mu) {
|
|
418
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
419
|
+
res.end('{"error":"unauthorized"}');
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
var result = users.setThemeBrand(mu.id, brand);
|
|
423
|
+
if (result.error) {
|
|
424
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
425
|
+
res.end(JSON.stringify({ error: result.error }));
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
429
|
+
res.end(JSON.stringify({ ok: true, themeBrand: result.themeBrand }));
|
|
430
|
+
} catch (e) {
|
|
431
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
432
|
+
res.end('{"error":"Invalid request"}');
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// POST /api/user/mate-onboarded
|
|
439
|
+
if (req.method === "POST" && fullUrl === "/api/user/mate-onboarded") {
|
|
440
|
+
var isMultiUser = users.isMultiUser();
|
|
441
|
+
var mu = getMultiUserFromReq(req);
|
|
442
|
+
if (!isMultiUser) {
|
|
443
|
+
// Single-user: save to daemon config
|
|
444
|
+
if (typeof opts.onSetMateOnboarded === "function") {
|
|
445
|
+
opts.onSetMateOnboarded();
|
|
446
|
+
}
|
|
447
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
448
|
+
res.end('{"ok":true}');
|
|
449
|
+
} else {
|
|
450
|
+
if (!mu) {
|
|
451
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
452
|
+
res.end('{"error":"unauthorized"}');
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
users.setMateOnboarded(mu.id);
|
|
456
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
457
|
+
res.end('{"ok":true}');
|
|
458
|
+
}
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// GET /api/user/tool-palettes
|
|
463
|
+
if (req.method === "GET" && fullUrl === "/api/user/tool-palettes") {
|
|
464
|
+
var isMultiUser = users.isMultiUser();
|
|
465
|
+
var muGet = getMultiUserFromReq(req);
|
|
466
|
+
var palettes = {};
|
|
467
|
+
if (!isMultiUser) {
|
|
468
|
+
if (typeof opts.onGetToolPalettes === "function") {
|
|
469
|
+
palettes = opts.onGetToolPalettes() || {};
|
|
470
|
+
}
|
|
471
|
+
} else {
|
|
472
|
+
if (!muGet) {
|
|
473
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
474
|
+
res.end('{"error":"unauthorized"}');
|
|
475
|
+
return true;
|
|
476
|
+
}
|
|
477
|
+
palettes = users.getToolPalettes(muGet.id) || {};
|
|
478
|
+
}
|
|
479
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
480
|
+
res.end(JSON.stringify(palettes));
|
|
481
|
+
return true;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// PUT /api/user/tool-palettes
|
|
485
|
+
if (req.method === "PUT" && fullUrl === "/api/user/tool-palettes") {
|
|
486
|
+
var isMultiUser = users.isMultiUser();
|
|
487
|
+
var muPut = getMultiUserFromReq(req);
|
|
488
|
+
var bodyTp = "";
|
|
489
|
+
req.on("data", function (chunk) { bodyTp += chunk; });
|
|
490
|
+
req.on("end", function () {
|
|
491
|
+
try {
|
|
492
|
+
var dataTp = JSON.parse(bodyTp);
|
|
493
|
+
var paletteName = dataTp.palette;
|
|
494
|
+
var order = dataTp.order;
|
|
495
|
+
var hidden = dataTp.hidden;
|
|
496
|
+
var result;
|
|
497
|
+
if (!isMultiUser) {
|
|
498
|
+
if (typeof opts.onSetToolPalette !== "function") {
|
|
499
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
500
|
+
res.end('{"error":"Not supported"}');
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
result = opts.onSetToolPalette(paletteName, order, hidden);
|
|
504
|
+
} else {
|
|
505
|
+
if (!muPut) {
|
|
506
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
507
|
+
res.end('{"error":"unauthorized"}');
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
result = users.setToolPalette(muPut.id, paletteName, order, hidden);
|
|
511
|
+
}
|
|
512
|
+
if (result && result.error) {
|
|
513
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
514
|
+
res.end(JSON.stringify({ error: result.error }));
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
518
|
+
res.end(JSON.stringify(result));
|
|
519
|
+
} catch (e) {
|
|
520
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
521
|
+
res.end('{"error":"Invalid request"}');
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
return true;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// GET /api/user/auto-continue
|
|
528
|
+
if (req.method === "GET" && fullUrl === "/api/user/auto-continue") {
|
|
529
|
+
var mu = getMultiUserFromReq(req);
|
|
530
|
+
if (!mu) {
|
|
531
|
+
// Single-user: read from daemon config
|
|
532
|
+
var enabled = false;
|
|
533
|
+
if (typeof opts.onGetDaemonConfig === "function") {
|
|
534
|
+
var dc = opts.onGetDaemonConfig();
|
|
535
|
+
enabled = !!dc.autoContinueOnRateLimit;
|
|
536
|
+
}
|
|
537
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
538
|
+
res.end(JSON.stringify({ autoContinueOnRateLimit: enabled }));
|
|
539
|
+
return true;
|
|
540
|
+
}
|
|
541
|
+
var val = users.getAutoContinue(mu.id);
|
|
542
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
543
|
+
res.end(JSON.stringify({ autoContinueOnRateLimit: val }));
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
return { handleRequest: handleRequest };
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
module.exports = { attachSettings: attachSettings };
|