@voltagent/libsql 2.0.2 → 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.mjs CHANGED
@@ -454,8 +454,12 @@ var LibSQLMemoryCore = class {
454
454
  await this.initialize();
455
455
  const messagesTable = `${this.tablePrefix}_messages`;
456
456
  const { limit, before, after, roles } = options || {};
457
- let sql = `SELECT * FROM ${messagesTable}
458
- WHERE conversation_id = ? AND user_id = ?`;
457
+ let sql = `
458
+ SELECT * FROM (
459
+ SELECT *
460
+ FROM ${messagesTable}
461
+ WHERE conversation_id = ? AND user_id = ?
462
+ `;
459
463
  const args = [conversationId, userId];
460
464
  if (roles && roles.length > 0) {
461
465
  const placeholders = roles.map(() => "?").join(",");
@@ -470,11 +474,12 @@ var LibSQLMemoryCore = class {
470
474
  sql += " AND created_at > ?";
471
475
  args.push(after.toISOString());
472
476
  }
473
- sql += " ORDER BY created_at ASC";
477
+ sql += " ORDER BY created_at DESC";
474
478
  if (limit && limit > 0) {
475
479
  sql += " LIMIT ?";
476
480
  args.push(limit);
477
481
  }
482
+ sql += " ) AS subq ORDER BY created_at ASC";
478
483
  const result = await this.client.execute({ sql, args });
479
484
  return result.rows.map((row) => {
480
485
  let parts;
@@ -588,6 +593,19 @@ var LibSQLMemoryCore = class {
588
593
  });
589
594
  }
590
595
  }
596
+ async deleteMessages(messageIds, userId, conversationId) {
597
+ await this.initialize();
598
+ if (messageIds.length === 0) {
599
+ return;
600
+ }
601
+ const messagesTable = `${this.tablePrefix}_messages`;
602
+ const placeholders = messageIds.map(() => "?").join(",");
603
+ const sql = `DELETE FROM ${messagesTable} WHERE conversation_id = ? AND user_id = ? AND message_id IN (${placeholders})`;
604
+ await this.client.execute({
605
+ sql,
606
+ args: [conversationId, userId, ...messageIds]
607
+ });
608
+ }
591
609
  // ============================================================================
592
610
  // Conversation Operations
593
611
  // ============================================================================
@@ -700,6 +718,23 @@ var LibSQLMemoryCore = class {
700
718
  updatedAt: row.updated_at
701
719
  }));
702
720
  }
721
+ async countConversations(options) {
722
+ await this.initialize();
723
+ const conversationsTable = `${this.tablePrefix}_conversations`;
724
+ let sql = `SELECT COUNT(*) as count FROM ${conversationsTable} WHERE 1=1`;
725
+ const args = [];
726
+ if (options.userId) {
727
+ sql += " AND user_id = ?";
728
+ args.push(options.userId);
729
+ }
730
+ if (options.resourceId) {
731
+ sql += " AND resource_id = ?";
732
+ args.push(options.resourceId);
733
+ }
734
+ const result = await this.client.execute({ sql, args });
735
+ const count = Number(result.rows[0]?.count ?? 0);
736
+ return Number.isNaN(count) ? 0 : count;
737
+ }
703
738
  async updateConversation(id, updates) {
704
739
  await this.initialize();
705
740
  const conversationsTable = `${this.tablePrefix}_conversations`;