@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/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
|
2
2
|
import { AGENTS_SCHEMA, AGENT_VERSIONS_SCHEMA, AgentsStorage, BackgroundTasksStorage, BlobStore, ChannelsStorage, DATASETS_SCHEMA, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, DatasetsStorage, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, ExperimentsStorage, FAVORITES_SCHEMA, FavoritesStorage, KNOWLEDGE_ACTIVITY_SCHEMA, KNOWLEDGE_CURSORS_SCHEMA, KNOWLEDGE_MENTIONS_SCHEMA, KNOWLEDGE_NODES_SCHEMA, KNOWLEDGE_RECORDS_SCHEMA, KNOWLEDGE_SEMANTIC_OUTBOX_SCHEMA, KnowledgeConflictError, KnowledgeNotFoundError, KnowledgeStorage, MCPClientsStorage, MCPServersStorage, MCP_CLIENTS_SCHEMA, MCP_CLIENT_VERSIONS_SCHEMA, MCP_SERVERS_SCHEMA, MCP_SERVER_VERSIONS_SCHEMA, MastraCompositeStore, MemoryStorage, OBSERVATIONAL_MEMORY_TABLE_SCHEMA, ObservabilityStorage, PROMPT_BLOCKS_SCHEMA, PROMPT_BLOCK_VERSIONS_SCHEMA, PromptBlocksStorage, SCORERS_SCHEMA, SCORER_DEFINITIONS_SCHEMA, SCORER_DEFINITION_VERSIONS_SCHEMA, SKILLS_SCHEMA, SKILL_BLOBS_SCHEMA, SKILL_VERSIONS_SCHEMA, SPAN_SCHEMA, SchedulesStorage, ScorerDefinitionsStorage, ScoresStorage, SkillsStorage, StoreOperations, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_BACKGROUND_TASKS, TABLE_CHANNEL_CONFIG, TABLE_CHANNEL_INSTALLATIONS, TABLE_CONFIGS, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, TABLE_FAVORITES, TABLE_KNOWLEDGE_ACTIVITY, TABLE_KNOWLEDGE_CURSORS, TABLE_KNOWLEDGE_MENTIONS, TABLE_KNOWLEDGE_NODES, TABLE_KNOWLEDGE_RECORDS, TABLE_KNOWLEDGE_SEMANTIC_OUTBOX, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, TABLE_MESSAGES, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, TABLE_RESOURCES, TABLE_SCHEDULES, TABLE_SCHEDULE_TRIGGERS, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SKILLS, TABLE_SKILL_BLOBS, TABLE_SKILL_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_TOOL_PROVIDER_CONNECTIONS, TABLE_WORKFLOW_DEFINITIONS, TABLE_WORKFLOW_SNAPSHOT, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, TOOL_PROVIDER_CONNECTIONS_SCHEMA, ToolProviderConnectionsStorage, TraceStatus, WORKFLOW_DEFINITIONS_SCHEMA, WORKSPACES_SCHEMA, WORKSPACE_VERSIONS_SCHEMA, WorkflowDefinitionsStorage, WorkflowsStorage, WorkspacesStorage, assertKnowledgeCeilingRaised, assertKnowledgeScopeWithinCeiling, calculatePagination, canonicalizeKnowledgeScope, createKnowledgeUlid, createStorageErrorId, executeRetentionPrune, hasErrorCode, isKnowledgeScopeVisible, knowledgeScopeKey, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, listTracesArgsSchema, matchesExpectedWorkflowStatus, normalizePerPage, normalizeScheduleTarget, parseKnowledgeNodeCursor, parseKnowledgeWikilinks, resolveListOrderBy, resolveRetentionTargets, retentionCutoffMs, toTraceSpans, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
3
3
|
import { createPool } from "mysql2/promise";
|
|
4
4
|
import { parseSqlIdentifier } from "@mastra/core/utils";
|
|
5
|
-
import { randomUUID } from "crypto";
|
|
6
5
|
import { MessageList } from "@mastra/core/agent";
|
|
7
6
|
import { skillSnapshotFieldValuesEqual } from "@mastra/core/storage/domains/skills";
|
|
8
7
|
//#region src/storage/db/schema-snapshot.ts
|
|
@@ -1688,6 +1687,13 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksSto
|
|
|
1688
1687
|
};
|
|
1689
1688
|
//#endregion
|
|
1690
1689
|
//#region src/storage/domains/blobs/index.ts
|
|
1690
|
+
const INSERT_IGNORE_SQL = `INSERT IGNORE INTO ${formatTableName(TABLE_SKILL_BLOBS)} (${[
|
|
1691
|
+
"hash",
|
|
1692
|
+
"content",
|
|
1693
|
+
"size",
|
|
1694
|
+
"mimeType",
|
|
1695
|
+
"createdAt"
|
|
1696
|
+
].map((column) => quoteIdentifier(column, "column name")).join(", ")}) VALUES (?, ?, ?, ?, ?)`;
|
|
1691
1697
|
var BlobsMySQL = class extends BlobStore {
|
|
1692
1698
|
pool;
|
|
1693
1699
|
operations;
|
|
@@ -1703,14 +1709,16 @@ var BlobsMySQL = class extends BlobStore {
|
|
|
1703
1709
|
});
|
|
1704
1710
|
}
|
|
1705
1711
|
async put(entry) {
|
|
1706
|
-
|
|
1707
|
-
|
|
1712
|
+
await this.pool.execute(INSERT_IGNORE_SQL, this.#insertArgs(entry));
|
|
1713
|
+
}
|
|
1714
|
+
#insertArgs(entry) {
|
|
1715
|
+
return [
|
|
1708
1716
|
entry.hash,
|
|
1709
1717
|
entry.content,
|
|
1710
1718
|
entry.size,
|
|
1711
1719
|
entry.mimeType ?? null,
|
|
1712
|
-
transformToSqlValue(
|
|
1713
|
-
]
|
|
1720
|
+
transformToSqlValue(entry.createdAt ?? /* @__PURE__ */ new Date())
|
|
1721
|
+
];
|
|
1714
1722
|
}
|
|
1715
1723
|
async get(hash) {
|
|
1716
1724
|
const [rows] = await this.pool.execute(`SELECT * FROM ${formatTableName(TABLE_SKILL_BLOBS)} WHERE ${quoteIdentifier("hash", "column name")} = ?`, [hash]);
|
|
@@ -1727,15 +1735,8 @@ var BlobsMySQL = class extends BlobStore {
|
|
|
1727
1735
|
}
|
|
1728
1736
|
async putMany(entries) {
|
|
1729
1737
|
if (entries.length === 0) return;
|
|
1730
|
-
await this.operations.
|
|
1731
|
-
|
|
1732
|
-
records: entries.map((entry) => ({
|
|
1733
|
-
hash: entry.hash,
|
|
1734
|
-
content: entry.content,
|
|
1735
|
-
size: entry.size,
|
|
1736
|
-
mimeType: entry.mimeType ?? null,
|
|
1737
|
-
createdAt: entry.createdAt ?? /* @__PURE__ */ new Date()
|
|
1738
|
-
}))
|
|
1738
|
+
await this.operations.withTransaction(async (connection) => {
|
|
1739
|
+
for (const entry of entries) await connection.execute(INSERT_IGNORE_SQL, this.#insertArgs(entry));
|
|
1739
1740
|
});
|
|
1740
1741
|
}
|
|
1741
1742
|
async getMany(hashes) {
|
|
@@ -2154,7 +2155,7 @@ var DatasetsMySQL = class DatasetsMySQL extends DatasetsStorage {
|
|
|
2154
2155
|
}
|
|
2155
2156
|
async createDataset(input) {
|
|
2156
2157
|
try {
|
|
2157
|
-
const id = input.id ?? randomUUID();
|
|
2158
|
+
const id = input.id ?? globalThis.crypto.randomUUID();
|
|
2158
2159
|
if (input.id !== void 0) this.validateCallerDefinedDatasetId(input.id);
|
|
2159
2160
|
const now = /* @__PURE__ */ new Date();
|
|
2160
2161
|
await (input.id === void 0 ? this.operations.insert.bind(this.operations) : this.operations.insertOnly.bind(this.operations))({
|
|
@@ -2414,8 +2415,8 @@ var DatasetsMySQL = class DatasetsMySQL extends DatasetsStorage {
|
|
|
2414
2415
|
const connection = await this.pool.getConnection();
|
|
2415
2416
|
try {
|
|
2416
2417
|
await connection.beginTransaction();
|
|
2417
|
-
const id = randomUUID();
|
|
2418
|
-
const versionId = randomUUID();
|
|
2418
|
+
const id = globalThis.crypto.randomUUID();
|
|
2419
|
+
const versionId = globalThis.crypto.randomUUID();
|
|
2419
2420
|
const now = /* @__PURE__ */ new Date();
|
|
2420
2421
|
const tableDatasetsName = formatTableName(TABLE_DATASETS);
|
|
2421
2422
|
const tableItemsName = formatTableName(TABLE_DATASET_ITEMS);
|
|
@@ -2478,7 +2479,7 @@ var DatasetsMySQL = class DatasetsMySQL extends DatasetsStorage {
|
|
|
2478
2479
|
const connection = await this.pool.getConnection();
|
|
2479
2480
|
try {
|
|
2480
2481
|
await connection.beginTransaction();
|
|
2481
|
-
const versionId = randomUUID();
|
|
2482
|
+
const versionId = globalThis.crypto.randomUUID();
|
|
2482
2483
|
const now = /* @__PURE__ */ new Date();
|
|
2483
2484
|
const tableDatasetsName = formatTableName(TABLE_DATASETS);
|
|
2484
2485
|
const tableItemsName = formatTableName(TABLE_DATASET_ITEMS);
|
|
@@ -2587,7 +2588,7 @@ var DatasetsMySQL = class DatasetsMySQL extends DatasetsStorage {
|
|
|
2587
2588
|
const connection = await this.pool.getConnection();
|
|
2588
2589
|
try {
|
|
2589
2590
|
await connection.beginTransaction();
|
|
2590
|
-
const versionId = randomUUID();
|
|
2591
|
+
const versionId = globalThis.crypto.randomUUID();
|
|
2591
2592
|
const now = /* @__PURE__ */ new Date();
|
|
2592
2593
|
const tableDatasetsName = formatTableName(TABLE_DATASETS);
|
|
2593
2594
|
const tableItemsName = formatTableName(TABLE_DATASET_ITEMS);
|
|
@@ -2818,7 +2819,7 @@ var DatasetsMySQL = class DatasetsMySQL extends DatasetsStorage {
|
|
|
2818
2819
|
}
|
|
2819
2820
|
async createDatasetVersion(datasetId, version) {
|
|
2820
2821
|
try {
|
|
2821
|
-
const id = randomUUID();
|
|
2822
|
+
const id = globalThis.crypto.randomUUID();
|
|
2822
2823
|
const now = /* @__PURE__ */ new Date();
|
|
2823
2824
|
await this.operations.insert({
|
|
2824
2825
|
tableName: TABLE_DATASET_VERSIONS,
|
|
@@ -2912,7 +2913,7 @@ var DatasetsMySQL = class DatasetsMySQL extends DatasetsStorage {
|
|
|
2912
2913
|
const [rows] = await connection.execute(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableItemsName} WHERE \`datasetId\` = ? AND \`externalId\` IN (${placeholders}) ORDER BY \`datasetVersion\` ASC`, [input.datasetId, ...externalIds]);
|
|
2913
2914
|
historyRows = rows.map((row) => this.mapItemFull(row));
|
|
2914
2915
|
}
|
|
2915
|
-
const plan = this.planDatasetItemBatch(input.items, historyRows, randomUUID);
|
|
2916
|
+
const plan = this.planDatasetItemBatch(input.items, historyRows, () => globalThis.crypto.randomUUID());
|
|
2916
2917
|
const existingItems = new Map([...plan.existingCurrentItems].map(([id, row]) => [id, this.datasetItemFromRow(row)]));
|
|
2917
2918
|
if (plan.inserts.length === 0) {
|
|
2918
2919
|
await connection.commit();
|
|
@@ -2955,7 +2956,7 @@ var DatasetsMySQL = class DatasetsMySQL extends DatasetsStorage {
|
|
|
2955
2956
|
});
|
|
2956
2957
|
}
|
|
2957
2958
|
await connection.execute(`INSERT INTO ${tableVersionsName} (\`id\`, \`datasetId\`, \`version\`, \`createdAt\`) VALUES (?, ?, ?, ?)`, [
|
|
2958
|
-
randomUUID(),
|
|
2959
|
+
globalThis.crypto.randomUUID(),
|
|
2959
2960
|
input.datasetId,
|
|
2960
2961
|
newVersion,
|
|
2961
2962
|
transformToSqlValue(now)
|
|
@@ -2986,7 +2987,7 @@ var DatasetsMySQL = class DatasetsMySQL extends DatasetsStorage {
|
|
|
2986
2987
|
try {
|
|
2987
2988
|
await connection.beginTransaction();
|
|
2988
2989
|
const now = /* @__PURE__ */ new Date();
|
|
2989
|
-
const versionId = randomUUID();
|
|
2990
|
+
const versionId = globalThis.crypto.randomUUID();
|
|
2990
2991
|
const tableDatasetsName = formatTableName(TABLE_DATASETS);
|
|
2991
2992
|
const tableItemsName = formatTableName(TABLE_DATASET_ITEMS);
|
|
2992
2993
|
const tableVersionsName = formatTableName(TABLE_DATASET_VERSIONS);
|
|
@@ -3287,7 +3288,7 @@ var ExperimentsMySQL = class ExperimentsMySQL extends ExperimentsStorage {
|
|
|
3287
3288
|
}
|
|
3288
3289
|
async createExperiment(input) {
|
|
3289
3290
|
try {
|
|
3290
|
-
const id = input.id ?? randomUUID();
|
|
3291
|
+
const id = input.id ?? globalThis.crypto.randomUUID();
|
|
3291
3292
|
const now = /* @__PURE__ */ new Date();
|
|
3292
3293
|
await this.operations.insert({
|
|
3293
3294
|
tableName: TABLE_EXPERIMENTS,
|
|
@@ -3566,7 +3567,7 @@ var ExperimentsMySQL = class ExperimentsMySQL extends ExperimentsStorage {
|
|
|
3566
3567
|
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."
|
|
3567
3568
|
});
|
|
3568
3569
|
try {
|
|
3569
|
-
const id = input.id ?? randomUUID();
|
|
3570
|
+
const id = input.id ?? globalThis.crypto.randomUUID();
|
|
3570
3571
|
const now = /* @__PURE__ */ new Date();
|
|
3571
3572
|
const purgeMetadata = await this.#withPurgeBarrier(input.experimentId, input.itemId, async (connection, marker) => {
|
|
3572
3573
|
await connection.execute(`INSERT INTO ${formatTableName(TABLE_EXPERIMENT_RESULTS)} (
|
|
@@ -3717,7 +3718,7 @@ var ExperimentsMySQL = class ExperimentsMySQL extends ExperimentsStorage {
|
|
|
3717
3718
|
await connection.execute(`INSERT INTO ${tableName} (${columns.map((column) => quoteIdentifier(column, "column name")).join(", ")})
|
|
3718
3719
|
VALUES (${Array.from({ length: columns.length }, () => "?").join(", ")})
|
|
3719
3720
|
ON DUPLICATE KEY UPDATE ${updateColumns.map((column) => `${quoteIdentifier(column, "column name")} = VALUES(${quoteIdentifier(column, "column name")})`).join(", ")}`, [
|
|
3720
|
-
randomUUID(),
|
|
3721
|
+
globalThis.crypto.randomUUID(),
|
|
3721
3722
|
input.experimentId,
|
|
3722
3723
|
input.itemId,
|
|
3723
3724
|
...updateValues,
|
|
@@ -6720,7 +6721,7 @@ var MemoryMySQL = class MemoryMySQL extends MemoryStorage {
|
|
|
6720
6721
|
});
|
|
6721
6722
|
const createdAt = message.createdAt ? new Date(message.createdAt) : /* @__PURE__ */ new Date();
|
|
6722
6723
|
const record = {
|
|
6723
|
-
id: message.id ?? randomUUID(),
|
|
6724
|
+
id: message.id ?? globalThis.crypto.randomUUID(),
|
|
6724
6725
|
thread_id: message.threadId,
|
|
6725
6726
|
content: JSON.stringify(message.content ?? message),
|
|
6726
6727
|
role: message.role,
|
|
@@ -6852,7 +6853,7 @@ var MemoryMySQL = class MemoryMySQL extends MemoryStorage {
|
|
|
6852
6853
|
text: `Source thread with id ${sourceThreadId} not found`,
|
|
6853
6854
|
details: { sourceThreadId }
|
|
6854
6855
|
});
|
|
6855
|
-
const newThreadId = providedThreadId || randomUUID();
|
|
6856
|
+
const newThreadId = providedThreadId || globalThis.crypto.randomUUID();
|
|
6856
6857
|
if (await this.getThreadById({ threadId: newThreadId })) throw new MastraError({
|
|
6857
6858
|
id: createStorageErrorId("MYSQL", "CLONE_THREAD", "THREAD_EXISTS"),
|
|
6858
6859
|
domain: ErrorDomain.STORAGE,
|
|
@@ -6918,7 +6919,7 @@ var MemoryMySQL = class MemoryMySQL extends MemoryStorage {
|
|
|
6918
6919
|
const targetResourceId = resourceId || sourceThread.resourceId;
|
|
6919
6920
|
for (const sourceRow of sourceMessageRows) {
|
|
6920
6921
|
const row = sourceRow;
|
|
6921
|
-
const newMessageId = randomUUID();
|
|
6922
|
+
const newMessageId = globalThis.crypto.randomUUID();
|
|
6922
6923
|
messageIdMap[row.id] = newMessageId;
|
|
6923
6924
|
let content = row.content;
|
|
6924
6925
|
try {
|
|
@@ -7345,7 +7346,7 @@ var MemoryMySQL = class MemoryMySQL extends MemoryStorage {
|
|
|
7345
7346
|
}
|
|
7346
7347
|
async initializeObservationalMemory(input) {
|
|
7347
7348
|
try {
|
|
7348
|
-
const id = randomUUID();
|
|
7349
|
+
const id = globalThis.crypto.randomUUID();
|
|
7349
7350
|
const now = /* @__PURE__ */ new Date();
|
|
7350
7351
|
const lookupKey = this.getOMKey(input.threadId, input.resourceId);
|
|
7351
7352
|
const record = {
|
|
@@ -7461,7 +7462,7 @@ var MemoryMySQL = class MemoryMySQL extends MemoryStorage {
|
|
|
7461
7462
|
}
|
|
7462
7463
|
async createReflectionGeneration(input) {
|
|
7463
7464
|
try {
|
|
7464
|
-
const id = randomUUID();
|
|
7465
|
+
const id = globalThis.crypto.randomUUID();
|
|
7465
7466
|
const now = /* @__PURE__ */ new Date();
|
|
7466
7467
|
const lookupKey = this.getOMKey(input.currentRecord.threadId, input.currentRecord.resourceId);
|
|
7467
7468
|
const record = {
|
|
@@ -7616,7 +7617,7 @@ var MemoryMySQL = class MemoryMySQL extends MemoryStorage {
|
|
|
7616
7617
|
return;
|
|
7617
7618
|
}
|
|
7618
7619
|
const newChunk = {
|
|
7619
|
-
id: `ombuf-${randomUUID()}`,
|
|
7620
|
+
id: `ombuf-${globalThis.crypto.randomUUID()}`,
|
|
7620
7621
|
cycleId: input.chunk.cycleId,
|
|
7621
7622
|
observations: input.chunk.observations,
|
|
7622
7623
|
tokenCount: input.chunk.tokenCount,
|
|
@@ -9119,7 +9120,7 @@ var SchedulesMySQL = class SchedulesMySQL extends SchedulesStorage {
|
|
|
9119
9120
|
await this.pool.execute(`DELETE FROM ${formatTableName(TABLE_SCHEDULES)} WHERE ${quoteIdentifier("id", "column name")} = ?`, [id]);
|
|
9120
9121
|
}
|
|
9121
9122
|
async recordTrigger(trigger) {
|
|
9122
|
-
const id = trigger.id ?? randomUUID();
|
|
9123
|
+
const id = trigger.id ?? globalThis.crypto.randomUUID();
|
|
9123
9124
|
await this.pool.execute(`INSERT INTO ${formatTableName(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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
9124
9125
|
id,
|
|
9125
9126
|
trigger.scheduleId,
|