@namzu/sandbox 23.0.1 → 25.0.0
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/CHANGELOG.md +290 -0
- package/dist/backends/http-worker-client.d.ts +3 -1
- package/dist/backends/http-worker-client.d.ts.map +1 -1
- package/dist/backends/http-worker-client.js +15 -4
- package/dist/backends/http-worker-client.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/local-virtual-computer/client.d.ts +21 -0
- package/dist/local-virtual-computer/client.d.ts.map +1 -0
- package/dist/local-virtual-computer/client.js +503 -0
- package/dist/local-virtual-computer/client.js.map +1 -0
- package/dist/local-virtual-computer/detached-process.d.ts +15 -0
- package/dist/local-virtual-computer/detached-process.d.ts.map +1 -0
- package/dist/local-virtual-computer/detached-process.js +111 -0
- package/dist/local-virtual-computer/detached-process.js.map +1 -0
- package/dist/local-virtual-computer/detached-worker.d.ts +11 -0
- package/dist/local-virtual-computer/detached-worker.d.ts.map +1 -0
- package/dist/local-virtual-computer/detached-worker.js +97 -0
- package/dist/local-virtual-computer/detached-worker.js.map +1 -0
- package/dist/local-virtual-computer/dialect.d.ts +26 -0
- package/dist/local-virtual-computer/dialect.d.ts.map +1 -0
- package/dist/local-virtual-computer/dialect.js +61 -0
- package/dist/local-virtual-computer/dialect.js.map +1 -0
- package/dist/local-virtual-computer/engine.d.ts +63 -0
- package/dist/local-virtual-computer/engine.d.ts.map +1 -0
- package/dist/local-virtual-computer/engine.js +125 -0
- package/dist/local-virtual-computer/engine.js.map +1 -0
- package/dist/local-virtual-computer/guest-stdio.d.ts +15 -0
- package/dist/local-virtual-computer/guest-stdio.d.ts.map +1 -0
- package/dist/local-virtual-computer/guest-stdio.js +330 -0
- package/dist/local-virtual-computer/guest-stdio.js.map +1 -0
- package/dist/local-virtual-computer/index.d.ts +36 -0
- package/dist/local-virtual-computer/index.d.ts.map +1 -0
- package/dist/local-virtual-computer/index.js +341 -0
- package/dist/local-virtual-computer/index.js.map +1 -0
- package/dist/local-virtual-computer/podman-machine.d.ts +17 -0
- package/dist/local-virtual-computer/podman-machine.d.ts.map +1 -0
- package/dist/local-virtual-computer/podman-machine.js +181 -0
- package/dist/local-virtual-computer/podman-machine.js.map +1 -0
- package/dist/local-virtual-computer/setup/contract.d.ts +360 -0
- package/dist/local-virtual-computer/setup/contract.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/contract.js +3 -0
- package/dist/local-virtual-computer/setup/contract.js.map +1 -0
- package/dist/local-virtual-computer/setup/elevated.d.ts +78 -0
- package/dist/local-virtual-computer/setup/elevated.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/elevated.js +548 -0
- package/dist/local-virtual-computer/setup/elevated.js.map +1 -0
- package/dist/local-virtual-computer/setup/host.d.ts +12 -0
- package/dist/local-virtual-computer/setup/host.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/host.js +93 -0
- package/dist/local-virtual-computer/setup/host.js.map +1 -0
- package/dist/local-virtual-computer/setup/idle.d.ts +18 -0
- package/dist/local-virtual-computer/setup/idle.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/idle.js +38 -0
- package/dist/local-virtual-computer/setup/idle.js.map +1 -0
- package/dist/local-virtual-computer/setup/image.d.ts +7 -0
- package/dist/local-virtual-computer/setup/image.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/image.js +124 -0
- package/dist/local-virtual-computer/setup/image.js.map +1 -0
- package/dist/local-virtual-computer/setup/index.d.ts +17 -0
- package/dist/local-virtual-computer/setup/index.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/index.js +17 -0
- package/dist/local-virtual-computer/setup/index.js.map +1 -0
- package/dist/local-virtual-computer/setup/limits.d.ts +30 -0
- package/dist/local-virtual-computer/setup/limits.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/limits.js +58 -0
- package/dist/local-virtual-computer/setup/limits.js.map +1 -0
- package/dist/local-virtual-computer/setup/plan.d.ts +8 -0
- package/dist/local-virtual-computer/setup/plan.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/plan.js +131 -0
- package/dist/local-virtual-computer/setup/plan.js.map +1 -0
- package/dist/local-virtual-computer/setup/readiness.d.ts +11 -0
- package/dist/local-virtual-computer/setup/readiness.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/readiness.js +320 -0
- package/dist/local-virtual-computer/setup/readiness.js.map +1 -0
- package/dist/local-virtual-computer/setup/registry.d.ts +18 -0
- package/dist/local-virtual-computer/setup/registry.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/registry.js +50 -0
- package/dist/local-virtual-computer/setup/registry.js.map +1 -0
- package/dist/local-virtual-computer/setup/restart.d.ts +8 -0
- package/dist/local-virtual-computer/setup/restart.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/restart.js +60 -0
- package/dist/local-virtual-computer/setup/restart.js.map +1 -0
- package/dist/local-virtual-computer/setup/resume.d.ts +14 -0
- package/dist/local-virtual-computer/setup/resume.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/resume.js +58 -0
- package/dist/local-virtual-computer/setup/resume.js.map +1 -0
- package/dist/local-virtual-computer/setup/run.d.ts +8 -0
- package/dist/local-virtual-computer/setup/run.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/run.js +200 -0
- package/dist/local-virtual-computer/setup/run.js.map +1 -0
- package/dist/local-virtual-computer/setup/windows-folder.d.ts +11 -0
- package/dist/local-virtual-computer/setup/windows-folder.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/windows-folder.js +14 -0
- package/dist/local-virtual-computer/setup/windows-folder.js.map +1 -0
- package/dist/local-virtual-computer/setup/wsl-package.d.ts +19 -0
- package/dist/local-virtual-computer/setup/wsl-package.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/wsl-package.js +242 -0
- package/dist/local-virtual-computer/setup/wsl-package.js.map +1 -0
- package/dist/local-virtual-computer/setup/wslc-shared.d.ts +27 -0
- package/dist/local-virtual-computer/setup/wslc-shared.d.ts.map +1 -0
- package/dist/local-virtual-computer/setup/wslc-shared.js +137 -0
- package/dist/local-virtual-computer/setup/wslc-shared.js.map +1 -0
- package/dist/local-virtual-computer/ssh-forward.d.ts +19 -0
- package/dist/local-virtual-computer/ssh-forward.d.ts.map +1 -0
- package/dist/local-virtual-computer/ssh-forward.js +179 -0
- package/dist/local-virtual-computer/ssh-forward.js.map +1 -0
- package/dist/local-virtual-computer/wslc-engine.d.ts +27 -0
- package/dist/local-virtual-computer/wslc-engine.d.ts.map +1 -0
- package/dist/local-virtual-computer/wslc-engine.js +98 -0
- package/dist/local-virtual-computer/wslc-engine.js.map +1 -0
- package/local-computer/Dockerfile +99 -0
- package/local-computer/app-catalog.cjs +240 -0
- package/local-computer/app-native-host.cjs +144 -0
- package/local-computer/browser-home.cjs +249 -0
- package/local-computer/build-image.mjs +310 -0
- package/local-computer/desktop-worker.cjs +477 -0
- package/local-computer/entrypoint.sh +161 -0
- package/local-computer/home.html +28 -0
- package/local-computer/new-tab/home.css +255 -0
- package/local-computer/new-tab/home.js +65 -0
- package/local-computer/new-tab/manifest.json +12 -0
- package/local-computer/new-tab/wordmark.svg +33 -0
- package/local-computer/openbox-rc.xml +41 -0
- package/local-computer/prepare-home.cjs +121 -0
- package/local-computer/tint2rc +44 -0
- package/package.json +13 -4
- package/src/backends/http-worker-client.ts +31 -3
- package/src/index.ts +13 -0
- package/src/local-virtual-computer/client.ts +573 -0
- package/src/local-virtual-computer/detached-process.ts +133 -0
- package/src/local-virtual-computer/detached-worker.ts +124 -0
- package/src/local-virtual-computer/dialect.ts +83 -0
- package/src/local-virtual-computer/engine.ts +197 -0
- package/src/local-virtual-computer/guest-stdio.ts +332 -0
- package/src/local-virtual-computer/index.ts +447 -0
- package/src/local-virtual-computer/podman-machine.ts +264 -0
- package/src/local-virtual-computer/setup/contract.ts +395 -0
- package/src/local-virtual-computer/setup/elevated.ts +655 -0
- package/src/local-virtual-computer/setup/host.ts +100 -0
- package/src/local-virtual-computer/setup/idle.ts +39 -0
- package/src/local-virtual-computer/setup/image.ts +159 -0
- package/src/local-virtual-computer/setup/index.ts +16 -0
- package/src/local-virtual-computer/setup/limits.ts +68 -0
- package/src/local-virtual-computer/setup/plan.ts +144 -0
- package/src/local-virtual-computer/setup/readiness.ts +386 -0
- package/src/local-virtual-computer/setup/registry.ts +50 -0
- package/src/local-virtual-computer/setup/restart.ts +64 -0
- package/src/local-virtual-computer/setup/resume.ts +65 -0
- package/src/local-virtual-computer/setup/run.ts +225 -0
- package/src/local-virtual-computer/setup/windows-folder.ts +13 -0
- package/src/local-virtual-computer/setup/wsl-package.ts +242 -0
- package/src/local-virtual-computer/setup/wslc-shared.ts +147 -0
- package/src/local-virtual-computer/ssh-forward.ts +195 -0
- package/src/local-virtual-computer/wslc-engine.ts +124 -0
- package/worker/server.js +1499 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { createHash, randomBytes, randomUUID } from 'node:crypto';
|
|
2
|
+
import { OperationDeadline } from '../backends/readiness.js';
|
|
3
|
+
import { localComputerClients } from './client.js';
|
|
4
|
+
import { containerIdQuery, ensureVolume, hardeningFlags, parsePublishedPorts, portsQuery, resourceFlags, } from './dialect.js';
|
|
5
|
+
import { LocalCommandError, LocalComputerSetupError, resolveLocalEngine, } from './engine.js';
|
|
6
|
+
import { resolveLocalPodmanEngine } from './podman-machine.js';
|
|
7
|
+
import { LocalForwardCleanupError } from './ssh-forward.js';
|
|
8
|
+
import { mapWslcFailure, resolveLocalWslcEngine, wslcSetupError } from './wslc-engine.js';
|
|
9
|
+
export { LocalComputerSetupError, } from './engine.js';
|
|
10
|
+
export const LOCAL_COMPUTER_IMAGE = 'namzu-local-computer:1';
|
|
11
|
+
export const LOCAL_COMPUTER_PROTOCOL_LABEL = 'org.namzu.local-computer.protocol';
|
|
12
|
+
const OWNER_LABEL = 'org.namzu.pal.owner';
|
|
13
|
+
function dimension(value, fallback) {
|
|
14
|
+
const result = value ?? fallback;
|
|
15
|
+
if (!Number.isSafeInteger(result) || result < 320 || result > 3840)
|
|
16
|
+
throw new Error('The Pal display dimensions must be integers between 320 and 3840');
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
function ownerFor(palId) {
|
|
20
|
+
return createHash('sha256').update(palId).digest('hex');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* One readiness probe must not outlive its turn: a published-port relay can
|
|
24
|
+
* accept a connection before the guest listens and then never answer it.
|
|
25
|
+
*/
|
|
26
|
+
const READINESS_ATTEMPT_MS = 3000;
|
|
27
|
+
async function verifyImage(engine, image, signal) {
|
|
28
|
+
let images;
|
|
29
|
+
try {
|
|
30
|
+
images = JSON.parse(await engine.run(['image', 'inspect', image], { signal }));
|
|
31
|
+
if (engine.dialect === 'wslc' && images.length === 0)
|
|
32
|
+
throw wslcSetupError('image-missing');
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
signal?.throwIfAborted();
|
|
36
|
+
if (engine.dialect === 'wslc') {
|
|
37
|
+
if (error instanceof LocalComputerSetupError)
|
|
38
|
+
throw error;
|
|
39
|
+
// A missing image makes `image inspect` exit non-zero carrying either
|
|
40
|
+
// the not-found code or no code at all (observed on wslc 3.0.1). Any
|
|
41
|
+
// other code (an HRESULT, a spawn errno) or a non-command failure
|
|
42
|
+
// surfaces as itself, so a crash is not mistaken for missing setup.
|
|
43
|
+
const mapped = mapWslcFailure(error);
|
|
44
|
+
if (mapped)
|
|
45
|
+
throw mapped;
|
|
46
|
+
if (error instanceof LocalCommandError &&
|
|
47
|
+
(error.errorCodes.length === 0 || error.errorCodes.includes('WSLC_E_IMAGE_NOT_FOUND')))
|
|
48
|
+
throw wslcSetupError('image-missing', error);
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
throw new LocalComputerSetupError(`The ${image} image is not installed on this local engine. Build packages/sandbox/local-computer/Dockerfile explicitly; Namzu does not pull or build it automatically.`);
|
|
52
|
+
}
|
|
53
|
+
if (images[0]?.Os !== 'linux' ||
|
|
54
|
+
images[0]?.Config?.Labels?.[LOCAL_COMPUTER_PROTOCOL_LABEL] !== '1' ||
|
|
55
|
+
images[0]?.Config?.User !== '1001:1001')
|
|
56
|
+
throw new LocalComputerSetupError('The local Pal computer image must declare the Namzu desktop protocol and non-root guest user; rebuild the shipped Dockerfile');
|
|
57
|
+
}
|
|
58
|
+
function portFor(ports, port) {
|
|
59
|
+
const mappings = ports[`${port}/tcp`];
|
|
60
|
+
if (!mappings || mappings.length !== 1 || mappings[0]?.HostIp !== '127.0.0.1')
|
|
61
|
+
throw new Error('The Pal computer control port must be published on IPv4 loopback only');
|
|
62
|
+
const result = Number(mappings[0].HostPort);
|
|
63
|
+
if (!Number.isSafeInteger(result) || result < 1 || result > 65535)
|
|
64
|
+
throw new Error('The Pal computer control port was not allocated');
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A separate guest desktop in a local Linux container. It does not provision
|
|
69
|
+
* a dedicated-kernel VM and never falls back to the operator's desktop.
|
|
70
|
+
*/
|
|
71
|
+
export function createLocalVirtualComputerProvider(options = {}) {
|
|
72
|
+
if (options.engine !== undefined &&
|
|
73
|
+
options.engine !== 'docker' &&
|
|
74
|
+
options.engine !== 'podman' &&
|
|
75
|
+
options.engine !== 'wslc')
|
|
76
|
+
throw new Error('Choose the Docker, Podman or wslc local computer engine');
|
|
77
|
+
const image = options.image ?? LOCAL_COMPUTER_IMAGE;
|
|
78
|
+
const normalExitPolicy = options.normalExitPolicy ?? 'computer-lifetime';
|
|
79
|
+
if (normalExitPolicy !== 'strict' && normalExitPolicy !== 'computer-lifetime')
|
|
80
|
+
throw new Error('Choose strict or computer-lifetime foreground execution ownership');
|
|
81
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9_./:@-]*$/.test(image))
|
|
82
|
+
throw new Error('Invalid local Pal image reference');
|
|
83
|
+
const width = dimension(options.width, 1280);
|
|
84
|
+
const height = dimension(options.height, 800);
|
|
85
|
+
const timeout = options.readyTimeoutMs ?? 60_000;
|
|
86
|
+
if (!Number.isSafeInteger(timeout) || timeout <= 0 || timeout > 2_147_483_647)
|
|
87
|
+
throw new Error('Invalid Pal computer readiness timeout');
|
|
88
|
+
const holders = new Set();
|
|
89
|
+
const pendingCleanup = new Map();
|
|
90
|
+
let generation = 0;
|
|
91
|
+
const prepare = async (signal) => {
|
|
92
|
+
const engine = options.engine === 'podman'
|
|
93
|
+
? await resolveLocalPodmanEngine(options, signal)
|
|
94
|
+
: options.engine === 'wslc'
|
|
95
|
+
? await resolveLocalWslcEngine(options, signal)
|
|
96
|
+
: await resolveLocalEngine(options, signal);
|
|
97
|
+
await verifyImage(engine, image, signal);
|
|
98
|
+
return engine;
|
|
99
|
+
};
|
|
100
|
+
const dialectOf = (engine) => engine.dialect ?? options.engine ?? 'docker';
|
|
101
|
+
return {
|
|
102
|
+
async probe() {
|
|
103
|
+
try {
|
|
104
|
+
await new OperationDeadline(timeout, 'local Pal computer probe').run(async (signal) => await prepare(signal));
|
|
105
|
+
return { ready: true };
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
return {
|
|
109
|
+
ready: false,
|
|
110
|
+
// The code lets an application choose its words by what failed, not
|
|
111
|
+
// by matching the message. A failure that is not a setup error (a
|
|
112
|
+
// timeout, say) carries no code: it is not known to be fixable by setup.
|
|
113
|
+
setupCode: error instanceof LocalComputerSetupError ? error.code : undefined,
|
|
114
|
+
reason: error instanceof LocalComputerSetupError
|
|
115
|
+
? error.message
|
|
116
|
+
: options.engine === 'wslc'
|
|
117
|
+
? 'Linux container support and the Pal computer image are required. Namzu sets them up; finish the setup from the Pal computer and try again.'
|
|
118
|
+
: `A local ${options.engine === 'podman' ? 'Podman machine' : 'Docker engine'} running Linux containers and the ${image} image are required. Build packages/sandbox/local-computer/Dockerfile explicitly; Namzu does not install or pull it automatically.`,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
async acquire(request) {
|
|
123
|
+
request.signal?.throwIfAborted();
|
|
124
|
+
if (request.pal.paused)
|
|
125
|
+
throw new Error('This Pal is paused');
|
|
126
|
+
if (!request.pal.id || !request.conversationId)
|
|
127
|
+
throw new Error('A Pal and conversation identity are required');
|
|
128
|
+
const owner = ownerFor(request.pal.id);
|
|
129
|
+
if (holders.has(owner)) {
|
|
130
|
+
const cleanup = pendingCleanup.get(owner);
|
|
131
|
+
if (!cleanup)
|
|
132
|
+
throw new Error('This Pal computer is already in use');
|
|
133
|
+
try {
|
|
134
|
+
await new OperationDeadline(timeout, 'local Pal computer recovery', request.signal).run(async (signal) => await cleanup(signal));
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
throw new Error('This Pal computer is already in use by an unconfirmed allocation; cleanup recovery is still required');
|
|
138
|
+
}
|
|
139
|
+
pendingCleanup.delete(owner);
|
|
140
|
+
holders.delete(owner);
|
|
141
|
+
}
|
|
142
|
+
holders.add(owner);
|
|
143
|
+
const name = `namzu-pal-${owner.slice(0, 24)}`;
|
|
144
|
+
const volume = `namzu-pal-data-${owner}`;
|
|
145
|
+
const environmentId = `local-container:${owner}`;
|
|
146
|
+
const token = randomBytes(32).toString('base64url');
|
|
147
|
+
const allocationId = randomUUID();
|
|
148
|
+
generation = Math.max(Date.now(), generation + 1);
|
|
149
|
+
const leaseGeneration = generation;
|
|
150
|
+
let engine;
|
|
151
|
+
let created = false;
|
|
152
|
+
let runAttempted = false;
|
|
153
|
+
let containerId;
|
|
154
|
+
let forwarding;
|
|
155
|
+
let clients;
|
|
156
|
+
const stop = async (signal) => {
|
|
157
|
+
if (!engine)
|
|
158
|
+
return;
|
|
159
|
+
// Only the name we successfully created is removed. No volume is
|
|
160
|
+
// deleted; profile/files survive the next allocation.
|
|
161
|
+
if (created) {
|
|
162
|
+
// Commit the browser profile before removing this allocation.
|
|
163
|
+
// Forced removal remains the recovery path if graceful stop fails.
|
|
164
|
+
try {
|
|
165
|
+
await engine.run(['stop', '--time', '10', containerId ?? name], { signal });
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
signal?.throwIfAborted();
|
|
169
|
+
}
|
|
170
|
+
await engine.run(['rm', '-f', containerId ?? name], { signal });
|
|
171
|
+
created = false;
|
|
172
|
+
}
|
|
173
|
+
await forwarding?.close();
|
|
174
|
+
holders.delete(owner);
|
|
175
|
+
};
|
|
176
|
+
try {
|
|
177
|
+
const deadline = new OperationDeadline(timeout, 'local Pal computer startup', request.signal);
|
|
178
|
+
const connected = await deadline.run(async (signal) => {
|
|
179
|
+
engine = await prepare(signal);
|
|
180
|
+
const dialect = dialectOf(engine);
|
|
181
|
+
const occupied = await engine.run(containerIdQuery(dialect, `name=^/${name}$`, { full: false }), { signal });
|
|
182
|
+
if (occupied.trim())
|
|
183
|
+
throw new Error('An earlier Pal computer allocation still exists; stop it explicitly before reconnecting');
|
|
184
|
+
await ensureVolume(engine, dialect, volume, `${OWNER_LABEL}=${owner}`, signal);
|
|
185
|
+
const volumes = JSON.parse(await engine.run(['volume', 'inspect', volume], { signal }));
|
|
186
|
+
if (volumes[0]?.Labels?.[OWNER_LABEL] !== owner)
|
|
187
|
+
throw new Error('The Pal data volume belongs to a different owner');
|
|
188
|
+
runAttempted = true;
|
|
189
|
+
const started = await engine.run([
|
|
190
|
+
'run',
|
|
191
|
+
'--detach',
|
|
192
|
+
'--pull=never',
|
|
193
|
+
// WSL machines can lack delegated cgroup controllers.
|
|
194
|
+
// This adapter provides no per-container resource quotas.
|
|
195
|
+
...resourceFlags(dialect),
|
|
196
|
+
'--name',
|
|
197
|
+
name,
|
|
198
|
+
'--label',
|
|
199
|
+
`${OWNER_LABEL}=${owner}`,
|
|
200
|
+
'--label',
|
|
201
|
+
`org.namzu.pal.generation=${leaseGeneration}`,
|
|
202
|
+
'--label',
|
|
203
|
+
`org.namzu.pal.allocation=${allocationId}`,
|
|
204
|
+
'--user',
|
|
205
|
+
'1001:1001',
|
|
206
|
+
...hardeningFlags(dialect),
|
|
207
|
+
'--network=bridge',
|
|
208
|
+
'--shm-size=256m',
|
|
209
|
+
'--tmpfs',
|
|
210
|
+
'/tmp:rw,nosuid,nodev,size=512m,mode=1777',
|
|
211
|
+
'--tmpfs',
|
|
212
|
+
'/run:rw,nosuid,nodev,size=16m,mode=1777',
|
|
213
|
+
'--mount',
|
|
214
|
+
`type=volume,source=${volume},target=/home/namzu`,
|
|
215
|
+
'--publish',
|
|
216
|
+
'127.0.0.1::2024',
|
|
217
|
+
'--publish',
|
|
218
|
+
'127.0.0.1::2025',
|
|
219
|
+
'--env',
|
|
220
|
+
`NAMZU_SANDBOX_SCREEN_WIDTH=${width}`,
|
|
221
|
+
'--env',
|
|
222
|
+
`NAMZU_SANDBOX_SCREEN_HEIGHT=${height}`,
|
|
223
|
+
'--env',
|
|
224
|
+
'NAMZU_SANDBOX_TOKEN',
|
|
225
|
+
image,
|
|
226
|
+
], { signal, env: { NAMZU_SANDBOX_TOKEN: token } });
|
|
227
|
+
created = true;
|
|
228
|
+
containerId = started.trim();
|
|
229
|
+
if (!/^[0-9a-f]{64}$/.test(containerId))
|
|
230
|
+
throw new Error('The Pal computer engine did not return a valid allocation identifier');
|
|
231
|
+
const ports = parsePublishedPorts(dialect, await engine.run(portsQuery(dialect, name), { signal }));
|
|
232
|
+
const guestPorts = [portFor(ports, 2024), portFor(ports, 2025)];
|
|
233
|
+
forwarding = await engine.forwardPorts?.(guestPorts, {
|
|
234
|
+
signal,
|
|
235
|
+
onLost() {
|
|
236
|
+
void clients?.sandbox.destroy().catch(() => {
|
|
237
|
+
// Destroy fences calls first; its retained lease can retry recovery.
|
|
238
|
+
});
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
const localPorts = forwarding?.ports ?? guestPorts;
|
|
242
|
+
const executionUrl = `http://127.0.0.1:${localPorts[0]}`;
|
|
243
|
+
const desktopUrl = `http://127.0.0.1:${localPorts[1]}`;
|
|
244
|
+
for (;;) {
|
|
245
|
+
signal.throwIfAborted();
|
|
246
|
+
forwarding?.assertAlive();
|
|
247
|
+
const attempt = new AbortController();
|
|
248
|
+
const attemptTimer = setTimeout(() => attempt.abort(), READINESS_ATTEMPT_MS);
|
|
249
|
+
const attemptSignal = AbortSignal.any([signal, attempt.signal]);
|
|
250
|
+
try {
|
|
251
|
+
const response = await fetch(`${desktopUrl}/readyz`, {
|
|
252
|
+
headers: { authorization: `Bearer ${token}` },
|
|
253
|
+
signal: attemptSignal,
|
|
254
|
+
});
|
|
255
|
+
const desktop = response.ok
|
|
256
|
+
? (await response.json())
|
|
257
|
+
: undefined;
|
|
258
|
+
const execution = await fetch(`${executionUrl}/healthz`, { signal: attemptSignal });
|
|
259
|
+
const worker = execution.ok
|
|
260
|
+
? (await execution.json())
|
|
261
|
+
: undefined;
|
|
262
|
+
if (desktop?.protocol === 1 &&
|
|
263
|
+
desktop.width === width &&
|
|
264
|
+
desktop.height === height &&
|
|
265
|
+
desktop.browserReady === true &&
|
|
266
|
+
worker?.protocolVersion === 2)
|
|
267
|
+
return {
|
|
268
|
+
executionUrl,
|
|
269
|
+
desktopUrl,
|
|
270
|
+
screenStream: desktop.stream?.protocol === 'rfb',
|
|
271
|
+
heldKeyboard: desktop.heldKeyboard?.version === 1,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
signal.throwIfAborted();
|
|
276
|
+
}
|
|
277
|
+
finally {
|
|
278
|
+
clearTimeout(attemptTimer);
|
|
279
|
+
}
|
|
280
|
+
await new Promise((resolve, reject) => {
|
|
281
|
+
const timer = setTimeout(() => {
|
|
282
|
+
signal.removeEventListener('abort', abort);
|
|
283
|
+
resolve();
|
|
284
|
+
}, 200);
|
|
285
|
+
const abort = () => {
|
|
286
|
+
clearTimeout(timer);
|
|
287
|
+
reject(signal.reason);
|
|
288
|
+
};
|
|
289
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
request.signal?.throwIfAborted();
|
|
294
|
+
clients = localComputerClients({
|
|
295
|
+
...connected,
|
|
296
|
+
normalExitPolicy,
|
|
297
|
+
token,
|
|
298
|
+
geometry: { width, height, scaleFactor: 1 },
|
|
299
|
+
stop,
|
|
300
|
+
});
|
|
301
|
+
const admitted = clients;
|
|
302
|
+
return {
|
|
303
|
+
palId: request.pal.id,
|
|
304
|
+
environmentId,
|
|
305
|
+
generation: leaseGeneration,
|
|
306
|
+
...admitted,
|
|
307
|
+
release: () => admitted.sandbox.destroy(),
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
if (error instanceof LocalForwardCleanupError)
|
|
312
|
+
forwarding = error.forward;
|
|
313
|
+
if (runAttempted && engine) {
|
|
314
|
+
const ownedEngine = engine;
|
|
315
|
+
const cleanup = async (signal) => {
|
|
316
|
+
// Reconcile an unacknowledged start by this attempt's unique
|
|
317
|
+
// label, never by a name another process may have acquired.
|
|
318
|
+
const owned = await ownedEngine.run(containerIdQuery(dialectOf(ownedEngine), `label=org.namzu.pal.allocation=${allocationId}`, { full: true }), { signal });
|
|
319
|
+
for (const id of owned.trim().split(/\s+/).filter(Boolean)) {
|
|
320
|
+
if (!/^[0-9a-f]{64}$/.test(id))
|
|
321
|
+
throw new Error('Invalid owned allocation identifier');
|
|
322
|
+
await ownedEngine.run(['rm', '-f', id], { signal });
|
|
323
|
+
}
|
|
324
|
+
created = false;
|
|
325
|
+
await forwarding?.close();
|
|
326
|
+
};
|
|
327
|
+
try {
|
|
328
|
+
await new OperationDeadline(timeout, 'local Pal computer cleanup').run(async (signal) => await cleanup(signal));
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
pendingCleanup.set(owner, cleanup);
|
|
332
|
+
throw new Error('Pal computer startup failed and cleanup could not be confirmed; the owned allocation requires operator recovery', { cause: error });
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
holders.delete(owner);
|
|
336
|
+
throw error;
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/local-virtual-computer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAEjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EACN,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,aAAa,GACb,MAAM,cAAc,CAAA;AACrB,OAAO,EAEN,iBAAiB,EAEjB,uBAAuB,EAGvB,kBAAkB,GAClB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAGzF,OAAO,EAEN,uBAAuB,GAEvB,MAAM,aAAa,CAAA;AAEpB,MAAM,CAAC,MAAM,oBAAoB,GAAG,wBAAwB,CAAA;AAC5D,MAAM,CAAC,MAAM,6BAA6B,GAAG,mCAAmC,CAAA;AAChF,MAAM,WAAW,GAAG,qBAAqB,CAAA;AA2BzC,SAAS,SAAS,CAAC,KAAyB,EAAE,QAAgB;IAC7D,MAAM,MAAM,GAAG,KAAK,IAAI,QAAQ,CAAA;IAChC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,GAAG,IAAI,MAAM,GAAG,IAAI;QACjE,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAA;IACpF,OAAO,MAAM,CAAA;AACd,CAAC;A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K,CAAC,CAAA;gBACrB,MAAM,KAAK,CAAA;YACZ,CAAC;QACF,CAAC;KACD,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type LocalComputerCommandRunner, type LocalEngine } from './engine.js';
|
|
2
|
+
interface PodmanMachineOptions {
|
|
3
|
+
readonly podmanBinary?: string;
|
|
4
|
+
readonly podmanMachine?: string;
|
|
5
|
+
readonly podmanConnection?: string;
|
|
6
|
+
readonly engineEndpoint?: string;
|
|
7
|
+
readonly runner?: LocalComputerCommandRunner;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Admit only a registered Windows WSL Podman machine. Its SSH connection is a
|
|
11
|
+
* local machine transport, not permission to select an arbitrary remote daemon.
|
|
12
|
+
* Capture its verified URL and identity so later named-connection edits cannot
|
|
13
|
+
* redirect an allocation. Never start, initialize or configure the machine.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveLocalPodmanEngine(options: PodmanMachineOptions, signal?: AbortSignal, platform?: NodeJS.Platform): Promise<LocalEngine>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=podman-machine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"podman-machine.d.ts","sourceRoot":"","sources":["../../src/local-virtual-computer/podman-machine.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,KAAK,0BAA0B,EAE/B,KAAK,WAAW,EAEhB,MAAM,aAAa,CAAA;AAGpB,UAAU,oBAAoB;IAC7B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAClC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,0BAA0B,CAAA;CAC5C;AAiCD;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC7C,OAAO,EAAE,oBAAoB,EAC7B,MAAM,CAAC,EAAE,WAAW,EACpB,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC1C,OAAO,CAAC,WAAW,CAAC,CA2MtB"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { lstat, realpath } from 'node:fs/promises';
|
|
2
|
+
import { createConnection } from 'node:net';
|
|
3
|
+
import { win32 } from 'node:path';
|
|
4
|
+
import { LocalComputerSetupError, nodeCommandRunner, } from './engine.js';
|
|
5
|
+
import { startLocalSshForward } from './ssh-forward.js';
|
|
6
|
+
async function confirmLocalPipe(path, signal) {
|
|
7
|
+
signal?.throwIfAborted();
|
|
8
|
+
await new Promise((resolve, reject) => {
|
|
9
|
+
const socket = createConnection(path);
|
|
10
|
+
const abort = () => {
|
|
11
|
+
socket.destroy();
|
|
12
|
+
reject(signal?.reason);
|
|
13
|
+
};
|
|
14
|
+
const finish = (error) => {
|
|
15
|
+
signal?.removeEventListener('abort', abort);
|
|
16
|
+
socket.destroy();
|
|
17
|
+
if (error)
|
|
18
|
+
reject(new LocalComputerSetupError('The selected local Podman machine pipe is unavailable; start that machine explicitly'));
|
|
19
|
+
else
|
|
20
|
+
resolve();
|
|
21
|
+
};
|
|
22
|
+
socket.once('connect', () => finish());
|
|
23
|
+
socket.once('error', finish);
|
|
24
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
25
|
+
if (signal?.aborted)
|
|
26
|
+
abort();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function insideProfile(path, profile) {
|
|
30
|
+
const relative = win32.relative(profile, path);
|
|
31
|
+
return !win32.isAbsolute(relative) && relative !== '..' && !relative.startsWith('..\\');
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Admit only a registered Windows WSL Podman machine. Its SSH connection is a
|
|
35
|
+
* local machine transport, not permission to select an arbitrary remote daemon.
|
|
36
|
+
* Capture its verified URL and identity so later named-connection edits cannot
|
|
37
|
+
* redirect an allocation. Never start, initialize or configure the machine.
|
|
38
|
+
*/
|
|
39
|
+
export async function resolveLocalPodmanEngine(options, signal, platform = process.platform) {
|
|
40
|
+
if (platform !== 'win32')
|
|
41
|
+
throw new LocalComputerSetupError('The Podman computer adapter requires a locally registered Windows WSL machine');
|
|
42
|
+
const machineName = options.podmanMachine;
|
|
43
|
+
const connectionName = options.podmanConnection;
|
|
44
|
+
if (!machineName ||
|
|
45
|
+
!connectionName ||
|
|
46
|
+
!/^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}$/.test(machineName) ||
|
|
47
|
+
!/^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}$/.test(connectionName))
|
|
48
|
+
throw new LocalComputerSetupError('Select an existing Podman machine and its registered connection explicitly');
|
|
49
|
+
if (options.engineEndpoint)
|
|
50
|
+
throw new LocalComputerSetupError('Podman machine transport is verified from local registration; an arbitrary engine endpoint is refused');
|
|
51
|
+
const selectedBinary = options.podmanBinary ?? 'podman';
|
|
52
|
+
const binary = /[\\/]|^[a-zA-Z]:/.test(selectedBinary)
|
|
53
|
+
? win32.resolve(process.cwd(), selectedBinary)
|
|
54
|
+
: selectedBinary;
|
|
55
|
+
// Native Podman probes /proc/self/uid_map even in remote mode. A WSL UNC
|
|
56
|
+
// caller directory produces ERROR_DIRECTORY rather than a missing file,
|
|
57
|
+
// which Podman treats as fatal. Pin this transport to a native directory
|
|
58
|
+
// without changing the embedding application's working directory.
|
|
59
|
+
const profile = process.env.USERPROFILE;
|
|
60
|
+
if (!profile || !/^[a-zA-Z]:[\\/]/.test(profile))
|
|
61
|
+
throw new LocalComputerSetupError('The Podman machine requires an existing native Windows operator profile directory');
|
|
62
|
+
const realProfile = await realpath(profile);
|
|
63
|
+
if (!/^[a-zA-Z]:[\\/]/.test(realProfile) || !(await lstat(realProfile)).isDirectory())
|
|
64
|
+
throw new LocalComputerSetupError('The Podman machine requires an existing native Windows operator profile directory');
|
|
65
|
+
const runner = options.runner ?? nodeCommandRunner;
|
|
66
|
+
const machines = JSON.parse(await runner.run(binary, ['machine', 'list', '--format', 'json'], {
|
|
67
|
+
signal,
|
|
68
|
+
cwd: realProfile,
|
|
69
|
+
}));
|
|
70
|
+
if (machines.find((machine) => machine.Name === machineName)?.VMType !== 'wsl')
|
|
71
|
+
throw new LocalComputerSetupError('The selected Podman machine must be registered locally with the Windows WSL provider');
|
|
72
|
+
const inspected = JSON.parse(await runner.run(binary, ['machine', 'inspect', machineName, '--format', '{{json .}}'], {
|
|
73
|
+
signal,
|
|
74
|
+
cwd: realProfile,
|
|
75
|
+
}));
|
|
76
|
+
if (inspected.Name !== machineName || inspected.State !== 'running')
|
|
77
|
+
throw new LocalComputerSetupError('The selected Podman machine is stopped or unavailable; start it explicitly');
|
|
78
|
+
const registrations = await runner.run(win32.join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'wsl.exe'), ['--list', '--quiet'], { signal, cwd: realProfile });
|
|
79
|
+
if (!registrations
|
|
80
|
+
.split(/\r?\n/)
|
|
81
|
+
.some((name) => name.trim().toLowerCase() === machineName.toLowerCase()))
|
|
82
|
+
throw new LocalComputerSetupError('The selected Podman machine is not a registered local WSL distribution');
|
|
83
|
+
const pipe = inspected.ConnectionInfo?.PodmanPipe?.Path;
|
|
84
|
+
if (pipe !== `\\\\.\\pipe\\${machineName}`)
|
|
85
|
+
throw new LocalComputerSetupError('The Podman machine must own its matching local Windows named pipe');
|
|
86
|
+
const identity = inspected.SSHConfig?.IdentityPath;
|
|
87
|
+
const configDir = inspected.ConfigDir?.Path;
|
|
88
|
+
if (!identity || !configDir || !win32.isAbsolute(identity) || !win32.isAbsolute(configDir))
|
|
89
|
+
throw new LocalComputerSetupError('The Podman machine must belong to the current Windows operator profile');
|
|
90
|
+
const [realIdentity, realConfig] = await Promise.all([
|
|
91
|
+
realpath(win32.normalize(identity)),
|
|
92
|
+
realpath(win32.normalize(configDir)),
|
|
93
|
+
]);
|
|
94
|
+
if (!insideProfile(realIdentity, realProfile) ||
|
|
95
|
+
!insideProfile(realConfig, realProfile) ||
|
|
96
|
+
!(await lstat(realIdentity)).isFile())
|
|
97
|
+
throw new LocalComputerSetupError('The Podman machine identity and configuration must remain inside the current Windows operator profile');
|
|
98
|
+
const connections = JSON.parse(await runner.run(binary, ['system', 'connection', 'list', '--format', 'json'], {
|
|
99
|
+
signal,
|
|
100
|
+
cwd: realProfile,
|
|
101
|
+
}));
|
|
102
|
+
const connection = connections.find((candidate) => candidate.Name === connectionName);
|
|
103
|
+
let url;
|
|
104
|
+
try {
|
|
105
|
+
url = new URL(connection?.URI ?? '');
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
throw new LocalComputerSetupError('The selected Podman machine connection is invalid');
|
|
109
|
+
}
|
|
110
|
+
const expectedUser = inspected.Rootful ? 'root' : inspected.SSHConfig?.RemoteUsername;
|
|
111
|
+
const port = inspected.SSHConfig?.Port;
|
|
112
|
+
if (!connection?.IsMachine ||
|
|
113
|
+
connection.ReadWrite !== true ||
|
|
114
|
+
!connection.Identity ||
|
|
115
|
+
win32.normalize(connection.Identity).toLowerCase() !==
|
|
116
|
+
win32.normalize(realIdentity).toLowerCase() ||
|
|
117
|
+
!Number.isSafeInteger(port) ||
|
|
118
|
+
Number(port) < 1 ||
|
|
119
|
+
Number(port) > 65535 ||
|
|
120
|
+
url.protocol !== 'ssh:' ||
|
|
121
|
+
url.hostname !== '127.0.0.1' ||
|
|
122
|
+
Number(url.port) !== port ||
|
|
123
|
+
!expectedUser ||
|
|
124
|
+
url.username !== expectedUser ||
|
|
125
|
+
url.password ||
|
|
126
|
+
url.search ||
|
|
127
|
+
url.hash ||
|
|
128
|
+
(inspected.Rootful
|
|
129
|
+
? url.pathname !== '/run/podman/podman.sock'
|
|
130
|
+
: !/^\/run\/user\/\d+\/podman\/podman\.sock$/.test(url.pathname)))
|
|
131
|
+
throw new LocalComputerSetupError('The Podman connection must match the selected local WSL machine identity, port, user and socket; remote connections are refused');
|
|
132
|
+
await confirmLocalPipe(pipe, signal);
|
|
133
|
+
const endpoint = `npipe:////./pipe/${machineName}`;
|
|
134
|
+
const run = (args, call) => {
|
|
135
|
+
const env = { ...process.env, ...call?.env };
|
|
136
|
+
for (const name of [
|
|
137
|
+
'CONTAINER_HOST',
|
|
138
|
+
'CONTAINER_CONNECTION',
|
|
139
|
+
'CONTAINER_SSHKEY',
|
|
140
|
+
'DOCKER_HOST',
|
|
141
|
+
'DOCKER_CONTEXT',
|
|
142
|
+
])
|
|
143
|
+
env[name] = undefined;
|
|
144
|
+
return runner.run(binary, ['--url', url.href, '--identity', realIdentity, ...args], {
|
|
145
|
+
...call,
|
|
146
|
+
env,
|
|
147
|
+
cwd: realProfile,
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
const info = JSON.parse(await run(['info', '--format', 'json'], { signal }));
|
|
151
|
+
if (info.host?.os !== 'linux')
|
|
152
|
+
throw new LocalComputerSetupError('The selected local Podman machine must run Linux containers');
|
|
153
|
+
return {
|
|
154
|
+
endpoint,
|
|
155
|
+
run,
|
|
156
|
+
async forwardPorts(ports, call) {
|
|
157
|
+
const key = (await runner.run(win32.join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'wsl.exe'), [
|
|
158
|
+
'--distribution',
|
|
159
|
+
machineName,
|
|
160
|
+
'--user',
|
|
161
|
+
'root',
|
|
162
|
+
'--exec',
|
|
163
|
+
'cat',
|
|
164
|
+
'/etc/ssh/ssh_host_ed25519_key.pub',
|
|
165
|
+
], { signal: call.signal, cwd: realProfile }))
|
|
166
|
+
.trim()
|
|
167
|
+
.split(/\s+/)
|
|
168
|
+
.slice(0, 2)
|
|
169
|
+
.join(' ');
|
|
170
|
+
return await startLocalSshForward({
|
|
171
|
+
identity: realIdentity,
|
|
172
|
+
port: Number(port),
|
|
173
|
+
user: expectedUser,
|
|
174
|
+
hostPublicKey: key,
|
|
175
|
+
ports,
|
|
176
|
+
...call,
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=podman-machine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"podman-machine.js","sourceRoot":"","sources":["../../src/local-virtual-computer/podman-machine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AACjC,OAAO,EAEN,uBAAuB,EAEvB,iBAAiB,GACjB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAUvD,KAAK,UAAU,gBAAgB,CAAC,IAAY,EAAE,MAAoB;IACjE,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAA;QACrC,MAAM,KAAK,GAAG,GAAG,EAAE;YAClB,MAAM,CAAC,OAAO,EAAE,CAAA;YAChB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACvB,CAAC,CAAA;QACD,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,EAAE;YAChC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;YAC3C,MAAM,CAAC,OAAO,EAAE,CAAA;YAChB,IAAI,KAAK;gBACR,MAAM,CACL,IAAI,uBAAuB,CAC1B,sFAAsF,CACtF,CACD,CAAA;;gBACG,OAAO,EAAE,CAAA;QACf,CAAC,CAAA;QACD,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,CAAA;QACtC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QAC5B,MAAM,EAAE,gBAAgB,CAAC,OA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