@mastra/spanner 1.5.0 → 1.6.0-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 +56 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +82 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +82 -12
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +7 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -3970,6 +3970,12 @@ function rowToExperiment(row) {
|
|
|
3970
3970
|
name: t.name ?? void 0,
|
|
3971
3971
|
description: t.description ?? void 0,
|
|
3972
3972
|
metadata: t.metadata ?? void 0,
|
|
3973
|
+
provenance: t.provenance ?? null,
|
|
3974
|
+
runnerAttestation: t.runnerAttestation ?? null,
|
|
3975
|
+
experimentSetId: t.experimentSetId ?? null,
|
|
3976
|
+
comparisonId: t.comparisonId ?? null,
|
|
3977
|
+
variantId: t.variantId ?? null,
|
|
3978
|
+
trialIndex: t.trialIndex == null ? null : Number(t.trialIndex),
|
|
3973
3979
|
datasetId: t.datasetId ?? null,
|
|
3974
3980
|
datasetVersion: t.datasetVersion == null ? null : Number(t.datasetVersion),
|
|
3975
3981
|
organizationId: t.organizationId ?? null,
|
|
@@ -4050,7 +4056,17 @@ var ExperimentsSpanner = class ExperimentsSpanner extends ExperimentsStorage {
|
|
|
4050
4056
|
await this.db.alterTable({
|
|
4051
4057
|
tableName: TABLE_EXPERIMENTS,
|
|
4052
4058
|
schema: TABLE_SCHEMAS[TABLE_EXPERIMENTS],
|
|
4053
|
-
ifNotExists: [
|
|
4059
|
+
ifNotExists: [
|
|
4060
|
+
"agentVersion",
|
|
4061
|
+
"organizationId",
|
|
4062
|
+
"projectId",
|
|
4063
|
+
"provenance",
|
|
4064
|
+
"runnerAttestation",
|
|
4065
|
+
"experimentSetId",
|
|
4066
|
+
"comparisonId",
|
|
4067
|
+
"variantId",
|
|
4068
|
+
"trialIndex"
|
|
4069
|
+
]
|
|
4054
4070
|
});
|
|
4055
4071
|
await this.db.alterTable({
|
|
4056
4072
|
tableName: TABLE_EXPERIMENT_RESULTS,
|
|
@@ -4071,6 +4087,16 @@ var ExperimentsSpanner = class ExperimentsSpanner extends ExperimentsStorage {
|
|
|
4071
4087
|
table: TABLE_EXPERIMENTS,
|
|
4072
4088
|
columns: ["datasetId"]
|
|
4073
4089
|
},
|
|
4090
|
+
{
|
|
4091
|
+
name: "mastra_experiments_grouping_idx",
|
|
4092
|
+
table: TABLE_EXPERIMENTS,
|
|
4093
|
+
columns: [
|
|
4094
|
+
"experimentSetId",
|
|
4095
|
+
"comparisonId",
|
|
4096
|
+
"variantId",
|
|
4097
|
+
"trialIndex"
|
|
4098
|
+
]
|
|
4099
|
+
},
|
|
4074
4100
|
{
|
|
4075
4101
|
name: "mastra_experiment_results_experimentid_idx",
|
|
4076
4102
|
table: TABLE_EXPERIMENT_RESULTS,
|
|
@@ -4115,6 +4141,12 @@ var ExperimentsSpanner = class ExperimentsSpanner extends ExperimentsStorage {
|
|
|
4115
4141
|
name: input.name ?? void 0,
|
|
4116
4142
|
description: input.description ?? void 0,
|
|
4117
4143
|
metadata: input.metadata ?? void 0,
|
|
4144
|
+
provenance: input.provenance ?? null,
|
|
4145
|
+
runnerAttestation: input.runnerAttestation ?? null,
|
|
4146
|
+
experimentSetId: input.experimentSetId ?? null,
|
|
4147
|
+
comparisonId: input.comparisonId ?? null,
|
|
4148
|
+
variantId: input.variantId ?? null,
|
|
4149
|
+
trialIndex: input.trialIndex ?? null,
|
|
4118
4150
|
datasetId: input.datasetId ?? null,
|
|
4119
4151
|
datasetVersion: input.datasetVersion ?? null,
|
|
4120
4152
|
organizationId: input.organizationId ?? null,
|
|
@@ -4139,6 +4171,12 @@ var ExperimentsSpanner = class ExperimentsSpanner extends ExperimentsStorage {
|
|
|
4139
4171
|
name: experiment.name ?? null,
|
|
4140
4172
|
description: experiment.description ?? null,
|
|
4141
4173
|
metadata: experiment.metadata ?? null,
|
|
4174
|
+
provenance: experiment.provenance,
|
|
4175
|
+
runnerAttestation: experiment.runnerAttestation,
|
|
4176
|
+
experimentSetId: experiment.experimentSetId,
|
|
4177
|
+
comparisonId: experiment.comparisonId,
|
|
4178
|
+
variantId: experiment.variantId,
|
|
4179
|
+
trialIndex: experiment.trialIndex,
|
|
4142
4180
|
datasetId: experiment.datasetId,
|
|
4143
4181
|
datasetVersion: experiment.datasetVersion,
|
|
4144
4182
|
organizationId: experiment.organizationId,
|
|
@@ -4273,6 +4311,22 @@ var ExperimentsSpanner = class ExperimentsSpanner extends ExperimentsStorage {
|
|
|
4273
4311
|
conditions.push(`${quoteIdent("status", "column name")} = @status`);
|
|
4274
4312
|
params.status = args.status;
|
|
4275
4313
|
}
|
|
4314
|
+
if (args.experimentSetId !== void 0) {
|
|
4315
|
+
conditions.push(`${quoteIdent("experimentSetId", "column name")} = @experimentSetId`);
|
|
4316
|
+
params.experimentSetId = args.experimentSetId;
|
|
4317
|
+
}
|
|
4318
|
+
if (args.comparisonId !== void 0) {
|
|
4319
|
+
conditions.push(`${quoteIdent("comparisonId", "column name")} = @comparisonId`);
|
|
4320
|
+
params.comparisonId = args.comparisonId;
|
|
4321
|
+
}
|
|
4322
|
+
if (args.variantId !== void 0) {
|
|
4323
|
+
conditions.push(`${quoteIdent("variantId", "column name")} = @variantId`);
|
|
4324
|
+
params.variantId = args.variantId;
|
|
4325
|
+
}
|
|
4326
|
+
if (args.trialIndex !== void 0) {
|
|
4327
|
+
conditions.push(`${quoteIdent("trialIndex", "column name")} = @trialIndex`);
|
|
4328
|
+
params.trialIndex = args.trialIndex;
|
|
4329
|
+
}
|
|
4276
4330
|
if (args.filters) {
|
|
4277
4331
|
const { organizationId, projectId } = args.filters;
|
|
4278
4332
|
if (organizationId !== void 0) {
|
|
@@ -6680,15 +6734,23 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6680
6734
|
}, error);
|
|
6681
6735
|
this.logger?.error?.(mastraError.toString());
|
|
6682
6736
|
this.logger?.trackException?.(mastraError);
|
|
6683
|
-
|
|
6737
|
+
throw mastraError;
|
|
6684
6738
|
}
|
|
6685
6739
|
}
|
|
6686
|
-
/**
|
|
6687
|
-
|
|
6740
|
+
/**
|
|
6741
|
+
* Resolves the `include` clause: pinned messages plus their before/after windows.
|
|
6742
|
+
*
|
|
6743
|
+
* @param include - Message ids to pin, each with an optional before/after window.
|
|
6744
|
+
* @param resourceId - When set, restricts both the pinned messages and their context
|
|
6745
|
+
* to that resource so an id from another resource returns nothing.
|
|
6746
|
+
*/
|
|
6747
|
+
async getIncludedMessages({ include, resourceId }) {
|
|
6688
6748
|
if (!include || include.length === 0) return null;
|
|
6749
|
+
const resourceCondition = resourceId ? ` AND ${quoteIdent("resourceId", "column name")} = @scopedResourceId` : "";
|
|
6750
|
+
const resourceParams = resourceId ? { scopedResourceId: resourceId } : {};
|
|
6689
6751
|
const ids = include.map((i) => i.id);
|
|
6690
6752
|
const placeholders = [];
|
|
6691
|
-
const idParams = {};
|
|
6753
|
+
const idParams = { ...resourceParams };
|
|
6692
6754
|
ids.forEach((id, i) => {
|
|
6693
6755
|
const name = `tid${i}`;
|
|
6694
6756
|
placeholders.push(`@${name}`);
|
|
@@ -6696,7 +6758,7 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6696
6758
|
});
|
|
6697
6759
|
const targetsSql = `SELECT id, content, role, type, ${quoteIdent("createdAt", "column name")}, ${quoteIdent("thread_id", "column name")} AS threadId, ${quoteIdent("resourceId", "column name")}
|
|
6698
6760
|
FROM ${quoteIdent(TABLE_MESSAGES, "table name")}
|
|
6699
|
-
WHERE id IN (${placeholders.join(", ")})`;
|
|
6761
|
+
WHERE id IN (${placeholders.join(", ")})${resourceCondition}`;
|
|
6700
6762
|
const [targetRows] = await this.database.run({
|
|
6701
6763
|
sql: targetsSql,
|
|
6702
6764
|
params: idParams,
|
|
@@ -6721,14 +6783,15 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6721
6783
|
sql: `SELECT id, content, role, type, ${quoteIdent("createdAt", "column name")}, ${quoteIdent("thread_id", "column name")} AS threadId, ${quoteIdent("resourceId", "column name")}
|
|
6722
6784
|
FROM ${quoteIdent(TABLE_MESSAGES, "table name")}
|
|
6723
6785
|
WHERE ${quoteIdent("thread_id", "column name")} = @threadId
|
|
6724
|
-
AND (${quoteIdent("createdAt", "column name")} < @ts OR (${quoteIdent("createdAt", "column name")} = @ts AND id < @id))
|
|
6786
|
+
AND (${quoteIdent("createdAt", "column name")} < @ts OR (${quoteIdent("createdAt", "column name")} = @ts AND id < @id))${resourceCondition}
|
|
6725
6787
|
ORDER BY ${quoteIdent("createdAt", "column name")} DESC, id DESC
|
|
6726
6788
|
LIMIT @lim`,
|
|
6727
6789
|
params: {
|
|
6728
6790
|
threadId,
|
|
6729
6791
|
ts: targetCreatedAt,
|
|
6730
6792
|
id: target.id,
|
|
6731
|
-
lim: withPreviousMessages
|
|
6793
|
+
lim: withPreviousMessages,
|
|
6794
|
+
...resourceParams
|
|
6732
6795
|
},
|
|
6733
6796
|
json: true
|
|
6734
6797
|
});
|
|
@@ -6742,14 +6805,15 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6742
6805
|
sql: `SELECT id, content, role, type, ${quoteIdent("createdAt", "column name")}, ${quoteIdent("thread_id", "column name")} AS threadId, ${quoteIdent("resourceId", "column name")}
|
|
6743
6806
|
FROM ${quoteIdent(TABLE_MESSAGES, "table name")}
|
|
6744
6807
|
WHERE ${quoteIdent("thread_id", "column name")} = @threadId
|
|
6745
|
-
AND (${quoteIdent("createdAt", "column name")} > @ts OR (${quoteIdent("createdAt", "column name")} = @ts AND id > @id))
|
|
6808
|
+
AND (${quoteIdent("createdAt", "column name")} > @ts OR (${quoteIdent("createdAt", "column name")} = @ts AND id > @id))${resourceCondition}
|
|
6746
6809
|
ORDER BY ${quoteIdent("createdAt", "column name")} ASC, id ASC
|
|
6747
6810
|
LIMIT @lim`,
|
|
6748
6811
|
params: {
|
|
6749
6812
|
threadId,
|
|
6750
6813
|
ts: targetCreatedAt,
|
|
6751
6814
|
id: target.id,
|
|
6752
|
-
lim: withNextMessages
|
|
6815
|
+
lim: withNextMessages,
|
|
6816
|
+
...resourceParams
|
|
6753
6817
|
},
|
|
6754
6818
|
json: true
|
|
6755
6819
|
});
|
|
@@ -6802,7 +6866,10 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6802
6866
|
hasMore: false
|
|
6803
6867
|
};
|
|
6804
6868
|
if (perPage === 0 && include && include.length > 0) {
|
|
6805
|
-
const includeMessages = await this.getIncludedMessages({
|
|
6869
|
+
const includeMessages = await this.getIncludedMessages({
|
|
6870
|
+
include,
|
|
6871
|
+
resourceId
|
|
6872
|
+
}) ?? [];
|
|
6806
6873
|
const parsedIncludes = this.parseAndFormatMessages(includeMessages, "v2");
|
|
6807
6874
|
const dirMul = direction === "ASC" ? 1 : -1;
|
|
6808
6875
|
return {
|
|
@@ -6860,7 +6927,10 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6860
6927
|
};
|
|
6861
6928
|
if (include?.length) {
|
|
6862
6929
|
const seen = new Set(messages.map((m) => m.id));
|
|
6863
|
-
(await this.getIncludedMessages({
|
|
6930
|
+
(await this.getIncludedMessages({
|
|
6931
|
+
include,
|
|
6932
|
+
resourceId
|
|
6933
|
+
}))?.forEach((msg) => {
|
|
6864
6934
|
if (!seen.has(msg.id)) {
|
|
6865
6935
|
messages.push(msg);
|
|
6866
6936
|
seen.add(msg.id);
|