terse-types 0.0.18 → 0.0.20

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.
@@ -0,0 +1,437 @@
1
+ import { z } from "zod";
2
+ import { GitHubEventType, WorkOSEventType, gitHubEventTypeSchema, gmailEventTypeSchema, linearEventTypeSchema, slackEventTypeSchema, workOSEventTypeSchema } from "./Configs.js";
3
+ import { IntegrationType, integrationTypeEnum } from "./Integrations.js";
4
+ import { SlackChannelType } from "./SlackTypes.js";
5
+ import { debugTrigger as debugTriggerWithPresenter, formatTriggerForAgent as formatTriggerForAgentWithPresenter } from "./TriggerPresenters.js";
6
+ const providerTriggerTypeSchema = z.union([slackEventTypeSchema, gitHubEventTypeSchema, linearEventTypeSchema, gmailEventTypeSchema, workOSEventTypeSchema]);
7
+ const TriggerHeaderSchema = z.object({
8
+ integrationType: integrationTypeEnum,
9
+ eventType: providerTriggerTypeSchema
10
+ });
11
+ const slackTriggerBaseSchema = TriggerHeaderSchema.extend({
12
+ integrationType: z.literal(IntegrationType.SLACK),
13
+ eventType: slackEventTypeSchema,
14
+ channelId: z.string(),
15
+ channelName: z.string().nullable(),
16
+ userId: z.string(),
17
+ userName: z.string().nullable(),
18
+ text: z.string(),
19
+ timestamp: z.string(),
20
+ // Keep both names during migration; `threadTs` is the target shared field.
21
+ threadTs: z.string().nullable().optional(),
22
+ threadTimestamp: z.string().nullable(),
23
+ teamId: z.string(),
24
+ permalink: z.string().nullable(),
25
+ channelType: z.enum(SlackChannelType).nullable(),
26
+ blocks: z.array(z.unknown()).nullable(),
27
+ attachments: z.array(z.unknown()).nullable(),
28
+ files: z.array(z.unknown()).nullable()
29
+ });
30
+ export const slackMessageTriggerSchema = slackTriggerBaseSchema.extend({
31
+ eventType: z.literal("message")
32
+ });
33
+ export const slackAppMentionTriggerSchema = slackTriggerBaseSchema.extend({
34
+ eventType: z.literal("app_mention")
35
+ });
36
+ export const slackReactionAddedTriggerSchema = slackTriggerBaseSchema.extend({
37
+ eventType: z.literal("reaction_added"),
38
+ reaction: z.string(),
39
+ itemType: z.string().nullable(),
40
+ itemUserId: z.string().nullable(),
41
+ itemChannelId: z.string().nullable(),
42
+ itemTimestamp: z.string().nullable()
43
+ });
44
+ export const slackTriggerSchema = z.discriminatedUnion("eventType", [slackMessageTriggerSchema, slackAppMentionTriggerSchema, slackReactionAddedTriggerSchema]);
45
+ // Github Event Data
46
+ export const fileDiffSchema = z.object({
47
+ filename: z.string(),
48
+ diff: z.string()
49
+ });
50
+ export const commitSchema = z.object({
51
+ sha: z.string(),
52
+ // Keep both names during migration; `message` is the target shared field.
53
+ message: z.string().optional(),
54
+ name: z.string(),
55
+ fileDiffs: z.array(fileDiffSchema)
56
+ });
57
+ export const pullRequestUserSchema = z.object({
58
+ login: z.string(),
59
+ email: z.string().optional()
60
+ });
61
+ export const pullRequestRefSchema = z.object({
62
+ ref: z.string(),
63
+ sha: z.string()
64
+ });
65
+ export const pullRequestSchema = z.object({
66
+ id: z.string(),
67
+ number: z.number(),
68
+ title: z.string(),
69
+ body: z.string().optional(),
70
+ state: z.enum(["open", "closed"]),
71
+ merged: z.boolean(),
72
+ head: pullRequestRefSchema,
73
+ base: pullRequestRefSchema,
74
+ // Keep both names during migration; `author` is the target shared field.
75
+ user: pullRequestUserSchema,
76
+ author: pullRequestUserSchema.optional(),
77
+ url: z.string().optional()
78
+ });
79
+ export const githubRepositorySchema = z.object({
80
+ id: z.number(),
81
+ name: z.string(),
82
+ owner: z.string(),
83
+ defaultBranch: z.string()
84
+ });
85
+ export const senderSchema = z.object({
86
+ login: z.string(),
87
+ email: z.string().optional()
88
+ });
89
+ const GithubTriggerBaseSchema = z.object({
90
+ integrationType: z.literal(IntegrationType.GITHUB),
91
+ username: z.string(),
92
+ installationId: z.number(),
93
+ repositoryName: z.string(),
94
+ repository: githubRepositorySchema,
95
+ sender: senderSchema
96
+ });
97
+ export const GithubPushTriggerSchema = GithubTriggerBaseSchema.extend({
98
+ eventType: z.literal(GitHubEventType.PUSH),
99
+ branch: z.string(),
100
+ commits: z.array(commitSchema),
101
+ pullRequest: z.undefined().optional()
102
+ });
103
+ const GithubPRTriggerBaseSchema = GithubTriggerBaseSchema.extend({
104
+ pullRequest: pullRequestSchema,
105
+ branch: z.string().optional(),
106
+ commits: z.array(commitSchema)
107
+ });
108
+ export const GithubPROpenedTriggerSchema = GithubPRTriggerBaseSchema.extend({
109
+ eventType: z.literal(GitHubEventType.PR_OPENED)
110
+ });
111
+ export const GithubPRSynchronizedTriggerSchema = GithubPRTriggerBaseSchema.extend({
112
+ eventType: z.literal(GitHubEventType.PR_SYNCHRONIZE)
113
+ });
114
+ export const GithubPRClosedTriggerSchema = GithubPRTriggerBaseSchema.extend({
115
+ eventType: z.literal(GitHubEventType.PR_CLOSED)
116
+ });
117
+ export const GithubPRMergedTriggerSchema = GithubPRTriggerBaseSchema.extend({
118
+ eventType: z.literal(GitHubEventType.PR_MERGED)
119
+ });
120
+ export const GithubPRTriggerSchema = z.discriminatedUnion("eventType", [GithubPROpenedTriggerSchema, GithubPRSynchronizedTriggerSchema, GithubPRClosedTriggerSchema, GithubPRMergedTriggerSchema]);
121
+ export const GithubTriggerSchema = z.discriminatedUnion("eventType", [
122
+ GithubPushTriggerSchema,
123
+ GithubPROpenedTriggerSchema,
124
+ GithubPRSynchronizedTriggerSchema,
125
+ GithubPRClosedTriggerSchema,
126
+ GithubPRMergedTriggerSchema
127
+ ]);
128
+ export const GmailParsedAttachmentSchema = z.object({
129
+ attachmentId: z.string(),
130
+ filename: z.string(),
131
+ mimeType: z.string(),
132
+ contentId: z.string().optional(),
133
+ isInline: z.boolean()
134
+ });
135
+ const gmailMessagePayloadSchema = z.object({
136
+ id: z.string(),
137
+ threadId: z.string(),
138
+ subject: z.string(),
139
+ from: z.string(),
140
+ to: z.string(),
141
+ date: z.string(),
142
+ internalDate: z.string(),
143
+ messageId: z.string(),
144
+ body: z.string(),
145
+ snippet: z.string(),
146
+ labelIds: z.array(z.string()),
147
+ attachments: z.array(GmailParsedAttachmentSchema).optional()
148
+ });
149
+ export const LinearWebhookActionSchema = z.enum(["create", "update", "remove"]);
150
+ export const LinearWebhookTypeSchema = z.union([z.literal("Issue"), z.literal("Comment"), z.literal("Project"), z.string()]);
151
+ export const LinearWebhookActorSchema = z.object({
152
+ id: z.string(),
153
+ name: z.string(),
154
+ email: z.string(),
155
+ url: z.string(),
156
+ type: z.string()
157
+ });
158
+ export const LinearWebhookStateSchema = z.object({
159
+ id: z.string(),
160
+ color: z.string(),
161
+ name: z.string(),
162
+ type: z.string()
163
+ });
164
+ export const LinearWebhookTeamSchema = z.object({
165
+ id: z.string(),
166
+ key: z.string(),
167
+ name: z.string()
168
+ });
169
+ export const LinearWebhookAssigneeSchema = z.object({
170
+ id: z.string(),
171
+ name: z.string()
172
+ });
173
+ export const LinearWebhookDataSchema = z.object({
174
+ id: z.string(),
175
+ createdAt: z.string(),
176
+ updatedAt: z.string(),
177
+ number: z.number(),
178
+ title: z.string(),
179
+ priority: z.number(),
180
+ sortOrder: z.number(),
181
+ prioritySortOrder: z.number(),
182
+ slaType: z.string(),
183
+ addedToTeamAt: z.string(),
184
+ trashed: z.boolean(),
185
+ labelIds: z.array(z.string()),
186
+ teamId: z.string(),
187
+ previousIdentifiers: z.array(z.string()),
188
+ stateId: z.string(),
189
+ reactionData: z.array(z.any()),
190
+ priorityLabel: z.string(),
191
+ botActor: z.string().optional(),
192
+ identifier: z.string(),
193
+ url: z.string(),
194
+ subscriberIds: z.array(z.string()),
195
+ state: LinearWebhookStateSchema,
196
+ team: LinearWebhookTeamSchema,
197
+ labels: z.array(z.any()),
198
+ description: z.string().optional(),
199
+ descriptionData: z.string().optional(),
200
+ assignee: LinearWebhookAssigneeSchema.optional()
201
+ });
202
+ export const LinearWebhookCommentDataSchema = z
203
+ .object({
204
+ id: z.string(),
205
+ body: z.string().optional(),
206
+ issueId: z.string().optional()
207
+ })
208
+ .passthrough();
209
+ export const linearWebhookPayloadSchema = z.object({
210
+ action: LinearWebhookActionSchema,
211
+ actor: LinearWebhookActorSchema,
212
+ createdAt: z.string(),
213
+ data: LinearWebhookDataSchema,
214
+ type: LinearWebhookTypeSchema,
215
+ url: z.string().optional(),
216
+ organizationId: z.string(),
217
+ webhookTimestamp: z.number(),
218
+ webhookId: z.string()
219
+ });
220
+ export const WorkOSWebhookDataSchema = z.record(z.string(), z.any());
221
+ export const workOSWebhookPayloadSchema = z.object({
222
+ id: z.string(),
223
+ event: z.string(),
224
+ data: WorkOSWebhookDataSchema,
225
+ created_at: z.string()
226
+ });
227
+ // MARK: Canonical Trigger Events
228
+ export const webhookTriggerTypeSchema = z.literal("webhook");
229
+ export const cronTriggerTypeSchema = z.literal("cron");
230
+ export const manualSampleTriggerTypeSchema = z.literal("manual_sample");
231
+ export const TriggerTypeSchema = z.union([
232
+ slackEventTypeSchema,
233
+ gitHubEventTypeSchema,
234
+ linearEventTypeSchema,
235
+ gmailEventTypeSchema,
236
+ workOSEventTypeSchema,
237
+ webhookTriggerTypeSchema,
238
+ cronTriggerTypeSchema,
239
+ manualSampleTriggerTypeSchema
240
+ ]);
241
+ export const baseTriggerSchema = z.object({
242
+ integrationType: integrationTypeEnum,
243
+ eventType: TriggerTypeSchema
244
+ });
245
+ export const gmailTriggerSchema = baseTriggerSchema
246
+ .extend({
247
+ integrationType: z.literal(IntegrationType.GMAIL),
248
+ eventType: gmailEventTypeSchema
249
+ })
250
+ .merge(gmailMessagePayloadSchema);
251
+ const linearTriggerBaseSchema = z.object({
252
+ integrationType: z.literal(IntegrationType.LINEAR),
253
+ action: LinearWebhookActionSchema,
254
+ actor: LinearWebhookActorSchema,
255
+ createdAt: z.string(),
256
+ url: z.string().optional(),
257
+ organizationId: z.string(),
258
+ webhookTimestamp: z.number(),
259
+ webhookId: z.string()
260
+ });
261
+ export const linearIssueCreatedTriggerSchema = linearTriggerBaseSchema.extend({
262
+ eventType: z.literal("issue.created"),
263
+ action: z.literal("create"),
264
+ type: z.literal("Issue"),
265
+ data: LinearWebhookDataSchema
266
+ });
267
+ export const linearIssueUpdatedTriggerSchema = linearTriggerBaseSchema.extend({
268
+ eventType: z.literal("issue.updated"),
269
+ action: z.literal("update"),
270
+ type: z.literal("Issue"),
271
+ data: LinearWebhookDataSchema
272
+ });
273
+ export const linearCommentCreatedTriggerSchema = linearTriggerBaseSchema.extend({
274
+ eventType: z.literal("comment.created"),
275
+ action: z.literal("create"),
276
+ type: z.literal("Comment"),
277
+ data: LinearWebhookCommentDataSchema
278
+ });
279
+ export const linearTriggerSchema = z.discriminatedUnion("eventType", [linearIssueCreatedTriggerSchema, linearIssueUpdatedTriggerSchema, linearCommentCreatedTriggerSchema]);
280
+ export const workOSTriggerUserSchema = z.object({
281
+ id: z.string(),
282
+ email: z.string(),
283
+ firstName: z.string().optional(),
284
+ lastName: z.string().optional(),
285
+ emailVerified: z.boolean(),
286
+ profilePictureUrl: z.string().optional()
287
+ });
288
+ export const workOSTriggerMembershipSchema = z.object({
289
+ id: z.string(),
290
+ userId: z.string(),
291
+ organizationId: z.string(),
292
+ role: z.object({
293
+ slug: z.string()
294
+ }),
295
+ status: z.string()
296
+ });
297
+ export const workOSTriggerInvitationSchema = z.object({
298
+ id: z.string(),
299
+ email: z.string(),
300
+ organizationId: z.string(),
301
+ inviterEmail: z.string().optional(),
302
+ state: z.string(),
303
+ acceptedAt: z.string().optional()
304
+ });
305
+ export const workOSTriggerOrganizationSchema = z.object({
306
+ id: z.string(),
307
+ name: z.string()
308
+ });
309
+ const workOSTriggerBaseSchema = baseTriggerSchema.extend({
310
+ integrationType: z.literal(IntegrationType.WORKOS),
311
+ eventType: workOSEventTypeSchema,
312
+ eventId: z.string(),
313
+ createdAt: z.string()
314
+ });
315
+ export const workOSUserCreatedTriggerSchema = workOSTriggerBaseSchema.extend({
316
+ eventType: z.literal(WorkOSEventType.USER_CREATED),
317
+ user: workOSTriggerUserSchema
318
+ });
319
+ export const workOSUserUpdatedTriggerSchema = workOSTriggerBaseSchema.extend({
320
+ eventType: z.literal(WorkOSEventType.USER_UPDATED),
321
+ user: workOSTriggerUserSchema
322
+ });
323
+ export const workOSUserDeletedTriggerSchema = workOSTriggerBaseSchema.extend({
324
+ eventType: z.literal(WorkOSEventType.USER_DELETED),
325
+ user: workOSTriggerUserSchema
326
+ });
327
+ export const workOSUserTriggerSchema = z.discriminatedUnion("eventType", [workOSUserCreatedTriggerSchema, workOSUserUpdatedTriggerSchema, workOSUserDeletedTriggerSchema]);
328
+ export const workOSOrganizationMembershipCreatedTriggerSchema = workOSTriggerBaseSchema.extend({
329
+ eventType: z.literal(WorkOSEventType.ORGANIZATION_MEMBERSHIP_CREATED),
330
+ membership: workOSTriggerMembershipSchema
331
+ });
332
+ export const workOSOrganizationMembershipUpdatedTriggerSchema = workOSTriggerBaseSchema.extend({
333
+ eventType: z.literal(WorkOSEventType.ORGANIZATION_MEMBERSHIP_UPDATED),
334
+ membership: workOSTriggerMembershipSchema
335
+ });
336
+ export const workOSOrganizationMembershipDeletedTriggerSchema = workOSTriggerBaseSchema.extend({
337
+ eventType: z.literal(WorkOSEventType.ORGANIZATION_MEMBERSHIP_DELETED),
338
+ membership: workOSTriggerMembershipSchema
339
+ });
340
+ export const workOSMembershipTriggerSchema = z.discriminatedUnion("eventType", [
341
+ workOSOrganizationMembershipCreatedTriggerSchema,
342
+ workOSOrganizationMembershipUpdatedTriggerSchema,
343
+ workOSOrganizationMembershipDeletedTriggerSchema
344
+ ]);
345
+ export const workOSInvitationCreatedTriggerSchema = workOSTriggerBaseSchema.extend({
346
+ eventType: z.literal(WorkOSEventType.INVITATION_CREATED),
347
+ invitation: workOSTriggerInvitationSchema,
348
+ user: workOSTriggerUserSchema.optional()
349
+ });
350
+ export const workOSInvitationAcceptedTriggerSchema = workOSTriggerBaseSchema.extend({
351
+ eventType: z.literal(WorkOSEventType.INVITATION_ACCEPTED),
352
+ invitation: workOSTriggerInvitationSchema,
353
+ user: workOSTriggerUserSchema.optional()
354
+ });
355
+ export const workOSInvitationResentTriggerSchema = workOSTriggerBaseSchema.extend({
356
+ eventType: z.literal(WorkOSEventType.INVITATION_RESENT),
357
+ invitation: workOSTriggerInvitationSchema,
358
+ user: workOSTriggerUserSchema.optional()
359
+ });
360
+ export const workOSInvitationRevokedTriggerSchema = workOSTriggerBaseSchema.extend({
361
+ eventType: z.literal(WorkOSEventType.INVITATION_REVOKED),
362
+ invitation: workOSTriggerInvitationSchema,
363
+ user: workOSTriggerUserSchema.optional()
364
+ });
365
+ export const workOSInvitationTriggerSchema = z.discriminatedUnion("eventType", [
366
+ workOSInvitationCreatedTriggerSchema,
367
+ workOSInvitationAcceptedTriggerSchema,
368
+ workOSInvitationResentTriggerSchema,
369
+ workOSInvitationRevokedTriggerSchema
370
+ ]);
371
+ export const workOSOrganizationTriggerSchema = workOSTriggerBaseSchema.extend({
372
+ eventType: z.literal(WorkOSEventType.ORGANIZATION_CREATED),
373
+ organization: workOSTriggerOrganizationSchema
374
+ });
375
+ export const workOSTriggerSchema = z.discriminatedUnion("eventType", [
376
+ workOSUserCreatedTriggerSchema,
377
+ workOSUserUpdatedTriggerSchema,
378
+ workOSUserDeletedTriggerSchema,
379
+ workOSOrganizationMembershipCreatedTriggerSchema,
380
+ workOSOrganizationMembershipUpdatedTriggerSchema,
381
+ workOSOrganizationMembershipDeletedTriggerSchema,
382
+ workOSInvitationCreatedTriggerSchema,
383
+ workOSInvitationAcceptedTriggerSchema,
384
+ workOSInvitationResentTriggerSchema,
385
+ workOSInvitationRevokedTriggerSchema,
386
+ workOSOrganizationTriggerSchema
387
+ ]);
388
+ export const webhookTriggerSchema = baseTriggerSchema.extend({
389
+ integrationType: z.literal(IntegrationType.WEBHOOK),
390
+ eventType: webhookTriggerTypeSchema,
391
+ body: z.record(z.string(), z.unknown()),
392
+ headers: z.record(z.string(), z.string()),
393
+ method: z.string()
394
+ });
395
+ export const cronTriggerSchema = baseTriggerSchema.extend({
396
+ integrationType: z.literal(IntegrationType.CRON_JOB),
397
+ eventType: cronTriggerTypeSchema,
398
+ inputId: z.string(),
399
+ isManualTrigger: z.boolean().optional(),
400
+ manualContext: z.string().optional()
401
+ });
402
+ export const manualSampleTriggerSchema = baseTriggerSchema.extend({
403
+ eventType: manualSampleTriggerTypeSchema
404
+ });
405
+ export const TriggerSchema = z.union([
406
+ slackTriggerSchema,
407
+ GithubTriggerSchema,
408
+ gmailTriggerSchema,
409
+ linearTriggerSchema,
410
+ workOSTriggerSchema,
411
+ webhookTriggerSchema,
412
+ cronTriggerSchema,
413
+ manualSampleTriggerSchema
414
+ ]);
415
+ export function parseTrigger(value) {
416
+ return TriggerSchema.parse(value);
417
+ }
418
+ export function createManualTrigger(params = {}) {
419
+ return parseTrigger({
420
+ integrationType: params.integrationType ?? IntegrationType.TERSE,
421
+ eventType: "manual_sample"
422
+ });
423
+ }
424
+ export function formatTriggerForAgent(event) {
425
+ return formatTriggerForAgentWithPresenter(event);
426
+ }
427
+ export function debugTrigger(event) {
428
+ return debugTriggerWithPresenter(event);
429
+ }
430
+ export const TriggerArraySchema = z.array(TriggerSchema);
431
+ export const serializedEventSchema = z.object({
432
+ integrationType: integrationTypeEnum,
433
+ eventType: TriggerTypeSchema,
434
+ formattedContent: z.string(),
435
+ debugLog: z.string(),
436
+ data: TriggerSchema
437
+ });
@@ -1,3 +1,8 @@
1
1
  import type { Trigger } from "./Triggers.js";
