@mastra/mssql 0.0.0-fix-model-router-machine-cache-20251021232825 → 0.0.0-fix-memory-search-fetch-20251027160505

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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
2
- import { MastraStorage, LegacyEvalsStorage, StoreOperations, TABLE_WORKFLOW_SNAPSHOT, ScoresStorage, TABLE_SCORERS, TracesStorage, TABLE_TRACES, WorkflowsStorage, MemoryStorage, resolveMessageLimit, TABLE_RESOURCES, TABLE_EVALS, TABLE_THREADS, TABLE_MESSAGES } from '@mastra/core/storage';
2
+ import { MastraStorage, LegacyEvalsStorage, StoreOperations, TABLE_WORKFLOW_SNAPSHOT, ScoresStorage, TABLE_SCORERS, WorkflowsStorage, MemoryStorage, resolveMessageLimit, TABLE_RESOURCES, TABLE_EVALS, TABLE_THREADS, TABLE_MESSAGES } from '@mastra/core/storage';
3
3
  import sql2 from 'mssql';
4
- import { parseSqlIdentifier, parseFieldKey } from '@mastra/core/utils';
4
+ import { parseSqlIdentifier } from '@mastra/core/utils';
5
5
  import { MessageList } from '@mastra/core/agent';
6
6
  import { saveScorePayloadSchema } from '@mastra/core/scores';
7
7
 
@@ -194,7 +194,7 @@ var MemoryMSSQL = class extends MemoryStorage {
194
194
  }
