@syncause/debug-daemon 0.1.1 → 0.1.2

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 (2) hide show
  1. package/dist/index.js +1478 -453
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -10740,7 +10740,7 @@ var require_winston = __commonJS({
10740
10740
  var require_object_hash = __commonJS({
10741
10741
  "node_modules/object-hash/index.js"(exports2, module2) {
10742
10742
  "use strict";
10743
- var crypto5 = require("crypto");
10743
+ var crypto6 = require("crypto");
10744
10744
  exports2 = module2.exports = objectHash;
10745
10745
  function objectHash(object, options) {
10746
10746
  options = applyDefaults(object, options);
@@ -10758,7 +10758,7 @@ var require_object_hash = __commonJS({
10758
10758
  exports2.keysMD5 = function(object) {
10759
10759
  return objectHash(object, { algorithm: "md5", encoding: "hex", excludeValues: true });
10760
10760
  };
10761
- var hashes = crypto5.getHashes ? crypto5.getHashes().slice() : ["sha1", "md5"];
10761
+ var hashes = crypto6.getHashes ? crypto6.getHashes().slice() : ["sha1", "md5"];
10762
10762
  hashes.push("passthrough");
10763
10763
  var encodings = ["buffer", "hex", "binary", "base64"];
10764
10764
  function applyDefaults(object, sourceOptions) {
@@ -10804,7 +10804,7 @@ var require_object_hash = __commonJS({
10804
10804
  function hash(object, options) {
10805
10805
  var hashingStream;
10806
10806
  if (options.algorithm !== "passthrough") {
10807
- hashingStream = crypto5.createHash(options.algorithm);
10807
+ hashingStream = crypto6.createHash(options.algorithm);
10808
10808
  } else {
10809
10809
  hashingStream = new PassThrough();
10810
10810
  }
@@ -15121,7 +15121,7 @@ var require_FileStreamRotator = __commonJS({
15121
15121
  var fs5 = require("fs");
15122
15122
  var path6 = require("path");
15123
15123
  var moment = require_moment();
15124
- var crypto5 = require("crypto");
15124
+ var crypto6 = require("crypto");
15125
15125
  var EventEmitter = require("events");
15126
15126
  var FileStreamRotator = {};
15127
15127
  module2.exports = FileStreamRotator;
@@ -15250,7 +15250,7 @@ var require_FileStreamRotator = __commonJS({
15250
15250
  }
15251
15251
  };
15252
15252
  function removeFile(file, verbose) {
15253
- if (file.hash === crypto5.createHash(file.hashType).update(file.name + "LOG_FILE" + file.date).digest("hex")) {
15253
+ if (file.hash === crypto6.createHash(file.hashType).update(file.name + "LOG_FILE" + file.date).digest("hex")) {
15254
15254
  try {
15255
15255
  if (fs5.existsSync(file.name)) {
15256
15256
  fs5.unlinkSync(file.name);
@@ -15316,7 +15316,7 @@ var require_FileStreamRotator = __commonJS({
15316
15316
  audit.files.push({
15317
15317
  date: time,
15318
15318
  name: logfile,
15319
- hash: crypto5.createHash(audit.hashType).update(logfile + "LOG_FILE" + time).digest("hex")
15319
+ hash: crypto6.createHash(audit.hashType).update(logfile + "LOG_FILE" + time).digest("hex")
15320
15320
  });
15321
15321
  if (audit.keep.days) {
15322
15322
  var oldestDate = moment().subtract(audit.keep.amount, "days").valueOf();
@@ -15993,6 +15993,733 @@ var require_p_limit = __commonJS({
15993
15993
  }
15994
15994
  });
15995
15995
 
15996
+ // node_modules/node-machine-id/dist/index.js
15997
+ var require_dist = __commonJS({
15998
+ "node_modules/node-machine-id/dist/index.js"(exports2, module2) {
15999
+ !(function(t, n) {
16000
+ "object" == typeof exports2 && "object" == typeof module2 ? module2.exports = n(require("child_process"), require("crypto")) : "function" == typeof define && define.amd ? define(["child_process", "crypto"], n) : "object" == typeof exports2 ? exports2["electron-machine-id"] = n(require("child_process"), require("crypto")) : t["electron-machine-id"] = n(t.child_process, t.crypto);
16001
+ })(exports2, function(t, n) {
16002
+ return (function(t2) {
16003
+ function n2(e) {
16004
+ if (r[e]) return r[e].exports;
16005
+ var o = r[e] = { exports: {}, id: e, loaded: false };
16006
+ return t2[e].call(o.exports, o, o.exports, n2), o.loaded = true, o.exports;
16007
+ }
16008
+ var r = {};
16009
+ return n2.m = t2, n2.c = r, n2.p = "", n2(0);
16010
+ })([function(t2, n2, r) {
16011
+ t2.exports = r(34);
16012
+ }, function(t2, n2, r) {
16013
+ var e = r(29)("wks"), o = r(33), i = r(2).Symbol, c = "function" == typeof i, u = t2.exports = function(t3) {
16014
+ return e[t3] || (e[t3] = c && i[t3] || (c ? i : o)("Symbol." + t3));
16015
+ };
16016
+ u.store = e;
16017
+ }, function(t2, n2) {
16018
+ var r = t2.exports = "undefined" != typeof window && window.Math == Math ? window : "undefined" != typeof self && self.Math == Math ? self : Function("return this")();
16019
+ "number" == typeof __g && (__g = r);
16020
+ }, function(t2, n2, r) {
16021
+ var e = r(9);
16022
+ t2.exports = function(t3) {
16023
+ if (!e(t3)) throw TypeError(t3 + " is not an object!");
16024
+ return t3;
16025
+ };
16026
+ }, function(t2, n2, r) {
16027
+ t2.exports = !r(24)(function() {
16028
+ return 7 != Object.defineProperty({}, "a", { get: function() {
16029
+ return 7;
16030
+ } }).a;
16031
+ });
16032
+ }, function(t2, n2, r) {
16033
+ var e = r(12), o = r(17);
16034
+ t2.exports = r(4) ? function(t3, n3, r2) {
16035
+ return e.f(t3, n3, o(1, r2));
16036
+ } : function(t3, n3, r2) {
16037
+ return t3[n3] = r2, t3;
16038
+ };
16039
+ }, function(t2, n2) {
16040
+ var r = t2.exports = { version: "2.4.0" };
16041
+ "number" == typeof __e && (__e = r);
16042
+ }, function(t2, n2, r) {
16043
+ var e = r(14);
16044
+ t2.exports = function(t3, n3, r2) {
16045
+ if (e(t3), void 0 === n3) return t3;
16046
+ switch (r2) {
16047
+ case 1:
16048
+ return function(r3) {
16049
+ return t3.call(n3, r3);
16050
+ };
16051
+ case 2:
16052
+ return function(r3, e2) {
16053
+ return t3.call(n3, r3, e2);
16054
+ };
16055
+ case 3:
16056
+ return function(r3, e2, o) {
16057
+ return t3.call(n3, r3, e2, o);
16058
+ };
16059
+ }
16060
+ return function() {
16061
+ return t3.apply(n3, arguments);
16062
+ };
16063
+ };
16064
+ }, function(t2, n2) {
16065
+ var r = {}.hasOwnProperty;
16066
+ t2.exports = function(t3, n3) {
16067
+ return r.call(t3, n3);
16068
+ };
16069
+ }, function(t2, n2) {
16070
+ t2.exports = function(t3) {
16071
+ return "object" == typeof t3 ? null !== t3 : "function" == typeof t3;
16072
+ };
16073
+ }, function(t2, n2) {
16074
+ t2.exports = {};
16075
+ }, function(t2, n2) {
16076
+ var r = {}.toString;
16077
+ t2.exports = function(t3) {
16078
+ return r.call(t3).slice(8, -1);
16079
+ };
16080
+ }, function(t2, n2, r) {
16081
+ var e = r(3), o = r(26), i = r(32), c = Object.defineProperty;
16082
+ n2.f = r(4) ? Object.defineProperty : function(t3, n3, r2) {
16083
+ if (e(t3), n3 = i(n3, true), e(r2), o) try {
16084
+ return c(t3, n3, r2);
16085
+ } catch (t4) {
16086
+ }
16087
+ if ("get" in r2 || "set" in r2) throw TypeError("Accessors not supported!");
16088
+ return "value" in r2 && (t3[n3] = r2.value), t3;
16089
+ };
16090
+ }, function(t2, n2, r) {
16091
+ var e = r(42), o = r(15);
16092
+ t2.exports = function(t3) {
16093
+ return e(o(t3));
16094
+ };
16095
+ }, function(t2, n2) {
16096
+ t2.exports = function(t3) {
16097
+ if ("function" != typeof t3) throw TypeError(t3 + " is not a function!");
16098
+ return t3;
16099
+ };
16100
+ }, function(t2, n2) {
16101
+ t2.exports = function(t3) {
16102
+ if (void 0 == t3) throw TypeError("Can't call method on " + t3);
16103
+ return t3;
16104
+ };
16105
+ }, function(t2, n2, r) {
16106
+ var e = r(9), o = r(2).document, i = e(o) && e(o.createElement);
16107
+ t2.exports = function(t3) {
16108
+ return i ? o.createElement(t3) : {};
16109
+ };
16110
+ }, function(t2, n2) {
16111
+ t2.exports = function(t3, n3) {
16112
+ return { enumerable: !(1 & t3), configurable: !(2 & t3), writable: !(4 & t3), value: n3 };
16113
+ };
16114
+ }, function(t2, n2, r) {
16115
+ var e = r(12).f, o = r(8), i = r(1)("toStringTag");
16116
+ t2.exports = function(t3, n3, r2) {
16117
+ t3 && !o(t3 = r2 ? t3 : t3.prototype, i) && e(t3, i, { configurable: true, value: n3 });
16118
+ };
16119
+ }, function(t2, n2, r) {
16120
+ var e = r(29)("keys"), o = r(33);
16121
+ t2.exports = function(t3) {
16122
+ return e[t3] || (e[t3] = o(t3));
16123
+ };
16124
+ }, function(t2, n2) {
16125
+ var r = Math.ceil, e = Math.floor;
16126
+ t2.exports = function(t3) {
16127
+ return isNaN(t3 = +t3) ? 0 : (t3 > 0 ? e : r)(t3);
16128
+ };
16129
+ }, function(t2, n2, r) {
16130
+ var e = r(11), o = r(1)("toStringTag"), i = "Arguments" == e(/* @__PURE__ */ (function() {
16131
+ return arguments;
16132
+ })()), c = function(t3, n3) {
16133
+ try {
16134
+ return t3[n3];
16135
+ } catch (t4) {
16136
+ }
16137
+ };
16138
+ t2.exports = function(t3) {
16139
+ var n3, r2, u;
16140
+ return void 0 === t3 ? "Undefined" : null === t3 ? "Null" : "string" == typeof (r2 = c(n3 = Object(t3), o)) ? r2 : i ? e(n3) : "Object" == (u = e(n3)) && "function" == typeof n3.callee ? "Arguments" : u;
16141
+ };
16142
+ }, function(t2, n2) {
16143
+ t2.exports = "constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",");
16144
+ }, function(t2, n2, r) {
16145
+ var e = r(2), o = r(6), i = r(7), c = r(5), u = "prototype", s = function(t3, n3, r2) {
16146
+ var f, a, p, l = t3 & s.F, v = t3 & s.G, h = t3 & s.S, d = t3 & s.P, y = t3 & s.B, _ = t3 & s.W, x = v ? o : o[n3] || (o[n3] = {}), m = x[u], w = v ? e : h ? e[n3] : (e[n3] || {})[u];
16147
+ v && (r2 = n3);
16148
+ for (f in r2) a = !l && w && void 0 !== w[f], a && f in x || (p = a ? w[f] : r2[f], x[f] = v && "function" != typeof w[f] ? r2[f] : y && a ? i(p, e) : _ && w[f] == p ? (function(t4) {
16149
+ var n4 = function(n5, r3, e2) {
16150
+ if (this instanceof t4) {
16151
+ switch (arguments.length) {
16152
+ case 0:
16153
+ return new t4();
16154
+ case 1:
16155
+ return new t4(n5);
16156
+ case 2:
16157
+ return new t4(n5, r3);
16158
+ }
16159
+ return new t4(n5, r3, e2);
16160
+ }
16161
+ return t4.apply(this, arguments);
16162
+ };
16163
+ return n4[u] = t4[u], n4;
16164
+ })(p) : d && "function" == typeof p ? i(Function.call, p) : p, d && ((x.virtual || (x.virtual = {}))[f] = p, t3 & s.R && m && !m[f] && c(m, f, p)));
16165
+ };
16166
+ s.F = 1, s.G = 2, s.S = 4, s.P = 8, s.B = 16, s.W = 32, s.U = 64, s.R = 128, t2.exports = s;
16167
+ }, function(t2, n2) {
16168
+ t2.exports = function(t3) {
16169
+ try {
16170
+ return !!t3();
16171
+ } catch (t4) {
16172
+ return true;
16173
+ }
16174
+ };
16175
+ }, function(t2, n2, r) {
16176
+ t2.exports = r(2).document && document.documentElement;
16177
+ }, function(t2, n2, r) {
16178
+ t2.exports = !r(4) && !r(24)(function() {
16179
+ return 7 != Object.defineProperty(r(16)("div"), "a", { get: function() {
16180
+ return 7;
16181
+ } }).a;
16182
+ });
16183
+ }, function(t2, n2, r) {
16184
+ "use strict";
16185
+ var e = r(28), o = r(23), i = r(57), c = r(5), u = r(8), s = r(10), f = r(45), a = r(18), p = r(52), l = r(1)("iterator"), v = !([].keys && "next" in [].keys()), h = "@@iterator", d = "keys", y = "values", _ = function() {
16186
+ return this;
16187
+ };
16188
+ t2.exports = function(t3, n3, r2, x, m, w, g) {
16189
+ f(r2, n3, x);
16190
+ var b, O, j, S = function(t4) {
16191
+ if (!v && t4 in T) return T[t4];
16192
+ switch (t4) {
16193
+ case d:
16194
+ return function() {
16195
+ return new r2(this, t4);
16196
+ };
16197
+ case y:
16198
+ return function() {
16199
+ return new r2(this, t4);
16200
+ };
16201
+ }
16202
+ return function() {
16203
+ return new r2(this, t4);
16204
+ };
16205
+ }, E = n3 + " Iterator", P = m == y, M = false, T = t3.prototype, A = T[l] || T[h] || m && T[m], k = A || S(m), C = m ? P ? S("entries") : k : void 0, I = "Array" == n3 ? T.entries || A : A;
16206
+ if (I && (j = p(I.call(new t3())), j !== Object.prototype && (a(j, E, true), e || u(j, l) || c(j, l, _))), P && A && A.name !== y && (M = true, k = function() {
16207
+ return A.call(this);
16208
+ }), e && !g || !v && !M && T[l] || c(T, l, k), s[n3] = k, s[E] = _, m) if (b = { values: P ? k : S(y), keys: w ? k : S(d), entries: C }, g) for (O in b) O in T || i(T, O, b[O]);
16209
+ else o(o.P + o.F * (v || M), n3, b);
16210
+ return b;
16211
+ };
16212
+ }, function(t2, n2) {
16213
+ t2.exports = true;
16214
+ }, function(t2, n2, r) {
16215
+ var e = r(2), o = "__core-js_shared__", i = e[o] || (e[o] = {});
16216
+ t2.exports = function(t3) {
16217
+ return i[t3] || (i[t3] = {});
16218
+ };
16219
+ }, function(t2, n2, r) {
16220
+ var e, o, i, c = r(7), u = r(41), s = r(25), f = r(16), a = r(2), p = a.process, l = a.setImmediate, v = a.clearImmediate, h = a.MessageChannel, d = 0, y = {}, _ = "onreadystatechange", x = function() {
16221
+ var t3 = +this;
16222
+ if (y.hasOwnProperty(t3)) {
16223
+ var n3 = y[t3];
16224
+ delete y[t3], n3();
16225
+ }
16226
+ }, m = function(t3) {
16227
+ x.call(t3.data);
16228
+ };
16229
+ l && v || (l = function(t3) {
16230
+ for (var n3 = [], r2 = 1; arguments.length > r2; ) n3.push(arguments[r2++]);
16231
+ return y[++d] = function() {
16232
+ u("function" == typeof t3 ? t3 : Function(t3), n3);
16233
+ }, e(d), d;
16234
+ }, v = function(t3) {
16235
+ delete y[t3];
16236
+ }, "process" == r(11)(p) ? e = function(t3) {
16237
+ p.nextTick(c(x, t3, 1));
16238
+ } : h ? (o = new h(), i = o.port2, o.port1.onmessage = m, e = c(i.postMessage, i, 1)) : a.addEventListener && "function" == typeof postMessage && !a.importScripts ? (e = function(t3) {
16239
+ a.postMessage(t3 + "", "*");
16240
+ }, a.addEventListener("message", m, false)) : e = _ in f("script") ? function(t3) {
16241
+ s.appendChild(f("script"))[_] = function() {
16242
+ s.removeChild(this), x.call(t3);
16243
+ };
16244
+ } : function(t3) {
16245
+ setTimeout(c(x, t3, 1), 0);
16246
+ }), t2.exports = { set: l, clear: v };
16247
+ }, function(t2, n2, r) {
16248
+ var e = r(20), o = Math.min;
16249
+ t2.exports = function(t3) {
16250
+ return t3 > 0 ? o(e(t3), 9007199254740991) : 0;
16251
+ };
16252
+ }, function(t2, n2, r) {
16253
+ var e = r(9);
16254
+ t2.exports = function(t3, n3) {
16255
+ if (!e(t3)) return t3;
16256
+ var r2, o;
16257
+ if (n3 && "function" == typeof (r2 = t3.toString) && !e(o = r2.call(t3))) return o;
16258
+ if ("function" == typeof (r2 = t3.valueOf) && !e(o = r2.call(t3))) return o;
16259
+ if (!n3 && "function" == typeof (r2 = t3.toString) && !e(o = r2.call(t3))) return o;
16260
+ throw TypeError("Can't convert object to primitive value");
16261
+ };
16262
+ }, function(t2, n2) {
16263
+ var r = 0, e = Math.random();
16264
+ t2.exports = function(t3) {
16265
+ return "Symbol(".concat(void 0 === t3 ? "" : t3, ")_", (++r + e).toString(36));
16266
+ };
16267
+ }, function(t2, n2, r) {
16268
+ "use strict";
16269
+ function e(t3) {
16270
+ return t3 && t3.__esModule ? t3 : { default: t3 };
16271
+ }
16272
+ function o() {
16273
+ return "win32" !== process.platform ? "" : "ia32" === process.arch && process.env.hasOwnProperty("PROCESSOR_ARCHITEW6432") ? "mixed" : "native";
16274
+ }
16275
+ function i(t3) {
16276
+ return (0, l.createHash)("sha256").update(t3).digest("hex");
16277
+ }
16278
+ function c(t3) {
16279
+ switch (h) {
16280
+ case "darwin":
16281
+ return t3.split("IOPlatformUUID")[1].split("\n")[0].replace(/\=|\s+|\"/gi, "").toLowerCase();
16282
+ case "win32":
16283
+ return t3.toString().split("REG_SZ")[1].replace(/\r+|\n+|\s+/gi, "").toLowerCase();
16284
+ case "linux":
16285
+ return t3.toString().replace(/\r+|\n+|\s+/gi, "").toLowerCase();
16286
+ case "freebsd":
16287
+ return t3.toString().replace(/\r+|\n+|\s+/gi, "").toLowerCase();
16288
+ default:
16289
+ throw new Error("Unsupported platform: " + process.platform);
16290
+ }
16291
+ }
16292
+ function u(t3) {
16293
+ var n3 = c((0, p.execSync)(y[h]).toString());
16294
+ return t3 ? n3 : i(n3);
16295
+ }
16296
+ function s(t3) {
16297
+ return new a.default(function(n3, r2) {
16298
+ return (0, p.exec)(y[h], {}, function(e2, o2, u2) {
16299
+ if (e2) return r2(new Error("Error while obtaining machine id: " + e2.stack));
16300
+ var s2 = c(o2.toString());
16301
+ return n3(t3 ? s2 : i(s2));
16302
+ });
16303
+ });
16304
+ }
16305
+ Object.defineProperty(n2, "__esModule", { value: true });
16306
+ var f = r(35), a = e(f);
16307
+ n2.machineIdSync = u, n2.machineId = s;
16308
+ var p = r(70), l = r(71), v = process, h = v.platform, d = { native: "%windir%\\System32", mixed: "%windir%\\sysnative\\cmd.exe /c %windir%\\System32" }, y = { darwin: "ioreg -rd1 -c IOPlatformExpertDevice", win32: d[o()] + "\\REG.exe QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography /v MachineGuid", linux: "( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :", freebsd: "kenv -q smbios.system.uuid || sysctl -n kern.hostuuid" };
16309
+ }, function(t2, n2, r) {
16310
+ t2.exports = { default: r(36), __esModule: true };
16311
+ }, function(t2, n2, r) {
16312
+ r(66), r(68), r(69), r(67), t2.exports = r(6).Promise;
16313
+ }, function(t2, n2) {
16314
+ t2.exports = function() {
16315
+ };
16316
+ }, function(t2, n2) {
16317
+ t2.exports = function(t3, n3, r, e) {
16318
+ if (!(t3 instanceof n3) || void 0 !== e && e in t3) throw TypeError(r + ": incorrect invocation!");
16319
+ return t3;
16320
+ };
16321
+ }, function(t2, n2, r) {
16322
+ var e = r(13), o = r(31), i = r(62);
16323
+ t2.exports = function(t3) {
16324
+ return function(n3, r2, c) {
16325
+ var u, s = e(n3), f = o(s.length), a = i(c, f);
16326
+ if (t3 && r2 != r2) {
16327
+ for (; f > a; ) if (u = s[a++], u != u) return true;
16328
+ } else for (; f > a; a++) if ((t3 || a in s) && s[a] === r2) return t3 || a || 0;
16329
+ return !t3 && -1;
16330
+ };
16331
+ };
16332
+ }, function(t2, n2, r) {
16333
+ var e = r(7), o = r(44), i = r(43), c = r(3), u = r(31), s = r(64), f = {}, a = {}, n2 = t2.exports = function(t3, n3, r2, p, l) {
16334
+ var v, h, d, y, _ = l ? function() {
16335
+ return t3;
16336
+ } : s(t3), x = e(r2, p, n3 ? 2 : 1), m = 0;
16337
+ if ("function" != typeof _) throw TypeError(t3 + " is not iterable!");
16338
+ if (i(_)) {
16339
+ for (v = u(t3.length); v > m; m++) if (y = n3 ? x(c(h = t3[m])[0], h[1]) : x(t3[m]), y === f || y === a) return y;
16340
+ } else for (d = _.call(t3); !(h = d.next()).done; ) if (y = o(d, x, h.value, n3), y === f || y === a) return y;
16341
+ };
16342
+ n2.BREAK = f, n2.RETURN = a;
16343
+ }, function(t2, n2) {
16344
+ t2.exports = function(t3, n3, r) {
16345
+ var e = void 0 === r;
16346
+ switch (n3.length) {
16347
+ case 0:
16348
+ return e ? t3() : t3.call(r);
16349
+ case 1:
16350
+ return e ? t3(n3[0]) : t3.call(r, n3[0]);
16351
+ case 2:
16352
+ return e ? t3(n3[0], n3[1]) : t3.call(r, n3[0], n3[1]);
16353
+ case 3:
16354
+ return e ? t3(n3[0], n3[1], n3[2]) : t3.call(r, n3[0], n3[1], n3[2]);
16355
+ case 4:
16356
+ return e ? t3(n3[0], n3[1], n3[2], n3[3]) : t3.call(r, n3[0], n3[1], n3[2], n3[3]);
16357
+ }
16358
+ return t3.apply(r, n3);
16359
+ };
16360
+ }, function(t2, n2, r) {
16361
+ var e = r(11);
16362
+ t2.exports = Object("z").propertyIsEnumerable(0) ? Object : function(t3) {
16363
+ return "String" == e(t3) ? t3.split("") : Object(t3);
16364
+ };
16365
+ }, function(t2, n2, r) {
16366
+ var e = r(10), o = r(1)("iterator"), i = Array.prototype;
16367
+ t2.exports = function(t3) {
16368
+ return void 0 !== t3 && (e.Array === t3 || i[o] === t3);
16369
+ };
16370
+ }, function(t2, n2, r) {
16371
+ var e = r(3);
16372
+ t2.exports = function(t3, n3, r2, o) {
16373
+ try {
16374
+ return o ? n3(e(r2)[0], r2[1]) : n3(r2);
16375
+ } catch (n4) {
16376
+ var i = t3.return;
16377
+ throw void 0 !== i && e(i.call(t3)), n4;
16378
+ }
16379
+ };
16380
+ }, function(t2, n2, r) {
16381
+ "use strict";
16382
+ var e = r(49), o = r(17), i = r(18), c = {};
16383
+ r(5)(c, r(1)("iterator"), function() {
16384
+ return this;
16385
+ }), t2.exports = function(t3, n3, r2) {
16386
+ t3.prototype = e(c, { next: o(1, r2) }), i(t3, n3 + " Iterator");
16387
+ };
16388
+ }, function(t2, n2, r) {
16389
+ var e = r(1)("iterator"), o = false;
16390
+ try {
16391
+ var i = [7][e]();
16392
+ i.return = function() {
16393
+ o = true;
16394
+ }, Array.from(i, function() {
16395
+ throw 2;
16396
+ });
16397
+ } catch (t3) {
16398
+ }
16399
+ t2.exports = function(t3, n3) {
16400
+ if (!n3 && !o) return false;
16401
+ var r2 = false;
16402
+ try {
16403
+ var i2 = [7], c = i2[e]();
16404
+ c.next = function() {
16405
+ return { done: r2 = true };
16406
+ }, i2[e] = function() {
16407
+ return c;
16408
+ }, t3(i2);
16409
+ } catch (t4) {
16410
+ }
16411
+ return r2;
16412
+ };
16413
+ }, function(t2, n2) {
16414
+ t2.exports = function(t3, n3) {
16415
+ return { value: n3, done: !!t3 };
16416
+ };
16417
+ }, function(t2, n2, r) {
16418
+ var e = r(2), o = r(30).set, i = e.MutationObserver || e.WebKitMutationObserver, c = e.process, u = e.Promise, s = "process" == r(11)(c);
16419
+ t2.exports = function() {
16420
+ var t3, n3, r2, f = function() {
16421
+ var e2, o2;
16422
+ for (s && (e2 = c.domain) && e2.exit(); t3; ) {
16423
+ o2 = t3.fn, t3 = t3.next;
16424
+ try {
16425
+ o2();
16426
+ } catch (e3) {
16427
+ throw t3 ? r2() : n3 = void 0, e3;
16428
+ }
16429
+ }
16430
+ n3 = void 0, e2 && e2.enter();
16431
+ };
16432
+ if (s) r2 = function() {
16433
+ c.nextTick(f);
16434
+ };
16435
+ else if (i) {
16436
+ var a = true, p = document.createTextNode("");
16437
+ new i(f).observe(p, { characterData: true }), r2 = function() {
16438
+ p.data = a = !a;
16439
+ };
16440
+ } else if (u && u.resolve) {
16441
+ var l = u.resolve();
16442
+ r2 = function() {
16443
+ l.then(f);
16444
+ };
16445
+ } else r2 = function() {
16446
+ o.call(e, f);
16447
+ };
16448
+ return function(e2) {
16449
+ var o2 = { fn: e2, next: void 0 };
16450
+ n3 && (n3.next = o2), t3 || (t3 = o2, r2()), n3 = o2;
16451
+ };
16452
+ };
16453
+ }, function(t2, n2, r) {
16454
+ var e = r(3), o = r(50), i = r(22), c = r(19)("IE_PROTO"), u = function() {
16455
+ }, s = "prototype", f = function() {
16456
+ var t3, n3 = r(16)("iframe"), e2 = i.length, o2 = ">";
16457
+ for (n3.style.display = "none", r(25).appendChild(n3), n3.src = "javascript:", t3 = n3.contentWindow.document, t3.open(), t3.write("<script>document.F=Object</script" + o2), t3.close(), f = t3.F; e2--; ) delete f[s][i[e2]];
16458
+ return f();
16459
+ };
16460
+ t2.exports = Object.create || function(t3, n3) {
16461
+ var r2;
16462
+ return null !== t3 ? (u[s] = e(t3), r2 = new u(), u[s] = null, r2[c] = t3) : r2 = f(), void 0 === n3 ? r2 : o(r2, n3);
16463
+ };
16464
+ }, function(t2, n2, r) {
16465
+ var e = r(12), o = r(3), i = r(54);
16466
+ t2.exports = r(4) ? Object.defineProperties : function(t3, n3) {
16467
+ o(t3);
16468
+ for (var r2, c = i(n3), u = c.length, s = 0; u > s; ) e.f(t3, r2 = c[s++], n3[r2]);
16469
+ return t3;
16470
+ };
16471
+ }, function(t2, n2, r) {
16472
+ var e = r(55), o = r(17), i = r(13), c = r(32), u = r(8), s = r(26), f = Object.getOwnPropertyDescriptor;
16473
+ n2.f = r(4) ? f : function(t3, n3) {
16474
+ if (t3 = i(t3), n3 = c(n3, true), s) try {
16475
+ return f(t3, n3);
16476
+ } catch (t4) {
16477
+ }
16478
+ if (u(t3, n3)) return o(!e.f.call(t3, n3), t3[n3]);
16479
+ };
16480
+ }, function(t2, n2, r) {
16481
+ var e = r(8), o = r(63), i = r(19)("IE_PROTO"), c = Object.prototype;
16482
+ t2.exports = Object.getPrototypeOf || function(t3) {
16483
+ return t3 = o(t3), e(t3, i) ? t3[i] : "function" == typeof t3.constructor && t3 instanceof t3.constructor ? t3.constructor.prototype : t3 instanceof Object ? c : null;
16484
+ };
16485
+ }, function(t2, n2, r) {
16486
+ var e = r(8), o = r(13), i = r(39)(false), c = r(19)("IE_PROTO");
16487
+ t2.exports = function(t3, n3) {
16488
+ var r2, u = o(t3), s = 0, f = [];
16489
+ for (r2 in u) r2 != c && e(u, r2) && f.push(r2);
16490
+ for (; n3.length > s; ) e(u, r2 = n3[s++]) && (~i(f, r2) || f.push(r2));
16491
+ return f;
16492
+ };
16493
+ }, function(t2, n2, r) {
16494
+ var e = r(53), o = r(22);
16495
+ t2.exports = Object.keys || function(t3) {
16496
+ return e(t3, o);
16497
+ };
16498
+ }, function(t2, n2) {
16499
+ n2.f = {}.propertyIsEnumerable;
16500
+ }, function(t2, n2, r) {
16501
+ var e = r(5);
16502
+ t2.exports = function(t3, n3, r2) {
16503
+ for (var o in n3) r2 && t3[o] ? t3[o] = n3[o] : e(t3, o, n3[o]);
16504
+ return t3;
16505
+ };
16506
+ }, function(t2, n2, r) {
16507
+ t2.exports = r(5);
16508
+ }, function(t2, n2, r) {
16509
+ var e = r(9), o = r(3), i = function(t3, n3) {
16510
+ if (o(t3), !e(n3) && null !== n3) throw TypeError(n3 + ": can't set as prototype!");
16511
+ };
16512
+ t2.exports = { set: Object.setPrototypeOf || ("__proto__" in {} ? (function(t3, n3, e2) {
16513
+ try {
16514
+ e2 = r(7)(Function.call, r(51).f(Object.prototype, "__proto__").set, 2), e2(t3, []), n3 = !(t3 instanceof Array);
16515
+ } catch (t4) {
16516
+ n3 = true;
16517
+ }
16518
+ return function(t4, r2) {
16519
+ return i(t4, r2), n3 ? t4.__proto__ = r2 : e2(t4, r2), t4;
16520
+ };
16521
+ })({}, false) : void 0), check: i };
16522
+ }, function(t2, n2, r) {
16523
+ "use strict";
16524
+ var e = r(2), o = r(6), i = r(12), c = r(4), u = r(1)("species");
16525
+ t2.exports = function(t3) {
16526
+ var n3 = "function" == typeof o[t3] ? o[t3] : e[t3];
16527
+ c && n3 && !n3[u] && i.f(n3, u, { configurable: true, get: function() {
16528
+ return this;
16529
+ } });
16530
+ };
16531
+ }, function(t2, n2, r) {
16532
+ var e = r(3), o = r(14), i = r(1)("species");
16533
+ t2.exports = function(t3, n3) {
16534
+ var r2, c = e(t3).constructor;
16535
+ return void 0 === c || void 0 == (r2 = e(c)[i]) ? n3 : o(r2);
16536
+ };
16537
+ }, function(t2, n2, r) {
16538
+ var e = r(20), o = r(15);
16539
+ t2.exports = function(t3) {
16540
+ return function(n3, r2) {
16541
+ var i, c, u = String(o(n3)), s = e(r2), f = u.length;
16542
+ return s < 0 || s >= f ? t3 ? "" : void 0 : (i = u.charCodeAt(s), i < 55296 || i > 56319 || s + 1 === f || (c = u.charCodeAt(s + 1)) < 56320 || c > 57343 ? t3 ? u.charAt(s) : i : t3 ? u.slice(s, s + 2) : (i - 55296 << 10) + (c - 56320) + 65536);
16543
+ };
16544
+ };
16545
+ }, function(t2, n2, r) {
16546
+ var e = r(20), o = Math.max, i = Math.min;
16547
+ t2.exports = function(t3, n3) {
16548
+ return t3 = e(t3), t3 < 0 ? o(t3 + n3, 0) : i(t3, n3);
16549
+ };
16550
+ }, function(t2, n2, r) {
16551
+ var e = r(15);
16552
+ t2.exports = function(t3) {
16553
+ return Object(e(t3));
16554
+ };
16555
+ }, function(t2, n2, r) {
16556
+ var e = r(21), o = r(1)("iterator"), i = r(10);
16557
+ t2.exports = r(6).getIteratorMethod = function(t3) {
16558
+ if (void 0 != t3) return t3[o] || t3["@@iterator"] || i[e(t3)];
16559
+ };
16560
+ }, function(t2, n2, r) {
16561
+ "use strict";
16562
+ var e = r(37), o = r(47), i = r(10), c = r(13);
16563
+ t2.exports = r(27)(Array, "Array", function(t3, n3) {
16564
+ this._t = c(t3), this._i = 0, this._k = n3;
16565
+ }, function() {
16566
+ var t3 = this._t, n3 = this._k, r2 = this._i++;
16567
+ return !t3 || r2 >= t3.length ? (this._t = void 0, o(1)) : "keys" == n3 ? o(0, r2) : "values" == n3 ? o(0, t3[r2]) : o(0, [r2, t3[r2]]);
16568
+ }, "values"), i.Arguments = i.Array, e("keys"), e("values"), e("entries");
16569
+ }, function(t2, n2) {
16570
+ }, function(t2, n2, r) {
16571
+ "use strict";
16572
+ var e, o, i, c = r(28), u = r(2), s = r(7), f = r(21), a = r(23), p = r(9), l = (r(3), r(14)), v = r(38), h = r(40), d = (r(58).set, r(60)), y = r(30).set, _ = r(48)(), x = "Promise", m = u.TypeError, w = u.process, g = u[x], w = u.process, b = "process" == f(w), O = function() {
16573
+ }, j = !!(function() {
16574
+ try {
16575
+ var t3 = g.resolve(1), n3 = (t3.constructor = {})[r(1)("species")] = function(t4) {
16576
+ t4(O, O);
16577
+ };
16578
+ return (b || "function" == typeof PromiseRejectionEvent) && t3.then(O) instanceof n3;
16579
+ } catch (t4) {
16580
+ }
16581
+ })(), S = function(t3, n3) {
16582
+ return t3 === n3 || t3 === g && n3 === i;
16583
+ }, E = function(t3) {
16584
+ var n3;
16585
+ return !(!p(t3) || "function" != typeof (n3 = t3.then)) && n3;
16586
+ }, P = function(t3) {
16587
+ return S(g, t3) ? new M(t3) : new o(t3);
16588
+ }, M = o = function(t3) {
16589
+ var n3, r2;
16590
+ this.promise = new t3(function(t4, e2) {
16591
+ if (void 0 !== n3 || void 0 !== r2) throw m("Bad Promise constructor");
16592
+ n3 = t4, r2 = e2;
16593
+ }), this.resolve = l(n3), this.reject = l(r2);
16594
+ }, T = function(t3) {
16595
+ try {
16596
+ t3();
16597
+ } catch (t4) {
16598
+ return { error: t4 };
16599
+ }
16600
+ }, A = function(t3, n3) {
16601
+ if (!t3._n) {
16602
+ t3._n = true;
16603
+ var r2 = t3._c;
16604
+ _(function() {
16605
+ for (var e2 = t3._v, o2 = 1 == t3._s, i2 = 0, c2 = function(n4) {
16606
+ var r3, i3, c3 = o2 ? n4.ok : n4.fail, u2 = n4.resolve, s2 = n4.reject, f2 = n4.domain;
16607
+ try {
16608
+ c3 ? (o2 || (2 == t3._h && I(t3), t3._h = 1), c3 === true ? r3 = e2 : (f2 && f2.enter(), r3 = c3(e2), f2 && f2.exit()), r3 === n4.promise ? s2(m("Promise-chain cycle")) : (i3 = E(r3)) ? i3.call(r3, u2, s2) : u2(r3)) : s2(e2);
16609
+ } catch (t4) {
16610
+ s2(t4);
16611
+ }
16612
+ }; r2.length > i2; ) c2(r2[i2++]);
16613
+ t3._c = [], t3._n = false, n3 && !t3._h && k(t3);
16614
+ });
16615
+ }
16616
+ }, k = function(t3) {
16617
+ y.call(u, function() {
16618
+ var n3, r2, e2, o2 = t3._v;
16619
+ if (C(t3) && (n3 = T(function() {
16620
+ b ? w.emit("unhandledRejection", o2, t3) : (r2 = u.onunhandledrejection) ? r2({ promise: t3, reason: o2 }) : (e2 = u.console) && e2.error && e2.error("Unhandled promise rejection", o2);
16621
+ }), t3._h = b || C(t3) ? 2 : 1), t3._a = void 0, n3) throw n3.error;
16622
+ });
16623
+ }, C = function(t3) {
16624
+ if (1 == t3._h) return false;
16625
+ for (var n3, r2 = t3._a || t3._c, e2 = 0; r2.length > e2; ) if (n3 = r2[e2++], n3.fail || !C(n3.promise)) return false;
16626
+ return true;
16627
+ }, I = function(t3) {
16628
+ y.call(u, function() {
16629
+ var n3;
16630
+ b ? w.emit("rejectionHandled", t3) : (n3 = u.onrejectionhandled) && n3({ promise: t3, reason: t3._v });
16631
+ });
16632
+ }, R = function(t3) {
16633
+ var n3 = this;
16634
+ n3._d || (n3._d = true, n3 = n3._w || n3, n3._v = t3, n3._s = 2, n3._a || (n3._a = n3._c.slice()), A(n3, true));
16635
+ }, F = function(t3) {
16636
+ var n3, r2 = this;
16637
+ if (!r2._d) {
16638
+ r2._d = true, r2 = r2._w || r2;
16639
+ try {
16640
+ if (r2 === t3) throw m("Promise can't be resolved itself");
16641
+ (n3 = E(t3)) ? _(function() {
16642
+ var e2 = { _w: r2, _d: false };
16643
+ try {
16644
+ n3.call(t3, s(F, e2, 1), s(R, e2, 1));
16645
+ } catch (t4) {
16646
+ R.call(e2, t4);
16647
+ }
16648
+ }) : (r2._v = t3, r2._s = 1, A(r2, false));
16649
+ } catch (t4) {
16650
+ R.call({ _w: r2, _d: false }, t4);
16651
+ }
16652
+ }
16653
+ };
16654
+ j || (g = function(t3) {
16655
+ v(this, g, x, "_h"), l(t3), e.call(this);
16656
+ try {
16657
+ t3(s(F, this, 1), s(R, this, 1));
16658
+ } catch (t4) {
16659
+ R.call(this, t4);
16660
+ }
16661
+ }, e = function(t3) {
16662
+ this._c = [], this._a = void 0, this._s = 0, this._d = false, this._v = void 0, this._h = 0, this._n = false;
16663
+ }, e.prototype = r(56)(g.prototype, { then: function(t3, n3) {
16664
+ var r2 = P(d(this, g));
16665
+ return r2.ok = "function" != typeof t3 || t3, r2.fail = "function" == typeof n3 && n3, r2.domain = b ? w.domain : void 0, this._c.push(r2), this._a && this._a.push(r2), this._s && A(this, false), r2.promise;
16666
+ }, catch: function(t3) {
16667
+ return this.then(void 0, t3);
16668
+ } }), M = function() {
16669
+ var t3 = new e();
16670
+ this.promise = t3, this.resolve = s(F, t3, 1), this.reject = s(R, t3, 1);
16671
+ }), a(a.G + a.W + a.F * !j, { Promise: g }), r(18)(g, x), r(59)(x), i = r(6)[x], a(a.S + a.F * !j, x, { reject: function(t3) {
16672
+ var n3 = P(this), r2 = n3.reject;
16673
+ return r2(t3), n3.promise;
16674
+ } }), a(a.S + a.F * (c || !j), x, { resolve: function(t3) {
16675
+ if (t3 instanceof g && S(t3.constructor, this)) return t3;
16676
+ var n3 = P(this), r2 = n3.resolve;
16677
+ return r2(t3), n3.promise;
16678
+ } }), a(a.S + a.F * !(j && r(46)(function(t3) {
16679
+ g.all(t3).catch(O);
16680
+ })), x, { all: function(t3) {
16681
+ var n3 = this, r2 = P(n3), e2 = r2.resolve, o2 = r2.reject, i2 = T(function() {
16682
+ var r3 = [], i3 = 0, c2 = 1;
16683
+ h(t3, false, function(t4) {
16684
+ var u2 = i3++, s2 = false;
16685
+ r3.push(void 0), c2++, n3.resolve(t4).then(function(t5) {
16686
+ s2 || (s2 = true, r3[u2] = t5, --c2 || e2(r3));
16687
+ }, o2);
16688
+ }), --c2 || e2(r3);
16689
+ });
16690
+ return i2 && o2(i2.error), r2.promise;
16691
+ }, race: function(t3) {
16692
+ var n3 = this, r2 = P(n3), e2 = r2.reject, o2 = T(function() {
16693
+ h(t3, false, function(t4) {
16694
+ n3.resolve(t4).then(r2.resolve, e2);
16695
+ });
16696
+ });
16697
+ return o2 && e2(o2.error), r2.promise;
16698
+ } });
16699
+ }, function(t2, n2, r) {
16700
+ "use strict";
16701
+ var e = r(61)(true);
16702
+ r(27)(String, "String", function(t3) {
16703
+ this._t = String(t3), this._i = 0;
16704
+ }, function() {
16705
+ var t3, n3 = this._t, r2 = this._i;
16706
+ return r2 >= n3.length ? { value: void 0, done: true } : (t3 = e(n3, r2), this._i += t3.length, { value: t3, done: false });
16707
+ });
16708
+ }, function(t2, n2, r) {
16709
+ r(65);
16710
+ for (var e = r(2), o = r(5), i = r(10), c = r(1)("toStringTag"), u = ["NodeList", "DOMTokenList", "MediaList", "StyleSheetList", "CSSRuleList"], s = 0; s < 5; s++) {
16711
+ var f = u[s], a = e[f], p = a && a.prototype;
16712
+ p && !p[c] && o(p, c, f), i[f] = i.Array;
16713
+ }
16714
+ }, function(t2, n2) {
16715
+ t2.exports = require("child_process");
16716
+ }, function(t2, n2) {
16717
+ t2.exports = require("crypto");
16718
+ }]);
16719
+ });
16720
+ }
16721
+ });
16722
+
15996
16723
  // src/transport/server/local.ts
15997
16724
  var fs3 = __toESM(require("fs"));
15998
16725
 
@@ -18652,109 +19379,360 @@ var getRequestListener = (fetchCallback, options = {}) => {
18652
19379
 
18653
19380
  // src/transport/server/hono-server.ts
18654
19381
  var import_node_http = require("node:http");
18655
- var HonoServer = class {
18656
- constructor(onActivity) {
18657
- this.onActivity = onActivity;
18658
- this.app = new Hono2();
18659
- this.setupRoutes();
19382
+
19383
+ // src/config/index.ts
19384
+ function getArgValue(key) {
19385
+ const keys = [key, key.toLowerCase()];
19386
+ for (const k of keys) {
19387
+ const prefix = `--${k}=`;
19388
+ const arg = process.argv.find((a) => a.startsWith(prefix));
19389
+ if (arg) return arg.slice(prefix.length);
19390
+ const index = process.argv.indexOf(`--${k}`);
19391
+ if (index !== -1 && index + 1 < process.argv.length && !process.argv[index + 1].startsWith("--")) {
19392
+ return process.argv[index + 1];
19393
+ }
18660
19394
  }
18661
- app;
18662
- handlers = /* @__PURE__ */ new Map();
18663
- server;
18664
- setupRoutes() {
18665
- this.app.use("*", async (c, next) => {
18666
- this.onActivity?.();
18667
- await next();
18668
- });
18669
- this.app.post("/", async (c) => {
18670
- const apiKey = c.req.header("x-api-key");
18671
- let body;
18672
- try {
18673
- body = await c.req.json();
18674
- } catch (e) {
18675
- return c.json({
18676
- jsonrpc: "2.0",
18677
- id: null,
18678
- error: { code: -32700 /* PARSE_ERROR */, message: "Parse error" }
18679
- }, 400);
18680
- }
18681
- Logger.getInstance().debug("Executing RPC handler", {
18682
- apiKey,
18683
- method: body?.method,
18684
- requestId: body?.id,
18685
- params: body?.params
18686
- });
18687
- if (!apiKey) {
18688
- Logger.getInstance().debug("Unauthorized: Invalid API Key");
18689
- return c.json({
18690
- jsonrpc: "2.0",
18691
- id: body?.id || null,
18692
- error: {
18693
- code: -32001 /* UNAUTHORIZED */,
18694
- message: "Unauthorized: Invalid API Key"
18695
- }
18696
- }, 401);
18697
- }
18698
- if (!body || body.jsonrpc !== "2.0" || !body.method || !body.id) {
18699
- Logger.getInstance().debug("Invalid Request: Not a standard JSON-RPC 2.0");
18700
- return c.json({
18701
- jsonrpc: "2.0",
18702
- id: body?.id || null,
18703
- error: { code: -32600 /* INVALID_REQUEST */, message: "Invalid Request: Not a standard JSON-RPC 2.0" }
18704
- }, 400);
18705
- }
18706
- const handler = this.handlers.get(body.method);
18707
- if (!handler) {
18708
- return c.json({
18709
- jsonrpc: "2.0",
18710
- id: body.id,
18711
- error: { code: -32601 /* METHOD_NOT_FOUND */, message: `Method not found: ${body.method}` }
18712
- });
18713
- }
18714
- try {
18715
- const result = await handler(body.params, apiKey);
18716
- Logger.getInstance().debug("RPC handler executed successfully", {
18717
- method: body.method,
18718
- requestId: body.id
18719
- });
18720
- return c.json({
18721
- jsonrpc: "2.0",
18722
- id: body.id,
18723
- result
18724
- });
18725
- } catch (err) {
18726
- Logger.getInstance().error(`RPC Handler Error for ${body.method}:`, err);
18727
- return c.json({
18728
- jsonrpc: "2.0",
18729
- id: body.id,
18730
- error: { code: -32603 /* INTERNAL_ERROR */, message: err.message || "Internal error" }
18731
- });
18732
- }
18733
- });
19395
+ return void 0;
19396
+ }
19397
+ function hasArgFlag(key) {
19398
+ const keys = [key, key.toLowerCase()];
19399
+ return keys.some((k) => process.argv.includes(`--${k}`));
19400
+ }
19401
+ function parseConfigInt(key, defaultValue) {
19402
+ const argValue = getArgValue(key);
19403
+ if (argValue) {
19404
+ const parsed2 = parseInt(argValue, 10);
19405
+ if (!isNaN(parsed2)) return parsed2;
18734
19406
  }
18735
- registerHandler(method, handler) {
18736
- Logger.getInstance().info(`Register handler ${method}`);
18737
- this.handlers.set(method, handler);
19407
+ const value = process.env[key];
19408
+ if (!value) return defaultValue;
19409
+ const parsed = parseInt(value, 10);
19410
+ return isNaN(parsed) ? defaultValue : parsed;
19411
+ }
19412
+ function parseConfigBool(key, defaultValue) {
19413
+ const argValue = getArgValue(key);
19414
+ if (argValue !== void 0) {
19415
+ const parsed2 = argValue.toLowerCase();
19416
+ return parsed2 === "true" || parsed2 === "1";
18738
19417
  }
18739
- async listen(options) {
18740
- const requestListener = getRequestListener(this.app.fetch);
18741
- this.server = (0, import_node_http.createServer)(requestListener);
18742
- return new Promise((resolve, reject) => {
18743
- const onError = (err) => {
18744
- Logger.getInstance().error("Failed to start Hono Server", err);
18745
- reject(err);
18746
- };
18747
- this.server.once("error", onError);
18748
- if (options.path) {
18749
- this.server.listen(options.path, () => {
18750
- this.server.removeListener("error", onError);
18751
- Logger.getInstance().info(`Hono Server listening on pipe/socket: ${options.path}`);
18752
- resolve();
18753
- });
18754
- } else {
18755
- this.server.listen(options.port || 3e3, options.host || "127.0.0.1", () => {
18756
- this.server.removeListener("error", onError);
18757
- Logger.getInstance().info(`Hono Server listening on HTTP, port: ${options.port}, host: ${options.host}`);
19418
+ if (hasArgFlag(key)) {
19419
+ return true;
19420
+ }
19421
+ const value = process.env[key];
19422
+ if (!value) return defaultValue;
19423
+ const parsed = value.toLowerCase();
19424
+ return parsed === "true" || parsed === "1";
19425
+ }
19426
+ function parseConfigString(key, defaultValue) {
19427
+ return getArgValue(key) || process.env[key] || defaultValue;
19428
+ }
19429
+ function buildServerConfig() {
19430
+ return {
19431
+ mode: parseConfigString("MODE", "local").toLowerCase(),
19432
+ autoShutdownMinutes: parseConfigInt("AUTO_SHUTDOWN_MINUTES", 5),
19433
+ httpPort: parseConfigInt("HTTP_PORT", 8080)
19434
+ };
19435
+ }
19436
+ function buildLogConfig() {
19437
+ return {
19438
+ logToConsole: parseConfigBool("LOG_TO_CONSOLE", false),
19439
+ logLevel: parseConfigString("LOG_LEVEL", "info").toLowerCase()
19440
+ };
19441
+ }
19442
+ function buildStorageConfig() {
19443
+ return {
19444
+ persistInterval: parseConfigInt("STORAGE_PERSIST_INTERVAL", 5e3),
19445
+ // 5 second
19446
+ maxTracesPerApp: parseConfigInt("STORAGE_MAX_TRACES_PER_APP", 250)
19447
+ };
19448
+ }
19449
+ function buildServiceConfig() {
19450
+ return {
19451
+ proxyUrl: parseConfigString("SERVICE_PROXY_URL", "https://api.syn-cause.com/codeproxy"),
19452
+ pollingInterval: parseConfigInt("SERVICE_POLLING_INTERVAL", 1e4),
19453
+ // 10 second
19454
+ bindingCheckInterval: parseConfigInt("SERVICE_BINDING_CHECK_INTERVAL", 6e4)
19455
+ // 1 minute
19456
+ };
19457
+ }
19458
+ var cachedConfig = null;
19459
+ function getConfig() {
19460
+ if (!cachedConfig) {
19461
+ cachedConfig = {
19462
+ server: buildServerConfig(),
19463
+ log: buildLogConfig(),
19464
+ storage: buildStorageConfig(),
19465
+ service: buildServiceConfig()
19466
+ };
19467
+ }
19468
+ return cachedConfig;
19469
+ }
19470
+
19471
+ // src/core/api/ProxyApi.ts
19472
+ var AuthInput = class _AuthInput {
19473
+ apiKey;
19474
+ jwtToken;
19475
+ constructor(info) {
19476
+ this.apiKey = info.apiKey;
19477
+ this.jwtToken = info.jwtToken;
19478
+ }
19479
+ hasApiKey() {
19480
+ return !!this.apiKey;
19481
+ }
19482
+ hasJwtToken() {
19483
+ return !!this.jwtToken;
19484
+ }
19485
+ static fromApiKey(apiKey) {
19486
+ return new _AuthInput({ apiKey });
19487
+ }
19488
+ static fromJwtToken(jwtToken) {
19489
+ return new _AuthInput({ jwtToken });
19490
+ }
19491
+ getHeaders() {
19492
+ const headers = {};
19493
+ if (this.apiKey) {
19494
+ headers["X-API-Key"] = this.apiKey;
19495
+ }
19496
+ if (this.jwtToken) {
19497
+ headers["Authorization"] = `Bearer ${this.jwtToken}`;
19498
+ }
19499
+ return headers;
19500
+ }
19501
+ /**
19502
+ * Get the key to use for LLM API calls.
19503
+ * Returns apiKey if available, otherwise returns jwtToken.
19504
+ */
19505
+ getLlmKey() {
19506
+ return this.apiKey || this.jwtToken || "";
19507
+ }
19508
+ };
19509
+ var ProxyAuth = class {
19510
+ auth;
19511
+ constructor(auth) {
19512
+ this.auth = auth;
19513
+ }
19514
+ update(auth) {
19515
+ const oldAuth = this.auth;
19516
+ if (oldAuth.hasApiKey() && auth.hasJwtToken() && !auth.hasApiKey()) {
19517
+ return false;
19518
+ }
19519
+ if (oldAuth.getLlmKey() === auth.getLlmKey()) {
19520
+ return false;
19521
+ }
19522
+ this.auth = auth;
19523
+ return true;
19524
+ }
19525
+ get() {
19526
+ return this.auth;
19527
+ }
19528
+ getHeaders() {
19529
+ return this.auth.getHeaders();
19530
+ }
19531
+ getLlmKey() {
19532
+ return this.auth.getLlmKey();
19533
+ }
19534
+ };
19535
+ var ProxyApi = class {
19536
+ proxyUrl;
19537
+ constructor(proxyUrl) {
19538
+ this.proxyUrl = proxyUrl;
19539
+ }
19540
+ async fetchAppList(auth) {
19541
+ try {
19542
+ const response = await fetch(`${this.proxyUrl}/api/v1/apps`, {
19543
+ headers: auth.getHeaders()
19544
+ });
19545
+ if (!response.ok) {
19546
+ Logger.getInstance().warn(`Failed to fetch app list: ${response.status} ${response.statusText}`);
19547
+ return null;
19548
+ }
19549
+ const data = await response.json();
19550
+ if (data.code !== 200 || !data.data) {
19551
+ Logger.getInstance().warn("Failed to fetch app list or no data returned");
19552
+ return null;
19553
+ }
19554
+ return Array.isArray(data.data) ? data.data : [];
19555
+ } catch (error) {
19556
+ Logger.getInstance().error("Error fetching app list:", error);
19557
+ return null;
19558
+ }
19559
+ }
19560
+ async checkDeviceBinding(deviceId) {
19561
+ try {
19562
+ const response = await fetch(`${this.proxyUrl}/api/v1/devices/checkBind?deviceId=${deviceId}`);
19563
+ if (!response.ok) {
19564
+ Logger.getInstance().warn(`Failed to check device binding: ${response.status} ${response.statusText}`);
19565
+ return null;
19566
+ }
19567
+ const result = await response.json();
19568
+ if (result.success && result.data) {
19569
+ if (typeof result.data.isBound === "string") {
19570
+ result.data.isBound = result.data.isBound === "true";
19571
+ }
19572
+ return result.data;
19573
+ }
19574
+ return null;
19575
+ } catch (error) {
19576
+ Logger.getInstance().error("Error checking device binding:", error);
19577
+ return null;
19578
+ }
19579
+ }
19580
+ async pollRuntimeFacts(appId, auth) {
19581
+ try {
19582
+ const response = await fetch(`${this.proxyUrl}/api/v1/traces/${appId}`, {
19583
+ headers: auth.getHeaders()
19584
+ });
19585
+ if (!response.ok) {
19586
+ Logger.getInstance().warn(`Failed to fetch RuntimeFacts for ${appId}: ${response.status} ${response.statusText}`);
19587
+ return [];
19588
+ }
19589
+ const data = await response.json();
19590
+ if (!Array.isArray(data.data)) {
19591
+ Logger.getInstance().warn("Fetched data is not an array:", data.data);
19592
+ return [];
19593
+ }
19594
+ return data.data;
19595
+ } catch (error) {
19596
+ Logger.getInstance().error(`Error polling traces for ${appId}:`, error);
19597
+ return [];
19598
+ }
19599
+ }
19600
+ async fetchSession(auth) {
19601
+ try {
19602
+ const response = await fetch(`${this.proxyUrl}/api/v1/auth/session`, {
19603
+ headers: auth.getHeaders()
19604
+ });
19605
+ if (!response.ok) {
19606
+ Logger.getInstance().warn(`Failed to fetch session: ${response.status} ${response.statusText}`);
19607
+ return null;
19608
+ }
19609
+ const result = await response.json();
19610
+ const isSuccess = result.success === true || result.success === "true";
19611
+ if (isSuccess && result.data && result.data.userId) {
19612
+ return result.data.userId;
19613
+ }
19614
+ return null;
19615
+ } catch (error) {
19616
+ Logger.getInstance().error("Error fetching session:", error);
19617
+ return null;
19618
+ }
19619
+ }
19620
+ };
19621
+ var proxyApi = new ProxyApi(getConfig().service.proxyUrl);
19622
+
19623
+ // src/transport/server/hono-server.ts
19624
+ var HonoServer = class {
19625
+ constructor(onActivity) {
19626
+ this.onActivity = onActivity;
19627
+ this.app = new Hono2();
19628
+ this.setupRoutes();
19629
+ }
19630
+ app;
19631
+ handlers = /* @__PURE__ */ new Map();
19632
+ server;
19633
+ setupRoutes() {
19634
+ this.app.use("*", async (c, next) => {
19635
+ this.onActivity?.();
19636
+ await next();
19637
+ });
19638
+ this.app.post("/", async (c) => {
19639
+ const apiKey = c.req.header("x-api-key");
19640
+ const authHeader = c.req.header("authorization");
19641
+ let auth;
19642
+ if (apiKey) {
19643
+ auth = AuthInput.fromApiKey(apiKey);
19644
+ } else if (authHeader && authHeader.startsWith("Bearer ")) {
19645
+ const jwtToken = authHeader.substring(7);
19646
+ auth = AuthInput.fromJwtToken(jwtToken);
19647
+ }
19648
+ let body;
19649
+ try {
19650
+ body = await c.req.json();
19651
+ } catch (e) {
19652
+ return c.json({
19653
+ jsonrpc: "2.0",
19654
+ id: null,
19655
+ error: { code: -32700 /* PARSE_ERROR */, message: "Parse error" }
19656
+ }, 400);
19657
+ }
19658
+ Logger.getInstance().debug("Executing RPC handler", {
19659
+ hasApiKey: !!apiKey,
19660
+ hasJwtToken: !!authHeader,
19661
+ method: body?.method,
19662
+ requestId: body?.id,
19663
+ params: body?.params
19664
+ });
19665
+ if (!auth) {
19666
+ Logger.getInstance().debug("Unauthorized: No valid authentication provided");
19667
+ return c.json({
19668
+ jsonrpc: "2.0",
19669
+ id: body?.id || null,
19670
+ error: {
19671
+ code: -32001 /* UNAUTHORIZED */,
19672
+ message: "Unauthorized: Please provide either x-api-key or Authorization header"
19673
+ }
19674
+ }, 401);
19675
+ }
19676
+ if (!body || body.jsonrpc !== "2.0" || !body.method || !body.id) {
19677
+ Logger.getInstance().debug("Invalid Request: Not a standard JSON-RPC 2.0");
19678
+ return c.json({
19679
+ jsonrpc: "2.0",
19680
+ id: body?.id || null,
19681
+ error: { code: -32600 /* INVALID_REQUEST */, message: "Invalid Request: Not a standard JSON-RPC 2.0" }
19682
+ }, 400);
19683
+ }
19684
+ const handler = this.handlers.get(body.method);
19685
+ if (!handler) {
19686
+ return c.json({
19687
+ jsonrpc: "2.0",
19688
+ id: body.id,
19689
+ error: { code: -32601 /* METHOD_NOT_FOUND */, message: `Method not found: ${body.method}` }
19690
+ });
19691
+ }
19692
+ try {
19693
+ const result = await handler(body.params, auth);
19694
+ Logger.getInstance().debug("RPC handler executed successfully", {
19695
+ method: body.method,
19696
+ requestId: body.id
19697
+ });
19698
+ return c.json({
19699
+ jsonrpc: "2.0",
19700
+ id: body.id,
19701
+ result
19702
+ });
19703
+ } catch (err) {
19704
+ Logger.getInstance().error(`RPC Handler Error for ${body.method}:`, err);
19705
+ return c.json({
19706
+ jsonrpc: "2.0",
19707
+ id: body.id,
19708
+ error: { code: -32603 /* INTERNAL_ERROR */, message: err.message || "Internal error" }
19709
+ });
19710
+ }
19711
+ });
19712
+ }
19713
+ registerHandler(method, handler) {
19714
+ Logger.getInstance().info(`Register handler ${method}`);
19715
+ this.handlers.set(method, handler);
19716
+ }
19717
+ async listen(options) {
19718
+ const requestListener = getRequestListener(this.app.fetch);
19719
+ this.server = (0, import_node_http.createServer)(requestListener);
19720
+ return new Promise((resolve, reject) => {
19721
+ const onError = (err) => {
19722
+ Logger.getInstance().error("Failed to start Hono Server", err);
19723
+ reject(err);
19724
+ };
19725
+ this.server.once("error", onError);
19726
+ if (options.path) {
19727
+ this.server.listen(options.path, () => {
19728
+ this.server.removeListener("error", onError);
19729
+ Logger.getInstance().info(`Hono Server listening on pipe/socket: ${options.path}`);
19730
+ resolve();
19731
+ });
19732
+ } else {
19733
+ this.server.listen(options.port || 3e3, options.host || "127.0.0.1", () => {
19734
+ this.server.removeListener("error", onError);
19735
+ Logger.getInstance().info(`Hono Server listening on HTTP, port: ${options.port}, host: ${options.host}`);
18758
19736
  resolve();
18759
19737
  });
18760
19738
  }
@@ -18792,13 +19770,13 @@ function __classPrivateFieldGet(receiver, state, kind, f) {
18792
19770
 
18793
19771
  // node_modules/openai/internal/utils/uuid.mjs
18794
19772
  var uuid4 = function() {
18795
- const { crypto: crypto5 } = globalThis;
18796
- if (crypto5?.randomUUID) {
18797
- uuid4 = crypto5.randomUUID.bind(crypto5);
18798
- return crypto5.randomUUID();
19773
+ const { crypto: crypto6 } = globalThis;
19774
+ if (crypto6?.randomUUID) {
19775
+ uuid4 = crypto6.randomUUID.bind(crypto6);
19776
+ return crypto6.randomUUID();
18799
19777
  }
18800
19778
  const u8 = new Uint8Array(1);
18801
- const randomByte = crypto5 ? () => crypto5.getRandomValues(u8)[0] : () => Math.random() * 255 & 255;
19779
+ const randomByte = crypto6 ? () => crypto6.getRandomValues(u8)[0] : () => Math.random() * 255 & 255;
18802
19780
  return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) => (+c ^ randomByte() & 15 >> +c / 4).toString(16));
18803
19781
  };
18804
19782
 
@@ -25590,51 +26568,56 @@ var LLMService = class {
25590
26568
  limit = (0, import_p_limit.default)(5);
25591
26569
  // Concurrency limit for LLM calls
25592
26570
  LLMURL = "https://api.syn-cause.com/llm";
25593
- apiKey = "";
25594
- language = "en";
25595
- constructor(apiKey = "", language) {
25596
- this.apiKey = apiKey;
26571
+ auth;
26572
+ language = "English";
26573
+ constructor(auth, language) {
26574
+ this.auth = auth;
25597
26575
  this.language = language || this.detectLanguage();
25598
26576
  }
25599
26577
  detectLanguage() {
25600
26578
  try {
25601
26579
  const envLang = process.env.LANG || process.env.LANGUAGE || process.env.LC_ALL || process.env.LC_MESSAGES;
25602
26580
  if (envLang && envLang.toLowerCase().startsWith("zh")) {
25603
- return "zh";
26581
+ return "Chinese";
25604
26582
  }
25605
26583
  const locale = Intl.DateTimeFormat().resolvedOptions().locale;
25606
26584
  if (locale.toLowerCase().startsWith("zh")) {
25607
- return "zh";
26585
+ return "Chinese";
25608
26586
  }
25609
26587
  } catch (e) {
25610
26588
  }
25611
- return "en";
26589
+ return "English";
25612
26590
  }
25613
26591
  async embedding(text) {
25614
- if (!this.apiKey) {
25615
- throw new Error("LLM API Key (userApiKey) is not set");
25616
- }
25617
- const llm = new OpenAI({
25618
- apiKey: this.apiKey,
25619
- baseURL: this.LLMURL
25620
- });
25621
- const embedding = await llm.embeddings.create({
25622
- model: "qwen3-embedding-8b",
25623
- input: text,
25624
- encoding_format: "float"
26592
+ return this.limit(async () => {
26593
+ const apiKey = this.auth.getLlmKey();
26594
+ if (!apiKey) {
26595
+ throw new Error("LLM API Key (userApiKey) is not set");
26596
+ }
26597
+ const llm = new OpenAI({
26598
+ apiKey,
26599
+ baseURL: this.LLMURL
26600
+ });
26601
+ const embedding = await llm.embeddings.create({
26602
+ model: "qwen3-embedding-8b",
26603
+ input: text,
26604
+ encoding_format: "float"
26605
+ });
26606
+ return embedding.data[0].embedding;
25625
26607
  });
25626
- return embedding.data[0].embedding;
25627
26608
  }
25628
26609
  async processRuntimeFactWithLLM(trace) {
25629
- if (!this.apiKey) {
25630
- Logger.getInstance().error("LLM API Key is missing, skipping LLM processing");
25631
- return trace;
25632
- }
25633
- const temp_spans = trace.invokeTree;
25634
- const en_prompt = `
26610
+ return this.limit(async () => {
26611
+ const apiKey = this.auth.getLlmKey();
26612
+ if (!apiKey) {
26613
+ Logger.getInstance().error("LLM API Key is missing, skipping LLM processing");
26614
+ return trace;
26615
+ }
26616
+ const temp_spans = trace.invokeTree;
26617
+ let prompt = `
25635
26618
  <task>
25636
26619
  This is runtime data captured from a program.
25637
- Please generate a JSON summary based on the data provided.
26620
+ Please generate a JSON summary based on the data provided. Output in ${this.language}.
25638
26621
  </task>
25639
26622
  <output_format>
25640
26623
  \`\`\`json
@@ -25651,57 +26634,37 @@ The data is as follows:
25651
26634
  ${JSON.stringify(temp_spans)}
25652
26635
  </data>
25653
26636
  `;
25654
- const zh_prompt = `
25655
- <task>
25656
- This is runtime data captured from a program.
25657
- Please summarize it into a JSON object.
25658
- </task>
25659
- <output_format>
25660
- \`\`\`json
25661
- {
25662
- "title": "Short title",
25663
- "summary": "Detailed summary, one sentence description. Must be brief.",
25664
- "related_interface": "Related interface, just one",
25665
- "status": "Status, success/failure"
25666
- }
25667
- \`\`\`
25668
- </output_format>
25669
- Data follows
25670
- <data>
25671
- ${JSON.stringify(temp_spans)}
25672
- </data>
25673
- `;
25674
- let prompt = this.language === "en" ? en_prompt : zh_prompt;
25675
- try {
25676
- const llm = new OpenAI({
25677
- apiKey: this.apiKey,
25678
- baseURL: this.LLMURL
25679
- });
25680
- const res = await this.limit(() => llm.chat.completions.create({
25681
- model: "gpt-4.1-nano",
25682
- messages: [{ role: "user", content: prompt }],
25683
- temperature: 0.3
25684
- }));
25685
- const content = res.choices[0].message?.content || "";
25686
- trace.llmRawResponse = content;
25687
- const extracted = this.extractJsonFromString(content);
25688
- if (extracted) {
25689
- try {
25690
- trace.summaryEmbedding = await this.embedding(extracted.summary);
25691
- } catch (error) {
25692
- Logger.getInstance().error(`Failed to generate embedding for trace ${trace.traceId}:`, error);
26637
+ try {
26638
+ const llm = new OpenAI({
26639
+ apiKey,
26640
+ baseURL: this.LLMURL
26641
+ });
26642
+ const res = await llm.chat.completions.create({
26643
+ model: "gpt-4.1-nano",
26644
+ messages: [{ role: "user", content: prompt }],
26645
+ temperature: 0.3
26646
+ });
26647
+ const content = res.choices[0].message?.content || "";
26648
+ trace.llmRawResponse = content;
26649
+ const extracted = this.extractJsonFromString(content);
26650
+ if (extracted) {
26651
+ try {
26652
+ trace.summaryEmbedding = await this.embedding(extracted.summary);
26653
+ } catch (error) {
26654
+ Logger.getInstance().error(`Failed to generate embedding for trace ${trace.traceId}:`, error);
26655
+ }
26656
+ return { ...trace, ...extracted };
26657
+ } else {
26658
+ trace.llmError = "Failed to extract JSON from response";
26659
+ Logger.getInstance().warn(`Failed to extract JSON for ${trace.traceId}. Content: ${content}`);
25693
26660
  }
25694
- return { ...trace, ...extracted };
25695
- } else {
25696
- trace.llmError = "Failed to extract JSON from response";
25697
- Logger.getInstance().warn(`Failed to extract JSON for ${trace.traceId}. Content: ${content}`);
26661
+ } catch (error) {
26662
+ const errorMessage = error instanceof Error ? error.message : String(error);
26663
+ Logger.getInstance().error(`LLM processing failed for trace ${trace.traceId}:`, error);
26664
+ trace.llmError = errorMessage;
25698
26665
  }
25699
- } catch (error) {
25700
- const errorMessage = error instanceof Error ? error.message : String(error);
25701
- Logger.getInstance().error(`LLM processing failed for trace ${trace.traceId}:`, error);
25702
- trace.llmError = errorMessage;
25703
- }
25704
- return trace;
26666
+ return trace;
26667
+ });
25705
26668
  }
25706
26669
  extractJsonFromString(input) {
25707
26670
  const match2 = input.match(/```json\s*([\s\S]*?)\s*```/);
@@ -25721,12 +26684,10 @@ ${JSON.stringify(temp_spans)}
25721
26684
 
25722
26685
  // src/core/services/AppService.ts
25723
26686
  var AppService = class {
25724
- userApiKey = "";
25725
- proxyUrl = "";
26687
+ auth;
25726
26688
  appCache = /* @__PURE__ */ new Map();
25727
- constructor(apiKey, proxyUrl) {
25728
- this.userApiKey = apiKey;
25729
- this.proxyUrl = proxyUrl;
26689
+ constructor(auth) {
26690
+ this.auth = auth;
25730
26691
  }
25731
26692
  /**
25732
26693
  * Convert AppResponse to App
@@ -25740,30 +26701,7 @@ var AppService = class {
25740
26701
  };
25741
26702
  }
25742
26703
  async fetchAppList() {
25743
- if (!this.userApiKey) {
25744
- Logger.getInstance().warn("No API key found for fetching app list.");
25745
- return null;
25746
- }
25747
- try {
25748
- const applist_response = await fetch(`${this.proxyUrl}/api/v1/apps?api_key=${this.userApiKey}`, {
25749
- headers: {
25750
- "X-API_Key": this.userApiKey
25751
- }
25752
- });
25753
- if (!applist_response.ok) {
25754
- Logger.getInstance().warn(`Failed to fetch app list: ${applist_response.status} ${applist_response.statusText}`);
25755
- return null;
25756
- }
25757
- const applist_data = await applist_response.json();
25758
- if (applist_data.code !== 200 || !applist_data.data) {
25759
- Logger.getInstance().warn("Failed to fetch app list or no data returned");
25760
- return null;
25761
- }
25762
- return Array.isArray(applist_data.data) ? applist_data.data : [];
25763
- } catch (error) {
25764
- Logger.getInstance().error("Error fetching app list:", error);
25765
- return null;
25766
- }
26704
+ return proxyApi.fetchAppList(this.auth.get());
25767
26705
  }
25768
26706
  /**
25769
26707
  * Refreshes the internal app cache by fetching the latest app list.
@@ -25784,6 +26722,7 @@ var AppService = class {
25784
26722
  }
25785
26723
  }
25786
26724
  this.appCache = newCache;
26725
+ Logger.getInstance().debug(`Found ${connectedAppIds.length} apps with key: ${this.auth.getLlmKey().substring(0, 10)}...`);
25787
26726
  return connectedAppIds;
25788
26727
  }
25789
26728
  getCachedApp(appId) {
@@ -25836,152 +26775,6 @@ var AppService = class {
25836
26775
  }
25837
26776
  };
25838
26777
 
25839
- // src/config/index.ts
25840
- function getArgValue(key) {
25841
- const keys = [key, key.toLowerCase()];
25842
- for (const k of keys) {
25843
- const prefix = `--${k}=`;
25844
- const arg = process.argv.find((a) => a.startsWith(prefix));
25845
- if (arg) return arg.slice(prefix.length);
25846
- const index = process.argv.indexOf(`--${k}`);
25847
- if (index !== -1 && index + 1 < process.argv.length && !process.argv[index + 1].startsWith("--")) {
25848
- return process.argv[index + 1];
25849
- }
25850
- }
25851
- return void 0;
25852
- }
25853
- function hasArgFlag(key) {
25854
- const keys = [key, key.toLowerCase()];
25855
- return keys.some((k) => process.argv.includes(`--${k}`));
25856
- }
25857
- function parseConfigInt(key, defaultValue) {
25858
- const argValue = getArgValue(key);
25859
- if (argValue) {
25860
- const parsed2 = parseInt(argValue, 10);
25861
- if (!isNaN(parsed2)) return parsed2;
25862
- }
25863
- const value = process.env[key];
25864
- if (!value) return defaultValue;
25865
- const parsed = parseInt(value, 10);
25866
- return isNaN(parsed) ? defaultValue : parsed;
25867
- }
25868
- function parseConfigBool(key, defaultValue) {
25869
- const argValue = getArgValue(key);
25870
- if (argValue !== void 0) {
25871
- const parsed2 = argValue.toLowerCase();
25872
- return parsed2 === "true" || parsed2 === "1";
25873
- }
25874
- if (hasArgFlag(key)) {
25875
- return true;
25876
- }
25877
- const value = process.env[key];
25878
- if (!value) return defaultValue;
25879
- const parsed = value.toLowerCase();
25880
- return parsed === "true" || parsed === "1";
25881
- }
25882
- function parseConfigString(key, defaultValue) {
25883
- return getArgValue(key) || process.env[key] || defaultValue;
25884
- }
25885
- function buildServerConfig() {
25886
- return {
25887
- mode: parseConfigString("MODE", "local").toLowerCase(),
25888
- autoShutdownMinutes: parseConfigInt("AUTO_SHUTDOWN_MINUTES", 5),
25889
- httpPort: parseConfigInt("HTTP_PORT", 8080)
25890
- };
25891
- }
25892
- function buildLogConfig() {
25893
- return {
25894
- logToConsole: parseConfigBool("LOG_TO_CONSOLE", false),
25895
- logLevel: parseConfigString("LOG_LEVEL", "info").toLowerCase()
25896
- };
25897
- }
25898
- function buildStorageConfig() {
25899
- return {
25900
- persistInterval: parseConfigInt("STORAGE_PERSIST_INTERVAL", 5e3),
25901
- // 5 second
25902
- maxTracesPerApp: parseConfigInt("STORAGE_MAX_TRACES_PER_APP", 250)
25903
- };
25904
- }
25905
- function buildServiceConfig() {
25906
- return {
25907
- proxyUrl: parseConfigString("SERVICE_PROXY_URL", "https://api.syn-cause.com/codeproxy"),
25908
- pollingInterval: parseConfigInt("SERVICE_POLLING_INTERVAL", 1e4)
25909
- // 10 second
25910
- };
25911
- }
25912
- var cachedConfig = null;
25913
- function getConfig() {
25914
- if (!cachedConfig) {
25915
- cachedConfig = {
25916
- server: buildServerConfig(),
25917
- log: buildLogConfig(),
25918
- storage: buildStorageConfig(),
25919
- service: buildServiceConfig()
25920
- };
25921
- }
25922
- return cachedConfig;
25923
- }
25924
-
25925
- // src/core/services/TracePollingService.ts
25926
- var TracePollingService = class {
25927
- userApiKey;
25928
- proxyUrl;
25929
- constructor(apiKey, proxyUrl) {
25930
- this.userApiKey = apiKey;
25931
- this.proxyUrl = proxyUrl;
25932
- }
25933
- /**
25934
- * Poll runtime facts for a specific appId
25935
- * @param appId The application ID to poll traces for
25936
- * @returns Array of runtime facts or empty array if failed
25937
- */
25938
- async pollRuntimeFacts(appId) {
25939
- try {
25940
- const response = await fetch(`${this.proxyUrl}/api/v1/traces/${appId}?api_key=${this.userApiKey}`, {
25941
- headers: {
25942
- "X-API_Key": this.userApiKey
25943
- }
25944
- });
25945
- if (!response.ok) {
25946
- Logger.getInstance().warn(`Failed to fetch RuntimeFacts for ${appId}: ${response.status} ${response.statusText}`);
25947
- return [];
25948
- }
25949
- const data = await response.json();
25950
- if (!Array.isArray(data.data)) {
25951
- Logger.getInstance().warn("Fetched data is not an array:", data.data);
25952
- return [];
25953
- }
25954
- if (data.data.length > 0) {
25955
- Logger.getInstance().info(`Fetched ${data.data.length} RuntimeFacts for ${appId}.`);
25956
- }
25957
- return data.data;
25958
- } catch (error) {
25959
- Logger.getInstance().error(`Error polling traces for ${appId}:`, error);
25960
- return [];
25961
- }
25962
- }
25963
- /**
25964
- * Poll runtime facts for multiple appIds in parallel
25965
- * @param appIds Array of application IDs to poll
25966
- * @returns Map of appId to runtime facts
25967
- */
25968
- async pollMultipleApps(appIds) {
25969
- const results = await Promise.all(
25970
- appIds.map(async (appId) => ({
25971
- appId,
25972
- facts: await this.pollRuntimeFacts(appId)
25973
- }))
25974
- );
25975
- const resultMap = /* @__PURE__ */ new Map();
25976
- for (const { appId, facts } of results) {
25977
- if (facts.length > 0) {
25978
- resultMap.set(appId, facts);
25979
- }
25980
- }
25981
- return resultMap;
25982
- }
25983
- };
25984
-
25985
26778
  // node_modules/uuid/dist/esm-node/rng.js
25986
26779
  var import_crypto2 = __toESM(require("crypto"));
25987
26780
  var rnds8Pool = new Uint8Array(256);
@@ -26361,12 +27154,10 @@ var FuzzySearchStrategy = class {
26361
27154
  // src/core/services/TraceSearchService.ts
26362
27155
  var TraceSearchService = class {
26363
27156
  diskStorage;
26364
- appService;
26365
27157
  embeddingStrategy;
26366
27158
  fuzzyStrategy;
26367
- constructor(diskStorage, llmService, appService) {
27159
+ constructor(diskStorage, llmService) {
26368
27160
  this.diskStorage = diskStorage;
26369
- this.appService = appService;
26370
27161
  this.embeddingStrategy = new EmbeddingSearchStrategy(llmService);
26371
27162
  this.fuzzyStrategy = new FuzzySearchStrategy();
26372
27163
  }
@@ -26462,21 +27253,19 @@ var RuntimeFactService = class {
26462
27253
  llmService;
26463
27254
  appService;
26464
27255
  // Sub-services
26465
- pollingService;
26466
27256
  processingService;
26467
27257
  searchService;
26468
- userApiKey = "";
26469
27258
  proxyUrl;
26470
- constructor(apiKey, diskStorage) {
26471
- this.userApiKey = apiKey;
27259
+ proxyAuth;
27260
+ constructor(auth, diskStorage) {
26472
27261
  this.diskStorage = diskStorage;
26473
27262
  this.proxyUrl = getConfig().service.proxyUrl;
26474
- this.llmService = new LLMService(apiKey);
26475
- this.appService = new AppService(apiKey, this.proxyUrl);
26476
- this.pollingService = new TracePollingService(apiKey, this.proxyUrl);
27263
+ this.proxyAuth = new ProxyAuth(auth);
27264
+ this.llmService = new LLMService(this.proxyAuth);
27265
+ this.appService = new AppService(this.proxyAuth);
26477
27266
  this.processingService = new TraceProcessingService(diskStorage, this.llmService);
26478
- this.searchService = new TraceSearchService(diskStorage, this.llmService, this.appService);
26479
- Logger.getInstance().info(`Registered RuntimeFactsService for apiKey: ${apiKey.substring(0, 8)}... with proxyUrl: ${this.proxyUrl}`);
27267
+ this.searchService = new TraceSearchService(diskStorage, this.llmService);
27268
+ Logger.getInstance().info(`Registered RuntimeFactsService with proxyUrl: ${this.proxyUrl}`);
26480
27269
  }
26481
27270
  getDiskStorage() {
26482
27271
  return this.diskStorage;
@@ -26490,18 +27279,27 @@ var RuntimeFactService = class {
26490
27279
  getAllApps() {
26491
27280
  return this.appService.getAllApps();
26492
27281
  }
26493
- async pollAllApps() {
27282
+ async pollAllApps(processedAppIds) {
26494
27283
  try {
26495
- const connectedAppIds = await this.appService.refreshCache();
27284
+ let connectedAppIds = await this.appService.refreshCache();
27285
+ if (processedAppIds && processedAppIds.size > 0) {
27286
+ const beforeCount = connectedAppIds.length;
27287
+ connectedAppIds = connectedAppIds.filter((id) => !processedAppIds.has(id));
27288
+ const afterCount = connectedAppIds.length;
27289
+ if (beforeCount !== afterCount) {
27290
+ Logger.getInstance().info(`Skipping ${beforeCount - afterCount} apps already processed in this cycle.`);
27291
+ }
27292
+ }
26496
27293
  await Promise.all(connectedAppIds.map((appId) => this.pollAndProcessApp(appId)));
26497
- const activeProjectIds = this.appService.getCachedProjectIds();
26498
- await this.diskStorage.cleanupInactiveProjects(activeProjectIds);
27294
+ if (processedAppIds) {
27295
+ connectedAppIds.forEach((id) => processedAppIds.add(id));
27296
+ }
26499
27297
  } catch (error) {
26500
27298
  Logger.getInstance().error("Error polling all apps:", error);
26501
27299
  }
26502
27300
  }
26503
27301
  async pollAndProcessApp(appId) {
26504
- const facts = await this.pollingService.pollRuntimeFacts(appId);
27302
+ const facts = await proxyApi.pollRuntimeFacts(appId, this.proxyAuth.get());
26505
27303
  if (facts.length > 0) {
26506
27304
  const app = this.appService.getCachedApp(appId);
26507
27305
  if (app && app.projectId) {
@@ -26517,20 +27315,59 @@ var RuntimeFactService = class {
26517
27315
  }
26518
27316
  }
26519
27317
  async getRuntimeFacts(projectId, searchText, matchMode = "embedding", limit2 = 10) {
27318
+ if (!this.checkProjectAccess(projectId)) {
27319
+ return [];
27320
+ }
26520
27321
  return this.searchService.getRuntimeFacts(projectId, searchText, matchMode, limit2);
26521
27322
  }
26522
27323
  async getRuntimeEvents(projectId) {
27324
+ if (!this.checkProjectAccess(projectId)) {
27325
+ return [];
27326
+ }
26523
27327
  return this.diskStorage.getProjectRuntimeEvents(projectId);
26524
27328
  }
26525
27329
  async findTraceById(traceId, projectId) {
27330
+ if (!this.checkProjectAccess(projectId)) {
27331
+ return null;
27332
+ }
26526
27333
  return this.searchService.findTraceById(traceId, projectId);
26527
27334
  }
26528
27335
  async searchTraces(query, limit2 = 5, projectId, minSimilarity) {
27336
+ if (!this.checkProjectAccess(projectId)) {
27337
+ return [];
27338
+ }
26529
27339
  return this.searchService.searchTraces(query, limit2, projectId, minSimilarity);
26530
27340
  }
26531
27341
  async getAppStatus(projectId) {
27342
+ if (!this.checkProjectAccess(projectId)) {
27343
+ return "NOT_FOUND" /* NOT_FOUND */;
27344
+ }
26532
27345
  return this.appService.getAppStatus(projectId);
26533
27346
  }
27347
+ /**
27348
+ * Checks if the current user has access to the given projectId.
27349
+ */
27350
+ checkProjectAccess(projectId) {
27351
+ const activeProjectIds = this.appService.getCachedProjectIds();
27352
+ const hasAccess = activeProjectIds.includes(projectId);
27353
+ if (!hasAccess) {
27354
+ Logger.getInstance().warn(`Unauthorized access attempt to projectId: ${projectId} by user with key: ${this.proxyAuth.getLlmKey().substring(0, 10)}...`);
27355
+ }
27356
+ return hasAccess;
27357
+ }
27358
+ /**
27359
+ * Get the list of project IDs that are currently active (in cache) for this user.
27360
+ */
27361
+ getActiveProjectIds() {
27362
+ return this.appService.getCachedProjectIds();
27363
+ }
27364
+ /**
27365
+ * Update the authentication information for this service and its components.
27366
+ * Returns true if the authentication was actually changed.
27367
+ */
27368
+ updateAuth(auth) {
27369
+ return this.proxyAuth.update(auth);
27370
+ }
26534
27371
  };
26535
27372
 
26536
27373
  // src/core/storage/disk.ts
@@ -26870,14 +27707,114 @@ var DiskStorage = class {
26870
27707
  }
26871
27708
  };
26872
27709
 
27710
+ // src/core/services/AnonymousService.ts
27711
+ var import_crypto4 = __toESM(require("crypto"));
27712
+ var import_node_machine_id = __toESM(require_dist());
27713
+ var DEVICE_ID_SALT = "syncause-salt-";
27714
+ function getSystemDeviceId() {
27715
+ try {
27716
+ const rawDeviceId = (0, import_node_machine_id.machineIdSync)();
27717
+ if (!rawDeviceId || rawDeviceId.trim().length === 0) {
27718
+ throw new Error("Raw device ID is empty");
27719
+ }
27720
+ Logger.getInstance().info("Device ID obtained (hashed for privacy)");
27721
+ return import_crypto4.default.createHash("sha256").update(DEVICE_ID_SALT + rawDeviceId).digest("hex");
27722
+ } catch (error) {
27723
+ Logger.getInstance().error("Failed to get system device ID", error);
27724
+ throw new Error(`Failed to get device ID: ${error instanceof Error ? error.message : "Unknown error"}`);
27725
+ }
27726
+ }
27727
+ var AnonymousBindingService = class {
27728
+ // Anonymous account tracking
27729
+ anonymousUserId = null;
27730
+ boundUserId = null;
27731
+ deviceId = getSystemDeviceId();
27732
+ bindingCheckInterval = null;
27733
+ isAnonymousBound = false;
27734
+ constructor() {
27735
+ }
27736
+ /**
27737
+ * Start periodic scanning for anonymous account binding status
27738
+ * @param intervalMs Check interval in milliseconds
27739
+ */
27740
+ async startBindingScanner(intervalMs) {
27741
+ this.stopBindingScanner();
27742
+ this.isAnonymousBound = false;
27743
+ Logger.getInstance().info(`Starting device binding scanner for deviceId: ${this.deviceId} with interval: ${intervalMs}ms`);
27744
+ const checkBinding = async () => {
27745
+ try {
27746
+ if (!this.deviceId) {
27747
+ Logger.getInstance().warn("Device binding scanner stopped: missing deviceId");
27748
+ this.stopBindingScanner();
27749
+ return;
27750
+ }
27751
+ const bindingData = await proxyApi.checkDeviceBinding(this.deviceId);
27752
+ if (bindingData) {
27753
+ if (this.anonymousUserId === null) {
27754
+ Logger.getInstance().info(`Found Anonymous UserId: ${bindingData.anonymousUserId}, bind UserId: ${bindingData.bindUserId}`);
27755
+ } else if (this.isAnonymousBound === false && bindingData.isBound) {
27756
+ Logger.getInstance().info(`Detected Bind UserId: ${bindingData.bindUserId}`);
27757
+ }
27758
+ this.anonymousUserId = bindingData.anonymousUserId;
27759
+ this.boundUserId = bindingData.bindUserId;
27760
+ this.isAnonymousBound = bindingData.isBound;
27761
+ if (this.isAnonymousBound) {
27762
+ Logger.getInstance().info("Anonymous account is bound. Stopping binding scanner.");
27763
+ this.stopBindingScanner();
27764
+ return;
27765
+ }
27766
+ }
27767
+ if (this.bindingCheckInterval) {
27768
+ this.bindingCheckInterval = setTimeout(checkBinding, intervalMs);
27769
+ }
27770
+ } catch (error) {
27771
+ Logger.getInstance().error("Error during device binding check:", error);
27772
+ if (this.bindingCheckInterval) {
27773
+ this.bindingCheckInterval = setTimeout(checkBinding, intervalMs);
27774
+ }
27775
+ }
27776
+ };
27777
+ this.bindingCheckInterval = setTimeout(checkBinding, 0);
27778
+ }
27779
+ /**
27780
+ * Stop the device binding scanner
27781
+ */
27782
+ stopBindingScanner() {
27783
+ if (this.bindingCheckInterval) {
27784
+ clearTimeout(this.bindingCheckInterval);
27785
+ this.bindingCheckInterval = null;
27786
+ Logger.getInstance().info("Device binding scanner stopped.");
27787
+ }
27788
+ }
27789
+ /**
27790
+ * Resolve the effective userId.
27791
+ * If the provided userId is the anonymous account:
27792
+ * - returns boundUserId if it's already bound
27793
+ * - returns current anonymousUserId otherwise
27794
+ * If the provided userId is not the anonymous account, returns it as is.
27795
+ */
27796
+ resolveEffectiveUserId(userId) {
27797
+ if (this.anonymousUserId === userId && this.isAnonymousBound && this.boundUserId) {
27798
+ return this.boundUserId;
27799
+ }
27800
+ return userId;
27801
+ }
27802
+ getAnonymousUserId() {
27803
+ return this.anonymousUserId;
27804
+ }
27805
+ };
27806
+
26873
27807
  // src/core/services/MultiUserRuntimeFactService.ts
26874
27808
  var MultiUserRuntimeFactService = class _MultiUserRuntimeFactService {
26875
27809
  static instance;
26876
- // <apiKey, service>
27810
+ // <userId, service>
26877
27811
  services = /* @__PURE__ */ new Map();
27812
+ // <llmKey, userId>
27813
+ llmKeyToUserId = /* @__PURE__ */ new Map();
26878
27814
  pollingInterval = null;
26879
27815
  // Shared DiskStorage instance for all RuntimeFactService instances
26880
27816
  sharedDiskStorage = null;
27817
+ anonymousBindingService = new AnonymousBindingService();
26881
27818
  constructor() {
26882
27819
  }
26883
27820
  initialize(basePath) {
@@ -26889,45 +27826,128 @@ var MultiUserRuntimeFactService = class _MultiUserRuntimeFactService {
26889
27826
  }
26890
27827
  return _MultiUserRuntimeFactService.instance;
26891
27828
  }
26892
- getOrCreateService(apiKey) {
26893
- let service = this.services.get(apiKey);
26894
- if (!service) {
26895
- if (!this.sharedDiskStorage) {
26896
- throw new Error("MultiUserRuntimeFactService not initialized. Call initialize() first.");
27829
+ async getOrCreateService(auth) {
27830
+ const llmKey = auth.getLlmKey();
27831
+ let userId = this.llmKeyToUserId.get(llmKey);
27832
+ if (!userId) {
27833
+ userId = await proxyApi.fetchSession(auth) || void 0;
27834
+ if (userId) {
27835
+ Logger.getInstance().info(`Cache userId: ${userId} with key: ${llmKey.substring(0, 10)}...`);
27836
+ this.llmKeyToUserId.set(llmKey, userId);
26897
27837
  }
26898
- service = new RuntimeFactService(apiKey, this.sharedDiskStorage);
26899
- this.services.set(apiKey, service);
26900
27838
  }
27839
+ if (!userId) {
27840
+ throw new Error(`Failed to fetch userId for auth`);
27841
+ }
27842
+ let resolvedUserId = this.anonymousBindingService.resolveEffectiveUserId(userId);
27843
+ let service = this.services.get(resolvedUserId);
27844
+ if (service) {
27845
+ if (resolvedUserId === userId) {
27846
+ if (service.updateAuth(auth)) {
27847
+ Logger.getInstance().info(`Updated credentials for primary userId: ${resolvedUserId} with key: ${llmKey.substring(0, 10)}...`);
27848
+ }
27849
+ }
27850
+ return service;
27851
+ }
27852
+ if (resolvedUserId !== userId) {
27853
+ service = this.services.get(userId);
27854
+ if (service) {
27855
+ if (service.updateAuth(auth)) {
27856
+ Logger.getInstance().info(`Updated credentials for anonymous userId: ${userId} with key: ${llmKey.substring(0, 10)}...`);
27857
+ }
27858
+ return service;
27859
+ }
27860
+ }
27861
+ if (!this.sharedDiskStorage) {
27862
+ throw new Error("MultiUserRuntimeFactService not initialized. Call initialize() first.");
27863
+ }
27864
+ service = new RuntimeFactService(auth, this.sharedDiskStorage);
27865
+ this.services.set(userId, service);
27866
+ Logger.getInstance().info(`Created RuntimeFactService for userId: ${userId}`);
26901
27867
  return service;
26902
27868
  }
26903
27869
  /**
26904
- * Registers an apiKey to the service. If a service for this apiKey doesn't exist, it will be created.
27870
+ * Registers an auth to the service. If a service for this auth doesn't exist, it will be created.
26905
27871
  */
26906
- registerApiKey(apiKey) {
26907
- this.getOrCreateService(apiKey);
27872
+ async registerAuth(auth) {
27873
+ await this.getOrCreateService(auth);
26908
27874
  }
26909
- async startGlobalPolling(intervalMs) {
26910
- if (this.pollingInterval) {
26911
- clearInterval(this.pollingInterval);
26912
- }
26913
- Logger.getInstance().info(`Starting global RuntimeFact polling for all registered apiKeys with interval: ${intervalMs}ms...`);
26914
- const runPollCycle = async () => {
26915
- const apiKeys = Array.from(this.services.keys());
26916
- await Promise.all(apiKeys.map(async (apiKey) => {
26917
- const service = this.services.get(apiKey);
26918
- if (service) {
26919
- try {
26920
- await service.pollAllApps();
26921
- } catch (error) {
26922
- Logger.getInstance().error(`Error polling for apiKey ${apiKey.substring(0, 8)}...:`, error);
26923
- }
27875
+ async startGlobalPolling(intervalMs, bindingCheckInterval) {
27876
+ this.stopGlobalPolling();
27877
+ if (bindingCheckInterval > 0) {
27878
+ this.anonymousBindingService.startBindingScanner(bindingCheckInterval);
27879
+ }
27880
+ Logger.getInstance().info(`Starting global RuntimeFact polling... Interval: ${intervalMs}ms`);
27881
+ const scheduleNext = () => {
27882
+ this.pollingInterval = setTimeout(async () => {
27883
+ try {
27884
+ await this.executePollCycle();
27885
+ } catch (error) {
27886
+ Logger.getInstance().error("Critical error in poll cycle:", error);
27887
+ } finally {
27888
+ if (this.pollingInterval) scheduleNext();
26924
27889
  }
26925
- }));
26926
- if (this.pollingInterval) {
26927
- this.pollingInterval = setTimeout(runPollCycle, intervalMs);
26928
- }
27890
+ }, intervalMs);
26929
27891
  };
26930
- this.pollingInterval = setTimeout(runPollCycle, 0);
27892
+ this.pollingInterval = setTimeout(async () => {
27893
+ await this.executePollCycle();
27894
+ if (this.pollingInterval) scheduleNext();
27895
+ }, 0);
27896
+ }
27897
+ /**
27898
+ * Executes a single polling cycle with priority:
27899
+ * 1. Categorize and cleanup redundant services
27900
+ * 2. Poll primary services first and collect processed App IDs
27901
+ * 3. Poll the anonymous service last, excluding already processed App IDs
27902
+ */
27903
+ async executePollCycle() {
27904
+ const anonymousUserId = this.anonymousBindingService.getAnonymousUserId();
27905
+ const primaryServices = [];
27906
+ let anonymousService = null;
27907
+ for (const [userId, service] of this.services.entries()) {
27908
+ const resolvedUserId = this.anonymousBindingService.resolveEffectiveUserId(userId);
27909
+ if (resolvedUserId !== userId && this.services.has(resolvedUserId)) {
27910
+ this.services.delete(userId);
27911
+ Logger.getInstance().info(`Polling: Pruned redundant anonymous service for ${userId}`);
27912
+ continue;
27913
+ }
27914
+ if (userId === anonymousUserId) {
27915
+ anonymousService = service;
27916
+ } else {
27917
+ primaryServices.push(service);
27918
+ }
27919
+ }
27920
+ const processedAppIds = /* @__PURE__ */ new Set();
27921
+ await Promise.all(primaryServices.map(async (service) => {
27922
+ try {
27923
+ await service.pollAllApps(processedAppIds);
27924
+ } catch (error) {
27925
+ Logger.getInstance().error("Error in primary service poll:", error);
27926
+ }
27927
+ }));
27928
+ if (anonymousService) {
27929
+ try {
27930
+ await anonymousService.pollAllApps(processedAppIds);
27931
+ } catch (error) {
27932
+ Logger.getInstance().error("Error in anonymous service poll:", error);
27933
+ }
27934
+ }
27935
+ if (this.sharedDiskStorage) {
27936
+ const globalActiveProjectIds = this.getAllActiveProjectIds();
27937
+ await this.sharedDiskStorage.cleanupInactiveProjects(globalActiveProjectIds);
27938
+ }
27939
+ }
27940
+ /**
27941
+ * Aggregates all active project IDs across all user services.
27942
+ * Used for shared DiskStorage cache cleanup.
27943
+ */
27944
+ getAllActiveProjectIds() {
27945
+ const allProjectIds = /* @__PURE__ */ new Set();
27946
+ for (const service of this.services.values()) {
27947
+ const projectIds = service.getActiveProjectIds();
27948
+ projectIds.forEach((id) => allProjectIds.add(id));
27949
+ }
27950
+ return Array.from(allProjectIds);
26931
27951
  }
26932
27952
  stopGlobalPolling() {
26933
27953
  if (this.pollingInterval) {
@@ -26941,6 +27961,7 @@ var MultiUserRuntimeFactService = class _MultiUserRuntimeFactService {
26941
27961
  */
26942
27962
  async shutdown() {
26943
27963
  this.stopGlobalPolling();
27964
+ this.anonymousBindingService.stopBindingScanner();
26944
27965
  if (this.sharedDiskStorage) {
26945
27966
  try {
26946
27967
  await this.sharedDiskStorage.shutdown();
@@ -26949,28 +27970,36 @@ var MultiUserRuntimeFactService = class _MultiUserRuntimeFactService {
26949
27970
  }
26950
27971
  }
26951
27972
  }
26952
- async getRuntimeFacts(apiKey, projectId, searchText, matchMode = "embedding", limit2 = 10) {
26953
- const service = this.getOrCreateService(apiKey);
27973
+ async getRuntimeFacts(auth, projectId, searchText, matchMode = "embedding", limit2 = 10) {
27974
+ const service = await this.getOrCreateService(auth);
26954
27975
  return await service.getRuntimeFacts(projectId, searchText, matchMode, limit2);
26955
27976
  }
26956
- async getAppList(apiKey) {
26957
- const service = this.getOrCreateService(apiKey);
27977
+ async getAppList(auth) {
27978
+ const service = await this.getOrCreateService(auth);
26958
27979
  return service.getAllApps();
26959
27980
  }
26960
- async getRuntimeEvents(apiKey, projectId) {
26961
- const service = this.getOrCreateService(apiKey);
27981
+ async getRuntimeEvents(auth, projectId) {
27982
+ const service = await this.getOrCreateService(auth);
26962
27983
  return await service.getRuntimeEvents(projectId);
26963
27984
  }
26964
27985
  };
26965
27986
 
26966
27987
  // src/rpc/handler/pingHandler.ts
26967
- async function pingHandler(params, apiKey) {
26968
- if (apiKey) {
26969
- MultiUserRuntimeFactService.getInstance().registerApiKey(apiKey);
27988
+ async function pingHandler(params, auth) {
27989
+ if (auth) {
27990
+ await MultiUserRuntimeFactService.getInstance().registerAuth(auth);
26970
27991
  }
26971
27992
  return "pong";
26972
27993
  }
26973
27994
 
27995
+ // src/rpc/handler/getAppListHandler.ts
27996
+ async function getAppListHandler(params, auth) {
27997
+ if (!auth) {
27998
+ throw new Error("Authentication required");
27999
+ }
28000
+ return await MultiUserRuntimeFactService.getInstance().getAppList(auth);
28001
+ }
28002
+
26974
28003
  // src/rpc/utils/errors.ts
26975
28004
  var RpcError = class extends Error {
26976
28005
  constructor(code, message, field, details) {
@@ -26994,16 +28023,6 @@ var RpcError = class extends Error {
26994
28023
  };
26995
28024
 
26996
28025
  // src/rpc/utils/validation.ts
26997
- function validateApiKey(apiKey) {
26998
- if (!apiKey) {
26999
- throw new RpcError(
27000
- "MISSING_API_KEY" /* MISSING_API_KEY */,
27001
- "API key is required",
27002
- "apiKey"
27003
- );
27004
- }
27005
- return apiKey;
27006
- }
27007
28026
  function validateRequiredParams(params, requiredFields) {
27008
28027
  if (!params) {
27009
28028
  throw new RpcError(
@@ -27023,30 +28042,28 @@ function validateRequiredParams(params, requiredFields) {
27023
28042
  }
27024
28043
  }
27025
28044
 
27026
- // src/rpc/handler/getAppListHandler.ts
27027
- async function getAppListHandler(params, apiKey) {
27028
- const validatedApiKey = validateApiKey(apiKey);
27029
- return await MultiUserRuntimeFactService.getInstance().getAppList(validatedApiKey);
27030
- }
27031
-
27032
28045
  // src/rpc/handler/getRuntimeEventsHandler.ts
27033
- async function getRuntimeEventsHandler(params, apiKey) {
27034
- const validatedApiKey = validateApiKey(apiKey);
28046
+ async function getRuntimeEventsHandler(params, auth) {
28047
+ if (!auth) {
28048
+ throw new Error("Authentication required");
28049
+ }
27035
28050
  const { projectId } = params;
27036
28051
  validateRequiredParams({ projectId }, ["projectId"]);
27037
28052
  return await MultiUserRuntimeFactService.getInstance().getRuntimeEvents(
27038
- validatedApiKey,
28053
+ auth,
27039
28054
  projectId
27040
28055
  );
27041
28056
  }
27042
28057
 
27043
28058
  // src/rpc/handler/getRuntimeFactsHandler.ts
27044
- async function getRuntimeFactsHandler(params, apiKey) {
27045
- const validatedApiKey = validateApiKey(apiKey);
28059
+ async function getRuntimeFactsHandler(params, auth) {
28060
+ if (!auth) {
28061
+ throw new Error("Authentication required");
28062
+ }
27046
28063
  const { projectId, searchText, matchMode } = params;
27047
28064
  validateRequiredParams({ projectId }, ["projectId"]);
27048
28065
  return await MultiUserRuntimeFactService.getInstance().getRuntimeFacts(
27049
- validatedApiKey,
28066
+ auth,
27050
28067
  projectId,
27051
28068
  searchText,
27052
28069
  matchMode
@@ -27064,11 +28081,13 @@ function formatTimestamp(timestampMilli) {
27064
28081
  const seconds = String(date.getSeconds()).padStart(2, "0");
27065
28082
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
27066
28083
  }
27067
- async function searchDebugTracesHandler(params, apiKey) {
27068
- const validatedApiKey = validateApiKey(apiKey);
28084
+ async function searchDebugTracesHandler(params, auth) {
28085
+ if (!auth) {
28086
+ throw new Error("Authentication required");
28087
+ }
27069
28088
  const { projectId, query, limit: limit2 } = params;
27070
28089
  validateRequiredParams({ projectId, query }, ["projectId", "query"]);
27071
- const service = MultiUserRuntimeFactService.getInstance().getOrCreateService(validatedApiKey);
28090
+ const service = await MultiUserRuntimeFactService.getInstance().getOrCreateService(auth);
27072
28091
  const results = await service.searchTraces(
27073
28092
  query,
27074
28093
  limit2,
@@ -27289,11 +28308,13 @@ _No SQL queries found._
27289
28308
  }
27290
28309
 
27291
28310
  // src/rpc/handler/getTraceInsightHandler.ts
27292
- async function getTraceInsightHandler(params, apiKey) {
27293
- const validatedApiKey = validateApiKey(apiKey);
28311
+ async function getTraceInsightHandler(params, auth) {
28312
+ if (!auth) {
28313
+ throw new Error("Authentication required");
28314
+ }
27294
28315
  const { projectId, traceId } = params;
27295
28316
  validateRequiredParams({ projectId, traceId }, ["projectId", "traceId"]);
27296
- const service = MultiUserRuntimeFactService.getInstance().getOrCreateService(validatedApiKey);
28317
+ const service = await MultiUserRuntimeFactService.getInstance().getOrCreateService(auth);
27297
28318
  const trace = await service.findTraceById(traceId, projectId);
27298
28319
  if (!trace) {
27299
28320
  throw new RpcError(
@@ -27547,11 +28568,13 @@ ${Array.from(new Set(allSqls)).join("\n")}
27547
28568
  }
27548
28569
 
27549
28570
  // src/rpc/handler/inspectMethodSnapshotHandler.ts
27550
- async function inspectMethodSnapshotHandler(params, apiKey) {
27551
- const validatedApiKey = validateApiKey(apiKey);
28571
+ async function inspectMethodSnapshotHandler(params, auth) {
28572
+ if (!auth) {
28573
+ throw new Error("Authentication required");
28574
+ }
27552
28575
  const { projectId, traceId, className, methodName, includeSubCalls = true } = params;
27553
28576
  validateRequiredParams({ projectId, traceId }, ["projectId", "traceId"]);
27554
- const service = MultiUserRuntimeFactService.getInstance().getOrCreateService(validatedApiKey);
28577
+ const service = await MultiUserRuntimeFactService.getInstance().getOrCreateService(auth);
27555
28578
  const trace = await service.findTraceById(traceId, projectId);
27556
28579
  if (!trace) return `Trace ${traceId} not found.`;
27557
28580
  if (!trace.invokeTree) {
@@ -27821,11 +28844,13 @@ function generateSuggestedFix(baseTrace, compareTrace) {
27821
28844
  }
27822
28845
 
27823
28846
  // src/rpc/handler/diffTraceExecutionHandler.ts
27824
- async function diffTraceExecutionHandler(params, apiKey) {
27825
- const validatedApiKey = validateApiKey(apiKey);
28847
+ async function diffTraceExecutionHandler(params, auth) {
28848
+ if (!auth) {
28849
+ throw new Error("Authentication required");
28850
+ }
27826
28851
  const { projectId, baseTraceId, compareTraceId } = params;
27827
28852
  validateRequiredParams({ projectId, baseTraceId }, ["projectId", "baseTraceId"]);
27828
- const service = MultiUserRuntimeFactService.getInstance().getOrCreateService(validatedApiKey);
28853
+ const service = await MultiUserRuntimeFactService.getInstance().getOrCreateService(auth);
27829
28854
  const baseTrace = await service.findTraceById(baseTraceId, projectId);
27830
28855
  if (!baseTrace) return `Base trace ${baseTraceId} not found.`;
27831
28856
  let compareTrace;
@@ -28112,7 +29137,7 @@ async function main() {
28112
29137
  autoShutdownMinutes: config.server.autoShutdownMinutes,
28113
29138
  httpPort: config.server.httpPort
28114
29139
  });
28115
- MultiUserRuntimeFactService.getInstance().startGlobalPolling(config.service.pollingInterval);
29140
+ MultiUserRuntimeFactService.getInstance().startGlobalPolling(config.service.pollingInterval, config.service.bindingCheckInterval);
28116
29141
  let server;
28117
29142
  if (config.server.mode === "remote") {
28118
29143
  server = await startServer2(serverConfig, config.server.httpPort);