@mastra/mcp-docs-server 1.1.5 → 1.1.6-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/docs/agents/adding-voice.md +349 -0
- package/.docs/docs/agents/agent-approval.md +558 -0
- package/.docs/docs/agents/agent-memory.md +209 -0
- package/.docs/docs/agents/guardrails.md +374 -0
- package/.docs/docs/agents/network-approval.md +275 -0
- package/.docs/docs/agents/networks.md +299 -0
- package/.docs/docs/agents/overview.md +304 -0
- package/.docs/docs/agents/processors.md +622 -0
- package/.docs/docs/agents/structured-output.md +273 -0
- package/.docs/docs/agents/supervisor-agents.md +304 -0
- package/.docs/docs/agents/using-tools.md +214 -0
- package/.docs/docs/build-with-ai/mcp-docs-server.md +238 -0
- package/.docs/docs/build-with-ai/skills.md +35 -0
- package/.docs/docs/community/contributing-templates.md +3 -0
- package/.docs/docs/community/discord.md +9 -0
- package/.docs/docs/community/licensing.md +66 -0
- package/.docs/docs/deployment/cloud-providers.md +15 -0
- package/.docs/docs/deployment/mastra-server.md +122 -0
- package/.docs/docs/deployment/monorepo.md +142 -0
- package/.docs/docs/deployment/overview.md +62 -0
- package/.docs/docs/deployment/studio.md +239 -0
- package/.docs/docs/deployment/web-framework.md +52 -0
- package/.docs/docs/deployment/workflow-runners.md +9 -0
- package/.docs/docs/evals/built-in-scorers.md +47 -0
- package/.docs/docs/evals/custom-scorers.md +519 -0
- package/.docs/docs/evals/overview.md +141 -0
- package/.docs/docs/evals/running-in-ci.md +124 -0
- package/.docs/docs/getting-started/build-with-ai.md +68 -0
- package/.docs/docs/getting-started/manual-install.md +226 -0
- package/.docs/docs/getting-started/project-structure.md +60 -0
- package/.docs/docs/getting-started/start.md +28 -0
- package/.docs/docs/getting-started/studio.md +101 -0
- package/.docs/docs/index.md +43 -0
- package/.docs/docs/mastra-cloud/deployment.md +77 -0
- package/.docs/docs/mastra-cloud/observability.md +38 -0
- package/.docs/docs/mastra-cloud/overview.md +23 -0
- package/.docs/docs/mastra-cloud/setup.md +42 -0
- package/.docs/docs/mastra-cloud/studio.md +24 -0
- package/.docs/docs/mastra-code/configuration.md +299 -0
- package/.docs/docs/mastra-code/customization.md +228 -0
- package/.docs/docs/mastra-code/modes.md +104 -0
- package/.docs/docs/mastra-code/overview.md +135 -0
- package/.docs/docs/mastra-code/tools.md +229 -0
- package/.docs/docs/mcp/overview.md +373 -0
- package/.docs/docs/mcp/publishing-mcp-server.md +95 -0
- package/.docs/docs/memory/memory-processors.md +314 -0
- package/.docs/docs/memory/message-history.md +260 -0
- package/.docs/docs/memory/observational-memory.md +248 -0
- package/.docs/docs/memory/overview.md +45 -0
- package/.docs/docs/memory/semantic-recall.md +272 -0
- package/.docs/docs/memory/storage.md +261 -0
- package/.docs/docs/memory/working-memory.md +400 -0
- package/.docs/docs/observability/datasets/overview.md +198 -0
- package/.docs/docs/observability/datasets/running-experiments.md +274 -0
- package/.docs/docs/observability/logging.md +99 -0
- package/.docs/docs/observability/overview.md +70 -0
- package/.docs/docs/observability/tracing/bridges/otel.md +209 -0
- package/.docs/docs/observability/tracing/exporters/arize.md +272 -0
- package/.docs/docs/observability/tracing/exporters/braintrust.md +111 -0
- package/.docs/docs/observability/tracing/exporters/cloud.md +127 -0
- package/.docs/docs/observability/tracing/exporters/datadog.md +187 -0
- package/.docs/docs/observability/tracing/exporters/default.md +209 -0
- package/.docs/docs/observability/tracing/exporters/laminar.md +100 -0
- package/.docs/docs/observability/tracing/exporters/langfuse.md +213 -0
- package/.docs/docs/observability/tracing/exporters/langsmith.md +198 -0
- package/.docs/docs/observability/tracing/exporters/otel.md +476 -0
- package/.docs/docs/observability/tracing/exporters/posthog.md +148 -0
- package/.docs/docs/observability/tracing/exporters/sentry.md +208 -0
- package/.docs/docs/observability/tracing/overview.md +1112 -0
- package/.docs/docs/observability/tracing/processors/sensitive-data-filter.md +300 -0
- package/.docs/docs/rag/chunking-and-embedding.md +183 -0
- package/.docs/docs/rag/graph-rag.md +215 -0
- package/.docs/docs/rag/overview.md +72 -0
- package/.docs/docs/rag/retrieval.md +515 -0
- package/.docs/docs/rag/vector-databases.md +645 -0
- package/.docs/docs/server/auth/auth0.md +220 -0
- package/.docs/docs/server/auth/better-auth.md +203 -0
- package/.docs/docs/server/auth/clerk.md +132 -0
- package/.docs/docs/server/auth/composite-auth.md +234 -0
- package/.docs/docs/server/auth/custom-auth-provider.md +513 -0
- package/.docs/docs/server/auth/firebase.md +272 -0
- package/.docs/docs/server/auth/jwt.md +110 -0
- package/.docs/docs/server/auth/simple-auth.md +180 -0
- package/.docs/docs/server/auth/supabase.md +117 -0
- package/.docs/docs/server/auth/workos.md +186 -0
- package/.docs/docs/server/auth.md +38 -0
- package/.docs/docs/server/custom-adapters.md +378 -0
- package/.docs/docs/server/custom-api-routes.md +267 -0
- package/.docs/docs/server/mastra-client.md +243 -0
- package/.docs/docs/server/mastra-server.md +71 -0
- package/.docs/docs/server/middleware.md +225 -0
- package/.docs/docs/server/request-context.md +471 -0
- package/.docs/docs/server/server-adapters.md +547 -0
- package/.docs/docs/streaming/events.md +237 -0
- package/.docs/docs/streaming/overview.md +175 -0
- package/.docs/docs/streaming/tool-streaming.md +175 -0
- package/.docs/docs/streaming/workflow-streaming.md +109 -0
- package/.docs/docs/voice/overview.md +959 -0
- package/.docs/docs/voice/speech-to-speech.md +102 -0
- package/.docs/docs/voice/speech-to-text.md +79 -0
- package/.docs/docs/voice/text-to-speech.md +83 -0
- package/.docs/docs/workflows/agents-and-tools.md +166 -0
- package/.docs/docs/workflows/control-flow.md +822 -0
- package/.docs/docs/workflows/error-handling.md +360 -0
- package/.docs/docs/workflows/human-in-the-loop.md +215 -0
- package/.docs/docs/workflows/overview.md +370 -0
- package/.docs/docs/workflows/snapshots.md +238 -0
- package/.docs/docs/workflows/suspend-and-resume.md +205 -0
- package/.docs/docs/workflows/time-travel.md +309 -0
- package/.docs/docs/workflows/workflow-state.md +181 -0
- package/.docs/docs/workspace/filesystem.md +164 -0
- package/.docs/docs/workspace/overview.md +239 -0
- package/.docs/docs/workspace/sandbox.md +63 -0
- package/.docs/docs/workspace/search.md +243 -0
- package/.docs/docs/workspace/skills.md +169 -0
- package/.docs/guides/agent-frameworks/ai-sdk.md +140 -0
- package/.docs/guides/build-your-ui/ai-sdk-ui.md +1499 -0
- package/.docs/guides/build-your-ui/assistant-ui.md +156 -0
- package/.docs/guides/build-your-ui/copilotkit.md +289 -0
- package/.docs/guides/deployment/amazon-ec2.md +130 -0
- package/.docs/guides/deployment/aws-lambda.md +248 -0
- package/.docs/guides/deployment/azure-app-services.md +114 -0
- package/.docs/guides/deployment/cloudflare.md +99 -0
- package/.docs/guides/deployment/digital-ocean.md +168 -0
- package/.docs/guides/deployment/inngest.md +682 -0
- package/.docs/guides/deployment/netlify.md +77 -0
- package/.docs/guides/deployment/vercel.md +101 -0
- package/.docs/guides/getting-started/astro.md +398 -0
- package/.docs/guides/getting-started/electron.md +504 -0
- package/.docs/guides/getting-started/express.md +251 -0
- package/.docs/guides/getting-started/hono.md +190 -0
- package/.docs/guides/getting-started/next-js.md +347 -0
- package/.docs/guides/getting-started/nuxt.md +497 -0
- package/.docs/guides/getting-started/quickstart.md +67 -0
- package/.docs/guides/getting-started/sveltekit.md +296 -0
- package/.docs/guides/getting-started/vite-react.md +425 -0
- package/.docs/guides/guide/ai-recruiter.md +226 -0
- package/.docs/guides/guide/chef-michel.md +211 -0
- package/.docs/guides/guide/code-review-bot.md +226 -0
- package/.docs/guides/guide/dev-assistant.md +307 -0
- package/.docs/guides/guide/docs-manager.md +238 -0
- package/.docs/guides/guide/github-actions-pr-description.md +236 -0
- package/.docs/guides/guide/notes-mcp-server.md +416 -0
- package/.docs/guides/guide/research-assistant.md +348 -0
- package/.docs/guides/guide/research-coordinator.md +416 -0
- package/.docs/guides/guide/stock-agent.md +132 -0
- package/.docs/guides/guide/web-search.md +320 -0
- package/.docs/guides/guide/whatsapp-chat-bot.md +405 -0
- package/.docs/guides/index.md +3 -0
- package/.docs/guides/migrations/agentnetwork.md +97 -0
- package/.docs/guides/migrations/ai-sdk-v4-to-v5.md +112 -0
- package/.docs/guides/migrations/network-to-supervisor.md +261 -0
- package/.docs/guides/migrations/upgrade-to-v1/agent.md +404 -0
- package/.docs/guides/migrations/upgrade-to-v1/cli.md +57 -0
- package/.docs/guides/migrations/upgrade-to-v1/client.md +337 -0
- package/.docs/guides/migrations/upgrade-to-v1/deployment.md +37 -0
- package/.docs/guides/migrations/upgrade-to-v1/evals.md +239 -0
- package/.docs/guides/migrations/upgrade-to-v1/mastra.md +143 -0
- package/.docs/guides/migrations/upgrade-to-v1/mcp.md +97 -0
- package/.docs/guides/migrations/upgrade-to-v1/memory.md +285 -0
- package/.docs/guides/migrations/upgrade-to-v1/overview.md +119 -0
- package/.docs/guides/migrations/upgrade-to-v1/processors.md +68 -0
- package/.docs/guides/migrations/upgrade-to-v1/rag.md +42 -0
- package/.docs/guides/migrations/upgrade-to-v1/storage.md +553 -0
- package/.docs/guides/migrations/upgrade-to-v1/tools.md +180 -0
- package/.docs/guides/migrations/upgrade-to-v1/tracing.md +412 -0
- package/.docs/guides/migrations/upgrade-to-v1/vectors.md +87 -0
- package/.docs/guides/migrations/upgrade-to-v1/voice.md +30 -0
- package/.docs/guides/migrations/upgrade-to-v1/workflows.md +341 -0
- package/.docs/guides/migrations/vnext-to-standard-apis.md +362 -0
- package/.docs/models/embeddings.md +161 -0
- package/.docs/models/gateways/azure-openai.md +128 -0
- package/.docs/models/gateways/custom-gateways.md +545 -0
- package/.docs/models/gateways/netlify.md +88 -0
- package/.docs/models/gateways/openrouter.md +219 -0
- package/.docs/models/gateways/vercel.md +225 -0
- package/.docs/models/gateways.md +14 -0
- package/.docs/models/index.md +286 -0
- package/.docs/models/providers/302ai.md +134 -0
- package/.docs/models/providers/abacus.md +125 -0
- package/.docs/models/providers/agentrouter.md +90 -0
- package/.docs/models/providers/aihubmix.md +107 -0
- package/.docs/models/providers/alibaba-cn.md +135 -0
- package/.docs/models/providers/alibaba.md +111 -0
- package/.docs/models/providers/amazon-bedrock.md +33 -0
- package/.docs/models/providers/anthropic.md +153 -0
- package/.docs/models/providers/azure.md +33 -0
- package/.docs/models/providers/bailing.md +72 -0
- package/.docs/models/providers/baseten.md +77 -0
- package/.docs/models/providers/berget.md +78 -0
- package/.docs/models/providers/cerebras.md +101 -0
- package/.docs/models/providers/chutes.md +136 -0
- package/.docs/models/providers/cloudflare-ai-gateway.md +33 -0
- package/.docs/models/providers/cloudflare-workers-ai.md +109 -0
- package/.docs/models/providers/cohere.md +33 -0
- package/.docs/models/providers/cortecs.md +91 -0
- package/.docs/models/providers/deepinfra.md +112 -0
- package/.docs/models/providers/deepseek.md +88 -0
- package/.docs/models/providers/fastrouter.md +84 -0
- package/.docs/models/providers/fireworks-ai.md +89 -0
- package/.docs/models/providers/firmware.md +85 -0
- package/.docs/models/providers/friendli.md +78 -0
- package/.docs/models/providers/github-models.md +125 -0
- package/.docs/models/providers/google-vertex.md +33 -0
- package/.docs/models/providers/google.md +159 -0
- package/.docs/models/providers/groq.md +107 -0
- package/.docs/models/providers/helicone.md +161 -0
- package/.docs/models/providers/huggingface.md +90 -0
- package/.docs/models/providers/iflowcn.md +84 -0
- package/.docs/models/providers/inception.md +72 -0
- package/.docs/models/providers/inference.md +79 -0
- package/.docs/models/providers/io-intelligence.md +87 -0
- package/.docs/models/providers/io-net.md +87 -0
- package/.docs/models/providers/jiekou.md +131 -0
- package/.docs/models/providers/kilo.md +333 -0
- package/.docs/models/providers/kimi-for-coding.md +100 -0
- package/.docs/models/providers/kuae-cloud-coding-plan.md +71 -0
- package/.docs/models/providers/llama.md +77 -0
- package/.docs/models/providers/lmstudio.md +73 -0
- package/.docs/models/providers/lucidquery.md +72 -0
- package/.docs/models/providers/minimax-cn-coding-plan.md +102 -0
- package/.docs/models/providers/minimax-cn.md +102 -0
- package/.docs/models/providers/minimax-coding-plan.md +102 -0
- package/.docs/models/providers/minimax.md +104 -0
- package/.docs/models/providers/mistral.md +124 -0
- package/.docs/models/providers/moark.md +72 -0
- package/.docs/models/providers/modelscope.md +77 -0
- package/.docs/models/providers/moonshotai-cn.md +76 -0
- package/.docs/models/providers/moonshotai.md +76 -0
- package/.docs/models/providers/morph.md +73 -0
- package/.docs/models/providers/nano-gpt.md +103 -0
- package/.docs/models/providers/nebius.md +116 -0
- package/.docs/models/providers/nova.md +72 -0
- package/.docs/models/providers/novita-ai.md +154 -0
- package/.docs/models/providers/nvidia.md +141 -0
- package/.docs/models/providers/ollama-cloud.md +103 -0
- package/.docs/models/providers/ollama.md +33 -0
- package/.docs/models/providers/openai.md +193 -0
- package/.docs/models/providers/opencode.md +100 -0
- package/.docs/models/providers/ovhcloud.md +83 -0
- package/.docs/models/providers/perplexity.md +100 -0
- package/.docs/models/providers/poe.md +183 -0
- package/.docs/models/providers/privatemode-ai.md +75 -0
- package/.docs/models/providers/requesty.md +90 -0
- package/.docs/models/providers/scaleway.md +84 -0
- package/.docs/models/providers/siliconflow-cn.md +138 -0
- package/.docs/models/providers/siliconflow.md +140 -0
- package/.docs/models/providers/stackit.md +78 -0
- package/.docs/models/providers/stepfun.md +73 -0
- package/.docs/models/providers/submodel.md +79 -0
- package/.docs/models/providers/synthetic.md +96 -0
- package/.docs/models/providers/togetherai.md +115 -0
- package/.docs/models/providers/upstage.md +73 -0
- package/.docs/models/providers/venice.md +95 -0
- package/.docs/models/providers/vivgrid.md +106 -0
- package/.docs/models/providers/vultr.md +75 -0
- package/.docs/models/providers/wandb.md +80 -0
- package/.docs/models/providers/xai.md +141 -0
- package/.docs/models/providers/xiaomi.md +71 -0
- package/.docs/models/providers/zai-coding-plan.md +80 -0
- package/.docs/models/providers/zai.md +79 -0
- package/.docs/models/providers/zenmux.md +161 -0
- package/.docs/models/providers/zhipuai-coding-plan.md +79 -0
- package/.docs/models/providers/zhipuai.md +79 -0
- package/.docs/models/providers.md +81 -0
- package/.docs/reference/agents/agent.md +141 -0
- package/.docs/reference/agents/generate.md +186 -0
- package/.docs/reference/agents/generateLegacy.md +173 -0
- package/.docs/reference/agents/getDefaultGenerateOptions.md +36 -0
- package/.docs/reference/agents/getDefaultOptions.md +34 -0
- package/.docs/reference/agents/getDefaultStreamOptions.md +36 -0
- package/.docs/reference/agents/getDescription.md +21 -0
- package/.docs/reference/agents/getInstructions.md +34 -0
- package/.docs/reference/agents/getLLM.md +37 -0
- package/.docs/reference/agents/getMemory.md +34 -0
- package/.docs/reference/agents/getModel.md +34 -0
- package/.docs/reference/agents/getTools.md +29 -0
- package/.docs/reference/agents/getVoice.md +34 -0
- package/.docs/reference/agents/listAgents.md +35 -0
- package/.docs/reference/agents/listScorers.md +34 -0
- package/.docs/reference/agents/listTools.md +34 -0
- package/.docs/reference/agents/listWorkflows.md +34 -0
- package/.docs/reference/agents/network.md +133 -0
- package/.docs/reference/ai-sdk/chat-route.md +82 -0
- package/.docs/reference/ai-sdk/handle-chat-stream.md +53 -0
- package/.docs/reference/ai-sdk/handle-network-stream.md +37 -0
- package/.docs/reference/ai-sdk/handle-workflow-stream.md +55 -0
- package/.docs/reference/ai-sdk/network-route.md +74 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-stream.md +231 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-v4-messages.md +79 -0
- package/.docs/reference/ai-sdk/to-ai-sdk-v5-messages.md +76 -0
- package/.docs/reference/ai-sdk/with-mastra.md +59 -0
- package/.docs/reference/ai-sdk/workflow-route.md +79 -0
- package/.docs/reference/auth/auth0.md +73 -0
- package/.docs/reference/auth/better-auth.md +71 -0
- package/.docs/reference/auth/clerk.md +36 -0
- package/.docs/reference/auth/firebase.md +80 -0
- package/.docs/reference/auth/jwt.md +26 -0
- package/.docs/reference/auth/supabase.md +33 -0
- package/.docs/reference/auth/workos.md +84 -0
- package/.docs/reference/cli/create-mastra.md +137 -0
- package/.docs/reference/cli/mastra.md +336 -0
- package/.docs/reference/client-js/agents.md +437 -0
- package/.docs/reference/client-js/error-handling.md +16 -0
- package/.docs/reference/client-js/logs.md +24 -0
- package/.docs/reference/client-js/mastra-client.md +63 -0
- package/.docs/reference/client-js/memory.md +221 -0
- package/.docs/reference/client-js/observability.md +72 -0
- package/.docs/reference/client-js/telemetry.md +20 -0
- package/.docs/reference/client-js/tools.md +44 -0
- package/.docs/reference/client-js/vectors.md +79 -0
- package/.docs/reference/client-js/workflows.md +199 -0
- package/.docs/reference/configuration.md +752 -0
- package/.docs/reference/core/addGateway.md +42 -0
- package/.docs/reference/core/getAgent.md +21 -0
- package/.docs/reference/core/getAgentById.md +21 -0
- package/.docs/reference/core/getDeployer.md +22 -0
- package/.docs/reference/core/getGateway.md +38 -0
- package/.docs/reference/core/getGatewayById.md +41 -0
- package/.docs/reference/core/getLogger.md +22 -0
- package/.docs/reference/core/getMCPServer.md +47 -0
- package/.docs/reference/core/getMCPServerById.md +55 -0
- package/.docs/reference/core/getMemory.md +50 -0
- package/.docs/reference/core/getScorer.md +54 -0
- package/.docs/reference/core/getScorerById.md +54 -0
- package/.docs/reference/core/getServer.md +22 -0
- package/.docs/reference/core/getStorage.md +22 -0
- package/.docs/reference/core/getStoredAgentById.md +89 -0
- package/.docs/reference/core/getTelemetry.md +22 -0
- package/.docs/reference/core/getVector.md +22 -0
- package/.docs/reference/core/getWorkflow.md +42 -0
- package/.docs/reference/core/listAgents.md +21 -0
- package/.docs/reference/core/listGateways.md +40 -0
- package/.docs/reference/core/listLogs.md +38 -0
- package/.docs/reference/core/listLogsByRunId.md +36 -0
- package/.docs/reference/core/listMCPServers.md +55 -0
- package/.docs/reference/core/listMemory.md +56 -0
- package/.docs/reference/core/listScorers.md +29 -0
- package/.docs/reference/core/listStoredAgents.md +93 -0
- package/.docs/reference/core/listVectors.md +22 -0
- package/.docs/reference/core/listWorkflows.md +21 -0
- package/.docs/reference/core/mastra-class.md +66 -0
- package/.docs/reference/core/mastra-model-gateway.md +153 -0
- package/.docs/reference/core/setLogger.md +26 -0
- package/.docs/reference/core/setStorage.md +27 -0
- package/.docs/reference/datasets/addItem.md +37 -0
- package/.docs/reference/datasets/addItems.md +35 -0
- package/.docs/reference/datasets/compareExperiments.md +52 -0
- package/.docs/reference/datasets/create.md +51 -0
- package/.docs/reference/datasets/dataset.md +82 -0
- package/.docs/reference/datasets/datasets-manager.md +94 -0
- package/.docs/reference/datasets/delete.md +25 -0
- package/.docs/reference/datasets/deleteExperiment.md +27 -0
- package/.docs/reference/datasets/deleteItem.md +27 -0
- package/.docs/reference/datasets/deleteItems.md +29 -0
- package/.docs/reference/datasets/get.md +31 -0
- package/.docs/reference/datasets/getDetails.md +47 -0
- package/.docs/reference/datasets/getExperiment.md +30 -0
- package/.docs/reference/datasets/getItem.md +33 -0
- package/.docs/reference/datasets/getItemHistory.md +31 -0
- package/.docs/reference/datasets/list.md +31 -0
- package/.docs/reference/datasets/listExperimentResults.md +39 -0
- package/.docs/reference/datasets/listExperiments.md +33 -0
- package/.docs/reference/datasets/listItems.md +46 -0
- package/.docs/reference/datasets/listVersions.md +33 -0
- package/.docs/reference/datasets/startExperiment.md +62 -0
- package/.docs/reference/datasets/startExperimentAsync.md +43 -0
- package/.docs/reference/datasets/update.md +48 -0
- package/.docs/reference/datasets/updateItem.md +38 -0
- package/.docs/reference/deployer/cloudflare.md +79 -0
- package/.docs/reference/deployer/netlify.md +80 -0
- package/.docs/reference/deployer/vercel.md +91 -0
- package/.docs/reference/deployer.md +100 -0
- package/.docs/reference/evals/answer-relevancy.md +105 -0
- package/.docs/reference/evals/answer-similarity.md +99 -0
- package/.docs/reference/evals/bias.md +120 -0
- package/.docs/reference/evals/completeness.md +136 -0
- package/.docs/reference/evals/content-similarity.md +101 -0
- package/.docs/reference/evals/context-precision.md +196 -0
- package/.docs/reference/evals/context-relevance.md +531 -0
- package/.docs/reference/evals/create-scorer.md +270 -0
- package/.docs/reference/evals/faithfulness.md +114 -0
- package/.docs/reference/evals/hallucination.md +213 -0
- package/.docs/reference/evals/keyword-coverage.md +128 -0
- package/.docs/reference/evals/mastra-scorer.md +123 -0
- package/.docs/reference/evals/noise-sensitivity.md +675 -0
- package/.docs/reference/evals/prompt-alignment.md +614 -0
- package/.docs/reference/evals/run-evals.md +179 -0
- package/.docs/reference/evals/scorer-utils.md +326 -0
- package/.docs/reference/evals/textual-difference.md +113 -0
- package/.docs/reference/evals/tone-consistency.md +119 -0
- package/.docs/reference/evals/tool-call-accuracy.md +533 -0
- package/.docs/reference/evals/toxicity.md +123 -0
- package/.docs/reference/harness/harness-class.md +708 -0
- package/.docs/reference/index.md +277 -0
- package/.docs/reference/logging/pino-logger.md +117 -0
- package/.docs/reference/mastra-code/createMastraCode.md +108 -0
- package/.docs/reference/memory/clone-utilities.md +199 -0
- package/.docs/reference/memory/cloneThread.md +130 -0
- package/.docs/reference/memory/createThread.md +68 -0
- package/.docs/reference/memory/deleteMessages.md +38 -0
- package/.docs/reference/memory/getThreadById.md +24 -0
- package/.docs/reference/memory/listThreads.md +145 -0
- package/.docs/reference/memory/memory-class.md +147 -0
- package/.docs/reference/memory/observational-memory.md +565 -0
- package/.docs/reference/memory/recall.md +91 -0
- package/.docs/reference/observability/tracing/bridges/otel.md +131 -0
- package/.docs/reference/observability/tracing/configuration.md +178 -0
- package/.docs/reference/observability/tracing/exporters/arize.md +141 -0
- package/.docs/reference/observability/tracing/exporters/braintrust.md +93 -0
- package/.docs/reference/observability/tracing/exporters/cloud-exporter.md +163 -0
- package/.docs/reference/observability/tracing/exporters/console-exporter.md +138 -0
- package/.docs/reference/observability/tracing/exporters/datadog.md +116 -0
- package/.docs/reference/observability/tracing/exporters/default-exporter.md +174 -0
- package/.docs/reference/observability/tracing/exporters/laminar.md +78 -0
- package/.docs/reference/observability/tracing/exporters/langfuse.md +134 -0
- package/.docs/reference/observability/tracing/exporters/langsmith.md +108 -0
- package/.docs/reference/observability/tracing/exporters/otel.md +199 -0
- package/.docs/reference/observability/tracing/exporters/posthog.md +92 -0
- package/.docs/reference/observability/tracing/exporters/sentry.md +184 -0
- package/.docs/reference/observability/tracing/instances.md +107 -0
- package/.docs/reference/observability/tracing/interfaces.md +743 -0
- package/.docs/reference/observability/tracing/processors/sensitive-data-filter.md +144 -0
- package/.docs/reference/observability/tracing/spans.md +224 -0
- package/.docs/reference/processors/batch-parts-processor.md +61 -0
- package/.docs/reference/processors/language-detector.md +82 -0
- package/.docs/reference/processors/message-history-processor.md +85 -0
- package/.docs/reference/processors/moderation-processor.md +104 -0
- package/.docs/reference/processors/pii-detector.md +108 -0
- package/.docs/reference/processors/processor-interface.md +521 -0
- package/.docs/reference/processors/prompt-injection-detector.md +72 -0
- package/.docs/reference/processors/semantic-recall-processor.md +117 -0
- package/.docs/reference/processors/system-prompt-scrubber.md +80 -0
- package/.docs/reference/processors/token-limiter-processor.md +115 -0
- package/.docs/reference/processors/tool-call-filter.md +85 -0
- package/.docs/reference/processors/tool-search-processor.md +111 -0
- package/.docs/reference/processors/unicode-normalizer.md +62 -0
- package/.docs/reference/processors/working-memory-processor.md +152 -0
- package/.docs/reference/rag/chunk.md +221 -0
- package/.docs/reference/rag/database-config.md +261 -0
- package/.docs/reference/rag/document.md +114 -0
- package/.docs/reference/rag/embeddings.md +92 -0
- package/.docs/reference/rag/extract-params.md +168 -0
- package/.docs/reference/rag/graph-rag.md +111 -0
- package/.docs/reference/rag/metadata-filters.md +216 -0
- package/.docs/reference/rag/rerank.md +75 -0
- package/.docs/reference/rag/rerankWithScorer.md +80 -0
- package/.docs/reference/server/create-route.md +262 -0
- package/.docs/reference/server/express-adapter.md +176 -0
- package/.docs/reference/server/fastify-adapter.md +90 -0
- package/.docs/reference/server/hono-adapter.md +162 -0
- package/.docs/reference/server/koa-adapter.md +127 -0
- package/.docs/reference/server/mastra-server.md +298 -0
- package/.docs/reference/server/register-api-route.md +249 -0
- package/.docs/reference/server/routes.md +306 -0
- package/.docs/reference/storage/cloudflare-d1.md +218 -0
- package/.docs/reference/storage/cloudflare.md +88 -0
- package/.docs/reference/storage/composite.md +235 -0
- package/.docs/reference/storage/convex.md +161 -0
- package/.docs/reference/storage/dynamodb.md +282 -0
- package/.docs/reference/storage/lance.md +131 -0
- package/.docs/reference/storage/libsql.md +135 -0
- package/.docs/reference/storage/mongodb.md +262 -0
- package/.docs/reference/storage/mssql.md +157 -0
- package/.docs/reference/storage/overview.md +121 -0
- package/.docs/reference/storage/postgresql.md +526 -0
- package/.docs/reference/storage/upstash.md +160 -0
- package/.docs/reference/streaming/ChunkType.md +292 -0
- package/.docs/reference/streaming/agents/MastraModelOutput.md +182 -0
- package/.docs/reference/streaming/agents/stream.md +221 -0
- package/.docs/reference/streaming/agents/streamLegacy.md +142 -0
- package/.docs/reference/streaming/workflows/observeStream.md +42 -0
- package/.docs/reference/streaming/workflows/resumeStream.md +61 -0
- package/.docs/reference/streaming/workflows/stream.md +88 -0
- package/.docs/reference/streaming/workflows/timeTravelStream.md +142 -0
- package/.docs/reference/templates/overview.md +194 -0
- package/.docs/reference/tools/create-tool.md +237 -0
- package/.docs/reference/tools/document-chunker-tool.md +89 -0
- package/.docs/reference/tools/graph-rag-tool.md +182 -0
- package/.docs/reference/tools/mcp-client.md +954 -0
- package/.docs/reference/tools/mcp-server.md +1271 -0
- package/.docs/reference/tools/vector-query-tool.md +459 -0
- package/.docs/reference/vectors/astra.md +121 -0
- package/.docs/reference/vectors/chroma.md +264 -0
- package/.docs/reference/vectors/convex.md +300 -0
- package/.docs/reference/vectors/couchbase.md +226 -0
- package/.docs/reference/vectors/duckdb.md +318 -0
- package/.docs/reference/vectors/elasticsearch.md +189 -0
- package/.docs/reference/vectors/lance.md +220 -0
- package/.docs/reference/vectors/libsql.md +305 -0
- package/.docs/reference/vectors/mongodb.md +295 -0
- package/.docs/reference/vectors/opensearch.md +99 -0
- package/.docs/reference/vectors/pg.md +408 -0
- package/.docs/reference/vectors/pinecone.md +168 -0
- package/.docs/reference/vectors/qdrant.md +222 -0
- package/.docs/reference/vectors/s3vectors.md +277 -0
- package/.docs/reference/vectors/turbopuffer.md +157 -0
- package/.docs/reference/vectors/upstash.md +294 -0
- package/.docs/reference/vectors/vectorize.md +147 -0
- package/.docs/reference/voice/azure.md +148 -0
- package/.docs/reference/voice/cloudflare.md +83 -0
- package/.docs/reference/voice/composite-voice.md +121 -0
- package/.docs/reference/voice/deepgram.md +79 -0
- package/.docs/reference/voice/elevenlabs.md +98 -0
- package/.docs/reference/voice/google-gemini-live.md +378 -0
- package/.docs/reference/voice/google.md +228 -0
- package/.docs/reference/voice/mastra-voice.md +311 -0
- package/.docs/reference/voice/murf.md +122 -0
- package/.docs/reference/voice/openai-realtime.md +203 -0
- package/.docs/reference/voice/openai.md +88 -0
- package/.docs/reference/voice/playai.md +80 -0
- package/.docs/reference/voice/sarvam.md +126 -0
- package/.docs/reference/voice/speechify.md +75 -0
- package/.docs/reference/voice/voice.addInstructions.md +55 -0
- package/.docs/reference/voice/voice.addTools.md +67 -0
- package/.docs/reference/voice/voice.answer.md +54 -0
- package/.docs/reference/voice/voice.close.md +51 -0
- package/.docs/reference/voice/voice.connect.md +94 -0
- package/.docs/reference/voice/voice.events.md +37 -0
- package/.docs/reference/voice/voice.getSpeakers.md +129 -0
- package/.docs/reference/voice/voice.listen.md +164 -0
- package/.docs/reference/voice/voice.off.md +54 -0
- package/.docs/reference/voice/voice.on.md +111 -0
- package/.docs/reference/voice/voice.send.md +65 -0
- package/.docs/reference/voice/voice.speak.md +157 -0
- package/.docs/reference/voice/voice.updateConfig.md +60 -0
- package/.docs/reference/workflows/run-methods/cancel.md +86 -0
- package/.docs/reference/workflows/run-methods/restart.md +33 -0
- package/.docs/reference/workflows/run-methods/resume.md +59 -0
- package/.docs/reference/workflows/run-methods/start.md +58 -0
- package/.docs/reference/workflows/run-methods/startAsync.md +67 -0
- package/.docs/reference/workflows/run-methods/timeTravel.md +142 -0
- package/.docs/reference/workflows/run.md +59 -0
- package/.docs/reference/workflows/step.md +119 -0
- package/.docs/reference/workflows/workflow-methods/branch.md +25 -0
- package/.docs/reference/workflows/workflow-methods/commit.md +17 -0
- package/.docs/reference/workflows/workflow-methods/create-run.md +63 -0
- package/.docs/reference/workflows/workflow-methods/dountil.md +25 -0
- package/.docs/reference/workflows/workflow-methods/dowhile.md +25 -0
- package/.docs/reference/workflows/workflow-methods/foreach.md +118 -0
- package/.docs/reference/workflows/workflow-methods/map.md +93 -0
- package/.docs/reference/workflows/workflow-methods/parallel.md +21 -0
- package/.docs/reference/workflows/workflow-methods/sleep.md +35 -0
- package/.docs/reference/workflows/workflow-methods/sleepUntil.md +35 -0
- package/.docs/reference/workflows/workflow-methods/then.md +21 -0
- package/.docs/reference/workflows/workflow.md +157 -0
- package/.docs/reference/workspace/e2b-sandbox.md +289 -0
- package/.docs/reference/workspace/filesystem.md +255 -0
- package/.docs/reference/workspace/gcs-filesystem.md +174 -0
- package/.docs/reference/workspace/local-filesystem.md +343 -0
- package/.docs/reference/workspace/local-sandbox.md +301 -0
- package/.docs/reference/workspace/s3-filesystem.md +175 -0
- package/.docs/reference/workspace/sandbox.md +87 -0
- package/.docs/reference/workspace/workspace-class.md +244 -0
- package/CHANGELOG.md +8 -0
- package/package.json +5 -5
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
# Integrate Mastra in your SvelteKit project
|
|
2
|
+
|
|
3
|
+
In this guide, you'll build a tool-calling AI agent using Mastra, then connect it to SvelteKit by importing and calling the agent directly from your routes.
|
|
4
|
+
|
|
5
|
+
You'll use [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) to create a beautiful, interactive chat experience.
|
|
6
|
+
|
|
7
|
+
## Before you begin
|
|
8
|
+
|
|
9
|
+
- You'll need an API key from a supported [model provider](https://mastra.ai/models). If you don't have a preference, use [OpenAI](https://mastra.ai/models/providers/openai).
|
|
10
|
+
- Install Node.js `v22.13.0` or later
|
|
11
|
+
|
|
12
|
+
## Create a new SvelteKit app (optional)
|
|
13
|
+
|
|
14
|
+
If you already have a SvelteKit app using Tailwind, skip to the next step.
|
|
15
|
+
|
|
16
|
+
Run the following command to [create a new SvelteKit app](https://svelte.dev/docs/kit/creating-a-project):
|
|
17
|
+
|
|
18
|
+
**npm**:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx sv create mastra-svelte --template minimal --types ts --add tailwindcss="plugins:forms" --install npm
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**pnpm**:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pnpm dlx sv create mastra-svelte --template minimal --types ts --add tailwindcss="plugins:forms" --install npm
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Yarn**:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
yarn dlx sv create mastra-svelte --template minimal --types ts --add tailwindcss="plugins:forms" --install npm
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Bun**:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
bun x sv create mastra-svelte --template minimal --types ts --add tailwindcss="plugins:forms" --install npm
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This creates a project called `mastra-svelte`, but you can replace it with any name you want. Tailwind was added for styling purposes later on.
|
|
43
|
+
|
|
44
|
+
## Initialize Mastra
|
|
45
|
+
|
|
46
|
+
Navigate to your SvelteKit project:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
cd mastra-svelte
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Run [`mastra init`](https://mastra.ai/reference/cli/mastra). When prompted, choose a provider (e.g. OpenAI) and enter your key:
|
|
53
|
+
|
|
54
|
+
**npm**:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npx mastra@latest init
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**pnpm**:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pnpm dlx mastra@latest init
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Yarn**:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
yarn dlx mastra@latest init
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Bun**:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
bun x mastra@latest init
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
This creates a `src/mastra` folder with an example weather agent and the following files:
|
|
79
|
+
|
|
80
|
+
- `index.ts` - Mastra config, including memory
|
|
81
|
+
- `tools/weather-tool.ts` - a tool to fetch weather for a given location
|
|
82
|
+
- `agents/weather-agent.ts`- a weather agent with a prompt that uses the tool
|
|
83
|
+
|
|
84
|
+
You'll call `weather-agent.ts` from your SvelteKit routes in the next steps.
|
|
85
|
+
|
|
86
|
+
## Install AI SDK UI
|
|
87
|
+
|
|
88
|
+
Install AI SDK UI along with the Mastra adapter:
|
|
89
|
+
|
|
90
|
+
**npm**:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm install @mastra/ai-sdk@latest @ai-sdk/svelte ai
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**pnpm**:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pnpm add @mastra/ai-sdk@latest @ai-sdk/svelte ai
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Yarn**:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
yarn add @mastra/ai-sdk@latest @ai-sdk/svelte ai
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Bun**:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
bun add @mastra/ai-sdk@latest @ai-sdk/svelte ai
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Create a chat route
|
|
115
|
+
|
|
116
|
+
Create `src/routes/api/chat/+server.ts`:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import type { RequestHandler } from './$types'
|
|
120
|
+
import { handleChatStream } from '@mastra/ai-sdk'
|
|
121
|
+
import { toAISdkV5Messages } from '@mastra/ai-sdk/ui'
|
|
122
|
+
import { createUIMessageStreamResponse } from 'ai'
|
|
123
|
+
import { mastra } from '../../../mastra'
|
|
124
|
+
|
|
125
|
+
const THREAD_ID = 'example-user-id'
|
|
126
|
+
const RESOURCE_ID = 'weather-chat'
|
|
127
|
+
|
|
128
|
+
export const POST: RequestHandler = async ({ request }) => {
|
|
129
|
+
const params = await request.json()
|
|
130
|
+
const stream = await handleChatStream({
|
|
131
|
+
mastra,
|
|
132
|
+
agentId: 'weather-agent',
|
|
133
|
+
params: {
|
|
134
|
+
...params,
|
|
135
|
+
memory: {
|
|
136
|
+
...params.memory,
|
|
137
|
+
thread: THREAD_ID,
|
|
138
|
+
resource: RESOURCE_ID,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
return createUIMessageStreamResponse({ stream })
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export const GET: RequestHandler = async () => {
|
|
147
|
+
const memory = await mastra.getAgentById('weather-agent').getMemory()
|
|
148
|
+
let response = null
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
response = await memory?.recall({
|
|
152
|
+
threadId: THREAD_ID,
|
|
153
|
+
resourceId: RESOURCE_ID,
|
|
154
|
+
})
|
|
155
|
+
} catch {
|
|
156
|
+
console.log('No previous messages found.')
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const uiMessages = toAISdkV5Messages(response?.messages || [])
|
|
160
|
+
|
|
161
|
+
return Response.json(uiMessages)
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The `POST` route accepts a prompt and streams the agent's response back in AI SDK format, while the `GET` route fetches message history from memory so the UI can be hydrated when the client reloads.
|
|
166
|
+
|
|
167
|
+
In order for the `GET` handler to be called, you need to create a `src/routes/+page.ts` file. Its `load()` function runs alongside `+page.svelte`.
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
import type { UIDataTypes, UIMessage, UITools } from 'ai'
|
|
171
|
+
import type { PageLoad } from './$types'
|
|
172
|
+
|
|
173
|
+
export const load: PageLoad = async ({ fetch }) => {
|
|
174
|
+
const response = await fetch('/api/chat')
|
|
175
|
+
const initialMessages = (await response.json()) as UIMessage<unknown, UIDataTypes, UITools>[]
|
|
176
|
+
return { initialMessages }
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Add the chat UI
|
|
181
|
+
|
|
182
|
+
Replace `src/routes/+page.svelte` with the following.
|
|
183
|
+
|
|
184
|
+
```svelte
|
|
185
|
+
<script lang="ts">
|
|
186
|
+
import { Chat } from '@ai-sdk/svelte';
|
|
187
|
+
import { DefaultChatTransport, type ToolUIPart } from 'ai';
|
|
188
|
+
|
|
189
|
+
let input = $state('');
|
|
190
|
+
const { data } = $props();
|
|
191
|
+
let messages = $derived(data.initialMessages)
|
|
192
|
+
|
|
193
|
+
const chat = new Chat({
|
|
194
|
+
transport: new DefaultChatTransport({
|
|
195
|
+
api: '/api/chat'
|
|
196
|
+
}),
|
|
197
|
+
get messages() {
|
|
198
|
+
return messages;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
function handleSubmit(event: SubmitEvent) {
|
|
203
|
+
event.preventDefault();
|
|
204
|
+
chat.sendMessage({ text: input });
|
|
205
|
+
input = '';
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const STATE_TO_LABEL_MAP: Record<ToolUIPart["state"], string> = {
|
|
209
|
+
"input-streaming": "Pending",
|
|
210
|
+
"input-available": "Running",
|
|
211
|
+
// @ts-expect-error - Only available in AI SDK v6
|
|
212
|
+
"approval-requested": "Awaiting Approval",
|
|
213
|
+
"approval-responded": "Responded",
|
|
214
|
+
"output-available": "Completed",
|
|
215
|
+
"output-error": "Error",
|
|
216
|
+
"output-denied": "Denied",
|
|
217
|
+
};
|
|
218
|
+
</script>
|
|
219
|
+
|
|
220
|
+
<main class="max-w-3xl mx-auto p-6 size-full h-screen">
|
|
221
|
+
<div class="flex flex-col h-full">
|
|
222
|
+
<div class="flex-1 min-h-0 overflow-y-auto" data-name="conversation">
|
|
223
|
+
<div data-name="conversation-content" class="flex flex-col gap-8">
|
|
224
|
+
{#each chat.messages as message, messageIndex (messageIndex)}
|
|
225
|
+
<div>
|
|
226
|
+
{#each message.parts as part, partIndex (partIndex)}
|
|
227
|
+
{#if part.type === 'text'}
|
|
228
|
+
<div data-name="message" class={[message.role === 'user' && 'ml-auto justify-end', 'group flex w-full max-w-[95%] flex-col gap-2', message.role === 'user' ? 'is-user' : 'is-assistant']}>
|
|
229
|
+
<div data-name="message-content" class={["is-user:dark flex w-fit max-w-full min-w-0 flex-col gap-2 overflow-hidden text-sm",
|
|
230
|
+
"group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-blue-100 group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground",
|
|
231
|
+
"group-[.is-assistant]:text-foreground"]}>
|
|
232
|
+
<div data-name="message-response" class="size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0">
|
|
233
|
+
{part.text}
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
</div>
|
|
237
|
+
{:else if part.type.startsWith('tool-')}
|
|
238
|
+
<div data-name="tool" class="not-prose mb-6 w-full rounded-lg border border-gray-300 shadow">
|
|
239
|
+
<details data-name="tool-header" class="w-full p-3 hover:cursor-pointer">
|
|
240
|
+
<summary class="font-medium text-sm">{(part as ToolUIPart).type.split("-").slice(1).join("-")} - {STATE_TO_LABEL_MAP[(part as ToolUIPart).state ?? 'output-available']}</summary>
|
|
241
|
+
<div data-name="tool-content" class="">
|
|
242
|
+
<div data-name="tool-input" class="space-y-2 overflow-hidden py-4">
|
|
243
|
+
<div class="font-medium text-muted-foreground text-xs uppercase tracking-wide">Parameters</div>
|
|
244
|
+
<pre class="w-full overflow-x-auto rounded-md border border-gray-300 bg-gray-50 p-3 text-sm"><code>{JSON.stringify((part as ToolUIPart).input, null, 2)}</code></pre>
|
|
245
|
+
</div>
|
|
246
|
+
<div data-name="tool-output" class="space-y-2 overflow-hidden py-4">
|
|
247
|
+
<div class="font-medium text-muted-foreground text-xs uppercase tracking-wide">{(part as ToolUIPart).errorText ? 'Error' : 'Result'}</div>
|
|
248
|
+
<pre class="w-full overflow-x-auto rounded-md border border-gray-300 bg-gray-50 p-3 text-sm"><code>{JSON.stringify((part as ToolUIPart).output, null, 2)}</code></pre>
|
|
249
|
+
{#if (part as ToolUIPart).errorText}
|
|
250
|
+
<div data-name="tool-error" class="text-red-600">
|
|
251
|
+
{(part as ToolUIPart).errorText}
|
|
252
|
+
</div>
|
|
253
|
+
{/if}
|
|
254
|
+
</div>
|
|
255
|
+
</div>
|
|
256
|
+
</details>
|
|
257
|
+
</div>
|
|
258
|
+
{/if}
|
|
259
|
+
{/each}
|
|
260
|
+
</div>
|
|
261
|
+
{/each}
|
|
262
|
+
</div>
|
|
263
|
+
</div>
|
|
264
|
+
<form class="w-full grid grid-cols-[1fr_auto] gap-6 shrink-0 pt-4" onsubmit={handleSubmit} data-name="prompt-input">
|
|
265
|
+
<input name="chat-input" class="rounded-lg border border-gray-300 shadow h-10" placeholder="City name" bind:value={input} />
|
|
266
|
+
<button class="bg-blue-600 text-white shadow-lg border border-blue-400 px-4 whitespace-nowrap rounded-lg text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]" type="submit">Send</button>
|
|
267
|
+
</form>
|
|
268
|
+
</div>
|
|
269
|
+
</main>
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
This page connects [`Chat`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) to the `api/chat` endpoint, sending prompts there and streaming the response back in chunks.
|
|
273
|
+
|
|
274
|
+
It renders the response text using custom message and tool components.
|
|
275
|
+
|
|
276
|
+
## Test your agent
|
|
277
|
+
|
|
278
|
+
1. Run your SvelteKit app with `npm run dev`
|
|
279
|
+
2. Open the chat at <http://localhost:5173>
|
|
280
|
+
3. Try asking about the weather. If your API key is set up correctly, you'll get a response
|
|
281
|
+
|
|
282
|
+
## Next steps
|
|
283
|
+
|
|
284
|
+
Congratulations on building your Mastra agent with SvelteKit! 🎉
|
|
285
|
+
|
|
286
|
+
From here, you can extend the project with your own tools and logic:
|
|
287
|
+
|
|
288
|
+
- Learn more about [agents](https://mastra.ai/docs/agents/overview)
|
|
289
|
+
- Give your agent its own [tools](https://mastra.ai/docs/agents/using-tools)
|
|
290
|
+
- Add human-like [memory](https://mastra.ai/docs/agents/agent-memory) to your agent
|
|
291
|
+
|
|
292
|
+
When you're ready, read more about how Mastra integrates with AI SDK UI and SvelteKit, and how to deploy your agent anywhere:
|
|
293
|
+
|
|
294
|
+
- Integrate Mastra with [AI SDK UI](https://mastra.ai/guides/build-your-ui/ai-sdk-ui)
|
|
295
|
+
- Deploy your agent [anywhere](https://mastra.ai/docs/deployment/overview)
|
|
296
|
+
- Try the [unofficial Svelte AI Elements](https://svelte-ai-elements.vercel.app/)
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
# Integrate Mastra in your React + Vite project
|
|
2
|
+
|
|
3
|
+
In this guide, you'll build a tool-calling AI agent using Mastra, then connect it to React by calling the agent directly from Mastra's standalone server.
|
|
4
|
+
|
|
5
|
+
You'll use [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) and [AI Elements](https://ai-sdk.dev/elements) to create a beautiful, interactive chat experience.
|
|
6
|
+
|
|
7
|
+
## Before you begin
|
|
8
|
+
|
|
9
|
+
- You'll need an API key from a supported [model provider](https://mastra.ai/models). If you don't have a preference, use [OpenAI](https://mastra.ai/models/providers/openai).
|
|
10
|
+
- Install Node.js `v22.13.0` or later
|
|
11
|
+
|
|
12
|
+
## Create a new React + Vite app (optional)
|
|
13
|
+
|
|
14
|
+
If you already have a React + Vite app using Tailwind, skip to the next step.
|
|
15
|
+
|
|
16
|
+
### Project scaffold
|
|
17
|
+
|
|
18
|
+
Run the following command to [create a new React + Vite app](https://vite.dev/guide/#scaffolding-your-first-vite-project):
|
|
19
|
+
|
|
20
|
+
**npm**:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm create vite@latest mastra-react -- --template react-ts
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**pnpm**:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm create vite mastra-react --template react-ts
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Yarn**:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
yarn create vite mastra-react --template react-ts
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Bun**:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
bunx create-vite mastra-react --template react-ts
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
This creates a project called `mastra-react`, but you can replace it with any name you want.
|
|
45
|
+
|
|
46
|
+
Navigate to your project directory:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
cd mastra-react
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Tailwind
|
|
53
|
+
|
|
54
|
+
Next, install Tailwind:
|
|
55
|
+
|
|
56
|
+
**npm**:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm install tailwindcss @tailwindcss/vite
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**pnpm**:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pnpm add tailwindcss @tailwindcss/vite
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Yarn**:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
yarn add tailwindcss @tailwindcss/vite
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Bun**:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
bun add tailwindcss @tailwindcss/vite
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Configure the Vite plugins:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { defineConfig } from 'vite'
|
|
84
|
+
import react from '@vitejs/plugin-react'
|
|
85
|
+
import path from 'path'
|
|
86
|
+
import tailwindcss from '@tailwindcss/vite'
|
|
87
|
+
|
|
88
|
+
export default defineConfig({
|
|
89
|
+
plugins: [react(), tailwindcss()],
|
|
90
|
+
resolve: {
|
|
91
|
+
alias: {
|
|
92
|
+
'@': path.resolve(__dirname, './src'),
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Replace everything in `src/index.css` with the following:
|
|
99
|
+
|
|
100
|
+
```css
|
|
101
|
+
@import 'tailwindcss';
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Add these `compilerOptions` to `tsconfig.json`:
|
|
105
|
+
|
|
106
|
+
```jsonc
|
|
107
|
+
{
|
|
108
|
+
// ...
|
|
109
|
+
"compilerOptions": {
|
|
110
|
+
"baseUrl": ".",
|
|
111
|
+
"paths": {
|
|
112
|
+
"@/*": ["./src/*"],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Edit `tsconfig.app.json` to resolve paths:
|
|
119
|
+
|
|
120
|
+
```jsonc
|
|
121
|
+
{
|
|
122
|
+
"compilerOptions": {
|
|
123
|
+
// ...
|
|
124
|
+
"baseUrl": ".",
|
|
125
|
+
"paths": {
|
|
126
|
+
"@/*": ["./src/*"],
|
|
127
|
+
},
|
|
128
|
+
// ...
|
|
129
|
+
},
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Initialize Mastra
|
|
134
|
+
|
|
135
|
+
Run [`mastra init`](https://mastra.ai/reference/cli/mastra). When prompted, choose a provider (e.g. OpenAI) and enter your key:
|
|
136
|
+
|
|
137
|
+
**npm**:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npx mastra@latest init
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**pnpm**:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
pnpm dlx mastra@latest init
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Yarn**:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
yarn dlx mastra@latest init
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Bun**:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
bun x mastra@latest init
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
This creates a `src/mastra` folder with an example weather agent and the following files:
|
|
162
|
+
|
|
163
|
+
- `index.ts` - Mastra config, including memory
|
|
164
|
+
- `tools/weather-tool.ts` - a tool to fetch weather for a given location
|
|
165
|
+
- `agents/weather-agent.ts`- a weather agent with a prompt that uses the tool
|
|
166
|
+
|
|
167
|
+
You'll call `weather-agent.ts` from your chat UI in the next steps.
|
|
168
|
+
|
|
169
|
+
## Install AI SDK UI & AI Elements
|
|
170
|
+
|
|
171
|
+
Install AI SDK UI along with the Mastra adapter:
|
|
172
|
+
|
|
173
|
+
**npm**:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
npm install @mastra/ai-sdk@latest @ai-sdk/react ai
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**pnpm**:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
pnpm add @mastra/ai-sdk@latest @ai-sdk/react ai
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**Yarn**:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
yarn add @mastra/ai-sdk@latest @ai-sdk/react ai
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Bun**:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
bun add @mastra/ai-sdk@latest @ai-sdk/react ai
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Next, initialize AI Elements. When prompted, choose the default options:
|
|
198
|
+
|
|
199
|
+
**npm**:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
npx ai-elements@latest
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**pnpm**:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
pnpm dlx ai-elements@latest
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**Yarn**:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
yarn dlx ai-elements@latest
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**Bun**:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
bun x ai-elements@latest
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
This downloads the entire AI Elements UI component library into a `@/components/ai-elements` folder.
|
|
224
|
+
|
|
225
|
+
## Create a chat route
|
|
226
|
+
|
|
227
|
+
Open `src/mastra/index.ts` and add a [chatRoute()](https://mastra.ai/reference/ai-sdk/chat-route) to your config. This creates an API route your React frontend can call for AI SDK-compatible chat responses, which you’ll use with useChat() next.
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
import { Mastra } from '@mastra/core/mastra'
|
|
231
|
+
// Existing imports...
|
|
232
|
+
import { chatRoute } from '@mastra/ai-sdk'
|
|
233
|
+
|
|
234
|
+
export const mastra = new Mastra({
|
|
235
|
+
// Existing config...
|
|
236
|
+
server: {
|
|
237
|
+
apiRoutes: [
|
|
238
|
+
chatRoute({
|
|
239
|
+
path: '/chat/:agentId',
|
|
240
|
+
}),
|
|
241
|
+
],
|
|
242
|
+
},
|
|
243
|
+
})
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Add the chat UI
|
|
247
|
+
|
|
248
|
+
Replace the `src/App.tsx` file to create a chat interface:
|
|
249
|
+
|
|
250
|
+
```tsx
|
|
251
|
+
import * as React from 'react'
|
|
252
|
+
import { DefaultChatTransport, type ToolUIPart } from 'ai'
|
|
253
|
+
import { useChat } from '@ai-sdk/react'
|
|
254
|
+
|
|
255
|
+
import {
|
|
256
|
+
PromptInput,
|
|
257
|
+
PromptInputBody,
|
|
258
|
+
PromptInputTextarea,
|
|
259
|
+
} from '@/components/ai-elements/prompt-input'
|
|
260
|
+
|
|
261
|
+
import {
|
|
262
|
+
Conversation,
|
|
263
|
+
ConversationContent,
|
|
264
|
+
ConversationScrollButton,
|
|
265
|
+
} from '@/components/ai-elements/conversation'
|
|
266
|
+
|
|
267
|
+
import { Message, MessageContent, MessageResponse } from '@/components/ai-elements/message'
|
|
268
|
+
|
|
269
|
+
import { Tool, ToolHeader, ToolContent, ToolInput, ToolOutput } from '@/components/ai-elements/tool'
|
|
270
|
+
|
|
271
|
+
export default function App() {
|
|
272
|
+
const [input, setInput] = React.useState<string>('')
|
|
273
|
+
|
|
274
|
+
const { messages, sendMessage, status } = useChat({
|
|
275
|
+
transport: new DefaultChatTransport({
|
|
276
|
+
api: 'http://localhost:4111/chat/weather-agent',
|
|
277
|
+
}),
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
const handleSubmit = async () => {
|
|
281
|
+
if (!input.trim()) return
|
|
282
|
+
|
|
283
|
+
sendMessage({ text: input })
|
|
284
|
+
setInput('')
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return (
|
|
288
|
+
<div className="relative mx-auto size-full h-screen max-w-4xl p-6">
|
|
289
|
+
<div className="flex h-full flex-col">
|
|
290
|
+
<Conversation className="h-full">
|
|
291
|
+
<ConversationContent>
|
|
292
|
+
{messages.map(message => (
|
|
293
|
+
<div key={message.id}>
|
|
294
|
+
{message.parts?.map((part, i) => {
|
|
295
|
+
if (part.type === 'text') {
|
|
296
|
+
return (
|
|
297
|
+
<Message key={`${message.id}-${i}`} from={message.role}>
|
|
298
|
+
<MessageContent>
|
|
299
|
+
<MessageResponse>{part.text}</MessageResponse>
|
|
300
|
+
</MessageContent>
|
|
301
|
+
</Message>
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (part.type?.startsWith('tool-')) {
|
|
306
|
+
return (
|
|
307
|
+
<Tool key={`${message.id}-${i}`}>
|
|
308
|
+
<ToolHeader
|
|
309
|
+
type={(part as ToolUIPart).type}
|
|
310
|
+
state={(part as ToolUIPart).state || 'output-available'}
|
|
311
|
+
className="cursor-pointer"
|
|
312
|
+
/>
|
|
313
|
+
<ToolContent>
|
|
314
|
+
<ToolInput input={(part as ToolUIPart).input || {}} />
|
|
315
|
+
<ToolOutput
|
|
316
|
+
output={(part as ToolUIPart).output}
|
|
317
|
+
errorText={(part as ToolUIPart).errorText}
|
|
318
|
+
/>
|
|
319
|
+
</ToolContent>
|
|
320
|
+
</Tool>
|
|
321
|
+
)
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return null
|
|
325
|
+
})}
|
|
326
|
+
</div>
|
|
327
|
+
))}
|
|
328
|
+
<ConversationScrollButton />
|
|
329
|
+
</ConversationContent>
|
|
330
|
+
</Conversation>
|
|
331
|
+
<PromptInput onSubmit={handleSubmit} className="mt-20">
|
|
332
|
+
<PromptInputBody>
|
|
333
|
+
<PromptInputTextarea
|
|
334
|
+
onChange={e => setInput(e.target.value)}
|
|
335
|
+
className="md:leading-10"
|
|
336
|
+
value={input}
|
|
337
|
+
placeholder="Ask about the weather..."
|
|
338
|
+
disabled={status !== 'ready'}
|
|
339
|
+
/>
|
|
340
|
+
</PromptInputBody>
|
|
341
|
+
</PromptInput>
|
|
342
|
+
</div>
|
|
343
|
+
</div>
|
|
344
|
+
)
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
This component connects [`useChat()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) to the `chat/weather-agent` endpoint, sending prompts there and streaming the response back in chunks.
|
|
349
|
+
|
|
350
|
+
It renders the response text using the [`<MessageResponse>`](https://ai-sdk.dev/elements/components/message#messageresponse-) component, and shows any tool invocations with the [`<Tool>`](https://ai-sdk.dev/elements/components/tool) component.
|
|
351
|
+
|
|
352
|
+
## Test your agent
|
|
353
|
+
|
|
354
|
+
In order to test your agent with the chat interface, you need to run both the Mastra server and the Vite development server.
|
|
355
|
+
|
|
356
|
+
1. Start the Mastra development server:
|
|
357
|
+
|
|
358
|
+
**npm**:
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
npx mastra dev
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
**pnpm**:
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
pnpm dlx mastra dev
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
**Yarn**:
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
yarn dlx mastra dev
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
**Bun**:
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
bun x mastra dev
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
2. In a separate terminal window, start the Vite development server:
|
|
383
|
+
|
|
384
|
+
**npm**:
|
|
385
|
+
|
|
386
|
+
```bash
|
|
387
|
+
npm run dev
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
**pnpm**:
|
|
391
|
+
|
|
392
|
+
```bash
|
|
393
|
+
pnpm run dev
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
**Yarn**:
|
|
397
|
+
|
|
398
|
+
```bash
|
|
399
|
+
yarn dev
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
**Bun**:
|
|
403
|
+
|
|
404
|
+
```bash
|
|
405
|
+
bun run dev
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
3. Open your application at <http://localhost:5173>
|
|
409
|
+
|
|
410
|
+
4. Try asking about the weather. If your API key is set up correctly, you'll get a response
|
|
411
|
+
|
|
412
|
+
## Next steps
|
|
413
|
+
|
|
414
|
+
Congratulations on building your Mastra agent with React! 🎉
|
|
415
|
+
|
|
416
|
+
From here, you can extend the project with your own tools and logic:
|
|
417
|
+
|
|
418
|
+
- Learn more about [agents](https://mastra.ai/docs/agents/overview)
|
|
419
|
+
- Give your agent its own [tools](https://mastra.ai/docs/agents/using-tools)
|
|
420
|
+
- Add human-like [memory](https://mastra.ai/docs/agents/agent-memory) to your agent
|
|
421
|
+
|
|
422
|
+
When you're ready, read more about how Mastra integrates with AI SDK UI and React, and how to deploy your agent anywhere:
|
|
423
|
+
|
|
424
|
+
- Integrate Mastra with [AI SDK UI](https://mastra.ai/guides/build-your-ui/ai-sdk-ui)
|
|
425
|
+
- Deploy your agent [anywhere](https://mastra.ai/docs/deployment/overview)
|