@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.
- package/CHANGELOG.md +58 -0
- package/dist/build/analyze/analyzeEntry.d.ts +2 -1
- package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
- package/dist/build/analyze/constants.d.ts.map +1 -1
- package/dist/build/analyze.cjs +2 -2
- package/dist/build/analyze.js +1 -1
- package/dist/build/bundler.cjs +3 -3
- package/dist/build/bundler.js +1 -1
- package/dist/build/index.cjs +12 -12
- package/dist/build/index.js +4 -4
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.js +1 -1
- package/dist/{chunk-HPIEW72C.cjs → chunk-AJX72IGP.cjs} +5 -5
- package/dist/{chunk-HPIEW72C.cjs.map → chunk-AJX72IGP.cjs.map} +1 -1
- package/dist/{chunk-BS2NS3OF.js → chunk-B2Q76NIL.js} +3 -3
- package/dist/{chunk-BS2NS3OF.js.map → chunk-B2Q76NIL.js.map} +1 -1
- package/dist/{chunk-S5UMATJZ.js → chunk-CVRN2K4O.js} +21 -11
- package/dist/chunk-CVRN2K4O.js.map +1 -0
- package/dist/{chunk-X4PRG273.js → chunk-FD5X42ZU.js} +4 -4
- package/dist/{chunk-X4PRG273.js.map → chunk-FD5X42ZU.js.map} +1 -1
- package/dist/{chunk-WVZENB5V.cjs → chunk-IAEJ3C3J.cjs} +21 -11
- package/dist/chunk-IAEJ3C3J.cjs.map +1 -0
- package/dist/{chunk-NMOPG6KM.cjs → chunk-NSINCI76.cjs} +9 -9
- package/dist/{chunk-NMOPG6KM.cjs.map → chunk-NSINCI76.cjs.map} +1 -1
- package/dist/{chunk-7TQIPPJV.cjs → chunk-OART5HV7.cjs} +15 -15
- package/dist/{chunk-7TQIPPJV.cjs.map → chunk-OART5HV7.cjs.map} +1 -1
- package/dist/{chunk-BTSMIAV6.js → chunk-VDRZB7JQ.js} +5 -5
- package/dist/{chunk-BTSMIAV6.js.map → chunk-VDRZB7JQ.js.map} +1 -1
- package/dist/{chunk-F54BDKO2.js → chunk-XHLN6E4D.js} +3 -3
- package/dist/{chunk-F54BDKO2.js.map → chunk-XHLN6E4D.js.map} +1 -1
- package/dist/{chunk-OVVFXLQK.cjs → chunk-Z546LAA6.cjs} +14 -14
- package/dist/{chunk-OVVFXLQK.cjs.map → chunk-Z546LAA6.cjs.map} +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.js +2 -2
- package/dist/server/handlers/auth/defaults.d.ts.map +1 -1
- package/dist/server/handlers/routes/agent-builder/router.d.ts.map +1 -1
- package/dist/server/handlers/routes/agents/handlers.d.ts +1 -10
- package/dist/server/handlers/routes/agents/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/agents/router.d.ts.map +1 -1
- package/dist/server/handlers/routes/memory/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/workflows/router.d.ts.map +1 -1
- package/dist/server/handlers/utils.d.ts +0 -7
- package/dist/server/handlers/utils.d.ts.map +1 -1
- package/dist/server/index.cjs +272 -258
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +273 -259
- package/dist/server/index.js.map +1 -1
- package/package.json +7 -7
- package/dist/chunk-S5UMATJZ.js.map +0 -1
- package/dist/chunk-WVZENB5V.cjs.map +0 -1
package/dist/server/index.cjs
CHANGED
|
@@ -24,13 +24,13 @@ var a2a = require('@mastra/server/handlers/a2a');
|
|
|
24
24
|
var streaming = require('hono/streaming');
|
|
25
25
|
var bodyLimit = require('hono/body-limit');
|
|
26
26
|
var agentBuilder = require('@mastra/server/handlers/agent-builder');
|
|
27
|
+
var agent = require('@mastra/core/agent');
|
|
28
|
+
var zod = require('zod');
|
|
29
|
+
var tools$1 = require('@mastra/server/handlers/tools');
|
|
27
30
|
var error = require('@mastra/core/error');
|
|
28
31
|
var llm = require('@mastra/core/llm');
|
|
29
32
|
var stream$1 = require('@mastra/core/stream');
|
|
30
33
|
var agents = require('@mastra/server/handlers/agents');
|
|
31
|
-
var agent = require('@mastra/core/agent');
|
|
32
|
-
var zod = require('zod');
|
|
33
|
-
var tools$1 = require('@mastra/server/handlers/tools');
|
|
34
34
|
var voice = require('@mastra/server/handlers/voice');
|
|
35
35
|
var logs = require('@mastra/server/handlers/logs');
|
|
36
36
|
var util = require('util');
|
|
@@ -1056,6 +1056,7 @@ async function getAgentExecutionHandler(c2) {
|
|
|
1056
1056
|
// src/server/handlers/auth/defaults.ts
|
|
1057
1057
|
var defaultAuthConfig = {
|
|
1058
1058
|
protected: ["/api/*"],
|
|
1059
|
+
public: ["/api"],
|
|
1059
1060
|
// Simple rule system
|
|
1060
1061
|
rules: [
|
|
1061
1062
|
// Admin users can do anything
|
|
@@ -1955,8 +1956,7 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
1955
1956
|
type: "object",
|
|
1956
1957
|
description: "Runtime context for the agent builder action execution"
|
|
1957
1958
|
}
|
|
1958
|
-
}
|
|
1959
|
-
required: ["step"]
|
|
1959
|
+
}
|
|
1960
1960
|
}
|
|
1961
1961
|
}
|
|
1962
1962
|
}
|
|
@@ -1999,8 +1999,7 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
1999
1999
|
type: "object",
|
|
2000
2000
|
description: "Runtime context for the agent builder action execution"
|
|
2001
2001
|
}
|
|
2002
|
-
}
|
|
2003
|
-
required: ["step"]
|
|
2002
|
+
}
|
|
2004
2003
|
}
|
|
2005
2004
|
}
|
|
2006
2005
|
}
|
|
@@ -2322,15 +2321,196 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2322
2321
|
);
|
|
2323
2322
|
return router;
|
|
2324
2323
|
}
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
}
|
|
2324
|
+
async function generateSystemPromptHandler(c2) {
|
|
2325
|
+
try {
|
|
2326
|
+
const agentId = c2.req.param("agentId");
|
|
2327
|
+
const isPlayground = c2.get("playground") === true;
|
|
2328
|
+
if (!isPlayground) {
|
|
2329
|
+
return c2.json({ error: "This API is only available in the playground environment" }, 403);
|
|
2330
|
+
}
|
|
2331
|
+
const { instructions, comment } = await c2.req.json();
|
|
2332
|
+
if (!instructions) {
|
|
2333
|
+
return c2.json({ error: "Missing instructions in request body" }, 400);
|
|
2334
|
+
}
|
|
2335
|
+
const mastra = c2.get("mastra");
|
|
2336
|
+
const agent$1 = mastra.getAgent(agentId);
|
|
2337
|
+
if (!agent$1) {
|
|
2338
|
+
return c2.json({ error: "Agent not found" }, 404);
|
|
2339
|
+
}
|
|
2340
|
+
let evalSummary = "";
|
|
2341
|
+
try {
|
|
2342
|
+
const testEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent$1.name, "test") || [];
|
|
2343
|
+
const liveEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent$1.name, "live") || [];
|
|
2344
|
+
const evalsMapped = [...testEvals, ...liveEvals].filter(
|
|
2345
|
+
({ instructions: evalInstructions }) => evalInstructions === instructions
|
|
2346
|
+
);
|
|
2347
|
+
evalSummary = evalsMapped.map(
|
|
2348
|
+
({ input, output, result: result2 }) => `
|
|
2349
|
+
Input: ${input}
|
|
2332
2350
|
|
|
2333
|
-
|
|
2351
|
+
Output: ${output}
|
|
2352
|
+
|
|
2353
|
+
Result: ${JSON.stringify(result2)}
|
|
2354
|
+
|
|
2355
|
+
`
|
|
2356
|
+
).join("");
|
|
2357
|
+
} catch (error) {
|
|
2358
|
+
mastra.getLogger().error(`Error fetching evals`, { error });
|
|
2359
|
+
}
|
|
2360
|
+
const ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS = `
|
|
2361
|
+
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.
|
|
2362
|
+
Follow these steps to analyze and enhance the instructions:
|
|
2363
|
+
1. ANALYSIS PHASE
|
|
2364
|
+
- Identify the core purpose and goals
|
|
2365
|
+
- Extract key constraints and requirements
|
|
2366
|
+
- Recognize domain-specific terminology and concepts
|
|
2367
|
+
- Note any implicit assumptions that should be made explicit
|
|
2368
|
+
2. PROMPT STRUCTURE
|
|
2369
|
+
Create a system prompt with these components:
|
|
2370
|
+
a) ROLE DEFINITION
|
|
2371
|
+
- Clear statement of the AI's role and purpose
|
|
2372
|
+
- Key responsibilities and scope
|
|
2373
|
+
- Primary stakeholders and users
|
|
2374
|
+
b) CORE CAPABILITIES
|
|
2375
|
+
- Main functions and abilities
|
|
2376
|
+
- Specific domain knowledge required
|
|
2377
|
+
- Tools and resources available
|
|
2378
|
+
c) BEHAVIORAL GUIDELINES
|
|
2379
|
+
- Communication style and tone
|
|
2380
|
+
- Decision-making framework
|
|
2381
|
+
- Error handling approach
|
|
2382
|
+
- Ethical considerations
|
|
2383
|
+
d) CONSTRAINTS & BOUNDARIES
|
|
2384
|
+
- Explicit limitations
|
|
2385
|
+
- Out-of-scope activities
|
|
2386
|
+
- Security and privacy considerations
|
|
2387
|
+
e) SUCCESS CRITERIA
|
|
2388
|
+
- Quality standards
|
|
2389
|
+
- Expected outcomes
|
|
2390
|
+
- Performance metrics
|
|
2391
|
+
3. QUALITY CHECKS
|
|
2392
|
+
Ensure the prompt is:
|
|
2393
|
+
- Clear and unambiguous
|
|
2394
|
+
- Comprehensive yet concise
|
|
2395
|
+
- Properly scoped
|
|
2396
|
+
- Technically accurate
|
|
2397
|
+
- Ethically sound
|
|
2398
|
+
4. OUTPUT FORMAT
|
|
2399
|
+
Return a structured response with:
|
|
2400
|
+
- Enhanced system prompt
|
|
2401
|
+
- Analysis of key components
|
|
2402
|
+
- Identified goals and constraints
|
|
2403
|
+
- Core domain concepts
|
|
2404
|
+
Remember: A good system prompt should be specific enough to guide behavior but flexible enough to handle edge cases.
|
|
2405
|
+
Focus on creating prompts that are clear, actionable, and aligned with the intended use case.
|
|
2406
|
+
`;
|
|
2407
|
+
const systemPromptAgent = new agent.Agent({
|
|
2408
|
+
name: "system-prompt-enhancer",
|
|
2409
|
+
instructions: ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS,
|
|
2410
|
+
model: agent$1.llm?.getModel()
|
|
2411
|
+
});
|
|
2412
|
+
const result = await systemPromptAgent.generate(
|
|
2413
|
+
`
|
|
2414
|
+
We need to improve the system prompt.
|
|
2415
|
+
Current: ${instructions}
|
|
2416
|
+
${comment ? `User feedback: ${comment}` : ""}
|
|
2417
|
+
${evalSummary ? `
|
|
2418
|
+
Evaluation Results:
|
|
2419
|
+
${evalSummary}` : ""}
|
|
2420
|
+
`,
|
|
2421
|
+
{
|
|
2422
|
+
output: zod.z.object({
|
|
2423
|
+
new_prompt: zod.z.string(),
|
|
2424
|
+
explanation: zod.z.string()
|
|
2425
|
+
})
|
|
2426
|
+
}
|
|
2427
|
+
);
|
|
2428
|
+
return c2.json(result?.object || {});
|
|
2429
|
+
} catch (error) {
|
|
2430
|
+
return handleError(error, "Error generating system prompt");
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
async function getToolsHandler(c2) {
|
|
2434
|
+
try {
|
|
2435
|
+
const tools = c2.get("tools");
|
|
2436
|
+
const result = await tools$1.getToolsHandler({
|
|
2437
|
+
tools
|
|
2438
|
+
});
|
|
2439
|
+
return c2.json(result || {});
|
|
2440
|
+
} catch (error) {
|
|
2441
|
+
return handleError(error, "Error getting tools");
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
async function getToolByIdHandler(c2) {
|
|
2445
|
+
try {
|
|
2446
|
+
const tools = c2.get("tools");
|
|
2447
|
+
const toolId = c2.req.param("toolId");
|
|
2448
|
+
const result = await tools$1.getToolByIdHandler({
|
|
2449
|
+
tools,
|
|
2450
|
+
toolId
|
|
2451
|
+
});
|
|
2452
|
+
return c2.json(result);
|
|
2453
|
+
} catch (error) {
|
|
2454
|
+
return handleError(error, "Error getting tool");
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
function executeToolHandler(tools) {
|
|
2458
|
+
return async (c2) => {
|
|
2459
|
+
try {
|
|
2460
|
+
const mastra = c2.get("mastra");
|
|
2461
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
2462
|
+
const toolId = decodeURIComponent(c2.req.param("toolId"));
|
|
2463
|
+
const runId = c2.req.query("runId");
|
|
2464
|
+
const { data } = await c2.req.json();
|
|
2465
|
+
const result = await tools$1.executeToolHandler(tools)({
|
|
2466
|
+
mastra,
|
|
2467
|
+
toolId,
|
|
2468
|
+
data,
|
|
2469
|
+
runtimeContext,
|
|
2470
|
+
runId
|
|
2471
|
+
});
|
|
2472
|
+
return c2.json(result);
|
|
2473
|
+
} catch (error) {
|
|
2474
|
+
return handleError(error, "Error executing tool");
|
|
2475
|
+
}
|
|
2476
|
+
};
|
|
2477
|
+
}
|
|
2478
|
+
async function getAgentToolHandler(c2) {
|
|
2479
|
+
try {
|
|
2480
|
+
const mastra = c2.get("mastra");
|
|
2481
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
2482
|
+
const agentId = c2.req.param("agentId");
|
|
2483
|
+
const toolId = c2.req.param("toolId");
|
|
2484
|
+
const result = await tools$1.getAgentToolHandler({
|
|
2485
|
+
mastra,
|
|
2486
|
+
agentId,
|
|
2487
|
+
toolId,
|
|
2488
|
+
runtimeContext
|
|
2489
|
+
});
|
|
2490
|
+
return c2.json(result);
|
|
2491
|
+
} catch (error) {
|
|
2492
|
+
return handleError(error, "Error getting agent tool");
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
async function executeAgentToolHandler(c2) {
|
|
2496
|
+
try {
|
|
2497
|
+
const mastra = c2.get("mastra");
|
|
2498
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
2499
|
+
const agentId = c2.req.param("agentId");
|
|
2500
|
+
const toolId = c2.req.param("toolId");
|
|
2501
|
+
const { data } = await c2.req.json();
|
|
2502
|
+
const result = await tools$1.executeAgentToolHandler({
|
|
2503
|
+
mastra,
|
|
2504
|
+
agentId,
|
|
2505
|
+
toolId,
|
|
2506
|
+
data,
|
|
2507
|
+
runtimeContext
|
|
2508
|
+
});
|
|
2509
|
+
return c2.json(result);
|
|
2510
|
+
} catch (error) {
|
|
2511
|
+
return handleError(error, "Error executing tool");
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2334
2514
|
var sharedBodyOptions = {
|
|
2335
2515
|
messages: {
|
|
2336
2516
|
type: "array",
|
|
@@ -2817,6 +2997,19 @@ async function updateAgentModelHandler(c2) {
|
|
|
2817
2997
|
return handleError(error, "Error updating agent model");
|
|
2818
2998
|
}
|
|
2819
2999
|
}
|
|
3000
|
+
async function resetAgentModelHandler(c2) {
|
|
3001
|
+
try {
|
|
3002
|
+
const mastra = c2.get("mastra");
|
|
3003
|
+
const agentId = c2.req.param("agentId");
|
|
3004
|
+
const result = await agents.resetAgentModelHandler({
|
|
3005
|
+
mastra,
|
|
3006
|
+
agentId
|
|
3007
|
+
});
|
|
3008
|
+
return c2.json(result);
|
|
3009
|
+
} catch (error) {
|
|
3010
|
+
return handleError(error, "Error resetting agent model");
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
2820
3013
|
async function deprecatedStreamVNextHandler(c2) {
|
|
2821
3014
|
return c2.json(
|
|
2822
3015
|
{
|
|
@@ -2829,28 +3022,6 @@ async function deprecatedStreamVNextHandler(c2) {
|
|
|
2829
3022
|
// 410 Gone status code for deprecated endpoints
|
|
2830
3023
|
);
|
|
2831
3024
|
}
|
|
2832
|
-
async function getModelProvidersHandler(c2) {
|
|
2833
|
-
const isPlayground = c2.get("playground") === true;
|
|
2834
|
-
if (!isPlayground) {
|
|
2835
|
-
return c2.json({ error: "This API is only available in the playground environment" }, 403);
|
|
2836
|
-
}
|
|
2837
|
-
const envVars = process.env;
|
|
2838
|
-
const providers = Object.entries(AllowedProviderKeys);
|
|
2839
|
-
const envKeys = Object.keys(envVars);
|
|
2840
|
-
const availableProviders = providers.filter(([_, value]) => envKeys.includes(value) && !!envVars[value]);
|
|
2841
|
-
const providerInfo = availableProviders.map(([key, envVar]) => {
|
|
2842
|
-
const providerConfig = llm.getProviderConfig(key);
|
|
2843
|
-
return {
|
|
2844
|
-
id: key,
|
|
2845
|
-
name: key.charAt(0).toUpperCase() + key.slice(1).replace(/-/g, " "),
|
|
2846
|
-
envVar,
|
|
2847
|
-
hasApiKey: !!envVars[envVar],
|
|
2848
|
-
docUrl: providerConfig?.docUrl || null,
|
|
2849
|
-
models: providerConfig?.models || []
|
|
2850
|
-
};
|
|
2851
|
-
});
|
|
2852
|
-
return c2.json(providerInfo);
|
|
2853
|
-
}
|
|
2854
3025
|
async function updateAgentModelInModelListHandler(c2) {
|
|
2855
3026
|
try {
|
|
2856
3027
|
const mastra = c2.get("mastra");
|
|
@@ -2883,196 +3054,6 @@ async function reorderAgentModelListHandler(c2) {
|
|
|
2883
3054
|
return handleError(error, "Error reordering agent model list");
|
|
2884
3055
|
}
|
|
2885
3056
|
}
|
|
2886
|
-
async function generateSystemPromptHandler(c2) {
|
|
2887
|
-
try {
|
|
2888
|
-
const agentId = c2.req.param("agentId");
|
|
2889
|
-
const isPlayground = c2.get("playground") === true;
|
|
2890
|
-
if (!isPlayground) {
|
|
2891
|
-
return c2.json({ error: "This API is only available in the playground environment" }, 403);
|
|
2892
|
-
}
|
|
2893
|
-
const { instructions, comment } = await c2.req.json();
|
|
2894
|
-
if (!instructions) {
|
|
2895
|
-
return c2.json({ error: "Missing instructions in request body" }, 400);
|
|
2896
|
-
}
|
|
2897
|
-
const mastra = c2.get("mastra");
|
|
2898
|
-
const agent$1 = mastra.getAgent(agentId);
|
|
2899
|
-
if (!agent$1) {
|
|
2900
|
-
return c2.json({ error: "Agent not found" }, 404);
|
|
2901
|
-
}
|
|
2902
|
-
let evalSummary = "";
|
|
2903
|
-
try {
|
|
2904
|
-
const testEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent$1.name, "test") || [];
|
|
2905
|
-
const liveEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent$1.name, "live") || [];
|
|
2906
|
-
const evalsMapped = [...testEvals, ...liveEvals].filter(
|
|
2907
|
-
({ instructions: evalInstructions }) => evalInstructions === instructions
|
|
2908
|
-
);
|
|
2909
|
-
evalSummary = evalsMapped.map(
|
|
2910
|
-
({ input, output, result: result2 }) => `
|
|
2911
|
-
Input: ${input}
|
|
2912
|
-
|
|
2913
|
-
Output: ${output}
|
|
2914
|
-
|
|
2915
|
-
Result: ${JSON.stringify(result2)}
|
|
2916
|
-
|
|
2917
|
-
`
|
|
2918
|
-
).join("");
|
|
2919
|
-
} catch (error) {
|
|
2920
|
-
mastra.getLogger().error(`Error fetching evals`, { error });
|
|
2921
|
-
}
|
|
2922
|
-
const ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS = `
|
|
2923
|
-
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.
|
|
2924
|
-
Follow these steps to analyze and enhance the instructions:
|
|
2925
|
-
1. ANALYSIS PHASE
|
|
2926
|
-
- Identify the core purpose and goals
|
|
2927
|
-
- Extract key constraints and requirements
|
|
2928
|
-
- Recognize domain-specific terminology and concepts
|
|
2929
|
-
- Note any implicit assumptions that should be made explicit
|
|
2930
|
-
2. PROMPT STRUCTURE
|
|
2931
|
-
Create a system prompt with these components:
|
|
2932
|
-
a) ROLE DEFINITION
|
|
2933
|
-
- Clear statement of the AI's role and purpose
|
|
2934
|
-
- Key responsibilities and scope
|
|
2935
|
-
- Primary stakeholders and users
|
|
2936
|
-
b) CORE CAPABILITIES
|
|
2937
|
-
- Main functions and abilities
|
|
2938
|
-
- Specific domain knowledge required
|
|
2939
|
-
- Tools and resources available
|
|
2940
|
-
c) BEHAVIORAL GUIDELINES
|
|
2941
|
-
- Communication style and tone
|
|
2942
|
-
- Decision-making framework
|
|
2943
|
-
- Error handling approach
|
|
2944
|
-
- Ethical considerations
|
|
2945
|
-
d) CONSTRAINTS & BOUNDARIES
|
|
2946
|
-
- Explicit limitations
|
|
2947
|
-
- Out-of-scope activities
|
|
2948
|
-
- Security and privacy considerations
|
|
2949
|
-
e) SUCCESS CRITERIA
|
|
2950
|
-
- Quality standards
|
|
2951
|
-
- Expected outcomes
|
|
2952
|
-
- Performance metrics
|
|
2953
|
-
3. QUALITY CHECKS
|
|
2954
|
-
Ensure the prompt is:
|
|
2955
|
-
- Clear and unambiguous
|
|
2956
|
-
- Comprehensive yet concise
|
|
2957
|
-
- Properly scoped
|
|
2958
|
-
- Technically accurate
|
|
2959
|
-
- Ethically sound
|
|
2960
|
-
4. OUTPUT FORMAT
|
|
2961
|
-
Return a structured response with:
|
|
2962
|
-
- Enhanced system prompt
|
|
2963
|
-
- Analysis of key components
|
|
2964
|
-
- Identified goals and constraints
|
|
2965
|
-
- Core domain concepts
|
|
2966
|
-
Remember: A good system prompt should be specific enough to guide behavior but flexible enough to handle edge cases.
|
|
2967
|
-
Focus on creating prompts that are clear, actionable, and aligned with the intended use case.
|
|
2968
|
-
`;
|
|
2969
|
-
const systemPromptAgent = new agent.Agent({
|
|
2970
|
-
name: "system-prompt-enhancer",
|
|
2971
|
-
instructions: ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS,
|
|
2972
|
-
model: agent$1.llm?.getModel()
|
|
2973
|
-
});
|
|
2974
|
-
const result = await systemPromptAgent.generate(
|
|
2975
|
-
`
|
|
2976
|
-
We need to improve the system prompt.
|
|
2977
|
-
Current: ${instructions}
|
|
2978
|
-
${comment ? `User feedback: ${comment}` : ""}
|
|
2979
|
-
${evalSummary ? `
|
|
2980
|
-
Evaluation Results:
|
|
2981
|
-
${evalSummary}` : ""}
|
|
2982
|
-
`,
|
|
2983
|
-
{
|
|
2984
|
-
output: zod.z.object({
|
|
2985
|
-
new_prompt: zod.z.string(),
|
|
2986
|
-
explanation: zod.z.string()
|
|
2987
|
-
})
|
|
2988
|
-
}
|
|
2989
|
-
);
|
|
2990
|
-
return c2.json(result?.object || {});
|
|
2991
|
-
} catch (error) {
|
|
2992
|
-
return handleError(error, "Error generating system prompt");
|
|
2993
|
-
}
|
|
2994
|
-
}
|
|
2995
|
-
async function getToolsHandler(c2) {
|
|
2996
|
-
try {
|
|
2997
|
-
const tools = c2.get("tools");
|
|
2998
|
-
const result = await tools$1.getToolsHandler({
|
|
2999
|
-
tools
|
|
3000
|
-
});
|
|
3001
|
-
return c2.json(result || {});
|
|
3002
|
-
} catch (error) {
|
|
3003
|
-
return handleError(error, "Error getting tools");
|
|
3004
|
-
}
|
|
3005
|
-
}
|
|
3006
|
-
async function getToolByIdHandler(c2) {
|
|
3007
|
-
try {
|
|
3008
|
-
const tools = c2.get("tools");
|
|
3009
|
-
const toolId = c2.req.param("toolId");
|
|
3010
|
-
const result = await tools$1.getToolByIdHandler({
|
|
3011
|
-
tools,
|
|
3012
|
-
toolId
|
|
3013
|
-
});
|
|
3014
|
-
return c2.json(result);
|
|
3015
|
-
} catch (error) {
|
|
3016
|
-
return handleError(error, "Error getting tool");
|
|
3017
|
-
}
|
|
3018
|
-
}
|
|
3019
|
-
function executeToolHandler(tools) {
|
|
3020
|
-
return async (c2) => {
|
|
3021
|
-
try {
|
|
3022
|
-
const mastra = c2.get("mastra");
|
|
3023
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
3024
|
-
const toolId = decodeURIComponent(c2.req.param("toolId"));
|
|
3025
|
-
const runId = c2.req.query("runId");
|
|
3026
|
-
const { data } = await c2.req.json();
|
|
3027
|
-
const result = await tools$1.executeToolHandler(tools)({
|
|
3028
|
-
mastra,
|
|
3029
|
-
toolId,
|
|
3030
|
-
data,
|
|
3031
|
-
runtimeContext,
|
|
3032
|
-
runId
|
|
3033
|
-
});
|
|
3034
|
-
return c2.json(result);
|
|
3035
|
-
} catch (error) {
|
|
3036
|
-
return handleError(error, "Error executing tool");
|
|
3037
|
-
}
|
|
3038
|
-
};
|
|
3039
|
-
}
|
|
3040
|
-
async function getAgentToolHandler(c2) {
|
|
3041
|
-
try {
|
|
3042
|
-
const mastra = c2.get("mastra");
|
|
3043
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
3044
|
-
const agentId = c2.req.param("agentId");
|
|
3045
|
-
const toolId = c2.req.param("toolId");
|
|
3046
|
-
const result = await tools$1.getAgentToolHandler({
|
|
3047
|
-
mastra,
|
|
3048
|
-
agentId,
|
|
3049
|
-
toolId,
|
|
3050
|
-
runtimeContext
|
|
3051
|
-
});
|
|
3052
|
-
return c2.json(result);
|
|
3053
|
-
} catch (error) {
|
|
3054
|
-
return handleError(error, "Error getting agent tool");
|
|
3055
|
-
}
|
|
3056
|
-
}
|
|
3057
|
-
async function executeAgentToolHandler(c2) {
|
|
3058
|
-
try {
|
|
3059
|
-
const mastra = c2.get("mastra");
|
|
3060
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
3061
|
-
const agentId = c2.req.param("agentId");
|
|
3062
|
-
const toolId = c2.req.param("toolId");
|
|
3063
|
-
const { data } = await c2.req.json();
|
|
3064
|
-
const result = await tools$1.executeAgentToolHandler({
|
|
3065
|
-
mastra,
|
|
3066
|
-
agentId,
|
|
3067
|
-
toolId,
|
|
3068
|
-
data,
|
|
3069
|
-
runtimeContext
|
|
3070
|
-
});
|
|
3071
|
-
return c2.json(result);
|
|
3072
|
-
} catch (error) {
|
|
3073
|
-
return handleError(error, "Error executing tool");
|
|
3074
|
-
}
|
|
3075
|
-
}
|
|
3076
3057
|
async function getSpeakersHandler(c2) {
|
|
3077
3058
|
try {
|
|
3078
3059
|
const mastra = c2.get("mastra");
|
|
@@ -3856,6 +3837,31 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
3856
3837
|
}),
|
|
3857
3838
|
updateAgentModelHandler
|
|
3858
3839
|
);
|
|
3840
|
+
router.post(
|
|
3841
|
+
"/:agentId/model/reset",
|
|
3842
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3843
|
+
w({
|
|
3844
|
+
description: "Reset the agent model to the original model set during construction",
|
|
3845
|
+
tags: ["agents"],
|
|
3846
|
+
parameters: [
|
|
3847
|
+
{
|
|
3848
|
+
name: "agentId",
|
|
3849
|
+
in: "path",
|
|
3850
|
+
required: true,
|
|
3851
|
+
schema: { type: "string" }
|
|
3852
|
+
}
|
|
3853
|
+
],
|
|
3854
|
+
responses: {
|
|
3855
|
+
200: {
|
|
3856
|
+
description: "Model reset to original successfully"
|
|
3857
|
+
},
|
|
3858
|
+
404: {
|
|
3859
|
+
description: "Agent not found"
|
|
3860
|
+
}
|
|
3861
|
+
}
|
|
3862
|
+
}),
|
|
3863
|
+
resetAgentModelHandler
|
|
3864
|
+
);
|
|
3859
3865
|
router.post(
|
|
3860
3866
|
"/:agentId/models/reorder",
|
|
3861
3867
|
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
@@ -7341,9 +7347,11 @@ async function getMemoryStatusHandler(c2) {
|
|
|
7341
7347
|
try {
|
|
7342
7348
|
const mastra = c2.get("mastra");
|
|
7343
7349
|
const agentId = c2.req.query("agentId");
|
|
7350
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7344
7351
|
const result = await memory.getMemoryStatusHandler({
|
|
7345
7352
|
mastra,
|
|
7346
|
-
agentId
|
|
7353
|
+
agentId,
|
|
7354
|
+
runtimeContext
|
|
7347
7355
|
});
|
|
7348
7356
|
return c2.json(result);
|
|
7349
7357
|
} catch (error) {
|
|
@@ -7354,9 +7362,11 @@ async function getMemoryConfigHandler(c2) {
|
|
|
7354
7362
|
try {
|
|
7355
7363
|
const mastra = c2.get("mastra");
|
|
7356
7364
|
const agentId = c2.req.query("agentId");
|
|
7365
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7357
7366
|
const result = await memory.getMemoryConfigHandler({
|
|
7358
7367
|
mastra,
|
|
7359
|
-
agentId
|
|
7368
|
+
agentId,
|
|
7369
|
+
runtimeContext
|
|
7360
7370
|
});
|
|
7361
7371
|
return c2.json(result);
|
|
7362
7372
|
} catch (error) {
|
|
@@ -7370,12 +7380,14 @@ async function getThreadsHandler(c2) {
|
|
|
7370
7380
|
const resourceId = c2.req.query("resourceid");
|
|
7371
7381
|
const orderBy = c2.req.query("orderBy");
|
|
7372
7382
|
const sortDirection = c2.req.query("sortDirection");
|
|
7383
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7373
7384
|
const result = await memory.getThreadsHandler({
|
|
7374
7385
|
mastra,
|
|
7375
7386
|
agentId,
|
|
7376
7387
|
resourceId,
|
|
7377
7388
|
orderBy,
|
|
7378
|
-
sortDirection
|
|
7389
|
+
sortDirection,
|
|
7390
|
+
runtimeContext
|
|
7379
7391
|
});
|
|
7380
7392
|
return c2.json(result);
|
|
7381
7393
|
} catch (error) {
|
|
@@ -7391,6 +7403,7 @@ async function getThreadsPaginatedHandler(c2) {
|
|
|
7391
7403
|
const perPage = parseInt(c2.req.query("perPage") || "100", 10);
|
|
7392
7404
|
const orderBy = c2.req.query("orderBy");
|
|
7393
7405
|
const sortDirection = c2.req.query("sortDirection");
|
|
7406
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7394
7407
|
const result = await memory.getThreadsPaginatedHandler({
|
|
7395
7408
|
mastra,
|
|
7396
7409
|
agentId,
|
|
@@ -7398,7 +7411,8 @@ async function getThreadsPaginatedHandler(c2) {
|
|
|
7398
7411
|
page,
|
|
7399
7412
|
perPage,
|
|
7400
7413
|
orderBy,
|
|
7401
|
-
sortDirection
|
|
7414
|
+
sortDirection,
|
|
7415
|
+
runtimeContext
|
|
7402
7416
|
});
|
|
7403
7417
|
return c2.json(result);
|
|
7404
7418
|
} catch (error) {
|
|
@@ -7410,10 +7424,12 @@ async function getThreadByIdHandler(c2) {
|
|
|
7410
7424
|
const mastra = c2.get("mastra");
|
|
7411
7425
|
const agentId = c2.req.query("agentId");
|
|
7412
7426
|
const threadId = c2.req.param("threadId");
|
|
7427
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7413
7428
|
const result = await memory.getThreadByIdHandler({
|
|
7414
7429
|
mastra,
|
|
7415
7430
|
agentId,
|
|
7416
|
-
threadId
|
|
7431
|
+
threadId,
|
|
7432
|
+
runtimeContext
|
|
7417
7433
|
});
|
|
7418
7434
|
return c2.json(result);
|
|
7419
7435
|
} catch (error) {
|
|
@@ -7425,10 +7441,12 @@ async function saveMessagesHandler(c2) {
|
|
|
7425
7441
|
const mastra = c2.get("mastra");
|
|
7426
7442
|
const agentId = c2.req.query("agentId");
|
|
7427
7443
|
const body = await c2.req.json();
|
|
7444
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7428
7445
|
const result = await memory.saveMessagesHandler({
|
|
7429
7446
|
mastra,
|
|
7430
7447
|
agentId,
|
|
7431
|
-
body
|
|
7448
|
+
body,
|
|
7449
|
+
runtimeContext
|
|
7432
7450
|
});
|
|
7433
7451
|
return c2.json(result);
|
|
7434
7452
|
} catch (error) {
|
|
@@ -7440,10 +7458,12 @@ async function createThreadHandler(c2) {
|
|
|
7440
7458
|
const mastra = c2.get("mastra");
|
|
7441
7459
|
const agentId = c2.req.query("agentId");
|
|
7442
7460
|
const body = await c2.req.json();
|
|
7461
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7443
7462
|
const result = await memory.createThreadHandler({
|
|
7444
7463
|
mastra,
|
|
7445
7464
|
agentId,
|
|
7446
|
-
body
|
|
7465
|
+
body,
|
|
7466
|
+
runtimeContext
|
|
7447
7467
|
});
|
|
7448
7468
|
return c2.json(result);
|
|
7449
7469
|
} catch (error) {
|
|
@@ -7456,11 +7476,13 @@ async function updateThreadHandler(c2) {
|
|
|
7456
7476
|
const agentId = c2.req.query("agentId");
|
|
7457
7477
|
const threadId = c2.req.param("threadId");
|
|
7458
7478
|
const body = await c2.req.json();
|
|
7479
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7459
7480
|
const result = await memory.updateThreadHandler({
|
|
7460
7481
|
mastra,
|
|
7461
7482
|
agentId,
|
|
7462
7483
|
threadId,
|
|
7463
|
-
body
|
|
7484
|
+
body,
|
|
7485
|
+
runtimeContext
|
|
7464
7486
|
});
|
|
7465
7487
|
return c2.json(result);
|
|
7466
7488
|
} catch (error) {
|
|
@@ -7472,10 +7494,12 @@ async function deleteThreadHandler(c2) {
|
|
|
7472
7494
|
const mastra = c2.get("mastra");
|
|
7473
7495
|
const agentId = c2.req.query("agentId");
|
|
7474
7496
|
const threadId = c2.req.param("threadId");
|
|
7497
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7475
7498
|
const result = await memory.deleteThreadHandler({
|
|
7476
7499
|
mastra,
|
|
7477
7500
|
agentId,
|
|
7478
|
-
threadId
|
|
7501
|
+
threadId,
|
|
7502
|
+
runtimeContext
|
|
7479
7503
|
});
|
|
7480
7504
|
return c2.json(result);
|
|
7481
7505
|
} catch (error) {
|
|
@@ -7488,11 +7512,13 @@ async function getMessagesHandler(c2) {
|
|
|
7488
7512
|
const agentId = c2.req.query("agentId");
|
|
7489
7513
|
const threadId = c2.req.param("threadId");
|
|
7490
7514
|
const limit = parseLimit(c2.req.query("limit"));
|
|
7515
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7491
7516
|
const result = await memory.getMessagesHandler({
|
|
7492
7517
|
mastra,
|
|
7493
7518
|
agentId,
|
|
7494
7519
|
threadId,
|
|
7495
|
-
limit
|
|
7520
|
+
limit,
|
|
7521
|
+
runtimeContext
|
|
7496
7522
|
});
|
|
7497
7523
|
return c2.json(result);
|
|
7498
7524
|
} catch (error) {
|
|
@@ -7531,11 +7557,13 @@ async function updateWorkingMemoryHandler(c2) {
|
|
|
7531
7557
|
const agentId = c2.req.query("agentId");
|
|
7532
7558
|
const threadId = c2.req.param("threadId");
|
|
7533
7559
|
const body = await c2.req.json();
|
|
7560
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7534
7561
|
const result = await memory.updateWorkingMemoryHandler({
|
|
7535
7562
|
mastra,
|
|
7536
7563
|
agentId,
|
|
7537
7564
|
threadId,
|
|
7538
|
-
body
|
|
7565
|
+
body,
|
|
7566
|
+
runtimeContext
|
|
7539
7567
|
});
|
|
7540
7568
|
return c2.json(result);
|
|
7541
7569
|
} catch (error) {
|
|
@@ -7548,11 +7576,13 @@ async function getWorkingMemoryHandler(c2) {
|
|
|
7548
7576
|
const agentId = c2.req.query("agentId");
|
|
7549
7577
|
const threadId = c2.req.param("threadId");
|
|
7550
7578
|
const resourceId = c2.req.query("resourceId");
|
|
7579
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7551
7580
|
const result = await memory.getWorkingMemoryHandler({
|
|
7552
7581
|
mastra,
|
|
7553
7582
|
agentId,
|
|
7554
7583
|
threadId,
|
|
7555
|
-
resourceId
|
|
7584
|
+
resourceId,
|
|
7585
|
+
runtimeContext
|
|
7556
7586
|
});
|
|
7557
7587
|
return c2.json(result);
|
|
7558
7588
|
} catch (error) {
|
|
@@ -10961,8 +10991,7 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
10961
10991
|
type: "object",
|
|
10962
10992
|
description: "Runtime context for the workflow execution"
|
|
10963
10993
|
}
|
|
10964
|
-
}
|
|
10965
|
-
required: ["step"]
|
|
10994
|
+
}
|
|
10966
10995
|
}
|
|
10967
10996
|
}
|
|
10968
10997
|
}
|
|
@@ -11015,8 +11044,7 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11015
11044
|
}
|
|
11016
11045
|
}
|
|
11017
11046
|
}
|
|
11018
|
-
}
|
|
11019
|
-
required: ["step"]
|
|
11047
|
+
}
|
|
11020
11048
|
}
|
|
11021
11049
|
}
|
|
11022
11050
|
}
|
|
@@ -11059,8 +11087,7 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11059
11087
|
type: "object",
|
|
11060
11088
|
description: "Runtime context for the workflow execution"
|
|
11061
11089
|
}
|
|
11062
|
-
}
|
|
11063
|
-
required: ["step"]
|
|
11090
|
+
}
|
|
11064
11091
|
}
|
|
11065
11092
|
}
|
|
11066
11093
|
}
|
|
@@ -12004,19 +12031,6 @@ async function createHonoServer(mastra, options = {
|
|
|
12004
12031
|
}),
|
|
12005
12032
|
rootHandler
|
|
12006
12033
|
);
|
|
12007
|
-
app.get(
|
|
12008
|
-
"/api/model-providers",
|
|
12009
|
-
w({
|
|
12010
|
-
description: "Get all model providers with available keys",
|
|
12011
|
-
tags: ["agents"],
|
|
12012
|
-
responses: {
|
|
12013
|
-
200: {
|
|
12014
|
-
description: "All model providers with available keys"
|
|
12015
|
-
}
|
|
12016
|
-
}
|
|
12017
|
-
}),
|
|
12018
|
-
getModelProvidersHandler
|
|
12019
|
-
);
|
|
12020
12034
|
app.route("/api/agents", agentsRouter(bodyLimitOptions));
|
|
12021
12035
|
if (options.isDev) {
|
|
12022
12036
|
app.route("/api/agents", agentsRouterDev(bodyLimitOptions));
|