@elizaos/plugin-localdb 2.0.3-beta.6 → 2.0.3-beta.7

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.
@@ -0,0 +1,7 @@
1
+ import { UUID, Plugin } from '@elizaos/core';
2
+ import { InMemoryDatabaseAdapter } from '@elizaos/plugin-inmemorydb';
3
+
4
+ declare function createDatabaseAdapter(agentId: UUID): InMemoryDatabaseAdapter;
5
+ declare const plugin: Plugin;
6
+
7
+ export { createDatabaseAdapter, plugin as default, plugin };
@@ -0,0 +1,113 @@
1
+ // index.browser.ts
2
+ import {
3
+ InMemoryDatabaseAdapter
4
+ } from "@elizaos/plugin-inmemorydb";
5
+ var BrowserLocalStorage = class {
6
+ constructor(key) {
7
+ this.key = key;
8
+ }
9
+ key;
10
+ collections = /* @__PURE__ */ new Map();
11
+ ready = false;
12
+ async init() {
13
+ const raw = globalThis.localStorage.getItem(this.key);
14
+ if (raw) {
15
+ const parsed = JSON.parse(raw);
16
+ for (const [collection, entries] of Object.entries(parsed)) {
17
+ this.collections.set(collection, new Map(Object.entries(entries)));
18
+ }
19
+ }
20
+ this.ready = true;
21
+ }
22
+ async close() {
23
+ await this.flush();
24
+ this.ready = false;
25
+ }
26
+ async isReady() {
27
+ return this.ready;
28
+ }
29
+ getCollection(collection) {
30
+ let current = this.collections.get(collection);
31
+ if (!current) {
32
+ current = /* @__PURE__ */ new Map();
33
+ this.collections.set(collection, current);
34
+ }
35
+ return current;
36
+ }
37
+ async flush() {
38
+ const out = {};
39
+ for (const [collection, entries] of this.collections) {
40
+ out[collection] = Object.fromEntries(entries);
41
+ }
42
+ globalThis.localStorage.setItem(this.key, JSON.stringify(out));
43
+ }
44
+ async get(collection, id) {
45
+ const item = this.getCollection(collection).get(id);
46
+ return item === void 0 ? null : item;
47
+ }
48
+ async getAll(collection) {
49
+ return Array.from(this.getCollection(collection).values());
50
+ }
51
+ async getWhere(collection, predicate) {
52
+ return (await this.getAll(collection)).filter(predicate);
53
+ }
54
+ async set(collection, id, data) {
55
+ this.getCollection(collection).set(id, data);
56
+ await this.flush();
57
+ }
58
+ async delete(collection, id) {
59
+ const deleted = this.getCollection(collection).delete(id);
60
+ if (deleted) await this.flush();
61
+ return deleted;
62
+ }
63
+ async deleteMany(collection, ids) {
64
+ const current = this.getCollection(collection);
65
+ for (const id of ids) current.delete(id);
66
+ await this.flush();
67
+ }
68
+ async deleteWhere(collection, predicate) {
69
+ const current = this.getCollection(collection);
70
+ for (const [id, item] of current) {
71
+ if (predicate(item)) current.delete(id);
72
+ }
73
+ await this.flush();
74
+ }
75
+ async count(collection, predicate) {
76
+ const current = this.getCollection(collection);
77
+ if (!predicate) return current.size;
78
+ let total = 0;
79
+ for (const item of current.values()) {
80
+ if (predicate(item)) total++;
81
+ }
82
+ return total;
83
+ }
84
+ async clear() {
85
+ this.collections.clear();
86
+ await this.flush();
87
+ }
88
+ };
89
+ function createDatabaseAdapter(agentId) {
90
+ return new InMemoryDatabaseAdapter(
91
+ new BrowserLocalStorage(`elizaos:localdb:${agentId}`),
92
+ agentId
93
+ );
94
+ }
95
+ var plugin = {
96
+ name: "@elizaos/plugin-localdb",
97
+ description: "Browser localStorage database storage for elizaOS examples.",
98
+ async init(_config, runtime) {
99
+ const r = runtime;
100
+ const hasAdapter = r.adapter !== void 0 || r.databaseAdapter !== void 0 || (r.hasDatabaseAdapter?.() ?? false);
101
+ if (hasAdapter) return;
102
+ const adapter = createDatabaseAdapter(runtime.agentId);
103
+ await adapter.initialize();
104
+ r.registerDatabaseAdapter?.(adapter);
105
+ }
106
+ };
107
+ var index_browser_default = plugin;
108
+ export {
109
+ createDatabaseAdapter,
110
+ index_browser_default as default,
111
+ plugin
112
+ };
113
+ //# sourceMappingURL=index.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../index.browser.ts"],"sourcesContent":["import type {\n IAgentRuntime,\n IDatabaseAdapter,\n Plugin,\n UUID,\n} from \"@elizaos/core\";\nimport {\n InMemoryDatabaseAdapter,\n type IStorage,\n} from \"@elizaos/plugin-inmemorydb\";\n\ntype RuntimeWithDatabase = IAgentRuntime & {\n registerDatabaseAdapter?: (adapter: IDatabaseAdapter) => void;\n adapter?: IDatabaseAdapter;\n databaseAdapter?: IDatabaseAdapter;\n hasDatabaseAdapter?: () => boolean;\n};\n\nclass BrowserLocalStorage implements IStorage {\n private collections = new Map<string, Map<string, unknown>>();\n private ready = false;\n\n constructor(private readonly key: string) {}\n\n async init(): Promise<void> {\n const raw = globalThis.localStorage.getItem(this.key);\n if (raw) {\n const parsed = JSON.parse(raw) as Record<string, Record<string, unknown>>;\n for (const [collection, entries] of Object.entries(parsed)) {\n this.collections.set(collection, new Map(Object.entries(entries)));\n }\n }\n this.ready = true;\n }\n\n async close(): Promise<void> {\n await this.flush();\n this.ready = false;\n }\n\n async isReady(): Promise<boolean> {\n return this.ready;\n }\n\n private getCollection(collection: string): Map<string, unknown> {\n let current = this.collections.get(collection);\n if (!current) {\n current = new Map();\n this.collections.set(collection, current);\n }\n return current;\n }\n\n private async flush(): Promise<void> {\n const out: Record<string, Record<string, unknown>> = {};\n for (const [collection, entries] of this.collections) {\n out[collection] = Object.fromEntries(entries);\n }\n globalThis.localStorage.setItem(this.key, JSON.stringify(out));\n }\n\n async get<T>(collection: string, id: string): Promise<T | null> {\n const item = this.getCollection(collection).get(id);\n return item === undefined ? null : (item as T);\n }\n\n async getAll<T>(collection: string): Promise<T[]> {\n return Array.from(this.getCollection(collection).values()) as T[];\n }\n\n async getWhere<T>(\n collection: string,\n predicate: (item: T) => boolean,\n ): Promise<T[]> {\n return (await this.getAll<T>(collection)).filter(predicate);\n }\n\n async set<T>(collection: string, id: string, data: T): Promise<void> {\n this.getCollection(collection).set(id, data);\n await this.flush();\n }\n\n async delete(collection: string, id: string): Promise<boolean> {\n const deleted = this.getCollection(collection).delete(id);\n if (deleted) await this.flush();\n return deleted;\n }\n\n async deleteMany(collection: string, ids: string[]): Promise<void> {\n const current = this.getCollection(collection);\n for (const id of ids) current.delete(id);\n await this.flush();\n }\n\n async deleteWhere<T = Record<string, unknown>>(\n collection: string,\n predicate: (item: T) => boolean,\n ): Promise<void> {\n const current = this.getCollection(collection);\n for (const [id, item] of current) {\n if (predicate(item as T)) current.delete(id);\n }\n await this.flush();\n }\n\n async count<T = Record<string, unknown>>(\n collection: string,\n predicate?: (item: T) => boolean,\n ): Promise<number> {\n const current = this.getCollection(collection);\n if (!predicate) return current.size;\n let total = 0;\n for (const item of current.values()) {\n if (predicate(item as T)) total++;\n }\n return total;\n }\n\n async clear(): Promise<void> {\n this.collections.clear();\n await this.flush();\n }\n}\n\nexport function createDatabaseAdapter(agentId: UUID): InMemoryDatabaseAdapter {\n return new InMemoryDatabaseAdapter(\n new BrowserLocalStorage(`elizaos:localdb:${agentId}`),\n agentId,\n );\n}\n\nexport const plugin: Plugin = {\n name: \"@elizaos/plugin-localdb\",\n description: \"Browser localStorage database storage for elizaOS examples.\",\n\n async init(\n _config: Record<string, string>,\n runtime: IAgentRuntime,\n ): Promise<void> {\n const r = runtime as RuntimeWithDatabase;\n const hasAdapter =\n r.adapter !== undefined ||\n r.databaseAdapter !== undefined ||\n (r.hasDatabaseAdapter?.() ?? false);\n\n if (hasAdapter) return;\n\n const adapter = createDatabaseAdapter(runtime.agentId);\n await adapter.initialize();\n r.registerDatabaseAdapter?.(adapter);\n },\n};\n\nexport default plugin;\n"],"mappings":";AAMA;AAAA,EACE;AAAA,OAEK;AASP,IAAM,sBAAN,MAA8C;AAAA,EAI5C,YAA6B,KAAa;AAAb;AAAA,EAAc;AAAA,EAAd;AAAA,EAHrB,cAAc,oBAAI,IAAkC;AAAA,EACpD,QAAQ;AAAA,EAIhB,MAAM,OAAsB;AAC1B,UAAM,MAAM,WAAW,aAAa,QAAQ,KAAK,GAAG;AACpD,QAAI,KAAK;AACP,YAAM,SAAS,KAAK,MAAM,GAAG;AAC7B,iBAAW,CAAC,YAAY,OAAO,KAAK,OAAO,QAAQ,MAAM,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 -0,0 +1,7 @@
1
+ import { UUID, Plugin } from '@elizaos/core';
2
+ import { InMemoryDatabaseAdapter } from '@elizaos/plugin-inmemorydb';
3
+
4
+ declare function createDatabaseAdapter(agentId: UUID, dataDir: string): InMemoryDatabaseAdapter;
5
+ declare const plugin: Plugin;
6
+
7
+ export { createDatabaseAdapter, plugin as default, plugin };
package/dist/index.js ADDED
@@ -0,0 +1,138 @@
1
+ // index.ts
2
+ import { mkdir, readFile, rename, writeFile } from "fs/promises";
3
+ import { dirname, join } from "path";
4
+ import { logger } from "@elizaos/core";
5
+ import {
6
+ InMemoryDatabaseAdapter
7
+ } from "@elizaos/plugin-inmemorydb";
8
+ var FileStorage = class {
9
+ collections = /* @__PURE__ */ new Map();
10
+ ready = false;
11
+ filePath;
12
+ writeChain = Promise.resolve();
13
+ constructor(dataDir) {
14
+ this.filePath = join(dataDir, "localdb.json");
15
+ }
16
+ async init() {
17
+ await mkdir(dirname(this.filePath), { recursive: true });
18
+ try {
19
+ const raw = await readFile(this.filePath, "utf8");
20
+ const parsed = JSON.parse(raw);
21
+ for (const [collection, entries] of Object.entries(parsed)) {
22
+ this.collections.set(collection, new Map(Object.entries(entries)));
23
+ }
24
+ } catch (error) {
25
+ if (error.code !== "ENOENT") throw error;
26
+ }
27
+ this.ready = true;
28
+ }
29
+ async close() {
30
+ await this.flush();
31
+ this.ready = false;
32
+ }
33
+ async isReady() {
34
+ return this.ready;
35
+ }
36
+ getCollection(collection) {
37
+ let current = this.collections.get(collection);
38
+ if (!current) {
39
+ current = /* @__PURE__ */ new Map();
40
+ this.collections.set(collection, current);
41
+ }
42
+ return current;
43
+ }
44
+ async flush() {
45
+ const out = {};
46
+ for (const [collection, entries] of this.collections) {
47
+ out[collection] = Object.fromEntries(entries);
48
+ }
49
+ const payload = JSON.stringify(out, null, 2);
50
+ const run = this.writeChain.then(() => this.writeAtomic(payload));
51
+ this.writeChain = run.catch(() => {
52
+ });
53
+ await run;
54
+ }
55
+ async writeAtomic(payload) {
56
+ const tmpPath = `${this.filePath}.tmp.${process.pid}`;
57
+ await writeFile(tmpPath, payload, "utf8");
58
+ await rename(tmpPath, this.filePath);
59
+ }
60
+ async get(collection, id) {
61
+ const item = this.getCollection(collection).get(id);
62
+ return item === void 0 ? null : item;
63
+ }
64
+ async getAll(collection) {
65
+ return Array.from(this.getCollection(collection).values());
66
+ }
67
+ async getWhere(collection, predicate) {
68
+ return (await this.getAll(collection)).filter(predicate);
69
+ }
70
+ async set(collection, id, data) {
71
+ this.getCollection(collection).set(id, data);
72
+ await this.flush();
73
+ }
74
+ async delete(collection, id) {
75
+ const deleted = this.getCollection(collection).delete(id);
76
+ if (deleted) await this.flush();
77
+ return deleted;
78
+ }
79
+ async deleteMany(collection, ids) {
80
+ const current = this.getCollection(collection);
81
+ for (const id of ids) current.delete(id);
82
+ await this.flush();
83
+ }
84
+ async deleteWhere(collection, predicate) {
85
+ const current = this.getCollection(collection);
86
+ for (const [id, item] of current) {
87
+ if (predicate(item)) current.delete(id);
88
+ }
89
+ await this.flush();
90
+ }
91
+ async count(collection, predicate) {
92
+ const current = this.getCollection(collection);
93
+ if (!predicate) return current.size;
94
+ let total = 0;
95
+ for (const item of current.values()) {
96
+ if (predicate(item)) total++;
97
+ }
98
+ return total;
99
+ }
100
+ async clear() {
101
+ this.collections.clear();
102
+ await this.flush();
103
+ }
104
+ };
105
+ function getDataDir(runtime) {
106
+ const configured = runtime.getSetting?.("LOCALDB_DATA_DIR");
107
+ if (typeof configured === "string" && configured.length > 0) {
108
+ return configured;
109
+ }
110
+ const envDir = process.env.LOCALDB_DATA_DIR;
111
+ if (typeof envDir === "string" && envDir.length > 0) {
112
+ return envDir;
113
+ }
114
+ return join(process.cwd(), ".eliza-localdb");
115
+ }
116
+ function createDatabaseAdapter(agentId, dataDir) {
117
+ return new InMemoryDatabaseAdapter(new FileStorage(dataDir), agentId);
118
+ }
119
+ var plugin = {
120
+ name: "@elizaos/plugin-localdb",
121
+ description: "Local JSON-file database storage for elizaOS examples.",
122
+ async init(_config, runtime) {
123
+ const r = runtime;
124
+ const hasAdapter = r.adapter !== void 0 || r.databaseAdapter !== void 0 || (r.hasDatabaseAdapter?.() ?? false);
125
+ if (hasAdapter) return;
126
+ const adapter = createDatabaseAdapter(runtime.agentId, getDataDir(r));
127
+ await adapter.initialize();
128
+ r.registerDatabaseAdapter?.(adapter);
129
+ logger.info({ src: "plugin:localdb" }, "Local database adapter registered");
130
+ }
131
+ };
132
+ var index_default = plugin;
133
+ export {
134
+ createDatabaseAdapter,
135
+ index_default as default,
136
+ plugin
137
+ };
138
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../index.ts"],"sourcesContent":["import { mkdir, readFile, rename, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport type {\n IAgentRuntime,\n IDatabaseAdapter,\n Plugin,\n UUID,\n} from \"@elizaos/core\";\nimport { logger } from \"@elizaos/core\";\nimport {\n InMemoryDatabaseAdapter,\n type IStorage,\n} from \"@elizaos/plugin-inmemorydb\";\n\ntype RuntimeWithDatabase = IAgentRuntime & {\n registerDatabaseAdapter?: (adapter: IDatabaseAdapter) => void;\n adapter?: IDatabaseAdapter;\n databaseAdapter?: IDatabaseAdapter;\n hasDatabaseAdapter?: () => boolean;\n getSetting?: (key: string) => string | undefined;\n};\n\nclass FileStorage implements IStorage {\n private collections = new Map<string, Map<string, unknown>>();\n private ready = false;\n private readonly filePath: string;\n private writeChain: Promise<void> = Promise.resolve();\n\n constructor(dataDir: string) {\n this.filePath = join(dataDir, \"localdb.json\");\n }\n\n async init(): Promise<void> {\n await mkdir(dirname(this.filePath), { recursive: true });\n try {\n const raw = await readFile(this.filePath, \"utf8\");\n const parsed = JSON.parse(raw) as Record<string, Record<string, unknown>>;\n for (const [collection, entries] of Object.entries(parsed)) {\n this.collections.set(collection, new Map(Object.entries(entries)));\n }\n } catch (error) {\n if ((error as { code?: string }).code !== \"ENOENT\") throw error;\n }\n this.ready = true;\n }\n\n async close(): Promise<void> {\n await this.flush();\n this.ready = false;\n }\n\n async isReady(): Promise<boolean> {\n return this.ready;\n }\n\n private getCollection(collection: string): Map<string, unknown> {\n let current = this.collections.get(collection);\n if (!current) {\n current = new Map();\n this.collections.set(collection, current);\n }\n return current;\n }\n\n private async flush(): Promise<void> {\n // Serialize all flushes through a single chained promise so independently\n // scheduled async mutations cannot interleave writes to the same file.\n // Snapshot the live data at enqueue time so the write reflects state at\n // the moment this mutation completed.\n const out: Record<string, Record<string, unknown>> = {};\n for (const [collection, entries] of this.collections) {\n out[collection] = Object.fromEntries(entries);\n }\n const payload = JSON.stringify(out, null, 2);\n\n const run = this.writeChain.then(() => this.writeAtomic(payload));\n // Keep the chain alive even if a write rejects, so a single failure does\n // not permanently break serialization for subsequent flushes.\n this.writeChain = run.catch(() => {});\n await run;\n }\n\n private async writeAtomic(payload: string): Promise<void> {\n // Write to a sibling temp file then rename for an atomic replace, so a\n // crash mid-write can never truncate or garble the live localdb.json.\n const tmpPath = `${this.filePath}.tmp.${process.pid}`;\n await writeFile(tmpPath, payload, \"utf8\");\n await rename(tmpPath, this.filePath);\n }\n\n async get<T>(collection: string, id: string): Promise<T | null> {\n const item = this.getCollection(collection).get(id);\n return item === undefined ? null : (item as T);\n }\n\n async getAll<T>(collection: string): Promise<T[]> {\n return Array.from(this.getCollection(collection).values()) as T[];\n }\n\n async getWhere<T>(\n collection: string,\n predicate: (item: T) => boolean,\n ): Promise<T[]> {\n return (await this.getAll<T>(collection)).filter(predicate);\n }\n\n async set<T>(collection: string, id: string, data: T): Promise<void> {\n this.getCollection(collection).set(id, data);\n await this.flush();\n }\n\n async delete(collection: string, id: string): Promise<boolean> {\n const deleted = this.getCollection(collection).delete(id);\n if (deleted) await this.flush();\n return deleted;\n }\n\n async deleteMany(collection: string, ids: string[]): Promise<void> {\n const current = this.getCollection(collection);\n for (const id of ids) current.delete(id);\n await this.flush();\n }\n\n async deleteWhere<T = Record<string, unknown>>(\n collection: string,\n predicate: (item: T) => boolean,\n ): Promise<void> {\n const current = this.getCollection(collection);\n for (const [id, item] of current) {\n if (predicate(item as T)) current.delete(id);\n }\n await this.flush();\n }\n\n async count<T = Record<string, unknown>>(\n collection: string,\n predicate?: (item: T) => boolean,\n ): Promise<number> {\n const current = this.getCollection(collection);\n if (!predicate) return current.size;\n let total = 0;\n for (const item of current.values()) {\n if (predicate(item as T)) total++;\n }\n return total;\n }\n\n async clear(): Promise<void> {\n this.collections.clear();\n await this.flush();\n }\n}\n\nfunction getDataDir(runtime: RuntimeWithDatabase): string {\n const configured = runtime.getSetting?.(\"LOCALDB_DATA_DIR\");\n if (typeof configured === \"string\" && configured.length > 0) {\n return configured;\n }\n\n const envDir = process.env.LOCALDB_DATA_DIR;\n if (typeof envDir === \"string\" && envDir.length > 0) {\n return envDir;\n }\n\n return join(process.cwd(), \".eliza-localdb\");\n}\n\nexport function createDatabaseAdapter(\n agentId: UUID,\n dataDir: string,\n): InMemoryDatabaseAdapter {\n return new InMemoryDatabaseAdapter(new FileStorage(dataDir), agentId);\n}\n\nexport const plugin: Plugin = {\n name: \"@elizaos/plugin-localdb\",\n description: \"Local JSON-file database storage for elizaOS examples.\",\n\n async init(\n _config: Record<string, string>,\n runtime: IAgentRuntime,\n ): Promise<void> {\n const r = runtime as RuntimeWithDatabase;\n const hasAdapter =\n r.adapter !== undefined ||\n r.databaseAdapter !== undefined ||\n (r.hasDatabaseAdapter?.() ?? false);\n\n if (hasAdapter) return;\n\n const adapter = createDatabaseAdapter(runtime.agentId, getDataDir(r));\n await adapter.initialize();\n r.registerDatabaseAdapter?.(adapter);\n logger.info({ src: \"plugin:localdb\" }, \"Local database adapter registered\");\n },\n};\n\nexport default plugin;\n"],"mappings":";AAAA,SAAS,OAAO,UAAU,QAAQ,iBAAiB;AACnD,SAAS,SAAS,YAAY;AAO9B,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,OAEK;AAUP,IAAM,cAAN,MAAsC;AAAA,EAC5B,cAAc,oBAAI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B;AACjB,UAAM,UAAU,KAAK,cAAc,UAAU;AAC7C,QAAI,CAAC,UAAW,QAAO,QAAQ;AAC/B,QAAI,QAAQ;AACZ,eAAW,QAAQ,QAAQ,OAAO,GAAG;AACnC,UAAI,UAAU,IAAS,EAAG;AAAA,IAC5B;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,QAAuB;AAC3B,SAAK,YAAY,MAAM;AACvB,UAAM,KAAK,MAAM;AAAA,EACnB;AACF;AAEA,SAAS,WAAW,SAAsC;AACxD,QAAM,aAAa,QAAQ,aAAa,kBAAkB;AAC1D,MAAI,OAAO,eAAe,YAAY,WAAW,SAAS,GAAG;AAC3D,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,QAAQ,IAAI;AAC3B,MAAI,OAAO,WAAW,YAAY,OAAO,SAAS,GAAG;AACnD,WAAO;AAAA,EACT;AAEA,SAAO,KAAK,QAAQ,IAAI,GAAG,gBAAgB;AAC7C;AAEO,SAAS,sBACd,SACA,SACyB;AACzB,SAAO,IAAI,wBAAwB,IAAI,YAAY,OAAO,GAAG,OAAO;AACtE;AAEO,IAAM,SAAiB;AAAA,EAC5B,MAAM;AAAA,EACN,aAAa;AAAA,EAEb,MAAM,KACJ,SACA,SACe;AACf,UAAM,IAAI;AACV,UAAM,aACJ,EAAE,YAAY,UACd,EAAE,oBAAoB,WACrB,EAAE,qBAAqB,KAAK;AAE/B,QAAI,WAAY;AAEhB,UAAM,UAAU,sBAAsB,QAAQ,SAAS,WAAW,CAAC,CAAC;AACpE,UAAM,QAAQ,WAAW;AACzB,MAAE,0BAA0B,OAAO;AACnC,WAAO,KAAK,EAAE,KAAK,iBAAiB,GAAG,mCAAmC;AAAA,EAC5E;AACF;AAEA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elizaos/plugin-localdb",
3
- "version": "2.0.3-beta.6",
3
+ "version": "2.0.3-beta.7",
4
4
  "type": "module",
