@mastra/pg 1.9.1 → 1.9.2-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/dist/index.cjs CHANGED
@@ -4280,6 +4280,307 @@ var AgentsPG = class _AgentsPG extends storage.AgentsStorage {
4280
4280
  };
4281
4281
  }
4282
4282
  };
4283
+ function getSchemaName3(schema) {
4284
+ return schema ? `"${schema}"` : '"public"';
4285
+ }
4286
+ function getTableName3(schemaName) {
4287
+ const quoted = `"${storage.TABLE_BACKGROUND_TASKS}"`;
4288
+ return schemaName ? `${schemaName}.${quoted}` : quoted;
4289
+ }
4290
+ function serializeJson(v) {
4291
+ if (typeof v === "object" && v != null) return JSON.stringify(v);
4292
+ return v ?? null;
4293
+ }
4294
+ function parseJson(v) {
4295
+ if (typeof v === "string") {
4296
+ try {
4297
+ return JSON.parse(v);
4298
+ } catch {
4299
+ return v;
4300
+ }
4301
+ }
4302
+ return v ?? void 0;
4303
+ }
4304
+ function rowToTask(row) {
4305
+ return {
4306
+ id: row.id,
4307
+ status: row.status,
4308
+ toolName: row.tool_name,
4309
+ toolCallId: row.tool_call_id,
4310
+ args: parseJson(row.args),
4311
+ agentId: row.agent_id,
4312
+ threadId: row.thread_id ?? void 0,
4313
+ resourceId: row.resource_id ?? void 0,
4314
+ runId: row.run_id,
4315
+ result: parseJson(row.result),
4316
+ error: parseJson(row.error),
4317
+ retryCount: Number(row.retry_count),
4318
+ maxRetries: Number(row.max_retries),
4319
+ timeoutMs: Number(row.timeout_ms),
4320
+ createdAt: row.createdAt instanceof Date ? row.createdAt : new Date(row.createdAt),
4321
+ startedAt: row.startedAt ? row.startedAt instanceof Date ? row.startedAt : new Date(row.startedAt) : void 0,
4322
+ completedAt: row.completedAt ? row.completedAt instanceof Date ? row.completedAt : new Date(row.completedAt) : void 0
4323
+ };
4324
+ }
4325
+ var BackgroundTasksPG = class _BackgroundTasksPG extends storage.BackgroundTasksStorage {
4326
+ #db;
4327
+ #schema;
4328
+ #skipDefaultIndexes;
4329
+ #indexes;
4330
+ static MANAGED_TABLES = [storage.TABLE_BACKGROUND_TASKS];
4331
+ constructor(config) {
4332
+ super();
4333
+ const { client, schemaName, skipDefaultIndexes, indexes } = resolvePgConfig(config);
4334
+ this.#db = new PgDB({ client, schemaName, skipDefaultIndexes });
4335
+ this.#schema = schemaName || "public";
4336
+ this.#skipDefaultIndexes = skipDefaultIndexes;
4337
+ this.#indexes = indexes?.filter((idx) => _BackgroundTasksPG.MANAGED_TABLES.includes(idx.table));
4338
+ }
4339
+ async init() {
4340
+ await this.#db.createTable({
4341
+ tableName: storage.TABLE_BACKGROUND_TASKS,
4342
+ schema: storage.TABLE_SCHEMAS[storage.TABLE_BACKGROUND_TASKS]
4343
+ });
4344
+ await this.createDefaultIndexes();
4345
+ await this.createCustomIndexes();
4346
+ }
4347
+ static getDefaultIndexDefs(schemaPrefix) {
4348
+ return [
4349
+ {
4350
+ name: `${schemaPrefix}mastra_bg_tasks_status_created_at_idx`,
4351
+ table: storage.TABLE_BACKGROUND_TASKS,
4352
+ columns: ["status", "createdAt"]
4353
+ },
4354
+ {
4355
+ name: `${schemaPrefix}mastra_bg_tasks_agent_status_idx`,
4356
+ table: storage.TABLE_BACKGROUND_TASKS,
4357
+ columns: ["agent_id", "status"]
4358
+ },
4359
+ {
4360
+ name: `${schemaPrefix}mastra_bg_tasks_thread_idx`,
4361
+ table: storage.TABLE_BACKGROUND_TASKS,
4362
+ columns: ["thread_id", "createdAt"]
4363
+ },
4364
+ {
4365
+ name: `${schemaPrefix}mastra_bg_tasks_tool_call_idx`,
4366
+ table: storage.TABLE_BACKGROUND_TASKS,
4367
+ columns: ["tool_call_id"]
4368
+ }
4369
+ ];
4370
+ }
4371
+ static getExportDDL(schemaName) {
4372
+ const statements = [];
4373
+ const parsedSchema = schemaName ? utils.parseSqlIdentifier(schemaName, "schema name") : "";
4374
+ const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
4375
+ statements.push(
4376
+ generateTableSQL({
4377
+ tableName: storage.TABLE_BACKGROUND_TASKS,
4378
+ schema: storage.TABLE_SCHEMAS[storage.TABLE_BACKGROUND_TASKS],
4379
+ schemaName,
4380
+ includeAllConstraints: true
4381
+ })
4382
+ );
4383
+ for (const idx of _BackgroundTasksPG.getDefaultIndexDefs(schemaPrefix)) {
4384
+ statements.push(generateIndexSQL(idx, schemaName));
4385
+ }
4386
+ return statements;
4387
+ }
4388
+ getDefaultIndexDefinitions() {
4389
+ const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
4390
+ return _BackgroundTasksPG.getDefaultIndexDefs(schemaPrefix);
4391
+ }
4392
+ async createDefaultIndexes() {
4393
+ if (this.#skipDefaultIndexes) return;
4394
+ for (const indexDef of this.getDefaultIndexDefinitions()) {
4395
+ try {
4396
+ await this.#db.createIndex(indexDef);
4397
+ } catch (error) {
4398
+ this.logger?.warn?.(`Failed to create index ${indexDef.name}:`, error);
4399
+ }
4400
+ }
4401
+ }
4402
+ async createCustomIndexes() {
4403
+ if (!this.#indexes || this.#indexes.length === 0) return;
4404
+ for (const indexDef of this.#indexes) {
4405
+ try {
4406
+ await this.#db.createIndex(indexDef);
4407
+ } catch (error) {
4408
+ this.logger?.warn?.(`Failed to create custom index ${indexDef.name}:`, error);
4409
+ }
4410
+ }
4411
+ }
4412
+ async dangerouslyClearAll() {
4413
+ await this.#db.clearTable({ tableName: storage.TABLE_BACKGROUND_TASKS });
4414
+ }
4415
+ async createTask(task) {
4416
+ await this.#db.insert({
4417
+ tableName: storage.TABLE_BACKGROUND_TASKS,
4418
+ record: {
4419
+ id: task.id,
4420
+ tool_call_id: task.toolCallId,
4421
+ tool_name: task.toolName,
4422
+ agent_id: task.agentId,
4423
+ thread_id: task.threadId ?? null,
4424
+ resource_id: task.resourceId ?? null,
4425
+ run_id: task.runId,
4426
+ status: task.status,
4427
+ args: serializeJson(task.args),
4428
+ result: serializeJson(task.result),
4429
+ error: serializeJson(task.error),
4430
+ retry_count: task.retryCount,
4431
+ max_retries: task.maxRetries,
4432
+ timeout_ms: task.timeoutMs,
4433
+ createdAt: task.createdAt.toISOString(),
4434
+ startedAt: task.startedAt?.toISOString() ?? null,
4435
+ completedAt: task.completedAt?.toISOString() ?? null
4436
+ }
4437
+ });
4438
+ }
4439
+ async updateTask(taskId, update) {
4440
+ const setClauses = [];
4441
+ const params = [];
4442
+ let paramIdx = 1;
4443
+ if ("status" in update) {
4444
+ setClauses.push(`"status" = $${paramIdx++}`);
4445
+ params.push(update.status);
4446
+ }
4447
+ if ("result" in update) {
4448
+ setClauses.push(`"result" = $${paramIdx++}`);
4449
+ params.push(serializeJson(update.result));
4450
+ }
4451
+ if ("error" in update) {
4452
+ setClauses.push(`"error" = $${paramIdx++}`);
4453
+ params.push(serializeJson(update.error));
4454
+ }
4455
+ if ("retryCount" in update) {
4456
+ setClauses.push(`"retry_count" = $${paramIdx++}`);
4457
+ params.push(update.retryCount);
4458
+ }
4459
+ if ("startedAt" in update) {
4460
+ setClauses.push(`"startedAt" = $${paramIdx++}`);
4461
+ params.push(update.startedAt?.toISOString() ?? null);
4462
+ }
4463
+ if ("completedAt" in update) {
4464
+ setClauses.push(`"completedAt" = $${paramIdx++}`);
4465
+ params.push(update.completedAt?.toISOString() ?? null);
4466
+ }
4467
+ if (setClauses.length === 0) return;
4468
+ const table = getTableName3(getSchemaName3(this.#schema));
4469
+ params.push(taskId);
4470
+ await this.#db.client.none(`UPDATE ${table} SET ${setClauses.join(", ")} WHERE "id" = $${paramIdx}`, params);
4471
+ }
4472
+ async getTask(taskId) {
4473
+ const table = getTableName3(getSchemaName3(this.#schema));
4474
+ const row = await this.#db.client.oneOrNone(`SELECT * FROM ${table} WHERE "id" = $1`, [taskId]);
4475
+ return row ? rowToTask(row) : null;
4476
+ }
4477
+ async listTasks(filter) {
4478
+ const table = getTableName3(getSchemaName3(this.#schema));
4479
+ const conditions = [];
4480
+ const params = [];
4481
+ let paramIdx = 1;
4482
+ if (filter.status) {
4483
+ const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
4484
+ const placeholders = statuses.map(() => `$${paramIdx++}`);
4485
+ conditions.push(`"status" IN (${placeholders.join(", ")})`);
4486
+ params.push(...statuses);
4487
+ }
4488
+ if (filter.agentId) {
4489
+ conditions.push(`"agent_id" = $${paramIdx++}`);
4490
+ params.push(filter.agentId);
4491
+ }
4492
+ if (filter.threadId) {
4493
+ conditions.push(`"thread_id" = $${paramIdx++}`);
4494
+ params.push(filter.threadId);
4495
+ }
4496
+ if (filter.resourceId) {
4497
+ conditions.push(`"resource_id" = $${paramIdx++}`);
4498
+ params.push(filter.resourceId);
4499
+ }
4500
+ if (filter.runId) {
4501
+ conditions.push(`"run_id" = $${paramIdx++}`);
4502
+ params.push(filter.runId);
4503
+ }
4504
+ if (filter.toolName) {
4505
+ conditions.push(`"tool_name" = $${paramIdx++}`);
4506
+ params.push(filter.toolName);
4507
+ }
4508
+ const dateCol = filter.dateFilterBy === "startedAt" ? '"startedAt"' : filter.dateFilterBy === "completedAt" ? '"completedAt"' : '"createdAt"';
4509
+ if (filter.fromDate) {
4510
+ conditions.push(`${dateCol} >= $${paramIdx++}`);
4511
+ params.push(filter.fromDate.toISOString());
4512
+ }
4513
+ if (filter.toDate) {
4514
+ conditions.push(`${dateCol} < $${paramIdx++}`);
4515
+ params.push(filter.toDate.toISOString());
4516
+ }
4517
+ const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
4518
+ const countResult = await this.#db.client.oneOrNone(
4519
+ `SELECT COUNT(*) as count FROM ${table} ${where}`,
4520
+ params.slice(0, paramIdx - 1)
4521
+ );
4522
+ const total = Number(countResult?.count ?? 0);
4523
+ const orderCol = filter.orderBy === "startedAt" ? '"startedAt"' : filter.orderBy === "completedAt" ? '"completedAt"' : '"createdAt"';
4524
+ const direction = filter.orderDirection === "desc" ? "DESC" : "ASC";
4525
+ let sql = `SELECT * FROM ${table} ${where} ORDER BY ${orderCol} ${direction}`;
4526
+ if (filter.perPage != null) {
4527
+ sql += ` LIMIT $${paramIdx++}`;
4528
+ params.push(filter.perPage);
4529
+ if (filter.page != null) {
4530
+ sql += ` OFFSET $${paramIdx++}`;
4531
+ params.push(filter.page * filter.perPage);
4532
+ }
4533
+ }
4534
+ const rows = await this.#db.client.manyOrNone(sql, params);
4535
+ return { tasks: rows.map(rowToTask), total };
4536
+ }
4537
+ async deleteTask(taskId) {
4538
+ const table = getTableName3(getSchemaName3(this.#schema));
4539
+ await this.#db.client.none(`DELETE FROM ${table} WHERE "id" = $1`, [taskId]);
4540
+ }
4541
+ async deleteTasks(filter) {
4542
+ const table = getTableName3(getSchemaName3(this.#schema));
4543
+ const conditions = [];
4544
+ const params = [];
4545
+ let paramIdx = 1;
4546
+ if (filter.status) {
4547
+ const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
4548
+ const placeholders = statuses.map(() => `$${paramIdx++}`);
4549
+ conditions.push(`"status" IN (${placeholders.join(", ")})`);
4550
+ params.push(...statuses);
4551
+ }
4552
+ const dateCol = filter.dateFilterBy === "startedAt" ? '"startedAt"' : filter.dateFilterBy === "completedAt" ? '"completedAt"' : '"createdAt"';
4553
+ if (filter.fromDate) {
4554
+ conditions.push(`${dateCol} >= $${paramIdx++}`);
4555
+ params.push(filter.fromDate.toISOString());
4556
+ }
4557
+ if (filter.toDate) {
4558
+ conditions.push(`${dateCol} < $${paramIdx++}`);
4559
+ params.push(filter.toDate.toISOString());
4560
+ }
4561
+ if (filter.agentId) {
4562
+ conditions.push(`"agent_id" = $${paramIdx++}`);
4563
+ params.push(filter.agentId);
4564
+ }
4565
+ if (conditions.length === 0) return;
4566
+ await this.#db.client.none(`DELETE FROM ${table} WHERE ${conditions.join(" AND ")}`, params);
4567
+ }
4568
+ async getRunningCount() {
4569
+ const table = getTableName3(getSchemaName3(this.#schema));
4570
+ const result = await this.#db.client.oneOrNone(
4571
+ `SELECT COUNT(*) FROM ${table} WHERE "status" = 'running'`
4572
+ );
4573
+ return Number(result?.count ?? 0);
4574
+ }
4575
+ async getRunningCountByAgent(agentId) {
4576
+ const table = getTableName3(getSchemaName3(this.#schema));
4577
+ const result = await this.#db.client.oneOrNone(
4578
+ `SELECT COUNT(*) FROM ${table} WHERE "status" = 'running' AND "agent_id" = $1`,
4579
+ [agentId]
4580
+ );
4581
+ return Number(result?.count ?? 0);
4582
+ }
4583
+ };
4283
4584
  var BlobsPG = class extends storage.BlobStore {
4284
4585
  #db;
4285
4586
  #schema;
@@ -7169,10 +7470,10 @@ try {
7169
7470
  _omTableSchema = storage.OBSERVATIONAL_MEMORY_TABLE_SCHEMA;
7170
7471
  } catch {
7171
7472
  }
7172
- function getSchemaName3(schema) {
7473
+ function getSchemaName4(schema) {
7173
7474
  return schema ? `"${schema}"` : '"public"';
7174
7475
  }
7175
- function getTableName3({ indexName, schemaName }) {
7476
+ function getTableName4({ indexName, schemaName }) {
7176
7477
  const quotedIndexName = `"${indexName}"`;
7177
7478
  return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
7178
7479
  }
@@ -7237,9 +7538,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
7237
7538
  ifNotExists: ["resourceId"]
7238
7539
  });
7239
7540
  if (omSchema) {
7240
- const omTableName = getTableName3({
7541
+ const omTableName = getTableName4({
7241
7542
  indexName: OM_TABLE,
7242
- schemaName: getSchemaName3(this.#schema)
7543
+ schemaName: getSchemaName4(this.#schema)
7243
7544
  });
7244
7545
  await this.#db.client.none(`CREATE INDEX IF NOT EXISTS idx_om_lookup_key ON ${omTableName} ("lookupKey")`);
7245
7546
  }
@@ -7362,7 +7663,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
7362
7663
  }
7363
7664
  async getThreadById({ threadId }) {
7364
7665
  try {
7365
- const tableName = getTableName3({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
7666
+ const tableName = getTableName4({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
7366
7667
  const thread = await this.#db.client.oneOrNone(
7367
7668
  `SELECT * FROM ${tableName} WHERE id = $1`,
7368
7669
  [threadId]
@@ -7420,7 +7721,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
7420
7721
  const { field, direction } = this.parseOrderBy(orderBy);
7421
7722
  const { offset, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
7422
7723
  try {
7423
- const tableName = getTableName3({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
7724
+ const tableName = getTableName4({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
7424
7725
  const whereClauses = [];
7425
7726
  const queryParams = [];
7426
7727
  let paramIndex = 1;
@@ -7499,7 +7800,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
7499
7800
  }
7500
7801
  async saveThread({ thread }) {
7501
7802
  try {
7502
- const tableName = getTableName3({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
7803
+ const tableName = getTableName4({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
7503
7804
  await this.#db.client.none(
7504
7805
  `INSERT INTO ${tableName} (
7505
7806
  id,
@@ -7550,7 +7851,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
7550
7851
  title,
7551
7852
  metadata
7552
7853
  }) {
7553
- const threadTableName = getTableName3({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
7854
+ const threadTableName = getTableName4({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
7554
7855
  const existingThread = await this.getThreadById({ threadId: id });
7555
7856
  if (!existingThread) {
7556
7857
  throw new error.MastraError({
@@ -7607,8 +7908,8 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
7607
7908
  }
7608
7909
  async deleteThread({ threadId }) {
7609
7910
  try {
7610
- const tableName = getTableName3({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
7611
- const threadTableName = getTableName3({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
7911
+ const tableName = getTableName4({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
7912
+ const threadTableName = getTableName4({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
7612
7913
  await this.#db.client.tx(async (t) => {
7613
7914
  await t.none(`DELETE FROM ${tableName} WHERE thread_id = $1`, [threadId]);
7614
7915
  const schemaName = this.#schema || "public";
@@ -7622,7 +7923,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
7622
7923
  [schemaName]
7623
7924
  );
7624
7925
  for (const { tablename } of vectorTables) {
7625
- const vectorTableName = getTableName3({ indexName: tablename, schemaName: getSchemaName3(this.#schema) });
7926
+ const vectorTableName = getTableName4({ indexName: tablename, schemaName: getSchemaName4(this.#schema) });
7626
7927
  await t.none(`DELETE FROM ${vectorTableName} WHERE metadata->>'thread_id' = $1`, [threadId]);
7627
7928
  }
7628
7929
  await t.none(`DELETE FROM ${threadTableName} WHERE id = $1`, [threadId]);
@@ -7673,7 +7974,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
7673
7974
  }
7674
7975
  async _getIncludedMessages({ include }) {
7675
7976
  if (!include || include.length === 0) return null;
7676
- const tableName = getTableName3({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
7977
+ const tableName = getTableName4({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
7677
7978
  const selectColumns = `id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"`;
7678
7979
  const targetIds = include.map((inc) => inc.id).filter(Boolean);
7679
7980
  if (targetIds.length === 0) return null;
@@ -7754,7 +8055,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
7754
8055
  if (messageIds.length === 0) return { messages: [] };
7755
8056
  const selectStatement = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"`;
7756
8057
  try {
7757
- const tableName = getTableName3({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
8058
+ const tableName = getTableName4({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
7758
8059
  const query = `
7759
8060
  ${selectStatement} FROM ${tableName}
7760
8061
  WHERE id IN (${inPlaceholders(messageIds.length)})
@@ -7817,7 +8118,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
7817
8118
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
7818
8119
  const orderByStatement = `ORDER BY COALESCE("${field}Z", "${field}") ${direction}`;
7819
8120
  const selectStatement = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"`;
7820
- const tableName = getTableName3({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
8121
+ const tableName = getTableName4({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
7821
8122
  const conditions = [`thread_id IN (${inPlaceholders(threadIds.length)})`];
7822
8123
  const queryParams = [...threadIds];
7823
8124
  let paramIndex = threadIds.length + 1;
@@ -7956,7 +8257,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
7956
8257
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
7957
8258
  const orderByStatement = `ORDER BY COALESCE("${field}Z", "${field}") ${direction}`;
7958
8259
  const selectStatement = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"`;
7959
- const tableName = getTableName3({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
8260
+ const tableName = getTableName4({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
7960
8261
  const conditions = [];
7961
8262
  const queryParams = [];
7962
8263
  let paramIndex = 1;
@@ -8083,7 +8384,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8083
8384
  });
8084
8385
  }
8085
8386
  try {
8086
- const tableName = getTableName3({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
8387
+ const tableName = getTableName4({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
8087
8388
  await this.#db.client.tx(async (t) => {
8088
8389
  for (const message of messages) {
8089
8390
  if (!message.threadId) {
@@ -8117,7 +8418,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8117
8418
  ]
8118
8419
  );
8119
8420
  }
8120
- const threadTableName = getTableName3({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
8421
+ const threadTableName = getTableName4({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
8121
8422
  const now = /* @__PURE__ */ new Date();
8122
8423
  await t.none(
8123
8424
  `UPDATE ${threadTableName}
@@ -8161,7 +8462,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8161
8462
  return [];
8162
8463
  }
8163
8464
  const messageIds = messages.map((m) => m.id);
8164
- const selectQuery = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId" FROM ${getTableName3({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) })} WHERE id IN (${inPlaceholders(messageIds.length)})`;
8465
+ const selectQuery = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId" FROM ${getTableName4({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) })} WHERE id IN (${inPlaceholders(messageIds.length)})`;
8165
8466
  const existingMessagesDb = await this.#db.client.manyOrNone(selectQuery, messageIds);
8166
8467
  if (existingMessagesDb.length === 0) {
8167
8468
  return [];
@@ -8218,7 +8519,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8218
8519
  }
8219
8520
  if (setClauses.length > 0) {
8220
8521
  values.push(id);
8221
- const sql = `UPDATE ${getTableName3({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) })} SET ${setClauses.join(", ")} WHERE id = $${paramIndex}`;
8522
+ const sql = `UPDATE ${getTableName4({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) })} SET ${setClauses.join(", ")} WHERE id = $${paramIndex}`;
8222
8523
  queries.push(t.none(sql, values));
8223
8524
  }
8224
8525
  }
@@ -8226,7 +8527,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8226
8527
  const threadIds = Array.from(threadIdsToUpdate);
8227
8528
  queries.push(
8228
8529
  t.none(
8229
- `UPDATE ${getTableName3({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName3(this.#schema) })} SET "updatedAt" = NOW(), "updatedAtZ" = NOW() WHERE id IN (${inPlaceholders(threadIds.length)})`,
8530
+ `UPDATE ${getTableName4({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName4(this.#schema) })} SET "updatedAt" = NOW(), "updatedAtZ" = NOW() WHERE id IN (${inPlaceholders(threadIds.length)})`,
8230
8531
  threadIds
8231
8532
  )
8232
8533
  );
@@ -8252,8 +8553,8 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8252
8553
  return;
8253
8554
  }
8254
8555
  try {
8255
- const messageTableName = getTableName3({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
8256
- const threadTableName = getTableName3({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
8556
+ const messageTableName = getTableName4({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
8557
+ const threadTableName = getTableName4({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
8257
8558
  await this.#db.client.tx(async (t) => {
8258
8559
  const placeholders = messageIds.map((_, idx) => `$${idx + 1}`).join(",");
8259
8560
  const messages = await t.manyOrNone(
@@ -8282,7 +8583,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8282
8583
  }
8283
8584
  }
8284
8585
  async getResourceById({ resourceId }) {
8285
- const tableName = getTableName3({ indexName: storage.TABLE_RESOURCES, schemaName: getSchemaName3(this.#schema) });
8586
+ const tableName = getTableName4({ indexName: storage.TABLE_RESOURCES, schemaName: getSchemaName4(this.#schema) });
8286
8587
  const result = await this.#db.client.oneOrNone(
8287
8588
  `SELECT * FROM ${tableName} WHERE id = $1`,
8288
8589
  [resourceId]
@@ -8333,7 +8634,7 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8333
8634
  },
8334
8635
  updatedAt: /* @__PURE__ */ new Date()
8335
8636
  };
8336
- const tableName = getTableName3({ indexName: storage.TABLE_RESOURCES, schemaName: getSchemaName3(this.#schema) });
8637
+ const tableName = getTableName4({ indexName: storage.TABLE_RESOURCES, schemaName: getSchemaName4(this.#schema) });
8337
8638
  const updates = [];
8338
8639
  const values = [];
8339
8640
  let paramIndex = 1;
@@ -8379,8 +8680,8 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8379
8680
  details: { newThreadId }
8380
8681
  });
8381
8682
  }
8382
- const threadTableName = getTableName3({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
8383
- const messageTableName = getTableName3({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
8683
+ const threadTableName = getTableName4({ indexName: storage.TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
8684
+ const messageTableName = getTableName4({ indexName: storage.TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
8384
8685
  try {
8385
8686
  return await this.#db.client.tx(async (t) => {
8386
8687
  let messageQuery = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"
@@ -8550,9 +8851,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8550
8851
  async getObservationalMemory(threadId, resourceId) {
8551
8852
  try {
8552
8853
  const lookupKey = this.getOMKey(threadId, resourceId);
8553
- const tableName = getTableName3({
8854
+ const tableName = getTableName4({
8554
8855
  indexName: OM_TABLE,
8555
- schemaName: getSchemaName3(this.#schema)
8856
+ schemaName: getSchemaName4(this.#schema)
8556
8857
  });
8557
8858
  const result = await this.#db.client.oneOrNone(
8558
8859
  `SELECT * FROM ${tableName} WHERE "lookupKey" = $1 ORDER BY "generationCount" DESC LIMIT 1`,
@@ -8575,9 +8876,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8575
8876
  async getObservationalMemoryHistory(threadId, resourceId, limit = 10, options) {
8576
8877
  try {
8577
8878
  const lookupKey = this.getOMKey(threadId, resourceId);
8578
- const tableName = getTableName3({
8879
+ const tableName = getTableName4({
8579
8880
  indexName: OM_TABLE,
8580
- schemaName: getSchemaName3(this.#schema)
8881
+ schemaName: getSchemaName4(this.#schema)
8581
8882
  });
8582
8883
  const conditions = [`"lookupKey" = $1`];
8583
8884
  const params = [lookupKey];
@@ -8642,9 +8943,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8642
8943
  config: input.config,
8643
8944
  observedTimezone: input.observedTimezone
8644
8945
  };
8645
- const tableName = getTableName3({
8946
+ const tableName = getTableName4({
8646
8947
  indexName: OM_TABLE,
8647
- schemaName: getSchemaName3(this.#schema)
8948
+ schemaName: getSchemaName4(this.#schema)
8648
8949
  });
8649
8950
  const nowStr = now.toISOString();
8650
8951
  await this.#db.client.none(
@@ -8715,9 +9016,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8715
9016
  async insertObservationalMemoryRecord(record) {
8716
9017
  try {
8717
9018
  const lookupKey = this.getOMKey(record.threadId, record.resourceId);
8718
- const tableName = getTableName3({
9019
+ const tableName = getTableName4({
8719
9020
  indexName: OM_TABLE,
8720
- schemaName: getSchemaName3(this.#schema)
9021
+ schemaName: getSchemaName4(this.#schema)
8721
9022
  });
8722
9023
  const lastObservedAtStr = record.lastObservedAt ? record.lastObservedAt.toISOString() : null;
8723
9024
  const lastBufferedAtTimeStr = record.lastBufferedAtTime ? record.lastBufferedAtTime.toISOString() : null;
@@ -8789,9 +9090,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8789
9090
  async updateActiveObservations(input) {
8790
9091
  try {
8791
9092
  const now = /* @__PURE__ */ new Date();
8792
- const tableName = getTableName3({
9093
+ const tableName = getTableName4({
8793
9094
  indexName: OM_TABLE,
8794
- schemaName: getSchemaName3(this.#schema)
9095
+ schemaName: getSchemaName4(this.#schema)
8795
9096
  });
8796
9097
  const lastObservedAtStr = input.lastObservedAt.toISOString();
8797
9098
  const nowStr = now.toISOString();
@@ -8873,9 +9174,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8873
9174
  metadata: input.currentRecord.metadata,
8874
9175
  observedTimezone: input.currentRecord.observedTimezone
8875
9176
  };
8876
- const tableName = getTableName3({
9177
+ const tableName = getTableName4({
8877
9178
  indexName: OM_TABLE,
8878
- schemaName: getSchemaName3(this.#schema)
9179
+ schemaName: getSchemaName4(this.#schema)
8879
9180
  });
8880
9181
  const nowStr = now.toISOString();
8881
9182
  const lastObservedAtStr = record.lastObservedAt?.toISOString() || null;
@@ -8949,9 +9250,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8949
9250
  }
8950
9251
  async setReflectingFlag(id, isReflecting) {
8951
9252
  try {
8952
- const tableName = getTableName3({
9253
+ const tableName = getTableName4({
8953
9254
  indexName: OM_TABLE,
8954
- schemaName: getSchemaName3(this.#schema)
9255
+ schemaName: getSchemaName4(this.#schema)
8955
9256
  });
8956
9257
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
8957
9258
  const result = await this.#db.client.query(
@@ -8984,9 +9285,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
8984
9285
  }
8985
9286
  async setObservingFlag(id, isObserving) {
8986
9287
  try {
8987
- const tableName = getTableName3({
9288
+ const tableName = getTableName4({
8988
9289
  indexName: OM_TABLE,
8989
- schemaName: getSchemaName3(this.#schema)
9290
+ schemaName: getSchemaName4(this.#schema)
8990
9291
  });
8991
9292
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
8992
9293
  const result = await this.#db.client.query(
@@ -9019,9 +9320,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9019
9320
  }
9020
9321
  async setBufferingObservationFlag(id, isBuffering, lastBufferedAtTokens) {
9021
9322
  try {
9022
- const tableName = getTableName3({
9323
+ const tableName = getTableName4({
9023
9324
  indexName: OM_TABLE,
9024
- schemaName: getSchemaName3(this.#schema)
9325
+ schemaName: getSchemaName4(this.#schema)
9025
9326
  });
9026
9327
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
9027
9328
  let query;
@@ -9060,9 +9361,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9060
9361
  }
9061
9362
  async setBufferingReflectionFlag(id, isBuffering) {
9062
9363
  try {
9063
- const tableName = getTableName3({
9364
+ const tableName = getTableName4({
9064
9365
  indexName: OM_TABLE,
9065
- schemaName: getSchemaName3(this.#schema)
9366
+ schemaName: getSchemaName4(this.#schema)
9066
9367
  });
9067
9368
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
9068
9369
  const result = await this.#db.client.query(
@@ -9096,9 +9397,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9096
9397
  async clearObservationalMemory(threadId, resourceId) {
9097
9398
  try {
9098
9399
  const lookupKey = this.getOMKey(threadId, resourceId);
9099
- const tableName = getTableName3({
9400
+ const tableName = getTableName4({
9100
9401
  indexName: OM_TABLE,
9101
- schemaName: getSchemaName3(this.#schema)
9402
+ schemaName: getSchemaName4(this.#schema)
9102
9403
  });
9103
9404
  await this.#db.client.none(`DELETE FROM ${tableName} WHERE "lookupKey" = $1`, [lookupKey]);
9104
9405
  } catch (error$1) {
@@ -9115,9 +9416,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9115
9416
  }
9116
9417
  async setPendingMessageTokens(id, tokenCount) {
9117
9418
  try {
9118
- const tableName = getTableName3({
9419
+ const tableName = getTableName4({
9119
9420
  indexName: OM_TABLE,
9120
- schemaName: getSchemaName3(this.#schema)
9421
+ schemaName: getSchemaName4(this.#schema)
9121
9422
  });
9122
9423
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
9123
9424
  const result = await this.#db.client.query(
@@ -9154,9 +9455,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9154
9455
  }
9155
9456
  async updateObservationalMemoryConfig(input) {
9156
9457
  try {
9157
- const tableName = getTableName3({
9458
+ const tableName = getTableName4({
9158
9459
  indexName: OM_TABLE,
9159
- schemaName: getSchemaName3(this.#schema)
9460
+ schemaName: getSchemaName4(this.#schema)
9160
9461
  });
9161
9462
  const selectResult = await this.#db.client.query(`SELECT config FROM ${tableName} WHERE id = $1`, [input.id]);
9162
9463
  if (selectResult.rowCount === 0) {
@@ -9196,9 +9497,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9196
9497
  // ============================================
9197
9498
  async updateBufferedObservations(input) {
9198
9499
  try {
9199
- const tableName = getTableName3({
9500
+ const tableName = getTableName4({
9200
9501
  indexName: OM_TABLE,
9201
- schemaName: getSchemaName3(this.#schema)
9502
+ schemaName: getSchemaName4(this.#schema)
9202
9503
  });
9203
9504
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
9204
9505
  const newChunk = {
@@ -9250,9 +9551,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9250
9551
  }
9251
9552
  async swapBufferedToActive(input) {
9252
9553
  try {
9253
- const tableName = getTableName3({
9554
+ const tableName = getTableName4({
9254
9555
  indexName: OM_TABLE,
9255
- schemaName: getSchemaName3(this.#schema)
9556
+ schemaName: getSchemaName4(this.#schema)
9256
9557
  });
9257
9558
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
9258
9559
  const record = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE id = $1`, [input.id]);
@@ -9415,9 +9716,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9415
9716
  }
9416
9717
  async updateBufferedReflection(input) {
9417
9718
  try {
9418
- const tableName = getTableName3({
9719
+ const tableName = getTableName4({
9419
9720
  indexName: OM_TABLE,
9420
- schemaName: getSchemaName3(this.#schema)
9721
+ schemaName: getSchemaName4(this.#schema)
9421
9722
  });
9422
9723
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
9423
9724
  const result = await this.#db.client.query(
@@ -9469,9 +9770,9 @@ var MemoryPG = class _MemoryPG extends storage.MemoryStorage {
9469
9770
  }
9470
9771
  async swapBufferedReflectionToActive(input) {
9471
9772
  try {
9472
- const tableName = getTableName3({
9773
+ const tableName = getTableName4({
9473
9774
  indexName: OM_TABLE,
9474
- schemaName: getSchemaName3(this.#schema)
9775
+ schemaName: getSchemaName4(this.#schema)
9475
9776
  });
9476
9777
  const record = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE id = $1`, [
9477
9778
  input.currentRecord.id
@@ -11500,10 +11801,10 @@ var ScorerDefinitionsPG = class _ScorerDefinitionsPG extends storage.ScorerDefin
11500
11801
  };
11501
11802
  }
11502
11803
  };
11503
- function getSchemaName4(schema) {
11804
+ function getSchemaName5(schema) {
11504
11805
  return schema ? `"${schema}"` : '"public"';
11505
11806
  }
11506
- function getTableName4({ indexName, schemaName }) {
11807
+ function getTableName5({ indexName, schemaName }) {
11507
11808
  const quotedIndexName = `"${indexName}"`;
11508
11809
  return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
11509
11810
  }
@@ -11617,7 +11918,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
11617
11918
  async getScoreById({ id }) {
11618
11919
  try {
11619
11920
  const result = await this.#db.client.oneOrNone(
11620
- `SELECT * FROM ${getTableName4({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) })} WHERE id = $1`,
11921
+ `SELECT * FROM ${getTableName5({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE id = $1`,
11621
11922
  [id]
11622
11923
  );
11623
11924
  return result ? transformScoreRow(result) : null;
@@ -11657,7 +11958,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
11657
11958
  }
11658
11959
  const whereClause = conditions.join(" AND ");
11659
11960
  const total = await this.#db.client.oneOrNone(
11660
- `SELECT COUNT(*) FROM ${getTableName4({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) })} WHERE ${whereClause}`,
11961
+ `SELECT COUNT(*) FROM ${getTableName5({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE ${whereClause}`,
11661
11962
  queryParams
11662
11963
  );
11663
11964
  const { page, perPage: perPageInput } = pagination;
@@ -11677,7 +11978,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
11677
11978
  const limitValue = perPageInput === false ? Number(total?.count) : perPage;
11678
11979
  const end = perPageInput === false ? Number(total?.count) : start + perPage;
11679
11980
  const result = await this.#db.client.manyOrNone(
11680
- `SELECT * FROM ${getTableName4({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) })} WHERE ${whereClause} ORDER BY "createdAt" DESC LIMIT $${paramIndex++} OFFSET $${paramIndex++}`,
11981
+ `SELECT * FROM ${getTableName5({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE ${whereClause} ORDER BY "createdAt" DESC LIMIT $${paramIndex++} OFFSET $${paramIndex++}`,
11681
11982
  [...queryParams, limitValue, start]
11682
11983
  );
11683
11984
  return {
@@ -11772,7 +12073,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
11772
12073
  }) {
11773
12074
  try {
11774
12075
  const total = await this.#db.client.oneOrNone(
11775
- `SELECT COUNT(*) FROM ${getTableName4({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) })} WHERE "runId" = $1`,
12076
+ `SELECT COUNT(*) FROM ${getTableName5({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE "runId" = $1`,
11776
12077
  [runId]
11777
12078
  );
11778
12079
  const { page, perPage: perPageInput } = pagination;
@@ -11792,7 +12093,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
11792
12093
  const limitValue = perPageInput === false ? Number(total?.count) : perPage;
11793
12094
  const end = perPageInput === false ? Number(total?.count) : start + perPage;
11794
12095
  const result = await this.#db.client.manyOrNone(
11795
- `SELECT * FROM ${getTableName4({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) })} WHERE "runId" = $1 LIMIT $2 OFFSET $3`,
12096
+ `SELECT * FROM ${getTableName5({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE "runId" = $1 LIMIT $2 OFFSET $3`,
11796
12097
  [runId, limitValue, start]
11797
12098
  );
11798
12099
  return {
@@ -11822,7 +12123,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
11822
12123
  }) {
11823
12124
  try {
11824
12125
  const total = await this.#db.client.oneOrNone(
11825
- `SELECT COUNT(*) FROM ${getTableName4({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2`,
12126
+ `SELECT COUNT(*) FROM ${getTableName5({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2`,
11826
12127
  [entityId, entityType]
11827
12128
  );
11828
12129
  const { page, perPage: perPageInput } = pagination;
@@ -11842,7 +12143,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
11842
12143
  const limitValue = perPageInput === false ? Number(total?.count) : perPage;
11843
12144
  const end = perPageInput === false ? Number(total?.count) : start + perPage;
11844
12145
  const result = await this.#db.client.manyOrNone(
11845
- `SELECT * FROM ${getTableName4({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2 LIMIT $3 OFFSET $4`,
12146
+ `SELECT * FROM ${getTableName5({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2 LIMIT $3 OFFSET $4`,
11846
12147
  [entityId, entityType, limitValue, start]
11847
12148
  );
11848
12149
  return {
@@ -11871,7 +12172,7 @@ var ScoresPG = class _ScoresPG extends storage.ScoresStorage {
11871
12172
  pagination
11872
12173
  }) {
11873
12174
  try {
11874
- const tableName = getTableName4({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) });
12175
+ const tableName = getTableName5({ indexName: storage.TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) });
11875
12176
  const countSQLResult = await this.#db.client.oneOrNone(
11876
12177
  `SELECT COUNT(*) as count FROM ${tableName} WHERE "traceId" = $1 AND "spanId" = $2`,
11877
12178
  [traceId, spanId]
@@ -12574,10 +12875,10 @@ var SkillsPG = class _SkillsPG extends storage.SkillsStorage {
12574
12875
  };
12575
12876
  }
12576
12877
  };
12577
- function getSchemaName5(schema) {
12878
+ function getSchemaName6(schema) {
12578
12879
  return schema ? `"${schema}"` : '"public"';
12579
12880
  }
12580
- function getTableName5({ indexName, schemaName }) {
12881
+ function getTableName6({ indexName, schemaName }) {
12581
12882
  const quotedIndexName = `"${indexName}"`;
12582
12883
  return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
12583
12884
  }
@@ -12689,7 +12990,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
12689
12990
  }) {
12690
12991
  try {
12691
12992
  return await this.#db.client.tx(async (t) => {
12692
- const tableName = getTableName5({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) });
12993
+ const tableName = getTableName6({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) });
12693
12994
  const existingSnapshotResult = await t.oneOrNone(
12694
12995
  `SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`,
12695
12996
  [workflowName, runId]
@@ -12750,7 +13051,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
12750
13051
  }) {
12751
13052
  try {
12752
13053
  return await this.#db.client.tx(async (t) => {
12753
- const tableName = getTableName5({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) });
13054
+ const tableName = getTableName6({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) });
12754
13055
  const existingSnapshotResult = await t.oneOrNone(
12755
13056
  `SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`,
12756
13057
  [workflowName, runId]
@@ -12800,7 +13101,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
12800
13101
  const updatedAtValue = updatedAt ? updatedAt : now;
12801
13102
  const sanitizedSnapshot = sanitizeJsonForPg(JSON.stringify(snapshot));
12802
13103
  await this.#db.client.none(
12803
- `INSERT INTO ${getTableName5({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) })} (workflow_name, run_id, "resourceId", snapshot, "createdAt", "updatedAt")
13104
+ `INSERT INTO ${getTableName6({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })} (workflow_name, run_id, "resourceId", snapshot, "createdAt", "updatedAt")
12804
13105
  VALUES ($1, $2, $3, $4, $5, $6)
12805
13106
  ON CONFLICT (workflow_name, run_id) DO UPDATE
12806
13107
  SET "resourceId" = $3, snapshot = $4, "updatedAt" = $6`,
@@ -12858,7 +13159,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
12858
13159
  }
12859
13160
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
12860
13161
  const query = `
12861
- SELECT * FROM ${getTableName5({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) })}
13162
+ SELECT * FROM ${getTableName6({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })}
12862
13163
  ${whereClause}
12863
13164
  ORDER BY "createdAt" DESC LIMIT 1
12864
13165
  `;
@@ -12886,7 +13187,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
12886
13187
  async deleteWorkflowRunById({ runId, workflowName }) {
12887
13188
  try {
12888
13189
  await this.#db.client.none(
12889
- `DELETE FROM ${getTableName5({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) })} WHERE run_id = $1 AND workflow_name = $2`,
13190
+ `DELETE FROM ${getTableName6({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })} WHERE run_id = $1 AND workflow_name = $2`,
12890
13191
  [runId, workflowName]
12891
13192
  );
12892
13193
  } catch (error$1) {
@@ -12954,7 +13255,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
12954
13255
  const usePagination = typeof perPage === "number" && typeof page === "number";
12955
13256
  if (usePagination) {
12956
13257
  const countResult = await this.#db.client.one(
12957
- `SELECT COUNT(*) as count FROM ${getTableName5({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) })} ${whereClause}`,
13258
+ `SELECT COUNT(*) as count FROM ${getTableName6({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })} ${whereClause}`,
12958
13259
  values
12959
13260
  );
12960
13261
  total = Number(countResult.count);
@@ -12962,7 +13263,7 @@ var WorkflowsPG = class _WorkflowsPG extends storage.WorkflowsStorage {
12962
13263
  const normalizedPerPage = usePagination ? storage.normalizePerPage(perPage, Number.MAX_SAFE_INTEGER) : 0;
12963
13264
  const offset = usePagination ? page * normalizedPerPage : void 0;
12964
13265
  const query = `
12965
- SELECT * FROM ${getTableName5({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) })}
13266
+ SELECT * FROM ${getTableName6({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })}
12966
13267
  ${whereClause}
12967
13268
  ORDER BY "createdAt" DESC
12968
13269
  ${usePagination ? ` LIMIT $${paramIndex} OFFSET $${paramIndex + 1}` : ""}
@@ -13685,7 +13986,8 @@ var ALL_DOMAINS = [
13685
13986
  AgentsPG,
13686
13987
  WorkflowsPG,
13687
13988
  DatasetsPG,
13688
- ExperimentsPG
13989
+ ExperimentsPG,
13990
+ BackgroundTasksPG
13689
13991
  ];
13690
13992
  function exportSchemas(schemaName) {
13691
13993
  const statements = [];
@@ -13739,7 +14041,8 @@ var PostgresStore = class extends storage.MastraCompositeStore {
13739
14041
  skills: new SkillsPG(domainConfig),
13740
14042
  blobs: new BlobsPG(domainConfig),
13741
14043
  datasets: new DatasetsPG(domainConfig),
13742
- experiments: new ExperimentsPG(domainConfig)
14044
+ experiments: new ExperimentsPG(domainConfig),
14045
+ backgroundTasks: new BackgroundTasksPG(domainConfig)
13743
14046
  };
13744
14047
  } catch (e) {
13745
14048
  throw new error.MastraError(
@@ -13929,6 +14232,7 @@ Example Complex Query:
13929
14232
  }`;
13930
14233
 
13931
14234
  exports.AgentsPG = AgentsPG;
14235
+ exports.BackgroundTasksPG = BackgroundTasksPG;
13932
14236
  exports.BlobsPG = BlobsPG;
13933
14237
  exports.DatasetsPG = DatasetsPG;
13934
14238
  exports.ExperimentsPG = ExperimentsPG;