@mastra/server 0.10.7-alpha.1 → 0.10.7-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_tsup-dts-rollup.d.cts +162 -22
- package/dist/_tsup-dts-rollup.d.ts +162 -22
- package/dist/{chunk-WE32JG64.cjs → chunk-4DTDPTQC.cjs} +7 -7
- package/dist/{chunk-NGURCFEJ.cjs → chunk-CPPYMJX5.cjs} +5 -5
- package/dist/{chunk-FYCCJXBC.cjs → chunk-GKM45O24.cjs} +13 -9
- package/dist/{chunk-ASKESBJW.cjs → chunk-MN6F4D5A.cjs} +35 -35
- package/dist/{chunk-CLYX4KLH.js → chunk-N2YBMSO2.js} +1 -1
- package/dist/{chunk-TGJMNUYJ.js → chunk-OSZM4EAY.js} +35 -35
- package/dist/{chunk-GPRXMWEQ.js → chunk-PMUATKV2.js} +9 -5
- package/dist/{chunk-6TJSHFCJ.cjs → chunk-RQ2Z56EC.cjs} +50 -20
- package/dist/{chunk-JKTNRUKY.js → chunk-SOBBILUG.js} +13 -49
- package/dist/{chunk-FRXZL32L.cjs → chunk-TO5U6HW3.cjs} +25 -61
- package/dist/{chunk-2HXKRRNS.js → chunk-XR7VJOOP.js} +1 -1
- package/dist/{chunk-I7KJZNX5.js → chunk-XUIJ7WRT.js} +50 -20
- package/dist/server/handlers/agents.cjs +7 -7
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/legacyWorkflows.cjs +11 -11
- package/dist/server/handlers/legacyWorkflows.js +1 -1
- package/dist/server/handlers/memory.cjs +9 -9
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/tools.cjs +5 -5
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/vNextNetwork.cjs +175 -0
- package/dist/server/handlers/vNextNetwork.d.cts +5 -0
- package/dist/server/handlers/vNextNetwork.d.ts +5 -0
- package/dist/server/handlers/vNextNetwork.js +169 -0
- package/dist/server/handlers/workflows.cjs +13 -13
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +10 -10
- package/dist/server/handlers.js +5 -5
- package/package.json +5 -5
|
@@ -17,20 +17,36 @@ chunk75ZPJI57_cjs.__export(memory_exports, {
|
|
|
17
17
|
saveMessagesHandler: () => saveMessagesHandler,
|
|
18
18
|
updateThreadHandler: () => updateThreadHandler
|
|
19
19
|
});
|
|
20
|
-
function getMemoryFromContext({
|
|
20
|
+
async function getMemoryFromContext({
|
|
21
21
|
mastra,
|
|
22
|
-
agentId
|
|
22
|
+
agentId,
|
|
23
|
+
networkId,
|
|
24
|
+
runtimeContext
|
|
23
25
|
}) {
|
|
24
26
|
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
25
27
|
if (agentId && !agent) {
|
|
26
28
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
27
29
|
}
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
+
const network = networkId ? mastra.vnext_getNetwork(networkId) : null;
|
|
31
|
+
if (networkId && !network) {
|
|
32
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Network not found" });
|
|
33
|
+
}
|
|
34
|
+
if (agent) {
|
|
35
|
+
return agent?.getMemory() || mastra.getMemory();
|
|
36
|
+
}
|
|
37
|
+
if (network) {
|
|
38
|
+
return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
|
|
39
|
+
}
|
|
40
|
+
return mastra.getMemory();
|
|
30
41
|
}
|
|
31
|
-
async function getMemoryStatusHandler({
|
|
42
|
+
async function getMemoryStatusHandler({
|
|
43
|
+
mastra,
|
|
44
|
+
agentId,
|
|
45
|
+
networkId,
|
|
46
|
+
runtimeContext
|
|
47
|
+
}) {
|
|
32
48
|
try {
|
|
33
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
49
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
34
50
|
if (!memory) {
|
|
35
51
|
return { result: false };
|
|
36
52
|
}
|
|
@@ -42,10 +58,12 @@ async function getMemoryStatusHandler({ mastra, agentId }) {
|
|
|
42
58
|
async function getThreadsHandler({
|
|
43
59
|
mastra,
|
|
44
60
|
agentId,
|
|
45
|
-
resourceId
|
|
61
|
+
resourceId,
|
|
62
|
+
networkId,
|
|
63
|
+
runtimeContext
|
|
46
64
|
}) {
|
|
47
65
|
try {
|
|
48
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
66
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
49
67
|
if (!memory) {
|
|
50
68
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
51
69
|
}
|
|
@@ -59,11 +77,13 @@ async function getThreadsHandler({
|
|
|
59
77
|
async function getThreadByIdHandler({
|
|
60
78
|
mastra,
|
|
61
79
|
agentId,
|
|
62
|
-
threadId
|
|
80
|
+
threadId,
|
|
81
|
+
networkId,
|
|
82
|
+
runtimeContext
|
|
63
83
|
}) {
|
|
64
84
|
try {
|
|
65
85
|
chunk57CJTIPW_cjs.validateBody({ threadId });
|
|
66
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
86
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
67
87
|
if (!memory) {
|
|
68
88
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
69
89
|
}
|
|
@@ -79,10 +99,12 @@ async function getThreadByIdHandler({
|
|
|
79
99
|
async function saveMessagesHandler({
|
|
80
100
|
mastra,
|
|
81
101
|
agentId,
|
|
82
|
-
body
|
|
102
|
+
body,
|
|
103
|
+
networkId,
|
|
104
|
+
runtimeContext
|
|
83
105
|
}) {
|
|
84
106
|
try {
|
|
85
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
107
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
86
108
|
if (!memory) {
|
|
87
109
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
88
110
|
}
|
|
@@ -106,10 +128,12 @@ async function saveMessagesHandler({
|
|
|
106
128
|
async function createThreadHandler({
|
|
107
129
|
mastra,
|
|
108
130
|
agentId,
|
|
109
|
-
body
|
|
131
|
+
body,
|
|
132
|
+
networkId,
|
|
133
|
+
runtimeContext
|
|
110
134
|
}) {
|
|
111
135
|
try {
|
|
112
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
136
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
113
137
|
if (!memory) {
|
|
114
138
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
115
139
|
}
|
|
@@ -129,10 +153,12 @@ async function updateThreadHandler({
|
|
|
129
153
|
mastra,
|
|
130
154
|
agentId,
|
|
131
155
|
threadId,
|
|
132
|
-
body
|
|
156
|
+
body,
|
|
157
|
+
networkId,
|
|
158
|
+
runtimeContext
|
|
133
159
|
}) {
|
|
134
160
|
try {
|
|
135
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
161
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
136
162
|
if (!body) {
|
|
137
163
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Body is required" });
|
|
138
164
|
}
|
|
@@ -163,11 +189,13 @@ async function updateThreadHandler({
|
|
|
163
189
|
async function deleteThreadHandler({
|
|
164
190
|
mastra,
|
|
165
191
|
agentId,
|
|
166
|
-
threadId
|
|
192
|
+
threadId,
|
|
193
|
+
networkId,
|
|
194
|
+
runtimeContext
|
|
167
195
|
}) {
|
|
168
196
|
try {
|
|
169
197
|
chunk57CJTIPW_cjs.validateBody({ threadId });
|
|
170
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
198
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
171
199
|
if (!memory) {
|
|
172
200
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
173
201
|
}
|
|
@@ -185,14 +213,16 @@ async function getMessagesHandler({
|
|
|
185
213
|
mastra,
|
|
186
214
|
agentId,
|
|
187
215
|
threadId,
|
|
188
|
-
limit
|
|
216
|
+
limit,
|
|
217
|
+
networkId,
|
|
218
|
+
runtimeContext
|
|
189
219
|
}) {
|
|
190
220
|
if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
|
|
191
221
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Invalid limit: must be a positive integer" });
|
|
192
222
|
}
|
|
193
223
|
try {
|
|
194
224
|
chunk57CJTIPW_cjs.validateBody({ threadId });
|
|
195
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
225
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
196
226
|
if (!memory) {
|
|
197
227
|
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
198
228
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { stringify, esm_default } from './chunk-
|
|
1
|
+
import { stringify, esm_default } from './chunk-OSZM4EAY.js';
|
|
2
2
|
import { handleError } from './chunk-M5ABIP7D.js';
|
|
3
3
|
import { HTTPException } from './chunk-NYN7KFXL.js';
|
|
4
4
|
import { __export } from './chunk-MLKGABMK.js';
|
|
5
5
|
import { ReadableStream } from 'stream/web';
|
|
6
|
-
import { RuntimeContext } from '@mastra/core/di';
|
|
7
6
|
|
|
8
7
|
// src/server/handlers/workflows.ts
|
|
9
8
|
var workflows_exports = {};
|
|
@@ -180,7 +179,7 @@ async function createWorkflowRunHandler({
|
|
|
180
179
|
if (!workflow) {
|
|
181
180
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
182
181
|
}
|
|
183
|
-
const run = workflow.
|
|
182
|
+
const run = await workflow.createRunAsync({ runId: prevRunId });
|
|
184
183
|
return { runId: run.runId };
|
|
185
184
|
} catch (error) {
|
|
186
185
|
throw new HTTPException(500, { message: error?.message || "Error creating workflow run" });
|
|
@@ -188,7 +187,7 @@ async function createWorkflowRunHandler({
|
|
|
188
187
|
}
|
|
189
188
|
async function startAsyncWorkflowHandler({
|
|
190
189
|
mastra,
|
|
191
|
-
runtimeContext
|
|
190
|
+
runtimeContext,
|
|
192
191
|
workflowId,
|
|
193
192
|
runId,
|
|
194
193
|
inputData
|
|
@@ -201,14 +200,7 @@ async function startAsyncWorkflowHandler({
|
|
|
201
200
|
if (!workflow) {
|
|
202
201
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
203
202
|
}
|
|
204
|
-
|
|
205
|
-
if (payloadRuntimeContext) {
|
|
206
|
-
runtimeContext = new RuntimeContext();
|
|
207
|
-
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
208
|
-
runtimeContext.set(key, value);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
const _run = workflow.createRun({ runId });
|
|
203
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
212
204
|
const result = await _run.start({
|
|
213
205
|
inputData,
|
|
214
206
|
runtimeContext
|
|
@@ -220,7 +212,7 @@ async function startAsyncWorkflowHandler({
|
|
|
220
212
|
}
|
|
221
213
|
async function startWorkflowRunHandler({
|
|
222
214
|
mastra,
|
|
223
|
-
runtimeContext
|
|
215
|
+
runtimeContext,
|
|
224
216
|
workflowId,
|
|
225
217
|
runId,
|
|
226
218
|
inputData
|
|
@@ -240,14 +232,7 @@ async function startWorkflowRunHandler({
|
|
|
240
232
|
if (!run) {
|
|
241
233
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
242
234
|
}
|
|
243
|
-
|
|
244
|
-
if (payloadRuntimeContext) {
|
|
245
|
-
runtimeContext = new RuntimeContext();
|
|
246
|
-
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
247
|
-
runtimeContext.set(key, value);
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
const _run = workflow.createRun({ runId });
|
|
235
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
251
236
|
void _run.start({
|
|
252
237
|
inputData,
|
|
253
238
|
runtimeContext
|
|
@@ -277,7 +262,7 @@ async function watchWorkflowHandler({
|
|
|
277
262
|
if (!run) {
|
|
278
263
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
279
264
|
}
|
|
280
|
-
const _run = workflow.
|
|
265
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
281
266
|
let unwatch;
|
|
282
267
|
let asyncRef = null;
|
|
283
268
|
const stream = new ReadableStream({
|
|
@@ -308,7 +293,7 @@ async function watchWorkflowHandler({
|
|
|
308
293
|
}
|
|
309
294
|
async function streamWorkflowHandler({
|
|
310
295
|
mastra,
|
|
311
|
-
runtimeContext
|
|
296
|
+
runtimeContext,
|
|
312
297
|
workflowId,
|
|
313
298
|
runId,
|
|
314
299
|
inputData
|
|
@@ -324,14 +309,7 @@ async function streamWorkflowHandler({
|
|
|
324
309
|
if (!workflow) {
|
|
325
310
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
326
311
|
}
|
|
327
|
-
|
|
328
|
-
if (payloadRuntimeContext) {
|
|
329
|
-
runtimeContext = new RuntimeContext();
|
|
330
|
-
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
331
|
-
runtimeContext.set(key, value);
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
const run = workflow.createRun({ runId });
|
|
312
|
+
const run = await workflow.createRunAsync({ runId });
|
|
335
313
|
const result = run.stream({
|
|
336
314
|
inputData,
|
|
337
315
|
runtimeContext
|
|
@@ -346,7 +324,7 @@ async function resumeAsyncWorkflowHandler({
|
|
|
346
324
|
workflowId,
|
|
347
325
|
runId,
|
|
348
326
|
body,
|
|
349
|
-
runtimeContext
|
|
327
|
+
runtimeContext
|
|
350
328
|
}) {
|
|
351
329
|
try {
|
|
352
330
|
if (!workflowId) {
|
|
@@ -366,14 +344,7 @@ async function resumeAsyncWorkflowHandler({
|
|
|
366
344
|
if (!run) {
|
|
367
345
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
368
346
|
}
|
|
369
|
-
|
|
370
|
-
if (payloadRuntimeContext) {
|
|
371
|
-
runtimeContext = new RuntimeContext();
|
|
372
|
-
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
373
|
-
runtimeContext.set(key, value);
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
const _run = workflow.createRun({ runId });
|
|
347
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
377
348
|
const result = await _run.resume({
|
|
378
349
|
step: body.step,
|
|
379
350
|
resumeData: body.resumeData,
|
|
@@ -389,7 +360,7 @@ async function resumeWorkflowHandler({
|
|
|
389
360
|
workflowId,
|
|
390
361
|
runId,
|
|
391
362
|
body,
|
|
392
|
-
runtimeContext
|
|
363
|
+
runtimeContext
|
|
393
364
|
}) {
|
|
394
365
|
try {
|
|
395
366
|
if (!workflowId) {
|
|
@@ -409,14 +380,7 @@ async function resumeWorkflowHandler({
|
|
|
409
380
|
if (!run) {
|
|
410
381
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
411
382
|
}
|
|
412
|
-
|
|
413
|
-
if (payloadRuntimeContext) {
|
|
414
|
-
runtimeContext = new RuntimeContext();
|
|
415
|
-
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
416
|
-
runtimeContext.set(key, value);
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
const _run = workflow.createRun({ runId });
|
|
383
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
420
384
|
void _run.resume({
|
|
421
385
|
step: body.step,
|
|
422
386
|
resumeData: body.resumeData,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkMN6F4D5A_cjs = require('./chunk-MN6F4D5A.cjs');
|
|
4
4
|
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
5
5
|
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
6
6
|
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
7
7
|
var web = require('stream/web');
|
|
8
|
-
var di = require('@mastra/core/di');
|
|
9
8
|
|
|
10
9
|
// src/server/handlers/workflows.ts
|
|
11
10
|
var workflows_exports = {};
|
|
@@ -34,16 +33,16 @@ async function getWorkflowsHandler({ mastra }) {
|
|
|
34
33
|
acc2[key2] = {
|
|
35
34
|
id: step.id,
|
|
36
35
|
description: step.description,
|
|
37
|
-
inputSchema: step.inputSchema ?
|
|
38
|
-
outputSchema: step.outputSchema ?
|
|
39
|
-
resumeSchema: step.resumeSchema ?
|
|
40
|
-
suspendSchema: step.suspendSchema ?
|
|
36
|
+
inputSchema: step.inputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.inputSchema)) : void 0,
|
|
37
|
+
outputSchema: step.outputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.outputSchema)) : void 0,
|
|
38
|
+
resumeSchema: step.resumeSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
39
|
+
suspendSchema: step.suspendSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.suspendSchema)) : void 0
|
|
41
40
|
};
|
|
42
41
|
return acc2;
|
|
43
42
|
}, {}),
|
|
44
43
|
stepGraph: workflow.serializedStepGraph,
|
|
45
|
-
inputSchema: workflow.inputSchema ?
|
|
46
|
-
outputSchema: workflow.outputSchema ?
|
|
44
|
+
inputSchema: workflow.inputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(workflow.inputSchema)) : void 0,
|
|
45
|
+
outputSchema: workflow.outputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(workflow.outputSchema)) : void 0
|
|
47
46
|
};
|
|
48
47
|
return acc;
|
|
49
48
|
}, {});
|
|
@@ -100,18 +99,18 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
|
100
99
|
acc[key] = {
|
|
101
100
|
id: step.id,
|
|
102
101
|
description: step.description,
|
|
103
|
-
inputSchema: step.inputSchema ?
|
|
104
|
-
outputSchema: step.outputSchema ?
|
|
105
|
-
resumeSchema: step.resumeSchema ?
|
|
106
|
-
suspendSchema: step.suspendSchema ?
|
|
102
|
+
inputSchema: step.inputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.inputSchema)) : void 0,
|
|
103
|
+
outputSchema: step.outputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.outputSchema)) : void 0,
|
|
104
|
+
resumeSchema: step.resumeSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
105
|
+
suspendSchema: step.suspendSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(step.suspendSchema)) : void 0
|
|
107
106
|
};
|
|
108
107
|
return acc;
|
|
109
108
|
}, {}),
|
|
110
109
|
name: workflow.name,
|
|
111
110
|
description: workflow.description,
|
|
112
111
|
stepGraph: workflow.serializedStepGraph,
|
|
113
|
-
inputSchema: workflow.inputSchema ?
|
|
114
|
-
outputSchema: workflow.outputSchema ?
|
|
112
|
+
inputSchema: workflow.inputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(workflow.inputSchema)) : void 0,
|
|
113
|
+
outputSchema: workflow.outputSchema ? chunkMN6F4D5A_cjs.stringify(chunkMN6F4D5A_cjs.esm_default(workflow.outputSchema)) : void 0
|
|
115
114
|
};
|
|
116
115
|
} catch (error) {
|
|
117
116
|
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflow" });
|
|
@@ -182,7 +181,7 @@ async function createWorkflowRunHandler({
|
|
|
182
181
|
if (!workflow) {
|
|
183
182
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
184
183
|
}
|
|
185
|
-
const run = workflow.
|
|
184
|
+
const run = await workflow.createRunAsync({ runId: prevRunId });
|
|
186
185
|
return { runId: run.runId };
|
|
187
186
|
} catch (error) {
|
|
188
187
|
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error creating workflow run" });
|
|
@@ -190,7 +189,7 @@ async function createWorkflowRunHandler({
|
|
|
190
189
|
}
|
|
191
190
|
async function startAsyncWorkflowHandler({
|
|
192
191
|
mastra,
|
|
193
|
-
runtimeContext
|
|
192
|
+
runtimeContext,
|
|
194
193
|
workflowId,
|
|
195
194
|
runId,
|
|
196
195
|
inputData
|
|
@@ -203,14 +202,7 @@ async function startAsyncWorkflowHandler({
|
|
|
203
202
|
if (!workflow) {
|
|
204
203
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
205
204
|
}
|
|
206
|
-
|
|
207
|
-
if (payloadRuntimeContext) {
|
|
208
|
-
runtimeContext = new di.RuntimeContext();
|
|
209
|
-
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
210
|
-
runtimeContext.set(key, value);
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
const _run = workflow.createRun({ runId });
|
|
205
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
214
206
|
const result = await _run.start({
|
|
215
207
|
inputData,
|
|
216
208
|
runtimeContext
|
|
@@ -222,7 +214,7 @@ async function startAsyncWorkflowHandler({
|
|
|
222
214
|
}
|
|
223
215
|
async function startWorkflowRunHandler({
|
|
224
216
|
mastra,
|
|
225
|
-
runtimeContext
|
|
217
|
+
runtimeContext,
|
|
226
218
|
workflowId,
|
|
227
219
|
runId,
|
|
228
220
|
inputData
|
|
@@ -242,14 +234,7 @@ async function startWorkflowRunHandler({
|
|
|
242
234
|
if (!run) {
|
|
243
235
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
244
236
|
}
|
|
245
|
-
|
|
246
|
-
if (payloadRuntimeContext) {
|
|
247
|
-
runtimeContext = new di.RuntimeContext();
|
|
248
|
-
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
249
|
-
runtimeContext.set(key, value);
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
const _run = workflow.createRun({ runId });
|
|
237
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
253
238
|
void _run.start({
|
|
254
239
|
inputData,
|
|
255
240
|
runtimeContext
|
|
@@ -279,7 +264,7 @@ async function watchWorkflowHandler({
|
|
|
279
264
|
if (!run) {
|
|
280
265
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
281
266
|
}
|
|
282
|
-
const _run = workflow.
|
|
267
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
283
268
|
let unwatch;
|
|
284
269
|
let asyncRef = null;
|
|
285
270
|
const stream = new web.ReadableStream({
|
|
@@ -310,7 +295,7 @@ async function watchWorkflowHandler({
|
|
|
310
295
|
}
|
|
311
296
|
async function streamWorkflowHandler({
|
|
312
297
|
mastra,
|
|
313
|
-
runtimeContext
|
|
298
|
+
runtimeContext,
|
|
314
299
|
workflowId,
|
|
315
300
|
runId,
|
|
316
301
|
inputData
|
|
@@ -326,14 +311,7 @@ async function streamWorkflowHandler({
|
|
|
326
311
|
if (!workflow) {
|
|
327
312
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
328
313
|
}
|
|
329
|
-
|
|
330
|
-
if (payloadRuntimeContext) {
|
|
331
|
-
runtimeContext = new di.RuntimeContext();
|
|
332
|
-
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
333
|
-
runtimeContext.set(key, value);
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
const run = workflow.createRun({ runId });
|
|
314
|
+
const run = await workflow.createRunAsync({ runId });
|
|
337
315
|
const result = run.stream({
|
|
338
316
|
inputData,
|
|
339
317
|
runtimeContext
|
|
@@ -348,7 +326,7 @@ async function resumeAsyncWorkflowHandler({
|
|
|
348
326
|
workflowId,
|
|
349
327
|
runId,
|
|
350
328
|
body,
|
|
351
|
-
runtimeContext
|
|
329
|
+
runtimeContext
|
|
352
330
|
}) {
|
|
353
331
|
try {
|
|
354
332
|
if (!workflowId) {
|
|
@@ -368,14 +346,7 @@ async function resumeAsyncWorkflowHandler({
|
|
|
368
346
|
if (!run) {
|
|
369
347
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
370
348
|
}
|
|
371
|
-
|
|
372
|
-
if (payloadRuntimeContext) {
|
|
373
|
-
runtimeContext = new di.RuntimeContext();
|
|
374
|
-
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
375
|
-
runtimeContext.set(key, value);
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
const _run = workflow.createRun({ runId });
|
|
349
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
379
350
|
const result = await _run.resume({
|
|
380
351
|
step: body.step,
|
|
381
352
|
resumeData: body.resumeData,
|
|
@@ -391,7 +362,7 @@ async function resumeWorkflowHandler({
|
|
|
391
362
|
workflowId,
|
|
392
363
|
runId,
|
|
393
364
|
body,
|
|
394
|
-
runtimeContext
|
|
365
|
+
runtimeContext
|
|
395
366
|
}) {
|
|
396
367
|
try {
|
|
397
368
|
if (!workflowId) {
|
|
@@ -411,14 +382,7 @@ async function resumeWorkflowHandler({
|
|
|
411
382
|
if (!run) {
|
|
412
383
|
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
413
384
|
}
|
|
414
|
-
|
|
415
|
-
if (payloadRuntimeContext) {
|
|
416
|
-
runtimeContext = new di.RuntimeContext();
|
|
417
|
-
Object.entries(payloadRuntimeContext || {}).forEach(([key, value]) => {
|
|
418
|
-
runtimeContext.set(key, value);
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
const _run = workflow.createRun({ runId });
|
|
385
|
+
const _run = await workflow.createRunAsync({ runId });
|
|
422
386
|
void _run.resume({
|
|
423
387
|
step: body.step,
|
|
424
388
|
resumeData: body.resumeData,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { stringify, esm_default } from './chunk-
|
|
1
|
+
import { stringify, esm_default } from './chunk-OSZM4EAY.js';
|
|
2
2
|
import { validateBody } from './chunk-H5PTF3Y4.js';
|
|
3
3
|
import { handleError } from './chunk-M5ABIP7D.js';
|
|
4
4
|
import { HTTPException } from './chunk-NYN7KFXL.js';
|
|
@@ -15,20 +15,36 @@ __export(memory_exports, {
|
|
|
15
15
|
saveMessagesHandler: () => saveMessagesHandler,
|
|
16
16
|
updateThreadHandler: () => updateThreadHandler
|
|
17
17
|
});
|
|
18
|
-
function getMemoryFromContext({
|
|
18
|
+
async function getMemoryFromContext({
|
|
19
19
|
mastra,
|
|
20
|
-
agentId
|
|
20
|
+
agentId,
|
|
21
|
+
networkId,
|
|
22
|
+
runtimeContext
|
|
21
23
|
}) {
|
|
22
24
|
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
23
25
|
if (agentId && !agent) {
|
|
24
26
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
25
27
|
}
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
+
const network = networkId ? mastra.vnext_getNetwork(networkId) : null;
|
|
29
|
+
if (networkId && !network) {
|
|
30
|
+
throw new HTTPException(404, { message: "Network not found" });
|
|
31
|
+
}
|
|
32
|
+
if (agent) {
|
|
33
|
+
return agent?.getMemory() || mastra.getMemory();
|
|
34
|
+
}
|
|
35
|
+
if (network) {
|
|
36
|
+
return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
|
|
37
|
+
}
|
|
38
|
+
return mastra.getMemory();
|
|
28
39
|
}
|
|
29
|
-
async function getMemoryStatusHandler({
|
|
40
|
+
async function getMemoryStatusHandler({
|
|
41
|
+
mastra,
|
|
42
|
+
agentId,
|
|
43
|
+
networkId,
|
|
44
|
+
runtimeContext
|
|
45
|
+
}) {
|
|
30
46
|
try {
|
|
31
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
47
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
32
48
|
if (!memory) {
|
|
33
49
|
return { result: false };
|
|
34
50
|
}
|
|
@@ -40,10 +56,12 @@ async function getMemoryStatusHandler({ mastra, agentId }) {
|
|
|
40
56
|
async function getThreadsHandler({
|
|
41
57
|
mastra,
|
|
42
58
|
agentId,
|
|
43
|
-
resourceId
|
|
59
|
+
resourceId,
|
|
60
|
+
networkId,
|
|
61
|
+
runtimeContext
|
|
44
62
|
}) {
|
|
45
63
|
try {
|
|
46
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
64
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
47
65
|
if (!memory) {
|
|
48
66
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
49
67
|
}
|
|
@@ -57,11 +75,13 @@ async function getThreadsHandler({
|
|
|
57
75
|
async function getThreadByIdHandler({
|
|
58
76
|
mastra,
|
|
59
77
|
agentId,
|
|
60
|
-
threadId
|
|
78
|
+
threadId,
|
|
79
|
+
networkId,
|
|
80
|
+
runtimeContext
|
|
61
81
|
}) {
|
|
62
82
|
try {
|
|
63
83
|
validateBody({ threadId });
|
|
64
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
84
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
65
85
|
if (!memory) {
|
|
66
86
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
67
87
|
}
|
|
@@ -77,10 +97,12 @@ async function getThreadByIdHandler({
|
|
|
77
97
|
async function saveMessagesHandler({
|
|
78
98
|
mastra,
|
|
79
99
|
agentId,
|
|
80
|
-
body
|
|
100
|
+
body,
|
|
101
|
+
networkId,
|
|
102
|
+
runtimeContext
|
|
81
103
|
}) {
|
|
82
104
|
try {
|
|
83
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
105
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
84
106
|
if (!memory) {
|
|
85
107
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
86
108
|
}
|
|
@@ -104,10 +126,12 @@ async function saveMessagesHandler({
|
|
|
104
126
|
async function createThreadHandler({
|
|
105
127
|
mastra,
|
|
106
128
|
agentId,
|
|
107
|
-
body
|
|
129
|
+
body,
|
|
130
|
+
networkId,
|
|
131
|
+
runtimeContext
|
|
108
132
|
}) {
|
|
109
133
|
try {
|
|
110
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
134
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
111
135
|
if (!memory) {
|
|
112
136
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
113
137
|
}
|
|
@@ -127,10 +151,12 @@ async function updateThreadHandler({
|
|
|
127
151
|
mastra,
|
|
128
152
|
agentId,
|
|
129
153
|
threadId,
|
|
130
|
-
body
|
|
154
|
+
body,
|
|
155
|
+
networkId,
|
|
156
|
+
runtimeContext
|
|
131
157
|
}) {
|
|
132
158
|
try {
|
|
133
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
159
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
134
160
|
if (!body) {
|
|
135
161
|
throw new HTTPException(400, { message: "Body is required" });
|
|
136
162
|
}
|
|
@@ -161,11 +187,13 @@ async function updateThreadHandler({
|
|
|
161
187
|
async function deleteThreadHandler({
|
|
162
188
|
mastra,
|
|
163
189
|
agentId,
|
|
164
|
-
threadId
|
|
190
|
+
threadId,
|
|
191
|
+
networkId,
|
|
192
|
+
runtimeContext
|
|
165
193
|
}) {
|
|
166
194
|
try {
|
|
167
195
|
validateBody({ threadId });
|
|
168
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
196
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
169
197
|
if (!memory) {
|
|
170
198
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
171
199
|
}
|
|
@@ -183,14 +211,16 @@ async function getMessagesHandler({
|
|
|
183
211
|
mastra,
|
|
184
212
|
agentId,
|
|
185
213
|
threadId,
|
|
186
|
-
limit
|
|
214
|
+
limit,
|
|
215
|
+
networkId,
|
|
216
|
+
runtimeContext
|
|
187
217
|
}) {
|
|
188
218
|
if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
|
|
189
219
|
throw new HTTPException(400, { message: "Invalid limit: must be a positive integer" });
|
|
190
220
|
}
|
|
191
221
|
try {
|
|
192
222
|
validateBody({ threadId });
|
|
193
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
223
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
194
224
|
if (!memory) {
|
|
195
225
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
196
226
|
}
|