@mastra/server 0.0.0-taofeeqInngest-20250603090617 → 0.0.0-transpile-packages-20250724123433

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.
Files changed (80) hide show
  1. package/LICENSE.md +11 -42
  2. package/dist/_tsup-dts-rollup.d.cts +390 -45
  3. package/dist/_tsup-dts-rollup.d.ts +390 -45
  4. package/dist/{chunk-OCWPVYNI.cjs → chunk-2KZFMI6P.cjs} +1 -0
  5. package/dist/{chunk-VPNDC2DI.cjs → chunk-2SLFAFTR.cjs} +12 -12
  6. package/dist/chunk-4D66QEKC.js +81 -0
  7. package/dist/{chunk-W7VCKPAD.js → chunk-5PQQ42EZ.js} +9 -9
  8. package/dist/{chunk-BNEY4P4P.cjs → chunk-7TP2LX5L.cjs} +16 -16
  9. package/dist/chunk-B2PAS2IB.cjs +514 -0
  10. package/dist/{chunk-J3PKLB3A.js → chunk-BK4XT6EG.js} +56 -17
  11. package/dist/chunk-CBFTEHOO.cjs +157 -0
  12. package/dist/{chunk-57CJTIPW.cjs → chunk-CCGRCYWJ.cjs} +2 -2
  13. package/dist/{chunk-C7564HUT.js → chunk-CRCR3ZUK.js} +3 -3
  14. package/dist/{chunk-ZE5AAC4I.cjs → chunk-FRVBFMO2.cjs} +26 -36
  15. package/dist/{chunk-DJJIUEL2.js → chunk-G4L7OMCA.js} +135 -26
  16. package/dist/{chunk-B4MQFJ7G.cjs → chunk-G7KH752Y.cjs} +5 -5
  17. package/dist/{chunk-KUNQFY2W.js → chunk-H7DMHBKY.js} +190 -57
  18. package/dist/{chunk-YIOVBYZH.cjs → chunk-JMLYCXMK.cjs} +43 -43
  19. package/dist/{chunk-CP55EVBK.js → chunk-KHZKYUNR.js} +15 -11
  20. package/dist/{chunk-NYN7KFXL.js → chunk-LCM566I4.js} +1 -0
  21. package/dist/chunk-LF7P5PLR.js +14 -0
  22. package/dist/{chunk-YWLUOY3D.cjs → chunk-LI436ITD.cjs} +107 -69
  23. package/dist/{chunk-TJKLBTFB.js → chunk-LRCAAFUA.js} +10 -20
  24. package/dist/{chunk-A3KDUGS7.cjs → chunk-LZ3VJXSO.cjs} +70 -31
  25. package/dist/{chunk-LIVAK2DM.js → chunk-MEGCYGBU.js} +108 -70
  26. package/dist/chunk-PZQDCRPV.cjs +16 -0
  27. package/dist/chunk-QGX47B5D.cjs +86 -0
  28. package/dist/{chunk-BFOA2QQY.js → chunk-RG473F6Y.js} +2 -2
  29. package/dist/{chunk-CMMOIUFC.cjs → chunk-RHSWAXKB.cjs} +34 -30
  30. package/dist/{chunk-H5PTF3Y4.js → chunk-RSEO4XPX.js} +1 -1
  31. package/dist/chunk-VULESSU5.js +149 -0
  32. package/dist/{chunk-55DOQLP6.js → chunk-WNVFNNWN.js} +2 -2
  33. package/dist/chunk-Z75RYULP.cjs +333 -0
  34. package/dist/server/handlers/agents.cjs +7 -7
  35. package/dist/server/handlers/agents.js +1 -1
  36. package/dist/server/handlers/error.cjs +2 -2
  37. package/dist/server/handlers/error.js +1 -1
  38. package/dist/server/handlers/legacyWorkflows.cjs +11 -11
  39. package/dist/server/handlers/legacyWorkflows.js +1 -1
  40. package/dist/server/handlers/logs.cjs +4 -4
  41. package/dist/server/handlers/logs.js +1 -1
  42. package/dist/server/handlers/memory.cjs +21 -9
  43. package/dist/server/handlers/memory.d.cts +3 -0
  44. package/dist/server/handlers/memory.d.ts +3 -0
  45. package/dist/server/handlers/memory.js +1 -1
  46. package/dist/server/handlers/network.cjs +5 -5
  47. package/dist/server/handlers/network.js +1 -1
  48. package/dist/server/handlers/scores.cjs +30 -0
  49. package/dist/server/handlers/scores.d.cts +6 -0
  50. package/dist/server/handlers/scores.d.ts +6 -0
  51. package/dist/server/handlers/scores.js +1 -0
  52. package/dist/server/handlers/telemetry.cjs +3 -3
  53. package/dist/server/handlers/telemetry.js +1 -1
  54. package/dist/server/handlers/tools.cjs +5 -5
  55. package/dist/server/handlers/tools.js +1 -1
  56. package/dist/server/handlers/utils.cjs +2 -2
  57. package/dist/server/handlers/utils.js +1 -1
  58. package/dist/server/handlers/vNextNetwork.cjs +218 -0
  59. package/dist/server/handlers/vNextNetwork.d.cts +6 -0
  60. package/dist/server/handlers/vNextNetwork.d.ts +6 -0
  61. package/dist/server/handlers/vNextNetwork.js +211 -0
  62. package/dist/server/handlers/vector.cjs +7 -7
  63. package/dist/server/handlers/vector.js +1 -1
  64. package/dist/server/handlers/voice.cjs +5 -5
  65. package/dist/server/handlers/voice.js +1 -1
  66. package/dist/server/handlers/workflows.cjs +24 -12
  67. package/dist/server/handlers/workflows.d.cts +3 -0
  68. package/dist/server/handlers/workflows.d.ts +3 -0
  69. package/dist/server/handlers/workflows.js +1 -1
  70. package/dist/server/handlers.cjs +28 -23
  71. package/dist/server/handlers.d.cts +3 -2
  72. package/dist/server/handlers.d.ts +3 -2
  73. package/dist/server/handlers.js +11 -10
  74. package/package.json +15 -15
  75. package/dist/chunk-64U3UDTH.cjs +0 -13
  76. package/dist/chunk-DQLE3DVM.js +0 -49
  77. package/dist/chunk-M5ABIP7D.js +0 -11
  78. package/dist/chunk-MMO2HDM6.cjs +0 -378
  79. package/dist/chunk-NEOOQUKW.cjs +0 -54
  80. package/dist/chunk-Y7UWRW5X.cjs +0 -221
