@mastra/spanner 1.6.7-alpha.0 → 1.7.0
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 +82 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +14 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -6959,6 +6959,88 @@ var MemorySpanner = class MemorySpanner extends _mastra_core_storage.MemoryStora
|
|
|
6959
6959
|
}, error);
|
|
6960
6960
|
}
|
|
6961
6961
|
}
|
|
6962
|
+
/**
|
|
6963
|
+
* Atomically reassign a thread and all of its messages to a different resource.
|
|
6964
|
+
*
|
|
6965
|
+
* Runs inside a single read-write transaction: the thread row is read inside the
|
|
6966
|
+
* transaction (acquiring a lock), then the thread and every message are moved together.
|
|
6967
|
+
* Overlapping transfers of the same thread serialize on the transaction, so they can never
|
|
6968
|
+
* interleave the thread update with the message update — either both move or neither does,
|
|
6969
|
+
* with no split-ownership window. The thread's `createdAt` is preserved. Callers are
|
|
6970
|
+
* responsible for authorizing the reassignment.
|
|
6971
|
+
*/
|
|
6972
|
+
async updateThreadResourceId({ threadId, resourceId }) {
|
|
6973
|
+
const tableThreads = quoteIdent(_mastra_core_storage.TABLE_THREADS, "table name");
|
|
6974
|
+
const messagesTable = quoteIdent(_mastra_core_storage.TABLE_MESSAGES, "table name");
|
|
6975
|
+
const now = /* @__PURE__ */ new Date();
|
|
6976
|
+
let existingThread = null;
|
|
6977
|
+
let noop = false;
|
|
6978
|
+
try {
|
|
6979
|
+
await this.db.runWithAbortRetry(() => this.database.runTransactionAsync(async (tx) => {
|
|
6980
|
+
try {
|
|
6981
|
+
const [rows] = await tx.run({
|
|
6982
|
+
sql: `SELECT * FROM ${tableThreads} WHERE id = @threadId LIMIT 1`,
|
|
6983
|
+
params: { threadId },
|
|
6984
|
+
json: true
|
|
6985
|
+
});
|
|
6986
|
+
const row = rows[0];
|
|
6987
|
+
if (!row) throw new _mastra_core_error.MastraError({
|
|
6988
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("SPANNER", "UPDATE_THREAD_RESOURCE_ID", "NOT_FOUND"),
|
|
6989
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
6990
|
+
category: _mastra_core_error.ErrorCategory.USER,
|
|
6991
|
+
text: `Thread ${threadId} not found`,
|
|
6992
|
+
details: { threadId }
|
|
6993
|
+
});
|
|
6994
|
+
existingThread = this.formatThreadRow(row);
|
|
6995
|
+
if (existingThread.resourceId === resourceId) {
|
|
6996
|
+
noop = true;
|
|
6997
|
+
await tx.commit();
|
|
6998
|
+
return;
|
|
6999
|
+
}
|
|
7000
|
+
await this.db.update({
|
|
7001
|
+
tableName: _mastra_core_storage.TABLE_THREADS,
|
|
7002
|
+
keys: { id: threadId },
|
|
7003
|
+
data: {
|
|
7004
|
+
resourceId,
|
|
7005
|
+
updatedAt: now
|
|
7006
|
+
},
|
|
7007
|
+
transaction: tx
|
|
7008
|
+
});
|
|
7009
|
+
await tx.runUpdate({
|
|
7010
|
+
sql: `UPDATE ${messagesTable} SET ${quoteIdent("resourceId", "column name")} = @resourceId WHERE ${quoteIdent("thread_id", "column name")} = @threadId`,
|
|
7011
|
+
params: {
|
|
7012
|
+
resourceId,
|
|
7013
|
+
threadId
|
|
7014
|
+
}
|
|
7015
|
+
});
|
|
7016
|
+
await tx.commit();
|
|
7017
|
+
} catch (err) {
|
|
7018
|
+
await tx.rollback().catch((rollbackErr) => {
|
|
7019
|
+
throw new AggregateError([err, rollbackErr], "Transaction and rollback both failed");
|
|
7020
|
+
});
|
|
7021
|
+
throw err;
|
|
7022
|
+
}
|
|
7023
|
+
}));
|
|
7024
|
+
const thread = existingThread;
|
|
7025
|
+
if (noop) return thread;
|
|
7026
|
+
return {
|
|
7027
|
+
...thread,
|
|
7028
|
+
resourceId,
|
|
7029
|
+
updatedAt: now
|
|
7030
|
+
};
|
|
7031
|
+
} catch (error) {
|
|
7032
|
+
if (error instanceof _mastra_core_error.MastraError) throw error;
|
|
7033
|
+
throw new _mastra_core_error.MastraError({
|
|
7034
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("SPANNER", "UPDATE_THREAD_RESOURCE_ID", "FAILED"),
|
|
7035
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
7036
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
|
|
7037
|
+
details: {
|
|
7038
|
+
threadId,
|
|
7039
|
+
resourceId
|
|
7040
|
+
}
|
|
7041
|
+
}, error);
|
|
7042
|
+
}
|
|
7043
|
+
}
|
|
6962
7044
|
/** Deletes a thread and all its messages atomically. */
|
|
6963
7045
|
async deleteThread({ threadId }) {
|
|
6964
7046
|
const messagesTable = quoteIdent(_mastra_core_storage.TABLE_MESSAGES, "table name");
|