@elizaos/plugin-sql 1.7.3-alpha.3 → 1.7.3-alpha.4

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.
@@ -61,6 +61,246 @@ var init_agent = __esm(() => {
61
61
  });
62
62
  });
63
63
 
64
+ // src/schema/entity.ts
65
+ import { sql as sql2 } from "drizzle-orm";
66
+ import { jsonb as jsonb2, pgTable as pgTable2, text as text2, timestamp as timestamp2, unique, uuid as uuid2 } from "drizzle-orm/pg-core";
67
+ var entityTable;
68
+ var init_entity = __esm(() => {
69
+ init_agent();
70
+ entityTable = pgTable2("entities", {
71
+ id: uuid2("id").notNull().primaryKey(),
72
+ agentId: uuid2("agent_id").notNull().references(() => agentTable.id, {
73
+ onDelete: "cascade"
74
+ }),
75
+ createdAt: timestamp2("created_at").default(sql2`now()`).notNull(),
76
+ names: text2("names").array().default(sql2`'{}'::text[]`).notNull(),
77
+ metadata: jsonb2("metadata").$type().default(sql2`'{}'::jsonb`).notNull()
78
+ }, (table) => {
79
+ return {
80
+ idAgentIdUnique: unique("id_agent_id_unique").on(table.id, table.agentId)
81
+ };
82
+ });
83
+ });
84
+
85
+ // src/schema/room.ts
86
+ import { sql as sql3 } from "drizzle-orm";
87
+ import { jsonb as jsonb3, pgTable as pgTable3, text as text3, timestamp as timestamp3, uuid as uuid3 } from "drizzle-orm/pg-core";
88
+ var roomTable;
89
+ var init_room = __esm(() => {
90
+ init_agent();
91
+ roomTable = pgTable3("rooms", {
92
+ id: uuid3("id").notNull().primaryKey().default(sql3`gen_random_uuid()`),
93
+ agentId: uuid3("agent_id").references(() => agentTable.id, {
94
+ onDelete: "cascade"
95
+ }),
96
+ source: text3("source").notNull(),
97
+ type: text3("type").notNull(),
98
+ messageServerId: uuid3("message_server_id"),
99
+ worldId: uuid3("world_id"),
100
+ name: text3("name"),
101
+ metadata: jsonb3("metadata").$type(),
102
+ channelId: text3("channel_id"),
103
+ createdAt: timestamp3("created_at").default(sql3`now()`).notNull()
104
+ });
105
+ });
106
+
107
+ // src/schema/memory.ts
108
+ import { relations, sql as sql4 } from "drizzle-orm";
109
+ import {
110
+ boolean as boolean2,
111
+ check,
112
+ foreignKey,
113
+ index,
114
+ jsonb as jsonb4,
115
+ pgTable as pgTable4,
116
+ text as text4,
117
+ timestamp as timestamp4,
118
+ uuid as uuid4
119
+ } from "drizzle-orm/pg-core";
120
+ var memoryTable, memoryRelations;
121
+ var init_memory = __esm(() => {
122
+ init_agent();
123
+ init_embedding();
124
+ init_entity();
125
+ init_room();
126
+ memoryTable = pgTable4("memories", {
127
+ id: uuid4("id").primaryKey().notNull(),
128
+ type: text4("type").notNull(),
129
+ createdAt: timestamp4("created_at").default(sql4`now()`).notNull(),
130
+ content: jsonb4("content").$type().notNull(),
131
+ entityId: uuid4("entity_id").references(() => entityTable.id, {
132
+ onDelete: "cascade"
133
+ }),
134
+ agentId: uuid4("agent_id").references(() => agentTable.id, {
135
+ onDelete: "cascade"
136
+ }).notNull(),
137
+ roomId: uuid4("room_id").references(() => roomTable.id, {
138
+ onDelete: "cascade"
139
+ }),
140
+ worldId: uuid4("world_id"),
141
+ unique: boolean2("unique").default(true).notNull(),
142
+ metadata: jsonb4("metadata").$type().default({}).notNull()
143
+ }, (table) => [
144
+ index("idx_memories_type_room").on(table.type, table.roomId),
145
+ index("idx_memories_world_id").on(table.worldId),
146
+ foreignKey({
147
+ name: "fk_room",
148
+ columns: [table.roomId],
149
+ foreignColumns: [roomTable.id]
150
+ }).onDelete("cascade"),
151
+ foreignKey({
152
+ name: "fk_user",
153
+ columns: [table.entityId],
154
+ foreignColumns: [entityTable.id]
155
+ }).onDelete("cascade"),
156
+ foreignKey({
157
+ name: "fk_agent",
158
+ columns: [table.agentId],
159
+ foreignColumns: [agentTable.id]
160
+ }).onDelete("cascade"),
161
+ index("idx_memories_metadata_type").on(sql4`((metadata->>'type'))`),
162
+ index("idx_memories_document_id").on(sql4`((metadata->>'documentId'))`),
163
+ index("idx_fragments_order").on(sql4`((metadata->>'documentId'))`, sql4`((metadata->>'position'))`),
164
+ check("fragment_metadata_check", sql4`
165
+ CASE
166
+ WHEN metadata->>'type' = 'fragment' THEN
167
+ metadata ? 'documentId' AND
168
+ metadata ? 'position'
169
+ ELSE true
170
+ END
171
+ `),
172
+ check("document_metadata_check", sql4`
173
+ CASE
174
+ WHEN metadata->>'type' = 'document' THEN
175
+ metadata ? 'timestamp'
176
+ ELSE true
177
+ END
178
+ `)
179
+ ]);
180
+ memoryRelations = relations(memoryTable, ({ one }) => ({
181
+ embedding: one(embeddingTable)
182
+ }));
183
+ });
184
+
185
+ // src/schema/embedding.ts
186
+ import { sql as sql5 } from "drizzle-orm";
187
+ import { check as check2, foreignKey as foreignKey2, index as index2, pgTable as pgTable5, timestamp as timestamp5, uuid as uuid5, vector } from "drizzle-orm/pg-core";
188
+ import { VECTOR_DIMS } from "@elizaos/core";
189
+ var DIMENSION_MAP, embeddingTable;
190
+ var init_embedding = __esm(() => {
191
+ init_memory();
192
+ DIMENSION_MAP = {
193
+ [VECTOR_DIMS.SMALL]: "dim384",
194
+ [VECTOR_DIMS.MEDIUM]: "dim512",
195
+ [VECTOR_DIMS.LARGE]: "dim768",
196
+ [VECTOR_DIMS.XL]: "dim1024",
197
+ [VECTOR_DIMS.XXL]: "dim1536",
198
+ [VECTOR_DIMS.XXXL]: "dim3072"
199
+ };
200
+ embeddingTable = pgTable5("embeddings", {
201
+ id: uuid5("id").primaryKey().defaultRandom().notNull(),
202
+ memoryId: uuid5("memory_id").references(() => memoryTable.id, { onDelete: "cascade" }),
203
+ createdAt: timestamp5("created_at").default(sql5`now()`).notNull(),
204
+ dim384: vector("dim_384", { dimensions: VECTOR_DIMS.SMALL }),
205
+ dim512: vector("dim_512", { dimensions: VECTOR_DIMS.MEDIUM }),
206
+ dim768: vector("dim_768", { dimensions: VECTOR_DIMS.LARGE }),
207
+ dim1024: vector("dim_1024", { dimensions: VECTOR_DIMS.XL }),
208
+ dim1536: vector("dim_1536", { dimensions: VECTOR_DIMS.XXL }),
209
+ dim3072: vector("dim_3072", { dimensions: VECTOR_DIMS.XXXL })
210
+ }, (table) => [
211
+ check2("embedding_source_check", sql5`"memory_id" IS NOT NULL`),
212
+ index2("idx_embedding_memory").on(table.memoryId),
213
+ foreignKey2({
214
+ name: "fk_embedding_memory",
215
+ columns: [table.memoryId],
216
+ foreignColumns: [memoryTable.id]
217
+ }).onDelete("cascade")
218
+ ]);
219
+ });
220
+
221
+ // src/schema/cache.ts
222
+ import { sql as sql6 } from "drizzle-orm";
223
+ import { jsonb as jsonb5, pgTable as pgTable6, text as text5, primaryKey, timestamp as timestamp6, uuid as uuid6 } from "drizzle-orm/pg-core";
224
+ var cacheTable;
225
+ var init_cache = __esm(() => {
226
+ init_agent();
227
+ cacheTable = pgTable6("cache", {
228
+ key: text5("key").notNull(),
229
+ agentId: uuid6("agent_id").notNull().references(() => agentTable.id, { onDelete: "cascade" }),
230
+ value: jsonb5("value").notNull(),
231
+ createdAt: timestamp6("created_at", { withTimezone: true }).default(sql6`now()`).notNull(),
232
+ expiresAt: timestamp6("expires_at", { withTimezone: true })
233
+ }, (table) => [primaryKey({ columns: [table.key, table.agentId] })]);
234
+ });
235
+
236
+ // src/schema/world.ts
237
+ import { sql as sql7 } from "drizzle-orm";
238
+ import { jsonb as jsonb6, pgTable as pgTable7, text as text6, timestamp as timestamp7, uuid as uuid7 } from "drizzle-orm/pg-core";
239
+ var worldTable;
240
+ var init_world = __esm(() => {
241
+ init_agent();
242
+ worldTable = pgTable7("worlds", {
243
+ id: uuid7("id").notNull().primaryKey().default(sql7`gen_random_uuid()`),
244
+ agentId: uuid7("agent_id").notNull().references(() => agentTable.id, { onDelete: "cascade" }),
245
+ name: text6("name").notNull(),
246
+ metadata: jsonb6("metadata").$type(),
247
+ messageServerId: uuid7("message_server_id"),
248
+ createdAt: timestamp7("created_at").default(sql7`now()`).notNull()
249
+ });
250
+ });
251
+
252
+ // src/schema/component.ts
253
+ import { sql as sql8 } from "drizzle-orm";
254
+ import { jsonb as jsonb7, pgTable as pgTable8, text as text7, timestamp as timestamp8, uuid as uuid8 } from "drizzle-orm/pg-core";
255
+ var componentTable;
256
+ var init_component = __esm(() => {
257
+ init_agent();
258
+ init_entity();
259
+ init_room();
260
+ init_world();
261
+ componentTable = pgTable8("components", {
262
+ id: uuid8("id").primaryKey().default(sql8`gen_random_uuid()`).notNull(),
263
+ entityId: uuid8("entity_id").references(() => entityTable.id, { onDelete: "cascade" }).notNull(),
264
+ agentId: uuid8("agent_id").references(() => agentTable.id, { onDelete: "cascade" }).notNull(),
265
+ roomId: uuid8("room_id").references(() => roomTable.id, { onDelete: "cascade" }).notNull(),
266
+ worldId: uuid8("world_id").references(() => worldTable.id, { onDelete: "cascade" }),
267
+ sourceEntityId: uuid8("source_entity_id").references(() => entityTable.id, {
268
+ onDelete: "cascade"
269
+ }),
270
+ type: text7("type").notNull(),
271
+ data: jsonb7("data").default(sql8`'{}'::jsonb`),
272
+ createdAt: timestamp8("created_at").default(sql8`now()`).notNull()
273
+ });
274
+ });
275
+
276
+ // src/schema/log.ts
277
+ import { sql as sql9 } from "drizzle-orm";
278
+ import { foreignKey as foreignKey3, jsonb as jsonb8, pgTable as pgTable9, text as text8, timestamp as timestamp9, uuid as uuid9 } from "drizzle-orm/pg-core";
279
+ var logTable;
280
+ var init_log = __esm(() => {
281
+ init_entity();
282
+ init_room();
283
+ logTable = pgTable9("logs", {
284
+ id: uuid9("id").defaultRandom().notNull(),
285
+ createdAt: timestamp9("created_at", { withTimezone: true }).default(sql9`now()`).notNull(),
286
+ entityId: uuid9("entity_id").notNull().references(() => entityTable.id, { onDelete: "cascade" }),
287
+ body: jsonb8("body").notNull(),
288
+ type: text8("type").notNull(),
289
+ roomId: uuid9("room_id").notNull().references(() => roomTable.id, { onDelete: "cascade" })
290
+ }, (table) => [
291
+ foreignKey3({
292
+ name: "fk_room",
293
+ columns: [table.roomId],
294
+ foreignColumns: [roomTable.id]
295
+ }).onDelete("cascade"),
296
+ foreignKey3({
297
+ name: "fk_user",
298
+ columns: [table.entityId],
299
+ foreignColumns: [entityTable.id]
300
+ }).onDelete("cascade")
301
+ ]);
302
+ });
303
+
64
304
  // src/schema/server.ts
65
305
  import { sql as sql10 } from "drizzle-orm";
66
306
  import { pgTable as pgTable10, timestamp as timestamp10, uuid as uuid10 } from "drizzle-orm/pg-core";
@@ -73,16 +313,260 @@ var init_server = __esm(() => {
73
313
  });
74
314
  });
75
315
 
