@automagik/omni 2.260721.1 → 2.260723.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 +76 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -125191,7 +125191,7 @@ import { fileURLToPath } from "url";
|
|
|
125191
125191
|
// package.json
|
|
125192
125192
|
var package_default = {
|
|
125193
125193
|
name: "@automagik/omni",
|
|
125194
|
-
version: "2.
|
|
125194
|
+
version: "2.260723.1",
|
|
125195
125195
|
description: "LLM-optimized CLI for Omni",
|
|
125196
125196
|
type: "module",
|
|
125197
125197
|
bin: {
|
package/dist/server/index.js
CHANGED
|
@@ -227026,7 +227026,7 @@ var init_sentry_scrub = __esm(() => {
|
|
|
227026
227026
|
var require_package7 = __commonJS((exports, module) => {
|
|
227027
227027
|
module.exports = {
|
|
227028
227028
|
name: "@omni/api",
|
|
227029
|
-
version: "2.
|
|
227029
|
+
version: "2.260723.1",
|
|
227030
227030
|
type: "module",
|
|
227031
227031
|
exports: {
|
|
227032
227032
|
".": {
|
|
@@ -337987,7 +337987,15 @@ class MessageService {
|
|
|
337987
337987
|
value -= 2;
|
|
337988
337988
|
return value;
|
|
337989
337989
|
};
|
|
337990
|
-
|
|
337990
|
+
const ranked = rows.map((message2) => ({ message: message2, score: score(message2) })).sort((a, b3) => b3.score - a.score || b3.message.platformTimestamp.getTime() - a.message.platformTimestamp.getTime());
|
|
337991
|
+
const AMBIGUOUS_TIE_WINDOW_MS = 5 * 60000;
|
|
337992
|
+
const top = ranked[0];
|
|
337993
|
+
if (!top)
|
|
337994
|
+
return null;
|
|
337995
|
+
const ambiguousTie = top.score > 0 && ranked.some((entry, index2) => index2 > 0 && entry.score === top.score && Math.abs(top.message.platformTimestamp.getTime() - entry.message.platformTimestamp.getTime()) <= AMBIGUOUS_TIE_WINDOW_MS);
|
|
337996
|
+
if (ambiguousTie)
|
|
337997
|
+
return null;
|
|
337998
|
+
return top.message;
|
|
337991
337999
|
}
|
|
337992
338000
|
async getByExternalIds(chatId, externalIds) {
|
|
337993
338001
|
if (externalIds.length === 0)
|
|
@@ -369656,6 +369664,69 @@ async function handleGupshupWebhook(request, plugin3, instanceId, webhookVerifyT
|
|
|
369656
369664
|
});
|
|
369657
369665
|
return new Response("OK", { status: 200 });
|
|
369658
369666
|
}
|
|
369667
|
+
var CROSS_ID_WINDOW_MS = 60000;
|
|
369668
|
+
var FILEMANAGER_URL_RE = /^https:\/\/filemanager\.gupshup\.io\/\S+$/;
|
|
369669
|
+
var recentTextByChat = new Map;
|
|
369670
|
+
var recentMediaByChat = new Map;
|
|
369671
|
+
function pruneExpiredCrossIdEntries(now) {
|
|
369672
|
+
for (const map of [recentTextByChat, recentMediaByChat]) {
|
|
369673
|
+
for (const [key, value] of map) {
|
|
369674
|
+
if (now - value.ts > CROSS_ID_WINDOW_MS * 1.5)
|
|
369675
|
+
map.delete(key);
|
|
369676
|
+
}
|
|
369677
|
+
}
|
|
369678
|
+
}
|
|
369679
|
+
function isRelayMediaEcho(chatKey, messageId, bodyText, now) {
|
|
369680
|
+
if (!messageId.startsWith("gs-entry-") || !FILEMANAGER_URL_RE.test(bodyText))
|
|
369681
|
+
return null;
|
|
369682
|
+
const lastMedia = recentMediaByChat.get(chatKey);
|
|
369683
|
+
if (lastMedia && now - lastMedia.ts <= CROSS_ID_WINDOW_MS)
|
|
369684
|
+
return lastMedia.id;
|
|
369685
|
+
return null;
|
|
369686
|
+
}
|
|
369687
|
+
function isDuplicateTextRedelivery(chatKey, messageId, bodyText, now) {
|
|
369688
|
+
const normalized = bodyText.toLowerCase().replace(/\s+/g, " ");
|
|
369689
|
+
if (normalized.length <= 3)
|
|
369690
|
+
return null;
|
|
369691
|
+
const textKey = `${chatKey}:${normalized}`;
|
|
369692
|
+
const prev = recentTextByChat.get(textKey);
|
|
369693
|
+
if (prev && prev.id !== messageId && now - prev.ts <= CROSS_ID_WINDOW_MS)
|
|
369694
|
+
return prev.id;
|
|
369695
|
+
if (!prev || prev.id === messageId)
|
|
369696
|
+
recentTextByChat.set(textKey, { ts: now, id: messageId });
|
|
369697
|
+
return null;
|
|
369698
|
+
}
|
|
369699
|
+
function isCrossIdDuplicate(instanceId, msg, from, logger5) {
|
|
369700
|
+
const now = Date.now();
|
|
369701
|
+
pruneExpiredCrossIdEntries(now);
|
|
369702
|
+
const chatKey = `${instanceId}:${from.trim()}`;
|
|
369703
|
+
const rawType = msg.type ?? msg.raw?.type ?? "";
|
|
369704
|
+
const bodyText = (msg.text ?? "").trim();
|
|
369705
|
+
if (rawType !== "text" || !bodyText) {
|
|
369706
|
+
if (rawType && rawType !== "text")
|
|
369707
|
+
recentMediaByChat.set(chatKey, { ts: now, id: msg.id });
|
|
369708
|
+
return false;
|
|
369709
|
+
}
|
|
369710
|
+
const echoOf = isRelayMediaEcho(chatKey, msg.id, bodyText, now);
|
|
369711
|
+
if (echoOf) {
|
|
369712
|
+
logger5.info("gupshup cross-id dedupe: relay media echo dropped", {
|
|
369713
|
+
instanceId,
|
|
369714
|
+
messageId: msg.id,
|
|
369715
|
+
mediaMessageId: echoOf
|
|
369716
|
+
});
|
|
369717
|
+
return true;
|
|
369718
|
+
}
|
|
369719
|
+
const duplicateOf = isDuplicateTextRedelivery(chatKey, msg.id, bodyText, now);
|
|
369720
|
+
if (duplicateOf) {
|
|
369721
|
+
logger5.info("gupshup cross-id dedupe: duplicate content dropped", {
|
|
369722
|
+
instanceId,
|
|
369723
|
+
messageId: msg.id,
|
|
369724
|
+
firstMessageId: duplicateOf
|
|
369725
|
+
});
|
|
369726
|
+
return true;
|
|
369727
|
+
}
|
|
369728
|
+
return false;
|
|
369729
|
+
}
|
|
369659
369730
|
async function processInboundMessage(plugin3, instanceId, webhook, dedupeCache, options = {}) {
|
|
369660
369731
|
const msg = webhook.messageobj;
|
|
369661
369732
|
const from = webhook.sender;
|
|
@@ -369663,6 +369734,9 @@ async function processInboundMessage(plugin3, instanceId, webhook, dedupeCache,
|
|
|
369663
369734
|
if (dedupeCache.isDuplicate(instanceId, dedupeKey, "gupshup", plugin3.getLogger())) {
|
|
369664
369735
|
return false;
|
|
369665
369736
|
}
|
|
369737
|
+
if (isCrossIdDuplicate(instanceId, msg, from, plugin3.getLogger())) {
|
|
369738
|
+
return false;
|
|
369739
|
+
}
|
|
369666
369740
|
const content = extractContent2(msg);
|
|
369667
369741
|
if (!content)
|
|
369668
369742
|
return false;
|