diff --git a/src/events/ans-bridge.ts b/src/events/ans-bridge.ts index c655cb0..c5fc96c 100644 --- a/src/events/ans-bridge.ts +++ b/src/events/ans-bridge.ts @@ -173,6 +173,10 @@ const EventPayloadSchemas: Readonly { + return EventPayloadSchemas[alertType] ?? AlertPayload +} + /** * JSON Schema for an event descriptor, in the subset ChatGPT accepts for tool * parameters: a plain object schema with no `$schema` and no top-level @@ -194,7 +198,7 @@ export function alertEventDefinitions(catalog: unknown) { description: `${alert.display_name}: ${alert.description}`, delivery: ['webhook'], inputSchema: descriptorSchema(AlertArguments), - payloadSchema: descriptorSchema(EventPayloadSchemas[alert.type]) + payloadSchema: descriptorSchema(payloadSchemaFor(alert.type)) })) } @@ -495,7 +499,7 @@ export async function forwardAnsWebhook( } catch { return new Response(null, { status: 400 }) } - const parsed = (EventPayloadSchemas[subscription.alertType] ?? AlertPayload).safeParse(raw) + const parsed = payloadSchemaFor(subscription.alertType).safeParse(raw) if (!parsed.success) { // Shape and failing paths only: alert values can hold customer data. console.log( diff --git a/tests/ans-bridge.test.ts b/tests/ans-bridge.test.ts index 36e0165..f35775d 100644 --- a/tests/ans-bridge.test.ts +++ b/tests/ans-bridge.test.ts @@ -1,7 +1,10 @@ +import { z } from 'zod' import { describe, expect, it, vi } from 'vitest' import { MAX_EVENT_BYTES, alertEventDefinitions, + AlertPayload, + payloadSchemaFor, SubscribeParams, UnsubscribeParams, forwardAnsWebhook, @@ -233,6 +236,11 @@ describe('ANS synchronous delivery bridge', () => { ).toEqual([]) }) + it('falls back to the generic alert payload for types without their own schema', () => { + expect(payloadSchemaFor('universal_ssl_event_type')).toBe(AlertPayload) + expect(() => z.toJSONSchema(payloadSchemaFor('universal_ssl_event_type'))).not.toThrow() + }) + it('does not accept subscriptions to events without an implemented contract', async () => { const deps = dependencies() deps.loadSubscription = vi.fn(async () => ({