@kya-os/checkpoint-wasm-runtime 1.0.0 → 1.1.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 (47) hide show
  1. package/CHANGELOG.md +166 -0
  2. package/dist/adapters.js +0 -2
  3. package/dist/adapters.mjs +0 -2
  4. package/dist/edge.js +0 -2
  5. package/dist/edge.mjs +0 -2
  6. package/dist/engine-edge.js +0 -2
  7. package/dist/engine-edge.mjs +0 -2
  8. package/dist/engine.js +447 -4
  9. package/dist/engine.mjs +447 -4
  10. package/dist/index.js +0 -2
  11. package/dist/index.mjs +0 -2
  12. package/dist/kya_os_engine_bg.wasm +0 -0
  13. package/dist/node.js +0 -2
  14. package/dist/node.mjs +0 -2
  15. package/dist/orchestrator-edge.d.mts +5 -199
  16. package/dist/orchestrator-edge.d.ts +5 -199
  17. package/dist/orchestrator-edge.js +0 -2
  18. package/dist/orchestrator-edge.mjs +0 -2
  19. package/dist/orchestrator-node.d.mts +49 -0
  20. package/dist/orchestrator-node.d.ts +49 -0
  21. package/dist/orchestrator-node.js +992 -0
  22. package/dist/orchestrator-node.mjs +983 -0
  23. package/dist/orchestrator.d.mts +4 -47
  24. package/dist/orchestrator.d.ts +4 -47
  25. package/dist/orchestrator.js +448 -8
  26. package/dist/orchestrator.mjs +448 -8
  27. package/dist/render-decision-C1a-iuiW.d.mts +200 -0
  28. package/dist/render-decision-Dsjwt96g.d.ts +200 -0
  29. package/package.json +14 -2
  30. package/wasm/kya-os-engine/package.json +7 -0
  31. package/wasm/kya-os-engine-web/package.json +7 -0
  32. package/dist/adapters.js.map +0 -1
  33. package/dist/adapters.mjs.map +0 -1
  34. package/dist/edge.js.map +0 -1
  35. package/dist/edge.mjs.map +0 -1
  36. package/dist/engine-edge.js.map +0 -1
  37. package/dist/engine-edge.mjs.map +0 -1
  38. package/dist/engine.js.map +0 -1
  39. package/dist/engine.mjs.map +0 -1
  40. package/dist/index.js.map +0 -1
  41. package/dist/index.mjs.map +0 -1
  42. package/dist/node.js.map +0 -1
  43. package/dist/node.mjs.map +0 -1
  44. package/dist/orchestrator-edge.js.map +0 -1
  45. package/dist/orchestrator-edge.mjs.map +0 -1
  46. package/dist/orchestrator.js.map +0 -1
  47. package/dist/orchestrator.mjs.map +0 -1
