@automagik/omni 2.260501.2 → 2.260501.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/server/index.js +187 -75
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -114177,7 +114177,7 @@ import { fileURLToPath } from "url";
|
|
|
114177
114177
|
// package.json
|
|
114178
114178
|
var package_default = {
|
|
114179
114179
|
name: "@automagik/omni",
|
|
114180
|
-
version: "2.260501.
|
|
114180
|
+
version: "2.260501.3",
|
|
114181
114181
|
description: "LLM-optimized CLI for Omni",
|
|
114182
114182
|
type: "module",
|
|
114183
114183
|
bin: {
|
package/dist/server/index.js
CHANGED
|
@@ -224654,7 +224654,7 @@ var init_sentry_scrub = __esm(() => {
|
|
|
224654
224654
|
var require_package8 = __commonJS((exports, module) => {
|
|
224655
224655
|
module.exports = {
|
|
224656
224656
|
name: "@omni/api",
|
|
224657
|
-
version: "2.260501.
|
|
224657
|
+
version: "2.260501.3",
|
|
224658
224658
|
type: "module",
|
|
224659
224659
|
exports: {
|
|
224660
224660
|
".": {
|
|
@@ -233824,7 +233824,7 @@ var init_src5 = __esm(() => {
|
|
|
233824
233824
|
init_schema2();
|
|
233825
233825
|
});
|
|
233826
233826
|
|
|
233827
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
233827
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/postgres.js
|
|
233828
233828
|
import { EventEmitter as EventEmitter4 } from "events";
|
|
233829
233829
|
import os6 from "os";
|
|
233830
233830
|
import path2 from "path";
|
|
@@ -234797,7 +234797,7 @@ Output: ${startupOutput}`));
|
|
|
234797
234797
|
};
|
|
234798
234798
|
});
|
|
234799
234799
|
|
|
234800
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
234800
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/logger.js
|
|
234801
234801
|
function formatTime2() {
|
|
234802
234802
|
const now = new Date;
|
|
234803
234803
|
return `${String(now.getHours()).padStart(2, "0")}:${String(now.getMinutes()).padStart(2, "0")}:${String(now.getSeconds()).padStart(2, "0")}`;
|
|
@@ -234861,7 +234861,7 @@ var init_logger4 = __esm(() => {
|
|
|
234861
234861
|
LEVELS = { debug: 10, info: 20, warn: 30, error: 40 };
|
|
234862
234862
|
});
|
|
234863
234863
|
|
|
234864
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
234864
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/sync.js
|
|
234865
234865
|
var {SQL: SQL2 } = globalThis.Bun;
|
|
234866
234866
|
function matchesPattern2(dbName, patterns) {
|
|
234867
234867
|
if (!patterns || patterns.length === 0)
|
|
@@ -235078,7 +235078,7 @@ var init_sync = __esm(() => {
|
|
|
235078
235078
|
init_logger4();
|
|
235079
235079
|
});
|
|
235080
235080
|
|
|
235081
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
235081
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/pg-wire.js
|
|
235082
235082
|
import { createHash as createHash7 } from "crypto";
|
|
235083
235083
|
|
|
235084
235084
|
class PgWireClient {
|
|
@@ -235650,7 +235650,7 @@ var init_pg_wire = __esm(() => {
|
|
|
235650
235650
|
};
|
|
235651
235651
|
});
|
|
235652
235652
|
|
|
235653
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
235653
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/restore.js
|
|
235654
235654
|
function matchesPattern3(dbName, patterns) {
|
|
235655
235655
|
if (!patterns || patterns.length === 0)
|
|
235656
235656
|
return true;
|
|
@@ -236003,7 +236003,7 @@ var init_restore = __esm(() => {
|
|
|
236003
236003
|
init_logger4();
|
|
236004
236004
|
});
|
|
236005
236005
|
|
|
236006
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
236006
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/dashboard.js
|
|
236007
236007
|
import { readFileSync as readFileSync3 } from "fs";
|
|
236008
236008
|
import { join as join14, dirname as dirname5 } from "path";
|
|
236009
236009
|
import { fileURLToPath } from "url";
|
|
@@ -236147,7 +236147,7 @@ var init_dashboard = __esm(() => {
|
|
|
236147
236147
|
};
|
|
236148
236148
|
});
|
|
236149
236149
|
|
|
236150
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
236150
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/protocol.js
|
|
236151
236151
|
function parseStartupMessage(data, fastPath = true) {
|
|
236152
236152
|
const length = data.readInt32BE(0);
|
|
236153
236153
|
const version4 = data.readInt32BE(4);
|
|
@@ -236300,7 +236300,7 @@ function buildErrorResponse({ severity = "FATAL", sqlstate, message: message2 })
|
|
|
236300
236300
|
var PROTOCOL_VERSION_3 = 196608;
|
|
236301
236301
|
var init_protocol = () => {};
|
|
236302
236302
|
|
|
236303
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
236303
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/router.js
|
|
236304
236304
|
import fs10 from "fs";
|
|
236305
236305
|
import { EventEmitter as EventEmitter5 } from "events";
|
|
236306
236306
|
function flushPending(target, pending) {
|
|
@@ -236636,7 +236636,7 @@ var init_router = __esm(() => {
|
|
|
236636
236636
|
};
|
|
236637
236637
|
});
|
|
236638
236638
|
|
|
236639
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
236639
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/stats-collector.js
|
|
236640
236640
|
class StatsCollector {
|
|
236641
236641
|
constructor(options = {}) {
|
|
236642
236642
|
this.pgManager = options.pgManager;
|
|
@@ -236955,7 +236955,7 @@ class StatsCollector {
|
|
|
236955
236955
|
}
|
|
236956
236956
|
var CPU_SAMPLE_MIN_INTERVAL_MS = 100, PROC_DISKSTATS_MIN_FIELDS = 14;
|
|
236957
236957
|
|
|
236958
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
236958
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/stats-dashboard.js
|
|
236959
236959
|
class StatsDashboard {
|
|
236960
236960
|
constructor(options = {}) {
|
|
236961
236961
|
this.enabled = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
@@ -237219,7 +237219,7 @@ var init_stats_dashboard = __esm(() => {
|
|
|
237219
237219
|
};
|
|
237220
237220
|
});
|
|
237221
237221
|
|
|
237222
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
237222
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/audit.js
|
|
237223
237223
|
import fs11 from "fs";
|
|
237224
237224
|
import os7 from "os";
|
|
237225
237225
|
import path3 from "path";
|
|
@@ -237315,7 +237315,7 @@ var init_audit = __esm(() => {
|
|
|
237315
237315
|
});
|
|
237316
237316
|
});
|
|
237317
237317
|
|
|
237318
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
237318
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/fingerprint.js
|
|
237319
237319
|
import crypto6 from "crypto";
|
|
237320
237320
|
import { execFileSync } from "child_process";
|
|
237321
237321
|
import fs12 from "fs";
|
|
@@ -237594,7 +237594,7 @@ var init_fingerprint = __esm(() => {
|
|
|
237594
237594
|
init_audit();
|
|
237595
237595
|
});
|
|
237596
237596
|
|
|
237597
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
237597
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/tokens.js
|
|
237598
237598
|
import crypto7 from "crypto";
|
|
237599
237599
|
function mintToken() {
|
|
237600
237600
|
const id = crypto7.randomBytes(TOKEN_ID_BYTES).toString("hex");
|
|
@@ -237648,7 +237648,7 @@ var init_tokens = __esm(() => {
|
|
|
237648
237648
|
FP_RE = /^[0-9a-f]{12}$/;
|
|
237649
237649
|
});
|
|
237650
237650
|
|
|
237651
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
237651
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/control-db.js
|
|
237652
237652
|
function query(client, text3, params = [], opts = {}) {
|
|
237653
237653
|
if (client.supportsQueryOptions && opts && Object.keys(opts).length > 0) {
|
|
237654
237654
|
return client.query(text3, params, opts);
|
|
@@ -237785,7 +237785,7 @@ var init_control_db = __esm(() => {
|
|
|
237785
237785
|
init_tokens();
|
|
237786
237786
|
});
|
|
237787
237787
|
|
|
237788
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
237788
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/admin-client.js
|
|
237789
237789
|
var {SQL: SQL3 } = globalThis.Bun;
|
|
237790
237790
|
import fs13 from "fs";
|
|
237791
237791
|
import path5 from "path";
|
|
@@ -237928,7 +237928,7 @@ function removeAdminDiscovery(controlSocketDir) {
|
|
|
237928
237928
|
}
|
|
237929
237929
|
var init_admin_client = () => {};
|
|
237930
237930
|
|
|
237931
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
237931
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/tenancy.js
|
|
237932
237932
|
function sanitizeName(name) {
|
|
237933
237933
|
const raw = (typeof name === "string" ? name : "").toLowerCase();
|
|
237934
237934
|
const collapsed = raw.replace(/[^a-z0-9]+/g, "_");
|
|
@@ -237952,7 +237952,7 @@ function isFingerprintEnforcementDisabled(env2 = process.env) {
|
|
|
237952
237952
|
}
|
|
237953
237953
|
var KILL_SWITCH_ENV = "PGSERVE_DISABLE_FINGERPRINT_ENFORCEMENT", NAME_TRUNCATE = 30, MAX_DB_IDENT = 63;
|
|
237954
237954
|
|
|
237955
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
237955
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/daemon-shared.js
|
|
237956
237956
|
function flushPending2(target, pending) {
|
|
237957
237957
|
const written = target.write(pending);
|
|
237958
237958
|
if (written === pending.byteLength)
|
|
@@ -237962,7 +237962,7 @@ function flushPending2(target, pending) {
|
|
|
237962
237962
|
return pending.subarray(written);
|
|
237963
237963
|
}
|
|
237964
237964
|
|
|
237965
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
237965
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/daemon-control.js
|
|
237966
237966
|
import fs14 from "fs";
|
|
237967
237967
|
function attachControlHandlers(PgserveDaemon) {
|
|
237968
237968
|
PgserveDaemon.prototype.handleSocketOpen = handleSocketOpen;
|
|
@@ -238297,7 +238297,7 @@ var init_daemon_control = __esm(() => {
|
|
|
238297
238297
|
MAX_STARTUP_BUFFER_SIZE2 = 1024 * 1024;
|
|
238298
238298
|
});
|
|
238299
238299
|
|
|
238300
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
238300
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/daemon-tcp.js
|
|
238301
238301
|
import fs15 from "fs";
|
|
238302
238302
|
function attachTcpHandlers(PgserveDaemon) {
|
|
238303
238303
|
PgserveDaemon.prototype.bindTcpListener = bindTcpListener;
|
|
@@ -238566,7 +238566,7 @@ var init_daemon_tcp = __esm(() => {
|
|
|
238566
238566
|
MAX_STARTUP_BUFFER_SIZE3 = 1024 * 1024;
|
|
238567
238567
|
});
|
|
238568
238568
|
|
|
238569
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
238569
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/gc.js
|
|
238570
238570
|
function defaultIsProcessAlive(pid) {
|
|
238571
238571
|
if (!Number.isInteger(pid) || pid <= 0)
|
|
238572
238572
|
return false;
|
|
@@ -238782,7 +238782,7 @@ var init_gc = __esm(() => {
|
|
|
238782
238782
|
HOURLY_MS = 60 * 60 * 1000;
|
|
238783
238783
|
});
|
|
238784
238784
|
|
|
238785
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
238785
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/daemon.js
|
|
238786
238786
|
import fs16 from "fs";
|
|
238787
238787
|
import path6 from "path";
|
|
238788
238788
|
import { EventEmitter as EventEmitter6 } from "events";
|
|
@@ -239279,7 +239279,7 @@ var init_daemon = __esm(() => {
|
|
|
239279
239279
|
attachTcpHandlers(PgserveDaemon);
|
|
239280
239280
|
});
|
|
239281
239281
|
|
|
239282
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
239282
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/sdk.js
|
|
239283
239283
|
import { spawn as spawn4 } from "child_process";
|
|
239284
239284
|
import fs17 from "fs";
|
|
239285
239285
|
import path7 from "path";
|
|
@@ -239402,7 +239402,7 @@ var init_sdk4 = __esm(() => {
|
|
|
239402
239402
|
__dirname2 = path7.dirname(fileURLToPath2(import.meta.url));
|
|
239403
239403
|
});
|
|
239404
239404
|
|
|
239405
|
-
// ../../node_modules/.bun/pgserve@2.1.
|
|
239405
|
+
// ../../node_modules/.bun/pgserve@2.1.3/node_modules/pgserve/src/index.js
|
|
239406
239406
|
var exports_src2 = {};
|
|
239407
239407
|
__export(exports_src2, {
|
|
239408
239408
|
stopDaemon: () => stopDaemon,
|
|
@@ -284827,6 +284827,9 @@ function buildWhatsAppMessageContext(rawPayload, chatId, instance4, text3) {
|
|
|
284827
284827
|
}
|
|
284828
284828
|
|
|
284829
284829
|
// ../api/src/services/turn-events.ts
|
|
284830
|
+
function getTurnEventsConnection() {
|
|
284831
|
+
return nc && !nc.isClosed() ? nc : null;
|
|
284832
|
+
}
|
|
284830
284833
|
async function initTurnEvents(natsUrl) {
|
|
284831
284834
|
if (nc && !nc.isClosed())
|
|
284832
284835
|
return;
|
|
@@ -308184,6 +308187,102 @@ var init_scheduler2 = __esm(() => {
|
|
|
308184
308187
|
log111 = createLogger("scheduler:setup");
|
|
308185
308188
|
});
|
|
308186
308189
|
|
|
308190
|
+
// ../api/src/services/agent-heartbeat.ts
|
|
308191
|
+
class AgentHeartbeatConsumer {
|
|
308192
|
+
subscription = null;
|
|
308193
|
+
loop = null;
|
|
308194
|
+
start(options) {
|
|
308195
|
+
if (this.subscription)
|
|
308196
|
+
return;
|
|
308197
|
+
const { natsConnection, turnService } = options;
|
|
308198
|
+
if (natsConnection.isClosed()) {
|
|
308199
|
+
log112.warn("Cannot start agent-heartbeat: NATS connection is closed");
|
|
308200
|
+
return;
|
|
308201
|
+
}
|
|
308202
|
+
this.subscription = natsConnection.subscribe(HEARTBEAT_SUBJECT);
|
|
308203
|
+
log112.info("Agent heartbeat consumer started", { subject: HEARTBEAT_SUBJECT });
|
|
308204
|
+
const sub = this.subscription;
|
|
308205
|
+
this.loop = (async () => {
|
|
308206
|
+
for await (const msg of sub) {
|
|
308207
|
+
try {
|
|
308208
|
+
const raw2 = sc3.decode(msg.data);
|
|
308209
|
+
const parsed = parseHeartbeat(raw2);
|
|
308210
|
+
if (!parsed) {
|
|
308211
|
+
log112.warn("Discarded malformed agent heartbeat", {
|
|
308212
|
+
subject: msg.subject,
|
|
308213
|
+
raw: raw2.slice(0, 200)
|
|
308214
|
+
});
|
|
308215
|
+
continue;
|
|
308216
|
+
}
|
|
308217
|
+
turnService.recordActivity(parsed.turnId).catch((error2) => {
|
|
308218
|
+
log112.warn("recordActivity failed for heartbeat (turn likely closed)", {
|
|
308219
|
+
turnId: parsed.turnId,
|
|
308220
|
+
error: error2 instanceof Error ? error2.message : String(error2)
|
|
308221
|
+
});
|
|
308222
|
+
});
|
|
308223
|
+
log112.debug("Agent heartbeat applied", {
|
|
308224
|
+
turnId: parsed.turnId,
|
|
308225
|
+
instanceId: parsed.instanceId,
|
|
308226
|
+
chatId: parsed.chatId
|
|
308227
|
+
});
|
|
308228
|
+
} catch (error2) {
|
|
308229
|
+
log112.warn("Failed to process agent heartbeat", {
|
|
308230
|
+
subject: msg.subject,
|
|
308231
|
+
error: error2 instanceof Error ? error2.message : String(error2)
|
|
308232
|
+
});
|
|
308233
|
+
}
|
|
308234
|
+
}
|
|
308235
|
+
})();
|
|
308236
|
+
}
|
|
308237
|
+
async stop() {
|
|
308238
|
+
if (!this.subscription)
|
|
308239
|
+
return;
|
|
308240
|
+
this.subscription.unsubscribe();
|
|
308241
|
+
this.subscription = null;
|
|
308242
|
+
try {
|
|
308243
|
+
await this.loop;
|
|
308244
|
+
} catch {} finally {
|
|
308245
|
+
this.loop = null;
|
|
308246
|
+
log112.info("Agent heartbeat consumer stopped");
|
|
308247
|
+
}
|
|
308248
|
+
}
|
|
308249
|
+
}
|
|
308250
|
+
function parseHeartbeat(raw2) {
|
|
308251
|
+
let value;
|
|
308252
|
+
try {
|
|
308253
|
+
value = JSON.parse(raw2);
|
|
308254
|
+
} catch {
|
|
308255
|
+
return null;
|
|
308256
|
+
}
|
|
308257
|
+
if (!value || typeof value !== "object")
|
|
308258
|
+
return null;
|
|
308259
|
+
const obj = value;
|
|
308260
|
+
const { turnId, instanceId, chatId, timestamp: timestamp3 } = obj;
|
|
308261
|
+
if (typeof turnId !== "string" || turnId.length === 0 || typeof instanceId !== "string" || instanceId.length === 0 || typeof chatId !== "string" || chatId.length === 0 || typeof timestamp3 !== "string" || timestamp3.length === 0) {
|
|
308262
|
+
return null;
|
|
308263
|
+
}
|
|
308264
|
+
return { turnId, instanceId, chatId, timestamp: timestamp3 };
|
|
308265
|
+
}
|
|
308266
|
+
function initAgentHeartbeat(options) {
|
|
308267
|
+
if (consumer)
|
|
308268
|
+
return;
|
|
308269
|
+
consumer = new AgentHeartbeatConsumer;
|
|
308270
|
+
consumer.start(options);
|
|
308271
|
+
}
|
|
308272
|
+
async function closeAgentHeartbeat() {
|
|
308273
|
+
if (!consumer)
|
|
308274
|
+
return;
|
|
308275
|
+
await consumer.stop();
|
|
308276
|
+
consumer = null;
|
|
308277
|
+
}
|
|
308278
|
+
var import_nats8, log112, sc3, HEARTBEAT_SUBJECT = "omni.agent.heartbeat.>", consumer = null;
|
|
308279
|
+
var init_agent_heartbeat = __esm(() => {
|
|
308280
|
+
init_src();
|
|
308281
|
+
import_nats8 = __toESM(require_mod4(), 1);
|
|
308282
|
+
log112 = createLogger("agent-heartbeat");
|
|
308283
|
+
sc3 = import_nats8.StringCodec();
|
|
308284
|
+
});
|
|
308285
|
+
|
|
308187
308286
|
// ../api/src/services/turn-monitor.ts
|
|
308188
308287
|
class TurnMonitor {
|
|
308189
308288
|
deps;
|
|
@@ -308195,7 +308294,7 @@ class TurnMonitor {
|
|
|
308195
308294
|
start() {
|
|
308196
308295
|
if (this.intervalId)
|
|
308197
308296
|
return;
|
|
308198
|
-
|
|
308297
|
+
log113.info("Turn monitor started", {
|
|
308199
308298
|
pollIntervalMs: POLL_INTERVAL_MS2,
|
|
308200
308299
|
nudgeMs: NUDGE_THRESHOLD_MS,
|
|
308201
308300
|
defaultStalledMs: DEFAULT_STALLED_THRESHOLD_MS,
|
|
@@ -308207,7 +308306,7 @@ class TurnMonitor {
|
|
|
308207
308306
|
if (this.intervalId) {
|
|
308208
308307
|
clearInterval(this.intervalId);
|
|
308209
308308
|
this.intervalId = null;
|
|
308210
|
-
|
|
308309
|
+
log113.info("Turn monitor stopped");
|
|
308211
308310
|
}
|
|
308212
308311
|
}
|
|
308213
308312
|
async tick() {
|
|
@@ -308235,7 +308334,7 @@ class TurnMonitor {
|
|
|
308235
308334
|
}
|
|
308236
308335
|
}
|
|
308237
308336
|
} catch (error2) {
|
|
308238
|
-
|
|
308337
|
+
log113.error("Turn monitor tick failed", { error: String(error2) });
|
|
308239
308338
|
} finally {
|
|
308240
308339
|
this.running = false;
|
|
308241
308340
|
}
|
|
@@ -308248,13 +308347,13 @@ class TurnMonitor {
|
|
|
308248
308347
|
idleSec,
|
|
308249
308348
|
message: `Turn idle for ${idleSec}s. Are you still working?`
|
|
308250
308349
|
});
|
|
308251
|
-
|
|
308350
|
+
log113.info("Turn nudge emitted", { turnId, nudgeCount, idleSec });
|
|
308252
308351
|
}
|
|
308253
308352
|
async handleStalled(turnId, instanceId, chatId, stalledAtMs, threshold) {
|
|
308254
308353
|
await this.deps.turnService.incrementNudge(turnId);
|
|
308255
308354
|
const payload = { turnId, instanceId, chatId, stalledAtMs, threshold };
|
|
308256
308355
|
publishTurnStalled(instanceId, chatId, payload);
|
|
308257
|
-
|
|
308356
|
+
log113.warn("Turn stalled \u2014 internal event emitted (no channel message sent)", payload);
|
|
308258
308357
|
}
|
|
308259
308358
|
async handleTimeout(turnId, instanceId, chatId, idleSec, nudgeCount) {
|
|
308260
308359
|
const closed = await this.deps.turnService.close(turnId, {
|
|
@@ -308277,14 +308376,14 @@ class TurnMonitor {
|
|
|
308277
308376
|
nudgeCount,
|
|
308278
308377
|
messagesSent: closed.messagesSent
|
|
308279
308378
|
});
|
|
308280
|
-
|
|
308379
|
+
log113.info("Turn force-closed (timeout)", { turnId, duration, nudgeCount });
|
|
308281
308380
|
}
|
|
308282
308381
|
}
|
|
308283
|
-
var
|
|
308382
|
+
var log113, NUDGE_THRESHOLD_MS = 120000, DEFAULT_STALLED_THRESHOLD_MS = 600000, TIMEOUT_THRESHOLD_MS = 1800000, POLL_INTERVAL_MS2 = 1e4;
|
|
308284
308383
|
var init_turn_monitor = __esm(() => {
|
|
308285
308384
|
init_src();
|
|
308286
308385
|
init_turn_events();
|
|
308287
|
-
|
|
308386
|
+
log113 = createLogger("turn-monitor");
|
|
308288
308387
|
});
|
|
308289
308388
|
|
|
308290
308389
|
// ../api/src/utils/startup-banner.ts
|
|
@@ -308358,12 +308457,12 @@ function printStartupBanner(options) {
|
|
|
308358
308457
|
process.stdout.write(`${line3}
|
|
308359
308458
|
`);
|
|
308360
308459
|
}
|
|
308361
|
-
|
|
308460
|
+
log114.info("Server ready", { host, port, version: version4 });
|
|
308362
308461
|
}
|
|
308363
|
-
var
|
|
308462
|
+
var log114, COLORS3, BOX, ANSI_ESCAPE_PATTERN;
|
|
308364
308463
|
var init_startup_banner = __esm(() => {
|
|
308365
308464
|
init_src();
|
|
308366
|
-
|
|
308465
|
+
log114 = createLogger("api:startup");
|
|
308367
308466
|
COLORS3 = {
|
|
308368
308467
|
reset: "\x1B[0m",
|
|
308369
308468
|
dim: "\x1B[2m",
|
|
@@ -308421,7 +308520,7 @@ class VoiceStreamRegistry {
|
|
|
308421
308520
|
clients = new Map;
|
|
308422
308521
|
add(ws, client) {
|
|
308423
308522
|
this.clients.set(ws, client);
|
|
308424
|
-
|
|
308523
|
+
log115.info("Voice WS client connected", {
|
|
308425
308524
|
sessionId: client.params.sessionId,
|
|
308426
308525
|
format: client.params.format,
|
|
308427
308526
|
filterUser: client.params.filterUserId ?? "all"
|
|
@@ -308486,11 +308585,11 @@ function parseVoiceStreamParams(url) {
|
|
|
308486
308585
|
return null;
|
|
308487
308586
|
return { sessionId, apiKey, format: format === "pcm" ? "pcm" : "opus", filterUserId };
|
|
308488
308587
|
}
|
|
308489
|
-
var
|
|
308588
|
+
var log115, opusCodec = null;
|
|
308490
308589
|
var init_voice3 = __esm(() => {
|
|
308491
308590
|
init_src();
|
|
308492
308591
|
init_src3();
|
|
308493
|
-
|
|
308592
|
+
log115 = createLogger("ws:voice");
|
|
308494
308593
|
});
|
|
308495
308594
|
|
|
308496
308595
|
// ../api/src/index.ts
|
|
@@ -308684,6 +308783,8 @@ function setupShutdownHandlers(server, earlyShutdown) {
|
|
|
308684
308783
|
shutdownLog.info("Stopping turn monitor");
|
|
308685
308784
|
globalTurnMonitor.stop();
|
|
308686
308785
|
}
|
|
308786
|
+
shutdownLog.info("Stopping agent heartbeat consumer");
|
|
308787
|
+
await closeAgentHeartbeat();
|
|
308687
308788
|
shutdownLog.info("Closing turn events NATS");
|
|
308688
308789
|
await closeTurnEvents();
|
|
308689
308790
|
if (globalInstanceMonitor) {
|
|
@@ -308724,7 +308825,7 @@ async function resolveCallAgentChatIds(services, ctx) {
|
|
|
308724
308825
|
senderId: ctx.senderId === ctx.chatId ? chat2.externalId : ctx.senderId
|
|
308725
308826
|
};
|
|
308726
308827
|
} catch {
|
|
308727
|
-
|
|
308828
|
+
log116.warn("call_agent: chat UUID not resolvable, using raw value (session may diverge)", {
|
|
308728
308829
|
chatId: ctx.chatId,
|
|
308729
308830
|
instanceId: ctx.instanceId
|
|
308730
308831
|
});
|
|
@@ -308733,23 +308834,23 @@ async function resolveCallAgentChatIds(services, ctx) {
|
|
|
308733
308834
|
}
|
|
308734
308835
|
async function setupEventBusServices(eventBus, services, db3) {
|
|
308735
308836
|
if (!eventBus) {
|
|
308736
|
-
|
|
308837
|
+
log116.warn("Skipping event bus services (no event bus)");
|
|
308737
308838
|
return;
|
|
308738
308839
|
}
|
|
308739
308840
|
try {
|
|
308740
308841
|
await setupMessagePersistence(eventBus, services);
|
|
308741
308842
|
} catch (error2) {
|
|
308742
|
-
|
|
308843
|
+
log116.error("Failed to set up message persistence", { error: String(error2) });
|
|
308743
308844
|
}
|
|
308744
308845
|
try {
|
|
308745
308846
|
await setupMediaProcessor(eventBus, db3, services);
|
|
308746
308847
|
} catch (error2) {
|
|
308747
|
-
|
|
308848
|
+
log116.error("Failed to set up media processor", { error: String(error2) });
|
|
308748
308849
|
}
|
|
308749
308850
|
try {
|
|
308750
308851
|
globalDispatcherCleanup = await setupAgentResponder(eventBus, services, db3);
|
|
308751
308852
|
} catch (error2) {
|
|
308752
|
-
|
|
308853
|
+
log116.error("Failed to set up agent dispatcher", { error: String(error2) });
|
|
308753
308854
|
}
|
|
308754
308855
|
try {
|
|
308755
308856
|
await services.automations.startEngine({
|
|
@@ -308825,34 +308926,44 @@ async function setupEventBusServices(eventBus, services, db3) {
|
|
|
308825
308926
|
}
|
|
308826
308927
|
});
|
|
308827
308928
|
} catch (error2) {
|
|
308828
|
-
|
|
308929
|
+
log116.error("Failed to start automation engine", { error: String(error2) });
|
|
308829
308930
|
}
|
|
308830
308931
|
try {
|
|
308831
308932
|
await setupSessionCleaner(eventBus, services, db3);
|
|
308832
308933
|
} catch (error2) {
|
|
308833
|
-
|
|
308934
|
+
log116.error("Failed to set up session cleaner", { error: String(error2) });
|
|
308834
308935
|
}
|
|
308835
308936
|
try {
|
|
308836
308937
|
await setupFollowUpHooks(eventBus, services);
|
|
308837
308938
|
} catch (error2) {
|
|
308838
|
-
|
|
308939
|
+
log116.error("Failed to set up follow-up hooks", { error: String(error2) });
|
|
308839
308940
|
}
|
|
308840
308941
|
if (globalChannelRegistry) {
|
|
308841
308942
|
try {
|
|
308842
308943
|
await setupSyncWorker(eventBus, services, globalChannelRegistry, db3);
|
|
308843
308944
|
} catch (error2) {
|
|
308844
|
-
|
|
308945
|
+
log116.error("Failed to set up sync worker", { error: String(error2) });
|
|
308845
308946
|
}
|
|
308846
308947
|
}
|
|
308847
308948
|
try {
|
|
308848
308949
|
await setupHistoryPushTracker(eventBus, services);
|
|
308849
308950
|
} catch (error2) {
|
|
308850
|
-
|
|
308951
|
+
log116.error("Failed to set up history-push tracker", { error: String(error2) });
|
|
308851
308952
|
}
|
|
308852
308953
|
try {
|
|
308853
308954
|
await initTurnEvents(NATS_URL);
|
|
308854
308955
|
} catch (error2) {
|
|
308855
|
-
|
|
308956
|
+
log116.error("Failed to initialize turn events", { error: String(error2) });
|
|
308957
|
+
}
|
|
308958
|
+
try {
|
|
308959
|
+
const turnEventsConn = getTurnEventsConnection();
|
|
308960
|
+
if (turnEventsConn) {
|
|
308961
|
+
initAgentHeartbeat({ natsConnection: turnEventsConn, turnService: services.turns });
|
|
308962
|
+
} else {
|
|
308963
|
+
log116.warn("Skipping agent heartbeat consumer: no NATS connection");
|
|
308964
|
+
}
|
|
308965
|
+
} catch (error2) {
|
|
308966
|
+
log116.error("Failed to initialize agent heartbeat consumer", { error: String(error2) });
|
|
308856
308967
|
}
|
|
308857
308968
|
try {
|
|
308858
308969
|
globalTurnMonitor = new TurnMonitor({
|
|
@@ -308860,42 +308971,42 @@ async function setupEventBusServices(eventBus, services, db3) {
|
|
|
308860
308971
|
instanceService: services.instances
|
|
308861
308972
|
});
|
|
308862
308973
|
globalTurnMonitor.start();
|
|
308863
|
-
|
|
308974
|
+
log116.info("Turn monitor started");
|
|
308864
308975
|
} catch (error2) {
|
|
308865
|
-
|
|
308976
|
+
log116.error("Failed to start turn monitor", { error: String(error2) });
|
|
308866
308977
|
}
|
|
308867
308978
|
}
|
|
308868
308979
|
async function waitForDatabaseReady(db3, maxAttempts = 30) {
|
|
308869
|
-
|
|
308980
|
+
log116.info("Waiting for database readiness");
|
|
308870
308981
|
for (let attempt = 1;attempt <= maxAttempts; attempt++) {
|
|
308871
308982
|
try {
|
|
308872
308983
|
await db3.execute(sql`SELECT 1`);
|
|
308873
|
-
|
|
308984
|
+
log116.info("Database ready", { attempt });
|
|
308874
308985
|
return;
|
|
308875
308986
|
} catch {
|
|
308876
308987
|
if (attempt === maxAttempts) {
|
|
308877
308988
|
throw new Error(`Database not ready after ${maxAttempts} attempts`);
|
|
308878
308989
|
}
|
|
308879
|
-
|
|
308990
|
+
log116.warn("Database not ready, retrying...", { attempt });
|
|
308880
308991
|
await new Promise((resolve4) => setTimeout(resolve4, 1000));
|
|
308881
308992
|
}
|
|
308882
308993
|
}
|
|
308883
308994
|
}
|
|
308884
308995
|
async function main() {
|
|
308885
|
-
|
|
308996
|
+
log116.info("Starting Omni API v2");
|
|
308886
308997
|
enableDefaultMetrics();
|
|
308887
308998
|
const pgserveConfig = resolvePgserveConfig();
|
|
308888
308999
|
const databaseUrl = await startEmbeddedPgserve(pgserveConfig);
|
|
308889
|
-
|
|
309000
|
+
log116.info("Connecting to database");
|
|
308890
309001
|
const db3 = createDb({ url: databaseUrl });
|
|
308891
309002
|
globalDbRef = db3;
|
|
308892
309003
|
const earlyShutdown = async () => {
|
|
308893
|
-
|
|
309004
|
+
log116.info("Shutdown during startup \u2014 cleaning up");
|
|
308894
309005
|
try {
|
|
308895
309006
|
await closeDb();
|
|
308896
309007
|
await stopEmbeddedPgserve();
|
|
308897
309008
|
} catch (err) {
|
|
308898
|
-
|
|
309009
|
+
log116.error("Cleanup failed during early shutdown", { error: String(err) });
|
|
308899
309010
|
} finally {
|
|
308900
309011
|
process.exit(1);
|
|
308901
309012
|
}
|
|
@@ -308909,7 +309020,7 @@ async function main() {
|
|
|
308909
309020
|
await stopEmbeddedPgserve();
|
|
308910
309021
|
throw error2;
|
|
308911
309022
|
}
|
|
308912
|
-
|
|
309023
|
+
log116.info("Running database migrations");
|
|
308913
309024
|
const migrationStart = Date.now();
|
|
308914
309025
|
const MIGRATION_TIMEOUT_MS = 60000;
|
|
308915
309026
|
try {
|
|
@@ -308922,17 +309033,17 @@ async function main() {
|
|
|
308922
309033
|
await stopEmbeddedPgserve();
|
|
308923
309034
|
throw error2;
|
|
308924
309035
|
}
|
|
308925
|
-
|
|
309036
|
+
log116.info("Database migrations complete", { durationMs: Date.now() - migrationStart });
|
|
308926
309037
|
try {
|
|
308927
309038
|
const driftReport = await verifyCriticalColumns(db3, API_CRITICAL_COLUMNS);
|
|
308928
309039
|
if (!driftReport.ok) {
|
|
308929
|
-
|
|
309040
|
+
log116.error(formatDriftReport(driftReport), { drift: driftReport.drift });
|
|
308930
309041
|
await closeDb();
|
|
308931
309042
|
await stopEmbeddedPgserve();
|
|
308932
309043
|
process.exit(1);
|
|
308933
309044
|
}
|
|
308934
309045
|
} catch (error2) {
|
|
308935
|
-
|
|
309046
|
+
log116.error("Schema drift check failed", { error: String(error2) });
|
|
308936
309047
|
await closeDb();
|
|
308937
309048
|
await stopEmbeddedPgserve();
|
|
308938
309049
|
process.exit(1);
|
|
@@ -308940,12 +309051,12 @@ async function main() {
|
|
|
308940
309051
|
try {
|
|
308941
309052
|
const [countRow] = await db3.select({ count: sql`count(*)::int` }).from(instances);
|
|
308942
309053
|
const rowCount = countRow?.count ?? 0;
|
|
308943
|
-
|
|
309054
|
+
log116.info("Post-migration content snapshot", { DB_ROW_COUNT_INSTANCES: rowCount });
|
|
308944
309055
|
if (rowCount === 0 && pgserveConfig.requireExisting) {
|
|
308945
|
-
|
|
309056
|
+
log116.error("PGSERVE_REQUIRE_EXISTING=true but instances table is empty after boot \u2014 verify PGSERVE_DATA points at the correct cluster (see #412).");
|
|
308946
309057
|
}
|
|
308947
309058
|
} catch (error2) {
|
|
308948
|
-
|
|
309059
|
+
log116.warn("Failed to read instances row count (non-fatal)", { error: String(error2) });
|
|
308949
309060
|
}
|
|
308950
309061
|
const eventBus = await connectToNats(db3);
|
|
308951
309062
|
if (eventBus) {
|
|
@@ -308963,9 +309074,9 @@ async function main() {
|
|
|
308963
309074
|
try {
|
|
308964
309075
|
await services.settings.seedDefaults();
|
|
308965
309076
|
} catch (error2) {
|
|
308966
|
-
|
|
309077
|
+
log116.error("Failed to seed default settings", { error: String(error2) });
|
|
308967
309078
|
}
|
|
308968
|
-
|
|
309079
|
+
log116.info("Initializing API key");
|
|
308969
309080
|
let apiKeyInfo;
|
|
308970
309081
|
try {
|
|
308971
309082
|
const keyResult = await services.apiKeys.initializePrimaryKey();
|
|
@@ -308975,17 +309086,17 @@ async function main() {
|
|
|
308975
309086
|
isFromEnv: keyResult.isFromEnv
|
|
308976
309087
|
};
|
|
308977
309088
|
if (keyResult.isNew) {
|
|
308978
|
-
|
|
309089
|
+
log116.info("Generated new primary API key");
|
|
308979
309090
|
} else if (keyResult.isFromEnv) {
|
|
308980
|
-
|
|
309091
|
+
log116.info("Using primary API key from environment");
|
|
308981
309092
|
} else {
|
|
308982
|
-
|
|
309093
|
+
log116.info("Using existing primary API key");
|
|
308983
309094
|
}
|
|
308984
309095
|
} catch (error2) {
|
|
308985
|
-
|
|
309096
|
+
log116.error("Failed to initialize primary API key", { error: String(error2) });
|
|
308986
309097
|
}
|
|
308987
309098
|
await setupEventBusServices(eventBus, services, db3);
|
|
308988
|
-
|
|
309099
|
+
log116.info("Starting scheduler");
|
|
308989
309100
|
setupScheduler(services, globalChannelRegistry);
|
|
308990
309101
|
const server = startBunServer(app);
|
|
308991
309102
|
printStartupBanner({
|
|
@@ -308999,7 +309110,7 @@ async function main() {
|
|
|
308999
309110
|
});
|
|
309000
309111
|
setupShutdownHandlers(server, earlyShutdown);
|
|
309001
309112
|
}
|
|
309002
|
-
var import__package3,
|
|
309113
|
+
var import__package3, log116, natsLog, pluginLog, shutdownLog, PORT, HOST, NATS_URL, voiceStreamRegistry, globalEventBus = null, globalChannelRegistry = null, globalInstanceMonitor = null, globalDispatcherCleanup = null, globalTurnMonitor = null, globalDbRef = null, UUID_RE3;
|
|
309003
309114
|
var init_src8 = __esm(() => {
|
|
309004
309115
|
init_instrument2();
|
|
309005
309116
|
init_src2();
|
|
@@ -309012,6 +309123,7 @@ var init_src8 = __esm(() => {
|
|
|
309012
309123
|
init_plugins2();
|
|
309013
309124
|
init_loader2();
|
|
309014
309125
|
init_scheduler2();
|
|
309126
|
+
init_agent_heartbeat();
|
|
309015
309127
|
init_api_keys();
|
|
309016
309128
|
init_turn_events();
|
|
309017
309129
|
init_turn_monitor();
|
|
@@ -309024,7 +309136,7 @@ var init_src8 = __esm(() => {
|
|
|
309024
309136
|
level: process.env.LOG_LEVEL ?? "info",
|
|
309025
309137
|
format: process.env.LOG_FORMAT ?? "auto"
|
|
309026
309138
|
});
|
|
309027
|
-
|
|
309139
|
+
log116 = createLogger("api:startup");
|
|
309028
309140
|
natsLog = createLogger("api:nats");
|
|
309029
309141
|
pluginLog = createLogger("api:plugins");
|
|
309030
309142
|
shutdownLog = createLogger("api:shutdown");
|
|
@@ -309034,7 +309146,7 @@ var init_src8 = __esm(() => {
|
|
|
309034
309146
|
voiceStreamRegistry = new VoiceStreamRegistry;
|
|
309035
309147
|
UUID_RE3 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
309036
309148
|
main().catch((error2) => {
|
|
309037
|
-
|
|
309149
|
+
log116.error("Failed to start API server", { error: String(error2) });
|
|
309038
309150
|
process.exit(1);
|
|
309039
309151
|
});
|
|
309040
309152
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automagik/omni",
|
|
3
|
-
"version": "2.260501.
|
|
3
|
+
"version": "2.260501.3",
|
|
4
4
|
"description": "LLM-optimized CLI for Omni",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -51,15 +51,15 @@
|
|
|
51
51
|
"qrcode-terminal": "^0.12.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@omni/api": "2.260501.
|
|
55
|
-
"@omni/channel-discord": "2.260501.
|
|
56
|
-
"@omni/channel-gupshup": "2.260501.
|
|
57
|
-
"@omni/channel-sdk": "2.260501.
|
|
58
|
-
"@omni/channel-slack": "2.260501.
|
|
59
|
-
"@omni/channel-telegram": "2.260501.
|
|
60
|
-
"@omni/channel-whatsapp": "2.260501.
|
|
61
|
-
"@omni/core": "2.260501.
|
|
62
|
-
"@omni/sdk": "2.260501.
|
|
54
|
+
"@omni/api": "2.260501.2",
|
|
55
|
+
"@omni/channel-discord": "2.260501.2",
|
|
56
|
+
"@omni/channel-gupshup": "2.260501.2",
|
|
57
|
+
"@omni/channel-sdk": "2.260501.2",
|
|
58
|
+
"@omni/channel-slack": "2.260501.2",
|
|
59
|
+
"@omni/channel-telegram": "2.260501.2",
|
|
60
|
+
"@omni/channel-whatsapp": "2.260501.2",
|
|
61
|
+
"@omni/core": "2.260501.2",
|
|
62
|
+
"@omni/sdk": "2.260501.2",
|
|
63
63
|
"@types/node": "^22.10.3",
|
|
64
64
|
"@types/qrcode-terminal": "^0.12.2",
|
|
65
65
|
"typescript": "^5.7.3"
|