@mastra/mcp-docs-server 0.0.0-commonjs-20250414101718
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/.docs/organized/changelogs/%40mastra%2Fastra.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +161 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +110 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +26 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +196 -0
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Frag.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +250 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +250 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +302 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +302 -0
- package/.docs/organized/changelogs/create-mastra.md +302 -0
- package/.docs/organized/changelogs/mastra.md +302 -0
- package/.docs/organized/code-examples/agent-network.md +282 -0
- package/.docs/organized/code-examples/agent.md +388 -0
- package/.docs/organized/code-examples/ai-sdk-useChat.md +378 -0
- package/.docs/organized/code-examples/assistant-ui.md +37 -0
- package/.docs/organized/code-examples/bird-checker-with-express.md +235 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +360 -0
- package/.docs/organized/code-examples/bird-checker-with-nextjs.md +250 -0
- package/.docs/organized/code-examples/client-side-tools.md +69 -0
- package/.docs/organized/code-examples/crypto-chatbot.md +96 -0
- package/.docs/organized/code-examples/fireworks-r1.md +159 -0
- package/.docs/organized/code-examples/mcp-registry-registry.md +63 -0
- package/.docs/organized/code-examples/memory-todo-agent.md +164 -0
- package/.docs/organized/code-examples/memory-with-context.md +167 -0
- package/.docs/organized/code-examples/memory-with-libsql.md +204 -0
- package/.docs/organized/code-examples/memory-with-mem0.md +121 -0
- package/.docs/organized/code-examples/memory-with-pg.md +224 -0
- package/.docs/organized/code-examples/memory-with-upstash.md +268 -0
- package/.docs/organized/code-examples/quick-start.md +129 -0
- package/.docs/organized/code-examples/stock-price-tool.md +124 -0
- package/.docs/organized/code-examples/weather-agent.md +353 -0
- package/.docs/organized/code-examples/workflow-ai-recruiter.md +159 -0
- package/.docs/organized/code-examples/workflow-with-inline-steps.md +111 -0
- package/.docs/organized/code-examples/workflow-with-memory.md +393 -0
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +131 -0
- package/.docs/raw/agents/adding-tools.mdx +317 -0
- package/.docs/raw/agents/adding-voice.mdx +175 -0
- package/.docs/raw/agents/agent-memory.mdx +62 -0
- package/.docs/raw/agents/mcp-guide.mdx +215 -0
- package/.docs/raw/agents/overview.mdx +303 -0
- package/.docs/raw/community/discord.mdx +12 -0
- package/.docs/raw/community/licensing.mdx +63 -0
- package/.docs/raw/deployment/client.mdx +120 -0
- package/.docs/raw/deployment/deployment.mdx +127 -0
- package/.docs/raw/deployment/server.mdx +282 -0
- package/.docs/raw/evals/custom-eval.mdx +22 -0
- package/.docs/raw/evals/overview.mdx +95 -0
- package/.docs/raw/evals/running-in-ci.mdx +81 -0
- package/.docs/raw/evals/textual-evals.mdx +54 -0
- package/.docs/raw/faq/index.mdx +63 -0
- package/.docs/raw/frameworks/ai-sdk.mdx +296 -0
- package/.docs/raw/frameworks/next-js.mdx +238 -0
- package/.docs/raw/getting-started/installation.mdx +442 -0
- package/.docs/raw/getting-started/mcp-docs-server.mdx +141 -0
- package/.docs/raw/getting-started/project-structure.mdx +80 -0
- package/.docs/raw/index.mdx +22 -0
- package/.docs/raw/integrations/index.mdx +213 -0
- package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
- package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +108 -0
- package/.docs/raw/memory/memory-processors.mdx +131 -0
- package/.docs/raw/memory/overview.mdx +119 -0
- package/.docs/raw/memory/semantic-recall.mdx +122 -0
- package/.docs/raw/memory/working-memory.mdx +87 -0
- package/.docs/raw/observability/logging.mdx +38 -0
- package/.docs/raw/observability/nextjs-tracing.mdx +108 -0
- package/.docs/raw/observability/tracing.mdx +115 -0
- package/.docs/raw/rag/chunking-and-embedding.mdx +156 -0
- package/.docs/raw/rag/overview.mdx +85 -0
- package/.docs/raw/rag/retrieval.mdx +365 -0
- package/.docs/raw/rag/vector-databases.mdx +340 -0
- package/.docs/raw/reference/agents/createTool.mdx +229 -0
- package/.docs/raw/reference/agents/generate.mdx +334 -0
- package/.docs/raw/reference/agents/getAgent.mdx +54 -0
- package/.docs/raw/reference/agents/stream.mdx +369 -0
- package/.docs/raw/reference/cli/build.mdx +55 -0
- package/.docs/raw/reference/cli/dev.mdx +134 -0
- package/.docs/raw/reference/cli/init.mdx +43 -0
- package/.docs/raw/reference/client-js/agents.mdx +107 -0
- package/.docs/raw/reference/client-js/error-handling.mdx +38 -0
- package/.docs/raw/reference/client-js/logs.mdx +24 -0
- package/.docs/raw/reference/client-js/memory.mdx +97 -0
- package/.docs/raw/reference/client-js/telemetry.mdx +20 -0
- package/.docs/raw/reference/client-js/tools.mdx +44 -0
- package/.docs/raw/reference/client-js/vectors.mdx +79 -0
- package/.docs/raw/reference/client-js/workflows.mdx +136 -0
- package/.docs/raw/reference/core/mastra-class.mdx +232 -0
- package/.docs/raw/reference/deployer/cloudflare.mdx +207 -0
- package/.docs/raw/reference/deployer/deployer.mdx +159 -0
- package/.docs/raw/reference/deployer/netlify.mdx +109 -0
- package/.docs/raw/reference/deployer/vercel.mdx +117 -0
- package/.docs/raw/reference/evals/answer-relevancy.mdx +186 -0
- package/.docs/raw/reference/evals/bias.mdx +186 -0
- package/.docs/raw/reference/evals/completeness.mdx +174 -0
- package/.docs/raw/reference/evals/content-similarity.mdx +183 -0
- package/.docs/raw/reference/evals/context-position.mdx +190 -0
- package/.docs/raw/reference/evals/context-precision.mdx +189 -0
- package/.docs/raw/reference/evals/context-relevancy.mdx +188 -0
- package/.docs/raw/reference/evals/contextual-recall.mdx +191 -0
- package/.docs/raw/reference/evals/faithfulness.mdx +193 -0
- package/.docs/raw/reference/evals/hallucination.mdx +219 -0
- package/.docs/raw/reference/evals/keyword-coverage.mdx +176 -0
- package/.docs/raw/reference/evals/prompt-alignment.mdx +238 -0
- package/.docs/raw/reference/evals/summarization.mdx +205 -0
- package/.docs/raw/reference/evals/textual-difference.mdx +161 -0
- package/.docs/raw/reference/evals/tone-consistency.mdx +181 -0
- package/.docs/raw/reference/evals/toxicity.mdx +165 -0
- package/.docs/raw/reference/index.mdx +12 -0
- package/.docs/raw/reference/memory/Memory.mdx +212 -0
- package/.docs/raw/reference/memory/createThread.mdx +95 -0
- package/.docs/raw/reference/memory/getThreadById.mdx +46 -0
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +48 -0
- package/.docs/raw/reference/memory/query.mdx +167 -0
- package/.docs/raw/reference/networks/agent-network.mdx +159 -0
- package/.docs/raw/reference/observability/create-logger.mdx +106 -0
- package/.docs/raw/reference/observability/logger.mdx +55 -0
- package/.docs/raw/reference/observability/otel-config.mdx +120 -0
- package/.docs/raw/reference/observability/providers/braintrust.mdx +40 -0
- package/.docs/raw/reference/observability/providers/dash0.mdx +40 -0
- package/.docs/raw/reference/observability/providers/index.mdx +16 -0
- package/.docs/raw/reference/observability/providers/laminar.mdx +41 -0
- package/.docs/raw/reference/observability/providers/langfuse.mdx +51 -0
- package/.docs/raw/reference/observability/providers/langsmith.mdx +48 -0
- package/.docs/raw/reference/observability/providers/langwatch.mdx +45 -0
- package/.docs/raw/reference/observability/providers/new-relic.mdx +40 -0
- package/.docs/raw/reference/observability/providers/signoz.mdx +40 -0
- package/.docs/raw/reference/observability/providers/traceloop.mdx +40 -0
- package/.docs/raw/reference/rag/astra.mdx +258 -0
- package/.docs/raw/reference/rag/chroma.mdx +281 -0
- package/.docs/raw/reference/rag/chunk.mdx +235 -0
- package/.docs/raw/reference/rag/document.mdx +127 -0
- package/.docs/raw/reference/rag/embeddings.mdx +160 -0
- package/.docs/raw/reference/rag/extract-params.mdx +226 -0
- package/.docs/raw/reference/rag/graph-rag.mdx +182 -0
- package/.docs/raw/reference/rag/libsql.mdx +357 -0
- package/.docs/raw/reference/rag/metadata-filters.mdx +298 -0
- package/.docs/raw/reference/rag/pg.mdx +477 -0
- package/.docs/raw/reference/rag/pinecone.mdx +281 -0
- package/.docs/raw/reference/rag/qdrant.mdx +236 -0
- package/.docs/raw/reference/rag/rerank.mdx +212 -0
- package/.docs/raw/reference/rag/turbopuffer.mdx +249 -0
- package/.docs/raw/reference/rag/upstash.mdx +247 -0
- package/.docs/raw/reference/rag/vectorize.mdx +298 -0
- package/.docs/raw/reference/storage/libsql.mdx +74 -0
- package/.docs/raw/reference/storage/postgresql.mdx +48 -0
- package/.docs/raw/reference/storage/upstash.mdx +86 -0
- package/.docs/raw/reference/tools/client.mdx +207 -0
- package/.docs/raw/reference/tools/document-chunker-tool.mdx +141 -0
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +154 -0
- package/.docs/raw/reference/tools/mcp-configuration.mdx +206 -0
- package/.docs/raw/reference/tools/vector-query-tool.mdx +212 -0
- package/.docs/raw/reference/voice/composite-voice.mdx +140 -0
- package/.docs/raw/reference/voice/deepgram.mdx +164 -0
- package/.docs/raw/reference/voice/elevenlabs.mdx +216 -0
- package/.docs/raw/reference/voice/google.mdx +198 -0
- package/.docs/raw/reference/voice/mastra-voice.mdx +394 -0
- package/.docs/raw/reference/voice/murf.mdx +251 -0
- package/.docs/raw/reference/voice/openai-realtime.mdx +431 -0
- package/.docs/raw/reference/voice/openai.mdx +168 -0
- package/.docs/raw/reference/voice/playai.mdx +159 -0
- package/.docs/raw/reference/voice/sarvam.mdx +260 -0
- package/.docs/raw/reference/voice/speechify.mdx +145 -0
- package/.docs/raw/reference/voice/voice.answer.mdx +122 -0
- package/.docs/raw/reference/voice/voice.connect.mdx +124 -0
- package/.docs/raw/reference/voice/voice.listen.mdx +195 -0
- package/.docs/raw/reference/voice/voice.on.mdx +189 -0
- package/.docs/raw/reference/voice/voice.send.mdx +118 -0
- package/.docs/raw/reference/voice/voice.speak.mdx +203 -0
- package/.docs/raw/reference/workflows/after.mdx +88 -0
- package/.docs/raw/reference/workflows/afterEvent.mdx +76 -0
- package/.docs/raw/reference/workflows/commit.mdx +37 -0
- package/.docs/raw/reference/workflows/createRun.mdx +77 -0
- package/.docs/raw/reference/workflows/else.mdx +72 -0
- package/.docs/raw/reference/workflows/events.mdx +305 -0
- package/.docs/raw/reference/workflows/execute.mdx +110 -0
- package/.docs/raw/reference/workflows/if.mdx +107 -0
- package/.docs/raw/reference/workflows/resume.mdx +155 -0
- package/.docs/raw/reference/workflows/resumeWithEvent.mdx +133 -0
- package/.docs/raw/reference/workflows/snapshots.mdx +207 -0
- package/.docs/raw/reference/workflows/start.mdx +84 -0
- package/.docs/raw/reference/workflows/step-class.mdx +100 -0
- package/.docs/raw/reference/workflows/step-condition.mdx +134 -0
- package/.docs/raw/reference/workflows/step-function.mdx +92 -0
- package/.docs/raw/reference/workflows/step-options.mdx +69 -0
- package/.docs/raw/reference/workflows/step-retries.mdx +203 -0
- package/.docs/raw/reference/workflows/suspend.mdx +70 -0
- package/.docs/raw/reference/workflows/then.mdx +74 -0
- package/.docs/raw/reference/workflows/until.mdx +165 -0
- package/.docs/raw/reference/workflows/watch.mdx +118 -0
- package/.docs/raw/reference/workflows/while.mdx +168 -0
- package/.docs/raw/reference/workflows/workflow.mdx +233 -0
- package/.docs/raw/storage/overview.mdx +378 -0
- package/.docs/raw/voice/overview.mdx +135 -0
- package/.docs/raw/voice/speech-to-text.mdx +45 -0
- package/.docs/raw/voice/text-to-speech.mdx +52 -0
- package/.docs/raw/voice/voice-to-voice.mdx +310 -0
- package/.docs/raw/workflows/control-flow.mdx +778 -0
- package/.docs/raw/workflows/dynamic-workflows.mdx +236 -0
- package/.docs/raw/workflows/error-handling.mdx +183 -0
- package/.docs/raw/workflows/nested-workflows.mdx +352 -0
- package/.docs/raw/workflows/overview.mdx +203 -0
- package/.docs/raw/workflows/steps.mdx +108 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +404 -0
- package/.docs/raw/workflows/variables.mdx +313 -0
- package/LICENSE.md +46 -0
- package/README.md +129 -0
- package/dist/_tsup-dts-rollup.d.ts +149 -0
- package/dist/chunk-QWYMT5LP.js +194 -0
- package/dist/prepare-docs/prepare.d.ts +1 -0
- package/dist/prepare-docs/prepare.js +1 -0
- package/dist/stdio.d.ts +1 -0
- package/dist/stdio.js +518 -0
- package/package.json +60 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
### package.json
|
|
2
|
+
```json
|
|
3
|
+
{
|
|
4
|
+
"name": "examples-workflow-with-memory",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": true,
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [],
|
|
12
|
+
"author": "",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"description": "",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "^20.17.27",
|
|
17
|
+
"tsx": "^4.19.3",
|
|
18
|
+
"typescript": "^5.8.2",
|
|
19
|
+
"zod": "^3.24.2"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@ai-sdk/openai": "latest",
|
|
23
|
+
"@mastra/core": "workspace:*",
|
|
24
|
+
"@mastra/memory": "workspace:*",
|
|
25
|
+
"@mastra/pg": "workspace:*"
|
|
26
|
+
},
|
|
27
|
+
"version": "0.0.1"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### mastra/agents/index.ts
|
|
33
|
+
```typescript
|
|
34
|
+
import { openai } from '@ai-sdk/openai';
|
|
35
|
+
import { Agent } from '@mastra/core/agent';
|
|
36
|
+
import { Memory } from '@mastra/memory';
|
|
37
|
+
import { PostgresStore } from '@mastra/pg';
|
|
38
|
+
|
|
39
|
+
const connectionString = process.env.POSTGRES_URL!;
|
|
40
|
+
const memory = new Memory({
|
|
41
|
+
storage: new PostgresStore({ connectionString }),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const catOne = new Agent({
|
|
45
|
+
name: 'cat-one',
|
|
46
|
+
memory,
|
|
47
|
+
instructions:
|
|
48
|
+
'You are a feline expert with comprehensive knowledge of all cat species, from domestic breeds to wild big cats. As a lifelong cat specialist, you understand their behavior, biology, social structures, and evolutionary history in great depth.',
|
|
49
|
+
model: openai('gpt-4o'),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### mastra/index.ts
|
|
55
|
+
```typescript
|
|
56
|
+
import { Mastra } from '@mastra/core';
|
|
57
|
+
import { createLogger } from '@mastra/core/logger';
|
|
58
|
+
|
|
59
|
+
import { catOne } from './agents/index';
|
|
60
|
+
import { sequentialWorkflow, parallelWorkflow, branchedWorkflow, cyclicalWorkflow } from './workflows';
|
|
61
|
+
|
|
62
|
+
export const mastra = new Mastra({
|
|
63
|
+
agents: { catOne },
|
|
64
|
+
logger: createLogger({
|
|
65
|
+
name: 'Mastra',
|
|
66
|
+
level: 'debug',
|
|
67
|
+
}),
|
|
68
|
+
workflows: {
|
|
69
|
+
sequentialWorkflow,
|
|
70
|
+
parallelWorkflow,
|
|
71
|
+
branchedWorkflow,
|
|
72
|
+
cyclicalWorkflow,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### mastra/tools/index.ts
|
|
79
|
+
```typescript
|
|
80
|
+
import { createTool } from '@mastra/core/tools';
|
|
81
|
+
import { z } from 'zod';
|
|
82
|
+
|
|
83
|
+
const getCatFact = async () => {
|
|
84
|
+
const { fact } = (await fetch('https://catfact.ninja/fact').then(res => res.json())) as {
|
|
85
|
+
fact: string;
|
|
86
|
+
};
|
|
87
|
+
return fact;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const catFact = createTool({
|
|
91
|
+
id: 'Get cat facts',
|
|
92
|
+
inputSchema: z.object({}),
|
|
93
|
+
description: 'Fetches cat facts',
|
|
94
|
+
execute: async () => {
|
|
95
|
+
console.log('using tool to fetch cat fact');
|
|
96
|
+
return {
|
|
97
|
+
catFact: await getCatFact(),
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### mastra/workflows/index.ts
|
|
105
|
+
```typescript
|
|
106
|
+
import { Workflow, Step } from '@mastra/core/workflows';
|
|
107
|
+
import { z } from 'zod';
|
|
108
|
+
|
|
109
|
+
const stepOne = new Step({
|
|
110
|
+
id: 'stepOne',
|
|
111
|
+
description: 'Doubles the input value',
|
|
112
|
+
inputSchema: z.object({
|
|
113
|
+
inputValue: z.number(),
|
|
114
|
+
}),
|
|
115
|
+
outputSchema: z.object({
|
|
116
|
+
doubledValue: z.number(),
|
|
117
|
+
}),
|
|
118
|
+
execute: async ({ context }) => {
|
|
119
|
+
const doubledValue = context.inputValue * 2;
|
|
120
|
+
return { doubledValue };
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const stepTwo = new Step({
|
|
125
|
+
id: 'stepTwo',
|
|
126
|
+
description: 'Adds 1 to the input value',
|
|
127
|
+
inputSchema: z.object({
|
|
128
|
+
valueToIncrement: z.number(),
|
|
129
|
+
}),
|
|
130
|
+
outputSchema: z.object({
|
|
131
|
+
incrementedValue: z.number(),
|
|
132
|
+
}),
|
|
133
|
+
execute: async ({ context }) => {
|
|
134
|
+
const incrementedValue = context.valueToIncrement + 1;
|
|
135
|
+
return { incrementedValue };
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const stepThree = new Step({
|
|
140
|
+
id: 'stepThree',
|
|
141
|
+
description: 'Squares the input value',
|
|
142
|
+
inputSchema: z.object({
|
|
143
|
+
valueToSquare: z.number(),
|
|
144
|
+
}),
|
|
145
|
+
outputSchema: z.object({
|
|
146
|
+
squaredValue: z.number(),
|
|
147
|
+
}),
|
|
148
|
+
execute: async ({ context }) => {
|
|
149
|
+
const squaredValue = context.valueToSquare * context.valueToSquare;
|
|
150
|
+
return { squaredValue };
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const stepFour = new Step({
|
|
155
|
+
id: 'stepFour',
|
|
156
|
+
description: 'Gives the square root of the input value',
|
|
157
|
+
inputSchema: z.object({
|
|
158
|
+
valueToRoot: z.number(),
|
|
159
|
+
}),
|
|
160
|
+
outputSchema: z.object({
|
|
161
|
+
rootValue: z.number(),
|
|
162
|
+
}),
|
|
163
|
+
execute: async ({ context }) => {
|
|
164
|
+
return { rootValue: Math.sqrt(context.valueToRoot) };
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const stepFive = new Step({
|
|
169
|
+
id: 'stepFive',
|
|
170
|
+
description: 'Triples the input value',
|
|
171
|
+
inputSchema: z.object({
|
|
172
|
+
inputValue: z.number(),
|
|
173
|
+
}),
|
|
174
|
+
outputSchema: z.object({
|
|
175
|
+
tripledValue: z.number(),
|
|
176
|
+
}),
|
|
177
|
+
execute: async ({ context }) => {
|
|
178
|
+
const tripledValue = context.inputValue * 3;
|
|
179
|
+
return { tripledValue };
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const stepSix = new Step({
|
|
184
|
+
id: 'stepSix',
|
|
185
|
+
description: 'Logs the input value',
|
|
186
|
+
inputSchema: z.object({
|
|
187
|
+
inputValue: z.number(),
|
|
188
|
+
}),
|
|
189
|
+
outputSchema: z.object({
|
|
190
|
+
rawText: z.string(),
|
|
191
|
+
}),
|
|
192
|
+
execute: async ({ context }) => {
|
|
193
|
+
console.log(context.inputValue);
|
|
194
|
+
return { rawText: context.inputValue.toString() };
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
export const sequentialWorkflow = new Workflow({
|
|
199
|
+
name: 'sequential-workflow',
|
|
200
|
+
triggerSchema: z.object({
|
|
201
|
+
firstValue: z.number(),
|
|
202
|
+
}),
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
sequentialWorkflow
|
|
206
|
+
.step(stepOne, {
|
|
207
|
+
variables: {
|
|
208
|
+
inputValue: {
|
|
209
|
+
step: 'trigger',
|
|
210
|
+
path: 'firstValue',
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
})
|
|
214
|
+
.then(stepTwo, {
|
|
215
|
+
variables: {
|
|
216
|
+
valueToIncrement: {
|
|
217
|
+
step: stepOne,
|
|
218
|
+
path: 'doubledValue',
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
})
|
|
222
|
+
.then(stepThree, {
|
|
223
|
+
variables: {
|
|
224
|
+
valueToSquare: {
|
|
225
|
+
step: stepTwo,
|
|
226
|
+
path: 'incrementedValue',
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
})
|
|
230
|
+
.then(stepFour, {
|
|
231
|
+
variables: {
|
|
232
|
+
valueToRoot: {
|
|
233
|
+
step: stepThree,
|
|
234
|
+
path: 'squaredValue',
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
})
|
|
238
|
+
.then(stepFive, {
|
|
239
|
+
variables: {
|
|
240
|
+
inputValue: {
|
|
241
|
+
step: stepFour,
|
|
242
|
+
path: 'rootValue',
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
sequentialWorkflow.commit();
|
|
248
|
+
|
|
249
|
+
export const parallelWorkflow = new Workflow({
|
|
250
|
+
name: 'parallel-workflow',
|
|
251
|
+
triggerSchema: z.object({
|
|
252
|
+
firstValue: z.number(),
|
|
253
|
+
}),
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
parallelWorkflow
|
|
257
|
+
.step(stepOne, {
|
|
258
|
+
variables: {
|
|
259
|
+
inputValue: {
|
|
260
|
+
step: 'trigger',
|
|
261
|
+
path: 'firstValue',
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
})
|
|
265
|
+
.then(stepSix, {
|
|
266
|
+
variables: {
|
|
267
|
+
inputValue: {
|
|
268
|
+
step: stepOne,
|
|
269
|
+
path: 'doubledValue',
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
})
|
|
273
|
+
.step(stepTwo, {
|
|
274
|
+
variables: {
|
|
275
|
+
valueToIncrement: {
|
|
276
|
+
step: 'trigger',
|
|
277
|
+
path: 'firstValue',
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
})
|
|
281
|
+
.step(stepThree, {
|
|
282
|
+
variables: {
|
|
283
|
+
valueToSquare: {
|
|
284
|
+
step: 'trigger',
|
|
285
|
+
path: 'firstValue',
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
parallelWorkflow.commit();
|
|
291
|
+
|
|
292
|
+
export const branchedWorkflow = new Workflow({
|
|
293
|
+
name: 'branched-workflow',
|
|
294
|
+
triggerSchema: z.object({
|
|
295
|
+
firstValue: z.number(),
|
|
296
|
+
}),
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
branchedWorkflow
|
|
300
|
+
.step(stepOne, {
|
|
301
|
+
variables: {
|
|
302
|
+
inputValue: {
|
|
303
|
+
step: 'trigger',
|
|
304
|
+
path: 'firstValue',
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
})
|
|
308
|
+
.then(stepTwo, {
|
|
309
|
+
variables: {
|
|
310
|
+
valueToIncrement: {
|
|
311
|
+
step: stepOne,
|
|
312
|
+
path: 'doubledValue',
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
})
|
|
316
|
+
.then(stepFour, {
|
|
317
|
+
variables: {
|
|
318
|
+
valueToRoot: {
|
|
319
|
+
step: stepTwo,
|
|
320
|
+
path: 'incrementedValue',
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
})
|
|
324
|
+
.after(stepOne)
|
|
325
|
+
.step(stepThree, {
|
|
326
|
+
variables: {
|
|
327
|
+
valueToSquare: {
|
|
328
|
+
step: stepOne,
|
|
329
|
+
path: 'doubledValue',
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
})
|
|
333
|
+
.then(stepFive, {
|
|
334
|
+
variables: {
|
|
335
|
+
inputValue: {
|
|
336
|
+
step: stepThree,
|
|
337
|
+
path: 'squaredValue',
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
branchedWorkflow.commit();
|
|
343
|
+
|
|
344
|
+
export const cyclicalWorkflow = new Workflow({
|
|
345
|
+
name: 'cyclical-workflow',
|
|
346
|
+
triggerSchema: z.object({
|
|
347
|
+
firstValue: z.number(),
|
|
348
|
+
}),
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
cyclicalWorkflow
|
|
352
|
+
.step(stepOne, {
|
|
353
|
+
variables: {
|
|
354
|
+
inputValue: {
|
|
355
|
+
step: 'trigger',
|
|
356
|
+
path: 'firstValue',
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
})
|
|
360
|
+
.then(stepTwo, {
|
|
361
|
+
variables: {
|
|
362
|
+
valueToIncrement: {
|
|
363
|
+
step: 'trigger',
|
|
364
|
+
path: 'firstValue',
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
})
|
|
368
|
+
.after(stepOne)
|
|
369
|
+
.step(stepThree, {
|
|
370
|
+
when: { ref: { step: stepOne, path: 'doubledValue' }, query: { $lte: 6 } },
|
|
371
|
+
variables: {
|
|
372
|
+
valueToSquare: {
|
|
373
|
+
step: stepOne,
|
|
374
|
+
path: 'doubledValue',
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
})
|
|
378
|
+
.step(stepOne, {
|
|
379
|
+
when: {
|
|
380
|
+
ref: { step: stepOne, path: 'doubledValue' },
|
|
381
|
+
query: { $lte: 120000 },
|
|
382
|
+
},
|
|
383
|
+
variables: {
|
|
384
|
+
inputValue: {
|
|
385
|
+
step: stepOne,
|
|
386
|
+
path: 'doubledValue',
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
cyclicalWorkflow.commit();
|
|
392
|
+
|
|
393
|
+
```
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
### package.json
|
|
2
|
+
```json
|
|
3
|
+
{
|
|
4
|
+
"name": "examples-workflow-with-separate-steps",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": true,
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
10
|
+
"dev": "mastra dev",
|
|
11
|
+
"start:workflow": "npx tsx src/index.ts"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"description": "",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^20.17.27",
|
|
19
|
+
"mastra": "workspace:*",
|
|
20
|
+
"tsx": "^4.19.3",
|
|
21
|
+
"typescript": "^5.8.2",
|
|
22
|
+
"zod": "^3.24.2"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@mastra/core": "workspace:*"
|
|
26
|
+
},
|
|
27
|
+
"version": "0.0.1-alpha.2"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### index.ts
|
|
33
|
+
```typescript
|
|
34
|
+
import { mastra } from './mastra';
|
|
35
|
+
|
|
36
|
+
async function main() {
|
|
37
|
+
const myWorkflow = mastra.getWorkflow('myWorkflow');
|
|
38
|
+
const { start } = myWorkflow.createRun();
|
|
39
|
+
try {
|
|
40
|
+
const res = await start({
|
|
41
|
+
triggerData: {
|
|
42
|
+
inputValue: 30,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
console.log(res.results);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
console.log(e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
main();
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### mastra/index.ts
|
|
56
|
+
```typescript
|
|
57
|
+
import { Mastra } from '@mastra/core';
|
|
58
|
+
|
|
59
|
+
import { myWorkflow } from './workflows';
|
|
60
|
+
|
|
61
|
+
export const mastra = new Mastra({
|
|
62
|
+
workflows: {
|
|
63
|
+
myWorkflow,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### mastra/workflows/index.ts
|
|
70
|
+
```typescript
|
|
71
|
+
import { Step, Workflow } from '@mastra/core/workflows';
|
|
72
|
+
import { z } from 'zod';
|
|
73
|
+
|
|
74
|
+
const stepOne = new Step({
|
|
75
|
+
id: 'stepOne',
|
|
76
|
+
execute: async ({ context }) => {
|
|
77
|
+
const triggerData = context?.triggerData;
|
|
78
|
+
const doubledValue = triggerData.inputValue * 2;
|
|
79
|
+
return { doubledValue };
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const stepTwo = new Step({
|
|
84
|
+
id: 'stepTwo',
|
|
85
|
+
execute: async ({ context }) => {
|
|
86
|
+
if (context?.steps.stepOne.status !== 'success') {
|
|
87
|
+
throw new Error('stepOne failed');
|
|
88
|
+
}
|
|
89
|
+
const stepOneResult = context?.steps.stepOne?.output;
|
|
90
|
+
const incrementedValue = stepOneResult.doubledValue + 1;
|
|
91
|
+
return { incrementedValue };
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const stepThree = new Step({
|
|
96
|
+
id: 'stepThree',
|
|
97
|
+
execute: async ({ context }) => {
|
|
98
|
+
const triggerData = context?.triggerData;
|
|
99
|
+
const tripledValue = triggerData.inputValue * 3;
|
|
100
|
+
return { tripledValue };
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const stepFour = new Step({
|
|
105
|
+
id: 'stepFour',
|
|
106
|
+
execute: async ({ context }) => {
|
|
107
|
+
if (context?.steps.stepThree.status !== 'success') {
|
|
108
|
+
throw new Error('stepThree failed');
|
|
109
|
+
}
|
|
110
|
+
const stepThreeResult = context?.steps.stepThree?.output;
|
|
111
|
+
const isEven = stepThreeResult.tripledValue % 2 === 0;
|
|
112
|
+
return { isEven };
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export const myWorkflow = new Workflow({
|
|
117
|
+
name: 'my-workflow',
|
|
118
|
+
triggerSchema: z.object({
|
|
119
|
+
inputValue: z.number(),
|
|
120
|
+
}),
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
myWorkflow.step(stepOne).then(stepTwo).step(stepThree).then(stepFour).commit();
|
|
124
|
+
|
|
125
|
+
const { start } = myWorkflow.createRun();
|
|
126
|
+
|
|
127
|
+
const result = await start({ triggerData: { inputValue: 3 } });
|
|
128
|
+
|
|
129
|
+
console.log(result);
|
|
130
|
+
|
|
131
|
+
```
|