@mastra/server 0.20.1-alpha.3 → 0.20.1

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 (48) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/{chunk-TMU7NSW7.js → chunk-HKW2536J.js} +5852 -2557
  3. package/dist/chunk-HKW2536J.js.map +1 -0
  4. package/dist/{chunk-AFJBHPHA.cjs → chunk-KJJA7GPJ.cjs} +6308 -2994
  5. package/dist/chunk-KJJA7GPJ.cjs.map +1 -0
  6. package/dist/server/handlers/agent-builder.cjs +16 -16
  7. package/dist/server/handlers/agent-builder.js +1 -1
  8. package/dist/server/handlers.cjs +2 -2
  9. package/dist/server/handlers.js +1 -1
  10. package/package.json +6 -6
  11. package/dist/chunk-44GFD2TF.js +0 -419
  12. package/dist/chunk-44GFD2TF.js.map +0 -1
  13. package/dist/chunk-75KU7JB6.cjs +0 -588
  14. package/dist/chunk-75KU7JB6.cjs.map +0 -1
  15. package/dist/chunk-77TGJGDW.cjs +0 -1279
  16. package/dist/chunk-77TGJGDW.cjs.map +0 -1
  17. package/dist/chunk-AFJBHPHA.cjs.map +0 -1
  18. package/dist/chunk-CHDN4NEY.js +0 -1277
  19. package/dist/chunk-CHDN4NEY.js.map +0 -1
  20. package/dist/chunk-EAIAF7Z6.js +0 -571
  21. package/dist/chunk-EAIAF7Z6.js.map +0 -1
  22. package/dist/chunk-TMU7NSW7.js.map +0 -1
  23. package/dist/chunk-WO2SYFUI.js +0 -5945
  24. package/dist/chunk-WO2SYFUI.js.map +0 -1
  25. package/dist/chunk-XCR65STK.cjs +0 -433
  26. package/dist/chunk-XCR65STK.cjs.map +0 -1
  27. package/dist/chunk-YWACVZRO.cjs +0 -5985
  28. package/dist/chunk-YWACVZRO.cjs.map +0 -1
  29. package/dist/dist-36GPHJSB.cjs +0 -2014
  30. package/dist/dist-36GPHJSB.cjs.map +0 -1
  31. package/dist/dist-3WEYC4YO.js +0 -2007
  32. package/dist/dist-3WEYC4YO.js.map +0 -1
  33. package/dist/dist-7MBYKZSM.js +0 -846
  34. package/dist/dist-7MBYKZSM.js.map +0 -1
  35. package/dist/dist-FGYSUA65.cjs +0 -935
  36. package/dist/dist-FGYSUA65.cjs.map +0 -1
  37. package/dist/dist-FNKPY5I5.cjs +0 -1412
  38. package/dist/dist-FNKPY5I5.cjs.map +0 -1
  39. package/dist/dist-H5ZHQKYG.js +0 -3
  40. package/dist/dist-H5ZHQKYG.js.map +0 -1
  41. package/dist/dist-HBUYSRRO.cjs +0 -850
  42. package/dist/dist-HBUYSRRO.cjs.map +0 -1
  43. package/dist/dist-IUCBLZK6.js +0 -1409
  44. package/dist/dist-IUCBLZK6.js.map +0 -1
  45. package/dist/dist-M4HXCUXC.cjs +0 -20
  46. package/dist/dist-M4HXCUXC.cjs.map +0 -1
  47. package/dist/dist-P32YPL35.js +0 -932
  48. package/dist/dist-P32YPL35.js.map +0 -1
