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

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/CHANGELOG.md CHANGED
@@ -1,5 +1,73 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 1.0.0-beta.6
4
+
5
+ ### Minor Changes
6
+
7
+ - Add stored agents support ([#10953](https://github.com/mastra-ai/mastra/pull/10953))
8
+
9
+ Agents can now be stored in the database and loaded at runtime. This lets you persist agent configurations and dynamically create executable Agent instances from storage.
10
+
11
+ ```typescript
12
+ import { Mastra } from '@mastra/core';
13
+ import { LibSQLStore } from '@mastra/libsql';
14
+
15
+ const mastra = new Mastra({
16
+ storage: new LibSQLStore({ url: ':memory:' }),
17
+ tools: { myTool },
18
+ scorers: { myScorer },
19
+ });
20
+
21
+ // Create agent in storage via API or directly
22
+ await mastra.getStorage().createAgent({
23
+ agent: {
24
+ id: 'my-agent',
25
+ name: 'My Agent',
26
+ instructions: 'You are helpful',
27
+ model: { provider: 'openai', name: 'gpt-4' },
28
+ tools: { myTool: {} },
29
+ scorers: { myScorer: { sampling: { type: 'ratio', rate: 0.5 } } },
30
+ },
31
+ });
32
+
33
+ // Load and use the agent
34
+ const agent = await mastra.getStoredAgentById('my-agent');
35
+ const response = await agent.generate({ messages: 'Hello!' });
36
+
37
+ // List all stored agents with pagination
38
+ const { agents, total, hasMore } = await mastra.listStoredAgents({
39
+ page: 0,
40
+ perPage: 10,
41
+ });
42
+ ```
43
+
44
+ Also adds a memory registry to Mastra so stored agents can reference memory instances by key.
45
+
46
+ ### Patch Changes
47
+
48
+ - Updated dependencies [[`72df8ae`](https://github.com/mastra-ai/mastra/commit/72df8ae595584cdd7747d5c39ffaca45e4507227), [`9198899`](https://github.com/mastra-ai/mastra/commit/91988995c427b185c33714b7f3be955367911324), [`653e65a`](https://github.com/mastra-ai/mastra/commit/653e65ae1f9502c2958a32f47a5a2df11e612a92), [`c6fd6fe`](https://github.com/mastra-ai/mastra/commit/c6fd6fedd09e9cf8004b03a80925f5e94826ad7e), [`0bed332`](https://github.com/mastra-ai/mastra/commit/0bed332843f627202c6520eaf671771313cd20f3)]:
49
+ - @mastra/core@1.0.0-beta.9
50
+
51
+ ## 1.0.0-beta.5
52
+
53
+ ### Patch Changes
54
+
55
+ - Fix saveScore not persisting ID correctly, breaking getScoreById retrieval ([#10915](https://github.com/mastra-ai/mastra/pull/10915))
56
+
57
+ **What Changed**
58
+ - saveScore now correctly returns scores that can be retrieved with getScoreById
59
+ - Validation errors now include contextual information (scorer, entity, trace details) for easier debugging
60
+
61
+ **Impact**
62
+ Previously, calling getScoreById after saveScore would return null because the generated ID wasn't persisted to the database. This is now fixed across all store implementations, ensuring consistent behavior and data integrity.
63
+
64
+ - PostgresStore was setting `this.stores = {}` in the constructor and only populating it in the async `init()` method. This broke Memory because it checks `storage.stores.memory` synchronously in `getInputProcessors()` before `init()` is called. ([#10943](https://github.com/mastra-ai/mastra/pull/10943))
65
+
66
+ The fix moves domain instance creation to the constructor. This is safe because pg-promise creates database connections lazily when queries are executed.
67
+
68
+ - Updated dependencies [[`0d41fe2`](https://github.com/mastra-ai/mastra/commit/0d41fe245355dfc66d61a0d9c85d9400aac351ff), [`6b3ba91`](https://github.com/mastra-ai/mastra/commit/6b3ba91494cc10394df96782f349a4f7b1e152cc), [`7907fd1`](https://github.com/mastra-ai/mastra/commit/7907fd1c5059813b7b870b81ca71041dc807331b)]:
69
+ - @mastra/core@1.0.0-beta.8
70
+
3
71
  ## 1.0.0-beta.4
4
72
 
5
73
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -1663,7 +1663,302 @@ function transformFromSqlRow({
1663
1663
  return result;
1664
1664
  }
1665
1665
 
1666
- // src/storage/domains/memory/index.ts
1666
+ // src/storage/domains/agents/index.ts
1667
+ var AgentsPG = class extends storage.AgentsStorage {
1668
+ client;
1669
+ schema;
1670
+ constructor({ client, schema }) {
1671
+ super();
1672
+ this.client = client;
1673
+ this.schema = schema;
1674
+ }
1675
+ parseJson(value, fieldName) {
1676
+ if (!value) return void 0;
1677
+ if (typeof value !== "string") return value;
1678
+ try {
1679
+ return JSON.parse(value);
1680
+ } catch (error$1) {
1681
+ const details = {
1682
+ value: value.length > 100 ? value.substring(0, 100) + "..." : value
1683
+ };
1684
+ if (fieldName) {
1685
+ details.field = fieldName;
1686
+ }
1687
+ throw new error.MastraError(
1688
+ {
1689
+ id: storage.createStorageErrorId("PG", "PARSE_JSON", "INVALID_JSON"),
1690
+ domain: error.ErrorDomain.STORAGE,
1691
+ category: error.ErrorCategory.SYSTEM,
1692
+ text: `Failed to parse JSON${fieldName ? ` for field "${fieldName}"` : ""}: ${error$1 instanceof Error ? error$1.message : "Unknown error"}`,
1693
+ details
1694
+ },
1695
+ error$1
1696
+ );
1697
+ }
1698
+ }
1699
+ parseRow(row) {
1700
+ return {
1701
+ id: row.id,
1702
+ name: row.name,
1703
+ description: row.description,
1704
+ instructions: row.instructions,
1705
+ model: this.parseJson(row.model, "model"),
1706
+ tools: this.parseJson(row.tools, "tools"),
1707
+ defaultOptions: this.parseJson(row.defaultOptions, "defaultOptions"),
1708
+ workflows: this.parseJson(row.workflows, "workflows"),
1709
+ agents: this.parseJson(row.agents, "agents"),
1710
+ inputProcessors: this.parseJson(row.inputProcessors, "inputProcessors"),
1711
+ outputProcessors: this.parseJson(row.outputProcessors, "outputProcessors"),
1712
+ memory: this.parseJson(row.memory, "memory"),
1713
+ scorers: this.parseJson(row.scorers, "scorers"),
1714
+ metadata: this.parseJson(row.metadata, "metadata"),
1715
+ createdAt: row.createdAtZ || row.createdAt,
1716
+ updatedAt: row.updatedAtZ || row.updatedAt
1717
+ };
1718
+ }
1719
+ async getAgentById({ id }) {
1720
+ try {
1721
+ const tableName = getTableName({ indexName: storage.TABLE_AGENTS, schemaName: getSchemaName(this.schema) });
1722
+ const result = await this.client.oneOrNone(`SELECT * FROM ${tableName} WHERE id = $1`, [id]);
1723
+ if (!result) {
1724
+ return null;
1725
+ }
1726
+ return this.parseRow(result);
1727
+ } catch (error$1) {
1728
+ throw new error.MastraError(
1729
+ {
1730
+ id: storage.createStorageErrorId("PG", "GET_AGENT_BY_ID", "FAILED"),
1731
+ domain: error.ErrorDomain.STORAGE,
1732
+ category: error.ErrorCategory.THIRD_PARTY,
1733
+ details: { agentId: id }
1734
+ },
1735
+ error$1
1736
+ );
1737
+ }
1738
+ }
1739
+ async createAgent({ agent }) {
1740
+ try {
1741
+ const tableName = getTableName({ indexName: storage.TABLE_AGENTS, schemaName: getSchemaName(this.schema) });
1742
+ const now = /* @__PURE__ */ new Date();
1743
+ const nowIso = now.toISOString();
1744
+ await this.client.none(
1745
+ `INSERT INTO ${tableName} (
1746
+ id, name, description, instructions, model, tools,
1747
+ "defaultOptions", workflows, agents, "inputProcessors", "outputProcessors", memory, scorers, metadata,
1748
+ "createdAt", "createdAtZ", "updatedAt", "updatedAtZ"
1749
+ ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)`,
1750
+ [
1751
+ agent.id,
1752
+ agent.name,
1753
+ agent.description ?? null,
1754
+ agent.instructions,
1755
+ JSON.stringify(agent.model),
1756
+ agent.tools ? JSON.stringify(agent.tools) : null,
1757
+ agent.defaultOptions ? JSON.stringify(agent.defaultOptions) : null,
1758
+ agent.workflows ? JSON.stringify(agent.workflows) : null,
1759
+ agent.agents ? JSON.stringify(agent.agents) : null,
1760
+ agent.inputProcessors ? JSON.stringify(agent.inputProcessors) : null,
1761
+ agent.outputProcessors ? JSON.stringify(agent.outputProcessors) : null,
1762
+ agent.memory ? JSON.stringify(agent.memory) : null,
1763
+ agent.scorers ? JSON.stringify(agent.scorers) : null,
1764
+ agent.metadata ? JSON.stringify(agent.metadata) : null,
1765
+ nowIso,
1766
+ nowIso,
1767
+ nowIso,
1768
+ nowIso
1769
+ ]
1770
+ );
1771
+ return {
1772
+ ...agent,
1773
+ createdAt: now,
1774
+ updatedAt: now
1775
+ };
1776
+ } catch (error$1) {
1777
+ throw new error.MastraError(
1778
+ {
1779
+ id: storage.createStorageErrorId("PG", "CREATE_AGENT", "FAILED"),
1780
+ domain: error.ErrorDomain.STORAGE,
1781
+ category: error.ErrorCategory.THIRD_PARTY,
1782
+ details: { agentId: agent.id }
1783
+ },
1784
+ error$1
1785
+ );
1786
+ }
1787
+ }
1788
+ async updateAgent({ id, ...updates }) {
1789
+ try {
1790
+ const tableName = getTableName({ indexName: storage.TABLE_AGENTS, schemaName: getSchemaName(this.schema) });
1791
+ const existingAgent = await this.getAgentById({ id });
1792
+ if (!existingAgent) {
1793
+ throw new error.MastraError({
1794
+ id: storage.createStorageErrorId("PG", "UPDATE_AGENT", "NOT_FOUND"),
1795
+ domain: error.ErrorDomain.STORAGE,
1796
+ category: error.ErrorCategory.USER,
1797
+ text: `Agent ${id} not found`,
1798
+ details: { agentId: id }
1799
+ });
1800
+ }
1801
+ const setClauses = [];
1802
+ const values = [];
1803
+ let paramIndex = 1;
1804
+ if (updates.name !== void 0) {
1805
+ setClauses.push(`name = $${paramIndex++}`);
1806
+ values.push(updates.name);
1807
+ }
1808
+ if (updates.description !== void 0) {
1809
+ setClauses.push(`description = $${paramIndex++}`);
1810
+ values.push(updates.description);
1811
+ }
1812
+ if (updates.instructions !== void 0) {
1813
+ setClauses.push(`instructions = $${paramIndex++}`);
1814
+ values.push(updates.instructions);
1815
+ }
1816
+ if (updates.model !== void 0) {
1817
+ setClauses.push(`model = $${paramIndex++}`);
1818
+ values.push(JSON.stringify(updates.model));
1819
+ }
1820
+ if (updates.tools !== void 0) {
1821
+ setClauses.push(`tools = $${paramIndex++}`);
1822
+ values.push(JSON.stringify(updates.tools));
1823
+ }
1824
+ if (updates.defaultOptions !== void 0) {
1825
+ setClauses.push(`"defaultOptions" = $${paramIndex++}`);
1826
+ values.push(JSON.stringify(updates.defaultOptions));
1827
+ }
1828
+ if (updates.workflows !== void 0) {
1829
+ setClauses.push(`workflows = $${paramIndex++}`);
1830
+ values.push(JSON.stringify(updates.workflows));
1831
+ }
1832
+ if (updates.agents !== void 0) {
1833
+ setClauses.push(`agents = $${paramIndex++}`);
1834
+ values.push(JSON.stringify(updates.agents));
1835
+ }
1836
+ if (updates.inputProcessors !== void 0) {
1837
+ setClauses.push(`"inputProcessors" = $${paramIndex++}`);
1838
+ values.push(JSON.stringify(updates.inputProcessors));
1839
+ }
1840
+ if (updates.outputProcessors !== void 0) {
1841
+ setClauses.push(`"outputProcessors" = $${paramIndex++}`);
1842
+ values.push(JSON.stringify(updates.outputProcessors));
1843
+ }
1844
+ if (updates.memory !== void 0) {
1845
+ setClauses.push(`memory = $${paramIndex++}`);
1846
+ values.push(JSON.stringify(updates.memory));
1847
+ }
1848
+ if (updates.scorers !== void 0) {
1849
+ setClauses.push(`scorers = $${paramIndex++}`);
1850
+ values.push(JSON.stringify(updates.scorers));
1851
+ }
1852
+ if (updates.metadata !== void 0) {
1853
+ const mergedMetadata = { ...existingAgent.metadata, ...updates.metadata };
1854
+ setClauses.push(`metadata = $${paramIndex++}`);
1855
+ values.push(JSON.stringify(mergedMetadata));
1856
+ }
1857
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1858
+ setClauses.push(`"updatedAt" = $${paramIndex++}`);
1859
+ values.push(now);
1860
+ setClauses.push(`"updatedAtZ" = $${paramIndex++}`);
1861
+ values.push(now);
1862
+ values.push(id);
1863
+ if (setClauses.length > 2) {
1864
+ await this.client.none(`UPDATE ${tableName} SET ${setClauses.join(", ")} WHERE id = $${paramIndex}`, values);
1865
+ }
1866
+ const updatedAgent = await this.getAgentById({ id });
1867
+ if (!updatedAgent) {
1868
+ throw new error.MastraError({
1869
+ id: storage.createStorageErrorId("PG", "UPDATE_AGENT", "NOT_FOUND_AFTER_UPDATE"),
1870
+ domain: error.ErrorDomain.STORAGE,
1871
+ category: error.ErrorCategory.SYSTEM,
1872
+ text: `Agent ${id} not found after update`,
1873
+ details: { agentId: id }
1874
+ });
1875
+ }
1876
+ return updatedAgent;
1877
+ } catch (error$1) {
1878
+ if (error$1 instanceof error.MastraError) {
1879
+ throw error$1;
1880
+ }
1881
+ throw new error.MastraError(
1882
+ {
1883
+ id: storage.createStorageErrorId("PG", "UPDATE_AGENT", "FAILED"),
1884
+ domain: error.ErrorDomain.STORAGE,
1885
+ category: error.ErrorCategory.THIRD_PARTY,
1886
+ details: { agentId: id }
1887
+ },
1888
+ error$1
1889
+ );
1890
+ }
1891
+ }
1892
+ async deleteAgent({ id }) {
1893
+ try {
1894
+ const tableName = getTableName({ indexName: storage.TABLE_AGENTS, schemaName: getSchemaName(this.schema) });
1895
+ await this.client.none(`DELETE FROM ${tableName} WHERE id = $1`, [id]);
1896
+ } catch (error$1) {
1897
+ throw new error.MastraError(
1898
+ {
1899
+ id: storage.createStorageErrorId("PG", "DELETE_AGENT", "FAILED"),
1900
+ domain: error.ErrorDomain.STORAGE,
1901
+ category: error.ErrorCategory.THIRD_PARTY,
1902
+ details: { agentId: id }
1903
+ },
1904
+ error$1
1905
+ );
1906
+ }
1907
+ }
1908
+ async listAgents(args) {
1909
+ const { page = 0, perPage: perPageInput, orderBy } = args || {};
1910
+ const { field, direction } = this.parseOrderBy(orderBy);
1911
+ if (page < 0) {
1912
+ throw new error.MastraError(
1913
+ {
1914
+ id: storage.createStorageErrorId("PG", "LIST_AGENTS", "INVALID_PAGE"),
1915
+ domain: error.ErrorDomain.STORAGE,
1916
+ category: error.ErrorCategory.USER,
1917
+ details: { page }
1918
+ },
1919
+ new Error("page must be >= 0")
1920
+ );
1921
+ }
1922
+ const perPage = storage.normalizePerPage(perPageInput, 100);
1923
+ const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
1924
+ try {
1925
+ const tableName = getTableName({ indexName: storage.TABLE_AGENTS, schemaName: getSchemaName(this.schema) });
1926
+ const countResult = await this.client.one(`SELECT COUNT(*) as count FROM ${tableName}`);
1927
+ const total = parseInt(countResult.count, 10);
1928
+ if (total === 0) {
1929
+ return {
1930
+ agents: [],
1931
+ total: 0,
1932
+ page,
1933
+ perPage: perPageForResponse,
1934
+ hasMore: false
1935
+ };
1936
+ }
1937
+ const limitValue = perPageInput === false ? total : perPage;
1938
+ const dataResult = await this.client.manyOrNone(
1939
+ `SELECT * FROM ${tableName} ORDER BY "${field}" ${direction} LIMIT $1 OFFSET $2`,
1940
+ [limitValue, offset]
1941
+ );
1942
+ const agents = (dataResult || []).map((row) => this.parseRow(row));
1943
+ return {
1944
+ agents,
1945
+ total,
1946
+ page,
1947
+ perPage: perPageForResponse,
1948
+ hasMore: perPageInput === false ? false : offset + perPage < total
1949
+ };
1950
+ } catch (error$1) {
1951
+ throw new error.MastraError(
1952
+ {
1953
+ id: storage.createStorageErrorId("PG", "LIST_AGENTS", "FAILED"),
1954
+ domain: error.ErrorDomain.STORAGE,
1955
+ category: error.ErrorCategory.THIRD_PARTY
1956
+ },
1957
+ error$1
1958
+ );
1959
+ }
1960
+ }
1961
+ };
1667
1962
  var MemoryPG = class extends storage.MemoryStorage {
1668
1963
  client;
1669
1964
  schema;
@@ -3737,15 +4032,15 @@ var ScoresPG = class extends storage.ScoresStorage {
3737
4032
  } catch (error$1) {
3738
4033
  throw new error.MastraError(
3739
4034
  {
3740
- id: storage.createStorageErrorId("PG", "SAVE_SCORE", "INVALID_PAYLOAD"),
4035
+ id: storage.createStorageErrorId("PG", "SAVE_SCORE", "VALIDATION_FAILED"),
3741
4036
  domain: error.ErrorDomain.STORAGE,
3742
4037
  category: error.ErrorCategory.USER,
3743
4038
  details: {
3744
- scorer: score.scorer.id,
3745
- entityId: score.entityId,
3746
- entityType: score.entityType,
3747
- traceId: score.traceId || "",
3748
- spanId: score.spanId || ""
4039
+ scorer: score.scorer?.id ?? "unknown",
4040
+ entityId: score.entityId ?? "unknown",
4041
+ entityType: score.entityType ?? "unknown",
4042
+ traceId: score.traceId ?? "",
4043
+ spanId: score.spanId ?? ""
3749
4044
  }
3750
4045
  },
3751
4046
  error$1
@@ -3753,6 +4048,7 @@ var ScoresPG = class extends storage.ScoresStorage {
3753
4048
  }
3754
4049
  try {
3755
4050
  const id = crypto.randomUUID();
4051
+ const now = /* @__PURE__ */ new Date();
3756
4052
  const {
3757
4053
  scorer,
3758
4054
  preprocessStepResult,
@@ -3775,14 +4071,15 @@ var ScoresPG = class extends storage.ScoresStorage {
3775
4071
  scorer: scorer ? JSON.stringify(scorer) : null,
3776
4072
  preprocessStepResult: preprocessStepResult ? JSON.stringify(preprocessStepResult) : null,
3777
4073
  analyzeStepResult: analyzeStepResult ? JSON.stringify(analyzeStepResult) : null,
4074
+ metadata: metadata ? JSON.stringify(metadata) : null,
4075
+ additionalContext: additionalContext ? JSON.stringify(additionalContext) : null,
3778
4076
  requestContext: requestContext ? JSON.stringify(requestContext) : null,
3779
4077
  entity: entity ? JSON.stringify(entity) : null,
3780
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3781
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
4078
+ createdAt: now.toISOString(),
4079
+ updatedAt: now.toISOString()
3782
4080
  }
3783
4081
  });
3784
- const scoreFromDb = await this.getScoreById({ id });
3785
- return { score: scoreFromDb };
4082
+ return { score: { ...parsedScore, id, createdAt: now, updatedAt: now } };
3786
4083
  } catch (error$1) {
3787
4084
  throw new error.MastraError(
3788
4085
  {
@@ -4164,17 +4461,17 @@ var WorkflowsPG = class extends storage.WorkflowsStorage {
4164
4461
  var PostgresStore = class extends storage.MastraStorage {
4165
4462
  #db;
4166
4463
  #pgp;
4167
- #config;
4168
4464
  schema;
4169
- isConnected = false;
4465
+ isInitialized = false;
4170
4466
  stores;
4171
4467
  constructor(config) {
4172
4468
  try {
4173
4469
  validateConfig("PostgresStore", config);
4174
4470
  super({ id: config.id, name: "PostgresStore", disableInit: config.disableInit });
4175
4471
  this.schema = config.schemaName || "public";
4472
+ let pgConfig;
4176
4473
  if (isConnectionStringConfig(config)) {
4177
- this.#config = {
4474
+ pgConfig = {
4178
4475
  id: config.id,
4179
4476
  connectionString: config.connectionString,
4180
4477
  max: config.max,
@@ -4182,14 +4479,14 @@ var PostgresStore = class extends storage.MastraStorage {
4182
4479
  ssl: config.ssl
4183
4480
  };
4184
4481
  } else if (isCloudSqlConfig(config)) {
4185
- this.#config = {
4482
+ pgConfig = {
4186
4483
  ...config,
4187
4484
  id: config.id,
4188
4485
  max: config.max,
4189
4486
  idleTimeoutMillis: config.idleTimeoutMillis
4190
4487
  };
4191
4488
  } else if (isHostConfig(config)) {
4192
- this.#config = {
4489
+ pgConfig = {
4193
4490
  id: config.id,
4194
4491
  host: config.host,
4195
4492
  port: config.port,
@@ -4205,7 +4502,22 @@ var PostgresStore = class extends storage.MastraStorage {
4205
4502
  "PostgresStore: invalid config. Provide either {connectionString}, {host,port,database,user,password}, or a pg ClientConfig (e.g., Cloud SQL connector with `stream`)."
4206
4503
  );
4207
4504
  }
4208
- this.stores = {};
4505
+ this.#pgp = pgPromise__default.default();
4506
+ this.#db = this.#pgp(pgConfig);
4507
+ const operations = new StoreOperationsPG({ client: this.#db, schemaName: this.schema });
4508
+ const scores = new ScoresPG({ client: this.#db, operations, schema: this.schema });
4509
+ const workflows = new WorkflowsPG({ client: this.#db, operations, schema: this.schema });
4510
+ const memory = new MemoryPG({ client: this.#db, schema: this.schema, operations });
4511
+ const observability = new ObservabilityPG({ client: this.#db, operations, schema: this.schema });
4512
+ const agents = new AgentsPG({ client: this.#db, schema: this.schema });
4513
+ this.stores = {
4514
+ operations,
4515
+ scores,
4516
+ workflows,
4517
+ memory,
4518
+ observability,
4519
+ agents
4520
+ };
4209
4521
  } catch (e) {
4210
4522
  throw new error.MastraError(
4211
4523
  {
@@ -4218,33 +4530,19 @@ var PostgresStore = class extends storage.MastraStorage {
4218
4530
  }
4219
4531
  }
4220
4532
  async init() {
4221
- if (this.isConnected) {
4533
+ if (this.isInitialized) {
4222
4534
  return;
4223
4535
  }
4224
4536
  try {
4225
- this.isConnected = true;
4226
- this.#pgp = pgPromise__default.default();
4227
- this.#db = this.#pgp(this.#config);
4228
- const operations = new StoreOperationsPG({ client: this.#db, schemaName: this.schema });
4229
- const scores = new ScoresPG({ client: this.#db, operations, schema: this.schema });
4230
- const workflows = new WorkflowsPG({ client: this.#db, operations, schema: this.schema });
4231
- const memory = new MemoryPG({ client: this.#db, schema: this.schema, operations });
4232
- const observability = new ObservabilityPG({ client: this.#db, operations, schema: this.schema });
4233
- this.stores = {
4234
- operations,
4235
- scores,
4236
- workflows,
4237
- memory,
4238
- observability
4239
- };
4537
+ this.isInitialized = true;
4240
4538
  await super.init();
4241
4539
  try {
4242
- await operations.createAutomaticIndexes();
4540
+ await this.stores.operations.createAutomaticIndexes();
4243
4541
  } catch (indexError) {
4244
4542
  console.warn("Failed to create indexes:", indexError);
4245
4543
  }
4246
4544
  } catch (error$1) {
4247
- this.isConnected = false;
4545
+ this.isInitialized = false;
4248
4546
  throw new error.MastraError(
4249
4547
  {
4250
4548
  id: storage.createStorageErrorId("PG", "INIT", "FAILED"),
@@ -4256,15 +4554,9 @@ var PostgresStore = class extends storage.MastraStorage {
4256
4554
  }
4257
4555
  }
4258
4556
  get db() {
4259
- if (!this.#db) {
4260
- throw new Error(`PostgresStore: Store is not initialized, please call "init()" first.`);
4261
- }
4262
4557
  return this.#db;
4263
4558
  }
4264
4559
  get pgp() {
4265
- if (!this.#pgp) {
4266
- throw new Error(`PostgresStore: Store is not initialized, please call "init()" first.`);
4267
- }
4268
4560
  return this.#pgp;
4269
4561
  }
4270
4562
  get supports() {
@@ -4276,7 +4568,8 @@ var PostgresStore = class extends storage.MastraStorage {
4276
4568
  deleteMessages: true,
4277
4569
  observabilityInstance: true,
4278
4570
  indexManagement: true,
4279
- listScoresBySpan: true
4571
+ listScoresBySpan: true,
4572
+ agents: true
4280
4573
  };
4281
4574
  }
4282
4575
  async createTable({