2
+ export interface TriggerDisplay {
3
+ title: string;
4
+ subtitle: string;
5
+ }
2
6
  export declare function formatTriggerForAgent(event: Trigger): string;
3
7
  export declare function debugTrigger(event: Trigger): string;
8
+ export declare function displayTrigger(event: Trigger): TriggerDisplay;
@@ -2,22 +2,32 @@ import { IntegrationType } from "./Integrations.js";
2
2
  const TriggerPresenters = {
3
3
  manual_sample: {
4
4
  formatForAgent: (event) => `Manual sample event for ${event.integrationType}.`,
5
- debug: (event) => `${event.integrationType} ${event.eventType}`
5
+ debug: (event) => `${event.integrationType} ${event.eventType}`,
6
+ display: (event) => ({
7
+ title: `Manual ${event.integrationType} sample`,
8
+ subtitle: event.eventType
9
+ })
6
10
  },
7
11
  [IntegrationType.GITHUB]: {
8
12
  formatForAgent: formatGithubTrigger,
9
- debug: (event) => `GitHub Event: ${event.eventType} - ${event.repository.owner}/${event.repository.name} - ${event.sender.login}`
13
+ debug: (event) => `GitHub Event: ${event.eventType} - ${event.repository.owner}/${event.repository.name} - ${event.sender.login}`,
14
+ display: formatGithubDisplay
10
15
  },
11
16
  [IntegrationType.SLACK]: {
12
17
  formatForAgent: formatSlackTrigger,
13
18
  debug: (event) => {
14
19
  const isDM = event.channelType === "im";
15
20
  return `Slack Event: ${event.eventType} - ${isDM ? "DM" : event.channelName || event.channelId} - ${event.userName || event.userId}`;
16
- }
21
+ },
22
+ display: formatSlackDisplay
17
23
  },
