@elizaos/plugin-sql 2.0.0-beta.1 → 2.0.3-beta.3

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 (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +87 -304
  3. package/package.json +24 -12
  4. package/src/dist/base.d.ts +22 -5
  5. package/src/dist/browser/index.browser.js +4719 -333
  6. package/src/dist/browser/index.browser.js.map +24 -20
  7. package/src/dist/cjs/index.node.cjs +4689 -278
  8. package/src/dist/cjs/index.node.cjs.map +27 -22
  9. package/src/dist/index.d.ts +2 -2
  10. package/src/dist/index.node.d.ts +40 -7
  11. package/src/dist/migration-service.d.ts +2 -2
  12. package/src/dist/node/index.node.js +4638 -225
  13. package/src/dist/node/index.node.js.map +27 -22
  14. package/src/dist/pg/adapter.d.ts +4 -4
  15. package/src/dist/pg/sslmode.d.ts +6 -0
  16. package/src/dist/pglite/adapter.d.ts +44 -5
  17. package/src/dist/pglite/manager.d.ts +185 -4
  18. package/src/dist/runtime-migrator/drizzle-adapters/database-introspector.d.ts +1 -1
  19. package/src/dist/runtime-migrator/drizzle-adapters/diff-calculator.d.ts +1 -1
  20. package/src/dist/runtime-migrator/drizzle-adapters/snapshot-generator.d.ts +1 -1
  21. package/src/dist/runtime-migrator/drizzle-adapters/sql-generator.d.ts +2 -2
  22. package/src/dist/runtime-migrator/extension-manager.d.ts +1 -1
  23. package/src/dist/runtime-migrator/index.d.ts +8 -8
  24. package/src/dist/runtime-migrator/runtime-migrator.d.ts +2 -2
  25. package/src/dist/runtime-migrator/storage/journal-storage.d.ts +1 -1
  26. package/src/dist/runtime-migrator/storage/migration-tracker.d.ts +1 -1
  27. package/src/dist/runtime-migrator/storage/snapshot-storage.d.ts +1 -1
  28. package/src/dist/schema/agent.d.ts +2 -2
  29. package/src/dist/schema/approvalRequests.d.ts +1 -1
  30. package/src/dist/schema/embedding.d.ts +22 -1
  31. package/src/dist/schema/index.d.ts +35 -35
  32. package/src/dist/schema/types.d.ts +2 -2
  33. package/src/dist/stores/connectorAccount.store.d.ts +1 -1
  34. package/src/dist/stores/types.d.ts +2 -2
  35. package/src/dist/write-back/index.d.ts +56 -0
@@ -1,9 +1,9 @@
1
1
  import { type Agent, type Component, type Entity, type Memory, type UUID } from "@elizaos/core";
2
2
  import type { NodePgDatabase } from "drizzle-orm/node-postgres";
3
3
  import type { Pool } from "pg";
4
- import { BaseDrizzleAdapter } from "../base";
5
- import { type EmbeddingDimensionColumn } from "../schema/embedding";
6
- import type { PostgresConnectionManager } from "./manager";
4
+ import { BaseDrizzleAdapter } from "../base.js";
5
+ import { type EmbeddingDimensionColumn } from "../schema/embedding.js";
6
+ import type { PostgresConnectionManager } from "./manager.js";
7
7
  export declare class PgDatabaseAdapter extends BaseDrizzleAdapter {
8
8
  protected embeddingDimension: EmbeddingDimensionColumn;
9
9
  private manager;
@@ -11,7 +11,7 @@ export declare class PgDatabaseAdapter extends BaseDrizzleAdapter {
11
11
  getManager(): PostgresConnectionManager;
12
12
  withEntityContext<T>(entityId: UUID | null, callback: (tx: NodePgDatabase) => Promise<T>): Promise<T>;
13
13
  getEntityByIds(entityIds: UUID[]): Promise<Entity[] | null>;
14
- getMemoriesByServerId(_params: {
14
+ getMemoriesByServerId(params: {
15
15
  serverId: UUID;
16
16
  count?: number;
17
17
  }): Promise<Memory[]>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * pg-connection-string currently treats these sslmode values like verify-full,
3
+ * but warns that its next major version will switch them to libpq semantics.
4
+ * Make the current strict TLS behavior explicit before node-postgres parses it.
5
+ */
6
+ export declare function normalizePgSslMode(connectionString: string): string;
@@ -1,16 +1,16 @@
1
1
  import type { PGlite } from "@electric-sql/pglite";
2
- import { type Agent, type Entity, type Memory, type UUID } from "@elizaos/core";
2
+ import { type Agent, type Entity, type Memory, type MemoryMetadata, type Relationship, type Room, type Task, type UUID, type World } from "@elizaos/core";
3
3
  import { type PgliteDatabase } from "drizzle-orm/pglite";
4
- import { BaseDrizzleAdapter } from "../base";
5
- import { type EmbeddingDimensionColumn } from "../schema/embedding";
6
- import type { PGliteClientManager } from "./manager";
4
+ import { BaseDrizzleAdapter } from "../base.js";
5
+ import { type EmbeddingDimensionColumn } from "../schema/embedding.js";
6
+ import type { PGliteClientManager } from "./manager.js";
7
7
  export declare class PgliteDatabaseAdapter extends BaseDrizzleAdapter {
8
8
  private manager;
9
9
  protected embeddingDimension: EmbeddingDimensionColumn;
10
10
  constructor(agentId: UUID, manager: PGliteClientManager);
11
11
  withEntityContext<T>(_entityId: UUID | null, callback: (tx: PgliteDatabase) => Promise<T>): Promise<T>;
12
12
  getEntityByIds(entityIds: UUID[]): Promise<Entity[] | null>;
13
- getMemoriesByServerId(_params: {
13
+ getMemoriesByServerId(params: {
14
14
  serverId: UUID;
15
15
  count?: number;
16
16
  }): Promise<Memory[]>;
@@ -21,4 +21,43 @@ export declare class PgliteDatabaseAdapter extends BaseDrizzleAdapter {
21
21
  close(): Promise<void>;
22
22
  getConnection(): Promise<PgliteDatabase>;
23
23
  getRawConnection(): PGlite;
24
+ createAgent(agent: Agent): Promise<boolean>;
25
+ updateAgent(agentId: UUID, agent: Partial<Agent>): Promise<boolean>;
26
+ deleteAgent(agentId: UUID): Promise<boolean>;
27
+ deleteAgents(agentIds: UUID[]): Promise<boolean>;
28
+ createEntities(entities: Entity[]): Promise<UUID[]>;
29
+ updateEntity(entity: Entity): Promise<void>;
30
+ deleteEntity(entityId: UUID): Promise<void>;
31
+ createWorld(world: World): Promise<UUID>;
32
+ updateWorld(world: World): Promise<void>;
33
+ removeWorld(id: UUID): Promise<void>;
34
+ createRooms(rooms: Room[]): Promise<UUID[]>;
35
+ updateRoom(room: Room): Promise<void>;
36
+ deleteRoom(roomId: UUID): Promise<void>;
37
+ addParticipant(entityId: UUID, roomId: UUID): Promise<boolean>;
38
+ removeParticipant(entityId: UUID, roomId: UUID): Promise<boolean>;
39
+ createMemory(memory: Memory & {
40
+ metadata?: MemoryMetadata;
41
+ }, tableName: string): Promise<UUID>;
42
+ updateMemory(memory: Partial<Memory> & {
43
+ id: UUID;
44
+ metadata?: MemoryMetadata;
45
+ }): Promise<boolean>;
46
+ deleteMemory(memoryId: UUID): Promise<void>;
47
+ deleteManyMemories(memoryIds: UUID[]): Promise<void>;
48
+ deleteAllMemories(roomIds: UUID[], tableName: string): Promise<void>;
49
+ deleteAllMemories(roomId: UUID, tableName: string): Promise<void>;
50
+ createRelationship(params: {
51
+ sourceEntityId: UUID;
52
+ targetEntityId: UUID;
53
+ tags?: string[];
54
+ metadata?: {
55
+ [key: string]: unknown;
56
+ };
57
+ }): Promise<boolean>;
58
+ updateRelationship(relationship: Relationship): Promise<void>;
59
+ deleteRelationships(relationshipIds: UUID[]): Promise<void>;
60
+ createTask(task: Task): Promise<UUID>;
61
+ updateTask(id: UUID, task: Partial<Task>): Promise<void>;
62
+ deleteTask(id: UUID): Promise<void>;
24
63
  }
@@ -1,6 +1,60 @@
1
1
  import { PGlite, type PGliteOptions } from "@electric-sql/pglite";
2
- import type { IDatabaseClientManager } from "../types";
2
+ import type { IDatabaseClientManager } from "../types.js";
3
+ import { WriteBackService } from "../write-back/index.js";
4
+ /**
5
+ * Canonical list of table names synced via Electric and tracked by the
6
+ * write-back service. Used by both syncShapesToTables (read path) and
7
+ * PgliteDatabaseAdapter (write path) so the two stay in sync.
8
+ */
9
+ export declare const SYNCED_TABLE_NAMES: readonly ["agents", "entities", "worlds", "rooms", "participants", "memories", "relationships", "tasks"];
10
+ /**
11
+ * Runtime sync status of the Electric Sync client wired into PGlite.
12
+ * - syncing: the sync stream is connecting or catching up with the source.
13
+ * - synced: the local PGlite is up-to-date with the Electric source.
14
+ * - error: the sync stream encountered a non-recoverable error.
15
+ * - disabled: no ELIZA_ELECTRIC_SYNC_URL was configured at boot.
16
+ */
17
+ export type PgliteSyncStatus = "syncing" | "synced" | "error" | "disabled";
18
+ /** Per-table sync state. */
19
+ export type PgliteSyncTableState = "pending" | "synced" | "error";
20
+ /** Per-table status map exposed by getSyncStatus(). */
21
+ export type PgliteSyncTableStatus = Record<string, {
22
+ state: PgliteSyncTableState;
23
+ error?: string;
24
+ }>;
25
+ /**
26
+ * Result row type for live queries. Matches the shape returned by
27
+ * {@link https://pglite.dev/docs/live-queries | pg.live.query()}.
28
+ */
29
+ export interface LiveQueryResult<T = Record<string, unknown>> {
30
+ rows: T[];
31
+ fields: {
32
+ name: string;
33
+ dataTypeID: number;
34
+ }[];
35
+ affectedRows?: number;
36
+ }
37
+ /**
38
+ * Return value from {@link https://pglite.dev/docs/live-queries | pg.live.query()}.
39
+ */
40
+ export interface LiveQueryReturn<T = Record<string, unknown>> {
41
+ initialResults: LiveQueryResult<T>;
42
+ unsubscribe: () => Promise<void>;
43
+ refresh: (options?: {
44
+ offset?: number;
45
+ limit?: number;
46
+ }) => Promise<void>;
47
+ }
48
+ /**
49
+ * The `pg.live` namespace added by the `@electric-sql/pglite/live` extension.
50
+ */
51
+ export interface LiveNamespace {
52
+ query<T = Record<string, unknown>>(sql: string, params: unknown[] | undefined, callback: (result: LiveQueryResult<T>) => void): Promise<LiveQueryReturn<T>>;
53
+ incrementalQuery<T = Record<string, unknown>>(sql: string, params: unknown[] | undefined, key: string, callback: (result: LiveQueryResult<T>) => void): Promise<LiveQueryReturn<T>>;
54
+ changes<T = Record<string, unknown>>(sql: string, params: unknown[] | undefined, key: string, callback: (changes: unknown[]) => void): Promise<LiveQueryReturn<T>>;
55
+ }
3
56
  export declare class PGliteClientManager implements IDatabaseClientManager<PGlite> {
57
+ private static readonly LOCK_STALE_MS;
4
58
  private client;
5
59
  private options;
6
60
  private shuttingDown;
@@ -8,8 +62,50 @@ export declare class PGliteClientManager implements IDatabaseClientManager<PGlit
8
62
  private initializePromise;
9
63
  private lockFd;
10
64
  private lockPath;
11
- constructor(options: PGliteOptions);
65
+ private syncUrl;
66
+ private agentId;
67
+ private syncStatus;
68
+ private syncError;
69
+ private syncUnsubscribe;
70
+ private syncTableStates;
71
+ private syncedTables;
72
+ private startSyncMutex;
73
+ private forceResyncMutex;
74
+ private writeBack;
75
+ constructor(options: PGliteOptions & {
76
+ syncUrl?: string;
77
+ agentId?: string;
78
+ writeBackBaseUrl?: string;
79
+ serviceKey?: string;
80
+ });
12
81
  getConnection(): PGlite;
82
+ /**
83
+ * Access the write-back service for forwarding local writes to the
84
+ * cloud API. Returns null when write-back is not configured.
85
+ */
86
+ getWriteBack(): WriteBackService | null;
87
+ /**
88
+ * Notify the write-back service of a local write to a sync table.
89
+ * Called by the adapter after a successful write operation.
90
+ * No-op when write-back is not configured.
91
+ */
92
+ notifyWrite(table: string, operation: "insert" | "upsert" | "delete", row: Record<string, unknown>): void;
93
+ /**
94
+ * Current Electric Sync status.
95
+ * - "disabled": no ELIZA_ELECTRIC_SYNC_URL was configured.
96
+ * - "syncing": sync client is connecting or catching up.
97
+ * - "synced": local PGlite is up-to-date with the Electric source.
98
+ * - "error": sync encountered an error (see syncError).
99
+ *
100
+ * Also returns per-table state so operators can see which specific
101
+ * tables are healthy vs errored vs still pending.
102
+ */
103
+ getSyncStatus(): {
104
+ status: PgliteSyncStatus;
105
+ error: string | null;
106
+ tables: PgliteSyncTableStatus;
107
+ synced: string[];
108
+ };
13
109
  isShuttingDown(): boolean;
14
110
  isInitialized(): boolean;
15
111
  initialize(): Promise<void>;
@@ -19,8 +115,28 @@ export declare class PGliteClientManager implements IDatabaseClientManager<PGlit
19
115
  private getDataDir;
20
116
  private isFileBackedDataDir;
21
117
  private getDataDirLockPath;
22
- private getLockPid;
23
- private isPidRunning;
118
+ private getLockInfo;
119
+ /**
120
+ * Decide whether an existing lock should be honored as held by a live owner.
121
+ *
122
+ * Single-writer safety comes first: a *confirmed-running* PID is always
123
+ * honored, regardless of how old its `createdAt` is. A long-running agent
124
+ * (days or weeks of uptime) must never have its live lock reclaimed by a
125
+ * second manager — that would open a dual-writer window, which is
126
+ * unrecoverable, whereas a falsely-bricked boot is recoverable by removing
127
+ * the lock file. This matches the sibling `reconcilePglitePidFile`, which
128
+ * also treats a live PID as "active".
129
+ *
130
+ * The staleness window only rescues the *unconfirmable* case. A bare
131
+ * `process.kill(pid, 0)` is vulnerable to PID reuse, and a recycled
132
+ * cross-user PID surfaces as `EPERM` (or another non-`ESRCH` error) rather
133
+ * than a clean success. For those we cannot prove the PID belongs to a live
134
+ * Eliza process, so we fall back to `createdAt`: a recent lock is still
135
+ * respected, but one older than `LOCK_STALE_MS` (or with no usable timestamp)
136
+ * is treated as stale and reclaimed so an aliased PID cannot brick boot
137
+ * forever. `ESRCH` is unambiguous — the process is gone and the lock is stale.
138
+ */
139
+ private isLockActive;
24
140
  private acquireDataDirLockIfNeeded;
25
141
  private releaseDataDirLock;
26
142
  private getErrorText;
@@ -28,5 +144,70 @@ export declare class PGliteClientManager implements IDatabaseClientManager<PGlit
28
144
  private createActiveLockError;
29
145
  private createManualResetRequiredError;
30
146
  private queryMigrationsSchema;
147
+ /**
148
+ * Ensure the Electric Sync stream is started. Idempotent — safe to call
149
+ * on every database operation. The first call after PGlite is initialized
150
+ * and after migrations have created the target tables will start the sync
151
+ * stream; subsequent calls are no-ops.
152
+ *
153
+ * This is deliberately separate from {@link initialize} because the Drizzle
154
+ * migrations that create the target tables run AFTER plugin init completes.
155
+ * Starting sync during init would try to insert into non-existent tables.
156
+ */
157
+ ensureSync(): Promise<void>;
158
+ /**
159
+ * Access the PGlite live query namespace for reactive queries that
160
+ * push updated results whenever the underlying tables change. Useful
161
+ * for dashboard health endpoints and real-time monitoring.
162
+ *
163
+ * Returns the {@link https://pglite.dev/docs/live-queries | pg.live}
164
+ * namespace, which provides:
165
+ * - `live.query(sql, params, callback)` — simple live query
166
+ * - `live.incrementalQuery(sql, params, key, callback)` — diff-based
167
+ * - `live.changes(sql, params, key, callback)` — raw change stream
168
+ *
169
+ * Returns null when PGlite extensions are disabled.
170
+ */
171
+ liveQuery(): LiveNamespace | null;
172
+ /**
173
+ * Force-reset the Electric Sync stream: unsubscribe, drop all internal
174
+ * sync state from the `electric` schema, and restart from scratch.
175
+ *
176
+ * Use this when operators diagnose a split-brain scenario (local PGlite
177
+ * has diverged from the source Postgres) or when the sync stream is
178
+ * stuck in an unrecoverable error state. The local data in the synced
179
+ * tables is preserved — only the Electric metadata tables are dropped,
180
+ * forcing a full re-sync that reconstructs state from the source.
181
+ *
182
+ * Returns the sync status after the reset. When sync is not configured
183
+ * (no ELIZA_ELECTRIC_SYNC_URL), returns null.
184
+ */
185
+ forceResync(): Promise<{
186
+ status: PgliteSyncStatus;
187
+ error: string | null;
188
+ tables: PgliteSyncTableStatus;
189
+ synced: string[];
190
+ } | null>;
191
+ private forceResyncInternal;
192
+ /**
193
+ * Start the Electric Sync stream after PGlite is initialized.
194
+ * Uses the official multi-table {@link https://pglite.dev/docs/sync#multi-table-sync | syncShapesToTables}
195
+ * API so all shape updates that happened in a single Postgres transaction
196
+ * are applied in a single PGlite transaction, preserving consistency
197
+ * across all runtime tables.
198
+ *
199
+ * Each shape is filtered by agent_id so that in a shared-Neon deployment
200
+ * an agent only syncs its own data — preserving per-agent physical isolation
201
+ * even though the source Postgres is multi-tenant.
202
+ *
203
+ * Sync failures are non-fatal: the agent runs on its local PGlite
204
+ * regardless of sync health. Per-table error state is tracked so
205
+ * operators can diagnose individual table issues without assuming
206
+ * the entire sync is broken.
207
+ */
208
+ private startSync;
209
+ /** Internal body of startSync, extracted so the mutex wraps only the
210
+ * syncShapesToTables call, not the early-return guards. */
211
+ private startSyncInternal;
31
212
  private initializeInternal;
32
213
  }
@@ -1,4 +1,4 @@
1
- import type { DrizzleDB, SchemaSnapshot } from "../types";
1
+ import type { DrizzleDB, SchemaSnapshot } from "../types.js";
2
2
  /**
3
3
  * Introspect the current database state and generate a snapshot
4
4
  * This is used when no previous snapshot exists for a plugin
@@ -1,4 +1,4 @@
1
- import type { SchemaCheckConstraint, SchemaColumn, SchemaForeignKey, SchemaIndex, SchemaSnapshot, SchemaUniqueConstraint } from "../types";
1
+ import type { SchemaCheckConstraint, SchemaColumn, SchemaForeignKey, SchemaIndex, SchemaSnapshot, SchemaUniqueConstraint } from "../types.js";
2
2
  export interface ColumnChanges {
3
3
  typeChanged?: boolean;
4
4
  prevType?: string;
@@ -1,4 +1,4 @@
1
- import type { SchemaSnapshot } from "../types";
1
+ import type { SchemaSnapshot } from "../types.js";
2
2
  type DrizzleSchema = Record<string, unknown>;
3
3
  /**
4
4
  * Generate a snapshot from a Drizzle schema
@@ -1,5 +1,5 @@
1
- import type { SchemaSnapshot } from "../types";
2
- import type { SchemaDiff } from "./diff-calculator";
1
+ import type { SchemaSnapshot } from "../types.js";
2
+ import type { SchemaDiff } from "./diff-calculator.js";
3
3
  /**
4
4
  * Data loss detection result
5
5
  * Based on Drizzle's pgPushUtils approach
@@ -1,4 +1,4 @@
1
- import type { DrizzleDB } from "./types";
1
+ import type { DrizzleDB } from "./types.js";
2
2
  export declare class ExtensionManager {
3
3
  private db;
4
4
  constructor(db: DrizzleDB);
@@ -1,8 +1,8 @@
1
- export { calculateDiff, hasDiffChanges, type SchemaDiff, } from "./drizzle-adapters/diff-calculator";
2
- export { createEmptySnapshot, generateSnapshot, hasChanges, hashSnapshot, } from "./drizzle-adapters/snapshot-generator";
3
- export { generateMigrationSQL, generateRenameColumnSQL, generateRenameTableSQL, } from "./drizzle-adapters/sql-generator";
4
- export { RuntimeMigrator } from "./runtime-migrator";
5
- export { JournalStorage } from "./storage/journal-storage";
6
- export { MigrationTracker } from "./storage/migration-tracker";
7
- export { SnapshotStorage } from "./storage/snapshot-storage";
8
- export * from "./types";
1
+ export { calculateDiff, hasDiffChanges, type SchemaDiff, } from "./drizzle-adapters/diff-calculator.js";
2
+ export { createEmptySnapshot, generateSnapshot, hasChanges, hashSnapshot, } from "./drizzle-adapters/snapshot-generator.js";
3
+ export { generateMigrationSQL, generateRenameColumnSQL, generateRenameTableSQL, } from "./drizzle-adapters/sql-generator.js";
4
+ export { RuntimeMigrator } from "./runtime-migrator.js";
5
+ export { JournalStorage } from "./storage/journal-storage.js";
6
+ export { MigrationTracker } from "./storage/migration-tracker.js";
7
+ export { SnapshotStorage } from "./storage/snapshot-storage.js";
8
+ export * from "./types.js";
@@ -1,5 +1,5 @@
1
- import { type DataLossCheck } from "./drizzle-adapters/sql-generator";
2
- import type { DrizzleDB, RuntimeMigrationOptions } from "./types";
1
+ import { type DataLossCheck } from "./drizzle-adapters/sql-generator.js";
2
+ import type { DrizzleDB, RuntimeMigrationOptions } from "./types.js";
3
3
  export declare class RuntimeMigrator {
4
4
  private db;
5
5
  private migrationTracker;
@@ -1,4 +1,4 @@
1
- import type { DrizzleDB, Journal, JournalEntry } from "../types";
1
+ import type { DrizzleDB, Journal, JournalEntry } from "../types.js";
2
2
  export declare class JournalStorage {
3
3
  private db;
4
4
  constructor(db: DrizzleDB);
@@ -1,4 +1,4 @@
1
- import type { DrizzleDB } from "../types";
1
+ import type { DrizzleDB } from "../types.js";
2
2
  export declare class MigrationTracker {
3
3
  private db;
4
4
  constructor(db: DrizzleDB);
@@ -1,4 +1,4 @@
1
- import type { DrizzleDB, SchemaSnapshot } from "../types";
1
+ import type { DrizzleDB, SchemaSnapshot } from "../types.js";
2
2
  export declare class SnapshotStorage {
3
3
  private db;
4
4
  constructor(db: DrizzleDB);
@@ -289,7 +289,7 @@ export declare const agentTable: import("drizzle-orm/pg-core").PgTableWithColumn
289
289
  dataType: "json";
290
290
  columnType: "PgJsonb";
291
291
  data: {
292
- [key: string]: string | number | boolean | Record<string, unknown>;
292
+ [key: string]: string | number | boolean | Record<string, unknown> | undefined;
293
293
  secrets?: {
294
294
  [key: string]: string | boolean | number;
295
295
  };
@@ -306,7 +306,7 @@ export declare const agentTable: import("drizzle-orm/pg-core").PgTableWithColumn
306
306
  generated: undefined;
307
307
  }, {}, {
308
308
  $type: {
309
- [key: string]: string | number | boolean | Record<string, unknown>;
309
+ [key: string]: string | number | boolean | Record<string, unknown> | undefined;
310
310
  secrets?: {
311
311
  [key: string]: string | boolean | number;
312
312
  };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Persistent backing store for the LifeOps human-in-the-loop approval queue.
3
3
  *
4
- * Owned by `plugins/app-lifeops` (see `src/lifeops/approval-queue.types.ts`),
4
+ * Owned by `plugins/plugin-personal-assistant` (see `src/lifeops/approval-queue.types.ts`),
5
5
  * but lives in plugin-sql so the runtime migrator picks it up automatically
6
6
  * for both PostgreSQL and PGlite deployments.
7
7
  *
@@ -4,6 +4,7 @@ export declare const VECTOR_DIMS: {
4
4
  readonly LARGE: 768;
5
5
  readonly XL: 1024;
6
6
  readonly XXL: 1536;
7
+ readonly XXL2: 2048;
7
8
  readonly XXXL: 3072;
8
9
  };
9
10
  export declare const DIMENSION_MAP: {
@@ -12,6 +13,7 @@ export declare const DIMENSION_MAP: {
12
13
  readonly 768: "dim768";
13
14
  readonly 1024: "dim1024";
14
15
  readonly 1536: "dim1536";
16
+ readonly 2048: "dim2048";
15
17
  readonly 3072: "dim3072";
16
18
  };
17
19
  /**
@@ -168,6 +170,25 @@ export declare const embeddingTable: import("drizzle-orm/pg-core").PgTableWithCo
168
170
  }, {}, {
169
171
  dimensions: 1536;
170
172
  }>;
173
+ dim2048: import("drizzle-orm/pg-core").PgColumn<{
174
+ name: "dim_2048";
175
+ tableName: "embeddings";
176
+ dataType: "array";
177
+ columnType: "PgVector";
178
+ data: number[];
179
+ driverParam: string;
180
+ notNull: false;
181
+ hasDefault: false;
182
+ isPrimaryKey: false;
183
+ isAutoincrement: false;
184
+ hasRuntimeDefault: false;
185
+ enumValues: undefined;
186
+ baseColumn: never;
187
+ identity: undefined;
188
+ generated: undefined;
189
+ }, {}, {
190
+ dimensions: 2048;
191
+ }>;
171
192
  dim3072: import("drizzle-orm/pg-core").PgColumn<{
172
193
  name: "dim_3072";
173
194
  tableName: "embeddings";
@@ -194,7 +215,7 @@ export declare const embeddingTable: import("drizzle-orm/pg-core").PgTableWithCo
194
215
  * Defines the possible values for the Embedding Dimension Column.
195
216
  * It can be "dim384", "dim512", "dim768", "dim1024", "dim1536", or "dim3072".
196
217
  */
197
- export type EmbeddingDimensionColumn = "dim384" | "dim512" | "dim768" | "dim1024" | "dim1536" | "dim3072";
218
+ export type EmbeddingDimensionColumn = "dim384" | "dim512" | "dim768" | "dim1024" | "dim1536" | "dim2048" | "dim3072";
198
219
  /**
199
220
  * Retrieve the type of a specific column in the EmbeddingTable based on the EmbeddingDimensionColumn key.
200
221
  */
@@ -1,35 +1,35 @@
1
- export { agentTable } from "./agent";
2
- export { approvalRequestTable } from "./approvalRequests";
3
- export type { AuthAuditOutcome } from "./authAuditEvent";
4
- export { authAuditEventTable } from "./authAuditEvent";
5
- export { authBootstrapJtiSeenTable } from "./authBootstrapJti";
6
- export type { AuthIdentityKind } from "./authIdentity";
7
- export { authIdentityCreatedAtDefault, authIdentityTable, } from "./authIdentity";
8
- export { authOwnerBindingTable } from "./authOwnerBinding";
9
- export { authOwnerLoginTokenTable } from "./authOwnerLoginToken";
10
- export type { AuthSessionKind } from "./authSession";
11
- export { authSessionTable } from "./authSession";
12
- export { cacheTable } from "./cache";
13
- export { channelTable } from "./channel";
14
- export { channelParticipantsTable } from "./channelParticipant";
15
- export { componentTable } from "./component";
16
- export { connectorAccountAuditEventsTable, connectorAccountCredentialsTable, connectorAccountsTable, oauthFlowsTable, } from "./connectorAccounts";
17
- export { embeddingTable } from "./embedding";
18
- export { entityTable } from "./entity";
19
- export { entityIdentityTable, entityMergeCandidateTable, factCandidateTable, } from "./entityIdentity";
20
- export { logTable } from "./log";
21
- export { longTermMemories } from "./longTermMemories";
22
- export { memoryTable } from "./memory";
23
- export { memoryAccessLogs } from "./memoryAccessLogs";
24
- export { messageTable } from "./message";
25
- export { messageServerTable } from "./messageServer";
26
- export { messageServerAgentsTable } from "./messageServerAgent";
27
- export { pairingAllowlistTable } from "./pairingAllowlist";
28
- export { pairingRequestTable } from "./pairingRequest";
29
- export { participantTable } from "./participant";
30
- export { relationshipTable } from "./relationship";
31
- export { roomTable } from "./room";
32
- export { serverTable } from "./server";
33
- export { sessionSummaries } from "./sessionSummaries";
34
- export { taskTable } from "./tasks";
35
- export { worldTable } from "./world";
1
+ export { agentTable } from "./agent.js";
2
+ export { approvalRequestTable } from "./approvalRequests.js";
3
+ export type { AuthAuditOutcome } from "./authAuditEvent.js";
4
+ export { authAuditEventTable } from "./authAuditEvent.js";
5
+ export { authBootstrapJtiSeenTable } from "./authBootstrapJti.js";
6
+ export type { AuthIdentityKind } from "./authIdentity.js";
7
+ export { authIdentityCreatedAtDefault, authIdentityTable, } from "./authIdentity.js";
8
+ export { authOwnerBindingTable } from "./authOwnerBinding.js";
9
+ export { authOwnerLoginTokenTable } from "./authOwnerLoginToken.js";
10
+ export type { AuthSessionKind } from "./authSession.js";
11
+ export { authSessionTable } from "./authSession.js";
12
+ export { cacheTable } from "./cache.js";
13
+ export { channelTable } from "./channel.js";
14
+ export { channelParticipantsTable } from "./channelParticipant.js";
15
+ export { componentTable } from "./component.js";
16
+ export { connectorAccountAuditEventsTable, connectorAccountCredentialsTable, connectorAccountsTable, oauthFlowsTable, } from "./connectorAccounts.js";
17
+ export { embeddingTable } from "./embedding.js";
18
+ export { entityTable } from "./entity.js";
19
+ export { entityIdentityTable, entityMergeCandidateTable, factCandidateTable, } from "./entityIdentity.js";
20
+ export { logTable } from "./log.js";
21
+ export { longTermMemories } from "./longTermMemories.js";
22
+ export { memoryTable } from "./memory.js";
23
+ export { memoryAccessLogs } from "./memoryAccessLogs.js";
24
+ export { messageTable } from "./message.js";
25
+ export { messageServerTable } from "./messageServer.js";
26
+ export { messageServerAgentsTable } from "./messageServerAgent.js";
27
+ export { pairingAllowlistTable } from "./pairingAllowlist.js";
28
+ export { pairingRequestTable } from "./pairingRequest.js";
29
+ export { participantTable } from "./participant.js";
30
+ export { relationshipTable } from "./relationship.js";
31
+ export { roomTable } from "./room.js";
32
+ export { serverTable } from "./server.js";
33
+ export { sessionSummaries } from "./sessionSummaries.js";
34
+ export { taskTable } from "./tasks.js";
35
+ export { worldTable } from "./world.js";
@@ -15,7 +15,7 @@ export declare const stringJsonb: {
15
15
  driverParam: string;
16
16
  enumValues: undefined;
17
17
  }>;
18
- <TConfig extends Record<string, any>>(fieldConfig?: TConfig): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
18
+ <TConfig extends Record<string, any>>(fieldConfig?: TConfig | undefined): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
19
19
  name: "";
20
20
  dataType: "custom";
21
21
  columnType: "PgCustomColumn";
@@ -49,7 +49,7 @@ export declare const numberTimestamp: {
49
49
  driverParam: string;
50
50
  enumValues: undefined;
51
51
  }>;
52
- <TConfig extends Record<string, any>>(fieldConfig?: TConfig): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
52
+ <TConfig extends Record<string, any>>(fieldConfig?: TConfig | undefined): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
53
53
  name: "";
54
54
  dataType: "custom";
55
55
  columnType: "PgCustomColumn";
@@ -1,5 +1,5 @@
1
1
  import type { AppendConnectorAccountAuditEventParams, ConnectorAccountAuditEventRecord, ConnectorAccountCredentialRefRecord, ConnectorAccountJsonObject, ConnectorAccountRecord, ConnectorOwnerBindingLookup, ConnectorOwnerBindingRecord, ConsumeOAuthFlowStateParams, CreateOAuthFlowStateParams, DeleteConnectorAccountParams, GetConnectorAccountCredentialRefParams, GetConnectorAccountParams, ListConnectorAccountCredentialRefsParams, ListConnectorAccountsParams, OAuthFlowRecord, SetConnectorAccountCredentialRefParams, UpsertConnectorAccountParams } from "@elizaos/core";
2
- import type { Store, StoreContext } from "./types";
2
+ import type { Store, StoreContext } from "./types.js";
3
3
  interface GetOAuthFlowStateParams {
4
4
  state?: string;
5
5
  stateHash?: string;
@@ -1,6 +1,6 @@
1
1
  import type { UUID } from "@elizaos/core";
2
- import type { EmbeddingDimensionColumn } from "../schema/embedding";
3
- import type { DrizzleDatabase } from "../types";
2
+ import type { EmbeddingDimensionColumn } from "../schema/embedding.js";
3
+ import type { DrizzleDatabase } from "../types.js";
4
4
  /**
5
5
  * Context passed to all stores for database operations.
6
6
  * Stores don't manage connections - they receive a context from the adapter.
@@ -0,0 +1,56 @@
1
+ /**
2
+ * WriteBackService — implements Electric's Pattern 1 (Online Writes).
3
+ *
4
+ * When an agent writes to its local PGlite, this service asynchronously
5
+ * forwards the write to the cloud API, which inserts it into the central
6
+ * Postgres. Electric then syncs the confirmed row back to PGlite via the
7
+ * existing syncShapesToTables read path, completing the round-trip.
8
+ *
9
+ * Writes are fire-and-forget — the agent never blocks on the HTTP POST.
10
+ * A small in-memory queue batches writes that arrive while a flush is
11
+ * in-flight, avoiding duplicate concurrent POSTs. Writes that fail are
12
+ * retried up to MAX_RETRIES times, then dropped with a warning log.
13
+ *
14
+ * Configured via:
15
+ * ELIZA_CLOUD_WRITE_BASE_URL — base URL of the cloud API, e.g.
16
+ * https://api.elizacloud.ai. The agentId is appended at runtime:
17
+ * {base}/api/v1/eliza/agents/{agentId}/write
18
+ * ELIZA_CLOUD_SERVICE_KEY — X-Service-Key value (WAIFU_SERVICE_KEY)
19
+ *
20
+ * If neither env var is set, the service is a no-op.
21
+ */
22
+ export interface WriteBackOptions {
23
+ /** Base URL of the cloud API. AgentId is appended at runtime. */
24
+ writeBaseUrl?: string | null;
25
+ /** Agent UUID for constructing the write endpoint URL. */
26
+ agentId?: string | null;
27
+ /** X-Service-Key value for authentication. */
28
+ serviceKey?: string | null;
29
+ }
30
+ export declare class WriteBackService {
31
+ private writeUrl;
32
+ private serviceKey;
33
+ private queue;
34
+ private flushing;
35
+ private flushTimer;
36
+ /** Incrementing counter ensures unique writeIds even without crypto. */
37
+ private writeCounter;
38
+ constructor(opts?: WriteBackOptions);
39
+ /** Whether the service is configured and active. */
40
+ get enabled(): boolean;
41
+ /**
42
+ * Enqueue a write to be forwarded to the cloud API.
43
+ * Returns immediately; the write is flushed asynchronously.
44
+ */
45
+ enqueue(table: string, operation: "insert" | "upsert" | "delete", row: Record<string, unknown>): void;
46
+ /**
47
+ * Flush all pending writes synchronously. Waits for any in-progress
48
+ * drain to complete, then picks up any remaining items.
49
+ * Used during shutdown to drain the queue before the agent exits.
50
+ */
51
+ flush(): Promise<void>;
52
+ private scheduleFlush;
53
+ private drainQueue;
54
+ private sendBatch;
55
+ private requeueOrDrop;
56
+ }