@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
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
4
- var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
5
- var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
3
+ var chunkCCGRCYWJ_cjs = require('./chunk-CCGRCYWJ.cjs');
4
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
5
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
6
6
  var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
7
7
  var stream = require('stream');
8
8
 
@@ -17,19 +17,20 @@ chunk75ZPJI57_cjs.__export(voice_exports, {
17
17
  async function getSpeakersHandler({ mastra, agentId }) {
18
18
  try {
19
19
  if (!agentId) {
20
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
20
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent ID is required" });
21
21
  }
22
22
  const agent = mastra.getAgent(agentId);
23
23
  if (!agent) {
24
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
24
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
25
25
  }
26
- if (!agent.voice) {
27
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
26
+ const voice = await agent.getVoice();
27
+ if (!voice) {
28
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
28
29
  }
29
- const speakers = await agent.voice.getSpeakers();
30
+ const speakers = await voice.getSpeakers();
30
31
  return speakers;
31
32
  } catch (error) {
32
- return chunk64U3UDTH_cjs.handleError(error, "Error getting speakers");
33
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting speakers");
33
34
  }
34
35
  }
35
36
  async function generateSpeechHandler({
@@ -39,25 +40,26 @@ async function generateSpeechHandler({
39
40
  }) {
40
41
  try {
41
42
  if (!agentId) {
42
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
43
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent ID is required" });
43
44
  }
44
- chunk57CJTIPW_cjs.validateBody({
45
+ chunkCCGRCYWJ_cjs.validateBody({
45
46
  text: body?.text
46
47
  });
47
48
  const agent = mastra.getAgent(agentId);
48
49
  if (!agent) {
49
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
50
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
50
51
  }
51
- if (!agent.voice) {
52
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
52
+ const voice = await agent.getVoice();
53
+ if (!voice) {
54
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
53
55
  }
54
- const audioStream = await agent.voice.speak(body.text, { speaker: body.speakerId });
56
+ const audioStream = await voice.speak(body.text, { speaker: body.speakerId });
55
57
  if (!audioStream) {
56
- throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: "Failed to generate speech" });
58
+ throw new chunk2KZFMI6P_cjs.HTTPException(500, { message: "Failed to generate speech" });
57
59
  }
58
60
  return audioStream;
59
61
  } catch (error) {
60
- return chunk64U3UDTH_cjs.handleError(error, "Error generating speech");
62
+ return chunkPZQDCRPV_cjs.handleError(error, "Error generating speech");
61
63
  }
62
64
  }
63
65
  async function transcribeSpeechHandler({
@@ -67,43 +69,45 @@ async function transcribeSpeechHandler({
67
69
  }) {
68
70
  try {
69
71
  if (!agentId) {
70
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
72
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent ID is required" });
71
73
  }
72
74
  if (!body?.audioData) {
73
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Audio data is required" });
75
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Audio data is required" });
74
76
  }
75
77
  const agent = mastra.getAgent(agentId);
76
78
  if (!agent) {
77
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
79
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
78
80
  }
79
- if (!agent.voice) {
80
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
81
+ const voice = await agent.getVoice();
82
+ if (!voice) {
83
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
81
84
  }
82
85
  const audioStream = new stream.Readable();
83
86
  audioStream.push(body.audioData);
84
87
  audioStream.push(null);
85
- const text = await agent.voice.listen(audioStream, body.options);
88
+ const text = await voice.listen(audioStream, body.options);
86
89
  return { text };
87
90
  } catch (error) {
88
- return chunk64U3UDTH_cjs.handleError(error, "Error transcribing speech");
91
+ return chunkPZQDCRPV_cjs.handleError(error, "Error transcribing speech");
89
92
  }
90
93
  }
91
94
  async function getListenerHandler({ mastra, agentId }) {
92
95
  try {
93
96
  if (!agentId) {
94
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
97
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent ID is required" });
95
98
  }
96
99
  const agent = mastra.getAgent(agentId);
97
100
  if (!agent) {
98
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
101
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
99
102
  }
100
- if (!agent.voice) {
101
- throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
103
+ const voice = await agent.getVoice();
104
+ if (!voice) {
105
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
102
106
  }
103
- const listeners = await agent.voice.getListener();
107
+ const listeners = await voice.getListener();
104
108
  return listeners;
105
109
  } catch (error) {
106
- return chunk64U3UDTH_cjs.handleError(error, "Error getting listeners");
110
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting listeners");
107
111
  }
108
112
  }
109
113
 
@@ -1,4 +1,4 @@
1
- import { HTTPException } from './chunk-NYN7KFXL.js';
1
+ import { HTTPException } from './chunk-LCM566I4.js';
2
2
 
3
3
  // src/server/handlers/utils.ts
4
4
  function validateBody(body) {
@@ -0,0 +1,149 @@
1
+ import { handleError } from './chunk-LF7P5PLR.js';
2
+ import { __export } from './chunk-MLKGABMK.js';
3
+
4
+ // src/server/handlers/scores.ts
5
+ var scores_exports = {};
6
+ __export(scores_exports, {
7
+ getScorerHandler: () => getScorerHandler,
8
+ getScorersHandler: () => getScorersHandler,
9
+ getScoresByEntityIdHandler: () => getScoresByEntityIdHandler,
10
+ getScoresByRunIdHandler: () => getScoresByRunIdHandler,
11
+ getScoresByScorerIdHandler: () => getScoresByScorerIdHandler,
12
+ saveScoreHandler: () => saveScoreHandler
13
+ });
14
+ async function getScorersFromSystem({
15
+ mastra,
16
+ runtimeContext
17
+ }) {
18
+ const agents = mastra.getAgents();
19
+ const workflows = mastra.getWorkflows();
20
+ const scorersMap = /* @__PURE__ */ new Map();
21
+ for (const [agentId, agent] of Object.entries(agents)) {
22
+ const scorers = await agent.getScorers({
23
+ runtimeContext
24
+ }) || {};
25
+ if (Object.keys(scorers).length > 0) {
26
+ for (const [scorerId, scorer] of Object.entries(scorers)) {
27
+ if (scorersMap.has(scorerId)) {
28
+ scorersMap.get(scorerId)?.agentIds.push(agentId);
29
+ } else {
30
+ scorersMap.set(scorerId, {
31
+ workflowIds: [],
32
+ ...scorer,
33
+ agentIds: [agentId]
34
+ });
35
+ }
36
+ }
37
+ }
38
+ }
39
+ for (const [workflowId, workflow] of Object.entries(workflows)) {
40
+ const scorers = await workflow.getScorers({
41
+ runtimeContext
42
+ }) || {};
43
+ if (Object.keys(scorers).length > 0) {
44
+ for (const [scorerId, scorer] of Object.entries(scorers)) {
45
+ if (scorersMap.has(scorerId)) {
46
+ scorersMap.get(scorerId)?.workflowIds.push(workflowId);
47
+ } else {
48
+ scorersMap.set(scorerId, {
49
+ agentIds: [],
50
+ ...scorer,
51
+ workflowIds: [workflowId]
52
+ });
53
+ }
54
+ }
55
+ }
56
+ }
57
+ return Object.fromEntries(scorersMap.entries());
58
+ }
59
+ async function getScorersHandler({ mastra, runtimeContext }) {
60
+ const scorers = await getScorersFromSystem({
61
+ mastra,
62
+ runtimeContext
63
+ });
64
+ return scorers;
65
+ }
66
+ async function getScorerHandler({
67
+ mastra,
68
+ scorerId,
69
+ runtimeContext
70
+ }) {
71
+ const scorers = await getScorersFromSystem({
72
+ mastra,
73
+ runtimeContext
74
+ });
75
+ const scorer = scorers[scorerId];
76
+ if (!scorer) {
77
+ return null;
78
+ }
79
+ return scorer;
80
+ }
81
+ async function getScoresByRunIdHandler({
82
+ mastra,
83
+ runId,
84
+ pagination
85
+ }) {
86
+ try {
87
+ const scores = await mastra.getStorage()?.getScoresByRunId?.({
88
+ runId,
89
+ pagination
90
+ }) || [];
91
+ return scores;
92
+ } catch (error) {
93
+ return handleError(error, "Error getting scores by run id");
94
+ }
95
+ }
96
+ async function getScoresByScorerIdHandler({
97
+ mastra,
98
+ scorerId,
99
+ pagination,
100
+ entityId,
101
+ entityType
102
+ }) {
103
+ try {
104
+ const scores = await mastra.getStorage()?.getScoresByScorerId?.({
105
+ scorerId,
106
+ pagination,
107
+ entityId,
108
+ entityType
109
+ }) || [];
110
+ return scores;
111
+ } catch (error) {
112
+ return handleError(error, "Error getting scores by scorer id");
113
+ }
114
+ }
115
+ async function getScoresByEntityIdHandler({
116
+ mastra,
117
+ entityId,
118
+ entityType,
119
+ pagination
120
+ }) {
121
+ try {
122
+ let entityIdToUse = entityId;
123
+ if (entityType === "AGENT") {
124
+ const agent = mastra.getAgentById(entityId);
125
+ entityIdToUse = agent.id;
126
+ } else if (entityType === "WORKFLOW") {
127
+ const workflow = mastra.getWorkflowById(entityId);
128
+ entityIdToUse = workflow.id;
129
+ }
130
+ const scores = await mastra.getStorage()?.getScoresByEntityId?.({
131
+ entityId: entityIdToUse,
132
+ entityType,
133
+ pagination
134
+ }) || [];
135
+ return scores;
136
+ } catch (error) {
137
+ return handleError(error, "Error getting scores by entity id");
138
+ }
139
+ }
140
+ async function saveScoreHandler({ mastra, score }) {
141
+ try {
142
+ const scores = await mastra.getStorage()?.saveScore?.(score) || [];
143
+ return scores;
144
+ } catch (error) {
145
+ return handleError(error, "Error saving score");
146
+ }
147
+ }
148
+
149
+ export { getScorerHandler, getScorersHandler, getScoresByEntityIdHandler, getScoresByRunIdHandler, getScoresByScorerIdHandler, saveScoreHandler, scores_exports };
@@ -1,5 +1,5 @@
1
- import { handleError } from './chunk-M5ABIP7D.js';
2
- import { HTTPException } from './chunk-NYN7KFXL.js';
1
+ import { handleError } from './chunk-LF7P5PLR.js';
2
+ import { HTTPException } from './chunk-LCM566I4.js';
3
3
  import { __export } from './chunk-MLKGABMK.js';
4
4
 
5
5
  // src/server/handlers/vector.ts
@@ -0,0 +1,333 @@
1
+ 'use strict';
2
+
3
+ var chunkCCGRCYWJ_cjs = require('./chunk-CCGRCYWJ.cjs');
4
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
5
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
6
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
7
+ var core = require('@mastra/core');
8
+
9
+ // src/server/handlers/memory.ts
10
+ var memory_exports = {};
11
+ chunk75ZPJI57_cjs.__export(memory_exports, {
12
+ createThreadHandler: () => createThreadHandler,
13
+ deleteThreadHandler: () => deleteThreadHandler,
14
+ getMemoryStatusHandler: () => getMemoryStatusHandler,
15
+ getMessagesHandler: () => getMessagesHandler,
16
+ getMessagesPaginatedHandler: () => getMessagesPaginatedHandler,
17
+ getThreadByIdHandler: () => getThreadByIdHandler,
18
+ getThreadsHandler: () => getThreadsHandler,
19
+ getWorkingMemoryHandler: () => getWorkingMemoryHandler,
20
+ saveMessagesHandler: () => saveMessagesHandler,
21
+ updateThreadHandler: () => updateThreadHandler,
22
+ updateWorkingMemoryHandler: () => updateWorkingMemoryHandler
23
+ });
24
+ async function getMemoryFromContext({
25
+ mastra,
26
+ agentId,
27
+ networkId,
28
+ runtimeContext
29
+ }) {
30
+ const agent = agentId ? mastra.getAgent(agentId) : null;
31
+ if (agentId && !agent) {
32
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
33
+ }
34
+ const network = networkId ? mastra.vnext_getNetwork(networkId) : null;
35
+ if (networkId && !network) {
36
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Network not found" });
37
+ }
38
+ if (agent) {
39
+ return agent?.getMemory() || mastra.getMemory();
40
+ }
41
+ if (network) {
42
+ return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
43
+ }
44
+ return mastra.getMemory();
45
+ }
46
+ async function getMemoryStatusHandler({
47
+ mastra,
48
+ agentId,
49
+ networkId,
50
+ runtimeContext
51
+ }) {
52
+ try {
53
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
54
+ if (!memory) {
55
+ return { result: false };
56
+ }
57
+ return { result: true };
58
+ } catch (error) {
59
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting memory status");
60
+ }
61
+ }
62
+ async function getThreadsHandler({
63
+ mastra,
64
+ agentId,
65
+ resourceId,
66
+ networkId,
67
+ runtimeContext
68
+ }) {
69
+ try {
70
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
71
+ if (!memory) {
72
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
73
+ }
74
+ chunkCCGRCYWJ_cjs.validateBody({ resourceId });
75
+ const threads = await memory.getThreadsByResourceId({ resourceId });
76
+ return threads;
77
+ } catch (error) {
78
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting threads");
79
+ }
80
+ }
81
+ async function getThreadByIdHandler({
82
+ mastra,
83
+ agentId,
84
+ threadId,
85
+ networkId,
86
+ runtimeContext
87
+ }) {
88
+ try {
89
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
90
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
91
+ if (!memory) {
92
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
93
+ }
94
+ const thread = await memory.getThreadById({ threadId });
95
+ if (!thread) {
96
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
97
+ }
98
+ return thread;
99
+ } catch (error) {
100
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting thread");
101
+ }
102
+ }
103
+ async function saveMessagesHandler({
104
+ mastra,
105
+ agentId,
106
+ body,
107
+ networkId,
108
+ runtimeContext
109
+ }) {
110
+ try {
111
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
112
+ if (!memory) {
113
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
114
+ }
115
+ if (!body?.messages) {
116
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Messages are required" });
117
+ }
118
+ if (!Array.isArray(body.messages)) {
119
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Messages should be an array" });
120
+ }
121
+ const processedMessages = body.messages.map((message) => ({
122
+ ...message,
123
+ id: memory.generateId(),
124
+ createdAt: message.createdAt ? new Date(message.createdAt) : /* @__PURE__ */ new Date()
125
+ }));
126
+ const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
127
+ return result;
128
+ } catch (error) {
129
+ return chunkPZQDCRPV_cjs.handleError(error, "Error saving messages");
130
+ }
131
+ }
132
+ async function createThreadHandler({
133
+ mastra,
134
+ agentId,
135
+ body,
136
+ networkId,
137
+ runtimeContext
138
+ }) {
139
+ try {
140
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
141
+ if (!memory) {
142
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
143
+ }
144
+ chunkCCGRCYWJ_cjs.validateBody({ resourceId: body?.resourceId });
145
+ const result = await memory.createThread({
146
+ resourceId: body?.resourceId,
147
+ title: body?.title,
148
+ metadata: body?.metadata,
149
+ threadId: body?.threadId
150
+ });
151
+ return result;
152
+ } catch (error) {
153
+ return chunkPZQDCRPV_cjs.handleError(error, "Error saving thread to memory");
154
+ }
155
+ }
156
+ async function updateThreadHandler({
157
+ mastra,
158
+ agentId,
159
+ threadId,
160
+ body,
161
+ networkId,
162
+ runtimeContext
163
+ }) {
164
+ try {
165
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
166
+ if (!body) {
167
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Body is required" });
168
+ }
169
+ const { title, metadata, resourceId } = body;
170
+ const updatedAt = /* @__PURE__ */ new Date();
171
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
172
+ if (!memory) {
173
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
174
+ }
175
+ const thread = await memory.getThreadById({ threadId });
176
+ if (!thread) {
177
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
178
+ }
179
+ const updatedThread = {
180
+ ...thread,
181
+ title: title || thread.title,
182
+ metadata: metadata || thread.metadata,
183
+ resourceId: resourceId || thread.resourceId,
184
+ createdAt: thread.createdAt,
185
+ updatedAt
186
+ };
187
+ const result = await memory.saveThread({ thread: updatedThread });
188
+ return result;
189
+ } catch (error) {
190
+ return chunkPZQDCRPV_cjs.handleError(error, "Error updating thread");
191
+ }
192
+ }
193
+ async function deleteThreadHandler({
194
+ mastra,
195
+ agentId,
196
+ threadId,
197
+ networkId,
198
+ runtimeContext
199
+ }) {
200
+ try {
201
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
202
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
203
+ if (!memory) {
204
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
205
+ }
206
+ const thread = await memory.getThreadById({ threadId });
207
+ if (!thread) {
208
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
209
+ }
210
+ await memory.deleteThread(threadId);
211
+ return { result: "Thread deleted" };
212
+ } catch (error) {
213
+ return chunkPZQDCRPV_cjs.handleError(error, "Error deleting thread");
214
+ }
215
+ }
216
+ async function getMessagesPaginatedHandler({
217
+ mastra,
218
+ threadId,
219
+ resourceId,
220
+ selectBy,
221
+ format
222
+ }) {
223
+ try {
224
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
225
+ const storage = mastra.getStorage();
226
+ if (!storage) {
227
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Storage is not initialized" });
228
+ }
229
+ const thread = await storage.getThreadById({ threadId });
230
+ if (!thread) {
231
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
232
+ }
233
+ const result = await storage.getMessagesPaginated({ threadId, resourceId, selectBy, format });
234
+ return result;
235
+ } catch (error) {
236
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting messages");
237
+ }
238
+ }
239
+ async function getMessagesHandler({
240
+ mastra,
241
+ agentId,
242
+ threadId,
243
+ limit,
244
+ networkId,
245
+ runtimeContext
246
+ }) {
247
+ if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
248
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Invalid limit: must be a positive integer" });
249
+ }
250
+ try {
251
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
252
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
253
+ if (!memory) {
254
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
255
+ }
256
+ const thread = await memory.getThreadById({ threadId });
257
+ if (!thread) {
258
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
259
+ }
260
+ const result = await memory.query({
261
+ threadId,
262
+ ...limit && { selectBy: { last: limit } }
263
+ });
264
+ return { messages: result.messages, uiMessages: result.uiMessages };
265
+ } catch (error) {
266
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting messages");
267
+ }
268
+ }
269
+ async function getWorkingMemoryHandler({
270
+ mastra,
271
+ agentId,
272
+ threadId,
273
+ resourceId,
274
+ networkId,
275
+ runtimeContext,
276
+ memoryConfig
277
+ }) {
278
+ try {
279
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
280
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
281
+ if (!memory) {
282
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
283
+ }
284
+ const thread = await memory.getThreadById({ threadId });
285
+ const threadExists = !!thread;
286
+ const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
287
+ const workingMemoryTemplate = template?.format === "json" ? { ...template, content: JSON.stringify(core.generateEmptyFromSchema(template.content)) } : template;
288
+ const workingMemory = await memory.getWorkingMemory({ threadId, resourceId, memoryConfig });
289
+ const config = memory.getMergedThreadConfig(memoryConfig || {});
290
+ const source = config.workingMemory?.scope === "resource" && resourceId ? "resource" : "thread";
291
+ return { workingMemory, source, workingMemoryTemplate, threadExists };
292
+ } catch (error) {
293
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting working memory");
294
+ }
295
+ }
296
+ async function updateWorkingMemoryHandler({
297
+ mastra,
298
+ agentId,
299
+ threadId,
300
+ body,
301
+ networkId,
302
+ runtimeContext
303
+ }) {
304
+ try {
305
+ chunkCCGRCYWJ_cjs.validateBody({ threadId });
306
+ const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
307
+ const { resourceId, memoryConfig, workingMemory } = body;
308
+ if (!memory) {
309
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
310
+ }
311
+ const thread = await memory.getThreadById({ threadId });
312
+ if (!thread) {
313
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
314
+ }
315
+ await memory.updateWorkingMemory({ threadId, resourceId, workingMemory, memoryConfig });
316
+ return { success: true };
317
+ } catch (error) {
318
+ return chunkPZQDCRPV_cjs.handleError(error, "Error updating working memory");
319
+ }
320
+ }
321
+
322
+ exports.createThreadHandler = createThreadHandler;
323
+ exports.deleteThreadHandler = deleteThreadHandler;
324
+ exports.getMemoryStatusHandler = getMemoryStatusHandler;
325
+ exports.getMessagesHandler = getMessagesHandler;
326
+ exports.getMessagesPaginatedHandler = getMessagesPaginatedHandler;
327
+ exports.getThreadByIdHandler = getThreadByIdHandler;
328
+ exports.getThreadsHandler = getThreadsHandler;
329
+ exports.getWorkingMemoryHandler = getWorkingMemoryHandler;
330
+ exports.memory_exports = memory_exports;
331
+ exports.saveMessagesHandler = saveMessagesHandler;
332
+ exports.updateThreadHandler = updateThreadHandler;
333
+ exports.updateWorkingMemoryHandler = updateWorkingMemoryHandler;
@@ -1,30 +1,30 @@
1
1
  'use strict';
2
2
 
3
- var chunkA3KDUGS7_cjs = require('../../chunk-A3KDUGS7.cjs');
3
+ var chunkLZ3VJXSO_cjs = require('../../chunk-LZ3VJXSO.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "generateHandler", {
8
8
  enumerable: true,
9
- get: function () { return chunkA3KDUGS7_cjs.generateHandler; }
9
+ get: function () { return chunkLZ3VJXSO_cjs.generateHandler; }
10
10
  });
11
11
  Object.defineProperty(exports, "getAgentByIdHandler", {
12
12
  enumerable: true,
13
- get: function () { return chunkA3KDUGS7_cjs.getAgentByIdHandler; }
13
+ get: function () { return chunkLZ3VJXSO_cjs.getAgentByIdHandler; }
14
14
  });
15
15
  Object.defineProperty(exports, "getAgentsHandler", {
16
16
  enumerable: true,
17
- get: function () { return chunkA3KDUGS7_cjs.getAgentsHandler; }
17
+ get: function () { return chunkLZ3VJXSO_cjs.getAgentsHandler; }
18
18
  });
19
19
  Object.defineProperty(exports, "getEvalsByAgentIdHandler", {
20
20
  enumerable: true,
21
- get: function () { return chunkA3KDUGS7_cjs.getEvalsByAgentIdHandler; }
21
+ get: function () { return chunkLZ3VJXSO_cjs.getEvalsByAgentIdHandler; }
22
22
  });
23
23
  Object.defineProperty(exports, "getLiveEvalsByAgentIdHandler", {
24
24
  enumerable: true,
25
- get: function () { return chunkA3KDUGS7_cjs.getLiveEvalsByAgentIdHandler; }
25
+ get: function () { return chunkLZ3VJXSO_cjs.getLiveEvalsByAgentIdHandler; }
26
26
  });
27
27
  Object.defineProperty(exports, "streamGenerateHandler", {
28
28
  enumerable: true,
29
- get: function () { return chunkA3KDUGS7_cjs.streamGenerateHandler; }
29
+ get: function () { return chunkLZ3VJXSO_cjs.streamGenerateHandler; }
30
30
  });
@@ -1 +1 @@
1
- export { generateHandler, getAgentByIdHandler, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, streamGenerateHandler } from '../../chunk-J3PKLB3A.js';
1
+ export { generateHandler, getAgentByIdHandler, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, streamGenerateHandler } from '../../chunk-BK4XT6EG.js';
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunk64U3UDTH_cjs = require('../../chunk-64U3UDTH.cjs');
3
+ var chunkPZQDCRPV_cjs = require('../../chunk-PZQDCRPV.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "handleError", {
8
8
  enumerable: true,
9
- get: function () { return chunk64U3UDTH_cjs.handleError; }
9
+ get: function () { return chunkPZQDCRPV_cjs.handleError; }
10
10
  });
@@ -1 +1 @@
1
- export { handleError } from '../../chunk-M5ABIP7D.js';
1
+ export { handleError } from '../../chunk-LF7P5PLR.js';