@mastra/lance 1.1.1-alpha.0 → 1.1.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/dist/index.js CHANGED
@@ -1639,6 +1639,16 @@ var StoreMemoryLance = class extends MemoryStorage {
1639
1639
  throw new Error("Unexpected end of retry loop");
1640
1640
  }
1641
1641
  };
1642
+ function lanceStringLiteral(value) {
1643
+ return `'${value.replaceAll("'", "''")}'`;
1644
+ }
1645
+ function tenancyClause(filters) {
1646
+ const parts = [];
1647
+ if (filters?.organizationId !== void 0)
1648
+ parts.push(`\`organizationId\` = ${lanceStringLiteral(filters.organizationId)}`);
1649
+ if (filters?.projectId !== void 0) parts.push(`\`projectId\` = ${lanceStringLiteral(filters.projectId)}`);
1650
+ return parts.length ? ` AND ${parts.join(" AND ")}` : "";
1651
+ }
1642
1652
  var StoreScoresLance = class extends ScoresStorage {
1643
1653
  client;
1644
1654
  #db;
@@ -1653,7 +1663,7 @@ var StoreScoresLance = class extends ScoresStorage {
1653
1663
  await this.#db.alterTable({
1654
1664
  tableName: TABLE_SCORERS,
1655
1665
  schema: SCORERS_SCHEMA,
1656
- ifNotExists: ["spanId", "requestContext"]
1666
+ ifNotExists: ["spanId", "requestContext", "organizationId", "projectId", "batchId", "datasetId", "datasetItemId"]
1657
1667
  });
1658
1668
  }
