@automagik/omni 2.260908.6 → 2.260908.8

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
@@ -34426,7 +34426,14 @@ var init_events = __esm(() => {
34426
34426
  });
34427
34427
 
34428
34428
  // ../core/src/schemas/agent-manifest.ts
34429
- var EVENT_TYPE_TOKEN_PATTERN, ManifestEventTypeSchema, ManifestAcceptsEntrySchema, ManifestPublishesEntrySchema, AgentEventManifestSchema;
34429
+ function checkPublishAllowed(manifest, eventType) {
34430
+ const publishes = manifest?.publishes;
34431
+ if (!Array.isArray(publishes)) {
34432
+ return true;
34433
+ }
34434
+ return publishes.some((entry) => entry?.event === eventType);
34435
+ }
34436
+ var EVENT_TYPE_TOKEN_PATTERN, ManifestEventTypeSchema, ManifestAcceptsEntrySchema, ManifestPublishesEntrySchema, AgentEventManifestSchema, PUBLISH_NOT_DECLARED = "publish_not_declared";
34430
34437
  var init_agent_manifest = __esm(() => {
34431
34438
  init_zod();
34432
34439
  init_types2();
@@ -40928,14 +40935,14 @@ async function releaseEmissionClaim(deps, claimedEventId, eventType) {
40928
40935
  });
40929
40936
  });
40930
40937
  }
40931
- async function enforceEmitEventSchema(deps, eventType, payload, trustedTenantId) {
40938
+ async function enforceEmitEventGates(deps, eventType, payload, trustedTenantId, emitterAgentId) {
40932
40939
  if (!deps.validateEmitEvent)
40933
40940
  return null;
40934
- const verdict = await deps.validateEmitEvent(eventType, payload, trustedTenantId);
40941
+ const verdict = await deps.validateEmitEvent(eventType, payload, trustedTenantId, emitterAgentId);
40935
40942
  if (verdict.valid)
40936
40943
  return null;
40937
40944
  const detail = verdict.errors?.length ? `: ${verdict.errors.join("; ")}` : "";
40938
- logger2.warn("Emit event refused by schema registry", { eventType, errors: verdict.errors });
40945
+ logger2.warn("Emit event refused by emission gate", { eventType, emitterAgentId, errors: verdict.errors });
40939
40946
  return `${verdict.reason ?? SCHEMA_VALIDATION_FAILED}${detail}`;
40940
40947
  }
40941
40948
  async function prepareEmitEvent(config2, context, deps, trustedTenantId, actionIndex, provenance) {
@@ -40949,9 +40956,9 @@ async function prepareEmitEvent(config2, context, deps, trustedTenantId, actionI
40949
40956
  payload = context.payload;
40950
40957
  }
40951
40958
  const eventType = substituteTemplate(config2.eventType, context);
40952
- const schemaError = await enforceEmitEventSchema(deps, eventType, payload, trustedTenantId);
40953
- if (schemaError !== null) {
40954
- return { error: schemaError };
40959
+ const gateError = await enforceEmitEventGates(deps, eventType, payload, trustedTenantId, context.automation?.managedByAgentId ?? null);
40960
+ if (gateError !== null) {
40961
+ return { error: gateError };
40955
40962
  }
40956
40963
  const correlationId = context.event?.metadata.correlationId ?? context.payload.correlationId ?? undefined;
40957
40964
  const causationId = context.event?.id ?? provenance?.parentEventId;
@@ -41695,7 +41702,7 @@ class AutomationEngine {
41695
41702
  const instanceId = event.metadata.instanceId ?? "global";
41696
41703
  const context = createTemplateContext(event.payload, {
41697
41704
  event: { id: event.id, type: event.type, timestamp: event.timestamp, metadata: event.metadata },
41698
- automation: { id: automation.id }
41705
+ automation: { id: automation.id, managedByAgentId: automation.managedByAgentId ?? null }
41699
41706
  });
41700
41707
  await this.queueExecution(automation, event, context, instanceId);
41701
41708
  }
@@ -41733,7 +41740,7 @@ class AutomationEngine {
41733
41740
  timestamp: syntheticEvent.timestamp,
41734
41741
  metadata: syntheticEvent.metadata
41735
41742
  },
41736
- automation: { id: automation.id }
41743
+ automation: { id: automation.id, managedByAgentId: automation.managedByAgentId ?? null }
41737
41744
  });
41738
41745
  await this.queueExecution(automation, syntheticEvent, context, instanceId);
41739
41746
  };
