@slates/provider 1.0.0-rc.17 → 1.0.0-rc.18

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
@@ -32,6 +32,9 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  Slate: () => Slate,
34
34
  SlateAction: () => SlateAction,
35
+ SlateActionBuilder: () => SlateActionBuilder,
36
+ SlateAdapter: () => SlateAdapter,
37
+ SlateAdapterSpec: () => SlateAdapterSpec,
35
38
  SlateAuth: () => SlateAuth,
36
39
  SlateConfig: () => SlateConfig,
37
40
  SlateContext: () => SlateContext,
@@ -39,9 +42,12 @@ __export(index_exports, {
39
42
  SlateDefaultPollingIntervalSeconds: () => SlateDefaultPollingIntervalSeconds,
40
43
  SlateError: () => SlateError,
41
44
  SlateLogger: () => SlateLogger,
45
+ SlatePublicContext: () => SlatePublicContext,
46
+ SlatePublicTool: () => SlatePublicTool,
42
47
  SlateSpecification: () => SlateSpecification,
43
48
  SlateTool: () => SlateTool,
44
49
  SlateTrigger: () => SlateTrigger,
50
+ adapterSpec: () => adapterSpec,
45
51
  allOf: () => allOf,
46
52
  anyOf: () => anyOf,
47
53
  auth: () => auth,
@@ -78,6 +84,7 @@ __export(index_exports, {
78
84
  metaWebhookHttp: () => metaWebhookHttp,
79
85
  normalizeOAuthTokenResponse: () => normalizeOAuthTokenResponse,
80
86
  pickDefined: () => pickDefined,
87
+ publicTool: () => publicTool,
81
88
  requestAxios: () => requestAxios,
82
89
  requestAxiosData: () => requestAxiosData,
83
90
  runWithContext: () => runWithContext,
@@ -148,6 +155,12 @@ var SlateAction = class {
148
155
  get docs() {
149
156
  return this._params.docs;
150
157
  }
158
+ get adapter() {
159
+ return this._params.adapter ?? null;
160
+ }
161
+ get isPublic() {
162
+ return this._params.isPublic === true;
163
+ }
151
164
  };
152
165
 
153
166
  // src/error/api.ts
@@ -892,11 +905,12 @@ var isScopes = (value) => typeof value === "object" && value !== null && "AND" i
892
905
 
893
906
  // src/action/builder.ts
894
907
  var SlateActionBuilder = class {
895
- constructor(type, spec2, params, factory) {
908
+ constructor(type, spec2, params, factory, isPublicTool = false) {
896
909
  this.type = type;
897
910
  this.spec = spec2;
898
911
  this.params = params;
899
912
  this.factory = factory;
913
+ this.isPublicTool = isPublicTool;
900
914
  this.#configSchema = spec2.configSchema;
901
915
  this.#authSchema = spec2.authSchema;
902
916
  }
@@ -904,6 +918,7 @@ var SlateActionBuilder = class {
904
918
  spec;
905
919
  params;
906
920
  factory;
921
+ isPublicTool;
907
922
  #configSchema;
908
923
  #authSchema;
909
924
  #inputSchema = null;
@@ -912,20 +927,34 @@ var SlateActionBuilder = class {
912
927
  #authMethods;
913
928
  #toolParams = null;
914
929
  #triggerParams = null;
930
+ #interfaceLocked = false;
915
931
  input(schema) {
932
+ if (this.#interfaceLocked) {
933
+ throw new SlateDeclarationError("Adapter contract input schema cannot be changed");
934
+ }
916
935
  this.#inputSchema = schema;
917
936
  return this;
918
937
  }
919
938
  output(schema) {
939
+ if (this.#interfaceLocked) {
940
+ throw new SlateDeclarationError("Adapter contract output schema cannot be changed");
941
+ }
920
942
  this.#outputSchema = schema;
921
943
  return this;
922
944
  }
945
+ lockInterface() {
946
+ this.#interfaceLocked = true;
947
+ return this;
948
+ }
923
949
  scopes(scopes) {
924
950
  validateScopes(scopes);
925
951
  this.#scopes = scopes;
926
952
  return this;
927
953
  }
928
954
  authMethods(authMethods) {
955
+ if (this.isPublicTool) {
956
+ throw new SlateDeclarationError("Public tools cannot require authentication methods");
957
+ }
929
958
  this.#authMethods = this.validateAuthMethods(authMethods);
930
959
  return this;
931
960
  }
@@ -981,6 +1010,9 @@ var SlateActionBuilder = class {
981
1010
  validateScopes(scopes);
982
1011
  }
983
1012
  let authMethods = this.validateAuthMethods(this.#authMethods ?? this.params.authMethods);
1013
+ if (this.isPublicTool && authMethods) {
1014
+ throw new SlateDeclarationError("Public tools cannot require authentication methods");
1015
+ }
984
1016
  if (!this.#inputSchema) {
985
1017
  throw new SlateDeclarationError("Input schema is not defined");
986
1018
  }
@@ -997,6 +1029,7 @@ var SlateActionBuilder = class {
997
1029
  ...this.params,
998
1030
  scopes,
999
1031
  authMethods,
1032
+ isPublic: this.isPublicTool === true,
1000
1033
  configSchema: this.#configSchema,
1001
1034
  authSchema: this.#authSchema,
1002
1035
  inputSchema: this.#inputSchema,
@@ -1016,16 +1049,40 @@ var SlateTool = class _SlateTool extends SlateAction {
1016
1049
  }
1017
1050
  static create(spec2, params) {
1018
1051
  return new SlateActionBuilder("tool", spec2, params, (params2) => {
1019
- if (params2.type !== "tool") throw new Error("Invalid action type for tool");
1020
- return new _SlateTool(spec2, params2.inputSchema, params2.outputSchema, params2);
1052
+ return _SlateTool.fromCreateParameters(spec2, params2);
1021
1053
  });
1022
1054
  }
1055
+ static fromCreateParameters(spec2, params) {
1056
+ if (params.type !== "tool") throw new Error("Invalid action type for tool");
1057
+ return new _SlateTool(spec2, params.inputSchema, params.outputSchema, params);
1058
+ }
1023
1059
  get handleInvocation() {
1024
1060
  return this.#handleInvocation;
1025
1061
  }
1026
1062
  };
1027
1063
  var tool = (spec2, params) => SlateTool.create(spec2, params);
1028
1064
 
1065
+ // src/action/publicTool.ts
1066
+ var SlatePublicTool = class {
1067
+ constructor() {
1068
+ }
1069
+ static create(spec2, params) {
1070
+ return new SlateActionBuilder(
1071
+ "tool",
1072
+ spec2,
1073
+ params,
1074
+ (params2) => {
1075
+ return SlateTool.fromCreateParameters(spec2, {
1076
+ ...params2,
1077
+ isPublic: true
1078
+ });
1079
+ },
1080
+ true
1081
+ );
1082
+ }
1083
+ };
1084
+ var publicTool = (spec2, params) => SlatePublicTool.create(spec2, params);
1085
+
1029
1086
  // src/action/trigger.ts
1030
1087
  var SlateDefaultPollingIntervalSeconds = 60 * 10;
1031
1088
  var SlateTrigger = class _SlateTrigger extends SlateAction {
@@ -1108,6 +1165,135 @@ var createTextAttachment = (content, mimeType) => ({
1108
1165
  }
1109
1166
  });
1110
1167
 
1168
+ // src/adapter/adapter.ts
1169
+ var SlateAdapter = class {
1170
+ constructor(_spec, _tools, _triggers) {
1171
+ this._spec = _spec;
1172
+ this._tools = _tools;
1173
+ this._triggers = _triggers;
1174
+ }
1175
+ _spec;
1176
+ _tools;
1177
+ _triggers;
1178
+ get spec() {
1179
+ return this._spec;
1180
+ }
1181
+ get id() {
1182
+ return this._spec.id;
1183
+ }
1184
+ get name() {
1185
+ return this._spec.name;
1186
+ }
1187
+ get capabilities() {
1188
+ return this._spec.capabilities;
1189
+ }
1190
+ get tools() {
1191
+ return this._tools;
1192
+ }
1193
+ get triggers() {
1194
+ return this._triggers;
1195
+ }
1196
+ get actions() {
1197
+ return [...this._triggers, ...this._tools];
1198
+ }
1199
+ };
1200
+
1201
+ // src/adapter/spec.ts
1202
+ var SlateAdapterSpec = class _SlateAdapterSpec {
1203
+ constructor(_params) {
1204
+ this._params = _params;
1205
+ }
1206
+ _params;
1207
+ static create(params) {
1208
+ let id = params.id?.trim();
1209
+ let name = params.name?.trim();
1210
+ if (!id) {
1211
+ throw new SlateDeclarationError("Adapter id must be a non-empty string");
1212
+ }
1213
+ if (!name) {
1214
+ throw new SlateDeclarationError("Adapter name must be a non-empty string");
1215
+ }
1216
+ return new _SlateAdapterSpec({
1217
+ id,
1218
+ name,
1219
+ capabilities: validateCapabilities(params.capabilities ?? [])
1220
+ });
1221
+ }
1222
+ get id() {
1223
+ return this._params.id;
1224
+ }
1225
+ get name() {
1226
+ return this._params.name;
1227
+ }
1228
+ get capabilities() {
1229
+ return this._params.capabilities;
1230
+ }
1231
+ get parameters() {
1232
+ return this._params;
1233
+ }
1234
+ tool(spec2, params) {
1235
+ return SlateTool.create(spec2, this.linkAction(params));
1236
+ }
1237
+ publicTool(spec2, params) {
1238
+ return SlatePublicTool.create(spec2, this.linkAction(params));
1239
+ }
1240
+ trigger(spec2, params) {
1241
+ return SlateTrigger.create(spec2, this.linkAction(params));
1242
+ }
1243
+ register(params) {
1244
+ let actions = [...params.tools, ...params.triggers];
1245
+ let seenKeys = /* @__PURE__ */ new Set();
1246
+ for (let action of actions) {
1247
+ if (action.adapter && action.adapter !== this.id) {
1248
+ throw new SlateDeclarationError(
1249
+ `Action "${action.key}" is linked to adapter "${action.adapter}", not "${this.id}"`
1250
+ );
1251
+ }
1252
+ if (!action.adapter) {
1253
+ throw new SlateDeclarationError(
1254
+ `Action "${action.key}" must be created with this adapter's tool(), publicTool(), or trigger() helpers`
1255
+ );
1256
+ }
1257
+ if (seenKeys.has(action.key)) {
1258
+ throw new SlateDeclarationError(
1259
+ `Adapter "${this.id}" already has an action with key "${action.key}"`
1260
+ );
1261
+ }
1262
+ seenKeys.add(action.key);
1263
+ }
1264
+ return new SlateAdapter(this, params.tools, params.triggers);
1265
+ }
1266
+ linkAction(params) {
1267
+ if (params.adapter != null && params.adapter !== this.id) {
1268
+ throw new SlateDeclarationError(
1269
+ `Action "${params.key}" cannot be linked to adapter "${this.id}" because it is already linked to "${params.adapter}"`
1270
+ );
1271
+ }
1272
+ return {
1273
+ ...params,
1274
+ adapter: this.id
1275
+ };
1276
+ }
1277
+ };
1278
+ var adapterSpec = (params) => SlateAdapterSpec.create(params);
1279
+ var validateCapabilities = (capabilities) => {
1280
+ let seenIds = /* @__PURE__ */ new Set();
1281
+ return capabilities.map((capability) => {
1282
+ let id = capability.id?.trim();
1283
+ if (!id) {
1284
+ throw new SlateDeclarationError("Adapter capability ids must be non-empty strings");
1285
+ }
1286
+ if (seenIds.has(id)) {
1287
+ throw new SlateDeclarationError(`Adapter capability "${id}" is defined more than once`);
1288
+ }
1289
+ seenIds.add(id);
1290
+ return {
1291
+ id,
1292
+ value: capability.value
1293
+ };
1294
+ });
1295
+ };
1296
+
1111
1297
  // src/auth/auth.ts
1112
1298
  var SlateAuth = class _SlateAuth {
1113
1299
  #outputSchema = null;
@@ -1907,26 +2093,19 @@ var SlateConfig = class _SlateConfig {
1907
2093
  var config = (schema) => SlateConfig.create(schema);
1908
2094
 
1909
2095
  // src/context/context.ts
1910
- var SlateContext = class {
1911
- constructor(config2, input, auth2, spec2, logger) {
2096
+ var SlatePublicContext = class {
2097
+ constructor(input, spec2, logger) {
1912
2098
  this.spec = spec2;
1913
2099
  this.logger = logger;
1914
- this.#config = config2;
1915
2100
  this.#input = input;
1916
- this.#auth = auth2;
1917
2101
  }
1918
2102
  spec;
1919
2103
  logger;
1920
- #config;
1921
2104
  #input;
1922
- #auth;
1923
2105
  #httpTraces = [];
1924
2106
  get specification() {
1925
2107
  return this.spec;
1926
2108
  }
1927
- get config() {
1928
- return Object.freeze(this.#config);
1929
- }
1930
2109
  get input() {
1931
2110
  return Object.freeze(this.#input);
1932
2111
  }
@@ -1944,9 +2123,6 @@ var SlateContext = class {
1944
2123
  this.#input.registrationDetails
1945
2124
  );
1946
2125
  }
1947
- get auth() {
1948
- return Object.freeze(this.#auth);
1949
- }
1950
2126
  recordHttpTrace(trace) {
1951
2127
  this.#httpTraces.push(trace);
1952
2128
  }
@@ -1981,6 +2157,21 @@ var SlateContext = class {
1981
2157
  this.logger.progress(message);
1982
2158
  }
1983
2159
  };
2160
+ var SlateContext = class extends SlatePublicContext {
2161
+ #config;
2162
+ #auth;
2163
+ constructor(config2, input, auth2, spec2, logger) {
2164
+ super(input, spec2, logger);
2165
+ this.#config = config2;
2166
+ this.#auth = auth2;
2167
+ }
2168
+ get config() {
2169
+ return Object.freeze(this.#config);
2170
+ }
2171
+ get auth() {
2172
+ return Object.freeze(this.#auth);
2173
+ }
2174
+ };
1984
2175
 
1985
2176
  // src/crypto/hmac.ts
1986
2177
  var import_crypto = require("crypto");
@@ -2129,14 +2320,40 @@ var setIfDefined = (target, key, value) => {
2129
2320
 
2130
2321
  // src/specification/slate.ts
2131
2322
  var Slate = class _Slate {
2132
- constructor(_spec, _actions) {
2323
+ constructor(_spec, _actions, _adapters) {
2133
2324
  this._spec = _spec;
2134
2325
  this._actions = _actions;
2326
+ this._adapters = _adapters;
2135
2327
  }
2136
2328
  _spec;
2137
2329
  _actions;
2330
+ _adapters;
2138
2331
  static create(params) {
2139
- return new _Slate(params.spec, [...params.triggers, ...params.tools]);
2332
+ let adapters = params.adapters ?? [];
2333
+ let actions = [...params.triggers, ...params.tools];
2334
+ let seenAdapterIds = /* @__PURE__ */ new Set();
2335
+ let seenActionKeys = new Map(actions.map((action) => [action.key, action]));
2336
+ for (let adapter of adapters) {
2337
+ if (seenAdapterIds.has(adapter.id)) {
2338
+ throw new SlateDeclarationError(
2339
+ `Adapter "${adapter.id}" is registered more than once`
2340
+ );
2341
+ }
2342
+ seenAdapterIds.add(adapter.id);
2343
+ for (let action of adapter.actions) {
2344
+ let existing = seenActionKeys.get(action.key);
2345
+ if (existing && existing !== action) {
2346
+ throw new SlateDeclarationError(
2347
+ `Adapter "${adapter.id}" action "${action.key}" conflicts with another action`
2348
+ );
2349
+ }
2350
+ if (!existing) {
2351
+ actions.push(action);
2352
+ seenActionKeys.set(action.key, action);
2353
+ }
2354
+ }
2355
+ }
2356
+ return new _Slate(params.spec, actions, adapters);
2140
2357
  }
2141
2358
  get spec() {
2142
2359
  return this._spec;
@@ -2144,6 +2361,9 @@ var Slate = class _Slate {
2144
2361
  get actions() {
2145
2362
  return this._actions;
2146
2363
  }
2364
+ get adapters() {
2365
+ return this._adapters;
2366
+ }
2147
2367
  };
2148
2368
 
2149
2369
  // src/specification/specification.ts
@@ -2246,6 +2466,9 @@ var getMetaWebhookVerificationResponse = (request, expectedVerifyToken) => {
2246
2466
  0 && (module.exports = {
2247
2467
  Slate,
2248
2468
  SlateAction,
2469
+ SlateActionBuilder,
2470
+ SlateAdapter,
2471
+ SlateAdapterSpec,
2249
2472
  SlateAuth,
2250
2473
  SlateConfig,
2251
2474
  SlateContext,
@@ -2253,9 +2476,12 @@ var getMetaWebhookVerificationResponse = (request, expectedVerifyToken) => {
2253
2476
  SlateDefaultPollingIntervalSeconds,
2254
2477
  SlateError,
2255
2478
  SlateLogger,
2479
+ SlatePublicContext,
2480
+ SlatePublicTool,
2256
2481
  SlateSpecification,
2257
2482
  SlateTool,
2258
2483
  SlateTrigger,
2484
+ adapterSpec,
2259
2485
  allOf,
2260
2486
  anyOf,
2261
2487
  auth,
@@ -2292,6 +2518,7 @@ var getMetaWebhookVerificationResponse = (request, expectedVerifyToken) => {
2292
2518
  metaWebhookHttp,
2293
2519
  normalizeOAuthTokenResponse,
2294
2520
  pickDefined,
2521
+ publicTool,
2295
2522
  requestAxios,
2296
2523
  requestAxiosData,
2297
2524
  runWithContext,