@slates/provider-handler 1.0.0-rc.3 → 1.0.0-rc.32
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 +1475 -2
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.module.js +1452 -2
- package/package.json +11 -10
- package/src/attachments.test.ts +171 -0
- package/src/index.ts +1060 -137
- package/src/pQueue.test.ts +18 -0
- package/src/pQueue.ts +18 -0
- package/src/spec.test.ts +83 -0
- package/src/spec.ts +150 -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slates/provider-handler",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.32",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"package.json"
|
|
12
12
|
],
|
|
13
13
|
"author": "Tobias Herber",
|
|
14
|
-
"license": "
|
|
14
|
+
"license": "FSL 1.1",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"source": "src/index.ts",
|
|
17
17
|
"exports": {
|
|
@@ -23,22 +23,23 @@
|
|
|
23
23
|
"main": "./dist/index.cjs",
|
|
24
24
|
"module": "./dist/index.module.js",
|
|
25
25
|
"types": "dist/index.d.ts",
|
|
26
|
-
"unpkg": "./dist/index.
|
|
26
|
+
"unpkg": "./dist/index.module.js",
|
|
27
27
|
"scripts": {
|
|
28
28
|
"test": "vitest run --passWithNoTests",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
29
|
+
"build": "tsup --config ../../tsup.packages.config.ts",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"biome:check": "biome check --write src"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@lowerdeck/error": "^1.0
|
|
34
|
-
"@slates/proto": "
|
|
35
|
-
"@slates/provider": "
|
|
36
|
-
"
|
|
34
|
+
"@lowerdeck/error": "^1.1.0",
|
|
35
|
+
"@slates/proto": "1.0.0-rc.19",
|
|
36
|
+
"@slates/provider": "1.0.0-rc.23",
|
|
37
|
+
"p-queue": "^6.6.2",
|
|
37
38
|
"zod": "^4.2.1"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"microbundle": "^0.15.1",
|
|
41
|
-
"@slates/tsconfig": "
|
|
42
|
+
"@slates/tsconfig": "1.0.0-rc.1",
|
|
42
43
|
"typescript": "5.8.2",
|
|
43
44
|
"vitest": "^3.1.2"
|
|
44
45
|
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { SLATES_PROTOCOL_VERSION, SlatesProviderProtoHandlerManager } from '@slates/proto';
|
|
2
|
+
import {
|
|
3
|
+
Slate,
|
|
4
|
+
SlateAuth,
|
|
5
|
+
SlateConfig,
|
|
6
|
+
SlatePublicTool,
|
|
7
|
+
SlateSpecification
|
|
8
|
+
} from '@slates/provider';
|
|
9
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { createProviderHandler } from './index';
|
|
12
|
+
|
|
13
|
+
let createManager = async () => {
|
|
14
|
+
let spec = SlateSpecification.create({
|
|
15
|
+
key: 'attachments-test',
|
|
16
|
+
name: 'Attachments Test',
|
|
17
|
+
config: SlateConfig.create(z.object({})),
|
|
18
|
+
auth: SlateAuth.create().output(z.object({}))
|
|
19
|
+
});
|
|
20
|
+
let tool = SlatePublicTool.create(spec, {
|
|
21
|
+
key: 'attach',
|
|
22
|
+
name: 'Attach'
|
|
23
|
+
})
|
|
24
|
+
.input(z.object({}))
|
|
25
|
+
.output(z.object({}))
|
|
26
|
+
.handleInvocation(async ctx => {
|
|
27
|
+
await ctx.addAttachment({
|
|
28
|
+
type: 'content',
|
|
29
|
+
content: new Response('hello', {
|
|
30
|
+
headers: { 'content-type': 'text/plain' }
|
|
31
|
+
}),
|
|
32
|
+
filename: 'hello.txt'
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return { output: {}, message: 'ok' };
|
|
36
|
+
})
|
|
37
|
+
.build();
|
|
38
|
+
let slate = Slate.create({ spec, triggers: [], tools: [tool] });
|
|
39
|
+
let manager = await createProviderHandler(slate, []).run();
|
|
40
|
+
|
|
41
|
+
await SlatesProviderProtoHandlerManager.handleInput(manager, {
|
|
42
|
+
jsonrpc: '2.0',
|
|
43
|
+
method: 'slates/hello',
|
|
44
|
+
params: { protocol: SLATES_PROTOCOL_VERSION }
|
|
45
|
+
});
|
|
46
|
+
await SlatesProviderProtoHandlerManager.handleInput(manager, {
|
|
47
|
+
jsonrpc: '2.0',
|
|
48
|
+
method: 'slates/participant.set',
|
|
49
|
+
params: {
|
|
50
|
+
participants: [
|
|
51
|
+
{ type: 'consumer', id: 'consumer', name: 'Consumer' },
|
|
52
|
+
{ type: 'hub', id: 'hub', name: 'Hub' }
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return manager;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
let invoke = async (manager: SlatesProviderProtoHandlerManager) =>
|
|
61
|
+
SlatesProviderProtoHandlerManager.handleInput(manager, {
|
|
62
|
+
jsonrpc: '2.0',
|
|
63
|
+
id: 'request',
|
|
64
|
+
method: 'slates/action.tool.invoke',
|
|
65
|
+
params: { actionId: 'attach', input: {} }
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
let expectInlineAttachment = (response: Awaited<ReturnType<typeof invoke>>) => {
|
|
69
|
+
expect(response).toMatchObject({
|
|
70
|
+
result: {
|
|
71
|
+
attachments: [
|
|
72
|
+
{
|
|
73
|
+
mimeType: 'text/plain',
|
|
74
|
+
content: {
|
|
75
|
+
type: 'content',
|
|
76
|
+
encoding: 'base64',
|
|
77
|
+
content: Buffer.from('hello').toString('base64')
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
describe('addAttachment fallback', () => {
|
|
86
|
+
afterEach(() => {
|
|
87
|
+
vi.restoreAllMocks();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('returns a standard inline attachment when capabilities and a live token are absent', async () => {
|
|
91
|
+
let fetchSpy = vi.spyOn(globalThis, 'fetch');
|
|
92
|
+
let response = await invoke(await createManager());
|
|
93
|
+
|
|
94
|
+
expectInlineAttachment(response);
|
|
95
|
+
expect(fetchSpy).not.toHaveBeenCalled();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('returns a standard inline attachment when direct upload is enabled without a live token', async () => {
|
|
99
|
+
let manager = await createManager();
|
|
100
|
+
let fetchSpy = vi.spyOn(globalThis, 'fetch');
|
|
101
|
+
|
|
102
|
+
await SlatesProviderProtoHandlerManager.handleInput(manager, {
|
|
103
|
+
jsonrpc: '2.0',
|
|
104
|
+
method: 'slates/hub.capabilities.set',
|
|
105
|
+
params: { capabilities: { attachments: { directUpload: { enabled: true } } } }
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expectInlineAttachment(await invoke(manager));
|
|
109
|
+
expect(fetchSpy).not.toHaveBeenCalled();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('returns a standard inline attachment when a live token exists without the capability', async () => {
|
|
113
|
+
let manager = await createManager();
|
|
114
|
+
let fetchSpy = vi.spyOn(globalThis, 'fetch');
|
|
115
|
+
|
|
116
|
+
await SlatesProviderProtoHandlerManager.handleInput(manager, {
|
|
117
|
+
jsonrpc: '2.0',
|
|
118
|
+
method: 'slates/hub.live_invocation.set',
|
|
119
|
+
params: { token: 'token', baseUrl: 'https://hub.example' }
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
expectInlineAttachment(await invoke(manager));
|
|
123
|
+
expect(fetchSpy).not.toHaveBeenCalled();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('uses direct upload only when both the capability and live token exist', async () => {
|
|
127
|
+
let manager = await createManager();
|
|
128
|
+
let fetchSpy = vi
|
|
129
|
+
.spyOn(globalThis, 'fetch')
|
|
130
|
+
.mockResolvedValueOnce(
|
|
131
|
+
new Response(
|
|
132
|
+
JSON.stringify({
|
|
133
|
+
attachments: [
|
|
134
|
+
{
|
|
135
|
+
referenceId: 'attachment-reference',
|
|
136
|
+
uploadUrl: 'https://uploads.example/attachment'
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
}),
|
|
140
|
+
{ status: 200, headers: { 'content-type': 'application/json' } }
|
|
141
|
+
)
|
|
142
|
+
)
|
|
143
|
+
.mockResolvedValueOnce(new Response(null, { status: 200 }));
|
|
144
|
+
|
|
145
|
+
await SlatesProviderProtoHandlerManager.handleInput(manager, {
|
|
146
|
+
jsonrpc: '2.0',
|
|
147
|
+
method: 'slates/hub.capabilities.set',
|
|
148
|
+
params: { capabilities: { attachments: { directUpload: { enabled: true } } } }
|
|
149
|
+
});
|
|
150
|
+
await SlatesProviderProtoHandlerManager.handleInput(manager, {
|
|
151
|
+
jsonrpc: '2.0',
|
|
152
|
+
method: 'slates/hub.live_invocation.set',
|
|
153
|
+
params: { token: 'token', baseUrl: 'https://hub.example' }
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
expect(await invoke(manager)).toMatchObject({
|
|
157
|
+
result: {
|
|
158
|
+
attachments: [
|
|
159
|
+
{
|
|
160
|
+
mimeType: 'text/plain',
|
|
161
|
+
content: {
|
|
162
|
+
type: 'upload_reference',
|
|
163
|
+
referenceId: 'attachment-reference'
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
expect(fetchSpy).toHaveBeenCalledTimes(2);
|
|
170
|
+
});
|
|
171
|
+
});
|