@mastra/mysql 0.11.0 → 0.11.1-alpha.1
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 +1 -1
- package/dist/index.cjs +34 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -33
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/blobs/index.d.ts.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/schedules/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,6 @@ let _mastra_core_error = require("@mastra/core/error");
|
|
|
3
3
|
let _mastra_core_storage = require("@mastra/core/storage");
|
|
4
4
|
let mysql2_promise = require("mysql2/promise");
|
|
5
5
|
let _mastra_core_utils = require("@mastra/core/utils");
|
|
6
|
-
let crypto$1 = require("crypto");
|
|
7
6
|
let _mastra_core_agent = require("@mastra/core/agent");
|
|
8
7
|
let _mastra_core_storage_domains_skills = require("@mastra/core/storage/domains/skills");
|
|
9
8
|
//#region src/storage/db/schema-snapshot.ts
|
|
@@ -1689,6 +1688,13 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends _mastra_core_stora
|
|
|
1689
1688
|
};
|
|
1690
1689
|
//#endregion
|
|
1691
1690
|
//#region src/storage/domains/blobs/index.ts
|
|
1691
|
+
const INSERT_IGNORE_SQL = `INSERT IGNORE INTO ${formatTableName(_mastra_core_storage.TABLE_SKILL_BLOBS)} (${[
|
|
1692
|
+
"hash",
|
|
1693
|
+
"content",
|
|
1694
|
+
"size",
|
|
1695
|
+
"mimeType",
|
|
1696
|
+
"createdAt"
|
|
1697
|
+
].map((column) => quoteIdentifier(column, "column name")).join(", ")}) VALUES (?, ?, ?, ?, ?)`;
|
|
1692
1698
|
var BlobsMySQL = class extends _mastra_core_storage.BlobStore {
|
|
1693
1699
|
pool;
|
|
1694
1700
|
operations;
|
|
@@ -1704,14 +1710,16 @@ var BlobsMySQL = class extends _mastra_core_storage.BlobStore {
|
|
|
1704
1710
|
});
|
|
1705
1711
|
}
|
|
1706
1712
|
async put(entry) {
|
|
1707
|
-
|
|
1708
|
-
|
|
1713
|
+
await this.pool.execute(INSERT_IGNORE_SQL, this.#insertArgs(entry));
|
|
1714
|
+
}
|
|
1715
|
+
#insertArgs(entry) {
|
|
1716
|
+
return [
|
|
1709
1717
|
entry.hash,
|
|
1710
1718
|
entry.content,
|
|
1711
1719
|
entry.size,
|
|
1712
1720
|
entry.mimeType ?? null,
|
|
1713
|
-
transformToSqlValue(
|
|
1714
|
-
]
|
|
1721
|
+
transformToSqlValue(entry.createdAt ?? /* @__PURE__ */ new Date())
|
|
1722
|
+
];
|
|
1715
1723
|
}
|
|
1716
1724
|
async get(hash) {
|
|
1717
1725
|
const [rows] = await this.pool.execute(`SELECT * FROM ${formatTableName(_mastra_core_storage.TABLE_SKILL_BLOBS)} WHERE ${quoteIdentifier("hash", "column name")} = ?`, [hash]);
|
|
@@ -1728,15 +1736,8 @@ var BlobsMySQL = class extends _mastra_core_storage.BlobStore {
|
|
|
1728
1736
|
}
|
|
1729
1737
|
async putMany(entries) {
|
|
1730
1738
|
if (entries.length === 0) return;
|
|
1731
|
-
await this.operations.
|
|
1732
|
-
|
|
1733
|
-
records: entries.map((entry) => ({
|
|
1734
|
-
hash: entry.hash,
|
|
1735
|
-
content: entry.content,
|
|
1736
|
-
size: entry.size,
|
|
1737
|
-
mimeType: entry.mimeType ?? null,
|
|
1738
|
-
createdAt: entry.createdAt ?? /* @__PURE__ */ new Date()
|
|
1739
|
-
}))
|
|
1739
|
+
await this.operations.withTransaction(async (connection) => {
|
|
1740
|
+
for (const entry of entries) await connection.execute(INSERT_IGNORE_SQL, this.#insertArgs(entry));
|
|
1740
1741
|
});
|
|
1741
1742
|
}
|
|
1742
1743
|
async getMany(hashes) {
|
|
@@ -2155,7 +2156,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2155
2156
|
}
|
|
2156
2157
|
async createDataset(input) {
|
|
2157
2158
|
try {
|
|
2158
|
-
const id = input.id ??
|
|
2159
|
+
const id = input.id ?? globalThis.crypto.randomUUID();
|
|
2159
2160
|
if (input.id !== void 0) this.validateCallerDefinedDatasetId(input.id);
|
|
2160
2161
|
const now = /* @__PURE__ */ new Date();
|
|
2161
2162
|
await (input.id === void 0 ? this.operations.insert.bind(this.operations) : this.operations.insertOnly.bind(this.operations))({
|
|
@@ -2415,8 +2416,8 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2415
2416
|
const connection = await this.pool.getConnection();
|
|
2416
2417
|
try {
|
|
2417
2418
|
await connection.beginTransaction();
|
|
2418
|
-
const id =
|
|
2419
|
-
const versionId =
|
|
2419
|
+
const id = globalThis.crypto.randomUUID();
|
|
2420
|
+
const versionId = globalThis.crypto.randomUUID();
|
|
2420
2421
|
const now = /* @__PURE__ */ new Date();
|
|
2421
2422
|
const tableDatasetsName = formatTableName(_mastra_core_storage.TABLE_DATASETS);
|
|
2422
2423
|
const tableItemsName = formatTableName(_mastra_core_storage.TABLE_DATASET_ITEMS);
|
|
@@ -2479,7 +2480,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2479
2480
|
const connection = await this.pool.getConnection();
|
|
2480
2481
|
try {
|
|
2481
2482
|
await connection.beginTransaction();
|
|
2482
|
-
const versionId =
|
|
2483
|
+
const versionId = globalThis.crypto.randomUUID();
|
|
2483
2484
|
const now = /* @__PURE__ */ new Date();
|
|
2484
2485
|
const tableDatasetsName = formatTableName(_mastra_core_storage.TABLE_DATASETS);
|
|
2485
2486
|
const tableItemsName = formatTableName(_mastra_core_storage.TABLE_DATASET_ITEMS);
|
|
@@ -2588,7 +2589,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2588
2589
|
const connection = await this.pool.getConnection();
|
|
2589
2590
|
try {
|
|
2590
2591
|
await connection.beginTransaction();
|
|
2591
|
-
const versionId =
|
|
2592
|
+
const versionId = globalThis.crypto.randomUUID();
|
|
2592
2593
|
const now = /* @__PURE__ */ new Date();
|
|
2593
2594
|
const tableDatasetsName = formatTableName(_mastra_core_storage.TABLE_DATASETS);
|
|
2594
2595
|
const tableItemsName = formatTableName(_mastra_core_storage.TABLE_DATASET_ITEMS);
|
|
@@ -2819,7 +2820,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2819
2820
|
}
|
|
2820
2821
|
async createDatasetVersion(datasetId, version) {
|
|
2821
2822
|
try {
|
|
2822
|
-
const id =
|
|
2823
|
+
const id = globalThis.crypto.randomUUID();
|
|
2823
2824
|
const now = /* @__PURE__ */ new Date();
|
|
2824
2825
|
await this.operations.insert({
|
|
2825
2826
|
tableName: _mastra_core_storage.TABLE_DATASET_VERSIONS,
|
|
@@ -2913,7 +2914,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2913
2914
|
const [rows] = await connection.execute(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableItemsName} WHERE \`datasetId\` = ? AND \`externalId\` IN (${placeholders}) ORDER BY \`datasetVersion\` ASC`, [input.datasetId, ...externalIds]);
|
|
2914
2915
|
historyRows = rows.map((row) => this.mapItemFull(row));
|
|
2915
2916
|
}
|
|
2916
|
-
const plan = this.planDatasetItemBatch(input.items, historyRows, crypto
|
|
2917
|
+
const plan = this.planDatasetItemBatch(input.items, historyRows, () => globalThis.crypto.randomUUID());
|
|
2917
2918
|
const existingItems = new Map([...plan.existingCurrentItems].map(([id, row]) => [id, this.datasetItemFromRow(row)]));
|
|
2918
2919
|
if (plan.inserts.length === 0) {
|
|
2919
2920
|
await connection.commit();
|
|
@@ -2956,7 +2957,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2956
2957
|
});
|
|
2957
2958
|
}
|
|
2958
2959
|
await connection.execute(`INSERT INTO ${tableVersionsName} (\`id\`, \`datasetId\`, \`version\`, \`createdAt\`) VALUES (?, ?, ?, ?)`, [
|
|
2959
|
-
|
|
2960
|
+
globalThis.crypto.randomUUID(),
|
|
2960
2961
|
input.datasetId,
|
|
2961
2962
|
newVersion,
|
|
2962
2963
|
transformToSqlValue(now)
|
|
@@ -2987,7 +2988,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
|
|
|
2987
2988
|
try {
|
|
2988
2989
|
await connection.beginTransaction();
|
|
2989
2990
|
const now = /* @__PURE__ */ new Date();
|
|
2990
|
-
const versionId =
|
|
2991
|
+
const versionId = globalThis.crypto.randomUUID();
|
|
2991
2992
|
const tableDatasetsName = formatTableName(_mastra_core_storage.TABLE_DATASETS);
|
|
2992
2993
|
const tableItemsName = formatTableName(_mastra_core_storage.TABLE_DATASET_ITEMS);
|
|
2993
2994
|
const tableVersionsName = formatTableName(_mastra_core_storage.TABLE_DATASET_VERSIONS);
|
|
@@ -3288,7 +3289,7 @@ var ExperimentsMySQL = class ExperimentsMySQL extends _mastra_core_storage.Exper
|
|
|
3288
3289
|
}
|
|
3289
3290
|
async createExperiment(input) {
|
|
3290
3291
|
try {
|
|
3291
|
-
const id = input.id ??
|
|
3292
|
+
const id = input.id ?? globalThis.crypto.randomUUID();
|
|
3292
3293
|
const now = /* @__PURE__ */ new Date();
|
|
3293
3294
|
await this.operations.insert({
|
|
3294
3295
|
tableName: _mastra_core_storage.TABLE_EXPERIMENTS,
|
|
@@ -3567,7 +3568,7 @@ var ExperimentsMySQL = class ExperimentsMySQL extends _mastra_core_storage.Exper
|
|
|
3567
3568
|
text: "Tool mock reports are not supported on the MySQL storage adapter. Use a supported adapter (LibSQL, PostgreSQL, MongoDB, or Spanner) to persist experiment tool mock reports."
|
|
3568
3569
|
});
|
|
3569
3570
|
try {
|
|
3570
|
-
const id = input.id ??
|
|
3571
|
+
const id = input.id ?? globalThis.crypto.randomUUID();
|
|
3571
3572
|
const now = /* @__PURE__ */ new Date();
|
|
3572
3573
|
const purgeMetadata = await this.#withPurgeBarrier(input.experimentId, input.itemId, async (connection, marker) => {
|
|
3573
3574
|
await connection.execute(`INSERT INTO ${formatTableName(_mastra_core_storage.TABLE_EXPERIMENT_RESULTS)} (
|
|
@@ -3718,7 +3719,7 @@ var ExperimentsMySQL = class ExperimentsMySQL extends _mastra_core_storage.Exper
|
|
|
3718
3719
|
await connection.execute(`INSERT INTO ${tableName} (${columns.map((column) => quoteIdentifier(column, "column name")).join(", ")})
|
|
3719
3720
|
VALUES (${Array.from({ length: columns.length }, () => "?").join(", ")})
|
|
3720
3721
|
ON DUPLICATE KEY UPDATE ${updateColumns.map((column) => `${quoteIdentifier(column, "column name")} = VALUES(${quoteIdentifier(column, "column name")})`).join(", ")}`, [
|
|
3721
|
-
|
|
3722
|
+
globalThis.crypto.randomUUID(),
|
|
3722
3723
|
input.experimentId,
|
|
3723
3724
|
input.itemId,
|
|
3724
3725
|
...updateValues,
|
|
@@ -6721,7 +6722,7 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
|
|
|
6721
6722
|
});
|
|
6722
6723
|
const createdAt = message.createdAt ? new Date(message.createdAt) : /* @__PURE__ */ new Date();
|
|
6723
6724
|
const record = {
|
|
6724
|
-
id: message.id ??
|
|
6725
|
+
id: message.id ?? globalThis.crypto.randomUUID(),
|
|
6725
6726
|
thread_id: message.threadId,
|
|
6726
6727
|
content: JSON.stringify(message.content ?? message),
|
|
6727
6728
|
role: message.role,
|
|
@@ -6853,7 +6854,7 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
|
|
|
6853
6854
|
text: `Source thread with id ${sourceThreadId} not found`,
|
|
6854
6855
|
details: { sourceThreadId }
|
|
6855
6856
|
});
|
|
6856
|
-
const newThreadId = providedThreadId ||
|
|
6857
|
+
const newThreadId = providedThreadId || globalThis.crypto.randomUUID();
|
|
6857
6858
|
if (await this.getThreadById({ threadId: newThreadId })) throw new _mastra_core_error.MastraError({
|
|
6858
6859
|
id: (0, _mastra_core_storage.createStorageErrorId)("MYSQL", "CLONE_THREAD", "THREAD_EXISTS"),
|
|
6859
6860
|
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
@@ -6919,7 +6920,7 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
|
|
|
6919
6920
|
const targetResourceId = resourceId || sourceThread.resourceId;
|
|
6920
6921
|
for (const sourceRow of sourceMessageRows) {
|
|
6921
6922
|
const row = sourceRow;
|
|
6922
|
-
const newMessageId =
|
|
6923
|
+
const newMessageId = globalThis.crypto.randomUUID();
|
|
6923
6924
|
messageIdMap[row.id] = newMessageId;
|
|
6924
6925
|
let content = row.content;
|
|
6925
6926
|
try {
|
|
@@ -7346,7 +7347,7 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
|
|
|
7346
7347
|
}
|
|
7347
7348
|
async initializeObservationalMemory(input) {
|
|
7348
7349
|
try {
|
|
7349
|
-
const id =
|
|
7350
|
+
const id = globalThis.crypto.randomUUID();
|
|
7350
7351
|
const now = /* @__PURE__ */ new Date();
|
|
7351
7352
|
const lookupKey = this.getOMKey(input.threadId, input.resourceId);
|
|
7352
7353
|
const record = {
|
|
@@ -7462,7 +7463,7 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
|
|
|
7462
7463
|
}
|
|
7463
7464
|
async createReflectionGeneration(input) {
|
|
7464
7465
|
try {
|
|
7465
|
-
const id =
|
|
7466
|
+
const id = globalThis.crypto.randomUUID();
|
|
7466
7467
|
const now = /* @__PURE__ */ new Date();
|
|
7467
7468
|
const lookupKey = this.getOMKey(input.currentRecord.threadId, input.currentRecord.resourceId);
|
|
7468
7469
|
const record = {
|
|
@@ -7617,7 +7618,7 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
|
|
|
7617
7618
|
return;
|
|
7618
7619
|
}
|
|
7619
7620
|
const newChunk = {
|
|
7620
|
-
id: `ombuf-${
|
|
7621
|
+
id: `ombuf-${globalThis.crypto.randomUUID()}`,
|
|
7621
7622
|
cycleId: input.chunk.cycleId,
|
|
7622
7623
|
observations: input.chunk.observations,
|
|
7623
7624
|
tokenCount: input.chunk.tokenCount,
|
|
@@ -9120,7 +9121,7 @@ var SchedulesMySQL = class SchedulesMySQL extends _mastra_core_storage.Schedules
|
|
|
9120
9121
|
await this.pool.execute(`DELETE FROM ${formatTableName(_mastra_core_storage.TABLE_SCHEDULES)} WHERE ${quoteIdentifier("id", "column name")} = ?`, [id]);
|
|
9121
9122
|
}
|
|
9122
9123
|
async recordTrigger(trigger) {
|
|
9123
|
-
const id = trigger.id ??
|
|
9124
|
+
const id = trigger.id ?? globalThis.crypto.randomUUID();
|
|
9124
9125
|
await this.pool.execute(`INSERT INTO ${formatTableName(_mastra_core_storage.TABLE_SCHEDULE_TRIGGERS)} (${quoteIdentifier("id", "column name")}, ${quoteIdentifier("schedule_id", "column name")}, ${quoteIdentifier("run_id", "column name")}, ${quoteIdentifier("scheduled_fire_at", "column name")}, ${quoteIdentifier("actual_fire_at", "column name")}, ${quoteIdentifier("outcome", "column name")}, ${quoteIdentifier("error", "column name")}, ${quoteIdentifier("trigger_kind", "column name")}, ${quoteIdentifier("parent_trigger_id", "column name")}, ${quoteIdentifier("metadata", "column name")}) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
9125
9126
|
id,
|
|
9126
9127
|
trigger.scheduleId,
|