@mastra/core 0.9.2 → 0.9.3-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.
Files changed (135) hide show
  1. package/dist/agent/index.cjs +2 -2
  2. package/dist/agent/index.d.cts +2 -2
  3. package/dist/agent/index.d.ts +2 -2
  4. package/dist/agent/index.js +1 -1
  5. package/dist/{base-Dq_YZkEc.d.ts → base-BCnFhShR.d.ts} +31 -11
  6. package/dist/{base-DT2poiVK.d.ts → base-CeEVvwRi.d.ts} +2 -2
  7. package/dist/{base-BihKcqDY.d.cts → base-D9APQt4V.d.cts} +2 -2
  8. package/dist/{base-B3g_Q3KV.d.cts → base-VMWGZau0.d.cts} +31 -11
  9. package/dist/base.cjs +2 -2
  10. package/dist/base.d.cts +1 -1
  11. package/dist/base.d.ts +1 -1
  12. package/dist/base.js +1 -1
  13. package/dist/bundler/index.cjs +2 -2
  14. package/dist/bundler/index.d.cts +1 -1
  15. package/dist/bundler/index.d.ts +1 -1
  16. package/dist/bundler/index.js +1 -1
  17. package/dist/{chunk-JTKSOVYL.cjs → chunk-37HZ77Z5.cjs} +13 -12
  18. package/dist/{chunk-JSKASUR2.cjs → chunk-5ENQX4BI.cjs} +9 -9
  19. package/dist/{chunk-HAFLSGW5.cjs → chunk-5FZR2ED6.cjs} +22 -22
  20. package/dist/{chunk-RZCYBC7D.cjs → chunk-6NUAJ6AB.cjs} +2 -2
  21. package/dist/{chunk-B7N24G5E.cjs → chunk-6YITFTRU.cjs} +2 -2
  22. package/dist/{chunk-KWYJUFY3.js → chunk-BFNYQFG2.js} +80 -55
  23. package/dist/chunk-BMSBIZKD.cjs +72 -0
  24. package/dist/{chunk-6FW4DXZO.cjs → chunk-CBSE7QQX.cjs} +2 -2
  25. package/dist/{chunk-MNGIRRFY.js → chunk-CPONI4EX.js} +1 -1
  26. package/dist/{chunk-WAW7QBY4.cjs → chunk-CRHH7KRS.cjs} +2 -2
  27. package/dist/{chunk-5TFGORLG.js → chunk-DWD7X4KB.js} +1 -1
  28. package/dist/{chunk-2JNVEJCM.js → chunk-EYMLOJ2Q.js} +6 -5
  29. package/dist/{chunk-Q6Z2YS6I.js → chunk-FVYYXFPR.js} +2 -2
  30. package/dist/chunk-FXAV2WYX.cjs +930 -0
  31. package/dist/{chunk-ZZRFVSYZ.cjs → chunk-GUMHVPHG.cjs} +4 -4
  32. package/dist/{chunk-2ZK5VAXE.js → chunk-IKZWOULI.js} +2 -2
  33. package/dist/{chunk-T3UZONPQ.cjs → chunk-ITFMXU6H.cjs} +2 -2
  34. package/dist/{chunk-IBKW4TJU.js → chunk-JCBDQUQY.js} +1 -1
  35. package/dist/{chunk-URYHOYKQ.js → chunk-KA5ISUNY.js} +6 -6
  36. package/dist/{chunk-QV4ZJLWA.js → chunk-KPOUHZFJ.js} +2 -2
  37. package/dist/{chunk-POEYDVX7.cjs → chunk-KXWR3FNX.cjs} +4 -4
  38. package/dist/{chunk-SIQPAONL.js → chunk-LIJBCNTU.js} +1 -1
  39. package/dist/{chunk-CLJQYXNM.js → chunk-NDAW47QQ.js} +6 -2
  40. package/dist/{chunk-XNBNJEES.cjs → chunk-OGNJRWRQ.cjs} +2 -2
  41. package/dist/chunk-Q6ZDDQOB.js +70 -0
  42. package/dist/{chunk-7IAP7VPO.js → chunk-QFJY3MEL.js} +2 -2
  43. package/dist/{chunk-47NGQPZI.js → chunk-R652KYQW.js} +1 -1
  44. package/dist/{chunk-FXUTMNQG.cjs → chunk-RE5MNHDE.cjs} +2 -2
  45. package/dist/{chunk-D63P5O4Q.cjs → chunk-RO52JMKQ.cjs} +6 -2
  46. package/dist/{chunk-52SRR7WR.js → chunk-T5V4W7WU.js} +1 -1
  47. package/dist/{chunk-GHK3HBWN.js → chunk-TCL7XDJL.js} +1 -1
  48. package/dist/{chunk-MYHX5XVW.cjs → chunk-UVRGQEMD.cjs} +79 -53
  49. package/dist/{chunk-ZVBLRU4W.cjs → chunk-ZMMZXEOL.cjs} +7 -7
  50. package/dist/chunk-ZQ7FXUGY.js +911 -0
  51. package/dist/deployer/index.cjs +2 -2
  52. package/dist/deployer/index.d.cts +1 -1
  53. package/dist/deployer/index.d.ts +1 -1
  54. package/dist/deployer/index.js +1 -1
  55. package/dist/eval/index.d.cts +2 -2
  56. package/dist/eval/index.d.ts +2 -2
  57. package/dist/index.cjs +78 -74
  58. package/dist/index.d.cts +6 -6
  59. package/dist/index.d.ts +6 -6
  60. package/dist/index.js +15 -15
  61. package/dist/integration/index.cjs +3 -3
  62. package/dist/integration/index.d.cts +2 -2
  63. package/dist/integration/index.d.ts +2 -2
  64. package/dist/integration/index.js +1 -1
  65. package/dist/llm/index.d.cts +2 -2
  66. package/dist/llm/index.d.ts +2 -2
  67. package/dist/mastra/index.cjs +2 -2
  68. package/dist/mastra/index.d.cts +2 -2
  69. package/dist/mastra/index.d.ts +2 -2
  70. package/dist/mastra/index.js +1 -1
  71. package/dist/memory/index.cjs +4 -4
  72. package/dist/memory/index.d.cts +2 -2
  73. package/dist/memory/index.d.ts +2 -2
  74. package/dist/memory/index.js +1 -1
  75. package/dist/network/index.cjs +6 -6
  76. package/dist/network/index.d.cts +2 -2
  77. package/dist/network/index.d.ts +2 -2
  78. package/dist/network/index.js +3 -3
  79. package/dist/relevance/index.cjs +4 -4
  80. package/dist/relevance/index.d.cts +2 -2
  81. package/dist/relevance/index.d.ts +2 -2
  82. package/dist/relevance/index.js +1 -1
  83. package/dist/server/index.cjs +1 -0
  84. package/dist/server/index.d.cts +9 -4
  85. package/dist/server/index.d.ts +9 -4
  86. package/dist/server/index.js +1 -0
  87. package/dist/storage/index.cjs +2 -2
  88. package/dist/storage/index.d.cts +2 -2
  89. package/dist/storage/index.d.ts +2 -2
  90. package/dist/storage/index.js +1 -1
  91. package/dist/storage/libsql/index.cjs +2 -2
  92. package/dist/storage/libsql/index.d.cts +2 -2
  93. package/dist/storage/libsql/index.d.ts +2 -2
  94. package/dist/storage/libsql/index.js +1 -1
  95. package/dist/telemetry/index.cjs +10 -6
  96. package/dist/telemetry/index.d.cts +14 -4
  97. package/dist/telemetry/index.d.ts +14 -4
  98. package/dist/telemetry/index.js +1 -1
  99. package/dist/tools/index.cjs +4 -4
  100. package/dist/tools/index.d.cts +2 -2
  101. package/dist/tools/index.d.ts +2 -2
  102. package/dist/tools/index.js +1 -1
  103. package/dist/tts/index.cjs +2 -2
  104. package/dist/tts/index.d.cts +1 -1
  105. package/dist/tts/index.d.ts +1 -1
  106. package/dist/tts/index.js +1 -1
  107. package/dist/utils.cjs +12 -12
  108. package/dist/utils.d.cts +8 -7
  109. package/dist/utils.d.ts +8 -7
  110. package/dist/utils.js +1 -1
  111. package/dist/vector/index.cjs +2 -2
  112. package/dist/vector/index.d.cts +3 -1
  113. package/dist/vector/index.d.ts +3 -1
  114. package/dist/vector/index.js +1 -1
  115. package/dist/vector/libsql/index.cjs +3 -3
  116. package/dist/vector/libsql/index.d.cts +1 -1
  117. package/dist/vector/libsql/index.d.ts +1 -1
  118. package/dist/vector/libsql/index.js +1 -1
  119. package/dist/voice/index.cjs +4 -4
  120. package/dist/voice/index.d.cts +2 -2
  121. package/dist/voice/index.d.ts +2 -2
  122. package/dist/voice/index.js +1 -1
  123. package/dist/workflows/index.cjs +22 -22
  124. package/dist/workflows/index.d.cts +3 -3
  125. package/dist/workflows/index.d.ts +3 -3
  126. package/dist/workflows/index.js +1 -1
  127. package/dist/workflows/vNext/index.cjs +175 -138
  128. package/dist/workflows/vNext/index.d.cts +37 -12
  129. package/dist/workflows/vNext/index.d.ts +37 -12
  130. package/dist/workflows/vNext/index.js +171 -134
  131. package/package.json +7 -5
  132. package/dist/chunk-D2Y3ET63.cjs +0 -362
  133. package/dist/chunk-LXIAHZ45.js +0 -37
  134. package/dist/chunk-YAJVZMZH.cjs +0 -39
  135. package/dist/chunk-ZCJJ6XOH.js +0 -344