@@ -70677,6 +70684,7 @@ __export(exports_src, {
70677
70684
  classifyEnvelope: () => classifyEnvelope,
70678
70685
  checkSessionReset: () => checkSessionReset,
70679
70686
  checkSchemaCompatibility: () => checkSchemaCompatibility,
70687
+ checkPublishAllowed: () => checkPublishAllowed,
70680
70688
  channelSupportsTypingIndicator: () => channelSupportsTypingIndicator,
70681
70689
  channelHasMessagingWindow: () => channelHasMessagingWindow,
70682
70690
  canonicalizeIpv4: () => canonicalizeIpv4,
@@ -70741,6 +70749,7 @@ __export(exports_src, {
70741
70749
  PersonWithIdentitiesSchema: () => PersonWithIdentitiesSchema,
70742
70750
  PersonSchema: () => PersonSchema,
70743
70751
  PaginationSchema: () => PaginationSchema,
70752
+ PUBLISH_NOT_DECLARED: () => PUBLISH_NOT_DECLARED,
70744
70753
  PROVIDER_SCHEMAS: () => PROVIDER_SCHEMAS,
70745
70754
  PAYLOAD_STAGES: () => PAYLOAD_STAGES,
70746
70755
  OutgoingMessageSchema: () => OutgoingMessageSchema,
@@ -136684,7 +136693,7 @@ import { fileURLToPath } from "url";
136684
136693
  // package.json
136685
136694
  var package_default = {
136686
136695
  name: "@automagik/omni",
136687
- version: "2.260908.6",
136696
+ version: "2.260908.8",
136688
136697
  repository: {
136689
136698
  type: "git",
136690
136699
  url: "git+https://github.com/automagik-dev/omni.git",
@@ -31330,7 +31330,14 @@ var init_events = __esm(() => {
31330
31330
  });
31331
31331
 
31332
31332
  // ../core/src/schemas/agent-manifest.ts
31333
- var EVENT_TYPE_TOKEN_PATTERN, ManifestEventTypeSchema, ManifestAcceptsEntrySchema, ManifestPublishesEntrySchema, AgentEventManifestSchema;
31333
+ function checkPublishAllowed(manifest, eventType) {
31334
+ const publishes = manifest?.publishes;
31335
+ if (!Array.isArray(publishes)) {
31336
+ return true;
31337
+ }
31338
+ return publishes.some((entry) => entry?.event === eventType);
31339
+ }
31340
+ var EVENT_TYPE_TOKEN_PATTERN, ManifestEventTypeSchema, ManifestAcceptsEntrySchema, ManifestPublishesEntrySchema, AgentEventManifestSchema, PUBLISH_NOT_DECLARED = "publish_not_declared";
31334
31341
  var init_agent_manifest = __esm(() => {
31335
31342
  init_zod();
31336
31343
  init_types2();
@@ -37832,14 +37839,14 @@ async function releaseEmissionClaim(deps, claimedEventId, eventType) {
37832
37839
  });
37833
37840
  });
37834
37841
  }
37835
- async function enforceEmitEventSchema(deps, eventType, payload, trustedTenantId) {
37842
+ async function enforceEmitEventGates(deps, eventType, payload, trustedTenantId, emitterAgentId) {
37836
37843
  if (!deps.validateEmitEvent)
37837
37844
  return null;
37838
- const verdict = await deps.validateEmitEvent(eventType, payload, trustedTenantId);
37845
+ const verdict = await deps.validateEmitEvent(eventType, payload, trustedTenantId, emitterAgentId);
37839
37846
  if (verdict.valid)
37840
37847
  return null;
37841
37848
  const detail = verdict.errors?.length ? `: ${verdict.errors.join("; ")}` : "";
37842
- logger2.warn("Emit event refused by schema registry", { eventType, errors: verdict.errors });
37849
+ logger2.warn("Emit event refused by emission gate", { eventType, emitterAgentId, errors: verdict.errors });
37843
37850
  return `${verdict.reason ?? SCHEMA_VALIDATION_FAILED}${detail}`;
37844
37851
  }
37845
37852
  async function prepareEmitEvent(config2, context2, deps, trustedTenantId, actionIndex, provenance) {
@@ -37853,9 +37860,9 @@ async function prepareEmitEvent(config2, context2, deps, trustedTenantId, action
37853
37860
  payload = context2.payload;
37854
37861
  }
37855
37862
  const eventType = substituteTemplate(config2.eventType, context2);
37856
- const schemaError = await enforceEmitEventSchema(deps, eventType, payload, trustedTenantId);
37857
- if (schemaError !== null) {
37858
- return { error: schemaError };
37863
+ const gateError = await enforceEmitEventGates(deps, eventType, payload, trustedTenantId, context2.automation?.managedByAgentId ?? null);
37864
+ if (gateError !== null) {
37865
+ return { error: gateError };
37859
37866
  }
37860
37867
  const correlationId = context2.event?.metadata.correlationId ?? context2.payload.correlationId ?? undefined;
37861
37868
  const causationId = context2.event?.id ?? provenance?.parentEventId;
@@ -38599,7 +38606,7 @@ class AutomationEngine {
38599
38606
  const instanceId = event.metadata.instanceId ?? "global";
38600
38607
  const context2 = createTemplateContext(event.payload, {
38601
38608
  event: { id: event.id, type: event.type, timestamp: event.timestamp, metadata: event.metadata },
38602
- automation: { id: automation.id }
38609
+ automation: { id: automation.id, managedByAgentId: automation.managedByAgentId ?? null }
38603
38610
  });
38604
38611
  await this.queueExecution(automation, event, context2, instanceId);
38605
38612
  }
@@ -38637,7 +38644,7 @@ class AutomationEngine {
38637
38644
  timestamp: syntheticEvent.timestamp,
38638
38645
  metadata: syntheticEvent.metadata
38639
38646
  },
38640
- automation: { id: automation.id }
38647
+ automation: { id: automation.id, managedByAgentId: automation.managedByAgentId ?? null }
38641
38648
  });
38642
38649
  await this.queueExecution(automation, syntheticEvent, context2, instanceId);
38643
38650
  };
@@ -44211,6 +44218,7 @@ __export(exports_src, {
44211
44218
  classifyEnvelope: () => classifyEnvelope,
44212
44219
  checkSessionReset: () => checkSessionReset,
44213
44220
  checkSchemaCompatibility: () => checkSchemaCompatibility,
44221
+ checkPublishAllowed: () => checkPublishAllowed,
44214
44222
  channelSupportsTypingIndicator: () => channelSupportsTypingIndicator,
44215
44223
  channelHasMessagingWindow: () => channelHasMessagingWindow,
44216
44224
  canonicalizeIpv4: () => canonicalizeIpv4,
@@ -44275,6 +44283,7 @@ __export(exports_src, {
44275
44283
  PersonWithIdentitiesSchema: () => PersonWithIdentitiesSchema,
44276
44284
  PersonSchema: () => PersonSchema,
44277
44285
  PaginationSchema: () => PaginationSchema,
44286
+ PUBLISH_NOT_DECLARED: () => PUBLISH_NOT_DECLARED,
44278
44287
  PROVIDER_SCHEMAS: () => PROVIDER_SCHEMAS,
44279
44288
  PAYLOAD_STAGES: () => PAYLOAD_STAGES,
44280
44289
  OutgoingMessageSchema: () => OutgoingMessageSchema,
@@ -251103,7 +251112,7 @@ var init_sentry_scrub = __esm(() => {
251103
251112
  var require_package7 = __commonJS((exports, module) => {
251104
251113
  module.exports = {
251105
251114
  name: "@omni/api",
251106
- version: "2.260908.6",
251115
+ version: "2.260908.8",
251107
251116
  private: true,
251108
251117
  type: "module",
251109
251118
  exports: {
@@ -387956,6 +387965,30 @@ async function resolveCallAgentChatIds(services, db3, ctx, trustedTenantId) {
387956
387965
  return { chatId: ctx.chatId, senderId: ctx.senderId };
387957
387966
  }
387958
387967
  }
387968
+ async function deadLetterRefusedEmission(services, db3, trustedTenantId, input) {
387969
+ try {
387970
+ await runTenantWorkDb(db3, trustedTenantId, () => services.deadLetters.createSchemaValidationFailure({
387971
+ eventId: generateId(),
387972
+ eventType: input.eventType,
387973
+ subject: input.eventType,
387974
+ payload: input.payload,
387975
+ errors: input.errors,
387976
+ reason: input.reason
387977
+ }));
387978
+ } catch (error3) {
387979
+ log130.error("Failed to dead-letter refused emit_event payload", {
387980
+ eventType: input.eventType,
387981
+ error: error3 instanceof Error ? error3.message : String(error3)
387982
+ });
387983
+ }
387984
+ }
387985
+ async function refusePublishNotDeclared(db3, trustedTenantId, emitterAgentId, eventType) {
387986
+ const [row] = await runTenantWorkDb(db3, trustedTenantId, () => scopedHandle(db3).select({ eventManifest: agents.eventManifest }).from(agents).where(eq(agents.id, emitterAgentId)).limit(1));
387987
+ if (checkPublishAllowed(row?.eventManifest ?? null, eventType)) {
387988
+ return null;
387989
+ }
387990
+ return [`event type '${eventType}' is not declared in the publishes manifest of agent ${emitterAgentId}`];
387991
+ }
387959
387992
  function buildAutomationEngineDeps(services, db3, options = {}) {
387960
387993
  const resolvePlugin = options.resolvePlugin ?? getPlugin;
387961
387994
  return {
@@ -388057,7 +388090,23 @@ function buildAutomationEngineDeps(services, db3, options = {}) {
388057
388090
  releaseEmittedEventClaim: async (eventId) => {
388058
388091
  await scopedHandle(db3).delete(omniEvents).where(eq(omniEvents.id, eventId));
388059
388092
  },
388060
- validateEmitEvent: async (eventType, payload, trustedTenantId = null) => {
388093
+ validateEmitEvent: async (eventType, payload, trustedTenantId = null, emitterAgentId = null) => {
388094
+ if (emitterAgentId) {
388095
+ const refusal = await refusePublishNotDeclared(db3, trustedTenantId, emitterAgentId, eventType);
388096
+ if (refusal) {
388097
+ log130.warn("emit_event refused: type not declared in the agent publishes manifest", {
388098
+ eventType,
388099
+ emitterAgentId
388100
+ });
388101
+ await deadLetterRefusedEmission(services, db3, trustedTenantId, {
388102
+ eventType,
388103
+ payload,
388104
+ errors: refusal,
388105
+ reason: PUBLISH_NOT_DECLARED
388106
+ });
388107
+ return { valid: false, errors: refusal, reason: PUBLISH_NOT_DECLARED };
388108
+ }
388109
+ }
388061
388110
  const verdict = await runTenantWorkDb(db3, trustedTenantId, () => services.eventSchemas.validate(eventType, payload));
388062
388111
  const strictEmit = process.env.OMNI_STRICT_EMIT_EVENT_SCHEMAS === "true";
388063
388112
  const refusedUnregistered = strictEmit && !verdict.registered;
@@ -388066,21 +388115,7 @@ function buildAutomationEngineDeps(services, db3, options = {}) {
388066
388115
  }
388067
388116
  const errors4 = refusedUnregistered ? [`no enabled schema is registered for event type '${eventType}'`] : verdict.errors;
388068
388117
  const reason2 = refusedUnregistered ? SCHEMA_NOT_REGISTERED : undefined;
388069
- try {
388070
- await runTenantWorkDb(db3, trustedTenantId, () => services.deadLetters.createSchemaValidationFailure({
388071
- eventId: generateId(),
388072
- eventType,
388073
- subject: eventType,
388074
- payload,
388075
- errors: errors4,
388076
- reason: reason2
388077
- }));
388078
- } catch (error3) {
388079
- log130.error("Failed to dead-letter refused emit_event payload", {
388080
- eventType,
388081
- error: error3 instanceof Error ? error3.message : String(error3)
388082
- });
388083
- }
388118
+ await deadLetterRefusedEmission(services, db3, trustedTenantId, { eventType, payload, errors: errors4, reason: reason2 });
388084
388119
  return { valid: false, errors: errors4, reason: reason2 };
388085
388120
  }
388086
388121
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automagik/omni",
3
- "version": "2.260908.6",
3
+ "version": "2.260908.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/automagik-dev/omni.git",