@elizaos/plugin-sql 1.0.0-beta.51 → 1.0.0-beta.52

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.
@@ -61,17 +61,26 @@ var PGliteClientManager = class {
61
61
  const timeout = setTimeout(() => {
62
62
  logger.warn("Shutdown timeout reached, forcing database connection closure...");
63
63
  this.client.close().finally(() => {
64
- process.exit(1);
64
+ logger.warn("Forced database connection closure complete.");
65
+ if (process.env.NODE_ENV !== "test") {
66
+ process.exit(1);
67
+ }
65
68
  });
66
69
  }, this.shutdownTimeout);
67
70
  try {
68
71
  await this.client.close();
69
72
  clearTimeout(timeout);
70
73
  logger.info("PGlite client shutdown completed successfully");
71
- process.exit(0);
74
+ if (process.env.NODE_ENV !== "test") {
75
+ process.exit(0);
76
+ }
72
77
  } catch (error) {
73
78
  logger.error("Error during graceful shutdown:", error);
74
- process.exit(1);
79
+ if (process.env.NODE_ENV !== "test") {
80
+ process.exit(1);
81
+ } else {
82
+ throw error;
83
+ }
75
84
  }
76
85
  }
77
86
  /**
@@ -343,4 +352,4 @@ export {
343
352
  PGliteClientManager,
344
353
  PostgresConnectionManager
345
354
  };
346
- //# sourceMappingURL=chunk-EYE2J2N6.js.map
355
+ //# sourceMappingURL=chunk-C7MPSX4Y.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 logger.warn('Forced database connection closure complete.');\n if (process.env.NODE_ENV !== 'test') {\n process.exit(1);\n }\n });\n }, this.shutdownTimeout);\n\n try {\n await this.client.close();\n clearTimeout(timeout);\n logger.info('PGlite client shutdown completed successfully');\n if (process.env.NODE_ENV !== 'test') {\n process.exit(0);\n }\n } catch (error) {\n logger.error('Error during graceful shutdown:', error);\n if (process.env.NODE_ENV !== 'test') {\n process.exit(1);\n } else {\n throw error;\n }\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}\n"],"mappings":";;;;AAAA,SAAS,WAAW,aAAa,WAAW,mBAAmB;AAC/D,SAAS,qBAAqB;AAC9B,SAAS,cAAkC;AAC3C,SAAS,qBAAqB;AAC9B,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,eAAe;AACxB,SAAS,eAAe;AAOjB,IAAM,sBAAN,MAAoE;AAAA,EAd3E,OAc2E;AAAA;AAAA;AAAA,EACjE;AAAA,EACA,eAAe;AAAA,EACN,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOnC,YAAY,SAAwB;AAClC,SAAK,SAAS,IAAI,OAAO;AAAA,MACvB,GAAG;AAAA,MACH,YAAY;AAAA,QACV;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AACD,SAAK,sBAAsB;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,gBAAwB;AAC7B,QAAI,KAAK,cAAc;AACrB,YAAM,IAAI,MAAM,iCAAiC;AAAA,IACnD;AACA,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAc,mBAAmB;AAC/B,QAAI,KAAK,cAAc;AACrB;AAAA,IACF;AAEA,SAAK,eAAe;AACpB,WAAO,KAAK,gDAAgD;AAE5D,UAAM,UAAU,WAAW,MAAM;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c,cAAc;AACpD,YAAM,cAAc,KAAK,QAAQ,eAAe;AAChD,YAAM,iBAAiB,KAAK,QAAQ,aAAa,oBAAoB;AACrE,MAAAF,QAAO,MAAM,4DAA4D,cAAc,EAAE;AAEzF,YAAMG,SAAQ,IAAI;AAAA,QAChB,kBAAkB;AAAA,QAClB,kBAAkB;AAAA,MACpB,CAAC;AAAA,IACH,SAAS,OAAO;AACd,MAAAH,QAAO,MAAM,2CAA2C,KAAK;AAAA,IAC/D;AAAA,EACF;AACF;","names":["fileURLToPath","logger","drizzle","migrate","logger","drizzle","fileURLToPath","migrate"]}
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  PGliteClientManager,
3
3
  PostgresConnectionManager,
4
4
  __name
5
- } from "./chunk-EYE2J2N6.js";
5
+ } from "./chunk-C7MPSX4Y.js";
6
6
 
7
7
  // src/index.ts
8
8
  import * as os from "node:os";
@@ -616,27 +616,42 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
616
616
  */
