@mastra/pg 1.10.0 → 1.10.1-alpha.1

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
@@ -4289,11 +4289,13 @@ function rowToTask(row) {
4289
4289
  runId: row.run_id,
4290
4290
  result: parseJson(row.result),
4291
4291
  error: parseJson(row.error),
4292
+ suspendPayload: parseJson(row.suspend_payload),
4292
4293
  retryCount: Number(row.retry_count),
4293
4294
  maxRetries: Number(row.max_retries),
4294
4295
  timeoutMs: Number(row.timeout_ms),
4295
4296
  createdAt: row.createdAt instanceof Date ? row.createdAt : new Date(row.createdAt),
4296
4297
  startedAt: row.startedAt ? row.startedAt instanceof Date ? row.startedAt : new Date(row.startedAt) : void 0,
4298
+ suspendedAt: row.suspendedAt ? row.suspendedAt instanceof Date ? row.suspendedAt : new Date(row.suspendedAt) : void 0,
4297
4299
  completedAt: row.completedAt ? row.completedAt instanceof Date ? row.completedAt : new Date(row.completedAt) : void 0
4298
4300
  };
4299
4301
  }
@@ -4316,6 +4318,11 @@ var BackgroundTasksPG = class _BackgroundTasksPG extends BackgroundTasksStorage
4316
4318
  tableName: TABLE_BACKGROUND_TASKS,
4317
4319
  schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS]
4318
4320
  });
4321
+ await this.#db.alterTable({
4322
+ tableName: TABLE_BACKGROUND_TASKS,
4323
+ schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS],
4324
+ ifNotExists: ["suspend_payload", "suspendedAt"]
4325
+ });
4319
4326
  await this.createDefaultIndexes();
4320
4327
  await this.createCustomIndexes();
4321
4328
  }
@@ -4402,11 +4409,13 @@ var BackgroundTasksPG = class _BackgroundTasksPG extends BackgroundTasksStorage
4402
4409
  args: serializeJson(task.args),
4403
4410
  result: serializeJson(task.result),
4404
4411
  error: serializeJson(task.error),
4412
+ suspend_payload: serializeJson(task.suspendPayload),
4405
4413
  retry_count: task.retryCount,
4406
4414
  max_retries: task.maxRetries,
4407
4415
  timeout_ms: task.timeoutMs,
4408
4416
  createdAt: task.createdAt.toISOString(),
4409
4417
  startedAt: task.startedAt?.toISOString() ?? null,
4418
+ suspendedAt: task.suspendedAt?.toISOString() ?? null,
4410
4419
  completedAt: task.completedAt?.toISOString() ?? null
4411
4420
  }
4412
4421
  });
@@ -4427,6 +4436,10 @@ var BackgroundTasksPG = class _BackgroundTasksPG extends BackgroundTasksStorage
4427
4436
  setClauses.push(`"error" = $${paramIdx++}`);
4428
4437
  params.push(serializeJson(update.error));
4429
4438
  }
4439
+ if ("suspendPayload" in update) {
4440
+ setClauses.push(`"suspend_payload" = $${paramIdx++}`);
4441
+ params.push(serializeJson(update.suspendPayload));
4442
+ }
4430
4443
  if ("retryCount" in update) {
4431
4444
  setClauses.push(`"retry_count" = $${paramIdx++}`);
4432
4445
  params.push(update.retryCount);
@@ -4435,6 +4448,10 @@ var BackgroundTasksPG = class _BackgroundTasksPG extends BackgroundTasksStorage
4435
4448
  setClauses.push(`"startedAt" = $${paramIdx++}`);
4436
4449
  params.push(update.startedAt?.toISOString() ?? null);
4437
4450
  }
4451
+ if ("suspendedAt" in update) {
4452
+ setClauses.push(`"suspendedAt" = $${paramIdx++}`);
4453
+ params.push(update.suspendedAt?.toISOString() ?? null);
4454
+ }
4438
4455
  if ("completedAt" in update) {
4439
4456
  setClauses.push(`"completedAt" = $${paramIdx++}`);
4440
4457
  params.push(update.completedAt?.toISOString() ?? null);
@@ -4480,7 +4497,11 @@ var BackgroundTasksPG = class _BackgroundTasksPG extends BackgroundTasksStorage
4480
4497
  conditions.push(`"tool_name" = $${paramIdx++}`);
4481
4498
  params.push(filter.toolName);
4482
4499
  }
