Class SqlStorageAdapter

SQL storage adapter implementation for AgentOS.

Provides full persistence for conversations and messages using a SQL database. Wraps @framers/sql-storage-adapter to provide AgentOS-specific schema and operations.

Features:

  • Cross-platform SQL support (SQLite, PostgreSQL, SQL.js, Capacitor)
  • Automatic schema creation and migration
  • Efficient querying with indexes
  • Transaction support for atomic operations
  • Type-safe API with full TypeScript support

Database Schema:

  • conversations table: Stores conversation metadata
  • messages table: Stores individual messages with foreign key to conversations
  • Indexes on frequently queried columns for performance

SqlStorageAdapter

Implements

Example

// Node.js with SQLite
const storage = new SqlStorageAdapter({
type: 'better-sqlite3',
database: './data/agentos.db',
enableWAL: true
});

await storage.initialize();

// Browser with SQL.js
const browserStorage = new SqlStorageAdapter({
type: 'sql.js',
database: 'agentos.db',
enableAutoMigration: true
});

await browserStorage.initialize();

Implements

Constructors

Methods

  • Initializes the storage adapter and creates the database schema.

    Schema created:

    • conversations table with indexes on userId and agentId
    • messages table with indexes on conversationId and timestamp
    • Foreign key constraints for referential integrity

    Must be called before any other operations.

    Returns Promise<void>

    Throws

    If database connection or schema creation fails

    Example

    await storage.initialize();
    console.log('Storage ready!');
  • Lists conversations for a user with optional filtering.

    Parameters

    • userId: string

      User whose conversations to list

    • Optional options: {
          limit?: number;
          offset?: number;
          agentId?: string;
      }

      Query options

      • Optional limit?: number
      • Optional offset?: number
      • Optional agentId?: string

    Returns Promise<IConversation[]>

    Array of conversations