@automagik/omni 2.260508.4 → 2.260509.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/server/index.js +100 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -123990,7 +123990,7 @@ import { fileURLToPath } from "url";
|
|
|
123990
123990
|
// package.json
|
|
123991
123991
|
var package_default = {
|
|
123992
123992
|
name: "@automagik/omni",
|
|
123993
|
-
version: "2.
|
|
123993
|
+
version: "2.260509.2",
|
|
123994
123994
|
description: "LLM-optimized CLI for Omni",
|
|
123995
123995
|
type: "module",
|
|
123996
123996
|
bin: {
|
package/dist/server/index.js
CHANGED
|
@@ -230060,7 +230060,7 @@ var init_sentry_scrub = __esm(() => {
|
|
|
230060
230060
|
var require_package8 = __commonJS((exports, module) => {
|
|
230061
230061
|
module.exports = {
|
|
230062
230062
|
name: "@omni/api",
|
|
230063
|
-
version: "2.
|
|
230063
|
+
version: "2.260509.2",
|
|
230064
230064
|
type: "module",
|
|
230065
230065
|
exports: {
|
|
230066
230066
|
".": {
|
|
@@ -282861,6 +282861,42 @@ class FollowUpLifecycleService {
|
|
|
282861
282861
|
});
|
|
282862
282862
|
}
|
|
282863
282863
|
}
|
|
282864
|
+
async armForInbound(input) {
|
|
282865
|
+
if (!this.eventBus)
|
|
282866
|
+
return;
|
|
282867
|
+
if (await this.isInActiveCloseState(input.chatId, input.instanceId))
|
|
282868
|
+
return;
|
|
282869
|
+
const config4 = input.config ?? await this.resolveConfig(input.chatId, input.instanceId, input.agentId);
|
|
282870
|
+
if (!config4 || config4.enabled === false)
|
|
282871
|
+
return;
|
|
282872
|
+
if (await this.shouldRefuseForTerminalDisarm({
|
|
282873
|
+
chatId: input.chatId,
|
|
282874
|
+
instanceId: input.instanceId,
|
|
282875
|
+
lastAgentMessageAt: input.lastInboundCustomerMessageAt
|
|
282876
|
+
})) {
|
|
282877
|
+
return;
|
|
282878
|
+
}
|
|
282879
|
+
try {
|
|
282880
|
+
await armSequence({ repo: this.repo, eventBus: this.eventBus, logger: this.logger }, {
|
|
282881
|
+
chatId: input.chatId,
|
|
282882
|
+
instanceId: input.instanceId,
|
|
282883
|
+
agentId: input.agentId,
|
|
282884
|
+
config: config4,
|
|
282885
|
+
lastAgentMessageAt: input.lastInboundCustomerMessageAt
|
|
282886
|
+
});
|
|
282887
|
+
this.logger.info("follow-up lifecycle: re-armed from inbound", {
|
|
282888
|
+
chatId: input.chatId,
|
|
282889
|
+
instanceId: input.instanceId,
|
|
282890
|
+
lastInboundCustomerMessageAt: input.lastInboundCustomerMessageAt.toISOString()
|
|
282891
|
+
});
|
|
282892
|
+
} catch (err) {
|
|
282893
|
+
this.logger.error("follow-up lifecycle: armForInbound failed", {
|
|
282894
|
+
chatId: input.chatId,
|
|
282895
|
+
instanceId: input.instanceId,
|
|
282896
|
+
error: err instanceof Error ? err.message : String(err)
|
|
282897
|
+
});
|
|
282898
|
+
}
|
|
282899
|
+
}
|
|
282864
282900
|
async touchInboundTimestamp(input) {
|
|
282865
282901
|
try {
|
|
282866
282902
|
await this.db.update(chatFollowUpState).set({ lastInboundCustomerMessageAt: input.at, updatedAt: input.at }).where(and2(eq(chatFollowUpState.chatId, input.chatId), eq(chatFollowUpState.instanceId, input.instanceId)));
|
|
@@ -283021,6 +283057,7 @@ class FollowUpSweeperService {
|
|
|
283021
283057
|
logger;
|
|
283022
283058
|
repo;
|
|
283023
283059
|
messagingWindowProbe;
|
|
283060
|
+
lifecycle = null;
|
|
283024
283061
|
constructor(db2, eventBus, logger6 = log85) {
|
|
283025
283062
|
this.db = db2;
|
|
283026
283063
|
this.eventBus = eventBus;
|
|
@@ -283039,16 +283076,69 @@ class FollowUpSweeperService {
|
|
|
283039
283076
|
};
|
|
283040
283077
|
this.messagingWindowProbe = createMessagingWindowProbe();
|
|
283041
283078
|
}
|
|
283079
|
+
setLifecycle(lifecycle2) {
|
|
283080
|
+
this.lifecycle = lifecycle2;
|
|
283081
|
+
}
|
|
283042
283082
|
async sweep() {
|
|
283043
283083
|
if (!this.eventBus) {
|
|
283044
|
-
return { scanned: 0, fired: 0, disarmed: 0, skipped: 0 };
|
|
283084
|
+
return { scanned: 0, fired: 0, disarmed: 0, skipped: 0, rearmed: 0 };
|
|
283045
283085
|
}
|
|
283046
|
-
|
|
283086
|
+
const rearmed = await this.sweepStaleCustomerReplied();
|
|
283087
|
+
const fireStats = await sweepFollowUps({
|
|
283047
283088
|
repo: this.repo,
|
|
283048
283089
|
eventBus: this.eventBus,
|
|
283049
283090
|
logger: this.logger,
|
|
283050
283091
|
messagingWindowProbe: this.messagingWindowProbe
|
|
283051
283092
|
});
|
|
283093
|
+
return { ...fireStats, rearmed };
|
|
283094
|
+
}
|
|
283095
|
+
async sweepStaleCustomerReplied() {
|
|
283096
|
+
if (!this.lifecycle)
|
|
283097
|
+
return 0;
|
|
283098
|
+
const now = new Date;
|
|
283099
|
+
const minBoundary = new Date(now.getTime() - STALE_PAUSE_MAX_AGE_MS);
|
|
283100
|
+
const maxBoundary = new Date(now.getTime() - STALE_PAUSE_MIN_AGE_MS);
|
|
283101
|
+
const candidates = await this.db.transaction(async (tx) => {
|
|
283102
|
+
return tx.select({
|
|
283103
|
+
chatId: chatFollowUpState.chatId,
|
|
283104
|
+
instanceId: chatFollowUpState.instanceId,
|
|
283105
|
+
agentId: chatFollowUpState.agentId,
|
|
283106
|
+
sequenceConfig: chatFollowUpState.sequenceConfig,
|
|
283107
|
+
lastInboundCustomerMessageAt: chatFollowUpState.lastInboundCustomerMessageAt
|
|
283108
|
+
}).from(chatFollowUpState).leftJoin(chats, eq(chatFollowUpState.chatId, chats.id)).where(and2(eq(chatFollowUpState.disarmReason, "customer_replied"), gt(chatFollowUpState.lastInboundCustomerMessageAt, minBoundary), lt(chatFollowUpState.lastInboundCustomerMessageAt, maxBoundary), sql`(${chats.settings}->>'agentPaused') IS DISTINCT FROM 'true'`)).orderBy(chatFollowUpState.lastInboundCustomerMessageAt).limit(STALE_PAUSE_MAX_PER_TICK).for("update", { of: chatFollowUpState, skipLocked: true });
|
|
283109
|
+
});
|
|
283110
|
+
let rearmed = 0;
|
|
283111
|
+
for (const row of candidates) {
|
|
283112
|
+
if (!row.lastInboundCustomerMessageAt)
|
|
283113
|
+
continue;
|
|
283114
|
+
const config4 = row.sequenceConfig;
|
|
283115
|
+
if (!config4)
|
|
283116
|
+
continue;
|
|
283117
|
+
const firstIntervalMinutes = config4.schedule.kind === "fixed" ? config4.schedule.intervalsMinutes[0] : config4.schedule.initialMinutes;
|
|
283118
|
+
if (typeof firstIntervalMinutes !== "number" || firstIntervalMinutes <= 0)
|
|
283119
|
+
continue;
|
|
283120
|
+
const ageMs = now.getTime() - row.lastInboundCustomerMessageAt.getTime();
|
|
283121
|
+
if (ageMs < firstIntervalMinutes * 60000) {
|
|
283122
|
+
continue;
|
|
283123
|
+
}
|
|
283124
|
+
try {
|
|
283125
|
+
await this.lifecycle.armForInbound({
|
|
283126
|
+
chatId: row.chatId,
|
|
283127
|
+
instanceId: row.instanceId,
|
|
283128
|
+
agentId: row.agentId,
|
|
283129
|
+
config: config4,
|
|
283130
|
+
lastInboundCustomerMessageAt: row.lastInboundCustomerMessageAt
|
|
283131
|
+
});
|
|
283132
|
+
rearmed += 1;
|
|
283133
|
+
} catch (err) {
|
|
283134
|
+
this.logger.warn("follow-up sweeper: stale-pause re-arm failed for row", {
|
|
283135
|
+
chatId: row.chatId,
|
|
283136
|
+
instanceId: row.instanceId,
|
|
283137
|
+
error: err instanceof Error ? err.message : String(err)
|
|
283138
|
+
});
|
|
283139
|
+
}
|
|
283140
|
+
}
|
|
283141
|
+
return rearmed;
|
|
283052
283142
|
}
|
|
283053
283143
|
async findAndLockDue(now, limit2) {
|
|
283054
283144
|
const rows = await this.db.transaction(async (tx) => {
|
|
@@ -283107,12 +283197,13 @@ class FollowUpSweeperService {
|
|
|
283107
283197
|
}
|
|
283108
283198
|
}
|
|
283109
283199
|
}
|
|
283110
|
-
var log85;
|
|
283200
|
+
var log85, STALE_PAUSE_MAX_AGE_MS, STALE_PAUSE_MIN_AGE_MS = 60000, STALE_PAUSE_MAX_PER_TICK = 100;
|
|
283111
283201
|
var init_follow_up_sweeper = __esm(() => {
|
|
283112
283202
|
init_src();
|
|
283113
283203
|
init_src5();
|
|
283114
283204
|
init_drizzle_orm();
|
|
283115
283205
|
log85 = createLogger("follow-up-sweeper");
|
|
283206
|
+
STALE_PAUSE_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
283116
283207
|
});
|
|
283117
283208
|
|
|
283118
283209
|
// ../api/src/services/genie-hosts.ts
|
|
@@ -289269,6 +289360,9 @@ function createServices(db2, eventBus) {
|
|
|
289269
289360
|
providerRegistry.register("imagegen", "gemini", new GeminiImageGenProvider(settings));
|
|
289270
289361
|
providerRegistry.register("videogen", "gemini", new GeminiVideoGenProvider(settings));
|
|
289271
289362
|
providerRegistry.register("vision", "gemini", new GeminiVisionProvider(settings));
|
|
289363
|
+
const followUpLifecycle = new FollowUpLifecycleService(db2, eventBus);
|
|
289364
|
+
const followUpSweeper = new FollowUpSweeperService(db2, eventBus);
|
|
289365
|
+
followUpSweeper.setLifecycle(followUpLifecycle);
|
|
289272
289366
|
return {
|
|
289273
289367
|
agents: new AgentService(db2, eventBus),
|
|
289274
289368
|
agentState: new AgentStateService(eventBus),
|
|
@@ -289297,8 +289391,8 @@ function createServices(db2, eventBus) {
|
|
|
289297
289391
|
tts,
|
|
289298
289392
|
turns: new TurnService(db2),
|
|
289299
289393
|
consumerOffsets: new ConsumerOffsetService(db2),
|
|
289300
|
-
followUpLifecycle
|
|
289301
|
-
followUpSweeper
|
|
289394
|
+
followUpLifecycle,
|
|
289395
|
+
followUpSweeper,
|
|
289302
289396
|
genieHosts: new GenieHostsService(db2),
|
|
289303
289397
|
eventBus
|
|
289304
289398
|
};
|