@elizaos/plugin-sql 1.0.0-beta.44 → 1.0.0-beta.46

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/migrate.js CHANGED
@@ -1,2 +1,55 @@
1
- import{a as o,b as t,c as a}from"./chunk-K7ZVMPCJ.js";import{logger as r}from"@elizaos/core";import{config as g}from"dotenv";import p from"node:os";import n from"node:path";g({path:"../../.env"});async function f(){if(process.env.POSTGRES_URL)try{let i=new a(process.env.POSTGRES_URL);await i.initialize(),await i.runMigrations(),r.success("PostgreSQL migrations completed successfully"),process.exit(0)}catch(i){r.warn("PostgreSQL migration failed:",i),process.exit(1)}else{let i=p.homedir(),s=n.join(i,".eliza"),c=n.join(s,"db");r.info("Using PGlite database");let e=new t({dataDir:c});try{await e.initialize(),await e.runMigrations(),r.success("PGlite migrations completed successfully"),await e.close(),process.exit(0)}catch(l){r.error("PGlite migration failed:",l);try{await e.close()}catch(m){r.error("Failed to close PGlite connection:",m)}process.exit(1)}}}o(f,"runMigrations");f().catch(i=>{r.error("Unhandled error in migrations:",i),process.exit(1)});
1
+ import {
2
+ PGliteClientManager,
3
+ PostgresConnectionManager,
4
+ __name
5
+ } from "./chunk-EYE2J2N6.js";
6
+
7
+ // src/migrate.ts
8
+ import { logger } from "@elizaos/core";
9
+ import { config } from "dotenv";
10
+ import os from "node:os";
11
+ import path from "node:path";
12
+ config({ path: "../../.env" });
13
+ async function runMigrations() {
14
+ if (process.env.POSTGRES_URL) {
15
+ try {
16
+ const connectionManager = new PostgresConnectionManager(process.env.POSTGRES_URL);
17
+ await connectionManager.initialize();
18
+ await connectionManager.runMigrations();
19
+ logger.success("PostgreSQL migrations completed successfully");
20
+ process.exit(0);
21
+ } catch (error) {
22
+ logger.warn("PostgreSQL migration failed:", error);
23
+ process.exit(1);
24
+ }
25
+ } else {
26
+ const homeDir = os.homedir();
27
+ const elizaDir = path.join(homeDir, ".eliza");
28
+ const elizaDbDir = path.join(elizaDir, "db");
29
+ logger.info("Using PGlite database");
30
+ const clientManager = new PGliteClientManager({
31
+ dataDir: elizaDbDir
32
+ });
33
+ try {
34
+ await clientManager.initialize();
35
+ await clientManager.runMigrations();
36
+ logger.success("PGlite migrations completed successfully");
37
+ await clientManager.close();
38
+ process.exit(0);
39
+ } catch (error) {
40
+ logger.error("PGlite migration failed:", error);
41
+ try {
42
+ await clientManager.close();
43
+ } catch (closeError) {
44
+ logger.error("Failed to close PGlite connection:", closeError);
45
+ }
46
+ process.exit(1);
47
+ }
48
+ }
49
+ }
50
+ __name(runMigrations, "runMigrations");
51
+ runMigrations().catch((error) => {
52
+ logger.error("Unhandled error in migrations:", error);
53
+ process.exit(1);
54
+ });
2
55
  //# sourceMappingURL=migrate.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/migrate.ts"],"sourceRoot":"./","sourcesContent":["import { logger } from '@elizaos/core';\nimport { config } from 'dotenv';\nimport { PGliteClientManager } from './pglite/manager.js';\nimport { PostgresConnectionManager } from './pg/manager.js';\nimport os from 'node:os';\nimport path from 'node:path';\n\nconfig({ path: '../../.env' });\n\n/**\n * Runs the database migrations based on the environment variable POSTGRES_URL.\n * If the POSTGRES_URL is provided, it indicates the use of a PostgreSQL database and the corresponding migration logic needs to be implemented.\n * If POSTGRES_URL is not provided, it uses a PGlite database and runs the migrations on it.\n * @returns {Promise<void>} A promise that resolves once the migrations are completed successfully or rejects if an error occurs.\n */\nasync function runMigrations() {\n if (process.env.POSTGRES_URL) {\n try {\n const connectionManager = new PostgresConnectionManager(process.env.POSTGRES_URL);\n await connectionManager.initialize();\n await connectionManager.runMigrations();\n // await connectionManager.close();\n logger.success('PostgreSQL migrations completed successfully');\n process.exit(0);\n } catch (error) {\n logger.warn('PostgreSQL migration failed:', error);\n process.exit(1);\n }\n } else {\n const homeDir = os.homedir();\n const elizaDir = path.join(homeDir, '.eliza');\n const elizaDbDir = path.join(elizaDir, 'db');\n\n logger.info('Using PGlite database');\n const clientManager = new PGliteClientManager({\n dataDir: elizaDbDir,\n });\n\n try {\n await clientManager.initialize();\n await clientManager.runMigrations();\n logger.success('PGlite migrations completed successfully');\n await clientManager.close();\n process.exit(0);\n } catch (error) {\n logger.error('PGlite migration failed:', error);\n try {\n await clientManager.close();\n } catch (closeError) {\n logger.error('Failed to close PGlite connection:', closeError);\n }\n process.exit(1);\n }\n }\n}\n\nrunMigrations().catch((error) => {\n logger.error('Unhandled error in migrations:', error);\n process.exit(1);\n});\n"],"mappings":"sDAAA,OAAS,UAAAA,MAAc,gBACvB,OAAS,UAAAC,MAAc,SAGvB,OAAOC,MAAQ,UACf,OAAOC,MAAU,YAEjBC,EAAO,CAAE,KAAM,YAAa,CAAC,EAQ7B,eAAeC,GAAgB,CAC7B,GAAI,QAAQ,IAAI,aACd,GAAI,CACF,IAAMC,EAAoB,IAAIC,EAA0B,QAAQ,IAAI,YAAY,EAChF,MAAMD,EAAkB,WAAW,EACnC,MAAMA,EAAkB,cAAc,EAEtCE,EAAO,QAAQ,8CAA8C,EAC7D,QAAQ,KAAK,CAAC,CAChB,OAASC,EAAO,CACdD,EAAO,KAAK,+BAAgCC,CAAK,EACjD,QAAQ,KAAK,CAAC,CAChB,KACK,CACL,IAAMC,EAAUC,EAAG,QAAQ,EACrBC,EAAWC,EAAK,KAAKH,EAAS,QAAQ,EACtCI,EAAaD,EAAK,KAAKD,EAAU,IAAI,EAE3CJ,EAAO,KAAK,uBAAuB,EACnC,IAAMO,EAAgB,IAAIC,EAAoB,CAC5C,QAASF,CACX,CAAC,EAED,GAAI,CACF,MAAMC,EAAc,WAAW,EAC/B,MAAMA,EAAc,cAAc,EAClCP,EAAO,QAAQ,0CAA0C,EACzD,MAAMO,EAAc,MAAM,EAC1B,QAAQ,KAAK,CAAC,CAChB,OAASN,EAAO,CACdD,EAAO,MAAM,2BAA4BC,CAAK,EAC9C,GAAI,CACF,MAAMM,EAAc,MAAM,CAC5B,OAASE,EAAY,CACnBT,EAAO,MAAM,qCAAsCS,CAAU,CAC/D,CACA,QAAQ,KAAK,CAAC,CAChB,CACF,CACF,CAvCeC,EAAAb,EAAA,iBAyCfA,EAAc,EAAE,MAAOI,GAAU,CAC/BD,EAAO,MAAM,iCAAkCC,CAAK,EACpD,QAAQ,KAAK,CAAC,CAChB,CAAC","names":["logger","config","os","path","config","runMigrations","connectionManager","PostgresConnectionManager","logger","error","homeDir","os","elizaDir","path","elizaDbDir","clientManager","PGliteClientManager","closeError","__name"]}
