@mastra/mysql 0.17.0 → 0.17.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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +4 -4
- package/dist/index.cjs +49 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +49 -2
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +8 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.17.0",
|
|
2
|
+
"version": "0.17.1-alpha.0",
|
|
3
3
|
"package": "@mastra/mysql",
|
|
4
4
|
"exports": {
|
|
5
5
|
"AgentsMySQL": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"MySQLStore": {
|
|
41
41
|
"types": "dist/storage/index.d.ts",
|
|
42
42
|
"implementation": "dist/index.js",
|
|
43
|
-
"line":
|
|
43
|
+
"line": 13573
|
|
44
44
|
},
|
|
45
45
|
"ObservabilityMySQL": {
|
|
46
46
|
"types": "dist/storage/domains/observability/index.d.ts",
|
|
@@ -75,12 +75,12 @@
|
|
|
75
75
|
"WorkflowsMySQL": {
|
|
76
76
|
"types": "dist/storage/domains/workflows/index.d.ts",
|
|
77
77
|
"implementation": "dist/index.js",
|
|
78
|
-
"line":
|
|
78
|
+
"line": 12414
|
|
79
79
|
},
|
|
80
80
|
"WorkspacesMySQL": {
|
|
81
81
|
"types": "dist/storage/domains/workspaces/index.d.ts",
|
|
82
82
|
"implementation": "dist/index.js",
|
|
83
|
-
"line":
|
|
83
|
+
"line": 12977
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
86
|
"modules": {}
|
package/dist/index.cjs
CHANGED
|
@@ -12371,6 +12371,8 @@ const OWNER_ID = quoteIdentifier("ownerId", "column name");
|
|
|
12371
12371
|
const LEASE_EXPIRES_AT = quoteIdentifier("leaseExpiresAt", "column name");
|
|
12372
12372
|
const UPDATED_AT = quoteIdentifier("updatedAt", "column name");
|
|
12373
12373
|
const RUN_OWNER_COLUMNS = `generation, ${OWNER_ID} AS ownerId, ${LEASE_EXPIRES_AT} AS leaseExpiresAt, ${DB_NOW_MS} AS nowMs`;
|
|
12374
|
+
/** Run ids per query in `getRunOwnerships`, keeping each prepared statement small. */
|
|
12375
|
+
const RUN_OWNERSHIP_BATCH_SIZE = 500;
|
|
12374
12376
|
function toRunOwnershipRecord(runId, row) {
|
|
12375
12377
|
const leaseExpiresAt = row.leaseExpiresAt === null ? null : Number(row.leaseExpiresAt);
|
|
12376
12378
|
return {
|
|
@@ -12385,6 +12387,21 @@ async function readRunOwner(q, runId) {
|
|
|
12385
12387
|
const [rows] = await q.execute(`SELECT ${RUN_OWNER_COLUMNS} FROM ${RUN_OWNERS_TABLE} WHERE ${RUN_ID} = ?`, [runId]);
|
|
12386
12388
|
return rows[0] ? toRunOwnershipRecord(runId, rows[0]) : null;
|
|
12387
12389
|
}
|
|
12390
|
+
const SUMMARY_WORKFLOW_ID_SQL = `JSON_EXTRACT(snapshot, '$.parentWorkflow.workflowId')`;
|
|
12391
|
+
const SUMMARY_RUN_ID_SQL = `JSON_EXTRACT(snapshot, '$.parentWorkflow.runId')`;
|
|
12392
|
+
/**
|
|
12393
|
+
* The summary snapshot `listWorkflowRuns({ summary: true })` returns: `status` and `timestamp`
|
|
12394
|
+
* when set, and `parentWorkflow` with only its `workflowId` and `runId` when both are non-empty
|
|
12395
|
+
* strings. Only these paths are read, so `context` is never sent. JSON_OBJECT() keeps a SQL NULL
|
|
12396
|
+
* as a JSON null, and merge-patching `{}` with it drops those keys. The snapshot column is JSON,
|
|
12397
|
+
* stored parsed, so each JSON_EXTRACT reads it without parsing it again.
|
|
12398
|
+
*/
|
|
12399
|
+
const SUMMARY_SNAPSHOT_SQL = `JSON_MERGE_PATCH('{}', JSON_OBJECT(
|
|
12400
|
+
'status', JSON_EXTRACT(snapshot, '$.status'),
|
|
12401
|
+
'timestamp', JSON_EXTRACT(snapshot, '$.timestamp'),
|
|
12402
|
+
'parentWorkflow', CASE WHEN JSON_TYPE(${SUMMARY_WORKFLOW_ID_SQL}) = 'STRING' AND JSON_TYPE(${SUMMARY_RUN_ID_SQL}) = 'STRING'
|
|
12403
|
+
AND JSON_UNQUOTE(${SUMMARY_WORKFLOW_ID_SQL}) <> '' AND JSON_UNQUOTE(${SUMMARY_RUN_ID_SQL}) <> ''
|
|
12404
|
+
THEN JSON_OBJECT('workflowId', ${SUMMARY_WORKFLOW_ID_SQL}, 'runId', ${SUMMARY_RUN_ID_SQL}) END))`;
|
|
12388
12405
|
function mapWorkflowRow(row) {
|
|
12389
12406
|
return {
|
|
12390
12407
|
workflowName: row.workflow_name,
|
|
@@ -12610,6 +12627,31 @@ var WorkflowsMySQL = class WorkflowsMySQL extends _mastra_core_storage.Workflows
|
|
|
12610
12627
|
throw this.#ownershipError("GET_RUN_OWNERSHIP", runId, error);
|
|
12611
12628
|
}
|
|
12612
12629
|
}
|
|
12630
|
+
/** Reads the records with one query per {@link RUN_OWNERSHIP_BATCH_SIZE} runs. */
|
|
12631
|
+
async getRunOwnerships({ runIds }) {
|
|
12632
|
+
const records = /* @__PURE__ */ new Map();
|
|
12633
|
+
const ids = [...new Set(runIds)];
|
|
12634
|
+
try {
|
|
12635
|
+
for (let start = 0; start < ids.length; start += RUN_OWNERSHIP_BATCH_SIZE) {
|
|
12636
|
+
const chunk = ids.slice(start, start + RUN_OWNERSHIP_BATCH_SIZE);
|
|
12637
|
+
const requested = chunk.map((_, i) => i === 0 ? "SELECT ? AS reqId" : "SELECT ?").join(" UNION ALL ");
|
|
12638
|
+
const [rows] = await this.pool.execute(`SELECT j.reqId, ${RUN_OWNER_COLUMNS} FROM (${requested}) j
|
|
12639
|
+
JOIN ${RUN_OWNERS_TABLE} o ON o.${RUN_ID} = j.reqId`, chunk);
|
|
12640
|
+
for (const row of rows) {
|
|
12641
|
+
const runId = String(row.reqId);
|
|
12642
|
+
records.set(runId, toRunOwnershipRecord(runId, row));
|
|
12643
|
+
}
|
|
12644
|
+
}
|
|
12645
|
+
return records;
|
|
12646
|
+
} catch (error) {
|
|
12647
|
+
throw new _mastra_core_error.MastraError({
|
|
12648
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("MYSQL", "GET_RUN_OWNERSHIPS", "FAILED"),
|
|
12649
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
12650
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
12651
|
+
details: { runCount: ids.length }
|
|
12652
|
+
}, error);
|
|
12653
|
+
}
|
|
12654
|
+
}
|
|
12613
12655
|
async deleteWorkflowRunById({ runId, workflowName, fence }) {
|
|
12614
12656
|
try {
|
|
12615
12657
|
await withRunFence(this.pool, RUN_OWNERS_TABLE, (0, _mastra_core_storage.resolveRunFence)(this, fence, runId), "deleteWorkflowRunById", (q) => q.execute(`DELETE FROM ${formatTableName(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT)} WHERE ${quoteIdentifier("workflow_name", "column name")} = ? AND ${quoteIdentifier("run_id", "column name")} = ?`, [workflowName, runId]));
|
|
@@ -12829,8 +12871,12 @@ var WorkflowsMySQL = class WorkflowsMySQL extends _mastra_core_storage.Workflows
|
|
|
12829
12871
|
}, error);
|
|
12830
12872
|
}
|
|
12831
12873
|
}
|
|
12874
|
+
/**
|
|
12875
|
+
* Lists runs newest first, with optional filters and pagination. With `summary`, each run's
|
|
12876
|
+
* snapshot holds only `status`, `timestamp` and `parentWorkflow`.
|
|
12877
|
+
*/
|
|
12832
12878
|
async listWorkflowRuns(args = {}) {
|
|
12833
|
-
const { workflowName, fromDate, toDate, perPage, page, resourceId, status } = args;
|
|
12879
|
+
const { workflowName, fromDate, toDate, perPage, page, resourceId, status, summary } = args;
|
|
12834
12880
|
const conditions = [];
|
|
12835
12881
|
const params = [];
|
|
12836
12882
|
if (workflowName) {
|
|
@@ -12872,7 +12918,8 @@ var WorkflowsMySQL = class WorkflowsMySQL extends _mastra_core_storage.Workflows
|
|
|
12872
12918
|
const offset = page * normalizedPerPage;
|
|
12873
12919
|
paginationClause = ` LIMIT ${Number(normalizedPerPage)} OFFSET ${Number(offset)}`;
|
|
12874
12920
|
}
|
|
12875
|
-
const
|
|
12921
|
+
const snapshot = summary ? `${SUMMARY_SNAPSHOT_SQL} AS snapshot` : "snapshot";
|
|
12922
|
+
const [rows] = await this.pool.execute(`SELECT workflow_name, run_id, resourceId, ${snapshot}, createdAt, updatedAt FROM ${tableName}${whereSql} ORDER BY ${quoteIdentifier("createdAt", "column name")} DESC${paginationClause}`, params);
|
|
12876
12923
|
const runs = rows.map(mapWorkflowRow);
|
|
12877
12924
|
return {
|
|
12878
12925
|
runs,
|