@@ -0,0 +1,157 @@
1
+ 'use strict';
2
+
3
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
4
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
5
+
6
+ // src/server/handlers/scores.ts
7
+ var scores_exports = {};
8
+ chunk75ZPJI57_cjs.__export(scores_exports, {
9
+ getScorerHandler: () => getScorerHandler,
10
+ getScorersHandler: () => getScorersHandler,
11
+ getScoresByEntityIdHandler: () => getScoresByEntityIdHandler,
12
+ getScoresByRunIdHandler: () => getScoresByRunIdHandler,
13
+ getScoresByScorerIdHandler: () => getScoresByScorerIdHandler,
14
+ saveScoreHandler: () => saveScoreHandler
15
+ });
16
+ async function getScorersFromSystem({
17
+ mastra,
18
+ runtimeContext
19
+ }) {
20
+ const agents = mastra.getAgents();
21
+ const workflows = mastra.getWorkflows();
22
+ const scorersMap = /* @__PURE__ */ new Map();
23
+ for (const [agentId, agent] of Object.entries(agents)) {
24
+ const scorers = await agent.getScorers({
25
+ runtimeContext
26
+ }) || {};
27
+ if (Object.keys(scorers).length > 0) {
28
+ for (const [scorerId, scorer] of Object.entries(scorers)) {
29
+ if (scorersMap.has(scorerId)) {
30
+ scorersMap.get(scorerId)?.agentIds.push(agentId);
31
+ } else {
32
+ scorersMap.set(scorerId, {
33
+ workflowIds: [],
34
+ ...scorer,
35
+ agentIds: [agentId]
36
+ });
37
+ }
38
+ }
39
+ }
40
+ }
41
+ for (const [workflowId, workflow] of Object.entries(workflows)) {
42
+ const scorers = await workflow.getScorers({
43
+ runtimeContext
44
+ }) || {};
45
+ if (Object.keys(scorers).length > 0) {
46
+ for (const [scorerId, scorer] of Object.entries(scorers)) {
47
+ if (scorersMap.has(scorerId)) {
48
+ scorersMap.get(scorerId)?.workflowIds.push(workflowId);
49
+ } else {
50
+ scorersMap.set(scorerId, {
51
+ agentIds: [],
52
+ ...scorer,
53
+ workflowIds: [workflowId]
54
+ });
55
+ }
56
+ }
57
+ }
58
+ }
59
+ return Object.fromEntries(scorersMap.entries());
60
+ }
61
+ async function getScorersHandler({ mastra, runtimeContext }) {
62
+ const scorers = await getScorersFromSystem({
63
+ mastra,
64
+ runtimeContext
65
+ });
66
+ return scorers;
67
+ }
68
+ async function getScorerHandler({
69
+ mastra,
70
+ scorerId,
71
+ runtimeContext
72
+ }) {
73
+ const scorers = await getScorersFromSystem({
74
+ mastra,
75
+ runtimeContext
76
+ });
77
+ const scorer = scorers[scorerId];
78
+ if (!scorer) {
79
+ return null;
80
+ }
81
+ return scorer;
82
+ }
83
+ async function getScoresByRunIdHandler({
84
+ mastra,
85
+ runId,
86
+ pagination
87
+ }) {
88
+ try {
89
+ const scores = await mastra.getStorage()?.getScoresByRunId?.({
90
+ runId,
91
+ pagination
92
+ }) || [];
93
+ return scores;
94
+ } catch (error) {
95
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting scores by run id");
96
+ }
97
+ }
98
+ async function getScoresByScorerIdHandler({
99
+ mastra,
100
+ scorerId,
101
+ pagination,
102
+ entityId,
103
+ entityType
104
+ }) {
105
+ try {
106
+ const scores = await mastra.getStorage()?.getScoresByScorerId?.({
107
+ scorerId,
108
+ pagination,
109
+ entityId,
110
+ entityType
111
+ }) || [];
112
+ return scores;
113
+ } catch (error) {
114
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting scores by scorer id");
115
+ }
116
+ }
117
+ async function getScoresByEntityIdHandler({
118
+ mastra,
119
+ entityId,
120
+ entityType,
121
+ pagination
122
+ }) {
123
+ try {
124
+ let entityIdToUse = entityId;
125
+ if (entityType === "AGENT") {
126
+ const agent = mastra.getAgentById(entityId);
127
+ entityIdToUse = agent.id;
128
+ } else if (entityType === "WORKFLOW") {
129
+ const workflow = mastra.getWorkflowById(entityId);
130
+ entityIdToUse = workflow.id;
131
+ }
132
+ const scores = await mastra.getStorage()?.getScoresByEntityId?.({
133
+ entityId: entityIdToUse,
134
+ entityType,
135
+ pagination
136
+ }) || [];
137
+ return scores;
138
+ } catch (error) {
139
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting scores by entity id");
140
+ }
141
+ }
142
+ async function saveScoreHandler({ mastra, score }) {
143
+ try {
144
+ const scores = await mastra.getStorage()?.saveScore?.(score) || [];
145
+ return scores;
146
+ } catch (error) {
147
+ return chunkPZQDCRPV_cjs.handleError(error, "Error saving score");
148
+ }
149
+ }
150
+
151
+ exports.getScorerHandler = getScorerHandler;
152
+ exports.getScorersHandler = getScorersHandler;
153
+ exports.getScoresByEntityIdHandler = getScoresByEntityIdHandler;
154
+ exports.getScoresByRunIdHandler = getScoresByRunIdHandler;
155
+ exports.getScoresByScorerIdHandler = getScoresByScorerIdHandler;
156
+ exports.saveScoreHandler = saveScoreHandler;
157
+ exports.scores_exports = scores_exports;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
3
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
4
4
 
