@mastra/pg 1.32.0-alpha.5 → 1.32.0-alpha.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.
@@ -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.32.0-alpha.5"
6
+ version: "1.32.0-alpha.6"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.32.0-alpha.5",
2
+ "version": "1.32.0-alpha.6",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
@@ -185,12 +185,14 @@ var PGFilterTranslator = class extends _mastra_core_vector_filter.BaseFilterTran
185
185
  if (key === "$options") continue;
186
186
  const newPath = currentPath ? `${currentPath}.${key}` : key;
187
187
  if (this.isLogicalOperator(key)) result[key] = Array.isArray(value) ? value.map((filter) => this.translateNode(filter)) : this.translateNode(value);
188
- else if (this.isOperator(key)) if (this.isArrayOperator(key) && !Array.isArray(value) && key !== "$elemMatch") result[key] = [value];
189
- else if (this.isBasicOperator(key) && Array.isArray(value)) result[key] = JSON.stringify(value);
190
- else result[key] = value;
191
- else if (typeof value === "object" && value !== null) if (Object.keys(value).some((k) => this.isOperator(k))) result[newPath] = this.translateNode(value);
192
- else Object.assign(result, this.translateNode(value, newPath));
193
- else result[newPath] = this.translateNode(value);
188
+ else if (this.isOperator(key)) {
189
+ if (this.isArrayOperator(key) && !Array.isArray(value) && key !== "$elemMatch") result[key] = [value];
190
+ else if (this.isBasicOperator(key) && Array.isArray(value)) result[key] = JSON.stringify(value);
191
+ else result[key] = value;
192
+ } else if (typeof value === "object" && value !== null) {
193
+ if (Object.keys(value).some((k) => this.isOperator(k))) result[newPath] = this.translateNode(value);
194
+ else Object.assign(result, this.translateNode(value, newPath));
195
+ } else result[newPath] = this.translateNode(value);
194
196
  }
195
197
  return result;
196
198
  }
