@automagik/omni 2.260423.9 → 2.260423.10
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 +77 -32
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -113929,7 +113929,7 @@ import { fileURLToPath } from "url";
|
|
|
113929
113929
|
// package.json
|
|
113930
113930
|
var package_default = {
|
|
113931
113931
|
name: "@automagik/omni",
|
|
113932
|
-
version: "2.260423.
|
|
113932
|
+
version: "2.260423.10",
|
|
113933
113933
|
description: "LLM-optimized CLI for Omni",
|
|
113934
113934
|
type: "module",
|
|
113935
113935
|
bin: {
|
package/dist/server/index.js
CHANGED
|
@@ -22659,6 +22659,10 @@ function generateCorrelationId(prefix = "corr") {
|
|
|
22659
22659
|
const random = Math.random().toString(36).substring(2, 10);
|
|
22660
22660
|
return `${prefix}-${timestamp}-${random}`;
|
|
22661
22661
|
}
|
|
22662
|
+
function isValidUuid(id) {
|
|
22663
|
+
const uuidRegex2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
22664
|
+
return uuidRegex2.test(id);
|
|
22665
|
+
}
|
|
22662
22666
|
var init_ids = () => {};
|
|
22663
22667
|
|
|
22664
22668
|
// ../../node_modules/.bun/croner@9.1.0/node_modules/croner/dist/croner.js
|
|
@@ -224550,7 +224554,7 @@ var init_sentry_scrub = __esm(() => {
|
|
|
224550
224554
|
var require_package8 = __commonJS((exports, module) => {
|
|
224551
224555
|
module.exports = {
|
|
224552
224556
|
name: "@omni/api",
|
|
224553
|
-
version: "2.260423.
|
|
224557
|
+
version: "2.260423.10",
|
|
224554
224558
|
type: "module",
|
|
224555
224559
|
exports: {
|
|
224556
224560
|
".": {
|
|
@@ -302860,6 +302864,9 @@ function mapContentType2(contentType) {
|
|
|
302860
302864
|
}
|
|
302861
302865
|
return null;
|
|
302862
302866
|
}
|
|
302867
|
+
function eventIdInsert(eventId) {
|
|
302868
|
+
return eventId && isValidUuid(eventId) ? { id: eventId } : {};
|
|
302869
|
+
}
|
|
302863
302870
|
async function resolveChatUuid(db2, instanceId, chatId) {
|
|
302864
302871
|
if (!instanceId || !chatId)
|
|
302865
302872
|
return null;
|
|
@@ -302883,6 +302890,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
302883
302890
|
try {
|
|
302884
302891
|
const chatUuid = await resolveChatUuid(db2, metadata.instanceId, payload.chatId);
|
|
302885
302892
|
const newEvent = {
|
|
302893
|
+
...eventIdInsert(event.id),
|
|
302886
302894
|
externalId: payload.externalId,
|
|
302887
302895
|
channel: mapChannelType(metadata.channelType),
|
|
302888
302896
|
instanceId: metadata.instanceId,
|
|
@@ -302907,7 +302915,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
302907
302915
|
conversationId: null,
|
|
302908
302916
|
chatUuid
|
|
302909
302917
|
};
|
|
302910
|
-
await db2.insert(omniEvents).values(newEvent);
|
|
302918
|
+
await db2.insert(omniEvents).values(newEvent).onConflictDoNothing({ target: omniEvents.id });
|
|
302911
302919
|
if (metadata.timings && metadata.correlationId) {
|
|
302912
302920
|
const tracker = getJourneyTracker();
|
|
302913
302921
|
tracker.recordCheckpoint(metadata.correlationId, "T4", JOURNEY_STAGES.T4);
|
|
@@ -302929,6 +302937,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
302929
302937
|
try {
|
|
302930
302938
|
const chatUuid = await resolveChatUuid(db2, metadata.instanceId, payload.chatId);
|
|
302931
302939
|
const newEvent = {
|
|
302940
|
+
...eventIdInsert(event.id),
|
|
302932
302941
|
externalId: payload.externalId,
|
|
302933
302942
|
channel: mapChannelType(metadata.channelType),
|
|
302934
302943
|
instanceId: metadata.instanceId,
|
|
@@ -302952,7 +302961,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
302952
302961
|
conversationId: null,
|
|
302953
302962
|
chatUuid
|
|
302954
302963
|
};
|
|
302955
|
-
await db2.insert(omniEvents).values(newEvent);
|
|
302964
|
+
await db2.insert(omniEvents).values(newEvent).onConflictDoNothing({ target: omniEvents.id });
|
|
302956
302965
|
log104.debug("Persisted message.sent", {
|
|
302957
302966
|
externalId: payload.externalId,
|
|
302958
302967
|
instanceId: metadata.instanceId
|
|
@@ -302975,6 +302984,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
302975
302984
|
if (updated.length === 0) {
|
|
302976
302985
|
const chatUuid = await resolveChatUuid(db2, metadata.instanceId, payload.chatId);
|
|
302977
302986
|
const newEvent = {
|
|
302987
|
+
...eventIdInsert(event.id),
|
|
302978
302988
|
externalId: payload.externalId,
|
|
302979
302989
|
channel: mapChannelType(metadata.channelType),
|
|
302980
302990
|
instanceId: metadata.instanceId,
|
|
@@ -302988,7 +302998,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
302988
302998
|
conversationId: null,
|
|
302989
302999
|
chatUuid
|
|
302990
303000
|
};
|
|
302991
|
-
await db2.insert(omniEvents).values(newEvent);
|
|
303001
|
+
await db2.insert(omniEvents).values(newEvent).onConflictDoNothing({ target: omniEvents.id });
|
|
302992
303002
|
}
|
|
302993
303003
|
log104.debug("Persisted message.delivered", {
|
|
302994
303004
|
externalId: payload.externalId
|
|
@@ -303010,6 +303020,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
303010
303020
|
if (updated.length === 0) {
|
|
303011
303021
|
const chatUuid = await resolveChatUuid(db2, metadata.instanceId, payload.chatId);
|
|
303012
303022
|
const newEvent = {
|
|
303023
|
+
...eventIdInsert(event.id),
|
|
303013
303024
|
externalId: payload.externalId,
|
|
303014
303025
|
channel: mapChannelType(metadata.channelType),
|
|
303015
303026
|
instanceId: metadata.instanceId,
|
|
@@ -303023,7 +303034,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
303023
303034
|
conversationId: null,
|
|
303024
303035
|
chatUuid
|
|
303025
303036
|
};
|
|
303026
|
-
await db2.insert(omniEvents).values(newEvent);
|
|
303037
|
+
await db2.insert(omniEvents).values(newEvent).onConflictDoNothing({ target: omniEvents.id });
|
|
303027
303038
|
}
|
|
303028
303039
|
log104.debug("Persisted message.read", {
|
|
303029
303040
|
externalId: payload.externalId
|
|
@@ -303041,6 +303052,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
303041
303052
|
try {
|
|
303042
303053
|
const chatUuid = await resolveChatUuid(db2, metadata.instanceId, payload.chatId);
|
|
303043
303054
|
const newEvent = {
|
|
303055
|
+
...eventIdInsert(event.id),
|
|
303044
303056
|
externalId: payload.externalId,
|
|
303045
303057
|
channel: mapChannelType(metadata.channelType),
|
|
303046
303058
|
instanceId: metadata.instanceId,
|
|
@@ -303060,7 +303072,7 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
303060
303072
|
conversationId: null,
|
|
303061
303073
|
chatUuid
|
|
303062
303074
|
};
|
|
303063
|
-
await db2.insert(omniEvents).values(newEvent);
|
|
303075
|
+
await db2.insert(omniEvents).values(newEvent).onConflictDoNothing({ target: omniEvents.id });
|
|
303064
303076
|
log104.debug("Persisted message.failed", {
|
|
303065
303077
|
chatId: payload.chatId,
|
|
303066
303078
|
error: payload.error
|
|
@@ -303125,6 +303137,9 @@ function shouldProcess(contentType) {
|
|
|
303125
303137
|
return false;
|
|
303126
303138
|
return PROCESSABLE_MEDIA_TYPES.has(contentType);
|
|
303127
303139
|
}
|
|
303140
|
+
function isUuid(value) {
|
|
303141
|
+
return typeof value === "string" && isValidUuid(value);
|
|
303142
|
+
}
|
|
303128
303143
|
function getMimeType2(content) {
|
|
303129
303144
|
if (content.mimeType)
|
|
303130
303145
|
return content.mimeType;
|
|
@@ -303203,6 +303218,28 @@ async function resolveMediaPath2(ctx, instanceId, chatId, externalId, content, m
|
|
|
303203
303218
|
fullPath: join25(ctx.mediaStorage.getBasePath(), filePath)
|
|
303204
303219
|
};
|
|
303205
303220
|
}
|
|
303221
|
+
async function resolveSafeMediaContentEventId(ctx, eventId) {
|
|
303222
|
+
if (!isUuid(eventId))
|
|
303223
|
+
return null;
|
|
303224
|
+
const maxWaitMs = 250;
|
|
303225
|
+
const pollMs = 50;
|
|
303226
|
+
const deadline = Date.now() + maxWaitMs;
|
|
303227
|
+
while (true) {
|
|
303228
|
+
try {
|
|
303229
|
+
const [event] = await ctx.db.select({ id: omniEvents.id }).from(omniEvents).where(eq(omniEvents.id, eventId)).limit(1);
|
|
303230
|
+
if (event)
|
|
303231
|
+
return event.id;
|
|
303232
|
+
} catch (error2) {
|
|
303233
|
+
log105.debug("Failed to validate media_content event FK", { eventId, error: String(error2) });
|
|
303234
|
+
return null;
|
|
303235
|
+
}
|
|
303236
|
+
if (Date.now() >= deadline) {
|
|
303237
|
+
log105.debug("Skipping media_content event FK; omni_event not found", { eventId });
|
|
303238
|
+
return null;
|
|
303239
|
+
}
|
|
303240
|
+
await new Promise((resolve4) => setTimeout(resolve4, pollMs));
|
|
303241
|
+
}
|
|
303242
|
+
}
|
|
303206
303243
|
async function persistProcessingResult(ctx, messageId, eventId, result, contentType) {
|
|
303207
303244
|
if (result.content) {
|
|
303208
303245
|
const updateField = getContentFieldForType(result.processingType, contentType);
|
|
@@ -303211,8 +303248,9 @@ async function persistProcessingResult(ctx, messageId, eventId, result, contentT
|
|
|
303211
303248
|
}
|
|
303212
303249
|
}
|
|
303213
303250
|
try {
|
|
303251
|
+
const safeEventId = await resolveSafeMediaContentEventId(ctx, eventId);
|
|
303214
303252
|
await ctx.db.insert(mediaContent).values({
|
|
303215
|
-
eventId:
|
|
303253
|
+
eventId: safeEventId,
|
|
303216
303254
|
mediaId: messageId,
|
|
303217
303255
|
processingType: result.processingType,
|
|
303218
303256
|
content: result.content ?? "",
|
|
@@ -424351,6 +424389,15 @@ init_src();
|
|
|
424351
424389
|
import { existsSync as existsSync2, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
424352
424390
|
import { basename, dirname as dirname2, join as join8 } from "path";
|
|
424353
424391
|
|
|
424392
|
+
// ../channel-whatsapp/src/utils/message.ts
|
|
424393
|
+
function getDocumentMessage(message2) {
|
|
424394
|
+
return message2?.documentMessage ?? message2?.documentWithCaptionMessage?.message?.documentMessage;
|
|
424395
|
+
}
|
|
424396
|
+
function getMessageContextInfo(msg) {
|
|
424397
|
+
const message2 = msg.message;
|
|
424398
|
+
return message2?.extendedTextMessage?.contextInfo ?? message2?.imageMessage?.contextInfo ?? message2?.videoMessage?.contextInfo ?? getDocumentMessage(message2)?.contextInfo;
|
|
424399
|
+
}
|
|
424400
|
+
|
|
424354
424401
|
// ../channel-whatsapp/src/utils/download.ts
|
|
424355
424402
|
function detectMediaType(msg) {
|
|
424356
424403
|
const message2 = msg.message;
|
|
@@ -424377,11 +424424,12 @@ function detectMediaType(msg) {
|
|
|
424377
424424
|
duration: message2.videoMessage.seconds || undefined
|
|
424378
424425
|
};
|
|
424379
424426
|
}
|
|
424380
|
-
|
|
424427
|
+
const documentMessage = getDocumentMessage(message2);
|
|
424428
|
+
if (documentMessage) {
|
|
424381
424429
|
return {
|
|
424382
424430
|
type: "document",
|
|
424383
|
-
mimeType:
|
|
424384
|
-
filename:
|
|
424431
|
+
mimeType: documentMessage.mimetype || "application/octet-stream",
|
|
424432
|
+
filename: documentMessage.fileName || undefined
|
|
424385
424433
|
};
|
|
424386
424434
|
}
|
|
424387
424435
|
if (message2.stickerMessage) {
|
|
@@ -424472,8 +424520,9 @@ function getMediaSize(msg) {
|
|
|
424472
424520
|
if (message2.videoMessage?.fileLength) {
|
|
424473
424521
|
return Number(message2.videoMessage.fileLength);
|
|
424474
424522
|
}
|
|
424475
|
-
|
|
424476
|
-
|
|
424523
|
+
const documentMessage = getDocumentMessage(message2);
|
|
424524
|
+
if (documentMessage?.fileLength) {
|
|
424525
|
+
return Number(documentMessage.fileLength);
|
|
424477
424526
|
}
|
|
424478
424527
|
if (message2.stickerMessage?.fileLength) {
|
|
424479
424528
|
return Number(message2.stickerMessage.fileLength);
|
|
@@ -424521,14 +424570,17 @@ var contentExtractors = [
|
|
|
424521
424570
|
})
|
|
424522
424571
|
},
|
|
424523
424572
|
{
|
|
424524
|
-
check: (m2) => !!m2
|
|
424525
|
-
extract: (m2) =>
|
|
424526
|
-
|
|
424527
|
-
|
|
424528
|
-
|
|
424529
|
-
|
|
424530
|
-
|
|
424531
|
-
|
|
424573
|
+
check: (m2) => !!getDocumentMessage(m2),
|
|
424574
|
+
extract: (m2) => {
|
|
424575
|
+
const document2 = getDocumentMessage(m2);
|
|
424576
|
+
return {
|
|
424577
|
+
type: "document",
|
|
424578
|
+
filename: document2?.fileName ?? undefined,
|
|
424579
|
+
mimeType: document2?.mimetype ?? "application/octet-stream",
|
|
424580
|
+
caption: document2?.caption ?? undefined,
|
|
424581
|
+
mediaUrl: document2?.url ?? undefined
|
|
424582
|
+
};
|
|
424583
|
+
}
|
|
424532
424584
|
},
|
|
424533
424585
|
{
|
|
424534
424586
|
check: (m2) => !!m2.stickerMessage,
|
|
@@ -424781,10 +424833,6 @@ function extractPhoneFromVcard(vcard) {
|
|
|
424781
424833
|
}
|
|
424782
424834
|
return;
|
|
424783
424835
|
}
|
|
424784
|
-
function getMessageContextInfo(msg) {
|
|
424785
|
-
const message2 = msg.message;
|
|
424786
|
-
return message2?.extendedTextMessage?.contextInfo ?? message2?.imageMessage?.contextInfo ?? message2?.videoMessage?.contextInfo ?? message2?.documentMessage?.contextInfo;
|
|
424787
|
-
}
|
|
424788
424836
|
function getReplyToId2(msg) {
|
|
424789
424837
|
const contextInfo = getMessageContextInfo(msg);
|
|
424790
424838
|
return contextInfo?.stanzaId || undefined;
|
|
@@ -427573,10 +427621,6 @@ class WhatsAppPlugin extends BaseChannelPlugin {
|
|
|
427573
427621
|
}
|
|
427574
427622
|
}
|
|
427575
427623
|
}
|
|
427576
|
-
getMessageContextInfo(rawMessage) {
|
|
427577
|
-
const message2 = rawMessage.message;
|
|
427578
|
-
return message2?.extendedTextMessage?.contextInfo ?? message2?.imageMessage?.contextInfo ?? message2?.videoMessage?.contextInfo ?? message2?.documentMessage?.contextInfo;
|
|
427579
|
-
}
|
|
427580
427624
|
async handleMessageReceived(instanceId, externalId, chatId, from, content, replyToId, rawMessage, isFromMe2, platformTimestamp) {
|
|
427581
427625
|
if (externalId && rawMessage.key) {
|
|
427582
427626
|
const cacheKey = `${instanceId}:${externalId}`;
|
|
@@ -427601,7 +427645,7 @@ class WhatsAppPlugin extends BaseChannelPlugin {
|
|
|
427601
427645
|
...rawMessage,
|
|
427602
427646
|
isFromMe: isFromMe2
|
|
427603
427647
|
};
|
|
427604
|
-
const contextInfo =
|
|
427648
|
+
const contextInfo = getMessageContextInfo(rawMessage);
|
|
427605
427649
|
if (contextInfo?.mentionedJid && contextInfo.mentionedJid.length > 0) {
|
|
427606
427650
|
extendedPayload.mentionedJids = contextInfo.mentionedJid;
|
|
427607
427651
|
this.logger.debug("Processing mentioned JIDs", {
|
|
@@ -428185,6 +428229,7 @@ class WhatsAppPlugin extends BaseChannelPlugin {
|
|
|
428185
428229
|
return null;
|
|
428186
428230
|
}
|
|
428187
428231
|
extractMediaContent(message2) {
|
|
428232
|
+
const documentMessage = getDocumentMessage(message2);
|
|
428188
428233
|
if (message2.imageMessage) {
|
|
428189
428234
|
return {
|
|
428190
428235
|
type: "image",
|
|
@@ -428202,11 +428247,11 @@ class WhatsAppPlugin extends BaseChannelPlugin {
|
|
|
428202
428247
|
caption: message2.videoMessage.caption ?? undefined
|
|
428203
428248
|
};
|
|
428204
428249
|
}
|
|
428205
|
-
if (
|
|
428250
|
+
if (documentMessage) {
|
|
428206
428251
|
return {
|
|
428207
428252
|
type: "document",
|
|
428208
|
-
mimeType:
|
|
428209
|
-
caption:
|
|
428253
|
+
mimeType: documentMessage.mimetype ?? "application/octet-stream",
|
|
428254
|
+
caption: documentMessage.caption ?? undefined
|
|
428210
428255
|
};
|
|
428211
428256
|
}
|
|
428212
428257
|
if (message2.stickerMessage) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automagik/omni",
|
|
3
|
-
"version": "2.260423.
|
|
3
|
+
"version": "2.260423.10",
|
|
4
4
|
"description": "LLM-optimized CLI for Omni",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -39,15 +39,15 @@
|
|
|
39
39
|
"qrcode-terminal": "^0.12.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@omni/api": "2.260423.
|
|
43
|
-
"@omni/channel-discord": "2.260423.
|
|
44
|
-
"@omni/channel-gupshup": "2.260423.
|
|
45
|
-
"@omni/channel-sdk": "2.260423.
|
|
46
|
-
"@omni/channel-slack": "2.260423.
|
|
47
|
-
"@omni/channel-telegram": "2.260423.
|
|
48
|
-
"@omni/channel-whatsapp": "2.260423.
|
|
49
|
-
"@omni/core": "2.260423.
|
|
50
|
-
"@omni/sdk": "2.260423.
|
|
42
|
+
"@omni/api": "2.260423.9",
|
|
43
|
+
"@omni/channel-discord": "2.260423.9",
|
|
44
|
+
"@omni/channel-gupshup": "2.260423.9",
|
|
45
|
+
"@omni/channel-sdk": "2.260423.9",
|
|
46
|
+
"@omni/channel-slack": "2.260423.9",
|
|
47
|
+
"@omni/channel-telegram": "2.260423.9",
|
|
48
|
+
"@omni/channel-whatsapp": "2.260423.9",
|
|
49
|
+
"@omni/core": "2.260423.9",
|
|
50
|
+
"@omni/sdk": "2.260423.9",
|
|
51
51
|
"@types/node": "^22.10.3",
|
|
52
52
|
"@types/qrcode-terminal": "^0.12.2",
|
|
53
53
|
"typescript": "^5.7.3"
|