@slates/provider 1.0.0-rc.21 → 1.0.0-rc.23

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.
@@ -9,17 +9,13 @@ import type {
9
9
  SlateActionParametersTrigger,
10
10
  SlateActionScopes,
11
11
  SlateActionType,
12
- SlatePollingOptions,
13
12
  SlatePublicToolInvocationHandler,
14
13
  SlateToolInvocationHandler,
15
14
  SlateTriggerMappingHandler,
16
- SlateTriggerPollingHandler,
17
- SlateTriggerWebhookAutoRegistrationHandler,
18
- SlateTriggerWebhookAutoUnregistrationHandler,
19
- SlateTriggerWebhookRequestHandler,
20
- SlateWebhookHttpOptions
15
+ SlateTriggerMatchesHandler
21
16
  } from './action';
22
17
  import { validateScopes } from './scopes';
18
+ import type { SlateTriggerGroup } from './triggerGroup';
23
19
 
24
20
  export class SlateActionBuilder<
25
21
  Type extends SlateActionType,
@@ -39,12 +35,10 @@ export class SlateActionBuilder<
39
35
 
40
36
  #toolParams: SlateActionParametersTool<ConfigType, AuthType, InputType, OutputType> | null =
41
37
  null;
42
- #triggerParams: SlateActionParametersTrigger<
43
- ConfigType,
44
- AuthType,
45
- InputType,
46
- OutputType
47
- > | null = null;
38
+ #triggerGroup: SlateTriggerGroup<ConfigType, AuthType> | null = null;
39
+ #triggerMatches: SlateTriggerMatchesHandler | null = null;
40
+ #triggerMap: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType> | null =
41
+ null;
48
42
  #interfaceLocked = false;
49
43
 
50
44
  constructor(
@@ -163,47 +157,36 @@ export class SlateActionBuilder<
163
157
  return this;
164
158
  }
165
159
 
166
- webhook(props: {
167
- handleEvent: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
168
- handleRequest: SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType>;
169
- autoRegisterWebhook?: SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType>;
170
- autoUnregisterWebhook?: SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType>;
171
- http?: SlateWebhookHttpOptions;
172
- }): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result, IsPublic> {
160
+ triggerGroup(
161
+ group: SlateTriggerGroup<ConfigType, AuthType>
162
+ ): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result, IsPublic> {
173
163
  if (this.type !== 'trigger') {
174
- throw new SlateDeclarationError('handleEvent can only be set for trigger actions');
164
+ throw new SlateDeclarationError('triggerGroup can only be set for trigger actions');
175
165
  }
176
166
 
177
- this.#triggerParams = {
178
- type: 'trigger',
179
- source: 'webhook',
180
- handleEvent: props.handleEvent,
181
- handleRequest: props.handleRequest,
182
- autoRegisterWebhook: props.autoRegisterWebhook,
183
- autoUnregisterWebhook: props.autoUnregisterWebhook,
184
- http: props.http
185
- };
186
-
167
+ this.#triggerGroup = group;
187
168
  return this;
188
169
  }
189
170
 
190
- polling(props: {
191
- options?: SlatePollingOptions;
192
- pollEvents?: SlateTriggerPollingHandler<ConfigType, AuthType, InputType>;
193
- handleEvent: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
194
- }): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result, IsPublic> {
171
+ matches(
172
+ handler: SlateTriggerMatchesHandler
173
+ ): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result, IsPublic> {
195
174
  if (this.type !== 'trigger') {
196
- throw new SlateDeclarationError('handleEvent can only be set for trigger actions');
175
+ throw new SlateDeclarationError('matches can only be set for trigger actions');
197
176
  }
198
177
 
199
- this.#triggerParams = {
200
- type: 'trigger',
201
- source: 'polling',
202
- polling: props.options,
203
- pollEvents: props.pollEvents,
204
- handleEvent: props.handleEvent
205
- };
178
+ this.#triggerMatches = handler;
179
+ return this;
180
+ }
206
181
 
182
+ map(
183
+ handler: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>
184
+ ): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result, IsPublic> {
185
+ if (this.type !== 'trigger') {
186
+ throw new SlateDeclarationError('map can only be set for trigger actions');
187
+ }
188
+
189
+ this.#triggerMap = handler;
207
190
  return this;
208
191
  }
209
192
 
@@ -227,9 +210,30 @@ export class SlateActionBuilder<
227
210
  if (this.type === 'tool' && !this.#toolParams) {
228
211
  throw new SlateDeclarationError('Tool invocation handler is not defined');
229
212
  }
