@automagik/omni 2.260531.4 → 2.260531.5
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 +184 -8
- package/package.json +1 -1
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.
|
|
124970
|
+
version: "2.260531.5",
|
|
124971
124971
|
description: "LLM-optimized CLI for Omni",
|
|
124972
124972
|
type: "module",
|
|
124973
124973
|
bin: {
|
package/dist/server/index.js
CHANGED
|
@@ -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.
|
|
225244
|
+
version: "2.260531.5",
|
|
225245
225245
|
type: "module",
|
|
225246
225246
|
exports: {
|
|
225247
225247
|
".": {
|
|
@@ -337739,9 +337739,113 @@ var init_session_storage = __esm(() => {
|
|
|
337739
337739
|
});
|
|
337740
337740
|
|
|
337741
337741
|
// ../api/src/plugins/agent-dispatcher.ts
|
|
337742
|
+
import { createHash as createHash10 } from "crypto";
|
|
337742
337743
|
import { unlink, writeFile as writeFile5 } from "fs/promises";
|
|
337743
337744
|
import { tmpdir as tmpdir11 } from "os";
|
|
337744
337745
|
import { join as join24, resolve as resolve2 } from "path";
|
|
337746
|
+
function sha256Digest(value) {
|
|
337747
|
+
return `sha256:${createHash10("sha256").update(value).digest("hex")}`;
|
|
337748
|
+
}
|
|
337749
|
+
function redactLifecycleText(value) {
|
|
337750
|
+
return value.replace(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/gi, "[EMAIL]").replace(/\b\+?\d[\d\s().-]{5,}\d\b/g, "[PHONE]").replace(/\b\d{6,}\b/g, "[NUMBER]").replace(/\b[^\s@]+@(s\.whatsapp\.net|g\.us|lid|newsletter)\b/gi, "[JID]");
|
|
337751
|
+
}
|
|
337752
|
+
function previewLifecycleText(value) {
|
|
337753
|
+
const redacted = redactLifecycleText(value).replace(/\s+/g, " ").trim();
|
|
337754
|
+
if (redacted.length <= LIFECYCLE_PREVIEW_MAX_CHARS)
|
|
337755
|
+
return redacted;
|
|
337756
|
+
return `${redacted.slice(0, LIFECYCLE_PREVIEW_MAX_CHARS - 1)}\u2026`;
|
|
337757
|
+
}
|
|
337758
|
+
function isLifecycleSafeExtraKey(key) {
|
|
337759
|
+
const lowered = key.toLowerCase();
|
|
337760
|
+
return !LIFECYCLE_SENSITIVE_KEY_PARTS.some((part) => lowered.includes(part));
|
|
337761
|
+
}
|
|
337762
|
+
function setTextLifecycleAttributes(attributes, prefix, value) {
|
|
337763
|
+
if (value === undefined)
|
|
337764
|
+
return;
|
|
337765
|
+
attributes[`khal.${prefix}_chars`] = value.length;
|
|
337766
|
+
attributes[`khal.${prefix}_sha256`] = sha256Digest(value);
|
|
337767
|
+
attributes[`khal.${prefix}_preview_redacted`] = previewLifecycleText(value);
|
|
337768
|
+
}
|
|
337769
|
+
function setOptionalLifecycleAttributes(attributes, pairs) {
|
|
337770
|
+
for (const [key, value] of pairs) {
|
|
337771
|
+
if (value)
|
|
337772
|
+
attributes[key] = value;
|
|
337773
|
+
}
|
|
337774
|
+
}
|
|
337775
|
+
function setChatLifecycleAttributes(attributes, chatId) {
|
|
337776
|
+
if (!chatId)
|
|
337777
|
+
return;
|
|
337778
|
+
attributes["omni.chat_id_sha256"] = sha256Digest(chatId);
|
|
337779
|
+
attributes["omni.chat_id_preview_redacted"] = previewLifecycleText(chatId);
|
|
337780
|
+
}
|
|
337781
|
+
function setSessionLifecycleAttributes(attributes, sessionId) {
|
|
337782
|
+
if (!sessionId)
|
|
337783
|
+
return;
|
|
337784
|
+
attributes["khal.session_id"] = sessionId;
|
|
337785
|
+
attributes["langfuse.session.id"] = sessionId;
|
|
337786
|
+
attributes["session.id"] = sessionId;
|
|
337787
|
+
}
|
|
337788
|
+
function setExtraLifecycleAttributes(attributes, extra) {
|
|
337789
|
+
if (!extra)
|
|
337790
|
+
return;
|
|
337791
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
337792
|
+
if (!isLifecycleSafeExtraKey(key) || value === undefined || value === null)
|
|
337793
|
+
continue;
|
|
337794
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
337795
|
+
attributes[`khal.${key}`] = typeof value === "string" ? previewLifecycleText(value) : value;
|
|
337796
|
+
}
|
|
337797
|
+
}
|
|
337798
|
+
}
|
|
337799
|
+
function buildLifecycleSpanAttributes(input) {
|
|
337800
|
+
const attributes = {
|
|
337801
|
+
"khal.lifecycle.stage": input.stage,
|
|
337802
|
+
"khal.event_type": input.eventType,
|
|
337803
|
+
"khal.channel": input.channel
|
|
337804
|
+
};
|
|
337805
|
+
setOptionalLifecycleAttributes(attributes, [
|
|
337806
|
+
["khal.provider", input.provider],
|
|
337807
|
+
["omni.instance_id", input.instanceId],
|
|
337808
|
+
["khal.trace_id", input.traceId],
|
|
337809
|
+
["khal.turn.message_id", input.messageId],
|
|
337810
|
+
["khal.agent_id", input.agentId]
|
|
337811
|
+
]);
|
|
337812
|
+
setChatLifecycleAttributes(attributes, input.chatId);
|
|
337813
|
+
setSessionLifecycleAttributes(attributes, input.sessionId);
|
|
337814
|
+
setTextLifecycleAttributes(attributes, "input", input.inputText);
|
|
337815
|
+
setTextLifecycleAttributes(attributes, "output", input.outputText);
|
|
337816
|
+
setExtraLifecycleAttributes(attributes, input.extra);
|
|
337817
|
+
return attributes;
|
|
337818
|
+
}
|
|
337819
|
+
async function withLifecycleSpan(name, attributes, fn) {
|
|
337820
|
+
let callbackStarted = false;
|
|
337821
|
+
try {
|
|
337822
|
+
const tracer2 = import_api32.trace.getTracer("omni.agent-dispatcher");
|
|
337823
|
+
return await tracer2.startActiveSpan(name, { attributes }, async (span) => {
|
|
337824
|
+
callbackStarted = true;
|
|
337825
|
+
try {
|
|
337826
|
+
const result = await fn();
|
|
337827
|
+
span.setStatus({ code: import_api32.SpanStatusCode.OK });
|
|
337828
|
+
return result;
|
|
337829
|
+
} catch (error3) {
|
|
337830
|
+
span.recordException(error3 instanceof Error ? error3 : new Error(String(error3)));
|
|
337831
|
+
span.setStatus({ code: import_api32.SpanStatusCode.ERROR, message: error3 instanceof Error ? error3.message : String(error3) });
|
|
337832
|
+
throw error3;
|
|
337833
|
+
} finally {
|
|
337834
|
+
span.end();
|
|
337835
|
+
}
|
|
337836
|
+
});
|
|
337837
|
+
} catch (error3) {
|
|
337838
|
+
if (callbackStarted)
|
|
337839
|
+
throw error3;
|
|
337840
|
+
log99.warn("Lifecycle span wrapper failed before dispatch; continuing without span", { spanName: name });
|
|
337841
|
+
return fn();
|
|
337842
|
+
}
|
|
337843
|
+
}
|
|
337844
|
+
function emitLifecycleSpan(name, attributes) {
|
|
337845
|
+
withLifecycleSpan(name, attributes, async () => {
|
|
337846
|
+
return;
|
|
337847
|
+
}).catch(() => {});
|
|
337848
|
+
}
|
|
337745
337849
|
function createPluginAckProvider(plugin7) {
|
|
337746
337850
|
if (!plugin7?.react || !plugin7?.unreact)
|
|
337747
337851
|
return null;
|
|
@@ -338811,7 +338915,20 @@ async function dispatchViaTurnBasedProvider(services, instance4, provider, trigg
|
|
|
338811
338915
|
OMNI_TURN_ID: turn.id
|
|
338812
338916
|
};
|
|
338813
338917
|
const dispatchStart = Date.now();
|
|
338814
|
-
await
|
|
338918
|
+
await withLifecycleSpan("omni.dispatch_to_agno", buildLifecycleSpanAttributes({
|
|
338919
|
+
stage: "dispatch_to_agno",
|
|
338920
|
+
eventType: "user_message_turn",
|
|
338921
|
+
channel: instance4.channel,
|
|
338922
|
+
provider: provider.schema,
|
|
338923
|
+
instanceId: instance4.id,
|
|
338924
|
+
chatId,
|
|
338925
|
+
sessionId: trigger.sessionId,
|
|
338926
|
+
traceId,
|
|
338927
|
+
messageId,
|
|
338928
|
+
agentId: agentRecord.id,
|
|
338929
|
+
inputText: trigger.content.text,
|
|
338930
|
+
extra: { mode: "turn-based", provider_id: provider.id, provider_schema: provider.schema }
|
|
338931
|
+
}), () => provider.trigger(trigger));
|
|
338815
338932
|
const dispatchDurationMs = Date.now() - dispatchStart;
|
|
338816
338933
|
if (sentryEnabled()) {
|
|
338817
338934
|
exports_public_api2.count("agent.dispatch", 1, { attributes: { provider_type: provider.schema, mode: "turn-based" } });
|
|
@@ -338852,12 +338969,34 @@ async function dispatchViaProvider(services, instance4, messages4, triggerType,
|
|
|
338852
338969
|
await executeBeforeAgentStartHooks(instance4, chatId, senderId, senderName, triggerType, traceId, messages4[0]?.metadata.correlationId, triggerFiles);
|
|
338853
338970
|
const customerContext = await resolveCustomerContext(services, personId, extractA2ACustomerContext(messages4, channel5));
|
|
338854
338971
|
const trigger = buildMessageTrigger(traceId, triggerType, rawEvent, channel5, instance4, chatId, senderId, personId, senderName, messages4, messageTexts, triggerFiles, sessionId, customerContext, allContextMessages, explicitKhalSessionId);
|
|
338972
|
+
const lifecycleBase = {
|
|
338973
|
+
eventType: "user_message_turn",
|
|
338974
|
+
channel: channel5,
|
|
338975
|
+
provider: provider.schema,
|
|
338976
|
+
instanceId: instance4.id,
|
|
338977
|
+
chatId,
|
|
338978
|
+
sessionId,
|
|
338979
|
+
traceId,
|
|
338980
|
+
messageId: messages4[0]?.payload.externalId,
|
|
338981
|
+
agentId: instance4.agentInternalId ?? instance4.agentId ?? undefined,
|
|
338982
|
+
inputText: messageTexts.join(`
|
|
338983
|
+
`)
|
|
338984
|
+
};
|
|
338985
|
+
emitLifecycleSpan("omni.provider_inbound", buildLifecycleSpanAttributes({
|
|
338986
|
+
...lifecycleBase,
|
|
338987
|
+
stage: "provider_inbound",
|
|
338988
|
+
extra: { trigger_type: triggerType, message_count: messages4.length }
|
|
338989
|
+
}));
|
|
338855
338990
|
if (provider.mode === "turn-based") {
|
|
338856
338991
|
return dispatchViaTurnBasedProvider(services, instance4, provider, trigger, messages4, chatId, traceId, db2);
|
|
338857
338992
|
}
|
|
338858
338993
|
const correlationId = messages4[0]?.metadata.correlationId;
|
|
338859
338994
|
const dispatchStart = Date.now();
|
|
338860
|
-
const result = await
|
|
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));
|
|
338861
339000
|
const dispatchDurationMs = Date.now() - dispatchStart;
|
|
338862
339001
|
if (sentryEnabled()) {
|
|
338863
339002
|
exports_public_api2.count("agent.dispatch", 1, { attributes: { provider_type: provider.schema } });
|
|
@@ -338875,7 +339014,13 @@ async function dispatchViaProvider(services, instance4, messages4, triggerType,
|
|
|
338875
339014
|
const _fmtMode = instance4.messageFormatMode ?? "convert";
|
|
338876
339015
|
const replyTo = messages4[0]?.payload.replyToId ?? messages4[0]?.payload.externalId;
|
|
338877
339016
|
recordJourneyCheckpoint(correlationId, "T8", JOURNEY_STAGES.T8);
|
|
338878
|
-
await
|
|
339017
|
+
await withLifecycleSpan("omni.provider_outbound", buildLifecycleSpanAttributes({
|
|
339018
|
+
...lifecycleBase,
|
|
339019
|
+
stage: "provider_outbound",
|
|
339020
|
+
outputText: parts.join(`
|
|
339021
|
+
`),
|
|
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));
|
|
338879
339024
|
recordJourneyCheckpoint(correlationId, "T9", JOURNEY_STAGES.T9);
|
|
338880
339025
|
await forwardToChainedInstance(instance4, parts, correlationId, messages4);
|
|
338881
339026
|
} else if (handoffTriggered) {
|
|
@@ -338916,7 +339061,30 @@ async function dispatchViaLegacy(services, instance4, messages4, triggerType, ch
|
|
|
338916
339061
|
const { avatarUrl: senderAvatarUrl, platformUsername: senderPlatformUsername } = await fetchSenderMetadata(services, channel5, instance4.id, senderId);
|
|
338917
339062
|
const { chatName, participantCount } = await fetchChatMetadata(services, instance4.id, chatId, chatType);
|
|
338918
339063
|
await executeBeforeAgentStartHooks(instance4, chatId, senderId, senderName, triggerType, traceId, messages4[0]?.metadata.correlationId, mediaFiles.length > 0 ? mediaFiles : undefined);
|
|
338919
|
-
const
|
|
339064
|
+
const lifecycleSessionId = computeSessionId(instance4.agentSessionStrategy ?? "per_chat", senderId, chatId, rawPl.threadId);
|
|
339065
|
+
const lifecycleBase = {
|
|
339066
|
+
eventType: "user_message_turn",
|
|
339067
|
+
channel: channel5,
|
|
339068
|
+
provider: "legacy-agent-runner",
|
|
339069
|
+
instanceId: instance4.id,
|
|
339070
|
+
chatId,
|
|
339071
|
+
sessionId: lifecycleSessionId,
|
|
339072
|
+
traceId,
|
|
339073
|
+
messageId: messages4[0]?.payload.externalId,
|
|
339074
|
+
agentId: instance4.agentInternalId ?? instance4.agentId ?? undefined,
|
|
339075
|
+
inputText: messageTexts.join(`
|
|
339076
|
+
`)
|
|
339077
|
+
};
|
|
339078
|
+
emitLifecycleSpan("omni.provider_inbound", buildLifecycleSpanAttributes({
|
|
339079
|
+
...lifecycleBase,
|
|
339080
|
+
stage: "provider_inbound",
|
|
339081
|
+
extra: { trigger_type: triggerType, message_count: messages4.length }
|
|
339082
|
+
}));
|
|
339083
|
+
const result = await withLifecycleSpan("omni.dispatch_to_agno", buildLifecycleSpanAttributes({
|
|
339084
|
+
...lifecycleBase,
|
|
339085
|
+
stage: "dispatch_to_agno",
|
|
339086
|
+
extra: { trigger_type: triggerType, provider_schema: "legacy-agent-runner" }
|
|
339087
|
+
}), () => services.agentRunner.run({
|
|
338920
339088
|
instance: instance4,
|
|
338921
339089
|
chatId,
|
|
338922
339090
|
personId,
|
|
@@ -338929,7 +339097,7 @@ async function dispatchViaLegacy(services, instance4, messages4, triggerType, ch
|
|
|
338929
339097
|
participantCount,
|
|
338930
339098
|
messages: messageTexts,
|
|
338931
339099
|
files: mediaFiles.length > 0 ? mediaFiles : undefined
|
|
338932
|
-
});
|
|
339100
|
+
}));
|
|
338933
339101
|
const correlationId = messages4[0]?.metadata.correlationId;
|
|
338934
339102
|
const selfChat = isSelfChat(chatId, instance4.ownerIdentifier);
|
|
338935
339103
|
const rawParts = selfChat ? result.parts.map((p2) => `${BOT_PREFIX}${p2}`) : result.parts;
|
|
@@ -338937,7 +339105,13 @@ async function dispatchViaLegacy(services, instance4, messages4, triggerType, ch
|
|
|
338937
339105
|
const _fmtMode = instance4.messageFormatMode ?? "convert";
|
|
338938
339106
|
const replyTo = messages4[0]?.payload.replyToId ?? messages4[0]?.payload.externalId;
|
|
338939
339107
|
recordJourneyCheckpoint(correlationId, "T8", JOURNEY_STAGES.T8);
|
|
338940
|
-
await
|
|
339108
|
+
await withLifecycleSpan("omni.provider_outbound", buildLifecycleSpanAttributes({
|
|
339109
|
+
...lifecycleBase,
|
|
339110
|
+
stage: "provider_outbound",
|
|
339111
|
+
outputText: parts.join(`
|
|
339112
|
+
`),
|
|
339113
|
+
extra: { parts_count: parts.length, provider_schema: "legacy-agent-runner" }
|
|
339114
|
+
}), () => sendResponseParts(channel5, instance4.id, chatId, parts, getSplitDelayConfig(instance4), _fmtMode, replyTo, correlationId, senderAgentId));
|
|
338941
339115
|
recordJourneyCheckpoint(correlationId, "T9", JOURNEY_STAGES.T9);
|
|
338942
339116
|
log99.info("Agent response via legacy runner", {
|
|
338943
339117
|
instanceId: instance4.id,
|
|
@@ -340449,7 +340623,7 @@ async function setupAgentDispatcher(eventBus, services, db2) {
|
|
|
340449
340623
|
log99.info("Agent dispatcher shutdown complete");
|
|
340450
340624
|
};
|
|
340451
340625
|
}
|
|
340452
|
-
var log99, _natsGenieProviderCtor, QUOTED_MESSAGE_MAX_CHARS = 4000, DM_HISTORY_LIMIT = 20, TRANSIENT_DISPATCH_ERROR_PATTERNS, TRANSIENT_DISPATCH_RETRY_DELAYS_MS, CHANNEL_MESSAGE_LIMITS, DEFAULT_MESSAGE_LIMIT = 4000, MEDIA_BASE_PATH3, MEDIA_ICONS, MEDIA_WAIT_NULL, mediaCompletions, mediaResultCache, MEDIA_WAIT_TIMEOUT_MS = 30000, DEFAULT_SEND_MEDIA_PATH_TYPES, BOT_PREFIX = "\uD83E\uDD16 ", activeStreams, sessionActivityStore, PROC_REACT_START, PROC_REACT_DONE = "\u2705", providerCache, openclawClientPool, nullFilterWarnedInstances, ACTIVE_OWNER_IDENTIFIER_CACHE_TTL_MS = 1e4, cachedActiveOwnerIdentifiers = null, cachedActiveOwnerIdentifiersAt = 0, DEFAULT_GATE_MODEL = "gemini-3-flash-preview", GATE_TIMEOUT_MS = 3000, setupAgentResponder;
|
|
340626
|
+
var import_api32, log99, _natsGenieProviderCtor, QUOTED_MESSAGE_MAX_CHARS = 4000, DM_HISTORY_LIMIT = 20, LIFECYCLE_PREVIEW_MAX_CHARS = 160, LIFECYCLE_SENSITIVE_KEY_PARTS, TRANSIENT_DISPATCH_ERROR_PATTERNS, TRANSIENT_DISPATCH_RETRY_DELAYS_MS, CHANNEL_MESSAGE_LIMITS, DEFAULT_MESSAGE_LIMIT = 4000, MEDIA_BASE_PATH3, MEDIA_ICONS, MEDIA_WAIT_NULL, mediaCompletions, mediaResultCache, MEDIA_WAIT_TIMEOUT_MS = 30000, DEFAULT_SEND_MEDIA_PATH_TYPES, BOT_PREFIX = "\uD83E\uDD16 ", activeStreams, sessionActivityStore, PROC_REACT_START, PROC_REACT_DONE = "\u2705", providerCache, openclawClientPool, nullFilterWarnedInstances, ACTIVE_OWNER_IDENTIFIER_CACHE_TTL_MS = 1e4, cachedActiveOwnerIdentifiers = null, cachedActiveOwnerIdentifiersAt = 0, DEFAULT_GATE_MODEL = "gemini-3-flash-preview", GATE_TIMEOUT_MS = 3000, setupAgentResponder;
|
|
340453
340627
|
var init_agent_dispatcher = __esm(() => {
|
|
340454
340628
|
init_src2();
|
|
340455
340629
|
init_src();
|
|
@@ -340466,8 +340640,10 @@ var init_agent_dispatcher = __esm(() => {
|
|
|
340466
340640
|
init_message_persistence();
|
|
340467
340641
|
init_session_storage();
|
|
340468
340642
|
init_src6();
|
|
340643
|
+
import_api32 = __toESM(require_src(), 1);
|
|
340469
340644
|
log99 = createLogger("agent-dispatcher");
|
|
340470
340645
|
_natsGenieProviderCtor = NatsGenieProvider;
|
|
340646
|
+
LIFECYCLE_SENSITIVE_KEY_PARTS = ["authorization", "bearer", "password", "secret", "token", "api_key", "apikey"];
|
|
340471
340647
|
TRANSIENT_DISPATCH_ERROR_PATTERNS = [
|
|
340472
340648
|
/ECONNREFUSED/i,
|
|
340473
340649
|
/ECONNRESET/i,
|