@mastra/dynamodb 0.10.4-alpha.0 → 0.10.4-alpha.1

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.
@@ -1,17 +1,20 @@
1
1
  import type { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
2
2
  import { Entity } from 'electrodb';
3
3
  import type { EvalRow } from '@mastra/core/storage';
4
- import type { MastraMessageV1 } from '@mastra/core';
5
- import type { MastraMessageV2 } from '@mastra/core';
4
+ import type { MastraMessageV1 } from '@mastra/core/memory';
5
+ import type { MastraMessageV2 } from '@mastra/core/memory';
6
6
  import { MastraStorage } from '@mastra/core/storage';
7
+ import type { PaginationInfo } from '@mastra/core/storage';
7
8
  import { Service } from 'electrodb';
8
- import type { StorageColumn } from '@mastra/core';
9
+ import type { StorageColumn } from '@mastra/core/storage';
9
10
  import type { StorageGetMessagesArg } from '@mastra/core/storage';
10
- import type { StorageThreadType } from '@mastra/core';
11
+ import type { StorageGetTracesArg } from '@mastra/core/storage';
12
+ import type { StorageThreadType } from '@mastra/core/memory';
11
13
  import type { TABLE_NAMES } from '@mastra/core/storage';
14
+ import type { Trace } from '@mastra/core/telemetry';
12
15
  import type { WorkflowRun } from '@mastra/core/storage';
13
16
  import type { WorkflowRuns } from '@mastra/core/storage';
14
- import type { WorkflowRunState } from '@mastra/core';
17
+ import type { WorkflowRunState } from '@mastra/core/workflows';
15
18
 
16
19
  export declare const baseAttributes: {
17
20
  readonly createdAt: {
@@ -175,6 +178,19 @@ declare class DynamoDBStore extends MastraStorage {
175
178
  private formatWorkflowRun;
176
179
  private getEntityNameForTable;
177
180
  getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
181
+ getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & {
182
+ traces: Trace[];
183
+ }>;
184
+ getThreadsByResourceIdPaginated(_args: {
185
+ resourceId: string;
186
+ page?: number;
187
+ perPage?: number;
188
+ }): Promise<PaginationInfo & {
189
+ threads: StorageThreadType[];
190
+ }>;
191
+ getMessagesPaginated(_args: StorageGetMessagesArg): Promise<PaginationInfo & {
192
+ messages: MastraMessageV1[] | MastraMessageV2[];
193
+ }>;
178
194
  /**
179
195
  * Closes the DynamoDB client connection and cleans up resources.
180
196
  * Should be called when the store is no longer needed, e.g., at the end of tests or application shutdown.
@@ -1,17 +1,20 @@
1
1
  import type { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
2
2
  import { Entity } from 'electrodb';
3
3
  import type { EvalRow } from '@mastra/core/storage';
4
- import type { MastraMessageV1 } from '@mastra/core';
5
- import type { MastraMessageV2 } from '@mastra/core';
4
+ import type { MastraMessageV1 } from '@mastra/core/memory';
5
+ import type { MastraMessageV2 } from '@mastra/core/memory';
6
6
  import { MastraStorage } from '@mastra/core/storage';
7
+ import type { PaginationInfo } from '@mastra/core/storage';
7
8
  import { Service } from 'electrodb';
8
- import type { StorageColumn } from '@mastra/core';
9
+ import type { StorageColumn } from '@mastra/core/storage';
9
10
  import type { StorageGetMessagesArg } from '@mastra/core/storage';
10
- import type { StorageThreadType } from '@mastra/core';
11
+ import type { StorageGetTracesArg } from '@mastra/core/storage';
12
+ import type { StorageThreadType } from '@mastra/core/memory';
11
13
  import type { TABLE_NAMES } from '@mastra/core/storage';
14
+ import type { Trace } from '@mastra/core/telemetry';
12
15
  import type { WorkflowRun } from '@mastra/core/storage';
13
16
  import type { WorkflowRuns } from '@mastra/core/storage';
14
- import type { WorkflowRunState } from '@mastra/core';
17
+ import type { WorkflowRunState } from '@mastra/core/workflows';
15
18
 
16
19
  export declare const baseAttributes: {
17
20
  readonly createdAt: {
@@ -175,6 +178,19 @@ declare class DynamoDBStore extends MastraStorage {
175
178
  private formatWorkflowRun;
176
179
  private getEntityNameForTable;
177
180
  getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
181
+ getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & {
182
+ traces: Trace[];
183
+ }>;
184
+ getThreadsByResourceIdPaginated(_args: {
185
+ resourceId: string;
186
+ page?: number;
187
+ perPage?: number;
188
+ }): Promise<PaginationInfo & {
189
+ threads: StorageThreadType[];
190
+ }>;
191
+ getMessagesPaginated(_args: StorageGetMessagesArg): Promise<PaginationInfo & {
192
+ messages: MastraMessageV1[] | MastraMessageV2[];
193
+ }>;
178
194
  /**
179
195
  * Closes the DynamoDB client connection and cleans up resources.
180
196
  * Should be called when the store is no longer needed, e.g., at the end of tests or application shutdown.
package/dist/index.cjs CHANGED
@@ -1078,7 +1078,7 @@ var DynamoDBStore = class extends storage.MastraStorage {
1078
1078
  updatedAt: now,
1079
1079
  resourceId
1080
1080
  };
1081
- await this.service.entities.workflowSnapshot.create(data).go();
1081
+ await this.service.entities.workflowSnapshot.upsert(data).go();
1082
1082
  } catch (error) {
1083
1083
  this.logger.error("Failed to persist workflow snapshot", { workflowName, runId, error });
1084
1084
  throw error;
@@ -1293,6 +1293,15 @@ var DynamoDBStore = class extends storage.MastraStorage {
1293
1293
  throw error;
1294
1294
  }
1295
1295
  }
1296
+ async getTracesPaginated(_args) {
1297
+ throw new Error("Method not implemented.");
1298
+ }
1299
+ async getThreadsByResourceIdPaginated(_args) {
1300
+ throw new Error("Method not implemented.");
1301
+ }
1302
+ async getMessagesPaginated(_args) {
1303
+ throw new Error("Method not implemented.");
1304
+ }
1296
1305
  /**
1297
1306
  * Closes the DynamoDB client connection and cleans up resources.
1298
1307
  * Should be called when the store is no longer needed, e.g., at the end of tests or application shutdown.
package/dist/index.js CHANGED
@@ -1076,7 +1076,7 @@ var DynamoDBStore = class extends MastraStorage {
1076
1076
  updatedAt: now,
1077
1077
  resourceId
1078
1078
  };
1079
- await this.service.entities.workflowSnapshot.create(data).go();
1079
+ await this.service.entities.workflowSnapshot.upsert(data).go();
1080
1080
  } catch (error) {
1081
1081
  this.logger.error("Failed to persist workflow snapshot", { workflowName, runId, error });
1082
1082
  throw error;
@@ -1291,6 +1291,15 @@ var DynamoDBStore = class extends MastraStorage {
1291
1291
  throw error;
1292
1292
  }
1293
1293
  }
1294
+ async getTracesPaginated(_args) {
1295
+ throw new Error("Method not implemented.");
1296
+ }
1297
+ async getThreadsByResourceIdPaginated(_args) {
1298
+ throw new Error("Method not implemented.");
1299
+ }
1300
+ async getMessagesPaginated(_args) {
1301
+ throw new Error("Method not implemented.");
1302
+ }
1294
1303
  /**
1295
1304
  * Closes the DynamoDB client connection and cleans up resources.
1296
1305
  * Should be called when the store is no longer needed, e.g., at the end of tests or application shutdown.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/dynamodb",
3
- "version": "0.10.4-alpha.0",
3
+ "version": "0.10.4-alpha.1",
4
4
  "description": "DynamoDB storage adapter for Mastra",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -42,7 +42,7 @@
42
42
  "vitest": "^3.2.2",
43
43
  "@internal/lint": "0.0.10",
44
44
  "@internal/storage-test-utils": "0.0.6",
45
- "@mastra/core": "0.10.4-alpha.1"
45
+ "@mastra/core": "0.10.4-alpha.3"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
@@ -901,6 +901,53 @@ describe('DynamoDBStore Integration Tests', () => {
901
901
  expect(loadedSnapshot?.context).toEqual(snapshot.context);
902
902
  });
903
903
 
904
+ test('should allow updating an existing workflow snapshot', async () => {
905
+ const wfName = 'update-test-wf';
906
+ const runId = `run-${randomUUID()}`;
907
+
908
+ // Create initial snapshot
909
+ const { snapshot: initialSnapshot } = sampleWorkflowSnapshot(wfName, runId);
910
+
911
+ await expect(
912
+ store.persistWorkflowSnapshot({
913
+ workflowName: wfName,
914
+ runId: runId,
915
+ snapshot: initialSnapshot,
916
+ }),
917
+ ).resolves.not.toThrow();
918
+
919
+ // Create updated snapshot with different data
920
+ const updatedSnapshot: WorkflowRunState = {
921
+ ...initialSnapshot,
922
+ value: { currentState: 'completed' },
923
+ context: {
924
+ step1: { status: 'success', output: { data: 'updated-test' } },
925
+ step2: { status: 'success', output: { data: 'new-step' } },
926
+ input: { source: 'updated-test' },
927
+ } as unknown as WorkflowRunState['context'],
928
+ timestamp: Date.now(),
929
+ };
930
+
931
+ // This should succeed (update existing snapshot)
932
+ await expect(
933
+ store.persistWorkflowSnapshot({
934
+ workflowName: wfName,
935
+ runId: runId,
936
+ snapshot: updatedSnapshot,
937
+ }),
938
+ ).resolves.not.toThrow();
939
+
940
+ // Verify the snapshot was updated
941
+ const loadedSnapshot = await store.loadWorkflowSnapshot({
942
+ workflowName: wfName,
943
+ runId: runId,
944
+ });
945
+
946
+ expect(loadedSnapshot?.runId).toEqual(updatedSnapshot.runId);
947
+ expect(loadedSnapshot?.value).toEqual(updatedSnapshot.value);
948
+ expect(loadedSnapshot?.context).toEqual(updatedSnapshot.context);
949
+ });
950
+
904
951
  test('getWorkflowRunById should retrieve correct run', async () => {
905
952
  const wfName = 'get-by-id-wf';
906
953
  const runId1 = `run-${randomUUID()}`;
@@ -1,13 +1,8 @@
1
1
  import { DynamoDBClient, DescribeTableCommand } from '@aws-sdk/client-dynamodb';
2
2
  import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
3
- import type {
4
- StorageThreadType,
5
- WorkflowRunState,
6
- MastraMessageV1,
7
- MastraMessageV2,
8
- StorageColumn,
9
- } from '@mastra/core';
10
3
  import { MessageList } from '@mastra/core/agent';
4
+ import type { StorageThreadType, MastraMessageV2, MastraMessageV1 } from '@mastra/core/memory';
5
+
11
6
  import {
12
7
  MastraStorage,
13
8
  TABLE_THREADS,
@@ -16,7 +11,18 @@ import {
16
11
  TABLE_EVALS,
17
12
  TABLE_TRACES,
18
13
  } from '@mastra/core/storage';
19
- import type { EvalRow, StorageGetMessagesArg, WorkflowRun, WorkflowRuns, TABLE_NAMES } from '@mastra/core/storage';
14
+ import type {
15
+ EvalRow,
16
+ StorageGetMessagesArg,
17
+ WorkflowRun,
18
+ WorkflowRuns,
19
+ TABLE_NAMES,
20
+ StorageGetTracesArg,
21
+ PaginationInfo,
22
+ StorageColumn,
23
+ } from '@mastra/core/storage';
24
+ import type { Trace } from '@mastra/core/telemetry';
25
+ import type { WorkflowRunState } from '@mastra/core/workflows';
20
26
  import type { Service } from 'electrodb';
21
27
  import { getElectroDbService } from '../entities';
22
28
 
@@ -771,8 +777,8 @@ export class DynamoDBStore extends MastraStorage {
771
777
  updatedAt: now,
772
778
  resourceId,
773
779
  };
774
- // Pass the data including 'entity'
775
- await this.service.entities.workflowSnapshot.create(data).go();
780
+ // Use upsert instead of create to handle both create and update cases
781
+ await this.service.entities.workflowSnapshot.upsert(data).go();
776
782
  } catch (error) {
777
783
  this.logger.error('Failed to persist workflow snapshot', { workflowName, runId, error });
778
784
  throw error;
@@ -1077,6 +1083,24 @@ export class DynamoDBStore extends MastraStorage {
1077
1083
  }
1078
1084
  }
1079
1085
 
1086
+ async getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & { traces: Trace[] }> {
1087
+ throw new Error('Method not implemented.');
1088
+ }
1089
+
1090
+ async getThreadsByResourceIdPaginated(_args: {
1091
+ resourceId: string;
1092
+ page?: number;
1093
+ perPage?: number;
1094
+ }): Promise<PaginationInfo & { threads: StorageThreadType[] }> {
1095
+ throw new Error('Method not implemented.');
1096
+ }
1097
+
1098
+ async getMessagesPaginated(
1099
+ _args: StorageGetMessagesArg,
1100
+ ): Promise<PaginationInfo & { messages: MastraMessageV1[] | MastraMessageV2[] }> {
1101
+ throw new Error('Method not implemented.');
1102
+ }
1103
+
1080
1104
  /**
1081
1105
  * Closes the DynamoDB client connection and cleans up resources.
1082
1106
  * Should be called when the store is no longer needed, e.g., at the end of tests or application shutdown.