@mastra/dynamodb 0.0.0-add-libsql-changeset-20250910154739
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +875 -0
- package/LICENSE.md +15 -0
- package/README.md +144 -0
- package/dist/entities/eval.d.ts +102 -0
- package/dist/entities/eval.d.ts.map +1 -0
- package/dist/entities/index.d.ts +746 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/message.d.ts +100 -0
- package/dist/entities/message.d.ts.map +1 -0
- package/dist/entities/resource.d.ts +54 -0
- package/dist/entities/resource.d.ts.map +1 -0
- package/dist/entities/score.d.ts +229 -0
- package/dist/entities/score.d.ts.map +1 -0
- package/dist/entities/thread.d.ts +69 -0
- package/dist/entities/thread.d.ts.map +1 -0
- package/dist/entities/trace.d.ts +127 -0
- package/dist/entities/trace.d.ts.map +1 -0
- package/dist/entities/utils.d.ts +21 -0
- package/dist/entities/utils.d.ts.map +1 -0
- package/dist/entities/workflow-snapshot.d.ts +74 -0
- package/dist/entities/workflow-snapshot.d.ts.map +1 -0
- package/dist/index.cjs +3139 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3137 -0
- package/dist/index.js.map +1 -0
- package/dist/storage/domains/legacy-evals/index.d.ts +19 -0
- package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +89 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -0
- package/dist/storage/domains/operations/index.d.ts +69 -0
- package/dist/storage/domains/operations/index.d.ts.map +1 -0
- package/dist/storage/domains/score/index.d.ts +43 -0
- package/dist/storage/domains/score/index.d.ts.map +1 -0
- package/dist/storage/domains/traces/index.d.ts +28 -0
- package/dist/storage/domains/traces/index.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +50 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +249 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/package.json +70 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# @mastra/dynamodb
|
|
2
|
+
|
|
3
|
+
A DynamoDB storage implementation for Mastra using a single-table design pattern with ElectroDB.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Efficient single-table design for all Mastra storage needs
|
|
8
|
+
- Based on ElectroDB for type-safe DynamoDB access
|
|
9
|
+
- Support for AWS credentials, regions, and endpoints
|
|
10
|
+
- Compatible with AWS DynamoDB Local for development
|
|
11
|
+
- Thread, Message, Trace, Eval, and Workflow operations
|
|
12
|
+
- Optimized for serverless environments
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @mastra/dynamodb
|
|
18
|
+
# or
|
|
19
|
+
pnpm add @mastra/dynamodb
|
|
20
|
+
# or
|
|
21
|
+
yarn add @mastra/dynamodb
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Prerequisites
|
|
25
|
+
|
|
26
|
+
Before using this package, you need to create a DynamoDB table with the required structure. See [TABLE_SETUP.md](./TABLE_SETUP.md) for detailed instructions on how to set up the table using CloudFormation or AWS CDK.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### Basic Usage
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { Memory } from '@mastra/memory';
|
|
34
|
+
import { DynamoDBStore } from '@mastra/dynamodb';
|
|
35
|
+
import { PineconeVector } from '@mastra/pinecone';
|
|
36
|
+
|
|
37
|
+
// Initialize the DynamoDB storage
|
|
38
|
+
const storage = new DynamoDBStore({
|
|
39
|
+
name: 'dynamodb',
|
|
40
|
+
config: {
|
|
41
|
+
region: 'us-east-1',
|
|
42
|
+
tableName: 'mastra-single-table', // Name of your DynamoDB table
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Initialize vector store (if using semantic recall)
|
|
47
|
+
const vector = new PineconeVector({
|
|
48
|
+
apiKey: process.env.PINECONE_API_KEY,
|
|
49
|
+
environment: process.env.PINECONE_ENVIRONMENT,
|
|
50
|
+
index: process.env.PINECONE_INDEX,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Memory combines storage (like DynamoDBStore) with an optional vector store for recall
|
|
54
|
+
// Create memory with DynamoDB storage
|
|
55
|
+
const memory = new Memory({
|
|
56
|
+
storage,
|
|
57
|
+
vector,
|
|
58
|
+
options: {
|
|
59
|
+
lastMessages: 10,
|
|
60
|
+
semanticRecall: true,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Local Development
|
|
66
|
+
|
|
67
|
+
For local development, you can use DynamoDB Local:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const storage = new DynamoDBStore({
|
|
71
|
+
name: 'dynamodb',
|
|
72
|
+
config: {
|
|
73
|
+
region: 'us-east-1',
|
|
74
|
+
tableName: 'mastra-single-table',
|
|
75
|
+
endpoint: 'http://localhost:8000', // Local DynamoDB endpoint
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### AWS IAM Permissions
|
|
81
|
+
|
|
82
|
+
The IAM role or user used by this package needs the following permissions:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"Version": "2012-10-17",
|
|
87
|
+
"Statement": [
|
|
88
|
+
{
|
|
89
|
+
"Effect": "Allow",
|
|
90
|
+
"Action": [
|
|
91
|
+
"dynamodb:DescribeTable",
|
|
92
|
+
"dynamodb:GetItem",
|
|
93
|
+
"dynamodb:PutItem",
|
|
94
|
+
"dynamodb:UpdateItem",
|
|
95
|
+
"dynamodb:DeleteItem",
|
|
96
|
+
"dynamodb:Query",
|
|
97
|
+
"dynamodb:Scan",
|
|
98
|
+
"dynamodb:BatchGetItem",
|
|
99
|
+
"dynamodb:BatchWriteItem"
|
|
100
|
+
],
|
|
101
|
+
"Resource": [
|
|
102
|
+
"arn:aws:dynamodb:*:*:table/${YOUR_TABLE_NAME}",
|
|
103
|
+
"arn:aws:dynamodb:*:*:table/${YOUR_TABLE_NAME}/index/*"
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Configuration Options
|
|
111
|
+
|
|
112
|
+
The `DynamoDBStore` constructor accepts the following configuration options:
|
|
113
|
+
|
|
114
|
+
| Option | Type | Required | Description |
|
|
115
|
+
| -------------------- | ------ | -------- | ---------------------------------------------------------- |
|
|
116
|
+
| `name` | string | Yes | A name for the storage instance |
|
|
117
|
+
| `config.region` | string | No | AWS region (default: 'us-east-1') |
|
|
118
|
+
| `config.tableName` | string | Yes | The name of your DynamoDB table |
|
|
119
|
+
| `config.endpoint` | string | No | Custom endpoint for DynamoDB (e.g., for local development) |
|
|
120
|
+
| `config.credentials` | object | No | AWS credentials (accessKeyId, secretAccessKey) |
|
|
121
|
+
|
|
122
|
+
## Architectural Approach
|
|
123
|
+
|
|
124
|
+
This storage adapter utilizes a **single-table design pattern** leveraging [ElectroDB](https://electrodb.dev/), which is a common and recommended approach for DynamoDB. This differs architecturally from relational database adapters (like `@mastra/pg` or `@mastra/libsql`) that typically use multiple tables, each dedicated to a specific entity (threads, messages, etc.).
|
|
125
|
+
|
|
126
|
+
Key aspects of this approach:
|
|
127
|
+
|
|
128
|
+
- **DynamoDB Native:** The single-table design is optimized for DynamoDB's key-value and query capabilities, often leading to better performance and scalability compared to mimicking relational models.
|
|
129
|
+
- **External Table Management:** Unlike some adapters that might offer helper functions to create tables via code, this adapter **expects the DynamoDB table and its associated Global Secondary Indexes (GSIs) to be provisioned externally** before use. Please refer to `TABLE_SETUP.md` for detailed instructions using tools like AWS CloudFormation or CDK. The adapter focuses solely on interacting with the pre-existing table structure.
|
|
130
|
+
- **Consistency via Interface:** While the underlying storage model differs, this adapter adheres to the same `MastraStorage` interface as other adapters, ensuring it can be used interchangeably within the Mastra `Memory` component.
|
|
131
|
+
|
|
132
|
+
## Advantage of Single-Table Design
|
|
133
|
+
|
|
134
|
+
This implementation uses a single-table design pattern with ElectroDB, which offers several advantages within the context of DynamoDB:
|
|
135
|
+
|
|
136
|
+
1. **Lower cost**: One table means fewer read/write capacity units to provision
|
|
137
|
+
2. **Better performance**: Related data is stored together for faster access
|
|
138
|
+
3. **Simplified administration**: Only one table to monitor and back up
|
|
139
|
+
4. **Reduced complexity**: Consistent access patterns across entities
|
|
140
|
+
5. **Transaction support**: Atomic operations across different entity types
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Entity } from 'electrodb';
|
|
2
|
+
export declare const evalEntity: Entity<string, string, string, {
|
|
3
|
+
model: {
|
|
4
|
+
entity: string;
|
|
5
|
+
version: string;
|
|
6
|
+
service: string;
|
|
7
|
+
};
|
|
8
|
+
attributes: {
|
|
9
|
+
input: {
|
|
10
|
+
type: "string";
|
|
11
|
+
required: true;
|
|
12
|
+
};
|
|
13
|
+
output: {
|
|
14
|
+
type: "string";
|
|
15
|
+
required: true;
|
|
16
|
+
};
|
|
17
|
+
result: {
|
|
18
|
+
type: "string";
|
|
19
|
+
required: true;
|
|
20
|
+
set: (value?: any) => any;
|
|
21
|
+
get: (value?: string) => any;
|
|
22
|
+
};
|
|
23
|
+
agent_name: {
|
|
24
|
+
type: "string";
|
|
25
|
+
required: true;
|
|
26
|
+
};
|
|
27
|
+
metric_name: {
|
|
28
|
+
type: "string";
|
|
29
|
+
required: true;
|
|
30
|
+
};
|
|
31
|
+
instructions: {
|
|
32
|
+
type: "string";
|
|
33
|
+
required: true;
|
|
34
|
+
};
|
|
35
|
+
test_info: {
|
|
36
|
+
type: "string";
|
|
37
|
+
required: false;
|
|
38
|
+
set: (value?: any) => any;
|
|
39
|
+
get: (value?: string) => string | undefined;
|
|
40
|
+
};
|
|
41
|
+
global_run_id: {
|
|
42
|
+
type: "string";
|
|
43
|
+
required: true;
|
|
44
|
+
};
|
|
45
|
+
run_id: {
|
|
46
|
+
type: "string";
|
|
47
|
+
required: true;
|
|
48
|
+
};
|
|
49
|
+
created_at: {
|
|
50
|
+
type: "string";
|
|
51
|
+
required: true;
|
|
52
|
+
default: () => string;
|
|
53
|
+
set: (value?: Date | string) => string;
|
|
54
|
+
};
|
|
55
|
+
createdAt: {
|
|
56
|
+
readonly type: "string";
|
|
57
|
+
readonly required: true;
|
|
58
|
+
readonly readOnly: true;
|
|
59
|
+
readonly set: (value?: Date | string) => string;
|
|
60
|
+
readonly default: () => string;
|
|
61
|
+
};
|
|
62
|
+
updatedAt: {
|
|
63
|
+
readonly type: "string";
|
|
64
|
+
readonly required: true;
|
|
65
|
+
readonly set: (value?: Date | string) => string;
|
|
66
|
+
readonly default: () => string;
|
|
67
|
+
};
|
|
68
|
+
metadata: {
|
|
69
|
+
readonly type: "string";
|
|
70
|
+
readonly set: (value?: Record<string, unknown> | string) => string | undefined;
|
|
71
|
+
readonly get: (value?: string) => any;
|
|
72
|
+
};
|
|
73
|
+
entity: {
|
|
74
|
+
type: "string";
|
|
75
|
+
required: true;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
indexes: {
|
|
79
|
+
primary: {
|
|
80
|
+
pk: {
|
|
81
|
+
field: string;
|
|
82
|
+
composite: ("entity" | "run_id")[];
|
|
83
|
+
};
|
|
84
|
+
sk: {
|
|
85
|
+
field: string;
|
|
86
|
+
composite: never[];
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
byAgent: {
|
|
90
|
+
index: string;
|
|
91
|
+
pk: {
|
|
92
|
+
field: string;
|
|
93
|
+
composite: ("entity" | "agent_name")[];
|
|
94
|
+
};
|
|
95
|
+
sk: {
|
|
96
|
+
field: string;
|
|
97
|
+
composite: "created_at"[];
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
}>;
|
|
102
|
+
//# sourceMappingURL=eval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval.d.ts","sourceRoot":"","sources":["../../src/entities/eval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;0BAwBH,GAAG;0BAOH,MAAM;;;;;;;;;;;;;;;;;0BAuBN,GAAG;0BAOH,MAAM;;;;;;;;;;;;;;0BAkBN,IAAI,GAAG,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmB/B,CAAC"}
|