@elizaos/plugin-sql 1.7.3-alpha.4 → 2.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,246 +61,6 @@ 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
-
304
64
  // src/schema/server.ts
305
65
  import { sql as sql10 } from "drizzle-orm";
306
66
  import { pgTable as pgTable10, timestamp as timestamp10, uuid as uuid10 } from "drizzle-orm/pg-core";
@@ -313,260 +73,16 @@ var init_server = __esm(() => {
313
73
  });
314
74
  });
315
75
 
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
-
560
76
  // src/types.ts
561
77
  function getDb(adapter) {
562
78
  return adapter.db;
563
79
  }
564
- function getRow(result, index6 = 0) {
565
- return result.rows[index6];
80
+ function getRow(result, index5 = 0) {
81
+ return result.rows[index5];
566
82
  }
567
83
 
568
84
  // src/runtime-migrator/storage/migration-tracker.ts
569
- import { sql as sql24 } from "drizzle-orm";
85
+ import { sql as sql23 } from "drizzle-orm";
570
86
 
571
87
  class MigrationTracker {
572
88
  db;
@@ -574,11 +90,11 @@ class MigrationTracker {
574
90
  this.db = db;
575
91
  }
576
92
  async ensureSchema() {
577
- await this.db.execute(sql24`CREATE SCHEMA IF NOT EXISTS migrations`);
93
+ await this.db.execute(sql23`CREATE SCHEMA IF NOT EXISTS migrations`);
578
94
  }
579
95
  async ensureTables() {
580
96
  await this.ensureSchema();
581
- await this.db.execute(sql24`
97
+ await this.db.execute(sql23`
582
98
  CREATE TABLE IF NOT EXISTS migrations._migrations (
583
99
  id SERIAL PRIMARY KEY,
584
100
  plugin_name TEXT NOT NULL,
@@ -586,7 +102,7 @@ class MigrationTracker {
586
102
  created_at BIGINT NOT NULL
587
103
  )
588
104
  `);
589
- await this.db.execute(sql24`
105
+ await this.db.execute(sql23`
590
106
  CREATE TABLE IF NOT EXISTS migrations._journal (
591
107
  plugin_name TEXT PRIMARY KEY,
592
108
  version TEXT NOT NULL,
@@ -594,7 +110,7 @@ class MigrationTracker {
594
110
  entries JSONB NOT NULL DEFAULT '[]'
595
111
  )
596
112
  `);
597
- await this.db.execute(sql24`
113
+ await this.db.execute(sql23`
598
114
  CREATE TABLE IF NOT EXISTS migrations._snapshots (
599
115
  id SERIAL PRIMARY KEY,
600
116
  plugin_name TEXT NOT NULL,
@@ -606,7 +122,7 @@ class MigrationTracker {
606
122
  `);
607
123
  }
608
124
  async getLastMigration(pluginName) {
609
- const result = await this.db.execute(sql24`SELECT id, hash, created_at
125
+ const result = await this.db.execute(sql23`SELECT id, hash, created_at
610
126
  FROM migrations._migrations
611
127
  WHERE plugin_name = ${pluginName}
612
128
  ORDER BY created_at DESC
@@ -614,14 +130,14 @@ class MigrationTracker {
614
130
  return getRow(result) || null;
615
131
  }
616
132
  async recordMigration(pluginName, hash, createdAt) {
617
- await this.db.execute(sql24`INSERT INTO migrations._migrations (plugin_name, hash, created_at)
133
+ await this.db.execute(sql23`INSERT INTO migrations._migrations (plugin_name, hash, created_at)
618
134
  VALUES (${pluginName}, ${hash}, ${createdAt})`);
619
135
  }
620
136
  }
621
137
  var init_migration_tracker = () => {};
622
138
 
623
139
  // src/runtime-migrator/storage/journal-storage.ts
624
- import { sql as sql25 } from "drizzle-orm";
140
+ import { sql as sql24 } from "drizzle-orm";
625
141
 
626
142
  class JournalStorage {
627
143
  db;
@@ -629,7 +145,7 @@ class JournalStorage {
629
145
  this.db = db;
630
146
  }
631
147
  async loadJournal(pluginName) {
632
- const result = await this.db.execute(sql25`SELECT version, dialect, entries
148
+ const result = await this.db.execute(sql24`SELECT version, dialect, entries
633
149
  FROM migrations._journal
634
150
  WHERE plugin_name = ${pluginName}`);
635
151
  if (result.rows.length === 0) {
@@ -643,7 +159,7 @@ class JournalStorage {
643
159
  };
644
160
  }
645
161
  async saveJournal(pluginName, journal) {
646
- await this.db.execute(sql25`INSERT INTO migrations._journal (plugin_name, version, dialect, entries)
162
+ await this.db.execute(sql24`INSERT INTO migrations._journal (plugin_name, version, dialect, entries)
647
163
  VALUES (${pluginName}, ${journal.version}, ${journal.dialect}, ${JSON.stringify(journal.entries)}::jsonb)
648
164
  ON CONFLICT (plugin_name)
649
165
  DO UPDATE SET
@@ -685,7 +201,7 @@ class JournalStorage {
685
201
  var init_journal_storage = () => {};
686
202
 
687
203
  // src/runtime-migrator/storage/snapshot-storage.ts
688
- import { sql as sql26 } from "drizzle-orm";
204
+ import { sql as sql25 } from "drizzle-orm";
689
205
 
690
206
  class SnapshotStorage {
691
207
  db;
@@ -693,7 +209,7 @@ class SnapshotStorage {
693
209
  this.db = db;
694
210
  }
695
211
  async saveSnapshot(pluginName, idx, snapshot) {
696
- await this.db.execute(sql26`INSERT INTO migrations._snapshots (plugin_name, idx, snapshot)
212
+ await this.db.execute(sql25`INSERT INTO migrations._snapshots (plugin_name, idx, snapshot)
697
213
  VALUES (${pluginName}, ${idx}, ${JSON.stringify(snapshot)}::jsonb)
698
214
  ON CONFLICT (plugin_name, idx)
699
215
  DO UPDATE SET
@@ -701,7 +217,7 @@ class SnapshotStorage {
701
217
  created_at = NOW()`);
702
218
  }
703
219
  async loadSnapshot(pluginName, idx) {
704
- const result = await this.db.execute(sql26`SELECT snapshot
220
+ const result = await this.db.execute(sql25`SELECT snapshot
705
221
  FROM migrations._snapshots
706
222
  WHERE plugin_name = ${pluginName} AND idx = ${idx}`);
707
223
  if (result.rows.length === 0) {
@@ -710,7 +226,7 @@ class SnapshotStorage {
710
226
  return result.rows[0].snapshot;
711
227
  }
712
228
  async getLatestSnapshot(pluginName) {
713
- const result = await this.db.execute(sql26`SELECT snapshot
229
+ const result = await this.db.execute(sql25`SELECT snapshot
714
230
  FROM migrations._snapshots
715
231
  WHERE plugin_name = ${pluginName}
716
232
  ORDER BY idx DESC
@@ -721,7 +237,7 @@ class SnapshotStorage {
721
237
  return result.rows[0].snapshot;
722
238
  }
723
239
  async getAllSnapshots(pluginName) {
724
- const result = await this.db.execute(sql26`SELECT snapshot
240
+ const result = await this.db.execute(sql25`SELECT snapshot
725
241
  FROM migrations._snapshots
726
242
  WHERE plugin_name = ${pluginName}
727
243
  ORDER BY idx ASC`);
@@ -731,7 +247,7 @@ class SnapshotStorage {
731
247
  var init_snapshot_storage = () => {};
732
248
 
733
249
  // src/runtime-migrator/extension-manager.ts
734
- import { sql as sql27 } from "drizzle-orm";
250
+ import { sql as sql26 } from "drizzle-orm";
735
251
  import { logger as logger8 } from "@elizaos/core";
736
252
 
737
253
  class ExtensionManager {
@@ -746,7 +262,7 @@ class ExtensionManager {
746
262
  logger8.warn({ src: "plugin:sql", extension }, "Invalid extension name - contains invalid characters");
747
263
  continue;
748
264
  }
749
- await this.db.execute(sql27`CREATE EXTENSION IF NOT EXISTS ${sql27.identifier(extension)}`);
265
+ await this.db.execute(sql26`CREATE EXTENSION IF NOT EXISTS ${sql26.identifier(extension)}`);
750
266
  logger8.debug({ src: "plugin:sql", extension }, "Extension installed");
751
267
  } catch (error) {
752
268
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -2388,12 +1904,12 @@ function objectToString(o) {
2388
1904
  function pad(n) {
2389
1905
  return n < 10 ? "0" + n.toString(10) : n.toString(10);
2390
1906
  }
2391
- function timestamp18() {
1907
+ function timestamp17() {
2392
1908
  var d = new Date, time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(":");
2393
1909
  return [d.getDate(), months[d.getMonth()], time].join(" ");
2394
1910
  }
2395
1911
  function log(...args) {
2396
- console.log("%s - %s", timestamp18(), format.apply(null, args));
1912
+ console.log("%s - %s", timestamp17(), format.apply(null, args));
2397
1913
  }
2398
1914
  function inherits(ctor, superCtor) {
2399
1915
  if (superCtor)
@@ -5159,10 +4675,10 @@ var require_stream = __commonJS((exports, module) => {
5159
4675
  dests[i2].emit("unpipe", this, { hasUnpiped: false });
5160
4676
  return this;
5161
4677
  }
5162
- let index6 = ArrayPrototypeIndexOf(state.pipes, dest);
5163
- if (index6 === -1)
4678
+ let index5 = ArrayPrototypeIndexOf(state.pipes, dest);
4679
+ if (index5 === -1)
5164
4680
  return this;
5165
- if (state.pipes.splice(index6, 1), state.pipes.length === 0)
4681
+ if (state.pipes.splice(index5, 1), state.pipes.length === 0)
5166
4682
  this.pause();
5167
4683
  return dest.emit("unpipe", this, unpipeInfo), this;
5168
4684
  };
@@ -6555,12 +6071,12 @@ var require_stream = __commonJS((exports, module) => {
6555
6071
  if ((options === null || options === undefined ? undefined : options.signal) != null)
6556
6072
  validateAbortSignal2(options.signal, "options.signal");
6557
6073
  return async function* () {
6558
- let index6 = 0;
6074
+ let index5 = 0;
6559
6075
  for await (let val of this) {
6560
6076
  var _options$signal;
6561
6077
  if (options !== null && options !== undefined && (_options$signal = options.signal) !== null && _options$signal !== undefined && _options$signal.aborted)
6562
6078
  throw new AbortError2({ cause: options.signal.reason });
6563
- yield [index6++, val];
6079
+ yield [index5++, val];
6564
6080
  }
6565
6081
  }.call(this);
6566
6082
  }
@@ -7206,7 +6722,7 @@ var init_crypto = __esm(() => {
7206
6722
  } catch (e) {
7207
6723
  errorProto = getProto(getProto(e)), INTRINSICS["%Error.prototype%"] = errorProto;
7208
6724
  }
7209
- var errorProto, doEval = function doEval(name) {
6725
+ var errorProto, doEval = function doEval2(name) {
7210
6726
  var value;
7211
6727
  if (name === "%AsyncFunction%")
7212
6728
  value = getEvalledConstructor("async function () {}");
@@ -7215,11 +6731,11 @@ var init_crypto = __esm(() => {
7215
6731
  else if (name === "%AsyncGeneratorFunction%")
7216
6732
  value = getEvalledConstructor("async function* () {}");
7217
6733
  else if (name === "%AsyncGenerator%") {
7218
- var fn = doEval("%AsyncGeneratorFunction%");
6734
+ var fn = doEval2("%AsyncGeneratorFunction%");
7219
6735
  if (fn)
7220
6736
  value = fn.prototype;
7221
6737
  } else if (name === "%AsyncIteratorPrototype%") {
7222
- var gen = doEval("%AsyncGenerator%");
6738
+ var gen = doEval2("%AsyncGenerator%");
7223
6739
  if (gen && getProto)
7224
6740
  value = getProto(gen.prototype);
7225
6741
  }
@@ -7865,8 +7381,8 @@ var init_crypto = __esm(() => {
7865
7381
  }
7866
7382
  return this.strip();
7867
7383
  };
7868
- function parseHex4Bits(string, index6) {
7869
- var c = string.charCodeAt(index6);
7384
+ function parseHex4Bits(string, index5) {
7385
+ var c = string.charCodeAt(index5);
7870
7386
  if (c >= 65 && c <= 70)
7871
7387
  return c - 55;
7872
7388
  else if (c >= 97 && c <= 102)
@@ -7874,10 +7390,10 @@ var init_crypto = __esm(() => {
7874
7390
  else
7875
7391
  return c - 48 & 15;
7876
7392
  }
7877
- function parseHexByte(string, lowerBound, index6) {
7878
- var r = parseHex4Bits(string, index6);
7879
- if (index6 - 1 >= lowerBound)
7880
- r |= parseHex4Bits(string, index6 - 1) << 4;
7393
+ function parseHexByte(string, lowerBound, index5) {
7394
+ var r = parseHex4Bits(string, index5);
7395
+ if (index5 - 1 >= lowerBound)
7396
+ r |= parseHex4Bits(string, index5 - 1) << 4;
7881
7397
  return r;
7882
7398
  }
7883
7399
  BN.prototype._parseHex = function(number, start, endian) {
@@ -9439,11 +8955,11 @@ var init_crypto = __esm(() => {
9439
8955
  comb[1] = points[a].toJ().mixedAdd(points[b]), comb[2] = points[a].add(points[b].neg());
9440
8956
  else
9441
8957
  comb[1] = points[a].toJ().mixedAdd(points[b]), comb[2] = points[a].toJ().mixedAdd(points[b].neg());
9442
- var index6 = [-3, -1, -5, -7, 0, 7, 5, 1, 3], jsf = getJSF(coeffs[a], coeffs[b]);
8958
+ var index5 = [-3, -1, -5, -7, 0, 7, 5, 1, 3], jsf = getJSF(coeffs[a], coeffs[b]);
9443
8959
  max = Math.max(jsf[0].length, max), naf[a] = Array(max), naf[b] = Array(max);
9444
8960
  for (j = 0;j < max; j++) {
9445
8961
  var ja = jsf[0][j] | 0, jb = jsf[1][j] | 0;
9446
- naf[a][j] = index6[(ja + 1) * 3 + (jb + 1)], naf[b][j] = 0, wnd[a] = comb;
8962
+ naf[a][j] = index5[(ja + 1) * 3 + (jb + 1)], naf[b][j] = 0, wnd[a] = comb;
9447
8963
  }
9448
8964
  }
9449
8965
  var acc = this.jpoint(null, null, null), tmp = this._wnafT4;
@@ -11540,8 +11056,8 @@ var init_crypto = __esm(() => {
11540
11056
  }
11541
11057
  return this.strip();
11542
11058
  };
11543
- function parseHex4Bits(string, index6) {
11544
- var c = string.charCodeAt(index6);
11059
+ function parseHex4Bits(string, index5) {
11060
+ var c = string.charCodeAt(index5);
11545
11061
  if (c >= 65 && c <= 70)
11546
11062
  return c - 55;
11547
11063
  else if (c >= 97 && c <= 102)
@@ -11549,10 +11065,10 @@ var init_crypto = __esm(() => {
11549
11065
  else
11550
11066
  return c - 48 & 15;
11551
11067
  }
11552
- function parseHexByte(string, lowerBound, index6) {
11553
- var r = parseHex4Bits(string, index6);
11554
- if (index6 - 1 >= lowerBound)
11555
- r |= parseHex4Bits(string, index6 - 1) << 4;
11068
+ function parseHexByte(string, lowerBound, index5) {
11069
+ var r = parseHex4Bits(string, index5);
11070
+ if (index5 - 1 >= lowerBound)
11071
+ r |= parseHex4Bits(string, index5 - 1) << 4;
11556
11072
  return r;
11557
11073
  }
11558
11074
  BN.prototype._parseHex = function(number, start, endian) {
@@ -13003,8 +12519,8 @@ var init_crypto = __esm(() => {
13003
12519
  }
13004
12520
  return this.strip();
13005
12521
  };
13006
- function parseHex4Bits(string, index6) {
13007
- var c = string.charCodeAt(index6);
12522
+ function parseHex4Bits(string, index5) {
12523
+ var c = string.charCodeAt(index5);
13008
12524
  if (c >= 65 && c <= 70)
13009
12525
  return c - 55;
13010
12526
  else if (c >= 97 && c <= 102)
@@ -13012,10 +12528,10 @@ var init_crypto = __esm(() => {
13012
12528
  else
13013
12529
  return c - 48 & 15;
13014
12530
  }
13015
- function parseHexByte(string, lowerBound, index6) {
13016
- var r = parseHex4Bits(string, index6);
13017
- if (index6 - 1 >= lowerBound)
13018
- r |= parseHex4Bits(string, index6 - 1) << 4;
12531
+ function parseHexByte(string, lowerBound, index5) {
12532
+ var r = parseHex4Bits(string, index5);
12533
+ if (index5 - 1 >= lowerBound)
12534
+ r |= parseHex4Bits(string, index5 - 1) << 4;
13019
12535
  return r;
13020
12536
  }
13021
12537
  BN.prototype._parseHex = function(number, start, endian) {
@@ -14369,13 +13885,13 @@ var init_crypto = __esm(() => {
14369
13885
  Reporter.prototype.enterKey = function(key) {
14370
13886
  return this._reporterState.path.push(key);
14371
13887
  };
14372
- Reporter.prototype.exitKey = function(index6) {
13888
+ Reporter.prototype.exitKey = function(index5) {
14373
13889
  var state = this._reporterState;
14374
- state.path = state.path.slice(0, index6 - 1);
13890
+ state.path = state.path.slice(0, index5 - 1);
14375
13891
  };
14376
- Reporter.prototype.leaveKey = function(index6, key, value) {
13892
+ Reporter.prototype.leaveKey = function(index5, key, value) {
14377
13893
  var state = this._reporterState;
14378
- if (this.exitKey(index6), state.obj !== null)
13894
+ if (this.exitKey(index5), state.obj !== null)
14379
13895
  state.obj[key] = value;
14380
13896
  };
14381
13897
  Reporter.prototype.path = function() {
@@ -15744,8 +15260,8 @@ var init_crypto = __esm(() => {
15744
15260
  }
15745
15261
  return this.strip();
15746
15262
  };
15747
- function parseHex4Bits(string, index6) {
15748
- var c = string.charCodeAt(index6);
15263
+ function parseHex4Bits(string, index5) {
15264
+ var c = string.charCodeAt(index5);
15749
15265
  if (c >= 65 && c <= 70)
15750
15266
  return c - 55;
15751
15267
  else if (c >= 97 && c <= 102)
@@ -15753,10 +15269,10 @@ var init_crypto = __esm(() => {
15753
15269
  else
15754
15270
  return c - 48 & 15;
15755
15271
  }
15756
- function parseHexByte(string, lowerBound, index6) {
15757
- var r = parseHex4Bits(string, index6);
15758
- if (index6 - 1 >= lowerBound)
15759
- r |= parseHex4Bits(string, index6 - 1) << 4;
15272
+ function parseHexByte(string, lowerBound, index5) {
15273
+ var r = parseHex4Bits(string, index5);
15274
+ if (index5 - 1 >= lowerBound)
15275
+ r |= parseHex4Bits(string, index5 - 1) << 4;
15760
15276
  return r;
15761
15277
  }
15762
15278
  BN.prototype._parseHex = function(number, start, endian) {
@@ -17148,8 +16664,8 @@ var init_crypto = __esm(() => {
17148
16664
  }
17149
16665
  return this._strip();
17150
16666
  };
17151
- function parseHex4Bits(string, index6) {
17152
- var c = string.charCodeAt(index6);
16667
+ function parseHex4Bits(string, index5) {
16668
+ var c = string.charCodeAt(index5);
17153
16669
  if (c >= 48 && c <= 57)
17154
16670
  return c - 48;
17155
16671
  else if (c >= 65 && c <= 70)
@@ -17159,10 +16675,10 @@ var init_crypto = __esm(() => {
17159
16675
  else
17160
16676
  assert(false, "Invalid character in " + string);
17161
16677
  }
17162
- function parseHexByte(string, lowerBound, index6) {
17163
- var r = parseHex4Bits(string, index6);
17164
- if (index6 - 1 >= lowerBound)
17165
- r |= parseHex4Bits(string, index6 - 1) << 4;
16678
+ function parseHexByte(string, lowerBound, index5) {
16679
+ var r = parseHex4Bits(string, index5);
16680
+ if (index5 - 1 >= lowerBound)
16681
+ r |= parseHex4Bits(string, index5 - 1) << 4;
17166
16682
  return r;
17167
16683
  }
17168
16684
  BN.prototype._parseHex = function(number, start, endian) {
@@ -19068,8 +18584,8 @@ function hasChanges(previousSnapshot, currentSnapshot) {
19068
18584
  const currHash = hashSnapshot(currentSnapshot);
19069
18585
  return prevHash !== currHash;
19070
18586
  }
19071
- var sqlToStr = (sql28, casing) => {
19072
- return sql28.toQuery({
18587
+ var sqlToStr = (sql27, casing) => {
18588
+ return sql27.toQuery({
19073
18589
  escapeName: () => {
19074
18590
  throw new Error("we don't support params for `sql` default values");
19075
18591
  },
@@ -19600,14 +19116,14 @@ async function generateMigrationSQL(previousSnapshot, currentSnapshot, diff) {
19600
19116
  const alterStatements = generateAlterColumnSQL(modified.table, modified.column, modified.changes);
19601
19117
  statements.push(...alterStatements);
19602
19118
  }
19603
- for (const index6 of diff.indexes.deleted) {
19604
- statements.push(generateDropIndexSQL(index6));
19119
+ for (const index5 of diff.indexes.deleted) {
19120
+ statements.push(generateDropIndexSQL(index5));
19605
19121
  }
19606
19122
  for (const alteredIndex of diff.indexes.altered) {
19607
19123
  statements.push(generateDropIndexSQL(alteredIndex.old));
19608
19124
  }
19609
- for (const index6 of diff.indexes.created) {
19610
- statements.push(generateCreateIndexSQL(index6));
19125
+ for (const index5 of diff.indexes.created) {
19126
+ statements.push(generateCreateIndexSQL(index5));
19611
19127
  }
19612
19128
  for (const alteredIndex of diff.indexes.altered) {
19613
19129
  statements.push(generateCreateIndexSQL(alteredIndex.new));
@@ -19704,18 +19220,18 @@ function generateCreateTableSQL(fullTableName, table) {
19704
19220
  return { tableSQL, fkSQLs };
19705
19221
  }
19706
19222
  function generateColumnDefinition(name, def) {
19707
- let sql28 = `"${name}" ${def.type}`;
19223
+ let sql27 = `"${name}" ${def.type}`;
19708
19224
  if (def.primaryKey && !def.type.includes("SERIAL")) {
19709
- sql28 += " PRIMARY KEY";
19225
+ sql27 += " PRIMARY KEY";
19710
19226
  }
19711
19227
  if (def.notNull) {
19712
- sql28 += " NOT NULL";
19228
+ sql27 += " NOT NULL";
19713
19229
  }
19714
19230
  if (def.default !== undefined) {
19715
19231
  const defaultValue = formatDefaultValue(def.default, def.type);
19716
- sql28 += ` DEFAULT ${defaultValue}`;
19232
+ sql27 += ` DEFAULT ${defaultValue}`;
19717
19233
  }
19718
- return sql28;
19234
+ return sql27;
19719
19235
  }
19720
19236
  function generateAddColumnSQL(table, column, definition) {
19721
19237
  const [schema, tableName] = table.includes(".") ? table.split(".") : ["public", table];
@@ -19842,27 +19358,27 @@ function formatDefaultValue(value, type) {
19842
19358
  }
19843
19359
  return String(value);
19844
19360
  }
19845
- function generateCreateIndexSQL(index6) {
19846
- const unique3 = index6.isUnique ? "UNIQUE " : "";
19847
- const method = index6.method || "btree";
19848
- const columns = index6.columns.map((c) => {
19361
+ function generateCreateIndexSQL(index5) {
19362
+ const unique3 = index5.isUnique ? "UNIQUE " : "";
19363
+ const method = index5.method || "btree";
19364
+ const columns = index5.columns.map((c) => {
19849
19365
  if (c.isExpression) {
19850
19366
  return c.expression;
19851
19367
  }
19852
19368
  return `"${c.expression}"${c.asc === false ? " DESC" : ""}`;
19853
19369
  }).join(", ");
19854
- const indexName = index6.name.includes(".") ? index6.name.split(".")[1] : index6.name;
19370
+ const indexName = index5.name.includes(".") ? index5.name.split(".")[1] : index5.name;
19855
19371
  let tableRef;
19856
- if (index6.table && index6.table.includes(".")) {
19857
- const [schema, table] = index6.table.split(".");
19372
+ if (index5.table && index5.table.includes(".")) {
19373
+ const [schema, table] = index5.table.split(".");
19858
19374
  tableRef = `"${schema}"."${table}"`;
19859
19375
  } else {
19860
- tableRef = `"${index6.table || ""}"`;
19376
+ tableRef = `"${index5.table || ""}"`;
19861
19377
  }
19862
19378
  return `CREATE ${unique3}INDEX "${indexName}" ON ${tableRef} USING ${method} (${columns});`;
19863
19379
  }
19864
- function generateDropIndexSQL(index6) {
19865
- const indexName = index6.name ? index6.name.includes(".") ? index6.name.split(".")[1] : index6.name : index6;
19380
+ function generateDropIndexSQL(index5) {
19381
+ const indexName = index5.name ? index5.name.includes(".") ? index5.name.split(".")[1] : index5.name : index5;
19866
19382
  return `DROP INDEX IF EXISTS "${indexName}";`;
19867
19383
  }
19868
19384
  function generateCreateForeignKeySQL(fk) {
@@ -19871,14 +19387,14 @@ function generateCreateForeignKeySQL(fk) {
19871
19387
  const tableFrom = fk.tableFrom;
19872
19388
  const columnsFrom = fk.columnsFrom.map((c) => `"${c}"`).join(", ");
19873
19389
  const columnsTo = fk.columnsTo.map((c) => `"${c}"`).join(", ");
19874
- let sql28 = `ALTER TABLE "${schemaFrom}"."${tableFrom}" ADD CONSTRAINT "${fk.name}" FOREIGN KEY (${columnsFrom}) REFERENCES "${schemaTo}"."${fk.tableTo}" (${columnsTo})`;
19390
+ let sql27 = `ALTER TABLE "${schemaFrom}"."${tableFrom}" ADD CONSTRAINT "${fk.name}" FOREIGN KEY (${columnsFrom}) REFERENCES "${schemaTo}"."${fk.tableTo}" (${columnsTo})`;
19875
19391
  if (fk.onDelete) {
19876
- sql28 += ` ON DELETE ${fk.onDelete}`;
19392
+ sql27 += ` ON DELETE ${fk.onDelete}`;
19877
19393
  }
19878
19394
  if (fk.onUpdate) {
19879
- sql28 += ` ON UPDATE ${fk.onUpdate}`;
19395
+ sql27 += ` ON UPDATE ${fk.onUpdate}`;
19880
19396
  }
19881
- return sql28 + ";";
19397
+ return sql27 + ";";
19882
19398
  }
19883
19399
  function generateDropForeignKeySQL(fk) {
19884
19400
  const [schema, tableName] = fk.tableFrom ? fk.tableFrom.includes(".") ? fk.tableFrom.split(".") : ["public", fk.tableFrom] : ["public", ""];
@@ -19889,12 +19405,12 @@ function generateCreateUniqueConstraintSQL(constraint) {
19889
19405
  const [schema, tableName] = table.includes(".") ? table.split(".") : ["public", table];
19890
19406
  const name = constraint.name;
19891
19407
  const columns = constraint.columns.map((c) => `"${c}"`).join(", ");
19892
- let sql28 = `ALTER TABLE "${schema}"."${tableName}" ADD CONSTRAINT "${name}" UNIQUE`;
19408
+ let sql27 = `ALTER TABLE "${schema}"."${tableName}" ADD CONSTRAINT "${name}" UNIQUE`;
19893
19409
  if (constraint.nullsNotDistinct) {
19894
- sql28 += ` NULLS NOT DISTINCT`;
19410
+ sql27 += ` NULLS NOT DISTINCT`;
19895
19411
  }
19896
- sql28 += ` (${columns});`;
19897
- return sql28;
19412
+ sql27 += ` (${columns});`;
19413
+ return sql27;
19898
19414
  }
19899
19415
  function generateDropUniqueConstraintSQL(constraint) {
19900
19416
  const table = constraint.table || "";
@@ -19961,7 +19477,7 @@ function normalizeSchemaName(input) {
19961
19477
  var init_schema_transformer = () => {};
19962
19478
 
19963
19479
  // src/runtime-migrator/drizzle-adapters/database-introspector.ts
19964
- import { sql as sql28 } from "drizzle-orm";
19480
+ import { sql as sql27 } from "drizzle-orm";
19965
19481
  import { logger as logger11 } from "@elizaos/core";
19966
19482
 
19967
19483
  class DatabaseIntrospector {
@@ -20088,7 +19604,7 @@ class DatabaseIntrospector {
20088
19604
  };
20089
19605
  }
20090
19606
  async getTables(schemaName) {
20091
- const result = await this.db.execute(sql28`SELECT
19607
+ const result = await this.db.execute(sql27`SELECT
20092
19608
  table_schema,
20093
19609
  table_name
20094
19610
  FROM information_schema.tables
@@ -20098,7 +19614,7 @@ class DatabaseIntrospector {
20098
19614
  return result.rows;
20099
19615
  }
20100
19616
  async getColumns(schemaName, tableName) {
20101
- const result = await this.db.execute(sql28`SELECT
19617
+ const result = await this.db.execute(sql27`SELECT
20102
19618
  a.attname AS column_name,
20103
19619
  CASE
20104
19620
  WHEN a.attnotnull THEN 'NO'
@@ -20141,7 +19657,7 @@ class DatabaseIntrospector {
20141
19657
  return result.rows;
20142
19658
  }
20143
19659
  async getIndexes(schemaName, tableName) {
20144
- const result = await this.db.execute(sql28`SELECT
19660
+ const result = await this.db.execute(sql27`SELECT
20145
19661
  i.relname AS name,
20146
19662
  idx.indisunique AS is_unique,
20147
19663
  idx.indisprimary AS is_primary,
@@ -20165,7 +19681,7 @@ class DatabaseIntrospector {
20165
19681
  return result.rows;
20166
19682
  }
20167
19683
  async getForeignKeys(schemaName, tableName) {
20168
- const result = await this.db.execute(sql28`SELECT
19684
+ const result = await this.db.execute(sql27`SELECT
20169
19685
  con.conname AS name,
20170
19686
  att.attname AS column_name,
20171
19687
  fnsp.nspname AS foreign_table_schema,
@@ -20200,7 +19716,7 @@ class DatabaseIntrospector {
20200
19716
  return result.rows;
20201
19717
  }
20202
19718
  async getPrimaryKeys(schemaName, tableName) {
20203
- const result = await this.db.execute(sql28`SELECT
19719
+ const result = await this.db.execute(sql27`SELECT
20204
19720
  con.conname AS name,
20205
19721
  ARRAY(
20206
19722
  SELECT a.attname
@@ -20218,7 +19734,7 @@ class DatabaseIntrospector {
20218
19734
  return result.rows;
20219
19735
  }
20220
19736
  async getUniqueConstraints(schemaName, tableName) {
20221
- const result = await this.db.execute(sql28`SELECT
19737
+ const result = await this.db.execute(sql27`SELECT
20222
19738
  con.conname AS name,
20223
19739
  ARRAY(
20224
19740
  SELECT a.attname
@@ -20236,7 +19752,7 @@ class DatabaseIntrospector {
20236
19752
  return result.rows;
20237
19753
  }
20238
19754
  async getCheckConstraints(schemaName, tableName) {
20239
- const result = await this.db.execute(sql28`SELECT
19755
+ const result = await this.db.execute(sql27`SELECT
20240
19756
  con.conname AS name,
20241
19757
  pg_get_constraintdef(con.oid) AS definition
20242
19758
  FROM pg_constraint con
@@ -20248,7 +19764,7 @@ class DatabaseIntrospector {
20248
19764
  return result.rows;
20249
19765
  }
20250
19766
  async getEnums(schemaName) {
20251
- const result = await this.db.execute(sql28`SELECT
19767
+ const result = await this.db.execute(sql27`SELECT
20252
19768
  n.nspname AS schema,
20253
19769
  t.typname AS name,
20254
19770
  e.enumlabel AS value,
@@ -20280,7 +19796,7 @@ class DatabaseIntrospector {
20280
19796
  }
20281
19797
  async hasExistingTables(pluginName) {
20282
19798
  const schemaName = pluginName === "@elizaos/plugin-sql" ? "public" : this.deriveSchemaName(pluginName);
20283
- const result = await this.db.execute(sql28`SELECT COUNT(*) AS count
19799
+ const result = await this.db.execute(sql27`SELECT COUNT(*) AS count
20284
19800
  FROM information_schema.tables
20285
19801
  WHERE table_schema = ${schemaName}
20286
19802
  AND table_type = 'BASE TABLE'`);
@@ -20294,7 +19810,7 @@ class DatabaseIntrospector {
20294
19810
  var init_database_introspector = () => {};
20295
19811
 
20296
19812
  // src/runtime-migrator/runtime-migrator.ts
20297
- import { sql as sql29 } from "drizzle-orm";
19813
+ import { sql as sql28 } from "drizzle-orm";
20298
19814
  import { logger as logger12 } from "@elizaos/core";
20299
19815
 
20300
19816
  class RuntimeMigrator {
@@ -20334,7 +19850,7 @@ class RuntimeMigrator {
20334
19850
  }
20335
19851
  for (const schemaName of schemasToCreate) {
20336
19852
  logger12.debug({ src: "plugin:sql", schemaName }, "Ensuring schema exists");
20337
- await this.db.execute(sql29.raw(`CREATE SCHEMA IF NOT EXISTS "${schemaName}"`));
19853
+ await this.db.execute(sql28.raw(`CREATE SCHEMA IF NOT EXISTS "${schemaName}"`));
20338
19854
  }
20339
19855
  }
20340
19856
  validateSchemaUsage(pluginName, snapshot) {
@@ -20492,11 +20008,11 @@ class RuntimeMigrator {
20492
20008
  try {
20493
20009
  logger12.debug({ src: "plugin:sql", pluginName }, "Using PostgreSQL advisory locks");
20494
20010
  const lockIdStr = lockId.toString();
20495
- const lockResult = await this.db.execute(sql29`SELECT pg_try_advisory_lock(CAST(${lockIdStr} AS bigint)) as acquired`);
20011
+ const lockResult = await this.db.execute(sql28`SELECT pg_try_advisory_lock(CAST(${lockIdStr} AS bigint)) as acquired`);
20496
20012
  lockAcquired = getRow(lockResult)?.acquired === true;
20497
20013
  if (!lockAcquired) {
20498
20014
  logger12.info({ src: "plugin:sql", pluginName }, "Migration already in progress, waiting for lock");
20499
- await this.db.execute(sql29`SELECT pg_advisory_lock(CAST(${lockIdStr} AS bigint))`);
20015
+ await this.db.execute(sql28`SELECT pg_advisory_lock(CAST(${lockIdStr} AS bigint))`);
20500
20016
  lockAcquired = true;
20501
20017
  logger12.info({ src: "plugin:sql", pluginName }, "Lock acquired");
20502
20018
  } else {
@@ -20627,7 +20143,7 @@ class RuntimeMigrator {
20627
20143
  if (lockAcquired && isRealPostgres) {
20628
20144
  try {
20629
20145
  const lockIdStr = lockId.toString();
20630
- await this.db.execute(sql29`SELECT pg_advisory_unlock(CAST(${lockIdStr} AS bigint))`);
20146
+ await this.db.execute(sql28`SELECT pg_advisory_unlock(CAST(${lockIdStr} AS bigint))`);
20631
20147
  logger12.debug({ src: "plugin:sql", pluginName }, "Advisory lock released");
20632
20148
  } catch (unlockError) {
20633
20149
  logger12.warn({
@@ -20642,23 +20158,23 @@ class RuntimeMigrator {
20642
20158
  async executeMigration(pluginName, snapshot, hash, sqlStatements) {
20643
20159
  let transactionStarted = false;
20644
20160
  try {
20645
- await this.db.execute(sql29`BEGIN`);
20161
+ await this.db.execute(sql28`BEGIN`);
20646
20162
  transactionStarted = true;
20647
20163
  for (const stmt of sqlStatements) {
20648
20164
  logger12.debug({ src: "plugin:sql", statement: stmt }, "Executing SQL statement");
20649
- await this.db.execute(sql29.raw(stmt));
20165
+ await this.db.execute(sql28.raw(stmt));
20650
20166
  }
20651
20167
  const idx = await this.journalStorage.getNextIdx(pluginName);
20652
20168
  await this.migrationTracker.recordMigration(pluginName, hash, Date.now());
20653
20169
  const tag = this.generateMigrationTag(idx, pluginName);
20654
20170
  await this.journalStorage.updateJournal(pluginName, idx, tag, true);
20655
20171
  await this.snapshotStorage.saveSnapshot(pluginName, idx, snapshot);
20656
- await this.db.execute(sql29`COMMIT`);
20172
+ await this.db.execute(sql28`COMMIT`);
20657
20173
  logger12.info({ src: "plugin:sql", pluginName, tag }, "Recorded migration");
20658
20174
  } catch (error) {
20659
20175
  if (transactionStarted) {
20660
20176
  try {
20661
- await this.db.execute(sql29`ROLLBACK`);
20177
+ await this.db.execute(sql28`ROLLBACK`);
20662
20178
  logger12.error({ src: "plugin:sql", error: error instanceof Error ? error.message : String(error) }, "Migration failed, rolled back");
20663
20179
  } catch (rollbackError) {
20664
20180
  logger12.error({
@@ -20672,8 +20188,8 @@ class RuntimeMigrator {
20672
20188
  }
20673
20189
  generateMigrationTag(idx, pluginName) {
20674
20190
  const prefix = idx.toString().padStart(4, "0");
20675
- const timestamp19 = Date.now().toString(36);
20676
- return `${prefix}_${pluginName}_${timestamp19}`;
20191
+ const timestamp18 = Date.now().toString(36);
20192
+ return `${prefix}_${pluginName}_${timestamp18}`;
20677
20193
  }
20678
20194
  async getStatus(pluginName) {
20679
20195
  const lastMigration = await this.migrationTracker.getLastMigration(pluginName);
@@ -20688,9 +20204,9 @@ class RuntimeMigrator {
20688
20204
  }
20689
20205
  async reset(pluginName) {
20690
20206
  logger12.warn({ src: "plugin:sql", pluginName }, "Resetting migrations");
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}`);
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}`);
20694
20210
  logger12.warn({ src: "plugin:sql", pluginName }, "Reset complete");
20695
20211
  }
20696
20212
  async checkMigration(pluginName, schema) {
@@ -20739,18 +20255,18 @@ var init_runtime_migrator2 = __esm(() => {
20739
20255
 
20740
20256
  // src/migrations.ts
20741
20257
  import { logger as logger13 } from "@elizaos/core";
20742
- import { sql as sql30 } from "drizzle-orm";
20258
+ import { sql as sql29 } from "drizzle-orm";
20743
20259
  async function migrateToEntityRLS(adapter) {
20744
20260
  const db = getDb(adapter);
20745
20261
  try {
20746
- await db.execute(sql30`SELECT 1 FROM pg_tables LIMIT 1`);
20262
+ await db.execute(sql29`SELECT 1 FROM pg_tables LIMIT 1`);
20747
20263
  } catch {
20748
20264
  logger13.debug("[Migration] ⊘ Not PostgreSQL, skipping PostgreSQL-specific migrations");
20749
20265
  return;
20750
20266
  }
20751
20267
  let schemaAlreadyMigrated = false;
20752
20268
  try {
20753
- const migrationCheck = await db.execute(sql30`
20269
+ const migrationCheck = await db.execute(sql29`
20754
20270
  SELECT column_name FROM information_schema.columns
20755
20271
  WHERE table_schema = 'public'
20756
20272
  AND table_name = 'rooms'
@@ -20772,7 +20288,7 @@ async function migrateToEntityRLS(adapter) {
20772
20288
  }
20773
20289
  logger13.debug("[Migration] → Schema migrated but RLS disabled, cleaning up...");
20774
20290
  try {
20775
- const tablesWithRls = await db.execute(sql30`
20291
+ const tablesWithRls = await db.execute(sql29`
20776
20292
  SELECT c.relname as tablename
20777
20293
  FROM pg_class c
20778
20294
  JOIN pg_namespace n ON n.oid = c.relnamespace
@@ -20785,7 +20301,7 @@ async function migrateToEntityRLS(adapter) {
20785
20301
  for (const row of tablesWithRls.rows) {
20786
20302
  const tableName = row.tablename;
20787
20303
  try {
20788
- await db.execute(sql30.raw(`ALTER TABLE "${tableName}" DISABLE ROW LEVEL SECURITY`));
20304
+ await db.execute(sql29.raw(`ALTER TABLE "${tableName}" DISABLE ROW LEVEL SECURITY`));
20789
20305
  } catch {}
20790
20306
  }
20791
20307
  logger13.debug(`[Migration] ✓ RLS cleanup completed (${tablesWithRls.rows.length} tables)`);
@@ -20801,14 +20317,14 @@ async function migrateToEntityRLS(adapter) {
20801
20317
  try {
20802
20318
  logger13.debug("[Migration] → Clearing RuntimeMigrator snapshot cache...");
20803
20319
  try {
20804
- await db.execute(sql30`DELETE FROM migrations._snapshots WHERE plugin_name = '@elizaos/plugin-sql'`);
20320
+ await db.execute(sql29`DELETE FROM migrations._snapshots WHERE plugin_name = '@elizaos/plugin-sql'`);
20805
20321
  logger13.debug("[Migration] ✓ Snapshot cache cleared");
20806
20322
  } catch (error) {
20807
20323
  logger13.debug("[Migration] ⊘ No snapshot cache to clear (migrations schema not yet created)");
20808
20324
  }
20809
20325
  logger13.debug("[Migration] → Checking for Row Level Security to disable...");
20810
20326
  try {
20811
- const tablesWithRls = await db.execute(sql30`
20327
+ const tablesWithRls = await db.execute(sql29`
20812
20328
  SELECT c.relname as tablename
20813
20329
  FROM pg_class c
20814
20330
  JOIN pg_namespace n ON n.oid = c.relnamespace
@@ -20821,7 +20337,7 @@ async function migrateToEntityRLS(adapter) {
20821
20337
  for (const row of tablesWithRls.rows) {
20822
20338
  const tableName = row.tablename;
20823
20339
  try {
20824
- await db.execute(sql30.raw(`ALTER TABLE "${tableName}" DISABLE ROW LEVEL SECURITY`));
20340
+ await db.execute(sql29.raw(`ALTER TABLE "${tableName}" DISABLE ROW LEVEL SECURITY`));
20825
20341
  logger13.debug(`[Migration] ✓ Disabled RLS on ${tableName}`);
20826
20342
  } catch (error) {
20827
20343
  logger13.debug(`[Migration] ⊘ Could not disable RLS on ${tableName}`);
@@ -20837,7 +20353,7 @@ async function migrateToEntityRLS(adapter) {
20837
20353
  const tablesToMigrate = ["channels", "worlds", "rooms"];
20838
20354
  for (const tableName of tablesToMigrate) {
20839
20355
  try {
20840
- const columnsResult = await db.execute(sql30`
20356
+ const columnsResult = await db.execute(sql29`
20841
20357
  SELECT column_name, data_type, is_nullable
20842
20358
  FROM information_schema.columns
20843
20359
  WHERE table_schema = 'public'
@@ -20853,19 +20369,19 @@ async function migrateToEntityRLS(adapter) {
20853
20369
  const oldColumnName = serverIdSnake ? "server_id" : "serverId";
20854
20370
  if (serverId && !messageServerId) {
20855
20371
  logger13.debug(`[Migration] → Renaming ${tableName}.${oldColumnName} to message_server_id...`);
20856
- await db.execute(sql30.raw(`ALTER TABLE "${tableName}" RENAME COLUMN "${oldColumnName}" TO "message_server_id"`));
20372
+ await db.execute(sql29.raw(`ALTER TABLE "${tableName}" RENAME COLUMN "${oldColumnName}" TO "message_server_id"`));
20857
20373
  logger13.debug(`[Migration] ✓ Renamed ${tableName}.${oldColumnName} → message_server_id`);
20858
20374
  if (serverId.data_type === "text") {
20859
20375
  try {
20860
20376
  logger13.debug(`[Migration] → Dropping DEFAULT constraint on ${tableName}.message_server_id...`);
20861
- await db.execute(sql30.raw(`ALTER TABLE "${tableName}" ALTER COLUMN "message_server_id" DROP DEFAULT`));
20377
+ await db.execute(sql29.raw(`ALTER TABLE "${tableName}" ALTER COLUMN "message_server_id" DROP DEFAULT`));
20862
20378
  logger13.debug(`[Migration] ✓ Dropped DEFAULT constraint`);
20863
20379
  } catch {
20864
20380
  logger13.debug(`[Migration] ⊘ No DEFAULT constraint to drop on ${tableName}.message_server_id`);
20865
20381
  }
20866
20382
  try {
20867
20383
  logger13.debug(`[Migration] → Converting ${tableName}.message_server_id from text to uuid...`);
20868
- await db.execute(sql30.raw(`
20384
+ await db.execute(sql29.raw(`
20869
20385
  ALTER TABLE "${tableName}"
20870
20386
  ALTER COLUMN "message_server_id" TYPE uuid
20871
20387
  USING CASE
@@ -20882,29 +20398,29 @@ async function migrateToEntityRLS(adapter) {
20882
20398
  }
20883
20399
  }
20884
20400
  if (tableName === "channels") {
20885
- const nullCountResult = await db.execute(sql30.raw(`SELECT COUNT(*) as count FROM "${tableName}" WHERE "message_server_id" IS NULL`));
20401
+ const nullCountResult = await db.execute(sql29.raw(`SELECT COUNT(*) as count FROM "${tableName}" WHERE "message_server_id" IS NULL`));
20886
20402
  const nullCount = nullCountResult.rows?.[0]?.count;
20887
20403
  if (nullCount && parseInt(nullCount, 10) > 0) {
20888
20404
  logger13.warn(`[Migration] ⚠️ ${tableName} has ${nullCount} rows with NULL message_server_id - these will be deleted`);
20889
- await db.execute(sql30.raw(`DELETE FROM "${tableName}" WHERE "message_server_id" IS NULL`));
20405
+ await db.execute(sql29.raw(`DELETE FROM "${tableName}" WHERE "message_server_id" IS NULL`));
20890
20406
  logger13.debug(`[Migration] ✓ Deleted ${nullCount} rows with NULL message_server_id from ${tableName}`);
20891
20407
  }
20892
20408
  logger13.debug(`[Migration] → Making ${tableName}.message_server_id NOT NULL...`);
20893
- await db.execute(sql30.raw(`ALTER TABLE "${tableName}" ALTER COLUMN "message_server_id" SET NOT NULL`));
20409
+ await db.execute(sql29.raw(`ALTER TABLE "${tableName}" ALTER COLUMN "message_server_id" SET NOT NULL`));
20894
20410
  logger13.debug(`[Migration] ✓ Set ${tableName}.message_server_id NOT NULL`);
20895
20411
  }
20896
20412
  } else if (serverId && messageServerId) {
20897
20413
  logger13.debug(`[Migration] → ${tableName} has both columns, dropping ${oldColumnName}...`);
20898
- await db.execute(sql30.raw(`ALTER TABLE "${tableName}" DROP COLUMN "${oldColumnName}" CASCADE`));
20414
+ await db.execute(sql29.raw(`ALTER TABLE "${tableName}" DROP COLUMN "${oldColumnName}" CASCADE`));
20899
20415
  logger13.debug(`[Migration] ✓ Dropped ${tableName}.${oldColumnName}`);
20900
20416
  } else if (!serverId && messageServerId) {
20901
20417
  if (messageServerId.data_type === "text") {
20902
20418
  logger13.debug(`[Migration] → ${tableName}.message_server_id exists but is TEXT, needs UUID conversion...`);
20903
20419
  logger13.debug(`[Migration] → Dropping DEFAULT constraint on ${tableName}.message_server_id...`);
20904
- await db.execute(sql30.raw(`ALTER TABLE "${tableName}" ALTER COLUMN "message_server_id" DROP DEFAULT`));
20420
+ await db.execute(sql29.raw(`ALTER TABLE "${tableName}" ALTER COLUMN "message_server_id" DROP DEFAULT`));
20905
20421
  logger13.debug(`[Migration] ✓ Dropped DEFAULT constraint`);
20906
20422
  logger13.debug(`[Migration] → Converting ${tableName}.message_server_id from text to uuid (generating UUIDs from text)...`);
20907
- await db.execute(sql30.raw(`
20423
+ await db.execute(sql29.raw(`
20908
20424
  ALTER TABLE "${tableName}"
20909
20425
  ALTER COLUMN "message_server_id" TYPE uuid
20910
20426
  USING CASE
@@ -20926,7 +20442,7 @@ async function migrateToEntityRLS(adapter) {
20926
20442
  }
20927
20443
  logger13.debug("[Migration] → Dropping all remaining RLS-managed server_id columns...");
20928
20444
  try {
20929
- const serverIdColumnsResult = await db.execute(sql30`
20445
+ const serverIdColumnsResult = await db.execute(sql29`
20930
20446
  SELECT table_name
20931
20447
  FROM information_schema.columns
20932
20448
  WHERE table_schema = 'public'
@@ -20948,7 +20464,7 @@ async function migrateToEntityRLS(adapter) {
20948
20464
  for (const row of tablesToClean) {
20949
20465
  const tableName = row.table_name;
20950
20466
  try {
20951
- await db.execute(sql30.raw(`ALTER TABLE "${tableName}" DROP COLUMN IF EXISTS server_id CASCADE`));
20467
+ await db.execute(sql29.raw(`ALTER TABLE "${tableName}" DROP COLUMN IF EXISTS server_id CASCADE`));
20952
20468
  logger13.debug(`[Migration] ✓ Dropped server_id from ${tableName}`);
20953
20469
  } catch (error) {
20954
20470
  logger13.debug(`[Migration] ⊘ Could not drop server_id from ${tableName}`);
@@ -20959,7 +20475,7 @@ async function migrateToEntityRLS(adapter) {
20959
20475
  }
20960
20476
  logger13.debug("[Migration] → Checking agents.owner_id → server_id rename...");
20961
20477
  try {
20962
- const agentsColumnsResult = await db.execute(sql30`
20478
+ const agentsColumnsResult = await db.execute(sql29`
20963
20479
  SELECT column_name
20964
20480
  FROM information_schema.columns
20965
20481
  WHERE table_schema = 'public'
@@ -20972,11 +20488,11 @@ async function migrateToEntityRLS(adapter) {
20972
20488
  const hasServerId = agentsColumns.some((c) => c.column_name === "server_id");
20973
20489
  if (hasOwnerId && !hasServerId) {
20974
20490
  logger13.debug("[Migration] → Renaming agents.owner_id to server_id...");
20975
- await db.execute(sql30.raw(`ALTER TABLE "agents" RENAME COLUMN "owner_id" TO "server_id"`));
20491
+ await db.execute(sql29.raw(`ALTER TABLE "agents" RENAME COLUMN "owner_id" TO "server_id"`));
20976
20492
  logger13.debug("[Migration] ✓ Renamed agents.owner_id → server_id");
20977
20493
  } else if (hasOwnerId && hasServerId) {
20978
20494
  logger13.debug("[Migration] → Both owner_id and server_id exist, dropping owner_id...");
20979
- await db.execute(sql30.raw(`ALTER TABLE "agents" DROP COLUMN "owner_id" CASCADE`));
20495
+ await db.execute(sql29.raw(`ALTER TABLE "agents" DROP COLUMN "owner_id" CASCADE`));
20980
20496
  logger13.debug("[Migration] ✓ Dropped agents.owner_id");
20981
20497
  } else {
20982
20498
  logger13.debug("[Migration] ⊘ agents table already has server_id (or no owner_id), skipping");
@@ -20986,7 +20502,7 @@ async function migrateToEntityRLS(adapter) {
20986
20502
  }
20987
20503
  logger13.debug("[Migration] → Checking for owners → servers data migration...");
20988
20504
  try {
20989
- const ownersTableResult = await db.execute(sql30`
20505
+ const ownersTableResult = await db.execute(sql29`
20990
20506
  SELECT table_name
20991
20507
  FROM information_schema.tables
20992
20508
  WHERE table_schema = 'public'
@@ -20994,7 +20510,7 @@ async function migrateToEntityRLS(adapter) {
20994
20510
  `);
20995
20511
  if (ownersTableResult.rows && ownersTableResult.rows.length > 0) {
20996
20512
  logger13.debug("[Migration] → Ensuring servers table exists...");
20997
- await db.execute(sql30.raw(`
20513
+ await db.execute(sql29.raw(`
20998
20514
  CREATE TABLE IF NOT EXISTS "servers" (
20999
20515
  "id" uuid PRIMARY KEY,
21000
20516
  "created_at" timestamp with time zone DEFAULT now() NOT NULL,
@@ -21002,7 +20518,7 @@ async function migrateToEntityRLS(adapter) {
21002
20518
  )
21003
20519
  `));
21004
20520
  logger13.debug("[Migration] → Migrating owners data to servers...");
21005
- await db.execute(sql30.raw(`
20521
+ await db.execute(sql29.raw(`
21006
20522
  INSERT INTO "servers" ("id", "created_at", "updated_at")
21007
20523
  SELECT "id", COALESCE("created_at", now()), COALESCE("updated_at", now())
21008
20524
  FROM "owners"
@@ -21010,7 +20526,7 @@ async function migrateToEntityRLS(adapter) {
21010
20526
  `));
21011
20527
  logger13.debug("[Migration] ✓ Migrated owners data to servers");
21012
20528
  logger13.debug("[Migration] → Dropping obsolete owners table...");
21013
- await db.execute(sql30.raw(`DROP TABLE IF EXISTS "owners" CASCADE`));
20529
+ await db.execute(sql29.raw(`DROP TABLE IF EXISTS "owners" CASCADE`));
21014
20530
  logger13.debug("[Migration] ✓ Dropped obsolete owners table");
21015
20531
  } else {
21016
20532
  logger13.debug("[Migration] ⊘ owners table not found, skipping");
@@ -21020,7 +20536,7 @@ async function migrateToEntityRLS(adapter) {
21020
20536
  }
21021
20537
  logger13.debug("[Migration] → Checking server_agents table rename...");
21022
20538
  try {
21023
- const tablesResult = await db.execute(sql30`
20539
+ const tablesResult = await db.execute(sql29`
21024
20540
  SELECT table_name
21025
20541
  FROM information_schema.tables
21026
20542
  WHERE table_schema = 'public'
@@ -21032,16 +20548,16 @@ async function migrateToEntityRLS(adapter) {
21032
20548
  const hasMessageServerAgents = tables.some((t) => t.table_name === "message_server_agents");
21033
20549
  if (hasServerAgents && !hasMessageServerAgents) {
21034
20550
  logger13.debug("[Migration] → Renaming server_agents to message_server_agents...");
21035
- await db.execute(sql30.raw(`ALTER TABLE "server_agents" RENAME TO "message_server_agents"`));
20551
+ await db.execute(sql29.raw(`ALTER TABLE "server_agents" RENAME TO "message_server_agents"`));
21036
20552
  logger13.debug("[Migration] ✓ Renamed server_agents → message_server_agents");
21037
20553
  logger13.debug("[Migration] → Renaming message_server_agents.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"`));
20554
+ await db.execute(sql29.raw(`ALTER TABLE "message_server_agents" RENAME COLUMN "server_id" TO "message_server_id"`));
21039
20555
  logger13.debug("[Migration] ✓ Renamed message_server_agents.server_id → message_server_id");
21040
20556
  } else if (!hasServerAgents && !hasMessageServerAgents) {
21041
20557
  logger13.debug("[Migration] ⊘ No server_agents table to migrate");
21042
20558
  } else if (hasMessageServerAgents) {
21043
20559
  logger13.debug("[Migration] → Checking message_server_agents columns...");
21044
- const columnsResult = await db.execute(sql30`
20560
+ const columnsResult = await db.execute(sql29`
21045
20561
  SELECT column_name
21046
20562
  FROM information_schema.columns
21047
20563
  WHERE table_schema = 'public'
@@ -21054,11 +20570,11 @@ async function migrateToEntityRLS(adapter) {
21054
20570
  const hasMessageServerId = columns.some((c) => c.column_name === "message_server_id");
21055
20571
  if (hasServerId && !hasMessageServerId) {
21056
20572
  logger13.debug("[Migration] → Renaming message_server_agents.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"`));
20573
+ await db.execute(sql29.raw(`ALTER TABLE "message_server_agents" RENAME COLUMN "server_id" TO "message_server_id"`));
21058
20574
  logger13.debug("[Migration] ✓ Renamed message_server_agents.server_id → message_server_id");
21059
20575
  } else if (!hasServerId && !hasMessageServerId) {
21060
20576
  logger13.debug("[Migration] → message_server_agents exists without required columns, truncating...");
21061
- await db.execute(sql30`TRUNCATE TABLE message_server_agents CASCADE`);
20577
+ await db.execute(sql29`TRUNCATE TABLE message_server_agents CASCADE`);
21062
20578
  logger13.debug("[Migration] ✓ Truncated message_server_agents");
21063
20579
  } else {
21064
20580
  logger13.debug("[Migration] ⊘ message_server_agents already has correct schema");
@@ -21069,7 +20585,7 @@ async function migrateToEntityRLS(adapter) {
21069
20585
  }
21070
20586
  logger13.debug("[Migration] → Checking channel_participants table...");
21071
20587
  try {
21072
- const columnsResult = await db.execute(sql30`
20588
+ const columnsResult = await db.execute(sql29`
21073
20589
  SELECT column_name
21074
20590
  FROM information_schema.columns
21075
20591
  WHERE table_schema = 'public'
@@ -21082,11 +20598,11 @@ async function migrateToEntityRLS(adapter) {
21082
20598
  const hasEntityId = columns.some((c) => c.column_name === "entity_id");
21083
20599
  if (hasUserId && !hasEntityId) {
21084
20600
  logger13.debug("[Migration] → Renaming channel_participants.user_id to entity_id...");
21085
- await db.execute(sql30.raw(`ALTER TABLE "channel_participants" RENAME COLUMN "user_id" TO "entity_id"`));
20601
+ await db.execute(sql29.raw(`ALTER TABLE "channel_participants" RENAME COLUMN "user_id" TO "entity_id"`));
21086
20602
  logger13.debug("[Migration] ✓ Renamed channel_participants.user_id → entity_id");
21087
20603
  } else if (!hasUserId && !hasEntityId) {
21088
20604
  logger13.debug("[Migration] → channel_participants exists without entity_id or user_id, truncating...");
21089
- await db.execute(sql30`TRUNCATE TABLE channel_participants CASCADE`);
20605
+ await db.execute(sql29`TRUNCATE TABLE channel_participants CASCADE`);
21090
20606
  logger13.debug("[Migration] ✓ Truncated channel_participants");
21091
20607
  } else {
21092
20608
  logger13.debug("[Migration] ⊘ channel_participants already has entity_id column");
@@ -21096,7 +20612,7 @@ async function migrateToEntityRLS(adapter) {
21096
20612
  }
21097
20613
  logger13.debug("[Migration] → Discovering and dropping all regular indexes...");
21098
20614
  try {
21099
- const indexesResult = await db.execute(sql30`
20615
+ const indexesResult = await db.execute(sql29`
21100
20616
  SELECT i.relname AS index_name
21101
20617
  FROM pg_index idx
21102
20618
  JOIN pg_class i ON i.oid = idx.indexrelid
@@ -21113,7 +20629,7 @@ async function migrateToEntityRLS(adapter) {
21113
20629
  for (const row of indexesToDrop) {
21114
20630
  const indexName = row.index_name;
21115
20631
  try {
21116
- await db.execute(sql30.raw(`DROP INDEX IF EXISTS "${indexName}"`));
20632
+ await db.execute(sql29.raw(`DROP INDEX IF EXISTS "${indexName}"`));
21117
20633
  logger13.debug(`[Migration] ✓ Dropped index ${indexName}`);
21118
20634
  } catch (error) {
21119
20635
  logger13.debug(`[Migration] ⊘ Could not drop index ${indexName}`);
@@ -21170,14 +20686,14 @@ async function migrateToEntityRLS(adapter) {
21170
20686
  ];
21171
20687
  for (const rename of columnRenames) {
21172
20688
  try {
21173
- const tableExistsResult = await db.execute(sql30`
20689
+ const tableExistsResult = await db.execute(sql29`
21174
20690
  SELECT 1 FROM information_schema.tables
21175
20691
  WHERE table_schema = 'public' AND table_name = ${rename.table}
21176
20692
  `);
21177
20693
  if (!tableExistsResult.rows || tableExistsResult.rows.length === 0) {
21178
20694
  continue;
21179
20695
  }
21180
- const columnsResult = await db.execute(sql30`
20696
+ const columnsResult = await db.execute(sql29`
21181
20697
  SELECT column_name
21182
20698
  FROM information_schema.columns
21183
20699
  WHERE table_schema = 'public'
@@ -21190,11 +20706,11 @@ async function migrateToEntityRLS(adapter) {
21190
20706
  const hasNewColumn = columns.some((c) => c.column_name === rename.to);
21191
20707
  if (hasOldColumn && !hasNewColumn) {
21192
20708
  logger13.debug(`[Migration] → Renaming ${rename.table}.${rename.from} to ${rename.to}...`);
21193
- await db.execute(sql30.raw(`ALTER TABLE "${rename.table}" RENAME COLUMN "${rename.from}" TO "${rename.to}"`));
20709
+ await db.execute(sql29.raw(`ALTER TABLE "${rename.table}" RENAME COLUMN "${rename.from}" TO "${rename.to}"`));
21194
20710
  logger13.debug(`[Migration] ✓ Renamed ${rename.table}.${rename.from} → ${rename.to}`);
21195
20711
  } else if (hasOldColumn && hasNewColumn) {
21196
20712
  logger13.debug(`[Migration] → Both columns exist, dropping ${rename.table}.${rename.from}...`);
21197
- await db.execute(sql30.raw(`ALTER TABLE "${rename.table}" DROP COLUMN "${rename.from}" CASCADE`));
20713
+ await db.execute(sql29.raw(`ALTER TABLE "${rename.table}" DROP COLUMN "${rename.from}" CASCADE`));
21198
20714
  logger13.debug(`[Migration] ✓ Dropped ${rename.table}.${rename.from}`);
21199
20715
  }
21200
20716
  } catch (error) {
@@ -21212,17 +20728,17 @@ var init_migrations = () => {};
21212
20728
 
21213
20729
  // src/rls.ts
21214
20730
  import { logger as logger14, validateUuid } from "@elizaos/core";
21215
- import { sql as sql31, eq as eq13 } from "drizzle-orm";
20731
+ import { sql as sql30, eq as eq13 } from "drizzle-orm";
21216
20732
  async function installRLSFunctions(adapter) {
21217
20733
  const db = getDb(adapter);
21218
- await db.execute(sql31`
20734
+ await db.execute(sql30`
21219
20735
  CREATE TABLE IF NOT EXISTS servers (
21220
20736
  id UUID PRIMARY KEY,
21221
20737
  created_at TIMESTAMPTZ DEFAULT NOW() NOT NULL,
21222
20738
  updated_at TIMESTAMPTZ DEFAULT NOW() NOT NULL
21223
20739
  )
21224
20740
  `);
21225
- await db.execute(sql31`
20741
+ await db.execute(sql30`
21226
20742
  CREATE OR REPLACE FUNCTION current_server_id() RETURNS UUID AS $$
21227
20743
  DECLARE
21228
20744
  server_id_text TEXT;
@@ -21241,7 +20757,7 @@ async function installRLSFunctions(adapter) {
21241
20757
  END;
21242
20758
  $$ LANGUAGE plpgsql STABLE;
21243
20759
  `);
21244
- await db.execute(sql31`
20760
+ await db.execute(sql30`
21245
20761
  CREATE OR REPLACE FUNCTION add_server_isolation(
21246
20762
  schema_name text,
21247
20763
  table_name text
@@ -21304,7 +20820,7 @@ async function installRLSFunctions(adapter) {
21304
20820
  END;
21305
20821
  $$ LANGUAGE plpgsql;
21306
20822
  `);
21307
- await db.execute(sql31`
20823
+ await db.execute(sql30`
21308
20824
  CREATE OR REPLACE FUNCTION apply_rls_to_all_tables() RETURNS void AS $$
21309
20825
  DECLARE
21310
20826
  tbl record;
@@ -21334,7 +20850,7 @@ async function installRLSFunctions(adapter) {
21334
20850
  async function applyRLSToNewTables(adapter) {
21335
20851
  const db = getDb(adapter);
21336
20852
  try {
21337
- await db.execute(sql31`SELECT apply_rls_to_all_tables()`);
20853
+ await db.execute(sql30`SELECT apply_rls_to_all_tables()`);
21338
20854
  logger14.info({ src: "plugin:sql" }, "RLS applied to all tables");
21339
20855
  } catch (error) {
21340
20856
  logger14.warn({ src: "plugin:sql", error: String(error) }, "Failed to apply RLS to some tables");
@@ -21343,7 +20859,7 @@ async function applyRLSToNewTables(adapter) {
21343
20859
  async function installEntityRLS(adapter) {
21344
20860
  const db = getDb(adapter);
21345
20861
  logger14.info("[Entity RLS] Installing entity RLS functions and policies...");
21346
- await db.execute(sql31`
20862
+ await db.execute(sql30`
21347
20863
  CREATE OR REPLACE FUNCTION current_entity_id()
21348
20864
  RETURNS UUID AS $$
21349
20865
  DECLARE
@@ -21365,7 +20881,7 @@ async function installEntityRLS(adapter) {
21365
20881
  $$ LANGUAGE plpgsql STABLE;
21366
20882
  `);
21367
20883
  logger14.info("[Entity RLS] Created current_entity_id() function");
21368
- await db.execute(sql31`
20884
+ await db.execute(sql30`
21369
20885
  CREATE OR REPLACE FUNCTION add_entity_isolation(
21370
20886
  schema_name text,
21371
20887
  table_name text,
@@ -21545,7 +21061,7 @@ async function installEntityRLS(adapter) {
21545
21061
  $$ LANGUAGE plpgsql;
21546
21062
  `);
21547
21063
  logger14.info("[Entity RLS] Created add_entity_isolation() function");
21548
- await db.execute(sql31`
21064
+ await db.execute(sql30`
21549
21065
  CREATE OR REPLACE FUNCTION apply_entity_rls_to_all_tables() RETURNS void AS $$
21550
21066
  DECLARE
21551
21067
  tbl record;
@@ -21591,7 +21107,7 @@ async function installEntityRLS(adapter) {
21591
21107
  async function applyEntityRLSToAllTables(adapter) {
21592
21108
  const db = getDb(adapter);
21593
21109
  try {
21594
- await db.execute(sql31`SELECT apply_entity_rls_to_all_tables()`);
21110
+ await db.execute(sql30`SELECT apply_entity_rls_to_all_tables()`);
21595
21111
  logger14.info("[Entity RLS] Applied entity RLS to all eligible tables");
21596
21112
  } catch (error) {
21597
21113
  logger14.warn("[Entity RLS] Failed to apply entity RLS to some tables:", String(error));
@@ -21717,14 +21233,391 @@ import { logger as logger17 } from "@elizaos/core";
21717
21233
  import { drizzle } from "drizzle-orm/pglite";
21718
21234
 
21719
21235
  // src/base.ts
21720
- init_embedding();
21721
- init_schema();
21722
21236
  import {
21723
21237
  DatabaseAdapter,
21724
21238
  logger as logger16
21725
21239
  } from "@elizaos/core";
21726
- import { and as and11, eq as eq14, inArray as inArray5, sql as sql32 } from "drizzle-orm";
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
+ });
21410
+
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
+ });
21727
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] })]);
21728
21621
  // src/utils.ts
21729
21622
  function sanitizeJsonObject(value, seen = new WeakSet) {
21730
21623
  if (value === null || value === undefined) {
@@ -21754,10 +21647,8 @@ function sanitizeJsonObject(value, seen = new WeakSet) {
21754
21647
  }
21755
21648
 
21756
21649
  // src/stores/agent.store.ts
21757
- init_schema();
21758
21650
  import { logger } from "@elizaos/core";
21759
21651
  import { count, eq } from "drizzle-orm";
21760
-
21761
21652
  class AgentStore {
21762
21653
  ctx;
21763
21654
  constructor(ctx) {
@@ -21944,9 +21835,9 @@ class AgentStore {
21944
21835
 
21945
21836
  // src/stores/memory.store.ts
21946
21837
  import { logger as logger2 } from "@elizaos/core";
21947
- import { and, cosineDistance, desc, eq as eq2, gte, inArray, lte, sql as sql18 } from "drizzle-orm";
21838
+ import { and, cosineDistance, desc, eq as eq2, gte, inArray, lte, sql as sql17 } from "drizzle-orm";
21948
21839
 
21949
- // ../../node_modules/uuid/dist/stringify.js
21840
+ // ../../node_modules/.bun/uuid@13.0.0/node_modules/uuid/dist/stringify.js
21950
21841
  var byteToHex = [];
21951
21842
  for (let i = 0;i < 256; ++i) {
21952
21843
  byteToHex.push((i + 256).toString(16).slice(1));
@@ -21955,7 +21846,7 @@ function unsafeStringify(arr, offset = 0) {
21955
21846
  return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
21956
21847
  }
21957
21848
 
21958
- // ../../node_modules/uuid/dist/rng.js
21849
+ // ../../node_modules/.bun/uuid@13.0.0/node_modules/uuid/dist/rng.js
21959
21850
  var getRandomValues;
21960
21851
  var rnds8 = new Uint8Array(16);
21961
21852
  function rng() {
@@ -21968,11 +21859,11 @@ function rng() {
21968
21859
  return getRandomValues(rnds8);
21969
21860
  }
21970
21861
 
21971
- // ../../node_modules/uuid/dist/native.js
21862
+ // ../../node_modules/.bun/uuid@13.0.0/node_modules/uuid/dist/native.js
21972
21863
  var randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
21973
21864
  var native_default = { randomUUID };
21974
21865
 
21975
- // ../../node_modules/uuid/dist/v4.js
21866
+ // ../../node_modules/.bun/uuid@13.0.0/node_modules/uuid/dist/v4.js
21976
21867
  function _v4(options, buf, offset) {
21977
21868
  options = options || {};
21978
21869
  const rnds = options.random ?? options.rng?.() ?? rng();
@@ -22001,8 +21892,6 @@ function v4(options, buf, offset) {
22001
21892
  }
22002
21893
  var v4_default = v4;
22003
21894
  // src/stores/memory.store.ts
22004
- init_schema();
22005
-
22006
21895
  class MemoryStore {
22007
21896
  ctx;
22008
21897
  constructor(ctx) {
@@ -22157,7 +22046,7 @@ class MemoryStore {
22157
22046
  async searchByEmbedding(embedding, params) {
22158
22047
  return this.ctx.withRetry(async () => {
22159
22048
  const cleanVector = embedding.map((n) => Number.isFinite(n) ? Number(n.toFixed(6)) : 0);
22160
- const similarity = sql18`1 - (${cosineDistance(embeddingTable[this.ctx.getEmbeddingDimension()], cleanVector)})`;
22049
+ const similarity = sql17`1 - (${cosineDistance(embeddingTable[this.ctx.getEmbeddingDimension()], cleanVector)})`;
22161
22050
  const conditions = [
22162
22051
  eq2(memoryTable.type, params.tableName),
22163
22052
  eq2(memoryTable.agentId, this.ctx.agentId)
@@ -22216,8 +22105,8 @@ class MemoryStore {
22216
22105
  {
22217
22106
  id: memoryId,
22218
22107
  type: tableName,
22219
- content: sql18`${contentToInsert}::jsonb`,
22220
- metadata: sql18`${metadataToInsert}::jsonb`,
22108
+ content: sql17`${contentToInsert}::jsonb`,
22109
+ metadata: sql17`${metadataToInsert}::jsonb`,
22221
22110
  entityId: memory.entityId,
22222
22111
  roomId: memory.roomId,
22223
22112
  worldId: memory.worldId,
@@ -22240,12 +22129,12 @@ class MemoryStore {
22240
22129
  const contentToUpdate = typeof memory.content === "string" ? memory.content : JSON.stringify(memory.content ?? {});
22241
22130
  const metadataToUpdate = typeof memory.metadata === "string" ? memory.metadata : JSON.stringify(memory.metadata ?? {});
22242
22131
  await tx.update(memoryTable).set({
22243
- content: sql18`${contentToUpdate}::jsonb`,
22244
- ...memory.metadata && { metadata: sql18`${metadataToUpdate}::jsonb` }
22132
+ content: sql17`${contentToUpdate}::jsonb`,
22133
+ ...memory.metadata && { metadata: sql17`${metadataToUpdate}::jsonb` }
22245
22134
  }).where(eq2(memoryTable.id, memory.id));
22246
22135
  } else if (memory.metadata) {
22247
22136
  const metadataToUpdate = typeof memory.metadata === "string" ? memory.metadata : JSON.stringify(memory.metadata ?? {});
22248
- await tx.update(memoryTable).set({ metadata: sql18`${metadataToUpdate}::jsonb` }).where(eq2(memoryTable.id, memory.id));
22137
+ await tx.update(memoryTable).set({ metadata: sql17`${metadataToUpdate}::jsonb` }).where(eq2(memoryTable.id, memory.id));
22249
22138
  }
22250
22139
  if (memory.embedding && Array.isArray(memory.embedding)) {
22251
22140
  await this.upsertEmbedding(tx, memory.id, memory.embedding);
@@ -22308,7 +22197,7 @@ class MemoryStore {
22308
22197
  const conditions = [eq2(memoryTable.roomId, roomId), eq2(memoryTable.type, tableName)];
22309
22198
  if (unique3)
22310
22199
  conditions.push(eq2(memoryTable.unique, true));
22311
- const result = await this.db.select({ count: sql18`count(*)` }).from(memoryTable).where(and(...conditions));
22200
+ const result = await this.db.select({ count: sql17`count(*)` }).from(memoryTable).where(and(...conditions));
22312
22201
  return Number(result[0]?.count ?? 0);
22313
22202
  }, "MemoryStore.count");
22314
22203
  }
@@ -22326,7 +22215,7 @@ class MemoryStore {
22326
22215
  }
22327
22216
  }
22328
22217
  async deleteFragments(tx, 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}`));
22218
+ const fragments = await tx.select({ id: memoryTable.id }).from(memoryTable).where(and(eq2(memoryTable.agentId, this.ctx.agentId), sql17`${memoryTable.metadata}->>'documentId' = ${documentId}`));
22330
22219
  if (fragments.length > 0) {
22331
22220
  const fragmentIds = fragments.map((f) => f.id);
22332
22221
  await tx.delete(embeddingTable).where(inArray(embeddingTable.memoryId, fragmentIds));
@@ -22337,8 +22226,6 @@ class MemoryStore {
22337
22226
 
22338
22227
  // src/stores/room.store.ts
22339
22228
  import { and as and2, eq as eq3, inArray as inArray2 } from "drizzle-orm";
22340
- init_schema();
22341
-
22342
22229
  class RoomStore {
22343
22230
  ctx;
22344
22231
  constructor(ctx) {
@@ -22424,10 +22311,8 @@ class RoomStore {
22424
22311
  }
22425
22312
 
22426
22313
  // src/stores/participant.store.ts
22427
- init_schema();
22428
22314
  import { logger as logger3 } from "@elizaos/core";
22429
22315
  import { and as and3, eq as eq4, inArray as inArray3 } from "drizzle-orm";
22430
-
22431
22316
  class ParticipantStore {
22432
22317
  ctx;
22433
22318
  constructor(ctx) {
@@ -22561,10 +22446,8 @@ class ParticipantStore {
22561
22446
  }
22562
22447
 
22563
22448
  // src/stores/entity.store.ts
22564
- init_schema();
22565
22449
  import { logger as logger4 } from "@elizaos/core";
22566
- import { and as and4, eq as eq5, inArray as inArray4, or, sql as sql19 } from "drizzle-orm";
22567
-
22450
+ import { and as and4, eq as eq5, inArray as inArray4, or, sql as sql18 } from "drizzle-orm";
22568
22451
  class EntityStore {
22569
22452
  ctx;
22570
22453
  constructor(ctx) {
@@ -22701,11 +22584,11 @@ class EntityStore {
22701
22584
  async getByNames(params) {
22702
22585
  return this.ctx.withRetry(async () => {
22703
22586
  const { names, agentId } = params;
22704
- const nameConditions = names.map((name) => sql19`${name} = ANY(${entityTable.names})`);
22705
- const query = sql19`
22587
+ const nameConditions = names.map((name) => sql18`${name} = ANY(${entityTable.names})`);
22588
+ const query = sql18`
22706
22589
  SELECT * FROM ${entityTable}
22707
22590
  WHERE ${entityTable.agentId} = ${agentId}
22708
- AND (${sql19.join(nameConditions, sql19` OR `)})
22591
+ AND (${sql18.join(nameConditions, sql18` OR `)})
22709
22592
  `;
22710
22593
  const result = await this.db.execute(query);
22711
22594
  return result.rows.map((row) => ({
@@ -22728,7 +22611,7 @@ class EntityStore {
22728
22611
  metadata: row.metadata || {}
22729
22612
  }));
22730
22613
  }
22731
- const searchQuery = sql19`
22614
+ const searchQuery = sql18`
22732
22615
  SELECT * FROM ${entityTable}
22733
22616
  WHERE ${entityTable.agentId} = ${agentId}
22734
22617
  AND EXISTS (
@@ -22763,9 +22646,7 @@ class EntityStore {
22763
22646
  }
22764
22647
 
22765
22648
  // src/stores/component.store.ts
22766
- init_schema();
22767
22649
  import { and as and5, eq as eq6 } from "drizzle-orm";
22768
-
22769
22650
  class ComponentStore {
22770
22651
  ctx;
22771
22652
  constructor(ctx) {
@@ -22855,9 +22736,7 @@ class ComponentStore {
22855
22736
 
22856
22737
  // src/stores/relationship.store.ts
22857
22738
  import { logger as logger5 } from "@elizaos/core";
22858
- import { and as and6, eq as eq7, sql as sql20 } from "drizzle-orm";
22859
- init_schema();
22860
-
22739
+ import { and as and6, eq as eq7, sql as sql19 } from "drizzle-orm";
22861
22740
  class RelationshipStore {
22862
22741
  ctx;
22863
22742
  constructor(ctx) {
@@ -22933,13 +22812,13 @@ class RelationshipStore {
22933
22812
  const { entityId, tags } = params;
22934
22813
  let query;
22935
22814
  if (tags && tags.length > 0) {
22936
- query = sql20`
22815
+ query = sql19`
22937
22816
  SELECT * FROM ${relationshipTable}
22938
22817
  WHERE (${relationshipTable.sourceEntityId} = ${entityId} OR ${relationshipTable.targetEntityId} = ${entityId})
22939
- AND ${relationshipTable.tags} && CAST(ARRAY[${sql20.join(tags, sql20`, `)}] AS text[])
22818
+ AND ${relationshipTable.tags} && CAST(ARRAY[${sql19.join(tags, sql19`, `)}] AS text[])
22940
22819
  `;
22941
22820
  } else {
22942
- query = sql20`
22821
+ query = sql19`
22943
22822
  SELECT * FROM ${relationshipTable}
22944
22823
  WHERE ${relationshipTable.sourceEntityId} = ${entityId} OR ${relationshipTable.targetEntityId} = ${entityId}
22945
22824
  `;
@@ -22960,10 +22839,8 @@ class RelationshipStore {
22960
22839
  }
22961
22840
 
22962
22841
  // src/stores/cache.store.ts
22963
- init_schema();
22964
22842
  import { logger as logger6 } from "@elizaos/core";
22965
22843
  import { and as and7, eq as eq8 } from "drizzle-orm";
22966
-
22967
22844
  class CacheStore {
22968
22845
  ctx;
22969
22846
  constructor(ctx) {
@@ -23036,8 +22913,6 @@ class CacheStore {
23036
22913
 
23037
22914
  // src/stores/world.store.ts
23038
22915
  import { eq as eq9 } from "drizzle-orm";
23039
- init_schema();
23040
-
23041
22916
  class WorldStore {
23042
22917
  ctx;
23043
22918
  constructor(ctx) {
@@ -23082,9 +22957,7 @@ class WorldStore {
23082
22957
  }
23083
22958
 
23084
22959
  // src/stores/task.store.ts
23085
- init_schema();
23086
- import { and as and8, eq as eq10, sql as sql21 } from "drizzle-orm";
23087
-
22960
+ import { and as and8, eq as eq10, sql as sql20 } from "drizzle-orm";
23088
22961
  class TaskStore {
23089
22962
  ctx;
23090
22963
  constructor(ctx) {
@@ -23118,7 +22991,7 @@ class TaskStore {
23118
22991
  async getAll(params) {
23119
22992
  return this.ctx.withRetry(async () => {
23120
22993
  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 ? [
23121
- sql21`${taskTable.tags} @> ARRAY[${sql21.join(params.tags.map((t) => sql21`${t}`), sql21`, `)}]::text[]`
22994
+ sql20`${taskTable.tags} @> ARRAY[${sql20.join(params.tags.map((t) => sql20`${t}`), sql20`, `)}]::text[]`
23122
22995
  ] : []));
23123
22996
  return result.map((row) => ({
23124
22997
  id: row.id,
@@ -23193,8 +23066,7 @@ class TaskStore {
23193
23066
  }
23194
23067
 
23195
23068
  // src/stores/log.store.ts
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";
23069
+ import { and as and9, desc as desc2, eq as eq11, gte as gte2, lte as lte2, sql as sql21 } from "drizzle-orm";
23198
23070
  import { logger as logger7 } from "@elizaos/core";
23199
23071
  class LogStore {
23200
23072
  ctx;
@@ -23207,7 +23079,7 @@ class LogStore {
23207
23079
  const jsonString = JSON.stringify(sanitizedBody);
23208
23080
  await this.ctx.withIsolationContext(params.entityId, async (tx) => {
23209
23081
  await tx.insert(logTable).values({
23210
- body: sql22`${jsonString}::jsonb`,
23082
+ body: sql21`${jsonString}::jsonb`,
23211
23083
  entityId: params.entityId,
23212
23084
  roomId: params.roomId,
23213
23085
  type: params.type
@@ -23247,7 +23119,7 @@ class LogStore {
23247
23119
  const runMap = new Map;
23248
23120
  const conditions = [
23249
23121
  eq11(logTable.type, "run_event"),
23250
- sql22`${logTable.body} ? 'runId'`,
23122
+ sql21`${logTable.body} ? 'runId'`,
23251
23123
  eq11(roomTable.agentId, agentId)
23252
23124
  ];
23253
23125
  if (params.roomId) {
@@ -23262,9 +23134,9 @@ class LogStore {
23262
23134
  const whereClause = and9(...conditions);
23263
23135
  const eventLimit = Math.max(limit * 20, 200);
23264
23136
  const runEventRows = await tx.select({
23265
- runId: sql22`(${logTable.body} ->> 'runId')`,
23266
- status: sql22`(${logTable.body} ->> 'status')`,
23267
- messageId: sql22`(${logTable.body} ->> 'messageId')`,
23137
+ runId: sql21`(${logTable.body} ->> 'runId')`,
23138
+ status: sql21`(${logTable.body} ->> 'status')`,
23139
+ messageId: sql21`(${logTable.body} ->> 'messageId')`,
23268
23140
  rawBody: logTable.body,
23269
23141
  createdAt: logTable.createdAt,
23270
23142
  roomId: logTable.roomId,
@@ -23311,15 +23183,15 @@ class LogStore {
23311
23183
  }
23312
23184
  }
23313
23185
  const createdAt = row.createdAt instanceof Date ? row.createdAt : new Date(row.createdAt);
23314
- const timestamp18 = createdAt.getTime();
23186
+ const timestamp17 = createdAt.getTime();
23315
23187
  const eventStatus = row.status ?? body?.status;
23316
23188
  if (eventStatus === "started") {
23317
- summary.startedAt = summary.startedAt === null ? timestamp18 : Math.min(summary.startedAt, timestamp18);
23189
+ summary.startedAt = summary.startedAt === null ? timestamp17 : Math.min(summary.startedAt, timestamp17);
23318
23190
  } else if (eventStatus === "completed" || eventStatus === "timeout" || eventStatus === "error") {
23319
23191
  summary.status = eventStatus;
23320
- summary.endedAt = timestamp18;
23192
+ summary.endedAt = timestamp17;
23321
23193
  if (summary.startedAt !== null) {
23322
- summary.durationMs = Math.max(timestamp18 - summary.startedAt, 0);
23194
+ summary.durationMs = Math.max(timestamp17 - summary.startedAt, 0);
23323
23195
  }
23324
23196
  }
23325
23197
  runMap.set(runId, summary);
@@ -23339,8 +23211,8 @@ class LogStore {
23339
23211
  const runIds = limitedRuns.map((run) => run.runId).filter(Boolean);
23340
23212
  if (runIds.length > 0) {
23341
23213
  const db = this.ctx.getDb();
23342
- const runIdArray = sql22`array[${sql22.join(runIds.map((id) => sql22`${id}`), sql22`, `)}]::text[]`;
23343
- const actionSummary = await db.execute(sql22`
23214
+ const runIdArray = sql21`array[${sql21.join(runIds.map((id) => sql21`${id}`), sql21`, `)}]::text[]`;
23215
+ const actionSummary = await db.execute(sql21`
23344
23216
  SELECT
23345
23217
  body->>'runId' as "runId",
23346
23218
  COUNT(*)::int as "actions",
@@ -23360,7 +23232,7 @@ class LogStore {
23360
23232
  counts.errors += Number(row.errors ?? 0);
23361
23233
  counts.modelCalls += Number(row.modelCalls ?? 0);
23362
23234
  }
23363
- const evaluatorSummary = await db.execute(sql22`
23235
+ const evaluatorSummary = await db.execute(sql21`
23364
23236
  SELECT
23365
23237
  body->>'runId' as "runId",
23366
23238
  COUNT(*)::int as "evaluators"
@@ -23376,7 +23248,7 @@ class LogStore {
23376
23248
  continue;
23377
23249
  counts.evaluators += Number(row.evaluators ?? 0);
23378
23250
  }
23379
- const genericSummary = await db.execute(sql22`
23251
+ const genericSummary = await db.execute(sql21`
23380
23252
  SELECT
23381
23253
  body->>'runId' as "runId",
23382
23254
  COUNT(*) FILTER (WHERE type LIKE 'useModel:%')::int as "modelLogs",
@@ -23419,9 +23291,7 @@ class LogStore {
23419
23291
 
23420
23292
  // src/stores/messaging.store.ts
23421
23293
  import { ChannelType } from "@elizaos/core";
23422
- import { and as and10, desc as desc3, eq as eq12, lt, sql as sql23 } from "drizzle-orm";
23423
- init_schema();
23424
-
23294
+ import { and as and10, desc as desc3, eq as eq12, lt, sql as sql22 } from "drizzle-orm";
23425
23295
  class MessagingStore {
23426
23296
  ctx;
23427
23297
  constructor(ctx) {
@@ -23492,7 +23362,7 @@ class MessagingStore {
23492
23362
  }
23493
23363
  async getMessageServerByRlsServerId(rlsServerId) {
23494
23364
  return this.ctx.withRetry(async () => {
23495
- const results = await this.db.execute(sql23`
23365
+ const results = await this.db.execute(sql22`
23496
23366
  SELECT id, name, source_type, source_id, metadata, created_at, updated_at
23497
23367
  FROM message_servers
23498
23368
  WHERE server_id = ${rlsServerId}
@@ -23957,7 +23827,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
23957
23827
  async getCachedEmbeddings(opts) {
23958
23828
  return this.withDatabase(async () => {
23959
23829
  try {
23960
- const results = await this.db.execute(sql32`
23830
+ const results = await this.db.execute(sql31`
23961
23831
  WITH content_text AS (
23962
23832
  SELECT
23963
23833
  m.id,
@@ -24017,7 +23887,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
24017
23887
  const jsonString = JSON.stringify(sanitizedBody);
24018
23888
  await this.withIsolationContext(params.entityId, async (tx) => {
24019
23889
  await tx.insert(logTable).values({
24020
- body: sql32`${jsonString}::jsonb`,
23890
+ body: sql31`${jsonString}::jsonb`,
24021
23891
  entityId: params.entityId,
24022
23892
  roomId: params.roomId,
24023
23893
  type: params.type
@@ -24168,6 +24038,9 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
24168
24038
  return this.withDatabase(() => this.worldStore.remove(id));
24169
24039
  }
24170
24040
  async createTask(task) {
24041
+ if (!task.worldId) {
24042
+ task = { ...task, worldId: this.agentId };
24043
+ }
24171
24044
  return this.withDatabase(() => this.taskStore.create(task));
24172
24045
  }
24173
24046
  async getTasks(params) {
@@ -24289,45 +24162,9 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
24289
24162
  async deleteMessage(messageId) {
24290
24163
  return this.messagingStore.deleteMessage(messageId);
24291
24164
  }
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
- }
24326
24165
  }
24327
24166
 
24328
24167
  // src/pglite/adapter.ts
24329
- init_embedding();
24330
-
24331
24168
  class PgliteDatabaseAdapter extends BaseDrizzleAdapter {
24332
24169
  manager;
24333
24170
  embeddingDimension = DIMENSION_MAP[384];
@@ -24426,7 +24263,6 @@ class PGliteClientManager {
24426
24263
  }
24427
24264
 
24428
24265
  // src/index.browser.ts
24429
- init_schema();
24430
24266
  init_migration_service();
24431
24267
  var GLOBAL_SINGLETONS = Symbol.for("@elizaos/plugin-sql/global-singletons");
24432
24268
  var globalSymbols = globalThis;
@@ -24467,5 +24303,5 @@ export {
24467
24303
  DatabaseMigrationService
24468
24304
  };
24469
24305
 
24470
- //# debugId=D001744F84EC701864756E2164756E21
24306
+ //# debugId=9F23F17868BE44CD64756E2164756E21
24471
24307
  //# sourceMappingURL=index.browser.js.map