@slates/provider-handler 1.0.0-rc.3 → 1.0.0-rc.31
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 +1462 -2
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.module.js +1439 -2
- package/package.json +12 -11
- package/src/attachments.test.ts +171 -0
- package/src/index.ts +1054 -136
- package/src/pQueue.test.ts +18 -0
- package/src/pQueue.ts +18 -0
- package/src/spec.ts +130 -21
- package/src/validation.ts +1 -1
- package/src/webhook.test.ts +65 -0
- package/src/webhook.ts +69 -0
- package/dist/action/action.d.ts +0 -90
- package/dist/action/action.d.ts.map +0 -1
- package/dist/action/builder.d.ts +0 -27
- package/dist/action/builder.d.ts.map +0 -1
- package/dist/action/index.d.ts +0 -5
- package/dist/action/index.d.ts.map +0 -1
- package/dist/action/tool.d.ts +0 -11
- package/dist/action/tool.d.ts.map +0 -1
- package/dist/action/trigger.d.ts +0 -14
- package/dist/action/trigger.d.ts.map +0 -1
- package/dist/auth/auth.d.ts +0 -26
- package/dist/auth/auth.d.ts.map +0 -1
- package/dist/auth/index.d.ts +0 -3
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/types.d.ts +0 -148
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/axios/index.d.ts +0 -4
- package/dist/axios/index.d.ts.map +0 -1
- package/dist/config/config.d.ts +0 -22
- package/dist/config/config.d.ts.map +0 -1
- package/dist/config/index.d.ts +0 -2
- package/dist/config/index.d.ts.map +0 -1
- package/dist/context/context.d.ts +0 -20
- package/dist/context/context.d.ts.map +0 -1
- package/dist/context/hook.d.ts +0 -4
- package/dist/context/hook.d.ts.map +0 -1
- package/dist/context/index.d.ts +0 -2
- package/dist/context/index.d.ts.map +0 -1
- package/dist/error/base.d.ts +0 -5
- package/dist/error/base.d.ts.map +0 -1
- package/dist/error/declaration.d.ts +0 -6
- package/dist/error/declaration.d.ts.map +0 -1
- package/dist/error/index.d.ts +0 -3
- package/dist/error/index.d.ts.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.modern.js +0 -2
- package/dist/index.modern.js.map +0 -1
- package/dist/index.module.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
- package/dist/spec.d.ts +0 -14
- package/dist/spec.d.ts.map +0 -1
- package/dist/specification/index.d.ts +0 -3
- package/dist/specification/index.d.ts.map +0 -1
- package/dist/specification/slate.d.ts +0 -15
- package/dist/specification/slate.d.ts.map +0 -1
- package/dist/specification/specification.d.ts +0 -30
- package/dist/specification/specification.d.ts.map +0 -1
- package/dist/specification/zero.d.ts +0 -13
- package/dist/specification/zero.d.ts.map +0 -1
- package/dist/state.d.ts +0 -8
- package/dist/state.d.ts.map +0 -1
- package/dist/tokens.d.ts +0 -34
- package/dist/tokens.d.ts.map +0 -1
- package/dist/validation.d.ts +0 -5
- package/dist/validation.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,1462 @@
|
|
|
1
|
-
var e=require("@lowerdeck/error"),t=require("@slates/proto"),r=require("@slates/provider");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=/*#__PURE__*/n(require("zod"));function i(e,t){if(!{}.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var a=0;function u(e){return"__private_"+a+++"_"+e}function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},s.apply(null,arguments)}function c(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}var l=function(t,r,n,o){var i=t.safeParse(r);if(!i.success)throw new e.ServiceError(function(t,r,n){return e.validationError({message:r,entity:t,errors:n.issues.map(function(e){return s({},e,{path:e.path.map(function(e){return String(e)})})})})}(n,o,i.error));return i.data},p=function(e){return e.toJSONSchema({unrepresentable:"any",override:function(e){var t=e.zodSchema._zod.def;"date"===t.type&&(e.jsonSchema.type="string",e.jsonSchema.format="date-time"),"bigint"===t.type&&(e.jsonSchema.type="number")}})},h=function(t,r){var n=t.spec.auth.authStack.find(function(e){return e.key==r});if(!n)throw new e.ServiceError(e.badRequestError({message:"Invalid authentication method ID: "+r}));return n},d=function(e,t){var r;return{id:t.key,name:t.name,type:t.type,scopes:"scopes"in t?t.scopes.map(function(e){return{id:e.scope,title:e.title,description:e.description}}):void 0,inputSchema:p(null!=(r=t.inputSchema)?r:o.default.object({})),outputSchema:p(e.spec.auth.outputSchema),capabilities:{getDefaultInput:{enabled:!(!("getDefaultInput"in t)||!t.getDefaultInput)},handleTokenRefresh:{enabled:!(!("handleTokenRefresh"in t)||!t.handleTokenRefresh)},handleChangedInput:{enabled:!!t.onInputChanged},getProfile:{enabled:!!t.getProfile}}}},f=function(t,r){var n=t.actions.find(function(e){return e.key==r});if(!n)throw new e.ServiceError(e.notFoundError("action",r));return n},v=function(t,r,n){var o=f(t,n);if(o.type!=r)throw new e.ServiceError(e.badRequestError({message:"Action with ID "+n+" is not of type "+r}));return o},m=function(e,t){var n;return s({},{id:t.key,name:t.name,description:t.description,instructions:t.instructions,constraints:t.constraints,tags:t.tags,metadata:t.metadata,inputSchema:p(t.inputSchema),outputSchema:p(t.outputSchema)},"tool"==t.type?{type:"action.tool",capabilities:{}}:{type:"action.trigger",capabilities:{},invocation:"polling"==t.source?{type:"polling",intervalSeconds:null!=(n=t.polling.intervalInSeconds)?n:r.SlateDefaultPollingIntervalSeconds}:{type:"webhook",autoRegistration:!!t.autoRegisterWebhook,autoUnregistration:!!t.autoUnregisterWebhook}})},g=/*#__PURE__*/u("value"),P=/*#__PURE__*/function(){function e(e){Object.defineProperty(this,g,{writable:!0,value:void 0}),i(this,g)[g]=e}var t,r,n=e.prototype;return n.get=function(){return i(this,g)[g]},n.set=function(e){i(this,g)[g]=e},t=e,(r=[{key:"value",get:function(){return i(this,g)[g]}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,c(n.key),n)}}(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),t}();exports.createProviderHandler=function(n,o){return t.createSlatesProviderProtoHandler(function(t){try{var i=new P(null),a=new P(null),u=new P(null),c=new P(null),g=new P(null),y=new r.SlateLogger(o),w=function(){var t=i.get(),r=a.get();if(!t||!r)throw new e.ServiceError(e.preconditionFailedError({message:"Connection context has not been initialized"}));return{protocol:t,participants:r}},I=function(){var t=w(),r=c.get(),o=g.get(),i=u.get();if(!r||!o||!i&&n.spec.auth.authStack.length>0)throw new e.ServiceError(e.preconditionFailedError({message:"Session context has not been initialized"}));return s({},t,{config:r.value,session:o,auth:i})};return t.onNotification("slates/hello",function(e){var t=e.params;try{return i.set(t.protocol),Promise.resolve()}catch(e){return Promise.reject(e)}}),t.onNotification("slates/participant.set",function(t){var r=t.params;try{if(!i.get())throw new e.ServiceError(e.preconditionFailedError({message:"Connection protocol has not been initialized"}));return a.set(r.participants),Promise.resolve()}catch(e){return Promise.reject(e)}}),t.onNotification("slates/auth.set",function(e){var t=e.params;try{w(),h(n,t.authenticationMethodId);var r=l(n.spec.authSchema,t.output,"auth","Invalid authentication output for method ID: "+t.authenticationMethodId);return u.set({authenticationMethodId:t.authenticationMethodId,output:r}),Promise.resolve()}catch(e){return Promise.reject(e)}}),t.onNotification("slates/config.set",function(e){var t=e.params;try{w();var r=l(n.spec.configSchema,t.config,"config","Invalid configuration");return c.set({value:r}),Promise.resolve()}catch(e){return Promise.reject(e)}}),t.onNotification("slates/session.start",function(e){var t=e.params;try{return w(),g.set({id:t.sessionId,state:t.state}),Promise.resolve()}catch(e){return Promise.reject(e)}}),t.onRequest("slates/config.changed",function(e){var t=e.params;try{w();var r=l(n.spec.config.configSchema,t.newConfig,"config","Invalid configuration"),o=n.spec.config.handlers.configChanged;return o?Promise.resolve(o({previousConfig:t.previousConfig,newConfig:r})).then(function(e){var t;return{success:!0,config:null!=(t=null==e?void 0:e.config)?t:r}}):Promise.resolve({success:!0,config:r})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/config.get_default",function(e){try{w();var t=n.spec.config.handlers.getDefaultConfig;return t?Promise.resolve(t()).then(function(e){return{config:e}}):Promise.resolve({config:null})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/config.schema.get",function(e){try{return w(),Promise.resolve({schema:p(n.spec.configSchema)})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/provider.identify",function(e){try{return w(),Promise.resolve({protocol:"slates@2026-01-01",provider:{type:"provider",id:n.spec.key,name:n.spec.name,description:n.spec.description,metadata:n.spec.parameters.metadata}})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/auth.methods.list",function(e){try{return w(),Promise.resolve({authenticationMethods:n.spec.auth.authStack.map(function(e){return d(n,e)})})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/auth.method.get",function(e){var t=e.params;try{w();var r=h(n,t.authenticationMethodId);return Promise.resolve({authenticationMethod:d(n,r)})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/auth.input.get_default",function(e){var t=e.params;try{w();var r=h(n,t.authenticationMethodId);return r.getDefaultInput?Promise.resolve(r.getDefaultInput()).then(function(e){return{input:e}}):Promise.resolve({input:null})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/auth.input.changed",function(e){var t=e.params;try{w();var r=h(n,t.authenticationMethodId);return r.onInputChanged?Promise.resolve(r.onInputChanged({previousInput:t.previousInput,newInput:t.newInput})).then(function(e){var r;return{success:!0,input:null!=(r=null==e?void 0:e.input)?r:t.newInput}}):Promise.resolve({success:!0,input:t.newInput})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/auth.output.get",function(e){var t=e.params;try{var r,o=function(e){return r?e:{output:a}};w();var i=h(n,t.authenticationMethodId),a=t.input;i.inputSchema&&(a=l(i.inputSchema,a,"auth","Invalid authentication input for method ID: "+t.authenticationMethodId));var u=function(){if("getOutput"in i)return Promise.resolve(i.getOutput({input:a})).then(function(e){return r=1,{output:e.output}})}();return Promise.resolve(u&&u.then?u.then(o):o(u))}catch(e){return Promise.reject(e)}}),t.onRequest("slates/auth.authorization_callback.handle",function(t){var r=t.params;try{var o,i=function(t){if(o)return t;throw new e.ServiceError(e.preconditionFailedError({message:"Authentication method does not support authorization callback handling: "+r.authenticationMethodId}))};w();var a=h(n,r.authenticationMethodId),u=function(){if("handleCallback"in a)return Promise.resolve(a.handleCallback({code:r.code,state:r.state,redirectUri:r.redirectUri,input:r.input,clientId:r.clientId,clientSecret:r.clientSecret,scopes:r.scopes})).then(function(e){return o=1,{output:e.output,input:e.input}})}();return Promise.resolve(u&&u.then?u.then(i):i(u))}catch(e){return Promise.reject(e)}}),t.onRequest("slates/auth.authorization_url.get",function(t){var r=t.params;try{var o,i=function(t){if(o)return t;throw new e.ServiceError(e.preconditionFailedError({message:"Authentication method does not support authorization URL retrieval: "+r.authenticationMethodId}))};w();var a=h(n,r.authenticationMethodId),u=function(){if("getAuthorizationUrl"in a)return Promise.resolve(a.getAuthorizationUrl({redirectUri:r.redirectUri,state:r.state,input:r.input,clientId:r.clientId,clientSecret:r.clientSecret,scopes:r.scopes})).then(function(e){return o=1,{authorizationUrl:e.url,input:e.input}})}();return Promise.resolve(u&&u.then?u.then(i):i(u))}catch(e){return Promise.reject(e)}}),t.onRequest("slates/auth.profile.get",function(t){var r=t.params;try{var o,i=function(t){if(o)return t;throw new e.ServiceError(e.preconditionFailedError({message:"Authentication method does not support profile retrieval: "+r.authenticationMethodId}))};w();var a=h(n,r.authenticationMethodId),u=function(){if(a.getProfile)return Promise.resolve(a.getProfile({output:r.output,input:r.input,scopes:r.scopes})).then(function(e){return o=1,{profile:e.profile}})}();return Promise.resolve(u&&u.then?u.then(i):i(u))}catch(e){return Promise.reject(e)}}),t.onRequest("slates/auth.token_refresh.handle",function(t){var r=t.params;try{var o,i=function(t){if(o)return t;throw new e.ServiceError(e.preconditionFailedError({message:"Authentication method does not support token refresh handling: "+r.authenticationMethodId}))};w();var a=h(n,r.authenticationMethodId),u=function(){if("handleTokenRefresh"in a&&a.handleTokenRefresh)return Promise.resolve(a.handleTokenRefresh({output:r.output,input:r.input,clientId:r.clientId,clientSecret:r.clientSecret,scopes:r.scopes})).then(function(e){return o=1,{output:e.output,input:e.input}})}();return Promise.resolve(u&&u.then?u.then(i):i(u))}catch(e){return Promise.reject(e)}}),t.onRequest("slates/actions.list",function(e){try{return w(),Promise.resolve({actions:n.actions.map(function(e){return m(0,e)})})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/action.get",function(e){var t=e.params;try{w();var r=f(n,t.actionId);return Promise.resolve({action:m(0,r)})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/action.tool.invoke",function(e){var t=e.params;try{var o,i=I(),a=v(n,"tool",t.actionId),u=l(a.inputSchema,t.input,"input","Invalid input for tool ID: "+t.actionId);return Promise.resolve(a.handleInvocation(new r.SlateContext(i.config,u,null==(o=i.auth)?void 0:o.output,n.spec,y))).then(function(e){return{output:e.output,message:e.message}})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/action.trigger.map_event",function(e){var t=e.params;try{var o,i=I(),a=v(n,"trigger",t.actionId),u=l(a.inputSchema,t.input,"input","Invalid event for trigger ID: "+t.actionId);return Promise.resolve(a.handleEvent(new r.SlateContext(i.config,u,null==(o=i.auth)?void 0:o.output,n.spec,y))).then(function(e){return{id:e.id,type:e.type,output:e.output}})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/action.trigger.poll_events",function(t){var o=t.params;try{var i,a=I(),u=v(n,"trigger",o.actionId);if(!u.pollEvents)throw new e.ServiceError(e.badRequestError({message:"Trigger action does not support polling: "+o.actionId}));return Promise.resolve(u.pollEvents(new r.SlateContext(a.config,{state:o.state},null==(i=a.auth)?void 0:i.output,n.spec,y))).then(function(e){return{inputs:e.inputs,updatedState:e.updatedState}})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/action.trigger.webhook_handle",function(t){var o=t.params;try{var i,a=I(),u=v(n,"trigger",o.actionId);if(!u.handleRequest)throw new e.ServiceError(e.badRequestError({message:"Trigger action does not support webhook requests: "+o.actionId}));var s=new Request(o.url,{method:o.method,headers:o.headers,body:o.body?Uint8Array.from(atob(o.body.content),function(e){return e.charCodeAt(0)}):null});return Promise.resolve(u.handleRequest(new r.SlateContext(a.config,{request:s,state:o.state},null==(i=a.auth)?void 0:i.output,n.spec,y))).then(function(e){return{inputs:e.inputs,updatedState:e.updatedState}})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/action.trigger.webhook_register",function(t){var o=t.params;try{var i,a=I(),u=v(n,"trigger",o.actionId);if(!u.autoRegisterWebhook)throw new e.ServiceError(e.badRequestError({message:"Trigger action does not support webhook auto-registration: "+o.actionId}));return Promise.resolve(u.autoRegisterWebhook(new r.SlateContext(a.config,{webhookBaseUrl:o.webhookBaseUrl},null==(i=a.auth)?void 0:i.output,n.spec,y))).then(function(e){return{registrationDetails:e.registrationDetails,state:e.state}})}catch(e){return Promise.reject(e)}}),t.onRequest("slates/action.trigger.webhook_unregister",function(t){var o=t.params;try{var i,a=I(),u=v(n,"trigger",o.actionId);if(!u.autoUnregisterWebhook)throw new e.ServiceError(e.badRequestError({message:"Trigger action does not support webhook auto-unregistration: "+o.actionId}));return Promise.resolve(u.autoUnregisterWebhook(new r.SlateContext(a.config,{webhookBaseUrl:o.webhookBaseUrl,registrationDetails:o.registrationDetails,state:o.state},null==(i=a.auth)?void 0:i.output,n.spec,y))).then(function(){return{}})}catch(e){return Promise.reject(e)}}),Promise.resolve()}catch(e){return Promise.reject(e)}})};
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
createProviderHandler: () => createProviderHandler
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
var import_error4 = require("@lowerdeck/error");
|
|
37
|
+
var import_proto = require("@slates/proto");
|
|
38
|
+
var import_provider2 = require("@slates/provider");
|
|
39
|
+
|
|
40
|
+
// src/pQueue.ts
|
|
41
|
+
var import_p_queue = __toESM(require("p-queue"), 1);
|
|
42
|
+
var resolveDefaultExport = (value) => {
|
|
43
|
+
let current = value;
|
|
44
|
+
for (let i = 0; i < 4; i++) {
|
|
45
|
+
if (typeof current === "function") return current;
|
|
46
|
+
if (current && typeof current === "object" && "default" in current) {
|
|
47
|
+
current = current.default;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
throw new TypeError("Module export is not a constructor");
|
|
53
|
+
};
|
|
54
|
+
var PQueue = resolveDefaultExport(import_p_queue.default);
|
|
55
|
+
|
|
56
|
+
// src/spec.ts
|
|
57
|
+
var import_error2 = require("@lowerdeck/error");
|
|
58
|
+
var import_provider = require("@slates/provider");
|
|
59
|
+
var import_zod = __toESM(require("zod"), 1);
|
|
60
|
+
|
|
61
|
+
// src/validation.ts
|
|
62
|
+
var import_error = require("@lowerdeck/error");
|
|
63
|
+
var zodToValidationError = (entity, message, e) => {
|
|
64
|
+
return (0, import_error.validationError)({
|
|
65
|
+
message,
|
|
66
|
+
entity,
|
|
67
|
+
errors: e.issues.map((i) => ({
|
|
68
|
+
...i,
|
|
69
|
+
path: i.path.map((p) => String(p))
|
|
70
|
+
}))
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
var validate = (schema, data, entity, message) => {
|
|
74
|
+
let result = schema.safeParse(data);
|
|
75
|
+
if (!result.success) {
|
|
76
|
+
throw new import_error.ServiceError(zodToValidationError(entity, message, result.error));
|
|
77
|
+
}
|
|
78
|
+
return result.data;
|
|
79
|
+
};
|
|
80
|
+
var toJsonSchema = (schema) => schema.toJSONSchema({
|
|
81
|
+
unrepresentable: "any",
|
|
82
|
+
override: (ctx) => {
|
|
83
|
+
let def = ctx.zodSchema._zod.def;
|
|
84
|
+
if (def.type === "date") {
|
|
85
|
+
ctx.jsonSchema.type = "string";
|
|
86
|
+
ctx.jsonSchema.format = "date-time";
|
|
87
|
+
}
|
|
88
|
+
if (def.type === "bigint") {
|
|
89
|
+
ctx.jsonSchema.type = "number";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// src/spec.ts
|
|
95
|
+
var getAuthMethod = (slate, authenticationMethodId) => {
|
|
96
|
+
let authMethod = slate.spec.auth.authStack.find((m) => m.key === authenticationMethodId);
|
|
97
|
+
if (!authMethod) {
|
|
98
|
+
throw new import_error2.ServiceError(
|
|
99
|
+
(0, import_error2.badRequestError)({
|
|
100
|
+
message: `Invalid authentication method ID: ${authenticationMethodId}`
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return authMethod;
|
|
105
|
+
};
|
|
106
|
+
var mapAuthMethod = (slate, m) => ({
|
|
107
|
+
id: m.key,
|
|
108
|
+
name: m.name,
|
|
109
|
+
type: m.type,
|
|
110
|
+
scopes: "scopes" in m ? m.scopes.map((s) => ({
|
|
111
|
+
id: s.scope,
|
|
112
|
+
title: s.title,
|
|
113
|
+
description: s.description
|
|
114
|
+
})) : void 0,
|
|
115
|
+
inputSchema: toJsonSchema(m.inputSchema ?? import_zod.default.object({})),
|
|
116
|
+
outputSchema: toJsonSchema(slate.spec.auth.outputSchema),
|
|
117
|
+
capabilities: {
|
|
118
|
+
getDefaultInput: { enabled: !!("getDefaultInput" in m && m.getDefaultInput) },
|
|
119
|
+
handleTokenRefresh: {
|
|
120
|
+
enabled: !!("handleTokenRefresh" in m && m.handleTokenRefresh)
|
|
121
|
+
},
|
|
122
|
+
handleChangedInput: {
|
|
123
|
+
enabled: !!m.onInputChanged
|
|
124
|
+
},
|
|
125
|
+
getProfile: { enabled: !!m.getProfile }
|
|
126
|
+
},
|
|
127
|
+
docs: m.docs ?? []
|
|
128
|
+
});
|
|
129
|
+
var getAction = (slate, actionId) => {
|
|
130
|
+
let action = slate.actions.find((m) => m.key === actionId);
|
|
131
|
+
if (!action) {
|
|
132
|
+
throw new import_error2.ServiceError((0, import_error2.notFoundError)(`action`, actionId));
|
|
133
|
+
}
|
|
134
|
+
return action;
|
|
135
|
+
};
|
|
136
|
+
var getAdapter = (slate, adapterId) => {
|
|
137
|
+
let adapter = slate.adapters.find((m) => m.id === adapterId);
|
|
138
|
+
if (!adapter) {
|
|
139
|
+
throw new import_error2.ServiceError((0, import_error2.notFoundError)(`adapter`, adapterId));
|
|
140
|
+
}
|
|
141
|
+
return adapter;
|
|
142
|
+
};
|
|
143
|
+
var mapAdapter = (adapter) => ({
|
|
144
|
+
id: adapter.id,
|
|
145
|
+
name: adapter.name,
|
|
146
|
+
capabilities: adapter.capabilities
|
|
147
|
+
});
|
|
148
|
+
var getActionWithType = (slate, type, actionId) => {
|
|
149
|
+
let action = getAction(slate, actionId);
|
|
150
|
+
if (action.type !== type) {
|
|
151
|
+
throw new import_error2.ServiceError(
|
|
152
|
+
(0, import_error2.badRequestError)({
|
|
153
|
+
message: `Action with ID ${actionId} is not of type ${type}`
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
return action;
|
|
158
|
+
};
|
|
159
|
+
var mapAction = (_slate, a) => {
|
|
160
|
+
let base = {
|
|
161
|
+
id: a.key,
|
|
162
|
+
name: a.name,
|
|
163
|
+
description: a.description,
|
|
164
|
+
instructions: a.instructions,
|
|
165
|
+
constraints: a.constraints,
|
|
166
|
+
tags: a.tags,
|
|
167
|
+
metadata: a.metadata,
|
|
168
|
+
scopes: a.scopes,
|
|
169
|
+
authMethods: a.authMethods,
|
|
170
|
+
docs: a.docs ?? [],
|
|
171
|
+
...a.adapter ? { adapter: a.adapter } : {},
|
|
172
|
+
inputSchema: toJsonSchema(a.inputSchema),
|
|
173
|
+
outputSchema: toJsonSchema(a.outputSchema)
|
|
174
|
+
};
|
|
175
|
+
if (a.type === "tool") {
|
|
176
|
+
return {
|
|
177
|
+
...base,
|
|
178
|
+
type: "action.tool",
|
|
179
|
+
capabilities: {},
|
|
180
|
+
isPublic: a.isPublic
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
...base,
|
|
185
|
+
type: "action.trigger",
|
|
186
|
+
capabilities: {},
|
|
187
|
+
triggerGroupId: a.triggerGroup.key
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
var getTriggerGroup = (slate, triggerGroupId) => {
|
|
191
|
+
let group = slate.triggerGroups.find((g) => g.key === triggerGroupId);
|
|
192
|
+
if (!group) {
|
|
193
|
+
throw new import_error2.ServiceError((0, import_error2.notFoundError)(`trigger_group`, triggerGroupId));
|
|
194
|
+
}
|
|
195
|
+
return group;
|
|
196
|
+
};
|
|
197
|
+
var getTriggersForGroup = (slate, triggerGroupId) => slate.actions.filter(
|
|
198
|
+
(action) => action.type === "trigger" && action.triggerGroup.key === triggerGroupId
|
|
199
|
+
);
|
|
200
|
+
var evaluateTriggerMatches = (slate, triggerGroupId, payload) => getTriggersForGroup(slate, triggerGroupId).filter((trigger) => trigger.matches(payload)).map((trigger) => trigger.key);
|
|
201
|
+
var getWebhookAutoRegistration = (group) => {
|
|
202
|
+
if (group.source !== "webhook" || !group.webhook?.autoRegistration) {
|
|
203
|
+
throw new import_error2.ServiceError(
|
|
204
|
+
(0, import_error2.badRequestError)({
|
|
205
|
+
message: `Trigger group does not support webhook auto-registration: ${group.key}`
|
|
206
|
+
})
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
return group.webhook.autoRegistration;
|
|
210
|
+
};
|
|
211
|
+
var getWebhookManualRegistration = (group) => {
|
|
212
|
+
if (group.source !== "webhook" || !group.webhook?.manualRegistration) {
|
|
213
|
+
throw new import_error2.ServiceError(
|
|
214
|
+
(0, import_error2.badRequestError)({
|
|
215
|
+
message: `Trigger group does not support manual webhook registration: ${group.key}`
|
|
216
|
+
})
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
return group.webhook.manualRegistration;
|
|
220
|
+
};
|
|
221
|
+
var mapTriggerGroup = (group) => ({
|
|
222
|
+
id: group.key,
|
|
223
|
+
name: group.name,
|
|
224
|
+
description: group.description,
|
|
225
|
+
metadata: group.metadata,
|
|
226
|
+
invocation: group.source === "polling" ? {
|
|
227
|
+
type: "polling",
|
|
228
|
+
intervalSeconds: group.polling?.intervalSeconds ?? import_provider.SlateDefaultPollingIntervalSeconds
|
|
229
|
+
} : {
|
|
230
|
+
type: "webhook",
|
|
231
|
+
registration: group.webhook?.manualRegistration ? {
|
|
232
|
+
mode: "manual",
|
|
233
|
+
userConfigSchema: toJsonSchema(group.webhook.manualRegistration.userConfigSchema),
|
|
234
|
+
fullConfigSchema: toJsonSchema(group.webhook.manualRegistration.fullConfigSchema)
|
|
235
|
+
} : { mode: "auto" }
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// src/state.ts
|
|
240
|
+
var State = class {
|
|
241
|
+
#value;
|
|
242
|
+
get value() {
|
|
243
|
+
return this.#value;
|
|
244
|
+
}
|
|
245
|
+
get() {
|
|
246
|
+
return this.#value;
|
|
247
|
+
}
|
|
248
|
+
set(value) {
|
|
249
|
+
this.#value = value;
|
|
250
|
+
}
|
|
251
|
+
constructor(initialValue) {
|
|
252
|
+
this.#value = initialValue;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// src/webhook.ts
|
|
257
|
+
var import_error3 = require("@lowerdeck/error");
|
|
258
|
+
var SLATE_WEBHOOK_RESPONSE_MAX_BODY_BYTES = 1024 * 1024;
|
|
259
|
+
var serializeBody = (body) => {
|
|
260
|
+
if (body === null) return null;
|
|
261
|
+
if (body.byteLength > SLATE_WEBHOOK_RESPONSE_MAX_BODY_BYTES) {
|
|
262
|
+
throw new import_error3.ServiceError(
|
|
263
|
+
(0, import_error3.badRequestError)({
|
|
264
|
+
message: `Webhook response body exceeds the ${SLATE_WEBHOOK_RESPONSE_MAX_BODY_BYTES}-byte limit`
|
|
265
|
+
})
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
encoding: "base64",
|
|
270
|
+
content: Buffer.from(body).toString("base64")
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
var headersToObject = (headers) => {
|
|
274
|
+
let result = {};
|
|
275
|
+
headers.forEach((value, key) => {
|
|
276
|
+
result[key] = value;
|
|
277
|
+
});
|
|
278
|
+
return result;
|
|
279
|
+
};
|
|
280
|
+
var validateStatus = (status) => {
|
|
281
|
+
if (!Number.isInteger(status) || status < 100 || status > 599) {
|
|
282
|
+
throw new import_error3.ServiceError(
|
|
283
|
+
(0, import_error3.badRequestError)({
|
|
284
|
+
message: "Webhook response status must be an integer between 100 and 599"
|
|
285
|
+
})
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
var serializeWebhookHttpResponse = async (response) => {
|
|
290
|
+
if (response instanceof Response) {
|
|
291
|
+
validateStatus(response.status);
|
|
292
|
+
return {
|
|
293
|
+
status: response.status,
|
|
294
|
+
headers: headersToObject(response.headers),
|
|
295
|
+
body: serializeBody(
|
|
296
|
+
response.body === null ? null : new Uint8Array(await response.arrayBuffer())
|
|
297
|
+
)
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
let status = response.status ?? 200;
|
|
301
|
+
validateStatus(status);
|
|
302
|
+
let body = typeof response.body === "string" ? new TextEncoder().encode(response.body) : response.body ?? null;
|
|
303
|
+
return {
|
|
304
|
+
status,
|
|
305
|
+
headers: response.headers ?? {},
|
|
306
|
+
body: serializeBody(body)
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// src/index.ts
|
|
311
|
+
var DEFAULT_MAX_ATTACHMENT_SIZE_BYTES = 1e8;
|
|
312
|
+
var routeAttachmentsThroughDirectUpload = async (attachments, live) => {
|
|
313
|
+
if (!attachments || attachments.length === 0 || !live) return attachments;
|
|
314
|
+
let contentEntries = attachments.map((attachment, index) => ({ attachment, index })).filter((entry) => entry.attachment.content.type === "content");
|
|
315
|
+
if (contentEntries.length === 0) return attachments;
|
|
316
|
+
let queue = new PQueue({ concurrency: 10 });
|
|
317
|
+
let replacements = /* @__PURE__ */ new Map();
|
|
318
|
+
await Promise.all(
|
|
319
|
+
contentEntries.map(
|
|
320
|
+
(entry) => queue.add(async () => {
|
|
321
|
+
try {
|
|
322
|
+
let body = entry.attachment.content.type === "content" ? entry.attachment.content.encoding === "base64" ? Buffer.from(entry.attachment.content.content, "base64") : Buffer.from(entry.attachment.content.content, "utf-8") : Buffer.alloc(0);
|
|
323
|
+
replacements.set(
|
|
324
|
+
entry.index,
|
|
325
|
+
await (0, import_provider2.uploadAttachmentDirect)({
|
|
326
|
+
live,
|
|
327
|
+
mimeType: entry.attachment.mimeType,
|
|
328
|
+
body
|
|
329
|
+
})
|
|
330
|
+
);
|
|
331
|
+
} catch {
|
|
332
|
+
replacements.set(entry.index, null);
|
|
333
|
+
}
|
|
334
|
+
})
|
|
335
|
+
)
|
|
336
|
+
);
|
|
337
|
+
return attachments.map(
|
|
338
|
+
(attachment, index) => replacements.has(index) ? replacements.get(index) : attachment
|
|
339
|
+
).filter((a) => a != null);
|
|
340
|
+
};
|
|
341
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
342
|
+
var getObjectKeyCount = (value) => isRecord(value) ? Object.keys(value).length : void 0;
|
|
343
|
+
var DOWNLOAD_ATTACHMENT_URL_KEYS = /* @__PURE__ */ new Set([
|
|
344
|
+
"downloadUrl",
|
|
345
|
+
"fileUrl",
|
|
346
|
+
"temporaryDownloadUrl",
|
|
347
|
+
"webContentLink"
|
|
348
|
+
]);
|
|
349
|
+
var isAttachmentUrl = (value) => /^[a-z][a-z0-9+.-]*:\/\//i.test(value);
|
|
350
|
+
var collectOutputUrlAttachments = (value, seen = /* @__PURE__ */ new Set()) => {
|
|
351
|
+
if (Array.isArray(value)) {
|
|
352
|
+
return value.flatMap((item) => collectOutputUrlAttachments(item, seen));
|
|
353
|
+
}
|
|
354
|
+
if (!isRecord(value)) {
|
|
355
|
+
return [];
|
|
356
|
+
}
|
|
357
|
+
let attachments = [];
|
|
358
|
+
for (let [key, nestedValue] of Object.entries(value)) {
|
|
359
|
+
if (DOWNLOAD_ATTACHMENT_URL_KEYS.has(key) && typeof nestedValue === "string" && nestedValue.length > 0 && isAttachmentUrl(nestedValue) && !seen.has(nestedValue)) {
|
|
360
|
+
seen.add(nestedValue);
|
|
361
|
+
attachments.push({
|
|
362
|
+
content: {
|
|
363
|
+
type: "url",
|
|
364
|
+
url: nestedValue
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
attachments.push(...collectOutputUrlAttachments(nestedValue, seen));
|
|
370
|
+
}
|
|
371
|
+
return attachments;
|
|
372
|
+
};
|
|
373
|
+
var mergeAttachments = (explicitAttachments, output) => {
|
|
374
|
+
let attachments = [...explicitAttachments ?? []];
|
|
375
|
+
let seen = new Set(attachments.map((attachment) => JSON.stringify(attachment)));
|
|
376
|
+
for (let attachment of collectOutputUrlAttachments(output)) {
|
|
377
|
+
let key = JSON.stringify(attachment);
|
|
378
|
+
if (seen.has(key)) continue;
|
|
379
|
+
seen.add(key);
|
|
380
|
+
attachments.push(attachment);
|
|
381
|
+
}
|
|
382
|
+
return attachments.length > 0 ? attachments : void 0;
|
|
383
|
+
};
|
|
384
|
+
var toErrorMetadata = (error) => {
|
|
385
|
+
if (error instanceof Error) {
|
|
386
|
+
return {
|
|
387
|
+
errorName: error.name,
|
|
388
|
+
errorMessage: error.message,
|
|
389
|
+
errorStack: error.stack
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
errorValue: String(error)
|
|
394
|
+
};
|
|
395
|
+
};
|
|
396
|
+
var formatEntityLabel = (name, key) => `"${name}" (${key})`;
|
|
397
|
+
var resolveTraceMessage = (message, result) => typeof message === "function" ? message(result) : message;
|
|
398
|
+
var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesProviderProtoHandler)(async (manager) => {
|
|
399
|
+
let protocol = new State(null);
|
|
400
|
+
let participants = new State(null);
|
|
401
|
+
let auth = new State(null);
|
|
402
|
+
let config = new State(null);
|
|
403
|
+
let session = new State(null);
|
|
404
|
+
let hubCapabilities = new State(null);
|
|
405
|
+
let liveInvocation = new State(
|
|
406
|
+
null
|
|
407
|
+
);
|
|
408
|
+
let getLiveInvocation = () => {
|
|
409
|
+
let directUpload = hubCapabilities.get()?.attachments?.directUpload;
|
|
410
|
+
let live = liveInvocation.get();
|
|
411
|
+
if (!directUpload?.enabled || !live) return null;
|
|
412
|
+
return {
|
|
413
|
+
...live,
|
|
414
|
+
maxAttachmentSizeBytes: directUpload.maxAttachmentSizeBytes ?? DEFAULT_MAX_ATTACHMENT_SIZE_BYTES
|
|
415
|
+
};
|
|
416
|
+
};
|
|
417
|
+
let supportsTriggerGroups = () => !!hubCapabilities.get()?.triggers;
|
|
418
|
+
let logger = new import_provider2.SlateLogger(listeners);
|
|
419
|
+
let providerTrace = {
|
|
420
|
+
providerId: slate.spec.key,
|
|
421
|
+
providerName: slate.spec.name
|
|
422
|
+
};
|
|
423
|
+
let traceProviderCall = async (trace, handler) => {
|
|
424
|
+
let startedAt = Date.now();
|
|
425
|
+
logger.info({
|
|
426
|
+
...providerTrace,
|
|
427
|
+
...trace.metadata,
|
|
428
|
+
component: trace.component,
|
|
429
|
+
functionName: trace.functionName,
|
|
430
|
+
phase: "start",
|
|
431
|
+
message: trace.message
|
|
432
|
+
});
|
|
433
|
+
try {
|
|
434
|
+
let result = await handler();
|
|
435
|
+
let successMessage = resolveTraceMessage(trace.successMessage, result);
|
|
436
|
+
logger.info({
|
|
437
|
+
...providerTrace,
|
|
438
|
+
...trace.metadata,
|
|
439
|
+
...trace.onSuccess?.(result) ?? {},
|
|
440
|
+
component: trace.component,
|
|
441
|
+
functionName: trace.functionName,
|
|
442
|
+
phase: "success",
|
|
443
|
+
durationMs: Date.now() - startedAt,
|
|
444
|
+
message: successMessage
|
|
445
|
+
});
|
|
446
|
+
return result;
|
|
447
|
+
} catch (error) {
|
|
448
|
+
logger.error({
|
|
449
|
+
...providerTrace,
|
|
450
|
+
...trace.metadata,
|
|
451
|
+
...toErrorMetadata(error),
|
|
452
|
+
component: trace.component,
|
|
453
|
+
functionName: trace.functionName,
|
|
454
|
+
phase: "error",
|
|
455
|
+
durationMs: Date.now() - startedAt,
|
|
456
|
+
message: trace.errorMessage ?? `${typeof trace.successMessage === "string" ? trace.successMessage : trace.message} failed`
|
|
457
|
+
});
|
|
458
|
+
throw error;
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
let getContextBasic = () => {
|
|
462
|
+
let currentProtocol = protocol.get();
|
|
463
|
+
let currentParticipants = participants.get();
|
|
464
|
+
if (!currentProtocol || !currentParticipants) {
|
|
465
|
+
throw new import_error4.ServiceError(
|
|
466
|
+
(0, import_error4.preconditionFailedError)({
|
|
467
|
+
message: "Connection context has not been initialized"
|
|
468
|
+
})
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
return {
|
|
472
|
+
protocol: currentProtocol,
|
|
473
|
+
participants: currentParticipants
|
|
474
|
+
};
|
|
475
|
+
};
|
|
476
|
+
let getContextFull = () => {
|
|
477
|
+
let basic = getContextBasic();
|
|
478
|
+
let currentConfig = config.get();
|
|
479
|
+
let currentSession = session.get();
|
|
480
|
+
let currentAuth = auth.get();
|
|
481
|
+
if (!currentConfig || !currentSession || !currentAuth && slate.spec.auth.authStack.length > 0) {
|
|
482
|
+
throw new import_error4.ServiceError(
|
|
483
|
+
(0, import_error4.preconditionFailedError)({
|
|
484
|
+
message: "Session context has not been initialized"
|
|
485
|
+
})
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
return {
|
|
489
|
+
...basic,
|
|
490
|
+
config: currentConfig.value,
|
|
491
|
+
session: currentSession,
|
|
492
|
+
auth: currentAuth
|
|
493
|
+
};
|
|
494
|
+
};
|
|
495
|
+
let getAuthConfig = () => config.get()?.value ?? {};
|
|
496
|
+
let getEmptyContext = () => new import_provider2.SlateContext({}, {}, {}, slate.spec, logger);
|
|
497
|
+
let getAuthContext = () => new import_provider2.SlateContext(getAuthConfig(), {}, {}, slate.spec, logger);
|
|
498
|
+
let withRequestTraces = (context, result) => {
|
|
499
|
+
let requestTraces = context.getHttpTraces();
|
|
500
|
+
return requestTraces.length > 0 ? { ...result, requestTraces } : result;
|
|
501
|
+
};
|
|
502
|
+
manager.onNotification("slates/hello", async ({ params }) => {
|
|
503
|
+
protocol.set(params.protocol);
|
|
504
|
+
});
|
|
505
|
+
manager.onNotification("slates/participant.set", async ({ params }) => {
|
|
506
|
+
if (!protocol.get()) {
|
|
507
|
+
throw new import_error4.ServiceError(
|
|
508
|
+
(0, import_error4.preconditionFailedError)({ message: "Connection protocol has not been initialized" })
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
participants.set(params.participants);
|
|
512
|
+
});
|
|
513
|
+
manager.onNotification("slates/auth.set", async ({ params }) => {
|
|
514
|
+
getContextBasic();
|
|
515
|
+
getAuthMethod(slate, params.authenticationMethodId);
|
|
516
|
+
let valRes = validate(
|
|
517
|
+
slate.spec.authSchema,
|
|
518
|
+
params.output,
|
|
519
|
+
"auth",
|
|
520
|
+
`Invalid authentication output for method ID: ${params.authenticationMethodId}`
|
|
521
|
+
);
|
|
522
|
+
auth.set({
|
|
523
|
+
authenticationMethodId: params.authenticationMethodId,
|
|
524
|
+
output: valRes
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
manager.onNotification("slates/config.set", async ({ params }) => {
|
|
528
|
+
getContextBasic();
|
|
529
|
+
let value = validate(
|
|
530
|
+
slate.spec.configSchema,
|
|
531
|
+
params.config,
|
|
532
|
+
"config",
|
|
533
|
+
"Invalid configuration"
|
|
534
|
+
);
|
|
535
|
+
config.set({ value });
|
|
536
|
+
});
|
|
537
|
+
manager.onNotification("slates/session.start", async ({ params }) => {
|
|
538
|
+
getContextBasic();
|
|
539
|
+
session.set({
|
|
540
|
+
id: params.sessionId,
|
|
541
|
+
state: params.state
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
manager.onNotification("slates/hub.capabilities.set", async ({ params }) => {
|
|
545
|
+
hubCapabilities.set(params.capabilities);
|
|
546
|
+
});
|
|
547
|
+
manager.onNotification("slates/hub.live_invocation.set", async ({ params }) => {
|
|
548
|
+
liveInvocation.set({
|
|
549
|
+
token: params.token,
|
|
550
|
+
baseUrl: params.baseUrl
|
|
551
|
+
});
|
|
552
|
+
});
|
|
553
|
+
manager.onRequest("slates/provider.capabilities.get", async () => ({
|
|
554
|
+
capabilities: {
|
|
555
|
+
hub: {
|
|
556
|
+
capabilitiesNotification: true,
|
|
557
|
+
liveInvocation: true
|
|
558
|
+
},
|
|
559
|
+
provider: {
|
|
560
|
+
triggerGroups: true
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}));
|
|
564
|
+
manager.onRequest("slates/config.changed", async ({ params }) => {
|
|
565
|
+
getContextBasic();
|
|
566
|
+
let newConfig = validate(
|
|
567
|
+
slate.spec.config.configSchema,
|
|
568
|
+
params.newConfig,
|
|
569
|
+
"config",
|
|
570
|
+
"Invalid configuration"
|
|
571
|
+
);
|
|
572
|
+
let configChanged = slate.spec.config.handlers.configChanged;
|
|
573
|
+
if (!configChanged) {
|
|
574
|
+
return { success: true, config: newConfig };
|
|
575
|
+
}
|
|
576
|
+
let context = getEmptyContext();
|
|
577
|
+
let updatedConfig = await traceProviderCall(
|
|
578
|
+
{
|
|
579
|
+
component: "config",
|
|
580
|
+
functionName: "configChanged",
|
|
581
|
+
message: "Running config change handler",
|
|
582
|
+
successMessage: "Config change handler completed",
|
|
583
|
+
metadata: {
|
|
584
|
+
hasPreviousConfig: params.previousConfig !== null,
|
|
585
|
+
newConfigKeyCount: getObjectKeyCount(newConfig)
|
|
586
|
+
},
|
|
587
|
+
onSuccess: (result) => ({
|
|
588
|
+
returnedConfig: !!result?.config
|
|
589
|
+
})
|
|
590
|
+
},
|
|
591
|
+
() => (0, import_provider2.runWithContext)(
|
|
592
|
+
context,
|
|
593
|
+
async () => configChanged({
|
|
594
|
+
previousConfig: params.previousConfig,
|
|
595
|
+
newConfig
|
|
596
|
+
})
|
|
597
|
+
)
|
|
598
|
+
);
|
|
599
|
+
return withRequestTraces(context, {
|
|
600
|
+
success: true,
|
|
601
|
+
config: updatedConfig?.config ?? newConfig
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
manager.onRequest("slates/config.get_default", async () => {
|
|
605
|
+
getContextBasic();
|
|
606
|
+
let getDefaultConfig = slate.spec.config.handlers.getDefaultConfig;
|
|
607
|
+
if (!getDefaultConfig) {
|
|
608
|
+
return { config: null };
|
|
609
|
+
}
|
|
610
|
+
let context = getEmptyContext();
|
|
611
|
+
let defaultConfig = await traceProviderCall(
|
|
612
|
+
{
|
|
613
|
+
component: "config",
|
|
614
|
+
functionName: "getDefaultConfig",
|
|
615
|
+
message: "Getting default config",
|
|
616
|
+
successMessage: "Default config retrieved",
|
|
617
|
+
onSuccess: (result) => ({
|
|
618
|
+
configKeyCount: getObjectKeyCount(result)
|
|
619
|
+
})
|
|
620
|
+
},
|
|
621
|
+
() => (0, import_provider2.runWithContext)(context, async () => getDefaultConfig())
|
|
622
|
+
);
|
|
623
|
+
return withRequestTraces(context, {
|
|
624
|
+
config: defaultConfig ?? null
|
|
625
|
+
});
|
|
626
|
+
});
|
|
627
|
+
manager.onRequest("slates/config.schema.get", async () => {
|
|
628
|
+
getContextBasic();
|
|
629
|
+
return {
|
|
630
|
+
schema: toJsonSchema(slate.spec.configSchema),
|
|
631
|
+
docs: slate.spec.config.docsReferences ?? []
|
|
632
|
+
};
|
|
633
|
+
});
|
|
634
|
+
manager.onRequest("slates/provider.identify", async () => {
|
|
635
|
+
getContextBasic();
|
|
636
|
+
return {
|
|
637
|
+
protocol: import_proto.SLATES_PROTOCOL_VERSION,
|
|
638
|
+
provider: {
|
|
639
|
+
type: "provider",
|
|
640
|
+
id: slate.spec.key,
|
|
641
|
+
name: slate.spec.name,
|
|
642
|
+
description: slate.spec.description,
|
|
643
|
+
metadata: slate.spec.parameters.metadata
|
|
644
|
+
},
|
|
645
|
+
docs: slate.spec.docs ?? []
|
|
646
|
+
};
|
|
647
|
+
});
|
|
648
|
+
manager.onRequest("slates/auth.methods.list", async () => {
|
|
649
|
+
getContextBasic();
|
|
650
|
+
return {
|
|
651
|
+
authenticationMethods: slate.spec.auth.authStack.map((m) => mapAuthMethod(slate, m))
|
|
652
|
+
};
|
|
653
|
+
});
|
|
654
|
+
manager.onRequest("slates/auth.method.get", async ({ params }) => {
|
|
655
|
+
getContextBasic();
|
|
656
|
+
let authMethod = getAuthMethod(slate, params.authenticationMethodId);
|
|
657
|
+
return {
|
|
658
|
+
authenticationMethod: mapAuthMethod(slate, authMethod)
|
|
659
|
+
};
|
|
660
|
+
});
|
|
661
|
+
manager.onRequest("slates/auth.input.get_default", async ({ params }) => {
|
|
662
|
+
getContextBasic();
|
|
663
|
+
let authMethod = getAuthMethod(slate, params.authenticationMethodId);
|
|
664
|
+
if (!authMethod.getDefaultInput) {
|
|
665
|
+
return { input: null };
|
|
666
|
+
}
|
|
667
|
+
let context = getEmptyContext();
|
|
668
|
+
let input = await traceProviderCall(
|
|
669
|
+
{
|
|
670
|
+
component: "auth",
|
|
671
|
+
functionName: "getDefaultInput",
|
|
672
|
+
message: "Getting default authentication input",
|
|
673
|
+
successMessage: "Default authentication input retrieved",
|
|
674
|
+
metadata: {
|
|
675
|
+
authenticationMethodId: params.authenticationMethodId,
|
|
676
|
+
authenticationMethodName: authMethod.name
|
|
677
|
+
},
|
|
678
|
+
onSuccess: (result) => ({
|
|
679
|
+
inputKeyCount: getObjectKeyCount(result)
|
|
680
|
+
})
|
|
681
|
+
},
|
|
682
|
+
() => (0, import_provider2.runWithContext)(context, () => authMethod.getDefaultInput())
|
|
683
|
+
);
|
|
684
|
+
return withRequestTraces(context, { input });
|
|
685
|
+
});
|
|
686
|
+
manager.onRequest("slates/auth.input.changed", async ({ params }) => {
|
|
687
|
+
getContextBasic();
|
|
688
|
+
let authMethod = getAuthMethod(slate, params.authenticationMethodId);
|
|
689
|
+
if (!authMethod.onInputChanged) {
|
|
690
|
+
return { success: true, input: params.newInput };
|
|
691
|
+
}
|
|
692
|
+
let context = getEmptyContext();
|
|
693
|
+
let updatedInput = await traceProviderCall(
|
|
694
|
+
{
|
|
695
|
+
component: "auth",
|
|
696
|
+
functionName: "onInputChanged",
|
|
697
|
+
message: "Running authentication input change handler",
|
|
698
|
+
successMessage: "Authentication input change handler completed",
|
|
699
|
+
metadata: {
|
|
700
|
+
authenticationMethodId: params.authenticationMethodId,
|
|
701
|
+
authenticationMethodName: authMethod.name,
|
|
702
|
+
hasPreviousInput: params.previousInput !== null,
|
|
703
|
+
newInputKeyCount: getObjectKeyCount(params.newInput)
|
|
704
|
+
},
|
|
705
|
+
onSuccess: (result) => ({
|
|
706
|
+
returnedInput: !!result?.input
|
|
707
|
+
})
|
|
708
|
+
},
|
|
709
|
+
() => (0, import_provider2.runWithContext)(
|
|
710
|
+
context,
|
|
711
|
+
() => authMethod.onInputChanged({
|
|
712
|
+
previousInput: params.previousInput,
|
|
713
|
+
newInput: params.newInput
|
|
714
|
+
})
|
|
715
|
+
)
|
|
716
|
+
);
|
|
717
|
+
return withRequestTraces(context, {
|
|
718
|
+
success: true,
|
|
719
|
+
input: updatedInput?.input ?? params.newInput
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
manager.onRequest("slates/auth.output.get", async ({ params }) => {
|
|
723
|
+
getContextBasic();
|
|
724
|
+
let authMethod = getAuthMethod(slate, params.authenticationMethodId);
|
|
725
|
+
let input = params.input;
|
|
726
|
+
if (authMethod.inputSchema) {
|
|
727
|
+
input = validate(
|
|
728
|
+
authMethod.inputSchema,
|
|
729
|
+
input,
|
|
730
|
+
"auth",
|
|
731
|
+
`Invalid authentication input for method ID: ${params.authenticationMethodId}`
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
if ("getOutput" in authMethod) {
|
|
735
|
+
let context = getAuthContext();
|
|
736
|
+
let outputRes = await traceProviderCall(
|
|
737
|
+
{
|
|
738
|
+
component: "auth",
|
|
739
|
+
functionName: "getOutput",
|
|
740
|
+
message: "Getting authentication output",
|
|
741
|
+
successMessage: "Authentication output retrieved",
|
|
742
|
+
metadata: {
|
|
743
|
+
authenticationMethodId: params.authenticationMethodId,
|
|
744
|
+
authenticationMethodName: authMethod.name,
|
|
745
|
+
inputKeyCount: getObjectKeyCount(input)
|
|
746
|
+
},
|
|
747
|
+
onSuccess: (result) => ({
|
|
748
|
+
outputKeyCount: getObjectKeyCount(result.output),
|
|
749
|
+
scopeCount: result.scopes?.length ?? 0
|
|
750
|
+
})
|
|
751
|
+
},
|
|
752
|
+
() => (0, import_provider2.runWithContext)(
|
|
753
|
+
context,
|
|
754
|
+
() => authMethod.getOutput({
|
|
755
|
+
input,
|
|
756
|
+
config: getAuthConfig()
|
|
757
|
+
})
|
|
758
|
+
)
|
|
759
|
+
);
|
|
760
|
+
return withRequestTraces(context, {
|
|
761
|
+
output: outputRes.output,
|
|
762
|
+
scopes: outputRes.scopes
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
return { output: input };
|
|
766
|
+
});
|
|
767
|
+
manager.onRequest("slates/auth.authorization_callback.handle", async ({ params }) => {
|
|
768
|
+
getContextBasic();
|
|
769
|
+
let authMethod = getAuthMethod(slate, params.authenticationMethodId);
|
|
770
|
+
if ("handleCallback" in authMethod) {
|
|
771
|
+
let context = getEmptyContext();
|
|
772
|
+
let callbackRes = await traceProviderCall(
|
|
773
|
+
{
|
|
774
|
+
component: "auth",
|
|
775
|
+
functionName: "handleCallback",
|
|
776
|
+
message: "Handling authentication callback",
|
|
777
|
+
successMessage: "Authentication callback handled",
|
|
778
|
+
metadata: {
|
|
779
|
+
authenticationMethodId: params.authenticationMethodId,
|
|
780
|
+
authenticationMethodName: authMethod.name,
|
|
781
|
+
scopeCount: params.scopes.length,
|
|
782
|
+
hasCallbackState: !!params.callbackState
|
|
783
|
+
},
|
|
784
|
+
onSuccess: (result) => ({
|
|
785
|
+
outputKeyCount: getObjectKeyCount(result.output),
|
|
786
|
+
returnedInput: !!result.input,
|
|
787
|
+
returnedScopeCount: result.scopes?.length
|
|
788
|
+
})
|
|
789
|
+
},
|
|
790
|
+
() => (0, import_provider2.runWithContext)(
|
|
791
|
+
context,
|
|
792
|
+
() => authMethod.handleCallback({
|
|
793
|
+
code: params.code,
|
|
794
|
+
state: params.state,
|
|
795
|
+
redirectUri: params.redirectUri,
|
|
796
|
+
input: params.input,
|
|
797
|
+
clientId: params.clientId,
|
|
798
|
+
clientSecret: params.clientSecret,
|
|
799
|
+
scopes: params.scopes,
|
|
800
|
+
callbackParams: params.callbackParams || {},
|
|
801
|
+
callbackState: params.callbackState || {},
|
|
802
|
+
config: getAuthConfig()
|
|
803
|
+
})
|
|
804
|
+
)
|
|
805
|
+
);
|
|
806
|
+
return withRequestTraces(context, {
|
|
807
|
+
output: callbackRes.output,
|
|
808
|
+
input: callbackRes.input,
|
|
809
|
+
scopes: callbackRes.scopes
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
throw new import_error4.ServiceError(
|
|
813
|
+
(0, import_error4.preconditionFailedError)({
|
|
814
|
+
message: `Authentication method does not support authorization callback handling: ${params.authenticationMethodId}`
|
|
815
|
+
})
|
|
816
|
+
);
|
|
817
|
+
});
|
|
818
|
+
manager.onRequest("slates/auth.authorization_url.get", async ({ params }) => {
|
|
819
|
+
getContextBasic();
|
|
820
|
+
let authMethod = getAuthMethod(slate, params.authenticationMethodId);
|
|
821
|
+
if ("getAuthorizationUrl" in authMethod) {
|
|
822
|
+
let context = getEmptyContext();
|
|
823
|
+
let urlRes = await traceProviderCall(
|
|
824
|
+
{
|
|
825
|
+
component: "auth",
|
|
826
|
+
functionName: "getAuthorizationUrl",
|
|
827
|
+
message: "Getting authentication authorization URL",
|
|
828
|
+
successMessage: "Authentication authorization URL retrieved",
|
|
829
|
+
metadata: {
|
|
830
|
+
authenticationMethodId: params.authenticationMethodId,
|
|
831
|
+
authenticationMethodName: authMethod.name,
|
|
832
|
+
scopeCount: params.scopes.length,
|
|
833
|
+
inputKeyCount: getObjectKeyCount(params.input)
|
|
834
|
+
},
|
|
835
|
+
onSuccess: (result) => ({
|
|
836
|
+
returnedInput: !!result.input,
|
|
837
|
+
hasCallbackState: !!result.callbackState
|
|
838
|
+
})
|
|
839
|
+
},
|
|
840
|
+
() => (0, import_provider2.runWithContext)(
|
|
841
|
+
context,
|
|
842
|
+
() => authMethod.getAuthorizationUrl({
|
|
843
|
+
redirectUri: params.redirectUri,
|
|
844
|
+
state: params.state,
|
|
845
|
+
input: params.input,
|
|
846
|
+
clientId: params.clientId,
|
|
847
|
+
clientSecret: params.clientSecret,
|
|
848
|
+
scopes: params.scopes,
|
|
849
|
+
config: getAuthConfig()
|
|
850
|
+
})
|
|
851
|
+
)
|
|
852
|
+
);
|
|
853
|
+
return withRequestTraces(context, {
|
|
854
|
+
authorizationUrl: urlRes.url,
|
|
855
|
+
input: urlRes.input,
|
|
856
|
+
callbackState: urlRes.callbackState
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
throw new import_error4.ServiceError(
|
|
860
|
+
(0, import_error4.preconditionFailedError)({
|
|
861
|
+
message: `Authentication method does not support authorization URL retrieval: ${params.authenticationMethodId}`
|
|
862
|
+
})
|
|
863
|
+
);
|
|
864
|
+
});
|
|
865
|
+
manager.onRequest("slates/auth.profile.get", async ({ params }) => {
|
|
866
|
+
getContextBasic();
|
|
867
|
+
let authMethod = getAuthMethod(slate, params.authenticationMethodId);
|
|
868
|
+
if (authMethod.getProfile) {
|
|
869
|
+
let context = getAuthContext();
|
|
870
|
+
let profileRes = await traceProviderCall(
|
|
871
|
+
{
|
|
872
|
+
component: "auth",
|
|
873
|
+
functionName: "getProfile",
|
|
874
|
+
message: "Getting authentication profile",
|
|
875
|
+
successMessage: "Authentication profile retrieved",
|
|
876
|
+
metadata: {
|
|
877
|
+
authenticationMethodId: params.authenticationMethodId,
|
|
878
|
+
authenticationMethodName: authMethod.name,
|
|
879
|
+
scopeCount: params.scopes.length,
|
|
880
|
+
inputKeyCount: getObjectKeyCount(params.input),
|
|
881
|
+
outputKeyCount: getObjectKeyCount(params.output)
|
|
882
|
+
},
|
|
883
|
+
onSuccess: (result) => ({
|
|
884
|
+
profileKeyCount: getObjectKeyCount(result.profile)
|
|
885
|
+
})
|
|
886
|
+
},
|
|
887
|
+
() => (0, import_provider2.runWithContext)(context, () => {
|
|
888
|
+
if (authMethod.type === "auth.oauth") {
|
|
889
|
+
return authMethod.getProfile({
|
|
890
|
+
output: params.output,
|
|
891
|
+
input: params.input,
|
|
892
|
+
scopes: params.scopes,
|
|
893
|
+
config: getAuthConfig()
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
return authMethod.getProfile({
|
|
897
|
+
output: params.output,
|
|
898
|
+
input: params.input,
|
|
899
|
+
scopes: params.scopes,
|
|
900
|
+
config: getAuthConfig()
|
|
901
|
+
});
|
|
902
|
+
})
|
|
903
|
+
);
|
|
904
|
+
return withRequestTraces(context, {
|
|
905
|
+
profile: profileRes.profile
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
throw new import_error4.ServiceError(
|
|
909
|
+
(0, import_error4.preconditionFailedError)({
|
|
910
|
+
message: `Authentication method does not support profile retrieval: ${params.authenticationMethodId}`
|
|
911
|
+
})
|
|
912
|
+
);
|
|
913
|
+
});
|
|
914
|
+
manager.onRequest("slates/auth.token_refresh.handle", async ({ params }) => {
|
|
915
|
+
getContextBasic();
|
|
916
|
+
let authMethod = getAuthMethod(slate, params.authenticationMethodId);
|
|
917
|
+
if ("handleTokenRefresh" in authMethod && authMethod.handleTokenRefresh) {
|
|
918
|
+
let context = getAuthContext();
|
|
919
|
+
let refreshRes = await traceProviderCall(
|
|
920
|
+
{
|
|
921
|
+
component: "auth",
|
|
922
|
+
functionName: "handleTokenRefresh",
|
|
923
|
+
message: "Refreshing authentication token",
|
|
924
|
+
successMessage: "Authentication token refreshed",
|
|
925
|
+
metadata: {
|
|
926
|
+
authenticationMethodId: params.authenticationMethodId,
|
|
927
|
+
authenticationMethodName: authMethod.name,
|
|
928
|
+
scopeCount: params.scopes.length,
|
|
929
|
+
inputKeyCount: getObjectKeyCount(params.input),
|
|
930
|
+
outputKeyCount: getObjectKeyCount(params.output)
|
|
931
|
+
},
|
|
932
|
+
onSuccess: (result) => ({
|
|
933
|
+
refreshedOutputKeyCount: getObjectKeyCount(result.output),
|
|
934
|
+
returnedInput: !!result.input
|
|
935
|
+
})
|
|
936
|
+
},
|
|
937
|
+
() => (0, import_provider2.runWithContext)(context, () => {
|
|
938
|
+
if (authMethod.type === "auth.oauth") {
|
|
939
|
+
return authMethod.handleTokenRefresh({
|
|
940
|
+
output: params.output,
|
|
941
|
+
input: params.input,
|
|
942
|
+
clientId: params.clientId,
|
|
943
|
+
clientSecret: params.clientSecret,
|
|
944
|
+
scopes: params.scopes,
|
|
945
|
+
config: getAuthConfig()
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
return authMethod.handleTokenRefresh({
|
|
949
|
+
output: params.output,
|
|
950
|
+
input: params.input,
|
|
951
|
+
clientId: params.clientId,
|
|
952
|
+
clientSecret: params.clientSecret,
|
|
953
|
+
scopes: params.scopes,
|
|
954
|
+
config: getAuthConfig()
|
|
955
|
+
});
|
|
956
|
+
})
|
|
957
|
+
);
|
|
958
|
+
return withRequestTraces(context, {
|
|
959
|
+
output: refreshRes.output,
|
|
960
|
+
input: refreshRes.input
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
throw new import_error4.ServiceError(
|
|
964
|
+
(0, import_error4.preconditionFailedError)({
|
|
965
|
+
message: `Authentication method does not support token refresh handling: ${params.authenticationMethodId}`
|
|
966
|
+
})
|
|
967
|
+
);
|
|
968
|
+
});
|
|
969
|
+
manager.onRequest("slates/actions.list", async ({ params }) => {
|
|
970
|
+
getContextBasic();
|
|
971
|
+
let actions = params.includeAdapterActions ? slate.actions : slate.actions.filter((action) => !action.adapter);
|
|
972
|
+
if (!supportsTriggerGroups()) {
|
|
973
|
+
actions = actions.filter((action) => action.type !== "trigger");
|
|
974
|
+
}
|
|
975
|
+
return {
|
|
976
|
+
actions: actions.map((a) => mapAction(slate, a))
|
|
977
|
+
};
|
|
978
|
+
});
|
|
979
|
+
manager.onRequest("slates/adapters.list", async () => {
|
|
980
|
+
getContextBasic();
|
|
981
|
+
return {
|
|
982
|
+
adapters: slate.adapters.map(mapAdapter)
|
|
983
|
+
};
|
|
984
|
+
});
|
|
985
|
+
manager.onRequest("slates/adapter.get", async ({ params }) => {
|
|
986
|
+
getContextBasic();
|
|
987
|
+
let adapter = getAdapter(slate, params.adapterId);
|
|
988
|
+
return {
|
|
989
|
+
adapter: mapAdapter(adapter)
|
|
990
|
+
};
|
|
991
|
+
});
|
|
992
|
+
manager.onRequest("slates/action.get", async ({ params }) => {
|
|
993
|
+
getContextBasic();
|
|
994
|
+
let action = getAction(slate, params.actionId);
|
|
995
|
+
return {
|
|
996
|
+
action: mapAction(slate, action)
|
|
997
|
+
};
|
|
998
|
+
});
|
|
999
|
+
manager.onRequest("slates/trigger_groups.list", async () => {
|
|
1000
|
+
getContextBasic();
|
|
1001
|
+
return {
|
|
1002
|
+
triggerGroups: slate.triggerGroups.map(mapTriggerGroup)
|
|
1003
|
+
};
|
|
1004
|
+
});
|
|
1005
|
+
manager.onRequest("slates/trigger_group.get", async ({ params }) => {
|
|
1006
|
+
getContextBasic();
|
|
1007
|
+
let triggerGroup = getTriggerGroup(slate, params.triggerGroupId);
|
|
1008
|
+
return {
|
|
1009
|
+
triggerGroup: mapTriggerGroup(triggerGroup)
|
|
1010
|
+
};
|
|
1011
|
+
});
|
|
1012
|
+
manager.onRequest("slates/action.tool.invoke", async ({ params }) => {
|
|
1013
|
+
let action = getActionWithType(slate, "tool", params.actionId);
|
|
1014
|
+
let input = validate(
|
|
1015
|
+
action.inputSchema,
|
|
1016
|
+
params.input,
|
|
1017
|
+
"input",
|
|
1018
|
+
`Invalid input for tool ID: ${params.actionId}`
|
|
1019
|
+
);
|
|
1020
|
+
let invoke = async (context) => {
|
|
1021
|
+
let res = await traceProviderCall(
|
|
1022
|
+
{
|
|
1023
|
+
component: "action",
|
|
1024
|
+
functionName: "handleInvocation",
|
|
1025
|
+
message: `Starting tool ${formatEntityLabel(action.name, action.key)}`,
|
|
1026
|
+
successMessage: `Completed tool ${formatEntityLabel(action.name, action.key)}`,
|
|
1027
|
+
errorMessage: `Tool ${formatEntityLabel(action.name, action.key)} failed`,
|
|
1028
|
+
metadata: {
|
|
1029
|
+
actionId: action.key,
|
|
1030
|
+
actionName: action.name,
|
|
1031
|
+
actionType: action.type,
|
|
1032
|
+
isPublic: action.isPublic,
|
|
1033
|
+
inputKeyCount: getObjectKeyCount(input)
|
|
1034
|
+
},
|
|
1035
|
+
onSuccess: (result) => ({
|
|
1036
|
+
hasMessage: !!result.message,
|
|
1037
|
+
actionResultMessage: result.message,
|
|
1038
|
+
outputKeyCount: getObjectKeyCount(result.output),
|
|
1039
|
+
attachmentCount: result.attachments?.length
|
|
1040
|
+
})
|
|
1041
|
+
},
|
|
1042
|
+
() => (0, import_provider2.runWithContext)(context, () => action.handleInvocation(context))
|
|
1043
|
+
);
|
|
1044
|
+
let contextAttachments = await context._finalizeAttachments();
|
|
1045
|
+
let merged = mergeAttachments(
|
|
1046
|
+
[...res.attachments ?? [], ...contextAttachments],
|
|
1047
|
+
res.output
|
|
1048
|
+
);
|
|
1049
|
+
let redacted = (0, import_provider2.redactUrlAttachmentSecrets)(
|
|
1050
|
+
merged,
|
|
1051
|
+
context._getAuthConfigForRedaction()
|
|
1052
|
+
);
|
|
1053
|
+
let finalAttachments = await routeAttachmentsThroughDirectUpload(
|
|
1054
|
+
redacted,
|
|
1055
|
+
getLiveInvocation()
|
|
1056
|
+
);
|
|
1057
|
+
return withRequestTraces(context, {
|
|
1058
|
+
output: res.output,
|
|
1059
|
+
message: res.message,
|
|
1060
|
+
attachments: finalAttachments
|
|
1061
|
+
});
|
|
1062
|
+
};
|
|
1063
|
+
if (action.isPublic) {
|
|
1064
|
+
getContextBasic();
|
|
1065
|
+
return invoke(new import_provider2.SlatePublicContext(input, slate.spec, logger, getLiveInvocation()));
|
|
1066
|
+
}
|
|
1067
|
+
let ctx = getContextFull();
|
|
1068
|
+
return invoke(
|
|
1069
|
+
new import_provider2.SlateContext(
|
|
1070
|
+
ctx.config,
|
|
1071
|
+
input,
|
|
1072
|
+
ctx.auth?.output,
|
|
1073
|
+
slate.spec,
|
|
1074
|
+
logger,
|
|
1075
|
+
getLiveInvocation()
|
|
1076
|
+
)
|
|
1077
|
+
);
|
|
1078
|
+
});
|
|
1079
|
+
manager.onRequest("slates/action.trigger.map_event", async ({ params }) => {
|
|
1080
|
+
let ctx = getContextFull();
|
|
1081
|
+
let action = getActionWithType(slate, "trigger", params.actionId);
|
|
1082
|
+
let input = validate(
|
|
1083
|
+
action.inputSchema,
|
|
1084
|
+
params.input,
|
|
1085
|
+
"input",
|
|
1086
|
+
`Invalid event for trigger ID: ${params.actionId}`
|
|
1087
|
+
);
|
|
1088
|
+
let context = new import_provider2.SlateContext(ctx.config, input, ctx.auth?.output, slate.spec, logger);
|
|
1089
|
+
let res = await traceProviderCall(
|
|
1090
|
+
{
|
|
1091
|
+
component: "action",
|
|
1092
|
+
functionName: "handleEvent",
|
|
1093
|
+
message: `Mapping event for trigger ${formatEntityLabel(action.name, action.key)}`,
|
|
1094
|
+
successMessage: (result) => `Mapped trigger event "${result.type}" for ${formatEntityLabel(action.name, action.key)}`,
|
|
1095
|
+
errorMessage: `Trigger ${formatEntityLabel(action.name, action.key)} failed while mapping an event`,
|
|
1096
|
+
metadata: {
|
|
1097
|
+
actionId: action.key,
|
|
1098
|
+
actionName: action.name,
|
|
1099
|
+
actionType: action.type,
|
|
1100
|
+
inputKeyCount: getObjectKeyCount(input)
|
|
1101
|
+
},
|
|
1102
|
+
onSuccess: (result) => ({
|
|
1103
|
+
eventType: result.type,
|
|
1104
|
+
hasEventId: !!result.id,
|
|
1105
|
+
outputKeyCount: getObjectKeyCount(result.output)
|
|
1106
|
+
})
|
|
1107
|
+
},
|
|
1108
|
+
() => (0, import_provider2.runWithContext)(context, () => action.map(context))
|
|
1109
|
+
);
|
|
1110
|
+
return withRequestTraces(context, { id: res.id, type: res.type, output: res.output });
|
|
1111
|
+
});
|
|
1112
|
+
manager.onRequest("slates/action.trigger.poll_events", async ({ params }) => {
|
|
1113
|
+
getContextBasic();
|
|
1114
|
+
if (supportsTriggerGroups()) {
|
|
1115
|
+
throw new import_error4.ServiceError(
|
|
1116
|
+
(0, import_error4.badRequestError)({
|
|
1117
|
+
message: `Legacy trigger polling is disabled once trigger_group support is announced: ${params.actionId}`
|
|
1118
|
+
})
|
|
1119
|
+
);
|
|
1120
|
+
}
|
|
1121
|
+
return { inputs: [], updatedState: params.state };
|
|
1122
|
+
});
|
|
1123
|
+
manager.onRequest("slates/action.trigger.webhook_handle", async ({ params }) => {
|
|
1124
|
+
getContextBasic();
|
|
1125
|
+
if (supportsTriggerGroups()) {
|
|
1126
|
+
throw new import_error4.ServiceError(
|
|
1127
|
+
(0, import_error4.badRequestError)({
|
|
1128
|
+
message: `Legacy trigger webhook handling is disabled once trigger_group support is announced: ${params.actionId}`
|
|
1129
|
+
})
|
|
1130
|
+
);
|
|
1131
|
+
}
|
|
1132
|
+
return { inputs: [], updatedState: params.state, response: null };
|
|
1133
|
+
});
|
|
1134
|
+
manager.onRequest("slates/action.trigger.webhook_register", async ({ params }) => {
|
|
1135
|
+
getContextBasic();
|
|
1136
|
+
if (supportsTriggerGroups()) {
|
|
1137
|
+
throw new import_error4.ServiceError(
|
|
1138
|
+
(0, import_error4.badRequestError)({
|
|
1139
|
+
message: `Legacy trigger webhook registration is disabled once trigger_group support is announced: ${params.actionId}`
|
|
1140
|
+
})
|
|
1141
|
+
);
|
|
1142
|
+
}
|
|
1143
|
+
return { registrationDetails: null };
|
|
1144
|
+
});
|
|
1145
|
+
manager.onRequest("slates/action.trigger.webhook_unregister", async ({ params }) => {
|
|
1146
|
+
getContextBasic();
|
|
1147
|
+
if (supportsTriggerGroups()) {
|
|
1148
|
+
throw new import_error4.ServiceError(
|
|
1149
|
+
(0, import_error4.badRequestError)({
|
|
1150
|
+
message: `Legacy trigger webhook unregistration is disabled once trigger_group support is announced: ${params.actionId}`
|
|
1151
|
+
})
|
|
1152
|
+
);
|
|
1153
|
+
}
|
|
1154
|
+
return {};
|
|
1155
|
+
});
|
|
1156
|
+
manager.onRequest("slates/trigger_group.webhook.targets_list", async ({ params }) => {
|
|
1157
|
+
let ctx = getContextFull();
|
|
1158
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1159
|
+
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1160
|
+
let context = new import_provider2.SlateContext(
|
|
1161
|
+
ctx.config,
|
|
1162
|
+
{ pageToken: params.pageToken ?? null },
|
|
1163
|
+
ctx.auth?.output,
|
|
1164
|
+
slate.spec,
|
|
1165
|
+
logger
|
|
1166
|
+
);
|
|
1167
|
+
let res = await traceProviderCall(
|
|
1168
|
+
{
|
|
1169
|
+
component: "action",
|
|
1170
|
+
functionName: "webhookTargetList",
|
|
1171
|
+
message: `Listing webhook targets for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1172
|
+
successMessage: (result) => `Listed ${result.targets.length} webhook target(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1173
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while listing webhook targets`,
|
|
1174
|
+
metadata: {
|
|
1175
|
+
triggerGroupId: group.key,
|
|
1176
|
+
triggerGroupName: group.name
|
|
1177
|
+
},
|
|
1178
|
+
onSuccess: (result) => ({
|
|
1179
|
+
targetCount: result.targets.length,
|
|
1180
|
+
hasNextPageToken: result.nextPageToken !== null
|
|
1181
|
+
})
|
|
1182
|
+
},
|
|
1183
|
+
() => (0, import_provider2.runWithContext)(context, () => autoRegistration.webhookTargetList(context))
|
|
1184
|
+
);
|
|
1185
|
+
return withRequestTraces(context, {
|
|
1186
|
+
targets: res.targets,
|
|
1187
|
+
nextPageToken: res.nextPageToken ?? null
|
|
1188
|
+
});
|
|
1189
|
+
});
|
|
1190
|
+
manager.onRequest("slates/trigger_group.webhook.register", async ({ params }) => {
|
|
1191
|
+
let ctx = getContextFull();
|
|
1192
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1193
|
+
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1194
|
+
let context = new import_provider2.SlateContext(
|
|
1195
|
+
ctx.config,
|
|
1196
|
+
{
|
|
1197
|
+
webhookTargetIdentifier: params.webhookTargetIdentifier,
|
|
1198
|
+
webhookTargetPayload: params.webhookTargetPayload,
|
|
1199
|
+
webhookUrl: params.webhookUrl
|
|
1200
|
+
},
|
|
1201
|
+
ctx.auth?.output,
|
|
1202
|
+
slate.spec,
|
|
1203
|
+
logger
|
|
1204
|
+
);
|
|
1205
|
+
let res = await traceProviderCall(
|
|
1206
|
+
{
|
|
1207
|
+
component: "action",
|
|
1208
|
+
functionName: "webhookRegister",
|
|
1209
|
+
message: `Registering webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1210
|
+
successMessage: `Registered webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1211
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while registering a webhook`,
|
|
1212
|
+
metadata: {
|
|
1213
|
+
triggerGroupId: group.key,
|
|
1214
|
+
triggerGroupName: group.name,
|
|
1215
|
+
webhookTargetIdentifier: params.webhookTargetIdentifier
|
|
1216
|
+
}
|
|
1217
|
+
},
|
|
1218
|
+
() => (0, import_provider2.runWithContext)(context, () => autoRegistration.webhookRegister(context))
|
|
1219
|
+
);
|
|
1220
|
+
return withRequestTraces(context, {
|
|
1221
|
+
webhookRegistrationIdentifier: res.webhookRegistrationIdentifier,
|
|
1222
|
+
webhookRegistrationPayload: res.webhookRegistrationPayload
|
|
1223
|
+
});
|
|
1224
|
+
});
|
|
1225
|
+
manager.onRequest("slates/trigger_group.webhook.unregister", async ({ params }) => {
|
|
1226
|
+
let ctx = getContextFull();
|
|
1227
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1228
|
+
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1229
|
+
let context = new import_provider2.SlateContext(
|
|
1230
|
+
ctx.config,
|
|
1231
|
+
{
|
|
1232
|
+
webhookRegistrationIdentifier: params.webhookRegistrationIdentifier,
|
|
1233
|
+
webhookRegistrationPayload: params.webhookRegistrationPayload
|
|
1234
|
+
},
|
|
1235
|
+
ctx.auth?.output,
|
|
1236
|
+
slate.spec,
|
|
1237
|
+
logger
|
|
1238
|
+
);
|
|
1239
|
+
await traceProviderCall(
|
|
1240
|
+
{
|
|
1241
|
+
component: "action",
|
|
1242
|
+
functionName: "webhookUnregister",
|
|
1243
|
+
message: `Unregistering webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1244
|
+
successMessage: `Unregistered webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1245
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while unregistering a webhook`,
|
|
1246
|
+
metadata: {
|
|
1247
|
+
triggerGroupId: group.key,
|
|
1248
|
+
triggerGroupName: group.name,
|
|
1249
|
+
webhookRegistrationIdentifier: params.webhookRegistrationIdentifier
|
|
1250
|
+
}
|
|
1251
|
+
},
|
|
1252
|
+
() => (0, import_provider2.runWithContext)(context, () => autoRegistration.webhookUnregister(context))
|
|
1253
|
+
);
|
|
1254
|
+
return withRequestTraces(context, {});
|
|
1255
|
+
});
|
|
1256
|
+
manager.onRequest("slates/trigger_group.webhook.manual_setup", async ({ params }) => {
|
|
1257
|
+
getContextBasic();
|
|
1258
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1259
|
+
let manualRegistration = getWebhookManualRegistration(group);
|
|
1260
|
+
let context = new import_provider2.SlateContext(
|
|
1261
|
+
{},
|
|
1262
|
+
{ webhookUrl: params.webhookUrl },
|
|
1263
|
+
{},
|
|
1264
|
+
slate.spec,
|
|
1265
|
+
logger
|
|
1266
|
+
);
|
|
1267
|
+
let res = await traceProviderCall(
|
|
1268
|
+
{
|
|
1269
|
+
component: "action",
|
|
1270
|
+
functionName: "webhookManualSetup",
|
|
1271
|
+
message: `Building manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1272
|
+
successMessage: `Built manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1273
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while building a manual webhook setup`,
|
|
1274
|
+
metadata: {
|
|
1275
|
+
triggerGroupId: group.key,
|
|
1276
|
+
triggerGroupName: group.name
|
|
1277
|
+
}
|
|
1278
|
+
},
|
|
1279
|
+
() => (0, import_provider2.runWithContext)(context, () => manualRegistration.setup(context))
|
|
1280
|
+
);
|
|
1281
|
+
return {
|
|
1282
|
+
webhookSetupDocument: res.webhookSetupDocument,
|
|
1283
|
+
partialWebhookRegistrationPayload: res.partialWebhookRegistrationPayload
|
|
1284
|
+
};
|
|
1285
|
+
});
|
|
1286
|
+
manager.onRequest("slates/trigger_group.webhook.manual_finish", async ({ params }) => {
|
|
1287
|
+
getContextBasic();
|
|
1288
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1289
|
+
let manualRegistration = getWebhookManualRegistration(group);
|
|
1290
|
+
if (!manualRegistration.finish) {
|
|
1291
|
+
throw new import_error4.ServiceError(
|
|
1292
|
+
(0, import_error4.badRequestError)({
|
|
1293
|
+
message: `Trigger group does not support manual webhook finish: ${params.triggerGroupId}`
|
|
1294
|
+
})
|
|
1295
|
+
);
|
|
1296
|
+
}
|
|
1297
|
+
let context = new import_provider2.SlateContext(
|
|
1298
|
+
{},
|
|
1299
|
+
{
|
|
1300
|
+
webhookUrl: params.webhookUrl,
|
|
1301
|
+
partialWebhookRegistrationPayload: params.partialWebhookRegistrationPayload,
|
|
1302
|
+
userWebhookRegistrationPayload: params.userWebhookRegistrationPayload
|
|
1303
|
+
},
|
|
1304
|
+
{},
|
|
1305
|
+
slate.spec,
|
|
1306
|
+
logger
|
|
1307
|
+
);
|
|
1308
|
+
let res = await traceProviderCall(
|
|
1309
|
+
{
|
|
1310
|
+
component: "action",
|
|
1311
|
+
functionName: "webhookManualFinish",
|
|
1312
|
+
message: `Finishing manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1313
|
+
successMessage: `Finished manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1314
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while finishing a manual webhook setup`,
|
|
1315
|
+
metadata: {
|
|
1316
|
+
triggerGroupId: group.key,
|
|
1317
|
+
triggerGroupName: group.name
|
|
1318
|
+
}
|
|
1319
|
+
},
|
|
1320
|
+
() => (0, import_provider2.runWithContext)(context, () => manualRegistration.finish(context))
|
|
1321
|
+
);
|
|
1322
|
+
return withRequestTraces(context, {
|
|
1323
|
+
webhookRegistrationPayload: res.webhookRegistrationPayload
|
|
1324
|
+
});
|
|
1325
|
+
});
|
|
1326
|
+
manager.onRequest("slates/trigger_group.webhook.process", async ({ params }) => {
|
|
1327
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1328
|
+
if (group.source !== "webhook" || !group.webhook) {
|
|
1329
|
+
throw new import_error4.ServiceError(
|
|
1330
|
+
(0, import_error4.badRequestError)({
|
|
1331
|
+
message: `Trigger group does not support webhook processing: ${params.triggerGroupId}`
|
|
1332
|
+
})
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
let req = new Request(params.url, {
|
|
1336
|
+
method: params.method,
|
|
1337
|
+
headers: params.headers,
|
|
1338
|
+
body: params.body ? Uint8Array.from(atob(params.body.content), (c) => c.charCodeAt(0)) : null
|
|
1339
|
+
});
|
|
1340
|
+
let context = new import_provider2.SlateContext(
|
|
1341
|
+
{},
|
|
1342
|
+
{
|
|
1343
|
+
request: req,
|
|
1344
|
+
webhookRegistrationPayload: params.webhookRegistrationPayload
|
|
1345
|
+
},
|
|
1346
|
+
{},
|
|
1347
|
+
slate.spec,
|
|
1348
|
+
logger
|
|
1349
|
+
);
|
|
1350
|
+
let res = await traceProviderCall(
|
|
1351
|
+
{
|
|
1352
|
+
component: "action",
|
|
1353
|
+
functionName: "webhookProcess",
|
|
1354
|
+
message: `Processing webhook request for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1355
|
+
successMessage: (result) => `Extracted ${result.events.length} event(s) from webhook request for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1356
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while processing a webhook request`,
|
|
1357
|
+
metadata: {
|
|
1358
|
+
triggerGroupId: group.key,
|
|
1359
|
+
triggerGroupName: group.name,
|
|
1360
|
+
requestMethod: params.method,
|
|
1361
|
+
hasRequestBody: !!params.body
|
|
1362
|
+
},
|
|
1363
|
+
onSuccess: (result) => ({
|
|
1364
|
+
eventCount: result.events.length,
|
|
1365
|
+
hasResponse: result.response !== void 0
|
|
1366
|
+
})
|
|
1367
|
+
},
|
|
1368
|
+
() => (0, import_provider2.runWithContext)(context, () => group.webhook.process(context))
|
|
1369
|
+
);
|
|
1370
|
+
for (let event of res.events) {
|
|
1371
|
+
if (!event.matchers) {
|
|
1372
|
+
throw new import_error4.ServiceError(
|
|
1373
|
+
(0, import_error4.preconditionFailedError)({
|
|
1374
|
+
message: `Trigger group "${group.key}" process handler must return matchers for every event (return [] if there is nothing to assert)`
|
|
1375
|
+
})
|
|
1376
|
+
);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
let response = res.response === void 0 ? void 0 : await serializeWebhookHttpResponse(res.response);
|
|
1380
|
+
return withRequestTraces(context, {
|
|
1381
|
+
events: res.events.map((event) => ({
|
|
1382
|
+
matchers: event.matchers,
|
|
1383
|
+
payload: event.payload,
|
|
1384
|
+
idempotencyKey: event.idempotencyKey,
|
|
1385
|
+
triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
|
|
1386
|
+
})),
|
|
1387
|
+
response
|
|
1388
|
+
});
|
|
1389
|
+
});
|
|
1390
|
+
manager.onRequest("slates/trigger_group.routing_matchers.get", async ({ params }) => {
|
|
1391
|
+
let ctx = getContextFull();
|
|
1392
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1393
|
+
let context = new import_provider2.SlateContext(ctx.config, {}, ctx.auth?.output, slate.spec, logger);
|
|
1394
|
+
let matchers = await traceProviderCall(
|
|
1395
|
+
{
|
|
1396
|
+
component: "action",
|
|
1397
|
+
functionName: "routingMatchers",
|
|
1398
|
+
message: `Getting routing matchers for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1399
|
+
successMessage: (result) => `Retrieved ${result.length} routing matcher(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1400
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while getting routing matchers`,
|
|
1401
|
+
metadata: {
|
|
1402
|
+
triggerGroupId: group.key,
|
|
1403
|
+
triggerGroupName: group.name
|
|
1404
|
+
},
|
|
1405
|
+
onSuccess: (result) => ({
|
|
1406
|
+
matcherCount: result.length
|
|
1407
|
+
})
|
|
1408
|
+
},
|
|
1409
|
+
() => (0, import_provider2.runWithContext)(context, () => group.routingMatchers(context))
|
|
1410
|
+
);
|
|
1411
|
+
return withRequestTraces(context, { matchers });
|
|
1412
|
+
});
|
|
1413
|
+
manager.onRequest("slates/trigger_group.polling.poll", async ({ params }) => {
|
|
1414
|
+
let ctx = getContextFull();
|
|
1415
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1416
|
+
if (group.source !== "polling" || !group.polling) {
|
|
1417
|
+
throw new import_error4.ServiceError(
|
|
1418
|
+
(0, import_error4.badRequestError)({
|
|
1419
|
+
message: `Trigger group does not support polling: ${params.triggerGroupId}`
|
|
1420
|
+
})
|
|
1421
|
+
);
|
|
1422
|
+
}
|
|
1423
|
+
let context = new import_provider2.SlateContext(
|
|
1424
|
+
ctx.config,
|
|
1425
|
+
{ state: params.state },
|
|
1426
|
+
ctx.auth?.output,
|
|
1427
|
+
slate.spec,
|
|
1428
|
+
logger
|
|
1429
|
+
);
|
|
1430
|
+
let res = await traceProviderCall(
|
|
1431
|
+
{
|
|
1432
|
+
component: "action",
|
|
1433
|
+
functionName: "pollEvents",
|
|
1434
|
+
message: `Polling events for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1435
|
+
successMessage: (result) => `Polled ${result.events.length} event(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1436
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while polling events`,
|
|
1437
|
+
metadata: {
|
|
1438
|
+
triggerGroupId: group.key,
|
|
1439
|
+
triggerGroupName: group.name,
|
|
1440
|
+
hasPreviousState: params.state !== null
|
|
1441
|
+
},
|
|
1442
|
+
onSuccess: (result) => ({
|
|
1443
|
+
eventCount: result.events.length,
|
|
1444
|
+
hasUpdatedState: result.updatedState !== void 0
|
|
1445
|
+
})
|
|
1446
|
+
},
|
|
1447
|
+
() => (0, import_provider2.runWithContext)(context, () => group.polling.pollEvents(context))
|
|
1448
|
+
);
|
|
1449
|
+
return withRequestTraces(context, {
|
|
1450
|
+
updatedState: res.updatedState,
|
|
1451
|
+
events: res.events.map((event) => ({
|
|
1452
|
+
payload: event.payload,
|
|
1453
|
+
idempotencyKey: event.idempotencyKey,
|
|
1454
|
+
triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
|
|
1455
|
+
}))
|
|
1456
|
+
});
|
|
1457
|
+
});
|
|
1458
|
+
});
|
|
1459
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1460
|
+
0 && (module.exports = {
|
|
1461
|
+
createProviderHandler
|
|
1462
|
+
});
|