@elizaos/plugin-sql 1.6.4-alpha.15 → 1.6.4-alpha.16
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 +152 -142
- package/dist/browser/index.browser.js.map +5 -4
- package/dist/browser/tsconfig.build.tsbuildinfo +1 -1
- package/dist/node/index.node.js +291 -12
- package/dist/node/index.node.js.map +9 -7
- package/dist/node/tsconfig.build.node.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/types/index.d.ts +0 -19
|
@@ -36,7 +36,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
// src/runtime-migrator/storage/migration-tracker.ts
|
|
39
|
-
import { sql as
|
|
39
|
+
import { sql as sql17 } from "drizzle-orm";
|
|
40
40
|
|
|
41
41
|
class MigrationTracker {
|
|
42
42
|
db;
|
|
@@ -44,11 +44,11 @@ class MigrationTracker {
|
|
|
44
44
|
this.db = db;
|
|
45
45
|
}
|
|
46
46
|
async ensureSchema() {
|
|
47
|
-
await this.db.execute(
|
|
47
|
+
await this.db.execute(sql17`CREATE SCHEMA IF NOT EXISTS migrations`);
|
|
48
48
|
}
|
|
49
49
|
async ensureTables() {
|
|
50
50
|
await this.ensureSchema();
|
|
51
|
-
await this.db.execute(
|
|
51
|
+
await this.db.execute(sql17`
|
|
52
52
|
CREATE TABLE IF NOT EXISTS migrations._migrations (
|
|
53
53
|
id SERIAL PRIMARY KEY,
|
|
54
54
|
plugin_name TEXT NOT NULL,
|
|
@@ -56,7 +56,7 @@ class MigrationTracker {
|
|
|
56
56
|
created_at BIGINT NOT NULL
|
|
57
57
|
)
|
|
58
58
|
`);
|
|
59
|
-
await this.db.execute(
|
|
59
|
+
await this.db.execute(sql17`
|
|
60
60
|
CREATE TABLE IF NOT EXISTS migrations._journal (
|
|
61
61
|
plugin_name TEXT PRIMARY KEY,
|
|
62
62
|
version TEXT NOT NULL,
|
|
@@ -64,7 +64,7 @@ class MigrationTracker {
|
|
|
64
64
|
entries JSONB NOT NULL DEFAULT '[]'
|
|
65
65
|
)
|
|
66
66
|
`);
|
|
67
|
-
await this.db.execute(
|
|
67
|
+
await this.db.execute(sql17`
|
|
68
68
|
CREATE TABLE IF NOT EXISTS migrations._snapshots (
|
|
69
69
|
id SERIAL PRIMARY KEY,
|
|
70
70
|
plugin_name TEXT NOT NULL,
|
|
@@ -76,7 +76,7 @@ class MigrationTracker {
|
|
|
76
76
|
`);
|
|
77
77
|
}
|
|
78
78
|
async getLastMigration(pluginName) {
|
|
79
|
-
const result = await this.db.execute(
|
|
79
|
+
const result = await this.db.execute(sql17`SELECT id, hash, created_at
|
|
80
80
|
FROM migrations._migrations
|
|
81
81
|
WHERE plugin_name = ${pluginName}
|
|
82
82
|
ORDER BY created_at DESC
|
|
@@ -84,14 +84,14 @@ class MigrationTracker {
|
|
|
84
84
|
return result.rows[0] || null;
|
|
85
85
|
}
|
|
86
86
|
async recordMigration(pluginName, hash, createdAt) {
|
|
87
|
-
await this.db.execute(
|
|
87
|
+
await this.db.execute(sql17`INSERT INTO migrations._migrations (plugin_name, hash, created_at)
|
|
88
88
|
VALUES (${pluginName}, ${hash}, ${createdAt})`);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
var init_migration_tracker = () => {};
|
|
92
92
|
|
|
93
93
|
// src/runtime-migrator/storage/journal-storage.ts
|
|
94
|
-
import { sql as
|
|
94
|
+
import { sql as sql18 } from "drizzle-orm";
|
|
95
95
|
|
|
96
96
|
class JournalStorage {
|
|
97
97
|
db;
|
|
@@ -99,7 +99,7 @@ class JournalStorage {
|
|
|
99
99
|
this.db = db;
|
|
100
100
|
}
|
|
101
101
|
async loadJournal(pluginName) {
|
|
102
|
-
const result = await this.db.execute(
|
|
102
|
+
const result = await this.db.execute(sql18`SELECT version, dialect, entries
|
|
103
103
|
FROM migrations._journal
|
|
104
104
|
WHERE plugin_name = ${pluginName}`);
|
|
105
105
|
if (result.rows.length === 0) {
|
|
@@ -113,7 +113,7 @@ class JournalStorage {
|
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
115
|
async saveJournal(pluginName, journal) {
|
|
116
|
-
await this.db.execute(
|
|
116
|
+
await this.db.execute(sql18`INSERT INTO migrations._journal (plugin_name, version, dialect, entries)
|
|
117
117
|
VALUES (${pluginName}, ${journal.version}, ${journal.dialect}, ${JSON.stringify(journal.entries)}::jsonb)
|
|
118
118
|
ON CONFLICT (plugin_name)
|
|
119
119
|
DO UPDATE SET
|
|
@@ -155,7 +155,7 @@ class JournalStorage {
|
|
|
155
155
|
var init_journal_storage = () => {};
|
|
156
156
|
|
|
157
157
|
// src/runtime-migrator/storage/snapshot-storage.ts
|
|
158
|
-
import { sql as
|
|
158
|
+
import { sql as sql19 } from "drizzle-orm";
|
|
159
159
|
|
|
160
160
|
class SnapshotStorage {
|
|
161
161
|
db;
|
|
@@ -163,7 +163,7 @@ class SnapshotStorage {
|
|
|
163
163
|
this.db = db;
|
|
164
164
|
}
|
|
165
165
|
async saveSnapshot(pluginName, idx, snapshot) {
|
|
166
|
-
await this.db.execute(
|
|
166
|
+
await this.db.execute(sql19`INSERT INTO migrations._snapshots (plugin_name, idx, snapshot)
|
|
167
167
|
VALUES (${pluginName}, ${idx}, ${JSON.stringify(snapshot)}::jsonb)
|
|
168
168
|
ON CONFLICT (plugin_name, idx)
|
|
169
169
|
DO UPDATE SET
|
|
@@ -171,7 +171,7 @@ class SnapshotStorage {
|
|
|
171
171
|
created_at = NOW()`);
|
|
172
172
|
}
|
|
173
173
|
async loadSnapshot(pluginName, idx) {
|
|
174
|
-
const result = await this.db.execute(
|
|
174
|
+
const result = await this.db.execute(sql19`SELECT snapshot
|
|
175
175
|
FROM migrations._snapshots
|
|
176
176
|
WHERE plugin_name = ${pluginName} AND idx = ${idx}`);
|
|
177
177
|
if (result.rows.length === 0) {
|
|
@@ -180,7 +180,7 @@ class SnapshotStorage {
|
|
|
180
180
|
return result.rows[0].snapshot;
|
|
181
181
|
}
|
|
182
182
|
async getLatestSnapshot(pluginName) {
|
|
183
|
-
const result = await this.db.execute(
|
|
183
|
+
const result = await this.db.execute(sql19`SELECT snapshot
|
|
184
184
|
FROM migrations._snapshots
|
|
185
185
|
WHERE plugin_name = ${pluginName}
|
|
186
186
|
ORDER BY idx DESC
|
|
@@ -191,7 +191,7 @@ class SnapshotStorage {
|
|
|
191
191
|
return result.rows[0].snapshot;
|
|
192
192
|
}
|
|
193
193
|
async getAllSnapshots(pluginName) {
|
|
194
|
-
const result = await this.db.execute(
|
|
194
|
+
const result = await this.db.execute(sql19`SELECT snapshot
|
|
195
195
|
FROM migrations._snapshots
|
|
196
196
|
WHERE plugin_name = ${pluginName}
|
|
197
197
|
ORDER BY idx ASC`);
|
|
@@ -201,7 +201,7 @@ class SnapshotStorage {
|
|
|
201
201
|
var init_snapshot_storage = () => {};
|
|
202
202
|
|
|
203
203
|
// src/runtime-migrator/extension-manager.ts
|
|
204
|
-
import { sql as
|
|
204
|
+
import { sql as sql20 } from "drizzle-orm";
|
|
205
205
|
import { logger } from "@elizaos/core";
|
|
206
206
|
|
|
207
207
|
class ExtensionManager {
|
|
@@ -216,7 +216,7 @@ class ExtensionManager {
|
|
|
216
216
|
logger.warn(`[RuntimeMigrator] Invalid extension name "${extension}" - contains invalid characters`);
|
|
217
217
|
continue;
|
|
218
218
|
}
|
|
219
|
-
await this.db.execute(
|
|
219
|
+
await this.db.execute(sql20`CREATE EXTENSION IF NOT EXISTS ${sql20.identifier(extension)}`);
|
|
220
220
|
logger.debug(`[RuntimeMigrator] Extension installed: ${extension}`);
|
|
221
221
|
} catch (error) {
|
|
222
222
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -1858,12 +1858,12 @@ function objectToString(o) {
|
|
|
1858
1858
|
function pad(n) {
|
|
1859
1859
|
return n < 10 ? "0" + n.toString(10) : n.toString(10);
|
|
1860
1860
|
}
|
|
1861
|
-
function
|
|
1861
|
+
function timestamp17() {
|
|
1862
1862
|
var d = new Date, time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(":");
|
|
1863
1863
|
return [d.getDate(), months[d.getMonth()], time].join(" ");
|
|
1864
1864
|
}
|
|
1865
1865
|
function log(...args) {
|
|
1866
|
-
console.log("%s - %s",
|
|
1866
|
+
console.log("%s - %s", timestamp17(), format.apply(null, args));
|
|
1867
1867
|
}
|
|
1868
1868
|
function inherits(ctor, superCtor) {
|
|
1869
1869
|
if (superCtor)
|
|
@@ -17863,8 +17863,8 @@ function hasChanges(previousSnapshot, currentSnapshot) {
|
|
|
17863
17863
|
const currHash = hashSnapshot(currentSnapshot);
|
|
17864
17864
|
return prevHash !== currHash;
|
|
17865
17865
|
}
|
|
17866
|
-
var sqlToStr = (
|
|
17867
|
-
return
|
|
17866
|
+
var sqlToStr = (sql21, casing) => {
|
|
17867
|
+
return sql21.toQuery({
|
|
17868
17868
|
escapeName: () => {
|
|
17869
17869
|
throw new Error("we don't support params for `sql` default values");
|
|
17870
17870
|
},
|
|
@@ -18502,18 +18502,18 @@ function generateCreateTableSQL(fullTableName, table) {
|
|
|
18502
18502
|
return { tableSQL, fkSQLs };
|
|
18503
18503
|
}
|
|
18504
18504
|
function generateColumnDefinition(name, def) {
|
|
18505
|
-
let
|
|
18505
|
+
let sql21 = `"${name}" ${def.type}`;
|
|
18506
18506
|
if (def.primaryKey && !def.type.includes("SERIAL")) {
|
|
18507
|
-
|
|
18507
|
+
sql21 += " PRIMARY KEY";
|
|
18508
18508
|
}
|
|
18509
18509
|
if (def.notNull) {
|
|
18510
|
-
|
|
18510
|
+
sql21 += " NOT NULL";
|
|
18511
18511
|
}
|
|
18512
18512
|
if (def.default !== undefined) {
|
|
18513
18513
|
const defaultValue = formatDefaultValue(def.default, def.type);
|
|
18514
|
-
|
|
18514
|
+
sql21 += ` DEFAULT ${defaultValue}`;
|
|
18515
18515
|
}
|
|
18516
|
-
return
|
|
18516
|
+
return sql21;
|
|
18517
18517
|
}
|
|
18518
18518
|
function generateAddColumnSQL(table, column, definition) {
|
|
18519
18519
|
const [schema, tableName] = table.includes(".") ? table.split(".") : ["public", table];
|
|
@@ -18669,14 +18669,14 @@ function generateCreateForeignKeySQL(fk) {
|
|
|
18669
18669
|
const tableFrom = fk.tableFrom;
|
|
18670
18670
|
const columnsFrom = fk.columnsFrom.map((c) => `"${c}"`).join(", ");
|
|
18671
18671
|
const columnsTo = fk.columnsTo.map((c) => `"${c}"`).join(", ");
|
|
18672
|
-
let
|
|
18672
|
+
let sql21 = `ALTER TABLE "${schemaFrom}"."${tableFrom}" ADD CONSTRAINT "${fk.name}" FOREIGN KEY (${columnsFrom}) REFERENCES "${schemaTo}"."${fk.tableTo}" (${columnsTo})`;
|
|
18673
18673
|
if (fk.onDelete) {
|
|
18674
|
-
|
|
18674
|
+
sql21 += ` ON DELETE ${fk.onDelete}`;
|
|
18675
18675
|
}
|
|
18676
18676
|
if (fk.onUpdate) {
|
|
18677
|
-
|
|
18677
|
+
sql21 += ` ON UPDATE ${fk.onUpdate}`;
|
|
18678
18678
|
}
|
|
18679
|
-
return
|
|
18679
|
+
return sql21 + ";";
|
|
18680
18680
|
}
|
|
18681
18681
|
function generateDropForeignKeySQL(fk) {
|
|
18682
18682
|
const [schema, tableName] = fk.tableFrom ? fk.tableFrom.includes(".") ? fk.tableFrom.split(".") : ["public", fk.tableFrom] : ["public", ""];
|
|
@@ -18687,12 +18687,12 @@ function generateCreateUniqueConstraintSQL(constraint) {
|
|
|
18687
18687
|
const [schema, tableName] = table.includes(".") ? table.split(".") : ["public", table];
|
|
18688
18688
|
const name = constraint.name;
|
|
18689
18689
|
const columns = constraint.columns.map((c) => `"${c}"`).join(", ");
|
|
18690
|
-
let
|
|
18690
|
+
let sql21 = `ALTER TABLE "${schema}"."${tableName}" ADD CONSTRAINT "${name}" UNIQUE`;
|
|
18691
18691
|
if (constraint.nullsNotDistinct) {
|
|
18692
|
-
|
|
18692
|
+
sql21 += ` NULLS NOT DISTINCT`;
|
|
18693
18693
|
}
|
|
18694
|
-
|
|
18695
|
-
return
|
|
18694
|
+
sql21 += ` (${columns});`;
|
|
18695
|
+
return sql21;
|
|
18696
18696
|
}
|
|
18697
18697
|
function generateDropUniqueConstraintSQL(constraint) {
|
|
18698
18698
|
const table = constraint.table || "";
|
|
@@ -18759,7 +18759,7 @@ function normalizeSchemaName(input) {
|
|
|
18759
18759
|
var init_schema_transformer = () => {};
|
|
18760
18760
|
|
|
18761
18761
|
// src/runtime-migrator/drizzle-adapters/database-introspector.ts
|
|
18762
|
-
import { sql as
|
|
18762
|
+
import { sql as sql21 } from "drizzle-orm";
|
|
18763
18763
|
import { logger as logger4 } from "@elizaos/core";
|
|
18764
18764
|
|
|
18765
18765
|
class DatabaseIntrospector {
|
|
@@ -18884,7 +18884,7 @@ class DatabaseIntrospector {
|
|
|
18884
18884
|
};
|
|
18885
18885
|
}
|
|
18886
18886
|
async getTables(schemaName) {
|
|
18887
|
-
const result = await this.db.execute(
|
|
18887
|
+
const result = await this.db.execute(sql21`SELECT
|
|
18888
18888
|
table_schema,
|
|
18889
18889
|
table_name
|
|
18890
18890
|
FROM information_schema.tables
|
|
@@ -18894,7 +18894,7 @@ class DatabaseIntrospector {
|
|
|
18894
18894
|
return result.rows;
|
|
18895
18895
|
}
|
|
18896
18896
|
async getColumns(schemaName, tableName) {
|
|
18897
|
-
const result = await this.db.execute(
|
|
18897
|
+
const result = await this.db.execute(sql21`SELECT
|
|
18898
18898
|
a.attname AS column_name,
|
|
18899
18899
|
CASE
|
|
18900
18900
|
WHEN a.attnotnull THEN 'NO'
|
|
@@ -18937,7 +18937,7 @@ class DatabaseIntrospector {
|
|
|
18937
18937
|
return result.rows;
|
|
18938
18938
|
}
|
|
18939
18939
|
async getIndexes(schemaName, tableName) {
|
|
18940
|
-
const result = await this.db.execute(
|
|
18940
|
+
const result = await this.db.execute(sql21`SELECT
|
|
18941
18941
|
i.relname AS name,
|
|
18942
18942
|
idx.indisunique AS is_unique,
|
|
18943
18943
|
idx.indisprimary AS is_primary,
|
|
@@ -18961,7 +18961,7 @@ class DatabaseIntrospector {
|
|
|
18961
18961
|
return result.rows;
|
|
18962
18962
|
}
|
|
18963
18963
|
async getForeignKeys(schemaName, tableName) {
|
|
18964
|
-
const result = await this.db.execute(
|
|
18964
|
+
const result = await this.db.execute(sql21`SELECT
|
|
18965
18965
|
con.conname AS name,
|
|
18966
18966
|
att.attname AS column_name,
|
|
18967
18967
|
fnsp.nspname AS foreign_table_schema,
|
|
@@ -18996,7 +18996,7 @@ class DatabaseIntrospector {
|
|
|
18996
18996
|
return result.rows;
|
|
18997
18997
|
}
|
|
18998
18998
|
async getPrimaryKeys(schemaName, tableName) {
|
|
18999
|
-
const result = await this.db.execute(
|
|
18999
|
+
const result = await this.db.execute(sql21`SELECT
|
|
19000
19000
|
con.conname AS name,
|
|
19001
19001
|
ARRAY(
|
|
19002
19002
|
SELECT a.attname
|
|
@@ -19014,7 +19014,7 @@ class DatabaseIntrospector {
|
|
|
19014
19014
|
return result.rows;
|
|
19015
19015
|
}
|
|
19016
19016
|
async getUniqueConstraints(schemaName, tableName) {
|
|
19017
|
-
const result = await this.db.execute(
|
|
19017
|
+
const result = await this.db.execute(sql21`SELECT
|
|
19018
19018
|
con.conname AS name,
|
|
19019
19019
|
ARRAY(
|
|
19020
19020
|
SELECT a.attname
|
|
@@ -19032,7 +19032,7 @@ class DatabaseIntrospector {
|
|
|
19032
19032
|
return result.rows;
|
|
19033
19033
|
}
|
|
19034
19034
|
async getCheckConstraints(schemaName, tableName) {
|
|
19035
|
-
const result = await this.db.execute(
|
|
19035
|
+
const result = await this.db.execute(sql21`SELECT
|
|
19036
19036
|
con.conname AS name,
|
|
19037
19037
|
pg_get_constraintdef(con.oid) AS definition
|
|
19038
19038
|
FROM pg_constraint con
|
|
@@ -19044,7 +19044,7 @@ class DatabaseIntrospector {
|
|
|
19044
19044
|
return result.rows;
|
|
19045
19045
|
}
|
|
19046
19046
|
async getEnums(schemaName) {
|
|
19047
|
-
const result = await this.db.execute(
|
|
19047
|
+
const result = await this.db.execute(sql21`SELECT
|
|
19048
19048
|
n.nspname AS schema,
|
|
19049
19049
|
t.typname AS name,
|
|
19050
19050
|
e.enumlabel AS value,
|
|
@@ -19076,7 +19076,7 @@ class DatabaseIntrospector {
|
|
|
19076
19076
|
}
|
|
19077
19077
|
async hasExistingTables(pluginName) {
|
|
19078
19078
|
const schemaName = pluginName === "@elizaos/plugin-sql" ? "public" : this.deriveSchemaName(pluginName);
|
|
19079
|
-
const result = await this.db.execute(
|
|
19079
|
+
const result = await this.db.execute(sql21`SELECT COUNT(*) AS count
|
|
19080
19080
|
FROM information_schema.tables
|
|
19081
19081
|
WHERE table_schema = ${schemaName}
|
|
19082
19082
|
AND table_type = 'BASE TABLE'`);
|
|
@@ -19090,7 +19090,7 @@ class DatabaseIntrospector {
|
|
|
19090
19090
|
var init_database_introspector = () => {};
|
|
19091
19091
|
|
|
19092
19092
|
// src/runtime-migrator/runtime-migrator.ts
|
|
19093
|
-
import { sql as
|
|
19093
|
+
import { sql as sql22 } from "drizzle-orm";
|
|
19094
19094
|
import { logger as logger5 } from "@elizaos/core";
|
|
19095
19095
|
|
|
19096
19096
|
class RuntimeMigrator {
|
|
@@ -19130,7 +19130,7 @@ class RuntimeMigrator {
|
|
|
19130
19130
|
}
|
|
19131
19131
|
for (const schemaName of schemasToCreate) {
|
|
19132
19132
|
logger5.debug(`[RuntimeMigrator] Ensuring schema '${schemaName}' exists`);
|
|
19133
|
-
await this.db.execute(
|
|
19133
|
+
await this.db.execute(sql22.raw(`CREATE SCHEMA IF NOT EXISTS "${schemaName}"`));
|
|
19134
19134
|
}
|
|
19135
19135
|
}
|
|
19136
19136
|
validateSchemaUsage(pluginName, snapshot) {
|
|
@@ -19377,11 +19377,11 @@ class RuntimeMigrator {
|
|
|
19377
19377
|
try {
|
|
19378
19378
|
logger5.debug(`[RuntimeMigrator] Using PostgreSQL advisory locks for ${pluginName}`);
|
|
19379
19379
|
const lockIdStr = lockId.toString();
|
|
19380
|
-
const lockResult = await this.db.execute(
|
|
19380
|
+
const lockResult = await this.db.execute(sql22`SELECT pg_try_advisory_lock(CAST(${lockIdStr} AS bigint)) as acquired`);
|
|
19381
19381
|
lockAcquired = lockResult.rows[0]?.acquired === true;
|
|
19382
19382
|
if (!lockAcquired) {
|
|
19383
19383
|
logger5.info(`[RuntimeMigrator] Migration already in progress for ${pluginName}, waiting for lock...`);
|
|
19384
|
-
await this.db.execute(
|
|
19384
|
+
await this.db.execute(sql22`SELECT pg_advisory_lock(CAST(${lockIdStr} AS bigint))`);
|
|
19385
19385
|
lockAcquired = true;
|
|
19386
19386
|
logger5.info(`[RuntimeMigrator] Lock acquired for ${pluginName}`);
|
|
19387
19387
|
} else {
|
|
@@ -19499,7 +19499,7 @@ class RuntimeMigrator {
|
|
|
19499
19499
|
if (lockAcquired && isRealPostgres) {
|
|
19500
19500
|
try {
|
|
19501
19501
|
const lockIdStr = lockId.toString();
|
|
19502
|
-
await this.db.execute(
|
|
19502
|
+
await this.db.execute(sql22`SELECT pg_advisory_unlock(CAST(${lockIdStr} AS bigint))`);
|
|
19503
19503
|
logger5.debug(`[RuntimeMigrator] Advisory lock released for ${pluginName}`);
|
|
19504
19504
|
} catch (unlockError) {
|
|
19505
19505
|
logger5.warn(`[RuntimeMigrator] Failed to release advisory lock for ${pluginName}:`, JSON.stringify(unlockError));
|
|
@@ -19510,23 +19510,23 @@ class RuntimeMigrator {
|
|
|
19510
19510
|
async executeMigration(pluginName, snapshot, hash, sqlStatements) {
|
|
19511
19511
|
let transactionStarted = false;
|
|
19512
19512
|
try {
|
|
19513
|
-
await this.db.execute(
|
|
19513
|
+
await this.db.execute(sql22`BEGIN`);
|
|
19514
19514
|
transactionStarted = true;
|
|
19515
19515
|
for (const stmt of sqlStatements) {
|
|
19516
19516
|
logger5.debug(`[RuntimeMigrator] Executing: ${stmt}`);
|
|
19517
|
-
await this.db.execute(
|
|
19517
|
+
await this.db.execute(sql22.raw(stmt));
|
|
19518
19518
|
}
|
|
19519
19519
|
const idx = await this.journalStorage.getNextIdx(pluginName);
|
|
19520
19520
|
await this.migrationTracker.recordMigration(pluginName, hash, Date.now());
|
|
19521
19521
|
const tag = this.generateMigrationTag(idx, pluginName);
|
|
19522
19522
|
await this.journalStorage.updateJournal(pluginName, idx, tag, true);
|
|
19523
19523
|
await this.snapshotStorage.saveSnapshot(pluginName, idx, snapshot);
|
|
19524
|
-
await this.db.execute(
|
|
19524
|
+
await this.db.execute(sql22`COMMIT`);
|
|
19525
19525
|
logger5.info(`[RuntimeMigrator] Recorded migration ${tag} for ${pluginName}`);
|
|
19526
19526
|
} catch (error) {
|
|
19527
19527
|
if (transactionStarted) {
|
|
19528
19528
|
try {
|
|
19529
|
-
await this.db.execute(
|
|
19529
|
+
await this.db.execute(sql22`ROLLBACK`);
|
|
19530
19530
|
logger5.error("[RuntimeMigrator] Migration failed, rolled back:", JSON.stringify(error));
|
|
19531
19531
|
} catch (rollbackError) {
|
|
19532
19532
|
logger5.error("[RuntimeMigrator] Failed to rollback transaction:", JSON.stringify(rollbackError));
|
|
@@ -19537,8 +19537,8 @@ class RuntimeMigrator {
|
|
|
19537
19537
|
}
|
|
19538
19538
|
generateMigrationTag(idx, pluginName) {
|
|
19539
19539
|
const prefix = idx.toString().padStart(4, "0");
|
|
19540
|
-
const
|
|
19541
|
-
return `${prefix}_${pluginName}_${
|
|
19540
|
+
const timestamp18 = Date.now().toString(36);
|
|
19541
|
+
return `${prefix}_${pluginName}_${timestamp18}`;
|
|
19542
19542
|
}
|
|
19543
19543
|
async getStatus(pluginName) {
|
|
19544
19544
|
const lastMigration = await this.migrationTracker.getLastMigration(pluginName);
|
|
@@ -19553,9 +19553,9 @@ class RuntimeMigrator {
|
|
|
19553
19553
|
}
|
|
19554
19554
|
async reset(pluginName) {
|
|
19555
19555
|
logger5.warn(`[RuntimeMigrator] Resetting migrations for ${pluginName}`);
|
|
19556
|
-
await this.db.execute(
|
|
19557
|
-
await this.db.execute(
|
|
19558
|
-
await this.db.execute(
|
|
19556
|
+
await this.db.execute(sql22`DELETE FROM migrations._migrations WHERE plugin_name = ${pluginName}`);
|
|
19557
|
+
await this.db.execute(sql22`DELETE FROM migrations._journal WHERE plugin_name = ${pluginName}`);
|
|
19558
|
+
await this.db.execute(sql22`DELETE FROM migrations._snapshots WHERE plugin_name = ${pluginName}`);
|
|
19559
19559
|
logger5.warn(`[RuntimeMigrator] Reset complete for ${pluginName}`);
|
|
19560
19560
|
}
|
|
19561
19561
|
async checkMigration(pluginName, schema) {
|
|
@@ -19713,7 +19713,7 @@ import {
|
|
|
19713
19713
|
lt,
|
|
19714
19714
|
lte,
|
|
19715
19715
|
or,
|
|
19716
|
-
sql as
|
|
19716
|
+
sql as sql23
|
|
19717
19717
|
} from "drizzle-orm";
|
|
19718
19718
|
|
|
19719
19719
|
// node_modules/uuid/dist/esm-browser/stringify.js
|
|
@@ -19792,6 +19792,7 @@ import { boolean, jsonb, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-c
|
|
|
19792
19792
|
var agentTable = pgTable("agents", {
|
|
19793
19793
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
19794
19794
|
enabled: boolean("enabled").default(true).notNull(),
|
|
19795
|
+
owner_id: uuid("owner_id"),
|
|
19795
19796
|
createdAt: timestamp("created_at", { withTimezone: true }).default(sql`now()`).notNull(),
|
|
19796
19797
|
updatedAt: timestamp("updated_at", { withTimezone: true }).default(sql`now()`).notNull(),
|
|
19797
19798
|
name: text("name").notNull(),
|
|
@@ -19940,6 +19941,7 @@ __export(exports_schema, {
|
|
|
19940
19941
|
roomTable: () => roomTable,
|
|
19941
19942
|
relationshipTable: () => relationshipTable,
|
|
19942
19943
|
participantTable: () => participantTable,
|
|
19944
|
+
ownersTable: () => ownersTable,
|
|
19943
19945
|
messageTable: () => messageTable,
|
|
19944
19946
|
messageServerTable: () => messageServerTable,
|
|
19945
19947
|
memoryTable: () => memoryTable,
|
|
@@ -20015,19 +20017,27 @@ var logTable = pgTable9("logs", {
|
|
|
20015
20017
|
foreignColumns: [entityTable.id]
|
|
20016
20018
|
}).onDelete("cascade")
|
|
20017
20019
|
]);
|
|
20018
|
-
// src/schema/
|
|
20020
|
+
// src/schema/owners.ts
|
|
20019
20021
|
import { sql as sql10 } from "drizzle-orm";
|
|
20020
|
-
import {
|
|
20021
|
-
var
|
|
20022
|
-
id: uuid10("id").
|
|
20022
|
+
import { pgTable as pgTable10, timestamp as timestamp10, uuid as uuid10 } from "drizzle-orm/pg-core";
|
|
20023
|
+
var ownersTable = pgTable10("owners", {
|
|
20024
|
+
id: uuid10("id").primaryKey(),
|
|
20023
20025
|
createdAt: timestamp10("created_at", { withTimezone: true }).default(sql10`now()`).notNull(),
|
|
20024
|
-
|
|
20026
|
+
updatedAt: timestamp10("updated_at", { withTimezone: true }).default(sql10`now()`).notNull()
|
|
20027
|
+
});
|
|
20028
|
+
// src/schema/participant.ts
|
|
20029
|
+
import { sql as sql11 } from "drizzle-orm";
|
|
20030
|
+
import { foreignKey as foreignKey4, index as index3, pgTable as pgTable11, text as text9, timestamp as timestamp11, uuid as uuid11 } from "drizzle-orm/pg-core";
|
|
20031
|
+
var participantTable = pgTable11("participants", {
|
|
20032
|
+
id: uuid11("id").notNull().primaryKey().default(sql11`gen_random_uuid()`),
|
|
20033
|
+
createdAt: timestamp11("created_at", { withTimezone: true }).default(sql11`now()`).notNull(),
|
|
20034
|
+
entityId: uuid11("entityId").references(() => entityTable.id, {
|
|
20025
20035
|
onDelete: "cascade"
|
|
20026
20036
|
}),
|
|
20027
|
-
roomId:
|
|
20037
|
+
roomId: uuid11("roomId").references(() => roomTable.id, {
|
|
20028
20038
|
onDelete: "cascade"
|
|
20029
20039
|
}),
|
|
20030
|
-
agentId:
|
|
20040
|
+
agentId: uuid11("agentId").references(() => agentTable.id, {
|
|
20031
20041
|
onDelete: "cascade"
|
|
20032
20042
|
}),
|
|
20033
20043
|
roomState: text9("roomState")
|
|
@@ -20046,23 +20056,23 @@ var participantTable = pgTable10("participants", {
|
|
|
20046
20056
|
}).onDelete("cascade")
|
|
20047
20057
|
]);
|
|
20048
20058
|
// src/schema/relationship.ts
|
|
20049
|
-
import { sql as
|
|
20059
|
+
import { sql as sql12 } from "drizzle-orm";
|
|
20050
20060
|
import {
|
|
20051
20061
|
foreignKey as foreignKey5,
|
|
20052
20062
|
index as index4,
|
|
20053
20063
|
jsonb as jsonb9,
|
|
20054
|
-
pgTable as
|
|
20064
|
+
pgTable as pgTable12,
|
|
20055
20065
|
text as text10,
|
|
20056
|
-
timestamp as
|
|
20066
|
+
timestamp as timestamp12,
|
|
20057
20067
|
unique as unique2,
|
|
20058
|
-
uuid as
|
|
20068
|
+
uuid as uuid12
|
|
20059
20069
|
} from "drizzle-orm/pg-core";
|
|
20060
|
-
var relationshipTable =
|
|
20061
|
-
id:
|
|
20062
|
-
createdAt:
|
|
20063
|
-
sourceEntityId:
|
|
20064
|
-
targetEntityId:
|
|
20065
|
-
agentId:
|
|
20070
|
+
var relationshipTable = pgTable12("relationships", {
|
|
20071
|
+
id: uuid12("id").notNull().primaryKey().default(sql12`gen_random_uuid()`),
|
|
20072
|
+
createdAt: timestamp12("created_at", { withTimezone: true }).default(sql12`now()`).notNull(),
|
|
20073
|
+
sourceEntityId: uuid12("sourceEntityId").notNull().references(() => entityTable.id, { onDelete: "cascade" }),
|
|
20074
|
+
targetEntityId: uuid12("targetEntityId").notNull().references(() => entityTable.id, { onDelete: "cascade" }),
|
|
20075
|
+
agentId: uuid12("agentId").notNull().references(() => agentTable.id, { onDelete: "cascade" }),
|
|
20066
20076
|
tags: text10("tags").array(),
|
|
20067
20077
|
metadata: jsonb9("metadata")
|
|
20068
20078
|
}, (table) => [
|
|
@@ -20080,52 +20090,52 @@ var relationshipTable = pgTable11("relationships", {
|
|
|
20080
20090
|
}).onDelete("cascade")
|
|
20081
20091
|
]);
|
|
20082
20092
|
// src/schema/tasks.ts
|
|
20083
|
-
import { jsonb as jsonb10, pgTable as
|
|
20084
|
-
import { sql as
|
|
20085
|
-
var taskTable =
|
|
20086
|
-
id:
|
|
20093
|
+
import { jsonb as jsonb10, pgTable as pgTable13, text as text11, timestamp as timestamp13, uuid as uuid13 } from "drizzle-orm/pg-core";
|
|
20094
|
+
import { sql as sql13 } from "drizzle-orm";
|
|
20095
|
+
var taskTable = pgTable13("tasks", {
|
|
20096
|
+
id: uuid13("id").primaryKey().defaultRandom(),
|
|
20087
20097
|
name: text11("name").notNull(),
|
|
20088
20098
|
description: text11("description"),
|
|
20089
|
-
roomId:
|
|
20090
|
-
worldId:
|
|
20091
|
-
entityId:
|
|
20092
|
-
agentId:
|
|
20093
|
-
tags: text11("tags").array().default(
|
|
20094
|
-
metadata: jsonb10("metadata").default(
|
|
20095
|
-
createdAt:
|
|
20096
|
-
updatedAt:
|
|
20099
|
+
roomId: uuid13("roomId"),
|
|
20100
|
+
worldId: uuid13("worldId"),
|
|
20101
|
+
entityId: uuid13("entityId"),
|
|
20102
|
+
agentId: uuid13("agent_id").notNull().references(() => agentTable.id, { onDelete: "cascade" }),
|
|
20103
|
+
tags: text11("tags").array().default(sql13`'{}'::text[]`),
|
|
20104
|
+
metadata: jsonb10("metadata").default(sql13`'{}'::jsonb`),
|
|
20105
|
+
createdAt: timestamp13("created_at", { withTimezone: true }).defaultNow(),
|
|
20106
|
+
updatedAt: timestamp13("updated_at", { withTimezone: true }).defaultNow()
|
|
20097
20107
|
});
|
|
20098
20108
|
// src/schema/messageServer.ts
|
|
20099
|
-
import { pgTable as
|
|
20100
|
-
import { sql as
|
|
20101
|
-
var messageServerTable =
|
|
20102
|
-
id:
|
|
20109
|
+
import { pgTable as pgTable14, text as text12, jsonb as jsonb11, timestamp as timestamp14, uuid as uuid14 } from "drizzle-orm/pg-core";
|
|
20110
|
+
import { sql as sql14 } from "drizzle-orm";
|
|
20111
|
+
var messageServerTable = pgTable14("message_servers", {
|
|
20112
|
+
id: uuid14("id").primaryKey(),
|
|
20103
20113
|
name: text12("name").notNull(),
|
|
20104
20114
|
sourceType: text12("source_type").notNull(),
|
|
20105
20115
|
sourceId: text12("source_id"),
|
|
20106
20116
|
metadata: jsonb11("metadata"),
|
|
20107
|
-
createdAt:
|
|
20108
|
-
updatedAt:
|
|
20117
|
+
createdAt: timestamp14("created_at", { mode: "date" }).default(sql14`CURRENT_TIMESTAMP`).notNull(),
|
|
20118
|
+
updatedAt: timestamp14("updated_at", { mode: "date" }).default(sql14`CURRENT_TIMESTAMP`).notNull()
|
|
20109
20119
|
});
|
|
20110
20120
|
// src/schema/channel.ts
|
|
20111
|
-
import { pgTable as
|
|
20112
|
-
import { sql as
|
|
20113
|
-
var channelTable =
|
|
20121
|
+
import { pgTable as pgTable15, text as text13, jsonb as jsonb12, timestamp as timestamp15, uuid as uuid15 } from "drizzle-orm/pg-core";
|
|
20122
|
+
import { sql as sql15 } from "drizzle-orm";
|
|
20123
|
+
var channelTable = pgTable15("channels", {
|
|
20114
20124
|
id: text13("id").primaryKey(),
|
|
20115
|
-
messageServerId:
|
|
20125
|
+
messageServerId: uuid15("server_id").notNull().references(() => messageServerTable.id, { onDelete: "cascade" }),
|
|
20116
20126
|
name: text13("name").notNull(),
|
|
20117
20127
|
type: text13("type").notNull(),
|
|
20118
20128
|
sourceType: text13("source_type"),
|
|
20119
20129
|
sourceId: text13("source_id"),
|
|
20120
20130
|
topic: text13("topic"),
|
|
20121
20131
|
metadata: jsonb12("metadata"),
|
|
20122
|
-
createdAt:
|
|
20123
|
-
updatedAt:
|
|
20132
|
+
createdAt: timestamp15("created_at", { mode: "date" }).default(sql15`CURRENT_TIMESTAMP`).notNull(),
|
|
20133
|
+
updatedAt: timestamp15("updated_at", { mode: "date" }).default(sql15`CURRENT_TIMESTAMP`).notNull()
|
|
20124
20134
|
});
|
|
20125
20135
|
// src/schema/message.ts
|
|
20126
|
-
import { pgTable as
|
|
20127
|
-
import { sql as
|
|
20128
|
-
var messageTable =
|
|
20136
|
+
import { pgTable as pgTable16, text as text14, jsonb as jsonb13, timestamp as timestamp16 } from "drizzle-orm/pg-core";
|
|
20137
|
+
import { sql as sql16 } from "drizzle-orm";
|
|
20138
|
+
var messageTable = pgTable16("central_messages", {
|
|
20129
20139
|
id: text14("id").primaryKey(),
|
|
20130
20140
|
channelId: text14("channel_id").notNull().references(() => channelTable.id, { onDelete: "cascade" }),
|
|
20131
20141
|
authorId: text14("author_id").notNull(),
|
|
@@ -20137,22 +20147,22 @@ var messageTable = pgTable15("central_messages", {
|
|
|
20137
20147
|
sourceType: text14("source_type"),
|
|
20138
20148
|
sourceId: text14("source_id"),
|
|
20139
20149
|
metadata: jsonb13("metadata"),
|
|
20140
|
-
createdAt:
|
|
20141
|
-
updatedAt:
|
|
20150
|
+
createdAt: timestamp16("created_at", { mode: "date" }).default(sql16`CURRENT_TIMESTAMP`).notNull(),
|
|
20151
|
+
updatedAt: timestamp16("updated_at", { mode: "date" }).default(sql16`CURRENT_TIMESTAMP`).notNull()
|
|
20142
20152
|
});
|
|
20143
20153
|
// src/schema/channelParticipant.ts
|
|
20144
|
-
import { pgTable as
|
|
20145
|
-
var channelParticipantsTable =
|
|
20154
|
+
import { pgTable as pgTable17, text as text15, primaryKey as primaryKey2 } from "drizzle-orm/pg-core";
|
|
20155
|
+
var channelParticipantsTable = pgTable17("channel_participants", {
|
|
20146
20156
|
channelId: text15("channel_id").notNull().references(() => channelTable.id, { onDelete: "cascade" }),
|
|
20147
20157
|
userId: text15("user_id").notNull()
|
|
20148
20158
|
}, (table) => ({
|
|
20149
20159
|
pk: primaryKey2({ columns: [table.channelId, table.userId] })
|
|
20150
20160
|
}));
|
|
20151
20161
|
// src/schema/serverAgent.ts
|
|
20152
|
-
import { pgTable as
|
|
20153
|
-
var serverAgentsTable =
|
|
20154
|
-
serverId:
|
|
20155
|
-
agentId:
|
|
20162
|
+
import { pgTable as pgTable18, uuid as uuid16, primaryKey as primaryKey3 } from "drizzle-orm/pg-core";
|
|
20163
|
+
var serverAgentsTable = pgTable18("server_agents", {
|
|
20164
|
+
serverId: uuid16("server_id").notNull().references(() => messageServerTable.id, { onDelete: "cascade" }),
|
|
20165
|
+
agentId: uuid16("agent_id").notNull().references(() => agentTable.id, { onDelete: "cascade" })
|
|
20156
20166
|
}, (table) => ({
|
|
20157
20167
|
pk: primaryKey3({ columns: [table.serverId, table.agentId] })
|
|
20158
20168
|
}));
|
|
@@ -20507,11 +20517,11 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
20507
20517
|
async getEntitiesByNames(params) {
|
|
20508
20518
|
return this.withDatabase(async () => {
|
|
20509
20519
|
const { names, agentId } = params;
|
|
20510
|
-
const nameConditions = names.map((name) =>
|
|
20511
|
-
const query =
|
|
20520
|
+
const nameConditions = names.map((name) => sql23`${name} = ANY(${entityTable.names})`);
|
|
20521
|
+
const query = sql23`
|
|
20512
20522
|
SELECT * FROM ${entityTable}
|
|
20513
20523
|
WHERE ${entityTable.agentId} = ${agentId}
|
|
20514
|
-
AND (${
|
|
20524
|
+
AND (${sql23.join(nameConditions, sql23` OR `)})
|
|
20515
20525
|
`;
|
|
20516
20526
|
const result = await this.db.execute(query);
|
|
20517
20527
|
return result.rows.map((row) => ({
|
|
@@ -20534,7 +20544,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
20534
20544
|
metadata: row.metadata || {}
|
|
20535
20545
|
}));
|
|
20536
20546
|
}
|
|
20537
|
-
const searchQuery =
|
|
20547
|
+
const searchQuery = sql23`
|
|
20538
20548
|
SELECT * FROM ${entityTable}
|
|
20539
20549
|
WHERE ${entityTable.agentId} = ${agentId}
|
|
20540
20550
|
AND EXISTS (
|
|
@@ -20792,7 +20802,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
20792
20802
|
async getCachedEmbeddings(opts) {
|
|
20793
20803
|
return this.withDatabase(async () => {
|
|
20794
20804
|
try {
|
|
20795
|
-
const results = await this.db.execute(
|
|
20805
|
+
const results = await this.db.execute(sql23`
|
|
20796
20806
|
WITH content_text AS (
|
|
20797
20807
|
SELECT
|
|
20798
20808
|
m.id,
|
|
@@ -20847,7 +20857,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
20847
20857
|
const jsonString = JSON.stringify(sanitizedBody);
|
|
20848
20858
|
await this.db.transaction(async (tx) => {
|
|
20849
20859
|
await tx.insert(logTable).values({
|
|
20850
|
-
body:
|
|
20860
|
+
body: sql23`${jsonString}::jsonb`,
|
|
20851
20861
|
entityId: params.entityId,
|
|
20852
20862
|
roomId: params.roomId,
|
|
20853
20863
|
type: params.type
|
|
@@ -20910,7 +20920,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
20910
20920
|
const runMap = new Map;
|
|
20911
20921
|
const conditions = [
|
|
20912
20922
|
eq(logTable.type, "run_event"),
|
|
20913
|
-
|
|
20923
|
+
sql23`${logTable.body} ? 'runId'`,
|
|
20914
20924
|
eq(roomTable.agentId, this.agentId)
|
|
20915
20925
|
];
|
|
20916
20926
|
if (params.roomId) {
|
|
@@ -20925,9 +20935,9 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
20925
20935
|
const whereClause = and(...conditions);
|
|
20926
20936
|
const eventLimit = Math.max(limit * 20, 200);
|
|
20927
20937
|
const runEventRows = await this.db.select({
|
|
20928
|
-
runId:
|
|
20929
|
-
status:
|
|
20930
|
-
messageId:
|
|
20938
|
+
runId: sql23`(${logTable.body} ->> 'runId')`,
|
|
20939
|
+
status: sql23`(${logTable.body} ->> 'status')`,
|
|
20940
|
+
messageId: sql23`(${logTable.body} ->> 'messageId')`,
|
|
20931
20941
|
rawBody: logTable.body,
|
|
20932
20942
|
createdAt: logTable.createdAt,
|
|
20933
20943
|
roomId: logTable.roomId,
|
|
@@ -20974,15 +20984,15 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
20974
20984
|
}
|
|
20975
20985
|
}
|
|
20976
20986
|
const createdAt = row.createdAt instanceof Date ? row.createdAt : new Date(row.createdAt);
|
|
20977
|
-
const
|
|
20987
|
+
const timestamp18 = createdAt.getTime();
|
|
20978
20988
|
const eventStatus = row.status ?? body?.status;
|
|
20979
20989
|
if (eventStatus === "started") {
|
|
20980
|
-
summary.startedAt = summary.startedAt === null ?
|
|
20990
|
+
summary.startedAt = summary.startedAt === null ? timestamp18 : Math.min(summary.startedAt, timestamp18);
|
|
20981
20991
|
} else if (eventStatus === "completed" || eventStatus === "timeout" || eventStatus === "error") {
|
|
20982
20992
|
summary.status = eventStatus;
|
|
20983
|
-
summary.endedAt =
|
|
20993
|
+
summary.endedAt = timestamp18;
|
|
20984
20994
|
if (summary.startedAt !== null) {
|
|
20985
|
-
summary.durationMs = Math.max(
|
|
20995
|
+
summary.durationMs = Math.max(timestamp18 - summary.startedAt, 0);
|
|
20986
20996
|
}
|
|
20987
20997
|
}
|
|
20988
20998
|
runMap.set(runId, summary);
|
|
@@ -21001,8 +21011,8 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
21001
21011
|
}
|
|
21002
21012
|
const runIds = limitedRuns.map((run) => run.runId).filter(Boolean);
|
|
21003
21013
|
if (runIds.length > 0) {
|
|
21004
|
-
const runIdArray =
|
|
21005
|
-
const actionSummary = await this.db.execute(
|
|
21014
|
+
const runIdArray = sql23`array[${sql23.join(runIds.map((id) => sql23`${id}`), sql23`, `)}]::text[]`;
|
|
21015
|
+
const actionSummary = await this.db.execute(sql23`
|
|
21006
21016
|
SELECT
|
|
21007
21017
|
body->>'runId' as "runId",
|
|
21008
21018
|
COUNT(*)::int as "actions",
|
|
@@ -21022,7 +21032,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
21022
21032
|
counts.errors += Number(row.errors ?? 0);
|
|
21023
21033
|
counts.modelCalls += Number(row.modelCalls ?? 0);
|
|
21024
21034
|
}
|
|
21025
|
-
const evaluatorSummary = await this.db.execute(
|
|
21035
|
+
const evaluatorSummary = await this.db.execute(sql23`
|
|
21026
21036
|
SELECT
|
|
21027
21037
|
body->>'runId' as "runId",
|
|
21028
21038
|
COUNT(*)::int as "evaluators"
|
|
@@ -21038,7 +21048,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
21038
21048
|
continue;
|
|
21039
21049
|
counts.evaluators += Number(row.evaluators ?? 0);
|
|
21040
21050
|
}
|
|
21041
|
-
const genericSummary = await this.db.execute(
|
|
21051
|
+
const genericSummary = await this.db.execute(sql23`
|
|
21042
21052
|
SELECT
|
|
21043
21053
|
body->>'runId' as "runId",
|
|
21044
21054
|
COUNT(*) FILTER (WHERE type LIKE 'useModel:%')::int as "modelLogs",
|
|
@@ -21091,7 +21101,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
21091
21101
|
async searchMemoriesByEmbedding(embedding, params) {
|
|
21092
21102
|
return this.withDatabase(async () => {
|
|
21093
21103
|
const cleanVector = embedding.map((n) => Number.isFinite(n) ? Number(n.toFixed(6)) : 0);
|
|
21094
|
-
const similarity =
|
|
21104
|
+
const similarity = sql23`1 - (${cosineDistance(embeddingTable[this.embeddingDimension], cleanVector)})`;
|
|
21095
21105
|
const conditions = [eq(memoryTable.type, params.tableName)];
|
|
21096
21106
|
if (params.unique) {
|
|
21097
21107
|
conditions.push(eq(memoryTable.unique, true));
|
|
@@ -21159,8 +21169,8 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
21159
21169
|
{
|
|
21160
21170
|
id: memoryId,
|
|
21161
21171
|
type: tableName,
|
|
21162
|
-
content:
|
|
21163
|
-
metadata:
|
|
21172
|
+
content: sql23`${contentToInsert}::jsonb`,
|
|
21173
|
+
metadata: sql23`${metadataToInsert}::jsonb`,
|
|
21164
21174
|
entityId: memory.entityId,
|
|
21165
21175
|
roomId: memory.roomId,
|
|
21166
21176
|
worldId: memory.worldId,
|
|
@@ -21191,13 +21201,13 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
21191
21201
|
const contentToUpdate = typeof memory.content === "string" ? memory.content : JSON.stringify(memory.content ?? {});
|
|
21192
21202
|
const metadataToUpdate = typeof memory.metadata === "string" ? memory.metadata : JSON.stringify(memory.metadata ?? {});
|
|
21193
21203
|
await tx.update(memoryTable).set({
|
|
21194
|
-
content:
|
|
21195
|
-
...memory.metadata && { metadata:
|
|
21204
|
+
content: sql23`${contentToUpdate}::jsonb`,
|
|
21205
|
+
...memory.metadata && { metadata: sql23`${metadataToUpdate}::jsonb` }
|
|
21196
21206
|
}).where(eq(memoryTable.id, memory.id));
|
|
21197
21207
|
} else if (memory.metadata) {
|
|
21198
21208
|
const metadataToUpdate = typeof memory.metadata === "string" ? memory.metadata : JSON.stringify(memory.metadata ?? {});
|
|
21199
21209
|
await tx.update(memoryTable).set({
|
|
21200
|
-
metadata:
|
|
21210
|
+
metadata: sql23`${metadataToUpdate}::jsonb`
|
|
21201
21211
|
}).where(eq(memoryTable.id, memory.id));
|
|
21202
21212
|
}
|
|
21203
21213
|
if (memory.embedding && Array.isArray(memory.embedding)) {
|
|
@@ -21264,7 +21274,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
21264
21274
|
}
|
|
21265
21275
|
}
|
|
21266
21276
|
async getMemoryFragments(tx, documentId) {
|
|
21267
|
-
const fragments = await tx.select({ id: memoryTable.id }).from(memoryTable).where(and(eq(memoryTable.agentId, this.agentId),
|
|
21277
|
+
const fragments = await tx.select({ id: memoryTable.id }).from(memoryTable).where(and(eq(memoryTable.agentId, this.agentId), sql23`${memoryTable.metadata}->>'documentId' = ${documentId}`));
|
|
21268
21278
|
return fragments.map((f) => ({ id: f.id }));
|
|
21269
21279
|
}
|
|
21270
21280
|
async deleteAllMemories(roomId, tableName) {
|
|
@@ -21293,7 +21303,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
21293
21303
|
if (unique3) {
|
|
21294
21304
|
conditions.push(eq(memoryTable.unique, true));
|
|
21295
21305
|
}
|
|
21296
|
-
const result = await this.db.select({ count:
|
|
21306
|
+
const result = await this.db.select({ count: sql23`count(*)` }).from(memoryTable).where(and(...conditions));
|
|
21297
21307
|
return Number(result[0]?.count ?? 0);
|
|
21298
21308
|
});
|
|
21299
21309
|
}
|
|
@@ -21524,13 +21534,13 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
21524
21534
|
const { entityId, tags } = params;
|
|
21525
21535
|
let query;
|
|
21526
21536
|
if (tags && tags.length > 0) {
|
|
21527
|
-
query =
|
|
21537
|
+
query = sql23`
|
|
21528
21538
|
SELECT * FROM ${relationshipTable}
|
|
21529
21539
|
WHERE (${relationshipTable.sourceEntityId} = ${entityId} OR ${relationshipTable.targetEntityId} = ${entityId})
|
|
21530
|
-
AND ${relationshipTable.tags} && CAST(ARRAY[${
|
|
21540
|
+
AND ${relationshipTable.tags} && CAST(ARRAY[${sql23.join(tags, sql23`, `)}] AS text[])
|
|
21531
21541
|
`;
|
|
21532
21542
|
} else {
|
|
21533
|
-
query =
|
|
21543
|
+
query = sql23`
|
|
21534
21544
|
SELECT * FROM ${relationshipTable}
|
|
21535
21545
|
WHERE ${relationshipTable.sourceEntityId} = ${entityId} OR ${relationshipTable.targetEntityId} = ${entityId}
|
|
21536
21546
|
`;
|
|
@@ -21657,7 +21667,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
21657
21667
|
return this.withRetry(async () => {
|
|
21658
21668
|
return this.withDatabase(async () => {
|
|
21659
21669
|
const result = await this.db.select().from(taskTable).where(and(eq(taskTable.agentId, this.agentId), ...params.roomId ? [eq(taskTable.roomId, params.roomId)] : [], ...params.tags && params.tags.length > 0 ? [
|
|
21660
|
-
|
|
21670
|
+
sql23`${taskTable.tags} @> ARRAY[${sql23.raw(params.tags.map((t) => `'${t.replace(/'/g, "''")}'`).join(", "))}]::text[]`
|
|
21661
21671
|
] : []));
|
|
21662
21672
|
return result.map((row) => ({
|
|
21663
21673
|
id: row.id,
|
|
@@ -22206,5 +22216,5 @@ export {
|
|
|
22206
22216
|
DatabaseMigrationService
|
|
22207
22217
|
};
|
|
22208
22218
|
|
|
22209
|
-
//# debugId=
|
|
22219
|
+
//# debugId=25A9605A86B0D67E64756E2164756E21
|
|
22210
22220
|
//# sourceMappingURL=index.browser.js.map
|