@mastra/core 0.10.13 → 0.10.15-alpha.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 (235) hide show
  1. package/a2a.d.ts +1 -0
  2. package/agent.d.ts +1 -0
  3. package/base.d.ts +1 -0
  4. package/bundler.d.ts +1 -0
  5. package/deployer.d.ts +1 -0
  6. package/di.d.ts +1 -0
  7. package/dist/a2a/index.cjs +79 -0
  8. package/dist/a2a/index.d.cts +780 -0
  9. package/dist/a2a/index.d.ts +780 -0
  10. package/dist/a2a/index.js +68 -0
  11. package/dist/agent/index.cjs +15 -0
  12. package/dist/agent/index.d.cts +29 -0
  13. package/dist/agent/index.d.ts +29 -0
  14. package/dist/agent/index.js +2 -0
  15. package/dist/base-B_y9sMg0.d.cts +162 -0
  16. package/dist/base-CTj7ESwt.d.cts +4132 -0
  17. package/dist/base-ClrXcCRx.d.ts +162 -0
  18. package/dist/base-qVqAnB-c.d.ts +4132 -0
  19. package/dist/base.cjs +10 -0
  20. package/dist/base.d.cts +6 -0
  21. package/dist/base.d.ts +6 -0
  22. package/dist/base.js +1 -0
  23. package/dist/bundler/index.cjs +10 -0
  24. package/dist/bundler/index.d.cts +30 -0
  25. package/dist/bundler/index.d.ts +30 -0
  26. package/dist/bundler/index.js +1 -0
  27. package/dist/chunk-32C7JDIZ.js +1 -0
  28. package/dist/chunk-4UWPFBC6.js +88 -0
  29. package/dist/chunk-4Z3OU5RY.cjs +31 -0
  30. package/dist/chunk-5HTMDAXP.js +359 -0
  31. package/dist/chunk-5IEKR756.js +53 -0
  32. package/dist/chunk-5YDTZN2X.js +114 -0
  33. package/dist/chunk-6UNGH46J.js +75 -0
  34. package/dist/chunk-6Y4UL5Z6.cjs +94 -0
  35. package/dist/chunk-7H2GET5Z.cjs +668 -0
  36. package/dist/chunk-7HZ6NIAF.cjs +2 -0
  37. package/dist/chunk-7XQIPES3.js +668 -0
  38. package/dist/chunk-AKYTYALY.js +70 -0
  39. package/dist/chunk-AOWJUV2N.js +2415 -0
  40. package/dist/chunk-ATXBSEFT.js +22 -0
  41. package/dist/chunk-B6TOBUS6.cjs +80 -0
  42. package/dist/chunk-B7SQOKEC.cjs +91 -0
  43. package/dist/chunk-BB4KXGBU.js +83 -0
  44. package/dist/chunk-BB6DPGIV.cjs +6 -0
  45. package/dist/chunk-BVD7NVAR.cjs +244 -0
  46. package/dist/chunk-C4LMN2IR.js +27 -0
  47. package/dist/chunk-DR4JS662.js +989 -0
  48. package/dist/chunk-F2WMR75C.cjs +183 -0
  49. package/dist/chunk-FEYYOBBG.cjs +24 -0
  50. package/dist/chunk-FL5SZ2XU.js +181 -0
  51. package/dist/chunk-GH2KM66J.js +37 -0
  52. package/dist/chunk-GWFS5DAR.cjs +37 -0
  53. package/dist/chunk-HNEE7IF4.js +60 -0
  54. package/dist/chunk-HSVOEWAM.cjs +2 -0
  55. package/dist/chunk-IBKM5CLQ.js +428 -0
  56. package/dist/chunk-ID5LG5CQ.cjs +659 -0
  57. package/dist/chunk-J52TXHZV.cjs +73 -0
  58. package/dist/chunk-J62R4M7K.js +240 -0
  59. package/dist/chunk-JNMQKJH4.js +10 -0
  60. package/dist/chunk-JQOMTERC.js +89 -0
  61. package/dist/chunk-LABUWBKX.cjs +71 -0
  62. package/dist/chunk-LBUQ6YNU.cjs +447 -0
  63. package/dist/chunk-LXFZUKP3.cjs +34 -0
  64. package/dist/chunk-MP2QBLUJ.cjs +70 -0
  65. package/dist/chunk-MUNFCOMB.cjs +62 -0
  66. package/dist/chunk-MVCHTRVB.js +5038 -0
  67. package/dist/chunk-NH5WJNNS.js +1 -0
  68. package/dist/chunk-P3Q73CAW.cjs +55 -0
  69. package/dist/chunk-Q33INUG2.cjs +81 -0
  70. package/dist/chunk-QFTBW7ZZ.cjs +2 -0
  71. package/dist/chunk-QQ5K5TZE.cjs +619 -0
  72. package/dist/chunk-R4V75T7J.js +1 -0
  73. package/dist/chunk-RVFWMGGR.js +77 -0
  74. package/dist/chunk-SGGPJWRQ.js +69 -0
  75. package/dist/chunk-ST5RMVLG.cjs +87 -0
  76. package/dist/chunk-TC2SCOTE.js +605 -0
  77. package/dist/chunk-TTMYHBQM.js +657 -0
  78. package/dist/chunk-U64IJDC5.cjs +109 -0
  79. package/dist/chunk-ULZ6MRTN.cjs +5065 -0
  80. package/dist/chunk-V5D2LIF5.js +68 -0
  81. package/dist/chunk-WQNOATKB.js +103 -0
  82. package/dist/chunk-Y7D2JLKS.js +4 -0
  83. package/dist/chunk-YOQP5T77.js +32 -0
  84. package/dist/chunk-ZCU3PLIL.cjs +2429 -0
  85. package/dist/chunk-ZIZ3CVHN.cjs +120 -0
  86. package/dist/chunk-ZPOUMTTH.cjs +362 -0
  87. package/dist/chunk-ZTPPDHQK.cjs +991 -0
  88. package/dist/chunk-ZZLBNB3U.cjs +12 -0
  89. package/dist/deployer/index.cjs +10 -0
  90. package/dist/deployer/index.d.cts +19 -0
  91. package/dist/deployer/index.d.ts +19 -0
  92. package/dist/deployer/index.js +1 -0
  93. package/dist/di/index.cjs +10 -0
  94. package/dist/di/index.d.cts +1 -0
  95. package/dist/di/index.d.ts +1 -0
  96. package/dist/di/index.js +1 -0
  97. package/dist/error/index.cjs +22 -0
  98. package/dist/error/index.d.cts +86 -0
  99. package/dist/error/index.d.ts +86 -0
  100. package/dist/error/index.js +1 -0
  101. package/dist/eval/index.cjs +14 -0
  102. package/dist/eval/index.d.cts +43 -0
  103. package/dist/eval/index.d.ts +43 -0
  104. package/dist/eval/index.js +1 -0
  105. package/dist/hooks/index.cjs +18 -0
  106. package/dist/hooks/index.d.cts +33 -0
  107. package/dist/hooks/index.d.ts +33 -0
  108. package/dist/hooks/index.js +1 -0
  109. package/dist/index.cjs +285 -0
  110. package/dist/index.d.cts +92 -0
  111. package/dist/index.d.ts +92 -0
  112. package/dist/index.js +112 -0
  113. package/dist/integration/index.cjs +14 -0
  114. package/dist/integration/index.d.cts +65 -0
  115. package/dist/integration/index.d.ts +65 -0
  116. package/dist/integration/index.js +1 -0
  117. package/dist/llm/index.cjs +10 -0
  118. package/dist/llm/index.d.cts +29 -0
  119. package/dist/llm/index.d.ts +29 -0
  120. package/dist/llm/index.js +1 -0
  121. package/dist/logger/index.cjs +43 -0
  122. package/dist/logger/index.d.cts +96 -0
  123. package/dist/logger/index.d.ts +96 -0
  124. package/dist/logger/index.js +2 -0
  125. package/dist/logger-B8XXh6ya.d.cts +159 -0
  126. package/dist/logger-Bpa2oLL4.d.ts +159 -0
  127. package/dist/mastra/index.cjs +10 -0
  128. package/dist/mastra/index.d.cts +29 -0
  129. package/dist/mastra/index.d.ts +29 -0
  130. package/dist/mastra/index.js +1 -0
  131. package/dist/mcp/index.cjs +106 -0
  132. package/dist/mcp/index.d.cts +29 -0
  133. package/dist/mcp/index.d.ts +29 -0
  134. package/dist/mcp/index.js +100 -0
  135. package/dist/memory/index.cjs +18 -0
  136. package/dist/memory/index.d.cts +29 -0
  137. package/dist/memory/index.d.ts +29 -0
  138. package/dist/memory/index.js +1 -0
  139. package/dist/network/index.cjs +311 -0
  140. package/dist/network/index.d.cts +29 -0
  141. package/dist/network/index.d.ts +29 -0
  142. package/dist/network/index.js +309 -0
  143. package/dist/network/vNext/index.cjs +880 -0
  144. package/dist/network/vNext/index.d.cts +29 -0
  145. package/dist/network/vNext/index.d.ts +29 -0
  146. package/dist/network/vNext/index.js +878 -0
  147. package/dist/relevance/index.cjs +18 -0
  148. package/dist/relevance/index.d.cts +50 -0
  149. package/dist/relevance/index.d.ts +50 -0
  150. package/dist/relevance/index.js +1 -0
  151. package/dist/runtime-context/index.cjs +10 -0
  152. package/dist/runtime-context/index.d.cts +52 -0
  153. package/dist/runtime-context/index.d.ts +52 -0
  154. package/dist/runtime-context/index.js +1 -0
  155. package/dist/server/index.cjs +62 -0
  156. package/dist/server/index.d.cts +52 -0
  157. package/dist/server/index.d.ts +52 -0
  158. package/dist/server/index.js +59 -0
  159. package/dist/storage/index.cjs +336 -0
  160. package/dist/storage/index.d.cts +149 -0
  161. package/dist/storage/index.d.ts +149 -0
  162. package/dist/storage/index.js +303 -0
  163. package/dist/telemetry/index.cjs +30 -0
  164. package/dist/telemetry/index.d.cts +75 -0
  165. package/dist/telemetry/index.d.ts +75 -0
  166. package/dist/telemetry/index.js +1 -0
  167. package/dist/telemetry/otel-vendor.cjs +103 -0
  168. package/dist/telemetry/otel-vendor.d.cts +20 -0
  169. package/dist/telemetry/otel-vendor.d.ts +20 -0
  170. package/dist/telemetry/otel-vendor.js +57 -0
  171. package/dist/tools/index.cjs +18 -0
  172. package/dist/tools/index.d.cts +41 -0
  173. package/dist/tools/index.d.ts +41 -0
  174. package/dist/tools/index.js +1 -0
  175. package/dist/tts/index.cjs +10 -0
  176. package/dist/tts/index.d.cts +28 -0
  177. package/dist/tts/index.d.ts +28 -0
  178. package/dist/tts/index.js +1 -0
  179. package/dist/types-Bo1uigWx.d.cts +17 -0
  180. package/dist/types-Bo1uigWx.d.ts +17 -0
  181. package/dist/utils.cjs +62 -0
  182. package/dist/utils.d.cts +150 -0
  183. package/dist/utils.d.ts +150 -0
  184. package/dist/utils.js +1 -0
  185. package/dist/vector/filter/index.cjs +192 -0
  186. package/dist/vector/filter/index.d.cts +128 -0
  187. package/dist/vector/filter/index.d.ts +128 -0
  188. package/dist/vector/filter/index.js +190 -0
  189. package/dist/vector/index.cjs +10 -0
  190. package/dist/vector/index.d.cts +77 -0
  191. package/dist/vector/index.d.ts +77 -0
  192. package/dist/vector/index.js +1 -0
  193. package/dist/voice/index.cjs +18 -0
  194. package/dist/voice/index.d.cts +29 -0
  195. package/dist/voice/index.d.ts +29 -0
  196. package/dist/voice/index.js +1 -0
  197. package/dist/workflows/constants.cjs +10 -0
  198. package/dist/workflows/constants.d.cts +3 -0
  199. package/dist/workflows/constants.d.ts +3 -0
  200. package/dist/workflows/constants.js +1 -0
  201. package/dist/workflows/index.cjs +42 -0
  202. package/dist/workflows/index.d.cts +285 -0
  203. package/dist/workflows/index.d.ts +285 -0
  204. package/dist/workflows/index.js +1 -0
  205. package/dist/workflows/legacy/index.cjs +90 -0
  206. package/dist/workflows/legacy/index.d.cts +91 -0
  207. package/dist/workflows/legacy/index.d.ts +91 -0
  208. package/dist/workflows/legacy/index.js +1 -0
  209. package/error.d.ts +1 -0
  210. package/eval.d.ts +1 -0
  211. package/hooks.d.ts +1 -0
  212. package/integration.d.ts +1 -0
  213. package/llm.d.ts +1 -0
  214. package/logger.d.ts +1 -0
  215. package/mastra.d.ts +1 -0
  216. package/mcp.d.ts +1 -0
  217. package/memory.d.ts +1 -0
  218. package/network/vNext.d.ts +1 -0
  219. package/network.d.ts +1 -0
  220. package/package.json +2 -3
  221. package/relevance.d.ts +1 -0
  222. package/runtime-context.d.ts +1 -0
  223. package/server.d.ts +1 -0
  224. package/storage.d.ts +1 -0
  225. package/telemetry/otel-vendor.d.ts +1 -0
  226. package/telemetry.d.ts +1 -0
  227. package/tools.d.ts +1 -0
  228. package/tts.d.ts +1 -0
  229. package/utils.d.ts +1 -0
  230. package/vector/filter.d.ts +1 -0
  231. package/vector.d.ts +1 -0
  232. package/voice.d.ts +1 -0
  233. package/workflows/_constants.d.ts +1 -0
  234. package/workflows/legacy.d.ts +1 -0
  235. package/workflows.d.ts +1 -0
