@slates/provider-handler 1.0.0-rc.31 → 1.0.0-rc.32

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.
package/dist/index.cjs CHANGED
@@ -187,6 +187,14 @@ var mapAction = (_slate, a) => {
187
187
  triggerGroupId: a.triggerGroup.key
188
188
  };
189
189
  };
190
+ var isMappableTrigger = (action) => action.type !== "trigger" || !!action.triggerGroup;
191
+ var getMappableAction = (slate, actionId) => {
192
+ let action = getAction(slate, actionId);
193
+ if (!isMappableTrigger(action)) {
194
+ throw new import_error2.ServiceError((0, import_error2.notFoundError)(`action`, actionId));
195
+ }
196
+ return action;
197
+ };
190
198
  var getTriggerGroup = (slate, triggerGroupId) => {
191
199
  let group = slate.triggerGroups.find((g) => g.key === triggerGroupId);
192
200
  if (!group) {
@@ -195,7 +203,7 @@ var getTriggerGroup = (slate, triggerGroupId) => {
195
203
  return group;
196
204
  };
197
205
  var getTriggersForGroup = (slate, triggerGroupId) => slate.actions.filter(
198
- (action) => action.type === "trigger" && action.triggerGroup.key === triggerGroupId
206
+ (action) => action.type === "trigger" && action.triggerGroup?.key === triggerGroupId
199
207
  );
200
208
  var evaluateTriggerMatches = (slate, triggerGroupId, payload) => getTriggersForGroup(slate, triggerGroupId).filter((trigger) => trigger.matches(payload)).map((trigger) => trigger.key);
201
209
  var getWebhookAutoRegistration = (group) => {
@@ -230,8 +238,12 @@ var mapTriggerGroup = (group) => ({
230
238
  type: "webhook",
231
239
  registration: group.webhook?.manualRegistration ? {
232
240
  mode: "manual",
233
- userConfigSchema: toJsonSchema(group.webhook.manualRegistration.userConfigSchema),
234
- fullConfigSchema: toJsonSchema(group.webhook.manualRegistration.fullConfigSchema)
241
+ userConfigSchema: toJsonSchema(
242
+ group.webhook.manualRegistration.userConfigSchema
243
+ ),
244
+ fullConfigSchema: toJsonSchema(
245
+ group.webhook.manualRegistration.fullConfigSchema
246
+ )
235
247
  } : { mode: "auto" }
236
248
  }
237
249
  });
@@ -557,7 +569,7 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
557
569
  liveInvocation: true
558
570
  },
559
571
  provider: {
560
- triggerGroups: true
572
+ triggerGroups: (slate.triggerGroups?.length ?? 0) > 0 && (slate.actions ?? []).every(isMappableTrigger)
561
573
  }
562
574
  }
563
575
  }));
@@ -969,6 +981,7 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
969
981
  manager.onRequest("slates/actions.list", async ({ params }) => {
970
982
  getContextBasic();
971
983
  let actions = params.includeAdapterActions ? slate.actions : slate.actions.filter((action) => !action.adapter);
984
+ actions = actions.filter(isMappableTrigger);
972
985
  if (!supportsTriggerGroups()) {
973
986
  actions = actions.filter((action) => action.type !== "trigger");
974
987
  }
@@ -991,7 +1004,7 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
991
1004
  });
992
1005
  manager.onRequest("slates/action.get", async ({ params }) => {
993
1006
  getContextBasic();
994
- let action = getAction(slate, params.actionId);
1007
+ let action = getMappableAction(slate, params.actionId);
995
1008
  return {
996
1009
  action: mapAction(slate, action)
997
1010
  };
@@ -165,6 +165,14 @@ var mapAction = (_slate, a) => {
165
165
  triggerGroupId: a.triggerGroup.key
166
166
  };
167
167
  };
168
+ var isMappableTrigger = (action) => action.type !== "trigger" || !!action.triggerGroup;
169
+ var getMappableAction = (slate, actionId) => {
170
+ let action = getAction(slate, actionId);
171
+ if (!isMappableTrigger(action)) {
172
+ throw new ServiceError2(notFoundError(`action`, actionId));
173
+ }
174
+ return action;
175
+ };
168
176
  var getTriggerGroup = (slate, triggerGroupId) => {
169
177
  let group = slate.triggerGroups.find((g) => g.key === triggerGroupId);
170
178
  if (!group) {
@@ -173,7 +181,7 @@ var getTriggerGroup = (slate, triggerGroupId) => {
173
181
  return group;
174
182
  };
175
183
  var getTriggersForGroup = (slate, triggerGroupId) => slate.actions.filter(
176
- (action) => action.type === "trigger" && action.triggerGroup.key === triggerGroupId
184
+ (action) => action.type === "trigger" && action.triggerGroup?.key === triggerGroupId
177
185
  );
178
186
  var evaluateTriggerMatches = (slate, triggerGroupId, payload) => getTriggersForGroup(slate, triggerGroupId).filter((trigger) => trigger.matches(payload)).map((trigger) => trigger.key);
179
187
  var getWebhookAutoRegistration = (group) => {
@@ -208,8 +216,12 @@ var mapTriggerGroup = (group) => ({
208
216
  type: "webhook",
209
217
  registration: group.webhook?.manualRegistration ? {
210
218
  mode: "manual",
211
- userConfigSchema: toJsonSchema(group.webhook.manualRegistration.userConfigSchema),
212
- fullConfigSchema: toJsonSchema(group.webhook.manualRegistration.fullConfigSchema)
219
+ userConfigSchema: toJsonSchema(
220
+ group.webhook.manualRegistration.userConfigSchema
221
+ ),
222
+ fullConfigSchema: toJsonSchema(
223
+ group.webhook.manualRegistration.fullConfigSchema
224
+ )
213
225
  } : { mode: "auto" }
214
226
  }
215
227
  });
@@ -535,7 +547,7 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
535
547
  liveInvocation: true
536
548
  },
537
549
  provider: {
538
- triggerGroups: true
550
+ triggerGroups: (slate.triggerGroups?.length ?? 0) > 0 && (slate.actions ?? []).every(isMappableTrigger)
539
551
  }
540
552
  }
541
553
  }));
