@mastra/libsql 0.13.8-alpha.0 → 0.13.8-alpha.2
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 +18 -0
- package/package.json +18 -5
- package/.turbo/turbo-build.log +0 -4
- package/eslint.config.js +0 -6
- package/src/index.ts +0 -3
- package/src/storage/domains/legacy-evals/index.ts +0 -149
- package/src/storage/domains/memory/index.ts +0 -937
- package/src/storage/domains/observability/index.ts +0 -237
- package/src/storage/domains/operations/index.ts +0 -506
- package/src/storage/domains/scores/index.ts +0 -226
- package/src/storage/domains/traces/index.ts +0 -150
- package/src/storage/domains/utils.ts +0 -272
- package/src/storage/domains/workflows/index.ts +0 -421
- package/src/storage/index.test.ts +0 -16
- package/src/storage/index.ts +0 -499
- package/src/vector/filter.test.ts +0 -906
- package/src/vector/filter.ts +0 -131
- package/src/vector/index.test.ts +0 -1693
- package/src/vector/index.ts +0 -515
- package/src/vector/prompt.ts +0 -101
- package/src/vector/sql-builder.ts +0 -548
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
- package/tsup.config.ts +0 -17
- package/vitest.config.ts +0 -11
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
2
|
-
import { AI_SPAN_SCHEMA, ObservabilityStorage, TABLE_AI_SPANS } from '@mastra/core/storage';
|
|
3
|
-
import type { AISpanRecord, AITraceRecord, AITracesPaginatedArg, PaginationInfo } from '@mastra/core/storage';
|
|
4
|
-
import type { StoreOperationsLibSQL } from '../operations';
|
|
5
|
-
import { buildDateRangeFilter, prepareWhereClause, transformFromSqlRow } from '../utils';
|
|
6
|
-
|
|
7
|
-
export class ObservabilityLibSQL extends ObservabilityStorage {
|
|
8
|
-
private operations: StoreOperationsLibSQL;
|
|
9
|
-
constructor({ operations }: { operations: StoreOperationsLibSQL }) {
|
|
10
|
-
super();
|
|
11
|
-
this.operations = operations;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async createAISpan(span: AISpanRecord): Promise<void> {
|
|
15
|
-
try {
|
|
16
|
-
return this.operations.insert({ tableName: TABLE_AI_SPANS, record: span });
|
|
17
|
-
} catch (error) {
|
|
18
|
-
throw new MastraError(
|
|
19
|
-
{
|
|
20
|
-
id: 'LIBSQL_STORE_CREATE_AI_SPAN_FAILED',
|
|
21
|
-
domain: ErrorDomain.STORAGE,
|
|
22
|
-
category: ErrorCategory.USER,
|
|
23
|
-
details: {
|
|
24
|
-
spanId: span.spanId,
|
|
25
|
-
traceId: span.traceId,
|
|
26
|
-
spanType: span.spanType,
|
|
27
|
-
spanName: span.name,
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
error,
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async getAITrace(traceId: string): Promise<AITraceRecord | null> {
|
|
36
|
-
try {
|
|
37
|
-
const spans = await this.operations.loadMany<AISpanRecord>({
|
|
38
|
-
tableName: TABLE_AI_SPANS,
|
|
39
|
-
whereClause: { sql: ' WHERE traceId = ?', args: [traceId] },
|
|
40
|
-
orderBy: 'startedAt DESC',
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
if (!spans || spans.length === 0) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
traceId,
|
|
49
|
-
spans: spans.map(span => transformFromSqlRow<AISpanRecord>({ tableName: TABLE_AI_SPANS, sqlRow: span })),
|
|
50
|
-
};
|
|
51
|
-
} catch (error) {
|
|
52
|
-
throw new MastraError(
|
|
53
|
-
{
|
|
54
|
-
id: 'LIBSQL_STORE_GET_AI_TRACE_FAILED',
|
|
55
|
-
domain: ErrorDomain.STORAGE,
|
|
56
|
-
category: ErrorCategory.USER,
|
|
57
|
-
details: {
|
|
58
|
-
traceId,
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
error,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async updateAISpan({
|
|
67
|
-
spanId,
|
|
68
|
-
traceId,
|
|
69
|
-
updates,
|
|
70
|
-
}: {
|
|
71
|
-
spanId: string;
|
|
72
|
-
traceId: string;
|
|
73
|
-
updates: Partial<Omit<AISpanRecord, 'spanId' | 'traceId'>>;
|
|
74
|
-
}): Promise<void> {
|
|
75
|
-
try {
|
|
76
|
-
await this.operations.update({
|
|
77
|
-
tableName: TABLE_AI_SPANS,
|
|
78
|
-
keys: { spanId, traceId },
|
|
79
|
-
data: { ...updates, updatedAt: new Date().toISOString() },
|
|
80
|
-
});
|
|
81
|
-
} catch (error) {
|
|
82
|
-
throw new MastraError(
|
|
83
|
-
{
|
|
84
|
-
id: 'LIBSQL_STORE_UPDATE_AI_SPAN_FAILED',
|
|
85
|
-
domain: ErrorDomain.STORAGE,
|
|
86
|
-
category: ErrorCategory.USER,
|
|
87
|
-
details: {
|
|
88
|
-
spanId,
|
|
89
|
-
traceId,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
error,
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async getAITracesPaginated({
|
|
98
|
-
filters,
|
|
99
|
-
pagination,
|
|
100
|
-
}: AITracesPaginatedArg): Promise<{ pagination: PaginationInfo; spans: AISpanRecord[] }> {
|
|
101
|
-
const page = pagination?.page ?? 0;
|
|
102
|
-
const perPage = pagination?.perPage ?? 10;
|
|
103
|
-
|
|
104
|
-
const filtersWithDateRange: Record<string, any> = {
|
|
105
|
-
...filters,
|
|
106
|
-
...buildDateRangeFilter(pagination?.dateRange, 'startedAt'),
|
|
107
|
-
};
|
|
108
|
-
const whereClause = prepareWhereClause(filtersWithDateRange, AI_SPAN_SCHEMA);
|
|
109
|
-
const orderBy = 'startedAt DESC';
|
|
110
|
-
|
|
111
|
-
let count = 0;
|
|
112
|
-
try {
|
|
113
|
-
count = await this.operations.loadTotalCount({
|
|
114
|
-
tableName: TABLE_AI_SPANS,
|
|
115
|
-
whereClause: { sql: whereClause.sql, args: whereClause.args },
|
|
116
|
-
});
|
|
117
|
-
} catch (error) {
|
|
118
|
-
throw new MastraError(
|
|
119
|
-
{
|
|
120
|
-
id: 'LIBSQL_STORE_GET_AI_TRACES_PAGINATED_COUNT_FAILED',
|
|
121
|
-
domain: ErrorDomain.STORAGE,
|
|
122
|
-
category: ErrorCategory.USER,
|
|
123
|
-
},
|
|
124
|
-
error,
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (count === 0) {
|
|
129
|
-
return {
|
|
130
|
-
pagination: {
|
|
131
|
-
total: 0,
|
|
132
|
-
page,
|
|
133
|
-
perPage,
|
|
134
|
-
hasMore: false,
|
|
135
|
-
},
|
|
136
|
-
spans: [],
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
try {
|
|
141
|
-
const spans = await this.operations.loadMany<AISpanRecord>({
|
|
142
|
-
tableName: TABLE_AI_SPANS,
|
|
143
|
-
whereClause,
|
|
144
|
-
orderBy,
|
|
145
|
-
offset: page * perPage,
|
|
146
|
-
limit: perPage,
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
return {
|
|
150
|
-
pagination: {
|
|
151
|
-
total: count,
|
|
152
|
-
page,
|
|
153
|
-
perPage,
|
|
154
|
-
hasMore: spans.length === perPage,
|
|
155
|
-
},
|
|
156
|
-
spans: spans.map(span => transformFromSqlRow<AISpanRecord>({ tableName: TABLE_AI_SPANS, sqlRow: span })),
|
|
157
|
-
};
|
|
158
|
-
} catch (error) {
|
|
159
|
-
throw new MastraError(
|
|
160
|
-
{
|
|
161
|
-
id: 'LIBSQL_STORE_GET_AI_TRACES_PAGINATED_FAILED',
|
|
162
|
-
domain: ErrorDomain.STORAGE,
|
|
163
|
-
category: ErrorCategory.USER,
|
|
164
|
-
},
|
|
165
|
-
error,
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async batchCreateAISpans(args: { records: AISpanRecord[] }): Promise<void> {
|
|
171
|
-
try {
|
|
172
|
-
return this.operations.batchInsert({
|
|
173
|
-
tableName: TABLE_AI_SPANS,
|
|
174
|
-
records: args.records.map(record => ({
|
|
175
|
-
...record,
|
|
176
|
-
createdAt: new Date().toISOString(),
|
|
177
|
-
updatedAt: new Date().toISOString(),
|
|
178
|
-
})),
|
|
179
|
-
});
|
|
180
|
-
} catch (error) {
|
|
181
|
-
throw new MastraError(
|
|
182
|
-
{
|
|
183
|
-
id: 'LIBSQL_STORE_BATCH_CREATE_AI_SPANS_FAILED',
|
|
184
|
-
domain: ErrorDomain.STORAGE,
|
|
185
|
-
category: ErrorCategory.USER,
|
|
186
|
-
},
|
|
187
|
-
error,
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
async batchUpdateAISpans(args: {
|
|
193
|
-
records: {
|
|
194
|
-
traceId: string;
|
|
195
|
-
spanId: string;
|
|
196
|
-
updates: Partial<Omit<AISpanRecord, 'spanId' | 'traceId'>>;
|
|
197
|
-
}[];
|
|
198
|
-
}): Promise<void> {
|
|
199
|
-
try {
|
|
200
|
-
return this.operations.batchUpdate({
|
|
201
|
-
tableName: TABLE_AI_SPANS,
|
|
202
|
-
updates: args.records.map(record => ({
|
|
203
|
-
keys: { spanId: record.spanId, traceId: record.traceId },
|
|
204
|
-
data: { ...record.updates, updatedAt: new Date().toISOString() },
|
|
205
|
-
})),
|
|
206
|
-
});
|
|
207
|
-
} catch (error) {
|
|
208
|
-
throw new MastraError(
|
|
209
|
-
{
|
|
210
|
-
id: 'LIBSQL_STORE_BATCH_UPDATE_AI_SPANS_FAILED',
|
|
211
|
-
domain: ErrorDomain.STORAGE,
|
|
212
|
-
category: ErrorCategory.USER,
|
|
213
|
-
},
|
|
214
|
-
error,
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
async batchDeleteAITraces(args: { traceIds: string[] }): Promise<void> {
|
|
220
|
-
try {
|
|
221
|
-
const keys = args.traceIds.map(traceId => ({ traceId }));
|
|
222
|
-
return this.operations.batchDelete({
|
|
223
|
-
tableName: TABLE_AI_SPANS,
|
|
224
|
-
keys,
|
|
225
|
-
});
|
|
226
|
-
} catch (error) {
|
|
227
|
-
throw new MastraError(
|
|
228
|
-
{
|
|
229
|
-
id: 'LIBSQL_STORE_BATCH_DELETE_AI_TRACES_FAILED',
|
|
230
|
-
domain: ErrorDomain.STORAGE,
|
|
231
|
-
category: ErrorCategory.USER,
|
|
232
|
-
},
|
|
233
|
-
error,
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|