@mastra/upstash 0.14.5 → 0.14.6-alpha.0
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 +9 -0
- package/package.json +17 -4
- package/.turbo/turbo-build.log +0 -4
- package/PAGINATION.md +0 -397
- package/docker-compose.yaml +0 -15
- package/eslint.config.js +0 -6
- package/src/index.ts +0 -3
- package/src/storage/domains/legacy-evals/index.ts +0 -279
- package/src/storage/domains/memory/index.ts +0 -1039
- package/src/storage/domains/operations/index.ts +0 -168
- package/src/storage/domains/scores/index.ts +0 -231
- package/src/storage/domains/traces/index.ts +0 -172
- package/src/storage/domains/utils.ts +0 -65
- package/src/storage/domains/workflows/index.ts +0 -280
- package/src/storage/index.test.ts +0 -13
- package/src/storage/index.ts +0 -404
- package/src/vector/filter.test.ts +0 -558
- package/src/vector/filter.ts +0 -260
- package/src/vector/hybrid.test.ts +0 -1455
- package/src/vector/index.test.ts +0 -1205
- package/src/vector/index.ts +0 -291
- package/src/vector/prompt.ts +0 -77
- package/src/vector/types.ts +0 -26
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
- package/tsup.config.ts +0 -17
- package/vitest.config.ts +0 -11
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import type { StepResult, WorkflowRun, WorkflowRuns, WorkflowRunState } from '@mastra/core';
|
|
2
|
-
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
3
|
-
import { TABLE_WORKFLOW_SNAPSHOT, WorkflowsStorage } from '@mastra/core/storage';
|
|
4
|
-
import type { Redis } from '@upstash/redis';
|
|
5
|
-
import type { StoreOperationsUpstash } from '../operations';
|
|
6
|
-
import { ensureDate, getKey } from '../utils';
|
|
7
|
-
|
|
8
|
-
function parseWorkflowRun(row: any): WorkflowRun {
|
|
9
|
-
let parsedSnapshot: WorkflowRunState | string = row.snapshot as string;
|
|
10
|
-
if (typeof parsedSnapshot === 'string') {
|
|
11
|
-
try {
|
|
12
|
-
parsedSnapshot = JSON.parse(row.snapshot as string) as WorkflowRunState;
|
|
13
|
-
} catch (e) {
|
|
14
|
-
// If parsing fails, return the raw snapshot string
|
|
15
|
-
console.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
workflowName: row.workflow_name,
|
|
21
|
-
runId: row.run_id,
|
|
22
|
-
snapshot: parsedSnapshot,
|
|
23
|
-
createdAt: ensureDate(row.createdAt)!,
|
|
24
|
-
updatedAt: ensureDate(row.updatedAt)!,
|
|
25
|
-
resourceId: row.resourceId,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export class WorkflowsUpstash extends WorkflowsStorage {
|
|
29
|
-
private client: Redis;
|
|
30
|
-
private operations: StoreOperationsUpstash;
|
|
31
|
-
|
|
32
|
-
constructor({ client, operations }: { client: Redis; operations: StoreOperationsUpstash }) {
|
|
33
|
-
super();
|
|
34
|
-
this.client = client;
|
|
35
|
-
this.operations = operations;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
updateWorkflowResults(
|
|
39
|
-
{
|
|
40
|
-
// workflowName,
|
|
41
|
-
// runId,
|
|
42
|
-
// stepId,
|
|
43
|
-
// result,
|
|
44
|
-
// runtimeContext,
|
|
45
|
-
}: {
|
|
46
|
-
workflowName: string;
|
|
47
|
-
runId: string;
|
|
48
|
-
stepId: string;
|
|
49
|
-
result: StepResult<any, any, any, any>;
|
|
50
|
-
runtimeContext: Record<string, any>;
|
|
51
|
-
},
|
|
52
|
-
): Promise<Record<string, StepResult<any, any, any, any>>> {
|
|
53
|
-
throw new Error('Method not implemented.');
|
|
54
|
-
}
|
|
55
|
-
updateWorkflowState(
|
|
56
|
-
{
|
|
57
|
-
// workflowName,
|
|
58
|
-
// runId,
|
|
59
|
-
// opts,
|
|
60
|
-
}: {
|
|
61
|
-
workflowName: string;
|
|
62
|
-
runId: string;
|
|
63
|
-
opts: {
|
|
64
|
-
status: string;
|
|
65
|
-
result?: StepResult<any, any, any, any>;
|
|
66
|
-
error?: string;
|
|
67
|
-
suspendedPaths?: Record<string, number[]>;
|
|
68
|
-
waitingPaths?: Record<string, number[]>;
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
): Promise<WorkflowRunState | undefined> {
|
|
72
|
-
throw new Error('Method not implemented.');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async persistWorkflowSnapshot(params: {
|
|
76
|
-
namespace: string;
|
|
77
|
-
workflowName: string;
|
|
78
|
-
runId: string;
|
|
79
|
-
snapshot: WorkflowRunState;
|
|
80
|
-
}): Promise<void> {
|
|
81
|
-
const { namespace = 'workflows', workflowName, runId, snapshot } = params;
|
|
82
|
-
try {
|
|
83
|
-
await this.operations.insert({
|
|
84
|
-
tableName: TABLE_WORKFLOW_SNAPSHOT,
|
|
85
|
-
record: {
|
|
86
|
-
namespace,
|
|
87
|
-
workflow_name: workflowName,
|
|
88
|
-
run_id: runId,
|
|
89
|
-
snapshot,
|
|
90
|
-
createdAt: new Date(),
|
|
91
|
-
updatedAt: new Date(),
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
} catch (error) {
|
|
95
|
-
throw new MastraError(
|
|
96
|
-
{
|
|
97
|
-
id: 'STORAGE_UPSTASH_STORAGE_PERSIST_WORKFLOW_SNAPSHOT_FAILED',
|
|
98
|
-
domain: ErrorDomain.STORAGE,
|
|
99
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
100
|
-
details: {
|
|
101
|
-
namespace,
|
|
102
|
-
workflowName,
|
|
103
|
-
runId,
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
error,
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async loadWorkflowSnapshot(params: {
|
|
112
|
-
namespace: string;
|
|
113
|
-
workflowName: string;
|
|
114
|
-
runId: string;
|
|
115
|
-
}): Promise<WorkflowRunState | null> {
|
|
116
|
-
const { namespace = 'workflows', workflowName, runId } = params;
|
|
117
|
-
const key = getKey(TABLE_WORKFLOW_SNAPSHOT, {
|
|
118
|
-
namespace,
|
|
119
|
-
workflow_name: workflowName,
|
|
120
|
-
run_id: runId,
|
|
121
|
-
});
|
|
122
|
-
try {
|
|
123
|
-
const data = await this.client.get<{
|
|
124
|
-
namespace: string;
|
|
125
|
-
workflow_name: string;
|
|
126
|
-
run_id: string;
|
|
127
|
-
snapshot: WorkflowRunState;
|
|
128
|
-
}>(key);
|
|
129
|
-
if (!data) return null;
|
|
130
|
-
return data.snapshot;
|
|
131
|
-
} catch (error) {
|
|
132
|
-
throw new MastraError(
|
|
133
|
-
{
|
|
134
|
-
id: 'STORAGE_UPSTASH_STORAGE_LOAD_WORKFLOW_SNAPSHOT_FAILED',
|
|
135
|
-
domain: ErrorDomain.STORAGE,
|
|
136
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
137
|
-
details: {
|
|
138
|
-
namespace,
|
|
139
|
-
workflowName,
|
|
140
|
-
runId,
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
error,
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async getWorkflowRunById({
|
|
149
|
-
runId,
|
|
150
|
-
workflowName,
|
|
151
|
-
}: {
|
|
152
|
-
runId: string;
|
|
153
|
-
workflowName?: string;
|
|
154
|
-
}): Promise<WorkflowRun | null> {
|
|
155
|
-
try {
|
|
156
|
-
const key =
|
|
157
|
-
getKey(TABLE_WORKFLOW_SNAPSHOT, { namespace: 'workflows', workflow_name: workflowName, run_id: runId }) + '*';
|
|
158
|
-
const keys = await this.operations.scanKeys(key);
|
|
159
|
-
const workflows = await Promise.all(
|
|
160
|
-
keys.map(async key => {
|
|
161
|
-
const data = await this.client.get<{
|
|
162
|
-
workflow_name: string;
|
|
163
|
-
run_id: string;
|
|
164
|
-
snapshot: WorkflowRunState | string;
|
|
165
|
-
createdAt: string | Date;
|
|
166
|
-
updatedAt: string | Date;
|
|
167
|
-
resourceId: string;
|
|
168
|
-
}>(key);
|
|
169
|
-
return data;
|
|
170
|
-
}),
|
|
171
|
-
);
|
|
172
|
-
const data = workflows.find(w => w?.run_id === runId && w?.workflow_name === workflowName) as WorkflowRun | null;
|
|
173
|
-
if (!data) return null;
|
|
174
|
-
return parseWorkflowRun(data);
|
|
175
|
-
} catch (error) {
|
|
176
|
-
throw new MastraError(
|
|
177
|
-
{
|
|
178
|
-
id: 'STORAGE_UPSTASH_STORAGE_GET_WORKFLOW_RUN_BY_ID_FAILED',
|
|
179
|
-
domain: ErrorDomain.STORAGE,
|
|
180
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
181
|
-
details: {
|
|
182
|
-
namespace: 'workflows',
|
|
183
|
-
runId,
|
|
184
|
-
workflowName: workflowName || '',
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
error,
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
async getWorkflowRuns({
|
|
193
|
-
workflowName,
|
|
194
|
-
fromDate,
|
|
195
|
-
toDate,
|
|
196
|
-
limit,
|
|
197
|
-
offset,
|
|
198
|
-
resourceId,
|
|
199
|
-
}: {
|
|
200
|
-
workflowName?: string;
|
|
201
|
-
fromDate?: Date;
|
|
202
|
-
toDate?: Date;
|
|
203
|
-
limit?: number;
|
|
204
|
-
offset?: number;
|
|
205
|
-
resourceId?: string;
|
|
206
|
-
}): Promise<WorkflowRuns> {
|
|
207
|
-
try {
|
|
208
|
-
// Get all workflow keys
|
|
209
|
-
let pattern = getKey(TABLE_WORKFLOW_SNAPSHOT, { namespace: 'workflows' }) + ':*';
|
|
210
|
-
if (workflowName && resourceId) {
|
|
211
|
-
pattern = getKey(TABLE_WORKFLOW_SNAPSHOT, {
|
|
212
|
-
namespace: 'workflows',
|
|
213
|
-
workflow_name: workflowName,
|
|
214
|
-
run_id: '*',
|
|
215
|
-
resourceId,
|
|
216
|
-
});
|
|
217
|
-
} else if (workflowName) {
|
|
218
|
-
pattern = getKey(TABLE_WORKFLOW_SNAPSHOT, { namespace: 'workflows', workflow_name: workflowName }) + ':*';
|
|
219
|
-
} else if (resourceId) {
|
|
220
|
-
pattern = getKey(TABLE_WORKFLOW_SNAPSHOT, {
|
|
221
|
-
namespace: 'workflows',
|
|
222
|
-
workflow_name: '*',
|
|
223
|
-
run_id: '*',
|
|
224
|
-
resourceId,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
const keys = await this.operations.scanKeys(pattern);
|
|
228
|
-
|
|
229
|
-
// Check if we have any keys before using pipeline
|
|
230
|
-
if (keys.length === 0) {
|
|
231
|
-
return { runs: [], total: 0 };
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Use pipeline for batch fetching to improve performance
|
|
235
|
-
const pipeline = this.client.pipeline();
|
|
236
|
-
keys.forEach(key => pipeline.get(key));
|
|
237
|
-
const results = await pipeline.exec();
|
|
238
|
-
|
|
239
|
-
// Filter and transform results - handle undefined results
|
|
240
|
-
let runs = results
|
|
241
|
-
.map((result: any) => result as Record<string, any> | null)
|
|
242
|
-
.filter(
|
|
243
|
-
(record): record is Record<string, any> =>
|
|
244
|
-
record !== null && record !== undefined && typeof record === 'object' && 'workflow_name' in record,
|
|
245
|
-
)
|
|
246
|
-
// Only filter by workflowName if it was specifically requested
|
|
247
|
-
.filter(record => !workflowName || record.workflow_name === workflowName)
|
|
248
|
-
.map(w => parseWorkflowRun(w!))
|
|
249
|
-
.filter(w => {
|
|
250
|
-
if (fromDate && w.createdAt < fromDate) return false;
|
|
251
|
-
if (toDate && w.createdAt > toDate) return false;
|
|
252
|
-
return true;
|
|
253
|
-
})
|
|
254
|
-
.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
|
255
|
-
|
|
256
|
-
const total = runs.length;
|
|
257
|
-
|
|
258
|
-
// Apply pagination if requested
|
|
259
|
-
if (limit !== undefined && offset !== undefined) {
|
|
260
|
-
runs = runs.slice(offset, offset + limit);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return { runs, total };
|
|
264
|
-
} catch (error) {
|
|
265
|
-
throw new MastraError(
|
|
266
|
-
{
|
|
267
|
-
id: 'STORAGE_UPSTASH_STORAGE_GET_WORKFLOW_RUNS_FAILED',
|
|
268
|
-
domain: ErrorDomain.STORAGE,
|
|
269
|
-
category: ErrorCategory.THIRD_PARTY,
|
|
270
|
-
details: {
|
|
271
|
-
namespace: 'workflows',
|
|
272
|
-
workflowName: workflowName || '',
|
|
273
|
-
resourceId: resourceId || '',
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
error,
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createTestSuite } from '@internal/storage-test-utils';
|
|
2
|
-
import { vi } from 'vitest';
|
|
3
|
-
import { UpstashStore } from './index';
|
|
4
|
-
|
|
5
|
-
// Increase timeout for all tests in this file to 30 seconds
|
|
6
|
-
vi.setConfig({ testTimeout: 200_000, hookTimeout: 200_000 });
|
|
7
|
-
|
|
8
|
-
createTestSuite(
|
|
9
|
-
new UpstashStore({
|
|
10
|
-
url: 'http://localhost:8079',
|
|
11
|
-
token: 'test_token',
|
|
12
|
-
}),
|
|
13
|
-
);
|
package/src/storage/index.ts
DELETED
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
import type { MastraMessageContentV2, MastraMessageV2 } from '@mastra/core/agent';
|
|
2
|
-
import type { StorageThreadType, MastraMessageV1 } from '@mastra/core/memory';
|
|
3
|
-
import type { ScoreRowData, ScoringSource } from '@mastra/core/scores';
|
|
4
|
-
import { MastraStorage } from '@mastra/core/storage';
|
|
5
|
-
import type {
|
|
6
|
-
TABLE_NAMES,
|
|
7
|
-
StorageColumn,
|
|
8
|
-
StorageGetMessagesArg,
|
|
9
|
-
StorageResourceType,
|
|
10
|
-
EvalRow,
|
|
11
|
-
WorkflowRuns,
|
|
12
|
-
WorkflowRun,
|
|
13
|
-
PaginationInfo,
|
|
14
|
-
PaginationArgs,
|
|
15
|
-
StorageGetTracesArg,
|
|
16
|
-
StoragePagination,
|
|
17
|
-
StorageDomains,
|
|
18
|
-
} from '@mastra/core/storage';
|
|
19
|
-
|
|
20
|
-
import type { StepResult, WorkflowRunState } from '@mastra/core/workflows';
|
|
21
|
-
import { Redis } from '@upstash/redis';
|
|
22
|
-
import { StoreLegacyEvalsUpstash } from './domains/legacy-evals';
|
|
23
|
-
import { StoreMemoryUpstash } from './domains/memory';
|
|
24
|
-
import { StoreOperationsUpstash } from './domains/operations';
|
|
25
|
-
import { ScoresUpstash } from './domains/scores';
|
|
26
|
-
import { TracesUpstash } from './domains/traces';
|
|
27
|
-
import { WorkflowsUpstash } from './domains/workflows';
|
|
28
|
-
|
|
29
|
-
export interface UpstashConfig {
|
|
30
|
-
url: string;
|
|
31
|
-
token: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export class UpstashStore extends MastraStorage {
|
|
35
|
-
private redis: Redis;
|
|
36
|
-
stores: StorageDomains;
|
|
37
|
-
|
|
38
|
-
constructor(config: UpstashConfig) {
|
|
39
|
-
super({ name: 'Upstash' });
|
|
40
|
-
this.redis = new Redis({
|
|
41
|
-
url: config.url,
|
|
42
|
-
token: config.token,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const operations = new StoreOperationsUpstash({ client: this.redis });
|
|
46
|
-
const traces = new TracesUpstash({ client: this.redis, operations });
|
|
47
|
-
const scores = new ScoresUpstash({ client: this.redis, operations });
|
|
48
|
-
const workflows = new WorkflowsUpstash({ client: this.redis, operations });
|
|
49
|
-
const memory = new StoreMemoryUpstash({ client: this.redis, operations });
|
|
50
|
-
const legacyEvals = new StoreLegacyEvalsUpstash({ client: this.redis, operations });
|
|
51
|
-
|
|
52
|
-
this.stores = {
|
|
53
|
-
operations,
|
|
54
|
-
traces,
|
|
55
|
-
scores,
|
|
56
|
-
workflows,
|
|
57
|
-
memory,
|
|
58
|
-
legacyEvals,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public get supports() {
|
|
63
|
-
return {
|
|
64
|
-
selectByIncludeResourceScope: true,
|
|
65
|
-
resourceWorkingMemory: true,
|
|
66
|
-
hasColumn: false,
|
|
67
|
-
createTable: false,
|
|
68
|
-
deleteMessages: true,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @deprecated Use getEvals instead
|
|
74
|
-
*/
|
|
75
|
-
async getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]> {
|
|
76
|
-
return this.stores.legacyEvals.getEvalsByAgentName(agentName, type);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Get all evaluations with pagination and total count
|
|
81
|
-
* @param options Pagination and filtering options
|
|
82
|
-
* @returns Object with evals array and total count
|
|
83
|
-
*/
|
|
84
|
-
async getEvals(
|
|
85
|
-
options: {
|
|
86
|
-
agentName?: string;
|
|
87
|
-
type?: 'test' | 'live';
|
|
88
|
-
} & PaginationArgs,
|
|
89
|
-
): Promise<PaginationInfo & { evals: EvalRow[] }> {
|
|
90
|
-
return this.stores.legacyEvals.getEvals(options);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* @deprecated use getTracesPaginated instead
|
|
95
|
-
*/
|
|
96
|
-
public async getTraces(args: StorageGetTracesArg): Promise<any[]> {
|
|
97
|
-
return this.stores.traces.getTraces(args);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public async getTracesPaginated(
|
|
101
|
-
args: {
|
|
102
|
-
name?: string;
|
|
103
|
-
scope?: string;
|
|
104
|
-
attributes?: Record<string, string>;
|
|
105
|
-
filters?: Record<string, any>;
|
|
106
|
-
} & PaginationArgs,
|
|
107
|
-
): Promise<PaginationInfo & { traces: any[] }> {
|
|
108
|
-
return this.stores.traces.getTracesPaginated(args);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async batchTraceInsert(args: { records: Record<string, any>[] }): Promise<void> {
|
|
112
|
-
return this.stores.traces.batchTraceInsert(args);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async createTable({
|
|
116
|
-
tableName,
|
|
117
|
-
schema,
|
|
118
|
-
}: {
|
|
119
|
-
tableName: TABLE_NAMES;
|
|
120
|
-
schema: Record<string, StorageColumn>;
|
|
121
|
-
}): Promise<void> {
|
|
122
|
-
return this.stores.operations.createTable({ tableName, schema });
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* No-op: This backend is schemaless and does not require schema changes.
|
|
127
|
-
* @param tableName Name of the table
|
|
128
|
-
* @param schema Schema of the table
|
|
129
|
-
* @param ifNotExists Array of column names to add if they don't exist
|
|
130
|
-
*/
|
|
131
|
-
async alterTable(args: {
|
|
132
|
-
tableName: TABLE_NAMES;
|
|
133
|
-
schema: Record<string, StorageColumn>;
|
|
134
|
-
ifNotExists: string[];
|
|
135
|
-
}): Promise<void> {
|
|
136
|
-
return this.stores.operations.alterTable(args);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async clearTable({ tableName }: { tableName: TABLE_NAMES }): Promise<void> {
|
|
140
|
-
return this.stores.operations.clearTable({ tableName });
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
async dropTable({ tableName }: { tableName: TABLE_NAMES }): Promise<void> {
|
|
144
|
-
return this.stores.operations.dropTable({ tableName });
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async insert({ tableName, record }: { tableName: TABLE_NAMES; record: Record<string, any> }): Promise<void> {
|
|
148
|
-
return this.stores.operations.insert({ tableName, record });
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async batchInsert(input: { tableName: TABLE_NAMES; records: Record<string, any>[] }): Promise<void> {
|
|
152
|
-
return this.stores.operations.batchInsert(input);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
async load<R>({ tableName, keys }: { tableName: TABLE_NAMES; keys: Record<string, string> }): Promise<R | null> {
|
|
156
|
-
return this.stores.operations.load<R>({ tableName, keys });
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async getThreadById({ threadId }: { threadId: string }): Promise<StorageThreadType | null> {
|
|
160
|
-
return this.stores.memory.getThreadById({ threadId });
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* @deprecated use getThreadsByResourceIdPaginated instead
|
|
165
|
-
*/
|
|
166
|
-
async getThreadsByResourceId({ resourceId }: { resourceId: string }): Promise<StorageThreadType[]> {
|
|
167
|
-
return this.stores.memory.getThreadsByResourceId({ resourceId });
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
public async getThreadsByResourceIdPaginated(args: {
|
|
171
|
-
resourceId: string;
|
|
172
|
-
page: number;
|
|
173
|
-
perPage: number;
|
|
174
|
-
}): Promise<PaginationInfo & { threads: StorageThreadType[] }> {
|
|
175
|
-
return this.stores.memory.getThreadsByResourceIdPaginated(args);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
async saveThread({ thread }: { thread: StorageThreadType }): Promise<StorageThreadType> {
|
|
179
|
-
return this.stores.memory.saveThread({ thread });
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async updateThread({
|
|
183
|
-
id,
|
|
184
|
-
title,
|
|
185
|
-
metadata,
|
|
186
|
-
}: {
|
|
187
|
-
id: string;
|
|
188
|
-
title: string;
|
|
189
|
-
metadata: Record<string, unknown>;
|
|
190
|
-
}): Promise<StorageThreadType> {
|
|
191
|
-
return this.stores.memory.updateThread({ id, title, metadata });
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
async deleteThread({ threadId }: { threadId: string }): Promise<void> {
|
|
195
|
-
return this.stores.memory.deleteThread({ threadId });
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async saveMessages(args: { messages: MastraMessageV1[]; format?: undefined | 'v1' }): Promise<MastraMessageV1[]>;
|
|
199
|
-
async saveMessages(args: { messages: MastraMessageV2[]; format: 'v2' }): Promise<MastraMessageV2[]>;
|
|
200
|
-
async saveMessages(
|
|
201
|
-
args: { messages: MastraMessageV1[]; format?: undefined | 'v1' } | { messages: MastraMessageV2[]; format: 'v2' },
|
|
202
|
-
): Promise<MastraMessageV2[] | MastraMessageV1[]> {
|
|
203
|
-
return this.stores.memory.saveMessages(args);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* @deprecated use getMessagesPaginated instead
|
|
208
|
-
*/
|
|
209
|
-
public async getMessages(args: StorageGetMessagesArg & { format?: 'v1' }): Promise<MastraMessageV1[]>;
|
|
210
|
-
public async getMessages(args: StorageGetMessagesArg & { format: 'v2' }): Promise<MastraMessageV2[]>;
|
|
211
|
-
public async getMessages({
|
|
212
|
-
threadId,
|
|
213
|
-
selectBy,
|
|
214
|
-
format,
|
|
215
|
-
}: StorageGetMessagesArg & { format?: 'v1' | 'v2' }): Promise<MastraMessageV1[] | MastraMessageV2[]> {
|
|
216
|
-
return this.stores.memory.getMessages({ threadId, selectBy, format });
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
async getMessagesById({ messageIds, format }: { messageIds: string[]; format: 'v1' }): Promise<MastraMessageV1[]>;
|
|
220
|
-
async getMessagesById({ messageIds, format }: { messageIds: string[]; format?: 'v2' }): Promise<MastraMessageV2[]>;
|
|
221
|
-
async getMessagesById({
|
|
222
|
-
messageIds,
|
|
223
|
-
format,
|
|
224
|
-
}: {
|
|
225
|
-
messageIds: string[];
|
|
226
|
-
format?: 'v1' | 'v2';
|
|
227
|
-
}): Promise<MastraMessageV1[] | MastraMessageV2[]> {
|
|
228
|
-
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
public async getMessagesPaginated(
|
|
232
|
-
args: StorageGetMessagesArg & {
|
|
233
|
-
format?: 'v1' | 'v2';
|
|
234
|
-
},
|
|
235
|
-
): Promise<PaginationInfo & { messages: MastraMessageV1[] | MastraMessageV2[] }> {
|
|
236
|
-
return this.stores.memory.getMessagesPaginated(args);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
async updateWorkflowResults({
|
|
240
|
-
workflowName,
|
|
241
|
-
runId,
|
|
242
|
-
stepId,
|
|
243
|
-
result,
|
|
244
|
-
runtimeContext,
|
|
245
|
-
}: {
|
|
246
|
-
workflowName: string;
|
|
247
|
-
runId: string;
|
|
248
|
-
stepId: string;
|
|
249
|
-
result: StepResult<any, any, any, any>;
|
|
250
|
-
runtimeContext: Record<string, any>;
|
|
251
|
-
}): Promise<Record<string, StepResult<any, any, any, any>>> {
|
|
252
|
-
return this.stores.workflows.updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext });
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
async updateWorkflowState({
|
|
256
|
-
workflowName,
|
|
257
|
-
runId,
|
|
258
|
-
opts,
|
|
259
|
-
}: {
|
|
260
|
-
workflowName: string;
|
|
261
|
-
runId: string;
|
|
262
|
-
opts: {
|
|
263
|
-
status: string;
|
|
264
|
-
result?: StepResult<any, any, any, any>;
|
|
265
|
-
error?: string;
|
|
266
|
-
suspendedPaths?: Record<string, number[]>;
|
|
267
|
-
waitingPaths?: Record<string, number[]>;
|
|
268
|
-
};
|
|
269
|
-
}): Promise<WorkflowRunState | undefined> {
|
|
270
|
-
return this.stores.workflows.updateWorkflowState({ workflowName, runId, opts });
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
async persistWorkflowSnapshot(params: {
|
|
274
|
-
namespace: string;
|
|
275
|
-
workflowName: string;
|
|
276
|
-
runId: string;
|
|
277
|
-
snapshot: WorkflowRunState;
|
|
278
|
-
}): Promise<void> {
|
|
279
|
-
return this.stores.workflows.persistWorkflowSnapshot(params);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
async loadWorkflowSnapshot(params: {
|
|
283
|
-
namespace: string;
|
|
284
|
-
workflowName: string;
|
|
285
|
-
runId: string;
|
|
286
|
-
}): Promise<WorkflowRunState | null> {
|
|
287
|
-
return this.stores.workflows.loadWorkflowSnapshot(params);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
async getWorkflowRuns({
|
|
291
|
-
workflowName,
|
|
292
|
-
fromDate,
|
|
293
|
-
toDate,
|
|
294
|
-
limit,
|
|
295
|
-
offset,
|
|
296
|
-
resourceId,
|
|
297
|
-
}: {
|
|
298
|
-
workflowName?: string;
|
|
299
|
-
fromDate?: Date;
|
|
300
|
-
toDate?: Date;
|
|
301
|
-
limit?: number;
|
|
302
|
-
offset?: number;
|
|
303
|
-
resourceId?: string;
|
|
304
|
-
} = {}): Promise<WorkflowRuns> {
|
|
305
|
-
return this.stores.workflows.getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId });
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
async getWorkflowRunById({
|
|
309
|
-
runId,
|
|
310
|
-
workflowName,
|
|
311
|
-
}: {
|
|
312
|
-
runId: string;
|
|
313
|
-
workflowName?: string;
|
|
314
|
-
}): Promise<WorkflowRun | null> {
|
|
315
|
-
return this.stores.workflows.getWorkflowRunById({ runId, workflowName });
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
async close(): Promise<void> {
|
|
319
|
-
// No explicit cleanup needed for Upstash Redis
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
async updateMessages(args: {
|
|
323
|
-
messages: (Partial<Omit<MastraMessageV2, 'createdAt'>> & {
|
|
324
|
-
id: string;
|
|
325
|
-
content?: { metadata?: MastraMessageContentV2['metadata']; content?: MastraMessageContentV2['content'] };
|
|
326
|
-
})[];
|
|
327
|
-
}): Promise<MastraMessageV2[]> {
|
|
328
|
-
return this.stores.memory.updateMessages(args);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
async deleteMessages(messageIds: string[]): Promise<void> {
|
|
332
|
-
return this.stores.memory.deleteMessages(messageIds);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
async getResourceById({ resourceId }: { resourceId: string }): Promise<StorageResourceType | null> {
|
|
336
|
-
return this.stores.memory.getResourceById({ resourceId });
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
async saveResource({ resource }: { resource: StorageResourceType }): Promise<StorageResourceType> {
|
|
340
|
-
return this.stores.memory.saveResource({ resource });
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
async updateResource({
|
|
344
|
-
resourceId,
|
|
345
|
-
workingMemory,
|
|
346
|
-
metadata,
|
|
347
|
-
}: {
|
|
348
|
-
resourceId: string;
|
|
349
|
-
workingMemory?: string;
|
|
350
|
-
metadata?: Record<string, unknown>;
|
|
351
|
-
}): Promise<StorageResourceType> {
|
|
352
|
-
return this.stores.memory.updateResource({ resourceId, workingMemory, metadata });
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
async getScoreById({ id: _id }: { id: string }): Promise<ScoreRowData | null> {
|
|
356
|
-
return this.stores.scores.getScoreById({ id: _id });
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
async saveScore(score: ScoreRowData): Promise<{ score: ScoreRowData }> {
|
|
360
|
-
return this.stores.scores.saveScore(score);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
async getScoresByRunId({
|
|
364
|
-
runId,
|
|
365
|
-
pagination,
|
|
366
|
-
}: {
|
|
367
|
-
runId: string;
|
|
368
|
-
pagination: StoragePagination;
|
|
369
|
-
}): Promise<{ pagination: PaginationInfo; scores: ScoreRowData[] }> {
|
|
370
|
-
return this.stores.scores.getScoresByRunId({ runId, pagination });
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
async getScoresByEntityId({
|
|
374
|
-
entityId,
|
|
375
|
-
entityType,
|
|
376
|
-
pagination,
|
|
377
|
-
}: {
|
|
378
|
-
pagination: StoragePagination;
|
|
379
|
-
entityId: string;
|
|
380
|
-
entityType: string;
|
|
381
|
-
}): Promise<{ pagination: PaginationInfo; scores: ScoreRowData[] }> {
|
|
382
|
-
return this.stores.scores.getScoresByEntityId({
|
|
383
|
-
entityId,
|
|
384
|
-
entityType,
|
|
385
|
-
pagination,
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
async getScoresByScorerId({
|
|
390
|
-
scorerId,
|
|
391
|
-
pagination,
|
|
392
|
-
entityId,
|
|
393
|
-
entityType,
|
|
394
|
-
source,
|
|
395
|
-
}: {
|
|
396
|
-
scorerId: string;
|
|
397
|
-
pagination: StoragePagination;
|
|
398
|
-
entityId?: string;
|
|
399
|
-
entityType?: string;
|
|
400
|
-
source?: ScoringSource;
|
|
401
|
-
}): Promise<{ pagination: PaginationInfo; scores: ScoreRowData[] }> {
|
|
402
|
-
return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
|
|
403
|
-
}
|
|
404
|
-
}
|