@koed-labs/server 0.0.0-stage → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +64 -2
  3. package/bin/koed.js +7 -0
  4. package/package.json +26 -4
  5. package/third-party-notices.json +92 -0
  6. package/vendor/chunk-2XKSVKQA.js +49 -0
  7. package/vendor/chunk-4OO6VAU3.js +259 -0
  8. package/vendor/chunk-53ZFCDHP.js +332 -0
  9. package/vendor/chunk-6JRWGOQG.js +236 -0
  10. package/vendor/chunk-6KS67EQE.js +75 -0
  11. package/vendor/chunk-7EGSY3E4.js +8 -0
  12. package/vendor/chunk-7FSHVVTZ.js +128 -0
  13. package/vendor/chunk-7NOQSX4T.js +14 -0
  14. package/vendor/chunk-7NXKPDF3.js +1586 -0
  15. package/vendor/chunk-ALJUSOF7.js +175 -0
  16. package/vendor/chunk-AVQCUFYQ.js +16 -0
  17. package/vendor/chunk-BGENSONI.js +18 -0
  18. package/vendor/chunk-BTS4ZTF3.js +43 -0
  19. package/vendor/chunk-BUIM2M4R.js +22 -0
  20. package/vendor/chunk-C4V72GXC.js +194 -0
  21. package/vendor/chunk-C5SNDPAP.js +2472 -0
  22. package/vendor/chunk-CHMH4LH5.js +2497 -0
  23. package/vendor/chunk-EA4QDDQA.js +58 -0
  24. package/vendor/chunk-EDPNYIX5.js +5448 -0
  25. package/vendor/chunk-FN3HUUO2.js +1974 -0
  26. package/vendor/chunk-FSNLU46W.js +14548 -0
  27. package/vendor/chunk-FYYRFX4U.js +4423 -0
  28. package/vendor/chunk-GFASBPV2.js +42 -0
  29. package/vendor/chunk-HC76426R.js +48 -0
  30. package/vendor/chunk-IY2HRXOZ.js +99 -0
  31. package/vendor/chunk-JBGD4JLR.js +3779 -0
  32. package/vendor/chunk-JYK6UL6D.js +261 -0
  33. package/vendor/chunk-LRP66XEY.js +13907 -0
  34. package/vendor/chunk-NOU7RHYZ.js +26 -0
  35. package/vendor/chunk-NVTMIAAF.js +113 -0
  36. package/vendor/chunk-O7DW2VAV.js +14 -0
  37. package/vendor/chunk-OCILJ737.js +299 -0
  38. package/vendor/chunk-PL3LWC5C.js +754 -0
  39. package/vendor/chunk-QRKHHWJJ.js +104 -0
  40. package/vendor/chunk-QT24SAW6.js +110 -0
  41. package/vendor/chunk-RCR4XPE3.js +26020 -0
  42. package/vendor/chunk-SHLRINKO.js +73 -0
  43. package/vendor/chunk-SNKWETM5.js +35 -0
  44. package/vendor/chunk-SRKIBFOE.js +242 -0
  45. package/vendor/chunk-T6UB5PNX.js +124 -0
  46. package/vendor/chunk-TG26CZGQ.js +23 -0
  47. package/vendor/chunk-TISYUUEJ.js +188 -0
  48. package/vendor/chunk-TSAYTRX3.js +89 -0
  49. package/vendor/chunk-TVYEB2GN.js +343 -0
  50. package/vendor/chunk-UB6JCVQ3.js +461 -0
  51. package/vendor/chunk-V67IQB7H.js +153 -0
  52. package/vendor/chunk-VGIYSDNU.js +522 -0
  53. package/vendor/chunk-W2HNI6AA.js +75 -0
  54. package/vendor/chunk-W2OJZZ6X.js +20 -0
  55. package/vendor/chunk-WDFERJG3.js +2208 -0
  56. package/vendor/chunk-WPIEF4LY.js +1647 -0
  57. package/vendor/chunk-XIZVLPHZ.js +18 -0
  58. package/vendor/chunk-YZLQZU5E.js +46 -0
  59. package/vendor/chunk-Z5WCAUA6.js +148 -0
  60. package/vendor/chunk-ZIOKV2X6.js +1589 -0
  61. package/vendor/chunk-ZOHNXUDY.js +12501 -0
  62. package/vendor/chunk-ZUDSZGVO.js +11 -0
  63. package/vendor/cli.js +7 -0
  64. package/vendor/component-manifest-catalog.js +9 -0
  65. package/vendor/control-plane.js +28 -0
  66. package/vendor/package.json +1 -0
  67. package/vendor/privacy-service-bootstrap.js +6 -0
