@notionhq/apps 0.0.13 → 0.0.15

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.
Files changed (111) hide show
  1. package/README.md +110 -49
  2. package/dist/box.generated.d.ts +164 -0
  3. package/dist/box.generated.d.ts.map +1 -0
  4. package/dist/box.generated.js +24 -0
  5. package/dist/calendar.generated.d.ts +1036 -0
  6. package/dist/calendar.generated.d.ts.map +1 -0
  7. package/dist/calendar.generated.js +42 -0
  8. package/dist/cli/build.js +7 -6
  9. package/dist/cli/emit-manifest.d.ts.map +1 -1
  10. package/dist/cli/emit-manifest.js +1 -4
  11. package/dist/confluence.generated.d.ts +98 -0
  12. package/dist/confluence.generated.d.ts.map +1 -0
  13. package/dist/confluence.generated.js +18 -0
  14. package/dist/connection-actions.d.ts +2 -0
  15. package/dist/connection-actions.d.ts.map +1 -0
  16. package/dist/connection-actions.js +0 -0
  17. package/dist/connection-trigger-definitions.generated.d.ts +34 -0
  18. package/dist/connection-trigger-definitions.generated.d.ts.map +1 -0
  19. package/dist/connection-trigger-definitions.generated.js +45 -0
  20. package/dist/connections.d.ts +15 -0
  21. package/dist/connections.d.ts.map +1 -0
  22. package/dist/connections.js +79 -0
  23. package/dist/connections.test.d.ts +2 -0
  24. package/dist/connections.test.d.ts.map +1 -0
  25. package/dist/context.d.ts.map +1 -1
  26. package/dist/context.js +3 -0
  27. package/dist/context.test.d.ts +2 -0
  28. package/dist/context.test.d.ts.map +1 -0
  29. package/dist/cursor.generated.d.ts +154 -0
  30. package/dist/cursor.generated.d.ts.map +1 -0
  31. package/dist/cursor.generated.js +18 -0
  32. package/dist/custom-block.d.ts +1 -1
  33. package/dist/custom-block.d.ts.map +1 -1
  34. package/dist/custom-block.js +3 -3
  35. package/dist/discord.generated.d.ts +279 -0
  36. package/dist/discord.generated.d.ts.map +1 -0
  37. package/dist/discord.generated.js +33 -0
  38. package/dist/gmail.generated.d.ts +184 -0
  39. package/dist/gmail.generated.d.ts.map +1 -0
  40. package/dist/gmail.generated.js +21 -0
  41. package/dist/googleCalendar.generated.d.ts +83 -0
  42. package/dist/googleCalendar.generated.d.ts.map +1 -0
  43. package/dist/googleCalendar.generated.js +15 -0
  44. package/dist/googleDrive.generated.d.ts +210 -0
  45. package/dist/googleDrive.generated.d.ts.map +1 -0
  46. package/dist/googleDrive.generated.js +27 -0
  47. package/dist/googleDriveOauth.generated.d.ts +851 -0
  48. package/dist/googleDriveOauth.generated.d.ts.map +1 -0
  49. package/dist/googleDriveOauth.generated.js +84 -0
  50. package/dist/index.d.ts +8 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +16 -0
  53. package/dist/outlook.generated.d.ts +224 -0
  54. package/dist/outlook.generated.d.ts.map +1 -0
  55. package/dist/outlook.generated.js +24 -0
  56. package/dist/providers.generated.d.ts +117 -0
  57. package/dist/providers.generated.d.ts.map +1 -0
  58. package/dist/providers.generated.js +108 -0
  59. package/dist/salesforce.generated.d.ts +151 -0
  60. package/dist/salesforce.generated.d.ts.map +1 -0
  61. package/dist/salesforce.generated.js +24 -0
  62. package/dist/slack.generated.d.ts +290 -0
  63. package/dist/slack.generated.d.ts.map +1 -0
  64. package/dist/slack.generated.js +30 -0
  65. package/dist/sync.d.ts +2 -2
  66. package/dist/sync.d.ts.map +1 -1
  67. package/dist/sync.js +3 -3
  68. package/dist/triggers.generated.d.ts +107 -32
  69. package/dist/triggers.generated.d.ts.map +1 -1
  70. package/dist/triggers.generated.js +36 -24
  71. package/dist/workflow-connections-types.test.d.ts +2 -0
  72. package/dist/workflow-connections-types.test.d.ts.map +1 -0
  73. package/dist/workflow-types.test.d.ts +2 -0
  74. package/dist/workflow-types.test.d.ts.map +1 -0
  75. package/dist/workflow.d.ts +24 -20
  76. package/dist/workflow.d.ts.map +1 -1
  77. package/dist/workflow.js +16 -19
  78. package/docs/BUILD.md +83 -14
  79. package/docs/CONNECTIONS.md +130 -0
  80. package/package.json +5 -1
  81. package/src/box.generated.ts +187 -0
  82. package/src/calendar.generated.ts +1117 -0
  83. package/src/cli/build.test.ts +35 -4
  84. package/src/cli/build.ts +6 -5
  85. package/src/cli/emit-manifest.ts +1 -5
  86. package/src/confluence.generated.ts +109 -0
  87. package/src/connection-actions.ts +2 -0
  88. package/src/connection-trigger-definitions.generated.ts +48 -0
  89. package/src/connections.test.ts +157 -0
  90. package/src/connections.ts +126 -0
  91. package/src/context.test.ts +26 -0
  92. package/src/context.ts +8 -0
  93. package/src/cursor.generated.ts +167 -0
  94. package/src/custom-block.test.ts +4 -4
  95. package/src/custom-block.ts +2 -2
  96. package/src/discord.generated.ts +318 -0
  97. package/src/gmail.generated.ts +205 -0
  98. package/src/googleCalendar.generated.ts +95 -0
  99. package/src/googleDrive.generated.ts +235 -0
  100. package/src/googleDriveOauth.generated.ts +980 -0
  101. package/src/index.ts +7 -0
  102. package/src/outlook.generated.ts +249 -0
  103. package/src/providers.generated.ts +207 -0
  104. package/src/salesforce.generated.ts +170 -0
  105. package/src/slack.generated.ts +330 -0
  106. package/src/sync.ts +2 -2
  107. package/src/triggers.generated.ts +112 -32
  108. package/src/workflow-connections-types.test.ts +59 -0
  109. package/src/workflow-types.test.ts +144 -0
  110. package/src/workflow.test.ts +135 -25
  111. package/src/workflow.ts +63 -34
