@mastra/server 0.0.0-fix-message-list-merge-20250718043058 → 0.0.0-fix-tool-call-history-20250730195323
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 +169 -16
- package/dist/_tsup-dts-rollup.d.ts +169 -16
- package/dist/{chunk-MEGCYGBU.js → chunk-36BLNJHS.js} +37 -37
- package/dist/chunk-424T5F2J.cjs +157 -0
- package/dist/{chunk-B2PAS2IB.cjs → chunk-6KP2OBYA.cjs} +47 -17
- package/dist/chunk-6T5JUKOQ.js +149 -0
- package/dist/{chunk-LI436ITD.cjs → chunk-HISYIDYH.cjs} +37 -37
- package/dist/{chunk-FRVBFMO2.cjs → chunk-HRSAZUIK.cjs} +5 -5
- package/dist/{chunk-LZ3VJXSO.cjs → chunk-I5JKUCGE.cjs} +36 -6
- package/dist/{chunk-KOHWJYJT.js → chunk-PIAJQ75M.js} +248 -5
- package/dist/{chunk-H7DMHBKY.js → chunk-T7HAZC2E.js} +31 -2
- package/dist/{chunk-JMLYCXMK.cjs → chunk-UCV4247U.cjs} +7 -7
- package/dist/{chunk-3CNDE7QY.cjs → chunk-UEVYOKAH.cjs} +251 -4
- package/dist/{chunk-BK4XT6EG.js → chunk-VTTN2FW3.js} +32 -3
- package/dist/{chunk-LRCAAFUA.js → chunk-WBRFIHSF.js} +1 -1
- package/dist/{chunk-5PQQ42EZ.js → chunk-ZYAFP2AV.js} +1 -1
- package/dist/server/handlers/agents.cjs +11 -7
- package/dist/server/handlers/agents.d.cts +1 -0
- package/dist/server/handlers/agents.d.ts +1 -0
- 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 +27 -11
- package/dist/server/handlers/memory.d.cts +4 -0
- package/dist/server/handlers/memory.d.ts +4 -0
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/scores.cjs +30 -0
- package/dist/server/handlers/scores.d.cts +6 -0
- package/dist/server/handlers/scores.d.ts +6 -0
- package/dist/server/handlers/scores.js +1 -0
- package/dist/server/handlers/tools.cjs +5 -5
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/vNextNetwork.cjs +5 -5
- package/dist/server/handlers/vNextNetwork.js +1 -1
- package/dist/server/handlers/workflows.cjs +19 -15
- package/dist/server/handlers/workflows.d.cts +1 -0
- package/dist/server/handlers/workflows.d.ts +1 -0
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +18 -13
- package/dist/server/handlers.d.cts +3 -2
- package/dist/server/handlers.d.ts +3 -2
- package/dist/server/handlers.js +6 -5
- package/package.json +5 -4
|
@@ -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: [agent.name]
|
|
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
|
|
3
|
+
var chunkHISYIDYH_cjs = require('./chunk-HISYIDYH.cjs');
|
|
4
4
|
var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
|
|
5
5
|
var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
|
|
6
6
|
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
@@ -21,6 +21,7 @@ chunk75ZPJI57_cjs.__export(workflows_exports, {
|
|
|
21
21
|
sendWorkflowRunEventHandler: () => sendWorkflowRunEventHandler,
|
|
22
22
|
startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
|
|
23
23
|
startWorkflowRunHandler: () => startWorkflowRunHandler,
|
|
24
|
+
streamVNextWorkflowHandler: () => streamVNextWorkflowHandler,
|
|
24
25
|
streamWorkflowHandler: () => streamWorkflowHandler,
|
|
25
26
|
watchWorkflowHandler: () => watchWorkflowHandler
|
|
26
27
|
});
|
|
@@ -30,10 +31,10 @@ function getSteps(steps, path) {
|
|
|
30
31
|
acc[fullKey] = {
|
|
31
32
|
id: step.id,
|
|
32
33
|
description: step.description,
|
|
33
|
-
inputSchema: step.inputSchema ?
|
|
34
|
-
outputSchema: step.outputSchema ?
|
|
35
|
-
resumeSchema: step.resumeSchema ?
|
|
36
|
-
suspendSchema: step.suspendSchema ?
|
|
34
|
+
inputSchema: step.inputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.inputSchema)) : void 0,
|
|
35
|
+
outputSchema: step.outputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.outputSchema)) : void 0,
|
|
36
|
+
resumeSchema: step.resumeSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
37
|
+
suspendSchema: step.suspendSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.suspendSchema)) : void 0,
|
|
37
38
|
isWorkflow: step.component === "WORKFLOW"
|
|
38
39
|
};
|
|
39
40
|
if (step.component === "WORKFLOW" && step.steps) {
|
|
@@ -54,17 +55,17 @@ async function getWorkflowsHandler({ mastra }) {
|
|
|
54
55
|
acc2[key2] = {
|
|
55
56
|
id: step.id,
|
|
56
57
|
description: step.description,
|
|
57
|
-
inputSchema: step.inputSchema ?
|
|
58
|
-
outputSchema: step.outputSchema ?
|
|
59
|
-
resumeSchema: step.resumeSchema ?
|
|
60
|
-
suspendSchema: step.suspendSchema ?
|
|
58
|
+
inputSchema: step.inputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.inputSchema)) : void 0,
|
|
59
|
+
outputSchema: step.outputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.outputSchema)) : void 0,
|
|
60
|
+
resumeSchema: step.resumeSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
61
|
+
suspendSchema: step.suspendSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.suspendSchema)) : void 0
|
|
61
62
|
};
|
|
62
63
|
return acc2;
|
|
63
64
|
}, {}),
|
|
64
65
|
allSteps: getSteps(workflow.steps) || {},
|
|
65
66
|
stepGraph: workflow.serializedStepGraph,
|
|
66
|
-
inputSchema: workflow.inputSchema ?
|
|
67
|
-
outputSchema: workflow.outputSchema ?
|
|
67
|
+
inputSchema: workflow.inputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(workflow.inputSchema)) : void 0,
|
|
68
|
+
outputSchema: workflow.outputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(workflow.outputSchema)) : void 0
|
|
68
69
|
};
|
|
69
70
|
return acc;
|
|
70
71
|
}, {});
|
|
@@ -121,10 +122,10 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
|
121
122
|
acc[key] = {
|
|
122
123
|
id: step.id,
|
|
123
124
|
description: step.description,
|
|
124
|
-
inputSchema: step.inputSchema ?
|
|
125
|
-
outputSchema: step.outputSchema ?
|
|
126
|
-
resumeSchema: step.resumeSchema ?
|
|
127
|
-
suspendSchema: step.suspendSchema ?
|
|
125
|
+
inputSchema: step.inputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.inputSchema)) : void 0,
|
|
126
|
+
outputSchema: step.outputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.outputSchema)) : void 0,
|
|
127
|
+
resumeSchema: step.resumeSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
128
|
+
suspendSchema: step.suspendSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(step.suspendSchema)) : void 0
|
|
128
129
|
};
|
|
129
130
|
return acc;
|
|
130
131
|
}, {}),
|
|
@@ -132,8 +133,8 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
|
132
133
|
name: workflow.name,
|
|
133
134
|
description: workflow.description,
|
|
134
135
|
stepGraph: workflow.serializedStepGraph,
|
|
135
|
-
inputSchema: workflow.inputSchema ?
|
|
136
|
-
outputSchema: workflow.outputSchema ?
|
|
136
|
+
inputSchema: workflow.inputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(workflow.inputSchema)) : void 0,
|
|
137
|
+
outputSchema: workflow.outputSchema ? chunkHISYIDYH_cjs.stringify(chunkHISYIDYH_cjs.esm_default(workflow.outputSchema)) : void 0
|
|
137
138
|
};
|
|
138
139
|
} catch (error) {
|
|
139
140
|
return chunkPZQDCRPV_cjs.handleError(error, "Error getting workflow");
|
|
@@ -342,6 +343,34 @@ async function streamWorkflowHandler({
|
|
|
342
343
|
return chunkPZQDCRPV_cjs.handleError(error, "Error executing workflow");
|
|
343
344
|
}
|
|
344
345
|
}
|
|
346
|
+
async function streamVNextWorkflowHandler({
|
|
347
|
+
mastra,
|
|
348
|
+
runtimeContext,
|
|
349
|
+
workflowId,
|
|
350
|
+
runId,
|
|
351
|
+
inputData
|
|
352
|
+
}) {
|
|
353
|
+
try {
|
|
354
|
+
if (!workflowId) {
|
|
355
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
356
|
+
}
|
|
357
|
+
if (!runId) {
|
|
358
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to stream workflow" });
|
|
359
|
+
}
|
|
360
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
361
|
+
if (!workflow) {
|
|
362
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
363
|
+
}
|
|
364
|
+
const run = await workflow.createRunAsync({ runId });
|
|
365
|
+
const result = run.streamVNext({
|
|
366
|
+
inputData,
|
|
367
|
+
runtimeContext
|
|
368
|
+
});
|
|
369
|
+
return result;
|
|
370
|
+
} catch (error) {
|
|
371
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error streaming workflow");
|
|
372
|
+
}
|
|
373
|
+
}
|
|
345
374
|
async function resumeAsyncWorkflowHandler({
|
|
346
375
|
mastra,
|
|
347
376
|
workflowId,
|
|
@@ -509,6 +538,7 @@ exports.resumeWorkflowHandler = resumeWorkflowHandler;
|
|
|
509
538
|
exports.sendWorkflowRunEventHandler = sendWorkflowRunEventHandler;
|
|
510
539
|
exports.startAsyncWorkflowHandler = startAsyncWorkflowHandler;
|
|
511
540
|
exports.startWorkflowRunHandler = startWorkflowRunHandler;
|
|
541
|
+
exports.streamVNextWorkflowHandler = streamVNextWorkflowHandler;
|
|
512
542
|
exports.streamWorkflowHandler = streamWorkflowHandler;
|
|
513
543
|
exports.watchWorkflowHandler = watchWorkflowHandler;
|
|
514
544
|
exports.workflows_exports = workflows_exports;
|
|
@@ -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: [agent.name]
|
|
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 };
|