230
- if (this.type === 'trigger' && !this.#triggerParams) {
231
- throw new SlateDeclarationError('Trigger event handlers are not defined');
213
+ if (this.type === 'trigger' && !this.#triggerGroup) {
214
+ throw new SlateDeclarationError('Trigger group is not defined');
215
+ }
216
+ if (this.type === 'trigger' && !this.#triggerMatches) {
217
+ throw new SlateDeclarationError('Trigger matches handler is not defined');
232
218
  }
219
+ if (this.type === 'trigger' && !this.#triggerMap) {
220
+ throw new SlateDeclarationError('Trigger map handler is not defined');
221
+ }
222
+
223
+ let triggerParams: SlateActionParametersTrigger<
224
+ ConfigType,
225
+ AuthType,
226
+ InputType,
227
+ OutputType & { type: string }
228
+ > | null =
229
+ this.type === 'trigger'
230
+ ? {
231
+ type: 'trigger',
232
+ triggerGroup: this.#triggerGroup!,
233
+ matches: this.#triggerMatches!,
234
+ map: this.#triggerMap! as any
235
+ }
236
+ : null;
233
237
 
234
238
  return this.factory({
235
239
  ...this.params,
@@ -242,7 +246,7 @@ export class SlateActionBuilder<
242
246
  outputSchema: this.#outputSchema,
243
247
 
244
248
  ...this.#toolParams!,
245
- ...this.#triggerParams!
249
+ ...(triggerParams as any)!
246
250
  }) as Result;
247
251
  }
248
252
  }
@@ -50,7 +50,9 @@ describe('uploadAttachmentDirect', () => {
50
50
  'content-length': '5'
51
51
  }
52
52
  });
53
- expect(upload[1]!.body).toEqual(new Uint8Array([1, 2, 3, 4, 5]));
53
+ expect(new Uint8Array(upload[1]!.body as ArrayBuffer)).toEqual(
54
+ new Uint8Array([1, 2, 3, 4, 5])
55
+ );
54
56
  expect(upload[1]).not.toHaveProperty('duplex');
55
57
  });
56
58
 
@@ -16,12 +16,15 @@ export interface SlateDirectUploadInput {
16
16
  let bufferAttachmentBody = async (
17
17
  body: SlateDirectUploadInput['body'],
18
18
  maxSizeBytes: number
19
- ) => {
19
+ ): Promise<ArrayBuffer> => {
20
20
  if (body instanceof Uint8Array) {
21
21
  if (body.byteLength > maxSizeBytes) {
22
22
  throw new Error(`Attachment exceeds the maximum size of ${maxSizeBytes} bytes`);
23
23
  }
24
- return body;
24
+
25
+ let buffered = new ArrayBuffer(body.byteLength);
26
+ new Uint8Array(buffered).set(body);
27
+ return buffered;
25
28
  }
26
29
 
27
30
  let reader = body.getReader();
@@ -41,10 +44,11 @@ let bufferAttachmentBody = async (
41
44
  chunks.push(value);
42
45
  }
43
46
 
44
- let buffered = new Uint8Array(sizeBytes);
47
+ let buffered = new ArrayBuffer(sizeBytes);
48
+ let bufferedView = new Uint8Array(buffered);
45
49
  let offset = 0;
46
50
  for (let chunk of chunks) {
47
- buffered.set(chunk, offset);
51
+ bufferedView.set(chunk, offset);
48
52
  offset += chunk.byteLength;
49
53
  }
50
54
  return buffered;
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { AuthConfigSecretRedactor } from '../auth/redact';
2
3
  import type { SlateContext } from '../context/context';
3
4
  import type { SlateSpecification } from '../specification/specification';
4
5
  import { tool } from './tool';
@@ -34,8 +35,17 @@ export let getFileUrlTool = <ConfigType extends {}, AuthType extends {}>(
34
35
  })
35
36
  .input(getFileUrlToolInputSchema)
36
37
  .output(getFileUrlToolOutputSchema)
37
- .handleInvocation(async ctx => ({
38
- output: await handleGetFileUrl(ctx),
39
- message: 'ok'
40
- }))
38
+ .handleInvocation(async ctx => {
39
+ let output = await handleGetFileUrl(ctx);
40
+ let redactor = new AuthConfigSecretRedactor(ctx._getAuthConfigForRedaction());
41
+
42
+ return {
43
+ output: {
44
+ ...output,
45
+ ...(output.headers ? { headers: redactor.redactEmbedded(output.headers) } : {}),
46
+ ...(output.query ? { query: redactor.redactEmbedded(output.query) } : {})
47
+ },
48
+ message: 'ok'
49
+ };
50
+ })
41
51
  .build();
@@ -5,3 +5,4 @@ export * from './publicTool';
5
5
  export * from './scopes';
6
6
  export * from './tool';
7
7
  export * from './trigger';
8
+ export * from './triggerGroup';
@@ -3,17 +3,11 @@ import type { SlateSpecification } from '../specification/specification';
3
3
  import {
4
4
  SlateAction,
5
5
  type SlateActionParameters,
6
- type SlatePollingOptions,
7
6
  type SlateTriggerMappingHandler,
8
- type SlateTriggerPollingHandler,
9
- type SlateTriggerWebhookAutoRegistrationHandler,
10
- type SlateTriggerWebhookAutoUnregistrationHandler,
11
- type SlateTriggerWebhookRequestHandler,
12
- type SlateWebhookHttpOptions
7
+ type SlateTriggerMatchesHandler
13
8
  } from './action';
14
9
  import { SlateActionBuilder } from './builder';
15
-
16
- export let SlateDefaultPollingIntervalSeconds = 60 * 10;
10
+ import type { SlateTriggerGroup } from './triggerGroup';
17
11
 
18
12
  export interface SlateTriggerParameters<
19
13
  ConfigType extends {},
@@ -24,14 +18,9 @@ export interface SlateTriggerParameters<
24
18
  }
