@slates/provider-handler 1.0.0-rc.19 → 1.0.0-rc.20

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
@@ -118,6 +118,18 @@ var getAction = (slate, actionId) => {
118
118
  }
119
119
  return action;
120
120
  };
121
+ var getAdapter = (slate, adapterId) => {
122
+ let adapter = slate.adapters.find((m) => m.id === adapterId);
123
+ if (!adapter) {
124
+ throw new import_error2.ServiceError((0, import_error2.notFoundError)(`adapter`, adapterId));
125
+ }
126
+ return adapter;
127
+ };
128
+ var mapAdapter = (adapter) => ({
129
+ id: adapter.id,
130
+ name: adapter.name,
131
+ capabilities: adapter.capabilities
132
+ });
121
133
  var getActionWithType = (slate, type, actionId) => {
122
134
  let action = getAction(slate, actionId);
123
135
  if (action.type !== type) {
@@ -141,6 +153,7 @@ var mapAction = (_slate, a) => {
141
153
  scopes: a.scopes,
142
154
  authMethods: a.authMethods,
143
155
  docs: a.docs ?? [],
156
+ ...a.adapter ? { adapter: a.adapter } : {},
144
157
  inputSchema: toJsonSchema(a.inputSchema),
145
158
  outputSchema: toJsonSchema(a.outputSchema)
146
159
  };
@@ -148,7 +161,8 @@ var mapAction = (_slate, a) => {
148
161
  return {
149
162
  ...base,
150
163
  type: "action.tool",
151
- capabilities: {}
164
+ capabilities: {},
165
+ isPublic: a.isPublic
152
166
  };
153
167
  }
154
168
  return {
@@ -833,10 +847,24 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
833
847
  })
834
848
  );
835
849
  });
