@elizaos/plugin-sql 1.0.0-beta.4 → 1.0.0-beta.41

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
@@ -7,6 +7,8 @@ import {
7
7
  // src/migrate.ts
8
8
  import { logger } from "@elizaos/core";
9
9
  import { config } from "dotenv";
10
+ import os from "node:os";
11
+ import path from "node:path";
10
12
  config({ path: "../../.env" });
11
13
  async function runMigrations() {
12
14
  if (process.env.POSTGRES_URL) {
@@ -21,9 +23,12 @@ async function runMigrations() {
21
23
  process.exit(1);
22
24
  }
23
25
  } else {
26
+ const homeDir = os.homedir();
27
+ const elizaDir = path.join(homeDir, ".eliza");
28
+ const elizaDbDir = path.join(elizaDir, "db");
24
29
  logger.info("Using PGlite database");
25
30
  const clientManager = new PGliteClientManager({
26
- dataDir: "../../pglite"
31
+ dataDir: elizaDbDir
27
32
  });
28
33
  try {
29
34
  await clientManager.initialize();
@@ -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';\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 logger.info('Using PGlite database');\n const clientManager = new PGliteClientManager({\n dataDir: '../../pglite',\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;AAIvB,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,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;AAnCe;AAqCf,cAAc,EAAE,MAAM,CAAC,UAAU;AAC/B,SAAO,MAAM,kCAAkC,KAAK;AACpD,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
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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> statement-breakpoint
3
- CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;
4
- --> statement-breakpoint
1
+ CREATE EXTENSION IF NOT EXISTS vector;--> statement-breakpoint
2
+ CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;--> statement-breakpoint
3
+
5
4
  CREATE TABLE "agents" (
6
5
  "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
7
6
  "enabled" boolean DEFAULT true NOT NULL,
@@ -83,6 +82,7 @@ CREATE TABLE "memories" (
83
82
  "entityId" uuid,
84
83
  "agentId" uuid,
85
84
  "roomId" uuid,
85
+ "worldId" uuid,
86
86
  "unique" boolean DEFAULT true NOT NULL,
87
87
  "metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,
88
88
  CONSTRAINT "fragment_metadata_check" CHECK (
@@ -173,9 +173,11 @@ ALTER TABLE "logs" ADD CONSTRAINT "fk_user" FOREIGN KEY ("entityId") REFERENCES
173
173
  ALTER TABLE "memories" ADD CONSTRAINT "memories_entityId_entities_id_fk" FOREIGN KEY ("entityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
174
174
  ALTER TABLE "memories" ADD CONSTRAINT "memories_agentId_agents_id_fk" FOREIGN KEY ("agentId") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
175
175
  ALTER TABLE "memories" ADD CONSTRAINT "memories_roomId_rooms_id_fk" FOREIGN KEY ("roomId") REFERENCES "public"."rooms"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
176
+ ALTER TABLE "memories" ADD CONSTRAINT "memories_worldId_worlds_id_fk" FOREIGN KEY ("worldId") REFERENCES "public"."worlds"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
176
177
  ALTER TABLE "memories" ADD CONSTRAINT "fk_room" FOREIGN KEY ("roomId") REFERENCES "public"."rooms"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
177
178
  ALTER TABLE "memories" ADD CONSTRAINT "fk_user" FOREIGN KEY ("entityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
178
- ALTER TABLE "memories" ADD CONSTRAINT "fk_agent" FOREIGN KEY ("agentId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
179
+ ALTER TABLE "memories" ADD CONSTRAINT "fk_agent" FOREIGN KEY ("agentId") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
180
+ ALTER TABLE "memories" ADD CONSTRAINT "fk_world" FOREIGN KEY ("worldId") REFERENCES "public"."worlds"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
179
181
  ALTER TABLE "participants" ADD CONSTRAINT "participants_entityId_entities_id_fk" FOREIGN KEY ("entityId") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
180
182
  ALTER TABLE "participants" ADD CONSTRAINT "participants_roomId_rooms_id_fk" FOREIGN KEY ("roomId") REFERENCES "public"."rooms"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
181
183
  ALTER TABLE "participants" ADD CONSTRAINT "participants_agentId_agents_id_fk" FOREIGN KEY ("agentId") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
@@ -191,6 +193,7 @@ ALTER TABLE "rooms" ADD CONSTRAINT "rooms_worldId_worlds_id_fk" FOREIGN KEY ("wo
191
193
  ALTER TABLE "worlds" ADD CONSTRAINT "worlds_agentId_agents_id_fk" FOREIGN KEY ("agentId") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
192
194
  CREATE INDEX "idx_embedding_memory" ON "embeddings" USING btree ("memory_id");--> statement-breakpoint
193
195
  CREATE INDEX "idx_memories_type_room" ON "memories" USING btree ("type","roomId");--> statement-breakpoint
196
+ CREATE INDEX "idx_memories_world_id" ON "memories" USING btree ("worldId");--> statement-breakpoint
194
197
  CREATE INDEX "idx_memories_metadata_type" ON "memories" USING btree (((metadata->>'type')));--> statement-breakpoint
195
198
  CREATE INDEX "idx_memories_document_id" ON "memories" USING btree (((metadata->>'documentId')));--> statement-breakpoint
196
199
  CREATE INDEX "idx_fragments_order" ON "memories" USING btree (((metadata->>'documentId')),((metadata->>'position')));--> statement-breakpoint
@@ -1,5 +1,5 @@
1
1
  {
2
- "id": "e868cf2d-10a2-406f-a31e-9342a0f29c35",
2
+ "id": "8d7ae0aa-76b7-4e80-9133-db45fb9b6d1e",
3
3
  "prevId": "00000000-0000-0000-0000-000000000000",
4
4
  "version": "7",
5
5
  "dialect": "postgresql",
@@ -20,7 +20,7 @@
20
20
  "type": "boolean",
21
21
  "primaryKey": false,
22
22
  "notNull": true,
23
- "default": "true"
23
+ "default": true
24
24
  },
25
25
  "createdAt": {
26
26
  "name": "createdAt",
@@ -620,6 +620,12 @@
620
620
  "primaryKey": false,
621
621
  "notNull": false
622
622
  },
623
+ "worldId": {
624
+ "name": "worldId",
625
+ "type": "uuid",
626
+ "primaryKey": false,
627
+ "notNull": false
628
+ },
623
629
  "unique": {
624
630
  "name": "unique",
625
631
  "type": "boolean",
@@ -657,6 +663,21 @@
657
663
  "method": "btree",
658
664
  "with": {}
659
665
  },
666
+ "idx_memories_world_id": {
667
+ "name": "idx_memories_world_id",
668
+ "columns": [
669
+ {
670
+ "expression": "worldId",
671
+ "isExpression": false,
672
+ "asc": true,
673
+ "nulls": "last"
674
+ }
675
+ ],
676
+ "isUnique": false,
677
+ "concurrently": false,
678
+ "method": "btree",
679
+ "with": {}
680
+ },
660
681
  "idx_memories_metadata_type": {
661
682
  "name": "idx_memories_metadata_type",
662
683
  "columns": [
@@ -737,6 +758,15 @@
737
758
  "onDelete": "cascade",
738
759
  "onUpdate": "no action"
739
760
  },
761
+ "memories_worldId_worlds_id_fk": {
762
+ "name": "memories_worldId_worlds_id_fk",
763
+ "tableFrom": "memories",
764
+ "tableTo": "worlds",
765
+ "columnsFrom": ["worldId"],
766
+ "columnsTo": ["id"],
767
+ "onDelete": "set null",
768
+ "onUpdate": "no action"
769
+ },
740
770
  "fk_room": {
741
771
  "name": "fk_room",
742
772
  "tableFrom": "memories",
@@ -758,11 +788,20 @@
758
788
  "fk_agent": {
759
789
  "name": "fk_agent",
760
790
  "tableFrom": "memories",
761
- "tableTo": "entities",
791
+ "tableTo": "agents",
762
792
  "columnsFrom": ["agentId"],
763
793
  "columnsTo": ["id"],
764
794
  "onDelete": "cascade",
765
795
  "onUpdate": "no action"
796
+ },
797
+ "fk_world": {
798
+ "name": "fk_world",
799
+ "tableFrom": "memories",
800
+ "tableTo": "worlds",
801
+ "columnsFrom": ["worldId"],
802
+ "columnsTo": ["id"],
803
+ "onDelete": "set null",
804
+ "onUpdate": "no action"
766
805
  }
767
806
  },
768
807
  "compositePrimaryKeys": {},
@@ -5,8 +5,8 @@
5
5
  {
6
6
  "idx": 0,
7
7
  "version": "7",
8
- "when": 1740921883121,
9
- "tag": "20250302132443_init",
8
+ "when": 1745909982134,
9
+ "tag": "0000_low_anita_blake",
10
10
  "breakpoints": true
11
11
  }
12
12
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elizaos/plugin-sql",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.41",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -27,29 +27,36 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "@electric-sql/pglite": "^0.2.17",
30
- "@elizaos/core": "^1.0.0-beta.4",
30
+ "@elizaos/core": "^1.0.0-beta.41",
31
31
  "@types/pg": "8.11.10",
32
32
  "drizzle-kit": "^0.30.4",
33
33
  "drizzle-orm": "^0.39.1",
34
34
  "pg": "^8.13.3"
35
35
  },
36
36
  "devDependencies": {
37
+ "@types/node": "22.8.4",
37
38
  "dockerode": "^4.0.4",
38
39
  "prettier": "3.5.3",
39
- "tsup": "8.4.0"
40
+ "tsup": "8.4.0",
41
+ "vitest": "^1.6.1",
42
+ "zod": "^3.22.4"
40
43
  },
41
44
  "scripts": {
42
45
  "build": "tsup",
43
46
  "dev": "tsup --watch",
44
- "migrate:generate": "drizzle-kit generate:pg",
47
+ "migrate:generate": "drizzle-kit generate",
45
48
  "migrate": "tsup src/migrate.ts --format esm --clean=false --onSuccess=\"node dist/migrate.js\"",
46
49
  "lint": "prettier --write ./src",
47
50
  "clean": "rm -rf dist .turbo node_modules .turbo-tsconfig.json tsconfig.tsbuildinfo",
48
51
  "format": "prettier --write ./src",
49
- "format:check": "prettier --check ./src"
52
+ "format:check": "prettier --check ./src",
53
+ "test": "vitest run",
54
+ "test:watch": "vitest",
55
+ "test:coverage": "vitest run --coverage"
50
56
  },
51
57
  "peerDependencies": {
52
- "typescript": "5.8.2"
58
+ "typescript": "5.8.2",
59
+ "whatwg-url": "7.1.0"
53
60
  },
54
- "gitHead": "55e5f31e3f9920fce14c57f149e185aa128e335b"
61
+ "gitHead": "62132d275b78fa5ae4d604586dffbbaf1be5a4c5"
55
62
  }