@slates/client 1.0.0-rc.2 → 1.0.0-rc.21

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/src/client.ts CHANGED
@@ -1,15 +1,33 @@
1
1
  import {
2
2
  SLATES_PROTOCOL_VERSION,
3
- SlateAuthenticationMethod,
4
- SlatesAction,
5
- SlatesParticipant,
6
- slatesRequestsByMethod,
7
- slatesResponsesByMethod
3
+ type SlateAuthenticationMethod,
4
+ type SlatesAction,
5
+ type SlatesActionTool,
6
+ type SlatesMessageActionGetResponse,
7
+ type SlatesMessageActionInvokeResponse,
8
+ type SlatesMessageActionsListResponse,
9
+ type SlatesMessageActionTriggerEventMapResponse,
10
+ type SlatesMessageActionTriggerWebhookHandleResponse,
11
+ type SlatesMessageActionTriggerWebhookRegisterResponse,
12
+ type SlatesMessageActionTriggerWebhookUnregisterResponse,
13
+ type SlatesMessageAuthAuthorizationUrlGetResponse,
14
+ type SlatesMessageAuthDefaultInputGetResponse,
15
+ type SlatesMessageAuthInputChangedResponse,
16
+ type SlatesMessageAuthMethodGetResponse,
17
+ type SlatesMessageAuthOutputGetResponse,
18
+ type SlatesMessageAuthProfileGetResponse,
19
+ type SlatesMessageAuthTokenRefreshHandleResponse,
20
+ type SlatesMessageConfigChangedResponse,
21
+ type SlatesMessageConfigDefaultGetResponse,
22
+ type SlatesMessageConfigSchemaGetResponse,
23
+ type SlatesMessageProviderIdentifyResponse,
24
+ type SlatesParticipant,
25
+ type SlatesRequests,
26
+ type SlatesResponsesByMethod
8
27
  } from '@slates/proto';
9
28
  import { randomUUID } from 'crypto';
10
- import z from 'zod';
11
29
  import { SlateProtocolError } from './error';
12
- import { SlatesClientState, SlatesProtocolClientOptions } from './types';
30
+ import type { SlatesClientState, SlatesProtocolClientOptions } from './types';
13
31
 