195
195
  async getThreadById({ threadId }) {
196
196
  try {
197
- const sql7 = `SELECT
197
+ const sql6 = `SELECT
198
198
  id,
199
199
  [resourceId],
200
200
  title,
@@ -205,7 +205,7 @@ var MemoryMSSQL = class extends MemoryStorage {
205
205
  WHERE id = @threadId`;
206
206
  const request = this.pool.request();
207
207
  request.input("threadId", threadId);
208
- const resultSet = await request.query(sql7);
208
+ const resultSet = await request.query(sql6);
209
209
  const thread = resultSet.recordset[0] || null;
210
210
  if (!thread) {
211
211
  return null;
@@ -378,7 +378,7 @@ var MemoryMSSQL = class extends MemoryStorage {
378
378
  };
379
379
  try {
380
380
  const table = getTableName({ indexName: TABLE_THREADS, schemaName: getSchemaName(this.schema) });
381
- const sql7 = `UPDATE ${table}
381
+ const sql6 = `UPDATE ${table}
382
382
  SET title = @title,
383
383
  metadata = @metadata,
384
384
  [updatedAt] = @updatedAt
@@ -389,7 +389,7 @@ var MemoryMSSQL = class extends MemoryStorage {
389
389
  req.input("title", title);
390
390
  req.input("metadata", JSON.stringify(mergedMetadata));
391
391
  req.input("updatedAt", /* @__PURE__ */ new Date());
392
- const result = await req.query(sql7);
392
+ const result = await req.query(sql6);
393
393
  let thread = result.recordset && result.recordset[0];
394
394
  if (thread && "seq_id" in thread) {
395
395
  const { seq_id, ...rest } = thread;
@@ -1338,12 +1338,12 @@ ${columns}
1338
1338
  const keyEntries = Object.entries(keys).map(([key, value]) => [parseSqlIdentifier(key, "column name"), value]);
1339
1339
  const conditions = keyEntries.map(([key], i) => `[${key}] = @param${i}`).join(" AND ");
1340
1340
  const values = keyEntries.map(([_, value]) => value);
1341
- const sql7 = `SELECT * FROM ${getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })} WHERE ${conditions}`;
1341
+ const sql6 = `SELECT * FROM ${getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })} WHERE ${conditions}`;
1342
1342
  const request = this.pool.request();
1343
1343
  values.forEach((value, i) => {
1344
1344
  request.input(`param${i}`, value);
1345
1345
  });
1346
- const resultSet = await request.query(sql7);
1346
+ const resultSet = await request.query(sql6);
1347
1347
  const result = resultSet.recordset[0] || null;
1348
1348
  if (!result) {
1349
1349
  return null;
@@ -1740,173 +1740,6 @@ var ScoresMSSQL = class extends ScoresStorage {
1740
1740
  }
1741
1741
  }
1742
1742
  };
1743
- var TracesMSSQL = class extends TracesStorage {
1744
- pool;
1745
- operations;
1746
- schema;
1747
- constructor({
1748
- pool,
1749
- operations,
1750
- schema
1751
- }) {
1752
- super();
1753
- this.pool = pool;
1754
- this.operations = operations;
1755
- this.schema = schema;
1756
- }
1757
- /** @deprecated use getTracesPaginated instead*/
1758
- async getTraces(args) {
1759
- if (args.fromDate || args.toDate) {
1760
- args.dateRange = {
1761
- start: args.fromDate,
1762
- end: args.toDate
1763
- };
1764
- }
1765
- const result = await this.getTracesPaginated(args);
1766
- return result.traces;
1767
- }
1768
- async getTracesPaginated(args) {
1769
- const { name, scope, page = 0, perPage: perPageInput, attributes, filters, dateRange } = args;
1770
- const fromDate = dateRange?.start;
1771
- const toDate = dateRange?.end;
1772
- const perPage = perPageInput !== void 0 ? perPageInput : 100;
1773
- const currentOffset = page * perPage;
1774
- const paramMap = {};
1775
- const conditions = [];
1776
- let paramIndex = 1;
1777
- if (name) {
1778
- const paramName = `p${paramIndex++}`;
1779
- conditions.push(`[name] LIKE @${paramName}`);
1780
- paramMap[paramName] = `${name}%`;
1781
- }
1782
- if (scope) {
1783
- const paramName = `p${paramIndex++}`;
1784
- conditions.push(`[scope] = @${paramName}`);
1785
- paramMap[paramName] = scope;
1786
- }
1787
- if (attributes) {
1788
- Object.entries(attributes).forEach(([key, value]) => {
1789
- const parsedKey = parseFieldKey(key);
1790
- const paramName = `p${paramIndex++}`;
1791
- conditions.push(`JSON_VALUE([attributes], '$.${parsedKey}') = @${paramName}`);
1792
- paramMap[paramName] = value;
1793
- });
1794
- }
1795
- if (filters) {
1796
- Object.entries(filters).forEach(([key, value]) => {
1797
- const parsedKey = parseFieldKey(key);
1798
- const paramName = `p${paramIndex++}`;
1799
- conditions.push(`[${parsedKey}] = @${paramName}`);
1800
- paramMap[paramName] = value;
1801
- });
1802
- }
1803
- if (fromDate instanceof Date && !isNaN(fromDate.getTime())) {
1804
- const paramName = `p${paramIndex++}`;
1805
- conditions.push(`[createdAt] >= @${paramName}`);
1806
- paramMap[paramName] = fromDate.toISOString();
1807
- }
1808
- if (toDate instanceof Date && !isNaN(toDate.getTime())) {
1809
- const paramName = `p${paramIndex++}`;
1810
- conditions.push(`[createdAt] <= @${paramName}`);
1811
- paramMap[paramName] = toDate.toISOString();
1812
- }
1813
- const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
1814
- const countQuery = `SELECT COUNT(*) as total FROM ${getTableName({ indexName: TABLE_TRACES, schemaName: getSchemaName(this.schema) })} ${whereClause}`;
1815
- let total = 0;
1816
- try {
1817
- const countRequest = this.pool.request();
1818
- Object.entries(paramMap).forEach(([key, value]) => {
1819
- if (value instanceof Date) {
1820
- countRequest.input(key, sql2.DateTime, value);
1821
- } else {
1822
- countRequest.input(key, value);
1823
- }
1824
- });
1825
- const countResult = await countRequest.query(countQuery);
1826
- total = parseInt(countResult.recordset[0].total, 10);
1827
- } catch (error) {
1828
- throw new MastraError(
1829
- {
1830
- id: "MASTRA_STORAGE_MSSQL_STORE_GET_TRACES_PAGINATED_FAILED_TO_RETRIEVE_TOTAL_COUNT",
1831
- domain: ErrorDomain.STORAGE,
1832
- category: ErrorCategory.THIRD_PARTY,
1833
- details: {
1834
- name: args.name ?? "",
1835
- scope: args.scope ?? ""
1836
- }
1837
- },
1838
- error
1839
- );
1840
- }
1841
- if (total === 0) {
1842
- return {
1843
- traces: [],
1844
- total: 0,
1845
- page,
1846
- perPage,
1847
- hasMore: false
1848
- };
1849
- }
1850
- const dataQuery = `SELECT * FROM ${getTableName({ indexName: TABLE_TRACES, schemaName: getSchemaName(this.schema) })} ${whereClause} ORDER BY [seq_id] DESC OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY`;
1851
- const dataRequest = this.pool.request();
1852
- Object.entries(paramMap).forEach(([key, value]) => {
1853
- if (value instanceof Date) {
1854
- dataRequest.input(key, sql2.DateTime, value);
1855
- } else {
1856
- dataRequest.input(key, value);
1857
- }
1858
- });
1859
- dataRequest.input("offset", currentOffset);
1860
- dataRequest.input("limit", perPage);
1861
- try {
1862
- const rowsResult = await dataRequest.query(dataQuery);
1863
- const rows = rowsResult.recordset;
1864
- const traces = rows.map((row) => ({
1865
- id: row.id,
1866
- parentSpanId: row.parentSpanId,
1867
- traceId: row.traceId,
1868
- name: row.name,
1869
- scope: row.scope,
1870
- kind: row.kind,
1871
- status: JSON.parse(row.status),
1872
- events: JSON.parse(row.events),
1873
- links: JSON.parse(row.links),
1874
- attributes: JSON.parse(row.attributes),
1875
- startTime: row.startTime,
1876
- endTime: row.endTime,
1877
- other: row.other,
1878
- createdAt: row.createdAt
1879
- }));
1880
- return {
1881
- traces,
1882
- total,
1883
- page,
1884
- perPage,
1885
- hasMore: currentOffset + traces.length < total
1886
- };
1887
- } catch (error) {
1888
- throw new MastraError(
1889
- {
1890
- id: "MASTRA_STORAGE_MSSQL_STORE_GET_TRACES_PAGINATED_FAILED_TO_RETRIEVE_TRACES",
1891
- domain: ErrorDomain.STORAGE,
1892
- category: ErrorCategory.THIRD_PARTY,
1893
- details: {
1894
- name: args.name ?? "",
1895
- scope: args.scope ?? ""
1896
- }
1897
- },
1898
- error
1899
- );
1900
- }
1901
- }
1902
- async batchTraceInsert({ records }) {
1903
- this.logger.debug("Batch inserting traces", { count: records.length });
1904
- await this.operations.batchInsert({
1905
- tableName: TABLE_TRACES,
1906
- records
1907
- });
1908
- }
1909
- };
1910
1743
  function parseWorkflowRun(row) {
1911
1744
  let parsedSnapshot = row.snapshot;
1912
1745
  if (typeof parsedSnapshot === "string") {
@@ -2173,13 +2006,11 @@ var MSSQLStore = class extends MastraStorage {
2173
2006
  const legacyEvals = new LegacyEvalsMSSQL({ pool: this.pool, schema: this.schema });
2174
2007
  const operations = new StoreOperationsMSSQL({ pool: this.pool, schemaName: this.schema });
2175
2008
  const scores = new ScoresMSSQL({ pool: this.pool, operations, schema: this.schema });
2176
- const traces = new TracesMSSQL({ pool: this.pool, operations, schema: this.schema });
2177
2009
  const workflows = new WorkflowsMSSQL({ pool: this.pool, operations, schema: this.schema });
2178
2010
  const memory = new MemoryMSSQL({ pool: this.pool, schema: this.schema, operations });
2179
2011
  this.stores = {
2180
2012
  operations,
2181
2013
  scores,
2182
- traces,
2183
2014
  workflows,
2184
2015
  legacyEvals,
2185
2016
  memory
@@ -2239,18 +2070,6 @@ var MSSQLStore = class extends MastraStorage {
2239
2070
  async getEvals(options = {}) {
2240
2071
  return this.stores.legacyEvals.getEvals(options);
2241
2072
  }
2242
- /**
2243
- * @deprecated use getTracesPaginated instead
2244
- */
2245
- async getTraces(args) {
2246
- return this.stores.traces.getTraces(args);
2247
- }
2248
- async getTracesPaginated(args) {
2249
- return this.stores.traces.getTracesPaginated(args);
2250
- }
2251
- async batchTraceInsert({ records }) {
2252
- return this.stores.traces.batchTraceInsert({ records });
2253
- }
2254
2073
  async createTable({
2255
2074
  tableName,
2256
2075
  schema