@automagik/omni 2.261008.2 → 2.261015.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 +1 -1
- package/dist/server/index.js +37 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -137462,7 +137462,7 @@ import { fileURLToPath } from "url";
|
|
|
137462
137462
|
// package.json
|
|
137463
137463
|
var package_default = {
|
|
137464
137464
|
name: "@automagik/omni",
|
|
137465
|
-
version: "2.
|
|
137465
|
+
version: "2.261015.1",
|
|
137466
137466
|
repository: {
|
|
137467
137467
|
type: "git",
|
|
137468
137468
|
url: "git+https://github.com/automagik-dev/omni.git",
|
package/dist/server/index.js
CHANGED
|
@@ -266444,7 +266444,7 @@ var init_sentry_scrub = __esm(() => {
|
|
|
266444
266444
|
var require_package7 = __commonJS((exports, module) => {
|
|
266445
266445
|
module.exports = {
|
|
266446
266446
|
name: "@omni/api",
|
|
266447
|
-
version: "2.
|
|
266447
|
+
version: "2.261015.1",
|
|
266448
266448
|
private: true,
|
|
266449
266449
|
type: "module",
|
|
266450
266450
|
exports: {
|
|
@@ -421658,6 +421658,7 @@ var DEFAULT_ASC_FLOW_BASE_URL = "https://sac-notredame.ascbrazil.com.br";
|
|
|
421658
421658
|
var REST_PREFIX = "/rest/v2";
|
|
421659
421659
|
var TURN_PENDING = { pronto: 0 };
|
|
421660
421660
|
var IN_FLIGHT_TTL_MS = 150000;
|
|
421661
|
+
var HANDOFF_PARKED_TTL_MS = 30 * 60000;
|
|
421661
421662
|
var UNDELIVERABLE_ERROR = "no ASC flow turn is polling this cod_atendimento \u2014 a text-only send cannot be delivered";
|
|
421662
421663
|
var HANDOFF_REFUSED_ERROR = "handoff refused: the transfer never held, so the turn answers without it";
|
|
421663
421664
|
var IN_FLIGHT_SWEEP_MS = 60000;
|
|
@@ -421958,6 +421959,10 @@ class AscFlowPlugin extends BaseChannelPlugin {
|
|
|
421958
421959
|
const cod = chatId.trim();
|
|
421959
421960
|
const entry = state.inFlight.get(cod);
|
|
421960
421961
|
if (entry?.correlationId && correlationId && entry.correlationId !== correlationId) {
|
|
421962
|
+
if (ready.hand_off === "sim") {
|
|
421963
|
+
this.carryLateHandoff(state, cod, entry, ready, "correlationId of a closed turn");
|
|
421964
|
+
return;
|
|
421965
|
+
}
|
|
421961
421966
|
this.logger.warn("[asc-flow] discarding an answer from a different turn", {
|
|
421962
421967
|
cod,
|
|
421963
421968
|
reason: "correlationId does not match the turn now in flight"
|
|
@@ -421965,6 +421970,10 @@ class AscFlowPlugin extends BaseChannelPlugin {
|
|
|
421965
421970
|
return;
|
|
421966
421971
|
}
|
|
421967
421972
|
if (entry && answering && entry !== answering) {
|
|
421973
|
+
if (ready.hand_off === "sim") {
|
|
421974
|
+
this.carryLateHandoff(state, cod, entry, ready, "the window now holds a newer turn");
|
|
421975
|
+
return;
|
|
421976
|
+
}
|
|
421968
421977
|
this.logger.warn("[asc-flow] discarding an answer whose turn already closed", {
|
|
421969
421978
|
cod,
|
|
421970
421979
|
reason: "the window now holds a newer turn \u2014 delivering this would answer the wrong message"
|
|
@@ -421987,6 +421996,18 @@ class AscFlowPlugin extends BaseChannelPlugin {
|
|
|
421987
421996
|
}
|
|
421988
421997
|
state.inFlight.set(cod, { text: "", at: Date.now(), ready });
|
|
421989
421998
|
}
|
|
421999
|
+
carryLateHandoff(state, cod, entry, ready, reason) {
|
|
422000
|
+
if (entry.ready?.hand_off === "sim") {
|
|
422001
|
+
this.logger.debug("[asc-flow] keeping the newer parked handoff over a late one", { cod, reason });
|
|
422002
|
+
return;
|
|
422003
|
+
}
|
|
422004
|
+
if (entry.ready) {
|
|
422005
|
+
this.pushDisplacedBubble(state, cod, entry.ready.resposta);
|
|
422006
|
+
}
|
|
422007
|
+
entry.ready = ready;
|
|
422008
|
+
entry.at = Date.now();
|
|
422009
|
+
this.logger.warn("[asc-flow] carrying a late handoff into the turn now in flight", { cod, reason });
|
|
422010
|
+
}
|
|
421990
422011
|
pushDisplacedBubble(state, cod, text) {
|
|
421991
422012
|
if (!text.trim())
|
|
421992
422013
|
return;
|
|
@@ -422212,7 +422233,7 @@ class AscFlowPlugin extends BaseChannelPlugin {
|
|
|
422212
422233
|
state.lastSweepAt = now;
|
|
422213
422234
|
let expired = 0;
|
|
422214
422235
|
for (const [cod, entry] of state.inFlight) {
|
|
422215
|
-
if (now - entry.at > IN_FLIGHT_TTL_MS) {
|
|
422236
|
+
if (now - entry.at > (entry.ready?.hand_off === "sim" ? HANDOFF_PARKED_TTL_MS : IN_FLIGHT_TTL_MS)) {
|
|
422216
422237
|
state.inFlight.delete(cod);
|
|
422217
422238
|
expired++;
|
|
422218
422239
|
}
|
|
@@ -422239,6 +422260,16 @@ class AscFlowPlugin extends BaseChannelPlugin {
|
|
|
422239
422260
|
const entry = state?.inFlight.get(codAtendimento);
|
|
422240
422261
|
if (!state || !entry)
|
|
422241
422262
|
return null;
|
|
422263
|
+
if (entry.ready?.hand_off === "sim" && entry.text !== text) {
|
|
422264
|
+
state.inFlight.delete(codAtendimento);
|
|
422265
|
+
this.rememberAnswered(state, codAtendimento, text);
|
|
422266
|
+
this.logger.warn("[asc-flow] delivering a parked handoff on a newer input", {
|
|
422267
|
+
instanceId,
|
|
422268
|
+
codAtendimento,
|
|
422269
|
+
ageMs: Date.now() - entry.at
|
|
422270
|
+
});
|
|
422271
|
+
return entry.ready;
|
|
422272
|
+
}
|
|
422242
422273
|
if (entry.text !== text)
|
|
422243
422274
|
return null;
|
|
422244
422275
|
const ageMs = Date.now() - entry.at;
|
|
@@ -422262,13 +422293,16 @@ class AscFlowPlugin extends BaseChannelPlugin {
|
|
|
422262
422293
|
ageMs
|
|
422263
422294
|
});
|
|
422264
422295
|
}
|
|
422296
|
+
this.rememberAnswered(state, codAtendimento, text);
|
|
422297
|
+
return entry.ready;
|
|
422298
|
+
}
|
|
422299
|
+
rememberAnswered(state, codAtendimento, text) {
|
|
422265
422300
|
if (state.lastAnswered.size >= IN_FLIGHT_MAX_ENTRIES) {
|
|
422266
422301
|
const oldest = state.lastAnswered.keys().next().value;
|
|
422267
422302
|
if (oldest !== undefined)
|
|
422268
422303
|
state.lastAnswered.delete(oldest);
|
|
422269
422304
|
}
|
|
422270
422305
|
state.lastAnswered.set(codAtendimento, text.trim());
|
|
422271
|
-
return entry.ready;
|
|
422272
422306
|
}
|
|
422273
422307
|
async isStaleFlowReplay(instanceId, turn) {
|
|
422274
422308
|
const state = this.ascFlowInstances.get(instanceId);
|