@@ -947,6 +959,7 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
947
959
  manager.onRequest("slates/actions.list", async ({ params }) => {
948
960
  getContextBasic();
949
961
  let actions = params.includeAdapterActions ? slate.actions : slate.actions.filter((action) => !action.adapter);
962
+ actions = actions.filter(isMappableTrigger);
950
963
  if (!supportsTriggerGroups()) {
951
964
  actions = actions.filter((action) => action.type !== "trigger");
952
965
  }
@@ -969,7 +982,7 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
969
982
  });
970
983
  manager.onRequest("slates/action.get", async ({ params }) => {
971
984
  getContextBasic();
972
- let action = getAction(slate, params.actionId);
985
+ let action = getMappableAction(slate, params.actionId);
973
986
  return {
974
987
  action: mapAction(slate, action)
975
988
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slates/provider-handler",
3
- "version": "1.0.0-rc.31",
3
+ "version": "1.0.0-rc.32",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -43,4 +43,4 @@
43
43
  "typescript": "5.8.2",
44
44
  "vitest": "^3.1.2"
45
45
  }
46
- }
46
+ }
package/src/index.ts CHANGED
@@ -19,13 +19,14 @@ import {
19
19
  import { PQueue } from './pQueue';
20
20
  import {
21
21
  evaluateTriggerMatches,
22
- getAction,
23
22
  getActionWithType,
24
23
  getAdapter,
25
24
  getAuthMethod,
25
+ getMappableAction,
26
26
  getTriggerGroup,
27
27
  getWebhookAutoRegistration,
28
28
  getWebhookManualRegistration,
29
+ isMappableTrigger,
29
30
  mapAction,
30
31
  mapAdapter,
31
32
  mapAuthMethod,
@@ -402,7 +403,9 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
402
403
  liveInvocation: true
403
404
  },
404
405
  provider: {
405
- triggerGroups: true
406
+ triggerGroups:
407
+ (slate.triggerGroups?.length ?? 0) > 0 &&
408
+ (slate.actions ?? []).every(isMappableTrigger)
406
409
  }
407
410
  }
408
411
  }));
@@ -868,6 +871,8 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
868
871
  ? slate.actions
869
872
  : slate.actions.filter(action => !action.adapter);
870
873
 
874
+ actions = actions.filter(isMappableTrigger);
875
+
871
876
  if (!supportsTriggerGroups()) {
872
877
  actions = actions.filter(action => action.type !== 'trigger');
873
878
  }
@@ -896,7 +901,7 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
896
901
 
