Skip to content

Commit 1a794a8

Browse files
abhiaiyer91tylerslaton
authored andcommitted
feat(mastra): add streamVNext to agui
- Adds a streamVNext workflow example - Supports all of the streamVNext events - Latest model support from the AI SDK as well Signed-off-by: Tyler Slaton <[email protected]>
1 parent 63d5158 commit 1a794a8

File tree

15 files changed

+3356
-2153
lines changed

15 files changed

+3356
-2153
lines changed

.github/workflows/dojo-e2e.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ jobs:
6666
test_path: tests/serverStarterAllFeaturesTests
6767
services: ["dojo","server-starter-all"]
6868
wait_on: http://localhost:9999,tcp:localhost:8001
69-
- suite: vercel-ai-sdk
70-
test_path: tests/vercelAISdkTests
71-
services: ["dojo"]
72-
wait_on: http://localhost:9999
69+
# - suite: vercel-ai-sdk
70+
# test_path: tests/vercelAISdkTests
71+
# services: ["dojo"]
72+
# wait_on: http://localhost:9999
7373

7474
steps:
7575
- name: Checkout code

typescript-sdk/apps/dojo/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ yarn-error.log*
3939
# typescript
4040
*.tsbuildinfo
4141
next-env.d.ts
42+
43+
# mastra
44+
.mastra

typescript-sdk/apps/dojo/e2e/tests/mastraAgentLocalTests/agenticChatPage.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test("[MastraAgentLocal] Agentic Chat sends and receives a message", async ({
2222

2323
await waitForAIResponse(page);
2424
await chat.assertUserMessageVisible("Hi, I am duaa");
25-
await chat.assertAgentReplyVisible(/Hello/i);
25+
await chat.assertAgentReplyVisible(/Hello|Hi/i);
2626
});
2727
});
2828

typescript-sdk/apps/dojo/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222
"@ag-ui/server-starter": "workspace:*",
2323
"@ag-ui/server-starter-all-features": "workspace:*",
2424
"@ag-ui/vercel-ai-sdk": "workspace:*",
25-
"@ai-sdk/openai": "^1.3.22",
2625
"@copilotkit/react-core": "1.10.5",
2726
"@copilotkit/react-ui": "1.10.5",
2827
"@copilotkit/runtime": "1.10.5",
2928
"@copilotkit/runtime-client-gql": "1.10.5",
3029
"@copilotkit/shared": "1.10.5",
31-
"@mastra/client-js": "^0.10.18",
32-
"@mastra/core": "^0.13.0",
33-
"@mastra/dynamodb": "^0.13.3",
34-
"@mastra/libsql": "^0.13.0",
35-
"@mastra/loggers": "^0.10.5",
36-
"@mastra/memory": "^0.12.0",
30+
"@mastra/client-js": "^0.14.0",
31+
"@mastra/core": "^0.19.0",
32+
"@mastra/dynamodb": "^0.15.4",
33+
"@mastra/libsql": "^0.15.0",
34+
"@mastra/loggers": "^0.10.14",
35+
"@mastra/memory": "^0.15.4",
36+
"@ai-sdk/openai": "^2.0.42",
3737
"@mdx-js/loader": "^3.1.0",
3838
"@mdx-js/mdx": "^3.1.0",
3939
"@mdx-js/react": "^3.1.0",
@@ -67,7 +67,7 @@
6767
"tailwind-merge": "^3.0.2",
6868
"tailwindcss-animate": "^1.0.7",
6969
"uuid": "^11.1.0",
70-
"zod": "^3.22.4"
70+
"zod": "^3.25.67"
7171
},
7272
"peerDependencies": {
7373
"@ag-ui/client": "workspace:*",
@@ -93,4 +93,4 @@
9393
"typescript": "^5",
9494
"wait-port": "^1.1.0"
9595
}
96-
}
96+
}

