@elizaos/plugin-sql 1.0.0-alpha.20 → 1.0.0-alpha.22
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/README.md +1 -14
- package/dist/{chunk-LLEN3JTK.js → chunk-2FOOMI3E.js} +41 -3
- package/dist/chunk-2FOOMI3E.js.map +1 -0
- package/dist/index.js +58 -208
- package/dist/index.js.map +1 -1
- package/dist/migrate.js +1 -1
- package/package.json +5 -4
- package/dist/chunk-LLEN3JTK.js.map +0 -1
package/README.md
CHANGED
|
@@ -9,19 +9,6 @@ A PostgreSQL database adapter built with Drizzle ORM for the ElizaOS ecosystem.
|
|
|
9
9
|
bun add @elizaos/plugin-sql
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
## Database Schema
|
|
13
|
-
|
|
14
|
-
The adapter includes the following tables:
|
|
15
|
-
- accounts
|
|
16
|
-
- cache
|
|
17
|
-
- embeddings
|
|
18
|
-
- goals
|
|
19
|
-
- logs
|
|
20
|
-
- memories
|
|
21
|
-
- participants
|
|
22
|
-
- relationships
|
|
23
|
-
- rooms
|
|
24
|
-
|
|
25
12
|
## Vector Dimensions
|
|
26
13
|
|
|
27
14
|
The adapter supports the following vector dimensions:
|
|
@@ -55,7 +42,7 @@ The adapter is typically used as part of the ElizaOS runtime:
|
|
|
55
42
|
|
|
56
43
|
```typescript
|
|
57
44
|
async function findDatabaseAdapter(runtime: IAgentRuntime) {
|
|
58
|
-
let adapter = runtime
|
|
45
|
+
let adapter = runtime;
|
|
59
46
|
|
|
60
47
|
if (!adapter) {
|
|
61
48
|
const drizzleAdapterPlugin = await import('@elizaos/plugin-sql');
|
|
@@ -93,6 +93,21 @@ var PGliteClientManager = class {
|
|
|
93
93
|
await this.gracefulShutdown();
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Asynchronously checks if migrations exist in the database.
|
|
98
|
+
* @returns {Promise<boolean>} A Promise that resolves to true if migrations exist, otherwise false.
|
|
99
|
+
*/
|
|
100
|
+
async hasMigrations() {
|
|
101
|
+
try {
|
|
102
|
+
const result = await this.client.query(
|
|
103
|
+
"SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = '__drizzle_migrations')"
|
|
104
|
+
);
|
|
105
|
+
return result.rows[0].exists;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
logger.error("Failed to check migrations:", error);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
96
111
|
/**
|
|
97
112
|
* Initializes the client for PGlite.
|
|
98
113
|
*
|
|
@@ -134,12 +149,16 @@ var PGliteClientManager = class {
|
|
|
134
149
|
async runMigrations() {
|
|
135
150
|
try {
|
|
136
151
|
const db = drizzle(this.client);
|
|
152
|
+
if (await this.hasMigrations()) {
|
|
153
|
+
logger.info("Migrations already exist, skipping...");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
137
156
|
await migrate(db, {
|
|
138
157
|
migrationsFolder: path.resolve(__dirname, "../drizzle/migrations")
|
|
139
158
|
});
|
|
140
159
|
logger.info("Migrations completed successfully!");
|
|
141
160
|
} catch (error) {
|
|
142
|
-
logger.error("Failed to run database migrations:", error);
|
|
161
|
+
logger.error("Failed to run database migrations (pglite):", error);
|
|
143
162
|
}
|
|
144
163
|
}
|
|
145
164
|
};
|
|
@@ -296,6 +315,21 @@ var PostgresConnectionManager = class {
|
|
|
296
315
|
async close() {
|
|
297
316
|
await this.cleanup();
|
|
298
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Asynchronously checks if migrations exist in the database.
|
|
320
|
+
* @returns {Promise<boolean>} A Promise that resolves to true if migrations exist, otherwise false.
|
|
321
|
+
*/
|
|
322
|
+
async hasMigrations() {
|
|
323
|
+
try {
|
|
324
|
+
const result = await this.pool.query(
|
|
325
|
+
"SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = '__drizzle_migrations')"
|
|
326
|
+
);
|
|
327
|
+
return result.rows[0].exists;
|
|
328
|
+
} catch (error) {
|
|
329
|
+
logger2.error("Failed to check migrations:", error);
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
299
333
|
/**
|
|
300
334
|
* Cleans up and closes the database pool.
|
|
301
335
|
* @returns {Promise<void>} A Promise that resolves when the database pool is closed.
|
|
@@ -316,12 +350,16 @@ var PostgresConnectionManager = class {
|
|
|
316
350
|
async runMigrations() {
|
|
317
351
|
try {
|
|
318
352
|
const db = drizzle2(this.pool);
|
|
353
|
+
if (await this.hasMigrations()) {
|
|
354
|
+
logger2.info("Migrations already exist, skipping...");
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
319
357
|
await migrate2(db, {
|
|
320
358
|
migrationsFolder: path2.resolve(__dirname2, "../drizzle/migrations")
|
|
321
359
|
});
|
|
322
360
|
logger2.info("Migrations completed successfully!");
|
|
323
361
|
} catch (error) {
|
|
324
|
-
logger2.error("Failed to run database migrations:", error);
|
|
362
|
+
logger2.error("Failed to run database migrations (pg):", error);
|
|
325
363
|
}
|
|
326
364
|
}
|
|
327
365
|
};
|
|
@@ -331,4 +369,4 @@ export {
|
|
|
331
369
|
PGliteClientManager,
|
|
332
370
|
PostgresConnectionManager
|
|
333
371
|
};
|
|
334
|
-
//# sourceMappingURL=chunk-
|
|
372
|
+
//# sourceMappingURL=chunk-2FOOMI3E.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/pg-lite/manager.ts","../src/pg/manager.ts"],"sourceRoot":"./","sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { PGlite, type PGliteOptions } from \"@electric-sql/pglite\";\nimport { fuzzystrmatch } from \"@electric-sql/pglite/contrib/fuzzystrmatch\";\nimport { vector } from \"@electric-sql/pglite/vector\";\nimport { logger } from \"@elizaos/core\";\nimport { drizzle } from \"drizzle-orm/pglite\";\nimport { migrate } from \"drizzle-orm/pglite/migrator\";\nimport type { IDatabaseClientManager } from \"../types\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\n/**\n * Class representing a database client manager for PGlite.\n * @implements { IDatabaseClientManager }\n */\nexport class PGliteClientManager implements IDatabaseClientManager<PGlite> {\n\tprivate client: PGlite;\n\tprivate shuttingDown = false;\n\tprivate readonly shutdownTimeout = 500;\n\n\t/**\n\t * Constructor for creating a new instance of PGlite with the provided options.\n\t * Initializes the PGlite client with additional extensions.\n\t * @param {PGliteOptions} options - The options to configure the PGlite client.\n\t */\n\tconstructor(options: PGliteOptions) {\n\t\tthis.client = new PGlite({\n\t\t\t...options,\n\t\t\textensions: {\n\t\t\t\tvector,\n\t\t\t\tfuzzystrmatch,\n\t\t\t},\n\t\t});\n\t\tthis.setupShutdownHandlers();\n\t}\n\n\t/**\n\t * Retrieves the PostgreSQL lite connection.\n\t *\n\t * @returns {PGlite} The PostgreSQL lite connection.\n\t * @throws {Error} If the client manager is currently shutting down.\n\t */\n\tpublic getConnection(): PGlite {\n\t\tif (this.shuttingDown) {\n\t\t\tthrow new Error(\"Client manager is shutting down\");\n\t\t}\n\t\treturn this.client;\n\t}\n\n\t/**\n\t * Initiates a graceful shutdown of the PGlite client.\n\t * Checks if the client is already in the process of shutting down.\n\t * Logs the start of shutdown process and sets shuttingDown flag to true.\n\t * Sets a timeout for the shutdown process and forces closure of database connection if timeout is reached.\n\t * Handles the shutdown process, closes the client connection, clears the timeout, and logs the completion of shutdown.\n\t * Logs any errors that occur during the shutdown process.\n\t */\n\tprivate async gracefulShutdown() {\n\t\tif (this.shuttingDown) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.shuttingDown = true;\n\t\tlogger.info(\"Starting graceful shutdown of PGlite client...\");\n\n\t\tconst timeout = setTimeout(() => {\n\t\t\tlogger.warn(\n\t\t\t\t\"Shutdown timeout reached, forcing database connection closure...\",\n\t\t\t);\n\t\t\tthis.client.close().finally(() => {\n\t\t\t\tprocess.exit(1);\n\t\t\t});\n\t\t}, this.shutdownTimeout);\n\n\t\ttry {\n\t\t\tawait this.client.close();\n\t\t\tclearTimeout(timeout);\n\t\t\tlogger.info(\"PGlite client shutdown completed successfully\");\n\t\t\tprocess.exit(0);\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Error during graceful shutdown:\", error);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\t/**\n\t * Sets up shutdown handlers for SIGINT, SIGTERM, and beforeExit events to gracefully shutdown the application.\n\t * @private\n\t */\n\tprivate setupShutdownHandlers() {\n\t\tprocess.on(\"SIGINT\", async () => {\n\t\t\tawait this.gracefulShutdown();\n\t\t});\n\n\t\tprocess.on(\"SIGTERM\", async () => {\n\t\t\tawait this.gracefulShutdown();\n\t\t});\n\n\t\tprocess.on(\"beforeExit\", async () => {\n\t\t\tawait this.gracefulShutdown();\n\t\t});\n\t}\n\n\t/**\n\t * Asynchronously checks if migrations exist in the database.\n\t * @returns {Promise<boolean>} A Promise that resolves to true if migrations exist, otherwise false.\n\t */\n\tprivate async hasMigrations(): Promise<boolean> {\n\t\ttry {\n\t\t\tconst result = await this.client.query(\n\t\t\t\t\"SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = '__drizzle_migrations')\"\n\t\t\t);\n\t\t\treturn (result.rows[0] as any).exists;\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Failed to check migrations:\", error);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\n\t/**\n\t * Initializes the client for PGlite.\n\t *\n\t * @returns {Promise<void>} A Promise that resolves when the client is initialized successfully\n\t */\n\tpublic async initialize(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.client.waitReady;\n\t\t\tlogger.info(\"PGlite client initialized successfully\");\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Failed to initialize PGlite client:\", error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Asynchronously closes the resource. If the resource is not already shutting down,\n\t * it performs a graceful shutdown before closing.\n\t *\n\t * @returns A promise that resolves once the resource has been closed.\n\t */\n\tpublic async close(): Promise<void> {\n\t\tif (!this.shuttingDown) {\n\t\t\tawait this.gracefulShutdown();\n\t\t}\n\t}\n\n\t/**\n\t * Check if the system is currently shutting down.\n\t *\n\t * @returns {boolean} True if the system is shutting down, false otherwise.\n\t */\n\tpublic isShuttingDown(): boolean {\n\t\treturn this.shuttingDown;\n\t}\n\n\t/**\n\t * Asynchronously runs database migrations using Drizzle.\n\t *\n\t * @returns {Promise<void>} A Promise that resolves once the migrations are completed successfully.\n\t */\n\tasync runMigrations(): Promise<void> {\n\t\ttry {\n\t\t\tconst db = drizzle(this.client);\n\t\t\tif (await this.hasMigrations()) {\n\t\t\t\tlogger.info(\"Migrations already exist, skipping...\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait migrate(db, {\n\t\t\t\tmigrationsFolder: path.resolve(__dirname, \"../drizzle/migrations\"),\n\t\t\t});\n\t\t\tlogger.info(\"Migrations completed successfully!\");\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Failed to run database migrations (pglite):\", error);\n\t\t\t// throw error;\n\t\t}\n\t}\n}\n","import path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { logger } from \"@elizaos/core\";\nimport { drizzle } from \"drizzle-orm/node-postgres\";\nimport { migrate } from \"drizzle-orm/node-postgres/migrator\";\nimport pkg, { type Pool as PgPool } from \"pg\";\nimport type { IDatabaseClientManager } from \"../types\";\n\nconst { Pool } = pkg;\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\n/**\n * Manages connections to a PostgreSQL database using a connection pool.\n * Implements IDatabaseClientManager interface.\n */\n\nexport class PostgresConnectionManager\n\timplements IDatabaseClientManager<PgPool>\n{\n\tprivate pool: PgPool;\n\tprivate isShuttingDown = false;\n\tprivate readonly connectionTimeout: number = 5000;\n\n\t/**\n\t * Constructor for creating a connection pool.\n\t * @param {string} connectionString - The connection string used to connect to the database.\n\t */\n\tconstructor(connectionString: string) {\n\t\tconst defaultConfig = {\n\t\t\tmax: 20,\n\t\t\tidleTimeoutMillis: 30000,\n\t\t\tconnectionTimeoutMillis: this.connectionTimeout,\n\t\t};\n\n\t\tthis.pool = new Pool({\n\t\t\t...defaultConfig,\n\t\t\tconnectionString,\n\t\t});\n\n\t\tthis.pool.on(\"error\", (err) => {\n\t\t\tlogger.error(\"Unexpected pool error\", err);\n\t\t\tthis.handlePoolError(err);\n\t\t});\n\n\t\tthis.setupPoolErrorHandling();\n\t\tthis.testConnection();\n\t}\n\n\t/**\n\t * Handles a pool error by attempting to reconnect the pool.\n\t *\n\t * @param {Error} error The error that occurred in the pool.\n\t * @throws {Error} If failed to reconnect the pool.\n\t */\n\tprivate async handlePoolError(error: Error) {\n\t\tlogger.error(\"Pool error occurred, attempting to reconnect\", {\n\t\t\terror: error.message,\n\t\t});\n\n\t\ttry {\n\t\t\tawait this.pool.end();\n\n\t\t\tthis.pool = new Pool({\n\t\t\t\t...this.pool.options,\n\t\t\t\tconnectionTimeoutMillis: this.connectionTimeout,\n\t\t\t});\n\n\t\t\tawait this.testConnection();\n\t\t\tlogger.success(\"Pool reconnection successful\");\n\t\t} catch (reconnectError) {\n\t\t\tlogger.error(\"Failed to reconnect pool\", {\n\t\t\t\terror:\n\t\t\t\t\treconnectError instanceof Error\n\t\t\t\t\t\t? reconnectError.message\n\t\t\t\t\t\t: String(reconnectError),\n\t\t\t});\n\t\t\tthrow reconnectError;\n\t\t}\n\t}\n\n\t/**\n\t * Asynchronously tests the database connection by executing a query to get the current timestamp.\n\t *\n\t * @returns {Promise<boolean>} - A Promise that resolves to true if the database connection test is successful.\n\t */\n\tasync testConnection(): Promise<boolean> {\n\t\tlet client: pkg.PoolClient | null = null;\n\t\ttry {\n\t\t\tclient = await this.pool.connect();\n\t\t\tconst result = await client.query(\"SELECT NOW()\");\n\t\t\tlogger.success(\"Database connection test successful:\", result.rows[0]);\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Database connection test failed:\", error);\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to connect to database: ${(error as Error).message}`,\n\t\t\t);\n\t\t} finally {\n\t\t\tif (client) client.release();\n\t\t}\n\t}\n\n\t/**\n\t * Sets up event listeners to handle pool cleanup on SIGINT, SIGTERM, and beforeExit events.\n\t */\n\tprivate setupPoolErrorHandling() {\n\t\tprocess.on(\"SIGINT\", async () => {\n\t\t\tawait this.cleanup();\n\t\t\tprocess.exit(0);\n\t\t});\n\n\t\tprocess.on(\"SIGTERM\", async () => {\n\t\t\tawait this.cleanup();\n\t\t\tprocess.exit(0);\n\t\t});\n\n\t\tprocess.on(\"beforeExit\", async () => {\n\t\t\tawait this.cleanup();\n\t\t});\n\t}\n\n\t/**\n\t * Get the connection pool.\n\t * @returns {PgPool} The connection pool\n\t * @throws {Error} If the connection manager is shutting down or an error occurs when trying to get the connection from the pool\n\t */\n\tpublic getConnection(): PgPool {\n\t\tif (this.isShuttingDown) {\n\t\t\tthrow new Error(\"Connection manager is shutting down\");\n\t\t}\n\n\t\ttry {\n\t\t\treturn this.pool;\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Failed to get connection from pool:\", error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Asynchronously acquires a database client from the connection pool.\n\t *\n\t * @returns {Promise<pkg.PoolClient>} A Promise that resolves with the acquired database client.\n\t * @throws {Error} If an error occurs while acquiring the database client.\n\t */\n\tpublic async getClient(): Promise<pkg.PoolClient> {\n\t\ttry {\n\t\t\treturn await this.pool.connect();\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Failed to acquire a database client:\", error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Initializes the PostgreSQL connection manager by testing the connection and logging the result.\n\t *\n\t * @returns {Promise<void>} A Promise that resolves once the manager is successfully initialized\n\t * @throws {Error} If there is an error initializing the connection manager\n\t */\n\tpublic async initialize(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.testConnection();\n\t\t\tlogger.info(\"PostgreSQL connection manager initialized successfully\");\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Failed to initialize connection manager:\", error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Asynchronously close the current process by executing a cleanup function.\n\t * @returns A promise that resolves once the cleanup is complete.\n\t */\n\tpublic async close(): Promise<void> {\n\t\tawait this.cleanup();\n\t}\n\n\t/**\n\t * Asynchronously checks if migrations exist in the database.\n\t * @returns {Promise<boolean>} A Promise that resolves to true if migrations exist, otherwise false.\n\t */\n\tprivate async hasMigrations(): Promise<boolean> {\n\t\ttry {\n\t\t\tconst result = await this.pool.query(\n\t\t\t\t\"SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = '__drizzle_migrations')\"\n\t\t\t);\n\t\t\treturn result.rows[0].exists;\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Failed to check migrations:\", error);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Cleans up and closes the database pool.\n\t * @returns {Promise<void>} A Promise that resolves when the database pool is closed.\n\t */\n\tasync cleanup(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.pool.end();\n\t\t\tlogger.info(\"Database pool closed\");\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Error closing database pool:\", error);\n\t\t}\n\t}\n\n\t/**\n\t * Asynchronously runs database migrations using the Drizzle library.\n\t *\n\t * @returns {Promise<void>} A Promise that resolves once the migrations are completed successfully.\n\t */\n\tasync runMigrations(): Promise<void> {\n\t\ttry {\n\t\t\tconst db = drizzle(this.pool);\n\t\t\tif (await this.hasMigrations()) {\n\t\t\t\tlogger.info(\"Migrations already exist, skipping...\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait migrate(db, {\n\t\t\t\tmigrationsFolder: path.resolve(__dirname, \"../drizzle/migrations\"),\n\t\t\t});\n\t\t\tlogger.info(\"Migrations completed successfully!\");\n\t\t} catch (error) {\n\t\t\tlogger.error(\"Failed to run database migrations (pg):\", error);\n\t\t\t// throw error;\n\t\t}\n\t}\n}\n"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AClE,CAAC;AACD,MAAAE,QAAO,KAAK,oCAAoC;AAAA,IACjD,SAAS,OAAO;AACf,MAAAA,QAAO,MAAM,2CAA2C,KAAK;AAAA,IAE9D;AAAA,EACD;AACD;","names":["path","fileURLToPath","logger","drizzle","migrate","__filename","fileURLToPath","__dirname","path","logger","drizzle","migrate"]}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
PGliteClientManager,
|
|
3
3
|
PostgresConnectionManager,
|
|
4
4
|
__name
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-2FOOMI3E.js";
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
8
8
|
import * as os from "node:os";
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
inArray,
|
|
30
30
|
lte,
|
|
31
31
|
or,
|
|
32
|
-
sql as
|
|
32
|
+
sql as sql12
|
|
33
33
|
} from "drizzle-orm";
|
|
34
34
|
import { v4 } from "uuid";
|
|
35
35
|
|
|
@@ -325,27 +325,18 @@ var componentTable = pgTable8("components", {
|
|
|
325
325
|
createdAt: numberTimestamp("createdAt").default(sql8`now()`).notNull()
|
|
326
326
|
});
|
|
327
327
|
|
|
328
|
-
// src/schema/
|
|
328
|
+
// src/schema/log.ts
|
|
329
329
|
import { sql as sql9 } from "drizzle-orm";
|
|
330
330
|
import { foreignKey as foreignKey3, jsonb as jsonb8, pgTable as pgTable9, text as text8, uuid as uuid9 } from "drizzle-orm/pg-core";
|
|
331
|
-
var
|
|
332
|
-
"
|
|
331
|
+
var logTable = pgTable9(
|
|
332
|
+
"logs",
|
|
333
333
|
{
|
|
334
|
-
id: uuid9("id").
|
|
334
|
+
id: uuid9("id").defaultRandom().notNull(),
|
|
335
335
|
createdAt: numberTimestamp("createdAt").default(sql9`now()`).notNull(),
|
|
336
|
-
entityId: uuid9("entityId").references(() => entityTable.id,
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
onDelete: "cascade"
|
|
341
|
-
}),
|
|
342
|
-
name: text8("name"),
|
|
343
|
-
status: text8("status"),
|
|
344
|
-
description: text8("description"),
|
|
345
|
-
roomId: uuid9("roomId").references(() => roomTable.id, {
|
|
346
|
-
onDelete: "cascade"
|
|
347
|
-
}),
|
|
348
|
-
objectives: jsonb8("objectives").default("[]").notNull()
|
|
336
|
+
entityId: uuid9("entityId").notNull().references(() => entityTable.id),
|
|
337
|
+
body: jsonb8("body").notNull(),
|
|
338
|
+
type: text8("type").notNull(),
|
|
339
|
+
roomId: uuid9("roomId").notNull().references(() => roomTable.id)
|
|
349
340
|
},
|
|
350
341
|
(table) => [
|
|
351
342
|
foreignKey3({
|
|
@@ -361,68 +352,41 @@ var goalTable = pgTable9(
|
|
|
361
352
|
]
|
|
362
353
|
);
|
|
363
354
|
|
|
364
|
-
// src/schema/log.ts
|
|
365
|
-
import { sql as sql10 } from "drizzle-orm";
|
|
366
|
-
import { foreignKey as foreignKey4, jsonb as jsonb9, pgTable as pgTable10, text as text9, uuid as uuid10 } from "drizzle-orm/pg-core";
|
|
367
|
-
var logTable = pgTable10(
|
|
368
|
-
"logs",
|
|
369
|
-
{
|
|
370
|
-
id: uuid10("id").defaultRandom().notNull(),
|
|
371
|
-
createdAt: numberTimestamp("createdAt").default(sql10`now()`).notNull(),
|
|
372
|
-
entityId: uuid10("entityId").notNull().references(() => entityTable.id),
|
|
373
|
-
body: jsonb9("body").notNull(),
|
|
374
|
-
type: text9("type").notNull(),
|
|
375
|
-
roomId: uuid10("roomId").notNull().references(() => roomTable.id)
|
|
376
|
-
},
|
|
377
|
-
(table) => [
|
|
378
|
-
foreignKey4({
|
|
379
|
-
name: "fk_room",
|
|
380
|
-
columns: [table.roomId],
|
|
381
|
-
foreignColumns: [roomTable.id]
|
|
382
|
-
}).onDelete("cascade"),
|
|
383
|
-
foreignKey4({
|
|
384
|
-
name: "fk_user",
|
|
385
|
-
columns: [table.entityId],
|
|
386
|
-
foreignColumns: [entityTable.id]
|
|
387
|
-
}).onDelete("cascade")
|
|
388
|
-
]
|
|
389
|
-
);
|
|
390
|
-
|
|
391
355
|
// src/schema/participant.ts
|
|
392
|
-
import { sql as
|
|
356
|
+
import { sql as sql10 } from "drizzle-orm";
|
|
393
357
|
import {
|
|
394
|
-
foreignKey as
|
|
358
|
+
foreignKey as foreignKey4,
|
|
395
359
|
index as index3,
|
|
396
|
-
pgTable as
|
|
397
|
-
text as
|
|
398
|
-
uuid as
|
|
360
|
+
pgTable as pgTable10,
|
|
361
|
+
text as text9,
|
|
362
|
+
uuid as uuid10
|
|
399
363
|
} from "drizzle-orm/pg-core";
|
|
400
|
-
var participantTable =
|
|
364
|
+
var participantTable = pgTable10(
|
|
401
365
|
"participants",
|
|
402
366
|
{
|
|
403
|
-
id:
|
|
404
|
-
createdAt: numberTimestamp("createdAt").default(
|
|
405
|
-
entityId:
|
|
367
|
+
id: uuid10("id").notNull().primaryKey().default(sql10`gen_random_uuid()`),
|
|
368
|
+
createdAt: numberTimestamp("createdAt").default(sql10`now()`).notNull(),
|
|
369
|
+
entityId: uuid10("entityId").references(() => entityTable.id, {
|
|
406
370
|
onDelete: "cascade"
|
|
407
371
|
}),
|
|
408
|
-
roomId:
|
|
372
|
+
roomId: uuid10("roomId").references(() => roomTable.id, {
|
|
409
373
|
onDelete: "cascade"
|
|
410
374
|
}),
|
|
411
|
-
agentId:
|
|
375
|
+
agentId: uuid10("agentId").references(() => agentTable.id, {
|
|
412
376
|
onDelete: "cascade"
|
|
413
377
|
}),
|
|
414
|
-
roomState:
|
|
378
|
+
roomState: text9("roomState")
|
|
415
379
|
},
|
|
416
380
|
(table) => [
|
|
417
381
|
// unique("participants_user_room_agent_unique").on(table.entityId, table.roomId, table.agentId),
|
|
418
382
|
index3("idx_participants_user").on(table.entityId),
|
|
419
383
|
index3("idx_participants_room").on(table.roomId),
|
|
420
|
-
|
|
384
|
+
foreignKey4({
|
|
421
385
|
name: "fk_room",
|
|
422
386
|
columns: [table.roomId],
|
|
423
387
|
foreignColumns: [roomTable.id]
|
|
424
388
|
}).onDelete("cascade"),
|
|
425
|
-
|
|
389
|
+
foreignKey4({
|
|
426
390
|
name: "fk_user",
|
|
427
391
|
columns: [table.entityId],
|
|
428
392
|
foreignColumns: [entityTable.id]
|
|
@@ -431,26 +395,26 @@ var participantTable = pgTable11(
|
|
|
431
395
|
);
|
|
432
396
|
|
|
433
397
|
// src/schema/relationship.ts
|
|
434
|
-
import { sql as
|
|
398
|
+
import { sql as sql11 } from "drizzle-orm";
|
|
435
399
|
import {
|
|
436
|
-
foreignKey as
|
|
400
|
+
foreignKey as foreignKey5,
|
|
437
401
|
index as index4,
|
|
438
|
-
jsonb as
|
|
439
|
-
pgTable as
|
|
440
|
-
text as
|
|
402
|
+
jsonb as jsonb9,
|
|
403
|
+
pgTable as pgTable11,
|
|
404
|
+
text as text10,
|
|
441
405
|
unique as unique6,
|
|
442
|
-
uuid as
|
|
406
|
+
uuid as uuid11
|
|
443
407
|
} from "drizzle-orm/pg-core";
|
|
444
|
-
var relationshipTable =
|
|
408
|
+
var relationshipTable = pgTable11(
|
|
445
409
|
"relationships",
|
|
446
410
|
{
|
|
447
|
-
id:
|
|
448
|
-
createdAt: numberTimestamp("createdAt").default(
|
|
449
|
-
sourceEntityId:
|
|
450
|
-
targetEntityId:
|
|
451
|
-
agentId:
|
|
452
|
-
tags:
|
|
453
|
-
metadata:
|
|
411
|
+
id: uuid11("id").notNull().primaryKey().default(sql11`gen_random_uuid()`),
|
|
412
|
+
createdAt: numberTimestamp("createdAt").default(sql11`now()`).notNull(),
|
|
413
|
+
sourceEntityId: uuid11("sourceEntityId").notNull().references(() => entityTable.id, { onDelete: "cascade" }),
|
|
414
|
+
targetEntityId: uuid11("targetEntityId").notNull().references(() => entityTable.id, { onDelete: "cascade" }),
|
|
415
|
+
agentId: uuid11("agentId").notNull().references(() => agentTable.id, { onDelete: "cascade" }),
|
|
416
|
+
tags: text10("tags").array(),
|
|
417
|
+
metadata: jsonb9("metadata")
|
|
454
418
|
},
|
|
455
419
|
(table) => [
|
|
456
420
|
index4("idx_relationships_users").on(
|
|
@@ -462,12 +426,12 @@ var relationshipTable = pgTable12(
|
|
|
462
426
|
table.targetEntityId,
|
|
463
427
|
table.agentId
|
|
464
428
|
),
|
|
465
|
-
|
|
429
|
+
foreignKey5({
|
|
466
430
|
name: "fk_user_a",
|
|
467
431
|
columns: [table.sourceEntityId],
|
|
468
432
|
foreignColumns: [entityTable.id]
|
|
469
433
|
}).onDelete("cascade"),
|
|
470
|
-
|
|
434
|
+
foreignKey5({
|
|
471
435
|
name: "fk_user_b",
|
|
472
436
|
columns: [table.targetEntityId],
|
|
473
437
|
foreignColumns: [entityTable.id]
|
|
@@ -476,16 +440,16 @@ var relationshipTable = pgTable12(
|
|
|
476
440
|
);
|
|
477
441
|
|
|
478
442
|
// src/schema/tasks.ts
|
|
479
|
-
import { jsonb as
|
|
480
|
-
var taskTable =
|
|
481
|
-
id:
|
|
482
|
-
name:
|
|
483
|
-
description:
|
|
484
|
-
roomId:
|
|
485
|
-
worldId:
|
|
486
|
-
agentId:
|
|
487
|
-
tags:
|
|
488
|
-
metadata:
|
|
443
|
+
import { jsonb as jsonb10, pgTable as pgTable12, text as text11, timestamp, uuid as uuid12 } from "drizzle-orm/pg-core";
|
|
444
|
+
var taskTable = pgTable12("tasks", {
|
|
445
|
+
id: uuid12("id").primaryKey().defaultRandom(),
|
|
446
|
+
name: text11("name").notNull(),
|
|
447
|
+
description: text11("description").notNull(),
|
|
448
|
+
roomId: uuid12("room_id"),
|
|
449
|
+
worldId: uuid12("world_id"),
|
|
450
|
+
agentId: uuid12("agent_id").notNull(),
|
|
451
|
+
tags: text11("tags").array(),
|
|
452
|
+
metadata: jsonb10("metadata"),
|
|
489
453
|
createdAt: timestamp("created_at").defaultNow(),
|
|
490
454
|
updatedAt: timestamp("updated_at").defaultNow()
|
|
491
455
|
});
|
|
@@ -583,9 +547,6 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
|
|
|
583
547
|
const usedDimension = Object.entries(DIMENSION_MAP).find(
|
|
584
548
|
([_, colName]) => existingMemory[0].embedding[colName] !== null
|
|
585
549
|
);
|
|
586
|
-
if (usedDimension && usedDimension[1] !== DIMENSION_MAP[dimension]) {
|
|
587
|
-
throw new Error("Cannot change embedding dimension for agent");
|
|
588
|
-
}
|
|
589
550
|
}
|
|
590
551
|
this.embeddingDimension = DIMENSION_MAP[dimension];
|
|
591
552
|
}
|
|
@@ -1014,7 +975,7 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
|
|
|
1014
975
|
async getCachedEmbeddings(opts) {
|
|
1015
976
|
return this.withDatabase(async () => {
|
|
1016
977
|
try {
|
|
1017
|
-
const results = await this.db.execute(
|
|
978
|
+
const results = await this.db.execute(sql12`
|
|
1018
979
|
WITH content_text AS (
|
|
1019
980
|
SELECT
|
|
1020
981
|
m.id,
|
|
@@ -1071,7 +1032,7 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
|
|
|
1071
1032
|
try {
|
|
1072
1033
|
await this.db.transaction(async (tx) => {
|
|
1073
1034
|
await tx.insert(logTable).values({
|
|
1074
|
-
body:
|
|
1035
|
+
body: sql12`${params.body}::jsonb`,
|
|
1075
1036
|
entityId: params.entityId,
|
|
1076
1037
|
roomId: params.roomId,
|
|
1077
1038
|
type: params.type
|
|
@@ -1097,30 +1058,12 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
|
|
|
1097
1058
|
tableName: params.tableName
|
|
1098
1059
|
});
|
|
1099
1060
|
}
|
|
1100
|
-
async updateGoalStatus(params) {
|
|
1101
|
-
return this.withDatabase(async () => {
|
|
1102
|
-
try {
|
|
1103
|
-
await this.db.transaction(async (tx) => {
|
|
1104
|
-
await tx.update(goalTable).set({
|
|
1105
|
-
status: params.status
|
|
1106
|
-
}).where(eq(goalTable.id, params.goalId));
|
|
1107
|
-
});
|
|
1108
|
-
} catch (error) {
|
|
1109
|
-
logger.error("Failed to update goal status:", {
|
|
1110
|
-
goalId: params.goalId,
|
|
1111
|
-
status: params.status,
|
|
1112
|
-
error: error instanceof Error ? error.message : String(error)
|
|
1113
|
-
});
|
|
1114
|
-
throw error;
|
|
1115
|
-
}
|
|
1116
|
-
});
|
|
1117
|
-
}
|
|
1118
1061
|
async searchMemoriesByEmbedding(embedding, params) {
|
|
1119
1062
|
return this.withDatabase(async () => {
|
|
1120
1063
|
const cleanVector = embedding.map(
|
|
1121
1064
|
(n) => Number.isFinite(n) ? Number(n.toFixed(6)) : 0
|
|
1122
1065
|
);
|
|
1123
|
-
const similarity =
|
|
1066
|
+
const similarity = sql12`1 - (${cosineDistance(
|
|
1124
1067
|
embeddingTable[this.embeddingDimension],
|
|
1125
1068
|
cleanVector
|
|
1126
1069
|
)})`;
|
|
@@ -1180,8 +1123,8 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
|
|
|
1180
1123
|
{
|
|
1181
1124
|
id: memoryId,
|
|
1182
1125
|
type: tableName,
|
|
1183
|
-
content:
|
|
1184
|
-
metadata:
|
|
1126
|
+
content: sql12`${contentToInsert}::jsonb`,
|
|
1127
|
+
metadata: sql12`${memory.metadata || {}}::jsonb`,
|
|
1185
1128
|
entityId: memory.entityId,
|
|
1186
1129
|
roomId: memory.roomId,
|
|
1187
1130
|
agentId: memory.agentId,
|
|
@@ -1258,103 +1201,10 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
|
|
|
1258
1201
|
if (unique7) {
|
|
1259
1202
|
conditions.push(eq(memoryTable.unique, true));
|
|
1260
1203
|
}
|
|
1261
|
-
const result = await this.db.select({ count:
|
|
1204
|
+
const result = await this.db.select({ count: sql12`count(*)` }).from(memoryTable).where(and(...conditions));
|
|
1262
1205
|
return Number(result[0]?.count ?? 0);
|
|
1263
1206
|
});
|
|
1264
1207
|
}
|
|
1265
|
-
async getGoals(params) {
|
|
1266
|
-
return this.withDatabase(async () => {
|
|
1267
|
-
const conditions = [eq(goalTable.roomId, params.roomId)];
|
|
1268
|
-
if (params.entityId) {
|
|
1269
|
-
conditions.push(eq(goalTable.entityId, params.entityId));
|
|
1270
|
-
}
|
|
1271
|
-
if (params.onlyInProgress) {
|
|
1272
|
-
conditions.push(eq(goalTable.status, "IN_PROGRESS"));
|
|
1273
|
-
}
|
|
1274
|
-
const query = this.db.select().from(goalTable).where(and(...conditions)).orderBy(desc(goalTable.createdAt));
|
|
1275
|
-
const result = await (params.count ? query.limit(params.count) : query);
|
|
1276
|
-
return result.map((row) => ({
|
|
1277
|
-
id: row.id,
|
|
1278
|
-
roomId: row.roomId,
|
|
1279
|
-
entityId: row.entityId,
|
|
1280
|
-
name: row.name ?? "",
|
|
1281
|
-
status: row.status ?? "NOT_STARTED",
|
|
1282
|
-
description: row.description ?? "",
|
|
1283
|
-
objectives: row.objectives,
|
|
1284
|
-
createdAt: row.createdAt
|
|
1285
|
-
}));
|
|
1286
|
-
});
|
|
1287
|
-
}
|
|
1288
|
-
async updateGoal(goal) {
|
|
1289
|
-
return this.withDatabase(async () => {
|
|
1290
|
-
try {
|
|
1291
|
-
await this.db.transaction(async (tx) => {
|
|
1292
|
-
await tx.update(goalTable).set({
|
|
1293
|
-
name: goal.name,
|
|
1294
|
-
status: goal.status,
|
|
1295
|
-
objectives: goal.objectives
|
|
1296
|
-
}).where(eq(goalTable.id, goal.id));
|
|
1297
|
-
});
|
|
1298
|
-
} catch (error) {
|
|
1299
|
-
logger.error("Failed to update goal:", {
|
|
1300
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1301
|
-
goalId: goal.id,
|
|
1302
|
-
status: goal.status
|
|
1303
|
-
});
|
|
1304
|
-
throw error;
|
|
1305
|
-
}
|
|
1306
|
-
});
|
|
1307
|
-
}
|
|
1308
|
-
async createGoal(goal) {
|
|
1309
|
-
return this.withDatabase(async () => {
|
|
1310
|
-
try {
|
|
1311
|
-
await this.db.transaction(async (tx) => {
|
|
1312
|
-
await tx.insert(goalTable).values({
|
|
1313
|
-
id: goal.id ?? v4(),
|
|
1314
|
-
roomId: goal.roomId,
|
|
1315
|
-
entityId: goal.entityId,
|
|
1316
|
-
name: goal.name,
|
|
1317
|
-
status: goal.status,
|
|
1318
|
-
objectives: sql13`${goal.objectives}::jsonb`
|
|
1319
|
-
});
|
|
1320
|
-
});
|
|
1321
|
-
} catch (error) {
|
|
1322
|
-
logger.error("Failed to update goal:", {
|
|
1323
|
-
goalId: goal.id,
|
|
1324
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1325
|
-
status: goal.status
|
|
1326
|
-
});
|
|
1327
|
-
throw error;
|
|
1328
|
-
}
|
|
1329
|
-
});
|
|
1330
|
-
}
|
|
1331
|
-
async removeGoal(goalId) {
|
|
1332
|
-
if (!goalId) throw new Error("Goal ID is required");
|
|
1333
|
-
return this.withDatabase(async () => {
|
|
1334
|
-
try {
|
|
1335
|
-
await this.db.transaction(async (tx) => {
|
|
1336
|
-
await tx.delete(goalTable).where(eq(goalTable.id, goalId));
|
|
1337
|
-
});
|
|
1338
|
-
logger.debug("Goal removal attempt:", {
|
|
1339
|
-
goalId,
|
|
1340
|
-
removed: true
|
|
1341
|
-
});
|
|
1342
|
-
} catch (error) {
|
|
1343
|
-
logger.error("Failed to remove goal:", {
|
|
1344
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1345
|
-
goalId
|
|
1346
|
-
});
|
|
1347
|
-
throw error;
|
|
1348
|
-
}
|
|
1349
|
-
});
|
|
1350
|
-
}
|
|
1351
|
-
async removeAllGoals(roomId) {
|
|
1352
|
-
return this.withDatabase(async () => {
|
|
1353
|
-
await this.db.transaction(async (tx) => {
|
|
1354
|
-
await tx.delete(goalTable).where(eq(goalTable.roomId, roomId));
|
|
1355
|
-
});
|
|
1356
|
-
});
|
|
1357
|
-
}
|
|
1358
1208
|
async getRoom(roomId) {
|
|
1359
1209
|
return this.withDatabase(async () => {
|
|
1360
1210
|
const result = await this.db.select({
|
|
@@ -1633,7 +1483,7 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
|
|
|
1633
1483
|
if (params.tags && params.tags.length > 0) {
|
|
1634
1484
|
const tagParams = params.tags.map((tag) => `'${tag.replace(/'/g, "''")}'`).join(", ");
|
|
1635
1485
|
query = query.where(
|
|
1636
|
-
|
|
1486
|
+
sql12`${relationshipTable.tags} @> ARRAY[${sql12.raw(
|
|
1637
1487
|
tagParams
|
|
1638
1488
|
)}]::text[]`
|
|
1639
1489
|
);
|
|
@@ -1796,7 +1646,7 @@ var BaseDrizzleAdapter = class extends DatabaseAdapter {
|
|
|
1796
1646
|
if (params.tags && params.tags.length > 0) {
|
|
1797
1647
|
const tagParams = params.tags.map((tag) => `'${tag.replace(/'/g, "''")}'`).join(", ");
|
|
1798
1648
|
query = query.where(
|
|
1799
|
-
|
|
1649
|
+
sql12`${taskTable.tags} @> ARRAY[${sql12.raw(tagParams)}]::text[]`
|
|
1800
1650
|
);
|
|
1801
1651
|
}
|
|
1802
1652
|
const result = await query;
|