@mastra/deployer 0.23.2 → 0.24.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/dist/build/analyze/analyzeEntry.d.ts +2 -1
  3. package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
  4. package/dist/build/analyze/constants.d.ts.map +1 -1
  5. package/dist/build/analyze.cjs +2 -2
  6. package/dist/build/analyze.js +1 -1
  7. package/dist/build/bundler.cjs +3 -3
  8. package/dist/build/bundler.js +1 -1
  9. package/dist/build/index.cjs +12 -12
  10. package/dist/build/index.js +4 -4
  11. package/dist/bundler/index.cjs +2 -2
  12. package/dist/bundler/index.js +1 -1
  13. package/dist/{chunk-HPIEW72C.cjs → chunk-AJX72IGP.cjs} +5 -5
  14. package/dist/{chunk-HPIEW72C.cjs.map → chunk-AJX72IGP.cjs.map} +1 -1
  15. package/dist/{chunk-BS2NS3OF.js → chunk-B2Q76NIL.js} +3 -3
  16. package/dist/{chunk-BS2NS3OF.js.map → chunk-B2Q76NIL.js.map} +1 -1
  17. package/dist/{chunk-S5UMATJZ.js → chunk-CVRN2K4O.js} +21 -11
  18. package/dist/chunk-CVRN2K4O.js.map +1 -0
  19. package/dist/{chunk-X4PRG273.js → chunk-FD5X42ZU.js} +4 -4
  20. package/dist/{chunk-X4PRG273.js.map → chunk-FD5X42ZU.js.map} +1 -1
  21. package/dist/{chunk-WVZENB5V.cjs → chunk-IAEJ3C3J.cjs} +21 -11
  22. package/dist/chunk-IAEJ3C3J.cjs.map +1 -0
  23. package/dist/{chunk-NMOPG6KM.cjs → chunk-NSINCI76.cjs} +9 -9
  24. package/dist/{chunk-NMOPG6KM.cjs.map → chunk-NSINCI76.cjs.map} +1 -1
  25. package/dist/{chunk-7TQIPPJV.cjs → chunk-OART5HV7.cjs} +15 -15
  26. package/dist/{chunk-7TQIPPJV.cjs.map → chunk-OART5HV7.cjs.map} +1 -1
  27. package/dist/{chunk-BTSMIAV6.js → chunk-VDRZB7JQ.js} +5 -5
  28. package/dist/{chunk-BTSMIAV6.js.map → chunk-VDRZB7JQ.js.map} +1 -1
  29. package/dist/{chunk-F54BDKO2.js → chunk-XHLN6E4D.js} +3 -3
  30. package/dist/{chunk-F54BDKO2.js.map → chunk-XHLN6E4D.js.map} +1 -1
  31. package/dist/{chunk-OVVFXLQK.cjs → chunk-Z546LAA6.cjs} +14 -14
  32. package/dist/{chunk-OVVFXLQK.cjs.map → chunk-Z546LAA6.cjs.map} +1 -1
  33. package/dist/index.cjs +5 -5
  34. package/dist/index.js +2 -2
  35. package/dist/server/handlers/auth/defaults.d.ts.map +1 -1
  36. package/dist/server/handlers/routes/agent-builder/router.d.ts.map +1 -1
  37. package/dist/server/handlers/routes/agents/handlers.d.ts +1 -10
  38. package/dist/server/handlers/routes/agents/handlers.d.ts.map +1 -1
  39. package/dist/server/handlers/routes/agents/router.d.ts.map +1 -1
  40. package/dist/server/handlers/routes/memory/handlers.d.ts.map +1 -1
  41. package/dist/server/handlers/routes/workflows/router.d.ts.map +1 -1
  42. package/dist/server/handlers/utils.d.ts +0 -7
  43. package/dist/server/handlers/utils.d.ts.map +1 -1
  44. package/dist/server/index.cjs +272 -258
  45. package/dist/server/index.cjs.map +1 -1
  46. package/dist/server/index.d.ts.map +1 -1
  47. package/dist/server/index.js +273 -259
  48. package/dist/server/index.js.map +1 -1
  49. package/package.json +7 -7
  50. package/dist/chunk-S5UMATJZ.js.map +0 -1
  51. package/dist/chunk-WVZENB5V.cjs.map +0 -1