5
5
  // src/server/handlers/utils.ts
6
6
  function validateBody(body) {
@@ -11,7 +11,7 @@ function validateBody(body) {
11
11
  return acc;
12
12
  }, {});
13
13
  if (Object.keys(errorResponse).length > 0) {
14
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: Object.values(errorResponse)[0] });
14
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: Object.values(errorResponse)[0] });
15
15
  }
16
16
  }
17
17
 
@@ -1,6 +1,6 @@
1
- import { validateBody } from './chunk-H5PTF3Y4.js';
2
- import { handleError } from './chunk-M5ABIP7D.js';
3
- import { HTTPException } from './chunk-NYN7KFXL.js';
1
+ import { validateBody } from './chunk-RSEO4XPX.js';
2
+ import { handleError } from './chunk-LF7P5PLR.js';
3
+ import { HTTPException } from './chunk-LCM566I4.js';
4
4
  import { __export } from './chunk-MLKGABMK.js';
5
5
 
6
6
  // src/server/handlers/network.ts
@@ -1,11 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunkYWLUOY3D_cjs = require('./chunk-YWLUOY3D.cjs');
4
- var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
5
- var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
6
- var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
3
+ var chunkLI436ITD_cjs = require('./chunk-LI436ITD.cjs');
4
+ var chunkCCGRCYWJ_cjs = require('./chunk-CCGRCYWJ.cjs');
5
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
6
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
7
7
  var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
