@mastra/spanner 1.6.0-alpha.0 → 1.6.0-alpha.2
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 +28 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +29 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -13
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +9 -3
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -6602,7 +6602,7 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6602
6602
|
text: `Thread ${id} not found`,
|
|
6603
6603
|
details: {
|
|
6604
6604
|
threadId: id,
|
|
6605
|
-
title
|
|
6605
|
+
title: title ?? null
|
|
6606
6606
|
}
|
|
6607
6607
|
});
|
|
6608
6608
|
existingThread = this.formatThreadRow(row);
|
|
@@ -6614,7 +6614,7 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6614
6614
|
tableName: TABLE_THREADS,
|
|
6615
6615
|
keys: { id },
|
|
6616
6616
|
data: {
|
|
6617
|
-
title,
|
|
6617
|
+
title: title ?? existingThread.title,
|
|
6618
6618
|
metadata: merged,
|
|
6619
6619
|
updatedAt: now
|
|
6620
6620
|
},
|
|
@@ -6642,7 +6642,7 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6642
6642
|
category: ErrorCategory.THIRD_PARTY,
|
|
6643
6643
|
details: {
|
|
6644
6644
|
threadId: id,
|
|
6645
|
-
title
|
|
6645
|
+
title: title ?? null
|
|
6646
6646
|
}
|
|
6647
6647
|
}, error);
|
|
6648
6648
|
}
|
|
@@ -6737,12 +6737,20 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6737
6737
|
throw mastraError;
|
|
6738
6738
|
}
|
|
6739
6739
|
}
|
|
6740
|
-
/**
|
|
6741
|
-
|
|
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 }) {
|
|
6742
6748
|
if (!include || include.length === 0) return null;
|
|
6749
|
+
const resourceCondition = resourceId ? ` AND ${quoteIdent("resourceId", "column name")} = @scopedResourceId` : "";
|
|
6750
|
+
const resourceParams = resourceId ? { scopedResourceId: resourceId } : {};
|
|
6743
6751
|
const ids = include.map((i) => i.id);
|
|
6744
6752
|
const placeholders = [];
|
|
6745
|
-
const idParams = {};
|
|
6753
|
+
const idParams = { ...resourceParams };
|
|
6746
6754
|
ids.forEach((id, i) => {
|
|
6747
6755
|
const name = `tid${i}`;
|
|
6748
6756
|
placeholders.push(`@${name}`);
|
|
@@ -6750,7 +6758,7 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6750
6758
|
});
|
|
6751
6759
|
const targetsSql = `SELECT id, content, role, type, ${quoteIdent("createdAt", "column name")}, ${quoteIdent("thread_id", "column name")} AS threadId, ${quoteIdent("resourceId", "column name")}
|
|
6752
6760
|
FROM ${quoteIdent(TABLE_MESSAGES, "table name")}
|
|
6753
|
-
WHERE id IN (${placeholders.join(", ")})`;
|
|
6761
|
+
WHERE id IN (${placeholders.join(", ")})${resourceCondition}`;
|
|
6754
6762
|
const [targetRows] = await this.database.run({
|
|
6755
6763
|
sql: targetsSql,
|
|
6756
6764
|
params: idParams,
|
|
@@ -6775,14 +6783,15 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6775
6783
|
sql: `SELECT id, content, role, type, ${quoteIdent("createdAt", "column name")}, ${quoteIdent("thread_id", "column name")} AS threadId, ${quoteIdent("resourceId", "column name")}
|
|
6776
6784
|
FROM ${quoteIdent(TABLE_MESSAGES, "table name")}
|
|
6777
6785
|
WHERE ${quoteIdent("thread_id", "column name")} = @threadId
|
|
6778
|
-
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}
|
|
6779
6787
|
ORDER BY ${quoteIdent("createdAt", "column name")} DESC, id DESC
|
|
6780
6788
|
LIMIT @lim`,
|
|
6781
6789
|
params: {
|
|
6782
6790
|
threadId,
|
|
6783
6791
|
ts: targetCreatedAt,
|
|
6784
6792
|
id: target.id,
|
|
6785
|
-
lim: withPreviousMessages
|
|
6793
|
+
lim: withPreviousMessages,
|
|
6794
|
+
...resourceParams
|
|
6786
6795
|
},
|
|
6787
6796
|
json: true
|
|
6788
6797
|
});
|
|
@@ -6796,14 +6805,15 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6796
6805
|
sql: `SELECT id, content, role, type, ${quoteIdent("createdAt", "column name")}, ${quoteIdent("thread_id", "column name")} AS threadId, ${quoteIdent("resourceId", "column name")}
|
|
6797
6806
|
FROM ${quoteIdent(TABLE_MESSAGES, "table name")}
|
|
6798
6807
|
WHERE ${quoteIdent("thread_id", "column name")} = @threadId
|
|
6799
|
-
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}
|
|
6800
6809
|
ORDER BY ${quoteIdent("createdAt", "column name")} ASC, id ASC
|
|
6801
6810
|
LIMIT @lim`,
|
|
6802
6811
|
params: {
|
|
6803
6812
|
threadId,
|
|
6804
6813
|
ts: targetCreatedAt,
|
|
6805
6814
|
id: target.id,
|
|
6806
|
-
lim: withNextMessages
|
|
6815
|
+
lim: withNextMessages,
|
|
6816
|
+
...resourceParams
|
|
6807
6817
|
},
|
|
6808
6818
|
json: true
|
|
6809
6819
|
});
|
|
@@ -6856,7 +6866,10 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6856
6866
|
hasMore: false
|
|
6857
6867
|
};
|
|
6858
6868
|
if (perPage === 0 && include && include.length > 0) {
|
|
6859
|
-
const includeMessages = await this.getIncludedMessages({
|
|
6869
|
+
const includeMessages = await this.getIncludedMessages({
|
|
6870
|
+
include,
|
|
6871
|
+
resourceId
|
|
6872
|
+
}) ?? [];
|
|
6860
6873
|
const parsedIncludes = this.parseAndFormatMessages(includeMessages, "v2");
|
|
6861
6874
|
const dirMul = direction === "ASC" ? 1 : -1;
|
|
6862
6875
|
return {
|
|
@@ -6914,7 +6927,10 @@ var MemorySpanner = class MemorySpanner extends MemoryStorage {
|
|
|
6914
6927
|
};
|
|
6915
6928
|
if (include?.length) {
|
|
6916
6929
|
const seen = new Set(messages.map((m) => m.id));
|
|
6917
|
-
(await this.getIncludedMessages({
|
|
6930
|
+
(await this.getIncludedMessages({
|
|
6931
|
+
include,
|
|
6932
|
+
resourceId
|
|
6933
|
+
}))?.forEach((msg) => {
|
|
6918
6934
|
if (!seen.has(msg.id)) {
|
|
6919
6935
|
messages.push(msg);
|
|
6920
6936
|
seen.add(msg.id);
|