@automagik/omni 2.260405.2 → 2.260406.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.
package/dist/index.js CHANGED
@@ -5779,11 +5779,11 @@ var require_nuid = __commonJS((exports) => {
5779
5779
  var require_core = __commonJS((exports) => {
5780
5780
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
5781
5781
  function adopt(value) {
5782
- return value instanceof P ? value : new P(function(resolve2) {
5783
- resolve2(value);
5782
+ return value instanceof P ? value : new P(function(resolve3) {
5783
+ resolve3(value);
5784
5784
  });
5785
5785
  }
5786
- return new (P || (P = Promise))(function(resolve2, reject) {
5786
+ return new (P || (P = Promise))(function(resolve3, reject) {
5787
5787
  function fulfilled(value) {
5788
5788
  try {
5789
5789
  step(generator.next(value));
@@ -5799,7 +5799,7 @@ var require_core = __commonJS((exports) => {
5799
5799
  }
5800
5800
  }
5801
5801
  function step(result) {
5802
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
5802
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
5803
5803
  }
5804
5804
  step((generator = generator.apply(thisArg, _arguments || [])).next());
5805
5805
  });
@@ -6002,11 +6002,11 @@ var require_core = __commonJS((exports) => {
6002
6002
  var require_util = __commonJS((exports) => {
6003
6003
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
6004
6004
  function adopt(value) {
6005
- return value instanceof P ? value : new P(function(resolve2) {
6006
- resolve2(value);
6005
+ return value instanceof P ? value : new P(function(resolve3) {
6006
+ resolve3(value);
6007
6007
  });
6008
6008
  }
6009
- return new (P || (P = Promise))(function(resolve2, reject) {
6009
+ return new (P || (P = Promise))(function(resolve3, reject) {
6010
6010
  function fulfilled(value) {
6011
6011
  try {
6012
6012
  step(generator.next(value));
@@ -6022,7 +6022,7 @@ var require_util = __commonJS((exports) => {
6022
6022
  }
6023
6023
  }
6024
6024
  function step(result) {
6025
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
6025
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
6026
6026
  }
6027
6027
  step((generator = generator.apply(thisArg, _arguments || [])).next());
6028
6028
  });
@@ -6036,14 +6036,14 @@ var require_util = __commonJS((exports) => {
6036
6036
  }, i);
6037
6037
  function verb(n) {
6038
6038
  i[n] = o[n] && function(v) {
6039
- return new Promise(function(resolve2, reject) {
6040
- v = o[n](v), settle(resolve2, reject, v.done, v.value);
6039
+ return new Promise(function(resolve3, reject) {
6040
+ v = o[n](v), settle(resolve3, reject, v.done, v.value);
6041
6041
  });
6042
6042
  };
6043
6043
  }
6044
- function settle(resolve2, reject, d, v) {
6044
+ function settle(resolve3, reject, d, v) {
6045
6045
  Promise.resolve(v).then(function(v2) {
6046
- resolve2({ value: v2, done: d });
6046
+ resolve3({ value: v2, done: d });
6047
6047
  }, reject);
6048
6048
  }
6049
6049
  };
@@ -6102,9 +6102,9 @@ var require_util = __commonJS((exports) => {
6102
6102
  }
6103
6103
  function delay(ms = 0) {
6104
6104
  let methods;
6105
- const p = new Promise((resolve2) => {
6105
+ const p = new Promise((resolve3) => {
6106
6106
  const timer = setTimeout(() => {
6107
- resolve2();
6107
+ resolve3();
6108
6108
  }, ms);
6109
6109
  const cancel = () => {
6110
6110
  if (timer) {
@@ -6123,18 +6123,18 @@ var require_util = __commonJS((exports) => {
6123
6123
  }
6124
6124
  function deferred() {
6125
6125
  let methods = {};
6126
- const p = new Promise((resolve2, reject) => {
6127
- methods = { resolve: resolve2, reject };
6126
+ const p = new Promise((resolve3, reject) => {
6127
+ methods = { resolve: resolve3, reject };
6128
6128
  });
6129
6129
  return Object.assign(p, methods);
6130
6130
  }
6131
6131
  function debugDeferred() {
6132
6132
  let methods = {};
6133
- const p = new Promise((resolve2, reject) => {
6133
+ const p = new Promise((resolve3, reject) => {
6134
6134
  methods = {
6135
6135
  resolve: (v) => {
6136
6136
  console.trace("resolve", v);
6137
- resolve2(v);
6137
+ resolve3(v);
6138
6138
  },
6139
6139
  reject: (err) => {
6140
6140
  console.trace("reject");
@@ -6616,11 +6616,11 @@ var require_ipparser = __commonJS((exports) => {
6616
6616
  var require_servers = __commonJS((exports) => {
6617
6617
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
6618
6618
  function adopt(value) {
6619
- return value instanceof P ? value : new P(function(resolve2) {
6620
- resolve2(value);
6619
+ return value instanceof P ? value : new P(function(resolve3) {
6620
+ resolve3(value);
6621
6621
  });
6622
6622
  }
6623
- return new (P || (P = Promise))(function(resolve2, reject) {
6623
+ return new (P || (P = Promise))(function(resolve3, reject) {
6624
6624
  function fulfilled(value) {
6625
6625
  try {
6626
6626
  step(generator.next(value));
@@ -6636,7 +6636,7 @@ var require_servers = __commonJS((exports) => {
6636
6636
  }
6637
6637
  }
6638
6638
  function step(result) {
6639
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
6639
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
6640
6640
  }
6641
6641
  step((generator = generator.apply(thisArg, _arguments || [])).next());
6642
6642
  });
@@ -12045,11 +12045,11 @@ var require_options = __commonJS((exports) => {
12045
12045
  var require_protocol = __commonJS((exports) => {
12046
12046
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
12047
12047
  function adopt(value) {
12048
- return value instanceof P ? value : new P(function(resolve2) {
12049
- resolve2(value);
12048
+ return value instanceof P ? value : new P(function(resolve3) {
12049
+ resolve3(value);
12050
12050
  });
12051
12051
  }
12052
- return new (P || (P = Promise))(function(resolve2, reject) {
12052
+ return new (P || (P = Promise))(function(resolve3, reject) {
12053
12053
  function fulfilled(value) {
12054
12054
  try {
12055
12055
  step(generator.next(value));
@@ -12065,7 +12065,7 @@ var require_protocol = __commonJS((exports) => {
12065
12065
  }
12066
12066
  }
12067
12067
  function step(result) {
12068
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
12068
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
12069
12069
  }
12070
12070
  step((generator = generator.apply(thisArg, _arguments || [])).next());
12071
12071
  });
@@ -12079,14 +12079,14 @@ var require_protocol = __commonJS((exports) => {
12079
12079
  }, i);
12080
12080
  function verb(n) {
12081
12081
  i[n] = o[n] && function(v) {
12082
- return new Promise(function(resolve2, reject) {
12083
- v = o[n](v), settle(resolve2, reject, v.done, v.value);
12082
+ return new Promise(function(resolve3, reject) {
12083
+ v = o[n](v), settle(resolve3, reject, v.done, v.value);
12084
12084
  });
12085
12085
  };
12086
12086
  }
12087
- function settle(resolve2, reject, d, v) {
12087
+ function settle(resolve3, reject, d, v) {
12088
12088
  Promise.resolve(v).then(function(v2) {
12089
- resolve2({ value: v2, done: d });
12089
+ resolve3({ value: v2, done: d });
12090
12090
  }, reject);
12091
12091
  }
12092
12092
  };
@@ -12497,12 +12497,12 @@ var require_protocol = __commonJS((exports) => {
12497
12497
  }
12498
12498
  _doDial(srv) {
12499
12499
  return __awaiter(this, undefined, undefined, function* () {
12500
- const { resolve: resolve2 } = this.options;
12500
+ const { resolve: resolve3 } = this.options;
12501
12501
  const alts = yield srv.resolve({
12502
12502
  fn: (0, transport_1.getResolveFn)(),
12503
12503
  debug: this.options.debug,
12504
12504
  randomize: !this.options.noRandomize,
12505
- resolve: resolve2
12505
+ resolve: resolve3
12506
12506
  });
12507
12507
  let lastErr = null;
12508
12508
  for (const a of alts) {
@@ -13250,11 +13250,11 @@ var require_jsutil = __commonJS((exports) => {
13250
13250
  var require_jsbaseclient_api = __commonJS((exports) => {
13251
13251
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
13252
13252
  function adopt(value) {
13253
- return value instanceof P ? value : new P(function(resolve2) {
13254
- resolve2(value);
13253
+ return value instanceof P ? value : new P(function(resolve3) {
13254
+ resolve3(value);
13255
13255
  });
13256
13256
  }
13257
- return new (P || (P = Promise))(function(resolve2, reject) {
13257
+ return new (P || (P = Promise))(function(resolve3, reject) {
13258
13258
  function fulfilled(value) {
13259
13259
  try {
13260
13260
  step(generator.next(value));
@@ -13270,7 +13270,7 @@ var require_jsbaseclient_api = __commonJS((exports) => {
13270
13270
  }
13271
13271
  }
13272
13272
  function step(result) {
13273
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
13273
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
13274
13274
  }
13275
13275
  step((generator = generator.apply(thisArg, _arguments || [])).next());
13276
13276
  });
@@ -13378,11 +13378,11 @@ var require_jsbaseclient_api = __commonJS((exports) => {
13378
13378
  var require_jslister = __commonJS((exports) => {
13379
13379
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
13380
13380
  function adopt(value) {
13381
- return value instanceof P ? value : new P(function(resolve2) {
13382
- resolve2(value);
13381
+ return value instanceof P ? value : new P(function(resolve3) {
13382
+ resolve3(value);
13383
13383
  });
13384
13384
  }
13385
- return new (P || (P = Promise))(function(resolve2, reject) {
13385
+ return new (P || (P = Promise))(function(resolve3, reject) {
13386
13386
  function fulfilled(value) {
13387
13387
  try {
13388
13388
  step(generator.next(value));
@@ -13398,7 +13398,7 @@ var require_jslister = __commonJS((exports) => {
13398
13398
  }
13399
13399
  }
13400
13400
  function step(result) {
13401
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
13401
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
13402
13402
  }
13403
13403
  step((generator = generator.apply(thisArg, _arguments || [])).next());
13404
13404
  });
@@ -13875,11 +13875,11 @@ var require_types2 = __commonJS((exports) => {
13875
13875
  var require_jsmconsumer_api = __commonJS((exports) => {
13876
13876
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
13877
13877
  function adopt(value) {
13878
- return value instanceof P ? value : new P(function(resolve2) {
13879
- resolve2(value);
13878
+ return value instanceof P ? value : new P(function(resolve3) {
13879
+ resolve3(value);
13880
13880
  });
13881
13881
  }
13882
- return new (P || (P = Promise))(function(resolve2, reject) {
13882
+ return new (P || (P = Promise))(function(resolve3, reject) {
13883
13883
  function fulfilled(value) {
13884
13884
  try {
13885
13885
  step(generator.next(value));
@@ -13895,7 +13895,7 @@ var require_jsmconsumer_api = __commonJS((exports) => {
13895
13895
  }
13896
13896
  }
13897
13897
  function step(result) {
13898
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
13898
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
13899
13899
  }
13900
13900
  step((generator = generator.apply(thisArg, _arguments || [])).next());
13901
13901
  });
@@ -14144,11 +14144,11 @@ var require_mod2 = __commonJS((exports) => {
14144
14144
  var require_jsmsg = __commonJS((exports) => {
14145
14145
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
14146
14146
  function adopt(value) {
14147
- return value instanceof P ? value : new P(function(resolve2) {
14148
- resolve2(value);
14147
+ return value instanceof P ? value : new P(function(resolve3) {
14148
+ resolve3(value);
14149
14149
  });
14150
14150
  }
14151
- return new (P || (P = Promise))(function(resolve2, reject) {
14151
+ return new (P || (P = Promise))(function(resolve3, reject) {
14152
14152
  function fulfilled(value) {
14153
14153
  try {
14154
14154
  step(generator.next(value));
@@ -14164,7 +14164,7 @@ var require_jsmsg = __commonJS((exports) => {
14164
14164
  }
14165
14165
  }
14166
14166
  function step(result) {
14167
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
14167
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
14168
14168
  }
14169
14169
  step((generator = generator.apply(thisArg, _arguments || [])).next());
14170
14170
  });
@@ -14337,11 +14337,11 @@ var require_jsmsg = __commonJS((exports) => {
14337
14337
  var require_typedsub = __commonJS((exports) => {
14338
14338
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
14339
14339
  function adopt(value) {
14340
- return value instanceof P ? value : new P(function(resolve2) {
14341
- resolve2(value);
14340
+ return value instanceof P ? value : new P(function(resolve3) {
14341
+ resolve3(value);
14342
14342
  });
14343
14343
  }
14344
- return new (P || (P = Promise))(function(resolve2, reject) {
14344
+ return new (P || (P = Promise))(function(resolve3, reject) {
14345
14345
  function fulfilled(value) {
14346
14346
  try {
14347
14347
  step(generator.next(value));
@@ -14357,7 +14357,7 @@ var require_typedsub = __commonJS((exports) => {
14357
14357
  }
14358
14358
  }
14359
14359
  function step(result) {
14360
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
14360
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
14361
14361
  }
14362
14362
  step((generator = generator.apply(thisArg, _arguments || [])).next());
14363
14363
  });
@@ -15080,11 +15080,11 @@ var require_sha_digest_parser = __commonJS((exports) => {
15080
15080
  var require_objectstore = __commonJS((exports) => {
15081
15081
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
15082
15082
  function adopt(value) {
15083
- return value instanceof P ? value : new P(function(resolve2) {
15084
- resolve2(value);
15083
+ return value instanceof P ? value : new P(function(resolve3) {
15084
+ resolve3(value);
15085
15085
  });
15086
15086
  }
15087
- return new (P || (P = Promise))(function(resolve2, reject) {
15087
+ return new (P || (P = Promise))(function(resolve3, reject) {
15088
15088
  function fulfilled(value) {
15089
15089
  try {
15090
15090
  step(generator.next(value));
@@ -15100,7 +15100,7 @@ var require_objectstore = __commonJS((exports) => {
15100
15100
  }
15101
15101
  }
15102
15102
  function step(result) {
15103
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
15103
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
15104
15104
  }
15105
15105
  step((generator = generator.apply(thisArg, _arguments || [])).next());
15106
15106
  });
@@ -15114,14 +15114,14 @@ var require_objectstore = __commonJS((exports) => {
15114
15114
  }, i);
15115
15115
  function verb(n) {
15116
15116
  i[n] = o[n] && function(v) {
15117
- return new Promise(function(resolve2, reject) {
15118
- v = o[n](v), settle(resolve2, reject, v.done, v.value);
15117
+ return new Promise(function(resolve3, reject) {
15118
+ v = o[n](v), settle(resolve3, reject, v.done, v.value);
15119
15119
  });
15120
15120
  };
15121
15121
  }
15122
- function settle(resolve2, reject, d, v) {
15122
+ function settle(resolve3, reject, d, v) {
15123
15123
  Promise.resolve(v).then(function(v2) {
15124
- resolve2({ value: v2, done: d });
15124
+ resolve3({ value: v2, done: d });
15125
15125
  }, reject);
15126
15126
  }
15127
15127
  };
@@ -15888,11 +15888,11 @@ var require_idleheartbeat_monitor = __commonJS((exports) => {
15888
15888
  var require_jsclient = __commonJS((exports) => {
15889
15889
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
15890
15890
  function adopt(value) {
15891
- return value instanceof P ? value : new P(function(resolve2) {
15892
- resolve2(value);
15891
+ return value instanceof P ? value : new P(function(resolve3) {
15892
+ resolve3(value);
15893
15893
  });
15894
15894
  }
15895
- return new (P || (P = Promise))(function(resolve2, reject) {
15895
+ return new (P || (P = Promise))(function(resolve3, reject) {
15896
15896
  function fulfilled(value) {
15897
15897
  try {
15898
15898
  step(generator.next(value));
@@ -15908,7 +15908,7 @@ var require_jsclient = __commonJS((exports) => {
15908
15908
  }
15909
15909
  }
15910
15910
  function step(result) {
15911
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
15911
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
15912
15912
  }
15913
15913
  step((generator = generator.apply(thisArg, _arguments || [])).next());
15914
15914
  });
@@ -16632,11 +16632,11 @@ var require_jsclient = __commonJS((exports) => {
16632
16632
  var require_kv = __commonJS((exports) => {
16633
16633
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
16634
16634
  function adopt(value) {
16635
- return value instanceof P ? value : new P(function(resolve2) {
16636
- resolve2(value);
16635
+ return value instanceof P ? value : new P(function(resolve3) {
16636
+ resolve3(value);
16637
16637
  });
16638
16638
  }
16639
- return new (P || (P = Promise))(function(resolve2, reject) {
16639
+ return new (P || (P = Promise))(function(resolve3, reject) {
16640
16640
  function fulfilled(value) {
16641
16641
  try {
16642
16642
  step(generator.next(value));
@@ -16652,7 +16652,7 @@ var require_kv = __commonJS((exports) => {
16652
16652
  }
16653
16653
  }
16654
16654
  function step(result) {
16655
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
16655
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
16656
16656
  }
16657
16657
  step((generator = generator.apply(thisArg, _arguments || [])).next());
16658
16658
  });
@@ -16666,14 +16666,14 @@ var require_kv = __commonJS((exports) => {
16666
16666
  }, i);
16667
16667
  function verb(n) {
16668
16668
  i[n] = o[n] && function(v) {
16669
- return new Promise(function(resolve2, reject) {
16670
- v = o[n](v), settle(resolve2, reject, v.done, v.value);
16669
+ return new Promise(function(resolve3, reject) {
16670
+ v = o[n](v), settle(resolve3, reject, v.done, v.value);
16671
16671
  });
16672
16672
  };
16673
16673
  }
16674
- function settle(resolve2, reject, d, v) {
16674
+ function settle(resolve3, reject, d, v) {
16675
16675
  Promise.resolve(v).then(function(v2) {
16676
- resolve2({ value: v2, done: d });
16676
+ resolve3({ value: v2, done: d });
16677
16677
  }, reject);
16678
16678
  }
16679
16679
  };
@@ -17614,11 +17614,11 @@ var require_kv = __commonJS((exports) => {
17614
17614
  var require_consumer = __commonJS((exports) => {
17615
17615
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
17616
17616
  function adopt(value) {
17617
- return value instanceof P ? value : new P(function(resolve2) {
17618
- resolve2(value);
17617
+ return value instanceof P ? value : new P(function(resolve3) {
17618
+ resolve3(value);
17619
17619
  });
17620
17620
  }
17621
- return new (P || (P = Promise))(function(resolve2, reject) {
17621
+ return new (P || (P = Promise))(function(resolve3, reject) {
17622
17622
  function fulfilled(value) {
17623
17623
  try {
17624
17624
  step(generator.next(value));
@@ -17634,7 +17634,7 @@ var require_consumer = __commonJS((exports) => {
17634
17634
  }
17635
17635
  }
17636
17636
  function step(result) {
17637
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
17637
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
17638
17638
  }
17639
17639
  step((generator = generator.apply(thisArg, _arguments || [])).next());
17640
17640
  });
@@ -17648,14 +17648,14 @@ var require_consumer = __commonJS((exports) => {
17648
17648
  }, i);
17649
17649
  function verb(n) {
17650
17650
  i[n] = o[n] && function(v) {
17651
- return new Promise(function(resolve2, reject) {
17652
- v = o[n](v), settle(resolve2, reject, v.done, v.value);
17651
+ return new Promise(function(resolve3, reject) {
17652
+ v = o[n](v), settle(resolve3, reject, v.done, v.value);
17653
17653
  });
17654
17654
  };
17655
17655
  }
17656
- function settle(resolve2, reject, d, v) {
17656
+ function settle(resolve3, reject, d, v) {
17657
17657
  Promise.resolve(v).then(function(v2) {
17658
- resolve2({ value: v2, done: d });
17658
+ resolve3({ value: v2, done: d });
17659
17659
  }, reject);
17660
17660
  }
17661
17661
  };
@@ -18507,11 +18507,11 @@ var require_consumer = __commonJS((exports) => {
18507
18507
  var require_jsmstream_api = __commonJS((exports) => {
18508
18508
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
18509
18509
  function adopt(value) {
18510
- return value instanceof P ? value : new P(function(resolve2) {
18511
- resolve2(value);
18510
+ return value instanceof P ? value : new P(function(resolve3) {
18511
+ resolve3(value);
18512
18512
  });
18513
18513
  }
18514
- return new (P || (P = Promise))(function(resolve2, reject) {
18514
+ return new (P || (P = Promise))(function(resolve3, reject) {
18515
18515
  function fulfilled(value) {
18516
18516
  try {
18517
18517
  step(generator.next(value));
@@ -18527,7 +18527,7 @@ var require_jsmstream_api = __commonJS((exports) => {
18527
18527
  }
18528
18528
  }
18529
18529
  function step(result) {
18530
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
18530
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
18531
18531
  }
18532
18532
  step((generator = generator.apply(thisArg, _arguments || [])).next());
18533
18533
  });
@@ -18978,11 +18978,11 @@ var require_jsmstream_api = __commonJS((exports) => {
18978
18978
  var require_jsm = __commonJS((exports) => {
18979
18979
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
18980
18980
  function adopt(value) {
18981
- return value instanceof P ? value : new P(function(resolve2) {
18982
- resolve2(value);
18981
+ return value instanceof P ? value : new P(function(resolve3) {
18982
+ resolve3(value);
18983
18983
  });
18984
18984
  }
18985
- return new (P || (P = Promise))(function(resolve2, reject) {
18985
+ return new (P || (P = Promise))(function(resolve3, reject) {
18986
18986
  function fulfilled(value) {
18987
18987
  try {
18988
18988
  step(generator.next(value));
@@ -18998,7 +18998,7 @@ var require_jsm = __commonJS((exports) => {
18998
18998
  }
18999
18999
  }
19000
19000
  function step(result) {
19001
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
19001
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
19002
19002
  }
19003
19003
  step((generator = generator.apply(thisArg, _arguments || [])).next());
19004
19004
  });
@@ -19012,14 +19012,14 @@ var require_jsm = __commonJS((exports) => {
19012
19012
  }, i);
19013
19013
  function verb(n) {
19014
19014
  i[n] = o[n] && function(v) {
19015
- return new Promise(function(resolve2, reject) {
19016
- v = o[n](v), settle(resolve2, reject, v.done, v.value);
19015
+ return new Promise(function(resolve3, reject) {
19016
+ v = o[n](v), settle(resolve3, reject, v.done, v.value);
19017
19017
  });
19018
19018
  };
19019
19019
  }
19020
- function settle(resolve2, reject, d, v) {
19020
+ function settle(resolve3, reject, d, v) {
19021
19021
  Promise.resolve(v).then(function(v2) {
19022
- resolve2({ value: v2, done: d });
19022
+ resolve3({ value: v2, done: d });
19023
19023
  }, reject);
19024
19024
  }
19025
19025
  };
@@ -19209,11 +19209,11 @@ var require_jsm = __commonJS((exports) => {
19209
19209
  var require_service = __commonJS((exports) => {
19210
19210
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
19211
19211
  function adopt(value) {
19212
- return value instanceof P ? value : new P(function(resolve2) {
19213
- resolve2(value);
19212
+ return value instanceof P ? value : new P(function(resolve3) {
19213
+ resolve3(value);
19214
19214
  });
19215
19215
  }
19216
- return new (P || (P = Promise))(function(resolve2, reject) {
19216
+ return new (P || (P = Promise))(function(resolve3, reject) {
19217
19217
  function fulfilled(value) {
19218
19218
  try {
19219
19219
  step(generator.next(value));
@@ -19229,7 +19229,7 @@ var require_service = __commonJS((exports) => {
19229
19229
  }
19230
19230
  }
19231
19231
  function step(result) {
19232
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
19232
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
19233
19233
  }
19234
19234
  step((generator = generator.apply(thisArg, _arguments || [])).next());
19235
19235
  });
@@ -19697,11 +19697,11 @@ var require_service = __commonJS((exports) => {
19697
19697
  var require_serviceclient = __commonJS((exports) => {
19698
19698
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
19699
19699
  function adopt(value) {
19700
- return value instanceof P ? value : new P(function(resolve2) {
19701
- resolve2(value);
19700
+ return value instanceof P ? value : new P(function(resolve3) {
19701
+ resolve3(value);
19702
19702
  });
19703
19703
  }
19704
- return new (P || (P = Promise))(function(resolve2, reject) {
19704
+ return new (P || (P = Promise))(function(resolve3, reject) {
19705
19705
  function fulfilled(value) {
19706
19706
  try {
19707
19707
  step(generator.next(value));
@@ -19717,7 +19717,7 @@ var require_serviceclient = __commonJS((exports) => {
19717
19717
  }
19718
19718
  }
19719
19719
  function step(result) {
19720
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
19720
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
19721
19721
  }
19722
19722
  step((generator = generator.apply(thisArg, _arguments || [])).next());
19723
19723
  });
@@ -19731,14 +19731,14 @@ var require_serviceclient = __commonJS((exports) => {
19731
19731
  }, i);
19732
19732
  function verb(n) {
19733
19733
  i[n] = o[n] && function(v) {
19734
- return new Promise(function(resolve2, reject) {
19735
- v = o[n](v), settle(resolve2, reject, v.done, v.value);
19734
+ return new Promise(function(resolve3, reject) {
19735
+ v = o[n](v), settle(resolve3, reject, v.done, v.value);
19736
19736
  });
19737
19737
  };
19738
19738
  }
19739
- function settle(resolve2, reject, d, v) {
19739
+ function settle(resolve3, reject, d, v) {
19740
19740
  Promise.resolve(v).then(function(v2) {
19741
- resolve2({ value: v2, done: d });
19741
+ resolve3({ value: v2, done: d });
19742
19742
  }, reject);
19743
19743
  }
19744
19744
  };
@@ -19819,11 +19819,11 @@ var require_serviceclient = __commonJS((exports) => {
19819
19819
  var require_nats = __commonJS((exports) => {
19820
19820
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
19821
19821
  function adopt(value) {
19822
- return value instanceof P ? value : new P(function(resolve2) {
19823
- resolve2(value);
19822
+ return value instanceof P ? value : new P(function(resolve3) {
19823
+ resolve3(value);
19824
19824
  });
19825
19825
  }
19826
- return new (P || (P = Promise))(function(resolve2, reject) {
19826
+ return new (P || (P = Promise))(function(resolve3, reject) {
19827
19827
  function fulfilled(value) {
19828
19828
  try {
19829
19829
  step(generator.next(value));
@@ -19839,7 +19839,7 @@ var require_nats = __commonJS((exports) => {
19839
19839
  }
19840
19840
  }
19841
19841
  function step(result) {
19842
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
19842
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
19843
19843
  }
19844
19844
  step((generator = generator.apply(thisArg, _arguments || [])).next());
19845
19845
  });
@@ -19853,14 +19853,14 @@ var require_nats = __commonJS((exports) => {
19853
19853
  }, i);
19854
19854
  function verb(n) {
19855
19855
  i[n] = o[n] && function(v) {
19856
- return new Promise(function(resolve2, reject) {
19857
- v = o[n](v), settle(resolve2, reject, v.done, v.value);
19856
+ return new Promise(function(resolve3, reject) {
19857
+ v = o[n](v), settle(resolve3, reject, v.done, v.value);
19858
19858
  });
19859
19859
  };
19860
19860
  }
19861
- function settle(resolve2, reject, d, v) {
19861
+ function settle(resolve3, reject, d, v) {
19862
19862
  Promise.resolve(v).then(function(v2) {
19863
- resolve2({ value: v2, done: d });
19863
+ resolve3({ value: v2, done: d });
19864
19864
  }, reject);
19865
19865
  }
19866
19866
  };
@@ -19888,7 +19888,7 @@ var require_nats = __commonJS((exports) => {
19888
19888
  this.listeners = [];
19889
19889
  }
19890
19890
  static connect(opts = {}) {
19891
- return new Promise((resolve2, reject) => {
19891
+ return new Promise((resolve3, reject) => {
19892
19892
  const nc = new NatsConnectionImpl(opts);
19893
19893
  protocol_1.ProtocolHandler.connect(nc.options, nc).then((ph) => {
19894
19894
  nc.protocol = ph;
@@ -19917,7 +19917,7 @@ var require_nats = __commonJS((exports) => {
19917
19917
  }
19918
19918
  });
19919
19919
  })();
19920
- resolve2(nc);
19920
+ resolve3(nc);
19921
19921
  }).catch((err) => {
19922
19922
  reject(err);
19923
19923
  });
@@ -20308,11 +20308,11 @@ ${errCtx.stack}`;
20308
20308
  var require_bench = __commonJS((exports) => {
20309
20309
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
20310
20310
  function adopt(value) {
20311
- return value instanceof P ? value : new P(function(resolve2) {
20312
- resolve2(value);
20311
+ return value instanceof P ? value : new P(function(resolve3) {
20312
+ resolve3(value);
20313
20313
  });
20314
20314
  }
20315
- return new (P || (P = Promise))(function(resolve2, reject) {
20315
+ return new (P || (P = Promise))(function(resolve3, reject) {
20316
20316
  function fulfilled(value) {
20317
20317
  try {
20318
20318
  step(generator.next(value));
@@ -20328,7 +20328,7 @@ var require_bench = __commonJS((exports) => {
20328
20328
  }
20329
20329
  }
20330
20330
  function step(result) {
20331
- result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected);
20331
+ result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
20332
20332
  }
20333
20333
  step((generator = generator.apply(thisArg, _arguments || [])).next());
20334
20334
  });
@@ -20342,14 +20342,14 @@ var require_bench = __commonJS((exports) => {
20342
20342
  }, i);
20343
20343
  function verb(n) {
20344
20344
  i[n] = o[n] && function(v) {
20345
- return new Promise(function(resolve2, reject) {
20346
- v = o[n](v), settle(resolve2, reject, v.done, v.value);
20345
+ return new Promise(function(resolve3, reject) {
20346
+ v = o[n](v), settle(resolve3, reject, v.done, v.value);
20347
20347
  });
20348
20348
  };
20349
20349
  }
20350
- function settle(resolve2, reject, d, v) {
20350
+ function settle(resolve3, reject, d, v) {
20351
20351
  Promise.resolve(v).then(function(v2) {
20352
- resolve2({ value: v2, done: d });
20352
+ resolve3({ value: v2, done: d });
20353
20353
  }, reject);
20354
20354
  }
20355
20355
  };
@@ -21100,11 +21100,11 @@ var require_nats_base_client = __commonJS((exports) => {
21100
21100
  var require_node_transport = __commonJS((exports) => {
21101
21101
  var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
21102
21102
  function adopt(value) {
21103
- return value instanceof P ? value : new P(function(resolve3) {
21104
- resolve3(value);
21103
+ return value instanceof P ? value : new P(function(resolve4) {
21104
+ resolve4(value);
21105
21105
  });
21106
21106
  }
21107
- return new (P || (P = Promise))(function(resolve3, reject) {
21107
+ return new (P || (P = Promise))(function(resolve4, reject) {
21108
21108
  function fulfilled(value) {
21109
21109
  try {
21110
21110
  step(generator.next(value));
@@ -21120,7 +21120,7 @@ var require_node_transport = __commonJS((exports) => {
21120
21120
  }
21121
21121
  }
21122
21122
  function step(result) {
21123
- result.done ? resolve3(result.value) : adopt(result.value).then(fulfilled, rejected);
21123
+ result.done ? resolve4(result.value) : adopt(result.value).then(fulfilled, rejected);
21124
21124
  }
21125
21125
  step((generator = generator.apply(thisArg, _arguments || [])).next());
21126
21126
  });
@@ -21179,8 +21179,8 @@ var require_node_transport = __commonJS((exports) => {
21179
21179
  var net_1 = __require("net");
21180
21180
  var util_1 = require_util();
21181
21181
  var tls_1 = __require("tls");
21182
- var { resolve: resolve2 } = __require("path");
21183
- var { readFile: readFile2, existsSync: existsSync6 } = __require("fs");
21182
+ var { resolve: resolve3 } = __require("path");
21183
+ var { readFile: readFile2, existsSync: existsSync7 } = __require("fs");
21184
21184
  var dns = __require("dns");
21185
21185
  var VERSION2 = "2.29.3";
21186
21186
  var LANG = "nats.js";
@@ -21295,8 +21295,8 @@ var require_node_transport = __commonJS((exports) => {
21295
21295
  }
21296
21296
  const d = (0, nats_base_client_1.deferred)();
21297
21297
  try {
21298
- fn = resolve2(fn);
21299
- if (!existsSync6(fn)) {
21298
+ fn = resolve3(fn);
21299
+ if (!existsSync7(fn)) {
21300
21300
  d.reject(new Error(`${fn} doesn't exist`));
21301
21301
  }
21302
21302
  readFile2(fn, (err, data2) => {
@@ -23511,7 +23511,7 @@ var require_pushgateway = __commonJS((exports, module) => {
23511
23511
  const options = Object.assign(requestParams, this.requestOptions, {
23512
23512
  method
23513
23513
  });
23514
- return new Promise((resolve2, reject) => {
23514
+ return new Promise((resolve3, reject) => {
23515
23515
  if (method === "DELETE" && options.headers) {
23516
23516
  delete options.headers["Content-Encoding"];
23517
23517
  }
@@ -23525,7 +23525,7 @@ var require_pushgateway = __commonJS((exports, module) => {
23525
23525
  if (resp.statusCode >= 400) {
23526
23526
  reject(new Error(`push failed with status ${resp.statusCode}, ${body}`));
23527
23527
  } else {
23528
- resolve2({ resp, body });
23528
+ resolve3({ resp, body });
23529
23529
  }
23530
23530
  });
23531
23531
  });
@@ -25829,7 +25829,7 @@ var require_cluster = __commonJS((exports, module) => {
25829
25829
  }
25830
25830
  clusterMetrics() {
25831
25831
  const requestId = requestCtr++;
25832
- return new Promise((resolve2, reject) => {
25832
+ return new Promise((resolve3, reject) => {
25833
25833
  let settled = false;
25834
25834
  function done(err, result) {
25835
25835
  if (settled)
@@ -25838,7 +25838,7 @@ var require_cluster = __commonJS((exports, module) => {
25838
25838
  if (err)
25839
25839
  reject(err);
25840
25840
  else
25841
- resolve2(result);
25841
+ resolve3(result);
25842
25842
  }
25843
25843
  const request = {
25844
25844
  responses: [],
@@ -28542,8 +28542,8 @@ var require_promise = __commonJS((exports) => {
28542
28542
  _resolve;
28543
28543
  _reject;
28544
28544
  constructor() {
28545
- this._promise = new Promise((resolve3, reject) => {
28546
- this._resolve = resolve3;
28545
+ this._promise = new Promise((resolve4, reject) => {
28546
+ this._resolve = resolve4;
28547
28547
  this._reject = reject;
28548
28548
  });
28549
28549
  }
@@ -28631,10 +28631,10 @@ var require_exporter = __commonJS((exports) => {
28631
28631
  var api_1 = require_src();
28632
28632
  var suppress_tracing_1 = require_suppress_tracing();
28633
28633
  function _export(exporter, arg) {
28634
- return new Promise((resolve3) => {
28634
+ return new Promise((resolve4) => {
28635
28635
  api_1.context.with((0, suppress_tracing_1.suppressTracing)(api_1.context.active()), () => {
28636
28636
  exporter.export(arg, (result) => {
28637
- resolve3(result);
28637
+ resolve4(result);
28638
28638
  });
28639
28639
  });
28640
28640
  });
@@ -30879,8 +30879,8 @@ var require_import_in_the_middle = __commonJS((exports, module) => {
30879
30879
  }).unref();
30880
30880
  function waitForAllMessagesAcknowledged() {
30881
30881
  const timer = setInterval(() => {}, 1000);
30882
- const promise = new Promise((resolve3) => {
30883
- resolveFn = resolve3;
30882
+ const promise = new Promise((resolve4) => {
30883
+ resolveFn = resolve4;
30884
30884
  }).then(() => {
30885
30885
  clearInterval(timer);
30886
30886
  });
@@ -33508,7 +33508,7 @@ var require_string = __commonJS((exports) => {
33508
33508
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
33509
33509
  var is = require_is();
33510
33510
  var stacktrace = require_stacktrace();
33511
- function truncate3(str, max = 0) {
33511
+ function truncate4(str, max = 0) {
33512
33512
  if (typeof str !== "string" || max === 0) {
33513
33513
  return str;
33514
33514
  }
@@ -33581,7 +33581,7 @@ var require_string = __commonJS((exports) => {
33581
33581
  exports.safeJoin = safeJoin;
33582
33582
  exports.snipLine = snipLine;
33583
33583
  exports.stringMatchesSomePattern = stringMatchesSomePattern;
33584
- exports.truncate = truncate3;
33584
+ exports.truncate = truncate4;
33585
33585
  });
33586
33586
 
33587
33587
  // ../../node_modules/.bun/@sentry+core@10.43.0/node_modules/@sentry/core/build/cjs/utils/misc.js
@@ -36769,8 +36769,8 @@ var require_syncpromise = __commonJS((exports) => {
36769
36769
  var STATE_RESOLVED = 1;
36770
36770
  var STATE_REJECTED = 2;
36771
36771
  function resolvedSyncPromise(value) {
36772
- return new SyncPromise((resolve3) => {
36773
- resolve3(value);
36772
+ return new SyncPromise((resolve4) => {
36773
+ resolve4(value);
36774
36774
  });
36775
36775
  }
36776
36776
  function rejectedSyncPromise(reason) {
@@ -36786,15 +36786,15 @@ var require_syncpromise = __commonJS((exports) => {
36786
36786
  this._runExecutor(executor);
36787
36787
  }
36788
36788
  then(onfulfilled, onrejected) {
36789
- return new SyncPromise((resolve3, reject) => {
36789
+ return new SyncPromise((resolve4, reject) => {
36790
36790
  this._handlers.push([
36791
36791
  false,
36792
36792
  (result) => {
36793
36793
  if (!onfulfilled) {
36794
- resolve3(result);
36794
+ resolve4(result);
36795
36795
  } else {
36796
36796
  try {
36797
- resolve3(onfulfilled(result));
36797
+ resolve4(onfulfilled(result));
36798
36798
  } catch (e) {
36799
36799
  reject(e);
36800
36800
  }
@@ -36805,7 +36805,7 @@ var require_syncpromise = __commonJS((exports) => {
36805
36805
  reject(reason);
36806
36806
  } else {
36807
36807
  try {
36808
- resolve3(onrejected(reason));
36808
+ resolve4(onrejected(reason));
36809
36809
  } catch (e) {
36810
36810
  reject(e);
36811
36811
  }
@@ -36819,7 +36819,7 @@ var require_syncpromise = __commonJS((exports) => {
36819
36819
  return this.then((val) => val, onrejected);
36820
36820
  }
36821
36821
  finally(onfinally) {
36822
- return new SyncPromise((resolve3, reject) => {
36822
+ return new SyncPromise((resolve4, reject) => {
36823
36823
  let val;
36824
36824
  let isRejected;
36825
36825
  return this.then((value) => {
@@ -36839,7 +36839,7 @@ var require_syncpromise = __commonJS((exports) => {
36839
36839
  reject(val);
36840
36840
  return;
36841
36841
  }
36842
- resolve3(val);
36842
+ resolve4(val);
36843
36843
  });
36844
36844
  });
36845
36845
  }
@@ -36868,21 +36868,21 @@ var require_syncpromise = __commonJS((exports) => {
36868
36868
  return;
36869
36869
  }
36870
36870
  if (is.isThenable(value)) {
36871
- value.then(resolve3, reject);
36871
+ value.then(resolve4, reject);
36872
36872
  return;
36873
36873
  }
36874
36874
  this._state = state;
36875
36875
  this._value = value;
36876
36876
  this._executeHandlers();
36877
36877
  };
36878
- const resolve3 = (value) => {
36878
+ const resolve4 = (value) => {
36879
36879
  setResult(STATE_RESOLVED, value);
36880
36880
  };
36881
36881
  const reject = (reason) => {
36882
36882
  setResult(STATE_REJECTED, reason);
36883
36883
  };
36884
36884
  try {
36885
- executor(resolve3, reject);
36885
+ executor(resolve4, reject);
36886
36886
  } catch (e) {
36887
36887
  reject(e);
36888
36888
  }
@@ -38133,7 +38133,7 @@ var require_promisebuffer = __commonJS((exports) => {
38133
38133
  }
38134
38134
  const promises = [
38135
38135
  drainPromise,
38136
- new Promise((resolve3) => timer.safeUnref(setTimeout(() => resolve3(false), timeout)))
38136
+ new Promise((resolve4) => timer.safeUnref(setTimeout(() => resolve4(false), timeout)))
38137
38137
  ];
38138
38138
  return Promise.race(promises);
38139
38139
  }
@@ -38675,7 +38675,7 @@ var require_client = __commonJS((exports) => {
38675
38675
  async _isClientDoneProcessing(timeout) {
38676
38676
  let ticked = 0;
38677
38677
  while (!timeout || ticked < timeout) {
38678
- await new Promise((resolve3) => setTimeout(resolve3, 1));
38678
+ await new Promise((resolve4) => setTimeout(resolve4, 1));
38679
38679
  if (!this._numProcessing) {
38680
38680
  return true;
38681
38681
  }
@@ -41092,7 +41092,7 @@ var require_path = __commonJS((exports) => {
41092
41092
  const parts = splitPathRe.exec(truncated);
41093
41093
  return parts ? parts.slice(1) : [];
41094
41094
  }
41095
- function resolve3(...args) {
41095
+ function resolve4(...args) {
41096
41096
  let resolvedPath = "";
41097
41097
  let resolvedAbsolute = false;
41098
41098
  for (let i = args.length - 1;i >= -1 && !resolvedAbsolute; i--) {
@@ -41125,8 +41125,8 @@ var require_path = __commonJS((exports) => {
41125
41125
  return arr.slice(start, end - start + 1);
41126
41126
  }
41127
41127
  function relative(from, to) {
41128
- from = resolve3(from).slice(1);
41129
- to = resolve3(to).slice(1);
41128
+ from = resolve4(from).slice(1);
41129
+ to = resolve4(to).slice(1);
41130
41130
  const fromParts = trim(from.split("/"));
41131
41131
  const toParts = trim(to.split("/"));
41132
41132
  const length = Math.min(fromParts.length, toParts.length);
@@ -41159,7 +41159,7 @@ var require_path = __commonJS((exports) => {
41159
41159
  function isAbsolute(path) {
41160
41160
  return path.charAt(0) === "/";
41161
41161
  }
41162
- function join9(...args) {
41162
+ function join10(...args) {
41163
41163
  return normalizePath(args.join("/"));
41164
41164
  }
41165
41165
  function dirname6(path) {
@@ -41184,10 +41184,10 @@ var require_path = __commonJS((exports) => {
41184
41184
  exports.basename = basename6;
41185
41185
  exports.dirname = dirname6;
41186
41186
  exports.isAbsolute = isAbsolute;
41187
- exports.join = join9;
41187
+ exports.join = join10;
41188
41188
  exports.normalizePath = normalizePath;
41189
41189
  exports.relative = relative;
41190
- exports.resolve = resolve3;
41190
+ exports.resolve = resolve4;
41191
41191
  });
41192
41192
 
41193
41193
  // ../../node_modules/.bun/@sentry+core@10.43.0/node_modules/@sentry/core/build/cjs/integrations/rewriteframes.js
@@ -49627,8 +49627,8 @@ var require_promise2 = __commonJS((exports) => {
49627
49627
  _resolve;
49628
49628
  _reject;
49629
49629
  constructor() {
49630
- this._promise = new Promise((resolve3, reject) => {
49631
- this._resolve = resolve3;
49630
+ this._promise = new Promise((resolve4, reject) => {
49631
+ this._resolve = resolve4;
49632
49632
  this._reject = reject;
49633
49633
  });
49634
49634
  }
@@ -49716,9 +49716,9 @@ var require_exporter2 = __commonJS((exports) => {
49716
49716
  var api_1 = require_src();
49717
49717
  var suppress_tracing_1 = require_suppress_tracing2();
49718
49718
  function _export(exporter, arg) {
49719
- return new Promise((resolve3) => {
49719
+ return new Promise((resolve4) => {
49720
49720
  api_1.context.with((0, suppress_tracing_1.suppressTracing)(api_1.context.active()), () => {
49721
- exporter.export(arg, resolve3);
49721
+ exporter.export(arg, resolve4);
49722
49722
  });
49723
49723
  });
49724
49724
  }
@@ -52199,14 +52199,14 @@ var require_BatchSpanProcessorBase = __commonJS((exports) => {
52199
52199
  this._maybeStartTimer();
52200
52200
  }
52201
52201
  _flushAll() {
52202
- return new Promise((resolve3, reject) => {
52202
+ return new Promise((resolve4, reject) => {
52203
52203
  const promises = [];
52204
52204
  const count = Math.ceil(this._finishedSpans.length / this._maxExportBatchSize);
52205
52205
  for (let i = 0, j = count;i < j; i++) {
52206
52206
  promises.push(this._flushOneBatch());
52207
52207
  }
52208
52208
  Promise.all(promises).then(() => {
52209
- resolve3();
52209
+ resolve4();
52210
52210
  }).catch(reject);
52211
52211
  });
52212
52212
  }
@@ -52215,7 +52215,7 @@ var require_BatchSpanProcessorBase = __commonJS((exports) => {
52215
52215
  if (this._finishedSpans.length === 0) {
52216
52216
  return Promise.resolve();
52217
52217
  }
52218
- return new Promise((resolve3, reject) => {
52218
+ return new Promise((resolve4, reject) => {
52219
52219
  const timer = setTimeout(() => {
52220
52220
  reject(new Error("Timeout"));
52221
52221
  }, this._exportTimeoutMillis);
@@ -52230,7 +52230,7 @@ var require_BatchSpanProcessorBase = __commonJS((exports) => {
52230
52230
  const doExport = () => this._exporter.export(spans, (result) => {
52231
52231
  clearTimeout(timer);
52232
52232
  if (result.code === core_1.ExportResultCode.SUCCESS) {
52233
- resolve3();
52233
+ resolve4();
52234
52234
  } else {
52235
52235
  reject(result.error ?? new Error("BatchSpanProcessor: span export failed"));
52236
52236
  }
@@ -52574,12 +52574,12 @@ var require_MultiSpanProcessor = __commonJS((exports) => {
52574
52574
  for (const spanProcessor of this._spanProcessors) {
52575
52575
  promises.push(spanProcessor.forceFlush());
52576
52576
  }
52577
- return new Promise((resolve3) => {
52577
+ return new Promise((resolve4) => {
52578
52578
  Promise.all(promises).then(() => {
52579
- resolve3();
52579
+ resolve4();
52580
52580
  }).catch((error2) => {
52581
52581
  (0, core_1.globalErrorHandler)(error2 || new Error("MultiSpanProcessor: forceFlush failed"));
52582
- resolve3();
52582
+ resolve4();
52583
52583
  });
52584
52584
  });
52585
52585
  }
@@ -52605,9 +52605,9 @@ var require_MultiSpanProcessor = __commonJS((exports) => {
52605
52605
  for (const spanProcessor of this._spanProcessors) {
52606
52606
  promises.push(spanProcessor.shutdown());
52607
52607
  }
52608
- return new Promise((resolve3, reject) => {
52608
+ return new Promise((resolve4, reject) => {
52609
52609
  Promise.all(promises).then(() => {
52610
- resolve3();
52610
+ resolve4();
52611
52611
  }, reject);
52612
52612
  });
52613
52613
  }
@@ -52660,32 +52660,32 @@ var require_BasicTracerProvider = __commonJS((exports) => {
52660
52660
  forceFlush() {
52661
52661
  const timeout = this._config.forceFlushTimeoutMillis;
52662
52662
  const promises = this._activeSpanProcessor["_spanProcessors"].map((spanProcessor) => {
52663
- return new Promise((resolve3) => {
52663
+ return new Promise((resolve4) => {
52664
52664
  let state;
52665
52665
  const timeoutInterval = setTimeout(() => {
52666
- resolve3(new Error(`Span processor did not completed within timeout period of ${timeout} ms`));
52666
+ resolve4(new Error(`Span processor did not completed within timeout period of ${timeout} ms`));
52667
52667
  state = ForceFlushState.timeout;
52668
52668
  }, timeout);
52669
52669
  spanProcessor.forceFlush().then(() => {
52670
52670
  clearTimeout(timeoutInterval);
52671
52671
  if (state !== ForceFlushState.timeout) {
52672
52672
  state = ForceFlushState.resolved;
52673
- resolve3(state);
52673
+ resolve4(state);
52674
52674
  }
52675
52675
  }).catch((error2) => {
52676
52676
  clearTimeout(timeoutInterval);
52677
52677
  state = ForceFlushState.error;
52678
- resolve3(error2);
52678
+ resolve4(error2);
52679
52679
  });
52680
52680
  });
52681
52681
  });
52682
- return new Promise((resolve3, reject) => {
52682
+ return new Promise((resolve4, reject) => {
52683
52683
  Promise.all(promises).then((results) => {
52684
52684
  const errors3 = results.filter((result) => result !== ForceFlushState.resolved);
52685
52685
  if (errors3.length > 0) {
52686
52686
  reject(errors3);
52687
52687
  } else {
52688
- resolve3();
52688
+ resolve4();
52689
52689
  }
52690
52690
  }).catch((error2) => reject([error2]));
52691
52691
  });
@@ -54543,13 +54543,13 @@ var require_context3 = __commonJS((exports) => {
54543
54543
  version: `10.${Number(os3.release().split(".")[0]) - 4}`
54544
54544
  };
54545
54545
  try {
54546
- const output = await new Promise((resolve3, reject) => {
54546
+ const output = await new Promise((resolve4, reject) => {
54547
54547
  node_child_process.execFile("/usr/bin/sw_vers", (error2, stdout) => {
54548
54548
  if (error2) {
54549
54549
  reject(error2);
54550
54550
  return;
54551
54551
  }
54552
- resolve3(stdout);
54552
+ resolve4(stdout);
54553
54553
  });
54554
54554
  });
54555
54555
  darwinInfo.name = matchFirst(/^ProductName:\s+(.*)$/m, output);
@@ -54726,14 +54726,14 @@ var require_contextlines = __commonJS((exports) => {
54726
54726
  return out;
54727
54727
  }
54728
54728
  function getContextLinesFromFile(path, ranges, output) {
54729
- return new Promise((resolve3, _reject) => {
54729
+ return new Promise((resolve4, _reject) => {
54730
54730
  const stream = node_fs.createReadStream(path);
54731
54731
  const lineReaded = node_readline.createInterface({
54732
54732
  input: stream
54733
54733
  });
54734
54734
  function destroyStreamAndResolve() {
54735
54735
  stream.destroy();
54736
- resolve3();
54736
+ resolve4();
54737
54737
  }
54738
54738
  let lineNumber = 0;
54739
54739
  let currentRangeIndex = 0;
@@ -55876,7 +55876,7 @@ var require_parse_proxy_response = __commonJS((exports) => {
55876
55876
  core.debug.log("[https-proxy-agent:parse-proxy-response]", ...args);
55877
55877
  }
55878
55878
  function parseProxyResponse(socket) {
55879
- return new Promise((resolve3, reject) => {
55879
+ return new Promise((resolve4, reject) => {
55880
55880
  let buffersLength = 0;
55881
55881
  const buffers = [];
55882
55882
  function read() {
@@ -55945,7 +55945,7 @@ var require_parse_proxy_response = __commonJS((exports) => {
55945
55945
  }
55946
55946
  debugLog("got proxy server response: %o %o", firstLine, headers);
55947
55947
  cleanup();
55948
- resolve3({
55948
+ resolve4({
55949
55949
  connect: {
55950
55950
  statusCode,
55951
55951
  statusText,
@@ -56121,7 +56121,7 @@ var require_http3 = __commonJS((exports) => {
56121
56121
  function createRequestExecutor(options3, httpModule, agent3) {
56122
56122
  const { hostname, pathname, port, protocol, search } = new URL(options3.url);
56123
56123
  return function makeRequest(request) {
56124
- return new Promise((resolve3, reject) => {
56124
+ return new Promise((resolve4, reject) => {
56125
56125
  core.suppressTracing(() => {
56126
56126
  let body = streamFromBody(request.body);
56127
56127
  const headers = { ...options3.headers };
@@ -56145,7 +56145,7 @@ var require_http3 = __commonJS((exports) => {
56145
56145
  res.setEncoding("utf8");
56146
56146
  const retryAfterHeader = res.headers["retry-after"] ?? null;
56147
56147
  const rateLimitsHeader = res.headers["x-sentry-rate-limits"] ?? null;
56148
- resolve3({
56148
+ resolve4({
56149
56149
  statusCode: res.statusCode,
56150
56150
  headers: {
56151
56151
  "retry-after": retryAfterHeader,
@@ -58261,7 +58261,7 @@ var require_instrumentation3 = __commonJS((exports) => {
58261
58261
  };
58262
58262
  const functionWithOriginalProperties = patchedFunctionWithOriginalProperties(patchedFunction, original);
58263
58263
  const promisified = function(path) {
58264
- return new Promise((resolve3) => functionWithOriginalProperties(path, resolve3));
58264
+ return new Promise((resolve4) => functionWithOriginalProperties(path, resolve4));
58265
58265
  };
58266
58266
  Object.defineProperty(promisified, "name", { value: functionName });
58267
58267
  Object.defineProperty(functionWithOriginalProperties, util_1.promisify.custom, {
@@ -67720,11 +67720,11 @@ var require_instrumentation17 = __commonJS((exports) => {
67720
67720
  }
67721
67721
  if (result instanceof Promise) {
67722
67722
  return result.then((result2) => {
67723
- return new Promise((resolve3) => {
67723
+ return new Promise((resolve4) => {
67724
67724
  utils.handleExecutionResult(plugin.getConfig(), span, result2);
67725
67725
  recordDuration();
67726
67726
  span.end();
67727
- resolve3(result2);
67727
+ resolve4(result2);
67728
67728
  });
67729
67729
  }).catch((error2) => {
67730
67730
  return new Promise((_2, reject) => {
@@ -71545,18 +71545,18 @@ var require_instrumentation25 = __commonJS((exports) => {
71545
71545
  return `00-${sc.traceId}-${sc.spanId}-0${Number(sc.traceFlags || api.TraceFlags.NONE).toString(16)}`;
71546
71546
  }
71547
71547
  _injectContextInfo(connection, tediousModule, traceparent) {
71548
- return new Promise((resolve3) => {
71548
+ return new Promise((resolve4) => {
71549
71549
  try {
71550
71550
  const sql = "set context_info @opentelemetry_traceparent";
71551
71551
  const req = new tediousModule.Request(sql, (_err) => {
71552
- resolve3();
71552
+ resolve4();
71553
71553
  });
71554
71554
  Object.defineProperty(req, exports.INJECTED_CTX, { value: true });
71555
71555
  const buf = Buffer.from(traceparent, "utf8");
71556
71556
  req.addParameter("opentelemetry_traceparent", tediousModule.TYPES.VarBinary, buf, { length: buf.length });
71557
71557
  connection.execSql(req);
71558
71558
  } catch {
71559
- resolve3();
71559
+ resolve4();
71560
71560
  }
71561
71561
  });
71562
71562
  }
@@ -76887,7 +76887,7 @@ import { fileURLToPath } from "url";
76887
76887
  // package.json
76888
76888
  var package_default = {
76889
76889
  name: "@automagik/omni",
76890
- version: "2.260405.2",
76890
+ version: "2.260406.1",
76891
76891
  description: "LLM-optimized CLI for Omni",
76892
76892
  type: "module",
76893
76893
  bin: {
@@ -77794,6 +77794,44 @@ function pm2NotFoundError() {
77794
77794
  Then retry: omni start`, undefined, 1);
77795
77795
  }
77796
77796
 
77797
+ // src/runtime-env.ts
77798
+ import { join as join3 } from "path";
77799
+ var LEGACY_DEFAULT_DATABASE_URL = "postgresql://postgres:postgres@localhost:5432/omni";
77800
+ var DEFAULT_PGSERVE_PORT = 8432;
77801
+ function buildEmbeddedDatabaseUrl(pgservePort = DEFAULT_PGSERVE_PORT) {
77802
+ return `postgresql://postgres:postgres@localhost:${pgservePort}/omni`;
77803
+ }
77804
+ function resolvePgservePort(serverConfig) {
77805
+ const maybe = serverConfig.pgservePort;
77806
+ if (typeof maybe === "number" && Number.isFinite(maybe) && maybe > 0) {
77807
+ return maybe;
77808
+ }
77809
+ return DEFAULT_PGSERVE_PORT;
77810
+ }
77811
+ function resolveDatabaseUrl(serverConfig) {
77812
+ const stored = serverConfig.databaseUrl?.trim() ?? "";
77813
+ if (stored && stored !== LEGACY_DEFAULT_DATABASE_URL) {
77814
+ return stored;
77815
+ }
77816
+ return buildEmbeddedDatabaseUrl(resolvePgservePort(serverConfig));
77817
+ }
77818
+ function buildRuntimeEnv(serverConfig, cliConfig) {
77819
+ const pgservePort = resolvePgservePort(serverConfig);
77820
+ return {
77821
+ API_PORT: String(serverConfig.port),
77822
+ DATABASE_URL: resolveDatabaseUrl(serverConfig),
77823
+ OMNI_API_KEY: cliConfig.apiKey ?? "",
77824
+ MEDIA_STORAGE_PATH: join3(serverConfig.dataDir, "media"),
77825
+ OMNI_PACKAGES_DIR: join3(serverConfig.dataDir, "packages"),
77826
+ PGSERVE_EMBEDDED: "true",
77827
+ PGSERVE_DATA: join3(serverConfig.dataDir, "pgserve"),
77828
+ PGSERVE_PORT: String(pgservePort),
77829
+ NATS_URL: "nats://localhost:4222",
77830
+ NODE_ENV: serverConfig.nodeEnv,
77831
+ LOG_LEVEL: serverConfig.logLevel
77832
+ };
77833
+ }
77834
+
77797
77835
  // src/utils/keys.ts
77798
77836
  function generateApiKey() {
77799
77837
  const bytes = new Uint8Array(16);
@@ -77844,8 +77882,11 @@ async function restartApiWithNewKey(newKey) {
77844
77882
  if (!proc) {
77845
77883
  continue;
77846
77884
  }
77885
+ const serverConfig = loadServerConfig();
77886
+ const cliConfig = loadConfig();
77887
+ const runtimeEnv = { ...buildRuntimeEnv(serverConfig, cliConfig), OMNI_API_KEY: newKey };
77847
77888
  await runPm2(["set", `${name}:OMNI_API_KEY`, newKey]);
77848
- const restartCode = await runPm2(["restart", name, "--update-env"], { OMNI_API_KEY: newKey });
77889
+ const restartCode = await runPm2(["restart", name], runtimeEnv);
77849
77890
  return { success: restartCode === 0, processName: name };
77850
77891
  }
77851
77892
  return { success: false, processName: null };
@@ -77880,9 +77921,9 @@ function printManualInstructions(newKey) {
77880
77921
  raw(` omni auth login --api-key ${key}`);
77881
77922
  raw("");
77882
77923
  raw(" 3. Or to rotate to a new key:");
77883
- raw(" a. Stop the API: pm2 stop omni-v2-api");
77924
+ raw(" a. Stop the API: omni stop");
77884
77925
  raw(" b. Delete primary key from DB manually");
77885
- raw(` c. Restart with: OMNI_API_KEY=${key} pm2 restart omni-v2-api --update-env`);
77926
+ raw(` c. Restart: OMNI_API_KEY=${key} omni start`);
77886
77927
  raw(` d. Login: omni auth login --api-key ${key}`);
77887
77928
  raw("");
77888
77929
  }
@@ -77953,8 +77994,9 @@ async function handleRotationSuccess(apiUrl, newKey, processName, apiUrlOverride
77953
77994
  warn("Config updated with new key, but validation failed.");
77954
77995
  raw("");
77955
77996
  raw(" The API may still be starting up, or the primary key was not deleted from DB.");
77956
- raw(" If the primary key row still exists in the database, delete it and restart:");
77957
- raw(` pm2 restart ${processName} --update-env`);
77997
+ raw(" If the primary key row still exists in the database, delete it and run:");
77998
+ raw(" omni restart");
77999
+ raw(" Or diagnose with: omni doctor --fix");
77958
78000
  raw(" Then verify with: omni status");
77959
78001
  raw("");
77960
78002
  console.log(` New key (save this): ${newKey}`);
@@ -79935,7 +79977,7 @@ async function findOrCreateAgent(client, agentName, providerId) {
79935
79977
  }
79936
79978
  }
79937
79979
  function createConnectCommand() {
79938
- return new Command("connect").description("Connect an Omni instance to a Genie agent via NATS").argument("<instance-id>", "Omni instance ID").argument("<agent-name>", "Genie agent name (from genie directory)").option("--nats-url <url>", "NATS server URL", "localhost:4222").action(async (instanceId, agentName, options) => {
79980
+ return new Command("connect").description("Connect an Omni instance to a Genie agent via NATS").argument("<instance-id>", "Omni instance ID").argument("<agent-name>", "Genie agent name (from genie directory)").option("--nats-url <url>", "NATS server URL", "localhost:4222").option("--mode <mode>", "Trigger mode: turn-based (round-trip) or fire-and-forget", "turn-based").option("--reply-filter <filter>", "Reply filter: all (reply to everything) or filtered", "all").action(async (instanceId, agentName, options) => {
79939
79981
  const client = getClient();
79940
79982
  info(`Discovering agent "${agentName}" from genie directory...`);
79941
79983
  let agentEntry;
@@ -79967,20 +80009,33 @@ Make sure genie is installed and the agent is registered:
79967
80009
  const agentId = await findOrCreateAgent(client, agentName, providerId);
79968
80010
  if (!agentId)
79969
80011
  return;
80012
+ const triggerMode = options.mode === "turn-based" ? "round-trip" : "fire-and-forget";
80013
+ const replyFilterMode = options.replyFilter;
80014
+ const agentReplyFilter = { mode: replyFilterMode, conditions: {} };
79970
80015
  info("Updating instance agent assignment...");
79971
80016
  try {
79972
- await client.instances.update(instanceId, { agentProviderId: providerId });
80017
+ await client.instances.update(instanceId, {
80018
+ agentId,
80019
+ agentProviderId: providerId,
80020
+ agentReplyFilter,
80021
+ triggerMode
80022
+ });
79973
80023
  } catch {
79974
80024
  warn("Could not update instance agent assignment automatically.");
79975
- info(`Set manually: omni instances update ${instanceId} --agent-provider-id ${providerId}`);
80025
+ info(`Set manually: omni instances update ${instanceId} --agent-id ${agentId} --agent-provider-id ${providerId}`);
80026
+ return;
79976
80027
  }
79977
- success(`Connected instance "${instanceId}" to genie agent "${agentName}".
79978
- NATS topics:
79979
- Inbound: omni.message.${instanceId}.*
79980
- Outbound: omni.reply.${instanceId}.*
79981
-
79982
- Next: Start the genie bridge:
79983
- genie omni start`);
80028
+ success(`Connected instance "${instanceId}" to genie agent "${agentName}".`);
80029
+ header("Configuration Summary");
80030
+ keyValue("Agent ID", agentId);
80031
+ keyValue("Provider ID", providerId);
80032
+ keyValue("Reply Filter", replyFilterMode);
80033
+ keyValue("Trigger Mode", `${triggerMode} (--mode ${options.mode})`);
80034
+ header("NATS Topics");
80035
+ keyValue("Inbound", `omni.message.${instanceId}.*`);
80036
+ keyValue("Outbound", `omni.reply.${instanceId}.*`);
80037
+ header("Next Step");
80038
+ info("Start the genie bridge: genie omni start");
79984
80039
  });
79985
80040
  }
79986
80041
 
@@ -80074,59 +80129,476 @@ function createDeadLettersCommand() {
80074
80129
  return deadLetters;
80075
80130
  }
80076
80131
 
80132
+ // src/commands/doctor.ts
80133
+ import { existsSync as existsSync3, readdirSync, statSync } from "fs";
80134
+ import { homedir as homedir2 } from "os";
80135
+ import { join as join5, resolve } from "path";
80136
+ init_config();
80137
+
80138
+ // src/health.ts
80139
+ var DEFAULT_API_PORT = 8882;
80140
+ var HEALTH_TIMEOUT_MS = 15000;
80141
+ var HEALTH_POLL_INTERVAL_MS = 500;
80142
+ function getHealthCheckUrl(port) {
80143
+ return `http://localhost:${port}/api/v2/health`;
80144
+ }
80145
+ async function waitForHealth(port, timeoutMs = HEALTH_TIMEOUT_MS) {
80146
+ const healthCheckUrl = getHealthCheckUrl(port);
80147
+ const deadline = Date.now() + timeoutMs;
80148
+ while (Date.now() < deadline) {
80149
+ try {
80150
+ const resp = await fetch(healthCheckUrl, { signal: AbortSignal.timeout(1000) });
80151
+ if (resp.ok)
80152
+ return true;
80153
+ } catch {}
80154
+ await Bun.sleep(HEALTH_POLL_INTERVAL_MS);
80155
+ }
80156
+ return false;
80157
+ }
80158
+
80159
+ // src/commands/doctor.ts
80160
+ init_output();
80161
+
80162
+ // src/server-bundle.ts
80163
+ init_output();
80164
+ import { dirname as dirname2, join as join4 } from "path";
80165
+ import { fileURLToPath as fileURLToPath2 } from "url";
80166
+ function getServerBundlePath() {
80167
+ try {
80168
+ const thisFile = fileURLToPath2(import.meta.url);
80169
+ const distDir = dirname2(thisFile);
80170
+ return join4(distDir, "server", "index.js");
80171
+ } catch {
80172
+ return join4(process.cwd(), "dist", "server", "index.js");
80173
+ }
80174
+ }
80175
+ function getServerLauncherPath() {
80176
+ try {
80177
+ const thisFile = fileURLToPath2(import.meta.url);
80178
+ const distDir = dirname2(thisFile);
80179
+ return join4(distDir, "..", "bin", "omni-server");
80180
+ } catch {
80181
+ return join4(process.cwd(), "bin", "omni-server");
80182
+ }
80183
+ }
80184
+ function bundleNotFoundError(bundlePath) {
80185
+ error(`Server bundle not found at: ${bundlePath}
80186
+ This command requires @automagik/omni installed from npm.
80187
+ Install: bun add -g @automagik/omni
80188
+ Or build locally: make cli-build-full`, undefined, 1);
80189
+ }
80190
+
80191
+ // src/commands/doctor.ts
80192
+ async function getPm2Processes2() {
80193
+ const { code, stdout } = await capturePm2("jlist");
80194
+ if (code !== 0 || !stdout.trim()) {
80195
+ return null;
80196
+ }
80197
+ try {
80198
+ return JSON.parse(stdout);
80199
+ } catch {
80200
+ return null;
80201
+ }
80202
+ }
80203
+ function readPm2EnvKey(entry, key) {
80204
+ if (!entry.pm2_env)
80205
+ return;
80206
+ const nested = entry.pm2_env.env?.[key];
80207
+ if (typeof nested === "string")
80208
+ return nested;
80209
+ const flat = entry.pm2_env[key];
80210
+ if (typeof flat === "string")
80211
+ return flat;
80212
+ return;
80213
+ }
80214
+ function productionDeps() {
80215
+ return {
80216
+ getPm2Processes: getPm2Processes2,
80217
+ canConnect: async (port) => {
80218
+ try {
80219
+ const socket = await Bun.connect({
80220
+ hostname: "127.0.0.1",
80221
+ port,
80222
+ socket: { data() {} }
80223
+ });
80224
+ socket.end();
80225
+ return true;
80226
+ } catch {
80227
+ return false;
80228
+ }
80229
+ },
80230
+ omniDbExists: async () => {
80231
+ try {
80232
+ const serverConfig = loadServerConfig();
80233
+ const resp = await fetch(getHealthCheckUrl(serverConfig.port), {
80234
+ signal: AbortSignal.timeout(1500),
80235
+ headers: { "Accept-Encoding": "identity" }
80236
+ });
80237
+ if (!resp.ok)
80238
+ return false;
80239
+ const body = await resp.json();
80240
+ return body?.checks?.database?.status === "ok";
80241
+ } catch {
80242
+ return false;
80243
+ }
80244
+ },
80245
+ findOrphanedDataDirs: () => {
80246
+ const roots = [process.cwd(), join5(homedir2(), "workspace"), join5(homedir2(), "repos")];
80247
+ const found = [];
80248
+ for (const root of roots) {
80249
+ if (!existsSync3(root))
80250
+ continue;
80251
+ try {
80252
+ scanForOrphans(root, found, 0);
80253
+ } catch {}
80254
+ }
80255
+ return found;
80256
+ },
80257
+ fetchHealthVersion: async (apiPort) => {
80258
+ try {
80259
+ const resp = await fetch(getHealthCheckUrl(apiPort), {
80260
+ signal: AbortSignal.timeout(1500),
80261
+ headers: { "Accept-Encoding": "identity" }
80262
+ });
80263
+ if (!resp.ok)
80264
+ return null;
80265
+ const body = await resp.json();
80266
+ return body.version ?? null;
80267
+ } catch {
80268
+ return null;
80269
+ }
80270
+ },
80271
+ validateStoredKey: async (apiPort) => {
80272
+ const cliConfig = loadConfig();
80273
+ if (!cliConfig.apiKey)
80274
+ return false;
80275
+ const baseUrl = cliConfig.apiUrl ?? `http://localhost:${apiPort}`;
80276
+ try {
80277
+ const client = createOmniClient({ baseUrl, apiKey: cliConfig.apiKey, cliVersion: VERSION });
80278
+ const result = await client.auth.validate();
80279
+ return result.valid === true;
80280
+ } catch {
80281
+ return false;
80282
+ }
80283
+ },
80284
+ loadState: () => ({
80285
+ serverConfig: loadServerConfig(),
80286
+ cliConfig: loadConfig()
80287
+ }),
80288
+ runPm2,
80289
+ saveCliConfig: saveConfig,
80290
+ reloadCliConfig: loadConfig,
80291
+ generateApiKey,
80292
+ sleepMs: (ms) => Bun.sleep(ms)
80293
+ };
80294
+ }
80295
+ function scanForOrphans(dir, acc, depth, maxDepth = 4) {
80296
+ if (depth > maxDepth)
80297
+ return;
80298
+ let entries;
80299
+ try {
80300
+ entries = readdirSync(dir);
80301
+ } catch {
80302
+ return;
80303
+ }
80304
+ for (const name of entries) {
80305
+ if (name === "node_modules" || name === ".git")
80306
+ continue;
80307
+ const full = join5(dir, name);
80308
+ let stats;
80309
+ try {
80310
+ stats = statSync(full);
80311
+ } catch {
80312
+ continue;
80313
+ }
80314
+ if (!stats.isDirectory())
80315
+ continue;
80316
+ if (name === ".pgserve-data") {
80317
+ acc.push(resolve(full));
80318
+ continue;
80319
+ }
80320
+ scanForOrphans(full, acc, depth + 1, maxDepth);
80321
+ }
80322
+ }
80323
+ async function checkPm2EnvDrift(deps) {
80324
+ const processes = await deps.getPm2Processes();
80325
+ if (!processes) {
80326
+ return { id: "pm2-env-drift", level: "WARN", detail: "pm2 not reachable \u2014 cannot compare env" };
80327
+ }
80328
+ const apiEntry = processes.find((p) => p.name === PM2_PROCESSES.api);
80329
+ if (!apiEntry) {
80330
+ return { id: "pm2-env-drift", level: "WARN", detail: `${PM2_PROCESSES.api} not found in pm2` };
80331
+ }
80332
+ const { serverConfig, cliConfig } = deps.loadState();
80333
+ const expected = buildRuntimeEnv(serverConfig, cliConfig);
80334
+ const storedDbUrl = readPm2EnvKey(apiEntry, "DATABASE_URL");
80335
+ const storedPgserveData = readPm2EnvKey(apiEntry, "PGSERVE_DATA");
80336
+ if (storedPgserveData && storedPgserveData !== expected.PGSERVE_DATA) {
80337
+ return {
80338
+ id: "pm2-env-drift",
80339
+ level: "FAIL",
80340
+ detail: `PGSERVE_DATA drift: pm2="${storedPgserveData}" expected="${expected.PGSERVE_DATA}"`
80341
+ };
80342
+ }
80343
+ if (storedDbUrl && storedDbUrl !== expected.DATABASE_URL) {
80344
+ return {
80345
+ id: "pm2-env-drift",
80346
+ level: "WARN",
80347
+ detail: `DATABASE_URL drift: pm2="${storedDbUrl}" expected="${expected.DATABASE_URL}"`
80348
+ };
80349
+ }
80350
+ return { id: "pm2-env-drift", level: "OK", detail: "pm2 stored env matches config" };
80351
+ }
80352
+ async function checkCliKeyValid(deps) {
80353
+ const { serverConfig } = deps.loadState();
80354
+ const valid = await deps.validateStoredKey(serverConfig.port);
80355
+ if (valid) {
80356
+ return { id: "cli-key-valid", level: "OK", detail: "stored CLI key validates against server" };
80357
+ }
80358
+ return { id: "cli-key-valid", level: "FAIL", detail: "stored CLI key does not validate" };
80359
+ }
80360
+ async function checkPgserveReachable(deps) {
80361
+ const { serverConfig } = deps.loadState();
80362
+ const port = resolvePgservePort(serverConfig);
80363
+ const ok = await deps.canConnect(port);
80364
+ if (ok) {
80365
+ return { id: "pgserve-reachable", level: "OK", detail: `pgserve listening on :${port}` };
80366
+ }
80367
+ return { id: "pgserve-reachable", level: "FAIL", detail: `cannot connect to pgserve on :${port}` };
80368
+ }
80369
+ async function checkOmniDbExists(deps) {
80370
+ const exists = await deps.omniDbExists();
80371
+ if (exists) {
80372
+ return { id: "omni-db-exists", level: "OK", detail: "omni database is reachable" };
80373
+ }
80374
+ return { id: "omni-db-exists", level: "FAIL", detail: "omni database is not reachable" };
80375
+ }
80376
+ function checkOrphanedDataDirs(deps) {
80377
+ const found = deps.findOrphanedDataDirs();
80378
+ if (found.length === 0) {
80379
+ return { id: "orphaned-data-dirs", level: "OK", detail: "no orphaned data directories found" };
80380
+ }
80381
+ return {
80382
+ id: "orphaned-data-dirs",
80383
+ level: "WARN",
80384
+ detail: `orphaned data dirs: ${found.join(", ")}`
80385
+ };
80386
+ }
80387
+ async function checkVersionMatch(deps) {
80388
+ const { serverConfig } = deps.loadState();
80389
+ const serverVersion = await deps.fetchHealthVersion(serverConfig.port);
80390
+ if (!serverVersion) {
80391
+ return { id: "version-match", level: "WARN", detail: "could not reach /api/v2/health" };
80392
+ }
80393
+ const cliClean = VERSION.split("+")[0];
80394
+ const serverClean = serverVersion.split("+")[0];
80395
+ if (cliClean === serverClean) {
80396
+ return { id: "version-match", level: "OK", detail: `cli=v${cliClean} server=v${serverClean}` };
80397
+ }
80398
+ return {
80399
+ id: "version-match",
80400
+ level: "WARN",
80401
+ detail: `version mismatch: cli=v${cliClean} server=v${serverClean}`
80402
+ };
80403
+ }
80404
+ async function checkPm2Status(deps) {
80405
+ const processes = await deps.getPm2Processes();
80406
+ if (!processes) {
80407
+ return { id: "pm2-status", level: "WARN", detail: "pm2 not reachable" };
80408
+ }
80409
+ const api = processes.find((p) => p.name === PM2_PROCESSES.api);
80410
+ const nats = processes.find((p) => p.name === PM2_PROCESSES.nats);
80411
+ const apiStatus = api?.pm2_env?.status ?? "missing";
80412
+ const natsStatus = nats?.pm2_env?.status ?? "missing";
80413
+ if (apiStatus === "online" && natsStatus === "online") {
80414
+ return { id: "pm2-status", level: "OK", detail: "omni-api and omni-nats online" };
80415
+ }
80416
+ return {
80417
+ id: "pm2-status",
80418
+ level: "FAIL",
80419
+ detail: `pm2 status: omni-api=${apiStatus} omni-nats=${natsStatus}`
80420
+ };
80421
+ }
80422
+ async function fixPm2EnvDrift(deps) {
80423
+ const { serverConfig, cliConfig } = deps.loadState();
80424
+ const env2 = buildRuntimeEnv(serverConfig, cliConfig);
80425
+ await deps.runPm2(["delete", PM2_PROCESSES.api], env2);
80426
+ const launcherPath = getServerLauncherPath();
80427
+ const startCode = await deps.runPm2(["start", launcherPath, "--name", PM2_PROCESSES.api, "--interpreter", "bash"], env2);
80428
+ if (startCode !== 0) {
80429
+ throw new Error(`pm2 start ${PM2_PROCESSES.api} exited ${startCode}`);
80430
+ }
80431
+ return `relaunched ${PM2_PROCESSES.api} with sanitized env`;
80432
+ }
80433
+ async function fixCliKeyValid(deps) {
80434
+ const { serverConfig, cliConfig } = deps.loadState();
80435
+ const newKey = deps.generateApiKey();
80436
+ const env2 = { ...buildRuntimeEnv(serverConfig, { ...cliConfig, apiKey: newKey }), OMNI_API_KEY: newKey };
80437
+ await deps.runPm2(["set", `${PM2_PROCESSES.api}:OMNI_API_KEY`, newKey]);
80438
+ const restartCode = await deps.runPm2(["restart", PM2_PROCESSES.api], env2);
80439
+ if (restartCode !== 0) {
80440
+ throw new Error(`pm2 restart ${PM2_PROCESSES.api} exited ${restartCode}`);
80441
+ }
80442
+ await deps.sleepMs(1000);
80443
+ const valid = await deps.validateStoredKey(serverConfig.port);
80444
+ if (!valid) {
80445
+ const updated2 = deps.reloadCliConfig();
80446
+ updated2.apiKey = newKey;
80447
+ deps.saveCliConfig(updated2);
80448
+ throw new Error("rotated key does not validate; manually delete __primary__ from api_keys and rerun");
80449
+ }
80450
+ const updated = deps.reloadCliConfig();
80451
+ updated.apiKey = newKey;
80452
+ deps.saveCliConfig(updated);
80453
+ return "rotated CLI key and re-validated";
80454
+ }
80455
+ function fixOrphanedDataDirs(deps) {
80456
+ const found = deps.findOrphanedDataDirs();
80457
+ if (found.length === 0) {
80458
+ return "no orphaned data dirs to clean";
80459
+ }
80460
+ raw("");
80461
+ warn("Review these commands before running them \u2014 orphaned dirs are not auto-deleted:");
80462
+ for (const dir of found) {
80463
+ raw(` rm -rf ${dir}`);
80464
+ }
80465
+ raw("");
80466
+ return `printed ${found.length} rm-rf suggestion(s)`;
80467
+ }
80468
+ async function runAllChecks(deps) {
80469
+ return [
80470
+ await checkPm2EnvDrift(deps),
80471
+ await checkCliKeyValid(deps),
80472
+ await checkPgserveReachable(deps),
80473
+ await checkOmniDbExists(deps),
80474
+ checkOrphanedDataDirs(deps),
80475
+ await checkVersionMatch(deps),
80476
+ await checkPm2Status(deps)
80477
+ ];
80478
+ }
80479
+ async function applyFix(deps, check) {
80480
+ try {
80481
+ if (check.id === "pm2-env-drift")
80482
+ return await fixPm2EnvDrift(deps);
80483
+ if (check.id === "cli-key-valid")
80484
+ return await fixCliKeyValid(deps);
80485
+ if (check.id === "orphaned-data-dirs")
80486
+ return fixOrphanedDataDirs(deps);
80487
+ return null;
80488
+ } catch (err) {
80489
+ const msg = err instanceof Error ? err.message : String(err);
80490
+ return `FAILED ${check.id}: ${msg}`;
80491
+ }
80492
+ }
80493
+ function summarizeChecks(checks) {
80494
+ const summary = { ok: 0, warn: 0, fail: 0 };
80495
+ for (const c2 of checks) {
80496
+ if (c2.level === "OK")
80497
+ summary.ok++;
80498
+ else if (c2.level === "WARN")
80499
+ summary.warn++;
80500
+ else
80501
+ summary.fail++;
80502
+ }
80503
+ return summary;
80504
+ }
80505
+ async function runDoctor(options, depsOverride) {
80506
+ const deps = depsOverride ?? productionDeps();
80507
+ let checks = await runAllChecks(deps);
80508
+ const fixesApplied = [];
80509
+ if (options.fix) {
80510
+ for (const check of checks) {
80511
+ if (check.level === "OK")
80512
+ continue;
80513
+ const result = await applyFix(deps, check);
80514
+ if (result !== null) {
80515
+ fixesApplied.push(result);
80516
+ }
80517
+ }
80518
+ checks = await runAllChecks(deps);
80519
+ }
80520
+ return { checks, summary: summarizeChecks(checks), fixesApplied };
80521
+ }
80522
+ function renderHuman(report) {
80523
+ raw("");
80524
+ raw(" omni doctor \u2014 checks:");
80525
+ raw("");
80526
+ for (const check of report.checks) {
80527
+ const marker = check.level === "OK" ? "\u2713" : check.level === "WARN" ? "\u26A0" : "\u2717";
80528
+ raw(` ${marker} ${check.id.padEnd(20)} ${check.detail}`);
80529
+ }
80530
+ raw("");
80531
+ raw(` summary: ${report.summary.ok} OK, ${report.summary.warn} WARN, ${report.summary.fail} FAIL`);
80532
+ if (report.fixesApplied.length > 0) {
80533
+ raw("");
80534
+ raw(" fixes applied:");
80535
+ for (const fix of report.fixesApplied) {
80536
+ raw(` - ${fix}`);
80537
+ }
80538
+ }
80539
+ raw("");
80540
+ }
80541
+ function createDoctorCommand() {
80542
+ return new Command("doctor").description("Diagnose and repair the embedded omni runtime (env drift, stale keys, version mismatch)").option("--fix", "Attempt to repair WARN/FAIL checks in-place (never touches ~/.omni/data/pgserve)").option("--json", "Emit the full report as structured JSON").option("--verbose", "Include additional diagnostic detail").addHelpText("after", `
80543
+ Checks:
80544
+ pm2-env-drift pm2 stored env vs. buildRuntimeEnv() from config
80545
+ cli-key-valid CLI-stored key validates against running server
80546
+ pgserve-reachable TCP connect to embedded pgserve port
80547
+ omni-db-exists omni database is reachable on embedded pgserve
80548
+ orphaned-data-dirs .pgserve-data directories outside ~/.omni
80549
+ version-match CLI version vs. /api/v2/health version field
80550
+ pm2-status omni-api and omni-nats both online in pm2
80551
+
80552
+ Safety:
80553
+ --fix NEVER touches ~/.omni/data/pgserve \u2014 it only operates on the pm2
80554
+ process lifecycle, stored env, and ~/.omni/config.json. Data directories
80555
+ are never auto-deleted; orphaned dirs print rm-rf commands for review.
80556
+ `).action(async (options) => {
80557
+ if (!await isPm2Available()) {
80558
+ warn("pm2 is not available in PATH \u2014 pm2-dependent checks will be WARN.");
80559
+ }
80560
+ const report = await runDoctor(options);
80561
+ if (options.json === true) {
80562
+ console.log(JSON.stringify(report, null, 2));
80563
+ return;
80564
+ }
80565
+ renderHuman(report);
80566
+ if (report.summary.fail > 0) {
80567
+ process.exit(1);
80568
+ }
80569
+ });
80570
+ }
80571
+
80077
80572
  // src/commands/done.ts
80078
- import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
80573
+ import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
80079
80574
  import { basename, extname } from "path";
80080
80575
 
80081
80576
  // src/context.ts
80082
80577
  init_config();
80083
80578
  async function resolveContext(flags) {
80084
- if (flags?.instance || flags?.chat || flags?.message) {
80085
- return {
80086
- instanceId: flags.instance ?? null,
80087
- chatId: flags.chat ?? null,
80088
- messageId: flags.message ?? null,
80089
- source: "flags"
80090
- };
80091
- }
80579
+ const flagInstance = flags?.instance;
80580
+ const flagChat = flags?.chat;
80581
+ const flagMessage = flags?.message;
80092
80582
  const envInstance = process.env.OMNI_INSTANCE;
80093
80583
  const envChat = process.env.OMNI_CHAT;
80094
80584
  const envMessage = process.env.OMNI_MESSAGE;
80095
- if (envInstance || envChat || envMessage) {
80096
- return {
80097
- instanceId: envInstance ?? null,
80098
- chatId: envChat ?? null,
80099
- messageId: envMessage ?? null,
80100
- source: "env"
80101
- };
80102
- }
80585
+ let apiInstance;
80586
+ let apiChat;
80587
+ let apiMessage;
80103
80588
  try {
80104
80589
  const client = getClient();
80105
80590
  const ctx = await client.context.get();
80106
- if (ctx.instanceId || ctx.chatId || ctx.messageId) {
80107
- return {
80108
- instanceId: ctx.instanceId,
80109
- chatId: ctx.chatId,
80110
- messageId: ctx.messageId,
80111
- source: "api"
80112
- };
80113
- }
80591
+ apiInstance = ctx.instanceId ?? undefined;
80592
+ apiChat = ctx.chatId ?? undefined;
80593
+ apiMessage = ctx.messageId ?? undefined;
80114
80594
  } catch {}
80115
80595
  const config = loadConfig();
80116
- if (config.defaultInstance) {
80117
- return {
80118
- instanceId: config.defaultInstance,
80119
- chatId: null,
80120
- messageId: null,
80121
- source: "config"
80122
- };
80123
- }
80124
- return {
80125
- instanceId: null,
80126
- chatId: null,
80127
- messageId: null,
80128
- source: "none"
80129
- };
80596
+ const configInstance = config.defaultInstance;
80597
+ const instanceId = flagInstance ?? envInstance ?? apiInstance ?? configInstance ?? null;
80598
+ const chatId = flagChat ?? envChat ?? apiChat ?? null;
80599
+ const messageId = flagMessage ?? envMessage ?? apiMessage ?? null;
80600
+ const source = flagInstance || flagChat || flagMessage ? "flags" : envInstance || envChat || envMessage ? "env" : apiInstance || apiChat || apiMessage ? "api" : configInstance ? "config" : "none";
80601
+ return { instanceId, chatId, messageId, source };
80130
80602
  }
80131
80603
  async function resolveInstanceFromContext(explicitInstance) {
80132
80604
  if (explicitInstance)
@@ -80201,7 +80673,7 @@ async function handleReact(client, ctx, emoji) {
80201
80673
  await closeTurn(client, "react", `Reacted ${emoji} + turn closed`);
80202
80674
  }
80203
80675
  async function handleMedia(client, ctx, mediaPath, caption) {
80204
- if (!existsSync3(mediaPath)) {
80676
+ if (!existsSync4(mediaPath)) {
80205
80677
  return error(`File not found: ${mediaPath}`);
80206
80678
  }
80207
80679
  try {
@@ -80241,8 +80713,7 @@ function createDoneCommand() {
80241
80713
  const client = getClient();
80242
80714
  const ctx = await resolveContext({
80243
80715
  instance: options.instance,
80244
- chat: options.chat,
80245
- message: options.message
80716
+ chat: options.chat
80246
80717
  });
80247
80718
  if (!ctx.instanceId) {
80248
80719
  return error("No instance in context. Set OMNI_INSTANCE, use --instance, or run: omni use <instance>");
@@ -80250,14 +80721,16 @@ function createDoneCommand() {
80250
80721
  if (!ctx.chatId) {
80251
80722
  return error("No chat in context. Set OMNI_CHAT, use --chat, or run: omni open <contact>");
80252
80723
  }
80724
+ const messageId = await resolveReplyTo(options.message);
80725
+ const ctxWithMessage = { ...ctx, messageId };
80253
80726
  if (options.skip)
80254
80727
  return handleSkip(client, options.reason);
80255
80728
  if (options.react)
80256
- return handleReact(client, ctx, options.react);
80729
+ return handleReact(client, ctxWithMessage, options.react);
80257
80730
  if (options.media)
80258
- return handleMedia(client, ctx, options.media, options.caption);
80731
+ return handleMedia(client, ctxWithMessage, options.media, options.caption);
80259
80732
  if (text)
80260
- return handleText(client, ctx, text);
80733
+ return handleText(client, ctxWithMessage, text);
80261
80734
  error('Specify what to do: omni done "text", omni done --media <file>, omni done --react <emoji>, or omni done --skip');
80262
80735
  });
80263
80736
  }
@@ -81473,9 +81946,104 @@ function createFilmCommand() {
81473
81946
  });
81474
81947
  }
81475
81948
 
81949
+ // src/commands/history.ts
81950
+ init_output();
81951
+ function truncate2(str, maxLen) {
81952
+ if (str.length <= maxLen)
81953
+ return str;
81954
+ return `${str.slice(0, maxLen - 1)}\u2026`;
81955
+ }
81956
+ function formatTime2(ts) {
81957
+ try {
81958
+ const d = new Date(ts);
81959
+ return d.toLocaleString("en-US", {
81960
+ month: "short",
81961
+ day: "2-digit",
81962
+ hour: "2-digit",
81963
+ minute: "2-digit",
81964
+ hour12: false
81965
+ });
81966
+ } catch {
81967
+ return ts;
81968
+ }
81969
+ }
81970
+ function senderLabel(msg) {
81971
+ if (msg.senderDisplayName)
81972
+ return msg.senderDisplayName;
81973
+ if (msg.isFromMe)
81974
+ return "me";
81975
+ if (msg.senderPlatformUserId)
81976
+ return msg.senderPlatformUserId;
81977
+ return "unknown";
81978
+ }
81979
+ function contentPreview(msg, full) {
81980
+ const maxLen = full ? 0 : 80;
81981
+ const parts = [];
81982
+ if (msg.textContent) {
81983
+ parts.push(msg.textContent);
81984
+ }
81985
+ if (msg.transcription) {
81986
+ parts.push(`[transcription] ${msg.transcription}`);
81987
+ }
81988
+ if (msg.mediaLocalPath) {
81989
+ parts.push(`[file] ${msg.mediaLocalPath}`);
81990
+ } else if (msg.mediaUrl) {
81991
+ parts.push(`[media] ${msg.mediaUrl}`);
81992
+ }
81993
+ const combined = parts.join(" | ") || "-";
81994
+ return maxLen > 0 ? truncate2(combined, maxLen) : combined;
81995
+ }
81996
+ function createHistoryCommand() {
81997
+ return new Command("history").description("Show recent messages in the open chat").option("--limit <n>", "Number of messages to fetch (default: 10)").option("--before <msg-id>", "Fetch messages before this message ID (pagination)").option("--full", "Show full content without truncation").option("--instance <id>", "Override instance (default: from context)").option("--chat <id>", "Override chat (default: from context)").action(async (options) => {
81998
+ const client = getClient();
81999
+ const ctx = await resolveContext({
82000
+ instance: options.instance,
82001
+ chat: options.chat
82002
+ });
82003
+ if (!ctx.instanceId) {
82004
+ return error("No instance in context. Set OMNI_INSTANCE, use --instance, or run: omni use <instance>");
82005
+ }
82006
+ if (!ctx.chatId) {
82007
+ return error("No chat in context. Set OMNI_CHAT, use --chat, or run: omni open <contact>");
82008
+ }
82009
+ const limit = options.limit ? Number.parseInt(options.limit, 10) : 10;
82010
+ if (Number.isNaN(limit) || limit < 1) {
82011
+ return error("--limit must be a positive integer");
82012
+ }
82013
+ try {
82014
+ const messages = await client.chats.getMessages(ctx.chatId, {
82015
+ limit,
82016
+ before: options.before
82017
+ });
82018
+ if (messages.length === 0) {
82019
+ return info("No messages found.");
82020
+ }
82021
+ const format = getCurrentFormat();
82022
+ if (format === "json") {
82023
+ console.log(JSON.stringify(messages, null, 2));
82024
+ return;
82025
+ }
82026
+ if (options.full) {
82027
+ setMaxCellWidth(0);
82028
+ }
82029
+ const rows = messages.map((msg) => ({
82030
+ ID: msg.externalId,
82031
+ TIME: formatTime2(msg.platformTimestamp),
82032
+ SENDER: senderLabel(msg),
82033
+ TYPE: msg.messageType,
82034
+ CONTENT: contentPreview(msg, !!options.full)
82035
+ }));
82036
+ list(rows, { rawData: messages });
82037
+ } catch (err) {
82038
+ const message = err instanceof Error ? err.message : "Unknown error";
82039
+ error(`Failed to fetch history: ${message}`);
82040
+ }
82041
+ });
82042
+ }
82043
+
81476
82044
  // src/commands/imagine.ts
81477
82045
  import { writeFileSync as writeFileSync3 } from "fs";
81478
- import { basename as basename2, dirname as dirname2, extname as extname2, join as join3 } from "path";
82046
+ import { basename as basename2, dirname as dirname3, extname as extname2, join as join6 } from "path";
81479
82047
  init_output();
81480
82048
  var ALLOWED_ASPECT_RATIOS = ["1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3"];
81481
82049
  function extensionForMime(mimeType) {
@@ -81486,13 +82054,13 @@ function extensionForMime(mimeType) {
81486
82054
  return ".png";
81487
82055
  }
81488
82056
  function buildOutputPath(outputBase, index, total, mimeType) {
81489
- const dir = dirname2(outputBase);
82057
+ const dir = dirname3(outputBase);
81490
82058
  const ext = extname2(outputBase) || extensionForMime(mimeType);
81491
82059
  const stem = basename2(outputBase, extname2(outputBase));
81492
82060
  if (total <= 1) {
81493
- return join3(dir, `${stem}${ext}`);
82061
+ return join6(dir, `${stem}${ext}`);
81494
82062
  }
81495
- return join3(dir, `${stem}-${index + 1}${ext}`);
82063
+ return join6(dir, `${stem}-${index + 1}${ext}`);
81496
82064
  }
81497
82065
  function parseAspectRatio(value) {
81498
82066
  if (!value)
@@ -81610,71 +82178,26 @@ function createImagineCommand() {
81610
82178
  }
81611
82179
 
81612
82180
  // src/commands/install.ts
81613
- import { chmodSync, existsSync as existsSync4, mkdirSync as mkdirSync2, writeFileSync as writeFileSync4 } from "fs";
81614
- import { homedir as homedir2 } from "os";
81615
- import { join as join5 } from "path";
82181
+ import { chmodSync, existsSync as existsSync5, mkdirSync as mkdirSync2, writeFileSync as writeFileSync4 } from "fs";
82182
+ import { homedir as homedir3 } from "os";
82183
+ import { join as join7 } from "path";
81616
82184
  import { createInterface as createInterface2 } from "readline";
81617
82185
  init_config();
81618
-
81619
- // src/health.ts
81620
- var DEFAULT_API_PORT = 8882;
81621
- var HEALTH_TIMEOUT_MS = 15000;
81622
- var HEALTH_POLL_INTERVAL_MS = 500;
81623
- function getHealthCheckUrl(port) {
81624
- return `http://localhost:${port}/api/v2/health`;
81625
- }
81626
- async function waitForHealth(port, timeoutMs = HEALTH_TIMEOUT_MS) {
81627
- const healthCheckUrl = getHealthCheckUrl(port);
81628
- const deadline = Date.now() + timeoutMs;
81629
- while (Date.now() < deadline) {
81630
- try {
81631
- const resp = await fetch(healthCheckUrl, { signal: AbortSignal.timeout(1000) });
81632
- if (resp.ok)
81633
- return true;
81634
- } catch {}
81635
- await Bun.sleep(HEALTH_POLL_INTERVAL_MS);
81636
- }
81637
- return false;
81638
- }
81639
-
81640
- // src/commands/install.ts
81641
- init_output();
81642
-
81643
- // src/server-bundle.ts
81644
82186
  init_output();
81645
- import { dirname as dirname3, join as join4 } from "path";
81646
- import { fileURLToPath as fileURLToPath2 } from "url";
81647
- function getServerBundlePath() {
81648
- try {
81649
- const thisFile = fileURLToPath2(import.meta.url);
81650
- const distDir = dirname3(thisFile);
81651
- return join4(distDir, "server", "index.js");
81652
- } catch {
81653
- return join4(process.cwd(), "dist", "server", "index.js");
81654
- }
82187
+ var DEFAULT_DATA_DIR = join7(homedir3(), ".omni", "data");
82188
+ var OMNI_DIR = join7(homedir3(), ".omni");
82189
+ var NATS_BINARY_PATH = join7(OMNI_DIR, "nats-server");
82190
+ var NATS_VERSION = "v2.12.4";
82191
+ function computeDefaultDatabaseUrl() {
82192
+ return buildEmbeddedDatabaseUrl();
81655
82193
  }
81656
- function getServerLauncherPath() {
81657
- try {
81658
- const thisFile = fileURLToPath2(import.meta.url);
81659
- const distDir = dirname3(thisFile);
81660
- return join4(distDir, "..", "bin", "omni-server");
81661
- } catch {
81662
- return join4(process.cwd(), "bin", "omni-server");
82194
+ function resolveInstallDatabaseUrl(options) {
82195
+ const flag = options.databaseUrlFlag?.trim();
82196
+ if (flag && flag.length > 0) {
82197
+ return flag;
81663
82198
  }
82199
+ return computeDefaultDatabaseUrl();
81664
82200
  }
81665
- function bundleNotFoundError(bundlePath) {
81666
- error(`Server bundle not found at: ${bundlePath}
81667
- This command requires @automagik/omni installed from npm.
81668
- Install: bun add -g @automagik/omni
81669
- Or build locally: make cli-build-full`, undefined, 1);
81670
- }
81671
-
81672
- // src/commands/install.ts
81673
- var DEFAULT_DATA_DIR = join5(homedir2(), ".omni", "data");
81674
- var DEFAULT_DATABASE_URL = process.env.DATABASE_URL ?? "postgresql://postgres:postgres@localhost:5432/omni";
81675
- var OMNI_DIR = join5(homedir2(), ".omni");
81676
- var NATS_BINARY_PATH = join5(OMNI_DIR, "nats-server");
81677
- var NATS_VERSION = "v2.12.4";
81678
82201
  async function isBunAvailable() {
81679
82202
  try {
81680
82203
  const proc = Bun.spawn({
@@ -81742,10 +82265,10 @@ async function downloadNats() {
81742
82265
  return false;
81743
82266
  }
81744
82267
  const arrayBuf = await resp.arrayBuffer();
81745
- const tarPath = join5(OMNI_DIR, fileName);
82268
+ const tarPath = join7(OMNI_DIR, fileName);
81746
82269
  writeFileSync4(tarPath, Buffer.from(arrayBuf));
81747
82270
  spinner.text = "Extracting NATS binary...";
81748
- const tmpDir = join5(OMNI_DIR, "nats-tmp");
82271
+ const tmpDir = join7(OMNI_DIR, "nats-tmp");
81749
82272
  mkdirSync2(tmpDir, { recursive: true });
81750
82273
  const tarProc = Bun.spawn({
81751
82274
  cmd: ["tar", "-xzf", tarPath, "-C", tmpDir],
@@ -81793,11 +82316,11 @@ async function promptLine(question, defaultValue = "") {
81793
82316
  input: process.stdin,
81794
82317
  output: process.stdout
81795
82318
  });
81796
- return new Promise((resolve) => {
82319
+ return new Promise((resolve2) => {
81797
82320
  rl.question(question, (answer) => {
81798
82321
  rl.close();
81799
82322
  const trimmed = answer.trim();
81800
- resolve(trimmed === "" ? defaultValue : trimmed);
82323
+ resolve2(trimmed === "" ? defaultValue : trimmed);
81801
82324
  });
81802
82325
  });
81803
82326
  }
@@ -81806,29 +82329,24 @@ async function promptYesNo(question, defaultYes = true) {
81806
82329
  input: process.stdin,
81807
82330
  output: process.stdout
81808
82331
  });
81809
- return new Promise((resolve) => {
82332
+ return new Promise((resolve2) => {
81810
82333
  rl.question(question, (answer) => {
81811
82334
  rl.close();
81812
82335
  const trimmed = answer.trim().toLowerCase();
81813
82336
  if (trimmed === "")
81814
- return resolve(defaultYes);
81815
- resolve(trimmed === "y" || trimmed === "yes");
82337
+ return resolve2(defaultYes);
82338
+ resolve2(trimmed === "y" || trimmed === "yes");
81816
82339
  });
81817
82340
  });
81818
82341
  }
81819
- function buildApiRuntimeEnv(cfg) {
81820
- return {
81821
- API_PORT: String(cfg.port),
81822
- DATABASE_URL: cfg.databaseUrl,
81823
- OMNI_API_KEY: cfg.apiKey,
81824
- MEDIA_STORAGE_PATH: join5(cfg.dataDir, "media"),
81825
- OMNI_PACKAGES_DIR: join5(cfg.dataDir, "packages"),
81826
- PGSERVE_EMBEDDED: "true",
81827
- PGSERVE_DATA: join5(cfg.dataDir, "pgserve"),
81828
- NATS_URL: "nats://localhost:4222",
81829
- NODE_ENV: "production",
81830
- LOG_LEVEL: "info"
82342
+ function buildWizardRuntimeEnv(cfg) {
82343
+ const serverConfig = {
82344
+ ...DEFAULT_SERVER_CONFIG,
82345
+ port: cfg.port,
82346
+ databaseUrl: cfg.databaseUrl,
82347
+ dataDir: cfg.dataDir
81831
82348
  };
82349
+ return buildRuntimeEnv(serverConfig, { apiKey: cfg.apiKey });
81832
82350
  }
81833
82351
  async function writeSystemdUnit(_cfg) {
81834
82352
  const apiUnit = `[Unit]
@@ -81842,7 +82360,7 @@ ExecStart=/usr/bin/env omni start
81842
82360
  ExecStop=/usr/bin/env omni stop
81843
82361
  ExecReload=/usr/bin/env omni restart
81844
82362
  Restart=on-failure
81845
- PIDFile=${homedir2()}/.pm2/pm2.pid
82363
+ PIDFile=${homedir3()}/.pm2/pm2.pid
81846
82364
 
81847
82365
  [Install]
81848
82366
  WantedBy=multi-user.target
@@ -81853,7 +82371,7 @@ After=network.target
81853
82371
 
81854
82372
  [Service]
81855
82373
  Type=simple
81856
- ExecStart="${NATS_BINARY_PATH}" -js -sd "${join5(_cfg.dataDir, "nats")}"
82374
+ ExecStart="${NATS_BINARY_PATH}" -js -sd "${join7(_cfg.dataDir, "nats")}"
81857
82375
  Restart=on-failure
81858
82376
  RestartSec=5
81859
82377
 
@@ -81903,7 +82421,7 @@ async function runSystemChecks(port) {
81903
82421
  return { bunOk, portOk };
81904
82422
  }
81905
82423
  async function ensureNats() {
81906
- if (existsSync4(NATS_BINARY_PATH)) {
82424
+ if (existsSync5(NATS_BINARY_PATH)) {
81907
82425
  raw(` \u2713 NATS binary found at ${NATS_BINARY_PATH}`);
81908
82426
  return;
81909
82427
  }
@@ -81927,22 +82445,23 @@ async function chooseProcessManager(nonInteractive, forceSystemd) {
81927
82445
  return "manual";
81928
82446
  return "pm2";
81929
82447
  }
81930
- async function promptConfig(nonInteractive, portOverride) {
82448
+ async function promptConfig(nonInteractive, portOverride, databaseUrlOverride) {
82449
+ const resolvedDatabaseUrl = resolveInstallDatabaseUrl({ databaseUrlFlag: databaseUrlOverride });
81931
82450
  if (nonInteractive) {
81932
82451
  return {
81933
82452
  port: portOverride ?? DEFAULT_API_PORT,
81934
82453
  dataDir: DEFAULT_DATA_DIR,
81935
- databaseUrl: DEFAULT_DATABASE_URL
82454
+ databaseUrl: resolvedDatabaseUrl
81936
82455
  };
81937
82456
  }
81938
82457
  const portStr = await promptLine(` API port [${DEFAULT_API_PORT}]: `, String(portOverride ?? DEFAULT_API_PORT));
81939
82458
  const port = Number.parseInt(portStr, 10);
81940
82459
  const dataDir = await promptLine(` Data directory [${DEFAULT_DATA_DIR}]: `, DEFAULT_DATA_DIR);
81941
- const databaseUrl = await promptLine(` Database URL [${DEFAULT_DATABASE_URL}]: `, DEFAULT_DATABASE_URL);
82460
+ const databaseUrl = databaseUrlOverride ? databaseUrlOverride : await promptLine(` Database URL [${resolvedDatabaseUrl}]: `, resolvedDatabaseUrl);
81942
82461
  return {
81943
82462
  port: Number.isNaN(port) ? DEFAULT_API_PORT : port,
81944
82463
  dataDir: dataDir || DEFAULT_DATA_DIR,
81945
- databaseUrl: databaseUrl || DEFAULT_DATABASE_URL
82464
+ databaseUrl: databaseUrl || resolvedDatabaseUrl
81946
82465
  };
81947
82466
  }
81948
82467
  async function promptApiKey(nonInteractive) {
@@ -81972,13 +82491,13 @@ async function startServices(cfg) {
81972
82491
  return;
81973
82492
  }
81974
82493
  const bundlePath = getServerBundlePath();
81975
- if (!existsSync4(bundlePath)) {
82494
+ if (!existsSync5(bundlePath)) {
81976
82495
  warn(`Server bundle not found at: ${bundlePath}
81977
82496
  Install @automagik/omni from npm: bun add -g @automagik/omni
81978
82497
  Or build locally: make cli-build-full`);
81979
82498
  return;
81980
82499
  }
81981
- const runtimeEnv = buildApiRuntimeEnv(cfg);
82500
+ const runtimeEnv = buildWizardRuntimeEnv(cfg);
81982
82501
  const apiSpinner = ora(`Starting ${PM2_PROCESSES.api} on port ${cfg.port}...`).start();
81983
82502
  const launcherPath = getServerLauncherPath();
81984
82503
  const apiCode = await runPm2(["start", launcherPath, "--name", PM2_PROCESSES.api, "--interpreter", "bash"], runtimeEnv);
@@ -81987,9 +82506,9 @@ async function startServices(cfg) {
81987
82506
  } else {
81988
82507
  apiSpinner.succeed(`${PM2_PROCESSES.api} started`);
81989
82508
  }
81990
- if (existsSync4(NATS_BINARY_PATH)) {
82509
+ if (existsSync5(NATS_BINARY_PATH)) {
81991
82510
  const natsSpinner = ora(`Starting ${PM2_PROCESSES.nats}...`).start();
81992
- const natsDataDir = join5(cfg.dataDir, "nats");
82511
+ const natsDataDir = join7(cfg.dataDir, "nats");
81993
82512
  mkdirSync2(natsDataDir, { recursive: true });
81994
82513
  const natsCode = await runPm2([
81995
82514
  "start",
@@ -82027,7 +82546,7 @@ function writeConfigFile(port, apiKey) {
82027
82546
  format: "human"
82028
82547
  };
82029
82548
  saveConfig(config);
82030
- success(`Config written to ${join5(homedir2(), ".omni", "config.json")}`);
82549
+ success(`Config written to ${join7(homedir3(), ".omni", "config.json")}`);
82031
82550
  }
82032
82551
  async function printDoneBanner(port, apiKey, nonInteractive, showFullGeneratedKey) {
82033
82552
  const displayedKey = showFullGeneratedKey ? apiKey : maskApiKey(apiKey);
@@ -82057,6 +82576,7 @@ async function runInstall(options) {
82057
82576
  const nonInteractive = options.nonInteractive === true;
82058
82577
  const forceSystemd = options.systemd === true;
82059
82578
  const portOverride = options.port !== undefined ? Number.parseInt(options.port, 10) : undefined;
82579
+ const databaseUrlOverride = options.databaseUrl && options.databaseUrl.trim().length > 0 ? options.databaseUrl.trim() : undefined;
82060
82580
  printBanner();
82061
82581
  const effectivePort = portOverride ?? DEFAULT_API_PORT;
82062
82582
  const { bunOk, portOk } = await runSystemChecks(effectivePort);
@@ -82068,7 +82588,7 @@ async function runInstall(options) {
82068
82588
  }
82069
82589
  await ensureNats();
82070
82590
  const processManager = await chooseProcessManager(nonInteractive, forceSystemd);
82071
- const { port, dataDir, databaseUrl } = await promptConfig(nonInteractive, portOverride);
82591
+ const { port, dataDir, databaseUrl } = await promptConfig(nonInteractive, portOverride, databaseUrlOverride);
82072
82592
  const { apiKey, generated: apiKeyGenerated } = await promptApiKey(nonInteractive);
82073
82593
  const cfg = { port, dataDir, databaseUrl, apiKey, processManager };
82074
82594
  await startServices(cfg);
@@ -82085,7 +82605,7 @@ async function runInstall(options) {
82085
82605
  process.exit(0);
82086
82606
  }
82087
82607
  function createInstallCommand() {
82088
- return new Command("install").description("Interactive setup wizard \u2014 bootstraps Omni server from zero").option("--non-interactive", "Use all defaults, skip prompts (for CI/scripted installs)").option("--systemd", "Write systemd unit instead of using PM2 (requires sudo)").option("--port <port>", `API port to use (default: ${DEFAULT_API_PORT})`).action(runInstall);
82608
+ return new Command("install").description("Interactive setup wizard \u2014 bootstraps Omni server from zero").option("--non-interactive", "Use all defaults, skip prompts (for CI/scripted installs)").option("--systemd", "Write systemd unit instead of using PM2 (requires sudo)").option("--port <port>", `API port to use (default: ${DEFAULT_API_PORT})`).option("--database-url <url>", "External PostgreSQL URL (opt-in external-DB mode; defaults to embedded pgserve)").action(runInstall);
82089
82609
  }
82090
82610
 
82091
82611
  // src/commands/instances.ts
@@ -82343,12 +82863,12 @@ function createInstancesCommand() {
82343
82863
  const client = getClient();
82344
82864
  const id = await resolveInstanceId(rawId);
82345
82865
  const renderQrAscii = async (qrData, expiresAt) => {
82346
- return new Promise((resolve) => {
82866
+ return new Promise((resolve2) => {
82347
82867
  import_qrcode_terminal.default.generate(qrData, { small: true }, (qrArt) => {
82348
82868
  raw(qrArt);
82349
82869
  if (expiresAt)
82350
82870
  dim(`Expires: ${expiresAt}`);
82351
- resolve();
82871
+ resolve2();
82352
82872
  });
82353
82873
  });
82354
82874
  };
@@ -83416,8 +83936,8 @@ function createLogsCommand() {
83416
83936
  }
83417
83937
 
83418
83938
  // src/commands/media.ts
83419
- import { createWriteStream, existsSync as existsSync5, mkdirSync as mkdirSync3, statSync } from "fs";
83420
- import { basename as basename4, dirname as dirname4, resolve } from "path";
83939
+ import { createWriteStream, existsSync as existsSync6, mkdirSync as mkdirSync3, statSync as statSync2 } from "fs";
83940
+ import { basename as basename4, dirname as dirname4, resolve as resolve2 } from "path";
83421
83941
  import { Readable } from "stream";
83422
83942
  import { pipeline } from "stream/promises";
83423
83943
  init_config();
@@ -83474,18 +83994,18 @@ function resolveOutputPath(outputPath, result) {
83474
83994
  const fallbackName = result.mediaLocalPath ? basename4(result.mediaLocalPath) : "";
83475
83995
  const filename = fallbackName || `${result.messageId}`;
83476
83996
  if (!outputPath)
83477
- return resolve(process.cwd(), filename);
83997
+ return resolve2(process.cwd(), filename);
83478
83998
  const isDirHint = outputPath.endsWith("/") || outputPath.endsWith("\\");
83479
- const resolved = resolve(outputPath);
83999
+ const resolved = resolve2(outputPath);
83480
84000
  if (isDirHint)
83481
- return resolve(resolved, filename);
83482
- if (existsSync5(resolved) && statSync(resolved).isDirectory())
83483
- return resolve(resolved, filename);
84001
+ return resolve2(resolved, filename);
84002
+ if (existsSync6(resolved) && statSync2(resolved).isDirectory())
84003
+ return resolve2(resolved, filename);
83484
84004
  return resolved;
83485
84005
  }
83486
84006
  async function downloadToFile(url, apiKey, destinationPath) {
83487
84007
  const destDir = dirname4(destinationPath);
83488
- if (!existsSync5(destDir))
84008
+ if (!existsSync6(destDir))
83489
84009
  mkdirSync3(destDir, { recursive: true });
83490
84010
  const resp = await fetch(url, {
83491
84011
  method: "GET",
@@ -83713,7 +84233,7 @@ function formatDate(date) {
83713
84233
  const d = typeof date === "string" ? new Date(date) : date;
83714
84234
  return d.toLocaleDateString("en-US", { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" });
83715
84235
  }
83716
- function truncate2(text, maxLen) {
84236
+ function truncate3(text, maxLen) {
83717
84237
  if (!text)
83718
84238
  return "-";
83719
84239
  const clean = text.replace(/\n/g, " ").trim();
@@ -83778,10 +84298,10 @@ function formatSearchResults(messages, chatMap) {
83778
84298
  const chat = chatMap.get(m.chatId);
83779
84299
  const chatName = chat?.name ?? chat?.externalId ?? m.chatId.slice(0, 8);
83780
84300
  return {
83781
- chat: truncate2(chatName, 20),
84301
+ chat: truncate3(chatName, 20),
83782
84302
  time: formatDate(m.platformTimestamp),
83783
84303
  type: m.messageType,
83784
- content: truncate2(getContentPreview(m), 50)
84304
+ content: truncate3(getContentPreview(m), 50)
83785
84305
  };
83786
84306
  });
83787
84307
  }
@@ -84583,7 +85103,7 @@ var LEVEL_LABELS = {
84583
85103
  warn: "WARN ",
84584
85104
  error: "ERROR"
84585
85105
  };
84586
- function formatTime2(timestamp) {
85106
+ function formatTime3(timestamp) {
84587
85107
  const date = new Date(timestamp);
84588
85108
  const hours = date.getHours().toString().padStart(2, "0");
84589
85109
  const minutes = date.getMinutes().toString().padStart(2, "0");
@@ -84634,7 +85154,7 @@ function formatData(data2) {
84634
85154
  }
84635
85155
  function formatPretty(entry) {
84636
85156
  const { level, time, module, msg, ...data2 } = entry;
84637
- const timeStr = formatTime2(time);
85157
+ const timeStr = formatTime3(time);
84638
85158
  const levelColor = COLORS[level];
84639
85159
  const levelStr = `${levelColor}${LEVEL_LABELS[level]}${COLORS.reset}`;
84640
85160
  const moduleStr = formatModule(module);
@@ -89136,7 +89656,7 @@ function createSubscription(options) {
89136
89656
  if (!isActive)
89137
89657
  break;
89138
89658
  if (activeCount >= concurrency) {
89139
- await new Promise((resolve2) => pendingMessages.push(resolve2));
89659
+ await new Promise((resolve3) => pendingMessages.push(resolve3));
89140
89660
  }
89141
89661
  activeCount++;
89142
89662
  processMessage(msg).catch((error2) => {
@@ -89149,7 +89669,7 @@ function createSubscription(options) {
89149
89669
  });
89150
89670
  }
89151
89671
  while (activeCount > 0) {
89152
- await new Promise((resolve2) => setTimeout(resolve2, 100));
89672
+ await new Promise((resolve3) => setTimeout(resolve3, 100));
89153
89673
  }
89154
89674
  } catch (error2) {
89155
89675
  if (isActive) {
@@ -89558,7 +90078,7 @@ class NatsEventBus {
89558
90078
  return Math.min(delay, maxDelayMs);
89559
90079
  }
89560
90080
  sleep(ms) {
89561
- return new Promise((resolve2) => setTimeout(resolve2, ms));
90081
+ return new Promise((resolve3) => setTimeout(resolve3, ms));
89562
90082
  }
89563
90083
  }
89564
90084
  // ../core/src/events/dead-letter.ts
@@ -91715,12 +92235,12 @@ class AutomationEngine {
91715
92235
  throw new QueueFullError(instanceId, queue.pending.length, maxQueueDepth);
91716
92236
  }
91717
92237
  const queueRef = queue;
91718
- return new Promise((resolve2) => {
92238
+ return new Promise((resolve3) => {
91719
92239
  queueRef.pending.push({
91720
92240
  automation,
91721
92241
  event,
91722
92242
  context,
91723
- resolve: resolve2
92243
+ resolve: resolve3
91724
92244
  });
91725
92245
  logger4.debug("Execution queued", {
91726
92246
  automationId: automation.id,
@@ -92020,13 +92540,13 @@ class OpenClawClient {
92020
92540
  }
92021
92541
  const id = crypto.randomUUID();
92022
92542
  const frame = { type: "req", id, method, params };
92023
- return new Promise((resolve2, reject) => {
92543
+ return new Promise((resolve3, reject) => {
92024
92544
  const timeout = setTimeout(() => {
92025
92545
  this.pending.delete(id);
92026
92546
  reject(new Error(`Request ${method} timed out after ${timeoutMs}ms`));
92027
92547
  }, timeoutMs);
92028
92548
  this.pending.set(id, {
92029
- resolve: resolve2,
92549
+ resolve: resolve3,
92030
92550
  reject,
92031
92551
  timeout,
92032
92552
  method
@@ -92045,7 +92565,7 @@ class OpenClawClient {
92045
92565
  return;
92046
92566
  if (this.closed)
92047
92567
  throw new Error("Client is stopped");
92048
- return new Promise((resolve2, reject) => {
92568
+ return new Promise((resolve3, reject) => {
92049
92569
  const timeout = setTimeout(() => {
92050
92570
  cleanup();
92051
92571
  reject(new Error(`Connection not ready within ${timeoutMs}ms`));
@@ -92053,7 +92573,7 @@ class OpenClawClient {
92053
92573
  const check = () => {
92054
92574
  if (this.connected) {
92055
92575
  cleanup();
92056
- resolve2();
92576
+ resolve3();
92057
92577
  } else if (this.closed) {
92058
92578
  cleanup();
92059
92579
  reject(new Error("Client stopped while waiting for connection"));
@@ -92376,8 +92896,8 @@ var log15 = createLogger("provider:a2a");
92376
92896
  // ../core/src/providers/nats-genie-provider.ts
92377
92897
  var import_nats4 = __toESM(require_mod4(), 1);
92378
92898
  import { mkdir, writeFile } from "fs/promises";
92379
- import { homedir as homedir3 } from "os";
92380
- import { join as join6 } from "path";
92899
+ import { homedir as homedir4 } from "os";
92900
+ import { join as join8 } from "path";
92381
92901
  var log16 = createLogger("provider:nats-genie");
92382
92902
 
92383
92903
  class NatsGenieProvider {
@@ -92456,15 +92976,16 @@ class NatsGenieProvider {
92456
92976
  await this.ensureConnected();
92457
92977
  if (!this.nc)
92458
92978
  return;
92459
- const topic = `omni.reply.${this.config.instanceId}.*`;
92979
+ const topic = `omni.reply.${this.config.instanceId}.>`;
92460
92980
  const sub = this.nc.subscribe(topic);
92461
92981
  this.replySubscription = sub;
92462
92982
  log16.info("Subscribed to agent replies", { topic });
92983
+ const subjectPrefix = `omni.reply.${this.config.instanceId}.`;
92463
92984
  (async () => {
92464
92985
  for await (const msg of sub) {
92465
92986
  try {
92466
92987
  const data2 = JSON.parse(this.sc.decode(msg.data));
92467
- const chatId = data2.chat_id || msg.subject.split(".").pop() || "";
92988
+ const chatId = data2.chat_id || (msg.subject.startsWith(subjectPrefix) ? msg.subject.slice(subjectPrefix.length) : msg.subject.split(".").pop() || "");
92468
92989
  if (data2.content && this.config.onReply) {
92469
92990
  await this.config.onReply(chatId, data2.content, {
92470
92991
  agent: data2.agent,
@@ -92494,6 +93015,41 @@ class NatsGenieProvider {
92494
93015
  };
92495
93016
  }
92496
93017
  }
93018
+ async resetSession(sessionKey, chatId, instanceId) {
93019
+ const resolvedInstanceId = instanceId ?? this.config.instanceId;
93020
+ if (!chatId) {
93021
+ log16.warn("NATS session reset skipped: missing chatId", {
93022
+ providerId: this.id,
93023
+ sessionKey
93024
+ });
93025
+ throw new Error("chatId is required to reset NATS Genie session");
93026
+ }
93027
+ const topic = `omni.session.reset.${resolvedInstanceId}.${chatId}`;
93028
+ const payload = {
93029
+ action: "kill",
93030
+ sessionKey,
93031
+ agent: this.config.agentName,
93032
+ instance_id: resolvedInstanceId,
93033
+ chat_id: chatId,
93034
+ timestamp: new Date().toISOString()
93035
+ };
93036
+ try {
93037
+ await this.ensureConnected();
93038
+ this.nc?.publish(topic, this.sc.encode(JSON.stringify(payload)));
93039
+ log16.info("Published session reset to NATS", {
93040
+ topic,
93041
+ providerId: this.id,
93042
+ sessionKey,
93043
+ chatId
93044
+ });
93045
+ } catch (error2) {
93046
+ log16.error("Failed to publish NATS session reset", {
93047
+ topic,
93048
+ error: error2 instanceof Error ? error2.message : String(error2)
93049
+ });
93050
+ throw error2;
93051
+ }
93052
+ }
92497
93053
  async dispose() {
92498
93054
  if (this.replySubscription) {
92499
93055
  this.replySubscription.unsubscribe();
@@ -92532,10 +93088,10 @@ class NatsGenieProvider {
92532
93088
  }
92533
93089
  async writeDeadLetter(payload, error2) {
92534
93090
  try {
92535
- const dlDir = join6(homedir3(), ".omni", "dead-letters");
93091
+ const dlDir = join8(homedir4(), ".omni", "dead-letters");
92536
93092
  await mkdir(dlDir, { recursive: true });
92537
93093
  const filename = `nats-genie-${Date.now()}-${payload.chatId}.json`;
92538
- await writeFile(join6(dlDir, filename), JSON.stringify({
93094
+ await writeFile(join8(dlDir, filename), JSON.stringify({
92539
93095
  payload,
92540
93096
  error: error2 instanceof Error ? error2.message : String(error2),
92541
93097
  timestamp: new Date().toISOString()
@@ -92883,9 +93439,9 @@ init_output();
92883
93439
  // src/commands/providers-setup.ts
92884
93440
  import { execFileSync as execFileSync2, execSync } from "child_process";
92885
93441
  import * as nodeCrypto2 from "crypto";
92886
- import { existsSync as existsSync6, mkdirSync as mkdirSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync5 } from "fs";
92887
- import { homedir as homedir4 } from "os";
92888
- import { dirname as dirname5, resolve as resolve2 } from "path";
93442
+ import { existsSync as existsSync7, mkdirSync as mkdirSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync5 } from "fs";
93443
+ import { homedir as homedir5 } from "os";
93444
+ import { dirname as dirname5, resolve as resolve3 } from "path";
92889
93445
  import { createInterface as createInterface3 } from "readline";
92890
93446
  init_config();
92891
93447
  init_output();
@@ -92894,11 +93450,11 @@ async function promptLine2(question, defaultValue = "") {
92894
93450
  input: process.stdin,
92895
93451
  output: process.stdout
92896
93452
  });
92897
- return new Promise((resolve3) => {
93453
+ return new Promise((resolve4) => {
92898
93454
  rl.question(question, (answer) => {
92899
93455
  rl.close();
92900
93456
  const trimmed = answer.trim();
92901
- resolve3(trimmed === "" ? defaultValue : trimmed);
93457
+ resolve4(trimmed === "" ? defaultValue : trimmed);
92902
93458
  });
92903
93459
  });
92904
93460
  }
@@ -92916,7 +93472,7 @@ async function promptSecret(question) {
92916
93472
  }
92917
93473
  process.stdin.resume();
92918
93474
  process.stdin.setEncoding("utf8");
92919
- return new Promise((resolve3) => {
93475
+ return new Promise((resolve4) => {
92920
93476
  let input = "";
92921
93477
  const onData = (ch) => {
92922
93478
  const c2 = ch.toString();
@@ -92928,7 +93484,7 @@ async function promptSecret(question) {
92928
93484
  process.stdin.removeListener("data", onData);
92929
93485
  process.stdout.write(`
92930
93486
  `);
92931
- resolve3(input.trim());
93487
+ resolve4(input.trim());
92932
93488
  } else if (c2 === "\x03") {
92933
93489
  process.exit(1);
92934
93490
  } else if (isBackspace(c2)) {
@@ -92943,7 +93499,7 @@ async function promptSecret(question) {
92943
93499
  function sendWsRequest(ws, method, params, timeoutMs = 15000) {
92944
93500
  const id = nodeCrypto2.randomUUID();
92945
93501
  const frame = { type: "req", id, method, params };
92946
- return new Promise((resolve3, reject) => {
93502
+ return new Promise((resolve4, reject) => {
92947
93503
  const timeout = setTimeout(() => {
92948
93504
  cleanup();
92949
93505
  reject(new Error(`WS request "${method}" timed out after ${timeoutMs}ms`));
@@ -92959,7 +93515,7 @@ function sendWsRequest(ws, method, params, timeoutMs = 15000) {
92959
93515
  return;
92960
93516
  cleanup();
92961
93517
  if (res.ok) {
92962
- resolve3(res.payload);
93518
+ resolve4(res.payload);
92963
93519
  } else {
92964
93520
  reject(new Error(res.error?.message ?? `Request "${method}" failed`));
92965
93521
  }
@@ -92979,13 +93535,13 @@ function sendWsRequest(ws, method, params, timeoutMs = 15000) {
92979
93535
  });
92980
93536
  }
92981
93537
  function waitForWsEvent(ws, eventName, buffered = [], timeoutMs = 1e4) {
92982
- return new Promise((resolve3, reject) => {
93538
+ return new Promise((resolve4, reject) => {
92983
93539
  for (let i = 0;i < buffered.length; i++) {
92984
93540
  try {
92985
93541
  const parsed = JSON.parse(String(buffered[i].data));
92986
93542
  if (parsed.type === "event" && parsed.event === eventName) {
92987
93543
  buffered.splice(i, 1);
92988
- resolve3(parsed);
93544
+ resolve4(parsed);
92989
93545
  return;
92990
93546
  }
92991
93547
  } catch {}
@@ -93004,7 +93560,7 @@ function waitForWsEvent(ws, eventName, buffered = [], timeoutMs = 1e4) {
93004
93560
  if (frame.type !== "event" || frame.event !== eventName)
93005
93561
  return;
93006
93562
  cleanup();
93007
- resolve3(frame);
93563
+ resolve4(frame);
93008
93564
  };
93009
93565
  const closeHandler = (ev) => {
93010
93566
  cleanup();
@@ -93020,7 +93576,7 @@ function waitForWsEvent(ws, eventName, buffered = [], timeoutMs = 1e4) {
93020
93576
  });
93021
93577
  }
93022
93578
  function openWs(url) {
93023
- return new Promise((resolve3, reject) => {
93579
+ return new Promise((resolve4, reject) => {
93024
93580
  const ws = new WebSocket(url);
93025
93581
  const buffered = [];
93026
93582
  const bufferListener = (event) => {
@@ -93029,7 +93585,7 @@ function openWs(url) {
93029
93585
  ws.addEventListener("message", bufferListener);
93030
93586
  const onOpen = () => {
93031
93587
  ws.removeEventListener("error", onError);
93032
- resolve3([ws, buffered, bufferListener]);
93588
+ resolve4([ws, buffered, bufferListener]);
93033
93589
  };
93034
93590
  const onError = () => {
93035
93591
  ws.removeEventListener("open", onOpen);
@@ -93111,10 +93667,10 @@ async function pairDevice(gatewayUrl, gatewayToken, keypair, spinner) {
93111
93667
  ws.close(1000, "pairing complete");
93112
93668
  }
93113
93669
  }
93114
- var OPENCLAW_CONFIG_PATH = resolve2(homedir4(), ".openclaw", "openclaw.json");
93670
+ var OPENCLAW_CONFIG_PATH = resolve3(homedir5(), ".openclaw", "openclaw.json");
93115
93671
  var PLUGIN_MARKER = "plugin-openclaw/omni.ts";
93116
93672
  function readOpenClawConfig(configPath) {
93117
- if (!existsSync6(configPath))
93673
+ if (!existsSync7(configPath))
93118
93674
  return {};
93119
93675
  const raw2 = readFileSync4(configPath, "utf-8").trim();
93120
93676
  if (!raw2)
@@ -93155,10 +93711,10 @@ function isValidUuid(value) {
93155
93711
  }
93156
93712
  function resolvePluginPath(explicit) {
93157
93713
  if (explicit) {
93158
- return existsSync6(explicit) ? resolve2(explicit) : null;
93714
+ return existsSync7(explicit) ? resolve3(explicit) : null;
93159
93715
  }
93160
- const cwdCandidate = resolve2(process.cwd(), "packages/plugin-openclaw/omni.ts");
93161
- return existsSync6(cwdCandidate) ? cwdCandidate : null;
93716
+ const cwdCandidate = resolve3(process.cwd(), "packages/plugin-openclaw/omni.ts");
93717
+ return existsSync7(cwdCandidate) ? cwdCandidate : null;
93162
93718
  }
93163
93719
  function registerPlugin(config2, pluginPath, configPath) {
93164
93720
  if (hasOpenClawCli()) {
@@ -93676,8 +94232,7 @@ function createReactCommand() {
93676
94232
  const client = getClient();
93677
94233
  const ctx = await resolveContext({
93678
94234
  instance: options.instance,
93679
- chat: options.chat,
93680
- message: options.message
94235
+ chat: options.chat
93681
94236
  });
93682
94237
  if (!ctx.instanceId) {
93683
94238
  return error("No instance in context. Set OMNI_INSTANCE, use --instance, or run: omni use <instance>");
@@ -93844,34 +94399,19 @@ ${formatExamples(examples)}`);
93844
94399
  }
93845
94400
 
93846
94401
  // src/commands/restart.ts
93847
- import { join as join7 } from "path";
93848
94402
  init_config();
93849
94403
  init_output();
93850
94404
  var RESTART_HEALTH_TIMEOUT_MS = 1e4;
93851
- function buildApiRuntimeEnv2() {
93852
- const serverConfig = loadServerConfig();
93853
- const config2 = loadConfig();
93854
- return {
93855
- API_PORT: String(serverConfig.port),
93856
- DATABASE_URL: serverConfig.databaseUrl,
93857
- OMNI_API_KEY: config2.apiKey ?? "",
93858
- MEDIA_STORAGE_PATH: join7(serverConfig.dataDir, "media"),
93859
- PGSERVE_EMBEDDED: "true",
93860
- PGSERVE_DATA: join7(serverConfig.dataDir, "pgserve"),
93861
- NATS_URL: "nats://localhost:4222",
93862
- NODE_ENV: serverConfig.nodeEnv,
93863
- LOG_LEVEL: serverConfig.logLevel
93864
- };
93865
- }
93866
94405
  async function runRestart() {
93867
94406
  if (!await isPm2Available()) {
93868
94407
  pm2NotFoundError();
93869
94408
  }
93870
94409
  const serverConfig = loadServerConfig();
94410
+ const cliConfig = loadConfig();
93871
94411
  const apiPort = serverConfig.port;
93872
94412
  info("Restarting omni services...");
93873
- const env2 = buildApiRuntimeEnv2();
93874
- const code = await runPm2(["restart", PM2_PROCESSES.api, PM2_PROCESSES.nats, "--update-env"], env2);
94413
+ const env2 = buildRuntimeEnv(serverConfig, cliConfig);
94414
+ const code = await runPm2(["restart", PM2_PROCESSES.api, PM2_PROCESSES.nats], env2);
93875
94415
  if (code !== 0) {
93876
94416
  warn("Some services may not have restarted cleanly \u2014 check pm2 status");
93877
94417
  }
@@ -94038,7 +94578,7 @@ function createSayCommand() {
94038
94578
  }
94039
94579
 
94040
94580
  // src/commands/see.ts
94041
- import { existsSync as existsSync7, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
94581
+ import { existsSync as existsSync8, readFileSync as readFileSync5, statSync as statSync3 } from "fs";
94042
94582
  import { extname as extname4 } from "path";
94043
94583
  init_output();
94044
94584
  var MIME_BY_EXT = {
@@ -94070,10 +94610,10 @@ function parseMaxTokens(value) {
94070
94610
  return n2;
94071
94611
  }
94072
94612
  function loadMedia(file) {
94073
- if (!existsSync7(file)) {
94613
+ if (!existsSync8(file)) {
94074
94614
  error(`File not found: ${file}`);
94075
94615
  }
94076
- const stat = statSync2(file);
94616
+ const stat = statSync3(file);
94077
94617
  if (!stat.isFile()) {
94078
94618
  error(`Not a regular file: ${file}`);
94079
94619
  }
@@ -94156,7 +94696,7 @@ function createSeeCommand() {
94156
94696
  }
94157
94697
 
94158
94698
  // src/commands/send.ts
94159
- import { existsSync as existsSync8, readFileSync as readFileSync6 } from "fs";
94699
+ import { existsSync as existsSync9, readFileSync as readFileSync6 } from "fs";
94160
94700
  import { basename as basename5, extname as extname5 } from "path";
94161
94701
  init_source();
94162
94702
  init_config();
@@ -94197,7 +94737,7 @@ var messageSenders = {
94197
94737
  const { to, media } = options3;
94198
94738
  if (!to || !media)
94199
94739
  return;
94200
- if (!existsSync8(media)) {
94740
+ if (!existsSync9(media)) {
94201
94741
  error(`File not found: ${media}`);
94202
94742
  return;
94203
94743
  }
@@ -94729,50 +95269,35 @@ function pickFilename(mimeType, provider) {
94729
95269
  }
94730
95270
 
94731
95271
  // src/commands/start.ts
94732
- import { existsSync as existsSync9, mkdirSync as mkdirSync5 } from "fs";
94733
- import { homedir as homedir5 } from "os";
94734
- import { join as join8 } from "path";
95272
+ import { existsSync as existsSync10, mkdirSync as mkdirSync5 } from "fs";
95273
+ import { homedir as homedir6 } from "os";
95274
+ import { join as join9 } from "path";
94735
95275
  init_config();
94736
95276
  init_output();
94737
95277
  var START_HEALTH_TIMEOUT_MS = 1e4;
94738
- function buildApiRuntimeEnv3() {
94739
- const serverConfig = loadServerConfig();
94740
- const config2 = loadConfig();
94741
- return {
94742
- API_PORT: String(serverConfig.port),
94743
- DATABASE_URL: serverConfig.databaseUrl,
94744
- OMNI_API_KEY: config2.apiKey ?? "",
94745
- MEDIA_STORAGE_PATH: join8(serverConfig.dataDir, "media"),
94746
- OMNI_PACKAGES_DIR: join8(serverConfig.dataDir, "packages"),
94747
- PGSERVE_EMBEDDED: "true",
94748
- PGSERVE_DATA: join8(serverConfig.dataDir, "pgserve"),
94749
- NATS_URL: "nats://localhost:4222",
94750
- NODE_ENV: serverConfig.nodeEnv,
94751
- LOG_LEVEL: serverConfig.logLevel
94752
- };
94753
- }
94754
95278
  async function runStart() {
94755
95279
  if (!await isPm2Available()) {
94756
95280
  pm2NotFoundError();
94757
95281
  }
94758
95282
  const bundlePath = getServerBundlePath();
94759
- if (!existsSync9(bundlePath)) {
95283
+ if (!existsSync10(bundlePath)) {
94760
95284
  bundleNotFoundError(bundlePath);
94761
95285
  }
94762
95286
  const serverConfig = loadServerConfig();
94763
95287
  const apiPort = serverConfig.port;
94764
95288
  info(`Starting ${PM2_PROCESSES.api} (port ${apiPort})...`);
94765
- const env2 = buildApiRuntimeEnv3();
95289
+ const cliConfig = loadConfig();
95290
+ const env2 = buildRuntimeEnv(serverConfig, cliConfig);
94766
95291
  const launcherPath = getServerLauncherPath();
94767
95292
  const apiCode = await runPm2(["start", launcherPath, "--name", PM2_PROCESSES.api, "--interpreter", "bash"], env2);
94768
95293
  if (apiCode !== 0) {
94769
95294
  error(`Failed to start ${PM2_PROCESSES.api} (pm2 exit code ${apiCode})`, undefined, 1);
94770
95295
  return;
94771
95296
  }
94772
- const natsPath = join8(homedir5(), ".omni", "nats-server");
94773
- if (existsSync9(natsPath)) {
95297
+ const natsPath = join9(homedir6(), ".omni", "nats-server");
95298
+ if (existsSync10(natsPath)) {
94774
95299
  info(`Starting ${PM2_PROCESSES.nats}...`);
94775
- const natsDataDir = join8(serverConfig.dataDir, "nats");
95300
+ const natsDataDir = join9(serverConfig.dataDir, "nats");
94776
95301
  mkdirSync5(natsDataDir, { recursive: true });
94777
95302
  const natsCode = await runPm2(["start", natsPath, "--name", PM2_PROCESSES.nats, "--", "-js", "-sd", natsDataDir]);
94778
95303
  if (natsCode !== 0) {
@@ -94968,10 +95493,193 @@ function createTtsCommand() {
94968
95493
 
94969
95494
  // src/commands/update.ts
94970
95495
  import { createInterface as createInterface4 } from "readline";
95496
+ init_source();
94971
95497
  init_config();
94972
95498
  init_output();
95499
+
95500
+ // src/sidecar-cleanup.ts
95501
+ var SIDECAR_BASENAME = "nats-reply-sidecar.mjs";
95502
+ var SIDECAR_NAME_HINT = "nats-reply-sidecar";
95503
+ function pm2EntryToMatch(entry) {
95504
+ if (!entry || typeof entry !== "object")
95505
+ return null;
95506
+ const name = typeof entry.name === "string" ? entry.name : "";
95507
+ const scriptPath = typeof entry.pm2_env?.pm_exec_path === "string" ? entry.pm2_env.pm_exec_path : "";
95508
+ const pmId = typeof entry.pm_id === "number" ? entry.pm_id : null;
95509
+ const nameMatch = name.includes(SIDECAR_NAME_HINT);
95510
+ const pathMatch = scriptPath.endsWith(`/${SIDECAR_BASENAME}`) || scriptPath.endsWith(SIDECAR_BASENAME);
95511
+ if (!nameMatch && !pathMatch)
95512
+ return null;
95513
+ return {
95514
+ name,
95515
+ pmId,
95516
+ scriptPath,
95517
+ matchedBy: nameMatch ? "name" : "script-path"
95518
+ };
95519
+ }
95520
+ function parsePm2SidecarMatches(rawJson) {
95521
+ const trimmed = rawJson.trim();
95522
+ if (trimmed.length === 0 || trimmed === "[]")
95523
+ return [];
95524
+ let parsed;
95525
+ try {
95526
+ parsed = JSON.parse(trimmed);
95527
+ } catch {
95528
+ return [];
95529
+ }
95530
+ if (!Array.isArray(parsed))
95531
+ return [];
95532
+ const matches = [];
95533
+ for (const entry of parsed) {
95534
+ const match = pm2EntryToMatch(entry);
95535
+ if (match !== null)
95536
+ matches.push(match);
95537
+ }
95538
+ return matches;
95539
+ }
95540
+ function parseRawSidecarMatches(rawPgrep) {
95541
+ const lines = rawPgrep.split(`
95542
+ `);
95543
+ const matches = [];
95544
+ for (const line of lines) {
95545
+ const trimmed = line.trim();
95546
+ if (trimmed.length === 0)
95547
+ continue;
95548
+ const firstSpace = trimmed.indexOf(" ");
95549
+ if (firstSpace === -1)
95550
+ continue;
95551
+ const pidStr = trimmed.slice(0, firstSpace);
95552
+ const command = trimmed.slice(firstSpace + 1);
95553
+ const pid = Number.parseInt(pidStr, 10);
95554
+ if (!Number.isFinite(pid) || pid <= 0)
95555
+ continue;
95556
+ if (!command.includes(SIDECAR_BASENAME))
95557
+ continue;
95558
+ matches.push({ pid, command });
95559
+ }
95560
+ return matches;
95561
+ }
95562
+ async function detectPm2Sidecars() {
95563
+ try {
95564
+ const proc = Bun.spawn({
95565
+ cmd: ["pm2", "jlist"],
95566
+ stdout: "pipe",
95567
+ stderr: "pipe"
95568
+ });
95569
+ const [stdout, exitCode] = await Promise.all([new Response(proc.stdout).text(), proc.exited]);
95570
+ if (exitCode !== 0)
95571
+ return [];
95572
+ return parsePm2SidecarMatches(stdout);
95573
+ } catch {
95574
+ return [];
95575
+ }
95576
+ }
95577
+ async function detectRawSidecars() {
95578
+ try {
95579
+ const proc = Bun.spawn({
95580
+ cmd: ["pgrep", "-fa", SIDECAR_BASENAME],
95581
+ stdout: "pipe",
95582
+ stderr: "pipe"
95583
+ });
95584
+ const [stdout, exitCode] = await Promise.all([new Response(proc.stdout).text(), proc.exited]);
95585
+ if (exitCode !== 0 && exitCode !== 1)
95586
+ return [];
95587
+ const matches = parseRawSidecarMatches(stdout);
95588
+ const ownPid = process.pid;
95589
+ return matches.filter((m2) => m2.pid !== ownPid);
95590
+ } catch {
95591
+ return [];
95592
+ }
95593
+ }
95594
+ async function stopPm2Sidecar(match) {
95595
+ const target = match.name.length > 0 ? match.name : match.pmId !== null ? String(match.pmId) : null;
95596
+ if (target === null)
95597
+ return false;
95598
+ for (const verb of ["stop", "delete"]) {
95599
+ const proc = Bun.spawn({
95600
+ cmd: ["pm2", verb, target],
95601
+ stdout: "pipe",
95602
+ stderr: "pipe"
95603
+ });
95604
+ const exitCode = await proc.exited;
95605
+ if (exitCode !== 0)
95606
+ return false;
95607
+ }
95608
+ return true;
95609
+ }
95610
+ async function killRawSidecar(match) {
95611
+ try {
95612
+ process.kill(match.pid, "SIGTERM");
95613
+ return true;
95614
+ } catch {
95615
+ return false;
95616
+ }
95617
+ }
95618
+ async function cleanupSidecars() {
95619
+ const [pm2Detected, rawDetected] = await Promise.all([detectPm2Sidecars(), detectRawSidecars()]);
95620
+ const pm2Stopped = [];
95621
+ const pm2Failed = [];
95622
+ for (const match of pm2Detected) {
95623
+ const ok = await stopPm2Sidecar(match);
95624
+ if (ok) {
95625
+ pm2Stopped.push(match);
95626
+ } else {
95627
+ pm2Failed.push(match);
95628
+ }
95629
+ }
95630
+ const rawKilled = [];
95631
+ const rawFailed = [];
95632
+ for (const match of rawDetected) {
95633
+ const ok = await killRawSidecar(match);
95634
+ if (ok) {
95635
+ rawKilled.push(match);
95636
+ } else {
95637
+ rawFailed.push(match);
95638
+ }
95639
+ }
95640
+ return {
95641
+ pm2Detected,
95642
+ rawDetected,
95643
+ pm2Stopped,
95644
+ pm2Failed,
95645
+ rawKilled,
95646
+ rawFailed
95647
+ };
95648
+ }
95649
+ function formatCleanupSummary(result) {
95650
+ const totalDetected = result.pm2Detected.length + result.rawDetected.length;
95651
+ if (totalDetected === 0)
95652
+ return "";
95653
+ const lines = [];
95654
+ lines.push(`Found ${totalDetected} legacy nats-reply-sidecar process(es) \u2014 stopping to prevent duplicate replies.`);
95655
+ for (const match of result.pm2Stopped) {
95656
+ const label = match.name || `pm_id=${match.pmId}`;
95657
+ lines.push(` \u2713 pm2: stopped and deleted "${label}" (matched by ${match.matchedBy})`);
95658
+ }
95659
+ for (const match of result.pm2Failed) {
95660
+ const label = match.name || `pm_id=${match.pmId}`;
95661
+ lines.push(` \u2717 pm2: failed to stop "${label}" \u2014 run \`pm2 stop ${label} && pm2 delete ${label}\` manually`);
95662
+ }
95663
+ for (const match of result.rawKilled) {
95664
+ lines.push(` \u2713 raw: SIGTERM sent to pid ${match.pid}`);
95665
+ }
95666
+ for (const match of result.rawFailed) {
95667
+ lines.push(` \u2717 raw: failed to signal pid ${match.pid} \u2014 kill it manually with \`kill ${match.pid}\``);
95668
+ }
95669
+ if (result.pm2Failed.length > 0 || result.rawFailed.length > 0) {
95670
+ lines.push("See docs/migration/nats-genie-sidecar-decommission.md for the manual cleanup runbook.");
95671
+ }
95672
+ return lines.join(`
95673
+ `);
95674
+ }
95675
+ function cleanupSucceeded(result) {
95676
+ return result.pm2Failed.length === 0 && result.rawFailed.length === 0;
95677
+ }
95678
+
95679
+ // src/commands/update.ts
94973
95680
  var PACKAGE_NAME = "@automagik/omni";
94974
95681
  var UPDATE_HEALTH_TIMEOUT_MS = 1e4;
95682
+ var VERIFY_POLL_INTERVAL_MS = 500;
94975
95683
  async function fetchLatestVersion() {
94976
95684
  try {
94977
95685
  const proc = Bun.spawn({
@@ -95028,12 +95736,16 @@ async function installLatest() {
95028
95736
  return exitCode === 0;
95029
95737
  }
95030
95738
  async function restartPm2Services(processNames) {
95739
+ const serverConfig = loadServerConfig();
95740
+ const cliConfig = loadConfig();
95741
+ const runtimeEnv = buildRuntimeEnv(serverConfig, cliConfig);
95031
95742
  let allSucceeded = true;
95032
95743
  for (const name of processNames) {
95033
95744
  const proc = Bun.spawn({
95034
95745
  cmd: ["pm2", "restart", name],
95035
95746
  stdout: "pipe",
95036
- stderr: "pipe"
95747
+ stderr: "pipe",
95748
+ env: { ...process.env, ...runtimeEnv }
95037
95749
  });
95038
95750
  const exitCode = await proc.exited;
95039
95751
  if (exitCode !== 0) {
@@ -95042,34 +95754,123 @@ async function restartPm2Services(processNames) {
95042
95754
  }
95043
95755
  return allSucceeded;
95044
95756
  }
95045
- async function restartServicesAndVerify(servicesToRestart, latest) {
95757
+ function normalizeVersion(version) {
95758
+ return version.split("+")[0] ?? version;
95759
+ }
95760
+ function decideUpdateVerify(args) {
95761
+ const cliVersion = normalizeVersion(args.latest);
95762
+ if (args.healthBody === null) {
95763
+ return { kind: "health-unreachable", apiPort: args.apiPort };
95764
+ }
95765
+ const serverVersion = args.healthBody.version ? normalizeVersion(args.healthBody.version) : null;
95766
+ if (!serverVersion || serverVersion !== cliVersion) {
95767
+ return { kind: "version-mismatch", cliVersion, serverVersion };
95768
+ }
95769
+ if (!args.keyValid) {
95770
+ return { kind: "auth-invalid" };
95771
+ }
95772
+ return { kind: "ok", cliVersion, serverVersion };
95773
+ }
95774
+ function updateErrorVersionMismatch(cli, server) {
95775
+ return `Server version mismatch: cli=v${cli} server=v${server ?? "unknown"}. Run: omni doctor`;
95776
+ }
95777
+ var UPDATE_ERROR_AUTH_INVALID = "Auth key invalid after restart. Run: omni doctor --fix";
95778
+ async function fetchHealthBody(apiPort, timeoutMs) {
95779
+ const url = getHealthCheckUrl(apiPort);
95780
+ const deadline = Date.now() + timeoutMs;
95781
+ while (Date.now() < deadline) {
95782
+ try {
95783
+ const resp = await fetch(url, {
95784
+ signal: AbortSignal.timeout(1500),
95785
+ headers: { "Accept-Encoding": "identity" }
95786
+ });
95787
+ if (resp.ok) {
95788
+ const body = await resp.json();
95789
+ return body;
95790
+ }
95791
+ } catch {}
95792
+ await Bun.sleep(VERIFY_POLL_INTERVAL_MS);
95793
+ }
95794
+ return null;
95795
+ }
95796
+ async function validateStoredKey(apiPort) {
95797
+ const cliConfig = loadConfig();
95798
+ if (!cliConfig.apiKey) {
95799
+ return false;
95800
+ }
95801
+ const baseUrl = cliConfig.apiUrl ?? `http://localhost:${apiPort}`;
95802
+ try {
95803
+ const client = createOmniClient({ baseUrl, apiKey: cliConfig.apiKey, cliVersion: VERSION });
95804
+ const result = await client.auth.validate();
95805
+ return result.valid === true;
95806
+ } catch {
95807
+ return false;
95808
+ }
95809
+ }
95810
+ function printVerifyBanner(latest) {
95811
+ console.log(`${source_default.green("\u2713")} CLI: v${latest}`);
95812
+ console.log(`${source_default.green("\u2713")} Server: v${latest} (healthy)`);
95813
+ console.log(`${source_default.green("\u2713")} Auth: key valid`);
95814
+ }
95815
+ async function runSidecarCleanup() {
95816
+ const cleanupSpinner = ora("Checking for legacy nats-reply-sidecar processes...").start();
95817
+ const result = await cleanupSidecars();
95818
+ cleanupSpinner.stop();
95819
+ const summary = formatCleanupSummary(result);
95820
+ if (summary.length > 0) {
95821
+ console.log(summary);
95822
+ }
95823
+ return result;
95824
+ }
95825
+ async function restartServicesAndVerify(servicesToRestart, latest, options3) {
95046
95826
  const apiPort = loadServerConfig().port;
95047
95827
  const restartSpinner = ora("Restarting services...").start();
95048
95828
  const restartSucceeded = await restartPm2Services(servicesToRestart);
95049
95829
  restartSpinner.stop();
95050
- const healthy = await waitForHealth(apiPort, UPDATE_HEALTH_TIMEOUT_MS);
95051
- if (restartSucceeded && healthy) {
95052
- success("Services restarted successfully.");
95053
- return;
95830
+ if (!restartSucceeded) {
95831
+ warn(`omni CLI updated to v${latest}, but one or more service restarts failed. Run \`omni status\`.`);
95832
+ process.exit(1);
95833
+ }
95834
+ let sidecarCleanupResult = null;
95835
+ if (options3.sidecarCleanup) {
95836
+ sidecarCleanupResult = await runSidecarCleanup();
95837
+ }
95838
+ const verifySpinner = ora("Verifying server version...").start();
95839
+ const healthBody = await fetchHealthBody(apiPort, UPDATE_HEALTH_TIMEOUT_MS);
95840
+ verifySpinner.stop();
95841
+ const keyValid = healthBody !== null ? await validateStoredKey(apiPort) : false;
95842
+ const result = decideUpdateVerify({ latest, apiPort, healthBody, keyValid });
95843
+ switch (result.kind) {
95844
+ case "ok":
95845
+ printVerifyBanner(result.cliVersion);
95846
+ if (sidecarCleanupResult !== null && !cleanupSucceeded(sidecarCleanupResult)) {
95847
+ warn("One or more legacy nats-reply-sidecar processes could not be stopped automatically. " + "See messages above and docs/migration/nats-genie-sidecar-decommission.md.");
95848
+ }
95849
+ return;
95850
+ case "health-unreachable":
95851
+ warn(`omni CLI updated to v${latest}, but health check failed on port ${result.apiPort}. Run \`omni status\`.`);
95852
+ process.exit(1);
95853
+ break;
95854
+ case "version-mismatch":
95855
+ console.error(`${source_default.red("\u2717")} ${updateErrorVersionMismatch(result.cliVersion, result.serverVersion)}`);
95856
+ process.exit(1);
95857
+ break;
95858
+ case "auth-invalid":
95859
+ console.error(`${source_default.red("\u2717")} ${UPDATE_ERROR_AUTH_INVALID}`);
95860
+ process.exit(1);
95861
+ break;
95054
95862
  }
95055
- const failures = [];
95056
- if (!restartSucceeded)
95057
- failures.push("one or more service restarts failed");
95058
- if (!healthy)
95059
- failures.push(`health check failed on port ${apiPort}`);
95060
- warn(`omni CLI updated to v${latest}, but ${failures.join(" and ")}. Run \`omni status\`.`);
95061
- process.exit(1);
95062
95863
  }
95063
95864
  async function promptConfirm(question) {
95064
95865
  const rl = createInterface4({
95065
95866
  input: process.stdin,
95066
95867
  output: process.stdout
95067
95868
  });
95068
- return new Promise((resolve3) => {
95869
+ return new Promise((resolve4) => {
95069
95870
  rl.question(question, (answer) => {
95070
95871
  rl.close();
95071
95872
  const trimmed = answer.trim().toLowerCase();
95072
- resolve3(trimmed === "" || trimmed === "y" || trimmed === "yes");
95873
+ resolve4(trimmed === "" || trimmed === "y" || trimmed === "yes");
95073
95874
  });
95074
95875
  });
95075
95876
  }
@@ -95103,18 +95904,37 @@ async function runUpdate(options3) {
95103
95904
  process.exit(1);
95104
95905
  }
95105
95906
  if (servicesToRestart.length > 0) {
95106
- await restartServicesAndVerify(servicesToRestart, latest);
95907
+ await restartServicesAndVerify(servicesToRestart, latest, {
95908
+ sidecarCleanup: options3.sidecarCleanup !== false
95909
+ });
95910
+ return;
95107
95911
  }
95108
95912
  success(`omni updated to v${latest}`);
95109
95913
  }
95110
95914
  function createUpdateCommand() {
95111
- return new Command("update").description(`Update ${PACKAGE_NAME} to the latest version (restart only services already running)`).option("-y, --yes", "Skip confirmation prompts (non-interactive)").option("--no-restart", "Update CLI only; skip service restarts and API health check on configured API port").addHelpText("after", `
95915
+ return new Command("update").description(`Update ${PACKAGE_NAME} to the latest version (restart only services already running)`).option("-y, --yes", "Skip confirmation prompts (non-interactive)").option("--no-restart", "Update CLI only; skip service restarts and verification").option("--no-sidecar-cleanup", "Skip the legacy nats-reply-sidecar.mjs cleanup step").addHelpText("after", `
95112
95916
  Behavior:
95113
95917
  - Installs the latest CLI package first.
95114
95918
  - Restarts tracked Omni services only when they were online before the update.
95115
- - When that restart path runs, update checks API health on the configured API port.
95116
- - Use --no-restart to skip restart and API health-check steps.
95117
- - Exits non-zero if install succeeds but restart or API health check fails in that restart path.
95919
+ - When that restart path runs, update performs 3-step verification:
95920
+ 1. Server version matches the new CLI version (via /api/v2/health).
95921
+ 2. Stored CLI API key still validates against the server.
95922
+ 3. On success, prints:
95923
+ \u2713 CLI: v<latest>
95924
+ \u2713 Server: v<latest> (healthy)
95925
+ \u2713 Auth: key valid
95926
+ - On mismatch, exits non-zero with:
95927
+ "Server version mismatch: cli=v<X> server=v<Y>. Run: omni doctor"
95928
+ - On auth failure, exits non-zero with:
95929
+ "Auth key invalid after restart. Run: omni doctor --fix"
95930
+ - After a successful restart, scans for any legacy nats-reply-sidecar.mjs
95931
+ process (PM2-managed or raw) and stops it. The sidecar was an external
95932
+ workaround for bugs that were fixed in #362; leaving it running causes
95933
+ every agent reply to be delivered twice. Skippable with
95934
+ --no-sidecar-cleanup. Manual runbook:
95935
+ docs/migration/nats-genie-sidecar-decommission.md
95936
+ - Use --no-restart to skip restart + verification entirely. --no-restart
95937
+ also skips sidecar cleanup; manage the sidecar manually.
95118
95938
  - Verify runtime health after update with: omni status
95119
95939
  `).action(runUpdate);
95120
95940
  }
@@ -95505,6 +96325,12 @@ var COMMANDS = [
95505
96325
  helpGroup: "Core",
95506
96326
  helpDescription: "Describe an image or video via Gemini Vision (verb command)"
95507
96327
  },
96328
+ {
96329
+ create: createHistoryCommand,
96330
+ category: "core",
96331
+ helpGroup: "Core",
96332
+ helpDescription: "Show recent messages in the open chat (verb command)"
96333
+ },
95508
96334
  { create: createChatsCommand, category: "core", helpGroup: "Core", helpDescription: "List and manage conversations" },
95509
96335
  {
95510
96336
  create: createMessagesCommand,
@@ -95655,6 +96481,12 @@ var COMMANDS = [
95655
96481
  helpGroup: "System",
95656
96482
  helpDescription: "Interactive setup wizard (bootstrap Omni server)"
95657
96483
  },
96484
+ {
96485
+ create: createDoctorCommand,
96486
+ category: "standard",
96487
+ helpGroup: "System",
96488
+ helpDescription: "Diagnose and repair the embedded omni runtime"
96489
+ },
95658
96490
  {
95659
96491
  create: createMediaCommand,
95660
96492
  category: "standard",