@mastra/code-sdk 1.2.0-alpha.17 → 1.2.0-alpha.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +22 -0
  3. package/dist/agents/modes/build.d.ts.map +1 -1
  4. package/dist/agents/modes/build.js +6 -1
  5. package/dist/agents/modes/build.js.map +1 -1
  6. package/dist/agents/modes/explore.d.ts.map +1 -1
  7. package/dist/agents/modes/explore.js +4 -1
  8. package/dist/agents/modes/explore.js.map +1 -1
  9. package/dist/agents/modes/plan.d.ts.map +1 -1
  10. package/dist/agents/modes/plan.js +6 -1
  11. package/dist/agents/modes/plan.js.map +1 -1
  12. package/dist/agents/tool-availability.d.ts.map +1 -1
  13. package/dist/agents/tool-availability.js +6 -2
  14. package/dist/agents/tool-availability.js.map +1 -1
  15. package/dist/agents/tools.d.ts +16 -0
  16. package/dist/agents/tools.d.ts.map +1 -1
  17. package/dist/agents/tools.js +15 -2
  18. package/dist/agents/tools.js.map +1 -1
  19. package/dist/agents/workflow-builder-agent.d.ts +2 -0
  20. package/dist/agents/workflow-builder-agent.d.ts.map +1 -0
  21. package/dist/agents/workflow-builder-agent.js +80 -0
  22. package/dist/agents/workflow-builder-agent.js.map +1 -0
  23. package/dist/index.d.ts +5 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +26 -7
  26. package/dist/index.js.map +1 -1
  27. package/dist/permissions.d.ts.map +1 -1
  28. package/dist/permissions.js +6 -1
  29. package/dist/permissions.js.map +1 -1
  30. package/dist/tools/workflows/create-workflow.d.ts +7 -0
  31. package/dist/tools/workflows/create-workflow.d.ts.map +1 -0
  32. package/dist/tools/workflows/create-workflow.js +81 -0
  33. package/dist/tools/workflows/create-workflow.js.map +1 -0
  34. package/dist/tools/workflows/delete-workflow.d.ts +7 -0
  35. package/dist/tools/workflows/delete-workflow.d.ts.map +1 -0
  36. package/dist/tools/workflows/delete-workflow.js +21 -0
  37. package/dist/tools/workflows/delete-workflow.js.map +1 -0
  38. package/dist/tools/workflows/ephemeral-memory.d.ts +7 -0
  39. package/dist/tools/workflows/ephemeral-memory.d.ts.map +1 -0
  40. package/dist/tools/workflows/ephemeral-memory.js +45 -0
  41. package/dist/tools/workflows/ephemeral-memory.js.map +1 -0
  42. package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
  43. package/dist/tools/workflows/extract-json-schema.d.ts.map +1 -0
  44. package/dist/tools/workflows/extract-json-schema.js +22 -0
  45. package/dist/tools/workflows/extract-json-schema.js.map +1 -0
  46. package/dist/tools/workflows/get-workflow.d.ts +11 -0
  47. package/dist/tools/workflows/get-workflow.d.ts.map +1 -0
  48. package/dist/tools/workflows/get-workflow.js +34 -0
  49. package/dist/tools/workflows/get-workflow.js.map +1 -0
  50. package/dist/tools/workflows/list-available-agents.d.ts +8 -0
  51. package/dist/tools/workflows/list-available-agents.d.ts.map +1 -0
  52. package/dist/tools/workflows/list-available-agents.js +32 -0
  53. package/dist/tools/workflows/list-available-agents.js.map +1 -0
  54. package/dist/tools/workflows/list-available-tools.d.ts +9 -0
  55. package/dist/tools/workflows/list-available-tools.d.ts.map +1 -0
  56. package/dist/tools/workflows/list-available-tools.js +40 -0
  57. package/dist/tools/workflows/list-available-tools.js.map +1 -0
  58. package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
  59. package/dist/tools/workflows/list-available-workflows.d.ts.map +1 -0
  60. package/dist/tools/workflows/list-available-workflows.js +32 -0
  61. package/dist/tools/workflows/list-available-workflows.js.map +1 -0
  62. package/dist/tools/workflows/list-workflows.d.ts +9 -0
  63. package/dist/tools/workflows/list-workflows.d.ts.map +1 -0
  64. package/dist/tools/workflows/list-workflows.js +33 -0
  65. package/dist/tools/workflows/list-workflows.js.map +1 -0
  66. package/dist/tools/workflows/run-workflow.d.ts +9 -0
  67. package/dist/tools/workflows/run-workflow.d.ts.map +1 -0
  68. package/dist/tools/workflows/run-workflow.js +52 -0
  69. package/dist/tools/workflows/run-workflow.js.map +1 -0
  70. package/dist/tools/workflows/save-workflow.d.ts +369 -0
  71. package/dist/tools/workflows/save-workflow.d.ts.map +1 -0
  72. package/dist/tools/workflows/save-workflow.js +28 -0
  73. package/dist/tools/workflows/save-workflow.js.map +1 -0
  74. package/dist/tools/workflows/tool-ids.d.ts +15 -0
  75. package/dist/tools/workflows/tool-ids.d.ts.map +1 -0
  76. package/dist/tools/workflows/tool-ids.js +19 -0
  77. package/dist/tools/workflows/tool-ids.js.map +1 -0
  78. package/dist/workflows/register-primitives.d.ts +52 -0
  79. package/dist/workflows/register-primitives.d.ts.map +1 -0
  80. package/dist/workflows/register-primitives.js +39 -0
  81. package/dist/workflows/register-primitives.js.map +1 -0
  82. package/dist/workflows/service.d.ts +64 -0
  83. package/dist/workflows/service.d.ts.map +1 -0
  84. package/dist/workflows/service.js +53 -0
  85. package/dist/workflows/service.js.map +1 -0
  86. package/package.json +8 -8
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-workflow.js","names":[],"sources":["../../../src/tools/workflows/create-workflow.ts"],"sourcesContent":["/**\n * Parent-mode tool: delegate workflow construction to the workflow-builder\n * sub-agent. The parent code-agent calls this with the user's request verbatim;\n * the sub-agent runs its own discovery → compose → save loop and returns a\n * one-paragraph summary the parent relays to the user.\n *\n * The split exists so the parent code-agent's system prompt stays focused on\n * coding and isn't polluted with the long workflow-authoring contract.\n */\nimport type { Mastra } from '@mastra/core/mastra';\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\n/**\n * Coerce an unknown thrown value into a readable string. Sub-agent tool errors\n * come through the stream in various shapes (Error, plain object, string) —\n * normalise so the parent tool's error message is always useful.\n */\nfunction stringifyError(err: unknown): string {\n if (err instanceof Error) return err.message;\n if (typeof err === 'string') return err;\n try {\n return JSON.stringify(err) ?? String(err);\n } catch {\n return String(err);\n }\n}\n\nexport const createWorkflowTool = createTool({\n id: 'create-workflow',\n description:\n 'Build and save a Dynamic Workflow on behalf of the user. Pass the user request verbatim — a focused sub-agent handles discovery, construction, and persistence, then returns a summary. Use this whenever the user asks to \"build a workflow\", \"compose a workflow\", or similar. Do NOT try to construct workflows inline yourself.',\n inputSchema: z.object({\n request: z.string().describe('The user request, verbatim — do not paraphrase or summarise.'),\n }),\n outputSchema: z.object({\n summary: z.string().describe('Natural-language summary of what the sub-agent built. Relay this to the user.'),\n workflowId: z.string().optional().describe('The id of the saved workflow, if save-workflow returned ok.'),\n }),\n execute: async ({ request }, { mastra, requestContext }) => {\n if (!mastra) throw new Error('create-workflow requires a Mastra context.');\n const builder = (mastra as Mastra).getAgent('workflow-builder' as never);\n if (!builder) {\n throw new Error(\n 'The \"workflow-builder\" sub-agent is not registered on this Mastra instance. Cannot build workflows.',\n );\n }\n\n // Propagate the parent code-agent's requestContext so the sub-agent's\n // dynamic model resolver (getDynamicModel) sees controller.session.modelId.\n // Without this the sub-agent throws \"No model selected\" even when the user\n // has /models configured for the main code-agent.\n const stream = await builder.stream(request, { requestContext });\n\n // Sub-agent runs its own tool loop. We MUST verify save-workflow actually\n // ran and returned ok — otherwise the sub-agent's natural-language \"summary\"\n // is worthless (it will happily claim success without ever calling the tool,\n // or claim success after save-workflow threw). Surface every error the\n // sub-agent's tools produce so the caller sees them instead of a fake ok.\n let workflowId: string | undefined;\n let saveAttempted = false;\n let saveSucceeded = false;\n const toolErrors: Array<{ toolName: string; error: string }> = [];\n\n const reader = stream.fullStream.getReader();\n let streamCompleted = false;\n try {\n while (true) {\n const { value, done } = await reader.read();\n if (done) {\n streamCompleted = true;\n break;\n }\n if (value?.type === 'tool-call' && value.payload?.toolName === 'save-workflow') {\n saveAttempted = true;\n }\n if (value?.type === 'tool-result' && value.payload?.toolName === 'save-workflow') {\n const result = value.payload.result as { id?: string; ok?: boolean } | undefined;\n if (result && result.ok === true && typeof result.id === 'string') {\n workflowId = result.id;\n saveSucceeded = true;\n }\n }\n if (value?.type === 'tool-error' && typeof value.payload?.toolName === 'string') {\n toolErrors.push({ toolName: value.payload.toolName, error: stringifyError(value.payload.error) });\n }\n }\n } finally {\n if (!streamCompleted) {\n await reader.cancel().catch(() => undefined);\n }\n reader.releaseLock();\n }\n\n const summary = await stream.text;\n\n // If save-workflow errored, surface that error explicitly — do NOT return\n // the sub-agent's summary as if things were fine.\n const saveErrors = toolErrors.filter(e => e.toolName === 'save-workflow');\n if (saveErrors.length > 0 && !saveSucceeded) {\n throw new Error(\n `create-workflow failed: save-workflow threw ${saveErrors.length} error(s):\\n- ${saveErrors\n .map(e => e.error)\n .join('\\n- ')}\\n\\nSub-agent summary (unreliable, save did not succeed):\\n${summary}`,\n );\n }\n\n // If save-workflow was never called, the sub-agent gave up (or hallucinated\n // success). Fail loudly so the caller doesn't think a workflow exists.\n if (!saveAttempted) {\n const otherErrors = toolErrors.length\n ? `\\n\\nOther sub-agent tool errors:\\n- ${toolErrors.map(e => `${e.toolName}: ${e.error}`).join('\\n- ')}`\n : '';\n throw new Error(\n `create-workflow failed: the workflow-builder sub-agent never called save-workflow. No workflow was persisted.${otherErrors}\\n\\nSub-agent summary:\\n${summary}`,\n );\n }\n\n // Save was attempted but never returned ok (no tool-result with { ok: true, id }).\n if (!saveSucceeded) {\n const otherErrors = toolErrors.length\n ? `\\n\\nSub-agent tool errors:\\n- ${toolErrors.map(e => `${e.toolName}: ${e.error}`).join('\\n- ')}`\n : '';\n throw new Error(\n `create-workflow failed: save-workflow was called but did not return { ok: true }.${otherErrors}\\n\\nSub-agent summary:\\n${summary}`,\n );\n }\n\n return { summary, workflowId };\n },\n});\n"],"mappings":";;;;;;;;AAkBA,SAAS,eAAe,KAAsB;CAC5C,IAAI,eAAe,OAAO,OAAO,IAAI;CACrC,IAAI,OAAO,QAAQ,UAAU,OAAO;CACpC,IAAI;EACF,OAAO,KAAK,UAAU,GAAG,KAAK,OAAO,GAAG;CAC1C,QAAQ;EACN,OAAO,OAAO,GAAG;CACnB;AACF;AAEA,MAAa,qBAAqB,WAAW;CAC3C,IAAI;CACJ,aACE;CACF,aAAa,EAAE,OAAO,EACpB,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,8DAA8D,EAC7F,CAAC;CACD,cAAc,EAAE,OAAO;EACrB,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,+EAA+E;EAC5G,YAAY,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,6DAA6D;CAC1G,CAAC;CACD,SAAS,OAAO,EAAE,WAAW,EAAE,QAAQ,qBAAqB;EAC1D,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,4CAA4C;EACzE,MAAM,UAAW,OAAkB,SAAS,kBAA2B;EACvE,IAAI,CAAC,SACH,MAAM,IAAI,MACR,uGACF;EAOF,MAAM,SAAS,MAAM,QAAQ,OAAO,SAAS,EAAE,eAAe,CAAC;EAO/D,IAAI;EACJ,IAAI,gBAAgB;EACpB,IAAI,gBAAgB;EACpB,MAAM,aAAyD,CAAC;EAEhE,MAAM,SAAS,OAAO,WAAW,UAAU;EAC3C,IAAI,kBAAkB;EACtB,IAAI;GACF,OAAO,MAAM;IACX,MAAM,EAAE,OAAO,SAAS,MAAM,OAAO,KAAK;IAC1C,IAAI,MAAM;KACR,kBAAkB;KAClB;IACF;IACA,IAAI,OAAO,SAAS,eAAe,MAAM,SAAS,aAAa,iBAC7D,gBAAgB;IAElB,IAAI,OAAO,SAAS,iBAAiB,MAAM,SAAS,aAAa,iBAAiB;KAChF,MAAM,SAAS,MAAM,QAAQ;KAC7B,IAAI,UAAU,OAAO,OAAO,QAAQ,OAAO,OAAO,OAAO,UAAU;MACjE,aAAa,OAAO;MACpB,gBAAgB;KAClB;IACF;IACA,IAAI,OAAO,SAAS,gBAAgB,OAAO,MAAM,SAAS,aAAa,UACrE,WAAW,KAAK;KAAE,UAAU,MAAM,QAAQ;KAAU,OAAO,eAAe,MAAM,QAAQ,KAAK;IAAE,CAAC;GAEpG;EACF,UAAU;GACR,IAAI,CAAC,iBACH,MAAM,OAAO,OAAO,CAAC,CAAC,YAAY,KAAA,CAAS;GAE7C,OAAO,YAAY;EACrB;EAEA,MAAM,UAAU,MAAM,OAAO;EAI7B,MAAM,aAAa,WAAW,QAAO,MAAK,EAAE,aAAa,eAAe;EACxE,IAAI,WAAW,SAAS,KAAK,CAAC,eAC5B,MAAM,IAAI,MACR,+CAA+C,WAAW,OAAO,gBAAgB,WAC9E,KAAI,MAAK,EAAE,KAAK,CAAC,CACjB,KAAK,MAAM,EAAE,6DAA6D,SAC/E;EAKF,IAAI,CAAC,eAAe;GAClB,MAAM,cAAc,WAAW,SAC3B,uCAAuC,WAAW,KAAI,MAAK,GAAG,EAAE,SAAS,IAAI,EAAE,OAAO,CAAC,CAAC,KAAK,MAAM,MACnG;GACJ,MAAM,IAAI,MACR,gHAAgH,YAAY,0BAA0B,SACxJ;EACF;EAGA,IAAI,CAAC,eAAe;GAClB,MAAM,cAAc,WAAW,SAC3B,iCAAiC,WAAW,KAAI,MAAK,GAAG,EAAE,SAAS,IAAI,EAAE,OAAO,CAAC,CAAC,KAAK,MAAM,MAC7F;GACJ,MAAM,IAAI,MACR,oFAAoF,YAAY,0BAA0B,SAC5H;EACF;EAEA,OAAO;GAAE;GAAS;EAAW;CAC/B;AACF,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const deleteWorkflowTool: import("@mastra/core/tools").Tool<{
2
+ id: string;
3
+ }, {
4
+ ok: true;
5
+ id: string;
6
+ }, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "delete-workflow", unknown>;
7
+ //# sourceMappingURL=delete-workflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete-workflow.d.ts","sourceRoot":"","sources":["../../../src/tools/workflows/delete-workflow.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,kBAAkB;;;;;8HAe7B,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { deleteWorkflow } from "../../workflows/service.js";
2
+ import { createTool } from "@mastra/core/tools";
3
+ import { z } from "zod";
4
+ //#region src/tools/workflows/delete-workflow.ts
5
+ const deleteWorkflowTool = createTool({
6
+ id: "delete-workflow",
7
+ description: "Remove a saved workflow from storage and unregister the live in-process Workflow instance. Idempotent. Subsequent save-workflow calls with the same id re-register cleanly.",
8
+ inputSchema: z.object({ id: z.string().describe("The workflow id to delete.") }),
9
+ outputSchema: z.object({
10
+ ok: z.literal(true),
11
+ id: z.string()
12
+ }),
13
+ execute: async ({ id }, { mastra }) => {
14
+ if (!mastra) throw new Error("delete-workflow requires a Mastra context.");
15
+ return deleteWorkflow(mastra, id);
16
+ }
17
+ });
18
+ //#endregion
19
+ export { deleteWorkflowTool };
20
+
21
+ //# sourceMappingURL=delete-workflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete-workflow.js","names":[],"sources":["../../../src/tools/workflows/delete-workflow.ts"],"sourcesContent":["/**\n * Parent-mode tool: delete a saved workflow from storage and unregister the\n * live in-process Workflow instance so a subsequent save-workflow with the\n * same id re-registers cleanly.\n */\nimport type { Mastra } from '@mastra/core/mastra';\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\nimport { deleteWorkflow } from '../../workflows/service.js';\n\nexport const deleteWorkflowTool = createTool({\n id: 'delete-workflow',\n description:\n 'Remove a saved workflow from storage and unregister the live in-process Workflow instance. Idempotent. Subsequent save-workflow calls with the same id re-register cleanly.',\n inputSchema: z.object({\n id: z.string().describe('The workflow id to delete.'),\n }),\n outputSchema: z.object({\n ok: z.literal(true),\n id: z.string(),\n }),\n execute: async ({ id }, { mastra }) => {\n if (!mastra) throw new Error('delete-workflow requires a Mastra context.');\n return deleteWorkflow(mastra as Mastra, id);\n },\n});\n"],"mappings":";;;;AAUA,MAAa,qBAAqB,WAAW;CAC3C,IAAI;CACJ,aACE;CACF,aAAa,EAAE,OAAO,EACpB,IAAI,EAAE,OAAO,CAAC,CAAC,SAAS,4BAA4B,EACtD,CAAC;CACD,cAAc,EAAE,OAAO;EACrB,IAAI,EAAE,QAAQ,IAAI;EAClB,IAAI,EAAE,OAAO;CACf,CAAC;CACD,SAAS,OAAO,EAAE,MAAM,EAAE,aAAa;EACrC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,4CAA4C;EACzE,OAAO,eAAe,QAAkB,EAAE;CAC5C;AACF,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { RequestContext } from '@mastra/core/request-context';
2
+ interface EphemeralMemoryOptions {
3
+ threadId?: string;
4
+ }
5
+ export declare function withEphemeralMemory<T>(requestContext: RequestContext | undefined, fn: (requestContext: RequestContext | undefined) => Promise<T>, options?: EphemeralMemoryOptions): Promise<T>;
6
+ export {};
7
+ //# sourceMappingURL=ephemeral-memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ephemeral-memory.d.ts","sourceRoot":"","sources":["../../../src/tools/workflows/ephemeral-memory.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAgD,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE5G,UAAU,sBAAsB;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,mBAAmB,CAAC,CAAC,EACzC,cAAc,EAAE,cAAc,GAAG,SAAS,EAC1C,EAAE,EAAE,CAAC,cAAc,EAAE,cAAc,GAAG,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,EAC9D,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,CAAC,CAAC,CA6BZ"}
@@ -0,0 +1,45 @@
1
+ import { randomUUID } from "crypto";
2
+ import { MASTRA_RESOURCE_ID_KEY, MASTRA_THREAD_ID_KEY, RequestContext } from "@mastra/core/request-context";
3
+ //#region src/tools/workflows/ephemeral-memory.ts
4
+ /**
5
+ * Sub-invocations launched from a parent chat turn (workflow agent steps,
6
+ * sub-agent tool calls) must run under a fresh isolated Mastra memory scope
7
+ * so they don't:
8
+ *
9
+ * - write their prompts/responses into the parent chat thread's history, or
10
+ * - contend with the parent turn's memory-dependent processors
11
+ * (observational-memory, task-state, working-memory-state).
12
+ *
13
+ * `withEphemeralMemory` copies the caller's request context into a child,
14
+ * replaces its MastraMemory with a fresh thread id and inherited resource id,
15
+ * then passes that isolated child to `fn`. The parent context is never mutated,
16
+ * so concurrent sub-invocations cannot overwrite or restore each other's
17
+ * memory values. Isolation writes the ephemeral ids instead of scrubbing them:
18
+ * inner agent invocations resolve their thread/resource via those reserved
19
+ * keys, and leaving them unset causes downstream storage saves to throw
20
+ * "Thread ID is required".
21
+ *
22
+ * Callers can override the ephemeral thread id (e.g. for tests) via
23
+ * `options.threadId`.
24
+ */
25
+ async function withEphemeralMemory(requestContext, fn, options = {}) {
26
+ if (!requestContext) return fn(void 0);
27
+ const childRequestContext = new RequestContext(requestContext.entries());
28
+ const mastraMemory = requestContext.get("MastraMemory");
29
+ const resourceId = requestContext.get(MASTRA_RESOURCE_ID_KEY);
30
+ const ephemeralThreadId = options.threadId ?? randomUUID();
31
+ const parentResourceId = mastraMemory?.resourceId ?? resourceId ?? "";
32
+ childRequestContext.set("MastraMemory", {
33
+ thread: { id: ephemeralThreadId },
34
+ resourceId: parentResourceId,
35
+ memoryConfig: void 0
36
+ });
37
+ childRequestContext.set(MASTRA_THREAD_ID_KEY, ephemeralThreadId);
38
+ if (parentResourceId) childRequestContext.set(MASTRA_RESOURCE_ID_KEY, parentResourceId);
39
+ else childRequestContext.delete(MASTRA_RESOURCE_ID_KEY);
40
+ return fn(childRequestContext);
41
+ }
42
+ //#endregion
43
+ export { withEphemeralMemory };
44
+
45
+ //# sourceMappingURL=ephemeral-memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ephemeral-memory.js","names":[],"sources":["../../../src/tools/workflows/ephemeral-memory.ts"],"sourcesContent":["/**\n * Sub-invocations launched from a parent chat turn (workflow agent steps,\n * sub-agent tool calls) must run under a fresh isolated Mastra memory scope\n * so they don't:\n *\n * - write their prompts/responses into the parent chat thread's history, or\n * - contend with the parent turn's memory-dependent processors\n * (observational-memory, task-state, working-memory-state).\n *\n * `withEphemeralMemory` copies the caller's request context into a child,\n * replaces its MastraMemory with a fresh thread id and inherited resource id,\n * then passes that isolated child to `fn`. The parent context is never mutated,\n * so concurrent sub-invocations cannot overwrite or restore each other's\n * memory values. Isolation writes the ephemeral ids instead of scrubbing them:\n * inner agent invocations resolve their thread/resource via those reserved\n * keys, and leaving them unset causes downstream storage saves to throw\n * \"Thread ID is required\".\n *\n * Callers can override the ephemeral thread id (e.g. for tests) via\n * `options.threadId`.\n */\nimport { randomUUID } from 'node:crypto';\nimport { MASTRA_RESOURCE_ID_KEY, MASTRA_THREAD_ID_KEY, RequestContext } from '@mastra/core/request-context';\n\ninterface EphemeralMemoryOptions {\n threadId?: string;\n}\n\nexport async function withEphemeralMemory<T>(\n requestContext: RequestContext | undefined,\n fn: (requestContext: RequestContext | undefined) => Promise<T>,\n options: EphemeralMemoryOptions = {},\n): Promise<T> {\n if (!requestContext) return fn(undefined);\n\n const childRequestContext = new RequestContext(requestContext.entries());\n const mastraMemory = requestContext.get('MastraMemory') as\n | { thread?: { id?: string }; resourceId?: string; memoryConfig?: unknown }\n | undefined;\n const resourceId = requestContext.get(MASTRA_RESOURCE_ID_KEY) as string | undefined;\n const ephemeralThreadId = options.threadId ?? randomUUID();\n const parentResourceId = mastraMemory?.resourceId ?? resourceId ?? '';\n\n childRequestContext.set('MastraMemory', {\n thread: { id: ephemeralThreadId },\n resourceId: parentResourceId,\n memoryConfig: undefined,\n });\n // Stamp the reserved thread/resource-key context values with the same\n // ephemeral ids. Inner agent invocations (workflow agent steps, sub-agent\n // tool calls) read these keys to resolve their runtime thread; leaving\n // MASTRA_THREAD_ID_KEY unset causes prepare-memory-step to build a\n // MessageList without a threadId, which storage rejects downstream.\n childRequestContext.set(MASTRA_THREAD_ID_KEY, ephemeralThreadId);\n if (parentResourceId) {\n childRequestContext.set(MASTRA_RESOURCE_ID_KEY, parentResourceId);\n } else {\n childRequestContext.delete(MASTRA_RESOURCE_ID_KEY);\n }\n\n return fn(childRequestContext);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4BA,eAAsB,oBACpB,gBACA,IACA,UAAkC,CAAC,GACvB;CACZ,IAAI,CAAC,gBAAgB,OAAO,GAAG,KAAA,CAAS;CAExC,MAAM,sBAAsB,IAAI,eAAe,eAAe,QAAQ,CAAC;CACvE,MAAM,eAAe,eAAe,IAAI,cAAc;CAGtD,MAAM,aAAa,eAAe,IAAI,sBAAsB;CAC5D,MAAM,oBAAoB,QAAQ,YAAY,WAAW;CACzD,MAAM,mBAAmB,cAAc,cAAc,cAAc;CAEnE,oBAAoB,IAAI,gBAAgB;EACtC,QAAQ,EAAE,IAAI,kBAAkB;EAChC,YAAY;EACZ,cAAc,KAAA;CAChB,CAAC;CAMD,oBAAoB,IAAI,sBAAsB,iBAAiB;CAC/D,IAAI,kBACF,oBAAoB,IAAI,wBAAwB,gBAAgB;MAEhE,oBAAoB,OAAO,sBAAsB;CAGnD,OAAO,GAAG,mBAAmB;AAC/B"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Extract a JSON Schema from a Mastra tool's schema field. Tools created via
3
+ * `createTool({...})` wrap their Zod schemas with `toStandardSchema`, exposing
4
+ * `['~standard'].jsonSchema` as a `{ input(opts), output(opts) }` converter
5
+ * (see packages/schema-compat/src/standard-schema/adapters/zod-v3.ts:110-119).
6
+ * `direction` selects which side — pass 'input' for inputSchema, 'output' for
7
+ * outputSchema. Returns undefined if the schema is missing or not
8
+ * standard-schema-compliant — the workflow-builder agent then knows the tool's
9
+ * shape is opaque and must reshape via mapping.
10
+ */
11
+ export declare function extractJsonSchema(maybeSchema: unknown, direction: 'input' | 'output'): unknown | undefined;
12
+ //# sourceMappingURL=extract-json-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-json-schema.d.ts","sourceRoot":"","sources":["../../../src/tools/workflows/extract-json-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAc1G"}
@@ -0,0 +1,22 @@
1
+ //#region src/tools/workflows/extract-json-schema.ts
2
+ /**
3
+ * Extract a JSON Schema from a Mastra tool's schema field. Tools created via
4
+ * `createTool({...})` wrap their Zod schemas with `toStandardSchema`, exposing
5
+ * `['~standard'].jsonSchema` as a `{ input(opts), output(opts) }` converter
6
+ * (see packages/schema-compat/src/standard-schema/adapters/zod-v3.ts:110-119).
7
+ * `direction` selects which side — pass 'input' for inputSchema, 'output' for
8
+ * outputSchema. Returns undefined if the schema is missing or not
9
+ * standard-schema-compliant — the workflow-builder agent then knows the tool's
10
+ * shape is opaque and must reshape via mapping.
11
+ */
12
+ function extractJsonSchema(maybeSchema, direction) {
13
+ try {
14
+ return (maybeSchema?.["~standard"]?.jsonSchema)?.[direction]?.({ target: "draft-2020-12" });
15
+ } catch {
16
+ return;
17
+ }
18
+ }
19
+ //#endregion
20
+ export { extractJsonSchema };
21
+
22
+ //# sourceMappingURL=extract-json-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-json-schema.js","names":["s"],"sources":["../../../src/tools/workflows/extract-json-schema.ts"],"sourcesContent":["/**\n * Extract a JSON Schema from a Mastra tool's schema field. Tools created via\n * `createTool({...})` wrap their Zod schemas with `toStandardSchema`, exposing\n * `['~standard'].jsonSchema` as a `{ input(opts), output(opts) }` converter\n * (see packages/schema-compat/src/standard-schema/adapters/zod-v3.ts:110-119).\n * `direction` selects which side — pass 'input' for inputSchema, 'output' for\n * outputSchema. Returns undefined if the schema is missing or not\n * standard-schema-compliant — the workflow-builder agent then knows the tool's\n * shape is opaque and must reshape via mapping.\n */\nexport function extractJsonSchema(maybeSchema: unknown, direction: 'input' | 'output'): unknown | undefined {\n try {\n const s = maybeSchema as\n | {\n ['~standard']?: {\n jsonSchema?: { input?: (opts: unknown) => unknown; output?: (opts: unknown) => unknown };\n };\n }\n | undefined;\n const converter = s?.['~standard']?.jsonSchema;\n return converter?.[direction]?.({ target: 'draft-2020-12' });\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAAgB,kBAAkB,aAAsB,WAAoD;CAC1G,IAAI;EASF,QADkBA,cAAI,YAAY,EAAE,WAAA,GACjB,UAAU,GAAG,EAAE,QAAQ,gBAAgB,CAAC;CAC7D,QAAQ;EACN;CACF;AACF"}
@@ -0,0 +1,11 @@
1
+ export declare const getWorkflowTool: import("@mastra/core/tools").Tool<{
2
+ id: string;
3
+ }, {
4
+ id: string;
5
+ status: "active" | "archived";
6
+ description?: string | undefined;
7
+ inputSchema?: any;
8
+ outputSchema?: any;
9
+ graph?: any[] | undefined;
10
+ }, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "get-workflow", unknown>;
11
+ //# sourceMappingURL=get-workflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-workflow.d.ts","sourceRoot":"","sources":["../../../src/tools/workflows/get-workflow.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,eAAe;;;;;;;;;2HA2B1B,CAAC"}
@@ -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"}