@mastra/pg 1.0.0-beta.3 → 1.0.0-beta.5

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, transformScoreRow as transformScoreRow$1 } 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: {
@@ -644,7 +644,7 @@ var PgVector = class extends MastraVector {
644
644
  } catch (error) {
645
645
  const mastraError = new MastraError(
646
646
  {
647
- id: "MASTRA_STORAGE_PG_VECTOR_QUERY_INVALID_INPUT",
647
+ id: createVectorErrorId("PG", "QUERY", "INVALID_INPUT"),
648
648
  domain: ErrorDomain.MASTRA_VECTOR,
649
649
  category: ErrorCategory.USER,
650
650
  details: {
@@ -700,7 +700,7 @@ var PgVector = class extends MastraVector {
700
700
  await client.query("ROLLBACK");
701
701
  const mastraError = new MastraError(
702
702
  {
703
- id: "MASTRA_STORAGE_PG_VECTOR_QUERY_FAILED",
703
+ id: createVectorErrorId("PG", "QUERY", "FAILED"),
704
704
  domain: ErrorDomain.MASTRA_VECTOR,
705
705
  category: ErrorCategory.THIRD_PARTY,
706
706
  details: {
@@ -769,7 +769,7 @@ var PgVector = class extends MastraVector {
769
769
  const [, expected, actual] = match;
770
770
  const mastraError2 = new MastraError(
771
771
  {
772
- id: "MASTRA_STORAGE_PG_VECTOR_UPSERT_INVALID_INPUT",
772
+ id: createVectorErrorId("PG", "UPSERT", "INVALID_INPUT"),
773
773
  domain: ErrorDomain.MASTRA_VECTOR,
774
774
  category: ErrorCategory.USER,
775
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.`,
@@ -787,7 +787,7 @@ var PgVector = class extends MastraVector {
787
787
  }
788
788
  const mastraError = new MastraError(
789
789
  {
790
- id: "MASTRA_STORAGE_PG_VECTOR_UPSERT_FAILED",
790
+ id: createVectorErrorId("PG", "UPSERT", "FAILED"),
791
791
  domain: ErrorDomain.MASTRA_VECTOR,
792
792
  category: ErrorCategory.THIRD_PARTY,
793
793
  details: {
@@ -875,7 +875,7 @@ var PgVector = class extends MastraVector {
875
875
  } catch (error) {
876
876
  const mastraError = new MastraError(
877
877
  {
878
- id: "MASTRA_STORAGE_PG_VECTOR_CREATE_INDEX_INVALID_INPUT",
878
+ id: createVectorErrorId("PG", "CREATE_INDEX", "INVALID_INPUT"),
879
879
  domain: ErrorDomain.MASTRA_VECTOR,
880
880
  category: ErrorCategory.USER,
881
881
  details: {
@@ -925,7 +925,7 @@ var PgVector = class extends MastraVector {
925
925
  }).catch((error) => {
926
926
  const mastraError = new MastraError(
927
927
  {
928
- id: "MASTRA_STORAGE_PG_VECTOR_CREATE_INDEX_FAILED",
928
+ id: createVectorErrorId("PG", "CREATE_INDEX", "FAILED"),
929
929
  domain: ErrorDomain.MASTRA_VECTOR,
930
930
  category: ErrorCategory.THIRD_PARTY,
931
931
  details: {
@@ -945,7 +945,7 @@ var PgVector = class extends MastraVector {
945
945
  } catch (error) {
946
946
  const mastraError = new MastraError(
947
947
  {
948
- id: "MASTRA_STORAGE_PG_VECTOR_BUILD_INDEX_FAILED",
948
+ id: createVectorErrorId("PG", "BUILD_INDEX", "FAILED"),
949
949
  domain: ErrorDomain.MASTRA_VECTOR,
950
950
  category: ErrorCategory.THIRD_PARTY,
951
951
  details: {
@@ -1145,7 +1145,7 @@ var PgVector = class extends MastraVector {
1145
1145
  } catch (e) {
1146
1146
  const mastraError = new MastraError(
1147
1147
  {
1148
- id: "MASTRA_STORAGE_PG_VECTOR_LIST_INDEXES_FAILED",
1148
+ id: createVectorErrorId("PG", "LIST_INDEXES", "FAILED"),
1149
1149
  domain: ErrorDomain.MASTRA_VECTOR,
1150
1150
  category: ErrorCategory.THIRD_PARTY
1151
1151
  },
@@ -1234,7 +1234,7 @@ var PgVector = class extends MastraVector {
1234
1234
  await client.query("ROLLBACK");
1235
1235
  const mastraError = new MastraError(
1236
1236
  {
1237
- id: "MASTRA_STORAGE_PG_VECTOR_DESCRIBE_INDEX_FAILED",
1237
+ id: createVectorErrorId("PG", "DESCRIBE_INDEX", "FAILED"),
1238
1238
  domain: ErrorDomain.MASTRA_VECTOR,
1239
1239
  category: ErrorCategory.THIRD_PARTY,
1240
1240
  details: {
@@ -1259,7 +1259,7 @@ var PgVector = class extends MastraVector {
1259
1259
  await client.query("ROLLBACK");
1260
1260
  const mastraError = new MastraError(
1261
1261
  {
1262
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_INDEX_FAILED",
1262
+ id: createVectorErrorId("PG", "DELETE_INDEX", "FAILED"),
1263
1263
  domain: ErrorDomain.MASTRA_VECTOR,
1264
1264
  category: ErrorCategory.THIRD_PARTY,
1265
1265
  details: {
@@ -1283,7 +1283,7 @@ var PgVector = class extends MastraVector {
1283
1283
  await client.query("ROLLBACK");
1284
1284
  const mastraError = new MastraError(
1285
1285
  {
1286
- id: "MASTRA_STORAGE_PG_VECTOR_TRUNCATE_INDEX_FAILED",
1286
+ id: createVectorErrorId("PG", "TRUNCATE_INDEX", "FAILED"),
1287
1287
  domain: ErrorDomain.MASTRA_VECTOR,
1288
1288
  category: ErrorCategory.THIRD_PARTY,
1289
1289
  details: {
@@ -1325,7 +1325,7 @@ var PgVector = class extends MastraVector {
1325
1325
  }
1326
1326
  if (!id && !filter) {
1327
1327
  throw new MastraError({
1328
- id: "MASTRA_STORAGE_PG_VECTOR_UPDATE_MISSING_PARAMS",
1328
+ id: createVectorErrorId("PG", "UPDATE_VECTOR", "NO_TARGET"),
1329
1329
  text: "Either id or filter must be provided",
1330
1330
  domain: ErrorDomain.MASTRA_VECTOR,
1331
1331
  category: ErrorCategory.USER,
@@ -1334,7 +1334,7 @@ var PgVector = class extends MastraVector {
1334
1334
  }
1335
1335
  if (id && filter) {
1336
1336
  throw new MastraError({
1337
- id: "MASTRA_STORAGE_PG_VECTOR_UPDATE_CONFLICTING_PARAMS",
1337
+ id: createVectorErrorId("PG", "UPDATE_VECTOR", "MUTUALLY_EXCLUSIVE"),
1338
1338
  text: "Cannot provide both id and filter - they are mutually exclusive",
1339
1339
  domain: ErrorDomain.MASTRA_VECTOR,
1340
1340
  category: ErrorCategory.USER,
@@ -1368,7 +1368,7 @@ var PgVector = class extends MastraVector {
1368
1368
  } else {
1369
1369
  if (!filter || Object.keys(filter).length === 0) {
1370
1370
  throw new MastraError({
1371
- id: "MASTRA_STORAGE_PG_VECTOR_UPDATE_EMPTY_FILTER",
1371
+ id: createVectorErrorId("PG", "UPDATE_VECTOR", "EMPTY_FILTER"),
1372
1372
  text: "Cannot update with empty filter",
1373
1373
  domain: ErrorDomain.MASTRA_VECTOR,
1374
1374
  category: ErrorCategory.USER,
@@ -1380,7 +1380,7 @@ var PgVector = class extends MastraVector {
1380
1380
  whereClause = filterQuery.trim().replace(/^WHERE\s+/i, "");
1381
1381
  if (!whereClause) {
1382
1382
  throw new MastraError({
1383
- id: "MASTRA_STORAGE_PG_VECTOR_UPDATE_INVALID_FILTER",
1383
+ id: createVectorErrorId("PG", "UPDATE_VECTOR", "INVALID_FILTER"),
1384
1384
  text: "Filter produced empty WHERE clause",
1385
1385
  domain: ErrorDomain.MASTRA_VECTOR,
1386
1386
  category: ErrorCategory.USER,
@@ -1411,7 +1411,7 @@ var PgVector = class extends MastraVector {
1411
1411
  }
1412
1412
  const mastraError = new MastraError(
1413
1413
  {
1414
- id: "MASTRA_STORAGE_PG_VECTOR_UPDATE_VECTOR_FAILED",
1414
+ id: createVectorErrorId("PG", "UPDATE_VECTOR", "FAILED"),
1415
1415
  domain: ErrorDomain.MASTRA_VECTOR,
1416
1416
  category: ErrorCategory.THIRD_PARTY,
1417
1417
  details: {
@@ -1448,7 +1448,7 @@ var PgVector = class extends MastraVector {
1448
1448
  } catch (error) {
1449
1449
  const mastraError = new MastraError(
1450
1450
  {
1451
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_VECTOR_FAILED",
1451
+ id: createVectorErrorId("PG", "DELETE_VECTOR", "FAILED"),
1452
1452
  domain: ErrorDomain.MASTRA_VECTOR,
1453
1453
  category: ErrorCategory.THIRD_PARTY,
1454
1454
  details: {
@@ -1478,7 +1478,7 @@ var PgVector = class extends MastraVector {
1478
1478
  const { tableName } = this.getTableName(indexName);
1479
1479
  if (!filter && !ids) {
1480
1480
  throw new MastraError({
1481
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_MISSING_PARAMS",
1481
+ id: createVectorErrorId("PG", "DELETE_VECTORS", "NO_TARGET"),
1482
1482
  text: "Either filter or ids must be provided",
1483
1483
  domain: ErrorDomain.MASTRA_VECTOR,
1484
1484
  category: ErrorCategory.USER,
@@ -1487,7 +1487,7 @@ var PgVector = class extends MastraVector {
1487
1487
  }
1488
1488
  if (filter && ids) {
1489
1489
  throw new MastraError({
1490
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_CONFLICTING_PARAMS",
1490
+ id: createVectorErrorId("PG", "DELETE_VECTORS", "MUTUALLY_EXCLUSIVE"),
1491
1491
  text: "Cannot provide both filter and ids - they are mutually exclusive",
1492
1492
  domain: ErrorDomain.MASTRA_VECTOR,
1493
1493
  category: ErrorCategory.USER,
@@ -1499,7 +1499,7 @@ var PgVector = class extends MastraVector {
1499
1499
  if (ids) {
1500
1500
  if (ids.length === 0) {
1501
1501
  throw new MastraError({
1502
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_EMPTY_IDS",
1502
+ id: createVectorErrorId("PG", "DELETE_VECTORS", "EMPTY_IDS"),
1503
1503
  text: "Cannot delete with empty ids array",
1504
1504
  domain: ErrorDomain.MASTRA_VECTOR,
1505
1505
  category: ErrorCategory.USER,
@@ -1512,7 +1512,7 @@ var PgVector = class extends MastraVector {
1512
1512
  } else {
1513
1513
  if (!filter || Object.keys(filter).length === 0) {
1514
1514
  throw new MastraError({
1515
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_EMPTY_FILTER",
1515
+ id: createVectorErrorId("PG", "DELETE_VECTORS", "EMPTY_FILTER"),
1516
1516
  text: "Cannot delete with empty filter. Use deleteIndex to delete all vectors.",
1517
1517
  domain: ErrorDomain.MASTRA_VECTOR,
1518
1518
  category: ErrorCategory.USER,
@@ -1524,7 +1524,7 @@ var PgVector = class extends MastraVector {
1524
1524
  const whereClause = filterQuery.trim().replace(/^WHERE\s+/i, "");
1525
1525
  if (!whereClause) {
1526
1526
  throw new MastraError({
1527
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_INVALID_FILTER",
1527
+ id: createVectorErrorId("PG", "DELETE_VECTORS", "INVALID_FILTER"),
1528
1528
  text: "Filter produced empty WHERE clause",
1529
1529
  domain: ErrorDomain.MASTRA_VECTOR,
1530
1530
  category: ErrorCategory.USER,
@@ -1547,7 +1547,7 @@ var PgVector = class extends MastraVector {
1547
1547
  }
1548
1548
  const mastraError = new MastraError(
1549
1549
  {
1550
- id: "MASTRA_STORAGE_PG_VECTOR_DELETE_VECTORS_FAILED",
1550
+ id: createVectorErrorId("PG", "DELETE_VECTORS", "FAILED"),
1551
1551
  domain: ErrorDomain.MASTRA_VECTOR,
1552
1552
  category: ErrorCategory.THIRD_PARTY,
1553
1553
  details: {
@@ -1687,7 +1687,7 @@ var MemoryPG = class extends MemoryStorage {
1687
1687
  } catch (error) {
1688
1688
  throw new MastraError(
1689
1689
  {
1690
- id: "MASTRA_STORAGE_PG_STORE_GET_THREAD_BY_ID_FAILED",
1690
+ id: createStorageErrorId("PG", "GET_THREAD_BY_ID", "FAILED"),
1691
1691
  domain: ErrorDomain.STORAGE,
1692
1692
  category: ErrorCategory.THIRD_PARTY,
1693
1693
  details: {
@@ -1702,7 +1702,7 @@ var MemoryPG = class extends MemoryStorage {
1702
1702
  const { resourceId, page = 0, perPage: perPageInput, orderBy } = args;
1703
1703
  if (page < 0) {
1704
1704
  throw new MastraError({
1705
- id: "MASTRA_STORAGE_PG_STORE_INVALID_PAGE",
1705
+ id: createStorageErrorId("PG", "LIST_THREADS_BY_RESOURCE_ID", "INVALID_PAGE"),
1706
1706
  domain: ErrorDomain.STORAGE,
1707
1707
  category: ErrorCategory.USER,
1708
1708
  text: "Page number must be non-negative",
@@ -1751,7 +1751,7 @@ var MemoryPG = class extends MemoryStorage {
1751
1751
  } catch (error) {
1752
1752
  const mastraError = new MastraError(
1753
1753
  {
1754
- id: "MASTRA_STORAGE_PG_STORE_LIST_THREADS_BY_RESOURCE_ID_FAILED",
1754
+ id: createStorageErrorId("PG", "LIST_THREADS_BY_RESOURCE_ID", "FAILED"),
1755
1755
  domain: ErrorDomain.STORAGE,
1756
1756
  category: ErrorCategory.THIRD_PARTY,
1757
1757
  details: {
@@ -1809,7 +1809,7 @@ var MemoryPG = class extends MemoryStorage {
1809
1809
  } catch (error) {
1810
1810
  throw new MastraError(
1811
1811
  {
1812
- id: "MASTRA_STORAGE_PG_STORE_SAVE_THREAD_FAILED",
1812
+ id: createStorageErrorId("PG", "SAVE_THREAD", "FAILED"),
1813
1813
  domain: ErrorDomain.STORAGE,
1814
1814
  category: ErrorCategory.THIRD_PARTY,
1815
1815
  details: {
@@ -1829,7 +1829,7 @@ var MemoryPG = class extends MemoryStorage {
1829
1829
  const existingThread = await this.getThreadById({ threadId: id });
1830
1830
  if (!existingThread) {
1831
1831
  throw new MastraError({
1832
- id: "MASTRA_STORAGE_PG_STORE_UPDATE_THREAD_FAILED",
1832
+ id: createStorageErrorId("PG", "UPDATE_THREAD", "FAILED"),
1833
1833
  domain: ErrorDomain.STORAGE,
1834
1834
  category: ErrorCategory.USER,
1835
1835
  text: `Thread ${id} not found`,
@@ -1867,7 +1867,7 @@ var MemoryPG = class extends MemoryStorage {
1867
1867
  } catch (error) {
1868
1868
  throw new MastraError(
1869
1869
  {
1870
- id: "MASTRA_STORAGE_PG_STORE_UPDATE_THREAD_FAILED",
1870
+ id: createStorageErrorId("PG", "UPDATE_THREAD", "FAILED"),
1871
1871
  domain: ErrorDomain.STORAGE,
1872
1872
  category: ErrorCategory.THIRD_PARTY,
1873
1873
  details: {
@@ -1904,7 +1904,7 @@ var MemoryPG = class extends MemoryStorage {
1904
1904
  } catch (error) {
1905
1905
  throw new MastraError(
1906
1906
  {
1907
- id: "MASTRA_STORAGE_PG_STORE_DELETE_THREAD_FAILED",
1907
+ id: createStorageErrorId("PG", "DELETE_THREAD", "FAILED"),
1908
1908
  domain: ErrorDomain.STORAGE,
1909
1909
  category: ErrorCategory.THIRD_PARTY,
1910
1910
  details: {
@@ -2011,7 +2011,7 @@ var MemoryPG = class extends MemoryStorage {
2011
2011
  } catch (error) {
2012
2012
  const mastraError = new MastraError(
2013
2013
  {
2014
- id: "MASTRA_STORAGE_PG_STORE_LIST_MESSAGES_BY_ID_FAILED",
2014
+ id: createStorageErrorId("PG", "LIST_MESSAGES_BY_ID", "FAILED"),
2015
2015
  domain: ErrorDomain.STORAGE,
2016
2016
  category: ErrorCategory.THIRD_PARTY,
2017
2017
  details: {
@@ -2033,7 +2033,7 @@ var MemoryPG = class extends MemoryStorage {
2033
2033
  if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
2034
2034
  throw new MastraError(
2035
2035
  {
2036
- id: "STORAGE_PG_LIST_MESSAGES_INVALID_THREAD_ID",
2036
+ id: createStorageErrorId("PG", "LIST_MESSAGES", "INVALID_THREAD_ID"),
2037
2037
  domain: ErrorDomain.STORAGE,
2038
2038
  category: ErrorCategory.THIRD_PARTY,
2039
2039
  details: { threadId: Array.isArray(threadId) ? String(threadId) : String(threadId) }
@@ -2043,7 +2043,7 @@ var MemoryPG = class extends MemoryStorage {
2043
2043
  }
2044
2044
  if (page < 0) {
2045
2045
  throw new MastraError({
2046
- id: "MASTRA_STORAGE_PG_STORE_INVALID_PAGE",
2046
+ id: createStorageErrorId("PG", "LIST_MESSAGES", "INVALID_PAGE"),
2047
2047
  domain: ErrorDomain.STORAGE,
2048
2048
  category: ErrorCategory.USER,
2049
2049
  text: "Page number must be non-negative",
@@ -2138,7 +2138,7 @@ var MemoryPG = class extends MemoryStorage {
2138
2138
  } catch (error) {
2139
2139
  const mastraError = new MastraError(
2140
2140
  {
2141
- id: "MASTRA_STORAGE_PG_STORE_LIST_MESSAGES_FAILED",
2141
+ id: createStorageErrorId("PG", "LIST_MESSAGES", "FAILED"),
2142
2142
  domain: ErrorDomain.STORAGE,
2143
2143
  category: ErrorCategory.THIRD_PARTY,
2144
2144
  details: {
@@ -2164,7 +2164,7 @@ var MemoryPG = class extends MemoryStorage {
2164
2164
  const threadId = messages[0]?.threadId;
2165
2165
  if (!threadId) {
2166
2166
  throw new MastraError({
2167
- id: "MASTRA_STORAGE_PG_STORE_SAVE_MESSAGES_FAILED",
2167
+ id: createStorageErrorId("PG", "SAVE_MESSAGES", "FAILED"),
2168
2168
  domain: ErrorDomain.STORAGE,
2169
2169
  category: ErrorCategory.THIRD_PARTY,
2170
2170
  text: `Thread ID is required`
@@ -2173,7 +2173,7 @@ var MemoryPG = class extends MemoryStorage {
2173
2173
  const thread = await this.getThreadById({ threadId });
2174
2174
  if (!thread) {
2175
2175
  throw new MastraError({
2176
- id: "MASTRA_STORAGE_PG_STORE_SAVE_MESSAGES_FAILED",
2176
+ id: createStorageErrorId("PG", "SAVE_MESSAGES", "FAILED"),
2177
2177
  domain: ErrorDomain.STORAGE,
2178
2178
  category: ErrorCategory.THIRD_PARTY,
2179
2179
  text: `Thread ${threadId} not found`,
@@ -2244,7 +2244,7 @@ var MemoryPG = class extends MemoryStorage {
2244
2244
  } catch (error) {
2245
2245
  throw new MastraError(
2246
2246
  {
2247
- id: "MASTRA_STORAGE_PG_STORE_SAVE_MESSAGES_FAILED",
2247
+ id: createStorageErrorId("PG", "SAVE_MESSAGES", "FAILED"),
2248
2248
  domain: ErrorDomain.STORAGE,
2249
2249
  category: ErrorCategory.THIRD_PARTY,
2250
2250
  details: {
@@ -2373,7 +2373,7 @@ var MemoryPG = class extends MemoryStorage {
2373
2373
  } catch (error) {
2374
2374
  throw new MastraError(
2375
2375
  {
2376
- id: "PG_STORE_DELETE_MESSAGES_FAILED",
2376
+ id: createStorageErrorId("PG", "DELETE_MESSAGES", "FAILED"),
2377
2377
  domain: ErrorDomain.STORAGE,
2378
2378
  category: ErrorCategory.THIRD_PARTY,
2379
2379
  details: { messageIds: messageIds.join(", ") }
@@ -2494,7 +2494,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2494
2494
  } catch (error) {
2495
2495
  throw new MastraError(
2496
2496
  {
2497
- id: "PG_STORE_CREATE_SPAN_FAILED",
2497
+ id: createStorageErrorId("PG", "CREATE_SPAN", "FAILED"),
2498
2498
  domain: ErrorDomain.STORAGE,
2499
2499
  category: ErrorCategory.USER,
2500
2500
  details: {
@@ -2540,7 +2540,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2540
2540
  } catch (error) {
2541
2541
  throw new MastraError(
2542
2542
  {
2543
- id: "PG_STORE_GET_TRACE_FAILED",
2543
+ id: createStorageErrorId("PG", "GET_TRACE", "FAILED"),
2544
2544
  domain: ErrorDomain.STORAGE,
2545
2545
  category: ErrorCategory.USER,
2546
2546
  details: {
@@ -2572,7 +2572,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2572
2572
  } catch (error) {
2573
2573
  throw new MastraError(
2574
2574
  {
2575
- id: "PG_STORE_UPDATE_SPAN_FAILED",
2575
+ id: createStorageErrorId("PG", "UPDATE_SPAN", "FAILED"),
2576
2576
  domain: ErrorDomain.STORAGE,
2577
2577
  category: ErrorCategory.USER,
2578
2578
  details: {
@@ -2608,7 +2608,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2608
2608
  name = `agent run: '${entityId}'`;
2609
2609
  } else {
2610
2610
  const error = new MastraError({
2611
- id: "PG_STORE_GET_TRACES_PAGINATED_FAILED",
2611
+ id: createStorageErrorId("PG", "GET_TRACES_PAGINATED", "INVALID_ENTITY_TYPE"),
2612
2612
  domain: ErrorDomain.STORAGE,
2613
2613
  category: ErrorCategory.USER,
2614
2614
  details: {
@@ -2676,7 +2676,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2676
2676
  } catch (error) {
2677
2677
  throw new MastraError(
2678
2678
  {
2679
- id: "PG_STORE_GET_TRACES_PAGINATED_FAILED",
2679
+ id: createStorageErrorId("PG", "GET_TRACES_PAGINATED", "FAILED"),
2680
2680
  domain: ErrorDomain.STORAGE,
2681
2681
  category: ErrorCategory.USER
2682
2682
  },
@@ -2705,7 +2705,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2705
2705
  } catch (error) {
2706
2706
  throw new MastraError(
2707
2707
  {
2708
- id: "PG_STORE_BATCH_CREATE_SPANS_FAILED",
2708
+ id: createStorageErrorId("PG", "BATCH_CREATE_SPANS", "FAILED"),
2709
2709
  domain: ErrorDomain.STORAGE,
2710
2710
  category: ErrorCategory.USER
2711
2711
  },
@@ -2740,7 +2740,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2740
2740
  } catch (error) {
2741
2741
  throw new MastraError(
2742
2742
  {
2743
- id: "PG_STORE_BATCH_UPDATE_SPANS_FAILED",
2743
+ id: createStorageErrorId("PG", "BATCH_UPDATE_SPANS", "FAILED"),
2744
2744
  domain: ErrorDomain.STORAGE,
2745
2745
  category: ErrorCategory.USER
2746
2746
  },
@@ -2759,7 +2759,7 @@ var ObservabilityPG = class extends ObservabilityStorage {
2759
2759
  } catch (error) {
2760
2760
  throw new MastraError(
2761
2761
  {
2762
- id: "PG_STORE_BATCH_DELETE_TRACES_FAILED",
2762
+ id: createStorageErrorId("PG", "BATCH_DELETE_TRACES", "FAILED"),
2763
2763
  domain: ErrorDomain.STORAGE,
2764
2764
  category: ErrorCategory.USER
2765
2765
  },
@@ -2889,7 +2889,7 @@ var StoreOperationsPG = class extends StoreOperations {
2889
2889
  } catch (error) {
2890
2890
  throw new MastraError(
2891
2891
  {
2892
- id: "MASTRA_STORAGE_PG_STORE_INSERT_FAILED",
2892
+ id: createStorageErrorId("PG", "INSERT", "FAILED"),
2893
2893
  domain: ErrorDomain.STORAGE,
2894
2894
  category: ErrorCategory.THIRD_PARTY,
2895
2895
  details: {
@@ -2908,7 +2908,7 @@ var StoreOperationsPG = class extends StoreOperations {
2908
2908
  } catch (error) {
2909
2909
  throw new MastraError(
2910
2910
  {
2911
- id: "MASTRA_STORAGE_PG_STORE_CLEAR_TABLE_FAILED",
2911
+ id: createStorageErrorId("PG", "CLEAR_TABLE", "FAILED"),
2912
2912
  domain: ErrorDomain.STORAGE,
2913
2913
  category: ErrorCategory.THIRD_PARTY,
2914
2914
  details: {
@@ -2981,7 +2981,7 @@ var StoreOperationsPG = class extends StoreOperations {
2981
2981
  } catch (error) {
2982
2982
  throw new MastraError(
2983
2983
  {
2984
- id: "MASTRA_STORAGE_PG_STORE_CREATE_TABLE_FAILED",
2984
+ id: createStorageErrorId("PG", "CREATE_TABLE", "FAILED"),
2985
2985
  domain: ErrorDomain.STORAGE,
2986
2986
  category: ErrorCategory.THIRD_PARTY,
2987
2987
  details: {
@@ -3068,7 +3068,7 @@ var StoreOperationsPG = class extends StoreOperations {
3068
3068
  } catch (error) {
3069
3069
  throw new MastraError(
3070
3070
  {
3071
- id: "MASTRA_STORAGE_PG_STORE_ALTER_TABLE_FAILED",
3071
+ id: createStorageErrorId("PG", "ALTER_TABLE", "FAILED"),
3072
3072
  domain: ErrorDomain.STORAGE,
3073
3073
  category: ErrorCategory.THIRD_PARTY,
3074
3074
  details: {
@@ -3102,7 +3102,7 @@ var StoreOperationsPG = class extends StoreOperations {
3102
3102
  } catch (error) {
3103
3103
  throw new MastraError(
3104
3104
  {
3105
- id: "MASTRA_STORAGE_PG_STORE_LOAD_FAILED",
3105
+ id: createStorageErrorId("PG", "LOAD", "FAILED"),
3106
3106
  domain: ErrorDomain.STORAGE,
3107
3107
  category: ErrorCategory.THIRD_PARTY,
3108
3108
  details: {
@@ -3124,7 +3124,7 @@ var StoreOperationsPG = class extends StoreOperations {
3124
3124
  await this.client.query("ROLLBACK");
3125
3125
  throw new MastraError(
3126
3126
  {
3127
- id: "MASTRA_STORAGE_PG_STORE_BATCH_INSERT_FAILED",
3127
+ id: createStorageErrorId("PG", "BATCH_INSERT", "FAILED"),
3128
3128
  domain: ErrorDomain.STORAGE,
3129
3129
  category: ErrorCategory.THIRD_PARTY,
3130
3130
  details: {
@@ -3144,7 +3144,7 @@ var StoreOperationsPG = class extends StoreOperations {
3144
3144
  } catch (error) {
3145
3145
  throw new MastraError(
3146
3146
  {
3147
- id: "MASTRA_STORAGE_PG_STORE_DROP_TABLE_FAILED",
3147
+ id: createStorageErrorId("PG", "DROP_TABLE", "FAILED"),
3148
3148
  domain: ErrorDomain.STORAGE,
3149
3149
  category: ErrorCategory.THIRD_PARTY,
3150
3150
  details: {
@@ -3217,7 +3217,7 @@ var StoreOperationsPG = class extends StoreOperations {
3217
3217
  }
3218
3218
  throw new MastraError(
3219
3219
  {
3220
- id: "MASTRA_STORAGE_PG_INDEX_CREATE_FAILED",
3220
+ id: createStorageErrorId("PG", "INDEX_CREATE", "FAILED"),
3221
3221
  domain: ErrorDomain.STORAGE,
3222
3222
  category: ErrorCategory.THIRD_PARTY,
3223
3223
  details: {
@@ -3249,7 +3249,7 @@ var StoreOperationsPG = class extends StoreOperations {
3249
3249
  } catch (error) {
3250
3250
  throw new MastraError(
3251
3251
  {
3252
- id: "MASTRA_STORAGE_PG_INDEX_DROP_FAILED",
3252
+ id: createStorageErrorId("PG", "INDEX_DROP", "FAILED"),
3253
3253
  domain: ErrorDomain.STORAGE,
3254
3254
  category: ErrorCategory.THIRD_PARTY,
3255
3255
  details: {
@@ -3325,7 +3325,7 @@ var StoreOperationsPG = class extends StoreOperations {
3325
3325
  } catch (error) {
3326
3326
  throw new MastraError(
3327
3327
  {
3328
- id: "MASTRA_STORAGE_PG_INDEX_LIST_FAILED",
3328
+ id: createStorageErrorId("PG", "INDEX_LIST", "FAILED"),
3329
3329
  domain: ErrorDomain.STORAGE,
3330
3330
  category: ErrorCategory.THIRD_PARTY,
3331
3331
  details: tableName ? {
@@ -3407,7 +3407,7 @@ var StoreOperationsPG = class extends StoreOperations {
3407
3407
  } catch (error) {
3408
3408
  throw new MastraError(
3409
3409
  {
3410
- id: "MASTRA_STORAGE_PG_STORE_CREATE_PERFORMANCE_INDEXES_FAILED",
3410
+ id: createStorageErrorId("PG", "CREATE_AUTOMATIC_INDEXES", "FAILED"),
3411
3411
  domain: ErrorDomain.STORAGE,
3412
3412
  category: ErrorCategory.THIRD_PARTY
3413
3413
  },
@@ -3469,7 +3469,7 @@ var StoreOperationsPG = class extends StoreOperations {
3469
3469
  } catch (error) {
3470
3470
  throw new MastraError(
3471
3471
  {
3472
- id: "MASTRA_STORAGE_PG_INDEX_DESCRIBE_FAILED",
3472
+ id: createStorageErrorId("PG", "INDEX_DESCRIBE", "FAILED"),
3473
3473
  domain: ErrorDomain.STORAGE,
3474
3474
  category: ErrorCategory.THIRD_PARTY,
3475
3475
  details: {
@@ -3514,7 +3514,7 @@ var StoreOperationsPG = class extends StoreOperations {
3514
3514
  } catch (error) {
3515
3515
  throw new MastraError(
3516
3516
  {
3517
- id: "MASTRA_STORAGE_PG_STORE_UPDATE_FAILED",
3517
+ id: createStorageErrorId("PG", "UPDATE", "FAILED"),
3518
3518
  domain: ErrorDomain.STORAGE,
3519
3519
  category: ErrorCategory.THIRD_PARTY,
3520
3520
  details: {
@@ -3542,7 +3542,7 @@ var StoreOperationsPG = class extends StoreOperations {
3542
3542
  await this.client.query("ROLLBACK");
3543
3543
  throw new MastraError(
3544
3544
  {
3545
- id: "MASTRA_STORAGE_PG_STORE_BATCH_UPDATE_FAILED",
3545
+ id: createStorageErrorId("PG", "BATCH_UPDATE", "FAILED"),
3546
3546
  domain: ErrorDomain.STORAGE,
3547
3547
  category: ErrorCategory.THIRD_PARTY,
3548
3548
  details: {
@@ -3583,7 +3583,7 @@ var StoreOperationsPG = class extends StoreOperations {
3583
3583
  } catch (error) {
3584
3584
  throw new MastraError(
3585
3585
  {
3586
- id: "MASTRA_STORAGE_PG_STORE_BATCH_DELETE_FAILED",
3586
+ id: createStorageErrorId("PG", "BATCH_DELETE", "FAILED"),
3587
3587
  domain: ErrorDomain.STORAGE,
3588
3588
  category: ErrorCategory.THIRD_PARTY,
3589
3589
  details: {
@@ -3628,7 +3628,7 @@ var ScoresPG = class extends ScoresStorage {
3628
3628
  } catch (error) {
3629
3629
  throw new MastraError(
3630
3630
  {
3631
- id: "MASTRA_STORAGE_PG_STORE_GET_SCORE_BY_ID_FAILED",
3631
+ id: createStorageErrorId("PG", "GET_SCORE_BY_ID", "FAILED"),
3632
3632
  domain: ErrorDomain.STORAGE,
3633
3633
  category: ErrorCategory.THIRD_PARTY
3634
3634
  },
@@ -3696,7 +3696,7 @@ var ScoresPG = class extends ScoresStorage {
3696
3696
  } catch (error) {
3697
3697
  throw new MastraError(
3698
3698
  {
3699
- id: "MASTRA_STORAGE_PG_STORE_GET_SCORES_BY_SCORER_ID_FAILED",
3699
+ id: createStorageErrorId("PG", "GET_SCORES_BY_SCORER_ID", "FAILED"),
3700
3700
  domain: ErrorDomain.STORAGE,
3701
3701
  category: ErrorCategory.THIRD_PARTY
3702
3702
  },
@@ -3711,15 +3711,15 @@ var ScoresPG = class extends ScoresStorage {
3711
3711
  } catch (error) {
3712
3712
  throw new MastraError(
3713
3713
  {
3714
- id: "MASTRA_STORAGE_PG_STORE_SAVE_SCORE_FAILED_INVALID_SCORE_PAYLOAD",
3714
+ id: createStorageErrorId("PG", "SAVE_SCORE", "VALIDATION_FAILED"),
3715
3715
  domain: ErrorDomain.STORAGE,
3716
3716
  category: ErrorCategory.USER,
3717
3717
  details: {
3718
- scorer: score.scorer.id,
3719
- entityId: score.entityId,
3720
- entityType: score.entityType,
3721
- traceId: score.traceId || "",
3722
- spanId: score.spanId || ""
3718
+ scorer: score.scorer?.id ?? "unknown",
3719
+ entityId: score.entityId ?? "unknown",
3720
+ entityType: score.entityType ?? "unknown",
3721
+ traceId: score.traceId ?? "",
3722
+ spanId: score.spanId ?? ""
3723
3723
  }
3724
3724
  },
3725
3725
  error
@@ -3727,6 +3727,7 @@ var ScoresPG = class extends ScoresStorage {
3727
3727
  }
3728
3728
  try {
3729
3729
  const id = crypto.randomUUID();
3730
+ const now = /* @__PURE__ */ new Date();
3730
3731
  const {
3731
3732
  scorer,
3732
3733
  preprocessStepResult,
@@ -3749,18 +3750,19 @@ var ScoresPG = class extends ScoresStorage {
3749
3750
  scorer: scorer ? JSON.stringify(scorer) : null,
3750
3751
  preprocessStepResult: preprocessStepResult ? JSON.stringify(preprocessStepResult) : null,
3751
3752
  analyzeStepResult: analyzeStepResult ? JSON.stringify(analyzeStepResult) : null,
3753
+ metadata: metadata ? JSON.stringify(metadata) : null,
3754
+ additionalContext: additionalContext ? JSON.stringify(additionalContext) : null,
3752
3755
  requestContext: requestContext ? JSON.stringify(requestContext) : null,
3753
3756
  entity: entity ? JSON.stringify(entity) : null,
3754
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3755
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
3757
+ createdAt: now.toISOString(),
3758
+ updatedAt: now.toISOString()
3756
3759
  }
3757
3760
  });
3758
- const scoreFromDb = await this.getScoreById({ id });
3759
- return { score: scoreFromDb };
3761
+ return { score: { ...parsedScore, id, createdAt: now, updatedAt: now } };
3760
3762
  } catch (error) {
3761
3763
  throw new MastraError(
3762
3764
  {
3763
- id: "MASTRA_STORAGE_PG_STORE_SAVE_SCORE_FAILED",
3765
+ id: createStorageErrorId("PG", "SAVE_SCORE", "FAILED"),
3764
3766
  domain: ErrorDomain.STORAGE,
3765
3767
  category: ErrorCategory.THIRD_PARTY
3766
3768
  },
@@ -3809,7 +3811,7 @@ var ScoresPG = class extends ScoresStorage {
3809
3811
  } catch (error) {
3810
3812
  throw new MastraError(
3811
3813
  {
3812
- id: "MASTRA_STORAGE_PG_STORE_GET_SCORES_BY_RUN_ID_FAILED",
3814
+ id: createStorageErrorId("PG", "GET_SCORES_BY_RUN_ID", "FAILED"),
3813
3815
  domain: ErrorDomain.STORAGE,
3814
3816
  category: ErrorCategory.THIRD_PARTY
3815
3817
  },
@@ -3859,7 +3861,7 @@ var ScoresPG = class extends ScoresStorage {
3859
3861
  } catch (error) {
3860
3862
  throw new MastraError(
3861
3863
  {
3862
- id: "MASTRA_STORAGE_PG_STORE_GET_SCORES_BY_ENTITY_ID_FAILED",
3864
+ id: createStorageErrorId("PG", "GET_SCORES_BY_ENTITY_ID", "FAILED"),
3863
3865
  domain: ErrorDomain.STORAGE,
3864
3866
  category: ErrorCategory.THIRD_PARTY
3865
3867
  },
@@ -3902,7 +3904,7 @@ var ScoresPG = class extends ScoresStorage {
3902
3904
  } catch (error) {
3903
3905
  throw new MastraError(
3904
3906
  {
3905
- id: "MASTRA_STORAGE_PG_STORE_GET_SCORES_BY_SPAN_FAILED",
3907
+ id: createStorageErrorId("PG", "GET_SCORES_BY_SPAN", "FAILED"),
3906
3908
  domain: ErrorDomain.STORAGE,
3907
3909
  category: ErrorCategory.THIRD_PARTY
3908
3910
  },
@@ -3977,7 +3979,7 @@ var WorkflowsPG = class extends WorkflowsStorage {
3977
3979
  } catch (error) {
3978
3980
  throw new MastraError(
3979
3981
  {
3980
- id: "MASTRA_STORAGE_PG_STORE_PERSIST_WORKFLOW_SNAPSHOT_FAILED",
3982
+ id: createStorageErrorId("PG", "PERSIST_WORKFLOW_SNAPSHOT", "FAILED"),
3981
3983
  domain: ErrorDomain.STORAGE,
3982
3984
  category: ErrorCategory.THIRD_PARTY
3983
3985
  },
@@ -3998,7 +4000,7 @@ var WorkflowsPG = class extends WorkflowsStorage {
3998
4000
  } catch (error) {
3999
4001
  throw new MastraError(
4000
4002
  {
4001
- id: "MASTRA_STORAGE_PG_STORE_LOAD_WORKFLOW_SNAPSHOT_FAILED",
4003
+ id: createStorageErrorId("PG", "LOAD_WORKFLOW_SNAPSHOT", "FAILED"),
4002
4004
  domain: ErrorDomain.STORAGE,
4003
4005
  category: ErrorCategory.THIRD_PARTY
4004
4006
  },
@@ -4039,7 +4041,7 @@ var WorkflowsPG = class extends WorkflowsStorage {
4039
4041
  } catch (error) {
4040
4042
  throw new MastraError(
4041
4043
  {
4042
- id: "MASTRA_STORAGE_PG_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED",
4044
+ id: createStorageErrorId("PG", "GET_WORKFLOW_RUN_BY_ID", "FAILED"),
4043
4045
  domain: ErrorDomain.STORAGE,
4044
4046
  category: ErrorCategory.THIRD_PARTY,
4045
4047
  details: {
@@ -4121,7 +4123,7 @@ var WorkflowsPG = class extends WorkflowsStorage {
4121
4123
  } catch (error) {
4122
4124
  throw new MastraError(
4123
4125
  {
4124
- id: "MASTRA_STORAGE_PG_STORE_LIST_WORKFLOW_RUNS_FAILED",
4126
+ id: createStorageErrorId("PG", "LIST_WORKFLOW_RUNS", "FAILED"),
4125
4127
  domain: ErrorDomain.STORAGE,
4126
4128
  category: ErrorCategory.THIRD_PARTY,
4127
4129
  details: {
@@ -4138,17 +4140,17 @@ var WorkflowsPG = class extends WorkflowsStorage {
4138
4140
  var PostgresStore = class extends MastraStorage {
4139
4141
  #db;
4140
4142
  #pgp;
4141
- #config;
4142
4143
  schema;
4143
- isConnected = false;
4144
+ isInitialized = false;
4144
4145
  stores;
4145
4146
  constructor(config) {
4146
4147
  try {
4147
4148
  validateConfig("PostgresStore", config);
4148
- super({ id: config.id, name: "PostgresStore" });
4149
+ super({ id: config.id, name: "PostgresStore", disableInit: config.disableInit });
4149
4150
  this.schema = config.schemaName || "public";
4151
+ let pgConfig;
4150
4152
  if (isConnectionStringConfig(config)) {
4151
- this.#config = {
4153
+ pgConfig = {
4152
4154
  id: config.id,
4153
4155
  connectionString: config.connectionString,
4154
4156
  max: config.max,
@@ -4156,14 +4158,14 @@ var PostgresStore = class extends MastraStorage {
4156
4158
  ssl: config.ssl
4157
4159
  };
4158
4160
  } else if (isCloudSqlConfig(config)) {
4159
- this.#config = {
4161
+ pgConfig = {
4160
4162
  ...config,
4161
4163
  id: config.id,
4162
4164
  max: config.max,
4163
4165
  idleTimeoutMillis: config.idleTimeoutMillis
4164
4166
  };
4165
4167
  } else if (isHostConfig(config)) {
4166
- this.#config = {
4168
+ pgConfig = {
4167
4169
  id: config.id,
4168
4170
  host: config.host,
4169
4171
  port: config.port,
@@ -4179,11 +4181,24 @@ var PostgresStore = class extends MastraStorage {
4179
4181
  "PostgresStore: invalid config. Provide either {connectionString}, {host,port,database,user,password}, or a pg ClientConfig (e.g., Cloud SQL connector with `stream`)."
4180
4182
  );
4181
4183
  }
4182
- this.stores = {};
4184
+ this.#pgp = pgPromise();
4185
+ this.#db = this.#pgp(pgConfig);
4186
+ const operations = new StoreOperationsPG({ client: this.#db, schemaName: this.schema });
4187
+ const scores = new ScoresPG({ client: this.#db, operations, schema: this.schema });
4188
+ const workflows = new WorkflowsPG({ client: this.#db, operations, schema: this.schema });
4189
+ const memory = new MemoryPG({ client: this.#db, schema: this.schema, operations });
4190
+ const observability = new ObservabilityPG({ client: this.#db, operations, schema: this.schema });
4191
+ this.stores = {
4192
+ operations,
4193
+ scores,
4194
+ workflows,
4195
+ memory,
4196
+ observability
4197
+ };
4183
4198
  } catch (e) {
4184
4199
  throw new MastraError(
4185
4200
  {
4186
- id: "MASTRA_STORAGE_PG_STORE_INITIALIZATION_FAILED",
4201
+ id: createStorageErrorId("PG", "INITIALIZATION", "FAILED"),
4187
4202
  domain: ErrorDomain.STORAGE,
4188
4203
  category: ErrorCategory.USER
4189
4204
  },
@@ -4192,36 +4207,22 @@ var PostgresStore = class extends MastraStorage {
4192
4207
  }
4193
4208
  }
4194
4209
  async init() {
4195
- if (this.isConnected) {
4210
+ if (this.isInitialized) {
4196
4211
  return;
4197
4212
  }
4198
4213
  try {
4199
- this.isConnected = true;
4200
- this.#pgp = pgPromise();
4201
- this.#db = this.#pgp(this.#config);
4202
- const operations = new StoreOperationsPG({ client: this.#db, schemaName: this.schema });
4203
- const scores = new ScoresPG({ client: this.#db, operations, schema: this.schema });
4204
- const workflows = new WorkflowsPG({ client: this.#db, operations, schema: this.schema });
4205
- const memory = new MemoryPG({ client: this.#db, schema: this.schema, operations });
4206
- const observability = new ObservabilityPG({ client: this.#db, operations, schema: this.schema });
4207
- this.stores = {
4208
- operations,
4209
- scores,
4210
- workflows,
4211
- memory,
4212
- observability
4213
- };
4214
+ this.isInitialized = true;
4214
4215
  await super.init();
4215
4216
  try {
4216
- await operations.createAutomaticIndexes();
4217
+ await this.stores.operations.createAutomaticIndexes();
4217
4218
  } catch (indexError) {
4218
4219
  console.warn("Failed to create indexes:", indexError);
4219
4220
  }
4220
4221
  } catch (error) {
4221
- this.isConnected = false;
4222
+ this.isInitialized = false;
4222
4223
  throw new MastraError(
4223
4224
  {
4224
- id: "MASTRA_STORAGE_POSTGRES_STORE_INIT_FAILED",
4225
+ id: createStorageErrorId("PG", "INIT", "FAILED"),
4225
4226
  domain: ErrorDomain.STORAGE,
4226
4227
  category: ErrorCategory.THIRD_PARTY
4227
4228
  },
@@ -4230,15 +4231,9 @@ var PostgresStore = class extends MastraStorage {
4230
4231
  }
4231
4232
  }
4232
4233
  get db() {
4233
- if (!this.#db) {
4234
- throw new Error(`PostgresStore: Store is not initialized, please call "init()" first.`);
4235
- }
4236
4234
  return this.#db;
4237
4235
  }
4238
4236
  get pgp() {
4239
- if (!this.#pgp) {
4240
- throw new Error(`PostgresStore: Store is not initialized, please call "init()" first.`);
4241
- }
4242
4237
  return this.#pgp;
4243
4238
  }
4244
4239
  get supports() {
@@ -4378,7 +4373,7 @@ var PostgresStore = class extends MastraStorage {
4378
4373
  async createSpan(span) {
4379
4374
  if (!this.stores.observability) {
4380
4375
  throw new MastraError({
4381
- id: "PG_STORE_OBSERVABILITY_NOT_INITIALIZED",
4376
+ id: createStorageErrorId("PG", "OBSERVABILITY", "NOT_INITIALIZED"),
4382
4377
  domain: ErrorDomain.STORAGE,
4383
4378
  category: ErrorCategory.SYSTEM,
4384
4379
  text: "Observability storage is not initialized"
@@ -4393,7 +4388,7 @@ var PostgresStore = class extends MastraStorage {
4393
4388
  }) {
4394
4389
  if (!this.stores.observability) {
4395
4390
  throw new MastraError({
4396
- id: "PG_STORE_OBSERVABILITY_NOT_INITIALIZED",
4391
+ id: createStorageErrorId("PG", "OBSERVABILITY", "NOT_INITIALIZED"),
4397
4392
  domain: ErrorDomain.STORAGE,
4398
4393
  category: ErrorCategory.SYSTEM,
4399
4394
  text: "Observability storage is not initialized"
@@ -4404,7 +4399,7 @@ var PostgresStore = class extends MastraStorage {
4404
4399
  async getTrace(traceId) {
4405
4400
  if (!this.stores.observability) {
4406
4401
  throw new MastraError({
4407
- id: "PG_STORE_OBSERVABILITY_NOT_INITIALIZED",
4402
+ id: createStorageErrorId("PG", "OBSERVABILITY", "NOT_INITIALIZED"),
4408
4403
  domain: ErrorDomain.STORAGE,
4409
4404
  category: ErrorCategory.SYSTEM,
4410
4405
  text: "Observability storage is not initialized"
@@ -4415,7 +4410,7 @@ var PostgresStore = class extends MastraStorage {
4415
4410
  async getTracesPaginated(args) {
4416
4411
  if (!this.stores.observability) {
4417
4412
  throw new MastraError({
4418
- id: "PG_STORE_OBSERVABILITY_NOT_INITIALIZED",
4413
+ id: createStorageErrorId("PG", "OBSERVABILITY", "NOT_INITIALIZED"),
4419
4414
  domain: ErrorDomain.STORAGE,
4420
4415
  category: ErrorCategory.SYSTEM,
4421
4416
  text: "Observability storage is not initialized"
@@ -4426,7 +4421,7 @@ var PostgresStore = class extends MastraStorage {
4426
4421
  async batchCreateSpans(args) {
4427
4422
  if (!this.stores.observability) {
4428
4423
  throw new MastraError({
4429
- id: "PG_STORE_OBSERVABILITY_NOT_INITIALIZED",
4424
+ id: createStorageErrorId("PG", "OBSERVABILITY", "NOT_INITIALIZED"),
4430
4425
  domain: ErrorDomain.STORAGE,
4431
4426
  category: ErrorCategory.SYSTEM,
4432
4427
  text: "Observability storage is not initialized"
@@ -4437,7 +4432,7 @@ var PostgresStore = class extends MastraStorage {
4437
4432
  async batchUpdateSpans(args) {
4438
4433
  if (!this.stores.observability) {
4439
4434
  throw new MastraError({
4440
- id: "PG_STORE_OBSERVABILITY_NOT_INITIALIZED",
4435
+ id: createStorageErrorId("PG", "OBSERVABILITY", "NOT_INITIALIZED"),
4441
4436
  domain: ErrorDomain.STORAGE,
4442
4437
  category: ErrorCategory.SYSTEM,
4443
4438
  text: "Observability storage is not initialized"
@@ -4448,7 +4443,7 @@ var PostgresStore = class extends MastraStorage {
4448
4443
  async batchDeleteTraces(args) {
4449
4444
  if (!this.stores.observability) {
4450
4445
  throw new MastraError({
4451
- id: "PG_STORE_OBSERVABILITY_NOT_INITIALIZED",
4446
+ id: createStorageErrorId("PG", "OBSERVABILITY", "NOT_INITIALIZED"),
4452
4447
  domain: ErrorDomain.STORAGE,
4453
4448
  category: ErrorCategory.SYSTEM,
4454
4449
  text: "Observability storage is not initialized"