@agent-webui/ai-desk-daemon 1.0.61-beta1 → 1.0.61-beta5

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 (2) hide show
  1. package/lib/daemon-registry.js +102 -13
  2. package/package.json +11 -11
@@ -5,8 +5,12 @@ const http = require('http');
5
5
  const https = require('https');
6
6
  const crypto = require('crypto');
7
7
 
8
+ const DEFAULT_REGISTRY_API_BASE_URL = 'https://desk.int.rclabenv.com/';
9
+
8
10
  function trim(value) {
9
- return typeof value === 'string' ? value.trim() : '';
11
+ if (typeof value === 'string') return value.trim();
12
+ if (typeof value === 'number' && Number.isFinite(value)) return String(value);
13
+ return '';
10
14
  }
11
15
 
12
16
  function normalizeApiBaseUrl(value) {
@@ -15,21 +19,82 @@ function normalizeApiBaseUrl(value) {
15
19
  return raw.endsWith('/api/v1') ? raw : `${raw}/api/v1`;
16
20
  }
17
21
 
18
- function getRegistryConfig(env = process.env) {
22
+ function parseTruthyEnv(value) {
23
+ const raw = trim(value).toLowerCase();
24
+ if (!raw) return null;
25
+ return raw === '1' || raw === 'true' || raw === 'yes' || raw === 'on';
26
+ }
27
+
28
+ function readRegistrySessionIdentity(homeDir = os.homedir()) {
29
+ const sessionPath = path.join(homeDir, '.aidesktop', 'session.json');
30
+ try {
31
+ if (!fs.existsSync(sessionPath)) return null;
32
+ const session = JSON.parse(fs.readFileSync(sessionPath, 'utf8'));
33
+ if (!session || typeof session !== 'object') return null;
34
+ const rcAccountId = trim(session.account_id || session.accountId);
35
+ const rcExtensionId = trim(session.extension_id || session.extensionId);
36
+ if (!rcAccountId || !rcExtensionId) return null;
37
+ return { rcAccountId, rcExtensionId };
38
+ } catch {
39
+ return null;
40
+ }
41
+ }
42
+
43
+ function readRegistryConfigFromDaemonConfig(homeDir = os.homedir()) {
44
+ const configPath = path.join(homeDir, '.aidesktop', 'daemon-config.json');
45
+ try {
46
+ if (!fs.existsSync(configPath)) return null;
47
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
48
+ const registry = config && typeof config === 'object' ? config.registry : null;
49
+ if (!registry || typeof registry !== 'object') return null;
50
+ const sessionIdentity = readRegistrySessionIdentity(homeDir);
51
+ const apiBaseUrl = normalizeApiBaseUrl(
52
+ registry.api_base_url || registry.apiBaseUrl || DEFAULT_REGISTRY_API_BASE_URL,
53
+ );
54
+ const rcAccountId = trim(registry.rc_account_id || registry.rcAccountId) ||
55
+ sessionIdentity?.rcAccountId || '';
56
+ const rcExtensionId = trim(registry.rc_extension_id || registry.rcExtensionId) ||
57
+ sessionIdentity?.rcExtensionId || '';
58
+ if (!apiBaseUrl || !rcAccountId || !rcExtensionId) return null;
59
+ return {
60
+ apiBaseUrl,
61
+ rcAccountId,
62
+ rcExtensionId,
63
+ rcUsername: trim(registry.rc_username || registry.rcUsername),
64
+ tlsInsecureSkipVerify: Boolean(registry.tls_insecure_skip_verify || registry.tlsInsecureSkipVerify),
65
+ };
66
+ } catch {
67
+ return null;
68
+ }
69
+ }
70
+
71
+ function getRegistryConfig(env = process.env, homeDir = os.homedir()) {
72
+ const daemonConfig = readRegistryConfigFromDaemonConfig(homeDir);
73
+ const sessionIdentity = readRegistrySessionIdentity(homeDir);
19
74
  const apiBaseUrl = normalizeApiBaseUrl(
20
75
  env.AI_DESK_API_BASE_URL || env.AI_DESK_BACKEND_API_URL || env.AI_DESK_BACKEND_URL,
21
- );
22
- const rcAccountId = trim(env.AI_DESK_RC_ACCOUNT_ID || env.rcAccountId);
23
- const rcExtensionId = trim(env.AI_DESK_RC_EXTENSION_ID || env.rcExtensionId);
24
- if (!apiBaseUrl || !rcAccountId || !rcExtensionId) {
25
- return null;
76
+ ) || daemonConfig?.apiBaseUrl || normalizeApiBaseUrl(DEFAULT_REGISTRY_API_BASE_URL);
77
+ const rcAccountId = trim(env.AI_DESK_RC_ACCOUNT_ID || env.rcAccountId) ||
78
+ daemonConfig?.rcAccountId ||
79
+ sessionIdentity?.rcAccountId ||
80
+ '';
81
+ const rcExtensionId = trim(env.AI_DESK_RC_EXTENSION_ID || env.rcExtensionId) ||
82
+ daemonConfig?.rcExtensionId ||
83
+ sessionIdentity?.rcExtensionId ||
84
+ '';
85
+ if (apiBaseUrl && rcAccountId && rcExtensionId) {
86
+ const tlsEnvValue = parseTruthyEnv(env.AI_DESK_TLS_INSECURE_SKIP_VERIFY);
87
+ return {
88
+ apiBaseUrl,
89
+ rcAccountId,
90
+ rcExtensionId,
91
+ rcUsername: trim(env.AI_DESK_RC_USERNAME || env.rcUsername) || daemonConfig?.rcUsername || '',
92
+ tlsInsecureSkipVerify: tlsEnvValue === null
93
+ ? Boolean(daemonConfig?.tlsInsecureSkipVerify)
94
+ : tlsEnvValue,
95
+ };
26
96
  }
27
- return {
28
- apiBaseUrl,
29
- rcAccountId,
30
- rcExtensionId,
31
- rcUsername: trim(env.AI_DESK_RC_USERNAME || env.rcUsername),
32
- };
97
+ return null;
33
98
  }
34
99
 
35
100
  function registryStatePaths(homeDir = os.homedir()) {
@@ -88,6 +153,20 @@ function listIpAddresses() {
88
153
  return [...new Set(out)];
89
154
  }
90
155
 
156
+ function listMacAddresses() {
157
+ const out = [];
158
+ const interfaces = os.networkInterfaces();
159
+ for (const items of Object.values(interfaces)) {
160
+ for (const item of items || []) {
161
+ const mac = trim(item.mac).toLowerCase();
162
+ if (!item.internal && mac && mac !== '00:00:00:00:00:00') {
163
+ out.push(mac);
164
+ }
165
+ }
166
+ }
167
+ return [...new Set(out)];
168
+ }
169
+
91
170
  function buildLifecyclePayload({
92
171
  event,
93
172
  runId,
@@ -96,16 +175,19 @@ function buildLifecyclePayload({
96
175
  version,
97
176
  daemonInstanceId,
98
177
  }) {
178
+ const macAddresses = listMacAddresses();
99
179
  return {
100
180
  daemonInstanceId,
101
181
  runId,
102
182
  event,
103
183
  seq,
184
+ machineId: macAddresses[0] || daemonInstanceId,
104
185
  hostname: os.hostname(),
105
186
  osUsername: os.userInfo().username,
106
187
  daemonVersion: version,
107
188
  port,
108
189
  ipAddresses: listIpAddresses(),
190
+ macAddresses,
109
191
  };
110
192
  }
111
193
 
@@ -118,6 +200,9 @@ function postJSON(urlString, payload, config) {
118
200
  url,
119
201
  {
120
202
  method: 'POST',
203
+ ...(url.protocol === 'https:' && config.tlsInsecureSkipVerify
204
+ ? { agent: new https.Agent({ rejectUnauthorized: false }) }
205
+ : {}),
121
206
  headers: {
122
207
  'Content-Type': 'application/json',
123
208
  'Content-Length': Buffer.byteLength(body),
@@ -174,10 +259,14 @@ async function reportLifecycle(event, { port, version, seq = 1 } = {}) {
174
259
 
175
260
  module.exports = {
176
261
  buildLifecyclePayload,
262
+ DEFAULT_REGISTRY_API_BASE_URL,
177
263
  getRegistryConfig,
264
+ readRegistrySessionIdentity,
265
+ readRegistryConfigFromDaemonConfig,
178
266
  registryStatePaths,
179
267
  ensureDaemonInstanceId,
180
268
  readRunState,
181
269
  writeRunState,
270
+ listMacAddresses,
182
271
  reportLifecycle,
183
272
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-webui/ai-desk-daemon",
3
- "version": "1.0.61-beta1",
3
+ "version": "1.0.61-beta5",
4
4
  "description": "AI Desk Daemon - CLI tool for managing the AI Desk daemon service",
5
5
  "workspaces": [
6
6
  "packages/*"
@@ -39,16 +39,16 @@
39
39
  "chalk": "^4.1.2"
40
40
  },
41
41
  "optionalDependencies": {
42
- "@agent-webui/ai-desk-daemon-darwin-arm64": "1.0.61-beta1",
43
- "@agent-webui/ai-desk-daemon-darwin-x64": "1.0.61-beta1",
44
- "@agent-webui/ai-desk-daemon-linux-arm64": "1.0.61-beta1",
45
- "@agent-webui/ai-desk-daemon-linux-x64": "1.0.61-beta1",
46
- "@agent-webui/ai-desk-daemon-win32-x64": "1.0.61-beta1",
47
- "@agent-webui/ai-desk-python-darwin-arm64": "1.0.61-beta1",
48
- "@agent-webui/ai-desk-python-darwin-x64": "1.0.61-beta1",
49
- "@agent-webui/ai-desk-python-linux-arm64": "1.0.61-beta1",
50
- "@agent-webui/ai-desk-python-linux-x64": "1.0.61-beta1",
51
- "@agent-webui/ai-desk-python-win32-x64": "1.0.61-beta1"
42
+ "@agent-webui/ai-desk-daemon-darwin-arm64": "1.0.61-beta5",
43
+ "@agent-webui/ai-desk-daemon-darwin-x64": "1.0.61-beta5",
44
+ "@agent-webui/ai-desk-daemon-linux-arm64": "1.0.61-beta5",
45
+ "@agent-webui/ai-desk-daemon-linux-x64": "1.0.61-beta5",
46
+ "@agent-webui/ai-desk-daemon-win32-x64": "1.0.61-beta5",
47
+ "@agent-webui/ai-desk-python-darwin-arm64": "1.0.61-beta5",
48
+ "@agent-webui/ai-desk-python-darwin-x64": "1.0.61-beta5",
49
+ "@agent-webui/ai-desk-python-linux-arm64": "1.0.61-beta5",
50
+ "@agent-webui/ai-desk-python-linux-x64": "1.0.61-beta5",
51
+ "@agent-webui/ai-desk-python-win32-x64": "1.0.61-beta5"
52
52
  },
53
53
  "repository": {
54
54
  "type": "git",