@mastra/pg 1.8.6 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -8463,17 +8463,34 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8463
8463
  );
8464
8464
  }
8465
8465
  }
8466
- async getObservationalMemoryHistory(threadId, resourceId, limit = 10) {
8466
+ async getObservationalMemoryHistory(threadId, resourceId, limit = 10, options) {
8467
8467
  try {
8468
8468
  const lookupKey = this.getOMKey(threadId, resourceId);
8469
8469
  const tableName = getTableName3({
8470
8470
  indexName: OM_TABLE,
8471
8471
  schemaName: getSchemaName3(this.#schema)
8472
8472
  });
8473
- const result = await this.#db.client.manyOrNone(
8474
- `SELECT * FROM ${tableName} WHERE "lookupKey" = $1 ORDER BY "generationCount" DESC LIMIT $2`,
8475
- [lookupKey, limit]
8476
- );
8473
+ const conditions = [`"lookupKey" = $1`];
8474
+ const params = [lookupKey];
8475
+ let paramIndex = 2;
8476
+ if (options?.from) {
8477
+ conditions.push(`"createdAtZ" >= $${paramIndex}`);
8478
+ params.push(options.from.toISOString());
8479
+ paramIndex++;
8480
+ }
8481
+ if (options?.to) {
8482
+ conditions.push(`"createdAtZ" <= $${paramIndex}`);
8483
+ params.push(options.to.toISOString());
8484
+ paramIndex++;
8485
+ }
8486
+ params.push(limit);
8487
+ let sql = `SELECT * FROM ${tableName} WHERE ${conditions.join(" AND ")} ORDER BY "generationCount" DESC LIMIT $${paramIndex}`;
8488
+ paramIndex++;
8489
+ if (options?.offset != null) {
8490
+ params.push(options.offset);
8491
+ sql += ` OFFSET $${paramIndex}`;
8492
+ }
8493
+ const result = await this.#db.client.manyOrNone(sql, params);
8477
8494
  if (!result) return [];
8478
8495
  return result.map((row) => this.parseOMRow(row));
8479
8496
  } catch (error) {
@@ -9026,6 +9043,45 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
9026
9043
  );
9027
9044
  }
9028
9045
  }
9046
+ async updateObservationalMemoryConfig(input) {
9047
+ try {
9048
+ const tableName = getTableName3({
9049
+ indexName: OM_TABLE,
9050
+ schemaName: getSchemaName3(this.#schema)
9051
+ });
9052
+ const selectResult = await this.#db.client.query(`SELECT config FROM ${tableName} WHERE id = $1`, [input.id]);
9053
+ if (selectResult.rowCount === 0) {
9054
+ throw new MastraError({
9055
+ id: createStorageErrorId("PG", "UPDATE_OM_CONFIG", "NOT_FOUND"),
9056
+ text: `Observational memory record not found: ${input.id}`,
9057
+ domain: ErrorDomain.STORAGE,
9058
+ category: ErrorCategory.THIRD_PARTY,
9059
+ details: { id: input.id }
9060
+ });
9061
+ }
9062
+ const row = selectResult.rows[0];
9063
+ const existing = row.config ? typeof row.config === "string" ? JSON.parse(row.config) : row.config : {};
9064
+ const merged = this.deepMergeConfig(existing, input.config);
9065
+ const nowStr = (/* @__PURE__ */ new Date()).toISOString();
9066
+ await this.#db.client.query(
9067
+ `UPDATE ${tableName} SET config = $1, "updatedAt" = $2, "updatedAtZ" = $3 WHERE id = $4`,
9068
+ [JSON.stringify(merged), nowStr, nowStr, input.id]
9069
+ );
9070
+ } catch (error) {
9071
+ if (error instanceof MastraError) {
9072
+ throw error;
9073
+ }
9074
+ throw new MastraError(
9075
+ {
9076
+ id: createStorageErrorId("PG", "UPDATE_OM_CONFIG", "FAILED"),
9077
+ domain: ErrorDomain.STORAGE,
9078
+ category: ErrorCategory.THIRD_PARTY,
9079
+ details: { id: input.id }
9080
+ },
9081
+ error
9082
+ );
9083
+ }
9084
+ }
9029
9085
  // ============================================
9030
9086
  // Async Buffering Methods
9031
9087
  // ============================================