@blazingagents/sdk 0.1.0

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.
Files changed (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +366 -0
  3. package/dist/chat-transport.d.ts +17 -0
  4. package/dist/chat-transport.js +58 -0
  5. package/dist/client.d.ts +38 -0
  6. package/dist/client.js +86 -0
  7. package/dist/contracts/api.d.ts +256 -0
  8. package/dist/contracts/api.js +189 -0
  9. package/dist/contracts/entities/agent-tools.d.ts +26 -0
  10. package/dist/contracts/entities/agent-tools.js +52 -0
  11. package/dist/contracts/entities/agents.d.ts +183 -0
  12. package/dist/contracts/entities/agents.js +153 -0
  13. package/dist/contracts/entities/artifacts.d.ts +71 -0
  14. package/dist/contracts/entities/artifacts.js +71 -0
  15. package/dist/contracts/entities/attribution.d.ts +27 -0
  16. package/dist/contracts/entities/attribution.js +27 -0
  17. package/dist/contracts/entities/chat.d.ts +269 -0
  18. package/dist/contracts/entities/chat.js +198 -0
  19. package/dist/contracts/entities/mcp-connections.d.ts +421 -0
  20. package/dist/contracts/entities/mcp-connections.js +473 -0
  21. package/dist/contracts/entities/memories.d.ts +56 -0
  22. package/dist/contracts/entities/memories.js +62 -0
  23. package/dist/contracts/entities/prompts.d.ts +61 -0
  24. package/dist/contracts/entities/prompts.js +96 -0
  25. package/dist/contracts/entities/providers.d.ts +123 -0
  26. package/dist/contracts/entities/providers.js +111 -0
  27. package/dist/contracts/entities/sessions.d.ts +156 -0
  28. package/dist/contracts/entities/sessions.js +120 -0
  29. package/dist/contracts/entities/skills.d.ts +167 -0
  30. package/dist/contracts/entities/skills.js +153 -0
  31. package/dist/contracts/entities/tasks.d.ts +457 -0
  32. package/dist/contracts/entities/tasks.js +252 -0
  33. package/dist/contracts/entities/tenants.d.ts +69 -0
  34. package/dist/contracts/entities/tenants.js +54 -0
  35. package/dist/contracts/entities/usage.d.ts +95 -0
  36. package/dist/contracts/entities/usage.js +117 -0
  37. package/dist/contracts/entities/workspaces.d.ts +89 -0
  38. package/dist/contracts/entities/workspaces.js +71 -0
  39. package/dist/contracts/ids.d.ts +57 -0
  40. package/dist/contracts/ids.js +79 -0
  41. package/dist/contracts/index.d.ts +15 -0
  42. package/dist/contracts/index.js +16 -0
  43. package/dist/contracts/limitations.d.ts +138 -0
  44. package/dist/contracts/limitations.js +140 -0
  45. package/dist/contracts/utils.d.ts +3 -0
  46. package/dist/contracts/utils.js +7 -0
  47. package/dist/errors.d.ts +33 -0
  48. package/dist/errors.js +48 -0
  49. package/dist/generation.d.ts +5 -0
  50. package/dist/generation.js +422 -0
  51. package/dist/http.d.ts +21 -0
  52. package/dist/http.js +307 -0
  53. package/dist/index.d.ts +20 -0
  54. package/dist/index.js +13 -0
  55. package/dist/relay.d.ts +20 -0
  56. package/dist/relay.js +113 -0
  57. package/dist/resources/agents.d.ts +8 -0
  58. package/dist/resources/agents.js +82 -0
  59. package/dist/resources/artifacts.d.ts +5 -0
  60. package/dist/resources/artifacts.js +29 -0
  61. package/dist/resources/mcp-connections.d.ts +2 -0
  62. package/dist/resources/mcp-connections.js +40 -0
  63. package/dist/resources/memories.d.ts +7 -0
  64. package/dist/resources/memories.js +33 -0
  65. package/dist/resources/prompts.d.ts +6 -0
  66. package/dist/resources/prompts.js +36 -0
  67. package/dist/resources/providers.d.ts +5 -0
  68. package/dist/resources/providers.js +38 -0
  69. package/dist/resources/sessions.d.ts +8 -0
  70. package/dist/resources/sessions.js +49 -0
  71. package/dist/resources/skills.d.ts +2 -0
  72. package/dist/resources/skills.js +49 -0
  73. package/dist/resources/tasks.d.ts +7 -0
  74. package/dist/resources/tasks.js +63 -0
  75. package/dist/resources/tenant.d.ts +6 -0
  76. package/dist/resources/tenant.js +19 -0
  77. package/dist/resources/usage.d.ts +7 -0
  78. package/dist/resources/usage.js +19 -0
  79. package/dist/resources/workspaces.d.ts +2 -0
  80. package/dist/resources/workspaces.js +31 -0
  81. package/dist/types.d.ts +381 -0
  82. package/dist/types.js +1 -0
  83. package/package.json +65 -0
@@ -0,0 +1,473 @@
1
+ import { z } from "zod";
2
+ import { mcpConnectionIdSchema, tenantIdSchema } from "../ids.js";
3
+ import { MAX_MCP_ATTACHMENT_METADATA_KEY_LENGTH, MAX_MCP_ATTACHMENT_METADATA_KEYS, MAX_MCP_BEARER_TOKEN_LENGTH, MAX_MCP_CONNECTION_NAME_LENGTH, MAX_MCP_CONNECTION_TEST_LATENCY_MS, MAX_MCP_CONNECTION_URL_LENGTH, MAX_MCP_OAUTH_CLIENT_ID_LENGTH, MAX_MCP_OAUTH_CLIENT_SECRET_LENGTH, MAX_MCP_OAUTH_SCOPE_LENGTH, MAX_MCP_SERVER_NAME_LENGTH, MAX_MCP_SERVER_VERSION_LENGTH, MAX_MCP_TOOL_NAME_LENGTH, MAX_MCP_TOOLS_PER_CONNECTION, } from "../limitations.js";
4
+ import { atLeastOneFieldMessage, hasObjectKeys, hasUniqueValues, } from "../utils.js";
5
+ const OPAQUE_MCP_OAUTH_TOKEN_PATTERN = /^[A-Za-z0-9_-]{43}$/;
6
+ export const mcpConnectionAuthTypeSchema = z.enum([
7
+ "none",
8
+ "bearer",
9
+ "oauth_authorization_code",
10
+ "oauth_client_credentials",
11
+ ]);
12
+ export const mcpConnectionStatusSchema = z.enum([
13
+ "connected",
14
+ "needs_auth",
15
+ "error",
16
+ ]);
17
+ export const mcpConnectionTestErrorCodeSchema = z.enum([
18
+ "MCP_CONNECTION_AUTHENTICATION_FAILED",
19
+ "MCP_CONNECTION_INVALID",
20
+ "MCP_CONNECTION_UNREACHABLE",
21
+ "MCP_CONNECTION_DISCOVERY_FAILED",
22
+ ]);
23
+ const mcpConnectionNameSchema = z
24
+ .string()
25
+ .trim()
26
+ .min(1)
27
+ .max(MAX_MCP_CONNECTION_NAME_LENGTH);
28
+ const bearerTokenSchema = z
29
+ .string()
30
+ .min(1)
31
+ .max(MAX_MCP_BEARER_TOKEN_LENGTH)
32
+ .regex(/^[!-~]+$/, "Bearer token must contain visible ASCII characters only");
33
+ const oauthClientIdSchema = z
34
+ .string()
35
+ .min(1)
36
+ .max(MAX_MCP_OAUTH_CLIENT_ID_LENGTH)
37
+ .regex(/^[!-~]+$/, "Client ID must contain visible ASCII characters only");
38
+ const oauthClientSecretSchema = z
39
+ .string()
40
+ .min(1)
41
+ .max(MAX_MCP_OAUTH_CLIENT_SECRET_LENGTH)
42
+ .regex(/^[!-~]+$/, "Client secret must contain visible ASCII characters only");
43
+ const storedOauthClientIdSchema = z
44
+ .string()
45
+ .min(1)
46
+ .max(MAX_MCP_OAUTH_CLIENT_ID_LENGTH);
47
+ const storedOauthClientSecretSchema = z
48
+ .string()
49
+ .min(1)
50
+ .max(MAX_MCP_OAUTH_CLIENT_SECRET_LENGTH);
51
+ const oauthScopeSchema = z
52
+ .string()
53
+ .trim()
54
+ .min(1)
55
+ .max(MAX_MCP_OAUTH_SCOPE_LENGTH)
56
+ .regex(/^[\x20-\x7e]+$/, "Scope must contain printable ASCII characters only");
57
+ const oauthIssuerSchema = z
58
+ .string()
59
+ .trim()
60
+ .url()
61
+ .refine((value) => {
62
+ try {
63
+ const url = new URL(value);
64
+ return ((url.protocol === "http:" || url.protocol === "https:") &&
65
+ url.username === "" &&
66
+ url.password === "" &&
67
+ url.search === "" &&
68
+ url.hash === "");
69
+ }
70
+ catch {
71
+ return false;
72
+ }
73
+ }, {
74
+ message: "OAuth issuer must be an http(s) URL without credentials, query, or fragment",
75
+ })
76
+ .transform((value) => new URL(value).toString());
77
+ const credentialFragmentSchema = z.string().min(1).max(4).nullable();
78
+ /** Mirrors the MCP SDK's SEP-2352 issuer-identity comparison. */
79
+ export function mcpOauthIssuersMatch(a, b) {
80
+ return (a === b ||
81
+ (a.endsWith("/") && a.slice(0, -1) === b) ||
82
+ (b.endsWith("/") && b.slice(0, -1) === a));
83
+ }
84
+ const oauthClientInformationSchema = z.looseObject({
85
+ client_id: storedOauthClientIdSchema,
86
+ client_secret: storedOauthClientSecretSchema.optional(),
87
+ issuer: oauthIssuerSchema,
88
+ });
89
+ const oauthConfidentialClientInformationSchema = oauthClientInformationSchema.safeExtend({
90
+ client_secret: oauthClientSecretSchema,
91
+ });
92
+ const oauthTokensSchema = z
93
+ .object({
94
+ access_token: z.string().min(1),
95
+ expires_in: z.number().positive().optional(),
96
+ issuer: oauthIssuerSchema,
97
+ refresh_token: z.string().optional(),
98
+ scope: z.string().optional(),
99
+ token_type: z.string().min(1),
100
+ })
101
+ .strict();
102
+ const oauthDiscoveryStateSchema = z.looseObject({
103
+ authorizationServerMetadata: z.record(z.string(), z.unknown()).optional(),
104
+ authorizationServerUrl: oauthIssuerSchema,
105
+ resourceMetadata: z.record(z.string(), z.unknown()).optional(),
106
+ resourceMetadataUrl: z.string().url().optional(),
107
+ });
108
+ export const mcpOauthClientCredentialsBundleSchema = z
109
+ .object({
110
+ clientInformation: oauthConfidentialClientInformationSchema,
111
+ discoveryState: oauthDiscoveryStateSchema.nullable(),
112
+ scope: oauthScopeSchema.nullable(),
113
+ tokens: oauthTokensSchema.nullable(),
114
+ type: z.literal("oauth_client_credentials"),
115
+ version: z.literal(1),
116
+ })
117
+ .strict()
118
+ .superRefine((bundle, context) => {
119
+ if (bundle.tokens &&
120
+ bundle.tokens.issuer !== bundle.clientInformation.issuer) {
121
+ context.addIssue({
122
+ code: "custom",
123
+ message: "OAuth token issuer must match the client issuer",
124
+ path: ["tokens", "issuer"],
125
+ });
126
+ }
127
+ });
128
+ export const mcpOauthAuthorizationCodeBundleSchema = z
129
+ .object({
130
+ clientInformation: oauthClientInformationSchema.nullable(),
131
+ discoveryState: oauthDiscoveryStateSchema.nullable(),
132
+ scope: oauthScopeSchema.nullable(),
133
+ tokens: oauthTokensSchema.nullable(),
134
+ type: z.literal("oauth_authorization_code"),
135
+ version: z.literal(1),
136
+ })
137
+ .strict()
138
+ .superRefine((bundle, context) => {
139
+ if (bundle.tokens && !bundle.clientInformation) {
140
+ context.addIssue({
141
+ code: "custom",
142
+ message: "OAuth tokens require client information",
143
+ path: ["clientInformation"],
144
+ });
145
+ return;
146
+ }
147
+ if (bundle.tokens &&
148
+ bundle.tokens.issuer !== bundle.clientInformation?.issuer) {
149
+ context.addIssue({
150
+ code: "custom",
151
+ message: "OAuth token issuer must match the client issuer",
152
+ path: ["tokens", "issuer"],
153
+ });
154
+ }
155
+ });
156
+ export const mcpOauthAuthorizationTransactionBundleSchema = z
157
+ .object({
158
+ clientInformation: oauthClientInformationSchema.nullable(),
159
+ codeVerifier: z.string().min(1).max(1024).nullable(),
160
+ credentialVersion: z.number().int().nonnegative(),
161
+ discoveryState: oauthDiscoveryStateSchema.nullable(),
162
+ expectedIssuer: oauthIssuerSchema,
163
+ expectedResource: z.string().url(),
164
+ redirectUri: z.string().url(),
165
+ scope: oauthScopeSchema.nullable(),
166
+ type: z.literal("oauth_authorization_code_transaction"),
167
+ version: z.literal(1),
168
+ })
169
+ .strict()
170
+ .superRefine((bundle, context) => {
171
+ if (bundle.clientInformation &&
172
+ bundle.clientInformation.issuer !== bundle.expectedIssuer) {
173
+ context.addIssue({
174
+ code: "custom",
175
+ message: "OAuth client issuer must match the expected issuer",
176
+ path: ["clientInformation", "issuer"],
177
+ });
178
+ }
179
+ if ((bundle.codeVerifier !== null || bundle.discoveryState !== null) &&
180
+ bundle.clientInformation === null) {
181
+ context.addIssue({
182
+ code: "custom",
183
+ message: "An active OAuth transaction requires client information",
184
+ path: ["clientInformation"],
185
+ });
186
+ }
187
+ });
188
+ export const mcpBearerCredentialBundleSchema = z
189
+ .object({
190
+ bearerToken: bearerTokenSchema,
191
+ type: z.literal("bearer"),
192
+ version: z.literal(1),
193
+ })
194
+ .strict();
195
+ export const mcpCredentialBundleSchema = z.discriminatedUnion("type", [
196
+ mcpBearerCredentialBundleSchema,
197
+ mcpOauthAuthorizationCodeBundleSchema,
198
+ mcpOauthClientCredentialsBundleSchema,
199
+ ]);
200
+ const mcpConnectionUrlSchema = z
201
+ .string()
202
+ .trim()
203
+ .max(MAX_MCP_CONNECTION_URL_LENGTH)
204
+ .url()
205
+ .refine((value) => {
206
+ try {
207
+ const url = new URL(value);
208
+ return ((url.protocol === "http:" || url.protocol === "https:") &&
209
+ url.username === "" &&
210
+ url.password === "" &&
211
+ url.hash === "" &&
212
+ url.search === "");
213
+ }
214
+ catch {
215
+ return false;
216
+ }
217
+ }, {
218
+ message: "URL must use http(s) without credentials, query, or fragment",
219
+ })
220
+ .transform((value) => new URL(value).toString());
221
+ export const mcpConnectionSchema = z
222
+ .object({
223
+ id: mcpConnectionIdSchema,
224
+ tenantId: tenantIdSchema,
225
+ name: mcpConnectionNameSchema,
226
+ url: mcpConnectionUrlSchema,
227
+ authType: mcpConnectionAuthTypeSchema,
228
+ status: mcpConnectionStatusSchema,
229
+ credentialVersion: z.number().int().nonnegative(),
230
+ credentialFragment: credentialFragmentSchema,
231
+ lastAuthErrorCode: mcpConnectionTestErrorCodeSchema.nullable(),
232
+ oauthIssuer: z.string().url().nullable(),
233
+ oauthResource: z.string().url().nullable(),
234
+ tokenExpiresAt: z.iso.datetime({ offset: true }).nullable(),
235
+ createdAt: z.iso.datetime({ offset: true }),
236
+ updatedAt: z.iso.datetime({ offset: true }),
237
+ })
238
+ .strict();
239
+ export const mcpConnectionResponseSchema = z
240
+ .object({
241
+ id: mcpConnectionIdSchema,
242
+ name: mcpConnectionNameSchema,
243
+ url: mcpConnectionUrlSchema,
244
+ authType: mcpConnectionAuthTypeSchema,
245
+ status: mcpConnectionStatusSchema,
246
+ credentialFragment: credentialFragmentSchema,
247
+ lastAuthErrorCode: mcpConnectionTestErrorCodeSchema.nullable(),
248
+ oauthIssuer: z.string().url().nullable(),
249
+ oauthResource: z.string().url().nullable(),
250
+ tokenExpiresAt: z.iso.datetime({ offset: true }).nullable(),
251
+ createdAt: z.iso.datetime({ offset: true }),
252
+ updatedAt: z.iso.datetime({ offset: true }),
253
+ })
254
+ .strict();
255
+ export const mcpConnectionsResponseSchema = z
256
+ .object({
257
+ mcpConnections: z.array(mcpConnectionResponseSchema),
258
+ })
259
+ .strict();
260
+ export const forwardedMetadataKeysSchema = z
261
+ .array(z.string().min(1).max(MAX_MCP_ATTACHMENT_METADATA_KEY_LENGTH))
262
+ .max(MAX_MCP_ATTACHMENT_METADATA_KEYS)
263
+ .refine(hasUniqueValues, {
264
+ message: "Forwarded metadata keys must be unique.",
265
+ });
266
+ export const mcpAttachmentResponseSchema = z
267
+ .object({
268
+ mcpConnectionId: mcpConnectionIdSchema,
269
+ forwardUserId: z.boolean(),
270
+ forwardedMetadataKeys: forwardedMetadataKeysSchema,
271
+ createdAt: z.iso.datetime({ offset: true }),
272
+ updatedAt: z.iso.datetime({ offset: true }),
273
+ })
274
+ .strict();
275
+ export const mcpAttachmentsResponseSchema = z
276
+ .object({
277
+ mcpAttachments: z.array(mcpAttachmentResponseSchema),
278
+ })
279
+ .strict();
280
+ export const updateMcpAttachmentBodySchema = z
281
+ .object({
282
+ forwardUserId: z.boolean().optional(),
283
+ forwardedMetadataKeys: forwardedMetadataKeysSchema.optional(),
284
+ })
285
+ .strict()
286
+ .refine(hasObjectKeys, {
287
+ message: atLeastOneFieldMessage,
288
+ });
289
+ const createNoneMcpConnectionBodySchema = z
290
+ .object({
291
+ name: mcpConnectionNameSchema,
292
+ url: mcpConnectionUrlSchema,
293
+ authType: z.literal("none"),
294
+ })
295
+ .strict();
296
+ const createBearerMcpConnectionBodySchema = z
297
+ .object({
298
+ name: mcpConnectionNameSchema,
299
+ url: mcpConnectionUrlSchema,
300
+ authType: z.literal("bearer"),
301
+ bearerToken: bearerTokenSchema,
302
+ })
303
+ .strict();
304
+ const oauthClientCredentialsFields = {
305
+ authType: z.literal("oauth_client_credentials"),
306
+ clientId: oauthClientIdSchema,
307
+ clientSecret: oauthClientSecretSchema,
308
+ scope: oauthScopeSchema.optional(),
309
+ url: mcpConnectionUrlSchema,
310
+ };
311
+ const oauthAuthorizationCodeFields = {
312
+ authType: z.literal("oauth_authorization_code"),
313
+ clientId: oauthClientIdSchema.optional(),
314
+ clientSecret: oauthClientSecretSchema.optional(),
315
+ scope: oauthScopeSchema.optional(),
316
+ url: mcpConnectionUrlSchema,
317
+ };
318
+ const createOauthAuthorizationCodeMcpConnectionBodySchema = z
319
+ .object({
320
+ ...oauthAuthorizationCodeFields,
321
+ name: mcpConnectionNameSchema,
322
+ })
323
+ .strict();
324
+ const createOauthClientCredentialsMcpConnectionBodySchema = z
325
+ .object({
326
+ ...oauthClientCredentialsFields,
327
+ name: mcpConnectionNameSchema,
328
+ })
329
+ .strict();
330
+ export const createMcpConnectionBodySchema = z
331
+ .discriminatedUnion("authType", [
332
+ createNoneMcpConnectionBodySchema,
333
+ createBearerMcpConnectionBodySchema,
334
+ createOauthAuthorizationCodeMcpConnectionBodySchema,
335
+ createOauthClientCredentialsMcpConnectionBodySchema,
336
+ ])
337
+ .superRefine((body, context) => {
338
+ if (body.authType === "oauth_authorization_code" &&
339
+ (body.clientId === undefined) !== (body.clientSecret === undefined)) {
340
+ context.addIssue({
341
+ code: "custom",
342
+ message: "OAuth client ID and secret must be provided together",
343
+ path: [body.clientId === undefined ? "clientId" : "clientSecret"],
344
+ });
345
+ }
346
+ });
347
+ export const updateMcpConnectionBodySchema = z
348
+ .object({
349
+ name: mcpConnectionNameSchema.optional(),
350
+ })
351
+ .strict()
352
+ .refine(hasObjectKeys, {
353
+ message: atLeastOneFieldMessage,
354
+ });
355
+ export const reconnectMcpConnectionBodySchema = z
356
+ .discriminatedUnion("authType", [
357
+ z
358
+ .object({
359
+ authType: z.literal("none"),
360
+ url: mcpConnectionUrlSchema,
361
+ })
362
+ .strict(),
363
+ z
364
+ .object({
365
+ authType: z.literal("bearer"),
366
+ bearerToken: bearerTokenSchema,
367
+ url: mcpConnectionUrlSchema,
368
+ })
369
+ .strict(),
370
+ z.object(oauthAuthorizationCodeFields).strict(),
371
+ z.object(oauthClientCredentialsFields).strict(),
372
+ ])
373
+ .superRefine((body, context) => {
374
+ if (body.authType === "oauth_authorization_code" &&
375
+ (body.clientId === undefined) !== (body.clientSecret === undefined)) {
376
+ context.addIssue({
377
+ code: "custom",
378
+ message: "OAuth client ID and secret must be provided together",
379
+ path: [body.clientId === undefined ? "clientId" : "clientSecret"],
380
+ });
381
+ }
382
+ });
383
+ export const mcpConnectionOauthConnectResponseSchema = z
384
+ .object({
385
+ authorizationUrl: z
386
+ .string()
387
+ .url()
388
+ .refine((value) => {
389
+ const url = new URL(value);
390
+ return (url.pathname === "/app/mcp-connections" &&
391
+ url.username === "" &&
392
+ url.password === "" &&
393
+ url.hash === "" &&
394
+ url.searchParams.size === 1 &&
395
+ OPAQUE_MCP_OAUTH_TOKEN_PATTERN.test(url.searchParams.get("mcpOAuthSetup") ?? ""));
396
+ }),
397
+ })
398
+ .strict();
399
+ export const mcpOauthAuthorizationLaunchResponseSchema = z
400
+ .object({
401
+ authorizationUrl: z
402
+ .string()
403
+ .url()
404
+ .refine((value) => {
405
+ const url = new URL(value);
406
+ return (url.pathname === "/v1/mcp/oauth/authorize" &&
407
+ url.username === "" &&
408
+ url.password === "" &&
409
+ url.hash === "" &&
410
+ url.searchParams.size === 1 &&
411
+ OPAQUE_MCP_OAUTH_TOKEN_PATTERN.test(url.searchParams.get("setup") ?? ""));
412
+ }),
413
+ })
414
+ .strict();
415
+ export const approveMcpOauthAuthorizationBodySchema = z
416
+ .object({ setupToken: z.string().regex(OPAQUE_MCP_OAUTH_TOKEN_PATTERN) })
417
+ .strict();
418
+ export const mcpConnectionLiveDetailsSchema = z
419
+ .object({
420
+ server: z
421
+ .object({
422
+ name: z.string().trim().min(1).max(MAX_MCP_SERVER_NAME_LENGTH),
423
+ version: z.string().trim().min(1).max(MAX_MCP_SERVER_VERSION_LENGTH),
424
+ })
425
+ .strict(),
426
+ toolNames: z
427
+ .array(z.string().trim().min(1).max(MAX_MCP_TOOL_NAME_LENGTH))
428
+ .max(MAX_MCP_TOOLS_PER_CONNECTION),
429
+ })
430
+ .strict();
431
+ const mcpConnectionTestOkResponseSchema = mcpConnectionLiveDetailsSchema
432
+ .extend({
433
+ ok: z.literal(true),
434
+ latencyMs: z
435
+ .number()
436
+ .int()
437
+ .nonnegative()
438
+ .max(MAX_MCP_CONNECTION_TEST_LATENCY_MS),
439
+ toolCount: z.number().int().nonnegative().max(MAX_MCP_TOOLS_PER_CONNECTION),
440
+ })
441
+ .strict()
442
+ .refine((result) => result.toolCount === result.toolNames.length, {
443
+ message: "toolCount must match toolNames length",
444
+ });
445
+ const mcpConnectionTestFailResponseSchema = z
446
+ .object({
447
+ ok: z.literal(false),
448
+ error: z
449
+ .object({
450
+ code: mcpConnectionTestErrorCodeSchema,
451
+ message: z.string().trim().min(1).max(200),
452
+ })
453
+ .strict(),
454
+ })
455
+ .strict();
456
+ export const mcpConnectionTestResponseSchema = z.discriminatedUnion("ok", [
457
+ mcpConnectionTestOkResponseSchema,
458
+ mcpConnectionTestFailResponseSchema,
459
+ ]);
460
+ export const mcpConnectionReconnectResultSchema = z.discriminatedUnion("status", [
461
+ z
462
+ .object({
463
+ status: z.literal("connected"),
464
+ connection: mcpConnectionResponseSchema,
465
+ })
466
+ .strict(),
467
+ z
468
+ .object({
469
+ status: z.literal("needs_auth"),
470
+ connection: mcpConnectionResponseSchema,
471
+ })
472
+ .strict(),
473
+ ]);
@@ -0,0 +1,56 @@
1
+ import { z } from "zod";
2
+ export declare const memoryTextSchema: z.ZodString;
3
+ export declare const memorySchema: z.ZodObject<{
4
+ id: z.ZodString;
5
+ tenantId: z.ZodString;
6
+ agentId: z.ZodString;
7
+ userId: z.ZodString;
8
+ text: z.ZodString;
9
+ createdAt: z.ZodISODateTime;
10
+ updatedAt: z.ZodISODateTime;
11
+ lastAccessedAt: z.ZodISODateTime;
12
+ }, z.core.$strict>;
13
+ export declare const memoryResponseSchema: z.ZodObject<{
14
+ memory: z.ZodObject<{
15
+ id: z.ZodString;
16
+ tenantId: z.ZodString;
17
+ agentId: z.ZodString;
18
+ userId: z.ZodString;
19
+ text: z.ZodString;
20
+ createdAt: z.ZodISODateTime;
21
+ updatedAt: z.ZodISODateTime;
22
+ lastAccessedAt: z.ZodISODateTime;
23
+ }, z.core.$strict>;
24
+ }, z.core.$strict>;
25
+ export declare const memoriesListResponseSchema: z.ZodObject<{
26
+ data: z.ZodArray<z.ZodObject<{
27
+ id: z.ZodString;
28
+ tenantId: z.ZodString;
29
+ agentId: z.ZodString;
30
+ userId: z.ZodString;
31
+ text: z.ZodString;
32
+ createdAt: z.ZodISODateTime;
33
+ updatedAt: z.ZodISODateTime;
34
+ lastAccessedAt: z.ZodISODateTime;
35
+ }, z.core.$strict>>;
36
+ nextCursor: z.ZodNullable<z.ZodString>;
37
+ }, z.core.$strict>;
38
+ export declare const memoriesListQuerySchema: z.ZodObject<{
39
+ userId: z.ZodOptional<z.ZodString>;
40
+ search: z.ZodOptional<z.ZodString>;
41
+ cursor: z.ZodOptional<z.ZodString>;
42
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
43
+ }, z.core.$strict>;
44
+ export declare const createMemoryBodySchema: z.ZodObject<{
45
+ text: z.ZodString;
46
+ userId: z.ZodDefault<z.ZodString>;
47
+ }, z.core.$strict>;
48
+ export declare const updateMemoryBodySchema: z.ZodObject<{
49
+ text: z.ZodString;
50
+ }, z.core.$strict>;
51
+ export type Memory = z.infer<typeof memorySchema>;
52
+ export type MemoryResponse = z.infer<typeof memoryResponseSchema>;
53
+ export type MemoriesListQuery = z.infer<typeof memoriesListQuerySchema>;
54
+ export type MemoriesListResponse = z.infer<typeof memoriesListResponseSchema>;
55
+ export type CreateMemoryBody = z.input<typeof createMemoryBodySchema>;
56
+ export type UpdateMemoryBody = z.infer<typeof updateMemoryBodySchema>;
@@ -0,0 +1,62 @@
1
+ import { z } from "zod";
2
+ import { cursorSchema, paginatedResponseSchema } from "../api.js";
3
+ import { agentIdSchema, memoryIdSchema, tenantIdSchema } from "../ids.js";
4
+ import { DEFAULT_MEMORIES_LIST_LIMIT, MAX_MEMORIES_LIST_LIMIT, MAX_MEMORY_TEXT_BYTES, } from "../limitations.js";
5
+ import { userIdSchema } from "./attribution.js";
6
+ /**
7
+ * Memory — a single Agent-owned text row (Agent Memories PRD). `userId` is
8
+ * optional Attribution: `''` marks an Agent-general row, stamped at creation
9
+ * and immutable. The record is the full tenant-facing shape; the generated
10
+ * `searchVector` never leaves the database. Text is capped at 10 KiB
11
+ * (bytes, not characters) here for a clean 4xx — the DB `octet_length`
12
+ * check is the hard backstop.
13
+ */
14
+ const textEncoder = new TextEncoder();
15
+ export const memoryTextSchema = z
16
+ .string()
17
+ .min(1)
18
+ .refine((text) => textEncoder.encode(text).length <= MAX_MEMORY_TEXT_BYTES, {
19
+ message: `Memory text must be at most ${MAX_MEMORY_TEXT_BYTES} bytes.`,
20
+ });
21
+ export const memorySchema = z
22
+ .object({
23
+ id: memoryIdSchema,
24
+ tenantId: tenantIdSchema,
25
+ agentId: agentIdSchema,
26
+ userId: userIdSchema,
27
+ text: memoryTextSchema,
28
+ createdAt: z.iso.datetime({ offset: true }),
29
+ updatedAt: z.iso.datetime({ offset: true }),
30
+ lastAccessedAt: z.iso.datetime({ offset: true }),
31
+ })
32
+ .strict();
33
+ export const memoryResponseSchema = z
34
+ .object({
35
+ memory: memorySchema,
36
+ })
37
+ .strict();
38
+ export const memoriesListResponseSchema = paginatedResponseSchema(memorySchema);
39
+ export const memoriesListQuerySchema = z
40
+ .object({
41
+ userId: userIdSchema.optional(),
42
+ search: z.string().trim().min(1).optional(),
43
+ cursor: cursorSchema.optional(),
44
+ limit: z.coerce
45
+ .number()
46
+ .int()
47
+ .min(1)
48
+ .max(MAX_MEMORIES_LIST_LIMIT)
49
+ .default(DEFAULT_MEMORIES_LIST_LIMIT),
50
+ })
51
+ .strict();
52
+ export const createMemoryBodySchema = z
53
+ .object({
54
+ text: memoryTextSchema,
55
+ userId: userIdSchema.default(""),
56
+ })
57
+ .strict();
58
+ export const updateMemoryBodySchema = z
59
+ .object({
60
+ text: memoryTextSchema,
61
+ })
62
+ .strict();
@@ -0,0 +1,61 @@
1
+ import { z } from "zod";
2
+ export interface PromptVariableParseResult {
3
+ invalidVariableNames: string[];
4
+ variables: string[];
5
+ }
6
+ export declare const promptVariableTokenPattern: RegExp;
7
+ export declare const promptVariableNamePattern: RegExp;
8
+ export declare function parsePromptVariables(template: string): PromptVariableParseResult;
9
+ export declare const promptTemplateSchema: z.ZodString;
10
+ export declare const promptSchema: z.ZodObject<{
11
+ id: z.ZodString;
12
+ tenantId: z.ZodString;
13
+ name: z.ZodString;
14
+ template: z.ZodString;
15
+ variables: z.ZodArray<z.ZodString>;
16
+ userId: z.ZodString;
17
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
18
+ createdAt: z.ZodISODateTime;
19
+ updatedAt: z.ZodISODateTime;
20
+ }, z.core.$strict>;
21
+ export declare const promptsResponseSchema: z.ZodObject<{
22
+ prompts: z.ZodArray<z.ZodObject<{
23
+ id: z.ZodString;
24
+ tenantId: z.ZodString;
25
+ name: z.ZodString;
26
+ template: z.ZodString;
27
+ variables: z.ZodArray<z.ZodString>;
28
+ userId: z.ZodString;
29
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
30
+ createdAt: z.ZodISODateTime;
31
+ updatedAt: z.ZodISODateTime;
32
+ }, z.core.$strict>>;
33
+ }, z.core.$strict>;
34
+ export declare const promptResponseSchema: z.ZodObject<{
35
+ id: z.ZodString;
36
+ tenantId: z.ZodString;
37
+ name: z.ZodString;
38
+ template: z.ZodString;
39
+ variables: z.ZodArray<z.ZodString>;
40
+ userId: z.ZodString;
41
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
42
+ createdAt: z.ZodISODateTime;
43
+ updatedAt: z.ZodISODateTime;
44
+ }, z.core.$strict>;
45
+ export declare const createPromptBodySchema: z.ZodObject<{
46
+ name: z.ZodString;
47
+ template: z.ZodString;
48
+ userId: z.ZodDefault<z.ZodString>;
49
+ metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
50
+ }, z.core.$strict>;
51
+ export declare const updatePromptBodySchema: z.ZodObject<{
52
+ name: z.ZodOptional<z.ZodString>;
53
+ template: z.ZodOptional<z.ZodString>;
54
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
55
+ }, z.core.$strict>;
56
+ export declare function renderPromptTemplate(template: string, values: Record<string, string>): string;
57
+ export type Prompt = z.infer<typeof promptSchema>;
58
+ export type PromptsResponse = z.infer<typeof promptsResponseSchema>;
59
+ export type PromptResponse = z.infer<typeof promptResponseSchema>;
60
+ export type CreatePromptBody = z.input<typeof createPromptBodySchema>;
61
+ export type UpdatePromptBody = z.infer<typeof updatePromptBodySchema>;