@mastra/mcp-docs-server 1.0.0-beta.13 → 1.0.0-beta.14
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%2Fagent-builder.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +98 -98
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +30 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +171 -171
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Frag.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Freact.md +9 -2
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +94 -94
- package/.docs/organized/changelogs/create-mastra.md +3 -3
- package/.docs/organized/changelogs/mastra.md +17 -17
- package/.docs/organized/code-examples/agent-v6.md +151 -0
- package/.docs/organized/code-examples/ai-elements.md +1 -1
- package/.docs/raw/agents/adding-voice.mdx +2 -3
- package/.docs/raw/agents/agent-approval.mdx +5 -6
- package/.docs/raw/agents/agent-memory.mdx +22 -30
- package/.docs/raw/agents/guardrails.mdx +60 -50
- package/.docs/raw/agents/networks.mdx +8 -12
- package/.docs/raw/agents/overview.mdx +39 -23
- package/.docs/raw/agents/processors.mdx +20 -19
- package/.docs/raw/agents/structured-output.mdx +11 -7
- package/.docs/raw/agents/using-tools.mdx +4 -5
- package/.docs/raw/deployment/mastra-server.mdx +3 -3
- package/.docs/raw/deployment/overview.mdx +7 -0
- package/.docs/raw/deployment/web-framework.mdx +4 -6
- package/.docs/raw/evals/custom-scorers.mdx +9 -6
- package/.docs/raw/evals/overview.mdx +3 -6
- package/.docs/raw/evals/running-in-ci.mdx +2 -2
- package/.docs/raw/getting-started/manual-install.mdx +20 -20
- package/.docs/raw/getting-started/mcp-docs-server.mdx +2 -2
- package/.docs/raw/guides/agent-frameworks/ai-sdk.mdx +4 -4
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +30 -30
- package/.docs/raw/guides/build-your-ui/assistant-ui.mdx +8 -8
- package/.docs/raw/guides/build-your-ui/copilotkit.mdx +11 -11
- package/.docs/raw/guides/deployment/amazon-ec2.mdx +9 -9
- package/.docs/raw/guides/deployment/aws-lambda.mdx +11 -11
- package/.docs/raw/guides/deployment/azure-app-services.mdx +2 -2
- package/.docs/raw/guides/deployment/cloudflare-deployer.mdx +5 -6
- package/.docs/raw/guides/deployment/digital-ocean.mdx +10 -10
- package/.docs/raw/guides/deployment/index.mdx +1 -1
- package/.docs/raw/guides/deployment/inngest.mdx +386 -0
- package/.docs/raw/guides/deployment/netlify-deployer.mdx +4 -4
- package/.docs/raw/guides/deployment/vercel-deployer.mdx +5 -6
- package/.docs/raw/guides/getting-started/astro.mdx +292 -451
- package/.docs/raw/guides/getting-started/express.mdx +7 -7
- package/.docs/raw/guides/getting-started/hono.mdx +18 -18
- package/.docs/raw/guides/getting-started/next-js.mdx +19 -20
- package/.docs/raw/guides/getting-started/quickstart.mdx +4 -4
- package/.docs/raw/guides/getting-started/sveltekit.mdx +238 -409
- package/.docs/raw/guides/getting-started/vite-react.mdx +21 -21
- package/.docs/raw/guides/guide/ai-recruiter.mdx +10 -10
- package/.docs/raw/guides/guide/chef-michel.mdx +9 -11
- package/.docs/raw/guides/guide/notes-mcp-server.mdx +15 -15
- package/.docs/raw/guides/guide/research-assistant.mdx +13 -13
- package/.docs/raw/guides/guide/stock-agent.mdx +5 -5
- package/.docs/raw/guides/guide/web-search.mdx +8 -8
- package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +7 -7
- package/.docs/raw/guides/migrations/ai-sdk-v4-to-v5.mdx +2 -2
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +1 -1
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +0 -2
- package/.docs/raw/guides/migrations/vnext-to-standard-apis.mdx +21 -23
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/mastra-cloud/setting-up.mdx +6 -2
- package/.docs/raw/mcp/overview.mdx +31 -13
- package/.docs/raw/mcp/publishing-mcp-server.mdx +2 -2
- package/.docs/raw/memory/memory-processors.mdx +9 -9
- package/.docs/raw/memory/message-history.mdx +69 -0
- package/.docs/raw/memory/overview.mdx +34 -76
- package/.docs/raw/memory/semantic-recall.mdx +58 -49
- package/.docs/raw/memory/storage.mdx +188 -0
- package/.docs/raw/memory/working-memory.mdx +7 -7
- package/.docs/raw/observability/logging.mdx +9 -10
- package/.docs/raw/observability/overview.mdx +0 -1
- package/.docs/raw/observability/tracing/bridges/otel.mdx +2 -2
- package/.docs/raw/observability/tracing/exporters/default.mdx +3 -3
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +1 -2
- package/.docs/raw/observability/tracing/overview.mdx +23 -25
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +3 -3
- package/.docs/raw/rag/chunking-and-embedding.mdx +6 -6
- package/.docs/raw/rag/graph-rag.mdx +7 -7
- package/.docs/raw/rag/overview.mdx +1 -1
- package/.docs/raw/rag/retrieval.mdx +21 -22
- package/.docs/raw/rag/vector-databases.mdx +22 -22
- package/.docs/raw/reference/agents/agent.mdx +3 -3
- package/.docs/raw/reference/agents/generate.mdx +1 -1
- package/.docs/raw/reference/agents/generateLegacy.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +2 -2
- package/.docs/raw/reference/agents/getDescription.mdx +1 -1
- package/.docs/raw/reference/agents/getInstructions.mdx +2 -2
- package/.docs/raw/reference/agents/getLLM.mdx +2 -2
- package/.docs/raw/reference/agents/getMemory.mdx +2 -2
- package/.docs/raw/reference/agents/getModel.mdx +2 -2
- package/.docs/raw/reference/agents/getTools.mdx +2 -2
- package/.docs/raw/reference/agents/getVoice.mdx +2 -2
- package/.docs/raw/reference/agents/listAgents.mdx +2 -2
- package/.docs/raw/reference/agents/listScorers.mdx +2 -2
- package/.docs/raw/reference/agents/listTools.mdx +2 -2
- package/.docs/raw/reference/agents/listWorkflows.mdx +2 -2
- package/.docs/raw/reference/agents/network.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/chat-route.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/network-route.mdx +2 -2
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-stream.mdx +6 -6
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v4-messages.mdx +3 -3
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v5-messages.mdx +3 -3
- package/.docs/raw/reference/ai-sdk/with-mastra.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/workflow-route.mdx +2 -2
- package/.docs/raw/reference/auth/auth0.mdx +1 -2
- package/.docs/raw/reference/auth/clerk.mdx +1 -2
- package/.docs/raw/reference/auth/firebase.mdx +2 -4
- package/.docs/raw/reference/auth/jwt.mdx +1 -2
- package/.docs/raw/reference/auth/supabase.mdx +1 -2
- package/.docs/raw/reference/auth/workos.mdx +1 -2
- package/.docs/raw/reference/cli/create-mastra.mdx +10 -10
- package/.docs/raw/reference/cli/mastra.mdx +9 -9
- package/.docs/raw/reference/client-js/agents.mdx +1 -2
- package/.docs/raw/reference/client-js/mastra-client.mdx +1 -1
- package/.docs/raw/reference/core/getAgent.mdx +1 -1
- package/.docs/raw/reference/core/getAgentById.mdx +1 -1
- package/.docs/raw/reference/core/getDeployer.mdx +1 -1
- package/.docs/raw/reference/core/getLogger.mdx +1 -1
- package/.docs/raw/reference/core/getMCPServer.mdx +1 -1
- package/.docs/raw/reference/core/getMCPServerById.mdx +1 -1
- package/.docs/raw/reference/core/getMemory.mdx +2 -2
- package/.docs/raw/reference/core/getServer.mdx +1 -1
- package/.docs/raw/reference/core/getStorage.mdx +2 -2
- package/.docs/raw/reference/core/getStoredAgentById.mdx +3 -3
- package/.docs/raw/reference/core/getTelemetry.mdx +1 -1
- package/.docs/raw/reference/core/getVector.mdx +1 -1
- package/.docs/raw/reference/core/getWorkflow.mdx +1 -1
- package/.docs/raw/reference/core/listAgents.mdx +1 -1
- package/.docs/raw/reference/core/listLogs.mdx +1 -1
- package/.docs/raw/reference/core/listLogsByRunId.mdx +1 -1
- package/.docs/raw/reference/core/listMCPServers.mdx +1 -1
- package/.docs/raw/reference/core/listMemory.mdx +2 -2
- package/.docs/raw/reference/core/listStoredAgents.mdx +4 -4
- package/.docs/raw/reference/core/listVectors.mdx +1 -1
- package/.docs/raw/reference/core/listWorkflows.mdx +1 -1
- package/.docs/raw/reference/core/setLogger.mdx +1 -1
- package/.docs/raw/reference/core/setStorage.mdx +2 -2
- package/.docs/raw/reference/core/setTelemetry.mdx +1 -1
- package/.docs/raw/reference/deployer/cloudflare.mdx +1 -2
- package/.docs/raw/reference/deployer/deployer.mdx +0 -1
- package/.docs/raw/reference/deployer/netlify.mdx +1 -1
- package/.docs/raw/reference/deployer/vercel.mdx +2 -4
- package/.docs/raw/reference/evals/answer-relevancy.mdx +1 -1
- package/.docs/raw/reference/evals/answer-similarity.mdx +1 -1
- package/.docs/raw/reference/evals/bias.mdx +1 -1
- package/.docs/raw/reference/evals/completeness.mdx +1 -1
- package/.docs/raw/reference/evals/content-similarity.mdx +1 -1
- package/.docs/raw/reference/evals/context-precision.mdx +1 -1
- package/.docs/raw/reference/evals/faithfulness.mdx +1 -1
- package/.docs/raw/reference/evals/hallucination.mdx +1 -1
- package/.docs/raw/reference/evals/keyword-coverage.mdx +1 -1
- package/.docs/raw/reference/evals/prompt-alignment.mdx +7 -7
- package/.docs/raw/reference/evals/textual-difference.mdx +1 -1
- package/.docs/raw/reference/evals/tone-consistency.mdx +1 -1
- package/.docs/raw/reference/evals/tool-call-accuracy.mdx +10 -10
- package/.docs/raw/reference/evals/toxicity.mdx +1 -1
- package/.docs/raw/reference/logging/pino-logger.mdx +6 -7
- package/.docs/raw/reference/memory/createThread.mdx +2 -2
- package/.docs/raw/reference/memory/deleteMessages.mdx +2 -2
- package/.docs/raw/reference/memory/listThreadsByResourceId.mdx +2 -2
- package/.docs/raw/reference/memory/memory-class.mdx +3 -3
- package/.docs/raw/reference/memory/query.mdx +2 -2
- package/.docs/raw/reference/memory/recall.mdx +2 -2
- package/.docs/raw/reference/observability/tracing/exporters/langfuse.mdx +1 -1
- package/.docs/raw/reference/processors/batch-parts-processor.mdx +2 -2
- package/.docs/raw/reference/processors/language-detector.mdx +2 -2
- package/.docs/raw/reference/processors/message-history-processor.mdx +2 -2
- package/.docs/raw/reference/processors/moderation-processor.mdx +3 -3
- package/.docs/raw/reference/processors/pii-detector.mdx +3 -3
- package/.docs/raw/reference/processors/processor-interface.mdx +13 -13
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +2 -2
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +2 -2
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -2
- package/.docs/raw/reference/processors/token-limiter-processor.mdx +2 -2
- package/.docs/raw/reference/processors/tool-call-filter.mdx +3 -3
- package/.docs/raw/reference/processors/unicode-normalizer.mdx +2 -2
- package/.docs/raw/reference/processors/working-memory-processor.mdx +3 -3
- package/.docs/raw/reference/rag/chunk.mdx +1 -1
- package/.docs/raw/reference/rag/extract-params.mdx +2 -2
- package/.docs/raw/reference/rag/metadata-filters.mdx +7 -7
- package/.docs/raw/reference/server/create-route.mdx +13 -13
- package/.docs/raw/reference/server/express-adapter.mdx +6 -7
- package/.docs/raw/reference/server/hono-adapter.mdx +6 -7
- package/.docs/raw/reference/server/mastra-server.mdx +20 -20
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +3 -3
- package/.docs/raw/reference/storage/cloudflare.mdx +2 -2
- package/.docs/raw/reference/storage/convex.mdx +6 -6
- package/.docs/raw/reference/storage/dynamodb.mdx +4 -4
- package/.docs/raw/reference/storage/lance.mdx +3 -3
- package/.docs/raw/reference/storage/libsql.mdx +69 -54
- package/.docs/raw/reference/storage/mongodb.mdx +80 -7
- package/.docs/raw/reference/storage/mssql.mdx +4 -4
- package/.docs/raw/{memory → reference}/storage/overview.mdx +12 -110
- package/.docs/raw/reference/storage/postgresql.mdx +78 -7
- package/.docs/raw/reference/storage/upstash.mdx +74 -2
- package/.docs/raw/reference/streaming/agents/stream.mdx +5 -5
- package/.docs/raw/reference/streaming/agents/streamLegacy.mdx +2 -2
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +1 -1
- package/.docs/raw/reference/streaming/workflows/resumeStream.mdx +1 -1
- package/.docs/raw/reference/streaming/workflows/stream.mdx +2 -2
- package/.docs/raw/reference/streaming/workflows/timeTravelStream.mdx +4 -4
- package/.docs/raw/reference/templates/overview.mdx +1 -2
- package/.docs/raw/reference/tools/create-tool.mdx +1 -4
- package/.docs/raw/reference/tools/vector-query-tool.mdx +1 -1
- package/.docs/raw/reference/vectors/astra.mdx +3 -3
- package/.docs/raw/reference/vectors/chroma.mdx +3 -3
- package/.docs/raw/reference/vectors/convex.mdx +12 -12
- package/.docs/raw/reference/vectors/couchbase.mdx +5 -5
- package/.docs/raw/reference/vectors/duckdb.mdx +10 -10
- package/.docs/raw/reference/vectors/elasticsearch.mdx +4 -4
- package/.docs/raw/reference/vectors/lance.mdx +4 -4
- package/.docs/raw/reference/vectors/libsql.mdx +61 -11
- package/.docs/raw/reference/vectors/mongodb.mdx +58 -5
- package/.docs/raw/reference/vectors/pg.mdx +53 -6
- package/.docs/raw/reference/vectors/pinecone.mdx +3 -3
- package/.docs/raw/reference/vectors/qdrant.mdx +3 -3
- package/.docs/raw/reference/vectors/s3vectors.mdx +6 -6
- package/.docs/raw/reference/vectors/turbopuffer.mdx +4 -4
- package/.docs/raw/reference/vectors/upstash.mdx +55 -6
- package/.docs/raw/reference/vectors/vectorize.mdx +3 -3
- package/.docs/raw/reference/workflows/run-methods/cancel.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/restart.mdx +1 -3
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/start.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/startAsync.mdx +2 -2
- package/.docs/raw/reference/workflows/run-methods/timeTravel.mdx +5 -5
- package/.docs/raw/reference/workflows/run.mdx +1 -1
- package/.docs/raw/reference/workflows/step.mdx +3 -3
- package/.docs/raw/reference/workflows/workflow-methods/branch.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/commit.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +3 -3
- package/.docs/raw/reference/workflows/workflow-methods/dountil.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/dowhile.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/foreach.mdx +6 -6
- package/.docs/raw/reference/workflows/workflow-methods/map.mdx +7 -7
- package/.docs/raw/reference/workflows/workflow-methods/parallel.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/sendEvent.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/sleep.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/sleepUntil.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow-methods/then.mdx +1 -1
- package/.docs/raw/reference/workflows/workflow-methods/waitForEvent.mdx +2 -2
- package/.docs/raw/reference/workflows/workflow.mdx +3 -3
- package/.docs/raw/server/auth/auth0.mdx +20 -14
- package/.docs/raw/server/auth/clerk.mdx +16 -9
- package/.docs/raw/server/auth/firebase.mdx +21 -15
- package/.docs/raw/server/auth/jwt.mdx +14 -7
- package/.docs/raw/server/auth/supabase.mdx +16 -9
- package/.docs/raw/server/auth/workos.mdx +19 -13
- package/.docs/raw/server/custom-adapters.mdx +10 -10
- package/.docs/raw/server/custom-api-routes.mdx +2 -4
- package/.docs/raw/server/mastra-client.mdx +24 -13
- package/.docs/raw/server/mastra-server.mdx +3 -3
- package/.docs/raw/server/middleware.mdx +7 -7
- package/.docs/raw/server/request-context.mdx +31 -30
- package/.docs/raw/server/server-adapters.mdx +6 -6
- package/.docs/raw/streaming/events.mdx +14 -7
- package/.docs/raw/streaming/overview.mdx +21 -10
- package/.docs/raw/streaming/tool-streaming.mdx +6 -6
- package/.docs/raw/streaming/workflow-streaming.mdx +6 -8
- package/.docs/raw/tools-mcp/advanced-usage.mdx +2 -2
- package/.docs/raw/tools-mcp/mcp-overview.mdx +31 -12
- package/.docs/raw/tools-mcp/overview.mdx +9 -10
- package/.docs/raw/voice/overview.mdx +1 -1
- package/.docs/raw/workflows/agents-and-tools.mdx +28 -19
- package/.docs/raw/workflows/control-flow.mdx +27 -40
- package/.docs/raw/workflows/error-handling.mdx +15 -22
- package/.docs/raw/workflows/human-in-the-loop.mdx +6 -7
- package/.docs/raw/workflows/inngest-workflow.mdx +8 -9
- package/.docs/raw/workflows/input-data-mapping.mdx +7 -7
- package/.docs/raw/workflows/overview.mdx +33 -22
- package/.docs/raw/workflows/snapshots.mdx +14 -44
- package/.docs/raw/workflows/suspend-and-resume.mdx +7 -7
- package/.docs/raw/workflows/time-travel.mdx +16 -16
- package/.docs/raw/workflows/workflow-state.mdx +5 -8
- package/CHANGELOG.md +9 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/stdio.js +53 -0
- package/package.json +4 -4
- package/.docs/raw/memory/conversation-history.mdx +0 -24
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +0 -140
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +0 -150
- package/.docs/raw/memory/storage/memory-with-pg.mdx +0 -138
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +0 -146
- package/.docs/raw/memory/threads-and-resources.mdx +0 -95
|
@@ -1,600 +1,441 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "
|
|
3
|
-
description:
|
|
2
|
+
title: "Astro | Frameworks"
|
|
3
|
+
description: "Get started with Mastra and Astro"
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
import Tabs from "@theme/Tabs";
|
|
7
7
|
import TabItem from "@theme/TabItem";
|
|
8
|
-
import Steps from "@site/src/components/Steps";
|
|
9
|
-
import StepItem from "@site/src/components/StepItem";
|
|
10
8
|
|
|
11
9
|
# Integrate Mastra in your Astro project
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
In this guide, you'll build a tool-calling AI agent using Mastra, then connect it to Astro by importing and calling the agent directly from your routes.
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
- Simplify deployment with a unified codebase for frontend and backend
|
|
17
|
-
- Take advantage of Astro's built-in [Actions](https://docs.astro.build/en/guides/actions/) or [Server Endpoints](https://docs.astro.build/en/guides/endpoints/#server-endpoints-api-routes) for efficient server-client workflows
|
|
13
|
+
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.
|
|
18
14
|
|
|
19
|
-
|
|
15
|
+
:::note
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
<TabItem value="actions" label="Actions">
|
|
23
|
-
|
|
24
|
-
:::warning
|
|
25
|
-
|
|
26
|
-
This guide assumes you're using Astro's Actions with React and the Vercel adapter.
|
|
17
|
+
While this guide shows you how to use Astro with React and full server-side rendering (SSR), there are many ways to use Astro with Mastra. You can [opt-in to SSR](https://docs.astro.build/en/guides/on-demand-rendering/#enabling-on-demand-rendering) on a per-file basis and use other frameworks like Svelte, Vue, Solid, or Preact. You can use Astro to build out a chat interface and call endpoints [natively in Astro](https://docs.astro.build/en/recipes/call-endpoints/).
|
|
27
18
|
|
|
28
19
|
:::
|
|
29
20
|
|
|
30
|
-
|
|
21
|
+
## Before you begin
|
|
31
22
|
|
|
32
|
-
|
|
23
|
+
- You'll need an API key from a supported [model provider](/models/v1). If you don't have a preference, use [OpenAI](/models/v1/providers/openai).
|
|
24
|
+
- Install Node.js `v22.13.0` or later
|
|
33
25
|
|
|
34
|
-
|
|
26
|
+
## Create a new Astro app (optional)
|
|
35
27
|
|
|
36
|
-
|
|
37
|
-
<TabItem value="npm" label="npm">
|
|
28
|
+
If you already have an Astro app, skip to the next step. Your Astro app should be setup like this:
|
|
38
29
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
- Use SSR (`output: "server"` in `astro.config.mjs`)
|
|
31
|
+
- Use the [React integration](https://docs.astro.build/en/guides/integrations-guide/react/)
|
|
32
|
+
- Tailwind installed
|
|
42
33
|
|
|
43
|
-
|
|
44
|
-
<TabItem value="yarn" label="yarn">
|
|
34
|
+
To support [on-demand rendering](https://docs.astro.build/en/guides/on-demand-rendering/) this guide will use the [Node.js adapter](https://docs.astro.build/en/guides/integrations-guide/node/) but any of the supported server adapters will work.
|
|
45
35
|
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
<Tabs groupId="pm">
|
|
37
|
+
<TabItem value="npm" label="npm">
|
|
38
|
+
```bash
|
|
39
|
+
npm create astro@latest mastra-astro -- --add node --add react --add tailwind --install --skip-houston --template minimal --git
|
|
48
40
|
```
|
|
49
|
-
|
|
50
41
|
</TabItem>
|
|
51
42
|
<TabItem value="pnpm" label="pnpm">
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
```bash
|
|
44
|
+
pnpm create astro@latest mastra-astro --add node --add react --add tailwind --install --skip-houston --template minimal --git
|
|
45
|
+
```
|
|
46
|
+
</TabItem>
|
|
47
|
+
<TabItem value="yarn" label="yarn">
|
|
48
|
+
```bash
|
|
49
|
+
yarn create astro@latest mastra-astro --add node --add react --add tailwind --install --skip-houston --template minimal --git
|
|
55
50
|
```
|
|
56
|
-
|
|
57
51
|
</TabItem>
|
|
58
52
|
<TabItem value="bun" label="bun">
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
bun add mastra@beta @mastra/core@beta @mastra/libsql@beta @ai-sdk/openai
|
|
53
|
+
```bash
|
|
54
|
+
bun create astro@latest mastra-astro --add node --add react --add tailwind --install --skip-houston --template minimal --git
|
|
62
55
|
```
|
|
63
|
-
|
|
64
56
|
</TabItem>
|
|
65
57
|
</Tabs>
|
|
66
58
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
<StepItem>
|
|
70
|
-
|
|
71
|
-
To integrate Mastra into your project, you have two options:
|
|
59
|
+
This creates a project called `mastra-astro`, but you can replace it with any name you want.
|
|
72
60
|
|
|
73
|
-
|
|
61
|
+
`cd` into your project and edit the `astro.config.mjs` file to set the [`output` setting](https://docs.astro.build/en/reference/configuration-reference/#output) to `"server"`:
|
|
74
62
|
|
|
75
|
-
|
|
63
|
+
```js title="astro.config.mjs {10}
|
|
64
|
+
// @ts-check
|
|
65
|
+
import { defineConfig } from 'astro/config';
|
|
76
66
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
import node from '@astrojs/node';
|
|
68
|
+
import react from '@astrojs/react';
|
|
69
|
+
import tailwindcss from '@tailwindcss/vite';
|
|
80
70
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
```bash copy
|
|
88
|
-
npx mastra@beta init
|
|
89
|
-
```
|
|
71
|
+
// https://astro.build/config
|
|
72
|
+
export default defineConfig({
|
|
73
|
+
output: 'server',
|
|
74
|
+
adapter: node({
|
|
75
|
+
mode: 'standalone'
|
|
76
|
+
}),
|
|
90
77
|
|
|
91
|
-
|
|
78
|
+
integrations: [react()],
|
|
92
79
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
"scripts": {
|
|
96
|
-
...
|
|
97
|
-
"dev:mastra": "mastra dev",
|
|
98
|
-
"build:mastra": "mastra build"
|
|
80
|
+
vite: {
|
|
81
|
+
plugins: [tailwindcss()]
|
|
99
82
|
}
|
|
100
|
-
}
|
|
83
|
+
});
|
|
101
84
|
```
|
|
102
85
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
<StepItem>
|
|
106
|
-
|
|
107
|
-
Modify the `tsconfig.json` file in your project root:
|
|
86
|
+
Lastly, edit the `tsconfig.json` to resolve paths:
|
|
108
87
|
|
|
109
|
-
```
|
|
88
|
+
```ts title="tsconfig.json"
|
|
110
89
|
{
|
|
111
|
-
|
|
112
|
-
|
|
90
|
+
"compilerOptions": {
|
|
91
|
+
// ...
|
|
92
|
+
"baseUrl": ".",
|
|
93
|
+
"paths": {
|
|
94
|
+
"@/*": [
|
|
95
|
+
"./src/*"
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
// ...
|
|
99
|
+
}
|
|
113
100
|
}
|
|
114
101
|
```
|
|
115
102
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
<StepItem>
|
|
119
|
-
|
|
120
|
-
Setup your API key in a `.env` file:
|
|
121
|
-
|
|
122
|
-
```bash title=".env" copy
|
|
123
|
-
OPENAI_API_KEY=<your-api-key>
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
</StepItem>
|
|
127
|
-
|
|
128
|
-
<StepItem>
|
|
129
|
-
|
|
130
|
-
Add `.mastra` and `.vercel` to your `.gitignore` file:
|
|
131
|
-
|
|
132
|
-
```bash title=".gitignore" copy
|
|
133
|
-
.mastra
|
|
134
|
-
.vercel
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
</StepItem>
|
|
138
|
-
|
|
139
|
-
<StepItem>
|
|
140
|
-
|
|
141
|
-
Astro uses Vite, which accesses environment variables via `import.meta.env` rather than `process.env`. As a result, the model constructor must explicitly receive the `apiKey` from the Vite environment like this:
|
|
142
|
-
|
|
143
|
-
```typescript title="src/mastra/agents/weather-agent.ts"
|
|
144
|
-
import { createOpenAI } from "@ai-sdk/openai";
|
|
145
|
-
|
|
146
|
-
const openai = createOpenAI({
|
|
147
|
-
apiKey: import.meta.env?.OPENAI_API_KEY,
|
|
148
|
-
compatibility: "strict"
|
|
149
|
-
});
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
> More configuration details are available in the AI SDK docs. See [Provider Instance](https://ai-sdk.dev/providers/ai-sdk-providers/openai#provider-instance) for more information.
|
|
153
|
-
|
|
154
|
-
</StepItem>
|
|
155
|
-
|
|
156
|
-
<StepItem>
|
|
103
|
+
## Initialize Mastra
|
|
157
104
|
|
|
158
|
-
|
|
105
|
+
Run [`mastra init`](/reference/v1/cli/mastra#mastra-init). When prompted, choose a provider (e.g. OpenAI) and enter your key:
|
|
159
106
|
|
|
160
|
-
<Tabs>
|
|
107
|
+
<Tabs groupId="pm">
|
|
161
108
|
<TabItem value="npm" label="npm">
|
|
162
109
|
|
|
163
|
-
```bash
|
|
164
|
-
|
|
110
|
+
```bash
|
|
111
|
+
npx mastra@beta init
|
|
165
112
|
```
|
|
166
113
|
|
|
167
114
|
</TabItem>
|
|
168
|
-
<TabItem value="
|
|
115
|
+
<TabItem value="pnpm" label="pnpm">
|
|
169
116
|
|
|
170
|
-
```bash
|
|
171
|
-
mastra
|
|
117
|
+
```bash
|
|
118
|
+
pnpm dlx mastra@beta init
|
|
172
119
|
```
|
|
173
120
|
|
|
174
121
|
</TabItem>
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
> Once running, your agents are available locally. See [Local Development Environment](/docs/v1/getting-started/studio) for more information.
|
|
178
|
-
|
|
179
|
-
</StepItem>
|
|
180
|
-
|
|
181
|
-
<StepItem>
|
|
182
|
-
|
|
183
|
-
With the Mastra Dev Server running, you can start your Astro site in the usual way.
|
|
184
|
-
|
|
185
|
-
</StepItem>
|
|
186
|
-
|
|
187
|
-
<StepItem>
|
|
188
|
-
|
|
189
|
-
Create an `actions` directory:
|
|
190
|
-
|
|
191
|
-
```bash copy
|
|
192
|
-
mkdir src/actions
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
</StepItem>
|
|
196
|
-
|
|
197
|
-
<StepItem>
|
|
198
|
-
|
|
199
|
-
Create a new Action, and add the example code:
|
|
200
|
-
|
|
201
|
-
```bash copy
|
|
202
|
-
touch src/actions/index.ts
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
```typescript title="src/actions/index.ts" showLineNumbers copy
|
|
206
|
-
import { defineAction } from "astro:actions";
|
|
207
|
-
import { z } from "astro:schema";
|
|
208
|
-
|
|
209
|
-
import { mastra } from "../mastra";
|
|
210
|
-
|
|
211
|
-
export const server = {
|
|
212
|
-
getWeatherInfo: defineAction({
|
|
213
|
-
input: z.object({
|
|
214
|
-
city: z.string(),
|
|
215
|
-
}),
|
|
216
|
-
handler: async (input) => {
|
|
217
|
-
const city = inputData.city;
|
|
218
|
-
const agent = mastra.getAgent("weatherAgent");
|
|
219
|
-
|
|
220
|
-
const result = await agent.generate(
|
|
221
|
-
`What's the weather like in ${city}?`,
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
return result.text;
|
|
225
|
-
},
|
|
226
|
-
}),
|
|
227
|
-
};
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
</StepItem>
|
|
231
|
-
|
|
232
|
-
<StepItem>
|
|
233
|
-
|
|
234
|
-
Create a new Form component, and add the example code:
|
|
235
|
-
|
|
236
|
-
```bash copy
|
|
237
|
-
touch src/components/form.tsx
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
```typescript title="src/components/form.tsx" showLineNumbers copy
|
|
241
|
-
import { actions } from "astro:actions";
|
|
242
|
-
import { useState } from "react";
|
|
243
|
-
|
|
244
|
-
export const Form = () => {
|
|
245
|
-
const [result, setResult] = useState<string | null>(null);
|
|
246
|
-
|
|
247
|
-
async function handleSubmit(formData: FormData) {
|
|
248
|
-
const city = formData.get("city")!.toString();
|
|
249
|
-
const { data } = await actions.getWeatherInfo({ city });
|
|
250
|
-
|
|
251
|
-
setResult(data || null);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return (
|
|
255
|
-
<>
|
|
256
|
-
<form action={handleSubmit}>
|
|
257
|
-
<input name="city" placeholder="Enter city" required />
|
|
258
|
-
<button type="submit">Get Weather</button>
|
|
259
|
-
</form>
|
|
260
|
-
{result && <pre>{result}</pre>}
|
|
261
|
-
</>
|
|
262
|
-
);
|
|
263
|
-
};
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
</StepItem>
|
|
267
|
-
|
|
268
|
-
<StepItem>
|
|
269
|
-
|
|
270
|
-
Create a new Page, and add the example code:
|
|
271
|
-
|
|
272
|
-
```bash copy
|
|
273
|
-
touch src/pages/test.astro
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
```astro title="src/pages/test.astro" showLineNumbers copy
|
|
277
|
-
---
|
|
278
|
-
import { Form } from '../components/form'
|
|
279
|
-
---
|
|
122
|
+
<TabItem value="yarn" label="yarn">
|
|
280
123
|
|
|
281
|
-
|
|
282
|
-
|
|
124
|
+
```bash
|
|
125
|
+
yarn dlx mastra@beta init
|
|
283
126
|
```
|
|
284
127
|
|
|
285
|
-
>
|
|
286
|
-
|
|
287
|
-
Submitting **London** as the city would return a result similar to:
|
|
288
|
-
|
|
289
|
-
```plaintext
|
|
290
|
-
Agent response: The current weather in London is as follows:
|
|
291
|
-
|
|
292
|
-
- **Temperature:** 12.9°C (Feels like 9.7°C)
|
|
293
|
-
- **Humidity:** 63%
|
|
294
|
-
- **Wind Speed:** 14.7 km/h
|
|
295
|
-
- **Wind Gusts:** 32.4 km/h
|
|
296
|
-
- **Conditions:** Overcast
|
|
128
|
+
</TabItem>
|
|
129
|
+
<TabItem value="bun" label="bun">
|
|
297
130
|
|
|
298
|
-
|
|
131
|
+
```bash
|
|
132
|
+
bunx mastra@beta init
|
|
299
133
|
```
|
|
300
134
|
|
|
301
|
-
</
|
|
302
|
-
|
|
303
|
-
</Steps>
|
|
304
|
-
</TabItem>
|
|
305
|
-
|
|
306
|
-
<TabItem value="server-endpoints" label="Server Endpoints">
|
|
307
|
-
|
|
308
|
-
:::warning
|
|
309
|
-
|
|
310
|
-
This guide assumes you're using Astro's Endpoints with React and the Vercel adapter, and your output is set to server.
|
|
311
|
-
|
|
312
|
-
:::
|
|
313
|
-
|
|
314
|
-
## Prerequisites
|
|
135
|
+
</TabItem>
|
|
136
|
+
</Tabs>
|
|
315
137
|
|
|
316
|
-
|
|
138
|
+
This creates a `src/mastra` folder with an example weather agent and the following files:
|
|
317
139
|
|
|
318
|
-
-
|
|
319
|
-
-
|
|
320
|
-
-
|
|
140
|
+
- `index.ts` - Mastra config, including memory
|
|
141
|
+
- `tools/weather-tool.ts` - a tool to fetch weather for a given location
|
|
142
|
+
- `agents/weather-agent.ts`- a weather agent with a prompt that uses the tool
|
|
321
143
|
|
|
322
|
-
|
|
144
|
+
You'll call `weather-agent.ts` from your Astro routes in the next steps.
|
|
323
145
|
|
|
324
|
-
|
|
146
|
+
## Install AI SDK UI & AI Elements
|
|
325
147
|
|
|
326
|
-
Install the
|
|
148
|
+
Install AI SDK UI along with the Mastra adapter:
|
|
327
149
|
|
|
328
|
-
<Tabs>
|
|
150
|
+
<Tabs groupId="pm">
|
|
329
151
|
<TabItem value="npm" label="npm">
|
|
330
152
|
|
|
331
|
-
```bash
|
|
332
|
-
npm install
|
|
153
|
+
```bash
|
|
154
|
+
npm install @mastra/ai-sdk@beta @ai-sdk/react ai
|
|
333
155
|
```
|
|
334
156
|
|
|
335
157
|
</TabItem>
|
|
336
|
-
<TabItem value="
|
|
158
|
+
<TabItem value="pnpm" label="pnpm">
|
|
337
159
|
|
|
338
|
-
```bash
|
|
339
|
-
|
|
160
|
+
```bash
|
|
161
|
+
pnpm add @mastra/ai-sdk@beta @ai-sdk/react ai
|
|
340
162
|
```
|
|
341
163
|
|
|
342
164
|
</TabItem>
|
|
343
|
-
<TabItem value="
|
|
165
|
+
<TabItem value="yarn" label="yarn">
|
|
344
166
|
|
|
345
|
-
```bash
|
|
346
|
-
|
|
167
|
+
```bash
|
|
168
|
+
yarn add @mastra/ai-sdk@beta @ai-sdk/react ai
|
|
347
169
|
```
|
|
348
170
|
|
|
349
171
|
</TabItem>
|
|
350
172
|
<TabItem value="bun" label="bun">
|
|
351
173
|
|
|
352
|
-
```bash
|
|
353
|
-
bun add
|
|
174
|
+
```bash
|
|
175
|
+
bun add @mastra/ai-sdk@beta @ai-sdk/react ai
|
|
354
176
|
```
|
|
355
177
|
|
|
356
178
|
</TabItem>
|
|
357
179
|
</Tabs>
|
|
358
180
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
<StepItem>
|
|
362
|
-
|
|
363
|
-
To integrate Mastra into your project, you have two options:
|
|
364
|
-
|
|
365
|
-
- Use the One-Liner
|
|
366
|
-
|
|
367
|
-
Run the following command to quickly scaffold the default Weather agent with sensible defaults:
|
|
368
|
-
|
|
369
|
-
```bash copy
|
|
370
|
-
npx mastra@beta init --default
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
> See [mastra init](/reference/v1/cli/create-mastra) for more information.
|
|
374
|
-
|
|
375
|
-
- Use the Interactive CLI
|
|
376
|
-
|
|
377
|
-
If you prefer to customize the setup, run the `init` command and choose from the options when prompted:
|
|
378
|
-
|
|
379
|
-
```bash copy
|
|
380
|
-
npx mastra@beta init
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
Add the `dev` and `build` scripts to `package.json`:
|
|
384
|
-
|
|
385
|
-
```json title="package.json"
|
|
386
|
-
{
|
|
387
|
-
"scripts": {
|
|
388
|
-
...
|
|
389
|
-
"dev:mastra": "mastra dev",
|
|
390
|
-
"build:mastra": "mastra build"
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
</StepItem>
|
|
396
|
-
|
|
397
|
-
<StepItem>
|
|
398
|
-
|
|
399
|
-
Modify the `tsconfig.json` file in your project root:
|
|
400
|
-
|
|
401
|
-
```json title="tsconfig.json"
|
|
402
|
-
{
|
|
403
|
-
...
|
|
404
|
-
"exclude": ["dist", ".mastra"]
|
|
405
|
-
}
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
</StepItem>
|
|
409
|
-
|
|
410
|
-
<StepItem>
|
|
411
|
-
|
|
412
|
-
Setup your API key in a `.env` file:
|
|
413
|
-
|
|
414
|
-
```bash title=".env" copy
|
|
415
|
-
OPENAI_API_KEY=<your-api-key>
|
|
416
|
-
```
|
|
181
|
+
Next, initialize AI Elements. When prompted, choose the default options:
|
|
417
182
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
<StepItem>
|
|
421
|
-
|
|
422
|
-
Add `.mastra` to your `.gitignore` file:
|
|
183
|
+
<Tabs groupId="pm">
|
|
184
|
+
<TabItem value="npm" label="npm">
|
|
423
185
|
|
|
424
|
-
```bash
|
|
425
|
-
|
|
426
|
-
.vercel
|
|
186
|
+
```bash
|
|
187
|
+
npx ai-elements@latest
|
|
427
188
|
```
|
|
428
189
|
|
|
429
|
-
</
|
|
430
|
-
|
|
431
|
-
<StepItem>
|
|
432
|
-
|
|
433
|
-
Astro uses Vite, which accesses environment variables via `import.meta.env` rather than `process.env`. As a result, the model constructor must explicitly receive the `apiKey` from the Vite environment like this:
|
|
434
|
-
|
|
435
|
-
```typescript title="src/mastra/agents/weather-agent.ts"
|
|
436
|
-
import { createOpenAI } from "@ai-sdk/openai";
|
|
190
|
+
</TabItem>
|
|
191
|
+
<TabItem value="pnpm" label="pnpm">
|
|
437
192
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
compatibility: "strict"
|
|
441
|
-
});
|
|
193
|
+
```bash
|
|
194
|
+
pnpm dlx ai-elements@latest
|
|
442
195
|
```
|
|
443
196
|
|
|
444
|
-
>
|
|
445
|
-
|
|
446
|
-
</StepItem>
|
|
447
|
-
|
|
448
|
-
<StepItem>
|
|
449
|
-
|
|
450
|
-
Start the Mastra Dev Server to expose your agents as REST endpoints:
|
|
451
|
-
|
|
452
|
-
<Tabs>
|
|
453
|
-
<TabItem value="npm" label="npm">
|
|
197
|
+
</TabItem>
|
|
198
|
+
<TabItem value="yarn" label="yarn">
|
|
454
199
|
|
|
455
|
-
```bash
|
|
456
|
-
|
|
200
|
+
```bash
|
|
201
|
+
yarn dlx ai-elements@latest
|
|
457
202
|
```
|
|
458
203
|
|
|
459
204
|
</TabItem>
|
|
460
|
-
<TabItem value="
|
|
205
|
+
<TabItem value="bun" label="bun">
|
|
461
206
|
|
|
462
|
-
```bash
|
|
463
|
-
|
|
207
|
+
```bash
|
|
208
|
+
bunx ai-elements@latest
|
|
464
209
|
```
|
|
465
210
|
|
|
466
211
|
</TabItem>
|
|
467
212
|
</Tabs>
|
|
468
213
|
|
|
469
|
-
|
|
214
|
+
This downloads the entire AI Elements UI component library into a `@/components/ai-elements` folder.
|
|
470
215
|
|
|
471
|
-
|
|
216
|
+
## Create a chat route
|
|
472
217
|
|
|
473
|
-
|
|
218
|
+
Create `src/pages/api/chat.ts`:
|
|
474
219
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
Create an `api` directory:
|
|
220
|
+
```ts title="src/pages/api/chat.ts"
|
|
221
|
+
import type { APIRoute } from "astro";
|
|
222
|
+
import { handleChatStream } from '@mastra/ai-sdk';
|
|
223
|
+
import { toAISdkV5Messages } from '@mastra/ai-sdk/ui'
|
|
224
|
+
import { createUIMessageStreamResponse } from 'ai';
|
|
225
|
+
import { mastra } from '@/mastra';
|
|
482
226
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
```
|
|
227
|
+
const THREAD_ID = 'example-user-id';
|
|
228
|
+
const RESOURCE_ID = 'weather-chat';
|
|
486
229
|
|
|
487
|
-
|
|
230
|
+
export const POST: APIRoute = async ({ request }) => {
|
|
231
|
+
const params = await request.json();
|
|
232
|
+
const stream = await handleChatStream({
|
|
233
|
+
mastra,
|
|
234
|
+
agentId: 'weather-agent',
|
|
235
|
+
params: {
|
|
236
|
+
...params,
|
|
237
|
+
memory: {
|
|
238
|
+
...params.memory,
|
|
239
|
+
thread: THREAD_ID,
|
|
240
|
+
resource: RESOURCE_ID,
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
return createUIMessageStreamResponse({ stream })
|
|
246
|
+
}
|
|
488
247
|
|
|
489
|
-
|
|
248
|
+
export const GET: APIRoute = async () => {
|
|
249
|
+
const memory = await mastra.getAgentById('weather-agent').getMemory()
|
|
250
|
+
let response = null
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
response = await memory?.recall({
|
|
254
|
+
threadId: THREAD_ID,
|
|
255
|
+
resourceId: RESOURCE_ID,
|
|
256
|
+
})
|
|
257
|
+
} catch {
|
|
258
|
+
console.log('No previous messages found.')
|
|
259
|
+
}
|
|
490
260
|
|
|
491
|
-
|
|
261
|
+
const uiMessages = toAISdkV5Messages(response?.messages || []);
|
|
492
262
|
|
|
493
|
-
|
|
494
|
-
|
|
263
|
+
return Response.json(uiMessages)
|
|
264
|
+
}
|
|
495
265
|
```
|
|
496
266
|
|
|
497
|
-
|
|
498
|
-
import type { APIRoute } from "astro";
|
|
267
|
+
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.
|
|
499
268
|
|
|
500
|
-
|
|
269
|
+
## Create a chat component
|
|
501
270
|
|
|
502
|
-
|
|
503
|
-
const { city } = await new Response(request.body).json();
|
|
504
|
-
const agent = mastra.getAgent("weatherAgent");
|
|
271
|
+
Create `src/components/chat.tsx`:
|
|
505
272
|
|
|
506
|
-
|
|
273
|
+
```tsx title="src/components/chat.tsx"
|
|
274
|
+
import '@/styles/global.css';
|
|
275
|
+
import { useEffect, useState } from 'react';
|
|
276
|
+
import { DefaultChatTransport, type ToolUIPart } from 'ai';
|
|
277
|
+
import { useChat } from '@ai-sdk/react';
|
|
507
278
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
279
|
+
import {
|
|
280
|
+
PromptInput,
|
|
281
|
+
PromptInputBody,
|
|
282
|
+
PromptInputTextarea,
|
|
283
|
+
} from '@/components/ai-elements/prompt-input';
|
|
513
284
|
|
|
514
|
-
|
|
285
|
+
import {
|
|
286
|
+
Conversation,
|
|
287
|
+
ConversationContent,
|
|
288
|
+
ConversationScrollButton,
|
|
289
|
+
} from '@/components/ai-elements/conversation';
|
|
515
290
|
|
|
516
|
-
|
|
291
|
+
import { Message, MessageContent, MessageResponse } from '@/components/ai-elements/message';
|
|
517
292
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
293
|
+
import {
|
|
294
|
+
Tool,
|
|
295
|
+
ToolHeader,
|
|
296
|
+
ToolContent,
|
|
297
|
+
ToolInput,
|
|
298
|
+
ToolOutput,
|
|
299
|
+
} from '@/components/ai-elements/tool';
|
|
521
300
|
|
|
522
|
-
```typescript title="src/components/form.tsx" showLineNumbers copy
|
|
523
|
-
import { useState } from "react";
|
|
524
301
|
|
|
525
|
-
|
|
526
|
-
const [
|
|
302
|
+
function Chat() {
|
|
303
|
+
const [input, setInput] = useState<string>('');
|
|
527
304
|
|
|
528
|
-
|
|
529
|
-
|
|
305
|
+
const { messages, setMessages, sendMessage, status } = useChat({
|
|
306
|
+
transport: new DefaultChatTransport({
|
|
307
|
+
api: '/api/chat',
|
|
308
|
+
}),
|
|
309
|
+
});
|
|
530
310
|
|
|
531
|
-
|
|
532
|
-
const
|
|
311
|
+
useEffect(() => {
|
|
312
|
+
const fetchMessages = async () => {
|
|
313
|
+
const res = await fetch('/api/chat');
|
|
314
|
+
const data = await res.json();
|
|
315
|
+
setMessages([...data]);
|
|
316
|
+
};
|
|
317
|
+
fetchMessages();
|
|
318
|
+
}, [setMessages]);
|
|
533
319
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
headers: { "Content-Type": "application/json" },
|
|
537
|
-
body: JSON.stringify({ city })
|
|
538
|
-
});
|
|
320
|
+
const handleSubmit = async () => {
|
|
321
|
+
if (!input.trim()) return;
|
|
539
322
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
}
|
|
323
|
+
sendMessage({ text: input });
|
|
324
|
+
setInput('');
|
|
325
|
+
};
|
|
543
326
|
|
|
544
327
|
return (
|
|
545
|
-
|
|
546
|
-
<
|
|
547
|
-
<
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
328
|
+
<div className="w-full p-6 relative size-full h-screen">
|
|
329
|
+
<div className="flex flex-col h-full">
|
|
330
|
+
<Conversation className="h-full">
|
|
331
|
+
<ConversationContent>
|
|
332
|
+
{messages.map((message) => (
|
|
333
|
+
<div key={message.id}>
|
|
334
|
+
{message.parts?.map((part, i) => {
|
|
335
|
+
if (part.type === 'text') {
|
|
336
|
+
return (
|
|
337
|
+
<Message
|
|
338
|
+
key={`${message.id}-${i}`}
|
|
339
|
+
from={message.role}>
|
|
340
|
+
<MessageContent>
|
|
341
|
+
<MessageResponse>{part.text}</MessageResponse>
|
|
342
|
+
</MessageContent>
|
|
343
|
+
</Message>
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (part.type?.startsWith('tool-')) {
|
|
348
|
+
return (
|
|
349
|
+
<Tool key={`${message.id}-${i}`}>
|
|
350
|
+
<ToolHeader
|
|
351
|
+
type={(part as ToolUIPart).type}
|
|
352
|
+
state={(part as ToolUIPart).state || 'output-available'}
|
|
353
|
+
className="cursor-pointer"
|
|
354
|
+
/>
|
|
355
|
+
<ToolContent>
|
|
356
|
+
<ToolInput input={(part as ToolUIPart).input || {}} />
|
|
357
|
+
<ToolOutput
|
|
358
|
+
output={(part as ToolUIPart).output}
|
|
359
|
+
errorText={(part as ToolUIPart).errorText}
|
|
360
|
+
/>
|
|
361
|
+
</ToolContent>
|
|
362
|
+
</Tool>
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return null;
|
|
367
|
+
})}
|
|
368
|
+
</div>
|
|
369
|
+
))}
|
|
370
|
+
<ConversationScrollButton />
|
|
371
|
+
</ConversationContent>
|
|
372
|
+
</Conversation>
|
|
373
|
+
|
|
374
|
+
<PromptInput onSubmit={handleSubmit} className="mt-20">
|
|
375
|
+
<PromptInputBody>
|
|
376
|
+
<PromptInputTextarea
|
|
377
|
+
onChange={(e) => setInput(e.target.value)}
|
|
378
|
+
className="md:leading-10"
|
|
379
|
+
value={input}
|
|
380
|
+
placeholder="Type your message..."
|
|
381
|
+
disabled={status !== 'ready'}
|
|
382
|
+
/>
|
|
383
|
+
</PromptInputBody>
|
|
384
|
+
</PromptInput>
|
|
385
|
+
</div>
|
|
386
|
+
</div>
|
|
552
387
|
);
|
|
553
|
-
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export default Chat;
|
|
554
391
|
```
|
|
555
392
|
|
|
556
|
-
|
|
393
|
+
This component connects [`useChat()`](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.
|
|
557
394
|
|
|
558
|
-
|
|
395
|
+
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.
|
|
559
396
|
|
|
560
|
-
|
|
397
|
+
## Render the chat component
|
|
561
398
|
|
|
562
|
-
|
|
563
|
-
touch src/pages/test.astro
|
|
564
|
-
```
|
|
399
|
+
The last step is to render the chat component on your index page. Edit `src/pages/index.astro`:
|
|
565
400
|
|
|
566
|
-
```
|
|
401
|
+
```html title="src/pages/index.astro" {2,14}
|
|
567
402
|
---
|
|
568
|
-
import
|
|
403
|
+
import Chat from '@/components/chat';
|
|
569
404
|
---
|
|
570
405
|
|
|
571
|
-
<
|
|
572
|
-
<
|
|
406
|
+
<html lang="en">
|
|
407
|
+
<head>
|
|
408
|
+
<meta charset="utf-8" />
|
|
409
|
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
410
|
+
<meta name="viewport" content="width=device-width" />
|
|
411
|
+
<meta name="generator" content={Astro.generator} />
|
|
412
|
+
<title>Astro</title>
|
|
413
|
+
</head>
|
|
414
|
+
<body>
|
|
415
|
+
<Chat client:load />
|
|
416
|
+
</body>
|
|
417
|
+
</html>
|
|
573
418
|
```
|
|
574
419
|
|
|
575
|
-
|
|
420
|
+
Import the `Chat` component and add it to the body with the `client:load` [directive](https://docs.astro.build/en/reference/directives-reference/#client-directives) so it runs on the client side.
|
|
576
421
|
|
|
577
|
-
|
|
422
|
+
## Test your agent
|
|
578
423
|
|
|
579
|
-
|
|
580
|
-
|
|
424
|
+
1. Run your Astro app with `npm run dev`
|
|
425
|
+
2. Open the chat at http://localhost:4321
|
|
426
|
+
3. Try asking about the weather. If your API key is set up correctly, you'll get a response
|
|
581
427
|
|
|
582
|
-
|
|
583
|
-
- **Humidity:** 63%
|
|
584
|
-
- **Wind Speed:** 14.7 km/h
|
|
585
|
-
- **Wind Gusts:** 32.4 km/h
|
|
586
|
-
- **Conditions:** Overcast
|
|
428
|
+
## Next steps
|
|
587
429
|
|
|
588
|
-
|
|
589
|
-
```
|
|
430
|
+
Congratulations on building your Mastra agent with Astro! 🎉
|
|
590
431
|
|
|
591
|
-
|
|
432
|
+
From here, you can extend the project with your own tools and logic:
|
|
592
433
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
434
|
+
- Learn more about [agents](/docs/v1/agents/overview)
|
|
435
|
+
- Give your agent its own [tools](/docs/v1/agents/using-tools)
|
|
436
|
+
- Add human-like [memory](/docs/v1/agents/agent-memory) to your agent
|
|
596
437
|
|
|
597
|
-
|
|
438
|
+
When you're ready, read more about how Mastra integrates with AI SDK UI and how to deploy your agent anywhere:
|
|
598
439
|
|
|
599
|
-
-
|
|
600
|
-
- [
|
|
440
|
+
- Integrate Mastra with [AI SDK UI](/guides/v1/build-your-ui/ai-sdk-ui)
|
|
441
|
+
- Deploy your agent [anywhere](/docs/v1/deployment/overview)
|