617
617
  async mergeAgentSettings(tx, agentId, updatedSettings) {
618
618
  const currentAgent = await tx.select({ settings: agentTable.settings }).from(agentTable).where(eq(agentTable.id, agentId)).limit(1);
619
- if (currentAgent.length === 0 || !currentAgent[0].settings) {
620
- return updatedSettings;
621
- }
622
- const currentSettings = currentAgent[0].settings;
623
- if (updatedSettings.secrets) {
624
- const currentSecrets = currentSettings.secrets || {};
625
- const updatedSecrets = updatedSettings.secrets;
626
- const mergedSecrets = { ...currentSecrets };
627
- for (const [key, value] of Object.entries(updatedSecrets)) {
628
- if (value === null) {
629
- delete mergedSecrets[key];
619
+ const currentSettings = currentAgent.length > 0 && currentAgent[0].settings ? currentAgent[0].settings : {};
620
+ const deepMerge = /* @__PURE__ */ __name((target, source) => {
621
+ if (source === null) {
622
+ return void 0;
623
+ }
624
+ if (Array.isArray(source) || typeof source !== "object") {
625
+ return source;
626
+ }
627
+ const output = typeof target === "object" && target !== null && !Array.isArray(target) ? { ...target } : {};
628
+ let isEmpty = true;
629
+ for (const key of Object.keys(source)) {
630
+ const sourceValue = source[key];
631
+ if (sourceValue === null) {
632
+ delete output[key];
633
+ } else if (typeof sourceValue === "object" && !Array.isArray(sourceValue)) {
634
+ const nestedMergeResult = deepMerge(output[key], sourceValue);
635
+ if (nestedMergeResult === void 0) {
636
+ delete output[key];
637
+ } else {
638
+ output[key] = nestedMergeResult;
639
+ isEmpty = false;
640
+ }
630
641
  } else {
631
- mergedSecrets[key] = value;
642
+ output[key] = sourceValue;
643
+ isEmpty = false;
632
644
  }
633
645
  }
634
- updatedSettings.secrets = mergedSecrets;
635
- }
636
- return {
637
- ...currentSettings,
638
- ...updatedSettings
639
- };
646
+ if (Object.keys(output).length === 0) {
647
+ if (!(typeof source === "object" && source !== null && Object.keys(source).length === 0)) {
648
+ return void 0;
649
+ }
650
+ }
651
+ return output;
652
+ }, "deepMerge");
653
+ const finalSettings = deepMerge(currentSettings, updatedSettings);
654
+ return finalSettings === void 0 ? {} : finalSettings;
640
655
  }
641
656
  /**
642
657
  * Asynchronously deletes an agent with the specified UUID and all related entries.
@@ -1193,6 +1208,7 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
1193
1208
  agentId: row.memory.agentId,
1194
1209
  roomId: row.memory.roomId,
1195
1210
  unique: row.memory.unique,
1211
+ metadata: row.memory.metadata,
1196
1212
  embedding: row.embedding ?? void 0
1197
1213
  };
1198
1214
  });
@@ -1708,23 +1724,31 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
1708
1724
  return this.withDatabase(async () => {
1709
1725
  const result = await this.db.select({
1710
1726
  id: roomTable.id,
1727
+ name: roomTable.name,
1728
+ // Added name
1711
1729
  channelId: roomTable.channelId,
1712
1730
  agentId: roomTable.agentId,
1713
1731
  serverId: roomTable.serverId,
1714
1732
  worldId: roomTable.worldId,
1715
1733
  type: roomTable.type,
1716
- source: roomTable.source
1734
+ source: roomTable.source,
1735
+ metadata: roomTable.metadata
1736
+ // Added metadata
1717
1737
  }).from(roomTable).where(and(eq(roomTable.id, roomId), eq(roomTable.agentId, this.agentId))).limit(1);
1718
1738
  if (result.length === 0) return null;
1719
1739
  const room = result[0];
1720
1740
  return {
1721
1741
  ...room,
1722
1742
  id: room.id,
1743
+ name: room.name ?? void 0,
1744
+ // Corrected to handle null
1723
1745
  agentId: room.agentId,
1724
1746
  serverId: room.serverId,
1725
1747
  worldId: room.worldId,
1726
1748
  channelId: room.channelId,
1727
- type: room.type
1749
+ type: room.type,
1750
+ metadata: room.metadata
1751
+ // Added metadata
1728
1752
  };
1729
1753
  });
1730
1754
  }