836
- manager.onRequest("slates/actions.list", async () => {
850
+ manager.onRequest("slates/actions.list", async ({ params }) => {
851
+ getContextBasic();
852
+ let actions = params.includeAdapterActions ? slate.actions : slate.actions.filter((action) => !action.adapter);
853
+ return {
854
+ actions: actions.map((a) => mapAction(slate, a))
855
+ };
856
+ });
857
+ manager.onRequest("slates/adapters.list", async () => {
858
+ getContextBasic();
859
+ return {
860
+ adapters: slate.adapters.map(mapAdapter)
861
+ };
862
+ });
863
+ manager.onRequest("slates/adapter.get", async ({ params }) => {
837
864
  getContextBasic();
865
+ let adapter = getAdapter(slate, params.adapterId);
838
866
  return {
839
- actions: slate.actions.map((a) => mapAction(slate, a))
867
+ adapter: mapAdapter(adapter)
840
868
  };
841
869
  });
842
870
  manager.onRequest("slates/action.get", async ({ params }) => {
@@ -847,7 +875,6 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
847
875
  };
848
876
  });
849
877
  manager.onRequest("slates/action.tool.invoke", async ({ params }) => {
850
- let ctx = getContextFull();
851
878
  let action = getActionWithType(slate, "tool", params.actionId);
852
879
  let input = validate(
853
880
  action.inputSchema,
@@ -855,34 +882,44 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
855
882
  "input",
856
883
  `Invalid input for tool ID: ${params.actionId}`
857
884
  );
858
- let context = new import_provider2.SlateContext(ctx.config, input, ctx.auth?.output, slate.spec, logger);
859
- let res = await traceProviderCall(
860
- {
861
- component: "action",
862
- functionName: "handleInvocation",
863
- message: `Starting tool ${formatEntityLabel(action.name, action.key)}`,
864
- successMessage: `Completed tool ${formatEntityLabel(action.name, action.key)}`,
865
- errorMessage: `Tool ${formatEntityLabel(action.name, action.key)} failed`,
866
- metadata: {
867
- actionId: action.key,
868
- actionName: action.name,
869
- actionType: action.type,
870
- inputKeyCount: getObjectKeyCount(input)
885
+ let invoke = async (context) => {
886
+ let res = await traceProviderCall(
887
+ {
888
+ component: "action",
889
+ functionName: "handleInvocation",
890
+ message: `Starting tool ${formatEntityLabel(action.name, action.key)}`,
891
+ successMessage: `Completed tool ${formatEntityLabel(action.name, action.key)}`,
892
+ errorMessage: `Tool ${formatEntityLabel(action.name, action.key)} failed`,
893
+ metadata: {
894
+ actionId: action.key,
895
+ actionName: action.name,
896
+ actionType: action.type,
897
+ isPublic: action.isPublic,
898
+ inputKeyCount: getObjectKeyCount(input)
899
+ },
900
+ onSuccess: (result) => ({
901
+ hasMessage: !!result.message,
902
+ actionResultMessage: result.message,
903
+ outputKeyCount: getObjectKeyCount(result.output),
904
+ attachmentCount: result.attachments?.length
905
+ })
871
906
  },
872
- onSuccess: (result) => ({
873
- hasMessage: !!result.message,
874
- actionResultMessage: result.message,
875
- outputKeyCount: getObjectKeyCount(result.output),
876
- attachmentCount: result.attachments?.length
877
- })
878
- },
879
- () => (0, import_provider2.runWithContext)(context, () => action.handleInvocation(context))
907
+ () => (0, import_provider2.runWithContext)(context, () => action.handleInvocation(context))
908
+ );
909
+ return withRequestTraces(context, {
910
+ output: res.output,
911
+ message: res.message,
912
+ attachments: mergeAttachments(res.attachments, res.output)
913
+ });
914
+ };
915
+ if (action.isPublic) {
916
+ getContextBasic();
917
+ return invoke(new import_provider2.SlatePublicContext(input, slate.spec, logger));
918
+ }
919
+ let ctx = getContextFull();
920
+ return invoke(
921
+ new import_provider2.SlateContext(ctx.config, input, ctx.auth?.output, slate.spec, logger)
880
922
  );
881
- return withRequestTraces(context, {
882
- output: res.output,
883
- message: res.message,
884
- attachments: mergeAttachments(res.attachments, res.output)
885
- });
886
923
  });
887
924
  manager.onRequest("slates/action.trigger.map_event", async ({ params }) => {
888
925
  let ctx = getContextFull();
@@ -7,12 +7,15 @@ import {
7
7
  import {
8
8
  runWithContext,
9
9
  SlateContext,
10
- SlateLogger
10
+ SlateLogger,
11
+ SlatePublicContext
11
12
  } from "@slates/provider";
12
13
 
13
14
  // src/spec.ts
14
15
  import { badRequestError, notFoundError, ServiceError as ServiceError2 } from "@lowerdeck/error";
15
- import { SlateDefaultPollingIntervalSeconds } from "@slates/provider";
16
+ import {
17
+ SlateDefaultPollingIntervalSeconds
18
+ } from "@slates/provider";
16
19
  import z from "zod";
17
20
 
18
21
  // src/validation.ts
@@ -91,6 +94,18 @@ var getAction = (slate, actionId) => {
91
94
  }
92
95
  return action;
93
96
  };
97
+ var getAdapter = (slate, adapterId) => {
98
+ let adapter = slate.adapters.find((m) => m.id === adapterId);
99
+ if (!adapter) {
100
+ throw new ServiceError2(notFoundError(`adapter`, adapterId));
101
+ }
102
+ return adapter;
103
+ };
104
+ var mapAdapter = (adapter) => ({
105
+ id: adapter.id,
106
+ name: adapter.name,
107
+ capabilities: adapter.capabilities
108
+ });
94
109
  var getActionWithType = (slate, type, actionId) => {
95
110
  let action = getAction(slate, actionId);
96
111
  if (action.type !== type) {
@@ -114,6 +129,7 @@ var mapAction = (_slate, a) => {
114
129
  scopes: a.scopes,
115
130
  authMethods: a.authMethods,
116
131
  docs: a.docs ?? [],
132
+ ...a.adapter ? { adapter: a.adapter } : {},
117
133
  inputSchema: toJsonSchema(a.inputSchema),
118
134
  outputSchema: toJsonSchema(a.outputSchema)
119
135
  };
@@ -121,7 +137,8 @@ var mapAction = (_slate, a) => {
121
137
  return {
122
138
  ...base,
123
139
  type: "action.tool",
124
- capabilities: {}
140
+ capabilities: {},
141
+ isPublic: a.isPublic
125
142
  };
126
143
  }
127
144
  return {
@@ -806,10 +823,24 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
806
823
  })
807
824
  );
808
825
  });
809
- manager.onRequest("slates/actions.list", async () => {
826
+ manager.onRequest("slates/actions.list", async ({ params }) => {
810
827
  getContextBasic();
828
+ let actions = params.includeAdapterActions ? slate.actions : slate.actions.filter((action) => !action.adapter);
811
829
  return {
812
- actions: slate.actions.map((a) => mapAction(slate, a))
830
+ actions: actions.map((a) => mapAction(slate, a))
831
+ };
832
+ });
833
+ manager.onRequest("slates/adapters.list", async () => {
834
+ getContextBasic();
835
+ return {
836
+ adapters: slate.adapters.map(mapAdapter)
837
+ };
838
+ });
839
+ manager.onRequest("slates/adapter.get", async ({ params }) => {
840
+ getContextBasic();
841
+ let adapter = getAdapter(slate, params.adapterId);
842
+ return {
843
+ adapter: mapAdapter(adapter)
813
844
  };
814
845
  });
815
846
  manager.onRequest("slates/action.get", async ({ params }) => {
@@ -820,7 +851,6 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
820
851
  };
821
852
  });
822
853
  manager.onRequest("slates/action.tool.invoke", async ({ params }) => {
823
- let ctx = getContextFull();
824
854
  let action = getActionWithType(slate, "tool", params.actionId);
825
855
  let input = validate(
826
856
  action.inputSchema,
@@ -828,34 +858,44 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
828
858
  "input",
829
859
  `Invalid input for tool ID: ${params.actionId}`
830
860
  );
831
- let context = new SlateContext(ctx.config, input, ctx.auth?.output, slate.spec, logger);
832
- let res = await traceProviderCall(
833
- {
834
- component: "action",
835
- functionName: "handleInvocation",
836
- message: `Starting tool ${formatEntityLabel(action.name, action.key)}`,
837
- successMessage: `Completed tool ${formatEntityLabel(action.name, action.key)}`,
838
- errorMessage: `Tool ${formatEntityLabel(action.name, action.key)} failed`,
839
- metadata: {
840
- actionId: action.key,
841
- actionName: action.name,
842
- actionType: action.type,
843
- inputKeyCount: getObjectKeyCount(input)
861
+ let invoke = async (context) => {
862
+ let res = await traceProviderCall(
863
+ {
864
+ component: "action",
865
+ functionName: "handleInvocation",
866
+ message: `Starting tool ${formatEntityLabel(action.name, action.key)}`,
867
+ successMessage: `Completed tool ${formatEntityLabel(action.name, action.key)}`,
868
+ errorMessage: `Tool ${formatEntityLabel(action.name, action.key)} failed`,
869
+ metadata: {
870
+ actionId: action.key,
871
+ actionName: action.name,
872
+ actionType: action.type,
873
+ isPublic: action.isPublic,
874
+ inputKeyCount: getObjectKeyCount(input)
875
+ },
876
+ onSuccess: (result) => ({
877
+ hasMessage: !!result.message,
878
+ actionResultMessage: result.message,
879
+ outputKeyCount: getObjectKeyCount(result.output),
880
+ attachmentCount: result.attachments?.length
881
+ })
844
882
  },
845
- onSuccess: (result) => ({
846
- hasMessage: !!result.message,
847
- actionResultMessage: result.message,
848
- outputKeyCount: getObjectKeyCount(result.output),
849
- attachmentCount: result.attachments?.length
850
- })
851
- },
852
- () => runWithContext(context, () => action.handleInvocation(context))
883
+ () => runWithContext(context, () => action.handleInvocation(context))
884
+ );
885
+ return withRequestTraces(context, {
886
+ output: res.output,
887
+ message: res.message,
888
+ attachments: mergeAttachments(res.attachments, res.output)
889
+ });
890
+ };
891
+ if (action.isPublic) {
892
+ getContextBasic();
893
+ return invoke(new SlatePublicContext(input, slate.spec, logger));
894
+ }
895
+ let ctx = getContextFull();
896
+ return invoke(
897
+ new SlateContext(ctx.config, input, ctx.auth?.output, slate.spec, logger)
853
898
  );
854
- return withRequestTraces(context, {
855
- output: res.output,
856
- message: res.message,
857
- attachments: mergeAttachments(res.attachments, res.output)
858
- });
859
899
  });
860
900
  manager.onRequest("slates/action.trigger.map_event", async ({ params }) => {
861
901
  let ctx = getContextFull();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slates/provider-handler",
3
- "version": "1.0.0-rc.19",
3
+ "version": "1.0.0-rc.20",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -33,7 +33,7 @@
33
33
  "dependencies": {
34
34
  "@lowerdeck/error": "^1.1.0",
35
35
  "@slates/proto": "1.0.0-rc.13",
36
- "@slates/provider": "1.0.0-rc.17",
36
+ "@slates/provider": "1.0.0-rc.18",
37
37
  "zod": "^4.2.1"
38
38
  },
39
39
  "devDependencies": {
package/src/index.ts CHANGED
@@ -10,9 +10,18 @@ import {
10
10
  type SlateAttachment,
11
11
  SlateContext,
12
12
  SlateLogger,
13
- type SlateLogListener
13
+ type SlateLogListener,
14
+ SlatePublicContext
14
15
  } from '@slates/provider';
15
- import { getAction, getActionWithType, getAuthMethod, mapAction, mapAuthMethod } from './spec';
16
+ import {
17
+ getAction,
18
+ getActionWithType,
19
+ getAdapter,
20
+ getAuthMethod,
21
+ mapAction,
22
+ mapAdapter,
23
+ mapAuthMethod
24
+ } from './spec';
16
25
  import { State } from './state';
17
26
  import { toJsonSchema, validate } from './validation';
18
27
  import { serializeWebhookHttpResponse } from './webhook';
@@ -232,7 +241,7 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
232
241
  let getAuthContext = () =>
233
242
  new SlateContext(getAuthConfig(), {}, {}, slate.spec as any, logger);
234
243
  let withRequestTraces = <Result extends Record<string, any>>(
235
- context: SlateContext<any, any, any>,
244
+ context: SlatePublicContext<any>,
236
245
  result: Result
237
246
  ) => {
238
247
  let requestTraces = context.getHttpTraces();
@@ -746,11 +755,32 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
746
755
  );
747
756
  });
748
757
 
749
- manager.onRequest('slates/actions.list', async () => {
758
+ manager.onRequest('slates/actions.list', async ({ params }) => {
759
+ getContextBasic();
760
+
761
+ let actions = params.includeAdapterActions
762
+ ? slate.actions
763
+ : slate.actions.filter(action => !action.adapter);
764
+
765
+ return {
766
+ actions: actions.map(a => mapAction(slate, a))
767
+ };
768
+ });
769
+
770
+ manager.onRequest('slates/adapters.list', async () => {
750
771
  getContextBasic();
751
772
 
752
773
  return {
753
- actions: slate.actions.map(a => mapAction(slate, a))
774
+ adapters: slate.adapters.map(mapAdapter)
775
+ };
776
+ });
777
+
778
+ manager.onRequest('slates/adapter.get', async ({ params }) => {
779
+ getContextBasic();
780
+ let adapter = getAdapter(slate, params.adapterId);
781
+
782
+ return {
783
+ adapter: mapAdapter(adapter)
754
784
  };
755
785
  });
756
786
 
@@ -764,7 +794,6 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
764
794
  });
765
795
 
766
796
  manager.onRequest('slates/action.tool.invoke', async ({ params }) => {
767
- let ctx = getContextFull();
768
797
  let action = getActionWithType(slate, 'tool', params.actionId);
769
798
 
770
799
  let input = validate(
@@ -774,35 +803,47 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
774
803
  `Invalid input for tool ID: ${params.actionId}`
775
804
  );
776
805
 
777
- let context = new SlateContext(ctx.config, input, ctx.auth?.output!, slate.spec, logger);
778
- let res = await traceProviderCall(
779
- {
780
- component: 'action',
781
- functionName: 'handleInvocation',
782
- message: `Starting tool ${formatEntityLabel(action.name, action.key)}`,
783
- successMessage: `Completed tool ${formatEntityLabel(action.name, action.key)}`,
784
- errorMessage: `Tool ${formatEntityLabel(action.name, action.key)} failed`,
785
- metadata: {
786
- actionId: action.key,
787
- actionName: action.name,
788
- actionType: action.type,
789
- inputKeyCount: getObjectKeyCount(input)
806
+ let invoke = async (context: SlatePublicContext<any>) => {
807
+ let res = await traceProviderCall(
808
+ {
809
+ component: 'action',
810
+ functionName: 'handleInvocation',
811
+ message: `Starting tool ${formatEntityLabel(action.name, action.key)}`,
812
+ successMessage: `Completed tool ${formatEntityLabel(action.name, action.key)}`,
813
+ errorMessage: `Tool ${formatEntityLabel(action.name, action.key)} failed`,
814
+ metadata: {
815
+ actionId: action.key,
816
+ actionName: action.name,
817
+ actionType: action.type,
818
+ isPublic: action.isPublic,
819
+ inputKeyCount: getObjectKeyCount(input)
820
+ },
821
+ onSuccess: result => ({
822
+ hasMessage: !!result.message,
823
+ actionResultMessage: result.message,
824
+ outputKeyCount: getObjectKeyCount(result.output),
825
+ attachmentCount: result.attachments?.length
826
+ })
790
827
  },
791
- onSuccess: result => ({
792
- hasMessage: !!result.message,
793
- actionResultMessage: result.message,
794
- outputKeyCount: getObjectKeyCount(result.output),
795
- attachmentCount: result.attachments?.length
796
- })
797
- },
798
- () => runWithContext(context, () => action.handleInvocation(context))
799
- );
828
+ () => runWithContext(context, () => action.handleInvocation(context as any))
829
+ );
800
830
 
801
- return withRequestTraces(context, {
802
- output: res.output,
803
- message: res.message,
804
- attachments: mergeAttachments(res.attachments, res.output)
805
- });
831
+ return withRequestTraces(context, {
832
+ output: res.output,
833
+ message: res.message,
834
+ attachments: mergeAttachments(res.attachments, res.output)
835
+ });
836
+ };
837
+
838
+ if (action.isPublic) {
839
+ getContextBasic();
840
+ return invoke(new SlatePublicContext(input, slate.spec, logger));
841
+ }
842
+
843
+ let ctx = getContextFull();
844
+ return invoke(
845
+ new SlateContext(ctx.config, input, ctx.auth?.output!, slate.spec, logger)
846
+ );
806
847
  });
807
848
 
808
849
  manager.onRequest('slates/action.trigger.map_event', async ({ params }) => {
package/src/spec.ts CHANGED
@@ -1,6 +1,14 @@
1
1
  import { badRequestError, notFoundError, ServiceError } from '@lowerdeck/error';
2
- import type { SlateAuthenticationMethod, SlatesAction } from '@slates/proto';
3
- import { type Slate, SlateDefaultPollingIntervalSeconds } from '@slates/provider';
2
+ import type {
3
+ SlateAuthenticationMethod,
4
+ SlatesAction,
5
+ SlateAdapter as SlatesAdapter
6
+ } from '@slates/proto';
7
+ import {
8
+ type Slate,
9
+ type SlateAdapter,
10
+ SlateDefaultPollingIntervalSeconds
11
+ } from '@slates/provider';
4
12
  import z from 'zod';
5
13
  import { toJsonSchema } from './validation';
6
14
 
@@ -67,6 +75,26 @@ export let getAction = <ConfigType extends {}, AuthType extends {}>(
67
75
  return action;
68
76
  };
69
77
 
78
+ export let getAdapter = <ConfigType extends {}, AuthType extends {}>(
79
+ slate: Slate<ConfigType, AuthType>,
80
+ adapterId: string
81
+ ) => {
82
+ let adapter = slate.adapters.find(m => m.id === adapterId);
83
+ if (!adapter) {
84
+ throw new ServiceError(notFoundError(`adapter`, adapterId));
85
+ }
86
+
87
+ return adapter;
88
+ };
89
+
90
+ export let mapAdapter = <ConfigType extends {}, AuthType extends {}>(
91
+ adapter: SlateAdapter<ConfigType, AuthType>
92
+ ): SlatesAdapter => ({
93
+ id: adapter.id,
94
+ name: adapter.name,
95
+ capabilities: adapter.capabilities
96
+ });
97
+
70
98
  export let getActionWithType = <
71
99
  Type extends 'tool' | 'trigger',
72
100
  ConfigType extends {},
@@ -103,6 +131,7 @@ export let mapAction = <ConfigType extends {}, AuthType extends {}>(
103
131
  scopes: a.scopes,
104
132
  authMethods: a.authMethods,
105
133
  docs: a.docs ?? [],
134
+ ...(a.adapter ? { adapter: a.adapter } : {}),
106
135
 
107
136
  inputSchema: toJsonSchema(a.inputSchema),
108
137
  outputSchema: toJsonSchema(a.outputSchema)
@@ -112,7 +141,8 @@ export let mapAction = <ConfigType extends {}, AuthType extends {}>(
112
141
  return {
113
142
  ...base,
114
143
  type: 'action.tool',
115
- capabilities: {}
144
+ capabilities: {},
145
+ isPublic: a.isPublic
116
146
  };
117
147
  }
118
148