@voltagent/libsql 2.0.3 → 2.1.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/edge.js CHANGED
@@ -483,8 +483,12 @@ var LibSQLMemoryCore = class {
483
483
  await this.initialize();
484
484
  const messagesTable = `${this.tablePrefix}_messages`;
485
485
  const { limit, before, after, roles } = options || {};
486
- let sql = `SELECT * FROM ${messagesTable}
487
- WHERE conversation_id = ? AND user_id = ?`;
486
+ let sql = `
487
+ SELECT * FROM (
488
+ SELECT *
489
+ FROM ${messagesTable}
490
+ WHERE conversation_id = ? AND user_id = ?
491
+ `;
488
492
  const args = [conversationId, userId];
489
493
  if (roles && roles.length > 0) {
490
494
  const placeholders = roles.map(() => "?").join(",");
@@ -499,11 +503,12 @@ var LibSQLMemoryCore = class {
499
503
  sql += " AND created_at > ?";
500
504
  args.push(after.toISOString());
501
505
  }
502
- sql += " ORDER BY created_at ASC";
506
+ sql += " ORDER BY created_at DESC";
503
507
  if (limit && limit > 0) {
504
508
  sql += " LIMIT ?";
505
509
  args.push(limit);
506
510
  }
511
+ sql += " ) AS subq ORDER BY created_at ASC";
507
512
  const result = await this.client.execute({ sql, args });
508
513
  return result.rows.map((row) => {
509
514
  let parts;