@@ -0,0 +1,330 @@
1
+ // Generated by notion tool-core codegen-script-types --connections. Do not edit.
2
+ import type { ConnectionActionInvoker } from "./connection-actions.js"
3
+ /**
4
+ * Script input for the "Find a Slack user by email" effect (`slack.findUserByEmail`),
5
+ * derived from its Tool Core definition's call_function input projection.
6
+ *
7
+ * Find a Slack user by email
8
+ */
9
+ export type FindUserByEmailScriptInput = {
10
+ email: string
11
+ }
12
+
13
+ /**
14
+ * Script result of the "Find a Slack user by email" effect (`slack.findUserByEmail`):
15
+ * the canonical Tool Core output schema with the effect's declared
16
+ * script-output projection applied, exactly as the runtime encoder
17
+ * returns it.
18
+ */
19
+ export type FindUserByEmailScriptOutput =
20
+ | {
21
+ handle: string
22
+ id: string
23
+ uri: string
24
+ displayName?: string
25
+ email?: string
26
+ notionUser?: string
27
+ realName?: string
28
+ statusEmoji?: string
29
+ statusText?: string
30
+ timeZone?: string
31
+ title?: string
32
+ }
33
+ | undefined
34
+
35
+ /**
36
+ * Script input for the "Get Slack channel threads" effect (`slack.getThreadsInChannelSince`),
37
+ * derived from its Tool Core definition's call_function input projection.
38
+ *
39
+ * Get all threads in a channel since a given timestamp
40
+ */
41
+ export type GetThreadsInChannelSinceScriptInput = {
42
+ /**
43
+ * The name of the channel without the # symbol. For example, "engineering".
44
+ */
45
+ channelName: string
46
+ /**
47
+ * ISO 8601 timestamp, for example 2026-01-01T00:00:00Z.
48
+ */
49
+ timestamp: string
50
+ }
51
+
52
+ /**
53
+ * Canonical Tool Core output for the "Get Slack channel threads" effect (`slack.getThreadsInChannelSince`).
54
+ * This is the definition's output schema; the effect's script surface may
55
+ * re-encode it before returning.
56
+ */
57
+ export type GetThreadsInChannelSinceScriptOutput = Array<
58
+ Array<{
59
+ channelId: string
60
+ channelUri: string
61
+ from:
62
+ | {
63
+ handle: string
64
+ id: string
65
+ type: "user"
66
+ uri: string
67
+ }
68
+ | {
69
+ type: "bot"
70
+ }
71
+ id: string
72
+ message: string
73
+ threadId: string
74
+ timestamp: string
75
+ uri: string
76
+ url: string
77
+ urls: Array<string>
78
+ channel?: string
79
+ fileIds?: Array<string>
80
+ files?: Array<string>
81
+ }>
82
+ >
83
+
84
+ /**
85
+ * Script input for the "Load Slack message" effect (`slack.loadMessage`),
86
+ * derived from its Tool Core definition's call_function input projection.
87
+ *
88
+ * Load a Slack message by ID.
89
+ */
90
+ export type LoadMessageScriptInput =
91
+ | {
92
+ /**
93
+ * Slack channel ID for the message.
94
+ */
95
+ channelId: string
96
+ /**
97
+ * Slack message timestamp (ts).
98
+ */
99
+ messageTs: string
100
+ /**
101
+ * Slack thread timestamp (ts) if threaded.
102
+ */
103
+ threadTs?: string
104
+ /**
105
+ * Slack workspace host parsed from the user's URL
106
+ */
107
+ workspaceHost?: string
108
+ }
109
+ | {
110
+ /**
111
+ * A Slack message identifier. Accepts a slackMessage:// URI as returned by other Slack tools (e.g. slackMessage://workspace.slack.com/C0123ABCDEF/12345/9876543210.987654), a https Slack archive URL, or a connector href from search results (slack://?base_url=...&channel_id=...&message_id=...).
112
+ */
113
+ url: string
114
+ }
115
+
116
+ /**
117
+ * Canonical Tool Core output for the "Load Slack message" effect (`slack.loadMessage`).
118
+ * This is the definition's output schema; the effect's script surface may
119
+ * re-encode it before returning.
120
+ */
121
+ export type LoadMessageScriptOutput = {
122
+ type: "slack"
123
+ channel: string
124
+ messages: Array<{
125
+ user: {
126
+ name: string
127
+ notionUserName?: string
128
+ notionUserId?: string
129
+ }
130
+ text: string
131
+ date?: string
132
+ ts?: string
133
+ attachments?: Array<string>
134
+ files?: Array<string>
135
+ }>
136
+ timestamp: number
137
+ additionalMessageToModel?: string
138
+ }
139
+
140
+ /**
141
+ * Script input for the "Query Slack channels" effect (`slack.queryChannels`),
142
+ * derived from its Tool Core definition's call_function input projection.
143
+ *
144
+ * Query Slack channels by criteria
145
+ */
146
+ export type QueryChannelsScriptInput = {
147
+ id?: string
148
+ name?: string
149
+ /**
150
+ * Filter channels created after this date. ISO format with timezone (e.g. 2024-01-01T00:00:00-05:00 for Eastern Time)
151
+ */
152
+ createdStart?: string
153
+ /**
154
+ * Filter channels created before this date. ISO format with timezone (e.g. 2024-01-01T00:00:00-05:00 for Eastern Time)
155
+ */
156
+ createdEnd?: string
157
+ isGeneral?: boolean
158
+ isIm?: boolean
159
+ isPrivate?: boolean
160
+ isMpim?: boolean
161
+ isShared?: boolean
162
+ isOrgShared?: boolean
163
+ botIsMember?: boolean
164
+ isArchived?: boolean
165
+ }
166
+
167
+ /**
168
+ * Canonical Tool Core output for the "Query Slack channels" effect (`slack.queryChannels`).
169
+ * This is the definition's output schema; the effect's script surface may
170
+ * re-encode it before returning.
171
+ */
172
+ export type QueryChannelsScriptOutput = Array<{
173
+ /**
174
+ * The Slack channel ID.
175
+ */
176
+ id: string
177
+ /**
178
+ * The prefixed channel URI.
179
+ */
180
+ uri: string
181
+ /**
182
+ * The user-navigable channel URL. Include this link when telling the user the channel was created.
183
+ */
184
+ url: string
185
+ /**
186
+ * The channel name, without a "#" prefix.
187
+ */
188
+ name: string
189
+ /**
190
+ * ISO 8601 timestamp of when the channel was created.
191
+ */
192
+ created: string
193
+ /**
194
+ * Whether this is the workspace's general channel.
195
+ */
196
+ isGeneral: boolean
197
+ /**
198
+ * Whether this is a direct message channel.
199
+ */
200
+ isIm: boolean
201
+ /**
202
+ * Whether the channel is private.
203
+ */
204
+ isPrivate: boolean
205
+ /**
206
+ * Whether this is a group direct message channel.
207
+ */
208
+ isMpim: boolean
209
+ /**
210
+ * Whether the channel is shared between Slack workspaces.
211
+ */
212
+ isShared: boolean
213
+ /**
214
+ * Whether the channel is shared across an Enterprise Grid organization.
215
+ */
216
+ isOrgShared: boolean
217
+ /**
218
+ * Whether the integration bot user is in the channel.
219
+ */
220
+ botIsMember: boolean
221
+ /**
222
+ * Whether the channel is archived.
223
+ */
224
+ isArchived: boolean
225
+ }>
226
+
227
+ /**
228
+ * Script input for the "Search Slack messages" effect (`slack.search`),
229
+ * derived from its Tool Core definition's call_function input projection.
230
+ *
231
+ * Search Slack via the configured connector.
232
+ */
233
+ export type SearchScriptInput = {
234
+ /**
235
+ * A single, focused question to search for.
236
+ */
237
+ question: string
238
+ /**
239
+ * Brief keywords capturing the core entities.
240
+ */
241
+ keywords?: string
242
+ /**
243
+ * Optional time window. Use only "default", "all_time", a duration matching /^\d+[dwmy]$/ (for example, "7d", "2w", "3m", or "1y"), or a date in "YYYY-MM-DD" format. Do not use natural-language durations or combine units.
244
+ */
245
+ lookback?: string
246
+ options?: {
247
+ /**
248
+ * Preferred Slack channel name. This boosts results from that channel but does not filter the search. Results from other conversations may be returned. Check each result's conversation before using it.
249
+ */
250
+ channel?: string
251
+ }
252
+ }
253
+
254
+ /**
255
+ * Canonical Tool Core output for the "Search Slack messages" effect (`slack.search`).
256
+ * This is the definition's output schema; the effect's script surface may
257
+ * re-encode it before returning.
258
+ */
259
+ export type SearchScriptOutput = {
260
+ results: Array<{
261
+ conversation: {
262
+ id: string
263
+ kind: "channel" | "dm" | "groupDm"
264
+ name: string
265
+ }
266
+ messageUrl: string
267
+ lastEdited: string
268
+ messages: Array<{
269
+ messageUrl: string
270
+ lastEdited: string
271
+ text: string
272
+ user: string
273
+ }>
274
+ }>
275
+ }
276
+
277
+ /**
278
+ * Script input for the "View Slack file URL" effect (`slack.viewFileUrl`),
279
+ * derived from its Tool Core definition's call_function input projection.
280
+ *
281
+ * Return a Slack file URL for script-agent viewing.
282
+ */
283
+ export type ViewFileUrlScriptInput = {
284
+ /**
285
+ * Slack private file URL or workspace file permalink to download and attach for viewing.
286
+ */
287
+ url: string
288
+ }
289
+
290
+ /**
291
+ * Canonical Tool Core output for the "View Slack file URL" effect (`slack.viewFileUrl`).
292
+ * This is the definition's output schema; the effect's script surface may
293
+ * re-encode it before returning.
294
+ */
295
+ export type ViewFileUrlScriptOutput = {
296
+ url: string
297
+ fileName?: string
298
+ fileUrl?: string
299
+ }
300
+
301
+ export class SlackConnectionClient {
302
+ constructor(private readonly invoke: ConnectionActionInvoker) {}
303
+ findUserByEmail(
304
+ args: FindUserByEmailScriptInput,
305
+ ): Promise<FindUserByEmailScriptOutput> {
306
+ return this.invoke<FindUserByEmailScriptOutput>("findUserByEmail", args)
307
+ }
308
+ getThreadsInChannelSince(
309
+ args: GetThreadsInChannelSinceScriptInput,
310
+ ): Promise<GetThreadsInChannelSinceScriptOutput> {
311
+ return this.invoke<GetThreadsInChannelSinceScriptOutput>(
312
+ "getThreadsInChannelSince",
313
+ args,
314
+ )
315
+ }
316
+ loadMessage(args: LoadMessageScriptInput): Promise<LoadMessageScriptOutput> {
317
+ return this.invoke<LoadMessageScriptOutput>("loadMessage", args)
318
+ }
319
+ queryChannels(
320
+ args: QueryChannelsScriptInput,
321
+ ): Promise<QueryChannelsScriptOutput> {
322
+ return this.invoke<QueryChannelsScriptOutput>("queryChannels", args)
323
+ }
324
+ search(args: SearchScriptInput): Promise<SearchScriptOutput> {
325
+ return this.invoke<SearchScriptOutput>("search", args)
326
+ }
327
+ viewFileUrl(args: ViewFileUrlScriptInput): Promise<ViewFileUrlScriptOutput> {
328
+ return this.invoke<ViewFileUrlScriptOutput>("viewFileUrl", args)
329
+ }
330
+ }
package/src/sync.ts CHANGED
@@ -89,7 +89,7 @@ export type SyncConfiguration<
89
89
  };
