@elizaos/plugin-sql 1.7.1-alpha.15 → 1.7.1-alpha.17

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.
@@ -652,7 +652,7 @@ var init_subquery = __esm(() => {
652
652
  });
653
653
 
654
654
  // ../../node_modules/drizzle-orm/version.js
655
- var version = "0.45.0";
655
+ var version = "0.45.1";
656
656
  var init_version = () => {};
657
657
 
658
658
  // ../../node_modules/drizzle-orm/tracing.js
@@ -13034,7 +13034,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
13034
13034
  names: this.normalizeEntityNames(entity2.names),
13035
13035
  metadata: entity2.metadata || {}
13036
13036
  }));
13037
- await tx.insert(entityTable).values(normalizedEntities);
13037
+ await tx.insert(entityTable).values(normalizedEntities).onConflictDoNothing();
13038
13038
  return true;
13039
13039
  });
13040
13040
  } catch (error) {
@@ -13264,7 +13264,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
13264
13264
  metadata: memoryTable.metadata
13265
13265
  },
13266
13266
  embedding: embeddingTable[this.embeddingDimension]
13267
- }).from(memoryTable).leftJoin(embeddingTable, eq(embeddingTable.memoryId, memoryTable.id)).where(and(...conditions2)).orderBy(desc(memoryTable.createdAt));
13267
+ }).from(memoryTable).leftJoin(embeddingTable, eq(embeddingTable.memoryId, memoryTable.id)).where(and(...conditions2)).orderBy(desc(memoryTable.createdAt), desc(memoryTable.id));
13268
13268
  const rows = await (async () => {
13269
13269
  if (params.count && offset !== undefined && offset > 0) {
13270
13270
  return baseQuery.limit(params.count).offset(offset);
@@ -13309,7 +13309,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
13309
13309
  roomId: memoryTable.roomId,
13310
13310
  unique: memoryTable.unique,
13311
13311
  metadata: memoryTable.metadata
13312
- }).from(memoryTable).where(and(...conditions2)).orderBy(desc(memoryTable.createdAt));
13312
+ }).from(memoryTable).where(and(...conditions2)).orderBy(desc(memoryTable.createdAt), desc(memoryTable.id));
13313
13313
  const rows = params.limit ? await query.limit(params.limit) : await query;
