@slates/provider 1.0.0-rc.22 → 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.
- package/dist/index.cjs +174 -61
- package/dist/index.d.cts +154 -96
- package/dist/index.d.ts +154 -96
- package/dist/index.module.js +171 -61
- 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 +296 -0
- package/src/adapter/index.test.ts +35 -14
- package/src/module/resolveDefaultExport.test.ts +3 -3
- package/src/specification/slate.test.ts +102 -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,122 @@ 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
|
+
var SlateDefaultPollingIntervalSeconds = 60 * 10;
|
|
1140
|
+
var SlateTriggerGroup = class _SlateTriggerGroup {
|
|
1141
|
+
constructor(_spec, _params) {
|
|
1142
|
+
this._spec = _spec;
|
|
1143
|
+
this._params = _params;
|
|
1144
|
+
}
|
|
1145
|
+
_spec;
|
|
1146
|
+
_params;
|
|
1147
|
+
static create(spec2, params) {
|
|
1148
|
+
return new SlateTriggerGroupBuilder(spec2, params, (p) => new _SlateTriggerGroup(spec2, p));
|
|
1149
|
+
}
|
|
1150
|
+
get spec() {
|
|
1151
|
+
return this._spec;
|
|
1152
|
+
}
|
|
1153
|
+
get key() {
|
|
1154
|
+
return this._params.key;
|
|
1155
|
+
}
|
|
1156
|
+
get name() {
|
|
1157
|
+
return this._params.name;
|
|
1158
|
+
}
|
|
1159
|
+
get description() {
|
|
1160
|
+
return this._params.description;
|
|
1161
|
+
}
|
|
1162
|
+
get metadata() {
|
|
1163
|
+
return this._params.metadata;
|
|
1134
1164
|
}
|
|
1135
1165
|
get source() {
|
|
1136
|
-
return this
|
|
1166
|
+
return this._params.source;
|
|
1137
1167
|
}
|
|
1138
|
-
get
|
|
1139
|
-
return this
|
|
1168
|
+
get polling() {
|
|
1169
|
+
return this._params.polling;
|
|
1140
1170
|
}
|
|
1141
|
-
get
|
|
1142
|
-
return this
|
|
1171
|
+
get webhook() {
|
|
1172
|
+
return this._params.webhook;
|
|
1143
1173
|
}
|
|
1144
|
-
get
|
|
1145
|
-
return this
|
|
1174
|
+
get routingMatchers() {
|
|
1175
|
+
return this._params.routingMatchers;
|
|
1146
1176
|
}
|
|
1147
|
-
|
|
1148
|
-
|
|
1177
|
+
};
|
|
1178
|
+
var SlateTriggerGroupBuilder = class {
|
|
1179
|
+
constructor(spec2, params, factory) {
|
|
1180
|
+
this.spec = spec2;
|
|
1181
|
+
this.params = params;
|
|
1182
|
+
this.factory = factory;
|
|
1183
|
+
}
|
|
1184
|
+
spec;
|
|
1185
|
+
params;
|
|
1186
|
+
factory;
|
|
1187
|
+
#source = null;
|
|
1188
|
+
#polling = null;
|
|
1189
|
+
#webhook = null;
|
|
1190
|
+
#routingMatchers = null;
|
|
1191
|
+
polling(props) {
|
|
1192
|
+
if (this.#source) {
|
|
1193
|
+
throw new SlateDeclarationError("Trigger group invocation is already defined");
|
|
1194
|
+
}
|
|
1195
|
+
this.#source = "polling";
|
|
1196
|
+
this.#polling = {
|
|
1197
|
+
intervalSeconds: props.intervalSeconds ?? SlateDefaultPollingIntervalSeconds,
|
|
1198
|
+
pollEvents: props.pollEvents
|
|
1199
|
+
};
|
|
1200
|
+
return this;
|
|
1201
|
+
}
|
|
1202
|
+
webhook(props) {
|
|
1203
|
+
if (this.#source) {
|
|
1204
|
+
throw new SlateDeclarationError("Trigger group invocation is already defined");
|
|
1205
|
+
}
|
|
1206
|
+
if (!!props.autoRegistration === !!props.manualRegistration) {
|
|
1207
|
+
throw new SlateDeclarationError(
|
|
1208
|
+
"Webhook trigger groups require exactly one of autoRegistration or manualRegistration"
|
|
1209
|
+
);
|
|
1210
|
+
}
|
|
1211
|
+
this.#source = "webhook";
|
|
1212
|
+
this.#webhook = {
|
|
1213
|
+
autoRegistration: props.autoRegistration,
|
|
1214
|
+
manualRegistration: props.manualRegistration,
|
|
1215
|
+
process: props.process
|
|
1216
|
+
};
|
|
1217
|
+
return this;
|
|
1149
1218
|
}
|
|
1150
|
-
|
|
1151
|
-
|
|
1219
|
+
routingMatchers(handler) {
|
|
1220
|
+
this.#routingMatchers = handler;
|
|
1221
|
+
return this;
|
|
1152
1222
|
}
|
|
1153
|
-
|
|
1154
|
-
|
|
1223
|
+
build() {
|
|
1224
|
+
if (!this.#source) {
|
|
1225
|
+
throw new SlateDeclarationError(
|
|
1226
|
+
"Trigger group invocation (polling or webhook) is not defined"
|
|
1227
|
+
);
|
|
1228
|
+
}
|
|
1229
|
+
if (!this.#routingMatchers) {
|
|
1230
|
+
throw new SlateDeclarationError("Trigger group routing matchers handler is not defined");
|
|
1231
|
+
}
|
|
1232
|
+
return this.factory({
|
|
1233
|
+
...this.params,
|
|
1234
|
+
source: this.#source,
|
|
1235
|
+
polling: this.#polling ?? void 0,
|
|
1236
|
+
webhook: this.#webhook ?? void 0,
|
|
1237
|
+
routingMatchers: this.#routingMatchers
|
|
1238
|
+
});
|
|
1155
1239
|
}
|
|
1156
1240
|
};
|
|
1157
|
-
var
|
|
1241
|
+
var triggerGroup = (spec2, params) => SlateTriggerGroup.create(spec2, params);
|
|
1158
1242
|
|
|
1159
1243
|
// src/action/attachment.ts
|
|
1160
1244
|
var createUrlAttachment = (url, opts = {}) => {
|
|
@@ -2581,14 +2665,16 @@ var setIfDefined = (target, key, value) => {
|
|
|
2581
2665
|
|
|
2582
2666
|
// src/specification/slate.ts
|
|
2583
2667
|
var Slate = class _Slate {
|
|
2584
|
-
constructor(_spec, _actions, _adapters) {
|
|
2668
|
+
constructor(_spec, _actions, _adapters, _triggerGroups) {
|
|
2585
2669
|
this._spec = _spec;
|
|
2586
2670
|
this._actions = _actions;
|
|
2587
2671
|
this._adapters = _adapters;
|
|
2672
|
+
this._triggerGroups = _triggerGroups;
|
|
2588
2673
|
}
|
|
2589
2674
|
_spec;
|
|
2590
2675
|
_actions;
|
|
2591
2676
|
_adapters;
|
|
2677
|
+
_triggerGroups;
|
|
2592
2678
|
static create(params) {
|
|
2593
2679
|
let adapters = params.adapters ?? [];
|
|
2594
2680
|
let actions = [...params.triggers, ...params.tools];
|
|
@@ -2614,7 +2700,25 @@ var Slate = class _Slate {
|
|
|
2614
2700
|
}
|
|
2615
2701
|
}
|
|
2616
2702
|
}
|
|
2617
|
-
|
|
2703
|
+
let triggerGroups = params.triggerGroups ?? [];
|
|
2704
|
+
let seenTriggerGroupKeys = /* @__PURE__ */ new Set();
|
|
2705
|
+
for (let group of triggerGroups) {
|
|
2706
|
+
if (seenTriggerGroupKeys.has(group.key)) {
|
|
2707
|
+
throw new SlateDeclarationError(
|
|
2708
|
+
`Trigger group "${group.key}" is registered more than once`
|
|
2709
|
+
);
|
|
2710
|
+
}
|
|
2711
|
+
seenTriggerGroupKeys.add(group.key);
|
|
2712
|
+
}
|
|
2713
|
+
let manualWebhookTriggerGroups = triggerGroups.filter(
|
|
2714
|
+
(group) => group.source === "webhook" && group.webhook?.manualRegistration
|
|
2715
|
+
);
|
|
2716
|
+
if (manualWebhookTriggerGroups.length > 1) {
|
|
2717
|
+
throw new SlateDeclarationError(
|
|
2718
|
+
`Only one trigger group may use manual webhook registration, but found: ${manualWebhookTriggerGroups.map((group) => group.key).join(", ")}`
|
|
2719
|
+
);
|
|
2720
|
+
}
|
|
2721
|
+
return new _Slate(params.spec, actions, adapters, triggerGroups);
|
|
2618
2722
|
}
|
|
2619
2723
|
get spec() {
|
|
2620
2724
|
return this._spec;
|
|
@@ -2625,6 +2729,9 @@ var Slate = class _Slate {
|
|
|
2625
2729
|
get adapters() {
|
|
2626
2730
|
return this._adapters;
|
|
2627
2731
|
}
|
|
2732
|
+
get triggerGroups() {
|
|
2733
|
+
return this._triggerGroups;
|
|
2734
|
+
}
|
|
2628
2735
|
};
|
|
2629
2736
|
|
|
2630
2737
|
// src/specification/specification.ts
|
|
@@ -2744,6 +2851,8 @@ export {
|
|
|
2744
2851
|
SlateSpecification,
|
|
2745
2852
|
SlateTool,
|
|
2746
2853
|
SlateTrigger,
|
|
2854
|
+
SlateTriggerGroup,
|
|
2855
|
+
SlateTriggerGroupBuilder,
|
|
2747
2856
|
adapterSpec,
|
|
2748
2857
|
allOf,
|
|
2749
2858
|
anyOf,
|
|
@@ -2795,6 +2904,7 @@ export {
|
|
|
2795
2904
|
statusLabelForApiError,
|
|
2796
2905
|
tool,
|
|
2797
2906
|
trigger,
|
|
2907
|
+
triggerGroup,
|
|
2798
2908
|
uploadAttachmentDirect,
|
|
2799
2909
|
validateScopes,
|
|
2800
2910
|
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