Skip to content

Commit 2b287ba

Browse files
authored
Add @ag-ui/mastra to /integrations (#46)
* copy existing mastra code * add example * make mastra work in the monorepo * Refactor MastraAgent to use provided resourceId instead of generating a random UUID * Add Vercel AI SDK integration to agents and menu configurations
1 parent 814311e commit 2b287ba

File tree

25 files changed

+14675
-427
lines changed

25 files changed

+14675
-427
lines changed

docs/quickstart/connect.mdx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,38 @@ export class OpenAIAgent extends AbstractAgent {}
8282
```
8383

8484
Finally, introduce your integration to the dojo by adding it to
85-
`apps/dojo/src/integrations.ts`:
85+
`apps/dojo/src/menu.ts`:
8686

8787
```ts
8888
// ...
89-
import { OpenAIAgent } from "@ag-ui/openai"
90-
91-
export const integrations = [
89+
export const menuIntegrations: MenuIntegrationConfig[] = [
9290
// ...
9391

9492
configureIntegration({
9593
id: "openai",
9694
name: "OpenAI",
9795
features: ["agentic_chat"],
96+
}),
97+
]
98+
```
99+
100+
And `apps/dojo/src/agents.ts`:
101+
102+
```ts
103+
// ...
104+
import { OpenAIAgent } from "@ag-ui/openai"
105+
106+
export const agentsIntegrations: AgentIntegrationConfig[] = [
107+
// ...
108+
109+
{
110+
id: "openai",
98111
agents: async () => {
99112
return {
100113
agentic_chat: new OpenAIAgent(),
101114
}
102115
},
103-
}),
116+
},
104117
]
105118
```
106119

typescript-sdk/.vscode/cspell.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"version": "0.2",
33
"language": "en",
4-
"words": ["ag-ui", "uuidv4", "untruncate"],
4+
"words": ["ag-ui", "uuidv4", "untruncate", "mastra", "agui", "agentic"],
55
"ignorePaths": ["node_modules/**", "dist/**", "build/**", ".git/**", "coverage/**"],
66
"allowCompoundWords": true,
77
"ignoreRegExpList": ["\\([^)]*\\)", "`[^`]*`", "'[^']*'", "\"[^\"]*\""]

typescript-sdk/apps/dojo/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12+
"@ag-ui/mastra": "workspace:*",
1213
"@ag-ui/starter": "workspace:*",
1314
"@ag-ui/vercel-ai-sdk": "workspace:*",
1415
"@ai-sdk/openai": "^1.3.22",
@@ -17,6 +18,7 @@
1718
"@copilotkit/runtime": "1.8.12",
1819
"@copilotkit/runtime-client-gql": "1.8.12",
1920
"@copilotkit/shared": "1.8.12",
21+
"@mastra/client-js": "^0.10.1",
2022
"@mdx-js/loader": "^3.1.0",
2123
"@mdx-js/mdx": "^3.1.0",
2224
"@mdx-js/react": "^3.1.0",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { AgentIntegrationConfig } from "./types/integration";
2+
import { StarterAgent } from "@ag-ui/starter";
3+
import { MastraClient } from "@mastra/client-js";
4+
import { MastraAgent } from "@ag-ui/mastra";
5+
import { VercelAISDKAgent } from "@ag-ui/vercel-ai-sdk";
6+
import { openai } from "@ai-sdk/openai";
7+
8+
export const agentsIntegrations: AgentIntegrationConfig[] = [
9+
{
10+
id: "starter",
11+
agents: async () => {
12+
return {
13+
agentic_chat: new StarterAgent(),
14+
};
15+
},
16+
},
17+
{
18+
id: "mastra",
19+
agents: async () => {
20+
const mastraClient = new MastraClient({
21+
baseUrl: "http://localhost:4111",
22+
});
23+
24+
return MastraAgent.getRemoteAgents({
25+
mastraClient,
26+
});
27+
},
28+
},
29+
{
30+
id: "vercel-ai-sdk",
31+
agents: async () => {
32+
return {
33+
agentic_chat: new VercelAISDKAgent({ model: openai("gpt-4o") }),
34+
};
35+
},
36+
},
37+
];

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const Chat = () => {
4141
},
4242
],
4343
handler: ({ background }) => {
44-
console.log("Changing background to", background);
4544
setBackground(background);
4645
},
4746
followUp: false,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import React from "react";
4-
import { integrations } from "@/integrations";
4+
import { menuIntegrations } from "@/menu";
55
import { notFound } from "next/navigation";
66

77
interface IntegrationPageProps {
@@ -14,7 +14,7 @@ export default function IntegrationPage({ params }: IntegrationPageProps) {
1414
const { integrationId } = React.use(params);
1515

1616
// Find the integration by ID
17-
const integration = integrations.find((integration) => integration.id === integrationId);
17+
const integration = menuIntegrations.find((integration) => integration.id === integrationId);
1818

1919
// If integration not found, show 404
2020
if (!integration) {

typescript-sdk/apps/dojo/src/app/api/copilotkit/[integrationId]/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import {
33
ExperimentalEmptyAdapter,
44
copilotRuntimeNextJSAppRouterEndpoint,
55
} from "@copilotkit/runtime";
6-
import { integrations } from "@/integrations";
6+
import { agentsIntegrations } from "@/agents";
77

88
import { NextRequest } from "next/server";
99

1010
export async function POST(request: NextRequest) {
1111
const integrationId = request.url.split("/").pop();
1212

13-
const integration = integrations.find((i) => i.id === integrationId);
13+
const integration = agentsIntegrations.find((i) => i.id === integrationId);
1414
if (!integration) {
1515
return new Response("Integration not found", { status: 404 });
1616
}

typescript-sdk/apps/dojo/src/components/sidebar/sidebar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
DropdownMenuSeparator,
1717
} from "../ui/dropdown-menu";
1818
import { Button } from "../ui/button";
19-
import { integrations } from "@/integrations";
19+
import { menuIntegrations } from "@/menu";
2020

2121
interface SidebarProps {
2222
activeTab?: string;
@@ -37,7 +37,7 @@ export function Sidebar({ activeTab = "preview", onTabChange, readmeContent }: S
3737
// Find the current integration (only if we have a valid integration ID)
3838
const currentIntegration =
3939
currentIntegrationId && currentIntegrationId !== ""
40-
? integrations.find((integration) => integration.id === currentIntegrationId)
40+
? menuIntegrations.find((integration) => integration.id === currentIntegrationId)
4141
: null;
4242

4343
// Filter demos based on current integration's features
@@ -112,7 +112,7 @@ export function Sidebar({ activeTab = "preview", onTabChange, readmeContent }: S
112112
</Button>
113113
</DropdownMenuTrigger>
114114
<DropdownMenuContent className="w-56">
115-
{integrations.map((integration) => (
115+
{menuIntegrations.map((integration) => (
116116
<DropdownMenuItem
117117
key={integration.id}
118118
onClick={() => {

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

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { MenuIntegrationConfig } from "./types/integration";
2+
3+
export const menuIntegrations: MenuIntegrationConfig[] = [
4+
{
5+
id: "starter",
6+
name: "Starter",
7+
features: ["agentic_chat"],
8+
},
9+
{
10+
id: "mastra",
11+
name: "Mastra",
12+
features: ["agentic_chat"],
13+
},
14+
{
15+
id: "vercel-ai-sdk",
16+
name: "Vercel AI SDK",
17+
features: ["agentic_chat"],
18+
},
19+
];

0 commit comments

Comments
 (0)