@@ -1,571 +0,0 @@
1
- import { InvalidArgumentError, LoadAPIKeyError, APICallError, EmptyResponseBodyError, TypeValidationError, JSONParseError, EventSourceParserStream } from './chunk-44GFD2TF.js';
2
-
3
- function combineHeaders(...headers) {
4
- return headers.reduce(
5
- (combinedHeaders, currentHeaders) => ({
6
- ...combinedHeaders,
7
- ...currentHeaders != null ? currentHeaders : {}
8
- }),
9
- {}
10
- );
11
- }
12
- function extractResponseHeaders(response) {
13
- return Object.fromEntries([...response.headers]);
14
- }
15
- var createIdGenerator = ({
16
- prefix,
17
- size = 16,
18
- alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
19
- separator = "-"
20
- } = {}) => {
21
- const generator = () => {
22
- const alphabetLength = alphabet.length;
23
- const chars = new Array(size);
24
- for (let i = 0; i < size; i++) {
25
- chars[i] = alphabet[Math.random() * alphabetLength | 0];
26
- }
27
- return chars.join("");
28
- };
29
- if (prefix == null) {
30
- return generator;
31
- }
32
- if (alphabet.includes(separator)) {
33
- throw new InvalidArgumentError({
34
- argument: "separator",
35
- message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
36
- });
37
- }
38
- return () => `${prefix}${separator}${generator()}`;
39
- };
40
- var generateId = createIdGenerator();
41
- function isAbortError(error) {
42
- return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
43
- error.name === "TimeoutError");
44
- }
45
- var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
46
- function handleFetchError({
47
- error,
48
- url,
49
- requestBodyValues
50
- }) {
51
- if (isAbortError(error)) {
52
- return error;
53
- }
54
- if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES.includes(error.message.toLowerCase())) {
55
- const cause = error.cause;
56
- if (cause != null) {
57
- return new APICallError({
58
- message: `Cannot connect to API: ${cause.message}`,
59
- cause,
60
- url,
61
- requestBodyValues,
62
- isRetryable: true
63
- // retry when network error
64
- });
65
- }
66
- }
67
- return error;
68
- }
69
- function removeUndefinedEntries(record) {
70
- return Object.fromEntries(
71
- Object.entries(record).filter(([_key, value]) => value != null)
72
- );
73
- }
74
- function loadApiKey({
75
- apiKey,
76
- environmentVariableName,
77
- apiKeyParameterName = "apiKey",
78
- description
79
- }) {
80
- if (typeof apiKey === "string") {
81
- return apiKey;
82
- }
83
- if (apiKey != null) {
84
- throw new LoadAPIKeyError({
85
- message: `${description} API key must be a string.`
86
- });
87
- }
88
- if (typeof process === "undefined") {
89
- throw new LoadAPIKeyError({
90
- message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
91
- });
92
- }
93
- apiKey = process.env[environmentVariableName];
94
- if (apiKey == null) {
95
- throw new LoadAPIKeyError({
96
- message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
97
- });
98
- }
99
- if (typeof apiKey !== "string") {
100
- throw new LoadAPIKeyError({
101
- message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
102
- });
103
- }
104
- return apiKey;
105
- }
106
- var suspectProtoRx = /"__proto__"\s*:/;
107
- var suspectConstructorRx = /"constructor"\s*:/;
108
- function _parse(text) {
109
- const obj = JSON.parse(text);
110
- if (obj === null || typeof obj !== "object") {
111
- return obj;
112
- }
113
- if (suspectProtoRx.test(text) === false && suspectConstructorRx.test(text) === false) {
114
- return obj;
115
- }
116
- return filter(obj);
117
- }
118
- function filter(obj) {
119
- let next = [obj];
120
- while (next.length) {
121
- const nodes = next;
122
- next = [];
123
- for (const node of nodes) {
124
- if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
125
- throw new SyntaxError("Object contains forbidden prototype property");
126
- }
127
- if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
128
- throw new SyntaxError("Object contains forbidden prototype property");
129
- }
130
- for (const key in node) {
131
- const value = node[key];
132
- if (value && typeof value === "object") {
133
- next.push(value);
134
- }
135
- }
136
- }
137
- }
138
- return obj;
139
- }
140
- function secureJsonParse(text) {
141
- const { stackTraceLimit } = Error;
142
- Error.stackTraceLimit = 0;
143
- try {
144
- return _parse(text);
145
- } finally {
146
- Error.stackTraceLimit = stackTraceLimit;
147
- }
148
- }
149
- var validatorSymbol = Symbol.for("vercel.ai.validator");
150
- function validator(validate) {
151
- return { [validatorSymbol]: true, validate };
152
- }
153
- function isValidator(value) {
154
- return typeof value === "object" && value !== null && validatorSymbol in value && value[validatorSymbol] === true && "validate" in value;
155
- }
156
- function asValidator(value) {
157
- return isValidator(value) ? value : standardSchemaValidator(value);
158
- }
159
- function standardSchemaValidator(standardSchema) {
160
- return validator(async (value) => {
161
- const result = await standardSchema["~standard"].validate(value);
162
- return result.issues == null ? { success: true, value: result.value } : {
163
- success: false,
164
- error: new TypeValidationError({
165
- value,
166
- cause: result.issues
167
- })
168
- };
169
- });
170
- }
171
- async function validateTypes({
172
- value,
173
- schema
174
- }) {
175
- const result = await safeValidateTypes({ value, schema });
176
- if (!result.success) {
177
- throw TypeValidationError.wrap({ value, cause: result.error });
178
- }
179
- return result.value;
180
- }
181
- async function safeValidateTypes({
182
- value,
183
- schema
184
- }) {
185
- const validator2 = asValidator(schema);
186
- try {
187
- if (validator2.validate == null) {
188
- return { success: true, value, rawValue: value };
189
- }
190
- const result = await validator2.validate(value);
191
- if (result.success) {
192
- return { success: true, value: result.value, rawValue: value };
193
- }
194
- return {
195
- success: false,
196
- error: TypeValidationError.wrap({ value, cause: result.error }),
197
- rawValue: value
198
- };
199
- } catch (error) {
200
- return {
201
- success: false,
202
- error: TypeValidationError.wrap({ value, cause: error }),
203
- rawValue: value
204
- };
205
- }
206
- }
207
- async function parseJSON({
208
- text,
209
- schema
210
- }) {
211
- try {
212
- const value = secureJsonParse(text);
213
- if (schema == null) {
214
- return value;
215
- }
216
- return validateTypes({ value, schema });
217
- } catch (error) {
218
- if (JSONParseError.isInstance(error) || TypeValidationError.isInstance(error)) {
219
- throw error;
220
- }
221
- throw new JSONParseError({ text, cause: error });
222
- }
223
- }
224
- async function safeParseJSON({
225
- text,
226
- schema
227
- }) {
228
- try {
229
- const value = secureJsonParse(text);
230
- if (schema == null) {
231
- return { success: true, value, rawValue: value };
232
- }
233
- return await safeValidateTypes({ value, schema });
234
- } catch (error) {
235
- return {
236
- success: false,
237
- error: JSONParseError.isInstance(error) ? error : new JSONParseError({ text, cause: error }),
238
- rawValue: void 0
239
- };
240
- }
241
- }
242
- function isParsableJson(input) {
243
- try {
244
- secureJsonParse(input);
245
- return true;
246
- } catch (e) {
247
- return false;
248
- }
249
- }
250
- function parseJsonEventStream({
251
- stream,
252
- schema
253
- }) {
254
- return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).pipeThrough(
255
- new TransformStream({
256
- async transform({ data }, controller) {
257
- if (data === "[DONE]") {
258
- return;
259
- }
260
- controller.enqueue(await safeParseJSON({ text: data, schema }));
261
- }
262
- })
263
- );
264
- }
265
- async function parseProviderOptions({
266
- provider,
267
- providerOptions,
268
- schema
269
- }) {
270
- if ((providerOptions == null ? void 0 : providerOptions[provider]) == null) {
271
- return void 0;
272
- }
273
- const parsedProviderOptions = await safeValidateTypes({
274
- value: providerOptions[provider],
275
- schema
276
- });
277
- if (!parsedProviderOptions.success) {
278
- throw new InvalidArgumentError({
279
- argument: "providerOptions",
280
- message: `invalid ${provider} provider options`,
281
- cause: parsedProviderOptions.error
282
- });
283
- }
284
- return parsedProviderOptions.value;
285
- }
286
- var getOriginalFetch2 = () => globalThis.fetch;
287
- var postJsonToApi = async ({
288
- url,
289
- headers,
290
- body,
291
- failedResponseHandler,
292
- successfulResponseHandler,
293
- abortSignal,
294
- fetch
295
- }) => postToApi({
296
- url,
297
- headers: {
298
- "Content-Type": "application/json",
299
- ...headers
300
- },
301
- body: {
302
- content: JSON.stringify(body),
303
- values: body
304
- },
305
- failedResponseHandler,
306
- successfulResponseHandler,
307
- abortSignal,
308
- fetch
309
- });
310
- var postFormDataToApi = async ({
311
- url,
312
- headers,
313
- formData,
314
- failedResponseHandler,
315
- successfulResponseHandler,
316
- abortSignal,
317
- fetch
318
- }) => postToApi({
319
- url,
320
- headers,
321
- body: {
322
- content: formData,
323
- values: Object.fromEntries(formData.entries())
324
- },
325
- failedResponseHandler,
326
- successfulResponseHandler,
327
- abortSignal,
328
- fetch
329
- });
330
- var postToApi = async ({
331
- url,
332
- headers = {},
333
- body,
334
- successfulResponseHandler,
335
- failedResponseHandler,
336
- abortSignal,
337
- fetch = getOriginalFetch2()
338
- }) => {
339
- try {
340
- const response = await fetch(url, {
341
- method: "POST",
342
- headers: removeUndefinedEntries(headers),
343
- body: body.content,
344
- signal: abortSignal
345
- });
346
- const responseHeaders = extractResponseHeaders(response);
347
- if (!response.ok) {
348
- let errorInformation;
349
- try {
350
- errorInformation = await failedResponseHandler({
351
- response,
352
- url,
353
- requestBodyValues: body.values
354
- });
355
- } catch (error) {
356
- if (isAbortError(error) || APICallError.isInstance(error)) {
357
- throw error;
358
- }
359
- throw new APICallError({
360
- message: "Failed to process error response",
361
- cause: error,
362
- statusCode: response.status,
363
- url,
364
- responseHeaders,
365
- requestBodyValues: body.values
366
- });
367
- }
368
- throw errorInformation.value;
369
- }
370
- try {
371
- return await successfulResponseHandler({
372
- response,
373
- url,
374
- requestBodyValues: body.values
375
- });
376
- } catch (error) {
377
- if (error instanceof Error) {
378
- if (isAbortError(error) || APICallError.isInstance(error)) {
379
- throw error;
380
- }
381
- }
382
- throw new APICallError({
383
- message: "Failed to process successful response",
384
- cause: error,
385
- statusCode: response.status,
386
- url,
387
- responseHeaders,
388
- requestBodyValues: body.values
389
- });
390
- }
391
- } catch (error) {
392
- throw handleFetchError({ error, url, requestBodyValues: body.values });
393
- }
394
- };
395
- function tool(tool2) {
396
- return tool2;
397
- }
398
- function createProviderDefinedToolFactory({
399
- id,
400
- name,
401
- inputSchema
402
- }) {
403
- return ({
404
- execute,
405
- outputSchema,
406
- toModelOutput,
407
- onInputStart,
408
- onInputDelta,
409
- onInputAvailable,
410
- ...args
411
- }) => tool({
412
- type: "provider-defined",
413
- id,
414
- name,
415
- args,
416
- inputSchema,
417
- outputSchema,
418
- execute,
419
- toModelOutput,
420
- onInputStart,
421
- onInputDelta,
422
- onInputAvailable
423
- });
424
- }
425
- function createProviderDefinedToolFactoryWithOutputSchema({
426
- id,
427
- name,
428
- inputSchema,
429
- outputSchema
430
- }) {
431
- return ({
432
- execute,
433
- toModelOutput,
434
- onInputStart,
435
- onInputDelta,
436
- onInputAvailable,
437
- ...args
438
- }) => tool({
439
- type: "provider-defined",
440
- id,
441
- name,
442
- args,
443
- inputSchema,
444
- outputSchema,
445
- execute,
446
- toModelOutput,
447
- onInputStart,
448
- onInputDelta,
449
- onInputAvailable
450
- });
451
- }
452
- async function resolve(value) {
453
- if (typeof value === "function") {
454
- value = value();
455
- }
456
- return Promise.resolve(value);
457
- }
458
- var createJsonErrorResponseHandler = ({
459
- errorSchema,
460
- errorToMessage,
461
- isRetryable
462
- }) => async ({ response, url, requestBodyValues }) => {
463
- const responseBody = await response.text();
464
- const responseHeaders = extractResponseHeaders(response);
465
- if (responseBody.trim() === "") {
466
- return {
467
- responseHeaders,
468
- value: new APICallError({
469
- message: response.statusText,
470
- url,
471
- requestBodyValues,
472
- statusCode: response.status,
473
- responseHeaders,
474
- responseBody,
475
- isRetryable: isRetryable == null ? void 0 : isRetryable(response)
476
- })
477
- };
478
- }
479
- try {
480
- const parsedError = await parseJSON({
481
- text: responseBody,
482
- schema: errorSchema
483
- });
484
- return {
485
- responseHeaders,
486
- value: new APICallError({
487
- message: errorToMessage(parsedError),
488
- url,
489
- requestBodyValues,
490
- statusCode: response.status,
491
- responseHeaders,
492
- responseBody,
493
- data: parsedError,
494
- isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
495
- })
496
- };
497
- } catch (parseError) {
498
- return {
499
- responseHeaders,
500
- value: new APICallError({
501
- message: response.statusText,
502
- url,
503
- requestBodyValues,
504
- statusCode: response.status,
505
- responseHeaders,
506
- responseBody,
507
- isRetryable: isRetryable == null ? void 0 : isRetryable(response)
508
- })
509
- };
510
- }
511
- };
512
- var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
513
- const responseHeaders = extractResponseHeaders(response);
514
- if (response.body == null) {
515
- throw new EmptyResponseBodyError({});
516
- }
517
- return {
518
- responseHeaders,
519
- value: parseJsonEventStream({
520
- stream: response.body,
521
- schema: chunkSchema
522
- })
523
- };
524
- };
525
- var createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
526
- const responseBody = await response.text();
527
- const parsedResult = await safeParseJSON({
528
- text: responseBody,
529
- schema: responseSchema
530
- });
531
- const responseHeaders = extractResponseHeaders(response);
532
- if (!parsedResult.success) {
533
- throw new APICallError({
534
- message: "Invalid JSON response",
535
- cause: parsedResult.error,
536
- statusCode: response.status,
537
- responseHeaders,
538
- responseBody,
539
- url,
540
- requestBodyValues
541
- });
542
- }
543
- return {
544
- responseHeaders,
545
- value: parsedResult.value,
546
- rawValue: parsedResult.rawValue
547
- };
548
- };
549
- var { btoa, atob } = globalThis;
550
- function convertBase64ToUint8Array(base64String) {
551
- const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
552
- const latin1string = atob(base64Url);
553
- return Uint8Array.from(latin1string, (byte) => byte.codePointAt(0));
554
- }
555
- function convertUint8ArrayToBase64(array) {
556
- let latin1string = "";
557
- for (let i = 0; i < array.length; i++) {
558
- latin1string += String.fromCodePoint(array[i]);
559
- }
560
- return btoa(latin1string);
561
- }
562
- function convertToBase64(value) {
563
- return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
564
- }
565
- function withoutTrailingSlash(url) {
566
- return url == null ? void 0 : url.replace(/\/$/, "");
567
- }
568
-
569
- export { combineHeaders, convertBase64ToUint8Array, convertToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, generateId, isParsableJson, loadApiKey, parseProviderOptions, postFormDataToApi, postJsonToApi, resolve, withoutTrailingSlash };
570
- //# sourceMappingURL=chunk-EAIAF7Z6.js.map
571
- //# sourceMappingURL=chunk-EAIAF7Z6.js.map