@automagik/omni 2.260930.1 → 2.260930.3
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 +41 -74
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -137462,7 +137462,7 @@ import { fileURLToPath } from "url";
|
|
|
137462
137462
|
// package.json
|
|
137463
137463
|
var package_default = {
|
|
137464
137464
|
name: "@automagik/omni",
|
|
137465
|
-
version: "2.260930.
|
|
137465
|
+
version: "2.260930.3",
|
|
137466
137466
|
repository: {
|
|
137467
137467
|
type: "git",
|
|
137468
137468
|
url: "git+https://github.com/automagik-dev/omni.git",
|
package/dist/server/index.js
CHANGED
|
@@ -266444,7 +266444,7 @@ var init_sentry_scrub = __esm(() => {
|
|
|
266444
266444
|
var require_package7 = __commonJS((exports, module) => {
|
|
266445
266445
|
module.exports = {
|
|
266446
266446
|
name: "@omni/api",
|
|
266447
|
-
version: "2.260930.
|
|
266447
|
+
version: "2.260930.3",
|
|
266448
266448
|
private: true,
|
|
266449
266449
|
type: "module",
|
|
266450
266450
|
exports: {
|
|
@@ -381951,11 +381951,7 @@ async function dispatchToAgent(services, instance4, msgs, triggerType, channel5,
|
|
|
381951
381951
|
}
|
|
381952
381952
|
async function applyCloseContactGate(services, chatRecordId, instanceId, chatId, chatSettings, trustedTenantId) {
|
|
381953
381953
|
if (chatSettings?.closed === true) {
|
|
381954
|
-
|
|
381955
|
-
instanceId,
|
|
381956
|
-
chatId,
|
|
381957
|
-
outcome: chatSettings.closeOutcome ?? null
|
|
381958
|
-
});
|
|
381954
|
+
logDrop("chat closed (terminal)", { chatId }, instanceId, { outcome: chatSettings.closeOutcome ?? null });
|
|
381959
381955
|
return "skip";
|
|
381960
381956
|
}
|
|
381961
381957
|
if (!chatSettings?.closeUntil)
|
|
@@ -382013,7 +382009,7 @@ async function processAgentResponse(services, instance4, messages4, triggerType,
|
|
|
382013
382009
|
const dispatchTenantId = firstMessage.metadata.trustedTenantId;
|
|
382014
382010
|
const personId = await resolvePersonId(services, channel5, instance4.id, senderId, firstMessage.metadata.personId, dispatchTenantId);
|
|
382015
382011
|
if (!personId) {
|
|
382016
|
-
|
|
382012
|
+
logDrop("could not resolve person ID", firstMessage.payload, instance4.id);
|
|
382017
382013
|
ackHandle.remove();
|
|
382018
382014
|
return;
|
|
382019
382015
|
}
|
|
@@ -382026,7 +382022,7 @@ async function processAgentResponse(services, instance4, messages4, triggerType,
|
|
|
382026
382022
|
}
|
|
382027
382023
|
const isAgentPaused = chatSettings?.agentPaused === true && gateResult !== "reopened";
|
|
382028
382024
|
if (isAgentPaused) {
|
|
382029
|
-
|
|
382025
|
+
logDrop("agent paused (handoff active)", firstMessage.payload, instance4.id);
|
|
382030
382026
|
ackHandle.remove();
|
|
382031
382027
|
return;
|
|
382032
382028
|
}
|
|
@@ -382034,9 +382030,7 @@ async function processAgentResponse(services, instance4, messages4, triggerType,
|
|
|
382034
382030
|
const resumedAt = new Date(chatSettings.agentResumedAt).getTime();
|
|
382035
382031
|
const msgTimestamp = (extractPlatformTimestamp(firstMessage.payload.rawPayload, Date.now()) ?? new Date).getTime();
|
|
382036
382032
|
if (msgTimestamp < resumedAt) {
|
|
382037
|
-
|
|
382038
|
-
instanceId: instance4.id,
|
|
382039
|
-
chatId,
|
|
382033
|
+
logDrop("pre-resume message (arrived during handoff window)", firstMessage.payload, instance4.id, {
|
|
382040
382034
|
msgTimestamp: new Date(msgTimestamp).toISOString(),
|
|
382041
382035
|
resumedAt: chatSettings.agentResumedAt
|
|
382042
382036
|
});
|
|
@@ -382724,28 +382718,29 @@ function isFirstPartyInstanceSender(sender, currentOwnerIdentifier, activeOwnerI
|
|
|
382724
382718
|
}
|
|
382725
382719
|
return false;
|
|
382726
382720
|
}
|
|
382727
|
-
async function listActiveOwnerIdentifiers(db2, trustedTenantId) {
|
|
382721
|
+
async function listActiveOwnerIdentifiers(db2, instance4, trustedTenantId) {
|
|
382728
382722
|
const now = Date.now();
|
|
382729
|
-
|
|
382730
|
-
|
|
382731
|
-
|
|
382732
|
-
|
|
382733
|
-
|
|
382734
|
-
|
|
382735
|
-
return [];
|
|
382736
|
-
const ids2 = rows2.map((row) => row.ownerIdentifier);
|
|
382737
|
-
tenantCachedActiveOwnerIdentifiers.set(trustedTenantId, { ids: ids2, at: now });
|
|
382738
|
-
return ids2;
|
|
382739
|
-
}
|
|
382740
|
-
if (cachedActiveOwnerIdentifiers && now - cachedActiveOwnerIdentifiersAt < ACTIVE_OWNER_IDENTIFIER_CACHE_TTL_MS) {
|
|
382741
|
-
return cachedActiveOwnerIdentifiers;
|
|
382742
|
-
}
|
|
382743
|
-
const rows = await db2.select({ ownerIdentifier: instances.ownerIdentifier }).from(instances).where(eq(instances.isActive, true));
|
|
382723
|
+
const cacheKey = `${trustedTenantId ?? ""}:${instance4.id}:${instance4.channel}:${instance4.slackTeamId ?? ""}`;
|
|
382724
|
+
const cached = cachedActiveOwnerIdentifiers.get(cacheKey);
|
|
382725
|
+
if (cached && now - cached.at < ACTIVE_OWNER_IDENTIFIER_CACHE_TTL_MS)
|
|
382726
|
+
return cached.ids;
|
|
382727
|
+
const where = and2(eq(instances.isActive, true), eq(instances.channel, instance4.channel), ne(instances.id, instance4.id), instance4.slackTeamId ? eq(instances.slackTeamId, instance4.slackTeamId) : undefined);
|
|
382728
|
+
const rows = trustedTenantId !== undefined ? await runInWorkerTenantScope(db2, trustedTenantId, () => scopedHandle(db2).select({ ownerIdentifier: instances.ownerIdentifier }).from(instances).where(where)) : await db2.select({ ownerIdentifier: instances.ownerIdentifier }).from(instances).where(where);
|
|
382744
382729
|
if (!Array.isArray(rows))
|
|
382745
382730
|
return [];
|
|
382746
|
-
|
|
382747
|
-
|
|
382748
|
-
return
|
|
382731
|
+
const ids2 = rows.map((row) => row.ownerIdentifier);
|
|
382732
|
+
cachedActiveOwnerIdentifiers.set(cacheKey, { ids: ids2, at: now });
|
|
382733
|
+
return ids2;
|
|
382734
|
+
}
|
|
382735
|
+
function logDrop(reason, payload, instanceId, extra = {}) {
|
|
382736
|
+
log94.warn(`Dropping inbound: ${reason}`, {
|
|
382737
|
+
instanceId,
|
|
382738
|
+
chatId: payload.chatId,
|
|
382739
|
+
sender: payload.from,
|
|
382740
|
+
externalId: payload.externalId,
|
|
382741
|
+
reason,
|
|
382742
|
+
...extra
|
|
382743
|
+
});
|
|
382749
382744
|
}
|
|
382750
382745
|
async function isAgentOutboundEcho(chatsService, messagesService, db2, payload, instanceId, trustedTenantId) {
|
|
382751
382746
|
if (payload.rawPayload?.isFromMe !== true)
|
|
@@ -382758,44 +382753,34 @@ async function isAgentOutboundEcho(chatsService, messagesService, db2, payload,
|
|
|
382758
382753
|
});
|
|
382759
382754
|
if (!priorMessage?.senderAgentId)
|
|
382760
382755
|
return false;
|
|
382761
|
-
|
|
382762
|
-
instanceId,
|
|
382763
|
-
chatId: payload.chatId,
|
|
382764
|
-
externalId: payload.externalId,
|
|
382756
|
+
logDrop("own outbound echo (agent-authored message received back)", payload, instanceId, {
|
|
382765
382757
|
senderAgentId: priorMessage.senderAgentId
|
|
382766
382758
|
});
|
|
382767
382759
|
return true;
|
|
382768
382760
|
}
|
|
382769
382761
|
async function shouldProcessMessage3(agentRunner, accessService, chatsService, messagesService, routeResolver, db2, payload, metadata, trustedTenantId) {
|
|
382770
382762
|
if (!metadata.instanceId) {
|
|
382771
|
-
|
|
382763
|
+
logDrop("no instanceId in metadata", payload, undefined);
|
|
382772
382764
|
return null;
|
|
382773
382765
|
}
|
|
382774
382766
|
if (payload.from === metadata.platformIdentityId) {
|
|
382775
|
-
|
|
382767
|
+
logDrop("message from self", payload, metadata.instanceId);
|
|
382776
382768
|
return null;
|
|
382777
382769
|
}
|
|
382778
382770
|
if (await isAgentOutboundEcho(chatsService, messagesService, db2, payload, metadata.instanceId, trustedTenantId)) {
|
|
382779
382771
|
return null;
|
|
382780
382772
|
}
|
|
382781
382773
|
if (payload.content?.type && NON_DISPATCHABLE_CONTENT_TYPES.has(payload.content.type)) {
|
|
382782
|
-
|
|
382783
|
-
instanceId: metadata.instanceId,
|
|
382784
|
-
chatId: payload.chatId,
|
|
382785
|
-
contentType: payload.content.type
|
|
382786
|
-
});
|
|
382774
|
+
logDrop("non-conversational content type", payload, metadata.instanceId, { contentType: payload.content.type });
|
|
382787
382775
|
return null;
|
|
382788
382776
|
}
|
|
382789
382777
|
if (isTrashEmojiOnly(payload.content?.text)) {
|
|
382790
|
-
|
|
382791
|
-
instanceId: metadata.instanceId,
|
|
382792
|
-
chatId: payload.chatId
|
|
382793
|
-
});
|
|
382778
|
+
logDrop("trash emoji message (session-cleaner handles this)", payload, metadata.instanceId);
|
|
382794
382779
|
return null;
|
|
382795
382780
|
}
|
|
382796
382781
|
const chatId = payload.chatId ?? "";
|
|
382797
382782
|
if (isBroadcastOrNewsletter(chatId)) {
|
|
382798
|
-
|
|
382783
|
+
logDrop("newsletter/broadcast chat", payload, metadata.instanceId);
|
|
382799
382784
|
return null;
|
|
382800
382785
|
}
|
|
382801
382786
|
const instance4 = await runDispatchDb(db2, trustedTenantId, () => agentRunner.getInstanceWithProvider(metadata.instanceId));
|
|
@@ -382803,19 +382788,16 @@ async function shouldProcessMessage3(agentRunner, accessService, chatsService, m
|
|
|
382803
382788
|
log94.debug("Instance has no agentId", { instanceId: metadata.instanceId });
|
|
382804
382789
|
return null;
|
|
382805
382790
|
}
|
|
382806
|
-
const activeOwnerIdentifiers = await listActiveOwnerIdentifiers(db2, trustedTenantId);
|
|
382791
|
+
const activeOwnerIdentifiers = await listActiveOwnerIdentifiers(db2, instance4, trustedTenantId);
|
|
382807
382792
|
if (!instance4.allowFirstParty && isFirstPartyInstanceSender(payload, instance4.ownerIdentifier, activeOwnerIdentifiers)) {
|
|
382808
|
-
|
|
382809
|
-
|
|
382793
|
+
logDrop("first-party cross-instance sender (set allowFirstParty to opt out)", payload, instance4.id, {
|
|
382794
|
+
channel: instance4.channel
|
|
382810
382795
|
});
|
|
382811
382796
|
return null;
|
|
382812
382797
|
}
|
|
382813
382798
|
const staleness = isInboundTooStale(payload.rawPayload, instance4.inboundMaxAgeMinutes);
|
|
382814
382799
|
if (staleness.stale) {
|
|
382815
|
-
|
|
382816
|
-
instanceId: instance4.id,
|
|
382817
|
-
chatId: payload.chatId,
|
|
382818
|
-
externalId: payload.externalId,
|
|
382800
|
+
logDrop("stale inbound message", payload, instance4.id, {
|
|
382819
382801
|
ageMs: staleness.ageMs,
|
|
382820
382802
|
maxAgeMs: staleness.maxAgeMs,
|
|
382821
382803
|
maxAgeMinutes: instance4.inboundMaxAgeMinutes
|
|
@@ -382849,12 +382831,7 @@ async function shouldProcessMessage3(agentRunner, accessService, chatsService, m
|
|
|
382849
382831
|
});
|
|
382850
382832
|
}
|
|
382851
382833
|
if (!shouldAgentReply(effectiveReplyFilter, messageContext)) {
|
|
382852
|
-
|
|
382853
|
-
instanceId: instance4.id,
|
|
382854
|
-
chatId: payload.chatId,
|
|
382855
|
-
messageContext,
|
|
382856
|
-
filter: effectiveReplyFilter
|
|
382857
|
-
});
|
|
382834
|
+
logDrop("did not pass reply filter", payload, instance4.id, { messageContext, filter: effectiveReplyFilter });
|
|
382858
382835
|
return null;
|
|
382859
382836
|
}
|
|
382860
382837
|
const channel5 = metadata.channelType ?? instance4.channel;
|
|
@@ -382892,13 +382869,7 @@ async function checkAccessWithFallback(accessService, instance4, payload, channe
|
|
|
382892
382869
|
}
|
|
382893
382870
|
if (accessResult.allowed)
|
|
382894
382871
|
return false;
|
|
382895
|
-
|
|
382896
|
-
instanceId: instance4.id,
|
|
382897
|
-
chatId: payload.chatId,
|
|
382898
|
-
from: payload.from,
|
|
382899
|
-
participantAlt,
|
|
382900
|
-
reason: accessResult.reason
|
|
382901
|
-
});
|
|
382872
|
+
logDrop(`access denied: ${accessResult.reason}`, payload, instance4.id, { participantAlt });
|
|
382902
382873
|
if (accessResult.mode === "allowlist" && !accessResult.rule && primaryId) {
|
|
382903
382874
|
accessService.requestPairing(instance4.id, primaryId, { channelType: instance4.channel }, trustedTenantId).catch((err2) => {
|
|
382904
382875
|
log94.warn("Failed to create pairing request", { instanceId: instance4.id, from: primaryId, error: String(err2) });
|
|
@@ -382918,7 +382889,7 @@ async function shouldProcessReaction(agentRunner, accessService, reactionDedup,
|
|
|
382918
382889
|
if (!instanceTriggersOnEvent(instance4, eventType))
|
|
382919
382890
|
return null;
|
|
382920
382891
|
if (!isReactionTrigger(instance4, payload.emoji)) {
|
|
382921
|
-
|
|
382892
|
+
logDrop("reaction emoji not in trigger list", payload, instance4.id, { emoji: payload.emoji });
|
|
382922
382893
|
return null;
|
|
382923
382894
|
}
|
|
382924
382895
|
const channel5 = metadata.channelType ?? instance4.channel;
|
|
@@ -382926,11 +382897,7 @@ async function shouldProcessReaction(agentRunner, accessService, reactionDedup,
|
|
|
382926
382897
|
if (accessDenied)
|
|
382927
382898
|
return null;
|
|
382928
382899
|
if (reactionDedup.isDuplicate(payload.messageId, payload.emoji, payload.from)) {
|
|
382929
|
-
|
|
382930
|
-
instanceId: instance4.id,
|
|
382931
|
-
messageId: payload.messageId,
|
|
382932
|
-
emoji: payload.emoji
|
|
382933
|
-
});
|
|
382900
|
+
logDrop("duplicate reaction", payload, instance4.id, { messageId: payload.messageId, emoji: payload.emoji });
|
|
382934
382901
|
return null;
|
|
382935
382902
|
}
|
|
382936
382903
|
return instance4;
|
|
@@ -383295,7 +383262,7 @@ async function setupAgentDispatcher(eventBus, services, db2) {
|
|
|
383295
383262
|
log94.info("Agent dispatcher shutdown complete");
|
|
383296
383263
|
};
|
|
383297
383264
|
}
|
|
383298
|
-
var import_api31, log94, agentDispatchLimiter, _natsGenieProviderCtor, QUOTED_MESSAGE_MAX_CHARS = 4000, DM_HISTORY_LIMIT = 20, LIFECYCLE_PREVIEW_MAX_CHARS = 160, LIFECYCLE_SENSITIVE_KEY_PARTS, PRESENCE_DEFAULT_MIN_MS = 5000, PRESENCE_DEFAULT_MAX_WAIT_MS = 30000, activeMessageDebouncer = null, DEFAULT_DISPATCH_ERROR_MESSAGE = "Opa, tive um probleminha aqui \uD83D\uDE05 Pode mandar de novo?", DEFAULT_ERROR_HANDOFF_MESSAGE = "T\xF4 com um probleminha t\xE9cnico aqui agora. Logo algu\xE9m do time vai entrar em contato com voc\xEA.", TRANSIENT_DISPATCH_ERROR_PATTERNS, TRANSIENT_DISPATCH_RETRY_DELAYS_MS, CHANNEL_MESSAGE_LIMITS, DEFAULT_MESSAGE_LIMIT = 4000, MEDIA_BASE_PATH3, NON_DISPATCHABLE_CONTENT_TYPES, MEDIA_ICONS, MEDIA_WAIT_NULL, mediaCompletions, mediaResultCache, MEDIA_WAIT_TIMEOUT_MS = 30000, DEFAULT_SEND_MEDIA_PATH_TYPES, BOT_PREFIX = "\uD83E\uDD16 ", activeStreams, activeRunAborts, CancelThreadPayloadSchema, sessionActivityStore, PROC_REACT_START, PROC_REACT_DONE = "\u2705", queuedMessageAcks, QUEUED_ACK_TIMEOUT_MS = 120000, providerCache, openclawClientPool, _openClawClientCtor, nullFilterWarnedInstances, ACTIVE_OWNER_IDENTIFIER_CACHE_TTL_MS = 1e4, cachedActiveOwnerIdentifiers
|
|
383265
|
+
var import_api31, log94, agentDispatchLimiter, _natsGenieProviderCtor, QUOTED_MESSAGE_MAX_CHARS = 4000, DM_HISTORY_LIMIT = 20, LIFECYCLE_PREVIEW_MAX_CHARS = 160, LIFECYCLE_SENSITIVE_KEY_PARTS, PRESENCE_DEFAULT_MIN_MS = 5000, PRESENCE_DEFAULT_MAX_WAIT_MS = 30000, activeMessageDebouncer = null, DEFAULT_DISPATCH_ERROR_MESSAGE = "Opa, tive um probleminha aqui \uD83D\uDE05 Pode mandar de novo?", DEFAULT_ERROR_HANDOFF_MESSAGE = "T\xF4 com um probleminha t\xE9cnico aqui agora. Logo algu\xE9m do time vai entrar em contato com voc\xEA.", TRANSIENT_DISPATCH_ERROR_PATTERNS, TRANSIENT_DISPATCH_RETRY_DELAYS_MS, CHANNEL_MESSAGE_LIMITS, DEFAULT_MESSAGE_LIMIT = 4000, MEDIA_BASE_PATH3, NON_DISPATCHABLE_CONTENT_TYPES, MEDIA_ICONS, MEDIA_WAIT_NULL, mediaCompletions, mediaResultCache, MEDIA_WAIT_TIMEOUT_MS = 30000, DEFAULT_SEND_MEDIA_PATH_TYPES, BOT_PREFIX = "\uD83E\uDD16 ", activeStreams, activeRunAborts, CancelThreadPayloadSchema, sessionActivityStore, PROC_REACT_START, PROC_REACT_DONE = "\u2705", queuedMessageAcks, QUEUED_ACK_TIMEOUT_MS = 120000, providerCache, openclawClientPool, _openClawClientCtor, nullFilterWarnedInstances, ACTIVE_OWNER_IDENTIFIER_CACHE_TTL_MS = 1e4, cachedActiveOwnerIdentifiers, setupAgentResponder;
|
|
383299
383266
|
var init_agent_dispatcher = __esm(() => {
|
|
383300
383267
|
init_src2();
|
|
383301
383268
|
init_src();
|
|
@@ -383364,7 +383331,7 @@ var init_agent_dispatcher = __esm(() => {
|
|
|
383364
383331
|
openclawClientPool = new Map;
|
|
383365
383332
|
_openClawClientCtor = OpenClawClient;
|
|
383366
383333
|
nullFilterWarnedInstances = new Set;
|
|
383367
|
-
|
|
383334
|
+
cachedActiveOwnerIdentifiers = new Map;
|
|
383368
383335
|
setupAgentResponder = setupAgentDispatcher;
|
|
383369
383336
|
});
|
|
383370
383337
|
|