@elizaos/plugin-sql 1.0.9 → 1.0.10

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/index.d.ts CHANGED
@@ -2357,7 +2357,7 @@ declare const serverAgentsTable: drizzle_orm_pg_core.PgTableWithColumns<{
2357
2357
  name: "server_id";
2358
2358
  tableName: "server_agents";
2359
2359
  dataType: "string";
2360
- columnType: "PgText";
2360
+ columnType: "PgUUID";
2361
2361
  data: string;
2362
2362
  driverParam: string;
2363
2363
  notNull: true;
@@ -2365,7 +2365,7 @@ declare const serverAgentsTable: drizzle_orm_pg_core.PgTableWithColumns<{
2365
2365
  isPrimaryKey: false;
2366
2366
  isAutoincrement: false;
2367
2367
  hasRuntimeDefault: false;
2368
- enumValues: [string, ...string[]];
2368
+ enumValues: undefined;
2369
2369
  baseColumn: never;
2370
2370
  identity: undefined;
2371
2371
  generated: undefined;
@@ -2374,7 +2374,7 @@ declare const serverAgentsTable: drizzle_orm_pg_core.PgTableWithColumns<{
2374
2374
  name: "agent_id";
2375
2375
  tableName: "server_agents";
2376
2376
  dataType: "string";
2377
- columnType: "PgText";
2377
+ columnType: "PgUUID";
2378
2378
  data: string;
2379
2379
  driverParam: string;
2380
2380
  notNull: true;
@@ -2382,7 +2382,7 @@ declare const serverAgentsTable: drizzle_orm_pg_core.PgTableWithColumns<{
2382
2382
  isPrimaryKey: false;
2383
2383
  isAutoincrement: false;
2384
2384
  hasRuntimeDefault: false;
2385
- enumValues: [string, ...string[]];
2385
+ enumValues: undefined;
2386
2386
  baseColumn: never;
2387
2387
  identity: undefined;
2388
2388
  generated: undefined;
package/dist/index.js CHANGED
@@ -219,7 +219,7 @@ var embeddingTable = pgTable5(
219
219
  "embeddings",
220
220
  {
221
221
  id: uuid5("id").primaryKey().defaultRandom().notNull(),
222
- memoryId: uuid5("memory_id").references(() => memoryTable.id),
222
+ memoryId: uuid5("memory_id").references(() => memoryTable.id, { onDelete: "cascade" }),
223
223
  createdAt: timestamp5("created_at").default(sql5`now()`).notNull(),
224
224
  dim384: vector2("dim_384", { dimensions: VECTOR_DIMS.SMALL }),
225
225
  dim512: vector2("dim_512", { dimensions: VECTOR_DIMS.MEDIUM }),
@@ -318,7 +318,7 @@ var logTable = pgTable9(
318
318
  {
319
319
  id: uuid9("id").defaultRandom().notNull(),
320
320
  createdAt: timestamp9("created_at", { withTimezone: true }).default(sql9`now()`).notNull(),
321
- entityId: uuid9("entityId").notNull().references(() => entityTable.id),
321
+ entityId: uuid9("entityId").notNull().references(() => entityTable.id, { onDelete: "cascade" }),
322
322
  body: jsonb8("body").notNull(),
323
323
  type: text8("type").notNull(),
324
324
  roomId: uuid9("roomId").notNull().references(() => roomTable.id, { onDelete: "cascade" })
@@ -422,7 +422,7 @@ var taskTable = pgTable12("tasks", {
422
422
  roomId: uuid12("roomId"),
423
423
  worldId: uuid12("worldId"),
424
424
  entityId: uuid12("entityId"),
425
- agentId: uuid12("agent_id").notNull(),
425
+ agentId: uuid12("agent_id").notNull().references(() => agentTable.id, { onDelete: "cascade" }),
426
426
  tags: text11("tags").array().default(sql12`'{}'::text[]`),
427
427
  metadata: jsonb10("metadata").default(sql12`'{}'::jsonb`),
428
428
  createdAt: timestamp12("created_at", { withTimezone: true }).defaultNow(),
@@ -496,13 +496,12 @@ var channelParticipantsTable = pgTable16(
496
496
  );
497
497
 
498
498
  // src/schema/serverAgent.ts
499
- import { pgTable as pgTable17, text as text16, primaryKey as primaryKey3 } from "drizzle-orm/pg-core";
499
+ import { pgTable as pgTable17, uuid as uuid13, primaryKey as primaryKey3 } from "drizzle-orm/pg-core";
500
500
  var serverAgentsTable = pgTable17(
501
501
  "server_agents",
502
502
  {
503
- serverId: text16("server_id").notNull().references(() => messageServerTable.id, { onDelete: "cascade" }),
504
- agentId: text16("agent_id").notNull()
505
- // This is the agent's UUID
503
+ serverId: uuid13("server_id").notNull().references(() => messageServerTable.id, { onDelete: "cascade" }),
504
+ agentId: uuid13("agent_id").notNull().references(() => agentTable.id, { onDelete: "cascade" })
506
505
  },
507
506
  (table) => ({
508
507
  pk: primaryKey3({ columns: [table.serverId, table.agentId] })
@@ -582,12 +581,10 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
582
581
  */
583
582
  async ensureEmbeddingDimension(dimension) {
584
583
  return this.withDatabase(async () => {
585
- const existingMemory = await this.db.select({
586
- embedding: embeddingTable
587
- }).from(memoryTable).innerJoin(embeddingTable, eq(embeddingTable.memoryId, memoryTable.id)).where(eq(memoryTable.agentId, this.agentId)).limit(1);
584
+ const existingMemory = await this.db.select().from(memoryTable).innerJoin(embeddingTable, eq(embeddingTable.memoryId, memoryTable.id)).where(eq(memoryTable.agentId, this.agentId)).limit(1);
588
585
  if (existingMemory.length > 0) {
589
586
  const usedDimension = Object.entries(DIMENSION_MAP).find(
590
- ([_, colName]) => existingMemory[0].embedding[colName] !== null
587
+ ([_, colName]) => existingMemory[0].embeddings[colName] !== null
591
588
  );
592
589
  }
593
590
  this.embeddingDimension = DIMENSION_MAP[dimension];
@@ -782,158 +779,23 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
782
779
  * @returns {Promise<boolean>} - A boolean indicating if the deletion was successful.
783
780
  */
784
781
  async deleteAgent(agentId) {
785
- logger.debug(`[DB] Starting deletion of agent with ID: ${agentId}`);
782
+ logger.debug(`[DB] Deleting agent with ID: ${agentId}`);
786
783
  return this.withDatabase(async () => {
787
784
  try {
788
- logger.debug(`[DB] Beginning database transaction for deleting agent: ${agentId}`);
789
- const deletePromise = new Promise((resolve, reject) => {
790
- const timeoutId = setTimeout(() => {
791
- logger.error(`[DB] Transaction timeout reached for agent deletion: ${agentId}`);
792
- reject(new Error("Database transaction timeout"));
793
- }, 3e4);
794
- this.db.transaction(async (tx) => {
795
- try {
796
- logger.debug(`[DB] Fetching entities for agent: ${agentId}`);
797
- const entities = await tx.select({ entityId: entityTable.id }).from(entityTable).where(eq(entityTable.agentId, agentId));
798
- const entityIds = entities.map((e) => e.entityId);
799
- logger.debug(
800
- `[DB] Found ${entityIds.length} entities to delete for agent ${agentId}`
801
- );
802
- logger.debug(`[DB] Fetching rooms for agent: ${agentId}`);
803
- const rooms = await tx.select({ roomId: roomTable.id }).from(roomTable).where(eq(roomTable.agentId, agentId));
804
- const roomIds = rooms.map((r) => r.roomId);
805
- logger.debug(`[DB] Found ${roomIds.length} rooms for agent ${agentId}`);
806
- logger.debug(
807
- `[DB] Explicitly deleting ALL logs with matching entityIds and roomIds`
808
- );
809
- if (entityIds.length > 0) {
810
- logger.debug(`[DB] Deleting logs for ${entityIds.length} entities (first batch)`);
811
- const BATCH_SIZE = 50;
812
- for (let i = 0; i < entityIds.length; i += BATCH_SIZE) {
813
- const batch = entityIds.slice(i, i + BATCH_SIZE);
814
- logger.debug(
815
- `[DB] Processing entity logs batch ${i / BATCH_SIZE + 1} with ${batch.length} entities`
816
- );
817
- await tx.delete(logTable).where(inArray(logTable.entityId, batch));
818
- }
819
- logger.debug(`[DB] Entity logs deletion completed successfully`);
820
- }
821
- if (roomIds.length > 0) {
822
- logger.debug(`[DB] Deleting logs for ${roomIds.length} rooms (first batch)`);
823
- const BATCH_SIZE = 50;
824
- for (let i = 0; i < roomIds.length; i += BATCH_SIZE) {
825
- const batch = roomIds.slice(i, i + BATCH_SIZE);
826
- logger.debug(
827
- `[DB] Processing room logs batch ${i / BATCH_SIZE + 1} with ${batch.length} rooms`
828
- );
829
- await tx.delete(logTable).where(inArray(logTable.roomId, batch));
830
- }
831
- logger.debug(`[DB] Room logs deletion completed successfully`);
832
- }
833
- let memoryIds = [];
834
- if (entityIds.length > 0) {
835
- logger.debug(`[DB] Finding memories belonging to entities`);
836
- const memories = await tx.select({ id: memoryTable.id }).from(memoryTable).where(inArray(memoryTable.entityId, entityIds));
837
- memoryIds = memories.map((m) => m.id);
838
- logger.debug(`[DB] Found ${memoryIds.length} memories belonging to entities`);
839
- }
840
- logger.debug(`[DB] Finding memories belonging to agent directly`);
841
- const agentMemories = await tx.select({ id: memoryTable.id }).from(memoryTable).where(eq(memoryTable.agentId, agentId));
842
- memoryIds = [...memoryIds, ...agentMemories.map((m) => m.id)];
843
- logger.debug(`[DB] Found total of ${memoryIds.length} memories to delete`);
844
- if (roomIds.length > 0) {
845
- logger.debug(`[DB] Finding memories belonging to rooms`);
846
- const roomMemories = await tx.select({ id: memoryTable.id }).from(memoryTable).where(inArray(memoryTable.roomId, roomIds));
847
- memoryIds = [...memoryIds, ...roomMemories.map((m) => m.id)];
848
- logger.debug(`[DB] Updated total to ${memoryIds.length} memories to delete`);
849
- }
850
- if (memoryIds.length > 0) {
851
- logger.debug(`[DB] Deleting embeddings for ${memoryIds.length} memories`);
852
- const BATCH_SIZE = 100;
853
- for (let i = 0; i < memoryIds.length; i += BATCH_SIZE) {
854
- const batch = memoryIds.slice(i, i + BATCH_SIZE);
855
- await tx.delete(embeddingTable).where(inArray(embeddingTable.memoryId, batch));
856
- }
857
- logger.debug(`[DB] Embeddings deleted successfully`);
858
- }
859
- if (memoryIds.length > 0) {
860
- logger.debug(`[DB] Deleting ${memoryIds.length} memories`);
861
- const BATCH_SIZE = 100;
862
- for (let i = 0; i < memoryIds.length; i += BATCH_SIZE) {
863
- const batch = memoryIds.slice(i, i + BATCH_SIZE);
864
- await tx.delete(memoryTable).where(inArray(memoryTable.id, batch));
865
- }
866
- logger.debug(`[DB] Memories deleted successfully`);
867
- }
868
- if (entityIds.length > 0) {
869
- logger.debug(`[DB] Deleting components for entities`);
870
- await tx.delete(componentTable).where(inArray(componentTable.entityId, entityIds));
871
- logger.debug(`[DB] Components deleted successfully`);
872
- }
873
- if (entityIds.length > 0) {
874
- logger.debug(`[DB] Deleting source entity references in components`);
875
- await tx.delete(componentTable).where(inArray(componentTable.sourceEntityId, entityIds));
876
- logger.debug(`[DB] Source entity references deleted successfully`);
877
- }
878
- if (roomIds.length > 0) {
879
- logger.debug(`[DB] Deleting participations for rooms`);
880
- await tx.delete(participantTable).where(inArray(participantTable.roomId, roomIds));
881
- logger.debug(`[DB] Participations deleted for rooms`);
882
- }
883
- logger.debug(`[DB] Deleting agent participations`);
884
- await tx.delete(participantTable).where(eq(participantTable.agentId, agentId));
885
- logger.debug(`[DB] Agent participations deleted`);
886
- if (roomIds.length > 0) {
887
- logger.debug(`[DB] Deleting rooms`);
888
- await tx.delete(roomTable).where(inArray(roomTable.id, roomIds));
889
- logger.debug(`[DB] Rooms deleted successfully`);
890
- }
891
- logger.debug(`[DB] Deleting cache entries`);
892
- await tx.delete(cacheTable).where(eq(cacheTable.agentId, agentId));
893
- logger.debug(`[DB] Cache entries deleted successfully`);
894
- logger.debug(`[DB] Deleting relationships`);
895
- if (entityIds.length > 0) {
896
- await tx.delete(relationshipTable).where(inArray(relationshipTable.sourceEntityId, entityIds));
897
- await tx.delete(relationshipTable).where(inArray(relationshipTable.targetEntityId, entityIds));
898
- }
899
- await tx.delete(relationshipTable).where(eq(relationshipTable.agentId, agentId));
900
- logger.debug(`[DB] Relationships deleted successfully`);
901
- if (entityIds.length > 0) {
902
- logger.debug(`[DB] Deleting entities`);
903
- await tx.delete(entityTable).where(eq(entityTable.agentId, agentId));
904
- logger.debug(`[DB] Entities deleted successfully`);
905
- }
906
- logger.debug(`[DB] Checking for world references`);
907
- const worlds = await tx.select({ id: worldTable.id }).from(worldTable).where(eq(worldTable.agentId, agentId));
908
- if (worlds.length > 0) {
909
- const worldIds = worlds.map((w) => w.id);
910
- logger.debug(`[DB] Found ${worldIds.length} worlds to delete`);
911
- await tx.delete(worldTable).where(inArray(worldTable.id, worldIds));
912
- logger.debug(`[DB] Worlds deleted successfully`);
913
- } else {
914
- logger.debug(`[DB] No worlds found for this agent`);
915
- }
916
- logger.debug(`[DB] Deleting agent ${agentId}`);
917
- await tx.delete(agentTable).where(eq(agentTable.id, agentId));
918
- logger.debug(`[DB] Agent deleted successfully`);
919
- resolve(true);
920
- } catch (error) {
921
- logger.error(`[DB] Error in transaction:`, error);
922
- reject(error);
923
- }
924
- }).catch((transactionError) => {
925
- clearTimeout(timeoutId);
926
- reject(transactionError);
927
- });
928
- });
929
- await deletePromise;
930
- logger.success(`[DB] Agent ${agentId} successfully deleted`);
785
+ const result = await this.db.delete(agentTable).where(eq(agentTable.id, agentId)).returning();
786
+ if (result.length === 0) {
787
+ logger.warn(`[DB] Agent ${agentId} not found`);
788
+ return false;
789
+ }
790
+ logger.success(
791
+ `[DB] Agent ${agentId} and all related data successfully deleted via cascade`
792
+ );
931
793
  return true;
932
794
  } catch (error) {
933
- logger.error(`[DB] Error in database transaction for agent deletion ${agentId}:`, error);
795
+ logger.error(`[DB] Failed to delete agent ${agentId}:`, error);
934
796
  if (error instanceof Error) {
935
- logger.error(`[DB] Error name: ${error.name}, message: ${error.message}`);
936
- logger.error(`[DB] Error stack: ${error.stack}`);
797
+ logger.error(`[DB] Error details: ${error.name} - ${error.message}`);
798
+ logger.error(`[DB] Stack trace: ${error.stack}`);
937
799
  }
938
800
  throw error;
939
801
  }
@@ -1107,8 +969,89 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
1107
969
  * @returns {Promise<void>} A Promise that resolves when the entity is updated.
1108
970
  */
1109
971
  async updateEntity(entity) {
972
+ if (!entity.id) {
973
+ throw new Error("Entity ID is required for update");
974
+ }
975
+ return this.withDatabase(async () => {
976
+ await this.db.update(entityTable).set(entity).where(eq(entityTable.id, entity.id));
977
+ });
978
+ }
979
+ /**
980
+ * Asynchronously deletes an entity from the database based on the provided ID.
981
+ * @param {UUID} entityId - The ID of the entity to delete.
982
+ * @returns {Promise<void>} A Promise that resolves when the entity is deleted.
983
+ */
984
+ async deleteEntity(entityId) {
985
+ return this.withDatabase(async () => {
986
+ await this.db.transaction(async (tx) => {
987
+ await tx.delete(componentTable).where(
988
+ or(eq(componentTable.entityId, entityId), eq(componentTable.sourceEntityId, entityId))
989
+ );
990
+ await tx.delete(entityTable).where(eq(entityTable.id, entityId));
991
+ });
992
+ });
993
+ }
994
+ /**
995
+ * Asynchronously retrieves entities by their names and agentId.
996
+ * @param {Object} params - The parameters for retrieving entities.
997
+ * @param {string[]} params.names - The names to search for.
998
+ * @param {UUID} params.agentId - The agent ID to filter by.
999
+ * @returns {Promise<Entity[]>} A Promise that resolves to an array of entities.
1000
+ */
1001
+ async getEntitiesByNames(params) {
1002
+ return this.withDatabase(async () => {
1003
+ const { names, agentId } = params;
1004
+ const nameConditions = names.map((name) => sql16`${name} = ANY(${entityTable.names})`);
1005
+ const query = sql16`
1006
+ SELECT * FROM ${entityTable}
1007
+ WHERE ${entityTable.agentId} = ${agentId}
1008
+ AND (${sql16.join(nameConditions, sql16` OR `)})
1009
+ `;
1010
+ const result = await this.db.execute(query);
1011
+ return result.rows.map((row) => ({
1012
+ id: row.id,
1013
+ agentId: row.agentId,
1014
+ names: row.names || [],
1015
+ metadata: row.metadata || {}
1016
+ }));
1017
+ });
1018
+ }
1019
+ /**
1020
+ * Asynchronously searches for entities by name with fuzzy matching.
1021
+ * @param {Object} params - The parameters for searching entities.
1022
+ * @param {string} params.query - The search query.
1023
+ * @param {UUID} params.agentId - The agent ID to filter by.
1024
+ * @param {number} params.limit - The maximum number of results to return.
1025
+ * @returns {Promise<Entity[]>} A Promise that resolves to an array of entities.
1026
+ */
1027
+ async searchEntitiesByName(params) {
1110
1028
  return this.withDatabase(async () => {
1111
- await this.db.update(entityTable).set(entity).where(and(eq(entityTable.id, entity.id), eq(entityTable.agentId, entity.agentId)));
1029
+ const { query, agentId, limit = 10 } = params;
1030
+ if (!query || query.trim() === "") {
1031
+ const result2 = await this.db.select().from(entityTable).where(eq(entityTable.agentId, agentId)).limit(limit);
1032
+ return result2.map((row) => ({
1033
+ id: row.id,
1034
+ agentId: row.agentId,
1035
+ names: row.names || [],
1036
+ metadata: row.metadata || {}
1037
+ }));
1038
+ }
1039
+ const searchQuery = sql16`
1040
+ SELECT * FROM ${entityTable}
1041
+ WHERE ${entityTable.agentId} = ${agentId}
1042
+ AND EXISTS (
1043
+ SELECT 1 FROM unnest(${entityTable.names}) AS name
1044
+ WHERE LOWER(name) LIKE LOWER(${"%" + query + "%"})
1045
+ )
1046
+ LIMIT ${limit}
1047
+ `;
1048
+ const result = await this.db.execute(searchQuery);
1049
+ return result.rows.map((row) => ({
1050
+ id: row.id,
1051
+ agentId: row.agentId,
1052
+ names: row.names || [],
1053
+ metadata: row.metadata || {}
1054
+ }));
1112
1055
  });
1113
1056
  }
1114
1057
  async getComponent(entityId, type, worldId, sourceEntityId) {
@@ -1484,7 +1427,7 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
1484
1427
  * @param value - The value to sanitize
1485
1428
  * @returns The sanitized value
1486
1429
  */
1487
- sanitizeJsonObject(value) {
1430
+ sanitizeJsonObject(value, seen = /* @__PURE__ */ new WeakSet()) {
1488
1431
  if (value === null || value === void 0) {
1489
1432
  return value;
1490
1433
  }
@@ -1492,13 +1435,18 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
1492
1435
  return value.replace(/\u0000/g, "").replace(/\\(?!["\\/bfnrtu])/g, "\\\\").replace(/\\u(?![0-9a-fA-F]{4})/g, "\\\\u");
1493
1436
  }
1494
1437
  if (typeof value === "object") {
1438
+ if (seen.has(value)) {
1439
+ return null;
1440
+ } else {
1441
+ seen.add(value);
1442
+ }
1495
1443
  if (Array.isArray(value)) {
1496
- return value.map((item) => this.sanitizeJsonObject(item));
1444
+ return value.map((item) => this.sanitizeJsonObject(item, seen));
1497
1445
  } else {
1498
1446
  const result = {};
1499
1447
  for (const [key, val] of Object.entries(value)) {
1500
1448
  const sanitizedKey = typeof key === "string" ? key.replace(/\u0000/g, "").replace(/\\u(?![0-9a-fA-F]{4})/g, "\\\\u") : key;
1501
- result[sanitizedKey] = this.sanitizeJsonObject(val);
1449
+ result[sanitizedKey] = this.sanitizeJsonObject(val, seen);
1502
1450
  }
1503
1451
  return result;
1504
1452
  }
@@ -3044,16 +2992,16 @@ var PGliteClientManager = class {
3044
2992
  import { logger as logger3 } from "@elizaos/core";
3045
2993
  import { drizzle as drizzle2 } from "drizzle-orm/node-postgres";
3046
2994
  var PgDatabaseAdapter = class extends BaseDrizzleAdapter {
3047
- constructor(agentId, manager) {
3048
- super(agentId);
3049
- this.manager = manager;
3050
- this.manager = manager;
3051
- this.db = this.manager.getDatabase();
3052
- }
3053
2995
  static {
3054
2996
  __name(this, "PgDatabaseAdapter");
3055
2997
  }
3056
2998
  embeddingDimension = DIMENSION_MAP[384];
2999
+ manager;
3000
+ constructor(agentId, manager, schema) {
3001
+ super(agentId);
3002
+ this.manager = manager;
3003
+ this.db = manager.getDatabase();
3004
+ }
3057
3005
  /**
3058
3006
  * Runs database migrations. For PostgreSQL, migrations should be handled
3059
3007
  * externally or during deployment, so this is a no-op.
@@ -3113,12 +3061,60 @@ var PgDatabaseAdapter = class extends BaseDrizzleAdapter {
3113
3061
  async getConnection() {
3114
3062
  return this.manager.getConnection();
3115
3063
  }
3064
+ async createAgent(agent) {
3065
+ return super.createAgent(agent);
3066
+ }
3067
+ getAgent(agentId) {
3068
+ return super.getAgent(agentId);
3069
+ }
3070
+ updateAgent(agentId, agent) {
3071
+ return super.updateAgent(agentId, agent);
3072
+ }
3073
+ deleteAgent(agentId) {
3074
+ return super.deleteAgent(agentId);
3075
+ }
3076
+ createEntities(entities) {
3077
+ return super.createEntities(entities);
3078
+ }
3079
+ getEntityByIds(entityIds) {
3080
+ return super.getEntityByIds(entityIds).then((result) => result || []);
3081
+ }
3082
+ updateEntity(entity) {
3083
+ return super.updateEntity(entity);
3084
+ }
3085
+ createMemory(memory, tableName) {
3086
+ return super.createMemory(memory, tableName);
3087
+ }
3088
+ getMemoryById(memoryId) {
3089
+ return super.getMemoryById(memoryId);
3090
+ }
3091
+ searchMemories(params) {
3092
+ return super.searchMemories(params);
3093
+ }
3094
+ updateMemory(memory) {
3095
+ return super.updateMemory(memory);
3096
+ }
3097
+ deleteMemory(memoryId) {
3098
+ return super.deleteMemory(memoryId);
3099
+ }
3100
+ createComponent(component) {
3101
+ return super.createComponent(component);
3102
+ }
3103
+ getComponent(entityId, type, worldId, sourceEntityId) {
3104
+ return super.getComponent(entityId, type, worldId, sourceEntityId);
3105
+ }
3106
+ updateComponent(component) {
3107
+ return super.updateComponent(component);
3108
+ }
3109
+ deleteComponent(componentId) {
3110
+ return super.deleteComponent(componentId);
3111
+ }
3116
3112
  };
3117
3113
 
3118
3114
  // src/pg/manager.ts
3115
+ import { drizzle as drizzle3 } from "drizzle-orm/node-postgres";
3119
3116
  import { Pool } from "pg";
3120
3117
  import { logger as logger4 } from "@elizaos/core";
3121
- import { drizzle as drizzle3 } from "drizzle-orm/node-postgres";
3122
3118
  var PostgresConnectionManager = class {
3123
3119
  static {
3124
3120
  __name(this, "PostgresConnectionManager");
@@ -3139,16 +3135,25 @@ var PostgresConnectionManager = class {
3139
3135
  return this.pool.connect();
3140
3136
  }
3141
3137
  async testConnection() {
3138
+ let client = null;
3142
3139
  try {
3143
- const client = await this.pool.connect();
3140
+ client = await this.pool.connect();
3144
3141
  await client.query("SELECT 1");
3145
- client.release();
3146
3142
  return true;
3147
3143
  } catch (error) {
3148
3144
  logger4.error("Failed to connect to the database:", error);
3149
3145
  return false;
3146
+ } finally {
3147
+ if (client) {
3148
+ client.release();
3149
+ }
3150
3150
  }
3151
3151
  }
3152
+ /**
3153
+ * Closes the connection pool.
3154
+ * @returns {Promise<void>}
3155
+ * @memberof PostgresConnectionManager
3156
+ */
3152
3157
  async close() {
3153
3158
  await this.pool.end();
3154
3159
  }
@@ -3991,17 +3996,15 @@ var ExtensionManager = class {
3991
3996
  static {
3992
3997
  __name(this, "ExtensionManager");
3993
3998
  }
3994
- async installRequiredExtensions() {
3995
- if (this.db?.driver?.constructor?.name === "PGlite") {
3996
- logger5.debug("[CUSTOM MIGRATOR] PGLite detected, skipping extension creation via SQL.");
3997
- return;
3998
- }
3999
- const extensions = ["vector", "fuzzystrmatch"];
4000
- for (const extension of extensions) {
3999
+ async installRequiredExtensions(requiredExtensions) {
4000
+ for (const extension of requiredExtensions) {
4001
4001
  try {
4002
4002
  await this.db.execute(sql17.raw(`CREATE EXTENSION IF NOT EXISTS "${extension}"`));
4003
- } catch (e) {
4004
- logger5.warn(`Could not install extension ${extension}:`, e);
4003
+ } catch (error) {
4004
+ logger5.warn(`Could not install extension ${extension}:`, {
4005
+ message: error.message,
4006
+ stack: error.stack
4007
+ });
4005
4008
  }
4006
4009
  }
4007
4010
  }
@@ -4043,7 +4046,7 @@ async function runPluginMigrations(db, pluginName, schema) {
4043
4046
  const namespaceManager = new PluginNamespaceManager(db);
4044
4047
  const introspector = new DrizzleSchemaIntrospector();
4045
4048
  const extensionManager = new ExtensionManager(db);
4046
- await extensionManager.installRequiredExtensions();
4049
+ await extensionManager.installRequiredExtensions(["vector", "fuzzystrmatch"]);
4047
4050
  const schemaName = await namespaceManager.getPluginSchema(pluginName);
4048
4051
  await namespaceManager.ensureNamespace(schemaName);
4049
4052
  const existingTables = await namespaceManager.introspectExistingTables(schemaName);