@slates/client 1.0.0-rc.13 → 1.0.0-rc.15
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 +5 -2
- package/dist/index.d.cts +26 -2
- package/dist/index.d.ts +26 -2
- package/dist/index.module.js +5 -2
- package/package.json +4 -4
- package/src/client.test.ts +252 -2
- package/src/client.ts +8 -3
package/dist/index.cjs
CHANGED
|
@@ -237,7 +237,9 @@ var SlatesProtocolClient = class {
|
|
|
237
237
|
}
|
|
238
238
|
async listTools() {
|
|
239
239
|
let result = await this.listActions();
|
|
240
|
-
return result.actions.filter(
|
|
240
|
+
return result.actions.filter(
|
|
241
|
+
(action) => action.type === "action.tool"
|
|
242
|
+
);
|
|
241
243
|
}
|
|
242
244
|
async listTriggers() {
|
|
243
245
|
let result = await this.listActions();
|
|
@@ -343,7 +345,8 @@ var SlatesProtocolClient = class {
|
|
|
343
345
|
encoding: "base64",
|
|
344
346
|
content: encodedBody
|
|
345
347
|
} : null,
|
|
346
|
-
state: d.state ?? null
|
|
348
|
+
state: d.state ?? null,
|
|
349
|
+
registrationDetails: d.registrationDetails ?? null
|
|
347
350
|
});
|
|
348
351
|
}
|
|
349
352
|
async unregisterTriggerWebhook(d) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SlatesProtocolVersion, SlatesParticipant, SlatesNotifications, SlatesRequests, SlatesResponses, SlatesResponsesByMethod, SlatesMessageProviderIdentifyResponse, SlatesMessageActionsListResponse, SlatesAction, SlatesMessageActionGetResponse, SlatesMessageConfigSchemaGetResponse, SlatesMessageConfigDefaultGetResponse, SlatesMessageConfigChangedResponse, SlateAuthenticationMethod, SlatesMessageAuthMethodGetResponse, SlatesMessageAuthDefaultInputGetResponse, SlatesMessageAuthInputChangedResponse, SlatesMessageAuthOutputGetResponse, SlatesMessageAuthAuthorizationUrlGetResponse, SlatesMessageAuthTokenRefreshHandleResponse, SlatesMessageAuthProfileGetResponse, SlatesMessageActionInvokeResponse, SlatesMessageActionTriggerEventMapResponse, SlatesMessageActionTriggerWebhookRegisterResponse, SlatesMessageActionTriggerWebhookHandleResponse, SlatesMessageActionTriggerWebhookUnregisterResponse } from '@slates/proto';
|
|
1
|
+
import { SlatesProtocolVersion, SlatesParticipant, SlatesNotifications, SlatesRequests, SlatesResponses, SlatesResponsesByMethod, SlatesMessageProviderIdentifyResponse, SlatesMessageActionsListResponse, SlatesActionTool, SlatesAction, SlatesMessageActionGetResponse, SlatesMessageConfigSchemaGetResponse, SlatesMessageConfigDefaultGetResponse, SlatesMessageConfigChangedResponse, SlateAuthenticationMethod, SlatesMessageAuthMethodGetResponse, SlatesMessageAuthDefaultInputGetResponse, SlatesMessageAuthInputChangedResponse, SlatesMessageAuthOutputGetResponse, SlatesMessageAuthAuthorizationUrlGetResponse, SlatesMessageAuthTokenRefreshHandleResponse, SlatesMessageAuthProfileGetResponse, SlatesMessageActionInvokeResponse, SlatesMessageActionTriggerEventMapResponse, SlatesMessageActionTriggerWebhookRegisterResponse, SlatesMessageActionTriggerWebhookHandleResponse, SlatesMessageActionTriggerWebhookUnregisterResponse } from '@slates/proto';
|
|
2
2
|
import { Slate, SlateLogListener } from '@slates/provider';
|
|
3
3
|
|
|
4
4
|
type SlatesJsonObject = Record<string, any>;
|
|
@@ -46,7 +46,7 @@ declare class SlatesProtocolClient {
|
|
|
46
46
|
}>['params']): Promise<SlatesResponsesByMethod[Key]['result']>;
|
|
47
47
|
identify(): Promise<SlatesMessageProviderIdentifyResponse['result']>;
|
|
48
48
|
listActions(): Promise<SlatesMessageActionsListResponse['result']>;
|
|
49
|
-
listTools(): Promise<
|
|
49
|
+
listTools(): Promise<SlatesActionTool[]>;
|
|
50
50
|
listTriggers(): Promise<SlatesAction[]>;
|
|
51
51
|
getAction(actionId: string): Promise<SlatesMessageActionGetResponse['result']>;
|
|
52
52
|
getTool(actionId: string): Promise<{
|
|
@@ -61,6 +61,7 @@ declare class SlatesProtocolClient {
|
|
|
61
61
|
}[];
|
|
62
62
|
type: "action.tool";
|
|
63
63
|
capabilities: Record<string, never>;
|
|
64
|
+
isPublic: boolean;
|
|
64
65
|
description?: string | undefined;
|
|
65
66
|
instructions?: string[] | undefined;
|
|
66
67
|
constraints?: string[] | undefined;
|
|
@@ -75,6 +76,7 @@ declare class SlatesProtocolClient {
|
|
|
75
76
|
}[];
|
|
76
77
|
} | undefined;
|
|
77
78
|
authMethods?: string[] | undefined;
|
|
79
|
+
adapter?: string | null | undefined;
|
|
78
80
|
}>;
|
|
79
81
|
getTrigger(actionId: string): Promise<{
|
|
80
82
|
id: string;
|
|
@@ -95,6 +97,26 @@ declare class SlatesProtocolClient {
|
|
|
95
97
|
type: "webhook";
|
|
96
98
|
autoRegistration: boolean;
|
|
97
99
|
autoUnregistration: boolean;
|
|
100
|
+
http?: {
|
|
101
|
+
methods?: ("GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS")[] | undefined;
|
|
102
|
+
sync?: {
|
|
103
|
+
mode: "match" | "never" | "always";
|
|
104
|
+
match?: {
|
|
105
|
+
method?: string | undefined;
|
|
106
|
+
hasQueryParam?: string | undefined;
|
|
107
|
+
hasHeader?: string | undefined;
|
|
108
|
+
jsonBodyField?: {
|
|
109
|
+
path: string;
|
|
110
|
+
equals?: string | undefined;
|
|
111
|
+
} | undefined;
|
|
112
|
+
formBodyField?: {
|
|
113
|
+
path: string;
|
|
114
|
+
equals?: string | undefined;
|
|
115
|
+
} | undefined;
|
|
116
|
+
}[] | undefined;
|
|
117
|
+
timeoutMs?: number | undefined;
|
|
118
|
+
} | undefined;
|
|
119
|
+
} | undefined;
|
|
98
120
|
};
|
|
99
121
|
description?: string | undefined;
|
|
100
122
|
instructions?: string[] | undefined;
|
|
@@ -110,6 +132,7 @@ declare class SlatesProtocolClient {
|
|
|
110
132
|
}[];
|
|
111
133
|
} | undefined;
|
|
112
134
|
authMethods?: string[] | undefined;
|
|
135
|
+
adapter?: string | null | undefined;
|
|
113
136
|
}>;
|
|
114
137
|
getConfigSchema(): Promise<SlatesMessageConfigSchemaGetResponse['result']>;
|
|
115
138
|
getDefaultConfig(): Promise<SlatesMessageConfigDefaultGetResponse['result']>;
|
|
@@ -177,6 +200,7 @@ declare class SlatesProtocolClient {
|
|
|
177
200
|
headers?: Record<string, string>;
|
|
178
201
|
body?: string | Uint8Array | null;
|
|
179
202
|
state?: any;
|
|
203
|
+
registrationDetails?: any;
|
|
180
204
|
}): Promise<SlatesMessageActionTriggerWebhookHandleResponse['result']>;
|
|
181
205
|
unregisterTriggerWebhook(d: {
|
|
182
206
|
actionId: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SlatesProtocolVersion, SlatesParticipant, SlatesNotifications, SlatesRequests, SlatesResponses, SlatesResponsesByMethod, SlatesMessageProviderIdentifyResponse, SlatesMessageActionsListResponse, SlatesAction, SlatesMessageActionGetResponse, SlatesMessageConfigSchemaGetResponse, SlatesMessageConfigDefaultGetResponse, SlatesMessageConfigChangedResponse, SlateAuthenticationMethod, SlatesMessageAuthMethodGetResponse, SlatesMessageAuthDefaultInputGetResponse, SlatesMessageAuthInputChangedResponse, SlatesMessageAuthOutputGetResponse, SlatesMessageAuthAuthorizationUrlGetResponse, SlatesMessageAuthTokenRefreshHandleResponse, SlatesMessageAuthProfileGetResponse, SlatesMessageActionInvokeResponse, SlatesMessageActionTriggerEventMapResponse, SlatesMessageActionTriggerWebhookRegisterResponse, SlatesMessageActionTriggerWebhookHandleResponse, SlatesMessageActionTriggerWebhookUnregisterResponse } from '@slates/proto';
|
|
1
|
+
import { SlatesProtocolVersion, SlatesParticipant, SlatesNotifications, SlatesRequests, SlatesResponses, SlatesResponsesByMethod, SlatesMessageProviderIdentifyResponse, SlatesMessageActionsListResponse, SlatesActionTool, SlatesAction, SlatesMessageActionGetResponse, SlatesMessageConfigSchemaGetResponse, SlatesMessageConfigDefaultGetResponse, SlatesMessageConfigChangedResponse, SlateAuthenticationMethod, SlatesMessageAuthMethodGetResponse, SlatesMessageAuthDefaultInputGetResponse, SlatesMessageAuthInputChangedResponse, SlatesMessageAuthOutputGetResponse, SlatesMessageAuthAuthorizationUrlGetResponse, SlatesMessageAuthTokenRefreshHandleResponse, SlatesMessageAuthProfileGetResponse, SlatesMessageActionInvokeResponse, SlatesMessageActionTriggerEventMapResponse, SlatesMessageActionTriggerWebhookRegisterResponse, SlatesMessageActionTriggerWebhookHandleResponse, SlatesMessageActionTriggerWebhookUnregisterResponse } from '@slates/proto';
|
|
2
2
|
import { Slate, SlateLogListener } from '@slates/provider';
|
|
3
3
|
|
|
4
4
|
type SlatesJsonObject = Record<string, any>;
|
|
@@ -46,7 +46,7 @@ declare class SlatesProtocolClient {
|
|
|
46
46
|
}>['params']): Promise<SlatesResponsesByMethod[Key]['result']>;
|
|
47
47
|
identify(): Promise<SlatesMessageProviderIdentifyResponse['result']>;
|
|
48
48
|
listActions(): Promise<SlatesMessageActionsListResponse['result']>;
|
|
49
|
-
listTools(): Promise<
|
|
49
|
+
listTools(): Promise<SlatesActionTool[]>;
|
|
50
50
|
listTriggers(): Promise<SlatesAction[]>;
|
|
51
51
|
getAction(actionId: string): Promise<SlatesMessageActionGetResponse['result']>;
|
|
52
52
|
getTool(actionId: string): Promise<{
|
|
@@ -61,6 +61,7 @@ declare class SlatesProtocolClient {
|
|
|
61
61
|
}[];
|
|
62
62
|
type: "action.tool";
|
|
63
63
|
capabilities: Record<string, never>;
|
|
64
|
+
isPublic: boolean;
|
|
64
65
|
description?: string | undefined;
|
|
65
66
|
instructions?: string[] | undefined;
|
|
66
67
|
constraints?: string[] | undefined;
|
|
@@ -75,6 +76,7 @@ declare class SlatesProtocolClient {
|
|
|
75
76
|
}[];
|
|
76
77
|
} | undefined;
|
|
77
78
|
authMethods?: string[] | undefined;
|
|
79
|
+
adapter?: string | null | undefined;
|
|
78
80
|
}>;
|
|
79
81
|
getTrigger(actionId: string): Promise<{
|
|
80
82
|
id: string;
|
|
@@ -95,6 +97,26 @@ declare class SlatesProtocolClient {
|
|
|
95
97
|
type: "webhook";
|
|
96
98
|
autoRegistration: boolean;
|
|
97
99
|
autoUnregistration: boolean;
|
|
100
|
+
http?: {
|
|
101
|
+
methods?: ("GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS")[] | undefined;
|
|
102
|
+
sync?: {
|
|
103
|
+
mode: "match" | "never" | "always";
|
|
104
|
+
match?: {
|
|
105
|
+
method?: string | undefined;
|
|
106
|
+
hasQueryParam?: string | undefined;
|
|
107
|
+
hasHeader?: string | undefined;
|
|
108
|
+
jsonBodyField?: {
|
|
109
|
+
path: string;
|
|
110
|
+
equals?: string | undefined;
|
|
111
|
+
} | undefined;
|
|
112
|
+
formBodyField?: {
|
|
113
|
+
path: string;
|
|
114
|
+
equals?: string | undefined;
|
|
115
|
+
} | undefined;
|
|
116
|
+
}[] | undefined;
|
|
117
|
+
timeoutMs?: number | undefined;
|
|
118
|
+
} | undefined;
|
|
119
|
+
} | undefined;
|
|
98
120
|
};
|
|
99
121
|
description?: string | undefined;
|
|
100
122
|
instructions?: string[] | undefined;
|
|
@@ -110,6 +132,7 @@ declare class SlatesProtocolClient {
|
|
|
110
132
|
}[];
|
|
111
133
|
} | undefined;
|
|
112
134
|
authMethods?: string[] | undefined;
|
|
135
|
+
adapter?: string | null | undefined;
|
|
113
136
|
}>;
|
|
114
137
|
getConfigSchema(): Promise<SlatesMessageConfigSchemaGetResponse['result']>;
|
|
115
138
|
getDefaultConfig(): Promise<SlatesMessageConfigDefaultGetResponse['result']>;
|
|
@@ -177,6 +200,7 @@ declare class SlatesProtocolClient {
|
|
|
177
200
|
headers?: Record<string, string>;
|
|
178
201
|
body?: string | Uint8Array | null;
|
|
179
202
|
state?: any;
|
|
203
|
+
registrationDetails?: any;
|
|
180
204
|
}): Promise<SlatesMessageActionTriggerWebhookHandleResponse['result']>;
|
|
181
205
|
unregisterTriggerWebhook(d: {
|
|
182
206
|
actionId: string;
|
package/dist/index.module.js
CHANGED
|
@@ -210,7 +210,9 @@ var SlatesProtocolClient = class {
|
|
|
210
210
|
}
|
|
211
211
|
async listTools() {
|
|
212
212
|
let result = await this.listActions();
|
|
213
|
-
return result.actions.filter(
|
|
213
|
+
return result.actions.filter(
|
|
214
|
+
(action) => action.type === "action.tool"
|
|
215
|
+
);
|
|
214
216
|
}
|
|
215
217
|
async listTriggers() {
|
|
216
218
|
let result = await this.listActions();
|
|
@@ -316,7 +318,8 @@ var SlatesProtocolClient = class {
|
|
|
316
318
|
encoding: "base64",
|
|
317
319
|
content: encodedBody
|
|
318
320
|
} : null,
|
|
319
|
-
state: d.state ?? null
|
|
321
|
+
state: d.state ?? null,
|
|
322
|
+
registrationDetails: d.registrationDetails ?? null
|
|
320
323
|
});
|
|
321
324
|
}
|
|
322
325
|
async unregisterTriggerWebhook(d) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slates/client",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.15",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"biome:check": "biome check --write src"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@slates/proto": "1.0.0-rc.
|
|
35
|
-
"@slates/provider": "1.0.0-rc.
|
|
36
|
-
"@slates/provider-handler": "1.0.0-rc.
|
|
34
|
+
"@slates/proto": "1.0.0-rc.13",
|
|
35
|
+
"@slates/provider": "1.0.0-rc.18",
|
|
36
|
+
"@slates/provider-handler": "1.0.0-rc.20"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@slates/tsconfig": "1.0.0-rc.1",
|
package/src/client.test.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
SlateAuth,
|
|
5
5
|
SlateConfig,
|
|
6
6
|
type SlateLogEntry,
|
|
7
|
+
SlatePublicTool,
|
|
7
8
|
SlateSpecification,
|
|
8
9
|
SlateTool,
|
|
9
10
|
SlateTrigger
|
|
@@ -312,7 +313,14 @@ let createTriggerTraceSlate = () => {
|
|
|
312
313
|
)
|
|
313
314
|
.webhook({
|
|
314
315
|
handleRequest: async () => ({
|
|
315
|
-
inputs: [{ id: 'webhook-1' }, { id: 'webhook-2' }]
|
|
316
|
+
inputs: [{ id: 'webhook-1' }, { id: 'webhook-2' }],
|
|
317
|
+
response: {
|
|
318
|
+
status: 202,
|
|
319
|
+
headers: {
|
|
320
|
+
'x-trigger-result': 'accepted'
|
|
321
|
+
},
|
|
322
|
+
body: 'accepted'
|
|
323
|
+
}
|
|
316
324
|
}),
|
|
317
325
|
handleEvent: async ctx => ({
|
|
318
326
|
id: ctx.input.id,
|
|
@@ -429,6 +437,83 @@ let createOauthConfigSlate = (seenConfig: SeenOAuthConfig) => {
|
|
|
429
437
|
});
|
|
430
438
|
};
|
|
431
439
|
|
|
440
|
+
type TokenConfig = {
|
|
441
|
+
prefix: string;
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
type SeenTokenConfig = Partial<Record<'output' | 'profile', TokenConfig>>;
|
|
445
|
+
|
|
446
|
+
let getRequiredTokenConfig = (ctx: { config?: Record<string, unknown> }): TokenConfig => {
|
|
447
|
+
expect(ctx.config).toBeDefined();
|
|
448
|
+
return ctx.config as TokenConfig;
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
type TokenAuthOutputContext = {
|
|
452
|
+
input: { token: string };
|
|
453
|
+
config?: Record<string, unknown>;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
type TokenAuthProfileContext = {
|
|
457
|
+
output: { token: string };
|
|
458
|
+
config?: Record<string, unknown>;
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
let createTokenConfigSlate = (seenConfig: SeenTokenConfig) => {
|
|
462
|
+
let config = SlateConfig.create(
|
|
463
|
+
z.object({
|
|
464
|
+
prefix: z.string()
|
|
465
|
+
})
|
|
466
|
+
);
|
|
467
|
+
|
|
468
|
+
let auth = SlateAuth.create<{ token: string }>()
|
|
469
|
+
.output(
|
|
470
|
+
z.object({
|
|
471
|
+
token: z.string()
|
|
472
|
+
})
|
|
473
|
+
)
|
|
474
|
+
.addTokenAuth({
|
|
475
|
+
type: 'auth.token',
|
|
476
|
+
key: 'token_auth',
|
|
477
|
+
name: 'Token Auth',
|
|
478
|
+
inputSchema: z.object({
|
|
479
|
+
token: z.string()
|
|
480
|
+
}),
|
|
481
|
+
getOutput: async (ctx: TokenAuthOutputContext) => {
|
|
482
|
+
let currentConfig = getRequiredTokenConfig(ctx);
|
|
483
|
+
seenConfig.output = currentConfig;
|
|
484
|
+
return {
|
|
485
|
+
output: {
|
|
486
|
+
token: `${currentConfig.prefix}:${ctx.input.token}`
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
},
|
|
490
|
+
getProfile: async (ctx: TokenAuthProfileContext) => {
|
|
491
|
+
let currentConfig = getRequiredTokenConfig(ctx);
|
|
492
|
+
seenConfig.profile = currentConfig;
|
|
493
|
+
return {
|
|
494
|
+
profile: {
|
|
495
|
+
prefix: currentConfig.prefix,
|
|
496
|
+
token: ctx.output.token
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
let spec = SlateSpecification.create({
|
|
503
|
+
key: 'token-config-slate',
|
|
504
|
+
name: 'Token Config Slate',
|
|
505
|
+
description: 'A slate that reads config in token auth hooks',
|
|
506
|
+
config,
|
|
507
|
+
auth
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
return Slate.create({
|
|
511
|
+
spec,
|
|
512
|
+
tools: [],
|
|
513
|
+
triggers: []
|
|
514
|
+
});
|
|
515
|
+
};
|
|
516
|
+
|
|
432
517
|
describe('@slates/client local transport', () => {
|
|
433
518
|
it('discovers auth/config and invokes tools with session state', async () => {
|
|
434
519
|
let slate = createDemoSlate();
|
|
@@ -463,6 +548,7 @@ describe('@slates/client local transport', () => {
|
|
|
463
548
|
]
|
|
464
549
|
});
|
|
465
550
|
expect(actions[0]!.authMethods).toEqual(['token_auth']);
|
|
551
|
+
expect(actions[0]!.isPublic).toBe(false);
|
|
466
552
|
|
|
467
553
|
let configSchema = await client.getConfigSchema();
|
|
468
554
|
expect(configSchema.schema.properties.prefix.type).toBe('string');
|
|
@@ -618,7 +704,7 @@ describe('@slates/client local transport', () => {
|
|
|
618
704
|
state: null
|
|
619
705
|
});
|
|
620
706
|
|
|
621
|
-
await client.request('slates/action.trigger.webhook_handle', {
|
|
707
|
+
let webhookResult = await client.request('slates/action.trigger.webhook_handle', {
|
|
622
708
|
actionId: 'webhook_trigger',
|
|
623
709
|
url: 'https://example.com/webhook',
|
|
624
710
|
method: 'POST',
|
|
@@ -628,6 +714,16 @@ describe('@slates/client local transport', () => {
|
|
|
628
714
|
body: null,
|
|
629
715
|
state: null
|
|
630
716
|
});
|
|
717
|
+
expect(webhookResult.response).toEqual({
|
|
718
|
+
status: 202,
|
|
719
|
+
headers: {
|
|
720
|
+
'x-trigger-result': 'accepted'
|
|
721
|
+
},
|
|
722
|
+
body: {
|
|
723
|
+
encoding: 'base64',
|
|
724
|
+
content: Buffer.from('accepted').toString('base64')
|
|
725
|
+
}
|
|
726
|
+
});
|
|
631
727
|
|
|
632
728
|
await waitForLogs();
|
|
633
729
|
|
|
@@ -651,6 +747,7 @@ describe('@slates/client local transport', () => {
|
|
|
651
747
|
component: 'action',
|
|
652
748
|
functionName: 'handleRequest',
|
|
653
749
|
inputCount: 2,
|
|
750
|
+
hasResponse: true,
|
|
654
751
|
actionId: 'webhook_trigger'
|
|
655
752
|
})
|
|
656
753
|
})
|
|
@@ -732,6 +829,49 @@ describe('@slates/client local transport', () => {
|
|
|
732
829
|
});
|
|
733
830
|
});
|
|
734
831
|
|
|
832
|
+
it('passes current profile config into token auth callbacks', async () => {
|
|
833
|
+
let seenConfig: SeenTokenConfig = {};
|
|
834
|
+
let client = createSlatesClient({
|
|
835
|
+
transport: createLocalSlateTransport({
|
|
836
|
+
slate: createTokenConfigSlate(seenConfig)
|
|
837
|
+
}),
|
|
838
|
+
state: {
|
|
839
|
+
config: {
|
|
840
|
+
prefix: 'configured'
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
let authOutput = await client.getAuthOutput({
|
|
846
|
+
authenticationMethodId: 'token_auth',
|
|
847
|
+
input: {
|
|
848
|
+
token: 'secret-token'
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
expect(authOutput.output).toEqual({
|
|
853
|
+
token: 'configured:secret-token'
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
let profile = await client.getAuthProfile({
|
|
857
|
+
authenticationMethodId: 'token_auth',
|
|
858
|
+
output: authOutput.output,
|
|
859
|
+
input: {
|
|
860
|
+
token: 'secret-token'
|
|
861
|
+
},
|
|
862
|
+
scopes: []
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
expect(profile.profile).toEqual({
|
|
866
|
+
prefix: 'configured',
|
|
867
|
+
token: 'configured:secret-token'
|
|
868
|
+
});
|
|
869
|
+
expect(seenConfig).toEqual({
|
|
870
|
+
output: { prefix: 'configured' },
|
|
871
|
+
profile: { prefix: 'configured' }
|
|
872
|
+
});
|
|
873
|
+
});
|
|
874
|
+
|
|
735
875
|
it('throws structured protocol errors for provider responses', async () => {
|
|
736
876
|
let client = createSlatesClient({
|
|
737
877
|
transport: {
|
|
@@ -901,4 +1041,114 @@ describe('@slates/client local transport', () => {
|
|
|
901
1041
|
});
|
|
902
1042
|
}
|
|
903
1043
|
});
|
|
1044
|
+
|
|
1045
|
+
it('lists, gets, and invokes public tools without config or auth', async () => {
|
|
1046
|
+
let config = SlateConfig.create(
|
|
1047
|
+
z.object({
|
|
1048
|
+
prefix: z.string()
|
|
1049
|
+
})
|
|
1050
|
+
);
|
|
1051
|
+
let auth = SlateAuth.create<{ token: string }>()
|
|
1052
|
+
.output(
|
|
1053
|
+
z.object({
|
|
1054
|
+
token: z.string()
|
|
1055
|
+
})
|
|
1056
|
+
)
|
|
1057
|
+
.addTokenAuth({
|
|
1058
|
+
type: 'auth.token',
|
|
1059
|
+
key: 'token_auth',
|
|
1060
|
+
name: 'Token Auth',
|
|
1061
|
+
inputSchema: z.object({
|
|
1062
|
+
token: z.string()
|
|
1063
|
+
}),
|
|
1064
|
+
getOutput: async ctx => ({
|
|
1065
|
+
output: {
|
|
1066
|
+
token: ctx.input.token
|
|
1067
|
+
}
|
|
1068
|
+
})
|
|
1069
|
+
});
|
|
1070
|
+
|
|
1071
|
+
let spec = SlateSpecification.create({
|
|
1072
|
+
key: 'public-tool-slate',
|
|
1073
|
+
name: 'Public Tool Slate',
|
|
1074
|
+
config,
|
|
1075
|
+
auth
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
let echoTool = SlateTool.create(spec, {
|
|
1079
|
+
key: 'echo',
|
|
1080
|
+
name: 'Echo'
|
|
1081
|
+
})
|
|
1082
|
+
.input(
|
|
1083
|
+
z.object({
|
|
1084
|
+
name: z.string()
|
|
1085
|
+
})
|
|
1086
|
+
)
|
|
1087
|
+
.output(
|
|
1088
|
+
z.object({
|
|
1089
|
+
greeting: z.string()
|
|
1090
|
+
})
|
|
1091
|
+
)
|
|
1092
|
+
.handleInvocation(async ctx => ({
|
|
1093
|
+
output: {
|
|
1094
|
+
greeting: `${ctx.config.prefix} ${ctx.input.name}`
|
|
1095
|
+
},
|
|
1096
|
+
message: 'done'
|
|
1097
|
+
}))
|
|
1098
|
+
.build();
|
|
1099
|
+
|
|
1100
|
+
let setupTool = SlatePublicTool.create(spec, {
|
|
1101
|
+
key: 'setup',
|
|
1102
|
+
name: 'Setup'
|
|
1103
|
+
})
|
|
1104
|
+
.input(z.object({}))
|
|
1105
|
+
.output(
|
|
1106
|
+
z.object({
|
|
1107
|
+
docsUrl: z.string()
|
|
1108
|
+
})
|
|
1109
|
+
)
|
|
1110
|
+
.handleInvocation(async ctx => {
|
|
1111
|
+
expect(ctx).not.toHaveProperty('config');
|
|
1112
|
+
expect(ctx).not.toHaveProperty('auth');
|
|
1113
|
+
|
|
1114
|
+
return {
|
|
1115
|
+
output: {
|
|
1116
|
+
docsUrl: 'https://example.com/setup'
|
|
1117
|
+
},
|
|
1118
|
+
message: 'ok'
|
|
1119
|
+
};
|
|
1120
|
+
})
|
|
1121
|
+
.build();
|
|
1122
|
+
|
|
1123
|
+
let client = createSlatesClient({
|
|
1124
|
+
transport: createLocalSlateTransport({
|
|
1125
|
+
slate: Slate.create({
|
|
1126
|
+
spec,
|
|
1127
|
+
tools: [echoTool, setupTool],
|
|
1128
|
+
triggers: []
|
|
1129
|
+
})
|
|
1130
|
+
})
|
|
1131
|
+
});
|
|
1132
|
+
|
|
1133
|
+
let tools = await client.listTools();
|
|
1134
|
+
expect(tools.map(tool => ({ id: tool.id, isPublic: tool.isPublic }))).toEqual([
|
|
1135
|
+
{ id: 'echo', isPublic: false },
|
|
1136
|
+
{ id: 'setup', isPublic: true }
|
|
1137
|
+
]);
|
|
1138
|
+
|
|
1139
|
+
let setup = await client.getTool('setup');
|
|
1140
|
+
expect(setup.isPublic).toBe(true);
|
|
1141
|
+
|
|
1142
|
+
let echo = await client.getTool('echo');
|
|
1143
|
+
expect(echo.isPublic).toBe(false);
|
|
1144
|
+
|
|
1145
|
+
let result = await client.invokeTool('setup', {});
|
|
1146
|
+
expect(result.output).toEqual({
|
|
1147
|
+
docsUrl: 'https://example.com/setup'
|
|
1148
|
+
});
|
|
1149
|
+
|
|
1150
|
+
await expect(client.invokeTool('echo', { name: 'Ada' })).rejects.toMatchObject({
|
|
1151
|
+
message: 'Session context has not been initialized'
|
|
1152
|
+
});
|
|
1153
|
+
});
|
|
904
1154
|
});
|
package/src/client.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
SLATES_PROTOCOL_VERSION,
|
|
3
3
|
type SlateAuthenticationMethod,
|
|
4
4
|
type SlatesAction,
|
|
5
|
+
type SlatesActionTool,
|
|
5
6
|
type SlatesMessageActionGetResponse,
|
|
6
7
|
type SlatesMessageActionInvokeResponse,
|
|
7
8
|
type SlatesMessageActionsListResponse,
|
|
@@ -173,9 +174,11 @@ export class SlatesProtocolClient {
|
|
|
173
174
|
return this.request('slates/actions.list', {});
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
async listTools(): Promise<
|
|
177
|
+
async listTools(): Promise<SlatesActionTool[]> {
|
|
177
178
|
let result = await this.listActions();
|
|
178
|
-
return result.actions.filter(
|
|
179
|
+
return result.actions.filter(
|
|
180
|
+
(action): action is SlatesActionTool => action.type === 'action.tool'
|
|
181
|
+
);
|
|
179
182
|
}
|
|
180
183
|
|
|
181
184
|
async listTriggers(): Promise<SlatesAction[]> {
|
|
@@ -356,6 +359,7 @@ export class SlatesProtocolClient {
|
|
|
356
359
|
headers?: Record<string, string>;
|
|
357
360
|
body?: string | Uint8Array | null;
|
|
358
361
|
state?: any;
|
|
362
|
+
registrationDetails?: any;
|
|
359
363
|
}): Promise<SlatesMessageActionTriggerWebhookHandleResponse['result']> {
|
|
360
364
|
this.ensureSession();
|
|
361
365
|
let encodedBody =
|
|
@@ -376,7 +380,8 @@ export class SlatesProtocolClient {
|
|
|
376
380
|
content: encodedBody
|
|
377
381
|
}
|
|
378
382
|
: null,
|
|
379
|
-
state: d.state ?? null
|
|
383
|
+
state: d.state ?? null,
|
|
384
|
+
registrationDetails: d.registrationDetails ?? null
|
|
380
385
|
});
|
|
381
386
|
}
|
|
382
387
|
|