@wipcomputer/memory-crystal 0.7.34-alpha.3 → 0.7.34-alpha.4

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 (97) hide show
  1. package/package.json +7 -4
  2. package/dist/chunk-25LXQJ4Z.js +0 -110
  3. package/dist/chunk-2DRXIRQW.js +0 -97
  4. package/dist/chunk-2GBYLMEF.js +0 -1385
  5. package/dist/chunk-2ZNH5F6E.js +0 -1281
  6. package/dist/chunk-3G3SFYYI.js +0 -288
  7. package/dist/chunk-3RG5ZIWI.js +0 -10
  8. package/dist/chunk-3S6TI23B.js +0 -97
  9. package/dist/chunk-3VFIJYS4.js +0 -818
  10. package/dist/chunk-437F27T6.js +0 -97
  11. package/dist/chunk-52QE3YI3.js +0 -1169
  12. package/dist/chunk-57RP3DIN.js +0 -1205
  13. package/dist/chunk-5HSZ4W2P.js +0 -62
  14. package/dist/chunk-5I7GMRDN.js +0 -146
  15. package/dist/chunk-645IPXW3.js +0 -290
  16. package/dist/chunk-7A7ELD4C.js +0 -1205
  17. package/dist/chunk-7FYY4GZM.js +0 -1205
  18. package/dist/chunk-7IUE7ODU.js +0 -254
  19. package/dist/chunk-7RMLKZIS.js +0 -108
  20. package/dist/chunk-AA3OPP4Z.js +0 -432
  21. package/dist/chunk-AEWLSYPH.js +0 -72
  22. package/dist/chunk-ASSZDR6I.js +0 -108
  23. package/dist/chunk-AYRJVWUC.js +0 -1205
  24. package/dist/chunk-CCYI5O3D.js +0 -148
  25. package/dist/chunk-CGIDSAJB.js +0 -288
  26. package/dist/chunk-D3I3ZSE2.js +0 -411
  27. package/dist/chunk-D3MACYZ4.js +0 -108
  28. package/dist/chunk-DACSKLY6.js +0 -219
  29. package/dist/chunk-DFQ72B7M.js +0 -248
  30. package/dist/chunk-DW5B4BL7.js +0 -108
  31. package/dist/chunk-EKSACBTJ.js +0 -1070
  32. package/dist/chunk-EXEZZADG.js +0 -248
  33. package/dist/chunk-F3Y7EL7K.js +0 -83
  34. package/dist/chunk-FBQWSDPC.js +0 -1328
  35. package/dist/chunk-FHRZNOMW.js +0 -1205
  36. package/dist/chunk-IM7N24MT.js +0 -129
  37. package/dist/chunk-IPNYIXFK.js +0 -1178
  38. package/dist/chunk-J7MRSZIO.js +0 -167
  39. package/dist/chunk-JITKI2OI.js +0 -106
  40. package/dist/chunk-JWZXYVET.js +0 -1068
  41. package/dist/chunk-KCQUXVYT.js +0 -108
  42. package/dist/chunk-KOQ43OX6.js +0 -1281
  43. package/dist/chunk-KYVWO6ZM.js +0 -1069
  44. package/dist/chunk-L3VHARQH.js +0 -413
  45. package/dist/chunk-LBWDS6BE.js +0 -288
  46. package/dist/chunk-LOVAHSQV.js +0 -411
  47. package/dist/chunk-LQOYCAGG.js +0 -446
  48. package/dist/chunk-LWAIPJ2W.js +0 -146
  49. package/dist/chunk-M5DHKW7M.js +0 -127
  50. package/dist/chunk-MBKCIJHM.js +0 -1328
  51. package/dist/chunk-MK42FMEG.js +0 -147
  52. package/dist/chunk-MOBMYHKL.js +0 -1205
  53. package/dist/chunk-MPLTNMRG.js +0 -67
  54. package/dist/chunk-NIJCVN3O.js +0 -147
  55. package/dist/chunk-NX647OM3.js +0 -310
  56. package/dist/chunk-NZCFSZQ7.js +0 -1205
  57. package/dist/chunk-O2UITJGH.js +0 -465
  58. package/dist/chunk-OCRA44AZ.js +0 -108
  59. package/dist/chunk-P3KJR66H.js +0 -117
  60. package/dist/chunk-PEK6JH65.js +0 -432
  61. package/dist/chunk-PJ6FFKEX.js +0 -77
  62. package/dist/chunk-PLUBBZYR.js +0 -800
  63. package/dist/chunk-PNKVD2UK.js +0 -26
  64. package/dist/chunk-PSQZURHO.js +0 -229
  65. package/dist/chunk-SGL6ISBJ.js +0 -1061
  66. package/dist/chunk-SJABZZT5.js +0 -97
  67. package/dist/chunk-TD3P3K32.js +0 -1199
  68. package/dist/chunk-TMDZJJKV.js +0 -288
  69. package/dist/chunk-UNHVZB5G.js +0 -411
  70. package/dist/chunk-VAFTWSTE.js +0 -1061
  71. package/dist/chunk-VNFXFQBB.js +0 -217
  72. package/dist/chunk-X3GVFKSJ.js +0 -1205
  73. package/dist/chunk-XZ3S56RQ.js +0 -1061
  74. package/dist/chunk-Y72C7F6O.js +0 -148
  75. package/dist/chunk-YLICP577.js +0 -1205
  76. package/dist/chunk-YX6AXLVK.js +0 -159
  77. package/dist/chunk-ZCQYHTNU.js +0 -146
  78. package/dist/cloud-crystal.js +0 -6
  79. package/dist/dev-update-SZ2Z4WCQ.js +0 -6
  80. package/dist/llm-XXLYPIOF.js +0 -16
  81. package/dist/mlx-setup-XKU67WCT.js +0 -289
  82. package/dist/search-pipeline-4K4OJSSS.js +0 -255
  83. package/dist/search-pipeline-4PRS6LI7.js +0 -280
  84. package/dist/search-pipeline-7UJMXPLO.js +0 -280
  85. package/dist/search-pipeline-CBV25NX7.js +0 -99
  86. package/dist/search-pipeline-DQTRLGBH.js +0 -74
  87. package/dist/search-pipeline-HNG37REH.js +0 -282
  88. package/dist/search-pipeline-IZFPLBUB.js +0 -280
  89. package/dist/search-pipeline-MID6F26Q.js +0 -73
  90. package/dist/search-pipeline-N52JZFNN.js +0 -282
  91. package/dist/search-pipeline-OPB2PRQQ.js +0 -280
  92. package/dist/search-pipeline-VXTE5HAD.js +0 -262
  93. package/dist/search-pipeline-XHFKADRG.js +0 -73
  94. package/dist/worker-demo.js +0 -186
  95. package/dist/worker-mcp.js +0 -404
  96. package/scripts/crystal-capture 2.sh +0 -29
  97. package/scripts/deploy-cloud 2.sh +0 -153
