@platless/axom-cli 0.5.9 → 0.6.52
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/README.md +25 -6
- package/dist/axom-patch/cli/README.md +129 -12
- package/dist/axom-patch/cli/account-limits/generate.py +15 -12
- package/dist/axom-patch/cli/account-limits/kimi-proxy.mjs +20 -3
- package/dist/axom-patch/cli/claude-account-limits.json +9 -9
- package/dist/axom-patch/cli/claude-replay-lifecycle.json +16 -0
- package/dist/axom-patch/cli/codex-account-limits.json +11 -11
- package/dist/axom-patch/cli/codex-terminal-output.json +16 -0
- package/dist/axom-patch/cli/commandcode-account-limits.json +9 -9
- package/dist/axom-patch/cli/kimi-quota.mjs +12 -0
- package/dist/axom-patch/cli/kimi-subagents.mjs +173 -0
- package/dist/axom-patch/cli/nightly-task.md +55 -13
- package/dist/axom-patch/cli/probes/claude-replay-lifecycle.mjs +31 -0
- package/dist/axom-patch/cli/probes/codex-terminal-output.mjs +33 -0
- package/dist/axom-patch/cli/probes/kimi-subagent-subwork.mjs +82 -0
- package/dist/axom-patch/cli/probes/zcode-env-account.mjs +81 -0
- package/dist/axom-patch/cli/probes/zcode-subagent-subwork.mjs +7 -0
- package/dist/axom-patch/cli/qoder/dist/axom-acp-compat.mjs +1687 -0
- package/dist/axom-patch/cli/qoder/releases/1.1.75.json +277 -0
- package/dist/axom-patch/cli/qoder-background-terminal.md +13 -6
- package/dist/axom-patch/cli/qoder-foreground-output.md +14 -8
- package/dist/axom-patch/cli/qoder-native-acp.json +227 -0
- package/dist/axom-patch/cli/qoder-steering.md +20 -25
- package/dist/axom-patch/cli/qoder-subagent-subwork.md +17 -68
- package/dist/axom-patch/cli/runtime.json +19 -19
- package/dist/axom-patch/cli/zcode/env-account.mjs +13 -0
- package/dist/axom-patch/cli/zcode/generate-env-account.py +52 -0
- package/dist/axom-patch/cli/zcode-account-limits.json +10 -11
- package/dist/axom-patch/cli/zcode-env-account.json +58 -0
- package/dist/axom-patch/cli/zcode-models.json +9 -10
- package/dist/axom-patch/cli/zcode-subagent-subwork.json +10 -11
- package/dist/cli.js +11 -45
- package/dist/commands/auth.js +4 -1
- package/dist/commands/knowledge.js +47 -0
- package/dist/commands/update.js +126 -3
- package/dist/commands/workstation.js +101 -164
- package/dist/commands/workstationRegistrations.js +116 -0
- package/dist/credentialBroker.js +13 -2
- package/dist/credentials.js +16 -0
- package/dist/install/claude/commands.js +15 -15
- package/dist/keepers/terminal/keeper.mjs +1089 -673
- package/dist/keepers/terminal/manifest.json +4 -4
- package/dist/mcp.js +1 -1
- package/dist/native/darwin-x64/axom-quic +0 -0
- package/dist/workstation/acp/acpAgents.js +113 -102
- package/dist/workstation/acp/acpClient.js +26 -0
- package/dist/workstation/acp/builds/install/npm.js +99 -10
- package/dist/workstation/acp/initializeResponse.js +6 -1
- package/dist/workstation/acp/managedPatches.js +189 -25
- package/dist/workstation/acp/managedRuntime.js +314 -0
- package/dist/workstation/acp/outbox.js +12 -5
- package/dist/workstation/acp/patchAssets.js +40 -0
- package/dist/workstation/acp/permission.js +2 -2
- package/dist/workstation/acp/processor/checkpoint.js +26 -34
- package/dist/workstation/acp/processor/control.js +7 -80
- package/dist/workstation/acp/processor/jsonrpc.js +8 -0
- package/dist/workstation/acp/processor/runtime.js +5 -81
- package/dist/workstation/acp/processor/session.js +54 -82
- package/dist/workstation/acp/processor/state.js +7 -13
- package/dist/workstation/acp/processor/step.js +3 -20
- package/dist/workstation/acp/processor/test/fixtureLog.js +9 -16
- package/dist/workstation/acp/processor/transport/local.js +19 -3
- package/dist/workstation/acp/processor/updates.js +156 -105
- package/dist/workstation/acp/processorSession.js +20 -173
- package/dist/workstation/acp/registry/catalog.js +65 -39
- package/dist/workstation/acp/registry/launch.js +16 -1
- package/dist/workstation/acp/switching.js +0 -3
- package/dist/workstation/acp/test/fakeAgent.js +13 -0
- package/dist/workstation/acp/test/keeperWorld.js +32 -3
- package/dist/workstation/acp/test/raw/sources.js +16 -130
- package/dist/workstation/acp/test/realAdapter.js +1 -47
- package/dist/workstation/acp/test/scriptAgent.js +11 -3
- package/dist/workstation/agentFlow.js +1 -1
- package/dist/workstation/agentSessions.js +114 -166
- package/dist/workstation/channels/agent.js +9 -1
- package/dist/workstation/channels/computer.js +27 -4
- package/dist/workstation/channels/management.js +130 -15
- package/dist/workstation/channels/url.js +1 -1
- package/dist/workstation/config.js +33 -9
- package/dist/workstation/connection/encryptedChannel.js +4 -1
- package/dist/workstation/control/bindingStore.js +204 -0
- package/dist/workstation/control/commands.js +125 -0
- package/dist/workstation/control/daemonIdentity.js +143 -0
- package/dist/workstation/control/deviceCommands.js +191 -0
- package/dist/workstation/control/deviceProtocol.js +68 -0
- package/dist/workstation/control/enrollment.js +106 -0
- package/dist/workstation/control/inspect.js +71 -0
- package/dist/workstation/control/locks.js +110 -0
- package/dist/workstation/control/protocol.js +40 -0
- package/dist/workstation/control/restartGuard.js +46 -0
- package/dist/workstation/control/rootFormat.js +16 -0
- package/dist/workstation/control/runtimeClient.js +152 -0
- package/dist/workstation/control/runtimeHost.js +235 -0
- package/dist/workstation/control/serverIdentity.js +35 -0
- package/dist/workstation/control/updateTransition.js +91 -0
- package/dist/workstation/daemon.js +266 -264
- package/dist/workstation/daemonctl.js +226 -25
- package/dist/workstation/desktopControl/audio.js +99 -0
- package/dist/workstation/desktopControl/automationDevice.js +219 -0
- package/dist/workstation/desktopControl/automationJson.js +74 -0
- package/dist/workstation/desktopControl/automationLocalState.js +23 -0
- package/dist/workstation/desktopControl/automationProtocol.js +253 -0
- package/dist/workstation/desktopControl/automationSchema.generated.js +1 -0
- package/dist/workstation/desktopControl/automationSession.js +81 -0
- package/dist/workstation/desktopControl/automationTransport.js +138 -0
- package/dist/workstation/desktopControl/capabilities.js +93 -0
- package/dist/workstation/desktopControl/captureModes.js +9 -0
- package/dist/workstation/desktopControl/captureTargetLabel.js +9 -0
- package/dist/workstation/desktopControl/deviceAdmission.js +229 -0
- package/dist/workstation/desktopControl/deviceOwnership.js +130 -0
- package/dist/workstation/desktopControl/deviceSockets.js +246 -0
- package/dist/workstation/desktopControl/helperProcess.js +602 -0
- package/dist/workstation/desktopControl/hostGrant.js +65 -0
- package/dist/workstation/desktopControl/lobby.js +131 -0
- package/dist/workstation/desktopControl/macProvider.js +156 -0
- package/dist/workstation/desktopControl/media.js +331 -0
- package/dist/workstation/desktopControl/nativeDeviceAdmission.js +207 -0
- package/dist/workstation/desktopControl/nativeProvider.js +1044 -0
- package/dist/workstation/desktopControl/networkEvidence.js +43 -0
- package/dist/workstation/desktopControl/overview.js +58 -0
- package/dist/workstation/desktopControl/ownershipProtocol.js +31 -0
- package/dist/workstation/desktopControl/protocol.js +311 -0
- package/dist/workstation/desktopControl/provider.js +1 -0
- package/dist/workstation/desktopControl/quicMedia.js +240 -0
- package/dist/workstation/desktopControl/rateController.js +226 -0
- package/dist/workstation/desktopControl/supervisor.js +1774 -0
- package/dist/workstation/desktopControl/transport.js +27 -0
- package/dist/workstation/desktopControl/wallpaper.js +98 -0
- package/dist/workstation/exec/policy.js +5 -0
- package/dist/workstation/files/client.js +10 -1
- package/dist/workstation/files/credentials.js +142 -0
- package/dist/workstation/files/host.js +9 -2
- package/dist/workstation/files/text.js +42 -8
- package/dist/workstation/journal.js +5 -2
- package/dist/workstation/keepers/acp/client.js +38 -2
- package/dist/workstation/keepers/kit/buildVersion.js +35 -11
- package/dist/workstation/keepers/kit/bundle.js +21 -17
- package/dist/workstation/keepers/kit/client.js +2 -2
- package/dist/workstation/keepers/kit/launcher.js +123 -7
- package/dist/workstation/keepers/kit/paths.js +2 -1
- package/dist/workstation/keepers/legacy.js +16 -2
- package/dist/workstation/keepers/policy.js +5 -34
- package/dist/workstation/keepers/terminal/client.js +115 -23
- package/dist/workstation/keepers/terminal/exec.js +6 -3
- package/dist/workstation/keepers/terminal/frames.js +73 -0
- package/dist/workstation/keepers/terminal/generations.js +5 -8
- package/dist/workstation/keepers/terminal/gridProtocol.js +16 -0
- package/dist/workstation/keepers/terminal/input.js +146 -0
- package/dist/workstation/keepers/terminal/keeper.js +22 -8
- package/dist/workstation/keepers/terminal/main.js +1 -1
- package/dist/workstation/keepers/terminal/metadata.js +138 -0
- package/dist/workstation/keepers/terminal/protocol.js +4 -28
- package/dist/workstation/keepers/terminal/pty.js +1 -330
- package/dist/workstation/keepers/terminal/screen.js +246 -0
- package/dist/workstation/keepers/terminal/sessions.js +526 -0
- package/dist/workstation/managedInstall.js +57 -0
- package/dist/workstation/oauth/deviceAuthorization.js +31 -17
- package/dist/workstation/protocol/agent.js +2 -15
- package/dist/workstation/protocol/management.js +113 -5
- package/dist/workstation/protocol/runtimeDiagnostics.js +15 -0
- package/dist/workstation/rd/artifact.js +120 -0
- package/dist/workstation/rd/control.js +117 -0
- package/dist/workstation/rd/display.js +29 -0
- package/dist/workstation/rd/host.js +213 -0
- package/dist/workstation/rd/migrationReadiness.js +46 -0
- package/dist/workstation/rd/provider.js +256 -0
- package/dist/workstation/rd/sessions.js +391 -0
- package/dist/workstation/rd/state.js +57 -0
- package/dist/workstation/rd/update.js +168 -0
- package/dist/workstation/rd/upkeep.js +80 -0
- package/dist/workstation/register.js +27 -37
- package/dist/workstation/registrations/enrollment.js +250 -0
- package/dist/workstation/registrations/enrollmentPending.js +361 -0
- package/dist/workstation/registrations/migration.js +356 -0
- package/dist/workstation/registrations/model.js +34 -0
- package/dist/workstation/registrations/removal.js +222 -0
- package/dist/workstation/registrations/store.js +737 -0
- package/dist/workstation/runtime/desktopBinding.js +20 -0
- package/dist/workstation/runtime/deviceDesktop.js +193 -0
- package/dist/workstation/runtime/deviceRuntime.js +568 -0
- package/dist/workstation/runtime/deviceServices.js +117 -0
- package/dist/workstation/runtime/events.js +20 -0
- package/dist/workstation/runtime/ownership.js +100 -0
- package/dist/workstation/runtime/registrationRuntime.js +575 -0
- package/dist/workstation/runtime/remoteDesktopAdapter.js +186 -0
- package/dist/workstation/runtime/removalActivity.js +184 -0
- package/dist/workstation/service/installer.js +197 -14
- package/dist/workstation/service/launchd.js +2 -0
- package/dist/workstation/service/systemd.js +1 -0
- package/dist/workstation/storageMetrics.js +118 -0
- package/dist/workstation/systemMetrics.js +47 -92
- package/dist/workstation/toolchain.js +94 -0
- package/dist/workstation/tools/browser.js +28 -4
- package/dist/workstation/tools/client.js +8 -27
- package/dist/workstation/tools/info.js +6 -13
- package/dist/workstation/tools/terminalRouter.js +17 -172
- package/dist/workstation/tools/validation.js +55 -1
- package/dist/workstation/update/archiveEvidence.js +206 -0
- package/dist/workstation/update/artifact.js +2 -1
- package/dist/workstation/update/coordinator.js +34 -13
- package/dist/workstation/update/deviceCompatibility.js +119 -0
- package/dist/workstation/update/deviceCoordinator.js +369 -0
- package/dist/workstation/update/deviceHealth.js +104 -0
- package/dist/workstation/update/deviceHealthProtocol.js +26 -0
- package/dist/workstation/update/deviceRecoveryLifecycle.js +46 -0
- package/dist/workstation/update/deviceRollback.js +78 -0
- package/dist/workstation/update/globalInstall.js +186 -0
- package/dist/workstation/update/legacyBridge.js +414 -0
- package/dist/workstation/update/legacyOwner.js +39 -0
- package/dist/workstation/update/npmInstaller.js +51 -25
- package/dist/workstation/update/privateDurability.js +61 -0
- package/dist/workstation/update/rdRollback.js +145 -0
- package/dist/workstation/update/recoveryPlan.js +124 -0
- package/dist/workstation/update/runUpdate.js +10 -3
- package/dist/workstation/update/taskRegistry.js +161 -3
- package/dist/workstation/update/watchdog.js +29806 -333
- package/dist/workstation/update/watchdogProcess.js +72 -0
- package/package.json +11 -7
- package/skills/axom/SKILL.md +11 -11
- package/skills/axom-definition/SKILL.md +3 -3
- package/skills/axom-platform/SKILL.md +3 -3
- package/dist/axom-patch/cli/probes/qoder-steering.mjs +0 -89
- package/dist/axom-patch/cli/probes/qoder-subagent-origin.mjs +0 -61
- package/dist/axom-patch/cli/qoder-steering.json +0 -52
- package/dist/axom-patch/cli/qoder-subagent-origin.json +0 -73
- package/dist/commands/guide.js +0 -38
- package/dist/runtime-deps/qoder-sdk/package-lock.json +0 -1189
- package/dist/runtime-deps/qoder-sdk/package.json +0 -8
- package/dist/workstation/acp/delegationMcp.js +0 -24
- package/dist/workstation/acp/processor/sideChannel.js +0 -80
- package/dist/workstation/acp/qoderStartup.js +0 -45
- package/dist/workstation/acp/test/raw/qoderCaptures.js +0 -125
- package/dist/workstation/qoderAdapter/backgroundProcess.js +0 -118
- package/dist/workstation/qoderAdapter/backgroundTerminal.js +0 -193
- package/dist/workstation/qoderAdapter/backgroundTerminalFold.js +0 -372
- package/dist/workstation/qoderAdapter/callbackContext.js +0 -76
- package/dist/workstation/qoderAdapter/completedContinuation.js +0 -139
- package/dist/workstation/qoderAdapter/contract.js +0 -78
- package/dist/workstation/qoderAdapter/foregroundOutput.js +0 -36
- package/dist/workstation/qoderAdapter/history.js +0 -85
- package/dist/workstation/qoderAdapter/identityIndex.js +0 -191
- package/dist/workstation/qoderAdapter/inputQueue.js +0 -42
- package/dist/workstation/qoderAdapter/main.js +0 -95
- package/dist/workstation/qoderAdapter/mapper.js +0 -117
- package/dist/workstation/qoderAdapter/observerPlugin.js +0 -245
- package/dist/workstation/qoderAdapter/observerReceiver.js +0 -187
- package/dist/workstation/qoderAdapter/permissions.js +0 -61
- package/dist/workstation/qoderAdapter/profile.js +0 -93
- package/dist/workstation/qoderAdapter/sdkDriver.js +0 -48
- package/dist/workstation/qoderAdapter/sdkRuntime.js +0 -93
- package/dist/workstation/qoderAdapter/sdkRuntimeInstall.js +0 -145
- package/dist/workstation/qoderAdapter/session.js +0 -319
- package/dist/workstation/qoderAdapter/subagentMeta.js +0 -28
- package/dist/workstation/qoderAdapter/subwork.js +0 -85
- package/dist/workstation/qoderAdapter/taskControl.js +0 -38
- package/dist/workstation/qoderAdapter/taskLedger.js +0 -163
- package/dist/workstation/qoderAdapter/usage.js +0 -37
- /package/dist/workstation/{qoderAdapter/types.js → desktopControl/automationPreparation.js} +0 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import WebSocket from 'ws';
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { openQuicMedia } from './quicMedia.js';
|
|
4
|
+
import { isTrustedPlaintextHost } from '../channels/url.js';
|
|
5
|
+
import { decodeDesktopControl, encodeDesktopControl, parseDesktopJson } from './protocol.js';
|
|
6
|
+
import { decodeDesktopTransport, encodeDesktopTransport } from './transport.js';
|
|
7
|
+
import { bounded, DesktopQueue, NativeCommandError } from './helperProcess.js';
|
|
8
|
+
import { mediaRequire } from './media.js';
|
|
9
|
+
export function desktopSocketUrl(server, role, allow = false) {
|
|
10
|
+
const url = new URL(server);
|
|
11
|
+
mediaRequire(!url.username && !url.password && !url.search && !url.hash && ['https:', 'http:'].includes(url.protocol));
|
|
12
|
+
mediaRequire(url.protocol === 'https:' || allow && isTrustedPlaintextHost(url.hostname));
|
|
13
|
+
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
14
|
+
url.pathname = `${url.pathname.replace(/\/$/, '')}/workstation/ws/desktop/${role}`;
|
|
15
|
+
return url;
|
|
16
|
+
}
|
|
17
|
+
/** Fixed paths, certificate validation on both legs, and no redirect/URL credential propagation. */
|
|
18
|
+
export class DeviceSockets {
|
|
19
|
+
server;
|
|
20
|
+
allowPrivateWs;
|
|
21
|
+
quicRetryAt = 0;
|
|
22
|
+
constructor(server, allowPrivateWs = false) {
|
|
23
|
+
this.server = server;
|
|
24
|
+
this.allowPrivateWs = allowPrivateWs;
|
|
25
|
+
}
|
|
26
|
+
async uploadWallpaper(grant, wallpaper, unchanged = false) {
|
|
27
|
+
const url = desktopSocketUrl(this.server, 'media', this.allowPrivateWs);
|
|
28
|
+
url.protocol = url.protocol === 'wss:' ? 'https:' : 'http:';
|
|
29
|
+
url.pathname = url.pathname.replace(/\/ws\/desktop\/media$/, '/desktop/background');
|
|
30
|
+
const headers = { 'X-Axom-Background-Grant': grant, 'Content-Type': 'image/webp' };
|
|
31
|
+
if (wallpaper) {
|
|
32
|
+
headers['X-Axom-Background-Asset'] = Buffer.from(JSON.stringify(wallpaper.asset)).toString('base64url');
|
|
33
|
+
headers['X-Axom-Background-Unchanged'] = unchanged ? '1' : '0';
|
|
34
|
+
}
|
|
35
|
+
else
|
|
36
|
+
headers['X-Axom-Background-Error'] = 'unavailable';
|
|
37
|
+
const response = await fetch(url, { method: 'POST', redirect: 'error', signal: AbortSignal.timeout(10_000), headers,
|
|
38
|
+
body: wallpaper && !unchanged ? new Uint8Array(wallpaper.bytes) : undefined });
|
|
39
|
+
if (!response.ok)
|
|
40
|
+
throw new NativeCommandError('transport_failed');
|
|
41
|
+
await response.body?.cancel();
|
|
42
|
+
}
|
|
43
|
+
async control(binding, signal, current) {
|
|
44
|
+
const queue = new DesktopQueue();
|
|
45
|
+
const socket = await this.open(binding, binding.controlGrant, 'control', signal, current, bytes => {
|
|
46
|
+
const raw = parseDesktopJson(bytes);
|
|
47
|
+
if (raw.type === 'media_grant') {
|
|
48
|
+
const grant = decodeDesktopTransport(bytes);
|
|
49
|
+
mediaRequire(grant.type === 'media_grant' && grant.controlGeneration === binding.controlGeneration && grant.sessionId === binding.sessionId);
|
|
50
|
+
queue.push(grant);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const message = decodeDesktopControl(bytes);
|
|
54
|
+
mediaRequire(message.sessionId === binding.sessionId && !['clipboard_result', 'offer', 'configured', 'input_result', 'resize_result', 'media_open', 'appearance_result', 'motion_cut_barrier', 'motion_cut_prepared', 'motion_cut_request', 'motion_cut_ack', 'motion_cut_fence', 'audio_configured', 'audio_state'].includes(message.type));
|
|
55
|
+
queue.push(message);
|
|
56
|
+
}
|
|
57
|
+
}, () => queue.close());
|
|
58
|
+
let overview;
|
|
59
|
+
let audio;
|
|
60
|
+
let audioOpening;
|
|
61
|
+
let audioSerial = 0;
|
|
62
|
+
const audioCostId = randomBytes(16).toString('hex');
|
|
63
|
+
let audioBytes = 0;
|
|
64
|
+
const prepareAudio = async () => {
|
|
65
|
+
if (!socket.audioToken || !current() || signal.aborted)
|
|
66
|
+
throw new NativeCommandError('audio_unavailable');
|
|
67
|
+
const serial = audioSerial;
|
|
68
|
+
audioOpening ??= this.open(binding, socket.audioToken, 'audio', signal, current, () => { });
|
|
69
|
+
const connection = await audioOpening;
|
|
70
|
+
if (serial !== audioSerial || !current()) {
|
|
71
|
+
connection.close();
|
|
72
|
+
throw new NativeCommandError('audio_unavailable');
|
|
73
|
+
}
|
|
74
|
+
audio = connection;
|
|
75
|
+
void connection.closed.then(() => { if (audio === connection) {
|
|
76
|
+
audio = undefined;
|
|
77
|
+
audioOpening = undefined;
|
|
78
|
+
} });
|
|
79
|
+
};
|
|
80
|
+
let retryAt = 0;
|
|
81
|
+
return { messages: queue, send: message => socket.send(encodeDesktopControl(message)),
|
|
82
|
+
prepareAudio: socket.audioToken ? prepareAudio : undefined,
|
|
83
|
+
sendAudio: socket.audioToken ? async (bytes) => {
|
|
84
|
+
if (!current() || signal.aborted)
|
|
85
|
+
return false;
|
|
86
|
+
const serial = audioSerial;
|
|
87
|
+
try {
|
|
88
|
+
if (!audio)
|
|
89
|
+
await prepareAudio();
|
|
90
|
+
const connection = audio;
|
|
91
|
+
if (serial !== audioSerial || !current()) {
|
|
92
|
+
connection.close();
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
audio = connection;
|
|
96
|
+
await bounded(connection.send(bytes), 80, 'audio_stale');
|
|
97
|
+
audioBytes += bytes.length + 32;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
audio?.close();
|
|
102
|
+
audio = undefined;
|
|
103
|
+
audioOpening = undefined;
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
} : undefined,
|
|
107
|
+
stopAudio: () => {
|
|
108
|
+
audioSerial++;
|
|
109
|
+
audio?.close();
|
|
110
|
+
void audioOpening?.then(connection => connection.close(), () => { });
|
|
111
|
+
audio = undefined;
|
|
112
|
+
audioOpening = undefined;
|
|
113
|
+
},
|
|
114
|
+
audioTransportCost: () => ({ id: audioCostId, totalBytes: audioBytes }),
|
|
115
|
+
sendOverview: socket.overviewToken ? async (bytes) => {
|
|
116
|
+
if (performance.now() < retryAt || !current() || signal.aborted)
|
|
117
|
+
return false;
|
|
118
|
+
try {
|
|
119
|
+
overview ??= await this.open(binding, socket.overviewToken, 'overview', signal, current, () => { });
|
|
120
|
+
await overview.send(bytes);
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
overview?.close();
|
|
125
|
+
overview = undefined;
|
|
126
|
+
retryAt = performance.now() + 5000;
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
} : undefined,
|
|
130
|
+
close: () => { audioSerial++; audio?.close(); overview?.close(); socket.close(); } };
|
|
131
|
+
}
|
|
132
|
+
async media(binding, grant, signal, current, quic) {
|
|
133
|
+
desktopSocketUrl(this.server, 'media', this.allowPrivateWs); // Apply the same origin/TLS policy before either transport.
|
|
134
|
+
if (quic && binding.mediaTransport !== 'wss' && (binding.mediaTransport === 'quic' || performance.now() >= this.quicRetryAt)) {
|
|
135
|
+
const native = await openQuicMedia(this.server, quic, signal, current);
|
|
136
|
+
if (native) {
|
|
137
|
+
// Once the single-use credential is sent, recovery needs a fresh epoch;
|
|
138
|
+
// never replay it over WSS after an ambiguous attachment acknowledgement.
|
|
139
|
+
try {
|
|
140
|
+
await native.send(2, Buffer.from(encodeDesktopTransport({ type: 'device_attach', sessionId: binding.sessionId, grant })));
|
|
141
|
+
const ack = await native.receive(5000);
|
|
142
|
+
mediaRequire(ack.kind === 2);
|
|
143
|
+
const attached = decodeDesktopTransport(ack.bytes);
|
|
144
|
+
mediaRequire(attached.type === 'attached' && attached.sessionId === binding.sessionId && attached.role === 'device_media' && attached.controlGeneration === binding.controlGeneration);
|
|
145
|
+
console.error(JSON.stringify({ event: 'desktop_media_attached', transport: 'quic', role: 'device_media', session: binding.sessionId }));
|
|
146
|
+
void native.receive().then(() => native.close(), () => native.close());
|
|
147
|
+
const id = randomBytes(16).toString('hex');
|
|
148
|
+
return { sendAudio: native.sendAudio, transportCost: () => ({ id, totalBytes: native.transportCost() }), networkSample: () => { const stats = native.pathStats(); return stats ? { ...stats, id } : undefined; }, send: bytes => native.send(3, bytes), close: () => native.close(), closed: native.closed, cutEvents: native.cutEvents, cutCommand: native.cutCommand, finishCut: native.finishCut };
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
this.quicRetryAt = performance.now() + 60000;
|
|
152
|
+
native.close();
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else
|
|
157
|
+
this.quicRetryAt = performance.now() + 60000;
|
|
158
|
+
}
|
|
159
|
+
if (binding.mediaTransport === 'quic')
|
|
160
|
+
throw new NativeCommandError('transport_failed');
|
|
161
|
+
const socket = await this.open(binding, grant, 'media', signal, current, () => { throw new NativeCommandError('invalid_request'); });
|
|
162
|
+
console.error(JSON.stringify({ event: 'desktop_media_attached', transport: 'wss', role: 'device_media', fallback: !quic ? 'not_offered' : 'connect_failed_or_backoff', session: binding.sessionId }));
|
|
163
|
+
const id = randomBytes(16).toString('hex');
|
|
164
|
+
let framingBytes = 0;
|
|
165
|
+
return { transportCost: () => ({ id, totalBytes: framingBytes }), send: async (bytes) => {
|
|
166
|
+
await socket.send(bytes);
|
|
167
|
+
framingBytes += bytes.length < 126 ? 6 : bytes.length <= 65535 ? 8 : 14;
|
|
168
|
+
}, sendCutBarrier: message => socket.send(encodeDesktopControl(message)), close: socket.close, closed: socket.closed };
|
|
169
|
+
}
|
|
170
|
+
async open(binding, grant, role, signal, current, onMessage, onClose = () => { }) {
|
|
171
|
+
mediaRequire(current() && !signal.aborted);
|
|
172
|
+
const ws = new WebSocket(desktopSocketUrl(this.server, role, this.allowPrivateWs), {
|
|
173
|
+
headers: role === 'control' ? { 'X-Axom-Desktop-Quic': '1', 'X-Axom-Desktop-Overview': '1', 'X-Axom-Desktop-Audio': '1' } : {},
|
|
174
|
+
rejectUnauthorized: true, followRedirects: false, maxPayload: 49152, perMessageDeflate: false,
|
|
175
|
+
});
|
|
176
|
+
let overviewToken;
|
|
177
|
+
let audioToken;
|
|
178
|
+
let attached = false, settle, reject;
|
|
179
|
+
const opening = new Promise((resolve, fail) => { settle = resolve; reject = fail; });
|
|
180
|
+
const close = () => { if (ws.readyState === WebSocket.CONNECTING || ws.readyState === WebSocket.OPEN)
|
|
181
|
+
ws.terminate(); };
|
|
182
|
+
const closed = new Promise(resolve => ws.once('close', () => {
|
|
183
|
+
signal.removeEventListener('abort', close);
|
|
184
|
+
onClose();
|
|
185
|
+
resolve();
|
|
186
|
+
if (!attached)
|
|
187
|
+
reject(new NativeCommandError('authorization_lost'));
|
|
188
|
+
}));
|
|
189
|
+
signal.addEventListener('abort', close, { once: true });
|
|
190
|
+
ws.on('error', () => { reject(new NativeCommandError('transport_failed')); close(); });
|
|
191
|
+
ws.once('open', () => {
|
|
192
|
+
if (!current() || signal.aborted) {
|
|
193
|
+
close();
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
ws.send(encodeDesktopTransport({ type: 'device_attach', sessionId: binding.sessionId, grant }));
|
|
197
|
+
});
|
|
198
|
+
ws.on('message', (data, binary) => {
|
|
199
|
+
try {
|
|
200
|
+
if (!current() || signal.aborted) {
|
|
201
|
+
close();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
mediaRequire(!binary);
|
|
205
|
+
const bytes = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
206
|
+
if (!attached) {
|
|
207
|
+
const ack = decodeDesktopTransport(bytes);
|
|
208
|
+
mediaRequire(ack.type === 'attached' && ack.sessionId === binding.sessionId && ack.role === (role === 'overview' || role === 'audio' ? 'device_control' : `device_${role}`) && ack.controlGeneration === binding.controlGeneration);
|
|
209
|
+
overviewToken = ack.overviewToken;
|
|
210
|
+
audioToken = ack.audioToken;
|
|
211
|
+
attached = true;
|
|
212
|
+
settle();
|
|
213
|
+
}
|
|
214
|
+
else
|
|
215
|
+
onMessage(bytes);
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
reject(new NativeCommandError('invalid_request'));
|
|
219
|
+
close();
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
try {
|
|
223
|
+
await bounded(opening, 5000);
|
|
224
|
+
mediaRequire(current() && !signal.aborted);
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
close();
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
let sendTail = Promise.resolve();
|
|
231
|
+
let pending = 0;
|
|
232
|
+
return { close, closed, overviewToken, audioToken, send: bytes => {
|
|
233
|
+
if (pending >= (role === 'media' ? 3 : 2))
|
|
234
|
+
return Promise.reject(new NativeCommandError('transport_failed'));
|
|
235
|
+
pending++;
|
|
236
|
+
const perform = async () => {
|
|
237
|
+
// This is the last check after any queued await, immediately before ws.send.
|
|
238
|
+
mediaRequire(current() && !signal.aborted && ws.readyState === WebSocket.OPEN && ws.bufferedAmount <= (role === 'media' ? 524288 : 65600));
|
|
239
|
+
await bounded(new Promise((resolve, fail) => ws.send(bytes, error => error ? fail(new NativeCommandError('transport_failed')) : resolve())), 5000);
|
|
240
|
+
};
|
|
241
|
+
const sent = role === 'media' ? perform() : sendTail.then(perform);
|
|
242
|
+
sendTail = sent.catch(() => { close(); }).finally(() => { pending--; });
|
|
243
|
+
return sent;
|
|
244
|
+
} };
|
|
245
|
+
}
|
|
246
|
+
}
|