Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feat/storage flavour durable objects #1652

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/src/storage/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ export abstract class MastraStorage extends MastraBase {
id: { type: 'text', nullable: false, primaryKey: true },
thread_id: { type: 'text', nullable: false },
content: { type: 'text', nullable: false },
role: { type: 'text', nullable: false },
type: { type: 'text', nullable: false },
createdAt: { type: 'timestamp', nullable: false },
},
});
Expand Down
12 changes: 10 additions & 2 deletions packages/core/src/storage/libsql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,29 @@ describe('MastraStorageLibSql', () => {
type: 'text',
threadId,
content: [{ type: 'text', text: 'Hello' }],
created_at: new Date().toISOString(),
createdAt: new Date().toISOString(),
}) as any;

beforeAll(async () => {
await storage.init();
});

afterAll(async () => {
beforeEach(async () => {
// Clear tables before each test
await storage.clearTable({ tableName: 'workflow_snapshot' });
await storage.clearTable({ tableName: 'evals' });
await storage.clearTable({ tableName: 'messages' });
await storage.clearTable({ tableName: 'threads' });
});

afterAll(async () => {
// Clear tables after tests
await storage.clearTable({ tableName: 'workflow_snapshot' });
await storage.clearTable({ tableName: 'evals' });
await storage.clearTable({ tableName: 'messages' });
await storage.clearTable({ tableName: 'threads' });
});

describe('Thread Operations', () => {
it('should create and retrieve a thread', async () => {
const thread = createSampleThread();
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/storage/libsql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ export class MastraStorageLibSql extends MastraStorage {

for (const message of messages) {
await tx.execute({
sql: `INSERT INTO ${MastraStorage.TABLE_MESSAGES} (id, thread_id, content, createdAt)
VALUES (?, ?, ?, ?)`,
args: [message.id, threadId, JSON.stringify(message), message.createdAt || new Date().toISOString()],
sql: `INSERT INTO ${MastraStorage.TABLE_MESSAGES} (id, thread_id, content, role, type, createdAt)
VALUES (?, ?, ?, ?, ?, ?)`,
args: [message.id, threadId, JSON.stringify(message), message.role, message.type, message.createdAt || new Date().toISOString()],
});
}

Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/storage/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { WorkflowRunState } from '../workflows';

export interface StorageColumn {
type: 'text' | 'timestamp';
type: 'text' | 'timestamp' | 'uuid' | 'jsonb' | 'integer';
primaryKey?: boolean;
nullable?: boolean;
references?: {
table: string;
column: string;
};
}

export interface WorkflowRow {
Expand Down
189 changes: 187 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions storage/durable-object/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@mastra/storage-durable-object",
"version": "0.0.0-alpha.0",
"description": "Cloudflare Durable Objects storage provider for Mastra",
"type": "module",
"main": "dist/index.js",
"module": "dist/storage-durable-object.esm.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/storage-durable-object.esm.js"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"./package.json": "./package.json"
},
"scripts": {
"build": "dts build",
"build:dev": "dts watch",
"test": "vitest run"
},
"dependencies": {
"@mastra/core": "workspace:*"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20250124.3",
"@tsconfig/recommended": "^1.0.7",
"@types/node": "^22.9.0",
"dts-cli": "^2.0.5",
"miniflare": "^3.20240117.0",
"vitest": "^2.1.8"
}
}
Loading
Loading