@mastra/server 0.0.0-update-scorers-api-20250801170445 → 0.0.0-usechat-duplicate-20251016110554
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4048 -0
- package/README.md +0 -5
- package/dist/chunk-2PLXW4ZX.cjs +2777 -0
- package/dist/chunk-2PLXW4ZX.cjs.map +1 -0
- package/dist/chunk-2S4IMB6E.cjs +130 -0
- package/dist/chunk-2S4IMB6E.cjs.map +1 -0
- package/dist/{chunk-X5SDJOY6.cjs → chunk-3LTO44EP.cjs} +66 -53
- package/dist/chunk-3LTO44EP.cjs.map +1 -0
- package/dist/{chunk-4US5W7PH.cjs → chunk-3SNGNFUJ.cjs} +23 -15
- package/dist/chunk-3SNGNFUJ.cjs.map +1 -0
- package/dist/{chunk-OW4FX5TS.js → chunk-4QCXUEAT.js} +10 -3
- package/dist/chunk-4QCXUEAT.js.map +1 -0
- package/dist/{chunk-SQ7KKIH3.js → chunk-67GYDFSB.js} +22 -5
- package/dist/chunk-67GYDFSB.js.map +1 -0
- package/dist/{chunk-ILCWPBYQ.cjs → chunk-6ZR275MD.cjs} +23 -5
- package/dist/chunk-6ZR275MD.cjs.map +1 -0
- package/dist/chunk-7HDOBOGG.cjs +17517 -0
- package/dist/chunk-7HDOBOGG.cjs.map +1 -0
- package/dist/{chunk-4MQU6AJN.js → chunk-ABRFV4XP.js} +4 -4
- package/dist/{chunk-4MQU6AJN.js.map → chunk-ABRFV4XP.js.map} +1 -1
- package/dist/{chunk-YS66MFDY.js → chunk-AHB4JCIQ.js} +48 -12
- package/dist/chunk-AHB4JCIQ.js.map +1 -0
- package/dist/{chunk-TXAQU2XN.js → chunk-AW5BU3RQ.js} +63 -22
- package/dist/chunk-AW5BU3RQ.js.map +1 -0
- package/dist/chunk-BATEJLED.js +124 -0
- package/dist/chunk-BATEJLED.js.map +1 -0
- package/dist/chunk-BZLZFHAT.cjs +682 -0
- package/dist/chunk-BZLZFHAT.cjs.map +1 -0
- package/dist/{chunk-BUOJL3MN.js → chunk-DB63UMTV.js} +220 -89
- package/dist/chunk-DB63UMTV.js.map +1 -0
- package/dist/{chunk-NCS2OXX6.cjs → chunk-EP3JQDPD.cjs} +4 -4
- package/dist/{chunk-NCS2OXX6.cjs.map → chunk-EP3JQDPD.cjs.map} +1 -1
- package/dist/chunk-FWO7VQDC.js +17481 -0
- package/dist/chunk-FWO7VQDC.js.map +1 -0
- package/dist/chunk-FZNS32WJ.js +46 -0
- package/dist/chunk-FZNS32WJ.js.map +1 -0
- package/dist/{chunk-4QSNRCOT.cjs → chunk-G4PUALCE.cjs} +10 -2
- package/dist/chunk-G4PUALCE.cjs.map +1 -0
- package/dist/chunk-GU4EWMZB.cjs +769 -0
- package/dist/chunk-GU4EWMZB.cjs.map +1 -0
- package/dist/{chunk-TRWPUPGD.js → chunk-HPXAM2PG.js} +109 -138
- package/dist/chunk-HPXAM2PG.js.map +1 -0
- package/dist/{chunk-JGVY3KWV.cjs → chunk-I3C4ODGV.cjs} +12 -11
- package/dist/chunk-I3C4ODGV.cjs.map +1 -0
- package/dist/chunk-JSLAYFEW.js +662 -0
- package/dist/chunk-JSLAYFEW.js.map +1 -0
- package/dist/chunk-LF2ZLOFP.js +767 -0
- package/dist/chunk-LF2ZLOFP.js.map +1 -0
- package/dist/{chunk-UVOSITKU.js → chunk-LLUOPR3J.js} +11 -10
- package/dist/chunk-LLUOPR3J.js.map +1 -0
- package/dist/chunk-LPM6BBAX.cjs +1043 -0
- package/dist/chunk-LPM6BBAX.cjs.map +1 -0
- package/dist/{chunk-S37KCGOR.cjs → chunk-MQDBNHBT.cjs} +222 -88
- package/dist/chunk-MQDBNHBT.cjs.map +1 -0
- package/dist/{chunk-G7NVCO5M.js → chunk-MYR4PVGN.js} +3 -3
- package/dist/{chunk-G7NVCO5M.js.map → chunk-MYR4PVGN.js.map} +1 -1
- package/dist/chunk-O7I5CWRX.cjs +44 -0
- package/dist/{chunk-Q7SFCCGT.cjs.map → chunk-O7I5CWRX.cjs.map} +1 -1
- package/dist/{chunk-HXIOPAHT.js → chunk-OEOGYAQC.js} +54 -42
- package/dist/chunk-OEOGYAQC.js.map +1 -0
- package/dist/chunk-OYL5TBJW.cjs +48 -0
- package/dist/chunk-OYL5TBJW.cjs.map +1 -0
- package/dist/chunk-PR4QN5HX.js +39 -0
- package/dist/{chunk-PZ5AY32C.js.map → chunk-PR4QN5HX.js.map} +1 -1
- package/dist/{chunk-HWHKM67I.js → chunk-QQXMIP6C.js} +21 -13
- package/dist/chunk-QQXMIP6C.js.map +1 -0
- package/dist/chunk-RQK4FQUD.js +1012 -0
- package/dist/chunk-RQK4FQUD.js.map +1 -0
- package/dist/chunk-SIW6CYO3.js +254 -0
- package/dist/chunk-SIW6CYO3.js.map +1 -0
- package/dist/{chunk-VIGPWTDA.cjs → chunk-SPRRK3P7.cjs} +64 -23
- package/dist/chunk-SPRRK3P7.cjs.map +1 -0
- package/dist/{chunk-GASWM5HJ.cjs → chunk-TOP25AIO.cjs} +110 -139
- package/dist/chunk-TOP25AIO.cjs.map +1 -0
- package/dist/{chunk-O4I563YW.cjs → chunk-TRGAMKHX.cjs} +50 -13
- package/dist/chunk-TRGAMKHX.cjs.map +1 -0
- package/dist/chunk-VY4ENABS.cjs +135 -0
- package/dist/chunk-VY4ENABS.cjs.map +1 -0
- package/dist/{chunk-BED2O446.cjs → chunk-XN74I6VW.cjs} +7 -7
- package/dist/{chunk-BED2O446.cjs.map → chunk-XN74I6VW.cjs.map} +1 -1
- package/dist/chunk-XVPBGW6Y.cjs +256 -0
- package/dist/chunk-XVPBGW6Y.cjs.map +1 -0
- package/dist/chunk-YWOK4F5A.js +131 -0
- package/dist/chunk-YWOK4F5A.js.map +1 -0
- package/dist/chunk-ZULZ2752.js +2774 -0
- package/dist/chunk-ZULZ2752.js.map +1 -0
- package/dist/dist-4MVGNSRL.cjs +1150 -0
- package/dist/dist-4MVGNSRL.cjs.map +1 -0
- package/dist/dist-FZYCV3VB.cjs +940 -0
- package/dist/dist-FZYCV3VB.cjs.map +1 -0
- package/dist/dist-G2BYZJOC.cjs +928 -0
- package/dist/dist-G2BYZJOC.cjs.map +1 -0
- package/dist/dist-P4MXBQ3U.cjs +16 -0
- package/dist/dist-P4MXBQ3U.cjs.map +1 -0
- package/dist/dist-PQZUVLPC.js +937 -0
- package/dist/dist-PQZUVLPC.js.map +1 -0
- package/dist/dist-R7WYX6LC.js +925 -0
- package/dist/dist-R7WYX6LC.js.map +1 -0
- package/dist/dist-RFMYFILX.cjs +764 -0
- package/dist/dist-RFMYFILX.cjs.map +1 -0
- package/dist/dist-X7XR3M3Z.js +1147 -0
- package/dist/dist-X7XR3M3Z.js.map +1 -0
- package/dist/dist-XVBSOGFK.js +761 -0
- package/dist/dist-XVBSOGFK.js.map +1 -0
- package/dist/dist-YREX2TJT.js +3 -0
- package/dist/dist-YREX2TJT.js.map +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/server/a2a/store.cjs +25 -0
- package/dist/server/a2a/store.cjs.map +1 -0
- package/dist/server/a2a/store.d.ts +3 -3
- package/dist/server/a2a/store.d.ts.map +1 -1
- package/dist/server/a2a/store.js +23 -0
- package/dist/server/a2a/store.js.map +1 -0
- package/dist/server/a2a/tasks.d.ts +7 -7
- package/dist/server/a2a/tasks.d.ts.map +1 -1
- package/dist/server/handlers/a2a.cjs +11 -11
- package/dist/server/handlers/a2a.d.ts +17 -15
- package/dist/server/handlers/a2a.d.ts.map +1 -1
- package/dist/server/handlers/a2a.js +1 -1
- package/dist/server/handlers/agent-builder.cjs +68 -0
- package/dist/server/handlers/agent-builder.cjs.map +1 -0
- package/dist/server/handlers/agent-builder.d.ts +94 -0
- package/dist/server/handlers/agent-builder.d.ts.map +1 -0
- package/dist/server/handlers/agent-builder.js +3 -0
- package/dist/server/handlers/agent-builder.js.map +1 -0
- package/dist/server/handlers/agents.cjs +53 -9
- package/dist/server/handlers/agents.d.ts +156 -33
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/legacyWorkflows.cjs +11 -11
- package/dist/server/handlers/legacyWorkflows.d.ts +1 -1
- package/dist/server/handlers/legacyWorkflows.d.ts.map +1 -1
- package/dist/server/handlers/legacyWorkflows.js +1 -1
- package/dist/server/handlers/logs.cjs +4 -4
- package/dist/server/handlers/logs.js +1 -1
- package/dist/server/handlers/memory.cjs +19 -15
- package/dist/server/handlers/memory.d.ts +24 -19
- package/dist/server/handlers/memory.d.ts.map +1 -1
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/observability.cjs +24 -0
- package/dist/server/handlers/observability.cjs.map +1 -0
- package/dist/server/handlers/observability.d.ts +49 -0
- package/dist/server/handlers/observability.d.ts.map +1 -0
- package/dist/server/handlers/observability.js +3 -0
- package/dist/server/handlers/observability.js.map +1 -0
- package/dist/server/handlers/scores.cjs +7 -7
- package/dist/server/handlers/scores.d.ts +110 -7
- package/dist/server/handlers/scores.d.ts.map +1 -1
- package/dist/server/handlers/scores.js +1 -1
- package/dist/server/handlers/telemetry.cjs +7 -3
- package/dist/server/handlers/telemetry.d.ts +2 -1
- package/dist/server/handlers/telemetry.d.ts.map +1 -1
- package/dist/server/handlers/telemetry.js +1 -1
- package/dist/server/handlers/tools.cjs +9 -5
- package/dist/server/handlers/tools.d.ts +5 -1
- package/dist/server/handlers/tools.d.ts.map +1 -1
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/utils.cjs +6 -2
- package/dist/server/handlers/utils.d.ts +6 -0
- package/dist/server/handlers/utils.d.ts.map +1 -1
- package/dist/server/handlers/utils.js +1 -1
- package/dist/server/handlers/vector.cjs +7 -7
- package/dist/server/handlers/vector.d.ts +1 -1
- package/dist/server/handlers/vector.js +1 -1
- package/dist/server/handlers/voice.cjs +5 -5
- package/dist/server/handlers/voice.d.ts +7 -5
- package/dist/server/handlers/voice.d.ts.map +1 -1
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +28 -16
- package/dist/server/handlers/workflows.d.ts +37 -34
- package/dist/server/handlers/workflows.d.ts.map +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +38 -33
- package/dist/server/handlers.d.ts +13 -12
- package/dist/server/handlers.d.ts.map +1 -1
- package/dist/server/handlers.js +13 -12
- package/dist/server/utils.d.ts +44 -0
- package/dist/server/utils.d.ts.map +1 -0
- package/dist/token-53CFGXUO.cjs +64 -0
- package/dist/token-53CFGXUO.cjs.map +1 -0
- package/dist/token-WAEKDUVY.js +62 -0
- package/dist/token-WAEKDUVY.js.map +1 -0
- package/dist/token-util-LY37VCIN.js +7 -0
- package/dist/token-util-LY37VCIN.js.map +1 -0
- package/dist/token-util-S4A355II.cjs +9 -0
- package/dist/token-util-S4A355II.cjs.map +1 -0
- package/package.json +36 -14
- package/dist/chunk-2XIJW7SV.cjs +0 -310
- package/dist/chunk-2XIJW7SV.cjs.map +0 -1
- package/dist/chunk-4CEZIJWJ.cjs +0 -150
- package/dist/chunk-4CEZIJWJ.cjs.map +0 -1
- package/dist/chunk-4QSNRCOT.cjs.map +0 -1
- package/dist/chunk-4US5W7PH.cjs.map +0 -1
- package/dist/chunk-7FHF55WA.js +0 -2041
- package/dist/chunk-7FHF55WA.js.map +0 -1
- package/dist/chunk-BUOJL3MN.js.map +0 -1
- package/dist/chunk-GASWM5HJ.cjs.map +0 -1
- package/dist/chunk-HWHKM67I.js.map +0 -1
- package/dist/chunk-HXIOPAHT.js.map +0 -1
- package/dist/chunk-ILCWPBYQ.cjs.map +0 -1
- package/dist/chunk-JGVY3KWV.cjs.map +0 -1
- package/dist/chunk-LRUH33B4.cjs +0 -2044
- package/dist/chunk-LRUH33B4.cjs.map +0 -1
- package/dist/chunk-O4I563YW.cjs.map +0 -1
- package/dist/chunk-OW4FX5TS.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -9
- package/dist/chunk-Q7SFCCGT.cjs +0 -11
- package/dist/chunk-S37KCGOR.cjs.map +0 -1
- package/dist/chunk-SQ7KKIH3.js.map +0 -1
- package/dist/chunk-TRWPUPGD.js.map +0 -1
- package/dist/chunk-TXAQU2XN.js.map +0 -1
- package/dist/chunk-UVOSITKU.js.map +0 -1
- package/dist/chunk-VIGPWTDA.cjs.map +0 -1
- package/dist/chunk-VOY6MGKA.js +0 -301
- package/dist/chunk-VOY6MGKA.js.map +0 -1
- package/dist/chunk-X5SDJOY6.cjs.map +0 -1
- package/dist/chunk-Y3J45CVZ.js +0 -144
- package/dist/chunk-Y3J45CVZ.js.map +0 -1
- package/dist/chunk-YS66MFDY.js.map +0 -1
- package/dist/server/handlers/network.cjs +0 -24
- package/dist/server/handlers/network.cjs.map +0 -1
- package/dist/server/handlers/network.d.ts +0 -50
- package/dist/server/handlers/network.d.ts.map +0 -1
- package/dist/server/handlers/network.js +0 -3
- package/dist/server/handlers/network.js.map +0 -1
- package/dist/server/handlers/vNextNetwork.cjs +0 -220
- package/dist/server/handlers/vNextNetwork.cjs.map +0 -1
- package/dist/server/handlers/vNextNetwork.d.ts +0 -179
- package/dist/server/handlers/vNextNetwork.d.ts.map +0 -1
- package/dist/server/handlers/vNextNetwork.js +0 -213
- package/dist/server/handlers/vNextNetwork.js.map +0 -1
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
import { sanitizeBody, validateBody } from './chunk-4QCXUEAT.js';
|
|
2
|
+
import { stringify } from './chunk-LF2ZLOFP.js';
|
|
3
|
+
import { handleError } from './chunk-CY4TP3FK.js';
|
|
4
|
+
import { HTTPException } from './chunk-MMROOK5J.js';
|
|
5
|
+
import { __export } from './chunk-PR4QN5HX.js';
|
|
6
|
+
import { PROVIDER_REGISTRY } from '@mastra/core/llm';
|
|
7
|
+
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
8
|
+
import { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';
|
|
9
|
+
|
|
10
|
+
// src/server/handlers/agents.ts
|
|
11
|
+
var agents_exports = {};
|
|
12
|
+
__export(agents_exports, {
|
|
13
|
+
approveToolCallHandler: () => approveToolCallHandler,
|
|
14
|
+
declineToolCallHandler: () => declineToolCallHandler,
|
|
15
|
+
generateHandler: () => generateHandler,
|
|
16
|
+
generateLegacyHandler: () => generateLegacyHandler,
|
|
17
|
+
getAgentByIdHandler: () => getAgentByIdHandler,
|
|
18
|
+
getAgentsHandler: () => getAgentsHandler,
|
|
19
|
+
getEvalsByAgentIdHandler: () => getEvalsByAgentIdHandler,
|
|
20
|
+
getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
|
|
21
|
+
getProvidersHandler: () => getProvidersHandler,
|
|
22
|
+
getSerializedAgentTools: () => getSerializedAgentTools,
|
|
23
|
+
getSerializedProcessors: () => getSerializedProcessors,
|
|
24
|
+
reorderAgentModelListHandler: () => reorderAgentModelListHandler,
|
|
25
|
+
streamGenerateHandler: () => streamGenerateHandler,
|
|
26
|
+
streamGenerateLegacyHandler: () => streamGenerateLegacyHandler,
|
|
27
|
+
streamNetworkHandler: () => streamNetworkHandler,
|
|
28
|
+
streamUIMessageHandler: () => streamUIMessageHandler,
|
|
29
|
+
updateAgentModelHandler: () => updateAgentModelHandler,
|
|
30
|
+
updateAgentModelInModelListHandler: () => updateAgentModelInModelListHandler
|
|
31
|
+
});
|
|
32
|
+
async function getSerializedAgentTools(tools) {
|
|
33
|
+
return Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
34
|
+
const _tool = tool;
|
|
35
|
+
const toolId = _tool.id ?? `tool-${key}`;
|
|
36
|
+
let inputSchemaForReturn = void 0;
|
|
37
|
+
if (_tool.inputSchema) {
|
|
38
|
+
if (_tool.inputSchema && typeof _tool.inputSchema === "object" && "jsonSchema" in _tool.inputSchema) {
|
|
39
|
+
inputSchemaForReturn = stringify(_tool.inputSchema.jsonSchema);
|
|
40
|
+
} else if (_tool.inputSchema) {
|
|
41
|
+
inputSchemaForReturn = stringify(zodToJsonSchema(_tool.inputSchema));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let outputSchemaForReturn = void 0;
|
|
45
|
+
if (_tool.outputSchema) {
|
|
46
|
+
if (_tool.outputSchema && typeof _tool.outputSchema === "object" && "jsonSchema" in _tool.outputSchema) {
|
|
47
|
+
outputSchemaForReturn = stringify(_tool.outputSchema.jsonSchema);
|
|
48
|
+
} else if (_tool.outputSchema) {
|
|
49
|
+
outputSchemaForReturn = stringify(zodToJsonSchema(_tool.outputSchema));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
acc[key] = {
|
|
53
|
+
..._tool,
|
|
54
|
+
id: toolId,
|
|
55
|
+
inputSchema: inputSchemaForReturn,
|
|
56
|
+
outputSchema: outputSchemaForReturn
|
|
57
|
+
};
|
|
58
|
+
return acc;
|
|
59
|
+
}, {});
|
|
60
|
+
}
|
|
61
|
+
function getSerializedProcessors(processors) {
|
|
62
|
+
return processors.map((processor) => {
|
|
63
|
+
return {
|
|
64
|
+
name: processor.name || processor.constructor.name
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async function getSerializedAgentDefinition({
|
|
69
|
+
agent,
|
|
70
|
+
runtimeContext
|
|
71
|
+
}) {
|
|
72
|
+
let serializedAgentAgents = {};
|
|
73
|
+
if ("listAgents" in agent) {
|
|
74
|
+
const agents = await agent.listAgents({ runtimeContext });
|
|
75
|
+
serializedAgentAgents = Object.entries(agents || {}).reduce(
|
|
76
|
+
(acc, [key, agent2]) => {
|
|
77
|
+
return {
|
|
78
|
+
...acc,
|
|
79
|
+
[key]: { id: agent2.id, name: agent2.name }
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
{}
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return serializedAgentAgents;
|
|
86
|
+
}
|
|
87
|
+
async function formatAgentList({
|
|
88
|
+
id,
|
|
89
|
+
mastra,
|
|
90
|
+
agent,
|
|
91
|
+
runtimeContext
|
|
92
|
+
}) {
|
|
93
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
94
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
95
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
96
|
+
const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext });
|
|
97
|
+
const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext });
|
|
98
|
+
const serializedAgentTools = await getSerializedAgentTools(tools);
|
|
99
|
+
let serializedAgentWorkflows = {};
|
|
100
|
+
if ("getWorkflows" in agent) {
|
|
101
|
+
const logger = mastra.getLogger();
|
|
102
|
+
try {
|
|
103
|
+
const workflows = await agent.getWorkflows({ runtimeContext });
|
|
104
|
+
serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
|
|
105
|
+
return {
|
|
106
|
+
...acc,
|
|
107
|
+
[key]: {
|
|
108
|
+
name: workflow.name || "Unnamed workflow"
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}, {});
|
|
112
|
+
} catch (error) {
|
|
113
|
+
logger.error("Error getting workflows for agent", { agentName: agent.name, error });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const serializedAgentAgents = await getSerializedAgentDefinition({ agent, runtimeContext });
|
|
117
|
+
const inputProcessors = await agent.getInputProcessors(runtimeContext);
|
|
118
|
+
const outputProcessors = await agent.getOutputProcessors(runtimeContext);
|
|
119
|
+
const serializedInputProcessors = getSerializedProcessors(inputProcessors);
|
|
120
|
+
const serializedOutputProcessors = getSerializedProcessors(outputProcessors);
|
|
121
|
+
const model = llm?.getModel();
|
|
122
|
+
const models = await agent.getModelList(runtimeContext);
|
|
123
|
+
const modelList = models?.map((md) => ({
|
|
124
|
+
...md,
|
|
125
|
+
model: {
|
|
126
|
+
modelId: md.model.modelId,
|
|
127
|
+
provider: md.model.provider,
|
|
128
|
+
modelVersion: md.model.specificationVersion
|
|
129
|
+
}
|
|
130
|
+
}));
|
|
131
|
+
return {
|
|
132
|
+
id,
|
|
133
|
+
name: agent.name,
|
|
134
|
+
instructions,
|
|
135
|
+
agents: serializedAgentAgents,
|
|
136
|
+
tools: serializedAgentTools,
|
|
137
|
+
workflows: serializedAgentWorkflows,
|
|
138
|
+
inputProcessors: serializedInputProcessors,
|
|
139
|
+
outputProcessors: serializedOutputProcessors,
|
|
140
|
+
provider: llm?.getProvider(),
|
|
141
|
+
modelId: llm?.getModelId(),
|
|
142
|
+
modelVersion: model?.specificationVersion,
|
|
143
|
+
defaultGenerateOptions,
|
|
144
|
+
defaultStreamOptions,
|
|
145
|
+
modelList
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
async function getAgentsHandler({
|
|
149
|
+
mastra,
|
|
150
|
+
runtimeContext
|
|
151
|
+
}) {
|
|
152
|
+
try {
|
|
153
|
+
const agents = mastra.getAgents();
|
|
154
|
+
const serializedAgentsMap = await Promise.all(
|
|
155
|
+
Object.entries(agents).map(async ([id, agent]) => {
|
|
156
|
+
return formatAgentList({ id, mastra, agent, runtimeContext });
|
|
157
|
+
})
|
|
158
|
+
);
|
|
159
|
+
const serializedAgents = serializedAgentsMap.reduce((acc, { id, ...rest }) => {
|
|
160
|
+
acc[id] = rest;
|
|
161
|
+
return acc;
|
|
162
|
+
}, {});
|
|
163
|
+
return serializedAgents;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
return handleError(error, "Error getting agents");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async function formatAgent({
|
|
169
|
+
mastra,
|
|
170
|
+
agent,
|
|
171
|
+
runtimeContext,
|
|
172
|
+
isPlayground
|
|
173
|
+
}) {
|
|
174
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
175
|
+
const serializedAgentTools = await getSerializedAgentTools(tools);
|
|
176
|
+
let serializedAgentWorkflows = {};
|
|
177
|
+
if ("getWorkflows" in agent) {
|
|
178
|
+
const logger = mastra.getLogger();
|
|
179
|
+
try {
|
|
180
|
+
const workflows = await agent.getWorkflows({ runtimeContext });
|
|
181
|
+
serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
|
|
182
|
+
return {
|
|
183
|
+
...acc,
|
|
184
|
+
[key]: {
|
|
185
|
+
name: workflow.name || "Unnamed workflow",
|
|
186
|
+
steps: Object.entries(workflow.steps).reduce(
|
|
187
|
+
(acc2, [key2, step]) => {
|
|
188
|
+
return {
|
|
189
|
+
...acc2,
|
|
190
|
+
[key2]: {
|
|
191
|
+
id: step.id,
|
|
192
|
+
description: step.description
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
},
|
|
196
|
+
{}
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
}, {});
|
|
201
|
+
} catch (error) {
|
|
202
|
+
logger.error("Error getting workflows for agent", { agentName: agent.name, error });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
let proxyRuntimeContext = runtimeContext;
|
|
206
|
+
if (isPlayground) {
|
|
207
|
+
proxyRuntimeContext = new Proxy(runtimeContext, {
|
|
208
|
+
get(target, prop) {
|
|
209
|
+
if (prop === "get") {
|
|
210
|
+
return function(key) {
|
|
211
|
+
const value = target.get(key);
|
|
212
|
+
return value ?? `<${key}>`;
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
return Reflect.get(target, prop);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });
|
|
220
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
221
|
+
const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });
|
|
222
|
+
const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });
|
|
223
|
+
const model = llm?.getModel();
|
|
224
|
+
const models = await agent.getModelList(runtimeContext);
|
|
225
|
+
const modelList = models?.map((md) => ({
|
|
226
|
+
...md,
|
|
227
|
+
model: {
|
|
228
|
+
modelId: md.model.modelId,
|
|
229
|
+
provider: md.model.provider,
|
|
230
|
+
modelVersion: md.model.specificationVersion
|
|
231
|
+
}
|
|
232
|
+
}));
|
|
233
|
+
const serializedAgentAgents = await getSerializedAgentDefinition({ agent, runtimeContext: proxyRuntimeContext });
|
|
234
|
+
const inputProcessors = await agent.getInputProcessors(proxyRuntimeContext);
|
|
235
|
+
const outputProcessors = await agent.getOutputProcessors(proxyRuntimeContext);
|
|
236
|
+
const serializedInputProcessors = getSerializedProcessors(inputProcessors);
|
|
237
|
+
const serializedOutputProcessors = getSerializedProcessors(outputProcessors);
|
|
238
|
+
return {
|
|
239
|
+
name: agent.name,
|
|
240
|
+
instructions,
|
|
241
|
+
tools: serializedAgentTools,
|
|
242
|
+
agents: serializedAgentAgents,
|
|
243
|
+
workflows: serializedAgentWorkflows,
|
|
244
|
+
inputProcessors: serializedInputProcessors,
|
|
245
|
+
outputProcessors: serializedOutputProcessors,
|
|
246
|
+
provider: llm?.getProvider(),
|
|
247
|
+
modelId: llm?.getModelId(),
|
|
248
|
+
modelVersion: model?.specificationVersion,
|
|
249
|
+
modelList,
|
|
250
|
+
defaultGenerateOptions,
|
|
251
|
+
defaultStreamOptions
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
async function getAgentByIdHandler({
|
|
255
|
+
mastra,
|
|
256
|
+
runtimeContext,
|
|
257
|
+
agentId,
|
|
258
|
+
isPlayground = false
|
|
259
|
+
}) {
|
|
260
|
+
try {
|
|
261
|
+
const agent = mastra.getAgent(agentId);
|
|
262
|
+
if (!agent) {
|
|
263
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
264
|
+
}
|
|
265
|
+
return formatAgent({ mastra, agent, runtimeContext, isPlayground });
|
|
266
|
+
} catch (error) {
|
|
267
|
+
return handleError(error, "Error getting agent");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async function getEvalsByAgentIdHandler({
|
|
271
|
+
mastra,
|
|
272
|
+
runtimeContext,
|
|
273
|
+
agentId
|
|
274
|
+
}) {
|
|
275
|
+
try {
|
|
276
|
+
const agent = mastra.getAgent(agentId);
|
|
277
|
+
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
|
|
278
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
279
|
+
return {
|
|
280
|
+
id: agentId,
|
|
281
|
+
name: agent.name,
|
|
282
|
+
instructions,
|
|
283
|
+
evals
|
|
284
|
+
};
|
|
285
|
+
} catch (error) {
|
|
286
|
+
return handleError(error, "Error getting test evals");
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
async function getLiveEvalsByAgentIdHandler({
|
|
290
|
+
mastra,
|
|
291
|
+
runtimeContext,
|
|
292
|
+
agentId
|
|
293
|
+
}) {
|
|
294
|
+
try {
|
|
295
|
+
const agent = mastra.getAgent(agentId);
|
|
296
|
+
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
|
|
297
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
298
|
+
return {
|
|
299
|
+
id: agentId,
|
|
300
|
+
name: agent.name,
|
|
301
|
+
instructions,
|
|
302
|
+
evals
|
|
303
|
+
};
|
|
304
|
+
} catch (error) {
|
|
305
|
+
return handleError(error, "Error getting live evals");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
async function generateLegacyHandler({
|
|
309
|
+
mastra,
|
|
310
|
+
runtimeContext,
|
|
311
|
+
agentId,
|
|
312
|
+
body,
|
|
313
|
+
abortSignal
|
|
314
|
+
}) {
|
|
315
|
+
try {
|
|
316
|
+
const agent = mastra.getAgent(agentId);
|
|
317
|
+
if (!agent) {
|
|
318
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
319
|
+
}
|
|
320
|
+
sanitizeBody(body, ["tools"]);
|
|
321
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
322
|
+
const finalResourceId = resourceId ?? resourceid;
|
|
323
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
324
|
+
...Array.from(runtimeContext.entries()),
|
|
325
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
326
|
+
]);
|
|
327
|
+
validateBody({ messages });
|
|
328
|
+
const result = await agent.generateLegacy(messages, {
|
|
329
|
+
...rest,
|
|
330
|
+
abortSignal,
|
|
331
|
+
// @ts-expect-error TODO fix types
|
|
332
|
+
resourceId: finalResourceId,
|
|
333
|
+
runtimeContext: finalRuntimeContext
|
|
334
|
+
});
|
|
335
|
+
return result;
|
|
336
|
+
} catch (error) {
|
|
337
|
+
return handleError(error, "Error generating from agent");
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
async function generateHandler({
|
|
341
|
+
mastra,
|
|
342
|
+
runtimeContext,
|
|
343
|
+
agentId,
|
|
344
|
+
body,
|
|
345
|
+
abortSignal
|
|
346
|
+
}) {
|
|
347
|
+
try {
|
|
348
|
+
const agent = mastra.getAgent(agentId);
|
|
349
|
+
if (!agent) {
|
|
350
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
351
|
+
}
|
|
352
|
+
sanitizeBody(body, ["tools"]);
|
|
353
|
+
const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
354
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
355
|
+
...Array.from(runtimeContext.entries()),
|
|
356
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
357
|
+
]);
|
|
358
|
+
validateBody({ messages });
|
|
359
|
+
const result = await agent.generate(messages, {
|
|
360
|
+
...rest,
|
|
361
|
+
runtimeContext: finalRuntimeContext,
|
|
362
|
+
format: rest.format || "mastra",
|
|
363
|
+
abortSignal
|
|
364
|
+
});
|
|
365
|
+
return result;
|
|
366
|
+
} catch (error) {
|
|
367
|
+
return handleError(error, "Error generating from agent");
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
async function streamGenerateLegacyHandler({
|
|
371
|
+
mastra,
|
|
372
|
+
runtimeContext,
|
|
373
|
+
agentId,
|
|
374
|
+
body,
|
|
375
|
+
abortSignal
|
|
376
|
+
}) {
|
|
377
|
+
try {
|
|
378
|
+
const agent = mastra.getAgent(agentId);
|
|
379
|
+
if (!agent) {
|
|
380
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
381
|
+
}
|
|
382
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
383
|
+
const finalResourceId = resourceId ?? resourceid;
|
|
384
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
385
|
+
...Array.from(runtimeContext.entries()),
|
|
386
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
387
|
+
]);
|
|
388
|
+
validateBody({ messages });
|
|
389
|
+
const streamResult = await agent.streamLegacy(messages, {
|
|
390
|
+
...rest,
|
|
391
|
+
abortSignal,
|
|
392
|
+
// @ts-expect-error TODO fix types
|
|
393
|
+
resourceId: finalResourceId,
|
|
394
|
+
runtimeContext: finalRuntimeContext
|
|
395
|
+
});
|
|
396
|
+
const streamResponse = rest.output ? streamResult.toTextStreamResponse({
|
|
397
|
+
headers: {
|
|
398
|
+
"Transfer-Encoding": "chunked"
|
|
399
|
+
}
|
|
400
|
+
}) : streamResult.toDataStreamResponse({
|
|
401
|
+
sendUsage: true,
|
|
402
|
+
sendReasoning: true,
|
|
403
|
+
getErrorMessage: (error) => {
|
|
404
|
+
return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
|
|
405
|
+
},
|
|
406
|
+
headers: {
|
|
407
|
+
"Transfer-Encoding": "chunked"
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
return streamResponse;
|
|
411
|
+
} catch (error) {
|
|
412
|
+
return handleError(error, "error streaming agent response");
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
function streamGenerateHandler({
|
|
416
|
+
mastra,
|
|
417
|
+
runtimeContext,
|
|
418
|
+
agentId,
|
|
419
|
+
body,
|
|
420
|
+
abortSignal
|
|
421
|
+
}) {
|
|
422
|
+
try {
|
|
423
|
+
const agent = mastra.getAgent(agentId);
|
|
424
|
+
if (!agent) {
|
|
425
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
426
|
+
}
|
|
427
|
+
sanitizeBody(body, ["tools"]);
|
|
428
|
+
const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
429
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
430
|
+
...Array.from(runtimeContext.entries()),
|
|
431
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
432
|
+
]);
|
|
433
|
+
validateBody({ messages });
|
|
434
|
+
const streamResult = agent.stream(messages, {
|
|
435
|
+
...rest,
|
|
436
|
+
runtimeContext: finalRuntimeContext,
|
|
437
|
+
abortSignal,
|
|
438
|
+
format: body.format ?? "mastra"
|
|
439
|
+
});
|
|
440
|
+
return streamResult;
|
|
441
|
+
} catch (error) {
|
|
442
|
+
return handleError(error, "error streaming agent response");
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function approveToolCallHandler({
|
|
446
|
+
mastra,
|
|
447
|
+
runtimeContext,
|
|
448
|
+
agentId,
|
|
449
|
+
body,
|
|
450
|
+
abortSignal
|
|
451
|
+
}) {
|
|
452
|
+
try {
|
|
453
|
+
const agent = mastra.getAgent(agentId);
|
|
454
|
+
if (!agent) {
|
|
455
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
456
|
+
}
|
|
457
|
+
sanitizeBody(body, ["tools"]);
|
|
458
|
+
const { runId, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
459
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
460
|
+
...Array.from(runtimeContext.entries()),
|
|
461
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
462
|
+
]);
|
|
463
|
+
const streamResult = agent.approveToolCall({
|
|
464
|
+
...rest,
|
|
465
|
+
runId,
|
|
466
|
+
runtimeContext: finalRuntimeContext,
|
|
467
|
+
abortSignal,
|
|
468
|
+
format: body.format ?? "mastra"
|
|
469
|
+
});
|
|
470
|
+
return streamResult;
|
|
471
|
+
} catch (error) {
|
|
472
|
+
return handleError(error, "error streaming agent response");
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
function declineToolCallHandler({
|
|
476
|
+
mastra,
|
|
477
|
+
runtimeContext,
|
|
478
|
+
agentId,
|
|
479
|
+
body,
|
|
480
|
+
abortSignal
|
|
481
|
+
}) {
|
|
482
|
+
try {
|
|
483
|
+
const agent = mastra.getAgent(agentId);
|
|
484
|
+
if (!agent) {
|
|
485
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
486
|
+
}
|
|
487
|
+
sanitizeBody(body, ["tools"]);
|
|
488
|
+
const { runId, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
489
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
490
|
+
...Array.from(runtimeContext.entries()),
|
|
491
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
492
|
+
]);
|
|
493
|
+
const streamResult = agent.declineToolCall({
|
|
494
|
+
...rest,
|
|
495
|
+
runId,
|
|
496
|
+
runtimeContext: finalRuntimeContext,
|
|
497
|
+
abortSignal,
|
|
498
|
+
format: body.format ?? "mastra"
|
|
499
|
+
});
|
|
500
|
+
return streamResult;
|
|
501
|
+
} catch (error) {
|
|
502
|
+
return handleError(error, "error streaming agent response");
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function streamNetworkHandler({
|
|
506
|
+
mastra,
|
|
507
|
+
runtimeContext,
|
|
508
|
+
agentId,
|
|
509
|
+
body
|
|
510
|
+
// abortSignal,
|
|
511
|
+
}) {
|
|
512
|
+
try {
|
|
513
|
+
const agent = mastra.getAgent(agentId);
|
|
514
|
+
if (!agent) {
|
|
515
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
516
|
+
}
|
|
517
|
+
sanitizeBody(body, ["tools"]);
|
|
518
|
+
const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
519
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
520
|
+
...Array.from(runtimeContext.entries()),
|
|
521
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
522
|
+
]);
|
|
523
|
+
validateBody({ messages });
|
|
524
|
+
const streamResult = agent.network(messages, {
|
|
525
|
+
...rest,
|
|
526
|
+
memory: {
|
|
527
|
+
thread: rest.thread ?? "",
|
|
528
|
+
resource: rest.resourceId ?? ""
|
|
529
|
+
},
|
|
530
|
+
runtimeContext: finalRuntimeContext
|
|
531
|
+
});
|
|
532
|
+
return streamResult;
|
|
533
|
+
} catch (error) {
|
|
534
|
+
return handleError(error, "error streaming agent loop response");
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
async function streamUIMessageHandler({
|
|
538
|
+
mastra,
|
|
539
|
+
runtimeContext,
|
|
540
|
+
agentId,
|
|
541
|
+
body,
|
|
542
|
+
abortSignal
|
|
543
|
+
}) {
|
|
544
|
+
try {
|
|
545
|
+
const agent = mastra.getAgent(agentId);
|
|
546
|
+
if (!agent) {
|
|
547
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
548
|
+
}
|
|
549
|
+
sanitizeBody(body, ["tools"]);
|
|
550
|
+
const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
551
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
552
|
+
...Array.from(runtimeContext.entries()),
|
|
553
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
554
|
+
]);
|
|
555
|
+
validateBody({ messages });
|
|
556
|
+
const streamResult = await agent.stream(messages, {
|
|
557
|
+
...rest,
|
|
558
|
+
runtimeContext: finalRuntimeContext,
|
|
559
|
+
abortSignal,
|
|
560
|
+
format: "aisdk"
|
|
561
|
+
});
|
|
562
|
+
return streamResult.toUIMessageStreamResponse();
|
|
563
|
+
} catch (error) {
|
|
564
|
+
return handleError(error, "error streaming agent response");
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
async function updateAgentModelHandler({
|
|
568
|
+
mastra,
|
|
569
|
+
agentId,
|
|
570
|
+
body
|
|
571
|
+
}) {
|
|
572
|
+
try {
|
|
573
|
+
const agent = mastra.getAgent(agentId);
|
|
574
|
+
if (!agent) {
|
|
575
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
576
|
+
}
|
|
577
|
+
const { modelId, provider } = body;
|
|
578
|
+
const newModel = `${provider}/${modelId}`;
|
|
579
|
+
agent.__updateModel({ model: newModel });
|
|
580
|
+
return { message: "Agent model updated" };
|
|
581
|
+
} catch (error) {
|
|
582
|
+
return handleError(error, "error updating agent model");
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
async function reorderAgentModelListHandler({
|
|
586
|
+
mastra,
|
|
587
|
+
agentId,
|
|
588
|
+
body
|
|
589
|
+
}) {
|
|
590
|
+
try {
|
|
591
|
+
const agent = mastra.getAgent(agentId);
|
|
592
|
+
if (!agent) {
|
|
593
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
594
|
+
}
|
|
595
|
+
const modelList = await agent.getModelList();
|
|
596
|
+
if (!modelList || modelList.length === 0) {
|
|
597
|
+
throw new HTTPException(400, { message: "Agent model list is not found or empty" });
|
|
598
|
+
}
|
|
599
|
+
agent.reorderModels(body.reorderedModelIds);
|
|
600
|
+
return { message: "Model list reordered" };
|
|
601
|
+
} catch (error) {
|
|
602
|
+
return handleError(error, "error reordering model list");
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
async function updateAgentModelInModelListHandler({
|
|
606
|
+
mastra,
|
|
607
|
+
agentId,
|
|
608
|
+
modelConfigId,
|
|
609
|
+
body
|
|
610
|
+
}) {
|
|
611
|
+
try {
|
|
612
|
+
const agent = mastra.getAgent(agentId);
|
|
613
|
+
if (!agent) {
|
|
614
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
615
|
+
}
|
|
616
|
+
const { model: bodyModel, maxRetries, enabled } = body;
|
|
617
|
+
if (!modelConfigId) {
|
|
618
|
+
throw new HTTPException(400, { message: "Model id is required" });
|
|
619
|
+
}
|
|
620
|
+
const modelList = await agent.getModelList();
|
|
621
|
+
if (!modelList || modelList.length === 0) {
|
|
622
|
+
throw new HTTPException(400, { message: "Agent model list is not found or empty" });
|
|
623
|
+
}
|
|
624
|
+
const modelToUpdate = modelList.find((m) => m.id === modelConfigId);
|
|
625
|
+
if (!modelToUpdate) {
|
|
626
|
+
throw new HTTPException(400, { message: "Model to update is not found in agent model list" });
|
|
627
|
+
}
|
|
628
|
+
let model;
|
|
629
|
+
if (bodyModel) {
|
|
630
|
+
const { modelId, provider } = bodyModel;
|
|
631
|
+
model = `${provider}/${modelId}`;
|
|
632
|
+
}
|
|
633
|
+
agent.updateModelInModelList({ id: modelConfigId, model, maxRetries, enabled });
|
|
634
|
+
return { message: "Model list updated" };
|
|
635
|
+
} catch (error) {
|
|
636
|
+
return handleError(error, "error updating model list");
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
async function getProvidersHandler() {
|
|
640
|
+
try {
|
|
641
|
+
const providers = Object.entries(PROVIDER_REGISTRY).map(([id, provider]) => {
|
|
642
|
+
const envVars = Array.isArray(provider.apiKeyEnvVar) ? provider.apiKeyEnvVar : [provider.apiKeyEnvVar];
|
|
643
|
+
const connected = envVars.every((envVar) => !!process.env[envVar]);
|
|
644
|
+
return {
|
|
645
|
+
id,
|
|
646
|
+
name: provider.name,
|
|
647
|
+
envVar: provider.apiKeyEnvVar,
|
|
648
|
+
connected,
|
|
649
|
+
docUrl: provider.docUrl,
|
|
650
|
+
models: [...provider.models]
|
|
651
|
+
// Convert readonly array to regular array
|
|
652
|
+
};
|
|
653
|
+
});
|
|
654
|
+
return { providers };
|
|
655
|
+
} catch (error) {
|
|
656
|
+
return handleError(error, "error fetching providers");
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
export { agents_exports, approveToolCallHandler, declineToolCallHandler, generateHandler, generateLegacyHandler, getAgentByIdHandler, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, getProvidersHandler, getSerializedAgentTools, getSerializedProcessors, reorderAgentModelListHandler, streamGenerateHandler, streamGenerateLegacyHandler, streamNetworkHandler, streamUIMessageHandler, updateAgentModelHandler, updateAgentModelInModelListHandler };
|
|
661
|
+
//# sourceMappingURL=chunk-JSLAYFEW.js.map
|
|
662
|
+
//# sourceMappingURL=chunk-JSLAYFEW.js.map
|