897
902
  manager.onRequest('slates/action.get', async ({ params }) => {
898
903
  getContextBasic();
899
- let action = getAction(slate, params.actionId);
904
+ let action = getMappableAction(slate, params.actionId);
900
905
 
901
906
  return {
902
907
  action: mapAction(slate, action)
@@ -0,0 +1,83 @@
1
+ import { isServiceError } from '@lowerdeck/error';
2
+ import { describe, expect, it } from 'vitest';
3
+ import { z } from 'zod';
4
+ import { getMappableAction, getTriggersForGroup, isMappableTrigger, mapAction } from './spec';
5
+
6
+ let baseAction = {
7
+ key: 'do_thing',
8
+ name: 'Do Thing',
9
+ description: 'desc',
10
+ instructions: undefined,
11
+ constraints: undefined,
12
+ tags: [],
13
+ metadata: {},
14
+ scopes: [],
15
+ authMethods: [],
16
+ docs: [],
17
+ adapter: undefined,
18
+ inputSchema: z.object({}),
19
+ outputSchema: z.object({})
20
+ };
21
+
22
+ let toolAction: any = { ...baseAction, type: 'tool', isPublic: false };
23
+
24
+ let validTriggerGroup = { key: 'my_group', name: 'My Group' };
25
+ let validTrigger: any = {
26
+ ...baseAction,
27
+ type: 'trigger',
28
+ triggerGroup: validTriggerGroup,
29
+ matches: () => true,
30
+ map: () => ({})
31
+ };
32
+
33
+ let incompatibleTrigger: any = { ...baseAction, type: 'trigger', triggerGroup: undefined };
34
+
35
+ describe('isMappableTrigger', () => {
36
+ it('is true for tool actions', () => {
37
+ expect(isMappableTrigger(toolAction)).toBe(true);
38
+ });
39
+
40
+ it('is true for triggers with a trigger group', () => {
41
+ expect(isMappableTrigger(validTrigger)).toBe(true);
42
+ });
43
+
44
+ it('is false for triggers missing a trigger group', () => {
45
+ expect(isMappableTrigger(incompatibleTrigger)).toBe(false);
46
+ });
47
+ });
48
+
49
+ describe('mapAction', () => {
50
+ it('maps a well-formed trigger', () => {
51
+ let mapped = mapAction({} as any, validTrigger);
52
+ expect(mapped).toMatchObject({ type: 'action.trigger', triggerGroupId: 'my_group' });
53
+ });
54
+ });
55
+
56
+ describe('getTriggersForGroup', () => {
57
+ it('filters out triggers missing a trigger group instead of throwing', () => {
58
+ let slate = { actions: [toolAction, validTrigger, incompatibleTrigger] } as any;
59
+
60
+ expect(getTriggersForGroup(slate, 'my_group')).toEqual([validTrigger]);
61
+ expect(getTriggersForGroup(slate, 'other_group')).toEqual([]);
62
+ });
63
+ });
64
+
65
+ describe('getMappableAction', () => {
66
+ it('returns tool and well-formed trigger actions', () => {
67
+ let slate = { actions: [toolAction, validTrigger] } as any;
68
+
69
+ expect(getMappableAction(slate, 'do_thing')).toBe(toolAction);
70
+ });
71
+
72
+ it('treats a trigger missing its group as not found instead of crashing', () => {
73
+ let slate = { actions: [incompatibleTrigger] } as any;
74
+
75
+ try {
76
+ getMappableAction(slate, 'do_thing');
77
+ expect.unreachable();
78
+ } catch (e) {
79
+ expect(isServiceError(e)).toBe(true);
80
+ expect((e as any).data.status).toBe(404);
81
+ }
82
+ });
83
+ });
package/src/spec.ts CHANGED
@@ -155,6 +155,22 @@ export let mapAction = <ConfigType extends {}, AuthType extends {}>(
155
155
  };
156
156
  };
157
157
 
158
+ export let isMappableTrigger = <ConfigType extends {}, AuthType extends {}>(
159
+ action: Slate<ConfigType, AuthType>['actions'][number]
160
+ ): boolean => action.type !== 'trigger' || !!action.triggerGroup;
161
+
162
+ export let getMappableAction = <ConfigType extends {}, AuthType extends {}>(
163
+ slate: Slate<ConfigType, AuthType>,
164
+ actionId: string
165
+ ) => {
166
+ let action = getAction(slate, actionId);
167
+ if (!isMappableTrigger(action)) {
168
+ throw new ServiceError(notFoundError(`action`, actionId));
169
+ }
170
+
171
+ return action;
172
+ };
173
+
158
174
  export let getTriggerGroup = <ConfigType extends {}, AuthType extends {}>(
159
175
  slate: Slate<ConfigType, AuthType>,
160
176
  triggerGroupId: string
@@ -173,7 +189,7 @@ export let getTriggersForGroup = <ConfigType extends {}, AuthType extends {}>(
173
189
  ): SlateTrigger<ConfigType, AuthType, any, any>[] =>
174
190
  slate.actions.filter(
175
191
  (action): action is SlateTrigger<ConfigType, AuthType, any, any> =>
176
- action.type === 'trigger' && action.triggerGroup.key === triggerGroupId
192
+ action.type === 'trigger' && action.triggerGroup?.key === triggerGroupId
177
193
  );
178
194
 
179
195
  export let evaluateTriggerMatches = <ConfigType extends {}, AuthType extends {}>(
@@ -231,8 +247,12 @@ export let mapTriggerGroup = <ConfigType extends {}, AuthType extends {}>(
231
247
  registration: group.webhook?.manualRegistration
232
248
  ? {
233
249
  mode: 'manual',
234
- userConfigSchema: toJsonSchema(group.webhook.manualRegistration.userConfigSchema),
235
- fullConfigSchema: toJsonSchema(group.webhook.manualRegistration.fullConfigSchema)
250
+ userConfigSchema: toJsonSchema(
251
+ group.webhook.manualRegistration.userConfigSchema
252
+ ),
253
+ fullConfigSchema: toJsonSchema(
254
+ group.webhook.manualRegistration.fullConfigSchema
255
+ )
236
256
  }
237
257
  : { mode: 'auto' }
238
258
  }