@automagik/omni 2.260910.15 → 2.260910.17

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.
@@ -44884,30 +44884,42 @@ class BaseChannelPlugin {
44884
44884
  timings,
44885
44885
  ingestMode: isHistorySync ? "history-sync" : "realtime"
44886
44886
  };
44887
- if (this.ingressClaim) {
44888
- const idempotencyKey = `${this.id}:${instanceId}:${payload.externalId}:${payload.content.type}`;
44889
- const eventId = await this.ingressClaim.claim({
44890
- idempotencyKey,
44887
+ return this.publishClaimed("message.received", payload, instanceId, {
44888
+ idempotencyKey: `${this.id}:${instanceId}:${payload.externalId}:${payload.content.type}`,
44889
+ externalId: payload.externalId,
44890
+ options
44891
+ });
44892
+ }
44893
+ async publishClaimed(type, payload, instanceId, params) {
44894
+ const { idempotencyKey, externalId, options = {} } = params;
44895
+ if (!this.ingressClaim) {
44896
+ return this.publishEventInternal(type, payload, instanceId, options);
44897
+ }
44898
+ const eventId = await this.ingressClaim.claim({
44899
+ idempotencyKey,
44900
+ instanceId,
44901
+ channelType: this.id,
44902
+ externalId,
44903
+ eventType: type
44904
+ });
44905
+ if (eventId === null) {
44906
+ this.logger.info(`Skipping duplicate inbound ${type} (idempotency key already journaled)`, {
44891
44907
  instanceId,
44892
- channelType: this.id,
44893
- externalId: payload.externalId
44908
+ idempotencyKey
44894
44909
  });
44895
- if (eventId === null) {
44896
- this.logger.info("Skipping duplicate inbound message (idempotency key already journaled)", {
44897
- instanceId,
44898
- idempotencyKey
44899
- });
44900
- return generateCorrelationId("evt");
44901
- }
44902
- options.publishEventId = eventId;
44903
- try {
44904
- return await this.publishEventInternal("message.received", payload, instanceId, options);
44905
- } catch (error) {
44906
- await this.ingressClaim.release(eventId).catch(() => {});
44907
- throw error;
44908
- }
44910
+ return generateCorrelationId("evt");
44909
44911
  }
44910
- return this.publishEventInternal("message.received", payload, instanceId, options);
44912
+ try {
44913
+ return await this.publishEventInternal(type, payload, instanceId, { ...options, publishEventId: eventId });
44914
+ } catch (error) {
44915
+ await this.ingressClaim.release(eventId).catch(() => {});
44916
+ throw error;
44917
+ }
44918
+ }
44919
+ reactionClaimParams(kind, instanceId, payload) {
44920
+ const raw = payload.rawPayload?.externalId;
44921
+ const externalId = typeof raw === "string" && raw.length > 0 ? raw : `${payload.messageId}:${payload.from}`;
44922
+ return { idempotencyKey: `${this.id}:${instanceId}:${externalId}:${kind}:${payload.emoji}`, externalId };
44911
44923
  }
44912
44924
  async emitMessageSent(params) {
44913
44925
  const { instanceId, ...payload } = params;
@@ -44928,11 +44940,11 @@ class BaseChannelPlugin {
44928
44940
  }
44929
44941
  async emitReactionReceived(params) {
44930
44942
  const { instanceId, ...payload } = params;
44931
- await this.publishEventInternal("reaction.received", payload, instanceId);
44943
+ await this.publishClaimed("reaction.received", payload, instanceId, this.reactionClaimParams("reaction.received", instanceId, payload));
44932
44944
  }
44933
44945
  async emitReactionRemoved(params) {
44934
44946
  const { instanceId, ...payload } = params;
44935
- await this.publishEventInternal("reaction.removed", payload, instanceId);
44947
+ await this.publishClaimed("reaction.removed", payload, instanceId, this.reactionClaimParams("reaction.removed", instanceId, payload));
44936
44948
  }
44937
44949
  async emitMessagePinned(params) {
44938
44950
  const { instanceId, ...payload } = params;
@@ -76973,7 +76985,7 @@ var require_ClientVoiceManager = __commonJS((exports, module) => {
76973
76985
 
76974
76986
  // ../../node_modules/.bun/@discordjs+ws@1.2.3/node_modules/@discordjs/ws/dist/index.js
76975
76987
  var require_dist9 = __commonJS((exports, module) => {
76976
- var __dirname = "/home/runner/work/omni/omni/.stable-source/node_modules/.bun/@discordjs+ws@1.2.3/node_modules/@discordjs/ws/dist";
76988
+ var __dirname = "/home/runner/work/omni/omni/node_modules/.bun/@discordjs+ws@1.2.3/node_modules/@discordjs/ws/dist";
76977
76989
  var __create2 = Object.create;
76978
76990
  var __defProp2 = Object.defineProperty;
76979
76991
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
@@ -162253,7 +162265,7 @@ var require_indexes = __commonJS((exports, module) => {
162253
162265
 
162254
162266
  // ../../node_modules/.bun/thread-stream@3.1.0/node_modules/thread-stream/index.js
162255
162267
  var require_thread_stream = __commonJS((exports, module) => {
162256
- var __dirname = "/home/runner/work/omni/omni/.stable-source/node_modules/.bun/thread-stream@3.1.0/node_modules/thread-stream";
162268
+ var __dirname = "/home/runner/work/omni/omni/node_modules/.bun/thread-stream@3.1.0/node_modules/thread-stream";
162257
162269
  var { version } = require_package5();
162258
162270
  var { EventEmitter: EventEmitter3 } = __require("events");
162259
162271
  var { Worker } = __require("worker_threads");
@@ -162674,7 +162686,7 @@ var require_thread_stream = __commonJS((exports, module) => {
162674
162686
 
162675
162687
  // ../../node_modules/.bun/pino@9.14.0/node_modules/pino/lib/transport.js
162676
162688
  var require_transport2 = __commonJS((exports, module) => {
162677
- var __dirname = "/home/runner/work/omni/omni/.stable-source/node_modules/.bun/pino@9.14.0/node_modules/pino/lib";
162689
+ var __dirname = "/home/runner/work/omni/omni/node_modules/.bun/pino@9.14.0/node_modules/pino/lib";
162678
162690
  var { createRequire: createRequire2 } = __require("module");
162679
162691
  var getCallers = require_caller();
162680
162692
  var { join: join8, isAbsolute, sep: sep2 } = __require("path");
@@ -244419,7 +244431,7 @@ var require_client3 = __commonJS((exports) => {
244419
244431
 
244420
244432
  // ../../node_modules/.bun/@sentry+node-core@10.52.0+2c50d7e904f6cfd7/node_modules/@sentry/node-core/build/cjs/sdk/esmLoader.js
244421
244433
  var require_esmLoader = __commonJS((exports) => {
244422
- var __filename = "/home/runner/work/omni/omni/.stable-source/node_modules/.bun/@sentry+node-core@10.52.0+2c50d7e904f6cfd7/node_modules/@sentry/node-core/build/cjs/sdk/esmLoader.js";
244434
+ var __filename = "/home/runner/work/omni/omni/node_modules/.bun/@sentry+node-core@10.52.0+2c50d7e904f6cfd7/node_modules/@sentry/node-core/build/cjs/sdk/esmLoader.js";
244423
244435
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
244424
244436
  var core3 = require_cjs6();
244425
244437
  var importInTheMiddle = require_import_in_the_middle();
@@ -251645,7 +251657,7 @@ var init_sentry_scrub = __esm(() => {
251645
251657
  var require_package7 = __commonJS((exports, module) => {
251646
251658
  module.exports = {
251647
251659
  name: "@omni/api",
251648
- version: "2.260910.15",
251660
+ version: "2.260910.17",
251649
251661
  private: true,
251650
251662
  type: "module",
251651
251663
  exports: {
@@ -278747,7 +278759,7 @@ var require_src45 = __commonJS((exports) => {
278747
278759
 
278748
278760
  // ../../node_modules/.bun/@grpc+grpc-js@1.14.3/node_modules/@grpc/grpc-js/build/src/channelz.js
278749
278761
  var require_channelz = __commonJS((exports) => {
278750
- var __dirname = "/home/runner/work/omni/omni/.stable-source/node_modules/.bun/@grpc+grpc-js@1.14.3/node_modules/@grpc/grpc-js/build/src";
278762
+ var __dirname = "/home/runner/work/omni/omni/node_modules/.bun/@grpc+grpc-js@1.14.3/node_modules/@grpc/grpc-js/build/src";
278751
278763
  Object.defineProperty(exports, "__esModule", { value: true });
278752
278764
  exports.registerChannelzSocket = exports.registerChannelzServer = exports.registerChannelzSubchannel = exports.registerChannelzChannel = exports.ChannelzCallTrackerStub = exports.ChannelzCallTracker = exports.ChannelzChildrenTrackerStub = exports.ChannelzChildrenTracker = exports.ChannelzTrace = exports.ChannelzTraceStub = undefined;
278753
278765
  exports.unregisterChannelzRef = unregisterChannelzRef;
@@ -284150,7 +284162,7 @@ var require_duration = __commonJS((exports) => {
284150
284162
 
284151
284163
  // ../../node_modules/.bun/@grpc+grpc-js@1.14.3/node_modules/@grpc/grpc-js/build/src/orca.js
284152
284164
  var require_orca = __commonJS((exports) => {
284153
- var __dirname = "/home/runner/work/omni/omni/.stable-source/node_modules/.bun/@grpc+grpc-js@1.14.3/node_modules/@grpc/grpc-js/build/src";
284165
+ var __dirname = "/home/runner/work/omni/omni/node_modules/.bun/@grpc+grpc-js@1.14.3/node_modules/@grpc/grpc-js/build/src";
284154
284166
  Object.defineProperty(exports, "__esModule", { value: true });
284155
284167
  exports.OrcaOobMetricsSubchannelWrapper = exports.GRPC_METRICS_HEADER = exports.ServerMetricRecorder = exports.PerRequestMetricRecorder = undefined;
284156
284168
  exports.createOrcaClient = createOrcaClient;
@@ -363161,7 +363173,7 @@ function createPluginDatabase(db2) {
363161
363173
  }
363162
363174
  function createIngressClaim(db2) {
363163
363175
  return {
363164
- async claim({ idempotencyKey, instanceId, channelType, externalId }) {
363176
+ async claim({ idempotencyKey, instanceId, channelType, externalId, eventType = "message.received" }) {
363165
363177
  const id = randomUUID2();
363166
363178
  try {
363167
363179
  const claimed = await db2.insert(omniEvents).values({
@@ -363169,7 +363181,7 @@ function createIngressClaim(db2) {
363169
363181
  externalId,
363170
363182
  channel: channelTypes.includes(channelType) ? channelType : "discord",
363171
363183
  instanceId,
363172
- eventType: "message.received",
363184
+ eventType,
363173
363185
  direction: "inbound",
363174
363186
  status: "received",
363175
363187
  idempotencyKey,
@@ -398350,8 +398362,7 @@ async function setupEventPersistence(eventBus, db2) {
398350
398362
  const sdb = scopedHandle(db2);
398351
398363
  const chatLink = await resolveChatLink(sdb, metadata.instanceId, payload.chatId);
398352
398364
  const personId = await resolvePersonId2(sdb, metadata.personId);
398353
- const newEvent = {
398354
- ...eventIdInsert(event.id),
398365
+ const columns2 = {
398355
398366
  externalId: payload.messageId,
398356
398367
  channel: mapChannelType(metadata.channelType),
398357
398368
  instanceId: metadata.instanceId,
@@ -398369,7 +398380,7 @@ async function setupEventPersistence(eventBus, db2) {
398369
398380
  conversationId: null,
398370
398381
  ...chatLink
398371
398382
  };
398372
- await sdb.insert(omniEvents).values(newEvent).onConflictDoNothing({ target: omniEvents.id });
398383
+ await sdb.insert(omniEvents).values({ ...eventIdInsert(event.id), ...columns2 }).onConflictDoUpdate({ target: omniEvents.id, set: columns2 });
398373
398384
  });
398374
398385
  log126.debug(`Persisted ${type}`, { messageId: payload.messageId, emoji: payload.emoji });
398375
398386
  } catch (error3) {
@@ -528518,63 +528529,6 @@ var contentExtractors = [
528518
528529
  {
528519
528530
  check: (m2) => !!m2.messageHistoryBundle,
528520
528531
  extract: () => null
528521
- },
528522
- {
528523
- check: (m2) => !!m2.deviceSentMessage,
528524
- extract: (m2) => {
528525
- const deviceMsg = m2.deviceSentMessage;
528526
- const innerMsg = deviceMsg?.message;
528527
- if (innerMsg) {
528528
- for (const { check, extract } of contentExtractors.slice(0, -3)) {
528529
- if (check(innerMsg)) {
528530
- return extract(innerMsg);
528531
- }
528532
- }
528533
- }
528534
- return null;
528535
- }
528536
- },
528537
- {
528538
- check: (m2) => !!m2.editedMessage,
528539
- extract: (m2) => {
528540
- const innerMsg = m2.editedMessage?.message;
528541
- if (innerMsg) {
528542
- for (const { check, extract } of contentExtractors.slice(0, -1)) {
528543
- if (check(innerMsg)) {
528544
- return extract(innerMsg);
528545
- }
528546
- }
528547
- }
528548
- return null;
528549
- }
528550
- },
528551
- {
528552
- check: (m2) => !!m2.ephemeralMessage,
528553
- extract: (m2) => {
528554
- const innerMsg = m2.ephemeralMessage?.message;
528555
- if (innerMsg) {
528556
- for (const { check, extract } of contentExtractors.slice(0, -1)) {
528557
- if (check(innerMsg)) {
528558
- return extract(innerMsg);
528559
- }
528560
- }
528561
- }
528562
- return null;
528563
- }
528564
- },
528565
- {
528566
- check: (m2) => !!m2.viewOnceMessage,
528567
- extract: (m2) => {
528568
- const innerMsg = m2.viewOnceMessage?.message;
528569
- if (innerMsg) {
528570
- for (const { check, extract } of contentExtractors.slice(0, -1)) {
528571
- if (check(innerMsg)) {
528572
- return extract(innerMsg);
528573
- }
528574
- }
528575
- }
528576
- return null;
528577
- }
528578
528532
  }
528579
528533
  ];
528580
528534
  var INTERNAL_MESSAGE_TYPES = new Set([
@@ -528598,10 +528552,33 @@ function extractUnknownContent(message2) {
528598
528552
  log52.debug("Unknown message type", { keys: messageKeys });
528599
528553
  return { type: "unknown" };
528600
528554
  }
528555
+ var ENVELOPE_KEYS = [
528556
+ "deviceSentMessage",
528557
+ "ephemeralMessage",
528558
+ "viewOnceMessage",
528559
+ "viewOnceMessageV2",
528560
+ "viewOnceMessageV2Extension",
528561
+ "editedMessage",
528562
+ "documentWithCaptionMessage",
528563
+ "associatedChildMessage",
528564
+ "groupStatusMessage",
528565
+ "groupStatusMessageV2"
528566
+ ];
528567
+ function unwrapEnvelopes(message2) {
528568
+ let current = message2;
528569
+ for (let depth = 0;depth < 5; depth++) {
528570
+ const record2 = current;
528571
+ const key = ENVELOPE_KEYS.find((k2) => record2[k2]?.message);
528572
+ if (!key)
528573
+ break;
528574
+ current = record2[key]?.message;
528575
+ }
528576
+ return current;
528577
+ }
528601
528578
  function extractContent3(msg) {
528602
- const message2 = msg.message;
528603
- if (!message2)
528579
+ if (!msg.message)
528604
528580
  return null;
528581
+ const message2 = unwrapEnvelopes(msg.message);
528605
528582
  for (const { check, extract } of contentExtractors) {
528606
528583
  if (check(message2)) {
528607
528584
  const result = extract(message2);
@@ -528715,8 +528692,11 @@ async function handleSpecialMessage(plugin10, instanceId, content, externalId, c
528715
528692
  await plugin10.handleReactionReceived(instanceId, externalId, chatId, senderId, content.emoji || "", content.targetMessageId || "", isFromMe(msg));
528716
528693
  return true;
528717
528694
  }
528718
- if (content.type === "edit" && content.targetMessageId) {
528719
- await plugin10.handleMessageEdited(instanceId, content.targetMessageId, chatId, content.editedText || content.text || "", isFromMe(msg));
528695
+ if (content.type === "edit") {
528696
+ log52.debug("Edit protocol message seen on upsert; awaiting messages.update", {
528697
+ instanceId,
528698
+ targetMessageId: content.targetMessageId
528699
+ });
528720
528700
  return true;
528721
528701
  }
528722
528702
  if (content.type === "delete" && content.targetMessageId) {
@@ -528890,6 +528870,11 @@ function setupMessageHandlers4(sock, plugin10, instanceId, decryptTracker, dedup
528890
528870
  if (update.update.status !== undefined && update.update.status !== null) {
528891
528871
  await processStatusUpdate(plugin10, instanceId, update.key, update.update.status);
528892
528872
  }
528873
+ const newText = extractEditedText(normalizeMessageContent(update.update.message));
528874
+ if (newText) {
528875
+ const { chatId } = resolveChatId(plugin10, instanceId, { key: update.key });
528876
+ await plugin10.handleMessageEdited(instanceId, update.key.id || "", chatId, newText, update.key.fromMe || false);
528877
+ }
528893
528878
  }
528894
528879
  });
528895
528880
  sock.ev.on("messages.delete", async (deletion) => {
@@ -531791,7 +531776,8 @@ class WhatsAppPlugin extends BaseChannelPlugin {
531791
531776
  messageId: targetMessageId,
531792
531777
  chatId,
531793
531778
  from,
531794
- emoji: ""
531779
+ emoji: "",
531780
+ rawPayload: { externalId, isFromMe: isFromMe2 }
531795
531781
  });
531796
531782
  }
531797
531783
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automagik/omni",
3
- "version": "2.260910.15",
3
+ "version": "2.260910.17",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/automagik-dev/omni.git",