@@ -1,167 +0,0 @@
1
- // src/cloud-crystal.ts
2
- async function embed(text, apiKey) {
3
- const resp = await fetch("https://api.openai.com/v1/embeddings", {
4
- method: "POST",
5
- headers: {
6
- "Authorization": `Bearer ${apiKey}`,
7
- "Content-Type": "application/json"
8
- },
9
- body: JSON.stringify({
10
- model: "text-embedding-3-small",
11
- input: text,
12
- dimensions: 1024
13
- })
14
- });
15
- if (!resp.ok) {
16
- const err = await resp.text();
17
- throw new Error(`Embedding failed: ${resp.status} ${err}`);
18
- }
19
- const data = await resp.json();
20
- return data.data[0].embedding;
21
- }
22
- var CloudCrystal = class {
23
- constructor(db, vectorize, apiKey) {
24
- this.db = db;
25
- this.vectorize = vectorize;
26
- this.apiKey = apiKey;
27
- }
28
- // Hybrid search: BM25 (FTS5) + vector (Vectorize) + RRF fusion + recency
29
- async search(userId, query, limit = 5, agentId) {
30
- const agentFilter = agentId ? "AND c.agent_id = ?" : "";
31
- const bm25Params = [userId, query];
32
- if (agentId) bm25Params.push(agentId);
33
- const bm25Results = await this.db.prepare(`
34
- SELECT c.id, c.text, c.role, c.agent_id, c.created_at, c.source_type,
35
- rank AS bm25_score
36
- FROM chunks_fts f
37
- JOIN chunks c ON c.id = f.rowid
38
- WHERE f.text MATCH ? AND c.user_id = ? ${agentFilter}
39
- ORDER BY rank
40
- LIMIT ?
41
- `).bind(query, userId, ...agentId ? [agentId] : [], limit * 3).all();
42
- const queryVec = await embed(query, this.apiKey);
43
- const vecResults = await this.vectorize.query(queryVec, {
44
- topK: limit * 3,
45
- filter: { user_id: userId, ...agentId ? { agent_id: agentId } : {} },
46
- returnMetadata: "all"
47
- });
48
- const k = 60;
49
- const scores = /* @__PURE__ */ new Map();
50
- const bm25Rows = bm25Results.results || [];
51
- for (let i = 0; i < bm25Rows.length; i++) {
52
- const id = bm25Rows[i].id;
53
- const existing = scores.get(id) || { score: 0, data: bm25Rows[i] };
54
- existing.score += 1 / (k + i + 1);
55
- scores.set(id, existing);
56
- }
57
- for (let i = 0; i < vecResults.matches.length; i++) {
58
- const match = vecResults.matches[i];
59
- const id = parseInt(match.id, 10);
60
- const existing = scores.get(id) || { score: 0 };
61
- existing.score += 1 / (k + i + 1);
62
- scores.set(id, existing);
63
- }
64
- const now = Date.now();
65
- for (const [id, entry] of scores) {
66
- if (entry.data?.created_at) {
67
- const age = now - new Date(entry.data.created_at).getTime();
68
- const dayAge = age / (1e3 * 60 * 60 * 24);
69
- const recencyBoost = Math.max(0, 1 - dayAge / 90) * 0.15;
70
- entry.score += recencyBoost;
71
- }
72
- }
73
- const ranked = [...scores.entries()].sort((a, b) => b[1].score - a[1].score).slice(0, limit);
74
- const needFetch = ranked.filter(([_, v]) => !v.data).map(([id]) => id);
75
- if (needFetch.length > 0) {
76
- const placeholders = needFetch.map(() => "?").join(",");
77
- const rows = await this.db.prepare(
78
- `SELECT id, text, role, agent_id, created_at, source_type FROM chunks WHERE id IN (${placeholders})`
79
- ).bind(...needFetch).all();
80
- const rowMap = new Map(rows.results.map((r) => [r.id, r]));
81
- for (const [id, entry] of scores) {
82
- if (!entry.data && rowMap.has(id)) {
83
- entry.data = rowMap.get(id);
84
- }
85
- }
86
- }
87
- return ranked.map(([id, entry]) => ({
88
- id,
89
- text: entry.data?.text || "",
90
- score: entry.score,
91
- role: entry.data?.role || "unknown",
92
- agent_id: entry.data?.agent_id || "unknown",
93
- created_at: entry.data?.created_at || "",
94
- source_type: entry.data?.source_type || "unknown"
95
- }));
96
- }
97
- // Ingest chunks (conversation turns)
98
- async ingest(userId, chunks) {
99
- let ingested = 0;
100
- for (const chunk of chunks) {
101
- const result = await this.db.prepare(`
102
- INSERT INTO chunks (user_id, text, role, agent_id, source_type, token_count)
103
- VALUES (?, ?, ?, ?, ?, ?)
104
- `).bind(
105
- userId,
106
- chunk.text,
107
- chunk.role,
108
- chunk.agent_id,
109
- chunk.source_type || "chatgpt",
110
- Math.ceil(chunk.text.length / 4)
111
- // rough token estimate
112
- ).run();
113
- const chunkId = result.meta.last_row_id;
114
- const vec = await embed(chunk.text, this.apiKey);
115
- await this.vectorize.upsert([{
116
- id: String(chunkId),
117
- values: vec,
118
- metadata: {
119
- user_id: userId,
120
- agent_id: chunk.agent_id,
121
- role: chunk.role,
122
- source_type: chunk.source_type || "chatgpt"
123
- }
124
- }]);
125
- ingested++;
126
- }
127
- return ingested;
128
- }
129
- // Remember a fact/preference/event
130
- async remember(userId, text, category = "fact") {
131
- const result = await this.db.prepare(`
132
- INSERT INTO memories (user_id, text, category) VALUES (?, ?, ?)
133
- `).bind(userId, text, category).run();
134
- return result.meta.last_row_id;
135
- }
136
- // Forget (deprecate) a memory
137
- async forget(userId, memoryId) {
138
- const result = await this.db.prepare(`
139
- UPDATE memories SET status = 'deprecated', updated_at = datetime('now')
140
- WHERE id = ? AND user_id = ? AND status = 'active'
141
- `).bind(memoryId, userId).run();
142
- return (result.meta.changes || 0) > 0;
143
- }
144
- // Status
145
- async status(userId) {
146
- const chunkCount = await this.db.prepare(
147
- "SELECT COUNT(*) as count FROM chunks WHERE user_id = ?"
148
- ).bind(userId).first();
149
- const memoryCount = await this.db.prepare(
150
- "SELECT COUNT(*) as count FROM memories WHERE user_id = ? AND status = ?"
151
- ).bind(userId, "active").first();
152
- const agents = await this.db.prepare(
153
- "SELECT DISTINCT agent_id FROM chunks WHERE user_id = ?"
154
- ).bind(userId).all();
155
- return {
156
- chunks: chunkCount?.count || 0,
157
- memories: memoryCount?.count || 0,
158
- agents: (agents.results || []).map((r) => r.agent_id),
159
- tier: "convenience"
160
- // Tier 2 users only
161
- };
162
- }
163
- };
164
-
165
- export {
166
- CloudCrystal
167
- };
@@ -1,106 +0,0 @@
1
- // src/crypto.ts
2
- import { readFileSync, existsSync } from "fs";
3
- import { createCipheriv, createDecipheriv, createHmac, randomBytes, hkdfSync } from "crypto";
4
- import { join } from "path";
5
- import { createHash } from "crypto";
6
- var HOME = process.env.HOME || "";
7
- var KEY_PATH = process.env.CRYSTAL_RELAY_KEY_PATH || join(HOME, ".openclaw", "secrets", "crystal-relay-key");
8
- function loadRelayKey() {
9
- if (!existsSync(KEY_PATH)) {
10
- throw new Error(
11
- `Relay key not found at ${KEY_PATH}
12
- Generate one: openssl rand -base64 32 > ${KEY_PATH} && chmod 600 ${KEY_PATH}
13
- Copy the same key to all trusted machines.`
14
- );
15
- }
16
- const raw = readFileSync(KEY_PATH, "utf-8").trim();
17
- const key = Buffer.from(raw, "base64");
18
- if (key.length !== 32) {
19
- throw new Error(`Relay key must be 32 bytes (256 bits). Got ${key.length} bytes. Regenerate with: openssl rand -base64 32`);
20
- }
21
- return key;
22
- }
23
- function deriveSigningKey(masterKey) {
24
- return Buffer.from(hkdfSync("sha256", masterKey, "", "crystal-relay-sign", 32));
25
- }
26
- function encrypt(plaintext, masterKey) {
27
- const nonce = randomBytes(12);
28
- const cipher = createCipheriv("aes-256-gcm", masterKey, nonce);
29
- const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
30
- const tag = cipher.getAuthTag();
31
- const signingKey = deriveSigningKey(masterKey);
32
- const hmacData = Buffer.concat([nonce, ciphertext, tag]);
33
- const hmac = createHmac("sha256", signingKey).update(hmacData).digest("hex");
34
- return {
35
- v: 1,
36
- nonce: nonce.toString("base64"),
37
- ciphertext: ciphertext.toString("base64"),
38
- tag: tag.toString("base64"),
39
- hmac
40
- };
41
- }
42
- function decrypt(payload, masterKey) {
43
- if (payload.v !== 1) {
44
- throw new Error(`Unknown payload version: ${payload.v}`);
45
- }
46
- const nonce = Buffer.from(payload.nonce, "base64");
47
- const ciphertext = Buffer.from(payload.ciphertext, "base64");
48
- const tag = Buffer.from(payload.tag, "base64");
49
- const signingKey = deriveSigningKey(masterKey);
50
- const hmacData = Buffer.concat([nonce, ciphertext, tag]);
51
- const expectedHmac = createHmac("sha256", signingKey).update(hmacData).digest("hex");
52
- if (payload.hmac !== expectedHmac) {
53
- throw new Error("HMAC verification failed \u2014 blob rejected (tampered or wrong key)");
54
- }
55
- const decipher = createDecipheriv("aes-256-gcm", masterKey, nonce);
56
- decipher.setAuthTag(tag);
57
- return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
58
- }
59
- function encryptJSON(data, masterKey) {
60
- const plaintext = Buffer.from(JSON.stringify(data), "utf-8");
61
- return encrypt(plaintext, masterKey);
62
- }
63
- function decryptJSON(payload, masterKey) {
64
- const plaintext = decrypt(payload, masterKey);
65
- return JSON.parse(plaintext.toString("utf-8"));
66
- }
67
- function encryptFile(filePath, masterKey) {
68
- const plaintext = readFileSync(filePath);
69
- return encrypt(plaintext, masterKey);
70
- }
71
- var RELAY_KEY_PATH = KEY_PATH;
72
- function generateRelayKey() {
73
- return randomBytes(32);
74
- }
75
- function encodePairingString(key) {
76
- if (key.length !== 32) throw new Error("Key must be 32 bytes");
77
- return `mc1:${key.toString("base64")}`;
78
- }
79
- function decodePairingString(str) {
80
- const trimmed = str.trim();
81
- if (!trimmed.startsWith("mc1:")) {
82
- throw new Error("Invalid pairing string (expected mc1: prefix)");
83
- }
84
- const key = Buffer.from(trimmed.slice(4), "base64");
85
- if (key.length !== 32) {
86
- throw new Error(`Invalid key length: expected 32 bytes, got ${key.length}`);
87
- }
88
- return key;
89
- }
90
- function hashBuffer(data) {
91
- return createHash("sha256").update(data).digest("hex");
92
- }
93
-
94
- export {
95
- loadRelayKey,
96
- encrypt,
97
- decrypt,
98
- encryptJSON,
99
- decryptJSON,
100
- encryptFile,
101
- RELAY_KEY_PATH,
102
- generateRelayKey,
103
- encodePairingString,
104
- decodePairingString,
105
- hashBuffer
106
- };