@@ -0,0 +1,26 @@
1
+ import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
+ import {
3
+ decryptRecoveryKit,
4
+ encryptRecoveryKit,
5
+ parseLoopbackOrigin,
6
+ personalSyncProviderEnvironment,
7
+ redeemPairingLink,
8
+ runPersonalSyncCommand
9
+ } from "./chunk-CHMH4LH5.js";
10
+ import "./chunk-EA4QDDQA.js";
11
+ import "./chunk-SRKIBFOE.js";
12
+ import "./chunk-TSAYTRX3.js";
13
+ import "./chunk-YZLQZU5E.js";
14
+ import "./chunk-W2HNI6AA.js";
15
+ import "./chunk-7NXKPDF3.js";
16
+ import "./chunk-ZOHNXUDY.js";
17
+ import "./chunk-FSNLU46W.js";
18
+ import "./chunk-BTS4ZTF3.js";
19
+ export {
20
+ decryptRecoveryKit,
21
+ encryptRecoveryKit,
22
+ parseLoopbackOrigin,
23
+ personalSyncProviderEnvironment,
24
+ redeemPairingLink,
25
+ runPersonalSyncCommand
26
+ };
@@ -0,0 +1,113 @@
1
+ import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
+ import {
3
+ checkCoreSetupNeeded,
4
+ createCliServiceContext,
5
+ deviceRequestCommand,
6
+ printJson
7
+ } from "./chunk-WDFERJG3.js";
8
+ import "./chunk-SHLRINKO.js";
9
+ import "./chunk-CHMH4LH5.js";
10
+ import "./chunk-EA4QDDQA.js";
11
+ import "./chunk-JYK6UL6D.js";
12
+ import "./chunk-WPIEF4LY.js";
13
+ import "./chunk-EDPNYIX5.js";
14
+ import "./chunk-QT24SAW6.js";
15
+ import "./chunk-TISYUUEJ.js";
16
+ import "./chunk-ALJUSOF7.js";
17
+ import "./chunk-SRKIBFOE.js";
18
+ import "./chunk-7FSHVVTZ.js";
19
+ import "./chunk-TSAYTRX3.js";
20
+ import "./chunk-YZLQZU5E.js";
21
+ import "./chunk-W2HNI6AA.js";
22
+ import "./chunk-V67IQB7H.js";
23
+ import "./chunk-FN3HUUO2.js";
24
+ import "./chunk-T6UB5PNX.js";
25
+ import "./chunk-7NXKPDF3.js";
26
+ import "./chunk-ZUDSZGVO.js";
27
+ import "./chunk-ZIOKV2X6.js";
28
+ import "./chunk-QRKHHWJJ.js";
29
+ import "./chunk-7EGSY3E4.js";
30
+ import "./chunk-IY2HRXOZ.js";
31
+ import "./chunk-4OO6VAU3.js";
32
+ import "./chunk-RCR4XPE3.js";
33
+ import "./chunk-ZOHNXUDY.js";
34
+ import "./chunk-FSNLU46W.js";
35
+ import "./chunk-BTS4ZTF3.js";
36
+
37
+ // packages/koed-server/dist/cli-pair-operations.js
38
+ var runPairCommand = async (subcommand, options, dependencies) => {
39
+ const { startDaemon, collectStartupStatus, resolvePaths, stdout, stderr } = createCliServiceContext(dependencies);
40
+ const deviceRequestCommand2 = dependencies.deviceRequest ?? deviceRequestCommand;
41
+ const wantsJson = options.json;
42
+ try {
43
+ const paths = resolvePaths();
44
+ const setupNeeded = checkCoreSetupNeeded(paths);
45
+ if (subcommand === "status" || subcommand === "cancel") {
46
+ const value = await deviceRequestCommand2(paths, subcommand);
47
+ if (wantsJson)
48
+ printJson(stdout, value);
49
+ else
50
+ stdout.write(`${value.state}
51
+ `);
52
+ return 0;
53
+ }
54
+ if (setupNeeded) {
55
+ stderr.write(`${setupNeeded}
56
+ `);
57
+ return 1;
58
+ }
59
+ let ready = await collectStartupStatus();
60
+ if (!ready.ok) {
61
+ const started = startDaemon();
62
+ if (!started.ok)
63
+ throw new Error(started.error ?? started.message);
64
+ for (let attempt = 0; attempt < 90 && !ready.ok; attempt += 1) {
65
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
66
+ ready = await collectStartupStatus();
67
+ }
68
+ }
69
+ if (!ready.ok)
70
+ throw new Error("Koed could not start. Run koed doctor for setup guidance.");
71
+ const initial = await deviceRequestCommand2(paths, "create", options.deviceLabel);
72
+ if (wantsJson)
73
+ printJson(stdout, initial);
74
+ else
75
+ stdout.write(initial.link ? `Paste this request into Devices \u2192 Add device on your existing Koed installation:
76
+
77
+ ${initial.link}
78
+
79
+ Expires ${initial.expiresAt}. Waiting for approval\u2026
80
+ ` : `Enrollment is ${initial.state}. Waiting\u2026
81
+ `);
82
+ if (options.detach)
83
+ return 0;
84
+ let previous = initial.state;
85
+ for (; ; ) {
86
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
87
+ const value = await deviceRequestCommand2(paths, "status");
88
+ if (value.state !== previous) {
89
+ if (wantsJson)
90
+ printJson(stdout, value);
91
+ else
92
+ stdout.write(`${value.state}
93
+ `);
94
+ previous = value.state;
95
+ }
96
+ if (value.state === "connected")
97
+ return 0;
98
+ if (["failed", "expired", "cancelled"].includes(value.state))
99
+ return 1;
100
+ }
101
+ } catch (error) {
102
+ const message = error instanceof Error ? error.message : String(error);
103
+ if (wantsJson)
104
+ printJson(stdout, { ok: false, error: message });
105
+ else
106
+ stderr.write(`${message}
107
+ `);
108
+ return 1;
109
+ }
110
+ };
111
+ export {
112
+ runPairCommand
113
+ };
@@ -0,0 +1,14 @@
1
+ import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
+ import {
3
+ checkCudaHost,
4
+ validateStagedCuda
5
+ } from "./chunk-TVYEB2GN.js";
6
+ import "./chunk-JYK6UL6D.js";
7
+ import "./chunk-QRKHHWJJ.js";
8
+ import "./chunk-7EGSY3E4.js";
9
+ import "./chunk-FSNLU46W.js";
10
+ import "./chunk-BTS4ZTF3.js";
11
+ export {
12
+ checkCudaHost,
13
+ validateStagedCuda
14
+ };
@@ -0,0 +1,299 @@
1
+ import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
+ import {
3
+ calculateRuntimeRequirements,
4
+ resolveEffectiveRuntimeConfig
5
+ } from "./chunk-SHLRINKO.js";
6
+ import "./chunk-ALJUSOF7.js";
7
+ import {
8
+ resolveKoedServerPaths
9
+ } from "./chunk-TSAYTRX3.js";
10
+ import "./chunk-YZLQZU5E.js";
11
+ import "./chunk-W2HNI6AA.js";
12
+ import {
13
+ resolveKoedAppRuntimeExecution,
14
+ resolveKoedControlPlaneVersion,
15
+ resolveKoedRuntimeOwner
16
+ } from "./chunk-V67IQB7H.js";
17
+ import {
18
+ activateGeneration,
19
+ cleanupGenerations,
20
+ discoverActualRuntimeIdentity,
21
+ readCurrentDesktopGeneration,
22
+ readCurrentDesktopGenerationOrderingEvidence,
23
+ readCurrentGeneration,
24
+ readCurrentGenerationOrderingEvidence,
25
+ readGenerationComponentPresence,
26
+ readStagedGeneration,
27
+ readStoredComponents,
28
+ resolveComponentManifestPinTarget,
29
+ stageComponent,
30
+ stageGeneration
31
+ } from "./chunk-FN3HUUO2.js";
32
+ import "./chunk-T6UB5PNX.js";
33
+ import "./chunk-7NXKPDF3.js";
34
+ import {
35
+ productionComponentManifestCatalog
36
+ } from "./chunk-ZUDSZGVO.js";
37
+ import "./chunk-ZIOKV2X6.js";
38
+ import "./chunk-QRKHHWJJ.js";
39
+ import "./chunk-7EGSY3E4.js";
40
+ import {
41
+ validateManifestCatalog
42
+ } from "./chunk-IY2HRXOZ.js";
43
+ import "./chunk-ZOHNXUDY.js";
44
+ import "./chunk-FSNLU46W.js";
45
+ import "./chunk-BTS4ZTF3.js";
46
+
47
+ // packages/koed-server/dist/cli-component-operations.js
48
+ import { existsSync as existsSync2 } from "node:fs";
49
+ import { resolve } from "node:path";
50
+
51
+ // packages/koed-server/dist/component-command-target.js
52
+ function resolveComponentCommandTarget(runtime, catalog) {
53
+ const host = {
54
+ platform: runtime.platform,
55
+ architecture: runtime.architecture
56
+ };
57
+ if (catalog === null)
58
+ return host;
59
+ const targets = /* @__PURE__ */ new Map();
60
+ for (const { target } of validateManifestCatalog(catalog).entries) {
61
+ if (target.platform === host.platform && target.architecture === host.architecture)
62
+ targets.set(JSON.stringify(target), target);
63
+ }
64
+ if (targets.size === 0)
65
+ throw new Error("Component pin catalog has no target for actual runtime.");
66
+ if (targets.size !== 1)
67
+ throw new Error("Component pin catalog has ambiguous targets for actual runtime.");
68
+ return [...targets.values()][0];
69
+ }
70
+
71
+ // packages/koed-server/dist/component-commands.js
72
+ import { existsSync, readdirSync } from "node:fs";
73
+ var requirementsFor = (context) => calculateRuntimeRequirements(resolveEffectiveRuntimeConfig(context.paths, context.environment ?? process.env, context.execution ?? resolveKoedAppRuntimeExecution()));
74
+ var requiredManifestPinsAvailable = (context, required) => {
75
+ const pinRequired = context.desktopRuntimeCapability ? required.filter((component) => component !== "base") : required;
76
+ if (pinRequired.length === 0)
77
+ return true;
78
+ if (!productionComponentManifestCatalog)
79
+ return false;
80
+ const catalog = validateManifestCatalog(productionComponentManifestCatalog);
81
+ return pinRequired.every((component) => {
82
+ try {
83
+ resolveComponentManifestPinTarget(catalog, {
84
+ component,
85
+ ...catalog.schemaVersion === 2 && component === "privacy" && context.target.platform === "linux" ? { variant: "cpu" } : {},
86
+ productVersion: context.controlPlaneVersion,
87
+ target: context.target,
88
+ runtime: context.runtime
89
+ });
90
+ return true;
91
+ } catch (error) {
92
+ if (error instanceof Error && (error.message.startsWith("Component pin catalog version mismatch") || error.message.startsWith("Required component manifest pin is missing") || error.message.startsWith("Component manifest pin target is ambiguous")))
93
+ return false;
94
+ throw error;
95
+ }
96
+ });
97
+ };
98
+ var storedGenerations = async (context) => {
99
+ if (!existsSync(context.paths.generationsDir))
100
+ return [];
101
+ const ids = readdirSync(context.paths.generationsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && /^[a-f0-9]{64}$/.test(entry.name)).map((entry) => entry.name);
102
+ const generations = [];
103
+ for (const id of ids) {
104
+ try {
105
+ const generation = await readStagedGeneration(context.paths, id);
106
+ if (generation.owner.kind === context.owner.kind && generation.owner.installationId === context.owner.installationId)
107
+ generations.push(generation);
108
+ } catch {
109
+ }
110
+ }
111
+ return generations;
112
+ };
113
+ var readOwnedCurrentGeneration = async (context) => {
114
+ try {
115
+ const evidence = context.desktopRuntimeCapability ? readCurrentDesktopGenerationOrderingEvidence(context.paths, context.desktopRuntimeCapability) : readCurrentGenerationOrderingEvidence(context.paths);
116
+ const currentBundle = evidence.kind !== "desktop-generation-ordering-evidence" || evidence.bundleDigest === context.desktopRuntimeCapability?.bundleDigest;
117
+ const generation = evidence.productVersion !== context.controlPlaneVersion || !currentBundle ? evidence : context.desktopRuntimeCapability ? await readCurrentDesktopGeneration(context.paths, context.desktopRuntimeCapability) : await readCurrentGeneration(context.paths);
118
+ return generation.owner.kind === context.owner.kind && generation.owner.installationId === context.owner.installationId ? generation : null;
119
+ } catch (error) {
120
+ if (error instanceof Error && error.message === "no active runtime generation")
121
+ return null;
122
+ throw error;
123
+ }
124
+ };
125
+ async function runComponentStatus(context) {
126
+ const required = requirementsFor(context).components;
127
+ const active = await readOwnedCurrentGeneration(context);
128
+ const priorPresence = active && "kind" in active ? active.kind === "desktop-generation-ordering-evidence" ? active.components : readGenerationComponentPresence(context.paths, active.id) : [];
129
+ const generations = await storedGenerations(context);
130
+ const installed = await readStoredComponents(context.paths, context.runtime);
131
+ const staged = generations.filter((generation) => generation.id !== active?.id);
132
+ const states = {
133
+ base: "not-required",
134
+ privacy: "not-required"
135
+ };
136
+ for (const component of ["base", "privacy"]) {
137
+ if (!required.includes(component))
138
+ continue;
139
+ if (active && !("kind" in active) && active[component]) {
140
+ states[component] = active.productVersion === context.controlPlaneVersion ? "active" : "incompatible";
141
+ continue;
142
+ }
143
+ const stored = staged.filter((generation) => generation[component] !== void 0);
144
+ states[component] = stored.some((generation) => generation.productVersion === context.controlPlaneVersion) ? "staged" : stored.length > 0 ? "incompatible" : installed.some((entry) => entry.manifest.component === component && entry.manifest.productVersion === context.controlPlaneVersion) ? "installed" : priorPresence.includes(component) || installed.some((entry) => entry.manifest.component === component) ? "incompatible" : "missing";
145
+ }
146
+ return {
147
+ components: states,
148
+ activeGeneration: active?.id ?? null,
149
+ activeVersion: active?.productVersion ?? null,
150
+ required,
151
+ requiredManifestPinsAvailable: requiredManifestPinsAvailable(context, required)
152
+ };
153
+ }
154
+ async function runComponentInstall(context, options) {
155
+ if (!options.source)
156
+ throw new Error("A manifest-pinned component source is required; provide offline archive and manifest paths or exact-version URLs.");
157
+ const version = options.version ?? context.controlPlaneVersion;
158
+ if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version))
159
+ throw new Error("component version must be an exact semantic version.");
160
+ const required = requirementsFor(context).components;
161
+ if (!required.includes(options.component))
162
+ throw new Error(`${options.component} component is not required by current runtime configuration.`);
163
+ if (options.component === "privacy" && context.target.platform === "linux" && productionComponentManifestCatalog?.schemaVersion === 2 && options.variant === void 0)
164
+ throw new Error("Linux Privacy installation requires --variant cpu or cuda with its matching authenticated source.");
165
+ const component = await stageComponent(context.paths, options.source, {
166
+ expectedComponent: options.component,
167
+ expectedVariant: options.variant,
168
+ expectedVersion: version,
169
+ target: context.target,
170
+ runtime: context.runtime,
171
+ signal: context.signal,
172
+ progress: context.progress
173
+ });
174
+ const selection = await readOwnedCurrentGeneration(context);
175
+ const active = selection && !("kind" in selection) ? selection : null;
176
+ const staged = await storedGenerations(context);
177
+ const installed = await readStoredComponents(context.paths, context.runtime);
178
+ const priorGeneration = staged.find((generation2) => generation2.productVersion === version);
179
+ const otherComponent = options.component === "base" ? active?.privacy?.manifest.productVersion === version ? active.privacy : priorGeneration?.privacy ?? installed.find((entry) => entry.manifest.component === "privacy" && entry.manifest.productVersion === version) : active?.base.kind === "manifest-pinned-component" && active.base.manifest.productVersion === version ? active.base : (priorGeneration?.base.kind === "manifest-pinned-component" ? priorGeneration.base : void 0) ?? installed.find((entry) => entry.manifest.component === "base" && entry.manifest.productVersion === version);
180
+ if (required.length > 1 && !otherComponent) {
181
+ if (options.component === "base")
182
+ await stageGeneration(context.paths, {
183
+ base: component,
184
+ owner: context.owner
185
+ });
186
+ return { state: "staged" };
187
+ }
188
+ const generation = await stageGeneration(context.paths, {
189
+ base: options.component === "base" ? component : otherComponent,
190
+ ...required.includes("privacy") ? {
191
+ privacy: options.component === "privacy" ? component : otherComponent
192
+ } : {},
193
+ owner: context.owner
194
+ });
195
+ if (version !== context.controlPlaneVersion || options.stageOnly || context.isRunning)
196
+ return { state: "staged" };
197
+ const activated = await activateGeneration(context.paths, generation.id, context.owner);
198
+ return { state: "active", generationId: activated.id };
199
+ }
200
+ async function runComponentActivate(context, version) {
201
+ if (version !== context.controlPlaneVersion)
202
+ throw new Error("Activation requires a matching control plane version; select the matching control-plane version before rollback activation.");
203
+ if (context.isRunning)
204
+ throw new Error("Stop Koed services before activating a component generation.");
205
+ const required = requirementsFor(context).components;
206
+ const candidates = (await storedGenerations(context)).filter((generation) => generation.productVersion === version).sort((left, right) => right.id.localeCompare(left.id));
207
+ const candidate = candidates.find((generation) => required.every((component) => generation[component] !== void 0));
208
+ if (!candidate)
209
+ throw new Error(`No complete staged generation for ${version}; install all required components first.`);
210
+ return activateGeneration(context.paths, candidate.id, context.owner, context.desktopRuntimeCapability);
211
+ }
212
+ async function runComponentCleanup(context) {
213
+ return cleanupGenerations(context.paths, 2, context.owner);
214
+ }
215
+
216
+ // packages/koed-server/dist/cli-component-operations.js
217
+ var runComponentCommand = async (operation, options, dependencies) => {
218
+ const stdout = dependencies.stdout ?? process.stdout;
219
+ const stderr = dependencies.stderr ?? process.stderr;
220
+ try {
221
+ if (dependencies.desktopRuntimeCapability)
222
+ throw new Error("Koed Desktop manages components for its bundled runtime. Use Koed Desktop to install or update components.");
223
+ const paths = (dependencies.resolvePaths ?? resolveKoedServerPaths)();
224
+ const runtime = discoverActualRuntimeIdentity();
225
+ const target = resolveComponentCommandTarget(runtime, productionComponentManifestCatalog);
226
+ const context = {
227
+ paths,
228
+ controlPlaneVersion: resolveKoedControlPlaneVersion(),
229
+ target,
230
+ runtime,
231
+ owner: resolveKoedRuntimeOwner(),
232
+ isRunning: existsSync2(resolve(paths.runDir, "koed-server.lock"))
233
+ };
234
+ let result;
235
+ switch (operation) {
236
+ case "status":
237
+ result = await runComponentStatus(context);
238
+ break;
239
+ case "cleanup":
240
+ result = await runComponentCleanup(context);
241
+ break;
242
+ case "activate": {
243
+ if (!options.version)
244
+ throw new Error("--version is required.");
245
+ result = await runComponentActivate(context, options.version);
246
+ break;
247
+ }
248
+ case "install": {
249
+ const component = options.component;
250
+ if (!component)
251
+ throw new Error("--component is required.");
252
+ if (component !== "base" && component !== "privacy")
253
+ throw new Error("--component must be base or privacy.");
254
+ const variant = options.variant;
255
+ if (variant !== void 0 && (component !== "privacy" || target.platform !== "linux" || target.architecture !== "x64" || variant !== "cpu" && variant !== "cuda"))
256
+ throw new Error("--variant must be cpu or cuda for Linux x64 Privacy.");
257
+ const hasOffline = options.archive !== void 0 || options.manifest !== void 0;
258
+ const hasRemote = options.archiveUrl !== void 0 || options.manifestUrl !== void 0;
259
+ if (hasOffline === hasRemote)
260
+ throw new Error("Provide exactly one complete offline archive/manifest set or exact-version URL set.");
261
+ if (hasOffline && (options.archive === void 0 || options.manifest === void 0))
262
+ throw new Error("Offline install requires --archive and --manifest paths.");
263
+ if (hasRemote && (options.archiveUrl === void 0 || options.manifestUrl === void 0))
264
+ throw new Error("Network install requires --archive-url and --manifest-url.");
265
+ const source = hasOffline ? {
266
+ kind: "offline",
267
+ archivePath: options.archive,
268
+ manifestPath: options.manifest
269
+ } : {
270
+ kind: "remote",
271
+ archiveUrl: options.archiveUrl,
272
+ manifestUrl: options.manifestUrl
273
+ };
274
+ result = await runComponentInstall(context, {
275
+ component,
276
+ ...variant === "cpu" || variant === "cuda" ? { variant } : {},
277
+ version: options.version,
278
+ source,
279
+ stageOnly: Boolean(options.stageOnly)
280
+ });
281
+ }
282
+ }
283
+ stdout.write(`${JSON.stringify(result, null, 2)}
284
+ `);
285
+ return 0;
286
+ } catch (error) {
287
+ const message = error instanceof Error ? error.message : String(error);
288
+ if (options.json)
289
+ stdout.write(`${JSON.stringify({ ok: false, error: message }, null, 2)}
290
+ `);
291
+ else
292
+ stderr.write(`${message}
293
+ `);
294
+ return 1;
295
+ }
296
+ };
297
+ export {
298
+ runComponentCommand
299
+ };