@@ -0,0 +1,447 @@
1
+ 'use strict';
2
+
3
+ var chunk4Z3OU5RY_cjs = require('./chunk-4Z3OU5RY.cjs');
4
+ var chunkB6TOBUS6_cjs = require('./chunk-B6TOBUS6.cjs');
5
+ var chunkP3Q73CAW_cjs = require('./chunk-P3Q73CAW.cjs');
6
+ var chunkLABUWBKX_cjs = require('./chunk-LABUWBKX.cjs');
7
+ var crypto = require('crypto');
8
+ var jsonSchemaToZod = require('json-schema-to-zod');
9
+ var zod = require('zod');
10
+ var schemaCompat = require('@mastra/schema-compat');
11
+
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
+
14
+ var jsonSchemaToZod__default = /*#__PURE__*/_interopDefault(jsonSchemaToZod);
15
+
16
+ var CoreToolBuilder = class extends chunkP3Q73CAW_cjs.MastraBase {
17
+ originalTool;
18
+ options;
19
+ logType;
20
+ constructor(input) {
21
+ super({ name: "CoreToolBuilder" });
22
+ this.originalTool = input.originalTool;
23
+ this.options = input.options;
24
+ this.logType = input.logType;
25
+ }
26
+ // Helper to get parameters based on tool type
27
+ getParameters = () => {
28
+ if (chunk4Z3OU5RY_cjs.isVercelTool(this.originalTool)) {
29
+ return this.originalTool.parameters ?? zod.z.object({});
30
+ }
31
+ return this.originalTool.inputSchema ?? zod.z.object({});
32
+ };
33
+ getOutputSchema = () => {
34
+ if ("outputSchema" in this.originalTool) return this.originalTool.outputSchema;
35
+ return null;
36
+ };
37
+ // For provider-defined tools, we need to include all required properties
38
+ buildProviderTool(tool) {
39
+ if ("type" in tool && tool.type === "provider-defined" && "id" in tool && typeof tool.id === "string" && tool.id.includes(".")) {
40
+ const parameters = this.getParameters();
41
+ const outputSchema = this.getOutputSchema();
42
+ return {
43
+ type: "provider-defined",
44
+ id: tool.id,
45
+ args: "args" in this.originalTool ? this.originalTool.args : {},
46
+ description: tool.description,
47
+ parameters: schemaCompat.convertZodSchemaToAISDKSchema(parameters),
48
+ ...outputSchema ? { outputSchema: schemaCompat.convertZodSchemaToAISDKSchema(outputSchema) } : {},
49
+ execute: this.originalTool.execute ? this.createExecute(
50
+ this.originalTool,
51
+ { ...this.options, description: this.originalTool.description },
52
+ this.logType
53
+ ) : void 0
54
+ };
55
+ }
56
+ return void 0;
57
+ }
58
+ createLogMessageOptions({ agentName, toolName, type }) {
59
+ if (!agentName) {
60
+ return {
61
+ start: `Executing tool ${toolName}`,
62
+ error: `Failed tool execution`
63
+ };
64
+ }
65
+ const prefix = `[Agent:${agentName}]`;
66
+ const toolType = type === "toolset" ? "toolset" : "tool";
67
+ return {
68
+ start: `${prefix} - Executing ${toolType} ${toolName}`,
69
+ error: `${prefix} - Failed ${toolType} execution`
70
+ };
71
+ }
72
+ createExecute(tool, options, logType) {
73
+ const { logger, mastra: _mastra, memory: _memory, runtimeContext, ...rest } = options;
74
+ const { start, error } = this.createLogMessageOptions({
75
+ agentName: options.agentName,
76
+ toolName: options.name,
77
+ type: logType
78
+ });
79
+ const execFunction = async (args, execOptions) => {
80
+ if (chunk4Z3OU5RY_cjs.isVercelTool(tool)) {
81
+ return tool?.execute?.(args, execOptions) ?? void 0;
82
+ }
83
+ return tool?.execute?.(
84
+ {
85
+ context: args,
86
+ threadId: options.threadId,
87
+ resourceId: options.resourceId,
88
+ mastra: options.mastra,
89
+ memory: options.memory,
90
+ runId: options.runId,
91
+ runtimeContext: options.runtimeContext ?? new chunkLABUWBKX_cjs.RuntimeContext()
92
+ },
93
+ execOptions
94
+ ) ?? void 0;
95
+ };
96
+ return async (args, execOptions) => {
97
+ let logger2 = options.logger || this.logger;
98
+ try {
99
+ logger2.debug(start, { ...rest, args });
100
+ return await execFunction(args, execOptions);
101
+ } catch (err) {
102
+ const mastraError = new chunkB6TOBUS6_cjs.MastraError(
103
+ {
104
+ id: "TOOL_EXECUTION_FAILED",
105
+ domain: "TOOL" /* TOOL */,
106
+ category: "USER" /* USER */,
107
+ details: {
108
+ error,
109
+ args,
110
+ model: rest.model?.modelId ?? ""
111
+ }
112
+ },
113
+ err
114
+ );
115
+ logger2.trackException(mastraError);
116
+ logger2.error(error, { ...rest, error: mastraError, args });
117
+ return mastraError;
118
+ }
119
+ };
120
+ }
121
+ build() {
122
+ const providerTool = this.buildProviderTool(this.originalTool);
123
+ if (providerTool) {
124
+ return providerTool;
125
+ }
126
+ const definition = {
127
+ type: "function",
128
+ description: this.originalTool.description,
129
+ parameters: this.getParameters(),
130
+ outputSchema: this.getOutputSchema(),
131
+ execute: this.originalTool.execute ? this.createExecute(
132
+ this.originalTool,
133
+ { ...this.options, description: this.originalTool.description },
134
+ this.logType
135
+ ) : void 0
136
+ };
137
+ const model = this.options.model;
138
+ const schemaCompatLayers = [];
139
+ if (model) {
140
+ schemaCompatLayers.push(
141
+ new schemaCompat.OpenAIReasoningSchemaCompatLayer(model),
142
+ new schemaCompat.OpenAISchemaCompatLayer(model),
143
+ new schemaCompat.GoogleSchemaCompatLayer(model),
144
+ new schemaCompat.AnthropicSchemaCompatLayer(model),
145
+ new schemaCompat.DeepSeekSchemaCompatLayer(model),
146
+ new schemaCompat.MetaSchemaCompatLayer(model)
147
+ );
148
+ }
149
+ const processedSchema = schemaCompat.applyCompatLayer({
150
+ schema: this.getParameters(),
151
+ compatLayers: schemaCompatLayers,
152
+ mode: "aiSdkSchema"
153
+ });
154
+ let processedOutputSchema;
155
+ if (this.getOutputSchema()) {
156
+ processedOutputSchema = schemaCompat.applyCompatLayer({
157
+ schema: this.getOutputSchema(),
158
+ compatLayers: schemaCompatLayers,
159
+ mode: "aiSdkSchema"
160
+ });
161
+ }
162
+ return {
163
+ ...definition,
164
+ parameters: processedSchema,
165
+ outputSchema: processedOutputSchema
166
+ };
167
+ }
168
+ };
169
+
170
+ // src/utils.ts
171
+ var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
172
+ function deepMerge(target, source) {
173
+ const output = { ...target };
174
+ if (!source) return output;
175
+ Object.keys(source).forEach((key) => {
176
+ const targetValue = output[key];
177
+ const sourceValue = source[key];
178
+ if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
179
+ output[key] = sourceValue;
180
+ } else if (sourceValue instanceof Object && targetValue instanceof Object && !Array.isArray(sourceValue) && !Array.isArray(targetValue)) {
181
+ output[key] = deepMerge(targetValue, sourceValue);
182
+ } else if (sourceValue !== void 0) {
183
+ output[key] = sourceValue;
184
+ }
185
+ });
186
+ return output;
187
+ }
188
+ function generateEmptyFromSchema(schema) {
189
+ try {
190
+ const parsedSchema = JSON.parse(schema);
191
+ if (!parsedSchema || parsedSchema.type !== "object" || !parsedSchema.properties) return {};
192
+ const obj = {};
193
+ const TYPE_DEFAULTS = {
194
+ string: "",
195
+ array: [],
196
+ object: {},
197
+ number: 0,
198
+ integer: 0,
199
+ boolean: false
200
+ };
201
+ for (const [key, prop] of Object.entries(parsedSchema.properties)) {
202
+ obj[key] = TYPE_DEFAULTS[prop.type] ?? null;
203
+ }
204
+ return obj;
205
+ } catch {
206
+ return {};
207
+ }
208
+ }
209
+ async function* maskStreamTags(stream, tag, options = {}) {
210
+ const { onStart, onEnd, onMask } = options;
211
+ const openTag = `<${tag}>`;
212
+ const closeTag = `</${tag}>`;
213
+ let buffer = "";
214
+ let fullContent = "";
215
+ let isMasking = false;
216
+ let isBuffering = false;
217
+ const trimOutsideDelimiter = (text, delimiter, trim) => {
218
+ if (!text.includes(delimiter)) {
219
+ return text;
220
+ }
221
+ const parts = text.split(delimiter);
222
+ if (trim === `before-start`) {
223
+ return `${delimiter}${parts[1]}`;
224
+ }
225
+ return `${parts[0]}${delimiter}`;
226
+ };
227
+ const startsWith = (text, pattern) => {
228
+ if (pattern.includes(openTag.substring(0, 3))) {
229
+ pattern = trimOutsideDelimiter(pattern, `<`, `before-start`);
230
+ }
231
+ return text.trim().startsWith(pattern.trim());
232
+ };
233
+ for await (const chunk of stream) {
234
+ fullContent += chunk;
235
+ if (isBuffering) buffer += chunk;
236
+ const chunkHasTag = startsWith(chunk, openTag);
237
+ const bufferHasTag = !chunkHasTag && isBuffering && startsWith(openTag, buffer);
238
+ let toYieldBeforeMaskedStartTag = ``;
239
+ if (!isMasking && (chunkHasTag || bufferHasTag)) {
240
+ isMasking = true;
241
+ isBuffering = false;
242
+ const taggedTextToMask = trimOutsideDelimiter(buffer, `<`, `before-start`);
243
+ if (taggedTextToMask !== buffer.trim()) {
244
+ toYieldBeforeMaskedStartTag = buffer.replace(taggedTextToMask, ``);
245
+ }
246
+ buffer = "";
247
+ onStart?.();
248
+ }
249
+ if (!isMasking && !isBuffering && startsWith(openTag, chunk) && chunk.trim() !== "") {
250
+ isBuffering = true;
251
+ buffer += chunk;
252
+ continue;
253
+ }
254
+ if (isBuffering && buffer && !startsWith(openTag, buffer)) {
255
+ yield buffer;
256
+ buffer = "";
257
+ isBuffering = false;
258
+ continue;
259
+ }
260
+ if (isMasking && fullContent.includes(closeTag)) {
261
+ onMask?.(chunk);
262
+ onEnd?.();
263
+ isMasking = false;
264
+ const lastFullContent = fullContent;
265
+ fullContent = ``;
266
+ const textUntilEndTag = trimOutsideDelimiter(lastFullContent, closeTag, "after-end");
267
+ if (textUntilEndTag !== lastFullContent) {
268
+ yield lastFullContent.replace(textUntilEndTag, ``);
269
+ }
270
+ continue;
271
+ }
272
+ if (isMasking) {
273
+ onMask?.(chunk);
274
+ if (toYieldBeforeMaskedStartTag) {
275
+ yield toYieldBeforeMaskedStartTag;
276
+ }
277
+ continue;
278
+ }
279
+ yield chunk;
280
+ }
281
+ }
282
+ function resolveSerializedZodOutput(schema) {
283
+ return Function("z", `"use strict";return (${schema});`)(zod.z);
284
+ }
285
+ function isZodType(value) {
286
+ return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
287
+ }
288
+ function createDeterministicId(input) {
289
+ return crypto.createHash("sha256").update(input).digest("hex").slice(0, 8);
290
+ }
291
+ function setVercelToolProperties(tool) {
292
+ const inputSchema = convertVercelToolParameters(tool);
293
+ const toolId = !("id" in tool) ? tool.description ? `tool-${createDeterministicId(tool.description)}` : `tool-${Math.random().toString(36).substring(2, 9)}` : tool.id;
294
+ return {
295
+ ...tool,
296
+ id: toolId,
297
+ inputSchema
298
+ };
299
+ }
300
+ function ensureToolProperties(tools) {
301
+ const toolsWithProperties = Object.keys(tools).reduce((acc, key) => {
302
+ const tool = tools?.[key];
303
+ if (tool) {
304
+ if (chunk4Z3OU5RY_cjs.isVercelTool(tool)) {
305
+ acc[key] = setVercelToolProperties(tool);
306
+ } else {
307
+ acc[key] = tool;
308
+ }
309
+ }
310
+ return acc;
311
+ }, {});
312
+ return toolsWithProperties;
313
+ }
314
+ function convertVercelToolParameters(tool) {
315
+ const schema = tool.parameters ?? zod.z.object({});
316
+ return isZodType(schema) ? schema : resolveSerializedZodOutput(jsonSchemaToZod__default.default(schema));
317
+ }
318
+ function makeCoreTool(originalTool, options, logType) {
319
+ return new CoreToolBuilder({ originalTool, options, logType }).build();
320
+ }
321
+ function createMastraProxy({ mastra, logger }) {
322
+ return new Proxy(mastra, {
323
+ get(target, prop) {
324
+ const hasProp = Reflect.has(target, prop);
325
+ if (hasProp) {
326
+ const value = Reflect.get(target, prop);
327
+ const isFunction = typeof value === "function";
328
+ if (isFunction) {
329
+ return value.bind(target);
330
+ }
331
+ return value;
332
+ }
333
+ if (prop === "logger") {
334
+ logger.warn(`Please use 'getLogger' instead, logger is deprecated`);
335
+ return Reflect.apply(target.getLogger, target, []);
336
+ }
337
+ if (prop === "telemetry") {
338
+ logger.warn(`Please use 'getTelemetry' instead, telemetry is deprecated`);
339
+ return Reflect.apply(target.getTelemetry, target, []);
340
+ }
341
+ if (prop === "storage") {
342
+ logger.warn(`Please use 'getStorage' instead, storage is deprecated`);
343
+ return Reflect.get(target, "storage");
344
+ }
345
+ if (prop === "agents") {
346
+ logger.warn(`Please use 'getAgents' instead, agents is deprecated`);
347
+ return Reflect.apply(target.getAgents, target, []);
348
+ }
349
+ if (prop === "tts") {
350
+ logger.warn(`Please use 'getTTS' instead, tts is deprecated`);
351
+ return Reflect.apply(target.getTTS, target, []);
352
+ }
353
+ if (prop === "vectors") {
354
+ logger.warn(`Please use 'getVectors' instead, vectors is deprecated`);
355
+ return Reflect.apply(target.getVectors, target, []);
356
+ }
357
+ if (prop === "memory") {
358
+ logger.warn(`Please use 'getMemory' instead, memory is deprecated`);
359
+ return Reflect.get(target, "memory");
360
+ }
361
+ return Reflect.get(target, prop);
362
+ }
363
+ });
364
+ }
365
+ function checkEvalStorageFields(traceObject, logger) {
366
+ const missingFields = [];
367
+ if (!traceObject.input) missingFields.push("input");
368
+ if (!traceObject.output) missingFields.push("output");
369
+ if (!traceObject.agentName) missingFields.push("agent_name");
370
+ if (!traceObject.metricName) missingFields.push("metric_name");
371
+ if (!traceObject.instructions) missingFields.push("instructions");
372
+ if (!traceObject.globalRunId) missingFields.push("global_run_id");
373
+ if (!traceObject.runId) missingFields.push("run_id");
374
+ if (missingFields.length > 0) {
375
+ if (logger) {
376
+ logger.warn("Skipping evaluation storage due to missing required fields", {
377
+ missingFields,
378
+ runId: traceObject.runId,
379
+ agentName: traceObject.agentName
380
+ });
381
+ } else {
382
+ console.warn("Skipping evaluation storage due to missing required fields", {
383
+ missingFields,
384
+ runId: traceObject.runId,
385
+ agentName: traceObject.agentName
386
+ });
387
+ }
388
+ return false;
389
+ }
390
+ return true;
391
+ }
392
+ function detectSingleMessageCharacteristics(message) {
393
+ if (typeof message === "object" && message !== null && (message.role === "function" || // UI-only role
394
+ message.role === "data" || // UI-only role
395
+ "toolInvocations" in message || // UI-specific field
396
+ "parts" in message || // UI-specific field
397
+ "experimental_attachments" in message)) {
398
+ return "has-ui-specific-parts";
399
+ } else if (typeof message === "object" && message !== null && "content" in message && (Array.isArray(message.content) || // Core messages can have array content
400
+ "experimental_providerMetadata" in message || "providerOptions" in message)) {
401
+ return "has-core-specific-parts";
402
+ } else if (typeof message === "object" && message !== null && "role" in message && "content" in message && typeof message.content === "string" && ["system", "user", "assistant", "tool"].includes(message.role)) {
403
+ return "message";
404
+ } else {
405
+ return "other";
406
+ }
407
+ }
408
+ function isUiMessage(message) {
409
+ return detectSingleMessageCharacteristics(message) === `has-ui-specific-parts`;
410
+ }
411
+ function isCoreMessage(message) {
412
+ return [`has-core-specific-parts`, `message`].includes(detectSingleMessageCharacteristics(message));
413
+ }
414
+ var SQL_IDENTIFIER_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
415
+ function parseSqlIdentifier(name, kind = "identifier") {
416
+ if (!SQL_IDENTIFIER_PATTERN.test(name) || name.length > 63) {
417
+ throw new Error(
418
+ `Invalid ${kind}: ${name}. Must start with a letter or underscore, contain only letters, numbers, or underscores, and be at most 63 characters long.`
419
+ );
420
+ }
421
+ return name;
422
+ }
423
+ function parseFieldKey(key) {
424
+ if (!key) throw new Error("Field key cannot be empty");
425
+ const segments = key.split(".");
426
+ for (const segment of segments) {
427
+ if (!SQL_IDENTIFIER_PATTERN.test(segment) || segment.length > 63) {
428
+ throw new Error(`Invalid field key segment: ${segment} in ${key}`);
429
+ }
430
+ }
431
+ return key;
432
+ }
433
+
434
+ exports.checkEvalStorageFields = checkEvalStorageFields;
435
+ exports.createMastraProxy = createMastraProxy;
436
+ exports.deepMerge = deepMerge;
437
+ exports.delay = delay;
438
+ exports.ensureToolProperties = ensureToolProperties;
439
+ exports.generateEmptyFromSchema = generateEmptyFromSchema;
440
+ exports.isCoreMessage = isCoreMessage;
441
+ exports.isUiMessage = isUiMessage;
442
+ exports.isZodType = isZodType;
443
+ exports.makeCoreTool = makeCoreTool;
444
+ exports.maskStreamTags = maskStreamTags;
445
+ exports.parseFieldKey = parseFieldKey;
446
+ exports.parseSqlIdentifier = parseSqlIdentifier;
447
+ exports.resolveSerializedZodOutput = resolveSerializedZodOutput;
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ // src/storage/storageWithInit.ts
4
+ var isAugmentedSymbol = Symbol("isAugmented");
5
+ function augmentWithInit(storage) {
6
+ let hasInitialized = null;
7
+ const ensureInit = async () => {
8
+ if (!hasInitialized) {
9
+ hasInitialized = storage.init();
10
+ }
11
+ await hasInitialized;
12
+ };
13
+ if (storage[isAugmentedSymbol]) {
14
+ return storage;
15
+ }
16
+ const proxy = new Proxy(storage, {
17
+ get(target, prop) {
18
+ if (prop === isAugmentedSymbol) {
19
+ return true;
20
+ }
21
+ const value = target[prop];
22
+ if (typeof value === "function" && prop !== "init") {
23
+ return async (...args) => {
24
+ await ensureInit();
25
+ return Reflect.apply(value, target, args);
26
+ };
27
+ }
28
+ return Reflect.get(target, prop);
29
+ }
30
+ });
31
+ return proxy;
32
+ }
33
+
34
+ exports.augmentWithInit = augmentWithInit;
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ var chunkB6TOBUS6_cjs = require('./chunk-B6TOBUS6.cjs');
4
+ var chunkP3Q73CAW_cjs = require('./chunk-P3Q73CAW.cjs');
5
+
6
+ // src/vector/vector.ts
7
+ var MastraVector = class extends chunkP3Q73CAW_cjs.MastraBase {
8
+ constructor() {
9
+ super({ name: "MastraVector", component: "VECTOR" });
10
+ }
11
+ get indexSeparator() {
12
+ return "_";
13
+ }
14
+ async validateExistingIndex(indexName, dimension, metric) {
15
+ let info;
16
+ try {
17
+ info = await this.describeIndex({ indexName });
18
+ } catch (infoError) {
19
+ const mastraError = new chunkB6TOBUS6_cjs.MastraError(
20
+ {
21
+ id: "VECTOR_VALIDATE_INDEX_FETCH_FAILED",
22
+ text: `Index "${indexName}" already exists, but failed to fetch index info for dimension check.`,
23
+ domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
24
+ category: "SYSTEM" /* SYSTEM */,
25
+ details: { indexName }
26
+ },
27
+ infoError
28
+ );
29
+ this.logger?.trackException(mastraError);
30
+ this.logger?.error(mastraError.toString());
31
+ throw mastraError;
32
+ }
33
+ const existingDim = info?.dimension;
34
+ const existingMetric = info?.metric;
35
+ if (existingDim === dimension) {
36
+ this.logger?.info(
37
+ `Index "${indexName}" already exists with ${existingDim} dimensions and metric ${existingMetric}, skipping creation.`
38
+ );
39
+ if (existingMetric !== metric) {
40
+ this.logger?.warn(
41
+ `Attempted to create index with metric "${metric}", but index already exists with metric "${existingMetric}". To use a different metric, delete and recreate the index.`
42
+ );
43
+ }
44
+ } else if (info) {
45
+ const mastraError = new chunkB6TOBUS6_cjs.MastraError({
46
+ id: "VECTOR_VALIDATE_INDEX_DIMENSION_MISMATCH",
47
+ text: `Index "${indexName}" already exists with ${existingDim} dimensions, but ${dimension} dimensions were requested`,
48
+ domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
49
+ category: "USER" /* USER */,
50
+ details: { indexName, existingDim, requestedDim: dimension }
51
+ });
52
+ this.logger?.trackException(mastraError);
53
+ this.logger?.error(mastraError.toString());
54
+ throw mastraError;
55
+ } else {
56
+ const mastraError = new chunkB6TOBUS6_cjs.MastraError({
57
+ id: "VECTOR_VALIDATE_INDEX_NO_DIMENSION",
58
+ text: `Index "${indexName}" already exists, but could not retrieve its dimensions for validation.`,
59
+ domain: "MASTRA_VECTOR" /* MASTRA_VECTOR */,
60
+ category: "SYSTEM" /* SYSTEM */,
61
+ details: { indexName }
62
+ });
63
+ this.logger?.trackException(mastraError);
64
+ this.logger?.error(mastraError.toString());
65
+ throw mastraError;
66
+ }
67
+ }
68
+ };
69
+
70
+ exports.MastraVector = MastraVector;
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ var ai = require('ai');
4
+ var test = require('ai/test');
5
+
6
+ // src/llm/model/mock.ts
7
+ function createMockModel({
8
+ objectGenerationMode,
9
+ mockText,
10
+ spyGenerate,
11
+ spyStream
12
+ }) {
13
+ const mockModel = new test.MockLanguageModelV1({
14
+ defaultObjectGenerationMode: objectGenerationMode,
15
+ doGenerate: async (props) => {
16
+ if (spyGenerate) {
17
+ spyGenerate(props);
18
+ }
19
+ if (objectGenerationMode === "json") {
20
+ return {
21
+ rawCall: { rawPrompt: null, rawSettings: {} },
22
+ finishReason: "stop",
23
+ usage: { promptTokens: 10, completionTokens: 20 },
24
+ text: JSON.stringify(mockText)
25
+ };
26
+ }
27
+ return {
28
+ rawCall: { rawPrompt: null, rawSettings: {} },
29
+ finishReason: "stop",
30
+ usage: { promptTokens: 10, completionTokens: 20 },
31
+ text: typeof mockText === "string" ? mockText : JSON.stringify(mockText)
32
+ };
33
+ },
34
+ doStream: async (props) => {
35
+ if (spyStream) {
36
+ spyStream(props);
37
+ }
38
+ const text = typeof mockText === "string" ? mockText : JSON.stringify(mockText);
39
+ const chunks = text.split(" ").map((word) => ({
40
+ type: "text-delta",
41
+ textDelta: word + " "
42
+ }));
43
+ return {
44
+ stream: ai.simulateReadableStream({
45
+ chunks: [
46
+ ...chunks,
47
+ {
48
+ type: "finish",
49
+ finishReason: "stop",
50
+ logprobs: void 0,
51
+ usage: { completionTokens: 10, promptTokens: 3 }
52
+ }
53
+ ]
54
+ }),
55
+ rawCall: { rawPrompt: null, rawSettings: {} }
56
+ };
57
+ }
58
+ });
59
+ return mockModel;
60
+ }
61
+
62
+ exports.createMockModel = createMockModel;