@automate.ax/integration-contracts 0.137.0 → 0.138.0

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.
@@ -1,5 +1,6 @@
1
1
  import type { airtableTriggerContracts } from "./airtable/index.js";
2
2
  import type { apifyTriggerContracts } from "./apify/index.js";
3
+ import type { anthropicTriggerContracts } from "./anthropic/index.js";
3
4
  import type { axiomTriggerContracts } from "./axiom/index.js";
4
5
  import type { automateTriggerContracts } from "./automate/index.js";
5
6
  import type { asanaTriggerContracts } from "./asana/index.js";
@@ -30,7 +31,7 @@ import type { vercelTriggerContracts } from "./vercel/index.js";
30
31
  import type { webflowTriggerContracts } from "./webflow/index.js";
31
32
  import type { whatsappTriggerContracts } from "./whatsapp/index.js";
32
33
  import type { z } from "zod";
33
- export type TriggerContractMap = typeof airtableTriggerContracts & typeof apifyTriggerContracts & typeof axiomTriggerContracts & typeof automateTriggerContracts & typeof asanaTriggerContracts & typeof brevoTriggerContracts & typeof convexTriggerContracts & typeof discordTriggerContracts & typeof closeTriggerContracts & typeof cloudflareTriggerContracts & typeof githubTriggerContracts & typeof gmailTriggerContracts & typeof googleCalendarTriggerContracts & typeof googleDriveTriggerContracts & typeof googleFormsTriggerContracts & typeof googleMeetTriggerContracts & typeof googleSheetsTriggerContracts & typeof hubspotTriggerContracts & typeof linearTriggerContracts & typeof millionVerifierTriggerContracts & typeof notionTriggerContracts & typeof outlookTriggerContracts & typeof redditTriggerContracts & typeof resendTriggerContracts & typeof slackTriggerContracts & typeof stripeTriggerContracts & typeof teamsTriggerContracts & typeof trelloTriggerContracts & typeof vercelTriggerContracts & typeof webflowTriggerContracts & typeof whatsappTriggerContracts;
34
+ export type TriggerContractMap = typeof airtableTriggerContracts & typeof anthropicTriggerContracts & typeof apifyTriggerContracts & typeof axiomTriggerContracts & typeof automateTriggerContracts & typeof asanaTriggerContracts & typeof brevoTriggerContracts & typeof convexTriggerContracts & typeof discordTriggerContracts & typeof closeTriggerContracts & typeof cloudflareTriggerContracts & typeof githubTriggerContracts & typeof gmailTriggerContracts & typeof googleCalendarTriggerContracts & typeof googleDriveTriggerContracts & typeof googleFormsTriggerContracts & typeof googleMeetTriggerContracts & typeof googleSheetsTriggerContracts & typeof hubspotTriggerContracts & typeof linearTriggerContracts & typeof millionVerifierTriggerContracts & typeof notionTriggerContracts & typeof outlookTriggerContracts & typeof redditTriggerContracts & typeof resendTriggerContracts & typeof slackTriggerContracts & typeof stripeTriggerContracts & typeof teamsTriggerContracts & typeof trelloTriggerContracts & typeof vercelTriggerContracts & typeof webflowTriggerContracts & typeof whatsappTriggerContracts;
34
35
  export type IntegrationTriggerType = keyof TriggerContractMap;
35
36
  /** Canonical authoring configuration for one integration trigger type. */
36
37
  export type TriggerConfig<TType extends IntegrationTriggerType> = z.input<TriggerContractMap[TType]["configSchema"]> extends Record<string, never> ? object : z.input<TriggerContractMap[TType]["configSchema"]>;
