@automagik/omni 2.260915.19 → 2.260915.21
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/db/drizzle/0074_trigger_logs_cost.sql +13 -0
- package/db/drizzle/meta/_journal.json +7 -0
- package/dist/commands/events.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/sdk/types.generated.d.ts +482 -7
- package/dist/sdk/types.generated.d.ts.map +1 -1
- package/dist/server/index.js +50 -4
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -38197,7 +38197,8 @@ async function executeCallAgentAction(config2, context2, deps, trustedTenantId,
|
|
|
38197
38197
|
result: {
|
|
38198
38198
|
response: result.fullResponse,
|
|
38199
38199
|
runId: result.metadata.runId,
|
|
38200
|
-
sessionId: result.metadata.sessionId
|
|
38200
|
+
sessionId: result.metadata.sessionId,
|
|
38201
|
+
...result.metadata.usage ? { usage: result.metadata.usage } : {}
|
|
38201
38202
|
},
|
|
38202
38203
|
error: result.metadata.status === "failed" ? "Agent call failed" : undefined
|
|
38203
38204
|
};
|
|
@@ -38219,6 +38220,7 @@ function dispatchCallAgent(run, deps, provenance) {
|
|
|
38219
38220
|
status: result.metadata.status,
|
|
38220
38221
|
providerRunId: result.metadata.runId,
|
|
38221
38222
|
response: result.fullResponse,
|
|
38223
|
+
...result.metadata.usage ? { usage: result.metadata.usage } : {},
|
|
38222
38224
|
error: result.metadata.status === "failed" ? "Agent call failed" : undefined
|
|
38223
38225
|
}), (error) => publish({ status: "failed", error: error instanceof Error ? error.message : "Unknown error" }));
|
|
38224
38226
|
return { success: true, result: { runId, accepted: true } };
|
|
@@ -173910,6 +173912,7 @@ var init_schema2 = __esm(() => {
|
|
|
173910
173912
|
durationMs: integer("duration_ms"),
|
|
173911
173913
|
inputTokens: integer("input_tokens"),
|
|
173912
173914
|
outputTokens: integer("output_tokens"),
|
|
173915
|
+
costUsd: numeric("cost_usd", { precision: 15, scale: 6 }),
|
|
173913
173916
|
error: text("error"),
|
|
173914
173917
|
metadata: jsonb("metadata").$type(),
|
|
173915
173918
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
@@ -251106,7 +251109,7 @@ var init_sentry_scrub = __esm(() => {
|
|
|
251106
251109
|
var require_package7 = __commonJS((exports, module) => {
|
|
251107
251110
|
module.exports = {
|
|
251108
251111
|
name: "@omni/api",
|
|
251109
|
-
version: "2.260915.
|
|
251112
|
+
version: "2.260915.21",
|
|
251110
251113
|
private: true,
|
|
251111
251114
|
type: "module",
|
|
251112
251115
|
exports: {
|
|
@@ -362163,6 +362166,31 @@ async function stampAgentUsage(db2, eventId, stamp) {
|
|
|
362163
362166
|
log87.warn("Failed to stamp agent usage on journal row", { eventId, error: String(error3) });
|
|
362164
362167
|
}
|
|
362165
362168
|
}
|
|
362169
|
+
async function recordAutomationTriggerLog(db2, entry) {
|
|
362170
|
+
try {
|
|
362171
|
+
const { usage } = entry;
|
|
362172
|
+
await scopedHandle(db2).insert(triggerLogs).values({
|
|
362173
|
+
instanceId: entry.instanceId,
|
|
362174
|
+
providerId: entry.providerId && isValidUuid(entry.providerId) ? entry.providerId : null,
|
|
362175
|
+
eventType: entry.eventType ?? "unknown",
|
|
362176
|
+
eventId: entry.eventId ?? "unknown",
|
|
362177
|
+
triggerType: "automation",
|
|
362178
|
+
channelType: entry.channelType,
|
|
362179
|
+
chatId: entry.chatId,
|
|
362180
|
+
senderId: entry.senderId,
|
|
362181
|
+
mode: "round-trip",
|
|
362182
|
+
respondedAt: entry.error ? null : new Date,
|
|
362183
|
+
responded: !entry.error,
|
|
362184
|
+
durationMs: entry.durationMs !== undefined ? Math.round(entry.durationMs) : null,
|
|
362185
|
+
inputTokens: usage?.tokensIn ?? null,
|
|
362186
|
+
outputTokens: usage?.tokensOut ?? null,
|
|
362187
|
+
costUsd: usage?.costUsd !== undefined ? String(usage.costUsd) : null,
|
|
362188
|
+
error: entry.error
|
|
362189
|
+
});
|
|
362190
|
+
} catch (error3) {
|
|
362191
|
+
log87.warn("Failed to record automation trigger log", { instanceId: entry.instanceId, error: String(error3) });
|
|
362192
|
+
}
|
|
362193
|
+
}
|
|
362166
362194
|
var log87;
|
|
362167
362195
|
var init_agent_usage2 = __esm(() => {
|
|
362168
362196
|
init_src();
|
|
@@ -370379,6 +370407,8 @@ class EventService {
|
|
|
370379
370407
|
totalCostUsd: sql`coalesce(sum((${omniEvents.metadata}->'agentUsage'->>'costUsd')::numeric), 0)::float`
|
|
370380
370408
|
}).from(omniEvents).where(whereClause);
|
|
370381
370409
|
const counts = countResults[0];
|
|
370410
|
+
const costExpr = sql`sum((${omniEvents.metadata}->'agentUsage'->>'costUsd')::numeric)::float`;
|
|
370411
|
+
const costByEventType = await this.db.select({ eventType: omniEvents.eventType, costUsd: costExpr }).from(omniEvents).where(and2(whereClause, sql`${omniEvents.metadata}->'agentUsage'->>'costUsd' is not null`)).groupBy(omniEvents.eventType);
|
|
370382
370412
|
const contentTypeCounts = await this.db.select({
|
|
370383
370413
|
contentType: omniEvents.contentType,
|
|
370384
370414
|
count: sql`count(*)::int`
|
|
@@ -370421,6 +370451,7 @@ class EventService {
|
|
|
370421
370451
|
avgProcessingTimeMs: counts?.avgProcessingTime ?? null,
|
|
370422
370452
|
avgAgentTimeMs: counts?.avgAgentTime ?? null,
|
|
370423
370453
|
totalCostUsd: counts?.totalCostUsd ?? 0,
|
|
370454
|
+
costByEventType: Object.fromEntries(costByEventType.map((c) => [c.eventType, c.costUsd])),
|
|
370424
370455
|
messageTypes: Object.fromEntries(contentTypeCounts.filter((c) => c.contentType != null).map((c) => [c.contentType, c.count])),
|
|
370425
370456
|
errorStages: Object.fromEntries(errorStageCounts.filter((c) => c.errorStage != null).map((c) => [c.errorStage, c.count])),
|
|
370426
370457
|
instances: Object.fromEntries(instanceCounts.filter((c) => c.instanceId != null).map((c) => [c.instanceId, c.count])),
|
|
@@ -380767,6 +380798,7 @@ var init_events3 = __esm(() => {
|
|
|
380767
380798
|
avgProcessingTimeMs: exports_external.number().nullable().openapi({ description: "Average processing time (ms)" }),
|
|
380768
380799
|
avgAgentTimeMs: exports_external.number().nullable().openapi({ description: "Average agent time (ms)" }),
|
|
380769
380800
|
totalCostUsd: exports_external.number().openapi({ description: "Sum of agent run cost (USD) stamped on events in range" }),
|
|
380801
|
+
costByEventType: exports_external.record(exports_external.string(), exports_external.number()).openapi({ description: "Agent run cost (USD) grouped by event type, for events with a stamped cost" }),
|
|
380770
380802
|
messageTypes: exports_external.record(exports_external.string(), exports_external.number()).openapi({ description: "Count by content type" }),
|
|
380771
380803
|
errorStages: exports_external.record(exports_external.string(), exports_external.number()).openapi({ description: "Count by error stage" }),
|
|
380772
380804
|
instances: exports_external.record(exports_external.string(), exports_external.number()).openapi({ description: "Count by instance" }),
|
|
@@ -400890,7 +400922,7 @@ async function runChatlessCallAgent(services, db3, ctx, cfg, trustedTenantId) {
|
|
|
400890
400922
|
});
|
|
400891
400923
|
return toCallAgentResult(db3, ctx, result, trustedTenantId);
|
|
400892
400924
|
}
|
|
400893
|
-
function toCallAgentResult(db3, ctx, result, trustedTenantId) {
|
|
400925
|
+
function toCallAgentResult(db3, ctx, result, trustedTenantId, instance4) {
|
|
400894
400926
|
const usage = agentUsageFromResult({
|
|
400895
400927
|
providerId: result.metadata.providerId,
|
|
400896
400928
|
runId: result.metadata.runId,
|
|
@@ -400899,6 +400931,20 @@ function toCallAgentResult(db3, ctx, result, trustedTenantId) {
|
|
|
400899
400931
|
if (usage) {
|
|
400900
400932
|
runTenantWorkDb(db3, trustedTenantId, () => stampAgentUsage(db3, ctx.event?.id, { usage, latencyMs: result.metadata.metrics?.durationMs })).catch((error3) => log133.warn("call_agent: usage stamp scope failed", { error: String(error3) }));
|
|
400901
400933
|
}
|
|
400934
|
+
if (instance4) {
|
|
400935
|
+
runTenantWorkDb(db3, trustedTenantId, () => recordAutomationTriggerLog(db3, {
|
|
400936
|
+
instanceId: instance4.id,
|
|
400937
|
+
providerId: result.metadata.providerId,
|
|
400938
|
+
eventId: ctx.event?.id,
|
|
400939
|
+
eventType: ctx.event?.type,
|
|
400940
|
+
chatId: ctx.chatId,
|
|
400941
|
+
senderId: ctx.senderId,
|
|
400942
|
+
channelType: instance4.channel ?? undefined,
|
|
400943
|
+
durationMs: result.metadata.metrics?.durationMs,
|
|
400944
|
+
usage,
|
|
400945
|
+
error: result.metadata.status === "failed" ? "Agent call failed" : undefined
|
|
400946
|
+
})).catch((error3) => log133.warn("call_agent: trigger log scope failed", { error: String(error3) }));
|
|
400947
|
+
}
|
|
400902
400948
|
return {
|
|
400903
400949
|
parts: result.parts,
|
|
400904
400950
|
fullResponse: result.parts.join(`
|
|
@@ -401021,7 +401067,7 @@ function buildAutomationEngineDeps(services, db3, options = {}) {
|
|
|
401021
401067
|
chatType: "dm",
|
|
401022
401068
|
messages: ctx.messages
|
|
401023
401069
|
});
|
|
401024
|
-
return toCallAgentResult(db3, ctx, result, trustedTenantId);
|
|
401070
|
+
return toCallAgentResult(db3, ctx, result, trustedTenantId, instance4);
|
|
401025
401071
|
},
|
|
401026
401072
|
staleIdleTimeoutGate: async (chatId, instanceId, eventSequenceIndex, trustedTenantId) => {
|
|
401027
401073
|
return services.followUpLifecycle.evaluateIdleTimeoutFreshness(chatId, instanceId, eventSequenceIndex, trustedTenantId);
|