1659
1669
  async dangerouslyClearAll() {
@@ -1719,7 +1729,7 @@ var StoreScoresLance = class extends ScoresStorage {
1719
1729
  async getScoreById({ id }) {
1720
1730
  try {
1721
1731
  const table = await this.client.openTable(TABLE_SCORERS);
1722
- const query = table.query().where(`id = '${id}'`).limit(1);
1732
+ const query = table.query().where(`id = ${lanceStringLiteral(id)}`).limit(1);
1723
1733
  const records = await query.toArray();
1724
1734
  if (records.length === 0) return null;
1725
1735
  return await this.transformScoreRow(records[0]);
@@ -1757,33 +1767,33 @@ var StoreScoresLance = class extends ScoresStorage {
1757
1767
  pagination,
1758
1768
  entityId,
1759
1769
  entityType,
1760
- source
1770
+ source,
1771
+ filters
1761
1772
  }) {
1762
1773
  try {
1763
1774
  const { page, perPage: perPageInput } = pagination;
1764
1775
  const perPage = normalizePerPage(perPageInput, 100);
1765
1776
  const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
1766
1777
  const table = await this.client.openTable(TABLE_SCORERS);
1767
- let query = table.query().where(`\`scorerId\` = '${scorerId}'`);
1778
+ const conditions = [`\`scorerId\` = ${lanceStringLiteral(scorerId)}`];
1768
1779
  if (source) {
1769
- query = query.where(`\`source\` = '${source}'`);
1780
+ conditions.push(`\`source\` = ${lanceStringLiteral(source)}`);
1770
1781
  }
1771
1782
  if (entityId) {
1772
- query = query.where(`\`entityId\` = '${entityId}'`);
1783
+ conditions.push(`\`entityId\` = ${lanceStringLiteral(entityId)}`);
1773
1784
  }
1774
1785
  if (entityType) {
1775
- query = query.where(`\`entityType\` = '${entityType}'`);
1776
- }
1777
- let totalQuery = table.query().where(`\`scorerId\` = '${scorerId}'`);
1778
- if (source) {
1779
- totalQuery = totalQuery.where(`\`source\` = '${source}'`);
1786
+ conditions.push(`\`entityType\` = ${lanceStringLiteral(entityType)}`);
1780
1787
  }
1781
- if (entityId) {
1782
- totalQuery = totalQuery.where(`\`entityId\` = '${entityId}'`);
1788
+ if (filters?.organizationId !== void 0) {
1789
+ conditions.push(`\`organizationId\` = ${lanceStringLiteral(filters.organizationId)}`);
1783
1790
  }
1784
- if (entityType) {
1785
- totalQuery = totalQuery.where(`\`entityType\` = '${entityType}'`);
1791
+ if (filters?.projectId !== void 0) {
1792
+ conditions.push(`\`projectId\` = ${lanceStringLiteral(filters.projectId)}`);
1786
1793
  }
1794
+ const whereClause = conditions.join(" AND ");
1795
+ let query = table.query().where(whereClause);
1796
+ const totalQuery = table.query().where(whereClause);
1787
1797
  const allRecords = await totalQuery.toArray();
1788
1798
  const total = allRecords.length;
1789
1799
  const end = perPageInput === false ? total : start + perPage;
@@ -1817,17 +1827,18 @@ var StoreScoresLance = class extends ScoresStorage {
1817
1827
  }
1818
1828
  async listScoresByRunId({
1819
1829
  runId,
1820
- pagination
1830
+ pagination,
1831
+ filters
1821
1832
  }) {
1822
1833
  try {
1823
1834
  const { page, perPage: perPageInput } = pagination;
1824
1835
  const perPage = normalizePerPage(perPageInput, 100);
1825
1836
  const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
1826
1837
  const table = await this.client.openTable(TABLE_SCORERS);
1827
- const allRecords = await table.query().where(`\`runId\` = '${runId}'`).toArray();
1838
+ const allRecords = await table.query().where(`\`runId\` = ${lanceStringLiteral(runId)}${tenancyClause(filters)}`).toArray();
1828
1839
  const total = allRecords.length;
1829
1840
  const end = perPageInput === false ? total : start + perPage;
1830
- let query = table.query().where(`\`runId\` = '${runId}'`);
1841
+ let query = table.query().where(`\`runId\` = ${lanceStringLiteral(runId)}${tenancyClause(filters)}`);
1831
1842
  if (perPageInput !== false) {
1832
1843
  query = query.limit(perPage);
1833
1844
  if (start > 0) query = query.offset(start);
@@ -1859,17 +1870,22 @@ var StoreScoresLance = class extends ScoresStorage {
1859
1870
  async listScoresByEntityId({
1860
1871
  entityId,
1861
1872
  entityType,
1862
- pagination
1873
+ pagination,
1874
+ filters
1863
1875
  }) {
1864
1876
  try {
1865
1877
  const { page, perPage: perPageInput } = pagination;
1866
1878
  const perPage = normalizePerPage(perPageInput, 100);
1867
1879
  const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
1868
1880
  const table = await this.client.openTable(TABLE_SCORERS);
1869
- const allRecords = await table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`).toArray();
1881
+ const allRecords = await table.query().where(
1882
+ `\`entityId\` = ${lanceStringLiteral(entityId)} AND \`entityType\` = ${lanceStringLiteral(entityType)}${tenancyClause(filters)}`
1883
+ ).toArray();
1870
1884
  const total = allRecords.length;
1871
1885
  const end = perPageInput === false ? total : start + perPage;
1872
- let query = table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`);
1886
+ let query = table.query().where(
1887
+ `\`entityId\` = ${lanceStringLiteral(entityId)} AND \`entityType\` = ${lanceStringLiteral(entityType)}${tenancyClause(filters)}`
1888
+ );
1873
1889
  if (perPageInput !== false) {
1874
1890
  query = query.limit(perPage);
1875
1891
  if (start > 0) query = query.offset(start);
@@ -1901,17 +1917,22 @@ var StoreScoresLance = class extends ScoresStorage {
1901
1917
  async listScoresBySpan({
1902
1918
  traceId,
1903
1919
  spanId,
1904
- pagination
1920
+ pagination,
1921
+ filters
1905
1922
  }) {
1906
1923
  try {
1907
1924
  const { page, perPage: perPageInput } = pagination;
1908
1925
  const perPage = normalizePerPage(perPageInput, 100);
1909
1926
  const { offset: start, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
1910
1927
  const table = await this.client.openTable(TABLE_SCORERS);
1911
- const allRecords = await table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).toArray();
1928
+ const allRecords = await table.query().where(
1929
+ `\`traceId\` = ${lanceStringLiteral(traceId)} AND \`spanId\` = ${lanceStringLiteral(spanId)}${tenancyClause(filters)}`
1930
+ ).toArray();
1912
1931
  const total = allRecords.length;
1913
1932
  const end = perPageInput === false ? total : start + perPage;
1914
- let query = table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`);
1933
+ let query = table.query().where(
1934
+ `\`traceId\` = ${lanceStringLiteral(traceId)} AND \`spanId\` = ${lanceStringLiteral(spanId)}${tenancyClause(filters)}`
1935
+ );
1915
1936
  if (perPageInput !== false) {
1916
1937
  query = query.limit(perPage);
1917
1938
  if (start > 0) query = query.offset(start);