@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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
2
- import { createVectorErrorId, AgentsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_SCHEMAS, createStorageErrorId, normalizePerPage, calculatePagination, BlobStore, TABLE_SKILL_BLOBS, DatasetsStorage, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, DATASETS_SCHEMA, TABLE_CONFIGS, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, ensureDate, safelyParseJSON, ExperimentsStorage, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, MCPClientsStorage, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, ObservabilityStorage, TABLE_SPANS, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, ScorerDefinitionsStorage, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, TABLE_SCORERS, SkillsStorage, TABLE_SKILLS, TABLE_SKILL_VERSIONS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, WorkspacesStorage, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, MastraCompositeStore, TraceStatus, getDefaultValue, transformScoreRow as transformScoreRow$1, getSqlType } from '@mastra/core/storage';
2
+ import { createVectorErrorId, AgentsStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_SCHEMAS, createStorageErrorId, normalizePerPage, calculatePagination, BackgroundTasksStorage, TABLE_BACKGROUND_TASKS, BlobStore, TABLE_SKILL_BLOBS, DatasetsStorage, TABLE_DATASETS, TABLE_DATASET_ITEMS, TABLE_DATASET_VERSIONS, DATASETS_SCHEMA, TABLE_CONFIGS, DATASET_ITEMS_SCHEMA, DATASET_VERSIONS_SCHEMA, ensureDate, safelyParseJSON, ExperimentsStorage, TABLE_EXPERIMENTS, TABLE_EXPERIMENT_RESULTS, EXPERIMENTS_SCHEMA, EXPERIMENT_RESULTS_SCHEMA, MCPClientsStorage, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, MCPServersStorage, TABLE_MCP_SERVERS, TABLE_MCP_SERVER_VERSIONS, MemoryStorage, TABLE_THREADS, TABLE_MESSAGES, TABLE_RESOURCES, ObservabilityStorage, TABLE_SPANS, listTracesArgsSchema, toTraceSpans, PromptBlocksStorage, TABLE_PROMPT_BLOCKS, TABLE_PROMPT_BLOCK_VERSIONS, ScorerDefinitionsStorage, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, ScoresStorage, TABLE_SCORERS, SkillsStorage, TABLE_SKILLS, TABLE_SKILL_VERSIONS, WorkflowsStorage, TABLE_WORKFLOW_SNAPSHOT, WorkspacesStorage, TABLE_WORKSPACES, TABLE_WORKSPACE_VERSIONS, MastraCompositeStore, TraceStatus, getDefaultValue, transformScoreRow as transformScoreRow$1, getSqlType } from '@mastra/core/storage';
3
3
  import { parseSqlIdentifier, parseFieldKey } from '@mastra/core/utils';
4
4
  import { MastraVector, validateTopK, validateUpsertInput } from '@mastra/core/vector';
5
5
  import { Mutex } from 'async-mutex';
@@ -4255,6 +4255,307 @@ var AgentsPG = class _AgentsPG extends AgentsStorage {
4255
4255
  };
4256
4256
  }
4257
4257
  };
