@mastra/mssql 1.2.0-alpha.0 → 1.2.1-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 +26 -0
- package/dist/docs/SKILL.md +2 -2
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-storage-mssql.md +3 -3
- package/dist/index.cjs +318 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +319 -5
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/background-tasks/index.d.ts +30 -0
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +2 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @mastra/mssql
|
|
2
2
|
|
|
3
|
+
## 1.2.1-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add `BackgroundTasksStorage` domain implementation so `@mastra/core` background task execution works with any storage adapter. ([#15307](https://github.com/mastra-ai/mastra/pull/15307))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`d63ffdb`](https://github.com/mastra-ai/mastra/commit/d63ffdbb2c11e76fe5ea45faab44bc15460f010c)]:
|
|
10
|
+
- @mastra/core@1.25.1-alpha.0
|
|
11
|
+
|
|
12
|
+
## 1.2.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- Added `requestContext` column to the spans table. Request context data from tracing is now persisted alongside other span data. ([#14020](https://github.com/mastra-ai/mastra/pull/14020))
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Added resilient column handling to insert and update operations. Unknown columns in records are now silently dropped instead of causing SQL errors, ensuring forward compatibility when newer domain packages add fields that haven't been migrated yet. ([#14021](https://github.com/mastra-ai/mastra/pull/14021))
|
|
21
|
+
|
|
22
|
+
For example, calling `db.insert({ tableName, record: { id: '1', title: 'Hello', futureField: 'value' } })` will silently ignore `futureField` if it doesn't exist in the database table, rather than throwing. The same applies to `update` — unknown fields in the data payload are dropped before building the SQL statement.
|
|
23
|
+
|
|
24
|
+
- Improved semantic recall performance for large message histories. Semantic recall no longer loads entire threads when only the recalled messages are needed, eliminating delays that previously scaled with total message count. (Fixes #11702) ([#14022](https://github.com/mastra-ai/mastra/pull/14022))
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [[`4f71b43`](https://github.com/mastra-ai/mastra/commit/4f71b436a4a6b8839842d8da47b57b84509af56c), [`a070277`](https://github.com/mastra-ai/mastra/commit/a07027766ce195ba74d0783116d894cbab25d44c), [`b628b91`](https://github.com/mastra-ai/mastra/commit/b628b9128b372c0f54214d902b07279f03443900), [`332c014`](https://github.com/mastra-ai/mastra/commit/332c014e076b81edf7fe45b58205882726415e90), [`6b63153`](https://github.com/mastra-ai/mastra/commit/6b63153878ea841c0f4ce632ba66bb33e57e9c1b), [`4246e34`](https://github.com/mastra-ai/mastra/commit/4246e34cec9c26636d0965942268e6d07c346671), [`b8837ee`](https://github.com/mastra-ai/mastra/commit/b8837ee77e2e84197609762bfabd8b3da326d30c), [`866cc2c`](https://github.com/mastra-ai/mastra/commit/866cc2cb1f0e3b314afab5194f69477fada745d1), [`5d950f7`](https://github.com/mastra-ai/mastra/commit/5d950f7bf426a215a1808f0abef7de5c8336ba1c), [`28c85b1`](https://github.com/mastra-ai/mastra/commit/28c85b184fc32b40f7f160483c982da6d388ecbd), [`e9a08fb`](https://github.com/mastra-ai/mastra/commit/e9a08fbef1ada7e50e961e2f54f55e8c10b4a45c), [`1d0a8a8`](https://github.com/mastra-ai/mastra/commit/1d0a8a8acf33203d5744fc429b090ad8598aa8ed), [`631ffd8`](https://github.com/mastra-ai/mastra/commit/631ffd82fed108648b448b28e6a90e38c5f53bf5), [`6bcbf8a`](https://github.com/mastra-ai/mastra/commit/6bcbf8a6774d5a53b21d61db8a45ce2593ca1616), [`aae2295`](https://github.com/mastra-ai/mastra/commit/aae2295838a2d329ad6640829e87934790ffe5b8), [`aa61f29`](https://github.com/mastra-ai/mastra/commit/aa61f29ff8095ce46a4ae16e46c4d8c79b2b685b), [`7ff3714`](https://github.com/mastra-ai/mastra/commit/7ff37148515439bb3be009a60e02c3e363299760), [`18c3a90`](https://github.com/mastra-ai/mastra/commit/18c3a90c9e48cf69500e308affeb8eba5860b2af), [`41d79a1`](https://github.com/mastra-ai/mastra/commit/41d79a14bd8cb6de1e2565fd0a04786bae2f211b), [`f35487b`](https://github.com/mastra-ai/mastra/commit/f35487bb2d46c636e22aa71d90025613ae38235a), [`6dc2192`](https://github.com/mastra-ai/mastra/commit/6dc21921aef0f0efab15cd0805fa3d18f277a76f), [`eeb3a3f`](https://github.com/mastra-ai/mastra/commit/eeb3a3f43aca10cf49479eed2a84b7d9ecea02ba), [`e673376`](https://github.com/mastra-ai/mastra/commit/e6733763ad1321aa7e5ae15096b9c2104f93b1f3), [`05f8d90`](https://github.com/mastra-ai/mastra/commit/05f8d9009290ce6aa03428b3add635268615db85), [`b2204c9`](https://github.com/mastra-ai/mastra/commit/b2204c98a42848bbfb6f0440f005dc2b6354f1cd), [`a1bf1e3`](https://github.com/mastra-ai/mastra/commit/a1bf1e385ed4c0ef6f11b56c5887442970d127f2), [`b6f647a`](https://github.com/mastra-ai/mastra/commit/b6f647ae2388e091f366581595feb957e37d5b40), [`0c57b8b`](https://github.com/mastra-ai/mastra/commit/0c57b8b0a69a97b5a4ae3f79be6c610f29f3cf7b), [`b081f27`](https://github.com/mastra-ai/mastra/commit/b081f272cf411716e1d6bd72ceac4bcee2657b19), [`4b8da97`](https://github.com/mastra-ai/mastra/commit/4b8da97a5ce306e97869df6c39535d9069e563db), [`0c09eac`](https://github.com/mastra-ai/mastra/commit/0c09eacb1926f64cfdc9ae5c6d63385cf8c9f72c), [`6b9b93d`](https://github.com/mastra-ai/mastra/commit/6b9b93d6f459d1ba6e36f163abf62a085ddb3d64), [`31b6067`](https://github.com/mastra-ai/mastra/commit/31b6067d0cc3ab10e1b29c36147f3b5266bc714a), [`797ac42`](https://github.com/mastra-ai/mastra/commit/797ac4276de231ad2d694d9aeca75980f6cd0419), [`0bc289e`](https://github.com/mastra-ai/mastra/commit/0bc289e2d476bf46c5b91c21969e8d0c6864691c), [`9b75a06`](https://github.com/mastra-ai/mastra/commit/9b75a06e53ebb0b950ba7c1e83a0142047185f46), [`4c3a1b1`](https://github.com/mastra-ai/mastra/commit/4c3a1b122ea083e003d71092f30f3b31680b01c0), [`256df35`](https://github.com/mastra-ai/mastra/commit/256df3571d62beb3ad4971faa432927cc140e603), [`85cc3b3`](https://github.com/mastra-ai/mastra/commit/85cc3b3b6f32ae4b083c26498f50d5b250ba944b), [`97ea28c`](https://github.com/mastra-ai/mastra/commit/97ea28c746e9e4147d56047bbb1c4a92417a3fec), [`d567299`](https://github.com/mastra-ai/mastra/commit/d567299cf81e02bd9d5221d4bc05967d6c224161), [`716ffe6`](https://github.com/mastra-ai/mastra/commit/716ffe68bed81f7c2690bc8581b9e140f7bf1c3d), [`8296332`](https://github.com/mastra-ai/mastra/commit/8296332de21c16e3dfc3d0b2d615720a6dc88f2f), [`4df2116`](https://github.com/mastra-ai/mastra/commit/4df211619dd922c047d396ca41cd7027c8c4c8e7), [`2219c1a`](https://github.com/mastra-ai/mastra/commit/2219c1acbd21da116da877f0036ffb985a9dd5a3), [`17c4145`](https://github.com/mastra-ai/mastra/commit/17c4145166099354545582335b5252bdfdfd908b)]:
|
|
27
|
+
- @mastra/core@1.11.0
|
|
28
|
+
|
|
3
29
|
## 1.2.0-alpha.0
|
|
4
30
|
|
|
5
31
|
### Minor Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-mssql
|
|
|
3
3
|
description: Documentation for @mastra/mssql. Use when working with @mastra/mssql APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/mssql"
|
|
6
|
-
version: "1.2.
|
|
6
|
+
version: "1.2.1-alpha.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -16,7 +16,7 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
16
16
|
|
|
17
17
|
### Reference
|
|
18
18
|
|
|
19
|
-
- [Reference: MSSQL
|
|
19
|
+
- [Reference: MSSQL storage](references/reference-storage-mssql.md) - Documentation for the MSSQL storage implementation in Mastra.
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# MSSQL
|
|
1
|
+
# MSSQL storage
|
|
2
2
|
|
|
3
3
|
The MSSQL storage implementation provides a production-ready storage solution using Microsoft SQL Server databases.
|
|
4
4
|
|
|
@@ -45,7 +45,7 @@ const storage = new MSSQLStore({
|
|
|
45
45
|
|
|
46
46
|
**schemaName** (`string`): The name of the schema you want the storage to use. Will use the default schema if not provided.
|
|
47
47
|
|
|
48
|
-
## Constructor
|
|
48
|
+
## Constructor examples
|
|
49
49
|
|
|
50
50
|
You can instantiate `MSSQLStore` in the following ways:
|
|
51
51
|
|
|
@@ -89,7 +89,7 @@ const store5 = new MSSQLStore({
|
|
|
89
89
|
})
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
## Additional
|
|
92
|
+
## Additional notes
|
|
93
93
|
|
|
94
94
|
### Schema Management
|
|
95
95
|
|
package/dist/index.cjs
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
var error = require('@mastra/core/error');
|
|
4
4
|
var storage = require('@mastra/core/storage');
|
|
5
5
|
var sql = require('mssql');
|
|
6
|
-
var agent = require('@mastra/core/agent');
|
|
7
6
|
var base = require('@mastra/core/base');
|
|
8
7
|
var utils = require('@mastra/core/utils');
|
|
8
|
+
var agent = require('@mastra/core/agent');
|
|
9
9
|
var crypto = require('crypto');
|
|
10
10
|
var evals = require('@mastra/core/evals');
|
|
11
11
|
|
|
@@ -1356,7 +1356,319 @@ function transformFromSqlRow({
|
|
|
1356
1356
|
return result;
|
|
1357
1357
|
}
|
|
1358
1358
|
|
|
1359
|
-
// src/storage/domains/
|
|
1359
|
+
// src/storage/domains/background-tasks/index.ts
|
|
1360
|
+
function serializeJson(v) {
|
|
1361
|
+
if (typeof v === "object" && v != null) return JSON.stringify(v);
|
|
1362
|
+
return v ?? null;
|
|
1363
|
+
}
|
|
1364
|
+
function rowToTask(row) {
|
|
1365
|
+
const parseJson = (val) => {
|
|
1366
|
+
if (val == null) return void 0;
|
|
1367
|
+
if (typeof val === "string") {
|
|
1368
|
+
try {
|
|
1369
|
+
return JSON.parse(val);
|
|
1370
|
+
} catch {
|
|
1371
|
+
return val;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
return val;
|
|
1375
|
+
};
|
|
1376
|
+
return {
|
|
1377
|
+
id: row.id,
|
|
1378
|
+
status: row.status,
|
|
1379
|
+
toolName: row.tool_name,
|
|
1380
|
+
toolCallId: row.tool_call_id,
|
|
1381
|
+
args: parseJson(row.args) ?? {},
|
|
1382
|
+
agentId: row.agent_id,
|
|
1383
|
+
threadId: row.thread_id ?? void 0,
|
|
1384
|
+
resourceId: row.resource_id ?? void 0,
|
|
1385
|
+
runId: row.run_id ?? "",
|
|
1386
|
+
result: parseJson(row.result),
|
|
1387
|
+
error: parseJson(row.error),
|
|
1388
|
+
retryCount: Number(row.retry_count),
|
|
1389
|
+
maxRetries: Number(row.max_retries),
|
|
1390
|
+
timeoutMs: Number(row.timeout_ms),
|
|
1391
|
+
createdAt: row.createdAt instanceof Date ? row.createdAt : new Date(row.createdAt),
|
|
1392
|
+
startedAt: row.startedAt ? row.startedAt instanceof Date ? row.startedAt : new Date(row.startedAt) : void 0,
|
|
1393
|
+
completedAt: row.completedAt ? row.completedAt instanceof Date ? row.completedAt : new Date(row.completedAt) : void 0
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
var BackgroundTasksMSSQL = class _BackgroundTasksMSSQL extends storage.BackgroundTasksStorage {
|
|
1397
|
+
pool;
|
|
1398
|
+
db;
|
|
1399
|
+
schema;
|
|
1400
|
+
needsConnect;
|
|
1401
|
+
skipDefaultIndexes;
|
|
1402
|
+
indexes;
|
|
1403
|
+
static MANAGED_TABLES = [storage.TABLE_BACKGROUND_TASKS];
|
|
1404
|
+
constructor(config) {
|
|
1405
|
+
super();
|
|
1406
|
+
const { pool, schemaName, skipDefaultIndexes, indexes, needsConnect } = resolveMssqlConfig(config);
|
|
1407
|
+
this.pool = pool;
|
|
1408
|
+
this.schema = schemaName;
|
|
1409
|
+
this.db = new MssqlDB({ pool, schemaName, skipDefaultIndexes });
|
|
1410
|
+
this.needsConnect = needsConnect;
|
|
1411
|
+
this.skipDefaultIndexes = skipDefaultIndexes;
|
|
1412
|
+
this.indexes = indexes?.filter(
|
|
1413
|
+
(idx) => _BackgroundTasksMSSQL.MANAGED_TABLES.includes(idx.table)
|
|
1414
|
+
);
|
|
1415
|
+
}
|
|
1416
|
+
async init() {
|
|
1417
|
+
if (this.needsConnect) {
|
|
1418
|
+
await this.pool.connect();
|
|
1419
|
+
this.needsConnect = false;
|
|
1420
|
+
}
|
|
1421
|
+
await this.db.createTable({
|
|
1422
|
+
tableName: storage.TABLE_BACKGROUND_TASKS,
|
|
1423
|
+
schema: storage.TABLE_SCHEMAS[storage.TABLE_BACKGROUND_TASKS]
|
|
1424
|
+
});
|
|
1425
|
+
await this.createDefaultIndexes();
|
|
1426
|
+
await this.createCustomIndexes();
|
|
1427
|
+
}
|
|
1428
|
+
getDefaultIndexDefinitions() {
|
|
1429
|
+
const schemaPrefix = this.schema ? `${this.schema}_` : "";
|
|
1430
|
+
return [
|
|
1431
|
+
{
|
|
1432
|
+
name: `${schemaPrefix}mastra_bg_tasks_status_created_at_idx`,
|
|
1433
|
+
table: storage.TABLE_BACKGROUND_TASKS,
|
|
1434
|
+
columns: ["status", "createdAt"]
|
|
1435
|
+
},
|
|
1436
|
+
{
|
|
1437
|
+
name: `${schemaPrefix}mastra_bg_tasks_agent_status_idx`,
|
|
1438
|
+
table: storage.TABLE_BACKGROUND_TASKS,
|
|
1439
|
+
columns: ["agent_id", "status"]
|
|
1440
|
+
},
|
|
1441
|
+
{
|
|
1442
|
+
name: `${schemaPrefix}mastra_bg_tasks_thread_idx`,
|
|
1443
|
+
table: storage.TABLE_BACKGROUND_TASKS,
|
|
1444
|
+
columns: ["thread_id", "createdAt"]
|
|
1445
|
+
},
|
|
1446
|
+
{
|
|
1447
|
+
name: `${schemaPrefix}mastra_bg_tasks_tool_call_idx`,
|
|
1448
|
+
table: storage.TABLE_BACKGROUND_TASKS,
|
|
1449
|
+
columns: ["tool_call_id"]
|
|
1450
|
+
}
|
|
1451
|
+
];
|
|
1452
|
+
}
|
|
1453
|
+
async createDefaultIndexes() {
|
|
1454
|
+
if (this.skipDefaultIndexes) return;
|
|
1455
|
+
for (const indexDef of this.getDefaultIndexDefinitions()) {
|
|
1456
|
+
try {
|
|
1457
|
+
await this.db.createIndex(indexDef);
|
|
1458
|
+
} catch (error) {
|
|
1459
|
+
this.logger?.warn?.(`Failed to create index ${indexDef.name}:`, error);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
async createCustomIndexes() {
|
|
1464
|
+
if (!this.indexes || this.indexes.length === 0) return;
|
|
1465
|
+
for (const indexDef of this.indexes) {
|
|
1466
|
+
try {
|
|
1467
|
+
await this.db.createIndex(indexDef);
|
|
1468
|
+
} catch (error) {
|
|
1469
|
+
this.logger?.warn?.(`Failed to create custom index ${indexDef.name}:`, error);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
async dangerouslyClearAll() {
|
|
1474
|
+
await this.db.clearTable({ tableName: storage.TABLE_BACKGROUND_TASKS });
|
|
1475
|
+
}
|
|
1476
|
+
tableName() {
|
|
1477
|
+
return getTableName2({ indexName: storage.TABLE_BACKGROUND_TASKS, schemaName: getSchemaName2(this.schema) });
|
|
1478
|
+
}
|
|
1479
|
+
async createTask(task) {
|
|
1480
|
+
await this.db.insert({
|
|
1481
|
+
tableName: storage.TABLE_BACKGROUND_TASKS,
|
|
1482
|
+
record: {
|
|
1483
|
+
id: task.id,
|
|
1484
|
+
tool_call_id: task.toolCallId,
|
|
1485
|
+
tool_name: task.toolName,
|
|
1486
|
+
agent_id: task.agentId,
|
|
1487
|
+
thread_id: task.threadId ?? null,
|
|
1488
|
+
resource_id: task.resourceId ?? null,
|
|
1489
|
+
run_id: task.runId,
|
|
1490
|
+
status: task.status,
|
|
1491
|
+
args: serializeJson(task.args),
|
|
1492
|
+
result: serializeJson(task.result),
|
|
1493
|
+
error: serializeJson(task.error),
|
|
1494
|
+
retry_count: task.retryCount,
|
|
1495
|
+
max_retries: task.maxRetries,
|
|
1496
|
+
timeout_ms: task.timeoutMs,
|
|
1497
|
+
createdAt: task.createdAt.toISOString(),
|
|
1498
|
+
startedAt: task.startedAt?.toISOString() ?? null,
|
|
1499
|
+
completedAt: task.completedAt?.toISOString() ?? null
|
|
1500
|
+
}
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
async updateTask(taskId, update) {
|
|
1504
|
+
const setClauses = [];
|
|
1505
|
+
const params = {};
|
|
1506
|
+
let idx = 1;
|
|
1507
|
+
if ("status" in update) {
|
|
1508
|
+
setClauses.push(`[status] = @p${idx}`);
|
|
1509
|
+
params[`p${idx++}`] = update.status;
|
|
1510
|
+
}
|
|
1511
|
+
if ("result" in update) {
|
|
1512
|
+
setClauses.push(`[result] = @p${idx}`);
|
|
1513
|
+
params[`p${idx++}`] = serializeJson(update.result);
|
|
1514
|
+
}
|
|
1515
|
+
if ("error" in update) {
|
|
1516
|
+
setClauses.push(`[error] = @p${idx}`);
|
|
1517
|
+
params[`p${idx++}`] = serializeJson(update.error);
|
|
1518
|
+
}
|
|
1519
|
+
if ("retryCount" in update) {
|
|
1520
|
+
setClauses.push(`[retry_count] = @p${idx}`);
|
|
1521
|
+
params[`p${idx++}`] = update.retryCount;
|
|
1522
|
+
}
|
|
1523
|
+
if ("startedAt" in update) {
|
|
1524
|
+
setClauses.push(`[startedAt] = @p${idx}`);
|
|
1525
|
+
params[`p${idx++}`] = update.startedAt?.toISOString() ?? null;
|
|
1526
|
+
}
|
|
1527
|
+
if ("completedAt" in update) {
|
|
1528
|
+
setClauses.push(`[completedAt] = @p${idx}`);
|
|
1529
|
+
params[`p${idx++}`] = update.completedAt?.toISOString() ?? null;
|
|
1530
|
+
}
|
|
1531
|
+
if (setClauses.length === 0) return;
|
|
1532
|
+
setClauses.push(`[id] = [id]`);
|
|
1533
|
+
params[`p${idx}`] = taskId;
|
|
1534
|
+
const request = this.pool.request();
|
|
1535
|
+
for (const [name, value] of Object.entries(params)) {
|
|
1536
|
+
request.input(name, value);
|
|
1537
|
+
}
|
|
1538
|
+
await request.query(`UPDATE ${this.tableName()} SET ${setClauses.join(", ")} WHERE [id] = @p${idx}`);
|
|
1539
|
+
}
|
|
1540
|
+
async getTask(taskId) {
|
|
1541
|
+
const request = this.pool.request();
|
|
1542
|
+
request.input("p1", taskId);
|
|
1543
|
+
const result = await request.query(`SELECT * FROM ${this.tableName()} WHERE [id] = @p1`);
|
|
1544
|
+
if (result.recordset.length === 0) return null;
|
|
1545
|
+
return rowToTask(result.recordset[0]);
|
|
1546
|
+
}
|
|
1547
|
+
async listTasks(filter) {
|
|
1548
|
+
const conditions = [];
|
|
1549
|
+
const params = {};
|
|
1550
|
+
let idx = 1;
|
|
1551
|
+
if (filter.status) {
|
|
1552
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
1553
|
+
const placeholders = statuses.map(() => {
|
|
1554
|
+
const name = `p${idx++}`;
|
|
1555
|
+
return `@${name}`;
|
|
1556
|
+
});
|
|
1557
|
+
statuses.forEach((s, i) => {
|
|
1558
|
+
params[`p${idx - statuses.length + i}`] = s;
|
|
1559
|
+
});
|
|
1560
|
+
conditions.push(`[status] IN (${placeholders.join(", ")})`);
|
|
1561
|
+
}
|
|
1562
|
+
if (filter.agentId) {
|
|
1563
|
+
params[`p${idx}`] = filter.agentId;
|
|
1564
|
+
conditions.push(`[agent_id] = @p${idx++}`);
|
|
1565
|
+
}
|
|
1566
|
+
if (filter.threadId) {
|
|
1567
|
+
params[`p${idx}`] = filter.threadId;
|
|
1568
|
+
conditions.push(`[thread_id] = @p${idx++}`);
|
|
1569
|
+
}
|
|
1570
|
+
if (filter.resourceId) {
|
|
1571
|
+
params[`p${idx}`] = filter.resourceId;
|
|
1572
|
+
conditions.push(`[resource_id] = @p${idx++}`);
|
|
1573
|
+
}
|
|
1574
|
+
if (filter.runId) {
|
|
1575
|
+
params[`p${idx}`] = filter.runId;
|
|
1576
|
+
conditions.push(`[run_id] = @p${idx++}`);
|
|
1577
|
+
}
|
|
1578
|
+
if (filter.toolName) {
|
|
1579
|
+
params[`p${idx}`] = filter.toolName;
|
|
1580
|
+
conditions.push(`[tool_name] = @p${idx++}`);
|
|
1581
|
+
}
|
|
1582
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "[startedAt]" : filter.dateFilterBy === "completedAt" ? "[completedAt]" : "[createdAt]";
|
|
1583
|
+
if (filter.fromDate) {
|
|
1584
|
+
params[`p${idx}`] = filter.fromDate.toISOString();
|
|
1585
|
+
conditions.push(`${dateCol} >= @p${idx++}`);
|
|
1586
|
+
}
|
|
1587
|
+
if (filter.toDate) {
|
|
1588
|
+
params[`p${idx}`] = filter.toDate.toISOString();
|
|
1589
|
+
conditions.push(`${dateCol} < @p${idx++}`);
|
|
1590
|
+
}
|
|
1591
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
1592
|
+
const countRequest = this.pool.request();
|
|
1593
|
+
for (const [name, value] of Object.entries(params)) {
|
|
1594
|
+
countRequest.input(name, value);
|
|
1595
|
+
}
|
|
1596
|
+
const countResult = await countRequest.query(`SELECT COUNT(*) as count FROM ${this.tableName()} ${where}`);
|
|
1597
|
+
const total = Number(countResult.recordset[0]?.count ?? 0);
|
|
1598
|
+
const orderCol = filter.orderBy === "startedAt" ? "[startedAt]" : filter.orderBy === "completedAt" ? "[completedAt]" : "[createdAt]";
|
|
1599
|
+
const direction = filter.orderDirection === "desc" ? "DESC" : "ASC";
|
|
1600
|
+
let sql5 = `SELECT * FROM ${this.tableName()} ${where} ORDER BY ${orderCol} ${direction}`;
|
|
1601
|
+
if (filter.perPage != null) {
|
|
1602
|
+
const offset = filter.page != null ? filter.page * filter.perPage : 0;
|
|
1603
|
+
params[`p${idx}`] = offset;
|
|
1604
|
+
params[`p${idx + 1}`] = filter.perPage;
|
|
1605
|
+
sql5 += ` OFFSET @p${idx} ROWS FETCH NEXT @p${idx + 1} ROWS ONLY`;
|
|
1606
|
+
idx += 2;
|
|
1607
|
+
}
|
|
1608
|
+
const request = this.pool.request();
|
|
1609
|
+
for (const [name, value] of Object.entries(params)) {
|
|
1610
|
+
request.input(name, value);
|
|
1611
|
+
}
|
|
1612
|
+
const result = await request.query(sql5);
|
|
1613
|
+
return { tasks: result.recordset.map(rowToTask), total };
|
|
1614
|
+
}
|
|
1615
|
+
async deleteTask(taskId) {
|
|
1616
|
+
const request = this.pool.request();
|
|
1617
|
+
request.input("p1", taskId);
|
|
1618
|
+
await request.query(`DELETE FROM ${this.tableName()} WHERE [id] = @p1`);
|
|
1619
|
+
}
|
|
1620
|
+
async deleteTasks(filter) {
|
|
1621
|
+
const conditions = [];
|
|
1622
|
+
const params = {};
|
|
1623
|
+
let idx = 1;
|
|
1624
|
+
if (filter.status) {
|
|
1625
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
1626
|
+
const placeholders = statuses.map(() => {
|
|
1627
|
+
const name = `p${idx++}`;
|
|
1628
|
+
return `@${name}`;
|
|
1629
|
+
});
|
|
1630
|
+
statuses.forEach((s, i) => {
|
|
1631
|
+
params[`p${idx - statuses.length + i}`] = s;
|
|
1632
|
+
});
|
|
1633
|
+
conditions.push(`[status] IN (${placeholders.join(", ")})`);
|
|
1634
|
+
}
|
|
1635
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "[startedAt]" : filter.dateFilterBy === "completedAt" ? "[completedAt]" : "[createdAt]";
|
|
1636
|
+
if (filter.fromDate) {
|
|
1637
|
+
params[`p${idx}`] = filter.fromDate.toISOString();
|
|
1638
|
+
conditions.push(`${dateCol} >= @p${idx++}`);
|
|
1639
|
+
}
|
|
1640
|
+
if (filter.toDate) {
|
|
1641
|
+
params[`p${idx}`] = filter.toDate.toISOString();
|
|
1642
|
+
conditions.push(`${dateCol} < @p${idx++}`);
|
|
1643
|
+
}
|
|
1644
|
+
if (filter.agentId) {
|
|
1645
|
+
params[`p${idx}`] = filter.agentId;
|
|
1646
|
+
conditions.push(`[agent_id] = @p${idx++}`);
|
|
1647
|
+
}
|
|
1648
|
+
if (filter.runId) {
|
|
1649
|
+
params[`p${idx}`] = filter.runId;
|
|
1650
|
+
conditions.push(`[run_id] = @p${idx++}`);
|
|
1651
|
+
}
|
|
1652
|
+
if (conditions.length === 0) return;
|
|
1653
|
+
const request = this.pool.request();
|
|
1654
|
+
for (const [name, value] of Object.entries(params)) {
|
|
1655
|
+
request.input(name, value);
|
|
1656
|
+
}
|
|
1657
|
+
await request.query(`DELETE FROM ${this.tableName()} WHERE ${conditions.join(" AND ")}`);
|
|
1658
|
+
}
|
|
1659
|
+
async getRunningCount() {
|
|
1660
|
+
const result = await this.pool.request().query(`SELECT COUNT(*) as count FROM ${this.tableName()} WHERE [status] = 'running'`);
|
|
1661
|
+
return Number(result.recordset[0]?.count ?? 0);
|
|
1662
|
+
}
|
|
1663
|
+
async getRunningCountByAgent(agentId) {
|
|
1664
|
+
const request = this.pool.request();
|
|
1665
|
+
request.input("p1", agentId);
|
|
1666
|
+
const result = await request.query(
|
|
1667
|
+
`SELECT COUNT(*) as count FROM ${this.tableName()} WHERE [status] = 'running' AND [agent_id] = @p1`
|
|
1668
|
+
);
|
|
1669
|
+
return Number(result.recordset[0]?.count ?? 0);
|
|
1670
|
+
}
|
|
1671
|
+
};
|
|
1360
1672
|
var MemoryMSSQL = class _MemoryMSSQL extends storage.MemoryStorage {
|
|
1361
1673
|
pool;
|
|
1362
1674
|
schema;
|
|
@@ -3994,11 +4306,13 @@ var MSSQLStore = class extends storage.MastraCompositeStore {
|
|
|
3994
4306
|
const workflows = new WorkflowsMSSQL(domainConfig);
|
|
3995
4307
|
const memory = new MemoryMSSQL(domainConfig);
|
|
3996
4308
|
const observability = new ObservabilityMSSQL(domainConfig);
|
|
4309
|
+
const backgroundTasks = new BackgroundTasksMSSQL(domainConfig);
|
|
3997
4310
|
this.stores = {
|
|
3998
4311
|
scores,
|
|
3999
4312
|
workflows,
|
|
4000
4313
|
memory,
|
|
4001
|
-
observability
|
|
4314
|
+
observability,
|
|
4315
|
+
backgroundTasks
|
|
4002
4316
|
};
|
|
4003
4317
|
} catch (e) {
|
|
4004
4318
|
throw new error.MastraError(
|
|
@@ -4051,6 +4365,7 @@ var MSSQLStore = class extends storage.MastraCompositeStore {
|
|
|
4051
4365
|
}
|
|
4052
4366
|
};
|
|
4053
4367
|
|
|
4368
|
+
exports.BackgroundTasksMSSQL = BackgroundTasksMSSQL;
|
|
4054
4369
|
exports.MSSQLStore = MSSQLStore;
|
|
4055
4370
|
exports.MemoryMSSQL = MemoryMSSQL;
|
|
4056
4371
|
exports.ObservabilityMSSQL = ObservabilityMSSQL;
|