@mastra/core 0.9.0 → 0.9.1-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 (94) hide show
  1. package/dist/agent/index.cjs +2 -2
  2. package/dist/agent/index.d.cts +4 -2
  3. package/dist/agent/index.d.ts +4 -2
  4. package/dist/agent/index.js +1 -1
  5. package/dist/{base-oP3DoUrm.d.cts → base-CZmT-p10.d.cts} +524 -53
  6. package/dist/{base-Bk5V1doj.d.ts → base-DDoWFpFc.d.ts} +524 -53
  7. package/dist/{chunk-NTHHPNOW.js → chunk-34622N67.js} +1 -1
  8. package/dist/{chunk-ATXF6TIO.cjs → chunk-422BXQRT.cjs} +24 -677
  9. package/dist/{chunk-HARYMLZH.js → chunk-4K4DHXRF.js} +6 -658
  10. package/dist/{chunk-N2ONCUUS.js → chunk-6AHC67YY.js} +132 -12
  11. package/dist/chunk-7AGAXO6B.cjs +588 -0
  12. package/dist/{chunk-GEIPVIW4.js → chunk-BFF2O6RO.js} +1 -1
  13. package/dist/{chunk-RASVJ3TR.js → chunk-BU45BMXY.js} +55 -1
  14. package/dist/{chunk-DIZZQ3E5.cjs → chunk-CEXM6WP5.cjs} +2 -2
  15. package/dist/chunk-HNEE7IF4.js +60 -0
  16. package/dist/{chunk-NZDXKMDP.cjs → chunk-LABUWBKX.cjs} +1 -1
  17. package/dist/chunk-MUNFCOMB.cjs +62 -0
  18. package/dist/{chunk-GJWCFDFN.js → chunk-PS2ZF6MA.js} +1 -1
  19. package/dist/{chunk-M472GIT6.js → chunk-SGGPJWRQ.js} +1 -1
  20. package/dist/{chunk-7CSNWYGJ.cjs → chunk-U5DGGGS2.cjs} +2 -2
  21. package/dist/{chunk-W5IA5OGL.cjs → chunk-V7IE36YV.cjs} +58 -4
  22. package/dist/chunk-VMVXIPGW.js +586 -0
  23. package/dist/{chunk-53P5ZBJE.cjs → chunk-YTTBFAQJ.cjs} +2 -2
  24. package/dist/{chunk-KZWBYRXW.cjs → chunk-YZFNMXY4.cjs} +135 -14
  25. package/dist/di/index.cjs +2 -2
  26. package/dist/di/index.d.cts +1 -52
  27. package/dist/di/index.d.ts +1 -52
  28. package/dist/di/index.js +1 -1
  29. package/dist/eval/index.d.cts +4 -2
  30. package/dist/eval/index.d.ts +4 -2
  31. package/dist/index.cjs +60 -55
  32. package/dist/index.d.cts +5 -3
  33. package/dist/index.d.ts +5 -3
  34. package/dist/index.js +10 -9
  35. package/dist/integration/index.cjs +3 -3
  36. package/dist/integration/index.d.cts +4 -2
  37. package/dist/integration/index.d.ts +4 -2
  38. package/dist/integration/index.js +1 -1
  39. package/dist/llm/index.cjs +8 -0
  40. package/dist/llm/index.d.cts +4 -2
  41. package/dist/llm/index.d.ts +4 -2
  42. package/dist/llm/index.js +1 -1
  43. package/dist/mastra/index.cjs +2 -2
  44. package/dist/mastra/index.d.cts +4 -2
  45. package/dist/mastra/index.d.ts +4 -2
  46. package/dist/mastra/index.js +1 -1
  47. package/dist/memory/index.cjs +7 -3
  48. package/dist/memory/index.d.cts +4 -2
  49. package/dist/memory/index.d.ts +4 -2
  50. package/dist/memory/index.js +1 -1
  51. package/dist/network/index.cjs +4 -4
  52. package/dist/network/index.d.cts +4 -2
  53. package/dist/network/index.d.ts +4 -2
  54. package/dist/network/index.js +2 -2
  55. package/dist/relevance/index.cjs +4 -4
  56. package/dist/relevance/index.d.cts +4 -2
  57. package/dist/relevance/index.d.ts +4 -2
  58. package/dist/relevance/index.js +1 -1
  59. package/dist/runtime-context/index.cjs +7 -68
  60. package/dist/runtime-context/index.js +1 -69
  61. package/dist/server/index.d.cts +4 -2
  62. package/dist/server/index.d.ts +4 -2
  63. package/dist/storage/index.d.cts +4 -2
  64. package/dist/storage/index.d.ts +4 -2
  65. package/dist/storage/libsql/index.cjs +19 -0
  66. package/dist/storage/libsql/index.d.cts +7 -8
  67. package/dist/storage/libsql/index.d.ts +7 -8
  68. package/dist/storage/libsql/index.js +19 -0
  69. package/dist/telemetry/index.d.cts +4 -2
  70. package/dist/telemetry/index.d.ts +4 -2
  71. package/dist/tools/index.cjs +4 -4
  72. package/dist/tools/index.d.cts +4 -2
  73. package/dist/tools/index.d.ts +4 -2
  74. package/dist/tools/index.js +1 -1
  75. package/dist/utils.cjs +14 -14
  76. package/dist/utils.d.cts +6 -4
  77. package/dist/utils.d.ts +6 -4
  78. package/dist/utils.js +1 -1
  79. package/dist/voice/index.d.cts +5 -3
  80. package/dist/voice/index.d.ts +5 -3
  81. package/dist/workflows/index.cjs +22 -26
  82. package/dist/workflows/index.d.cts +5 -3
  83. package/dist/workflows/index.d.ts +5 -3
  84. package/dist/workflows/index.js +1 -1
  85. package/dist/workflows/vNext/index.cjs +1058 -0
  86. package/dist/workflows/vNext/index.d.cts +180 -0
  87. package/dist/workflows/vNext/index.d.ts +180 -0
  88. package/dist/workflows/vNext/index.js +1046 -0
  89. package/package.json +11 -1
  90. package/workflows/vNext.d.ts +1 -0
  91. /package/dist/{chunk-WEYWYKLG.cjs → chunk-27PAET7X.cjs} +0 -0
  92. /package/dist/{chunk-FRQFWZDN.cjs → chunk-HSVOEWAM.cjs} +0 -0
  93. /package/dist/{chunk-ZDWFBE5L.js → chunk-NH5WJNNS.js} +0 -0
  94. /package/dist/{chunk-LANFNMEE.js → chunk-SGTFVHOZ.js} +0 -0