25
19
  > extends SlateActionParameters {
26
20
  type: 'trigger';
27
- source: 'polling' | 'webhook';
28
- polling?: SlatePollingOptions;
29
- handleEvent: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
30
- handleRequest?: SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType>;
31
- http?: SlateWebhookHttpOptions;
32
- pollEvents?: SlateTriggerPollingHandler<ConfigType, AuthType, InputType>;
33
- autoRegisterWebhook?: SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType>;
34
- autoUnregisterWebhook?: SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType>;
21
+ triggerGroup: SlateTriggerGroup<ConfigType, AuthType>;
22
+ matches: SlateTriggerMatchesHandler;
23
+ map: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
35
24
  }
36
25
 
37
26
  export class SlateTrigger<
@@ -42,14 +31,9 @@ export class SlateTrigger<
42
31
  type: string;
43
32
  }
44
33
  > extends SlateAction<'trigger', ConfigType, AuthType, InputType, OutputType> {
45
- #source: 'polling' | 'webhook';
46
- #polling: SlatePollingOptions;
47
- #handleEvent: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
48
- #handleRequest?: SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType>;
49
- #http?: SlateWebhookHttpOptions;
50
- #pollEvents?: SlateTriggerPollingHandler<ConfigType, AuthType, InputType>;
51
- #autoRegisterWebhook?: SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType>;
52
- #autoUnregisterWebhook?: SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType>;
34
+ #triggerGroup: SlateTriggerGroup<ConfigType, AuthType>;
35
+ #matches: SlateTriggerMatchesHandler;
36
+ #map: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
53
37
 
54
38
  private constructor(
55
39
  spec: SlateSpecification<ConfigType, AuthType>,
@@ -59,16 +43,9 @@ export class SlateTrigger<
59
43
  ) {
60
44
  super('trigger', spec, inputSchema, outputSchema, params);
61
45
 
62
- this.#source = params.source;
63
- this.#polling = params.polling || {
64
- intervalInSeconds: SlateDefaultPollingIntervalSeconds
65
- };
66
- this.#handleEvent = params.handleEvent;
67
- this.#handleRequest = params.handleRequest;
68
- this.#http = params.http;
69
- this.#pollEvents = params.pollEvents;
70
- this.#autoRegisterWebhook = params.autoRegisterWebhook;
71
- this.#autoUnregisterWebhook = params.autoUnregisterWebhook;
46
+ this.#triggerGroup = params.triggerGroup;
47
+ this.#matches = params.matches;
48
+ this.#map = params.map;
72
49
  }
73
50
 
74
51
  static create<ConfigType extends {}, AuthType extends {}>(
@@ -81,36 +58,16 @@ export class SlateTrigger<
81
58
  });
82
59
  }
83
60
 