1
+ {"version":3,"sources":["../src/migrate.ts"],"sourceRoot":"./","sourcesContent":["import { logger } from '@elizaos/core';\nimport { config } from 'dotenv';\nimport { PGliteClientManager } from './pglite/manager.js';\nimport { PostgresConnectionManager } from './pg/manager.js';\nimport os from 'node:os';\nimport path from 'node:path';\n\nconfig({ path: '../../.env' });\n\n/**\n * Runs the database migrations based on the environment variable POSTGRES_URL.\n * If the POSTGRES_URL is provided, it indicates the use of a PostgreSQL database and the corresponding migration logic needs to be implemented.\n * If POSTGRES_URL is not provided, it uses a PGlite database and runs the migrations on it.\n * @returns {Promise<void>} A promise that resolves once the migrations are completed successfully or rejects if an error occurs.\n */\nasync function runMigrations() {\n if (process.env.POSTGRES_URL) {\n try {\n const connectionManager = new PostgresConnectionManager(process.env.POSTGRES_URL);\n await connectionManager.initialize();\n await connectionManager.runMigrations();\n // await connectionManager.close();\n logger.success('PostgreSQL migrations completed successfully');\n process.exit(0);\n } catch (error) {\n logger.warn('PostgreSQL migration failed:', error);\n process.exit(1);\n }\n } else {\n const homeDir = os.homedir();\n const elizaDir = path.join(homeDir, '.eliza');\n const elizaDbDir = path.join(elizaDir, 'db');\n\n logger.info('Using PGlite database');\n const clientManager = new PGliteClientManager({\n dataDir: elizaDbDir,\n });\n\n try {\n await clientManager.initialize();\n await clientManager.runMigrations();\n logger.success('PGlite migrations completed successfully');\n await clientManager.close();\n process.exit(0);\n } catch (error) {\n logger.error('PGlite migration failed:', error);\n try {\n await clientManager.close();\n } catch (closeError) {\n logger.error('Failed to close PGlite connection:', closeError);\n }\n process.exit(1);\n }\n }\n}\n\nrunMigrations().catch((error) => {\n logger.error('Unhandled error in migrations:', error);\n process.exit(1);\n});\n"],"mappings":";;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,cAAc;AAGvB,OAAO,QAAQ;AACf,OAAO,UAAU;AAEjB,OAAO,EAAE,MAAM,aAAa,CAAC;AAQ7B,eAAe,gBAAgB;AAC7B,MAAI,QAAQ,IAAI,cAAc;AAC5B,QAAI;AACF,YAAM,oBAAoB,IAAI,0BAA0B,QAAQ,IAAI,YAAY;AAChF,YAAM,kBAAkB,WAAW;AACnC,YAAM,kBAAkB,cAAc;AAEtC,aAAO,QAAQ,8CAA8C;AAC7D,cAAQ,KAAK,CAAC;AAAA,IAChB,SAAS,OAAO;AACd,aAAO,KAAK,gCAAgC,KAAK;AACjD,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF,OAAO;AACL,UAAM,UAAU,GAAG,QAAQ;AAC3B,UAAM,WAAW,KAAK,KAAK,SAAS,QAAQ;AAC5C,UAAM,aAAa,KAAK,KAAK,UAAU,IAAI;AAE3C,WAAO,KAAK,uBAAuB;AACnC,UAAM,gBAAgB,IAAI,oBAAoB;AAAA,MAC5C,SAAS;AAAA,IACX,CAAC;AAED,QAAI;AACF,YAAM,cAAc,WAAW;AAC/B,YAAM,cAAc,cAAc;AAClC,aAAO,QAAQ,0CAA0C;AACzD,YAAM,cAAc,MAAM;AAC1B,cAAQ,KAAK,CAAC;AAAA,IAChB,SAAS,OAAO;AACd,aAAO,MAAM,4BAA4B,KAAK;AAC9C,UAAI;AACF,cAAM,cAAc,MAAM;AAAA,MAC5B,SAAS,YAAY;AACnB,eAAO,MAAM,sCAAsC,UAAU;AAAA,MAC/D;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AACF;AAvCe;AAyCf,cAAc,EAAE,MAAM,CAAC,UAAU;AAC/B,SAAO,MAAM,kCAAkC,KAAK;AACpD,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@elizaos/plugin-sql",
3
- "version": "1.0.0-beta.44",
3
+ "version": "1.0.0-beta.46",
4
4
  "type": "module",
5
- "main": "./dist/index.js",
6
- "module": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/elizaos-plugins/plugin-sql"
@@ -12,13 +12,22 @@
12
12
  "publishConfig": {
13
13
  "access": "public"
14
14
  },
15
+ "exports": {
16
+ "./package.json": "./package.json",
17
+ ".": {
18
+ "import": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ }
22
+ }
23
+ },
15
24
  "files": [
16
25
  "dist",
17
26
  "drizzle"
18
27
  ],
19
28
  "dependencies": {
20
29
  "@electric-sql/pglite": "^0.2.17",
21
- "@elizaos/core": "^1.0.0-beta.44",
30
+ "@elizaos/core": "^1.0.0-beta.46",
22
31
  "@types/pg": "8.11.10",
23
32
  "drizzle-kit": "^0.30.4",
24
33
  "drizzle-orm": "^0.39.1",
@@ -49,5 +58,5 @@
49
58
  "typescript": "5.8.2",
50
59
  "whatwg-url": "7.1.0"
51
60
  },
52
- "gitHead": "be0fcf2621f3d11009085d19b1501a911a089ecd"
61
+ "gitHead": "f21720cb14c0da8cf0047721be78d4cd0d83947e"
53
62
  }
@@ -1,2 +0,0 @@
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
package/dist/index.d.ts DELETED
@@ -1,30 +0,0 @@
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 };
package/dist/migrate.d.ts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { }