@mastra/deployer 0.23.3 → 0.24.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 +68 -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/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/utils.d.ts +0 -7
- package/dist/server/handlers/utils.d.ts.map +1 -1
- package/dist/server/index.cjs +267 -248
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +268 -249
- 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.js
CHANGED
|
@@ -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
|
|
@@ -2294,15 +2295,196 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2294
2295
|
);
|
|
2295
2296
|
return router;
|
|
2296
2297
|
}
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
}
|
|
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}
|
|
2326
|
+
|
|
2327
|
+
Result: ${JSON.stringify(result2)}
|
|
2304
2328
|
|
|
2305
|
-
|
|
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
|
+
}
|
|
2306
2488
|
var sharedBodyOptions = {
|
|
2307
2489
|
messages: {
|
|
2308
2490
|
type: "array",
|
|
@@ -2789,6 +2971,19 @@ async function updateAgentModelHandler(c2) {
|
|
|
2789
2971
|
return handleError(error, "Error updating agent model");
|
|
2790
2972
|
}
|
|
2791
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
|
+
}
|
|
2792
2987
|
async function deprecatedStreamVNextHandler(c2) {
|
|
2793
2988
|
return c2.json(
|
|
2794
2989
|
{
|
|
@@ -2801,28 +2996,6 @@ async function deprecatedStreamVNextHandler(c2) {
|
|
|
2801
2996
|
// 410 Gone status code for deprecated endpoints
|
|
2802
2997
|
);
|
|
2803
2998
|
}
|
|
2804
|
-
async function getModelProvidersHandler(c2) {
|
|
2805
|
-
const isPlayground = c2.get("playground") === true;
|
|
2806
|
-
if (!isPlayground) {
|
|
2807
|
-
return c2.json({ error: "This API is only available in the playground environment" }, 403);
|
|
2808
|
-
}
|
|
2809
|
-
const envVars = process.env;
|
|
2810
|
-
const providers = Object.entries(AllowedProviderKeys);
|
|
2811
|
-
const envKeys = Object.keys(envVars);
|
|
2812
|
-
const availableProviders = providers.filter(([_, value]) => envKeys.includes(value) && !!envVars[value]);
|
|
2813
|
-
const providerInfo = availableProviders.map(([key, envVar]) => {
|
|
2814
|
-
const providerConfig = getProviderConfig(key);
|
|
2815
|
-
return {
|
|
2816
|
-
id: key,
|
|
2817
|
-
name: key.charAt(0).toUpperCase() + key.slice(1).replace(/-/g, " "),
|
|
2818
|
-
envVar,
|
|
2819
|
-
hasApiKey: !!envVars[envVar],
|
|
2820
|
-
docUrl: providerConfig?.docUrl || null,
|
|
2821
|
-
models: providerConfig?.models || []
|
|
2822
|
-
};
|
|
2823
|
-
});
|
|
2824
|
-
return c2.json(providerInfo);
|
|
2825
|
-
}
|
|
2826
2999
|
async function updateAgentModelInModelListHandler(c2) {
|
|
2827
3000
|
try {
|
|
2828
3001
|
const mastra = c2.get("mastra");
|
|
@@ -2855,196 +3028,6 @@ async function reorderAgentModelListHandler(c2) {
|
|
|
2855
3028
|
return handleError(error, "Error reordering agent model list");
|
|
2856
3029
|
}
|
|
2857
3030
|
}
|
|
2858
|
-
async function generateSystemPromptHandler(c2) {
|
|
2859
|
-
try {
|
|
2860
|
-
const agentId = c2.req.param("agentId");
|
|
2861
|
-
const isPlayground = c2.get("playground") === true;
|
|
2862
|
-
if (!isPlayground) {
|
|
2863
|
-
return c2.json({ error: "This API is only available in the playground environment" }, 403);
|
|
2864
|
-
}
|
|
2865
|
-
const { instructions, comment } = await c2.req.json();
|
|
2866
|
-
if (!instructions) {
|
|
2867
|
-
return c2.json({ error: "Missing instructions in request body" }, 400);
|
|
2868
|
-
}
|
|
2869
|
-
const mastra = c2.get("mastra");
|
|
2870
|
-
const agent = mastra.getAgent(agentId);
|
|
2871
|
-
if (!agent) {
|
|
2872
|
-
return c2.json({ error: "Agent not found" }, 404);
|
|
2873
|
-
}
|
|
2874
|
-
let evalSummary = "";
|
|
2875
|
-
try {
|
|
2876
|
-
const testEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
|
|
2877
|
-
const liveEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
|
|
2878
|
-
const evalsMapped = [...testEvals, ...liveEvals].filter(
|
|
2879
|
-
({ instructions: evalInstructions }) => evalInstructions === instructions
|
|
2880
|
-
);
|
|
2881
|
-
evalSummary = evalsMapped.map(
|
|
2882
|
-
({ input, output, result: result2 }) => `
|
|
2883
|
-
Input: ${input}
|
|
2884
|
-
|
|
2885
|
-
Output: ${output}
|
|
2886
|
-
|
|
2887
|
-
Result: ${JSON.stringify(result2)}
|
|
2888
|
-
|
|
2889
|
-
`
|
|
2890
|
-
).join("");
|
|
2891
|
-
} catch (error) {
|
|
2892
|
-
mastra.getLogger().error(`Error fetching evals`, { error });
|
|
2893
|
-
}
|
|
2894
|
-
const ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS = `
|
|
2895
|
-
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.
|
|
2896
|
-
Follow these steps to analyze and enhance the instructions:
|
|
2897
|
-
1. ANALYSIS PHASE
|
|
2898
|
-
- Identify the core purpose and goals
|
|
2899
|
-
- Extract key constraints and requirements
|
|
2900
|
-
- Recognize domain-specific terminology and concepts
|
|
2901
|
-
- Note any implicit assumptions that should be made explicit
|
|
2902
|
-
2. PROMPT STRUCTURE
|
|
2903
|
-
Create a system prompt with these components:
|
|
2904
|
-
a) ROLE DEFINITION
|
|
2905
|
-
- Clear statement of the AI's role and purpose
|
|
2906
|
-
- Key responsibilities and scope
|
|
2907
|
-
- Primary stakeholders and users
|
|
2908
|
-
b) CORE CAPABILITIES
|
|
2909
|
-
- Main functions and abilities
|
|
2910
|
-
- Specific domain knowledge required
|
|
2911
|
-
- Tools and resources available
|
|
2912
|
-
c) BEHAVIORAL GUIDELINES
|
|
2913
|
-
- Communication style and tone
|
|
2914
|
-
- Decision-making framework
|
|
2915
|
-
- Error handling approach
|
|
2916
|
-
- Ethical considerations
|
|
2917
|
-
d) CONSTRAINTS & BOUNDARIES
|
|
2918
|
-
- Explicit limitations
|
|
2919
|
-
- Out-of-scope activities
|
|
2920
|
-
- Security and privacy considerations
|
|
2921
|
-
e) SUCCESS CRITERIA
|
|
2922
|
-
- Quality standards
|
|
2923
|
-
- Expected outcomes
|
|
2924
|
-
- Performance metrics
|
|
2925
|
-
3. QUALITY CHECKS
|
|
2926
|
-
Ensure the prompt is:
|
|
2927
|
-
- Clear and unambiguous
|
|
2928
|
-
- Comprehensive yet concise
|
|
2929
|
-
- Properly scoped
|
|
2930
|
-
- Technically accurate
|
|
2931
|
-
- Ethically sound
|
|
2932
|
-
4. OUTPUT FORMAT
|
|
2933
|
-
Return a structured response with:
|
|
2934
|
-
- Enhanced system prompt
|
|
2935
|
-
- Analysis of key components
|
|
2936
|
-
- Identified goals and constraints
|
|
2937
|
-
- Core domain concepts
|
|
2938
|
-
Remember: A good system prompt should be specific enough to guide behavior but flexible enough to handle edge cases.
|
|
2939
|
-
Focus on creating prompts that are clear, actionable, and aligned with the intended use case.
|
|
2940
|
-
`;
|
|
2941
|
-
const systemPromptAgent = new Agent({
|
|
2942
|
-
name: "system-prompt-enhancer",
|
|
2943
|
-
instructions: ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS,
|
|
2944
|
-
model: agent.llm?.getModel()
|
|
2945
|
-
});
|
|
2946
|
-
const result = await systemPromptAgent.generate(
|
|
2947
|
-
`
|
|
2948
|
-
We need to improve the system prompt.
|
|
2949
|
-
Current: ${instructions}
|
|
2950
|
-
${comment ? `User feedback: ${comment}` : ""}
|
|
2951
|
-
${evalSummary ? `
|
|
2952
|
-
Evaluation Results:
|
|
2953
|
-
${evalSummary}` : ""}
|
|
2954
|
-
`,
|
|
2955
|
-
{
|
|
2956
|
-
output: z.object({
|
|
2957
|
-
new_prompt: z.string(),
|
|
2958
|
-
explanation: z.string()
|
|
2959
|
-
})
|
|
2960
|
-
}
|
|
2961
|
-
);
|
|
2962
|
-
return c2.json(result?.object || {});
|
|
2963
|
-
} catch (error) {
|
|
2964
|
-
return handleError(error, "Error generating system prompt");
|
|
2965
|
-
}
|
|
2966
|
-
}
|
|
2967
|
-
async function getToolsHandler(c2) {
|
|
2968
|
-
try {
|
|
2969
|
-
const tools = c2.get("tools");
|
|
2970
|
-
const result = await getToolsHandler$1({
|
|
2971
|
-
tools
|
|
2972
|
-
});
|
|
2973
|
-
return c2.json(result || {});
|
|
2974
|
-
} catch (error) {
|
|
2975
|
-
return handleError(error, "Error getting tools");
|
|
2976
|
-
}
|
|
2977
|
-
}
|
|
2978
|
-
async function getToolByIdHandler(c2) {
|
|
2979
|
-
try {
|
|
2980
|
-
const tools = c2.get("tools");
|
|
2981
|
-
const toolId = c2.req.param("toolId");
|
|
2982
|
-
const result = await getToolByIdHandler$1({
|
|
2983
|
-
tools,
|
|
2984
|
-
toolId
|
|
2985
|
-
});
|
|
2986
|
-
return c2.json(result);
|
|
2987
|
-
} catch (error) {
|
|
2988
|
-
return handleError(error, "Error getting tool");
|
|
2989
|
-
}
|
|
2990
|
-
}
|
|
2991
|
-
function executeToolHandler(tools) {
|
|
2992
|
-
return async (c2) => {
|
|
2993
|
-
try {
|
|
2994
|
-
const mastra = c2.get("mastra");
|
|
2995
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
2996
|
-
const toolId = decodeURIComponent(c2.req.param("toolId"));
|
|
2997
|
-
const runId = c2.req.query("runId");
|
|
2998
|
-
const { data } = await c2.req.json();
|
|
2999
|
-
const result = await executeToolHandler$1(tools)({
|
|
3000
|
-
mastra,
|
|
3001
|
-
toolId,
|
|
3002
|
-
data,
|
|
3003
|
-
runtimeContext,
|
|
3004
|
-
runId
|
|
3005
|
-
});
|
|
3006
|
-
return c2.json(result);
|
|
3007
|
-
} catch (error) {
|
|
3008
|
-
return handleError(error, "Error executing tool");
|
|
3009
|
-
}
|
|
3010
|
-
};
|
|
3011
|
-
}
|
|
3012
|
-
async function getAgentToolHandler(c2) {
|
|
3013
|
-
try {
|
|
3014
|
-
const mastra = c2.get("mastra");
|
|
3015
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
3016
|
-
const agentId = c2.req.param("agentId");
|
|
3017
|
-
const toolId = c2.req.param("toolId");
|
|
3018
|
-
const result = await getAgentToolHandler$1({
|
|
3019
|
-
mastra,
|
|
3020
|
-
agentId,
|
|
3021
|
-
toolId,
|
|
3022
|
-
runtimeContext
|
|
3023
|
-
});
|
|
3024
|
-
return c2.json(result);
|
|
3025
|
-
} catch (error) {
|
|
3026
|
-
return handleError(error, "Error getting agent tool");
|
|
3027
|
-
}
|
|
3028
|
-
}
|
|
3029
|
-
async function executeAgentToolHandler(c2) {
|
|
3030
|
-
try {
|
|
3031
|
-
const mastra = c2.get("mastra");
|
|
3032
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
3033
|
-
const agentId = c2.req.param("agentId");
|
|
3034
|
-
const toolId = c2.req.param("toolId");
|
|
3035
|
-
const { data } = await c2.req.json();
|
|
3036
|
-
const result = await executeAgentToolHandler$1({
|
|
3037
|
-
mastra,
|
|
3038
|
-
agentId,
|
|
3039
|
-
toolId,
|
|
3040
|
-
data,
|
|
3041
|
-
runtimeContext
|
|
3042
|
-
});
|
|
3043
|
-
return c2.json(result);
|
|
3044
|
-
} catch (error) {
|
|
3045
|
-
return handleError(error, "Error executing tool");
|
|
3046
|
-
}
|
|
3047
|
-
}
|
|
3048
3031
|
async function getSpeakersHandler(c2) {
|
|
3049
3032
|
try {
|
|
3050
3033
|
const mastra = c2.get("mastra");
|
|
@@ -3828,6 +3811,31 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
3828
3811
|
}),
|
|
3829
3812
|
updateAgentModelHandler
|
|
3830
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
|
+
);
|
|
3831
3839
|
router.post(
|
|
3832
3840
|
"/:agentId/models/reorder",
|
|
3833
3841
|
bodyLimit(bodyLimitOptions),
|
|
@@ -7313,9 +7321,11 @@ async function getMemoryStatusHandler(c2) {
|
|
|
7313
7321
|
try {
|
|
7314
7322
|
const mastra = c2.get("mastra");
|
|
7315
7323
|
const agentId = c2.req.query("agentId");
|
|
7324
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7316
7325
|
const result = await getMemoryStatusHandler$1({
|
|
7317
7326
|
mastra,
|
|
7318
|
-
agentId
|
|
7327
|
+
agentId,
|
|
7328
|
+
runtimeContext
|
|
7319
7329
|
});
|
|
7320
7330
|
return c2.json(result);
|
|
7321
7331
|
} catch (error) {
|
|
@@ -7326,9 +7336,11 @@ async function getMemoryConfigHandler(c2) {
|
|
|
7326
7336
|
try {
|
|
7327
7337
|
const mastra = c2.get("mastra");
|
|
7328
7338
|
const agentId = c2.req.query("agentId");
|
|
7339
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7329
7340
|
const result = await getMemoryConfigHandler$1({
|
|
7330
7341
|
mastra,
|
|
7331
|
-
agentId
|
|
7342
|
+
agentId,
|
|
7343
|
+
runtimeContext
|
|
7332
7344
|
});
|
|
7333
7345
|
return c2.json(result);
|
|
7334
7346
|
} catch (error) {
|
|
@@ -7342,12 +7354,14 @@ async function getThreadsHandler(c2) {
|
|
|
7342
7354
|
const resourceId = c2.req.query("resourceid");
|
|
7343
7355
|
const orderBy = c2.req.query("orderBy");
|
|
7344
7356
|
const sortDirection = c2.req.query("sortDirection");
|
|
7357
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7345
7358
|
const result = await getThreadsHandler$1({
|
|
7346
7359
|
mastra,
|
|
7347
7360
|
agentId,
|
|
7348
7361
|
resourceId,
|
|
7349
7362
|
orderBy,
|
|
7350
|
-
sortDirection
|
|
7363
|
+
sortDirection,
|
|
7364
|
+
runtimeContext
|
|
7351
7365
|
});
|
|
7352
7366
|
return c2.json(result);
|
|
7353
7367
|
} catch (error) {
|
|
@@ -7363,6 +7377,7 @@ async function getThreadsPaginatedHandler(c2) {
|
|
|
7363
7377
|
const perPage = parseInt(c2.req.query("perPage") || "100", 10);
|
|
7364
7378
|
const orderBy = c2.req.query("orderBy");
|
|
7365
7379
|
const sortDirection = c2.req.query("sortDirection");
|
|
7380
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7366
7381
|
const result = await getThreadsPaginatedHandler$1({
|
|
7367
7382
|
mastra,
|
|
7368
7383
|
agentId,
|
|
@@ -7370,7 +7385,8 @@ async function getThreadsPaginatedHandler(c2) {
|
|
|
7370
7385
|
page,
|
|
7371
7386
|
perPage,
|
|
7372
7387
|
orderBy,
|
|
7373
|
-
sortDirection
|
|
7388
|
+
sortDirection,
|
|
7389
|
+
runtimeContext
|
|
7374
7390
|
});
|
|
7375
7391
|
return c2.json(result);
|
|
7376
7392
|
} catch (error) {
|
|
@@ -7382,10 +7398,12 @@ async function getThreadByIdHandler(c2) {
|
|
|
7382
7398
|
const mastra = c2.get("mastra");
|
|
7383
7399
|
const agentId = c2.req.query("agentId");
|
|
7384
7400
|
const threadId = c2.req.param("threadId");
|
|
7401
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7385
7402
|
const result = await getThreadByIdHandler$1({
|
|
7386
7403
|
mastra,
|
|
7387
7404
|
agentId,
|
|
7388
|
-
threadId
|
|
7405
|
+
threadId,
|
|
7406
|
+
runtimeContext
|
|
7389
7407
|
});
|
|
7390
7408
|
return c2.json(result);
|
|
7391
7409
|
} catch (error) {
|
|
@@ -7397,10 +7415,12 @@ async function saveMessagesHandler(c2) {
|
|
|
7397
7415
|
const mastra = c2.get("mastra");
|
|
7398
7416
|
const agentId = c2.req.query("agentId");
|
|
7399
7417
|
const body = await c2.req.json();
|
|
7418
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7400
7419
|
const result = await saveMessagesHandler$1({
|
|
7401
7420
|
mastra,
|
|
7402
7421
|
agentId,
|
|
7403
|
-
body
|
|
7422
|
+
body,
|
|
7423
|
+
runtimeContext
|
|
7404
7424
|
});
|
|
7405
7425
|
return c2.json(result);
|
|
7406
7426
|
} catch (error) {
|
|
@@ -7412,10 +7432,12 @@ async function createThreadHandler(c2) {
|
|
|
7412
7432
|
const mastra = c2.get("mastra");
|
|
7413
7433
|
const agentId = c2.req.query("agentId");
|
|
7414
7434
|
const body = await c2.req.json();
|
|
7435
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7415
7436
|
const result = await createThreadHandler$1({
|
|
7416
7437
|
mastra,
|
|
7417
7438
|
agentId,
|
|
7418
|
-
body
|
|
7439
|
+
body,
|
|
7440
|
+
runtimeContext
|
|
7419
7441
|
});
|
|
7420
7442
|
return c2.json(result);
|
|
7421
7443
|
} catch (error) {
|
|
@@ -7428,11 +7450,13 @@ async function updateThreadHandler(c2) {
|
|
|
7428
7450
|
const agentId = c2.req.query("agentId");
|
|
7429
7451
|
const threadId = c2.req.param("threadId");
|
|
7430
7452
|
const body = await c2.req.json();
|
|
7453
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7431
7454
|
const result = await updateThreadHandler$1({
|
|
7432
7455
|
mastra,
|
|
7433
7456
|
agentId,
|
|
7434
7457
|
threadId,
|
|
7435
|
-
body
|
|
7458
|
+
body,
|
|
7459
|
+
runtimeContext
|
|
7436
7460
|
});
|
|
7437
7461
|
return c2.json(result);
|
|
7438
7462
|
} catch (error) {
|
|
@@ -7444,10 +7468,12 @@ async function deleteThreadHandler(c2) {
|
|
|
7444
7468
|
const mastra = c2.get("mastra");
|
|
7445
7469
|
const agentId = c2.req.query("agentId");
|
|
7446
7470
|
const threadId = c2.req.param("threadId");
|
|
7471
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7447
7472
|
const result = await deleteThreadHandler$1({
|
|
7448
7473
|
mastra,
|
|
7449
7474
|
agentId,
|
|
7450
|
-
threadId
|
|
7475
|
+
threadId,
|
|
7476
|
+
runtimeContext
|
|
7451
7477
|
});
|
|
7452
7478
|
return c2.json(result);
|
|
7453
7479
|
} catch (error) {
|
|
@@ -7460,11 +7486,13 @@ async function getMessagesHandler(c2) {
|
|
|
7460
7486
|
const agentId = c2.req.query("agentId");
|
|
7461
7487
|
const threadId = c2.req.param("threadId");
|
|
7462
7488
|
const limit = parseLimit(c2.req.query("limit"));
|
|
7489
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7463
7490
|
const result = await getMessagesHandler$1({
|
|
7464
7491
|
mastra,
|
|
7465
7492
|
agentId,
|
|
7466
7493
|
threadId,
|
|
7467
|
-
limit
|
|
7494
|
+
limit,
|
|
7495
|
+
runtimeContext
|
|
7468
7496
|
});
|
|
7469
7497
|
return c2.json(result);
|
|
7470
7498
|
} catch (error) {
|
|
@@ -7503,11 +7531,13 @@ async function updateWorkingMemoryHandler(c2) {
|
|
|
7503
7531
|
const agentId = c2.req.query("agentId");
|
|
7504
7532
|
const threadId = c2.req.param("threadId");
|
|
7505
7533
|
const body = await c2.req.json();
|
|
7534
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7506
7535
|
const result = await updateWorkingMemoryHandler$1({
|
|
7507
7536
|
mastra,
|
|
7508
7537
|
agentId,
|
|
7509
7538
|
threadId,
|
|
7510
|
-
body
|
|
7539
|
+
body,
|
|
7540
|
+
runtimeContext
|
|
7511
7541
|
});
|
|
7512
7542
|
return c2.json(result);
|
|
7513
7543
|
} catch (error) {
|
|
@@ -7520,11 +7550,13 @@ async function getWorkingMemoryHandler(c2) {
|
|
|
7520
7550
|
const agentId = c2.req.query("agentId");
|
|
7521
7551
|
const threadId = c2.req.param("threadId");
|
|
7522
7552
|
const resourceId = c2.req.query("resourceId");
|
|
7553
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
7523
7554
|
const result = await getWorkingMemoryHandler$1({
|
|
7524
7555
|
mastra,
|
|
7525
7556
|
agentId,
|
|
7526
7557
|
threadId,
|
|
7527
|
-
resourceId
|
|
7558
|
+
resourceId,
|
|
7559
|
+
runtimeContext
|
|
7528
7560
|
});
|
|
7529
7561
|
return c2.json(result);
|
|
7530
7562
|
} catch (error) {
|
|
@@ -11973,19 +12005,6 @@ async function createHonoServer(mastra, options = {
|
|
|
11973
12005
|
}),
|
|
11974
12006
|
rootHandler
|
|
11975
12007
|
);
|
|
11976
|
-
app.get(
|
|
11977
|
-
"/api/model-providers",
|
|
11978
|
-
w({
|
|
11979
|
-
description: "Get all model providers with available keys",
|
|
11980
|
-
tags: ["agents"],
|
|
11981
|
-
responses: {
|
|
11982
|
-
200: {
|
|
11983
|
-
description: "All model providers with available keys"
|
|
11984
|
-
}
|
|
11985
|
-
}
|
|
11986
|
-
}),
|
|
11987
|
-
getModelProvidersHandler
|
|
11988
|
-
);
|
|
11989
12008
|
app.route("/api/agents", agentsRouter(bodyLimitOptions));
|
|
11990
12009
|
if (options.isDev) {
|
|
11991
12010
|
app.route("/api/agents", agentsRouterDev(bodyLimitOptions));
|