@@ -1451,19 +1453,21 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
1451
1453
  try {
1452
1454
  existingIndexInfo = await this.describeIndexMetadata({ indexName }, client);
1453
1455
  dimension = existingIndexInfo.dimension;
1454
- if (isConfigEmpty && existingIndexInfo.metric === metric) if (existingIndexInfo.type === "flat") this.logger?.debug(`No index exists for ${vectorIndexName}, will create default ivfflat index`);
1455
- else {
1456
- this.logger?.debug(`Index ${vectorIndexName} already exists (type: ${existingIndexInfo.type}, metric: ${existingIndexInfo.metric}), preserving existing configuration`);
1457
- const cacheKey = await this.getIndexCacheKey({
1458
- indexName,
1459
- dimension,
1460
- type: existingIndexInfo.type,
1461
- metric: existingIndexInfo.metric,
1462
- vectorType: existingIndexInfo.vectorType
1463
- });
1464
- this.createdIndexes.set(indexName, cacheKey);
1465
- this.indexVectorTypes.set(indexName, existingIndexInfo.vectorType);
1466
- return;
1456
+ if (isConfigEmpty && existingIndexInfo.metric === metric) {
1457
+ if (existingIndexInfo.type === "flat") this.logger?.debug(`No index exists for ${vectorIndexName}, will create default ivfflat index`);
1458
+ else {
1459
+ this.logger?.debug(`Index ${vectorIndexName} already exists (type: ${existingIndexInfo.type}, metric: ${existingIndexInfo.metric}), preserving existing configuration`);
1460
+ const cacheKey = await this.getIndexCacheKey({
1461
+ indexName,
1462
+ dimension,
1463
+ type: existingIndexInfo.type,
1464
+ metric: existingIndexInfo.metric,
1465
+ vectorType: existingIndexInfo.vectorType
1466
+ });
1467
+ this.createdIndexes.set(indexName, cacheKey);
1468
+ this.indexVectorTypes.set(indexName, existingIndexInfo.vectorType);
1469
+ return;
1470
+ }
1467
1471
  }
1468
1472
  let configMatches = existingIndexInfo.metric === metric && existingIndexInfo.type === indexType;
1469
1473
  if (indexType === "hnsw") configMatches = configMatches && existingIndexInfo.config.m === (indexConfig.hnsw?.m ?? 8) && existingIndexInfo.config.efConstruction === (indexConfig.hnsw?.efConstruction ?? 32);
@@ -2969,19 +2973,13 @@ var PgDB = class extends _mastra_core_base.MastraBase {
2969
2973
  return filtered;
2970
2974
  }
2971
2975
  async hasColumn(table, column) {
2972
- const schema = this.schemaName || "public";
2973
2976
  const snapshot = this.schemaSnapshot;
2974
2977
  if (snapshot) {
2975
2978
  const columns = snapshot.columns.get(table);
2976
2979
  if (!columns) return false;
2977
2980
  return columns.has(column) || columns.has(column.toLowerCase());
2978
2981
  }
2979
- return !!await this.client.oneOrNone(`SELECT 1 FROM information_schema.columns WHERE table_schema = $1 AND table_name = $2 AND (column_name = $3 OR column_name = $4)`, [
2980
- schema,
2981
- table,
2982
- column,
2983
- column.toLowerCase()
2984
- ]);
2982
+ return await this.getColumnType(table, column) !== null;
2985
2983
  }
2986
2984
  /**
2987
2985
  * Returns the Postgres data type of a column (e.g. `jsonb`, `json`, `text`),
@@ -3003,7 +3001,7 @@ var PgDB = class extends _mastra_core_base.MastraBase {
3003
3001
  const cached = this.columnTypeCache.get(table)?.get(column);
3004
3002
  if (cached !== void 0) return cached;
3005
3003
  const schema = this.schemaName || "public";
3006
- const dataType = (await this.client.oneOrNone(`SELECT data_type FROM information_schema.columns WHERE table_schema = $1 AND table_name = $2 AND (column_name = $3 OR column_name = $4)`, [
3004
+ const dataType = (await this.client.oneOrNone(`SELECT data_type FROM information_schema.columns WHERE table_schema = $1 AND table_name = $2 AND (column_name = $3 OR column_name = $4) ORDER BY (column_name = $3) DESC LIMIT 1`, [
3007
3005
  schema,
3008
3006
  table,
3009
3007
  column,
@@ -5392,15 +5390,19 @@ var BackgroundTasksPG = class BackgroundTasksPG extends _mastra_core_storage.Bac
5392
5390
  where += ` AND "status" = $${paramIdx++}`;
5393
5391
  params.push(options.expectedStatus);
5394
5392
  }
5395
- if (options?.expectedOwnerId !== void 0) if (options.expectedOwnerId === null) where += ` AND "ownerId" IS NULL`;
5396
- else {
5397
- where += ` AND "ownerId" = $${paramIdx++}`;
5398
- params.push(options.expectedOwnerId);
5393
+ if (options?.expectedOwnerId !== void 0) {
5394
+ if (options.expectedOwnerId === null) where += ` AND "ownerId" IS NULL`;
5395
+ else {
5396
+ where += ` AND "ownerId" = $${paramIdx++}`;
5397
+ params.push(options.expectedOwnerId);
5398
+ }
5399
5399
  }
5400
- if (options?.expectedLeaseExpiresAt !== void 0) if (options.expectedLeaseExpiresAt === null) where += ` AND "leaseExpiresAtZ" IS NULL`;
5401
- else {
5402
- where += ` AND "leaseExpiresAtZ" = $${paramIdx++}`;
5403
- params.push(options.expectedLeaseExpiresAt.toISOString());
5400
+ if (options?.expectedLeaseExpiresAt !== void 0) {
5401
+ if (options.expectedLeaseExpiresAt === null) where += ` AND "leaseExpiresAtZ" IS NULL`;
5402
+ else {
5403
+ where += ` AND "leaseExpiresAtZ" = $${paramIdx++}`;
5404
+ params.push(options.expectedLeaseExpiresAt.toISOString());
5405
+ }
5404
5406
  }
5405
5407
  return ((await this.#db.client.query(`UPDATE ${table} SET ${setClauses.join(", ")} WHERE ${where}`, params)).rowCount ?? 0) > 0;
5406
5408
  }
@@ -5698,9 +5700,10 @@ var ChannelsPG = class ChannelsPG extends _mastra_core_storage.ChannelsStorage {
5698
5700
  await this.#db.clearTable({ tableName: _mastra_core_storage.TABLE_CHANNEL_CONFIG });
5699
5701
  }
5700
5702
  async saveInstallation(installation) {
5703
+ const schemaName = getSchemaName$5(this.#schema);
5701
5704
  const tableName = getTableName$5({
5702
5705
  indexName: _mastra_core_storage.TABLE_CHANNEL_INSTALLATIONS,
5703
- schemaName: getSchemaName$5(this.#schema)
5706
+ schemaName
5704
5707
  });
5705
5708
  const now = (/* @__PURE__ */ new Date()).toISOString();
5706
5709
  const createdAt = installation.createdAt?.toISOString() ?? now;
@@ -5731,47 +5734,53 @@ var ChannelsPG = class ChannelsPG extends _mastra_core_storage.ChannelsStorage {
5731
5734
  ]);
