@mastra/mcp-docs-server 1.0.0-beta.10 → 1.0.0-beta.13
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 +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +50 -50
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +109 -109
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +38 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +264 -264
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +37 -37
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Flance.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +104 -104
- package/.docs/organized/changelogs/%40mastra%2Freact.md +66 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +59 -59
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +39 -39
- package/.docs/organized/changelogs/create-mastra.md +31 -31
- package/.docs/organized/changelogs/mastra.md +49 -49
- package/.docs/organized/code-examples/quick-start.md +0 -4
- package/.docs/organized/code-examples/stock-price-tool.md +21 -2
- package/.docs/raw/agents/agent-approval.mdx +136 -2
- package/.docs/raw/agents/agent-memory.mdx +4 -4
- package/.docs/raw/agents/guardrails.mdx +44 -7
- package/.docs/raw/agents/networks.mdx +1 -1
- package/.docs/raw/agents/overview.mdx +2 -2
- package/.docs/raw/agents/processors.mdx +151 -0
- package/.docs/raw/agents/using-tools.mdx +1 -1
- package/.docs/raw/course/01-first-agent/07-creating-your-agent.md +1 -2
- package/.docs/raw/course/01-first-agent/12-connecting-tool-to-agent.md +1 -1
- package/.docs/raw/course/01-first-agent/16-adding-memory-to-agent.md +1 -2
- package/.docs/raw/course/02-agent-tools-mcp/05-updating-your-agent.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/10-updating-agent-instructions-zapier.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/16-updating-agent-instructions-github.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/21-updating-agent-instructions-hackernews.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/27-updating-agent-instructions-filesystem.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/31-enhancing-memory-configuration.md +2 -2
- package/.docs/raw/course/03-agent-memory/04-creating-basic-memory-agent.md +1 -2
- package/.docs/raw/course/03-agent-memory/08-configuring-conversation-history.md +1 -2
- package/.docs/raw/course/03-agent-memory/16-configuring-semantic-recall.md +3 -4
- package/.docs/raw/course/03-agent-memory/21-configuring-working-memory.md +2 -3
- package/.docs/raw/course/03-agent-memory/22-custom-working-memory-templates.md +2 -3
- package/.docs/raw/course/03-agent-memory/25-combining-memory-features.md +1 -2
- package/.docs/raw/course/03-agent-memory/27-creating-learning-assistant.md +2 -3
- package/.docs/raw/course/04-workflows/11-creating-an-ai-agent.md +2 -3
- package/.docs/raw/deployment/cloud-providers.mdx +20 -0
- package/.docs/raw/deployment/{building-mastra.mdx → mastra-server.mdx} +2 -2
- package/.docs/raw/deployment/monorepo.mdx +23 -44
- package/.docs/raw/deployment/overview.mdx +28 -53
- package/.docs/raw/deployment/web-framework.mdx +12 -14
- package/.docs/raw/getting-started/mcp-docs-server.mdx +57 -0
- package/.docs/raw/getting-started/start.mdx +10 -1
- package/.docs/raw/getting-started/studio.mdx +25 -2
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +1021 -67
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/aws-lambda.mdx +3 -6
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/azure-app-services.mdx +4 -6
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/cloudflare-deployer.mdx +4 -0
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/digital-ocean.mdx +3 -6
- package/.docs/raw/guides/deployment/index.mdx +32 -0
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/netlify-deployer.mdx +4 -0
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/vercel-deployer.mdx +4 -0
- package/.docs/raw/guides/getting-started/express.mdx +71 -152
- package/.docs/raw/guides/getting-started/hono.mdx +227 -0
- package/.docs/raw/guides/getting-started/next-js.mdx +173 -63
- package/.docs/raw/guides/getting-started/vite-react.mdx +307 -137
- package/.docs/raw/guides/guide/research-assistant.mdx +4 -4
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +70 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/client.mdx +17 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/overview.mdx +6 -0
- package/.docs/raw/index.mdx +1 -1
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/dashboard.mdx +2 -6
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/observability.mdx +1 -5
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/overview.mdx +2 -6
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/setting-up.mdx +3 -6
- package/.docs/raw/memory/overview.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-pg.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +1 -1
- package/.docs/raw/{server-db/storage.mdx → memory/storage/overview.mdx} +2 -2
- package/.docs/raw/observability/logging.mdx +1 -1
- package/.docs/raw/observability/tracing/exporters/cloud.mdx +1 -1
- package/.docs/raw/observability/tracing/exporters/default.mdx +1 -1
- package/.docs/raw/rag/chunking-and-embedding.mdx +12 -25
- package/.docs/raw/rag/graph-rag.mdx +220 -0
- package/.docs/raw/rag/overview.mdx +1 -2
- package/.docs/raw/rag/retrieval.mdx +13 -29
- package/.docs/raw/rag/vector-databases.mdx +7 -3
- package/.docs/raw/reference/agents/agent.mdx +11 -4
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getDefaultOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getInstructions.mdx +1 -1
- package/.docs/raw/reference/agents/getLLM.mdx +1 -1
- package/.docs/raw/reference/agents/getMemory.mdx +1 -1
- package/.docs/raw/reference/agents/getModel.mdx +1 -1
- package/.docs/raw/reference/agents/listScorers.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/chat-route.mdx +1 -1
- 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 +1 -1
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v4-messages.mdx +127 -0
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v5-messages.mdx +107 -0
- package/.docs/raw/reference/ai-sdk/workflow-route.mdx +1 -1
- package/.docs/raw/reference/auth/auth0.mdx +1 -1
- package/.docs/raw/reference/auth/clerk.mdx +1 -1
- package/.docs/raw/reference/auth/firebase.mdx +1 -1
- package/.docs/raw/reference/auth/jwt.mdx +1 -1
- package/.docs/raw/reference/auth/supabase.mdx +1 -1
- package/.docs/raw/reference/auth/workos.mdx +1 -1
- package/.docs/raw/reference/cli/mastra.mdx +1 -1
- package/.docs/raw/reference/client-js/mastra-client.mdx +1 -1
- package/.docs/raw/reference/client-js/workflows.mdx +20 -0
- package/.docs/raw/reference/core/getServer.mdx +3 -3
- package/.docs/raw/reference/core/getStorage.mdx +1 -1
- package/.docs/raw/reference/core/getStoredAgentById.mdx +1 -1
- package/.docs/raw/reference/core/listStoredAgents.mdx +1 -1
- package/.docs/raw/reference/core/setStorage.mdx +1 -1
- package/.docs/raw/reference/logging/pino-logger.mdx +1 -1
- package/.docs/raw/reference/processors/processor-interface.mdx +314 -13
- package/.docs/raw/reference/rag/database-config.mdx +1 -1
- package/.docs/raw/reference/server/create-route.mdx +1 -1
- package/.docs/raw/reference/server/express-adapter.mdx +4 -4
- package/.docs/raw/reference/server/hono-adapter.mdx +4 -4
- package/.docs/raw/reference/server/mastra-server.mdx +2 -2
- package/.docs/raw/reference/server/routes.mdx +28 -1
- package/.docs/raw/reference/streaming/ChunkType.mdx +23 -2
- package/.docs/raw/reference/streaming/agents/stream.mdx +38 -29
- package/.docs/raw/reference/streaming/workflows/stream.mdx +33 -20
- package/.docs/raw/reference/tools/create-tool.mdx +23 -1
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +3 -3
- package/.docs/raw/reference/tools/vector-query-tool.mdx +3 -3
- package/.docs/raw/reference/workflows/run-methods/startAsync.mdx +143 -0
- package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +35 -0
- package/.docs/raw/reference/workflows/workflow-methods/foreach.mdx +68 -3
- package/.docs/raw/reference/workflows/workflow.mdx +37 -0
- package/.docs/raw/{auth → server/auth}/auth0.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/clerk.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/firebase.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/index.mdx +6 -6
- package/.docs/raw/{auth → server/auth}/jwt.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/supabase.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/workos.mdx +1 -1
- package/.docs/raw/{server-db → server}/custom-adapters.mdx +3 -3
- package/.docs/raw/{server-db → server}/custom-api-routes.mdx +1 -1
- package/.docs/raw/{server-db → server}/mastra-client.mdx +2 -2
- package/.docs/raw/{server-db → server}/mastra-server.mdx +12 -10
- package/.docs/raw/{server-db → server}/middleware.mdx +2 -2
- package/.docs/raw/{server-db → server}/request-context.mdx +3 -3
- package/.docs/raw/{server-db → server}/server-adapters.mdx +6 -6
- package/.docs/raw/tools-mcp/overview.mdx +2 -2
- package/.docs/raw/workflows/control-flow.mdx +348 -2
- package/.docs/raw/workflows/error-handling.mdx +162 -1
- package/.docs/raw/workflows/overview.mdx +2 -2
- package/CHANGELOG.md +21 -0
- package/package.json +5 -5
- package/.docs/organized/changelogs/%40internal%2Fai-sdk-v4.md +0 -1
- package/.docs/raw/deployment/cloud-providers/index.mdx +0 -55
- /package/.docs/raw/{deployment/cloud-providers → guides/deployment}/amazon-ec2.mdx +0 -0
|
@@ -7,7 +7,7 @@ import PropertiesTable from "@site/src/components/PropertiesTable";
|
|
|
7
7
|
|
|
8
8
|
# chatRoute()
|
|
9
9
|
|
|
10
|
-
Creates a chat route handler for streaming agent conversations using the AI SDK format. This function registers an HTTP `POST` endpoint that accepts messages, executes an agent, and streams the response back to the client in AI SDK-compatible format. You have to use it inside a [custom API route](/docs/v1/server
|
|
10
|
+
Creates a chat route handler for streaming agent conversations using the AI SDK format. This function registers an HTTP `POST` endpoint that accepts messages, executes an agent, and streams the response back to the client in AI SDK-compatible format. You have to use it inside a [custom API route](/docs/v1/server/custom-api-routes).
|
|
11
11
|
|
|
12
12
|
Use [`handleChatStream()`](/reference/v1/ai-sdk/handle-chat-stream) if you need a framework-agnostic handler.
|
|
13
13
|
|
|
@@ -7,7 +7,7 @@ import PropertiesTable from "@site/src/components/PropertiesTable";
|
|
|
7
7
|
|
|
8
8
|
# handleChatStream()
|
|
9
9
|
|
|
10
|
-
Framework-agnostic handler for streaming agent chat in AI SDK-compatible format. Use this function directly when you need to handle chat streaming outside Hono or Mastra's own [apiRoutes](/docs/v1/server
|
|
10
|
+
Framework-agnostic handler for streaming agent chat in AI SDK-compatible format. Use this function directly when you need to handle chat streaming outside Hono or Mastra's own [apiRoutes](/docs/v1/server/custom-api-routes) feature.
|
|
11
11
|
|
|
12
12
|
`handleChatStream()` returns a `ReadableStream` that you can wrap with [`createUIMessageStreamResponse()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response).
|
|
13
13
|
|
|
@@ -7,7 +7,7 @@ import PropertiesTable from "@site/src/components/PropertiesTable";
|
|
|
7
7
|
|
|
8
8
|
# handleNetworkStream()
|
|
9
9
|
|
|
10
|
-
Framework-agnostic handler for streaming network execution in AI SDK-compatible format. Use this function directly when you need to handle network streaming outside Hono or Mastra's own [apiRoutes](/docs/v1/server
|
|
10
|
+
Framework-agnostic handler for streaming network execution in AI SDK-compatible format. Use this function directly when you need to handle network streaming outside Hono or Mastra's own [apiRoutes](/docs/v1/server/custom-api-routes) feature.
|
|
11
11
|
|
|
12
12
|
`handleNetworkStream()` returns a `ReadableStream` that you can wrap with [`createUIMessageStreamResponse()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response).
|
|
13
13
|
|
|
@@ -7,7 +7,7 @@ import PropertiesTable from "@site/src/components/PropertiesTable";
|
|
|
7
7
|
|
|
8
8
|
# handleWorkflowStream()
|
|
9
9
|
|
|
10
|
-
Framework-agnostic handler for streaming workflow execution in AI SDK-compatible format. Use this function directly when you need to handle workflow streaming outside Hono or Mastra's own [apiRoutes](/docs/v1/server
|
|
10
|
+
Framework-agnostic handler for streaming workflow execution in AI SDK-compatible format. Use this function directly when you need to handle workflow streaming outside Hono or Mastra's own [apiRoutes](/docs/v1/server/custom-api-routes) feature.
|
|
11
11
|
|
|
12
12
|
`handleWorkflowStream()` returns a `ReadableStream` that you can wrap with [`createUIMessageStreamResponse()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response).
|
|
13
13
|
|
|
@@ -7,7 +7,7 @@ import PropertiesTable from "@site/src/components/PropertiesTable";
|
|
|
7
7
|
|
|
8
8
|
# networkRoute()
|
|
9
9
|
|
|
10
|
-
Creates a network route handler for streaming network execution using the AI SDK format. This function registers an HTTP `POST` endpoint that accepts messages, executes an agent network, and streams the response back to the client in AI SDK-compatible format. Agent networks allow a routing agent to delegate tasks to other agents. You have to use it inside a [custom API route](/docs/v1/server
|
|
10
|
+
Creates a network route handler for streaming network execution using the AI SDK format. This function registers an HTTP `POST` endpoint that accepts messages, executes an agent network, and streams the response back to the client in AI SDK-compatible format. Agent networks allow a routing agent to delegate tasks to other agents. You have to use it inside a [custom API route](/docs/v1/server/custom-api-routes).
|
|
11
11
|
|
|
12
12
|
Use [`handleNetworkStream()`](/reference/v1/ai-sdk/handle-network-stream) if you need a framework-agnostic handler.
|
|
13
13
|
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: toAISdkV4Messages() | AI SDK"
|
|
3
|
+
description: API reference for toAISdkV4Messages(), a function to convert Mastra messages to AI SDK v4 UI messages.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import PropertiesTable from "@site/src/components/PropertiesTable";
|
|
7
|
+
|
|
8
|
+
# toAISdkV4Messages()
|
|
9
|
+
|
|
10
|
+
Converts messages from various input formats to AI SDK V4 UI message format. This function accepts messages in multiple formats (strings, AI SDK V4/V5 messages, Mastra DB messages, etc.) and normalizes them to the AI SDK V4 `UIMessage` format, which is suitable for use with AI SDK UI components like `useChat()`.
|
|
11
|
+
|
|
12
|
+
## Usage example
|
|
13
|
+
|
|
14
|
+
```typescript title="app/chat/page.tsx" copy
|
|
15
|
+
import { toAISdkV4Messages } from "@mastra/ai-sdk";
|
|
16
|
+
import { useChat } from "ai/react"; // AI SDK V4
|
|
17
|
+
|
|
18
|
+
// Stored messages from your database, memory or API
|
|
19
|
+
const storedMessages = [
|
|
20
|
+
{ id: "1", role: "user", parts: [{ type: "text", text: "Hello" }] },
|
|
21
|
+
{ id: "2", role: "assistant", parts: [{ type: "text", text: "Hi there!" }] }
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
export default function Chat() {
|
|
25
|
+
const { messages } = useChat({
|
|
26
|
+
initialMessages: toAISdkV4Messages(storedMessages)
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div>
|
|
31
|
+
{messages.map((message) => (
|
|
32
|
+
<div key={message.id}>
|
|
33
|
+
{message.role}: {message.content}
|
|
34
|
+
</div>
|
|
35
|
+
))}
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Parameters
|
|
42
|
+
|
|
43
|
+
<PropertiesTable
|
|
44
|
+
content={[
|
|
45
|
+
{
|
|
46
|
+
name: "messages",
|
|
47
|
+
type: "MessageListInput",
|
|
48
|
+
description: "Messages to convert. Can be a string, array of strings, a single message object, or an array of message objects in any supported format.",
|
|
49
|
+
isOptional: false,
|
|
50
|
+
},
|
|
51
|
+
]}
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
## Returns
|
|
55
|
+
|
|
56
|
+
Returns an array of AI SDK V4 `UIMessage` objects with the following structure:
|
|
57
|
+
|
|
58
|
+
<PropertiesTable
|
|
59
|
+
content={[
|
|
60
|
+
{
|
|
61
|
+
name: "id",
|
|
62
|
+
type: "string",
|
|
63
|
+
description: "Unique message identifier.",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "role",
|
|
67
|
+
type: "'user' | 'assistant' | 'system'",
|
|
68
|
+
description: "The role of the message sender.",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "content",
|
|
72
|
+
type: "string",
|
|
73
|
+
description: "Text content of the message.",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "parts",
|
|
77
|
+
type: "UIMessagePart[]",
|
|
78
|
+
description: "Array of UI parts including text, tool-invocation, file, reasoning, source, and step markers.",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "createdAt",
|
|
82
|
+
type: "Date",
|
|
83
|
+
description: "Message creation timestamp.",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "toolInvocations",
|
|
87
|
+
type: "ToolInvocation[]",
|
|
88
|
+
description: "Array of tool invocations for assistant messages.",
|
|
89
|
+
isOptional: true,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "experimental_attachments",
|
|
93
|
+
type: "Attachment[]",
|
|
94
|
+
description: "File attachments on the message.",
|
|
95
|
+
isOptional: true,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: "metadata",
|
|
99
|
+
type: "Record<string, unknown>",
|
|
100
|
+
description: "Custom metadata attached to the message.",
|
|
101
|
+
isOptional: true,
|
|
102
|
+
},
|
|
103
|
+
]}
|
|
104
|
+
/>
|
|
105
|
+
|
|
106
|
+
## Examples
|
|
107
|
+
|
|
108
|
+
### Converting simple text messages
|
|
109
|
+
|
|
110
|
+
```typescript copy
|
|
111
|
+
import { toAISdkV4Messages } from "@mastra/ai-sdk";
|
|
112
|
+
|
|
113
|
+
const messages = toAISdkV4Messages(["Hello", "How can I help you today?"]);
|
|
114
|
+
// Returns array of UIMessage objects with user role and content string
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Loading messages with Mastra client
|
|
118
|
+
|
|
119
|
+
```typescript copy
|
|
120
|
+
import { MastraClient } from "@mastra/client-js";
|
|
121
|
+
import { toAISdkV4Messages } from "@mastra/ai-sdk";
|
|
122
|
+
|
|
123
|
+
const client = new MastraClient();
|
|
124
|
+
|
|
125
|
+
const { messages } = await client.listThreadMessages("thread-id", { agentId: "myAgent" });
|
|
126
|
+
const uiMessages = toAISdkV4Messages(messages);
|
|
127
|
+
```
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: toAISdkV5Messages() | AI SDK"
|
|
3
|
+
description: API reference for toAISdkV5Messages(), a function to convert Mastra messages to AI SDK v5 UI messages.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import PropertiesTable from "@site/src/components/PropertiesTable";
|
|
7
|
+
|
|
8
|
+
# toAISdkV5Messages()
|
|
9
|
+
|
|
10
|
+
Converts messages from various input formats to AI SDK V5 UI message format. This function accepts messages in multiple formats (strings, AI SDK V4/V5 messages, Mastra DB messages, etc.) and normalizes them to the AI SDK V5 `UIMessage` format, which is suitable for use with AI SDK UI components like `useChat()`.
|
|
11
|
+
|
|
12
|
+
## Usage example
|
|
13
|
+
|
|
14
|
+
```typescript title="app/chat/page.tsx" copy
|
|
15
|
+
import { toAISdkV5Messages } from "@mastra/ai-sdk";
|
|
16
|
+
import { useChat } from "ai/react";
|
|
17
|
+
|
|
18
|
+
// Stored messages from your database, memory or API
|
|
19
|
+
const storedMessages = [
|
|
20
|
+
{ id: "1", role: "user", content: "Hello", parts: [{ type: "text", text: "Hello" }] },
|
|
21
|
+
{ id: "2", role: "assistant", content: "Hi there!", parts: [{ type: "text", text: "Hi there!" }] }
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
export default function Chat() {
|
|
25
|
+
const { messages } = useChat({
|
|
26
|
+
initialMessages: toAISdkV5Messages(storedMessages)
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div>
|
|
31
|
+
{messages.map((message) => (
|
|
32
|
+
<div key={message.id}>
|
|
33
|
+
{message.role}: {message.parts.map(part =>
|
|
34
|
+
part.type === "text" ? part.text : null
|
|
35
|
+
)}
|
|
36
|
+
</div>
|
|
37
|
+
))}
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Parameters
|
|
44
|
+
|
|
45
|
+
<PropertiesTable
|
|
46
|
+
content={[
|
|
47
|
+
{
|
|
48
|
+
name: "messages",
|
|
49
|
+
type: "MessageListInput",
|
|
50
|
+
description: "Messages to convert. Can be a string, array of strings, a single message object, or an array of message objects in any supported format.",
|
|
51
|
+
isOptional: false,
|
|
52
|
+
},
|
|
53
|
+
]}
|
|
54
|
+
/>
|
|
55
|
+
|
|
56
|
+
## Returns
|
|
57
|
+
|
|
58
|
+
Returns an array of AI SDK V5 `UIMessage` objects with the following structure:
|
|
59
|
+
|
|
60
|
+
<PropertiesTable
|
|
61
|
+
content={[
|
|
62
|
+
{
|
|
63
|
+
name: "id",
|
|
64
|
+
type: "string",
|
|
65
|
+
description: "Unique message identifier.",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "role",
|
|
69
|
+
type: "'user' | 'assistant' | 'system'",
|
|
70
|
+
description: "The role of the message sender.",
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "parts",
|
|
74
|
+
type: "UIMessagePart[]",
|
|
75
|
+
description: "Array of UI parts including text, tool results, files, reasoning, sources, and step markers.",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "metadata",
|
|
79
|
+
type: "Record<string, unknown>",
|
|
80
|
+
description: "Optional metadata including createdAt, threadId, resourceId, and custom fields.",
|
|
81
|
+
isOptional: true,
|
|
82
|
+
},
|
|
83
|
+
]}
|
|
84
|
+
/>
|
|
85
|
+
|
|
86
|
+
## Examples
|
|
87
|
+
|
|
88
|
+
### Converting simple text messages
|
|
89
|
+
|
|
90
|
+
```typescript copy
|
|
91
|
+
import { toAISdkV5Messages } from "@mastra/ai-sdk";
|
|
92
|
+
|
|
93
|
+
const messages = toAISdkV5Messages(["Hello", "How can I help you today?"]);
|
|
94
|
+
// Returns array of UIMessage objects with user role
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Loading messages with Mastra client
|
|
98
|
+
|
|
99
|
+
```typescript copy
|
|
100
|
+
import { MastraClient } from "@mastra/client-js";
|
|
101
|
+
import { toAISdkV5Messages } from "@mastra/ai-sdk";
|
|
102
|
+
|
|
103
|
+
const client = new MastraClient();
|
|
104
|
+
|
|
105
|
+
const { messages } = await client.listThreadMessages("thread-id", { agentId: "myAgent" });
|
|
106
|
+
const uiMessages = toAISdkV5Messages(messages);
|
|
107
|
+
```
|
|
@@ -7,7 +7,7 @@ import PropertiesTable from "@site/src/components/PropertiesTable";
|
|
|
7
7
|
|
|
8
8
|
# workflowRoute()
|
|
9
9
|
|
|
10
|
-
Creates a workflow route handler for streaming workflow execution using the AI SDK format. This function registers an HTTP `POST` endpoint that accepts input data, executes a workflow, and streams the response back to the client in AI SDK-compatible format. You have to use it inside a [custom API route](/docs/v1/server
|
|
10
|
+
Creates a workflow route handler for streaming workflow execution using the AI SDK format. This function registers an HTTP `POST` endpoint that accepts input data, executes a workflow, and streams the response back to the client in AI SDK-compatible format. You have to use it inside a [custom API route](/docs/v1/server/custom-api-routes).
|
|
11
11
|
|
|
12
12
|
Use [`handleWorkflowStream()`](/reference/v1/ai-sdk/handle-workflow-stream) if you need a framework-agnostic handler.
|
|
13
13
|
|
|
@@ -86,7 +86,7 @@ Under the hood Mastra's Rollup server locates your Mastra entry file and bundles
|
|
|
86
86
|
|
|
87
87
|
The output in `.mastra` can be deployed to any cloud server using [`mastra start`](#mastra-start).
|
|
88
88
|
|
|
89
|
-
If you're deploying to a [serverless platform](/
|
|
89
|
+
If you're deploying to a [serverless platform](/guides/v1/deployment) you need to install the correct deployer in order to receive the correct output in `.mastra`.
|
|
90
90
|
|
|
91
91
|
It accepts [common flags][common-flags].
|
|
92
92
|
|
|
@@ -5,7 +5,7 @@ description: Learn how to interact with Mastra using the client-js SDK.
|
|
|
5
5
|
|
|
6
6
|
# Mastra Client SDK
|
|
7
7
|
|
|
8
|
-
The Mastra Client SDK provides a simple and type-safe interface for interacting with your [Mastra Server](/docs/v1/deployment/
|
|
8
|
+
The Mastra Client SDK provides a simple and type-safe interface for interacting with your [Mastra Server](/docs/v1/deployment/mastra-server) from your client environment.
|
|
9
9
|
|
|
10
10
|
## Usage example
|
|
11
11
|
|
|
@@ -48,8 +48,16 @@ const run = await workflow.createRun();
|
|
|
48
48
|
|
|
49
49
|
// Or with an existing runId
|
|
50
50
|
const run = await workflow.createRun({ runId: "existing-run-id" });
|
|
51
|
+
|
|
52
|
+
// Or with a resourceId to associate the run with a specific resource
|
|
53
|
+
const run = await workflow.createRun({
|
|
54
|
+
runId: "my-run-id",
|
|
55
|
+
resourceId: "user-123"
|
|
56
|
+
});
|
|
51
57
|
```
|
|
52
58
|
|
|
59
|
+
The `resourceId` parameter associates the workflow run with a specific resource (e.g., user ID, tenant ID). This value is persisted with the run and can be used for filtering and querying runs later.
|
|
60
|
+
|
|
53
61
|
### startAsync()
|
|
54
62
|
|
|
55
63
|
Start a workflow run and await the full result:
|
|
@@ -80,6 +88,18 @@ const result = await run.startAsync({
|
|
|
80
88
|
|
|
81
89
|
The `initialState` object should match the structure defined in the workflow's `stateSchema`. See [Workflow State](/docs/v1/workflows/workflow-state) for more details.
|
|
82
90
|
|
|
91
|
+
To associate a run with a specific resource, pass `resourceId` to `createRun()`:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const run = await workflow.createRun({ resourceId: "user-123" });
|
|
95
|
+
|
|
96
|
+
const result = await run.startAsync({
|
|
97
|
+
inputData: {
|
|
98
|
+
city: "New York",
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
83
103
|
### start()
|
|
84
104
|
|
|
85
105
|
Start a workflow run without waiting for completion:
|
|
@@ -25,12 +25,12 @@ This method does not accept any parameters.
|
|
|
25
25
|
name: "server",
|
|
26
26
|
type: "ServerConfig | undefined",
|
|
27
27
|
description:
|
|
28
|
-
"The configured server configuration including port, timeout, API routes, middleware, CORS settings, and build options, or undefined if no server has been configured.",
|
|
28
|
+
"The configured server configuration including port, host, studioBase, timeout, API routes, middleware, CORS settings, and build options, or undefined if no server has been configured.",
|
|
29
29
|
},
|
|
30
30
|
]}
|
|
31
31
|
/>
|
|
32
32
|
|
|
33
33
|
## Related
|
|
34
34
|
|
|
35
|
-
- [Server deployment](/docs/v1/deployment/
|
|
36
|
-
- [Server configuration](/docs/v1/server
|
|
35
|
+
- [Server deployment](/docs/v1/deployment/mastra-server)
|
|
36
|
+
- [Server configuration](/docs/v1/server/custom-api-routes)
|
|
@@ -179,5 +179,5 @@ When using `raw: true`, the returned object has the following structure:
|
|
|
179
179
|
## Related
|
|
180
180
|
|
|
181
181
|
- [Mastra.listStoredAgents()](/reference/v1/core/listStoredAgents)
|
|
182
|
-
- [Storage overview](/docs/v1/
|
|
182
|
+
- [Storage overview](/docs/v1/memory/storage/overview)
|
|
183
183
|
- [Agents overview](/docs/v1/agents/overview)
|
|
@@ -147,5 +147,5 @@ async function getAllStoredAgents(mastra: Mastra) {
|
|
|
147
147
|
## Related
|
|
148
148
|
|
|
149
149
|
- [Mastra.getStoredAgentById()](/reference/v1/core/getStoredAgentById)
|
|
150
|
-
- [Storage overview](/docs/v1/
|
|
150
|
+
- [Storage overview](/docs/v1/memory/storage/overview)
|
|
151
151
|
- [Agents overview](/docs/v1/agents/overview)
|
|
@@ -7,7 +7,7 @@ description: Documentation for PinoLogger, which provides methods to record even
|
|
|
7
7
|
|
|
8
8
|
A Logger instance is created using `new PinoLogger()` and provides methods to record events at various severity levels.
|
|
9
9
|
|
|
10
|
-
When deploying to Mastra Cloud, logs are displayed on the [Logs](/docs/v1/
|
|
10
|
+
When deploying to Mastra Cloud, logs are displayed on the [Logs](/docs/v1/mastra-cloud/dashboard#logs) page. In self-hosted or custom environments, logs can be directed to files or external services depending on the configured transports.
|
|
11
11
|
|
|
12
12
|
## Usage example
|
|
13
13
|
|