@mastra/server 0.0.0-declaration-maps-20250730185206 → 0.0.0-dynamic-model-router-20251009204130
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/CHANGELOG.md +3969 -0
- package/README.md +0 -5
- package/dist/chunk-2PLXW4ZX.cjs +2777 -0
- package/dist/chunk-2PLXW4ZX.cjs.map +1 -0
- package/dist/chunk-2S4IMB6E.cjs +130 -0
- package/dist/chunk-2S4IMB6E.cjs.map +1 -0
- package/dist/chunk-3Q7FKRVX.cjs +682 -0
- package/dist/chunk-3Q7FKRVX.cjs.map +1 -0
- package/dist/{chunk-4US5W7PH.cjs → chunk-3SNGNFUJ.cjs} +23 -15
- package/dist/chunk-3SNGNFUJ.cjs.map +1 -0
- package/dist/{chunk-OW4FX5TS.js → chunk-4QCXUEAT.js} +10 -3
- package/dist/chunk-4QCXUEAT.js.map +1 -0
- package/dist/{chunk-TXAQU2XN.js → chunk-5BNQIYQN.js} +60 -22
- package/dist/chunk-5BNQIYQN.js.map +1 -0
- package/dist/{chunk-SQ7KKIH3.js → chunk-67GYDFSB.js} +22 -5
- package/dist/chunk-67GYDFSB.js.map +1 -0
- package/dist/{chunk-ILCWPBYQ.cjs → chunk-6ZR275MD.cjs} +23 -5
- package/dist/chunk-6ZR275MD.cjs.map +1 -0
- package/dist/{chunk-4MQU6AJN.js → chunk-ABRFV4XP.js} +4 -4
- package/dist/{chunk-4MQU6AJN.js.map → chunk-ABRFV4XP.js.map} +1 -1
- package/dist/{chunk-YS66MFDY.js → chunk-AHB4JCIQ.js} +48 -12
- package/dist/chunk-AHB4JCIQ.js.map +1 -0
- package/dist/chunk-BATEJLED.js +124 -0
- package/dist/chunk-BATEJLED.js.map +1 -0
- package/dist/{chunk-BUOJL3MN.js → chunk-DB63UMTV.js} +220 -89
- package/dist/chunk-DB63UMTV.js.map +1 -0
- package/dist/{chunk-NCS2OXX6.cjs → chunk-EP3JQDPD.cjs} +4 -4
- package/dist/{chunk-NCS2OXX6.cjs.map → chunk-EP3JQDPD.cjs.map} +1 -1
- package/dist/chunk-FZNS32WJ.js +46 -0
- package/dist/chunk-FZNS32WJ.js.map +1 -0
- package/dist/{chunk-4QSNRCOT.cjs → chunk-G4PUALCE.cjs} +10 -2
- package/dist/chunk-G4PUALCE.cjs.map +1 -0
- package/dist/chunk-GU4EWMZB.cjs +769 -0
- package/dist/chunk-GU4EWMZB.cjs.map +1 -0
- package/dist/chunk-HKW2536J.js +17477 -0
- package/dist/chunk-HKW2536J.js.map +1 -0
- package/dist/{chunk-TRWPUPGD.js → chunk-HPXAM2PG.js} +109 -138
- package/dist/chunk-HPXAM2PG.js.map +1 -0
- package/dist/{chunk-JGVY3KWV.cjs → chunk-I3C4ODGV.cjs} +12 -11
- package/dist/chunk-I3C4ODGV.cjs.map +1 -0
- package/dist/chunk-KJJA7GPJ.cjs +17513 -0
- package/dist/chunk-KJJA7GPJ.cjs.map +1 -0
- package/dist/chunk-LF2ZLOFP.js +767 -0
- package/dist/chunk-LF2ZLOFP.js.map +1 -0
- package/dist/{chunk-UVOSITKU.js → chunk-LLUOPR3J.js} +11 -10
- package/dist/chunk-LLUOPR3J.js.map +1 -0
- package/dist/{chunk-VIGPWTDA.cjs → chunk-LNT5N7XW.cjs} +61 -23
- package/dist/chunk-LNT5N7XW.cjs.map +1 -0
- package/dist/chunk-LPM6BBAX.cjs +1043 -0
- package/dist/chunk-LPM6BBAX.cjs.map +1 -0
- package/dist/chunk-LV66LYKV.js +662 -0
- package/dist/chunk-LV66LYKV.js.map +1 -0
- package/dist/{chunk-S37KCGOR.cjs → chunk-MQDBNHBT.cjs} +222 -88
- package/dist/chunk-MQDBNHBT.cjs.map +1 -0
- package/dist/{chunk-G7NVCO5M.js → chunk-MYR4PVGN.js} +3 -3
- package/dist/{chunk-G7NVCO5M.js.map → chunk-MYR4PVGN.js.map} +1 -1
- package/dist/chunk-O7I5CWRX.cjs +44 -0
- package/dist/{chunk-Q7SFCCGT.cjs.map → chunk-O7I5CWRX.cjs.map} +1 -1
- package/dist/chunk-OYL5TBJW.cjs +48 -0
- package/dist/chunk-OYL5TBJW.cjs.map +1 -0
- package/dist/chunk-PR4QN5HX.js +39 -0
- package/dist/{chunk-PZ5AY32C.js.map → chunk-PR4QN5HX.js.map} +1 -1
- package/dist/{chunk-HWHKM67I.js → chunk-QQXMIP6C.js} +21 -13
- package/dist/chunk-QQXMIP6C.js.map +1 -0
- package/dist/chunk-RQK4FQUD.js +1012 -0
- package/dist/chunk-RQK4FQUD.js.map +1 -0
- package/dist/chunk-SIW6CYO3.js +254 -0
- package/dist/chunk-SIW6CYO3.js.map +1 -0
- package/dist/{chunk-GASWM5HJ.cjs → chunk-TOP25AIO.cjs} +110 -139
- package/dist/chunk-TOP25AIO.cjs.map +1 -0
- package/dist/{chunk-O4I563YW.cjs → chunk-TRGAMKHX.cjs} +50 -13
- package/dist/chunk-TRGAMKHX.cjs.map +1 -0
- package/dist/chunk-VY4ENABS.cjs +135 -0
- package/dist/chunk-VY4ENABS.cjs.map +1 -0
- package/dist/{chunk-HXIOPAHT.js → chunk-WHABYJRY.js} +51 -41
- package/dist/chunk-WHABYJRY.js.map +1 -0
- package/dist/{chunk-BED2O446.cjs → chunk-XN74I6VW.cjs} +7 -7
- package/dist/{chunk-BED2O446.cjs.map → chunk-XN74I6VW.cjs.map} +1 -1
- package/dist/chunk-XVPBGW6Y.cjs +256 -0
- package/dist/chunk-XVPBGW6Y.cjs.map +1 -0
- package/dist/{chunk-X5SDJOY6.cjs → chunk-YJU744I4.cjs} +63 -52
- package/dist/chunk-YJU744I4.cjs.map +1 -0
- package/dist/chunk-YWOK4F5A.js +131 -0
- package/dist/chunk-YWOK4F5A.js.map +1 -0
- package/dist/chunk-ZULZ2752.js +2774 -0
- package/dist/chunk-ZULZ2752.js.map +1 -0
- package/dist/dist-4MVGNSRL.cjs +1150 -0
- package/dist/dist-4MVGNSRL.cjs.map +1 -0
- package/dist/dist-FZYCV3VB.cjs +940 -0
- package/dist/dist-FZYCV3VB.cjs.map +1 -0
- package/dist/dist-G2BYZJOC.cjs +928 -0
- package/dist/dist-G2BYZJOC.cjs.map +1 -0
- package/dist/dist-P4MXBQ3U.cjs +16 -0
- package/dist/dist-P4MXBQ3U.cjs.map +1 -0
- package/dist/dist-PQZUVLPC.js +937 -0
- package/dist/dist-PQZUVLPC.js.map +1 -0
- package/dist/dist-R7WYX6LC.js +925 -0
- package/dist/dist-R7WYX6LC.js.map +1 -0
- package/dist/dist-RFMYFILX.cjs +764 -0
- package/dist/dist-RFMYFILX.cjs.map +1 -0
- package/dist/dist-X7XR3M3Z.js +1147 -0
- package/dist/dist-X7XR3M3Z.js.map +1 -0
- package/dist/dist-XVBSOGFK.js +761 -0
- package/dist/dist-XVBSOGFK.js.map +1 -0
- package/dist/dist-YREX2TJT.js +3 -0
- package/dist/dist-YREX2TJT.js.map +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/server/a2a/store.cjs +25 -0
- package/dist/server/a2a/store.cjs.map +1 -0
- package/dist/server/a2a/store.d.ts +3 -3
- package/dist/server/a2a/store.d.ts.map +1 -1
- package/dist/server/a2a/store.js +23 -0
- package/dist/server/a2a/store.js.map +1 -0
- package/dist/server/a2a/tasks.d.ts +7 -7
- package/dist/server/a2a/tasks.d.ts.map +1 -1
- package/dist/server/handlers/a2a.cjs +11 -11
- package/dist/server/handlers/a2a.d.ts +17 -15
- package/dist/server/handlers/a2a.d.ts.map +1 -1
- package/dist/server/handlers/a2a.js +1 -1
- package/dist/server/handlers/agent-builder.cjs +68 -0
- package/dist/server/handlers/agent-builder.cjs.map +1 -0
- package/dist/server/handlers/agent-builder.d.ts +94 -0
- package/dist/server/handlers/agent-builder.d.ts.map +1 -0
- package/dist/server/handlers/agent-builder.js +3 -0
- package/dist/server/handlers/agent-builder.js.map +1 -0
- package/dist/server/handlers/agents.cjs +53 -9
- package/dist/server/handlers/agents.d.ts +154 -31
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/legacyWorkflows.cjs +11 -11
- package/dist/server/handlers/legacyWorkflows.d.ts +1 -1
- package/dist/server/handlers/legacyWorkflows.d.ts.map +1 -1
- package/dist/server/handlers/legacyWorkflows.js +1 -1
- package/dist/server/handlers/logs.cjs +4 -4
- package/dist/server/handlers/logs.js +1 -1
- package/dist/server/handlers/memory.cjs +19 -15
- package/dist/server/handlers/memory.d.ts +22 -18
- package/dist/server/handlers/memory.d.ts.map +1 -1
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/observability.cjs +24 -0
- package/dist/server/handlers/observability.cjs.map +1 -0
- package/dist/server/handlers/observability.d.ts +49 -0
- package/dist/server/handlers/observability.d.ts.map +1 -0
- package/dist/server/handlers/observability.js +3 -0
- package/dist/server/handlers/observability.js.map +1 -0
- package/dist/server/handlers/scores.cjs +7 -7
- package/dist/server/handlers/scores.d.ts +209 -7
- package/dist/server/handlers/scores.d.ts.map +1 -1
- package/dist/server/handlers/scores.js +1 -1
- package/dist/server/handlers/telemetry.cjs +7 -3
- package/dist/server/handlers/telemetry.d.ts +2 -1
- package/dist/server/handlers/telemetry.d.ts.map +1 -1
- package/dist/server/handlers/telemetry.js +1 -1
- package/dist/server/handlers/tools.cjs +9 -5
- package/dist/server/handlers/tools.d.ts +5 -1
- package/dist/server/handlers/tools.d.ts.map +1 -1
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/utils.cjs +6 -2
- package/dist/server/handlers/utils.d.ts +6 -0
- package/dist/server/handlers/utils.d.ts.map +1 -1
- package/dist/server/handlers/utils.js +1 -1
- package/dist/server/handlers/vector.cjs +7 -7
- package/dist/server/handlers/vector.d.ts +1 -1
- package/dist/server/handlers/vector.js +1 -1
- package/dist/server/handlers/voice.cjs +5 -5
- package/dist/server/handlers/voice.d.ts +7 -5
- package/dist/server/handlers/voice.d.ts.map +1 -1
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +28 -16
- package/dist/server/handlers/workflows.d.ts +37 -34
- package/dist/server/handlers/workflows.d.ts.map +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +38 -33
- package/dist/server/handlers.d.ts +13 -12
- package/dist/server/handlers.d.ts.map +1 -1
- package/dist/server/handlers.js +13 -12
- package/dist/server/utils.d.ts +44 -0
- package/dist/server/utils.d.ts.map +1 -0
- package/dist/token-53CFGXUO.cjs +64 -0
- package/dist/token-53CFGXUO.cjs.map +1 -0
- package/dist/token-WAEKDUVY.js +62 -0
- package/dist/token-WAEKDUVY.js.map +1 -0
- package/dist/token-util-LY37VCIN.js +7 -0
- package/dist/token-util-LY37VCIN.js.map +1 -0
- package/dist/token-util-S4A355II.cjs +9 -0
- package/dist/token-util-S4A355II.cjs.map +1 -0
- package/package.json +36 -14
- package/dist/chunk-2XIJW7SV.cjs +0 -310
- package/dist/chunk-2XIJW7SV.cjs.map +0 -1
- package/dist/chunk-4CEZIJWJ.cjs +0 -150
- package/dist/chunk-4CEZIJWJ.cjs.map +0 -1
- package/dist/chunk-4QSNRCOT.cjs.map +0 -1
- package/dist/chunk-4US5W7PH.cjs.map +0 -1
- package/dist/chunk-7FHF55WA.js +0 -2041
- package/dist/chunk-7FHF55WA.js.map +0 -1
- package/dist/chunk-BUOJL3MN.js.map +0 -1
- package/dist/chunk-GASWM5HJ.cjs.map +0 -1
- package/dist/chunk-HWHKM67I.js.map +0 -1
- package/dist/chunk-HXIOPAHT.js.map +0 -1
- package/dist/chunk-ILCWPBYQ.cjs.map +0 -1
- package/dist/chunk-JGVY3KWV.cjs.map +0 -1
- package/dist/chunk-LRUH33B4.cjs +0 -2044
- package/dist/chunk-LRUH33B4.cjs.map +0 -1
- package/dist/chunk-O4I563YW.cjs.map +0 -1
- package/dist/chunk-OW4FX5TS.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -9
- package/dist/chunk-Q7SFCCGT.cjs +0 -11
- package/dist/chunk-S37KCGOR.cjs.map +0 -1
- package/dist/chunk-SQ7KKIH3.js.map +0 -1
- package/dist/chunk-TRWPUPGD.js.map +0 -1
- package/dist/chunk-TXAQU2XN.js.map +0 -1
- package/dist/chunk-UVOSITKU.js.map +0 -1
- package/dist/chunk-VIGPWTDA.cjs.map +0 -1
- package/dist/chunk-VOY6MGKA.js +0 -301
- package/dist/chunk-VOY6MGKA.js.map +0 -1
- package/dist/chunk-X5SDJOY6.cjs.map +0 -1
- package/dist/chunk-Y3J45CVZ.js +0 -144
- package/dist/chunk-Y3J45CVZ.js.map +0 -1
- package/dist/chunk-YS66MFDY.js.map +0 -1
- package/dist/server/handlers/network.cjs +0 -24
- package/dist/server/handlers/network.cjs.map +0 -1
- package/dist/server/handlers/network.d.ts +0 -50
- package/dist/server/handlers/network.d.ts.map +0 -1
- package/dist/server/handlers/network.js +0 -3
- package/dist/server/handlers/network.js.map +0 -1
- package/dist/server/handlers/vNextNetwork.cjs +0 -220
- package/dist/server/handlers/vNextNetwork.cjs.map +0 -1
- package/dist/server/handlers/vNextNetwork.d.ts +0 -179
- package/dist/server/handlers/vNextNetwork.d.ts.map +0 -1
- package/dist/server/handlers/vNextNetwork.js +0 -213
- package/dist/server/handlers/vNextNetwork.js.map +0 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkG4PUALCE_cjs = require('./chunk-G4PUALCE.cjs');
|
|
4
4
|
var chunkRE4RPXT2_cjs = require('./chunk-RE4RPXT2.cjs');
|
|
5
5
|
var chunk7NADHFD2_cjs = require('./chunk-7NADHFD2.cjs');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var chunkO7I5CWRX_cjs = require('./chunk-O7I5CWRX.cjs');
|
|
7
|
+
var utils = require('@mastra/core/utils');
|
|
8
8
|
|
|
9
9
|
// src/server/handlers/memory.ts
|
|
10
10
|
var memory_exports = {};
|
|
11
|
-
|
|
11
|
+
chunkO7I5CWRX_cjs.__export(memory_exports, {
|
|
12
12
|
createThreadHandler: () => createThreadHandler,
|
|
13
13
|
deleteMessagesHandler: () => deleteMessagesHandler,
|
|
14
14
|
deleteThreadHandler: () => deleteThreadHandler,
|
|
@@ -18,6 +18,7 @@ chunkQ7SFCCGT_cjs.__export(memory_exports, {
|
|
|
18
18
|
getMessagesPaginatedHandler: () => getMessagesPaginatedHandler,
|
|
19
19
|
getThreadByIdHandler: () => getThreadByIdHandler,
|
|
20
20
|
getThreadsHandler: () => getThreadsHandler,
|
|
21
|
+
getThreadsPaginatedHandler: () => getThreadsPaginatedHandler,
|
|
21
22
|
getWorkingMemoryHandler: () => getWorkingMemoryHandler,
|
|
22
23
|
saveMessagesHandler: () => saveMessagesHandler,
|
|
23
24
|
searchMemoryHandler: () => searchMemoryHandler,
|
|
@@ -27,33 +28,26 @@ chunkQ7SFCCGT_cjs.__export(memory_exports, {
|
|
|
27
28
|
async function getMemoryFromContext({
|
|
28
29
|
mastra,
|
|
29
30
|
agentId,
|
|
30
|
-
networkId,
|
|
31
31
|
runtimeContext
|
|
32
32
|
}) {
|
|
33
33
|
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
34
34
|
if (agentId && !agent) {
|
|
35
35
|
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Agent not found" });
|
|
36
36
|
}
|
|
37
|
-
const network = networkId ? mastra.vnext_getNetwork(networkId) : null;
|
|
38
|
-
if (networkId && !network) {
|
|
39
|
-
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Network not found" });
|
|
40
|
-
}
|
|
41
37
|
if (agent) {
|
|
42
|
-
return await agent?.getMemory(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
|
|
38
|
+
return await agent?.getMemory({
|
|
39
|
+
runtimeContext
|
|
40
|
+
}) || mastra.getMemory();
|
|
46
41
|
}
|
|
47
42
|
return mastra.getMemory();
|
|
48
43
|
}
|
|
49
44
|
async function getMemoryStatusHandler({
|
|
50
45
|
mastra,
|
|
51
46
|
agentId,
|
|
52
|
-
networkId,
|
|
53
47
|
runtimeContext
|
|
54
48
|
}) {
|
|
55
49
|
try {
|
|
56
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
50
|
+
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
57
51
|
if (!memory) {
|
|
58
52
|
return { result: false };
|
|
59
53
|
}
|
|
@@ -65,11 +59,10 @@ async function getMemoryStatusHandler({
|
|
|
65
59
|
async function getMemoryConfigHandler({
|
|
66
60
|
mastra,
|
|
67
61
|
agentId,
|
|
68
|
-
networkId,
|
|
69
62
|
runtimeContext
|
|
70
63
|
}) {
|
|
71
64
|
try {
|
|
72
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
65
|
+
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
73
66
|
if (!memory) {
|
|
74
67
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
75
68
|
}
|
|
@@ -83,17 +76,16 @@ async function getThreadsHandler({
|
|
|
83
76
|
mastra,
|
|
84
77
|
agentId,
|
|
85
78
|
resourceId,
|
|
86
|
-
networkId,
|
|
87
79
|
runtimeContext,
|
|
88
80
|
orderBy,
|
|
89
81
|
sortDirection
|
|
90
82
|
}) {
|
|
91
83
|
try {
|
|
92
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
84
|
+
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
93
85
|
if (!memory) {
|
|
94
86
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
95
87
|
}
|
|
96
|
-
|
|
88
|
+
chunkG4PUALCE_cjs.validateBody({ resourceId });
|
|
97
89
|
const threads = await memory.getThreadsByResourceId({
|
|
98
90
|
resourceId,
|
|
99
91
|
orderBy,
|
|
@@ -104,16 +96,43 @@ async function getThreadsHandler({
|
|
|
104
96
|
return chunkRE4RPXT2_cjs.handleError(error, "Error getting threads");
|
|
105
97
|
}
|
|
106
98
|
}
|
|
99
|
+
async function getThreadsPaginatedHandler({
|
|
100
|
+
mastra,
|
|
101
|
+
agentId,
|
|
102
|
+
resourceId,
|
|
103
|
+
runtimeContext,
|
|
104
|
+
page,
|
|
105
|
+
perPage,
|
|
106
|
+
orderBy,
|
|
107
|
+
sortDirection
|
|
108
|
+
}) {
|
|
109
|
+
try {
|
|
110
|
+
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
111
|
+
if (!memory) {
|
|
112
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
113
|
+
}
|
|
114
|
+
chunkG4PUALCE_cjs.validateBody({ resourceId });
|
|
115
|
+
const result = await memory.getThreadsByResourceIdPaginated({
|
|
116
|
+
resourceId,
|
|
117
|
+
page,
|
|
118
|
+
perPage,
|
|
119
|
+
orderBy,
|
|
120
|
+
sortDirection
|
|
121
|
+
});
|
|
122
|
+
return result;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error getting paginated threads");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
107
127
|
async function getThreadByIdHandler({
|
|
108
128
|
mastra,
|
|
109
129
|
agentId,
|
|
110
130
|
threadId,
|
|
111
|
-
networkId,
|
|
112
131
|
runtimeContext
|
|
113
132
|
}) {
|
|
114
133
|
try {
|
|
115
|
-
|
|
116
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
134
|
+
chunkG4PUALCE_cjs.validateBody({ threadId });
|
|
135
|
+
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
117
136
|
if (!memory) {
|
|
118
137
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
119
138
|
}
|
|
@@ -130,11 +149,10 @@ async function saveMessagesHandler({
|
|
|
130
149
|
mastra,
|
|
131
150
|
agentId,
|
|
132
151
|
body,
|
|
133
|
-
networkId,
|
|
134
152
|
runtimeContext
|
|
135
153
|
}) {
|
|
136
154
|
try {
|
|
137
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
155
|
+
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
138
156
|
if (!memory) {
|
|
139
157
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
140
158
|
}
|
|
@@ -165,15 +183,14 @@ async function createThreadHandler({
|
|
|
165
183
|
mastra,
|
|
166
184
|
agentId,
|
|
167
185
|
body,
|
|
168
|
-
networkId,
|
|
169
186
|
runtimeContext
|
|
170
187
|
}) {
|
|
171
188
|
try {
|
|
172
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
189
|
+
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
173
190
|
if (!memory) {
|
|
174
191
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
175
192
|
}
|
|
176
|
-
|
|
193
|
+
chunkG4PUALCE_cjs.validateBody({ resourceId: body?.resourceId });
|
|
177
194
|
const result = await memory.createThread({
|
|
178
195
|
resourceId: body?.resourceId,
|
|
179
196
|
title: body?.title,
|
|
@@ -190,17 +207,16 @@ async function updateThreadHandler({
|
|
|
190
207
|
agentId,
|
|
191
208
|
threadId,
|
|
192
209
|
body,
|
|
193
|
-
networkId,
|
|
194
210
|
runtimeContext
|
|
195
211
|
}) {
|
|
196
212
|
try {
|
|
197
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
213
|
+
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
198
214
|
if (!body) {
|
|
199
215
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Body is required" });
|
|
200
216
|
}
|
|
201
217
|
const { title, metadata, resourceId } = body;
|
|
202
218
|
const updatedAt = /* @__PURE__ */ new Date();
|
|
203
|
-
|
|
219
|
+
chunkG4PUALCE_cjs.validateBody({ threadId });
|
|
204
220
|
if (!memory) {
|
|
205
221
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
206
222
|
}
|
|
@@ -226,12 +242,11 @@ async function deleteThreadHandler({
|
|
|
226
242
|
mastra,
|
|
227
243
|
agentId,
|
|
228
244
|
threadId,
|
|
229
|
-
networkId,
|
|
230
245
|
runtimeContext
|
|
231
246
|
}) {
|
|
232
247
|
try {
|
|
233
|
-
|
|
234
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
248
|
+
chunkG4PUALCE_cjs.validateBody({ threadId });
|
|
249
|
+
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
235
250
|
if (!memory) {
|
|
236
251
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
237
252
|
}
|
|
@@ -253,7 +268,7 @@ async function getMessagesPaginatedHandler({
|
|
|
253
268
|
format
|
|
254
269
|
}) {
|
|
255
270
|
try {
|
|
256
|
-
|
|
271
|
+
chunkG4PUALCE_cjs.validateBody({ threadId });
|
|
257
272
|
const storage = mastra.getStorage();
|
|
258
273
|
if (!storage) {
|
|
259
274
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Storage is not initialized" });
|
|
@@ -273,15 +288,14 @@ async function getMessagesHandler({
|
|
|
273
288
|
agentId,
|
|
274
289
|
threadId,
|
|
275
290
|
limit,
|
|
276
|
-
networkId,
|
|
277
291
|
runtimeContext
|
|
278
292
|
}) {
|
|
279
293
|
if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
|
|
280
294
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Invalid limit: must be a positive integer" });
|
|
281
295
|
}
|
|
282
296
|
try {
|
|
283
|
-
|
|
284
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
297
|
+
chunkG4PUALCE_cjs.validateBody({ threadId });
|
|
298
|
+
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
285
299
|
if (!memory) {
|
|
286
300
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
287
301
|
}
|
|
@@ -303,20 +317,19 @@ async function getWorkingMemoryHandler({
|
|
|
303
317
|
agentId,
|
|
304
318
|
threadId,
|
|
305
319
|
resourceId,
|
|
306
|
-
networkId,
|
|
307
320
|
runtimeContext,
|
|
308
321
|
memoryConfig
|
|
309
322
|
}) {
|
|
310
323
|
try {
|
|
311
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
312
|
-
|
|
324
|
+
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
325
|
+
chunkG4PUALCE_cjs.validateBody({ threadId });
|
|
313
326
|
if (!memory) {
|
|
314
327
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
315
328
|
}
|
|
316
329
|
const thread = await memory.getThreadById({ threadId });
|
|
317
330
|
const threadExists = !!thread;
|
|
318
331
|
const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
|
|
319
|
-
const workingMemoryTemplate = template?.format === "json" ? { ...template, content: JSON.stringify(
|
|
332
|
+
const workingMemoryTemplate = template?.format === "json" ? { ...template, content: JSON.stringify(utils.generateEmptyFromSchema(template.content)) } : template;
|
|
320
333
|
const workingMemory = await memory.getWorkingMemory({ threadId, resourceId, memoryConfig });
|
|
321
334
|
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
322
335
|
const source = config.workingMemory?.scope === "resource" && resourceId ? "resource" : "thread";
|
|
@@ -330,12 +343,11 @@ async function updateWorkingMemoryHandler({
|
|
|
330
343
|
agentId,
|
|
331
344
|
threadId,
|
|
332
345
|
body,
|
|
333
|
-
networkId,
|
|
334
346
|
runtimeContext
|
|
335
347
|
}) {
|
|
336
348
|
try {
|
|
337
|
-
|
|
338
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
349
|
+
chunkG4PUALCE_cjs.validateBody({ threadId });
|
|
350
|
+
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
339
351
|
const { resourceId, memoryConfig, workingMemory } = body;
|
|
340
352
|
if (!memory) {
|
|
341
353
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
@@ -354,14 +366,13 @@ async function deleteMessagesHandler({
|
|
|
354
366
|
mastra,
|
|
355
367
|
agentId,
|
|
356
368
|
messageIds,
|
|
357
|
-
networkId,
|
|
358
369
|
runtimeContext
|
|
359
370
|
}) {
|
|
360
371
|
try {
|
|
361
372
|
if (messageIds === void 0 || messageIds === null) {
|
|
362
373
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "messageIds is required" });
|
|
363
374
|
}
|
|
364
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
375
|
+
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
365
376
|
if (!memory) {
|
|
366
377
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
367
378
|
}
|
|
@@ -382,13 +393,12 @@ async function searchMemoryHandler({
|
|
|
382
393
|
resourceId,
|
|
383
394
|
threadId,
|
|
384
395
|
limit = 20,
|
|
385
|
-
networkId,
|
|
386
396
|
runtimeContext,
|
|
387
397
|
memoryConfig
|
|
388
398
|
}) {
|
|
389
399
|
try {
|
|
390
|
-
|
|
391
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
400
|
+
chunkG4PUALCE_cjs.validateBody({ searchQuery, resourceId });
|
|
401
|
+
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
392
402
|
if (!memory) {
|
|
393
403
|
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
394
404
|
}
|
|
@@ -547,11 +557,12 @@ exports.getMessagesHandler = getMessagesHandler;
|
|
|
547
557
|
exports.getMessagesPaginatedHandler = getMessagesPaginatedHandler;
|
|
548
558
|
exports.getThreadByIdHandler = getThreadByIdHandler;
|
|
549
559
|
exports.getThreadsHandler = getThreadsHandler;
|
|
560
|
+
exports.getThreadsPaginatedHandler = getThreadsPaginatedHandler;
|
|
550
561
|
exports.getWorkingMemoryHandler = getWorkingMemoryHandler;
|
|
551
562
|
exports.memory_exports = memory_exports;
|
|
552
563
|
exports.saveMessagesHandler = saveMessagesHandler;
|
|
553
564
|
exports.searchMemoryHandler = searchMemoryHandler;
|
|
554
565
|
exports.updateThreadHandler = updateThreadHandler;
|
|
555
566
|
exports.updateWorkingMemoryHandler = updateWorkingMemoryHandler;
|
|
556
|
-
//# sourceMappingURL=chunk-
|
|
557
|
-
//# sourceMappingURL=chunk-
|
|
567
|
+
//# sourceMappingURL=chunk-YJU744I4.cjs.map
|
|
568
|
+
//# sourceMappingURL=chunk-YJU744I4.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/memory.ts"],"names":["__export","HTTPException","handleError","validateBody","generateEmptyFromSchema"],"mappings":";;;;;;;;;AAAA,IAAA,cAAA,GAAA;AAAAA,0BAAA,CAAA,cAAA,EAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,qBAAA,EAAA,MAAA,qBAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,sBAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,sBAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA,kBAAA;AAAA,EAAA,2BAAA,EAAA,MAAA,2BAAA;AAAA,EAAA,oBAAA,EAAA,MAAA,oBAAA;AAAA,EAAA,iBAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,0BAAA,EAAA,MAAA,0BAAA;AAAA,EAAA,uBAAA,EAAA,MAAA,uBAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,mBAAA,EAAA,MA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B,IAAA,CAAK,CAAC,GAAG,CAAA,KAAM,IAAI,IAAA,CAAK,CAAA,CAAE,SAAS,CAAA,CAAE,SAAQ,GAAI,IAAI,IAAA,CAAK,CAAA,CAAE,SAAS,CAAA,CAAE,SAAS,CAAA,CAChF,KAAA,CAAM,CAAA,EAAG,KAAK,CAAA;AAEjB,IAAA,OAAO;AAAA,MACL,OAAA,EAAS,aAAA;AAAA,MACT,OAAO,aAAA,CAAc,MAAA;AAAA,MACrB,KAAA,EAAO,WAAA;AAAA,MACP,WAAA,EAAa,gBAAgB,UAAA,GAAa,QAAA;AAAA,MAC1C,UAAA,EAAY,oBAAoB,UAAA,GAAa;AAAA,KAC/C;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,OAAOC,6BAAA,CAAY,OAAO,wBAAwB,CAAA;AAAA,EACpD;AACF","file":"chunk-YJU744I4.cjs","sourcesContent":["import type { RuntimeContext } from '@mastra/core/di';\nimport type { MastraMemory } from '@mastra/core/memory';\nimport type { StorageGetMessagesArg, ThreadSortOptions } from '@mastra/core/storage';\nimport { generateEmptyFromSchema } from '@mastra/core/utils';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\n\nimport { handleError } from './error';\nimport { validateBody } from './utils';\n\ninterface MemoryContext extends Context {\n agentId?: string;\n resourceId?: string;\n threadId?: string;\n runtimeContext?: RuntimeContext;\n}\n\nasync function getMemoryFromContext({\n mastra,\n agentId,\n runtimeContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'runtimeContext'>): Promise<MastraMemory | null | undefined> {\n const agent = agentId ? mastra.getAgent(agentId) : null;\n if (agentId && !agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n if (agent) {\n return (\n (await agent?.getMemory({\n runtimeContext,\n })) || mastra.getMemory()\n );\n }\n\n return mastra.getMemory();\n}\n\n// Memory handlers\nexport async function getMemoryStatusHandler({\n mastra,\n agentId,\n runtimeContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'runtimeContext'>) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });\n\n if (!memory) {\n return { result: false };\n }\n\n return { result: true };\n } catch (error) {\n return handleError(error, 'Error getting memory status');\n }\n}\n\nexport async function getMemoryConfigHandler({\n mastra,\n agentId,\n runtimeContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'runtimeContext'>) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });\n\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n // Get the merged configuration (defaults + custom)\n const config = memory.getMergedThreadConfig({});\n\n return { config };\n } catch (error) {\n return handleError(error, 'Error getting memory configuration');\n }\n}\n\nexport async function getThreadsHandler({\n mastra,\n agentId,\n resourceId,\n runtimeContext,\n orderBy,\n sortDirection,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'resourceId' | 'runtimeContext'> & ThreadSortOptions) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });\n\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n validateBody({ resourceId });\n\n const threads = await memory.getThreadsByResourceId({\n resourceId: resourceId!,\n orderBy,\n sortDirection,\n });\n return threads;\n } catch (error) {\n return handleError(error, 'Error getting threads');\n }\n}\n\nexport async function getThreadsPaginatedHandler({\n mastra,\n agentId,\n resourceId,\n runtimeContext,\n page,\n perPage,\n orderBy,\n sortDirection,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'resourceId' | 'runtimeContext'> & {\n page: number;\n perPage: number;\n} & ThreadSortOptions) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });\n\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n validateBody({ resourceId });\n\n const result = await memory.getThreadsByResourceIdPaginated({\n resourceId: resourceId!,\n page,\n perPage,\n orderBy,\n sortDirection,\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error getting paginated threads');\n }\n}\n\nexport async function getThreadByIdHandler({\n mastra,\n agentId,\n threadId,\n runtimeContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'threadId' | 'runtimeContext'>) {\n try {\n validateBody({ threadId });\n\n const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n const thread = await memory.getThreadById({ threadId: threadId! });\n if (!thread) {\n throw new HTTPException(404, { message: 'Thread not found' });\n }\n\n return thread;\n } catch (error) {\n return handleError(error, 'Error getting thread');\n }\n}\n\nexport async function saveMessagesHandler({\n mastra,\n agentId,\n body,\n runtimeContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'runtimeContext'> & {\n body: {\n messages: Parameters<MastraMemory['saveMessages']>[0]['messages'];\n };\n}) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });\n\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n if (!body?.messages) {\n throw new HTTPException(400, { message: 'Messages are required' });\n }\n\n if (!Array.isArray(body.messages)) {\n throw new HTTPException(400, { message: 'Messages should be an array' });\n }\n\n // Validate that all messages have threadId and resourceId\n const invalidMessages = body.messages.filter(message => !message.threadId || !message.resourceId);\n if (invalidMessages.length > 0) {\n throw new HTTPException(400, {\n message: `All messages must have threadId and resourceId fields. Found ${invalidMessages.length} invalid message(s).`,\n });\n }\n\n const processedMessages = body.messages.map(message => ({\n ...message,\n id: message.id || memory.generateId(),\n createdAt: message.createdAt ? new Date(message.createdAt) : new Date(),\n }));\n\n const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });\n return result;\n } catch (error) {\n return handleError(error, 'Error saving messages');\n }\n}\n\nexport async function createThreadHandler({\n mastra,\n agentId,\n body,\n runtimeContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'runtimeContext'> & {\n body?: Omit<Parameters<MastraMemory['createThread']>[0], 'resourceId'> & { resourceId?: string };\n}) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });\n\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n validateBody({ resourceId: body?.resourceId });\n\n const result = await memory.createThread({\n resourceId: body?.resourceId!,\n title: body?.title,\n metadata: body?.metadata,\n threadId: body?.threadId,\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error saving thread to memory');\n }\n}\n\nexport async function updateThreadHandler({\n mastra,\n agentId,\n threadId,\n body,\n runtimeContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'threadId' | 'runtimeContext'> & {\n body?: Parameters<MastraMemory['saveThread']>[0]['thread'];\n}) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });\n\n if (!body) {\n throw new HTTPException(400, { message: 'Body is required' });\n }\n\n const { title, metadata, resourceId } = body;\n const updatedAt = new Date();\n\n validateBody({ threadId });\n\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n const thread = await memory.getThreadById({ threadId: threadId! });\n if (!thread) {\n throw new HTTPException(404, { message: 'Thread not found' });\n }\n\n const updatedThread = {\n ...thread,\n title: title || thread.title,\n metadata: metadata || thread.metadata,\n resourceId: resourceId || thread.resourceId,\n createdAt: thread.createdAt,\n updatedAt,\n };\n\n const result = await memory.saveThread({ thread: updatedThread });\n return result;\n } catch (error) {\n return handleError(error, 'Error updating thread');\n }\n}\n\nexport async function deleteThreadHandler({\n mastra,\n agentId,\n threadId,\n runtimeContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'threadId' | 'runtimeContext'>) {\n try {\n validateBody({ threadId });\n\n const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n const thread = await memory.getThreadById({ threadId: threadId! });\n if (!thread) {\n throw new HTTPException(404, { message: 'Thread not found' });\n }\n\n await memory.deleteThread(threadId!);\n return { result: 'Thread deleted' };\n } catch (error) {\n return handleError(error, 'Error deleting thread');\n }\n}\n\nexport async function getMessagesPaginatedHandler({\n mastra,\n threadId,\n resourceId,\n selectBy,\n format,\n}: StorageGetMessagesArg & Pick<MemoryContext, 'mastra'>) {\n try {\n validateBody({ threadId });\n\n const storage = mastra.getStorage();\n\n if (!storage) {\n throw new HTTPException(400, { message: 'Storage is not initialized' });\n }\n\n const thread = await storage.getThreadById({ threadId: threadId! });\n\n if (!thread) {\n throw new HTTPException(404, { message: 'Thread not found' });\n }\n\n const result = await storage.getMessagesPaginated({ threadId: threadId!, resourceId, selectBy, format });\n return result;\n } catch (error) {\n return handleError(error, 'Error getting messages');\n }\n}\n\nexport async function getMessagesHandler({\n mastra,\n agentId,\n threadId,\n limit,\n runtimeContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'threadId' | 'runtimeContext'> & {\n limit?: number;\n}) {\n if (limit !== undefined && (!Number.isInteger(limit) || limit <= 0)) {\n throw new HTTPException(400, { message: 'Invalid limit: must be a positive integer' });\n }\n try {\n validateBody({ threadId });\n\n const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });\n\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n const thread = await memory.getThreadById({ threadId: threadId! });\n if (!thread) {\n throw new HTTPException(404, { message: 'Thread not found' });\n }\n\n const result = await memory.query({\n threadId: threadId!,\n ...(limit && { selectBy: { last: limit } }),\n });\n return { messages: result.messages, uiMessages: result.uiMessages };\n } catch (error) {\n return handleError(error, 'Error getting messages');\n }\n}\n\n/**\n * Handler to get the working memory for a thread (optionally resource-scoped).\n * @returns workingMemory - the working memory for the thread\n * @returns source - thread or resource\n */\nexport async function getWorkingMemoryHandler({\n mastra,\n agentId,\n threadId,\n resourceId,\n runtimeContext,\n memoryConfig,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'threadId' | 'runtimeContext'> & {\n resourceId?: Parameters<MastraMemory['getWorkingMemory']>[0]['resourceId'];\n memoryConfig?: Parameters<MastraMemory['getWorkingMemory']>[0]['memoryConfig'];\n}) {\n try {\n const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });\n validateBody({ threadId });\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n const thread = await memory.getThreadById({ threadId: threadId! });\n const threadExists = !!thread;\n const template = await memory.getWorkingMemoryTemplate({ memoryConfig });\n const workingMemoryTemplate =\n template?.format === 'json'\n ? { ...template, content: JSON.stringify(generateEmptyFromSchema(template.content)) }\n : template;\n const workingMemory = await memory.getWorkingMemory({ threadId: threadId!, resourceId, memoryConfig });\n const config = memory.getMergedThreadConfig(memoryConfig || {});\n const source = config.workingMemory?.scope === 'resource' && resourceId ? 'resource' : 'thread';\n return { workingMemory, source, workingMemoryTemplate, threadExists };\n } catch (error) {\n return handleError(error, 'Error getting working memory');\n }\n}\n\n/**\n * Handler to update the working memory for a thread (optionally resource-scoped).\n * @param threadId - the thread id\n * @param body - the body containing the working memory to update and the resource id (optional)\n */\nexport async function updateWorkingMemoryHandler({\n mastra,\n agentId,\n threadId,\n body,\n runtimeContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'threadId' | 'runtimeContext'> & {\n body: Omit<Parameters<MastraMemory['updateWorkingMemory']>[0], 'threadId'>;\n}) {\n try {\n validateBody({ threadId });\n const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });\n const { resourceId, memoryConfig, workingMemory } = body;\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n const thread = await memory.getThreadById({ threadId: threadId! });\n if (!thread) {\n throw new HTTPException(404, { message: 'Thread not found' });\n }\n\n await memory.updateWorkingMemory({ threadId: threadId!, resourceId, workingMemory, memoryConfig });\n return { success: true };\n } catch (error) {\n return handleError(error, 'Error updating working memory');\n }\n}\n\ninterface SearchResult {\n id: string;\n role: string;\n content: any;\n createdAt: Date;\n threadId?: string;\n threadTitle?: string;\n score?: number;\n context?: {\n before?: SearchResult[];\n after?: SearchResult[];\n };\n}\n\ninterface SearchResponse {\n results: SearchResult[];\n count: number;\n query: string;\n searchScope?: string;\n searchType?: string;\n}\n\n/**\n * Handler to delete one or more messages.\n * @param messageIds - Can be a single ID, array of IDs, or objects with ID property\n */\nexport async function deleteMessagesHandler({\n mastra,\n agentId,\n messageIds,\n runtimeContext,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'runtimeContext'> & {\n messageIds: string | string[] | { id: string } | { id: string }[];\n}) {\n try {\n if (messageIds === undefined || messageIds === null) {\n throw new HTTPException(400, { message: 'messageIds is required' });\n }\n\n const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n // Delete the messages - let the memory method handle validation\n await memory.deleteMessages(messageIds as any);\n\n // Count messages for response\n let count = 1;\n if (Array.isArray(messageIds)) {\n count = messageIds.length;\n }\n\n return { success: true, message: `${count} message${count === 1 ? '' : 's'} deleted successfully` };\n } catch (error) {\n return handleError(error, 'Error deleting messages');\n }\n}\n\nexport async function searchMemoryHandler({\n mastra,\n agentId,\n searchQuery,\n resourceId,\n threadId,\n limit = 20,\n runtimeContext,\n memoryConfig,\n}: Pick<MemoryContext, 'mastra' | 'agentId' | 'runtimeContext'> & {\n searchQuery: string;\n resourceId: string;\n threadId?: string;\n limit?: number;\n memoryConfig?: any;\n}): Promise<SearchResponse | ReturnType<typeof handleError>> {\n try {\n validateBody({ searchQuery, resourceId });\n\n const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });\n if (!memory) {\n throw new HTTPException(400, { message: 'Memory is not initialized' });\n }\n\n // Get memory configuration first to check scope\n const config = memory.getMergedThreadConfig(memoryConfig || {});\n const hasSemanticRecall = !!config?.semanticRecall;\n const resourceScope = typeof config?.semanticRecall === 'object' && config?.semanticRecall?.scope === 'resource';\n\n // Only validate thread ownership if we're in thread scope\n if (threadId && !resourceScope) {\n const thread = await memory.getThreadById({ threadId });\n if (!thread) {\n throw new HTTPException(404, { message: 'Thread not found' });\n }\n if (thread.resourceId !== resourceId) {\n throw new HTTPException(403, { message: 'Thread does not belong to the specified resource' });\n }\n }\n\n const searchResults: SearchResult[] = [];\n const messageMap = new Map<string, boolean>(); // For deduplication\n\n // If threadId is provided and scope is thread-based, check if the thread exists\n if (threadId && !resourceScope) {\n const thread = await memory.getThreadById({ threadId });\n if (!thread) {\n // Thread doesn't exist yet (new unsaved thread) - return empty results\n return {\n results: [],\n count: 0,\n query: searchQuery,\n searchScope: 'thread',\n searchType: hasSemanticRecall ? 'semantic' : 'text',\n };\n }\n }\n\n // If resource scope is enabled or no threadId provided, search across all threads\n if (!threadId || resourceScope) {\n // Search across all threads for this resource\n const threads = await memory.getThreadsByResourceId({ resourceId });\n\n // If no threads exist yet, return empty results\n if (threads.length === 0) {\n return {\n results: [],\n count: 0,\n query: searchQuery,\n searchScope: 'resource',\n searchType: hasSemanticRecall ? 'semantic' : 'text',\n };\n }\n\n for (const thread of threads) {\n // Use rememberMessages for semantic search\n const result = await memory.rememberMessages({\n threadId: thread.id,\n resourceId,\n vectorMessageSearch: searchQuery,\n config,\n });\n\n // Get thread messages for context\n const threadMessages = (await memory.query({ threadId: thread.id })).uiMessages;\n\n // Process results\n result.messagesV2.forEach(msg => {\n if (messageMap.has(msg.id)) return;\n messageMap.set(msg.id, true);\n\n const content =\n msg.content.content || msg.content.parts?.map(p => (p.type === 'text' ? p.text : '')).join(' ') || '';\n\n if (!hasSemanticRecall && !content.toLowerCase().includes(searchQuery.toLowerCase())) {\n return;\n }\n\n const messageIndex = threadMessages.findIndex(m => m.id === msg.id);\n\n const searchResult: SearchResult = {\n id: msg.id,\n role: msg.role,\n content,\n createdAt: msg.createdAt,\n threadId: msg.threadId || thread.id,\n threadTitle: thread.title || msg.threadId || thread.id,\n };\n\n if (messageIndex !== -1) {\n searchResult.context = {\n before: threadMessages.slice(Math.max(0, messageIndex - 2), messageIndex).map(m => ({\n id: m.id,\n role: m.role,\n content: m.content,\n createdAt: m.createdAt || new Date(),\n })),\n after: threadMessages.slice(messageIndex + 1, messageIndex + 3).map(m => ({\n id: m.id,\n role: m.role,\n content: m.content,\n createdAt: m.createdAt || new Date(),\n })),\n };\n }\n\n searchResults.push(searchResult);\n });\n }\n } else if (threadId) {\n // Search in specific thread only\n const thread = await memory.getThreadById({ threadId });\n if (!thread) {\n // Thread doesn't exist yet - return empty results\n return {\n results: [],\n count: 0,\n query: searchQuery,\n searchScope: 'thread',\n searchType: hasSemanticRecall ? 'semantic' : 'text',\n };\n }\n\n const result = await memory.rememberMessages({\n threadId,\n resourceId,\n vectorMessageSearch: searchQuery,\n config,\n });\n\n const threadMessages = (await memory.query({ threadId })).uiMessages;\n\n result.messagesV2.forEach(msg => {\n // Skip duplicates\n if (messageMap.has(msg.id)) return;\n messageMap.set(msg.id, true);\n\n // Extract content\n const content =\n msg.content.content || msg.content.parts?.map(p => (p.type === 'text' ? p.text : '')).join(' ') || '';\n\n // If not using semantic recall, filter by text search\n if (!hasSemanticRecall && !content.toLowerCase().includes(searchQuery.toLowerCase())) {\n return;\n }\n\n // Find message index for context\n const messageIndex = threadMessages.findIndex(m => m.id === msg.id);\n\n const searchResult: SearchResult = {\n id: msg.id,\n role: msg.role,\n content,\n createdAt: msg.createdAt,\n threadId: threadId,\n threadTitle: thread?.title || threadId,\n };\n\n // Add context if found\n if (messageIndex !== -1) {\n searchResult.context = {\n before: threadMessages.slice(Math.max(0, messageIndex - 2), messageIndex).map(m => ({\n id: m.id,\n role: m.role,\n content: m.content,\n createdAt: m.createdAt || new Date(),\n })),\n after: threadMessages.slice(messageIndex + 1, messageIndex + 3).map(m => ({\n id: m.id,\n role: m.role,\n content: m.content,\n createdAt: m.createdAt || new Date(),\n })),\n };\n }\n\n searchResults.push(searchResult);\n });\n }\n\n // Sort by date (newest first) and limit\n const sortedResults = searchResults\n .sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())\n .slice(0, limit);\n\n return {\n results: sortedResults,\n count: sortedResults.length,\n query: searchQuery,\n searchScope: resourceScope ? 'resource' : 'thread',\n searchType: hasSemanticRecall ? 'semantic' : 'text',\n };\n } catch (error) {\n return handleError(error, 'Error searching memory');\n }\n}\n"]}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { stringify } from './chunk-LF2ZLOFP.js';
|
|
2
|
+
import { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';
|
|
3
|
+
|
|
4
|
+
function getSteps(steps, path) {
|
|
5
|
+
return Object.entries(steps).reduce((acc, [key, step]) => {
|
|
6
|
+
const fullKey = path ? `${path}.${key}` : key;
|
|
7
|
+
acc[fullKey] = {
|
|
8
|
+
id: step.id,
|
|
9
|
+
description: step.description,
|
|
10
|
+
inputSchema: step.inputSchema ? stringify(zodToJsonSchema(step.inputSchema)) : void 0,
|
|
11
|
+
outputSchema: step.outputSchema ? stringify(zodToJsonSchema(step.outputSchema)) : void 0,
|
|
12
|
+
resumeSchema: step.resumeSchema ? stringify(zodToJsonSchema(step.resumeSchema)) : void 0,
|
|
13
|
+
suspendSchema: step.suspendSchema ? stringify(zodToJsonSchema(step.suspendSchema)) : void 0,
|
|
14
|
+
isWorkflow: step.component === "WORKFLOW",
|
|
15
|
+
component: step.component
|
|
16
|
+
};
|
|
17
|
+
if (step.component === "WORKFLOW" && step.steps) {
|
|
18
|
+
const nestedSteps = getSteps(step.steps, fullKey) || {};
|
|
19
|
+
acc = { ...acc, ...nestedSteps };
|
|
20
|
+
}
|
|
21
|
+
return acc;
|
|
22
|
+
}, {});
|
|
23
|
+
}
|
|
24
|
+
function getWorkflowInfo(workflow) {
|
|
25
|
+
return {
|
|
26
|
+
name: workflow.name,
|
|
27
|
+
description: workflow.description,
|
|
28
|
+
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
29
|
+
acc[key] = {
|
|
30
|
+
id: step.id,
|
|
31
|
+
description: step.description,
|
|
32
|
+
inputSchema: step.inputSchema ? stringify(zodToJsonSchema(step.inputSchema)) : void 0,
|
|
33
|
+
outputSchema: step.outputSchema ? stringify(zodToJsonSchema(step.outputSchema)) : void 0,
|
|
34
|
+
resumeSchema: step.resumeSchema ? stringify(zodToJsonSchema(step.resumeSchema)) : void 0,
|
|
35
|
+
suspendSchema: step.suspendSchema ? stringify(zodToJsonSchema(step.suspendSchema)) : void 0,
|
|
36
|
+
component: step.component
|
|
37
|
+
};
|
|
38
|
+
return acc;
|
|
39
|
+
}, {}),
|
|
40
|
+
allSteps: getSteps(workflow.steps) || {},
|
|
41
|
+
stepGraph: workflow.serializedStepGraph,
|
|
42
|
+
inputSchema: workflow.inputSchema ? stringify(zodToJsonSchema(workflow.inputSchema)) : void 0,
|
|
43
|
+
outputSchema: workflow.outputSchema ? stringify(zodToJsonSchema(workflow.outputSchema)) : void 0
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
var WorkflowRegistry = class {
|
|
47
|
+
static additionalWorkflows = {};
|
|
48
|
+
/**
|
|
49
|
+
* Register a workflow temporarily
|
|
50
|
+
*/
|
|
51
|
+
static registerTemporaryWorkflow(id, workflow) {
|
|
52
|
+
this.additionalWorkflows[id] = workflow;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Register all workflows from map
|
|
56
|
+
*/
|
|
57
|
+
static registerTemporaryWorkflows(workflows, mastra) {
|
|
58
|
+
for (const [id, workflow] of Object.entries(workflows)) {
|
|
59
|
+
if (mastra) {
|
|
60
|
+
workflow.__registerMastra(mastra);
|
|
61
|
+
workflow.__registerPrimitives({
|
|
62
|
+
logger: mastra.getLogger(),
|
|
63
|
+
telemetry: mastra.getTelemetry(),
|
|
64
|
+
storage: mastra.getStorage(),
|
|
65
|
+
memory: mastra.getMemory(),
|
|
66
|
+
agents: mastra.getAgents(),
|
|
67
|
+
tts: mastra.getTTS(),
|
|
68
|
+
vectors: mastra.getVectors()
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
this.additionalWorkflows[id] = workflow;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get a workflow by ID from the registry (returns undefined if not found)
|
|
76
|
+
*/
|
|
77
|
+
static getWorkflow(workflowId) {
|
|
78
|
+
return this.additionalWorkflows[workflowId];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get all workflows from the registry
|
|
82
|
+
*/
|
|
83
|
+
static getAllWorkflows() {
|
|
84
|
+
return { ...this.additionalWorkflows };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Clean up a temporary workflow
|
|
88
|
+
*/
|
|
89
|
+
static cleanupTemporaryWorkflow(workflowId) {
|
|
90
|
+
delete this.additionalWorkflows[workflowId];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Clean up all registered workflows
|
|
94
|
+
*/
|
|
95
|
+
static cleanup() {
|
|
96
|
+
this.additionalWorkflows = {};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Check if a workflow ID is a valid agent-builder workflow
|
|
100
|
+
*/
|
|
101
|
+
static isAgentBuilderWorkflow(workflowId) {
|
|
102
|
+
return workflowId in this.additionalWorkflows;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get all registered temporary workflow IDs (for debugging)
|
|
106
|
+
*/
|
|
107
|
+
static getRegisteredWorkflowIds() {
|
|
108
|
+
return Object.keys(this.additionalWorkflows);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
function convertInstructionsToString(message) {
|
|
112
|
+
if (!message) {
|
|
113
|
+
return "";
|
|
114
|
+
}
|
|
115
|
+
if (typeof message === "string") {
|
|
116
|
+
return message;
|
|
117
|
+
}
|
|
118
|
+
if (Array.isArray(message)) {
|
|
119
|
+
return message.map((m) => {
|
|
120
|
+
if (typeof m === "string") {
|
|
121
|
+
return m;
|
|
122
|
+
}
|
|
123
|
+
return typeof m.content === "string" ? m.content : "";
|
|
124
|
+
}).filter((content) => content).join("\n");
|
|
125
|
+
}
|
|
126
|
+
return typeof message.content === "string" ? message.content : "";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { WorkflowRegistry, convertInstructionsToString, getWorkflowInfo };
|
|
130
|
+
//# sourceMappingURL=chunk-YWOK4F5A.js.map
|
|
131
|
+
//# sourceMappingURL=chunk-YWOK4F5A.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/utils.ts"],"names":[],"mappings":";;;AAKA,SAAS,QAAA,CAAS,OAA0C,IAAA,EAAe;AACzE,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,CAAE,MAAA,CAAY,CAAC,GAAA,EAAK,CAAC,GAAA,EAAK,IAAI,CAAA,KAAM;AAC7D,IAAA,MAAM,UAAU,IAAA,GAAO,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,GAAK,GAAA;AAC1C,IAAA,GAAA,CAAI,OAAO,CAAA,GAAI;AAAA,MACb,IAAI,IAAA,CAAK,EAAA;AAAA,MACT,aAAa,IAAA,CAAK,WAAA;AAAA,MAClB,WAAA,EAAa,KAAK,WAAA,GAAc,SAAA,CAAU,gBAAgB,IAAA,CAAK,WAAW,CAAC,CAAA,GAAI,MAAA;AAAA,MAC/E,YAAA,EAAc,KAAK,YAAA,GAAe,SAAA,CAAU,gBAAgB,IAAA,CAAK,YAAY,CAAC,CAAA,GAAI,MAAA;AAAA,MAClF,YAAA,EAAc,KAAK,YAAA,GAAe,SAAA,CAAU,gBAAgB,IAAA,CAAK,YAAY,CAAC,CAAA,GAAI,MAAA;AAAA,MAClF,aAAA,EAAe,KAAK,aAAA,GAAgB,SAAA,CAAU,gBAAgB,IAAA,CAAK,aAAa,CAAC,CAAA,GAAI,MAAA;AAAA,MACrF,UAAA,EAAY,KAAK,SAAA,KAAc,UAAA;AAAA,MAC/B,WAAW,IAAA,CAAK;AAAA,KAClB;AAEA,IAAA,IAAI,IAAA,CAAK,SAAA,KAAc,UAAA,IAAc,IAAA,CAAK,KAAA,EAAO;AAC/C,MAAA,MAAM,cAAc,QA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k-YWOK4F5A.js","sourcesContent":["import type { SystemMessage } from '@mastra/core';\nimport { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';\nimport type { StepWithComponent, Workflow, WorkflowInfo } from '@mastra/core/workflows';\nimport { stringify } from 'superjson';\n\nfunction getSteps(steps: Record<string, StepWithComponent>, path?: string) {\n return Object.entries(steps).reduce<any>((acc, [key, step]) => {\n const fullKey = path ? `${path}.${key}` : key;\n acc[fullKey] = {\n id: step.id,\n description: step.description,\n inputSchema: step.inputSchema ? stringify(zodToJsonSchema(step.inputSchema)) : undefined,\n outputSchema: step.outputSchema ? stringify(zodToJsonSchema(step.outputSchema)) : undefined,\n resumeSchema: step.resumeSchema ? stringify(zodToJsonSchema(step.resumeSchema)) : undefined,\n suspendSchema: step.suspendSchema ? stringify(zodToJsonSchema(step.suspendSchema)) : undefined,\n isWorkflow: step.component === 'WORKFLOW',\n component: step.component,\n };\n\n if (step.component === 'WORKFLOW' && step.steps) {\n const nestedSteps = getSteps(step.steps, fullKey) || {};\n acc = { ...acc, ...nestedSteps };\n }\n\n return acc;\n }, {});\n}\n\nexport function getWorkflowInfo(workflow: Workflow): WorkflowInfo {\n return {\n name: workflow.name,\n description: workflow.description,\n steps: Object.entries(workflow.steps).reduce<any>((acc, [key, step]) => {\n acc[key] = {\n id: step.id,\n description: step.description,\n inputSchema: step.inputSchema ? stringify(zodToJsonSchema(step.inputSchema)) : undefined,\n outputSchema: step.outputSchema ? stringify(zodToJsonSchema(step.outputSchema)) : undefined,\n resumeSchema: step.resumeSchema ? stringify(zodToJsonSchema(step.resumeSchema)) : undefined,\n suspendSchema: step.suspendSchema ? stringify(zodToJsonSchema(step.suspendSchema)) : undefined,\n component: step.component,\n };\n return acc;\n }, {}),\n allSteps: getSteps(workflow.steps) || {},\n stepGraph: workflow.serializedStepGraph,\n inputSchema: workflow.inputSchema ? stringify(zodToJsonSchema(workflow.inputSchema)) : undefined,\n outputSchema: workflow.outputSchema ? stringify(zodToJsonSchema(workflow.outputSchema)) : undefined,\n };\n}\n\n/**\n * Workflow Registry for temporarily registering additional workflows\n * that are not part of the user's Mastra instance (e.g., internal template workflows)\n */\nexport class WorkflowRegistry {\n private static additionalWorkflows: Record<string, Workflow> = {};\n\n /**\n * Register a workflow temporarily\n */\n static registerTemporaryWorkflow(id: string, workflow: Workflow): void {\n this.additionalWorkflows[id] = workflow;\n }\n\n /**\n * Register all workflows from map\n */\n static registerTemporaryWorkflows(workflows: Record<string, Workflow>, mastra?: any): void {\n for (const [id, workflow] of Object.entries(workflows)) {\n // Register Mastra instance with the workflow if provided\n if (mastra) {\n workflow.__registerMastra(mastra);\n workflow.__registerPrimitives({\n logger: mastra.getLogger(),\n telemetry: mastra.getTelemetry(),\n storage: mastra.getStorage(),\n memory: mastra.getMemory(),\n agents: mastra.getAgents(),\n tts: mastra.getTTS(),\n vectors: mastra.getVectors(),\n });\n }\n this.additionalWorkflows[id] = workflow;\n }\n }\n\n /**\n * Get a workflow by ID from the registry (returns undefined if not found)\n */\n static getWorkflow(workflowId: string): Workflow | undefined {\n return this.additionalWorkflows[workflowId];\n }\n\n /**\n * Get all workflows from the registry\n */\n static getAllWorkflows(): Record<string, Workflow> {\n return { ...this.additionalWorkflows };\n }\n\n /**\n * Clean up a temporary workflow\n */\n static cleanupTemporaryWorkflow(workflowId: string): void {\n delete this.additionalWorkflows[workflowId];\n }\n /**\n * Clean up all registered workflows\n */\n static cleanup(): void {\n // Clear all workflows (since we register all agent-builder workflows each time)\n this.additionalWorkflows = {};\n }\n\n /**\n * Check if a workflow ID is a valid agent-builder workflow\n */\n static isAgentBuilderWorkflow(workflowId: string): boolean {\n return workflowId in this.additionalWorkflows;\n }\n\n /**\n * Get all registered temporary workflow IDs (for debugging)\n */\n static getRegisteredWorkflowIds(): string[] {\n return Object.keys(this.additionalWorkflows);\n }\n}\n\nexport function convertInstructionsToString(message: SystemMessage): string {\n if (!message) {\n return '';\n }\n\n if (typeof message === 'string') {\n return message;\n }\n\n if (Array.isArray(message)) {\n return message\n .map(m => {\n if (typeof m === 'string') {\n return m;\n }\n // Safely extract content from message objects\n return typeof m.content === 'string' ? m.content : '';\n })\n .filter(content => content) // Remove empty strings\n .join('\\n');\n }\n\n // Handle single message object - safely extract content\n return typeof message.content === 'string' ? message.content : '';\n}\n"]}
|