@@ -323,6 +323,7 @@ export declare const whatsappTriggerContracts: {
323
323
  timestamp: z.ZodString;
324
324
  type: z.ZodEnum<{
325
325
  unknown: "unknown";
326
+ system: "system";
326
327
  audio: "audio";
327
328
  document: "document";
328
329
  image: "image";
@@ -330,7 +331,6 @@ export declare const whatsappTriggerContracts: {
330
331
  order: "order";
331
332
  text: "text";
332
333
  location: "location";
333
- system: "system";
334
334
  contacts: "contacts";
335
335
  reaction: "reaction";
336
336
  button: "button";
@@ -418,6 +418,7 @@ export declare const whatsappTriggerContracts: {
418
418
  timestamp: z.ZodString;
419
419
  type: z.ZodEnum<{
420
420
  unknown: "unknown";
421
+ system: "system";
421
422
  audio: "audio";
422
423
  document: "document";
423
424
  image: "image";
@@ -425,7 +426,6 @@ export declare const whatsappTriggerContracts: {
425
426
  order: "order";
426
427
  text: "text";
427
428
  location: "location";
428
- system: "system";
429
429
  contacts: "contacts";
430
430
  reaction: "reaction";
431
431
  button: "button";
@@ -89,6 +89,7 @@ export declare const WHATSAPP_WEBHOOK_SCHEMA: z.ZodObject<{
89
89
  timestamp: z.ZodString;
90
90
  type: z.ZodEnum<{
91
91
  unknown: "unknown";
92
+ system: "system";
92
93
  audio: "audio";
93
94
  document: "document";
94
95
  image: "image";
@@ -96,7 +97,6 @@ export declare const WHATSAPP_WEBHOOK_SCHEMA: z.ZodObject<{
96
97
  order: "order";
97
98
  text: "text";
98
99
  location: "location";
99
- system: "system";
100
100
  contacts: "contacts";
101
101
  reaction: "reaction";
102
102
  button: "button";
@@ -182,6 +182,7 @@ export declare const WHATSAPP_MESSAGE_RECEIVED_EVENT_SCHEMA: z.ZodObject<{
182
182
  timestamp: z.ZodString;
183
183
  type: z.ZodEnum<{
184
184
  unknown: "unknown";
185
+ system: "system";
185
186
  audio: "audio";
186
187
  document: "document";
187
188
  image: "image";
@@ -189,7 +190,6 @@ export declare const WHATSAPP_MESSAGE_RECEIVED_EVENT_SCHEMA: z.ZodObject<{
189
190
  order: "order";
190
191
  text: "text";
191
192
  location: "location";
192
- system: "system";
193
193
  contacts: "contacts";
194
194
  reaction: "reaction";
195
195
  button: "button";
@@ -277,6 +277,7 @@ export declare const WHATSAPP_MESSAGE_RECEIVED_EVENT_SCHEMA: z.ZodObject<{
277
277
  timestamp: z.ZodString;
278
278
  type: z.ZodEnum<{
279
279
  unknown: "unknown";
280
+ system: "system";
280
281
  audio: "audio";
281
282
  document: "document";
282
283
  image: "image";
@@ -284,7 +285,6 @@ export declare const WHATSAPP_MESSAGE_RECEIVED_EVENT_SCHEMA: z.ZodObject<{
284
285
  order: "order";
285
286
  text: "text";
286
287
  location: "location";
287
- system: "system";
288
288
  contacts: "contacts";
289
289
  reaction: "reaction";
290
290
  button: "button";
@@ -768,7 +768,7 @@ export declare function normalizeWhatsAppWebhook(input: unknown): {
768
768
  message: {
769
769
  id: string;
770
770
  timestamp: string;
771
- type: "unknown" | "audio" | "document" | "image" | "video" | "order" | "text" | "location" | "system" | "contacts" | "reaction" | "button" | "interactive" | "sticker" | "unsupported";
771
+ type: "unknown" | "system" | "audio" | "document" | "image" | "video" | "order" | "text" | "location" | "contacts" | "reaction" | "button" | "interactive" | "sticker" | "unsupported";
772
772
  content?: z.core.util.JSONType | undefined;
773
773
  context?: {
774
774
  messageId: string;
@@ -781,7 +781,7 @@ export declare function normalizeWhatsAppWebhook(input: unknown): {
781
781
  from: string;
782
782
  id: string;
783
783
  timestamp: string;
784
- type: "unknown" | "audio" | "document" | "image" | "video" | "order" | "text" | "location" | "system" | "contacts" | "reaction" | "button" | "interactive" | "sticker" | "unsupported";
784
+ type: "unknown" | "system" | "audio" | "document" | "image" | "video" | "order" | "text" | "location" | "contacts" | "reaction" | "button" | "interactive" | "sticker" | "unsupported";
785
785
  audio?: {
786
786
  id: string;
787
787
  mime_type?: string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automate.ax/integration-contracts",
3
- "version": "0.137.0",
3
+ "version": "0.138.0",
4
4
  "description": "Shared integration payload contracts and provider primitives for Automate.ax.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -18,6 +18,7 @@
18
18
  },
19
19
  "zshy": {
20
20
  "exports": {
21
+ "./anthropic": "./src/anthropic/index.ts",
21
22
  "./apify": "./src/apify/index.ts",
22
23
  "./airtable": "./src/airtable/index.ts",
23
24
  "./automate": "./src/automate/index.ts",
@@ -59,13 +60,15 @@
59
60
  }
60
61
  },
61
62
  "dependencies": {
62
- "@automate.ax/codec": "0.137.0",
63
+ "@anthropic-ai/sdk": "0.123.0",
64
+ "@automate.ax/codec": "0.138.0",
63
65
  "@cfworker/json-schema": "^4.1.1",
64
66
  "@googleapis/calendar": "^16.0.0",
65
67
  "@googleapis/forms": "^6.0.1",
66
68
  "@googleapis/gmail": "^12.0.0",
67
69
  "@googleapis/meet": "^5.0.0",
68
70
  "@notionhq/client": "5.26.0",
71
+ "@zachsents/zippy": "^1.4.0",
69
72
  "@octokit/openapi-webhooks-types": "^12.1.0",
70
73
  "@octokit/rest": "^22.0.1",
71
74
  "convex": "^1.45.0",
@@ -111,6 +114,11 @@
111
114
  "node": ">=24"
112
115
  },
113
116
  "exports": {
117
+ "./anthropic": {
118
+ "bun": "./src/anthropic/index.ts",
119
+ "types": "./dist/anthropic/index.d.ts",
120
+ "default": "./dist/anthropic/index.js"
121
+ },
114
122
  "./apify": {
115
123
  "bun": "./src/apify/index.ts",
116
124
  "types": "./dist/apify/index.d.ts",
@@ -0,0 +1,500 @@
1
+ import type { Beta } from "@anthropic-ai/sdk/resources/beta/beta"
2
+ import type { Encodable } from "@automate.ax/codec"
3
+ import * as z from "zod"
4
+ import { isPlainObject } from "@zachsents/zippy"
5
+ import type { CamelCasedPropertiesDeep } from "type-fest"
6
+
7
+ export const ANTHROPIC_SESSION_WEBHOOK_TYPES = [
8
+ "session.status_run_started",
9
+ "session.status_idled",
10
+ "session.budget_reached",
11
+ "session.status_rescheduled",
12
+ "session.status_terminated",
13
+ "session.thread_created",
14
+ "session.thread_idled",
15
+ "session.thread_terminated",
16
+ "session.outcome_evaluation_ended",
17
+ "session.updated",
18
+ "session.deleted",
19
+ ] as const
20
+
21
+ export const ANTHROPIC_AGENT_WEBHOOK_TYPES = [
22
+ "agent.created",
23
+ "agent.updated",
24
+ "agent.archived",
25
+ "agent.deleted",
26
+ ] as const
27
+
28
+ export const ANTHROPIC_ENVIRONMENT_WEBHOOK_TYPES = [
29
+ "environment.created",
30
+ "environment.updated",
31
+ "environment.archived",
32
+ "environment.deleted",
33
+ ] as const
34
+
35
+ export const ANTHROPIC_WEBHOOK_TYPES = [
36
+ ...ANTHROPIC_SESSION_WEBHOOK_TYPES,
37
+ ...ANTHROPIC_AGENT_WEBHOOK_TYPES,
38
+ ...ANTHROPIC_ENVIRONMENT_WEBHOOK_TYPES,
39
+ ] as const
40
+
41
+ export type AnthropicWebhookType = (typeof ANTHROPIC_WEBHOOK_TYPES)[number]
42
+
43
+ export const ANTHROPIC_TRIGGER_CONFIG_SCHEMA = z.object({})
44
+
45
+ export const ANTHROPIC_IDLE_EVENT_SCHEMA = z.object({
46
+ id: z.string(),
47
+ processedAt: z.iso.datetime(),
48
+ stopReason: z.discriminatedUnion("type", [
49
+ z.object({ type: z.literal("end_turn") }),
50
+ z.object({
51
+ eventIds: z.string().array(),
52
+ type: z.literal("requires_action"),
53
+ }),
54
+ z.object({ type: z.literal("budget_reached") }),
55
+ z.object({ type: z.literal("retries_exhausted") }),
56
+ ]),
57
+ type: z.literal("session.status_idle"),
58
+ })
59
+
60
+ const ANTHROPIC_EVENT_FIELDS = {
61
+ createdAt: z.iso.datetime(),
62
+ id: z.string(),
63
+ organizationId: z.string(),
64
+ resourceId: z.string(),
65
+ workspaceId: z.string(),
66
+ } as const
67
+
68
+ const ANTHROPIC_RESOURCE_SCHEMA = z
69
+ .object({ id: z.string(), type: z.string() })
70
+ .catchall(z.json())
71
+
72
+ /** Public camel-case form of an authoritative Managed Agents object. */
73
+ export type AnthropicAgentResource =
74
+ CamelCasedPropertiesDeep<Beta.BetaManagedAgentsAgent> & Encodable
75
+
76
+ /** Public camel-case form of an authoritative Managed Agents environment. */
77
+ export type AnthropicEnvironmentResource =
78
+ CamelCasedPropertiesDeep<Beta.BetaEnvironment> & Encodable
79
+
80
+ /** Public camel-case form of an authoritative Managed Agents session. */
81
+ export type AnthropicSessionResource =
82
+ CamelCasedPropertiesDeep<Beta.BetaManagedAgentsSession> & Encodable
83
+
84
+ /** Authoritative resource type carried by one provider event type. */
85
+ type AnthropicEventResource<TType extends AnthropicWebhookType> =
86
+ TType extends `${string}.deleted`
87
+ ? null
88
+ : TType extends `agent.${string}`
89
+ ? AnthropicAgentResource
90
+ : TType extends `environment.${string}`
91
+ ? AnthropicEnvironmentResource
92
+ : AnthropicSessionResource
93
+
94
+ /** Thread identifier presence carried by one provider event type. */
95
+ type AnthropicEventThreadId<TType extends AnthropicWebhookType> = TType extends
96
+ | "session.thread_created"
97
+ | "session.thread_idled"
98
+ | "session.thread_terminated"
99
+ ? string
100
+ : null
101
+
102
+ /** Exact public payload for one Managed Agents webhook type. */
103
+ export type AnthropicSemanticEvent<TType extends AnthropicWebhookType> =
104
+ TType extends AnthropicWebhookType
105
+ ? {
106
+ createdAt: string
107
+ id: string
108
+ idleEvent: TType extends "session.status_idled"
109
+ ? z.output<typeof ANTHROPIC_IDLE_EVENT_SCHEMA>
110
+ : null
111
+ organizationId: string
112
+ providerEventType: TType
113
+ resource: AnthropicEventResource<TType>
114
+ resourceId: string
115
+ sessionThreadId: AnthropicEventThreadId<TType>
116
+ workspaceId: string
117
+ }
118
+ : never
119
+
120
+ export type AnthropicAgentEvent = AnthropicSemanticEvent<
121
+ (typeof ANTHROPIC_AGENT_WEBHOOK_TYPES)[number]
122
+ >
123
+ export type AnthropicEnvironmentEvent = AnthropicSemanticEvent<
124
+ (typeof ANTHROPIC_ENVIRONMENT_WEBHOOK_TYPES)[number]
125
+ >
126
+ export type AnthropicSessionEvent = AnthropicSemanticEvent<
127
+ (typeof ANTHROPIC_SESSION_WEBHOOK_TYPES)[number]
128
+ >
129
+ export type AnthropicEvent = AnthropicSemanticEvent<AnthropicWebhookType>
130
+ export type AnthropicRunEvent = AnthropicSemanticEvent<
131
+ "session.status_idled" | "session.status_terminated"
132
+ >
133
+
134
+ const ANTHROPIC_AGENT_RESOURCE_SCHEMA = z.custom<AnthropicAgentResource>(
135
+ (value) => ANTHROPIC_RESOURCE_SCHEMA.safeParse(value).success,
136
+ )
137
+ const ANTHROPIC_ENVIRONMENT_RESOURCE_SCHEMA =
138
+ z.custom<AnthropicEnvironmentResource>(
139
+ (value) => ANTHROPIC_RESOURCE_SCHEMA.safeParse(value).success,
140
+ )
141
+ const ANTHROPIC_SESSION_RESOURCE_SCHEMA = z.custom<AnthropicSessionResource>(
142
+ (value) => ANTHROPIC_RESOURCE_SCHEMA.safeParse(value).success,
143
+ )
144
+
145
+ /**
146
+ * Builds one exact non-deletion webhook payload schema.
147
+ *
148
+ * @param providerEventType - Exact provider event discriminator.
149
+ * @param resource - Authoritative resource schema for the event family.
150
+ */
151
+ function resourceEventSchema<
152
+ const TType extends AnthropicWebhookType,
153
+ TResource,
154
+ >(providerEventType: TType, resource: z.ZodType<TResource>) {
155
+ return z.object({
156
+ ...ANTHROPIC_EVENT_FIELDS,
157
+ idleEvent: z.null(),
158
+ providerEventType: z.literal(providerEventType),
159
+ resource,
160
+ sessionThreadId: z.null(),
161
+ })
162
+ }
163
+
164
+ /**
165
+ * Builds one exact deletion webhook payload schema.
166
+ *
167
+ * @param providerEventType - Exact provider event discriminator.
168
+ */
169
+ function deletedEventSchema<const TType extends AnthropicWebhookType>(
170
+ providerEventType: TType,
171
+ ) {
172
+ return z.object({
173
+ ...ANTHROPIC_EVENT_FIELDS,
174
+ idleEvent: z.null(),
175
+ providerEventType: z.literal(providerEventType),
176
+ resource: z.null(),
177
+ sessionThreadId: z.null(),
178
+ })
179
+ }
180
+
181
+ /** Builds the exact enriched session-idled payload schema. */
182
+ function sessionIdledEventSchema() {
183
+ return z.object({
184
+ ...ANTHROPIC_EVENT_FIELDS,
185
+ idleEvent: ANTHROPIC_IDLE_EVENT_SCHEMA,
186
+ providerEventType: z.literal("session.status_idled"),
187
+ resource: ANTHROPIC_SESSION_RESOURCE_SCHEMA,
188
+ sessionThreadId: z.null(),
189
+ })
190
+ }
191
+
192
+ /**
193
+ * Builds an exact session-thread lifecycle payload schema.
194
+ *
195
+ * @param providerEventType - Exact thread event discriminator.
196
+ */
197
+ function sessionThreadEventSchema<
198
+ const TType extends
199
+ | "session.thread_created"
200
+ | "session.thread_idled"
201
+ | "session.thread_terminated",
202
+ >(providerEventType: TType) {
203
+ return z.object({
204
+ ...ANTHROPIC_EVENT_FIELDS,
205
+ idleEvent: z.null(),
206
+ providerEventType: z.literal(providerEventType),
207
+ resource: ANTHROPIC_SESSION_RESOURCE_SCHEMA,
208
+ sessionThreadId: z.string(),
209
+ })
210
+ }
211
+
212
+ /** Exact runtime schema registry for every provider webhook type. */
213
+ type AnthropicEventSchemas = {
214
+ readonly [TType in AnthropicWebhookType]: z.ZodType<
215
+ AnthropicSemanticEvent<TType>
216
+ >
217
+ }
218
+
219
+ const ANTHROPIC_EVENT_SCHEMAS: AnthropicEventSchemas = {
220
+ "agent.archived": resourceEventSchema(
221
+ "agent.archived",
222
+ ANTHROPIC_AGENT_RESOURCE_SCHEMA,
223
+ ),
224
+ "agent.created": resourceEventSchema(
225
+ "agent.created",
226
+ ANTHROPIC_AGENT_RESOURCE_SCHEMA,
227
+ ),
228
+ "agent.deleted": deletedEventSchema("agent.deleted"),
229
+ "agent.updated": resourceEventSchema(
230
+ "agent.updated",
231
+ ANTHROPIC_AGENT_RESOURCE_SCHEMA,
232
+ ),
233
+ "environment.archived": resourceEventSchema(
234
+ "environment.archived",
235
+ ANTHROPIC_ENVIRONMENT_RESOURCE_SCHEMA,
236
+ ),
237
+ "environment.created": resourceEventSchema(
238
+ "environment.created",
239
+ ANTHROPIC_ENVIRONMENT_RESOURCE_SCHEMA,
240
+ ),
241
+ "environment.deleted": deletedEventSchema("environment.deleted"),
242
+ "environment.updated": resourceEventSchema(
243
+ "environment.updated",
244
+ ANTHROPIC_ENVIRONMENT_RESOURCE_SCHEMA,
245
+ ),
246
+ "session.budget_reached": resourceEventSchema(
247
+ "session.budget_reached",
248
+ ANTHROPIC_SESSION_RESOURCE_SCHEMA,
249
+ ),
250
+ "session.deleted": deletedEventSchema("session.deleted"),
251
+ "session.outcome_evaluation_ended": resourceEventSchema(
252
+ "session.outcome_evaluation_ended",
253
+ ANTHROPIC_SESSION_RESOURCE_SCHEMA,
254
+ ),
255
+ "session.status_idled": sessionIdledEventSchema(),
256
+ "session.status_rescheduled": resourceEventSchema(
257
+ "session.status_rescheduled",
258
+ ANTHROPIC_SESSION_RESOURCE_SCHEMA,
259
+ ),
260
+ "session.status_run_started": resourceEventSchema(
261
+ "session.status_run_started",
262
+ ANTHROPIC_SESSION_RESOURCE_SCHEMA,
263
+ ),
264
+ "session.status_terminated": resourceEventSchema(
265
+ "session.status_terminated",
266
+ ANTHROPIC_SESSION_RESOURCE_SCHEMA,
267
+ ),
268
+ "session.thread_created": sessionThreadEventSchema("session.thread_created"),
269
+ "session.thread_idled": sessionThreadEventSchema("session.thread_idled"),
270
+ "session.thread_terminated": sessionThreadEventSchema(
271
+ "session.thread_terminated",
272
+ ),
273
+ "session.updated": resourceEventSchema(
274
+ "session.updated",
275
+ ANTHROPIC_SESSION_RESOURCE_SCHEMA,
276
+ ),
277
+ } as const
278
+
279
+ export const ANTHROPIC_AGENT_EVENT_SCHEMA: z.ZodType<AnthropicAgentEvent> =
280
+ z.union([
281
+ ANTHROPIC_EVENT_SCHEMAS["agent.archived"],
282
+ ANTHROPIC_EVENT_SCHEMAS["agent.created"],
283
+ ANTHROPIC_EVENT_SCHEMAS["agent.deleted"],
284
+ ANTHROPIC_EVENT_SCHEMAS["agent.updated"],
285
+ ])
286
+
287
+ export const ANTHROPIC_ENVIRONMENT_EVENT_SCHEMA: z.ZodType<AnthropicEnvironmentEvent> =
288
+ z.union([
289
+ ANTHROPIC_EVENT_SCHEMAS["environment.archived"],
290
+ ANTHROPIC_EVENT_SCHEMAS["environment.created"],
291
+ ANTHROPIC_EVENT_SCHEMAS["environment.deleted"],
292
+ ANTHROPIC_EVENT_SCHEMAS["environment.updated"],
293
+ ])
294
+
295
+ export const ANTHROPIC_SESSION_EVENT_SCHEMA: z.ZodType<AnthropicSessionEvent> =
296
+ z.union([
297
+ ANTHROPIC_EVENT_SCHEMAS["session.budget_reached"],
298
+ ANTHROPIC_EVENT_SCHEMAS["session.deleted"],
299
+ ANTHROPIC_EVENT_SCHEMAS["session.outcome_evaluation_ended"],
300
+ ANTHROPIC_EVENT_SCHEMAS["session.status_idled"],
301
+ ANTHROPIC_EVENT_SCHEMAS["session.status_rescheduled"],
302
+ ANTHROPIC_EVENT_SCHEMAS["session.status_run_started"],
303
+ ANTHROPIC_EVENT_SCHEMAS["session.status_terminated"],
304
+ ANTHROPIC_EVENT_SCHEMAS["session.thread_created"],
305
+ ANTHROPIC_EVENT_SCHEMAS["session.thread_idled"],
306
+ ANTHROPIC_EVENT_SCHEMAS["session.thread_terminated"],
307
+ ANTHROPIC_EVENT_SCHEMAS["session.updated"],
308
+ ])
309
+
310
+ export const ANTHROPIC_RUN_EVENT_SCHEMA: z.ZodType<AnthropicRunEvent> = z.union(
311
+ [
312
+ ANTHROPIC_EVENT_SCHEMAS["session.status_idled"],
313
+ ANTHROPIC_EVENT_SCHEMAS["session.status_terminated"],
314
+ ],
315
+ )
316
+
317
+ export const ANTHROPIC_EVENT_SCHEMA: z.ZodType<AnthropicEvent> = z.union([
318
+ ANTHROPIC_AGENT_EVENT_SCHEMA,
319
+ ANTHROPIC_ENVIRONMENT_EVENT_SCHEMA,
320
+ ANTHROPIC_SESSION_EVENT_SCHEMA,
321
+ ])
322
+
323
+ export const anthropicEventTypeMap = {
324
+ "agent.archived": "anthropic.agent.archived",
325
+ "agent.created": "anthropic.agent.created",
326
+ "agent.deleted": "anthropic.agent.deleted",
327
+ "agent.updated": "anthropic.agent.updated",
328
+ "environment.archived": "anthropic.environment.archived",
329
+ "environment.created": "anthropic.environment.created",
330
+ "environment.deleted": "anthropic.environment.deleted",
331
+ "environment.updated": "anthropic.environment.updated",
332
+ "session.budget_reached": "anthropic.session.budgetReached",
333
+ "session.deleted": "anthropic.session.deleted",
334
+ "session.outcome_evaluation_ended":
335
+ "anthropic.session.outcomeEvaluationEnded",
336
+ "session.status_idled": "anthropic.session.idled",
337
+ "session.status_rescheduled": "anthropic.session.rescheduled",
338
+ "session.status_run_started": "anthropic.session.runStarted",
339
+ "session.status_terminated": "anthropic.session.terminated",
340
+ "session.thread_created": "anthropic.session.threadCreated",
341
+ "session.thread_idled": "anthropic.session.threadIdled",
342
+ "session.thread_terminated": "anthropic.session.threadTerminated",
343
+ "session.updated": "anthropic.session.updated",
344
+ } as const satisfies Record<AnthropicWebhookType, string>
345
+
346
+ export const ANTHROPIC_BROAD_EVENT_TYPES = {
347
+ agent: "anthropic.agent.event",
348
+ environment: "anthropic.environment.event",
349
+ session: "anthropic.session.event",
350
+ } as const
351
+
352
+ type AnthropicTriggerEventTypes = {
353
+ readonly "anthropic.agent.archived": AnthropicSemanticEvent<"agent.archived">
354
+ readonly "anthropic.agent.created": AnthropicSemanticEvent<"agent.created">
355
+ readonly "anthropic.agent.deleted": AnthropicSemanticEvent<"agent.deleted">
356
+ readonly "anthropic.agent.event": AnthropicAgentEvent
357
+ readonly "anthropic.agent.updated": AnthropicSemanticEvent<"agent.updated">
358
+ readonly "anthropic.environment.archived": AnthropicSemanticEvent<"environment.archived">
359
+ readonly "anthropic.environment.created": AnthropicSemanticEvent<"environment.created">
360
+ readonly "anthropic.environment.deleted": AnthropicSemanticEvent<"environment.deleted">
361
+ readonly "anthropic.environment.event": AnthropicEnvironmentEvent
362
+ readonly "anthropic.environment.updated": AnthropicSemanticEvent<"environment.updated">
363
+ readonly "anthropic.session.budgetReached": AnthropicSemanticEvent<"session.budget_reached">
364
+ readonly "anthropic.session.deleted": AnthropicSemanticEvent<"session.deleted">
365
+ readonly "anthropic.session.event": AnthropicSessionEvent
366
+ readonly "anthropic.session.idled": AnthropicSemanticEvent<"session.status_idled">
367
+ readonly "anthropic.session.outcomeEvaluationEnded": AnthropicSemanticEvent<"session.outcome_evaluation_ended">
368
+ readonly "anthropic.session.rescheduled": AnthropicSemanticEvent<"session.status_rescheduled">
369
+ readonly "anthropic.session.runStarted": AnthropicSemanticEvent<"session.status_run_started">
370
+ readonly "anthropic.session.terminated": AnthropicSemanticEvent<"session.status_terminated">
371
+ readonly "anthropic.session.threadCreated": AnthropicSemanticEvent<"session.thread_created">
372
+ readonly "anthropic.session.threadIdled": AnthropicSemanticEvent<"session.thread_idled">
373
+ readonly "anthropic.session.threadTerminated": AnthropicSemanticEvent<"session.thread_terminated">
374
+ readonly "anthropic.session.updated": AnthropicSemanticEvent<"session.updated">
375
+ }
376
+
377
+ /** Named trigger registry shape keeps declaration emission compact. */
378
+ type AnthropicTriggerContracts = {
379
+ readonly [TType in keyof AnthropicTriggerEventTypes]: {
380
+ readonly configSchema: typeof ANTHROPIC_TRIGGER_CONFIG_SCHEMA
381
+ readonly eventSchema: z.ZodType<AnthropicTriggerEventTypes[TType]>
382
+ }
383
+ }
384
+
385
+ /**
386
+ * Binds one event schema to the shared Managed Agents trigger configuration.
387
+ *
388
+ * @param eventSchema - Family or semantic event schema.
389
+ */
390
+ function triggerContract<const TEventSchema extends z.ZodType<AnthropicEvent>>(
391
+ eventSchema: TEventSchema,
392
+ ) {
393
+ return { configSchema: ANTHROPIC_TRIGGER_CONFIG_SCHEMA, eventSchema } as const
394
+ }
395
+
396
+ export const anthropicTriggerContracts: AnthropicTriggerContracts = {
397
+ "anthropic.agent.archived": triggerContract(
398
+ ANTHROPIC_EVENT_SCHEMAS["agent.archived"],
399
+ ),
400
+ "anthropic.agent.created": triggerContract(
401
+ ANTHROPIC_EVENT_SCHEMAS["agent.created"],
402
+ ),
403
+ "anthropic.agent.deleted": triggerContract(
404
+ ANTHROPIC_EVENT_SCHEMAS["agent.deleted"],
405
+ ),
406
+ "anthropic.agent.event": triggerContract(ANTHROPIC_AGENT_EVENT_SCHEMA),
407
+ "anthropic.agent.updated": triggerContract(
408
+ ANTHROPIC_EVENT_SCHEMAS["agent.updated"],
409
+ ),
410
+ "anthropic.environment.archived": triggerContract(
411
+ ANTHROPIC_EVENT_SCHEMAS["environment.archived"],
412
+ ),
413
+ "anthropic.environment.created": triggerContract(
414
+ ANTHROPIC_EVENT_SCHEMAS["environment.created"],
415
+ ),
416
+ "anthropic.environment.deleted": triggerContract(
417
+ ANTHROPIC_EVENT_SCHEMAS["environment.deleted"],
418
+ ),
419
+ "anthropic.environment.event": triggerContract(
420
+ ANTHROPIC_ENVIRONMENT_EVENT_SCHEMA,
421
+ ),
422
+ "anthropic.environment.updated": triggerContract(
423
+ ANTHROPIC_EVENT_SCHEMAS["environment.updated"],
424
+ ),
425
+ "anthropic.session.budgetReached": triggerContract(
426
+ ANTHROPIC_EVENT_SCHEMAS["session.budget_reached"],
427
+ ),
428
+ "anthropic.session.deleted": triggerContract(
429
+ ANTHROPIC_EVENT_SCHEMAS["session.deleted"],
430
+ ),
431
+ "anthropic.session.event": triggerContract(ANTHROPIC_SESSION_EVENT_SCHEMA),
432
+ "anthropic.session.idled": triggerContract(
433
+ ANTHROPIC_EVENT_SCHEMAS["session.status_idled"],
434
+ ),
435
+ "anthropic.session.outcomeEvaluationEnded": triggerContract(
436
+ ANTHROPIC_EVENT_SCHEMAS["session.outcome_evaluation_ended"],
437
+ ),
438
+ "anthropic.session.rescheduled": triggerContract(
439
+ ANTHROPIC_EVENT_SCHEMAS["session.status_rescheduled"],
440
+ ),
441
+ "anthropic.session.runStarted": triggerContract(
442
+ ANTHROPIC_EVENT_SCHEMAS["session.status_run_started"],
443
+ ),
444
+ "anthropic.session.terminated": triggerContract(
445
+ ANTHROPIC_EVENT_SCHEMAS["session.status_terminated"],
446
+ ),
447
+ "anthropic.session.threadCreated": triggerContract(
448
+ ANTHROPIC_EVENT_SCHEMAS["session.thread_created"],
449
+ ),
450
+ "anthropic.session.threadIdled": triggerContract(
451
+ ANTHROPIC_EVENT_SCHEMAS["session.thread_idled"],
452
+ ),
453
+ "anthropic.session.threadTerminated": triggerContract(
454
+ ANTHROPIC_EVENT_SCHEMAS["session.thread_terminated"],
455
+ ),
456
+ "anthropic.session.updated": triggerContract(
457
+ ANTHROPIC_EVENT_SCHEMAS["session.updated"],
458
+ ),
459
+ } as const
460
+
461
+ /**
462
+ * Returns the broad and semantic event types for one verified delivery.
463
+ *
464
+ * @param type - Provider webhook event type.
465
+ */
466
+ export function getAnthropicEventTypes(type: AnthropicWebhookType) {
467
+ return [
468
+ type.startsWith("agent.")
469
+ ? ANTHROPIC_BROAD_EVENT_TYPES.agent
470
+ : type.startsWith("environment.")
471
+ ? ANTHROPIC_BROAD_EVENT_TYPES.environment
472
+ : ANTHROPIC_BROAD_EVENT_TYPES.session,
473
+ anthropicEventTypeMap[type],
474
+ ] as const
475
+ }
476
+
477
+ /**
478
+ * Converts Anthropic provider response keys to the public camelCase contract.
479
+ *
480
+ * @param value - Provider response value.
481
+ */
482
+ export function normalizeAnthropicValue(value: unknown): unknown {
483
+ if (Array.isArray(value)) return value.map(normalizeAnthropicValue)
484
+ if (!isPlainObject(value)) return value
485
+
486
+ return Object.fromEntries(
487
+ Object.entries(value).map(([key, item]) => {
488
+ const publicKey = key.replace(
489
+ /_([a-z0-9])/g,
490
+ (_match, character: string) => character.toUpperCase(),
491
+ )
492
+ return [
493
+ publicKey,
494
+ ["input", "inputSchema", "metadata"].includes(publicKey)
495
+ ? item
496
+ : normalizeAnthropicValue(item),
497
+ ]
498
+ }),
499
+ )
500
+ }
package/src/triggers.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { airtableTriggerContracts } from "./airtable"
2
2
  import type { apifyTriggerContracts } from "./apify"
3
+ import type { anthropicTriggerContracts } from "./anthropic"
3
4
  import type { axiomTriggerContracts } from "./axiom"
4
5
  import type { automateTriggerContracts } from "./automate"
5
6
  import type { asanaTriggerContracts } from "./asana"
@@ -32,6 +33,7 @@ import type { whatsappTriggerContracts } from "./whatsapp"
32
33
  import type { z } from "zod"
33
34
 
34
35
  export type TriggerContractMap = typeof airtableTriggerContracts &
36
+ typeof anthropicTriggerContracts &
35
37
  typeof apifyTriggerContracts &
36
38
  typeof axiomTriggerContracts &
37
39
  typeof automateTriggerContracts &