mcard-js 2.1.49 → 2.1.50

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,275 @@
1
+ import {
2
+ createPage
3
+ } from "./chunk-3EIBJPNF.js";
4
+ import {
5
+ MCard
6
+ } from "./chunk-GGQCF7ZK.js";
7
+ import {
8
+ init_Handle,
9
+ validateHandle
10
+ } from "./chunk-ADV52544.js";
11
+ import {
12
+ DEFAULT_PAGE_SIZE,
13
+ INDEXEDDB_DEFAULT_DB_NAME,
14
+ INDEXEDDB_DEFAULT_DB_VERSION
15
+ } from "./chunk-ETJWXHKZ.js";
16
+
17
+ // src/storage/engines/IndexedDBEngine.ts
18
+ import { openDB } from "idb";
19
+ init_Handle();
20
+ var IndexedDBEngine = class {
21
+ db = null;
22
+ dbName;
23
+ constructor(dbName = INDEXEDDB_DEFAULT_DB_NAME) {
24
+ this.dbName = dbName;
25
+ }
26
+ /**
27
+ * Initialize the database connection
28
+ */
29
+ async init() {
30
+ this.db = await openDB(this.dbName, INDEXEDDB_DEFAULT_DB_VERSION, {
31
+ upgrade(db) {
32
+ if (!db.objectStoreNames.contains("cards")) {
33
+ db.createObjectStore("cards", { keyPath: "hash" });
34
+ }
35
+ if (!db.objectStoreNames.contains("handles")) {
36
+ const handleStore = db.createObjectStore("handles", { keyPath: "handle" });
37
+ handleStore.createIndex("by-hash", "currentHash");
38
+ }
39
+ if (!db.objectStoreNames.contains("handleHistory")) {
40
+ const historyStore = db.createObjectStore("handleHistory", {
41
+ keyPath: "id",
42
+ autoIncrement: true
43
+ });
44
+ historyStore.createIndex("by-handle", "handle");
45
+ }
46
+ }
47
+ });
48
+ }
49
+ ensureDb() {
50
+ if (!this.db) {
51
+ throw new Error("Database not initialized. Call init() first.");
52
+ }
53
+ return this.db;
54
+ }
55
+ // =========== Card Operations ===========
56
+ async add(card) {
57
+ const db = this.ensureDb();
58
+ await db.put("cards", {
59
+ hash: card.hash,
60
+ content: card.content,
61
+ g_time: card.g_time
62
+ });
63
+ return card.hash;
64
+ }
65
+ async get(hash) {
66
+ const db = this.ensureDb();
67
+ const record = await db.get("cards", hash);
68
+ if (!record) return null;
69
+ return MCard.fromData(record.content, record.hash, record.g_time);
70
+ }
71
+ async delete(hash) {
72
+ const db = this.ensureDb();
73
+ await db.delete("cards", hash);
74
+ }
75
+ async getPage(pageNumber, pageSize = DEFAULT_PAGE_SIZE) {
76
+ const db = this.ensureDb();
77
+ const totalItems = await db.count("cards");
78
+ const allCards = await db.getAll("cards");
79
+ const start = (pageNumber - 1) * pageSize;
80
+ const pageRecords = allCards.slice(start, start + pageSize);
81
+ const items = pageRecords.map((r) => MCard.fromData(r.content, r.hash, r.g_time));
82
+ return createPage(items, totalItems, pageNumber, pageSize);
83
+ }
84
+ async count() {
85
+ const db = this.ensureDb();
86
+ return db.count("cards");
87
+ }
88
+ async searchByHash(hashPrefix) {
89
+ const db = this.ensureDb();
90
+ const start = hashPrefix;
91
+ const end = hashPrefix + "\uFFFF";
92
+ const range = IDBKeyRange.bound(start, end);
93
+ const records = await db.getAll("cards", range);
94
+ return records.map((r) => MCard.fromData(r.content, r.hash, r.g_time));
95
+ }
96
+ async search(query, pageNumber, pageSize = DEFAULT_PAGE_SIZE) {
97
+ const db = this.ensureDb();
98
+ const records = await db.getAll("cards");
99
+ const decoder = new TextDecoder();
100
+ const filtered = records.filter((r) => {
101
+ try {
102
+ const text = decoder.decode(r.content);
103
+ return text.includes(query);
104
+ } catch {
105
+ return false;
106
+ }
107
+ });
108
+ const totalItems = filtered.length;
109
+ const start = (pageNumber - 1) * pageSize;
110
+ const pageItems = filtered.slice(start, start + pageSize).map((r) => MCard.fromData(r.content, r.hash, r.g_time));
111
+ return createPage(pageItems, totalItems, pageNumber, pageSize);
112
+ }
113
+ async getAll() {
114
+ const db = this.ensureDb();
115
+ const records = await db.getAll("cards");
116
+ return records.map((r) => MCard.fromData(r.content, r.hash, r.g_time));
117
+ }
118
+ async clear() {
119
+ const db = this.ensureDb();
120
+ await db.clear("cards");
121
+ await db.clear("handles");
122
+ await db.clear("handleHistory");
123
+ }
124
+ // =========== Handle Operations ===========
125
+ async registerHandle(handle, hash) {
126
+ const db = this.ensureDb();
127
+ const normalized = validateHandle(handle);
128
+ const existing = await db.get("handles", normalized);
129
+ if (existing) {
130
+ throw new Error(`Handle '${handle}' already exists.`);
131
+ }
132
+ const now = (/* @__PURE__ */ new Date()).toISOString();
133
+ await db.put("handles", {
134
+ handle: normalized,
135
+ currentHash: hash,
136
+ createdAt: now,
137
+ updatedAt: now
138
+ });
139
+ }
140
+ async resolveHandle(handle) {
141
+ const db = this.ensureDb();
142
+ const normalized = validateHandle(handle);
143
+ const record = await db.get("handles", normalized);
144
+ return record?.currentHash ?? null;
145
+ }
146
+ async getByHandle(handle) {
147
+ const hash = await this.resolveHandle(handle);
148
+ if (!hash) return null;
149
+ return this.get(hash);
150
+ }
151
+ async updateHandle(handle, newHash) {
152
+ const db = this.ensureDb();
153
+ const normalized = validateHandle(handle);
154
+ const existing = await db.get("handles", normalized);
155
+ if (!existing) {
156
+ throw new Error(`Handle '${handle}' not found.`);
157
+ }
158
+ const previousHash = existing.currentHash;
159
+ const now = (/* @__PURE__ */ new Date()).toISOString();
160
+ await db.add("handleHistory", {
161
+ handle: normalized,
162
+ previousHash,
163
+ changedAt: now
164
+ });
165
+ await db.put("handles", {
166
+ ...existing,
167
+ currentHash: newHash,
168
+ updatedAt: now
169
+ });
170
+ return previousHash;
171
+ }
172
+ async getHandleHistory(handle) {
173
+ const db = this.ensureDb();
174
+ const normalized = validateHandle(handle);
175
+ const records = await db.getAllFromIndex("handleHistory", "by-handle", normalized);
176
+ return records.map((r) => ({ previousHash: r.previousHash, changedAt: r.changedAt })).reverse();
177
+ }
178
+ async pruneHandleHistory(handle, options = {}) {
179
+ const db = this.ensureDb();
180
+ const normalized = validateHandle(handle);
181
+ const records = await db.getAllFromIndex("handleHistory", "by-handle", normalized);
182
+ let toDelete;
183
+ if (options.deleteAll) {
184
+ toDelete = records;
185
+ } else if (options.olderThan) {
186
+ toDelete = records.filter((r) => r.changedAt < options.olderThan);
187
+ } else {
188
+ return 0;
189
+ }
190
+ const tx = db.transaction("handleHistory", "readwrite");
191
+ for (const record of toDelete) {
192
+ await tx.store.delete(record.id);
193
+ }
194
+ await tx.done;
195
+ return toDelete.length;
196
+ }
197
+ // =========== Handle Management Operations ===========
198
+ async getAllHandles() {
199
+ const db = this.ensureDb();
200
+ const records = await db.getAll("handles");
201
+ return records.map((r) => ({ handle: r.handle, hash: r.currentHash }));
202
+ }
203
+ async removeHandle(handle) {
204
+ const db = this.ensureDb();
205
+ const normalized = validateHandle(handle);
206
+ const keysToTry = normalized !== handle.trim() ? [normalized, handle.trim()] : [normalized];
207
+ const tx = db.transaction(["handles", "handleHistory"], "readwrite");
208
+ const handleStore = tx.objectStore("handles");
209
+ const historyStore = tx.objectStore("handleHistory");
210
+ for (const key of keysToTry) {
211
+ await handleStore.delete(key);
212
+ }
213
+ const historyIndex = historyStore.index("by-handle");
214
+ for (const key of keysToTry) {
215
+ let cursor = await historyIndex.openCursor(key);
216
+ while (cursor) {
217
+ await cursor.delete();
218
+ cursor = await cursor.continue();
219
+ }
220
+ }
221
+ await tx.done;
222
+ }
223
+ async renameHandle(oldHandle, newHandle) {
224
+ const db = this.ensureDb();
225
+ const normalizedOld = validateHandle(oldHandle);
226
+ const normalizedNew = validateHandle(newHandle);
227
+ if (normalizedOld === normalizedNew) return;
228
+ const oldEntry = await db.get("handles", normalizedOld);
229
+ if (!oldEntry) throw new Error(`Handle '${oldHandle}' not found.`);
230
+ const newEntry = await db.get("handles", normalizedNew);
231
+ if (newEntry) throw new Error(`Handle '${newHandle}' already exists.`);
232
+ const tx = db.transaction(["handles", "handleHistory"], "readwrite");
233
+ const handleStore = tx.objectStore("handles");
234
+ const historyStore = tx.objectStore("handleHistory");
235
+ const now = (/* @__PURE__ */ new Date()).toISOString();
236
+ await handleStore.put({
237
+ ...oldEntry,
238
+ handle: normalizedNew,
239
+ updatedAt: now
240
+ });
241
+ await handleStore.delete(normalizedOld);
242
+ const historyIndex = historyStore.index("by-handle");
243
+ let cursor = await historyIndex.openCursor(normalizedOld);
244
+ while (cursor) {
245
+ const record = cursor.value;
246
+ record.handle = normalizedNew;
247
+ await cursor.update(record);
248
+ cursor = await cursor.continue();
249
+ }
250
+ await tx.done;
251
+ }
252
+ async deleteHistoryEntry(handle, previousHash) {
253
+ const db = this.ensureDb();
254
+ const normalized = validateHandle(handle);
255
+ const records = await db.getAllFromIndex("handleHistory", "by-handle", normalized);
256
+ const entries = records.sort((a, b) => a.id - b.id);
257
+ const targetIdx = entries.findIndex((e) => e.previousHash === previousHash);
258
+ if (targetIdx === -1) return;
259
+ const target = entries[targetIdx];
260
+ const successor = entries[targetIdx + 1];
261
+ const tx = db.transaction("handleHistory", "readwrite");
262
+ const store = tx.objectStore("handleHistory");
263
+ if (successor && targetIdx > 0) {
264
+ const predecessor = entries[targetIdx - 1];
265
+ successor.previousHash = predecessor.previousHash;
266
+ await store.put(successor);
267
+ }
268
+ await store.delete(target.id);
269
+ await tx.done;
270
+ }
271
+ };
272
+
273
+ export {
274
+ IndexedDBEngine
275
+ };
@@ -0,0 +1,101 @@
1
+ import {
2
+ API_KEY_HEADER_NAME,
3
+ BINARY_CHECK_SAMPLE_SIZE,
4
+ CONTENT_DETECTION_SAMPLE_SIZE,
5
+ CORS_ORIGINS,
6
+ DEFAULT_API_PORT,
7
+ DEFAULT_CLM_TIMEOUT_MS,
8
+ DEFAULT_EMBEDDING_MODEL,
9
+ DEFAULT_EXECUTION_LOG_PATH,
10
+ DEFAULT_IDENTITY_PROVIDER,
11
+ DEFAULT_IDENTITY_SPACE_PATH,
12
+ DEFAULT_JS_API_PORT,
13
+ DEFAULT_LMSTUDIO_BASE_URL,
14
+ DEFAULT_MAX_ETA_STEPS,
15
+ DEFAULT_MAX_INTROSPECTION_DEPTH,
16
+ DEFAULT_MAX_PROBLEM_BYTES,
17
+ DEFAULT_MAX_REDUCTION_STEPS,
18
+ DEFAULT_OLLAMA_BASE_URL,
19
+ DEFAULT_OTLP_ENDPOINT,
20
+ DEFAULT_PAGE_SIZE,
21
+ DEFAULT_PYTHON_API_PORT,
22
+ DEFAULT_SANDBOX_TIMEOUT_MS,
23
+ DEFAULT_SERVER_HOST,
24
+ DEFAULT_SQLJS_WASM_URL,
25
+ DEFAULT_VISION_MODEL,
26
+ DEFAULT_VLLM_BASE_URL,
27
+ DEFAULT_VM_EXECUTION_TIMEOUT_MS,
28
+ DEFAULT_WS_HOST,
29
+ DEFAULT_WS_PORT,
30
+ DEFAULT_WS_RECONNECT_MS,
31
+ DETECTION_SAMPLE_CAP,
32
+ EMBEDDING_MODELS,
33
+ ENV_API_PORT,
34
+ ENV_WS_PORT,
35
+ INDEXEDDB_DEFAULT_DB_NAME,
36
+ INDEXEDDB_DEFAULT_DB_VERSION,
37
+ KNOWN_TYPE_SIZE_LIMIT,
38
+ LLM_DEFAULT_RETRY_COUNT,
39
+ LLM_DEFAULT_RETRY_DELAY_SECS,
40
+ LLM_DEFAULT_TIMEOUT_SECS,
41
+ MAX_FILE_SIZE,
42
+ MAX_PAGE_SIZE,
43
+ MAX_VECTOR_CONTENT_CHARS,
44
+ MIN_PAGE_SIZE,
45
+ READ_CHUNK_SIZE,
46
+ READ_TIMEOUT_MS,
47
+ SQLITE_BUSY_TIMEOUT_MS,
48
+ VISION_MODELS,
49
+ WRAP_WIDTH_KNOWN
50
+ } from "./chunk-ETJWXHKZ.js";
51
+ import "./chunk-PNKVD2UK.js";
52
+ export {
53
+ API_KEY_HEADER_NAME,
54
+ BINARY_CHECK_SAMPLE_SIZE,
55
+ CONTENT_DETECTION_SAMPLE_SIZE,
56
+ CORS_ORIGINS,
57
+ DEFAULT_API_PORT,
58
+ DEFAULT_CLM_TIMEOUT_MS,
59
+ DEFAULT_EMBEDDING_MODEL,
60
+ DEFAULT_EXECUTION_LOG_PATH,
61
+ DEFAULT_IDENTITY_PROVIDER,
62
+ DEFAULT_IDENTITY_SPACE_PATH,
63
+ DEFAULT_JS_API_PORT,
64
+ DEFAULT_LMSTUDIO_BASE_URL,
65
+ DEFAULT_MAX_ETA_STEPS,
66
+ DEFAULT_MAX_INTROSPECTION_DEPTH,
67
+ DEFAULT_MAX_PROBLEM_BYTES,
68
+ DEFAULT_MAX_REDUCTION_STEPS,
69
+ DEFAULT_OLLAMA_BASE_URL,
70
+ DEFAULT_OTLP_ENDPOINT,
71
+ DEFAULT_PAGE_SIZE,
72
+ DEFAULT_PYTHON_API_PORT,
73
+ DEFAULT_SANDBOX_TIMEOUT_MS,
74
+ DEFAULT_SERVER_HOST,
75
+ DEFAULT_SQLJS_WASM_URL,
76
+ DEFAULT_VISION_MODEL,
77
+ DEFAULT_VLLM_BASE_URL,
78
+ DEFAULT_VM_EXECUTION_TIMEOUT_MS,
79
+ DEFAULT_WS_HOST,
80
+ DEFAULT_WS_PORT,
81
+ DEFAULT_WS_RECONNECT_MS,
82
+ DETECTION_SAMPLE_CAP,
83
+ EMBEDDING_MODELS,
84
+ ENV_API_PORT,
85
+ ENV_WS_PORT,
86
+ INDEXEDDB_DEFAULT_DB_NAME,
87
+ INDEXEDDB_DEFAULT_DB_VERSION,
88
+ KNOWN_TYPE_SIZE_LIMIT,
89
+ LLM_DEFAULT_RETRY_COUNT,
90
+ LLM_DEFAULT_RETRY_DELAY_SECS,
91
+ LLM_DEFAULT_TIMEOUT_SECS,
92
+ MAX_FILE_SIZE,
93
+ MAX_PAGE_SIZE,
94
+ MAX_VECTOR_CONTENT_CHARS,
95
+ MIN_PAGE_SIZE,
96
+ READ_CHUNK_SIZE,
97
+ READ_TIMEOUT_MS,
98
+ SQLITE_BUSY_TIMEOUT_MS,
99
+ VISION_MODELS,
100
+ WRAP_WIDTH_KNOWN
101
+ };
@@ -546,12 +546,12 @@ var app_config_default = {
546
546
  },
