@mastra/mssql 0.3.1 → 0.3.2-alpha.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +9 -0
- package/dist/index.cjs +46 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +8 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +8 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/storage/domains/memory/index.ts +60 -0
- package/src/storage/index.ts +12 -0
package/dist/index.js
CHANGED
|
@@ -584,6 +584,46 @@ var MemoryMSSQL = class extends MemoryStorage {
|
|
|
584
584
|
return [];
|
|
585
585
|
}
|
|
586
586
|
}
|
|
587
|
+
async getMessagesById({
|
|
588
|
+
messageIds,
|
|
589
|
+
format
|
|
590
|
+
}) {
|
|
591
|
+
if (messageIds.length === 0) return [];
|
|
592
|
+
const selectStatement = `SELECT seq_id, id, content, role, type, [createdAt], thread_id AS threadId, resourceId`;
|
|
593
|
+
const orderByStatement = `ORDER BY [seq_id] DESC`;
|
|
594
|
+
try {
|
|
595
|
+
let rows = [];
|
|
596
|
+
let query = `${selectStatement} FROM ${getTableName({ indexName: TABLE_MESSAGES, schemaName: getSchemaName(this.schema) })} WHERE [id] IN (${messageIds.map((_, i) => `@id${i}`).join(", ")})`;
|
|
597
|
+
const request = this.pool.request();
|
|
598
|
+
messageIds.forEach((id, i) => request.input(`id${i}`, id));
|
|
599
|
+
query += ` ${orderByStatement}`;
|
|
600
|
+
const result = await request.query(query);
|
|
601
|
+
const remainingRows = result.recordset || [];
|
|
602
|
+
rows.push(...remainingRows);
|
|
603
|
+
rows.sort((a, b) => {
|
|
604
|
+
const timeDiff = a.seq_id - b.seq_id;
|
|
605
|
+
return timeDiff;
|
|
606
|
+
});
|
|
607
|
+
rows = rows.map(({ seq_id, ...rest }) => rest);
|
|
608
|
+
if (format === `v1`) return this._parseAndFormatMessages(rows, format);
|
|
609
|
+
return this._parseAndFormatMessages(rows, `v2`);
|
|
610
|
+
} catch (error) {
|
|
611
|
+
const mastraError = new MastraError(
|
|
612
|
+
{
|
|
613
|
+
id: "MASTRA_STORAGE_MSSQL_STORE_GET_MESSAGES_BY_ID_FAILED",
|
|
614
|
+
domain: ErrorDomain.STORAGE,
|
|
615
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
616
|
+
details: {
|
|
617
|
+
messageIds: JSON.stringify(messageIds)
|
|
618
|
+
}
|
|
619
|
+
},
|
|
620
|
+
error
|
|
621
|
+
);
|
|
622
|
+
this.logger?.error?.(mastraError.toString());
|
|
623
|
+
this.logger?.trackException(mastraError);
|
|
624
|
+
return [];
|
|
625
|
+
}
|
|
626
|
+
}
|
|
587
627
|
async getMessagesPaginated(args) {
|
|
588
628
|
const { threadId, selectBy } = args;
|
|
589
629
|
const { page = 0, perPage: perPageInput } = selectBy?.pagination || {};
|
|
@@ -2183,6 +2223,12 @@ var MSSQLStore = class extends MastraStorage {
|
|
|
2183
2223
|
async getMessages(args) {
|
|
2184
2224
|
return this.stores.memory.getMessages(args);
|
|
2185
2225
|
}
|
|
2226
|
+
async getMessagesById({
|
|
2227
|
+
messageIds,
|
|
2228
|
+
format
|
|
2229
|
+
}) {
|
|
2230
|
+
return this.stores.memory.getMessagesById({ messageIds, format });
|
|
2231
|
+
}
|
|
2186
2232
|
async getMessagesPaginated(args) {
|
|
2187
2233
|
return this.stores.memory.getMessagesPaginated(args);
|
|
2188
2234
|
}
|