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

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 +84 -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()) {
@@ -118,6 +183,9 @@ function postJSON(urlString, payload, config) {
118
183
  url,
119
184
  {
120
185
  method: 'POST',
186
+ ...(url.protocol === 'https:' && config.tlsInsecureSkipVerify
187
+ ? { agent: new https.Agent({ rejectUnauthorized: false }) }
188
+ : {}),
121
189
  headers: {
122
190
  'Content-Type': 'application/json',
123
191
  'Content-Length': Buffer.byteLength(body),
@@ -174,7 +242,10 @@ async function reportLifecycle(event, { port, version, seq = 1 } = {}) {
174
242
 
175
243
  module.exports = {
176
244
  buildLifecyclePayload,
245
+ DEFAULT_REGISTRY_API_BASE_URL,
177
246
  getRegistryConfig,
247
+ readRegistrySessionIdentity,
248
+ readRegistryConfigFromDaemonConfig,
178
249
  registryStatePaths,
179
250
  ensureDaemonInstanceId,
180
251
  readRunState,
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-beta4",
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-beta4",
43
+ "@agent-webui/ai-desk-daemon-darwin-x64": "1.0.61-beta4",
44
+ "@agent-webui/ai-desk-daemon-linux-arm64": "1.0.61-beta4",
45
+ "@agent-webui/ai-desk-daemon-linux-x64": "1.0.61-beta4",
46
+ "@agent-webui/ai-desk-daemon-win32-x64": "1.0.61-beta4",
47
+ "@agent-webui/ai-desk-python-darwin-arm64": "1.0.61-beta4",
48
+ "@agent-webui/ai-desk-python-darwin-x64": "1.0.61-beta4",
49
+ "@agent-webui/ai-desk-python-linux-arm64": "1.0.61-beta4",
50
+ "@agent-webui/ai-desk-python-linux-x64": "1.0.61-beta4",
51
+ "@agent-webui/ai-desk-python-win32-x64": "1.0.61-beta4"
52
52
  },
53
53
  "repository": {
54
54
  "type": "git",