8
- var di = require('@mastra/core/di');
9
8
  var tools = require('@mastra/core/tools');
10
9
 
11
10
  // src/server/handlers/tools.ts
@@ -26,8 +25,8 @@ async function getToolsHandler({ tools }) {
26
25
  const tool = _tool;
27
26
  acc[id] = {
28
27
  ...tool,
29
- inputSchema: tool.inputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(tool.inputSchema)) : void 0,
30
- outputSchema: tool.outputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(tool.outputSchema)) : void 0
28
+ inputSchema: tool.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.inputSchema)) : void 0,
29
+ outputSchema: tool.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.outputSchema)) : void 0
31
30
  };
32
31
  return acc;
33
32
  },
@@ -35,23 +34,23 @@ async function getToolsHandler({ tools }) {
35
34
  );
36
35
  return serializedTools;
37
36
  } catch (error) {
38
- return chunk64U3UDTH_cjs.handleError(error, "Error getting tools");
37
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting tools");
39
38
  }
40
39
  }
41
40
  async function getToolByIdHandler({ tools, toolId }) {
42
41
  try {
43
42
  const tool = Object.values(tools || {}).find((tool2) => tool2.id === toolId);
44
43
  if (!tool) {
45
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
44
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
46
45
  }
47
46
  const serializedTool = {
48
47
  ...tool,
49
- inputSchema: tool.inputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(tool.inputSchema)) : void 0,
50
- outputSchema: tool.outputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(tool.outputSchema)) : void 0
48
+ inputSchema: tool.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.inputSchema)) : void 0,
49
+ outputSchema: tool.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.outputSchema)) : void 0
51
50
  };
52
51
  return serializedTool;
53
52
  } catch (error) {
54
- return chunk64U3UDTH_cjs.handleError(error, "Error getting tool");
53
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting tool");
55
54
  }
56
55
  }
57
56
  function executeToolHandler(tools$1) {
@@ -60,38 +59,33 @@ function executeToolHandler(tools$1) {
60
59
  runId,
61
60
  toolId,
62
61
  data,
63
- runtimeContext,
64
- runtimeContextFromRequest
62
+ runtimeContext
65
63
  }) => {
66
64
  try {
67
65
  if (!toolId) {
68
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Tool ID is required" });
66
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Tool ID is required" });
69
67
  }
70
68
  const tool = Object.values(tools$1 || {}).find((tool2) => tool2.id === toolId);
71
69
  if (!tool) {
72
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
70
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
73
71
  }
74
72
  if (!tool?.execute) {
75
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Tool is not executable" });
73
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Tool is not executable" });
76
74
  }
77
- chunk57CJTIPW_cjs.validateBody({ data });
75
+ chunkCCGRCYWJ_cjs.validateBody({ data });
78
76
  if (tools.isVercelTool(tool)) {
79
77
  const result2 = await tool.execute(data);
80
78
  return result2;
81
79
  }
82
- const finalRuntimeContext = new di.RuntimeContext([
83
- ...Array.from(runtimeContext.entries()),
84
- ...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
85
- ]);
86
80
  const result = await tool.execute({
87
81
  context: data,
88
82
  mastra,
89
83
  runId,
90
- runtimeContext: finalRuntimeContext
84
+ runtimeContext
91
85
  });
92
86
  return result;
93
87
  } catch (error) {
94
- return chunk64U3UDTH_cjs.handleError(error, "Error executing tool");
88
+ return chunkPZQDCRPV_cjs.handleError(error, "Error executing tool");
95
89
  }
96
90
  };
97
91
  }