18
24
  [IntegrationType.GMAIL]: {
19
25
  formatForAgent: formatGmailTrigger,
20
- debug: (event) => `Gmail Event: ${event.subject} message ID: ${event.messageId}`
26
+ debug: (event) => `Gmail Event: ${event.subject} message ID: ${event.messageId}`,
27
+ display: (event) => ({
28
+ title: event.subject || "(no subject)",
29
+ subtitle: `from ${event.from}`
30
+ })
21
31
  },
22
32
  [IntegrationType.LINEAR]: {
23
33
  formatForAgent: formatLinearTrigger,
@@ -26,23 +36,39 @@ const TriggerPresenters = {
26
36
  return `Linear ${event.type} Event: ${event.data.identifier} - ${event.data.title} (${event.action})`;
27
37
  }
28
38
  return `Linear ${event.type} Event: Comment on issue ${event.data.issueId || "Unknown"} (${event.action})`;
39
+ },
40
+ display: (event) => {
41
+ if (event.type === "Issue") {
42
+ return {
43
+ title: `${event.data.identifier} ${event.data.title}`,
44
+ subtitle: `${event.data.team?.name || "Linear"} · ${event.action} issue`
45
+ };
46
+ }
47
+ return {
48
+ title: `Comment on ${event.data.issueId || "Unknown issue"}`,
49
+ subtitle: `${event.actor.name} · ${event.action} comment`
50
+ };
29
51
  }