316
+ // src/schema/participant.ts
317
+ import { sql as sql11 } from "drizzle-orm";
318
+ import { foreignKey as foreignKey4, index as index3, pgTable as pgTable11, text as text9, timestamp as timestamp11, uuid as uuid11 } from "drizzle-orm/pg-core";
319
+ var participantTable;
320
+ var init_participant = __esm(() => {
321
+ init_agent();
322
+ init_entity();
323
+ init_room();
324
+ participantTable = pgTable11("participants", {
325
+ id: uuid11("id").notNull().primaryKey().default(sql11`gen_random_uuid()`),
326
+ createdAt: timestamp11("created_at", { withTimezone: true }).default(sql11`now()`).notNull(),
327
+ entityId: uuid11("entity_id").references(() => entityTable.id, {
328
+ onDelete: "cascade"
329
+ }),
330
+ roomId: uuid11("room_id").references(() => roomTable.id, {
331
+ onDelete: "cascade"
332
+ }),
333
+ agentId: uuid11("agent_id").references(() => agentTable.id, {
334
+ onDelete: "cascade"
335
+ }),
336
+ roomState: text9("room_state")
337
+ }, (table) => [
338
+ index3("idx_participants_user").on(table.entityId),
339
+ index3("idx_participants_room").on(table.roomId),
340
+ foreignKey4({
341
+ name: "fk_room",
342
+ columns: [table.roomId],
343
+ foreignColumns: [roomTable.id]
344
+ }).onDelete("cascade"),
345
+ foreignKey4({
346
+ name: "fk_user",
347
+ columns: [table.entityId],
348
+ foreignColumns: [entityTable.id]
349
+ }).onDelete("cascade")
350
+ ]);
351
+ });
352
+
353
+ // src/schema/relationship.ts
354
+ import { sql as sql12 } from "drizzle-orm";
355
+ import {
356
+ foreignKey as foreignKey5,
357
+ index as index4,
358
+ jsonb as jsonb9,
359
+ pgTable as pgTable12,
360
+ text as text10,
361
+ timestamp as timestamp12,
362
+ unique as unique2,
363
+ uuid as uuid12
364
+ } from "drizzle-orm/pg-core";
365
+ var relationshipTable;
366
+ var init_relationship = __esm(() => {
367
+ init_agent();
368
+ init_entity();
369
+ relationshipTable = pgTable12("relationships", {
370
+ id: uuid12("id").notNull().primaryKey().default(sql12`gen_random_uuid()`),
371
+ createdAt: timestamp12("created_at", { withTimezone: true }).default(sql12`now()`).notNull(),
372
+ sourceEntityId: uuid12("source_entity_id").notNull().references(() => entityTable.id, { onDelete: "cascade" }),
373
+ targetEntityId: uuid12("target_entity_id").notNull().references(() => entityTable.id, { onDelete: "cascade" }),
374
+ agentId: uuid12("agent_id").notNull().references(() => agentTable.id, { onDelete: "cascade" }),
375
+ tags: text10("tags").array(),
376
+ metadata: jsonb9("metadata").$type()
377
+ }, (table) => [
378
+ index4("idx_relationships_users").on(table.sourceEntityId, table.targetEntityId),
379
+ unique2("unique_relationship").on(table.sourceEntityId, table.targetEntityId, table.agentId),
380
+ foreignKey5({
381
+ name: "fk_user_a",
382
+ columns: [table.sourceEntityId],
383
+ foreignColumns: [entityTable.id]
384
+ }).onDelete("cascade"),
385
+ foreignKey5({
386
+ name: "fk_user_b",
387
+ columns: [table.targetEntityId],
388
+ foreignColumns: [entityTable.id]
389
+ }).onDelete("cascade")
390
+ ]);
391
+ });
392
+
393
+ // src/schema/tasks.ts
394
+ import { jsonb as jsonb10, pgTable as pgTable13, text as text11, timestamp as timestamp13, uuid as uuid13 } from "drizzle-orm/pg-core";
395
+ import { sql as sql13 } from "drizzle-orm";
396
+ var taskTable;
397
+ var init_tasks = __esm(() => {
398
+ init_agent();
399
+ taskTable = pgTable13("tasks", {
400
+ id: uuid13("id").primaryKey().defaultRandom(),
401
+ name: text11("name").notNull(),
402
+ description: text11("description"),
403
+ roomId: uuid13("room_id"),
404
+ worldId: uuid13("world_id"),
405
+ entityId: uuid13("entity_id"),
406
+ agentId: uuid13("agent_id").notNull().references(() => agentTable.id, { onDelete: "cascade" }),
407
+ tags: text11("tags").array().default(sql13`'{}'::text[]`),
408
+ metadata: jsonb10("metadata").$type().default(sql13`'{}'::jsonb`),
409
+ createdAt: timestamp13("created_at", { withTimezone: true }).defaultNow(),
410
+ updatedAt: timestamp13("updated_at", { withTimezone: true }).defaultNow()
411
+ });
412
+ });
413
+
414
+ // src/schema/user.ts
415
+ import { sql as sql14 } from "drizzle-orm";
416
+ import { index as index5, pgTable as pgTable14, text as text12, timestamp as timestamp14, uuid as uuid14 } from "drizzle-orm/pg-core";
417
+ var userTable;
418
+ var init_user = __esm(() => {
419
+ userTable = pgTable14("users", {
420
+ id: uuid14("id").notNull().primaryKey().default(sql14`gen_random_uuid()`),
421
+ email: text12("email").notNull().unique(),
422
+ username: text12("username").notNull(),
423
+ passwordHash: text12("password_hash").notNull(),
424
+ createdAt: timestamp14("created_at").default(sql14`now()`).notNull(),
425
+ updatedAt: timestamp14("updated_at").default(sql14`now()`).notNull(),
426
+ lastLoginAt: timestamp14("last_login_at")
427
+ }, (table) => ({
428
+ emailIdx: index5("idx_users_email").on(table.email),
429
+ usernameIdx: index5("idx_users_username").on(table.username)
430
+ }));
431
+ });
432
+
433
+ // src/schema/messageServer.ts
434
+ import { pgTable as pgTable15, text as text13, jsonb as jsonb11, timestamp as timestamp15, uuid as uuid15 } from "drizzle-orm/pg-core";
435
+ import { sql as sql15 } from "drizzle-orm";
436
+ var messageServerTable;
437
+ var init_messageServer = __esm(() => {
438
+ messageServerTable = pgTable15("message_servers", {
439
+ id: uuid15("id").primaryKey(),
440
+ name: text13("name").notNull(),
441
+ sourceType: text13("source_type").notNull(),
442
+ sourceId: text13("source_id"),
443
+ metadata: jsonb11("metadata").$type(),
444
+ createdAt: timestamp15("created_at", { mode: "date" }).default(sql15`CURRENT_TIMESTAMP`).notNull(),
445
+ updatedAt: timestamp15("updated_at", { mode: "date" }).default(sql15`CURRENT_TIMESTAMP`).notNull()
446
+ });
447
+ });
448
+
449
+ // src/schema/channel.ts
450
+ import { pgTable as pgTable16, text as text14, jsonb as jsonb12, timestamp as timestamp16, uuid as uuid16 } from "drizzle-orm/pg-core";
451
+ import { sql as sql16 } from "drizzle-orm";
452
+ var channelTable;
453
+ var init_channel = __esm(() => {
454
+ init_messageServer();
455
+ channelTable = pgTable16("channels", {
456
+ id: text14("id").primaryKey(),
457
+ messageServerId: uuid16("message_server_id").notNull().references(() => messageServerTable.id, { onDelete: "cascade" }),
458
+ name: text14("name").notNull(),
459
+ type: text14("type").notNull(),
460
+ sourceType: text14("source_type"),
461
+ sourceId: text14("source_id"),
462
+ topic: text14("topic"),
463
+ metadata: jsonb12("metadata").$type(),
464
+ createdAt: timestamp16("created_at", { mode: "date" }).default(sql16`CURRENT_TIMESTAMP`).notNull(),
465
+ updatedAt: timestamp16("updated_at", { mode: "date" }).default(sql16`CURRENT_TIMESTAMP`).notNull()
466
+ });
467
+ });
468
+
469
+ // src/schema/message.ts
470
+ import { pgTable as pgTable17, text as text15, jsonb as jsonb13, timestamp as timestamp17 } from "drizzle-orm/pg-core";
471
+ import { sql as sql17 } from "drizzle-orm";
472
+ var messageTable;
473
+ var init_message = __esm(() => {
474
+ init_channel();
475
+ messageTable = pgTable17("central_messages", {
476
+ id: text15("id").primaryKey(),
477
+ channelId: text15("channel_id").notNull().references(() => channelTable.id, { onDelete: "cascade" }),
478
+ authorId: text15("author_id").notNull(),
479
+ content: text15("content").notNull(),
480
+ rawMessage: jsonb13("raw_message"),
481
+ inReplyToRootMessageId: text15("in_reply_to_root_message_id").references(() => messageTable.id, {
482
+ onDelete: "set null"
483
+ }),
484
+ sourceType: text15("source_type"),
485
+ sourceId: text15("source_id"),
486
+ metadata: jsonb13("metadata").$type(),
487
+ createdAt: timestamp17("created_at", { mode: "date" }).default(sql17`CURRENT_TIMESTAMP`).notNull(),
488
+ updatedAt: timestamp17("updated_at", { mode: "date" }).default(sql17`CURRENT_TIMESTAMP`).notNull()
489
+ });
490
+ });
491
+
492
+ // src/schema/channelParticipant.ts
493
+ import { pgTable as pgTable18, text as text16, primaryKey as primaryKey2 } from "drizzle-orm/pg-core";
494
+ var channelParticipantsTable;
495
+ var init_channelParticipant = __esm(() => {
496
+ init_channel();
497
+ channelParticipantsTable = pgTable18("channel_participants", {
498
+ channelId: text16("channel_id").notNull().references(() => channelTable.id, { onDelete: "cascade" }),
499
+ entityId: text16("entity_id").notNull()
500
+ }, (table) => [primaryKey2({ columns: [table.channelId, table.entityId] })]);
501
+ });
502
+
503
+ // src/schema/messageServerAgent.ts
504
+ import { pgTable as pgTable19, uuid as uuid17, primaryKey as primaryKey3 } from "drizzle-orm/pg-core";
505
+ var messageServerAgentsTable;
506
+ var init_messageServerAgent = __esm(() => {
507
+ init_messageServer();
508
+ init_agent();
509
+ messageServerAgentsTable = pgTable19("message_server_agents", {
510
+ messageServerId: uuid17("message_server_id").notNull().references(() => messageServerTable.id, { onDelete: "cascade" }),
511
+ agentId: uuid17("agent_id").notNull().references(() => agentTable.id, { onDelete: "cascade" })
512
+ }, (table) => [primaryKey3({ columns: [table.messageServerId, table.agentId] })]);
513
+ });
514
+
515
+ // src/schema/index.ts
516
+ var exports_schema = {};
517
+ __export(exports_schema, {
518
+ worldTable: () => worldTable,
519
+ userTable: () => userTable,
520
+ taskTable: () => taskTable,
521
+ serverTable: () => serverTable,
522
+ roomTable: () => roomTable,
523
+ relationshipTable: () => relationshipTable,
524
+ participantTable: () => participantTable,
525
+ messageTable: () => messageTable,
526
+ messageServerTable: () => messageServerTable,
527
+ messageServerAgentsTable: () => messageServerAgentsTable,
528
+ memoryTable: () => memoryTable,
529
+ logTable: () => logTable,
530
+ entityTable: () => entityTable,
531
+ embeddingTable: () => embeddingTable,
532
+ componentTable: () => componentTable,
533
+ channelTable: () => channelTable,
534
+ channelParticipantsTable: () => channelParticipantsTable,
535
+ cacheTable: () => cacheTable,
536
+ agentTable: () => agentTable
537
+ });
538
+ var init_schema = __esm(() => {
539
+ init_agent();
540
+ init_cache();
541
+ init_component();
542
+ init_embedding();
543
+ init_entity();
544
+ init_log();
545
+ init_memory();
546
+ init_server();
547
+ init_participant();
548
+ init_relationship();
549
+ init_room();
550
+ init_world();
551
+ init_tasks();
552
+ init_user();
553
+ init_messageServer();
554
+ init_channel();
555
+ init_message();
556
+ init_channelParticipant();
557
+ init_messageServerAgent();
558
+ });
559
+
76
560
  // src/types.ts
77
561
  function getDb(adapter) {
78
562
  return adapter.db;
79
563
  }
