@mastra/core 0.10.3 → 0.10.4-alpha.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.
- package/dist/agent/index.cjs +4 -4
- package/dist/agent/index.d.cts +4 -3
- package/dist/agent/index.d.ts +4 -3
- package/dist/agent/index.js +2 -2
- package/dist/{base-Dmg7H-Iz.d.cts → base-BBs8xtlU.d.cts} +71 -6
- package/dist/{base-BY9WFI65.d.cts → base-Bi9KB0TN.d.ts} +19 -3
- package/dist/{base-C0yUw8BC.d.ts → base-CO-L7hF9.d.cts} +19 -3
- package/dist/{base-Bdo-CPMn.d.ts → base-DKqdQHNd.d.ts} +71 -6
- package/dist/base.cjs +2 -2
- package/dist/base.d.cts +3 -2
- package/dist/base.d.ts +3 -2
- package/dist/base.js +1 -1
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.d.cts +3 -2
- package/dist/bundler/index.d.ts +3 -2
- package/dist/bundler/index.js +1 -1
- package/dist/{chunk-NMDM4IZN.cjs → chunk-2D7NOO7S.cjs} +16 -11
- package/dist/{chunk-EWDGXKOQ.js → chunk-36UICULV.js} +2 -1
- package/dist/{chunk-JOCKZ2US.js → chunk-5IEKR756.js} +1 -1
- package/dist/{chunk-XXVGT7SJ.js → chunk-5YDTZN2X.js} +32 -9
- package/dist/{chunk-4TEWSQS5.js → chunk-6FYLLPWK.js} +1 -1
- package/dist/chunk-7LRIVP5A.cjs +138 -0
- package/dist/{chunk-FLPSXJWQ.js → chunk-7UNDRBOU.js} +2 -2
- package/dist/{chunk-DTJ4KVHM.js → chunk-ATXBSEFT.js} +1 -1
- package/dist/chunk-BBAQW23O.cjs +68 -0
- package/dist/{chunk-OBEALYTK.js → chunk-DO5R43AJ.js} +16 -11
- package/dist/{chunk-5EB62G6T.js → chunk-DU32FMDF.js} +3 -3
- package/dist/{chunk-CYJF6U6B.cjs → chunk-FEYYOBBG.cjs} +2 -2
- package/dist/{chunk-K7BZ4VXX.js → chunk-GSELXPJC.js} +3 -3
- package/dist/{chunk-SH2C4VTJ.cjs → chunk-GV6P24NY.cjs} +25 -14
- package/dist/{chunk-FHLDRRKJ.cjs → chunk-H5IRI46R.cjs} +3 -3
- package/dist/{chunk-FGBS7VRU.js → chunk-HFEELWJO.js} +33 -23
- package/dist/{chunk-PMAVDBJY.js → chunk-IM7CLVLZ.js} +1 -1
- package/dist/{chunk-TIPFGQCO.js → chunk-IZGRJXUQ.js} +19 -8
- package/dist/{chunk-XJCP3SLA.js → chunk-JNMQKJH4.js} +1 -1
- package/dist/{chunk-3JGO7S6X.cjs → chunk-JYLH5IY3.cjs} +4 -4
- package/dist/{chunk-TAHSAZUN.cjs → chunk-LEK3J7YN.cjs} +2 -2
- package/dist/{chunk-B4TMM6NT.js → chunk-MGOJI66G.js} +25 -9
- package/dist/{chunk-ERUGEZPR.cjs → chunk-NFGQDPZL.cjs} +2 -2
- package/dist/{chunk-7MWWPVCE.js → chunk-NWJWIOVO.js} +48 -2
- package/dist/{chunk-MVXVUMLA.cjs → chunk-OKHKG5C7.cjs} +42 -26
- package/dist/{chunk-VHZPWE5L.cjs → chunk-P3Q73CAW.cjs} +6 -6
- package/dist/chunk-PVGSY24V.js +63 -0
- package/dist/chunk-QVROTSA5.cjs +408 -0
- package/dist/{chunk-VBSKHNCY.cjs → chunk-RO5VPM3P.cjs} +39 -29
- package/dist/{chunk-LMTSGD2E.cjs → chunk-RORSYAKV.cjs} +7 -7
- package/dist/{chunk-HZ7ME4LD.cjs → chunk-S6WRT7GI.cjs} +4 -4
- package/dist/{chunk-ZPOETARN.js → chunk-SI2ENZ3O.js} +2 -2
- package/dist/chunk-TRJIWZKM.js +390 -0
- package/dist/{chunk-IBIGJYTD.cjs → chunk-UJODXBBX.cjs} +8 -8
- package/dist/{chunk-677GIYFF.js → chunk-YCYAVLYR.js} +1 -1
- package/dist/{chunk-TICDQWVJ.cjs → chunk-ZAXPU6F2.cjs} +2 -1
- package/dist/{chunk-RFAN7FAT.cjs → chunk-ZIZ3CVHN.cjs} +32 -9
- package/dist/{chunk-PKYG5CWB.cjs → chunk-ZZLBNB3U.cjs} +2 -2
- package/dist/deployer/index.cjs +2 -2
- package/dist/deployer/index.d.cts +3 -2
- package/dist/deployer/index.d.ts +3 -2
- package/dist/deployer/index.js +1 -1
- package/dist/error/index.cjs +19 -72
- package/dist/error/index.d.cts +25 -31
- package/dist/error/index.d.ts +25 -31
- package/dist/error/index.js +1 -70
- package/dist/eval/index.d.cts +4 -3
- package/dist/eval/index.d.ts +4 -3
- package/dist/index.cjs +58 -58
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +14 -14
- package/dist/integration/index.d.cts +4 -3
- package/dist/integration/index.d.ts +4 -3
- package/dist/llm/index.d.cts +4 -3
- package/dist/llm/index.d.ts +4 -3
- package/dist/logger/index.cjs +10 -10
- package/dist/logger/index.d.cts +60 -7
- package/dist/logger/index.d.ts +60 -7
- package/dist/logger/index.js +2 -2
- package/dist/logger-CpL0z5v_.d.cts +158 -0
- package/dist/logger-DtVDdb81.d.ts +158 -0
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.cts +5 -4
- package/dist/mastra/index.d.ts +5 -4
- package/dist/mastra/index.js +1 -1
- package/dist/mcp/index.cjs +4 -4
- package/dist/mcp/index.d.cts +5 -4
- package/dist/mcp/index.d.ts +5 -4
- package/dist/mcp/index.js +3 -3
- package/dist/memory/index.cjs +4 -4
- package/dist/memory/index.d.cts +4 -3
- package/dist/memory/index.d.ts +4 -3
- package/dist/memory/index.js +1 -1
- package/dist/network/index.cjs +6 -6
- package/dist/network/index.d.cts +4 -3
- package/dist/network/index.d.ts +4 -3
- package/dist/network/index.js +3 -3
- package/dist/relevance/index.cjs +4 -4
- package/dist/relevance/index.d.cts +5 -4
- package/dist/relevance/index.d.ts +5 -4
- package/dist/relevance/index.js +1 -1
- package/dist/server/index.cjs +4 -4
- package/dist/server/index.d.cts +5 -4
- package/dist/server/index.d.ts +5 -4
- package/dist/server/index.js +2 -2
- package/dist/storage/index.cjs +17 -12
- package/dist/storage/index.d.cts +11 -5
- package/dist/storage/index.d.ts +11 -5
- package/dist/storage/index.js +9 -4
- package/dist/telemetry/index.cjs +7 -7
- package/dist/telemetry/index.d.cts +4 -3
- package/dist/telemetry/index.d.ts +4 -3
- package/dist/telemetry/index.js +1 -1
- package/dist/tools/index.d.cts +6 -5
- package/dist/tools/index.d.ts +6 -5
- package/dist/tts/index.cjs +2 -2
- package/dist/tts/index.d.cts +3 -2
- package/dist/tts/index.d.ts +3 -2
- package/dist/tts/index.js +1 -1
- package/dist/utils.cjs +14 -14
- package/dist/utils.d.cts +4 -3
- package/dist/utils.d.ts +4 -3
- package/dist/utils.js +1 -1
- package/dist/vector/index.cjs +2 -2
- package/dist/vector/index.d.cts +3 -2
- package/dist/vector/index.d.ts +3 -2
- package/dist/vector/index.js +1 -1
- package/dist/voice/index.cjs +4 -4
- package/dist/voice/index.d.cts +4 -3
- package/dist/voice/index.d.ts +4 -3
- package/dist/voice/index.js +1 -1
- package/dist/workflows/index.cjs +9 -9
- package/dist/workflows/index.d.cts +5 -4
- package/dist/workflows/index.d.ts +5 -4
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/legacy/index.cjs +22 -22
- package/dist/workflows/legacy/index.d.cts +5 -4
- package/dist/workflows/legacy/index.d.ts +5 -4
- package/dist/workflows/legacy/index.js +1 -1
- package/package.json +10 -11
- package/dist/chunk-WWLMZIHW.cjs +0 -995
- package/dist/chunk-X6VHQCYN.cjs +0 -92
- package/dist/chunk-Y5BGCPNZ.js +0 -977
- package/dist/logger-BF2Sn7JX.d.cts +0 -79
- package/dist/logger-BF2Sn7JX.d.ts +0 -79
package/dist/chunk-WWLMZIHW.cjs
DELETED
|
@@ -1,995 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunk4Z3OU5RY_cjs = require('./chunk-4Z3OU5RY.cjs');
|
|
4
|
-
var chunkVHZPWE5L_cjs = require('./chunk-VHZPWE5L.cjs');
|
|
5
|
-
var chunkLABUWBKX_cjs = require('./chunk-LABUWBKX.cjs');
|
|
6
|
-
var crypto = require('crypto');
|
|
7
|
-
var jsonSchemaToZod = require('json-schema-to-zod');
|
|
8
|
-
var zod = require('zod');
|
|
9
|
-
var ai = require('ai');
|
|
10
|
-
var zodFromJsonSchema = require('zod-from-json-schema');
|
|
11
|
-
var zodToJsonSchema = require('zod-to-json-schema');
|
|
12
|
-
|
|
13
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
|
|
15
|
-
var jsonSchemaToZod__default = /*#__PURE__*/_interopDefault(jsonSchemaToZod);
|
|
16
|
-
|
|
17
|
-
var ALL_STRING_CHECKS = ["regex", "emoji", "email", "url", "uuid", "cuid", "min", "max"];
|
|
18
|
-
var ALL_NUMBER_CHECKS = [
|
|
19
|
-
"min",
|
|
20
|
-
// gte internally
|
|
21
|
-
"max",
|
|
22
|
-
// lte internally
|
|
23
|
-
"multipleOf"
|
|
24
|
-
];
|
|
25
|
-
var ALL_ARRAY_CHECKS = ["min", "max", "length"];
|
|
26
|
-
var UNSUPPORTED_ZOD_TYPES = ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
|
|
27
|
-
var SUPPORTED_ZOD_TYPES = [
|
|
28
|
-
"ZodObject",
|
|
29
|
-
"ZodArray",
|
|
30
|
-
"ZodUnion",
|
|
31
|
-
"ZodString",
|
|
32
|
-
"ZodNumber",
|
|
33
|
-
"ZodDate",
|
|
34
|
-
"ZodAny",
|
|
35
|
-
"ZodDefault"
|
|
36
|
-
];
|
|
37
|
-
var ToolCompatibility = class extends chunkVHZPWE5L_cjs.MastraBase {
|
|
38
|
-
model;
|
|
39
|
-
constructor(model) {
|
|
40
|
-
super({ name: "SchemaCompatibility" });
|
|
41
|
-
this.model = model;
|
|
42
|
-
}
|
|
43
|
-
getModel() {
|
|
44
|
-
return this.model;
|
|
45
|
-
}
|
|
46
|
-
applyZodSchemaCompatibility(zodSchema2) {
|
|
47
|
-
const newSchema = zod.z.object(
|
|
48
|
-
Object.entries(zodSchema2.shape || {}).reduce(
|
|
49
|
-
(acc, [key, value]) => ({
|
|
50
|
-
...acc,
|
|
51
|
-
[key]: this.processZodType(value)
|
|
52
|
-
}),
|
|
53
|
-
{}
|
|
54
|
-
)
|
|
55
|
-
);
|
|
56
|
-
return { schema: newSchema };
|
|
57
|
-
}
|
|
58
|
-
defaultZodObjectHandler(value) {
|
|
59
|
-
const zodObject = value;
|
|
60
|
-
const processedShape = Object.entries(zodObject.shape || {}).reduce(
|
|
61
|
-
(acc, [key, propValue]) => {
|
|
62
|
-
const typedPropValue = propValue;
|
|
63
|
-
const processedValue = this.processZodType(typedPropValue);
|
|
64
|
-
acc[key] = processedValue;
|
|
65
|
-
return acc;
|
|
66
|
-
},
|
|
67
|
-
{}
|
|
68
|
-
);
|
|
69
|
-
let result = zod.z.object(processedShape);
|
|
70
|
-
if (value.description) {
|
|
71
|
-
result = result.describe(value.description);
|
|
72
|
-
}
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
mergeParameterDescription(description, constraints) {
|
|
76
|
-
if (Object.keys(constraints).length > 0) {
|
|
77
|
-
return (description ? description + "\n" : "") + JSON.stringify(constraints);
|
|
78
|
-
} else {
|
|
79
|
-
return description;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
defaultUnsupportedZodTypeHandler(value, throwOnTypes = UNSUPPORTED_ZOD_TYPES) {
|
|
83
|
-
if (throwOnTypes.includes(value._def.typeName)) {
|
|
84
|
-
throw new Error(`${this.model.modelId} does not support zod type: ${value._def.typeName}`);
|
|
85
|
-
}
|
|
86
|
-
return value;
|
|
87
|
-
}
|
|
88
|
-
defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS) {
|
|
89
|
-
const zodArray = value._def;
|
|
90
|
-
const arrayType = zodArray.type;
|
|
91
|
-
const constraints = {};
|
|
92
|
-
if (zodArray.minLength?.value !== void 0 && handleChecks.includes("min")) {
|
|
93
|
-
constraints.minLength = zodArray.minLength.value;
|
|
94
|
-
}
|
|
95
|
-
if (zodArray.maxLength?.value !== void 0 && handleChecks.includes("max")) {
|
|
96
|
-
constraints.maxLength = zodArray.maxLength.value;
|
|
97
|
-
}
|
|
98
|
-
if (zodArray.exactLength?.value !== void 0 && handleChecks.includes("length")) {
|
|
99
|
-
constraints.exactLength = zodArray.exactLength.value;
|
|
100
|
-
}
|
|
101
|
-
const processedType = arrayType._def.typeName === "ZodObject" ? this.processZodType(arrayType) : arrayType;
|
|
102
|
-
let result = zod.z.array(processedType);
|
|
103
|
-
if (zodArray.minLength?.value !== void 0 && !handleChecks.includes("min")) {
|
|
104
|
-
result = result.min(zodArray.minLength.value);
|
|
105
|
-
}
|
|
106
|
-
if (zodArray.maxLength?.value !== void 0 && !handleChecks.includes("max")) {
|
|
107
|
-
result = result.max(zodArray.maxLength.value);
|
|
108
|
-
}
|
|
109
|
-
if (zodArray.exactLength?.value !== void 0 && !handleChecks.includes("length")) {
|
|
110
|
-
result = result.length(zodArray.exactLength.value);
|
|
111
|
-
}
|
|
112
|
-
const description = this.mergeParameterDescription(value.description, constraints);
|
|
113
|
-
if (description) {
|
|
114
|
-
result = result.describe(description);
|
|
115
|
-
}
|
|
116
|
-
return result;
|
|
117
|
-
}
|
|
118
|
-
defaultZodUnionHandler(value) {
|
|
119
|
-
const zodUnion = value;
|
|
120
|
-
const processedOptions = zodUnion._def.options.map((option) => this.processZodType(option));
|
|
121
|
-
if (processedOptions.length < 2) throw new Error("Union must have at least 2 options");
|
|
122
|
-
let result = zod.z.union(processedOptions);
|
|
123
|
-
if (value.description) {
|
|
124
|
-
result = result.describe(value.description);
|
|
125
|
-
}
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS) {
|
|
129
|
-
const zodString = value;
|
|
130
|
-
const constraints = {};
|
|
131
|
-
const checks = zodString._def.checks || [];
|
|
132
|
-
const newChecks = [];
|
|
133
|
-
for (const check of checks) {
|
|
134
|
-
if ("kind" in check) {
|
|
135
|
-
if (handleChecks.includes(check.kind)) {
|
|
136
|
-
switch (check.kind) {
|
|
137
|
-
case "regex": {
|
|
138
|
-
constraints.regex = {
|
|
139
|
-
pattern: check.regex.source,
|
|
140
|
-
flags: check.regex.flags
|
|
141
|
-
};
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
case "emoji": {
|
|
145
|
-
constraints.emoji = true;
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
case "email": {
|
|
149
|
-
constraints.email = true;
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
case "url": {
|
|
153
|
-
constraints.url = true;
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
case "uuid": {
|
|
157
|
-
constraints.uuid = true;
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
case "cuid": {
|
|
161
|
-
constraints.cuid = true;
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
case "min": {
|
|
165
|
-
constraints.minLength = check.value;
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
case "max": {
|
|
169
|
-
constraints.maxLength = check.value;
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
} else {
|
|
174
|
-
newChecks.push(check);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
let result = zod.z.string();
|
|
179
|
-
for (const check of newChecks) {
|
|
180
|
-
result = result._addCheck(check);
|
|
181
|
-
}
|
|
182
|
-
const description = this.mergeParameterDescription(value.description, constraints);
|
|
183
|
-
if (description) {
|
|
184
|
-
result = result.describe(description);
|
|
185
|
-
}
|
|
186
|
-
return result;
|
|
187
|
-
}
|
|
188
|
-
defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS) {
|
|
189
|
-
const zodNumber = value;
|
|
190
|
-
const constraints = {};
|
|
191
|
-
const checks = zodNumber._def.checks || [];
|
|
192
|
-
const newChecks = [];
|
|
193
|
-
for (const check of checks) {
|
|
194
|
-
if ("kind" in check) {
|
|
195
|
-
if (handleChecks.includes(check.kind)) {
|
|
196
|
-
switch (check.kind) {
|
|
197
|
-
case "min":
|
|
198
|
-
if (check.inclusive) {
|
|
199
|
-
constraints.gte = check.value;
|
|
200
|
-
} else {
|
|
201
|
-
constraints.gt = check.value;
|
|
202
|
-
}
|
|
203
|
-
break;
|
|
204
|
-
case "max":
|
|
205
|
-
if (check.inclusive) {
|
|
206
|
-
constraints.lte = check.value;
|
|
207
|
-
} else {
|
|
208
|
-
constraints.lt = check.value;
|
|
209
|
-
}
|
|
210
|
-
break;
|
|
211
|
-
case "multipleOf": {
|
|
212
|
-
constraints.multipleOf = check.value;
|
|
213
|
-
break;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
} else {
|
|
217
|
-
newChecks.push(check);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
let result = zod.z.number();
|
|
222
|
-
for (const check of newChecks) {
|
|
223
|
-
switch (check.kind) {
|
|
224
|
-
case "int":
|
|
225
|
-
result = result.int();
|
|
226
|
-
break;
|
|
227
|
-
case "finite":
|
|
228
|
-
result = result.finite();
|
|
229
|
-
break;
|
|
230
|
-
default:
|
|
231
|
-
result = result._addCheck(check);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
const description = this.mergeParameterDescription(value.description, constraints);
|
|
235
|
-
if (description) {
|
|
236
|
-
result = result.describe(description);
|
|
237
|
-
}
|
|
238
|
-
return result;
|
|
239
|
-
}
|
|
240
|
-
defaultZodDateHandler(value) {
|
|
241
|
-
const zodDate = value;
|
|
242
|
-
const constraints = {};
|
|
243
|
-
const checks = zodDate._def.checks || [];
|
|
244
|
-
for (const check of checks) {
|
|
245
|
-
if ("kind" in check) {
|
|
246
|
-
switch (check.kind) {
|
|
247
|
-
case "min":
|
|
248
|
-
const minDate = new Date(check.value);
|
|
249
|
-
if (!isNaN(minDate.getTime())) {
|
|
250
|
-
constraints.minDate = minDate.toISOString();
|
|
251
|
-
}
|
|
252
|
-
break;
|
|
253
|
-
case "max":
|
|
254
|
-
const maxDate = new Date(check.value);
|
|
255
|
-
if (!isNaN(maxDate.getTime())) {
|
|
256
|
-
constraints.maxDate = maxDate.toISOString();
|
|
257
|
-
}
|
|
258
|
-
break;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
constraints.dateFormat = "date-time";
|
|
263
|
-
let result = zod.z.string().describe("date-time");
|
|
264
|
-
const description = this.mergeParameterDescription(value.description, constraints);
|
|
265
|
-
if (description) {
|
|
266
|
-
result = result.describe(description);
|
|
267
|
-
}
|
|
268
|
-
return result;
|
|
269
|
-
}
|
|
270
|
-
defaultZodOptionalHandler(value, handleTypes = SUPPORTED_ZOD_TYPES) {
|
|
271
|
-
if (handleTypes.includes(value._def.innerType._def.typeName)) {
|
|
272
|
-
return this.processZodType(value._def.innerType).optional();
|
|
273
|
-
} else {
|
|
274
|
-
return value;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
process(tool) {
|
|
278
|
-
if (chunk4Z3OU5RY_cjs.isVercelTool(tool)) {
|
|
279
|
-
return {
|
|
280
|
-
description: tool.description,
|
|
281
|
-
// TODO: should we also process vercel tool params?
|
|
282
|
-
parameters: ai.zodSchema(convertVercelToolParameters(tool))
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
const { schema } = this.applyZodSchemaCompatibility(tool.inputSchema);
|
|
286
|
-
return {
|
|
287
|
-
description: tool.description,
|
|
288
|
-
parameters: convertZodSchemaToAISDKSchema(schema, this.getSchemaTarget())
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
// src/tools/tool-compatibility/provider-compats/anthropic.ts
|
|
294
|
-
var AnthropicToolCompat = class extends ToolCompatibility {
|
|
295
|
-
constructor(model) {
|
|
296
|
-
super(model);
|
|
297
|
-
}
|
|
298
|
-
getSchemaTarget() {
|
|
299
|
-
return "jsonSchema7";
|
|
300
|
-
}
|
|
301
|
-
shouldApply() {
|
|
302
|
-
return this.getModel().modelId.includes("claude");
|
|
303
|
-
}
|
|
304
|
-
processZodType(value) {
|
|
305
|
-
switch (value._def.typeName) {
|
|
306
|
-
case "ZodOptional":
|
|
307
|
-
const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined"];
|
|
308
|
-
if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
|
|
309
|
-
if (this.getModel().modelId.includes("claude-3.7")) handleTypes.push("ZodTuple");
|
|
310
|
-
return this.defaultZodOptionalHandler(value, handleTypes);
|
|
311
|
-
case "ZodObject": {
|
|
312
|
-
return this.defaultZodObjectHandler(value);
|
|
313
|
-
}
|
|
314
|
-
case "ZodArray": {
|
|
315
|
-
return this.defaultZodArrayHandler(value, []);
|
|
316
|
-
}
|
|
317
|
-
case "ZodUnion": {
|
|
318
|
-
return this.defaultZodUnionHandler(value);
|
|
319
|
-
}
|
|
320
|
-
// the claude-3.5-haiku model support these properties but the model doesn't respect them, but it respects them when they're
|
|
321
|
-
// added to the tool description
|
|
322
|
-
case "ZodString": {
|
|
323
|
-
if (this.getModel().modelId.includes("claude-3.5-haiku")) {
|
|
324
|
-
return this.defaultZodStringHandler(value, ["max", "min"]);
|
|
325
|
-
} else {
|
|
326
|
-
return value;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
default:
|
|
330
|
-
if (this.getModel().modelId.includes("claude-3.7")) {
|
|
331
|
-
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodTuple", "ZodUndefined"]);
|
|
332
|
-
} else {
|
|
333
|
-
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined"]);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
// src/tools/tool-compatibility/provider-compats/deepseek.ts
|
|
340
|
-
var DeepSeekToolCompat = class extends ToolCompatibility {
|
|
341
|
-
constructor(model) {
|
|
342
|
-
super(model);
|
|
343
|
-
}
|
|
344
|
-
getSchemaTarget() {
|
|
345
|
-
return "jsonSchema7";
|
|
346
|
-
}
|
|
347
|
-
shouldApply() {
|
|
348
|
-
return this.getModel().modelId.includes("deepseek");
|
|
349
|
-
}
|
|
350
|
-
processZodType(value) {
|
|
351
|
-
switch (value._def.typeName) {
|
|
352
|
-
case "ZodOptional":
|
|
353
|
-
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
354
|
-
case "ZodObject": {
|
|
355
|
-
return this.defaultZodObjectHandler(value);
|
|
356
|
-
}
|
|
357
|
-
case "ZodArray": {
|
|
358
|
-
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
359
|
-
}
|
|
360
|
-
case "ZodUnion": {
|
|
361
|
-
return this.defaultZodUnionHandler(value);
|
|
362
|
-
}
|
|
363
|
-
case "ZodString": {
|
|
364
|
-
return this.defaultZodStringHandler(value);
|
|
365
|
-
}
|
|
366
|
-
default:
|
|
367
|
-
return value;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
// src/tools/tool-compatibility/provider-compats/google.ts
|
|
373
|
-
var GoogleToolCompat = class extends ToolCompatibility {
|
|
374
|
-
constructor(model) {
|
|
375
|
-
super(model);
|
|
376
|
-
}
|
|
377
|
-
getSchemaTarget() {
|
|
378
|
-
return "jsonSchema7";
|
|
379
|
-
}
|
|
380
|
-
shouldApply() {
|
|
381
|
-
return this.getModel().provider.includes("google") || this.getModel().modelId.includes("google");
|
|
382
|
-
}
|
|
383
|
-
processZodType(value) {
|
|
384
|
-
switch (value._def.typeName) {
|
|
385
|
-
case "ZodOptional":
|
|
386
|
-
return this.defaultZodOptionalHandler(value, [
|
|
387
|
-
"ZodObject",
|
|
388
|
-
"ZodArray",
|
|
389
|
-
"ZodUnion",
|
|
390
|
-
"ZodString",
|
|
391
|
-
"ZodNumber",
|
|
392
|
-
...UNSUPPORTED_ZOD_TYPES
|
|
393
|
-
]);
|
|
394
|
-
case "ZodObject": {
|
|
395
|
-
return this.defaultZodObjectHandler(value);
|
|
396
|
-
}
|
|
397
|
-
case "ZodArray": {
|
|
398
|
-
return this.defaultZodArrayHandler(value, []);
|
|
399
|
-
}
|
|
400
|
-
case "ZodUnion": {
|
|
401
|
-
return this.defaultZodUnionHandler(value);
|
|
402
|
-
}
|
|
403
|
-
// Google models support these properties but the model doesn't respect them, but it respects them when they're
|
|
404
|
-
// added to the tool description
|
|
405
|
-
case "ZodString": {
|
|
406
|
-
return this.defaultZodStringHandler(value);
|
|
407
|
-
}
|
|
408
|
-
case "ZodNumber": {
|
|
409
|
-
return this.defaultZodNumberHandler(value);
|
|
410
|
-
}
|
|
411
|
-
default:
|
|
412
|
-
return this.defaultUnsupportedZodTypeHandler(value);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
};
|
|
416
|
-
|
|
417
|
-
// src/tools/tool-compatibility/provider-compats/meta.ts
|
|
418
|
-
var MetaToolCompat = class extends ToolCompatibility {
|
|
419
|
-
constructor(model) {
|
|
420
|
-
super(model);
|
|
421
|
-
}
|
|
422
|
-
getSchemaTarget() {
|
|
423
|
-
return "jsonSchema7";
|
|
424
|
-
}
|
|
425
|
-
shouldApply() {
|
|
426
|
-
return this.getModel().modelId.includes("meta");
|
|
427
|
-
}
|
|
428
|
-
processZodType(value) {
|
|
429
|
-
switch (value._def.typeName) {
|
|
430
|
-
case "ZodOptional":
|
|
431
|
-
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
432
|
-
case "ZodObject": {
|
|
433
|
-
return this.defaultZodObjectHandler(value);
|
|
434
|
-
}
|
|
435
|
-
case "ZodArray": {
|
|
436
|
-
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
437
|
-
}
|
|
438
|
-
case "ZodUnion": {
|
|
439
|
-
return this.defaultZodUnionHandler(value);
|
|
440
|
-
}
|
|
441
|
-
case "ZodNumber": {
|
|
442
|
-
return this.defaultZodNumberHandler(value);
|
|
443
|
-
}
|
|
444
|
-
case "ZodString": {
|
|
445
|
-
return this.defaultZodStringHandler(value);
|
|
446
|
-
}
|
|
447
|
-
default:
|
|
448
|
-
return value;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
// src/tools/tool-compatibility/provider-compats/openai.ts
|
|
454
|
-
var OpenAIToolCompat = class extends ToolCompatibility {
|
|
455
|
-
constructor(model) {
|
|
456
|
-
super(model);
|
|
457
|
-
}
|
|
458
|
-
getSchemaTarget() {
|
|
459
|
-
return `jsonSchema7`;
|
|
460
|
-
}
|
|
461
|
-
shouldApply() {
|
|
462
|
-
if (!this.getModel().supportsStructuredOutputs && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
|
|
463
|
-
return true;
|
|
464
|
-
}
|
|
465
|
-
return false;
|
|
466
|
-
}
|
|
467
|
-
processZodType(value) {
|
|
468
|
-
switch (value._def.typeName) {
|
|
469
|
-
case "ZodOptional":
|
|
470
|
-
return this.defaultZodOptionalHandler(value, [
|
|
471
|
-
"ZodObject",
|
|
472
|
-
"ZodArray",
|
|
473
|
-
"ZodUnion",
|
|
474
|
-
"ZodString",
|
|
475
|
-
"ZodNever",
|
|
476
|
-
"ZodUndefined",
|
|
477
|
-
"ZodTuple"
|
|
478
|
-
]);
|
|
479
|
-
case "ZodObject": {
|
|
480
|
-
return this.defaultZodObjectHandler(value);
|
|
481
|
-
}
|
|
482
|
-
case "ZodUnion": {
|
|
483
|
-
return this.defaultZodUnionHandler(value);
|
|
484
|
-
}
|
|
485
|
-
case "ZodArray": {
|
|
486
|
-
return this.defaultZodArrayHandler(value);
|
|
487
|
-
}
|
|
488
|
-
case "ZodString": {
|
|
489
|
-
const model = this.getModel();
|
|
490
|
-
const checks = ["emoji"];
|
|
491
|
-
if (model.modelId.includes("gpt-4o-mini")) {
|
|
492
|
-
checks.push("regex");
|
|
493
|
-
}
|
|
494
|
-
return this.defaultZodStringHandler(value, checks);
|
|
495
|
-
}
|
|
496
|
-
default:
|
|
497
|
-
return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined", "ZodTuple"]);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
var OpenAIReasoningToolCompat = class extends ToolCompatibility {
|
|
502
|
-
constructor(model) {
|
|
503
|
-
super(model);
|
|
504
|
-
}
|
|
505
|
-
getSchemaTarget() {
|
|
506
|
-
return `openApi3`;
|
|
507
|
-
}
|
|
508
|
-
isReasoningModel() {
|
|
509
|
-
return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`);
|
|
510
|
-
}
|
|
511
|
-
shouldApply() {
|
|
512
|
-
if ((this.getModel().supportsStructuredOutputs || this.isReasoningModel()) && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
|
|
513
|
-
return true;
|
|
514
|
-
}
|
|
515
|
-
return false;
|
|
516
|
-
}
|
|
517
|
-
processZodType(value) {
|
|
518
|
-
switch (value._def.typeName) {
|
|
519
|
-
case "ZodOptional":
|
|
520
|
-
const innerZodType = this.processZodType(value._def.innerType);
|
|
521
|
-
return innerZodType.nullable();
|
|
522
|
-
case "ZodObject": {
|
|
523
|
-
return this.defaultZodObjectHandler(value);
|
|
524
|
-
}
|
|
525
|
-
case "ZodArray": {
|
|
526
|
-
return this.defaultZodArrayHandler(value);
|
|
527
|
-
}
|
|
528
|
-
case "ZodUnion": {
|
|
529
|
-
return this.defaultZodUnionHandler(value);
|
|
530
|
-
}
|
|
531
|
-
case "ZodDefault": {
|
|
532
|
-
const defaultDef = value._def;
|
|
533
|
-
const innerType = defaultDef.innerType;
|
|
534
|
-
const defaultValue = defaultDef.defaultValue();
|
|
535
|
-
const constraints = {};
|
|
536
|
-
if (defaultValue !== void 0) {
|
|
537
|
-
constraints.defaultValue = defaultValue;
|
|
538
|
-
}
|
|
539
|
-
const description = this.mergeParameterDescription(value.description, constraints);
|
|
540
|
-
let result = this.processZodType(innerType);
|
|
541
|
-
if (description) {
|
|
542
|
-
result = result.describe(description);
|
|
543
|
-
}
|
|
544
|
-
return result;
|
|
545
|
-
}
|
|
546
|
-
case "ZodNumber": {
|
|
547
|
-
return this.defaultZodNumberHandler(value);
|
|
548
|
-
}
|
|
549
|
-
case "ZodString": {
|
|
550
|
-
return this.defaultZodStringHandler(value);
|
|
551
|
-
}
|
|
552
|
-
case "ZodDate": {
|
|
553
|
-
return this.defaultZodDateHandler(value);
|
|
554
|
-
}
|
|
555
|
-
case "ZodAny": {
|
|
556
|
-
return zod.z.string().describe(
|
|
557
|
-
(value.description ?? "") + `
|
|
558
|
-
Argument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`
|
|
559
|
-
);
|
|
560
|
-
}
|
|
561
|
-
default:
|
|
562
|
-
return this.defaultUnsupportedZodTypeHandler(value);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
};
|
|
566
|
-
|
|
567
|
-
// src/tools/tool-compatibility/builder.ts
|
|
568
|
-
function convertZodSchemaToAISDKSchema(zodSchema2, target = "jsonSchema7") {
|
|
569
|
-
return ai.jsonSchema(
|
|
570
|
-
zodToJsonSchema.zodToJsonSchema(zodSchema2, {
|
|
571
|
-
$refStrategy: "none",
|
|
572
|
-
target
|
|
573
|
-
}),
|
|
574
|
-
{
|
|
575
|
-
validate: (value) => {
|
|
576
|
-
const result = zodSchema2.safeParse(value);
|
|
577
|
-
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
);
|
|
581
|
-
}
|
|
582
|
-
function convertVercelToolParameters(tool) {
|
|
583
|
-
const schema = tool.parameters ?? zod.z.object({});
|
|
584
|
-
if (isZodType(schema)) {
|
|
585
|
-
return schema;
|
|
586
|
-
} else {
|
|
587
|
-
const jsonSchemaToConvert = "jsonSchema" in schema ? schema.jsonSchema : schema;
|
|
588
|
-
try {
|
|
589
|
-
return zodFromJsonSchema.convertJsonSchemaToZod(jsonSchemaToConvert);
|
|
590
|
-
} catch (e) {
|
|
591
|
-
const errorMessage = `[CoreToolBuilder] Failed to convert Vercel tool JSON schema parameters to Zod. Original schema: ${JSON.stringify(jsonSchemaToConvert)}`;
|
|
592
|
-
console.error(errorMessage, e);
|
|
593
|
-
throw new Error(errorMessage + (e instanceof Error ? `
|
|
594
|
-
${e.stack}` : "\nUnknown error object"));
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
function convertInputSchema(tool) {
|
|
599
|
-
const schema = tool.inputSchema ?? zod.z.object({});
|
|
600
|
-
if (isZodType(schema)) {
|
|
601
|
-
return schema;
|
|
602
|
-
} else {
|
|
603
|
-
try {
|
|
604
|
-
return zodFromJsonSchema.convertJsonSchemaToZod(schema);
|
|
605
|
-
} catch (e) {
|
|
606
|
-
const errorMessage = `[CoreToolBuilder] Failed to convert tool input JSON schema to Zod. Original schema: ${JSON.stringify(schema)}`;
|
|
607
|
-
console.error(errorMessage, e);
|
|
608
|
-
throw new Error(errorMessage + (e instanceof Error ? `
|
|
609
|
-
${e.stack}` : "\nUnknown error object"));
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
var CoreToolBuilder = class extends chunkVHZPWE5L_cjs.MastraBase {
|
|
614
|
-
originalTool;
|
|
615
|
-
options;
|
|
616
|
-
logType;
|
|
617
|
-
constructor(input) {
|
|
618
|
-
super({ name: "CoreToolBuilder" });
|
|
619
|
-
this.originalTool = input.originalTool;
|
|
620
|
-
this.options = input.options;
|
|
621
|
-
this.logType = input.logType;
|
|
622
|
-
}
|
|
623
|
-
// Helper to get parameters based on tool type
|
|
624
|
-
getParameters = () => {
|
|
625
|
-
if (chunk4Z3OU5RY_cjs.isVercelTool(this.originalTool)) {
|
|
626
|
-
return convertVercelToolParameters(this.originalTool);
|
|
627
|
-
}
|
|
628
|
-
return convertInputSchema(this.originalTool);
|
|
629
|
-
};
|
|
630
|
-
// For provider-defined tools, we need to include all required properties
|
|
631
|
-
buildProviderTool(tool) {
|
|
632
|
-
if ("type" in tool && tool.type === "provider-defined" && "id" in tool && typeof tool.id === "string" && tool.id.includes(".")) {
|
|
633
|
-
return {
|
|
634
|
-
type: "provider-defined",
|
|
635
|
-
id: tool.id,
|
|
636
|
-
args: "args" in this.originalTool ? this.originalTool.args : {},
|
|
637
|
-
description: tool.description,
|
|
638
|
-
parameters: convertZodSchemaToAISDKSchema(this.getParameters()),
|
|
639
|
-
execute: this.originalTool.execute ? this.createExecute(
|
|
640
|
-
this.originalTool,
|
|
641
|
-
{ ...this.options, description: this.originalTool.description },
|
|
642
|
-
this.logType
|
|
643
|
-
) : void 0
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
return void 0;
|
|
647
|
-
}
|
|
648
|
-
createLogMessageOptions({ agentName, toolName, type }) {
|
|
649
|
-
if (!agentName) {
|
|
650
|
-
return {
|
|
651
|
-
start: `Executing tool ${toolName}`,
|
|
652
|
-
error: `Failed tool execution`
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
|
-
const prefix = `[Agent:${agentName}]`;
|
|
656
|
-
const toolType = type === "toolset" ? "toolset" : "tool";
|
|
657
|
-
return {
|
|
658
|
-
start: `${prefix} - Executing ${toolType} ${toolName}`,
|
|
659
|
-
error: `${prefix} - Failed ${toolType} execution`
|
|
660
|
-
};
|
|
661
|
-
}
|
|
662
|
-
createExecute(tool, options, logType) {
|
|
663
|
-
const { logger, mastra: _mastra, memory: _memory, runtimeContext, ...rest } = options;
|
|
664
|
-
const { start, error } = this.createLogMessageOptions({
|
|
665
|
-
agentName: options.agentName,
|
|
666
|
-
toolName: options.name,
|
|
667
|
-
type: logType
|
|
668
|
-
});
|
|
669
|
-
const execFunction = async (args, execOptions) => {
|
|
670
|
-
if (chunk4Z3OU5RY_cjs.isVercelTool(tool)) {
|
|
671
|
-
return tool?.execute?.(args, execOptions) ?? void 0;
|
|
672
|
-
}
|
|
673
|
-
return tool?.execute?.(
|
|
674
|
-
{
|
|
675
|
-
context: args,
|
|
676
|
-
threadId: options.threadId,
|
|
677
|
-
resourceId: options.resourceId,
|
|
678
|
-
mastra: options.mastra,
|
|
679
|
-
memory: options.memory,
|
|
680
|
-
runId: options.runId,
|
|
681
|
-
runtimeContext: options.runtimeContext ?? new chunkLABUWBKX_cjs.RuntimeContext()
|
|
682
|
-
},
|
|
683
|
-
execOptions
|
|
684
|
-
) ?? void 0;
|
|
685
|
-
};
|
|
686
|
-
return async (args, execOptions) => {
|
|
687
|
-
try {
|
|
688
|
-
(options.logger || this.logger).debug(start, { ...rest, args });
|
|
689
|
-
return await execFunction(args, execOptions);
|
|
690
|
-
} catch (err) {
|
|
691
|
-
(options.logger || this.logger).error(error, { ...rest, error: err, args });
|
|
692
|
-
throw err;
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
build() {
|
|
697
|
-
const providerTool = this.buildProviderTool(this.originalTool);
|
|
698
|
-
if (providerTool) {
|
|
699
|
-
return providerTool;
|
|
700
|
-
}
|
|
701
|
-
const definition = {
|
|
702
|
-
type: "function",
|
|
703
|
-
description: this.originalTool.description,
|
|
704
|
-
parameters: this.getParameters(),
|
|
705
|
-
execute: this.originalTool.execute ? this.createExecute(
|
|
706
|
-
this.originalTool,
|
|
707
|
-
{ ...this.options, description: this.originalTool.description },
|
|
708
|
-
this.logType
|
|
709
|
-
) : void 0
|
|
710
|
-
};
|
|
711
|
-
const parametersObject = {};
|
|
712
|
-
if (chunk4Z3OU5RY_cjs.isVercelTool(this.originalTool)) {
|
|
713
|
-
parametersObject.parameters = this.getParameters();
|
|
714
|
-
} else {
|
|
715
|
-
parametersObject.inputSchema = this.getParameters();
|
|
716
|
-
}
|
|
717
|
-
const model = this.options.model;
|
|
718
|
-
const hasParameters = parametersObject.parameters || parametersObject.inputSchema;
|
|
719
|
-
if (model && hasParameters) {
|
|
720
|
-
for (const compat of [
|
|
721
|
-
new OpenAIReasoningToolCompat(model),
|
|
722
|
-
new OpenAIToolCompat(model),
|
|
723
|
-
new GoogleToolCompat(model),
|
|
724
|
-
new AnthropicToolCompat(model),
|
|
725
|
-
new DeepSeekToolCompat(model),
|
|
726
|
-
new MetaToolCompat(model)
|
|
727
|
-
]) {
|
|
728
|
-
if (compat.shouldApply()) {
|
|
729
|
-
return { ...definition, ...compat.process({ ...this.originalTool, ...parametersObject }) };
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
return {
|
|
734
|
-
...definition,
|
|
735
|
-
parameters: convertZodSchemaToAISDKSchema(this.getParameters())
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
|
-
};
|
|
739
|
-
|
|
740
|
-
// src/utils.ts
|
|
741
|
-
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
742
|
-
function deepMerge(target, source) {
|
|
743
|
-
const output = { ...target };
|
|
744
|
-
if (!source) return output;
|
|
745
|
-
Object.keys(source).forEach((key) => {
|
|
746
|
-
const targetValue = output[key];
|
|
747
|
-
const sourceValue = source[key];
|
|
748
|
-
if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
|
|
749
|
-
output[key] = sourceValue;
|
|
750
|
-
} else if (sourceValue instanceof Object && targetValue instanceof Object && !Array.isArray(sourceValue) && !Array.isArray(targetValue)) {
|
|
751
|
-
output[key] = deepMerge(targetValue, sourceValue);
|
|
752
|
-
} else if (sourceValue !== void 0) {
|
|
753
|
-
output[key] = sourceValue;
|
|
754
|
-
}
|
|
755
|
-
});
|
|
756
|
-
return output;
|
|
757
|
-
}
|
|
758
|
-
async function* maskStreamTags(stream, tag, options = {}) {
|
|
759
|
-
const { onStart, onEnd, onMask } = options;
|
|
760
|
-
const openTag = `<${tag}>`;
|
|
761
|
-
const closeTag = `</${tag}>`;
|
|
762
|
-
let buffer = "";
|
|
763
|
-
let fullContent = "";
|
|
764
|
-
let isMasking = false;
|
|
765
|
-
let isBuffering = false;
|
|
766
|
-
const trimOutsideDelimiter = (text, delimiter, trim) => {
|
|
767
|
-
if (!text.includes(delimiter)) {
|
|
768
|
-
return text;
|
|
769
|
-
}
|
|
770
|
-
const parts = text.split(delimiter);
|
|
771
|
-
if (trim === `before-start`) {
|
|
772
|
-
return `${delimiter}${parts[1]}`;
|
|
773
|
-
}
|
|
774
|
-
return `${parts[0]}${delimiter}`;
|
|
775
|
-
};
|
|
776
|
-
const startsWith = (text, pattern) => {
|
|
777
|
-
if (pattern.includes(openTag.substring(0, 3))) {
|
|
778
|
-
pattern = trimOutsideDelimiter(pattern, `<`, `before-start`);
|
|
779
|
-
}
|
|
780
|
-
return text.trim().startsWith(pattern.trim());
|
|
781
|
-
};
|
|
782
|
-
for await (const chunk of stream) {
|
|
783
|
-
fullContent += chunk;
|
|
784
|
-
if (isBuffering) buffer += chunk;
|
|
785
|
-
const chunkHasTag = startsWith(chunk, openTag);
|
|
786
|
-
const bufferHasTag = !chunkHasTag && isBuffering && startsWith(openTag, buffer);
|
|
787
|
-
let toYieldBeforeMaskedStartTag = ``;
|
|
788
|
-
if (!isMasking && (chunkHasTag || bufferHasTag)) {
|
|
789
|
-
isMasking = true;
|
|
790
|
-
isBuffering = false;
|
|
791
|
-
const taggedTextToMask = trimOutsideDelimiter(buffer, `<`, `before-start`);
|
|
792
|
-
if (taggedTextToMask !== buffer.trim()) {
|
|
793
|
-
toYieldBeforeMaskedStartTag = buffer.replace(taggedTextToMask, ``);
|
|
794
|
-
}
|
|
795
|
-
buffer = "";
|
|
796
|
-
onStart?.();
|
|
797
|
-
}
|
|
798
|
-
if (!isMasking && !isBuffering && startsWith(openTag, chunk) && chunk.trim() !== "") {
|
|
799
|
-
isBuffering = true;
|
|
800
|
-
buffer += chunk;
|
|
801
|
-
continue;
|
|
802
|
-
}
|
|
803
|
-
if (isBuffering && buffer && !startsWith(openTag, buffer)) {
|
|
804
|
-
yield buffer;
|
|
805
|
-
buffer = "";
|
|
806
|
-
isBuffering = false;
|
|
807
|
-
continue;
|
|
808
|
-
}
|
|
809
|
-
if (isMasking && fullContent.includes(closeTag)) {
|
|
810
|
-
onMask?.(chunk);
|
|
811
|
-
onEnd?.();
|
|
812
|
-
isMasking = false;
|
|
813
|
-
const lastFullContent = fullContent;
|
|
814
|
-
fullContent = ``;
|
|
815
|
-
const textUntilEndTag = trimOutsideDelimiter(lastFullContent, closeTag, "after-end");
|
|
816
|
-
if (textUntilEndTag !== lastFullContent) {
|
|
817
|
-
yield lastFullContent.replace(textUntilEndTag, ``);
|
|
818
|
-
}
|
|
819
|
-
continue;
|
|
820
|
-
}
|
|
821
|
-
if (isMasking) {
|
|
822
|
-
onMask?.(chunk);
|
|
823
|
-
if (toYieldBeforeMaskedStartTag) {
|
|
824
|
-
yield toYieldBeforeMaskedStartTag;
|
|
825
|
-
}
|
|
826
|
-
continue;
|
|
827
|
-
}
|
|
828
|
-
yield chunk;
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
function resolveSerializedZodOutput(schema) {
|
|
832
|
-
return Function("z", `"use strict";return (${schema});`)(zod.z);
|
|
833
|
-
}
|
|
834
|
-
function isZodType(value) {
|
|
835
|
-
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
836
|
-
}
|
|
837
|
-
function createDeterministicId(input) {
|
|
838
|
-
return crypto.createHash("sha256").update(input).digest("hex").slice(0, 8);
|
|
839
|
-
}
|
|
840
|
-
function setVercelToolProperties(tool) {
|
|
841
|
-
const inputSchema = convertVercelToolParameters2(tool);
|
|
842
|
-
const toolId = !("id" in tool) ? tool.description ? `tool-${createDeterministicId(tool.description)}` : `tool-${Math.random().toString(36).substring(2, 9)}` : tool.id;
|
|
843
|
-
return {
|
|
844
|
-
...tool,
|
|
845
|
-
id: toolId,
|
|
846
|
-
inputSchema
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
function ensureToolProperties(tools) {
|
|
850
|
-
const toolsWithProperties = Object.keys(tools).reduce((acc, key) => {
|
|
851
|
-
const tool = tools?.[key];
|
|
852
|
-
if (tool) {
|
|
853
|
-
if (chunk4Z3OU5RY_cjs.isVercelTool(tool)) {
|
|
854
|
-
acc[key] = setVercelToolProperties(tool);
|
|
855
|
-
} else {
|
|
856
|
-
acc[key] = tool;
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
return acc;
|
|
860
|
-
}, {});
|
|
861
|
-
return toolsWithProperties;
|
|
862
|
-
}
|
|
863
|
-
function convertVercelToolParameters2(tool) {
|
|
864
|
-
const schema = tool.parameters ?? zod.z.object({});
|
|
865
|
-
return isZodType(schema) ? schema : resolveSerializedZodOutput(jsonSchemaToZod__default.default(schema));
|
|
866
|
-
}
|
|
867
|
-
function makeCoreTool(originalTool, options, logType) {
|
|
868
|
-
return new CoreToolBuilder({ originalTool, options, logType }).build();
|
|
869
|
-
}
|
|
870
|
-
function createMastraProxy({ mastra, logger }) {
|
|
871
|
-
return new Proxy(mastra, {
|
|
872
|
-
get(target, prop) {
|
|
873
|
-
const hasProp = Reflect.has(target, prop);
|
|
874
|
-
if (hasProp) {
|
|
875
|
-
const value = Reflect.get(target, prop);
|
|
876
|
-
const isFunction = typeof value === "function";
|
|
877
|
-
if (isFunction) {
|
|
878
|
-
return value.bind(target);
|
|
879
|
-
}
|
|
880
|
-
return value;
|
|
881
|
-
}
|
|
882
|
-
if (prop === "logger") {
|
|
883
|
-
logger.warn(`Please use 'getLogger' instead, logger is deprecated`);
|
|
884
|
-
return Reflect.apply(target.getLogger, target, []);
|
|
885
|
-
}
|
|
886
|
-
if (prop === "telemetry") {
|
|
887
|
-
logger.warn(`Please use 'getTelemetry' instead, telemetry is deprecated`);
|
|
888
|
-
return Reflect.apply(target.getTelemetry, target, []);
|
|
889
|
-
}
|
|
890
|
-
if (prop === "storage") {
|
|
891
|
-
logger.warn(`Please use 'getStorage' instead, storage is deprecated`);
|
|
892
|
-
return Reflect.get(target, "storage");
|
|
893
|
-
}
|
|
894
|
-
if (prop === "agents") {
|
|
895
|
-
logger.warn(`Please use 'getAgents' instead, agents is deprecated`);
|
|
896
|
-
return Reflect.apply(target.getAgents, target, []);
|
|
897
|
-
}
|
|
898
|
-
if (prop === "tts") {
|
|
899
|
-
logger.warn(`Please use 'getTTS' instead, tts is deprecated`);
|
|
900
|
-
return Reflect.apply(target.getTTS, target, []);
|
|
901
|
-
}
|
|
902
|
-
if (prop === "vectors") {
|
|
903
|
-
logger.warn(`Please use 'getVectors' instead, vectors is deprecated`);
|
|
904
|
-
return Reflect.apply(target.getVectors, target, []);
|
|
905
|
-
}
|
|
906
|
-
if (prop === "memory") {
|
|
907
|
-
logger.warn(`Please use 'getMemory' instead, memory is deprecated`);
|
|
908
|
-
return Reflect.get(target, "memory");
|
|
909
|
-
}
|
|
910
|
-
return Reflect.get(target, prop);
|
|
911
|
-
}
|
|
912
|
-
});
|
|
913
|
-
}
|
|
914
|
-
function checkEvalStorageFields(traceObject, logger) {
|
|
915
|
-
const missingFields = [];
|
|
916
|
-
if (!traceObject.input) missingFields.push("input");
|
|
917
|
-
if (!traceObject.output) missingFields.push("output");
|
|
918
|
-
if (!traceObject.agentName) missingFields.push("agent_name");
|
|
919
|
-
if (!traceObject.metricName) missingFields.push("metric_name");
|
|
920
|
-
if (!traceObject.instructions) missingFields.push("instructions");
|
|
921
|
-
if (!traceObject.globalRunId) missingFields.push("global_run_id");
|
|
922
|
-
if (!traceObject.runId) missingFields.push("run_id");
|
|
923
|
-
if (missingFields.length > 0) {
|
|
924
|
-
if (logger) {
|
|
925
|
-
logger.warn("Skipping evaluation storage due to missing required fields", {
|
|
926
|
-
missingFields,
|
|
927
|
-
runId: traceObject.runId,
|
|
928
|
-
agentName: traceObject.agentName
|
|
929
|
-
});
|
|
930
|
-
} else {
|
|
931
|
-
console.warn("Skipping evaluation storage due to missing required fields", {
|
|
932
|
-
missingFields,
|
|
933
|
-
runId: traceObject.runId,
|
|
934
|
-
agentName: traceObject.agentName
|
|
935
|
-
});
|
|
936
|
-
}
|
|
937
|
-
return false;
|
|
938
|
-
}
|
|
939
|
-
return true;
|
|
940
|
-
}
|
|
941
|
-
function detectSingleMessageCharacteristics(message) {
|
|
942
|
-
if (typeof message === "object" && message !== null && (message.role === "function" || // UI-only role
|
|
943
|
-
message.role === "data" || // UI-only role
|
|
944
|
-
"toolInvocations" in message || // UI-specific field
|
|
945
|
-
"parts" in message || // UI-specific field
|
|
946
|
-
"experimental_attachments" in message)) {
|
|
947
|
-
return "has-ui-specific-parts";
|
|
948
|
-
} else if (typeof message === "object" && message !== null && "content" in message && (Array.isArray(message.content) || // Core messages can have array content
|
|
949
|
-
"experimental_providerMetadata" in message || "providerOptions" in message)) {
|
|
950
|
-
return "has-core-specific-parts";
|
|
951
|
-
} else if (typeof message === "object" && message !== null && "role" in message && "content" in message && typeof message.content === "string" && ["system", "user", "assistant", "tool"].includes(message.role)) {
|
|
952
|
-
return "message";
|
|
953
|
-
} else {
|
|
954
|
-
return "other";
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
function isUiMessage(message) {
|
|
958
|
-
return detectSingleMessageCharacteristics(message) === `has-ui-specific-parts`;
|
|
959
|
-
}
|
|
960
|
-
function isCoreMessage(message) {
|
|
961
|
-
return [`has-core-specific-parts`, `message`].includes(detectSingleMessageCharacteristics(message));
|
|
962
|
-
}
|
|
963
|
-
var SQL_IDENTIFIER_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
964
|
-
function parseSqlIdentifier(name, kind = "identifier") {
|
|
965
|
-
if (!SQL_IDENTIFIER_PATTERN.test(name) || name.length > 63) {
|
|
966
|
-
throw new Error(
|
|
967
|
-
`Invalid ${kind}: ${name}. Must start with a letter or underscore, contain only letters, numbers, or underscores, and be at most 63 characters long.`
|
|
968
|
-
);
|
|
969
|
-
}
|
|
970
|
-
return name;
|
|
971
|
-
}
|
|
972
|
-
function parseFieldKey(key) {
|
|
973
|
-
if (!key) throw new Error("Field key cannot be empty");
|
|
974
|
-
const segments = key.split(".");
|
|
975
|
-
for (const segment of segments) {
|
|
976
|
-
if (!SQL_IDENTIFIER_PATTERN.test(segment) || segment.length > 63) {
|
|
977
|
-
throw new Error(`Invalid field key segment: ${segment} in ${key}`);
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
return key;
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
exports.checkEvalStorageFields = checkEvalStorageFields;
|
|
984
|
-
exports.createMastraProxy = createMastraProxy;
|
|
985
|
-
exports.deepMerge = deepMerge;
|
|
986
|
-
exports.delay = delay;
|
|
987
|
-
exports.ensureToolProperties = ensureToolProperties;
|
|
988
|
-
exports.isCoreMessage = isCoreMessage;
|
|
989
|
-
exports.isUiMessage = isUiMessage;
|
|
990
|
-
exports.isZodType = isZodType;
|
|
991
|
-
exports.makeCoreTool = makeCoreTool;
|
|
992
|
-
exports.maskStreamTags = maskStreamTags;
|
|
993
|
-
exports.parseFieldKey = parseFieldKey;
|
|
994
|
-
exports.parseSqlIdentifier = parseSqlIdentifier;
|
|
995
|
-
exports.resolveSerializedZodOutput = resolveSerializedZodOutput;
|