Skip to content

Commit 5a728a4

Browse files
committed
feat: enhance agent functionality and improve configuration
- Added new external packages to next.config.ts for enhanced functionality. - Updated acpAgent to include detailed role and capabilities descriptions for better user guidance. - Integrated MongoDB memory options with MongosVector support in mongodb.ts. - Refactored index.ts to improve agent management and telemetry options. - Implemented new API routes for chat and completion functionalities, allowing for enhanced user interactions. - Developed ChatExtra and Chat components to facilitate user input and display message streams. - Created Completion component to handle user prompts and display completion results.
1 parent 63a0d35 commit 5a728a4

10 files changed

Lines changed: 413 additions & 138 deletions

File tree

app/api/chat-extra/route.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { mastra } from "../../../src/mastra";
2+
import { RuntimeContext } from "@mastra/core/runtime-context";
3+
4+
export async function POST(req: Request) {
5+
const { messages, data } = await req.json();
6+
const myAgent = mastra.getAgent("weatherAgent");
7+
8+
const runtimeContext = new RuntimeContext();
9+
10+
if (data) {
11+
for (const [key, value] of Object.entries(data)) {
12+
runtimeContext.set(key, value);
13+
}
14+
}
15+
16+
const stream = await myAgent.stream(messages, {
17+
runtimeContext,
18+
format: "aisdk",
19+
});
20+
return stream.toUIMessageStreamResponse();
21+
}

app/api/chat/route.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { mastra } from "../../../src/mastra";
2+
3+
export async function POST(req: Request) {
4+
const { messages } = await req.json();
5+
const myAgent = mastra.getAgent("weatherAgent");
6+
const stream = await myAgent.stream(messages, { format: "aisdk" });
7+
8+
return stream.toUIMessageStreamResponse();
9+
}

app/api/completion/route.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { mastra } from "../../../src/mastra";
2+
3+
export async function POST(req: Request) {
4+
const { prompt } = await req.json();
5+
const myAgent = mastra.getAgent("weatherAgent");
6+
const stream = await myAgent.stream([{ role: "user", content: prompt }], {
7+
format: "aisdk",
8+
});
9+
10+
return stream.toUIMessageStreamResponse();
11+
}

app/test/chat-extra.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"use client";
2+
3+
import { useChat } from "@ai-sdk/react";
4+
import { useState } from "react";
5+
import { DefaultChatTransport } from 'ai';
6+
7+
export function ChatExtra() {
8+
const [inputValue, setInputValue] = useState('')
9+
const { messages, sendMessage } = useChat({
10+
transport: new DefaultChatTransport({
11+
api: 'http://localhost:4111/chat',
12+
}),
13+
});
14+
15+
const handleFormSubmit = (e: React.FormEvent) => {
16+
e.preventDefault();
17+
sendMessage({ text: inputValue }, {
18+
body: {
19+
data: {
20+
userId: "user123",
21+
preferences: {
22+
language: "en",
23+
temperature: "celsius"
24+
}
25+
}
26+
}
27+
});
28+
};
29+
30+
return (
31+
<div>
32+
<pre>{JSON.stringify(messages, null, 2)}</pre>
33+
<form onSubmit={handleFormSubmit}>
34+
<input value={inputValue} onChange={e=>setInputValue(e.target.value)} placeholder="Name of city" />
35+
</form>
36+
</div>
37+
);
38+
}

app/test/chat.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use client";
2+
3+
import { useChat } from "@ai-sdk/react";
4+
import { useState } from "react";
5+
import { DefaultChatTransport } from 'ai';
6+
7+
export function Chat() {
8+
const [inputValue, setInputValue] = useState('')
9+
const { messages, sendMessage} = useChat({
10+
transport: new DefaultChatTransport({
11+
api: 'http://localhost:4111/chat',
12+
}),
13+
});
14+
15+
const handleFormSubmit = (e: React.FormEvent) => {
16+
e.preventDefault();
17+
sendMessage({ text: inputValue });
18+
};
19+
20+
return (
21+
<div>
22+
<pre>{JSON.stringify(messages, null, 2)}</pre>
23+
<form onSubmit={handleFormSubmit}>
24+
<input value={inputValue} onChange={e=>setInputValue(e.target.value)} placeholder="Name of city" />
25+
</form>
26+
</div>
27+
);
28+
}

