@slates/provider 1.0.0-rc.7 → 1.0.0-rc.9
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 +1619 -2
- package/dist/index.d.cts +620 -0
- package/dist/index.d.ts +620 -9
- package/dist/index.module.js +1547 -2
- package/package.json +6 -4
- package/src/action/action.ts +18 -3
- package/src/action/attachment.ts +41 -0
- package/src/action/builder.ts +21 -4
- package/src/action/index.ts +2 -2
- package/src/action/scopes.test.ts +77 -0
- package/src/action/scopes.ts +101 -0
- package/src/action/tool.ts +8 -4
- package/src/action/trigger.ts +11 -11
- package/src/auth/auth.ts +3 -3
- package/src/auth/types.ts +7 -6
- package/src/axios/index.ts +55 -23
- package/src/axios/trace.ts +443 -0
- package/src/config/config.ts +3 -3
- package/src/context/context.ts +29 -2
- package/src/context/hook.ts +1 -1
- package/src/error/axios.ts +219 -0
- package/src/error/base.test.ts +178 -0
- package/src/error/base.ts +108 -2
- package/src/error/declaration.ts +7 -2
- package/src/error/defaults.ts +50 -0
- package/src/error/index.ts +3 -0
- package/src/error/service.ts +160 -0
- package/src/error/types.ts +73 -0
- package/src/error/utils.ts +155 -0
- package/src/index.ts +1 -0
- package/src/logger/logger.test.ts +57 -0
- package/src/logger/logger.ts +72 -11
- package/src/specification/slate.ts +2 -2
- package/src/specification/specification.ts +2 -2
- package/dist/action/action.d.ts +0 -98
- 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 -14
- package/dist/action/tool.d.ts.map +0 -1
- package/dist/action/trigger.d.ts +0 -32
- package/dist/action/trigger.d.ts.map +0 -1
- package/dist/auth/auth.d.ts +0 -30
- 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 -150
- 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 -26
- 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 -3
- 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/logger/index.d.ts +0 -2
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/logger/logger.d.ts +0 -20
- package/dist/logger/logger.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/tokens.d.ts +0 -34
- package/dist/tokens.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,620 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import z, { z as z$1 } from 'zod';
|
|
2
|
+
import { AxiosResponse, AxiosError, CreateAxiosDefaults, AxiosInstance } from 'axios';
|
|
3
|
+
import { ServiceError, ErrorRecord, ErrorData } from '@lowerdeck/error';
|
|
4
|
+
|
|
5
|
+
interface SlateHttpTraceTextBody {
|
|
6
|
+
contentType?: string;
|
|
7
|
+
text: string;
|
|
8
|
+
truncated?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface SlateHttpTrace {
|
|
11
|
+
startedAt: string;
|
|
12
|
+
durationMs: number;
|
|
13
|
+
request: {
|
|
14
|
+
method: string;
|
|
15
|
+
url: string;
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
body?: SlateHttpTraceTextBody;
|
|
18
|
+
};
|
|
19
|
+
response?: {
|
|
20
|
+
status: number;
|
|
21
|
+
statusText?: string;
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
body?: SlateHttpTraceTextBody;
|
|
24
|
+
};
|
|
25
|
+
error?: {
|
|
26
|
+
code?: string;
|
|
27
|
+
message: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type SlateLogType = 'info' | 'warn' | 'error' | 'progress';
|
|
32
|
+
type SlateLogFields = Record<string, unknown>;
|
|
33
|
+
type SlateLogMessageInput = string | Error | boolean | number | null | undefined | object | SlateLogMessageInput[];
|
|
34
|
+
interface SlateLogEntry {
|
|
35
|
+
type: SlateLogType;
|
|
36
|
+
message: string;
|
|
37
|
+
timestamp: Date;
|
|
38
|
+
data?: SlateLogFields;
|
|
39
|
+
}
|
|
40
|
+
type SlateLogListener = (entries: SlateLogEntry[]) => void;
|
|
41
|
+
declare class SlateLogger {
|
|
42
|
+
#private;
|
|
43
|
+
constructor(listeners?: SlateLogListener[]);
|
|
44
|
+
private flush;
|
|
45
|
+
private scheduleFlush;
|
|
46
|
+
log(type: SlateLogType, message: SlateLogMessageInput): void;
|
|
47
|
+
info(...message: SlateLogMessageInput[]): void;
|
|
48
|
+
warn(...message: SlateLogMessageInput[]): void;
|
|
49
|
+
error(...message: SlateLogMessageInput[]): void;
|
|
50
|
+
progress(...message: SlateLogMessageInput[]): void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type SlateAuthWithOauth<InputType extends {}, OutputType extends {
|
|
54
|
+
token: string;
|
|
55
|
+
refreshToken?: string;
|
|
56
|
+
expiresAt?: number | string | Date;
|
|
57
|
+
}> = {
|
|
58
|
+
type: 'auth.oauth';
|
|
59
|
+
name: string;
|
|
60
|
+
key: string;
|
|
61
|
+
scopes: {
|
|
62
|
+
title: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
scope: string;
|
|
65
|
+
}[];
|
|
66
|
+
inputSchema?: z.ZodType<InputType>;
|
|
67
|
+
onInputChanged?: (params: {
|
|
68
|
+
previousInput: InputType | null;
|
|
69
|
+
newInput: InputType;
|
|
70
|
+
}) => Promise<{
|
|
71
|
+
input?: InputType;
|
|
72
|
+
} | undefined>;
|
|
73
|
+
getDefaultInput?: () => Promise<InputType>;
|
|
74
|
+
getAuthorizationUrl: (ctx: {
|
|
75
|
+
redirectUri: string;
|
|
76
|
+
state: string;
|
|
77
|
+
input: InputType;
|
|
78
|
+
clientId: string;
|
|
79
|
+
clientSecret: string;
|
|
80
|
+
scopes: string[];
|
|
81
|
+
}) => Promise<{
|
|
82
|
+
url: string;
|
|
83
|
+
input?: InputType;
|
|
84
|
+
callbackState?: Record<string, any>;
|
|
85
|
+
}>;
|
|
86
|
+
handleCallback: (ctx: {
|
|
87
|
+
code: string;
|
|
88
|
+
state: string;
|
|
89
|
+
redirectUri: string;
|
|
90
|
+
input: InputType;
|
|
91
|
+
clientId: string;
|
|
92
|
+
clientSecret: string;
|
|
93
|
+
scopes: string[];
|
|
94
|
+
callbackState: Record<string, any>;
|
|
95
|
+
}) => Promise<{
|
|
96
|
+
output: OutputType;
|
|
97
|
+
input?: InputType;
|
|
98
|
+
scopes?: string[];
|
|
99
|
+
}>;
|
|
100
|
+
handleTokenRefresh?: (ctx: {
|
|
101
|
+
output: OutputType;
|
|
102
|
+
input: InputType;
|
|
103
|
+
clientId: string;
|
|
104
|
+
clientSecret: string;
|
|
105
|
+
scopes: string[];
|
|
106
|
+
}) => Promise<{
|
|
107
|
+
output: OutputType;
|
|
108
|
+
input?: InputType;
|
|
109
|
+
}>;
|
|
110
|
+
getProfile?: (ctx: {
|
|
111
|
+
output: OutputType;
|
|
112
|
+
input: InputType;
|
|
113
|
+
scopes: string[];
|
|
114
|
+
}) => Promise<{
|
|
115
|
+
profile: Record<string, any>;
|
|
116
|
+
}>;
|
|
117
|
+
};
|
|
118
|
+
type SlateAuthWithToken<InputType extends {}, OutputType extends {
|
|
119
|
+
token?: string;
|
|
120
|
+
}> = {
|
|
121
|
+
type: 'auth.token';
|
|
122
|
+
name: string;
|
|
123
|
+
key: string;
|
|
124
|
+
inputSchema?: z.ZodType<InputType>;
|
|
125
|
+
getOutput: (ctx: {
|
|
126
|
+
input: InputType;
|
|
127
|
+
}) => Promise<{
|
|
128
|
+
output: OutputType;
|
|
129
|
+
}>;
|
|
130
|
+
onInputChanged?: (params: {
|
|
131
|
+
previousInput: InputType;
|
|
132
|
+
newInput: InputType;
|
|
133
|
+
}) => Promise<{
|
|
134
|
+
input?: InputType;
|
|
135
|
+
} | undefined>;
|
|
136
|
+
getDefaultInput?: () => Promise<InputType>;
|
|
137
|
+
getProfile?: (ctx: {
|
|
138
|
+
output: OutputType;
|
|
139
|
+
input: InputType;
|
|
140
|
+
}) => Promise<{
|
|
141
|
+
profile: Record<string, any>;
|
|
142
|
+
}>;
|
|
143
|
+
};
|
|
144
|
+
type SlateAuthWithServiceAccount<InputType extends {}, OutputType extends {}> = {
|
|
145
|
+
type: 'auth.service_account';
|
|
146
|
+
name: string;
|
|
147
|
+
key: string;
|
|
148
|
+
inputSchema?: z.ZodType<InputType>;
|
|
149
|
+
getOutput: (ctx: {
|
|
150
|
+
input: InputType;
|
|
151
|
+
}) => Promise<{
|
|
152
|
+
output: OutputType;
|
|
153
|
+
}>;
|
|
154
|
+
onInputChanged?: (params: {
|
|
155
|
+
previousInput: InputType;
|
|
156
|
+
newInput: InputType;
|
|
157
|
+
}) => Promise<{
|
|
158
|
+
input?: InputType;
|
|
159
|
+
} | undefined>;
|
|
160
|
+
getDefaultInput?: () => Promise<InputType>;
|
|
161
|
+
getProfile?: (ctx: {
|
|
162
|
+
output: OutputType;
|
|
163
|
+
input: InputType;
|
|
164
|
+
}) => Promise<{
|
|
165
|
+
profile: Record<string, any>;
|
|
166
|
+
}>;
|
|
167
|
+
};
|
|
168
|
+
type SlateAuthWithCustomData<InputType extends {}, OutputType extends {}> = {
|
|
169
|
+
type: 'auth.custom';
|
|
170
|
+
name: string;
|
|
171
|
+
key: string;
|
|
172
|
+
inputSchema?: z.ZodType<InputType>;
|
|
173
|
+
getOutput: (ctx: {
|
|
174
|
+
input: InputType;
|
|
175
|
+
}) => Promise<{
|
|
176
|
+
output: OutputType;
|
|
177
|
+
}>;
|
|
178
|
+
onInputChanged?: (params: {
|
|
179
|
+
previousInput: InputType;
|
|
180
|
+
newInput: InputType;
|
|
181
|
+
}) => Promise<{
|
|
182
|
+
input?: InputType;
|
|
183
|
+
} | undefined>;
|
|
184
|
+
getDefaultInput?: () => Promise<InputType>;
|
|
185
|
+
getProfile?: (ctx: {
|
|
186
|
+
output: OutputType;
|
|
187
|
+
input: InputType;
|
|
188
|
+
}) => Promise<{
|
|
189
|
+
profile: Record<string, any>;
|
|
190
|
+
}>;
|
|
191
|
+
};
|
|
192
|
+
type SlateAuthWithNone<_InputType extends {}, _OutputType extends {}> = {
|
|
193
|
+
type: 'auth.none';
|
|
194
|
+
name: string;
|
|
195
|
+
key: string;
|
|
196
|
+
};
|
|
197
|
+
type SlateAuthType<InputType extends {}, OutputType extends {}> = SlateAuthWithOauth<InputType, OutputType & {
|
|
198
|
+
token: string;
|
|
199
|
+
}> | SlateAuthWithToken<InputType, OutputType & {
|
|
200
|
+
token?: string;
|
|
201
|
+
}> | SlateAuthWithServiceAccount<InputType, OutputType> | SlateAuthWithCustomData<InputType, OutputType> | SlateAuthWithNone<InputType, OutputType>;
|
|
202
|
+
|
|
203
|
+
declare class SlateAuth<OutputType extends {} = {}> {
|
|
204
|
+
#private;
|
|
205
|
+
private constructor();
|
|
206
|
+
static create<OutputType extends {}>(): SlateAuth<OutputType>;
|
|
207
|
+
output<NewOutputType extends {}>(schema: z.ZodType<NewOutputType>): SlateAuth<NewOutputType>;
|
|
208
|
+
private addAuth;
|
|
209
|
+
addOauth<InputType extends {}>(auth: SlateAuthType<InputType, OutputType> & {
|
|
210
|
+
type: 'auth.oauth';
|
|
211
|
+
}): SlateAuth<OutputType>;
|
|
212
|
+
addTokenAuth<InputType extends {}>(auth: SlateAuthType<InputType, OutputType> & {
|
|
213
|
+
type: 'auth.token';
|
|
214
|
+
}): SlateAuth<OutputType>;
|
|
215
|
+
addServiceAccountAuth<InputType extends {}>(auth: SlateAuthType<InputType, OutputType> & {
|
|
216
|
+
type: 'auth.service_account';
|
|
217
|
+
}): SlateAuth<OutputType>;
|
|
218
|
+
addCustomAuth<InputType extends {}>(auth: SlateAuthType<InputType, OutputType> & {
|
|
219
|
+
type: 'auth.custom';
|
|
220
|
+
}): SlateAuth<OutputType>;
|
|
221
|
+
addNone(): SlateAuth<OutputType>;
|
|
222
|
+
get authStack(): (SlateAuthWithOauth<any, OutputType & {
|
|
223
|
+
token: string;
|
|
224
|
+
}> | SlateAuthWithToken<any, OutputType & {
|
|
225
|
+
token?: string;
|
|
226
|
+
}> | SlateAuthWithServiceAccount<any, OutputType> | SlateAuthWithCustomData<any, OutputType>)[];
|
|
227
|
+
get outputSchema(): z.ZodType<OutputType, unknown, z.core.$ZodTypeInternals<OutputType, unknown>>;
|
|
228
|
+
}
|
|
229
|
+
declare let auth: <OutputType extends {} = {}>() => SlateAuth<OutputType>;
|
|
230
|
+
|
|
231
|
+
declare class SlateConfig<ConfigType extends {}> {
|
|
232
|
+
#private;
|
|
233
|
+
private constructor();
|
|
234
|
+
static create<ConfigType extends {}>(schema: z.ZodType<ConfigType>): SlateConfig<ConfigType>;
|
|
235
|
+
config<NewConfigType extends {}>(schema: z.ZodType<NewConfigType>): SlateConfig<NewConfigType>;
|
|
236
|
+
onConfigChanged(handler: (params: {
|
|
237
|
+
previousConfig: ConfigType | null;
|
|
238
|
+
newConfig: ConfigType;
|
|
239
|
+
}) => {
|
|
240
|
+
config: ConfigType | undefined;
|
|
241
|
+
} | undefined): SlateConfig<ConfigType>;
|
|
242
|
+
getDefaultConfig(getter: () => ConfigType): SlateConfig<ConfigType>;
|
|
243
|
+
get configSchema(): z.ZodType<ConfigType, unknown, z.core.$ZodTypeInternals<ConfigType, unknown>>;
|
|
244
|
+
get handlers(): {
|
|
245
|
+
configChanged: ((params: {
|
|
246
|
+
previousConfig: ConfigType | null;
|
|
247
|
+
newConfig: ConfigType;
|
|
248
|
+
}) => {
|
|
249
|
+
config: ConfigType | undefined;
|
|
250
|
+
} | undefined) | null;
|
|
251
|
+
getDefaultConfig: (() => ConfigType) | null;
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
declare let config: <ConfigType extends {}>(schema: z.ZodType<ConfigType>) => SlateConfig<ConfigType>;
|
|
255
|
+
|
|
256
|
+
interface SlateSpecificationParameters {
|
|
257
|
+
key: string;
|
|
258
|
+
name: string;
|
|
259
|
+
description?: string;
|
|
260
|
+
metadata?: Record<string, any>;
|
|
261
|
+
}
|
|
262
|
+
interface SlateSpecificationCreateParameters<ConfigType extends {}, AuthType extends {}> extends SlateSpecificationParameters {
|
|
263
|
+
config: SlateConfig<ConfigType>;
|
|
264
|
+
auth: SlateAuth<AuthType>;
|
|
265
|
+
}
|
|
266
|
+
declare class SlateSpecification<ConfigType extends {}, AuthType extends {}> {
|
|
267
|
+
private readonly _config;
|
|
268
|
+
private readonly _auth;
|
|
269
|
+
private readonly _params;
|
|
270
|
+
private constructor();
|
|
271
|
+
static create<ConfigType extends {}, AuthType extends {}>(params: SlateSpecificationCreateParameters<ConfigType, AuthType>): SlateSpecification<ConfigType, AuthType>;
|
|
272
|
+
get configSchema(): z.ZodType<ConfigType, unknown, z.core.$ZodTypeInternals<ConfigType, unknown>>;
|
|
273
|
+
get authSchema(): z.ZodType<AuthType>;
|
|
274
|
+
get config(): SlateConfig<ConfigType>;
|
|
275
|
+
get auth(): SlateAuth<AuthType>;
|
|
276
|
+
get parameters(): SlateSpecificationParameters;
|
|
277
|
+
get key(): string;
|
|
278
|
+
get name(): string;
|
|
279
|
+
get description(): string | undefined;
|
|
280
|
+
}
|
|
281
|
+
declare let spec: <ConfigType extends {}, AuthType extends {}>(params: SlateSpecificationCreateParameters<ConfigType, AuthType>) => SlateSpecification<ConfigType, AuthType>;
|
|
282
|
+
|
|
283
|
+
declare class SlateContext<ConfigType extends {}, AuthType extends {}, InputType extends {}> {
|
|
284
|
+
#private;
|
|
285
|
+
private readonly spec;
|
|
286
|
+
private readonly logger;
|
|
287
|
+
constructor(config: ConfigType, input: InputType, auth: AuthType, spec: SlateSpecification<ConfigType, AuthType>, logger: SlateLogger);
|
|
288
|
+
get specification(): SlateSpecification<ConfigType, AuthType>;
|
|
289
|
+
get config(): Readonly<ConfigType>;
|
|
290
|
+
get input(): Readonly<InputType>;
|
|
291
|
+
get event(): Readonly<InputType>;
|
|
292
|
+
get state(): "state" extends keyof InputType ? InputType["state"] : never;
|
|
293
|
+
get request(): "request" extends keyof InputType ? InputType["request"] : never;
|
|
294
|
+
get auth(): Readonly<AuthType>;
|
|
295
|
+
recordHttpTrace(trace: SlateHttpTrace): void;
|
|
296
|
+
getHttpTraces(): {
|
|
297
|
+
error?: {
|
|
298
|
+
code?: string;
|
|
299
|
+
message: string;
|
|
300
|
+
};
|
|
301
|
+
response?: {
|
|
302
|
+
status: number;
|
|
303
|
+
statusText?: string;
|
|
304
|
+
headers?: Record<string, string>;
|
|
305
|
+
body?: SlateHttpTraceTextBody;
|
|
306
|
+
};
|
|
307
|
+
request: {
|
|
308
|
+
body?: SlateHttpTraceTextBody;
|
|
309
|
+
headers?: Record<string, string>;
|
|
310
|
+
method: string;
|
|
311
|
+
url: string;
|
|
312
|
+
};
|
|
313
|
+
startedAt: string;
|
|
314
|
+
durationMs: number;
|
|
315
|
+
}[];
|
|
316
|
+
info(message: SlateLogMessageInput): void;
|
|
317
|
+
warn(message: SlateLogMessageInput): void;
|
|
318
|
+
error(message: SlateLogMessageInput): void;
|
|
319
|
+
progress(message: SlateLogMessageInput): void;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
declare let runWithContext: <ConfigType extends {}, AuthType extends {}, InputType extends {}, RV>(context: SlateContext<ConfigType, AuthType, InputType>, fn: () => Promise<RV>) => Promise<RV>;
|
|
323
|
+
declare let getCurrentContext: <ConfigType extends {}, AuthType extends {}, InputType extends {}>() => SlateContext<ConfigType, AuthType, InputType>;
|
|
324
|
+
|
|
325
|
+
interface SlateAttachmentUrlContent {
|
|
326
|
+
type: 'url';
|
|
327
|
+
url: string;
|
|
328
|
+
}
|
|
329
|
+
interface SlateAttachmentInlineContent {
|
|
330
|
+
type: 'content';
|
|
331
|
+
encoding: 'base64' | 'utf-8';
|
|
332
|
+
content: string;
|
|
333
|
+
}
|
|
334
|
+
interface SlateAttachment {
|
|
335
|
+
mimeType?: string;
|
|
336
|
+
content: SlateAttachmentUrlContent | SlateAttachmentInlineContent;
|
|
337
|
+
}
|
|
338
|
+
declare let createUrlAttachment: (url: string, mimeType?: string) => SlateAttachment;
|
|
339
|
+
declare let createBase64Attachment: (content: string, mimeType?: string) => SlateAttachment;
|
|
340
|
+
declare let createTextAttachment: (content: string, mimeType?: string) => SlateAttachment;
|
|
341
|
+
|
|
342
|
+
type SlateActionType = 'tool' | 'trigger';
|
|
343
|
+
interface SlateActionScopeClause {
|
|
344
|
+
OR: string[];
|
|
345
|
+
}
|
|
346
|
+
interface SlateActionScopes {
|
|
347
|
+
AND: SlateActionScopeClause[];
|
|
348
|
+
}
|
|
349
|
+
interface SlateActionParameters {
|
|
350
|
+
key: string;
|
|
351
|
+
name: string;
|
|
352
|
+
description?: string;
|
|
353
|
+
instructions?: string[];
|
|
354
|
+
constraints?: string[];
|
|
355
|
+
tags?: {
|
|
356
|
+
destructive?: boolean;
|
|
357
|
+
readOnly?: boolean;
|
|
358
|
+
[key: string]: boolean | undefined;
|
|
359
|
+
};
|
|
360
|
+
metadata?: Record<string, any>;
|
|
361
|
+
scopes?: SlateActionScopes;
|
|
362
|
+
}
|
|
363
|
+
type SlateToolInvocationHandler<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> = (context: SlateContext<ConfigType, AuthType, InputType>) => Promise<{
|
|
364
|
+
output: OutputType;
|
|
365
|
+
message: string;
|
|
366
|
+
attachments?: SlateAttachment[];
|
|
367
|
+
}>;
|
|
368
|
+
type SlateTriggerMappingHandler<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> = (context: SlateContext<ConfigType, AuthType, InputType>) => Promise<{
|
|
369
|
+
type: string;
|
|
370
|
+
id: string;
|
|
371
|
+
output: OutputType;
|
|
372
|
+
}>;
|
|
373
|
+
type SlateTriggerPollingHandler<ConfigType extends {}, AuthType extends {}, InputType extends {}> = (context: SlateContext<ConfigType, AuthType, {
|
|
374
|
+
state: any | null;
|
|
375
|
+
}>) => Promise<{
|
|
376
|
+
inputs: InputType[];
|
|
377
|
+
updatedState?: any;
|
|
378
|
+
}>;
|
|
379
|
+
type SlateTriggerWebhookRequestHandler<ConfigType extends {}, AuthType extends {}, InputType extends {}> = (context: SlateContext<ConfigType, AuthType, {
|
|
380
|
+
request: Request;
|
|
381
|
+
state: any | null;
|
|
382
|
+
}>) => Promise<{
|
|
383
|
+
inputs: InputType[];
|
|
384
|
+
updatedState?: any;
|
|
385
|
+
}>;
|
|
386
|
+
type SlateTriggerWebhookAutoRegistrationHandler<ConfigType extends {}, AuthType extends {}> = (context: SlateContext<ConfigType, AuthType, {
|
|
387
|
+
webhookBaseUrl: string;
|
|
388
|
+
}>) => Promise<{
|
|
389
|
+
registrationDetails: any;
|
|
390
|
+
state?: any;
|
|
391
|
+
}>;
|
|
392
|
+
type SlateTriggerWebhookAutoUnregistrationHandler<ConfigType extends {}, AuthType extends {}> = (context: SlateContext<ConfigType, AuthType, {
|
|
393
|
+
webhookBaseUrl: string;
|
|
394
|
+
registrationDetails: any;
|
|
395
|
+
state: any | null;
|
|
396
|
+
}>) => Promise<unknown>;
|
|
397
|
+
interface SlateActionParametersTool<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> {
|
|
398
|
+
type: 'tool';
|
|
399
|
+
handleInvocation: SlateToolInvocationHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
400
|
+
}
|
|
401
|
+
interface SlatePollingOptions {
|
|
402
|
+
intervalInSeconds?: number;
|
|
403
|
+
}
|
|
404
|
+
interface SlateActionParametersTrigger<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> {
|
|
405
|
+
type: 'trigger';
|
|
406
|
+
source: 'polling' | 'webhook';
|
|
407
|
+
polling?: SlatePollingOptions;
|
|
408
|
+
handleEvent: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
409
|
+
handleRequest?: SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType>;
|
|
410
|
+
pollEvents?: SlateTriggerPollingHandler<ConfigType, AuthType, InputType>;
|
|
411
|
+
autoRegisterWebhook?: SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType>;
|
|
412
|
+
autoUnregisterWebhook?: SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType>;
|
|
413
|
+
}
|
|
414
|
+
type SlateActionParametersAny<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> = SlateActionParametersTool<ConfigType, AuthType, InputType, OutputType> | SlateActionParametersTrigger<ConfigType, AuthType, InputType, OutputType>;
|
|
415
|
+
type SlateActionCreateParameters<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> = SlateActionParametersAny<ConfigType, AuthType, InputType, OutputType> & SlateActionParameters & {
|
|
416
|
+
configSchema: z$1.ZodType<ConfigType>;
|
|
417
|
+
authSchema: z$1.ZodType<AuthType>;
|
|
418
|
+
inputSchema: z$1.ZodType<InputType>;
|
|
419
|
+
outputSchema: z$1.ZodType<OutputType>;
|
|
420
|
+
};
|
|
421
|
+
declare abstract class SlateAction<Type extends SlateActionType, ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> {
|
|
422
|
+
readonly type: Type;
|
|
423
|
+
protected readonly _spec: SlateSpecification<ConfigType, AuthType>;
|
|
424
|
+
protected readonly _inputSchema: z$1.ZodType<InputType>;
|
|
425
|
+
protected readonly _outputSchema: z$1.ZodType<OutputType>;
|
|
426
|
+
protected readonly _params: SlateActionParameters;
|
|
427
|
+
constructor(type: Type, _spec: SlateSpecification<ConfigType, AuthType>, _inputSchema: z$1.ZodType<InputType>, _outputSchema: z$1.ZodType<OutputType>, _params: SlateActionParameters);
|
|
428
|
+
get configSchema(): z$1.ZodType<ConfigType, unknown, z$1.core.$ZodTypeInternals<ConfigType, unknown>>;
|
|
429
|
+
get inputSchema(): z$1.ZodType<InputType, unknown, z$1.core.$ZodTypeInternals<InputType, unknown>>;
|
|
430
|
+
get outputSchema(): z$1.ZodType<OutputType, unknown, z$1.core.$ZodTypeInternals<OutputType, unknown>>;
|
|
431
|
+
get parameters(): SlateActionParameters;
|
|
432
|
+
get key(): string;
|
|
433
|
+
get name(): string;
|
|
434
|
+
get description(): string | undefined;
|
|
435
|
+
get tags(): {
|
|
436
|
+
[key: string]: boolean | undefined;
|
|
437
|
+
destructive?: boolean;
|
|
438
|
+
readOnly?: boolean;
|
|
439
|
+
} | undefined;
|
|
440
|
+
get instructions(): string[] | undefined;
|
|
441
|
+
get constraints(): string[] | undefined;
|
|
442
|
+
get metadata(): Record<string, any> | undefined;
|
|
443
|
+
get scopes(): SlateActionScopes | undefined;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
type SlateActionScopeValue = string;
|
|
447
|
+
type SlateActionScopeClauseInput = SlateActionScopeValue | readonly SlateActionScopeValue[] | SlateActionScopeClause;
|
|
448
|
+
type SlateActionScopesInput = SlateActionScopeClauseInput | SlateActionScopes;
|
|
449
|
+
declare let scopeClause: (...scopes: SlateActionScopeValue[]) => SlateActionScopeClause;
|
|
450
|
+
declare let anyOf: (...scopes: SlateActionScopeValue[]) => SlateActionScopes;
|
|
451
|
+
declare let allOf: (...inputs: SlateActionScopesInput[]) => SlateActionScopes;
|
|
452
|
+
declare let mergeScopes: (...inputs: Array<SlateActionScopes | null | undefined | false>) => SlateActionScopes | undefined;
|
|
453
|
+
declare let validateScopes: (scopes: SlateActionScopes) => SlateActionScopes;
|
|
454
|
+
|
|
455
|
+
declare class SlateActionBuilder<Type extends SlateActionType, ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}, Result extends SlateAction<Type, ConfigType, AuthType, any, any>> {
|
|
456
|
+
#private;
|
|
457
|
+
private readonly type;
|
|
458
|
+
readonly spec: SlateSpecification<ConfigType, AuthType>;
|
|
459
|
+
private readonly params;
|
|
460
|
+
private readonly factory;
|
|
461
|
+
constructor(type: Type, spec: SlateSpecification<ConfigType, AuthType>, params: SlateActionParameters, factory: (params: SlateActionCreateParameters<any, any, any, any>) => Result);
|
|
462
|
+
input<NewInputType extends {}>(schema: z.ZodType<NewInputType>): SlateActionBuilder<Type, ConfigType, AuthType, NewInputType, OutputType, Result>;
|
|
463
|
+
output<NewOutputType extends {}>(schema: z.ZodType<NewOutputType>): SlateActionBuilder<Type, ConfigType, AuthType, InputType, NewOutputType, Result>;
|
|
464
|
+
scopes(scopes: SlateActionScopes): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result>;
|
|
465
|
+
handleInvocation(handler: SlateToolInvocationHandler<ConfigType, AuthType, InputType, OutputType>): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result>;
|
|
466
|
+
webhook(props: {
|
|
467
|
+
handleEvent: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
468
|
+
handleRequest: SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType>;
|
|
469
|
+
autoRegisterWebhook?: SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType>;
|
|
470
|
+
autoUnregisterWebhook?: SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType>;
|
|
471
|
+
}): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result>;
|
|
472
|
+
polling(props: {
|
|
473
|
+
options?: SlatePollingOptions;
|
|
474
|
+
pollEvents?: SlateTriggerPollingHandler<ConfigType, AuthType, InputType>;
|
|
475
|
+
handleEvent: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
476
|
+
}): SlateActionBuilder<Type, ConfigType, AuthType, InputType, OutputType, Result>;
|
|
477
|
+
build(): Result;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
interface SlateToolParameters<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> extends SlateActionParameters {
|
|
481
|
+
handleInvocation: SlateToolInvocationHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
482
|
+
}
|
|
483
|
+
declare class SlateTool<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {}> extends SlateAction<'tool', ConfigType, AuthType, InputType, OutputType> {
|
|
484
|
+
#private;
|
|
485
|
+
private constructor();
|
|
486
|
+
static create<ConfigType extends {}, AuthType extends {}>(spec: SlateSpecification<ConfigType, AuthType>, params: SlateActionParameters): SlateActionBuilder<"tool", ConfigType, AuthType, {}, {}, SlateTool<any, any, any, any>>;
|
|
487
|
+
get handleInvocation(): SlateToolInvocationHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
488
|
+
}
|
|
489
|
+
declare let tool: <ConfigType extends {}, AuthType extends {}>(spec: SlateSpecification<ConfigType, AuthType>, params: SlateActionParameters) => SlateActionBuilder<"tool", ConfigType, AuthType, {}, {}, SlateTool<any, any, any, any>>;
|
|
490
|
+
|
|
491
|
+
declare let SlateDefaultPollingIntervalSeconds: number;
|
|
492
|
+
interface SlateTriggerParameters<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {
|
|
493
|
+
type: string;
|
|
494
|
+
}> extends SlateActionParameters {
|
|
495
|
+
type: 'trigger';
|
|
496
|
+
source: 'polling' | 'webhook';
|
|
497
|
+
polling?: SlatePollingOptions;
|
|
498
|
+
handleEvent: SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
499
|
+
handleRequest?: SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType>;
|
|
500
|
+
pollEvents?: SlateTriggerPollingHandler<ConfigType, AuthType, InputType>;
|
|
501
|
+
autoRegisterWebhook?: SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType>;
|
|
502
|
+
autoUnregisterWebhook?: SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType>;
|
|
503
|
+
}
|
|
504
|
+
declare class SlateTrigger<ConfigType extends {}, AuthType extends {}, InputType extends {}, OutputType extends {
|
|
505
|
+
type: string;
|
|
506
|
+
}> extends SlateAction<'trigger', ConfigType, AuthType, InputType, OutputType> {
|
|
507
|
+
#private;
|
|
508
|
+
private constructor();
|
|
509
|
+
static create<ConfigType extends {}, AuthType extends {}>(spec: SlateSpecification<ConfigType, AuthType>, params: SlateActionParameters): SlateActionBuilder<"trigger", ConfigType, AuthType, {}, {}, SlateTrigger<any, any, any, any>>;
|
|
510
|
+
get polling(): SlatePollingOptions;
|
|
511
|
+
get source(): "polling" | "webhook";
|
|
512
|
+
get handleEvent(): SlateTriggerMappingHandler<ConfigType, AuthType, InputType, OutputType>;
|
|
513
|
+
get handleRequest(): SlateTriggerWebhookRequestHandler<ConfigType, AuthType, InputType> | undefined;
|
|
514
|
+
get pollEvents(): SlateTriggerPollingHandler<ConfigType, AuthType, InputType> | undefined;
|
|
515
|
+
get autoRegisterWebhook(): SlateTriggerWebhookAutoRegistrationHandler<ConfigType, AuthType> | undefined;
|
|
516
|
+
get autoUnregisterWebhook(): SlateTriggerWebhookAutoUnregistrationHandler<ConfigType, AuthType> | undefined;
|
|
517
|
+
}
|
|
518
|
+
declare let trigger: <ConfigType extends {}, AuthType extends {}>(spec: SlateSpecification<ConfigType, AuthType>, params: SlateActionParameters) => SlateActionBuilder<"trigger", ConfigType, AuthType, {}, {}, SlateTrigger<any, any, any, any>>;
|
|
519
|
+
|
|
520
|
+
declare class SlateError extends Error {
|
|
521
|
+
cause?: unknown;
|
|
522
|
+
data: SlateErrorResponse;
|
|
523
|
+
constructor(input: SlateErrorInput);
|
|
524
|
+
get code(): string;
|
|
525
|
+
get kind(): SlateErrorKind;
|
|
526
|
+
get status(): number | undefined;
|
|
527
|
+
get retryable(): boolean | undefined;
|
|
528
|
+
toResponse(): SlateErrorResponse;
|
|
529
|
+
toJSON(): SlateErrorResponse;
|
|
530
|
+
static is(error: unknown): error is SlateError;
|
|
531
|
+
static fromUnknown(error: unknown, defaults?: Partial<SlateErrorResponse>): SlateError;
|
|
532
|
+
static fromServiceError(error: unknown, defaults?: Partial<SlateErrorInput>): SlateError;
|
|
533
|
+
static fromAxios(error: unknown, options?: SlateAxiosErrorOptions): SlateError;
|
|
534
|
+
}
|
|
535
|
+
declare let createSlateError: (input: SlateErrorInput) => SlateError;
|
|
536
|
+
|
|
537
|
+
type SlateErrorKind = 'declaration' | 'validation' | 'request' | 'auth' | 'config' | 'resource' | 'payment' | 'upstream' | 'transport' | 'internal';
|
|
538
|
+
interface SlateErrorIssue {
|
|
539
|
+
path?: string[];
|
|
540
|
+
code?: string;
|
|
541
|
+
message: string;
|
|
542
|
+
[key: string]: unknown;
|
|
543
|
+
}
|
|
544
|
+
interface SlateErrorProviderInfo {
|
|
545
|
+
key?: string;
|
|
546
|
+
service?: string;
|
|
547
|
+
operation?: string;
|
|
548
|
+
}
|
|
549
|
+
interface SlateErrorUpstreamInfo {
|
|
550
|
+
status?: number;
|
|
551
|
+
code?: string;
|
|
552
|
+
type?: string;
|
|
553
|
+
requestId?: string;
|
|
554
|
+
method?: string;
|
|
555
|
+
url?: string;
|
|
556
|
+
}
|
|
557
|
+
interface SlateErrorResponse {
|
|
558
|
+
code: string;
|
|
559
|
+
message: string;
|
|
560
|
+
kind: SlateErrorKind;
|
|
561
|
+
retryable?: boolean;
|
|
562
|
+
status?: number;
|
|
563
|
+
issues?: SlateErrorIssue[];
|
|
564
|
+
provider?: SlateErrorProviderInfo;
|
|
565
|
+
upstream?: SlateErrorUpstreamInfo;
|
|
566
|
+
baggage?: Record<string, unknown>;
|
|
567
|
+
}
|
|
568
|
+
interface SlateErrorInput extends Omit<SlateErrorResponse, 'kind'> {
|
|
569
|
+
kind?: SlateErrorKind;
|
|
570
|
+
cause?: unknown;
|
|
571
|
+
}
|
|
572
|
+
interface SlateAxiosErrorOptions {
|
|
573
|
+
defaults?: Partial<SlateErrorResponse>;
|
|
574
|
+
extractResponseData?: (response: AxiosResponse) => unknown;
|
|
575
|
+
mapAxiosError?: (error: AxiosError, inferred: SlateErrorResponse) => SlateError | Partial<SlateErrorResponse> | void;
|
|
576
|
+
}
|
|
577
|
+
interface SlateServiceErrorData {
|
|
578
|
+
status: number;
|
|
579
|
+
code: string;
|
|
580
|
+
message: string;
|
|
581
|
+
hint?: string;
|
|
582
|
+
description?: string;
|
|
583
|
+
reason?: string;
|
|
584
|
+
errors?: unknown;
|
|
585
|
+
[key: string]: unknown;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
declare let isAxiosErrorLike: (error: unknown) => error is AxiosError;
|
|
589
|
+
declare let inferSlateErrorFromAxios: (error: AxiosError, options?: SlateAxiosErrorOptions) => SlateErrorResponse;
|
|
590
|
+
|
|
591
|
+
declare class SlateDeclarationError extends SlateError {
|
|
592
|
+
constructor(message: string, input?: Partial<SlateError['data']>);
|
|
593
|
+
static is(error: unknown): error is SlateDeclarationError;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
declare let mapServiceErrorCode: (code: string, status?: number) => string;
|
|
597
|
+
declare let isServiceErrorData: (value: unknown) => value is SlateServiceErrorData;
|
|
598
|
+
declare let getServiceErrorData: (error: unknown) => SlateServiceErrorData | null;
|
|
599
|
+
declare let mapServiceErrorToSlateErrorInput: (error: ServiceError<ErrorRecord<any, any>> | ErrorRecord<any, any> | ErrorData<any, any> | SlateServiceErrorData, defaults?: Partial<SlateErrorInput>) => SlateErrorInput;
|
|
600
|
+
|
|
601
|
+
interface SlateAxiosDefaults extends CreateAxiosDefaults {
|
|
602
|
+
errorMapping?: SlateAxiosErrorOptions;
|
|
603
|
+
}
|
|
604
|
+
declare let createAxios: (config?: SlateAxiosDefaults) => AxiosInstance;
|
|
605
|
+
declare let axios: AxiosInstance;
|
|
606
|
+
|
|
607
|
+
declare class Slate<ConfigType extends {}, AuthType extends {}> {
|
|
608
|
+
private readonly _spec;
|
|
609
|
+
private readonly _actions;
|
|
610
|
+
private constructor();
|
|
611
|
+
static create<ConfigType extends {}, AuthType extends {}>(params: {
|
|
612
|
+
spec: SlateSpecification<ConfigType, AuthType>;
|
|
613
|
+
triggers: SlateTrigger<ConfigType, AuthType, any, any>[];
|
|
614
|
+
tools: SlateTool<ConfigType, AuthType, any, any>[];
|
|
615
|
+
}): Slate<ConfigType, AuthType>;
|
|
616
|
+
get spec(): SlateSpecification<ConfigType, AuthType>;
|
|
617
|
+
get actions(): (SlateTrigger<ConfigType, AuthType, any, any> | SlateTool<ConfigType, AuthType, any, any>)[];
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
export { Slate, SlateAction, SlateActionBuilder, type SlateActionCreateParameters, type SlateActionParameters, type SlateActionParametersAny, type SlateActionParametersTool, type SlateActionParametersTrigger, type SlateActionScopeClause, type SlateActionScopeClauseInput, type SlateActionScopeValue, type SlateActionScopes, type SlateActionScopesInput, type SlateActionType, type SlateAttachment, type SlateAttachmentInlineContent, type SlateAttachmentUrlContent, SlateAuth, type SlateAuthType, type SlateAuthWithCustomData, type SlateAuthWithNone, type SlateAuthWithOauth, type SlateAuthWithServiceAccount, type SlateAuthWithToken, type SlateAxiosDefaults, type SlateAxiosErrorOptions, SlateConfig, SlateContext, SlateDeclarationError, SlateDefaultPollingIntervalSeconds, SlateError, type SlateErrorInput, type SlateErrorIssue, type SlateErrorKind, type SlateErrorProviderInfo, type SlateErrorResponse, type SlateErrorUpstreamInfo, type SlateLogEntry, type SlateLogFields, type SlateLogListener, type SlateLogMessageInput, type SlateLogType, SlateLogger, type SlatePollingOptions, type SlateServiceErrorData, SlateSpecification, type SlateSpecificationCreateParameters, type SlateSpecificationParameters, SlateTool, type SlateToolInvocationHandler, type SlateToolParameters, SlateTrigger, type SlateTriggerMappingHandler, type SlateTriggerParameters, type SlateTriggerPollingHandler, type SlateTriggerWebhookAutoRegistrationHandler, type SlateTriggerWebhookAutoUnregistrationHandler, type SlateTriggerWebhookRequestHandler, allOf, anyOf, auth, axios, config, createAxios, createBase64Attachment, createSlateError, createTextAttachment, createUrlAttachment, getCurrentContext, getServiceErrorData, inferSlateErrorFromAxios, isAxiosErrorLike, isServiceErrorData, mapServiceErrorCode, mapServiceErrorToSlateErrorInput, mergeScopes, runWithContext, scopeClause, spec, tool, trigger, validateScopes };
|