@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,148 +0,0 @@
1
- // src/summarize.ts
2
- import { writeFileSync, existsSync, mkdirSync } from "fs";
3
- import { join } from "path";
4
- import https from "https";
5
- import http from "http";
6
- var SUMMARY_MODE = process.env.CRYSTAL_SUMMARY_MODE || "simple";
7
- var SUMMARY_PROVIDER = process.env.CRYSTAL_SUMMARY_PROVIDER || "openai";
8
- var SUMMARY_MODEL = process.env.CRYSTAL_SUMMARY_MODEL || "gpt-4o-mini";
9
- function generateSimpleSummary(messages) {
10
- const firstUser = messages.find((m) => m.role === "user");
11
- const title = firstUser ? firstUser.text.slice(0, 80).replace(/\n/g, " ").trim() : "Untitled Session";
12
- const slug = title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 50);
13
- const preview = messages.slice(0, 10).map((m) => {
14
- const roleLabel = m.role === "user" ? "User" : "Assistant";
15
- const snippet = m.text.slice(0, 200).replace(/\n/g, " ").trim();
16
- return `**${roleLabel}:** ${snippet}${m.text.length > 200 ? "..." : ""}`;
17
- }).join("\n\n");
18
- const date = messages[0]?.timestamp?.slice(0, 10) || (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
19
- return {
20
- title,
21
- slug,
22
- summary: preview,
23
- topics: [],
24
- messageCount: messages.length,
25
- date
26
- };
27
- }
28
- async function generateLlmSummary(messages) {
29
- const condensed = messages.slice(0, 30).map((m) => {
30
- const roleLabel = m.role === "user" ? "User" : "Assistant";
31
- const text = m.text.slice(0, 500);
32
- return `${roleLabel}: ${text}`;
33
- }).join("\n\n");
34
- const prompt = `Summarize this conversation. Return JSON only, no markdown fences.
35
-
36
- Format:
37
- {"title": "short title", "slug": "url-safe-slug", "summary": "2-4 sentences", "topics": ["topic1", "topic2"]}
38
-
39
- Conversation:
40
- ${condensed}`;
41
- const apiKey = process.env.OPENAI_API_KEY;
42
- if (!apiKey) {
43
- return generateSimpleSummary(messages);
44
- }
45
- try {
46
- const body = JSON.stringify({
47
- model: SUMMARY_MODEL,
48
- messages: [{ role: "user", content: prompt }],
49
- temperature: 0.3,
50
- max_tokens: 300
51
- });
52
- const result = await httpPost("https://api.openai.com/v1/chat/completions", body, {
53
- "Authorization": `Bearer ${apiKey}`,
54
- "Content-Type": "application/json"
55
- });
56
- const parsed = JSON.parse(result);
57
- const content = parsed.choices?.[0]?.message?.content || "";
58
- const jsonStr = content.replace(/```json?\n?/g, "").replace(/```/g, "").trim();
59
- const data = JSON.parse(jsonStr);
60
- const date = messages[0]?.timestamp?.slice(0, 10) || (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
61
- return {
62
- title: data.title || "Untitled",
63
- slug: (data.slug || "untitled").slice(0, 50),
64
- summary: data.summary || "",
65
- topics: data.topics || [],
66
- messageCount: messages.length,
67
- date
68
- };
69
- } catch {
70
- return generateSimpleSummary(messages);
71
- }
72
- }
73
- function httpPost(url, body, headers) {
74
- return new Promise((resolve, reject) => {
75
- const parsed = new URL(url);
76
- const client = parsed.protocol === "https:" ? https : http;
77
- const req = client.request({
78
- hostname: parsed.hostname,
79
- port: parsed.port,
80
- path: parsed.pathname + parsed.search,
81
- method: "POST",
82
- headers: { ...headers, "Content-Length": Buffer.byteLength(body) },
83
- timeout: 3e4
84
- }, (res) => {
85
- let data = "";
86
- res.on("data", (chunk) => {
87
- data += chunk;
88
- });
89
- res.on("end", () => {
90
- if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
91
- resolve(data);
92
- } else {
93
- reject(new Error(`HTTP ${res.statusCode}: ${data.slice(0, 200)}`));
94
- }
95
- });
96
- });
97
- req.on("error", reject);
98
- req.on("timeout", () => {
99
- req.destroy();
100
- reject(new Error("Request timeout"));
101
- });
102
- req.write(body);
103
- req.end();
104
- });
105
- }
106
- async function generateSessionSummary(messages) {
107
- if (SUMMARY_MODE === "llm") {
108
- return generateLlmSummary(messages);
109
- }
110
- return generateSimpleSummary(messages);
111
- }
112
- function formatSummaryMarkdown(summary, sessionId) {
113
- const lines = [];
114
- lines.push(`# ${summary.title}`);
115
- lines.push("");
116
- lines.push(`**Session:** ${sessionId} **Date:** ${summary.date} **Messages:** ${summary.messageCount}`);
117
- lines.push("");
118
- lines.push("## Summary");
119
- lines.push("");
120
- lines.push(summary.summary);
121
- if (summary.topics.length > 0) {
122
- lines.push("");
123
- lines.push("## Key Topics");
124
- lines.push("");
125
- for (const topic of summary.topics) {
126
- lines.push(`- ${topic}`);
127
- }
128
- }
129
- lines.push("");
130
- return lines.join("\n");
131
- }
132
- function writeSummaryFile(sessionsDir, summary, agentId, sessionId) {
133
- if (!existsSync(sessionsDir)) mkdirSync(sessionsDir, { recursive: true });
134
- const now = /* @__PURE__ */ new Date();
135
- const dateStr = now.toISOString().slice(0, 10);
136
- const timeStr = now.toISOString().slice(11, 19).replace(/:/g, "-");
137
- const filename = `${dateStr}--${timeStr}--${agentId}--${summary.slug}.md`;
138
- const filepath = join(sessionsDir, filename);
139
- const content = formatSummaryMarkdown(summary, sessionId);
140
- writeFileSync(filepath, content);
141
- return filepath;
142
- }
143
-
144
- export {
145
- generateSessionSummary,
146
- formatSummaryMarkdown,
147
- writeSummaryFile
148
- };