@mastra/pg 1.8.6 → 1.9.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 1.9.0-alpha.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Implemented `updateObservationalMemoryConfig()` in Postgres, LibSQL, and MongoDB storage adapters. This enables per-record config overrides for observational memory thresholds, supporting the new `memory.updateObservationalMemoryConfig()` API in `@mastra/memory`. ([#15115](https://github.com/mastra-ai/mastra/pull/15115))
8
+
9
+ ### Patch Changes
10
+
11
+ - Fixed observational memory date-range queries to use ISO-string timestamp columns (`createdAtZ`) instead of the raw `createdAt` column, ensuring correct filtering when querying observations by date range. ([#15115](https://github.com/mastra-ai/mastra/pull/15115))
12
+
13
+ - Updated dependencies [[`a50d220`](https://github.com/mastra-ai/mastra/commit/a50d220b01ecbc5644d489a3d446c3bd4ab30245)]:
14
+ - @mastra/core@1.23.0-alpha.9
15
+
3
16
  ## 1.8.6
4
17
 
5
18
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-pg
3
3
  description: Documentation for @mastra/pg. Use when working with @mastra/pg APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/pg"
6
- version: "1.8.6"
6
+ version: "1.9.0-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.8.6",
2
+ "version": "1.9.0-alpha.0",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -8488,17 +8488,34 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8488
8488
  );
8489
8489
  }
8490
8490
  }
8491
- async getObservationalMemoryHistory(threadId, resourceId, limit = 10) {
8491
+ async getObservationalMemoryHistory(threadId, resourceId, limit = 10, options) {
8492
8492
  try {
8493
8493
  const lookupKey = this.getOMKey(threadId, resourceId);
8494
8494
  const tableName = getTableName3({
8495
8495
  indexName: OM_TABLE,
8496
8496
  schemaName: getSchemaName3(this.#schema)
8497
8497
  });
8498
- const result = await this.#db.client.manyOrNone(
8499
- `SELECT * FROM ${tableName} WHERE "lookupKey" = $1 ORDER BY "generationCount" DESC LIMIT $2`,
8500
- [lookupKey, limit]
8501
- );
8498
+ const conditions = [`"lookupKey" = $1`];
8499
+ const params = [lookupKey];
8500
+ let paramIndex = 2;
8501
+ if (options?.from) {
8502
+ conditions.push(`"createdAtZ" >= $${paramIndex}`);
8503
+ params.push(options.from.toISOString());
8504
+ paramIndex++;
8505
+ }
8506
+ if (options?.to) {
8507
+ conditions.push(`"createdAtZ" <= $${paramIndex}`);
8508
+ params.push(options.to.toISOString());
8509
+ paramIndex++;
8510
+ }
8511
+ params.push(limit);
8512
+ let sql = `SELECT * FROM ${tableName} WHERE ${conditions.join(" AND ")} ORDER BY "generationCount" DESC LIMIT $${paramIndex}`;
8513
+ paramIndex++;
8514
+ if (options?.offset != null) {
8515
+ params.push(options.offset);
8516
+ sql += ` OFFSET $${paramIndex}`;
8517
+ }
8518
+ const result = await this.#db.client.manyOrNone(sql, params);
8502
8519
  if (!result) return [];
8503
8520
  return result.map((row) => this.parseOMRow(row));
8504
8521
  } catch (error$1) {
@@ -9051,6 +9068,45 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9051
9068
  );
9052
9069
  }
9053
9070
  }
9071
+ async updateObservationalMemoryConfig(input) {
9072
+ try {
9073
+ const tableName = getTableName3({
9074
+ indexName: OM_TABLE,
9075
+ schemaName: getSchemaName3(this.#schema)
9076
+ });
9077
+ const selectResult = await this.#db.client.query(`SELECT config FROM ${tableName} WHERE id = $1`, [input.id]);
9078
+ if (selectResult.rowCount === 0) {
9079
+ throw new error.MastraError({
9080
+ id: storage.createStorageErrorId("PG", "UPDATE_OM_CONFIG", "NOT_FOUND"),
9081
+ text: `Observational memory record not found: ${input.id}`,
9082
+ domain: error.ErrorDomain.STORAGE,
9083
+ category: error.ErrorCategory.THIRD_PARTY,
9084
+ details: { id: input.id }
9085
+ });
9086
+ }
9087
+ const row = selectResult.rows[0];
9088
+ const existing = row.config ? typeof row.config === "string" ? JSON.parse(row.config) : row.config : {};
9089
+ const merged = this.deepMergeConfig(existing, input.config);
9090
+ const nowStr = (/* @__PURE__ */ new Date()).toISOString();
9091
+ await this.#db.client.query(
9092
+ `UPDATE ${tableName} SET config = $1, "updatedAt" = $2, "updatedAtZ" = $3 WHERE id = $4`,
9093
+ [JSON.stringify(merged), nowStr, nowStr, input.id]
9094
+ );
9095
+ } catch (error$1) {
9096
+ if (error$1 instanceof error.MastraError) {
9097
+ throw error$1;
9098
+ }
9099
+ throw new error.MastraError(
9100
+ {
9101
+ id: storage.createStorageErrorId("PG", "UPDATE_OM_CONFIG", "FAILED"),
9102
+ domain: error.ErrorDomain.STORAGE,
9103
+ category: error.ErrorCategory.THIRD_PARTY,
9104
+ details: { id: input.id }
9105
+ },
9106
+ error$1
9107
+ );
9108
+ }
9109
+ }
9054
9110
  // ============================================
9055
9111
  // Async Buffering Methods
9056
9112
  // ============================================