14
32
  let createDefaultParticipants = (): SlatesParticipant[] => [
15
33
  {
@@ -118,10 +136,10 @@ export class SlatesProtocolClient {
118
136
  ];
119
137
  }
120
138
 
121
- async request<Key extends keyof typeof slatesRequestsByMethod>(
139
+ async request<Key extends keyof SlatesResponsesByMethod & SlatesRequests['method']>(
122
140
  method: Key,
123
- params: z.infer<(typeof slatesRequestsByMethod)[Key]>['params']
124
- ): Promise<z.infer<(typeof slatesResponsesByMethod)[Key]>['result']> {
141
+ params: Extract<SlatesRequests, { method: Key }>['params']
142
+ ): Promise<SlatesResponsesByMethod[Key]['result']> {
125
143
  let id = randomUUID();
126
144
  let responses = await this.transport.send([
127
145
  ...this.buildStateMessages(),
@@ -130,7 +148,7 @@ export class SlatesProtocolClient {
130
148
  id,
131
149
  method,
132
150
  params
133
- } as z.infer<(typeof slatesRequestsByMethod)[Key]>
151
+ } as Extract<SlatesRequests, { method: Key }>
134
152
  ]);
135
153
 
136
154
  let response = responses.find(message => 'id' in message && message.id === id) as
@@ -148,17 +166,19 @@ export class SlatesProtocolClient {
148
166
  return response.result;
149
167
  }
150
168
 
151
- async identify() {
169
+ async identify(): Promise<SlatesMessageProviderIdentifyResponse['result']> {
152
170
  return this.request('slates/provider.identify', {});
153
171
  }
154
172
 
155
- async listActions() {
173
+ async listActions(): Promise<SlatesMessageActionsListResponse['result']> {
156
174
  return this.request('slates/actions.list', {});
157
175
  }
158
176
 
159
- async listTools(): Promise<SlatesAction[]> {
177
+ async listTools(): Promise<SlatesActionTool[]> {
160
178
  let result = await this.listActions();
161
- return result.actions.filter(action => action.type === 'action.tool');
179
+ return result.actions.filter(
180
+ (action): action is SlatesActionTool => action.type === 'action.tool'
181
+ );
162
182
  }
163
183
 
164
184
  async listTriggers(): Promise<SlatesAction[]> {
@@ -166,7 +186,7 @@ export class SlatesProtocolClient {
166
186
  return result.actions.filter(action => action.type === 'action.trigger');
167
187
  }
168
188
 
169
- async getAction(actionId: string) {
189
+ async getAction(actionId: string): Promise<SlatesMessageActionGetResponse['result']> {
170
190
  return this.request('slates/action.get', { actionId });
171
191
  }
172
192
 
@@ -188,18 +208,18 @@ export class SlatesProtocolClient {
188
208
  return result.action;
189
209
  }
190
210
 
191
- async getConfigSchema() {
211
+ async getConfigSchema(): Promise<SlatesMessageConfigSchemaGetResponse['result']> {
192
212
  return this.request('slates/config.schema.get', {});
193
213
  }
194
214
 
195
- async getDefaultConfig() {
215
+ async getDefaultConfig(): Promise<SlatesMessageConfigDefaultGetResponse['result']> {
196
216
  return this.request('slates/config.get_default', {});
197
217
  }
198
218
 
199
219
  async updateConfig(
200
220
  previousConfig: Record<string, any> | null,
201
221
  newConfig: Record<string, any>
202
- ) {
222
+ ): Promise<SlatesMessageConfigChangedResponse['result']> {
203
223
  return this.request('slates/config.changed', {
204
224
  previousConfig,
205
225
  newConfig
@@ -210,13 +230,17 @@ export class SlatesProtocolClient {
210
230
  return this.request('slates/auth.methods.list', {});
211
231
  }
212
232
 
213
- async getAuthMethod(authenticationMethodId: string) {
233
+ async getAuthMethod(
234
+ authenticationMethodId: string
235
+ ): Promise<SlatesMessageAuthMethodGetResponse['result']> {
214
236
  return this.request('slates/auth.method.get', {
215
237
  authenticationMethodId
216
238
  });
217
239
  }
218
240
 
219
- async getDefaultAuthInput(authenticationMethodId: string) {
241
+ async getDefaultAuthInput(
242
+ authenticationMethodId: string
243
+ ): Promise<SlatesMessageAuthDefaultInputGetResponse['result']> {
220
244
  return this.request('slates/auth.input.get_default', {
221
245
  authenticationMethodId
222
246
  });
@@ -226,7 +250,7 @@ export class SlatesProtocolClient {
226
250
  authenticationMethodId: string;
227
251
  previousInput: Record<string, any> | null;
228
252
  newInput: Record<string, any>;
229
- }) {
253
+ }): Promise<SlatesMessageAuthInputChangedResponse['result']> {
230
254
  return this.request('slates/auth.input.changed', {
231
255
  authenticationMethodId: d.authenticationMethodId,
232
256
  previousInput: d.previousInput,
@@ -234,7 +258,10 @@ export class SlatesProtocolClient {
234
258
  });
235
259
  }
236
260
 
237
- async getAuthOutput(d: { authenticationMethodId: string; input: Record<string, any> }) {
261
+ async getAuthOutput(d: {
262
+ authenticationMethodId: string;
263
+ input: Record<string, any>;
264
+ }): Promise<SlatesMessageAuthOutputGetResponse['result']> {
238
265
  return this.request('slates/auth.output.get', {
239
266
  authenticationMethodId: d.authenticationMethodId,
240
267
  input: d.input
@@ -249,7 +276,7 @@ export class SlatesProtocolClient {
249
276
  clientId: string;
250
277
  clientSecret: string;
251
278
  scopes: string[];
252
- }) {
279
+ }): Promise<SlatesMessageAuthAuthorizationUrlGetResponse['result']> {
253
280
  return this.request('slates/auth.authorization_url.get', d);
254
281
  }
255
282
 
@@ -262,6 +289,7 @@ export class SlatesProtocolClient {
262
289
  clientId: string;
263
290
  clientSecret: string;
264
291
  scopes: string[];
292
+ callbackParams?: Record<string, string>;
265
293
  callbackState?: Record<string, any>;
266
294
  }): Promise<{
267
295
  output: Record<string, any>;
@@ -278,7 +306,7 @@ export class SlatesProtocolClient {
278
306
  clientId: string;
279
307
  clientSecret: string;
280
308
  scopes: string[];
281
- }) {
309
+ }): Promise<SlatesMessageAuthTokenRefreshHandleResponse['result']> {
282
310
  return this.request('slates/auth.token_refresh.handle', d);
283
311
  }
284
312
 
@@ -287,11 +315,14 @@ export class SlatesProtocolClient {
287
315
  output: Record<string, any>;
288
316
  input: Record<string, any>;
289
317
  scopes: string[];
290
- }) {
318
+ }): Promise<SlatesMessageAuthProfileGetResponse['result']> {
291
319
  return this.request('slates/auth.profile.get', d);
292
320
  }
293
321
 
294
- async invokeTool(actionId: string, input: Record<string, any>) {
322
+ async invokeTool(
323
+ actionId: string,
324
+ input: Record<string, any>
325
+ ): Promise<SlatesMessageActionInvokeResponse['result']> {
295
326
  this.ensureSession();
296
327
  return this.request('slates/action.tool.invoke', {
297
328
  actionId,
@@ -299,7 +330,10 @@ export class SlatesProtocolClient {
299
330
  });
300
331
  }
301
332
 
302
- async mapTriggerEvent(actionId: string, input: Record<string, any>) {
333
+ async mapTriggerEvent(
334
+ actionId: string,
335
+ input: Record<string, any>
336
+ ): Promise<SlatesMessageActionTriggerEventMapResponse['result']> {
303
337
  this.ensureSession();
304
338
  return this.request('slates/action.trigger.map_event', {
305
339
  actionId,
@@ -307,7 +341,10 @@ export class SlatesProtocolClient {
307
341
  });
308
342
  }
309
343
 
310
- async registerTriggerWebhook(actionId: string, webhookBaseUrl: string) {
344
+ async registerTriggerWebhook(
345
+ actionId: string,
346
+ webhookBaseUrl: string
347
+ ): Promise<SlatesMessageActionTriggerWebhookRegisterResponse['result']> {
311
348
  this.ensureSession();
312
349
  return this.request('slates/action.trigger.webhook_register', {
313
350
  actionId,
@@ -322,7 +359,8 @@ export class SlatesProtocolClient {
322
359
  headers?: Record<string, string>;
323
360
  body?: string | Uint8Array | null;
324
361
  state?: any;
325
- }) {
362
+ registrationDetails?: any;
363
+ }): Promise<SlatesMessageActionTriggerWebhookHandleResponse['result']> {
326
364
  this.ensureSession();
327
365
  let encodedBody =
328
366
  typeof d.body === 'string'
@@ -342,7 +380,8 @@ export class SlatesProtocolClient {
342
380
  content: encodedBody
343
381
  }
344
382
  : null,
345
- state: d.state ?? null
383
+ state: d.state ?? null,
384
+ registrationDetails: d.registrationDetails ?? null
346
385
  });
347
386
  }
348
387
 
@@ -351,7 +390,7 @@ export class SlatesProtocolClient {
351
390
  webhookBaseUrl: string;
352
391
  registrationDetails: any;
353
392
  state?: any;
354
- }) {
393
+ }): Promise<SlatesMessageActionTriggerWebhookUnregisterResponse['result']> {
355
394
  this.ensureSession();
356
395
  return this.request('slates/action.trigger.webhook_unregister', {
357
396
  actionId: d.actionId,
package/src/error.ts CHANGED
@@ -18,10 +18,11 @@ export interface SlateProtocolErrorResponse {
18
18
  kind: SlateProtocolErrorKind;
19
19
  retryable?: boolean;
20
20
  status?: number;
21
- issues?: Array<Record<string, unknown>>;
21
+ issues?: Record<string, unknown>[];
22
22
  provider?: Record<string, unknown>;
23
23
  upstream?: Record<string, unknown>;
24
24
  baggage?: Record<string, unknown>;
25
+ requestTraces?: Record<string, unknown>[];
25
26
  [key: string]: unknown;
26
27
  }
27
28
 
@@ -61,7 +62,8 @@ let normalizeResponse = (
61
62
  let code =
62
63
  typeof error.code === 'string'
63
64
  ? error.code
64
- : defaults.code ?? (source === 'transport' ? 'transport.invoke_failed' : 'internal.unexpected');
65
+ : (defaults.code ??
66
+ (source === 'transport' ? 'transport.invoke_failed' : 'internal.unexpected'));
65
67
 
66
68
  return {
67
69
  ...defaults,
@@ -69,13 +71,15 @@ let normalizeResponse = (
69
71
  code,
70
72
  message: error.message,
71
73
  kind:
72
- (typeof error.kind === 'string' ? (error.kind as SlateProtocolErrorKind) : defaults.kind) ??
73
- inferKindFromCode(code)
74
+ (typeof error.kind === 'string'
75
+ ? (error.kind as SlateProtocolErrorKind)
76
+ : defaults.kind) ?? inferKindFromCode(code)
74
77
  };
75
78
  }
76
79
 
77
80
  let code =
78
- defaults.code ?? (source === 'transport' ? 'transport.invoke_failed' : 'internal.unexpected');
81
+ defaults.code ??
82
+ (source === 'transport' ? 'transport.invoke_failed' : 'internal.unexpected');
79
83
 
80
84
  return {
81
85
  ...defaults,
@@ -83,13 +87,11 @@ let normalizeResponse = (
83
87
  message:
84
88
  error instanceof Error
85
89
  ? error.message
86
- : defaults.message ?? 'The slate returned an unexpected error.',
90
+ : (defaults.message ?? 'The slate returned an unexpected error.'),
87
91
  kind: defaults.kind ?? inferKindFromCode(code),
88
92
  baggage: {
89
93
  ...(defaults.baggage ?? {}),
90
- ...(error instanceof Error
91
- ? { originalName: error.name }
92
- : { originalValue: error })
94
+ ...(error instanceof Error ? { originalName: error.name } : { originalValue: error })
93
95
  }
94
96
  };
95
97
  };
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SlatesProtocolClient } from './client';
2
- import { SlatesProtocolClientOptions } from './types';
2
+ import type { SlatesProtocolClientOptions } from './types';
3
3
 
4
4
  export * from './client';
5
5
  export * from './error';
package/src/transport.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
- SlatesNotifications,
2
+ type SlatesNotifications,
3
3
  SlatesProviderProtoHandlerManager,
4
- SlatesRequests,
5
- SlatesResponses
4
+ type SlatesRequests,
5
+ type SlatesResponses
6
6
  } from '@slates/proto';
7
- import { Slate, SlateLogListener } from '@slates/provider';
7
+ import type { Slate, SlateLogListener } from '@slates/provider';
8
8
  import { createProviderHandler } from '@slates/provider-handler';
9
9
  import { SlateProtocolError } from './error';
10
- import { SlatesMessageTransport } from './types';
10
+ import type { SlatesMessageTransport } from './types';
11
11
 
12
12
  type ProviderMessage = SlatesNotifications | SlatesRequests;
13
13
  type ProviderResponse = SlatesNotifications | SlatesResponses;
@@ -39,7 +39,7 @@ export let createLocalSlateTransport = <ConfigType extends {}, AuthType extends
39
39
  let responses: ProviderResponse[] = [];
40
40
 
41
41
  for (let message of messages as ProviderMessage[]) {
42
- let response;
42
+ let response: any;
43
43
  try {
44
44
  response = await SlatesProviderProtoHandlerManager.handleInput(manager, message);
45
45
  } catch (error) {
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  SlatesNotifications,
3
3
  SlatesParticipant,
4
4
  SlatesProtocolVersion,