84
- get polling() {
85
- return this.#polling;
86
- }
87
-
88
- get source() {
89
- return this.#source;
90
- }
91
-
92
- get handleEvent() {
93
- return this.#handleEvent;
94
- }
95
-
96
- get handleRequest() {
97
- return this.#handleRequest;
98
- }
99
-
100
- get http() {
101
- return this.#http;
102
- }
103
-
104
- get pollEvents() {
105
- return this.#pollEvents;
61
+ get triggerGroup() {
62
+ return this.#triggerGroup;
106
63
  }
107
64
 
108
- get autoRegisterWebhook() {
109
- return this.#autoRegisterWebhook;
65
+ get matches() {
66
+ return this.#matches;
110
67
  }
111
68
 
112
- get autoUnregisterWebhook() {
113
- return this.#autoUnregisterWebhook;
69
+ get map() {
70
+ return this.#map;
114
71
  }
115
72
  }
116
73
 
@@ -0,0 +1,296 @@
1
+ import type z from 'zod';
2
+ import { SlateDeclarationError } from '../error';
3
+ import type { SlateSpecification } from '../specification/specification';
4
+ import type { SlateContext } from '../context';
5
+ import type { SlateWebhookHttpResponseInit } from './action';
6
+
7
+ export let SlateDefaultPollingIntervalSeconds = 60 * 10;
8
+
9
+ export type SlateTriggerRoutingMatcher = Record<string, any>;
10
+
11
+ export type SlateWebhookTargetOwnership = 'single_user' | 'multi_user';
12
+
13
+ export interface SlateWebhookTarget {
14
+ webhookTargetIdentifier: string;
15
+ name: string;
16
+ description?: string;
17
+ metadata: Record<string, any>;
18
+ webhookTargetPayload: any;
19
+ targetOwnership: SlateWebhookTargetOwnership;
20
+ }
21
+
22
+ export type SlateTriggerGroupRoutingMatchersHandler<ConfigType extends {}, AuthType extends {}> = (
23
+ context: SlateContext<ConfigType, AuthType, {}>
24
+ ) => Promise<SlateTriggerRoutingMatcher[]>;
25
+
26
+ export type SlateTriggerGroupPollHandler<ConfigType extends {}, AuthType extends {}> = (
27
+ context: SlateContext<ConfigType, AuthType, { state: any | null }>
28
+ ) => Promise<{
29
+ events: { payload: any; idempotencyKey?: string }[];
30
+ updatedState?: any;
31
+ }>;
32
+
33
+ export type SlateWebhookTargetListHandler<ConfigType extends {}, AuthType extends {}> = (
34
+ context: SlateContext<ConfigType, AuthType, { pageToken: any | null }>
35
+ ) => Promise<{
36
+ targets: SlateWebhookTarget[];
37
+ nextPageToken: any | null;
38
+ }>;
39
+
40
+ export type SlateWebhookRegisterHandler<ConfigType extends {}, AuthType extends {}> = (
41
+ context: SlateContext<
42
+ ConfigType,
43
+ AuthType,
44
+ {
45
+ webhookTargetIdentifier: string;
46
+ webhookTargetPayload: any;
47
+ webhookUrl: string;
48
+ }
49
+ >
50
+ ) => Promise<{
51
+ webhookRegistrationIdentifier: string;
52
+ webhookRegistrationPayload: any;
53
+ }>;
54
+
55
+ export type SlateWebhookUnregisterHandler<ConfigType extends {}, AuthType extends {}> = (
56
+ context: SlateContext<
57
+ ConfigType,
58
+ AuthType,
59
+ {
60
+ webhookRegistrationIdentifier: string;
61
+ webhookRegistrationPayload: any;
62
+ }
63
+ >
64
+ ) => Promise<unknown>;
65
+
66
+ export type SlateWebhookManualSetupHandler<FullConfigSchema extends z.ZodType<any> = z.ZodType<any>> =
67
+ (
68
+ context: SlateContext<{}, {}, { webhookUrl: string }>
69
+ ) => Promise<{
70
+ webhookSetupDocument: string;
71
+ partialWebhookRegistrationPayload: Partial<z.infer<FullConfigSchema>>;
72
+ }>;
73
+
74
+ export type SlateWebhookManualFinishHandler<
75
+ UserConfigSchema extends z.ZodType<any> = z.ZodType<any>,
76
+ FullConfigSchema extends z.ZodType<any> = z.ZodType<any>
77
+ > = (
78
+ context: SlateContext<
79
+ {},
80
+ {},
81
+ {
82
+ webhookUrl: string;
83
+ partialWebhookRegistrationPayload: Partial<z.infer<FullConfigSchema>>;
84
+ userWebhookRegistrationPayload: z.infer<UserConfigSchema>;
85
+ }
86
+ >
87
+ ) => Promise<{
88
+ webhookRegistrationPayload: z.infer<FullConfigSchema>;
89
+ }>;
90
+
91
+ export type SlateWebhookProcessHandler = (
92
+ context: SlateContext<
93
+ {},
94
+ {},
95
+ {
96
+ request: Request;
97
+ webhookRegistrationPayload: any;
98
+ }
99
+ >
100
+ ) => Promise<{
101
+ events: {
102
+ matchers: SlateTriggerRoutingMatcher[];
103
+ payload: any;
104
+ idempotencyKey?: string;
105
+ }[];
106
+ response?: Response | SlateWebhookHttpResponseInit;
107
+ }>;
108
+
109
+ export interface SlateTriggerGroupPollingParameters<ConfigType extends {}, AuthType extends {}> {
110
+ intervalSeconds: number;
111
+ pollEvents: SlateTriggerGroupPollHandler<ConfigType, AuthType>;
112
+ }
113
+
114
+ export interface SlateTriggerGroupWebhookAutoRegistrationParameters<
115
+ ConfigType extends {},
116
+ AuthType extends {}
117
+ > {
118
+ webhookTargetList: SlateWebhookTargetListHandler<ConfigType, AuthType>;
119
+ webhookRegister: SlateWebhookRegisterHandler<ConfigType, AuthType>;
120
+ webhookUnregister: SlateWebhookUnregisterHandler<ConfigType, AuthType>;
121
+ }
122
+
123
+ export interface SlateTriggerGroupWebhookManualRegistrationParameters<
124
+ UserConfigSchema extends z.ZodType<any> = z.ZodType<any>,
125
+ FullConfigSchema extends z.ZodType<any> = z.ZodType<any>
126
+ > {
127
+ userConfigSchema: UserConfigSchema;
128
+ fullConfigSchema: FullConfigSchema;
129
+ setup: SlateWebhookManualSetupHandler<FullConfigSchema>;
130
+ finish?: SlateWebhookManualFinishHandler<UserConfigSchema, FullConfigSchema>;
131
+ }
132
+
133
+ export interface SlateTriggerGroupWebhookParameters<ConfigType extends {}, AuthType extends {}> {
134
+ autoRegistration?: SlateTriggerGroupWebhookAutoRegistrationParameters<ConfigType, AuthType>;
135
+ manualRegistration?: SlateTriggerGroupWebhookManualRegistrationParameters<any, any>;
136
+ process: SlateWebhookProcessHandler;
137
+ }
138
+
139
+ export interface SlateTriggerGroupCreateParameters {
140
+ key: string;
141
+ name: string;
142
+ description?: string;
143
+ metadata?: Record<string, any>;
144
+ }
145
+
146
+ export interface SlateTriggerGroupParameters<ConfigType extends {}, AuthType extends {}>
147
+ extends SlateTriggerGroupCreateParameters {
148
+ source: 'polling' | 'webhook';
149
+ polling?: SlateTriggerGroupPollingParameters<ConfigType, AuthType>;
150
+ webhook?: SlateTriggerGroupWebhookParameters<ConfigType, AuthType>;
151
+ routingMatchers: SlateTriggerGroupRoutingMatchersHandler<ConfigType, AuthType>;
152
+ }
153
+
154
+ export class SlateTriggerGroup<ConfigType extends {}, AuthType extends {}> {
155
+ private constructor(
156
+ private readonly _spec: SlateSpecification<ConfigType, AuthType>,
157
+ private readonly _params: SlateTriggerGroupParameters<ConfigType, AuthType>
158
+ ) {}
159
+
160
+ static create<ConfigType extends {}, AuthType extends {}>(
161
+ spec: SlateSpecification<ConfigType, AuthType>,
162
+ params: SlateTriggerGroupCreateParameters
163
+ ) {
164
+ return new SlateTriggerGroupBuilder(spec, params, p => new SlateTriggerGroup(spec, p));
165
+ }
166
+
167
+ get spec() {
168
+ return this._spec;
169
+ }
170
+
171
+ get key() {
172
+ return this._params.key;
173
+ }
174
+
175
+ get name() {
176
+ return this._params.name;
177
+ }
178
+
179
+ get description() {
180
+ return this._params.description;
181
+ }
182
+
183
+ get metadata() {
184
+ return this._params.metadata;
185
+ }
186
+
187
+ get source() {
188
+ return this._params.source;
189
+ }
190
+
191
+ get polling() {
192
+ return this._params.polling;
193
+ }
194
+
195
+ get webhook() {
196
+ return this._params.webhook;
197
+ }
198
+
199
+ get routingMatchers() {
200
+ return this._params.routingMatchers;
201
+ }
202
+ }
203
+
204
+ export class SlateTriggerGroupBuilder<ConfigType extends {}, AuthType extends {}> {
205
+ #source: 'polling' | 'webhook' | null = null;
206
+ #polling: SlateTriggerGroupPollingParameters<ConfigType, AuthType> | null = null;
207
+ #webhook: SlateTriggerGroupWebhookParameters<ConfigType, AuthType> | null = null;
208
+ #routingMatchers: SlateTriggerGroupRoutingMatchersHandler<ConfigType, AuthType> | null = null;
209
+
210
+ constructor(
211
+ private readonly spec: SlateSpecification<ConfigType, AuthType>,
212
+ private readonly params: SlateTriggerGroupCreateParameters,
213
+ private readonly factory: (
214
+ params: SlateTriggerGroupParameters<ConfigType, AuthType>
215
+ ) => SlateTriggerGroup<ConfigType, AuthType>
216
+ ) {}
217
+
218
+ polling(props: {
219
+ intervalSeconds?: number;
220
+ pollEvents: SlateTriggerGroupPollHandler<ConfigType, AuthType>;
221
+ }): SlateTriggerGroupBuilder<ConfigType, AuthType> {
222
+ if (this.#source) {
223
+ throw new SlateDeclarationError('Trigger group invocation is already defined');
224
+ }
225
+
226
+ this.#source = 'polling';
227
+ this.#polling = {
228
+ intervalSeconds: props.intervalSeconds ?? SlateDefaultPollingIntervalSeconds,
229
+ pollEvents: props.pollEvents
230
+ };
231
+
232
+ return this;
233
+ }
234
+
235
+ webhook<
236
+ UserConfigSchema extends z.ZodType<any> = z.ZodType<any>,
237
+ FullConfigSchema extends z.ZodType<any> = z.ZodType<any>
238
+ >(props: {
239
+ autoRegistration?: SlateTriggerGroupWebhookAutoRegistrationParameters<ConfigType, AuthType>;
240
+ manualRegistration?: SlateTriggerGroupWebhookManualRegistrationParameters<
241
+ UserConfigSchema,
242
+ FullConfigSchema
243
+ >;
244
+ process: SlateWebhookProcessHandler;
245
+ }): SlateTriggerGroupBuilder<ConfigType, AuthType> {
246
+ if (this.#source) {
247
+ throw new SlateDeclarationError('Trigger group invocation is already defined');
248
+ }
249
+
250
+ if (!!props.autoRegistration === !!props.manualRegistration) {
251
+ throw new SlateDeclarationError(
252
+ 'Webhook trigger groups require exactly one of autoRegistration or manualRegistration'
253
+ );
254
+ }
255
+
256
+ this.#source = 'webhook';
257
+ this.#webhook = {
258
+ autoRegistration: props.autoRegistration,
259
+ manualRegistration: props.manualRegistration,
260
+ process: props.process
261
+ };
262
+
263
+ return this;
264
+ }
265
+
266
+ routingMatchers(
267
+ handler: SlateTriggerGroupRoutingMatchersHandler<ConfigType, AuthType>
268
+ ): SlateTriggerGroupBuilder<ConfigType, AuthType> {
269
+ this.#routingMatchers = handler;
270
+ return this;
271
+ }
272
+
273
+ build(): SlateTriggerGroup<ConfigType, AuthType> {
274
+ if (!this.#source) {
275
+ throw new SlateDeclarationError(
276
+ 'Trigger group invocation (polling or webhook) is not defined'
277
+ );
278
+ }
279
+ if (!this.#routingMatchers) {
280
+ throw new SlateDeclarationError('Trigger group routing matchers handler is not defined');
281
+ }
282
+
283
+ return this.factory({
284
+ ...this.params,
285
+ source: this.#source,
286
+ polling: this.#polling ?? undefined,
287
+ webhook: this.#webhook ?? undefined,
288
+ routingMatchers: this.#routingMatchers
289
+ });
290
+ }
291
+ }
292
+
293
+ export let triggerGroup = <ConfigType extends {}, AuthType extends {}>(
294
+ spec: SlateSpecification<ConfigType, AuthType>,
295
+ params: SlateTriggerGroupCreateParameters
296
+ ) => SlateTriggerGroup.create(spec, params);