@pixelbyte-software/pixcode 1.45.0 → 1.46.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.
@@ -306,6 +306,18 @@ const db = {
306
306
  const userDb = {
307
307
  hasUsers: () => store.count('users', (r) => r.is_active) > 0,
308
308
 
309
+ listUsers: () => store.raw.users.map((row) => ({
310
+ id: row.id,
311
+ username: row.username,
312
+ created_at: row.created_at,
313
+ last_login: row.last_login,
314
+ is_active: Boolean(row.is_active),
315
+ git_name: row.git_name || null,
316
+ git_email: row.git_email || null,
317
+ has_completed_onboarding: Boolean(row.has_completed_onboarding),
318
+ role: row.role || null,
319
+ })),
320
+
309
321
  createUser: (username, passwordHash) => {
310
322
  const row = store.insert('users', {
311
323
  username,
@@ -320,6 +332,33 @@ const userDb = {
320
332
  return { id: row.id, username: row.username };
321
333
  },
322
334
 
335
+ createManagedUser: (username, passwordHash, metadata = {}) => {
336
+ const existing = store.raw.users.find((r) => r.username === username);
337
+ if (existing) {
338
+ throw new Error('Username already exists.');
339
+ }
340
+
341
+ const row = store.insert('users', {
342
+ username,
343
+ password_hash: passwordHash,
344
+ created_at: nowIso(),
345
+ last_login: null,
346
+ is_active: metadata.is_active !== false,
347
+ git_name: metadata.git_name || null,
348
+ git_email: metadata.git_email || null,
349
+ has_completed_onboarding: false,
350
+ role: metadata.role || 'member',
351
+ });
352
+ return {
353
+ id: row.id,
354
+ username: row.username,
355
+ created_at: row.created_at,
356
+ last_login: row.last_login,
357
+ is_active: Boolean(row.is_active),
358
+ role: row.role || 'member',
359
+ };
360
+ },
361
+
323
362
  getUserByUsername: (username) =>
324
363
  store.findWhere('users', (r) => r.username === username && r.is_active) || undefined,
325
364
 
@@ -339,6 +378,7 @@ const userDb = {
339
378
  username: row.username,
340
379
  created_at: row.created_at,
341
380
  last_login: row.last_login,
381
+ role: row.role || null,
342
382
  };
343
383
  },
344
384
 
@@ -350,9 +390,23 @@ const userDb = {
350
390
  username: row.username,
351
391
  created_at: row.created_at,
352
392
  last_login: row.last_login,
393
+ role: row.role || null,
353
394
  };
354
395
  },
355
396
 
397
+ updateUser: (userId, patch = {}) => {
398
+ const allowed = {};
399
+ if (typeof patch.username === 'string' && patch.username.trim()) allowed.username = patch.username.trim();
400
+ if (typeof patch.git_name === 'string') allowed.git_name = patch.git_name;
401
+ if (typeof patch.git_email === 'string') allowed.git_email = patch.git_email;
402
+ if (typeof patch.role === 'string') allowed.role = patch.role;
403
+ if (typeof patch.is_active === 'boolean') allowed.is_active = patch.is_active;
404
+ store.updateWhere('users', (r) => r.id === userId, allowed);
405
+ return userDb.listUsers().find((user) => user.id === userId) || null;
406
+ },
407
+
408
+ setUserActive: (userId, isActive) => userDb.updateUser(userId, { is_active: Boolean(isActive) }),
409
+
356
410
  updateGitConfig: (userId, gitName, gitEmail) => {
357
411
  store.updateWhere('users', (r) => r.id === userId, { git_name: gitName, git_email: gitEmail });
358
412
  },
@@ -1,17 +1,27 @@
1
1
  import express from 'express';
2
2
 
3
3
  import {
4
+ checkRemoteAccessHealth,
5
+ createAdminUser,
4
6
  createEvaluationRun,
5
7
  createEvaluationSuite,
8
+ createProjectCollaborator,
6
9
  createSecret,
7
10
  createSecurityAuditRun,
8
11
  createTeamMember,
12
+ detectTailscaleStatus,
13
+ exportAuditLog,
14
+ getAuditLog,
9
15
  getPlatformizationState,
16
+ getRemoteAccessState,
10
17
  listSecrets,
11
18
  materializeScopedEnv,
12
19
  recordUsageEvent,
20
+ saveRemoteAccessConfig,
13
21
  summarizeUsageEvents,
22
+ updateAdminUser,
14
23
  updateMarketplacePluginHealth,
24
+ updateProjectCollaborator,
15
25
  updateTeamMember,
16
26
  upsertMarketplacePlugin,
17
27
  } from '../services/platformization.js';
@@ -56,6 +66,48 @@ router.patch('/team/members/:id', (req, res) => {
56
66
  res.json({ success: true, member });
57
67
  });
58
68
 
69
+ router.get('/admin/users', (_req, res) => {
70
+ res.json({ success: true, users: getPlatformizationState().adminUsers });
71
+ });
72
+
73
+ router.post('/admin/users', async (req, res) => {
74
+ try {
75
+ res.status(201).json({ success: true, user: await createAdminUser(req.body || {}, userId(req)) });
76
+ } catch (error) {
77
+ handleError(res, error);
78
+ }
79
+ });
80
+
81
+ router.patch('/admin/users/:id', (req, res) => {
82
+ const user = updateAdminUser(req.params.id, req.body || {}, userId(req));
83
+ if (!user) {
84
+ res.status(404).json({ success: false, error: 'Admin user not found.' });
85
+ return;
86
+ }
87
+ res.json({ success: true, user });
88
+ });
89
+
90
+ router.get('/project-collaborators', (_req, res) => {
91
+ res.json({ success: true, collaborators: getPlatformizationState().projectCollaborators });
92
+ });
93
+
94
+ router.post('/project-collaborators', (req, res) => {
95
+ try {
96
+ res.status(201).json({ success: true, collaborator: createProjectCollaborator(req.body || {}, userId(req)) });
97
+ } catch (error) {
98
+ handleError(res, error);
99
+ }
100
+ });
101
+
102
+ router.patch('/project-collaborators/:id', (req, res) => {
103
+ const collaborator = updateProjectCollaborator(req.params.id, req.body || {}, userId(req));
104
+ if (!collaborator) {
105
+ res.status(404).json({ success: false, error: 'Project collaborator not found.' });
106
+ return;
107
+ }
108
+ res.json({ success: true, collaborator });
109
+ });
110
+
59
111
  router.get('/secrets', (_req, res) => {
60
112
  res.json({ success: true, secrets: listSecrets() });
61
113
  });
@@ -122,8 +174,39 @@ router.post('/security/audit-runs', (req, res) => {
122
174
  res.status(201).json({ success: true, run: createSecurityAuditRun(req.body || {}, userId(req)) });
123
175
  });
124
176
 
125
- router.get('/audit-log', (_req, res) => {
126
- res.json({ success: true, auditLog: getPlatformizationState().auditLog });
177
+ router.get('/remote-access', (_req, res) => {
178
+ res.json({ success: true, remoteAccess: getRemoteAccessState() });
179
+ });
180
+
181
+ router.post('/remote-access/configs', (req, res) => {
182
+ try {
183
+ res.status(201).json({ success: true, config: saveRemoteAccessConfig(req.body || {}, userId(req)) });
184
+ } catch (error) {
185
+ handleError(res, error);
186
+ }
187
+ });
188
+
189
+ router.get('/remote-access/tailscale', async (_req, res) => {
190
+ res.json({ success: true, tailscale: await detectTailscaleStatus() });
191
+ });
192
+
193
+ router.post('/remote-access/health', async (req, res) => {
194
+ try {
195
+ res.json({ success: true, health: await checkRemoteAccessHealth(req.body || {}, userId(req)) });
196
+ } catch (error) {
197
+ handleError(res, error);
198
+ }
199
+ });
200
+
201
+ router.get('/audit-log', (req, res) => {
202
+ res.json({ success: true, auditLog: getAuditLog(req.query || {}) });
203
+ });
204
+
205
+ router.get('/audit-log/export', (req, res) => {
206
+ const format = req.query.format === 'csv' ? 'csv' : 'json';
207
+ const body = exportAuditLog(format, req.query || {});
208
+ res.setHeader('Content-Type', format === 'csv' ? 'text/csv; charset=utf-8' : 'application/json; charset=utf-8');
209
+ res.send(body);
127
210
  });
128
211
 
129
212
  export default router;
@@ -1,8 +1,14 @@
1
1
  import crypto from 'node:crypto';
2
+ import os from 'node:os';
3
+ import { execFile } from 'node:child_process';
4
+ import { promisify } from 'node:util';
2
5
 
3
- import { appConfigDb } from '../database/db.js';
6
+ import bcrypt from 'bcryptjs';
7
+
8
+ import { appConfigDb, userDb } from '../database/db.js';
4
9
 
5
10
  const CONFIG_KEY = 'platformization';
11
+ const execFileAsync = promisify(execFile);
6
12
 
7
13
  export const TEAM_ROLES = {
8
14
  owner: [
@@ -31,6 +37,23 @@ export const TEAM_ROLES = {
31
37
  'eval:run',
32
38
  'usage:view',
33
39
  ],
40
+ project_partner: [
41
+ 'project:write',
42
+ 'run:create',
43
+ 'run:approve',
44
+ 'review:manage',
45
+ 'usage:view',
46
+ ],
47
+ project_worker: [
48
+ 'project:write',
49
+ 'run:create',
50
+ 'review:update',
51
+ ],
52
+ project_reviewer: [
53
+ 'project:read',
54
+ 'review:manage',
55
+ 'usage:view',
56
+ ],
34
57
  viewer: [
35
58
  'project:read',
36
59
  'usage:view',
@@ -61,6 +84,8 @@ function emptyStore() {
61
84
  evaluationRuns: [],
62
85
  usageEvents: [],
63
86
  securityAuditRuns: [],
87
+ projectCollaborators: [],
88
+ remoteAccessConfigs: [],
64
89
  auditLog: [],
65
90
  };
66
91
  }
@@ -78,6 +103,8 @@ function readStore() {
78
103
  evaluationRuns: Array.isArray(parsed.evaluationRuns) ? parsed.evaluationRuns : [],
79
104
  usageEvents: Array.isArray(parsed.usageEvents) ? parsed.usageEvents : [],
80
105
  securityAuditRuns: Array.isArray(parsed.securityAuditRuns) ? parsed.securityAuditRuns : [],
106
+ projectCollaborators: Array.isArray(parsed.projectCollaborators) ? parsed.projectCollaborators : [],
107
+ remoteAccessConfigs: Array.isArray(parsed.remoteAccessConfigs) ? parsed.remoteAccessConfigs : [],
81
108
  auditLog: Array.isArray(parsed.auditLog) ? parsed.auditLog : [],
82
109
  };
83
110
  } catch {
@@ -179,6 +206,9 @@ export function getPlatformizationState() {
179
206
  evaluationRuns: store.evaluationRuns,
180
207
  usageSummary: summarizeUsageEvents(store.usageEvents),
181
208
  securityAuditRuns: store.securityAuditRuns,
209
+ adminUsers: listAdminUsers(),
210
+ projectCollaborators: store.projectCollaborators,
211
+ remoteAccessConfigs: store.remoteAccessConfigs,
182
212
  auditLog: store.auditLog,
183
213
  };
184
214
  }
@@ -226,6 +256,151 @@ export function updateTeamMember(memberId, patch = {}, actorId = null) {
226
256
  return updated;
227
257
  }
228
258
 
259
+ export function listAdminUsers() {
260
+ return userDb.listUsers().map((user) => ({
261
+ id: user.id,
262
+ username: user.username,
263
+ role: user.role || 'member',
264
+ status: user.is_active ? 'active' : 'disabled',
265
+ isActive: Boolean(user.is_active),
266
+ createdAt: user.created_at,
267
+ lastLogin: user.last_login,
268
+ }));
269
+ }
270
+
271
+ export async function createAdminUser(input = {}, actorId = null) {
272
+ const username = compact(input.username || input.email || '');
273
+ const password = String(input.password || '');
274
+ if (!username || password.length < 6) {
275
+ throw new Error('Admin user creation requires a username and a password with at least 6 characters.');
276
+ }
277
+
278
+ const role = normalizeRole(input.role || 'member');
279
+ const passwordHash = await bcrypt.hash(password, 12);
280
+ const user = userDb.createManagedUser(username, passwordHash, {
281
+ role,
282
+ is_active: input.status !== 'disabled',
283
+ });
284
+
285
+ const store = readStore();
286
+ const member = {
287
+ id: crypto.randomUUID(),
288
+ userId: user.id,
289
+ email: input.email || username,
290
+ displayName: compact(input.displayName || username, 80),
291
+ role,
292
+ projectScopes: Array.isArray(input.projectScopes) ? input.projectScopes : [],
293
+ status: input.status || 'active',
294
+ createdAt: nowIso(),
295
+ updatedAt: nowIso(),
296
+ permissions: TEAM_ROLES[role],
297
+ };
298
+ store.teamMembers.unshift(member);
299
+ addAudit(store, 'admin.user.created', actorId, { userId: user.id, username, role });
300
+ writeStore(store);
301
+ return {
302
+ ...user,
303
+ status: member.status,
304
+ permissions: member.permissions,
305
+ };
306
+ }
307
+
308
+ export function updateAdminUser(userId, patch = {}, actorId = null) {
309
+ const numericUserId = Number(userId);
310
+ const role = patch.role ? normalizeRole(patch.role) : undefined;
311
+ const isActive = patch.status === 'disabled' ? false : patch.status === 'active' ? true : undefined;
312
+ const user = userDb.updateUser(numericUserId, {
313
+ username: patch.username,
314
+ role,
315
+ is_active: isActive,
316
+ });
317
+ if (!user) return null;
318
+
319
+ const store = readStore();
320
+ store.teamMembers = store.teamMembers.map((member) => {
321
+ if (member.userId !== numericUserId) return member;
322
+ const nextRole = role || member.role;
323
+ const nextStatus = patch.status || member.status;
324
+ return {
325
+ ...member,
326
+ role: nextRole,
327
+ status: nextStatus,
328
+ permissions: TEAM_ROLES[nextRole] || TEAM_ROLES.viewer,
329
+ updatedAt: nowIso(),
330
+ };
331
+ });
332
+ addAudit(store, 'admin.user.updated', actorId, { userId: numericUserId, role: role || user.role, status: patch.status });
333
+ writeStore(store);
334
+ return {
335
+ ...user,
336
+ role: role || user.role || 'member',
337
+ status: user.is_active ? 'active' : 'disabled',
338
+ };
339
+ }
340
+
341
+ export function createProjectCollaborator(input = {}, actorId = null) {
342
+ const projectName = compact(input.projectName || input.project || '');
343
+ const projectPath = input.projectPath || null;
344
+ const userRef = compact(input.userRef || input.email || input.username || '');
345
+ if (!projectName || !userRef) {
346
+ throw new Error('Project collaborator requires a project name and user reference.');
347
+ }
348
+
349
+ const role = ['partner', 'worker', 'reviewer', 'viewer'].includes(input.role) ? input.role : 'worker';
350
+ const capabilities = {
351
+ chatAgents: input.capabilities?.chatAgents !== false,
352
+ viewFiles: true,
353
+ editFiles: role === 'partner' || role === 'worker',
354
+ useShell: role === 'partner',
355
+ approveActions: role === 'partner' || role === 'reviewer',
356
+ manageSecrets: role === 'partner',
357
+ manageProjectSettings: role === 'partner',
358
+ };
359
+ const collaborator = {
360
+ id: crypto.randomUUID(),
361
+ projectName,
362
+ projectPath,
363
+ userRef,
364
+ role,
365
+ capabilities: {
366
+ ...capabilities,
367
+ ...(input.capabilities && typeof input.capabilities === 'object' ? input.capabilities : {}),
368
+ },
369
+ status: input.status || 'active',
370
+ createdAt: nowIso(),
371
+ updatedAt: nowIso(),
372
+ };
373
+ const store = readStore();
374
+ store.projectCollaborators.unshift(collaborator);
375
+ addAudit(store, 'project.collaborator.created', actorId, { collaboratorId: collaborator.id, projectName, userRef, role });
376
+ writeStore(store);
377
+ return collaborator;
378
+ }
379
+
380
+ export function updateProjectCollaborator(collaboratorId, patch = {}, actorId = null) {
381
+ const store = readStore();
382
+ let updated = null;
383
+ store.projectCollaborators = store.projectCollaborators.map((collaborator) => {
384
+ if (collaborator.id !== collaboratorId) return collaborator;
385
+ updated = {
386
+ ...collaborator,
387
+ ...patch,
388
+ id: collaborator.id,
389
+ capabilities: {
390
+ ...collaborator.capabilities,
391
+ ...(patch.capabilities && typeof patch.capabilities === 'object' ? patch.capabilities : {}),
392
+ },
393
+ updatedAt: nowIso(),
394
+ };
395
+ return updated;
396
+ });
397
+ if (updated) {
398
+ addAudit(store, 'project.collaborator.updated', actorId, { collaboratorId, role: updated.role, status: updated.status });
399
+ writeStore(store);
400
+ }
401
+ return updated;
402
+ }
403
+
229
404
  export function createSecret(input = {}, actorId = null) {
230
405
  const name = compact(input.name || input.envName || '');
231
406
  const value = input.value;
@@ -458,3 +633,178 @@ export function createSecurityAuditRun(input = {}, actorId = null) {
458
633
  writeStore(store);
459
634
  return run;
460
635
  }
636
+
637
+ export function getAuditLog(filters = {}) {
638
+ const store = readStore();
639
+ let entries = store.auditLog;
640
+ if (filters.userId) {
641
+ entries = entries.filter((entry) => String(entry.actorId) === String(filters.userId));
642
+ }
643
+ if (filters.eventType) {
644
+ entries = entries.filter((entry) => entry.action === filters.eventType || entry.action.includes(filters.eventType));
645
+ }
646
+ if (filters.projectName) {
647
+ entries = entries.filter((entry) => entry.details?.projectName === filters.projectName);
648
+ }
649
+ if (filters.severity) {
650
+ entries = entries.filter((entry) => entry.details?.severity === filters.severity);
651
+ }
652
+ return entries.slice(0, Number(filters.limit || 200));
653
+ }
654
+
655
+ export function exportAuditLog(format = 'json', filters = {}) {
656
+ const entries = getAuditLog(filters);
657
+ if (format === 'csv') {
658
+ const header = ['id', 'createdAt', 'actorId', 'action', 'details'];
659
+ const lines = entries.map((entry) => header.map((field) => {
660
+ const value = field === 'details' ? JSON.stringify(entry.details || {}) : entry[field];
661
+ return `"${String(value ?? '').replace(/"/g, '""')}"`;
662
+ }).join(','));
663
+ return [header.join(','), ...lines].join('\n');
664
+ }
665
+ return JSON.stringify(entries, null, 2);
666
+ }
667
+
668
+ function normalizeAccessMode(mode) {
669
+ return ['lan', 'tailscale', 'cloudflare_tunnel', 'custom_domain'].includes(mode) ? mode : 'lan';
670
+ }
671
+
672
+ function normalizePublicUrl(value) {
673
+ const raw = typeof value === 'string' ? value.trim() : '';
674
+ if (!raw) return null;
675
+ const url = new URL(raw);
676
+ if (!['http:', 'https:'].includes(url.protocol)) {
677
+ throw new Error('Remote access URL must use http or https.');
678
+ }
679
+ url.pathname = url.pathname.replace(/\/+$/, '');
680
+ url.search = '';
681
+ url.hash = '';
682
+ return url.toString().replace(/\/$/, '');
683
+ }
684
+
685
+ export function saveRemoteAccessConfig(input = {}, actorId = null) {
686
+ const mode = normalizeAccessMode(input.mode);
687
+ const id = input.id || mode;
688
+ const config = {
689
+ id,
690
+ mode,
691
+ label: compact(input.label || mode.replace(/_/g, ' '), 80),
692
+ url: input.url ? normalizePublicUrl(input.url) : null,
693
+ targetPort: Number(input.targetPort || process.env.SERVER_PORT || 3001),
694
+ public: mode === 'cloudflare_tunnel' || mode === 'custom_domain',
695
+ tlsRequired: mode === 'cloudflare_tunnel' || mode === 'custom_domain',
696
+ privateOnly: mode === 'tailscale' || mode === 'lan',
697
+ status: input.status || 'configured',
698
+ notes: compact(input.notes || '', 240),
699
+ updatedAt: nowIso(),
700
+ createdAt: input.createdAt || nowIso(),
701
+ lastHealth: input.lastHealth || null,
702
+ };
703
+ const store = readStore();
704
+ store.remoteAccessConfigs = [config, ...store.remoteAccessConfigs.filter((item) => item.id !== id)];
705
+ addAudit(store, 'remote.access.configured', actorId, { mode, url: config.url, public: config.public });
706
+ writeStore(store);
707
+ return config;
708
+ }
709
+
710
+ export function getRemoteAccessState() {
711
+ const store = readStore();
712
+ return {
713
+ host: os.hostname(),
714
+ platform: os.platform(),
715
+ localUrl: `http://127.0.0.1:${process.env.SERVER_PORT || 3001}`,
716
+ configs: store.remoteAccessConfigs,
717
+ recommendations: [
718
+ {
719
+ mode: 'tailscale',
720
+ label: 'Tailscale private network',
721
+ recommendedWhen: 'No stable domain, no public IP, private team access.',
722
+ },
723
+ {
724
+ mode: 'cloudflare_tunnel',
725
+ label: 'Cloudflare Tunnel',
726
+ recommendedWhen: 'Stable public HTTPS URL without opening inbound ports.',
727
+ },
728
+ {
729
+ mode: 'custom_domain',
730
+ label: 'Custom domain / reverse proxy',
731
+ recommendedWhen: 'Existing domain, reverse proxy, and TLS termination.',
732
+ },
733
+ ],
734
+ };
735
+ }
736
+
737
+ export async function detectTailscaleStatus() {
738
+ try {
739
+ const { stdout } = await execFileAsync('tailscale', ['status', '--json'], { timeout: 5000 });
740
+ const status = JSON.parse(stdout || '{}');
741
+ const self = status.Self || {};
742
+ const tailscaleIps = Array.isArray(self.TailscaleIPs) ? self.TailscaleIPs : [];
743
+ return {
744
+ installed: true,
745
+ loggedIn: Boolean(self.ID || self.DNSName || tailscaleIps.length),
746
+ backendState: status.BackendState || null,
747
+ deviceName: self.HostName || os.hostname(),
748
+ magicDnsName: self.DNSName || null,
749
+ tailscaleIp: tailscaleIps[0] || null,
750
+ pixcodeUrl: tailscaleIps[0] ? `http://${tailscaleIps[0]}:${process.env.SERVER_PORT || 3001}` : null,
751
+ checkedAt: nowIso(),
752
+ message: tailscaleIps[0] ? 'Tailscale is ready for private Pixcode access.' : 'Tailscale CLI is installed but no device IP was detected.',
753
+ };
754
+ } catch (error) {
755
+ return {
756
+ installed: false,
757
+ loggedIn: false,
758
+ backendState: 'missing',
759
+ deviceName: os.hostname(),
760
+ magicDnsName: null,
761
+ tailscaleIp: null,
762
+ pixcodeUrl: null,
763
+ checkedAt: nowIso(),
764
+ message: error?.code === 'ENOENT' ? 'Tailscale CLI is not installed.' : (error?.message || 'Tailscale status could not be read.'),
765
+ };
766
+ }
767
+ }
768
+
769
+ export async function checkRemoteAccessHealth(input = {}, actorId = null) {
770
+ const url = normalizePublicUrl(input.url || input.remoteUrl || '');
771
+ const checkedAt = nowIso();
772
+ if (!url) {
773
+ throw new Error('Remote access health check requires a URL.');
774
+ }
775
+ const parsed = new URL(url);
776
+ const controller = new AbortController();
777
+ const timeout = setTimeout(() => controller.abort(), Number(input.timeoutMs || 5000));
778
+ try {
779
+ const response = await fetch(`${url}/api/auth/status`, { signal: controller.signal });
780
+ const health = {
781
+ url,
782
+ reachable: response.ok,
783
+ checkedAt,
784
+ statusCode: response.status,
785
+ https: parsed.protocol === 'https:',
786
+ websocketExpected: true,
787
+ message: response.ok ? 'Pixcode auth endpoint is reachable.' : `Pixcode returned HTTP ${response.status}.`,
788
+ };
789
+ const store = readStore();
790
+ addAudit(store, 'remote.access.health_checked', actorId, { url, reachable: health.reachable, https: health.https });
791
+ writeStore(store);
792
+ return health;
793
+ } catch (error) {
794
+ const health = {
795
+ url,
796
+ reachable: false,
797
+ checkedAt,
798
+ statusCode: null,
799
+ https: parsed.protocol === 'https:',
800
+ websocketExpected: true,
801
+ message: error?.name === 'AbortError' ? 'Health check timed out.' : (error?.message || 'Remote access URL is unreachable.'),
802
+ };
803
+ const store = readStore();
804
+ addAudit(store, 'remote.access.health_checked', actorId, { url, reachable: false, https: health.https });
805
+ writeStore(store);
806
+ return health;
807
+ } finally {
808
+ clearTimeout(timeout);
809
+ }
810
+ }