@mastra/server 0.0.0-remove-cloud-span-transform-20250425214156 → 0.0.0-scorers-api-v2-20250801171841
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/LICENSE.md +11 -42
- package/README.md +48 -135
- package/dist/chunk-2XIJW7SV.cjs +310 -0
- package/dist/chunk-2XIJW7SV.cjs.map +1 -0
- package/dist/chunk-4CEZIJWJ.cjs +150 -0
- package/dist/chunk-4CEZIJWJ.cjs.map +1 -0
- package/dist/chunk-4MQU6AJN.js +83 -0
- package/dist/chunk-4MQU6AJN.js.map +1 -0
- package/dist/{chunk-QN4KF3BH.cjs → chunk-4QSNRCOT.cjs} +4 -2
- package/dist/chunk-4QSNRCOT.cjs.map +1 -0
- package/dist/chunk-4US5W7PH.cjs +120 -0
- package/dist/chunk-4US5W7PH.cjs.map +1 -0
- package/dist/chunk-7FHF55WA.js +2041 -0
- package/dist/chunk-7FHF55WA.js.map +1 -0
- package/dist/{chunk-FV45V6WC.cjs → chunk-7NADHFD2.cjs} +3 -7
- package/dist/chunk-7NADHFD2.cjs.map +1 -0
- package/dist/chunk-BED2O446.cjs +88 -0
- package/dist/chunk-BED2O446.cjs.map +1 -0
- package/dist/chunk-BUOJL3MN.js +529 -0
- package/dist/chunk-BUOJL3MN.js.map +1 -0
- package/dist/chunk-CY4TP3FK.js +16 -0
- package/dist/chunk-CY4TP3FK.js.map +1 -0
- package/dist/{chunk-4JINXASC.js → chunk-G7NVCO5M.js} +7 -4
- package/dist/chunk-G7NVCO5M.js.map +1 -0
- package/dist/chunk-GASWM5HJ.cjs +514 -0
- package/dist/chunk-GASWM5HJ.cjs.map +1 -0
- package/dist/{chunk-Q6SHQECN.js → chunk-HWHKM67I.js} +36 -10
- package/dist/chunk-HWHKM67I.js.map +1 -0
- package/dist/chunk-HXIOPAHT.js +541 -0
- package/dist/chunk-HXIOPAHT.js.map +1 -0
- package/dist/{chunk-7IWQE76Z.cjs → chunk-ILCWPBYQ.cjs} +18 -10
- package/dist/chunk-ILCWPBYQ.cjs.map +1 -0
- package/dist/chunk-JGVY3KWV.cjs +334 -0
- package/dist/chunk-JGVY3KWV.cjs.map +1 -0
- package/dist/chunk-LRUH33B4.cjs +2044 -0
- package/dist/chunk-LRUH33B4.cjs.map +1 -0
- package/dist/{chunk-TRDNDNGQ.js → chunk-MMROOK5J.js} +4 -7
- package/dist/chunk-MMROOK5J.js.map +1 -0
- package/dist/{chunk-M56ECCHK.cjs → chunk-NCS2OXX6.cjs} +22 -19
- package/dist/chunk-NCS2OXX6.cjs.map +1 -0
- package/dist/{chunk-D3G23FP3.cjs → chunk-O4I563YW.cjs} +26 -22
- package/dist/chunk-O4I563YW.cjs.map +1 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-OW4FX5TS.js} +3 -1
- package/dist/chunk-OW4FX5TS.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +9 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-Q7SFCCGT.cjs +11 -0
- package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
- package/dist/chunk-RE4RPXT2.cjs +18 -0
- package/dist/chunk-RE4RPXT2.cjs.map +1 -0
- package/dist/chunk-S37KCGOR.cjs +546 -0
- package/dist/chunk-S37KCGOR.cjs.map +1 -0
- package/dist/{chunk-WTHDCRMY.js → chunk-SQ7KKIH3.js} +14 -6
- package/dist/chunk-SQ7KKIH3.js.map +1 -0
- package/dist/chunk-TRWPUPGD.js +506 -0
- package/dist/chunk-TRWPUPGD.js.map +1 -0
- package/dist/chunk-TXAQU2XN.js +151 -0
- package/dist/chunk-TXAQU2XN.js.map +1 -0
- package/dist/{chunk-LFOBHRFO.js → chunk-UVOSITKU.js} +76 -59
- package/dist/chunk-UVOSITKU.js.map +1 -0
- package/dist/chunk-VIGPWTDA.cjs +159 -0
- package/dist/chunk-VIGPWTDA.cjs.map +1 -0
- package/dist/chunk-VOY6MGKA.js +301 -0
- package/dist/chunk-VOY6MGKA.js.map +1 -0
- package/dist/chunk-X5SDJOY6.cjs +557 -0
- package/dist/chunk-X5SDJOY6.cjs.map +1 -0
- package/dist/{chunk-RE6YL32K.js → chunk-Y3J45CVZ.js} +54 -30
- package/dist/chunk-Y3J45CVZ.js.map +1 -0
- package/dist/{chunk-5JNVY6DU.js → chunk-YS66MFDY.js} +9 -5
- package/dist/chunk-YS66MFDY.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/server/a2a/protocol.d.ts +8 -0
- package/dist/server/a2a/protocol.d.ts.map +1 -0
- package/dist/server/a2a/store.d.ts +14 -0
- package/dist/server/a2a/store.d.ts.map +1 -0
- package/dist/server/a2a/tasks.d.ts +20 -0
- package/dist/server/a2a/tasks.d.ts.map +1 -0
- package/dist/server/handlers/a2a.cjs +32 -0
- package/dist/server/handlers/a2a.cjs.map +1 -0
- package/dist/server/handlers/a2a.d.ts +66 -0
- package/dist/server/handlers/a2a.d.ts.map +1 -0
- package/dist/server/handlers/a2a.js +3 -0
- package/dist/server/handlers/a2a.js.map +1 -0
- package/dist/server/handlers/agents.cjs +13 -7
- package/dist/server/handlers/agents.cjs.map +1 -0
- package/dist/server/handlers/agents.d.ts +81 -6
- package/dist/server/handlers/agents.d.ts.map +1 -0
- package/dist/server/handlers/agents.js +3 -1
- package/dist/server/handlers/agents.js.map +1 -0
- package/dist/server/handlers/error.cjs +4 -2
- package/dist/server/handlers/error.cjs.map +1 -0
- package/dist/server/handlers/error.d.ts +2 -1
- package/dist/server/handlers/error.d.ts.map +1 -0
- package/dist/server/handlers/error.js +3 -1
- package/dist/server/handlers/error.js.map +1 -0
- package/dist/server/handlers/legacyWorkflows.cjs +48 -0
- package/dist/server/handlers/legacyWorkflows.cjs.map +1 -0
- package/dist/server/handlers/legacyWorkflows.d.ts +59 -0
- package/dist/server/handlers/legacyWorkflows.d.ts.map +1 -0
- package/dist/server/handlers/legacyWorkflows.js +3 -0
- package/dist/server/handlers/legacyWorkflows.js.map +1 -0
- package/dist/server/handlers/logs.cjs +6 -4
- package/dist/server/handlers/logs.cjs.map +1 -0
- package/dist/server/handlers/logs.d.ts +34 -3
- package/dist/server/handlers/logs.d.ts.map +1 -0
- package/dist/server/handlers/logs.js +3 -1
- package/dist/server/handlers/logs.js.map +1 -0
- package/dist/server/handlers/memory.cjs +35 -9
- package/dist/server/handlers/memory.cjs.map +1 -0
- package/dist/server/handlers/memory.d.ts +113 -8
- package/dist/server/handlers/memory.d.ts.map +1 -0
- package/dist/server/handlers/memory.js +3 -1
- package/dist/server/handlers/memory.js.map +1 -0
- package/dist/server/handlers/network.cjs +7 -5
- package/dist/server/handlers/network.cjs.map +1 -0
- package/dist/server/handlers/network.d.ts +50 -4
- package/dist/server/handlers/network.d.ts.map +1 -0
- package/dist/server/handlers/network.js +3 -1
- package/dist/server/handlers/network.js.map +1 -0
- package/dist/server/handlers/scores.cjs +32 -0
- package/dist/server/handlers/scores.cjs.map +1 -0
- package/dist/server/handlers/scores.d.ts +49 -0
- package/dist/server/handlers/scores.d.ts.map +1 -0
- package/dist/server/handlers/scores.js +3 -0
- package/dist/server/handlers/scores.js.map +1 -0
- package/dist/server/handlers/telemetry.cjs +5 -3
- package/dist/server/handlers/telemetry.cjs.map +1 -0
- package/dist/server/handlers/telemetry.d.ts +32 -2
- package/dist/server/handlers/telemetry.d.ts.map +1 -0
- package/dist/server/handlers/telemetry.js +3 -1
- package/dist/server/handlers/telemetry.js.map +1 -0
- package/dist/server/handlers/tools.cjs +7 -5
- package/dist/server/handlers/tools.cjs.map +1 -0
- package/dist/server/handlers/tools.d.ts +21 -4
- package/dist/server/handlers/tools.d.ts.map +1 -0
- package/dist/server/handlers/tools.js +3 -1
- package/dist/server/handlers/tools.js.map +1 -0
- package/dist/server/handlers/utils.cjs +4 -2
- package/dist/server/handlers/utils.cjs.map +1 -0
- package/dist/server/handlers/utils.d.ts +2 -1
- package/dist/server/handlers/utils.d.ts.map +1 -0
- package/dist/server/handlers/utils.js +3 -1
- package/dist/server/handlers/utils.js.map +1 -0
- package/dist/server/handlers/vNextNetwork.cjs +220 -0
- package/dist/server/handlers/vNextNetwork.cjs.map +1 -0
- package/dist/server/handlers/vNextNetwork.d.ts +179 -0
- package/dist/server/handlers/vNextNetwork.d.ts.map +1 -0
- package/dist/server/handlers/vNextNetwork.js +213 -0
- package/dist/server/handlers/vNextNetwork.js.map +1 -0
- package/dist/server/handlers/vector.cjs +9 -7
- package/dist/server/handlers/vector.cjs.map +1 -0
- package/dist/server/handlers/vector.d.ts +51 -6
- package/dist/server/handlers/vector.d.ts.map +1 -0
- package/dist/server/handlers/vector.js +3 -1
- package/dist/server/handlers/vector.js.map +1 -0
- package/dist/server/handlers/voice.cjs +10 -4
- package/dist/server/handlers/voice.cjs.map +1 -0
- package/dist/server/handlers/voice.d.ts +39 -3
- package/dist/server/handlers/voice.d.ts.map +1 -0
- package/dist/server/handlers/voice.js +3 -1
- package/dist/server/handlers/voice.js.map +1 -0
- package/dist/server/handlers/workflows.cjs +35 -13
- package/dist/server/handlers/workflows.cjs.map +1 -0
- package/dist/server/handlers/workflows.d.ts +88 -10
- package/dist/server/handlers/workflows.d.ts.map +1 -0
- package/dist/server/handlers/workflows.js +3 -1
- package/dist/server/handlers/workflows.js.map +1 -0
- package/dist/server/handlers.cjs +41 -29
- package/dist/server/handlers.cjs.map +1 -0
- package/dist/server/handlers.d.ts +13 -10
- package/dist/server/handlers.d.ts.map +1 -0
- package/dist/server/handlers.js +14 -10
- package/dist/server/handlers.js.map +1 -0
- package/dist/server/http-exception.d.ts +87 -0
- package/dist/server/http-exception.d.ts.map +1 -0
- package/dist/server/types.d.ts +10 -0
- package/dist/server/types.d.ts.map +1 -0
- package/package.json +17 -15
- package/dist/_tsup-dts-rollup.d.cts +0 -648
- package/dist/_tsup-dts-rollup.d.ts +0 -648
- package/dist/chunk-2FJURXCL.cjs +0 -213
- package/dist/chunk-3AHQ5RGN.js +0 -11
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-55HTWX4C.cjs +0 -93
- package/dist/chunk-5SWCVTNL.cjs +0 -5579
- package/dist/chunk-B66WVPGJ.js +0 -297
- package/dist/chunk-FPIWDH5Y.cjs +0 -126
- package/dist/chunk-HCOPJZ4A.cjs +0 -164
- package/dist/chunk-OMN3UI6X.js +0 -5576
- package/dist/chunk-R4J7XQYU.js +0 -156
- package/dist/chunk-RBQASTUP.js +0 -203
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/chunk-TZK63M5N.cjs +0 -317
- package/dist/chunk-ZHNKYTNS.cjs +0 -309
- package/dist/chunk-ZLBRQFDD.cjs +0 -13
- package/dist/index.d.cts +0 -1
- package/dist/server/handlers/agents.d.cts +0 -6
- package/dist/server/handlers/error.d.cts +0 -1
- package/dist/server/handlers/logs.d.cts +0 -3
- package/dist/server/handlers/memory.d.cts +0 -8
- package/dist/server/handlers/network.d.cts +0 -4
- package/dist/server/handlers/telemetry.d.cts +0 -2
- package/dist/server/handlers/tools.d.cts +0 -4
- package/dist/server/handlers/utils.d.cts +0 -1
- package/dist/server/handlers/vNextWorkflows.cjs +0 -46
- package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
- package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
- package/dist/server/handlers/vNextWorkflows.js +0 -1
- package/dist/server/handlers/vector.d.cts +0 -6
- package/dist/server/handlers/voice.d.cts +0 -3
- package/dist/server/handlers/workflows.d.cts +0 -10
- package/dist/server/handlers.d.cts +0 -10
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { validateBody } from './chunk-
|
|
2
|
-
import { handleError } from './chunk-
|
|
3
|
-
import {
|
|
1
|
+
import { validateBody } from './chunk-OW4FX5TS.js';
|
|
2
|
+
import { handleError } from './chunk-CY4TP3FK.js';
|
|
3
|
+
import { HTTPException } from './chunk-MMROOK5J.js';
|
|
4
|
+
import { __export } from './chunk-PZ5AY32C.js';
|
|
4
5
|
import { Readable } from 'stream';
|
|
5
6
|
|
|
6
7
|
// src/server/handlers/voice.ts
|
|
7
8
|
var voice_exports = {};
|
|
8
9
|
__export(voice_exports, {
|
|
9
10
|
generateSpeechHandler: () => generateSpeechHandler,
|
|
11
|
+
getListenerHandler: () => getListenerHandler,
|
|
10
12
|
getSpeakersHandler: () => getSpeakersHandler,
|
|
11
13
|
transcribeSpeechHandler: () => transcribeSpeechHandler
|
|
12
14
|
});
|
|
@@ -19,10 +21,11 @@ async function getSpeakersHandler({ mastra, agentId }) {
|
|
|
19
21
|
if (!agent) {
|
|
20
22
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
21
23
|
}
|
|
22
|
-
|
|
24
|
+
const voice = await agent.getVoice();
|
|
25
|
+
if (!voice) {
|
|
23
26
|
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
24
27
|
}
|
|
25
|
-
const speakers = await
|
|
28
|
+
const speakers = await voice.getSpeakers();
|
|
26
29
|
return speakers;
|
|
27
30
|
} catch (error) {
|
|
28
31
|
return handleError(error, "Error getting speakers");
|
|
@@ -44,10 +47,11 @@ async function generateSpeechHandler({
|
|
|
44
47
|
if (!agent) {
|
|
45
48
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
46
49
|
}
|
|
47
|
-
|
|
50
|
+
const voice = await agent.getVoice();
|
|
51
|
+
if (!voice) {
|
|
48
52
|
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
49
53
|
}
|
|
50
|
-
const audioStream = await
|
|
54
|
+
const audioStream = await voice.speak(body.text, { speaker: body.speakerId });
|
|
51
55
|
if (!audioStream) {
|
|
52
56
|
throw new HTTPException(500, { message: "Failed to generate speech" });
|
|
53
57
|
}
|
|
@@ -72,17 +76,39 @@ async function transcribeSpeechHandler({
|
|
|
72
76
|
if (!agent) {
|
|
73
77
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
74
78
|
}
|
|
75
|
-
|
|
79
|
+
const voice = await agent.getVoice();
|
|
80
|
+
if (!voice) {
|
|
76
81
|
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
77
82
|
}
|
|
78
83
|
const audioStream = new Readable();
|
|
79
84
|
audioStream.push(body.audioData);
|
|
80
85
|
audioStream.push(null);
|
|
81
|
-
const text = await
|
|
86
|
+
const text = await voice.listen(audioStream, body.options);
|
|
82
87
|
return { text };
|
|
83
88
|
} catch (error) {
|
|
84
89
|
return handleError(error, "Error transcribing speech");
|
|
85
90
|
}
|
|
86
91
|
}
|
|
92
|
+
async function getListenerHandler({ mastra, agentId }) {
|
|
93
|
+
try {
|
|
94
|
+
if (!agentId) {
|
|
95
|
+
throw new HTTPException(400, { message: "Agent ID is required" });
|
|
96
|
+
}
|
|
97
|
+
const agent = mastra.getAgent(agentId);
|
|
98
|
+
if (!agent) {
|
|
99
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
100
|
+
}
|
|
101
|
+
const voice = await agent.getVoice();
|
|
102
|
+
if (!voice) {
|
|
103
|
+
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
104
|
+
}
|
|
105
|
+
const listeners = await voice.getListener();
|
|
106
|
+
return listeners;
|
|
107
|
+
} catch (error) {
|
|
108
|
+
return handleError(error, "Error getting listeners");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
87
111
|
|
|
88
|
-
export { generateSpeechHandler, getSpeakersHandler, transcribeSpeechHandler, voice_exports };
|
|
112
|
+
export { generateSpeechHandler, getListenerHandler, getSpeakersHandler, transcribeSpeechHandler, voice_exports };
|
|
113
|
+
//# sourceMappingURL=chunk-HWHKM67I.js.map
|
|
114
|
+
//# sourceMappingURL=chunk-HWHKM67I.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/voice.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,aAAA,GAAA;AAAA,QAAA,CAAA,aAAA,EAAA;AAAA,E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0CAA0C,CAAA;AAAA,IACpF;AAEA,IAAA,MAAM,SAAA,GAAY,MAAM,KAAA,CAAM,WAAA,EAAY;AAC1C,IAAA,OAAO,SAAA;AAAA,EACT,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,yBAAyB,CAAA;AAAA,EACrD;AACF","file":"chunk-HWHKM67I.js","sourcesContent":["import { Readable } from 'stream';\nimport type { Agent } from '@mastra/core/agent';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\n\nimport { handleError } from './error';\nimport { validateBody } from './utils';\n\ninterface VoiceContext extends Context {\n agentId?: string;\n}\n\n/**\n * Get available speakers for an agent\n */\nexport async function getSpeakersHandler({ mastra, agentId }: VoiceContext) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice();\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const speakers = await voice.getSpeakers();\n return speakers;\n } catch (error) {\n return handleError(error, 'Error getting speakers');\n }\n}\n\n/**\n * Generate speech from text\n */\nexport async function generateSpeechHandler({\n mastra,\n agentId,\n body,\n}: VoiceContext & {\n body?: {\n text?: string;\n speakerId?: string;\n };\n}) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n validateBody({\n text: body?.text,\n });\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice();\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const audioStream = await voice.speak(body!.text!, { speaker: body!.speakerId! });\n\n if (!audioStream) {\n throw new HTTPException(500, { message: 'Failed to generate speech' });\n }\n\n return audioStream;\n } catch (error) {\n return handleError(error, 'Error generating speech');\n }\n}\n\n/**\n * Transcribe speech to text\n */\nexport async function transcribeSpeechHandler({\n mastra,\n agentId,\n body,\n}: VoiceContext & {\n body?: {\n audioData?: Buffer;\n options?: Parameters<NonNullable<Agent['voice']>['listen']>[1];\n };\n}) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n if (!body?.audioData) {\n throw new HTTPException(400, { message: 'Audio data is required' });\n }\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice();\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const audioStream = new Readable();\n audioStream.push(body.audioData);\n audioStream.push(null);\n\n const text = await voice.listen(audioStream, body.options);\n return { text };\n } catch (error) {\n return handleError(error, 'Error transcribing speech');\n }\n}\n\n/**\n * Get available listeners for an agent\n */\nexport async function getListenerHandler({ mastra, agentId }: VoiceContext) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice();\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const listeners = await voice.getListener();\n return listeners;\n } catch (error) {\n return handleError(error, 'Error getting listeners');\n }\n}\n"]}
|
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
import { validateBody } from './chunk-OW4FX5TS.js';
|
|
2
|
+
import { handleError } from './chunk-CY4TP3FK.js';
|
|
3
|
+
import { HTTPException } from './chunk-MMROOK5J.js';
|
|
4
|
+
import { __export } from './chunk-PZ5AY32C.js';
|
|
5
|
+
import { generateEmptyFromSchema } from '@mastra/core';
|
|
6
|
+
|
|
7
|
+
// src/server/handlers/memory.ts
|
|
8
|
+
var memory_exports = {};
|
|
9
|
+
__export(memory_exports, {
|
|
10
|
+
createThreadHandler: () => createThreadHandler,
|
|
11
|
+
deleteMessagesHandler: () => deleteMessagesHandler,
|
|
12
|
+
deleteThreadHandler: () => deleteThreadHandler,
|
|
13
|
+
getMemoryConfigHandler: () => getMemoryConfigHandler,
|
|
14
|
+
getMemoryStatusHandler: () => getMemoryStatusHandler,
|
|
15
|
+
getMessagesHandler: () => getMessagesHandler,
|
|
16
|
+
getMessagesPaginatedHandler: () => getMessagesPaginatedHandler,
|
|
17
|
+
getThreadByIdHandler: () => getThreadByIdHandler,
|
|
18
|
+
getThreadsHandler: () => getThreadsHandler,
|
|
19
|
+
getWorkingMemoryHandler: () => getWorkingMemoryHandler,
|
|
20
|
+
saveMessagesHandler: () => saveMessagesHandler,
|
|
21
|
+
searchMemoryHandler: () => searchMemoryHandler,
|
|
22
|
+
updateThreadHandler: () => updateThreadHandler,
|
|
23
|
+
updateWorkingMemoryHandler: () => updateWorkingMemoryHandler
|
|
24
|
+
});
|
|
25
|
+
async function getMemoryFromContext({
|
|
26
|
+
mastra,
|
|
27
|
+
agentId,
|
|
28
|
+
networkId,
|
|
29
|
+
runtimeContext
|
|
30
|
+
}) {
|
|
31
|
+
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
32
|
+
if (agentId && !agent) {
|
|
33
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
34
|
+
}
|
|
35
|
+
const network = networkId ? mastra.vnext_getNetwork(networkId) : null;
|
|
36
|
+
if (networkId && !network) {
|
|
37
|
+
throw new HTTPException(404, { message: "Network not found" });
|
|
38
|
+
}
|
|
39
|
+
if (agent) {
|
|
40
|
+
return await agent?.getMemory() || mastra.getMemory();
|
|
41
|
+
}
|
|
42
|
+
if (network) {
|
|
43
|
+
return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
|
|
44
|
+
}
|
|
45
|
+
return mastra.getMemory();
|
|
46
|
+
}
|
|
47
|
+
async function getMemoryStatusHandler({
|
|
48
|
+
mastra,
|
|
49
|
+
agentId,
|
|
50
|
+
networkId,
|
|
51
|
+
runtimeContext
|
|
52
|
+
}) {
|
|
53
|
+
try {
|
|
54
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
55
|
+
if (!memory) {
|
|
56
|
+
return { result: false };
|
|
57
|
+
}
|
|
58
|
+
return { result: true };
|
|
59
|
+
} catch (error) {
|
|
60
|
+
return handleError(error, "Error getting memory status");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function getMemoryConfigHandler({
|
|
64
|
+
mastra,
|
|
65
|
+
agentId,
|
|
66
|
+
networkId,
|
|
67
|
+
runtimeContext
|
|
68
|
+
}) {
|
|
69
|
+
try {
|
|
70
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
71
|
+
if (!memory) {
|
|
72
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
73
|
+
}
|
|
74
|
+
const config = memory.getMergedThreadConfig({});
|
|
75
|
+
return { config };
|
|
76
|
+
} catch (error) {
|
|
77
|
+
return handleError(error, "Error getting memory configuration");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function getThreadsHandler({
|
|
81
|
+
mastra,
|
|
82
|
+
agentId,
|
|
83
|
+
resourceId,
|
|
84
|
+
networkId,
|
|
85
|
+
runtimeContext,
|
|
86
|
+
orderBy,
|
|
87
|
+
sortDirection
|
|
88
|
+
}) {
|
|
89
|
+
try {
|
|
90
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
91
|
+
if (!memory) {
|
|
92
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
93
|
+
}
|
|
94
|
+
validateBody({ resourceId });
|
|
95
|
+
const threads = await memory.getThreadsByResourceId({
|
|
96
|
+
resourceId,
|
|
97
|
+
orderBy,
|
|
98
|
+
sortDirection
|
|
99
|
+
});
|
|
100
|
+
return threads;
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return handleError(error, "Error getting threads");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async function getThreadByIdHandler({
|
|
106
|
+
mastra,
|
|
107
|
+
agentId,
|
|
108
|
+
threadId,
|
|
109
|
+
networkId,
|
|
110
|
+
runtimeContext
|
|
111
|
+
}) {
|
|
112
|
+
try {
|
|
113
|
+
validateBody({ threadId });
|
|
114
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
115
|
+
if (!memory) {
|
|
116
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
117
|
+
}
|
|
118
|
+
const thread = await memory.getThreadById({ threadId });
|
|
119
|
+
if (!thread) {
|
|
120
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
121
|
+
}
|
|
122
|
+
return thread;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
return handleError(error, "Error getting thread");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async function saveMessagesHandler({
|
|
128
|
+
mastra,
|
|
129
|
+
agentId,
|
|
130
|
+
body,
|
|
131
|
+
networkId,
|
|
132
|
+
runtimeContext
|
|
133
|
+
}) {
|
|
134
|
+
try {
|
|
135
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
136
|
+
if (!memory) {
|
|
137
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
138
|
+
}
|
|
139
|
+
if (!body?.messages) {
|
|
140
|
+
throw new HTTPException(400, { message: "Messages are required" });
|
|
141
|
+
}
|
|
142
|
+
if (!Array.isArray(body.messages)) {
|
|
143
|
+
throw new HTTPException(400, { message: "Messages should be an array" });
|
|
144
|
+
}
|
|
145
|
+
const invalidMessages = body.messages.filter((message) => !message.threadId || !message.resourceId);
|
|
146
|
+
if (invalidMessages.length > 0) {
|
|
147
|
+
throw new HTTPException(400, {
|
|
148
|
+
message: `All messages must have threadId and resourceId fields. Found ${invalidMessages.length} invalid message(s).`
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
const processedMessages = body.messages.map((message) => ({
|
|
152
|
+
...message,
|
|
153
|
+
id: message.id || memory.generateId(),
|
|
154
|
+
createdAt: message.createdAt ? new Date(message.createdAt) : /* @__PURE__ */ new Date()
|
|
155
|
+
}));
|
|
156
|
+
const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
|
|
157
|
+
return result;
|
|
158
|
+
} catch (error) {
|
|
159
|
+
return handleError(error, "Error saving messages");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async function createThreadHandler({
|
|
163
|
+
mastra,
|
|
164
|
+
agentId,
|
|
165
|
+
body,
|
|
166
|
+
networkId,
|
|
167
|
+
runtimeContext
|
|
168
|
+
}) {
|
|
169
|
+
try {
|
|
170
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
171
|
+
if (!memory) {
|
|
172
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
173
|
+
}
|
|
174
|
+
validateBody({ resourceId: body?.resourceId });
|
|
175
|
+
const result = await memory.createThread({
|
|
176
|
+
resourceId: body?.resourceId,
|
|
177
|
+
title: body?.title,
|
|
178
|
+
metadata: body?.metadata,
|
|
179
|
+
threadId: body?.threadId
|
|
180
|
+
});
|
|
181
|
+
return result;
|
|
182
|
+
} catch (error) {
|
|
183
|
+
return handleError(error, "Error saving thread to memory");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async function updateThreadHandler({
|
|
187
|
+
mastra,
|
|
188
|
+
agentId,
|
|
189
|
+
threadId,
|
|
190
|
+
body,
|
|
191
|
+
networkId,
|
|
192
|
+
runtimeContext
|
|
193
|
+
}) {
|
|
194
|
+
try {
|
|
195
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
196
|
+
if (!body) {
|
|
197
|
+
throw new HTTPException(400, { message: "Body is required" });
|
|
198
|
+
}
|
|
199
|
+
const { title, metadata, resourceId } = body;
|
|
200
|
+
const updatedAt = /* @__PURE__ */ new Date();
|
|
201
|
+
validateBody({ threadId });
|
|
202
|
+
if (!memory) {
|
|
203
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
204
|
+
}
|
|
205
|
+
const thread = await memory.getThreadById({ threadId });
|
|
206
|
+
if (!thread) {
|
|
207
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
208
|
+
}
|
|
209
|
+
const updatedThread = {
|
|
210
|
+
...thread,
|
|
211
|
+
title: title || thread.title,
|
|
212
|
+
metadata: metadata || thread.metadata,
|
|
213
|
+
resourceId: resourceId || thread.resourceId,
|
|
214
|
+
createdAt: thread.createdAt,
|
|
215
|
+
updatedAt
|
|
216
|
+
};
|
|
217
|
+
const result = await memory.saveThread({ thread: updatedThread });
|
|
218
|
+
return result;
|
|
219
|
+
} catch (error) {
|
|
220
|
+
return handleError(error, "Error updating thread");
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
async function deleteThreadHandler({
|
|
224
|
+
mastra,
|
|
225
|
+
agentId,
|
|
226
|
+
threadId,
|
|
227
|
+
networkId,
|
|
228
|
+
runtimeContext
|
|
229
|
+
}) {
|
|
230
|
+
try {
|
|
231
|
+
validateBody({ threadId });
|
|
232
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
233
|
+
if (!memory) {
|
|
234
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
235
|
+
}
|
|
236
|
+
const thread = await memory.getThreadById({ threadId });
|
|
237
|
+
if (!thread) {
|
|
238
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
239
|
+
}
|
|
240
|
+
await memory.deleteThread(threadId);
|
|
241
|
+
return { result: "Thread deleted" };
|
|
242
|
+
} catch (error) {
|
|
243
|
+
return handleError(error, "Error deleting thread");
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async function getMessagesPaginatedHandler({
|
|
247
|
+
mastra,
|
|
248
|
+
threadId,
|
|
249
|
+
resourceId,
|
|
250
|
+
selectBy,
|
|
251
|
+
format
|
|
252
|
+
}) {
|
|
253
|
+
try {
|
|
254
|
+
validateBody({ threadId });
|
|
255
|
+
const storage = mastra.getStorage();
|
|
256
|
+
if (!storage) {
|
|
257
|
+
throw new HTTPException(400, { message: "Storage is not initialized" });
|
|
258
|
+
}
|
|
259
|
+
const thread = await storage.getThreadById({ threadId });
|
|
260
|
+
if (!thread) {
|
|
261
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
262
|
+
}
|
|
263
|
+
const result = await storage.getMessagesPaginated({ threadId, resourceId, selectBy, format });
|
|
264
|
+
return result;
|
|
265
|
+
} catch (error) {
|
|
266
|
+
return handleError(error, "Error getting messages");
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async function getMessagesHandler({
|
|
270
|
+
mastra,
|
|
271
|
+
agentId,
|
|
272
|
+
threadId,
|
|
273
|
+
limit,
|
|
274
|
+
networkId,
|
|
275
|
+
runtimeContext
|
|
276
|
+
}) {
|
|
277
|
+
if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
|
|
278
|
+
throw new HTTPException(400, { message: "Invalid limit: must be a positive integer" });
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
validateBody({ threadId });
|
|
282
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
283
|
+
if (!memory) {
|
|
284
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
285
|
+
}
|
|
286
|
+
const thread = await memory.getThreadById({ threadId });
|
|
287
|
+
if (!thread) {
|
|
288
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
289
|
+
}
|
|
290
|
+
const result = await memory.query({
|
|
291
|
+
threadId,
|
|
292
|
+
...limit && { selectBy: { last: limit } }
|
|
293
|
+
});
|
|
294
|
+
return { messages: result.messages, uiMessages: result.uiMessages };
|
|
295
|
+
} catch (error) {
|
|
296
|
+
return handleError(error, "Error getting messages");
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
async function getWorkingMemoryHandler({
|
|
300
|
+
mastra,
|
|
301
|
+
agentId,
|
|
302
|
+
threadId,
|
|
303
|
+
resourceId,
|
|
304
|
+
networkId,
|
|
305
|
+
runtimeContext,
|
|
306
|
+
memoryConfig
|
|
307
|
+
}) {
|
|
308
|
+
try {
|
|
309
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
310
|
+
validateBody({ threadId });
|
|
311
|
+
if (!memory) {
|
|
312
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
313
|
+
}
|
|
314
|
+
const thread = await memory.getThreadById({ threadId });
|
|
315
|
+
const threadExists = !!thread;
|
|
316
|
+
const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
|
|
317
|
+
const workingMemoryTemplate = template?.format === "json" ? { ...template, content: JSON.stringify(generateEmptyFromSchema(template.content)) } : template;
|
|
318
|
+
const workingMemory = await memory.getWorkingMemory({ threadId, resourceId, memoryConfig });
|
|
319
|
+
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
320
|
+
const source = config.workingMemory?.scope === "resource" && resourceId ? "resource" : "thread";
|
|
321
|
+
return { workingMemory, source, workingMemoryTemplate, threadExists };
|
|
322
|
+
} catch (error) {
|
|
323
|
+
return handleError(error, "Error getting working memory");
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
async function updateWorkingMemoryHandler({
|
|
327
|
+
mastra,
|
|
328
|
+
agentId,
|
|
329
|
+
threadId,
|
|
330
|
+
body,
|
|
331
|
+
networkId,
|
|
332
|
+
runtimeContext
|
|
333
|
+
}) {
|
|
334
|
+
try {
|
|
335
|
+
validateBody({ threadId });
|
|
336
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
337
|
+
const { resourceId, memoryConfig, workingMemory } = body;
|
|
338
|
+
if (!memory) {
|
|
339
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
340
|
+
}
|
|
341
|
+
const thread = await memory.getThreadById({ threadId });
|
|
342
|
+
if (!thread) {
|
|
343
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
344
|
+
}
|
|
345
|
+
await memory.updateWorkingMemory({ threadId, resourceId, workingMemory, memoryConfig });
|
|
346
|
+
return { success: true };
|
|
347
|
+
} catch (error) {
|
|
348
|
+
return handleError(error, "Error updating working memory");
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async function deleteMessagesHandler({
|
|
352
|
+
mastra,
|
|
353
|
+
agentId,
|
|
354
|
+
messageIds,
|
|
355
|
+
networkId,
|
|
356
|
+
runtimeContext
|
|
357
|
+
}) {
|
|
358
|
+
try {
|
|
359
|
+
if (messageIds === void 0 || messageIds === null) {
|
|
360
|
+
throw new HTTPException(400, { message: "messageIds is required" });
|
|
361
|
+
}
|
|
362
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
363
|
+
if (!memory) {
|
|
364
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
365
|
+
}
|
|
366
|
+
await memory.deleteMessages(messageIds);
|
|
367
|
+
let count = 1;
|
|
368
|
+
if (Array.isArray(messageIds)) {
|
|
369
|
+
count = messageIds.length;
|
|
370
|
+
}
|
|
371
|
+
return { success: true, message: `${count} message${count === 1 ? "" : "s"} deleted successfully` };
|
|
372
|
+
} catch (error) {
|
|
373
|
+
return handleError(error, "Error deleting messages");
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
async function searchMemoryHandler({
|
|
377
|
+
mastra,
|
|
378
|
+
agentId,
|
|
379
|
+
searchQuery,
|
|
380
|
+
resourceId,
|
|
381
|
+
threadId,
|
|
382
|
+
limit = 20,
|
|
383
|
+
networkId,
|
|
384
|
+
runtimeContext,
|
|
385
|
+
memoryConfig
|
|
386
|
+
}) {
|
|
387
|
+
try {
|
|
388
|
+
validateBody({ searchQuery, resourceId });
|
|
389
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
390
|
+
if (!memory) {
|
|
391
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
392
|
+
}
|
|
393
|
+
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
394
|
+
const hasSemanticRecall = !!config?.semanticRecall;
|
|
395
|
+
const resourceScope = typeof config?.semanticRecall === "object" && config?.semanticRecall?.scope === "resource";
|
|
396
|
+
if (threadId && !resourceScope) {
|
|
397
|
+
const thread = await memory.getThreadById({ threadId });
|
|
398
|
+
if (!thread) {
|
|
399
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
400
|
+
}
|
|
401
|
+
if (thread.resourceId !== resourceId) {
|
|
402
|
+
throw new HTTPException(403, { message: "Thread does not belong to the specified resource" });
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
const searchResults = [];
|
|
406
|
+
const messageMap = /* @__PURE__ */ new Map();
|
|
407
|
+
if (threadId && !resourceScope) {
|
|
408
|
+
const thread = await memory.getThreadById({ threadId });
|
|
409
|
+
if (!thread) {
|
|
410
|
+
return {
|
|
411
|
+
results: [],
|
|
412
|
+
count: 0,
|
|
413
|
+
query: searchQuery,
|
|
414
|
+
searchScope: "thread",
|
|
415
|
+
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (!threadId || resourceScope) {
|
|
420
|
+
const threads = await memory.getThreadsByResourceId({ resourceId });
|
|
421
|
+
if (threads.length === 0) {
|
|
422
|
+
return {
|
|
423
|
+
results: [],
|
|
424
|
+
count: 0,
|
|
425
|
+
query: searchQuery,
|
|
426
|
+
searchScope: "resource",
|
|
427
|
+
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
for (const thread of threads) {
|
|
431
|
+
const result = await memory.rememberMessages({
|
|
432
|
+
threadId: thread.id,
|
|
433
|
+
resourceId,
|
|
434
|
+
vectorMessageSearch: searchQuery,
|
|
435
|
+
config
|
|
436
|
+
});
|
|
437
|
+
const threadMessages = (await memory.query({ threadId: thread.id })).uiMessages;
|
|
438
|
+
result.messagesV2.forEach((msg) => {
|
|
439
|
+
if (messageMap.has(msg.id)) return;
|
|
440
|
+
messageMap.set(msg.id, true);
|
|
441
|
+
const content = msg.content.content || msg.content.parts?.map((p) => p.type === "text" ? p.text : "").join(" ") || "";
|
|
442
|
+
if (!hasSemanticRecall && !content.toLowerCase().includes(searchQuery.toLowerCase())) {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const messageIndex = threadMessages.findIndex((m) => m.id === msg.id);
|
|
446
|
+
const searchResult = {
|
|
447
|
+
id: msg.id,
|
|
448
|
+
role: msg.role,
|
|
449
|
+
content,
|
|
450
|
+
createdAt: msg.createdAt,
|
|
451
|
+
threadId: msg.threadId || thread.id,
|
|
452
|
+
threadTitle: thread.title || msg.threadId || thread.id
|
|
453
|
+
};
|
|
454
|
+
if (messageIndex !== -1) {
|
|
455
|
+
searchResult.context = {
|
|
456
|
+
before: threadMessages.slice(Math.max(0, messageIndex - 2), messageIndex).map((m) => ({
|
|
457
|
+
id: m.id,
|
|
458
|
+
role: m.role,
|
|
459
|
+
content: m.content,
|
|
460
|
+
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
461
|
+
})),
|
|
462
|
+
after: threadMessages.slice(messageIndex + 1, messageIndex + 3).map((m) => ({
|
|
463
|
+
id: m.id,
|
|
464
|
+
role: m.role,
|
|
465
|
+
content: m.content,
|
|
466
|
+
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
467
|
+
}))
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
searchResults.push(searchResult);
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
} else if (threadId) {
|
|
474
|
+
const thread = await memory.getThreadById({ threadId });
|
|
475
|
+
if (!thread) {
|
|
476
|
+
return {
|
|
477
|
+
results: [],
|
|
478
|
+
count: 0,
|
|
479
|
+
query: searchQuery,
|
|
480
|
+
searchScope: "thread",
|
|
481
|
+
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
const result = await memory.rememberMessages({
|
|
485
|
+
threadId,
|
|
486
|
+
resourceId,
|
|
487
|
+
vectorMessageSearch: searchQuery,
|
|
488
|
+
config
|
|
489
|
+
});
|
|
490
|
+
const threadMessages = (await memory.query({ threadId })).uiMessages;
|
|
491
|
+
result.messagesV2.forEach((msg) => {
|
|
492
|
+
if (messageMap.has(msg.id)) return;
|
|
493
|
+
messageMap.set(msg.id, true);
|
|
494
|
+
const content = msg.content.content || msg.content.parts?.map((p) => p.type === "text" ? p.text : "").join(" ") || "";
|
|
495
|
+
if (!hasSemanticRecall && !content.toLowerCase().includes(searchQuery.toLowerCase())) {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
const messageIndex = threadMessages.findIndex((m) => m.id === msg.id);
|
|
499
|
+
const searchResult = {
|
|
500
|
+
id: msg.id,
|
|
501
|
+
role: msg.role,
|
|
502
|
+
content,
|
|
503
|
+
createdAt: msg.createdAt,
|
|
504
|
+
threadId,
|
|
505
|
+
threadTitle: thread?.title || threadId
|
|
506
|
+
};
|
|
507
|
+
if (messageIndex !== -1) {
|
|
508
|
+
searchResult.context = {
|
|
509
|
+
before: threadMessages.slice(Math.max(0, messageIndex - 2), messageIndex).map((m) => ({
|
|
510
|
+
id: m.id,
|
|
511
|
+
role: m.role,
|
|
512
|
+
content: m.content,
|
|
513
|
+
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
514
|
+
})),
|
|
515
|
+
after: threadMessages.slice(messageIndex + 1, messageIndex + 3).map((m) => ({
|
|
516
|
+
id: m.id,
|
|
517
|
+
role: m.role,
|
|
518
|
+
content: m.content,
|
|
519
|
+
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
520
|
+
}))
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
searchResults.push(searchResult);
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
const sortedResults = searchResults.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()).slice(0, limit);
|
|
527
|
+
return {
|
|
528
|
+
results: sortedResults,
|
|
529
|
+
count: sortedResults.length,
|
|
530
|
+
query: searchQuery,
|
|
531
|
+
searchScope: resourceScope ? "resource" : "thread",
|
|
532
|
+
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
533
|
+
};
|
|
534
|
+
} catch (error) {
|
|
535
|
+
return handleError(error, "Error searching memory");
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
export { createThreadHandler, deleteMessagesHandler, deleteThreadHandler, getMemoryConfigHandler, getMemoryStatusHandler, getMessagesHandler, getMessagesPaginatedHandler, getThreadByIdHandler, getThreadsHandler, getWorkingMemoryHandler, memory_exports, saveMessagesHandler, searchMemoryHandler, updateThreadHandler, updateWorkingMemoryHandler };
|
|
540
|
+
//# sourceMappingURL=chunk-HXIOPAHT.js.map
|
|
541
|
+
//# sourceMappingURL=chunk-HXIOPAHT.js.map
|