@livedesk/client 0.1.241 → 0.1.242
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/bin/livedesk-client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { randomBytes } from 'node:crypto';
|
|
4
4
|
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statfsSync, statSync, writeFileSync } from 'node:fs';
|
|
@@ -143,9 +143,16 @@ function publishWindowsOwnedAgentRecords(records, {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
export function requestClientRuntimeShutdown(signal = 'SIGTERM') {
|
|
147
|
-
disposeAgentTerminationHandlers.requestTermination(signal);
|
|
148
|
-
}
|
|
146
|
+
export function requestClientRuntimeShutdown(signal = 'SIGTERM') {
|
|
147
|
+
disposeAgentTerminationHandlers.requestTermination(signal);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const HUB_SELF_AGENT_SHUTDOWN_MESSAGE = 'livedesk.self-agent.shutdown';
|
|
151
|
+
const HUB_SELF_AGENT_READY_MESSAGE = 'livedesk.self-agent.ready';
|
|
152
|
+
|
|
153
|
+
function isHubSelfAgentRuntime() {
|
|
154
|
+
return isTruthy(process.env.LIVEDESK_HUB_SELF_AGENT);
|
|
155
|
+
}
|
|
149
156
|
|
|
150
157
|
function requestActiveAgentStop(signal = 'SIGTERM') {
|
|
151
158
|
const child = activeAgentProcess;
|
|
@@ -4111,7 +4118,7 @@ export async function waitForManagerFromSupabase(supabase, options = {}) {
|
|
|
4111
4118
|
}
|
|
4112
4119
|
}
|
|
4113
4120
|
|
|
4114
|
-
async function prepareLoginConnection(parsed, existingConnectionPage = null, getSupabaseClient = createSupabaseClient) {
|
|
4121
|
+
async function prepareLoginConnection(parsed, existingConnectionPage = null, getSupabaseClient = createSupabaseClient) {
|
|
4115
4122
|
if (parsed.logout) {
|
|
4116
4123
|
clearSavedSession();
|
|
4117
4124
|
}
|
|
@@ -4375,7 +4382,46 @@ async function prepareLoginConnection(parsed, existingConnectionPage = null, get
|
|
|
4375
4382
|
rediscoverOnDisconnect: shouldLogin,
|
|
4376
4383
|
rediscoverOnInvalidPair: shouldLogin
|
|
4377
4384
|
};
|
|
4378
|
-
}
|
|
4385
|
+
}
|
|
4386
|
+
|
|
4387
|
+
export function prepareHubSelfAgentConnection(parsed) {
|
|
4388
|
+
const manager = String(parsed?.manager || '').trim();
|
|
4389
|
+
const pair = String(parsed?.pair || '').trim();
|
|
4390
|
+
const deviceId = String(parsed?.deviceId || '').trim();
|
|
4391
|
+
const endpoint = parseManagerEndpoint(manager);
|
|
4392
|
+
const loopbackHosts = new Set(['127.0.0.1', 'localhost', '::1']);
|
|
4393
|
+
if (!endpoint || !loopbackHosts.has(endpoint.host.toLowerCase())) {
|
|
4394
|
+
throw new Error('Hub Self Agent must connect to this Hub through a loopback endpoint.');
|
|
4395
|
+
}
|
|
4396
|
+
if (!pair) throw new Error('Hub Self Agent requires the current Hub pair token.');
|
|
4397
|
+
if (!deviceId) throw new Error('Hub Self Agent requires the Hub device identity.');
|
|
4398
|
+
|
|
4399
|
+
let forwarded = Array.isArray(parsed.forwarded) ? [...parsed.forwarded] : [];
|
|
4400
|
+
forwarded = upsertForwardedOption(forwarded, '--manager', manager);
|
|
4401
|
+
forwarded = upsertForwardedOption(forwarded, '--device-id', deviceId);
|
|
4402
|
+
const slot = normalizeSlotNumber(parsed.slot);
|
|
4403
|
+
if (slot) forwarded = upsertForwardedOption(forwarded, '--slot', slot);
|
|
4404
|
+
return {
|
|
4405
|
+
...parsed,
|
|
4406
|
+
engine: 'fast',
|
|
4407
|
+
manager,
|
|
4408
|
+
pair,
|
|
4409
|
+
deviceId,
|
|
4410
|
+
slot,
|
|
4411
|
+
transport: 'tcp',
|
|
4412
|
+
relay: '',
|
|
4413
|
+
relayExplicit: false,
|
|
4414
|
+
requireFast: true,
|
|
4415
|
+
connectionPage: null,
|
|
4416
|
+
forwarded,
|
|
4417
|
+
connectionTransport: 'direct-tcp',
|
|
4418
|
+
directReachable: true,
|
|
4419
|
+
directProbeSkipReason: '',
|
|
4420
|
+
discoverySource: 'hub-self-agent',
|
|
4421
|
+
rediscoverOnDisconnect: false,
|
|
4422
|
+
rediscoverOnInvalidPair: false
|
|
4423
|
+
};
|
|
4424
|
+
}
|
|
4379
4425
|
|
|
4380
4426
|
function getFastRuntime() {
|
|
4381
4427
|
const platform = os.platform();
|
|
@@ -4858,9 +4904,10 @@ function spawnAgent(command, args, env = process.env, onStart = null) {
|
|
|
4858
4904
|
windowsHide: true
|
|
4859
4905
|
});
|
|
4860
4906
|
child.livedeskOwnsProcessGroup = ownsProcessGroup;
|
|
4861
|
-
child.livedeskWindowsTreeTracker = createWindowsProcessTreeTracker(child, {
|
|
4862
|
-
spawnedAtMs: agentSpawnedAtMs,
|
|
4863
|
-
|
|
4907
|
+
child.livedeskWindowsTreeTracker = createWindowsProcessTreeTracker(child, {
|
|
4908
|
+
spawnedAtMs: agentSpawnedAtMs,
|
|
4909
|
+
ownerPid: WINDOWS_PROCESS_MANIFEST_OWNER?.pid || process.pid,
|
|
4910
|
+
publishTrackedRecords: WINDOWS_PROCESS_MANIFEST_OWNER
|
|
4864
4911
|
? publishWindowsOwnedAgentRecords
|
|
4865
4912
|
: null
|
|
4866
4913
|
});
|
|
@@ -4959,8 +5006,9 @@ export function requiresFastTransport(prepared = {}) {
|
|
|
4959
5006
|
|| prepared.relayExplicit === true;
|
|
4960
5007
|
}
|
|
4961
5008
|
|
|
4962
|
-
export async function runClientRuntime(argv = process.argv.slice(2), runtimeOptions = {}) {
|
|
4963
|
-
|
|
5009
|
+
export async function runClientRuntime(argv = process.argv.slice(2), runtimeOptions = {}) {
|
|
5010
|
+
const hubSelfAgent = isHubSelfAgentRuntime();
|
|
5011
|
+
if (!hubSelfAgent) startNetworkChangeMonitor();
|
|
4964
5012
|
if (isTruthy(process.env.LIVEDESK_DESKTOP_HOST)) {
|
|
4965
5013
|
unregisterWindowsStartup();
|
|
4966
5014
|
}
|
|
@@ -4977,9 +5025,11 @@ export async function runClientRuntime(argv = process.argv.slice(2), runtimeOpti
|
|
|
4977
5025
|
if (parsed.updateWaitPid) {
|
|
4978
5026
|
await waitForProcessExit(parsed.updateWaitPid);
|
|
4979
5027
|
}
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
5028
|
+
if (!hubSelfAgent) {
|
|
5029
|
+
writeClientUpdateRuntimeStage('launcher-started', {
|
|
5030
|
+
restartVerified: false
|
|
5031
|
+
});
|
|
5032
|
+
}
|
|
4983
5033
|
if (parsed.help) {
|
|
4984
5034
|
printHelp();
|
|
4985
5035
|
return;
|
|
@@ -5015,7 +5065,7 @@ export async function runClientRuntime(argv = process.argv.slice(2), runtimeOpti
|
|
|
5015
5065
|
return supabaseClientPromise;
|
|
5016
5066
|
};
|
|
5017
5067
|
let connectionPage = null;
|
|
5018
|
-
if (isTruthy(process.env.LIVEDESK_UNIFIED_RUNTIME)) {
|
|
5068
|
+
if (isTruthy(process.env.LIVEDESK_UNIFIED_RUNTIME) && !hubSelfAgent) {
|
|
5019
5069
|
let resolveStarted;
|
|
5020
5070
|
let rejectStarted;
|
|
5021
5071
|
const started = new Promise((resolve, reject) => {
|
|
@@ -5052,7 +5102,9 @@ export async function runClientRuntime(argv = process.argv.slice(2), runtimeOpti
|
|
|
5052
5102
|
if (savedSlot) {
|
|
5053
5103
|
parsed.slot = savedSlot;
|
|
5054
5104
|
}
|
|
5055
|
-
const prepared =
|
|
5105
|
+
const prepared = hubSelfAgent
|
|
5106
|
+
? prepareHubSelfAgentConnection(parsed)
|
|
5107
|
+
: await prepareLoginConnection(parsed, connectionPage, getSupabaseClient);
|
|
5056
5108
|
connectionPage = prepared.connectionPage || connectionPage;
|
|
5057
5109
|
prepared.connectionPage?.update({
|
|
5058
5110
|
manager: prepared.manager,
|
|
@@ -5106,8 +5158,14 @@ export async function runClientRuntime(argv = process.argv.slice(2), runtimeOpti
|
|
|
5106
5158
|
runtimeId: fastRuntime?.rid || '',
|
|
5107
5159
|
state: 'launching'
|
|
5108
5160
|
});
|
|
5109
|
-
result = await spawnAgent(fastLaunch.command, launchArgs, buildFastEnvironment(prepared), child => {
|
|
5110
|
-
|
|
5161
|
+
result = await spawnAgent(fastLaunch.command, launchArgs, buildFastEnvironment(prepared), child => {
|
|
5162
|
+
if (hubSelfAgent && typeof process.send === 'function') {
|
|
5163
|
+
process.send({
|
|
5164
|
+
type: HUB_SELF_AGENT_READY_MESSAGE,
|
|
5165
|
+
agentPid: Number(child.pid || 0)
|
|
5166
|
+
});
|
|
5167
|
+
}
|
|
5168
|
+
updateAgentDashboard({
|
|
5111
5169
|
engine: 'fast',
|
|
5112
5170
|
command: fastLaunch.command,
|
|
5113
5171
|
args: redactAgentArgs(launchArgs),
|
|
@@ -5254,8 +5312,14 @@ export async function runClientRuntime(argv = process.argv.slice(2), runtimeOpti
|
|
|
5254
5312
|
}
|
|
5255
5313
|
}
|
|
5256
5314
|
|
|
5257
|
-
if (process.argv[1] && resolve(process.argv[1]) === resolve(fileURLToPath(import.meta.url))) {
|
|
5258
|
-
|
|
5315
|
+
if (process.argv[1] && resolve(process.argv[1]) === resolve(fileURLToPath(import.meta.url))) {
|
|
5316
|
+
if (isHubSelfAgentRuntime()) {
|
|
5317
|
+
process.on('message', message => {
|
|
5318
|
+
if (message?.type !== HUB_SELF_AGENT_SHUTDOWN_MESSAGE) return;
|
|
5319
|
+
requestClientRuntimeShutdown(message?.signal === 'SIGINT' ? 'SIGINT' : 'SIGTERM');
|
|
5320
|
+
});
|
|
5321
|
+
}
|
|
5322
|
+
runClientRuntime().catch(error => {
|
|
5259
5323
|
console.error(error?.message || error);
|
|
5260
5324
|
process.exit(1);
|
|
5261
5325
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livedesk/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.242",
|
|
4
4
|
"description": "LiveDesk local remote client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"ws": "^8.18.3"
|
|
43
43
|
},
|
|
44
44
|
"optionalDependencies": {
|
|
45
|
-
"@livedesk/fast-linux-x64": "0.1.440",
|
|
46
|
-
"@livedesk/fast-osx-arm64": "0.1.440",
|
|
47
|
-
"@livedesk/fast-osx-x64": "0.1.440",
|
|
48
|
-
"@livedesk/fast-win-x64": "0.1.440"
|
|
45
|
+
"@livedesk/fast-linux-x64": "0.1.440",
|
|
46
|
+
"@livedesk/fast-osx-arm64": "0.1.440",
|
|
47
|
+
"@livedesk/fast-osx-x64": "0.1.440",
|
|
48
|
+
"@livedesk/fast-win-x64": "0.1.440"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|