@elizaos/plugin-sql 1.6.2-alpha.2 → 1.6.2-alpha.21

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.
@@ -18641,7 +18641,7 @@ function formatDefaultValue(value, type) {
18641
18641
  return String(value);
18642
18642
  }
18643
18643
  function generateCreateIndexSQL(index5) {
18644
- const unique4 = index5.isUnique ? "UNIQUE " : "";
18644
+ const unique3 = index5.isUnique ? "UNIQUE " : "";
18645
18645
  const method = index5.method || "btree";
18646
18646
  const columns = index5.columns.map((c) => {
18647
18647
  if (c.isExpression) {
@@ -18657,7 +18657,7 @@ function generateCreateIndexSQL(index5) {
18657
18657
  } else {
18658
18658
  tableRef = `"${index5.table || ""}"`;
18659
18659
  }
18660
- return `CREATE ${unique4}INDEX "${indexName}" ON ${tableRef} USING ${method} (${columns});`;
18660
+ return `CREATE ${unique3}INDEX "${indexName}" ON ${tableRef} USING ${method} (${columns});`;
18661
18661
  }
18662
18662
  function generateDropIndexSQL(index5) {
18663
18663
  const indexName = index5.name ? index5.name.includes(".") ? index5.name.split(".")[1] : index5.name : index5;
@@ -19788,7 +19788,7 @@ import {
19788
19788
 
19789
19789
  // src/schema/agent.ts
19790
19790
  import { sql } from "drizzle-orm";
19791
- import { boolean, jsonb, pgTable, text, timestamp, unique, uuid } from "drizzle-orm/pg-core";
19791
+ import { boolean, jsonb, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
19792
19792
  var agentTable = pgTable("agents", {
19793
19793
  id: uuid("id").primaryKey().defaultRandom(),
19794
19794
  enabled: boolean("enabled").default(true).notNull(),
@@ -19806,15 +19806,11 @@ var agentTable = pgTable("agents", {
19806
19806
  plugins: jsonb("plugins").$type().default(sql`'[]'::jsonb`).notNull(),
19807
19807
  settings: jsonb("settings").$type().default(sql`'{}'::jsonb`).notNull(),
19808
19808
  style: jsonb("style").$type().default(sql`'{}'::jsonb`).notNull()
19809
- }, (table) => {
19810
- return {
19811
- nameUnique: unique("name_unique").on(table.name)
19812
- };
19813
19809
  });
19814
19810
 
19815
19811
  // src/schema/entity.ts
19816
19812
  import { sql as sql2 } from "drizzle-orm";
19817
- import { jsonb as jsonb2, pgTable as pgTable2, text as text2, timestamp as timestamp2, unique as unique2, uuid as uuid2 } from "drizzle-orm/pg-core";
19813
+ import { jsonb as jsonb2, pgTable as pgTable2, text as text2, timestamp as timestamp2, unique, uuid as uuid2 } from "drizzle-orm/pg-core";
19818
19814
  var entityTable = pgTable2("entities", {
19819
19815
  id: uuid2("id").notNull().primaryKey(),
19820
19816
  agentId: uuid2("agent_id").notNull().references(() => agentTable.id, {
@@ -19825,7 +19821,7 @@ var entityTable = pgTable2("entities", {
19825
19821
  metadata: jsonb2("metadata").default(sql2`'{}'::jsonb`).notNull()
19826
19822
  }, (table) => {
19827
19823
  return {
19828
- idAgentIdUnique: unique2("id_agent_id_unique").on(table.id, table.agentId)
19824
+ idAgentIdUnique: unique("id_agent_id_unique").on(table.id, table.agentId)
19829
19825
  };
19830
19826
  });
19831
19827
 
@@ -20058,7 +20054,7 @@ import {
20058
20054
  pgTable as pgTable11,
20059
20055
  text as text10,
20060
20056
  timestamp as timestamp11,
20061
- unique as unique3,
20057
+ unique as unique2,
20062
20058
  uuid as uuid11
20063
20059
  } from "drizzle-orm/pg-core";
20064
20060
  var relationshipTable = pgTable11("relationships", {
@@ -20071,7 +20067,7 @@ var relationshipTable = pgTable11("relationships", {
20071
20067
  metadata: jsonb9("metadata")
20072
20068
  }, (table) => [
20073
20069
  index4("idx_relationships_users").on(table.sourceEntityId, table.targetEntityId),
20074
- unique3("unique_relationship").on(table.sourceEntityId, table.targetEntityId, table.agentId),
20070
+ unique2("unique_relationship").on(table.sourceEntityId, table.targetEntityId, table.agentId),
20075
20071
  foreignKey5({
20076
20072
  name: "fk_user_a",
20077
20073
  columns: [table.sourceEntityId],
@@ -20257,17 +20253,12 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
20257
20253
  async createAgent(agent) {
20258
20254
  return this.withDatabase(async () => {
20259
20255
  try {
20260
- const conditions = [];
20261
20256
  if (agent.id) {
20262
- conditions.push(eq(agentTable.id, agent.id));
20263
- }
20264
- if (agent.name) {
20265
- conditions.push(eq(agentTable.name, agent.name));
20266
- }
20267
- const existing = conditions.length > 0 ? await this.db.select({ id: agentTable.id }).from(agentTable).where(or(...conditions)).limit(1) : [];
20268
- if (existing.length > 0) {
20269
- logger7.warn(`Attempted to create an agent with a duplicate ID or name. ID: ${agent.id}, name: ${agent.name}`);
20270
- return false;
20257
+ const existing = await this.db.select({ id: agentTable.id }).from(agentTable).where(eq(agentTable.id, agent.id)).limit(1);
20258
+ if (existing.length > 0) {
20259
+ logger7.warn(`Attempted to create an agent with a duplicate ID. ID: ${agent.id}`);
20260
+ return false;
20261
+ }
20271
20262
  }
20272
20263
  await this.db.transaction(async (tx) => {
20273
20264
  await tx.insert(agentTable).values({
@@ -20650,9 +20641,12 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
20650
20641
  });
20651
20642
  }
20652
20643
  async getMemories(params) {
20653
- const { entityId, agentId, roomId, worldId, tableName, unique: unique4, start, end } = params;
20644
+ const { entityId, agentId, roomId, worldId, tableName, unique: unique3, start, end, offset } = params;
20654
20645
  if (!tableName)
20655
20646
  throw new Error("tableName is required");
20647
+ if (offset !== undefined && offset < 0) {
20648
+ throw new Error("offset must be a non-negative number");
20649
+ }
20656
20650
  return this.withDatabase(async () => {
20657
20651
  const conditions = [eq(memoryTable.type, tableName)];
20658
20652
  if (start) {
@@ -20670,13 +20664,13 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
20670
20664
  if (end) {
20671
20665
  conditions.push(lte(memoryTable.createdAt, new Date(end)));
20672
20666
  }
20673
- if (unique4) {
20667
+ if (unique3) {
20674
20668
  conditions.push(eq(memoryTable.unique, true));
20675
20669
  }
20676
20670
  if (agentId) {
20677
20671
  conditions.push(eq(memoryTable.agentId, agentId));
20678
20672
  }
20679
- const query = this.db.select({
20673
+ const baseQuery = this.db.select({
20680
20674
  memory: {
20681
20675
  id: memoryTable.id,
20682
20676
  type: memoryTable.type,
@@ -20690,7 +20684,17 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
20690
20684
  },
20691
20685
  embedding: embeddingTable[this.embeddingDimension]
20692
20686
  }).from(memoryTable).leftJoin(embeddingTable, eq(embeddingTable.memoryId, memoryTable.id)).where(and(...conditions)).orderBy(desc(memoryTable.createdAt));
20693
- const rows = params.count ? await query.limit(params.count) : await query;
20687
+ const rows = await (async () => {
20688
+ if (params.count && offset !== undefined && offset > 0) {
20689
+ return baseQuery.limit(params.count).offset(offset);
20690
+ } else if (params.count) {
20691
+ return baseQuery.limit(params.count);
20692
+ } else if (offset !== undefined && offset > 0) {
20693
+ return baseQuery.offset(offset);
20694
+ } else {
20695
+ return baseQuery;
20696
+ }
20697
+ })();
20694
20698
  return rows.map((row) => ({
20695
20699
  id: row.memory.id,
20696
20700
  type: row.memory.type,
@@ -21281,12 +21285,12 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
21281
21285
  logger7.debug(`All memories removed successfully: roomId: ${roomId}, tableName: ${tableName}`);
21282
21286
  });
21283
21287
  }
21284
- async countMemories(roomId, unique4 = true, tableName = "") {
21288
+ async countMemories(roomId, unique3 = true, tableName = "") {
21285
21289
  if (!tableName)
21286
21290
  throw new Error("tableName is required");
21287
21291
  return this.withDatabase(async () => {
21288
21292
  const conditions = [eq(memoryTable.roomId, roomId), eq(memoryTable.type, tableName)];
21289
- if (unique4) {
21293
+ if (unique3) {
21290
21294
  conditions.push(eq(memoryTable.unique, true));
21291
21295
  }
21292
21296
  const result = await this.db.select({ count: sql22`count(*)` }).from(memoryTable).where(and(...conditions));
@@ -22202,5 +22206,5 @@ export {
22202
22206
  DatabaseMigrationService
22203
22207
  };
22204
22208
 
22205
- //# debugId=DC208193344AB9F064756E2164756E21
22209
+ //# debugId=2E7587FF28B8361264756E2164756E21
22206
22210
  //# sourceMappingURL=index.browser.js.map