@mastra/mssql 1.0.0-beta.4 → 1.0.0-beta.6
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 +29 -0
- package/dist/index.cjs +76 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +75 -36
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +2 -2
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +4 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +6 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
|
|
2
2
|
import { MastraStorage, createStorageErrorId, StoreOperations, TABLE_WORKFLOW_SNAPSHOT, TABLE_SCHEMAS, TABLE_THREADS, TABLE_MESSAGES, TABLE_TRACES, TABLE_SCORERS, TABLE_SPANS, ScoresStorage, normalizePerPage, calculatePagination, WorkflowsStorage, MemoryStorage, TABLE_RESOURCES, ObservabilityStorage, transformScoreRow as transformScoreRow$1 } from '@mastra/core/storage';
|
|
3
|
-
import
|
|
3
|
+
import sql3 from 'mssql';
|
|
4
4
|
import { MessageList } from '@mastra/core/agent';
|
|
5
5
|
import { parseSqlIdentifier } from '@mastra/core/utils';
|
|
6
6
|
import { randomUUID } from 'crypto';
|
|
@@ -227,7 +227,7 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
227
227
|
dataRequest.input("resourceId", resourceId);
|
|
228
228
|
dataRequest.input("offset", offset);
|
|
229
229
|
if (limitValue > 2147483647) {
|
|
230
|
-
dataRequest.input("perPage",
|
|
230
|
+
dataRequest.input("perPage", sql3.BigInt, limitValue);
|
|
231
231
|
} else {
|
|
232
232
|
dataRequest.input("perPage", limitValue);
|
|
233
233
|
}
|
|
@@ -291,12 +291,12 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
291
291
|
req.input("title", thread.title);
|
|
292
292
|
const metadata = thread.metadata ? JSON.stringify(thread.metadata) : null;
|
|
293
293
|
if (metadata === null) {
|
|
294
|
-
req.input("metadata",
|
|
294
|
+
req.input("metadata", sql3.NVarChar, null);
|
|
295
295
|
} else {
|
|
296
296
|
req.input("metadata", metadata);
|
|
297
297
|
}
|
|
298
|
-
req.input("createdAt",
|
|
299
|
-
req.input("updatedAt",
|
|
298
|
+
req.input("createdAt", sql3.DateTime2, thread.createdAt);
|
|
299
|
+
req.input("updatedAt", sql3.DateTime2, thread.updatedAt);
|
|
300
300
|
await req.query(mergeSql);
|
|
301
301
|
return thread;
|
|
302
302
|
} catch (error) {
|
|
@@ -592,7 +592,7 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
592
592
|
return result2.recordset || [];
|
|
593
593
|
}
|
|
594
594
|
request.input("offset", offset);
|
|
595
|
-
request.input("limit", perPage > 2147483647 ?
|
|
595
|
+
request.input("limit", perPage > 2147483647 ? sql3.BigInt : sql3.Int, perPage);
|
|
596
596
|
const result = await request.query(
|
|
597
597
|
`${baseQuery}${actualWhereClause} ${orderByStatement} OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`
|
|
598
598
|
);
|
|
@@ -717,7 +717,7 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
717
717
|
"content",
|
|
718
718
|
typeof message.content === "string" ? message.content : JSON.stringify(message.content)
|
|
719
719
|
);
|
|
720
|
-
request.input("createdAt",
|
|
720
|
+
request.input("createdAt", sql3.DateTime2, message.createdAt);
|
|
721
721
|
request.input("role", message.role);
|
|
722
722
|
request.input("type", message.type || "v2");
|
|
723
723
|
request.input("resourceId", message.resourceId);
|
|
@@ -736,7 +736,7 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
736
736
|
await request.query(mergeSql);
|
|
737
737
|
}
|
|
738
738
|
const threadReq = transaction.request();
|
|
739
|
-
threadReq.input("updatedAt",
|
|
739
|
+
threadReq.input("updatedAt", sql3.DateTime2, /* @__PURE__ */ new Date());
|
|
740
740
|
threadReq.input("id", threadId);
|
|
741
741
|
await threadReq.query(`UPDATE ${tableThreads} SET [updatedAt] = @updatedAt WHERE id = @id`);
|
|
742
742
|
await transaction.commit();
|
|
@@ -1437,7 +1437,7 @@ var StoreOperationsMSSQL = class extends StoreOperations {
|
|
|
1437
1437
|
const value = record[col];
|
|
1438
1438
|
const preparedValue = this.prepareValue(value, col, tableName);
|
|
1439
1439
|
if (preparedValue instanceof Date) {
|
|
1440
|
-
request.input(`param${i}`,
|
|
1440
|
+
request.input(`param${i}`, sql3.DateTime2, preparedValue);
|
|
1441
1441
|
} else if (preparedValue === null || preparedValue === void 0) {
|
|
1442
1442
|
request.input(`param${i}`, this.getMssqlType(tableName, col), null);
|
|
1443
1443
|
} else {
|
|
@@ -1775,23 +1775,23 @@ ${columns}
|
|
|
1775
1775
|
const col = TABLE_SCHEMAS[tableName]?.[columnName];
|
|
1776
1776
|
switch (col?.type) {
|
|
1777
1777
|
case "text":
|
|
1778
|
-
return
|
|
1778
|
+
return sql3.NVarChar;
|
|
1779
1779
|
case "timestamp":
|
|
1780
|
-
return
|
|
1780
|
+
return sql3.DateTime2;
|
|
1781
1781
|
case "uuid":
|
|
1782
|
-
return
|
|
1782
|
+
return sql3.UniqueIdentifier;
|
|
1783
1783
|
case "jsonb":
|
|
1784
|
-
return
|
|
1784
|
+
return sql3.NVarChar;
|
|
1785
1785
|
case "integer":
|
|
1786
|
-
return
|
|
1786
|
+
return sql3.Int;
|
|
1787
1787
|
case "bigint":
|
|
1788
|
-
return
|
|
1788
|
+
return sql3.BigInt;
|
|
1789
1789
|
case "float":
|
|
1790
|
-
return
|
|
1790
|
+
return sql3.Float;
|
|
1791
1791
|
case "boolean":
|
|
1792
|
-
return
|
|
1792
|
+
return sql3.Bit;
|
|
1793
1793
|
default:
|
|
1794
|
-
return
|
|
1794
|
+
return sql3.NVarChar;
|
|
1795
1795
|
}
|
|
1796
1796
|
}
|
|
1797
1797
|
/**
|
|
@@ -2340,13 +2340,21 @@ var ScoresMSSQL = class extends ScoresStorage {
|
|
|
2340
2340
|
{
|
|
2341
2341
|
id: createStorageErrorId("MSSQL", "SAVE_SCORE", "VALIDATION_FAILED"),
|
|
2342
2342
|
domain: ErrorDomain.STORAGE,
|
|
2343
|
-
category: ErrorCategory.
|
|
2343
|
+
category: ErrorCategory.USER,
|
|
2344
|
+
details: {
|
|
2345
|
+
scorer: score.scorer?.id ?? "unknown",
|
|
2346
|
+
entityId: score.entityId ?? "unknown",
|
|
2347
|
+
entityType: score.entityType ?? "unknown",
|
|
2348
|
+
traceId: score.traceId ?? "",
|
|
2349
|
+
spanId: score.spanId ?? ""
|
|
2350
|
+
}
|
|
2344
2351
|
},
|
|
2345
2352
|
error
|
|
2346
2353
|
);
|
|
2347
2354
|
}
|
|
2348
2355
|
try {
|
|
2349
2356
|
const scoreId = randomUUID();
|
|
2357
|
+
const now = /* @__PURE__ */ new Date();
|
|
2350
2358
|
const {
|
|
2351
2359
|
scorer,
|
|
2352
2360
|
preprocessStepResult,
|
|
@@ -2373,12 +2381,11 @@ var ScoresMSSQL = class extends ScoresStorage {
|
|
|
2373
2381
|
requestContext: requestContext || null,
|
|
2374
2382
|
entity: entity || null,
|
|
2375
2383
|
scorer: scorer || null,
|
|
2376
|
-
createdAt:
|
|
2377
|
-
updatedAt:
|
|
2384
|
+
createdAt: now.toISOString(),
|
|
2385
|
+
updatedAt: now.toISOString()
|
|
2378
2386
|
}
|
|
2379
2387
|
});
|
|
2380
|
-
|
|
2381
|
-
return { score: scoreFromDb };
|
|
2388
|
+
return { score: { ...validatedScore, id: scoreId, createdAt: now, updatedAt: now } };
|
|
2382
2389
|
} catch (error) {
|
|
2383
2390
|
throw new MastraError(
|
|
2384
2391
|
{
|
|
@@ -2684,7 +2691,7 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2684
2691
|
const transaction = this.pool.transaction();
|
|
2685
2692
|
try {
|
|
2686
2693
|
await transaction.begin();
|
|
2687
|
-
const selectRequest = new
|
|
2694
|
+
const selectRequest = new sql3.Request(transaction);
|
|
2688
2695
|
selectRequest.input("workflow_name", workflowName);
|
|
2689
2696
|
selectRequest.input("run_id", runId);
|
|
2690
2697
|
const existingSnapshotResult = await selectRequest.query(
|
|
@@ -2712,12 +2719,12 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2712
2719
|
}
|
|
2713
2720
|
snapshot.context[stepId] = result;
|
|
2714
2721
|
snapshot.requestContext = { ...snapshot.requestContext, ...requestContext };
|
|
2715
|
-
const upsertReq = new
|
|
2722
|
+
const upsertReq = new sql3.Request(transaction);
|
|
2716
2723
|
upsertReq.input("workflow_name", workflowName);
|
|
2717
2724
|
upsertReq.input("run_id", runId);
|
|
2718
2725
|
upsertReq.input("snapshot", JSON.stringify(snapshot));
|
|
2719
|
-
upsertReq.input("createdAt",
|
|
2720
|
-
upsertReq.input("updatedAt",
|
|
2726
|
+
upsertReq.input("createdAt", sql3.DateTime2, /* @__PURE__ */ new Date());
|
|
2727
|
+
upsertReq.input("updatedAt", sql3.DateTime2, /* @__PURE__ */ new Date());
|
|
2721
2728
|
await upsertReq.query(
|
|
2722
2729
|
`MERGE ${table} AS target
|
|
2723
2730
|
USING (SELECT @workflow_name AS workflow_name, @run_id AS run_id) AS src
|
|
@@ -2757,7 +2764,7 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2757
2764
|
const transaction = this.pool.transaction();
|
|
2758
2765
|
try {
|
|
2759
2766
|
await transaction.begin();
|
|
2760
|
-
const selectRequest = new
|
|
2767
|
+
const selectRequest = new sql3.Request(transaction);
|
|
2761
2768
|
selectRequest.input("workflow_name", workflowName);
|
|
2762
2769
|
selectRequest.input("run_id", runId);
|
|
2763
2770
|
const existingSnapshotResult = await selectRequest.query(
|
|
@@ -2785,11 +2792,11 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2785
2792
|
);
|
|
2786
2793
|
}
|
|
2787
2794
|
const updatedSnapshot = { ...snapshot, ...opts };
|
|
2788
|
-
const updateRequest = new
|
|
2795
|
+
const updateRequest = new sql3.Request(transaction);
|
|
2789
2796
|
updateRequest.input("snapshot", JSON.stringify(updatedSnapshot));
|
|
2790
2797
|
updateRequest.input("workflow_name", workflowName);
|
|
2791
2798
|
updateRequest.input("run_id", runId);
|
|
2792
|
-
updateRequest.input("updatedAt",
|
|
2799
|
+
updateRequest.input("updatedAt", sql3.DateTime2, /* @__PURE__ */ new Date());
|
|
2793
2800
|
await updateRequest.query(
|
|
2794
2801
|
`UPDATE ${table} SET snapshot = @snapshot, [updatedAt] = @updatedAt WHERE workflow_name = @workflow_name AND run_id = @run_id`
|
|
2795
2802
|
);
|
|
@@ -2829,8 +2836,8 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2829
2836
|
request.input("run_id", runId);
|
|
2830
2837
|
request.input("resourceId", resourceId);
|
|
2831
2838
|
request.input("snapshot", JSON.stringify(snapshot));
|
|
2832
|
-
request.input("createdAt",
|
|
2833
|
-
request.input("updatedAt",
|
|
2839
|
+
request.input("createdAt", sql3.DateTime2, new Date(now));
|
|
2840
|
+
request.input("updatedAt", sql3.DateTime2, new Date(now));
|
|
2834
2841
|
const mergeSql = `MERGE INTO ${table} AS target
|
|
2835
2842
|
USING (SELECT @workflow_name AS workflow_name, @run_id AS run_id) AS src
|
|
2836
2843
|
ON target.workflow_name = src.workflow_name AND target.run_id = src.run_id
|
|
@@ -2927,6 +2934,35 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2927
2934
|
);
|
|
2928
2935
|
}
|
|
2929
2936
|
}
|
|
2937
|
+
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
2938
|
+
const table = getTableName({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName(this.schema) });
|
|
2939
|
+
const transaction = this.pool.transaction();
|
|
2940
|
+
try {
|
|
2941
|
+
await transaction.begin();
|
|
2942
|
+
const deleteRequest = new sql3.Request(transaction);
|
|
2943
|
+
deleteRequest.input("workflow_name", workflowName);
|
|
2944
|
+
deleteRequest.input("run_id", runId);
|
|
2945
|
+
await deleteRequest.query(`DELETE FROM ${table} WHERE workflow_name = @workflow_name AND run_id = @run_id`);
|
|
2946
|
+
await transaction.commit();
|
|
2947
|
+
} catch (error) {
|
|
2948
|
+
try {
|
|
2949
|
+
await transaction.rollback();
|
|
2950
|
+
} catch {
|
|
2951
|
+
}
|
|
2952
|
+
throw new MastraError(
|
|
2953
|
+
{
|
|
2954
|
+
id: createStorageErrorId("MSSQL", "DELETE_WORKFLOW_RUN_BY_ID", "FAILED"),
|
|
2955
|
+
domain: ErrorDomain.STORAGE,
|
|
2956
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
2957
|
+
details: {
|
|
2958
|
+
runId,
|
|
2959
|
+
workflowName
|
|
2960
|
+
}
|
|
2961
|
+
},
|
|
2962
|
+
error
|
|
2963
|
+
);
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2930
2966
|
async listWorkflowRuns({
|
|
2931
2967
|
workflowName,
|
|
2932
2968
|
fromDate,
|
|
@@ -2970,7 +3006,7 @@ var WorkflowsMSSQL = class extends WorkflowsStorage {
|
|
|
2970
3006
|
const request = this.pool.request();
|
|
2971
3007
|
Object.entries(paramMap).forEach(([key, value]) => {
|
|
2972
3008
|
if (value instanceof Date) {
|
|
2973
|
-
request.input(key,
|
|
3009
|
+
request.input(key, sql3.DateTime, value);
|
|
2974
3010
|
} else {
|
|
2975
3011
|
request.input(key, value);
|
|
2976
3012
|
}
|
|
@@ -3033,7 +3069,7 @@ var MSSQLStore = class extends MastraStorage {
|
|
|
3033
3069
|
}
|
|
3034
3070
|
}
|
|
3035
3071
|
this.schema = config.schemaName || "dbo";
|
|
3036
|
-
this.pool = "connectionString" in config ? new
|
|
3072
|
+
this.pool = "connectionString" in config ? new sql3.ConnectionPool(config.connectionString) : new sql3.ConnectionPool({
|
|
3037
3073
|
server: config.server,
|
|
3038
3074
|
database: config.database,
|
|
3039
3075
|
user: config.user,
|
|
@@ -3224,6 +3260,9 @@ var MSSQLStore = class extends MastraStorage {
|
|
|
3224
3260
|
}) {
|
|
3225
3261
|
return this.stores.workflows.getWorkflowRunById({ runId, workflowName });
|
|
3226
3262
|
}
|
|
3263
|
+
async deleteWorkflowRunById({ runId, workflowName }) {
|
|
3264
|
+
return this.stores.workflows.deleteWorkflowRunById({ runId, workflowName });
|
|
3265
|
+
}
|
|
3227
3266
|
async close() {
|
|
3228
3267
|
await this.pool.close();
|
|
3229
3268
|
}
|
|
@@ -3302,8 +3341,8 @@ var MSSQLStore = class extends MastraStorage {
|
|
|
3302
3341
|
source: _source
|
|
3303
3342
|
});
|
|
3304
3343
|
}
|
|
3305
|
-
async saveScore(
|
|
3306
|
-
return this.stores.scores.saveScore(
|
|
3344
|
+
async saveScore(score) {
|
|
3345
|
+
return this.stores.scores.saveScore(score);
|
|
3307
3346
|
}
|
|
3308
3347
|
async listScoresByRunId({
|
|
3309
3348
|
runId: _runId,
|