@automagik/omni 2.260904.1 → 2.260904.2

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 CHANGED
@@ -128298,7 +128298,7 @@ import { fileURLToPath } from "url";
128298
128298
  // package.json
128299
128299
  var package_default = {
128300
128300
  name: "@automagik/omni",
128301
- version: "2.260904.1",
128301
+ version: "2.260904.2",
128302
128302
  repository: {
128303
128303
  type: "git",
128304
128304
  url: "git+https://github.com/automagik-dev/omni.git",
@@ -242910,7 +242910,7 @@ var init_sentry_scrub = __esm(() => {
242910
242910
  var require_package7 = __commonJS((exports, module) => {
242911
242911
  module.exports = {
242912
242912
  name: "@omni/api",
242913
- version: "2.260904.1",
242913
+ version: "2.260904.2",
242914
242914
  type: "module",
242915
242915
  exports: {
242916
242916
  ".": {
@@ -344750,7 +344750,7 @@ async function sendTypingPresence(channel5, instanceId, chatId, state) {
344750
344750
  log91.debug("Failed to send typing presence", { error: String(error3) });
344751
344751
  }
344752
344752
  }
344753
- async function sendTextMessage5(channel5, instanceId, chatId, text3, messageFormatMode = "convert", replyTo, correlationId, senderAgentId, systemNotice) {
344753
+ async function sendTextMessage5(channel5, instanceId, chatId, text3, messageFormatMode = "convert", replyTo, correlationId, senderAgentId, systemNotice, part) {
344754
344754
  const plugin11 = await getPlugin(channel5);
344755
344755
  if (!plugin11)
344756
344756
  throw new Error(`Channel plugin not found: ${channel5}`);
@@ -344761,7 +344761,13 @@ async function sendTextMessage5(channel5, instanceId, chatId, text3, messageForm
344761
344761
  to: chatId,
344762
344762
  content: { type: "text", text: sanitized },
344763
344763
  replyTo,
344764
- metadata: { messageFormatMode, correlationId, senderAgentId, systemNotice }
344764
+ metadata: {
344765
+ messageFormatMode,
344766
+ correlationId,
344767
+ senderAgentId,
344768
+ systemNotice,
344769
+ ...part ? { partIndex: part.index, partCount: part.count } : {}
344770
+ }
344765
344771
  });
344766
344772
  }
344767
344773
  function resolveDispatchErrorMessage(instanceErrorMessages, env2 = process.env, random = Math.random) {
@@ -345223,14 +345229,15 @@ function isSelfChat(chatId, ownerIdentifier) {
345223
345229
  }
345224
345230
  async function sendResponseParts(channel5, instanceId, chatId, parts, splitConfig, messageFormatMode = "convert", replyTo, correlationId, senderAgentId) {
345225
345231
  const messageLimit = getMessageLimit(channel5);
345226
- const allChunks = [];
345232
+ const chunked = [];
345227
345233
  for (const part of parts) {
345228
- allChunks.push(...chunkText(part, messageLimit));
345234
+ chunked.push(...chunkText(part, messageLimit));
345229
345235
  }
345236
+ const allChunks = chunked.map((chunk2) => sanitizeOutboundText(chunk2)).filter(Boolean);
345230
345237
  const isSlack = channel5 === "slack";
345231
345238
  for (const [index2, chunk2] of allChunks.entries()) {
345232
345239
  const chunkReplyTo = isSlack || index2 === 0 ? replyTo : undefined;
345233
- await sendTextMessage5(channel5, instanceId, chatId, chunk2, messageFormatMode, chunkReplyTo, correlationId, senderAgentId);
345240
+ await sendTextMessage5(channel5, instanceId, chatId, chunk2, messageFormatMode, chunkReplyTo, correlationId, senderAgentId, undefined, { index: index2, count: allChunks.length });
345234
345241
  const isLastChunk = index2 === allChunks.length - 1;
345235
345242
  if (!isLastChunk) {
345236
345243
  const delay2 = calculateSplitDelay(splitConfig);
@@ -380572,6 +380579,23 @@ function resolveOutboundText(message2) {
380572
380579
  const formatted = formatMode === "passthrough" ? text : markdownToWhatsApp(text);
380573
380580
  return encodeAscEmoji(formatted);
380574
380581
  }
380582
+ function collectTurnParts(message2, turn) {
380583
+ const meta = message2.metadata ?? {};
380584
+ const partCount = Number(meta.partCount ?? 1);
380585
+ const partIndex = Number(meta.partIndex ?? 0);
380586
+ if (!turn || message2.content.type !== "text" || !(partCount > 1) || !(partIndex >= 0))
380587
+ return message2;
380588
+ const part = message2.content.text ?? "";
380589
+ if (partIndex < partCount - 1) {
380590
+ turn.parts = [...turn.parts ?? [], part];
380591
+ return null;
380592
+ }
380593
+ const text = [...turn.parts ?? [], part].join(`
380594
+
380595
+ `);
380596
+ turn.parts = undefined;
380597
+ return { ...message2, content: { ...message2.content, text } };
380598
+ }
380575
380599
  function listOptionsOf(content) {
380576
380600
  return {
380577
380601
  ...content.list?.sectionTitle !== undefined ? { sectionTitle: content.list.sectionTitle } : {},
@@ -380688,9 +380712,8 @@ class AscFlowPlugin extends BaseChannelPlugin {
380688
380712
  if (!state) {
380689
380713
  return { success: false, error: "ASC Flow instance not connected", retryable: false, timestamp: Date.now() };
380690
380714
  }
380691
- const { content, to } = message2;
380715
+ const { to } = message2;
380692
380716
  const meta = message2.metadata ?? {};
380693
- const text = resolveOutboundText(message2);
380694
380717
  const correlationId = meta.correlationId;
380695
380718
  if (correlationId)
380696
380719
  this.captureT10(correlationId);
@@ -380698,12 +380721,24 @@ class AscFlowPlugin extends BaseChannelPlugin {
380698
380721
  const cod = toCodAtendimento(to);
380699
380722
  const answering = state.inFlight.get(to.trim());
380700
380723
  const polling = answering !== undefined && answering.text !== "";
380701
- const { rich, bubbles } = await this.prepareTurn(message2, text);
380724
+ const turnMessage = collectTurnParts(message2, polling ? answering : undefined);
380725
+ if (!turnMessage)
380726
+ return { success: true, timestamp: Date.now() };
380727
+ const content = turnMessage.content;
380728
+ const text = resolveOutboundText(turnMessage);
380729
+ const { rich, bubbles } = await this.prepareTurn(turnMessage, text);
380702
380730
  const lastBubble = bubbles[bubbles.length - 1] ?? "";
380703
380731
  const ura = rich ? null : buildUra(lastBubble, content.buttons, listOptionsOf(content));
380704
380732
  if (!rich && !ura && !polling)
380705
380733
  return this.refuseUndeliverable(instanceId, to, content.type);
380706
- const { delivered } = await this.deliver(state, cod, { text, bubbles, lastBubble, rich, ura, message: message2 });
380734
+ const { delivered } = await this.deliver(state, cod, {
380735
+ text,
380736
+ bubbles,
380737
+ lastBubble,
380738
+ rich,
380739
+ ura,
380740
+ message: turnMessage
380741
+ });
380707
380742
  const handoff = meta.isHandoff === true ? await this.runHandoff(state, instanceId, cod, meta, delivered ? "" : lastBubble) : null;
380708
380743
  const handoffRefused = meta.isHandoff === true && handoff === null;
380709
380744
  this.resolveTurn(state, to, buildReadyBody({ delivered, lastBubble, bubbles, handoff, ura }), answering, correlationId);
@@ -380712,7 +380747,7 @@ class AscFlowPlugin extends BaseChannelPlugin {
380712
380747
  if (correlationId)
380713
380748
  this.captureT11(correlationId);
380714
380749
  const messageId = crypto.randomUUID();
380715
- await this.emitTurnSent(instanceId, message2, messageId, {
380750
+ await this.emitTurnSent(instanceId, turnMessage, messageId, {
380716
380751
  cod,
380717
380752
  bubbles: bubbles.length,
380718
380753
  ura,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automagik/omni",
3
- "version": "2.260904.1",
3
+ "version": "2.260904.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/automagik-dev/omni.git",