@slates/provider 1.0.0-rc.22 → 1.0.0-rc.24
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 +180 -63
- package/dist/index.d.cts +160 -96
- package/dist/index.d.ts +160 -96
- package/dist/index.module.js +177 -63
- package/package.json +2 -2
- package/src/action/action.ts +6 -88
- package/src/action/builder.ts +50 -46
- package/src/action/index.ts +1 -0
- package/src/action/trigger.ts +17 -60
- package/src/action/triggerGroup.ts +332 -0
- package/src/adapter/index.test.ts +35 -14
- package/src/auth/types.ts +8 -0
- package/src/module/resolveDefaultExport.test.ts +3 -3
- package/src/specification/slate.test.ts +105 -0
- package/src/specification/slate.ts +31 -3
- package/src/webhook/graph.ts +2 -2
- package/src/webhook/meta.ts +2 -2
package/dist/index.module.js
CHANGED
|
@@ -825,7 +825,9 @@ var SlateActionBuilder = class {
|
|
|
825
825
|
#scopes;
|
|
826
826
|
#authMethods;
|
|
827
827
|
#toolParams = null;
|
|
828
|
-
#
|
|
828
|
+
#triggerGroup = null;
|
|
829
|
+
#triggerMatches = null;
|
|
830
|
+
#triggerMap = null;
|
|
829
831
|
#interfaceLocked = false;
|
|
830
832
|
input(schema) {
|
|
831
833
|
if (this.#interfaceLocked) {
|
|
@@ -875,32 +877,25 @@ var SlateActionBuilder = class {
|
|
|
875
877
|
};
|
|
876
878
|
return this;
|
|
877
879
|
}
|
|
878
|
-
|
|
880
|
+
triggerGroup(group) {
|
|
879
881
|
if (this.type !== "trigger") {
|
|
880
|
-
throw new SlateDeclarationError("
|
|
882
|
+
throw new SlateDeclarationError("triggerGroup can only be set for trigger actions");
|
|
881
883
|
}
|
|
882
|
-
this.#
|
|
883
|
-
type: "trigger",
|
|
884
|
-
source: "webhook",
|
|
885
|
-
handleEvent: props.handleEvent,
|
|
886
|
-
handleRequest: props.handleRequest,
|
|
887
|
-
autoRegisterWebhook: props.autoRegisterWebhook,
|
|
888
|
-
autoUnregisterWebhook: props.autoUnregisterWebhook,
|
|
889
|
-
http: props.http
|
|
890
|
-
};
|
|
884
|
+
this.#triggerGroup = group;
|
|
891
885
|
return this;
|
|
892
886
|
}
|
|
893
|
-
|
|
887
|
+
matches(handler) {
|
|
894
888
|
if (this.type !== "trigger") {
|
|
895
|
-
throw new SlateDeclarationError("
|
|
889
|
+
throw new SlateDeclarationError("matches can only be set for trigger actions");
|
|
896
890
|
}
|
|
897
|
-
this.#
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
}
|
|
891
|
+
this.#triggerMatches = handler;
|
|
892
|
+
return this;
|
|
893
|
+
}
|
|
894
|
+
map(handler) {
|
|
895
|
+
if (this.type !== "trigger") {
|
|
896
|
+
throw new SlateDeclarationError("map can only be set for trigger actions");
|
|
897
|
+
}
|
|
898
|
+
this.#triggerMap = handler;
|
|
904
899
|
return this;
|
|
905
900
|
}
|
|
906
901
|
build() {
|
|
@@ -921,9 +916,21 @@ var SlateActionBuilder = class {
|
|
|
921
916
|
if (this.type === "tool" && !this.#toolParams) {
|
|
922
917
|
throw new SlateDeclarationError("Tool invocation handler is not defined");
|
|
923
918
|
}
|
|
924
|
-
if (this.type === "trigger" && !this.#
|
|
925
|
-
throw new SlateDeclarationError("Trigger
|
|
919
|
+
if (this.type === "trigger" && !this.#triggerGroup) {
|
|
920
|
+
throw new SlateDeclarationError("Trigger group is not defined");
|
|
921
|
+
}
|
|
922
|
+
if (this.type === "trigger" && !this.#triggerMatches) {
|
|
923
|
+
throw new SlateDeclarationError("Trigger matches handler is not defined");
|
|
926
924
|
}
|
|
925
|
+
if (this.type === "trigger" && !this.#triggerMap) {
|
|
926
|
+
throw new SlateDeclarationError("Trigger map handler is not defined");
|
|
927
|
+
}
|
|
928
|
+
let triggerParams = this.type === "trigger" ? {
|
|
929
|
+
type: "trigger",
|
|
930
|
+
triggerGroup: this.#triggerGroup,
|
|
931
|
+
matches: this.#triggerMatches,
|
|
932
|
+
map: this.#triggerMap
|
|
933
|
+
} : null;
|
|
927
934
|
return this.factory({
|
|
928
935
|
...this.params,
|
|
929
936
|
scopes,
|
|
@@ -934,7 +941,7 @@ var SlateActionBuilder = class {
|
|
|
934
941
|
inputSchema: this.#inputSchema,
|
|
935
942
|
outputSchema: this.#outputSchema,
|
|
936
943
|
...this.#toolParams,
|
|
937
|
-
...
|
|
944
|
+
...triggerParams
|
|
938
945
|
});
|
|
939
946
|
}
|
|
940
947
|
};
|
|
@@ -1100,28 +1107,15 @@ var SlatePublicTool = class {
|
|
|
1100
1107
|
var publicTool = (spec2, params) => SlatePublicTool.create(spec2, params);
|
|
1101
1108
|
|
|
1102
1109
|
// src/action/trigger.ts
|
|
1103
|
-
var SlateDefaultPollingIntervalSeconds = 60 * 10;
|
|
1104
1110
|
var SlateTrigger = class _SlateTrigger extends SlateAction {
|
|
1105
|
-
#
|
|
1106
|
-
#
|
|
1107
|
-
#
|
|
1108
|
-
#handleRequest;
|
|
1109
|
-
#http;
|
|
1110
|
-
#pollEvents;
|
|
1111
|
-
#autoRegisterWebhook;
|
|
1112
|
-
#autoUnregisterWebhook;
|
|
1111
|
+
#triggerGroup;
|
|
1112
|
+
#matches;
|
|
1113
|
+
#map;
|
|
1113
1114
|
constructor(spec2, inputSchema, outputSchema, params) {
|
|
1114
1115
|
super("trigger", spec2, inputSchema, outputSchema, params);
|
|
1115
|
-
this.#
|
|
1116
|
-
this.#
|
|
1117
|
-
|
|
1118
|
-
};
|
|
1119
|
-
this.#handleEvent = params.handleEvent;
|
|
1120
|
-
this.#handleRequest = params.handleRequest;
|
|
1121
|
-
this.#http = params.http;
|
|
1122
|
-
this.#pollEvents = params.pollEvents;
|
|
1123
|
-
this.#autoRegisterWebhook = params.autoRegisterWebhook;
|
|
1124
|
-
this.#autoUnregisterWebhook = params.autoUnregisterWebhook;
|
|
1116
|
+
this.#triggerGroup = params.triggerGroup;
|
|
1117
|
+
this.#matches = params.matches;
|
|
1118
|
+
this.#map = params.map;
|
|
1125
1119
|
}
|
|
1126
1120
|
static create(spec2, params) {
|
|
1127
1121
|
return new SlateActionBuilder("trigger", spec2, params, (params2) => {
|
|
@@ -1129,32 +1123,126 @@ var SlateTrigger = class _SlateTrigger extends SlateAction {
|
|
|
1129
1123
|
return new _SlateTrigger(spec2, params2.inputSchema, params2.outputSchema, params2);
|
|
1130
1124
|
});
|
|
1131
1125
|
}
|
|
1132
|
-
get
|
|
1133
|
-
return this.#
|
|
1126
|
+
get triggerGroup() {
|
|
1127
|
+
return this.#triggerGroup;
|
|
1128
|
+
}
|
|
1129
|
+
get matches() {
|
|
1130
|
+
return this.#matches;
|
|
1131
|
+
}
|
|
1132
|
+
get map() {
|
|
1133
|
+
return this.#map;
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
var trigger = (spec2, params) => SlateTrigger.create(spec2, params);
|
|
1137
|
+
|
|
1138
|
+
// src/action/triggerGroup.ts
|
|
1139
|
+
import { z as z2 } from "zod";
|
|
1140
|
+
var SlateDefaultPollingIntervalSeconds = 60 * 10;
|
|
1141
|
+
var SlateTriggerGroup = class _SlateTriggerGroup {
|
|
1142
|
+
constructor(_spec, _params) {
|
|
1143
|
+
this._spec = _spec;
|
|
1144
|
+
this._params = _params;
|
|
1145
|
+
}
|
|
1146
|
+
_spec;
|
|
1147
|
+
_params;
|
|
1148
|
+
static create(spec2, params) {
|
|
1149
|
+
return new SlateTriggerGroupBuilder(spec2, params, (p) => new _SlateTriggerGroup(spec2, p));
|
|
1150
|
+
}
|
|
1151
|
+
get spec() {
|
|
1152
|
+
return this._spec;
|
|
1153
|
+
}
|
|
1154
|
+
get key() {
|
|
1155
|
+
return this._params.key;
|
|
1156
|
+
}
|
|
1157
|
+
get name() {
|
|
1158
|
+
return this._params.name;
|
|
1159
|
+
}
|
|
1160
|
+
get description() {
|
|
1161
|
+
return this._params.description;
|
|
1162
|
+
}
|
|
1163
|
+
get metadata() {
|
|
1164
|
+
return this._params.metadata;
|
|
1165
|
+
}
|
|
1166
|
+
get eventSchema() {
|
|
1167
|
+
return this._params.eventSchema ?? z2.object({}).passthrough();
|
|
1134
1168
|
}
|
|
1135
1169
|
get source() {
|
|
1136
|
-
return this
|
|
1170
|
+
return this._params.source;
|
|
1137
1171
|
}
|
|
1138
|
-
get
|
|
1139
|
-
return this
|
|
1172
|
+
get polling() {
|
|
1173
|
+
return this._params.polling;
|
|
1140
1174
|
}
|
|
1141
|
-
get
|
|
1142
|
-
return this
|
|
1175
|
+
get webhook() {
|
|
1176
|
+
return this._params.webhook;
|
|
1143
1177
|
}
|
|
1144
|
-
get
|
|
1145
|
-
return this
|
|
1178
|
+
get routingMatchers() {
|
|
1179
|
+
return this._params.routingMatchers;
|
|
1146
1180
|
}
|
|
1147
|
-
|
|
1148
|
-
|
|
1181
|
+
};
|
|
1182
|
+
var SlateTriggerGroupBuilder = class {
|
|
1183
|
+
constructor(spec2, params, factory) {
|
|
1184
|
+
this.spec = spec2;
|
|
1185
|
+
this.params = params;
|
|
1186
|
+
this.factory = factory;
|
|
1187
|
+
}
|
|
1188
|
+
spec;
|
|
1189
|
+
params;
|
|
1190
|
+
factory;
|
|
1191
|
+
#source = null;
|
|
1192
|
+
#polling = null;
|
|
1193
|
+
#webhook = null;
|
|
1194
|
+
#routingMatchers = null;
|
|
1195
|
+
polling(props) {
|
|
1196
|
+
if (this.#source) {
|
|
1197
|
+
throw new SlateDeclarationError("Trigger group invocation is already defined");
|
|
1198
|
+
}
|
|
1199
|
+
this.#source = "polling";
|
|
1200
|
+
this.#polling = {
|
|
1201
|
+
intervalSeconds: props.intervalSeconds ?? SlateDefaultPollingIntervalSeconds,
|
|
1202
|
+
pollEvents: props.pollEvents
|
|
1203
|
+
};
|
|
1204
|
+
return this;
|
|
1205
|
+
}
|
|
1206
|
+
webhook(props) {
|
|
1207
|
+
if (this.#source) {
|
|
1208
|
+
throw new SlateDeclarationError("Trigger group invocation is already defined");
|
|
1209
|
+
}
|
|
1210
|
+
if (!!props.autoRegistration === !!props.manualRegistration) {
|
|
1211
|
+
throw new SlateDeclarationError(
|
|
1212
|
+
"Webhook trigger groups require exactly one of autoRegistration or manualRegistration"
|
|
1213
|
+
);
|
|
1214
|
+
}
|
|
1215
|
+
this.#source = "webhook";
|
|
1216
|
+
this.#webhook = {
|
|
1217
|
+
autoRegistration: props.autoRegistration,
|
|
1218
|
+
manualRegistration: props.manualRegistration,
|
|
1219
|
+
process: props.process
|
|
1220
|
+
};
|
|
1221
|
+
return this;
|
|
1149
1222
|
}
|
|
1150
|
-
|
|
1151
|
-
|
|
1223
|
+
routingMatchers(handler) {
|
|
1224
|
+
this.#routingMatchers = handler;
|
|
1225
|
+
return this;
|
|
1152
1226
|
}
|
|
1153
|
-
|
|
1154
|
-
|
|
1227
|
+
build() {
|
|
1228
|
+
if (!this.#source) {
|
|
1229
|
+
throw new SlateDeclarationError(
|
|
1230
|
+
"Trigger group invocation (polling or webhook) is not defined"
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
if (!this.#routingMatchers) {
|
|
1234
|
+
throw new SlateDeclarationError("Trigger group routing matchers handler is not defined");
|
|
1235
|
+
}
|
|
1236
|
+
return this.factory({
|
|
1237
|
+
...this.params,
|
|
1238
|
+
source: this.#source,
|
|
1239
|
+
polling: this.#polling ?? void 0,
|
|
1240
|
+
webhook: this.#webhook ?? void 0,
|
|
1241
|
+
routingMatchers: this.#routingMatchers
|
|
1242
|
+
});
|
|
1155
1243
|
}
|
|
1156
1244
|
};
|
|
1157
|
-
var
|
|
1245
|
+
var triggerGroup = (spec2, params) => SlateTriggerGroup.create(spec2, params);
|
|
1158
1246
|
|
|
1159
1247
|
// src/action/attachment.ts
|
|
1160
1248
|
var createUrlAttachment = (url, opts = {}) => {
|
|
@@ -2581,14 +2669,16 @@ var setIfDefined = (target, key, value) => {
|
|
|
2581
2669
|
|
|
2582
2670
|
// src/specification/slate.ts
|
|
2583
2671
|
var Slate = class _Slate {
|
|
2584
|
-
constructor(_spec, _actions, _adapters) {
|
|
2672
|
+
constructor(_spec, _actions, _adapters, _triggerGroups) {
|
|
2585
2673
|
this._spec = _spec;
|
|
2586
2674
|
this._actions = _actions;
|
|
2587
2675
|
this._adapters = _adapters;
|
|
2676
|
+
this._triggerGroups = _triggerGroups;
|
|
2588
2677
|
}
|
|
2589
2678
|
_spec;
|
|
2590
2679
|
_actions;
|
|
2591
2680
|
_adapters;
|
|
2681
|
+
_triggerGroups;
|
|
2592
2682
|
static create(params) {
|
|
2593
2683
|
let adapters = params.adapters ?? [];
|
|
2594
2684
|
let actions = [...params.triggers, ...params.tools];
|
|
@@ -2614,7 +2704,25 @@ var Slate = class _Slate {
|
|
|
2614
2704
|
}
|
|
2615
2705
|
}
|
|
2616
2706
|
}
|
|
2617
|
-
|
|
2707
|
+
let triggerGroups = params.triggerGroups ?? [];
|
|
2708
|
+
let seenTriggerGroupKeys = /* @__PURE__ */ new Set();
|
|
2709
|
+
for (let group of triggerGroups) {
|
|
2710
|
+
if (seenTriggerGroupKeys.has(group.key)) {
|
|
2711
|
+
throw new SlateDeclarationError(
|
|
2712
|
+
`Trigger group "${group.key}" is registered more than once`
|
|
2713
|
+
);
|
|
2714
|
+
}
|
|
2715
|
+
seenTriggerGroupKeys.add(group.key);
|
|
2716
|
+
}
|
|
2717
|
+
let manualWebhookTriggerGroups = triggerGroups.filter(
|
|
2718
|
+
(group) => group.source === "webhook" && group.webhook?.manualRegistration
|
|
2719
|
+
);
|
|
2720
|
+
if (manualWebhookTriggerGroups.length > 1) {
|
|
2721
|
+
throw new SlateDeclarationError(
|
|
2722
|
+
`Only one trigger group may use manual webhook registration, but found: ${manualWebhookTriggerGroups.map((group) => group.key).join(", ")}`
|
|
2723
|
+
);
|
|
2724
|
+
}
|
|
2725
|
+
return new _Slate(params.spec, actions, adapters, triggerGroups);
|
|
2618
2726
|
}
|
|
2619
2727
|
get spec() {
|
|
2620
2728
|
return this._spec;
|
|
@@ -2625,10 +2733,13 @@ var Slate = class _Slate {
|
|
|
2625
2733
|
get adapters() {
|
|
2626
2734
|
return this._adapters;
|
|
2627
2735
|
}
|
|
2736
|
+
get triggerGroups() {
|
|
2737
|
+
return this._triggerGroups;
|
|
2738
|
+
}
|
|
2628
2739
|
};
|
|
2629
2740
|
|
|
2630
2741
|
// src/specification/specification.ts
|
|
2631
|
-
import
|
|
2742
|
+
import z3 from "zod";
|
|
2632
2743
|
var SlateSpecification = class _SlateSpecification {
|
|
2633
2744
|
constructor(_config, _auth, _params) {
|
|
2634
2745
|
this._config = _config;
|
|
@@ -2645,7 +2756,7 @@ var SlateSpecification = class _SlateSpecification {
|
|
|
2645
2756
|
return this._config.configSchema;
|
|
2646
2757
|
}
|
|
2647
2758
|
get authSchema() {
|
|
2648
|
-
return "outputSchema" in this._auth ? this._auth.outputSchema :
|
|
2759
|
+
return "outputSchema" in this._auth ? this._auth.outputSchema : z3.object({});
|
|
2649
2760
|
}
|
|
2650
2761
|
get config() {
|
|
2651
2762
|
return this._config;
|
|
@@ -2744,6 +2855,8 @@ export {
|
|
|
2744
2855
|
SlateSpecification,
|
|
2745
2856
|
SlateTool,
|
|
2746
2857
|
SlateTrigger,
|
|
2858
|
+
SlateTriggerGroup,
|
|
2859
|
+
SlateTriggerGroupBuilder,
|
|
2747
2860
|
adapterSpec,
|
|
2748
2861
|
allOf,
|
|
2749
2862
|
anyOf,
|
|
@@ -2795,6 +2908,7 @@ export {
|
|
|
2795
2908
|
statusLabelForApiError,
|
|
2796
2909
|
tool,
|
|
2797
2910
|
trigger,
|
|
2911
|
+
triggerGroup,
|
|
2798
2912
|
uploadAttachmentDirect,
|
|
2799
2913
|
validateScopes,
|
|
2800
2914
|
verifyHmacSignature
|
package/package.json
CHANGED
package/src/action/action.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { SlateContext, SlatePublicContext } from '../context';
|
|
|
3
3
|
import type { SlateActionDocsReference } from '../docs';
|
|
4
4
|
import type { SlateSpecification } from '../specification/specification';
|
|
5
5
|
import type { SlateAttachment } from './attachment';
|
|
6
|
+
import type { SlateTriggerGroup } from './triggerGroup';
|
|
6
7
|
|
|
7
8
|
export type SlateActionType = 'tool' | 'trigger';
|
|
8
9
|
|
|
@@ -52,6 +53,8 @@ export type SlatePublicToolInvocationHandler<InputType extends {}, OutputType ex
|
|
|
52
53
|
attachments?: SlateAttachment[];
|
|
53
54
|
}>;
|
|
54
55
|
|
|
56
|
+
export type SlateTriggerMatchesHandler = (payload: unknown) => boolean;
|
|
57
|
+
|
|
55
58
|
export type SlateTriggerMappingHandler<
|
|
56
59
|
ConfigType extends {},
|
|
57
60
|
AuthType extends {},
|
|
@@ -63,88 +66,12 @@ export type SlateTriggerMappingHandler<
|
|
|
63
66
|
output: OutputType;
|
|
64
67
|
}>;
|
|
65
68
|
|
|
66
|
-
export type SlateTriggerPollingHandler<
|
|
67
|
-
ConfigType extends {},
|
|
68
|
-
AuthType extends {},
|
|
69
|
-
InputType extends {}
|
|
70
|
-
> = (context: SlateContext<ConfigType, AuthType, { state: any | null }>) => Promise<{
|
|
71
|
-
inputs: InputType[];
|
|
72
|
-
updatedState?: any;
|
|
73
|
-
}>;
|
|
74
|
-
|
|
75
69
|
export interface SlateWebhookHttpResponseInit {
|
|
76
70
|
status?: number;
|
|
77
71
|
headers?: Record<string, string>;
|
|
78
72
|
body?: string | Uint8Array | null;
|
|
79
73
|
}
|
|
80
74
|
|
|
81
|
-
export type SlateWebhookHttpMethod =
|
|
82
|
-
| 'GET'
|
|
83
|
-
| 'POST'
|
|
84
|
-
| 'PUT'
|
|
85
|
-
| 'PATCH'
|
|
86
|
-
| 'DELETE'
|
|
87
|
-
| 'HEAD'
|
|
88
|
-
| 'OPTIONS';
|
|
89
|
-
|
|
90
|
-
export interface SlateWebhookRequestMatcher {
|
|
91
|
-
method?: string;
|
|
92
|
-
hasQueryParam?: string;
|
|
93
|
-
hasHeader?: string;
|
|
94
|
-
jsonBodyField?: {
|
|
95
|
-
path: string;
|
|
96
|
-
equals?: string;
|
|
97
|
-
};
|
|
98
|
-
formBodyField?: {
|
|
99
|
-
path: string;
|
|
100
|
-
equals?: string;
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export interface SlateWebhookHttpOptions {
|
|
105
|
-
methods?: SlateWebhookHttpMethod[];
|
|
106
|
-
sync?: {
|
|
107
|
-
mode: 'never' | 'match' | 'always';
|
|
108
|
-
match?: SlateWebhookRequestMatcher[];
|
|
109
|
-
timeoutMs?: number;
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export type SlateTriggerWebhookRequestHandler<
|
|
114
|
-
ConfigType extends {},
|
|
115
|
-
AuthType extends {},
|
|
116
|
-
InputType extends {}
|
|
117
|
-
> = (
|
|
118
|
-
context: SlateContext<
|
|
119
|
-
ConfigType,
|
|
120
|
-
AuthType,
|
|
121
|
-
{ request: Request; state: any | null; registrationDetails: any | null }
|
|
122
|
-
>
|
|
123
|
-
) => Promise<{
|
|
124
|
-
inputs: InputType[];
|
|
125
|
-
updatedState?: any;
|
|
126
|
-
response?: Response | SlateWebhookHttpResponseInit;
|
|
127
|
-
}>;
|
|
128
|
-
|
|
129
|
-
export type SlateTriggerWebhookAutoRegistrationHandler<
|
|
130
|
-
ConfigType extends {},
|
|
131
|
-
AuthType extends {}
|
|
132
|
-
> = (context: SlateContext<ConfigType, AuthType, { webhookBaseUrl: string }>) => Promise<{
|
|
133
|
-
registrationDetails: any;
|
|
134
|
-
state?: any;
|
|
135
|
-
}>;
|
|
136
|
-
|
|
137
|
-
export type SlateTriggerWebhookAutoUnregistrationHandler<
|
|
138
|
-
ConfigType extends {},
|
|
139
|
-
AuthType extends {}
|
|
140
|
-
> = (
|
|
141
|
-
context: SlateContext<
|
|
142
|
-
ConfigType,
|
|
143
|
-
AuthType,
|
|
144
|
-
{ webhookBaseUrl: string; registrationDetails: any; state: any | null }
|
|
145
|
-
>
|
|
146
|
-
) => Promise<unknown>;
|
|
147
|
-
|
|
148
75
|
export interface SlateActionParametersTool<
|
|
149
76
|
ConfigType extends {},
|
|
150
77
|
AuthType extends {},
|
|
@@ -155,10 +82,6 @@ export interface SlateActionParametersTool<
|
|
|
155
82
|
handleInvocation: SlateToolInvocationHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
156
83
|
}
|
|
157
84
|
|
|
158
|
-
export interface SlatePollingOptions {
|
|
159
|
-
intervalInSeconds?: number;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
85
|
export interface SlateActionParametersTrigger<
|
|
163
86
|
ConfigType extends {},
|
|
164
87
|
AuthType extends {},
|
|
@@ -166,14 +89,9 @@ export interface SlateActionParametersTrigger<
|
|
|
166
89
|
OutputType extends {}
|
|
167
90
|
> {
|
|
168
91
|
type: 'trigger';
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
handleRequest?: SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType>;
|
|
173
|
-
http?: SlateWebhookHttpOptions;
|
|
174
|
-
pollEvents?: SlateTriggerPollingHandler<ConfigType, AuthType, InputType>;
|
|
175
|
-
autoRegisterWebhook?: SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType>;
|
|
176
|
-
autoUnregisterWebhook?: SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType>;
|
|
92
|
+
triggerGroup: SlateTriggerGroup<ConfigType, AuthType>;
|
|
93
|
+
matches: SlateTriggerMatchesHandler;
|
|
94
|
+
map: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
177
95
|
}
|
|
178
96
|
|
|
179
97
|
export type SlateActionParametersAny<
|
package/src/action/builder.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
#
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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('
|
|
164
|
+
throw new SlateDeclarationError('triggerGroup can only be set for trigger actions');
|
|
175
165
|
}
|
|
176
166
|
|
|
177
|
-
this.#
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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('
|
|
175
|
+
throw new SlateDeclarationError('matches can only be set for trigger actions');
|
|
197
176
|
}
|
|
198
177
|
|
|
199
|
-
this.#
|
|
200
|
-
|
|
201
|
-
|
|
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.#
|
|
231
|
-
throw new SlateDeclarationError('Trigger
|
|
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
|
-
...
|
|
249
|
+
...(triggerParams as any)!
|
|
246
250
|
}) as Result;
|
|
247
251
|
}
|
|
248
252
|
}
|
package/src/action/index.ts
CHANGED