@@ -100,34 +94,30 @@ async function executeAgentToolHandler({
100
94
  agentId,
101
95
  toolId,
102
96
  data,
103
- runtimeContext,
104
- runtimeContextFromRequest
97
+ runtimeContext
105
98
  }) {
106
99
  try {
107
100
  const agent = agentId ? mastra.getAgent(agentId) : null;
108
101
  if (!agent) {
109
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
102
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
110
103
  }
111
- const tool = Object.values(agent?.tools || {}).find((tool2) => tool2.id === toolId);
104
+ const agentTools = await agent.getTools({ runtimeContext });
105
+ const tool = Object.values(agentTools || {}).find((tool2) => tool2.id === toolId);
112
106
  if (!tool) {
113
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
107
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
114
108
  }
115
109
  if (!tool?.execute) {
116
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Tool is not executable" });
110
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Tool is not executable" });
117
111
  }
118
- const finalRuntimeContext = new di.RuntimeContext([
119
- ...Array.from(runtimeContext.entries()),
120
- ...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
121
- ]);
122
112
  const result = await tool.execute({
123
113
  context: data,
124
- runtimeContext: finalRuntimeContext,
114
+ runtimeContext,
125
115
  mastra,
126
116
  runId: agentId
127
117
  });
128
118
  return result;
129
119
  } catch (error) {
130
- return chunk64U3UDTH_cjs.handleError(error, "Error executing tool");
120
+ return chunkPZQDCRPV_cjs.handleError(error, "Error executing tool");
131
121
  }
132
122
  }
133
123
 
@@ -1,7 +1,8 @@
1
- import { validateBody } from './chunk-H5PTF3Y4.js';
2
- import { handleError } from './chunk-M5ABIP7D.js';
3
- import { HTTPException } from './chunk-NYN7KFXL.js';
1
+ import { validateBody } from './chunk-RSEO4XPX.js';
2
+ import { handleError } from './chunk-LF7P5PLR.js';
3
+ import { HTTPException } from './chunk-LCM566I4.js';
4
4
  import { __export } from './chunk-MLKGABMK.js';
5
+ import { generateEmptyFromSchema } from '@mastra/core';
5
6
 
6
7
  // src/server/handlers/memory.ts
7
8
  var memory_exports = {};
@@ -10,25 +11,44 @@ __export(memory_exports, {
10
11
  deleteThreadHandler: () => deleteThreadHandler,
11
12
  getMemoryStatusHandler: () => getMemoryStatusHandler,
12
13
  getMessagesHandler: () => getMessagesHandler,
14
+ getMessagesPaginatedHandler: () => getMessagesPaginatedHandler,
13
15
  getThreadByIdHandler: () => getThreadByIdHandler,
14
16
  getThreadsHandler: () => getThreadsHandler,
17
+ getWorkingMemoryHandler: () => getWorkingMemoryHandler,
15
18
  saveMessagesHandler: () => saveMessagesHandler,
16
- updateThreadHandler: () => updateThreadHandler
19
+ updateThreadHandler: () => updateThreadHandler,
20
+ updateWorkingMemoryHandler: () => updateWorkingMemoryHandler
17
21
  });