90
90
 
91
91
  /** Configuration for a sync backed by a Notion-as-Code data source. */
92
- type DataSourceSyncConfiguration<
92
+ export type DataSourceSyncConfiguration<
93
93
  Properties extends readonly NotionAsCodeProperty[],
94
94
  PrimaryKey extends KeyPropertyName<AppsSchemaForProperties<Properties>>,
95
95
  State,
@@ -165,7 +165,7 @@ export function createSync<
165
165
  }
166
166
 
167
167
  /** Create a sync backed by a Notion-as-Code data source. */
168
- export function createDataSourceSync<
168
+ export function sync<
169
169
  const Properties extends readonly NotionAsCodeProperty[],
170
170
  const PrimaryKey extends KeyPropertyName<AppsSchemaForProperties<Properties>>,
171
171
  State = unknown,
@@ -1,6 +1,8 @@
1
1
  // Generated by scripts/generate-triggers.ts — do not edit by hand.
2
2
  // Regenerate with: pnpm run generate
3
3
 
4
+ import type { WorkflowConnection, WorkflowConnectionKeys } from "./connections.js";
5
+
4
6
  import type {
5
7
  CalendarEventCanceledEvent,
6
8
  CalendarEventCreatedEvent,
@@ -72,24 +74,32 @@ export type {
72
74
  WebhookEvent,
73
75
  } from "./triggers.js";
74
76
 
75
- /** A message was posted in a subscribed Slack channel. */
76
- export type SlackMessageTrigger = {
77
+ /** Triggers immediately after a new message is posted in Slack (includes new threads and replies) */
78
+ export type SlackMessageTrigger<TKey extends string = string> = {
77
79
  type: "slack.message";
80
+ /** Key of the declared slack connection. */
81
+ connectionKey?: TKey;
78
82
  };
79
83
 
80
- /** A reaction was added to a Slack message. */
81
- export type SlackReactionAddedTrigger = {
84
+ /** Triggers immediately after a reaction is added to a message in Slack */
85
+ export type SlackReactionAddedTrigger<TKey extends string = string> = {
82
86
  type: "slack.reaction.added";
87
+ /** Key of the declared slack connection. */
88
+ connectionKey?: TKey;
83
89
  };
84
90
 
85
- /** The Notion app was mentioned in a Slack message. */
86
- export type SlackAppMentionTrigger = {
91
+ /** Triggers when the agent is mentioned in a Slack channel or direct message */
92
+ export type SlackAppMentionTrigger<TKey extends string = string> = {
87
93
  type: "slack.app.mention";
94
+ /** Key of the declared slack connection. */
95
+ connectionKey?: TKey;
88
96
  };
89
97
 
90
- /** A Discord interaction was received. */
91
- export type DiscordInteractionTrigger = {
98
+ /** Triggers when a user invokes the /ai slash command in a configured Discord channel */
99
+ export type DiscordInteractionTrigger<TKey extends string = string> = {
92
100
  type: "discord.interaction";
101
+ /** Key of the declared discord connection. */
102
+ connectionKey?: TKey;
93
103
  };
94
104
 
95
105
  /** An email was received. */
@@ -107,19 +117,25 @@ export type MailLabelAppliedTrigger = {
107
117
  type: "mail.label.applied";
108
118
  };
109
119
 
110
- /** A calendar event was created. */
111
- export type CalendarEventCreatedTrigger = {
120
+ /** Triggers immediately when a calendar event is created */
121
+ export type CalendarEventCreatedTrigger<TKey extends string = string> = {
112
122
  type: "calendar.event.created";
123
+ /** Key of the declared calendar connection. */
124
+ connectionKey?: TKey;
113
125
  };
114
126
 
115
- /** A calendar event was updated. */
116
- export type CalendarEventUpdatedTrigger = {
127
+ /** Triggers immediately when a calendar event is updated */
128
+ export type CalendarEventUpdatedTrigger<TKey extends string = string> = {
117
129
  type: "calendar.event.updated";
130
+ /** Key of the declared calendar connection. */
131
+ connectionKey?: TKey;
118
132
  };
119
133
 
120
- /** A calendar event was canceled. */
121
- export type CalendarEventCanceledTrigger = {
134
+ /** Triggers immediately when a calendar event is canceled */
135
+ export type CalendarEventCanceledTrigger<TKey extends string = string> = {
122
136
  type: "calendar.event.canceled";
137
+ /** Key of the declared calendar connection. */
138
+ connectionKey?: TKey;
123
139
  };
124
140
 
125
141
  /** A page has been added to a database. */
@@ -167,9 +183,11 @@ export type WebhookTrigger = {
167
183
  type: "webhooks.webhook";
168
184
  };
169
185
 
170
- /** Files changed in a watched Google Drive folder or drive. */
171
- export type GoogleDriveOauthFilesChangedTrigger = {
186
+ /** Watches for file changes in a specific Google Drive folder (direct children only) or shared drive. The My Drive root is not supported. Fires on a schedule and provides change tokens for fetching the list of changes. */
187
+ export type GoogleDriveOauthFilesChangedTrigger<TKey extends string = string> = {
172
188
  type: "googleDriveOauth.filesChanged";
189
+ /** Key of the declared googleDriveOauth connection. */
190
+ connectionKey?: TKey;
173
191
  };
174
192
 
175
193
  /** A recurring schedule fired. */
@@ -182,44 +200,48 @@ export const triggers = {
182
200
  /**
183
201
  * Declare that a workflow can run on `slack.message` events.
184
202
  *
185
- * A message was posted in a subscribed Slack channel.
203
+ * Triggers immediately after a new message is posted in Slack (includes new threads and replies)
186
204
  */
187
- slackMessage(): SlackMessageTrigger {
205
+ slackMessage<const TKey extends string = never>(options: { connectionKey: TKey } | undefined = undefined): SlackMessageTrigger<TKey> {
188
206
  return {
189
207
  type: "slack.message",
208
+ ...(options === undefined ? {} : { connectionKey: options.connectionKey }),
190
209
  };
191
210
  },
192
211
 
193
212
  /**
194
213
  * Declare that a workflow can run on `slack.reaction.added` events.
195
214
  *
196
- * A reaction was added to a Slack message.
215
+ * Triggers immediately after a reaction is added to a message in Slack
197
216
  */
198
- slackReactionAdded(): SlackReactionAddedTrigger {
217
+ slackReactionAdded<const TKey extends string = never>(options: { connectionKey: TKey } | undefined = undefined): SlackReactionAddedTrigger<TKey> {
199
218
  return {
200
219
  type: "slack.reaction.added",
220
+ ...(options === undefined ? {} : { connectionKey: options.connectionKey }),
201
221
  };
202
222
  },
203
223
 
204
224
  /**
205
225
  * Declare that a workflow can run on `slack.app.mention` events.
206
226
  *
207
- * The Notion app was mentioned in a Slack message.
227
+ * Triggers when the agent is mentioned in a Slack channel or direct message
208
228
  */
209
- slackAppMention(): SlackAppMentionTrigger {
229
+ slackAppMention<const TKey extends string = never>(options: { connectionKey: TKey } | undefined = undefined): SlackAppMentionTrigger<TKey> {
210
230
  return {
211
231
  type: "slack.app.mention",
232
+ ...(options === undefined ? {} : { connectionKey: options.connectionKey }),
212
233
  };
213
234
  },
214
235
 
215
236
  /**
216
237
  * Declare that a workflow can run on `discord.interaction` events.
217
238
  *
218
- * A Discord interaction was received.
239
+ * Triggers when a user invokes the /ai slash command in a configured Discord channel
219
240
  */
220
- discordInteraction(): DiscordInteractionTrigger {
241
+ discordInteraction<const TKey extends string = never>(options: { connectionKey: TKey } | undefined = undefined): DiscordInteractionTrigger<TKey> {
221
242
  return {
222
243
  type: "discord.interaction",
244
+ ...(options === undefined ? {} : { connectionKey: options.connectionKey }),
223
245
  };
224
246
  },
225
247
 
@@ -259,33 +281,36 @@ export const triggers = {
259
281
  /**
260
282
  * Declare that a workflow can run on `calendar.event.created` events.
261
283
  *
262
- * A calendar event was created.
284
+ * Triggers immediately when a calendar event is created
263
285
  */
264
- calendarEventCreated(): CalendarEventCreatedTrigger {
286
+ calendarEventCreated<const TKey extends string = never>(options: { connectionKey: TKey } | undefined = undefined): CalendarEventCreatedTrigger<TKey> {
265
287
  return {
266
288
  type: "calendar.event.created",
289
+ ...(options === undefined ? {} : { connectionKey: options.connectionKey }),
267
290
  };
268
291
  },
269
292
 
270
293
  /**
271
294
  * Declare that a workflow can run on `calendar.event.updated` events.
272
295
  *
273
- * A calendar event was updated.
296
+ * Triggers immediately when a calendar event is updated
274
297
  */
275
- calendarEventUpdated(): CalendarEventUpdatedTrigger {
298
+ calendarEventUpdated<const TKey extends string = never>(options: { connectionKey: TKey } | undefined = undefined): CalendarEventUpdatedTrigger<TKey> {
276
299
  return {
277
300
  type: "calendar.event.updated",
301
+ ...(options === undefined ? {} : { connectionKey: options.connectionKey }),
278
302
  };
279
303
  },
280
304
 
281
305
  /**
282
306
  * Declare that a workflow can run on `calendar.event.canceled` events.
283
307
  *
284
- * A calendar event was canceled.
308
+ * Triggers immediately when a calendar event is canceled
285
309
  */
286
- calendarEventCanceled(): CalendarEventCanceledTrigger {
310
+ calendarEventCanceled<const TKey extends string = never>(options: { connectionKey: TKey } | undefined = undefined): CalendarEventCanceledTrigger<TKey> {
287
311
  return {
288
312
  type: "calendar.event.canceled",
313
+ ...(options === undefined ? {} : { connectionKey: options.connectionKey }),
289
314
  };
290
315
  },
291
316
 
@@ -391,11 +416,12 @@ export const triggers = {
391
416
  /**
392
417
  * Declare that a workflow can run on `googleDriveOauth.filesChanged` events.
393
418
  *
394
- * Files changed in a watched Google Drive folder or drive.
419
+ * Watches for file changes in a specific Google Drive folder (direct children only) or shared drive. The My Drive root is not supported. Fires on a schedule and provides change tokens for fetching the list of changes.
395
420
  */
396
- googleDriveOauthFilesChanged(): GoogleDriveOauthFilesChangedTrigger {
421
+ googleDriveOauthFilesChanged<const TKey extends string = never>(options: { connectionKey: TKey } | undefined = undefined): GoogleDriveOauthFilesChangedTrigger<TKey> {
397
422
  return {
398
423
  type: "googleDriveOauth.filesChanged",
424
+ ...(options === undefined ? {} : { connectionKey: options.connectionKey }),
399
425
  };
400
426
  },
401
427
 
@@ -411,6 +437,60 @@ export const triggers = {
411
437
  },
412
438
  } as const;
413
439
 
440
+ /** Trigger creators restricted to the workflow's declared provider keys. */
441
+ export type WorkflowTriggerCreators<TConnections extends readonly WorkflowConnection[]> = {
442
+ slackMessage(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "slack"> }): SlackMessageTrigger<WorkflowConnectionKeys<TConnections, "slack">>;
443
+ slackReactionAdded(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "slack"> }): SlackReactionAddedTrigger<WorkflowConnectionKeys<TConnections, "slack">>;
444
+ slackAppMention(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "slack"> }): SlackAppMentionTrigger<WorkflowConnectionKeys<TConnections, "slack">>;
445
+ discordInteraction(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "discord"> }): DiscordInteractionTrigger<WorkflowConnectionKeys<TConnections, "discord">>;
446
+ mailEmailReceived(): MailEmailReceivedTrigger;
447
+ mailEmailSent(): MailEmailSentTrigger;
448
+ mailLabelApplied(): MailLabelAppliedTrigger;
449
+ calendarEventCreated(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "calendar"> }): CalendarEventCreatedTrigger<WorkflowConnectionKeys<TConnections, "calendar">>;
450
+ calendarEventUpdated(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "calendar"> }): CalendarEventUpdatedTrigger<WorkflowConnectionKeys<TConnections, "calendar">>;
451
+ calendarEventCanceled(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "calendar"> }): CalendarEventCanceledTrigger<WorkflowConnectionKeys<TConnections, "calendar">>;
452
+ notionPageCreated(): NotionPageCreatedTrigger;
453
+ notionPageUpdated(): NotionPageUpdatedTrigger;
454
+ notionPageDeleted(): NotionPageDeletedTrigger;
455
+ notionMeetingNoteSummaryCompleted(): NotionMeetingNoteSummaryCompletedTrigger;
456
+ notionCommentAdded(): NotionCommentAddedTrigger;
457
+ notionAgentMentioned(): NotionAgentMentionedTrigger;
458
+ notionButtonPressed(): NotionButtonPressedTrigger;
459
+ notionDatabaseAgentUpdated(): NotionDatabaseAgentUpdatedTrigger;
460
+ webhook(): WebhookTrigger;
461
+ googleDriveOauthFilesChanged(options?: { connectionKey: WorkflowConnectionKeys<TConnections, "googleDriveOauth"> }): GoogleDriveOauthFilesChangedTrigger<WorkflowConnectionKeys<TConnections, "googleDriveOauth">>;
462
+ scheduled(): RecurrenceTrigger;
463
+ };
464
+
465
+ /** Triggers whose connection keys belong to the declared provider. */
466
+ export type WorkflowTriggerForConnections<TConnections extends readonly WorkflowConnection[]> =
467
+ | SlackMessageTrigger<WorkflowConnectionKeys<TConnections, "slack">>
468
+ | SlackReactionAddedTrigger<WorkflowConnectionKeys<TConnections, "slack">>
469
+ | SlackAppMentionTrigger<WorkflowConnectionKeys<TConnections, "slack">>
470
+ | DiscordInteractionTrigger<WorkflowConnectionKeys<TConnections, "discord">>
471
+ | MailEmailReceivedTrigger
472
+ | MailEmailSentTrigger
473
+ | MailLabelAppliedTrigger
474
+ | CalendarEventCreatedTrigger<WorkflowConnectionKeys<TConnections, "calendar">>
475
+ | CalendarEventUpdatedTrigger<WorkflowConnectionKeys<TConnections, "calendar">>
476
+ | CalendarEventCanceledTrigger<WorkflowConnectionKeys<TConnections, "calendar">>
477
+ | NotionPageCreatedTrigger
478
+ | NotionPageUpdatedTrigger
479
+ | NotionPageDeletedTrigger
480
+ | NotionMeetingNoteSummaryCompletedTrigger
481
+ | NotionCommentAddedTrigger
482
+ | NotionAgentMentionedTrigger
483
+ | NotionButtonPressedTrigger
484
+ | NotionDatabaseAgentUpdatedTrigger
485
+ | WebhookTrigger
486
+ | GoogleDriveOauthFilesChangedTrigger<WorkflowConnectionKeys<TConnections, "googleDriveOauth">>
487
+ | RecurrenceTrigger;
488
+
489
+ /** @internal */
490
+ export function createWorkflowTriggers<TConnections extends readonly WorkflowConnection[]>(): WorkflowTriggerCreators<TConnections> {
491
+ return triggers;
492
+ }
493
+
414
494
  /** Event that can trigger a workflow. */
415
495
  export type WorkflowTrigger =
416
496
  | SlackMessageTrigger
@@ -0,0 +1,59 @@
1
+ import { expectTypeOf, it } from "vitest";
2
+ import { triggers } from "./triggers.generated.js";
3
+ import { connections, workflow, type WorkflowConnection } from "./workflow.js";
4
+
5
+ it("infers only the declared provider clients", () => {
6
+ workflow({
7
+ name: "Calendar",
8
+ description: "Calendar only",
9
+ triggers: [triggers.notionPageCreated()],
10
+ connections: [connections.calendar({ key: "work" })],
11
+ handler(_event, context) {
12
+ expectTypeOf<keyof typeof context.connections>().toEqualTypeOf<"calendar">();
13
+ expectTypeOf(context.connections.calendar).toBeFunction();
14
+ },
15
+ });
16
+ const requirements = [connections.calendar(), connections.slack({ key: "support" })];
17
+ workflow({
18
+ name: "Multiple providers",
19
+ description: "Preserves providers in a separately declared array",
20
+ triggers: [triggers.notionPageCreated()],
21
+ connections: requirements,
22
+ handler(_event, context) {
23
+ expectTypeOf<keyof typeof context.connections>().toEqualTypeOf<"calendar" | "slack">();
24
+ },
25
+ });
26
+ });
27
+
28
+ it("exposes no providers for omitted or empty connections", () => {
29
+ workflow({
30
+ name: "No connections",
31
+ description: "Omitted",
32
+ triggers: [triggers.notionPageCreated()],
33
+ handler(_event, context) {
34
+ expectTypeOf<keyof typeof context.connections>().toEqualTypeOf<never>();
35
+ },
36
+ });
37
+ workflow({
38
+ name: "No connections",
39
+ description: "Empty",
40
+ triggers: [triggers.notionPageCreated()],
41
+ connections: [],
42
+ handler(_event, context) {
43
+ expectTypeOf<keyof typeof context.connections>().toEqualTypeOf<never>();
44
+ },
45
+ });
46
+ });
47
+
48
+ it("preserves literal declarations checked with satisfies", () => {
49
+ const requirements = [connections.slack()] satisfies readonly WorkflowConnection[];
50
+ workflow({
51
+ name: "Slack",
52
+ description: "Slack only",
53
+ triggers: [triggers.notionPageCreated()],
54
+ connections: requirements,
55
+ handler(_event, context) {
56
+ expectTypeOf<keyof typeof context.connections>().toEqualTypeOf<"slack">();
57
+ },
58
+ });
59
+ });