4483
- const dateCol = filter.dateFilterBy === "startedAt" ? '"startedAt"' : filter.dateFilterBy === "completedAt" ? '"completedAt"' : '"createdAt"';
4500
+ if (filter.toolCallId) {
4501
+ conditions.push(`"tool_call_id" = $${paramIdx++}`);
4502
+ params.push(filter.toolCallId);
4503
+ }
4504
+ const dateCol = filter.dateFilterBy === "startedAt" ? '"startedAt"' : filter.dateFilterBy === "suspendedAt" ? '"suspendedAt"' : filter.dateFilterBy === "completedAt" ? '"completedAt"' : '"createdAt"';
4484
4505
  if (filter.fromDate) {
4485
4506
  conditions.push(`${dateCol} >= $${paramIdx++}`);
4486
4507
  params.push(filter.fromDate.toISOString());
@@ -4495,7 +4516,7 @@ var BackgroundTasksPG = class _BackgroundTasksPG extends BackgroundTasksStorage
4495
4516
  params.slice(0, paramIdx - 1)
4496
4517
  );
4497
4518
  const total = Number(countResult?.count ?? 0);
4498
- const orderCol = filter.orderBy === "startedAt" ? '"startedAt"' : filter.orderBy === "completedAt" ? '"completedAt"' : '"createdAt"';
4519
+ const orderCol = filter.orderBy === "startedAt" ? '"startedAt"' : filter.orderBy === "suspendedAt" ? '"suspendedAt"' : filter.orderBy === "completedAt" ? '"completedAt"' : '"createdAt"';
4499
4520
  const direction = filter.orderDirection === "desc" ? "DESC" : "ASC";
4500
4521
  let sql = `SELECT * FROM ${table} ${where} ORDER BY ${orderCol} ${direction}`;
4501
4522
  if (filter.perPage != null) {
@@ -4524,7 +4545,7 @@ var BackgroundTasksPG = class _BackgroundTasksPG extends BackgroundTasksStorage
4524
4545
  conditions.push(`"status" IN (${placeholders.join(", ")})`);
4525
4546
  params.push(...statuses);
4526
4547
  }
4527
- const dateCol = filter.dateFilterBy === "startedAt" ? '"startedAt"' : filter.dateFilterBy === "completedAt" ? '"completedAt"' : '"createdAt"';
4548
+ const dateCol = filter.dateFilterBy === "startedAt" ? '"startedAt"' : filter.dateFilterBy === "suspendedAt" ? '"suspendedAt"' : filter.dateFilterBy === "completedAt" ? '"completedAt"' : '"createdAt"';
4528
4549
  if (filter.fromDate) {
4529
4550
  conditions.push(`${dateCol} >= $${paramIdx++}`);
4530
4551
  params.push(filter.fromDate.toISOString());
@@ -7834,12 +7855,21 @@ var MemoryPG = class _MemoryPG extends MemoryStorage {
7834
7855
  resourceId: row.resourceId
7835
7856
  };
7836
7857
  }
7837
- async getThreadById({ threadId }) {
7858
+ async getThreadById({
7859
+ threadId,
7860
+ resourceId
7861
+ }) {
7838
7862
  try {
7839
7863
  const tableName = getTableName4({ indexName: TABLE_THREADS, schemaName: getSchemaName4(this.#schema) });
7864
+ let query = `SELECT * FROM ${tableName} WHERE id = $1`;
7865
+ let params = [threadId];
7866
+ if (resourceId !== void 0) {
7867
+ query += ` AND "resourceId" = $2`;
7868
+ params.push(resourceId);
7869
+ }
7840
7870
  const thread = await this.#db.client.oneOrNone(
7841
- `SELECT * FROM ${tableName} WHERE id = $1`,
7842
- [threadId]
7871
+ query,
7872
+ params
7843
7873
  );
7844
7874
  if (!thread) {
7845
7875
  return null;