@slates/provider 1.0.0-rc.1 → 1.0.0-rc.10
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 +1881 -0
- package/dist/index.d.cts +622 -0
- package/dist/index.d.ts +622 -0
- package/dist/index.module.js +1809 -0
- package/package.json +13 -5
- 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 +10 -6
- package/src/axios/index.ts +56 -9
- package/src/axios/trace.test.ts +378 -0
- package/src/axios/trace.ts +776 -0
- package/src/config/config.ts +3 -3
- package/src/context/context.ts +29 -2
- package/src/context/hook.ts +9 -4
- package/src/context/index.ts +1 -0
- package/src/error/axios.ts +220 -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 +75 -0
- package/src/error/utils.ts +157 -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/tsconfig.json +0 -8
|
@@ -0,0 +1,1809 @@
|
|
|
1
|
+
// src/action/action.ts
|
|
2
|
+
var SlateAction = class {
|
|
3
|
+
constructor(type, _spec, _inputSchema, _outputSchema, _params) {
|
|
4
|
+
this.type = type;
|
|
5
|
+
this._spec = _spec;
|
|
6
|
+
this._inputSchema = _inputSchema;
|
|
7
|
+
this._outputSchema = _outputSchema;
|
|
8
|
+
this._params = _params;
|
|
9
|
+
}
|
|
10
|
+
type;
|
|
11
|
+
_spec;
|
|
12
|
+
_inputSchema;
|
|
13
|
+
_outputSchema;
|
|
14
|
+
_params;
|
|
15
|
+
get configSchema() {
|
|
16
|
+
return this._spec.configSchema;
|
|
17
|
+
}
|
|
18
|
+
get inputSchema() {
|
|
19
|
+
return this._inputSchema;
|
|
20
|
+
}
|
|
21
|
+
get outputSchema() {
|
|
22
|
+
return this._outputSchema;
|
|
23
|
+
}
|
|
24
|
+
get parameters() {
|
|
25
|
+
return this._params;
|
|
26
|
+
}
|
|
27
|
+
get key() {
|
|
28
|
+
return this._params.key;
|
|
29
|
+
}
|
|
30
|
+
get name() {
|
|
31
|
+
return this._params.name;
|
|
32
|
+
}
|
|
33
|
+
get description() {
|
|
34
|
+
return this._params.description;
|
|
35
|
+
}
|
|
36
|
+
get tags() {
|
|
37
|
+
return this._params.tags;
|
|
38
|
+
}
|
|
39
|
+
get instructions() {
|
|
40
|
+
return this._params.instructions;
|
|
41
|
+
}
|
|
42
|
+
get constraints() {
|
|
43
|
+
return this._params.constraints;
|
|
44
|
+
}
|
|
45
|
+
get metadata() {
|
|
46
|
+
return this._params.metadata;
|
|
47
|
+
}
|
|
48
|
+
get scopes() {
|
|
49
|
+
return this._params.scopes;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/error/axios.ts
|
|
54
|
+
import { isAxiosError } from "axios";
|
|
55
|
+
|
|
56
|
+
// src/context/hook.ts
|
|
57
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
58
|
+
var asyncLocalStorage = new AsyncLocalStorage();
|
|
59
|
+
var runWithContext = (context, fn) => {
|
|
60
|
+
return asyncLocalStorage.run(context, fn);
|
|
61
|
+
};
|
|
62
|
+
var getCurrentContext = () => {
|
|
63
|
+
let context = asyncLocalStorage.getStore();
|
|
64
|
+
if (!context) {
|
|
65
|
+
throw new Error("No Slate context is available");
|
|
66
|
+
}
|
|
67
|
+
return context;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/error/defaults.ts
|
|
71
|
+
var DEFAULT_CODE = "internal.unexpected";
|
|
72
|
+
var DEFAULT_MESSAGES = {
|
|
73
|
+
"declaration.invalid_definition": "The slate definition is invalid.",
|
|
74
|
+
"context.missing": "No Slate context is available.",
|
|
75
|
+
"input.invalid": "The provided input is invalid.",
|
|
76
|
+
"request.bad": "The request is invalid.",
|
|
77
|
+
"request.invalid_version": "The requested version is invalid.",
|
|
78
|
+
"request.precondition_failed": "The request precondition failed.",
|
|
79
|
+
"request.not_acceptable": "The request is not acceptable.",
|
|
80
|
+
"request.rate_limited": "Too many requests were made in a short period of time.",
|
|
81
|
+
"config.invalid": "The provided configuration is invalid.",
|
|
82
|
+
"auth.required": "Authentication is required.",
|
|
83
|
+
"auth.invalid": "Authentication failed.",
|
|
84
|
+
"auth.expired": "Authentication has expired.",
|
|
85
|
+
"permission.denied": "Permission was denied.",
|
|
86
|
+
"resource.not_found": "The requested resource was not found.",
|
|
87
|
+
"resource.conflict": "The requested resource is in conflict.",
|
|
88
|
+
"resource.gone": "The requested resource is no longer available.",
|
|
89
|
+
"payment.required": "Payment is required to continue.",
|
|
90
|
+
"operation.not_implemented": "The requested operation is not implemented.",
|
|
91
|
+
"upstream.invalid_request": "The upstream service rejected the request.",
|
|
92
|
+
"upstream.rate_limited": "The upstream service rate limited the request.",
|
|
93
|
+
"upstream.timeout": "The upstream service timed out.",
|
|
94
|
+
"upstream.network_error": "A network error occurred while contacting the upstream service.",
|
|
95
|
+
"upstream.unavailable": "The upstream service is unavailable.",
|
|
96
|
+
"upstream.invalid_response": "The upstream service returned an invalid response.",
|
|
97
|
+
"upstream.error": "The upstream service returned an error.",
|
|
98
|
+
"transport.invoke_failed": "The provider transport failed.",
|
|
99
|
+
"internal.timeout": "The operation timed out.",
|
|
100
|
+
"internal.unexpected": "An unexpected internal error occurred."
|
|
101
|
+
};
|
|
102
|
+
var SERVICE_ERROR_CODE_MAP = {
|
|
103
|
+
invalid_data: "input.invalid",
|
|
104
|
+
bad_request: "request.bad",
|
|
105
|
+
not_found: "resource.not_found",
|
|
106
|
+
unauthorized: "auth.required",
|
|
107
|
+
forbidden: "permission.denied",
|
|
108
|
+
invalid_version: "request.invalid_version",
|
|
109
|
+
conflict: "resource.conflict",
|
|
110
|
+
gone: "resource.gone",
|
|
111
|
+
payment_required: "payment.required",
|
|
112
|
+
precondition_failed: "request.precondition_failed",
|
|
113
|
+
not_acceptable: "request.not_acceptable",
|
|
114
|
+
not_implemented: "operation.not_implemented",
|
|
115
|
+
too_many_requests: "request.rate_limited",
|
|
116
|
+
timeout: "internal.timeout",
|
|
117
|
+
internal_server_error: "internal.unexpected"
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/error/utils.ts
|
|
121
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
122
|
+
var normalizeKind = (code, kind) => {
|
|
123
|
+
if (kind) return kind;
|
|
124
|
+
if (code.startsWith("declaration.")) return "declaration";
|
|
125
|
+
if (code.startsWith("input.")) return "validation";
|
|
126
|
+
if (code.startsWith("request.")) return "request";
|
|
127
|
+
if (code.startsWith("config.")) return "config";
|
|
128
|
+
if (code.startsWith("auth.") || code.startsWith("permission.")) return "auth";
|
|
129
|
+
if (code.startsWith("resource.")) return "resource";
|
|
130
|
+
if (code.startsWith("payment.")) return "payment";
|
|
131
|
+
if (code.startsWith("transport.")) return "transport";
|
|
132
|
+
if (code.startsWith("upstream.")) return "upstream";
|
|
133
|
+
return "internal";
|
|
134
|
+
};
|
|
135
|
+
var normalizeStatus = (code, status) => {
|
|
136
|
+
if (status) return status;
|
|
137
|
+
if (code === "input.invalid" || code === "request.bad" || code === "config.invalid")
|
|
138
|
+
return 400;
|
|
139
|
+
if (code === "request.invalid_version") return 400;
|
|
140
|
+
if (code === "auth.required" || code === "auth.invalid" || code === "auth.expired")
|
|
141
|
+
return 401;
|
|
142
|
+
if (code === "payment.required") return 402;
|
|
143
|
+
if (code === "permission.denied") return 403;
|
|
144
|
+
if (code === "resource.not_found") return 404;
|
|
145
|
+
if (code === "resource.conflict") return 409;
|
|
146
|
+
if (code === "resource.gone") return 410;
|
|
147
|
+
if (code === "request.not_acceptable") return 406;
|
|
148
|
+
if (code === "request.precondition_failed") return 412;
|
|
149
|
+
if (code === "request.rate_limited" || code === "upstream.rate_limited") return 429;
|
|
150
|
+
if (code === "operation.not_implemented") return 501;
|
|
151
|
+
if (code === "upstream.invalid_request") return 400;
|
|
152
|
+
if (code === "upstream.timeout" || code === "internal.timeout") return 504;
|
|
153
|
+
if (code === "upstream.unavailable") return 503;
|
|
154
|
+
if (code === "upstream.error") return 502;
|
|
155
|
+
return void 0;
|
|
156
|
+
};
|
|
157
|
+
var normalizeRetryable = (code, retryable) => {
|
|
158
|
+
if (typeof retryable === "boolean") return retryable;
|
|
159
|
+
return code === "request.rate_limited" || code === "upstream.rate_limited" || code === "upstream.timeout" || code === "upstream.network_error" || code === "upstream.unavailable" || code === "upstream.error" || code === "transport.invoke_failed" || code === "internal.timeout";
|
|
160
|
+
};
|
|
161
|
+
var getDefaultMessage = (code, message) => {
|
|
162
|
+
if (message && message.trim()) return message;
|
|
163
|
+
return DEFAULT_MESSAGES[code] ?? DEFAULT_MESSAGES[DEFAULT_CODE];
|
|
164
|
+
};
|
|
165
|
+
var cleanRecord = (value) => {
|
|
166
|
+
if (!value) return void 0;
|
|
167
|
+
let entries = Object.entries(value).filter(([, entry]) => entry !== void 0);
|
|
168
|
+
if (entries.length === 0) return void 0;
|
|
169
|
+
return Object.fromEntries(entries);
|
|
170
|
+
};
|
|
171
|
+
var mergeRecords = (left, right) => {
|
|
172
|
+
if (!left && !right) return void 0;
|
|
173
|
+
return cleanRecord({
|
|
174
|
+
...left ?? {},
|
|
175
|
+
...right ?? {}
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
var mergeSlateErrorData = (base, override) => {
|
|
179
|
+
if (!override) return base;
|
|
180
|
+
return {
|
|
181
|
+
...base,
|
|
182
|
+
...override,
|
|
183
|
+
provider: cleanRecord({
|
|
184
|
+
...base.provider ?? {},
|
|
185
|
+
...override.provider ?? {}
|
|
186
|
+
}),
|
|
187
|
+
upstream: cleanRecord({
|
|
188
|
+
...base.upstream ?? {},
|
|
189
|
+
...override.upstream ?? {}
|
|
190
|
+
}),
|
|
191
|
+
baggage: mergeRecords(base.baggage, override.baggage),
|
|
192
|
+
issues: override.issues ?? base.issues,
|
|
193
|
+
requestTraces: override.requestTraces ?? base.requestTraces
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
var sanitizeForBaggage = (value, depth = 0) => {
|
|
197
|
+
if (value == null) return value;
|
|
198
|
+
if (depth >= 4) return "[truncated]";
|
|
199
|
+
if (typeof value === "string") {
|
|
200
|
+
return value.length > 2e3 ? `${value.slice(0, 2e3)}...[truncated]` : value;
|
|
201
|
+
}
|
|
202
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
203
|
+
return value;
|
|
204
|
+
}
|
|
205
|
+
if (Array.isArray(value)) {
|
|
206
|
+
return value.slice(0, 20).map((item) => sanitizeForBaggage(item, depth + 1));
|
|
207
|
+
}
|
|
208
|
+
if (isRecord(value)) {
|
|
209
|
+
return Object.fromEntries(
|
|
210
|
+
Object.entries(value).slice(0, 30).map(([key, entry]) => [key, sanitizeForBaggage(entry, depth + 1)])
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
return String(value);
|
|
214
|
+
};
|
|
215
|
+
var normalizeSlateErrorInput = (input) => {
|
|
216
|
+
let code = input.code || DEFAULT_CODE;
|
|
217
|
+
return {
|
|
218
|
+
code,
|
|
219
|
+
message: getDefaultMessage(code, input.message),
|
|
220
|
+
kind: normalizeKind(code, input.kind),
|
|
221
|
+
retryable: normalizeRetryable(code, input.retryable),
|
|
222
|
+
status: normalizeStatus(code, input.status ?? input.upstream?.status),
|
|
223
|
+
issues: input.issues,
|
|
224
|
+
provider: cleanRecord(input.provider),
|
|
225
|
+
upstream: cleanRecord({
|
|
226
|
+
...input.upstream,
|
|
227
|
+
status: input.upstream?.status ?? input.status
|
|
228
|
+
}),
|
|
229
|
+
baggage: cleanRecord(input.baggage),
|
|
230
|
+
requestTraces: input.requestTraces
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
var isSlateErrorResponse = (error) => {
|
|
234
|
+
if (!isRecord(error)) return false;
|
|
235
|
+
return typeof error.code === "string" && typeof error.message === "string";
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// src/error/axios.ts
|
|
239
|
+
var getResponseField = (value, key) => {
|
|
240
|
+
if (!isRecord(value)) return void 0;
|
|
241
|
+
return value[key];
|
|
242
|
+
};
|
|
243
|
+
var getNestedMessage = (value) => {
|
|
244
|
+
if (typeof value === "string") return value;
|
|
245
|
+
if (!isRecord(value)) return void 0;
|
|
246
|
+
let message = getResponseField(value, "message");
|
|
247
|
+
if (typeof message === "string" && message.trim()) return message;
|
|
248
|
+
let description = getResponseField(value, "description");
|
|
249
|
+
if (typeof description === "string" && description.trim()) return description;
|
|
250
|
+
let error = getResponseField(value, "error");
|
|
251
|
+
if (typeof error === "string" && error.trim()) return error;
|
|
252
|
+
if (isRecord(error)) {
|
|
253
|
+
let nested = getNestedMessage(error);
|
|
254
|
+
if (nested) return nested;
|
|
255
|
+
}
|
|
256
|
+
let errorDescription = getResponseField(value, "error_description");
|
|
257
|
+
if (typeof errorDescription === "string" && errorDescription.trim()) {
|
|
258
|
+
return errorDescription;
|
|
259
|
+
}
|
|
260
|
+
return void 0;
|
|
261
|
+
};
|
|
262
|
+
var getNestedCode = (value) => {
|
|
263
|
+
if (!isRecord(value)) return void 0;
|
|
264
|
+
let directCode = getResponseField(value, "code");
|
|
265
|
+
if (typeof directCode === "string" && directCode.trim()) return directCode;
|
|
266
|
+
let errorCode = getResponseField(value, "error_code");
|
|
267
|
+
if (typeof errorCode === "string" && errorCode.trim()) return errorCode;
|
|
268
|
+
let type = getResponseField(value, "type");
|
|
269
|
+
if (typeof type === "string" && type.trim()) return type;
|
|
270
|
+
let error = getResponseField(value, "error");
|
|
271
|
+
if (typeof error === "string" && error.trim()) return error;
|
|
272
|
+
if (isRecord(error)) return getNestedCode(error);
|
|
273
|
+
return void 0;
|
|
274
|
+
};
|
|
275
|
+
var getNestedType = (value) => {
|
|
276
|
+
if (!isRecord(value)) return void 0;
|
|
277
|
+
let type = getResponseField(value, "type");
|
|
278
|
+
if (typeof type === "string" && type.trim()) return type;
|
|
279
|
+
let error = getResponseField(value, "error");
|
|
280
|
+
if (isRecord(error)) {
|
|
281
|
+
let nestedType = getNestedType(error);
|
|
282
|
+
if (nestedType) return nestedType;
|
|
283
|
+
}
|
|
284
|
+
return void 0;
|
|
285
|
+
};
|
|
286
|
+
var getHeaderValue = (headers, key) => {
|
|
287
|
+
if (!headers) return void 0;
|
|
288
|
+
if (typeof headers.get === "function") {
|
|
289
|
+
let value = headers.get(key);
|
|
290
|
+
if (typeof value === "string" && value.trim()) return value;
|
|
291
|
+
}
|
|
292
|
+
if (isRecord(headers)) {
|
|
293
|
+
for (let [headerKey, headerValue] of Object.entries(headers)) {
|
|
294
|
+
if (headerKey.toLowerCase() !== key.toLowerCase()) continue;
|
|
295
|
+
if (typeof headerValue === "string" && headerValue.trim()) return headerValue;
|
|
296
|
+
if (Array.isArray(headerValue)) {
|
|
297
|
+
let first = headerValue.find((item) => typeof item === "string" && item.trim());
|
|
298
|
+
if (typeof first === "string") return first;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return void 0;
|
|
303
|
+
};
|
|
304
|
+
var buildRequestUrl = (error) => {
|
|
305
|
+
let baseURL = error.config?.baseURL;
|
|
306
|
+
let url = error.config?.url;
|
|
307
|
+
if (!url) return void 0;
|
|
308
|
+
if (!baseURL) return url;
|
|
309
|
+
try {
|
|
310
|
+
return new URL(url, baseURL).toString();
|
|
311
|
+
} catch {
|
|
312
|
+
return url;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
var getProviderDefaults = () => {
|
|
316
|
+
try {
|
|
317
|
+
let ctx = getCurrentContext();
|
|
318
|
+
return {
|
|
319
|
+
provider: {
|
|
320
|
+
key: ctx.specification.key
|
|
321
|
+
},
|
|
322
|
+
...ctx.getHttpTraces().length > 0 ? { requestTraces: ctx.getHttpTraces() } : {}
|
|
323
|
+
};
|
|
324
|
+
} catch {
|
|
325
|
+
return {};
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
var inferAxiosCode = (error, data) => {
|
|
329
|
+
let status = error.response?.status;
|
|
330
|
+
let axiosCode = error.code?.toUpperCase();
|
|
331
|
+
let remoteCode = getNestedCode(data)?.toLowerCase();
|
|
332
|
+
if (axiosCode === "ECONNABORTED" || axiosCode === "ETIMEDOUT" || status === 408 || remoteCode?.includes("timeout")) {
|
|
333
|
+
return "upstream.timeout";
|
|
334
|
+
}
|
|
335
|
+
if (!error.response) {
|
|
336
|
+
return "upstream.network_error";
|
|
337
|
+
}
|
|
338
|
+
if (status === 401) return "auth.invalid";
|
|
339
|
+
if (status === 403) {
|
|
340
|
+
return remoteCode?.includes("rate") ? "upstream.rate_limited" : "permission.denied";
|
|
341
|
+
}
|
|
342
|
+
if (status === 404) return "resource.not_found";
|
|
343
|
+
if (status === 409) return "resource.conflict";
|
|
344
|
+
if (status === 422 || status === 400) return "upstream.invalid_request";
|
|
345
|
+
if (status === 429) return "upstream.rate_limited";
|
|
346
|
+
if (status === 502 || status === 503 || status === 504) return "upstream.unavailable";
|
|
347
|
+
if (status && status >= 500) return "upstream.error";
|
|
348
|
+
return "upstream.error";
|
|
349
|
+
};
|
|
350
|
+
var inferAxiosMessage = (error, data, code) => {
|
|
351
|
+
return getNestedMessage(data) ?? error.response?.statusText ?? error.message ?? getDefaultMessage(code);
|
|
352
|
+
};
|
|
353
|
+
var inferAxiosRetryable = (error, code) => {
|
|
354
|
+
let headerValue = getHeaderValue(error.response?.headers, "retry-after");
|
|
355
|
+
if (headerValue) return true;
|
|
356
|
+
return normalizeRetryable(code, void 0);
|
|
357
|
+
};
|
|
358
|
+
var isAxiosErrorLike = (error) => isAxiosError(error);
|
|
359
|
+
var inferSlateErrorFromAxios = (error, options = {}) => {
|
|
360
|
+
let responseData = error.response ? options.extractResponseData?.(error.response) ?? error.response.data : void 0;
|
|
361
|
+
let code = inferAxiosCode(error, responseData);
|
|
362
|
+
return normalizeSlateErrorInput({
|
|
363
|
+
...getProviderDefaults(),
|
|
364
|
+
...options.defaults,
|
|
365
|
+
code: options.defaults?.code ?? code,
|
|
366
|
+
message: options.defaults?.message ?? inferAxiosMessage(error, responseData, code),
|
|
367
|
+
kind: options.defaults?.kind ?? normalizeKind(options.defaults?.code ?? code),
|
|
368
|
+
retryable: options.defaults?.retryable ?? inferAxiosRetryable(error, options.defaults?.code ?? code),
|
|
369
|
+
status: options.defaults?.status ?? error.response?.status,
|
|
370
|
+
provider: {
|
|
371
|
+
...getProviderDefaults().provider,
|
|
372
|
+
...options.defaults?.provider ?? {}
|
|
373
|
+
},
|
|
374
|
+
upstream: {
|
|
375
|
+
...options.defaults?.upstream ?? {},
|
|
376
|
+
status: error.response?.status ?? options.defaults?.upstream?.status,
|
|
377
|
+
code: getNestedCode(responseData) ?? options.defaults?.upstream?.code,
|
|
378
|
+
type: getNestedType(responseData) ?? options.defaults?.upstream?.type,
|
|
379
|
+
requestId: getHeaderValue(error.response?.headers, "x-request-id") ?? getHeaderValue(error.response?.headers, "request-id") ?? getHeaderValue(error.response?.headers, "x-correlation-id") ?? options.defaults?.upstream?.requestId,
|
|
380
|
+
method: error.config?.method?.toUpperCase() ?? options.defaults?.upstream?.method,
|
|
381
|
+
url: buildRequestUrl(error) ?? options.defaults?.upstream?.url
|
|
382
|
+
},
|
|
383
|
+
baggage: mergeRecords(options.defaults?.baggage, {
|
|
384
|
+
axiosCode: error.code,
|
|
385
|
+
response: sanitizeForBaggage(responseData)
|
|
386
|
+
})
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// src/error/service.ts
|
|
391
|
+
import { isServiceError } from "@lowerdeck/error";
|
|
392
|
+
var SERVICE_ERROR_DATA_RESERVED_KEYS = /* @__PURE__ */ new Set([
|
|
393
|
+
"status",
|
|
394
|
+
"code",
|
|
395
|
+
"message",
|
|
396
|
+
"hint",
|
|
397
|
+
"description",
|
|
398
|
+
"reason",
|
|
399
|
+
"errors",
|
|
400
|
+
"object",
|
|
401
|
+
"ok"
|
|
402
|
+
]);
|
|
403
|
+
var isStructuredValue = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
|
|
404
|
+
var mapServiceErrorCodeByStatus = (status) => {
|
|
405
|
+
if (status === 400) return "request.bad";
|
|
406
|
+
if (status === 401) return "auth.required";
|
|
407
|
+
if (status === 402) return "payment.required";
|
|
408
|
+
if (status === 403) return "permission.denied";
|
|
409
|
+
if (status === 404) return "resource.not_found";
|
|
410
|
+
if (status === 406) return "request.not_acceptable";
|
|
411
|
+
if (status === 409) return "resource.conflict";
|
|
412
|
+
if (status === 410) return "resource.gone";
|
|
413
|
+
if (status === 412) return "request.precondition_failed";
|
|
414
|
+
if (status === 429) return "request.rate_limited";
|
|
415
|
+
if (status === 501) return "operation.not_implemented";
|
|
416
|
+
if (status === 504) return "internal.timeout";
|
|
417
|
+
if (status && status >= 500) return "internal.unexpected";
|
|
418
|
+
return DEFAULT_CODE;
|
|
419
|
+
};
|
|
420
|
+
var normalizeServiceErrorIssues = (errors) => {
|
|
421
|
+
if (!Array.isArray(errors)) return void 0;
|
|
422
|
+
let issues = errors.map((error) => {
|
|
423
|
+
if (!isRecord(error)) {
|
|
424
|
+
return {
|
|
425
|
+
message: String(error)
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
let path = Array.isArray(error.path) ? error.path.map((entry) => String(entry)) : void 0;
|
|
429
|
+
return {
|
|
430
|
+
...error,
|
|
431
|
+
path,
|
|
432
|
+
code: typeof error.code === "string" ? error.code : void 0,
|
|
433
|
+
message: typeof error.message === "string" ? error.message : typeof error.hint === "string" ? error.hint : "Validation issue"
|
|
434
|
+
};
|
|
435
|
+
});
|
|
436
|
+
return issues.length > 0 ? issues : void 0;
|
|
437
|
+
};
|
|
438
|
+
var getServiceErrorBaggage = (data) => {
|
|
439
|
+
let extraEntries = Object.entries(data).filter(([key]) => !SERVICE_ERROR_DATA_RESERVED_KEYS.has(key));
|
|
440
|
+
return cleanRecord({
|
|
441
|
+
serviceError: {
|
|
442
|
+
code: data.code,
|
|
443
|
+
status: data.status,
|
|
444
|
+
hint: data.hint,
|
|
445
|
+
description: data.description,
|
|
446
|
+
reason: data.reason
|
|
447
|
+
},
|
|
448
|
+
...extraEntries.length > 0 ? {
|
|
449
|
+
serviceErrorData: sanitizeForBaggage(Object.fromEntries(extraEntries))
|
|
450
|
+
} : {}
|
|
451
|
+
});
|
|
452
|
+
};
|
|
453
|
+
var mapServiceErrorCode = (code, status) => SERVICE_ERROR_CODE_MAP[code] ?? mapServiceErrorCodeByStatus(status);
|
|
454
|
+
var isServiceErrorData = (value) => isRecord(value) && typeof value.status === "number" && typeof value.code === "string" && typeof value.message === "string" && !("config" in value) && !("request" in value) && !("response" in value) && !("isAxiosError" in value);
|
|
455
|
+
var getServiceErrorData = (error) => {
|
|
456
|
+
if (isServiceError(error)) {
|
|
457
|
+
return isServiceErrorData(error.data) ? error.data : null;
|
|
458
|
+
}
|
|
459
|
+
if (isServiceErrorData(error)) {
|
|
460
|
+
return error;
|
|
461
|
+
}
|
|
462
|
+
if (isStructuredValue(error) && "data" in error && isServiceErrorData(error.data)) {
|
|
463
|
+
return error.data;
|
|
464
|
+
}
|
|
465
|
+
if (isStructuredValue(error) && "toResponse" in error && typeof error.toResponse === "function") {
|
|
466
|
+
let response = error.toResponse();
|
|
467
|
+
return isServiceErrorData(response) ? response : null;
|
|
468
|
+
}
|
|
469
|
+
return null;
|
|
470
|
+
};
|
|
471
|
+
var mapServiceErrorToSlateErrorInput = (error, defaults = {}) => {
|
|
472
|
+
let data = getServiceErrorData(error);
|
|
473
|
+
if (!data) {
|
|
474
|
+
return {
|
|
475
|
+
code: defaults.code ?? DEFAULT_CODE,
|
|
476
|
+
message: defaults.message ?? "An unexpected internal error occurred.",
|
|
477
|
+
kind: defaults.kind,
|
|
478
|
+
retryable: defaults.retryable,
|
|
479
|
+
status: defaults.status,
|
|
480
|
+
provider: defaults.provider,
|
|
481
|
+
upstream: defaults.upstream,
|
|
482
|
+
baggage: defaults.baggage
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
let code = defaults.code ?? mapServiceErrorCode(data.code, data.status);
|
|
486
|
+
return {
|
|
487
|
+
code,
|
|
488
|
+
message: defaults.message ?? data.message,
|
|
489
|
+
kind: defaults.kind ?? normalizeKind(code),
|
|
490
|
+
retryable: defaults.retryable ?? normalizeRetryable(code),
|
|
491
|
+
status: defaults.status ?? data.status,
|
|
492
|
+
issues: defaults.issues ?? normalizeServiceErrorIssues(data.errors),
|
|
493
|
+
provider: defaults.provider,
|
|
494
|
+
upstream: defaults.upstream,
|
|
495
|
+
baggage: cleanRecord({
|
|
496
|
+
...defaults.baggage ?? {},
|
|
497
|
+
...getServiceErrorBaggage(data)
|
|
498
|
+
})
|
|
499
|
+
};
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// src/error/base.ts
|
|
503
|
+
var SlateError = class _SlateError extends Error {
|
|
504
|
+
cause;
|
|
505
|
+
data;
|
|
506
|
+
constructor(input) {
|
|
507
|
+
let normalized = normalizeSlateErrorInput(input);
|
|
508
|
+
super(normalized.message);
|
|
509
|
+
this.name = "SlateError";
|
|
510
|
+
this.data = normalized;
|
|
511
|
+
this.cause = input.cause;
|
|
512
|
+
}
|
|
513
|
+
get code() {
|
|
514
|
+
return this.data.code;
|
|
515
|
+
}
|
|
516
|
+
get kind() {
|
|
517
|
+
return this.data.kind;
|
|
518
|
+
}
|
|
519
|
+
get status() {
|
|
520
|
+
return this.data.status;
|
|
521
|
+
}
|
|
522
|
+
get retryable() {
|
|
523
|
+
return this.data.retryable;
|
|
524
|
+
}
|
|
525
|
+
toResponse() {
|
|
526
|
+
return {
|
|
527
|
+
...this.data
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
toJSON() {
|
|
531
|
+
return this.toResponse();
|
|
532
|
+
}
|
|
533
|
+
static is(error) {
|
|
534
|
+
return error instanceof _SlateError;
|
|
535
|
+
}
|
|
536
|
+
static fromUnknown(error, defaults = {}) {
|
|
537
|
+
if (_SlateError.is(error)) return error;
|
|
538
|
+
if (isSlateErrorResponse(error)) return new _SlateError({ ...defaults, ...error });
|
|
539
|
+
if (getServiceErrorData(error)) return _SlateError.fromServiceError(error, defaults);
|
|
540
|
+
if (isAxiosErrorLike(error)) return _SlateError.fromAxios(error, { defaults });
|
|
541
|
+
if (error instanceof Error) {
|
|
542
|
+
return new _SlateError({
|
|
543
|
+
code: defaults.code ?? DEFAULT_CODE,
|
|
544
|
+
message: error.message,
|
|
545
|
+
kind: defaults.kind,
|
|
546
|
+
retryable: defaults.retryable,
|
|
547
|
+
status: defaults.status,
|
|
548
|
+
issues: defaults.issues,
|
|
549
|
+
provider: defaults.provider,
|
|
550
|
+
upstream: defaults.upstream,
|
|
551
|
+
baggage: mergeRecords(defaults.baggage, {
|
|
552
|
+
originalName: error.name
|
|
553
|
+
}),
|
|
554
|
+
cause: error
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
return new _SlateError({
|
|
558
|
+
code: defaults.code ?? DEFAULT_CODE,
|
|
559
|
+
message: getDefaultMessage(defaults.code ?? DEFAULT_CODE, defaults.message),
|
|
560
|
+
kind: defaults.kind,
|
|
561
|
+
retryable: defaults.retryable,
|
|
562
|
+
status: defaults.status,
|
|
563
|
+
issues: defaults.issues,
|
|
564
|
+
provider: defaults.provider,
|
|
565
|
+
upstream: defaults.upstream,
|
|
566
|
+
baggage: mergeRecords(defaults.baggage, {
|
|
567
|
+
originalValue: sanitizeForBaggage(error)
|
|
568
|
+
})
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
static fromServiceError(error, defaults = {}) {
|
|
572
|
+
return new _SlateError(mapServiceErrorToSlateErrorInput(error, defaults));
|
|
573
|
+
}
|
|
574
|
+
static fromAxios(error, options = {}) {
|
|
575
|
+
if (_SlateError.is(error)) return error;
|
|
576
|
+
if (getServiceErrorData(error))
|
|
577
|
+
return _SlateError.fromServiceError(error, options.defaults);
|
|
578
|
+
if (!isAxiosErrorLike(error)) return _SlateError.fromUnknown(error, options.defaults);
|
|
579
|
+
let inferred = inferSlateErrorFromAxios(error, options);
|
|
580
|
+
let mapped = options.mapAxiosError?.(error, inferred);
|
|
581
|
+
if (_SlateError.is(mapped)) return mapped;
|
|
582
|
+
return new _SlateError(mergeSlateErrorData(inferred, mapped ?? void 0));
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
var createSlateError = (input) => new SlateError(input);
|
|
586
|
+
|
|
587
|
+
// src/error/declaration.ts
|
|
588
|
+
var SlateDeclarationError = class _SlateDeclarationError extends SlateError {
|
|
589
|
+
constructor(message, input = {}) {
|
|
590
|
+
super({
|
|
591
|
+
code: "declaration.invalid_definition",
|
|
592
|
+
kind: "declaration",
|
|
593
|
+
message,
|
|
594
|
+
...input
|
|
595
|
+
});
|
|
596
|
+
this.name = "SlateError.DeclarationError";
|
|
597
|
+
}
|
|
598
|
+
static is(error) {
|
|
599
|
+
return error instanceof _SlateDeclarationError;
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
// src/action/scopes.ts
|
|
604
|
+
var scopeClause = (...scopes) => {
|
|
605
|
+
assertScopeValues(scopes);
|
|
606
|
+
return {
|
|
607
|
+
OR: [...scopes]
|
|
608
|
+
};
|
|
609
|
+
};
|
|
610
|
+
var anyOf = (...scopes) => ({
|
|
611
|
+
AND: [scopeClause(...scopes)]
|
|
612
|
+
});
|
|
613
|
+
var allOf = (...inputs) => {
|
|
614
|
+
let AND = inputs.flatMap((input) => normalizeScopes(input).AND);
|
|
615
|
+
return validateScopes({ AND });
|
|
616
|
+
};
|
|
617
|
+
var mergeScopes = (...inputs) => {
|
|
618
|
+
let AND = inputs.flatMap((input) => input ? input.AND : []);
|
|
619
|
+
if (AND.length === 0) {
|
|
620
|
+
return void 0;
|
|
621
|
+
}
|
|
622
|
+
return validateScopes({ AND });
|
|
623
|
+
};
|
|
624
|
+
var validateScopes = (scopes) => {
|
|
625
|
+
if (!Array.isArray(scopes.AND) || scopes.AND.length === 0) {
|
|
626
|
+
throw new SlateDeclarationError("Action scopes must include at least one AND clause");
|
|
627
|
+
}
|
|
628
|
+
return {
|
|
629
|
+
AND: scopes.AND.map((clause) => normalizeClause(clause))
|
|
630
|
+
};
|
|
631
|
+
};
|
|
632
|
+
var normalizeScopes = (input) => {
|
|
633
|
+
if (isScopes(input)) {
|
|
634
|
+
return validateScopes(input);
|
|
635
|
+
}
|
|
636
|
+
return {
|
|
637
|
+
AND: [normalizeClause(input)]
|
|
638
|
+
};
|
|
639
|
+
};
|
|
640
|
+
var normalizeClause = (input) => {
|
|
641
|
+
if (typeof input === "string") {
|
|
642
|
+
return scopeClause(input);
|
|
643
|
+
}
|
|
644
|
+
if (Array.isArray(input)) {
|
|
645
|
+
return scopeClause(...input);
|
|
646
|
+
}
|
|
647
|
+
if (!isClause(input)) {
|
|
648
|
+
throw new SlateDeclarationError("Action scope clauses must be strings or OR clauses");
|
|
649
|
+
}
|
|
650
|
+
assertScopeValues(input.OR);
|
|
651
|
+
return {
|
|
652
|
+
OR: [...input.OR]
|
|
653
|
+
};
|
|
654
|
+
};
|
|
655
|
+
var assertScopeValues = (scopes) => {
|
|
656
|
+
if (scopes.length === 0) {
|
|
657
|
+
throw new SlateDeclarationError("Each action scope clause must include at least one OR scope");
|
|
658
|
+
}
|
|
659
|
+
for (let scope of scopes) {
|
|
660
|
+
if (typeof scope !== "string" || scope.trim().length === 0) {
|
|
661
|
+
throw new SlateDeclarationError("Action scopes must be non-empty strings");
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
var isClause = (value) => typeof value === "object" && value !== null && "OR" in value && Array.isArray(value.OR);
|
|
666
|
+
var isScopes = (value) => typeof value === "object" && value !== null && "AND" in value && Array.isArray(value.AND);
|
|
667
|
+
|
|
668
|
+
// src/action/builder.ts
|
|
669
|
+
var SlateActionBuilder = class {
|
|
670
|
+
constructor(type, spec2, params, factory) {
|
|
671
|
+
this.type = type;
|
|
672
|
+
this.spec = spec2;
|
|
673
|
+
this.params = params;
|
|
674
|
+
this.factory = factory;
|
|
675
|
+
this.#configSchema = spec2.configSchema;
|
|
676
|
+
this.#authSchema = spec2.authSchema;
|
|
677
|
+
}
|
|
678
|
+
type;
|
|
679
|
+
spec;
|
|
680
|
+
params;
|
|
681
|
+
factory;
|
|
682
|
+
#configSchema;
|
|
683
|
+
#authSchema;
|
|
684
|
+
#inputSchema = null;
|
|
685
|
+
#outputSchema = null;
|
|
686
|
+
#scopes;
|
|
687
|
+
#toolParams = null;
|
|
688
|
+
#triggerParams = null;
|
|
689
|
+
input(schema) {
|
|
690
|
+
this.#inputSchema = schema;
|
|
691
|
+
return this;
|
|
692
|
+
}
|
|
693
|
+
output(schema) {
|
|
694
|
+
this.#outputSchema = schema;
|
|
695
|
+
return this;
|
|
696
|
+
}
|
|
697
|
+
scopes(scopes) {
|
|
698
|
+
validateScopes(scopes);
|
|
699
|
+
this.#scopes = scopes;
|
|
700
|
+
return this;
|
|
701
|
+
}
|
|
702
|
+
handleInvocation(handler) {
|
|
703
|
+
if (this.type !== "tool") {
|
|
704
|
+
throw new SlateDeclarationError("handleInvocation can only be set for tool actions");
|
|
705
|
+
}
|
|
706
|
+
this.#toolParams = {
|
|
707
|
+
type: "tool",
|
|
708
|
+
handleInvocation: handler
|
|
709
|
+
};
|
|
710
|
+
return this;
|
|
711
|
+
}
|
|
712
|
+
webhook(props) {
|
|
713
|
+
if (this.type !== "trigger") {
|
|
714
|
+
throw new SlateDeclarationError("handleEvent can only be set for trigger actions");
|
|
715
|
+
}
|
|
716
|
+
this.#triggerParams = {
|
|
717
|
+
type: "trigger",
|
|
718
|
+
source: "webhook",
|
|
719
|
+
handleEvent: props.handleEvent,
|
|
720
|
+
handleRequest: props.handleRequest,
|
|
721
|
+
autoRegisterWebhook: props.autoRegisterWebhook,
|
|
722
|
+
autoUnregisterWebhook: props.autoUnregisterWebhook
|
|
723
|
+
};
|
|
724
|
+
return this;
|
|
725
|
+
}
|
|
726
|
+
polling(props) {
|
|
727
|
+
if (this.type !== "trigger") {
|
|
728
|
+
throw new SlateDeclarationError("handleEvent can only be set for trigger actions");
|
|
729
|
+
}
|
|
730
|
+
this.#triggerParams = {
|
|
731
|
+
type: "trigger",
|
|
732
|
+
source: "polling",
|
|
733
|
+
polling: props.options,
|
|
734
|
+
pollEvents: props.pollEvents,
|
|
735
|
+
handleEvent: props.handleEvent
|
|
736
|
+
};
|
|
737
|
+
return this;
|
|
738
|
+
}
|
|
739
|
+
build() {
|
|
740
|
+
let scopes = this.#scopes ?? this.params.scopes;
|
|
741
|
+
if (scopes) {
|
|
742
|
+
validateScopes(scopes);
|
|
743
|
+
}
|
|
744
|
+
if (!this.#inputSchema) {
|
|
745
|
+
throw new SlateDeclarationError("Input schema is not defined");
|
|
746
|
+
}
|
|
747
|
+
if (!this.#outputSchema) {
|
|
748
|
+
throw new SlateDeclarationError("Output schema is not defined");
|
|
749
|
+
}
|
|
750
|
+
if (this.type === "tool" && !this.#toolParams) {
|
|
751
|
+
throw new SlateDeclarationError("Tool invocation handler is not defined");
|
|
752
|
+
}
|
|
753
|
+
if (this.type === "trigger" && !this.#triggerParams) {
|
|
754
|
+
throw new SlateDeclarationError("Trigger event handlers are not defined");
|
|
755
|
+
}
|
|
756
|
+
return this.factory({
|
|
757
|
+
...this.params,
|
|
758
|
+
scopes,
|
|
759
|
+
configSchema: this.#configSchema,
|
|
760
|
+
authSchema: this.#authSchema,
|
|
761
|
+
inputSchema: this.#inputSchema,
|
|
762
|
+
outputSchema: this.#outputSchema,
|
|
763
|
+
...this.#toolParams,
|
|
764
|
+
...this.#triggerParams
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
// src/action/tool.ts
|
|
770
|
+
var SlateTool = class _SlateTool extends SlateAction {
|
|
771
|
+
#handleInvocation;
|
|
772
|
+
constructor(spec2, inputSchema, outputSchema, params) {
|
|
773
|
+
super("tool", spec2, inputSchema, outputSchema, params);
|
|
774
|
+
this.#handleInvocation = params.handleInvocation;
|
|
775
|
+
}
|
|
776
|
+
static create(spec2, params) {
|
|
777
|
+
return new SlateActionBuilder("tool", spec2, params, (params2) => {
|
|
778
|
+
if (params2.type !== "tool") throw new Error("Invalid action type for tool");
|
|
779
|
+
return new _SlateTool(spec2, params2.inputSchema, params2.outputSchema, params2);
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
get handleInvocation() {
|
|
783
|
+
return this.#handleInvocation;
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
var tool = (spec2, params) => SlateTool.create(spec2, params);
|
|
787
|
+
|
|
788
|
+
// src/action/trigger.ts
|
|
789
|
+
var SlateDefaultPollingIntervalSeconds = 60 * 10;
|
|
790
|
+
var SlateTrigger = class _SlateTrigger extends SlateAction {
|
|
791
|
+
#source;
|
|
792
|
+
#polling;
|
|
793
|
+
#handleEvent;
|
|
794
|
+
#handleRequest;
|
|
795
|
+
#pollEvents;
|
|
796
|
+
#autoRegisterWebhook;
|
|
797
|
+
#autoUnregisterWebhook;
|
|
798
|
+
constructor(spec2, inputSchema, outputSchema, params) {
|
|
799
|
+
super("trigger", spec2, inputSchema, outputSchema, params);
|
|
800
|
+
this.#source = params.source;
|
|
801
|
+
this.#polling = params.polling || {
|
|
802
|
+
intervalInSeconds: SlateDefaultPollingIntervalSeconds
|
|
803
|
+
};
|
|
804
|
+
this.#handleEvent = params.handleEvent;
|
|
805
|
+
this.#handleRequest = params.handleRequest;
|
|
806
|
+
this.#pollEvents = params.pollEvents;
|
|
807
|
+
this.#autoRegisterWebhook = params.autoRegisterWebhook;
|
|
808
|
+
this.#autoUnregisterWebhook = params.autoUnregisterWebhook;
|
|
809
|
+
}
|
|
810
|
+
static create(spec2, params) {
|
|
811
|
+
return new SlateActionBuilder("trigger", spec2, params, (params2) => {
|
|
812
|
+
if (params2.type !== "trigger") throw new Error("Invalid action type for trigger");
|
|
813
|
+
return new _SlateTrigger(spec2, params2.inputSchema, params2.outputSchema, params2);
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
get polling() {
|
|
817
|
+
return this.#polling;
|
|
818
|
+
}
|
|
819
|
+
get source() {
|
|
820
|
+
return this.#source;
|
|
821
|
+
}
|
|
822
|
+
get handleEvent() {
|
|
823
|
+
return this.#handleEvent;
|
|
824
|
+
}
|
|
825
|
+
get handleRequest() {
|
|
826
|
+
return this.#handleRequest;
|
|
827
|
+
}
|
|
828
|
+
get pollEvents() {
|
|
829
|
+
return this.#pollEvents;
|
|
830
|
+
}
|
|
831
|
+
get autoRegisterWebhook() {
|
|
832
|
+
return this.#autoRegisterWebhook;
|
|
833
|
+
}
|
|
834
|
+
get autoUnregisterWebhook() {
|
|
835
|
+
return this.#autoUnregisterWebhook;
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
var trigger = (spec2, params) => SlateTrigger.create(spec2, params);
|
|
839
|
+
|
|
840
|
+
// src/action/attachment.ts
|
|
841
|
+
var createUrlAttachment = (url, mimeType) => ({
|
|
842
|
+
mimeType,
|
|
843
|
+
content: {
|
|
844
|
+
type: "url",
|
|
845
|
+
url
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
var createBase64Attachment = (content, mimeType) => ({
|
|
849
|
+
mimeType,
|
|
850
|
+
content: {
|
|
851
|
+
type: "content",
|
|
852
|
+
encoding: "base64",
|
|
853
|
+
content
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
var createTextAttachment = (content, mimeType) => ({
|
|
857
|
+
mimeType,
|
|
858
|
+
content: {
|
|
859
|
+
type: "content",
|
|
860
|
+
encoding: "utf-8",
|
|
861
|
+
content
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
// src/auth/auth.ts
|
|
866
|
+
var SlateAuth = class _SlateAuth {
|
|
867
|
+
#outputSchema = null;
|
|
868
|
+
#authStack = [];
|
|
869
|
+
constructor() {
|
|
870
|
+
}
|
|
871
|
+
static create() {
|
|
872
|
+
return new _SlateAuth();
|
|
873
|
+
}
|
|
874
|
+
output(schema) {
|
|
875
|
+
this.#outputSchema = schema;
|
|
876
|
+
return this;
|
|
877
|
+
}
|
|
878
|
+
addAuth(auth2) {
|
|
879
|
+
let existingKeys = this.#authStack.map((a) => a.key);
|
|
880
|
+
if (existingKeys.includes(auth2.key)) {
|
|
881
|
+
throw new Error(`Auth with key "${auth2.key}" already exists in the auth stack`);
|
|
882
|
+
}
|
|
883
|
+
this.#authStack.push(auth2);
|
|
884
|
+
return this;
|
|
885
|
+
}
|
|
886
|
+
addOauth(auth2) {
|
|
887
|
+
this.addAuth(auth2);
|
|
888
|
+
return this;
|
|
889
|
+
}
|
|
890
|
+
addTokenAuth(auth2) {
|
|
891
|
+
this.addAuth(auth2);
|
|
892
|
+
return this;
|
|
893
|
+
}
|
|
894
|
+
addServiceAccountAuth(auth2) {
|
|
895
|
+
this.addAuth(auth2);
|
|
896
|
+
return this;
|
|
897
|
+
}
|
|
898
|
+
addCustomAuth(auth2) {
|
|
899
|
+
this.addAuth(auth2);
|
|
900
|
+
return this;
|
|
901
|
+
}
|
|
902
|
+
addNone() {
|
|
903
|
+
this.addAuth({
|
|
904
|
+
type: "auth.none",
|
|
905
|
+
name: "No Authentication",
|
|
906
|
+
key: "none"
|
|
907
|
+
});
|
|
908
|
+
return this;
|
|
909
|
+
}
|
|
910
|
+
get authStack() {
|
|
911
|
+
return this.#authStack.filter((a) => a.type !== "auth.none");
|
|
912
|
+
}
|
|
913
|
+
get outputSchema() {
|
|
914
|
+
if (!this.#outputSchema) {
|
|
915
|
+
throw new Error("Output schema is not defined for this auth");
|
|
916
|
+
}
|
|
917
|
+
return this.#outputSchema;
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
var auth = () => SlateAuth.create();
|
|
921
|
+
|
|
922
|
+
// src/axios/index.ts
|
|
923
|
+
import baseAxios, { getAdapter, isAxiosError as isAxiosError2 } from "axios";
|
|
924
|
+
|
|
925
|
+
// src/axios/trace.ts
|
|
926
|
+
var traceDraftsByConfig = /* @__PURE__ */ new WeakMap();
|
|
927
|
+
var traceDraftsByHeaders = /* @__PURE__ */ new WeakMap();
|
|
928
|
+
var TRACE_TEXT_LIMIT = 10 * 1024;
|
|
929
|
+
var REDACTED_VALUE = "[redacted]";
|
|
930
|
+
var STRUCTURED_DEPTH_LIMIT = 6;
|
|
931
|
+
var STRUCTURED_ENTRY_LIMIT = 50;
|
|
932
|
+
var CORE_SECRET_KEY_ATOMS = [
|
|
933
|
+
// HTTP authentication
|
|
934
|
+
"authorization",
|
|
935
|
+
"proxy[-_.]?authorization",
|
|
936
|
+
"www[-_.]?authenticate",
|
|
937
|
+
"bearer",
|
|
938
|
+
// Generic tokens
|
|
939
|
+
"token",
|
|
940
|
+
"tokens",
|
|
941
|
+
"access[-_.]?token",
|
|
942
|
+
"refresh[-_.]?token",
|
|
943
|
+
"id[-_.]?token",
|
|
944
|
+
"auth[-_.]?token",
|
|
945
|
+
"bearer[-_.]?token",
|
|
946
|
+
"session[-_.]?token",
|
|
947
|
+
"api[-_.]?token",
|
|
948
|
+
"app[-_.]?token",
|
|
949
|
+
"user[-_.]?token",
|
|
950
|
+
"oauth[-_.]?token",
|
|
951
|
+
"personal[-_.]?access[-_.]?token",
|
|
952
|
+
"x[-_.]?auth[-_.]?token",
|
|
953
|
+
"x[-_.]?access[-_.]?token",
|
|
954
|
+
"x[-_.]?refresh[-_.]?token",
|
|
955
|
+
// API keys
|
|
956
|
+
"apikey",
|
|
957
|
+
"api[-_.]?key",
|
|
958
|
+
"app[-_.]?key",
|
|
959
|
+
"x[-_.]?api[-_.]?key",
|
|
960
|
+
"x[-_.]?app[-_.]?key",
|
|
961
|
+
// OAuth client credentials
|
|
962
|
+
"client[-_.]?secret",
|
|
963
|
+
"client[-_.]?key",
|
|
964
|
+
"consumer[-_.]?secret",
|
|
965
|
+
"consumer[-_.]?key",
|
|
966
|
+
// Cryptographic keys
|
|
967
|
+
"private[-_.]?key",
|
|
968
|
+
"privatekey",
|
|
969
|
+
"secret[-_.]?key",
|
|
970
|
+
"secretkey",
|
|
971
|
+
"secret[-_.]?access[-_.]?key",
|
|
972
|
+
"encryption[-_.]?key",
|
|
973
|
+
"decryption[-_.]?key",
|
|
974
|
+
"signing[-_.]?key",
|
|
975
|
+
"signing[-_.]?secret",
|
|
976
|
+
"master[-_.]?key",
|
|
977
|
+
"master[-_.]?secret",
|
|
978
|
+
"master[-_.]?password",
|
|
979
|
+
"shared[-_.]?secret",
|
|
980
|
+
"webhook[-_.]?secret",
|
|
981
|
+
"webhook[-_.]?signing[-_.]?secret",
|
|
982
|
+
// OAuth codes & PKCE
|
|
983
|
+
"auth[-_.]?code",
|
|
984
|
+
"authcode",
|
|
985
|
+
"authorization[-_.]?code",
|
|
986
|
+
"code[-_.]?verifier",
|
|
987
|
+
"code[-_.]?challenge",
|
|
988
|
+
// Passwords & passcodes
|
|
989
|
+
"password",
|
|
990
|
+
"passwd",
|
|
991
|
+
"pwd",
|
|
992
|
+
"passphrase",
|
|
993
|
+
"pass[-_.]?phrase",
|
|
994
|
+
"pin",
|
|
995
|
+
"passcode",
|
|
996
|
+
// Generic secret markers
|
|
997
|
+
"secret",
|
|
998
|
+
"secrets",
|
|
999
|
+
"credential",
|
|
1000
|
+
"credentials",
|
|
1001
|
+
"creds",
|
|
1002
|
+
"auth",
|
|
1003
|
+
"x[-_.]?auth",
|
|
1004
|
+
"x[-_.]?auth[-_.]?key",
|
|
1005
|
+
// CSRF / XSRF
|
|
1006
|
+
"csrf",
|
|
1007
|
+
"xsrf",
|
|
1008
|
+
"csrf[-_.]?token",
|
|
1009
|
+
"xsrf[-_.]?token",
|
|
1010
|
+
"x[-_.]?csrf[-_.]?token",
|
|
1011
|
+
"x[-_.]?xsrf[-_.]?token",
|
|
1012
|
+
// JWT
|
|
1013
|
+
"jwt",
|
|
1014
|
+
// Sessions & cookies
|
|
1015
|
+
"session[-_.]?id",
|
|
1016
|
+
"sessionid",
|
|
1017
|
+
"sid",
|
|
1018
|
+
"cookie",
|
|
1019
|
+
"cookies",
|
|
1020
|
+
"set[-_.]?cookie",
|
|
1021
|
+
// Signatures / MAC
|
|
1022
|
+
"signature",
|
|
1023
|
+
"x[-_.]?hub[-_.]?signature",
|
|
1024
|
+
"x[-_.]?signature",
|
|
1025
|
+
"sig",
|
|
1026
|
+
"hmac",
|
|
1027
|
+
"mac",
|
|
1028
|
+
// Crypto artifacts
|
|
1029
|
+
"salt",
|
|
1030
|
+
"nonce",
|
|
1031
|
+
// Multi-factor / verification
|
|
1032
|
+
"otp",
|
|
1033
|
+
"totp",
|
|
1034
|
+
"mfa",
|
|
1035
|
+
"mfa[-_.]?code",
|
|
1036
|
+
"2fa",
|
|
1037
|
+
"two[-_.]?factor",
|
|
1038
|
+
"twofactor",
|
|
1039
|
+
"verification[-_.]?code",
|
|
1040
|
+
"verify[-_.]?code",
|
|
1041
|
+
"confirm(?:ation)?[-_.]?code",
|
|
1042
|
+
"sms[-_.]?code",
|
|
1043
|
+
"email[-_.]?code",
|
|
1044
|
+
// Recovery & seed phrases
|
|
1045
|
+
"seed[-_.]?phrase",
|
|
1046
|
+
"mnemonic",
|
|
1047
|
+
"recovery[-_.]?key",
|
|
1048
|
+
"recovery[-_.]?code",
|
|
1049
|
+
"recovery[-_.]?phrase",
|
|
1050
|
+
// PII / financial
|
|
1051
|
+
"card[-_.]?number",
|
|
1052
|
+
"card[-_.]?code",
|
|
1053
|
+
"cvv",
|
|
1054
|
+
"cvc",
|
|
1055
|
+
"ccv",
|
|
1056
|
+
"cc[-_.]?num(?:ber)?",
|
|
1057
|
+
"pan",
|
|
1058
|
+
"ssn",
|
|
1059
|
+
"social[-_.]?security",
|
|
1060
|
+
"license[-_.]?key"
|
|
1061
|
+
];
|
|
1062
|
+
var URL_FORM_SECRET_KEY_ATOMS = [...CORE_SECRET_KEY_ATOMS, "code"];
|
|
1063
|
+
var buildKeyBoundaryPattern = (atoms, flags) => new RegExp(
|
|
1064
|
+
`(?:^|[^A-Za-z0-9])(?:${atoms.join("|")})(?=[^A-Za-z0-9]|$)`,
|
|
1065
|
+
flags
|
|
1066
|
+
);
|
|
1067
|
+
var SECRET_KEY_PATTERN = buildKeyBoundaryPattern(CORE_SECRET_KEY_ATOMS, "i");
|
|
1068
|
+
var URL_FORM_SECRET_KEY_PATTERN = buildKeyBoundaryPattern(
|
|
1069
|
+
URL_FORM_SECRET_KEY_ATOMS,
|
|
1070
|
+
"i"
|
|
1071
|
+
);
|
|
1072
|
+
var NON_SECRET_KEY_EXACT = /* @__PURE__ */ new Set([
|
|
1073
|
+
"token_type",
|
|
1074
|
+
"token-type",
|
|
1075
|
+
"tokentype",
|
|
1076
|
+
"token_kind",
|
|
1077
|
+
"token-kind",
|
|
1078
|
+
"tokenkind",
|
|
1079
|
+
"token_ttl",
|
|
1080
|
+
"token-ttl",
|
|
1081
|
+
"token_expires_in",
|
|
1082
|
+
"token-expires-in",
|
|
1083
|
+
"token_expiry",
|
|
1084
|
+
"signature_method",
|
|
1085
|
+
"signature-method",
|
|
1086
|
+
"signature_type",
|
|
1087
|
+
"signature-type",
|
|
1088
|
+
"signature_version",
|
|
1089
|
+
"signature-version",
|
|
1090
|
+
"auth_type",
|
|
1091
|
+
"auth-type",
|
|
1092
|
+
"auth_method",
|
|
1093
|
+
"auth-method",
|
|
1094
|
+
"authentication_type",
|
|
1095
|
+
"authentication-type",
|
|
1096
|
+
"authentication_method",
|
|
1097
|
+
"authentication-method",
|
|
1098
|
+
"grant_type",
|
|
1099
|
+
"grant-type",
|
|
1100
|
+
"password_strength",
|
|
1101
|
+
"password-strength",
|
|
1102
|
+
"password_policy",
|
|
1103
|
+
"password-policy",
|
|
1104
|
+
"key_type",
|
|
1105
|
+
"key-type",
|
|
1106
|
+
"key_name",
|
|
1107
|
+
"key-name",
|
|
1108
|
+
"key_id",
|
|
1109
|
+
"key-id",
|
|
1110
|
+
"kid"
|
|
1111
|
+
]);
|
|
1112
|
+
var isSecretKeyName = (name) => {
|
|
1113
|
+
let normalized = name.toLowerCase();
|
|
1114
|
+
if (NON_SECRET_KEY_EXACT.has(normalized)) return false;
|
|
1115
|
+
return SECRET_KEY_PATTERN.test(normalized);
|
|
1116
|
+
};
|
|
1117
|
+
var isUrlFormSecretKeyName = (name) => {
|
|
1118
|
+
let normalized = name.toLowerCase();
|
|
1119
|
+
if (NON_SECRET_KEY_EXACT.has(normalized)) return false;
|
|
1120
|
+
return URL_FORM_SECRET_KEY_PATTERN.test(normalized);
|
|
1121
|
+
};
|
|
1122
|
+
var KNOWN_SECRET_VALUE_PATTERNS = [
|
|
1123
|
+
// JSON Web Tokens (header.payload.signature)
|
|
1124
|
+
/\beyJ[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{4,}\b/g,
|
|
1125
|
+
// AWS access key IDs
|
|
1126
|
+
/\b(?:AKIA|ASIA|AGPA|AIDA|ANPA|ANVA|AROA|APKA|ASCA)[A-Z0-9]{16}\b/g,
|
|
1127
|
+
// GitHub tokens (PAT / OAuth / server-to-server / user-to-server / refresh)
|
|
1128
|
+
/\bgh[pousr]_[A-Za-z0-9]{30,}\b/g,
|
|
1129
|
+
// Slack tokens
|
|
1130
|
+
/\bxox[abprs]-[A-Za-z0-9-]{10,}\b/g,
|
|
1131
|
+
// Stripe secret / public / restricted keys
|
|
1132
|
+
/\b(?:sk|rk|pk)_(?:test|live)_[A-Za-z0-9]{16,}\b/g,
|
|
1133
|
+
// OpenAI API keys
|
|
1134
|
+
/\bsk-(?:proj-)?[A-Za-z0-9_-]{20,}\b/g,
|
|
1135
|
+
// Anthropic API keys
|
|
1136
|
+
/\bsk-ant-[A-Za-z0-9_-]{20,}\b/g,
|
|
1137
|
+
// Google API keys
|
|
1138
|
+
/\bAIza[A-Za-z0-9_-]{35}\b/g,
|
|
1139
|
+
// SendGrid API keys
|
|
1140
|
+
/\bSG\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\b/g,
|
|
1141
|
+
// Twilio API keys
|
|
1142
|
+
/\bSK[0-9a-fA-F]{32}\b/g,
|
|
1143
|
+
// PEM-encoded private keys (multi-line)
|
|
1144
|
+
/-----BEGIN[A-Z ]*PRIVATE KEY-----[\s\S]*?-----END[A-Z ]*PRIVATE KEY-----/g,
|
|
1145
|
+
// SSH private keys (OpenSSH format)
|
|
1146
|
+
/-----BEGIN OPENSSH PRIVATE KEY-----[\s\S]*?-----END OPENSSH PRIVATE KEY-----/g
|
|
1147
|
+
];
|
|
1148
|
+
var HTTP_AUTH_SCHEME_PATTERN = /\b(bearer|basic|digest|token|negotiate|apikey)\s+([A-Za-z0-9_\-.~+/=]{4,})/gi;
|
|
1149
|
+
var GENERIC_KEY_VALUE_PATTERN = /(?<![A-Za-z0-9])([A-Za-z0-9][A-Za-z0-9_\-.]*)(\s*=\s*)([^&#\s;]+)/g;
|
|
1150
|
+
var GENERIC_JSON_KEY_VALUE_PATTERN = /"([^"\\]*(?:\\.[^"\\]*)*)"(\s*:\s*)"([^"\\]*(?:\\.[^"\\]*)*)"/g;
|
|
1151
|
+
var SAFE_HEADER_NAMES = /* @__PURE__ */ new Set([
|
|
1152
|
+
"accept",
|
|
1153
|
+
"accept-encoding",
|
|
1154
|
+
"accept-language",
|
|
1155
|
+
"cache-control",
|
|
1156
|
+
"connection",
|
|
1157
|
+
"content-encoding",
|
|
1158
|
+
"content-language",
|
|
1159
|
+
"content-length",
|
|
1160
|
+
"content-type",
|
|
1161
|
+
"date",
|
|
1162
|
+
"etag",
|
|
1163
|
+
"expires",
|
|
1164
|
+
"if-modified-since",
|
|
1165
|
+
"if-none-match",
|
|
1166
|
+
"keep-alive",
|
|
1167
|
+
"last-modified",
|
|
1168
|
+
"location",
|
|
1169
|
+
"origin",
|
|
1170
|
+
"pragma",
|
|
1171
|
+
"referer",
|
|
1172
|
+
"referrer-policy",
|
|
1173
|
+
"request-id",
|
|
1174
|
+
"retry-after",
|
|
1175
|
+
"server",
|
|
1176
|
+
"transfer-encoding",
|
|
1177
|
+
"user-agent",
|
|
1178
|
+
"vary",
|
|
1179
|
+
"via",
|
|
1180
|
+
"x-correlation-id",
|
|
1181
|
+
"x-powered-by",
|
|
1182
|
+
"x-request-id",
|
|
1183
|
+
"x-slates-provider",
|
|
1184
|
+
"x-trace-id"
|
|
1185
|
+
]);
|
|
1186
|
+
var SAFE_HEADER_PREFIXES = ["ratelimit-", "x-ratelimit-"];
|
|
1187
|
+
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1188
|
+
var isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
1189
|
+
var normalizeContentType = (value) => value?.split(";")[0]?.trim().toLowerCase() || void 0;
|
|
1190
|
+
var isTextContentType = (contentType) => !contentType || /(^text\/)|json|xml|html|javascript|graphql|x-www-form-urlencoded|svg/.test(contentType);
|
|
1191
|
+
var isSafeHeaderName = (name) => {
|
|
1192
|
+
let normalized = name.toLowerCase();
|
|
1193
|
+
if (isSecretKeyName(normalized)) return false;
|
|
1194
|
+
if (SAFE_HEADER_NAMES.has(normalized)) return true;
|
|
1195
|
+
return SAFE_HEADER_PREFIXES.some((prefix) => normalized.startsWith(prefix));
|
|
1196
|
+
};
|
|
1197
|
+
var truncateText = (text) => {
|
|
1198
|
+
if (text.length <= TRACE_TEXT_LIMIT) {
|
|
1199
|
+
return { text, truncated: false };
|
|
1200
|
+
}
|
|
1201
|
+
return {
|
|
1202
|
+
text: `${text.slice(0, TRACE_TEXT_LIMIT)}...[truncated]`,
|
|
1203
|
+
truncated: true
|
|
1204
|
+
};
|
|
1205
|
+
};
|
|
1206
|
+
var sanitizeFreeText = (text) => {
|
|
1207
|
+
if (!text) return text;
|
|
1208
|
+
let result = text;
|
|
1209
|
+
result = result.replace(
|
|
1210
|
+
HTTP_AUTH_SCHEME_PATTERN,
|
|
1211
|
+
(_match, scheme) => `${scheme} ${REDACTED_VALUE}`
|
|
1212
|
+
);
|
|
1213
|
+
for (let pattern of KNOWN_SECRET_VALUE_PATTERNS) {
|
|
1214
|
+
result = result.replace(pattern, REDACTED_VALUE);
|
|
1215
|
+
}
|
|
1216
|
+
result = result.replace(
|
|
1217
|
+
GENERIC_KEY_VALUE_PATTERN,
|
|
1218
|
+
(match, key, equals, _value) => isUrlFormSecretKeyName(key) ? `${key}${equals}${REDACTED_VALUE}` : match
|
|
1219
|
+
);
|
|
1220
|
+
result = result.replace(
|
|
1221
|
+
GENERIC_JSON_KEY_VALUE_PATTERN,
|
|
1222
|
+
(match, key, colon, _value) => isSecretKeyName(key) ? `"${key}"${colon}"${REDACTED_VALUE}"` : match
|
|
1223
|
+
);
|
|
1224
|
+
return result;
|
|
1225
|
+
};
|
|
1226
|
+
var sanitizeScalar = (value) => truncateText(sanitizeFreeText(value));
|
|
1227
|
+
var redactStructuredValue = (value, depth = 0) => {
|
|
1228
|
+
if (value == null) return value;
|
|
1229
|
+
if (depth >= STRUCTURED_DEPTH_LIMIT) return "[truncated]";
|
|
1230
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
1231
|
+
return typeof value === "string" ? sanitizeFreeText(value) : value;
|
|
1232
|
+
}
|
|
1233
|
+
if (Array.isArray(value)) {
|
|
1234
|
+
return value.slice(0, STRUCTURED_ENTRY_LIMIT).map((entry) => redactStructuredValue(entry, depth + 1));
|
|
1235
|
+
}
|
|
1236
|
+
if (isRecord2(value)) {
|
|
1237
|
+
return Object.fromEntries(
|
|
1238
|
+
Object.entries(value).slice(0, STRUCTURED_ENTRY_LIMIT).map(([key, entry]) => [
|
|
1239
|
+
key,
|
|
1240
|
+
isSecretKeyName(key) ? REDACTED_VALUE : redactStructuredValue(entry, depth + 1)
|
|
1241
|
+
])
|
|
1242
|
+
);
|
|
1243
|
+
}
|
|
1244
|
+
return String(value);
|
|
1245
|
+
};
|
|
1246
|
+
var maybeParseJson = (text, contentType) => {
|
|
1247
|
+
let trimmed = text.trim();
|
|
1248
|
+
if (!trimmed) return null;
|
|
1249
|
+
if (!contentType?.includes("json") && !/^[\[{]/.test(trimmed)) {
|
|
1250
|
+
return null;
|
|
1251
|
+
}
|
|
1252
|
+
try {
|
|
1253
|
+
return JSON.parse(trimmed);
|
|
1254
|
+
} catch {
|
|
1255
|
+
return null;
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
var sanitizeTextBody = (text, contentType) => {
|
|
1259
|
+
if (!text) return void 0;
|
|
1260
|
+
let normalizedContentType = normalizeContentType(contentType);
|
|
1261
|
+
let parsedJson = maybeParseJson(text, normalizedContentType);
|
|
1262
|
+
let normalizedText = parsedJson !== null ? JSON.stringify(redactStructuredValue(parsedJson)) : sanitizeFreeText(text);
|
|
1263
|
+
let { text: truncatedText, truncated } = truncateText(normalizedText);
|
|
1264
|
+
return {
|
|
1265
|
+
...normalizedContentType ? { contentType: normalizedContentType } : {},
|
|
1266
|
+
text: truncatedText,
|
|
1267
|
+
...truncated ? { truncated: true } : {}
|
|
1268
|
+
};
|
|
1269
|
+
};
|
|
1270
|
+
var isBinaryLike = (value) => {
|
|
1271
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(value)) return true;
|
|
1272
|
+
if (value instanceof ArrayBuffer) return true;
|
|
1273
|
+
if (ArrayBuffer.isView(value)) return true;
|
|
1274
|
+
if (typeof Blob !== "undefined" && value instanceof Blob) return true;
|
|
1275
|
+
if (typeof FormData !== "undefined" && value instanceof FormData) return true;
|
|
1276
|
+
return false;
|
|
1277
|
+
};
|
|
1278
|
+
var serializeTextBody = (value, contentType) => {
|
|
1279
|
+
let normalizedContentType = normalizeContentType(contentType);
|
|
1280
|
+
if (value == null || isBinaryLike(value) || !isTextContentType(normalizedContentType)) {
|
|
1281
|
+
return void 0;
|
|
1282
|
+
}
|
|
1283
|
+
if (typeof value === "string") {
|
|
1284
|
+
return sanitizeTextBody(value, normalizedContentType);
|
|
1285
|
+
}
|
|
1286
|
+
if (value instanceof URLSearchParams) {
|
|
1287
|
+
return sanitizeTextBody(value.toString(), normalizedContentType);
|
|
1288
|
+
}
|
|
1289
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
1290
|
+
return sanitizeTextBody(String(value), normalizedContentType);
|
|
1291
|
+
}
|
|
1292
|
+
if (Array.isArray(value) || isRecord2(value)) {
|
|
1293
|
+
return sanitizeTextBody(JSON.stringify(redactStructuredValue(value)), "application/json");
|
|
1294
|
+
}
|
|
1295
|
+
return void 0;
|
|
1296
|
+
};
|
|
1297
|
+
var buildUrl = (baseURL, url) => {
|
|
1298
|
+
if (!url) return "";
|
|
1299
|
+
if (!baseURL) return url;
|
|
1300
|
+
try {
|
|
1301
|
+
return new URL(url, baseURL).toString();
|
|
1302
|
+
} catch {
|
|
1303
|
+
return url;
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
var REDACTED_ENCODED = encodeURIComponent(REDACTED_VALUE);
|
|
1307
|
+
var decodeRedactedMarker = (value) => REDACTED_ENCODED === REDACTED_VALUE ? value : value.split(REDACTED_ENCODED).join(REDACTED_VALUE);
|
|
1308
|
+
var redactHashFragment = (hash) => {
|
|
1309
|
+
if (!hash || !hash.includes("=")) return hash;
|
|
1310
|
+
let withoutHash = hash.startsWith("#") ? hash.slice(1) : hash;
|
|
1311
|
+
let redacted = withoutHash.replace(
|
|
1312
|
+
/(?<![A-Za-z0-9])([A-Za-z0-9][A-Za-z0-9_\-.]*)=([^&]*)/g,
|
|
1313
|
+
(match, key, _rawValue) => isUrlFormSecretKeyName(key) ? `${key}=${REDACTED_VALUE}` : match
|
|
1314
|
+
);
|
|
1315
|
+
return redacted ? `#${redacted}` : "";
|
|
1316
|
+
};
|
|
1317
|
+
var sanitizeUrl = (value) => {
|
|
1318
|
+
if (!value) return value;
|
|
1319
|
+
try {
|
|
1320
|
+
let url = new URL(value);
|
|
1321
|
+
if (url.username || url.password) {
|
|
1322
|
+
url.username = "";
|
|
1323
|
+
url.password = "";
|
|
1324
|
+
}
|
|
1325
|
+
for (let key of Array.from(url.searchParams.keys())) {
|
|
1326
|
+
if (isUrlFormSecretKeyName(key)) {
|
|
1327
|
+
url.searchParams.set(key, REDACTED_VALUE);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
url.hash = redactHashFragment(url.hash);
|
|
1331
|
+
return decodeRedactedMarker(url.toString());
|
|
1332
|
+
} catch {
|
|
1333
|
+
return value.replace(
|
|
1334
|
+
/([?&]([^=&#]+)=)([^&#]+)/g,
|
|
1335
|
+
(_match, prefix, key, rawValue) => isUrlFormSecretKeyName(key) ? `${prefix}${REDACTED_VALUE}` : `${prefix}${rawValue}`
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
};
|
|
1339
|
+
var flattenHeaderValue = (value) => {
|
|
1340
|
+
if (typeof value === "string") return value;
|
|
1341
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
1342
|
+
if (Array.isArray(value)) {
|
|
1343
|
+
let normalized = value.map((entry) => flattenHeaderValue(entry)).filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
1344
|
+
return normalized.length > 0 ? normalized.join(", ") : void 0;
|
|
1345
|
+
}
|
|
1346
|
+
return void 0;
|
|
1347
|
+
};
|
|
1348
|
+
var headerEntries = (headers) => {
|
|
1349
|
+
if (!headers) return [];
|
|
1350
|
+
if (typeof headers.toJSON === "function") {
|
|
1351
|
+
let json = headers.toJSON();
|
|
1352
|
+
if (isRecord2(json)) {
|
|
1353
|
+
return Object.entries(json).map(([key, value]) => {
|
|
1354
|
+
let flattened = flattenHeaderValue(value);
|
|
1355
|
+
return flattened ? [key, flattened] : null;
|
|
1356
|
+
}).filter((entry) => entry !== null);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
if (typeof headers.entries === "function") {
|
|
1360
|
+
return Array.from(
|
|
1361
|
+
headers.entries()
|
|
1362
|
+
).map(([key, value]) => [key, value]);
|
|
1363
|
+
}
|
|
1364
|
+
if (isRecord2(headers)) {
|
|
1365
|
+
return Object.entries(headers).map(([key, value]) => {
|
|
1366
|
+
let flattened = flattenHeaderValue(value);
|
|
1367
|
+
return flattened ? [key, flattened] : null;
|
|
1368
|
+
}).filter((entry) => entry !== null);
|
|
1369
|
+
}
|
|
1370
|
+
return [];
|
|
1371
|
+
};
|
|
1372
|
+
var sanitizeHeaders = (headers) => {
|
|
1373
|
+
let entries = headerEntries(headers).map(([key, value]) => [key.toLowerCase(), sanitizeScalar(value).text]).filter(([key]) => isSafeHeaderName(key));
|
|
1374
|
+
if (entries.length === 0) return void 0;
|
|
1375
|
+
return Object.fromEntries(entries);
|
|
1376
|
+
};
|
|
1377
|
+
var getContentType = (headers) => headerEntries(headers).find(([key]) => key.toLowerCase() === "content-type")?.[1];
|
|
1378
|
+
var takeTraceDraft = (config2) => {
|
|
1379
|
+
if (!config2) return void 0;
|
|
1380
|
+
let draft = config2.__slatesHttpTraceDraft ?? (isObjectLike(config2) ? traceDraftsByConfig.get(config2) : void 0) ?? (isObjectLike(config2.headers) ? traceDraftsByHeaders.get(config2.headers) : void 0);
|
|
1381
|
+
if (!draft) return void 0;
|
|
1382
|
+
return draft;
|
|
1383
|
+
};
|
|
1384
|
+
var clearTraceDraft = (config2, draft) => {
|
|
1385
|
+
if (!config2) return;
|
|
1386
|
+
if (config2.__slatesHttpTraceDraft === draft) {
|
|
1387
|
+
delete config2.__slatesHttpTraceDraft;
|
|
1388
|
+
}
|
|
1389
|
+
if (isObjectLike(config2)) {
|
|
1390
|
+
traceDraftsByConfig.delete(config2);
|
|
1391
|
+
}
|
|
1392
|
+
if (isObjectLike(config2.headers)) {
|
|
1393
|
+
traceDraftsByHeaders.delete(config2.headers);
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
var attachHttpTraceDraft = (config2, context) => {
|
|
1397
|
+
let traceAwareConfig = config2;
|
|
1398
|
+
let contentType = getContentType(config2.headers);
|
|
1399
|
+
traceAwareConfig.__slatesHttpTraceDraft = {
|
|
1400
|
+
context,
|
|
1401
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1402
|
+
startedAtMs: Date.now(),
|
|
1403
|
+
request: {
|
|
1404
|
+
method: (config2.method ?? "GET").toUpperCase(),
|
|
1405
|
+
url: sanitizeUrl(buildUrl(config2.baseURL, config2.url)),
|
|
1406
|
+
...sanitizeHeaders(config2.headers) ? { headers: sanitizeHeaders(config2.headers) } : {},
|
|
1407
|
+
...serializeTextBody(config2.data, contentType) ? { body: serializeTextBody(config2.data, contentType) } : {}
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
if (isObjectLike(traceAwareConfig)) {
|
|
1411
|
+
traceDraftsByConfig.set(traceAwareConfig, traceAwareConfig.__slatesHttpTraceDraft);
|
|
1412
|
+
}
|
|
1413
|
+
if (isObjectLike(traceAwareConfig.headers)) {
|
|
1414
|
+
traceDraftsByHeaders.set(
|
|
1415
|
+
traceAwareConfig.headers,
|
|
1416
|
+
traceAwareConfig.__slatesHttpTraceDraft
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
return config2;
|
|
1420
|
+
};
|
|
1421
|
+
var recordHttpTraceFromResponse = (response) => {
|
|
1422
|
+
let config2 = response.config;
|
|
1423
|
+
let draft = takeTraceDraft(config2);
|
|
1424
|
+
if (!draft) return response;
|
|
1425
|
+
clearTraceDraft(config2, draft);
|
|
1426
|
+
let contentType = getContentType(response.headers);
|
|
1427
|
+
draft.context.recordHttpTrace({
|
|
1428
|
+
startedAt: draft.startedAt,
|
|
1429
|
+
durationMs: Math.max(Date.now() - draft.startedAtMs, 0),
|
|
1430
|
+
request: draft.request,
|
|
1431
|
+
response: {
|
|
1432
|
+
status: response.status,
|
|
1433
|
+
...response.statusText ? { statusText: response.statusText } : {},
|
|
1434
|
+
...sanitizeHeaders(response.headers) ? { headers: sanitizeHeaders(response.headers) } : {},
|
|
1435
|
+
...serializeTextBody(response.data, contentType) ? { body: serializeTextBody(response.data, contentType) } : {}
|
|
1436
|
+
}
|
|
1437
|
+
});
|
|
1438
|
+
return response;
|
|
1439
|
+
};
|
|
1440
|
+
var recordHttpTraceFromError = (error) => {
|
|
1441
|
+
let config2 = error.config;
|
|
1442
|
+
let draft = takeTraceDraft(config2);
|
|
1443
|
+
if (!draft) return;
|
|
1444
|
+
clearTraceDraft(config2, draft);
|
|
1445
|
+
let responseContentType = getContentType(error.response?.headers);
|
|
1446
|
+
draft.context.recordHttpTrace({
|
|
1447
|
+
startedAt: draft.startedAt,
|
|
1448
|
+
durationMs: Math.max(Date.now() - draft.startedAtMs, 0),
|
|
1449
|
+
request: draft.request,
|
|
1450
|
+
...error.response ? {
|
|
1451
|
+
response: {
|
|
1452
|
+
status: error.response.status,
|
|
1453
|
+
...error.response.statusText ? { statusText: error.response.statusText } : {},
|
|
1454
|
+
...sanitizeHeaders(error.response.headers) ? { headers: sanitizeHeaders(error.response.headers) } : {},
|
|
1455
|
+
...serializeTextBody(error.response.data, responseContentType) ? { body: serializeTextBody(error.response.data, responseContentType) } : {}
|
|
1456
|
+
}
|
|
1457
|
+
} : {},
|
|
1458
|
+
error: {
|
|
1459
|
+
...error.code ? { code: error.code } : {},
|
|
1460
|
+
message: error.message
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
};
|
|
1464
|
+
|
|
1465
|
+
// src/axios/index.ts
|
|
1466
|
+
var applySlateInterceptors = (instance, errorMapping) => {
|
|
1467
|
+
instance.interceptors.request.use(
|
|
1468
|
+
(request) => {
|
|
1469
|
+
let ctx = getCurrentContext();
|
|
1470
|
+
let spec2 = ctx.specification;
|
|
1471
|
+
request.headers.set("User-Agent", `slates.dev@1.0.0/${spec2.key}`);
|
|
1472
|
+
request.headers.set("X-Slates-Provider", spec2.key);
|
|
1473
|
+
let tracedRequest = attachHttpTraceDraft(request, ctx);
|
|
1474
|
+
if (!tracedRequest.__slatesTraceAdapterWrapped) {
|
|
1475
|
+
let adapter = getAdapter(tracedRequest.adapter ?? baseAxios.defaults.adapter);
|
|
1476
|
+
tracedRequest.adapter = async (config2) => {
|
|
1477
|
+
try {
|
|
1478
|
+
let response = await adapter(config2);
|
|
1479
|
+
return recordHttpTraceFromResponse(response);
|
|
1480
|
+
} catch (error) {
|
|
1481
|
+
if (isAxiosError2(error)) {
|
|
1482
|
+
recordHttpTraceFromError(error);
|
|
1483
|
+
}
|
|
1484
|
+
throw error;
|
|
1485
|
+
}
|
|
1486
|
+
};
|
|
1487
|
+
tracedRequest.__slatesTraceAdapterWrapped = true;
|
|
1488
|
+
}
|
|
1489
|
+
return tracedRequest;
|
|
1490
|
+
},
|
|
1491
|
+
(error) => Promise.reject(error)
|
|
1492
|
+
);
|
|
1493
|
+
instance.interceptors.response.use(
|
|
1494
|
+
(response) => response,
|
|
1495
|
+
(error) => Promise.reject(SlateError.fromAxios(error, errorMapping))
|
|
1496
|
+
);
|
|
1497
|
+
};
|
|
1498
|
+
applySlateInterceptors(baseAxios);
|
|
1499
|
+
var createAxios = (config2) => {
|
|
1500
|
+
let { errorMapping, ...axiosConfig } = config2 ?? {};
|
|
1501
|
+
let instance = baseAxios.create({
|
|
1502
|
+
...axiosConfig,
|
|
1503
|
+
headers: {
|
|
1504
|
+
...axiosConfig.headers
|
|
1505
|
+
}
|
|
1506
|
+
});
|
|
1507
|
+
applySlateInterceptors(instance, errorMapping);
|
|
1508
|
+
return instance;
|
|
1509
|
+
};
|
|
1510
|
+
var axios = createAxios();
|
|
1511
|
+
|
|
1512
|
+
// src/config/config.ts
|
|
1513
|
+
var SlateConfig = class _SlateConfig {
|
|
1514
|
+
#configSchema;
|
|
1515
|
+
#configChanged = null;
|
|
1516
|
+
#getDefaultConfig = null;
|
|
1517
|
+
constructor(schema) {
|
|
1518
|
+
this.#configSchema = schema;
|
|
1519
|
+
}
|
|
1520
|
+
static create(schema) {
|
|
1521
|
+
return new _SlateConfig(schema);
|
|
1522
|
+
}
|
|
1523
|
+
config(schema) {
|
|
1524
|
+
this.#configSchema = schema;
|
|
1525
|
+
return this;
|
|
1526
|
+
}
|
|
1527
|
+
onConfigChanged(handler) {
|
|
1528
|
+
this.#configChanged = handler;
|
|
1529
|
+
return this;
|
|
1530
|
+
}
|
|
1531
|
+
getDefaultConfig(getter) {
|
|
1532
|
+
this.#getDefaultConfig = getter;
|
|
1533
|
+
return this;
|
|
1534
|
+
}
|
|
1535
|
+
get configSchema() {
|
|
1536
|
+
return this.#configSchema;
|
|
1537
|
+
}
|
|
1538
|
+
get handlers() {
|
|
1539
|
+
return {
|
|
1540
|
+
configChanged: this.#configChanged,
|
|
1541
|
+
getDefaultConfig: this.#getDefaultConfig
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1544
|
+
};
|
|
1545
|
+
var config = (schema) => SlateConfig.create(schema);
|
|
1546
|
+
|
|
1547
|
+
// src/context/context.ts
|
|
1548
|
+
var SlateContext = class {
|
|
1549
|
+
constructor(config2, input, auth2, spec2, logger) {
|
|
1550
|
+
this.spec = spec2;
|
|
1551
|
+
this.logger = logger;
|
|
1552
|
+
this.#config = config2;
|
|
1553
|
+
this.#input = input;
|
|
1554
|
+
this.#auth = auth2;
|
|
1555
|
+
}
|
|
1556
|
+
spec;
|
|
1557
|
+
logger;
|
|
1558
|
+
#config;
|
|
1559
|
+
#input;
|
|
1560
|
+
#auth;
|
|
1561
|
+
#httpTraces = [];
|
|
1562
|
+
get specification() {
|
|
1563
|
+
return this.spec;
|
|
1564
|
+
}
|
|
1565
|
+
get config() {
|
|
1566
|
+
return Object.freeze(this.#config);
|
|
1567
|
+
}
|
|
1568
|
+
get input() {
|
|
1569
|
+
return Object.freeze(this.#input);
|
|
1570
|
+
}
|
|
1571
|
+
get event() {
|
|
1572
|
+
return Object.freeze(this.#input);
|
|
1573
|
+
}
|
|
1574
|
+
get state() {
|
|
1575
|
+
return Object.freeze(this.#input.state);
|
|
1576
|
+
}
|
|
1577
|
+
get request() {
|
|
1578
|
+
return Object.freeze(this.#input.request);
|
|
1579
|
+
}
|
|
1580
|
+
get auth() {
|
|
1581
|
+
return Object.freeze(this.#auth);
|
|
1582
|
+
}
|
|
1583
|
+
recordHttpTrace(trace) {
|
|
1584
|
+
this.#httpTraces.push(trace);
|
|
1585
|
+
}
|
|
1586
|
+
getHttpTraces() {
|
|
1587
|
+
return this.#httpTraces.map((trace) => ({
|
|
1588
|
+
...trace,
|
|
1589
|
+
request: {
|
|
1590
|
+
...trace.request,
|
|
1591
|
+
...trace.request.headers ? { headers: { ...trace.request.headers } } : {},
|
|
1592
|
+
...trace.request.body ? { body: { ...trace.request.body } } : {}
|
|
1593
|
+
},
|
|
1594
|
+
...trace.response ? {
|
|
1595
|
+
response: {
|
|
1596
|
+
...trace.response,
|
|
1597
|
+
...trace.response.headers ? { headers: { ...trace.response.headers } } : {},
|
|
1598
|
+
...trace.response.body ? { body: { ...trace.response.body } } : {}
|
|
1599
|
+
}
|
|
1600
|
+
} : {},
|
|
1601
|
+
...trace.error ? { error: { ...trace.error } } : {}
|
|
1602
|
+
}));
|
|
1603
|
+
}
|
|
1604
|
+
info(message) {
|
|
1605
|
+
this.logger.info(message);
|
|
1606
|
+
}
|
|
1607
|
+
warn(message) {
|
|
1608
|
+
this.logger.warn(message);
|
|
1609
|
+
}
|
|
1610
|
+
error(message) {
|
|
1611
|
+
this.logger.error(message);
|
|
1612
|
+
}
|
|
1613
|
+
progress(message) {
|
|
1614
|
+
this.logger.progress(message);
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
|
|
1618
|
+
// src/logger/logger.ts
|
|
1619
|
+
import { encode } from "@toon-format/toon";
|
|
1620
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1621
|
+
var normalizeMessage = (message) => {
|
|
1622
|
+
if (Array.isArray(message)) {
|
|
1623
|
+
let parts = message.map((part) => normalizeMessage(part));
|
|
1624
|
+
let combinedMessage = parts.map((part) => part.message).filter(Boolean).join(" ").trim();
|
|
1625
|
+
let dataParts = parts.map((part) => {
|
|
1626
|
+
if (part.data) {
|
|
1627
|
+
return {
|
|
1628
|
+
message: part.message,
|
|
1629
|
+
...part.data
|
|
1630
|
+
};
|
|
1631
|
+
}
|
|
1632
|
+
return part.message;
|
|
1633
|
+
}).filter(Boolean);
|
|
1634
|
+
return {
|
|
1635
|
+
message: combinedMessage || "Log entry",
|
|
1636
|
+
data: dataParts.length > 0 ? { parts: dataParts } : void 0
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
1639
|
+
if (typeof message === "object") {
|
|
1640
|
+
if (message === null) return { message: "null" };
|
|
1641
|
+
if (message instanceof Error) {
|
|
1642
|
+
return {
|
|
1643
|
+
message: `${message.name}: ${message.message}`,
|
|
1644
|
+
data: {
|
|
1645
|
+
error: {
|
|
1646
|
+
name: message.name,
|
|
1647
|
+
message: message.message,
|
|
1648
|
+
stack: message.stack
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
if (isRecord3(message) && typeof message.message === "string") {
|
|
1654
|
+
let { message: text, ...data } = message;
|
|
1655
|
+
return {
|
|
1656
|
+
message: text || "Log entry",
|
|
1657
|
+
data: Object.keys(data).length > 0 ? data : void 0
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1660
|
+
return {
|
|
1661
|
+
message: encode(message),
|
|
1662
|
+
data: isRecord3(message) ? message : void 0
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1665
|
+
return { message: String(message) };
|
|
1666
|
+
};
|
|
1667
|
+
var SlateLogger = class {
|
|
1668
|
+
#logs = [];
|
|
1669
|
+
#listeners = [];
|
|
1670
|
+
#timer = null;
|
|
1671
|
+
constructor(listeners = []) {
|
|
1672
|
+
this.#listeners.push(...listeners);
|
|
1673
|
+
}
|
|
1674
|
+
flush() {
|
|
1675
|
+
if (this.#timer) clearTimeout(this.#timer);
|
|
1676
|
+
if (this.#logs.length === 0) return;
|
|
1677
|
+
let logs = this.#logs.splice(0);
|
|
1678
|
+
for (let listener of this.#listeners) {
|
|
1679
|
+
listener(logs);
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
scheduleFlush() {
|
|
1683
|
+
if (this.#timer) return;
|
|
1684
|
+
this.#timer = setTimeout(() => {
|
|
1685
|
+
this.flush();
|
|
1686
|
+
this.#timer = null;
|
|
1687
|
+
}, 10);
|
|
1688
|
+
}
|
|
1689
|
+
log(type, message) {
|
|
1690
|
+
let normalized = normalizeMessage(message);
|
|
1691
|
+
this.#logs.push({
|
|
1692
|
+
type,
|
|
1693
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
1694
|
+
message: normalized.message,
|
|
1695
|
+
data: normalized.data
|
|
1696
|
+
});
|
|
1697
|
+
this.scheduleFlush();
|
|
1698
|
+
}
|
|
1699
|
+
info(...message) {
|
|
1700
|
+
this.log("info", message.length === 1 ? message[0] : message.flat());
|
|
1701
|
+
}
|
|
1702
|
+
warn(...message) {
|
|
1703
|
+
this.log("warn", message.length === 1 ? message[0] : message.flat());
|
|
1704
|
+
}
|
|
1705
|
+
error(...message) {
|
|
1706
|
+
this.log("error", message.length === 1 ? message[0] : message.flat());
|
|
1707
|
+
}
|
|
1708
|
+
progress(...message) {
|
|
1709
|
+
this.log("progress", message.length === 1 ? message[0] : message.flat());
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
|
|
1713
|
+
// src/specification/slate.ts
|
|
1714
|
+
var Slate = class _Slate {
|
|
1715
|
+
constructor(_spec, _actions) {
|
|
1716
|
+
this._spec = _spec;
|
|
1717
|
+
this._actions = _actions;
|
|
1718
|
+
}
|
|
1719
|
+
_spec;
|
|
1720
|
+
_actions;
|
|
1721
|
+
static create(params) {
|
|
1722
|
+
return new _Slate(params.spec, [...params.triggers, ...params.tools]);
|
|
1723
|
+
}
|
|
1724
|
+
get spec() {
|
|
1725
|
+
return this._spec;
|
|
1726
|
+
}
|
|
1727
|
+
get actions() {
|
|
1728
|
+
return this._actions;
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1731
|
+
|
|
1732
|
+
// src/specification/specification.ts
|
|
1733
|
+
import z from "zod";
|
|
1734
|
+
var SlateSpecification = class _SlateSpecification {
|
|
1735
|
+
constructor(_config, _auth, _params) {
|
|
1736
|
+
this._config = _config;
|
|
1737
|
+
this._auth = _auth;
|
|
1738
|
+
this._params = _params;
|
|
1739
|
+
}
|
|
1740
|
+
_config;
|
|
1741
|
+
_auth;
|
|
1742
|
+
_params;
|
|
1743
|
+
static create(params) {
|
|
1744
|
+
return new _SlateSpecification(params.config, params.auth, params);
|
|
1745
|
+
}
|
|
1746
|
+
get configSchema() {
|
|
1747
|
+
return this._config.configSchema;
|
|
1748
|
+
}
|
|
1749
|
+
get authSchema() {
|
|
1750
|
+
return "outputSchema" in this._auth ? this._auth.outputSchema : z.object({});
|
|
1751
|
+
}
|
|
1752
|
+
get config() {
|
|
1753
|
+
return this._config;
|
|
1754
|
+
}
|
|
1755
|
+
get auth() {
|
|
1756
|
+
return this._auth;
|
|
1757
|
+
}
|
|
1758
|
+
get parameters() {
|
|
1759
|
+
return this._params;
|
|
1760
|
+
}
|
|
1761
|
+
get key() {
|
|
1762
|
+
return this._params.key;
|
|
1763
|
+
}
|
|
1764
|
+
get name() {
|
|
1765
|
+
return this._params.name;
|
|
1766
|
+
}
|
|
1767
|
+
get description() {
|
|
1768
|
+
return this._params.description;
|
|
1769
|
+
}
|
|
1770
|
+
};
|
|
1771
|
+
var spec = (params) => SlateSpecification.create(params);
|
|
1772
|
+
export {
|
|
1773
|
+
Slate,
|
|
1774
|
+
SlateAction,
|
|
1775
|
+
SlateAuth,
|
|
1776
|
+
SlateConfig,
|
|
1777
|
+
SlateContext,
|
|
1778
|
+
SlateDeclarationError,
|
|
1779
|
+
SlateDefaultPollingIntervalSeconds,
|
|
1780
|
+
SlateError,
|
|
1781
|
+
SlateLogger,
|
|
1782
|
+
SlateSpecification,
|
|
1783
|
+
SlateTool,
|
|
1784
|
+
SlateTrigger,
|
|
1785
|
+
allOf,
|
|
1786
|
+
anyOf,
|
|
1787
|
+
auth,
|
|
1788
|
+
axios,
|
|
1789
|
+
config,
|
|
1790
|
+
createAxios,
|
|
1791
|
+
createBase64Attachment,
|
|
1792
|
+
createSlateError,
|
|
1793
|
+
createTextAttachment,
|
|
1794
|
+
createUrlAttachment,
|
|
1795
|
+
getCurrentContext,
|
|
1796
|
+
getServiceErrorData,
|
|
1797
|
+
inferSlateErrorFromAxios,
|
|
1798
|
+
isAxiosErrorLike,
|
|
1799
|
+
isServiceErrorData,
|
|
1800
|
+
mapServiceErrorCode,
|
|
1801
|
+
mapServiceErrorToSlateErrorInput,
|
|
1802
|
+
mergeScopes,
|
|
1803
|
+
runWithContext,
|
|
1804
|
+
scopeClause,
|
|
1805
|
+
spec,
|
|
1806
|
+
tool,
|
|
1807
|
+
trigger,
|
|
1808
|
+
validateScopes
|
|
1809
|
+
};
|