@@ -1,18 +1,18 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkFKUPMQZP_cjs = require('./chunk-FKUPMQZP.cjs');
4
+ var chunk7AGAXO6B_cjs = require('./chunk-7AGAXO6B.cjs');
4
5
  var chunkRIBNDTA6_cjs = require('./chunk-RIBNDTA6.cjs');
5
- var chunk53P5ZBJE_cjs = require('./chunk-53P5ZBJE.cjs');
6
+ var chunkYTTBFAQJ_cjs = require('./chunk-YTTBFAQJ.cjs');
6
7
  var chunkD63P5O4Q_cjs = require('./chunk-D63P5O4Q.cjs');
7
8
  var chunkO7IW545H_cjs = require('./chunk-O7IW545H.cjs');
8
- var chunkNZDXKMDP_cjs = require('./chunk-NZDXKMDP.cjs');
9
+ var chunkLABUWBKX_cjs = require('./chunk-LABUWBKX.cjs');
9
10
  var chunkST5RMVLG_cjs = require('./chunk-ST5RMVLG.cjs');
10
11
  var chunkRWTSGWWL_cjs = require('./chunk-RWTSGWWL.cjs');
11
12
  var api = require('@opentelemetry/api');
12
13
  var zod = require('zod');
13
14
  var radash = require('radash');
14
15
  var crypto$1 = require('crypto');
15
- var ai = require('ai');
16
16
  var EventEmitter = require('events');
17
17
  var sift = require('sift');
18
18
  var xstate = require('xstate');
@@ -50,9 +50,6 @@ var Step = class {
50
50
  this.retryConfig = retryConfig;
51
51
  }
52
52
  };
53
- function createStep(opts) {
54
- return new Step(opts);
55
- }
56
53
 
57
54
  // src/workflows/types.ts
