@elizaos/plugin-sql 2.0.0-alpha.2 → 2.0.0-alpha.20

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.
Files changed (108) hide show
  1. package/dist/base.d.ts +1102 -0
  2. package/dist/browser/index.browser.js +3887 -1999
  3. package/dist/browser/index.browser.js.map +32 -20
  4. package/dist/browser/index.d.ts +2 -2
  5. package/dist/cjs/index.d.ts +2 -0
  6. package/dist/cjs/index.node.cjs +8184 -0
  7. package/dist/cjs/index.node.cjs.map +67 -0
  8. package/dist/index.d.ts +4 -2
  9. package/dist/index.js +2 -0
  10. package/dist/index.node.d.ts +17 -0
  11. package/dist/migration-service.d.ts +17 -0
  12. package/dist/migrations.d.ts +15 -0
  13. package/dist/node/index.d.ts +2 -2
  14. package/dist/node/index.node.js +4411 -8649
  15. package/dist/node/index.node.js.map +34 -117
  16. package/dist/pg/adapter.d.ts +41 -0
  17. package/dist/pg/manager.d.ts +14 -0
  18. package/dist/pglite/adapter.d.ts +23 -0
  19. package/dist/pglite/errors.d.ts +20 -0
  20. package/dist/pglite/manager.d.ts +25 -0
  21. package/dist/rls.d.ts +13 -0
  22. package/dist/runtime-migrator/crypto-utils.d.ts +25 -0
  23. package/dist/runtime-migrator/drizzle-adapters/database-introspector.d.ts +58 -0
  24. package/dist/runtime-migrator/drizzle-adapters/diff-calculator.d.ts +77 -0
  25. package/dist/runtime-migrator/drizzle-adapters/snapshot-generator.d.ts +21 -0
  26. package/dist/runtime-migrator/drizzle-adapters/sql-generator.d.ts +38 -0
  27. package/dist/runtime-migrator/extension-manager.d.ts +6 -0
  28. package/dist/runtime-migrator/index.d.ts +8 -0
  29. package/dist/runtime-migrator/runtime-migrator.d.ts +95 -0
  30. package/dist/runtime-migrator/schema-transformer.d.ts +18 -0
  31. package/dist/runtime-migrator/storage/journal-storage.d.ts +10 -0
  32. package/dist/runtime-migrator/storage/migration-tracker.d.ts +13 -0
  33. package/dist/runtime-migrator/storage/snapshot-storage.d.ts +9 -0
  34. package/dist/runtime-migrator/types.d.ts +157 -0
  35. package/dist/schema/agent.d.ts +344 -0
  36. package/dist/schema/approvalRequests.d.ts +277 -0
  37. package/dist/schema/authAuditEvent.d.ts +153 -0
  38. package/dist/schema/authBootstrapJti.d.ts +49 -0
  39. package/dist/schema/authIdentity.d.ts +121 -0
  40. package/dist/schema/authOwnerBinding.d.ts +168 -0
  41. package/dist/schema/authOwnerLoginToken.d.ts +122 -0
  42. package/dist/schema/authSession.d.ts +225 -0
  43. package/dist/schema/cache.d.ts +97 -0
  44. package/dist/schema/channel.d.ts +177 -0
  45. package/dist/schema/channelParticipant.d.ts +41 -0
  46. package/dist/schema/component.d.ts +163 -0
  47. package/dist/schema/embedding.d.ts +204 -0
  48. package/dist/schema/entity.d.ts +125 -0
  49. package/dist/schema/entityIdentity.d.ts +577 -0
  50. package/dist/schema/index.d.ts +34 -0
  51. package/dist/schema/log.d.ts +114 -0
  52. package/dist/schema/longTermMemories.d.ts +254 -0
  53. package/dist/schema/memory.d.ts +185 -0
  54. package/dist/schema/memoryAccessLogs.d.ts +109 -0
  55. package/dist/schema/message.d.ts +194 -0
  56. package/dist/schema/messageServer.d.ts +126 -0
  57. package/dist/schema/messageServerAgent.d.ts +41 -0
  58. package/dist/schema/pairingAllowlist.d.ts +113 -0
  59. package/dist/schema/pairingRequest.d.ts +147 -0
  60. package/dist/schema/participant.d.ts +114 -0
  61. package/dist/schema/relationship.d.ts +156 -0
  62. package/dist/schema/room.d.ts +195 -0
  63. package/dist/schema/server.d.ts +64 -0
  64. package/dist/schema/sessionSummaries.d.ts +273 -0
  65. package/dist/schema/tasks.d.ts +225 -0
  66. package/dist/schema/types.d.ts +68 -0
  67. package/dist/schema/world.d.ts +114 -0
  68. package/dist/services/advanced-memory-storage.d.ts +36 -0
  69. package/dist/types.d.ts +13 -0
  70. package/dist/utils/string-to-uuid.d.ts +2 -0
  71. package/dist/utils.d.ts +4 -0
  72. package/dist/utils.node.d.ts +4 -0
  73. package/drizzle/index.ts +17 -0
  74. package/package.json +50 -17
  75. package/schema/agent.ts +50 -0
  76. package/schema/approvalRequests.ts +57 -0
  77. package/schema/authAuditEvent.ts +29 -0
  78. package/schema/authBootstrapJti.ts +18 -0
  79. package/schema/authIdentity.ts +35 -0
  80. package/schema/authOwnerBinding.ts +43 -0
  81. package/schema/authOwnerLoginToken.ts +50 -0
  82. package/schema/authSession.ts +44 -0
  83. package/schema/cache.ts +22 -0
  84. package/schema/channel.ts +19 -0
  85. package/schema/channelParticipant.ts +13 -0
  86. package/schema/component.ts +37 -0
  87. package/schema/embedding.ts +73 -0
  88. package/schema/entity.ts +28 -0
  89. package/schema/entityIdentity.ts +142 -0
  90. package/schema/index.ts +41 -0
  91. package/schema/log.ts +38 -0
  92. package/schema/longTermMemories.ts +27 -0
  93. package/schema/memory.ts +103 -0
  94. package/schema/memoryAccessLogs.ts +19 -0
  95. package/schema/message.ts +24 -0
  96. package/schema/messageServer.ts +12 -0
  97. package/schema/messageServerAgent.ts +16 -0
  98. package/schema/pairingAllowlist.ts +36 -0
  99. package/schema/pairingRequest.ts +46 -0
  100. package/schema/participant.ts +43 -0
  101. package/schema/relationship.ts +50 -0
  102. package/schema/room.ts +37 -0
  103. package/schema/server.ts +14 -0
  104. package/schema/sessionSummaries.ts +27 -0
  105. package/schema/tasks.ts +24 -0
  106. package/schema/types.ts +42 -0
  107. package/schema/world.ts +20 -0
  108. package/types.ts +19 -0
