@mastra/pg 1.0.0-beta.2 → 1.0.0-beta.4

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,11 +1,11 @@
1
1
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
2
+ import { createVectorErrorId, MastraStorage, createStorageErrorId, StoreOperations, TABLE_SCHEMAS, TABLE_WORKFLOW_SNAPSHOT, TABLE_SPANS, TABLE_THREADS, TABLE_MESSAGES, TABLE_TRACES, TABLE_SCORERS, ScoresStorage, normalizePerPage, calculatePagination, WorkflowsStorage, MemoryStorage, TABLE_RESOURCES, ObservabilityStorage, transformScoreRow as transformScoreRow$1 } from '@mastra/core/storage';
2
3
  import { parseSqlIdentifier, parseFieldKey } from '@mastra/core/utils';
3
4
  import { MastraVector } from '@mastra/core/vector';
4
5
  import { Mutex } from 'async-mutex';
5
6
  import * as pg from 'pg';
6
7
  import xxhash from 'xxhash-wasm';
7
8
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
8
- import { MastraStorage, StoreOperations, TABLE_SCHEMAS, TABLE_WORKFLOW_SNAPSHOT, TABLE_SPANS, TABLE_THREADS, TABLE_MESSAGES, TABLE_TRACES, TABLE_SCORERS, ScoresStorage, normalizePerPage, calculatePagination, WorkflowsStorage, MemoryStorage, TABLE_RESOURCES, ObservabilityStorage, safelyParseJSON } from '@mastra/core/storage';
9
9
  import pgPromise from 'pg-promise';
10
10
  import { MessageList } from '@mastra/core/agent';
11
11
  import { saveScorePayloadSchema } from '@mastra/core/evals';