4258
+ function getSchemaName3(schema) {
4259
+ return schema ? `"${schema}"` : '"public"';
4260
+ }
4261
+ function getTableName3(schemaName) {
4262
+ const quoted = `"${TABLE_BACKGROUND_TASKS}"`;
4263
+ return schemaName ? `${schemaName}.${quoted}` : quoted;
4264
+ }
4265
+ function serializeJson(v) {
4266
+ if (typeof v === "object" && v != null) return JSON.stringify(v);
4267
+ return v ?? null;
4268
+ }
4269
+ function parseJson(v) {
4270
+ if (typeof v === "string") {
4271
+ try {
4272
+ return JSON.parse(v);
4273
+ } catch {
4274
+ return v;
4275
+ }
4276
+ }
4277
+ return v ?? void 0;
4278
+ }
4279
+ function rowToTask(row) {
4280
+ return {
4281
+ id: row.id,
4282
+ status: row.status,
4283
+ toolName: row.tool_name,
4284
+ toolCallId: row.tool_call_id,
4285
+ args: parseJson(row.args),
4286
+ agentId: row.agent_id,
4287
+ threadId: row.thread_id ?? void 0,
4288
+ resourceId: row.resource_id ?? void 0,
4289
+ runId: row.run_id,
4290
+ result: parseJson(row.result),
4291
+ error: parseJson(row.error),
4292
+ retryCount: Number(row.retry_count),
4293
+ maxRetries: Number(row.max_retries),
4294
+ timeoutMs: Number(row.timeout_ms),
4295
+ createdAt: row.createdAt instanceof Date ? row.createdAt : new Date(row.createdAt),
4296
+ startedAt: row.startedAt ? row.startedAt instanceof Date ? row.startedAt : new Date(row.startedAt) : void 0,
4297
+ completedAt: row.completedAt ? row.completedAt instanceof Date ? row.completedAt : new Date(row.completedAt) : void 0
4298
+ };
4299
+ }
4300
+ var BackgroundTasksPG = class _BackgroundTasksPG extends BackgroundTasksStorage {
4301
+ #db;
4302
+ #schema;
4303
+ #skipDefaultIndexes;
4304
+ #indexes;
4305
+ static MANAGED_TABLES = [TABLE_BACKGROUND_TASKS];
4306
+ constructor(config) {
4307
+ super();
4308
+ const { client, schemaName, skipDefaultIndexes, indexes } = resolvePgConfig(config);
4309
+ this.#db = new PgDB({ client, schemaName, skipDefaultIndexes });
4310
+ this.#schema = schemaName || "public";
4311
+ this.#skipDefaultIndexes = skipDefaultIndexes;
4312
+ this.#indexes = indexes?.filter((idx) => _BackgroundTasksPG.MANAGED_TABLES.includes(idx.table));
4313
+ }
4314
+ async init() {
4315
+ await this.#db.createTable({
4316
+ tableName: TABLE_BACKGROUND_TASKS,
4317
+ schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS]
4318
+ });
4319
+ await this.createDefaultIndexes();
4320
+ await this.createCustomIndexes();
4321
+ }
4322
+ static getDefaultIndexDefs(schemaPrefix) {
4323
+ return [
4324
+ {
4325
+ name: `${schemaPrefix}mastra_bg_tasks_status_created_at_idx`,
4326
+ table: TABLE_BACKGROUND_TASKS,
4327
+ columns: ["status", "createdAt"]
4328
+ },
4329
+ {
4330
+ name: `${schemaPrefix}mastra_bg_tasks_agent_status_idx`,
4331
+ table: TABLE_BACKGROUND_TASKS,
4332
+ columns: ["agent_id", "status"]
4333
+ },
4334
+ {
4335
+ name: `${schemaPrefix}mastra_bg_tasks_thread_idx`,
4336
+ table: TABLE_BACKGROUND_TASKS,
4337
+ columns: ["thread_id", "createdAt"]
4338
+ },
4339
+ {
4340
+ name: `${schemaPrefix}mastra_bg_tasks_tool_call_idx`,
4341
+ table: TABLE_BACKGROUND_TASKS,
4342
+ columns: ["tool_call_id"]
4343
+ }
4344
+ ];
4345
+ }
4346
+ static getExportDDL(schemaName) {
4347
+ const statements = [];
4348
+ const parsedSchema = schemaName ? parseSqlIdentifier(schemaName, "schema name") : "";
4349
+ const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
4350
+ statements.push(
4351
+ generateTableSQL({
4352
+ tableName: TABLE_BACKGROUND_TASKS,
4353
+ schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS],
4354
+ schemaName,
4355
+ includeAllConstraints: true
4356
+ })
4357
+ );
4358
+ for (const idx of _BackgroundTasksPG.getDefaultIndexDefs(schemaPrefix)) {
4359
+ statements.push(generateIndexSQL(idx, schemaName));
4360
+ }
4361
+ return statements;
4362
+ }
4363
+ getDefaultIndexDefinitions() {
4364
+ const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
4365
+ return _BackgroundTasksPG.getDefaultIndexDefs(schemaPrefix);
4366
+ }
4367
+ async createDefaultIndexes() {
4368
+ if (this.#skipDefaultIndexes) return;
4369
+ for (const indexDef of this.getDefaultIndexDefinitions()) {
4370
+ try {
4371
+ await this.#db.createIndex(indexDef);
4372
+ } catch (error) {
4373
+ this.logger?.warn?.(`Failed to create index ${indexDef.name}:`, error);
4374
+ }
4375
+ }
4376
+ }
4377
+ async createCustomIndexes() {
4378
+ if (!this.#indexes || this.#indexes.length === 0) return;
4379
+ for (const indexDef of this.#indexes) {
4380
+ try {
4381
+ await this.#db.createIndex(indexDef);
4382
+ } catch (error) {
4383
+ this.logger?.warn?.(`Failed to create custom index ${indexDef.name}:`, error);
4384
+ }
4385
+ }
4386
+ }
4387
+ async dangerouslyClearAll() {
4388
+ await this.#db.clearTable({ tableName: TABLE_BACKGROUND_TASKS });
4389
+ }
4390
+ async createTask(task) {
4391
+ await this.#db.insert({
4392
+ tableName: TABLE_BACKGROUND_TASKS,
4393
+ record: {
4394
+ id: task.id,
4395
+ tool_call_id: task.toolCallId,
4396
+ tool_name: task.toolName,
4397
+ agent_id: task.agentId,
4398
+ thread_id: task.threadId ?? null,
4399
+ resource_id: task.resourceId ?? null,
4400
+ run_id: task.runId,
4401
+ status: task.status,
4402
+ args: serializeJson(task.args),
4403
+ result: serializeJson(task.result),
4404
+ error: serializeJson(task.error),
4405
+ retry_count: task.retryCount,
4406
+ max_retries: task.maxRetries,
4407
+ timeout_ms: task.timeoutMs,
4408
+ createdAt: task.createdAt.toISOString(),
4409
+ startedAt: task.startedAt?.toISOString() ?? null,
4410
+ completedAt: task.completedAt?.toISOString() ?? null
4411
+ }
4412
+ });
4413
+ }
4414
+ async updateTask(taskId, update) {
4415
+ const setClauses = [];
4416
+ const params = [];
4417
+ let paramIdx = 1;
4418
+ if ("status" in update) {
4419
+ setClauses.push(`"status" = $${paramIdx++}`);
4420
+ params.push(update.status);
4421
+ }
4422
+ if ("result" in update) {
4423
+ setClauses.push(`"result" = $${paramIdx++}`);
4424
+ params.push(serializeJson(update.result));
4425
+ }
4426
+ if ("error" in update) {
4427
+ setClauses.push(`"error" = $${paramIdx++}`);
4428
+ params.push(serializeJson(update.error));
4429
+ }
4430
+ if ("retryCount" in update) {
4431
+ setClauses.push(`"retry_count" = $${paramIdx++}`);
4432
+ params.push(update.retryCount);
4433
+ }
4434
+ if ("startedAt" in update) {
4435
+ setClauses.push(`"startedAt" = $${paramIdx++}`);
4436
+ params.push(update.startedAt?.toISOString() ?? null);
4437
+ }
4438
+ if ("completedAt" in update) {
4439
+ setClauses.push(`"completedAt" = $${paramIdx++}`);
4440
+ params.push(update.completedAt?.toISOString() ?? null);
4441
+ }
4442
+ if (setClauses.length === 0) return;
4443
+ const table = getTableName3(getSchemaName3(this.#schema));
4444
+ params.push(taskId);
4445
+ await this.#db.client.none(`UPDATE ${table} SET ${setClauses.join(", ")} WHERE "id" = $${paramIdx}`, params);
4446
+ }
4447
+ async getTask(taskId) {
4448
+ const table = getTableName3(getSchemaName3(this.#schema));
4449
+ const row = await this.#db.client.oneOrNone(`SELECT * FROM ${table} WHERE "id" = $1`, [taskId]);
4450
+ return row ? rowToTask(row) : null;
4451
+ }
4452
+ async listTasks(filter) {
4453
+ const table = getTableName3(getSchemaName3(this.#schema));
4454
+ const conditions = [];
4455
+ const params = [];
4456
+ let paramIdx = 1;
4457
+ if (filter.status) {
4458
+ const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
4459
+ const placeholders = statuses.map(() => `$${paramIdx++}`);
4460
+ conditions.push(`"status" IN (${placeholders.join(", ")})`);
4461
+ params.push(...statuses);
4462
+ }
4463
+ if (filter.agentId) {
4464
+ conditions.push(`"agent_id" = $${paramIdx++}`);
4465
+ params.push(filter.agentId);
4466
+ }
4467
+ if (filter.threadId) {
4468
+ conditions.push(`"thread_id" = $${paramIdx++}`);
4469
+ params.push(filter.threadId);
4470
+ }
4471
+ if (filter.resourceId) {
4472
+ conditions.push(`"resource_id" = $${paramIdx++}`);
4473
+ params.push(filter.resourceId);
4474
+ }
4475
+ if (filter.runId) {
4476
+ conditions.push(`"run_id" = $${paramIdx++}`);
4477
+ params.push(filter.runId);
4478
+ }
4479
+ if (filter.toolName) {
4480
+ conditions.push(`"tool_name" = $${paramIdx++}`);
4481
+ params.push(filter.toolName);
4482
+ }
4483
+ const dateCol = filter.dateFilterBy === "startedAt" ? '"startedAt"' : filter.dateFilterBy === "completedAt" ? '"completedAt"' : '"createdAt"';
4484
+ if (filter.fromDate) {
4485
+ conditions.push(`${dateCol} >= $${paramIdx++}`);
4486
+ params.push(filter.fromDate.toISOString());
4487
+ }
4488
+ if (filter.toDate) {
4489
+ conditions.push(`${dateCol} < $${paramIdx++}`);
4490
+ params.push(filter.toDate.toISOString());
4491
+ }
4492
+ const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
4493
+ const countResult = await this.#db.client.oneOrNone(
4494
+ `SELECT COUNT(*) as count FROM ${table} ${where}`,
4495
+ params.slice(0, paramIdx - 1)
4496
+ );
4497
+ const total = Number(countResult?.count ?? 0);
4498
+ const orderCol = filter.orderBy === "startedAt" ? '"startedAt"' : filter.orderBy === "completedAt" ? '"completedAt"' : '"createdAt"';
4499
+ const direction = filter.orderDirection === "desc" ? "DESC" : "ASC";
4500
+ let sql = `SELECT * FROM ${table} ${where} ORDER BY ${orderCol} ${direction}`;
4501
+ if (filter.perPage != null) {
4502
+ sql += ` LIMIT $${paramIdx++}`;
4503
+ params.push(filter.perPage);
4504
+ if (filter.page != null) {
4505
+ sql += ` OFFSET $${paramIdx++}`;
4506
+ params.push(filter.page * filter.perPage);
4507
+ }
4508
+ }
4509
+ const rows = await this.#db.client.manyOrNone(sql, params);
4510
+ return { tasks: rows.map(rowToTask), total };
4511
+ }
4512
+ async deleteTask(taskId) {
4513
+ const table = getTableName3(getSchemaName3(this.#schema));
4514
+ await this.#db.client.none(`DELETE FROM ${table} WHERE "id" = $1`, [taskId]);
4515
+ }
4516
+ async deleteTasks(filter) {
4517
+ const table = getTableName3(getSchemaName3(this.#schema));
4518
+ const conditions = [];
4519
+ const params = [];
4520
+ let paramIdx = 1;
4521
+ if (filter.status) {
4522
+ const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
4523
+ const placeholders = statuses.map(() => `$${paramIdx++}`);
4524
+ conditions.push(`"status" IN (${placeholders.join(", ")})`);
4525
+ params.push(...statuses);
4526
+ }
4527
+ const dateCol = filter.dateFilterBy === "startedAt" ? '"startedAt"' : filter.dateFilterBy === "completedAt" ? '"completedAt"' : '"createdAt"';
4528
+ if (filter.fromDate) {
4529
+ conditions.push(`${dateCol} >= $${paramIdx++}`);
4530
+ params.push(filter.fromDate.toISOString());
4531
+ }
4532
+ if (filter.toDate) {
4533
+ conditions.push(`${dateCol} < $${paramIdx++}`);
4534
+ params.push(filter.toDate.toISOString());
4535
+ }
4536
+ if (filter.agentId) {
4537
+ conditions.push(`"agent_id" = $${paramIdx++}`);
4538
+ params.push(filter.agentId);
4539
+ }
4540
+ if (conditions.length === 0) return;
4541
+ await this.#db.client.none(`DELETE FROM ${table} WHERE ${conditions.join(" AND ")}`, params);
4542
+ }
4543
+ async getRunningCount() {
4544
+ const table = getTableName3(getSchemaName3(this.#schema));
4545
+ const result = await this.#db.client.oneOrNone(
4546
+ `SELECT COUNT(*) FROM ${table} WHERE "status" = 'running'`
4547
+ );
4548
+ return Number(result?.count ?? 0);
4549
+ }
4550
+ async getRunningCountByAgent(agentId) {
4551
+ const table = getTableName3(getSchemaName3(this.#schema));
4552
+ const result = await this.#db.client.oneOrNone(
4553
+ `SELECT COUNT(*) FROM ${table} WHERE "status" = 'running' AND "agent_id" = $1`,
4554
+ [agentId]
4555
+ );
4556
+ return Number(result?.count ?? 0);
4557
+ }
4558
+ };
4258
4559
  var BlobsPG = class extends BlobStore {
4259
4560
  #db;
4260
4561
  #schema;
@@ -7144,10 +7445,10 @@ try {
7144
7445
  _omTableSchema = storage.OBSERVATIONAL_MEMORY_TABLE_SCHEMA;
7145
7446
  } catch {
7146
7447
  }
7147
- function getSchemaName3(schema) {
7448
+ function getSchemaName4(schema) {
7148
7449
  return schema ? `"${schema}"` : '"public"';
7149
7450
  }
7150
- function getTableName3({ indexName, schemaName }) {
7451
+ function getTableName4({ indexName, schemaName }) {
7151
7452
  const quotedIndexName = `"${indexName}"`;
7152
7453
  return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
7153
7454
  }
@@ -7212,9 +7513,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7212
7513
  ifNotExists: ["resourceId"]
7213
7514
  });
7214
7515
  if (omSchema) {
7215
- const omTableName = getTableName3({
7516
+ const omTableName = getTableName4({
7216
7517
  indexName: OM_TABLE,
7217
- schemaName: getSchemaName3(this.#schema)
7518
+ schemaName: getSchemaName4(this.#schema)
7218
7519
  });
7219
7520
  await this.#db.client.none(`CREATE INDEX IF NOT EXISTS idx_om_lookup_key ON ${omTableName} ("lookupKey")`);
7220
7521
  }
@@ -7337,7 +7638,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7337
7638
  }
7338
7639
  async getThreadById({ threadId }) {
7339
7640
  try {
7340
- const tableName = getTableName3({ indexName: TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
7641
+ const tableName = getTableName4({ indexName: TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
7341
7642
  const thread = await this.#db.client.oneOrNone(
7342
7643
  `SELECT * FROM ${tableName} WHERE id = $1`,
7343
7644
  [threadId]
@@ -7395,7 +7696,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7395
7696
  const { field, direction } = this.parseOrderBy(orderBy);
7396
7697
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
7397
7698
  try {
7398
- const tableName = getTableName3({ indexName: TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
7699
+ const tableName = getTableName4({ indexName: TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
7399
7700
  const whereClauses = [];
7400
7701
  const queryParams = [];
7401
7702
  let paramIndex = 1;
@@ -7474,7 +7775,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7474
7775
  }
7475
7776
  async saveThread({ thread }) {
7476
7777
  try {
7477
- const tableName = getTableName3({ indexName: TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
7778
+ const tableName = getTableName4({ indexName: TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
7478
7779
  await this.#db.client.none(
7479
7780
  `INSERT INTO ${tableName} (
7480
7781
  id,
@@ -7525,7 +7826,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7525
7826
  title,
7526
7827
  metadata
7527
7828
  }) {
7528
- const threadTableName = getTableName3({ indexName: TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
7829
+ const threadTableName = getTableName4({ indexName: TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
7529
7830
  const existingThread = await this.getThreadById({ threadId: id });
7530
7831
  if (!existingThread) {
7531
7832
  throw new MastraError({
@@ -7582,8 +7883,8 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7582
7883
  }
7583
7884
  async deleteThread({ threadId }) {
7584
7885
  try {
7585
- const tableName = getTableName3({ indexName: TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
7586
- const threadTableName = getTableName3({ indexName: TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
7886
+ const tableName = getTableName4({ indexName: TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
7887
+ const threadTableName = getTableName4({ indexName: TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
7587
7888
  await this.#db.client.tx(async (t) => {
7588
7889
  await t.none(`DELETE FROM ${tableName} WHERE thread_id = $1`, [threadId]);
7589
7890
  const schemaName = this.#schema || "public";
@@ -7597,7 +7898,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7597
7898
  [schemaName]
7598
7899
  );
7599
7900
  for (const { tablename } of vectorTables) {
7600
- const vectorTableName = getTableName3({ indexName: tablename, schemaName: getSchemaName3(this.#schema) });
7901
+ const vectorTableName = getTableName4({ indexName: tablename, schemaName: getSchemaName4(this.#schema) });
7601
7902
  await t.none(`DELETE FROM ${vectorTableName} WHERE metadata->>'thread_id' = $1`, [threadId]);
7602
7903
  }
7603
7904
  await t.none(`DELETE FROM ${threadTableName} WHERE id = $1`, [threadId]);
@@ -7648,7 +7949,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7648
7949
  }
7649
7950
  async _getIncludedMessages({ include }) {
7650
7951
  if (!include || include.length === 0) return null;
7651
- const tableName = getTableName3({ indexName: TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
7952
+ const tableName = getTableName4({ indexName: TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
7652
7953
  const selectColumns = `id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"`;
7653
7954
  const targetIds = include.map((inc) => inc.id).filter(Boolean);
7654
7955
  if (targetIds.length === 0) return null;
@@ -7729,7 +8030,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7729
8030
  if (messageIds.length === 0) return { messages: [] };
7730
8031
  const selectStatement = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"`;
7731
8032
  try {
7732
- const tableName = getTableName3({ indexName: TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
8033
+ const tableName = getTableName4({ indexName: TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
7733
8034
  const query = `
7734
8035
  ${selectStatement} FROM ${tableName}
7735
8036
  WHERE id IN (${inPlaceholders(messageIds.length)})
@@ -7792,7 +8093,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7792
8093
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
7793
8094
  const orderByStatement = `ORDER BY COALESCE("${field}Z", "${field}") ${direction}`;
7794
8095
  const selectStatement = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"`;
7795
- const tableName = getTableName3({ indexName: TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
8096
+ const tableName = getTableName4({ indexName: TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
7796
8097
  const conditions = [`thread_id IN (${inPlaceholders(threadIds.length)})`];
7797
8098
  const queryParams = [...threadIds];
7798
8099
  let paramIndex = threadIds.length + 1;
@@ -7931,7 +8232,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7931
8232
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
7932
8233
  const orderByStatement = `ORDER BY COALESCE("${field}Z", "${field}") ${direction}`;
7933
8234
  const selectStatement = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"`;
7934
- const tableName = getTableName3({ indexName: TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
8235
+ const tableName = getTableName4({ indexName: TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
7935
8236
  const conditions = [];
7936
8237
  const queryParams = [];
7937
8238
  let paramIndex = 1;
@@ -8058,7 +8359,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8058
8359
  });
8059
8360
  }
8060
8361
  try {
8061
- const tableName = getTableName3({ indexName: TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
8362
+ const tableName = getTableName4({ indexName: TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
8062
8363
  await this.#db.client.tx(async (t) => {
8063
8364
  for (const message of messages) {
8064
8365
  if (!message.threadId) {
@@ -8092,7 +8393,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8092
8393
  ]
8093
8394
  );
8094
8395
  }
8095
- const threadTableName = getTableName3({ indexName: TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
8396
+ const threadTableName = getTableName4({ indexName: TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
8096
8397
  const now = /* @__PURE__ */ new Date();
8097
8398
  await t.none(
8098
8399
  `UPDATE ${threadTableName}
@@ -8136,7 +8437,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8136
8437
  return [];
8137
8438
  }
8138
8439
  const messageIds = messages.map((m) => m.id);
8139
- const selectQuery = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId" FROM ${getTableName3({ indexName: TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) })} WHERE id IN (${inPlaceholders(messageIds.length)})`;
8440
+ const selectQuery = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId" FROM ${getTableName4({ indexName: TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) })} WHERE id IN (${inPlaceholders(messageIds.length)})`;
8140
8441
  const existingMessagesDb = await this.#db.client.manyOrNone(selectQuery, messageIds);
8141
8442
  if (existingMessagesDb.length === 0) {
8142
8443
  return [];
@@ -8193,7 +8494,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8193
8494
  }
8194
8495
  if (setClauses.length > 0) {
8195
8496
  values.push(id);
8196
- const sql = `UPDATE ${getTableName3({ indexName: TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) })} SET ${setClauses.join(", ")} WHERE id = $${paramIndex}`;
8497
+ const sql = `UPDATE ${getTableName4({ indexName: TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) })} SET ${setClauses.join(", ")} WHERE id = $${paramIndex}`;
8197
8498
  queries.push(t.none(sql, values));
8198
8499
  }
8199
8500
  }
@@ -8201,7 +8502,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8201
8502
  const threadIds = Array.from(threadIdsToUpdate);
8202
8503
  queries.push(
8203
8504
  t.none(
8204
- `UPDATE ${getTableName3({ indexName: TABLE_THREADS, schemaName: getSchemaName3(this.#schema) })} SET "updatedAt" = NOW(), "updatedAtZ" = NOW() WHERE id IN (${inPlaceholders(threadIds.length)})`,
8505
+ `UPDATE ${getTableName4({ indexName: TABLE_THREADS, schemaName: getSchemaName4(this.#schema) })} SET "updatedAt" = NOW(), "updatedAtZ" = NOW() WHERE id IN (${inPlaceholders(threadIds.length)})`,
8205
8506
  threadIds
8206
8507
  )
8207
8508
  );
@@ -8227,8 +8528,8 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8227
8528
  return;
8228
8529
  }
8229
8530
  try {
8230
- const messageTableName = getTableName3({ indexName: TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
8231
- const threadTableName = getTableName3({ indexName: TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
8531
+ const messageTableName = getTableName4({ indexName: TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
8532
+ const threadTableName = getTableName4({ indexName: TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
8232
8533
  await this.#db.client.tx(async (t) => {
8233
8534
  const placeholders = messageIds.map((_, idx) => `$${idx + 1}`).join(",");
8234
8535
  const messages = await t.manyOrNone(
@@ -8257,7 +8558,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8257
8558
  }
8258
8559
  }
8259
8560
  async getResourceById({ resourceId }) {
8260
- const tableName = getTableName3({ indexName: TABLE_RESOURCES, schemaName: getSchemaName3(this.#schema) });
8561
+ const tableName = getTableName4({ indexName: TABLE_RESOURCES, schemaName: getSchemaName4(this.#schema) });
8261
8562
  const result = await this.#db.client.oneOrNone(
8262
8563
  `SELECT * FROM ${tableName} WHERE id = $1`,
8263
8564
  [resourceId]
@@ -8308,7 +8609,7 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8308
8609
  },
8309
8610
  updatedAt: /* @__PURE__ */ new Date()
8310
8611
  };
8311
- const tableName = getTableName3({ indexName: TABLE_RESOURCES, schemaName: getSchemaName3(this.#schema) });
8612
+ const tableName = getTableName4({ indexName: TABLE_RESOURCES, schemaName: getSchemaName4(this.#schema) });
8312
8613
  const updates = [];
8313
8614
  const values = [];
8314
8615
  let paramIndex = 1;
@@ -8354,8 +8655,8 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8354
8655
  details: { newThreadId }
8355
8656
  });
8356
8657
  }
8357
- const threadTableName = getTableName3({ indexName: TABLE_THREADS, schemaName: getSchemaName3(this.#schema) });
8358
- const messageTableName = getTableName3({ indexName: TABLE_MESSAGES, schemaName: getSchemaName3(this.#schema) });
8658
+ const threadTableName = getTableName4({ indexName: TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
8659
+ const messageTableName = getTableName4({ indexName: TABLE_MESSAGES, schemaName: getSchemaName4(this.#schema) });
8359
8660
  try {
8360
8661
  return await this.#db.client.tx(async (t) => {
8361
8662
  let messageQuery = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"
@@ -8525,9 +8826,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8525
8826
  async getObservationalMemory(threadId, resourceId) {
8526
8827
  try {
8527
8828
  const lookupKey = this.getOMKey(threadId, resourceId);
8528
- const tableName = getTableName3({
8829
+ const tableName = getTableName4({
8529
8830
  indexName: OM_TABLE,
8530
- schemaName: getSchemaName3(this.#schema)
8831
+ schemaName: getSchemaName4(this.#schema)
8531
8832
  });
8532
8833
  const result = await this.#db.client.oneOrNone(
8533
8834
  `SELECT * FROM ${tableName} WHERE "lookupKey" = $1 ORDER BY "generationCount" DESC LIMIT 1`,
@@ -8550,9 +8851,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8550
8851
  async getObservationalMemoryHistory(threadId, resourceId, limit = 10, options) {
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 conditions = [`"lookupKey" = $1`];
8558
8859
  const params = [lookupKey];
@@ -8617,9 +8918,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8617
8918
  config: input.config,
8618
8919
  observedTimezone: input.observedTimezone
8619
8920
  };
8620
- const tableName = getTableName3({
8921
+ const tableName = getTableName4({
8621
8922
  indexName: OM_TABLE,
8622
- schemaName: getSchemaName3(this.#schema)
8923
+ schemaName: getSchemaName4(this.#schema)
8623
8924
  });
8624
8925
  const nowStr = now.toISOString();
8625
8926
  await this.#db.client.none(
@@ -8690,9 +8991,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8690
8991
  async insertObservationalMemoryRecord(record) {
8691
8992
  try {
8692
8993
  const lookupKey = this.getOMKey(record.threadId, record.resourceId);
8693
- const tableName = getTableName3({
8994
+ const tableName = getTableName4({
8694
8995
  indexName: OM_TABLE,
8695
- schemaName: getSchemaName3(this.#schema)
8996
+ schemaName: getSchemaName4(this.#schema)
8696
8997
  });
8697
8998
  const lastObservedAtStr = record.lastObservedAt ? record.lastObservedAt.toISOString() : null;
8698
8999
  const lastBufferedAtTimeStr = record.lastBufferedAtTime ? record.lastBufferedAtTime.toISOString() : null;
@@ -8764,9 +9065,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8764
9065
  async updateActiveObservations(input) {
8765
9066
  try {
8766
9067
  const now = /* @__PURE__ */ new Date();
8767
- const tableName = getTableName3({
9068
+ const tableName = getTableName4({
8768
9069
  indexName: OM_TABLE,
8769
- schemaName: getSchemaName3(this.#schema)
9070
+ schemaName: getSchemaName4(this.#schema)
8770
9071
  });
8771
9072
  const lastObservedAtStr = input.lastObservedAt.toISOString();
8772
9073
  const nowStr = now.toISOString();
@@ -8848,9 +9149,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8848
9149
  metadata: input.currentRecord.metadata,
8849
9150
  observedTimezone: input.currentRecord.observedTimezone
8850
9151
  };
8851
- const tableName = getTableName3({
9152
+ const tableName = getTableName4({
8852
9153
  indexName: OM_TABLE,
8853
- schemaName: getSchemaName3(this.#schema)
9154
+ schemaName: getSchemaName4(this.#schema)
8854
9155
  });
8855
9156
  const nowStr = now.toISOString();
8856
9157
  const lastObservedAtStr = record.lastObservedAt?.toISOString() || null;
@@ -8924,9 +9225,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8924
9225
  }
8925
9226
  async setReflectingFlag(id, isReflecting) {
8926
9227
  try {
8927
- const tableName = getTableName3({
9228
+ const tableName = getTableName4({
8928
9229
  indexName: OM_TABLE,
8929
- schemaName: getSchemaName3(this.#schema)
9230
+ schemaName: getSchemaName4(this.#schema)
8930
9231
  });
8931
9232
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
8932
9233
  const result = await this.#db.client.query(
@@ -8959,9 +9260,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8959
9260
  }
8960
9261
  async setObservingFlag(id, isObserving) {
8961
9262
  try {
8962
- const tableName = getTableName3({
9263
+ const tableName = getTableName4({
8963
9264
  indexName: OM_TABLE,
8964
- schemaName: getSchemaName3(this.#schema)
9265
+ schemaName: getSchemaName4(this.#schema)
8965
9266
  });
8966
9267
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
8967
9268
  const result = await this.#db.client.query(
@@ -8994,9 +9295,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
8994
9295
  }
8995
9296
  async setBufferingObservationFlag(id, isBuffering, lastBufferedAtTokens) {
8996
9297
  try {
8997
- const tableName = getTableName3({
9298
+ const tableName = getTableName4({
8998
9299
  indexName: OM_TABLE,
8999
- schemaName: getSchemaName3(this.#schema)
9300
+ schemaName: getSchemaName4(this.#schema)
9000
9301
  });
9001
9302
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
9002
9303
  let query;
@@ -9035,9 +9336,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
9035
9336
  }
9036
9337
  async setBufferingReflectionFlag(id, isBuffering) {
9037
9338
  try {
9038
- const tableName = getTableName3({
9339
+ const tableName = getTableName4({
9039
9340
  indexName: OM_TABLE,
9040
- schemaName: getSchemaName3(this.#schema)
9341
+ schemaName: getSchemaName4(this.#schema)
9041
9342
  });
9042
9343
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
9043
9344
  const result = await this.#db.client.query(
@@ -9071,9 +9372,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
9071
9372
  async clearObservationalMemory(threadId, resourceId) {
9072
9373
  try {
9073
9374
  const lookupKey = this.getOMKey(threadId, resourceId);
9074
- const tableName = getTableName3({
9375
+ const tableName = getTableName4({
9075
9376
  indexName: OM_TABLE,
9076
- schemaName: getSchemaName3(this.#schema)
9377
+ schemaName: getSchemaName4(this.#schema)
9077
9378
  });
9078
9379
  await this.#db.client.none(`DELETE FROM ${tableName} WHERE "lookupKey" = $1`, [lookupKey]);
9079
9380
  } catch (error) {
@@ -9090,9 +9391,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
9090
9391
  }
9091
9392
  async setPendingMessageTokens(id, tokenCount) {
9092
9393
  try {
9093
- const tableName = getTableName3({
9394
+ const tableName = getTableName4({
9094
9395
  indexName: OM_TABLE,
9095
- schemaName: getSchemaName3(this.#schema)
9396
+ schemaName: getSchemaName4(this.#schema)
9096
9397
  });
9097
9398
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
9098
9399
  const result = await this.#db.client.query(
@@ -9129,9 +9430,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
9129
9430
  }
9130
9431
  async updateObservationalMemoryConfig(input) {
9131
9432
  try {
9132
- const tableName = getTableName3({
9433
+ const tableName = getTableName4({
9133
9434
  indexName: OM_TABLE,
9134
- schemaName: getSchemaName3(this.#schema)
9435
+ schemaName: getSchemaName4(this.#schema)
9135
9436
  });
9136
9437
  const selectResult = await this.#db.client.query(`SELECT config FROM ${tableName} WHERE id = $1`, [input.id]);
9137
9438
  if (selectResult.rowCount === 0) {
@@ -9171,9 +9472,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
9171
9472
  // ============================================
9172
9473
  async updateBufferedObservations(input) {
9173
9474
  try {
9174
- const tableName = getTableName3({
9475
+ const tableName = getTableName4({
9175
9476
  indexName: OM_TABLE,
9176
- schemaName: getSchemaName3(this.#schema)
9477
+ schemaName: getSchemaName4(this.#schema)
9177
9478
  });
9178
9479
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
9179
9480
  const newChunk = {
@@ -9225,9 +9526,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
9225
9526
  }
9226
9527
  async swapBufferedToActive(input) {
9227
9528
  try {
9228
- const tableName = getTableName3({
9529
+ const tableName = getTableName4({
9229
9530
  indexName: OM_TABLE,
9230
- schemaName: getSchemaName3(this.#schema)
9531
+ schemaName: getSchemaName4(this.#schema)
9231
9532
  });
9232
9533
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
9233
9534
  const record = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE id = $1`, [input.id]);
@@ -9390,9 +9691,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
9390
9691
  }
9391
9692
  async updateBufferedReflection(input) {
9392
9693
  try {
9393
- const tableName = getTableName3({
9694
+ const tableName = getTableName4({
9394
9695
  indexName: OM_TABLE,
9395
- schemaName: getSchemaName3(this.#schema)
9696
+ schemaName: getSchemaName4(this.#schema)
9396
9697
  });
9397
9698
  const nowStr = (/* @__PURE__ */ new Date()).toISOString();
9398
9699
  const result = await this.#db.client.query(
@@ -9444,9 +9745,9 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
9444
9745
  }
9445
9746
  async swapBufferedReflectionToActive(input) {
9446
9747
  try {
9447
- const tableName = getTableName3({
9748
+ const tableName = getTableName4({
9448
9749
  indexName: OM_TABLE,
9449
- schemaName: getSchemaName3(this.#schema)
9750
+ schemaName: getSchemaName4(this.#schema)
9450
9751
  });
9451
9752
  const record = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE id = $1`, [
9452
9753
  input.currentRecord.id
@@ -11475,10 +11776,10 @@ var ScorerDefinitionsPG = class _ScorerDefinitionsPG extends ScorerDefinitionsSt
11475
11776
  };
11476
11777
  }
11477
11778
  };
11478
- function getSchemaName4(schema) {
11779
+ function getSchemaName5(schema) {
11479
11780
  return schema ? `"${schema}"` : '"public"';
11480
11781
  }
11481
- function getTableName4({ indexName, schemaName }) {
11782
+ function getTableName5({ indexName, schemaName }) {
11482
11783
  const quotedIndexName = `"${indexName}"`;
11483
11784
  return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
11484
11785
  }
@@ -11592,7 +11893,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
11592
11893
  async getScoreById({ id }) {
11593
11894
  try {
11594
11895
  const result = await this.#db.client.oneOrNone(
11595
- `SELECT * FROM ${getTableName4({ indexName: TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) })} WHERE id = $1`,
11896
+ `SELECT * FROM ${getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE id = $1`,
11596
11897
  [id]
11597
11898
  );
11598
11899
  return result ? transformScoreRow(result) : null;
@@ -11632,7 +11933,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
11632
11933
  }
11633
11934
  const whereClause = conditions.join(" AND ");
11634
11935
  const total = await this.#db.client.oneOrNone(
11635
- `SELECT COUNT(*) FROM ${getTableName4({ indexName: TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) })} WHERE ${whereClause}`,
11936
+ `SELECT COUNT(*) FROM ${getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE ${whereClause}`,
11636
11937
  queryParams
11637
11938
  );
11638
11939
  const { page, perPage: perPageInput } = pagination;
@@ -11652,7 +11953,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
11652
11953
  const limitValue = perPageInput === false ? Number(total?.count) : perPage;
11653
11954
  const end = perPageInput === false ? Number(total?.count) : start + perPage;
11654
11955
  const result = await this.#db.client.manyOrNone(
11655
- `SELECT * FROM ${getTableName4({ indexName: TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) })} WHERE ${whereClause} ORDER BY "createdAt" DESC LIMIT $${paramIndex++} OFFSET $${paramIndex++}`,
11956
+ `SELECT * FROM ${getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE ${whereClause} ORDER BY "createdAt" DESC LIMIT $${paramIndex++} OFFSET $${paramIndex++}`,
11656
11957
  [...queryParams, limitValue, start]
11657
11958
  );
11658
11959
  return {
@@ -11747,7 +12048,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
11747
12048
  }) {
11748
12049
  try {
11749
12050
  const total = await this.#db.client.oneOrNone(
11750
- `SELECT COUNT(*) FROM ${getTableName4({ indexName: TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) })} WHERE "runId" = $1`,
12051
+ `SELECT COUNT(*) FROM ${getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE "runId" = $1`,
11751
12052
  [runId]
11752
12053
  );
11753
12054
  const { page, perPage: perPageInput } = pagination;
@@ -11767,7 +12068,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
11767
12068
  const limitValue = perPageInput === false ? Number(total?.count) : perPage;
11768
12069
  const end = perPageInput === false ? Number(total?.count) : start + perPage;
11769
12070
  const result = await this.#db.client.manyOrNone(
11770
- `SELECT * FROM ${getTableName4({ indexName: TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) })} WHERE "runId" = $1 LIMIT $2 OFFSET $3`,
12071
+ `SELECT * FROM ${getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE "runId" = $1 LIMIT $2 OFFSET $3`,
11771
12072
  [runId, limitValue, start]
11772
12073
  );
11773
12074
  return {
@@ -11797,7 +12098,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
11797
12098
  }) {
11798
12099
  try {
11799
12100
  const total = await this.#db.client.oneOrNone(
11800
- `SELECT COUNT(*) FROM ${getTableName4({ indexName: TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2`,
12101
+ `SELECT COUNT(*) FROM ${getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2`,
11801
12102
  [entityId, entityType]
11802
12103
  );
11803
12104
  const { page, perPage: perPageInput } = pagination;
@@ -11817,7 +12118,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
11817
12118
  const limitValue = perPageInput === false ? Number(total?.count) : perPage;
11818
12119
  const end = perPageInput === false ? Number(total?.count) : start + perPage;
11819
12120
  const result = await this.#db.client.manyOrNone(
11820
- `SELECT * FROM ${getTableName4({ indexName: TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2 LIMIT $3 OFFSET $4`,
12121
+ `SELECT * FROM ${getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) })} WHERE "entityId" = $1 AND "entityType" = $2 LIMIT $3 OFFSET $4`,
11821
12122
  [entityId, entityType, limitValue, start]
11822
12123
  );
11823
12124
  return {
@@ -11846,7 +12147,7 @@ var ScoresPG = class _ScoresPG extends ScoresStorage {
11846
12147
  pagination
11847
12148
  }) {
11848
12149
  try {
11849
- const tableName = getTableName4({ indexName: TABLE_SCORERS, schemaName: getSchemaName4(this.#schema) });
12150
+ const tableName = getTableName5({ indexName: TABLE_SCORERS, schemaName: getSchemaName5(this.#schema) });
11850
12151
  const countSQLResult = await this.#db.client.oneOrNone(
11851
12152
  `SELECT COUNT(*) as count FROM ${tableName} WHERE "traceId" = $1 AND "spanId" = $2`,
11852
12153
  [traceId, spanId]
@@ -12549,10 +12850,10 @@ var SkillsPG = class _SkillsPG extends SkillsStorage {
12549
12850
  };
12550
12851
  }
12551
12852
  };
12552
- function getSchemaName5(schema) {
12853
+ function getSchemaName6(schema) {
12553
12854
  return schema ? `"${schema}"` : '"public"';
12554
12855
  }
12555
- function getTableName5({ indexName, schemaName }) {
12856
+ function getTableName6({ indexName, schemaName }) {
12556
12857
  const quotedIndexName = `"${indexName}"`;
12557
12858
  return schemaName ? `${schemaName}.${quotedIndexName}` : quotedIndexName;
12558
12859
  }
@@ -12664,7 +12965,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
12664
12965
  }) {
12665
12966
  try {
12666
12967
  return await this.#db.client.tx(async (t) => {
12667
- const tableName = getTableName5({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) });
12968
+ const tableName = getTableName6({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) });
12668
12969
  const existingSnapshotResult = await t.oneOrNone(
12669
12970
  `SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`,
12670
12971
  [workflowName, runId]
@@ -12725,7 +13026,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
12725
13026
  }) {
12726
13027
  try {
12727
13028
  return await this.#db.client.tx(async (t) => {
12728
- const tableName = getTableName5({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) });
13029
+ const tableName = getTableName6({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) });
12729
13030
  const existingSnapshotResult = await t.oneOrNone(
12730
13031
  `SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`,
12731
13032
  [workflowName, runId]
@@ -12775,7 +13076,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
12775
13076
  const updatedAtValue = updatedAt ? updatedAt : now;
12776
13077
  const sanitizedSnapshot = sanitizeJsonForPg(JSON.stringify(snapshot));
12777
13078
  await this.#db.client.none(
12778
- `INSERT INTO ${getTableName5({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) })} (workflow_name, run_id, "resourceId", snapshot, "createdAt", "updatedAt")
13079
+ `INSERT INTO ${getTableName6({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })} (workflow_name, run_id, "resourceId", snapshot, "createdAt", "updatedAt")
12779
13080
  VALUES ($1, $2, $3, $4, $5, $6)
12780
13081
  ON CONFLICT (workflow_name, run_id) DO UPDATE
12781
13082
  SET "resourceId" = $3, snapshot = $4, "updatedAt" = $6`,
@@ -12833,7 +13134,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
12833
13134
  }
12834
13135
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
12835
13136
  const query = `
12836
- SELECT * FROM ${getTableName5({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) })}
13137
+ SELECT * FROM ${getTableName6({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })}
12837
13138
  ${whereClause}
12838
13139
  ORDER BY "createdAt" DESC LIMIT 1
12839
13140
  `;
@@ -12861,7 +13162,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
12861
13162
  async deleteWorkflowRunById({ runId, workflowName }) {
12862
13163
  try {
12863
13164
  await this.#db.client.none(
12864
- `DELETE FROM ${getTableName5({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) })} WHERE run_id = $1 AND workflow_name = $2`,
13165
+ `DELETE FROM ${getTableName6({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })} WHERE run_id = $1 AND workflow_name = $2`,
12865
13166
  [runId, workflowName]
12866
13167
  );
12867
13168
  } catch (error) {
@@ -12929,7 +13230,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
12929
13230
  const usePagination = typeof perPage === "number" && typeof page === "number";
12930
13231
  if (usePagination) {
12931
13232
  const countResult = await this.#db.client.one(
12932
- `SELECT COUNT(*) as count FROM ${getTableName5({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) })} ${whereClause}`,
13233
+ `SELECT COUNT(*) as count FROM ${getTableName6({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })} ${whereClause}`,
12933
13234
  values
12934
13235
  );
12935
13236
  total = Number(countResult.count);
@@ -12937,7 +13238,7 @@ var WorkflowsPG = class _WorkflowsPG extends WorkflowsStorage {
12937
13238
  const normalizedPerPage = usePagination ? normalizePerPage(perPage, Number.MAX_SAFE_INTEGER) : 0;
12938
13239
  const offset = usePagination ? page * normalizedPerPage : void 0;
12939
13240
  const query = `
12940
- SELECT * FROM ${getTableName5({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName5(this.#schema) })}
13241
+ SELECT * FROM ${getTableName6({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: getSchemaName6(this.#schema) })}
12941
13242
  ${whereClause}
12942
13243
  ORDER BY "createdAt" DESC
12943
13244
  ${usePagination ? ` LIMIT $${paramIndex} OFFSET $${paramIndex + 1}` : ""}
@@ -13660,7 +13961,8 @@ var ALL_DOMAINS = [
13660
13961
  AgentsPG,
13661
13962
  WorkflowsPG,
13662
13963
  DatasetsPG,
13663
- ExperimentsPG
13964
+ ExperimentsPG,
13965
+ BackgroundTasksPG
13664
13966
  ];
13665
13967
  function exportSchemas(schemaName) {
13666
13968
  const statements = [];
@@ -13714,7 +14016,8 @@ var PostgresStore = class extends MastraCompositeStore {
13714
14016
  skills: new SkillsPG(domainConfig),
13715
14017
  blobs: new BlobsPG(domainConfig),
13716
14018
  datasets: new DatasetsPG(domainConfig),
13717
- experiments: new ExperimentsPG(domainConfig)
14019
+ experiments: new ExperimentsPG(domainConfig),
14020
+ backgroundTasks: new BackgroundTasksPG(domainConfig)
13718
14021
  };
13719
14022
  } catch (e) {
13720
14023
  throw new MastraError(
@@ -13903,6 +14206,6 @@ Example Complex Query:
13903
14206
  ]
13904
14207
  }`;
13905
14208
 
13906
- export { AgentsPG, BlobsPG, DatasetsPG, ExperimentsPG, MCPClientsPG, MCPServersPG, MemoryPG, ObservabilityPG, PGVECTOR_PROMPT, PgVector, PoolAdapter, PostgresStore, PromptBlocksPG, ScorerDefinitionsPG, ScoresPG, SkillsPG, WorkflowsPG, WorkspacesPG, exportSchemas };
14209
+ export { AgentsPG, BackgroundTasksPG, BlobsPG, DatasetsPG, ExperimentsPG, MCPClientsPG, MCPServersPG, MemoryPG, ObservabilityPG, PGVECTOR_PROMPT, PgVector, PoolAdapter, PostgresStore, PromptBlocksPG, ScorerDefinitionsPG, ScoresPG, SkillsPG, WorkflowsPG, WorkspacesPG, exportSchemas };
13907
14210
  //# sourceMappingURL=index.js.map
13908
14211
  //# sourceMappingURL=index.js.map