@elizaos/plugin-sql 1.0.0-beta.41 → 1.0.0-beta.43
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/chunk-K7ZVMPCJ.js +2 -0
- package/dist/chunk-K7ZVMPCJ.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +10 -2483
- package/dist/index.js.map +1 -1
- package/dist/migrate.d.ts +2 -0
- package/dist/migrate.js +1 -54
- package/dist/migrate.js.map +1 -1
- package/package.json +6 -15
- package/dist/chunk-ROCRMD5N.js +0 -338
- package/dist/chunk-ROCRMD5N.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var d=Object.defineProperty;var a=(g,t)=>d(g,"name",{value:t,configurable:!0});import{dirname as w,resolve as f}from"node:path";import{fileURLToPath as y}from"node:url";import{PGlite as P}from"@electric-sql/pglite";import{fuzzystrmatch as b}from"@electric-sql/pglite/contrib/fuzzystrmatch";import{vector as v}from"@electric-sql/pglite/vector";import{logger as i}from"@elizaos/core";import{drizzle as S}from"drizzle-orm/pglite";import{migrate as E}from"drizzle-orm/pglite/migrator";var c=class c{constructor(t){this.shuttingDown=!1;this.shutdownTimeout=500;this.client=new P({...t,extensions:{vector:v,fuzzystrmatch:b}}),this.setupShutdownHandlers()}getConnection(){if(this.shuttingDown)throw new Error("Client manager is shutting down");return this.client}async gracefulShutdown(){if(this.shuttingDown)return;this.shuttingDown=!0,i.info("Starting graceful shutdown of PGlite client...");let t=setTimeout(()=>{i.warn("Shutdown timeout reached, forcing database connection closure..."),this.client.close().finally(()=>{process.exit(1)})},this.shutdownTimeout);try{await this.client.close(),clearTimeout(t),i.info("PGlite client shutdown completed successfully"),process.exit(0)}catch(o){i.error("Error during graceful shutdown:",o),process.exit(1)}}setupShutdownHandlers(){process.on("SIGINT",async()=>{await this.gracefulShutdown()}),process.on("SIGTERM",async()=>{await this.gracefulShutdown()}),process.on("beforeExit",async()=>{await this.gracefulShutdown()})}async initialize(){try{await this.client.waitReady,i.info("PGlite client initialized successfully")}catch(t){throw i.error("Failed to initialize PGlite client:",t),t}}async close(){this.shuttingDown||await this.gracefulShutdown()}isShuttingDown(){return this.shuttingDown}async runMigrations(){try{let t=S(this.client),o=await import.meta.resolve("@elizaos/plugin-sql/package.json"),r=y(o),s=w(r),n=f(s,"drizzle/migrations");i.debug(`Resolved migrations path (pglite) using import.meta.resolve: ${n}`),await E(t,{migrationsFolder:n,migrationsSchema:"public"})}catch(t){i.error("Failed to run database migrations (pglite):",t)}}};a(c,"PGliteClientManager");var p=c;import u from"node:path";import{fileURLToPath as z}from"node:url";import{logger as e}from"@elizaos/core";import{drizzle as D}from"drizzle-orm/node-postgres";import{migrate as T}from"drizzle-orm/node-postgres/migrator";import C from"pg";var{Pool:h}=C,l=class l{constructor(t){this.isShuttingDown=!1;this.connectionTimeout=5e3;let o={max:20,idleTimeoutMillis:3e4,connectionTimeoutMillis:this.connectionTimeout};this.pool=new h({...o,connectionString:t}),this.pool.on("error",r=>{e.error("Unexpected pool error",r),this.handlePoolError(r)}),this.setupPoolErrorHandling(),this.testConnection()}async handlePoolError(t){e.error("Pool error occurred, attempting to reconnect",{error:t.message});try{await this.pool.end(),this.pool=new h({...this.pool.options,connectionTimeoutMillis:this.connectionTimeout}),await this.testConnection(),e.success("Pool reconnection successful")}catch(o){throw e.error("Failed to reconnect pool",{error:o instanceof Error?o.message:String(o)}),o}}async testConnection(){let t=null;try{t=await this.pool.connect();let o=await t.query("SELECT NOW()");return e.success("Database connection test successful:",o.rows[0]),!0}catch(o){throw e.error("Database connection test failed:",o),new Error(`Failed to connect to database: ${o.message}`)}finally{t&&t.release()}}setupPoolErrorHandling(){process.on("SIGINT",async()=>{await this.cleanup(),process.exit(0)}),process.on("SIGTERM",async()=>{await this.cleanup(),process.exit(0)}),process.on("beforeExit",async()=>{await this.cleanup()})}getConnection(){if(this.isShuttingDown)throw new Error("Connection manager is shutting down");try{return this.pool}catch(t){throw e.error("Failed to get connection from pool:",t),t}}async getClient(){try{return await this.pool.connect()}catch(t){throw e.error("Failed to acquire a database client:",t),t}}async initialize(){try{await this.testConnection(),e.debug("PostgreSQL connection manager initialized successfully")}catch(t){throw e.error("Failed to initialize connection manager:",t),t}}async close(){await this.cleanup()}async cleanup(){try{await this.pool.end(),e.info("Database pool closed")}catch(t){e.error("Error closing database pool:",t)}}async runMigrations(){try{let t=D(this.pool),o=await import.meta.resolve("@elizaos/plugin-sql/package.json"),r=z(o),s=u.dirname(r),n=u.resolve(s,"drizzle/migrations");e.debug(`Resolved migrations path (pg) using import.meta.resolve: ${n}`),await T(t,{migrationsFolder:n,migrationsSchema:"public"})}catch(t){e.error("Failed to run database migrations (pg):",t)}}};a(l,"PostgresConnectionManager");var m=l;export{a,p as b,m as c};
|
|
2
|
+
//# sourceMappingURL=chunk-K7ZVMPCJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/pglite/manager.ts","../src/pg/manager.ts"],"sourceRoot":"./","sourcesContent":["import { dirname as pathDirname, resolve as pathResolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { PGlite, type PGliteOptions } from '@electric-sql/pglite';\nimport { fuzzystrmatch } from '@electric-sql/pglite/contrib/fuzzystrmatch';\nimport { vector } from '@electric-sql/pglite/vector';\nimport { logger } from '@elizaos/core';\nimport { drizzle } from 'drizzle-orm/pglite';\nimport { migrate } from 'drizzle-orm/pglite/migrator';\nimport type { IDatabaseClientManager } from '../types';\n\n/**\n * Class representing a database client manager for PGlite.\n * @implements { IDatabaseClientManager }\n */\nexport class PGliteClientManager implements IDatabaseClientManager<PGlite> {\n private client: PGlite;\n private shuttingDown = false;\n private readonly shutdownTimeout = 500;\n\n /**\n * Constructor for creating a new instance of PGlite with the provided options.\n * Initializes the PGlite client with additional extensions.\n * @param {PGliteOptions} options - The options to configure the PGlite client.\n */\n constructor(options: PGliteOptions) {\n this.client = new PGlite({\n ...options,\n extensions: {\n vector,\n fuzzystrmatch,\n },\n });\n this.setupShutdownHandlers();\n }\n\n /**\n * Retrieves the PostgreSQL lite connection.\n *\n * @returns {PGlite} The PostgreSQL lite connection.\n * @throws {Error} If the client manager is currently shutting down.\n */\n public getConnection(): PGlite {\n if (this.shuttingDown) {\n throw new Error('Client manager is shutting down');\n }\n return this.client;\n }\n\n /**\n * Initiates a graceful shutdown of the PGlite client.\n * Checks if the client is already in the process of shutting down.\n * Logs the start of shutdown process and sets shuttingDown flag to true.\n * Sets a timeout for the shutdown process and forces closure of database connection if timeout is reached.\n * Handles the shutdown process, closes the client connection, clears the timeout, and logs the completion of shutdown.\n * Logs any errors that occur during the shutdown process.\n */\n private async gracefulShutdown() {\n if (this.shuttingDown) {\n return;\n }\n\n this.shuttingDown = true;\n logger.info('Starting graceful shutdown of PGlite client...');\n\n const timeout = setTimeout(() => {\n logger.warn('Shutdown timeout reached, forcing database connection closure...');\n this.client.close().finally(() => {\n process.exit(1);\n });\n }, this.shutdownTimeout);\n\n try {\n await this.client.close();\n clearTimeout(timeout);\n logger.info('PGlite client shutdown completed successfully');\n process.exit(0);\n } catch (error) {\n logger.error('Error during graceful shutdown:', error);\n process.exit(1);\n }\n }\n\n /**\n * Sets up shutdown handlers for SIGINT, SIGTERM, and beforeExit events to gracefully shutdown the application.\n * @private\n */\n private setupShutdownHandlers() {\n process.on('SIGINT', async () => {\n await this.gracefulShutdown();\n });\n\n process.on('SIGTERM', async () => {\n await this.gracefulShutdown();\n });\n\n process.on('beforeExit', async () => {\n await this.gracefulShutdown();\n });\n }\n\n /**\n * Initializes the client for PGlite.\n *\n * @returns {Promise<void>} A Promise that resolves when the client is initialized successfully\n */\n public async initialize(): Promise<void> {\n try {\n await this.client.waitReady;\n logger.info('PGlite client initialized successfully');\n } catch (error) {\n logger.error('Failed to initialize PGlite client:', error);\n throw error;\n }\n }\n\n /**\n * Asynchronously closes the resource. If the resource is not already shutting down,\n * it performs a graceful shutdown before closing.\n *\n * @returns A promise that resolves once the resource has been closed.\n */\n public async close(): Promise<void> {\n if (!this.shuttingDown) {\n await this.gracefulShutdown();\n }\n }\n\n /**\n * Check if the system is currently shutting down.\n *\n * @returns {boolean} True if the system is shutting down, false otherwise.\n */\n public isShuttingDown(): boolean {\n return this.shuttingDown;\n }\n\n /**\n * Asynchronously runs database migrations using Drizzle.\n *\n * Drizzle will first check if the migrations are already applied.\n * If there is a diff between database schema and migrations, it will apply the migrations.\n * If they are already applied, it will skip them.\n *\n * @returns {Promise<void>} A Promise that resolves once the migrations are completed successfully.\n */\n async runMigrations(): Promise<void> {\n try {\n const db = drizzle(this.client);\n\n const packageJsonUrl = await import.meta.resolve('@elizaos/plugin-sql/package.json');\n const packageJsonPath = fileURLToPath(packageJsonUrl);\n const packageRoot = pathDirname(packageJsonPath);\n const migrationsPath = pathResolve(packageRoot, 'drizzle/migrations');\n logger.debug(\n `Resolved migrations path (pglite) using import.meta.resolve: ${migrationsPath}`\n );\n\n await migrate(db, {\n migrationsFolder: migrationsPath,\n migrationsSchema: 'public',\n });\n } catch (error) {\n logger.error('Failed to run database migrations (pglite):', error);\n }\n }\n}\n","import path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { logger } from '@elizaos/core';\nimport { drizzle } from 'drizzle-orm/node-postgres';\nimport { migrate } from 'drizzle-orm/node-postgres/migrator';\nimport pkg, { type Pool as PgPool } from 'pg';\nimport type { IDatabaseClientManager } from '../types';\n\nconst { Pool } = pkg;\n\n/**\n * Manages connections to a PostgreSQL database using a connection pool.\n * Implements IDatabaseClientManager interface.\n */\n\nexport class PostgresConnectionManager implements IDatabaseClientManager<PgPool> {\n private pool: PgPool;\n private isShuttingDown = false;\n private readonly connectionTimeout: number = 5000;\n\n /**\n * Constructor for creating a connection pool.\n * @param {string} connectionString - The connection string used to connect to the database.\n */\n constructor(connectionString: string) {\n const defaultConfig = {\n max: 20,\n idleTimeoutMillis: 30000,\n connectionTimeoutMillis: this.connectionTimeout,\n };\n\n this.pool = new Pool({\n ...defaultConfig,\n connectionString,\n });\n\n this.pool.on('error', (err) => {\n logger.error('Unexpected pool error', err);\n this.handlePoolError(err);\n });\n\n this.setupPoolErrorHandling();\n this.testConnection();\n }\n\n /**\n * Handles a pool error by attempting to reconnect the pool.\n *\n * @param {Error} error The error that occurred in the pool.\n * @throws {Error} If failed to reconnect the pool.\n */\n private async handlePoolError(error: Error) {\n logger.error('Pool error occurred, attempting to reconnect', {\n error: error.message,\n });\n\n try {\n await this.pool.end();\n\n this.pool = new Pool({\n ...this.pool.options,\n connectionTimeoutMillis: this.connectionTimeout,\n });\n\n await this.testConnection();\n logger.success('Pool reconnection successful');\n } catch (reconnectError) {\n logger.error('Failed to reconnect pool', {\n error: reconnectError instanceof Error ? reconnectError.message : String(reconnectError),\n });\n throw reconnectError;\n }\n }\n\n /**\n * Asynchronously tests the database connection by executing a query to get the current timestamp.\n *\n * @returns {Promise<boolean>} - A Promise that resolves to true if the database connection test is successful.\n */\n async testConnection(): Promise<boolean> {\n let client: pkg.PoolClient | null = null;\n try {\n client = await this.pool.connect();\n const result = await client.query('SELECT NOW()');\n logger.success('Database connection test successful:', result.rows[0]);\n return true;\n } catch (error) {\n logger.error('Database connection test failed:', error);\n throw new Error(`Failed to connect to database: ${(error as Error).message}`);\n } finally {\n if (client) client.release();\n }\n }\n\n /**\n * Sets up event listeners to handle pool cleanup on SIGINT, SIGTERM, and beforeExit events.\n */\n private setupPoolErrorHandling() {\n process.on('SIGINT', async () => {\n await this.cleanup();\n process.exit(0);\n });\n\n process.on('SIGTERM', async () => {\n await this.cleanup();\n process.exit(0);\n });\n\n process.on('beforeExit', async () => {\n await this.cleanup();\n });\n }\n\n /**\n * Get the connection pool.\n * @returns {PgPool} The connection pool\n * @throws {Error} If the connection manager is shutting down or an error occurs when trying to get the connection from the pool\n */\n public getConnection(): PgPool {\n if (this.isShuttingDown) {\n throw new Error('Connection manager is shutting down');\n }\n\n try {\n return this.pool;\n } catch (error) {\n logger.error('Failed to get connection from pool:', error);\n throw error;\n }\n }\n\n /**\n * Asynchronously acquires a database client from the connection pool.\n *\n * @returns {Promise<pkg.PoolClient>} A Promise that resolves with the acquired database client.\n * @throws {Error} If an error occurs while acquiring the database client.\n */\n public async getClient(): Promise<pkg.PoolClient> {\n try {\n return await this.pool.connect();\n } catch (error) {\n logger.error('Failed to acquire a database client:', error);\n throw error;\n }\n }\n\n /**\n * Initializes the PostgreSQL connection manager by testing the connection and logging the result.\n *\n * @returns {Promise<void>} A Promise that resolves once the manager is successfully initialized\n * @throws {Error} If there is an error initializing the connection manager\n */\n public async initialize(): Promise<void> {\n try {\n await this.testConnection();\n logger.debug('PostgreSQL connection manager initialized successfully');\n } catch (error) {\n logger.error('Failed to initialize connection manager:', error);\n throw error;\n }\n }\n\n /**\n * Asynchronously close the current process by executing a cleanup function.\n * @returns A promise that resolves once the cleanup is complete.\n */\n public async close(): Promise<void> {\n await this.cleanup();\n }\n\n /**\n * Cleans up and closes the database pool.\n * @returns {Promise<void>} A Promise that resolves when the database pool is closed.\n */\n async cleanup(): Promise<void> {\n try {\n await this.pool.end();\n logger.info('Database pool closed');\n } catch (error) {\n logger.error('Error closing database pool:', error);\n }\n }\n\n /**\n * Asynchronously runs database migrations using the Drizzle library.\n *\n * Drizzle will first check if the migrations are already applied.\n * If there is a diff between database schema and migrations, it will apply the migrations.\n * If they are already applied, it will skip them.\n *\n * @returns {Promise<void>} A Promise that resolves once the migrations are completed successfully.\n */\n async runMigrations(): Promise<void> {\n try {\n const db = drizzle(this.pool);\n\n const packageJsonUrl = await import.meta.resolve('@elizaos/plugin-sql/package.json');\n const packageJsonPath = fileURLToPath(packageJsonUrl);\n const packageRoot = path.dirname(packageJsonPath);\n const migrationsPath = path.resolve(packageRoot, 'drizzle/migrations');\n logger.debug(`Resolved migrations path (pg) using import.meta.resolve: ${migrationsPath}`);\n\n await migrate(db, {\n migrationsFolder: migrationsPath,\n migrationsSchema: 'public',\n });\n } catch (error) {\n logger.error('Failed to run database migrations (pg):', error);\n }\n }\n}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CAAuCC,CAAK,EACnDA,CACR,CACF,CAQA,MAAa,WAAqC,CAChD,GAAI,CACF,OAAO,MAAM,KAAK,KAAK,QAAQ,CACjC,OAASA,EAAO,CACd,MAAAD,EAAO,MAAM,uCAAwCC,CAAK,EACpDA,CACR,CACF,CAQA,MAAa,YAA4B,CACvC,GAAI,CACF,MAAM,KAAK,eAAe,EAC1BD,EAAO,MAAM,wDAAwD,CACvE,OAASC,EAAO,CACd,MAAAD,EAAO,MAAM,2CAA4CC,CAAK,EACxDA,CACR,CACF,CAMA,MAAa,OAAuB,CAClC,MAAM,KAAK,QAAQ,CACrB,CAMA,MAAM,SAAyB,CAC7B,GAAI,CACF,MAAM,KAAK,KAAK,IAAI,EACpBD,EAAO,KAAK,sBAAsB,CACpC,OAASC,EAAO,CACdD,EAAO,MAAM,+BAAgCC,CAAK,CACpD,CACF,CAWA,MAAM,eAA+B,CACnC,GAAI,CACF,IAAMI,EAAKC,EAAQ,KAAK,IAAI,EAEtBC,EAAiB,MAAM,YAAY,QAAQ,kCAAkC,EAC7EC,EAAkBC,EAAcF,CAAc,EAC9CG,EAAcC,EAAK,QAAQH,CAAe,EAC1CI,EAAiBD,EAAK,QAAQD,EAAa,oBAAoB,EACrEV,EAAO,MAAM,4DAA4DY,CAAc,EAAE,EAEzF,MAAMC,EAAQR,EAAI,CAChB,iBAAkBO,EAClB,iBAAkB,QACpB,CAAC,CACH,OAASX,EAAO,CACdD,EAAO,MAAM,0CAA2CC,CAAK,CAC/D,CACF,CACF,EAnMiFa,EAAAlB,EAAA,6BAA1E,IAAMmB,EAANnB","names":["pathDirname","pathResolve","fileURLToPath","PGlite","fuzzystrmatch","vector","logger","drizzle","migrate","_PGliteClientManager","options","PGlite","vector","fuzzystrmatch","logger","timeout","error","db","drizzle","packageJsonUrl","packageJsonPath","fileURLToPath","packageRoot","pathDirname","migrationsPath","pathResolve","migrate","__name","PGliteClientManager","path","fileURLToPath","logger","drizzle","migrate","pkg","Pool","pkg","_PostgresConnectionManager","connectionString","defaultConfig","err","logger","error","reconnectError","client","result","db","drizzle","packageJsonUrl","packageJsonPath","fileURLToPath","packageRoot","path","migrationsPath","migrate","__name","PostgresConnectionManager"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Plugin, UUID, IDatabaseAdapter } from '@elizaos/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a database adapter based on the provided configuration.
|
|
5
|
+
* If a postgresUrl is provided in the config, a PgDatabaseAdapter is initialized using the PostgresConnectionManager.
|
|
6
|
+
* If no postgresUrl is provided, a PgliteDatabaseAdapter is initialized using PGliteClientManager with the dataDir from the config.
|
|
7
|
+
*
|
|
8
|
+
* @param {object} config - The configuration object.
|
|
9
|
+
* @param {string} [config.dataDir] - The directory where data is stored. Defaults to "./elizadb".
|
|
10
|
+
* @param {string} [config.postgresUrl] - The URL for the PostgreSQL database.
|
|
11
|
+
* @param {UUID} agentId - The unique identifier for the agent.
|
|
12
|
+
* @returns {IDatabaseAdapter} The created database adapter.
|
|
13
|
+
*/
|
|
14
|
+
declare function createDatabaseAdapter(config: {
|
|
15
|
+
dataDir?: string;
|
|
16
|
+
postgresUrl?: string;
|
|
17
|
+
}, agentId: UUID): IDatabaseAdapter;
|
|
18
|
+
/**
|
|
19
|
+
* SQL plugin for database adapter using Drizzle ORM
|
|
20
|
+
*
|
|
21
|
+
* @typedef {Object} Plugin
|
|
22
|
+
* @property {string} name - The name of the plugin
|
|
23
|
+
* @property {string} description - The description of the plugin
|
|
24
|
+
* @property {Function} init - The initialization function for the plugin
|
|
25
|
+
* @param {any} _ - Input parameter
|
|
26
|
+
* @param {IAgentRuntime} runtime - The runtime environment for the agent
|
|
27
|
+
*/
|
|
28
|
+
declare const sqlPlugin: Plugin;
|
|
29
|
+
|
|
30
|
+
export { createDatabaseAdapter, sqlPlugin as default };
|