@@ -22,13 +22,13 @@ import { getAgentCardByIdHandler as getAgentCardByIdHandler$1, getAgentExecution
22
22
  import { stream } from 'hono/streaming';
23
23
  import { bodyLimit } from 'hono/body-limit';
24
24
  import { getAgentBuilderActionsHandler as getAgentBuilderActionsHandler$1, getAgentBuilderActionByIdHandler as getAgentBuilderActionByIdHandler$1, getAgentBuilderActionRunsHandler as getAgentBuilderActionRunsHandler$1, getAgentBuilderActionRunExecutionResultHandler as getAgentBuilderActionRunExecutionResultHandler$1, getAgentBuilderActionRunByIdHandler as getAgentBuilderActionRunByIdHandler$1, resumeAgentBuilderActionHandler as resumeAgentBuilderActionHandler$1, resumeAsyncAgentBuilderActionHandler as resumeAsyncAgentBuilderActionHandler$1, streamAgentBuilderActionHandler as streamAgentBuilderActionHandler$1, streamVNextAgentBuilderActionHandler as streamVNextAgentBuilderActionHandler$1, createAgentBuilderActionRunHandler as createAgentBuilderActionRunHandler$1, startAsyncAgentBuilderActionHandler as startAsyncAgentBuilderActionHandler$1, startAgentBuilderActionRunHandler as startAgentBuilderActionRunHandler$1, watchAgentBuilderActionHandler as watchAgentBuilderActionHandler$1, cancelAgentBuilderActionRunHandler as cancelAgentBuilderActionRunHandler$1, sendAgentBuilderActionRunEventHandler as sendAgentBuilderActionRunEventHandler$1 } from '@mastra/server/handlers/agent-builder';
25
- import { MastraError, ErrorCategory, ErrorDomain, getErrorFromUnknown } from '@mastra/core/error';
26
- import { getProviderConfig, PROVIDER_REGISTRY } from '@mastra/core/llm';
27
- import { ChunkFrom } from '@mastra/core/stream';
28
- import { getAgentsHandler as getAgentsHandler$1, getAgentByIdHandler as getAgentByIdHandler$1, getEvalsByAgentIdHandler as getEvalsByAgentIdHandler$1, getLiveEvalsByAgentIdHandler as getLiveEvalsByAgentIdHandler$1, generateLegacyHandler as generateLegacyHandler$1, generateHandler as generateHandler$1, getAgentFromSystem, streamNetworkHandler as streamNetworkHandler$1, streamGenerateHandler as streamGenerateHandler$1, streamGenerateLegacyHandler as streamGenerateLegacyHandler$1, streamUIMessageHandler as streamUIMessageHandler$1, updateAgentModelHandler as updateAgentModelHandler$1, reorderAgentModelListHandler as reorderAgentModelListHandler$1, updateAgentModelInModelListHandler as updateAgentModelInModelListHandler$1, approveToolCallHandler as approveToolCallHandler$1, declineToolCallHandler as declineToolCallHandler$1 } from '@mastra/server/handlers/agents';
29
25
  import { Agent } from '@mastra/core/agent';
30
26
  import { z } from 'zod';
31
27
  import { getAgentToolHandler as getAgentToolHandler$1, executeAgentToolHandler as executeAgentToolHandler$1, getToolsHandler as getToolsHandler$1, getToolByIdHandler as getToolByIdHandler$1, executeToolHandler as executeToolHandler$1 } from '@mastra/server/handlers/tools';
28
+ import { MastraError, ErrorCategory, ErrorDomain, getErrorFromUnknown } from '@mastra/core/error';
29
+ import { PROVIDER_REGISTRY, getProviderConfig } from '@mastra/core/llm';
30
+ import { ChunkFrom } from '@mastra/core/stream';
31
+ import { getAgentsHandler as getAgentsHandler$1, getAgentByIdHandler as getAgentByIdHandler$1, getEvalsByAgentIdHandler as getEvalsByAgentIdHandler$1, getLiveEvalsByAgentIdHandler as getLiveEvalsByAgentIdHandler$1, generateLegacyHandler as generateLegacyHandler$1, generateHandler as generateHandler$1, getAgentFromSystem, streamNetworkHandler as streamNetworkHandler$1, streamGenerateHandler as streamGenerateHandler$1, streamGenerateLegacyHandler as streamGenerateLegacyHandler$1, streamUIMessageHandler as streamUIMessageHandler$1, updateAgentModelHandler as updateAgentModelHandler$1, resetAgentModelHandler as resetAgentModelHandler$1, reorderAgentModelListHandler as reorderAgentModelListHandler$1, updateAgentModelInModelListHandler as updateAgentModelInModelListHandler$1, approveToolCallHandler as approveToolCallHandler$1, declineToolCallHandler as declineToolCallHandler$1 } from '@mastra/server/handlers/agents';
32
32
  import { getSpeakersHandler as getSpeakersHandler$1, generateSpeechHandler, getListenerHandler as getListenerHandler$1, transcribeSpeechHandler } from '@mastra/server/handlers/voice';
33
33
  import { getLogsHandler as getLogsHandler$1, getLogTransports as getLogTransports$1, getLogsByRunIdHandler as getLogsByRunIdHandler$1 } from '@mastra/server/handlers/logs';
34
34
  import util from 'util';
@@ -1030,6 +1030,7 @@ async function getAgentExecutionHandler(c2) {
1030
1030
  // src/server/handlers/auth/defaults.ts
1031
1031
  var defaultAuthConfig = {
1032
1032
  protected: ["/api/*"],
1033
+ public: ["/api"],
1033
1034
  // Simple rule system
1034
1035
  rules: [
1035
1036
  // Admin users can do anything
@@ -1929,8 +1930,7 @@ function agentBuilderRouter(bodyLimitOptions) {
1929
1930
  type: "object",
1930
1931
  description: "Runtime context for the agent builder action execution"
1931
1932
  }
1932
- },
1933
- required: ["step"]
1933
+ }
1934
1934
  }
1935
1935
  }