30
52
  },
31
53
  [IntegrationType.WORKOS]: {
32
54
  formatForAgent: formatWorkOSTrigger,
33
- debug: (event) => `WorkOS ${event.eventType}`
55
+ debug: (event) => `WorkOS ${event.eventType}`,
56
+ display: formatWorkOSDisplay
34
57
  },
35
58
  [IntegrationType.WEBHOOK]: {
36
59
  formatForAgent: formatWebhookTrigger,
37
- debug: (event) => `Webhook Trigger (${event.method})`
60
+ debug: (event) => `Webhook Trigger (${event.method})`,
61
+ display: formatWebhookDisplay
38
62
  },
39
63
  [IntegrationType.CRON_JOB]: {
40
64
  formatForAgent: formatCronTrigger,
41
- debug: (event) => (event.isManualTrigger ? "Manual Trigger" : "Scheduled Event")
65
+ debug: (event) => (event.isManualTrigger ? "Manual Trigger" : "Scheduled Event"),
66
+ display: formatCronDisplay
42
67
  },
43
68
  [IntegrationType.WEBMONITOR]: {
44
69
  formatForAgent: formatWebMonitorTrigger,
45
- debug: (event) => `${event.query.slice(0, 80)}${event.query.length > 80 ? "…" : ""}`
70
+ debug: (event) => `${event.query.slice(0, 80)}${event.query.length > 80 ? "…" : ""}`,
71
+ display: formatWebMonitorDisplay
46
72
  }