@@ -1,344 +0,0 @@
1
- import { RuntimeContext } from './chunk-SGGPJWRQ.js';
2
- import { createHash } from 'crypto';
3
- import { convertToCoreMessages } from 'ai';
4
- import jsonSchemaToZod from 'json-schema-to-zod';
5
- import { z } from 'zod';
6
-
7
- // src/tools/tool.ts
8
- var Tool = class {
9
- id;
10
- description;
11
- inputSchema;
12
- outputSchema;
13
- execute;
14
- mastra;
15
- constructor(opts) {
16
- this.id = opts.id;
17
- this.description = opts.description;
18
- this.inputSchema = opts.inputSchema;
19
- this.outputSchema = opts.outputSchema;
20
- this.execute = opts.execute;
21
- this.mastra = opts.mastra;
22
- }
23
- };
24
- function createTool(opts) {
25
- return new Tool(opts);
26
- }
27
- var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
28
- function deepMerge(target, source) {
29
- const output = { ...target };
30
- if (!source) return output;
31
- Object.keys(source).forEach((key) => {
32
- const targetValue = output[key];
33
- const sourceValue = source[key];
34
- if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
35
- output[key] = sourceValue;
36
- } else if (sourceValue instanceof Object && targetValue instanceof Object && !Array.isArray(sourceValue) && !Array.isArray(targetValue)) {
37
- output[key] = deepMerge(targetValue, sourceValue);
38
- } else if (sourceValue !== void 0) {
39
- output[key] = sourceValue;
40
- }
41
- });
42
- return output;
43
- }
44
- async function* maskStreamTags(stream, tag, options = {}) {
45
- const { onStart, onEnd, onMask } = options;
46
- const openTag = `<${tag}>`;
47
- const closeTag = `</${tag}>`;
48
- let buffer = "";
49
- let fullContent = "";
50
- let isMasking = false;
51
- let isBuffering = false;
52
- const trimOutsideDelimiter = (text, delimiter, trim) => {
53
- if (!text.includes(delimiter)) {
54
- return text;
55
- }
56
- const parts = text.split(delimiter);
57
- if (trim === `before-start`) {
58
- return `${delimiter}${parts[1]}`;
59
- }
60
- return `${parts[0]}${delimiter}`;
61
- };
62
- const startsWith = (text, pattern) => {
63
- if (pattern.includes(openTag.substring(0, 3))) {
64
- pattern = trimOutsideDelimiter(pattern, `<`, `before-start`);
65
- }
66
- return text.trim().startsWith(pattern.trim());
67
- };
68
- for await (const chunk of stream) {
69
- fullContent += chunk;
70
- if (isBuffering) buffer += chunk;
71
- const chunkHasTag = startsWith(chunk, openTag);
72
- const bufferHasTag = !chunkHasTag && isBuffering && startsWith(openTag, buffer);
73
- let toYieldBeforeMaskedStartTag = ``;
74
- if (!isMasking && (chunkHasTag || bufferHasTag)) {
75
- isMasking = true;
76
- isBuffering = false;
77
- const taggedTextToMask = trimOutsideDelimiter(buffer, `<`, `before-start`);
78
- if (taggedTextToMask !== buffer.trim()) {
79
- toYieldBeforeMaskedStartTag = buffer.replace(taggedTextToMask, ``);
80
- }
81
- buffer = "";
82
- onStart?.();
83
- }
84
- if (!isMasking && !isBuffering && startsWith(openTag, chunk) && chunk.trim() !== "") {
85
- isBuffering = true;
86
- buffer += chunk;
87
- continue;
88
- }
89
- if (isBuffering && buffer && !startsWith(openTag, buffer)) {
90
- yield buffer;
91
- buffer = "";
92
- isBuffering = false;
93
- continue;
94
- }
95
- if (isMasking && fullContent.includes(closeTag)) {
96
- onMask?.(chunk);
97
- onEnd?.();
98
- isMasking = false;
99
- const lastFullContent = fullContent;
100
- fullContent = ``;
101
- const textUntilEndTag = trimOutsideDelimiter(lastFullContent, closeTag, "after-end");
102
- if (textUntilEndTag !== lastFullContent) {
103
- yield lastFullContent.replace(textUntilEndTag, ``);
104
- }
105
- continue;
106
- }
107
- if (isMasking) {
108
- onMask?.(chunk);
109
- if (toYieldBeforeMaskedStartTag) {
110
- yield toYieldBeforeMaskedStartTag;
111
- }
112
- continue;
113
- }
114
- yield chunk;
115
- }
116
- }
117
- function resolveSerializedZodOutput(schema) {
118
- return Function("z", `"use strict";return (${schema});`)(z);
119
- }
120
- function isVercelTool(tool) {
121
- return !!(tool && !(tool instanceof Tool) && "parameters" in tool);
122
- }
123
- function createLogMessageOptions({ agentName, toolName, type }) {
124
- if (!agentName) {
125
- return {
126
- start: `Executing tool ${toolName}`,
127
- error: `Failed tool execution`
128
- };
129
- }
130
- const prefix = `[Agent:${agentName}]`;
131
- const toolType = type === "toolset" ? "toolset" : "tool";
132
- return {
133
- start: `${prefix} - Executing ${toolType} ${toolName}`,
134
- error: `${prefix} - Failed ${toolType} execution`
135
- };
136
- }
137
- function createExecute(tool, options, logType) {
138
- const { logger, mastra: _mastra, memory: _memory, runtimeContext, ...rest } = options;
139
- const { start, error } = createLogMessageOptions({
140
- agentName: options.agentName,
141
- toolName: options.name,
142
- type: logType
143
- });
144
- const execFunction = async (args, execOptions) => {
145
- if (isVercelTool(tool)) {
146
- return tool?.execute?.(args, execOptions) ?? void 0;
147
- }
148
- return tool?.execute?.(
149
- {
150
- context: args,
151
- threadId: options.threadId,
152
- resourceId: options.resourceId,
153
- mastra: options.mastra,
154
- memory: options.memory,
155
- runId: options.runId,
156
- runtimeContext: runtimeContext ?? new RuntimeContext()
157
- },
158
- execOptions
159
- ) ?? void 0;
160
- };
161
- return async (args, execOptions) => {
162
- try {
163
- logger.debug(start, { ...rest, args });
164
- return await execFunction(args, execOptions);
165
- } catch (err) {
166
- logger.error(error, { ...rest, error: err, args });
167
- throw err;
168
- }
169
- };
170
- }
171
- function isZodType(value) {
172
- return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
173
- }
174
- function createDeterministicId(input) {
175
- return createHash("sha256").update(input).digest("hex").slice(0, 8);
176
- }
177
- function setVercelToolProperties(tool) {
178
- const inputSchema = convertVercelToolParameters(tool);
179
- const toolId = !("id" in tool) ? tool.description ? `tool-${createDeterministicId(tool.description)}` : `tool-${Math.random().toString(36).substring(2, 9)}` : tool.id;
180
- return {
181
- ...tool,
182
- id: toolId,
183
- inputSchema
184
- };
185
- }
186
- function ensureToolProperties(tools) {
187
- const toolsWithProperties = Object.keys(tools).reduce((acc, key) => {
188
- const tool = tools?.[key];
189
- if (tool) {
190
- if (isVercelTool(tool)) {
191
- acc[key] = setVercelToolProperties(tool);
192
- } else {
193
- acc[key] = tool;
194
- }
195
- }
196
- return acc;
197
- }, {});
198
- return toolsWithProperties;
199
- }
200
- function convertVercelToolParameters(tool) {
201
- const schema = tool.parameters ?? z.object({});
202
- return isZodType(schema) ? schema : resolveSerializedZodOutput(jsonSchemaToZod(schema));
203
- }
204
- function convertInputSchema(tool) {
205
- const schema = tool.inputSchema ?? z.object({});
206
- return isZodType(schema) ? schema : resolveSerializedZodOutput(jsonSchemaToZod(schema));
207
- }
208
- function makeCoreTool(tool, options, logType) {
209
- const getParameters = () => {
210
- if (isVercelTool(tool)) {
211
- return convertVercelToolParameters(tool);
212
- }
213
- return convertInputSchema(tool);
214
- };
215
- const isProviderDefined = "type" in tool && tool.type === "provider-defined" && "id" in tool && typeof tool.id === "string" && tool.id.includes(".");
216
- if (isProviderDefined) {
217
- return {
218
- type: "provider-defined",
219
- id: tool.id,
220
- args: "args" in tool ? tool.args : {},
221
- description: tool.description,
222
- parameters: getParameters(),
223
- execute: tool.execute ? createExecute(tool, { ...options, description: tool.description }, logType) : void 0
224
- };
225
- }
226
- return {
227
- type: "function",
228
- description: tool.description,
229
- parameters: getParameters(),
230
- execute: tool.execute ? createExecute(tool, { ...options, description: tool.description }, logType) : void 0
231
- };
232
- }
233
- function createMastraProxy({ mastra, logger }) {
234
- return new Proxy(mastra, {
235
- get(target, prop) {
236
- const hasProp = Reflect.has(target, prop);
237
- if (hasProp) {
238
- const value = Reflect.get(target, prop);
239
- const isFunction = typeof value === "function";
240
- if (isFunction) {
241
- return value.bind(target);
242
- }
243
- return value;
244
- }
245
- if (prop === "logger") {
246
- logger.warn(`Please use 'getLogger' instead, logger is deprecated`);
247
- return Reflect.apply(target.getLogger, target, []);
248
- }
249
- if (prop === "telemetry") {
250
- logger.warn(`Please use 'getTelemetry' instead, telemetry is deprecated`);
251
- return Reflect.apply(target.getTelemetry, target, []);
252
- }
253
- if (prop === "storage") {
254
- logger.warn(`Please use 'getStorage' instead, storage is deprecated`);
255
- return Reflect.get(target, "storage");
256
- }
257
- if (prop === "agents") {
258
- logger.warn(`Please use 'getAgents' instead, agents is deprecated`);
259
- return Reflect.apply(target.getAgents, target, []);
260
- }
261
- if (prop === "tts") {
262
- logger.warn(`Please use 'getTTS' instead, tts is deprecated`);
263
- return Reflect.apply(target.getTTS, target, []);
264
- }
265
- if (prop === "vectors") {
266
- logger.warn(`Please use 'getVectors' instead, vectors is deprecated`);
267
- return Reflect.apply(target.getVectors, target, []);
268
- }
269
- if (prop === "memory") {
270
- logger.warn(`Please use 'getMemory' instead, memory is deprecated`);
271
- return Reflect.get(target, "memory");
272
- }
273
- return Reflect.get(target, prop);
274
- }
275
- });
276
- }
277
- function checkEvalStorageFields(traceObject, logger) {
278
- const missingFields = [];
279
- if (!traceObject.input) missingFields.push("input");
280
- if (!traceObject.output) missingFields.push("output");
281
- if (!traceObject.agentName) missingFields.push("agent_name");
282
- if (!traceObject.metricName) missingFields.push("metric_name");
283
- if (!traceObject.instructions) missingFields.push("instructions");
284
- if (!traceObject.globalRunId) missingFields.push("global_run_id");
285
- if (!traceObject.runId) missingFields.push("run_id");
286
- if (missingFields.length > 0) {
287
- if (logger) {
288
- logger.warn("Skipping evaluation storage due to missing required fields", {
289
- missingFields,
290
- runId: traceObject.runId,
291
- agentName: traceObject.agentName
292
- });
293
- } else {
294
- console.warn("Skipping evaluation storage due to missing required fields", {
295
- missingFields,
296
- runId: traceObject.runId,
297
- agentName: traceObject.agentName
298
- });
299
- }
300
- return false;
301
- }
302
- return true;
303
- }
304
- function detectSingleMessageCharacteristics(message) {
305
- if (typeof message === "object" && message !== null && (message.role === "function" || // UI-only role
306
- message.role === "data" || // UI-only role
307
- "toolInvocations" in message || // UI-specific field
308
- "parts" in message || // UI-specific field
309
- "experimental_attachments" in message)) {
310
- return "has-ui-specific-parts";
311
- } else if (typeof message === "object" && message !== null && "content" in message && (Array.isArray(message.content) || // Core messages can have array content
312
- "experimental_providerMetadata" in message || "providerOptions" in message)) {
313
- return "has-core-specific-parts";
314
- } else if (typeof message === "object" && message !== null && "role" in message && "content" in message && typeof message.content === "string" && ["system", "user", "assistant", "tool"].includes(message.role)) {
315
- return "message";
316
- } else {
317
- return "other";
318
- }
319
- }
320
- function isUiMessage(message) {
321
- return detectSingleMessageCharacteristics(message) === `has-ui-specific-parts`;
322
- }
323
- function isCoreMessage(message) {
324
- return [`has-core-specific-parts`, `message`].includes(detectSingleMessageCharacteristics(message));
325
- }
326
- function ensureAllMessagesAreCoreMessages(messages) {
327
- return messages.map((message) => {
328
- if (isUiMessage(message)) {
329
- return convertToCoreMessages([message]);
330
- }
331
- if (isCoreMessage(message)) {
332
- return message;
333
- }
334
- const characteristics = detectSingleMessageCharacteristics(message);
335
- throw new Error(
336
- `Message does not appear to be a core message or a UI message but must be one of the two, found "${characteristics}" type for message:
337
-
338
- ${JSON.stringify(message, null, 2)}
339
- `
340
- );
341
- }).flat();
342
- }
343
-
344
- export { Tool, checkEvalStorageFields, createMastraProxy, createTool, deepMerge, delay, ensureAllMessagesAreCoreMessages, ensureToolProperties, isVercelTool, isZodType, makeCoreTool, maskStreamTags, resolveSerializedZodOutput };