@mastra/core 0.8.0-alpha.4 → 0.8.0-alpha.5
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 +2 -2
- 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-DKCrhg-t.d.ts → base-C1_qIrbQ.d.ts} +6 -10
- package/dist/{base-CsysLRiE.d.cts → base-DUSE03ps.d.cts} +6 -10
- package/dist/{chunk-YZDUZFVZ.cjs → chunk-AAMFAGE5.cjs} +6 -0
- package/dist/{chunk-3ZXH2ILQ.cjs → chunk-E7N5CDWQ.cjs} +9 -11
- package/dist/{chunk-C76A6MVU.js → chunk-KHMCAV4W.js} +1 -1
- package/dist/{chunk-ADBGSSBH.cjs → chunk-LK5H7SEM.cjs} +62 -88
- package/dist/{chunk-R6ERLKCY.cjs → chunk-S3VEAYDK.cjs} +2 -2
- package/dist/{chunk-5LOK7ABN.js → chunk-TFDALD5V.js} +62 -88
- package/dist/{chunk-HQF32W4R.js → chunk-VVNZXXHP.js} +8 -10
- package/dist/{chunk-BRBHQ6KS.js → chunk-YVPTMEI4.js} +6 -0
- package/dist/eval/index.d.cts +1 -1
- package/dist/eval/index.d.ts +1 -1
- package/dist/index.cjs +30 -30
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -5
- package/dist/integration/index.d.cts +1 -1
- package/dist/integration/index.d.ts +1 -1
- package/dist/llm/index.d.cts +1 -1
- package/dist/llm/index.d.ts +1 -1
- package/dist/mastra/index.d.cts +1 -1
- package/dist/mastra/index.d.ts +1 -1
- package/dist/memory/index.cjs +3 -3
- 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/network/index.cjs +2 -2
- package/dist/network/index.d.cts +1 -1
- package/dist/network/index.d.ts +1 -1
- package/dist/network/index.js +1 -1
- package/dist/relevance/index.cjs +4 -4
- package/dist/relevance/index.d.cts +1 -1
- package/dist/relevance/index.d.ts +1 -1
- package/dist/relevance/index.js +1 -1
- package/dist/server/index.d.cts +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/storage/index.d.cts +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/libsql/index.d.cts +1 -1
- package/dist/storage/libsql/index.d.ts +1 -1
- package/dist/telemetry/index.d.cts +1 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/tools/index.d.cts +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/vector/libsql/index.cjs +3 -3
- package/dist/vector/libsql/index.js +1 -1
- package/dist/voice/index.d.cts +2 -2
- package/dist/voice/index.d.ts +2 -2
- package/dist/workflows/index.cjs +22 -22
- package/dist/workflows/index.d.cts +2 -2
- package/dist/workflows/index.d.ts +2 -2
- package/dist/workflows/index.js +1 -1
- package/package.json +1 -1
package/dist/agent/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkLK5H7SEM_cjs = require('../chunk-LK5H7SEM.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "Agent", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkLK5H7SEM_cjs.Agent; }
|
|
10
10
|
});
|
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 { j as Agent, k as AgentConfig, aM as AgentGenerateOptions, aN as AgentStreamOptions, aG as MastraLanguageModel, aH as ToolsInput, aL as ToolsetsInput } from '../base-
|
|
4
|
+
export { j as Agent, k as AgentConfig, aM as AgentGenerateOptions, aN as AgentStreamOptions, aG as MastraLanguageModel, aH as ToolsInput, aL as ToolsetsInput } from '../base-DUSE03ps.cjs';
|
|
5
5
|
import '../base-CvQbEqGB.cjs';
|
|
6
6
|
import '../types-BtMyV38I.cjs';
|
|
7
7
|
import 'sift';
|
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 { j as Agent, k as AgentConfig, aM as AgentGenerateOptions, aN as AgentStreamOptions, aG as MastraLanguageModel, aH as ToolsInput, aL as ToolsetsInput } from '../base-
|
|
4
|
+
export { j as Agent, k as AgentConfig, aM as AgentGenerateOptions, aN as AgentStreamOptions, aG as MastraLanguageModel, aH as ToolsInput, aL as ToolsetsInput } from '../base-C1_qIrbQ.js';
|
|
5
5
|
import '../base-BA_in99t.js';
|
|
6
6
|
import '../types-BtMyV38I.js';
|
|
7
7
|
import 'sift';
|
package/dist/agent/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Agent } from '../chunk-
|
|
1
|
+
export { Agent } from '../chunk-TFDALD5V.js';
|
|
@@ -1148,7 +1148,7 @@ declare abstract class MastraMemory extends MastraBase {
|
|
|
1148
1148
|
* Implementations can override this to provide additional tools.
|
|
1149
1149
|
*/
|
|
1150
1150
|
getTools(_config?: MemoryConfig): Record<string, CoreTool>;
|
|
1151
|
-
protected createEmbeddingIndex(): Promise<{
|
|
1151
|
+
protected createEmbeddingIndex(dimensions?: number): Promise<{
|
|
1152
1152
|
indexName: string;
|
|
1153
1153
|
}>;
|
|
1154
1154
|
getMergedThreadConfig(config?: MemoryConfig): MemoryConfig;
|
|
@@ -1785,9 +1785,10 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
1785
1785
|
}): Promise<string>;
|
|
1786
1786
|
getMostRecentUserMessage(messages: Array<CoreMessage$1>): CoreUserMessage$1 | undefined;
|
|
1787
1787
|
genTitle(userMessage: CoreUserMessage$1 | undefined): Promise<string>;
|
|
1788
|
-
fetchMemory({ threadId, memoryConfig, resourceId, userMessages, systemMessage, runId, }: {
|
|
1788
|
+
fetchMemory({ threadId, thread: passedThread, memoryConfig, resourceId, userMessages, systemMessage, runId, }: {
|
|
1789
1789
|
resourceId: string;
|
|
1790
1790
|
threadId: string;
|
|
1791
|
+
thread?: StorageThreadType;
|
|
1791
1792
|
memoryConfig?: MemoryConfig;
|
|
1792
1793
|
userMessages: CoreMessage$1[];
|
|
1793
1794
|
systemMessage: CoreMessage$1;
|
|
@@ -1798,13 +1799,7 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
1798
1799
|
threadId: string;
|
|
1799
1800
|
messages: CoreMessage$1[];
|
|
1800
1801
|
}>;
|
|
1801
|
-
|
|
1802
|
-
runId: string;
|
|
1803
|
-
resourceId: string;
|
|
1804
|
-
result: Record<string, any>;
|
|
1805
|
-
threadId: string;
|
|
1806
|
-
memoryConfig: MemoryConfig | undefined;
|
|
1807
|
-
}): Promise<void>;
|
|
1802
|
+
private getResponseMessages;
|
|
1808
1803
|
sanitizeResponseMessages(messages: Array<CoreMessage$1>): Array<CoreMessage$1>;
|
|
1809
1804
|
convertTools({ toolsets, threadId, resourceId, runId, }: {
|
|
1810
1805
|
toolsets?: ToolsetsInput;
|
|
@@ -1812,9 +1807,10 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
1812
1807
|
resourceId?: string;
|
|
1813
1808
|
runId?: string;
|
|
1814
1809
|
}): Record<string, CoreTool>;
|
|
1815
|
-
preExecute({ resourceId, runId, threadId, memoryConfig, messages, systemMessage, }: {
|
|
1810
|
+
preExecute({ resourceId, runId, threadId, thread, memoryConfig, messages, systemMessage, }: {
|
|
1816
1811
|
runId?: string;
|
|
1817
1812
|
threadId: string;
|
|
1813
|
+
thread?: StorageThreadType;
|
|
1818
1814
|
memoryConfig?: MemoryConfig;
|
|
1819
1815
|
messages: CoreMessage$1[];
|
|
1820
1816
|
resourceId: string;
|
|
@@ -1148,7 +1148,7 @@ declare abstract class MastraMemory extends MastraBase {
|
|
|
1148
1148
|
* Implementations can override this to provide additional tools.
|
|
1149
1149
|
*/
|
|
1150
1150
|
getTools(_config?: MemoryConfig): Record<string, CoreTool>;
|
|
1151
|
-
protected createEmbeddingIndex(): Promise<{
|
|
1151
|
+
protected createEmbeddingIndex(dimensions?: number): Promise<{
|
|
1152
1152
|
indexName: string;
|
|
1153
1153
|
}>;
|
|
1154
1154
|
getMergedThreadConfig(config?: MemoryConfig): MemoryConfig;
|
|
@@ -1785,9 +1785,10 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
1785
1785
|
}): Promise<string>;
|
|
1786
1786
|
getMostRecentUserMessage(messages: Array<CoreMessage$1>): CoreUserMessage$1 | undefined;
|
|
1787
1787
|
genTitle(userMessage: CoreUserMessage$1 | undefined): Promise<string>;
|
|
1788
|
-
fetchMemory({ threadId, memoryConfig, resourceId, userMessages, systemMessage, runId, }: {
|
|
1788
|
+
fetchMemory({ threadId, thread: passedThread, memoryConfig, resourceId, userMessages, systemMessage, runId, }: {
|
|
1789
1789
|
resourceId: string;
|
|
1790
1790
|
threadId: string;
|
|
1791
|
+
thread?: StorageThreadType;
|
|
1791
1792
|
memoryConfig?: MemoryConfig;
|
|
1792
1793
|
userMessages: CoreMessage$1[];
|
|
1793
1794
|
systemMessage: CoreMessage$1;
|
|
@@ -1798,13 +1799,7 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
1798
1799
|
threadId: string;
|
|
1799
1800
|
messages: CoreMessage$1[];
|
|
1800
1801
|
}>;
|
|
1801
|
-
|
|
1802
|
-
runId: string;
|
|
1803
|
-
resourceId: string;
|
|
1804
|
-
result: Record<string, any>;
|
|
1805
|
-
threadId: string;
|
|
1806
|
-
memoryConfig: MemoryConfig | undefined;
|
|
1807
|
-
}): Promise<void>;
|
|
1802
|
+
private getResponseMessages;
|
|
1808
1803
|
sanitizeResponseMessages(messages: Array<CoreMessage$1>): Array<CoreMessage$1>;
|
|
1809
1804
|
convertTools({ toolsets, threadId, resourceId, runId, }: {
|
|
1810
1805
|
toolsets?: ToolsetsInput;
|
|
@@ -1812,9 +1807,10 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
1812
1807
|
resourceId?: string;
|
|
1813
1808
|
runId?: string;
|
|
1814
1809
|
}): Record<string, CoreTool>;
|
|
1815
|
-
preExecute({ resourceId, runId, threadId, memoryConfig, messages, systemMessage, }: {
|
|
1810
|
+
preExecute({ resourceId, runId, threadId, thread, memoryConfig, messages, systemMessage, }: {
|
|
1816
1811
|
runId?: string;
|
|
1817
1812
|
threadId: string;
|
|
1813
|
+
thread?: StorageThreadType;
|
|
1818
1814
|
memoryConfig?: MemoryConfig;
|
|
1819
1815
|
messages: CoreMessage$1[];
|
|
1820
1816
|
resourceId: string;
|
|
@@ -431,6 +431,12 @@ var LibSQLVector = class extends chunk7JBINHJX_cjs.MastraVector {
|
|
|
431
431
|
authToken,
|
|
432
432
|
syncInterval
|
|
433
433
|
});
|
|
434
|
+
if (connectionUrl.includes(`file:`) || connectionUrl.includes(`:memory:`)) {
|
|
435
|
+
void this.turso.execute({
|
|
436
|
+
sql: "PRAGMA journal_mode=WAL;",
|
|
437
|
+
args: {}
|
|
438
|
+
});
|
|
439
|
+
}
|
|
434
440
|
}
|
|
435
441
|
// If we're in the .mastra/output directory, use the dir outside .mastra dir
|
|
436
442
|
// reason we need to do this is libsql relative file paths are based on cwd, not current file path
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkAAMFAGE5_cjs = require('./chunk-AAMFAGE5.cjs');
|
|
4
4
|
var chunk3HRHS5S2_cjs = require('./chunk-3HRHS5S2.cjs');
|
|
5
5
|
var chunk64VPB7ZD_cjs = require('./chunk-64VPB7ZD.cjs');
|
|
6
6
|
var chunkD63P5O4Q_cjs = require('./chunk-D63P5O4Q.cjs');
|
|
@@ -155,7 +155,7 @@ var MastraMemory = class extends chunkD63P5O4Q_cjs.MastraBase {
|
|
|
155
155
|
`Found deprecated Memory vector db file ${oldDb} this db is now merged with the default ${newDb} file. Delete the old one to use the new one. You will need to migrate any data if that's important to you. For now the deprecated path will be used but in a future breaking change we will only use the new db file path.`
|
|
156
156
|
);
|
|
157
157
|
}
|
|
158
|
-
this.vector = new
|
|
158
|
+
this.vector = new chunkAAMFAGE5_cjs.LibSQLVector({
|
|
159
159
|
connectionUrl: hasOldDb ? `file:${oldDb}` : `file:${newDb}`
|
|
160
160
|
});
|
|
161
161
|
}
|
|
@@ -196,17 +196,15 @@ var MastraMemory = class extends chunkD63P5O4Q_cjs.MastraBase {
|
|
|
196
196
|
getTools(_config) {
|
|
197
197
|
return {};
|
|
198
198
|
}
|
|
199
|
-
async createEmbeddingIndex() {
|
|
199
|
+
async createEmbeddingIndex(dimensions) {
|
|
200
200
|
const defaultDimensions = 1536;
|
|
201
|
-
const dimensionsByModelId = {
|
|
202
|
-
"bge-small-en-v1.5": 384,
|
|
203
|
-
"bge-base-en-v1.5": 768,
|
|
204
|
-
"voyage-3-lite": 512
|
|
205
|
-
};
|
|
206
|
-
const dimensions = dimensionsByModelId[this.embedder.modelId] || defaultDimensions;
|
|
207
201
|
const isDefault = dimensions === defaultDimensions;
|
|
208
|
-
const
|
|
209
|
-
|
|
202
|
+
const usedDimensions = dimensions ?? defaultDimensions;
|
|
203
|
+
const indexName = isDefault ? "memory_messages" : `memory_messages_${usedDimensions}`;
|
|
204
|
+
await this.vector.createIndex({
|
|
205
|
+
indexName,
|
|
206
|
+
dimension: usedDimensions
|
|
207
|
+
});
|
|
210
208
|
return { indexName };
|
|
211
209
|
}
|
|
212
210
|
getMergedThreadConfig(config) {
|
|
@@ -891,6 +891,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
|
|
|
891
891
|
}
|
|
892
892
|
async fetchMemory({
|
|
893
893
|
threadId,
|
|
894
|
+
thread: passedThread,
|
|
894
895
|
memoryConfig,
|
|
895
896
|
resourceId,
|
|
896
897
|
userMessages,
|
|
@@ -899,9 +900,9 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
|
|
|
899
900
|
}) {
|
|
900
901
|
const memory = this.getMemory();
|
|
901
902
|
if (memory) {
|
|
902
|
-
const thread = await memory.getThreadById({
|
|
903
|
+
const thread = passedThread ?? (await memory.getThreadById({
|
|
903
904
|
threadId
|
|
904
|
-
});
|
|
905
|
+
}));
|
|
905
906
|
if (!thread) {
|
|
906
907
|
return {
|
|
907
908
|
threadId: threadId || "",
|
|
@@ -959,80 +960,54 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
|
|
|
959
960
|
messages: userMessages
|
|
960
961
|
};
|
|
961
962
|
}
|
|
962
|
-
|
|
963
|
-
|
|
963
|
+
getResponseMessages({
|
|
964
|
+
response,
|
|
964
965
|
threadId,
|
|
965
|
-
resourceId
|
|
966
|
-
runId,
|
|
967
|
-
memoryConfig
|
|
966
|
+
resourceId
|
|
968
967
|
}) {
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
resourceId,
|
|
981
|
-
threadId,
|
|
982
|
-
memoryStore: this.getMemory()?.constructor.name
|
|
983
|
-
});
|
|
984
|
-
await memory.saveMessages({
|
|
985
|
-
memoryConfig,
|
|
986
|
-
messages: responseMessagesWithoutIncompleteToolCalls.map((message, index) => {
|
|
987
|
-
const messageId = crypto$1.randomUUID();
|
|
988
|
-
let toolCallIds;
|
|
989
|
-
let toolCallArgs;
|
|
990
|
-
let toolNames;
|
|
991
|
-
let type = "text";
|
|
992
|
-
if (message.role === "tool") {
|
|
993
|
-
toolCallIds = message.content.map(content => content.toolCallId);
|
|
994
|
-
type = "tool-result";
|
|
995
|
-
}
|
|
996
|
-
if (message.role === "assistant") {
|
|
997
|
-
const assistantContent = message.content;
|
|
998
|
-
const assistantToolCalls = assistantContent.map(content => {
|
|
999
|
-
if (content.type === "tool-call") {
|
|
1000
|
-
return {
|
|
1001
|
-
toolCallId: content.toolCallId,
|
|
1002
|
-
toolArgs: content.args,
|
|
1003
|
-
toolName: content.toolName
|
|
1004
|
-
};
|
|
1005
|
-
}
|
|
1006
|
-
return void 0;
|
|
1007
|
-
})?.filter(Boolean);
|
|
1008
|
-
toolCallIds = assistantToolCalls?.map(toolCall => toolCall.toolCallId);
|
|
1009
|
-
toolCallArgs = assistantToolCalls?.map(toolCall => toolCall.toolArgs);
|
|
1010
|
-
toolNames = assistantToolCalls?.map(toolCall => toolCall.toolName);
|
|
1011
|
-
type = assistantContent?.[0]?.type;
|
|
1012
|
-
}
|
|
1013
|
-
return {
|
|
1014
|
-
id: messageId,
|
|
1015
|
-
threadId,
|
|
1016
|
-
resourceId,
|
|
1017
|
-
role: message.role,
|
|
1018
|
-
content: message.content,
|
|
1019
|
-
createdAt: new Date(Date.now() + index),
|
|
1020
|
-
// use Date.now() + index to make sure every message is atleast one millisecond apart
|
|
1021
|
-
toolCallIds: toolCallIds?.length ? toolCallIds : void 0,
|
|
1022
|
-
toolCallArgs: toolCallArgs?.length ? toolCallArgs : void 0,
|
|
1023
|
-
toolNames: toolNames?.length ? toolNames : void 0,
|
|
1024
|
-
type
|
|
1025
|
-
};
|
|
1026
|
-
})
|
|
1027
|
-
});
|
|
1028
|
-
}
|
|
968
|
+
if (!response.messages) return [];
|
|
969
|
+
const messagesArray = Array.isArray(response.messages) ? response.messages : [response.messages];
|
|
970
|
+
return this.sanitizeResponseMessages(messagesArray).map((message, index) => {
|
|
971
|
+
const messageId = crypto$1.randomUUID();
|
|
972
|
+
let toolCallIds;
|
|
973
|
+
let toolCallArgs;
|
|
974
|
+
let toolNames;
|
|
975
|
+
let type = "text";
|
|
976
|
+
if (message.role === "tool") {
|
|
977
|
+
toolCallIds = message.content.map(content => content.toolCallId);
|
|
978
|
+
type = "tool-result";
|
|
1029
979
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
980
|
+
if (message.role === "assistant") {
|
|
981
|
+
const assistantContent = message.content;
|
|
982
|
+
const assistantToolCalls = assistantContent.map(content => {
|
|
983
|
+
if (content.type === "tool-call") {
|
|
984
|
+
return {
|
|
985
|
+
toolCallId: content.toolCallId,
|
|
986
|
+
toolArgs: content.args,
|
|
987
|
+
toolName: content.toolName
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
return void 0;
|
|
991
|
+
})?.filter(Boolean);
|
|
992
|
+
toolCallIds = assistantToolCalls?.map(toolCall => toolCall.toolCallId);
|
|
993
|
+
toolCallArgs = assistantToolCalls?.map(toolCall => toolCall.toolArgs);
|
|
994
|
+
toolNames = assistantToolCalls?.map(toolCall => toolCall.toolName);
|
|
995
|
+
type = assistantContent?.[0]?.type;
|
|
996
|
+
}
|
|
997
|
+
return {
|
|
998
|
+
id: messageId,
|
|
999
|
+
threadId,
|
|
1000
|
+
resourceId,
|
|
1001
|
+
role: message.role,
|
|
1002
|
+
content: message.content,
|
|
1003
|
+
createdAt: new Date(Date.now() + index),
|
|
1004
|
+
// use Date.now() + index to make sure every message is atleast one millisecond apart
|
|
1005
|
+
toolCallIds: toolCallIds?.length ? toolCallIds : void 0,
|
|
1006
|
+
toolCallArgs: toolCallArgs?.length ? toolCallArgs : void 0,
|
|
1007
|
+
toolNames: toolNames?.length ? toolNames : void 0,
|
|
1008
|
+
type
|
|
1009
|
+
};
|
|
1010
|
+
});
|
|
1036
1011
|
}
|
|
1037
1012
|
sanitizeResponseMessages(messages) {
|
|
1038
1013
|
let toolResultIds = [];
|
|
@@ -1196,6 +1171,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
|
|
|
1196
1171
|
resourceId,
|
|
1197
1172
|
runId,
|
|
1198
1173
|
threadId,
|
|
1174
|
+
thread,
|
|
1199
1175
|
memoryConfig,
|
|
1200
1176
|
messages,
|
|
1201
1177
|
systemMessage
|
|
@@ -1207,6 +1183,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
|
|
|
1207
1183
|
});
|
|
1208
1184
|
const saveMessageResponse = await this.fetchMemory({
|
|
1209
1185
|
threadId,
|
|
1186
|
+
thread,
|
|
1210
1187
|
resourceId,
|
|
1211
1188
|
userMessages: messages,
|
|
1212
1189
|
memoryConfig,
|
|
@@ -1269,6 +1246,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
|
|
|
1269
1246
|
resourceId,
|
|
1270
1247
|
runId,
|
|
1271
1248
|
threadId: threadIdToUse,
|
|
1249
|
+
thread,
|
|
1272
1250
|
memoryConfig,
|
|
1273
1251
|
messages,
|
|
1274
1252
|
systemMessage
|
|
@@ -1344,7 +1322,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
|
|
|
1344
1322
|
try {
|
|
1345
1323
|
const userMessage = this.getMostRecentUserMessage(messages);
|
|
1346
1324
|
const newMessages = userMessage ? [userMessage] : messages;
|
|
1347
|
-
const threadMessages = newMessages.map(u => {
|
|
1325
|
+
const threadMessages = this.sanitizeResponseMessages(chunk64VPB7ZD_cjs.ensureAllMessagesAreCoreMessages(newMessages)).map(u => {
|
|
1348
1326
|
return {
|
|
1349
1327
|
id: this.getMemory()?.generateId(),
|
|
1350
1328
|
createdAt: /* @__PURE__ */new Date(),
|
|
@@ -1356,19 +1334,7 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
|
|
|
1356
1334
|
type: "text"
|
|
1357
1335
|
};
|
|
1358
1336
|
});
|
|
1359
|
-
|
|
1360
|
-
await memory.saveMessages({
|
|
1361
|
-
messages: threadMessages,
|
|
1362
|
-
memoryConfig: memoryConfig2
|
|
1363
|
-
});
|
|
1364
|
-
await this.saveResponse({
|
|
1365
|
-
result,
|
|
1366
|
-
threadId: threadId2,
|
|
1367
|
-
resourceId,
|
|
1368
|
-
memoryConfig: memoryConfig2,
|
|
1369
|
-
runId: runId2
|
|
1370
|
-
});
|
|
1371
|
-
})(), (async () => {
|
|
1337
|
+
void (async () => {
|
|
1372
1338
|
if (!thread.title?.startsWith("New Thread")) {
|
|
1373
1339
|
return;
|
|
1374
1340
|
}
|
|
@@ -1383,7 +1349,15 @@ exports.Agent = class Agent extends (_a = chunkD63P5O4Q_cjs.MastraBase) {
|
|
|
1383
1349
|
memoryConfig: memoryConfig2,
|
|
1384
1350
|
title
|
|
1385
1351
|
});
|
|
1386
|
-
})()
|
|
1352
|
+
})();
|
|
1353
|
+
await memory.saveMessages({
|
|
1354
|
+
messages: [...threadMessages, ...this.getResponseMessages({
|
|
1355
|
+
threadId: threadId2,
|
|
1356
|
+
resourceId,
|
|
1357
|
+
response: result.response
|
|
1358
|
+
})],
|
|
1359
|
+
memoryConfig: memoryConfig2
|
|
1360
|
+
});
|
|
1387
1361
|
} catch (e) {
|
|
1388
1362
|
this.logger.error("Error saving response", {
|
|
1389
1363
|
error: e,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkLK5H7SEM_cjs = require('./chunk-LK5H7SEM.cjs');
|
|
4
4
|
var cohereAi = require('cohere-ai');
|
|
5
5
|
|
|
6
6
|
var CohereRelevanceScorer = class {
|
|
@@ -38,7 +38,7 @@ Relevance score (0-1):`;
|
|
|
38
38
|
var MastraAgentRelevanceScorer = class {
|
|
39
39
|
agent;
|
|
40
40
|
constructor(name, model) {
|
|
41
|
-
this.agent = new
|
|
41
|
+
this.agent = new chunkLK5H7SEM_cjs.Agent({
|
|
42
42
|
name: `Relevance Scorer ${name}`,
|
|
43
43
|
instructions: `You are a specialized agent for evaluating the relevance of text to queries.
|
|
44
44
|
Your task is to rate how well a text passage answers a given query.
|
|
@@ -884,6 +884,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
884
884
|
}
|
|
885
885
|
async fetchMemory({
|
|
886
886
|
threadId,
|
|
887
|
+
thread: passedThread,
|
|
887
888
|
memoryConfig,
|
|
888
889
|
resourceId,
|
|
889
890
|
userMessages,
|
|
@@ -892,9 +893,9 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
892
893
|
}) {
|
|
893
894
|
const memory = this.getMemory();
|
|
894
895
|
if (memory) {
|
|
895
|
-
const thread = await memory.getThreadById({
|
|
896
|
+
const thread = passedThread ?? (await memory.getThreadById({
|
|
896
897
|
threadId
|
|
897
|
-
});
|
|
898
|
+
}));
|
|
898
899
|
if (!thread) {
|
|
899
900
|
return {
|
|
900
901
|
threadId: threadId || "",
|
|
@@ -952,80 +953,54 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
952
953
|
messages: userMessages
|
|
953
954
|
};
|
|
954
955
|
}
|
|
955
|
-
|
|
956
|
-
|
|
956
|
+
getResponseMessages({
|
|
957
|
+
response,
|
|
957
958
|
threadId,
|
|
958
|
-
resourceId
|
|
959
|
-
runId,
|
|
960
|
-
memoryConfig
|
|
959
|
+
resourceId
|
|
961
960
|
}) {
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
resourceId,
|
|
974
|
-
threadId,
|
|
975
|
-
memoryStore: this.getMemory()?.constructor.name
|
|
976
|
-
});
|
|
977
|
-
await memory.saveMessages({
|
|
978
|
-
memoryConfig,
|
|
979
|
-
messages: responseMessagesWithoutIncompleteToolCalls.map((message, index) => {
|
|
980
|
-
const messageId = randomUUID();
|
|
981
|
-
let toolCallIds;
|
|
982
|
-
let toolCallArgs;
|
|
983
|
-
let toolNames;
|
|
984
|
-
let type = "text";
|
|
985
|
-
if (message.role === "tool") {
|
|
986
|
-
toolCallIds = message.content.map(content => content.toolCallId);
|
|
987
|
-
type = "tool-result";
|
|
988
|
-
}
|
|
989
|
-
if (message.role === "assistant") {
|
|
990
|
-
const assistantContent = message.content;
|
|
991
|
-
const assistantToolCalls = assistantContent.map(content => {
|
|
992
|
-
if (content.type === "tool-call") {
|
|
993
|
-
return {
|
|
994
|
-
toolCallId: content.toolCallId,
|
|
995
|
-
toolArgs: content.args,
|
|
996
|
-
toolName: content.toolName
|
|
997
|
-
};
|
|
998
|
-
}
|
|
999
|
-
return void 0;
|
|
1000
|
-
})?.filter(Boolean);
|
|
1001
|
-
toolCallIds = assistantToolCalls?.map(toolCall => toolCall.toolCallId);
|
|
1002
|
-
toolCallArgs = assistantToolCalls?.map(toolCall => toolCall.toolArgs);
|
|
1003
|
-
toolNames = assistantToolCalls?.map(toolCall => toolCall.toolName);
|
|
1004
|
-
type = assistantContent?.[0]?.type;
|
|
1005
|
-
}
|
|
1006
|
-
return {
|
|
1007
|
-
id: messageId,
|
|
1008
|
-
threadId,
|
|
1009
|
-
resourceId,
|
|
1010
|
-
role: message.role,
|
|
1011
|
-
content: message.content,
|
|
1012
|
-
createdAt: new Date(Date.now() + index),
|
|
1013
|
-
// use Date.now() + index to make sure every message is atleast one millisecond apart
|
|
1014
|
-
toolCallIds: toolCallIds?.length ? toolCallIds : void 0,
|
|
1015
|
-
toolCallArgs: toolCallArgs?.length ? toolCallArgs : void 0,
|
|
1016
|
-
toolNames: toolNames?.length ? toolNames : void 0,
|
|
1017
|
-
type
|
|
1018
|
-
};
|
|
1019
|
-
})
|
|
1020
|
-
});
|
|
1021
|
-
}
|
|
961
|
+
if (!response.messages) return [];
|
|
962
|
+
const messagesArray = Array.isArray(response.messages) ? response.messages : [response.messages];
|
|
963
|
+
return this.sanitizeResponseMessages(messagesArray).map((message, index) => {
|
|
964
|
+
const messageId = randomUUID();
|
|
965
|
+
let toolCallIds;
|
|
966
|
+
let toolCallArgs;
|
|
967
|
+
let toolNames;
|
|
968
|
+
let type = "text";
|
|
969
|
+
if (message.role === "tool") {
|
|
970
|
+
toolCallIds = message.content.map(content => content.toolCallId);
|
|
971
|
+
type = "tool-result";
|
|
1022
972
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
973
|
+
if (message.role === "assistant") {
|
|
974
|
+
const assistantContent = message.content;
|
|
975
|
+
const assistantToolCalls = assistantContent.map(content => {
|
|
976
|
+
if (content.type === "tool-call") {
|
|
977
|
+
return {
|
|
978
|
+
toolCallId: content.toolCallId,
|
|
979
|
+
toolArgs: content.args,
|
|
980
|
+
toolName: content.toolName
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
return void 0;
|
|
984
|
+
})?.filter(Boolean);
|
|
985
|
+
toolCallIds = assistantToolCalls?.map(toolCall => toolCall.toolCallId);
|
|
986
|
+
toolCallArgs = assistantToolCalls?.map(toolCall => toolCall.toolArgs);
|
|
987
|
+
toolNames = assistantToolCalls?.map(toolCall => toolCall.toolName);
|
|
988
|
+
type = assistantContent?.[0]?.type;
|
|
989
|
+
}
|
|
990
|
+
return {
|
|
991
|
+
id: messageId,
|
|
992
|
+
threadId,
|
|
993
|
+
resourceId,
|
|
994
|
+
role: message.role,
|
|
995
|
+
content: message.content,
|
|
996
|
+
createdAt: new Date(Date.now() + index),
|
|
997
|
+
// use Date.now() + index to make sure every message is atleast one millisecond apart
|
|
998
|
+
toolCallIds: toolCallIds?.length ? toolCallIds : void 0,
|
|
999
|
+
toolCallArgs: toolCallArgs?.length ? toolCallArgs : void 0,
|
|
1000
|
+
toolNames: toolNames?.length ? toolNames : void 0,
|
|
1001
|
+
type
|
|
1002
|
+
};
|
|
1003
|
+
});
|
|
1029
1004
|
}
|
|
1030
1005
|
sanitizeResponseMessages(messages) {
|
|
1031
1006
|
let toolResultIds = [];
|
|
@@ -1189,6 +1164,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
1189
1164
|
resourceId,
|
|
1190
1165
|
runId,
|
|
1191
1166
|
threadId,
|
|
1167
|
+
thread,
|
|
1192
1168
|
memoryConfig,
|
|
1193
1169
|
messages,
|
|
1194
1170
|
systemMessage
|
|
@@ -1200,6 +1176,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
1200
1176
|
});
|
|
1201
1177
|
const saveMessageResponse = await this.fetchMemory({
|
|
1202
1178
|
threadId,
|
|
1179
|
+
thread,
|
|
1203
1180
|
resourceId,
|
|
1204
1181
|
userMessages: messages,
|
|
1205
1182
|
memoryConfig,
|
|
@@ -1262,6 +1239,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
1262
1239
|
resourceId,
|
|
1263
1240
|
runId,
|
|
1264
1241
|
threadId: threadIdToUse,
|
|
1242
|
+
thread,
|
|
1265
1243
|
memoryConfig,
|
|
1266
1244
|
messages,
|
|
1267
1245
|
systemMessage
|
|
@@ -1337,7 +1315,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
1337
1315
|
try {
|
|
1338
1316
|
const userMessage = this.getMostRecentUserMessage(messages);
|
|
1339
1317
|
const newMessages = userMessage ? [userMessage] : messages;
|
|
1340
|
-
const threadMessages = newMessages.map(u => {
|
|
1318
|
+
const threadMessages = this.sanitizeResponseMessages(ensureAllMessagesAreCoreMessages(newMessages)).map(u => {
|
|
1341
1319
|
return {
|
|
1342
1320
|
id: this.getMemory()?.generateId(),
|
|
1343
1321
|
createdAt: /* @__PURE__ */new Date(),
|
|
@@ -1349,19 +1327,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
1349
1327
|
type: "text"
|
|
1350
1328
|
};
|
|
1351
1329
|
});
|
|
1352
|
-
|
|
1353
|
-
await memory.saveMessages({
|
|
1354
|
-
messages: threadMessages,
|
|
1355
|
-
memoryConfig: memoryConfig2
|
|
1356
|
-
});
|
|
1357
|
-
await this.saveResponse({
|
|
1358
|
-
result,
|
|
1359
|
-
threadId: threadId2,
|
|
1360
|
-
resourceId,
|
|
1361
|
-
memoryConfig: memoryConfig2,
|
|
1362
|
-
runId: runId2
|
|
1363
|
-
});
|
|
1364
|
-
})(), (async () => {
|
|
1330
|
+
void (async () => {
|
|
1365
1331
|
if (!thread.title?.startsWith("New Thread")) {
|
|
1366
1332
|
return;
|
|
1367
1333
|
}
|
|
@@ -1376,7 +1342,15 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
1376
1342
|
memoryConfig: memoryConfig2,
|
|
1377
1343
|
title
|
|
1378
1344
|
});
|
|
1379
|
-
})()
|
|
1345
|
+
})();
|
|
1346
|
+
await memory.saveMessages({
|
|
1347
|
+
messages: [...threadMessages, ...this.getResponseMessages({
|
|
1348
|
+
threadId: threadId2,
|
|
1349
|
+
resourceId,
|
|
1350
|
+
response: result.response
|
|
1351
|
+
})],
|
|
1352
|
+
memoryConfig: memoryConfig2
|
|
1353
|
+
});
|
|
1380
1354
|
} catch (e) {
|
|
1381
1355
|
this.logger.error("Error saving response", {
|
|
1382
1356
|
error: e,
|