@@ -550,7 +550,7 @@ var PgVector = class extends MastraVector {
550
550
  } catch (error) {
551
551
  throw new MastraError(
552
552
  {
553
- id: "MASTRA_STORAGE_PG_VECTOR_INITIALIZATION_FAILED",
553
+ id: createVectorErrorId("PG", "INITIALIZATION", "FAILED"),
554
554
  domain: ErrorDomain.MASTRA_VECTOR,
555
555
  category: ErrorCategory.THIRD_PARTY,
556
556
  details: {
@@ -596,9 +596,6 @@ var PgVector = class extends MastraVector {
596
596
  if (this.vectorExtensionSchema === "pg_catalog") {
597
597
  return "vector";
598
598
  }
599
- if (this.vectorExtensionSchema === (this.schema || "public")) {
600
- return "vector";
601
- }
602
599
  const validatedSchema = parseSqlIdentifier(this.vectorExtensionSchema, "vector extension schema");
603
600
  return `${validatedSchema}.vector`;
604
601
  }
@@ -647,7 +644,7 @@ var PgVector = class extends MastraVector {
647
644
  } catch (error) {
648
645
  const mastraError = new MastraError(
649
646
  {
650
- id: "MASTRA_STORAGE_PG_VECTOR_QUERY_INVALID_INPUT",
647
+ id: createVectorErrorId("PG", "QUERY", "INVALID_INPUT"),
651
648
  domain: ErrorDomain.MASTRA_VECTOR,
652
649
  category: ErrorCategory.USER,
653
650
  details: {
@@ -703,7 +700,7 @@ var PgVector = class extends MastraVector {
703
700
  await client.query("ROLLBACK");
704
701
  const mastraError = new MastraError(
705
702
  {
706
- id: "MASTRA_STORAGE_PG_VECTOR_QUERY_FAILED",
703
+ id: createVectorErrorId("PG", "QUERY", "FAILED"),
707
704
  domain: ErrorDomain.MASTRA_VECTOR,
708
705
  category: ErrorCategory.THIRD_PARTY,
709
706
  details: {
@@ -772,7 +769,7 @@ var PgVector = class extends MastraVector {
772
769
  const [, expected, actual] = match;
773
770
  const mastraError2 = new MastraError(
774
771
  {
775
- id: "MASTRA_STORAGE_PG_VECTOR_UPSERT_INVALID_INPUT",
772
+ id: createVectorErrorId("PG", "UPSERT", "INVALID_INPUT"),
776
773
  domain: ErrorDomain.MASTRA_VECTOR,
777
774
  category: ErrorCategory.USER,
778
775
  text: `Vector dimension mismatch: Index "${indexName}" expects ${expected} dimensions but got ${actual} dimensions. Either use a matching embedding model or delete and recreate the index with the new dimension.`,
@@ -790,7 +787,7 @@ var PgVector = class extends MastraVector {
790
787
  }
791
788
  const mastraError = new MastraError(
792
789
  {
793
- id: "MASTRA_STORAGE_PG_VECTOR_UPSERT_FAILED",
790
+ id: createVectorErrorId("PG", "UPSERT", "FAILED"),
794
791
  domain: ErrorDomain.MASTRA_VECTOR,
795
792
  category: ErrorCategory.THIRD_PARTY,
796
793
  details: {
@@ -878,7 +875,7 @@ var PgVector = class extends MastraVector {
878
875
  } catch (error) {
879
876
  const mastraError = new MastraError(
880
877
  {
881
- id: "MASTRA_STORAGE_PG_VECTOR_CREATE_INDEX_INVALID_INPUT",
878
+ id: createVectorErrorId("PG", "CREATE_INDEX", "INVALID_INPUT"),
882
879
  domain: ErrorDomain.MASTRA_VECTOR,
883
880
  category: ErrorCategory.USER,
884
881
  details: {
@@ -928,7 +925,7 @@ var PgVector = class extends MastraVector {
928
925
  }).catch((error) => {
929
926
  const mastraError = new MastraError(
930
927
  {
931
- id: "MASTRA_STORAGE_PG_VECTOR_CREATE_INDEX_FAILED",
928
+ id: createVectorErrorId("PG", "CREATE_INDEX", "FAILED"),
932
929
  domain: ErrorDomain.MASTRA_VECTOR,
933
930
  category: ErrorCategory.THIRD_PARTY,
934
931
  details: {
@@ -948,7 +945,7 @@ var PgVector = class extends MastraVector {
948
945
  } catch (error) {
949
946
  const mastraError = new MastraError(
950
947
  {
951
- id: "MASTRA_STORAGE_PG_VECTOR_BUILD_INDEX_FAILED",
948
+ id: createVectorErrorId("PG", "BUILD_INDEX", "FAILED"),
952
949
  domain: ErrorDomain.MASTRA_VECTOR,
953
950
  category: ErrorCategory.THIRD_PARTY,
954
951
  details: {
@@ -1148,7 +1145,7 @@ var PgVector = class extends MastraVector {
1148
1145
  } catch (e) {
1149
1146
  const mastraError = new MastraError(
1150
1147
  {
1151
- id: "MASTRA_STORAGE_PG_VECTOR_LIST_INDEXES_FAILED",
1148
+ id: createVectorErrorId("PG", "LIST_INDEXES", "FAILED"),
1152
1149
  domain: ErrorDomain.MASTRA_VECTOR,
1153
1150
  category: ErrorCategory.THIRD_PARTY
1154
1151
  },
@@ -1237,7 +1234,7 @@ var PgVector = class extends MastraVector {
1237
1234
  await client.query("ROLLBACK");
1238
1235
  const mastraError = new MastraError(
1239
1236
  {
1240
- id: "MASTRA_STORAGE_PG_VECTOR_DESCRIBE_INDEX_FAILED",
1237
+ id: createVectorErrorId("PG", "DESCRIBE_INDEX", "FAILED"),
1241
1238
  domain: ErrorDomain.MASTRA_VECTOR,
1242
1239
  category: ErrorCategory.THIRD_PARTY,
1243
1240
  details: {
@@ -1262,7 +1259,7 @@ var PgVector = class extends MastraVector {
1262
1259
  await client.query("ROLLBACK");
1263
1260
  const mastraError = new MastraError(
1264
1261
  {
1265
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_INDEX_FAILED",
1262
+ id: createVectorErrorId("PG", "DELETE_INDEX", "FAILED"),
1266
1263
  domain: ErrorDomain.MASTRA_VECTOR,
1267
1264
  category: ErrorCategory.THIRD_PARTY,
1268
1265
  details: {
@@ -1286,7 +1283,7 @@ var PgVector = class extends MastraVector {
1286
1283
  await client.query("ROLLBACK");
1287
1284
  const mastraError = new MastraError(
1288
1285
  {
1289
- id: "MASTRA_STORAGE_PG_VECTOR_TRUNCATE_INDEX_FAILED",
1286
+ id: createVectorErrorId("PG", "TRUNCATE_INDEX", "FAILED"),
1290
1287
  domain: ErrorDomain.MASTRA_VECTOR,
1291
1288
  category: ErrorCategory.THIRD_PARTY,
1292
1289
  details: {
@@ -1328,7 +1325,7 @@ var PgVector = class extends MastraVector {
1328
1325
  }
1329
1326
  if (!id && !filter) {
1330
1327
  throw new MastraError({
1331
- id: "MASTRA_STORAGE_PG_VECTOR_UPDATE_MISSING_PARAMS",
1328
+ id: createVectorErrorId("PG", "UPDATE_VECTOR", "NO_TARGET"),
1332
1329
  text: "Either id or filter must be provided",
1333
1330
  domain: ErrorDomain.MASTRA_VECTOR,
1334
1331
  category: ErrorCategory.USER,
@@ -1337,7 +1334,7 @@ var PgVector = class extends MastraVector {
1337
1334
  }
1338
1335
  if (id && filter) {
1339
1336
  throw new MastraError({
1340
- id: "MASTRA_STORAGE_PG_VECTOR_UPDATE_CONFLICTING_PARAMS",
1337
+ id: createVectorErrorId("PG", "UPDATE_VECTOR", "MUTUALLY_EXCLUSIVE"),
1341
1338
  text: "Cannot provide both id and filter - they are mutually exclusive",
1342
1339
  domain: ErrorDomain.MASTRA_VECTOR,
1343
1340
  category: ErrorCategory.USER,
@@ -1371,7 +1368,7 @@ var PgVector = class extends MastraVector {
1371
1368
  } else {
1372
1369
  if (!filter || Object.keys(filter).length === 0) {
1373
1370
  throw new MastraError({
1374
- id: "MASTRA_STORAGE_PG_VECTOR_UPDATE_EMPTY_FILTER",
1371
+ id: createVectorErrorId("PG", "UPDATE_VECTOR", "EMPTY_FILTER"),
1375
1372
  text: "Cannot update with empty filter",
1376
1373
  domain: ErrorDomain.MASTRA_VECTOR,
1377
1374
  category: ErrorCategory.USER,
@@ -1383,7 +1380,7 @@ var PgVector = class extends MastraVector {
1383
1380
  whereClause = filterQuery.trim().replace(/^WHERE\s+/i, "");
1384
1381
  if (!whereClause) {
1385
1382
  throw new MastraError({
1386
- id: "MASTRA_STORAGE_PG_VECTOR_UPDATE_INVALID_FILTER",
1383
+ id: createVectorErrorId("PG", "UPDATE_VECTOR", "INVALID_FILTER"),
1387
1384
  text: "Filter produced empty WHERE clause",
1388
1385
  domain: ErrorDomain.MASTRA_VECTOR,
1389
1386
  category: ErrorCategory.USER,
@@ -1414,7 +1411,7 @@ var PgVector = class extends MastraVector {
1414
1411
  }
1415
1412
  const mastraError = new MastraError(
1416
1413
  {
1417
- id: "MASTRA_STORAGE_PG_VECTOR_UPDATE_VECTOR_FAILED",
1414
+ id: createVectorErrorId("PG", "UPDATE_VECTOR", "FAILED"),
1418
1415
  domain: ErrorDomain.MASTRA_VECTOR,
1419
1416
  category: ErrorCategory.THIRD_PARTY,
1420
1417
  details: {
@@ -1451,7 +1448,7 @@ var PgVector = class extends MastraVector {
1451
1448
  } catch (error) {
1452
1449
  const mastraError = new MastraError(
1453
1450
  {
1454
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_VECTOR_FAILED",
1451
+ id: createVectorErrorId("PG", "DELETE_VECTOR", "FAILED"),
1455
1452
  domain: ErrorDomain.MASTRA_VECTOR,
1456
1453
  category: ErrorCategory.THIRD_PARTY,
1457
1454
  details: {
@@ -1481,7 +1478,7 @@ var PgVector = class extends MastraVector {
1481
1478
  const { tableName } = this.getTableName(indexName);
1482
1479
  if (!filter && !ids) {
1483
1480
  throw new MastraError({
1484
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_MISSING_PARAMS",
1481
+ id: createVectorErrorId("PG", "DELETE_VECTORS", "NO_TARGET"),
1485
1482
  text: "Either filter or ids must be provided",
1486
1483
  domain: ErrorDomain.MASTRA_VECTOR,
1487
1484
  category: ErrorCategory.USER,
@@ -1490,7 +1487,7 @@ var PgVector = class extends MastraVector {
1490
1487
  }
1491
1488
  if (filter && ids) {
1492
1489
  throw new MastraError({
1493
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_CONFLICTING_PARAMS",
1490
+ id: createVectorErrorId("PG", "DELETE_VECTORS", "MUTUALLY_EXCLUSIVE"),
1494
1491
  text: "Cannot provide both filter and ids - they are mutually exclusive",
1495
1492
  domain: ErrorDomain.MASTRA_VECTOR,
1496
1493
  category: ErrorCategory.USER,
@@ -1502,7 +1499,7 @@ var PgVector = class extends MastraVector {
1502
1499
  if (ids) {
1503
1500
  if (ids.length === 0) {
1504
1501
  throw new MastraError({
1505
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_EMPTY_IDS",
1502
+ id: createVectorErrorId("PG", "DELETE_VECTORS", "EMPTY_IDS"),
1506
1503
  text: "Cannot delete with empty ids array",
1507
1504
  domain: ErrorDomain.MASTRA_VECTOR,
1508
1505
  category: ErrorCategory.USER,
@@ -1515,7 +1512,7 @@ var PgVector = class extends MastraVector {
1515
1512
  } else {
1516
1513
  if (!filter || Object.keys(filter).length === 0) {
1517
1514
  throw new MastraError({
1518
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_EMPTY_FILTER",
1515
+ id: createVectorErrorId("PG", "DELETE_VECTORS", "EMPTY_FILTER"),
1519
1516
  text: "Cannot delete with empty filter. Use deleteIndex to delete all vectors.",
1520
1517
  domain: ErrorDomain.MASTRA_VECTOR,
1521
1518
  category: ErrorCategory.USER,
@@ -1527,7 +1524,7 @@ var PgVector = class extends MastraVector {
1527
1524
  const whereClause = filterQuery.trim().replace(/^WHERE\s+/i, "");
1528
1525
  if (!whereClause) {
1529
1526
  throw new MastraError({
1530
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_INVALID_FILTER",
1527
+ id: createVectorErrorId("PG", "DELETE_VECTORS", "INVALID_FILTER"),
1531
1528
  text: "Filter produced empty WHERE clause",
1532
1529
  domain: ErrorDomain.MASTRA_VECTOR,
1533
1530
  category: ErrorCategory.USER,
@@ -1550,7 +1547,7 @@ var PgVector = class extends MastraVector {
1550
1547
  }
1551
1548
  const mastraError = new MastraError(
1552
1549
  {
1553
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_VECTORS_FAILED",
1550
+ id: createVectorErrorId("PG", "DELETE_VECTORS", "FAILED"),
1554
1551
  domain: ErrorDomain.MASTRA_VECTOR,
1555
1552
  category: ErrorCategory.THIRD_PARTY,
1556
1553
  details: {
@@ -1690,7 +1687,7 @@ var MemoryPG = class extends MemoryStorage {
1690
1687
  } catch (error) {
1691
1688
  throw new MastraError(
1692
1689
  {
1693
- id: "MASTRA_STORAGE_PG_STORE_GET_THREAD_BY_ID_FAILED",
1690
+ id: createStorageErrorId("PG", "GET_THREAD_BY_ID", "FAILED"),
1694
1691
  domain: ErrorDomain.STORAGE,
1695
1692
  category: ErrorCategory.THIRD_PARTY,
1696
1693
  details: {
@@ -1705,7 +1702,7 @@ var MemoryPG = class extends MemoryStorage {
1705
1702
  const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
1706
1703
  if (page < 0) {
1707
1704
  throw new MastraError({
1708
- id: "MASTRA_STORAGE_PG_STORE_INVALID_PAGE",
1705
+ id: createStorageErrorId("PG", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
1709
1706
  domain: ErrorDomain.STORAGE,
1710
1707
  category: ErrorCategory.USER,
1711
1708
  text: "Page number must be non-negative",
@@ -1754,7 +1751,7 @@ var MemoryPG = class extends MemoryStorage {
1754
1751
  } catch (error) {
1755
1752
  const mastraError = new MastraError(
1756
1753
  {
1757
- id: "MASTRA_STORAGE_PG_STORE_LIST_THREADS_BY_RESOURCE_ID_FAILED",
1754
+ id: createStorageErrorId("PG", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
1758
1755
  domain: ErrorDomain.STORAGE,
1759
1756
  category: ErrorCategory.THIRD_PARTY,
1760
1757
  details: {
@@ -1812,7 +1809,7 @@ var MemoryPG = class extends MemoryStorage {
1812
1809
  } catch (error) {
1813
1810
  throw new MastraError(
1814
1811
  {
1815
- id: "MASTRA_STORAGE_PG_STORE_SAVE_THREAD_FAILED",
1812
+ id: createStorageErrorId("PG", "SAVE_THREAD", "FAILED"),
1816
1813
  domain: ErrorDomain.STORAGE,
1817
1814
  category: ErrorCategory.THIRD_PARTY,
1818
1815
  details: {
@@ -1832,7 +1829,7 @@ var MemoryPG = class extends MemoryStorage {
1832
1829
  const existingThread = await this.getThreadById({ threadId: id });
1833
1830
  if (!existingThread) {
1834
1831
  throw new MastraError({
1835
- id: "MASTRA_STORAGE_PG_STORE_UPDATE_THREAD_FAILED",
1832
+ id: createStorageErrorId("PG", "UPDATE_THREAD", "FAILED"),
1836
1833
  domain: ErrorDomain.STORAGE,
1837
1834
  category: ErrorCategory.USER,
1838
1835
  text: `Thread ${id} not found`,
@@ -1870,7 +1867,7 @@ var MemoryPG = class extends MemoryStorage {
1870
1867
  } catch (error) {
1871
1868
  throw new MastraError(
1872
1869
  {
1873
- id: "MASTRA_STORAGE_PG_STORE_UPDATE_THREAD_FAILED",
1870
+ id: createStorageErrorId("PG", "UPDATE_THREAD", "FAILED"),
1874
1871
  domain: ErrorDomain.STORAGE,
1875
1872
  category: ErrorCategory.THIRD_PARTY,
1876
1873
  details: {
@@ -1888,12 +1885,26 @@ var MemoryPG = class extends MemoryStorage {
1888
1885
  const threadTableName = getTableName({ indexName: TABLE_THREADS, schemaName: getSchemaName(this.schema) });
1889
1886
  await this.client.tx(async (t) => {
1890
1887
  await t.none(`DELETE FROM ${tableName} WHERE thread_id = $1`, [threadId]);
1888
+ const schemaName = this.schema || "public";
1889
+ const vectorTables = await t.manyOrNone(
1890
+ `
1891
+ SELECT tablename
1892
+ FROM pg_tables
1893
+ WHERE schemaname = $1
1894
+ AND (tablename = 'memory_messages' OR tablename LIKE 'memory_messages_%')
1895
+ `,
1896
+ [schemaName]
1897
+ );
1898
+ for (const { tablename } of vectorTables) {
1899
+ const vectorTableName = getTableName({ indexName: tablename, schemaName: getSchemaName(this.schema) });
1900
+ await t.none(`DELETE FROM ${vectorTableName} WHERE metadata->>'thread_id' = $1`, [threadId]);
1901
+ }
1891
1902
  await t.none(`DELETE FROM ${threadTableName} WHERE id = $1`, [threadId]);
1892
1903
  });
1893
1904
  } catch (error) {
1894
1905
  throw new MastraError(
1895
1906
  {
1896
- id: "MASTRA_STORAGE_PG_STORE_DELETE_THREAD_FAILED",
1907
+ id: createStorageErrorId("PG", "DELETE_THREAD", "FAILED"),
1897
1908
  domain: ErrorDomain.STORAGE,
1898
1909
  category: ErrorCategory.THIRD_PARTY,
1899
1910
  details: {
@@ -1904,28 +1915,26 @@ var MemoryPG = class extends MemoryStorage {
1904
1915
  );
1905
1916
  }
1906
1917
  }
1907
- async _getIncludedMessages({
1908
- threadId,
1909
- include
1910
- }) {
1911
- if (!threadId.trim()) throw new Error("threadId must be a non-empty string");
1912
- if (!include) return null;
1918
+ async _getIncludedMessages({ include }) {
1919
+ if (!include || include.length === 0) return null;
1913
1920
  const unionQueries = [];
1914
1921
  const params = [];
1915
1922
  let paramIdx = 1;
1916
1923
  const tableName = getTableName({ indexName: TABLE_MESSAGES, schemaName: getSchemaName(this.schema) });
1917
1924
  for (const inc of include) {
1918
1925
  const { id, withPreviousMessages = 0, withNextMessages = 0 } = inc;
1919
- const searchId = inc.threadId || threadId;
1920
1926
  unionQueries.push(
1921
1927
  `
1922
1928
  SELECT * FROM (
1923
- WITH ordered_messages AS (
1929
+ WITH target_thread AS (
1930
+ SELECT thread_id FROM ${tableName} WHERE id = $${paramIdx}
1931
+ ),
1932
+ ordered_messages AS (
1924
1933
  SELECT
1925
1934
  *,
1926
1935
  ROW_NUMBER() OVER (ORDER BY "createdAt" ASC) as row_num
1927
1936
  FROM ${tableName}
1928
- WHERE thread_id = $${paramIdx}
1937
+ WHERE thread_id = (SELECT thread_id FROM target_thread)
1929
1938
  )
1930
1939
  SELECT
1931
1940
  m.id,
@@ -1937,24 +1946,24 @@ var MemoryPG = class extends MemoryStorage {
1937
1946
  m.thread_id AS "threadId",
1938
1947
  m."resourceId"
1939
1948
  FROM ordered_messages m
1940
- WHERE m.id = $${paramIdx + 1}
1949
+ WHERE m.id = $${paramIdx}
1941
1950
  OR EXISTS (
1942
1951
  SELECT 1 FROM ordered_messages target
1943
- WHERE target.id = $${paramIdx + 1}
1952
+ WHERE target.id = $${paramIdx}
1944
1953
  AND (
1945
1954
  -- Get previous messages (messages that come BEFORE the target)
1946
- (m.row_num < target.row_num AND m.row_num >= target.row_num - $${paramIdx + 2})
1955
+ (m.row_num < target.row_num AND m.row_num >= target.row_num - $${paramIdx + 1})
1947
1956
  OR
1948
1957
  -- Get next messages (messages that come AFTER the target)
1949
- (m.row_num > target.row_num AND m.row_num <= target.row_num + $${paramIdx + 3})
1958
+ (m.row_num > target.row_num AND m.row_num <= target.row_num + $${paramIdx + 2})
1950
1959
  )
1951
1960
  )
1952
1961
  ) AS query_${paramIdx}
1953
1962
  `
1954
1963
  // Keep ASC for final sorting after fetching context
1955
1964
  );
1956
- params.push(searchId, id, withPreviousMessages, withNextMessages);
1957
- paramIdx += 4;
1965
+ params.push(id, withPreviousMessages, withNextMessages);
1966
+ paramIdx += 3;
1958
1967
  }
1959
1968
  const finalQuery = unionQueries.join(" UNION ALL ") + ' ORDER BY "createdAt" ASC';
1960
1969
  const includedRows = await this.client.manyOrNone(finalQuery, params);
@@ -2002,7 +2011,7 @@ var MemoryPG = class extends MemoryStorage {
2002
2011
  } catch (error) {
2003
2012
  const mastraError = new MastraError(
2004
2013
  {
2005
- id: "MASTRA_STORAGE_PG_STORE_LIST_MESSAGES_BY_ID_FAILED",
2014
+ id: createStorageErrorId("PG", "LIST_MESSAGES_BY_ID", "FAILED"),
2006
2015
  domain: ErrorDomain.STORAGE,
2007
2016
  category: ErrorCategory.THIRD_PARTY,
2008
2017
  details: {
@@ -2018,25 +2027,28 @@ var MemoryPG = class extends MemoryStorage {
2018
2027
  }
2019
2028
  async listMessages(args) {
2020
2029
  const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
2021
- if (!threadId.trim()) {
2030
+ const threadIds = (Array.isArray(threadId) ? threadId : [threadId]).filter(
2031
+ (id) => typeof id === "string"
2032
+ );
2033
+ if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
2022
2034
  throw new MastraError(
2023
2035
  {
2024
- id: "STORAGE_PG_LIST_MESSAGES_INVALID_THREAD_ID",
2036
+ id: createStorageErrorId("PG", "LIST_MESSAGES", "INVALID_THREAD_ID"),
2025
2037
  domain: ErrorDomain.STORAGE,
2026
2038
  category: ErrorCategory.THIRD_PARTY,
2027
- details: { threadId }
2039
+ details: { threadId: Array.isArray(threadId) ? String(threadId) : String(threadId) }
2028
2040
  },
2029
- new Error("threadId must be a non-empty string")
2041
+ new Error("threadId must be a non-empty string or array of non-empty strings")
2030
2042
  );
2031
2043
  }
2032
2044
  if (page < 0) {
2033
2045
  throw new MastraError({
2034
- id: "MASTRA_STORAGE_PG_STORE_INVALID_PAGE",
2046
+ id: createStorageErrorId("PG", "LIST_MESSAGES", "INVALID_PAGE"),
2035
2047
  domain: ErrorDomain.STORAGE,
2036
2048
  category: ErrorCategory.USER,
2037
2049
  text: "Page number must be non-negative",
2038
2050
  details: {
2039
- threadId,
2051
+ threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
2040
2052
  page
2041
2053
  }
2042
2054
  });
@@ -2048,9 +2060,10 @@ var MemoryPG = class extends MemoryStorage {
2048
2060
  const orderByStatement = `ORDER BY "${field}" ${direction}`;
2049
2061
  const selectStatement = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"`;
2050
2062
  const tableName = getTableName({ indexName: TABLE_MESSAGES, schemaName: getSchemaName(this.schema) });
2051
- const conditions = [`thread_id = $1`];
2052
- const queryParams = [threadId];
2053
- let paramIndex = 2;
2063
+ const threadPlaceholders = threadIds.map((_, i) => `$${i + 1}`).join(", ");
2064
+ const conditions = [`thread_id IN (${threadPlaceholders})`];
2065
+ const queryParams = [...threadIds];
2066
+ let paramIndex = threadIds.length + 1;
2054
2067
  if (resourceId) {
2055
2068
  conditions.push(`"resourceId" = $${paramIndex++}`);
2056
2069
  queryParams.push(resourceId);
@@ -2082,7 +2095,7 @@ var MemoryPG = class extends MemoryStorage {
2082
2095
  }
2083
2096
  const messageIds = new Set(messages.map((m) => m.id));
2084
2097
  if (include && include.length > 0) {
2085
- const includeMessages = await this._getIncludedMessages({ threadId, include });
2098
+ const includeMessages = await this._getIncludedMessages({ include });
2086
2099
  if (includeMessages) {
2087
2100
  for (const includeMsg of includeMessages) {
2088
2101
  if (!messageIds.has(includeMsg.id)) {
@@ -2109,7 +2122,10 @@ var MemoryPG = class extends MemoryStorage {
2109
2122
  }
2110
2123
  return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
2111
2124
  });
2112
- const returnedThreadMessageIds = new Set(finalMessages.filter((m) => m.threadId === threadId).map((m) => m.id));
2125
+ const threadIdSet = new Set(threadIds);
2126
+ const returnedThreadMessageIds = new Set(
2127
+ finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
2128
+ );
2113
2129
  const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
2114
2130
  const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
2115
2131
  return {
@@ -2122,11 +2138,11 @@ var MemoryPG = class extends MemoryStorage {
2122
2138
  } catch (error) {
2123
2139
  const mastraError = new MastraError(
2124
2140
  {
2125
- id: "MASTRA_STORAGE_PG_STORE_LIST_MESSAGES_FAILED",
2141
+ id: createStorageErrorId("PG", "LIST_MESSAGES", "FAILED"),
2126
2142
  domain: ErrorDomain.STORAGE,
2127
2143
  category: ErrorCategory.THIRD_PARTY,
2128
2144
  details: {
2129
- threadId,
2145
+ threadId: Array.isArray(threadId) ? threadId.join(",") : threadId,
2130
2146
  resourceId: resourceId ?? ""
2131
2147
  }
2132
2148
  },
@@ -2148,7 +2164,7 @@ var MemoryPG = class extends MemoryStorage {
2148
2164
  const threadId = messages[0]?.threadId;
2149
2165
  if (!threadId) {
2150
2166
  throw new MastraError({
2151
- id: "MASTRA_STORAGE_PG_STORE_SAVE_MESSAGES_FAILED",
2167
+ id: createStorageErrorId("PG", "SAVE_MESSAGES", "FAILED"),
2152
2168
  domain: ErrorDomain.STORAGE,
2153
2169
  category: ErrorCategory.THIRD_PARTY,
2154
2170
  text: `Thread ID is required`
@@ -2157,7 +2173,7 @@ var MemoryPG = class extends MemoryStorage {
2157
2173
  const thread = await this.getThreadById({ threadId });
2158
2174
  if (!thread) {
2159
2175
  throw new MastraError({
2160
- id: "MASTRA_STORAGE_PG_STORE_SAVE_MESSAGES_FAILED",
2176
+ id: createStorageErrorId("PG", "SAVE_MESSAGES", "FAILED"),
2161
2177
  domain: ErrorDomain.STORAGE,
2162
2178
  category: ErrorCategory.THIRD_PARTY,
2163
2179
  text: `Thread ${threadId} not found`,
@@ -2228,7 +2244,7 @@ var MemoryPG = class extends MemoryStorage {
2228
2244
  } catch (error) {
2229
2245
  throw new MastraError(
2230
2246
  {
2231
- id: "MASTRA_STORAGE_PG_STORE_SAVE_MESSAGES_FAILED",
2247
+ id: createStorageErrorId("PG", "SAVE_MESSAGES", "FAILED"),
2232
2248
  domain: ErrorDomain.STORAGE,
2233
2249
  category: ErrorCategory.THIRD_PARTY,
2234
2250
  details: {
@@ -2357,7 +2373,7 @@ var MemoryPG = class extends MemoryStorage {
2357
2373
  } catch (error) {
2358
2374
  throw new MastraError(
2359
2375
  {
2360
- id: "PG_STORE_DELETE_MESSAGES_FAILED",
2376
+ id: createStorageErrorId("PG", "DELETE_MESSAGES", "FAILED"),
2361
2377
  domain: ErrorDomain.STORAGE,
2362
2378
  category: ErrorCategory.THIRD_PARTY,
2363
2379
  details: { messageIds: messageIds.join(", ") }
@@ -2478,7 +2494,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2478
2494
  } catch (error) {
2479
2495
  throw new MastraError(
2480
2496
  {
2481
- id: "PG_STORE_CREATE_SPAN_FAILED",
2497
+ id: createStorageErrorId("PG", "CREATE_SPAN", "FAILED"),
2482
2498
  domain: ErrorDomain.STORAGE,
2483
2499
  category: ErrorCategory.USER,
2484
2500
  details: {
@@ -2524,7 +2540,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2524
2540
  } catch (error) {
2525
2541
  throw new MastraError(
2526
2542
  {
2527
- id: "PG_STORE_GET_TRACE_FAILED",
2543
+ id: createStorageErrorId("PG", "GET_TRACE", "FAILED"),
2528
2544
  domain: ErrorDomain.STORAGE,
2529
2545
  category: ErrorCategory.USER,
2530
2546
  details: {
@@ -2556,7 +2572,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2556
2572
  } catch (error) {
2557
2573
  throw new MastraError(
2558
2574
  {
2559
- id: "PG_STORE_UPDATE_SPAN_FAILED",
2575
+ id: createStorageErrorId("PG", "UPDATE_SPAN", "FAILED"),
2560
2576
  domain: ErrorDomain.STORAGE,
2561
2577
  category: ErrorCategory.USER,
2562
2578
  details: {
@@ -2592,7 +2608,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2592
2608
  name = `agent run: '${entityId}'`;
2593
2609
  } else {
2594
2610
  const error = new MastraError({
2595
- id: "PG_STORE_GET_TRACES_PAGINATED_FAILED",
2611
+ id: createStorageErrorId("PG", "GET_TRACES_PAGINATED", "INVALID_ENTITY_TYPE"),
2596
2612
  domain: ErrorDomain.STORAGE,
2597
2613
  category: ErrorCategory.USER,
2598
2614
  details: {
@@ -2660,7 +2676,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2660
2676
  } catch (error) {
2661
2677
  throw new MastraError(
2662
2678
  {
2663
- id: "PG_STORE_GET_TRACES_PAGINATED_FAILED",
2679
+ id: createStorageErrorId("PG", "GET_TRACES_PAGINATED", "FAILED"),
2664
2680
  domain: ErrorDomain.STORAGE,
2665
2681
  category: ErrorCategory.USER
2666
2682
  },
@@ -2689,7 +2705,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2689
2705
  } catch (error) {
2690
2706
  throw new MastraError(
2691
2707
  {
2692
- id: "PG_STORE_BATCH_CREATE_SPANS_FAILED",
2708
+ id: createStorageErrorId("PG", "BATCH_CREATE_SPANS", "FAILED"),
2693
2709
  domain: ErrorDomain.STORAGE,
2694
2710
  category: ErrorCategory.USER
2695
2711
  },
@@ -2724,7 +2740,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2724
2740
  } catch (error) {
2725
2741
  throw new MastraError(
2726
2742
  {
2727
- id: "PG_STORE_BATCH_UPDATE_SPANS_FAILED",
2743
+ id: createStorageErrorId("PG", "BATCH_UPDATE_SPANS", "FAILED"),
2728
2744
  domain: ErrorDomain.STORAGE,
2729
2745
  category: ErrorCategory.USER
2730
2746
  },
@@ -2743,7 +2759,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2743
2759
  } catch (error) {
2744
2760
  throw new MastraError(
2745
2761
  {
2746
- id: "PG_STORE_BATCH_DELETE_TRACES_FAILED",
2762
+ id: createStorageErrorId("PG", "BATCH_DELETE_TRACES", "FAILED"),
2747
2763
  domain: ErrorDomain.STORAGE,
2748
2764
  category: ErrorCategory.USER
2749
2765
  },
@@ -2873,7 +2889,7 @@ var StoreOperationsPG = class extends StoreOperations {
2873
2889
  } catch (error) {
2874
2890
  throw new MastraError(
2875
2891
  {
2876
- id: "MASTRA_STORAGE_PG_STORE_INSERT_FAILED",
2892
+ id: createStorageErrorId("PG", "INSERT", "FAILED"),
2877
2893
  domain: ErrorDomain.STORAGE,
2878
2894
  category: ErrorCategory.THIRD_PARTY,
2879
2895
  details: {
@@ -2892,7 +2908,7 @@ var StoreOperationsPG = class extends StoreOperations {
2892
2908
  } catch (error) {
2893
2909
  throw new MastraError(
2894
2910
  {
2895
- id: "MASTRA_STORAGE_PG_STORE_CLEAR_TABLE_FAILED",
2911
+ id: createStorageErrorId("PG", "CLEAR_TABLE", "FAILED"),
2896
2912
  domain: ErrorDomain.STORAGE,
2897
2913
  category: ErrorCategory.THIRD_PARTY,
2898
2914
  details: {
@@ -2965,7 +2981,7 @@ var StoreOperationsPG = class extends StoreOperations {
2965
2981
  } catch (error) {
2966
2982
  throw new MastraError(
2967
2983
  {
2968
- id: "MASTRA_STORAGE_PG_STORE_CREATE_TABLE_FAILED",
2984
+ id: createStorageErrorId("PG", "CREATE_TABLE", "FAILED"),
2969
2985
  domain: ErrorDomain.STORAGE,
2970
2986
  category: ErrorCategory.THIRD_PARTY,
2971
2987
  details: {
@@ -3052,7 +3068,7 @@ var StoreOperationsPG = class extends StoreOperations {
3052
3068
  } catch (error) {
3053
3069
  throw new MastraError(
3054
3070
  {
3055
- id: "MASTRA_STORAGE_PG_STORE_ALTER_TABLE_FAILED",
3071
+ id: createStorageErrorId("PG", "ALTER_TABLE", "FAILED"),
3056
3072
  domain: ErrorDomain.STORAGE,
3057
3073
  category: ErrorCategory.THIRD_PARTY,
3058
3074
  details: {
@@ -3086,7 +3102,7 @@ var StoreOperationsPG = class extends StoreOperations {
3086
3102
  } catch (error) {
3087
3103
  throw new MastraError(
3088
3104
  {
3089
- id: "MASTRA_STORAGE_PG_STORE_LOAD_FAILED",
3105
+ id: createStorageErrorId("PG", "LOAD", "FAILED"),
3090
3106
  domain: ErrorDomain.STORAGE,
3091
3107
  category: ErrorCategory.THIRD_PARTY,
3092
3108
  details: {
@@ -3108,7 +3124,7 @@ var StoreOperationsPG = class extends StoreOperations {
3108
3124
  await this.client.query("ROLLBACK");
3109
3125
  throw new MastraError(
3110
3126
  {
3111
- id: "MASTRA_STORAGE_PG_STORE_BATCH_INSERT_FAILED",
3127
+ id: createStorageErrorId("PG", "BATCH_INSERT", "FAILED"),
3112
3128
  domain: ErrorDomain.STORAGE,
3113
3129
  category: ErrorCategory.THIRD_PARTY,
3114
3130
  details: {
@@ -3128,7 +3144,7 @@ var StoreOperationsPG = class extends StoreOperations {
3128
3144
  } catch (error) {
3129
3145
  throw new MastraError(
3130
3146
  {
3131
- id: "MASTRA_STORAGE_PG_STORE_DROP_TABLE_FAILED",
3147
+ id: createStorageErrorId("PG", "DROP_TABLE", "FAILED"),
3132
3148
  domain: ErrorDomain.STORAGE,
3133
3149
  category: ErrorCategory.THIRD_PARTY,
3134
3150
  details: {
@@ -3201,7 +3217,7 @@ var StoreOperationsPG = class extends StoreOperations {
3201
3217
  }
3202
3218
  throw new MastraError(
3203
3219
  {
3204
- id: "MASTRA_STORAGE_PG_INDEX_CREATE_FAILED",
3220
+ id: createStorageErrorId("PG", "INDEX_CREATE", "FAILED"),
3205
3221
  domain: ErrorDomain.STORAGE,
3206
3222
  category: ErrorCategory.THIRD_PARTY,
3207
3223
  details: {
@@ -3233,7 +3249,7 @@ var StoreOperationsPG = class extends StoreOperations {
3233
3249
  } catch (error) {
3234
3250
  throw new MastraError(
3235
3251
  {
3236
- id: "MASTRA_STORAGE_PG_INDEX_DROP_FAILED",
3252
+ id: createStorageErrorId("PG", "INDEX_DROP", "FAILED"),
3237
3253
  domain: ErrorDomain.STORAGE,
3238
3254
  category: ErrorCategory.THIRD_PARTY,
3239
3255
  details: {
@@ -3309,7 +3325,7 @@ var StoreOperationsPG = class extends StoreOperations {
3309
3325
  } catch (error) {
3310
3326
  throw new MastraError(
3311
3327
  {
3312
- id: "MASTRA_STORAGE_PG_INDEX_LIST_FAILED",
3328
+ id: createStorageErrorId("PG", "INDEX_LIST", "FAILED"),
3313
3329
  domain: ErrorDomain.STORAGE,
3314
3330
  category: ErrorCategory.THIRD_PARTY,
3315
3331
  details: tableName ? {
@@ -3391,7 +3407,7 @@ var StoreOperationsPG = class extends StoreOperations {
3391
3407
  } catch (error) {
3392
3408
  throw new MastraError(
3393
3409
  {
3394
- id: "MASTRA_STORAGE_PG_STORE_CREATE_PERFORMANCE_INDEXES_FAILED",
3410
+ id: createStorageErrorId("PG", "CREATE_AUTOMATIC_INDEXES", "FAILED"),
3395
3411
  domain: ErrorDomain.STORAGE,
3396
3412
  category: ErrorCategory.THIRD_PARTY
3397
3413
  },
@@ -3453,7 +3469,7 @@ var StoreOperationsPG = class extends StoreOperations {
3453
3469
  } catch (error) {
3454
3470
  throw new MastraError(
3455
3471
  {
3456
- id: "MASTRA_STORAGE_PG_INDEX_DESCRIBE_FAILED",
3472
+ id: createStorageErrorId("PG", "INDEX_DESCRIBE", "FAILED"),
3457
3473
  domain: ErrorDomain.STORAGE,
3458
3474
  category: ErrorCategory.THIRD_PARTY,
3459
3475
  details: {
@@ -3498,7 +3514,7 @@ var StoreOperationsPG = class extends StoreOperations {
3498
3514
  } catch (error) {
3499
3515
  throw new MastraError(
3500
3516
  {
3501
- id: "MASTRA_STORAGE_PG_STORE_UPDATE_FAILED",
3517
+ id: createStorageErrorId("PG", "UPDATE", "FAILED"),
3502
3518
  domain: ErrorDomain.STORAGE,
3503
3519
  category: ErrorCategory.THIRD_PARTY,
3504
3520
  details: {
@@ -3526,7 +3542,7 @@ var StoreOperationsPG = class extends StoreOperations {
3526
3542
  await this.client.query("ROLLBACK");
3527
3543
  throw new MastraError(
3528
3544
  {
3529
- id: "MASTRA_STORAGE_PG_STORE_BATCH_UPDATE_FAILED",
3545
+ id: createStorageErrorId("PG", "BATCH_UPDATE", "FAILED"),
3530
3546
  domain: ErrorDomain.STORAGE,
3531
3547
  category: ErrorCategory.THIRD_PARTY,
3532
3548
  details: {
@@ -3567,7 +3583,7 @@ var StoreOperationsPG = class extends StoreOperations {
3567
3583
  } catch (error) {
3568
3584
  throw new MastraError(
3569
3585
  {
3570
- id: "MASTRA_STORAGE_PG_STORE_BATCH_DELETE_FAILED",
3586
+ id: createStorageErrorId("PG", "BATCH_DELETE", "FAILED"),
3571
3587
  domain: ErrorDomain.STORAGE,
3572
3588
  category: ErrorCategory.THIRD_PARTY,
3573
3589
  details: {
@@ -3581,20 +3597,12 @@ var StoreOperationsPG = class extends StoreOperations {
3581
3597
  }
3582
3598
  };
3583
3599
  function transformScoreRow(row) {
3584
- return {
3585
- ...row,
3586
- input: safelyParseJSON(row.input),
3587
- scorer: safelyParseJSON(row.scorer),
3588
- preprocessStepResult: safelyParseJSON(row.preprocessStepResult),
3589
- analyzeStepResult: safelyParseJSON(row.analyzeStepResult),
3590
- metadata: safelyParseJSON(row.metadata),
3591
- output: safelyParseJSON(row.output),
3592
- additionalContext: safelyParseJSON(row.additionalContext),
3593
- requestContext: safelyParseJSON(row.requestContext),
3594
- entity: safelyParseJSON(row.entity),
3595
- createdAt: row.createdAtZ || row.createdAt,
3596
- updatedAt: row.updatedAtZ || row.updatedAt
3597
- };
3600
+ return transformScoreRow$1(row, {
3601
+ preferredTimestampFields: {
3602
+ createdAt: "createdAtZ",
3603
+ updatedAt: "updatedAtZ"
3604
+ }
3605
+ });
3598
3606
  }
3599
3607
  var ScoresPG = class extends ScoresStorage {
3600
3608
  client;
@@ -3620,7 +3628,7 @@ var ScoresPG = class extends ScoresStorage {
3620
3628
  } catch (error) {
3621
3629
  throw new MastraError(
3622
3630
  {
3623
- id: "MASTRA_STORAGE_PG_STORE_GET_SCORE_BY_ID_FAILED",
3631
+ id: createStorageErrorId("PG", "GET_SCORE_BY_ID", "FAILED"),
3624
3632
  domain: ErrorDomain.STORAGE,
3625
3633
  category: ErrorCategory.THIRD_PARTY
3626
3634
  },
@@ -3688,7 +3696,7 @@ var ScoresPG = class extends ScoresStorage {
3688
3696
  } catch (error) {
3689
3697
  throw new MastraError(
3690
3698
  {
3691
- id: "MASTRA_STORAGE_PG_STORE_GET_SCORES_BY_SCORER_ID_FAILED",
3699
+ id: createStorageErrorId("PG", "GET_SCORES_BY_SCORER_ID", "FAILED"),
3692
3700
  domain: ErrorDomain.STORAGE,
3693
3701
  category: ErrorCategory.THIRD_PARTY
3694
3702
  },
@@ -3703,7 +3711,7 @@ var ScoresPG = class extends ScoresStorage {
3703
3711
  } catch (error) {
3704
3712
  throw new MastraError(
3705
3713
  {
3706
- id: "MASTRA_STORAGE_PG_STORE_SAVE_SCORE_FAILED_INVALID_SCORE_PAYLOAD",
3714
+ id: createStorageErrorId("PG", "SAVE_SCORE", "INVALID_PAYLOAD"),
3707
3715
  domain: ErrorDomain.STORAGE,
3708
3716
  category: ErrorCategory.USER,
3709
3717
  details: {
@@ -3741,8 +3749,6 @@ var ScoresPG = class extends ScoresStorage {
3741
3749
  scorer: scorer ? JSON.stringify(scorer) : null,
3742
3750
  preprocessStepResult: preprocessStepResult ? JSON.stringify(preprocessStepResult) : null,
3743
3751
  analyzeStepResult: analyzeStepResult ? JSON.stringify(analyzeStepResult) : null,
3744
- metadata: metadata ? JSON.stringify(metadata) : null,
3745
- additionalContext: additionalContext ? JSON.stringify(additionalContext) : null,
3746
3752
  requestContext: requestContext ? JSON.stringify(requestContext) : null,
3747
3753
  entity: entity ? JSON.stringify(entity) : null,
3748
3754
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -3754,7 +3760,7 @@ var ScoresPG = class extends ScoresStorage {
3754
3760
  } catch (error) {
3755
3761
  throw new MastraError(
3756
3762
  {
3757
- id: "MASTRA_STORAGE_PG_STORE_SAVE_SCORE_FAILED",
3763
+ id: createStorageErrorId("PG", "SAVE_SCORE", "FAILED"),
3758
3764
  domain: ErrorDomain.STORAGE,
3759
3765
  category: ErrorCategory.THIRD_PARTY
3760
3766
  },
@@ -3803,7 +3809,7 @@ var ScoresPG = class extends ScoresStorage {
3803
3809
  } catch (error) {
3804
3810
  throw new MastraError(
3805
3811
  {
3806
- id: "MASTRA_STORAGE_PG_STORE_GET_SCORES_BY_RUN_ID_FAILED",
3812
+ id: createStorageErrorId("PG", "GET_SCORES_BY_RUN_ID", "FAILED"),
3807
3813
  domain: ErrorDomain.STORAGE,
3808
3814
  category: ErrorCategory.THIRD_PARTY
3809
3815
  },
@@ -3853,7 +3859,7 @@ var ScoresPG = class extends ScoresStorage {
3853
3859
  } catch (error) {
3854
3860
  throw new MastraError(
3855
3861
  {
3856
- id: "MASTRA_STORAGE_PG_STORE_GET_SCORES_BY_ENTITY_ID_FAILED",
3862
+ id: createStorageErrorId("PG", "GET_SCORES_BY_ENTITY_ID", "FAILED"),
3857
3863
  domain: ErrorDomain.STORAGE,
3858
3864
  category: ErrorCategory.THIRD_PARTY
3859
3865
  },
@@ -3896,7 +3902,7 @@ var ScoresPG = class extends ScoresStorage {
3896
3902
  } catch (error) {
3897
3903
  throw new MastraError(
3898
3904
  {
3899
- id: "MASTRA_STORAGE_PG_STORE_GET_SCORES_BY_SPAN_FAILED",
3905
+ id: createStorageErrorId("PG", "GET_SCORES_BY_SPAN", "FAILED"),
3900
3906
  domain: ErrorDomain.STORAGE,
3901
3907
  category: ErrorCategory.THIRD_PARTY
3902
3908
  },
@@ -3971,7 +3977,7 @@ var WorkflowsPG = class extends WorkflowsStorage {
3971
3977
  } catch (error) {
3972
3978
  throw new MastraError(
3973
3979
  {
3974
- id: "MASTRA_STORAGE_PG_STORE_PERSIST_WORKFLOW_SNAPSHOT_FAILED",
3980
+ id: createStorageErrorId("PG", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
3975
3981
  domain: ErrorDomain.STORAGE,
3976
3982
  category: ErrorCategory.THIRD_PARTY
3977
3983
  },
@@ -3992,7 +3998,7 @@ var WorkflowsPG = class extends WorkflowsStorage {
3992
3998
  } catch (error) {
3993
3999
  throw new MastraError(
3994
4000
  {
3995
- id: "MASTRA_STORAGE_PG_STORE_LOAD_WORKFLOW_SNAPSHOT_FAILED",
4001
+ id: createStorageErrorId("PG", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
3996
4002
  domain: ErrorDomain.STORAGE,
3997
4003
  category: ErrorCategory.THIRD_PARTY
3998
4004
  },
@@ -4033,7 +4039,7 @@ var WorkflowsPG = class extends WorkflowsStorage {
4033
4039
  } catch (error) {
4034
4040
  throw new MastraError(
4035
4041
  {
4036
- id: "MASTRA_STORAGE_PG_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED",
4042
+ id: createStorageErrorId("PG", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
4037
4043
  domain: ErrorDomain.STORAGE,
4038
4044
  category: ErrorCategory.THIRD_PARTY,
4039
4045
  details: {
@@ -4115,7 +4121,7 @@ var WorkflowsPG = class extends WorkflowsStorage {
4115
4121
  } catch (error) {
4116
4122
  throw new MastraError(
4117
4123
  {
4118
- id: "MASTRA_STORAGE_PG_STORE_LIST_WORKFLOW_RUNS_FAILED",
4124
+ id: createStorageErrorId("PG", "LIST_WORKFLOW_RUNS", "FAILED"),
4119
4125
  domain: ErrorDomain.STORAGE,
4120
4126
  category: ErrorCategory.THIRD_PARTY,
4121
4127
  details: {
@@ -4139,7 +4145,7 @@ var PostgresStore = class extends MastraStorage {
4139
4145
  constructor(config) {
4140
4146
  try {
4141
4147
  validateConfig("PostgresStore", config);
4142
- super({ id: config.id, name: "PostgresStore" });
4148
+ super({ id: config.id, name: "PostgresStore", disableInit: config.disableInit });
4143
4149
  this.schema = config.schemaName || "public";
4144
4150
  if (isConnectionStringConfig(config)) {
4145
4151
  this.#config = {
@@ -4177,7 +4183,7 @@ var PostgresStore = class extends MastraStorage {
4177
4183
  } catch (e) {
4178
4184
  throw new MastraError(
4179
4185
  {
4180
- id: "MASTRA_STORAGE_PG_STORE_INITIALIZATION_FAILED",
4186
+ id: createStorageErrorId("PG", "INITIALIZATION", "FAILED"),
4181
4187
  domain: ErrorDomain.STORAGE,
4182
4188
  category: ErrorCategory.USER
4183
4189
  },
@@ -4215,7 +4221,7 @@ var PostgresStore = class extends MastraStorage {
4215
4221
  this.isConnected = false;
4216
4222
  throw new MastraError(
4217
4223
  {
4218
- id: "MASTRA_STORAGE_POSTGRES_STORE_INIT_FAILED",
4224
+ id: createStorageErrorId("PG", "INIT", "FAILED"),
4219
4225
  domain: ErrorDomain.STORAGE,
4220
4226
  category: ErrorCategory.THIRD_PARTY
4221
4227
  },
@@ -4372,7 +4378,7 @@ var PostgresStore = class extends MastraStorage {
4372
4378
  async createSpan(span) {
4373
4379
  if (!this.stores.observability) {
4374
4380
  throw new MastraError({
4375
- id: "PG_STORE_OBSERVABILITY_NOT_INITIALIZED",
4381
+ id: createStorageErrorId("PG", "OBSERVABILITY", "NOT_INITIALIZED"),
4376
4382
  domain: ErrorDomain.STORAGE,
4377
4383
  category: ErrorCategory.SYSTEM,
4378
4384
  text: "Observability storage is not initialized"
@@ -4387,7 +4393,7 @@ var PostgresStore = class extends MastraStorage {
4387
4393
  }) {
4388
4394
  if (!this.stores.observability) {
4389
4395
  throw new MastraError({
4390
- id: "PG_STORE_OBSERVABILITY_NOT_INITIALIZED",
4396
+ id: createStorageErrorId("PG", "OBSERVABILITY", "NOT_INITIALIZED"),
4391
4397
  domain: ErrorDomain.STORAGE,
4392
4398
  category: ErrorCategory.SYSTEM,
4393
4399
  text: "Observability storage is not initialized"
@@ -4398,7 +4404,7 @@ var PostgresStore = class extends MastraStorage {
4398
4404
  async getTrace(traceId) {
4399
4405
  if (!this.stores.observability) {
4400
4406
  throw new MastraError({
4401
- id: "PG_STORE_OBSERVABILITY_NOT_INITIALIZED",
4407
+ id: createStorageErrorId("PG", "OBSERVABILITY", "NOT_INITIALIZED"),
4402
4408
  domain: ErrorDomain.STORAGE,
4403
4409
  category: ErrorCategory.SYSTEM,
4404
4410
  text: "Observability storage is not initialized"
@@ -4409,7 +4415,7 @@ var PostgresStore = class extends MastraStorage {
4409
4415
  async getTracesPaginated(args) {
4410
4416
  if (!this.stores.observability) {
4411
4417
  throw new MastraError({
4412
- id: "PG_STORE_OBSERVABILITY_NOT_INITIALIZED",
4418
+ id: createStorageErrorId("PG", "OBSERVABILITY", "NOT_INITIALIZED"),
4413
4419
  domain: ErrorDomain.STORAGE,
4414
4420
  category: ErrorCategory.SYSTEM,
4415
4421
  text: "Observability storage is not initialized"
@@ -4420,7 +4426,7 @@ var PostgresStore = class extends MastraStorage {
4420
4426
  async batchCreateSpans(args) {
4421
4427
  if (!this.stores.observability) {
4422
4428
  throw new MastraError({
4423
- id: "PG_STORE_OBSERVABILITY_NOT_INITIALIZED",
4429
+ id: createStorageErrorId("PG", "OBSERVABILITY", "NOT_INITIALIZED"),
4424
4430
  domain: ErrorDomain.STORAGE,
4425
4431
  category: ErrorCategory.SYSTEM,
4426
4432
  text: "Observability storage is not initialized"
@@ -4431,7 +4437,7 @@ var PostgresStore = class extends MastraStorage {
4431
4437
  async batchUpdateSpans(args) {
4432
4438
  if (!this.stores.observability) {
4433
4439
  throw new MastraError({
4434
- id: "PG_STORE_OBSERVABILITY_NOT_INITIALIZED",
4440
+ id: createStorageErrorId("PG", "OBSERVABILITY", "NOT_INITIALIZED"),
4435
4441
  domain: ErrorDomain.STORAGE,
4436
4442
  category: ErrorCategory.SYSTEM,
4437
4443
  text: "Observability storage is not initialized"
@@ -4442,7 +4448,7 @@ var PostgresStore = class extends MastraStorage {
4442
4448
  async batchDeleteTraces(args) {
4443
4449
  if (!this.stores.observability) {
4444
4450
  throw new MastraError({
4445
- id: "PG_STORE_OBSERVABILITY_NOT_INITIALIZED",
4451
+ id: createStorageErrorId("PG", "OBSERVABILITY", "NOT_INITIALIZED"),
4446
4452
  domain: ErrorDomain.STORAGE,
4447
4453
  category: ErrorCategory.SYSTEM,
4448
4454
  text: "Observability storage is not initialized"