@@ -0,0 +1,50 @@
1
+ import { sql } from "drizzle-orm";
2
+ import {
3
+ foreignKey,
4
+ index,
5
+ jsonb,
6
+ pgTable,
7
+ text,
8
+ timestamp,
9
+ unique,
10
+ uuid,
11
+ } from "drizzle-orm/pg-core";
12
+ import { agentTable } from "./agent";
13
+ import { entityTable } from "./entity";
14
+
15
+ /**
16
+ * Defines the relationshipTable containing information about relationships between entities and agents.
17
+ * @type {import('knex').TableBuilder}
18
+ */
19
+ export const relationshipTable = pgTable(
20
+ "relationships",
21
+ {
22
+ id: uuid("id").notNull().primaryKey().default(sql`gen_random_uuid()`),
23
+ createdAt: timestamp("created_at", { withTimezone: true }).default(sql`now()`).notNull(),
24
+ sourceEntityId: uuid("source_entity_id")
25
+ .notNull()
26
+ .references(() => entityTable.id, { onDelete: "cascade" }),
27
+ targetEntityId: uuid("target_entity_id")
28
+ .notNull()
29
+ .references(() => entityTable.id, { onDelete: "cascade" }),
30
+ agentId: uuid("agent_id")
31
+ .notNull()
32
+ .references(() => agentTable.id, { onDelete: "cascade" }),
33
+ tags: text("tags").array(),
34
+ metadata: jsonb("metadata"),
35
+ },
36
+ (table) => [
37
+ index("idx_relationships_users").on(table.sourceEntityId, table.targetEntityId),
38
+ unique("unique_relationship").on(table.sourceEntityId, table.targetEntityId, table.agentId),
39
+ foreignKey({
40
+ name: "fk_user_a",
41
+ columns: [table.sourceEntityId],
42
+ foreignColumns: [entityTable.id],
43
+ }).onDelete("cascade"),
44
+ foreignKey({
45
+ name: "fk_user_b",
46
+ columns: [table.targetEntityId],
47
+ foreignColumns: [entityTable.id],
48
+ }).onDelete("cascade"),
49
+ ]
50
+ );
package/schema/room.ts ADDED
@@ -0,0 +1,37 @@
1
+ import type { Metadata } from "@elizaos/core";
2
+ import { sql } from "drizzle-orm";
3
+ import { jsonb, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
4
+ import { agentTable } from "./agent";
5
+
6
+ /**
7
+ * Defines a table schema for 'rooms' in the database.
8
+ *
9
+ * @typedef {object} RoomTable
10
+ * @property {string} id - The unique identifier for the room.
11
+ * @property {string} agentId - The UUID of the agent associated with the room.
12
+ * @property {string} source - The source of the room.
13
+ * @property {string} type - The type of the room.
14
+ * @property {string} messageServerId - The message server ID of the room.
15
+ * @property {string} worldId - The UUID of the world associated with the room.
16
+ * @property {string} name - The name of the room.
17
+ * @property {object} metadata - Additional metadata for the room in JSON format.
18
+ * @property {string} channelId - The channel ID of the room.
19
+ * @property {number} createdAt - The timestamp of when the room was created.
20
+ */
21
+ export const roomTable = pgTable("rooms", {
22
+ id: uuid("id").notNull().primaryKey().default(sql`gen_random_uuid()`),
23
+ agentId: uuid("agent_id").references(() => agentTable.id, {
24
+ onDelete: "cascade",
25
+ }),
26
+ source: text("source").notNull(),
27
+ type: text("type").notNull(),
28
+ messageServerId: uuid("message_server_id"),
29
+ worldId: uuid("world_id"), // no guarantee that world exists, it is optional for now
30
+ // .references(() => worldTable.id, {
31
+ // onDelete: 'cascade',
32
+ // }),
33
+ name: text("name"),
34
+ metadata: jsonb("metadata").$type<Metadata>(),
35
+ channelId: text("channel_id"),
36
+ createdAt: timestamp("created_at").default(sql`now()`).notNull(),
37
+ });
@@ -0,0 +1,14 @@
1
+ import { sql } from "drizzle-orm";
2
+ import { pgTable, timestamp, uuid } from "drizzle-orm/pg-core";
3
+
4
+ /**
5
+ * Represents a table for storing server data for RLS multi-tenant isolation.
6
+ * Each server represents one elizaOS instance in a multi-tenant deployment.
7
+ *
8
+ * @type {Table}
9
+ */
10
+ export const serverTable = pgTable("servers", {
11
+ id: uuid("id").primaryKey(),
12
+ createdAt: timestamp("created_at", { withTimezone: true }).default(sql`now()`).notNull(),
13
+ updatedAt: timestamp("updated_at", { withTimezone: true }).default(sql`now()`).notNull(),
14
+ });
@@ -0,0 +1,27 @@
1
+ import { sql } from "drizzle-orm";
2
+ import { index, integer, jsonb, pgTable, real, text, timestamp, uuid } from "drizzle-orm/pg-core";
3
+
4
+ export const sessionSummaries = pgTable(
5
+ "session_summaries",
6
+ {
7
+ id: uuid("id").primaryKey().notNull(),
8
+ agentId: uuid("agent_id").notNull(),
9
+ roomId: uuid("room_id").notNull(),
10
+ entityId: uuid("entity_id"),
11
+ summary: text("summary").notNull(),
12
+ messageCount: integer("message_count").notNull(),
13
+ lastMessageOffset: integer("last_message_offset").default(0).notNull(),
14
+ startTime: timestamp("start_time").notNull(),
15
+ endTime: timestamp("end_time").notNull(),
16
+ topics: jsonb("topics").$type<string[]>(),
17
+ metadata: jsonb("metadata"),
18
+ embedding: real("embedding").array(),
19
+ createdAt: timestamp("created_at").default(sql`now()`).notNull(),
20
+ updatedAt: timestamp("updated_at").default(sql`now()`).notNull(),
21
+ },
22
+ (table) => [
23
+ index("session_summaries_agent_room_idx").on(table.agentId, table.roomId),
24
+ index("session_summaries_entity_idx").on(table.entityId),
25
+ index("session_summaries_start_time_idx").on(table.startTime),
26
+ ]
27
+ );
@@ -0,0 +1,24 @@
1
+ import { sql } from "drizzle-orm";
2
+ import { jsonb, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
3
+ import { agentTable } from "./agent";
4
+
5
+ /**
6
+ * Represents a table schema for tasks in the database.
7
+ *
8
+ * @type {PgTable}
9
+ */
10
+ export const taskTable = pgTable("tasks", {
11
+ id: uuid("id").primaryKey().defaultRandom(),
12
+ name: text("name").notNull(),
13
+ description: text("description"),
14
+ roomId: uuid("room_id"),
15
+ worldId: uuid("world_id"),
16
+ entityId: uuid("entity_id"),
17
+ agentId: uuid("agent_id")
18
+ .notNull()
19
+ .references(() => agentTable.id, { onDelete: "cascade" }),
20
+ tags: text("tags").array().default(sql`'{}'::text[]`),
21
+ metadata: jsonb("metadata").default(sql`'{}'::jsonb`),
22
+ createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
23
+ updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
24
+ });
@@ -0,0 +1,42 @@
1
+ import { customType } from "drizzle-orm/pg-core";
2
+
3
+ /**
4
+ * Represents a custom type for converting a string to a JSONB format and vice versa.
5
+ * @param {Object} options - The options for the custom type.
6
+ * @param {Function} options.dataType - A function that returns the data type as "jsonb".
7
+ * @param {Function} options.toDriver - A function that converts a string to a JSON string.
8
+ * @param {Function} options.fromDriver - A function that converts a JSON string back to a string.
9
+ * @returns {Object} - The custom type for string to JSONB conversion.
10
+ */
11
+
12
+ export const stringJsonb = customType<{ data: string; driverData: string }>({
13
+ dataType() {
14
+ return "jsonb";
15
+ },
16
+ toDriver(value: string): string {
17
+ return JSON.stringify(value);
18
+ },
19
+ fromDriver(value: string): string {
20
+ return JSON.stringify(value);
21
+ },
22
+ });
23
+
24
+ /**
25
+ * Represents a custom type for converting a number to a timestamp string and vice versa.
26
+ * @param {Object} options - The options for the custom type.
27
+ * @param {Function} options.dataType - A function that returns the data type as "timestamptz".
28
+ * @param {Function} options.toDriver - A function that converts a number to a timestamp string using the Date object's toISOString method.
29
+ * @param {Function} options.fromDriver - A function that converts a timestamp string to a number using the Date object's getTime method.
30
+ * @returns {Object} - The custom type for number to timestamp conversion.
31
+ */
32
+ export const numberTimestamp = customType<{ data: number; driverData: string }>({
33
+ dataType() {
34
+ return "timestamptz";
35
+ },
36
+ toDriver(value: number): string {
37
+ return new Date(value).toISOString();
38
+ },
39
+ fromDriver(value: string): number {
40
+ return new Date(value).getTime();
41
+ },
42
+ });
@@ -0,0 +1,20 @@
1
+ import { sql } from "drizzle-orm";
2
+ import { jsonb, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
3
+ import { agentTable } from "./agent";
4
+
5
+ /**
6
+ * Represents a table schema for worlds in the database.
7
+ *
8
+ * @type {PgTable}
9
+ */
10
+
11
+ export const worldTable = pgTable("worlds", {
12
+ id: uuid("id").notNull().primaryKey().default(sql`gen_random_uuid()`),
13
+ agentId: uuid("agent_id")
14
+ .notNull()
15
+ .references(() => agentTable.id, { onDelete: "cascade" }),
16
+ name: text("name").notNull(),
17
+ metadata: jsonb("metadata"),
18
+ messageServerId: uuid("message_server_id"),
19
+ createdAt: timestamp("created_at").default(sql`now()`).notNull(),
20
+ });
package/types.ts ADDED
@@ -0,0 +1,19 @@
1
+ import type { IDatabaseAdapter } from "@elizaos/core";
2
+ import type { NodePgDatabase } from "drizzle-orm/node-postgres";
3
+ import type { PgliteDatabase } from "drizzle-orm/pglite";
4
+
5
+ export type DrizzleDatabase = NodePgDatabase | PgliteDatabase;
6
+
7
+ export interface IDatabaseClientManager<T> {
8
+ initialize(): Promise<void>;
9
+ getConnection(): T;
10
+ close(): Promise<void>;
11
+ }
12
+
13
+ export function getDb(adapter: IDatabaseAdapter): DrizzleDatabase {
14
+ return adapter.db as DrizzleDatabase;
15
+ }
16
+
17
+ export function getRow<T>(result: { rows: unknown[] }, index = 0): T | undefined {
18
+ return result.rows[index] as T | undefined;
19
+ }