13314
13314
  return rows.map((row) => ({
13315
13315
  id: row.id,
@@ -13356,7 +13356,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
13356
13356
  const rows = await this.db.select({
13357
13357
  memory: memoryTable,
13358
13358
  embedding: embeddingTable[this.embeddingDimension]
13359
- }).from(memoryTable).leftJoin(embeddingTable, eq(embeddingTable.memoryId, memoryTable.id)).where(and(...conditions2)).orderBy(desc(memoryTable.createdAt));
13359
+ }).from(memoryTable).leftJoin(embeddingTable, eq(embeddingTable.memoryId, memoryTable.id)).where(and(...conditions2)).orderBy(desc(memoryTable.createdAt), desc(memoryTable.id));
13360
13360
  return rows.map((row) => ({
13361
13361
  id: row.memory.id,
13362
13362
  createdAt: row.memory.createdAt.getTime(),
@@ -13725,10 +13725,6 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
13725
13725
  }
13726
13726
  async createMemory(memory, tableName) {
13727
13727
  const memoryId = memory.id ?? v4();
13728
- const existing = await this.getMemoryById(memoryId);
13729
- if (existing) {
13730
- return memoryId;
13731
- }
13732
13728
  if (memory.unique === undefined) {
13733
13729
  memory.unique = true;
13734
13730
  if (memory.embedding && Array.isArray(memory.embedding)) {
@@ -13746,7 +13742,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
13746
13742
  const contentToInsert = typeof memory.content === "string" ? memory.content : JSON.stringify(memory.content ?? {});
13747
13743
  const metadataToInsert = typeof memory.metadata === "string" ? memory.metadata : JSON.stringify(memory.metadata ?? {});
13748
13744
  await this.withIsolationContext(memory.entityId, async (tx) => {
13749
- await tx.insert(memoryTable).values([
13745
+ const inserted = await tx.insert(memoryTable).values([
13750
13746
  {
13751
13747
  id: memoryId,
13752
13748
  type: tableName,
@@ -13759,20 +13755,29 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
13759
13755
  unique: memory.unique,
13760
13756
  createdAt: memory.createdAt ? new Date(memory.createdAt) : new Date
13761
13757
  }
13762
- ]);
13763
- if (memory.embedding && Array.isArray(memory.embedding)) {
13764
- const embeddingValues = {
13765
- id: v4(),
13766
- memoryId,
13767
- createdAt: memory.createdAt ? new Date(memory.createdAt) : new Date
13768
- };
13769
- const cleanVector = memory.embedding.map((n) => Number.isFinite(n) ? Number(n.toFixed(6)) : 0);
13770
- embeddingValues[this.embeddingDimension] = cleanVector;
13771
- await tx.insert(embeddingTable).values([embeddingValues]);
13758
+ ]).onConflictDoNothing().returning();
13759
+ if (inserted.length > 0 && memory.embedding && Array.isArray(memory.embedding)) {
13760
+ await this.upsertEmbedding(tx, memoryId, memory.embedding);
13772
13761
  }
13773
13762
  });
13774
13763
  return memoryId;
13775
13764
  }
13765
+ async upsertEmbedding(tx, memoryId, embedding) {
13766
+ const cleanVector = embedding.map((n) => Number.isFinite(n) ? Number(n.toFixed(6)) : 0);
13767
+ const existingEmbedding = await tx.select({ id: embeddingTable.id }).from(embeddingTable).where(eq(embeddingTable.memoryId, memoryId)).limit(1);
13768
+ if (existingEmbedding.length > 0) {
13769
+ const updateValues = {};
13770
+ updateValues[this.embeddingDimension] = cleanVector;
13771
+ await tx.update(embeddingTable).set(updateValues).where(eq(embeddingTable.memoryId, memoryId));
13772
+ } else {
13773
+ const embeddingValues = {
13774
+ id: v4(),
13775
+ memoryId
13776
+ };
13777
+ embeddingValues[this.embeddingDimension] = cleanVector;
13778
+ await tx.insert(embeddingTable).values([embeddingValues]);
13779
+ }
13780
+ }
13776
13781
  async updateMemory(memory) {
13777
13782
  return this.withDatabase(async () => {
13778
13783
  try {
@@ -13791,20 +13796,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
13791
13796
  }).where(eq(memoryTable.id, memory.id));
13792
13797
  }
13793
13798
  if (memory.embedding && Array.isArray(memory.embedding)) {
13794
- const cleanVector = memory.embedding.map((n) => Number.isFinite(n) ? Number(n.toFixed(6)) : 0);
13795
- const existingEmbedding = await tx.select({ id: embeddingTable.id }).from(embeddingTable).where(eq(embeddingTable.memoryId, memory.id)).limit(1);
13796
- if (existingEmbedding.length > 0) {
13797
- const updateValues = {};
13798
- updateValues[this.embeddingDimension] = cleanVector;
13799
- await tx.update(embeddingTable).set(updateValues).where(eq(embeddingTable.memoryId, memory.id));
13800
- } else {
13801
- const embeddingValues = {
13802
- id: v4(),
13803
- memoryId: memory.id
13804
- };
13805
- embeddingValues[this.embeddingDimension] = cleanVector;
13806
- await tx.insert(embeddingTable).values([embeddingValues]);
13807
- }
13799
+ await this.upsertEmbedding(tx, memory.id, memory.embedding);
13808
13800
  }
13809
13801
  });
13810
13802
  return true;
@@ -13944,9 +13936,8 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
13944
13936
  agentId: this.agentId,
13945
13937
  id: room.id || v4()
13946
13938
  }));
13947
- const insertedRooms = await this.db.insert(roomTable).values(roomsWithIds).onConflictDoNothing().returning();
13948
- const insertedIds = insertedRooms.map((r) => r.id);
13949
- return insertedIds;
13939
+ await this.db.insert(roomTable).values(roomsWithIds).onConflictDoNothing();
13940
+ return roomsWithIds.map((r) => r.id);
13950
13941
  });
13951
13942
  }
