@automagik/omni 2.260910.6 → 2.260910.7
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 +4 -18
- package/dist/server/index.js +93 -113
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -42456,9 +42456,8 @@ async function processRow2(row, now, deps, stats) {
|
|
|
42456
42456
|
silentForSeconds,
|
|
42457
42457
|
stalledAt: now.getTime()
|
|
42458
42458
|
};
|
|
42459
|
-
|
|
42459
|
+
await publishTransition(deps, "system.connector.stalled", { ...payload }, row);
|
|
42460
42460
|
stats.stalled += 1;
|
|
42461
|
-
await runHook(deps.logger, "onStalled", row, () => deps.onStalled?.(row, payload, eventId));
|
|
42462
42461
|
return;
|
|
42463
42462
|
}
|
|
42464
42463
|
if (row.livenessStatus === "stalled") {
|
|
@@ -42475,7 +42474,6 @@ async function processRow2(row, now, deps, stats) {
|
|
|
42475
42474
|
};
|
|
42476
42475
|
await publishTransition(deps, "system.connector.recovered", { ...payload }, row);
|
|
42477
42476
|
stats.recovered += 1;
|
|
42478
|
-
await runHook(deps.logger, "onRecovered", row, () => deps.onRecovered?.(row, payload));
|
|
42479
42477
|
}
|
|
42480
42478
|
}
|
|
42481
42479
|
async function publishTransition(deps, type, payload, row) {
|
|
@@ -42484,24 +42482,12 @@ async function publishTransition(deps, type, payload, row) {
|
|
|
42484
42482
|
type,
|
|
42485
42483
|
sourceName: row.name
|
|
42486
42484
|
});
|
|
42487
|
-
return
|
|
42485
|
+
return;
|
|
42488
42486
|
}
|
|
42489
|
-
|
|
42487
|
+
await deps.eventBus.publishGeneric(type, payload, {
|
|
42490
42488
|
source: "connector-liveness",
|
|
42491
42489
|
...row.tenantId ? { tenantId: row.tenantId } : {}
|
|
42492
42490
|
});
|
|
42493
|
-
return result.id;
|
|
42494
|
-
}
|
|
42495
|
-
async function runHook(logger5, name, row, hook) {
|
|
42496
|
-
try {
|
|
42497
|
-
await hook();
|
|
42498
|
-
} catch (err2) {
|
|
42499
|
-
logger5.error(`connector liveness: ${name} hook failed`, {
|
|
42500
|
-
sourceId: row.id,
|
|
42501
|
-
sourceName: row.name,
|
|
42502
|
-
error: err2 instanceof Error ? err2.message : String(err2)
|
|
42503
|
-
});
|
|
42504
|
-
}
|
|
42505
42491
|
}
|
|
42506
42492
|
|
|
42507
42493
|
// ../core/src/connectors/index.ts
|
|
@@ -137139,7 +137125,7 @@ import { fileURLToPath } from "url";
|
|
|
137139
137125
|
// package.json
|
|
137140
137126
|
var package_default = {
|
|
137141
137127
|
name: "@automagik/omni",
|
|
137142
|
-
version: "2.260910.
|
|
137128
|
+
version: "2.260910.7",
|
|
137143
137129
|
repository: {
|
|
137144
137130
|
type: "git",
|
|
137145
137131
|
url: "git+https://github.com/automagik-dev/omni.git",
|
package/dist/server/index.js
CHANGED
|
@@ -39360,9 +39360,8 @@ async function processRow2(row, now, deps, stats) {
|
|
|
39360
39360
|
silentForSeconds,
|
|
39361
39361
|
stalledAt: now.getTime()
|
|
39362
39362
|
};
|
|
39363
|
-
|
|
39363
|
+
await publishTransition(deps, "system.connector.stalled", { ...payload }, row);
|
|
39364
39364
|
stats.stalled += 1;
|
|
39365
|
-
await runHook(deps.logger, "onStalled", row, () => deps.onStalled?.(row, payload, eventId));
|
|
39366
39365
|
return;
|
|
39367
39366
|
}
|
|
39368
39367
|
if (row.livenessStatus === "stalled") {
|
|
@@ -39379,7 +39378,6 @@ async function processRow2(row, now, deps, stats) {
|
|
|
39379
39378
|
};
|
|
39380
39379
|
await publishTransition(deps, "system.connector.recovered", { ...payload }, row);
|
|
39381
39380
|
stats.recovered += 1;
|
|
39382
|
-
await runHook(deps.logger, "onRecovered", row, () => deps.onRecovered?.(row, payload));
|
|
39383
39381
|
}
|
|
39384
39382
|
}
|
|
39385
39383
|
async function publishTransition(deps, type, payload, row) {
|
|
@@ -39388,24 +39386,12 @@ async function publishTransition(deps, type, payload, row) {
|
|
|
39388
39386
|
type,
|
|
39389
39387
|
sourceName: row.name
|
|
39390
39388
|
});
|
|
39391
|
-
return
|
|
39389
|
+
return;
|
|
39392
39390
|
}
|
|
39393
|
-
|
|
39391
|
+
await deps.eventBus.publishGeneric(type, payload, {
|
|
39394
39392
|
source: "connector-liveness",
|
|
39395
39393
|
...row.tenantId ? { tenantId: row.tenantId } : {}
|
|
39396
39394
|
});
|
|
39397
|
-
return result.id;
|
|
39398
|
-
}
|
|
39399
|
-
async function runHook(logger5, name, row, hook) {
|
|
39400
|
-
try {
|
|
39401
|
-
await hook();
|
|
39402
|
-
} catch (err2) {
|
|
39403
|
-
logger5.error(`connector liveness: ${name} hook failed`, {
|
|
39404
|
-
sourceId: row.id,
|
|
39405
|
-
sourceName: row.name,
|
|
39406
|
-
error: err2 instanceof Error ? err2.message : String(err2)
|
|
39407
|
-
});
|
|
39408
|
-
}
|
|
39409
39395
|
}
|
|
39410
39396
|
|
|
39411
39397
|
// ../core/src/connectors/index.ts
|
|
@@ -251595,7 +251581,7 @@ var init_sentry_scrub = __esm(() => {
|
|
|
251595
251581
|
var require_package7 = __commonJS((exports, module) => {
|
|
251596
251582
|
module.exports = {
|
|
251597
251583
|
name: "@omni/api",
|
|
251598
|
-
version: "2.260910.
|
|
251584
|
+
version: "2.260910.7",
|
|
251599
251585
|
private: true,
|
|
251600
251586
|
type: "module",
|
|
251601
251587
|
exports: {
|
|
@@ -363727,14 +363713,27 @@ async function maybeFindOrCreateParticipant(services, chatId, from, rawPayload,
|
|
|
363727
363713
|
platformIdentityId
|
|
363728
363714
|
});
|
|
363729
363715
|
}
|
|
363730
|
-
async function maybeRecordMessageEdit(services, created, rawPayload, messageId, newText, platformTimestamp, from) {
|
|
363716
|
+
async function maybeRecordMessageEdit(services, created, rawPayload, chatId, messageId, contentType, newText, platformTimestamp, from) {
|
|
363717
|
+
const editedBy = truncate4(from, 255) ?? undefined;
|
|
363718
|
+
if (contentType === "edit") {
|
|
363719
|
+
const targetExternalId = rawPayload?.editedMessageId;
|
|
363720
|
+
if (typeof targetExternalId !== "string")
|
|
363721
|
+
return;
|
|
363722
|
+
const target = await services.messages.getByExternalId(chatId, targetExternalId);
|
|
363723
|
+
if (!target)
|
|
363724
|
+
return;
|
|
363725
|
+
const editedAtMs2 = rawPayload?.editedAt;
|
|
363726
|
+
const editedAt2 = new Date(typeof editedAtMs2 === "number" ? editedAtMs2 : platformTimestamp.getTime());
|
|
363727
|
+
await services.messages.recordEdit(target.id, newText ?? "", editedAt2, editedBy);
|
|
363728
|
+
return;
|
|
363729
|
+
}
|
|
363731
363730
|
if (created)
|
|
363732
363731
|
return;
|
|
363733
363732
|
if (rawPayload?.isEdited !== true)
|
|
363734
363733
|
return;
|
|
363735
363734
|
const editedAtMs = rawPayload.editDate;
|
|
363736
363735
|
const editedAt = new Date(typeof editedAtMs === "number" ? editedAtMs : platformTimestamp.getTime());
|
|
363737
|
-
await services.messages.recordEdit(messageId, newText ?? "", editedAt,
|
|
363736
|
+
await services.messages.recordEdit(messageId, newText ?? "", editedAt, editedBy);
|
|
363738
363737
|
}
|
|
363739
363738
|
async function maybeRecordParticipantActivity(services, chatId, from) {
|
|
363740
363739
|
if (!from)
|
|
@@ -363743,7 +363742,7 @@ async function maybeRecordParticipantActivity(services, chatId, from) {
|
|
|
363743
363742
|
await services.chats.recordParticipantActivity(chatId, activityUserId);
|
|
363744
363743
|
}
|
|
363745
363744
|
function maybeUpdateRecency(services, instanceId, chatId, rawPayload, payload, platformTimestamp, trustedTenantId) {
|
|
363746
|
-
if (rawPayload?.isEdited === true)
|
|
363745
|
+
if (rawPayload?.isEdited === true || payload.content.type === "edit")
|
|
363747
363746
|
return;
|
|
363748
363747
|
const preview = sanitizeText(buildChatPreview(payload, rawPayload)) ?? "";
|
|
363749
363748
|
const isFromMe2 = rawPayload?.isFromMe === true;
|
|
@@ -363869,7 +363868,7 @@ async function handleMessageReceived(services, payload, metadata, eventTimestamp
|
|
|
363869
363868
|
isForwarded: !!(rawPayload?.isForwarded || rawPayload?.forwardingScore),
|
|
363870
363869
|
rawPayload
|
|
363871
363870
|
});
|
|
363872
|
-
await maybeRecordMessageEdit(services, created, rawPayload, message2.id, sanitizeText(payload.content.text) ?? undefined, platformTimestamp ?? new Date(eventTimestamp), payload.from);
|
|
363871
|
+
await maybeRecordMessageEdit(services, created, rawPayload, chat2.id, message2.id, payload.content.type, sanitizeText(payload.content.text) ?? undefined, platformTimestamp ?? new Date(eventTimestamp), payload.from);
|
|
363873
363872
|
if (created) {
|
|
363874
363873
|
log90.debug("Created message", { externalId: payload.externalId, chatId: chat2.id });
|
|
363875
363874
|
await linkReplyTarget(services, chat2.id, message2.id, payload.replyToId);
|
|
@@ -375966,18 +375965,8 @@ class WebhookService {
|
|
|
375966
375965
|
expectedIntervalSeconds: source.expectedIntervalSeconds
|
|
375967
375966
|
};
|
|
375968
375967
|
}
|
|
375969
|
-
async sweepLiveness(
|
|
375970
|
-
|
|
375971
|
-
const hooks2 = deadLetters ? {
|
|
375972
|
-
onStalled: (row, payload, publishedEventId) => fileStallDeadLetter(deadLetters, row, payload, publishedEventId),
|
|
375973
|
-
onRecovered: (row) => resolveStallDeadLetters(deadLetters, row)
|
|
375974
|
-
} : {};
|
|
375975
|
-
return sweepConnectorLiveness({
|
|
375976
|
-
repo: this.livenessRepo(),
|
|
375977
|
-
eventBus: this.eventBus,
|
|
375978
|
-
logger: log112,
|
|
375979
|
-
...hooks2
|
|
375980
|
-
});
|
|
375968
|
+
async sweepLiveness() {
|
|
375969
|
+
return sweepConnectorLiveness({ repo: this.livenessRepo(), eventBus: this.eventBus, logger: log112 });
|
|
375981
375970
|
}
|
|
375982
375971
|
livenessRepo() {
|
|
375983
375972
|
return {
|
|
@@ -376007,35 +375996,6 @@ class WebhookService {
|
|
|
376007
375996
|
};
|
|
376008
375997
|
}
|
|
376009
375998
|
}
|
|
376010
|
-
async function fileStallDeadLetter(deadLetters, row, payload, publishedEventId) {
|
|
376011
|
-
const event = {
|
|
376012
|
-
id: publishedEventId ?? generateId(),
|
|
376013
|
-
type: "system.connector.stalled",
|
|
376014
|
-
payload: { ...payload },
|
|
376015
|
-
metadata: {
|
|
376016
|
-
correlationId: generateId(),
|
|
376017
|
-
source: "connector-liveness",
|
|
376018
|
-
...row.tenantId ? { tenantId: row.tenantId } : {}
|
|
376019
|
-
},
|
|
376020
|
-
timestamp: payload.stalledAt
|
|
376021
|
-
};
|
|
376022
|
-
await deadLetters.create({
|
|
376023
|
-
event,
|
|
376024
|
-
subject: "system.connector.stalled.internal.global",
|
|
376025
|
-
error: new Error(`Connector '${row.name}' declared >=1 event or heartbeat per ${row.expectedIntervalSeconds}s ` + `but has been silent for ${payload.silentForSeconds}s`),
|
|
376026
|
-
retryCount: 0,
|
|
376027
|
-
autoRetry: false
|
|
376028
|
-
});
|
|
376029
|
-
}
|
|
376030
|
-
async function resolveStallDeadLetters(deadLetters, row) {
|
|
376031
|
-
const { items } = await deadLetters.list({ status: ["pending"], eventType: ["system.connector.stalled"] });
|
|
376032
|
-
for (const entry of items) {
|
|
376033
|
-
const stored = entry.payload;
|
|
376034
|
-
if (stored.payload?.sourceId === row.id) {
|
|
376035
|
-
await deadLetters.resolve(entry.id, "connector-liveness: recovered");
|
|
376036
|
-
}
|
|
376037
|
-
}
|
|
376038
|
-
}
|
|
376039
375999
|
var log112;
|
|
376040
376000
|
var init_webhooks = __esm(() => {
|
|
376041
376001
|
init_src();
|
|
@@ -398036,53 +397996,63 @@ async function setupEventPersistence(eventBus, db2) {
|
|
|
398036
397996
|
}
|
|
398037
397997
|
}, { ...CONSUMER_OPTIONS, durable: `event-persistence-${type.replace(".", "-")}` });
|
|
398038
397998
|
}
|
|
398039
|
-
await eventBus.subscribePattern("custom.>",
|
|
398040
|
-
|
|
398041
|
-
|
|
398042
|
-
|
|
398043
|
-
|
|
398044
|
-
|
|
398045
|
-
|
|
398046
|
-
|
|
398047
|
-
|
|
398048
|
-
|
|
398049
|
-
const chatLink = chatUuid ? { chatUuid, canonicalChatId: null } : await resolveChatLink(sdb, instanceId ?? undefined, payloadChatId);
|
|
398050
|
-
const newEvent = {
|
|
398051
|
-
...eventIdInsert(event.id),
|
|
398052
|
-
channel: "internal",
|
|
398053
|
-
instanceId,
|
|
398054
|
-
personId,
|
|
398055
|
-
eventType: event.type.slice(0, 255),
|
|
398056
|
-
direction: "internal",
|
|
398057
|
-
status: "completed",
|
|
398058
|
-
receivedAt: new Date(event.timestamp),
|
|
398059
|
-
rawPayload: deepSanitize(payload),
|
|
398060
|
-
metadata: {
|
|
398061
|
-
correlationId: metadata.correlationId,
|
|
398062
|
-
source: metadata.source,
|
|
398063
|
-
fullEventType: event.type
|
|
398064
|
-
},
|
|
398065
|
-
causationId: metadata.causationId ?? null,
|
|
398066
|
-
conversationId: null,
|
|
398067
|
-
chatId: payloadChatId,
|
|
398068
|
-
...chatLink
|
|
398069
|
-
};
|
|
398070
|
-
await sdb.insert(omniEvents).values(newEvent).onConflictDoNothing({ target: omniEvents.id });
|
|
398071
|
-
});
|
|
398072
|
-
} catch (error3) {
|
|
398073
|
-
log125.error("Failed to persist custom event", {
|
|
398074
|
-
eventType: event.type,
|
|
398075
|
-
eventId: event.id,
|
|
398076
|
-
error: String(error3)
|
|
398077
|
-
});
|
|
398078
|
-
}
|
|
398079
|
-
}, { ...CONSUMER_OPTIONS, durable: "event-persistence-custom", startFrom: "new" });
|
|
397999
|
+
await eventBus.subscribePattern("custom.>", (event) => journalInternalEvent(db2, event), {
|
|
398000
|
+
...CONSUMER_OPTIONS,
|
|
398001
|
+
durable: "event-persistence-custom",
|
|
398002
|
+
startFrom: "new"
|
|
398003
|
+
});
|
|
398004
|
+
await eventBus.subscribePattern("system.connector.>", (event) => journalInternalEvent(db2, event), {
|
|
398005
|
+
...CONSUMER_OPTIONS,
|
|
398006
|
+
durable: "event-persistence-connector",
|
|
398007
|
+
startFrom: "new"
|
|
398008
|
+
});
|
|
398080
398009
|
log125.info("Event persistence initialized - listening for message events");
|
|
398081
398010
|
} catch (error3) {
|
|
398082
398011
|
log125.error("Failed to set up event persistence", { error: String(error3) });
|
|
398083
398012
|
throw error3;
|
|
398084
398013
|
}
|
|
398085
398014
|
}
|
|
398015
|
+
async function journalInternalEvent(db2, event) {
|
|
398016
|
+
const metadata = event.metadata;
|
|
398017
|
+
try {
|
|
398018
|
+
await runConsumerInTenantContext(db2, event, async () => {
|
|
398019
|
+
const sdb = scopedHandle(db2);
|
|
398020
|
+
const payload = typeof event.payload === "object" && event.payload !== null ? event.payload : {};
|
|
398021
|
+
const instanceId = metadata.instanceId && isValidUuid(metadata.instanceId) ? metadata.instanceId : null;
|
|
398022
|
+
const payloadChatId = typeof payload.chatId === "string" ? payload.chatId : undefined;
|
|
398023
|
+
const personId = await resolvePersonId2(sdb, metadata.personId) ?? await resolvePersonId2(sdb, payload.personId);
|
|
398024
|
+
const chatUuid = await resolveChatUuidById(sdb, payload.chatUuid);
|
|
398025
|
+
const chatLink = chatUuid ? { chatUuid, canonicalChatId: null } : await resolveChatLink(sdb, instanceId ?? undefined, payloadChatId);
|
|
398026
|
+
const newEvent = {
|
|
398027
|
+
...eventIdInsert(event.id),
|
|
398028
|
+
channel: "internal",
|
|
398029
|
+
instanceId,
|
|
398030
|
+
personId,
|
|
398031
|
+
eventType: event.type.slice(0, 255),
|
|
398032
|
+
direction: "internal",
|
|
398033
|
+
status: "completed",
|
|
398034
|
+
receivedAt: new Date(event.timestamp),
|
|
398035
|
+
rawPayload: deepSanitize(payload),
|
|
398036
|
+
metadata: {
|
|
398037
|
+
correlationId: metadata.correlationId,
|
|
398038
|
+
source: metadata.source,
|
|
398039
|
+
fullEventType: event.type
|
|
398040
|
+
},
|
|
398041
|
+
causationId: metadata.causationId ?? null,
|
|
398042
|
+
conversationId: null,
|
|
398043
|
+
chatId: payloadChatId,
|
|
398044
|
+
...chatLink
|
|
398045
|
+
};
|
|
398046
|
+
await sdb.insert(omniEvents).values(newEvent).onConflictDoNothing({ target: omniEvents.id });
|
|
398047
|
+
});
|
|
398048
|
+
} catch (error3) {
|
|
398049
|
+
log125.error("Failed to persist custom event", {
|
|
398050
|
+
eventType: event.type,
|
|
398051
|
+
eventId: event.id,
|
|
398052
|
+
error: String(error3)
|
|
398053
|
+
});
|
|
398054
|
+
}
|
|
398055
|
+
}
|
|
398086
398056
|
var log125, NO_CHAT_LINK, CONSUMER_OPTIONS;
|
|
398087
398057
|
var init_event_persistence = __esm(() => {
|
|
398088
398058
|
init_src();
|
|
@@ -400459,7 +400429,7 @@ function setupScheduler(services, channelRegistry2) {
|
|
|
400459
400429
|
await withCronMonitor("connector-liveness-sweeper", "*/30 * * * * *", 1, 1, async () => {
|
|
400460
400430
|
const startTime3 = Date.now();
|
|
400461
400431
|
try {
|
|
400462
|
-
const stats = await services.webhooks.sweepLiveness(
|
|
400432
|
+
const stats = await services.webhooks.sweepLiveness();
|
|
400463
400433
|
recordScheduledJob("connector-liveness-sweeper", "success", (Date.now() - startTime3) / 1000);
|
|
400464
400434
|
if (stats.stalled > 0 || stats.recovered > 0) {
|
|
400465
400435
|
log131.info("Connector liveness sweep tick", { ...stats });
|
|
@@ -527852,6 +527822,9 @@ function getMediaSize(msg) {
|
|
|
527852
527822
|
var log52 = createLogger("whatsapp:messages");
|
|
527853
527823
|
var fallbackDedupeCache3 = createInboundDedupeCache();
|
|
527854
527824
|
var downloadGuard9 = createDownloadGuard({ maxSizeBytes: getWhatsAppMediaDownloadMaxBytes() });
|
|
527825
|
+
function extractEditedText(edited) {
|
|
527826
|
+
return edited?.conversation || edited?.extendedTextMessage?.text || edited?.imageMessage?.caption || edited?.videoMessage?.caption || edited?.documentMessage?.caption || undefined;
|
|
527827
|
+
}
|
|
527855
527828
|
function joinLines(...parts) {
|
|
527856
527829
|
const text = parts.filter((p2) => typeof p2 === "string" && p2.trim().length > 0).join(`
|
|
527857
527830
|
`);
|
|
@@ -528081,7 +528054,7 @@ var contentExtractors = [
|
|
|
528081
528054
|
return {
|
|
528082
528055
|
type: "edit",
|
|
528083
528056
|
targetMessageId: proto3?.key?.id ?? undefined,
|
|
528084
|
-
editedText: proto3?.editedMessage
|
|
528057
|
+
editedText: extractEditedText(proto3?.editedMessage)
|
|
528085
528058
|
};
|
|
528086
528059
|
}
|
|
528087
528060
|
if (protoType === 0) {
|
|
@@ -528168,6 +528141,20 @@ var contentExtractors = [
|
|
|
528168
528141
|
return null;
|
|
528169
528142
|
}
|
|
528170
528143
|
},
|
|
528144
|
+
{
|
|
528145
|
+
check: (m2) => !!m2.editedMessage,
|
|
528146
|
+
extract: (m2) => {
|
|
528147
|
+
const innerMsg = m2.editedMessage?.message;
|
|
528148
|
+
if (innerMsg) {
|
|
528149
|
+
for (const { check, extract } of contentExtractors.slice(0, -1)) {
|
|
528150
|
+
if (check(innerMsg)) {
|
|
528151
|
+
return extract(innerMsg);
|
|
528152
|
+
}
|
|
528153
|
+
}
|
|
528154
|
+
}
|
|
528155
|
+
return null;
|
|
528156
|
+
}
|
|
528157
|
+
},
|
|
528171
528158
|
{
|
|
528172
528159
|
check: (m2) => !!m2.ephemeralMessage,
|
|
528173
528160
|
extract: (m2) => {
|
|
@@ -528497,13 +528484,6 @@ function setupMessageHandlers4(sock, plugin10, instanceId, decryptTracker, dedup
|
|
|
528497
528484
|
if (update.update.status !== undefined && update.update.status !== null) {
|
|
528498
528485
|
await processStatusUpdate(plugin10, instanceId, update.key, update.update.status);
|
|
528499
528486
|
}
|
|
528500
|
-
if (update.update.message) {
|
|
528501
|
-
const editedContent = update.update.message;
|
|
528502
|
-
const newText = editedContent.conversation || editedContent.extendedTextMessage?.text || editedContent.imageMessage?.caption || editedContent.videoMessage?.caption || null;
|
|
528503
|
-
if (newText) {
|
|
528504
|
-
await plugin10.handleMessageEdited(instanceId, update.key.id || "", update.key.remoteJid || "", newText, update.key.fromMe || false);
|
|
528505
|
-
}
|
|
528506
|
-
}
|
|
528507
528487
|
}
|
|
528508
528488
|
});
|
|
528509
528489
|
sock.ev.on("messages.delete", async (deletion) => {
|