58
55
  var WhenConditionReturnValue = /* @__PURE__ */(WhenConditionReturnValue2 => {
@@ -62,663 +59,13 @@ var WhenConditionReturnValue = /* @__PURE__ */(WhenConditionReturnValue2 => {
62
59
  WhenConditionReturnValue2["LIMBO"] = "limbo";
63
60
  return WhenConditionReturnValue2;
64
61
  })(WhenConditionReturnValue || {});
65
-
66
- // src/llm/model/base.ts
67
- var MastraLLMBase = class extends chunkD63P5O4Q_cjs.MastraBase {
68
- // @ts-ignore
69
- #mastra;
70
- #model;
71
- constructor({
72
- name,
73
- model
74
- }) {
75
- super({
76
- component: chunkO7IW545H_cjs.RegisteredLogger.LLM,
77
- name
78
- });
79
- this.#model = model;
80
- }
81
- getProvider() {
82
- return this.#model.provider;
83
- }
84
- getModelId() {
85
- return this.#model.modelId;
86
- }
87
- getModel() {
88
- return this.#model;
89
- }
90
- convertToMessages(messages) {
91
- if (Array.isArray(messages)) {
92
- return messages.map(m => {
93
- if (typeof m === "string") {
94
- return {
95
- role: "user",
96
- content: m
97
- };
98
- }
99
- return m;
100
- });
101
- }
102
- return [{
103
- role: "user",
104
- content: messages
105
- }];
106
- }
107
- __registerPrimitives(p) {
108
- if (p.telemetry) {
109
- this.__setTelemetry(p.telemetry);
110
- }
111
- if (p.logger) {
112
- this.__setLogger(p.logger);
113
- }
114
- }
115
- __registerMastra(p) {
116
- this.#mastra = p;
117
- }
118
- async __text(input) {
119
- this.logger.debug(`[LLMs:${this.name}] Generating text.`, {
120
- input
121
- });
122
- throw new Error("Method not implemented.");
123
- }
124
- async __textObject(input) {
125
- this.logger.debug(`[LLMs:${this.name}] Generating object.`, {
126
- input
127
- });
128
- throw new Error("Method not implemented.");
129
- }
130
- async generate(messages, options) {
131
- this.logger.debug(`[LLMs:${this.name}] Generating text.`, {
132
- messages,
133
- options
134
- });
135
- throw new Error("Method not implemented.");
136
- }
137
- async __stream(input) {
138
- this.logger.debug(`[LLMs:${this.name}] Streaming text.`, {
139
- input
140
- });
141
- throw new Error("Method not implemented.");
142
- }
143
- async __streamObject(input) {
144
- this.logger.debug(`[LLMs:${this.name}] Streaming object.`, {
145
- input
146
- });
147
- throw new Error("Method not implemented.");
148
- }
149
- async stream(messages, options) {
150
- this.logger.debug(`[LLMs:${this.name}] Streaming text.`, {
151
- messages,
152
- options
153
- });
154
- throw new Error("Method not implemented.");
155
- }
156
- };
157
- var MastraLLM = class extends MastraLLMBase {
158
- #model;
159
- #mastra;
160
- constructor({
161
- model,
162
- mastra
163
- }) {
164
- super({
165
- name: "aisdk",
166
- model
167
- });
168
- this.#model = model;
169
- if (mastra) {
170
- this.#mastra = mastra;
171
- if (mastra.getLogger()) {
172
- this.__setLogger(mastra.getLogger());
173
- }
174
- }
175
- }
176
- __registerPrimitives(p) {
177
- if (p.telemetry) {
178
- this.__setTelemetry(p.telemetry);
179
- }
180
- if (p.logger) {
181
- this.__setLogger(p.logger);
182
- }
183
- }
184
- __registerMastra(p) {
185
- this.#mastra = p;
186
- }
187
- getProvider() {
188
- return this.#model.provider;
189
- }
190
- getModelId() {
191
- return this.#model.modelId;
192
- }
193
- getModel() {
194
- return this.#model;
195
- }
196
- convertTools({
197
- tools,
198
- runId,
199
- threadId,
200
- resourceId,
201
- memory,
202
- runtimeContext
203
- }) {
204
- this.logger.debug("Starting tool conversion for LLM");
205
- let mastraProxy = void 0;
206
- const logger = this.logger;
207
- if (this.#mastra) {
208
- mastraProxy = chunk53P5ZBJE_cjs.createMastraProxy({
209
- mastra: this.#mastra,
210
- logger
211
- });
212
- }
213
- const converted = Object.entries(tools || {}).reduce((memo, value) => {
214
- const k = value[0];
215
- const tool = value[1];
216
- if (tool) {
217
- const options = {
218
- name: k,
219
- runId,
220
- threadId,
221
- resourceId,
222
- logger: this.logger,
223
- memory,
224
- mastra: mastraProxy,
225
- runtimeContext
226
- };
227
- memo[k] = chunk53P5ZBJE_cjs.makeCoreTool(tool, options);
228
- }
229
- return memo;
230
- }, {});
231
- this.logger.debug(`Converted tools for LLM`);
232
- return converted;
233
- }
234
- async __text({
235
- runId,
236
- messages,
237
- maxSteps = 5,
238
- tools,
239
- convertedTools,
240
- temperature,
241
- toolChoice = "auto",
242
- onStepFinish,
243
- experimental_output,
244
- telemetry,
245
- threadId,
246
- resourceId,
247
- memory,
248
- runtimeContext,
249
- ...rest
250
- }) {
251
- const model = this.#model;
252
- this.logger.debug(`[LLM] - Generating text`, {
253
- runId,
254
- messages,
255
- maxSteps,
256
- threadId,
257
- resourceId,
258
- tools: Object.keys(tools || convertedTools || {})
259
- });
260
- const finalTools = convertedTools || this.convertTools({
261
- tools,
262
- runId,
263
- threadId,
264
- resourceId,
265
- memory,
266
- runtimeContext
267
- });
268
- const argsForExecute = {
269
- model,
270
- temperature,
271
- tools: {
272
- ...finalTools
273
- },
274
- toolChoice,
275
- maxSteps,
276
- onStepFinish: async props => {
277
- void onStepFinish?.(props);
278
- this.logger.debug("[LLM] - Step Change:", {
279
- text: props?.text,
280
- toolCalls: props?.toolCalls,
281
- toolResults: props?.toolResults,
282
- finishReason: props?.finishReason,
283
- usage: props?.usage,
284
- runId
285
- });
286
- if (props?.response?.headers?.["x-ratelimit-remaining-tokens"] && parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"], 10) < 2e3) {
287
- this.logger.warn("Rate limit approaching, waiting 10 seconds", {
288
- runId
289
- });
290
- await chunk53P5ZBJE_cjs.delay(10 * 1e3);
291
- }
292
- },
293
- ...rest
294
- };
295
- let schema;
296
- if (experimental_output) {
297
- this.logger.debug("[LLM] - Using experimental output", {
298
- runId
299
- });
300
- if (typeof experimental_output.parse === "function") {
301
- schema = experimental_output;
302
- if (schema instanceof zod.z.ZodArray) {
303
- schema = schema._def.type;
304
- }
305
- } else {
306
- schema = ai.jsonSchema(experimental_output);
307
- }
308
- }
309
- return await ai.generateText({
310
- messages,
311
- ...argsForExecute,
312
- experimental_telemetry: {
313
- ...this.experimental_telemetry,
314
- ...telemetry
315
- },
316
- experimental_output: schema ? ai.Output.object({
317
- schema
318
- }) : void 0
319
- });
320
- }
321
- async __textObject({
322
- messages,
323
- onStepFinish,
324
- maxSteps = 5,
325
- tools,
326
- convertedTools,
327
- structuredOutput,
328
- runId,
329
- temperature,
330
- toolChoice = "auto",
331
- telemetry,
332
- threadId,
333
- resourceId,
334
- memory,
335
- runtimeContext,
336
- ...rest
337
- }) {
338
- const model = this.#model;
339
- this.logger.debug(`[LLM] - Generating a text object`, {
340
- runId
341
- });
342
- const finalTools = convertedTools || this.convertTools({
343
- tools,
344
- runId,
345
- threadId,
346
- resourceId,
347
- memory,
348
- runtimeContext
349
- });
350
- const argsForExecute = {
351
- model,
352
- temperature,
353
- tools: {
354
- ...finalTools
355
- },
356
- maxSteps,
357
- toolChoice,
358
- onStepFinish: async props => {
359
- void onStepFinish?.(props);
360
- this.logger.debug("[LLM] - Step Change:", {
361
- text: props?.text,
362
- toolCalls: props?.toolCalls,
363
- toolResults: props?.toolResults,
364
- finishReason: props?.finishReason,
365
- usage: props?.usage,
366
- runId
367
- });
368
- if (props?.response?.headers?.["x-ratelimit-remaining-tokens"] && parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"], 10) < 2e3) {
369
- this.logger.warn("Rate limit approaching, waiting 10 seconds", {
370
- runId
371
- });
372
- await chunk53P5ZBJE_cjs.delay(10 * 1e3);
373
- }
374
- },
375
- ...rest
376
- };
377
- let schema;
378
- let output = "object";
379
- if (typeof structuredOutput.parse === "function") {
380
- schema = structuredOutput;
381
- if (schema instanceof zod.z.ZodArray) {
382
- output = "array";
383
- schema = schema._def.type;
384
- }
385
- } else {
386
- schema = ai.jsonSchema(structuredOutput);
387
- }
388
- return await ai.generateObject({
389
- messages,
390
- ...argsForExecute,
391
- output,
392
- schema,
393
- experimental_telemetry: {
394
- ...this.experimental_telemetry,
395
- ...telemetry
396
- }
397
- });
398
- }
399
- async __stream({
400
- messages,
401
- onStepFinish,
402
- onFinish,
403
- maxSteps = 5,
404
- tools,
405
- convertedTools,
406
- runId,
407
- temperature,
408
- toolChoice = "auto",
409
- experimental_output,
410
- telemetry,
411
- threadId,
412
- resourceId,
413
- memory,
414
- runtimeContext,
415
- ...rest
416
- }) {
417
- const model = this.#model;
418
- this.logger.debug(`[LLM] - Streaming text`, {
419
- runId,
420
- threadId,
421
- resourceId,
422
- messages,
423
- maxSteps,
424
- tools: Object.keys(tools || convertedTools || {})
425
- });
426
- const finalTools = convertedTools || this.convertTools({
427
- tools,
428
- runId,
429
- threadId,
430
- resourceId,
431
- memory,
432
- runtimeContext
433
- });
434
- const argsForExecute = {
435
- model,
436
- temperature,
437
- tools: {
438
- ...finalTools
439
- },
440
- maxSteps,
441
- toolChoice,
442
- onStepFinish: async props => {
443
- void onStepFinish?.(props);
444
- this.logger.debug("[LLM] - Stream Step Change:", {
445
- text: props?.text,
446
- toolCalls: props?.toolCalls,
447
- toolResults: props?.toolResults,
448
- finishReason: props?.finishReason,
449
- usage: props?.usage,
450
- runId
451
- });
452
- if (props?.response?.headers?.["x-ratelimit-remaining-tokens"] && parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"], 10) < 2e3) {
453
- this.logger.warn("Rate limit approaching, waiting 10 seconds", {
454
- runId
455
- });
456
- await chunk53P5ZBJE_cjs.delay(10 * 1e3);
457
- }
458
- },
459
- onFinish: async props => {
460
- void onFinish?.(props);
461
- this.logger.debug("[LLM] - Stream Finished:", {
462
- text: props?.text,
463
- toolCalls: props?.toolCalls,
464
- toolResults: props?.toolResults,
465
- finishReason: props?.finishReason,
466
- usage: props?.usage,
467
- runId,
468
- threadId,
469
- resourceId
470
- });
471
- },
472
- ...rest
473
- };
474
- let schema;
475
- if (experimental_output) {
476
- this.logger.debug("[LLM] - Using experimental output", {
477
- runId
478
- });
479
- if (typeof experimental_output.parse === "function") {
480
- schema = experimental_output;
481
- if (schema instanceof zod.z.ZodArray) {
482
- schema = schema._def.type;
483
- }
484
- } else {
485
- schema = ai.jsonSchema(experimental_output);
486
- }
487
- }
488
- return await ai.streamText({
489
- messages,
490
- ...argsForExecute,
491
- experimental_telemetry: {
492
- ...this.experimental_telemetry,
493
- ...telemetry
494
- },
495
- experimental_output: schema ? ai.Output.object({
496
- schema
497
- }) : void 0
498
- });
499
- }
500
- async __streamObject({
501
- messages,
502
- runId,
503
- tools,
504
- convertedTools,
505
- maxSteps = 5,
506
- toolChoice = "auto",
507
- runtimeContext,
508
- threadId,
509
- resourceId,
510
- memory,
511
- temperature,
512
- onStepFinish,
513
- onFinish,
514
- structuredOutput,
515
- telemetry,
516
- ...rest
517
- }) {
518
- const model = this.#model;
519
- this.logger.debug(`[LLM] - Streaming structured output`, {
520
- runId,
521
- messages,
522
- maxSteps,
523
- tools: Object.keys(tools || convertedTools || {})
524
- });
525
- const finalTools = convertedTools || this.convertTools({
526
- tools,
527
- runId,
528
- threadId,
529
- resourceId,
530
- memory,
531
- runtimeContext
532
- });
533
- const argsForExecute = {
534
- model,
535
- temperature,
536
- tools: {
537
- ...finalTools
538
- },
539
- maxSteps,
540
- toolChoice,
541
- onStepFinish: async props => {
542
- void onStepFinish?.(props);
543
- this.logger.debug("[LLM] - Stream Step Change:", {
544
- text: props?.text,
545
- toolCalls: props?.toolCalls,
546
- toolResults: props?.toolResults,
547
- finishReason: props?.finishReason,
548
- usage: props?.usage,
549
- runId,
550
- threadId,
551
- resourceId
552
- });
553
- if (props?.response?.headers?.["x-ratelimit-remaining-tokens"] && parseInt(props?.response?.headers?.["x-ratelimit-remaining-tokens"], 10) < 2e3) {
554
- this.logger.warn("Rate limit approaching, waiting 10 seconds", {
555
- runId
556
- });
557
- await chunk53P5ZBJE_cjs.delay(10 * 1e3);
558
- }
559
- },
560
- onFinish: async props => {
561
- void onFinish?.(props);
562
- this.logger.debug("[LLM] - Stream Finished:", {
563
- text: props?.text,
564
- toolCalls: props?.toolCalls,
565
- toolResults: props?.toolResults,
566
- finishReason: props?.finishReason,
567
- usage: props?.usage,
568
- runId,
569
- threadId,
570
- resourceId
571
- });
572
- },
573
- ...rest
574
- };
575
- let schema;
576
- let output = "object";
577
- if (typeof structuredOutput.parse === "function") {
578
- schema = structuredOutput;
579
- if (schema instanceof zod.z.ZodArray) {
580
- output = "array";
581
- schema = schema._def.type;
582
- }
583
- } else {
584
- schema = ai.jsonSchema(structuredOutput);
585
- }
586
- return ai.streamObject({
587
- messages,
588
- ...argsForExecute,
589
- output,
590
- schema,
591
- experimental_telemetry: {
592
- ...this.experimental_telemetry,
593
- ...telemetry
594
- }
595
- });
596
- }
597
- async generate(messages, {
598
- maxSteps = 5,
599
- output,
600
- ...rest
601
- }) {
602
- const msgs = this.convertToMessages(messages);
603
- if (!output) {
604
- return await this.__text({
605
- messages: msgs,
606
- maxSteps,
607
- ...rest
608
- });
609
- }
610
- return await this.__textObject({
611
- messages: msgs,
612
- structuredOutput: output,
613
- maxSteps,
614
- ...rest
615
- });
616
- }
617
- async stream(messages, {
618
- maxSteps = 5,
619
- output,
620
- ...rest
621
- }) {
622
- const msgs = this.convertToMessages(messages);
623
- if (!output) {
624
- return await this.__stream({
625
- messages: msgs,
626
- maxSteps,
627
- ...rest
628
- });
629
- }
630
- return await this.__streamObject({
631
- messages: msgs,
632
- structuredOutput: output,
633
- maxSteps,
634
- ...rest
635
- });
636
- }
637
- convertToUIMessages(messages) {
638
- function addToolMessageToChat({
639
- toolMessage,
640
- messages: messages2,
641
- toolResultContents
642
- }) {
643
- const chatMessages2 = messages2.map(message => {
644
- if (message.toolInvocations) {
645
- return {
646
- ...message,
647
- toolInvocations: message.toolInvocations.map(toolInvocation => {
648
- const toolResult = toolMessage.content.find(tool => tool.toolCallId === toolInvocation.toolCallId);
649
- if (toolResult) {
650
- return {
651
- ...toolInvocation,
652
- state: "result",
653
- result: toolResult.result
654
- };
655
- }
656
- return toolInvocation;
657
- })
658
- };
659
- }
660
- return message;
661
- });
662
- const resultContents = [...toolResultContents, ...toolMessage.content];
663
- return {
664
- chatMessages: chatMessages2,
665
- toolResultContents: resultContents
666
- };
667
- }
668
- const {
669
- chatMessages
670
- } = messages.reduce((obj, message) => {
671
- if (message.role === "tool") {
672
- return addToolMessageToChat({
673
- toolMessage: message,
674
- messages: obj.chatMessages,
675
- toolResultContents: obj.toolResultContents
676
- });
677
- }
678
- let textContent = "";
679
- let toolInvocations = [];
680
- if (typeof message.content === "string") {
681
- textContent = message.content;
682
- } else if (typeof message.content === "number") {
683
- textContent = String(message.content);
684
- } else if (Array.isArray(message.content)) {
685
- for (const content of message.content) {
686
- if (content.type === "text") {
687
- textContent += content.text;
688
- } else if (content.type === "tool-call") {
689
- const toolResult = obj.toolResultContents.find(tool => tool.toolCallId === content.toolCallId);
690
- toolInvocations.push({
691
- state: toolResult ? "result" : "call",
692
- toolCallId: content.toolCallId,
693
- toolName: content.toolName,
694
- args: content.args,
695
- result: toolResult?.result
696
- });
697
- }
698
- }
699
- }
700
- obj.chatMessages.push({
701
- id: message.id,
702
- role: message.role,
703
- content: textContent,
704
- toolInvocations
705
- });
706
- return obj;
707
- }, {
708
- chatMessages: [],
709
- toolResultContents: []
710
- });
711
- return chatMessages;
712
- }
713
- };
714
-
715
- // src/agent/index.ts
716
62
  var _Agent_decorators, _init, _a;
717
63
  _Agent_decorators = [chunkRIBNDTA6_cjs.InstrumentClass({
718
64
  prefix: "agent",
719
65
  excludeMethods: ["hasOwnMemory", "getMemory", "__primitive", "__setTools", "__setLogger", "__setTelemetry", "log"]
720
66
  })];
721
67
  exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
68
+ id;
722
69
  name;
723
70
  llm;
724
71
  instructions;
@@ -737,11 +84,12 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
737
84
  component: chunkO7IW545H_cjs.RegisteredLogger.AGENT
738
85
  });
