@koed-labs/server 0.0.0-bootstrap.0 → 0.10.3

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 (56) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +65 -0
  3. package/bin/koed.js +7 -0
  4. package/package.json +22 -4
  5. package/third-party-notices.json +92 -0
  6. package/vendor/chunk-2BWTLF7A.js +13883 -0
  7. package/vendor/chunk-2DA7EFZV.js +924 -0
  8. package/vendor/chunk-2S3OGPUC.js +58 -0
  9. package/vendor/chunk-473OA62O.js +26827 -0
  10. package/vendor/chunk-6JRWGOQG.js +236 -0
  11. package/vendor/chunk-7NOQSX4T.js +14 -0
  12. package/vendor/chunk-7NXKPDF3.js +1586 -0
  13. package/vendor/chunk-A4NKL2PK.js +153 -0
  14. package/vendor/chunk-A6WMU2GG.js +48 -0
  15. package/vendor/chunk-AFLKCQHF.js +73 -0
  16. package/vendor/chunk-BTS4ZTF3.js +43 -0
  17. package/vendor/chunk-C3N4N5HR.js +108 -0
  18. package/vendor/chunk-DXTAWHY3.js +25 -0
  19. package/vendor/chunk-G4IIVVJO.js +56 -0
  20. package/vendor/chunk-GELDEJJ2.js +4337 -0
  21. package/vendor/chunk-HFM6ROJL.js +188 -0
  22. package/vendor/chunk-HK2H3MVE.js +328 -0
  23. package/vendor/chunk-HZJK5RWC.js +5088 -0
  24. package/vendor/chunk-J2L726BC.js +2497 -0
  25. package/vendor/chunk-JBGD4JLR.js +3779 -0
  26. package/vendor/chunk-JJNLH5GA.js +2470 -0
  27. package/vendor/chunk-JKOG52PE.js +128 -0
  28. package/vendor/chunk-K2EIFEQF.js +89 -0
  29. package/vendor/chunk-KUIWH33N.js +16 -0
  30. package/vendor/chunk-NEWIOOM6.js +34 -0
  31. package/vendor/chunk-NM5NXCVM.js +2404 -0
  32. package/vendor/chunk-PT3AUPGE.js +459 -0
  33. package/vendor/chunk-PY5LYLV7.js +143 -0
  34. package/vendor/chunk-QIIKMG3M.js +103 -0
  35. package/vendor/chunk-QT24SAW6.js +110 -0
  36. package/vendor/chunk-RVYJKKWA.js +22 -0
  37. package/vendor/chunk-SKVYP7NY.js +1647 -0
  38. package/vendor/chunk-TSRPHKAC.js +780 -0
  39. package/vendor/chunk-UI5RLBKQ.js +30 -0
  40. package/vendor/chunk-VPC5NLZG.js +259 -0
  41. package/vendor/chunk-W2HNI6AA.js +75 -0
  42. package/vendor/chunk-X6M525ZJ.js +20 -0
  43. package/vendor/chunk-XIZVLPHZ.js +18 -0
  44. package/vendor/chunk-XNFVSVBS.js +242 -0
  45. package/vendor/chunk-YCDEMYY6.js +2076 -0
  46. package/vendor/chunk-YJ6XUZT6.js +292 -0
  47. package/vendor/chunk-YJWREXN6.js +26020 -0
  48. package/vendor/chunk-YK4F4VY2.js +173 -0
  49. package/vendor/chunk-YOFI4PCH.js +36 -0
  50. package/vendor/chunk-ZUGNCQZE.js +247 -0
  51. package/vendor/chunk-ZXX4ZNJY.js +21 -0
  52. package/vendor/cli.js +7 -0
  53. package/vendor/component-manifest-catalog.js +8 -0
  54. package/vendor/control-plane.js +23 -0
  55. package/vendor/package.json +1 -0
  56. package/vendor/privacy-service-bootstrap.js +6 -0