13952
13943
  async deleteRoom(roomId) {
@@ -14244,7 +14235,7 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
14244
14235
  ...world,
14245
14236
  id: newWorldId,
14246
14237
  name: world.name || ""
14247
- });
14238
+ }).onConflictDoNothing();
14248
14239
  return newWorldId;
14249
14240
  });
14250
14241
  }
@@ -14516,16 +14507,14 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
14516
14507
  createdAt: now,
14517
14508
  updatedAt: now
14518
14509
  };
14519
- await this.db.transaction(async (tx) => {
14520
- await tx.insert(channelTable).values(channelToInsert);
14521
- if (participantIds && participantIds.length > 0) {
14522
- const participantValues = participantIds.map((entityId) => ({
14523
- channelId: newId,
14524
- entityId
14525
- }));
14526
- await tx.insert(channelParticipantsTable).values(participantValues).onConflictDoNothing();
14527
- }
14528
- });
14510
+ await this.db.insert(channelTable).values(channelToInsert).onConflictDoNothing();
14511
+ if (participantIds && participantIds.length > 0) {
14512
+ const participantValues = participantIds.map((entityId) => ({
14513
+ channelId: newId,
14514
+ entityId
14515
+ }));
14516
+ await this.db.insert(channelParticipantsTable).values(participantValues).onConflictDoNothing();
14517
+ }
14529
14518
  return channelToInsert;
14530
14519
  });
14531
14520
  }
@@ -14758,7 +14747,7 @@ class PgliteDatabaseAdapter extends BaseDrizzleAdapter {
14758
14747
  this.db = drizzle(this.manager.getConnection());
14759
14748
  }
14760
14749
  async withIsolationContext(_entityId, callback) {
14761
- return this.db.transaction(callback);
14750
+ return callback(this.db);
14762
14751
  }
