@automagik/omni 2.260609.3 → 2.260609.4
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 +47 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -124971,7 +124971,7 @@ import { fileURLToPath } from "url";
|
|
|
124971
124971
|
// package.json
|
|
124972
124972
|
var package_default = {
|
|
124973
124973
|
name: "@automagik/omni",
|
|
124974
|
-
version: "2.260609.
|
|
124974
|
+
version: "2.260609.4",
|
|
124975
124975
|
description: "LLM-optimized CLI for Omni",
|
|
124976
124976
|
type: "module",
|
|
124977
124977
|
bin: {
|
package/dist/server/index.js
CHANGED
|
@@ -225245,7 +225245,7 @@ var init_sentry_scrub = __esm(() => {
|
|
|
225245
225245
|
var require_package7 = __commonJS((exports, module) => {
|
|
225246
225246
|
module.exports = {
|
|
225247
225247
|
name: "@omni/api",
|
|
225248
|
-
version: "2.260609.
|
|
225248
|
+
version: "2.260609.4",
|
|
225249
225249
|
type: "module",
|
|
225250
225250
|
exports: {
|
|
225251
225251
|
".": {
|
|
@@ -335748,6 +335748,28 @@ class MessageService {
|
|
|
335748
335748
|
const [result] = await this.db.select().from(messages2).where(and2(eq(messages2.chatId, chatId), eq(messages2.isFromMe, true), or2(...aliasConditions))).orderBy(desc(messages2.platformTimestamp)).limit(1);
|
|
335749
335749
|
return result ?? null;
|
|
335750
335750
|
}
|
|
335751
|
+
async findRecentOutboundBefore(chatId, before, inboundText) {
|
|
335752
|
+
const upperBound = new Date(before.getTime() + 2000);
|
|
335753
|
+
const rows = await this.db.select().from(messages2).where(and2(eq(messages2.chatId, chatId), eq(messages2.isFromMe, true), lte(messages2.platformTimestamp, upperBound), sql`${messages2.deletedAt} IS NULL`)).orderBy(desc(messages2.platformTimestamp)).limit(8);
|
|
335754
|
+
if (rows.length === 0)
|
|
335755
|
+
return null;
|
|
335756
|
+
const hint = (inboundText ?? "").toLocaleLowerCase("pt-BR");
|
|
335757
|
+
const wantsPlanLikeTarget = /\b(esse|essa|este|esta|op[c\u00E7][a\u00E3]o|plano|quero|gostei)\b/i.test(hint);
|
|
335758
|
+
if (!wantsPlanLikeTarget)
|
|
335759
|
+
return rows[0] ?? null;
|
|
335760
|
+
const score = (message2) => {
|
|
335761
|
+
const text3 = (message2.textContent ?? "").toLocaleLowerCase("pt-BR");
|
|
335762
|
+
let value = 0;
|
|
335763
|
+
if (/op[c\u00E7][a\u00E3]o|plano/.test(text3))
|
|
335764
|
+
value += 4;
|
|
335765
|
+
if (/r\$|mensal|coparticipa|enfermaria|apartamento|ambulatorial|notrelife|hapvida/.test(text3))
|
|
335766
|
+
value += 3;
|
|
335767
|
+
if (/\?\s*$/.test(text3) && !/r\$/.test(text3))
|
|
335768
|
+
value -= 2;
|
|
335769
|
+
return value;
|
|
335770
|
+
};
|
|
335771
|
+
return rows.map((message2) => ({ message: message2, score: score(message2) })).sort((a, b3) => b3.score - a.score || b3.message.platformTimestamp.getTime() - a.message.platformTimestamp.getTime())[0]?.message ?? null;
|
|
335772
|
+
}
|
|
335751
335773
|
async getByExternalIds(chatId, externalIds) {
|
|
335752
335774
|
if (externalIds.length === 0)
|
|
335753
335775
|
return [];
|
|
@@ -338454,7 +338476,7 @@ function getMessageContentText(msg) {
|
|
|
338454
338476
|
function uniqueNonEmpty(values2) {
|
|
338455
338477
|
return [...new Set(values2.filter((value) => typeof value === "string" && value.length > 0))];
|
|
338456
338478
|
}
|
|
338457
|
-
async function lookupQuotedMessage(messages4, chatDbId, replyToId, aliases) {
|
|
338479
|
+
async function lookupQuotedMessage(messages4, chatDbId, replyToId, aliases, options = {}) {
|
|
338458
338480
|
const quoted = await messages4.getByExternalId(chatDbId, replyToId);
|
|
338459
338481
|
if (quoted)
|
|
338460
338482
|
return quoted;
|
|
@@ -338472,14 +338494,19 @@ async function lookupQuotedMessage(messages4, chatDbId, replyToId, aliases) {
|
|
|
338472
338494
|
if (byExternalId)
|
|
338473
338495
|
return byExternalId;
|
|
338474
338496
|
}
|
|
338497
|
+
if (options.inboundAt && aliasLookup.findRecentOutboundBefore) {
|
|
338498
|
+
const fallback = await aliasLookup.findRecentOutboundBefore(chatDbId, options.inboundAt, options.inboundText);
|
|
338499
|
+
if (fallback)
|
|
338500
|
+
return fallback;
|
|
338501
|
+
}
|
|
338475
338502
|
return null;
|
|
338476
338503
|
}
|
|
338477
|
-
async function resolveQuotedMessage(services, instanceId, chatId, replyToId, providerAliases = []) {
|
|
338504
|
+
async function resolveQuotedMessage(services, instanceId, chatId, replyToId, providerAliases = [], options = {}) {
|
|
338478
338505
|
try {
|
|
338479
338506
|
const chat2 = await services.chats.findByExternalIdSmart(instanceId, chatId);
|
|
338480
338507
|
if (!chat2)
|
|
338481
338508
|
return null;
|
|
338482
|
-
const quoted = await lookupQuotedMessage(services.messages, chat2.id, replyToId, providerAliases);
|
|
338509
|
+
const quoted = await lookupQuotedMessage(services.messages, chat2.id, replyToId, providerAliases, options);
|
|
338483
338510
|
if (!quoted)
|
|
338484
338511
|
return null;
|
|
338485
338512
|
const sender = quoted.senderDisplayName ?? quoted.senderPlatformUserId ?? (quoted.isFromMe ? "You" : "unknown");
|
|
@@ -338560,13 +338587,27 @@ function extractQuotedProviderAliases(rawPayload) {
|
|
|
338560
338587
|
topContext?.id
|
|
338561
338588
|
]);
|
|
338562
338589
|
}
|
|
338590
|
+
function extractInboundPlatformDate(rawPayload) {
|
|
338591
|
+
if (!rawPayload)
|
|
338592
|
+
return;
|
|
338593
|
+
const messageObj = isRecord(rawPayload.messageobj) ? rawPayload.messageobj : undefined;
|
|
338594
|
+
const timestamp3 = messageObj?.timestamp;
|
|
338595
|
+
if (typeof timestamp3 === "number" && Number.isFinite(timestamp3) && timestamp3 > 0) {
|
|
338596
|
+
return new Date(timestamp3 * 1000);
|
|
338597
|
+
}
|
|
338598
|
+
return;
|
|
338599
|
+
}
|
|
338563
338600
|
async function prependQuotedContext(services, instanceId, chatId, messages4, entries, messageKeyByIndex) {
|
|
338564
338601
|
for (const [index2, m2] of messages4.entries()) {
|
|
338565
338602
|
const replyToId = m2.payload.replyToId;
|
|
338566
338603
|
if (!replyToId)
|
|
338567
338604
|
continue;
|
|
338568
|
-
const
|
|
338569
|
-
const
|
|
338605
|
+
const rawPayload = m2.payload.rawPayload;
|
|
338606
|
+
const providerAliases = extractQuotedProviderAliases(rawPayload);
|
|
338607
|
+
const quotedText = await resolveQuotedMessage(services, instanceId, chatId, replyToId, providerAliases, {
|
|
338608
|
+
inboundAt: extractInboundPlatformDate(rawPayload),
|
|
338609
|
+
inboundText: m2.payload.content?.text
|
|
338610
|
+
});
|
|
338570
338611
|
if (!quotedText)
|
|
338571
338612
|
continue;
|
|
338572
338613
|
const messageKey = messageKeyByIndex.get(index2);
|