80
- function getRow(result, index5 = 0) {
81
- return result.rows[index5];
564
+ function getRow(result, index6 = 0) {
565
+ return result.rows[index6];
82
566
  }
83
567
 
84
568
  // src/runtime-migrator/storage/migration-tracker.ts
85
- import { sql as sql23 } from "drizzle-orm";
569
+ import { sql as sql24 } from "drizzle-orm";
86
570
 
87
571
  class MigrationTracker {
88
572
  db;
@@ -90,11 +574,11 @@ class MigrationTracker {
90
574
  this.db = db;
91
575
  }
92
576
  async ensureSchema() {
93
- await this.db.execute(sql23`CREATE SCHEMA IF NOT EXISTS migrations`);
577
+ await this.db.execute(sql24`CREATE SCHEMA IF NOT EXISTS migrations`);
94
578
  }
95
579
  async ensureTables() {
96
580
  await this.ensureSchema();
97
- await this.db.execute(sql23`
581
+ await this.db.execute(sql24`
98
582
  CREATE TABLE IF NOT EXISTS migrations._migrations (
99
583
  id SERIAL PRIMARY KEY,
100
584
  plugin_name TEXT NOT NULL,
@@ -102,7 +586,7 @@ class MigrationTracker {
102
586
  created_at BIGINT NOT NULL
103
587
  )
104
588
  `);
105
- await this.db.execute(sql23`
589
+ await this.db.execute(sql24`
106
590
  CREATE TABLE IF NOT EXISTS migrations._journal (
107
591
  plugin_name TEXT PRIMARY KEY,
108
592
  version TEXT NOT NULL,
@@ -110,7 +594,7 @@ class MigrationTracker {
110
594
  entries JSONB NOT NULL DEFAULT '[]'
111
595
  )
112
596
  `);
113
- await this.db.execute(sql23`
597
+ await this.db.execute(sql24`
114
598
  CREATE TABLE IF NOT EXISTS migrations._snapshots (
115
599
  id SERIAL PRIMARY KEY,
116
600
  plugin_name TEXT NOT NULL,
@@ -122,7 +606,7 @@ class MigrationTracker {
122
606
  `);
123
607
  }
124
608
  async getLastMigration(pluginName) {
125
- const result = await this.db.execute(sql23`SELECT id, hash, created_at
609
+ const result = await this.db.execute(sql24`SELECT id, hash, created_at
126
610
  FROM migrations._migrations
127
611
  WHERE plugin_name = ${pluginName}
128
612
  ORDER BY created_at DESC
@@ -130,14 +614,14 @@ class MigrationTracker {
130
614
  return getRow(result) || null;
131
615
  }
132
616
  async recordMigration(pluginName, hash, createdAt) {
133
- await this.db.execute(sql23`INSERT INTO migrations._migrations (plugin_name, hash, created_at)
617
+ await this.db.execute(sql24`INSERT INTO migrations._migrations (plugin_name, hash, created_at)
134
618
  VALUES (${pluginName}, ${hash}, ${createdAt})`);
135
619
  }
136
620
  }
137
621
  var init_migration_tracker = () => {};
138
622
 
139
623
  // src/runtime-migrator/storage/journal-storage.ts
140
- import { sql as sql24 } from "drizzle-orm";
624
+ import { sql as sql25 } from "drizzle-orm";
141
625
 
142
626
  class JournalStorage {
143
627
  db;
@@ -145,7 +629,7 @@ class JournalStorage {
145
629
  this.db = db;
146
630
  }
147
631
  async loadJournal(pluginName) {
148
- const result = await this.db.execute(sql24`SELECT version, dialect, entries
632
+ const result = await this.db.execute(sql25`SELECT version, dialect, entries
149
633
  FROM migrations._journal
150
634
  WHERE plugin_name = ${pluginName}`);
151
635
  if (result.rows.length === 0) {
@@ -159,7 +643,7 @@ class JournalStorage {
159
643
  };
160
644
  }
161
645
  async saveJournal(pluginName, journal) {
162
- await this.db.execute(sql24`INSERT INTO migrations._journal (plugin_name, version, dialect, entries)
646
+ await this.db.execute(sql25`INSERT INTO migrations._journal (plugin_name, version, dialect, entries)
163
647
  VALUES (${pluginName}, ${journal.version}, ${journal.dialect}, ${JSON.stringify(journal.entries)}::jsonb)
164
648
  ON CONFLICT (plugin_name)
165
649
  DO UPDATE SET
@@ -201,7 +685,7 @@ class JournalStorage {
201
685
  var init_journal_storage = () => {};
202
686
 
203
687
  // src/runtime-migrator/storage/snapshot-storage.ts
204
- import { sql as sql25 } from "drizzle-orm";
688
+ import { sql as sql26 } from "drizzle-orm";
205
689
 
206
690
  class SnapshotStorage {
207
691
  db;
@@ -209,7 +693,7 @@ class SnapshotStorage {
209
693
  this.db = db;
210
694
  }
211
695
  async saveSnapshot(pluginName, idx, snapshot) {
212
- await this.db.execute(sql25`INSERT INTO migrations._snapshots (plugin_name, idx, snapshot)
696
+ await this.db.execute(sql26`INSERT INTO migrations._snapshots (plugin_name, idx, snapshot)
213
697
  VALUES (${pluginName}, ${idx}, ${JSON.stringify(snapshot)}::jsonb)
214
698
  ON CONFLICT (plugin_name, idx)
215
699
  DO UPDATE SET
@@ -217,7 +701,7 @@ class SnapshotStorage {
217
701
  created_at = NOW()`);
218
702
  }
219
703
  async loadSnapshot(pluginName, idx) {
220
- const result = await this.db.execute(sql25`SELECT snapshot
704
+ const result = await this.db.execute(sql26`SELECT snapshot
221
705
  FROM migrations._snapshots
222
706
  WHERE plugin_name = ${pluginName} AND idx = ${idx}`);
223
707
  if (result.rows.length === 0) {
@@ -226,7 +710,7 @@ class SnapshotStorage {
226
710
  return result.rows[0].snapshot;
227
711
  }
228
712
  async getLatestSnapshot(pluginName) {
229
- const result = await this.db.execute(sql25`SELECT snapshot
713
+ const result = await this.db.execute(sql26`SELECT snapshot
230
714
  FROM migrations._snapshots
231
715
  WHERE plugin_name = ${pluginName}
232
716
  ORDER BY idx DESC
@@ -237,7 +721,7 @@ class SnapshotStorage {
237
721
  return result.rows[0].snapshot;
238
722
  }
239
723
  async getAllSnapshots(pluginName) {
240
- const result = await this.db.execute(sql25`SELECT snapshot
724
+ const result = await this.db.execute(sql26`SELECT snapshot
241
725
  FROM migrations._snapshots
242
726
  WHERE plugin_name = ${pluginName}
243
727
  ORDER BY idx ASC`);
@@ -247,7 +731,7 @@ class SnapshotStorage {
247
731
  var init_snapshot_storage = () => {};
248
732
 
249
733
  // src/runtime-migrator/extension-manager.ts
250
- import { sql as sql26 } from "drizzle-orm";
734
+ import { sql as sql27 } from "drizzle-orm";
251
735
  import { logger as logger8 } from "@elizaos/core";
252
736
 
253
737
  class ExtensionManager {
@@ -262,7 +746,7 @@ class ExtensionManager {
262
746
  logger8.warn({ src: "plugin:sql", extension }, "Invalid extension name - contains invalid characters");
263
747
  continue;
264
748
  }
265
- await this.db.execute(sql26`CREATE EXTENSION IF NOT EXISTS ${sql26.identifier(extension)}`);
749
+ await this.db.execute(sql27`CREATE EXTENSION IF NOT EXISTS ${sql27.identifier(extension)}`);
266
750
  logger8.debug({ src: "plugin:sql", extension }, "Extension installed");
267
751
  } catch (error) {
268
752
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -1904,12 +2388,12 @@ function objectToString(o) {
1904
2388
  function pad(n) {
1905
2389
  return n < 10 ? "0" + n.toString(10) : n.toString(10);
1906
2390
  }
1907
- function timestamp17() {
2391
+ function timestamp18() {
1908
2392
  var d = new Date, time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(":");
1909
2393
  return [d.getDate(), months[d.getMonth()], time].join(" ");
1910
2394
  }
1911
2395
  function log(...args) {
1912
- console.log("%s - %s", timestamp17(), format.apply(null, args));
2396
+ console.log("%s - %s", timestamp18(), format.apply(null, args));
1913
2397
  }
1914
2398
  function inherits(ctor, superCtor) {
1915
2399
  if (superCtor)
@@ -4675,10 +5159,10 @@ var require_stream = __commonJS((exports, module) => {
4675
5159
  dests[i2].emit("unpipe", this, { hasUnpiped: false });
4676
5160
  return this;
4677
5161
  }
4678
- let index5 = ArrayPrototypeIndexOf(state.pipes, dest);
4679
- if (index5 === -1)
5162
+ let index6 = ArrayPrototypeIndexOf(state.pipes, dest);
5163
+ if (index6 === -1)
4680
5164
  return this;
4681
- if (state.pipes.splice(index5, 1), state.pipes.length === 0)
5165
+ if (state.pipes.splice(index6, 1), state.pipes.length === 0)
4682
5166
  this.pause();
4683
5167
  return dest.emit("unpipe", this, unpipeInfo), this;
4684
5168
  };
@@ -6071,12 +6555,12 @@ var require_stream = __commonJS((exports, module) => {
6071
6555
  if ((options === null || options === undefined ? undefined : options.signal) != null)
6072
6556
  validateAbortSignal2(options.signal, "options.signal");
6073
6557
  return async function* () {
6074
- let index5 = 0;
6558
+ let index6 = 0;
6075
6559
  for await (let val of this) {
6076
6560
  var _options$signal;
6077
6561
  if (options !== null && options !== undefined && (_options$signal = options.signal) !== null && _options$signal !== undefined && _options$signal.aborted)
6078
6562
  throw new AbortError2({ cause: options.signal.reason });
6079
- yield [index5++, val];
6563
+ yield [index6++, val];
6080
6564
  }
6081
6565
  }.call(this);
6082
6566
  }
@@ -7381,8 +7865,8 @@ var init_crypto = __esm(() => {
7381
7865
  }
7382
7866
  return this.strip();
7383
7867
  };
7384
- function parseHex4Bits(string, index5) {
7385
- var c = string.charCodeAt(index5);
7868
+ function parseHex4Bits(string, index6) {
7869
+ var c = string.charCodeAt(index6);
7386
7870
  if (c >= 65 && c <= 70)
7387
7871
  return c - 55;
7388
7872
  else if (c >= 97 && c <= 102)
@@ -7390,10 +7874,10 @@ var init_crypto = __esm(() => {
7390
7874
  else
7391
7875
  return c - 48 & 15;
7392
7876
  }
7393
- function parseHexByte(string, lowerBound, index5) {
7394
- var r = parseHex4Bits(string, index5);
7395
- if (index5 - 1 >= lowerBound)
7396
- r |= parseHex4Bits(string, index5 - 1) << 4;
7877
+ function parseHexByte(string, lowerBound, index6) {
7878
+ var r = parseHex4Bits(string, index6);
7879
+ if (index6 - 1 >= lowerBound)
7880
+ r |= parseHex4Bits(string, index6 - 1) << 4;
7397
7881
  return r;
7398
7882
  }
7399
7883
  BN.prototype._parseHex = function(number, start, endian) {
@@ -8955,11 +9439,11 @@ var init_crypto = __esm(() => {
8955
9439
  comb[1] = points[a].toJ().mixedAdd(points[b]), comb[2] = points[a].add(points[b].neg());
8956
9440
  else
8957
9441
  comb[1] = points[a].toJ().mixedAdd(points[b]), comb[2] = points[a].toJ().mixedAdd(points[b].neg());
8958
- var index5 = [-3, -1, -5, -7, 0, 7, 5, 1, 3], jsf = getJSF(coeffs[a], coeffs[b]);
9442
+ var index6 = [-3, -1, -5, -7, 0, 7, 5, 1, 3], jsf = getJSF(coeffs[a], coeffs[b]);
8959
9443
  max = Math.max(jsf[0].length, max), naf[a] = Array(max), naf[b] = Array(max);
8960
9444
  for (j = 0;j < max; j++) {
8961
9445
  var ja = jsf[0][j] | 0, jb = jsf[1][j] | 0;
8962
- naf[a][j] = index5[(ja + 1) * 3 + (jb + 1)], naf[b][j] = 0, wnd[a] = comb;
9446
+ naf[a][j] = index6[(ja + 1) * 3 + (jb + 1)], naf[b][j] = 0, wnd[a] = comb;
8963
9447
  }
8964
9448
  }
8965
9449
  var acc = this.jpoint(null, null, null), tmp = this._wnafT4;
@@ -11056,8 +11540,8 @@ var init_crypto = __esm(() => {
11056
11540
  }
11057
11541
  return this.strip();
11058
11542
  };
11059
- function parseHex4Bits(string, index5) {
11060
- var c = string.charCodeAt(index5);
11543
+ function parseHex4Bits(string, index6) {
11544
+ var c = string.charCodeAt(index6);
11061
11545
  if (c >= 65 && c <= 70)
11062
11546
  return c - 55;
11063
11547
  else if (c >= 97 && c <= 102)
@@ -11065,10 +11549,10 @@ var init_crypto = __esm(() => {
11065
11549
  else
11066
11550
  return c - 48 & 15;
11067
11551
  }
11068
- function parseHexByte(string, lowerBound, index5) {
11069
- var r = parseHex4Bits(string, index5);
11070
- if (index5 - 1 >= lowerBound)
11071
- r |= parseHex4Bits(string, index5 - 1) << 4;
11552
+ function parseHexByte(string, lowerBound, index6) {
11553
+ var r = parseHex4Bits(string, index6);
11554
+ if (index6 - 1 >= lowerBound)
11555
+ r |= parseHex4Bits(string, index6 - 1) << 4;
11072
11556
  return r;
11073
11557
  }
11074
11558
  BN.prototype._parseHex = function(number, start, endian) {
@@ -12519,8 +13003,8 @@ var init_crypto = __esm(() => {
12519
13003
  }
12520
13004
  return this.strip();
12521
13005
  };
12522
- function parseHex4Bits(string, index5) {
12523
- var c = string.charCodeAt(index5);
13006
+ function parseHex4Bits(string, index6) {
13007
+ var c = string.charCodeAt(index6);
12524
13008
  if (c >= 65 && c <= 70)
12525
13009
  return c - 55;
12526
13010
  else if (c >= 97 && c <= 102)
@@ -12528,10 +13012,10 @@ var init_crypto = __esm(() => {
12528
13012
  else
12529
13013
  return c - 48 & 15;
12530
13014
  }
12531
- function parseHexByte(string, lowerBound, index5) {
12532
- var r = parseHex4Bits(string, index5);
12533
- if (index5 - 1 >= lowerBound)
12534
- r |= parseHex4Bits(string, index5 - 1) << 4;
13015
+ function parseHexByte(string, lowerBound, index6) {
13016
+ var r = parseHex4Bits(string, index6);
13017
+ if (index6 - 1 >= lowerBound)
13018
+ r |= parseHex4Bits(string, index6 - 1) << 4;
12535
13019
  return r;
12536
13020
  }
12537
13021
  BN.prototype._parseHex = function(number, start, endian) {
@@ -13885,13 +14369,13 @@ var init_crypto = __esm(() => {
13885
14369
  Reporter.prototype.enterKey = function(key) {
13886
14370
  return this._reporterState.path.push(key);
13887
14371
  };
13888
- Reporter.prototype.exitKey = function(index5) {
14372
+ Reporter.prototype.exitKey = function(index6) {
13889
14373
  var state = this._reporterState;
13890
- state.path = state.path.slice(0, index5 - 1);
14374
+ state.path = state.path.slice(0, index6 - 1);
13891
14375
  };
13892
- Reporter.prototype.leaveKey = function(index5, key, value) {
14376
+ Reporter.prototype.leaveKey = function(index6, key, value) {
13893
14377
  var state = this._reporterState;
13894
- if (this.exitKey(index5), state.obj !== null)
14378
+ if (this.exitKey(index6), state.obj !== null)
13895
14379
  state.obj[key] = value;
13896
14380
  };
13897
14381
  Reporter.prototype.path = function() {
@@ -15260,8 +15744,8 @@ var init_crypto = __esm(() => {
15260
15744
  }
15261
15745
  return this.strip();
15262
15746
  };
15263
- function parseHex4Bits(string, index5) {
15264
- var c = string.charCodeAt(index5);
15747
+ function parseHex4Bits(string, index6) {
15748
+ var c = string.charCodeAt(index6);
15265
15749
  if (c >= 65 && c <= 70)
15266
15750
  return c - 55;
15267
15751
  else if (c >= 97 && c <= 102)
@@ -15269,10 +15753,10 @@ var init_crypto = __esm(() => {
15269
15753
  else
15270
15754
  return c - 48 & 15;
15271
15755
  }
15272
- function parseHexByte(string, lowerBound, index5) {
15273
- var r = parseHex4Bits(string, index5);
15274
- if (index5 - 1 >= lowerBound)
15275
- r |= parseHex4Bits(string, index5 - 1) << 4;
15756
+ function parseHexByte(string, lowerBound, index6) {
15757
+ var r = parseHex4Bits(string, index6);
15758
+ if (index6 - 1 >= lowerBound)
15759
+ r |= parseHex4Bits(string, index6 - 1) << 4;
15276
15760
  return r;
15277
15761
  }
15278
15762
  BN.prototype._parseHex = function(number, start, endian) {
@@ -16664,8 +17148,8 @@ var init_crypto = __esm(() => {
16664
17148
  }
16665
17149
  return this._strip();
16666
17150
  };
16667
- function parseHex4Bits(string, index5) {
16668
- var c = string.charCodeAt(index5);
17151
+ function parseHex4Bits(string, index6) {
17152
+ var c = string.charCodeAt(index6);
16669
17153
  if (c >= 48 && c <= 57)
16670
17154
  return c - 48;
16671
17155
  else if (c >= 65 && c <= 70)
@@ -16675,10 +17159,10 @@ var init_crypto = __esm(() => {
16675
17159
  else
16676
17160
  assert(false, "Invalid character in " + string);
16677
17161
  }
16678
- function parseHexByte(string, lowerBound, index5) {
16679
- var r = parseHex4Bits(string, index5);
16680
- if (index5 - 1 >= lowerBound)
16681
- r |= parseHex4Bits(string, index5 - 1) << 4;
17162
+ function parseHexByte(string, lowerBound, index6) {
17163
+ var r = parseHex4Bits(string, index6);
17164
+ if (index6 - 1 >= lowerBound)
17165
+ r |= parseHex4Bits(string, index6 - 1) << 4;
16682
17166
  return r;
16683
17167
  }
16684
17168
  BN.prototype._parseHex = function(number, start, endian) {
@@ -18584,8 +19068,8 @@ function hasChanges(previousSnapshot, currentSnapshot) {
18584
19068
  const currHash = hashSnapshot(currentSnapshot);
18585
19069
  return prevHash !== currHash;
18586
19070
  }
18587
- var sqlToStr = (sql27, casing) => {
18588
- return sql27.toQuery({
19071
+ var sqlToStr = (sql28, casing) => {
19072
+ return sql28.toQuery({
18589
19073
  escapeName: () => {
18590
19074
  throw new Error("we don't support params for `sql` default values");
18591
19075
  },
@@ -19116,14 +19600,14 @@ async function generateMigrationSQL(previousSnapshot, currentSnapshot, diff) {
19116
19600
  const alterStatements = generateAlterColumnSQL(modified.table, modified.column, modified.changes);
19117
19601
  statements.push(...alterStatements);
19118
19602
  }
19119
- for (const index5 of diff.indexes.deleted) {
19120
- statements.push(generateDropIndexSQL(index5));
19603
+ for (const index6 of diff.indexes.deleted) {
19604
+ statements.push(generateDropIndexSQL(index6));
19121
19605
  }
19122
19606
  for (const alteredIndex of diff.indexes.altered) {
19123
19607
  statements.push(generateDropIndexSQL(alteredIndex.old));
19124
19608
  }
19125
- for (const index5 of diff.indexes.created) {
19126
- statements.push(generateCreateIndexSQL(index5));
19609
+ for (const index6 of diff.indexes.created) {
19610
+ statements.push(generateCreateIndexSQL(index6));
19127
19611
  }
19128
19612
  for (const alteredIndex of diff.indexes.altered) {
19129
19613
  statements.push(generateCreateIndexSQL(alteredIndex.new));
@@ -19220,18 +19704,18 @@ function generateCreateTableSQL(fullTableName, table) {
19220
19704
  return { tableSQL, fkSQLs };
19221
19705
  }
19222
19706
  function generateColumnDefinition(name, def) {
19223
- let sql27 = `"${name}" ${def.type}`;
19707
+ let sql28 = `"${name}" ${def.type}`;
19224
19708
  if (def.primaryKey && !def.type.includes("SERIAL")) {
19225
- sql27 += " PRIMARY KEY";
19709
+ sql28 += " PRIMARY KEY";
19226
19710
  }
19227
19711
  if (def.notNull) {
19228
- sql27 += " NOT NULL";
19712
+ sql28 += " NOT NULL";
19229
19713
  }
19230
19714
  if (def.default !== undefined) {
19231
19715
  const defaultValue = formatDefaultValue(def.default, def.type);
19232
- sql27 += ` DEFAULT ${defaultValue}`;
19716
+ sql28 += ` DEFAULT ${defaultValue}`;
19233
19717
  }
19234
- return sql27;
19718
+ return sql28;
19235
19719
  }
19236
19720
  function generateAddColumnSQL(table, column, definition) {
19237
19721
  const [schema, tableName] = table.includes(".") ? table.split(".") : ["public", table];
@@ -19358,27 +19842,27 @@ function formatDefaultValue(value, type) {
19358
19842
  }
19359
19843
  return String(value);
19360
19844
  }
19361
- function generateCreateIndexSQL(index5) {
19362
- const unique3 = index5.isUnique ? "UNIQUE " : "";
19363
- const method = index5.method || "btree";
19364
- const columns = index5.columns.map((c) => {
19845
+ function generateCreateIndexSQL(index6) {
19846
+ const unique3 = index6.isUnique ? "UNIQUE " : "";
19847
+ const method = index6.method || "btree";
19848
+ const columns = index6.columns.map((c) => {
19365
19849
  if (c.isExpression) {
19366
19850
  return c.expression;
19367
19851
  }
19368
19852
  return `"${c.expression}"${c.asc === false ? " DESC" : ""}`;
19369
19853
  }).join(", ");
19370
- const indexName = index5.name.includes(".") ? index5.name.split(".")[1] : index5.name;
19854
+ const indexName = index6.name.includes(".") ? index6.name.split(".")[1] : index6.name;
19371
19855
  let tableRef;
19372
- if (index5.table && index5.table.includes(".")) {
19373
- const [schema, table] = index5.table.split(".");
19856
+ if (index6.table && index6.table.includes(".")) {
19857
+ const [schema, table] = index6.table.split(".");
19374
19858
  tableRef = `"${schema}"."${table}"`;
19375
19859
  } else {
19376
- tableRef = `"${index5.table || ""}"`;
19860
+ tableRef = `"${index6.table || ""}"`;
19377
19861
  }
19378
19862
  return `CREATE ${unique3}INDEX "${indexName}" ON ${tableRef} USING ${method} (${columns});`;
19379
19863
  }
19380
- function generateDropIndexSQL(index5) {
19381
- const indexName = index5.name ? index5.name.includes(".") ? index5.name.split(".")[1] : index5.name : index5;
19864
+ function generateDropIndexSQL(index6) {
19865
+ const indexName = index6.name ? index6.name.includes(".") ? index6.name.split(".")[1] : index6.name : index6;
19382
19866
  return `DROP INDEX IF EXISTS "${indexName}";`;
19383
19867
  }
19384
19868
  function generateCreateForeignKeySQL(fk) {
@@ -19387,14 +19871,14 @@ function generateCreateForeignKeySQL(fk) {
19387
19871
  const tableFrom = fk.tableFrom;
19388
19872
  const columnsFrom = fk.columnsFrom.map((c) => `"${c}"`).join(", ");
19389
19873
  const columnsTo = fk.columnsTo.map((c) => `"${c}"`).join(", ");
19390
- let sql27 = `ALTER TABLE "${schemaFrom}"."${tableFrom}" ADD CONSTRAINT "${fk.name}" FOREIGN KEY (${columnsFrom}) REFERENCES "${schemaTo}"."${fk.tableTo}" (${columnsTo})`;
19874
+ let sql28 = `ALTER TABLE "${schemaFrom}"."${tableFrom}" ADD CONSTRAINT "${fk.name}" FOREIGN KEY (${columnsFrom}) REFERENCES "${schemaTo}"."${fk.tableTo}" (${columnsTo})`;
19391
19875
  if (fk.onDelete) {
19392
- sql27 += ` ON DELETE ${fk.onDelete}`;
19876
+ sql28 += ` ON DELETE ${fk.onDelete}`;
19393
19877
  }
19394
19878
  if (fk.onUpdate) {
19395
- sql27 += ` ON UPDATE ${fk.onUpdate}`;
19879
+ sql28 += ` ON UPDATE ${fk.onUpdate}`;
19396
19880
  }
19397
- return sql27 + ";";
19881
+ return sql28 + ";";
19398
19882
  }
19399
19883
  function generateDropForeignKeySQL(fk) {
19400
19884
  const [schema, tableName] = fk.tableFrom ? fk.tableFrom.includes(".") ? fk.tableFrom.split(".") : ["public", fk.tableFrom] : ["public", ""];
@@ -19405,12 +19889,12 @@ function generateCreateUniqueConstraintSQL(constraint) {
19405
19889
  const [schema, tableName] = table.includes(".") ? table.split(".") : ["public", table];
19406
19890
  const name = constraint.name;
19407
19891
  const columns = constraint.columns.map((c) => `"${c}"`).join(", ");
19408
- let sql27 = `ALTER TABLE "${schema}"."${tableName}" ADD CONSTRAINT "${name}" UNIQUE`;
19892
+ let sql28 = `ALTER TABLE "${schema}"."${tableName}" ADD CONSTRAINT "${name}" UNIQUE`;
19409
19893
  if (constraint.nullsNotDistinct) {
19410
- sql27 += ` NULLS NOT DISTINCT`;
19894
+ sql28 += ` NULLS NOT DISTINCT`;
19411
19895
  }
19412
- sql27 += ` (${columns});`;
19413
- return sql27;
19896
+ sql28 += ` (${columns});`;
19897
+ return sql28;
19414
19898
  }
19415
19899
  function generateDropUniqueConstraintSQL(constraint) {
19416
19900
  const table = constraint.table || "";
@@ -19477,7 +19961,7 @@ function normalizeSchemaName(input) {
19477
19961
  var init_schema_transformer = () => {};
19478
19962
 
19479
19963
  // src/runtime-migrator/drizzle-adapters/database-introspector.ts
19480
- import { sql as sql27 } from "drizzle-orm";
19964
+ import { sql as sql28 } from "drizzle-orm";
19481
19965
  import { logger as logger11 } from "@elizaos/core";
19482
19966
 
19483
19967
  class DatabaseIntrospector {
@@ -19604,7 +20088,7 @@ class DatabaseIntrospector {
19604
20088
  };
19605
20089
  }
19606
20090
  async getTables(schemaName) {
19607
- const result = await this.db.execute(sql27`SELECT
20091
+ const result = await this.db.execute(sql28`SELECT
19608
20092
  table_schema,
19609
20093
  table_name
19610
20094
  FROM information_schema.tables
@@ -19614,7 +20098,7 @@ class DatabaseIntrospector {
19614
20098
  return result.rows;
19615
20099
  }
19616
20100
  async getColumns(schemaName, tableName) {
19617
- const result = await this.db.execute(sql27`SELECT
20101
+ const result = await this.db.execute(sql28`SELECT
19618
20102
  a.attname AS column_name,
19619
20103
  CASE
19620
20104
  WHEN a.attnotnull THEN 'NO'
@@ -19657,7 +20141,7 @@ class DatabaseIntrospector {
19657
20141
  return result.rows;
19658
20142
  }
19659
20143
  async getIndexes(schemaName, tableName) {
19660
- const result = await this.db.execute(sql27`SELECT
20144
+ const result = await this.db.execute(sql28`SELECT
19661
20145
  i.relname AS name,
19662
20146
  idx.indisunique AS is_unique,
19663
20147
  idx.indisprimary AS is_primary,
@@ -19681,7 +20165,7 @@ class DatabaseIntrospector {
19681
20165
  return result.rows;
19682
20166
  }
19683
20167
  async getForeignKeys(schemaName, tableName) {
19684
- const result = await this.db.execute(sql27`SELECT
20168
+ const result = await this.db.execute(sql28`SELECT
19685
20169
  con.conname AS name,
19686
20170
  att.attname AS column_name,
19687
20171
  fnsp.nspname AS foreign_table_schema,
@@ -19716,7 +20200,7 @@ class DatabaseIntrospector {
19716
20200
  return result.rows;
19717
20201
  }
19718
20202
  async getPrimaryKeys(schemaName, tableName) {
19719
- const result = await this.db.execute(sql27`SELECT
20203
+ const result = await this.db.execute(sql28`SELECT
19720
20204
  con.conname AS name,
19721
20205
  ARRAY(
19722
20206
  SELECT a.attname
@@ -19734,7 +20218,7 @@ class DatabaseIntrospector {
19734
20218
  return result.rows;
19735
20219
  }
19736
20220
  async getUniqueConstraints(schemaName, tableName) {
19737
- const result = await this.db.execute(sql27`SELECT
20221
+ const result = await this.db.execute(sql28`SELECT
19738
20222
  con.conname AS name,
19739
20223
  ARRAY(
19740
20224
  SELECT a.attname
@@ -19752,7 +20236,7 @@ class DatabaseIntrospector {
19752
20236
  return result.rows;
19753
20237
  }
19754
20238
  async getCheckConstraints(schemaName, tableName) {
19755
- const result = await this.db.execute(sql27`SELECT
20239
+ const result = await this.db.execute(sql28`SELECT
19756
20240
  con.conname AS name,
19757
20241
  pg_get_constraintdef(con.oid) AS definition
19758
20242
  FROM pg_constraint con
@@ -19764,7 +20248,7 @@ class DatabaseIntrospector {
19764
20248
  return result.rows;
19765
20249
  }
19766
20250
  async getEnums(schemaName) {
19767
- const result = await this.db.execute(sql27`SELECT
20251
+ const result = await this.db.execute(sql28`SELECT
19768
20252
  n.nspname AS schema,
19769
20253
  t.typname AS name,
19770
20254
  e.enumlabel AS value,
@@ -19796,7 +20280,7 @@ class DatabaseIntrospector {
19796
20280
  }
19797
20281
  async hasExistingTables(pluginName) {
19798
20282
  const schemaName = pluginName === "@elizaos/plugin-sql" ? "public" : this.deriveSchemaName(pluginName);
19799
- const result = await this.db.execute(sql27`SELECT COUNT(*) AS count
20283
+ const result = await this.db.execute(sql28`SELECT COUNT(*) AS count
19800
20284
  FROM information_schema.tables
19801
20285
  WHERE table_schema = ${schemaName}
19802
20286
  AND table_type = 'BASE TABLE'`);
@@ -19810,7 +20294,7 @@ class DatabaseIntrospector {
19810
20294
  var init_database_introspector = () => {};
19811
20295
 
19812
20296
  // src/runtime-migrator/runtime-migrator.ts
19813
- import { sql as sql28 } from "drizzle-orm";
20297
+ import { sql as sql29 } from "drizzle-orm";
19814
20298
  import { logger as logger12 } from "@elizaos/core";
19815
20299
 
19816
20300
  class RuntimeMigrator {
@@ -19850,7 +20334,7 @@ class RuntimeMigrator {
19850
20334
  }
19851
20335
  for (const schemaName of schemasToCreate) {
19852
20336
  logger12.debug({ src: "plugin:sql", schemaName }, "Ensuring schema exists");
19853
- await this.db.execute(sql28.raw(`CREATE SCHEMA IF NOT EXISTS "${schemaName}"`));
20337
+ await this.db.execute(sql29.raw(`CREATE SCHEMA IF NOT EXISTS "${schemaName}"`));
19854
20338
  }
19855
20339
  }
19856
20340
  validateSchemaUsage(pluginName, snapshot) {
@@ -20008,11 +20492,11 @@ class RuntimeMigrator {
20008
20492
  try {
20009
20493
  logger12.debug({ src: "plugin:sql", pluginName }, "Using PostgreSQL advisory locks");
20010
20494
  const lockIdStr = lockId.toString();
20011
- const lockResult = await this.db.execute(sql28`SELECT pg_try_advisory_lock(CAST(${lockIdStr} AS bigint)) as acquired`);
20495
+ const lockResult = await this.db.execute(sql29`SELECT pg_try_advisory_lock(CAST(${lockIdStr} AS bigint)) as acquired`);
20012
20496
  lockAcquired = getRow(lockResult)?.acquired === true;
20013
20497
  if (!lockAcquired) {
20014
20498
  logger12.info({ src: "plugin:sql", pluginName }, "Migration already in progress, waiting for lock");
20015
- await this.db.execute(sql28`SELECT pg_advisory_lock(CAST(${lockIdStr} AS bigint))`);
20499
+ await this.db.execute(sql29`SELECT pg_advisory_lock(CAST(${lockIdStr} AS bigint))`);
20016
20500
  lockAcquired = true;
20017
20501
  logger12.info({ src: "plugin:sql", pluginName }, "Lock acquired");
20018
20502
  } else {
@@ -20143,7 +20627,7 @@ class RuntimeMigrator {
20143
20627
  if (lockAcquired && isRealPostgres) {
20144
20628
  try {
20145
20629
  const lockIdStr = lockId.toString();
20146
- await this.db.execute(sql28`SELECT pg_advisory_unlock(CAST(${lockIdStr} AS bigint))`);
20630
+ await this.db.execute(sql29`SELECT pg_advisory_unlock(CAST(${lockIdStr} AS bigint))`);
20147
20631
  logger12.debug({ src: "plugin:sql", pluginName }, "Advisory lock released");
20148
20632
  } catch (unlockError) {
20149
20633
  logger12.warn({
@@ -20158,23 +20642,23 @@ class RuntimeMigrator {
20158
20642
  async executeMigration(pluginName, snapshot, hash, sqlStatements) {
20159
20643
  let transactionStarted = false;
20160
20644
  try {
20161
- await this.db.execute(sql28`BEGIN`);
20645
+ await this.db.execute(sql29`BEGIN`);
20162
20646
  transactionStarted = true;
20163
20647
  for (const stmt of sqlStatements) {
20164
20648
  logger12.debug({ src: "plugin:sql", statement: stmt }, "Executing SQL statement");
20165
- await this.db.execute(sql28.raw(stmt));
20649
+ await this.db.execute(sql29.raw(stmt));
20166
20650
  }
20167
20651
  const idx = await this.journalStorage.getNextIdx(pluginName);
20168
20652
  await this.migrationTracker.recordMigration(pluginName, hash, Date.now());
20169
20653
  const tag = this.generateMigrationTag(idx, pluginName);
20170
20654
  await this.journalStorage.updateJournal(pluginName, idx, tag, true);
20171
20655
  await this.snapshotStorage.saveSnapshot(pluginName, idx, snapshot);
20172
- await this.db.execute(sql28`COMMIT`);
20656
+ await this.db.execute(sql29`COMMIT`);
20173
20657
  logger12.info({ src: "plugin:sql", pluginName, tag }, "Recorded migration");
20174
20658
  } catch (error) {
20175
20659
  if (transactionStarted) {
20176
20660
  try {
20177
- await this.db.execute(sql28`ROLLBACK`);
20661
+ await this.db.execute(sql29`ROLLBACK`);
20178
20662
  logger12.error({ src: "plugin:sql", error: error instanceof Error ? error.message : String(error) }, "Migration failed, rolled back");
20179
20663
  } catch (rollbackError) {
20180
20664
  logger12.error({
@@ -20188,8 +20672,8 @@ class RuntimeMigrator {
20188
20672
  }
20189
20673
  generateMigrationTag(idx, pluginName) {
20190
20674
  const prefix = idx.toString().padStart(4, "0");
20191
- const timestamp18 = Date.now().toString(36);
20192
- return `${prefix}_${pluginName}_${timestamp18}`;
20675
+ const timestamp19 = Date.now().toString(36);
20676
+ return `${prefix}_${pluginName}_${timestamp19}`;
20193
20677
  }
20194
20678
  async getStatus(pluginName) {
20195
20679
  const lastMigration = await this.migrationTracker.getLastMigration(pluginName);
@@ -20204,9 +20688,9 @@ class RuntimeMigrator {
20204
20688
  }
20205
20689
  async reset(pluginName) {
20206
20690
  logger12.warn({ src: "plugin:sql", pluginName }, "Resetting migrations");
20207
- await this.db.execute(sql28`DELETE FROM migrations._migrations WHERE plugin_name = ${pluginName}`);
20208
- await this.db.execute(sql28`DELETE FROM migrations._journal WHERE plugin_name = ${pluginName}`);
20209
- await this.db.execute(sql28`DELETE FROM migrations._snapshots WHERE plugin_name = ${pluginName}`);
20691
+ await this.db.execute(sql29`DELETE FROM migrations._migrations WHERE plugin_name = ${pluginName}`);
20692
+ await this.db.execute(sql29`DELETE FROM migrations._journal WHERE plugin_name = ${pluginName}`);
20693
+ await this.db.execute(sql29`DELETE FROM migrations._snapshots WHERE plugin_name = ${pluginName}`);
20210
20694
  logger12.warn({ src: "plugin:sql", pluginName }, "Reset complete");
20211
20695
  }
20212
20696
  async checkMigration(pluginName, schema) {
@@ -20255,18 +20739,18 @@ var init_runtime_migrator2 = __esm(() => {
20255
20739
 
20256
20740
  // src/migrations.ts
20257
20741
  import { logger as logger13 } from "@elizaos/core";
20258
- import { sql as sql29 } from "drizzle-orm";
20742
+ import { sql as sql30 } from "drizzle-orm";
20259
20743
  async function migrateToEntityRLS(adapter) {
20260
20744
  const db = getDb(adapter);
20261
20745
  try {
20262
- await db.execute(sql29`SELECT 1 FROM pg_tables LIMIT 1`);
20746
+ await db.execute(sql30`SELECT 1 FROM pg_tables LIMIT 1`);
20263
20747
  } catch {
20264
20748
  logger13.debug("[Migration] ⊘ Not PostgreSQL, skipping PostgreSQL-specific migrations");
20265
20749
  return;
20266
20750
  }
20267
20751
  let schemaAlreadyMigrated = false;
20268
20752
  try {
20269
- const migrationCheck = await db.execute(sql29`
20753
+ const migrationCheck = await db.execute(sql30`
20270
20754
  SELECT column_name FROM information_schema.columns
20271
20755
  WHERE table_schema = 'public'
20272
20756
  AND table_name = 'rooms'
@@ -20288,7 +20772,7 @@ async function migrateToEntityRLS(adapter) {
20288
20772
  }
20289
20773
  logger13.debug("[Migration] → Schema migrated but RLS disabled, cleaning up...");
20290
20774
  try {
20291
- const tablesWithRls = await db.execute(sql29`
20775
+ const tablesWithRls = await db.execute(sql30`
20292
20776
  SELECT c.relname as tablename
20293
20777
  FROM pg_class c
20294
20778
  JOIN pg_namespace n ON n.oid = c.relnamespace
@@ -20301,7 +20785,7 @@ async function migrateToEntityRLS(adapter) {
20301
20785
  for (const row of tablesWithRls.rows) {
20302
20786
  const tableName = row.tablename;
20303
20787
  try {
20304
- await db.execute(sql29.raw(`ALTER TABLE "${tableName}" DISABLE ROW LEVEL SECURITY`));
20788
+ await db.execute(sql30.raw(`ALTER TABLE "${tableName}" DISABLE ROW LEVEL SECURITY`));
20305
20789
  } catch {}
20306
20790
  }
20307
20791
  logger13.debug(`[Migration] ✓ RLS cleanup completed (${tablesWithRls.rows.length} tables)`);
@@ -20317,14 +20801,14 @@ async function migrateToEntityRLS(adapter) {
20317
20801
  try {
20318
20802
  logger13.debug("[Migration] → Clearing RuntimeMigrator snapshot cache...");
20319
20803
  try {
20320
- await db.execute(sql29`DELETE FROM migrations._snapshots WHERE plugin_name = '@elizaos/plugin-sql'`);
20804
+ await db.execute(sql30`DELETE FROM migrations._snapshots WHERE plugin_name = '@elizaos/plugin-sql'`);
20321
20805
  logger13.debug("[Migration] ✓ Snapshot cache cleared");
20322
20806
  } catch (error) {
20323
20807
  logger13.debug("[Migration] ⊘ No snapshot cache to clear (migrations schema not yet created)");
20324
20808
  }
20325
20809
  logger13.debug("[Migration] → Checking for Row Level Security to disable...");
20326
20810
  try {
20327
- const tablesWithRls = await db.execute(sql29`
20811
+ const tablesWithRls = await db.execute(sql30`
20328
20812
  SELECT c.relname as tablename
20329
20813
  FROM pg_class c
20330
20814
  JOIN pg_namespace n ON n.oid = c.relnamespace
@@ -20337,7 +20821,7 @@ async function migrateToEntityRLS(adapter) {
20337
20821
  for (const row of tablesWithRls.rows) {
20338
20822
  const tableName = row.tablename;
20339
20823
  try {
20340
- await db.execute(sql29.raw(`ALTER TABLE "${tableName}" DISABLE ROW LEVEL SECURITY`));
20824
+ await db.execute(sql30.raw(`ALTER TABLE "${tableName}" DISABLE ROW LEVEL SECURITY`));
20341
20825
  logger13.debug(`[Migration] ✓ Disabled RLS on ${tableName}`);
20342
20826
  } catch (error) {
20343
20827
  logger13.debug(`[Migration] ⊘ Could not disable RLS on ${tableName}`);
@@ -20353,7 +20837,7 @@ async function migrateToEntityRLS(adapter) {
20353
20837
  const tablesToMigrate = ["channels", "worlds", "rooms"];
20354
20838
  for (const tableName of tablesToMigrate) {
20355
20839
  try {
20356
- const columnsResult = await db.execute(sql29`
20840
+ const columnsResult = await db.execute(sql30`
20357
20841
  SELECT column_name, data_type, is_nullable
20358
20842
  FROM information_schema.columns
20359
20843
  WHERE table_schema = 'public'
@@ -20369,19 +20853,19 @@ async function migrateToEntityRLS(adapter) {
20369
20853
  const oldColumnName = serverIdSnake ? "server_id" : "serverId";
20370
20854
  if (serverId && !messageServerId) {
20371
20855
  logger13.debug(`[Migration] → Renaming ${tableName}.${oldColumnName} to message_server_id...`);
20372
- await db.execute(sql29.raw(`ALTER TABLE "${tableName}" RENAME COLUMN "${oldColumnName}" TO "message_server_id"`));
20856
+ await db.execute(sql30.raw(`ALTER TABLE "${tableName}" RENAME COLUMN "${oldColumnName}" TO "message_server_id"`));
20373
20857
  logger13.debug(`[Migration] ✓ Renamed ${tableName}.${oldColumnName} → message_server_id`);
20374
20858
  if (serverId.data_type === "text") {
20375
20859
  try {
20376
20860
  logger13.debug(`[Migration] → Dropping DEFAULT constraint on ${tableName}.message_server_id...`);
20377
- await db.execute(sql29.raw(`ALTER TABLE "${tableName}" ALTER COLUMN "message_server_id" DROP DEFAULT`));
20861
+ await db.execute(sql30.raw(`ALTER TABLE "${tableName}" ALTER COLUMN "message_server_id" DROP DEFAULT`));
20378
20862
  logger13.debug(`[Migration] ✓ Dropped DEFAULT constraint`);
20379
20863
  } catch {
20380
20864
  logger13.debug(`[Migration] ⊘ No DEFAULT constraint to drop on ${tableName}.message_server_id`);
20381
20865
  }
20382
20866
  try {
20383
20867
  logger13.debug(`[Migration] → Converting ${tableName}.message_server_id from text to uuid...`);
20384
- await db.execute(sql29.raw(`
20868
+ await db.execute(sql30.raw(`
20385
20869
  ALTER TABLE "${tableName}"
20386
20870
  ALTER COLUMN "message_server_id" TYPE uuid
20387
20871
  USING CASE
@@ -20398,29 +20882,29 @@ async function migrateToEntityRLS(adapter) {
20398
20882
  }
20399
20883
  }
20400
20884
  if (tableName === "channels") {
20401
- const nullCountResult = await db.execute(sql29.raw(`SELECT COUNT(*) as count FROM "${tableName}" WHERE "message_server_id" IS NULL`));
20885
+ const nullCountResult = await db.execute(sql30.raw(`SELECT COUNT(*) as count FROM "${tableName}" WHERE "message_server_id" IS NULL`));
20402
20886
  const nullCount = nullCountResult.rows?.[0]?.count;
20403
20887
  if (nullCount && parseInt(nullCount, 10) > 0) {
20404
20888
  logger13.warn(`[Migration] ⚠️ ${tableName} has ${nullCount} rows with NULL message_server_id - these will be deleted`);
20405
- await db.execute(sql29.raw(`DELETE FROM "${tableName}" WHERE "message_server_id" IS NULL`));
20889
+ await db.execute(sql30.raw(`DELETE FROM "${tableName}" WHERE "message_server_id" IS NULL`));
20406
20890
  logger13.debug(`[Migration] ✓ Deleted ${nullCount} rows with NULL message_server_id from ${tableName}`);
20407
20891
  }
20408
20892
  logger13.debug(`[Migration] → Making ${tableName}.message_server_id NOT NULL...`);
20409
- await db.execute(sql29.raw(`ALTER TABLE "${tableName}" ALTER COLUMN "message_server_id" SET NOT NULL`));
20893
+ await db.execute(sql30.raw(`ALTER TABLE "${tableName}" ALTER COLUMN "message_server_id" SET NOT NULL`));
20410
20894
  logger13.debug(`[Migration] ✓ Set ${tableName}.message_server_id NOT NULL`);
20411
20895
  }
20412
20896
  } else if (serverId && messageServerId) {
20413
20897
  logger13.debug(`[Migration] → ${tableName} has both columns, dropping ${oldColumnName}...`);
20414
- await db.execute(sql29.raw(`ALTER TABLE "${tableName}" DROP COLUMN "${oldColumnName}" CASCADE`));
20898
+ await db.execute(sql30.raw(`ALTER TABLE "${tableName}" DROP COLUMN "${oldColumnName}" CASCADE`));
20415
20899
  logger13.debug(`[Migration] ✓ Dropped ${tableName}.${oldColumnName}`);
20416
20900
  } else if (!serverId && messageServerId) {
20417
20901
  if (messageServerId.data_type === "text") {
20418
20902
  logger13.debug(`[Migration] → ${tableName}.message_server_id exists but is TEXT, needs UUID conversion...`);
20419
20903
  logger13.debug(`[Migration] → Dropping DEFAULT constraint on ${tableName}.message_server_id...`);
20420
- await db.execute(sql29.raw(`ALTER TABLE "${tableName}" ALTER COLUMN "message_server_id" DROP DEFAULT`));
20904
+ await db.execute(sql30.raw(`ALTER TABLE "${tableName}" ALTER COLUMN "message_server_id" DROP DEFAULT`));
20421
20905
  logger13.debug(`[Migration] ✓ Dropped DEFAULT constraint`);
20422
20906
  logger13.debug(`[Migration] → Converting ${tableName}.message_server_id from text to uuid (generating UUIDs from text)...`);
20423
- await db.execute(sql29.raw(`
20907
+ await db.execute(sql30.raw(`
20424
20908
  ALTER TABLE "${tableName}"
20425
20909
  ALTER COLUMN "message_server_id" TYPE uuid
20426
20910
  USING CASE
@@ -20442,7 +20926,7 @@ async function migrateToEntityRLS(adapter) {
20442
20926
  }
20443
20927
  logger13.debug("[Migration] → Dropping all remaining RLS-managed server_id columns...");
20444
20928
  try {
20445
- const serverIdColumnsResult = await db.execute(sql29`
20929
+ const serverIdColumnsResult = await db.execute(sql30`
20446
20930
  SELECT table_name
20447
20931
  FROM information_schema.columns
20448
20932
  WHERE table_schema = 'public'
@@ -20464,7 +20948,7 @@ async function migrateToEntityRLS(adapter) {
20464
20948
  for (const row of tablesToClean) {
20465
20949
  const tableName = row.table_name;
20466
20950
  try {
20467
- await db.execute(sql29.raw(`ALTER TABLE "${tableName}" DROP COLUMN IF EXISTS server_id CASCADE`));
20951
+ await db.execute(sql30.raw(`ALTER TABLE "${tableName}" DROP COLUMN IF EXISTS server_id CASCADE`));
20468
20952
  logger13.debug(`[Migration] ✓ Dropped server_id from ${tableName}`);
20469
20953
  } catch (error) {
20470
20954
  logger13.debug(`[Migration] ⊘ Could not drop server_id from ${tableName}`);
@@ -20475,7 +20959,7 @@ async function migrateToEntityRLS(adapter) {
20475
20959
  }
20476
20960
  logger13.debug("[Migration] → Checking agents.owner_id → server_id rename...");
20477
20961
  try {
20478
- const agentsColumnsResult = await db.execute(sql29`
20962
+ const agentsColumnsResult = await db.execute(sql30`
20479
20963
  SELECT column_name
20480
20964
  FROM information_schema.columns
20481
20965
  WHERE table_schema = 'public'
@@ -20488,11 +20972,11 @@ async function migrateToEntityRLS(adapter) {
20488
20972
  const hasServerId = agentsColumns.some((c) => c.column_name === "server_id");
20489
20973
  if (hasOwnerId && !hasServerId) {
20490
20974
  logger13.debug("[Migration] → Renaming agents.owner_id to server_id...");
20491
- await db.execute(sql29.raw(`ALTER TABLE "agents" RENAME COLUMN "owner_id" TO "server_id"`));
20975
+ await db.execute(sql30.raw(`ALTER TABLE "agents" RENAME COLUMN "owner_id" TO "server_id"`));
20492
20976
  logger13.debug("[Migration] ✓ Renamed agents.owner_id → server_id");
20493
20977
  } else if (hasOwnerId && hasServerId) {
20494
20978
  logger13.debug("[Migration] → Both owner_id and server_id exist, dropping owner_id...");
20495
- await db.execute(sql29.raw(`ALTER TABLE "agents" DROP COLUMN "owner_id" CASCADE`));
20979
+ await db.execute(sql30.raw(`ALTER TABLE "agents" DROP COLUMN "owner_id" CASCADE`));
20496
20980
  logger13.debug("[Migration] ✓ Dropped agents.owner_id");
20497
20981
  } else {
20498
20982
  logger13.debug("[Migration] ⊘ agents table already has server_id (or no owner_id), skipping");
@@ -20502,7 +20986,7 @@ async function migrateToEntityRLS(adapter) {
20502
20986
  }
20503
20987
  logger13.debug("[Migration] → Checking for owners → servers data migration...");
20504
20988
  try {
20505
- const ownersTableResult = await db.execute(sql29`
20989
+ const ownersTableResult = await db.execute(sql30`
20506
20990
  SELECT table_name
20507
20991
  FROM information_schema.tables
20508
20992
  WHERE table_schema = 'public'
@@ -20510,7 +20994,7 @@ async function migrateToEntityRLS(adapter) {
20510
20994
  `);
20511
20995
  if (ownersTableResult.rows && ownersTableResult.rows.length > 0) {
20512
20996
  logger13.debug("[Migration] → Ensuring servers table exists...");
20513
- await db.execute(sql29.raw(`
20997
+ await db.execute(sql30.raw(`
20514
20998
  CREATE TABLE IF NOT EXISTS "servers" (
20515
20999
  "id" uuid PRIMARY KEY,
20516
21000
  "created_at" timestamp with time zone DEFAULT now() NOT NULL,
@@ -20518,7 +21002,7 @@ async function migrateToEntityRLS(adapter) {
20518
21002
  )
20519
21003
  `));
20520
21004
  logger13.debug("[Migration] → Migrating owners data to servers...");
20521
- await db.execute(sql29.raw(`
21005
+ await db.execute(sql30.raw(`
20522
21006
  INSERT INTO "servers" ("id", "created_at", "updated_at")
20523
21007
  SELECT "id", COALESCE("created_at", now()), COALESCE("updated_at", now())
20524
21008
  FROM "owners"
@@ -20526,7 +21010,7 @@ async function migrateToEntityRLS(adapter) {
20526
21010
  `));
20527
21011
  logger13.debug("[Migration] ✓ Migrated owners data to servers");
20528
21012
  logger13.debug("[Migration] → Dropping obsolete owners table...");
20529
- await db.execute(sql29.raw(`DROP TABLE IF EXISTS "owners" CASCADE`));
21013
+ await db.execute(sql30.raw(`DROP TABLE IF EXISTS "owners" CASCADE`));
20530
21014
  logger13.debug("[Migration] ✓ Dropped obsolete owners table");
20531
21015
  } else {
20532
21016
  logger13.debug("[Migration] ⊘ owners table not found, skipping");
@@ -20536,7 +21020,7 @@ async function migrateToEntityRLS(adapter) {
20536
21020
  }
20537
21021
  logger13.debug("[Migration] → Checking server_agents table rename...");
20538
21022
  try {
20539
- const tablesResult = await db.execute(sql29`
21023
+ const tablesResult = await db.execute(sql30`
20540
21024
  SELECT table_name
20541
21025
  FROM information_schema.tables
20542
21026
  WHERE table_schema = 'public'
@@ -20548,16 +21032,16 @@ async function migrateToEntityRLS(adapter) {
20548
21032
  const hasMessageServerAgents = tables.some((t) => t.table_name === "message_server_agents");
20549
21033
  if (hasServerAgents && !hasMessageServerAgents) {
20550
21034
  logger13.debug("[Migration] → Renaming server_agents to message_server_agents...");
20551
- await db.execute(sql29.raw(`ALTER TABLE "server_agents" RENAME TO "message_server_agents"`));
21035
+ await db.execute(sql30.raw(`ALTER TABLE "server_agents" RENAME TO "message_server_agents"`));
20552
21036
  logger13.debug("[Migration] ✓ Renamed server_agents → message_server_agents");
20553
21037
  logger13.debug("[Migration] → Renaming message_server_agents.server_id to message_server_id...");
20554
- await db.execute(sql29.raw(`ALTER TABLE "message_server_agents" RENAME COLUMN "server_id" TO "message_server_id"`));
21038
+ await db.execute(sql30.raw(`ALTER TABLE "message_server_agents" RENAME COLUMN "server_id" TO "message_server_id"`));
20555
21039
  logger13.debug("[Migration] ✓ Renamed message_server_agents.server_id → message_server_id");
20556
21040
  } else if (!hasServerAgents && !hasMessageServerAgents) {
20557
21041
  logger13.debug("[Migration] ⊘ No server_agents table to migrate");
20558
21042
  } else if (hasMessageServerAgents) {
20559
21043
  logger13.debug("[Migration] → Checking message_server_agents columns...");
20560
- const columnsResult = await db.execute(sql29`
21044
+ const columnsResult = await db.execute(sql30`
20561
21045
  SELECT column_name
20562
21046
  FROM information_schema.columns
20563
21047
  WHERE table_schema = 'public'
@@ -20570,11 +21054,11 @@ async function migrateToEntityRLS(adapter) {
20570
21054
  const hasMessageServerId = columns.some((c) => c.column_name === "message_server_id");
20571
21055
  if (hasServerId && !hasMessageServerId) {
20572
21056
  logger13.debug("[Migration] → Renaming message_server_agents.server_id to message_server_id...");
20573
- await db.execute(sql29.raw(`ALTER TABLE "message_server_agents" RENAME COLUMN "server_id" TO "message_server_id"`));
21057
+ await db.execute(sql30.raw(`ALTER TABLE "message_server_agents" RENAME COLUMN "server_id" TO "message_server_id"`));
20574
21058
  logger13.debug("[Migration] ✓ Renamed message_server_agents.server_id → message_server_id");
20575
21059
  } else if (!hasServerId && !hasMessageServerId) {
20576
21060
  logger13.debug("[Migration] → message_server_agents exists without required columns, truncating...");
20577
- await db.execute(sql29`TRUNCATE TABLE message_server_agents CASCADE`);
21061
+ await db.execute(sql30`TRUNCATE TABLE message_server_agents CASCADE`);
20578
21062
  logger13.debug("[Migration] ✓ Truncated message_server_agents");
20579
21063
  } else {
20580
21064
  logger13.debug("[Migration] ⊘ message_server_agents already has correct schema");
@@ -20585,7 +21069,7 @@ async function migrateToEntityRLS(adapter) {
20585
21069
  }
20586
21070
  logger13.debug("[Migration] → Checking channel_participants table...");
20587
21071
  try {
20588
- const columnsResult = await db.execute(sql29`
21072
+ const columnsResult = await db.execute(sql30`
20589
21073
  SELECT column_name
20590
21074
  FROM information_schema.columns
20591
21075
  WHERE table_schema = 'public'
@@ -20598,11 +21082,11 @@ async function migrateToEntityRLS(adapter) {
20598
21082
  const hasEntityId = columns.some((c) => c.column_name === "entity_id");
20599
21083
  if (hasUserId && !hasEntityId) {
20600
21084
  logger13.debug("[Migration] → Renaming channel_participants.user_id to entity_id...");
20601
- await db.execute(sql29.raw(`ALTER TABLE "channel_participants" RENAME COLUMN "user_id" TO "entity_id"`));
21085
+ await db.execute(sql30.raw(`ALTER TABLE "channel_participants" RENAME COLUMN "user_id" TO "entity_id"`));
20602
21086
  logger13.debug("[Migration] ✓ Renamed channel_participants.user_id → entity_id");
20603
21087
  } else if (!hasUserId && !hasEntityId) {
20604
21088
  logger13.debug("[Migration] → channel_participants exists without entity_id or user_id, truncating...");
20605
- await db.execute(sql29`TRUNCATE TABLE channel_participants CASCADE`);
21089
+ await db.execute(sql30`TRUNCATE TABLE channel_participants CASCADE`);
20606
21090
  logger13.debug("[Migration] ✓ Truncated channel_participants");
20607
21091
  } else {
20608
21092
  logger13.debug("[Migration] ⊘ channel_participants already has entity_id column");
@@ -20612,7 +21096,7 @@ async function migrateToEntityRLS(adapter) {
20612
21096
  }
20613
21097
  logger13.debug("[Migration] → Discovering and dropping all regular indexes...");
20614
21098
  try {
20615
- const indexesResult = await db.execute(sql29`
21099
+ const indexesResult = await db.execute(sql30`
20616
21100
  SELECT i.relname AS index_name
20617
21101
  FROM pg_index idx
20618
21102
  JOIN pg_class i ON i.oid = idx.indexrelid
@@ -20629,7 +21113,7 @@ async function migrateToEntityRLS(adapter) {
20629
21113
  for (const row of indexesToDrop) {
20630
21114
  const indexName = row.index_name;
20631
21115
  try {
20632
- await db.execute(sql29.raw(`DROP INDEX IF EXISTS "${indexName}"`));
21116
+ await db.execute(sql30.raw(`DROP INDEX IF EXISTS "${indexName}"`));
20633
21117
  logger13.debug(`[Migration] ✓ Dropped index ${indexName}`);
20634
21118
  } catch (error) {
20635
21119
  logger13.debug(`[Migration] ⊘ Could not drop index ${indexName}`);
@@ -20686,14 +21170,14 @@ async function migrateToEntityRLS(adapter) {
20686
21170
  ];
20687
21171
  for (const rename of columnRenames) {
20688
21172
  try {
20689
- const tableExistsResult = await db.execute(sql29`
21173
+ const tableExistsResult = await db.execute(sql30`
20690
21174
  SELECT 1 FROM information_schema.tables
20691
21175
  WHERE table_schema = 'public' AND table_name = ${rename.table}
20692
21176
  `);
20693
21177
  if (!tableExistsResult.rows || tableExistsResult.rows.length === 0) {
20694
21178
  continue;
20695
21179
  }
20696
- const columnsResult = await db.execute(sql29`
21180
+ const columnsResult = await db.execute(sql30`
20697
21181
  SELECT column_name
20698
21182
  FROM information_schema.columns
20699
21183
  WHERE table_schema = 'public'
@@ -20706,11 +21190,11 @@ async function migrateToEntityRLS(adapter) {
20706
21190
  const hasNewColumn = columns.some((c) => c.column_name === rename.to);
20707
21191
  if (hasOldColumn && !hasNewColumn) {
20708
21192
  logger13.debug(`[Migration] → Renaming ${rename.table}.${rename.from} to ${rename.to}...`);
20709
- await db.execute(sql29.raw(`ALTER TABLE "${rename.table}" RENAME COLUMN "${rename.from}" TO "${rename.to}"`));
21193
+ await db.execute(sql30.raw(`ALTER TABLE "${rename.table}" RENAME COLUMN "${rename.from}" TO "${rename.to}"`));
20710
21194
  logger13.debug(`[Migration] ✓ Renamed ${rename.table}.${rename.from} → ${rename.to}`);
20711
21195
  } else if (hasOldColumn && hasNewColumn) {
20712
21196
  logger13.debug(`[Migration] → Both columns exist, dropping ${rename.table}.${rename.from}...`);
20713
- await db.execute(sql29.raw(`ALTER TABLE "${rename.table}" DROP COLUMN "${rename.from}" CASCADE`));
21197
+ await db.execute(sql30.raw(`ALTER TABLE "${rename.table}" DROP COLUMN "${rename.from}" CASCADE`));
20714
21198
  logger13.debug(`[Migration] ✓ Dropped ${rename.table}.${rename.from}`);
20715
21199
  }
20716
21200
  } catch (error) {
@@ -20728,17 +21212,17 @@ var init_migrations = () => {};
20728
21212
 
20729
21213
  // src/rls.ts
20730
21214
  import { logger as logger14, validateUuid } from "@elizaos/core";
20731
- import { sql as sql30, eq as eq13 } from "drizzle-orm";
21215
+ import { sql as sql31, eq as eq13 } from "drizzle-orm";
20732
21216
  async function installRLSFunctions(adapter) {
20733
21217
  const db = getDb(adapter);
20734
- await db.execute(sql30`
21218
+ await db.execute(sql31`
20735
21219
  CREATE TABLE IF NOT EXISTS servers (
20736
21220
  id UUID PRIMARY KEY,
20737
21221
  created_at TIMESTAMPTZ DEFAULT NOW() NOT NULL,
20738
21222
  updated_at TIMESTAMPTZ DEFAULT NOW() NOT NULL
20739
21223
  )
20740
21224
  `);
20741
- await db.execute(sql30`
21225
+ await db.execute(sql31`
20742
21226
  CREATE OR REPLACE FUNCTION current_server_id() RETURNS UUID AS $$
20743
21227
  DECLARE
20744
21228
  server_id_text TEXT;
@@ -20757,7 +21241,7 @@ async function installRLSFunctions(adapter) {
20757
21241
  END;
20758
21242
  $$ LANGUAGE plpgsql STABLE;
20759
21243
  `);
20760
- await db.execute(sql30`
21244
+ await db.execute(sql31`
20761
21245
  CREATE OR REPLACE FUNCTION add_server_isolation(
20762
21246
  schema_name text,
20763
21247
  table_name text
@@ -20820,7 +21304,7 @@ async function installRLSFunctions(adapter) {
20820
21304
  END;
20821
21305
  $$ LANGUAGE plpgsql;
20822
21306
  `);
20823
- await db.execute(sql30`
21307
+ await db.execute(sql31`
20824
21308
  CREATE OR REPLACE FUNCTION apply_rls_to_all_tables() RETURNS void AS $$
20825
21309
  DECLARE
20826
21310
  tbl record;
@@ -20850,7 +21334,7 @@ async function installRLSFunctions(adapter) {
20850
21334
  async function applyRLSToNewTables(adapter) {
20851
21335
  const db = getDb(adapter);
20852
21336
  try {
20853
- await db.execute(sql30`SELECT apply_rls_to_all_tables()`);
21337
+ await db.execute(sql31`SELECT apply_rls_to_all_tables()`);
20854
21338
  logger14.info({ src: "plugin:sql" }, "RLS applied to all tables");
20855
21339
  } catch (error) {
20856
21340
  logger14.warn({ src: "plugin:sql", error: String(error) }, "Failed to apply RLS to some tables");
@@ -20859,7 +21343,7 @@ async function applyRLSToNewTables(adapter) {
20859
21343
  async function installEntityRLS(adapter) {
20860
21344
  const db = getDb(adapter);
20861
21345
  logger14.info("[Entity RLS] Installing entity RLS functions and policies...");
20862
- await db.execute(sql30`
21346
+ await db.execute(sql31`
20863
21347
  CREATE OR REPLACE FUNCTION current_entity_id()
20864
21348
  RETURNS UUID AS $$
20865
21349
  DECLARE
@@ -20881,7 +21365,7 @@ async function installEntityRLS(adapter) {
20881
21365
  $$ LANGUAGE plpgsql STABLE;
20882
21366
  `);
20883
21367
  logger14.info("[Entity RLS] Created current_entity_id() function");
20884
- await db.execute(sql30`
21368
+ await db.execute(sql31`
20885
21369
  CREATE OR REPLACE FUNCTION add_entity_isolation(
20886
21370
  schema_name text,
20887
21371
  table_name text,
@@ -21061,7 +21545,7 @@ async function installEntityRLS(adapter) {
21061
21545
  $$ LANGUAGE plpgsql;
21062
21546
  `);
21063
21547
  logger14.info("[Entity RLS] Created add_entity_isolation() function");
21064
- await db.execute(sql30`
21548
+ await db.execute(sql31`
21065
21549
  CREATE OR REPLACE FUNCTION apply_entity_rls_to_all_tables() RETURNS void AS $$
21066
21550
  DECLARE
21067
21551
  tbl record;
@@ -21107,7 +21591,7 @@ async function installEntityRLS(adapter) {
21107
21591
  async function applyEntityRLSToAllTables(adapter) {
21108
21592
  const db = getDb(adapter);
21109
21593
  try {
21110
- await db.execute(sql30`SELECT apply_entity_rls_to_all_tables()`);
21594
+ await db.execute(sql31`SELECT apply_entity_rls_to_all_tables()`);
21111
21595
  logger14.info("[Entity RLS] Applied entity RLS to all eligible tables");
21112
21596
  } catch (error) {
21113
21597
  logger14.warn("[Entity RLS] Failed to apply entity RLS to some tables:", String(error));
@@ -21233,391 +21717,14 @@ import { logger as logger17 } from "@elizaos/core";
21233
21717
  import { drizzle } from "drizzle-orm/pglite";
21234
21718
 
21235
21719
  // src/base.ts
21720
+ init_embedding();
21721
+ init_schema();
21236
21722
  import {
21237
21723
  DatabaseAdapter,
21238
21724
  logger as logger16
21239
21725
  } from "@elizaos/core";
21240
- import { and as and11, eq as eq14, inArray as inArray5, sql as sql31 } from "drizzle-orm";
21241
-
21242
- // src/schema/embedding.ts
21243
- import { sql as sql5 } from "drizzle-orm";
21244
- import { check as check2, foreignKey as foreignKey2, index as index2, pgTable as pgTable5, timestamp as timestamp5, uuid as uuid5, vector } from "drizzle-orm/pg-core";
21245
- import { VECTOR_DIMS } from "@elizaos/core";
21246
-
21247
- // src/schema/memory.ts
21248
- init_agent();
21249
- import { relations, sql as sql4 } from "drizzle-orm";
21250
- import {
21251
- boolean as boolean2,
21252
- check,
21253
- foreignKey,
21254
- index,
21255
- jsonb as jsonb4,
21256
- pgTable as pgTable4,
21257
- text as text4,
21258
- timestamp as timestamp4,
21259
- uuid as uuid4
21260
- } from "drizzle-orm/pg-core";
21261
-
21262
- // src/schema/entity.ts
21263
- init_agent();
21264
- import { sql as sql2 } from "drizzle-orm";
21265
- import { jsonb as jsonb2, pgTable as pgTable2, text as text2, timestamp as timestamp2, unique, uuid as uuid2 } from "drizzle-orm/pg-core";
21266
- var entityTable = pgTable2("entities", {
21267
- id: uuid2("id").notNull().primaryKey(),
21268
- agentId: uuid2("agent_id").notNull().references(() => agentTable.id, {
21269
- onDelete: "cascade"
21270
- }),
21271
- createdAt: timestamp2("created_at").default(sql2`now()`).notNull(),
21272
- names: text2("names").array().default(sql2`'{}'::text[]`).notNull(),
21273
- metadata: jsonb2("metadata").$type().default(sql2`'{}'::jsonb`).notNull()
21274
- }, (table) => {
21275
- return {
21276
- idAgentIdUnique: unique("id_agent_id_unique").on(table.id, table.agentId)
21277
- };
21278
- });
21279
-
21280
- // src/schema/room.ts
21281
- init_agent();
21282
- import { sql as sql3 } from "drizzle-orm";
21283
- import { jsonb as jsonb3, pgTable as pgTable3, text as text3, timestamp as timestamp3, uuid as uuid3 } from "drizzle-orm/pg-core";
21284
- var roomTable = pgTable3("rooms", {
21285
- id: uuid3("id").notNull().primaryKey().default(sql3`gen_random_uuid()`),
21286
- agentId: uuid3("agent_id").references(() => agentTable.id, {
21287
- onDelete: "cascade"
21288
- }),
21289
- source: text3("source").notNull(),
21290
- type: text3("type").notNull(),
21291
- messageServerId: uuid3("message_server_id"),
21292
- worldId: uuid3("world_id"),
21293
- name: text3("name"),
21294
- metadata: jsonb3("metadata").$type(),
21295
- channelId: text3("channel_id"),
21296
- createdAt: timestamp3("created_at").default(sql3`now()`).notNull()
21297
- });
21298
-
21299
- // src/schema/memory.ts
21300
- var memoryTable = pgTable4("memories", {
21301
- id: uuid4("id").primaryKey().notNull(),
21302
- type: text4("type").notNull(),
21303
- createdAt: timestamp4("created_at").default(sql4`now()`).notNull(),
21304
- content: jsonb4("content").$type().notNull(),
21305
- entityId: uuid4("entity_id").references(() => entityTable.id, {
21306
- onDelete: "cascade"
21307
- }),
21308
- agentId: uuid4("agent_id").references(() => agentTable.id, {
21309
- onDelete: "cascade"
21310
- }).notNull(),
21311
- roomId: uuid4("room_id").references(() => roomTable.id, {
21312
- onDelete: "cascade"
21313
- }),
21314
- worldId: uuid4("world_id"),
21315
- unique: boolean2("unique").default(true).notNull(),
21316
- metadata: jsonb4("metadata").$type().default({}).notNull()
21317
- }, (table) => [
21318
- index("idx_memories_type_room").on(table.type, table.roomId),
21319
- index("idx_memories_world_id").on(table.worldId),
21320
- foreignKey({
21321
- name: "fk_room",
21322
- columns: [table.roomId],
21323
- foreignColumns: [roomTable.id]
21324
- }).onDelete("cascade"),
21325
- foreignKey({
21326
- name: "fk_user",
21327
- columns: [table.entityId],
21328
- foreignColumns: [entityTable.id]
21329
- }).onDelete("cascade"),
21330
- foreignKey({
21331
- name: "fk_agent",
21332
- columns: [table.agentId],
21333
- foreignColumns: [agentTable.id]
21334
- }).onDelete("cascade"),
21335
- index("idx_memories_metadata_type").on(sql4`((metadata->>'type'))`),
21336
- index("idx_memories_document_id").on(sql4`((metadata->>'documentId'))`),
21337
- index("idx_fragments_order").on(sql4`((metadata->>'documentId'))`, sql4`((metadata->>'position'))`),
21338
- check("fragment_metadata_check", sql4`
21339
- CASE
21340
- WHEN metadata->>'type' = 'fragment' THEN
21341
- metadata ? 'documentId' AND
21342
- metadata ? 'position'
21343
- ELSE true
21344
- END
21345
- `),
21346
- check("document_metadata_check", sql4`
21347
- CASE
21348
- WHEN metadata->>'type' = 'document' THEN
21349
- metadata ? 'timestamp'
21350
- ELSE true
21351
- END
21352
- `)
21353
- ]);
21354
- var memoryRelations = relations(memoryTable, ({ one }) => ({
21355
- embedding: one(embeddingTable)
21356
- }));
21357
-
21358
- // src/schema/embedding.ts
21359
- var DIMENSION_MAP = {
21360
- [VECTOR_DIMS.SMALL]: "dim384",
21361
- [VECTOR_DIMS.MEDIUM]: "dim512",
21362
- [VECTOR_DIMS.LARGE]: "dim768",
21363
- [VECTOR_DIMS.XL]: "dim1024",
21364
- [VECTOR_DIMS.XXL]: "dim1536",
21365
- [VECTOR_DIMS.XXXL]: "dim3072"
21366
- };
21367
- var embeddingTable = pgTable5("embeddings", {
21368
- id: uuid5("id").primaryKey().defaultRandom().notNull(),
21369
- memoryId: uuid5("memory_id").references(() => memoryTable.id, { onDelete: "cascade" }),
21370
- createdAt: timestamp5("created_at").default(sql5`now()`).notNull(),
21371
- dim384: vector("dim_384", { dimensions: VECTOR_DIMS.SMALL }),
21372
- dim512: vector("dim_512", { dimensions: VECTOR_DIMS.MEDIUM }),
21373
- dim768: vector("dim_768", { dimensions: VECTOR_DIMS.LARGE }),
21374
- dim1024: vector("dim_1024", { dimensions: VECTOR_DIMS.XL }),
21375
- dim1536: vector("dim_1536", { dimensions: VECTOR_DIMS.XXL }),
21376
- dim3072: vector("dim_3072", { dimensions: VECTOR_DIMS.XXXL })
21377
- }, (table) => [
21378
- check2("embedding_source_check", sql5`"memory_id" IS NOT NULL`),
21379
- index2("idx_embedding_memory").on(table.memoryId),
21380
- foreignKey2({
21381
- name: "fk_embedding_memory",
21382
- columns: [table.memoryId],
21383
- foreignColumns: [memoryTable.id]
21384
- }).onDelete("cascade")
21385
- ]);
21386
-
21387
- // src/schema/index.ts
21388
- init_agent();
21389
- var exports_schema = {};
21390
- __export(exports_schema, {
21391
- worldTable: () => worldTable,
21392
- taskTable: () => taskTable,
21393
- serverTable: () => serverTable,
21394
- roomTable: () => roomTable,
21395
- relationshipTable: () => relationshipTable,
21396
- participantTable: () => participantTable,
21397
- messageTable: () => messageTable,
21398
- messageServerTable: () => messageServerTable,
21399
- messageServerAgentsTable: () => messageServerAgentsTable,
21400
- memoryTable: () => memoryTable,
21401
- logTable: () => logTable,
21402
- entityTable: () => entityTable,
21403
- embeddingTable: () => embeddingTable,
21404
- componentTable: () => componentTable,
21405
- channelTable: () => channelTable,
21406
- channelParticipantsTable: () => channelParticipantsTable,
21407
- cacheTable: () => cacheTable,
21408
- agentTable: () => agentTable
21409
- });
21726
+ import { and as and11, eq as eq14, inArray as inArray5, sql as sql32 } from "drizzle-orm";
21410
21727
 
21411
- // src/schema/cache.ts
21412
- init_agent();
21413
- import { sql as sql6 } from "drizzle-orm";
21414
- import { jsonb as jsonb5, pgTable as pgTable6, text as text5, primaryKey, timestamp as timestamp6, uuid as uuid6 } from "drizzle-orm/pg-core";
21415
- var cacheTable = pgTable6("cache", {
21416
- key: text5("key").notNull(),
21417
- agentId: uuid6("agent_id").notNull().references(() => agentTable.id, { onDelete: "cascade" }),
21418
- value: jsonb5("value").notNull(),
21419
- createdAt: timestamp6("created_at", { withTimezone: true }).default(sql6`now()`).notNull(),
21420
- expiresAt: timestamp6("expires_at", { withTimezone: true })
21421
- }, (table) => [primaryKey({ columns: [table.key, table.agentId] })]);
21422
- // src/schema/component.ts
21423
- init_agent();
21424
- import { sql as sql8 } from "drizzle-orm";
21425
- import { jsonb as jsonb7, pgTable as pgTable8, text as text7, timestamp as timestamp8, uuid as uuid8 } from "drizzle-orm/pg-core";
21426
-
21427
- // src/schema/world.ts
21428
- init_agent();
21429
- import { sql as sql7 } from "drizzle-orm";
21430
- import { jsonb as jsonb6, pgTable as pgTable7, text as text6, timestamp as timestamp7, uuid as uuid7 } from "drizzle-orm/pg-core";
21431
- var worldTable = pgTable7("worlds", {
21432
- id: uuid7("id").notNull().primaryKey().default(sql7`gen_random_uuid()`),
21433
- agentId: uuid7("agent_id").notNull().references(() => agentTable.id, { onDelete: "cascade" }),
21434
- name: text6("name").notNull(),
21435
- metadata: jsonb6("metadata").$type(),
21436
- messageServerId: uuid7("message_server_id"),
21437
- createdAt: timestamp7("created_at").default(sql7`now()`).notNull()
21438
- });
21439
-
21440
- // src/schema/component.ts
21441
- var componentTable = pgTable8("components", {
21442
- id: uuid8("id").primaryKey().default(sql8`gen_random_uuid()`).notNull(),
21443
- entityId: uuid8("entity_id").references(() => entityTable.id, { onDelete: "cascade" }).notNull(),
21444
- agentId: uuid8("agent_id").references(() => agentTable.id, { onDelete: "cascade" }).notNull(),
21445
- roomId: uuid8("room_id").references(() => roomTable.id, { onDelete: "cascade" }).notNull(),
21446
- worldId: uuid8("world_id").references(() => worldTable.id, { onDelete: "cascade" }),
21447
- sourceEntityId: uuid8("source_entity_id").references(() => entityTable.id, {
21448
- onDelete: "cascade"
21449
- }),
21450
- type: text7("type").notNull(),
21451
- data: jsonb7("data").default(sql8`'{}'::jsonb`),
21452
- createdAt: timestamp8("created_at").default(sql8`now()`).notNull()
21453
- });
21454
- // src/schema/log.ts
21455
- import { sql as sql9 } from "drizzle-orm";
21456
- import { foreignKey as foreignKey3, jsonb as jsonb8, pgTable as pgTable9, text as text8, timestamp as timestamp9, uuid as uuid9 } from "drizzle-orm/pg-core";
21457
- var logTable = pgTable9("logs", {
21458
- id: uuid9("id").defaultRandom().notNull(),
21459
- createdAt: timestamp9("created_at", { withTimezone: true }).default(sql9`now()`).notNull(),
21460
- entityId: uuid9("entity_id").notNull().references(() => entityTable.id, { onDelete: "cascade" }),
21461
- body: jsonb8("body").notNull(),
21462
- type: text8("type").notNull(),
21463
- roomId: uuid9("room_id").notNull().references(() => roomTable.id, { onDelete: "cascade" })
21464
- }, (table) => [
21465
- foreignKey3({
21466
- name: "fk_room",
21467
- columns: [table.roomId],
21468
- foreignColumns: [roomTable.id]
21469
- }).onDelete("cascade"),
21470
- foreignKey3({
21471
- name: "fk_user",
21472
- columns: [table.entityId],
21473
- foreignColumns: [entityTable.id]
21474
- }).onDelete("cascade")
21475
- ]);
21476
-
21477
- // src/schema/index.ts
21478
- init_server();
21479
-
21480
- // src/schema/participant.ts
21481
- init_agent();
21482
- import { sql as sql11 } from "drizzle-orm";
21483
- import { foreignKey as foreignKey4, index as index3, pgTable as pgTable11, text as text9, timestamp as timestamp11, uuid as uuid11 } from "drizzle-orm/pg-core";
21484
- var participantTable = pgTable11("participants", {
21485
- id: uuid11("id").notNull().primaryKey().default(sql11`gen_random_uuid()`),
21486
- createdAt: timestamp11("created_at", { withTimezone: true }).default(sql11`now()`).notNull(),
21487
- entityId: uuid11("entity_id").references(() => entityTable.id, {
21488
- onDelete: "cascade"
21489
- }),
21490
- roomId: uuid11("room_id").references(() => roomTable.id, {
21491
- onDelete: "cascade"
21492
- }),
21493
- agentId: uuid11("agent_id").references(() => agentTable.id, {
21494
- onDelete: "cascade"
21495
- }),
21496
- roomState: text9("room_state")
21497
- }, (table) => [
21498
- index3("idx_participants_user").on(table.entityId),
21499
- index3("idx_participants_room").on(table.roomId),
21500
- foreignKey4({
21501
- name: "fk_room",
21502
- columns: [table.roomId],
21503
- foreignColumns: [roomTable.id]
21504
- }).onDelete("cascade"),
21505
- foreignKey4({
21506
- name: "fk_user",
21507
- columns: [table.entityId],
21508
- foreignColumns: [entityTable.id]
21509
- }).onDelete("cascade")
21510
- ]);
21511
- // src/schema/relationship.ts
21512
- init_agent();
21513
- import { sql as sql12 } from "drizzle-orm";
21514
- import {
21515
- foreignKey as foreignKey5,
21516
- index as index4,
21517
- jsonb as jsonb9,
21518
- pgTable as pgTable12,
21519
- text as text10,
21520
- timestamp as timestamp12,
21521
- unique as unique2,
21522
- uuid as uuid12
21523
- } from "drizzle-orm/pg-core";
21524
- var relationshipTable = pgTable12("relationships", {
21525
- id: uuid12("id").notNull().primaryKey().default(sql12`gen_random_uuid()`),
21526
- createdAt: timestamp12("created_at", { withTimezone: true }).default(sql12`now()`).notNull(),
21527
- sourceEntityId: uuid12("source_entity_id").notNull().references(() => entityTable.id, { onDelete: "cascade" }),
21528
- targetEntityId: uuid12("target_entity_id").notNull().references(() => entityTable.id, { onDelete: "cascade" }),
21529
- agentId: uuid12("agent_id").notNull().references(() => agentTable.id, { onDelete: "cascade" }),
21530
- tags: text10("tags").array(),
21531
- metadata: jsonb9("metadata").$type()
21532
- }, (table) => [
21533
- index4("idx_relationships_users").on(table.sourceEntityId, table.targetEntityId),
21534
- unique2("unique_relationship").on(table.sourceEntityId, table.targetEntityId, table.agentId),
21535
- foreignKey5({
21536
- name: "fk_user_a",
21537
- columns: [table.sourceEntityId],
21538
- foreignColumns: [entityTable.id]
21539
- }).onDelete("cascade"),
21540
- foreignKey5({
21541
- name: "fk_user_b",
21542
- columns: [table.targetEntityId],
21543
- foreignColumns: [entityTable.id]
21544
- }).onDelete("cascade")
21545
- ]);
21546
- // src/schema/tasks.ts
21547
- init_agent();
21548
- import { jsonb as jsonb10, pgTable as pgTable13, text as text11, timestamp as timestamp13, uuid as uuid13 } from "drizzle-orm/pg-core";
21549
- import { sql as sql13 } from "drizzle-orm";
21550
- var taskTable = pgTable13("tasks", {
21551
- id: uuid13("id").primaryKey().defaultRandom(),
21552
- name: text11("name").notNull(),
21553
- description: text11("description"),
21554
- roomId: uuid13("room_id"),
21555
- worldId: uuid13("world_id"),
21556
- entityId: uuid13("entity_id"),
21557
- agentId: uuid13("agent_id").notNull().references(() => agentTable.id, { onDelete: "cascade" }),
21558
- tags: text11("tags").array().default(sql13`'{}'::text[]`),
21559
- metadata: jsonb10("metadata").$type().default(sql13`'{}'::jsonb`),
21560
- createdAt: timestamp13("created_at", { withTimezone: true }).defaultNow(),
21561
- updatedAt: timestamp13("updated_at", { withTimezone: true }).defaultNow()
21562
- });
21563
- // src/schema/messageServer.ts
21564
- import { pgTable as pgTable14, text as text12, jsonb as jsonb11, timestamp as timestamp14, uuid as uuid14 } from "drizzle-orm/pg-core";
21565
- import { sql as sql14 } from "drizzle-orm";
21566
- var messageServerTable = pgTable14("message_servers", {
21567
- id: uuid14("id").primaryKey(),
21568
- name: text12("name").notNull(),
21569
- sourceType: text12("source_type").notNull(),
21570
- sourceId: text12("source_id"),
21571
- metadata: jsonb11("metadata").$type(),
21572
- createdAt: timestamp14("created_at", { mode: "date" }).default(sql14`CURRENT_TIMESTAMP`).notNull(),
21573
- updatedAt: timestamp14("updated_at", { mode: "date" }).default(sql14`CURRENT_TIMESTAMP`).notNull()
21574
- });
21575
- // src/schema/channel.ts
21576
- import { pgTable as pgTable15, text as text13, jsonb as jsonb12, timestamp as timestamp15, uuid as uuid15 } from "drizzle-orm/pg-core";
21577
- import { sql as sql15 } from "drizzle-orm";
21578
- var channelTable = pgTable15("channels", {
21579
- id: text13("id").primaryKey(),
21580
- messageServerId: uuid15("message_server_id").notNull().references(() => messageServerTable.id, { onDelete: "cascade" }),
21581
- name: text13("name").notNull(),
21582
- type: text13("type").notNull(),
21583
- sourceType: text13("source_type"),
21584
- sourceId: text13("source_id"),
21585
- topic: text13("topic"),
21586
- metadata: jsonb12("metadata").$type(),
21587
- createdAt: timestamp15("created_at", { mode: "date" }).default(sql15`CURRENT_TIMESTAMP`).notNull(),
21588
- updatedAt: timestamp15("updated_at", { mode: "date" }).default(sql15`CURRENT_TIMESTAMP`).notNull()
21589
- });
21590
- // src/schema/message.ts
21591
- import { pgTable as pgTable16, text as text14, jsonb as jsonb13, timestamp as timestamp16 } from "drizzle-orm/pg-core";
21592
- import { sql as sql16 } from "drizzle-orm";
21593
- var messageTable = pgTable16("central_messages", {
21594
- id: text14("id").primaryKey(),
21595
- channelId: text14("channel_id").notNull().references(() => channelTable.id, { onDelete: "cascade" }),
21596
- authorId: text14("author_id").notNull(),
21597
- content: text14("content").notNull(),
21598
- rawMessage: jsonb13("raw_message"),
21599
- inReplyToRootMessageId: text14("in_reply_to_root_message_id").references(() => messageTable.id, {
21600
- onDelete: "set null"
21601
- }),
21602
- sourceType: text14("source_type"),
21603
- sourceId: text14("source_id"),
21604
- metadata: jsonb13("metadata").$type(),
21605
- createdAt: timestamp16("created_at", { mode: "date" }).default(sql16`CURRENT_TIMESTAMP`).notNull(),
21606
- updatedAt: timestamp16("updated_at", { mode: "date" }).default(sql16`CURRENT_TIMESTAMP`).notNull()
21607
- });
21608
- // src/schema/channelParticipant.ts
21609
- import { pgTable as pgTable17, text as text15, primaryKey as primaryKey2 } from "drizzle-orm/pg-core";
21610
- var channelParticipantsTable = pgTable17("channel_participants", {
21611
- channelId: text15("channel_id").notNull().references(() => channelTable.id, { onDelete: "cascade" }),
21612
- entityId: text15("entity_id").notNull()
21613
- }, (table) => [primaryKey2({ columns: [table.channelId, table.entityId] })]);
21614
- // src/schema/messageServerAgent.ts
21615
- import { pgTable as pgTable18, uuid as uuid16, primaryKey as primaryKey3 } from "drizzle-orm/pg-core";
21616
- init_agent();
21617
- var messageServerAgentsTable = pgTable18("message_server_agents", {
21618
- messageServerId: uuid16("message_server_id").notNull().references(() => messageServerTable.id, { onDelete: "cascade" }),
21619
- agentId: uuid16("agent_id").notNull().references(() => agentTable.id, { onDelete: "cascade" })
21620
- }, (table) => [primaryKey3({ columns: [table.messageServerId, table.agentId] })]);
21621
21728
  // src/utils.ts
21622
21729
  function sanitizeJsonObject(value, seen = new WeakSet) {
21623
21730
  if (value === null || value === undefined) {
@@ -21647,8 +21754,10 @@ function sanitizeJsonObject(value, seen = new WeakSet) {
21647
21754
  }
21648
21755
 
21649
21756
  // src/stores/agent.store.ts
21757
+ init_schema();
21650
21758
  import { logger } from "@elizaos/core";
21651
21759
  import { count, eq } from "drizzle-orm";
21760
+
21652
21761
  class AgentStore {
21653
21762
  ctx;
21654
21763
  constructor(ctx) {
@@ -21835,7 +21944,7 @@ class AgentStore {
21835
21944
 
21836
21945
  // src/stores/memory.store.ts
21837
21946
  import { logger as logger2 } from "@elizaos/core";
21838
- import { and, cosineDistance, desc, eq as eq2, gte, inArray, lte, sql as sql17 } from "drizzle-orm";
21947
+ import { and, cosineDistance, desc, eq as eq2, gte, inArray, lte, sql as sql18 } from "drizzle-orm";
21839
21948
 
21840
21949
  // ../../node_modules/uuid/dist/stringify.js
21841
21950
  var byteToHex = [];
@@ -21892,6 +22001,8 @@ function v4(options, buf, offset) {
21892
22001
  }
21893
22002
  var v4_default = v4;
21894
22003
  // src/stores/memory.store.ts
22004
+ init_schema();
22005
+
21895
22006
  class MemoryStore {
21896
22007
  ctx;
21897
22008
  constructor(ctx) {
@@ -22046,7 +22157,7 @@ class MemoryStore {
22046
22157
  async searchByEmbedding(embedding, params) {
22047
22158
  return this.ctx.withRetry(async () => {
22048
22159
  const cleanVector = embedding.map((n) => Number.isFinite(n) ? Number(n.toFixed(6)) : 0);
22049
- const similarity = sql17`1 - (${cosineDistance(embeddingTable[this.ctx.getEmbeddingDimension()], cleanVector)})`;
22160
+ const similarity = sql18`1 - (${cosineDistance(embeddingTable[this.ctx.getEmbeddingDimension()], cleanVector)})`;
22050
22161
  const conditions = [
22051
22162
  eq2(memoryTable.type, params.tableName),
22052
22163
  eq2(memoryTable.agentId, this.ctx.agentId)
@@ -22105,8 +22216,8 @@ class MemoryStore {
22105
22216
  {
22106
22217
  id: memoryId,
22107
22218
  type: tableName,
22108
- content: sql17`${contentToInsert}::jsonb`,
22109
- metadata: sql17`${metadataToInsert}::jsonb`,
22219
+ content: sql18`${contentToInsert}::jsonb`,
22220
+ metadata: sql18`${metadataToInsert}::jsonb`,
22110
22221
  entityId: memory.entityId,
22111
22222
  roomId: memory.roomId,
22112
22223
  worldId: memory.worldId,
@@ -22129,12 +22240,12 @@ class MemoryStore {
22129
22240
  const contentToUpdate = typeof memory.content === "string" ? memory.content : JSON.stringify(memory.content ?? {});
22130
22241
  const metadataToUpdate = typeof memory.metadata === "string" ? memory.metadata : JSON.stringify(memory.metadata ?? {});
22131
22242
  await tx.update(memoryTable).set({
22132
- content: sql17`${contentToUpdate}::jsonb`,
22133
- ...memory.metadata && { metadata: sql17`${metadataToUpdate}::jsonb` }
22243
+ content: sql18`${contentToUpdate}::jsonb`,
22244
+ ...memory.metadata && { metadata: sql18`${metadataToUpdate}::jsonb` }
22134
22245
  }).where(eq2(memoryTable.id, memory.id));
22135
22246
  } else if (memory.metadata) {
22136
22247
  const metadataToUpdate = typeof memory.metadata === "string" ? memory.metadata : JSON.stringify(memory.metadata ?? {});
22137
- await tx.update(memoryTable).set({ metadata: sql17`${metadataToUpdate}::jsonb` }).where(eq2(memoryTable.id, memory.id));
22248
+ await tx.update(memoryTable).set({ metadata: sql18`${metadataToUpdate}::jsonb` }).where(eq2(memoryTable.id, memory.id));
22138
22249
  }
22139
22250
  if (memory.embedding && Array.isArray(memory.embedding)) {
22140
22251
  await this.upsertEmbedding(tx, memory.id, memory.embedding);
@@ -22197,7 +22308,7 @@ class MemoryStore {
22197
22308
  const conditions = [eq2(memoryTable.roomId, roomId), eq2(memoryTable.type, tableName)];
22198
22309
  if (unique3)
22199
22310
  conditions.push(eq2(memoryTable.unique, true));
22200
- const result = await this.db.select({ count: sql17`count(*)` }).from(memoryTable).where(and(...conditions));
22311
+ const result = await this.db.select({ count: sql18`count(*)` }).from(memoryTable).where(and(...conditions));
22201
22312
  return Number(result[0]?.count ?? 0);
22202
22313
  }, "MemoryStore.count");
22203
22314
  }
@@ -22215,7 +22326,7 @@ class MemoryStore {
22215
22326
  }
22216
22327
  }
22217
22328
  async deleteFragments(tx, documentId) {
22218
- const fragments = await tx.select({ id: memoryTable.id }).from(memoryTable).where(and(eq2(memoryTable.agentId, this.ctx.agentId), sql17`${memoryTable.metadata}->>'documentId' = ${documentId}`));
22329
+ const fragments = await tx.select({ id: memoryTable.id }).from(memoryTable).where(and(eq2(memoryTable.agentId, this.ctx.agentId), sql18`${memoryTable.metadata}->>'documentId' = ${documentId}`));
22219
22330
  if (fragments.length > 0) {
22220
22331
  const fragmentIds = fragments.map((f) => f.id);
22221
22332
  await tx.delete(embeddingTable).where(inArray(embeddingTable.memoryId, fragmentIds));
@@ -22226,6 +22337,8 @@ class MemoryStore {
22226
22337
 
22227
22338
  // src/stores/room.store.ts
22228
22339
  import { and as and2, eq as eq3, inArray as inArray2 } from "drizzle-orm";
22340
+ init_schema();
22341
+
22229
22342
  class RoomStore {
22230
22343
  ctx;
22231
22344
  constructor(ctx) {
@@ -22311,8 +22424,10 @@ class RoomStore {
22311
22424
  }
22312
22425
 
22313
22426
  // src/stores/participant.store.ts
22427
+ init_schema();
22314
22428
  import { logger as logger3 } from "@elizaos/core";
22315
22429
  import { and as and3, eq as eq4, inArray as inArray3 } from "drizzle-orm";
22430
+
22316
22431
  class ParticipantStore {
22317
22432
  ctx;
22318
22433
  constructor(ctx) {
@@ -22446,8 +22561,10 @@ class ParticipantStore {
22446
22561
  }
22447
22562
 
22448
22563
  // src/stores/entity.store.ts
22564
+ init_schema();
22449
22565
  import { logger as logger4 } from "@elizaos/core";
22450
- import { and as and4, eq as eq5, inArray as inArray4, or, sql as sql18 } from "drizzle-orm";
22566
+ import { and as and4, eq as eq5, inArray as inArray4, or, sql as sql19 } from "drizzle-orm";
22567
+
22451
22568
  class EntityStore {
22452
22569
  ctx;
22453
22570
  constructor(ctx) {
@@ -22584,11 +22701,11 @@ class EntityStore {
22584
22701
  async getByNames(params) {
22585
22702
  return this.ctx.withRetry(async () => {
22586
22703
  const { names, agentId } = params;
22587
- const nameConditions = names.map((name) => sql18`${name} = ANY(${entityTable.names})`);
22588
- const query = sql18`
22704
+ const nameConditions = names.map((name) => sql19`${name} = ANY(${entityTable.names})`);
22705
+ const query = sql19`
22589
22706
  SELECT * FROM ${entityTable}
22590
22707
  WHERE ${entityTable.agentId} = ${agentId}
22591
- AND (${sql18.join(nameConditions, sql18` OR `)})
22708
+ AND (${sql19.join(nameConditions, sql19` OR `)})
22592
22709
  `;
22593
22710
  const result = await this.db.execute(query);
22594
22711
  return result.rows.map((row) => ({
@@ -22611,7 +22728,7 @@ class EntityStore {
22611
22728
  metadata: row.metadata || {}
22612
22729
  }));
22613
22730
  }
22614
- const searchQuery = sql18`
22731
+ const searchQuery = sql19`
22615
22732
  SELECT * FROM ${entityTable}
22616
22733
  WHERE ${entityTable.agentId} = ${agentId}
22617
22734
  AND EXISTS (
@@ -22646,7 +22763,9 @@ class EntityStore {
22646
22763
  }
22647
22764
 
22648
22765
  // src/stores/component.store.ts
22766
+ init_schema();
22649
22767
  import { and as and5, eq as eq6 } from "drizzle-orm";
22768
+
22650
22769
  class ComponentStore {
22651
22770
  ctx;
22652
22771
  constructor(ctx) {
@@ -22736,7 +22855,9 @@ class ComponentStore {
22736
22855
 
22737
22856
  // src/stores/relationship.store.ts
22738
22857
  import { logger as logger5 } from "@elizaos/core";
22739
- import { and as and6, eq as eq7, sql as sql19 } from "drizzle-orm";
22858
+ import { and as and6, eq as eq7, sql as sql20 } from "drizzle-orm";
22859
+ init_schema();
22860
+
22740
22861
  class RelationshipStore {
22741
22862
  ctx;
22742
22863
  constructor(ctx) {
@@ -22812,13 +22933,13 @@ class RelationshipStore {
22812
22933
  const { entityId, tags } = params;
22813
22934
  let query;
22814
22935
  if (tags && tags.length > 0) {
22815
- query = sql19`
22936
+ query = sql20`
22816
22937
  SELECT * FROM ${relationshipTable}
22817
22938
  WHERE (${relationshipTable.sourceEntityId} = ${entityId} OR ${relationshipTable.targetEntityId} = ${entityId})
22818
- AND ${relationshipTable.tags} && CAST(ARRAY[${sql19.join(tags, sql19`, `)}] AS text[])
22939
+ AND ${relationshipTable.tags} && CAST(ARRAY[${sql20.join(tags, sql20`, `)}] AS text[])
22819
22940
  `;
22820
22941
  } else {
22821
- query = sql19`
22942
+ query = sql20`
22822
22943
  SELECT * FROM ${relationshipTable}
22823
22944
  WHERE ${relationshipTable.sourceEntityId} = ${entityId} OR ${relationshipTable.targetEntityId} = ${entityId}
22824
22945
  `;
@@ -22839,8 +22960,10 @@ class RelationshipStore {
22839
22960
  }
22840
22961
 
22841
22962
  // src/stores/cache.store.ts
22963
+ init_schema();
22842
22964
  import { logger as logger6 } from "@elizaos/core";
22843
22965
  import { and as and7, eq as eq8 } from "drizzle-orm";
22966
+
22844
22967
  class CacheStore {
22845
22968
  ctx;
22846
22969
  constructor(ctx) {
@@ -22913,6 +23036,8 @@ class CacheStore {
22913
23036
 
22914
23037
  // src/stores/world.store.ts
22915
23038
  import { eq as eq9 } from "drizzle-orm";
23039
+ init_schema();
23040
+
22916
23041
  class WorldStore {
22917
23042
  ctx;
22918
23043
  constructor(ctx) {
@@ -22957,7 +23082,9 @@ class WorldStore {
22957
23082
  }
22958
23083
 
22959
23084
  // src/stores/task.store.ts
22960
- import { and as and8, eq as eq10, sql as sql20 } from "drizzle-orm";
23085
+ init_schema();
23086
+ import { and as and8, eq as eq10, sql as sql21 } from "drizzle-orm";
23087
+
22961
23088
  class TaskStore {
22962
23089
  ctx;
22963
23090
  constructor(ctx) {
@@ -22991,7 +23118,7 @@ class TaskStore {
22991
23118
  async getAll(params) {
22992
23119
  return this.ctx.withRetry(async () => {
22993
23120
  const result = await this.db.select().from(taskTable).where(and8(eq10(taskTable.agentId, this.ctx.agentId), ...params.roomId ? [eq10(taskTable.roomId, params.roomId)] : [], ...params.tags && params.tags.length > 0 ? [
22994
- sql20`${taskTable.tags} @> ARRAY[${sql20.join(params.tags.map((t) => sql20`${t}`), sql20`, `)}]::text[]`
23121
+ sql21`${taskTable.tags} @> ARRAY[${sql21.join(params.tags.map((t) => sql21`${t}`), sql21`, `)}]::text[]`
22995
23122
  ] : []));
22996
23123
  return result.map((row) => ({
22997
23124
  id: row.id,
@@ -23066,7 +23193,8 @@ class TaskStore {
23066
23193
  }
23067
23194
 
23068
23195
  // src/stores/log.store.ts
23069
- import { and as and9, desc as desc2, eq as eq11, gte as gte2, lte as lte2, sql as sql21 } from "drizzle-orm";
23196
+ init_schema();
23197
+ import { and as and9, desc as desc2, eq as eq11, gte as gte2, lte as lte2, sql as sql22 } from "drizzle-orm";
23070
23198
  import { logger as logger7 } from "@elizaos/core";
23071
23199
  class LogStore {
23072
23200
  ctx;
@@ -23079,7 +23207,7 @@ class LogStore {
23079
23207
  const jsonString = JSON.stringify(sanitizedBody);
23080
23208
  await this.ctx.withIsolationContext(params.entityId, async (tx) => {
23081
23209
  await tx.insert(logTable).values({
23082
- body: sql21`${jsonString}::jsonb`,
23210
+ body: sql22`${jsonString}::jsonb`,
23083
23211
  entityId: params.entityId,
23084
23212
  roomId: params.roomId,
23085
23213
  type: params.type
@@ -23119,7 +23247,7 @@ class LogStore {
23119
23247
  const runMap = new Map;
23120
23248
  const conditions = [
23121
23249
  eq11(logTable.type, "run_event"),
23122
- sql21`${logTable.body} ? 'runId'`,
23250
+ sql22`${logTable.body} ? 'runId'`,
23123
23251
  eq11(roomTable.agentId, agentId)
23124
23252
  ];
23125
23253
  if (params.roomId) {
@@ -23134,9 +23262,9 @@ class LogStore {
23134
23262
  const whereClause = and9(...conditions);
23135
23263
  const eventLimit = Math.max(limit * 20, 200);
23136
23264
  const runEventRows = await tx.select({
23137
- runId: sql21`(${logTable.body} ->> 'runId')`,
23138
- status: sql21`(${logTable.body} ->> 'status')`,
23139
- messageId: sql21`(${logTable.body} ->> 'messageId')`,
23265
+ runId: sql22`(${logTable.body} ->> 'runId')`,
23266
+ status: sql22`(${logTable.body} ->> 'status')`,
23267
+ messageId: sql22`(${logTable.body} ->> 'messageId')`,
23140
23268
  rawBody: logTable.body,
23141
23269
  createdAt: logTable.createdAt,
23142
23270
  roomId: logTable.roomId,
@@ -23183,15 +23311,15 @@ class LogStore {
23183
23311
  }
23184
23312
  }
23185
23313
  const createdAt = row.createdAt instanceof Date ? row.createdAt : new Date(row.createdAt);
23186
- const timestamp17 = createdAt.getTime();
23314
+ const timestamp18 = createdAt.getTime();
23187
23315
  const eventStatus = row.status ?? body?.status;
23188
23316
  if (eventStatus === "started") {
23189
- summary.startedAt = summary.startedAt === null ? timestamp17 : Math.min(summary.startedAt, timestamp17);
23317
+ summary.startedAt = summary.startedAt === null ? timestamp18 : Math.min(summary.startedAt, timestamp18);
23190
23318
  } else if (eventStatus === "completed" || eventStatus === "timeout" || eventStatus === "error") {
23191
23319
  summary.status = eventStatus;
23192
- summary.endedAt = timestamp17;
23320
+ summary.endedAt = timestamp18;
23193
23321
  if (summary.startedAt !== null) {
23194
- summary.durationMs = Math.max(timestamp17 - summary.startedAt, 0);
23322
+ summary.durationMs = Math.max(timestamp18 - summary.startedAt, 0);
23195
23323
  }
23196
23324
  }
23197
23325
  runMap.set(runId, summary);
@@ -23211,8 +23339,8 @@ class LogStore {
23211
23339
  const runIds = limitedRuns.map((run) => run.runId).filter(Boolean);
23212
23340
  if (runIds.length > 0) {
23213
23341
  const db = this.ctx.getDb();
23214
- const runIdArray = sql21`array[${sql21.join(runIds.map((id) => sql21`${id}`), sql21`, `)}]::text[]`;
23215
- const actionSummary = await db.execute(sql21`
23342
+ const runIdArray = sql22`array[${sql22.join(runIds.map((id) => sql22`${id}`), sql22`, `)}]::text[]`;
23343
+ const actionSummary = await db.execute(sql22`
23216
23344
  SELECT
23217
23345
  body->>'runId' as "runId",
23218
23346
  COUNT(*)::int as "actions",
@@ -23232,7 +23360,7 @@ class LogStore {
23232
23360
  counts.errors += Number(row.errors ?? 0);
23233
23361
  counts.modelCalls += Number(row.modelCalls ?? 0);
23234
23362
  }
23235
- const evaluatorSummary = await db.execute(sql21`
23363
+ const evaluatorSummary = await db.execute(sql22`
23236
23364
  SELECT
23237
23365
  body->>'runId' as "runId",
23238
23366
  COUNT(*)::int as "evaluators"
@@ -23248,7 +23376,7 @@ class LogStore {
23248
23376
  continue;
23249
23377
  counts.evaluators += Number(row.evaluators ?? 0);
23250
23378
  }
23251
- const genericSummary = await db.execute(sql21`
23379
+ const genericSummary = await db.execute(sql22`
23252
23380
  SELECT
23253
23381
  body->>'runId' as "runId",
23254
23382
  COUNT(*) FILTER (WHERE type LIKE 'useModel:%')::int as "modelLogs",
@@ -23291,7 +23419,9 @@ class LogStore {
23291
23419
 
23292
23420
  // src/stores/messaging.store.ts
23293
23421
  import { ChannelType } from "@elizaos/core";
23294
- import { and as and10, desc as desc3, eq as eq12, lt, sql as sql22 } from "drizzle-orm";
23422
+ import { and as and10, desc as desc3, eq as eq12, lt, sql as sql23 } from "drizzle-orm";
23423
+ init_schema();
23424
+
23295
23425
  class MessagingStore {
23296
23426
  ctx;
23297
23427
  constructor(ctx) {
@@ -23362,7 +23492,7 @@ class MessagingStore {
23362
23492
  }
23363
23493
  async getMessageServerByRlsServerId(rlsServerId) {
23364
23494
  return this.ctx.withRetry(async () => {
23365
- const results = await this.db.execute(sql22`
23495
+ const results = await this.db.execute(sql23`
23366
23496
  SELECT id, name, source_type, source_id, metadata, created_at, updated_at
23367
23497
  FROM message_servers
23368
23498
  WHERE server_id = ${rlsServerId}
@@ -23827,7 +23957,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
23827
23957
  async getCachedEmbeddings(opts) {
23828
23958
  return this.withDatabase(async () => {
23829
23959
  try {
23830
- const results = await this.db.execute(sql31`
23960
+ const results = await this.db.execute(sql32`
23831
23961
  WITH content_text AS (
23832
23962
  SELECT
23833
23963
  m.id,
@@ -23887,7 +24017,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
23887
24017
  const jsonString = JSON.stringify(sanitizedBody);
23888
24018
  await this.withIsolationContext(params.entityId, async (tx) => {
23889
24019
  await tx.insert(logTable).values({
23890
- body: sql31`${jsonString}::jsonb`,
24020
+ body: sql32`${jsonString}::jsonb`,
23891
24021
  entityId: params.entityId,
23892
24022
  roomId: params.roomId,
23893
24023
  type: params.type
@@ -24159,9 +24289,45 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
24159
24289
  async deleteMessage(messageId) {
24160
24290
  return this.messagingStore.deleteMessage(messageId);
24161
24291
  }
24292
+ async getUserByEmail(email) {
24293
+ return this.withDatabase(async () => {
24294
+ const { userTable: userTable2 } = await Promise.resolve().then(() => (init_schema(), exports_schema));
24295
+ const rows = await this.db.select().from(userTable2).where(eq14(userTable2.email, email.toLowerCase())).limit(1);
24296
+ return rows.length > 0 ? rows[0] : null;
24297
+ });
24298
+ }
24299
+ async getUserByUsername(username) {
24300
+ return this.withDatabase(async () => {
24301
+ const { userTable: userTable2 } = await Promise.resolve().then(() => (init_schema(), exports_schema));
24302
+ const rows = await this.db.select().from(userTable2).where(eq14(userTable2.username, username)).limit(1);
24303
+ return rows.length > 0 ? rows[0] : null;
24304
+ });
24305
+ }
24306
+ async getUserById(id) {
24307
+ return this.withDatabase(async () => {
24308
+ const { userTable: userTable2 } = await Promise.resolve().then(() => (init_schema(), exports_schema));
24309
+ const rows = await this.db.select().from(userTable2).where(eq14(userTable2.id, id)).limit(1);
24310
+ return rows.length > 0 ? rows[0] : null;
24311
+ });
24312
+ }
24313
+ async createUser(user) {
24314
+ return this.withDatabase(async () => {
24315
+ const { userTable: userTable2 } = await Promise.resolve().then(() => (init_schema(), exports_schema));
24316
+ await this.db.insert(userTable2).values(user);
24317
+ return user;
24318
+ });
24319
+ }
24320
+ async updateUserLastLogin(userId) {
24321
+ return this.withDatabase(async () => {
24322
+ const { userTable: userTable2 } = await Promise.resolve().then(() => (init_schema(), exports_schema));
24323
+ await this.db.update(userTable2).set({ lastLoginAt: new Date }).where(eq14(userTable2.id, userId));
24324
+ });
24325
+ }
24162
24326
  }
24163
24327
 
24164
24328
  // src/pglite/adapter.ts
24329
+ init_embedding();
24330
+
24165
24331
  class PgliteDatabaseAdapter extends BaseDrizzleAdapter {
24166
24332
  manager;
24167
24333
  embeddingDimension = DIMENSION_MAP[384];
@@ -24260,6 +24426,7 @@ class PGliteClientManager {
24260
24426
  }
24261
24427
 
24262
24428
  // src/index.browser.ts
24429
+ init_schema();
24263
24430
  init_migration_service();
24264
24431
  var GLOBAL_SINGLETONS = Symbol.for("@elizaos/plugin-sql/global-singletons");
24265
24432
  var globalSymbols = globalThis;
@@ -24300,5 +24467,5 @@ export {
24300
24467
  DatabaseMigrationService
24301
24468
  };
24302
24469
 
24303
- //# debugId=0A9AA0ECC3C837CD64756E2164756E21
24470
+ //# debugId=D001744F84EC701864756E2164756E21
24304
24471
  //# sourceMappingURL=index.browser.js.map