app/test/completion.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use client";
2+
3+
import { useCompletion } from "@ai-sdk/react";
4+
5+
export function Completion() {
6+
const { completion, input, handleInputChange, handleSubmit } = useCompletion({
7+
api: "api/completion"
8+
});
9+
10+
return (
11+
<div>
12+
<form onSubmit={handleSubmit}>
13+
<input value={input} onChange={handleInputChange} placeholder="Name of city" />
14+
</form>
15+
<p>Completion result: {completion}</p>
16+
</div>
17+
);
18+
}

next.config.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { NextConfig } from "next";
22

33
const nextConfig: NextConfig = {
4-
serverExternalPackages: ["@mastra/*", "ai-sdk-provider-gemini-cli", "@mcpc-tech/*", "@openrouter/*", "@supermemory/*", "playwright-core", "crawlee"],
4+
serverExternalPackages: ["@mastra/*", "cheerio", "jsdom", "ai-sdk-provider-gemini-cli", "@mcpc-tech/*", "@openrouter/*", "@supermemory/*", "playwright-core", "crawlee"],
55
allowedDevOrigins: ['http://localhost:4111', '**'],
66
typedRoutes: true,
77
reactStrictMode: true,
@@ -15,46 +15,53 @@ const nextConfig: NextConfig = {
1515
cacheMaxMemorySize: 128 * 1024 * 1024, // 128 MB
1616
compiler: {
1717
emotion: true,
18+
styledComponents: true,
19+
styledJsx: {
20+
useLightningcss: true,
21+
}
1822
},
1923
// TODO: enable this when we have a proper domain
2024
compress: true,
2125
poweredByHeader: false,
22-
basePath: "",
2326
trailingSlash: false,
24-
25-
images: {
26-
remotePatterns: [
27-
{
28-
protocol: "https",
29-
hostname: "**",
30-
},
31-
],
32-
},
33-
3427
// exportPathMap: async function () {
3528
// return {
3629
// "/": { page: "/" },
3730
// };
3831
// },
3932
experimental: {
40-
// adapterPath: "./src/adapter/edge.ts",
4133
useSkewCookie: true,
4234
multiZoneDraftMode: true,
4335
appNavFailHandling: true,
4436
prerenderEarlyExit: true,
4537
linkNoTouchStart: true,
4638
caseSensitiveRoutes: true,
47-
// clientParamParsingOrigins: [],
4839
dynamicOnHover: true,
4940
preloadEntriesOnStart: true,
50-
fetchCacheKeyPrefix: "",
5141
isrFlushToDisk: true,
52-
// urlImports: [],
5342
workerThreads: true,
5443
disableOptimizedLoading: true,
5544
hideLogsAfterAbort: true,
5645
optimizeCss: true,
57-
// swcPlugins: [["./src/swc-plugin.js", {}]],
46+
esmExternals: true,
47+
scrollRestoration: true,
48+
cpus: 16,
49+
// cssChunking: true,
50+
// craCompat: true,
51+
// validateRSCRequestHeaders: true,
52+
webpackMemoryOptimizations: true,
53+
webpackBuildWorker: true,
54+
// turbopackTreeShaking: true,
55+
turbopackMinify: true,
56+
turbopackImportTypeBytes: true,
57+
// turbopackMemoryLimit: 8192,
58+
// turbopackRemoveUnusedExports: true,
59+
turbopackFileSystemCacheForDev: true,
60+
// turbopackFileSystemCacheForBuild: true,
61+
useCache: true,
62+
useLightningcss: true,
63+
useWasmBinary: true,
64+
// swcTraceProfiling: true,
5865
// forceSwcTransforms: true,
5966
ppr: false,
6067
},

0 commit comments

Comments
 (0)