@automagik/omni 2.260911.4 → 2.260911.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.
@@ -38333,6 +38333,8 @@ class DebounceManager {
38333
38333
  this.windows.set(key, window2);
38334
38334
  }
38335
38335
  window2.messages.push(message2);
38336
+ window2.from = from;
38337
+ window2.instanceId = instanceId;
38336
38338
  window2.lastActivityAt = Date.now();
38337
38339
  this.resetTimer(key, window2);
38338
38340
  }
@@ -38667,6 +38669,23 @@ class AutomationEngine {
38667
38669
  throw err2;
38668
38670
  }
38669
38671
  }
38672
+ resolveDebounceKey(automation, event, instanceId) {
38673
+ const payload = event.payload;
38674
+ const template = automation.debounce?.key;
38675
+ if (!template) {
38676
+ const from = payload.from;
38677
+ return from?.id ? buildConversationKey(instanceId, from.id) : null;
38678
+ }
38679
+ const rendered = substituteTemplate(template, createTemplateContext(payload)).trim();
38680
+ if (!rendered) {
38681
+ logger4.debug("Debounce key template rendered empty \u2014 processing immediately", {
38682
+ automationId: automation.id,
38683
+ eventId: event.id
38684
+ });
38685
+ return null;
38686
+ }
38687
+ return `${instanceId}:${rendered}`;
38688
+ }
38670
38689
  async handleDebounced(automation, event) {
38671
38690
  const manager = this.debounceManagers.get(automation.id);
38672
38691
  if (!manager) {
@@ -38676,11 +38695,11 @@ class AutomationEngine {
38676
38695
  const payload = event.payload;
38677
38696
  const instanceId = event.metadata.instanceId ?? "global";
38678
38697
  const from = payload.from;
38679
- if (!from?.id) {
38698
+ const key = this.resolveDebounceKey(automation, event, instanceId);
38699
+ if (!key) {
38680
38700
  await this.handleImmediate(automation, event);
38681
38701
  return;
38682
38702
  }
38683
- const key = buildConversationKey(instanceId, from.id);
38684
38703
  if (event.type.startsWith("presence.")) {
38685
38704
  manager.handlePresenceEvent(key, event.type);
38686
38705
  return;
@@ -251672,7 +251691,7 @@ var init_sentry_scrub = __esm(() => {
251672
251691
  var require_package7 = __commonJS((exports, module) => {
251673
251692
  module.exports = {
251674
251693
  name: "@omni/api",
251675
- version: "2.260911.4",
251694
+ version: "2.260911.5",
251676
251695
  private: true,
251677
251696
  type: "module",
251678
251697
  exports: {
@@ -379441,7 +379460,8 @@ var init_automations3 = __esm(() => {
379441
379460
  maxMs: exports_external.number().int().optional(),
379442
379461
  baseDelayMs: exports_external.number().int().optional(),
379443
379462
  maxWaitMs: exports_external.number().int().optional(),
379444
- extendOnEvents: exports_external.array(exports_external.string()).optional()
379463
+ extendOnEvents: exports_external.array(exports_external.string()).optional(),
379464
+ key: exports_external.string().optional().describe('Template over the event payload naming the debounce window (#1110), e.g. "{{payload.pull_request.id}}"; ' + 'absent = grouped by conversation (instance + sender). Not allowed with mode "presence"')
379445
379465
  });
379446
379466
  AutomationSchema = exports_external.object({
379447
379467
  id: exports_external.string().uuid().openapi({ description: "Automation UUID" }),
@@ -385195,7 +385215,7 @@ async function resolveTestEvent(services, body) {
385195
385215
  timestamp: row.receivedAt.getTime()
385196
385216
  };
385197
385217
  }
385198
- var automationsRoutes, conditionSchema, webhookActionSchema, sendMessageActionSchema, emitEventActionSchema, logActionSchema, callAgentActionSchema, actionSchema, debounceSchema, createAutomationSchema, updateAutomationSchema, listQuerySchema5, testAutomationSchema, logsQuerySchema;
385218
+ var automationsRoutes, conditionSchema, webhookActionSchema, sendMessageActionSchema, emitEventActionSchema, logActionSchema, callAgentActionSchema, actionSchema, debounceKeySchema, debounceSchema, createAutomationSchema, updateAutomationSchema, listQuerySchema5, testAutomationSchema, logsQuerySchema;
385199
385219
  var init_automations4 = __esm(() => {
385200
385220
  init_dist6();
385201
385221
  init_dist2();
@@ -385261,24 +385281,31 @@ var init_automations4 = __esm(() => {
385261
385281
  logActionSchema,
385262
385282
  callAgentActionSchema
385263
385283
  ]);
385284
+ debounceKeySchema = exports_external.string().min(1).optional().describe('Template over the event payload naming the debounce window (#1110), e.g. "{{payload.pull_request.id}}"; ' + 'omit to group by conversation (instance + sender) as before. Not allowed with mode "presence"');
385264
385285
  debounceSchema = exports_external.discriminatedUnion("mode", [
385265
- exports_external.object({ mode: exports_external.literal("none") }),
385286
+ exports_external.object({ mode: exports_external.literal("none"), key: debounceKeySchema }),
385266
385287
  exports_external.object({
385267
385288
  mode: exports_external.literal("fixed"),
385268
- delayMs: exports_external.number().int().min(100).max(300000).describe("Fixed delay in milliseconds")
385289
+ delayMs: exports_external.number().int().min(100).max(300000).describe("Fixed delay in milliseconds"),
385290
+ key: debounceKeySchema
385269
385291
  }),
385270
385292
  exports_external.object({
385271
385293
  mode: exports_external.literal("range"),
385272
385294
  minMs: exports_external.number().int().min(100).describe("Minimum delay"),
385273
- maxMs: exports_external.number().int().max(300000).describe("Maximum delay")
385295
+ maxMs: exports_external.number().int().max(300000).describe("Maximum delay"),
385296
+ key: debounceKeySchema
385274
385297
  }),
385275
385298
  exports_external.object({
385276
385299
  mode: exports_external.literal("presence"),
385277
385300
  baseDelayMs: exports_external.number().int().min(100).describe("Base delay"),
385278
385301
  maxWaitMs: exports_external.number().int().max(300000).optional().describe("Maximum total wait"),
385279
- extendOnEvents: exports_external.array(exports_external.string()).describe("Events that extend the timer")
385302
+ extendOnEvents: exports_external.array(exports_external.string()).describe("Events that extend the timer"),
385303
+ key: debounceKeySchema
385280
385304
  })
385281
- ]);
385305
+ ]).refine((debounce3) => !(debounce3.mode === "presence" && debounce3.key), {
385306
+ message: 'debounce.key cannot be combined with mode "presence": presence extension only applies to conversations',
385307
+ path: ["key"]
385308
+ });
385282
385309
  createAutomationSchema = exports_external.object({
385283
385310
  name: exports_external.string().min(1).max(255).describe("Automation name"),
385284
385311
  description: exports_external.string().optional().describe("Description"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automagik/omni",
3
- "version": "2.260911.4",
3
+ "version": "2.260911.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/automagik-dev/omni.git",