@mastra/code-sdk 1.2.0-alpha.8 → 1.2.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 +237 -0
- package/README.md +22 -0
- package/dist/agents/model.d.ts.map +1 -1
- package/dist/agents/model.js +5 -2
- package/dist/agents/model.js.map +1 -1
- package/dist/agents/modes/build.d.ts.map +1 -1
- package/dist/agents/modes/build.js +6 -1
- package/dist/agents/modes/build.js.map +1 -1
- package/dist/agents/modes/explore.d.ts.map +1 -1
- package/dist/agents/modes/explore.js +4 -1
- package/dist/agents/modes/explore.js.map +1 -1
- package/dist/agents/modes/plan.d.ts.map +1 -1
- package/dist/agents/modes/plan.js +8 -3
- package/dist/agents/modes/plan.js.map +1 -1
- package/dist/agents/prompts/index.d.ts.map +1 -1
- package/dist/agents/prompts/index.js +4 -1
- package/dist/agents/prompts/index.js.map +1 -1
- package/dist/agents/prompts/plan.d.ts +1 -1
- package/dist/agents/prompts/plan.d.ts.map +1 -1
- package/dist/agents/prompts/plan.js +2 -2
- package/dist/agents/prompts/plan.js.map +1 -1
- package/dist/agents/prompts/tool-guidance.d.ts +2 -0
- package/dist/agents/prompts/tool-guidance.d.ts.map +1 -1
- package/dist/agents/prompts/tool-guidance.js +3 -2
- package/dist/agents/prompts/tool-guidance.js.map +1 -1
- package/dist/agents/tool-availability.d.ts.map +1 -1
- package/dist/agents/tool-availability.js +15 -6
- package/dist/agents/tool-availability.js.map +1 -1
- package/dist/agents/tools.d.ts +16 -0
- package/dist/agents/tools.d.ts.map +1 -1
- package/dist/agents/tools.js +16 -3
- package/dist/agents/tools.js.map +1 -1
- package/dist/agents/workflow-builder-agent.d.ts +2 -0
- package/dist/agents/workflow-builder-agent.d.ts.map +1 -0
- package/dist/agents/workflow-builder-agent.js +80 -0
- package/dist/agents/workflow-builder-agent.js.map +1 -0
- package/dist/headless/cli.d.ts.map +1 -1
- package/dist/headless/cli.js +3 -0
- package/dist/headless/cli.js.map +1 -1
- package/dist/hooks/manager.d.ts +9 -2
- package/dist/hooks/manager.d.ts.map +1 -1
- package/dist/hooks/manager.js +19 -3
- package/dist/hooks/manager.js.map +1 -1
- package/dist/hooks/types.d.ts +20 -0
- package/dist/hooks/types.d.ts.map +1 -1
- package/dist/hooks/types.js.map +1 -1
- package/dist/index.d.ts +73 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +204 -69
- package/dist/index.js.map +1 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +6 -1
- package/dist/permissions.js.map +1 -1
- package/dist/plugin.d.ts +64 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +3 -1
- package/dist/plugin.js.map +1 -1
- package/dist/plugins/loader.d.ts +7 -3
- package/dist/plugins/loader.d.ts.map +1 -1
- package/dist/plugins/loader.js +53 -1
- package/dist/plugins/loader.js.map +1 -1
- package/dist/plugins/manager.d.ts +36 -2
- package/dist/plugins/manager.d.ts.map +1 -1
- package/dist/plugins/manager.js +74 -2
- package/dist/plugins/manager.js.map +1 -1
- package/dist/plugins/signal-lane.d.ts +58 -0
- package/dist/plugins/signal-lane.d.ts.map +1 -0
- package/dist/plugins/signal-lane.js +166 -0
- package/dist/plugins/signal-lane.js.map +1 -0
- package/dist/plugins/types.d.ts +36 -0
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/tools/workflows/create-workflow.d.ts +7 -0
- package/dist/tools/workflows/create-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/create-workflow.js +81 -0
- package/dist/tools/workflows/create-workflow.js.map +1 -0
- package/dist/tools/workflows/delete-workflow.d.ts +7 -0
- package/dist/tools/workflows/delete-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/delete-workflow.js +21 -0
- package/dist/tools/workflows/delete-workflow.js.map +1 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts +7 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts.map +1 -0
- package/dist/tools/workflows/ephemeral-memory.js +45 -0
- package/dist/tools/workflows/ephemeral-memory.js.map +1 -0
- package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
- package/dist/tools/workflows/extract-json-schema.d.ts.map +1 -0
- package/dist/tools/workflows/extract-json-schema.js +22 -0
- package/dist/tools/workflows/extract-json-schema.js.map +1 -0
- package/dist/tools/workflows/get-workflow.d.ts +11 -0
- package/dist/tools/workflows/get-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/get-workflow.js +34 -0
- package/dist/tools/workflows/get-workflow.js.map +1 -0
- package/dist/tools/workflows/list-available-agents.d.ts +8 -0
- package/dist/tools/workflows/list-available-agents.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-agents.js +32 -0
- package/dist/tools/workflows/list-available-agents.js.map +1 -0
- package/dist/tools/workflows/list-available-tools.d.ts +9 -0
- package/dist/tools/workflows/list-available-tools.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-tools.js +40 -0
- package/dist/tools/workflows/list-available-tools.js.map +1 -0
- package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-available-workflows.d.ts.map +1 -0
- package/dist/tools/workflows/list-available-workflows.js +32 -0
- package/dist/tools/workflows/list-available-workflows.js.map +1 -0
- package/dist/tools/workflows/list-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-workflows.d.ts.map +1 -0
- package/dist/tools/workflows/list-workflows.js +33 -0
- package/dist/tools/workflows/list-workflows.js.map +1 -0
- package/dist/tools/workflows/run-workflow.d.ts +9 -0
- package/dist/tools/workflows/run-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/run-workflow.js +52 -0
- package/dist/tools/workflows/run-workflow.js.map +1 -0
- package/dist/tools/workflows/save-workflow.d.ts +369 -0
- package/dist/tools/workflows/save-workflow.d.ts.map +1 -0
- package/dist/tools/workflows/save-workflow.js +28 -0
- package/dist/tools/workflows/save-workflow.js.map +1 -0
- package/dist/tools/workflows/tool-ids.d.ts +15 -0
- package/dist/tools/workflows/tool-ids.d.ts.map +1 -0
- package/dist/tools/workflows/tool-ids.js +19 -0
- package/dist/tools/workflows/tool-ids.js.map +1 -0
- package/dist/utils/plans.d.ts +9 -6
- package/dist/utils/plans.d.ts.map +1 -1
- package/dist/utils/plans.js +11 -11
- package/dist/utils/plans.js.map +1 -1
- package/dist/workflows/register-primitives.d.ts +52 -0
- package/dist/workflows/register-primitives.d.ts.map +1 -0
- package/dist/workflows/register-primitives.js +39 -0
- package/dist/workflows/register-primitives.js.map +1 -0
- package/dist/workflows/service.d.ts +64 -0
- package/dist/workflows/service.d.ts.map +1 -0
- package/dist/workflows/service.js +53 -0
- package/dist/workflows/service.js.map +1 -0
- package/package.json +15 -15
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getWorkflow } from "../../workflows/service.js";
|
|
2
|
+
import { createTool } from "@mastra/core/tools";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region src/tools/workflows/get-workflow.ts
|
|
5
|
+
const getWorkflowTool = createTool({
|
|
6
|
+
id: "get-workflow",
|
|
7
|
+
description: "Return the full stored definition of a workflow (input/output schemas + the step graph).",
|
|
8
|
+
inputSchema: z.object({ id: z.string().describe("The workflow id.") }),
|
|
9
|
+
outputSchema: z.object({
|
|
10
|
+
id: z.string(),
|
|
11
|
+
description: z.string().optional(),
|
|
12
|
+
status: z.enum(["active", "archived"]),
|
|
13
|
+
inputSchema: z.any().optional(),
|
|
14
|
+
outputSchema: z.any().optional(),
|
|
15
|
+
graph: z.array(z.any()).optional()
|
|
16
|
+
}),
|
|
17
|
+
execute: async ({ id }, { mastra }) => {
|
|
18
|
+
if (!mastra) throw new Error("get-workflow requires a Mastra context.");
|
|
19
|
+
const def = await getWorkflow(mastra, id);
|
|
20
|
+
if (!def) throw new Error(`No workflow with id "${id}".`);
|
|
21
|
+
return {
|
|
22
|
+
id: def.id,
|
|
23
|
+
description: def.description,
|
|
24
|
+
status: def.status,
|
|
25
|
+
inputSchema: def.inputSchema,
|
|
26
|
+
outputSchema: def.outputSchema,
|
|
27
|
+
graph: def.graph
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
//#endregion
|
|
32
|
+
export { getWorkflowTool };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=get-workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-workflow.js","names":[],"sources":["../../../src/tools/workflows/get-workflow.ts"],"sourcesContent":["/**\n * Parent-mode tool: inspect a saved workflow's full definition.\n */\nimport type { Mastra } from '@mastra/core/mastra';\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\nimport { getWorkflow } from '../../workflows/service.js';\n\nexport const getWorkflowTool = createTool({\n id: 'get-workflow',\n description: 'Return the full stored definition of a workflow (input/output schemas + the step graph).',\n inputSchema: z.object({\n id: z.string().describe('The workflow id.'),\n }),\n outputSchema: z.object({\n id: z.string(),\n description: z.string().optional(),\n status: z.enum(['active', 'archived']),\n inputSchema: z.any().optional(),\n outputSchema: z.any().optional(),\n graph: z.array(z.any()).optional(),\n }),\n execute: async ({ id }, { mastra }) => {\n if (!mastra) throw new Error('get-workflow requires a Mastra context.');\n const def = await getWorkflow(mastra as Mastra, id);\n if (!def) throw new Error(`No workflow with id \"${id}\".`);\n return {\n id: def.id,\n description: def.description,\n status: def.status,\n inputSchema: def.inputSchema,\n outputSchema: def.outputSchema,\n graph: def.graph,\n };\n },\n});\n"],"mappings":";;;;AAQA,MAAa,kBAAkB,WAAW;CACxC,IAAI;CACJ,aAAa;CACb,aAAa,EAAE,OAAO,EACpB,IAAI,EAAE,OAAO,CAAC,CAAC,SAAS,kBAAkB,EAC5C,CAAC;CACD,cAAc,EAAE,OAAO;EACrB,IAAI,EAAE,OAAO;EACb,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;EACjC,QAAQ,EAAE,KAAK,CAAC,UAAU,UAAU,CAAC;EACrC,aAAa,EAAE,IAAI,CAAC,CAAC,SAAS;EAC9B,cAAc,EAAE,IAAI,CAAC,CAAC,SAAS;EAC/B,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS;CACnC,CAAC;CACD,SAAS,OAAO,EAAE,MAAM,EAAE,aAAa;EACrC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,yCAAyC;EACtE,MAAM,MAAM,MAAM,YAAY,QAAkB,EAAE;EAClD,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,wBAAwB,GAAG,GAAG;EACxD,OAAO;GACL,IAAI,IAAI;GACR,aAAa,IAAI;GACjB,QAAQ,IAAI;GACZ,aAAa,IAAI;GACjB,cAAc,IAAI;GAClB,OAAO,IAAI;EACb;CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const listAvailableAgentsTool: import("@mastra/core/tools").Tool<Record<string, never>, {
|
|
2
|
+
agents: {
|
|
3
|
+
id: string;
|
|
4
|
+
outputShape: string;
|
|
5
|
+
description?: string | undefined;
|
|
6
|
+
}[];
|
|
7
|
+
}, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "list-available-agents", unknown>;
|
|
8
|
+
//# sourceMappingURL=list-available-agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-available-agents.d.ts","sourceRoot":"","sources":["../../../src/tools/workflows/list-available-agents.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,uBAAuB;;;;;;oIA8BlC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createTool } from "@mastra/core/tools";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/tools/workflows/list-available-agents.ts
|
|
4
|
+
/**
|
|
5
|
+
* Sub-agent tool: list agents the workflow-builder can reference in agent-step
|
|
6
|
+
* entries of a Dynamic Workflow graph. Read-only.
|
|
7
|
+
*/
|
|
8
|
+
/** Self / management tools the workflow-builder shouldn't recursively try to compose. */
|
|
9
|
+
const WORKFLOW_BUILDER_NOISE_AGENTS = /* @__PURE__ */ new Set(["workflow-builder"]);
|
|
10
|
+
const listAvailableAgentsTool = createTool({
|
|
11
|
+
id: "list-available-agents",
|
|
12
|
+
description: "Returns the agents currently registered on the Mastra instance. The agent ids returned here are the only valid values you can put in `{ type: \"agent\", agentId }` graph entries. `outputShape` describes the default text output; an entry-level `outputSchema` replaces that default with structured output.",
|
|
13
|
+
inputSchema: z.object({}),
|
|
14
|
+
outputSchema: z.object({ agents: z.array(z.object({
|
|
15
|
+
id: z.string(),
|
|
16
|
+
description: z.string().optional(),
|
|
17
|
+
outputShape: z.string()
|
|
18
|
+
})) }),
|
|
19
|
+
execute: async (_input, { mastra }) => {
|
|
20
|
+
if (!mastra) throw new Error("list-available-agents requires a Mastra context.");
|
|
21
|
+
const all = mastra.listAgents?.() ?? {};
|
|
22
|
+
return { agents: Object.entries(all).filter(([id]) => !WORKFLOW_BUILDER_NOISE_AGENTS.has(id)).map(([id, a]) => ({
|
|
23
|
+
id,
|
|
24
|
+
description: a?.description,
|
|
25
|
+
outputShape: "Default: { text: string }. An entry-level outputSchema produces that schema instead."
|
|
26
|
+
})) };
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
//#endregion
|
|
30
|
+
export { listAvailableAgentsTool };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=list-available-agents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-available-agents.js","names":[],"sources":["../../../src/tools/workflows/list-available-agents.ts"],"sourcesContent":["/**\n * Sub-agent tool: list agents the workflow-builder can reference in agent-step\n * entries of a Dynamic Workflow graph. Read-only.\n */\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\n/** Self / management tools the workflow-builder shouldn't recursively try to compose. */\nconst WORKFLOW_BUILDER_NOISE_AGENTS = new Set(['workflow-builder']);\n\nexport const listAvailableAgentsTool = createTool({\n id: 'list-available-agents',\n description:\n 'Returns the agents currently registered on the Mastra instance. The agent ids returned here are the only valid values you can put in `{ type: \"agent\", agentId }` graph entries. `outputShape` describes the default text output; an entry-level `outputSchema` replaces that default with structured output.',\n inputSchema: z.object({}),\n outputSchema: z.object({\n agents: z.array(\n z.object({\n id: z.string(),\n description: z.string().optional(),\n // Human-readable string in v1. Could become a JSON Schema now that\n // structuredOutput round-trips through the rehydrator\n // (packages/core/src/workflows/rehydrate-workflow.ts).\n outputShape: z.string(),\n }),\n ),\n }),\n execute: async (_input, { mastra }) => {\n if (!mastra) throw new Error('list-available-agents requires a Mastra context.');\n const all = (mastra as { listAgents?: () => Record<string, unknown> }).listAgents?.() ?? {};\n return {\n agents: Object.entries(all)\n .filter(([id]) => !WORKFLOW_BUILDER_NOISE_AGENTS.has(id))\n .map(([id, a]) => ({\n id,\n description: (a as { description?: string } | undefined)?.description,\n outputShape: 'Default: { text: string }. An entry-level outputSchema produces that schema instead.',\n })),\n };\n },\n});\n"],"mappings":";;;;;;;;AAQA,MAAM,gDAAgC,IAAI,IAAI,CAAC,kBAAkB,CAAC;AAElE,MAAa,0BAA0B,WAAW;CAChD,IAAI;CACJ,aACE;CACF,aAAa,EAAE,OAAO,CAAC,CAAC;CACxB,cAAc,EAAE,OAAO,EACrB,QAAQ,EAAE,MACR,EAAE,OAAO;EACP,IAAI,EAAE,OAAO;EACb,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;EAIjC,aAAa,EAAE,OAAO;CACxB,CAAC,CACH,EACF,CAAC;CACD,SAAS,OAAO,QAAQ,EAAE,aAAa;EACrC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,kDAAkD;EAC/E,MAAM,MAAO,OAA0D,aAAa,KAAK,CAAC;EAC1F,OAAO,EACL,QAAQ,OAAO,QAAQ,GAAG,CAAC,CACxB,QAAQ,CAAC,QAAQ,CAAC,8BAA8B,IAAI,EAAE,CAAC,CAAC,CACxD,KAAK,CAAC,IAAI,QAAQ;GACjB;GACA,aAAc,GAA4C;GAC1D,aAAa;EACf,EAAE,EACN;CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const listAvailableToolsTool: import("@mastra/core/tools").Tool<Record<string, never>, {
|
|
2
|
+
tools: {
|
|
3
|
+
id: string;
|
|
4
|
+
description?: string | undefined;
|
|
5
|
+
inputSchema?: any;
|
|
6
|
+
outputSchema?: any;
|
|
7
|
+
}[];
|
|
8
|
+
}, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "list-available-tools", unknown>;
|
|
9
|
+
//# sourceMappingURL=list-available-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-available-tools.d.ts","sourceRoot":"","sources":["../../../src/tools/workflows/list-available-tools.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,sBAAsB;;;;;;;mIAgCjC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { WORKFLOW_BUILDER_NOISE_TOOL_IDS } from "./tool-ids.js";
|
|
2
|
+
import { extractJsonSchema } from "./extract-json-schema.js";
|
|
3
|
+
import { createTool } from "@mastra/core/tools";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
//#region src/tools/workflows/list-available-tools.ts
|
|
6
|
+
/**
|
|
7
|
+
* Sub-agent tool: list tools the workflow-builder can reference in tool-step
|
|
8
|
+
* entries of a Dynamic Workflow graph. Returns JSON Schema for inputs/outputs
|
|
9
|
+
* so the LLM has ground truth instead of guessing.
|
|
10
|
+
*/
|
|
11
|
+
/** Authoring and management tools are not valid workflow building blocks. */
|
|
12
|
+
const WORKFLOW_BUILDER_NOISE_TOOLS = new Set(WORKFLOW_BUILDER_NOISE_TOOL_IDS);
|
|
13
|
+
const listAvailableToolsTool = createTool({
|
|
14
|
+
id: "list-available-tools",
|
|
15
|
+
description: "Returns the tools currently registered on the Mastra instance. The tool ids returned here are the only valid values you can put in `{ type: \"tool\", toolId }` graph entries. Each row includes `inputSchema` and `outputSchema` as JSON Schema — read them to know what fields the tool accepts and emits; never invent field names.",
|
|
16
|
+
inputSchema: z.object({}),
|
|
17
|
+
outputSchema: z.object({ tools: z.array(z.object({
|
|
18
|
+
id: z.string(),
|
|
19
|
+
description: z.string().optional(),
|
|
20
|
+
inputSchema: z.any().optional(),
|
|
21
|
+
outputSchema: z.any().optional()
|
|
22
|
+
})) }),
|
|
23
|
+
execute: async (_input, { mastra }) => {
|
|
24
|
+
if (!mastra) throw new Error("list-available-tools requires a Mastra context.");
|
|
25
|
+
const all = mastra.listTools?.() ?? {};
|
|
26
|
+
return { tools: Object.entries(all).filter(([id]) => !WORKFLOW_BUILDER_NOISE_TOOLS.has(id)).map(([id, t]) => {
|
|
27
|
+
const tool = t;
|
|
28
|
+
return {
|
|
29
|
+
id,
|
|
30
|
+
description: tool?.description,
|
|
31
|
+
inputSchema: extractJsonSchema(tool?.inputSchema, "input"),
|
|
32
|
+
outputSchema: extractJsonSchema(tool?.outputSchema, "output")
|
|
33
|
+
};
|
|
34
|
+
}) };
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
//#endregion
|
|
38
|
+
export { listAvailableToolsTool };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=list-available-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-available-tools.js","names":[],"sources":["../../../src/tools/workflows/list-available-tools.ts"],"sourcesContent":["/**\n * Sub-agent tool: list tools the workflow-builder can reference in tool-step\n * entries of a Dynamic Workflow graph. Returns JSON Schema for inputs/outputs\n * so the LLM has ground truth instead of guessing.\n */\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\nimport { extractJsonSchema } from './extract-json-schema.js';\nimport { WORKFLOW_BUILDER_NOISE_TOOL_IDS } from './tool-ids.js';\n\n/** Authoring and management tools are not valid workflow building blocks. */\nconst WORKFLOW_BUILDER_NOISE_TOOLS = new Set<string>(WORKFLOW_BUILDER_NOISE_TOOL_IDS);\n\nexport const listAvailableToolsTool = createTool({\n id: 'list-available-tools',\n description:\n 'Returns the tools currently registered on the Mastra instance. The tool ids returned here are the only valid values you can put in `{ type: \"tool\", toolId }` graph entries. Each row includes `inputSchema` and `outputSchema` as JSON Schema — read them to know what fields the tool accepts and emits; never invent field names.',\n inputSchema: z.object({}),\n outputSchema: z.object({\n tools: z.array(\n z.object({\n id: z.string(),\n description: z.string().optional(),\n inputSchema: z.any().optional(),\n outputSchema: z.any().optional(),\n }),\n ),\n }),\n execute: async (_input, { mastra }) => {\n if (!mastra) throw new Error('list-available-tools requires a Mastra context.');\n const all = (mastra as { listTools?: () => Record<string, unknown> }).listTools?.() ?? {};\n return {\n tools: Object.entries(all)\n .filter(([id]) => !WORKFLOW_BUILDER_NOISE_TOOLS.has(id))\n .map(([id, t]) => {\n const tool = t as { description?: string; inputSchema?: unknown; outputSchema?: unknown } | undefined;\n return {\n id,\n description: tool?.description,\n inputSchema: extractJsonSchema(tool?.inputSchema, 'input'),\n outputSchema: extractJsonSchema(tool?.outputSchema, 'output'),\n };\n }),\n };\n },\n});\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,+BAA+B,IAAI,IAAY,+BAA+B;AAEpF,MAAa,yBAAyB,WAAW;CAC/C,IAAI;CACJ,aACE;CACF,aAAa,EAAE,OAAO,CAAC,CAAC;CACxB,cAAc,EAAE,OAAO,EACrB,OAAO,EAAE,MACP,EAAE,OAAO;EACP,IAAI,EAAE,OAAO;EACb,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;EACjC,aAAa,EAAE,IAAI,CAAC,CAAC,SAAS;EAC9B,cAAc,EAAE,IAAI,CAAC,CAAC,SAAS;CACjC,CAAC,CACH,EACF,CAAC;CACD,SAAS,OAAO,QAAQ,EAAE,aAAa;EACrC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,iDAAiD;EAC9E,MAAM,MAAO,OAAyD,YAAY,KAAK,CAAC;EACxF,OAAO,EACL,OAAO,OAAO,QAAQ,GAAG,CAAC,CACvB,QAAQ,CAAC,QAAQ,CAAC,6BAA6B,IAAI,EAAE,CAAC,CAAC,CACvD,KAAK,CAAC,IAAI,OAAO;GAChB,MAAM,OAAO;GACb,OAAO;IACL;IACA,aAAa,MAAM;IACnB,aAAa,kBAAkB,MAAM,aAAa,OAAO;IACzD,cAAc,kBAAkB,MAAM,cAAc,QAAQ;GAC9D;EACF,CAAC,EACL;CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const listAvailableWorkflowsTool: import("@mastra/core/tools").Tool<Record<string, never>, {
|
|
2
|
+
workflows: {
|
|
3
|
+
id: string;
|
|
4
|
+
description?: string | undefined;
|
|
5
|
+
inputSchema?: any;
|
|
6
|
+
outputSchema?: any;
|
|
7
|
+
}[];
|
|
8
|
+
}, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "list-available-workflows", unknown>;
|
|
9
|
+
//# sourceMappingURL=list-available-workflows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-available-workflows.d.ts","sourceRoot":"","sources":["../../../src/tools/workflows/list-available-workflows.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,0BAA0B;;;;;;;uIA8BrC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { extractJsonSchema } from "./extract-json-schema.js";
|
|
2
|
+
import { createTool } from "@mastra/core/tools";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region src/tools/workflows/list-available-workflows.ts
|
|
5
|
+
const listAvailableWorkflowsTool = createTool({
|
|
6
|
+
id: "list-available-workflows",
|
|
7
|
+
description: "Returns the workflows currently registered on the Mastra instance (both code-defined and dynamic). The ids returned here are the only valid values you can put in `{ type: \"workflow\", workflowId }` graph entries. Each row includes `inputSchema` and `outputSchema` as JSON Schema — read them to know what shape the nested workflow expects and produces; never invent field names.",
|
|
8
|
+
inputSchema: z.object({}),
|
|
9
|
+
outputSchema: z.object({ workflows: z.array(z.object({
|
|
10
|
+
id: z.string(),
|
|
11
|
+
description: z.string().optional(),
|
|
12
|
+
inputSchema: z.any().optional(),
|
|
13
|
+
outputSchema: z.any().optional()
|
|
14
|
+
})) }),
|
|
15
|
+
execute: async (_input, { mastra }) => {
|
|
16
|
+
if (!mastra) throw new Error("list-available-workflows requires a Mastra context.");
|
|
17
|
+
const all = mastra.listWorkflows?.() ?? {};
|
|
18
|
+
return { workflows: Object.entries(all).map(([id, wf]) => {
|
|
19
|
+
const w = wf;
|
|
20
|
+
return {
|
|
21
|
+
id,
|
|
22
|
+
description: w?.description,
|
|
23
|
+
inputSchema: extractJsonSchema(w?.inputSchema, "input"),
|
|
24
|
+
outputSchema: extractJsonSchema(w?.outputSchema, "output")
|
|
25
|
+
};
|
|
26
|
+
}) };
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
//#endregion
|
|
30
|
+
export { listAvailableWorkflowsTool };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=list-available-workflows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-available-workflows.js","names":[],"sources":["../../../src/tools/workflows/list-available-workflows.ts"],"sourcesContent":["/**\n * Sub-agent tool: list workflows the workflow-builder can reference in\n * `{ type: \"workflow\", workflowId }` graph entries. Includes both code-defined\n * and Dynamic Workflows, so the builder can nest one workflow inside another.\n * The pre-flight validator rejects self-references and dependency cycles.\n */\nimport type { Mastra } from '@mastra/core/mastra';\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\nimport { extractJsonSchema } from './extract-json-schema.js';\n\nexport const listAvailableWorkflowsTool = createTool({\n id: 'list-available-workflows',\n description:\n 'Returns the workflows currently registered on the Mastra instance (both code-defined and dynamic). The ids returned here are the only valid values you can put in `{ type: \"workflow\", workflowId }` graph entries. Each row includes `inputSchema` and `outputSchema` as JSON Schema — read them to know what shape the nested workflow expects and produces; never invent field names.',\n inputSchema: z.object({}),\n outputSchema: z.object({\n workflows: z.array(\n z.object({\n id: z.string(),\n description: z.string().optional(),\n inputSchema: z.any().optional(),\n outputSchema: z.any().optional(),\n }),\n ),\n }),\n execute: async (_input, { mastra }) => {\n if (!mastra) throw new Error('list-available-workflows requires a Mastra context.');\n const all = (mastra as Mastra).listWorkflows?.() ?? {};\n return {\n workflows: Object.entries(all).map(([id, wf]) => {\n const w = wf as { description?: string; inputSchema?: unknown; outputSchema?: unknown } | undefined;\n return {\n id,\n description: w?.description,\n inputSchema: extractJsonSchema(w?.inputSchema, 'input'),\n outputSchema: extractJsonSchema(w?.outputSchema, 'output'),\n };\n }),\n };\n },\n});\n"],"mappings":";;;;AAWA,MAAa,6BAA6B,WAAW;CACnD,IAAI;CACJ,aACE;CACF,aAAa,EAAE,OAAO,CAAC,CAAC;CACxB,cAAc,EAAE,OAAO,EACrB,WAAW,EAAE,MACX,EAAE,OAAO;EACP,IAAI,EAAE,OAAO;EACb,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;EACjC,aAAa,EAAE,IAAI,CAAC,CAAC,SAAS;EAC9B,cAAc,EAAE,IAAI,CAAC,CAAC,SAAS;CACjC,CAAC,CACH,EACF,CAAC;CACD,SAAS,OAAO,QAAQ,EAAE,aAAa;EACrC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,qDAAqD;EAClF,MAAM,MAAO,OAAkB,gBAAgB,KAAK,CAAC;EACrD,OAAO,EACL,WAAW,OAAO,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,QAAQ;GAC/C,MAAM,IAAI;GACV,OAAO;IACL;IACA,aAAa,GAAG;IAChB,aAAa,kBAAkB,GAAG,aAAa,OAAO;IACtD,cAAc,kBAAkB,GAAG,cAAc,QAAQ;GAC3D;EACF,CAAC,EACH;CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const listWorkflowsTool: import("@mastra/core/tools").Tool<Record<string, never>, {
|
|
2
|
+
workflows: {
|
|
3
|
+
id: string;
|
|
4
|
+
status: "active" | "archived";
|
|
5
|
+
description?: string | undefined;
|
|
6
|
+
}[];
|
|
7
|
+
total: number;
|
|
8
|
+
}, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "list-workflows", unknown>;
|
|
9
|
+
//# sourceMappingURL=list-workflows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-workflows.d.ts","sourceRoot":"","sources":["../../../src/tools/workflows/list-workflows.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,iBAAiB;;;;;;;6HAsB5B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { listWorkflows } from "../../workflows/service.js";
|
|
2
|
+
import { createTool } from "@mastra/core/tools";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region src/tools/workflows/list-workflows.ts
|
|
5
|
+
const listWorkflowsTool = createTool({
|
|
6
|
+
id: "list-workflows",
|
|
7
|
+
description: "List active Dynamic Workflows persisted to storage. Returns id + description + status for each.",
|
|
8
|
+
inputSchema: z.object({}),
|
|
9
|
+
outputSchema: z.object({
|
|
10
|
+
workflows: z.array(z.object({
|
|
11
|
+
id: z.string(),
|
|
12
|
+
description: z.string().optional(),
|
|
13
|
+
status: z.enum(["active", "archived"])
|
|
14
|
+
})),
|
|
15
|
+
total: z.number()
|
|
16
|
+
}),
|
|
17
|
+
execute: async (_input, { mastra }) => {
|
|
18
|
+
if (!mastra) throw new Error("list-workflows requires a Mastra context.");
|
|
19
|
+
const { workflows, total } = await listWorkflows(mastra);
|
|
20
|
+
return {
|
|
21
|
+
workflows: workflows.map((wf) => ({
|
|
22
|
+
id: wf.id,
|
|
23
|
+
description: wf.description,
|
|
24
|
+
status: wf.status
|
|
25
|
+
})),
|
|
26
|
+
total
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
//#endregion
|
|
31
|
+
export { listWorkflowsTool };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=list-workflows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-workflows.js","names":[],"sources":["../../../src/tools/workflows/list-workflows.ts"],"sourcesContent":["/**\n * Parent-mode tool: list saved workflows. Read-only, available in all modes.\n */\nimport type { Mastra } from '@mastra/core/mastra';\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\nimport { listWorkflows } from '../../workflows/service.js';\n\nexport const listWorkflowsTool = createTool({\n id: 'list-workflows',\n description: 'List active Dynamic Workflows persisted to storage. Returns id + description + status for each.',\n inputSchema: z.object({}),\n outputSchema: z.object({\n workflows: z.array(\n z.object({\n id: z.string(),\n description: z.string().optional(),\n status: z.enum(['active', 'archived']),\n }),\n ),\n total: z.number(),\n }),\n execute: async (_input, { mastra }) => {\n if (!mastra) throw new Error('list-workflows requires a Mastra context.');\n const { workflows, total } = await listWorkflows(mastra as Mastra);\n return {\n workflows: workflows.map(wf => ({ id: wf.id, description: wf.description, status: wf.status })),\n total,\n };\n },\n});\n"],"mappings":";;;;AAQA,MAAa,oBAAoB,WAAW;CAC1C,IAAI;CACJ,aAAa;CACb,aAAa,EAAE,OAAO,CAAC,CAAC;CACxB,cAAc,EAAE,OAAO;EACrB,WAAW,EAAE,MACX,EAAE,OAAO;GACP,IAAI,EAAE,OAAO;GACb,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;GACjC,QAAQ,EAAE,KAAK,CAAC,UAAU,UAAU,CAAC;EACvC,CAAC,CACH;EACA,OAAO,EAAE,OAAO;CAClB,CAAC;CACD,SAAS,OAAO,QAAQ,EAAE,aAAa;EACrC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,2CAA2C;EACxE,MAAM,EAAE,WAAW,UAAU,MAAM,cAAc,MAAgB;EACjE,OAAO;GACL,WAAW,UAAU,KAAI,QAAO;IAAE,IAAI,GAAG;IAAI,aAAa,GAAG;IAAa,QAAQ,GAAG;GAAO,EAAE;GAC9F;EACF;CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const runWorkflowTool: import("@mastra/core/tools").Tool<{
|
|
2
|
+
workflowId: string;
|
|
3
|
+
inputData: any;
|
|
4
|
+
}, {
|
|
5
|
+
status: string;
|
|
6
|
+
result?: any;
|
|
7
|
+
error?: any;
|
|
8
|
+
}, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "run-workflow", unknown>;
|
|
9
|
+
//# sourceMappingURL=run-workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-workflow.d.ts","sourceRoot":"","sources":["../../../src/tools/workflows/run-workflow.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,eAAe;;;;;;;2HAkD1B,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { runWorkflow } from "../../workflows/service.js";
|
|
2
|
+
import { withEphemeralMemory } from "./ephemeral-memory.js";
|
|
3
|
+
import { createTool } from "@mastra/core/tools";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
//#region src/tools/workflows/run-workflow.ts
|
|
6
|
+
const runWorkflowTool = createTool({
|
|
7
|
+
id: "run-workflow",
|
|
8
|
+
description: "Run a saved workflow by id with the provided input data. Returns the run result inline. Use when the user asks you to \"run X\", \"execute X\", or asks for the outcome of a saved workflow.",
|
|
9
|
+
inputSchema: z.object({
|
|
10
|
+
workflowId: z.string().describe("The id of the saved workflow to run."),
|
|
11
|
+
inputData: z.any().describe("The input object the workflow consumes. Must match the workflow inputSchema.")
|
|
12
|
+
}),
|
|
13
|
+
outputSchema: z.object({
|
|
14
|
+
status: z.string(),
|
|
15
|
+
result: z.any().optional(),
|
|
16
|
+
error: z.any().optional()
|
|
17
|
+
}),
|
|
18
|
+
execute: async ({ workflowId, inputData }, { mastra, requestContext }) => {
|
|
19
|
+
if (!mastra) throw new Error("run-workflow requires a Mastra context.");
|
|
20
|
+
return withEphemeralMemory(requestContext, async (ephemeralRequestContext) => {
|
|
21
|
+
const result = await runWorkflow(mastra, workflowId, inputData, ephemeralRequestContext);
|
|
22
|
+
if (result.status === "tripwire" && result.tripwire) return {
|
|
23
|
+
status: result.status,
|
|
24
|
+
error: `Tripwire: ${result.tripwire.reason ?? "unknown"} (processor: ${result.tripwire.processorId ?? "unknown"})`
|
|
25
|
+
};
|
|
26
|
+
let errorText;
|
|
27
|
+
if (result.error instanceof Error) {
|
|
28
|
+
errorText = `${result.error.name}: ${result.error.message}`;
|
|
29
|
+
const cause = result.error.cause;
|
|
30
|
+
if (cause) try {
|
|
31
|
+
errorText += ` | cause: ${JSON.stringify(cause, Object.getOwnPropertyNames(cause))}`;
|
|
32
|
+
} catch {
|
|
33
|
+
errorText += ` | cause: ${String(cause)}`;
|
|
34
|
+
}
|
|
35
|
+
if (result.error.stack) errorText += `\nstack: ${result.error.stack}`;
|
|
36
|
+
} else if (result.error) try {
|
|
37
|
+
errorText = JSON.stringify(result.error, Object.getOwnPropertyNames(result.error));
|
|
38
|
+
} catch {
|
|
39
|
+
errorText = String(result.error);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
status: result.status,
|
|
43
|
+
result: result.result,
|
|
44
|
+
error: errorText
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
//#endregion
|
|
50
|
+
export { runWorkflowTool };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=run-workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-workflow.js","names":[],"sources":["../../../src/tools/workflows/run-workflow.ts"],"sourcesContent":["/**\n * Parent-mode tool: run a saved workflow with input data. Returns the run\n * result inline so the parent agent can summarise / chain it.\n */\nimport type { Mastra } from '@mastra/core/mastra';\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\nimport { runWorkflow } from '../../workflows/service.js';\nimport { withEphemeralMemory } from './ephemeral-memory.js';\n\nexport const runWorkflowTool = createTool({\n id: 'run-workflow',\n description:\n 'Run a saved workflow by id with the provided input data. Returns the run result inline. Use when the user asks you to \"run X\", \"execute X\", or asks for the outcome of a saved workflow.',\n inputSchema: z.object({\n workflowId: z.string().describe('The id of the saved workflow to run.'),\n inputData: z.any().describe('The input object the workflow consumes. Must match the workflow inputSchema.'),\n }),\n outputSchema: z.object({\n status: z.string(),\n result: z.any().optional(),\n error: z.any().optional(),\n }),\n execute: async ({ workflowId, inputData }, { mastra, requestContext }) => {\n if (!mastra) throw new Error('run-workflow requires a Mastra context.');\n // Forward the caller's requestContext so agent steps can resolve dynamic\n // model/tool bindings from session state, and swap the caller's chat\n // memory scope for a fresh isolated one for the duration of the run so\n // the workflow's agent step doesn't write into (or read from) the parent\n // chat thread. See ephemeral-memory.ts.\n return withEphemeralMemory(requestContext, async ephemeralRequestContext => {\n const result = await runWorkflow(mastra as Mastra, workflowId, inputData, ephemeralRequestContext);\n if (result.status === 'tripwire' && result.tripwire) {\n return {\n status: result.status,\n error: `Tripwire: ${result.tripwire.reason ?? 'unknown'} (processor: ${result.tripwire.processorId ?? 'unknown'})`,\n };\n }\n let errorText: string | undefined;\n if (result.error instanceof Error) {\n errorText = `${result.error.name}: ${result.error.message}`;\n const cause = (result.error as { cause?: unknown }).cause;\n if (cause) {\n try {\n errorText += ` | cause: ${JSON.stringify(cause, Object.getOwnPropertyNames(cause))}`;\n } catch {\n errorText += ` | cause: ${String(cause)}`;\n }\n }\n if (result.error.stack) errorText += `\\nstack: ${result.error.stack}`;\n } else if (result.error) {\n try {\n errorText = JSON.stringify(result.error, Object.getOwnPropertyNames(result.error));\n } catch {\n errorText = String(result.error);\n }\n }\n return { status: result.status, result: result.result, error: errorText };\n });\n },\n});\n"],"mappings":";;;;;AAUA,MAAa,kBAAkB,WAAW;CACxC,IAAI;CACJ,aACE;CACF,aAAa,EAAE,OAAO;EACpB,YAAY,EAAE,OAAO,CAAC,CAAC,SAAS,sCAAsC;EACtE,WAAW,EAAE,IAAI,CAAC,CAAC,SAAS,8EAA8E;CAC5G,CAAC;CACD,cAAc,EAAE,OAAO;EACrB,QAAQ,EAAE,OAAO;EACjB,QAAQ,EAAE,IAAI,CAAC,CAAC,SAAS;EACzB,OAAO,EAAE,IAAI,CAAC,CAAC,SAAS;CAC1B,CAAC;CACD,SAAS,OAAO,EAAE,YAAY,aAAa,EAAE,QAAQ,qBAAqB;EACxE,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,yCAAyC;EAMtE,OAAO,oBAAoB,gBAAgB,OAAM,4BAA2B;GAC1E,MAAM,SAAS,MAAM,YAAY,QAAkB,YAAY,WAAW,uBAAuB;GACjG,IAAI,OAAO,WAAW,cAAc,OAAO,UACzC,OAAO;IACL,QAAQ,OAAO;IACf,OAAO,aAAa,OAAO,SAAS,UAAU,UAAU,eAAe,OAAO,SAAS,eAAe,UAAU;GAClH;GAEF,IAAI;GACJ,IAAI,OAAO,iBAAiB,OAAO;IACjC,YAAY,GAAG,OAAO,MAAM,KAAK,IAAI,OAAO,MAAM;IAClD,MAAM,QAAS,OAAO,MAA8B;IACpD,IAAI,OACF,IAAI;KACF,aAAa,aAAa,KAAK,UAAU,OAAO,OAAO,oBAAoB,KAAK,CAAC;IACnF,QAAQ;KACN,aAAa,aAAa,OAAO,KAAK;IACxC;IAEF,IAAI,OAAO,MAAM,OAAO,aAAa,YAAY,OAAO,MAAM;GAChE,OAAO,IAAI,OAAO,OAChB,IAAI;IACF,YAAY,KAAK,UAAU,OAAO,OAAO,OAAO,oBAAoB,OAAO,KAAK,CAAC;GACnF,QAAQ;IACN,YAAY,OAAO,OAAO,KAAK;GACjC;GAEF,OAAO;IAAE,QAAQ,OAAO;IAAQ,QAAQ,OAAO;IAAQ,OAAO;GAAU;EAC1E,CAAC;CACH;AACF,CAAC"}
|