@elizaos/plugin-sql 1.7.0 → 1.7.1-alpha.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/browser/index.browser.js +4 -3
- package/dist/browser/index.browser.js.map +4 -4
- package/dist/browser/tsconfig.build.tsbuildinfo +1 -1
- package/dist/node/index.node.js +131 -125
- package/dist/node/index.node.js.map +6 -6
- package/dist/node/tsconfig.build.node.tsbuildinfo +1 -1
- package/package.json +4 -4
package/dist/node/index.node.js
CHANGED
|
@@ -11661,8 +11661,9 @@ class PgliteDatabaseAdapter extends BaseDrizzleAdapter {
|
|
|
11661
11661
|
}
|
|
11662
11662
|
async withDatabase(operation) {
|
|
11663
11663
|
if (this.manager.isShuttingDown()) {
|
|
11664
|
-
|
|
11665
|
-
|
|
11664
|
+
const error = new Error("Database is shutting down - operation rejected");
|
|
11665
|
+
logger11.warn({ src: "plugin:sql", error: error.message }, "Database operation rejected during shutdown");
|
|
11666
|
+
throw error;
|
|
11666
11667
|
}
|
|
11667
11668
|
return operation();
|
|
11668
11669
|
}
|
|
@@ -11718,6 +11719,110 @@ class PGliteClientManager {
|
|
|
11718
11719
|
|
|
11719
11720
|
// src/pg/adapter.ts
|
|
11720
11721
|
import { logger as logger12 } from "@elizaos/core";
|
|
11722
|
+
class PgDatabaseAdapter extends BaseDrizzleAdapter {
|
|
11723
|
+
embeddingDimension = DIMENSION_MAP[384];
|
|
11724
|
+
manager;
|
|
11725
|
+
constructor(agentId, manager, _schema) {
|
|
11726
|
+
super(agentId);
|
|
11727
|
+
this.manager = manager;
|
|
11728
|
+
this.db = manager.getDatabase();
|
|
11729
|
+
}
|
|
11730
|
+
getManager() {
|
|
11731
|
+
return this.manager;
|
|
11732
|
+
}
|
|
11733
|
+
async withEntityContext(entityId, callback) {
|
|
11734
|
+
return await this.manager.withEntityContext(entityId, callback);
|
|
11735
|
+
}
|
|
11736
|
+
async getEntityByIds(entityIds) {
|
|
11737
|
+
return this.getEntitiesByIds(entityIds);
|
|
11738
|
+
}
|
|
11739
|
+
async getMemoriesByServerId(_params) {
|
|
11740
|
+
logger12.warn({ src: "plugin:sql" }, "getMemoriesByServerId called but not implemented");
|
|
11741
|
+
return [];
|
|
11742
|
+
}
|
|
11743
|
+
async ensureAgentExists(agent) {
|
|
11744
|
+
const existingAgent = await this.getAgent(this.agentId);
|
|
11745
|
+
if (existingAgent) {
|
|
11746
|
+
return existingAgent;
|
|
11747
|
+
}
|
|
11748
|
+
const newAgent = {
|
|
11749
|
+
id: this.agentId,
|
|
11750
|
+
name: agent.name || "Unknown Agent",
|
|
11751
|
+
username: agent.username,
|
|
11752
|
+
bio: agent.bio || "An AI agent",
|
|
11753
|
+
createdAt: agent.createdAt || Date.now(),
|
|
11754
|
+
updatedAt: agent.updatedAt || Date.now()
|
|
11755
|
+
};
|
|
11756
|
+
await this.createAgent(newAgent);
|
|
11757
|
+
const createdAgent = await this.getAgent(this.agentId);
|
|
11758
|
+
if (!createdAgent) {
|
|
11759
|
+
throw new Error("Failed to create agent");
|
|
11760
|
+
}
|
|
11761
|
+
return createdAgent;
|
|
11762
|
+
}
|
|
11763
|
+
async withDatabase(operation) {
|
|
11764
|
+
return await this.withRetry(async () => {
|
|
11765
|
+
return await operation();
|
|
11766
|
+
});
|
|
11767
|
+
}
|
|
11768
|
+
async init() {
|
|
11769
|
+
logger12.debug({ src: "plugin:sql" }, "PgDatabaseAdapter initialized");
|
|
11770
|
+
}
|
|
11771
|
+
async isReady() {
|
|
11772
|
+
return this.manager.testConnection();
|
|
11773
|
+
}
|
|
11774
|
+
async close() {
|
|
11775
|
+
await this.manager.close();
|
|
11776
|
+
}
|
|
11777
|
+
async getConnection() {
|
|
11778
|
+
return this.manager.getConnection();
|
|
11779
|
+
}
|
|
11780
|
+
async createAgent(agent) {
|
|
11781
|
+
return super.createAgent(agent);
|
|
11782
|
+
}
|
|
11783
|
+
getAgent(agentId) {
|
|
11784
|
+
return super.getAgent(agentId);
|
|
11785
|
+
}
|
|
11786
|
+
updateAgent(agentId, agent) {
|
|
11787
|
+
return super.updateAgent(agentId, agent);
|
|
11788
|
+
}
|
|
11789
|
+
deleteAgent(agentId) {
|
|
11790
|
+
return super.deleteAgent(agentId);
|
|
11791
|
+
}
|
|
11792
|
+
createEntities(entities) {
|
|
11793
|
+
return super.createEntities(entities);
|
|
11794
|
+
}
|
|
11795
|
+
getEntitiesByIds(entityIds) {
|
|
11796
|
+
return super.getEntitiesByIds(entityIds).then((result) => result || []);
|
|
11797
|
+
}
|
|
11798
|
+
updateEntity(entity2) {
|
|
11799
|
+
return super.updateEntity(entity2);
|
|
11800
|
+
}
|
|
11801
|
+
createMemory(memory, tableName) {
|
|
11802
|
+
return super.createMemory(memory, tableName);
|
|
11803
|
+
}
|
|
11804
|
+
getMemoryById(memoryId) {
|
|
11805
|
+
return super.getMemoryById(memoryId);
|
|
11806
|
+
}
|
|
11807
|
+
updateMemory(memory) {
|
|
11808
|
+
return super.updateMemory(memory);
|
|
11809
|
+
}
|
|
11810
|
+
deleteMemory(memoryId) {
|
|
11811
|
+
return super.deleteMemory(memoryId);
|
|
11812
|
+
}
|
|
11813
|
+
createComponent(component) {
|
|
11814
|
+
return super.createComponent(component);
|
|
11815
|
+
}
|
|
11816
|
+
getComponent(entityId, type, worldId, sourceEntityId) {
|
|
11817
|
+
return super.getComponent(entityId, type, worldId, sourceEntityId);
|
|
11818
|
+
}
|
|
11819
|
+
updateComponent(component) {
|
|
11820
|
+
return super.updateComponent(component);
|
|
11821
|
+
}
|
|
11822
|
+
deleteComponent(componentId) {
|
|
11823
|
+
return super.deleteComponent(componentId);
|
|
11824
|
+
}
|
|
11825
|
+
}
|
|
11721
11826
|
|
|
11722
11827
|
// ../../node_modules/drizzle-orm/node-postgres/driver.js
|
|
11723
11828
|
init_entity();
|
|
@@ -11741,12 +11846,12 @@ var { Pool, types: types3 } = pg;
|
|
|
11741
11846
|
var NativePool = pg.native ? pg.native.Pool : undefined;
|
|
11742
11847
|
|
|
11743
11848
|
class NodePgPreparedQuery extends PgPreparedQuery {
|
|
11744
|
-
constructor(client, queryString, params,
|
|
11849
|
+
constructor(client, queryString, params, logger13, cache, queryMetadata, cacheConfig, fields, name, _isResponseInArrayMode, customResultMapper) {
|
|
11745
11850
|
super({ sql: queryString, params }, cache, queryMetadata, cacheConfig);
|
|
11746
11851
|
this.client = client;
|
|
11747
11852
|
this.queryString = queryString;
|
|
11748
11853
|
this.params = params;
|
|
11749
|
-
this.logger =
|
|
11854
|
+
this.logger = logger13;
|
|
11750
11855
|
this.fields = fields;
|
|
11751
11856
|
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
11752
11857
|
this.customResultMapper = customResultMapper;
|
|
@@ -11956,11 +12061,11 @@ class NodePgDatabase extends PgDatabase {
|
|
|
11956
12061
|
}
|
|
11957
12062
|
function construct2(client, config = {}) {
|
|
11958
12063
|
const dialect2 = new PgDialect({ casing: config.casing });
|
|
11959
|
-
let
|
|
12064
|
+
let logger13;
|
|
11960
12065
|
if (config.logger === true) {
|
|
11961
|
-
|
|
12066
|
+
logger13 = new DefaultLogger;
|
|
11962
12067
|
} else if (config.logger !== false) {
|
|
11963
|
-
|
|
12068
|
+
logger13 = config.logger;
|
|
11964
12069
|
}
|
|
11965
12070
|
let schema2;
|
|
11966
12071
|
if (config.schema) {
|
|
@@ -11971,7 +12076,7 @@ function construct2(client, config = {}) {
|
|
|
11971
12076
|
tableNamesMap: tablesConfig.tableNamesMap
|
|
11972
12077
|
};
|
|
11973
12078
|
}
|
|
11974
|
-
const driver = new NodePgDriver(client, dialect2, { logger:
|
|
12079
|
+
const driver = new NodePgDriver(client, dialect2, { logger: logger13, cache: config.cache });
|
|
11975
12080
|
const session2 = driver.createSession(schema2);
|
|
11976
12081
|
const db2 = new NodePgDatabase(dialect2, session2, schema2);
|
|
11977
12082
|
db2.$client = client;
|
|
@@ -12006,134 +12111,32 @@ function drizzle2(...params) {
|
|
|
12006
12111
|
drizzle22.mock = mock;
|
|
12007
12112
|
})(drizzle2 || (drizzle2 = {}));
|
|
12008
12113
|
|
|
12009
|
-
// src/pg/adapter.ts
|
|
12010
|
-
class PgDatabaseAdapter extends BaseDrizzleAdapter {
|
|
12011
|
-
embeddingDimension = DIMENSION_MAP[384];
|
|
12012
|
-
manager;
|
|
12013
|
-
constructor(agentId, manager, _schema) {
|
|
12014
|
-
super(agentId);
|
|
12015
|
-
this.manager = manager;
|
|
12016
|
-
this.db = manager.getDatabase();
|
|
12017
|
-
}
|
|
12018
|
-
getManager() {
|
|
12019
|
-
return this.manager;
|
|
12020
|
-
}
|
|
12021
|
-
async withEntityContext(entityId, callback) {
|
|
12022
|
-
return await this.manager.withEntityContext(entityId, callback);
|
|
12023
|
-
}
|
|
12024
|
-
async getEntityByIds(entityIds) {
|
|
12025
|
-
return this.getEntitiesByIds(entityIds);
|
|
12026
|
-
}
|
|
12027
|
-
async getMemoriesByServerId(_params) {
|
|
12028
|
-
logger12.warn({ src: "plugin:sql" }, "getMemoriesByServerId called but not implemented");
|
|
12029
|
-
return [];
|
|
12030
|
-
}
|
|
12031
|
-
async ensureAgentExists(agent) {
|
|
12032
|
-
const existingAgent = await this.getAgent(this.agentId);
|
|
12033
|
-
if (existingAgent) {
|
|
12034
|
-
return existingAgent;
|
|
12035
|
-
}
|
|
12036
|
-
const newAgent = {
|
|
12037
|
-
id: this.agentId,
|
|
12038
|
-
name: agent.name || "Unknown Agent",
|
|
12039
|
-
username: agent.username,
|
|
12040
|
-
bio: agent.bio || "An AI agent",
|
|
12041
|
-
createdAt: agent.createdAt || Date.now(),
|
|
12042
|
-
updatedAt: agent.updatedAt || Date.now()
|
|
12043
|
-
};
|
|
12044
|
-
await this.createAgent(newAgent);
|
|
12045
|
-
const createdAgent = await this.getAgent(this.agentId);
|
|
12046
|
-
if (!createdAgent) {
|
|
12047
|
-
throw new Error("Failed to create agent");
|
|
12048
|
-
}
|
|
12049
|
-
return createdAgent;
|
|
12050
|
-
}
|
|
12051
|
-
async withDatabase(operation) {
|
|
12052
|
-
return await this.withRetry(async () => {
|
|
12053
|
-
const client = await this.manager.getClient();
|
|
12054
|
-
try {
|
|
12055
|
-
const db2 = drizzle2(client);
|
|
12056
|
-
this.db = db2;
|
|
12057
|
-
return await operation();
|
|
12058
|
-
} finally {
|
|
12059
|
-
client.release();
|
|
12060
|
-
}
|
|
12061
|
-
});
|
|
12062
|
-
}
|
|
12063
|
-
async init() {
|
|
12064
|
-
logger12.debug({ src: "plugin:sql" }, "PgDatabaseAdapter initialized");
|
|
12065
|
-
}
|
|
12066
|
-
async isReady() {
|
|
12067
|
-
return this.manager.testConnection();
|
|
12068
|
-
}
|
|
12069
|
-
async close() {
|
|
12070
|
-
await this.manager.close();
|
|
12071
|
-
}
|
|
12072
|
-
async getConnection() {
|
|
12073
|
-
return this.manager.getConnection();
|
|
12074
|
-
}
|
|
12075
|
-
async createAgent(agent) {
|
|
12076
|
-
return super.createAgent(agent);
|
|
12077
|
-
}
|
|
12078
|
-
getAgent(agentId) {
|
|
12079
|
-
return super.getAgent(agentId);
|
|
12080
|
-
}
|
|
12081
|
-
updateAgent(agentId, agent) {
|
|
12082
|
-
return super.updateAgent(agentId, agent);
|
|
12083
|
-
}
|
|
12084
|
-
deleteAgent(agentId) {
|
|
12085
|
-
return super.deleteAgent(agentId);
|
|
12086
|
-
}
|
|
12087
|
-
createEntities(entities) {
|
|
12088
|
-
return super.createEntities(entities);
|
|
12089
|
-
}
|
|
12090
|
-
getEntitiesByIds(entityIds) {
|
|
12091
|
-
return super.getEntitiesByIds(entityIds).then((result) => result || []);
|
|
12092
|
-
}
|
|
12093
|
-
updateEntity(entity2) {
|
|
12094
|
-
return super.updateEntity(entity2);
|
|
12095
|
-
}
|
|
12096
|
-
createMemory(memory, tableName) {
|
|
12097
|
-
return super.createMemory(memory, tableName);
|
|
12098
|
-
}
|
|
12099
|
-
getMemoryById(memoryId) {
|
|
12100
|
-
return super.getMemoryById(memoryId);
|
|
12101
|
-
}
|
|
12102
|
-
updateMemory(memory) {
|
|
12103
|
-
return super.updateMemory(memory);
|
|
12104
|
-
}
|
|
12105
|
-
deleteMemory(memoryId) {
|
|
12106
|
-
return super.deleteMemory(memoryId);
|
|
12107
|
-
}
|
|
12108
|
-
createComponent(component) {
|
|
12109
|
-
return super.createComponent(component);
|
|
12110
|
-
}
|
|
12111
|
-
getComponent(entityId, type, worldId, sourceEntityId) {
|
|
12112
|
-
return super.getComponent(entityId, type, worldId, sourceEntityId);
|
|
12113
|
-
}
|
|
12114
|
-
updateComponent(component) {
|
|
12115
|
-
return super.updateComponent(component);
|
|
12116
|
-
}
|
|
12117
|
-
deleteComponent(componentId) {
|
|
12118
|
-
return super.deleteComponent(componentId);
|
|
12119
|
-
}
|
|
12120
|
-
}
|
|
12121
|
-
|
|
12122
12114
|
// src/pg/manager.ts
|
|
12123
12115
|
init_drizzle_orm();
|
|
12124
12116
|
import { Pool as Pool2 } from "pg";
|
|
12125
|
-
import { logger as logger13 } from "@elizaos/core";
|
|
12117
|
+
import { logger as logger13, validateUuid as validateUuid2 } from "@elizaos/core";
|
|
12126
12118
|
|
|
12127
12119
|
class PostgresConnectionManager {
|
|
12128
12120
|
pool;
|
|
12129
12121
|
db;
|
|
12130
12122
|
constructor(connectionString, rlsServerId) {
|
|
12131
|
-
const poolConfig = {
|
|
12123
|
+
const poolConfig = {
|
|
12124
|
+
connectionString,
|
|
12125
|
+
max: 20,
|
|
12126
|
+
min: 2,
|
|
12127
|
+
idleTimeoutMillis: 30000,
|
|
12128
|
+
connectionTimeoutMillis: 5000,
|
|
12129
|
+
keepAlive: true,
|
|
12130
|
+
keepAliveInitialDelayMillis: 1e4
|
|
12131
|
+
};
|
|
12132
12132
|
if (rlsServerId) {
|
|
12133
12133
|
poolConfig.application_name = rlsServerId;
|
|
12134
12134
|
logger13.debug({ src: "plugin:sql", rlsServerId: rlsServerId.substring(0, 8) }, "Pool configured with RLS server");
|
|
12135
12135
|
}
|
|
12136
12136
|
this.pool = new Pool2(poolConfig);
|
|
12137
|
+
this.pool.on("error", (err) => {
|
|
12138
|
+
logger13.warn({ src: "plugin:sql", error: err?.message || String(err) }, "Pool client error (connection will be replaced)");
|
|
12139
|
+
});
|
|
12137
12140
|
this.db = drizzle2(this.pool, { casing: "snake_case" });
|
|
12138
12141
|
}
|
|
12139
12142
|
getDatabase() {
|
|
@@ -12164,8 +12167,11 @@ class PostgresConnectionManager {
|
|
|
12164
12167
|
const dataIsolationEnabled = process.env.ENABLE_DATA_ISOLATION === "true";
|
|
12165
12168
|
return await this.db.transaction(async (tx) => {
|
|
12166
12169
|
if (dataIsolationEnabled && entityId) {
|
|
12170
|
+
if (!validateUuid2(entityId)) {
|
|
12171
|
+
throw new Error(`Invalid UUID format for entity context: ${entityId}`);
|
|
12172
|
+
}
|
|
12167
12173
|
try {
|
|
12168
|
-
await tx.execute(sql`SET LOCAL app.entity_id = ${entityId}`);
|
|
12174
|
+
await tx.execute(sql.raw(`SET LOCAL app.entity_id = '${entityId}'`));
|
|
12169
12175
|
logger13.debug(`[Entity Context] Set app.entity_id = ${entityId}`);
|
|
12170
12176
|
} catch (error) {
|
|
12171
12177
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -12324,5 +12330,5 @@ export {
|
|
|
12324
12330
|
DatabaseMigrationService
|
|
12325
12331
|
};
|
|
12326
12332
|
|
|
12327
|
-
//# debugId=
|
|
12333
|
+
//# debugId=E1AE4E5A3724400564756E2164756E21
|
|
12328
12334
|
//# sourceMappingURL=index.node.js.map
|