1936
1936
  }
@@ -1973,8 +1973,7 @@ function agentBuilderRouter(bodyLimitOptions) {
1973
1973
  type: "object",
1974
1974
  description: "Runtime context for the agent builder action execution"
1975
1975
  }
1976
- },
1977
- required: ["step"]
1976
+ }
1978
1977
  }
1979
1978
  }
1980
1979
  }
@@ -2296,15 +2295,196 @@ function agentBuilderRouter(bodyLimitOptions) {
2296
2295
  );
2297
2296
  return router;
2298
2297
  }
2299
- var AllowedProviderKeys = {
2300
- openai: "OPENAI_API_KEY",
2301
- xai: "XAI_API_KEY",
2302
- anthropic: "ANTHROPIC_API_KEY",
2303
- google: "GOOGLE_GENERATIVE_AI_API_KEY",
2304
- groq: "GROQ_API_KEY"
2305
- };
2298
+ async function generateSystemPromptHandler(c2) {
2299
+ try {
2300
+ const agentId = c2.req.param("agentId");
2301
+ const isPlayground = c2.get("playground") === true;
2302
+ if (!isPlayground) {
2303
+ return c2.json({ error: "This API is only available in the playground environment" }, 403);
2304
+ }
2305
+ const { instructions, comment } = await c2.req.json();
2306
+ if (!instructions) {
2307
+ return c2.json({ error: "Missing instructions in request body" }, 400);
2308
+ }
2309
+ const mastra = c2.get("mastra");
2310
+ const agent = mastra.getAgent(agentId);
2311
+ if (!agent) {
2312
+ return c2.json({ error: "Agent not found" }, 404);
2313
+ }
2314
+ let evalSummary = "";
2315
+ try {
2316
+ const testEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
2317
+ const liveEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
2318
+ const evalsMapped = [...testEvals, ...liveEvals].filter(
2319
+ ({ instructions: evalInstructions }) => evalInstructions === instructions
2320
+ );
2321
+ evalSummary = evalsMapped.map(
2322
+ ({ input, output, result: result2 }) => `
2323
+ Input: ${input}
2324
+
2325
+ Output: ${output}
2306
2326
 
2307
- // src/server/handlers/routes/agents/handlers.ts
2327
+ Result: ${JSON.stringify(result2)}
2328
+
2329
+ `
2330
+ ).join("");
2331
+ } catch (error) {
2332
+ mastra.getLogger().error(`Error fetching evals`, { error });
2333
+ }
2334
+ const ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS = `
2335
+ You are an expert system prompt engineer, specialized in analyzing and enhancing instructions to create clear, effective, and comprehensive system prompts. Your goal is to help users transform their basic instructions into well-structured system prompts that will guide AI behavior effectively.
2336
+ Follow these steps to analyze and enhance the instructions:
2337
+ 1. ANALYSIS PHASE
2338
+ - Identify the core purpose and goals
2339
+ - Extract key constraints and requirements
2340
+ - Recognize domain-specific terminology and concepts
2341
+ - Note any implicit assumptions that should be made explicit
2342
+ 2. PROMPT STRUCTURE
2343
+ Create a system prompt with these components:
2344
+ a) ROLE DEFINITION
2345
+ - Clear statement of the AI's role and purpose
2346
+ - Key responsibilities and scope
2347
+ - Primary stakeholders and users
2348
+ b) CORE CAPABILITIES
2349
+ - Main functions and abilities
2350
+ - Specific domain knowledge required
2351
+ - Tools and resources available
2352
+ c) BEHAVIORAL GUIDELINES
2353
+ - Communication style and tone
2354
+ - Decision-making framework
2355
+ - Error handling approach
2356
+ - Ethical considerations
2357
+ d) CONSTRAINTS & BOUNDARIES
2358
+ - Explicit limitations
2359
+ - Out-of-scope activities
2360
+ - Security and privacy considerations
2361
+ e) SUCCESS CRITERIA
2362
+ - Quality standards
2363
+ - Expected outcomes
2364
+ - Performance metrics
2365
+ 3. QUALITY CHECKS
2366
+ Ensure the prompt is:
2367
+ - Clear and unambiguous
2368
+ - Comprehensive yet concise
2369
+ - Properly scoped
2370
+ - Technically accurate
2371
+ - Ethically sound
2372
+ 4. OUTPUT FORMAT
2373
+ Return a structured response with:
2374
+ - Enhanced system prompt
2375
+ - Analysis of key components
2376
+ - Identified goals and constraints
2377
+ - Core domain concepts
2378
+ Remember: A good system prompt should be specific enough to guide behavior but flexible enough to handle edge cases.
2379
+ Focus on creating prompts that are clear, actionable, and aligned with the intended use case.
2380
+ `;
2381
+ const systemPromptAgent = new Agent({
2382
+ name: "system-prompt-enhancer",
2383
+ instructions: ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS,
2384
+ model: agent.llm?.getModel()
2385
+ });
2386
+ const result = await systemPromptAgent.generate(
2387
+ `
2388
+ We need to improve the system prompt.
2389
+ Current: ${instructions}
2390
+ ${comment ? `User feedback: ${comment}` : ""}
2391
+ ${evalSummary ? `
2392
+ Evaluation Results:
2393
+ ${evalSummary}` : ""}
2394
+ `,
2395
+ {
2396
+ output: z.object({
2397
+ new_prompt: z.string(),
2398
+ explanation: z.string()
2399
+ })
2400
+ }
2401
+ );
2402
+ return c2.json(result?.object || {});
2403
+ } catch (error) {
2404
+ return handleError(error, "Error generating system prompt");
2405
+ }
2406
+ }
2407
+ async function getToolsHandler(c2) {
2408
+ try {
2409
+ const tools = c2.get("tools");
2410
+ const result = await getToolsHandler$1({
2411
+ tools
2412
+ });
2413
+ return c2.json(result || {});
2414
+ } catch (error) {
2415
+ return handleError(error, "Error getting tools");
2416
+ }
2417
+ }
2418
+ async function getToolByIdHandler(c2) {
2419
+ try {
2420
+ const tools = c2.get("tools");
2421
+ const toolId = c2.req.param("toolId");
2422
+ const result = await getToolByIdHandler$1({
2423
+ tools,
2424
+ toolId
2425
+ });
2426
+ return c2.json(result);
2427
+ } catch (error) {
2428
+ return handleError(error, "Error getting tool");
2429
+ }
2430
+ }
2431
+ function executeToolHandler(tools) {
2432
+ return async (c2) => {
2433
+ try {
2434
+ const mastra = c2.get("mastra");
2435
+ const runtimeContext = c2.get("runtimeContext");
2436
+ const toolId = decodeURIComponent(c2.req.param("toolId"));
2437
+ const runId = c2.req.query("runId");
2438
+ const { data } = await c2.req.json();
2439
+ const result = await executeToolHandler$1(tools)({
2440
+ mastra,
2441
+ toolId,
2442
+ data,
2443
+ runtimeContext,
2444
+ runId
2445
+ });
2446
+ return c2.json(result);
2447
+ } catch (error) {
2448
+ return handleError(error, "Error executing tool");
2449
+ }
2450
+ };
2451
+ }
2452
+ async function getAgentToolHandler(c2) {
2453
+ try {
2454
+ const mastra = c2.get("mastra");
2455
+ const runtimeContext = c2.get("runtimeContext");
2456
+ const agentId = c2.req.param("agentId");
2457
+ const toolId = c2.req.param("toolId");
2458
+ const result = await getAgentToolHandler$1({
2459
+ mastra,
2460
+ agentId,
2461
+ toolId,
2462
+ runtimeContext
2463
+ });
2464
+ return c2.json(result);
2465
+ } catch (error) {
2466
+ return handleError(error, "Error getting agent tool");
2467
+ }
2468
+ }
2469
+ async function executeAgentToolHandler(c2) {
2470
+ try {
2471
+ const mastra = c2.get("mastra");
2472
+ const runtimeContext = c2.get("runtimeContext");
2473
+ const agentId = c2.req.param("agentId");
2474
+ const toolId = c2.req.param("toolId");
2475
+ const { data } = await c2.req.json();
2476
+ const result = await executeAgentToolHandler$1({
2477
+ mastra,
2478
+ agentId,
2479
+ toolId,
2480
+ data,
2481
+ runtimeContext
2482
+ });
2483
+ return c2.json(result);
2484
+ } catch (error) {
2485
+ return handleError(error, "Error executing tool");
2486
+ }
2487
+ }
2308
2488
  var sharedBodyOptions = {
2309
2489
  messages: {
2310
2490
  type: "array",
@@ -2791,6 +2971,19 @@ async function updateAgentModelHandler(c2) {
2791
2971
  return handleError(error, "Error updating agent model");
2792
2972
  }
2793
2973
  }
2974
+ async function resetAgentModelHandler(c2) {
2975
+ try {
2976
+ const mastra = c2.get("mastra");
2977
+ const agentId = c2.req.param("agentId");
2978
+ const result = await resetAgentModelHandler$1({
2979
+ mastra,
2980
+ agentId
2981
+ });
2982
+ return c2.json(result);
2983
+ } catch (error) {
2984
+ return handleError(error, "Error resetting agent model");
2985
+ }
2986
+ }
2794
2987
  async function deprecatedStreamVNextHandler(c2) {
2795
2988
  return c2.json(
2796
2989
  {
@@ -2803,28 +2996,6 @@ async function deprecatedStreamVNextHandler(c2) {
2803
2996
  // 410 Gone status code for deprecated endpoints
2804
2997
  );
2805
2998
  }
2806
- async function getModelProvidersHandler(c2) {
2807
- const isPlayground = c2.get("playground") === true;
2808
- if (!isPlayground) {
2809
- return c2.json({ error: "This API is only available in the playground environment" }, 403);
2810
- }
2811
- const envVars = process.env;
2812
- const providers = Object.entries(AllowedProviderKeys);
2813
- const envKeys = Object.keys(envVars);
2814
- const availableProviders = providers.filter(([_, value]) => envKeys.includes(value) && !!envVars[value]);
2815
- const providerInfo = availableProviders.map(([key, envVar]) => {
2816
- const providerConfig = getProviderConfig(key);
2817
- return {
2818
- id: key,
2819
- name: key.charAt(0).toUpperCase() + key.slice(1).replace(/-/g, " "),
2820
- envVar,
2821
- hasApiKey: !!envVars[envVar],
2822
- docUrl: providerConfig?.docUrl || null,
2823
- models: providerConfig?.models || []
2824
- };
2825
- });
2826
- return c2.json(providerInfo);
2827
- }
2828
2999
  async function updateAgentModelInModelListHandler(c2) {
2829
3000
  try {
2830
3001
  const mastra = c2.get("mastra");
@@ -2857,196 +3028,6 @@ async function reorderAgentModelListHandler(c2) {
2857
3028
  return handleError(error, "Error reordering agent model list");
2858
3029
  }
2859
3030
  }
2860
- async function generateSystemPromptHandler(c2) {
2861
- try {
2862
- const agentId = c2.req.param("agentId");
2863
- const isPlayground = c2.get("playground") === true;
2864
- if (!isPlayground) {
2865
- return c2.json({ error: "This API is only available in the playground environment" }, 403);
2866
- }
2867
- const { instructions, comment } = await c2.req.json();
2868
- if (!instructions) {
2869
- return c2.json({ error: "Missing instructions in request body" }, 400);
2870
- }
2871
- const mastra = c2.get("mastra");
2872
- const agent = mastra.getAgent(agentId);
2873
- if (!agent) {
2874
- return c2.json({ error: "Agent not found" }, 404);
2875
- }
2876
- let evalSummary = "";
2877
- try {
2878
- const testEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
2879
- const liveEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
2880
- const evalsMapped = [...testEvals, ...liveEvals].filter(
2881
- ({ instructions: evalInstructions }) => evalInstructions === instructions
2882
- );
2883
- evalSummary = evalsMapped.map(
2884
- ({ input, output, result: result2 }) => `
2885
- Input: ${input}
2886
-
2887
- Output: ${output}
2888
-
2889
- Result: ${JSON.stringify(result2)}
2890
-
2891
- `
2892
- ).join("");
2893
- } catch (error) {
2894
- mastra.getLogger().error(`Error fetching evals`, { error });
2895
- }
2896
- const ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS = `
2897
- You are an expert system prompt engineer, specialized in analyzing and enhancing instructions to create clear, effective, and comprehensive system prompts. Your goal is to help users transform their basic instructions into well-structured system prompts that will guide AI behavior effectively.
2898
- Follow these steps to analyze and enhance the instructions:
2899
- 1. ANALYSIS PHASE
2900
- - Identify the core purpose and goals
2901
- - Extract key constraints and requirements
2902
- - Recognize domain-specific terminology and concepts
2903
- - Note any implicit assumptions that should be made explicit
2904
- 2. PROMPT STRUCTURE
2905
- Create a system prompt with these components:
2906
- a) ROLE DEFINITION
2907
- - Clear statement of the AI's role and purpose
2908
- - Key responsibilities and scope
2909
- - Primary stakeholders and users
2910
- b) CORE CAPABILITIES
2911
- - Main functions and abilities
2912
- - Specific domain knowledge required
2913
- - Tools and resources available
2914
- c) BEHAVIORAL GUIDELINES
2915
- - Communication style and tone
2916
- - Decision-making framework
2917
- - Error handling approach
2918
- - Ethical considerations
2919
- d) CONSTRAINTS & BOUNDARIES
2920
- - Explicit limitations
2921
- - Out-of-scope activities
2922
- - Security and privacy considerations
2923
- e) SUCCESS CRITERIA
2924
- - Quality standards
2925
- - Expected outcomes
2926
- - Performance metrics
2927
- 3. QUALITY CHECKS
2928
- Ensure the prompt is:
2929
- - Clear and unambiguous
2930
- - Comprehensive yet concise
2931
- - Properly scoped
2932
- - Technically accurate
2933
- - Ethically sound
2934
- 4. OUTPUT FORMAT
2935
- Return a structured response with:
2936
- - Enhanced system prompt
2937
- - Analysis of key components
2938
- - Identified goals and constraints
2939
- - Core domain concepts
2940
- Remember: A good system prompt should be specific enough to guide behavior but flexible enough to handle edge cases.
2941
- Focus on creating prompts that are clear, actionable, and aligned with the intended use case.
2942
- `;
2943
- const systemPromptAgent = new Agent({
2944
- name: "system-prompt-enhancer",
2945
- instructions: ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS,
2946
- model: agent.llm?.getModel()
2947
- });
2948
- const result = await systemPromptAgent.generate(
2949
- `
2950
- We need to improve the system prompt.
2951
- Current: ${instructions}
2952
- ${comment ? `User feedback: ${comment}` : ""}
2953
- ${evalSummary ? `
2954
- Evaluation Results:
2955
- ${evalSummary}` : ""}
2956
- `,
2957
- {
2958
- output: z.object({
2959
- new_prompt: z.string(),
2960
- explanation: z.string()
2961
- })
2962
- }
2963
- );
2964
- return c2.json(result?.object || {});
2965
- } catch (error) {
2966
- return handleError(error, "Error generating system prompt");
2967
- }
2968
- }
2969
- async function getToolsHandler(c2) {
2970
- try {
2971
- const tools = c2.get("tools");
2972
- const result = await getToolsHandler$1({
2973
- tools
2974
- });
2975
- return c2.json(result || {});
2976
- } catch (error) {
2977
- return handleError(error, "Error getting tools");
2978
- }
2979
- }
2980
- async function getToolByIdHandler(c2) {
2981
- try {
2982
- const tools = c2.get("tools");
2983
- const toolId = c2.req.param("toolId");
2984
- const result = await getToolByIdHandler$1({
2985
- tools,
2986
- toolId
2987
- });
2988
- return c2.json(result);
2989
- } catch (error) {
2990
- return handleError(error, "Error getting tool");
2991
- }
2992
- }
2993
- function executeToolHandler(tools) {
2994
- return async (c2) => {
2995
- try {
2996
- const mastra = c2.get("mastra");
2997
- const runtimeContext = c2.get("runtimeContext");
2998
- const toolId = decodeURIComponent(c2.req.param("toolId"));
2999
- const runId = c2.req.query("runId");
3000
- const { data } = await c2.req.json();
3001
- const result = await executeToolHandler$1(tools)({
3002
- mastra,
3003
- toolId,
3004
- data,
3005
- runtimeContext,
3006
- runId
3007
- });
3008
- return c2.json(result);
3009
- } catch (error) {
3010
- return handleError(error, "Error executing tool");
3011
- }
3012
- };
3013
- }
3014
- async function getAgentToolHandler(c2) {
3015
- try {
3016
- const mastra = c2.get("mastra");
3017
- const runtimeContext = c2.get("runtimeContext");
3018
- const agentId = c2.req.param("agentId");
3019
- const toolId = c2.req.param("toolId");
3020
- const result = await getAgentToolHandler$1({
3021
- mastra,
3022
- agentId,
3023
- toolId,
3024
- runtimeContext
3025
- });
3026
- return c2.json(result);
3027
- } catch (error) {
3028
- return handleError(error, "Error getting agent tool");
3029
- }
3030
- }
3031
- async function executeAgentToolHandler(c2) {
3032
- try {
3033
- const mastra = c2.get("mastra");
3034
- const runtimeContext = c2.get("runtimeContext");
3035
- const agentId = c2.req.param("agentId");
3036
- const toolId = c2.req.param("toolId");
3037
- const { data } = await c2.req.json();
3038
- const result = await executeAgentToolHandler$1({
3039
- mastra,
3040
- agentId,
3041
- toolId,
3042
- data,
3043
- runtimeContext
3044
- });
3045
- return c2.json(result);
3046
- } catch (error) {
3047
- return handleError(error, "Error executing tool");
3048
- }
3049
- }
3050
3031
  async function getSpeakersHandler(c2) {
3051
3032
  try {
3052
3033
  const mastra = c2.get("mastra");
@@ -3830,6 +3811,31 @@ function agentsRouter(bodyLimitOptions) {
3830
3811
  }),
3831
3812
  updateAgentModelHandler
3832
3813
  );
3814
+ router.post(
3815
+ "/:agentId/model/reset",
3816
+ bodyLimit(bodyLimitOptions),
3817
+ w({
3818
+ description: "Reset the agent model to the original model set during construction",
3819
+ tags: ["agents"],
3820
+ parameters: [
3821
+ {
3822
+ name: "agentId",
3823
+ in: "path",
3824
+ required: true,
3825
+ schema: { type: "string" }
3826
+ }
3827
+ ],
3828
+ responses: {
3829
+ 200: {
3830
+ description: "Model reset to original successfully"
3831
+ },
3832
+ 404: {
3833
+ description: "Agent not found"
3834
+ }
3835
+ }
3836
+ }),
3837
+ resetAgentModelHandler
3838
+ );
3833
3839
  router.post(
3834
3840
  "/:agentId/models/reorder",
3835
3841
  bodyLimit(bodyLimitOptions),
@@ -7315,9 +7321,11 @@ async function getMemoryStatusHandler(c2) {
7315
7321
  try {
7316
7322
  const mastra = c2.get("mastra");
7317
7323
  const agentId = c2.req.query("agentId");
7324
+ const runtimeContext = c2.get("runtimeContext");
7318
7325
  const result = await getMemoryStatusHandler$1({
7319
7326
  mastra,
7320
- agentId
7327
+ agentId,
7328
+ runtimeContext
7321
7329
  });
7322
7330
  return c2.json(result);
7323
7331
  } catch (error) {
@@ -7328,9 +7336,11 @@ async function getMemoryConfigHandler(c2) {
7328
7336
  try {
7329
7337
  const mastra = c2.get("mastra");
7330
7338
  const agentId = c2.req.query("agentId");
7339
+ const runtimeContext = c2.get("runtimeContext");
7331
7340
  const result = await getMemoryConfigHandler$1({
7332
7341
  mastra,
7333
- agentId
7342
+ agentId,
7343
+ runtimeContext
7334
7344
  });
7335
7345
  return c2.json(result);
7336
7346
  } catch (error) {
@@ -7344,12 +7354,14 @@ async function getThreadsHandler(c2) {
7344
7354
  const resourceId = c2.req.query("resourceid");
7345
7355
  const orderBy = c2.req.query("orderBy");
7346
7356
  const sortDirection = c2.req.query("sortDirection");
7357
+ const runtimeContext = c2.get("runtimeContext");
7347
7358
  const result = await getThreadsHandler$1({
7348
7359
  mastra,
7349
7360
  agentId,
7350
7361
  resourceId,
7351
7362
  orderBy,
7352
- sortDirection
7363
+ sortDirection,
7364
+ runtimeContext
7353
7365
  });
7354
7366
  return c2.json(result);
7355
7367
  } catch (error) {
@@ -7365,6 +7377,7 @@ async function getThreadsPaginatedHandler(c2) {
7365
7377
  const perPage = parseInt(c2.req.query("perPage") || "100", 10);
7366
7378
  const orderBy = c2.req.query("orderBy");
7367
7379
  const sortDirection = c2.req.query("sortDirection");
7380
+ const runtimeContext = c2.get("runtimeContext");
7368
7381
  const result = await getThreadsPaginatedHandler$1({
7369
7382
  mastra,
7370
7383
  agentId,
@@ -7372,7 +7385,8 @@ async function getThreadsPaginatedHandler(c2) {
7372
7385
  page,
7373
7386
  perPage,
7374
7387
  orderBy,
7375
- sortDirection
7388
+ sortDirection,
7389
+ runtimeContext
7376
7390
  });
7377
7391
  return c2.json(result);
7378
7392
  } catch (error) {
@@ -7384,10 +7398,12 @@ async function getThreadByIdHandler(c2) {
7384
7398
  const mastra = c2.get("mastra");
7385
7399
  const agentId = c2.req.query("agentId");
7386
7400
  const threadId = c2.req.param("threadId");
7401
+ const runtimeContext = c2.get("runtimeContext");
7387
7402
  const result = await getThreadByIdHandler$1({
7388
7403
  mastra,
7389
7404
  agentId,
7390
- threadId
7405
+ threadId,
7406
+ runtimeContext
7391
7407
  });
7392
7408
  return c2.json(result);
7393
7409
  } catch (error) {
@@ -7399,10 +7415,12 @@ async function saveMessagesHandler(c2) {
7399
7415
  const mastra = c2.get("mastra");
7400
7416
  const agentId = c2.req.query("agentId");
7401
7417
  const body = await c2.req.json();
7418
+ const runtimeContext = c2.get("runtimeContext");
7402
7419
  const result = await saveMessagesHandler$1({
7403
7420
  mastra,
7404
7421
  agentId,
7405
- body
7422
+ body,
7423
+ runtimeContext
7406
7424
  });
7407
7425
  return c2.json(result);
7408
7426
  } catch (error) {
@@ -7414,10 +7432,12 @@ async function createThreadHandler(c2) {
7414
7432
  const mastra = c2.get("mastra");
7415
7433
  const agentId = c2.req.query("agentId");
7416
7434
  const body = await c2.req.json();
7435
+ const runtimeContext = c2.get("runtimeContext");
7417
7436
  const result = await createThreadHandler$1({
7418
7437
  mastra,
7419
7438
  agentId,
7420
- body
7439
+ body,
7440
+ runtimeContext
7421
7441
  });
7422
7442
  return c2.json(result);
7423
7443
  } catch (error) {
@@ -7430,11 +7450,13 @@ async function updateThreadHandler(c2) {
7430
7450
  const agentId = c2.req.query("agentId");
7431
7451
  const threadId = c2.req.param("threadId");
7432
7452
  const body = await c2.req.json();
7453
+ const runtimeContext = c2.get("runtimeContext");
7433
7454
  const result = await updateThreadHandler$1({
7434
7455
  mastra,
7435
7456
  agentId,
7436
7457
  threadId,
7437
- body
7458
+ body,
7459
+ runtimeContext
7438
7460
  });
7439
7461
  return c2.json(result);
7440
7462
  } catch (error) {
@@ -7446,10 +7468,12 @@ async function deleteThreadHandler(c2) {
7446
7468
  const mastra = c2.get("mastra");
7447
7469
  const agentId = c2.req.query("agentId");
7448
7470
  const threadId = c2.req.param("threadId");
7471
+ const runtimeContext = c2.get("runtimeContext");
7449
7472
  const result = await deleteThreadHandler$1({
7450
7473
  mastra,
7451
7474
  agentId,
7452
- threadId
7475
+ threadId,
7476
+ runtimeContext
7453
7477
  });
7454
7478
  return c2.json(result);
7455
7479
  } catch (error) {
@@ -7462,11 +7486,13 @@ async function getMessagesHandler(c2) {
7462
7486
  const agentId = c2.req.query("agentId");
7463
7487
  const threadId = c2.req.param("threadId");
7464
7488
  const limit = parseLimit(c2.req.query("limit"));
7489
+ const runtimeContext = c2.get("runtimeContext");
7465
7490
  const result = await getMessagesHandler$1({
7466
7491
  mastra,
7467
7492
  agentId,
7468
7493
  threadId,
7469
- limit
7494
+ limit,
7495
+ runtimeContext
7470
7496
  });
7471
7497
  return c2.json(result);
7472
7498
  } catch (error) {
@@ -7505,11 +7531,13 @@ async function updateWorkingMemoryHandler(c2) {
7505
7531
  const agentId = c2.req.query("agentId");
7506
7532
  const threadId = c2.req.param("threadId");
7507
7533
  const body = await c2.req.json();
7534
+ const runtimeContext = c2.get("runtimeContext");
7508
7535
  const result = await updateWorkingMemoryHandler$1({
7509
7536
  mastra,
7510
7537
  agentId,
7511
7538
  threadId,
7512
- body
7539
+ body,
7540
+ runtimeContext
7513
7541
  });
7514
7542
  return c2.json(result);
7515
7543
  } catch (error) {
@@ -7522,11 +7550,13 @@ async function getWorkingMemoryHandler(c2) {
7522
7550
  const agentId = c2.req.query("agentId");
7523
7551
  const threadId = c2.req.param("threadId");
7524
7552
  const resourceId = c2.req.query("resourceId");
7553
+ const runtimeContext = c2.get("runtimeContext");
7525
7554
  const result = await getWorkingMemoryHandler$1({
7526
7555
  mastra,
7527
7556
  agentId,
7528
7557
  threadId,
7529
- resourceId
7558
+ resourceId,
7559
+ runtimeContext
7530
7560
  });
7531
7561
  return c2.json(result);
7532
7562
  } catch (error) {
@@ -10935,8 +10965,7 @@ function workflowsRouter(bodyLimitOptions) {
10935
10965
  type: "object",
10936
10966
  description: "Runtime context for the workflow execution"
10937
10967
  }
10938
- },
10939
- required: ["step"]
10968
+ }
10940
10969
  }
10941
10970
  }
10942
10971
  }
@@ -10989,8 +11018,7 @@ function workflowsRouter(bodyLimitOptions) {
10989
11018
  }
10990
11019
  }
10991
11020
  }
10992
- },
10993
- required: ["step"]
11021
+ }
10994
11022
  }
10995
11023
  }
10996
11024
  }
@@ -11033,8 +11061,7 @@ function workflowsRouter(bodyLimitOptions) {
11033
11061
  type: "object",
11034
11062
  description: "Runtime context for the workflow execution"
11035
11063
  }
11036
- },
11037
- required: ["step"]
11064
+ }
11038
11065
  }
11039
11066
  }
11040
11067
  }
@@ -11978,19 +12005,6 @@ async function createHonoServer(mastra, options = {
11978
12005
  }),
11979
12006
  rootHandler
11980
12007
  );
11981
- app.get(
11982
- "/api/model-providers",
11983
- w({
11984
- description: "Get all model providers with available keys",
11985
- tags: ["agents"],
11986
- responses: {
11987
- 200: {
11988
- description: "All model providers with available keys"
11989
- }
11990
- }
11991
- }),
11992
- getModelProvidersHandler
11993
- );
11994
12008
  app.route("/api/agents", agentsRouter(bodyLimitOptions));
11995
12009
  if (options.isDev) {
11996
12010
  app.route("/api/agents", agentsRouterDev(bodyLimitOptions));