47
73
  };
48
74
  function dispatchPresenter(event, method) {
@@ -77,6 +103,12 @@ export function debugTrigger(event) {
77
103
  }
78
104
  return dispatchPresenter(event, "debug");
79
105
  }
106
+ export function displayTrigger(event) {
107
+ if (event.eventType === "manual_sample") {
108
+ return TriggerPresenters.manual_sample.display(event);
109
+ }
110
+ return dispatchPresenter(event, "display");
111
+ }
80
112
  function formatGithubTrigger(event) {
81
113
  const indentMultiline = (text) => text
82
114
  .split("\n")
@@ -174,6 +206,122 @@ function formatSlackTrigger(event) {
174
206
  : ""}
175
207
  `;
176
208
  }
209
+ function formatSlackDisplay(event) {
210
+ const channelLabel = event.channelType === "im" ? "DM" : event.channelName || event.channelId;
211
+ const actorLabel = event.userName || event.userId;
212
+ if (event.eventType === "reaction_added") {
213
+ return {
214
+ title: `:${event.reaction || "reaction"}: reaction`,
215
+ subtitle: `${channelLabel} by ${actorLabel}`
216
+ };
217
+ }
218
+ const messageText = event.text?.trim();
219
+ return {
220
+ title: messageText && messageText.length > 0 ? truncateForDisplay(messageText, 80) : "(no message text)",
221
+ subtitle: `${channelLabel} by ${actorLabel}`
222
+ };
223
+ }
224
+ function truncateForDisplay(value, maxLength) {
225
+ return value.length > maxLength ? `${value.slice(0, maxLength - 1)}…` : value;
226
+ }
227
+ function formatGithubDisplay(event) {
228
+ if (event.pullRequest) {
229
+ return {
230
+ title: `#${event.pullRequest.number} ${truncateForDisplay(event.pullRequest.title, 80)}`,
231
+ subtitle: `${event.repository.owner}/${event.repository.name} · ${event.eventType} by ${event.sender.login}`
232
+ };
233
+ }
234
+ if (event.commits.length > 0) {
235
+ const latestCommit = event.commits[event.commits.length - 1];
236
+ const commitMessage = latestCommit.message || latestCommit.name || latestCommit.sha.slice(0, 7);
237
+ return {
238
+ title: truncateForDisplay(commitMessage, 80),
239
+ subtitle: `${event.repository.owner}/${event.repository.name} · ${event.commits.length} commit${event.commits.length === 1 ? "" : "s"} on ${event.branch || "branch"}`
240
+ };
241
+ }
242
+ return {
243
+ title: `${event.repository.owner}/${event.repository.name}`,
244
+ subtitle: `${event.eventType} by ${event.sender.login}`
245
+ };
246
+ }
247
+ function formatWorkOSDisplay(event) {
248
+ if ("user" in event && event.user) {
249
+ return {
250
+ title: event.user.email,
251
+ subtitle: humanizeWorkOSEventType(event.eventType)
252
+ };
253
+ }
254
+ if ("organization" in event && event.organization) {
255
+ return {
256
+ title: event.organization.name,
257
+ subtitle: humanizeWorkOSEventType(event.eventType)
258
+ };
259
+ }
260
+ if ("invitation" in event && event.invitation) {
261
+ return {
262
+ title: event.invitation.email,
263
+ subtitle: humanizeWorkOSEventType(event.eventType)
264
+ };
265
+ }
266
+ if ("membership" in event && event.membership) {
267
+ return {
268
+ title: event.membership.role.slug,
269
+ subtitle: humanizeWorkOSEventType(event.eventType)
270
+ };
271
+ }
272
+ return {
273
+ title: "WorkOS event",
274
+ subtitle: humanizeWorkOSEventType(event.eventType)
275
+ };
276
+ }
277
+ function humanizeWorkOSEventType(eventType) {
278
+ return eventType.replaceAll(".", " ");
279
+ }
280
+ function formatWebhookDisplay(event) {
281
+ const bodyPreview = summarizeUnknown(event.body);
282
+ return {
283
+ title: bodyPreview || "Webhook trigger",
284
+ subtitle: event.method
285
+ };
286
+ }
287
+ function formatCronDisplay(event) {
288
+ return {
289
+ title: event.isManualTrigger ? "Manual trigger" : "Scheduled event",
290
+ subtitle: event.manualContext ? truncateForDisplay(event.manualContext, 80) : event.inputId
291
+ };
292
+ }
293
+ function formatWebMonitorDisplay(event) {
294
+ const sourceLabel = firstHost(event.sourceUrls);
295
+ const outputPreview = typeof event.payload === "string" ? event.payload : typeof event.rawPayload === "string" ? event.rawPayload : "";
296
+ return {
297
+ title: sourceLabel ? `Change detected on ${sourceLabel}` : "Web monitor match",
298
+ subtitle: truncateForDisplay(outputPreview || event.query, 100)
299
+ };
300
+ }
301
+ function firstHost(urls) {
302
+ const first = urls[0];
303
+ if (!first)
304
+ return null;
305
+ try {
306
+ return new URL(first).host;
307
+ }
308
+ catch {
309
+ return first;
310
+ }
311
+ }
312
+ function summarizeUnknown(value) {
313
+ if (typeof value === "string") {
314
+ return truncateForDisplay(value.trim() || "Webhook trigger", 80);
315
+ }
316
+ if (value && typeof value === "object") {
317
+ const record = value;
318
+ const preferred = [record.title, record.subject, record.name, record.action, record.type, record.event].find(v => typeof v === "string" && v.trim().length > 0);
319
+ if (typeof preferred === "string") {
320
+ return truncateForDisplay(preferred, 80);
321
+ }
322
+ }
323
+ return "Webhook trigger";
324
+ }
177
325
  function formatGmailTrigger(event) {
178
326
  const attachmentInfo = event.attachments?.map(attachment => `- ${attachment.filename} ${attachment.isInline ? "Inline" : "Attachment"} (${attachment.mimeType})`).join("\n") || "No attachments";
179
327
  return `
@@ -2820,6 +2820,7 @@ export declare function createManualTrigger(params?: {
2820
2820
  }): Trigger;
2821
2821
  export declare function formatTriggerForAgent(event: Trigger): string;
2822
2822
  export declare function debugTrigger(event: Trigger): string;
2823
+ export declare function displayTrigger(event: Trigger): SerializedEventDisplay;
2823
2824
  export declare const TriggerArraySchema: z.ZodArray<z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
2824
2825
  integrationType: z.ZodLiteral<IntegrationType.SLACK>;
2825
2826
  channelId: z.ZodString;
@@ -3496,6 +3497,11 @@ export declare const TriggerArraySchema: z.ZodArray<z.ZodUnion<readonly [z.ZodDi
3496
3497
  integrationType: z.ZodEnum<typeof IntegrationType>;
3497
3498
  eventType: z.ZodLiteral<"manual_sample">;
3498
3499
  }, z.core.$strip>]>>;
3500
+ export declare const serializedEventDisplaySchema: z.ZodObject<{
3501
+ title: z.ZodString;
3502
+ subtitle: z.ZodString;
3503
+ }, z.core.$strip>;
3504
+ export type SerializedEventDisplay = z.infer<typeof serializedEventDisplaySchema>;
3499
3505
  export declare const serializedEventSchema: z.ZodObject<{
3500
3506
  integrationType: z.ZodEnum<typeof IntegrationType>;
3501
3507
  eventType: z.ZodUnion<readonly [z.ZodEnum<{
@@ -3529,6 +3535,10 @@ export declare const serializedEventSchema: z.ZodObject<{
3529
3535
  }>, z.ZodLiteral<"webhook">, z.ZodLiteral<"cron">, z.ZodLiteral<"webmonitor">, z.ZodLiteral<"manual_sample">]>;
3530
3536
  formattedContent: z.ZodString;
3531
3537
  debugLog: z.ZodString;
3538
+ display: z.ZodOptional<z.ZodObject<{
3539
+ title: z.ZodString;
3540
+ subtitle: z.ZodString;
3541
+ }, z.core.$strip>>;
3532
3542
  data: z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
3533
3543
  integrationType: z.ZodLiteral<IntegrationType.SLACK>;
3534
3544
  channelId: z.ZodString;