5
5
  "description": "File-backed (Node) and localStorage (browser) persistence via plugin-inmemorydb; ships compiled ESM in dist/.",
6
6
  "main": "./dist/index.js",
@@ -46,8 +46,8 @@
46
46
  "test": "vitest run"
47
47
  },
48
48
  "dependencies": {
49
- "@elizaos/core": "2.0.3-beta.6",
50
- "@elizaos/plugin-inmemorydb": "2.0.3-beta.6"
49
+ "@elizaos/core": "2.0.3-beta.7",
50
+ "@elizaos/plugin-inmemorydb": "2.0.3-beta.7"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "25.6.2",
@@ -56,8 +56,8 @@
56
56
  "vitest": "^4.0.18"
57
57
  },
58
58
  "peerDependencies": {
59
- "@elizaos/core": "2.0.3-beta.6",
60
- "@elizaos/plugin-inmemorydb": "2.0.3-beta.6"
59
+ "@elizaos/core": "2.0.3-beta.7",
60
+ "@elizaos/plugin-inmemorydb": "2.0.3-beta.7"
61
61
  },
62
62
  "publishConfig": {
63
63
  "access": "public"
@@ -67,5 +67,5 @@
67
67
  "url": "git+https://github.com/elizaos/eliza.git",
68
68
  "directory": "plugins/plugin-localdb"
69
69
  },
70
- "gitHead": "990dc996172b3e0fb525a75052a5ac28a4cd4de5"
70
+ "gitHead": "61094f10458d11055c75b3dd0bae374e3f66bac5"
71
71
  }