@elizaos/plugin-sql 1.7.1-alpha.6 → 1.7.1-alpha.7
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 +3 -3
- package/dist/browser/tsconfig.build.tsbuildinfo +1 -1
- package/dist/node/index.node.js +130 -124
- package/dist/node/index.node.js.map +5 -5
- 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();
|
|
@@ -11740,12 +11845,12 @@ init_utils();
|
|
|
11740
11845
|
var { Pool, types: types3 } = pg;
|
|
11741
11846
|
|
|
11742
11847
|
class NodePgPreparedQuery extends PgPreparedQuery {
|
|
11743
|
-
constructor(client, queryString, params,
|
|
11848
|
+
constructor(client, queryString, params, logger13, cache, queryMetadata, cacheConfig, fields, name, _isResponseInArrayMode, customResultMapper) {
|
|
11744
11849
|
super({ sql: queryString, params }, cache, queryMetadata, cacheConfig);
|
|
11745
11850
|
this.client = client;
|
|
11746
11851
|
this.queryString = queryString;
|
|
11747
11852
|
this.params = params;
|
|
11748
|
-
this.logger =
|
|
11853
|
+
this.logger = logger13;
|
|
11749
11854
|
this.fields = fields;
|
|
11750
11855
|
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
11751
11856
|
this.customResultMapper = customResultMapper;
|
|
@@ -11955,11 +12060,11 @@ class NodePgDatabase extends PgDatabase {
|
|
|
11955
12060
|
}
|
|
11956
12061
|
function construct2(client, config = {}) {
|
|
11957
12062
|
const dialect2 = new PgDialect({ casing: config.casing });
|
|
11958
|
-
let
|
|
12063
|
+
let logger13;
|
|
11959
12064
|
if (config.logger === true) {
|
|
11960
|
-
|
|
12065
|
+
logger13 = new DefaultLogger;
|
|
11961
12066
|
} else if (config.logger !== false) {
|
|
11962
|
-
|
|
12067
|
+
logger13 = config.logger;
|
|
11963
12068
|
}
|
|
11964
12069
|
let schema2;
|
|
11965
12070
|
if (config.schema) {
|
|
@@ -11970,7 +12075,7 @@ function construct2(client, config = {}) {
|
|
|
11970
12075
|
tableNamesMap: tablesConfig.tableNamesMap
|
|
11971
12076
|
};
|
|
11972
12077
|
}
|
|
11973
|
-
const driver = new NodePgDriver(client, dialect2, { logger:
|
|
12078
|
+
const driver = new NodePgDriver(client, dialect2, { logger: logger13, cache: config.cache });
|
|
11974
12079
|
const session2 = driver.createSession(schema2);
|
|
11975
12080
|
const db2 = new NodePgDatabase(dialect2, session2, schema2);
|
|
11976
12081
|
db2.$client = client;
|
|
@@ -12005,134 +12110,32 @@ function drizzle2(...params) {
|
|
|
12005
12110
|
drizzle22.mock = mock;
|
|
12006
12111
|
})(drizzle2 || (drizzle2 = {}));
|
|
12007
12112
|
|
|
12008
|
-
// src/pg/adapter.ts
|
|
12009
|
-
class PgDatabaseAdapter extends BaseDrizzleAdapter {
|
|
12010
|
-
embeddingDimension = DIMENSION_MAP[384];
|
|
12011
|
-
manager;
|
|
12012
|
-
constructor(agentId, manager, _schema) {
|
|
12013
|
-
super(agentId);
|
|
12014
|
-
this.manager = manager;
|
|
12015
|
-
this.db = manager.getDatabase();
|
|
12016
|
-
}
|
|
12017
|
-
getManager() {
|
|
12018
|
-
return this.manager;
|
|
12019
|
-
}
|
|
12020
|
-
async withEntityContext(entityId, callback) {
|
|
12021
|
-
return await this.manager.withEntityContext(entityId, callback);
|
|
12022
|
-
}
|
|
12023
|
-
async getEntityByIds(entityIds) {
|
|
12024
|
-
return this.getEntitiesByIds(entityIds);
|
|
12025
|
-
}
|
|
12026
|
-
async getMemoriesByServerId(_params) {
|
|
12027
|
-
logger12.warn({ src: "plugin:sql" }, "getMemoriesByServerId called but not implemented");
|
|
12028
|
-
return [];
|
|
12029
|
-
}
|
|
12030
|
-
async ensureAgentExists(agent) {
|
|
12031
|
-
const existingAgent = await this.getAgent(this.agentId);
|
|
12032
|
-
if (existingAgent) {
|
|
12033
|
-
return existingAgent;
|
|
12034
|
-
}
|
|
12035
|
-
const newAgent = {
|
|
12036
|
-
id: this.agentId,
|
|
12037
|
-
name: agent.name || "Unknown Agent",
|
|
12038
|
-
username: agent.username,
|
|
12039
|
-
bio: agent.bio || "An AI agent",
|
|
12040
|
-
createdAt: agent.createdAt || Date.now(),
|
|
12041
|
-
updatedAt: agent.updatedAt || Date.now()
|
|
12042
|
-
};
|
|
12043
|
-
await this.createAgent(newAgent);
|
|
12044
|
-
const createdAgent = await this.getAgent(this.agentId);
|
|
12045
|
-
if (!createdAgent) {
|
|
12046
|
-
throw new Error("Failed to create agent");
|
|
12047
|
-
}
|
|
12048
|
-
return createdAgent;
|
|
12049
|
-
}
|
|
12050
|
-
async withDatabase(operation) {
|
|
12051
|
-
return await this.withRetry(async () => {
|
|
12052
|
-
const client = await this.manager.getClient();
|
|
12053
|
-
try {
|
|
12054
|
-
const db2 = drizzle2(client);
|
|
12055
|
-
this.db = db2;
|
|
12056
|
-
return await operation();
|
|
12057
|
-
} finally {
|
|
12058
|
-
client.release();
|
|
12059
|
-
}
|
|
12060
|
-
});
|
|
12061
|
-
}
|
|
12062
|
-
async init() {
|
|
12063
|
-
logger12.debug({ src: "plugin:sql" }, "PgDatabaseAdapter initialized");
|
|
12064
|
-
}
|
|
12065
|
-
async isReady() {
|
|
12066
|
-
return this.manager.testConnection();
|
|
12067
|
-
}
|
|
12068
|
-
async close() {
|
|
12069
|
-
await this.manager.close();
|
|
12070
|
-
}
|
|
12071
|
-
async getConnection() {
|
|
12072
|
-
return this.manager.getConnection();
|
|
12073
|
-
}
|
|
12074
|
-
async createAgent(agent) {
|
|
12075
|
-
return super.createAgent(agent);
|
|
12076
|
-
}
|
|
12077
|
-
getAgent(agentId) {
|
|
12078
|
-
return super.getAgent(agentId);
|
|
12079
|
-
}
|
|
12080
|
-
updateAgent(agentId, agent) {
|
|
12081
|
-
return super.updateAgent(agentId, agent);
|
|
12082
|
-
}
|
|
12083
|
-
deleteAgent(agentId) {
|
|
12084
|
-
return super.deleteAgent(agentId);
|
|
12085
|
-
}
|
|
12086
|
-
createEntities(entities) {
|
|
12087
|
-
return super.createEntities(entities);
|
|
12088
|
-
}
|
|
12089
|
-
getEntitiesByIds(entityIds) {
|
|
12090
|
-
return super.getEntitiesByIds(entityIds).then((result) => result || []);
|
|
12091
|
-
}
|
|
12092
|
-
updateEntity(entity2) {
|
|
12093
|
-
return super.updateEntity(entity2);
|
|
12094
|
-
}
|
|
12095
|
-
createMemory(memory, tableName) {
|
|
12096
|
-
return super.createMemory(memory, tableName);
|
|
12097
|
-
}
|
|
12098
|
-
getMemoryById(memoryId) {
|
|
12099
|
-
return super.getMemoryById(memoryId);
|
|
12100
|
-
}
|
|
12101
|
-
updateMemory(memory) {
|
|
12102
|
-
return super.updateMemory(memory);
|
|
12103
|
-
}
|
|
12104
|
-
deleteMemory(memoryId) {
|
|
12105
|
-
return super.deleteMemory(memoryId);
|
|
12106
|
-
}
|
|
12107
|
-
createComponent(component) {
|
|
12108
|
-
return super.createComponent(component);
|
|
12109
|
-
}
|
|
12110
|
-
getComponent(entityId, type, worldId, sourceEntityId) {
|
|
12111
|
-
return super.getComponent(entityId, type, worldId, sourceEntityId);
|
|
12112
|
-
}
|
|
12113
|
-
updateComponent(component) {
|
|
12114
|
-
return super.updateComponent(component);
|
|
12115
|
-
}
|
|
12116
|
-
deleteComponent(componentId) {
|
|
12117
|
-
return super.deleteComponent(componentId);
|
|
12118
|
-
}
|
|
12119
|
-
}
|
|
12120
|
-
|
|
12121
12113
|
// src/pg/manager.ts
|
|
12122
12114
|
init_drizzle_orm();
|
|
12123
12115
|
import { Pool as Pool2 } from "pg";
|
|
12124
|
-
import { logger as logger13 } from "@elizaos/core";
|
|
12116
|
+
import { logger as logger13, validateUuid as validateUuid2 } from "@elizaos/core";
|
|
12125
12117
|
|
|
12126
12118
|
class PostgresConnectionManager {
|
|
12127
12119
|
pool;
|
|
12128
12120
|
db;
|
|
12129
12121
|
constructor(connectionString, rlsServerId) {
|
|
12130
|
-
const poolConfig = {
|
|
12122
|
+
const poolConfig = {
|
|
12123
|
+
connectionString,
|
|
12124
|
+
max: 20,
|
|
12125
|
+
min: 2,
|
|
12126
|
+
idleTimeoutMillis: 30000,
|
|
12127
|
+
connectionTimeoutMillis: 5000,
|
|
12128
|
+
keepAlive: true,
|
|
12129
|
+
keepAliveInitialDelayMillis: 1e4
|
|
12130
|
+
};
|
|
12131
12131
|
if (rlsServerId) {
|
|
12132
12132
|
poolConfig.application_name = rlsServerId;
|
|
12133
12133
|
logger13.debug({ src: "plugin:sql", rlsServerId: rlsServerId.substring(0, 8) }, "Pool configured with RLS server");
|
|
12134
12134
|
}
|
|
12135
12135
|
this.pool = new Pool2(poolConfig);
|
|
12136
|
+
this.pool.on("error", (err) => {
|
|
12137
|
+
logger13.warn({ src: "plugin:sql", error: err?.message || String(err) }, "Pool client error (connection will be replaced)");
|
|
12138
|
+
});
|
|
12136
12139
|
this.db = drizzle2(this.pool, { casing: "snake_case" });
|
|
12137
12140
|
}
|
|
12138
12141
|
getDatabase() {
|
|
@@ -12163,6 +12166,9 @@ class PostgresConnectionManager {
|
|
|
12163
12166
|
const dataIsolationEnabled = process.env.ENABLE_DATA_ISOLATION === "true";
|
|
12164
12167
|
return await this.db.transaction(async (tx) => {
|
|
12165
12168
|
if (dataIsolationEnabled && entityId) {
|
|
12169
|
+
if (!validateUuid2(entityId)) {
|
|
12170
|
+
throw new Error(`Invalid UUID format for entity context: ${entityId}`);
|
|
12171
|
+
}
|
|
12166
12172
|
try {
|
|
12167
12173
|
await tx.execute(sql.raw(`SET LOCAL app.entity_id = '${entityId}'`));
|
|
12168
12174
|
logger13.debug(`[Entity Context] Set app.entity_id = ${entityId}`);
|
|
@@ -12323,5 +12329,5 @@ export {
|
|
|
12323
12329
|
DatabaseMigrationService
|
|
12324
12330
|
};
|
|
12325
12331
|
|
|
12326
|
-
//# debugId=
|
|
12332
|
+
//# debugId=71E0E3CA07B8EA3964756E2164756E21
|
|
12327
12333
|
//# sourceMappingURL=index.node.js.map
|