Skip to content

Commit 4795943

Browse files
committed
chore: Update Mastra integration in the Dojo
1 parent f28efcd commit 4795943

File tree

6 files changed

+153
-61
lines changed

6 files changed

+153
-61
lines changed

apps/dojo/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
"@copilotkit/shared": "0.0.0-feat-cpk-1-5-20251104211725",
3434
"@copilotkitnext/runtime": "0.0.20",
3535
"@copilotkitnext/react": "0.0.20",
36-
"@mastra/client-js": "^0.15.2",
37-
"@mastra/core": "^0.20.2",
36+
"@mastra/client-js": "^0.16.8",
37+
"@mastra/core": "^0.23.3",
3838
"@mastra/dynamodb": "^0.15.9",
39-
"@mastra/libsql": "^0.15.2",
39+
"@mastra/libsql": "^0.16.1 ",
4040
"@mastra/loggers": "^0.10.18",
4141
"@mastra/memory": "^0.15.10",
4242
"@mdx-js/loader": "^3.1.1",

apps/dojo/src/agents.ts

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { AgentIntegrationConfig } from "./types/integration";
44
import { MiddlewareStarterAgent } from "@ag-ui/middleware-starter";
55
import { ServerStarterAgent } from "@ag-ui/server-starter";
66
import { ServerStarterAllFeaturesAgent } from "@ag-ui/server-starter-all-features";
7-
// import { MastraClient } from "@mastra/client-js";
8-
// import { MastraAgent } from "@ag-ui/mastra";
9-
// import { VercelAISDKAgent } from "@ag-ui/vercel-ai-sdk";
10-
// import { openai } from "@ai-sdk/openai";
7+
import { MastraClient } from "@mastra/client-js";
8+
import { MastraAgent } from "@ag-ui/mastra";
9+
import { VercelAISDKAgent } from "@ag-ui/vercel-ai-sdk";
10+
import { openai } from "@ai-sdk/openai";
1111
import { LangGraphAgent, LangGraphHttpAgent } from "@ag-ui/langgraph";
1212
import { AgnoAgent } from "@ag-ui/agno";
1313
import { LlamaIndexAgent } from "@ag-ui/llamaindex";
1414
import { CrewAIAgent } from "@ag-ui/crewai";
1515
import getEnvVars from "./env";
16-
// import { mastra } from "./mastra";
16+
import { mastra } from "./mastra";
1717
import { PydanticAIAgent } from "@ag-ui/pydantic-ai";
1818
import { ADKAgent } from "@ag-ui/adk";
1919
import { SpringAiAgent } from "@ag-ui/spring-ai";
@@ -116,34 +116,32 @@ export const agentsIntegrations: AgentIntegrationConfig[] = [
116116
};
117117
},
118118
},
119-
// Disable until we can support Vercel AI SDK v5
120-
// {
121-
// id: "mastra",
122-
// agents: async () => {
123-
// const mastraClient = new MastraClient({
124-
// baseUrl: envVars.mastraUrl,
125-
// });
119+
{
120+
id: "mastra",
121+
agents: async () => {
122+
const mastraClient = new MastraClient({
123+
baseUrl: envVars.mastraUrl,
124+
});
126125

127-
// return MastraAgent.getRemoteAgents({
128-
// mastraClient,
129-
// });
130-
// },
131-
// },
132-
// {
133-
// id: "mastra-agent-local",
134-
// agents: async () => {
135-
// return MastraAgent.getLocalAgents({ mastra });
136-
// },
137-
// },
138-
// Disabled until we can support Vercel AI SDK v5
139-
// {
140-
// id: "vercel-ai-sdk",
141-
// agents: async () => {
142-
// return {
143-
// agentic_chat: new VercelAISDKAgent({ model: openai("gpt-4o") }),
144-
// };
145-
// },
146-
// },
126+
return MastraAgent.getRemoteAgents({
127+
mastraClient,
128+
});
129+
},
130+
},
131+
{
132+
id: "mastra-agent-local",
133+
agents: async () => {
134+
return MastraAgent.getLocalAgents({ mastra });
135+
},
136+
},
137+
{
138+
id: "vercel-ai-sdk",
139+
agents: async () => {
140+
return {
141+
agentic_chat: new VercelAISDKAgent({ model: openai("gpt-4o") }),
142+
};
143+
},
144+
},
147145
{
148146
id: "langgraph",
149147
agents: async () => {

apps/dojo/src/files.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,27 @@
519519
"type": "file"
520520
}
521521
],
522+
"vercel-ai-sdk::agentic_chat": [
523+
{
524+
"name": "page.tsx",
525+
"content": "\"use client\";\nimport React, { useState } from \"react\";\nimport \"@copilotkit/react-ui/styles.css\";\nimport \"./style.css\";\nimport {\n CopilotKit,\n useFrontendTool,\n} from \"@copilotkit/react-core\";\nimport { CopilotChat } from \"@copilotkit/react-ui\";\n\ninterface AgenticChatProps {\n params: Promise<{\n integrationId: string;\n }>;\n}\n\nconst AgenticChat: React.FC<AgenticChatProps> = ({ params }) => {\n const { integrationId } = React.use(params);\n\n return (\n <CopilotKit\n runtimeUrl={`/api/copilotkit/${integrationId}`}\n showDevConsole={false}\n // agent lock to the relevant agent\n agent=\"agentic_chat\"\n >\n <Chat />\n </CopilotKit>\n );\n};\n\nconst Chat = () => {\n const [background, setBackground] = useState<string>(\"--copilot-kit-background-color\");\n\n useFrontendTool({\n name: \"change_background\",\n description:\n \"Change the background color of the chat. Can be anything that the CSS background attribute accepts. Regular colors, linear of radial gradients etc.\",\n parameters: [\n {\n name: \"background\",\n type: \"string\",\n description: \"The background. Prefer gradients. Only use when asked.\",\n },\n ],\n handler: ({ background }) => {\n setBackground(background);\n return {\n status: \"success\",\n message: `Background changed to ${background}`,\n };\n },\n });\n\n return (\n <div\n className=\"flex justify-center items-center h-full w-full\"\n data-testid=\"background-container\"\n style={{ background }}\n >\n <div className=\"h-full w-full md:w-8/10 md:h-8/10 rounded-lg\">\n <CopilotChat\n className=\"h-full rounded-2xl max-w-6xl mx-auto\"\n labels={{ initial: \"Hi, I'm an agent. Want to chat?\" }}\n suggestions={[\n {\n title: \"Change background\",\n message: \"Change the background to something new.\",\n },\n {\n title: \"Generate sonnet\",\n message: \"Write a short sonnet about AI.\",\n },\n ]}\n />\n </div>\n </div>\n );\n};\n\nexport default AgenticChat;\n",
526+
"language": "typescript",
527+
"type": "file"
528+
},
529+
{
530+
"name": "style.css",
531+
"content": ".copilotKitInput {\n border-bottom-left-radius: 0.75rem;\n border-bottom-right-radius: 0.75rem;\n border-top-left-radius: 0.75rem;\n border-top-right-radius: 0.75rem;\n border: 1px solid var(--copilot-kit-separator-color) !important;\n}\n \n.copilotKitChat {\n background-color: #fff !important;\n}\n ",
532+
"language": "css",
533+
"type": "file"
534+
},
535+
{
536+
"name": "README.mdx",
537+
"content": "# 🤖 Agentic Chat with Frontend Tools\n\n## What This Demo Shows\n\nThis demo showcases CopilotKit's **agentic chat** capabilities with **frontend\ntool integration**:\n\n1. **Natural Conversation**: Chat with your Copilot in a familiar chat interface\n2. **Frontend Tool Execution**: The Copilot can directly interacts with your UI\n by calling frontend functions\n3. **Seamless Integration**: Tools defined in the frontend and automatically\n discovered and made available to the agent\n\n## How to Interact\n\nTry asking your Copilot to:\n\n- \"Can you change the background color to something more vibrant?\"\n- \"Make the background a blue to purple gradient\"\n- \"Set the background to a sunset-themed gradient\"\n- \"Change it back to a simple light color\"\n\nYou can also chat about other topics - the agent will respond conversationally\nwhile having the ability to use your UI tools when appropriate.\n\n## ✨ Frontend Tool Integration in Action\n\n**What's happening technically:**\n\n- The React component defines a frontend function using `useCopilotAction`\n- CopilotKit automatically exposes this function to the agent\n- When you make a request, the agent determines whether to use the tool\n- The agent calls the function with the appropriate parameters\n- The UI immediately updates in response\n\n**What you'll see in this demo:**\n\n- The Copilot understands requests to change the background\n- It generates CSS values for colors and gradients\n- When it calls the tool, the background changes instantly\n- The agent provides a conversational response about the changes it made\n\nThis technique of exposing frontend functions to your Copilot can be extended to\nany UI manipulation you want to enable, from theme changes to data filtering,\nnavigation, or complex UI state management!\n",
538+
"language": "markdown",
539+
"type": "file"
540+
},
541+
{}
542+
],
522543
"langgraph::agentic_chat": [
523544
{
524545
"name": "page.tsx",

apps/dojo/src/mastra/index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const mastra = new Mastra({
5757
5858
Your primary function is to help users get weather details for specific locations. When responding:
5959
- Always ask for a location if none is provided
60-
- If the location name isnt in English, please translate it
60+
- If the location name isn't in English, please translate it
6161
- If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
6262
- Include relevant details like humidity, wind conditions, and precipitation
6363
- Keep responses concise but informative
@@ -105,7 +105,7 @@ export const mastra = new Mastra({
105105
"One-Pot Meal",
106106
"Vegetarian",
107107
"Vegan",
108-
]),
108+
])
109109
)
110110
.describe("A list of special preferences for the recipe"),
111111
cooking_time: z
@@ -117,21 +117,25 @@ export const mastra = new Mastra({
117117
icon: z
118118
.string()
119119
.describe(
120-
"The icon emoji (not emoji code like '\x1f35e', but the actual emoji like 🥕) of the ingredient",
120+
"The icon emoji (not emoji code like '\x1f35e', but the actual emoji like 🥕) of the ingredient"
121121
),
122122
name: z.string().describe("The name of the ingredient"),
123-
amount: z.string().describe("The amount of the ingredient"),
124-
}),
123+
amount: z
124+
.string()
125+
.describe("The amount of the ingredient"),
126+
})
125127
)
126128
.describe(
127-
"Entire list of ingredients for the recipe, including the new ingredients and the ones that are already in the recipe",
129+
"Entire list of ingredients for the recipe, including the new ingredients and the ones that are already in the recipe"
128130
),
129131
instructions: z
130132
.array(z.string())
131133
.describe(
132-
"Entire list of instructions for the recipe, including the new instructions and the ones that are already there",
134+
"Entire list of instructions for the recipe, including the new instructions and the ones that are already there"
133135
),
134-
changes: z.string().describe("A description of the changes made to the recipe"),
136+
changes: z
137+
.string()
138+
.describe("A description of the changes made to the recipe"),
135139
}),
136140
}),
137141
},

integrations/mastra/typescript/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
},
5959
"dependencies": {
6060
"@ai-sdk/ui-utils": "^1.2.11",
61-
"@mastra/client-js": "^0.15.2",
61+
"@mastra/client-js": "^0.16.8",
6262
"rxjs": "7.8.1"
6363
},
6464
"peerDependencies": {
@@ -71,7 +71,7 @@
7171
"devDependencies": {
7272
"@ag-ui/client": "workspace:*",
7373
"@ag-ui/core": "workspace:*",
74-
"@mastra/core": "^0.23.2",
74+
"@mastra/core": "^0.23.3",
7575
"@types/jest": "^29.5.14",
7676
"@types/node": "^20.19.24",
7777
"jest": "^29.7.0",

pnpm-lock.yaml

Lines changed: 85 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)