@mastra/mysql 0.8.0 → 0.8.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/CHANGELOG.md +55 -0
- package/dist/index.cjs +92 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +93 -15
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts +2 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
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, hasErrorCode, isKnowledgeScopeVisible, knowledgeScopeKey, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, listTracesArgsSchema, normalizePerPage, normalizeScheduleTarget, parseKnowledgeNodeCursor, parseKnowledgeWikilinks, toTraceSpans, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
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, hasErrorCode, isKnowledgeScopeVisible, knowledgeScopeKey, knowledgeSemanticDocumentId, knowledgeSemanticIdempotencyKey, listTracesArgsSchema, matchesExpectedWorkflowStatus, normalizePerPage, normalizeScheduleTarget, parseKnowledgeNodeCursor, parseKnowledgeWikilinks, toTraceSpans, validateStorageMetadataFilter } from "@mastra/core/storage";
|
|
3
3
|
import { createPool } from "mysql2/promise";
|
|
4
4
|
import { parseSqlIdentifier } from "@mastra/core/utils";
|
|
5
5
|
import { randomUUID } from "crypto";
|
|
@@ -2576,7 +2576,11 @@ var DatasetsMySQL = class DatasetsMySQL extends DatasetsStorage {
|
|
|
2576
2576
|
try {
|
|
2577
2577
|
const tableItemsName = formatTableName(TABLE_DATASET_ITEMS);
|
|
2578
2578
|
let rows;
|
|
2579
|
-
if (args.datasetVersion !== void 0) [rows] = await this.pool.execute(`SELECT * FROM ${tableItemsName} WHERE \`id\` = ? AND \`datasetVersion\`
|
|
2579
|
+
if (args.datasetVersion !== void 0) [rows] = await this.pool.execute(`SELECT * FROM ${tableItemsName} WHERE \`id\` = ? AND \`datasetVersion\` <= ? AND (\`validTo\` IS NULL OR \`validTo\` > ?) AND \`isDeleted\` = 0 ORDER BY \`datasetVersion\` DESC LIMIT 1`, [
|
|
2580
|
+
args.id,
|
|
2581
|
+
args.datasetVersion,
|
|
2582
|
+
args.datasetVersion
|
|
2583
|
+
]);
|
|
2580
2584
|
else [rows] = await this.pool.execute(`SELECT * FROM ${tableItemsName} WHERE \`id\` = ? AND \`validTo\` IS NULL AND \`isDeleted\` = 0`, [args.id]);
|
|
2581
2585
|
return rows.length > 0 ? this.mapItem(rows[0]) : null;
|
|
2582
2586
|
} catch (error) {
|
|
@@ -3013,7 +3017,8 @@ var ExperimentsMySQL = class ExperimentsMySQL extends ExperimentsStorage {
|
|
|
3013
3017
|
"experimentSetId",
|
|
3014
3018
|
"comparisonId",
|
|
3015
3019
|
"variantId",
|
|
3016
|
-
"trialIndex"
|
|
3020
|
+
"trialIndex",
|
|
3021
|
+
"scorerIds"
|
|
3017
3022
|
]
|
|
3018
3023
|
});
|
|
3019
3024
|
await this.operations.alterTable({
|
|
@@ -3022,7 +3027,8 @@ var ExperimentsMySQL = class ExperimentsMySQL extends ExperimentsStorage {
|
|
|
3022
3027
|
ifNotExists: [
|
|
3023
3028
|
"comment",
|
|
3024
3029
|
"organizationId",
|
|
3025
|
-
"projectId"
|
|
3030
|
+
"projectId",
|
|
3031
|
+
"attempt"
|
|
3026
3032
|
]
|
|
3027
3033
|
});
|
|
3028
3034
|
await this.createDefaultIndexes();
|
|
@@ -3040,8 +3046,9 @@ var ExperimentsMySQL = class ExperimentsMySQL extends ExperimentsStorage {
|
|
|
3040
3046
|
agentVersion: row.agentVersion ?? null,
|
|
3041
3047
|
organizationId: row.organizationId ?? null,
|
|
3042
3048
|
projectId: row.projectId ?? null,
|
|
3043
|
-
targetType: row.targetType,
|
|
3044
|
-
targetId: row.targetId,
|
|
3049
|
+
targetType: row.targetType ?? null,
|
|
3050
|
+
targetId: row.targetId ?? null,
|
|
3051
|
+
scorerIds: parseJSON$2(row.scorerIds) ?? null,
|
|
3045
3052
|
name: row.name ?? void 0,
|
|
3046
3053
|
description: row.description ?? void 0,
|
|
3047
3054
|
metadata: parseJSON$2(row.metadata),
|
|
@@ -3077,6 +3084,7 @@ var ExperimentsMySQL = class ExperimentsMySQL extends ExperimentsStorage {
|
|
|
3077
3084
|
startedAt: parseDateTime(row.startedAt) ?? /* @__PURE__ */ new Date(),
|
|
3078
3085
|
completedAt: parseDateTime(row.completedAt) ?? /* @__PURE__ */ new Date(),
|
|
3079
3086
|
retryCount: row.retryCount,
|
|
3087
|
+
attempt: row.attempt != null ? Number(row.attempt) : 0,
|
|
3080
3088
|
traceId: row.traceId ?? null,
|
|
3081
3089
|
status: row.status ?? null,
|
|
3082
3090
|
tags: row.tags ? parseJSON$2(row.tags) ?? null : null,
|
|
@@ -3097,8 +3105,9 @@ var ExperimentsMySQL = class ExperimentsMySQL extends ExperimentsStorage {
|
|
|
3097
3105
|
agentVersion: input.agentVersion ?? null,
|
|
3098
3106
|
organizationId: input.organizationId ?? null,
|
|
3099
3107
|
projectId: input.projectId ?? null,
|
|
3100
|
-
targetType: input.targetType,
|
|
3101
|
-
targetId: input.targetId,
|
|
3108
|
+
targetType: input.targetType ?? null,
|
|
3109
|
+
targetId: input.targetId ?? null,
|
|
3110
|
+
scorerIds: input.scorerIds ? JSON.stringify(input.scorerIds) : null,
|
|
3102
3111
|
name: input.name ?? null,
|
|
3103
3112
|
description: input.description ?? null,
|
|
3104
3113
|
metadata: input.metadata ? JSON.stringify(input.metadata) : null,
|
|
@@ -3126,8 +3135,9 @@ var ExperimentsMySQL = class ExperimentsMySQL extends ExperimentsStorage {
|
|
|
3126
3135
|
agentVersion: input.agentVersion ?? null,
|
|
3127
3136
|
organizationId: input.organizationId ?? null,
|
|
3128
3137
|
projectId: input.projectId ?? null,
|
|
3129
|
-
targetType: input.targetType,
|
|
3130
|
-
targetId: input.targetId,
|
|
3138
|
+
targetType: input.targetType ?? null,
|
|
3139
|
+
targetId: input.targetId ?? null,
|
|
3140
|
+
scorerIds: input.scorerIds ?? null,
|
|
3131
3141
|
name: input.name,
|
|
3132
3142
|
description: input.description,
|
|
3133
3143
|
metadata: input.metadata,
|
|
@@ -3371,12 +3381,13 @@ var ExperimentsMySQL = class ExperimentsMySQL extends ExperimentsStorage {
|
|
|
3371
3381
|
organizationId: input.organizationId ?? null,
|
|
3372
3382
|
projectId: input.projectId ?? null,
|
|
3373
3383
|
input: JSON.stringify(input.input),
|
|
3374
|
-
output: input.output ? JSON.stringify(input.output) : null,
|
|
3375
|
-
groundTruth: input.groundTruth ? JSON.stringify(input.groundTruth) : null,
|
|
3384
|
+
output: input.output != null ? JSON.stringify(input.output) : null,
|
|
3385
|
+
groundTruth: input.groundTruth != null ? JSON.stringify(input.groundTruth) : null,
|
|
3376
3386
|
error: input.error ? JSON.stringify(input.error) : null,
|
|
3377
3387
|
startedAt: input.startedAt,
|
|
3378
3388
|
completedAt: input.completedAt,
|
|
3379
3389
|
retryCount: input.retryCount,
|
|
3390
|
+
attempt: input.attempt ?? 0,
|
|
3380
3391
|
traceId: input.traceId ?? null,
|
|
3381
3392
|
status: input.status ?? null,
|
|
3382
3393
|
tags: input.tags ? JSON.stringify(input.tags) : null,
|
|
@@ -3397,6 +3408,7 @@ var ExperimentsMySQL = class ExperimentsMySQL extends ExperimentsStorage {
|
|
|
3397
3408
|
startedAt: input.startedAt,
|
|
3398
3409
|
completedAt: input.completedAt,
|
|
3399
3410
|
retryCount: input.retryCount,
|
|
3411
|
+
attempt: input.attempt ?? 0,
|
|
3400
3412
|
traceId: input.traceId ?? null,
|
|
3401
3413
|
status: input.status ?? null,
|
|
3402
3414
|
tags: input.tags ?? null,
|
|
@@ -3429,6 +3441,66 @@ var ExperimentsMySQL = class ExperimentsMySQL extends ExperimentsStorage {
|
|
|
3429
3441
|
}, error);
|
|
3430
3442
|
}
|
|
3431
3443
|
}
|
|
3444
|
+
async upsertExperimentResult(input) {
|
|
3445
|
+
if (input.toolMockReport) throw new MastraError({
|
|
3446
|
+
id: "MYSQL_EXPERIMENT_TOOL_MOCK_REPORT_UNSUPPORTED",
|
|
3447
|
+
domain: ErrorDomain.STORAGE,
|
|
3448
|
+
category: ErrorCategory.USER,
|
|
3449
|
+
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."
|
|
3450
|
+
});
|
|
3451
|
+
try {
|
|
3452
|
+
const attempt = input.attempt ?? 0;
|
|
3453
|
+
const existingId = (await this.operations.query(`SELECT ${quoteIdentifier("id", "column name")} FROM ${formatTableName(TABLE_EXPERIMENT_RESULTS)} WHERE ${quoteIdentifier("experimentId", "column name")} = ? AND ${quoteIdentifier("itemId", "column name")} = ? AND COALESCE(${quoteIdentifier("attempt", "column name")}, 0) = ?`, [
|
|
3454
|
+
input.experimentId,
|
|
3455
|
+
input.itemId,
|
|
3456
|
+
attempt
|
|
3457
|
+
]))[0]?.id;
|
|
3458
|
+
if (!existingId) return await this.addExperimentResult({
|
|
3459
|
+
...input,
|
|
3460
|
+
attempt
|
|
3461
|
+
});
|
|
3462
|
+
await this.operations.update({
|
|
3463
|
+
tableName: TABLE_EXPERIMENT_RESULTS,
|
|
3464
|
+
keys: { id: existingId },
|
|
3465
|
+
data: {
|
|
3466
|
+
itemDatasetVersion: input.itemDatasetVersion ?? null,
|
|
3467
|
+
organizationId: input.organizationId ?? null,
|
|
3468
|
+
projectId: input.projectId ?? null,
|
|
3469
|
+
input: JSON.stringify(input.input),
|
|
3470
|
+
output: input.output != null ? JSON.stringify(input.output) : null,
|
|
3471
|
+
groundTruth: input.groundTruth != null ? JSON.stringify(input.groundTruth) : null,
|
|
3472
|
+
error: input.error ? JSON.stringify(input.error) : null,
|
|
3473
|
+
startedAt: input.startedAt,
|
|
3474
|
+
completedAt: input.completedAt,
|
|
3475
|
+
retryCount: input.retryCount,
|
|
3476
|
+
attempt,
|
|
3477
|
+
traceId: input.traceId ?? null,
|
|
3478
|
+
status: input.status ?? null,
|
|
3479
|
+
tags: input.tags ? JSON.stringify(input.tags) : null
|
|
3480
|
+
}
|
|
3481
|
+
});
|
|
3482
|
+
const updated = await this.getExperimentResultById({ id: existingId });
|
|
3483
|
+
if (!updated) throw new MastraError({
|
|
3484
|
+
id: "MYSQL_UPSERT_EXPERIMENT_RESULT_NOT_FOUND",
|
|
3485
|
+
domain: ErrorDomain.STORAGE,
|
|
3486
|
+
category: ErrorCategory.USER,
|
|
3487
|
+
text: `Experiment result ${existingId} not found after upsert`,
|
|
3488
|
+
details: {
|
|
3489
|
+
experimentId: input.experimentId,
|
|
3490
|
+
itemId: input.itemId,
|
|
3491
|
+
attempt
|
|
3492
|
+
}
|
|
3493
|
+
});
|
|
3494
|
+
return updated;
|
|
3495
|
+
} catch (error) {
|
|
3496
|
+
if (error instanceof MastraError) throw error;
|
|
3497
|
+
throw new MastraError({
|
|
3498
|
+
id: "MYSQL_UPSERT_EXPERIMENT_RESULT_FAILED",
|
|
3499
|
+
domain: ErrorDomain.STORAGE,
|
|
3500
|
+
category: ErrorCategory.THIRD_PARTY
|
|
3501
|
+
}, error);
|
|
3502
|
+
}
|
|
3503
|
+
}
|
|
3432
3504
|
async updateExperimentResult(input) {
|
|
3433
3505
|
try {
|
|
3434
3506
|
const existing = await this.operations.load({
|
|
@@ -9314,7 +9386,7 @@ var ScoresMySQL = class ScoresMySQL extends ScoresStorage {
|
|
|
9314
9386
|
}
|
|
9315
9387
|
async saveScore(score) {
|
|
9316
9388
|
try {
|
|
9317
|
-
const id = crypto.randomUUID();
|
|
9389
|
+
const id = score.id ?? crypto.randomUUID();
|
|
9318
9390
|
const now = /* @__PURE__ */ new Date();
|
|
9319
9391
|
await this.operations.insert({
|
|
9320
9392
|
tableName: TABLE_SCORERS,
|
|
@@ -10528,9 +10600,15 @@ var WorkflowsMySQL = class WorkflowsMySQL extends WorkflowsStorage {
|
|
|
10528
10600
|
await connection.rollback();
|
|
10529
10601
|
return;
|
|
10530
10602
|
}
|
|
10603
|
+
const existing = parseSnapshot(rows[0].snapshot);
|
|
10604
|
+
const { expectedStatus, ...state } = opts;
|
|
10605
|
+
if (!matchesExpectedWorkflowStatus(existing.status, expectedStatus)) {
|
|
10606
|
+
await connection.rollback();
|
|
10607
|
+
return;
|
|
10608
|
+
}
|
|
10531
10609
|
const updatedSnapshot = {
|
|
10532
|
-
...
|
|
10533
|
-
...
|
|
10610
|
+
...existing,
|
|
10611
|
+
...state
|
|
10534
10612
|
};
|
|
10535
10613
|
await connection.execute(`UPDATE ${formatTableName(TABLE_WORKFLOW_SNAPSHOT)} SET ${quoteIdentifier("snapshot", "column name")} = ?, ${quoteIdentifier("updatedAt", "column name")} = ? WHERE ${quoteIdentifier("workflow_name", "column name")} = ? AND ${quoteIdentifier("run_id", "column name")} = ?`, [
|
|
10536
10614
|
JSON.stringify(updatedSnapshot),
|