@@ -0,0 +1,292 @@
1
+ import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
+ import {
3
+ calculateRuntimeRequirements,
4
+ resolveEffectiveRuntimeConfig
5
+ } from "./chunk-AFLKCQHF.js";
6
+ import {
7
+ activateGeneration,
8
+ cleanupGenerations,
9
+ discoverActualRuntimeIdentity,
10
+ readCurrentDesktopGeneration,
11
+ readCurrentDesktopGenerationOrderingEvidence,
12
+ readCurrentGeneration,
13
+ readCurrentGenerationOrderingEvidence,
14
+ readGenerationComponentPresence,
15
+ readStagedGeneration,
16
+ readStoredComponents,
17
+ resolveComponentManifestPinTarget,
18
+ stageComponent,
19
+ stageGeneration
20
+ } from "./chunk-NM5NXCVM.js";
21
+ import "./chunk-G4IIVVJO.js";
22
+ import {
23
+ resolveKoedAppRuntimeExecution,
24
+ resolveKoedControlPlaneVersion,
25
+ resolveKoedRuntimeOwner
26
+ } from "./chunk-A4NKL2PK.js";
27
+ import {
28
+ productionComponentManifestCatalog,
29
+ validateManifestCatalog
30
+ } from "./chunk-QIIKMG3M.js";
31
+ import "./chunk-2DA7EFZV.js";
32
+ import {
33
+ resolveKoedServerPaths
34
+ } from "./chunk-K2EIFEQF.js";
35
+ import "./chunk-UI5RLBKQ.js";
36
+ import "./chunk-W2HNI6AA.js";
37
+ import "./chunk-473OA62O.js";
38
+ import "./chunk-BTS4ZTF3.js";
39
+
40
+ // packages/koed-server/dist/cli-component-operations.js
41
+ import { existsSync as existsSync2 } from "node:fs";
42
+ import { resolve } from "node:path";
43
+
44
+ // packages/koed-server/dist/component-command-target.js
45
+ function resolveComponentCommandTarget(runtime, catalog) {
46
+ const host = {
47
+ platform: runtime.platform,
48
+ architecture: runtime.architecture
49
+ };
50
+ if (catalog === null)
51
+ return host;
52
+ const targets = /* @__PURE__ */ new Map();
53
+ for (const { target } of validateManifestCatalog(catalog).entries) {
54
+ if (target.platform === host.platform && target.architecture === host.architecture)
55
+ targets.set(JSON.stringify(target), target);
56
+ }
57
+ if (targets.size === 0)
58
+ throw new Error("Component pin catalog has no target for actual runtime.");
59
+ if (targets.size !== 1)
60
+ throw new Error("Component pin catalog has ambiguous targets for actual runtime.");
61
+ return [...targets.values()][0];
62
+ }
63
+
64
+ // packages/koed-server/dist/component-commands.js
65
+ import { existsSync, readdirSync } from "node:fs";
66
+ var requirementsFor = (context) => calculateRuntimeRequirements(resolveEffectiveRuntimeConfig(context.paths, context.environment ?? process.env, context.execution ?? resolveKoedAppRuntimeExecution()));
67
+ var requiredManifestPinsAvailable = (context, required) => {
68
+ const pinRequired = context.desktopRuntimeCapability ? required.filter((component) => component !== "base") : required;
69
+ if (pinRequired.length === 0)
70
+ return true;
71
+ if (!productionComponentManifestCatalog)
72
+ return false;
73
+ const catalog = validateManifestCatalog(productionComponentManifestCatalog);
74
+ return pinRequired.every((component) => {
75
+ try {
76
+ resolveComponentManifestPinTarget(catalog, {
77
+ component,
78
+ ...catalog.schemaVersion === 2 && component === "privacy" && context.target.platform === "linux" ? { variant: "cpu" } : {},
79
+ productVersion: context.controlPlaneVersion,
80
+ target: context.target,
81
+ runtime: context.runtime
82
+ });
83
+ return true;
84
+ } catch (error) {
85
+ 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")))
86
+ return false;
87
+ throw error;
88
+ }
89
+ });
90
+ };
91
+ var storedGenerations = async (context) => {
92
+ if (!existsSync(context.paths.generationsDir))
93
+ return [];
94
+ const ids = readdirSync(context.paths.generationsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && /^[a-f0-9]{64}$/.test(entry.name)).map((entry) => entry.name);
95
+ const generations = [];
96
+ for (const id of ids) {
97
+ try {
98
+ const generation = await readStagedGeneration(context.paths, id);
99
+ if (generation.owner.kind === context.owner.kind && generation.owner.installationId === context.owner.installationId)
100
+ generations.push(generation);
101
+ } catch {
102
+ }
103
+ }
104
+ return generations;
105
+ };
106
+ var readOwnedCurrentGeneration = async (context) => {
107
+ try {
108
+ const evidence = context.desktopRuntimeCapability ? readCurrentDesktopGenerationOrderingEvidence(context.paths, context.desktopRuntimeCapability) : readCurrentGenerationOrderingEvidence(context.paths);
109
+ const currentBundle = evidence.kind !== "desktop-generation-ordering-evidence" || evidence.bundleDigest === context.desktopRuntimeCapability?.bundleDigest;
110
+ const generation = evidence.productVersion !== context.controlPlaneVersion || !currentBundle ? evidence : context.desktopRuntimeCapability ? await readCurrentDesktopGeneration(context.paths, context.desktopRuntimeCapability) : await readCurrentGeneration(context.paths);
111
+ return generation.owner.kind === context.owner.kind && generation.owner.installationId === context.owner.installationId ? generation : null;
112
+ } catch (error) {
113
+ if (error instanceof Error && error.message === "no active runtime generation")
114
+ return null;
115
+ throw error;
116
+ }
117
+ };
118
+ async function runComponentStatus(context) {
119
+ const required = requirementsFor(context).components;
120
+ const active = await readOwnedCurrentGeneration(context);
121
+ const priorPresence = active && "kind" in active ? active.kind === "desktop-generation-ordering-evidence" ? active.components : readGenerationComponentPresence(context.paths, active.id) : [];
122
+ const generations = await storedGenerations(context);
123
+ const installed = await readStoredComponents(context.paths, context.runtime);
124
+ const staged = generations.filter((generation) => generation.id !== active?.id);
125
+ const states = {
126
+ base: "not-required",
127
+ privacy: "not-required"
128
+ };
129
+ for (const component of ["base", "privacy"]) {
130
+ if (!required.includes(component))
131
+ continue;
132
+ if (active && !("kind" in active) && active[component]) {
133
+ states[component] = active.productVersion === context.controlPlaneVersion ? "active" : "incompatible";
134
+ continue;
135
+ }
136
+ const stored = staged.filter((generation) => generation[component] !== void 0);
137
+ 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";
138
+ }
139
+ return {
140
+ components: states,
141
+ activeGeneration: active?.id ?? null,
142
+ activeVersion: active?.productVersion ?? null,
143
+ required,
144
+ requiredManifestPinsAvailable: requiredManifestPinsAvailable(context, required)
145
+ };
146
+ }
147
+ async function runComponentInstall(context, options) {
148
+ if (!options.source)
149
+ throw new Error("A manifest-pinned component source is required; provide offline archive and manifest paths or exact-version URLs.");
150
+ const version = options.version ?? context.controlPlaneVersion;
151
+ if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version))
152
+ throw new Error("component version must be an exact semantic version.");
153
+ const required = requirementsFor(context).components;
154
+ if (!required.includes(options.component))
155
+ throw new Error(`${options.component} component is not required by current runtime configuration.`);
156
+ if (options.component === "privacy" && context.target.platform === "linux" && productionComponentManifestCatalog?.schemaVersion === 2 && options.variant === void 0)
157
+ throw new Error("Linux Privacy installation requires --variant cpu or cuda with its matching authenticated source.");
158
+ const component = await stageComponent(context.paths, options.source, {
159
+ expectedComponent: options.component,
160
+ expectedVariant: options.variant,
161
+ expectedVersion: version,
162
+ target: context.target,
163
+ runtime: context.runtime,
164
+ signal: context.signal,
165
+ progress: context.progress
166
+ });
167
+ const selection = await readOwnedCurrentGeneration(context);
168
+ const active = selection && !("kind" in selection) ? selection : null;
169
+ const staged = await storedGenerations(context);
170
+ const installed = await readStoredComponents(context.paths, context.runtime);
171
+ const priorGeneration = staged.find((generation2) => generation2.productVersion === version);
172
+ 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);
173
+ if (required.length > 1 && !otherComponent) {
174
+ if (options.component === "base")
175
+ await stageGeneration(context.paths, {
176
+ base: component,
177
+ owner: context.owner
178
+ });
179
+ return { state: "staged" };
180
+ }
181
+ const generation = await stageGeneration(context.paths, {
182
+ base: options.component === "base" ? component : otherComponent,
183
+ ...required.includes("privacy") ? {
184
+ privacy: options.component === "privacy" ? component : otherComponent
185
+ } : {},
186
+ owner: context.owner
187
+ });
188
+ if (version !== context.controlPlaneVersion || options.stageOnly || context.isRunning)
189
+ return { state: "staged" };
190
+ const activated = await activateGeneration(context.paths, generation.id, context.owner);
191
+ return { state: "active", generationId: activated.id };
192
+ }
193
+ async function runComponentActivate(context, version) {
194
+ if (version !== context.controlPlaneVersion)
195
+ throw new Error("Activation requires a matching control plane version; select the matching control-plane version before rollback activation.");
196
+ if (context.isRunning)
197
+ throw new Error("Stop Koed services before activating a component generation.");
198
+ const required = requirementsFor(context).components;
199
+ const candidates = (await storedGenerations(context)).filter((generation) => generation.productVersion === version).sort((left, right) => right.id.localeCompare(left.id));
200
+ const candidate = candidates.find((generation) => required.every((component) => generation[component] !== void 0));
201
+ if (!candidate)
202
+ throw new Error(`No complete staged generation for ${version}; install all required components first.`);
203
+ return activateGeneration(context.paths, candidate.id, context.owner, context.desktopRuntimeCapability);
204
+ }
205
+ async function runComponentCleanup(context) {
206
+ return cleanupGenerations(context.paths, 2, context.owner);
207
+ }
208
+
209
+ // packages/koed-server/dist/cli-component-operations.js
210
+ var runComponentCommand = async (operation, options, dependencies) => {
211
+ const stdout = dependencies.stdout ?? process.stdout;
212
+ const stderr = dependencies.stderr ?? process.stderr;
213
+ try {
214
+ if (dependencies.desktopRuntimeCapability)
215
+ throw new Error("Koed Desktop manages components for its bundled runtime. Use Koed Desktop to install or update components.");
216
+ const paths = (dependencies.resolvePaths ?? resolveKoedServerPaths)();
217
+ const runtime = discoverActualRuntimeIdentity();
218
+ const target = resolveComponentCommandTarget(runtime, productionComponentManifestCatalog);
219
+ const context = {
220
+ paths,
221
+ controlPlaneVersion: resolveKoedControlPlaneVersion(),
222
+ target,
223
+ runtime,
224
+ owner: resolveKoedRuntimeOwner(),
225
+ isRunning: existsSync2(resolve(paths.runDir, "koed-server.lock"))
226
+ };
227
+ let result;
228
+ switch (operation) {
229
+ case "status":
230
+ result = await runComponentStatus(context);
231
+ break;
232
+ case "cleanup":
233
+ result = await runComponentCleanup(context);
234
+ break;
235
+ case "activate": {
236
+ if (!options.version)
237
+ throw new Error("--version is required.");
238
+ result = await runComponentActivate(context, options.version);
239
+ break;
240
+ }
241
+ case "install": {
242
+ const component = options.component;
243
+ if (!component)
244
+ throw new Error("--component is required.");
245
+ if (component !== "base" && component !== "privacy")
246
+ throw new Error("--component must be base or privacy.");
247
+ const variant = options.variant;
248
+ if (variant !== void 0 && (component !== "privacy" || target.platform !== "linux" || target.architecture !== "x64" || variant !== "cpu" && variant !== "cuda"))
249
+ throw new Error("--variant must be cpu or cuda for Linux x64 Privacy.");
250
+ const hasOffline = options.archive !== void 0 || options.manifest !== void 0;
251
+ const hasRemote = options.archiveUrl !== void 0 || options.manifestUrl !== void 0;
252
+ if (hasOffline === hasRemote)
253
+ throw new Error("Provide exactly one complete offline archive/manifest set or exact-version URL set.");
254
+ if (hasOffline && (options.archive === void 0 || options.manifest === void 0))
255
+ throw new Error("Offline install requires --archive and --manifest paths.");
256
+ if (hasRemote && (options.archiveUrl === void 0 || options.manifestUrl === void 0))
257
+ throw new Error("Network install requires --archive-url and --manifest-url.");
258
+ const source = hasOffline ? {
259
+ kind: "offline",
260
+ archivePath: options.archive,
261
+ manifestPath: options.manifest
262
+ } : {
263
+ kind: "remote",
264
+ archiveUrl: options.archiveUrl,
265
+ manifestUrl: options.manifestUrl
266
+ };
267
+ result = await runComponentInstall(context, {
268
+ component,
269
+ ...variant === "cpu" || variant === "cuda" ? { variant } : {},
270
+ version: options.version,
271
+ source,
272
+ stageOnly: Boolean(options.stageOnly)
273
+ });
274
+ }
275
+ }
276
+ stdout.write(`${JSON.stringify(result, null, 2)}
277
+ `);
278
+ return 0;
279
+ } catch (error) {
280
+ const message = error instanceof Error ? error.message : String(error);
281
+ if (options.json)
282
+ stdout.write(`${JSON.stringify({ ok: false, error: message }, null, 2)}
283
+ `);
284
+ else
285
+ stderr.write(`${message}
286
+ `);
287
+ return 1;
288
+ }
289
+ };
290
+ export {
291
+ runComponentCommand
292
+ };