18
- function getMemoryFromContext({
22
+ async function getMemoryFromContext({
19
23
  mastra,
20
- agentId
24
+ agentId,
25
+ networkId,
26
+ runtimeContext
21
27
  }) {
22
28
  const agent = agentId ? mastra.getAgent(agentId) : null;
23
29
  if (agentId && !agent) {
24
30
  throw new HTTPException(404, { message: "Agent not found" });
25
31
  }
26
- const memory = agent?.getMemory?.() || mastra.getMemory();
27
- return memory;
32
+ const network = networkId ? mastra.vnext_getNetwork(networkId) : null;
33
+ if (networkId && !network) {
34
+ throw new HTTPException(404, { message: "Network not found" });
35
+ }
36
+ if (agent) {
37
+ return agent?.getMemory() || mastra.getMemory();
38
+ }
39
+ if (network) {
40
+ return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
41
+ }
42
+ return mastra.getMemory();
28
43
  }
29
- async function getMemoryStatusHandler({ mastra, agentId }) {
44
+ async function getMemoryStatusHandler({
45
+ mastra,
46
+ agentId,
47
+ networkId,
48
+ runtimeContext
49
+ }) {
30
50
  try {
31
- const memory = getMemoryFromContext({ mastra, agentId });
51
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
32
52
  if (!memory) {
33
53
  return { result: false };
34
54
  }
@@ -40,10 +60,12 @@ async function getMemoryStatusHandler({ mastra, agentId }) {
40
60
  async function getThreadsHandler({
41
61
  mastra,
42
62
  agentId,
43
- resourceId
63
+ resourceId,
64
+ networkId,
65
+ runtimeContext
44
66
  }) {
45
67
  try {
46
- const memory = getMemoryFromContext({ mastra, agentId });
68
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
47
69
  if (!memory) {
48
70
  throw new HTTPException(400, { message: "Memory is not initialized" });
49
71
  }
@@ -57,11 +79,13 @@ async function getThreadsHandler({
57
79
  async function getThreadByIdHandler({
58
80
  mastra,
59
81
  agentId,
60
- threadId
82
+ threadId,
83
+ networkId,
84
+ runtimeContext
61
85
  }) {
62
86
  try {
63
87
  validateBody({ threadId });
64
- const memory = getMemoryFromContext({ mastra, agentId });
88
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
65
89
  if (!memory) {
66
90
  throw new HTTPException(400, { message: "Memory is not initialized" });
67
91
  }
@@ -77,10 +101,12 @@ async function getThreadByIdHandler({
77
101
  async function saveMessagesHandler({
78
102
  mastra,
79
103
  agentId,
80
- body
104
+ body,
105
+ networkId,
106
+ runtimeContext
81
107
  }) {
82
108
  try {
83
- const memory = getMemoryFromContext({ mastra, agentId });
109
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
84
110
  if (!memory) {
85
111
  throw new HTTPException(400, { message: "Memory is not initialized" });
86
112
  }
@@ -104,10 +130,12 @@ async function saveMessagesHandler({
104
130
  async function createThreadHandler({
105
131
  mastra,
106
132
  agentId,
107
- body
133
+ body,
134
+ networkId,
135
+ runtimeContext
108
136
  }) {
109
137
  try {
110
- const memory = getMemoryFromContext({ mastra, agentId });
138
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
111
139
  if (!memory) {
112
140
  throw new HTTPException(400, { message: "Memory is not initialized" });
113
141
  }
@@ -127,10 +155,12 @@ async function updateThreadHandler({
127
155
  mastra,
128
156
  agentId,
129
157
  threadId,
130
- body
158
+ body,
159
+ networkId,
160
+ runtimeContext
131
161
  }) {
132
162
  try {
133
- const memory = getMemoryFromContext({ mastra, agentId });
163
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
134
164
  if (!body) {
135
165
  throw new HTTPException(400, { message: "Body is required" });
136
166
  }
@@ -161,11 +191,13 @@ async function updateThreadHandler({
161
191
  async function deleteThreadHandler({
162
192
  mastra,
163
193
  agentId,
164
- threadId
194
+ threadId,
195
+ networkId,
196
+ runtimeContext
165
197
  }) {
166
198
  try {
167
199
  validateBody({ threadId });
168
- const memory = getMemoryFromContext({ mastra, agentId });
200
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
169
201
  if (!memory) {
170
202
  throw new HTTPException(400, { message: "Memory is not initialized" });
171
203
  }
@@ -179,18 +211,43 @@ async function deleteThreadHandler({
179
211
  return handleError(error, "Error deleting thread");
180
212
  }
181
213
  }
214
+ async function getMessagesPaginatedHandler({
215
+ mastra,
216
+ threadId,
217
+ resourceId,
218
+ selectBy,
219
+ format
220
+ }) {
221
+ try {
222
+ validateBody({ threadId });
223
+ const storage = mastra.getStorage();
224
+ if (!storage) {
225
+ throw new HTTPException(400, { message: "Storage is not initialized" });
226
+ }
227
+ const thread = await storage.getThreadById({ threadId });
228
+ if (!thread) {
229
+ throw new HTTPException(404, { message: "Thread not found" });
230
+ }
231
+ const result = await storage.getMessagesPaginated({ threadId, resourceId, selectBy, format });
232
+ return result;
233
+ } catch (error) {
234
+ return handleError(error, "Error getting messages");
235
+ }
236
+ }
182
237
  async function getMessagesHandler({
183
238
  mastra,
184
239
  agentId,
185
240
  threadId,
186
- limit
241
+ limit,
242
+ networkId,
243
+ runtimeContext
187
244
  }) {
188
245
  if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
189
246
  throw new HTTPException(400, { message: "Invalid limit: must be a positive integer" });
190
247
  }
191
248
  try {
192
249
  validateBody({ threadId });
193
- const memory = getMemoryFromContext({ mastra, agentId });
250
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
194
251
  if (!memory) {
195
252
  throw new HTTPException(400, { message: "Memory is not initialized" });
196
253
  }
@@ -202,10 +259,62 @@ async function getMessagesHandler({
202
259
  threadId,
203
260
  ...limit && { selectBy: { last: limit } }
204
261
  });
205
- return result;
262
+ return { messages: result.messages, uiMessages: result.uiMessages };
206
263
  } catch (error) {
207
264
  return handleError(error, "Error getting messages");
208
265
  }
209
266
  }
267
+ async function getWorkingMemoryHandler({
268
+ mastra,
269
+ agentId,
270
+ threadId,
271
+ resourceId,
272
+ networkId,
273
+ runtimeContext,
274
+ memoryConfig
275
+ }) {
276
+ try {
277
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
278
+ validateBody({ threadId });
279
+ if (!memory) {
280
+ throw new HTTPException(400, { message: "Memory is not initialized" });
281
+ }
282
+ const thread = await memory.getThreadById({ threadId });
283
+ const threadExists = !!thread;
284
+ const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
285
+ const workingMemoryTemplate = template?.format === "json" ? { ...template, content: JSON.stringify(generateEmptyFromSchema(template.content)) } : template;
286
+ const workingMemory = await memory.getWorkingMemory({ threadId, resourceId, memoryConfig });
287
+ const config = memory.getMergedThreadConfig(memoryConfig || {});
288
+ const source = config.workingMemory?.scope === "resource" && resourceId ? "resource" : "thread";
289
+ return { workingMemory, source, workingMemoryTemplate, threadExists };
290
+ } catch (error) {
291
+ return handleError(error, "Error getting working memory");
292
+ }
293
+ }
294
+ async function updateWorkingMemoryHandler({
295
+ mastra,
296
+ agentId,
297
+ threadId,
298
+ body,
299
+ networkId,
300
+ runtimeContext
301
+ }) {
302
+ try {
303
+ validateBody({ threadId });
304
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
305
+ const { resourceId, memoryConfig, workingMemory } = body;
306
+ if (!memory) {
307
+ throw new HTTPException(400, { message: "Memory is not initialized" });
308
+ }
309
+ const thread = await memory.getThreadById({ threadId });
310
+ if (!thread) {
311
+ throw new HTTPException(404, { message: "Thread not found" });
312
+ }
313
+ await memory.updateWorkingMemory({ threadId, resourceId, workingMemory, memoryConfig });
314
+ return { success: true };
315
+ } catch (error) {
316
+ return handleError(error, "Error updating working memory");
317
+ }
318
+ }
210
319
 
211
- export { createThreadHandler, deleteThreadHandler, getMemoryStatusHandler, getMessagesHandler, getThreadByIdHandler, getThreadsHandler, memory_exports, saveMessagesHandler, updateThreadHandler };
320
+ export { createThreadHandler, deleteThreadHandler, getMemoryStatusHandler, getMessagesHandler, getMessagesPaginatedHandler, getThreadByIdHandler, getThreadsHandler, getWorkingMemoryHandler, memory_exports, saveMessagesHandler, updateThreadHandler, updateWorkingMemoryHandler };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
4
- var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
3
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
4
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
5
5
  var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
6
6
 
7
7
  // src/server/handlers/telemetry.ts
@@ -15,13 +15,13 @@ async function getTelemetryHandler({ mastra, body }) {
15
15
  const telemetry = mastra.getTelemetry();
16
16
  const storage = mastra.getStorage();
17
17
  if (!telemetry) {
18
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Telemetry is not initialized" });
18
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Telemetry is not initialized" });
19
19
  }
20
20
  if (!storage) {
21
21
  return [];
22
22
  }
23
23
  if (!body) {
24
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Body is required" });
24
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Body is required" });
25
25
  }
26
26
  const { name, scope, page, perPage, attribute, fromDate, toDate } = body;
27
27
  const attributes = attribute ? Object.fromEntries(
@@ -41,7 +41,7 @@ async function getTelemetryHandler({ mastra, body }) {
41
41
  });
42
42
  return traces;
43
43
  } catch (error2) {
44
- return chunk64U3UDTH_cjs.handleError(error2, "Error getting telemetry");
44
+ return chunkPZQDCRPV_cjs.handleError(error2, "Error getting telemetry");
45
45
  }
46
46
  }
47
47
  async function storeTelemetryHandler({ mastra, body }) {