5732
5735
  }
5733
5736
  async getInstallation(id) {
5737
+ const schemaName = getSchemaName$5(this.#schema);
5734
5738
  const tableName = getTableName$5({
5735
5739
  indexName: _mastra_core_storage.TABLE_CHANNEL_INSTALLATIONS,
5736
- schemaName: getSchemaName$5(this.#schema)
5740
+ schemaName
5737
5741
  });
5738
5742
  const row = await this.#db.readClient.oneOrNone(`SELECT * FROM ${tableName} WHERE "id" = $1`, [id]);
5739
5743
  return row ? this.#parseInstallationRow(row) : null;
5740
5744
  }
5741
5745
  async getInstallationByAgent(platform, agentId) {
5746
+ const schemaName = getSchemaName$5(this.#schema);
5742
5747
  const tableName = getTableName$5({
5743
5748
  indexName: _mastra_core_storage.TABLE_CHANNEL_INSTALLATIONS,
5744
- schemaName: getSchemaName$5(this.#schema)
5749
+ schemaName
5745
5750
  });
5746
5751
  const row = await this.#db.readClient.oneOrNone(`SELECT * FROM ${tableName} WHERE "platform" = $1 AND "agentId" = $2 ORDER BY CASE "status" WHEN 'active' THEN 0 WHEN 'pending' THEN 1 ELSE 2 END, "updatedAt" DESC LIMIT 1`, [platform, agentId]);
5747
5752
  return row ? this.#parseInstallationRow(row) : null;
5748
5753
  }
5749
5754
  async getInstallationByWebhookId(webhookId) {
5755
+ const schemaName = getSchemaName$5(this.#schema);
5750
5756
  const tableName = getTableName$5({
5751
5757
  indexName: _mastra_core_storage.TABLE_CHANNEL_INSTALLATIONS,
5752
- schemaName: getSchemaName$5(this.#schema)
5758
+ schemaName
5753
5759
  });
5754
5760
  const row = await this.#db.readClient.oneOrNone(`SELECT * FROM ${tableName} WHERE "webhookId" = $1`, [webhookId]);
5755
5761
  return row ? this.#parseInstallationRow(row) : null;
5756
5762
  }
5757
5763
  async listInstallations(platform) {
5764
+ const schemaName = getSchemaName$5(this.#schema);
5758
5765
  const tableName = getTableName$5({
5759
5766
  indexName: _mastra_core_storage.TABLE_CHANNEL_INSTALLATIONS,
5760
- schemaName: getSchemaName$5(this.#schema)
5767
+ schemaName
5761
5768
  });
5762
5769
  return (await this.#db.readClient.manyOrNone(`SELECT * FROM ${tableName} WHERE "platform" = $1 ORDER BY "createdAt" DESC`, [platform])).map((row) => this.#parseInstallationRow(row));
5763
5770
  }
5764
5771
  async deleteInstallation(id) {
5772
+ const schemaName = getSchemaName$5(this.#schema);
5765
5773
  const tableName = getTableName$5({
5766
5774
  indexName: _mastra_core_storage.TABLE_CHANNEL_INSTALLATIONS,
5767
- schemaName: getSchemaName$5(this.#schema)
5775
+ schemaName
5768
5776
  });
5769
5777
  await this.#db.client.none(`DELETE FROM ${tableName} WHERE "id" = $1`, [id]);
5770
5778
  }
5771
5779
  async saveConfig(config) {
5780
+ const schemaName = getSchemaName$5(this.#schema);
5772
5781
  const tableName = getTableName$5({
5773
5782
  indexName: _mastra_core_storage.TABLE_CHANNEL_CONFIG,
5774
- schemaName: getSchemaName$5(this.#schema)
5783
+ schemaName
5775
5784
  });
5776
5785
  const now = config.updatedAt.toISOString();
5777
5786
  await this.#db.client.none(`INSERT INTO ${tableName} ("platform", "data", "updatedAt", "updatedAtZ")
@@ -5787,9 +5796,10 @@ var ChannelsPG = class ChannelsPG extends _mastra_core_storage.ChannelsStorage {
5787
5796
  ]);
5788
5797
  }
5789
5798
  async getConfig(platform) {
5799
+ const schemaName = getSchemaName$5(this.#schema);
5790
5800
  const tableName = getTableName$5({
5791
5801
  indexName: _mastra_core_storage.TABLE_CHANNEL_CONFIG,
5792
- schemaName: getSchemaName$5(this.#schema)
5802
+ schemaName
5793
5803
  });
5794
5804
  const row = await this.#db.readClient.oneOrNone(`SELECT * FROM ${tableName} WHERE "platform" = $1`, [platform]);
5795
5805
  if (!row) return null;
@@ -5800,9 +5810,10 @@ var ChannelsPG = class ChannelsPG extends _mastra_core_storage.ChannelsStorage {
5800
5810
  };
5801
5811
  }
5802
5812
  async deleteConfig(platform) {
5813
+ const schemaName = getSchemaName$5(this.#schema);
5803
5814
  const tableName = getTableName$5({
5804
5815
  indexName: _mastra_core_storage.TABLE_CHANNEL_CONFIG,
5805
- schemaName: getSchemaName$5(this.#schema)
5816
+ schemaName
5806
5817
  });
5807
5818
  await this.#db.client.none(`DELETE FROM ${tableName} WHERE "platform" = $1`, [platform]);
5808
5819
  }
@@ -11720,10 +11731,11 @@ const DB_NOW_MS = `(EXTRACT(EPOCH FROM clock_timestamp()) * 1000)::bigint`;
11720
11731
  */
11721
11732
  async function assertRunFence(t, claimsTable, fence, operation) {
11722
11733
  const row = await t.oneOrNone(`SELECT generation, "ownerId" FROM ${claimsTable} WHERE "runId" = $1 FOR SHARE`, [fence.runId]);
11723
- if (!(0, _mastra_core_storage.matchesRunFence)(row && {
11734
+ const current = row && {
11724
11735
  generation: Number(row.generation),
11725
11736
  ownerId: row.ownerId
11726
- }, fence)) throw new _mastra_core_storage.RunFenceConflictError(fence, operation);
11737
+ };
11738
+ if (!(0, _mastra_core_storage.matchesRunFence)(current, fence)) throw new _mastra_core_storage.RunFenceConflictError(fence, operation);
11727
11739
  }
11728
11740
  /**
11729
11741
  * Runs `write` directly when it carries no fence, or in a transaction behind
@@ -14850,9 +14862,10 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
14850
14862
  async updateNotificationRow(threadId, id, data) {
14851
14863
  const entries = Object.entries(data).filter(([, value]) => value !== void 0);
14852
14864
  if (entries.length === 0) return;
14865
+ const schemaName = getSchemaName$5(this.#schema);
14853
14866
  const tableName = getTableName$5({
14854
14867
  indexName: _mastra_core_storage.TABLE_NOTIFICATIONS,
14855
- schemaName: getSchemaName$5(this.#schema)
14868
+ schemaName
14856
14869
  });
14857
14870
  const setColumns = entries.map(([key], index) => `"${(0, _mastra_core_utils.parseSqlIdentifier)(key, "column name")}" = $${index + 1}`);
14858
14871
  const values = entries.map(([key, value]) => {
@@ -14951,9 +14964,10 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
14951
14964
  }
14952
14965
  const limit = input.limit ? ` LIMIT $${args.length + 1}` : "";
14953
14966
  if (input.limit) args.push(input.limit);
14967
+ const schemaName = getSchemaName$5(this.#schema);
14954
14968
  const tableName = getTableName$5({
14955
14969
  indexName: _mastra_core_storage.TABLE_NOTIFICATIONS,
14956
- schemaName: getSchemaName$5(this.#schema)
14970
+ schemaName
14957
14971
  });
14958
14972
  return (await this.#db.readClient.manyOrNone(`SELECT * FROM ${tableName} WHERE ${conditions.join(" AND ")} ORDER BY "updatedAt" DESC${limit}`, args)).map((row) => rowToNotification(row));
14959
14973
  }
@@ -14974,9 +14988,10 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
14974
14988
  }
14975
14989
  const limit = input.limit ? ` LIMIT $${args.length + 1}` : "";
14976
14990
  if (input.limit) args.push(input.limit);
14991
+ const schemaName = getSchemaName$5(this.#schema);
14977
14992
  const tableName = getTableName$5({
14978
14993
  indexName: _mastra_core_storage.TABLE_NOTIFICATIONS,
14979
- schemaName: getSchemaName$5(this.#schema)
14994
+ schemaName
14980
14995
  });
14981
14996
  return (await this.#db.readClient.manyOrNone(`SELECT * FROM ${tableName} WHERE ${conditions.join(" AND ")} ORDER BY CASE WHEN "deliverAt" IS NULL THEN "summaryAt" WHEN "summaryAt" IS NULL THEN "deliverAt" WHEN "deliverAt" <= "summaryAt" THEN "deliverAt" ELSE "summaryAt" END ASC, "updatedAt" ASC${limit}`, args)).map((row) => rowToNotification(row));
14982
14997
  }
@@ -14988,9 +15003,10 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
14988
15003
  * lagging read replica cannot yield stale or missing rows mid-update.
14989
15004
  */
14990
15005
  async #getNotification(client, input) {
15006
+ const schemaName = getSchemaName$5(this.#schema);
14991
15007
  const tableName = getTableName$5({
14992
15008
  indexName: _mastra_core_storage.TABLE_NOTIFICATIONS,
14993
- schemaName: getSchemaName$5(this.#schema)
15009
+ schemaName
14994
15010
  });
14995
15011
  const row = await client.oneOrNone(`SELECT * FROM ${tableName} WHERE "threadId" = $1 AND "id" = $2 LIMIT 1`, [input.threadId, input.id]);
14996
15012
  return row ? rowToNotification(row) : null;
@@ -15038,9 +15054,10 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
15038
15054
  };
15039
15055
  const columns = Object.keys(assignments);
15040
15056
  const setClause = columns.map((column, index) => `"${(0, _mastra_core_utils.parseSqlIdentifier)(column, "column name")}" = $${index + 1}`).join(", ");
15057
+ const schemaName = getSchemaName$5(this.#schema);
15041
15058
  const tableName = getTableName$5({
15042
15059
  indexName: _mastra_core_storage.TABLE_NOTIFICATIONS,
15043
- schemaName: getSchemaName$5(this.#schema)
15060
+ schemaName
15044
15061
  });
15045
15062
  return (await this.#db.client.manyOrNone(`UPDATE ${tableName} SET ${setClause} WHERE "threadId" = $${columns.length + 1} AND "id" = ANY($${columns.length + 2}::text[]) RETURNING *`, [
15046
15063
  ...Object.values(assignments),
@@ -15050,9 +15067,10 @@ var NotificationsPG = class NotificationsPG extends _mastra_core_storage.Notific
15050
15067
  }
15051
15068
  async findCoalescable(input) {
15052
15069
  if (!input.dedupeKey && !input.coalesceKey) return void 0;
15070
+ const schemaName = getSchemaName$5(this.#schema);
15053
15071
  const tableName = getTableName$5({
15054
15072
  indexName: _mastra_core_storage.TABLE_NOTIFICATIONS,
15055
- schemaName: getSchemaName$5(this.#schema)
15073
+ schemaName
15056
15074
  });
15057
15075
  const row = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE "threadId" = $1 AND "source" = $2 AND "kind" = $3 AND "status" = $4 AND (("agentId" = $5::text) OR ("agentId" IS NULL AND $5::text IS NULL)) AND (("resourceId" = $6::text) OR ("resourceId" IS NULL AND $6::text IS NULL)) AND (($7::text IS NOT NULL AND "dedupeKey" = $7::text) OR ($8::text IS NOT NULL AND "coalesceKey" = $8::text)) ORDER BY "updatedAt" DESC LIMIT 1`, [
15058
15076
  input.threadId,
@@ -15594,18 +15612,18 @@ var ObservabilityPG = class ObservabilityPG extends _mastra_core_storage.Observa
15594
15612
  case _mastra_core_storage.TraceStatus.RUNNING:
15595
15613
  conditions.push(`r."endedAtZ" IS NULL AND r."error" IS NULL`);
15596
15614
  break;
15597
- case _mastra_core_storage.TraceStatus.SUCCESS:
15598
- conditions.push(`r."endedAtZ" IS NOT NULL AND r."error" IS NULL`);
15599
- break;
15615
+ case _mastra_core_storage.TraceStatus.SUCCESS: conditions.push(`r."endedAtZ" IS NOT NULL AND r."error" IS NULL`);
15600
15616
  }
15601
- if (filters.hasChildError !== void 0) if (filters.hasChildError) conditions.push(`EXISTS (
15617
+ if (filters.hasChildError !== void 0) {
15618
+ if (filters.hasChildError) conditions.push(`EXISTS (
15602
15619
  SELECT 1 FROM ${tableName} c
15603
15620
  WHERE c."traceId" = r."traceId" AND c."error" IS NOT NULL
15604
15621
  )`);
15605
- else conditions.push(`NOT EXISTS (
15622
+ else conditions.push(`NOT EXISTS (
15606
15623
  SELECT 1 FROM ${tableName} c
15607
15624
  WHERE c."traceId" = r."traceId" AND c."error" IS NOT NULL
15608
15625
  )`);
15626
+ }
15609
15627
  }
15610
15628
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
15611
15629
  const orderField = orderBy?.field ?? "startedAt";
@@ -16785,9 +16803,6 @@ function additiveColumns(schema) {
16785
16803
  }
16786
16804
  ];
16787
16805
  }
16788
- /** Existence probe for an additive column. Params: schema, table, column. */
16789
- const columnExistsSQL = `SELECT 1 FROM information_schema.columns
16790
- WHERE table_schema = $1 AND table_name = $2 AND column_name = $3`;
16791
16806
  /** Index CREATEs. Safe to run repeatedly. */
16792
16807
  function allIndexDDL(schema) {
16793
16808
  return tableIndexes().map((spec) => indexDDL(schema, spec));
@@ -16795,7 +16810,7 @@ function allIndexDDL(schema) {
16795
16810
  //#endregion
16796
16811
  //#region src/storage/domains/observability/v-next/discovery.ts
16797
16812
  const DEFAULT_TTL_SECONDS = 300;
16798
- const DEFAULT_LOOKBACK_SECONDS = 720 * 60 * 60;
16813
+ const DEFAULT_LOOKBACK_SECONDS = 2592e3;
16799
16814
  /** All signal tables that contain a column. Used by cross-signal discovery. */
16800
16815
  const SIGNAL_TABLES_WITH_CONTEXT = [
16801
16816
  TABLE_SPAN_EVENTS,
@@ -18040,7 +18055,7 @@ function shiftRange(range, period) {
18040
18055
  offset = 864e5;
18041
18056
  break;
18042
18057
  case "previous_week":
18043
- offset = 7 * 864e5;
18058
+ offset = 6048e5;
18044
18059
  break;
18045
18060
  default: offset = duration;
18046
18061
  }
@@ -18160,12 +18175,14 @@ function pushFeedbackIdentity(acc, feedbackType, feedbackSource) {
18160
18175
  acc.conditions.push(`"valueNumber" IS NOT NULL`);
18161
18176
  }
18162
18177
  async function createFeedback(client, schema, args) {
18163
- const insert = buildInsert(schema, TABLE_FEEDBACK_EVENTS, [feedbackRecordToRow(args.feedback)], FEEDBACK_UPSERT_CLAUSE);
18178
+ const row = feedbackRecordToRow(args.feedback);
18179
+ const insert = buildInsert(schema, TABLE_FEEDBACK_EVENTS, [row], FEEDBACK_UPSERT_CLAUSE);
18164
18180
  if (insert) await client.query(insert.text, insert.values);
18165
18181
  }
18166
18182
  async function batchCreateFeedback(client, schema, args) {
18167
18183
  if (args.feedbacks.length === 0) return;
18168
- const insert = buildInsert(schema, TABLE_FEEDBACK_EVENTS, [...new Map(args.feedbacks.map((feedback) => [feedback.feedbackId, feedback])).values()].map(feedbackRecordToRow), FEEDBACK_UPSERT_CLAUSE);
18184
+ const rows = [...new Map(args.feedbacks.map((feedback) => [feedback.feedbackId, feedback])).values()].map(feedbackRecordToRow);
18185
+ const insert = buildInsert(schema, TABLE_FEEDBACK_EVENTS, rows, FEEDBACK_UPSERT_CLAUSE);
18169
18186
  if (insert) await client.query(insert.text, insert.values);
18170
18187
  }
18171
18188
  async function updateFeedbackReviewStatus(client, schema, args) {
@@ -18367,7 +18384,8 @@ function applyLogFilters(acc, filters) {
18367
18384
  }
18368
18385
  async function batchCreateLogs(client, schema, args) {
18369
18386
  if (args.logs.length === 0) return;
18370
- const insert = buildInsert(schema, TABLE_LOG_EVENTS, args.logs.map(logRecordToRow));
18387
+ const rows = args.logs.map(logRecordToRow);
18388
+ const insert = buildInsert(schema, TABLE_LOG_EVENTS, rows);
18371
18389
  if (insert) await client.query(insert.text, insert.values);
18372
18390
  }
18373
18391
  async function listLogs(client, schema, args) {
@@ -18442,7 +18460,8 @@ function pushMetricNameFilter(acc, names) {
18442
18460
  }
18443
18461
  async function batchCreateMetrics(client, schema, args) {
18444
18462
  if (args.metrics.length === 0) return;
18445
- const insert = buildInsert(schema, TABLE_METRIC_EVENTS, args.metrics.map(metricRecordToRow));
18463
+ const rows = args.metrics.map(metricRecordToRow);
18464
+ const insert = buildInsert(schema, TABLE_METRIC_EVENTS, rows);
18446
18465
  if (insert) await client.query(insert.text, insert.values);
18447
18466
  }
18448
18467
  async function listMetrics(client, schema, args) {
@@ -20419,7 +20438,7 @@ function predicateFields(predicate, fields = /* @__PURE__ */ new Set()) {
20419
20438
  return fields;
20420
20439
  }
20421
20440
  function canUseThreadCandidates(probe) {
20422
- return Number(probe.threadCount) <= 16384 && Number(probe.traceCount) <= 1e5 && Number(probe.threadBytes) + Number(probe.traceBytes) <= 4 * 1024 * 1024;
20441
+ return Number(probe.threadCount) <= 16384 && Number(probe.traceCount) <= 1e5 && Number(probe.threadBytes) + Number(probe.traceBytes) <= 4194304;
20423
20442
  }
20424
20443
  function compilePostgresThreadRowsQuery(schema, plan, strategy = "full") {
20425
20444
  const values = [plan.timeRange.from, plan.timeRange.to];
@@ -21062,9 +21081,7 @@ function buildListTracesFilters(filters, spanTable, nextParamIdx) {
21062
21081
  case _mastra_core_storage.TraceStatus.RUNNING:
21063
21082
  conditions.push(`r."isPending"`);
21064
21083
  break;
21065
- case _mastra_core_storage.TraceStatus.SUCCESS:
21066
- conditions.push(`r."error" IS NULL AND NOT r."isPending"`);
21067
- break;
21084
+ case _mastra_core_storage.TraceStatus.SUCCESS: conditions.push(`r."error" IS NULL AND NOT r."isPending"`);
21068
21085
  }
21069
21086
  if (filters.hasChildError !== void 0) {
21070
21087
  const sub = `EXISTS (
@@ -21400,9 +21417,7 @@ function buildListBranchesFilters(filters, spanType, spanTable, nextParamIdx) {
21400
21417
  case _mastra_core_storage.TraceStatus.RUNNING:
21401
21418
  conditions.push(`r."isPending"`);
21402
21419
  break;
21403
- case _mastra_core_storage.TraceStatus.SUCCESS:
21404
- conditions.push(`r."error" IS NULL AND NOT r."isPending"`);
21405
- break;
21420
+ case _mastra_core_storage.TraceStatus.SUCCESS: conditions.push(`r."error" IS NULL AND NOT r."isPending"`);
21406
21421
  }
21407
21422
  return {
21408
21423
  conditions,
@@ -21743,7 +21758,7 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
21743
21758
  } catch (error) {
21744
21759
  if (!isDuplicateRelationError(error)) throw error;
21745
21760
  }
21746
- for (const { table, column, ddl } of additiveColumns(this.#schema)) if (!await this.#client.oneOrNone(columnExistsSQL, [
21761
+ for (const { table, column, ddl } of additiveColumns(this.#schema)) if (!await this.#client.oneOrNone("SELECT 1 FROM information_schema.columns\n WHERE table_schema = $1 AND table_name = $2 AND column_name = $3", [
21747
21762
  this.#schema,
21748
21763
  table,
21749
21764
  column
@@ -22911,15 +22926,19 @@ var SchedulesPG = class SchedulesPG extends _mastra_core_storage.SchedulesStorag
22911
22926
  params.push(filter.workflowId);
22912
22927
  conditions.push(`target->>'workflowId' = $${params.length}`);
22913
22928
  }
22914
- if (filter?.ownerType !== void 0) if (filter.ownerType === null) conditions.push("owner_type IS NULL");
22915
- else {
22916
- params.push(filter.ownerType);
22917
- conditions.push(`owner_type = $${params.length}`);
22929
+ if (filter?.ownerType !== void 0) {
22930
+ if (filter.ownerType === null) conditions.push("owner_type IS NULL");
22931
+ else {
22932
+ params.push(filter.ownerType);
22933
+ conditions.push(`owner_type = $${params.length}`);
22934
+ }
22918
22935
  }
22919
- if (filter?.ownerId !== void 0) if (filter.ownerId === null) conditions.push("owner_id IS NULL");
22920
- else {
22921
- params.push(filter.ownerId);
22922
- conditions.push(`owner_id = $${params.length}`);
22936
+ if (filter?.ownerId !== void 0) {
22937
+ if (filter.ownerId === null) conditions.push("owner_id IS NULL");
22938
+ else {
22939
+ params.push(filter.ownerId);
22940
+ conditions.push(`owner_id = $${params.length}`);
22941
+ }
22923
22942
  }
22924
22943
  const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
22925
22944
  return (await this.#readClient.manyOrNone(`SELECT * FROM ${this.#table(_mastra_core_storage.TABLE_SCHEDULES)} ${where} ORDER BY created_at ASC`, params)).map(rowToSchedule);
@@ -26029,16 +26048,20 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
26029
26048
  values.push(status);
26030
26049
  paramIndex++;
26031
26050
  }
26032
- if (resourceId) if (await this.#db.hasColumn(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId")) {
26033
- conditions.push(`"resourceId" = $${paramIndex}`);
26034
- values.push(resourceId);
26035
- paramIndex++;
26036
- } else this.logger?.warn?.(`[${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
26037
- if (threadId) if (await this.#db.getColumnType(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "snapshot") === "jsonb") {
26038
- conditions.push(`${WORKFLOW_SNAPSHOT_THREAD_ID_EXPR} = $${paramIndex}`);
26039
- values.push(threadId);
26040
- paramIndex++;
26041
- } else this.logger?.warn?.(`[${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}] snapshot column is not jsonb. Skipping threadId filter.`);
26051
+ if (resourceId) {
26052
+ if (await this.#db.hasColumn(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId")) {
26053
+ conditions.push(`"resourceId" = $${paramIndex}`);
26054
+ values.push(resourceId);
26055
+ paramIndex++;
26056
+ } else this.logger?.warn?.(`[${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
26057
+ }
26058
+ if (threadId) {
26059
+ if (await this.#db.getColumnType(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT, "snapshot") === "jsonb") {
26060
+ conditions.push(`${WORKFLOW_SNAPSHOT_THREAD_ID_EXPR} = $${paramIndex}`);
26061
+ values.push(threadId);
26062
+ paramIndex++;
26063
+ } else this.logger?.warn?.(`[${_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT}] snapshot column is not jsonb. Skipping threadId filter.`);
26064
+ }
26042
26065
  if (fromDate) {
26043
26066
  conditions.push(`"createdAt" >= $${paramIndex}`);
26044
26067
  values.push(fromDate);