14763
14752
  async getEntityByIds(entityIds) {
14764
14753
  return this.getEntitiesByIds(entityIds);
@@ -14905,51 +14894,6 @@ class PgDatabaseAdapter extends BaseDrizzleAdapter {
14905
14894
  async getConnection() {
14906
14895
  return this.manager.getConnection();
14907
14896
  }
14908
- async createAgent(agent) {
14909
- return super.createAgent(agent);
14910
- }
14911
- getAgent(agentId) {
14912
- return super.getAgent(agentId);
14913
- }
14914
- updateAgent(agentId, agent) {
14915
- return super.updateAgent(agentId, agent);
14916
- }
14917
- deleteAgent(agentId) {
14918
- return super.deleteAgent(agentId);
14919
- }
14920
- createEntities(entities) {
14921
- return super.createEntities(entities);
14922
- }
14923
- getEntitiesByIds(entityIds) {
14924
- return super.getEntitiesByIds(entityIds).then((result) => result || []);
14925
- }
14926
- updateEntity(entity2) {
14927
- return super.updateEntity(entity2);
14928
- }
14929
- createMemory(memory, tableName) {
14930
- return super.createMemory(memory, tableName);
14931
- }
14932
- getMemoryById(memoryId) {
14933
- return super.getMemoryById(memoryId);
14934
- }
14935
- updateMemory(memory) {
14936
- return super.updateMemory(memory);
14937
- }
14938
- deleteMemory(memoryId) {
14939
- return super.deleteMemory(memoryId);
14940
- }
14941
- createComponent(component) {
14942
- return super.createComponent(component);
14943
- }
14944
- getComponent(entityId, type, worldId, sourceEntityId) {
14945
- return super.getComponent(entityId, type, worldId, sourceEntityId);
14946
- }
14947
- updateComponent(component) {
14948
- return super.updateComponent(component);
14949
- }
14950
- deleteComponent(componentId) {
14951
- return super.deleteComponent(componentId);
14952
- }
14953
14897
  }
14954
14898
 
14955
14899
  // ../../node_modules/drizzle-orm/node-postgres/driver.js
@@ -14971,7 +14915,6 @@ init_sql();
14971
14915
  init_tracing();
14972
14916
  init_utils();
14973
14917
  var { Pool, types: types3 } = pg;
14974
- var NativePool = pg.native ? pg.native.Pool : undefined;
14975
14918
 
14976
14919
  class NodePgPreparedQuery extends PgPreparedQuery {
14977
14920
  constructor(client, queryString, params, logger13, cache, queryMetadata, cacheConfig, fields, name, _isResponseInArrayMode, customResultMapper) {
@@ -15129,7 +15072,8 @@ class NodePgSession extends PgSession {
15129
15072
  return new NodePgPreparedQuery(this.client, query.sql, query.params, this.logger, this.cache, queryMetadata, cacheConfig, fields, name, isResponseInArrayMode, customResultMapper);
15130
15073
  }
15131
15074
  async transaction(transaction, config) {
15132
- const session2 = this.client instanceof Pool || NativePool && this.client instanceof NativePool ? new NodePgSession(await this.client.connect(), this.dialect, this.schema, this.options) : this;
15075
+ const isPool = this.client instanceof Pool || Object.getPrototypeOf(this.client).constructor.name.includes("Pool");
15076
+ const session2 = isPool ? new NodePgSession(await this.client.connect(), this.dialect, this.schema, this.options) : this;
15133
15077
  const tx = new NodePgTransaction(this.dialect, session2, this.schema);
15134
15078
  await tx.execute(sql`begin${config ? sql` ${tx.getTransactionConfigSQL(config)}` : undefined}`);
15135
15079
  try {
@@ -15140,9 +15084,8 @@ class NodePgSession extends PgSession {
15140
15084
  await tx.execute(sql`rollback`);
15141
15085
  throw error;
15142
15086
  } finally {
15143
- if (this.client instanceof Pool || NativePool && this.client instanceof NativePool) {
15087
+ if (isPool)
15144
15088
  session2.client.release();
15145
- }
15146
15089
  }
15147
15090
  }
15148
15091
  async count(sql22) {
@@ -15386,51 +15329,6 @@ class NeonDatabaseAdapter extends BaseDrizzleAdapter {
15386
15329
  async getConnection() {
15387
15330
  return this.manager.getConnection();
15388
15331
  }
15389
- async createAgent(agent) {
15390
- return super.createAgent(agent);
15391
- }
15392
- getAgent(agentId) {
15393
- return super.getAgent(agentId);
15394
- }
15395
- updateAgent(agentId, agent) {
15396
- return super.updateAgent(agentId, agent);
15397
- }
15398
- deleteAgent(agentId) {
15399
- return super.deleteAgent(agentId);
15400
- }
15401
- createEntities(entities) {
15402
- return super.createEntities(entities);
15403
- }
15404
- getEntitiesByIds(entityIds) {
15405
- return super.getEntitiesByIds(entityIds).then((result) => result || []);
15406
- }
15407
- updateEntity(entity2) {
15408
- return super.updateEntity(entity2);
15409
- }
15410
- createMemory(memory, tableName) {
15411
- return super.createMemory(memory, tableName);
15412
- }
15413
- getMemoryById(memoryId) {
15414
- return super.getMemoryById(memoryId);
15415
- }
15416
- updateMemory(memory) {
15417
- return super.updateMemory(memory);
15418
- }
15419
- deleteMemory(memoryId) {
15420
- return super.deleteMemory(memoryId);
15421
- }
15422
- createComponent(component) {
15423
- return super.createComponent(component);
15424
- }
15425
- getComponent(entityId, type, worldId, sourceEntityId) {
15426
- return super.getComponent(entityId, type, worldId, sourceEntityId);
15427
- }
15428
- updateComponent(component) {
15429
- return super.updateComponent(component);
15430
- }
15431
- deleteComponent(componentId) {
15432
- return super.deleteComponent(componentId);
15433
- }
15434
15332
  }
15435
15333
 
15436
15334
  // ../../node_modules/@neondatabase/serverless/index.mjs
@@ -20853,5 +20751,5 @@ export {
20853
20751
  DatabaseMigrationService
20854
20752
  };
20855
20753
 
20856
- //# debugId=E4C1FB1BD2EABD5064756E2164756E21
20754
+ //# debugId=0F9065BB487B8FE864756E2164756E21
20857
20755
  //# sourceMappingURL=index.node.js.map