@mastra/server 0.22.0-alpha.1 → 0.22.1

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 CHANGED
@@ -1,5 +1,52 @@
1
1
  # @mastra/server
2
2
 
3
+ ## 0.22.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Get agent registered on a parent agent via API ([#9106](https://github.com/mastra-ai/mastra/pull/9106))
8
+
9
+ - Updated dependencies []:
10
+ - @mastra/core@0.22.1
11
+
12
+ ## 0.22.1-alpha.0
13
+
14
+ ### Patch Changes
15
+
16
+ - Get agent registered on a parent agent via API ([#9106](https://github.com/mastra-ai/mastra/pull/9106))
17
+
18
+ - Updated dependencies []:
19
+ - @mastra/core@0.22.1-alpha.0
20
+
21
+ ## 0.22.0
22
+
23
+ ### Minor Changes
24
+
25
+ - Consolidate streamVNext logic into stream, move old stream function into streamLegacy ([#9092](https://github.com/mastra-ai/mastra/pull/9092))
26
+
27
+ - Update peer dependencies to match core package version bump (0.21.2) ([#9038](https://github.com/mastra-ai/mastra/pull/9038))
28
+
29
+ - Update peer dependencies to match core package version bump (0.22.0) ([#9092](https://github.com/mastra-ai/mastra/pull/9092))
30
+
31
+ - Update peer dependencies to match core package version bump (0.21.2) ([#9021](https://github.com/mastra-ai/mastra/pull/9021))
32
+
33
+ ### Patch Changes
34
+
35
+ - Updated `watch` and `watchAsync` methods to use proper function overloads instead of generic conditional types, ensuring compatibility with the base Run class signatures. ([#9048](https://github.com/mastra-ai/mastra/pull/9048))
36
+
37
+ - Generate a title for Agent.network() threads ([#8853](https://github.com/mastra-ai/mastra/pull/8853))
38
+
39
+ - Fix custom metadata preservation in UIMessages when loading threads. The `getMessagesHandler` now converts `messagesV2` (V2 format with metadata) instead of `messages` (V1 format without metadata) to AIV5.UI format. Also updates the abstract `MastraMemory.query()` return type to include `messagesV2` for proper type safety. ([#9029](https://github.com/mastra-ai/mastra/pull/9029))
40
+
41
+ - Fix provider tools for popular providers and add support for anthropic/claude skills. ([#9038](https://github.com/mastra-ai/mastra/pull/9038))
42
+
43
+ - Show agent tool output better in playground ([#9021](https://github.com/mastra-ai/mastra/pull/9021))
44
+
45
+ - Update peerdeps to 0.23.0-0 ([#9043](https://github.com/mastra-ai/mastra/pull/9043))
46
+
47
+ - Updated dependencies [[`c67ca32`](https://github.com/mastra-ai/mastra/commit/c67ca32e3c2cf69bfc146580770c720220ca44ac), [`efb5ed9`](https://github.com/mastra-ai/mastra/commit/efb5ed946ae7f410bc68c9430beb4b010afd25ec), [`dbc9e12`](https://github.com/mastra-ai/mastra/commit/dbc9e1216ba575ba59ead4afb727a01215f7de4f), [`99e41b9`](https://github.com/mastra-ai/mastra/commit/99e41b94957cdd25137d3ac12e94e8b21aa01b68), [`c28833c`](https://github.com/mastra-ai/mastra/commit/c28833c5b6d8e10eeffd7f7d39129d53b8bca240), [`8ea07b4`](https://github.com/mastra-ai/mastra/commit/8ea07b4bdc73e4218437dbb6dcb0f4b23e745a44), [`ba201b8`](https://github.com/mastra-ai/mastra/commit/ba201b8f8feac4c72350f2dbd52c13c7297ba7b0), [`f053e89`](https://github.com/mastra-ai/mastra/commit/f053e89160dbd0bd3333fc3492f68231b5c7c349), [`4fc4136`](https://github.com/mastra-ai/mastra/commit/4fc413652866a8d2240694fddb2562e9edbb70df), [`b78e04d`](https://github.com/mastra-ai/mastra/commit/b78e04d935a16ecb1e59c5c96e564903527edddd), [`d10baf5`](https://github.com/mastra-ai/mastra/commit/d10baf5a3c924f2a6654e23a3e318ed03f189b76), [`038c55a`](https://github.com/mastra-ai/mastra/commit/038c55a7090fc1b1513a966386d3072617f836ac), [`182f045`](https://github.com/mastra-ai/mastra/commit/182f0458f25bd70aa774e64fd923c8a483eddbf1), [`9a1a485`](https://github.com/mastra-ai/mastra/commit/9a1a4859b855e37239f652bf14b1ecd1029b8c4e), [`9257233`](https://github.com/mastra-ai/mastra/commit/9257233c4ffce09b2bedc2a9adbd70d7a83fa8e2), [`7620d2b`](https://github.com/mastra-ai/mastra/commit/7620d2bddeb4fae4c3c0a0b4e672969795fca11a), [`b2365f0`](https://github.com/mastra-ai/mastra/commit/b2365f038dd4c5f06400428b224af963f399ad50), [`0f1a4c9`](https://github.com/mastra-ai/mastra/commit/0f1a4c984fb4b104b2f0b63ba18c9fa77f567700), [`9029ba3`](https://github.com/mastra-ai/mastra/commit/9029ba34459c8859fed4c6b73efd8e2d0021e7ba), [`426cc56`](https://github.com/mastra-ai/mastra/commit/426cc561c85ae76a112ded2385532a91f9f9f074), [`00931fb`](https://github.com/mastra-ai/mastra/commit/00931fb1a21aa42c4fbc20c2c40dd62466b8fc8f), [`e473bfe`](https://github.com/mastra-ai/mastra/commit/e473bfe416c0b8e876973c2b6a6f13c394b7a93f), [`b78e04d`](https://github.com/mastra-ai/mastra/commit/b78e04d935a16ecb1e59c5c96e564903527edddd), [`2db6160`](https://github.com/mastra-ai/mastra/commit/2db6160e2022ff8827c15d30157e684683b934b5), [`8aeea37`](https://github.com/mastra-ai/mastra/commit/8aeea37efdde347c635a67fed56794943b7f74ec), [`02fe153`](https://github.com/mastra-ai/mastra/commit/02fe15351d6021d214da48ec982a0e9e4150bcee), [`648e2ca`](https://github.com/mastra-ai/mastra/commit/648e2ca42da54838c6ccbdaadc6fadd808fa6b86), [`74567b3`](https://github.com/mastra-ai/mastra/commit/74567b3d237ae3915cd0bca3cf55fa0a64e4e4a4), [`b65c5e0`](https://github.com/mastra-ai/mastra/commit/b65c5e0fe6f3c390a9a8bbcf69304d972c3a4afb), [`15a1733`](https://github.com/mastra-ai/mastra/commit/15a1733074cee8bd37370e1af34cd818e89fa7ac), [`fc2a774`](https://github.com/mastra-ai/mastra/commit/fc2a77468981aaddc3e77f83f0c4ad4a4af140da), [`4e08933`](https://github.com/mastra-ai/mastra/commit/4e08933625464dfde178347af5b6278fcf34188e)]:
48
+ - @mastra/core@0.22.0
49
+
3
50
  ## 0.22.0-alpha.1
4
51
 
5
52
  ### Minor Changes
@@ -15,6 +15,7 @@ __export(agents_exports, {
15
15
  generateHandler: () => generateHandler,
16
16
  generateLegacyHandler: () => generateLegacyHandler,
17
17
  getAgentByIdHandler: () => getAgentByIdHandler,
18
+ getAgentFromSystem: () => getAgentFromSystem,
18
19
  getAgentsHandler: () => getAgentsHandler,
19
20
  getEvalsByAgentIdHandler: () => getEvalsByAgentIdHandler,
20
21
  getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
@@ -164,6 +165,39 @@ async function formatAgentList({
164
165
  modelList
165
166
  };
166
167
  }
168
+ async function getAgentFromSystem({ mastra, agentId }) {
169
+ const logger = mastra.getLogger();
170
+ if (!agentId) {
171
+ throw new HTTPException(400, { message: "Agent ID is required" });
172
+ }
173
+ let agent;
174
+ try {
175
+ agent = mastra.getAgent(agentId);
176
+ } catch (error) {
177
+ logger.debug("Error getting agent from mastra, searching agents for agent", error);
178
+ }
179
+ if (!agent) {
180
+ logger.debug(`Agent ${agentId} not found, looking through sub-agents`);
181
+ const agents = mastra.getAgents();
182
+ if (Object.keys(agents || {}).length) {
183
+ for (const [_, ag] of Object.entries(agents)) {
184
+ try {
185
+ const subAgents = await ag.listAgents();
186
+ if (subAgents[agentId]) {
187
+ agent = subAgents[agentId];
188
+ break;
189
+ }
190
+ } catch (error) {
191
+ logger.debug("Error getting agent from agent", error);
192
+ }
193
+ }
194
+ }
195
+ }
196
+ if (!agent) {
197
+ throw new HTTPException(404, { message: `Agent with name ${agentId} not found` });
198
+ }
199
+ return agent;
200
+ }
167
201
  async function getAgentsHandler({
168
202
  mastra,
169
203
  runtimeContext
@@ -277,10 +311,7 @@ async function getAgentByIdHandler({
277
311
  isPlayground = false
278
312
  }) {
279
313
  try {
280
- const agent = mastra.getAgent(agentId);
281
- if (!agent) {
282
- throw new HTTPException(404, { message: "Agent not found" });
283
- }
314
+ const agent = await getAgentFromSystem({ mastra, agentId });
284
315
  return formatAgent({ mastra, agent, runtimeContext, isPlayground });
285
316
  } catch (error) {
286
317
  return handleError(error, "Error getting agent");
@@ -292,7 +323,7 @@ async function getEvalsByAgentIdHandler({
292
323
  agentId
293
324
  }) {
294
325
  try {
295
- const agent = mastra.getAgent(agentId);
326
+ const agent = await getAgentFromSystem({ mastra, agentId });
296
327
  const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
297
328
  const instructions = await agent.getInstructions({ runtimeContext });
298
329
  return {
@@ -311,7 +342,7 @@ async function getLiveEvalsByAgentIdHandler({
311
342
  agentId
312
343
  }) {
313
344
  try {
314
- const agent = mastra.getAgent(agentId);
345
+ const agent = await getAgentFromSystem({ mastra, agentId });
315
346
  const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
316
347
  const instructions = await agent.getInstructions({ runtimeContext });
317
348
  return {
@@ -332,10 +363,7 @@ async function generateLegacyHandler({
332
363
  abortSignal
333
364
  }) {
334
365
  try {
335
- const agent = mastra.getAgent(agentId);
336
- if (!agent) {
337
- throw new HTTPException(404, { message: "Agent not found" });
338
- }
366
+ const agent = await getAgentFromSystem({ mastra, agentId });
339
367
  sanitizeBody(body, ["tools"]);
340
368
  const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
341
369
  const finalResourceId = resourceId ?? resourceid;
@@ -364,10 +392,7 @@ async function generateHandler({
364
392
  abortSignal
365
393
  }) {
366
394
  try {
367
- const agent = mastra.getAgent(agentId);
368
- if (!agent) {
369
- throw new HTTPException(404, { message: "Agent not found" });
370
- }
395
+ const agent = await getAgentFromSystem({ mastra, agentId });
371
396
  sanitizeBody(body, ["tools"]);
372
397
  const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
373
398
  const finalRuntimeContext = new RuntimeContext([
@@ -394,10 +419,7 @@ async function streamGenerateLegacyHandler({
394
419
  abortSignal
395
420
  }) {
396
421
  try {
397
- const agent = mastra.getAgent(agentId);
398
- if (!agent) {
399
- throw new HTTPException(404, { message: "Agent not found" });
400
- }
422
+ const agent = await getAgentFromSystem({ mastra, agentId });
401
423
  const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
402
424
  const finalResourceId = resourceId ?? resourceid;
403
425
  const finalRuntimeContext = new RuntimeContext([
@@ -431,7 +453,7 @@ async function streamGenerateLegacyHandler({
431
453
  return handleError(error, "error streaming agent response");
432
454
  }
433
455
  }
434
- function streamGenerateHandler({
456
+ async function streamGenerateHandler({
435
457
  mastra,
436
458
  runtimeContext,
437
459
  agentId,
@@ -439,10 +461,7 @@ function streamGenerateHandler({
439
461
  abortSignal
440
462
  }) {
441
463
  try {
442
- const agent = mastra.getAgent(agentId);
443
- if (!agent) {
444
- throw new HTTPException(404, { message: "Agent not found" });
445
- }
464
+ const agent = await getAgentFromSystem({ mastra, agentId });
446
465
  sanitizeBody(body, ["tools"]);
447
466
  const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
448
467
  const finalRuntimeContext = new RuntimeContext([
@@ -461,7 +480,7 @@ function streamGenerateHandler({
461
480
  return handleError(error, "error streaming agent response");
462
481
  }
463
482
  }
464
- function approveToolCallHandler({
483
+ async function approveToolCallHandler({
465
484
  mastra,
466
485
  runtimeContext,
467
486
  agentId,
@@ -469,10 +488,7 @@ function approveToolCallHandler({
469
488
  abortSignal
470
489
  }) {
471
490
  try {
472
- const agent = mastra.getAgent(agentId);
473
- if (!agent) {
474
- throw new HTTPException(404, { message: "Agent not found" });
475
- }
491
+ const agent = await getAgentFromSystem({ mastra, agentId });
476
492
  sanitizeBody(body, ["tools"]);
477
493
  const { runId, runtimeContext: agentRuntimeContext, ...rest } = body;
478
494
  const finalRuntimeContext = new RuntimeContext([
@@ -491,7 +507,7 @@ function approveToolCallHandler({
491
507
  return handleError(error, "error streaming agent response");
492
508
  }
493
509
  }
494
- function declineToolCallHandler({
510
+ async function declineToolCallHandler({
495
511
  mastra,
496
512
  runtimeContext,
497
513
  agentId,
@@ -499,10 +515,7 @@ function declineToolCallHandler({
499
515
  abortSignal
500
516
  }) {
501
517
  try {
502
- const agent = mastra.getAgent(agentId);
503
- if (!agent) {
504
- throw new HTTPException(404, { message: "Agent not found" });
505
- }
518
+ const agent = await getAgentFromSystem({ mastra, agentId });
506
519
  sanitizeBody(body, ["tools"]);
507
520
  const { runId, runtimeContext: agentRuntimeContext, ...rest } = body;
508
521
  const finalRuntimeContext = new RuntimeContext([
@@ -521,7 +534,7 @@ function declineToolCallHandler({
521
534
  return handleError(error, "error streaming agent response");
522
535
  }
523
536
  }
524
- function streamNetworkHandler({
537
+ async function streamNetworkHandler({
525
538
  mastra,
526
539
  runtimeContext,
527
540
  agentId,
@@ -529,10 +542,7 @@ function streamNetworkHandler({
529
542
  // abortSignal,
530
543
  }) {
531
544
  try {
532
- const agent = mastra.getAgent(agentId);
533
- if (!agent) {
534
- throw new HTTPException(404, { message: "Agent not found" });
535
- }
545
+ const agent = await getAgentFromSystem({ mastra, agentId });
536
546
  sanitizeBody(body, ["tools"]);
537
547
  const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
538
548
  const finalRuntimeContext = new RuntimeContext([
@@ -562,10 +572,7 @@ async function streamUIMessageHandler({
562
572
  abortSignal
563
573
  }) {
564
574
  try {
565
- const agent = mastra.getAgent(agentId);
566
- if (!agent) {
567
- throw new HTTPException(404, { message: "Agent not found" });
568
- }
575
+ const agent = await getAgentFromSystem({ mastra, agentId });
569
576
  sanitizeBody(body, ["tools"]);
570
577
  const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
571
578
  const finalRuntimeContext = new RuntimeContext([
@@ -590,10 +597,7 @@ async function updateAgentModelHandler({
590
597
  body
591
598
  }) {
592
599
  try {
593
- const agent = mastra.getAgent(agentId);
594
- if (!agent) {
595
- throw new HTTPException(404, { message: "Agent not found" });
596
- }
600
+ const agent = await getAgentFromSystem({ mastra, agentId });
597
601
  const { modelId, provider } = body;
598
602
  const newModel = `${provider}/${modelId}`;
599
603
  agent.__updateModel({ model: newModel });
@@ -608,10 +612,7 @@ async function reorderAgentModelListHandler({
608
612
  body
609
613
  }) {
610
614
  try {
611
- const agent = mastra.getAgent(agentId);
612
- if (!agent) {
613
- throw new HTTPException(404, { message: "Agent not found" });
614
- }
615
+ const agent = await getAgentFromSystem({ mastra, agentId });
615
616
  const modelList = await agent.getModelList();
616
617
  if (!modelList || modelList.length === 0) {
617
618
  throw new HTTPException(400, { message: "Agent model list is not found or empty" });
@@ -629,10 +630,7 @@ async function updateAgentModelInModelListHandler({
629
630
  body
630
631
  }) {
631
632
  try {
632
- const agent = mastra.getAgent(agentId);
633
- if (!agent) {
634
- throw new HTTPException(404, { message: "Agent not found" });
635
- }
633
+ const agent = await getAgentFromSystem({ mastra, agentId });
636
634
  const { model: bodyModel, maxRetries, enabled } = body;
637
635
  if (!modelConfigId) {
638
636
  throw new HTTPException(400, { message: "Model id is required" });
@@ -677,6 +675,6 @@ async function getProvidersHandler() {
677
675
  }
678
676
  }
679
677
 
680
- export { agents_exports, approveToolCallHandler, declineToolCallHandler, generateHandler, generateLegacyHandler, getAgentByIdHandler, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, getProvidersHandler, getSerializedAgentTools, getSerializedProcessors, reorderAgentModelListHandler, streamGenerateHandler, streamGenerateLegacyHandler, streamNetworkHandler, streamUIMessageHandler, updateAgentModelHandler, updateAgentModelInModelListHandler };
681
- //# sourceMappingURL=chunk-XDAYZS6N.js.map
682
- //# sourceMappingURL=chunk-XDAYZS6N.js.map
678
+ export { agents_exports, approveToolCallHandler, declineToolCallHandler, generateHandler, generateLegacyHandler, getAgentByIdHandler, getAgentFromSystem, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, getProvidersHandler, getSerializedAgentTools, getSerializedProcessors, reorderAgentModelListHandler, streamGenerateHandler, streamGenerateLegacyHandler, streamNetworkHandler, streamUIMessageHandler, updateAgentModelHandler, updateAgentModelInModelListHandler };
679
+ //# sourceMappingURL=chunk-CFBJQKRE.js.map
680
+ //# sourceMappingURL=chunk-CFBJQKRE.js.map
@@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,QAAQ,CAAA,CAAA,EAAI,OAAO,CAAA,CAAA;AAAA,IAChC;AAEA,IAAA,KAAA,CAAM,uBAAuB,EAAE,EAAA,EAAI,eAAe,KAAA,EAAO,UAAA,EAAY,SAAS,CAAA;AAE9E,IAAA,OAAO,EAAE,SAAS,oBAAA,EAAqB;AAAA,EACzC,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,2BAA2B,CAAA;AAAA,EACvD;AACF;AAEA,eAAsB,mBAAA,GAAsB;AAC1C,EAAA,IAAI;AACF,IAAA,MAAM,SAAA,GAAY,MAAA,CAAO,OAAA,CAAQ,iBAAiB,CAAA,CAAE,IAAI,CAAC,CAAC,EAAA,EAAI,QAAQ,CAAA,KAAM;AAE1E,MAAA,MAAM,OAAA,GAAU,KAAA,CAAM,OAAA,CAAQ,QAAA,CAAS,YAAY,IAAI,QAAA,CAAS,YAAA,GAAe,CAAC,QAAA,CAAS,YAAY,CAAA;AACrG,MAAA,MAAM,SAAA,GAAY,QAAQ,KAAA,CAAM,CAAA,MAAA,KAAU,CAAC,CAAC,OAAA,CAAQ,GAAA,CAAI,MAAM,CAAC,CAAA;AAE/D,MAAA,OAAO;AAAA,QACL,EAAA;AAAA,QACA,MAAM,QAAA,CAAS,IAAA;AAAA,QACf,QAAQ,QAAA,CAAS,YAAA;AAAA,QACjB,SAAA;AAAA,QACA,QAAQ,QAAA,CAAS,MAAA;AAAA,QACjB,MAAA,EAAQ,CAAC,GAAG,QAAA,CAAS,MAAM;AAAA;AAAA,OAC7B;AAAA,IACF,CAAC,CAAA;AAED,IAAA,OAAO,EAAE,SAAA,EAAU;AAAA,EACrB,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,0BAA0B,CAAA;AAAA,EACtD;AACF","file":"chunk-CFBJQKRE.js","sourcesContent":["import type { Agent, AgentModelManagerConfig } from '@mastra/core/agent';\nimport { PROVIDER_REGISTRY } from '@mastra/core/llm';\nimport type { SystemMessage } from '@mastra/core/llm';\nimport type { InputProcessor, OutputProcessor } from '@mastra/core/processors';\nimport { RuntimeContext } from '@mastra/core/runtime-context';\nimport { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';\nimport { stringify } from 'superjson';\n\nimport type {\n StreamTextOnFinishCallback,\n StreamTextOnStepFinishCallback,\n} from '../../../../core/dist/llm/model/base.types';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\n\nimport { handleError } from './error';\nimport { sanitizeBody, validateBody } from './utils';\n\ntype GetBody<\n T extends keyof Agent & { [K in keyof Agent]: Agent[K] extends (...args: any) => any ? K : never }[keyof Agent],\n> = {\n messages: Parameters<Agent[T]>[0];\n} & Parameters<Agent[T]>[1];\n\ntype GetHITLBody<\n T extends keyof Agent & { [K in keyof Agent]: Agent[K] extends (...args: any) => any ? K : never }[keyof Agent],\n> = Parameters<Agent[T]>[0];\n\nexport interface SerializedProcessor {\n name: string;\n}\n\nexport interface SerializedTool {\n id: string;\n description?: string;\n inputSchema?: string;\n outputSchema?: string;\n requireApproval?: boolean;\n}\n\nexport interface SerializedWorkflow {\n name: string;\n steps?: Record<string, { id: string; description?: string }>;\n}\n\nexport interface SerializedAgent {\n name: string;\n instructions?: SystemMessage;\n tools: Record<string, SerializedTool>;\n agents: Record<string, SerializedAgentDefinition>;\n workflows: Record<string, SerializedWorkflow>;\n inputProcessors: SerializedProcessor[];\n outputProcessors: SerializedProcessor[];\n provider?: string;\n modelId?: string;\n modelVersion?: string;\n modelList?: Array<\n Omit<AgentModelManagerConfig, 'model'> & {\n model: {\n modelId: string;\n provider: string;\n modelVersion: string;\n };\n }\n >;\n // We can't use the true types here because they are not serializable\n defaultGenerateOptions?: Record<string, unknown>;\n defaultStreamOptions?: Record<string, unknown>;\n}\n\nexport interface SerializedAgentWithId extends SerializedAgent {\n id: string;\n}\n\nexport async function getSerializedAgentTools(tools: Record<string, unknown>): Promise<Record<string, SerializedTool>> {\n return Object.entries(tools || {}).reduce<Record<string, SerializedTool>>((acc, [key, tool]) => {\n const _tool = tool as {\n id?: string;\n description?: string;\n inputSchema?: { jsonSchema?: unknown } | unknown;\n outputSchema?: { jsonSchema?: unknown } | unknown;\n };\n\n const toolId = _tool.id ?? `tool-${key}`;\n\n let inputSchemaForReturn: string | undefined = undefined;\n let outputSchemaForReturn: string | undefined = undefined;\n\n try {\n if (_tool.inputSchema) {\n if (_tool.inputSchema && typeof _tool.inputSchema === 'object' && 'jsonSchema' in _tool.inputSchema) {\n inputSchemaForReturn = stringify(_tool.inputSchema.jsonSchema);\n } else if (typeof _tool.inputSchema === 'function') {\n const inputSchema = _tool.inputSchema();\n if (inputSchema && inputSchema.jsonSchema) {\n inputSchemaForReturn = stringify(inputSchema.jsonSchema);\n }\n } else if (_tool.inputSchema) {\n inputSchemaForReturn = stringify(zodToJsonSchema(_tool.inputSchema as Parameters<typeof zodToJsonSchema>[0]));\n }\n }\n\n if (_tool.outputSchema) {\n if (_tool.outputSchema && typeof _tool.outputSchema === 'object' && 'jsonSchema' in _tool.outputSchema) {\n outputSchemaForReturn = stringify(_tool.outputSchema.jsonSchema);\n } else if (typeof _tool.outputSchema === 'function') {\n const outputSchema = _tool.outputSchema();\n if (outputSchema && outputSchema.jsonSchema) {\n outputSchemaForReturn = stringify(outputSchema.jsonSchema);\n }\n } else if (_tool.outputSchema) {\n outputSchemaForReturn = stringify(\n zodToJsonSchema(_tool.outputSchema as Parameters<typeof zodToJsonSchema>[0]),\n );\n }\n }\n } catch (error) {\n console.error(`Error getting serialized tool`, {\n toolId: _tool.id,\n error,\n });\n }\n\n acc[key] = {\n ..._tool,\n id: toolId,\n inputSchema: inputSchemaForReturn,\n outputSchema: outputSchemaForReturn,\n };\n return acc;\n }, {});\n}\n\nexport function getSerializedProcessors(processors: (InputProcessor | OutputProcessor)[]): SerializedProcessor[] {\n return processors.map(processor => {\n // Processors are class instances or objects with a name property\n // Use the name property if available, otherwise fall back to constructor name\n return {\n name: processor.name || processor.constructor.name,\n };\n });\n}\n\ninterface SerializedAgentDefinition {\n id: string;\n name: string;\n}\n\nasync function getSerializedAgentDefinition({\n agent,\n runtimeContext,\n}: {\n agent: Agent;\n runtimeContext: RuntimeContext;\n}): Promise<Record<string, SerializedAgentDefinition>> {\n let serializedAgentAgents: Record<string, SerializedAgentDefinition> = {};\n\n if ('listAgents' in agent) {\n const agents = await agent.listAgents({ runtimeContext });\n serializedAgentAgents = Object.entries(agents || {}).reduce<Record<string, SerializedAgentDefinition>>(\n (acc, [key, agent]) => {\n return {\n ...acc,\n [key]: { id: agent.id, name: agent.name },\n };\n },\n {},\n );\n }\n return serializedAgentAgents;\n}\n\nasync function formatAgentList({\n id,\n mastra,\n agent,\n runtimeContext,\n}: {\n id: string;\n mastra: Context['mastra'];\n agent: Agent;\n runtimeContext: RuntimeContext;\n}): Promise<SerializedAgentWithId> {\n const instructions = await agent.getInstructions({ runtimeContext });\n const tools = await agent.getTools({ runtimeContext });\n const llm = await agent.getLLM({ runtimeContext });\n const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext });\n const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext });\n const serializedAgentTools = await getSerializedAgentTools(tools);\n\n let serializedAgentWorkflows: Record<\n string,\n { name: string; steps?: Record<string, { id: string; description?: string }> }\n > = {};\n\n if ('getWorkflows' in agent) {\n const logger = mastra.getLogger();\n try {\n const workflows = await agent.getWorkflows({ runtimeContext });\n serializedAgentWorkflows = Object.entries(workflows || {}).reduce<\n Record<string, { name: string; steps?: Record<string, { id: string; description?: string }> }>\n >((acc, [key, workflow]) => {\n return {\n ...acc,\n [key]: {\n name: workflow.name || 'Unnamed workflow',\n },\n };\n }, {});\n } catch (error) {\n logger.error('Error getting workflows for agent', { agentName: agent.name, error });\n }\n }\n\n const serializedAgentAgents = await getSerializedAgentDefinition({ agent, runtimeContext });\n\n // Get and serialize processors\n const inputProcessors = await agent.getInputProcessors(runtimeContext);\n const outputProcessors = await agent.getOutputProcessors(runtimeContext);\n const serializedInputProcessors = getSerializedProcessors(inputProcessors);\n const serializedOutputProcessors = getSerializedProcessors(outputProcessors);\n\n const model = llm?.getModel();\n const models = await agent.getModelList(runtimeContext);\n const modelList = models?.map(md => ({\n ...md,\n model: {\n modelId: md.model.modelId,\n provider: md.model.provider,\n modelVersion: md.model.specificationVersion,\n },\n }));\n\n return {\n id,\n name: agent.name,\n instructions,\n agents: serializedAgentAgents,\n tools: serializedAgentTools,\n workflows: serializedAgentWorkflows,\n inputProcessors: serializedInputProcessors,\n outputProcessors: serializedOutputProcessors,\n provider: llm?.getProvider(),\n modelId: llm?.getModelId(),\n modelVersion: model?.specificationVersion,\n defaultGenerateOptions,\n defaultStreamOptions,\n modelList,\n };\n}\n\nexport async function getAgentFromSystem({ mastra, agentId }: { mastra: Context['mastra']; agentId: string }) {\n const logger = mastra.getLogger();\n\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n let agent;\n\n try {\n agent = mastra.getAgent(agentId);\n } catch (error) {\n logger.debug('Error getting agent from mastra, searching agents for agent', error);\n }\n\n if (!agent) {\n logger.debug(`Agent ${agentId} not found, looking through sub-agents`);\n const agents = mastra.getAgents();\n if (Object.keys(agents || {}).length) {\n for (const [_, ag] of Object.entries(agents)) {\n try {\n const subAgents = await ag.listAgents();\n\n if (subAgents[agentId]) {\n agent = subAgents[agentId];\n break;\n }\n } catch (error) {\n logger.debug('Error getting agent from agent', error);\n }\n }\n }\n }\n\n if (!agent) {\n throw new HTTPException(404, { message: `Agent with name ${agentId} not found` });\n }\n\n return agent;\n}\n\n// Agent handlers\nexport async function getAgentsHandler({\n mastra,\n runtimeContext,\n}: Context & { runtimeContext: RuntimeContext }): Promise<Record<string, SerializedAgent>> {\n try {\n const agents = mastra.getAgents();\n\n const serializedAgentsMap = await Promise.all(\n Object.entries(agents).map(async ([id, agent]) => {\n return formatAgentList({ id, mastra, agent, runtimeContext });\n }),\n );\n\n const serializedAgents = serializedAgentsMap.reduce<\n Record<string, Omit<(typeof serializedAgentsMap)[number], 'id'>>\n >((acc, { id, ...rest }) => {\n acc[id] = rest;\n return acc;\n }, {});\n\n return serializedAgents;\n } catch (error) {\n return handleError(error, 'Error getting agents');\n }\n}\n\nasync function formatAgent({\n mastra,\n agent,\n runtimeContext,\n isPlayground,\n}: {\n mastra: Context['mastra'];\n agent: Agent;\n runtimeContext: RuntimeContext;\n isPlayground: boolean;\n}): Promise<SerializedAgent> {\n const tools = await agent.getTools({ runtimeContext });\n\n const serializedAgentTools = await getSerializedAgentTools(tools);\n\n let serializedAgentWorkflows: Record<\n string,\n { name: string; steps: Record<string, { id: string; description?: string }> }\n > = {};\n\n if ('getWorkflows' in agent) {\n const logger = mastra.getLogger();\n try {\n const workflows = await agent.getWorkflows({ runtimeContext });\n\n serializedAgentWorkflows = Object.entries(workflows || {}).reduce<\n Record<string, { name: string; steps: Record<string, { id: string; description?: string }> }>\n >((acc, [key, workflow]) => {\n return {\n ...acc,\n [key]: {\n name: workflow.name || 'Unnamed workflow',\n steps: Object.entries(workflow.steps).reduce<Record<string, { id: string; description?: string }>>(\n (acc, [key, step]) => {\n return {\n ...acc,\n [key]: {\n id: step.id,\n description: step.description,\n },\n };\n },\n {},\n ),\n },\n };\n }, {});\n } catch (error) {\n logger.error('Error getting workflows for agent', { agentName: agent.name, error });\n }\n }\n\n let proxyRuntimeContext = runtimeContext;\n if (isPlayground) {\n proxyRuntimeContext = new Proxy(runtimeContext, {\n get(target, prop) {\n if (prop === 'get') {\n return function (key: string) {\n const value = target.get(key);\n return value ?? `<${key}>`;\n };\n }\n return Reflect.get(target, prop);\n },\n });\n }\n\n const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });\n const llm = await agent.getLLM({ runtimeContext });\n const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });\n const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });\n\n const model = llm?.getModel();\n const models = await agent.getModelList(runtimeContext);\n const modelList = models?.map(md => ({\n ...md,\n model: {\n modelId: md.model.modelId,\n provider: md.model.provider,\n modelVersion: md.model.specificationVersion,\n },\n }));\n\n const serializedAgentAgents = await getSerializedAgentDefinition({ agent, runtimeContext: proxyRuntimeContext });\n\n // Get and serialize processors\n const inputProcessors = await agent.getInputProcessors(proxyRuntimeContext);\n const outputProcessors = await agent.getOutputProcessors(proxyRuntimeContext);\n const serializedInputProcessors = getSerializedProcessors(inputProcessors);\n const serializedOutputProcessors = getSerializedProcessors(outputProcessors);\n\n return {\n name: agent.name,\n instructions,\n tools: serializedAgentTools,\n agents: serializedAgentAgents,\n workflows: serializedAgentWorkflows,\n inputProcessors: serializedInputProcessors,\n outputProcessors: serializedOutputProcessors,\n provider: llm?.getProvider(),\n modelId: llm?.getModelId(),\n modelVersion: model?.specificationVersion,\n modelList,\n defaultGenerateOptions,\n defaultStreamOptions,\n };\n}\n\nexport async function getAgentByIdHandler({\n mastra,\n runtimeContext,\n agentId,\n isPlayground = false,\n}: Context & { isPlayground?: boolean; runtimeContext: RuntimeContext; agentId: string }): Promise<\n SerializedAgent | ReturnType<typeof handleError>\n> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n return formatAgent({ mastra, agent, runtimeContext, isPlayground });\n } catch (error) {\n return handleError(error, 'Error getting agent');\n }\n}\n\nexport async function getEvalsByAgentIdHandler({\n mastra,\n runtimeContext,\n agentId,\n}: Context & { runtimeContext: RuntimeContext; agentId: string }) {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n const evals = (await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, 'test')) || [];\n const instructions = await agent.getInstructions({ runtimeContext });\n return {\n id: agentId,\n name: agent.name,\n instructions,\n evals,\n };\n } catch (error) {\n return handleError(error, 'Error getting test evals');\n }\n}\n\nexport async function getLiveEvalsByAgentIdHandler({\n mastra,\n runtimeContext,\n agentId,\n}: Context & { runtimeContext: RuntimeContext; agentId: string }) {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n const evals = (await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, 'live')) || [];\n const instructions = await agent.getInstructions({ runtimeContext });\n\n return {\n id: agentId,\n name: agent.name,\n instructions,\n evals,\n };\n } catch (error) {\n return handleError(error, 'Error getting live evals');\n }\n}\n\nexport async function generateLegacyHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetBody<'generateLegacy'> & {\n // @deprecated use resourceId\n resourceid?: string;\n runtimeContext?: Record<string, unknown>;\n };\n abortSignal?: AbortSignal;\n}) {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n // UI Frameworks may send \"client tools\" in the body,\n // but it interferes with llm providers tool handling, so we remove them\n sanitizeBody(body, ['tools']);\n\n const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;\n // Use resourceId if provided, fall back to resourceid (deprecated)\n const finalResourceId = resourceId ?? resourceid;\n\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n validateBody({ messages });\n\n const result = await agent.generateLegacy(messages, {\n ...rest,\n abortSignal,\n // @ts-expect-error TODO fix types\n resourceId: finalResourceId,\n runtimeContext: finalRuntimeContext,\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error generating from agent');\n }\n}\n\nexport async function generateHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetBody<'generate'> & {\n runtimeContext?: Record<string, unknown>;\n format?: 'mastra' | 'aisdk';\n };\n abortSignal?: AbortSignal;\n}): Promise<ReturnType<Agent['generate']>> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n // UI Frameworks may send \"client tools\" in the body,\n // but it interferes with llm providers tool handling, so we remove them\n sanitizeBody(body, ['tools']);\n\n const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;\n\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n validateBody({ messages });\n\n const result = await agent.generate(messages, {\n ...rest,\n runtimeContext: finalRuntimeContext,\n format: rest.format || 'mastra',\n abortSignal,\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error generating from agent');\n }\n}\n\nexport async function streamGenerateLegacyHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetBody<'streamLegacy'> & {\n // @deprecated use resourceId\n resourceid?: string;\n runtimeContext?: string;\n };\n abortSignal?: AbortSignal;\n}): Promise<Response | undefined> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;\n // Use resourceId if provided, fall back to resourceid (deprecated)\n const finalResourceId = resourceId ?? resourceid;\n\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n validateBody({ messages });\n\n const streamResult = await agent.streamLegacy(messages, {\n ...rest,\n abortSignal,\n // @ts-expect-error TODO fix types\n resourceId: finalResourceId,\n runtimeContext: finalRuntimeContext,\n });\n\n const streamResponse = rest.output\n ? streamResult.toTextStreamResponse({\n headers: {\n 'Transfer-Encoding': 'chunked',\n },\n })\n : streamResult.toDataStreamResponse({\n sendUsage: true,\n sendReasoning: true,\n getErrorMessage: (error: any) => {\n return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;\n },\n headers: {\n 'Transfer-Encoding': 'chunked',\n },\n });\n\n return streamResponse;\n } catch (error) {\n return handleError(error, 'error streaming agent response');\n }\n}\n\nexport async function streamGenerateHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetBody<'stream'> & {\n runtimeContext?: string;\n format?: 'aisdk' | 'mastra';\n };\n abortSignal?: AbortSignal;\n}): ReturnType<Agent['stream']> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n // UI Frameworks may send \"client tools\" in the body,\n // but it interferes with llm providers tool handling, so we remove them\n sanitizeBody(body, ['tools']);\n\n const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n validateBody({ messages });\n\n const streamResult = agent.stream(messages, {\n ...rest,\n runtimeContext: finalRuntimeContext,\n abortSignal,\n format: body.format ?? 'mastra',\n });\n\n return streamResult;\n } catch (error) {\n return handleError(error, 'error streaming agent response');\n }\n}\n\nexport async function approveToolCallHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetHITLBody<'approveToolCall'> & {\n runtimeContext?: string;\n format?: 'aisdk' | 'mastra';\n };\n abortSignal?: AbortSignal;\n}): ReturnType<Agent['approveToolCall']> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n // UI Frameworks may send \"client tools\" in the body,\n // but it interferes with llm providers tool handling, so we remove them\n sanitizeBody(body, ['tools']);\n\n const { runId, runtimeContext: agentRuntimeContext, ...rest } = body;\n\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n const streamResult = agent.approveToolCall({\n ...rest,\n runId,\n runtimeContext: finalRuntimeContext,\n abortSignal,\n format: body.format ?? 'mastra',\n });\n\n return streamResult;\n } catch (error) {\n return handleError(error, 'error streaming agent response');\n }\n}\n\nexport async function declineToolCallHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetHITLBody<'declineToolCall'> & {\n runtimeContext?: string;\n format?: 'aisdk' | 'mastra';\n };\n abortSignal?: AbortSignal;\n}): ReturnType<Agent['declineToolCall']> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n // UI Frameworks may send \"client tools\" in the body,\n // but it interferes with llm providers tool handling, so we remove them\n sanitizeBody(body, ['tools']);\n\n const { runId, runtimeContext: agentRuntimeContext, ...rest } = body;\n\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n const streamResult = agent.declineToolCall({\n ...rest,\n runId,\n runtimeContext: finalRuntimeContext,\n abortSignal,\n format: body.format ?? 'mastra',\n });\n\n return streamResult;\n } catch (error) {\n return handleError(error, 'error streaming agent response');\n }\n}\n\nexport async function streamNetworkHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n // abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetBody<'network'> & {\n thread?: string;\n resourceId?: string;\n };\n // abortSignal?: AbortSignal;\n}): ReturnType<Agent['network']> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n // UI Frameworks may send \"client tools\" in the body,\n // but it interferes with llm providers tool handling, so we remove them\n sanitizeBody(body, ['tools']);\n\n const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n validateBody({ messages });\n\n const streamResult = agent.network(messages, {\n ...rest,\n memory: {\n thread: rest.thread ?? '',\n resource: rest.resourceId ?? '',\n options: rest.memory?.options ?? {},\n },\n runtimeContext: finalRuntimeContext,\n });\n\n return streamResult;\n } catch (error) {\n return handleError(error, 'error streaming agent loop response');\n }\n}\n\nexport async function streamUIMessageHandler({\n mastra,\n runtimeContext,\n agentId,\n body,\n abortSignal,\n}: Context & {\n runtimeContext: RuntimeContext;\n agentId: string;\n body: GetBody<'stream'> & {\n runtimeContext?: string;\n onStepFinish?: StreamTextOnStepFinishCallback<any>;\n onFinish?: StreamTextOnFinishCallback<any>;\n output?: undefined;\n };\n abortSignal?: AbortSignal;\n}): Promise<Response | undefined> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n // UI Frameworks may send \"client tools\" in the body,\n // but it interferes with llm providers tool handling, so we remove them\n sanitizeBody(body, ['tools']);\n\n const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;\n const finalRuntimeContext = new RuntimeContext<Record<string, unknown>>([\n ...Array.from(runtimeContext.entries()),\n ...Array.from(Object.entries(agentRuntimeContext ?? {})),\n ]);\n\n validateBody({ messages });\n\n const streamResult = await agent.stream(messages, {\n ...rest,\n runtimeContext: finalRuntimeContext,\n abortSignal,\n format: 'aisdk',\n });\n\n return streamResult.toUIMessageStreamResponse();\n } catch (error) {\n return handleError(error, 'error streaming agent response');\n }\n}\n\nexport async function updateAgentModelHandler({\n mastra,\n agentId,\n body,\n}: Context & {\n agentId: string;\n body: {\n modelId: string;\n provider: string;\n };\n}): Promise<{ message: string }> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const { modelId, provider } = body;\n\n // Use the universal Mastra router format: provider/model\n const newModel = `${provider}/${modelId}`;\n\n agent.__updateModel({ model: newModel });\n\n return { message: 'Agent model updated' };\n } catch (error) {\n return handleError(error, 'error updating agent model');\n }\n}\n\nexport async function reorderAgentModelListHandler({\n mastra,\n agentId,\n body,\n}: Context & {\n agentId: string;\n body: {\n reorderedModelIds: Array<string>;\n };\n}): Promise<{ message: string }> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const modelList = await agent.getModelList();\n if (!modelList || modelList.length === 0) {\n throw new HTTPException(400, { message: 'Agent model list is not found or empty' });\n }\n\n agent.reorderModels(body.reorderedModelIds);\n\n return { message: 'Model list reordered' };\n } catch (error) {\n return handleError(error, 'error reordering model list');\n }\n}\n\nexport async function updateAgentModelInModelListHandler({\n mastra,\n agentId,\n modelConfigId,\n body,\n}: Context & {\n agentId: string;\n modelConfigId: string;\n body: {\n model?: {\n modelId: string;\n provider: string;\n };\n maxRetries?: number;\n enabled?: boolean;\n };\n}): Promise<{ message: string }> {\n try {\n const agent = await getAgentFromSystem({ mastra, agentId });\n\n const { model: bodyModel, maxRetries, enabled } = body;\n\n if (!modelConfigId) {\n throw new HTTPException(400, { message: 'Model id is required' });\n }\n\n const modelList = await agent.getModelList();\n if (!modelList || modelList.length === 0) {\n throw new HTTPException(400, { message: 'Agent model list is not found or empty' });\n }\n\n const modelToUpdate = modelList.find(m => m.id === modelConfigId);\n if (!modelToUpdate) {\n throw new HTTPException(400, { message: 'Model to update is not found in agent model list' });\n }\n\n let model: string | undefined;\n if (bodyModel) {\n const { modelId, provider } = bodyModel;\n // Use the universal Mastra router format: provider/model\n model = `${provider}/${modelId}`;\n }\n\n agent.updateModelInModelList({ id: modelConfigId, model, maxRetries, enabled });\n\n return { message: 'Model list updated' };\n } catch (error) {\n return handleError(error, 'error updating model list');\n }\n}\n\nexport async function getProvidersHandler() {\n try {\n const providers = Object.entries(PROVIDER_REGISTRY).map(([id, provider]) => {\n // Check if the provider is connected by checking for its API key env var(s)\n const envVars = Array.isArray(provider.apiKeyEnvVar) ? provider.apiKeyEnvVar : [provider.apiKeyEnvVar];\n const connected = envVars.every(envVar => !!process.env[envVar]);\n\n return {\n id,\n name: provider.name,\n envVar: provider.apiKeyEnvVar,\n connected,\n docUrl: provider.docUrl,\n models: [...provider.models], // Convert readonly array to regular array\n };\n });\n\n return { providers };\n } catch (error) {\n return handleError(error, 'error fetching providers');\n }\n}\n"]}