@mastra/core 0.4.4 → 0.5.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/index.cjs +64 -6
- package/dist/agent/index.d.cts +1 -1
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/{base-DqRXkxCw.d.ts → base-42kpYoR1.d.ts} +14 -6
- package/dist/{base-CbCmDLUb.d.cts → base-C_bOLlEO.d.cts} +14 -6
- package/dist/{chunk-WIBGG4X6.js → chunk-3GC7P4J6.js} +1 -1
- package/dist/{chunk-5XPCMNGW.js → chunk-KQN7VU7J.js} +2 -1
- package/dist/{chunk-KNVTCZW7.js → chunk-MGBSRQQW.js} +6 -3
- package/dist/{chunk-E7K35ROR.js → chunk-NWPCPTB7.js} +65 -7
- package/dist/{chunk-L7SWFW3L.js → chunk-P47D7HYO.js} +2 -2
- package/dist/{chunk-5NRHVENG.js → chunk-PBED2445.js} +12 -4
- package/dist/{chunk-JXEH6PBQ.js → chunk-SH6KVX4B.js} +1 -1
- package/dist/{chunk-NGD2HQYW.js → chunk-UFMLHP4G.js} +1 -1
- package/dist/eval/index.d.cts +1 -1
- package/dist/eval/index.d.ts +1 -1
- package/dist/index.cjs +83 -13
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -6
- package/dist/integration/index.d.cts +2 -2
- package/dist/integration/index.d.ts +2 -2
- package/dist/llm/index.d.cts +1 -1
- package/dist/llm/index.d.ts +1 -1
- package/dist/mastra/index.cjs +7 -3
- package/dist/mastra/index.d.cts +2 -2
- package/dist/mastra/index.d.ts +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +18 -6
- package/dist/memory/index.d.cts +1 -1
- package/dist/memory/index.d.ts +1 -1
- package/dist/memory/index.js +1 -1
- package/dist/relevance/index.cjs +64 -6
- package/dist/relevance/index.js +1 -1
- package/dist/storage/index.cjs +2 -1
- package/dist/storage/index.d.cts +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/index.js +1 -1
- package/dist/storage/libsql/index.cjs +7 -3
- package/dist/storage/libsql/index.d.cts +1 -1
- package/dist/storage/libsql/index.d.ts +1 -1
- package/dist/storage/libsql/index.js +1 -1
- package/dist/telemetry/index.d.cts +1 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/tools/index.d.cts +2 -2
- package/dist/tools/index.d.ts +2 -2
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/dist/vector/libsql/index.cjs +2 -2
- package/dist/vector/libsql/index.js +1 -1
- package/dist/{workflow-fGgxPZk4.d.ts → workflow-CFuzV18A.d.ts} +1 -1
- package/dist/{workflow-DlRFMI4Q.d.cts → workflow-CosscczK.d.cts} +1 -1
- package/dist/workflows/index.d.cts +3 -3
- package/dist/workflows/index.d.ts +3 -3
- package/package.json +1 -1
package/dist/agent/index.cjs
CHANGED
|
@@ -398,7 +398,8 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
398
398
|
tools,
|
|
399
399
|
runId,
|
|
400
400
|
threadId,
|
|
401
|
-
resourceId
|
|
401
|
+
resourceId,
|
|
402
|
+
memory
|
|
402
403
|
} = {}) {
|
|
403
404
|
this.logger.debug("Starting tool conversion for LLM");
|
|
404
405
|
const converted = Object.entries(tools || {}).reduce((memo, value) => {
|
|
@@ -419,6 +420,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
419
420
|
threadId,
|
|
420
421
|
resourceId,
|
|
421
422
|
mastra: this.#mastra,
|
|
423
|
+
memory,
|
|
422
424
|
runId
|
|
423
425
|
}, options) ?? void 0;
|
|
424
426
|
} catch (error) {
|
|
@@ -453,6 +455,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
453
455
|
telemetry,
|
|
454
456
|
threadId,
|
|
455
457
|
resourceId,
|
|
458
|
+
memory,
|
|
456
459
|
...rest
|
|
457
460
|
}) {
|
|
458
461
|
const model = this.#model;
|
|
@@ -468,7 +471,8 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
468
471
|
tools,
|
|
469
472
|
runId,
|
|
470
473
|
threadId,
|
|
471
|
-
resourceId
|
|
474
|
+
resourceId,
|
|
475
|
+
memory
|
|
472
476
|
});
|
|
473
477
|
const argsForExecute = {
|
|
474
478
|
model,
|
|
@@ -536,6 +540,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
536
540
|
telemetry,
|
|
537
541
|
threadId,
|
|
538
542
|
resourceId,
|
|
543
|
+
memory,
|
|
539
544
|
...rest
|
|
540
545
|
}) {
|
|
541
546
|
const model = this.#model;
|
|
@@ -546,7 +551,8 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
546
551
|
tools,
|
|
547
552
|
runId,
|
|
548
553
|
threadId,
|
|
549
|
-
resourceId
|
|
554
|
+
resourceId,
|
|
555
|
+
memory
|
|
550
556
|
});
|
|
551
557
|
const argsForExecute = {
|
|
552
558
|
model,
|
|
@@ -611,6 +617,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
611
617
|
telemetry,
|
|
612
618
|
threadId,
|
|
613
619
|
resourceId,
|
|
620
|
+
memory,
|
|
614
621
|
...rest
|
|
615
622
|
}) {
|
|
616
623
|
const model = this.#model;
|
|
@@ -626,7 +633,8 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
626
633
|
tools,
|
|
627
634
|
runId,
|
|
628
635
|
threadId,
|
|
629
|
-
resourceId
|
|
636
|
+
resourceId,
|
|
637
|
+
memory
|
|
630
638
|
});
|
|
631
639
|
const argsForExecute = {
|
|
632
640
|
model,
|
|
@@ -708,6 +716,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
708
716
|
telemetry,
|
|
709
717
|
threadId,
|
|
710
718
|
resourceId,
|
|
719
|
+
memory,
|
|
711
720
|
...rest
|
|
712
721
|
}) {
|
|
713
722
|
const model = this.#model;
|
|
@@ -721,7 +730,8 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
721
730
|
tools,
|
|
722
731
|
runId,
|
|
723
732
|
threadId,
|
|
724
|
-
resourceId
|
|
733
|
+
resourceId,
|
|
734
|
+
memory
|
|
725
735
|
});
|
|
726
736
|
const argsForExecute = {
|
|
727
737
|
model,
|
|
@@ -796,6 +806,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
796
806
|
output,
|
|
797
807
|
temperature,
|
|
798
808
|
telemetry,
|
|
809
|
+
memory,
|
|
799
810
|
...rest
|
|
800
811
|
} = {}) {
|
|
801
812
|
const msgs = this.convertToMessages(messages);
|
|
@@ -808,6 +819,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
808
819
|
convertedTools,
|
|
809
820
|
runId,
|
|
810
821
|
temperature,
|
|
822
|
+
memory,
|
|
811
823
|
...rest
|
|
812
824
|
});
|
|
813
825
|
}
|
|
@@ -820,6 +832,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
820
832
|
convertedTools,
|
|
821
833
|
runId,
|
|
822
834
|
telemetry,
|
|
835
|
+
memory,
|
|
823
836
|
...rest
|
|
824
837
|
});
|
|
825
838
|
}
|
|
@@ -1342,6 +1355,8 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1342
1355
|
threadId,
|
|
1343
1356
|
resourceId
|
|
1344
1357
|
});
|
|
1358
|
+
const memory = this.getMemory();
|
|
1359
|
+
const memoryTools = memory?.getTools();
|
|
1345
1360
|
const converted = Object.entries(this.tools || {}).reduce((memo, value) => {
|
|
1346
1361
|
const k = value[0];
|
|
1347
1362
|
const tool = this.tools[k];
|
|
@@ -1362,6 +1377,7 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1362
1377
|
return tool?.execute?.({
|
|
1363
1378
|
context: args,
|
|
1364
1379
|
mastra: this.#mastra,
|
|
1380
|
+
memory,
|
|
1365
1381
|
runId,
|
|
1366
1382
|
threadId,
|
|
1367
1383
|
resourceId
|
|
@@ -1380,8 +1396,44 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1380
1396
|
}
|
|
1381
1397
|
return memo;
|
|
1382
1398
|
}, {});
|
|
1399
|
+
const convertedMemoryTools = memoryTools ? Object.entries(memoryTools).reduce((memo, [k, tool]) => {
|
|
1400
|
+
memo[k] = {
|
|
1401
|
+
description: tool.description,
|
|
1402
|
+
parameters: tool.parameters,
|
|
1403
|
+
execute: typeof tool?.execute === "function" ? async (args, options) => {
|
|
1404
|
+
try {
|
|
1405
|
+
this.logger.debug(`[Agent:${this.name}] - Executing memory tool ${k}`, {
|
|
1406
|
+
name: k,
|
|
1407
|
+
description: tool.description,
|
|
1408
|
+
args,
|
|
1409
|
+
runId,
|
|
1410
|
+
threadId,
|
|
1411
|
+
resourceId
|
|
1412
|
+
});
|
|
1413
|
+
return tool?.execute?.({
|
|
1414
|
+
context: args,
|
|
1415
|
+
mastra: this.#mastra,
|
|
1416
|
+
memory,
|
|
1417
|
+
runId,
|
|
1418
|
+
threadId,
|
|
1419
|
+
resourceId
|
|
1420
|
+
}, options) ?? void 0;
|
|
1421
|
+
} catch (err) {
|
|
1422
|
+
this.logger.error(`[Agent:${this.name}] - Failed memory tool execution`, {
|
|
1423
|
+
error: err,
|
|
1424
|
+
runId,
|
|
1425
|
+
threadId,
|
|
1426
|
+
resourceId
|
|
1427
|
+
});
|
|
1428
|
+
throw err;
|
|
1429
|
+
}
|
|
1430
|
+
} : void 0
|
|
1431
|
+
};
|
|
1432
|
+
return memo;
|
|
1433
|
+
}, {}) : {};
|
|
1383
1434
|
const toolsFromToolsetsConverted = {
|
|
1384
|
-
...converted
|
|
1435
|
+
...converted,
|
|
1436
|
+
...convertedMemoryTools
|
|
1385
1437
|
};
|
|
1386
1438
|
const toolsFromToolsets = Object.values(toolsets || {});
|
|
1387
1439
|
if (toolsFromToolsets.length > 0) {
|
|
@@ -1651,6 +1703,7 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1651
1703
|
experimental_output,
|
|
1652
1704
|
threadId,
|
|
1653
1705
|
resourceId,
|
|
1706
|
+
memory: this.getMemory(),
|
|
1654
1707
|
...rest
|
|
1655
1708
|
});
|
|
1656
1709
|
const outputText2 = result2.text;
|
|
@@ -1678,6 +1731,7 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1678
1731
|
telemetry,
|
|
1679
1732
|
threadId,
|
|
1680
1733
|
resourceId,
|
|
1734
|
+
memory: this.getMemory(),
|
|
1681
1735
|
...rest
|
|
1682
1736
|
});
|
|
1683
1737
|
const outputText2 = result2.text;
|
|
@@ -1701,6 +1755,7 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1701
1755
|
temperature,
|
|
1702
1756
|
toolChoice,
|
|
1703
1757
|
telemetry,
|
|
1758
|
+
memory: this.getMemory(),
|
|
1704
1759
|
...rest
|
|
1705
1760
|
});
|
|
1706
1761
|
const outputText = JSON.stringify(result.object);
|
|
@@ -1798,6 +1853,7 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1798
1853
|
runId: runIdToUse,
|
|
1799
1854
|
toolChoice,
|
|
1800
1855
|
experimental_output,
|
|
1856
|
+
memory: this.getMemory(),
|
|
1801
1857
|
...rest
|
|
1802
1858
|
});
|
|
1803
1859
|
const newStreamResult = streamResult;
|
|
@@ -1836,6 +1892,7 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1836
1892
|
runId: runIdToUse,
|
|
1837
1893
|
toolChoice,
|
|
1838
1894
|
telemetry,
|
|
1895
|
+
memory: this.getMemory(),
|
|
1839
1896
|
...rest
|
|
1840
1897
|
});
|
|
1841
1898
|
}
|
|
@@ -1871,6 +1928,7 @@ exports.Agent = class Agent extends (_a = MastraBase) {
|
|
|
1871
1928
|
runId: runIdToUse,
|
|
1872
1929
|
toolChoice,
|
|
1873
1930
|
telemetry,
|
|
1931
|
+
memory: this.getMemory(),
|
|
1874
1932
|
...rest
|
|
1875
1933
|
});
|
|
1876
1934
|
}
|
package/dist/agent/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Message as AiMessageType } from 'ai';
|
|
2
2
|
import 'json-schema';
|
|
3
3
|
import 'zod';
|
|
4
|
-
export { A as Agent, n as AgentConfig, ao as AgentGenerateOptions, ap as AgentStreamOptions, an as ToolsInput, am as ToolsetsInput } from '../base-
|
|
4
|
+
export { A as Agent, n as AgentConfig, ao as AgentGenerateOptions, ap as AgentStreamOptions, an as ToolsInput, am as ToolsetsInput } from '../base-C_bOLlEO.cjs';
|
|
5
5
|
import '../base-hs9NDAZ2.cjs';
|
|
6
6
|
import '../types-m9RryK9a.cjs';
|
|
7
7
|
import '../voice/index.cjs';
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Message as AiMessageType } from 'ai';
|
|
2
2
|
import 'json-schema';
|
|
3
3
|
import 'zod';
|
|
4
|
-
export { A as Agent, n as AgentConfig, ao as AgentGenerateOptions, ap as AgentStreamOptions, an as ToolsInput, am as ToolsetsInput } from '../base-
|
|
4
|
+
export { A as Agent, n as AgentConfig, ao as AgentGenerateOptions, ap as AgentStreamOptions, an as ToolsInput, am as ToolsetsInput } from '../base-42kpYoR1.js';
|
|
5
5
|
import '../base-D90KQ4XI.js';
|
|
6
6
|
import '../types-m9RryK9a.js';
|
|
7
7
|
import '../voice/index.js';
|
package/dist/agent/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Agent } from '../chunk-
|
|
1
|
+
export { Agent } from '../chunk-NWPCPTB7.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ai from 'ai';
|
|
2
|
-
import { EmbeddingModel, CoreMessage as CoreMessage$1, Message, UserContent, AssistantContent, ToolExecutionOptions, LanguageModelV1, TelemetrySettings, generateText, generateObject, streamText, GenerateTextResult, GenerateObjectResult, streamObject, StreamTextResult, StreamObjectResult, CoreSystemMessage as CoreSystemMessage$1, CoreAssistantMessage as CoreAssistantMessage$1, CoreUserMessage as CoreUserMessage$1, CoreToolMessage as CoreToolMessage$1, EmbedResult as EmbedResult$1, EmbedManyResult as EmbedManyResult$1, LanguageModel as LanguageModel$1, DeepPartial, ToolContent } from 'ai';
|
|
2
|
+
import { EmbeddingModel, CoreTool as CoreTool$1, CoreMessage as CoreMessage$1, Message, UserContent, AssistantContent, ToolExecutionOptions, LanguageModelV1, TelemetrySettings, generateText, generateObject, streamText, GenerateTextResult, GenerateObjectResult, streamObject, StreamTextResult, StreamObjectResult, CoreSystemMessage as CoreSystemMessage$1, CoreAssistantMessage as CoreAssistantMessage$1, CoreUserMessage as CoreUserMessage$1, CoreToolMessage as CoreToolMessage$1, EmbedResult as EmbedResult$1, EmbedManyResult as EmbedManyResult$1, LanguageModel as LanguageModel$1, DeepPartial, ToolContent } from 'ai';
|
|
3
3
|
import { M as MastraBase, T as Telemetry } from './base-D90KQ4XI.js';
|
|
4
4
|
import { Query } from 'sift';
|
|
5
5
|
import { z, ZodSchema } from 'zod';
|
|
@@ -35,6 +35,12 @@ declare abstract class MastraMemory extends MastraBase {
|
|
|
35
35
|
threadId: string;
|
|
36
36
|
memoryConfig?: MemoryConfig;
|
|
37
37
|
}): Promise<string | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Get tools that should be available to the agent.
|
|
40
|
+
* This will be called when converting tools for the agent.
|
|
41
|
+
* Implementations can override this to provide additional tools.
|
|
42
|
+
*/
|
|
43
|
+
getTools(config?: MemoryConfig): Record<string, CoreTool$1>;
|
|
38
44
|
protected createEmbeddingIndex(): Promise<{
|
|
39
45
|
indexName: string;
|
|
40
46
|
}>;
|
|
@@ -547,8 +553,8 @@ type StructuredOutput = {
|
|
|
547
553
|
items: StructuredOutputArrayItem;
|
|
548
554
|
};
|
|
549
555
|
};
|
|
550
|
-
type GenerateReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? GenerateTextResult<any,
|
|
551
|
-
type StreamReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? StreamTextResult<any,
|
|
556
|
+
type GenerateReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? GenerateTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown> : GenerateObjectResult<Z extends ZodSchema ? z.infer<Z> : unknown>;
|
|
557
|
+
type StreamReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? StreamTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown> : StreamObjectResult<any, Z extends ZodSchema ? z.infer<Z> : unknown, any>;
|
|
552
558
|
type OutputType = StructuredOutput | ZodSchema | JSONSchema7 | undefined;
|
|
553
559
|
type GenerateTextOptions = Parameters<typeof generateText>[0];
|
|
554
560
|
type StreamTextOptions = Parameters<typeof streamText>[0];
|
|
@@ -692,7 +698,7 @@ declare class Agent<TTools extends Record<string, ToolAction<any, any, any, any>
|
|
|
692
698
|
generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentGenerateOptions<Z> & {
|
|
693
699
|
output?: never;
|
|
694
700
|
experimental_output?: never;
|
|
695
|
-
}): Promise<GenerateTextResult<any,
|
|
701
|
+
}): Promise<GenerateTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown>>;
|
|
696
702
|
generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentGenerateOptions<Z> & ({
|
|
697
703
|
output: Z;
|
|
698
704
|
experimental_output?: never;
|
|
@@ -703,14 +709,14 @@ declare class Agent<TTools extends Record<string, ToolAction<any, any, any, any>
|
|
|
703
709
|
stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentStreamOptions<Z> & {
|
|
704
710
|
output?: never;
|
|
705
711
|
experimental_output?: never;
|
|
706
|
-
}): Promise<
|
|
712
|
+
}): Promise<StreamTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown>>;
|
|
707
713
|
stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentStreamOptions<Z> & ({
|
|
708
714
|
output: Z;
|
|
709
715
|
experimental_output?: never;
|
|
710
716
|
} | {
|
|
711
717
|
experimental_output: Z;
|
|
712
718
|
output?: never;
|
|
713
|
-
})): Promise<
|
|
719
|
+
})): Promise<StreamObjectResult<any, Z extends ZodSchema ? z.infer<Z> : unknown, any>>;
|
|
714
720
|
/**
|
|
715
721
|
* Convert text to speech using the configured voice provider
|
|
716
722
|
* @param input Text or text stream to convert to speech
|
|
@@ -825,6 +831,7 @@ type MemoryConfig = {
|
|
|
825
831
|
workingMemory?: {
|
|
826
832
|
enabled: boolean;
|
|
827
833
|
template?: string;
|
|
834
|
+
use?: 'text-stream' | 'tool-call';
|
|
828
835
|
};
|
|
829
836
|
};
|
|
830
837
|
type SharedMemoryConfig = {
|
|
@@ -846,6 +853,7 @@ declare abstract class MastraStorage extends MastraBase {
|
|
|
846
853
|
/** @deprecated import { TABLE_TRACES } from '@mastra/core/storage' instead */
|
|
847
854
|
static readonly TABLE_TRACES = "mastra_traces";
|
|
848
855
|
protected hasInitialized: null | Promise<boolean>;
|
|
856
|
+
protected shouldCacheInit: boolean;
|
|
849
857
|
constructor({ name }: {
|
|
850
858
|
name: string;
|
|
851
859
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ai from 'ai';
|
|
2
|
-
import { EmbeddingModel, CoreMessage as CoreMessage$1, Message, UserContent, AssistantContent, ToolExecutionOptions, LanguageModelV1, TelemetrySettings, generateText, generateObject, streamText, GenerateTextResult, GenerateObjectResult, streamObject, StreamTextResult, StreamObjectResult, CoreSystemMessage as CoreSystemMessage$1, CoreAssistantMessage as CoreAssistantMessage$1, CoreUserMessage as CoreUserMessage$1, CoreToolMessage as CoreToolMessage$1, EmbedResult as EmbedResult$1, EmbedManyResult as EmbedManyResult$1, LanguageModel as LanguageModel$1, DeepPartial, ToolContent } from 'ai';
|
|
2
|
+
import { EmbeddingModel, CoreTool as CoreTool$1, CoreMessage as CoreMessage$1, Message, UserContent, AssistantContent, ToolExecutionOptions, LanguageModelV1, TelemetrySettings, generateText, generateObject, streamText, GenerateTextResult, GenerateObjectResult, streamObject, StreamTextResult, StreamObjectResult, CoreSystemMessage as CoreSystemMessage$1, CoreAssistantMessage as CoreAssistantMessage$1, CoreUserMessage as CoreUserMessage$1, CoreToolMessage as CoreToolMessage$1, EmbedResult as EmbedResult$1, EmbedManyResult as EmbedManyResult$1, LanguageModel as LanguageModel$1, DeepPartial, ToolContent } from 'ai';
|
|
3
3
|
import { M as MastraBase, T as Telemetry } from './base-hs9NDAZ2.cjs';
|
|
4
4
|
import { Query } from 'sift';
|
|
5
5
|
import { z, ZodSchema } from 'zod';
|
|
@@ -35,6 +35,12 @@ declare abstract class MastraMemory extends MastraBase {
|
|
|
35
35
|
threadId: string;
|
|
36
36
|
memoryConfig?: MemoryConfig;
|
|
37
37
|
}): Promise<string | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Get tools that should be available to the agent.
|
|
40
|
+
* This will be called when converting tools for the agent.
|
|
41
|
+
* Implementations can override this to provide additional tools.
|
|
42
|
+
*/
|
|
43
|
+
getTools(config?: MemoryConfig): Record<string, CoreTool$1>;
|
|
38
44
|
protected createEmbeddingIndex(): Promise<{
|
|
39
45
|
indexName: string;
|
|
40
46
|
}>;
|
|
@@ -547,8 +553,8 @@ type StructuredOutput = {
|
|
|
547
553
|
items: StructuredOutputArrayItem;
|
|
548
554
|
};
|
|
549
555
|
};
|
|
550
|
-
type GenerateReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? GenerateTextResult<any,
|
|
551
|
-
type StreamReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? StreamTextResult<any,
|
|
556
|
+
type GenerateReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? GenerateTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown> : GenerateObjectResult<Z extends ZodSchema ? z.infer<Z> : unknown>;
|
|
557
|
+
type StreamReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? StreamTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown> : StreamObjectResult<any, Z extends ZodSchema ? z.infer<Z> : unknown, any>;
|
|
552
558
|
type OutputType = StructuredOutput | ZodSchema | JSONSchema7 | undefined;
|
|
553
559
|
type GenerateTextOptions = Parameters<typeof generateText>[0];
|
|
554
560
|
type StreamTextOptions = Parameters<typeof streamText>[0];
|
|
@@ -692,7 +698,7 @@ declare class Agent<TTools extends Record<string, ToolAction<any, any, any, any>
|
|
|
692
698
|
generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentGenerateOptions<Z> & {
|
|
693
699
|
output?: never;
|
|
694
700
|
experimental_output?: never;
|
|
695
|
-
}): Promise<GenerateTextResult<any,
|
|
701
|
+
}): Promise<GenerateTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown>>;
|
|
696
702
|
generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentGenerateOptions<Z> & ({
|
|
697
703
|
output: Z;
|
|
698
704
|
experimental_output?: never;
|
|
@@ -703,14 +709,14 @@ declare class Agent<TTools extends Record<string, ToolAction<any, any, any, any>
|
|
|
703
709
|
stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentStreamOptions<Z> & {
|
|
704
710
|
output?: never;
|
|
705
711
|
experimental_output?: never;
|
|
706
|
-
}): Promise<
|
|
712
|
+
}): Promise<StreamTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown>>;
|
|
707
713
|
stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentStreamOptions<Z> & ({
|
|
708
714
|
output: Z;
|
|
709
715
|
experimental_output?: never;
|
|
710
716
|
} | {
|
|
711
717
|
experimental_output: Z;
|
|
712
718
|
output?: never;
|
|
713
|
-
})): Promise<
|
|
719
|
+
})): Promise<StreamObjectResult<any, Z extends ZodSchema ? z.infer<Z> : unknown, any>>;
|
|
714
720
|
/**
|
|
715
721
|
* Convert text to speech using the configured voice provider
|
|
716
722
|
* @param input Text or text stream to convert to speech
|
|
@@ -825,6 +831,7 @@ type MemoryConfig = {
|
|
|
825
831
|
workingMemory?: {
|
|
826
832
|
enabled: boolean;
|
|
827
833
|
template?: string;
|
|
834
|
+
use?: 'text-stream' | 'tool-call';
|
|
828
835
|
};
|
|
829
836
|
};
|
|
830
837
|
type SharedMemoryConfig = {
|
|
@@ -846,6 +853,7 @@ declare abstract class MastraStorage extends MastraBase {
|
|
|
846
853
|
/** @deprecated import { TABLE_TRACES } from '@mastra/core/storage' instead */
|
|
847
854
|
static readonly TABLE_TRACES = "mastra_traces";
|
|
848
855
|
protected hasInitialized: null | Promise<boolean>;
|
|
856
|
+
protected shouldCacheInit: boolean;
|
|
849
857
|
constructor({ name }: {
|
|
850
858
|
name: string;
|
|
851
859
|
});
|
|
@@ -14,6 +14,7 @@ var MastraStorage = class extends MastraBase {
|
|
|
14
14
|
/** @deprecated import { TABLE_TRACES } from '@mastra/core/storage' instead */
|
|
15
15
|
static TABLE_TRACES = TABLE_TRACES;
|
|
16
16
|
hasInitialized = null;
|
|
17
|
+
shouldCacheInit = true;
|
|
17
18
|
constructor({ name }) {
|
|
18
19
|
super({
|
|
19
20
|
component: "STORAGE",
|
|
@@ -69,7 +70,7 @@ var MastraStorage = class extends MastraBase {
|
|
|
69
70
|
return this.getTraces({ scope, page, perPage, attributes });
|
|
70
71
|
}
|
|
71
72
|
async init() {
|
|
72
|
-
if (await this.hasInitialized) {
|
|
73
|
+
if (this.shouldCacheInit && await this.hasInitialized) {
|
|
73
74
|
return;
|
|
74
75
|
}
|
|
75
76
|
this.hasInitialized = Promise.all([
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MastraStorage } from './chunk-
|
|
1
|
+
import { MastraStorage } from './chunk-KQN7VU7J.js';
|
|
2
2
|
import { TABLE_WORKFLOW_SNAPSHOT, TABLE_THREADS, TABLE_MESSAGES, TABLE_EVALS, TABLE_TRACES } from './chunk-RG66XEJT.js';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { createClient } from '@libsql/client';
|
|
@@ -14,6 +14,9 @@ var LibSQLStore = class extends MastraStorage {
|
|
|
14
14
|
client;
|
|
15
15
|
constructor({ config }) {
|
|
16
16
|
super({ name: `LibSQLStore` });
|
|
17
|
+
if (config.url === ":memory:") {
|
|
18
|
+
this.shouldCacheInit = false;
|
|
19
|
+
}
|
|
17
20
|
this.client = createClient({
|
|
18
21
|
url: this.rewriteDbUrl(config.url),
|
|
19
22
|
authToken: config.authToken
|
|
@@ -23,8 +26,8 @@ var LibSQLStore = class extends MastraStorage {
|
|
|
23
26
|
if (url.startsWith("file:") && !url.startsWith("file:/")) {
|
|
24
27
|
const cwd = process.cwd();
|
|
25
28
|
const relativePath = url.slice("file:".length);
|
|
26
|
-
if (cwd.
|
|
27
|
-
const baseDir = join(cwd, `..`);
|
|
29
|
+
if (cwd.includes(".mastra") && (cwd.endsWith(`output`) || cwd.endsWith(`output/`) || cwd.endsWith(`output\\`))) {
|
|
30
|
+
const baseDir = join(cwd, `..`, `..`);
|
|
28
31
|
const fullPath = join(baseDir, relativePath);
|
|
29
32
|
this.logger.debug(
|
|
30
33
|
`Initializing LibSQL db with url ${url} with relative file path from inside .mastra directory. Rewriting relative file url to "file:${fullPath}". This ensures it's outside the .mastra directory. If the db is stored inside .mastra it will be deleted when Mastra re-bundles code.`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InstrumentClass } from './chunk-W5HVJX45.js';
|
|
2
|
-
import { delay } from './chunk-
|
|
2
|
+
import { delay } from './chunk-3GC7P4J6.js';
|
|
3
3
|
import { MastraBase } from './chunk-OZ4XVJ6F.js';
|
|
4
4
|
import { RegisteredLogger } from './chunk-PHMSPCTC.js';
|
|
5
5
|
import { executeHook } from './chunk-BB4KXGBU.js';
|
|
@@ -138,7 +138,8 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
138
138
|
tools,
|
|
139
139
|
runId,
|
|
140
140
|
threadId,
|
|
141
|
-
resourceId
|
|
141
|
+
resourceId,
|
|
142
|
+
memory
|
|
142
143
|
} = {}) {
|
|
143
144
|
this.logger.debug("Starting tool conversion for LLM");
|
|
144
145
|
const converted = Object.entries(tools || {}).reduce((memo, value) => {
|
|
@@ -159,6 +160,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
159
160
|
threadId,
|
|
160
161
|
resourceId,
|
|
161
162
|
mastra: this.#mastra,
|
|
163
|
+
memory,
|
|
162
164
|
runId
|
|
163
165
|
}, options) ?? void 0;
|
|
164
166
|
} catch (error) {
|
|
@@ -193,6 +195,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
193
195
|
telemetry,
|
|
194
196
|
threadId,
|
|
195
197
|
resourceId,
|
|
198
|
+
memory,
|
|
196
199
|
...rest
|
|
197
200
|
}) {
|
|
198
201
|
const model = this.#model;
|
|
@@ -208,7 +211,8 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
208
211
|
tools,
|
|
209
212
|
runId,
|
|
210
213
|
threadId,
|
|
211
|
-
resourceId
|
|
214
|
+
resourceId,
|
|
215
|
+
memory
|
|
212
216
|
});
|
|
213
217
|
const argsForExecute = {
|
|
214
218
|
model,
|
|
@@ -276,6 +280,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
276
280
|
telemetry,
|
|
277
281
|
threadId,
|
|
278
282
|
resourceId,
|
|
283
|
+
memory,
|
|
279
284
|
...rest
|
|
280
285
|
}) {
|
|
281
286
|
const model = this.#model;
|
|
@@ -286,7 +291,8 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
286
291
|
tools,
|
|
287
292
|
runId,
|
|
288
293
|
threadId,
|
|
289
|
-
resourceId
|
|
294
|
+
resourceId,
|
|
295
|
+
memory
|
|
290
296
|
});
|
|
291
297
|
const argsForExecute = {
|
|
292
298
|
model,
|
|
@@ -351,6 +357,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
351
357
|
telemetry,
|
|
352
358
|
threadId,
|
|
353
359
|
resourceId,
|
|
360
|
+
memory,
|
|
354
361
|
...rest
|
|
355
362
|
}) {
|
|
356
363
|
const model = this.#model;
|
|
@@ -366,7 +373,8 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
366
373
|
tools,
|
|
367
374
|
runId,
|
|
368
375
|
threadId,
|
|
369
|
-
resourceId
|
|
376
|
+
resourceId,
|
|
377
|
+
memory
|
|
370
378
|
});
|
|
371
379
|
const argsForExecute = {
|
|
372
380
|
model,
|
|
@@ -448,6 +456,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
448
456
|
telemetry,
|
|
449
457
|
threadId,
|
|
450
458
|
resourceId,
|
|
459
|
+
memory,
|
|
451
460
|
...rest
|
|
452
461
|
}) {
|
|
453
462
|
const model = this.#model;
|
|
@@ -461,7 +470,8 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
461
470
|
tools,
|
|
462
471
|
runId,
|
|
463
472
|
threadId,
|
|
464
|
-
resourceId
|
|
473
|
+
resourceId,
|
|
474
|
+
memory
|
|
465
475
|
});
|
|
466
476
|
const argsForExecute = {
|
|
467
477
|
model,
|
|
@@ -536,6 +546,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
536
546
|
output,
|
|
537
547
|
temperature,
|
|
538
548
|
telemetry,
|
|
549
|
+
memory,
|
|
539
550
|
...rest
|
|
540
551
|
} = {}) {
|
|
541
552
|
const msgs = this.convertToMessages(messages);
|
|
@@ -548,6 +559,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
548
559
|
convertedTools,
|
|
549
560
|
runId,
|
|
550
561
|
temperature,
|
|
562
|
+
memory,
|
|
551
563
|
...rest
|
|
552
564
|
});
|
|
553
565
|
}
|
|
@@ -560,6 +572,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
560
572
|
convertedTools,
|
|
561
573
|
runId,
|
|
562
574
|
telemetry,
|
|
575
|
+
memory,
|
|
563
576
|
...rest
|
|
564
577
|
});
|
|
565
578
|
}
|
|
@@ -974,6 +987,8 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
974
987
|
threadId,
|
|
975
988
|
resourceId
|
|
976
989
|
});
|
|
990
|
+
const memory = this.getMemory();
|
|
991
|
+
const memoryTools = memory?.getTools();
|
|
977
992
|
const converted = Object.entries(this.tools || {}).reduce((memo, value) => {
|
|
978
993
|
const k = value[0];
|
|
979
994
|
const tool = this.tools[k];
|
|
@@ -994,6 +1009,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
994
1009
|
return tool?.execute?.({
|
|
995
1010
|
context: args,
|
|
996
1011
|
mastra: this.#mastra,
|
|
1012
|
+
memory,
|
|
997
1013
|
runId,
|
|
998
1014
|
threadId,
|
|
999
1015
|
resourceId
|
|
@@ -1012,8 +1028,44 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
1012
1028
|
}
|
|
1013
1029
|
return memo;
|
|
1014
1030
|
}, {});
|
|
1031
|
+
const convertedMemoryTools = memoryTools ? Object.entries(memoryTools).reduce((memo, [k, tool]) => {
|
|
1032
|
+
memo[k] = {
|
|
1033
|
+
description: tool.description,
|
|
1034
|
+
parameters: tool.parameters,
|
|
1035
|
+
execute: typeof tool?.execute === "function" ? async (args, options) => {
|
|
1036
|
+
try {
|
|
1037
|
+
this.logger.debug(`[Agent:${this.name}] - Executing memory tool ${k}`, {
|
|
1038
|
+
name: k,
|
|
1039
|
+
description: tool.description,
|
|
1040
|
+
args,
|
|
1041
|
+
runId,
|
|
1042
|
+
threadId,
|
|
1043
|
+
resourceId
|
|
1044
|
+
});
|
|
1045
|
+
return tool?.execute?.({
|
|
1046
|
+
context: args,
|
|
1047
|
+
mastra: this.#mastra,
|
|
1048
|
+
memory,
|
|
1049
|
+
runId,
|
|
1050
|
+
threadId,
|
|
1051
|
+
resourceId
|
|
1052
|
+
}, options) ?? void 0;
|
|
1053
|
+
} catch (err) {
|
|
1054
|
+
this.logger.error(`[Agent:${this.name}] - Failed memory tool execution`, {
|
|
1055
|
+
error: err,
|
|
1056
|
+
runId,
|
|
1057
|
+
threadId,
|
|
1058
|
+
resourceId
|
|
1059
|
+
});
|
|
1060
|
+
throw err;
|
|
1061
|
+
}
|
|
1062
|
+
} : void 0
|
|
1063
|
+
};
|
|
1064
|
+
return memo;
|
|
1065
|
+
}, {}) : {};
|
|
1015
1066
|
const toolsFromToolsetsConverted = {
|
|
1016
|
-
...converted
|
|
1067
|
+
...converted,
|
|
1068
|
+
...convertedMemoryTools
|
|
1017
1069
|
};
|
|
1018
1070
|
const toolsFromToolsets = Object.values(toolsets || {});
|
|
1019
1071
|
if (toolsFromToolsets.length > 0) {
|
|
@@ -1283,6 +1335,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
1283
1335
|
experimental_output,
|
|
1284
1336
|
threadId,
|
|
1285
1337
|
resourceId,
|
|
1338
|
+
memory: this.getMemory(),
|
|
1286
1339
|
...rest
|
|
1287
1340
|
});
|
|
1288
1341
|
const outputText2 = result2.text;
|
|
@@ -1310,6 +1363,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
1310
1363
|
telemetry,
|
|
1311
1364
|
threadId,
|
|
1312
1365
|
resourceId,
|
|
1366
|
+
memory: this.getMemory(),
|
|
1313
1367
|
...rest
|
|
1314
1368
|
});
|
|
1315
1369
|
const outputText2 = result2.text;
|
|
@@ -1333,6 +1387,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
1333
1387
|
temperature,
|
|
1334
1388
|
toolChoice,
|
|
1335
1389
|
telemetry,
|
|
1390
|
+
memory: this.getMemory(),
|
|
1336
1391
|
...rest
|
|
1337
1392
|
});
|
|
1338
1393
|
const outputText = JSON.stringify(result.object);
|
|
@@ -1430,6 +1485,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
1430
1485
|
runId: runIdToUse,
|
|
1431
1486
|
toolChoice,
|
|
1432
1487
|
experimental_output,
|
|
1488
|
+
memory: this.getMemory(),
|
|
1433
1489
|
...rest
|
|
1434
1490
|
});
|
|
1435
1491
|
const newStreamResult = streamResult;
|
|
@@ -1468,6 +1524,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
1468
1524
|
runId: runIdToUse,
|
|
1469
1525
|
toolChoice,
|
|
1470
1526
|
telemetry,
|
|
1527
|
+
memory: this.getMemory(),
|
|
1471
1528
|
...rest
|
|
1472
1529
|
});
|
|
1473
1530
|
}
|
|
@@ -1503,6 +1560,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
1503
1560
|
runId: runIdToUse,
|
|
1504
1561
|
toolChoice,
|
|
1505
1562
|
telemetry,
|
|
1563
|
+
memory: this.getMemory(),
|
|
1506
1564
|
...rest
|
|
1507
1565
|
});
|
|
1508
1566
|
}
|
|
@@ -434,8 +434,8 @@ var LibSQLVector = class extends MastraVector {
|
|
|
434
434
|
if (url.startsWith("file:") && !url.startsWith("file:/")) {
|
|
435
435
|
const cwd = process.cwd();
|
|
436
436
|
const relativePath = url.slice("file:".length);
|
|
437
|
-
if (cwd.
|
|
438
|
-
const baseDir = join(cwd, `..`);
|
|
437
|
+
if (cwd.includes(".mastra") && (cwd.endsWith(`output`) || cwd.endsWith(`output/`) || cwd.endsWith(`output\\`))) {
|
|
438
|
+
const baseDir = join(cwd, `..`, `..`);
|
|
439
439
|
const fullPath = join(baseDir, relativePath);
|
|
440
440
|
this.logger.debug(
|
|
441
441
|
`Initializing LibSQL db with url ${url} with relative file path from inside .mastra directory. Rewriting relative file url to "file:${fullPath}". This ensures it's outside the .mastra directory. If the db is stored inside .mastra it will be deleted when Mastra re-bundles code.`
|