@livedesk/client 0.1.246 → 0.1.247
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 +102 -102
- package/package.json +5 -5
- package/src/runtime/agent-process-lifecycle.js +7 -7
package/bin/livedesk-client.js
CHANGED
|
@@ -143,16 +143,16 @@ function publishWindowsOwnedAgentRecords(records, {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
|
|
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
|
-
}
|
|
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
|
+
}
|
|
156
156
|
|
|
157
157
|
function requestActiveAgentStop(signal = 'SIGTERM') {
|
|
158
158
|
const child = activeAgentProcess;
|
|
@@ -4118,7 +4118,7 @@ export async function waitForManagerFromSupabase(supabase, options = {}) {
|
|
|
4118
4118
|
}
|
|
4119
4119
|
}
|
|
4120
4120
|
|
|
4121
|
-
async function prepareLoginConnection(parsed, existingConnectionPage = null, getSupabaseClient = createSupabaseClient) {
|
|
4121
|
+
async function prepareLoginConnection(parsed, existingConnectionPage = null, getSupabaseClient = createSupabaseClient) {
|
|
4122
4122
|
if (parsed.logout) {
|
|
4123
4123
|
clearSavedSession();
|
|
4124
4124
|
}
|
|
@@ -4382,46 +4382,46 @@ async function prepareLoginConnection(parsed, existingConnectionPage = null, get
|
|
|
4382
4382
|
rediscoverOnDisconnect: shouldLogin,
|
|
4383
4383
|
rediscoverOnInvalidPair: shouldLogin
|
|
4384
4384
|
};
|
|
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
|
-
}
|
|
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
|
+
}
|
|
4425
4425
|
|
|
4426
4426
|
function getFastRuntime() {
|
|
4427
4427
|
const platform = os.platform();
|
|
@@ -4904,10 +4904,10 @@ function spawnAgent(command, args, env = process.env, onStart = null) {
|
|
|
4904
4904
|
windowsHide: true
|
|
4905
4905
|
});
|
|
4906
4906
|
child.livedeskOwnsProcessGroup = ownsProcessGroup;
|
|
4907
|
-
child.livedeskWindowsTreeTracker = createWindowsProcessTreeTracker(child, {
|
|
4908
|
-
spawnedAtMs: agentSpawnedAtMs,
|
|
4909
|
-
ownerPid: WINDOWS_PROCESS_MANIFEST_OWNER?.pid || process.pid,
|
|
4910
|
-
publishTrackedRecords: WINDOWS_PROCESS_MANIFEST_OWNER
|
|
4907
|
+
child.livedeskWindowsTreeTracker = createWindowsProcessTreeTracker(child, {
|
|
4908
|
+
spawnedAtMs: agentSpawnedAtMs,
|
|
4909
|
+
ownerPid: WINDOWS_PROCESS_MANIFEST_OWNER?.pid || process.pid,
|
|
4910
|
+
publishTrackedRecords: WINDOWS_PROCESS_MANIFEST_OWNER
|
|
4911
4911
|
? publishWindowsOwnedAgentRecords
|
|
4912
4912
|
: null
|
|
4913
4913
|
});
|
|
@@ -5006,9 +5006,9 @@ export function requiresFastTransport(prepared = {}) {
|
|
|
5006
5006
|
|| prepared.relayExplicit === true;
|
|
5007
5007
|
}
|
|
5008
5008
|
|
|
5009
|
-
export async function runClientRuntime(argv = process.argv.slice(2), runtimeOptions = {}) {
|
|
5010
|
-
const hubSelfAgent = isHubSelfAgentRuntime();
|
|
5011
|
-
if (!hubSelfAgent) startNetworkChangeMonitor();
|
|
5009
|
+
export async function runClientRuntime(argv = process.argv.slice(2), runtimeOptions = {}) {
|
|
5010
|
+
const hubSelfAgent = isHubSelfAgentRuntime();
|
|
5011
|
+
if (!hubSelfAgent) startNetworkChangeMonitor();
|
|
5012
5012
|
if (isTruthy(process.env.LIVEDESK_DESKTOP_HOST)) {
|
|
5013
5013
|
unregisterWindowsStartup();
|
|
5014
5014
|
}
|
|
@@ -5025,11 +5025,11 @@ export async function runClientRuntime(argv = process.argv.slice(2), runtimeOpti
|
|
|
5025
5025
|
if (parsed.updateWaitPid) {
|
|
5026
5026
|
await waitForProcessExit(parsed.updateWaitPid);
|
|
5027
5027
|
}
|
|
5028
|
-
if (!hubSelfAgent) {
|
|
5029
|
-
writeClientUpdateRuntimeStage('launcher-started', {
|
|
5030
|
-
restartVerified: false
|
|
5031
|
-
});
|
|
5032
|
-
}
|
|
5028
|
+
if (!hubSelfAgent) {
|
|
5029
|
+
writeClientUpdateRuntimeStage('launcher-started', {
|
|
5030
|
+
restartVerified: false
|
|
5031
|
+
});
|
|
5032
|
+
}
|
|
5033
5033
|
if (parsed.help) {
|
|
5034
5034
|
printHelp();
|
|
5035
5035
|
return;
|
|
@@ -5065,7 +5065,7 @@ export async function runClientRuntime(argv = process.argv.slice(2), runtimeOpti
|
|
|
5065
5065
|
return supabaseClientPromise;
|
|
5066
5066
|
};
|
|
5067
5067
|
let connectionPage = null;
|
|
5068
|
-
if (isTruthy(process.env.LIVEDESK_UNIFIED_RUNTIME) && !hubSelfAgent) {
|
|
5068
|
+
if (isTruthy(process.env.LIVEDESK_UNIFIED_RUNTIME) && !hubSelfAgent) {
|
|
5069
5069
|
let resolveStarted;
|
|
5070
5070
|
let rejectStarted;
|
|
5071
5071
|
const started = new Promise((resolve, reject) => {
|
|
@@ -5102,9 +5102,9 @@ export async function runClientRuntime(argv = process.argv.slice(2), runtimeOpti
|
|
|
5102
5102
|
if (savedSlot) {
|
|
5103
5103
|
parsed.slot = savedSlot;
|
|
5104
5104
|
}
|
|
5105
|
-
const prepared = hubSelfAgent
|
|
5106
|
-
? prepareHubSelfAgentConnection(parsed)
|
|
5107
|
-
: await prepareLoginConnection(parsed, connectionPage, getSupabaseClient);
|
|
5105
|
+
const prepared = hubSelfAgent
|
|
5106
|
+
? prepareHubSelfAgentConnection(parsed)
|
|
5107
|
+
: await prepareLoginConnection(parsed, connectionPage, getSupabaseClient);
|
|
5108
5108
|
connectionPage = prepared.connectionPage || connectionPage;
|
|
5109
5109
|
prepared.connectionPage?.update({
|
|
5110
5110
|
manager: prepared.manager,
|
|
@@ -5158,14 +5158,14 @@ export async function runClientRuntime(argv = process.argv.slice(2), runtimeOpti
|
|
|
5158
5158
|
runtimeId: fastRuntime?.rid || '',
|
|
5159
5159
|
state: 'launching'
|
|
5160
5160
|
});
|
|
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({
|
|
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({
|
|
5169
5169
|
engine: 'fast',
|
|
5170
5170
|
command: fastLaunch.command,
|
|
5171
5171
|
args: redactAgentArgs(launchArgs),
|
|
@@ -5277,11 +5277,11 @@ export async function runClientRuntime(argv = process.argv.slice(2), runtimeOpti
|
|
|
5277
5277
|
console.log(`[LiveDesk Client] Restarting Agent after ${restart.reason}.`);
|
|
5278
5278
|
continue;
|
|
5279
5279
|
}
|
|
5280
|
-
const terminalShutdownRequested = disposeAgentTerminationHandlers.isTerminating?.() === true;
|
|
5281
|
-
if (result?.signal && terminalShutdownRequested) {
|
|
5282
|
-
connectionPage?.close?.();
|
|
5283
|
-
process.kill(process.pid, result.signal);
|
|
5284
|
-
return;
|
|
5280
|
+
const terminalShutdownRequested = disposeAgentTerminationHandlers.isTerminating?.() === true;
|
|
5281
|
+
if (result?.signal && terminalShutdownRequested) {
|
|
5282
|
+
connectionPage?.close?.();
|
|
5283
|
+
process.kill(process.pid, result.signal);
|
|
5284
|
+
return;
|
|
5285
5285
|
}
|
|
5286
5286
|
if (result?.code === EXIT_CLIENT_UPDATE) {
|
|
5287
5287
|
connectionPage?.close?.();
|
|
@@ -5294,11 +5294,11 @@ export async function runClientRuntime(argv = process.argv.slice(2), runtimeOpti
|
|
|
5294
5294
|
if (pairChanged || cachedHandshakeFailed) {
|
|
5295
5295
|
clearCachedHubTarget();
|
|
5296
5296
|
}
|
|
5297
|
-
console.error(pairChanged
|
|
5298
|
-
? 'LiveDesk Hub pair token changed. Refreshing Hub discovery now.'
|
|
5299
|
-
: result?.signal
|
|
5300
|
-
? `LiveDesk Agent ended unexpectedly with signal ${result.signal}. Keeping the Client alive and reconnecting to the Hub now.`
|
|
5301
|
-
: 'LiveDesk Hub connection ended. Looking for the current Hub now.');
|
|
5297
|
+
console.error(pairChanged
|
|
5298
|
+
? 'LiveDesk Hub pair token changed. Refreshing Hub discovery now.'
|
|
5299
|
+
: result?.signal
|
|
5300
|
+
? `LiveDesk Agent ended unexpectedly with signal ${result.signal}. Keeping the Client alive and reconnecting to the Hub now.`
|
|
5301
|
+
: 'LiveDesk Hub connection ended. Looking for the current Hub now.');
|
|
5302
5302
|
connectionPage?.update({
|
|
5303
5303
|
agent: {
|
|
5304
5304
|
requestedEngine: prepared.engine,
|
|
@@ -5307,27 +5307,27 @@ export async function runClientRuntime(argv = process.argv.slice(2), runtimeOpti
|
|
|
5307
5307
|
},
|
|
5308
5308
|
manager: '',
|
|
5309
5309
|
message: 'The previous Hub is unavailable. LiveDesk is finding the current Hub automatically.'
|
|
5310
|
-
});
|
|
5311
|
-
continue;
|
|
5312
|
-
}
|
|
5313
|
-
if (result?.signal) {
|
|
5314
|
-
connectionPage?.close?.();
|
|
5315
|
-
process.kill(process.pid, result.signal);
|
|
5316
|
-
return;
|
|
5317
|
-
}
|
|
5318
|
-
connectionPage?.close?.();
|
|
5310
|
+
});
|
|
5311
|
+
continue;
|
|
5312
|
+
}
|
|
5313
|
+
if (result?.signal) {
|
|
5314
|
+
connectionPage?.close?.();
|
|
5315
|
+
process.kill(process.pid, result.signal);
|
|
5316
|
+
return;
|
|
5317
|
+
}
|
|
5318
|
+
connectionPage?.close?.();
|
|
5319
5319
|
process.exit(result?.code ?? 0);
|
|
5320
5320
|
}
|
|
5321
5321
|
}
|
|
5322
5322
|
|
|
5323
|
-
if (process.argv[1] && resolve(process.argv[1]) === resolve(fileURLToPath(import.meta.url))) {
|
|
5324
|
-
if (isHubSelfAgentRuntime()) {
|
|
5325
|
-
process.on('message', message => {
|
|
5326
|
-
if (message?.type !== HUB_SELF_AGENT_SHUTDOWN_MESSAGE) return;
|
|
5327
|
-
requestClientRuntimeShutdown(message?.signal === 'SIGINT' ? 'SIGINT' : 'SIGTERM');
|
|
5328
|
-
});
|
|
5329
|
-
}
|
|
5330
|
-
runClientRuntime().catch(error => {
|
|
5323
|
+
if (process.argv[1] && resolve(process.argv[1]) === resolve(fileURLToPath(import.meta.url))) {
|
|
5324
|
+
if (isHubSelfAgentRuntime()) {
|
|
5325
|
+
process.on('message', message => {
|
|
5326
|
+
if (message?.type !== HUB_SELF_AGENT_SHUTDOWN_MESSAGE) return;
|
|
5327
|
+
requestClientRuntimeShutdown(message?.signal === 'SIGINT' ? 'SIGINT' : 'SIGTERM');
|
|
5328
|
+
});
|
|
5329
|
+
}
|
|
5330
|
+
runClientRuntime().catch(error => {
|
|
5331
5331
|
console.error(error?.message || error);
|
|
5332
5332
|
process.exit(1);
|
|
5333
5333
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livedesk/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.247",
|
|
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.
|
|
46
|
-
"@livedesk/fast-osx-arm64": "0.1.
|
|
47
|
-
"@livedesk/fast-osx-x64": "0.1.
|
|
48
|
-
"@livedesk/fast-win-x64": "0.1.
|
|
45
|
+
"@livedesk/fast-linux-x64": "0.1.444",
|
|
46
|
+
"@livedesk/fast-osx-arm64": "0.1.444",
|
|
47
|
+
"@livedesk/fast-osx-x64": "0.1.444",
|
|
48
|
+
"@livedesk/fast-win-x64": "0.1.444"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
@@ -852,10 +852,10 @@ export function installAgentTerminationHandlers({
|
|
|
852
852
|
// dispatching its JavaScript SIGTERM listener. Replacement startup must
|
|
853
853
|
// enter this exact cleanup state machine directly instead of simulating an
|
|
854
854
|
// operating-system signal.
|
|
855
|
-
dispose.requestTermination = (signal = 'SIGTERM') => {
|
|
856
|
-
const normalizedSignal = signal === 'SIGINT' ? 'SIGINT' : 'SIGTERM';
|
|
857
|
-
handlers.get(normalizedSignal)?.();
|
|
858
|
-
};
|
|
859
|
-
dispose.isTerminating = () => terminating;
|
|
860
|
-
return dispose;
|
|
861
|
-
}
|
|
855
|
+
dispose.requestTermination = (signal = 'SIGTERM') => {
|
|
856
|
+
const normalizedSignal = signal === 'SIGINT' ? 'SIGINT' : 'SIGTERM';
|
|
857
|
+
handlers.get(normalizedSignal)?.();
|
|
858
|
+
};
|
|
859
|
+
dispose.isTerminating = () => terminating;
|
|
860
|
+
return dispose;
|
|
861
|
+
}
|