typescript-sdk/apps/dojo/src/agents.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,15 @@ export const agentsIntegrations: AgentIntegrationConfig[] = [
116116
return MastraAgent.getLocalAgents({ mastra });
117117
},
118118
},
119-
{
120-
id: "vercel-ai-sdk",
121-
agents: async () => {
122-
return {
123-
agentic_chat: new VercelAISDKAgent({ model: openai("gpt-4o") }),
124-
};
125-
},
126-
},
119+
// Disabled until we can support Vercel AI SDK v5
120+
// {
121+
// id: "vercel-ai-sdk",
122+
// agents: async () => {
123+
// return {
124+
// agentic_chat: new VercelAISDKAgent({ model: openai("gpt-4o") }),
125+
// };
126+
// },
127+
// },
127128
{
128129
id: "langgraph",
129130
agents: async () => {

typescript-sdk/apps/dojo/src/app/[integrationId]/feature/agentic_chat/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const Chat = () => {
3737
{
3838
name: "background",
3939
type: "string",
40-
description: "The background. Prefer gradients.",
40+
description: "The background. Prefer gradients. Only use when asked.",
4141
},
4242
],
4343
handler: ({ background }) => {

typescript-sdk/apps/dojo/src/files.json

Lines changed: 11 additions & 37 deletions
Large diffs are not rendered by default.

typescript-sdk/apps/dojo/src/mastra/index.ts

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Memory } from "@mastra/memory";
44
import { LibSQLStore } from "@mastra/libsql";
55
import { DynamoDBStore } from "@mastra/dynamodb";
66

7-
import { Mastra } from "@mastra/core";
7+
import { createStep, createWorkflow, Mastra } from "@mastra/core";
88
import { createTool } from "@mastra/core";
99
import { z } from "zod";
1010

@@ -13,17 +13,63 @@ import { z } from "zod";
1313
function getStorage(): LibSQLStore | DynamoDBStore {
1414
if (process.env.DYNAMODB_TABLE_NAME) {
1515
return new DynamoDBStore({
16-
name: "dynamodb",
17-
config: {
18-
tableName: process.env.DYNAMODB_TABLE_NAME
19-
},
20-
});
16+
name: "dynamodb",
17+
config: {
18+
tableName: process.env.DYNAMODB_TABLE_NAME
19+
},
20+
});
2121
} else {
2222
return new LibSQLStore({ url: "file::memory:" });
2323
}
2424
}
2525

26+
export const weatherInfo = createTool({
27+
id: "Get Weather Information",
28+
description: `Fetches the current weather information for a given city`,
29+
inputSchema: z.object({
30+
city: z.string(),
31+
}),
32+
outputSchema: z.object({
33+
text: z.string(),
34+
}),
35+
execute: async ({ writer }) => {
36+
const step = createStep({
37+
id: "weather-info",
38+
inputSchema: z.object({}),
39+
outputSchema: z.object({
40+
text: z.string(),
41+
}),
42+
execute: async () => {
43+
return {
44+
text: "70 degrees"
45+
}
46+
}
47+
})
48+
49+
const workflow = createWorkflow({
50+
id: "weather-info",
51+
inputSchema: z.object({}),
52+
outputSchema: z.object({}),
53+
steps: [step],
54+
}).then(step).commit();
2655

56+
const run = await workflow.createRunAsync()
57+
58+
const stream = run.streamVNext()
59+
60+
for await (const chunk of stream) {
61+
console.log('WORKFLOW CHUNK', chunk)
62+
if ('payload' in chunk) {
63+
await writer!.write({
64+
type: `${chunk.from}-${chunk.type}`,
65+
payload: chunk.payload,
66+
})
67+
}
68+
}
69+
70+
return await stream.result as any;
71+
},
72+
});
2773

2874
export const mastra = new Mastra({
2975
agents: {
@@ -38,10 +84,11 @@ export const mastra = new Mastra({
3884
- If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
3985
- Include relevant details like humidity, wind conditions, and precipitation
4086
- Keep responses concise but informative
41-
42-
Use the weatherTool to fetch current weather data.
43-
`,
87+
`,
4488
model: openai("gpt-4o"),
89+
tools: {
90+
weatherInfo
91+
},
4592
memory: new Memory({
4693
storage: getStorage(),
4794
options: {

typescript-sdk/apps/dojo/src/menu.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ export const menuIntegrations: MenuIntegrationConfig[] = [
9898
"tool_based_generative_ui",
9999
],
100100
},
101-
{
102-
id: "vercel-ai-sdk",
103-
name: "Vercel AI SDK",
104-
features: ["agentic_chat"],
105-
},
101+
// Disabled until we can support Vercel AI SDK v5
102+
// {
103+
// id: "vercel-ai-sdk",
104+
// name: "Vercel AI SDK",
105+
// features: ["agentic_chat"],
106+
// },
106107
{
107108
id: "middleware-starter",
108109
name: "Middleware Starter",

0 commit comments

Comments
 (0)