@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,500 +1,329 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "
|
|
3
|
-
description:
|
|
2
|
+
title: "SvelteKit | Frameworks"
|
|
3
|
+
description: "Get started with Mastra and SvelteKit"
|
|
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 SvelteKit project
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- Build flexible APIs to serve AI-powered features
|
|
16
|
-
- Simplify deployment with a unified codebase for frontend and backend
|
|
17
|
-
- Take advantage of SvelteKit's built-in [Actions](https://kit.svelte.dev/docs/form-actions) or [Server Endpoints](https://svelte.dev/docs/kit/routing#server) for efficient server-client workflows
|
|
18
|
-
|
|
19
|
-
Use this guide to scaffold and integrate Mastra with your SvelteKit project.
|
|
20
|
-
|
|
21
|
-
<Tabs>
|
|
22
|
-
<TabItem value="actions" label="Actions">
|
|
23
|
-
|
|
24
|
-
<Steps>
|
|
25
|
-
|
|
26
|
-
<StepItem>
|
|
27
|
-
|
|
28
|
-
Install Mastra
|
|
29
|
-
|
|
30
|
-
Install the required packages:
|
|
31
|
-
|
|
32
|
-
<Tabs>
|
|
33
|
-
<TabItem value="npm" label="npm">
|
|
34
|
-
```bash copy
|
|
35
|
-
npm install mastra@beta @mastra/core@beta @mastra/libsql@beta @ai-sdk/openai
|
|
36
|
-
```
|
|
37
|
-
</TabItem>
|
|
38
|
-
<TabItem value="yarn" label="yarn">
|
|
39
|
-
```bash copy
|
|
40
|
-
yarn add mastra@beta @mastra/core@beta @mastra/libsql@beta @ai-sdk/openai
|
|
41
|
-
```
|
|
42
|
-
</TabItem>
|
|
43
|
-
<TabItem value="pnpm" label="pnpm">
|
|
44
|
-
```bash copy
|
|
45
|
-
pnpm add mastra@beta @mastra/core@beta @mastra/libsql@beta @ai-sdk/openai
|
|
46
|
-
```
|
|
47
|
-
</TabItem>
|
|
48
|
-
<TabItem value="bun" label="bun">
|
|
49
|
-
```bash copy
|
|
50
|
-
bun add mastra@beta @mastra/core@beta @mastra/libsql@beta @ai-sdk/openai
|
|
51
|
-
```
|
|
52
|
-
</TabItem>
|
|
53
|
-
</Tabs>
|
|
54
|
-
|
|
55
|
-
</StepItem>
|
|
56
|
-
|
|
57
|
-
<StepItem>
|
|
58
|
-
|
|
59
|
-
To integrate Mastra into your project, you have two options:
|
|
11
|
+
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.
|
|
60
12
|
|
|
61
|
-
-
|
|
13
|
+
You'll use [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) to create a beautiful, interactive chat experience.
|
|
62
14
|
|
|
63
|
-
|
|
15
|
+
## Before you begin
|
|
64
16
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
```
|
|
17
|
+
- 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).
|
|
18
|
+
- Install Node.js `v22.13.0` or later
|
|
68
19
|
|
|
69
|
-
|
|
20
|
+
## Create a new SvelteKit app (optional)
|
|
70
21
|
|
|
71
|
-
|
|
22
|
+
If you already have a SvelteKit app using Tailwind, skip to the next step.
|
|
72
23
|
|
|
73
|
-
|
|
24
|
+
Run the following command to [create a new SvelteKit app](https://svelte.dev/docs/kit/creating-a-project):
|
|
74
25
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
```
|
|
26
|
+
<Tabs groupId="pm">
|
|
27
|
+
<TabItem value="npm" label="npm">
|
|
78
28
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
```json title="package.json"
|
|
82
|
-
{
|
|
83
|
-
"scripts": {
|
|
84
|
-
...
|
|
85
|
-
"dev:mastra": "mastra dev",
|
|
86
|
-
"build:mastra": "mastra build"
|
|
87
|
-
}
|
|
88
|
-
}
|
|
29
|
+
```bash
|
|
30
|
+
npx sv create mastra-svelte --template minimal --types ts --add tailwindcss="plugins:forms" --install npm
|
|
89
31
|
```
|
|
90
32
|
|
|
91
|
-
</
|
|
92
|
-
|
|
93
|
-
<StepItem>
|
|
94
|
-
|
|
95
|
-
Modify the `tsconfig.json` file in your project root:
|
|
96
|
-
|
|
97
|
-
```json title="tsconfig.json"
|
|
98
|
-
{
|
|
99
|
-
...
|
|
100
|
-
"exclude": ["dist", ".mastra"]
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
</StepItem>
|
|
105
|
-
|
|
106
|
-
<StepItem>
|
|
107
|
-
|
|
108
|
-
The `VITE_` prefix is required for environment variables to be accessible in the Vite environment, that SvelteKit uses.
|
|
109
|
-
[Read more about Vite environment variables](https://vite.dev/guide/env-and-mode.html#env-variables).
|
|
33
|
+
</TabItem>
|
|
34
|
+
<TabItem value="pnpm" label="pnpm">
|
|
110
35
|
|
|
111
|
-
```bash
|
|
112
|
-
|
|
36
|
+
```bash
|
|
37
|
+
pnpm dlx sv create mastra-svelte --template minimal --types ts --add tailwindcss="plugins:forms" --install pnpm
|
|
113
38
|
```
|
|
114
39
|
|
|
115
|
-
</
|
|
116
|
-
|
|
117
|
-
<StepItem>
|
|
118
|
-
|
|
119
|
-
Add `.mastra` to your `.gitignore` file:
|
|
40
|
+
</TabItem>
|
|
41
|
+
<TabItem value="yarn" label="yarn">
|
|
120
42
|
|
|
121
|
-
```bash
|
|
122
|
-
|
|
43
|
+
```bash
|
|
44
|
+
yarn dlx sv create mastra-svelte --template minimal --types ts --add tailwindcss="plugins:forms" --install yarn
|
|
123
45
|
```
|
|
124
46
|
|
|
125
|
-
</
|
|
126
|
-
|
|
127
|
-
<StepItem>
|
|
128
|
-
|
|
129
|
-
Update the Mastra Agent
|
|
130
|
-
|
|
131
|
-
```typescript title="src/mastra/agents/weather-agent.ts"
|
|
132
|
-
import { createOpenAI } from "@ai-sdk/openai";
|
|
47
|
+
</TabItem>
|
|
48
|
+
<TabItem value="bun" label="bun">
|
|
133
49
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
compatibility: "strict"
|
|
137
|
-
});
|
|
50
|
+
```bash
|
|
51
|
+
bun dlx sv create mastra-svelte --template minimal --types ts --add tailwindcss="plugins:forms" --install bun
|
|
138
52
|
```
|
|
139
53
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
> 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.
|
|
143
|
-
|
|
144
|
-
</StepItem>
|
|
145
|
-
|
|
146
|
-
<StepItem>
|
|
147
|
-
|
|
148
|
-
Start the Mastra Dev Server to expose your agents as REST endpoints:
|
|
149
|
-
|
|
150
|
-
<Tabs>
|
|
151
|
-
<TabItem value="npm" label="npm">
|
|
152
|
-
```bash copy
|
|
153
|
-
npm run dev:mastra
|
|
154
|
-
```
|
|
155
|
-
</TabItem>
|
|
156
|
-
<TabItem value="cli" label="CLI">
|
|
157
|
-
```bash copy
|
|
158
|
-
mastra dev:mastra
|
|
159
|
-
```
|
|
160
|
-
</TabItem>
|
|
54
|
+
</TabItem>
|
|
161
55
|
</Tabs>
|
|
162
56
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
</StepItem>
|
|
166
|
-
|
|
167
|
-
<StepItem>
|
|
168
|
-
|
|
169
|
-
With the Mastra Dev Server running, you can start your SvelteKit site in the usual way.
|
|
170
|
-
|
|
171
|
-
</StepItem>
|
|
57
|
+
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.
|
|
172
58
|
|
|
173
|
-
|
|
59
|
+
## Initialize Mastra
|
|
174
60
|
|
|
175
|
-
|
|
176
|
-
mkdir src/routes/test
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
</StepItem>
|
|
180
|
-
|
|
181
|
-
<StepItem>
|
|
182
|
-
|
|
183
|
-
Create a new Action, and add the example code:
|
|
184
|
-
|
|
185
|
-
```bash copy
|
|
186
|
-
touch src/routes/test/+page.server.ts
|
|
187
|
-
```
|
|
61
|
+
`cd` into your SvelteKit project and run [`mastra init`](/reference/v1/cli/mastra#mastra-init).
|
|
188
62
|
|
|
189
|
-
|
|
190
|
-
import type { Actions } from "./$types";
|
|
191
|
-
import { mastra } from "../../mastra";
|
|
63
|
+
When prompted, choose a provider (e.g. OpenAI) and enter your key:
|
|
192
64
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const city = (await event.request.formData()).get("city")!.toString();
|
|
196
|
-
const agent = mastra.getAgent("weatherAgent");
|
|
65
|
+
<Tabs groupId="pm">
|
|
66
|
+
<TabItem value="npm" label="npm">
|
|
197
67
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
} satisfies Actions;
|
|
68
|
+
```bash
|
|
69
|
+
cd mastra-svelte
|
|
70
|
+
npx mastra@beta init
|
|
202
71
|
```
|
|
203
72
|
|
|
204
|
-
</
|
|
205
|
-
|
|
206
|
-
<StepItem>
|
|
207
|
-
|
|
208
|
-
Create a new Page file, and add the example code:
|
|
73
|
+
</TabItem>
|
|
74
|
+
<TabItem value="pnpm" label="pnpm">
|
|
209
75
|
|
|
210
|
-
```bash
|
|
211
|
-
|
|
76
|
+
```bash
|
|
77
|
+
cd mastra-svelte
|
|
78
|
+
pnpm dlx mastra@beta init
|
|
212
79
|
```
|
|
213
80
|
|
|
214
|
-
|
|
215
|
-
<
|
|
216
|
-
import type { PageProps} from './$types';
|
|
217
|
-
let { form }: PageProps = $props();
|
|
218
|
-
</script>
|
|
219
|
-
|
|
220
|
-
<h1>Test</h1>
|
|
221
|
-
|
|
222
|
-
<form method="POST">
|
|
223
|
-
<input name="city" placeholder="Enter city" required />
|
|
224
|
-
<button type="submit">Get Weather</button>
|
|
225
|
-
</form>
|
|
226
|
-
|
|
227
|
-
{#if form?.result}
|
|
228
|
-
<pre>{form.result}</pre>
|
|
229
|
-
{/if}
|
|
81
|
+
</TabItem>
|
|
82
|
+
<TabItem value="yarn" label="yarn">
|
|
230
83
|
|
|
84
|
+
```bash
|
|
85
|
+
cd mastra-svelte
|
|
86
|
+
yarn dlx mastra@beta init
|
|
231
87
|
```
|
|
232
88
|
|
|
233
|
-
>
|
|
234
|
-
|
|
235
|
-
Submitting **London** as the city would return a result similar to:
|
|
236
|
-
|
|
237
|
-
```plaintext
|
|
238
|
-
The current weather in London is as follows:
|
|
239
|
-
|
|
240
|
-
- **Temperature:** 16°C (feels like 13.8°C)
|
|
241
|
-
- **Humidity:** 62%
|
|
242
|
-
- **Wind Speed:** 12.6 km/h
|
|
243
|
-
- **Wind Gusts:** 32.4 km/h
|
|
244
|
-
- **Conditions:** Overcast
|
|
89
|
+
</TabItem>
|
|
90
|
+
<TabItem value="bun" label="bun">
|
|
245
91
|
|
|
246
|
-
|
|
92
|
+
```bash
|
|
93
|
+
cd mastra-svelte
|
|
94
|
+
bunx mastra@beta init
|
|
247
95
|
```
|
|
248
96
|
|
|
249
|
-
</StepItem>
|
|
250
|
-
|
|
251
|
-
</Steps>
|
|
252
97
|
</TabItem>
|
|
253
|
-
|
|
254
|
-
<TabItem value="server-endpoints" label="Server Endpoints">
|
|
255
|
-
|
|
256
|
-
<Steps>
|
|
257
|
-
|
|
258
|
-
<StepItem>
|
|
259
|
-
|
|
260
|
-
Install the required packages:
|
|
261
|
-
|
|
262
|
-
<Tabs>
|
|
263
|
-
<TabItem value="npm" label="npm">
|
|
264
|
-
```bash copy
|
|
265
|
-
npm install mastra@beta @mastra/core@beta @mastra/libsql@beta @ai-sdk/openai
|
|
266
|
-
```
|
|
267
|
-
</TabItem>
|
|
268
|
-
<TabItem value="yarn" label="yarn">
|
|
269
|
-
```bash copy
|
|
270
|
-
yarn add mastra@beta @mastra/core@beta @mastra/libsql@beta @ai-sdk/openai
|
|
271
|
-
```
|
|
272
|
-
</TabItem>
|
|
273
|
-
<TabItem value="pnpm" label="pnpm">
|
|
274
|
-
```bash copy
|
|
275
|
-
pnpm add mastra@beta @mastra/core@beta @mastra/libsql@beta @ai-sdk/openai
|
|
276
|
-
```
|
|
277
|
-
</TabItem>
|
|
278
|
-
<TabItem value="bun" label="bun">
|
|
279
|
-
```bash copy
|
|
280
|
-
bun add mastra@beta @mastra/core@beta @mastra/libsql@beta @ai-sdk/openai
|
|
281
|
-
```
|
|
282
|
-
</TabItem>
|
|
283
98
|
</Tabs>
|
|
284
99
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
<StepItem>
|
|
288
|
-
|
|
289
|
-
To integrate Mastra into your project, you have two options:
|
|
290
|
-
|
|
291
|
-
- Use the One-Liner
|
|
292
|
-
|
|
293
|
-
Run the following command to quickly scaffold the default Weather agent with sensible defaults:
|
|
100
|
+
This creates a `src/mastra` folder with an example weather agent and the following files:
|
|
294
101
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
102
|
+
- `index.ts` - Mastra config, including memory
|
|
103
|
+
- `tools/weather-tool.ts` - a tool to fetch weather for a given location
|
|
104
|
+
- `agents/weather-agent.ts`- a weather agent with a prompt that uses the tool
|
|
298
105
|
|
|
299
|
-
|
|
106
|
+
You'll call `weather-agent.ts` from your SvelteKit routes in the next steps.
|
|
300
107
|
|
|
301
|
-
|
|
108
|
+
## Install AI SDK UI
|
|
302
109
|
|
|
303
|
-
|
|
110
|
+
Install AI SDK UI along with the Mastra adapter:
|
|
304
111
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
```
|
|
112
|
+
<Tabs groupId="pm">
|
|
113
|
+
<TabItem value="npm" label="npm">
|
|
308
114
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
```json title="package.json"
|
|
312
|
-
{
|
|
313
|
-
"scripts": {
|
|
314
|
-
...
|
|
315
|
-
"dev:mastra": "mastra dev",
|
|
316
|
-
"build:mastra": "mastra build"
|
|
317
|
-
}
|
|
318
|
-
}
|
|
115
|
+
```bash
|
|
116
|
+
npm install @mastra/ai-sdk@beta @ai-sdk/svelte ai
|
|
319
117
|
```
|
|
320
118
|
|
|
321
|
-
</
|
|
322
|
-
|
|
323
|
-
<StepItem>
|
|
324
|
-
|
|
325
|
-
Modify the `tsconfig.json` file in your project root:
|
|
326
|
-
|
|
327
|
-
```json title="tsconfig.json"
|
|
328
|
-
{
|
|
329
|
-
...
|
|
330
|
-
"exclude": ["dist", ".mastra"]
|
|
331
|
-
}
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
</StepItem>
|
|
335
|
-
|
|
336
|
-
<StepItem>
|
|
337
|
-
|
|
338
|
-
The `VITE_` prefix is required for environment variables to be accessible in the Vite environment, that SvelteKit uses.
|
|
339
|
-
[Read more about Vite environment variables](https://vite.dev/guide/env-and-mode.html#env-variables).
|
|
119
|
+
</TabItem>
|
|
120
|
+
<TabItem value="pnpm" label="pnpm">
|
|
340
121
|
|
|
341
|
-
```bash
|
|
342
|
-
|
|
122
|
+
```bash
|
|
123
|
+
pnpm add @mastra/ai-sdk@beta @ai-sdk/svelte ai
|
|
343
124
|
```
|
|
344
125
|
|
|
345
|
-
</
|
|
346
|
-
|
|
347
|
-
<StepItem>
|
|
348
|
-
|
|
349
|
-
Add `.mastra` to your `.gitignore` file:
|
|
126
|
+
</TabItem>
|
|
127
|
+
<TabItem value="yarn" label="yarn">
|
|
350
128
|
|
|
351
|
-
```bash
|
|
352
|
-
|
|
129
|
+
```bash
|
|
130
|
+
yarn add @mastra/ai-sdk@beta @ai-sdk/svelte ai
|
|
353
131
|
```
|
|
354
132
|
|
|
355
|
-
</
|
|
356
|
-
|
|
357
|
-
<StepItem>
|
|
358
|
-
|
|
359
|
-
Update the Mastra Agent
|
|
360
|
-
|
|
361
|
-
```typescript title="src/mastra/agents/weather-agent.ts"
|
|
362
|
-
import { createOpenAI } from "@ai-sdk/openai";
|
|
133
|
+
</TabItem>
|
|
134
|
+
<TabItem value="bun" label="bun">
|
|
363
135
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
compatibility: "strict"
|
|
367
|
-
});
|
|
136
|
+
```bash
|
|
137
|
+
bun add @mastra/ai-sdk@beta @ai-sdk/svelte ai
|
|
368
138
|
```
|
|
369
139
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
> 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.
|
|
373
|
-
|
|
374
|
-
</StepItem>
|
|
375
|
-
|
|
376
|
-
<StepItem>
|
|
377
|
-
|
|
378
|
-
Start the Mastra Dev Server to expose your agents as REST endpoints:
|
|
379
|
-
|
|
380
|
-
<Tabs>
|
|
381
|
-
<TabItem value="npm" label="npm">
|
|
382
|
-
```bash copy
|
|
383
|
-
npm run dev:mastra
|
|
384
|
-
```
|
|
385
|
-
</TabItem>
|
|
386
|
-
<TabItem value="cli" label="CLI">
|
|
387
|
-
```bash copy
|
|
388
|
-
mastra dev:mastra
|
|
389
|
-
```
|
|
390
|
-
</TabItem>
|
|
140
|
+
</TabItem>
|
|
391
141
|
</Tabs>
|
|
392
142
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
143
|
+
## Create a chat route
|
|
144
|
+
|
|
145
|
+
Create `src/routes/api/chat/+server.ts`:
|
|
146
|
+
|
|
147
|
+
```ts title="src/routes/api/chat/+server.ts"
|
|
148
|
+
import type { RequestHandler } from "./$types";
|
|
149
|
+
import { handleChatStream } from "@mastra/ai-sdk";
|
|
150
|
+
import { toAISdkV5Messages } from "@mastra/ai-sdk/ui";
|
|
151
|
+
import { createUIMessageStreamResponse } from "ai";
|
|
152
|
+
import { mastra } from "../../../mastra";
|
|
153
|
+
|
|
154
|
+
const THREAD_ID = "example-user-id";
|
|
155
|
+
const RESOURCE_ID = "weather-chat";
|
|
156
|
+
|
|
157
|
+
export const POST: RequestHandler = async ({ request }) => {
|
|
158
|
+
const params = await request.json();
|
|
159
|
+
const stream = await handleChatStream({
|
|
160
|
+
mastra,
|
|
161
|
+
agentId: "weather-agent",
|
|
162
|
+
params: {
|
|
163
|
+
...params,
|
|
164
|
+
memory: {
|
|
165
|
+
...params.memory,
|
|
166
|
+
thread: THREAD_ID,
|
|
167
|
+
resource: RESOURCE_ID,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return createUIMessageStreamResponse({ stream });
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export const GET: RequestHandler = async () => {
|
|
176
|
+
const memory = await mastra.getAgentById("weather-agent").getMemory();
|
|
177
|
+
let response = null;
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
response = await memory?.recall({
|
|
181
|
+
threadId: THREAD_ID,
|
|
182
|
+
resourceId: RESOURCE_ID,
|
|
183
|
+
});
|
|
184
|
+
} catch {
|
|
185
|
+
console.log("No previous messages found.");
|
|
186
|
+
}
|
|
412
187
|
|
|
413
|
-
|
|
188
|
+
const uiMessages = toAISdkV5Messages(response?.messages || []);
|
|
414
189
|
|
|
415
|
-
|
|
416
|
-
|
|
190
|
+
return Response.json(uiMessages);
|
|
191
|
+
};
|
|
417
192
|
```
|
|
418
193
|
|
|
419
|
-
|
|
420
|
-
import { json } from "@sveltejs/kit";
|
|
421
|
-
import { mastra } from "../../mastra";
|
|
194
|
+
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.
|
|
422
195
|
|
|
423
|
-
|
|
424
|
-
const { city } = await request.json();
|
|
196
|
+
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`.
|
|
425
197
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
198
|
+
```ts title="src/routes/+page.ts"
|
|
199
|
+
import type { UIDataTypes, UIMessage, UITools } from "ai";
|
|
200
|
+
import type { PageLoad } from "./$types";
|
|
429
201
|
|
|
430
|
-
|
|
431
|
-
|
|
202
|
+
export const load: PageLoad = async ({ fetch }) => {
|
|
203
|
+
const response = await fetch("/api/chat");
|
|
204
|
+
const initialMessages = (await response.json()) as UIMessage<
|
|
205
|
+
unknown,
|
|
206
|
+
UIDataTypes,
|
|
207
|
+
UITools
|
|
208
|
+
>[];
|
|
209
|
+
return { initialMessages };
|
|
210
|
+
};
|
|
432
211
|
```
|
|
433
212
|
|
|
434
|
-
|
|
213
|
+
## Add the chat UI
|
|
435
214
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
Create a new Page, and add the example code:
|
|
439
|
-
|
|
440
|
-
```bash copy
|
|
441
|
-
touch src/routes/weather-api-test/+page.svelte
|
|
442
|
-
```
|
|
215
|
+
Replace `src/routes/+page.svelte` with the following.
|
|
443
216
|
|
|
444
|
-
```
|
|
217
|
+
```html title="src/routes/+page.svelte"
|
|
445
218
|
<script lang="ts">
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
219
|
+
import { Chat } from '@ai-sdk/svelte';
|
|
220
|
+
import { DefaultChatTransport, type ToolUIPart } from 'ai';
|
|
221
|
+
|
|
222
|
+
let input = $state('');
|
|
223
|
+
const { data } = $props();
|
|
224
|
+
let messages = $derived(data.initialMessages)
|
|
225
|
+
|
|
226
|
+
const chat = new Chat({
|
|
227
|
+
transport: new DefaultChatTransport({
|
|
228
|
+
api: '/api/chat'
|
|
229
|
+
}),
|
|
230
|
+
get messages() {
|
|
231
|
+
return messages;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
function handleSubmit(event: SubmitEvent) {
|
|
236
|
+
event.preventDefault();
|
|
237
|
+
chat.sendMessage({ text: input });
|
|
238
|
+
input = '';
|
|
239
|
+
}
|
|
464
240
|
|
|
465
|
-
<
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
241
|
+
const STATE_TO_LABEL_MAP: Record<ToolUIPart["state"], string> = {
|
|
242
|
+
"input-streaming": "Pending",
|
|
243
|
+
"input-available": "Running",
|
|
244
|
+
// @ts-expect-error - Only available in AI SDK v6
|
|
245
|
+
"approval-requested": "Awaiting Approval",
|
|
246
|
+
"approval-responded": "Responded",
|
|
247
|
+
"output-available": "Completed",
|
|
248
|
+
"output-error": "Error",
|
|
249
|
+
"output-denied": "Denied",
|
|
250
|
+
};
|
|
251
|
+
</script>
|
|
470
252
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
253
|
+
<main class="max-w-3xl mx-auto p-6 size-full h-screen">
|
|
254
|
+
<div class="flex flex-col h-full">
|
|
255
|
+
<div class="flex-1 min-h-0 overflow-y-auto" data-name="conversation">
|
|
256
|
+
<div data-name="conversation-content" class="flex flex-col gap-8">
|
|
257
|
+
{#each chat.messages as message, messageIndex (messageIndex)}
|
|
258
|
+
<div>
|
|
259
|
+
{#each message.parts as part, partIndex (partIndex)}
|
|
260
|
+
{#if part.type === 'text'}
|
|
261
|
+
<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']}>
|
|
262
|
+
<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",
|
|
263
|
+
"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",
|
|
264
|
+
"group-[.is-assistant]:text-foreground"]}>
|
|
265
|
+
<div data-name="message-response" class="size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0">
|
|
266
|
+
{part.text}
|
|
267
|
+
</div>
|
|
268
|
+
</div>
|
|
269
|
+
</div>
|
|
270
|
+
{:else if part.type.startsWith('tool-')}
|
|
271
|
+
<div data-name="tool" class="not-prose mb-6 w-full rounded-lg border border-gray-300 shadow">
|
|
272
|
+
<details data-name="tool-header" class="w-full p-3 hover:cursor-pointer">
|
|
273
|
+
<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>
|
|
274
|
+
<div data-name="tool-content" class="">
|
|
275
|
+
<div data-name="tool-input" class="space-y-2 overflow-hidden py-4">
|
|
276
|
+
<div class="font-medium text-muted-foreground text-xs uppercase tracking-wide">Parameters</div>
|
|
277
|
+
<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>
|
|
278
|
+
</div>
|
|
279
|
+
<div data-name="tool-output" class="space-y-2 overflow-hidden py-4">
|
|
280
|
+
<div class="font-medium text-muted-foreground text-xs uppercase tracking-wide">{(part as ToolUIPart).errorText ? 'Error' : 'Result'}</div>
|
|
281
|
+
<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>
|
|
282
|
+
{#if (part as ToolUIPart).errorText}
|
|
283
|
+
<div data-name="tool-error" class="text-red-600">
|
|
284
|
+
{(part as ToolUIPart).errorText}
|
|
285
|
+
</div>
|
|
286
|
+
{/if}
|
|
287
|
+
</div>
|
|
288
|
+
</div>
|
|
289
|
+
</details>
|
|
290
|
+
</div>
|
|
291
|
+
{/if}
|
|
292
|
+
{/each}
|
|
293
|
+
</div>
|
|
294
|
+
{/each}
|
|
295
|
+
</div>
|
|
296
|
+
</div>
|
|
297
|
+
<form class="w-full grid grid-cols-[1fr_auto] gap-6 shrink-0 pt-4" onsubmit={handleSubmit} data-name="prompt-input">
|
|
298
|
+
<input name="chat-input" class="rounded-lg border border-gray-300 shadow h-10" placeholder="City name" bind:value={input} />
|
|
299
|
+
<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>
|
|
300
|
+
</form>
|
|
301
|
+
</div>
|
|
302
|
+
</main>
|
|
474
303
|
```
|
|
475
304
|
|
|
476
|
-
|
|
305
|
+
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.
|
|
477
306
|
|
|
478
|
-
|
|
307
|
+
It renders the response text using custom message and tool components.
|
|
479
308
|
|
|
480
|
-
|
|
481
|
-
The current weather in London is as follows:
|
|
309
|
+
## Test your agent
|
|
482
310
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
- **Wind Gusts:** 30.6 km/h
|
|
487
|
-
- **Conditions:** Overcast
|
|
311
|
+
1. Run your SvelteKit app with `npm run dev`
|
|
312
|
+
2. Open the chat at http://localhost:5173
|
|
313
|
+
3. Try asking about the weather. If your API key is set up correctly, you'll get a response
|
|
488
314
|
|
|
489
|
-
|
|
490
|
-
```
|
|
315
|
+
## Next steps
|
|
491
316
|
|
|
492
|
-
|
|
317
|
+
Congratulations on building your Mastra agent with SvelteKit! 🎉
|
|
493
318
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
319
|
+
From here, you can extend the project with your own tools and logic:
|
|
320
|
+
|
|
321
|
+
- Learn more about [agents](/docs/v1/agents/overview)
|
|
322
|
+
- Give your agent its own [tools](/docs/v1/agents/using-tools)
|
|
323
|
+
- Add human-like [memory](/docs/v1/agents/agent-memory) to your agent
|
|
497
324
|
|
|
498
|
-
|
|
325
|
+
When you're ready, read more about how Mastra integrates with AI SDK UI and SvelteKit, and how to deploy your agent anywhere:
|
|
499
326
|
|
|
500
|
-
- [
|
|
327
|
+
- Integrate Mastra with [AI SDK UI](/guides/v1/build-your-ui/ai-sdk-ui)
|
|
328
|
+
- Deploy your agent [anywhere](/docs/v1/deployment/overview)
|
|
329
|
+
- Try the [unofficial Svelte AI Elements](https://svelte-ai-elements.vercel.app/)
|