@slates/proto 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 +1103 -0
- package/dist/index.d.cts +3521 -0
- package/dist/index.d.ts +3521 -0
- package/dist/index.module.js +997 -0
- package/package.json +14 -7
- package/src/handler/provider.test.ts +121 -0
- package/src/handler/provider.ts +268 -27
- package/src/index.ts +1 -0
- package/src/messages/action.ts +26 -7
- package/src/messages/auth.ts +15 -10
- package/src/messages/config.ts +4 -2
- package/src/messages/controlFlow.ts +2 -1
- package/src/messages/identify.ts +3 -2
- package/src/messages/index.ts +15 -18
- package/src/messages/tracing.ts +38 -0
- package/src/types/action.ts +11 -1
- package/src/types/authMethod.ts +11 -2
- package/src/version.ts +3 -0
- package/src/messages/log.ts +0 -29
- package/tsconfig.json +0 -8
|
@@ -0,0 +1,997 @@
|
|
|
1
|
+
// src/handler/provider.ts
|
|
2
|
+
import {
|
|
3
|
+
badRequestError,
|
|
4
|
+
isServiceError,
|
|
5
|
+
notFoundError,
|
|
6
|
+
validationError
|
|
7
|
+
} from "@lowerdeck/error";
|
|
8
|
+
|
|
9
|
+
// src/messages/action.ts
|
|
10
|
+
import z5 from "zod";
|
|
11
|
+
|
|
12
|
+
// src/types/action.ts
|
|
13
|
+
import z from "zod";
|
|
14
|
+
var slatesActionScopeClause = z.object({
|
|
15
|
+
OR: z.array(z.string()).min(1)
|
|
16
|
+
});
|
|
17
|
+
var slatesActionScopes = z.object({
|
|
18
|
+
AND: z.array(slatesActionScopeClause).min(1)
|
|
19
|
+
});
|
|
20
|
+
var slatesActionBase = z.object({
|
|
21
|
+
id: z.string(),
|
|
22
|
+
name: z.string(),
|
|
23
|
+
description: z.string().optional(),
|
|
24
|
+
instructions: z.array(z.string()).optional(),
|
|
25
|
+
constraints: z.array(z.string()).optional(),
|
|
26
|
+
tags: z.object({
|
|
27
|
+
destructive: z.boolean().optional(),
|
|
28
|
+
readOnly: z.boolean().optional()
|
|
29
|
+
}).optional(),
|
|
30
|
+
metadata: z.record(z.string(), z.any()).optional(),
|
|
31
|
+
scopes: slatesActionScopes.optional(),
|
|
32
|
+
inputSchema: z.record(z.string(), z.any()),
|
|
33
|
+
outputSchema: z.record(z.string(), z.any())
|
|
34
|
+
});
|
|
35
|
+
var slatesActionTool = slatesActionBase.extend({
|
|
36
|
+
type: z.literal("action.tool"),
|
|
37
|
+
capabilities: z.object({})
|
|
38
|
+
});
|
|
39
|
+
var slatesActionTrigger = slatesActionBase.extend({
|
|
40
|
+
type: z.literal("action.trigger"),
|
|
41
|
+
capabilities: z.object({}),
|
|
42
|
+
invocation: z.union([
|
|
43
|
+
z.object({
|
|
44
|
+
type: z.literal("polling"),
|
|
45
|
+
intervalSeconds: z.number().min(60 * 10)
|
|
46
|
+
}),
|
|
47
|
+
z.object({
|
|
48
|
+
type: z.literal("webhook"),
|
|
49
|
+
autoRegistration: z.boolean(),
|
|
50
|
+
autoUnregistration: z.boolean()
|
|
51
|
+
})
|
|
52
|
+
])
|
|
53
|
+
});
|
|
54
|
+
var slatesAction = z.union([slatesActionTool, slatesActionTrigger]);
|
|
55
|
+
|
|
56
|
+
// src/types/authMethod.ts
|
|
57
|
+
import z2 from "zod";
|
|
58
|
+
var slatesAuthenticationMethod = z2.object({
|
|
59
|
+
id: z2.string(),
|
|
60
|
+
name: z2.string(),
|
|
61
|
+
type: z2.union([
|
|
62
|
+
z2.literal("auth.oauth"),
|
|
63
|
+
z2.literal("auth.token"),
|
|
64
|
+
z2.literal("auth.service_account"),
|
|
65
|
+
z2.literal("auth.custom")
|
|
66
|
+
]),
|
|
67
|
+
scopes: z2.array(
|
|
68
|
+
z2.object({
|
|
69
|
+
id: z2.string(),
|
|
70
|
+
title: z2.string(),
|
|
71
|
+
description: z2.string().optional(),
|
|
72
|
+
defaultChecked: z2.boolean().optional()
|
|
73
|
+
})
|
|
74
|
+
).optional(),
|
|
75
|
+
inputSchema: z2.record(z2.string(), z2.any()),
|
|
76
|
+
outputSchema: z2.record(z2.string(), z2.any()),
|
|
77
|
+
capabilities: z2.object({
|
|
78
|
+
getDefaultInput: z2.object({ enabled: z2.boolean() }).optional(),
|
|
79
|
+
handleChangedInput: z2.object({ enabled: z2.boolean() }).optional(),
|
|
80
|
+
handleTokenRefresh: z2.object({ enabled: z2.boolean() }).optional(),
|
|
81
|
+
getProfile: z2.object({ enabled: z2.boolean() }).optional()
|
|
82
|
+
}),
|
|
83
|
+
docs: z2.object({
|
|
84
|
+
oauthDocsLink: z2.string().optional(),
|
|
85
|
+
oauthScopesLink: z2.string().optional(),
|
|
86
|
+
tokenDocsLink: z2.string().optional(),
|
|
87
|
+
serviceAccountDocsLink: z2.string().optional(),
|
|
88
|
+
customAuthDocsLink: z2.string().optional()
|
|
89
|
+
}).optional()
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// src/types/participant.ts
|
|
93
|
+
import z3 from "zod";
|
|
94
|
+
var slatesParticipant = z3.object({
|
|
95
|
+
type: z3.union([z3.literal("consumer"), z3.literal("hub")]),
|
|
96
|
+
id: z3.string(),
|
|
97
|
+
name: z3.string(),
|
|
98
|
+
description: z3.string().optional(),
|
|
99
|
+
metadata: z3.record(z3.string(), z3.any()).optional()
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// src/messages/tracing.ts
|
|
103
|
+
import z4 from "zod";
|
|
104
|
+
var slatesRequestTraceTextBody = z4.object({
|
|
105
|
+
contentType: z4.string().optional(),
|
|
106
|
+
text: z4.string(),
|
|
107
|
+
truncated: z4.boolean().optional()
|
|
108
|
+
});
|
|
109
|
+
var slatesRequestTrace = z4.object({
|
|
110
|
+
startedAt: z4.string(),
|
|
111
|
+
durationMs: z4.number().nonnegative(),
|
|
112
|
+
request: z4.object({
|
|
113
|
+
method: z4.string(),
|
|
114
|
+
url: z4.string(),
|
|
115
|
+
headers: z4.record(z4.string(), z4.string()).optional(),
|
|
116
|
+
body: slatesRequestTraceTextBody.optional()
|
|
117
|
+
}),
|
|
118
|
+
response: z4.object({
|
|
119
|
+
status: z4.number(),
|
|
120
|
+
statusText: z4.string().optional(),
|
|
121
|
+
headers: z4.record(z4.string(), z4.string()).optional(),
|
|
122
|
+
body: slatesRequestTraceTextBody.optional()
|
|
123
|
+
}).optional(),
|
|
124
|
+
error: z4.object({
|
|
125
|
+
code: z4.string().optional(),
|
|
126
|
+
message: z4.string()
|
|
127
|
+
}).optional()
|
|
128
|
+
});
|
|
129
|
+
var withRequestTraces = (shape) => z4.object({
|
|
130
|
+
...shape,
|
|
131
|
+
requestTraces: z4.array(slatesRequestTrace).optional()
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// src/messages/action.ts
|
|
135
|
+
var slatesMessageActionsListRequest = z5.object({
|
|
136
|
+
jsonrpc: z5.literal("2.0"),
|
|
137
|
+
method: z5.literal("slates/actions.list"),
|
|
138
|
+
id: z5.string(),
|
|
139
|
+
params: z5.object({})
|
|
140
|
+
});
|
|
141
|
+
var slatesMessageActionsListResponse = z5.object({
|
|
142
|
+
jsonrpc: z5.literal("2.0"),
|
|
143
|
+
id: z5.string(),
|
|
144
|
+
result: z5.object({
|
|
145
|
+
actions: z5.array(slatesAction)
|
|
146
|
+
})
|
|
147
|
+
});
|
|
148
|
+
var slatesMessageActionGetRequest = z5.object({
|
|
149
|
+
jsonrpc: z5.literal("2.0"),
|
|
150
|
+
method: z5.literal("slates/action.get"),
|
|
151
|
+
id: z5.string(),
|
|
152
|
+
params: z5.object({
|
|
153
|
+
actionId: z5.string()
|
|
154
|
+
})
|
|
155
|
+
});
|
|
156
|
+
var slatesMessageActionGetResponse = z5.object({
|
|
157
|
+
jsonrpc: z5.literal("2.0"),
|
|
158
|
+
id: z5.string(),
|
|
159
|
+
result: z5.object({
|
|
160
|
+
action: slatesAction
|
|
161
|
+
})
|
|
162
|
+
});
|
|
163
|
+
var slatesMessageActionInvokeRequest = z5.object({
|
|
164
|
+
jsonrpc: z5.literal("2.0"),
|
|
165
|
+
method: z5.literal("slates/action.tool.invoke"),
|
|
166
|
+
id: z5.string(),
|
|
167
|
+
params: z5.object({
|
|
168
|
+
actionId: z5.string(),
|
|
169
|
+
input: z5.record(z5.string(), z5.any())
|
|
170
|
+
})
|
|
171
|
+
});
|
|
172
|
+
var slatesMessageActionInvokeResponse = z5.object({
|
|
173
|
+
jsonrpc: z5.literal("2.0"),
|
|
174
|
+
id: z5.string(),
|
|
175
|
+
result: withRequestTraces({
|
|
176
|
+
output: z5.record(z5.string(), z5.any()),
|
|
177
|
+
message: z5.string().optional(),
|
|
178
|
+
attachments: z5.array(
|
|
179
|
+
z5.object({
|
|
180
|
+
mimeType: z5.string().optional(),
|
|
181
|
+
content: z5.union([
|
|
182
|
+
z5.object({
|
|
183
|
+
type: z5.literal("url"),
|
|
184
|
+
url: z5.string()
|
|
185
|
+
}),
|
|
186
|
+
z5.object({
|
|
187
|
+
type: z5.literal("content"),
|
|
188
|
+
encoding: z5.union([z5.literal("base64"), z5.literal("utf-8")]),
|
|
189
|
+
content: z5.string()
|
|
190
|
+
})
|
|
191
|
+
])
|
|
192
|
+
})
|
|
193
|
+
).optional()
|
|
194
|
+
})
|
|
195
|
+
});
|
|
196
|
+
var slatesMessageActionTriggerEventMapRequest = z5.object({
|
|
197
|
+
jsonrpc: z5.literal("2.0"),
|
|
198
|
+
method: z5.literal("slates/action.trigger.map_event"),
|
|
199
|
+
id: z5.string(),
|
|
200
|
+
params: z5.object({
|
|
201
|
+
actionId: z5.string(),
|
|
202
|
+
input: z5.record(z5.string(), z5.any())
|
|
203
|
+
})
|
|
204
|
+
});
|
|
205
|
+
var slatesMessageActionTriggerEventMapResponse = z5.object({
|
|
206
|
+
jsonrpc: z5.literal("2.0"),
|
|
207
|
+
id: z5.string(),
|
|
208
|
+
result: withRequestTraces({
|
|
209
|
+
type: z5.string(),
|
|
210
|
+
id: z5.string(),
|
|
211
|
+
output: z5.record(z5.string(), z5.any())
|
|
212
|
+
})
|
|
213
|
+
});
|
|
214
|
+
var slatesMessageActionTriggerEventsPollRequest = z5.object({
|
|
215
|
+
jsonrpc: z5.literal("2.0"),
|
|
216
|
+
method: z5.literal("slates/action.trigger.poll_events"),
|
|
217
|
+
id: z5.string(),
|
|
218
|
+
params: z5.object({
|
|
219
|
+
actionId: z5.string(),
|
|
220
|
+
state: z5.any().nullable()
|
|
221
|
+
})
|
|
222
|
+
});
|
|
223
|
+
var slatesMessageActionTriggerEventsPollResponse = z5.object({
|
|
224
|
+
jsonrpc: z5.literal("2.0"),
|
|
225
|
+
id: z5.string(),
|
|
226
|
+
result: withRequestTraces({
|
|
227
|
+
inputs: z5.array(z5.record(z5.string(), z5.any())),
|
|
228
|
+
updatedState: z5.any().nullable().optional()
|
|
229
|
+
})
|
|
230
|
+
});
|
|
231
|
+
var slatesMessageActionTriggerWebhookHandleRequest = z5.object({
|
|
232
|
+
jsonrpc: z5.literal("2.0"),
|
|
233
|
+
method: z5.literal("slates/action.trigger.webhook_handle"),
|
|
234
|
+
id: z5.string(),
|
|
235
|
+
params: z5.object({
|
|
236
|
+
actionId: z5.string(),
|
|
237
|
+
url: z5.string(),
|
|
238
|
+
method: z5.string(),
|
|
239
|
+
headers: z5.record(z5.string(), z5.string()),
|
|
240
|
+
body: z5.object({
|
|
241
|
+
encoding: z5.literal("base64"),
|
|
242
|
+
content: z5.string()
|
|
243
|
+
}).nullable(),
|
|
244
|
+
state: z5.any().nullable()
|
|
245
|
+
})
|
|
246
|
+
});
|
|
247
|
+
var slatesMessageActionTriggerWebhookHandleResponse = z5.object({
|
|
248
|
+
jsonrpc: z5.literal("2.0"),
|
|
249
|
+
id: z5.string(),
|
|
250
|
+
result: withRequestTraces({
|
|
251
|
+
inputs: z5.array(z5.record(z5.string(), z5.any())),
|
|
252
|
+
updatedState: z5.any().nullable().optional()
|
|
253
|
+
})
|
|
254
|
+
});
|
|
255
|
+
var slatesMessageActionTriggerWebhookRegisterRequest = z5.object({
|
|
256
|
+
jsonrpc: z5.literal("2.0"),
|
|
257
|
+
method: z5.literal("slates/action.trigger.webhook_register"),
|
|
258
|
+
id: z5.string(),
|
|
259
|
+
params: z5.object({
|
|
260
|
+
actionId: z5.string(),
|
|
261
|
+
webhookBaseUrl: z5.string()
|
|
262
|
+
})
|
|
263
|
+
});
|
|
264
|
+
var slatesMessageActionTriggerWebhookRegisterResponse = z5.object({
|
|
265
|
+
jsonrpc: z5.literal("2.0"),
|
|
266
|
+
id: z5.string(),
|
|
267
|
+
result: withRequestTraces({
|
|
268
|
+
registrationDetails: z5.any(),
|
|
269
|
+
state: z5.any().optional()
|
|
270
|
+
})
|
|
271
|
+
});
|
|
272
|
+
var slatesMessageActionTriggerWebhookUnregisterRequest = z5.object({
|
|
273
|
+
jsonrpc: z5.literal("2.0"),
|
|
274
|
+
method: z5.literal("slates/action.trigger.webhook_unregister"),
|
|
275
|
+
id: z5.string(),
|
|
276
|
+
params: z5.object({
|
|
277
|
+
actionId: z5.string(),
|
|
278
|
+
webhookBaseUrl: z5.string(),
|
|
279
|
+
registrationDetails: z5.any(),
|
|
280
|
+
state: z5.any().optional()
|
|
281
|
+
})
|
|
282
|
+
});
|
|
283
|
+
var slatesMessageActionTriggerWebhookUnregisterResponse = z5.object({
|
|
284
|
+
jsonrpc: z5.literal("2.0"),
|
|
285
|
+
id: z5.string(),
|
|
286
|
+
result: withRequestTraces({})
|
|
287
|
+
});
|
|
288
|
+
var slatesActionResponsesByMethod = {
|
|
289
|
+
"slates/actions.list": slatesMessageActionsListResponse,
|
|
290
|
+
"slates/action.get": slatesMessageActionGetResponse,
|
|
291
|
+
"slates/action.tool.invoke": slatesMessageActionInvokeResponse,
|
|
292
|
+
"slates/action.trigger.map_event": slatesMessageActionTriggerEventMapResponse,
|
|
293
|
+
"slates/action.trigger.poll_events": slatesMessageActionTriggerEventsPollResponse,
|
|
294
|
+
"slates/action.trigger.webhook_handle": slatesMessageActionTriggerWebhookHandleResponse,
|
|
295
|
+
"slates/action.trigger.webhook_register": slatesMessageActionTriggerWebhookRegisterResponse,
|
|
296
|
+
"slates/action.trigger.webhook_unregister": slatesMessageActionTriggerWebhookUnregisterResponse
|
|
297
|
+
};
|
|
298
|
+
var slatesActionRequestsByMethod = {
|
|
299
|
+
"slates/actions.list": slatesMessageActionsListRequest,
|
|
300
|
+
"slates/action.get": slatesMessageActionGetRequest,
|
|
301
|
+
"slates/action.tool.invoke": slatesMessageActionInvokeRequest,
|
|
302
|
+
"slates/action.trigger.map_event": slatesMessageActionTriggerEventMapRequest,
|
|
303
|
+
"slates/action.trigger.poll_events": slatesMessageActionTriggerEventsPollRequest,
|
|
304
|
+
"slates/action.trigger.webhook_handle": slatesMessageActionTriggerWebhookHandleRequest,
|
|
305
|
+
"slates/action.trigger.webhook_register": slatesMessageActionTriggerWebhookRegisterRequest,
|
|
306
|
+
"slates/action.trigger.webhook_unregister": slatesMessageActionTriggerWebhookUnregisterRequest
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// src/messages/auth.ts
|
|
310
|
+
import z6 from "zod";
|
|
311
|
+
var slatesMessageSetAuthNotification = z6.object({
|
|
312
|
+
jsonrpc: z6.literal("2.0"),
|
|
313
|
+
method: z6.literal("slates/auth.set"),
|
|
314
|
+
params: z6.object({
|
|
315
|
+
authenticationMethodId: z6.string(),
|
|
316
|
+
output: z6.record(z6.string(), z6.any())
|
|
317
|
+
})
|
|
318
|
+
});
|
|
319
|
+
var slatesMessageAuthMethodsListRequest = z6.object({
|
|
320
|
+
jsonrpc: z6.literal("2.0"),
|
|
321
|
+
method: z6.literal("slates/auth.methods.list"),
|
|
322
|
+
id: z6.string(),
|
|
323
|
+
params: z6.object({})
|
|
324
|
+
});
|
|
325
|
+
var slatesMessageAuthMethodsListResponse = z6.object({
|
|
326
|
+
jsonrpc: z6.literal("2.0"),
|
|
327
|
+
id: z6.string(),
|
|
328
|
+
result: z6.object({
|
|
329
|
+
authenticationMethods: z6.array(slatesAuthenticationMethod)
|
|
330
|
+
})
|
|
331
|
+
});
|
|
332
|
+
var slatesMessageAuthMethodGetRequest = z6.object({
|
|
333
|
+
jsonrpc: z6.literal("2.0"),
|
|
334
|
+
method: z6.literal("slates/auth.method.get"),
|
|
335
|
+
id: z6.string(),
|
|
336
|
+
params: z6.object({
|
|
337
|
+
authenticationMethodId: z6.string()
|
|
338
|
+
})
|
|
339
|
+
});
|
|
340
|
+
var slatesMessageAuthMethodGetResponse = z6.object({
|
|
341
|
+
jsonrpc: z6.literal("2.0"),
|
|
342
|
+
id: z6.string(),
|
|
343
|
+
result: z6.object({
|
|
344
|
+
authenticationMethod: slatesAuthenticationMethod
|
|
345
|
+
})
|
|
346
|
+
});
|
|
347
|
+
var slatesMessageAuthInputChangedRequest = z6.object({
|
|
348
|
+
jsonrpc: z6.literal("2.0"),
|
|
349
|
+
method: z6.literal("slates/auth.input.changed"),
|
|
350
|
+
id: z6.string(),
|
|
351
|
+
params: z6.object({
|
|
352
|
+
authenticationMethodId: z6.string(),
|
|
353
|
+
previousInput: z6.record(z6.string(), z6.any()).nullable(),
|
|
354
|
+
newInput: z6.record(z6.string(), z6.any())
|
|
355
|
+
})
|
|
356
|
+
});
|
|
357
|
+
var slatesMessageAuthInputChangedResponse = z6.object({
|
|
358
|
+
jsonrpc: z6.literal("2.0"),
|
|
359
|
+
id: z6.string(),
|
|
360
|
+
result: withRequestTraces({
|
|
361
|
+
input: z6.record(z6.string(), z6.any()).optional()
|
|
362
|
+
})
|
|
363
|
+
});
|
|
364
|
+
var slatesMessageAuthDefaultInputGetRequest = z6.object({
|
|
365
|
+
jsonrpc: z6.literal("2.0"),
|
|
366
|
+
method: z6.literal("slates/auth.input.get_default"),
|
|
367
|
+
id: z6.string(),
|
|
368
|
+
params: z6.object({
|
|
369
|
+
authenticationMethodId: z6.string()
|
|
370
|
+
})
|
|
371
|
+
});
|
|
372
|
+
var slatesMessageAuthDefaultInputGetResponse = z6.object({
|
|
373
|
+
jsonrpc: z6.literal("2.0"),
|
|
374
|
+
id: z6.string(),
|
|
375
|
+
result: withRequestTraces({
|
|
376
|
+
input: z6.record(z6.string(), z6.any())
|
|
377
|
+
})
|
|
378
|
+
});
|
|
379
|
+
var slatesMessageAuthAuthorizationUrlGetRequest = z6.object({
|
|
380
|
+
jsonrpc: z6.literal("2.0"),
|
|
381
|
+
method: z6.literal("slates/auth.authorization_url.get"),
|
|
382
|
+
id: z6.string(),
|
|
383
|
+
params: z6.object({
|
|
384
|
+
authenticationMethodId: z6.string(),
|
|
385
|
+
redirectUri: z6.string(),
|
|
386
|
+
state: z6.string(),
|
|
387
|
+
input: z6.record(z6.string(), z6.any()),
|
|
388
|
+
clientId: z6.string(),
|
|
389
|
+
clientSecret: z6.string(),
|
|
390
|
+
scopes: z6.array(z6.string())
|
|
391
|
+
})
|
|
392
|
+
});
|
|
393
|
+
var slatesMessageAuthAuthorizationUrlGetResponse = z6.object({
|
|
394
|
+
jsonrpc: z6.literal("2.0"),
|
|
395
|
+
id: z6.string(),
|
|
396
|
+
result: withRequestTraces({
|
|
397
|
+
authorizationUrl: z6.string(),
|
|
398
|
+
input: z6.record(z6.string(), z6.any()).optional(),
|
|
399
|
+
callbackState: z6.record(z6.string(), z6.any()).optional()
|
|
400
|
+
})
|
|
401
|
+
});
|
|
402
|
+
var slatesMessageAuthAuthorizationCallbackHandleRequest = z6.object({
|
|
403
|
+
jsonrpc: z6.literal("2.0"),
|
|
404
|
+
method: z6.literal("slates/auth.authorization_callback.handle"),
|
|
405
|
+
id: z6.string(),
|
|
406
|
+
params: z6.object({
|
|
407
|
+
authenticationMethodId: z6.string(),
|
|
408
|
+
code: z6.string(),
|
|
409
|
+
state: z6.string(),
|
|
410
|
+
redirectUri: z6.string(),
|
|
411
|
+
input: z6.record(z6.string(), z6.any()),
|
|
412
|
+
clientId: z6.string(),
|
|
413
|
+
clientSecret: z6.string(),
|
|
414
|
+
scopes: z6.array(z6.string()),
|
|
415
|
+
callbackParams: z6.record(z6.string(), z6.string()).optional(),
|
|
416
|
+
callbackState: z6.record(z6.string(), z6.any()).optional()
|
|
417
|
+
})
|
|
418
|
+
});
|
|
419
|
+
var slatesMessageAuthAuthorizationCallbackHandleResponse = z6.object({
|
|
420
|
+
jsonrpc: z6.literal("2.0"),
|
|
421
|
+
id: z6.string(),
|
|
422
|
+
result: withRequestTraces({
|
|
423
|
+
output: z6.record(z6.string(), z6.any()),
|
|
424
|
+
input: z6.record(z6.string(), z6.any()).optional(),
|
|
425
|
+
scopes: z6.array(z6.string()).optional()
|
|
426
|
+
})
|
|
427
|
+
});
|
|
428
|
+
var slatesMessageAuthTokenRefreshHandleRequest = z6.object({
|
|
429
|
+
jsonrpc: z6.literal("2.0"),
|
|
430
|
+
method: z6.literal("slates/auth.token_refresh.handle"),
|
|
431
|
+
id: z6.string(),
|
|
432
|
+
params: z6.object({
|
|
433
|
+
authenticationMethodId: z6.string(),
|
|
434
|
+
output: z6.record(z6.string(), z6.any()),
|
|
435
|
+
input: z6.record(z6.string(), z6.any()),
|
|
436
|
+
clientId: z6.string(),
|
|
437
|
+
clientSecret: z6.string(),
|
|
438
|
+
scopes: z6.array(z6.string())
|
|
439
|
+
})
|
|
440
|
+
});
|
|
441
|
+
var slatesMessageAuthTokenRefreshHandleResponse = z6.object({
|
|
442
|
+
jsonrpc: z6.literal("2.0"),
|
|
443
|
+
id: z6.string(),
|
|
444
|
+
result: withRequestTraces({
|
|
445
|
+
output: z6.record(z6.string(), z6.any()),
|
|
446
|
+
input: z6.record(z6.string(), z6.any()).optional()
|
|
447
|
+
})
|
|
448
|
+
});
|
|
449
|
+
var slatesMessageAuthProfileGetRequest = z6.object({
|
|
450
|
+
jsonrpc: z6.literal("2.0"),
|
|
451
|
+
method: z6.literal("slates/auth.profile.get"),
|
|
452
|
+
id: z6.string(),
|
|
453
|
+
params: z6.object({
|
|
454
|
+
authenticationMethodId: z6.string(),
|
|
455
|
+
output: z6.record(z6.string(), z6.any()),
|
|
456
|
+
input: z6.record(z6.string(), z6.any()),
|
|
457
|
+
scopes: z6.array(z6.string())
|
|
458
|
+
})
|
|
459
|
+
});
|
|
460
|
+
var slatesMessageAuthProfileGetResponse = z6.object({
|
|
461
|
+
jsonrpc: z6.literal("2.0"),
|
|
462
|
+
id: z6.string(),
|
|
463
|
+
result: withRequestTraces({
|
|
464
|
+
profile: z6.record(z6.string(), z6.any())
|
|
465
|
+
})
|
|
466
|
+
});
|
|
467
|
+
var slatesMessageAuthOutputGetRequest = z6.object({
|
|
468
|
+
jsonrpc: z6.literal("2.0"),
|
|
469
|
+
method: z6.literal("slates/auth.output.get"),
|
|
470
|
+
id: z6.string(),
|
|
471
|
+
params: z6.object({
|
|
472
|
+
authenticationMethodId: z6.string(),
|
|
473
|
+
input: z6.record(z6.string(), z6.any())
|
|
474
|
+
})
|
|
475
|
+
});
|
|
476
|
+
var slatesMessageAuthOutputGetResponse = z6.object({
|
|
477
|
+
jsonrpc: z6.literal("2.0"),
|
|
478
|
+
id: z6.string(),
|
|
479
|
+
result: withRequestTraces({
|
|
480
|
+
output: z6.record(z6.string(), z6.any())
|
|
481
|
+
})
|
|
482
|
+
});
|
|
483
|
+
var slatesAuthResponsesByMethod = {
|
|
484
|
+
"slates/auth.methods.list": slatesMessageAuthMethodsListResponse,
|
|
485
|
+
"slates/auth.method.get": slatesMessageAuthMethodGetResponse,
|
|
486
|
+
"slates/auth.input.changed": slatesMessageAuthInputChangedResponse,
|
|
487
|
+
"slates/auth.input.get_default": slatesMessageAuthDefaultInputGetResponse,
|
|
488
|
+
"slates/auth.authorization_url.get": slatesMessageAuthAuthorizationUrlGetResponse,
|
|
489
|
+
"slates/auth.authorization_callback.handle": slatesMessageAuthAuthorizationCallbackHandleResponse,
|
|
490
|
+
"slates/auth.token_refresh.handle": slatesMessageAuthTokenRefreshHandleResponse,
|
|
491
|
+
"slates/auth.profile.get": slatesMessageAuthProfileGetResponse,
|
|
492
|
+
"slates/auth.output.get": slatesMessageAuthOutputGetResponse
|
|
493
|
+
};
|
|
494
|
+
var slatesAuthRequestsByMethod = {
|
|
495
|
+
"slates/auth.methods.list": slatesMessageAuthMethodsListRequest,
|
|
496
|
+
"slates/auth.method.get": slatesMessageAuthMethodGetRequest,
|
|
497
|
+
"slates/auth.input.changed": slatesMessageAuthInputChangedRequest,
|
|
498
|
+
"slates/auth.input.get_default": slatesMessageAuthDefaultInputGetRequest,
|
|
499
|
+
"slates/auth.authorization_url.get": slatesMessageAuthAuthorizationUrlGetRequest,
|
|
500
|
+
"slates/auth.authorization_callback.handle": slatesMessageAuthAuthorizationCallbackHandleRequest,
|
|
501
|
+
"slates/auth.token_refresh.handle": slatesMessageAuthTokenRefreshHandleRequest,
|
|
502
|
+
"slates/auth.profile.get": slatesMessageAuthProfileGetRequest,
|
|
503
|
+
"slates/auth.output.get": slatesMessageAuthOutputGetRequest
|
|
504
|
+
};
|
|
505
|
+
var slatesAuthNotificationsByMethod = {
|
|
506
|
+
"slates/auth.set": slatesMessageSetAuthNotification
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
// src/messages/config.ts
|
|
510
|
+
import z7 from "zod";
|
|
511
|
+
var slatesMessageSetConfigNotification = z7.object({
|
|
512
|
+
jsonrpc: z7.literal("2.0"),
|
|
513
|
+
method: z7.literal("slates/config.set"),
|
|
514
|
+
params: z7.object({
|
|
515
|
+
config: z7.record(z7.string(), z7.any())
|
|
516
|
+
})
|
|
517
|
+
});
|
|
518
|
+
var slatesMessageConfigSchemaGetRequest = z7.object({
|
|
519
|
+
jsonrpc: z7.literal("2.0"),
|
|
520
|
+
method: z7.literal("slates/config.schema.get"),
|
|
521
|
+
id: z7.string(),
|
|
522
|
+
params: z7.object({})
|
|
523
|
+
});
|
|
524
|
+
var slatesMessageConfigSchemaGetResponse = z7.object({
|
|
525
|
+
jsonrpc: z7.literal("2.0"),
|
|
526
|
+
id: z7.string(),
|
|
527
|
+
result: z7.object({
|
|
528
|
+
schema: z7.record(z7.string(), z7.any())
|
|
529
|
+
})
|
|
530
|
+
});
|
|
531
|
+
var slatesMessageConfigChangedRequest = z7.object({
|
|
532
|
+
jsonrpc: z7.literal("2.0"),
|
|
533
|
+
method: z7.literal("slates/config.changed"),
|
|
534
|
+
id: z7.string(),
|
|
535
|
+
params: z7.object({
|
|
536
|
+
previousConfig: z7.record(z7.string(), z7.any()).nullable(),
|
|
537
|
+
newConfig: z7.record(z7.string(), z7.any())
|
|
538
|
+
})
|
|
539
|
+
});
|
|
540
|
+
var slatesMessageConfigChangedResponse = z7.object({
|
|
541
|
+
jsonrpc: z7.literal("2.0"),
|
|
542
|
+
id: z7.string(),
|
|
543
|
+
result: withRequestTraces({
|
|
544
|
+
success: z7.boolean(),
|
|
545
|
+
config: z7.record(z7.string(), z7.any()).optional(),
|
|
546
|
+
errors: z7.array(
|
|
547
|
+
z7.object({
|
|
548
|
+
code: z7.string(),
|
|
549
|
+
message: z7.string(),
|
|
550
|
+
path: z7.array(z7.string()).optional()
|
|
551
|
+
})
|
|
552
|
+
).optional()
|
|
553
|
+
})
|
|
554
|
+
});
|
|
555
|
+
var slatesMessageConfigDefaultGetRequest = z7.object({
|
|
556
|
+
jsonrpc: z7.literal("2.0"),
|
|
557
|
+
method: z7.literal("slates/config.get_default"),
|
|
558
|
+
id: z7.string(),
|
|
559
|
+
params: z7.object({})
|
|
560
|
+
});
|
|
561
|
+
var slatesMessageConfigDefaultGetResponse = z7.object({
|
|
562
|
+
jsonrpc: z7.literal("2.0"),
|
|
563
|
+
id: z7.string(),
|
|
564
|
+
result: withRequestTraces({
|
|
565
|
+
config: z7.record(z7.string(), z7.any()).nullable()
|
|
566
|
+
})
|
|
567
|
+
});
|
|
568
|
+
var slatesConfigResponsesByMethod = {
|
|
569
|
+
"slates/config.schema.get": slatesMessageConfigSchemaGetResponse,
|
|
570
|
+
"slates/config.get_default": slatesMessageConfigDefaultGetResponse,
|
|
571
|
+
"slates/config.changed": slatesMessageConfigChangedResponse
|
|
572
|
+
};
|
|
573
|
+
var slatesConfigRequestsByMethod = {
|
|
574
|
+
"slates/config.schema.get": slatesMessageConfigSchemaGetRequest,
|
|
575
|
+
"slates/config.get_default": slatesMessageConfigDefaultGetRequest,
|
|
576
|
+
"slates/config.changed": slatesMessageConfigChangedRequest
|
|
577
|
+
};
|
|
578
|
+
var slatesConfigNotificationsByMethod = {
|
|
579
|
+
"slates/config.set": slatesMessageSetConfigNotification
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
// src/messages/controlFlow.ts
|
|
583
|
+
import z8 from "zod";
|
|
584
|
+
|
|
585
|
+
// src/version.ts
|
|
586
|
+
var SLATES_PROTOCOL_VERSION = "slates@2026-01-01";
|
|
587
|
+
|
|
588
|
+
// src/messages/controlFlow.ts
|
|
589
|
+
var slatesMessageHelloNotification = z8.object({
|
|
590
|
+
jsonrpc: z8.literal("2.0"),
|
|
591
|
+
method: z8.literal("slates/hello"),
|
|
592
|
+
params: z8.object({
|
|
593
|
+
protocol: z8.literal(SLATES_PROTOCOL_VERSION)
|
|
594
|
+
})
|
|
595
|
+
});
|
|
596
|
+
var slatesMessageSetParticipantsNotification = z8.object({
|
|
597
|
+
jsonrpc: z8.literal("2.0"),
|
|
598
|
+
method: z8.literal("slates/participant.set"),
|
|
599
|
+
params: z8.object({
|
|
600
|
+
participants: z8.array(slatesParticipant)
|
|
601
|
+
})
|
|
602
|
+
});
|
|
603
|
+
var slatesMessageSessionStartNotification = z8.object({
|
|
604
|
+
jsonrpc: z8.literal("2.0"),
|
|
605
|
+
method: z8.literal("slates/session.start"),
|
|
606
|
+
params: z8.object({
|
|
607
|
+
sessionId: z8.string(),
|
|
608
|
+
state: z8.record(z8.string(), z8.any())
|
|
609
|
+
})
|
|
610
|
+
});
|
|
611
|
+
var slatesControlFlowNotificationsByMethod = {
|
|
612
|
+
"slates/hello": slatesMessageHelloNotification,
|
|
613
|
+
"slates/participant.set": slatesMessageSetParticipantsNotification,
|
|
614
|
+
"slates/session.start": slatesMessageSessionStartNotification
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
// src/messages/identify.ts
|
|
618
|
+
import z9 from "zod";
|
|
619
|
+
var slatesMessageProviderIdentifyRequest = z9.object({
|
|
620
|
+
jsonrpc: z9.literal("2.0"),
|
|
621
|
+
method: z9.literal("slates/provider.identify"),
|
|
622
|
+
id: z9.string(),
|
|
623
|
+
params: z9.object({})
|
|
624
|
+
});
|
|
625
|
+
var slatesMessageProviderIdentifyResponse = z9.object({
|
|
626
|
+
jsonrpc: z9.literal("2.0"),
|
|
627
|
+
id: z9.string(),
|
|
628
|
+
result: z9.object({
|
|
629
|
+
protocol: z9.literal(SLATES_PROTOCOL_VERSION),
|
|
630
|
+
provider: z9.object({
|
|
631
|
+
type: z9.literal("provider"),
|
|
632
|
+
id: z9.string(),
|
|
633
|
+
name: z9.string(),
|
|
634
|
+
description: z9.string().optional(),
|
|
635
|
+
metadata: z9.record(z9.string(), z9.any()).optional()
|
|
636
|
+
})
|
|
637
|
+
})
|
|
638
|
+
});
|
|
639
|
+
var slatesIdentifyResponsesByMethod = {
|
|
640
|
+
"slates/provider.identify": slatesMessageProviderIdentifyResponse
|
|
641
|
+
};
|
|
642
|
+
var slatesIdentifyRequestsByMethod = {
|
|
643
|
+
"slates/provider.identify": slatesMessageProviderIdentifyRequest
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// src/messages/index.ts
|
|
647
|
+
var slatesResponsesByMethod = {
|
|
648
|
+
...slatesActionResponsesByMethod,
|
|
649
|
+
...slatesAuthResponsesByMethod,
|
|
650
|
+
...slatesConfigResponsesByMethod,
|
|
651
|
+
...slatesIdentifyResponsesByMethod
|
|
652
|
+
};
|
|
653
|
+
var slatesRequestsByMethod = {
|
|
654
|
+
...slatesActionRequestsByMethod,
|
|
655
|
+
...slatesAuthRequestsByMethod,
|
|
656
|
+
...slatesConfigRequestsByMethod,
|
|
657
|
+
...slatesIdentifyRequestsByMethod
|
|
658
|
+
};
|
|
659
|
+
var slatesNotificationsByMethod = {
|
|
660
|
+
...slatesAuthNotificationsByMethod,
|
|
661
|
+
...slatesConfigNotificationsByMethod,
|
|
662
|
+
...slatesControlFlowNotificationsByMethod
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
// src/handler/provider.ts
|
|
666
|
+
var SlatesProviderProtoHandlerManager = class {
|
|
667
|
+
#implMap = /* @__PURE__ */ new Map();
|
|
668
|
+
onNotification(method, handler) {
|
|
669
|
+
let schema = slatesNotificationsByMethod[method];
|
|
670
|
+
if (!schema) {
|
|
671
|
+
throw new Error(`No schema found for method: ${method}`);
|
|
672
|
+
}
|
|
673
|
+
this.#implMap.set(method, {
|
|
674
|
+
type: "notification",
|
|
675
|
+
handler,
|
|
676
|
+
schema
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
onRequest(method, cb) {
|
|
680
|
+
let schema = slatesRequestsByMethod[method];
|
|
681
|
+
if (!schema) {
|
|
682
|
+
throw new Error(`No schema found for method: ${method}`);
|
|
683
|
+
}
|
|
684
|
+
this.#implMap.set(method, {
|
|
685
|
+
type: "request",
|
|
686
|
+
handler: cb,
|
|
687
|
+
schema
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
async _handleInput(input) {
|
|
691
|
+
try {
|
|
692
|
+
if (typeof input !== "object" || input === null) {
|
|
693
|
+
return {
|
|
694
|
+
jsonrpc: "2.0",
|
|
695
|
+
id: input.id,
|
|
696
|
+
error: toSlateErrorResponse(badRequestError({ message: "Invalid input" }))
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
if (input.jsonrpc !== "2.0") {
|
|
700
|
+
return {
|
|
701
|
+
jsonrpc: "2.0",
|
|
702
|
+
id: input.id,
|
|
703
|
+
error: toSlateErrorResponse(badRequestError({ message: "Invalid jsonrpc version" }))
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
let method = input.method;
|
|
707
|
+
if (typeof method !== "string") {
|
|
708
|
+
return {
|
|
709
|
+
jsonrpc: "2.0",
|
|
710
|
+
id: input.id,
|
|
711
|
+
error: toSlateErrorResponse(
|
|
712
|
+
badRequestError({ message: "Invalid or missing method" })
|
|
713
|
+
)
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
let impl = this.#implMap.get(input.method);
|
|
717
|
+
if (!impl) {
|
|
718
|
+
return {
|
|
719
|
+
jsonrpc: "2.0",
|
|
720
|
+
id: input.id,
|
|
721
|
+
error: toSlateErrorResponse(notFoundError("handler", input.method))
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
let parsed = impl.schema.safeParse(input);
|
|
725
|
+
if (!parsed.success) {
|
|
726
|
+
return {
|
|
727
|
+
jsonrpc: "2.0",
|
|
728
|
+
id: input.id,
|
|
729
|
+
error: toSlateErrorResponse(
|
|
730
|
+
validationError({
|
|
731
|
+
entity: "request",
|
|
732
|
+
message: "Invalid request parameters",
|
|
733
|
+
errors: parsed.error.issues.map((i) => ({
|
|
734
|
+
...i,
|
|
735
|
+
path: i.path.map((p) => String(p))
|
|
736
|
+
}))
|
|
737
|
+
})
|
|
738
|
+
)
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
if (impl.type === "notification") {
|
|
742
|
+
await impl.handler(parsed.data);
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
let result = await impl.handler(parsed.data);
|
|
746
|
+
return {
|
|
747
|
+
jsonrpc: "2.0",
|
|
748
|
+
id: parsed.data.id,
|
|
749
|
+
result
|
|
750
|
+
};
|
|
751
|
+
} catch (err) {
|
|
752
|
+
if (!getSlateErrorResponse(err) && !getServiceErrorData(err)) {
|
|
753
|
+
console.error(err);
|
|
754
|
+
}
|
|
755
|
+
return {
|
|
756
|
+
jsonrpc: "2.0",
|
|
757
|
+
id: input.id,
|
|
758
|
+
error: toSlateErrorResponse(err, {
|
|
759
|
+
message: "Internal server error"
|
|
760
|
+
})
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
static async handleInput(manager, input) {
|
|
765
|
+
return manager._handleInput(input);
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
var createSlatesProviderProtoHandler = (cb) => ({
|
|
769
|
+
run: async () => {
|
|
770
|
+
let manager = new SlatesProviderProtoHandlerManager();
|
|
771
|
+
await cb(manager);
|
|
772
|
+
return manager;
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
var toSlateErrorResponse = (error, defaults = {}) => {
|
|
776
|
+
let slateError = getSlateErrorResponse(error);
|
|
777
|
+
if (slateError) return slateError;
|
|
778
|
+
let serviceError = getServiceErrorData(error);
|
|
779
|
+
if (serviceError) {
|
|
780
|
+
return mapServiceErrorToSlateErrorResponse(serviceError, defaults);
|
|
781
|
+
}
|
|
782
|
+
return mapUnknownErrorToSlateErrorResponse(error, defaults);
|
|
783
|
+
};
|
|
784
|
+
var SERVICE_ERROR_CODE_MAP = {
|
|
785
|
+
invalid_data: "input.invalid",
|
|
786
|
+
bad_request: "request.bad",
|
|
787
|
+
not_found: "resource.not_found",
|
|
788
|
+
unauthorized: "auth.required",
|
|
789
|
+
forbidden: "permission.denied",
|
|
790
|
+
invalid_version: "request.invalid_version",
|
|
791
|
+
conflict: "resource.conflict",
|
|
792
|
+
gone: "resource.gone",
|
|
793
|
+
payment_required: "payment.required",
|
|
794
|
+
precondition_failed: "request.precondition_failed",
|
|
795
|
+
not_acceptable: "request.not_acceptable",
|
|
796
|
+
not_implemented: "operation.not_implemented",
|
|
797
|
+
too_many_requests: "request.rate_limited",
|
|
798
|
+
timeout: "internal.timeout",
|
|
799
|
+
internal_server_error: "internal.unexpected"
|
|
800
|
+
};
|
|
801
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
802
|
+
var isStructuredValue = (value) => (typeof value === "object" || typeof value === "function") && value !== null;
|
|
803
|
+
var isSlateErrorPayload = (value) => isRecord(value) && typeof value.code === "string" && typeof value.message === "string" && typeof value.kind === "string";
|
|
804
|
+
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);
|
|
805
|
+
var getSlateErrorResponse = (error) => {
|
|
806
|
+
if (isStructuredValue(error) && "name" in error && typeof error.name === "string" && error.name.startsWith("SlateError") && "toResponse" in error && typeof error.toResponse === "function") {
|
|
807
|
+
let response = error.toResponse();
|
|
808
|
+
return isSlateErrorPayload(response) ? response : null;
|
|
809
|
+
}
|
|
810
|
+
if (isSlateErrorPayload(error)) return error;
|
|
811
|
+
if (isStructuredValue(error) && "data" in error && isSlateErrorPayload(error.data)) {
|
|
812
|
+
return error.data;
|
|
813
|
+
}
|
|
814
|
+
return null;
|
|
815
|
+
};
|
|
816
|
+
var getServiceErrorData = (error) => {
|
|
817
|
+
if (isServiceError(error) && isServiceErrorData(error.data)) {
|
|
818
|
+
return error.data;
|
|
819
|
+
}
|
|
820
|
+
if (isServiceErrorData(error)) return error;
|
|
821
|
+
if (isStructuredValue(error) && "data" in error && isServiceErrorData(error.data)) {
|
|
822
|
+
return error.data;
|
|
823
|
+
}
|
|
824
|
+
if (isStructuredValue(error) && "toResponse" in error && typeof error.toResponse === "function") {
|
|
825
|
+
let response = error.toResponse();
|
|
826
|
+
if (isServiceErrorData(response)) return response;
|
|
827
|
+
}
|
|
828
|
+
return null;
|
|
829
|
+
};
|
|
830
|
+
var mapKind = (code) => {
|
|
831
|
+
if (code.startsWith("declaration.")) return "declaration";
|
|
832
|
+
if (code.startsWith("input.")) return "validation";
|
|
833
|
+
if (code.startsWith("request.")) return "request";
|
|
834
|
+
if (code.startsWith("config.")) return "config";
|
|
835
|
+
if (code.startsWith("auth.") || code.startsWith("permission.")) return "auth";
|
|
836
|
+
if (code.startsWith("resource.")) return "resource";
|
|
837
|
+
if (code.startsWith("payment.")) return "payment";
|
|
838
|
+
if (code.startsWith("transport.")) return "transport";
|
|
839
|
+
if (code.startsWith("upstream.")) return "upstream";
|
|
840
|
+
return "internal";
|
|
841
|
+
};
|
|
842
|
+
var mapRetryable = (code) => 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";
|
|
843
|
+
var mapServiceErrorCode = (code, status) => {
|
|
844
|
+
if (SERVICE_ERROR_CODE_MAP[code]) return SERVICE_ERROR_CODE_MAP[code];
|
|
845
|
+
if (status === 400) return "request.bad";
|
|
846
|
+
if (status === 401) return "auth.required";
|
|
847
|
+
if (status === 402) return "payment.required";
|
|
848
|
+
if (status === 403) return "permission.denied";
|
|
849
|
+
if (status === 404) return "resource.not_found";
|
|
850
|
+
if (status === 406) return "request.not_acceptable";
|
|
851
|
+
if (status === 409) return "resource.conflict";
|
|
852
|
+
if (status === 410) return "resource.gone";
|
|
853
|
+
if (status === 412) return "request.precondition_failed";
|
|
854
|
+
if (status === 429) return "request.rate_limited";
|
|
855
|
+
if (status === 501) return "operation.not_implemented";
|
|
856
|
+
if (status === 504) return "internal.timeout";
|
|
857
|
+
if (status && status >= 500) return "internal.unexpected";
|
|
858
|
+
return "internal.unexpected";
|
|
859
|
+
};
|
|
860
|
+
var mapIssues = (errors) => {
|
|
861
|
+
if (!Array.isArray(errors)) return void 0;
|
|
862
|
+
let issues = errors.map((error) => {
|
|
863
|
+
if (!isRecord(error)) {
|
|
864
|
+
return { message: String(error) };
|
|
865
|
+
}
|
|
866
|
+
return {
|
|
867
|
+
...error,
|
|
868
|
+
path: Array.isArray(error.path) ? error.path.map((entry) => String(entry)) : void 0,
|
|
869
|
+
code: typeof error.code === "string" ? error.code : void 0,
|
|
870
|
+
message: typeof error.message === "string" ? error.message : "Validation issue"
|
|
871
|
+
};
|
|
872
|
+
});
|
|
873
|
+
return issues.length > 0 ? issues : void 0;
|
|
874
|
+
};
|
|
875
|
+
var mapServiceErrorToSlateErrorResponse = (error, defaults = {}) => {
|
|
876
|
+
let code = defaults.code ?? mapServiceErrorCode(error.code, error.status);
|
|
877
|
+
let extraEntries = Object.entries(error).filter(
|
|
878
|
+
([key]) => ![
|
|
879
|
+
"status",
|
|
880
|
+
"code",
|
|
881
|
+
"message",
|
|
882
|
+
"errors",
|
|
883
|
+
"hint",
|
|
884
|
+
"description",
|
|
885
|
+
"reason",
|
|
886
|
+
"object",
|
|
887
|
+
"ok"
|
|
888
|
+
].includes(key)
|
|
889
|
+
);
|
|
890
|
+
return {
|
|
891
|
+
code,
|
|
892
|
+
kind: mapKind(code),
|
|
893
|
+
message: error.message,
|
|
894
|
+
retryable: mapRetryable(code),
|
|
895
|
+
status: error.status,
|
|
896
|
+
...mapIssues(error.errors) ? { issues: mapIssues(error.errors) } : {},
|
|
897
|
+
baggage: {
|
|
898
|
+
serviceError: {
|
|
899
|
+
code: error.code,
|
|
900
|
+
status: error.status,
|
|
901
|
+
hint: error.hint,
|
|
902
|
+
description: error.description,
|
|
903
|
+
reason: error.reason
|
|
904
|
+
},
|
|
905
|
+
...extraEntries.length > 0 ? { serviceErrorData: Object.fromEntries(extraEntries) } : {}
|
|
906
|
+
}
|
|
907
|
+
};
|
|
908
|
+
};
|
|
909
|
+
var mapUnknownErrorToSlateErrorResponse = (error, defaults = {}) => ({
|
|
910
|
+
code: defaults.code ?? "internal.unexpected",
|
|
911
|
+
kind: "internal",
|
|
912
|
+
message: defaults.message ?? (error instanceof Error ? error.message : "An unexpected internal error occurred."),
|
|
913
|
+
retryable: false,
|
|
914
|
+
status: 500,
|
|
915
|
+
...error instanceof Error ? {
|
|
916
|
+
baggage: {
|
|
917
|
+
originalName: error.name
|
|
918
|
+
}
|
|
919
|
+
} : {}
|
|
920
|
+
});
|
|
921
|
+
export {
|
|
922
|
+
SLATES_PROTOCOL_VERSION,
|
|
923
|
+
SlatesProviderProtoHandlerManager,
|
|
924
|
+
createSlatesProviderProtoHandler,
|
|
925
|
+
slatesAction,
|
|
926
|
+
slatesActionBase,
|
|
927
|
+
slatesActionRequestsByMethod,
|
|
928
|
+
slatesActionResponsesByMethod,
|
|
929
|
+
slatesActionScopeClause,
|
|
930
|
+
slatesActionScopes,
|
|
931
|
+
slatesActionTool,
|
|
932
|
+
slatesActionTrigger,
|
|
933
|
+
slatesAuthNotificationsByMethod,
|
|
934
|
+
slatesAuthRequestsByMethod,
|
|
935
|
+
slatesAuthResponsesByMethod,
|
|
936
|
+
slatesAuthenticationMethod,
|
|
937
|
+
slatesConfigNotificationsByMethod,
|
|
938
|
+
slatesConfigRequestsByMethod,
|
|
939
|
+
slatesConfigResponsesByMethod,
|
|
940
|
+
slatesControlFlowNotificationsByMethod,
|
|
941
|
+
slatesIdentifyRequestsByMethod,
|
|
942
|
+
slatesIdentifyResponsesByMethod,
|
|
943
|
+
slatesMessageActionGetRequest,
|
|
944
|
+
slatesMessageActionGetResponse,
|
|
945
|
+
slatesMessageActionInvokeRequest,
|
|
946
|
+
slatesMessageActionInvokeResponse,
|
|
947
|
+
slatesMessageActionTriggerEventMapRequest,
|
|
948
|
+
slatesMessageActionTriggerEventMapResponse,
|
|
949
|
+
slatesMessageActionTriggerEventsPollRequest,
|
|
950
|
+
slatesMessageActionTriggerEventsPollResponse,
|
|
951
|
+
slatesMessageActionTriggerWebhookHandleRequest,
|
|
952
|
+
slatesMessageActionTriggerWebhookHandleResponse,
|
|
953
|
+
slatesMessageActionTriggerWebhookRegisterRequest,
|
|
954
|
+
slatesMessageActionTriggerWebhookRegisterResponse,
|
|
955
|
+
slatesMessageActionTriggerWebhookUnregisterRequest,
|
|
956
|
+
slatesMessageActionTriggerWebhookUnregisterResponse,
|
|
957
|
+
slatesMessageActionsListRequest,
|
|
958
|
+
slatesMessageActionsListResponse,
|
|
959
|
+
slatesMessageAuthAuthorizationCallbackHandleRequest,
|
|
960
|
+
slatesMessageAuthAuthorizationCallbackHandleResponse,
|
|
961
|
+
slatesMessageAuthAuthorizationUrlGetRequest,
|
|
962
|
+
slatesMessageAuthAuthorizationUrlGetResponse,
|
|
963
|
+
slatesMessageAuthDefaultInputGetRequest,
|
|
964
|
+
slatesMessageAuthDefaultInputGetResponse,
|
|
965
|
+
slatesMessageAuthInputChangedRequest,
|
|
966
|
+
slatesMessageAuthInputChangedResponse,
|
|
967
|
+
slatesMessageAuthMethodGetRequest,
|
|
968
|
+
slatesMessageAuthMethodGetResponse,
|
|
969
|
+
slatesMessageAuthMethodsListRequest,
|
|
970
|
+
slatesMessageAuthMethodsListResponse,
|
|
971
|
+
slatesMessageAuthOutputGetRequest,
|
|
972
|
+
slatesMessageAuthOutputGetResponse,
|
|
973
|
+
slatesMessageAuthProfileGetRequest,
|
|
974
|
+
slatesMessageAuthProfileGetResponse,
|
|
975
|
+
slatesMessageAuthTokenRefreshHandleRequest,
|
|
976
|
+
slatesMessageAuthTokenRefreshHandleResponse,
|
|
977
|
+
slatesMessageConfigChangedRequest,
|
|
978
|
+
slatesMessageConfigChangedResponse,
|
|
979
|
+
slatesMessageConfigDefaultGetRequest,
|
|
980
|
+
slatesMessageConfigDefaultGetResponse,
|
|
981
|
+
slatesMessageConfigSchemaGetRequest,
|
|
982
|
+
slatesMessageConfigSchemaGetResponse,
|
|
983
|
+
slatesMessageHelloNotification,
|
|
984
|
+
slatesMessageProviderIdentifyRequest,
|
|
985
|
+
slatesMessageProviderIdentifyResponse,
|
|
986
|
+
slatesMessageSessionStartNotification,
|
|
987
|
+
slatesMessageSetAuthNotification,
|
|
988
|
+
slatesMessageSetConfigNotification,
|
|
989
|
+
slatesMessageSetParticipantsNotification,
|
|
990
|
+
slatesNotificationsByMethod,
|
|
991
|
+
slatesParticipant,
|
|
992
|
+
slatesRequestTrace,
|
|
993
|
+
slatesRequestTraceTextBody,
|
|
994
|
+
slatesRequestsByMethod,
|
|
995
|
+
slatesResponsesByMethod,
|
|
996
|
+
withRequestTraces
|
|
997
|
+
};
|