@koed-labs/server 0.10.3 → 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 (54) hide show
  1. package/README.md +3 -3
  2. package/package.json +1 -1
  3. package/vendor/{chunk-A6WMU2GG.js → chunk-2XKSVKQA.js} +5 -4
  4. package/vendor/{chunk-VPC5NLZG.js → chunk-4OO6VAU3.js} +1 -1
  5. package/vendor/{chunk-HK2H3MVE.js → chunk-53ZFCDHP.js} +4 -0
  6. package/vendor/chunk-6KS67EQE.js +75 -0
  7. package/vendor/chunk-7EGSY3E4.js +8 -0
  8. package/vendor/{chunk-JKOG52PE.js → chunk-7FSHVVTZ.js} +1 -1
  9. package/vendor/chunk-ALJUSOF7.js +175 -0
  10. package/vendor/{chunk-KUIWH33N.js → chunk-AVQCUFYQ.js} +1 -1
  11. package/vendor/chunk-BGENSONI.js +18 -0
  12. package/vendor/{chunk-ZXX4ZNJY.js → chunk-BUIM2M4R.js} +3 -2
  13. package/vendor/{chunk-YK4F4VY2.js → chunk-C4V72GXC.js} +51 -30
  14. package/vendor/{chunk-JJNLH5GA.js → chunk-C5SNDPAP.js} +21 -19
  15. package/vendor/{chunk-J2L726BC.js → chunk-CHMH4LH5.js} +3 -3
  16. package/vendor/{chunk-2S3OGPUC.js → chunk-EA4QDDQA.js} +2 -2
  17. package/vendor/{chunk-HZJK5RWC.js → chunk-EDPNYIX5.js} +575 -215
  18. package/vendor/{chunk-NM5NXCVM.js → chunk-FN3HUUO2.js} +558 -988
  19. package/vendor/{chunk-473OA62O.js → chunk-FSNLU46W.js} +218 -12497
  20. package/vendor/{chunk-GELDEJJ2.js → chunk-FYYRFX4U.js} +133 -47
  21. package/vendor/{chunk-YOFI4PCH.js → chunk-GFASBPV2.js} +7 -1
  22. package/vendor/chunk-HC76426R.js +48 -0
  23. package/vendor/{chunk-QIIKMG3M.js → chunk-IY2HRXOZ.js} +1 -5
  24. package/vendor/{chunk-ZUGNCQZE.js → chunk-JYK6UL6D.js} +22 -8
  25. package/vendor/{chunk-2BWTLF7A.js → chunk-LRP66XEY.js} +45 -21
  26. package/vendor/{chunk-DXTAWHY3.js → chunk-NOU7RHYZ.js} +8 -7
  27. package/vendor/{chunk-C3N4N5HR.js → chunk-NVTMIAAF.js} +26 -21
  28. package/vendor/chunk-O7DW2VAV.js +14 -0
  29. package/vendor/{chunk-YJ6XUZT6.js → chunk-OCILJ737.js} +23 -16
  30. package/vendor/{chunk-TSRPHKAC.js → chunk-PL3LWC5C.js} +16 -42
  31. package/vendor/chunk-QRKHHWJJ.js +104 -0
  32. package/vendor/{chunk-YJWREXN6.js → chunk-RCR4XPE3.js} +1 -1
  33. package/vendor/{chunk-AFLKCQHF.js → chunk-SHLRINKO.js} +2 -2
  34. package/vendor/{chunk-NEWIOOM6.js → chunk-SNKWETM5.js} +3 -2
  35. package/vendor/{chunk-XNFVSVBS.js → chunk-SRKIBFOE.js} +1 -1
  36. package/vendor/{chunk-G4IIVVJO.js → chunk-T6UB5PNX.js} +70 -2
  37. package/vendor/{chunk-RVYJKKWA.js → chunk-TG26CZGQ.js} +5 -4
  38. package/vendor/{chunk-HFM6ROJL.js → chunk-TISYUUEJ.js} +1 -1
  39. package/vendor/{chunk-K2EIFEQF.js → chunk-TSAYTRX3.js} +1 -1
  40. package/vendor/chunk-TVYEB2GN.js +343 -0
  41. package/vendor/{chunk-PT3AUPGE.js → chunk-UB6JCVQ3.js} +3 -1
  42. package/vendor/chunk-VGIYSDNU.js +522 -0
  43. package/vendor/{chunk-X6M525ZJ.js → chunk-W2OJZZ6X.js} +5 -5
  44. package/vendor/{chunk-YCDEMYY6.js → chunk-WDFERJG3.js} +231 -99
  45. package/vendor/{chunk-SKVYP7NY.js → chunk-WPIEF4LY.js} +8 -8
  46. package/vendor/{chunk-UI5RLBKQ.js → chunk-YZLQZU5E.js} +17 -1
  47. package/vendor/{chunk-PY5LYLV7.js → chunk-Z5WCAUA6.js} +26 -21
  48. package/vendor/chunk-ZIOKV2X6.js +1589 -0
  49. package/vendor/chunk-ZOHNXUDY.js +12501 -0
  50. package/vendor/chunk-ZUDSZGVO.js +11 -0
  51. package/vendor/component-manifest-catalog.js +2 -1
  52. package/vendor/control-plane.js +11 -6
  53. package/vendor/chunk-2DA7EFZV.js +0 -924
  54. /package/vendor/{chunk-A4NKL2PK.js → chunk-V67IQB7H.js} +0 -0