@@ -0,0 +1,992 @@
1
+ 'use strict';
2
+
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
+ }) : x)(function(x) {
12
+ if (typeof require !== "undefined") return require.apply(this, arguments);
13
+ throw Error('Dynamic require of "' + x + '" is not supported');
14
+ });
15
+ var __commonJS = (cb, mod) => function __require2() {
16
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
+ // If the importer is in node compatibility mode or this is not an ESM
28
+ // file that has been converted to a CommonJS file using a Babel-
29
+ // compatible transform (i.e. "__esModule" has not been set), then set
30
+ // "default" to the CommonJS "module.exports" for node compatibility.
31
+ !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
+ mod
33
+ ));
34
+
35
+ // wasm/kya-os-engine/kya_os_engine.js
36
+ var require_kya_os_engine = __commonJS({
37
+ "wasm/kya-os-engine/kya_os_engine.js"(exports$1, module) {
38
+ var imports = {};
39
+ imports["__wbindgen_placeholder__"] = module.exports;
40
+ var cachedUint8ArrayMemory0 = null;
41
+ function getUint8ArrayMemory0() {
42
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
43
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
44
+ }
45
+ return cachedUint8ArrayMemory0;
46
+ }
47
+ var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
48
+ cachedTextDecoder.decode();
49
+ function decodeText(ptr, len) {
50
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
51
+ }
52
+ function getStringFromWasm0(ptr, len) {
53
+ ptr = ptr >>> 0;
54
+ return decodeText(ptr, len);
55
+ }
56
+ var heap = new Array(128).fill(void 0);
57
+ heap.push(void 0, null, true, false);
58
+ var heap_next = heap.length;
59
+ function addHeapObject(obj) {
60
+ if (heap_next === heap.length) heap.push(heap.length + 1);
61
+ const idx = heap_next;
62
+ heap_next = heap[idx];
63
+ heap[idx] = obj;
64
+ return idx;
65
+ }
66
+ function getObject(idx) {
67
+ return heap[idx];
68
+ }
69
+ var WASM_VECTOR_LEN = 0;
70
+ var cachedTextEncoder = new TextEncoder();
71
+ if (!("encodeInto" in cachedTextEncoder)) {
72
+ cachedTextEncoder.encodeInto = function(arg, view) {
73
+ const buf = cachedTextEncoder.encode(arg);
74
+ view.set(buf);
75
+ return {
76
+ read: arg.length,
77
+ written: buf.length
78
+ };
79
+ };
80
+ }
81
+ function passStringToWasm0(arg, malloc, realloc) {
82
+ if (realloc === void 0) {
83
+ const buf = cachedTextEncoder.encode(arg);
84
+ const ptr2 = malloc(buf.length, 1) >>> 0;
85
+ getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
86
+ WASM_VECTOR_LEN = buf.length;
87
+ return ptr2;
88
+ }
89
+ let len = arg.length;
90
+ let ptr = malloc(len, 1) >>> 0;
91
+ const mem = getUint8ArrayMemory0();
92
+ let offset = 0;
93
+ for (; offset < len; offset++) {
94
+ const code = arg.charCodeAt(offset);
95
+ if (code > 127) break;
96
+ mem[ptr + offset] = code;
97
+ }
98
+ if (offset !== len) {
99
+ if (offset !== 0) {
100
+ arg = arg.slice(offset);
101
+ }
102
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
103
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
104
+ const ret = cachedTextEncoder.encodeInto(arg, view);
105
+ offset += ret.written;
106
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
107
+ }
108
+ WASM_VECTOR_LEN = offset;
109
+ return ptr;
110
+ }
111
+ var cachedDataViewMemory0 = null;
112
+ function getDataViewMemory0() {
113
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
114
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
115
+ }
116
+ return cachedDataViewMemory0;
117
+ }
118
+ function isLikeNone(x) {
119
+ return x === void 0 || x === null;
120
+ }
121
+ function debugString(val) {
122
+ const type = typeof val;
123
+ if (type == "number" || type == "boolean" || val == null) {
124
+ return `${val}`;
125
+ }
126
+ if (type == "string") {
127
+ return `"${val}"`;
128
+ }
129
+ if (type == "symbol") {
130
+ const description = val.description;
131
+ if (description == null) {
132
+ return "Symbol";
133
+ } else {
134
+ return `Symbol(${description})`;
135
+ }
136
+ }
137
+ if (type == "function") {
138
+ const name = val.name;
139
+ if (typeof name == "string" && name.length > 0) {
140
+ return `Function(${name})`;
141
+ } else {
142
+ return "Function";
143
+ }
144
+ }
145
+ if (Array.isArray(val)) {
146
+ const length = val.length;
147
+ let debug = "[";
148
+ if (length > 0) {
149
+ debug += debugString(val[0]);
150
+ }
151
+ for (let i = 1; i < length; i++) {
152
+ debug += ", " + debugString(val[i]);
153
+ }
154
+ debug += "]";
155
+ return debug;
156
+ }
157
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
158
+ let className;
159
+ if (builtInMatches && builtInMatches.length > 1) {
160
+ className = builtInMatches[1];
161
+ } else {
162
+ return toString.call(val);
163
+ }
164
+ if (className == "Object") {
165
+ try {
166
+ return "Object(" + JSON.stringify(val) + ")";
167
+ } catch (_) {
168
+ return "Object";
169
+ }
170
+ }
171
+ if (val instanceof Error) {
172
+ return `${val.name}: ${val.message}
173
+ ${val.stack}`;
174
+ }
175
+ return className;
176
+ }
177
+ function handleError(f, args) {
178
+ try {
179
+ return f.apply(this, args);
180
+ } catch (e) {
181
+ wasm.__wbindgen_export3(addHeapObject(e));
182
+ }
183
+ }
184
+ function getArrayU8FromWasm0(ptr, len) {
185
+ ptr = ptr >>> 0;
186
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
187
+ }
188
+ function dropObject(idx) {
189
+ if (idx < 132) return;
190
+ heap[idx] = heap_next;
191
+ heap_next = idx;
192
+ }
193
+ function takeObject(idx) {
194
+ const ret = getObject(idx);
195
+ dropObject(idx);
196
+ return ret;
197
+ }
198
+ exports$1.verify = function(input_js, ctx_js) {
199
+ try {
200
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
201
+ wasm.verify(retptr, addHeapObject(input_js), addHeapObject(ctx_js));
202
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
203
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
204
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
205
+ if (r2) {
206
+ throw takeObject(r1);
207
+ }
208
+ return takeObject(r0);
209
+ } finally {
210
+ wasm.__wbindgen_add_to_stack_pointer(16);
211
+ }
212
+ };
213
+ exports$1.__wbg_Error_e83987f665cf5504 = function(arg0, arg1) {
214
+ const ret = Error(getStringFromWasm0(arg0, arg1));
215
+ return addHeapObject(ret);
216
+ };
217
+ exports$1.__wbg_Number_bb48ca12f395cd08 = function(arg0) {
218
+ const ret = Number(getObject(arg0));
219
+ return ret;
220
+ };
221
+ exports$1.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
222
+ const ret = String(getObject(arg1));
223
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
224
+ const len1 = WASM_VECTOR_LEN;
225
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
226
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
227
+ };
228
+ exports$1.__wbg___wbindgen_bigint_get_as_i64_f3ebc5a755000afd = function(arg0, arg1) {
229
+ const v = getObject(arg1);
230
+ const ret = typeof v === "bigint" ? v : void 0;
231
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
232
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
233
+ };
234
+ exports$1.__wbg___wbindgen_boolean_get_6d5a1ee65bab5f68 = function(arg0) {
235
+ const v = getObject(arg0);
236
+ const ret = typeof v === "boolean" ? v : void 0;
237
+ return isLikeNone(ret) ? 16777215 : ret ? 1 : 0;
238
+ };
239
+ exports$1.__wbg___wbindgen_debug_string_df47ffb5e35e6763 = function(arg0, arg1) {
240
+ const ret = debugString(getObject(arg1));
241
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
242
+ const len1 = WASM_VECTOR_LEN;
243
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
244
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
245
+ };
246
+ exports$1.__wbg___wbindgen_in_bb933bd9e1b3bc0f = function(arg0, arg1) {
247
+ const ret = getObject(arg0) in getObject(arg1);
248
+ return ret;
249
+ };
250
+ exports$1.__wbg___wbindgen_is_bigint_cb320707dcd35f0b = function(arg0) {
251
+ const ret = typeof getObject(arg0) === "bigint";
252
+ return ret;
253
+ };
254
+ exports$1.__wbg___wbindgen_is_function_ee8a6c5833c90377 = function(arg0) {
255
+ const ret = typeof getObject(arg0) === "function";
256
+ return ret;
257
+ };
258
+ exports$1.__wbg___wbindgen_is_object_c818261d21f283a4 = function(arg0) {
259
+ const val = getObject(arg0);
260
+ const ret = typeof val === "object" && val !== null;
261
+ return ret;
262
+ };
263
+ exports$1.__wbg___wbindgen_is_string_fbb76cb2940daafd = function(arg0) {
264
+ const ret = typeof getObject(arg0) === "string";
265
+ return ret;
266
+ };
267
+ exports$1.__wbg___wbindgen_is_undefined_2d472862bd29a478 = function(arg0) {
268
+ const ret = getObject(arg0) === void 0;
269
+ return ret;
270
+ };
271
+ exports$1.__wbg___wbindgen_jsval_eq_6b13ab83478b1c50 = function(arg0, arg1) {
272
+ const ret = getObject(arg0) === getObject(arg1);
273
+ return ret;
274
+ };
275
+ exports$1.__wbg___wbindgen_jsval_loose_eq_b664b38a2f582147 = function(arg0, arg1) {
276
+ const ret = getObject(arg0) == getObject(arg1);
277
+ return ret;
278
+ };
279
+ exports$1.__wbg___wbindgen_number_get_a20bf9b85341449d = function(arg0, arg1) {
280
+ const obj = getObject(arg1);
281
+ const ret = typeof obj === "number" ? obj : void 0;
282
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
283
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
284
+ };
285
+ exports$1.__wbg___wbindgen_string_get_e4f06c90489ad01b = function(arg0, arg1) {
286
+ const obj = getObject(arg1);
287
+ const ret = typeof obj === "string" ? obj : void 0;
288
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
289
+ var len1 = WASM_VECTOR_LEN;
290
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
291
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
292
+ };
293
+ exports$1.__wbg___wbindgen_throw_b855445ff6a94295 = function(arg0, arg1) {
294
+ throw new Error(getStringFromWasm0(arg0, arg1));
295
+ };
296
+ exports$1.__wbg_call_e762c39fa8ea36bf = function() {
297
+ return handleError(function(arg0, arg1) {
298
+ const ret = getObject(arg0).call(getObject(arg1));
299
+ return addHeapObject(ret);
300
+ }, arguments);
301
+ };
302
+ exports$1.__wbg_done_2042aa2670fb1db1 = function(arg0) {
303
+ const ret = getObject(arg0).done;
304
+ return ret;
305
+ };
306
+ exports$1.__wbg_entries_e171b586f8f6bdbf = function(arg0) {
307
+ const ret = Object.entries(getObject(arg0));
308
+ return addHeapObject(ret);
309
+ };
310
+ exports$1.__wbg_get_7bed016f185add81 = function(arg0, arg1) {
311
+ const ret = getObject(arg0)[arg1 >>> 0];
312
+ return addHeapObject(ret);
313
+ };
314
+ exports$1.__wbg_get_efcb449f58ec27c2 = function() {
315
+ return handleError(function(arg0, arg1) {
316
+ const ret = Reflect.get(getObject(arg0), getObject(arg1));
317
+ return addHeapObject(ret);
318
+ }, arguments);
319
+ };
320
+ exports$1.__wbg_get_with_ref_key_1dc361bd10053bfe = function(arg0, arg1) {
321
+ const ret = getObject(arg0)[getObject(arg1)];
322
+ return addHeapObject(ret);
323
+ };
324
+ exports$1.__wbg_instanceof_ArrayBuffer_70beb1189ca63b38 = function(arg0) {
325
+ let result;
326
+ try {
327
+ result = getObject(arg0) instanceof ArrayBuffer;
328
+ } catch (_) {
329
+ result = false;
330
+ }
331
+ const ret = result;
332
+ return ret;
333
+ };
334
+ exports$1.__wbg_instanceof_Map_8579b5e2ab5437c7 = function(arg0) {
335
+ let result;
336
+ try {
337
+ result = getObject(arg0) instanceof Map;
338
+ } catch (_) {
339
+ result = false;
340
+ }
341
+ const ret = result;
342
+ return ret;
343
+ };
344
+ exports$1.__wbg_instanceof_Uint8Array_20c8e73002f7af98 = function(arg0) {
345
+ let result;
346
+ try {
347
+ result = getObject(arg0) instanceof Uint8Array;
348
+ } catch (_) {
349
+ result = false;
350
+ }
351
+ const ret = result;
352
+ return ret;
353
+ };
354
+ exports$1.__wbg_isArray_96e0af9891d0945d = function(arg0) {
355
+ const ret = Array.isArray(getObject(arg0));
356
+ return ret;
357
+ };
358
+ exports$1.__wbg_isSafeInteger_d216eda7911dde36 = function(arg0) {
359
+ const ret = Number.isSafeInteger(getObject(arg0));
360
+ return ret;
361
+ };
362
+ exports$1.__wbg_iterator_e5822695327a3c39 = function() {
363
+ const ret = Symbol.iterator;
364
+ return addHeapObject(ret);
365
+ };
366
+ exports$1.__wbg_length_69bca3cb64fc8748 = function(arg0) {
367
+ const ret = getObject(arg0).length;
368
+ return ret;
369
+ };
370
+ exports$1.__wbg_length_cdd215e10d9dd507 = function(arg0) {
371
+ const ret = getObject(arg0).length;
372
+ return ret;
373
+ };
374
+ exports$1.__wbg_new_1acc0b6eea89d040 = function() {
375
+ const ret = new Object();
376
+ return addHeapObject(ret);
377
+ };
378
+ exports$1.__wbg_new_5a79be3ab53b8aa5 = function(arg0) {
379
+ const ret = new Uint8Array(getObject(arg0));
380
+ return addHeapObject(ret);
381
+ };
382
+ exports$1.__wbg_new_68651c719dcda04e = function() {
383
+ const ret = /* @__PURE__ */ new Map();
384
+ return addHeapObject(ret);
385
+ };
386
+ exports$1.__wbg_new_e17d9f43105b08be = function() {
387
+ const ret = new Array();
388
+ return addHeapObject(ret);
389
+ };
390
+ exports$1.__wbg_next_020810e0ae8ebcb0 = function() {
391
+ return handleError(function(arg0) {
392
+ const ret = getObject(arg0).next();
393
+ return addHeapObject(ret);
394
+ }, arguments);
395
+ };
396
+ exports$1.__wbg_next_2c826fe5dfec6b6a = function(arg0) {
397
+ const ret = getObject(arg0).next;
398
+ return addHeapObject(ret);
399
+ };
400
+ exports$1.__wbg_prototypesetcall_2a6620b6922694b2 = function(arg0, arg1, arg2) {
401
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
402
+ };
403
+ exports$1.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
404
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
405
+ };
406
+ exports$1.__wbg_set_907fb406c34a251d = function(arg0, arg1, arg2) {
407
+ const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
408
+ return addHeapObject(ret);
409
+ };
410
+ exports$1.__wbg_set_c213c871859d6500 = function(arg0, arg1, arg2) {
411
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
412
+ };
413
+ exports$1.__wbg_value_692627309814bb8c = function(arg0) {
414
+ const ret = getObject(arg0).value;
415
+ return addHeapObject(ret);
416
+ };
417
+ exports$1.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
418
+ const ret = getStringFromWasm0(arg0, arg1);
419
+ return addHeapObject(ret);
420
+ };
421
+ exports$1.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
422
+ const ret = BigInt.asUintN(64, arg0);
423
+ return addHeapObject(ret);
424
+ };
425
+ exports$1.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
426
+ const ret = arg0;
427
+ return addHeapObject(ret);
428
+ };
429
+ exports$1.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
430
+ const ret = arg0;
431
+ return addHeapObject(ret);
432
+ };
433
+ exports$1.__wbindgen_object_clone_ref = function(arg0) {
434
+ const ret = getObject(arg0);
435
+ return addHeapObject(ret);
436
+ };
437
+ exports$1.__wbindgen_object_drop_ref = function(arg0) {
438
+ takeObject(arg0);
439
+ };
440
+ var wasmPath = `${__dirname}/kya_os_engine_bg.wasm`;
441
+ var wasmBytes = __require("fs").readFileSync(wasmPath);
442
+ var wasmModule2 = new WebAssembly.Module(wasmBytes);
443
+ var wasm = exports$1.__wasm = new WebAssembly.Instance(wasmModule2, imports).exports;
444
+ }
445
+ });
446
+
447
+ // src/engine/adapters/outbound-url-policy.ts
448
+ var BLOCKED_HOSTNAMES = /* @__PURE__ */ new Set(["localhost", "metadata", "metadata.google.internal"]);
449
+ var UnsafeOutboundUrl = class extends Error {
450
+ kind = "UnsafeOutboundUrl";
451
+ };
452
+ function assertSafeHttpsUrl(rawUrl, label = "outbound URL") {
453
+ let parsed;
454
+ try {
455
+ parsed = new URL(rawUrl);
456
+ } catch {
457
+ throw new UnsafeOutboundUrl(`${label} must be a valid URL: ${rawUrl}`);
458
+ }
459
+ if (parsed.protocol !== "https:") {
460
+ throw new UnsafeOutboundUrl(`${label} must use https: ${rawUrl}`);
461
+ }
462
+ if (parsed.username || parsed.password) {
463
+ throw new UnsafeOutboundUrl(`${label} must not contain credentials: ${rawUrl}`);
464
+ }
465
+ const hostname = normalizeHostname(parsed.hostname);
466
+ if (!hostname || isBlockedHostname(hostname)) {
467
+ throw new UnsafeOutboundUrl(`${label} targets a local or private host: ${rawUrl}`);
468
+ }
469
+ return rawUrl;
470
+ }
471
+ function normalizeHostname(hostname) {
472
+ let normalized = hostname.trim().toLowerCase();
473
+ if (normalized.startsWith("[") && normalized.endsWith("]")) {
474
+ normalized = normalized.slice(1, -1);
475
+ }
476
+ while (normalized.endsWith(".")) {
477
+ normalized = normalized.slice(0, -1);
478
+ }
479
+ return normalized;
480
+ }
481
+ function isBlockedHostname(hostname) {
482
+ if (BLOCKED_HOSTNAMES.has(hostname) || hostname.endsWith(".localhost")) {
483
+ return true;
484
+ }
485
+ const ipv4 = parseIpv4(hostname);
486
+ if (ipv4) {
487
+ return isBlockedIpv4(ipv4);
488
+ }
489
+ return isBlockedIpv6(hostname);
490
+ }
491
+ function parseIpv4(hostname) {
492
+ const parts = hostname.split(".");
493
+ if (parts.length !== 4) return null;
494
+ const octets = parts.map((part) => {
495
+ if (!/^\d{1,3}$/.test(part)) return Number.NaN;
496
+ const value = Number(part);
497
+ return value >= 0 && value <= 255 ? value : Number.NaN;
498
+ });
499
+ if (octets.some(Number.isNaN)) return null;
500
+ return octets;
501
+ }
502
+ function isBlockedIpv4([a, b]) {
503
+ return a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168 || a === 198 && (b === 18 || b === 19) || a >= 224;
504
+ }
505
+ function isBlockedIpv6(hostname) {
506
+ if (!hostname.includes(":")) return false;
507
+ const ipv4Mapped = hostname.match(/(?:^|:)ffff:(\d{1,3}(?:\.\d{1,3}){3})$/);
508
+ if (ipv4Mapped) {
509
+ const ipv4 = parseIpv4(ipv4Mapped[1]);
510
+ return ipv4 ? isBlockedIpv4(ipv4) : true;
511
+ }
512
+ if (hostname === "::" || hostname === "::1" || hostname === "0:0:0:0:0:0:0:1") {
513
+ return true;
514
+ }
515
+ const firstSegment = Number.parseInt(hostname.split(":")[0] || "0", 16);
516
+ if (Number.isNaN(firstSegment)) return true;
517
+ return (firstSegment & 65024) === 64512 || // unique local fc00::/7
518
+ (firstSegment & 65472) === 65152 || // link-local fe80::/10
519
+ (firstSegment & 65280) === 65280;
520
+ }
521
+
522
+ // src/engine/index.ts
523
+ var wasmModule = __toESM(require_kya_os_engine());
524
+ function engineVerify(input, ctx) {
525
+ const verify2 = wasmModule.verify;
526
+ return verify2(input, ctx);
527
+ }
528
+
529
+ // src/engine/adapters/util.ts
530
+ function base64UrlDecode(input) {
531
+ const padded = input.replace(/-/g, "+").replace(/_/g, "/");
532
+ const padding = padded.length % 4 === 0 ? "" : "=".repeat(4 - padded.length % 4);
533
+ return new Uint8Array(Buffer.from(padded + padding, "base64"));
534
+ }
535
+
536
+ // src/engine/orchestrator/build-agent-request.ts
537
+ function buildAgentRequest(req, opts = {}) {
538
+ const mcpI = tryBuildMcpIFromBody(req);
539
+ if (mcpI) {
540
+ return { protocol: "McpI", request: mcpI };
541
+ }
542
+ if (opts.legacyEnvelopeFallback) {
543
+ const legacyMcpI = tryBuildMcpIFromLegacyHeader(req);
544
+ if (legacyMcpI) {
545
+ return { protocol: "McpI", request: legacyMcpI };
546
+ }
547
+ }
548
+ if (getHeader(req, "signature-input")) {
549
+ return { protocol: "HttpSigned", request: buildHttpSigned(req) };
550
+ }
551
+ return { protocol: "PlainHttp", request: buildPlainHttp(req) };
552
+ }
553
+ function hasMalformedJwsBody(req) {
554
+ const parsed = parseBodyAsObject(req.body);
555
+ if (!parsed || typeof parsed !== "object") return false;
556
+ const meta = parsed._meta;
557
+ if (!meta || typeof meta !== "object") return false;
558
+ const proof = meta.proof;
559
+ if (!proof || typeof proof !== "object") return false;
560
+ const jws = proof.jws;
561
+ if (typeof jws !== "string" || jws.length === 0) return false;
562
+ const raw = Array.from(Buffer.from(jws, "utf8"));
563
+ return parseJwsPayloadStruct(raw) === null;
564
+ }
565
+ function extractIssuer(request) {
566
+ if (request.protocol === "McpI") return request.request.payload.iss || null;
567
+ return null;
568
+ }
569
+ function extractAgentDid(request) {
570
+ if (request.protocol === "McpI") return request.request.payload.sub || null;
571
+ return null;
572
+ }
573
+ function extractCredentialStatusUrl(request) {
574
+ if (request.protocol !== "McpI") return null;
575
+ const raw = decodeJwsPayloadJson(request.request.raw);
576
+ if (!raw) return null;
577
+ const vc = raw.vc;
578
+ if (!vc || typeof vc !== "object") return null;
579
+ const credentialStatus = vc.credentialStatus;
580
+ if (!credentialStatus || typeof credentialStatus !== "object") return null;
581
+ const id = credentialStatus.id;
582
+ return typeof id === "string" ? id : null;
583
+ }
584
+ function tryBuildMcpIFromBody(req) {
585
+ const parsed = parseBodyAsObject(req.body);
586
+ if (!parsed) return null;
587
+ const meta = parsed._meta;
588
+ if (!meta || typeof meta !== "object") return null;
589
+ const proof = meta.proof;
590
+ if (!proof || typeof proof !== "object") return null;
591
+ const jws = proof.jws;
592
+ if (typeof jws !== "string" || jws.length === 0) return null;
593
+ const raw = Array.from(Buffer.from(jws, "utf8"));
594
+ const payload = parseJwsPayloadStruct(raw);
595
+ if (!payload) return null;
596
+ return { raw, payload };
597
+ }
598
+ function parseBodyAsObject(body) {
599
+ if (!body) return null;
600
+ if (Buffer.isBuffer(body)) {
601
+ try {
602
+ return JSON.parse(body.toString("utf8"));
603
+ } catch {
604
+ return null;
605
+ }
606
+ }
607
+ if (typeof body === "string") {
608
+ try {
609
+ return JSON.parse(body);
610
+ } catch {
611
+ return null;
612
+ }
613
+ }
614
+ if (typeof body === "object") return body;
615
+ return null;
616
+ }
617
+ function tryBuildMcpIFromLegacyHeader(req) {
618
+ const header = getHeader(req, "kya-delegation");
619
+ if (!header) return null;
620
+ let parsed;
621
+ try {
622
+ parsed = JSON.parse(header);
623
+ } catch {
624
+ return null;
625
+ }
626
+ if (!parsed || typeof parsed !== "object") return null;
627
+ const obj = parsed;
628
+ const protectedSeg = obj.protected;
629
+ const payloadSeg = obj.payload;
630
+ const signatureSeg = obj.signature;
631
+ if (typeof protectedSeg !== "string" || typeof payloadSeg !== "string" || typeof signatureSeg !== "string") {
632
+ return null;
633
+ }
634
+ const compact = `${protectedSeg}.${payloadSeg}.${signatureSeg}`;
635
+ const raw = Array.from(Buffer.from(compact, "utf8"));
636
+ const payload = parseJwsPayloadStruct(raw);
637
+ if (!payload) return null;
638
+ return { raw, payload };
639
+ }
640
+ function parseJwsPayloadStruct(rawBytes) {
641
+ const json = decodeJwsPayloadJson(rawBytes);
642
+ if (!json || typeof json !== "object") return null;
643
+ return projectMcpIPayload(json);
644
+ }
645
+ function decodeJwsPayloadJson(rawBytes) {
646
+ const text = Buffer.from(rawBytes).toString("utf8");
647
+ const segments = text.split(".");
648
+ if (segments.length !== 3) return null;
649
+ let decoded;
650
+ try {
651
+ decoded = base64UrlDecode(segments[1]);
652
+ } catch {
653
+ return null;
654
+ }
655
+ try {
656
+ return JSON.parse(Buffer.from(decoded).toString("utf8"));
657
+ } catch {
658
+ return null;
659
+ }
660
+ }
661
+ function projectMcpIPayload(raw) {
662
+ const aud = raw.aud;
663
+ const iss = raw.iss;
664
+ const sub = raw.sub;
665
+ const nonce = raw.nonce;
666
+ const sessionId = raw.sessionId;
667
+ const ts = raw.ts;
668
+ const requestHash = raw.requestHash;
669
+ const responseHash = raw.responseHash;
670
+ if (typeof aud !== "string" || typeof iss !== "string" || typeof sub !== "string" || typeof nonce !== "string" || typeof sessionId !== "string" || typeof ts !== "number" || typeof requestHash !== "string" || typeof responseHash !== "string") {
671
+ return null;
672
+ }
673
+ return { aud, iss, sub, nonce, sessionId, ts, requestHash, responseHash };
674
+ }
675
+ function buildHttpSigned(req) {
676
+ return {
677
+ raw: bodyAsBytes(req.body),
678
+ method: req.method,
679
+ path: req.url,
680
+ headers: flattenHeaders(req.headers)
681
+ };
682
+ }
683
+ function buildPlainHttp(req) {
684
+ return {
685
+ raw: bodyAsBytes(req.body),
686
+ method: req.method,
687
+ path: req.url,
688
+ headers: flattenHeaders(req.headers),
689
+ userAgent: getHeader(req, "user-agent") ?? null,
690
+ remoteIp: req.remoteAddress ?? null
691
+ };
692
+ }
693
+ function getHeader(req, name) {
694
+ const lowered = name.toLowerCase();
695
+ for (const [key, value] of Object.entries(req.headers)) {
696
+ if (key.toLowerCase() !== lowered) continue;
697
+ if (Array.isArray(value)) return value[0] ?? null;
698
+ if (typeof value === "string") return value;
699
+ }
700
+ return null;
701
+ }
702
+ function flattenHeaders(headers) {
703
+ const out = [];
704
+ for (const [key, value] of Object.entries(headers)) {
705
+ if (value === void 0) continue;
706
+ if (Array.isArray(value)) {
707
+ for (const v of value) out.push([key, v]);
708
+ } else {
709
+ out.push([key, value]);
710
+ }
711
+ }
712
+ return out;
713
+ }
714
+ function bodyAsBytes(body) {
715
+ if (!body) return [];
716
+ if (Buffer.isBuffer(body)) return Array.from(body);
717
+ if (typeof body === "string") return Array.from(Buffer.from(body, "utf8"));
718
+ if (typeof body === "object") return Array.from(Buffer.from(JSON.stringify(body), "utf8"));
719
+ return [];
720
+ }
721
+
722
+ // src/engine/orchestrator/verify-request.ts
723
+ var DEFAULT_REPUTATION_BASELINE = 1;
724
+ function makeVerifyRequest(opts) {
725
+ let argusWarningLogged = false;
726
+ const log = opts.logger ?? defaultLogger;
727
+ return async function verifyRequest2(req) {
728
+ if (!argusWarningLogged && !opts.argusUrl) {
729
+ log(
730
+ '[Checkpoint] WARNING: Argus URL not configured; reputation will degrade to baseline 1.0 ("trust by default"). Set ARGUS_API_URL to enable.'
731
+ );
732
+ argusWarningLogged = true;
733
+ }
734
+ return verifyRequest_internal(req, opts);
735
+ };
736
+ }
737
+ async function verifyRequest(req, opts) {
738
+ return verifyRequest_internal(req, opts);
739
+ }
740
+ async function verifyRequest_internal(req, opts) {
741
+ if (hasMalformedJwsBody(req)) {
742
+ return blockWithParseError("malformed JWS body", opts.enforcementMode);
743
+ }
744
+ const agentRequest = buildAgentRequest(req, {
745
+ legacyEnvelopeFallback: opts.legacyEnvelopeFallback
746
+ });
747
+ const issuer = extractIssuer(agentRequest);
748
+ const agentDid = extractAgentDid(agentRequest);
749
+ const credentialStatusUrl = extractCredentialStatusUrl(agentRequest);
750
+ const baseline = opts.reputationBaseline ?? DEFAULT_REPUTATION_BASELINE;
751
+ const [didResult, statusResult, repResult] = await Promise.allSettled([
752
+ issuer ? opts.didResolver.resolve(issuer) : Promise.resolve(null),
753
+ credentialStatusUrl ? fetchCredentialStatus(credentialStatusUrl, opts.statusListCache) : Promise.resolve(null),
754
+ agentDid ? opts.reputationOracle.score(agentDid) : Promise.resolve(baseline)
755
+ ]);
756
+ if (didResult.status === "rejected") {
757
+ if (isDidResolverError(didResult.reason)) {
758
+ return blockWithParseError(
759
+ didResult.reason instanceof Error ? didResult.reason.message : String(didResult.reason),
760
+ opts.enforcementMode
761
+ );
762
+ }
763
+ throw didResult.reason;
764
+ }
765
+ if (statusResult.status === "rejected") {
766
+ if (statusResult.reason instanceof UnsafeOutboundUrl) {
767
+ return blockWithParseError(statusResult.reason.message, opts.enforcementMode);
768
+ }
769
+ throw statusResult.reason;
770
+ }
771
+ if (repResult.status === "rejected") {
772
+ throw repResult.reason;
773
+ }
774
+ const didDoc = didResult.value;
775
+ const revokedIndices = statusResult.value;
776
+ const repScore = repResult.value;
777
+ const tenantDecision = await opts.policyEvaluator.evaluate({
778
+ tenantHost: opts.tenantHost,
779
+ reputation: repScore
780
+ });
781
+ const ctx = {
782
+ didDocs: didDoc && issuer ? { [issuer]: didDoc } : {},
783
+ revoked: revokedIndices !== null && credentialStatusUrl ? { [credentialStatusUrl]: revokedIndices } : {},
784
+ reputation: agentDid ? { [agentDid]: repScore } : {},
785
+ tenantDecision,
786
+ nowUnix: opts.clock.nowUnix(),
787
+ enforcementMode: opts.enforcementMode
788
+ };
789
+ return engineVerify(agentRequest, ctx);
790
+ }
791
+ async function fetchCredentialStatus(credentialStatusUrl, statusListCache) {
792
+ assertSafeHttpsUrl(credentialStatusUrl, "credential status URL");
793
+ return statusListCache.fetch(credentialStatusUrl);
794
+ }
795
+ function isDidResolverError(err) {
796
+ if (!(err instanceof Error)) return false;
797
+ const kind = err.kind;
798
+ return kind === "DidNotFound" || kind === "DidResolverTimeout" || kind === "DidResolverError" || kind === "MalformedDid" || kind === "UnsupportedKeyType" || kind === "UnsupportedDidMethod";
799
+ }
800
+ function blockWithParseError(detail, enforcementMode) {
801
+ return {
802
+ decision: {
803
+ kind: "Block",
804
+ reason: {
805
+ kind: "ParseError",
806
+ detail
807
+ }
808
+ },
809
+ enforcementMode,
810
+ engineInfo: {
811
+ name: "checkpoint-engine-wasm",
812
+ version: "0.0.0-host-synth",
813
+ rulesetHash: "sha256:host-synthesized",
814
+ rulesetVersion: "0.0.0-host-synth",
815
+ extras: { synthesized: true }
816
+ }
817
+ };
818
+ }
819
+ function defaultLogger(msg) {
820
+ console.warn(msg);
821
+ }
822
+
823
+ // src/engine/orchestrator/render-decision.ts
824
+ function renderDecisionAsResponse(result) {
825
+ const baseHeaders = buildBaseHeaders(result);
826
+ if (result.enforcementMode === "observe") {
827
+ return {
828
+ status: null,
829
+ headers: {
830
+ ...baseHeaders,
831
+ "X-Checkpoint-Mode": "observe",
832
+ "X-Checkpoint-Would-Have-Been": result.decision.kind,
833
+ ...wouldHaveBeenReasonHeader(result)
834
+ }
835
+ };
836
+ }
837
+ switch (result.decision.kind) {
838
+ case "Permit":
839
+ return {
840
+ status: null,
841
+ headers: { ...baseHeaders, "X-Checkpoint-Decision": "permit" }
842
+ };
843
+ case "Block": {
844
+ const reason = result.decision.reason;
845
+ return {
846
+ status: httpStatusForBlockReason(reason),
847
+ headers: {
848
+ ...baseHeaders,
849
+ ...blockHeaders(reason),
850
+ "X-Checkpoint-Decision": "block",
851
+ "X-Checkpoint-Reason": reason.kind
852
+ },
853
+ body: blockResponseBody(reason)
854
+ };
855
+ }
856
+ case "Challenge": {
857
+ const params = result.decision.params;
858
+ return {
859
+ status: 401,
860
+ headers: {
861
+ ...baseHeaders,
862
+ "X-Checkpoint-Decision": "challenge",
863
+ "X-Checkpoint-Challenge": params.nonce
864
+ },
865
+ body: {
866
+ challenge: params
867
+ }
868
+ };
869
+ }
870
+ case "Redirect": {
871
+ const target = result.decision.target;
872
+ return {
873
+ status: 302,
874
+ headers: {
875
+ ...baseHeaders,
876
+ "X-Checkpoint-Decision": "redirect",
877
+ Location: target.url,
878
+ "X-Checkpoint-Redirect-Reason": target.reason
879
+ }
880
+ };
881
+ }
882
+ case "Instruct": {
883
+ const payload = result.decision.payload;
884
+ return {
885
+ status: 422,
886
+ headers: {
887
+ ...baseHeaders,
888
+ "X-Checkpoint-Decision": "instruct",
889
+ "Content-Type": "application/problem+json"
890
+ },
891
+ body: {
892
+ type: payload.problem,
893
+ title: payload.title,
894
+ suggestedActions: payload.suggestedActions
895
+ }
896
+ };
897
+ }
898
+ }
899
+ }
900
+ function buildBaseHeaders(result) {
901
+ const headers = {
902
+ "X-Checkpoint-Engine": result.engineInfo.name,
903
+ "X-Checkpoint-Engine-Version": result.engineInfo.version
904
+ };
905
+ if (result.engineInfo.rulesetHash) {
906
+ headers["X-Checkpoint-Ruleset-Hash"] = result.engineInfo.rulesetHash;
907
+ }
908
+ return headers;
909
+ }
910
+ function httpStatusForBlockReason(reason) {
911
+ switch (reason.kind) {
912
+ case "Unauthenticated":
913
+ case "Expired":
914
+ return 401;
915
+ case "ParseError":
916
+ return 400;
917
+ case "InvalidSignature":
918
+ case "Revoked":
919
+ case "OutOfScope":
920
+ case "LowReputation":
921
+ case "PolicyDenied":
922
+ return 403;
923
+ }
924
+ }
925
+ function blockHeaders(reason) {
926
+ if (reason.kind === "Unauthenticated") {
927
+ return { "WWW-Authenticate": 'KyaProof realm="checkpoint"' };
928
+ }
929
+ return {};
930
+ }
931
+ function blockResponseBody(reason) {
932
+ switch (reason.kind) {
933
+ case "Revoked":
934
+ case "InvalidSignature":
935
+ case "Unauthenticated":
936
+ case "Expired":
937
+ return { error: humanError(reason.kind), reason: reason.kind };
938
+ case "OutOfScope":
939
+ return {
940
+ error: "requested scope is not granted",
941
+ reason: "OutOfScope",
942
+ requested: reason.requested,
943
+ granted: reason.granted
944
+ };
945
+ case "LowReputation":
946
+ return {
947
+ error: "agent reputation below tenant threshold",
948
+ reason: "LowReputation",
949
+ score: reason.score,
950
+ threshold: reason.threshold
951
+ };
952
+ case "PolicyDenied":
953
+ return {
954
+ error: "tenant policy denied the request",
955
+ reason: "PolicyDenied",
956
+ detail: reason.detail
957
+ };
958
+ case "ParseError":
959
+ return {
960
+ error: "request envelope could not be parsed",
961
+ reason: "ParseError",
962
+ detail: reason.detail
963
+ };
964
+ }
965
+ }
966
+ function humanError(kind) {
967
+ switch (kind) {
968
+ case "Revoked":
969
+ return "credential has been revoked";
970
+ case "InvalidSignature":
971
+ return "request signature failed verification";
972
+ case "Unauthenticated":
973
+ return "authentication required";
974
+ case "Expired":
975
+ return "credential is expired";
976
+ }
977
+ }
978
+ function wouldHaveBeenReasonHeader(result) {
979
+ if (result.decision.kind === "Block") {
980
+ return { "X-Checkpoint-Would-Have-Been-Reason": result.decision.reason.kind };
981
+ }
982
+ return {};
983
+ }
984
+
985
+ exports.buildAgentRequest = buildAgentRequest;
986
+ exports.extractAgentDid = extractAgentDid;
987
+ exports.extractCredentialStatusUrl = extractCredentialStatusUrl;
988
+ exports.extractIssuer = extractIssuer;
989
+ exports.hasMalformedJwsBody = hasMalformedJwsBody;
990
+ exports.makeVerifyRequest = makeVerifyRequest;
991
+ exports.renderDecisionAsResponse = renderDecisionAsResponse;
992
+ exports.verifyRequest = verifyRequest;