@clagentic/console 1.5.0-beta.3 → 1.5.0-beta.4

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/lib/sdk-bridge.js CHANGED
@@ -8,7 +8,7 @@ var { getCodexConfig } = require("./codex-defaults");
8
8
  var { splitShellSegments, attachSkillDiscovery, discoverSkillsWithMeta, mergeSkillsWithMeta } = require("./sdk-skill-discovery");
9
9
  var { createMessageQueue } = require("./sdk-message-queue");
10
10
  var { attachMessageProcessor } = require("./sdk-message-processor");
11
- var { readAgentToolsFromFile } = require("./agents");
11
+ var { readAgentToolsFromFile, parseFrontmatter, slugifyAgentName, AGENTS_SOURCE_DIR } = require("./agents");
12
12
  var { discoverWorkflows } = require("./sdk-workflow-discovery");
13
13
  var { buildEnrichedSlashCommands } = require("./sdk-slash-enrichment");
14
14
 
@@ -453,7 +453,7 @@ function createSDKBridge(opts) {
453
453
  tag: "claude-elicitation",
454
454
  };
455
455
  // Route to session owner only — body carries MCP message text.
456
- if (usersModule.isMultiUser() && session.ownerId && pushModule.sendPushToUser) {
456
+ if (session.ownerId && pushModule.sendPushToUser) {
457
457
  pushModule.sendPushToUser(session.ownerId, _elicitPayload);
458
458
  } else {
459
459
  pushModule.sendPush(_elicitPayload);
@@ -709,7 +709,7 @@ function createSDKBridge(opts) {
709
709
  body: permissionPushBody(toolName, input),
710
710
  };
711
711
  // Route to session owner only — body carries tool name and input (may contain paths/code).
712
- if (usersModule.isMultiUser() && session.ownerId && pushModule.sendPushToUser) {
712
+ if (session.ownerId && pushModule.sendPushToUser) {
713
713
  pushModule.sendPushToUser(session.ownerId, _permPayload);
714
714
  } else {
715
715
  pushModule.sendPush(_permPayload);
@@ -915,8 +915,7 @@ function createSDKBridge(opts) {
915
915
  }
916
916
  var authUser = session.ownerId ? usersModule.findUserById(session.ownerId) : null;
917
917
  var authLinuxUser = authUser && authUser.linuxUser ? authUser.linuxUser : null;
918
- var canAutoLogin = !usersModule.isMultiUser()
919
- || !!authLinuxUser
918
+ var canAutoLogin = !!authLinuxUser
920
919
  || (authUser && authUser.role === "admin");
921
920
  var authTitle = (session.vendor === "codex" ? "Codex" : "Claude Code") + " is not logged in.";
922
921
  var authMsg = {
@@ -1213,8 +1212,7 @@ function createSDKBridge(opts) {
1213
1212
  var vendorName = session.vendor.charAt(0).toUpperCase() + session.vendor.slice(1);
1214
1213
  var authUser = session.ownerId ? usersModule.findUserById(session.ownerId) : null;
1215
1214
  var authLinuxUser = authUser && authUser.linuxUser ? authUser.linuxUser : null;
1216
- var canAutoLogin = !usersModule.isMultiUser()
1217
- || !!authLinuxUser
1215
+ var canAutoLogin = !!authLinuxUser
1218
1216
  || (authUser && authUser.role === "admin");
1219
1217
  var authState = getFreshAuthState();
1220
1218
  logAuthDecision("emit-auth-required", session, "missing adapter", authState);
@@ -1411,6 +1409,10 @@ function createSDKBridge(opts) {
1411
1409
  // JSON array syntax for the tools field. We read the tools list directly
1412
1410
  // from disk and set claudeOpts.tools explicitly so restriction is enforced
1413
1411
  // even if the SDK's parsing path has any quirks.
1412
+ // lr-5bd7 — declared outside the agent block so the model override can be
1413
+ // applied when queryModel is computed below (after loop-settings resolution).
1414
+ var _agentDeclaredModel = null;
1415
+
1414
1416
  if (session.agentName && sessionAdapter.vendor !== 'codex') {
1415
1417
  claudeOpts.agent = session.agentName;
1416
1418
  var agentTools = readAgentToolsFromFile(session.agentName);
@@ -1418,6 +1420,36 @@ function createSDKBridge(opts) {
1418
1420
  claudeOpts.tools = agentTools;
1419
1421
  console.log("[sdk-bridge] agent tools enforced for " + session.agentName + ": " + agentTools.join(", "));
1420
1422
  }
1423
+
1424
+ // lr-5bd7 — inject AGENT.md body as systemPrompt on the main thread.
1425
+ // The `agents` map approach (PR #264) only applies to subagent invocations
1426
+ // via the Agent tool; it does not deliver the body to the main conversation.
1427
+ // Setting claudeOpts.systemPrompt bypasses settingSources/agents-map resolution
1428
+ // and ensures the model receives the agent persona directly.
1429
+ // We keep claudeOpts.agent set — it still applies tool restrictions via settingSources.
1430
+ var agentSlug = slugifyAgentName(session.agentName);
1431
+ var agentFilePath = path.join(AGENTS_SOURCE_DIR, agentSlug + ".md");
1432
+ var agentRaw;
1433
+ try {
1434
+ agentRaw = fs.readFileSync(agentFilePath, "utf8");
1435
+ } catch (e) {
1436
+ agentRaw = null;
1437
+ }
1438
+ if (agentRaw) {
1439
+ var agentParsed = parseFrontmatter(agentRaw);
1440
+ var agentBody = agentParsed && agentParsed.body ? agentParsed.body.trim() : null;
1441
+ if (agentBody) {
1442
+ claudeOpts.systemPrompt = agentBody;
1443
+ console.log("[sdk-bridge] agent body injected as systemPrompt for " + session.agentName + " (" + agentBody.length + " chars)");
1444
+ }
1445
+ // lr-5bd7 — capture the agent's declared model so we can override queryModel below.
1446
+ // The UI-selected model (sm.currentModel / session.model) must not override the
1447
+ // agent's own model declaration (e.g. opus for holden).
1448
+ if (agentParsed && agentParsed.meta && agentParsed.meta.model) {
1449
+ _agentDeclaredModel = agentParsed.meta.model;
1450
+ console.log("[sdk-bridge] agent declared model for " + session.agentName + ": " + _agentDeclaredModel);
1451
+ }
1452
+ }
1421
1453
  }
1422
1454
 
1423
1455
  // Per-loop settings override global defaults when present
@@ -1502,6 +1534,14 @@ function createSDKBridge(opts) {
1502
1534
  queryModel = modelEntryValue(queryModel) || undefined;
1503
1535
  }
1504
1536
 
1537
+ // lr-5bd7 — agent model wins over the UI-selected model. Apply after all
1538
+ // vendor-validation logic so the agent model goes through as-is (it is
1539
+ // already a valid short-form like "opus" or a full model ID).
1540
+ if (_agentDeclaredModel) {
1541
+ queryModel = _agentDeclaredModel;
1542
+ console.log("[sdk-bridge] agent model override applied: " + queryModel);
1543
+ }
1544
+
1505
1545
  var codexConfig = getCodexConfig(sm);
1506
1546
  var mergedMcpServers = mergeMcpServers(getMcpServers(), getRemoteMcpServers) || undefined;
1507
1547
  var queryOpts = {
@@ -333,7 +333,7 @@ function attachMessageProcessor(ctx) {
333
333
  tag: "claude-ask",
334
334
  };
335
335
  // Route to session owner only — content carries prompt text.
336
- if (usersModule.isMultiUser() && session.ownerId && pushModule.sendPushToUser) {
336
+ if (session.ownerId && pushModule.sendPushToUser) {
337
337
  pushModule.sendPushToUser(session.ownerId, _askPayload);
338
338
  } else {
339
339
  pushModule.sendPush(_askPayload);
@@ -514,8 +514,7 @@ function attachMessageProcessor(ctx) {
514
514
  if (isLoginPrompt) {
515
515
  var authUser = session.ownerId ? usersModule.findUserById(session.ownerId) : null;
516
516
  var authLinuxUser = authUser && authUser.linuxUser ? authUser.linuxUser : null;
517
- var canAutoLogin = !usersModule.isMultiUser()
518
- || !!authLinuxUser
517
+ var canAutoLogin = !!authLinuxUser
519
518
  || (authUser && authUser.role === "admin");
520
519
  var authTitle = session.vendor === "codex" ? "Codex is not logged in." : "Claude Code is not logged in.";
521
520
  var loginCommand = session.vendor === "codex"
@@ -561,7 +560,7 @@ function attachMessageProcessor(ctx) {
561
560
  tag: "claude-done",
562
561
  };
563
562
  // Route to session owner only — body carries response preview text.
564
- if (usersModule.isMultiUser() && session.ownerId && pushModule.sendPushToUser) {
563
+ if (session.ownerId && pushModule.sendPushToUser) {
565
564
  pushModule.sendPushToUser(session.ownerId, _donePayload);
566
565
  } else {
567
566
  pushModule.sendPush(_donePayload);
@@ -26,11 +26,6 @@ function attachAdmin(ctx) {
26
26
 
27
27
  // List all users (admin only)
28
28
  if (req.method === "GET" && fullUrl === "/api/admin/users") {
29
- if (!users.isMultiUser()) {
30
- res.writeHead(404, { "Content-Type": "application/json" });
31
- res.end('{"error":"Not found"}');
32
- return true;
33
- }
34
29
  var mu = getMultiUserFromReq(req);
35
30
  if (!mu) {
36
31
  res.writeHead(401, { "Content-Type": "application/json" });
@@ -54,11 +49,6 @@ function attachAdmin(ctx) {
54
49
 
55
50
  // Remove user (admin only)
56
51
  if (req.method === "DELETE" && fullUrl.indexOf("/api/admin/users/") === 0) {
57
- if (!users.isMultiUser()) {
58
- res.writeHead(404, { "Content-Type": "application/json" });
59
- res.end('{"error":"Not found"}');
60
- return true;
61
- }
62
52
  var mu = getMultiUserFromReq(req);
63
53
  if (!mu || mu.role !== "admin") {
64
54
  res.writeHead(403, { "Content-Type": "application/json" });
@@ -99,11 +89,6 @@ function attachAdmin(ctx) {
99
89
 
100
90
  // Create user (admin only) — generates a temporary PIN that must be changed on first login
101
91
  if (req.method === "POST" && fullUrl === "/api/admin/users") {
102
- if (!users.isMultiUser()) {
103
- res.writeHead(404, { "Content-Type": "application/json" });
104
- res.end('{"error":"Not found"}');
105
- return true;
106
- }
107
92
  var mu = getMultiUserFromReq(req);
108
93
  if (!mu || mu.role !== "admin") {
109
94
  res.writeHead(403, { "Content-Type": "application/json" });
@@ -166,11 +151,6 @@ function attachAdmin(ctx) {
166
151
 
167
152
  // Reset user PIN (admin only) — generates a new temp PIN
168
153
  if (req.method === "POST" && fullUrl.match(/^\/api\/admin\/users\/[^/]+\/reset-pin$/)) {
169
- if (!users.isMultiUser()) {
170
- res.writeHead(404, { "Content-Type": "application/json" });
171
- res.end('{"error":"Not found"}');
172
- return true;
173
- }
174
154
  var mu = getMultiUserFromReq(req);
175
155
  if (!mu || mu.role !== "admin") {
176
156
  res.writeHead(403, { "Content-Type": "application/json" });
@@ -214,11 +194,6 @@ function attachAdmin(ctx) {
214
194
 
215
195
  // Set Linux user mapping (admin only, OS-level multi-user)
216
196
  if (req.method === "PUT" && fullUrl.match(/^\/api\/admin\/users\/[^/]+\/linux-user$/)) {
217
- if (!users.isMultiUser()) {
218
- res.writeHead(404, { "Content-Type": "application/json" });
219
- res.end('{"error":"Not found"}');
220
- return true;
221
- }
222
197
  var mu = getMultiUserFromReq(req);
223
198
  if (!mu || mu.role !== "admin") {
224
199
  res.writeHead(403, { "Content-Type": "application/json" });
@@ -250,11 +225,6 @@ function attachAdmin(ctx) {
250
225
 
251
226
  // Update user permissions (admin only)
252
227
  if (req.method === "PUT" && fullUrl.match(/^\/api\/admin\/users\/[^/]+\/permissions$/)) {
253
- if (!users.isMultiUser()) {
254
- res.writeHead(404, { "Content-Type": "application/json" });
255
- res.end('{"error":"Not found"}');
256
- return true;
257
- }
258
228
  var mu = getMultiUserFromReq(req);
259
229
  if (!mu || mu.role !== "admin") {
260
230
  res.writeHead(403, { "Content-Type": "application/json" });
@@ -286,11 +256,6 @@ function attachAdmin(ctx) {
286
256
 
287
257
  // Create invite (admin only)
288
258
  if (req.method === "POST" && fullUrl === "/api/admin/invites") {
289
- if (!users.isMultiUser()) {
290
- res.writeHead(404, { "Content-Type": "application/json" });
291
- res.end('{"error":"Not found"}');
292
- return true;
293
- }
294
259
  var mu = getMultiUserFromReq(req);
295
260
  if (!mu || mu.role !== "admin") {
296
261
  res.writeHead(403, { "Content-Type": "application/json" });
@@ -308,11 +273,6 @@ function attachAdmin(ctx) {
308
273
 
309
274
  // List invites (admin only)
310
275
  if (req.method === "GET" && fullUrl === "/api/admin/invites") {
311
- if (!users.isMultiUser()) {
312
- res.writeHead(404, { "Content-Type": "application/json" });
313
- res.end('{"error":"Not found"}');
314
- return true;
315
- }
316
276
  var mu = getMultiUserFromReq(req);
317
277
  if (!mu || mu.role !== "admin") {
318
278
  res.writeHead(403, { "Content-Type": "application/json" });
@@ -326,11 +286,6 @@ function attachAdmin(ctx) {
326
286
 
327
287
  // Revoke invite (admin only)
328
288
  if (req.method === "DELETE" && fullUrl.indexOf("/api/admin/invites/") === 0) {
329
- if (!users.isMultiUser()) {
330
- res.writeHead(404, { "Content-Type": "application/json" });
331
- res.end('{"error":"Not found"}');
332
- return true;
333
- }
334
289
  var mu = getMultiUserFromReq(req);
335
290
  if (!mu || mu.role !== "admin") {
336
291
  res.writeHead(403, { "Content-Type": "application/json" });
@@ -356,7 +311,7 @@ function attachAdmin(ctx) {
356
311
 
357
312
  // Send invite via email (admin only)
358
313
  if (req.method === "POST" && fullUrl === "/api/admin/invites/email") {
359
- if (!users.isMultiUser() || !smtp.isSmtpConfigured()) {
314
+ if (!smtp.isSmtpConfigured()) {
360
315
  res.writeHead(400, { "Content-Type": "application/json" });
361
316
  res.end('{"error":"SMTP not configured"}');
362
317
  return true;
@@ -398,11 +353,6 @@ function attachAdmin(ctx) {
398
353
 
399
354
  // Get SMTP config (admin only)
400
355
  if (req.method === "GET" && fullUrl === "/api/admin/smtp") {
401
- if (!users.isMultiUser()) {
402
- res.writeHead(404, { "Content-Type": "application/json" });
403
- res.end('{"error":"Not found"}');
404
- return true;
405
- }
406
356
  var mu = getMultiUserFromReq(req);
407
357
  if (!mu || mu.role !== "admin") {
408
358
  res.writeHead(403, { "Content-Type": "application/json" });
@@ -422,11 +372,6 @@ function attachAdmin(ctx) {
422
372
 
423
373
  // Save SMTP config (admin only)
424
374
  if (req.method === "POST" && fullUrl === "/api/admin/smtp") {
425
- if (!users.isMultiUser()) {
426
- res.writeHead(404, { "Content-Type": "application/json" });
427
- res.end('{"error":"Not found"}');
428
- return true;
429
- }
430
375
  var mu = getMultiUserFromReq(req);
431
376
  if (!mu || mu.role !== "admin") {
432
377
  res.writeHead(403, { "Content-Type": "application/json" });
@@ -488,11 +433,6 @@ function attachAdmin(ctx) {
488
433
 
489
434
  // Test SMTP connection (admin only)
490
435
  if (req.method === "POST" && fullUrl === "/api/admin/smtp/test") {
491
- if (!users.isMultiUser()) {
492
- res.writeHead(404, { "Content-Type": "application/json" });
493
- res.end('{"error":"Not found"}');
494
- return true;
495
- }
496
436
  var mu = getMultiUserFromReq(req);
497
437
  if (!mu || mu.role !== "admin") {
498
438
  res.writeHead(403, { "Content-Type": "application/json" });
@@ -543,11 +483,6 @@ function attachAdmin(ctx) {
543
483
 
544
484
  // Set project visibility (admin only)
545
485
  if (req.method === "PUT" && /^\/api\/admin\/projects\/[a-z0-9_-]+\/visibility$/.test(fullUrl)) {
546
- if (!users.isMultiUser()) {
547
- res.writeHead(404, { "Content-Type": "application/json" });
548
- res.end('{"error":"Not found"}');
549
- return true;
550
- }
551
486
  var mu = getMultiUserFromReq(req);
552
487
  var _visSlug = fullUrl.split("/")[4];
553
488
  var _visAccess = onGetProjectAccess ? onGetProjectAccess(_visSlug) : null;
@@ -596,11 +531,6 @@ function attachAdmin(ctx) {
596
531
 
597
532
  // Set project owner (admin only)
598
533
  if (req.method === "PUT" && /^\/api\/admin\/projects\/[a-z0-9_-]+\/owner$/.test(fullUrl)) {
599
- if (!users.isMultiUser()) {
600
- res.writeHead(404, { "Content-Type": "application/json" });
601
- res.end('{"error":"Not found"}');
602
- return true;
603
- }
604
534
  var mu = getMultiUserFromReq(req);
605
535
  if (!mu || mu.role !== "admin") {
606
536
  res.writeHead(403, { "Content-Type": "application/json" });
@@ -648,11 +578,6 @@ function attachAdmin(ctx) {
648
578
 
649
579
  // Set project allowed users (admin only)
650
580
  if (req.method === "PUT" && /^\/api\/admin\/projects\/[a-z0-9_-]+\/users$/.test(fullUrl)) {
651
- if (!users.isMultiUser()) {
652
- res.writeHead(404, { "Content-Type": "application/json" });
653
- res.end('{"error":"Not found"}');
654
- return true;
655
- }
656
581
  var mu = getMultiUserFromReq(req);
657
582
  var _usrSlug = fullUrl.split("/")[4];
658
583
  var _usrAccess = onGetProjectAccess ? onGetProjectAccess(_usrSlug) : null;
@@ -701,11 +626,6 @@ function attachAdmin(ctx) {
701
626
 
702
627
  // Get project access info (admin or project owner)
703
628
  if (req.method === "GET" && /^\/api\/admin\/projects\/[a-z0-9_-]+\/access$/.test(fullUrl)) {
704
- if (!users.isMultiUser()) {
705
- res.writeHead(404, { "Content-Type": "application/json" });
706
- res.end('{"error":"Not found"}');
707
- return true;
708
- }
709
629
  var mu = getMultiUserFromReq(req);
710
630
  var _accSlug = fullUrl.split("/")[4];
711
631
  var _accAccess = onGetProjectAccess ? onGetProjectAccess(_accSlug) : null;
@@ -734,11 +654,6 @@ function attachAdmin(ctx) {
734
654
 
735
655
  // GET /api/admin/audit — tail the audit log (admin only, read-only)
736
656
  if (req.method === "GET" && fullUrl.indexOf("/api/admin/audit") === 0) {
737
- if (!users.isMultiUser()) {
738
- res.writeHead(404, { "Content-Type": "application/json" });
739
- res.end('{"error":"Not found"}');
740
- return true;
741
- }
742
657
  var mu = getMultiUserFromReq(req);
743
658
  if (!mu || mu.role !== "admin") {
744
659
  res.writeHead(403, { "Content-Type": "application/json" });
@@ -10,30 +10,6 @@ var audit = require("./audit");
10
10
  // treated as valid for one additional TTL cycle to avoid forced logouts on upgrade.
11
11
  var TOKEN_TTL_MS = 30 * 24 * 60 * 60 * 1000;
12
12
 
13
- // --- PIN hashing ---
14
-
15
- function generateAuthToken(pin) {
16
- var salt = crypto.randomBytes(16).toString("hex");
17
- var hash = crypto.scryptSync("clay:" + pin, salt, 64).toString("hex");
18
- return salt + ":" + hash;
19
- }
20
-
21
- function verifyPin(pin, storedHash) {
22
- if (!storedHash) return false;
23
- // New scrypt format: salt_hex:hash_hex (contains colon)
24
- if (storedHash.indexOf(":") !== -1) {
25
- var parts = storedHash.split(":");
26
- var salt = parts[0];
27
- var hash = parts[1];
28
- var derived = crypto.scryptSync("clay:" + pin, salt, 64).toString("hex");
29
- return crypto.timingSafeEqual(Buffer.from(derived, "hex"), Buffer.from(hash, "hex"));
30
- }
31
- // Legacy SHA256 format (no colon)
32
- var legacyHash = crypto.createHash("sha256").update("clay:" + pin).digest("hex");
33
- var match = crypto.timingSafeEqual(Buffer.from(legacyHash, "hex"), Buffer.from(storedHash, "hex"));
34
- return match;
35
- }
36
-
37
13
  // --- Cookie helpers ---
38
14
 
39
15
  function parseCookies(req) {
@@ -46,12 +22,6 @@ function parseCookies(req) {
46
22
  return cookies;
47
23
  }
48
24
 
49
- function isAuthed(req, authToken) {
50
- if (!authToken) return true;
51
- var cookies = parseCookies(req);
52
- return cookies["relay_auth"] === authToken;
53
- }
54
-
55
25
  // --- PIN rate limiting ---
56
26
 
57
27
  var PIN_MAX_ATTEMPTS = 5;
@@ -64,11 +34,8 @@ function attachAuth(ctx) {
64
34
  var tlsOptions = ctx.tlsOptions;
65
35
  var osUsers = ctx.osUsers;
66
36
  var provisionLinuxUser = ctx.provisionLinuxUser;
67
- var onUpgradePin = ctx.onUpgradePin;
68
37
  var onUserProvisioned = ctx.onUserProvisioned;
69
38
 
70
- var authToken = ctx.pinHash || null;
71
-
72
39
  // --- Multi-user auth tokens (persisted to disk) ---
73
40
  var TOKENS_NAME = _isDevMode ? "auth-tokens-dev.json" : "auth-tokens.json";
74
41
  var MULTI_USER_COOKIE = _isDevMode ? "relay_auth_user_dev" : "relay_auth_user";
@@ -335,25 +302,18 @@ function attachAuth(ctx) {
335
302
  }
336
303
 
337
304
  // --- Auth page selection ---
338
- var pinPage = pages.pinPageHtml();
339
305
  var adminSetupPage = pages.adminSetupPageHtml();
340
306
  var loginPage = pages.multiUserLoginPageHtml();
341
307
  var smtpLoginPage = pages.smtpLoginPageHtml();
342
308
 
343
309
  function getAuthPage() {
344
- if (!users.isMultiUser()) return pinPage;
345
310
  if (!users.hasAdmin()) return adminSetupPage;
346
311
  if (smtp.isEmailLoginEnabled()) return smtpLoginPage;
347
312
  return loginPage;
348
313
  }
349
314
 
350
315
  function isRequestAuthed(req) {
351
- if (users.isMultiUser()) return isMultiUserAuthed(req);
352
- return isAuthed(req, authToken);
353
- }
354
-
355
- function setAuthToken(hash) {
356
- authToken = hash;
316
+ return isMultiUserAuthed(req);
357
317
  }
358
318
 
359
319
  // --- Route handler ---
@@ -423,56 +383,8 @@ function attachAuth(ctx) {
423
383
  }
424
384
  }
425
385
 
426
- // Global auth endpoint (single-user PIN)
427
- if (req.method === "POST" && req.url === "/auth") {
428
- var ip = req.socket.remoteAddress || "";
429
- var remaining = checkPinRateLimit(ip);
430
- if (remaining !== null) {
431
- res.writeHead(429, { "Content-Type": "application/json" });
432
- res.end(JSON.stringify({ ok: false, locked: true, retryAfter: remaining }));
433
- return true;
434
- }
435
- var body = "";
436
- req.on("data", function (chunk) { body += chunk; });
437
- req.on("end", function () {
438
- try {
439
- var data = JSON.parse(body);
440
- if (authToken && verifyPin(data.pin, authToken)) {
441
- clearPinFailures(ip);
442
- // Auto-upgrade legacy SHA256 hash to scrypt
443
- if (authToken.indexOf(":") === -1) {
444
- var upgraded = generateAuthToken(data.pin);
445
- authToken = upgraded;
446
- if (typeof onUpgradePin === "function") {
447
- onUpgradePin(upgraded);
448
- }
449
- }
450
- res.writeHead(200, {
451
- "Set-Cookie": "relay_auth=" + authToken + "; Path=/; HttpOnly; SameSite=Strict; Max-Age=31536000" + (tlsOptions ? "; Secure" : ""),
452
- "Content-Type": "application/json",
453
- });
454
- res.end('{"ok":true}');
455
- } else {
456
- recordPinFailure(ip);
457
- var attemptsLeft = PIN_MAX_ATTEMPTS - (pinAttempts[ip] ? pinAttempts[ip].count : 0);
458
- res.writeHead(401, { "Content-Type": "application/json" });
459
- res.end(JSON.stringify({ ok: false, attemptsLeft: Math.max(attemptsLeft, 0) }));
460
- }
461
- } catch (e) {
462
- res.writeHead(400);
463
- res.end("Bad request");
464
- }
465
- });
466
- return true;
467
- }
468
-
469
386
  // Admin setup (first-time multi-user setup)
470
387
  if (req.method === "POST" && fullUrl === "/auth/setup") {
471
- if (!users.isMultiUser()) {
472
- res.writeHead(400, { "Content-Type": "application/json" });
473
- res.end('{"error":"Multi-user mode is not enabled"}');
474
- return true;
475
- }
476
388
  if (users.hasAdmin()) {
477
389
  res.writeHead(400, { "Content-Type": "application/json" });
478
390
  res.end('{"error":"Admin already exists"}');
@@ -546,11 +458,6 @@ function attachAuth(ctx) {
546
458
 
547
459
  // Multi-user login
548
460
  if (req.method === "POST" && fullUrl === "/auth/login") {
549
- if (!users.isMultiUser()) {
550
- res.writeHead(400, { "Content-Type": "application/json" });
551
- res.end('{"error":"Multi-user mode is not enabled"}');
552
- return true;
553
- }
554
461
  var ip = req.socket.remoteAddress || "";
555
462
  // IP-only pre-check (username not yet known — body not read)
556
463
  var remaining = checkPinRateLimit(ip);
@@ -602,7 +509,7 @@ function attachAuth(ctx) {
602
509
 
603
510
  // Request OTP code (SMTP login)
604
511
  if (req.method === "POST" && fullUrl === "/auth/request-otp") {
605
- if (!users.isMultiUser() || !smtp.isEmailLoginEnabled()) {
512
+ if (!smtp.isEmailLoginEnabled()) {
606
513
  res.writeHead(400, { "Content-Type": "application/json" });
607
514
  res.end('{"error":"OTP login not available"}');
608
515
  return true;
@@ -654,7 +561,7 @@ function attachAuth(ctx) {
654
561
 
655
562
  // Verify OTP code (SMTP login)
656
563
  if (req.method === "POST" && fullUrl === "/auth/verify-otp") {
657
- if (!users.isMultiUser() || !smtp.isEmailLoginEnabled()) {
564
+ if (!smtp.isEmailLoginEnabled()) {
658
565
  res.writeHead(400, { "Content-Type": "application/json" });
659
566
  res.end('{"error":"OTP login not available"}');
660
567
  return true;
@@ -706,11 +613,6 @@ function attachAuth(ctx) {
706
613
 
707
614
  // Invite registration
708
615
  if (req.method === "POST" && fullUrl === "/auth/register") {
709
- if (!users.isMultiUser()) {
710
- res.writeHead(400, { "Content-Type": "application/json" });
711
- res.end('{"error":"Multi-user mode is not enabled"}');
712
- return true;
713
- }
714
616
  var body = "";
715
617
  req.on("data", function (chunk) { body += chunk; });
716
618
  req.on("end", function () {
@@ -786,23 +688,16 @@ function attachAuth(ctx) {
786
688
 
787
689
  // Logout
788
690
  if (req.method === "POST" && fullUrl === "/auth/logout") {
789
- if (users.isMultiUser()) {
790
- var cookies = parseCookies(req);
791
- var token = cookies[MULTI_USER_COOKIE];
792
- if (token && multiUserTokens[token]) {
793
- delete multiUserTokens[token];
794
- saveTokens();
795
- }
796
- res.writeHead(200, {
797
- "Set-Cookie": MULTI_USER_COOKIE + "=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0" + (tlsOptions ? "; Secure" : ""),
798
- "Content-Type": "application/json",
799
- });
800
- } else {
801
- res.writeHead(200, {
802
- "Set-Cookie": "relay_auth=; Path=/; HttpOnly; SameSite=Strict; Max-Age=0" + (tlsOptions ? "; Secure" : ""),
803
- "Content-Type": "application/json",
804
- });
691
+ var cookies = parseCookies(req);
692
+ var token = cookies[MULTI_USER_COOKIE];
693
+ if (token && multiUserTokens[token]) {
694
+ delete multiUserTokens[token];
695
+ saveTokens();
805
696
  }
697
+ res.writeHead(200, {
698
+ "Set-Cookie": MULTI_USER_COOKIE + "=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0" + (tlsOptions ? "; Secure" : ""),
699
+ "Content-Type": "application/json",
700
+ });
806
701
  res.end('{"ok":true}');
807
702
  return true;
808
703
  }
@@ -810,11 +705,6 @@ function attachAuth(ctx) {
810
705
  // Invite page (magic link)
811
706
  if (req.method === "GET" && fullUrl.indexOf("/invite/") === 0) {
812
707
  var inviteCode = fullUrl.substring("/invite/".length);
813
- if (!users.isMultiUser()) {
814
- res.writeHead(404, { "Content-Type": "text/plain" });
815
- res.end("Not found");
816
- return true;
817
- }
818
708
  var validation = users.validateInvite(inviteCode);
819
709
  if (!validation.valid) {
820
710
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
@@ -840,7 +730,6 @@ function attachAuth(ctx) {
840
730
  revokeUserTokens: revokeUserTokens,
841
731
  setRecovery: setRecovery,
842
732
  clearRecovery: clearRecovery,
843
- setAuthToken: setAuthToken,
844
733
  getAuthPage: getAuthPage,
845
734
  createMultiUserSession: createMultiUserSession,
846
735
  isUserLockedOut: isUserLockedOut,
@@ -848,4 +737,4 @@ function attachAuth(ctx) {
848
737
  };
849
738
  }
850
739
 
851
- module.exports = { attachAuth: attachAuth, generateAuthToken: generateAuthToken, verifyPin: verifyPin };
740
+ module.exports = { attachAuth: attachAuth };
package/lib/server-dm.js CHANGED
@@ -15,13 +15,8 @@ function attachDm(ctx) {
15
15
  var pushModule = ctx.pushModule;
16
16
 
17
17
  function handleMessage(ws, msg) {
18
- var userId;
19
- if (users.isMultiUser()) {
20
- if (!ws._clayUser) return false;
21
- userId = ws._clayUser.id;
22
- } else {
23
- userId = "default";
24
- }
18
+ if (!ws._clayUser) return false;
19
+ var userId = ws._clayUser.id;
25
20
 
26
21
  if (msg.type === "dm_list") {
27
22
  var dmList = dm.getDmList(userId);
@@ -9,14 +9,11 @@ function attachPalette(ctx) {
9
9
  function handleRequest(req, res, fullUrl) {
10
10
  if (req.method !== "GET" || fullUrl !== "/api/palette/search") return false;
11
11
 
12
- var paletteUser = null;
13
- if (users.isMultiUser()) {
14
- paletteUser = getMultiUserFromReq(req);
15
- if (!paletteUser) {
16
- res.writeHead(401, { "Content-Type": "application/json" });
17
- res.end('{"error":"unauthorized"}');
18
- return true;
19
- }
12
+ var paletteUser = getMultiUserFromReq(req);
13
+ if (!paletteUser) {
14
+ res.writeHead(401, { "Content-Type": "application/json" });
15
+ res.end('{"error":"unauthorized"}');
16
+ return true;
20
17
  }
21
18
  var pqs = req.url.indexOf("?") >= 0 ? req.url.substring(req.url.indexOf("?")) : "";
22
19
  var pQuery = new URLSearchParams(pqs).get("q") || "";
@@ -34,12 +31,8 @@ function attachPalette(ctx) {
34
31
  pCtx.sm.sessions.forEach(function (session) {
35
32
  if (session.hidden) return;
36
33
  if (paletteUser) {
37
- if (users.isMultiUser()) {
38
- var sAccess = onGetProjectAccess ? onGetProjectAccess(pSlug) : null;
39
- if (!users.canAccessSession(paletteUser.id, session, sAccess)) return;
40
- }
41
- } else {
42
- if (session.ownerId) return;
34
+ var sAccess = onGetProjectAccess ? onGetProjectAccess(pSlug) : null;
35
+ if (!users.canAccessSession(paletteUser.id, session, sAccess)) return;
43
36
  }
44
37
  var pItem = {
45
38
  projectSlug: pSlug,
@@ -70,12 +63,8 @@ function attachPalette(ctx) {
70
63
  pCtx.sm.sessions.forEach(function (session) {
71
64
  if (session.hidden) return;
72
65
  if (paletteUser) {
73
- if (users.isMultiUser()) {
74
- var sAccess = onGetProjectAccess ? onGetProjectAccess(pSlug) : null;
75
- if (!users.canAccessSession(paletteUser.id, session, sAccess)) return;
76
- }
77
- } else {
78
- if (session.ownerId) return;
66
+ var sAccess = onGetProjectAccess ? onGetProjectAccess(pSlug) : null;
67
+ if (!users.canAccessSession(paletteUser.id, session, sAccess)) return;
79
68
  }
80
69
  accessibleSessions.push(session);
81
70
  });