547
547
  identity: {
548
548
  provider: "sqlite",
549
- space_path: "./data/IDENTITY_SPACE.db",
549
+ space_path: "./data/agent_identities.db",
550
550
  api_endpoint: null,
551
551
  default_vapid_contact: "mailto:developer@example.com"
552
552
  },
553
553
  storage: {
554
- default_db_path: "./data/DEFAULT_DB_FILE.db",
554
+ default_db_path: "./data/content_memory.db",
555
555
  test_db_path: "./tests/data/test_mcard.db",
556
556
  default_data_root_dirname: "data",
557
557
  default_data_user: "guest",
@@ -561,7 +561,7 @@ var app_config_default = {
561
561
  default_mcard_db: "mcard.db",
562
562
  default_server_log_db: "server_log.db",
563
563
  default_push_subscriptions_file: "subscriptions.json",
564
- default_vcard_db_path: "data/vcard.db"
564
+ default_execution_log_path: "./data/execution_log.db"
565
565
  },
566
566
  services: {
567
567
  default_ollama_base_url: "http://localhost:11434",
@@ -612,11 +612,11 @@ var DEFAULT_MAX_PROBLEM_BYTES = 2 * 1024 * 1024;
612
612
  var INDEXEDDB_DEFAULT_DB_NAME = "mcard-db";
613
613
  var INDEXEDDB_DEFAULT_DB_VERSION = 1;
614
614
  var DEFAULT_IDENTITY_PROVIDER = String(identity.provider ?? "sqlite");
615
- var DEFAULT_IDENTITY_SPACE_PATH = String(identity.space_path ?? "./data/IDENTITY_SPACE.db");
615
+ var DEFAULT_IDENTITY_SPACE_PATH = String(identity.space_path ?? "./data/agent_identities.db");
616
+ var DEFAULT_EXECUTION_LOG_PATH = String(app_config_default.storage?.default_execution_log_path ?? "./data/execution_log.db");
616
617
  var DEFAULT_API_PORT = Number(network.default_api_port ?? 5320);
617
618
  var DEFAULT_PYTHON_API_PORT = Number(network.default_python_api_port ?? 28302);
618
619
  var DEFAULT_JS_API_PORT = Number(network.default_js_api_port ?? 28303);
619
- var DEFAULT_VCARD_DB_PATH = String(app_config_default.storage?.default_vcard_db_path ?? "./data/vcard.db");
620
620
  var DEFAULT_WS_PORT = Number(network.default_ws_port ?? 5321);
621
621
  var DEFAULT_WS_HOST = String(network.default_ws_host ?? "127.0.0.1");
622
622
  var DEFAULT_SERVER_HOST = String(network.default_server_host ?? "0.0.0.0");
@@ -16,7 +16,11 @@ import {
16
16
  } from "./chunk-XJZOEM5F.js";
17
17
  import {
18
18
  IndexedDBEngine
19
- } from "./chunk-NGTY4P6A.js";
19
+ } from "./chunk-ZMK2HTZ5.js";
20
+ import {
21
+ CardCollection,
22
+ Maybe
23
+ } from "./chunk-VJPXJVEH.js";
20
24
  import {
21
25
  IO
22
26
  } from "./chunk-MPMRBT5R.js";
@@ -25,28 +29,24 @@ import {
25
29
  } from "./chunk-2KADE3SE.js";
26
30
  import {
27
31
  SqliteWasmEngine
28
- } from "./chunk-7AXRV7NS.js";
29
- import "./chunk-HIVVDGE5.js";
32
+ } from "./chunk-XETU7TV4.js";
33
+ import "./chunk-GIKMCG4D.js";
30
34
  import "./chunk-3EIBJPNF.js";
35
+ import {
36
+ ContentTypeInterpreter,
37
+ MCard
38
+ } from "./chunk-GGQCF7ZK.js";
31
39
  import {
32
40
  ContentHandle,
33
41
  HandleValidationError,
34
42
  init_Handle,
35
43
  validateHandle
36
44
  } from "./chunk-ADV52544.js";
45
+ import "./chunk-ETJWXHKZ.js";
37
46
  import {
38
47
  ALGORITHM_HIERARCHY,
39
48
  EVENT_CONSTANTS
40
49
  } from "./chunk-KEC7YFG3.js";
41
- import {
42
- CardCollection,
43
- Maybe
44
- } from "./chunk-QPVEUPMU.js";
45
- import "./chunk-3FFEA2XK.js";
46
- import {
47
- ContentTypeInterpreter,
48
- MCard
49
- } from "./chunk-GGQCF7ZK.js";
50
50
  import {
51
51
  GTime,
52
52
  HashValidator