@@ -1,7 +1,39 @@
1
1
  import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
+ import {
3
+ require_proper_lockfile
4
+ } from "./chunk-7NXKPDF3.js";
5
+ import {
6
+ __toESM
7
+ } from "./chunk-BTS4ZTF3.js";
8
+
9
+ // packages/koed-server/dist/file-lock.js
10
+ var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
11
+ import { mkdirSync } from "node:fs";
12
+ import { dirname } from "node:path";
13
+ var withFileLock = (file, operation) => {
14
+ mkdirSync(dirname(file), { recursive: true, mode: 448 });
15
+ const deadline = Date.now() + 5e3;
16
+ let release;
17
+ while (true) {
18
+ try {
19
+ release = import_proper_lockfile.default.lockSync(file, { realpath: false, stale: 3e4 });
20
+ break;
21
+ } catch (error) {
22
+ if (error.code !== "ELOCKED" || Date.now() >= deadline)
23
+ throw error;
24
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
25
+ }
26
+ }
27
+ try {
28
+ return operation();
29
+ } finally {
30
+ release();
31
+ }
32
+ };
2
33
 
3
34
  // packages/koed-server/dist/runtime-state.js
4
- import { readFileSync as nodeReadFileSync } from "node:fs";
35
+ import { randomUUID } from "node:crypto";
36
+ import { readFileSync as nodeReadFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
5
37
 
6
38
  // packages/koed-server/dist/process-liveness.js
7
39
  var isProcessRunning = (pid) => {
@@ -25,15 +57,48 @@ var validHttpUrl = (value) => {
25
57
  }
26
58
  };
27
59
  var validProcessMap = (value) => value === void 0 || isRecord(value) && Object.values(value).every((pid) => typeof pid === "number" && Number.isInteger(pid) && pid >= 0);
60
+ var validIdentityMap = (value) => value === void 0 || isRecord(value) && Object.values(value).every((identity) => typeof identity === "string" && identity.length > 0);
28
61
  var validRuntimeState = (value) => {
29
62
  if (!isRecord(value))
30
63
  return false;
31
64
  const validRuntimeMode = value.runtimeMode === void 0 || value.runtimeMode === "local-personal" || value.runtimeMode === "external" || value.runtimeMode === "developer";
32
65
  const validDependencyMode = value.dependencyMode === void 0 || value.dependencyMode === "bundled-local" || value.dependencyMode === "external";
33
66
  const validAutomaticPorts = value.automaticPorts === void 0 || typeof value.automaticPorts === "boolean";
34
- return typeof value.pid === "number" && Number.isInteger(value.pid) && value.pid > 0 && typeof value.startedAt === "string" && !Number.isNaN(Date.parse(value.startedAt)) && typeof value.repoRoot === "string" && Boolean(value.repoRoot.trim()) && validHttpUrl(value.apiUrl) && Array.isArray(value.services) && value.services.every((service) => typeof service === "string") && validRuntimeMode && validDependencyMode && validAutomaticPorts && validProcessMap(value.processes);
67
+ return typeof value.pid === "number" && Number.isInteger(value.pid) && value.pid > 0 && typeof value.startedAt === "string" && !Number.isNaN(Date.parse(value.startedAt)) && typeof value.repoRoot === "string" && Boolean(value.repoRoot.trim()) && validHttpUrl(value.apiUrl) && Array.isArray(value.services) && value.services.every((service) => typeof service === "string") && validRuntimeMode && validDependencyMode && validAutomaticPorts && validProcessMap(value.processes) && validIdentityMap(value.processIdentities);
35
68
  };
36
69
  var isRuntimeGenerationState = (value) => isRecord(value) && (Object.keys(value).length === 7 || Object.keys(value).length === 8 && ["manifest-pinned-store", "signed-store", "desktop-bundle"].includes(String(value.source))) && value.schemaVersion === 1 && typeof value.generationId === "string" && /^[a-f0-9]{64}$/.test(value.generationId) && typeof value.pid === "number" && Number.isInteger(value.pid) && value.pid > 0 && typeof value.processIdentity === "string" && value.processIdentity.length > 0 && typeof value.startedAt === "string" && !Number.isNaN(Date.parse(value.startedAt)) && isRecord(value.owner) && Object.keys(value.owner).length === 2 && ["cli", "desktop", "standalone"].includes(String(value.owner.kind)) && typeof value.owner.installationId === "string" && /^[A-Za-z0-9._-]{1,128}$/.test(value.owner.installationId) && typeof value.pinToken === "string" && /^[a-f0-9]{64}$/.test(value.pinToken);
70
+ function writeRuntimeState(path, state) {
71
+ withFileLock(path, () => {
72
+ const temporary = `${path}.${randomUUID()}.tmp`;
73
+ try {
74
+ writeFileSync(temporary, `${JSON.stringify(state, null, 2)}
75
+ `, {
76
+ flag: "wx",
77
+ mode: 384
78
+ });
79
+ renameSync(temporary, path);
80
+ } finally {
81
+ rmSync(temporary, { force: true });
82
+ }
83
+ });
84
+ }
85
+ function removeOwnedRuntimeState(path, owner, read = nodeReadFileSync, remove = rmSync) {
86
+ return withFileLock(path, () => {
87
+ let contents;
88
+ try {
89
+ contents = read(path, "utf8");
90
+ } catch (error) {
91
+ if (error.code === "ENOENT")
92
+ return true;
93
+ throw error;
94
+ }
95
+ const state = JSON.parse(contents);
96
+ if (!isRecord(state) || state.pid !== owner.pid || state.startedAt !== owner.startedAt)
97
+ return false;
98
+ remove(path, { force: true });
99
+ return true;
100
+ });
101
+ }
37
102
  var readActiveRuntimeState = (path, readFileSync = nodeReadFileSync, checkPid = isProcessRunning) => {
38
103
  try {
39
104
  const parsed = JSON.parse(String(readFileSync(path, "utf8")));
@@ -50,7 +115,10 @@ var applyActiveRuntimeUrls = (environment, runtime) => ({
50
115
 
51
116
  export {
52
117
  isProcessRunning,
118
+ withFileLock,
53
119
  isRuntimeGenerationState,
120
+ writeRuntimeState,
121
+ removeOwnedRuntimeState,
54
122
  readActiveRuntimeState,
55
123
  applyActiveRuntimeUrls
56
124
  };
@@ -6,11 +6,12 @@ import {
6
6
  invalidateUpstreamEnrollmentReferences,
7
7
  readUpstreamEnrollmentBinding,
8
8
  startUpstreamEnrollment
9
- } from "./chunk-SKVYP7NY.js";
10
- import "./chunk-YJWREXN6.js";
11
- import "./chunk-XNFVSVBS.js";
9
+ } from "./chunk-WPIEF4LY.js";
10
+ import "./chunk-SRKIBFOE.js";
12
11
  import "./chunk-7NXKPDF3.js";
13
- import "./chunk-473OA62O.js";
12
+ import "./chunk-RCR4XPE3.js";
13
+ import "./chunk-ZOHNXUDY.js";
14
+ import "./chunk-FSNLU46W.js";
14
15
  import "./chunk-BTS4ZTF3.js";
15
16
  export {
16
17
  cancelUpstreamEnrollment,
@@ -1,7 +1,7 @@
1
1
  import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
2
  import {
3
3
  isProcessRunning
4
- } from "./chunk-G4IIVVJO.js";
4
+ } from "./chunk-T6UB5PNX.js";
5
5
  import {
6
6
  require_proper_lockfile
7
7
  } from "./chunk-7NXKPDF3.js";
@@ -2,7 +2,7 @@ import { createRequire as createKoedRequire } from "node:module"; const require
2
2
  import {
3
3
  isPackagedRuntimeMode,
4
4
  resolvePackagedResourcesPath
5
- } from "./chunk-UI5RLBKQ.js";
5
+ } from "./chunk-YZLQZU5E.js";
6
6
 
7
7
  // packages/koed-server/dist/paths.js
8
8
  import { mkdirSync } from "node:fs";
@@ -0,0 +1,343 @@
1
+ import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
+ import {
3
+ collectLocalModelStatus
4
+ } from "./chunk-JYK6UL6D.js";
5
+ import {
6
+ compareNativeVersions
7
+ } from "./chunk-QRKHHWJJ.js";
8
+ import {
9
+ external_exports
10
+ } from "./chunk-FSNLU46W.js";
11
+
12
+ // packages/koed-server/dist/runtime-release-validation.js
13
+ import { mkdtempSync, rmSync } from "node:fs";
14
+ import { dirname, join, resolve } from "node:path";
15
+
16
+ // packages/koed-server/dist/native-validation-process.js
17
+ import { spawn } from "node:child_process";
18
+ import { request } from "node:http";
19
+ import { setTimeout as delay } from "node:timers/promises";
20
+ async function withNativeProbe(binary, args, context, action, observeOutput) {
21
+ context.signal.throwIfAborted();
22
+ const child = spawn(binary, args, {
23
+ cwd: context.cwd,
24
+ env: context.env,
25
+ detached: true,
26
+ stdio: ["ignore", "pipe", "pipe"]
27
+ });
28
+ let output = "";
29
+ const append = (chunk) => {
30
+ output = (output + chunk).slice(-64 * 1024);
31
+ observeOutput?.(output);
32
+ };
33
+ child.stdout.setEncoding("utf8").on("data", append);
34
+ child.stderr.setEncoding("utf8").on("data", append);
35
+ const ended = new AbortController();
36
+ const killGroup = () => {
37
+ if (child.pid) {
38
+ try {
39
+ process.kill(-child.pid, "SIGKILL");
40
+ } catch (error) {
41
+ if (error.code !== "ESRCH")
42
+ throw error;
43
+ }
44
+ }
45
+ };
46
+ let exited = false;
47
+ child.once("error", (error) => {
48
+ append(error.message);
49
+ ended.abort(error);
50
+ });
51
+ child.once("exit", () => {
52
+ killGroup();
53
+ exited = true;
54
+ ended.abort(new Error("Native probe exited."));
55
+ });
56
+ const stop = () => {
57
+ if (!exited)
58
+ killGroup();
59
+ };
60
+ const closed = new Promise((done) => child.once("close", done));
61
+ context.signal.addEventListener("abort", stop, { once: true });
62
+ try {
63
+ return await action({
64
+ closed,
65
+ log: () => output,
66
+ lifetime: AbortSignal.any([context.signal, ended.signal])
67
+ });
68
+ } finally {
69
+ context.signal.removeEventListener("abort", stop);
70
+ stop();
71
+ await closed;
72
+ }
73
+ }
74
+ async function nativeCommand(binary, args, context) {
75
+ const signal = AbortSignal.any([context.signal, AbortSignal.timeout(1e4)]);
76
+ return withNativeProbe(binary, args, { ...context, signal }, async (probe) => {
77
+ const code = await probe.closed;
78
+ signal.throwIfAborted();
79
+ if (code !== 0)
80
+ throw new Error(probe.log().trim().slice(-1500) || `Exited with code ${code}.`);
81
+ return probe.log().trim();
82
+ });
83
+ }
84
+ function socketRequest(socketPath, path, signal, body) {
85
+ return new Promise((done, fail) => {
86
+ const req = request({
87
+ socketPath,
88
+ path,
89
+ signal,
90
+ agent: false,
91
+ method: body ? "POST" : "GET",
92
+ headers: body ? { "Content-Type": "application/json" } : {}
93
+ }, (res) => {
94
+ const chunks = [];
95
+ let bytes = 0;
96
+ res.on("error", fail);
97
+ res.on("data", (chunk) => {
98
+ bytes += chunk.length;
99
+ if (bytes > 1024 * 1024)
100
+ res.destroy(new Error("Validation response exceeded 1 MiB."));
101
+ else
102
+ chunks.push(chunk);
103
+ });
104
+ res.on("end", () => done({
105
+ status: res.statusCode ?? 0,
106
+ body: Buffer.concat(chunks).toString("utf8")
107
+ }));
108
+ });
109
+ req.on("error", fail);
110
+ req.end(body);
111
+ });
112
+ }
113
+ async function requestProbeEmbeddings(socket, inputs2, signal) {
114
+ const startup = AbortSignal.any([signal, AbortSignal.timeout(4e4)]);
115
+ for (; ; ) {
116
+ startup.throwIfAborted();
117
+ try {
118
+ const health = await socketRequest(socket, "/health", startup);
119
+ if (health.status === 200)
120
+ break;
121
+ if (health.status !== 503)
122
+ throw new Error(`Embedding health check returned HTTP ${health.status}.`);
123
+ } catch (error) {
124
+ if (!["ENOENT", "ECONNREFUSED"].includes(error.code ?? ""))
125
+ throw error;
126
+ }
127
+ await delay(100, void 0, { signal: startup });
128
+ }
129
+ const result = await socketRequest(socket, "/v1/embeddings", signal, JSON.stringify({ model: "qualification", input: inputs2 }));
130
+ if (result.status !== 200)
131
+ throw new Error(`Embedding request returned HTTP ${result.status}.`);
132
+ return JSON.parse(result.body);
133
+ }
134
+
135
+ // packages/koed-server/dist/runtime-release-validation.js
136
+ var minimumDriver = "550.54.14";
137
+ var minimumCosine = 0.999;
138
+ var inputs = [
139
+ "The train arrives at noon.",
140
+ "A red kite is flying over the lake.",
141
+ "Measure twice, cut once."
142
+ ];
143
+ var NativeValidationError = class extends Error {
144
+ reason;
145
+ constructor(reason, message2) {
146
+ super(message2);
147
+ this.reason = reason;
148
+ }
149
+ };
150
+ async function checkCudaHost(signal) {
151
+ const context = {
152
+ cwd: "/",
153
+ env: { PATH: "/usr/bin:/bin", LANG: "C", LC_ALL: "C" },
154
+ signal
155
+ };
156
+ let driverVersion;
157
+ try {
158
+ const output = await nativeCommand("/usr/bin/nvidia-smi", ["--query-gpu=driver_version", "--format=csv,noheader"], context);
159
+ const versions = new Set(output.split(/\r?\n/).map((row) => row.trim()));
160
+ driverVersion = [...versions][0] ?? "";
161
+ if (versions.size !== 1 || !/^\d{1,4}\.\d{1,4}(\.\d{1,4})?$/.test(driverVersion))
162
+ throw new Error("No consistent NVIDIA driver version was reported.");
163
+ } catch (error) {
164
+ context.signal.throwIfAborted();
165
+ throw new NativeValidationError("cuda_device_unavailable", `Cannot query the NVIDIA GPU driver: ${message(error)}`);
166
+ }
167
+ const [major, minor, patch = 0] = driverVersion.split(".").map(Number);
168
+ if (compareNativeVersions(`${major}.${minor}.${patch}`, minimumDriver) < 0)
169
+ throw new NativeValidationError("cuda_driver_too_old", `NVIDIA driver ${driverVersion} is older than required ${minimumDriver}.`);
170
+ const loaded = await nativeCommand(process.execPath, [
171
+ "-p",
172
+ String.raw`process.report.getReport().sharedObjects.some(p => /\/libcuda\.so(?:\.\d+)*$/.test(p))`
173
+ ], {
174
+ ...context,
175
+ env: { ...context.env, LD_PRELOAD: "libcuda.so.1" }
176
+ });
177
+ if (loaded !== "true")
178
+ throw new NativeValidationError("cuda_driver_library_unavailable", "The host loader could not load libcuda.so.1.");
179
+ return driverVersion;
180
+ }
181
+ async function discover(root, context) {
182
+ const driverVersion = await checkCudaHost(context.signal);
183
+ const binary = resolve(root, "llama.cpp/cuda/llama-server");
184
+ try {
185
+ const listing = await nativeCommand(binary, ["--list-devices"], {
186
+ ...context,
187
+ env: { ...context.env, LD_LIBRARY_PATH: dirname(binary) }
188
+ });
189
+ const match = /^\s*(CUDA\d+):[ \t]+([^\r\n]+)/m.exec(listing);
190
+ if (!match)
191
+ throw new Error("The staged binary listed no CUDA device.");
192
+ return { driverVersion, device: match[1], description: match[2].trim() };
193
+ } catch (error) {
194
+ context.signal.throwIfAborted();
195
+ throw new NativeValidationError("cuda_device_unavailable", `CUDA device discovery failed: ${message(error)}`);
196
+ }
197
+ }
198
+ var message = (error) => error instanceof Error ? error.message : String(error);
199
+ var responseSchema = external_exports.object({
200
+ data: external_exports.array(external_exports.object({
201
+ index: external_exports.number().int(),
202
+ embedding: external_exports.array(external_exports.number().finite()).min(1)
203
+ })).length(inputs.length)
204
+ });
205
+ function vectors(body) {
206
+ const parsed = responseSchema.safeParse(body);
207
+ if (!parsed.success)
208
+ throw new NativeValidationError("vector_agreement_failed", "Expected one finite, nonempty embedding per test input.");
209
+ const rows = parsed.data.data.sort((a, b) => a.index - b.index);
210
+ if (rows.some((row, index) => row.index !== index))
211
+ throw new NativeValidationError("vector_agreement_failed", "The embedding response did not identify each input exactly once.");
212
+ return rows.map((row) => row.embedding);
213
+ }
214
+ async function embed(root, model, device, context) {
215
+ const backend = device ? "cuda" : "cpu";
216
+ const binary = resolve(root, `llama.cpp/${backend}/llama-server`);
217
+ const socket = join(context.cwd, `${backend}.sock`);
218
+ const args = [
219
+ "--model",
220
+ model,
221
+ "--alias",
222
+ "qualification",
223
+ "--embedding",
224
+ "--pooling",
225
+ "last",
226
+ "--ctx-size",
227
+ "2048",
228
+ "--batch-size",
229
+ "512",
230
+ "--ubatch-size",
231
+ "512",
232
+ "--parallel",
233
+ "1",
234
+ "--threads",
235
+ "2",
236
+ "--threads-batch",
237
+ "2",
238
+ "--n-gpu-layers",
239
+ device ? "all" : "0",
240
+ "--device",
241
+ device ?? "none",
242
+ "--fit",
243
+ "off",
244
+ "--host",
245
+ socket,
246
+ "-lv",
247
+ "4"
248
+ ];
249
+ let offloaded = false, allocationFailed = false;
250
+ return withNativeProbe(binary, args, { ...context, env: { ...context.env, LD_LIBRARY_PATH: dirname(binary) } }, async (probe) => {
251
+ try {
252
+ const result = vectors(await requestProbeEmbeddings(socket, inputs, probe.lifetime));
253
+ if (device && !offloaded)
254
+ throw new NativeValidationError("cuda_offload_unconfirmed", "The staged server did not confirm GPU layer offload.");
255
+ return result;
256
+ } catch (error) {
257
+ context.signal.throwIfAborted();
258
+ if (probe.lifetime.aborted)
259
+ await probe.closed;
260
+ const log = probe.log();
261
+ if (device && allocationFailed)
262
+ throw new NativeValidationError("cuda_memory_pressure", "CUDA ran out of VRAM during validation. Check nvidia-smi for competing GPU workloads and retry.");
263
+ if (error instanceof NativeValidationError)
264
+ throw error;
265
+ throw new NativeValidationError("inference_failed", `${backend.toUpperCase()} embedding probe failed: ${message(error)} ${log.slice(-650).trim()}`);
266
+ }
267
+ }, (tail) => {
268
+ offloaded ||= /offloaded [1-9]\d*\/\d+ layers to GPU/i.test(tail);
269
+ allocationFailed ||= /out of memory|cudaErrorMemoryAllocation|cudaMalloc.*fail/i.test(tail);
270
+ });
271
+ }
272
+ function compare(cpu, gpu) {
273
+ const dimensions = cpu[0].length;
274
+ return cpu.map((left, i) => {
275
+ const right = gpu[i];
276
+ if (left.length !== dimensions || right.length !== dimensions)
277
+ throw new NativeValidationError("vector_agreement_failed", `Embedding dimensions differ for input ${i + 1}.`);
278
+ let dot = 0, normA = 0, normB = 0;
279
+ for (let j = 0; j < dimensions; j++) {
280
+ const a = left[j], b = right[j];
281
+ dot += a * b;
282
+ normA += a * a;
283
+ normB += b * b;
284
+ }
285
+ const cosine = dot / (Math.sqrt(normA) * Math.sqrt(normB));
286
+ if (!Number.isFinite(cosine) || cosine < minimumCosine)
287
+ throw new NativeValidationError("vector_agreement_failed", `CPU/GPU agreement failed for input ${i + 1}: cosine ${cosine}; required ${minimumCosine}.`);
288
+ return { dimensions, cosine };
289
+ });
290
+ }
291
+ async function validateStagedCuda(paths, root, environment, options) {
292
+ const signal = AbortSignal.any([
293
+ options.signal,
294
+ AbortSignal.timeout(12e4)
295
+ ]);
296
+ const cwd = mkdtempSync("/tmp/koed-native-probe-");
297
+ try {
298
+ const env = {
299
+ PATH: "/usr/bin:/bin",
300
+ LANG: "C",
301
+ LC_ALL: "C",
302
+ HOME: cwd,
303
+ TMPDIR: cwd
304
+ };
305
+ for (const key of ["CUDA_VISIBLE_DEVICES", "CUDA_DEVICE_ORDER"])
306
+ if (environment[key] !== void 0)
307
+ env[key] = environment[key];
308
+ const context = { cwd, env, signal };
309
+ const device = await discover(root, context);
310
+ const model = await collectLocalModelStatus(paths, "embedding", environment, signal);
311
+ signal.throwIfAborted();
312
+ if (model.state === "missing" && !options.requireModel)
313
+ return {
314
+ ok: true,
315
+ scope: "device-only",
316
+ ...device,
317
+ message: "CUDA device discovery passed. Install the embedding model for inference validation."
318
+ };
319
+ if (model.state !== "installed")
320
+ throw new NativeValidationError(`model_${model.state}`, model.message);
321
+ const cpu = await embed(root, model.modelPath, null, context);
322
+ const gpu = await embed(root, model.modelPath, device.device, context);
323
+ const agreement = compare(cpu, gpu);
324
+ signal.throwIfAborted();
325
+ return {
326
+ ok: true,
327
+ scope: "inference",
328
+ ...device,
329
+ modelSha256: model.sha256,
330
+ minimumCosine,
331
+ agreement,
332
+ message: "CUDA device discovery, GPU offload and CPU/GPU embedding agreement passed."
333
+ };
334
+ } finally {
335
+ rmSync(cwd, { recursive: true, force: true });
336
+ }
337
+ }
338
+
339
+ export {
340
+ nativeCommand,
341
+ checkCudaHost,
342
+ validateStagedCuda
343
+ };
@@ -1,7 +1,8 @@
1
1
  import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
2
  import {
3
+ assertNoReleaseRuntime,
3
4
  resolvePackagedKoedRuntimeRoot
4
- } from "./chunk-UI5RLBKQ.js";
5
+ } from "./chunk-YZLQZU5E.js";
5
6
  import "./chunk-BTS4ZTF3.js";
6
7
 
7
8
  // packages/koed-server/dist/runtime-packaged.js
@@ -415,6 +416,7 @@ var copyAsset = (paths, root, asset) => {
415
416
  return target;
416
417
  };
417
418
  var installPackagedRuntime = (paths, environment = process.env, dependencies = {}) => {
419
+ assertNoReleaseRuntime(paths);
418
420
  const root = resolvePackagedKoedRuntimeRoot(environment);
419
421
  const platform = dependencies.platform ?? process.platform;
420
422
  const architecture = dependencies.architecture ?? process.arch;