@mastra/core 0.5.0-alpha.1 → 0.5.0-alpha.10
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 +260 -110
- package/dist/agent/index.d.cts +8 -6
- package/dist/agent/index.d.ts +8 -6
- package/dist/agent/index.js +1 -1
- package/dist/{base-D90KQ4XI.d.ts → base-BZViaFTt.d.ts} +2 -0
- package/dist/{base-C_bOLlEO.d.cts → base-DLJ5WisC.d.cts} +233 -57
- package/dist/{base-hs9NDAZ2.d.cts → base-DboIg_Cd.d.cts} +2 -0
- package/dist/{base-42kpYoR1.d.ts → base-mFfX31Ho.d.ts} +233 -57
- package/dist/base.cjs +8 -1
- package/dist/base.d.cts +1 -1
- package/dist/base.d.ts +1 -1
- package/dist/base.js +1 -1
- package/dist/bundler/index.cjs +8 -1
- package/dist/bundler/index.d.cts +1 -1
- package/dist/bundler/index.d.ts +1 -1
- package/dist/bundler/index.js +1 -1
- package/dist/{chunk-UFMLHP4G.js → chunk-27KRMMYF.js} +110 -107
- package/dist/{chunk-PHMSPCTC.js → chunk-3JSTLSIP.js} +8 -1
- package/dist/{chunk-SH6KVX4B.js → chunk-4AQBRUR2.js} +1 -1
- package/dist/{chunk-P47D7HYO.js → chunk-4DD2PP2R.js} +70 -6
- package/dist/{chunk-OZ4XVJ6F.js → chunk-4VHCCQ7P.js} +1 -1
- package/dist/{chunk-C2YWDMSM.js → chunk-5IKL2XPR.js} +280 -42
- package/dist/{chunk-4YRYBCOZ.js → chunk-6PNJOPFO.js} +1 -1
- package/dist/{chunk-KQN7VU7J.js → chunk-7TZAPEAT.js} +1 -1
- package/dist/{chunk-QAAJAHDB.js → chunk-CLJYFFOS.js} +1 -1
- package/dist/{chunk-SVEAENO7.js → chunk-ECNK7OU3.js} +1 -1
- package/dist/{chunk-3GC7P4J6.js → chunk-IM7CM3DU.js} +149 -2
- package/dist/{chunk-PBED2445.js → chunk-NR5T72G7.js} +25 -11
- package/dist/{chunk-MGBSRQQW.js → chunk-QAZ2ONKM.js} +30 -8
- package/dist/{chunk-I5KM37BN.js → chunk-QLYZGX5Z.js} +7 -1
- package/dist/{chunk-NWPCPTB7.js → chunk-TWAIC2XA.js} +67 -112
- package/dist/deployer/index.cjs +8 -1
- package/dist/deployer/index.d.cts +1 -1
- package/dist/deployer/index.d.ts +1 -1
- package/dist/deployer/index.js +1 -1
- package/dist/eval/index.d.cts +6 -4
- package/dist/eval/index.d.ts +6 -4
- package/dist/hooks/index.d.cts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/index.cjs +837 -300
- package/dist/index.d.cts +13 -16
- package/dist/index.d.ts +13 -16
- package/dist/index.js +15 -15
- package/dist/integration/index.d.cts +10 -9
- package/dist/integration/index.d.ts +10 -9
- package/dist/llm/index.d.cts +8 -6
- package/dist/llm/index.d.ts +8 -6
- package/dist/logger/index.cjs +8 -1
- package/dist/logger/index.js +1 -1
- package/dist/mastra/index.cjs +138 -111
- package/dist/mastra/index.d.cts +11 -61
- package/dist/mastra/index.d.ts +11 -61
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +133 -20
- package/dist/memory/index.d.cts +6 -4
- package/dist/memory/index.d.ts +6 -4
- package/dist/memory/index.js +1 -1
- package/dist/relevance/index.cjs +260 -110
- package/dist/relevance/index.js +1 -1
- package/dist/storage/index.cjs +8 -1
- package/dist/storage/index.d.cts +6 -4
- package/dist/storage/index.d.ts +6 -4
- package/dist/storage/index.js +1 -1
- package/dist/storage/libsql/index.cjs +36 -7
- package/dist/storage/libsql/index.d.cts +6 -4
- package/dist/storage/libsql/index.d.ts +6 -4
- package/dist/storage/libsql/index.js +1 -1
- package/dist/telemetry/index.d.cts +6 -4
- package/dist/telemetry/index.d.ts +6 -4
- package/dist/telemetry/otel-vendor.cjs +5 -0
- package/dist/telemetry/otel-vendor.d.cts +1 -0
- package/dist/telemetry/otel-vendor.d.ts +1 -0
- package/dist/telemetry/otel-vendor.js +1 -0
- package/dist/tools/index.d.cts +14 -12
- package/dist/tools/index.d.ts +14 -12
- package/dist/tts/index.cjs +8 -1
- package/dist/tts/index.d.cts +1 -1
- package/dist/tts/index.d.ts +1 -1
- package/dist/tts/index.js +1 -1
- package/dist/{types-m9RryK9a.d.cts → types-CwTG2XyQ.d.cts} +1 -1
- package/dist/{types-m9RryK9a.d.ts → types-CwTG2XyQ.d.ts} +1 -1
- package/dist/utils.cjs +176 -0
- package/dist/utils.d.cts +68 -1
- package/dist/utils.d.ts +68 -1
- package/dist/utils.js +1 -1
- package/dist/vector/index.cjs +14 -1
- package/dist/vector/index.d.cts +6 -1
- package/dist/vector/index.d.ts +6 -1
- package/dist/vector/index.js +1 -1
- package/dist/vector/libsql/index.cjs +82 -5
- package/dist/vector/libsql/index.d.cts +17 -1
- package/dist/vector/libsql/index.d.ts +17 -1
- package/dist/vector/libsql/index.js +1 -1
- package/dist/voice/index.cjs +8 -1
- package/dist/voice/index.d.cts +1 -1
- package/dist/voice/index.d.ts +1 -1
- package/dist/voice/index.js +1 -1
- package/dist/workflows/index.cjs +332 -41
- package/dist/workflows/index.d.cts +9 -8
- package/dist/workflows/index.d.ts +9 -8
- package/dist/workflows/index.js +1 -1
- package/package.json +8 -2
- package/dist/workflow-CFuzV18A.d.ts +0 -96
- package/dist/workflow-CosscczK.d.cts +0 -96
package/dist/agent/index.cjs
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var crypto$1 = require('crypto');
|
|
4
|
-
var zod = require('zod');
|
|
5
4
|
var stream = require('stream');
|
|
6
5
|
var pino = require('pino');
|
|
7
6
|
var pretty = require('pino-pretty');
|
|
8
7
|
var ai = require('ai');
|
|
8
|
+
var zod = require('zod');
|
|
9
|
+
var jsonSchemaToZod = require('json-schema-to-zod');
|
|
9
10
|
var api = require('@opentelemetry/api');
|
|
10
11
|
|
|
11
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
13
|
|
|
13
14
|
var pino__default = /*#__PURE__*/_interopDefault(pino);
|
|
14
15
|
var pretty__default = /*#__PURE__*/_interopDefault(pretty);
|
|
16
|
+
var jsonSchemaToZod__default = /*#__PURE__*/_interopDefault(jsonSchemaToZod);
|
|
15
17
|
|
|
16
18
|
var __create = Object.create;
|
|
17
19
|
var __defProp = Object.defineProperty;
|
|
@@ -74,7 +76,14 @@ var Logger = class {
|
|
|
74
76
|
const transportsAry = Object.entries(this.transports);
|
|
75
77
|
this.logger = pino__default.default({
|
|
76
78
|
name: options.name || "app",
|
|
77
|
-
level: options.level || LogLevel.INFO
|
|
79
|
+
level: options.level || LogLevel.INFO,
|
|
80
|
+
formatters: {
|
|
81
|
+
level: label => {
|
|
82
|
+
return {
|
|
83
|
+
level: label
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
78
87
|
}, options.overrideDefaultTransports ? options?.transports?.default : transportsAry.length === 0 ? pretty__default.default({
|
|
79
88
|
colorize: true,
|
|
80
89
|
levelFirst: true,
|
|
@@ -354,7 +363,193 @@ var MastraLLMBase = class extends MastraBase {
|
|
|
354
363
|
throw new Error("Method not implemented.");
|
|
355
364
|
}
|
|
356
365
|
};
|
|
366
|
+
|
|
367
|
+
// src/tools/tool.ts
|
|
368
|
+
var Tool = class {
|
|
369
|
+
id;
|
|
370
|
+
description;
|
|
371
|
+
inputSchema;
|
|
372
|
+
outputSchema;
|
|
373
|
+
execute;
|
|
374
|
+
mastra;
|
|
375
|
+
constructor(opts) {
|
|
376
|
+
this.id = opts.id;
|
|
377
|
+
this.description = opts.description;
|
|
378
|
+
this.inputSchema = opts.inputSchema;
|
|
379
|
+
this.outputSchema = opts.outputSchema;
|
|
380
|
+
this.execute = opts.execute;
|
|
381
|
+
this.mastra = opts.mastra;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
// src/utils.ts
|
|
357
386
|
var delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
387
|
+
function resolveSerializedZodOutput(schema) {
|
|
388
|
+
return Function("z", `"use strict";return (${schema});`)(zod.z);
|
|
389
|
+
}
|
|
390
|
+
function isVercelTool(tool) {
|
|
391
|
+
return !(tool instanceof Tool);
|
|
392
|
+
}
|
|
393
|
+
function createLogMessageOptions({
|
|
394
|
+
agentName,
|
|
395
|
+
toolName,
|
|
396
|
+
tool,
|
|
397
|
+
type
|
|
398
|
+
}) {
|
|
399
|
+
if (!agentName) {
|
|
400
|
+
return {
|
|
401
|
+
start: `Executing tool ${toolName}`,
|
|
402
|
+
error: `Failed tool execution`
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
const prefix = `[Agent:${agentName}]`;
|
|
406
|
+
const vercelPrefix = isVercelTool(tool) ? "Vercel " : "";
|
|
407
|
+
const toolType = type === "toolset" ? "toolset" : "tool";
|
|
408
|
+
return {
|
|
409
|
+
start: `${prefix} - Executing ${vercelPrefix}${toolType} ${toolName}`,
|
|
410
|
+
error: `${prefix} - Failed ${vercelPrefix}${toolType} execution`
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
function createExecute(tool, options, logType) {
|
|
414
|
+
const {
|
|
415
|
+
logger,
|
|
416
|
+
...rest
|
|
417
|
+
} = options;
|
|
418
|
+
const {
|
|
419
|
+
start,
|
|
420
|
+
error
|
|
421
|
+
} = createLogMessageOptions({
|
|
422
|
+
agentName: options.agentName,
|
|
423
|
+
toolName: options.name,
|
|
424
|
+
tool,
|
|
425
|
+
type: logType
|
|
426
|
+
});
|
|
427
|
+
const execFunction = async (args, execOptions) => {
|
|
428
|
+
if (isVercelTool(tool)) {
|
|
429
|
+
return tool?.execute?.(args, execOptions) ?? void 0;
|
|
430
|
+
}
|
|
431
|
+
return tool?.execute?.({
|
|
432
|
+
context: args,
|
|
433
|
+
threadId: options.threadId,
|
|
434
|
+
resourceId: options.resourceId,
|
|
435
|
+
mastra: options.mastra,
|
|
436
|
+
memory: options.memory,
|
|
437
|
+
runId: options.runId
|
|
438
|
+
}, execOptions) ?? void 0;
|
|
439
|
+
};
|
|
440
|
+
return async (args, execOptions) => {
|
|
441
|
+
try {
|
|
442
|
+
logger.debug(start, {
|
|
443
|
+
...rest,
|
|
444
|
+
args
|
|
445
|
+
});
|
|
446
|
+
return await execFunction(args, execOptions);
|
|
447
|
+
} catch (err) {
|
|
448
|
+
logger.error(error, {
|
|
449
|
+
...rest,
|
|
450
|
+
error: err,
|
|
451
|
+
args
|
|
452
|
+
});
|
|
453
|
+
throw err;
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
function isZodType(value) {
|
|
458
|
+
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
459
|
+
}
|
|
460
|
+
function createDeterministicId(input) {
|
|
461
|
+
return crypto$1.createHash("sha256").update(input).digest("hex").slice(0, 8);
|
|
462
|
+
}
|
|
463
|
+
function setVercelToolProperties(tool) {
|
|
464
|
+
const inputSchema = convertVercelToolParameters(tool);
|
|
465
|
+
const toolId = !("id" in tool) ? tool.description ? `tool-${createDeterministicId(tool.description)}` : `tool-${Math.random().toString(36).substring(2, 9)}` : tool.id;
|
|
466
|
+
return {
|
|
467
|
+
...tool,
|
|
468
|
+
id: toolId,
|
|
469
|
+
inputSchema
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
function ensureToolProperties(tools) {
|
|
473
|
+
const toolsWithProperties = Object.keys(tools).reduce((acc, key) => {
|
|
474
|
+
const tool = tools?.[key];
|
|
475
|
+
if (tool) {
|
|
476
|
+
if (isVercelTool(tool)) {
|
|
477
|
+
acc[key] = setVercelToolProperties(tool);
|
|
478
|
+
} else {
|
|
479
|
+
acc[key] = tool;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return acc;
|
|
483
|
+
}, {});
|
|
484
|
+
return toolsWithProperties;
|
|
485
|
+
}
|
|
486
|
+
function convertVercelToolParameters(tool) {
|
|
487
|
+
const schema = tool.parameters ?? zod.z.object({});
|
|
488
|
+
return isZodType(schema) ? schema : resolveSerializedZodOutput(jsonSchemaToZod__default.default(schema));
|
|
489
|
+
}
|
|
490
|
+
function makeCoreTool(tool, options, logType) {
|
|
491
|
+
const getParameters = () => {
|
|
492
|
+
if (isVercelTool(tool)) {
|
|
493
|
+
return convertVercelToolParameters(tool);
|
|
494
|
+
}
|
|
495
|
+
return tool.inputSchema ?? zod.z.object({});
|
|
496
|
+
};
|
|
497
|
+
return {
|
|
498
|
+
description: tool.description,
|
|
499
|
+
parameters: getParameters(),
|
|
500
|
+
execute: tool.execute ? createExecute(tool, {
|
|
501
|
+
...options,
|
|
502
|
+
description: tool.description
|
|
503
|
+
}, logType) : void 0
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
function createMastraProxy({
|
|
507
|
+
mastra,
|
|
508
|
+
logger
|
|
509
|
+
}) {
|
|
510
|
+
return new Proxy(mastra, {
|
|
511
|
+
get(target, prop) {
|
|
512
|
+
const hasProp = Reflect.has(target, prop);
|
|
513
|
+
if (hasProp) {
|
|
514
|
+
const value = Reflect.get(target, prop);
|
|
515
|
+
const isFunction = typeof value === "function";
|
|
516
|
+
if (isFunction) {
|
|
517
|
+
return value.bind(target);
|
|
518
|
+
}
|
|
519
|
+
return value;
|
|
520
|
+
}
|
|
521
|
+
if (prop === "logger") {
|
|
522
|
+
logger.warn(`Please use 'getLogger' instead, logger is deprecated`);
|
|
523
|
+
return Reflect.apply(target.getLogger, target, []);
|
|
524
|
+
}
|
|
525
|
+
if (prop === "telemetry") {
|
|
526
|
+
logger.warn(`Please use 'getTelemetry' instead, telemetry is deprecated`);
|
|
527
|
+
return Reflect.apply(target.getTelemetry, target, []);
|
|
528
|
+
}
|
|
529
|
+
if (prop === "storage") {
|
|
530
|
+
logger.warn(`Please use 'getStorage' instead, storage is deprecated`);
|
|
531
|
+
return Reflect.get(target, "storage");
|
|
532
|
+
}
|
|
533
|
+
if (prop === "agents") {
|
|
534
|
+
logger.warn(`Please use 'getAgents' instead, agents is deprecated`);
|
|
535
|
+
return Reflect.apply(target.getAgents, target, []);
|
|
536
|
+
}
|
|
537
|
+
if (prop === "tts") {
|
|
538
|
+
logger.warn(`Please use 'getTTS' instead, tts is deprecated`);
|
|
539
|
+
return Reflect.apply(target.getTTS, target, []);
|
|
540
|
+
}
|
|
541
|
+
if (prop === "vectors") {
|
|
542
|
+
logger.warn(`Please use 'getVectors' instead, vectors is deprecated`);
|
|
543
|
+
return Reflect.apply(target.getVectors, target, []);
|
|
544
|
+
}
|
|
545
|
+
if (prop === "memory") {
|
|
546
|
+
logger.warn(`Please use 'getMemory' instead, memory is deprecated`);
|
|
547
|
+
return Reflect.get(target, "memory");
|
|
548
|
+
}
|
|
549
|
+
return Reflect.get(target, prop);
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
358
553
|
|
|
359
554
|
// src/llm/model/model.ts
|
|
360
555
|
var MastraLLM = class extends MastraLLMBase {
|
|
@@ -406,36 +601,16 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
406
601
|
const k = value[0];
|
|
407
602
|
const tool = value[1];
|
|
408
603
|
if (tool) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
});
|
|
418
|
-
return tool?.execute?.({
|
|
419
|
-
context: props,
|
|
420
|
-
threadId,
|
|
421
|
-
resourceId,
|
|
422
|
-
mastra: this.#mastra,
|
|
423
|
-
memory,
|
|
424
|
-
runId
|
|
425
|
-
}, options) ?? void 0;
|
|
426
|
-
} catch (error) {
|
|
427
|
-
this.logger.error("Error executing tool", {
|
|
428
|
-
tool: k,
|
|
429
|
-
props,
|
|
430
|
-
error,
|
|
431
|
-
runId,
|
|
432
|
-
threadId,
|
|
433
|
-
resourceId
|
|
434
|
-
});
|
|
435
|
-
throw error;
|
|
436
|
-
}
|
|
437
|
-
} : void 0
|
|
604
|
+
const options = {
|
|
605
|
+
name: k,
|
|
606
|
+
runId,
|
|
607
|
+
threadId,
|
|
608
|
+
resourceId,
|
|
609
|
+
logger: this.logger,
|
|
610
|
+
memory,
|
|
611
|
+
mastra: this.#mastra
|
|
438
612
|
};
|
|
613
|
+
memo[k] = makeCoreTool(tool, options);
|
|
439
614
|
}
|
|
440
615
|
return memo;
|
|
441
616
|
}, {});
|
|
@@ -1021,10 +1196,13 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1021
1196
|
this.metrics = {};
|
|
1022
1197
|
this.evals = {};
|
|
1023
1198
|
if (config.tools) {
|
|
1024
|
-
this.tools = config.tools;
|
|
1199
|
+
this.tools = ensureToolProperties(config.tools);
|
|
1025
1200
|
}
|
|
1026
1201
|
if (config.mastra) {
|
|
1027
|
-
this
|
|
1202
|
+
this.__registerPrimitives({
|
|
1203
|
+
telemetry: config.mastra.getTelemetry(),
|
|
1204
|
+
logger: config.mastra.getLogger()
|
|
1205
|
+
});
|
|
1028
1206
|
}
|
|
1029
1207
|
if (config.metrics) {
|
|
1030
1208
|
this.logger.warn("The metrics property is deprecated. Please use evals instead to add evaluation metrics.");
|
|
@@ -1062,12 +1240,14 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1062
1240
|
this.__setLogger(p.logger);
|
|
1063
1241
|
}
|
|
1064
1242
|
this.llm.__registerPrimitives(p);
|
|
1065
|
-
this.#mastra = p;
|
|
1066
1243
|
this.logger.debug(`[Agents:${this.name}] initialized.`, {
|
|
1067
1244
|
model: this.model,
|
|
1068
1245
|
name: this.name
|
|
1069
1246
|
});
|
|
1070
1247
|
}
|
|
1248
|
+
__registerMastra(mastra) {
|
|
1249
|
+
this.#mastra = mastra;
|
|
1250
|
+
}
|
|
1071
1251
|
/**
|
|
1072
1252
|
* Set the concrete tools for the agent
|
|
1073
1253
|
* @param tools
|
|
@@ -1083,8 +1263,8 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1083
1263
|
message
|
|
1084
1264
|
}) {
|
|
1085
1265
|
const {
|
|
1086
|
-
|
|
1087
|
-
} = await this.llm.
|
|
1266
|
+
text
|
|
1267
|
+
} = await this.llm.__text({
|
|
1088
1268
|
messages: [{
|
|
1089
1269
|
role: "system",
|
|
1090
1270
|
content: `
|
|
@@ -1092,23 +1272,22 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1092
1272
|
- you will generate a short title based on the first message a user begins a conversation with
|
|
1093
1273
|
- ensure it is not more than 80 characters long
|
|
1094
1274
|
- the title should be a summary of the user's message
|
|
1095
|
-
- do not use quotes or colons
|
|
1275
|
+
- do not use quotes or colons
|
|
1276
|
+
- the entire text you return will be used as the title`
|
|
1096
1277
|
}, {
|
|
1097
1278
|
role: "user",
|
|
1098
1279
|
content: JSON.stringify(message)
|
|
1099
|
-
}]
|
|
1100
|
-
structuredOutput: zod.z.object({
|
|
1101
|
-
title: zod.z.string()
|
|
1102
|
-
})
|
|
1280
|
+
}]
|
|
1103
1281
|
});
|
|
1104
|
-
|
|
1282
|
+
const cleanedText = text.replace(/<think>[\s\S]*?<\/think>/g, "").trim();
|
|
1283
|
+
return cleanedText;
|
|
1105
1284
|
}
|
|
1106
1285
|
getMostRecentUserMessage(messages) {
|
|
1107
1286
|
const userMessages = messages.filter(message => message.role === "user");
|
|
1108
1287
|
return userMessages.at(-1);
|
|
1109
1288
|
}
|
|
1110
1289
|
async genTitle(userMessage) {
|
|
1111
|
-
let title =
|
|
1290
|
+
let title = `New Thread ${(/* @__PURE__ */new Date()).toISOString()}`;
|
|
1112
1291
|
try {
|
|
1113
1292
|
if (userMessage) {
|
|
1114
1293
|
title = await this.generateTitleFromUserMessage({
|
|
@@ -1130,17 +1309,18 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1130
1309
|
const userMessage = this.getMostRecentUserMessage(userMessages);
|
|
1131
1310
|
const memory = this.getMemory();
|
|
1132
1311
|
if (memory) {
|
|
1312
|
+
const config = memory.getMergedThreadConfig(memoryConfig);
|
|
1133
1313
|
let thread;
|
|
1134
1314
|
if (!threadId) {
|
|
1135
1315
|
this.logger.debug(`No threadId, creating new thread for agent ${this.name}`, {
|
|
1136
1316
|
runId: runId || this.name
|
|
1137
1317
|
});
|
|
1138
|
-
const title = await this.genTitle(userMessage);
|
|
1318
|
+
const title = config?.threads?.generateTitle ? await this.genTitle(userMessage) : void 0;
|
|
1139
1319
|
thread = await memory.createThread({
|
|
1140
1320
|
threadId,
|
|
1141
1321
|
resourceId,
|
|
1142
|
-
|
|
1143
|
-
|
|
1322
|
+
memoryConfig,
|
|
1323
|
+
title
|
|
1144
1324
|
});
|
|
1145
1325
|
} else {
|
|
1146
1326
|
thread = await memory.getThreadById({
|
|
@@ -1150,7 +1330,7 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1150
1330
|
this.logger.debug(`Thread with id ${threadId} not found, creating new thread for agent ${this.name}`, {
|
|
1151
1331
|
runId: runId || this.name
|
|
1152
1332
|
});
|
|
1153
|
-
const title = await this.genTitle(userMessage);
|
|
1333
|
+
const title = config?.threads?.generateTitle ? await this.genTitle(userMessage) : void 0;
|
|
1154
1334
|
thread = await memory.createThread({
|
|
1155
1335
|
threadId,
|
|
1156
1336
|
resourceId,
|
|
@@ -1174,6 +1354,7 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1174
1354
|
});
|
|
1175
1355
|
const memoryMessages = threadId && memory ? (await memory.rememberMessages({
|
|
1176
1356
|
threadId,
|
|
1357
|
+
resourceId,
|
|
1177
1358
|
config: memoryConfig,
|
|
1178
1359
|
vectorMessageSearch: messages.slice(-1).map(m => {
|
|
1179
1360
|
if (typeof m === `string`) {
|
|
@@ -1293,6 +1474,7 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1293
1474
|
let toolResultIds = [];
|
|
1294
1475
|
let toolCallIds = [];
|
|
1295
1476
|
for (const message of messages) {
|
|
1477
|
+
if (!Array.isArray(message.content)) continue;
|
|
1296
1478
|
if (message.role === "tool") {
|
|
1297
1479
|
for (const content of message.content) {
|
|
1298
1480
|
if (content.type === "tool-result") {
|
|
@@ -1311,7 +1493,9 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1311
1493
|
}
|
|
1312
1494
|
const messagesBySanitizedContent = messages.map(message => {
|
|
1313
1495
|
if (message.role !== "assistant" && message.role !== `tool` && message.role !== `user`) return message;
|
|
1314
|
-
if (typeof message.content === "string"
|
|
1496
|
+
if (!message.content || typeof message.content === "string" || typeof message.content === "number") {
|
|
1497
|
+
return message;
|
|
1498
|
+
}
|
|
1315
1499
|
const sanitizedContent = message.content.filter(content => {
|
|
1316
1500
|
if (content.type === `tool-call`) {
|
|
1317
1501
|
return toolResultIds.includes(content.toolCallId);
|
|
@@ -1356,43 +1540,30 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1356
1540
|
resourceId
|
|
1357
1541
|
});
|
|
1358
1542
|
const memory = this.getMemory();
|
|
1359
|
-
const memoryTools = memory?.getTools();
|
|
1543
|
+
const memoryTools = memory?.getTools?.();
|
|
1544
|
+
let mastraProxy = void 0;
|
|
1545
|
+
const logger = this.logger;
|
|
1546
|
+
if (this.#mastra) {
|
|
1547
|
+
mastraProxy = createMastraProxy({
|
|
1548
|
+
mastra: this.#mastra,
|
|
1549
|
+
logger
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1360
1552
|
const converted = Object.entries(this.tools || {}).reduce((memo, value) => {
|
|
1361
1553
|
const k = value[0];
|
|
1362
1554
|
const tool = this.tools[k];
|
|
1363
1555
|
if (tool) {
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
runId,
|
|
1374
|
-
threadId,
|
|
1375
|
-
resourceId
|
|
1376
|
-
});
|
|
1377
|
-
return tool?.execute?.({
|
|
1378
|
-
context: args,
|
|
1379
|
-
mastra: this.#mastra,
|
|
1380
|
-
memory,
|
|
1381
|
-
runId,
|
|
1382
|
-
threadId,
|
|
1383
|
-
resourceId
|
|
1384
|
-
}, options) ?? void 0;
|
|
1385
|
-
} catch (err) {
|
|
1386
|
-
this.logger.error(`[Agent:${this.name}] - Failed execution`, {
|
|
1387
|
-
error: err,
|
|
1388
|
-
runId,
|
|
1389
|
-
threadId,
|
|
1390
|
-
resourceId
|
|
1391
|
-
});
|
|
1392
|
-
throw err;
|
|
1393
|
-
}
|
|
1394
|
-
} : void 0
|
|
1556
|
+
const options = {
|
|
1557
|
+
name: k,
|
|
1558
|
+
runId,
|
|
1559
|
+
threadId,
|
|
1560
|
+
resourceId,
|
|
1561
|
+
logger: this.logger,
|
|
1562
|
+
mastra: mastraProxy,
|
|
1563
|
+
memory,
|
|
1564
|
+
agentName: this.name
|
|
1395
1565
|
};
|
|
1566
|
+
memo[k] = makeCoreTool(tool, options);
|
|
1396
1567
|
}
|
|
1397
1568
|
return memo;
|
|
1398
1569
|
}, {});
|
|
@@ -1412,7 +1583,7 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1412
1583
|
});
|
|
1413
1584
|
return tool?.execute?.({
|
|
1414
1585
|
context: args,
|
|
1415
|
-
mastra:
|
|
1586
|
+
mastra: mastraProxy,
|
|
1416
1587
|
memory,
|
|
1417
1588
|
runId,
|
|
1418
1589
|
threadId,
|
|
@@ -1443,36 +1614,15 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1443
1614
|
toolsFromToolsets.forEach(toolset => {
|
|
1444
1615
|
Object.entries(toolset).forEach(([toolName, tool]) => {
|
|
1445
1616
|
const toolObj = tool;
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
description: toolObj.description,
|
|
1454
|
-
args,
|
|
1455
|
-
runId,
|
|
1456
|
-
threadId,
|
|
1457
|
-
resourceId
|
|
1458
|
-
});
|
|
1459
|
-
return toolObj?.execute?.({
|
|
1460
|
-
context: args,
|
|
1461
|
-
runId,
|
|
1462
|
-
threadId,
|
|
1463
|
-
resourceId
|
|
1464
|
-
}, options) ?? void 0;
|
|
1465
|
-
} catch (error) {
|
|
1466
|
-
this.logger.error(`[Agent:${this.name}] - Failed toolset execution`, {
|
|
1467
|
-
error,
|
|
1468
|
-
runId,
|
|
1469
|
-
threadId,
|
|
1470
|
-
resourceId
|
|
1471
|
-
});
|
|
1472
|
-
throw error;
|
|
1473
|
-
}
|
|
1474
|
-
} : void 0
|
|
1617
|
+
const options = {
|
|
1618
|
+
name: toolName,
|
|
1619
|
+
runId,
|
|
1620
|
+
threadId,
|
|
1621
|
+
resourceId,
|
|
1622
|
+
logger: this.logger,
|
|
1623
|
+
agentName: this.name
|
|
1475
1624
|
};
|
|
1625
|
+
toolsFromToolsetsConverted[toolName] = makeCoreTool(toolObj, options, "toolset");
|
|
1476
1626
|
});
|
|
1477
1627
|
});
|
|
1478
1628
|
}
|
package/dist/agent/index.d.cts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
export { Message as AiMessageType } from 'ai';
|
|
2
2
|
import 'json-schema';
|
|
3
3
|
import 'zod';
|
|
4
|
-
export { A as Agent,
|
|
5
|
-
import '../base-
|
|
6
|
-
import '../types-
|
|
4
|
+
export { A as Agent, l as AgentConfig, aw as AgentGenerateOptions, ax as AgentStreamOptions, a as ToolsInput, av as ToolsetsInput } from '../base-DLJ5WisC.cjs';
|
|
5
|
+
import '../base-DboIg_Cd.cjs';
|
|
6
|
+
import '../types-CwTG2XyQ.cjs';
|
|
7
7
|
import '../voice/index.cjs';
|
|
8
8
|
import 'sift';
|
|
9
|
-
import '../vector/index.cjs';
|
|
10
|
-
import '../vector/filter/index.cjs';
|
|
11
|
-
import '@opentelemetry/api';
|
|
12
9
|
import '../index-mKY1XrpK.cjs';
|
|
13
10
|
import 'stream';
|
|
14
11
|
import 'pino';
|
|
12
|
+
import '../deployer/index.cjs';
|
|
13
|
+
import '../bundler/index.cjs';
|
|
14
|
+
import '@opentelemetry/api';
|
|
15
15
|
import '@opentelemetry/sdk-trace-base';
|
|
16
|
+
import '../vector/index.cjs';
|
|
17
|
+
import '../vector/filter/index.cjs';
|
|
16
18
|
import '../tts/index.cjs';
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
export { Message as AiMessageType } from 'ai';
|
|
2
2
|
import 'json-schema';
|
|
3
3
|
import 'zod';
|
|
4
|
-
export { A as Agent,
|
|
5
|
-
import '../base-
|
|
6
|
-
import '../types-
|
|
4
|
+
export { A as Agent, l as AgentConfig, aw as AgentGenerateOptions, ax as AgentStreamOptions, a as ToolsInput, av as ToolsetsInput } from '../base-mFfX31Ho.js';
|
|
5
|
+
import '../base-BZViaFTt.js';
|
|
6
|
+
import '../types-CwTG2XyQ.js';
|
|
7
7
|
import '../voice/index.js';
|
|
8
8
|
import 'sift';
|
|
9
|
-
import '../vector/index.js';
|
|
10
|
-
import '../vector/filter/index.js';
|
|
11
|
-
import '@opentelemetry/api';
|
|
12
9
|
import '../index-mKY1XrpK.js';
|
|
13
10
|
import 'stream';
|
|
14
11
|
import 'pino';
|
|
12
|
+
import '../deployer/index.js';
|
|
13
|
+
import '../bundler/index.js';
|
|
14
|
+
import '@opentelemetry/api';
|
|
15
15
|
import '@opentelemetry/sdk-trace-base';
|
|
16
|
+
import '../vector/index.js';
|
|
17
|
+
import '../vector/filter/index.js';
|
|
16
18
|
import '../tts/index.js';
|
package/dist/agent/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Agent } from '../chunk-
|
|
1
|
+
export { Agent } from '../chunk-TWAIC2XA.js';
|
|
@@ -38,6 +38,8 @@ type OtelConfig = {
|
|
|
38
38
|
export?: {
|
|
39
39
|
/** Export to an OTLP (OpenTelemetry Protocol) endpoint */
|
|
40
40
|
type: 'otlp';
|
|
41
|
+
/** Whether to use gRPC or HTTP for OTLP */
|
|
42
|
+
protocol?: 'grpc' | 'http';
|
|
41
43
|
/** OTLP endpoint URL */
|
|
42
44
|
endpoint?: string;
|
|
43
45
|
/** Optional headers for OTLP requests */
|