@automagik/omni 2.260531.5 → 2.260601.1

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
@@ -124967,7 +124967,7 @@ import { fileURLToPath } from "url";
124967
124967
  // package.json
124968
124968
  var package_default = {
124969
124969
  name: "@automagik/omni",
124970
- version: "2.260531.5",
124970
+ version: "2.260601.1",
124971
124971
  description: "LLM-optimized CLI for Omni",
124972
124972
  type: "module",
124973
124973
  bin: {
@@ -225241,7 +225241,7 @@ var init_sentry_scrub = __esm(() => {
225241
225241
  var require_package7 = __commonJS((exports, module) => {
225242
225242
  module.exports = {
225243
225243
  name: "@omni/api",
225244
- version: "2.260531.5",
225244
+ version: "2.260601.1",
225245
225245
  type: "module",
225246
225246
  exports: {
225247
225247
  ".": {
@@ -337846,6 +337846,18 @@ function emitLifecycleSpan(name, attributes) {
337846
337846
  return;
337847
337847
  }).catch(() => {});
337848
337848
  }
337849
+ function activeProviderTraceContext() {
337850
+ const activeSpan = import_api32.trace.getActiveSpan();
337851
+ const spanContext = activeSpan?.spanContext();
337852
+ if (!spanContext?.traceId || !spanContext?.spanId)
337853
+ return;
337854
+ return {
337855
+ traceId: spanContext.traceId,
337856
+ spanId: spanContext.spanId,
337857
+ traceFlags: spanContext.traceFlags,
337858
+ traceState: spanContext.traceState?.serialize()
337859
+ };
337860
+ }
337849
337861
  function createPluginAckProvider(plugin7) {
337850
337862
  if (!plugin7?.react || !plugin7?.unreact)
337851
337863
  return null;
@@ -338982,63 +338994,76 @@ async function dispatchViaProvider(services, instance4, messages4, triggerType,
338982
338994
  inputText: messageTexts.join(`
338983
338995
  `)
338984
338996
  };
338985
- emitLifecycleSpan("omni.provider_inbound", buildLifecycleSpanAttributes({
338997
+ return withLifecycleSpan("omni.turn", buildLifecycleSpanAttributes({
338986
338998
  ...lifecycleBase,
338987
- stage: "provider_inbound",
338988
- extra: { trigger_type: triggerType, message_count: messages4.length }
338989
- }));
338990
- if (provider.mode === "turn-based") {
338991
- return dispatchViaTurnBasedProvider(services, instance4, provider, trigger, messages4, chatId, traceId, db2);
338992
- }
338993
- const correlationId = messages4[0]?.metadata.correlationId;
338994
- const dispatchStart = Date.now();
338995
- const result = await withLifecycleSpan("omni.dispatch_to_agno", buildLifecycleSpanAttributes({
338996
- ...lifecycleBase,
338997
- stage: "dispatch_to_agno",
338998
- extra: { trigger_type: triggerType, provider_id: provider.id, provider_schema: provider.schema }
338999
- }), () => provider.trigger(trigger));
339000
- const dispatchDurationMs = Date.now() - dispatchStart;
339001
- if (sentryEnabled()) {
339002
- exports_public_api2.count("agent.dispatch", 1, { attributes: { provider_type: provider.schema } });
339003
- exports_public_api2.distribution("agent.dispatch.latency", dispatchDurationMs, {
339004
- unit: "millisecond",
339005
- attributes: { provider_type: provider.schema }
339006
- });
339007
- }
339008
- const chatAfterRun = await services.chats.findByExternalIdSmart(instance4.id, chatId);
339009
- const handoffTriggered = chatAfterRun?.settings?.agentPaused === true;
339010
- if (result && result.parts.length > 0 && !handoffTriggered) {
339011
- const selfChat = isSelfChat(chatId, instance4.ownerIdentifier);
339012
- const rawParts = selfChat ? result.parts.map((p2) => `${BOT_PREFIX}${p2}`) : result.parts;
339013
- const parts = await Promise.all(rawParts.map((part) => executeBeforeMessageWriteHooks(instance4.id, chatId, part)));
339014
- const _fmtMode = instance4.messageFormatMode ?? "convert";
339015
- const replyTo = messages4[0]?.payload.replyToId ?? messages4[0]?.payload.externalId;
339016
- recordJourneyCheckpoint(correlationId, "T8", JOURNEY_STAGES.T8);
339017
- await withLifecycleSpan("omni.provider_outbound", buildLifecycleSpanAttributes({
338999
+ stage: "turn",
339000
+ extra: {
339001
+ trigger_type: triggerType,
339002
+ message_count: messages4.length,
339003
+ provider_id: provider.id,
339004
+ provider_schema: provider.schema
339005
+ }
339006
+ }), async () => {
339007
+ await withLifecycleSpan("omni.provider_inbound", buildLifecycleSpanAttributes({
339008
+ ...lifecycleBase,
339009
+ stage: "provider_inbound",
339010
+ extra: { trigger_type: triggerType, message_count: messages4.length }
339011
+ }), async () => {
339012
+ return;
339013
+ });
339014
+ if (provider.mode === "turn-based") {
339015
+ return dispatchViaTurnBasedProvider(services, instance4, provider, trigger, messages4, chatId, traceId, db2);
339016
+ }
339017
+ const correlationId = messages4[0]?.metadata.correlationId;
339018
+ const dispatchStart = Date.now();
339019
+ const result = await withLifecycleSpan("omni.dispatch_to_agno", buildLifecycleSpanAttributes({
339018
339020
  ...lifecycleBase,
339019
- stage: "provider_outbound",
339020
- outputText: parts.join(`
339021
+ stage: "dispatch_to_agno",
339022
+ extra: { trigger_type: triggerType, provider_id: provider.id, provider_schema: provider.schema }
339023
+ }), () => provider.trigger({ ...trigger, traceContext: activeProviderTraceContext() ?? trigger.traceContext }));
339024
+ const dispatchDurationMs = Date.now() - dispatchStart;
339025
+ if (sentryEnabled()) {
339026
+ exports_public_api2.count("agent.dispatch", 1, { attributes: { provider_type: provider.schema } });
339027
+ exports_public_api2.distribution("agent.dispatch.latency", dispatchDurationMs, {
339028
+ unit: "millisecond",
339029
+ attributes: { provider_type: provider.schema }
339030
+ });
339031
+ }
339032
+ const chatAfterRun = await services.chats.findByExternalIdSmart(instance4.id, chatId);
339033
+ const handoffTriggered = chatAfterRun?.settings?.agentPaused === true;
339034
+ if (result && result.parts.length > 0 && !handoffTriggered) {
339035
+ const selfChat = isSelfChat(chatId, instance4.ownerIdentifier);
339036
+ const rawParts = selfChat ? result.parts.map((p2) => `${BOT_PREFIX}${p2}`) : result.parts;
339037
+ const parts = await Promise.all(rawParts.map((part) => executeBeforeMessageWriteHooks(instance4.id, chatId, part)));
339038
+ const _fmtMode = instance4.messageFormatMode ?? "convert";
339039
+ const replyTo = messages4[0]?.payload.replyToId ?? messages4[0]?.payload.externalId;
339040
+ recordJourneyCheckpoint(correlationId, "T8", JOURNEY_STAGES.T8);
339041
+ await withLifecycleSpan("omni.provider_outbound", buildLifecycleSpanAttributes({
339042
+ ...lifecycleBase,
339043
+ stage: "provider_outbound",
339044
+ outputText: parts.join(`
339021
339045
  `),
339022
- extra: { parts_count: parts.length, provider_id: provider.id, provider_schema: provider.schema }
339023
- }), () => sendResponseParts(channel5, instance4.id, chatId, parts, getSplitDelayConfig(instance4), _fmtMode, replyTo, correlationId, senderAgentId));
339024
- recordJourneyCheckpoint(correlationId, "T9", JOURNEY_STAGES.T9);
339025
- await forwardToChainedInstance(instance4, parts, correlationId, messages4);
339026
- } else if (handoffTriggered) {
339027
- log99.info("Agent response suppressed \u2014 handoff triggered during run", {
339046
+ extra: { parts_count: parts.length, provider_id: provider.id, provider_schema: provider.schema }
339047
+ }), () => sendResponseParts(channel5, instance4.id, chatId, parts, getSplitDelayConfig(instance4), _fmtMode, replyTo, correlationId, senderAgentId));
339048
+ recordJourneyCheckpoint(correlationId, "T9", JOURNEY_STAGES.T9);
339049
+ await forwardToChainedInstance(instance4, parts, correlationId, messages4);
339050
+ } else if (handoffTriggered) {
339051
+ log99.info("Agent response suppressed \u2014 handoff triggered during run", {
339052
+ instanceId: instance4.id,
339053
+ chatId
339054
+ });
339055
+ }
339056
+ log99.info("Agent response via IAgentProvider", {
339028
339057
  instanceId: instance4.id,
339029
- chatId
339058
+ chatId,
339059
+ parts: result?.parts.length ?? 0,
339060
+ providerId: result?.metadata.providerId,
339061
+ durationMs: result?.metadata.durationMs,
339062
+ triggerType,
339063
+ traceId
339030
339064
  });
339031
- }
339032
- log99.info("Agent response via IAgentProvider", {
339033
- instanceId: instance4.id,
339034
- chatId,
339035
- parts: result?.parts.length ?? 0,
339036
- providerId: result?.metadata.providerId,
339037
- durationMs: result?.metadata.durationMs,
339038
- triggerType,
339039
- traceId
339065
+ return true;
339040
339066
  });
339041
- return true;
339042
339067
  }
339043
339068
  async function dispatchViaLegacy(services, instance4, messages4, triggerType, channel5, chatId, senderId, personId, senderName, traceId, perThreadExtraContext, senderAgentId) {
339044
339069
  const { messageTexts, mediaFiles } = await prepareAgentContent(services, instance4, messages4);
@@ -355645,6 +355670,67 @@ function extractReactionTargetParticipant(rawPayload) {
355645
355670
  const participant = key?.participant;
355646
355671
  return typeof participant === "string" && participant.length > 0 ? participant : undefined;
355647
355672
  }
355673
+ async function resolveReactionTarget(services, instanceId, resolvedTo, messageId) {
355674
+ const metadata = {};
355675
+ const chat2 = await services.chats.findByExternalIdSmart(instanceId, resolvedTo);
355676
+ if (!chat2) {
355677
+ if (isUUID(messageId)) {
355678
+ throw new OmniError({
355679
+ code: ERROR_CODES.NOT_FOUND,
355680
+ message: `Reaction target message not found: ${messageId}`,
355681
+ context: { instanceId, resolvedTo, messageId },
355682
+ recoverable: false
355683
+ });
355684
+ }
355685
+ log110.warn("Reaction target chat not found in DB; deferring fromMe to channel plugin fallback (#386)", {
355686
+ instanceId,
355687
+ resolvedTo,
355688
+ messageId,
355689
+ fallback: "plugin-heuristic"
355690
+ });
355691
+ return { targetMessageId: messageId, metadata };
355692
+ }
355693
+ const target = isUUID(messageId) ? await getReactionTargetByOmniId(services, instanceId, chat2.id, messageId) : await services.messages.getByExternalId(chat2.id, messageId);
355694
+ if (!target) {
355695
+ log110.warn("Reaction target message not found in DB; deferring fromMe to channel plugin fallback (#386)", {
355696
+ instanceId,
355697
+ chatId: chat2.id,
355698
+ messageId,
355699
+ fallback: "plugin-heuristic"
355700
+ });
355701
+ return { targetMessageId: messageId, metadata };
355702
+ }
355703
+ metadata.fromMe = target.isFromMe === true;
355704
+ if (target.isFromMe !== true) {
355705
+ const participant = extractReactionTargetParticipant(target.rawPayload);
355706
+ if (participant)
355707
+ metadata.targetParticipant = participant;
355708
+ }
355709
+ return { targetMessageId: target.externalId, metadata };
355710
+ }
355711
+ async function getReactionTargetByOmniId(services, instanceId, chatId, messageId) {
355712
+ let target;
355713
+ try {
355714
+ target = await services.messages.getById(messageId);
355715
+ } catch (error3) {
355716
+ if (error3 instanceof NotFoundError) {
355717
+ throw reactionTargetNotFound(instanceId, chatId, messageId);
355718
+ }
355719
+ throw error3;
355720
+ }
355721
+ if (target.chatId !== chatId) {
355722
+ throw reactionTargetNotFound(instanceId, chatId, messageId);
355723
+ }
355724
+ return target;
355725
+ }
355726
+ function reactionTargetNotFound(instanceId, chatId, messageId) {
355727
+ return new OmniError({
355728
+ code: ERROR_CODES.NOT_FOUND,
355729
+ message: `Reaction target message not found: ${messageId}`,
355730
+ context: { instanceId, chatId, messageId },
355731
+ recoverable: false
355732
+ });
355733
+ }
355648
355734
  async function resolveRecipient(to, channelType, services) {
355649
355735
  if (!isUUID(to))
355650
355736
  return to;
@@ -356401,39 +356487,13 @@ var init_messages5 = __esm(() => {
356401
356487
  });
356402
356488
  }
356403
356489
  const resolvedTo = await resolveRecipient(to, instance4.channel, services);
356404
- const reactionMetadata = {};
356405
- const chat2 = await services.chats.findByExternalIdSmart(instanceId, resolvedTo);
356406
- if (chat2) {
356407
- const target = await services.messages.getByExternalId(chat2.id, messageId);
356408
- if (target) {
356409
- reactionMetadata.fromMe = target.isFromMe === true;
356410
- if (target.isFromMe !== true) {
356411
- const participant = extractReactionTargetParticipant(target.rawPayload);
356412
- if (participant)
356413
- reactionMetadata.targetParticipant = participant;
356414
- }
356415
- } else {
356416
- log110.warn("Reaction target message not found in DB; deferring fromMe to channel plugin fallback (#386)", {
356417
- instanceId,
356418
- chatId: chat2.id,
356419
- messageId,
356420
- fallback: "plugin-heuristic"
356421
- });
356422
- }
356423
- } else {
356424
- log110.warn("Reaction target chat not found in DB; deferring fromMe to channel plugin fallback (#386)", {
356425
- instanceId,
356426
- resolvedTo,
356427
- messageId,
356428
- fallback: "plugin-heuristic"
356429
- });
356430
- }
356490
+ const { targetMessageId, metadata: reactionMetadata } = await resolveReactionTarget(services, instanceId, resolvedTo, messageId);
356431
356491
  const outgoingMessage = {
356432
356492
  to: resolvedTo,
356433
356493
  content: {
356434
356494
  type: "reaction",
356435
356495
  emoji,
356436
- targetMessageId: messageId
356496
+ targetMessageId
356437
356497
  },
356438
356498
  metadata: reactionMetadata
356439
356499
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automagik/omni",
3
- "version": "2.260531.5",
3
+ "version": "2.260601.1",
4
4
  "description": "LLM-optimized CLI for Omni",
5
5
  "type": "module",
6
6
  "bin": {