Skip to content

Commit ffc1f1f

Browse files
committed
add support for dynamodb for mastra memory storage
1 parent e2023e0 commit ffc1f1f

File tree

3 files changed

+620
-67
lines changed

3 files changed

+620
-67
lines changed

typescript-sdk/apps/dojo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@copilotkit/shared": "1.8.14-next.4",
2828
"@mastra/client-js": "^0.10.9",
2929
"@mastra/core": "^0.10.10",
30+
"@mastra/dynamodb": "^0.13.0",
3031
"@mastra/libsql": "^0.11.0",
3132
"@mastra/loggers": "^0.10.3",
3233
"@mastra/memory": "^0.11.1",

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,24 @@ import { openai } from "@ai-sdk/openai";
22
import { Agent } from "@mastra/core/agent";
33
import { Memory } from "@mastra/memory";
44
import { LibSQLStore } from "@mastra/libsql";
5+
import { DynamoDBStore } from "@mastra/dynamodb";
6+
57
import { Mastra } from "@mastra/core";
68
import { z } from "zod";
79

8-
// import { weatherTool } from "../tools/weather-tool";
10+
11+
let storage: LibSQLStore | DynamoDBStore
12+
13+
if (process.env.DYNAMODB_TABLE_NAME) {
14+
storage = new DynamoDBStore({
15+
name: "dynamodb",
16+
config: {
17+
tableName: process.env.DYNAMODB_TABLE_NAME
18+
},
19+
});
20+
} else {
21+
storage = new LibSQLStore({ url: "file::memory:" });
22+
}
923

1024
export const mastra = new Mastra({
1125
agents: {
@@ -24,9 +38,8 @@ export const mastra = new Mastra({
2438
Use the weatherTool to fetch current weather data.
2539
`,
2640
model: openai("gpt-4o"),
27-
// tools: { weatherTool },
2841
memory: new Memory({
29-
storage: new LibSQLStore({ url: "file::memory:" }),
42+
storage: storage,
3043
options: {
3144
workingMemory: {
3245
enabled: true,
@@ -53,7 +66,7 @@ export const mastra = new Mastra({
5366
`,
5467
model: openai("gpt-4o"),
5568
memory: new Memory({
56-
storage: new LibSQLStore({ url: "file::memory:" }),
69+
storage: storage,
5770
options: {
5871
workingMemory: {
5972
enabled: true,

0 commit comments

Comments
 (0)