739
86
  this.name = config.name;
87
+ this.id = config.name;
740
88
  this.instructions = config.instructions;
741
89
  if (!config.model) {
742
90
  throw new Error(`LanguageModel is required to create an Agent. Please provide the 'model'.`);
743
91
  }
744
- this.llm = new MastraLLM({
92
+ this.llm = new chunk7AGAXO6B_cjs.MastraLLM({
745
93
  model: config.model,
746
94
  mastra: config.mastra
747
95
  });
@@ -751,7 +99,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
751
99
  this.metrics = {};
752
100
  this.evals = {};
753
101
  if (config.tools) {
754
- this.tools = chunk53P5ZBJE_cjs.ensureToolProperties(config.tools);
102
+ this.tools = chunkYTTBFAQJ_cjs.ensureToolProperties(config.tools);
755
103
  }
756
104
  if (config.mastra) {
757
105
  this.__registerMastra(config.mastra);
@@ -826,7 +174,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
826
174
  const {
827
175
  text
828
176
  } = await this.llm.__text({
829
- runtimeContext: new chunkNZDXKMDP_cjs.RuntimeContext(),
177
+ runtimeContext: new chunkLABUWBKX_cjs.RuntimeContext(),
830
178
  messages: [{
831
179
  role: "system",
832
180
  content: `
@@ -881,7 +229,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
881
229
  messages: userMessages
882
230
  };
883
231
  }
884
- const newMessages = chunk53P5ZBJE_cjs.ensureAllMessagesAreCoreMessages(userMessages);
232
+ const newMessages = chunkYTTBFAQJ_cjs.ensureAllMessagesAreCoreMessages(userMessages);
885
233
  const now = Date.now();
886
234
  const messages = newMessages.map((u, index) => {
887
235
  return {
@@ -1059,7 +407,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
1059
407
  let mastraProxy = void 0;
1060
408
  const logger = this.logger;
1061
409
  if (this.#mastra) {
1062
- mastraProxy = chunk53P5ZBJE_cjs.createMastraProxy({
410
+ mastraProxy = chunkYTTBFAQJ_cjs.createMastraProxy({
1063
411
  mastra: this.#mastra,
1064
412
  logger
1065
413
  });
@@ -1079,7 +427,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
1079
427
  agentName: this.name,
1080
428
  runtimeContext
1081
429
  };
1082
- memo[k] = chunk53P5ZBJE_cjs.makeCoreTool(tool, options);
430
+ memo[k] = chunkYTTBFAQJ_cjs.makeCoreTool(tool, options);
1083
431
  }
1084
432
  return memo;
1085
433
  }, {});
@@ -1144,7 +492,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
1144
492
  agentName: this.name,
1145
493
  runtimeContext
1146
494
  };
1147
- const convertedToCoreTool = chunk53P5ZBJE_cjs.makeCoreTool(toolObj, options, "toolset");
495
+ const convertedToCoreTool = chunkYTTBFAQJ_cjs.makeCoreTool(toolObj, options, "toolset");
1148
496
  toolsFromToolsetsConverted[toolName] = convertedToCoreTool;
1149
497
  });
1150
498
  });
@@ -1170,7 +518,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
1170
518
  agentName: this.name,
1171
519
  runtimeContext
1172
520
  };
1173
- const convertedToCoreTool = chunk53P5ZBJE_cjs.makeCoreTool(rest, options, "client-tool");
521
+ const convertedToCoreTool = chunkYTTBFAQJ_cjs.makeCoreTool(rest, options, "client-tool");
1174
522
  toolsFromToolsetsConverted[toolName] = convertedToCoreTool;
1175
523
  });
1176
524
  }
@@ -1337,7 +685,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
1337
685
  const userMessage = this.getMostRecentUserMessage(messages);
1338
686
  const newMessages = userMessage ? [userMessage] : messages;
1339
687
  const now = Date.now();
1340
- const threadMessages = this.sanitizeResponseMessages(chunk53P5ZBJE_cjs.ensureAllMessagesAreCoreMessages(newMessages)).map((u, index) => {
688
+ const threadMessages = this.sanitizeResponseMessages(chunkYTTBFAQJ_cjs.ensureAllMessagesAreCoreMessages(newMessages)).map((u, index) => {
1341
689
  return {
1342
690
  id: this.getMemory()?.generateId(),
1343
691
  createdAt: new Date(now + index),
@@ -1441,7 +789,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
1441
789
  messagesToUse = [messages];
1442
790
  }
1443
791
  const runIdToUse = runId || crypto$1.randomUUID();
1444
- const normalizedRuntimeContext = runtimeContext ?? new chunkNZDXKMDP_cjs.RuntimeContext();
792
+ const normalizedRuntimeContext = runtimeContext ?? new chunkLABUWBKX_cjs.RuntimeContext();
1445
793
  const {
1446
794
  before,
1447
795
  after
@@ -1574,7 +922,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
1574
922
  runtimeContext,
1575
923
  ...rest
1576
924
  } = Object.assign({}, this.#defaultStreamOptions, streamOptions);
1577
- const normalizedRuntimeContext = runtimeContext ?? new chunkNZDXKMDP_cjs.RuntimeContext();
925
+ const normalizedRuntimeContext = runtimeContext ?? new chunkLABUWBKX_cjs.RuntimeContext();
1578
926
  const runIdToUse = runId || crypto$1.randomUUID();
1579
927
  let messagesToUse = [];
1580
928
  if (typeof messages === `string`) {
@@ -2398,7 +1746,7 @@ var Machine = class extends EventEmitter__default.default {
2398
1746
  const logger = this.logger;
2399
1747
  let mastraProxy = void 0;
2400
1748
  if (this.#mastra) {
2401
- mastraProxy = chunk53P5ZBJE_cjs.createMastraProxy({
1749
+ mastraProxy = chunkYTTBFAQJ_cjs.createMastraProxy({
2402
1750
  mastra: this.#mastra,
2403
1751
  logger
2404
1752
  });
@@ -3265,7 +2613,7 @@ var WorkflowInstance = class {
3265
2613
  } = {}) {
3266
2614
  const results = await this.execute({
3267
2615
  triggerData,
3268
- runtimeContext: runtimeContext ?? new chunkNZDXKMDP_cjs.RuntimeContext()
2616
+ runtimeContext: runtimeContext ?? new chunkLABUWBKX_cjs.RuntimeContext()
3269
2617
  });
3270
2618
  if (this.#onFinish) {
3271
2619
  this.#onFinish();
@@ -3287,7 +2635,7 @@ var WorkflowInstance = class {
3287
2635
  resumeData,
3288
2636
  runtimeContext
3289
2637
  } = {
3290
- runtimeContext: new chunkNZDXKMDP_cjs.RuntimeContext()
2638
+ runtimeContext: new chunkLABUWBKX_cjs.RuntimeContext()
3291
2639
  }) {
3292
2640
  this.#executionSpan = this.#mastra?.getTelemetry()?.tracer.startSpan(`workflow.${this.name}.execute`, {
3293
2641
  attributes: {
@@ -3387,7 +2735,7 @@ var WorkflowInstance = class {
3387
2735
  hasSubscribers(stepId) {
3388
2736
  return Object.keys(this.#stepSubscriberGraph).some(key => key.split("&&").includes(stepId));
3389
2737
  }
3390
- async runMachine(parentStepId, input, runtimeContext = new chunkNZDXKMDP_cjs.RuntimeContext()) {
2738
+ async runMachine(parentStepId, input, runtimeContext = new chunkLABUWBKX_cjs.RuntimeContext()) {
3391
2739
  const stepStatus = input.steps[parentStepId]?.status;
3392
2740
  const subscriberKeys = Object.keys(this.#stepSubscriberGraph).filter(key => key.split("&&").includes(parentStepId));
3393
2741
  subscriberKeys.forEach(key => {
@@ -3575,7 +2923,7 @@ var WorkflowInstance = class {
3575
2923
  timestamp: Date.now()
3576
2924
  };
3577
2925
  }
3578
- async resumeWithEvent(eventName, data, runtimeContext = new chunkNZDXKMDP_cjs.RuntimeContext()) {
2926
+ async resumeWithEvent(eventName, data, runtimeContext = new chunkLABUWBKX_cjs.RuntimeContext()) {
3579
2927
  const event = this.events?.[eventName];
3580
2928
  if (!event) {
3581
2929
  throw new Error(`Event ${eventName} not found`);
@@ -3592,7 +2940,7 @@ var WorkflowInstance = class {
3592
2940
  async resume({
3593
2941
  stepId,
3594
2942
  context: resumeContext,
3595
- runtimeContext = new chunkNZDXKMDP_cjs.RuntimeContext()
2943
+ runtimeContext = new chunkLABUWBKX_cjs.RuntimeContext()
3596
2944
  }) {
3597
2945
  await new Promise(resolve => setTimeout(resolve, 0));
3598
2946
  return this._resume({
@@ -4651,7 +3999,7 @@ var Workflow = class extends chunkD63P5O4Q_cjs.MastraBase {
4651
3999
  runId,
4652
4000
  stepId,
4653
4001
  context: resumeContext,
4654
- runtimeContext = new chunkNZDXKMDP_cjs.RuntimeContext()
4002
+ runtimeContext = new chunkLABUWBKX_cjs.RuntimeContext()
4655
4003
  }) {
4656
4004
  this.logger.warn(`Please use 'resume' on the 'createRun' call instead, resume is deprecated`);
4657
4005
  const activeRun = this.#runs.get(runId);
@@ -4690,7 +4038,7 @@ var Workflow = class extends chunkD63P5O4Q_cjs.MastraBase {
4690
4038
  context: {
4691
4039
  resumedEvent: data
4692
4040
  },
4693
- runtimeContext: new chunkNZDXKMDP_cjs.RuntimeContext()
4041
+ runtimeContext: new chunkLABUWBKX_cjs.RuntimeContext()
4694
4042
  });
4695
4043
  return results;
4696
4044
  }
@@ -4738,7 +4086,6 @@ exports.Step = Step;
4738
4086
  exports.WhenConditionReturnValue = WhenConditionReturnValue;
4739
4087
  exports.Workflow = Workflow;
4740
4088
  exports.agentToStep = agentToStep;
4741
- exports.createStep = createStep;
4742
4089
  exports.getActivePathsAndStatus = getActivePathsAndStatus;
4743
4090
  exports.getResultActivePaths = getResultActivePaths;
4744
4091
  exports.getStepResult = getStepResult;