dsh-cooper-memory 0.1.0 → 0.1.1
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.
- package/CHANGELOG.md +24 -0
- package/README.md +15 -6
- package/docs/DETAIL.md +1 -1
- package/lib/llm.mjs +137 -41
- package/mcp.mjs +7 -2
- package/package.json +4 -2
- package/web.mjs +5 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.1 — 2026-11-19
|
|
4
|
+
|
|
5
|
+
安全修复(**0.1.0 用户建议升级**):
|
|
6
|
+
|
|
7
|
+
- 移除 `lib/llm.mjs` 里写死的 `baseURL` / `model` / `apiKeyEnv` 兜底值。0.1.0 在 profile 没配 `baseURL` 时,会把使用者的 API key 发到作者私有的网关;现在缺任何一项直接报错,`memory_probe_llm` 返回 `stage: "config"`。
|
|
8
|
+
- 删除注释里泄露网关地址、模型 id、凭据 ref 的调试笔记。
|
|
9
|
+
- `~/.dsh/.credentials.yaml` 只解析点名的那个 ref,不再把整个文件里「`sk-` 开头 / 长度 > 20」的值全部读进内存。
|
|
10
|
+
- provider 由 `agent-default-model.provider` 决定,找不到时不再回落到文件里第一个 `baseURL`。
|
|
11
|
+
|
|
12
|
+
修复:
|
|
13
|
+
|
|
14
|
+
- `web.mjs` 默认端口 7890 → 17890,与 README / DETAIL 一致。
|
|
15
|
+
- 蒸馏按钮改用 `runDistill(this)`,不再依赖 `window.event`。
|
|
16
|
+
- MCP `serverInfo.version` 从 `package.json` 读取,不再写死 0.1.0。
|
|
17
|
+
|
|
18
|
+
测试:
|
|
19
|
+
|
|
20
|
+
- 新增 `test/`(14 个用例):配置解析、凭据最小化、只向配置的 base 发请求、MCP stdio 全链路、发布包泄露扫描。`npm test` 可跑。
|
|
21
|
+
|
|
22
|
+
## 0.1.0 — 2026-11-19
|
|
23
|
+
|
|
24
|
+
首个公开版本。
|
package/README.md
CHANGED
|
@@ -66,15 +66,17 @@ dsh-cooper-memory-web # http://127.0.0.1:17890
|
|
|
66
66
|
|
|
67
67
|
## 配置 LLM(可选)
|
|
68
68
|
|
|
69
|
-
不配也能用:规则提取、知识库、检索、版本管理全部离线可用。配了才启用 `memory_distill`。
|
|
69
|
+
不配也能用:规则提取、知识库、检索、版本管理全部离线可用。配了才启用 `memory_distill` / `memory_probe_llm`。
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
**包里没有内置的默认地址、默认模型或默认凭据名**,三项都必须来自你自己的机器:
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
| 项 | 来源(按优先级) |
|
|
74
|
+
|---|---|
|
|
75
|
+
| `baseURL` | `LLM_BASE_URL` / `DEEPSEEK_BASE_URL` → profile `cordis.patch.yml` 里 `agent-default-model.provider` 指向的那个 provider 的 `baseURL` |
|
|
76
|
+
| `model` | `LLM_MODEL` → profile `cordis.patch.yml` 里 `agent-default-model.model` |
|
|
77
|
+
| `key` | `LLM_KEY_ENV` 指定的环境变量或 `~/.dsh/.credentials.yaml` 里的同名 ref → 该 provider 的 `apiKeyEnv` → `DEEPSEEK_API_KEY` |
|
|
76
78
|
|
|
77
|
-
|
|
79
|
+
缺任何一项,`memory_probe_llm` 会返回 `stage: "config"` 并列出缺什么,`memory_distill` 会直接报错——不会退回到某个写死的地址去发请求。凭据文件只解析上面点名的那个 ref,其余条目不会进内存。
|
|
78
80
|
|
|
79
81
|
## 导入工作流
|
|
80
82
|
|
|
@@ -87,6 +89,13 @@ dsh-cooper-memory import-lingshu # 真正写入
|
|
|
87
89
|
|
|
88
90
|
只导入 `knowledge` 与 `contextual` 层;`structural`(审核裁决记录)会跳过。
|
|
89
91
|
|
|
92
|
+
## 隐私边界
|
|
93
|
+
|
|
94
|
+
- 除了 `memory_distill` / `memory_probe_llm`,其余功能完全离线,进程不发起任何外部请求
|
|
95
|
+
- 蒸馏会把最近的用户发言原样发到你配置的 `baseURL`,**不做密钥打码**;别在会进记忆的对话里贴 key
|
|
96
|
+
- 出口只有 `baseURL + /chat/completions` 一个,没有遥测、没有回传
|
|
97
|
+
- 记忆与知识库以明文存在 `~/.dsh-memory/mem.db`,没有加密;SQLite 里不保存 API key
|
|
98
|
+
|
|
90
99
|
## 已知限制
|
|
91
100
|
|
|
92
101
|
- **不做向量检索**:只有 FTS5 trigram + 中文二元组,靠措辞重合召回
|
package/docs/DETAIL.md
CHANGED
|
@@ -72,7 +72,7 @@ chunk_versions → 只追加,永不删除
|
|
|
72
72
|
| `MEM_ROOT` | `~/.dsh-memory` | 数据目录 |
|
|
73
73
|
| `MEM_DB` | `$MEM_ROOT/mem.db` | 数据库路径 |
|
|
74
74
|
| `MEM_WEB_PORT` | `17890` | 浏览器界面端口 |
|
|
75
|
-
| `LLM_KEY_ENV` | `
|
|
75
|
+
| `LLM_KEY_ENV` | `DEEPSEEK_API_KEY` | 从哪个环境变量 / 凭据 ref 取 key |
|
|
76
76
|
| `LLM_MODEL` | 取 profile 配置 | 覆盖模型 |
|
|
77
77
|
| `DEEPSEEK_BASE_URL` | 取 profile 配置 | 覆盖推理网关地址 |
|
|
78
78
|
|
package/lib/llm.mjs
CHANGED
|
@@ -1,79 +1,175 @@
|
|
|
1
1
|
// lib/llm.mjs —— 给服务进程用的最小 LLM 客户端
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// baseURL
|
|
5
|
-
//
|
|
3
|
+
// 配置只从本机读取,**不内置任何开发者默认地址 / 模型 / 凭据名**:
|
|
4
|
+
// baseURL : LLM_BASE_URL | DEEPSEEK_BASE_URL > profile 里当前 provider 的 baseURL
|
|
5
|
+
// model : LLM_MODEL > profile 里 agent-default-model 的 model
|
|
6
|
+
// key : LLM_KEY_ENV 指定的 env/凭据 ref > profile 里 provider 的 apiKeyEnv > DEEPSEEK_API_KEY
|
|
6
7
|
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
8
|
+
// 三项缺任何一项都直接报错,绝不回落到某个内置网关 —— 否则使用者的凭据会被发到与
|
|
9
|
+
// 他无关的上游。provider 由 agent-default-model.provider 决定;该 provider 找不到时
|
|
10
|
+
// 不会去猜别的 provider 的地址,而是按"缺少 baseURL"处理。
|
|
11
|
+
//
|
|
12
|
+
// 两个已知坑:
|
|
13
|
+
// 1. ~/.dsh/.credentials.yaml 是 flow mapping,值可能带尾随逗号或右花括号,必须剥掉
|
|
14
|
+
// 2. 推理模型的 max_tokens 太小会被 reasoning 吃光,content 返回空串
|
|
10
15
|
|
|
11
16
|
import fs from 'node:fs';
|
|
12
17
|
import os from 'node:os';
|
|
13
18
|
import path from 'node:path';
|
|
14
19
|
|
|
15
|
-
const
|
|
16
|
-
base: 'https://api.ai8yx.com/v1',
|
|
17
|
-
model: 'deepseek-v4.1-flash-1017',
|
|
18
|
-
keyEnv: 'CT_API_KEY',
|
|
19
|
-
};
|
|
20
|
+
const FALLBACK_KEY_ENV = 'DEEPSEEK_API_KEY';
|
|
20
21
|
|
|
21
22
|
function readText(p) {
|
|
22
23
|
try { return fs.readFileSync(p, 'utf8'); } catch { return ''; }
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
function profilePatchPath() {
|
|
26
|
+
export function profilePatchPath() {
|
|
26
27
|
const profile = process.env.DSH_PROFILE || 'desktop';
|
|
27
28
|
return path.join(os.homedir(), '.dsh', 'profiles', profile, 'cordis.patch.yml');
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
const indentOf = (line) => line.match(/^ */)[0].length;
|
|
32
|
+
|
|
33
|
+
/** 取 startIdx 这一行下面、缩进更深的那一段(跳过空行与整行注释) */
|
|
34
|
+
function blockLines(lines, startIdx) {
|
|
35
|
+
const baseIndent = indentOf(lines[startIdx]);
|
|
36
|
+
const out = [];
|
|
37
|
+
for (let i = startIdx + 1; i < lines.length; i++) {
|
|
38
|
+
const line = lines[i];
|
|
39
|
+
if (!line.trim() || line.trim().startsWith('#')) { out.push(line); continue; }
|
|
40
|
+
if (indentOf(line) <= baseIndent) break;
|
|
41
|
+
out.push(line);
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 在块内取 `key: value` 的标量值(去掉成对引号) */
|
|
47
|
+
function scalar(block, key) {
|
|
48
|
+
const re = new RegExp('^\\s*' + key + ':\\s*(\\S.*?)\\s*$');
|
|
49
|
+
for (const line of block) {
|
|
50
|
+
const m = line.match(re);
|
|
51
|
+
if (m) return m[1].replace(/^['"]|['"]$/g, '');
|
|
52
|
+
}
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function firstScalar(lines, key) {
|
|
57
|
+
const re = new RegExp('^\\s*' + key + ':\\s*(\\S.*?)\\s*$');
|
|
58
|
+
for (const line of lines) {
|
|
59
|
+
const m = line.match(re);
|
|
60
|
+
if (m) return m[1].replace(/^['"]|['"]$/g, '');
|
|
61
|
+
}
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** providers: 下面的 name → 该 provider 的配置块 */
|
|
66
|
+
export function providerMap(lines) {
|
|
67
|
+
const idx = lines.findIndex((l) => /^\s*providers:\s*$/.test(l));
|
|
68
|
+
if (idx < 0) return {};
|
|
69
|
+
const inner = blockLines(lines, idx);
|
|
70
|
+
const entries = inner
|
|
71
|
+
.map((line, i) => ({ line, i }))
|
|
72
|
+
.filter(({ line }) => /^\s*[A-Za-z0-9_.-]+:\s*$/.test(line));
|
|
73
|
+
if (!entries.length) return {};
|
|
74
|
+
const baseIndent = Math.min(...entries.map(({ line }) => indentOf(line)));
|
|
75
|
+
const tops = entries.filter(({ line }) => indentOf(line) === baseIndent);
|
|
76
|
+
const map = {};
|
|
77
|
+
tops.forEach(({ line, i }, k) => {
|
|
78
|
+
const end = k + 1 < tops.length ? tops[k + 1].i : inner.length;
|
|
79
|
+
map[line.trim().replace(/:\s*$/, '')] = inner.slice(i + 1, end);
|
|
80
|
+
});
|
|
81
|
+
return map;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 从 profile patch 里取 agent-default-model 与它指向的 provider 的 baseURL / apiKeyEnv */
|
|
85
|
+
export function readProviderConfig() {
|
|
32
86
|
const yaml = readText(profilePatchPath());
|
|
33
|
-
const out = {};
|
|
87
|
+
const out = { base: '', keyEnv: '', model: '', provider: '' };
|
|
34
88
|
if (!yaml) return out;
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
if (keyM) out.keyEnv = keyM[1].replace(/['"]/g, '');
|
|
39
|
-
// agent-default-model 那段里的 model:
|
|
40
|
-
const idx = yaml.indexOf('agent-default-model');
|
|
89
|
+
const lines = yaml.split(/\r?\n/);
|
|
90
|
+
|
|
91
|
+
const idx = lines.findIndex((l) => /^\s*-?\s*id:\s*agent-default-model\s*$/.test(l));
|
|
41
92
|
if (idx >= 0) {
|
|
42
|
-
const block =
|
|
43
|
-
|
|
44
|
-
|
|
93
|
+
const block = blockLines(lines, idx);
|
|
94
|
+
out.provider = scalar(block, 'provider');
|
|
95
|
+
out.model = scalar(block, 'model');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const providers = providerMap(lines);
|
|
99
|
+
const names = Object.keys(providers);
|
|
100
|
+
const chosen = out.provider ? providers[out.provider] : null;
|
|
101
|
+
if (chosen) {
|
|
102
|
+
out.base = scalar(chosen, 'baseURL');
|
|
103
|
+
out.keyEnv = scalar(chosen, 'apiKeyEnv');
|
|
104
|
+
out.models = chosen
|
|
105
|
+
.filter((l) => /^\s*-\s*id:/.test(l))
|
|
106
|
+
.map((l) => l.replace(/^.*?-\s*id:\s*/, '').replace(/['"]/g, '').trim());
|
|
107
|
+
} else if (!names.length) {
|
|
108
|
+
// 旧版扁平写法:整个文件没有 providers 映射时,退回首个 baseURL / apiKeyEnv
|
|
109
|
+
out.base = firstScalar(lines, 'baseURL');
|
|
110
|
+
out.keyEnv = firstScalar(lines, 'apiKeyEnv');
|
|
45
111
|
}
|
|
112
|
+
// out.provider 存在但匹配不到 provider 时,base 保持为空 → 由 resolveConfig 报缺配置
|
|
46
113
|
return out;
|
|
47
114
|
}
|
|
48
115
|
|
|
49
|
-
/**
|
|
50
|
-
|
|
116
|
+
/**
|
|
117
|
+
* 凭据:只解析调用方点名要的 ref,不把整个凭据文件读进内存对象。
|
|
118
|
+
* refs 是 flow mapping,值可能带尾巴的逗号或右花括号。
|
|
119
|
+
*/
|
|
120
|
+
export function readCredentials(allow = []) {
|
|
51
121
|
const yaml = readText(path.join(os.homedir(), '.dsh', '.credentials.yaml'));
|
|
122
|
+
const want = new Set(allow.filter(Boolean));
|
|
52
123
|
const refs = {};
|
|
53
|
-
if (!yaml) return refs;
|
|
54
|
-
for (const line of yaml.split(
|
|
124
|
+
if (!yaml || !want.size) return refs;
|
|
125
|
+
for (const line of yaml.split(/\r?\n/)) {
|
|
55
126
|
const m = line.match(/^\s*([A-Za-z0-9_.-]+)\s*:\s*(\S+)\s*$/);
|
|
56
|
-
if (!m) continue;
|
|
57
|
-
|
|
58
|
-
if (/^sk-/.test(v) || v.length > 20) refs[m[1]] = v;
|
|
127
|
+
if (!m || !want.has(m[1])) continue;
|
|
128
|
+
refs[m[1]] = m[2].replace(/[,}]+$/, '');
|
|
59
129
|
}
|
|
60
130
|
return refs;
|
|
61
131
|
}
|
|
62
132
|
|
|
63
133
|
export function resolveConfig() {
|
|
64
134
|
const prov = readProviderConfig();
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
135
|
+
const keyEnv = process.env.LLM_KEY_ENV || prov.keyEnv || FALLBACK_KEY_ENV;
|
|
136
|
+
const refs = readCredentials([keyEnv, FALLBACK_KEY_ENV]);
|
|
137
|
+
|
|
138
|
+
let key = null;
|
|
139
|
+
let usedKeyEnv = keyEnv;
|
|
140
|
+
let keyFrom = 'none';
|
|
141
|
+
if (process.env[keyEnv]) { key = process.env[keyEnv]; keyFrom = 'env'; }
|
|
142
|
+
else if (refs[keyEnv]) { key = refs[keyEnv]; keyFrom = 'file'; }
|
|
143
|
+
else if (refs[FALLBACK_KEY_ENV]) { key = refs[FALLBACK_KEY_ENV]; usedKeyEnv = FALLBACK_KEY_ENV; keyFrom = 'file'; }
|
|
144
|
+
|
|
145
|
+
const base = (process.env.LLM_BASE_URL || process.env.DEEPSEEK_BASE_URL || prov.base || '').replace(/\/+$/, '');
|
|
146
|
+
const model = process.env.LLM_MODEL || prov.model || '';
|
|
147
|
+
|
|
148
|
+
const missing = [];
|
|
149
|
+
if (!key) missing.push(`凭据 ${keyEnv}(环境变量或 ~/.dsh/.credentials.yaml 里的同名 ref)`);
|
|
150
|
+
if (!base) missing.push('baseURL(profile 的 providers.<名字>.baseURL,或环境变量 LLM_BASE_URL)');
|
|
151
|
+
if (!model) missing.push('model(profile 的 agent-default-model.model,或环境变量 LLM_MODEL)');
|
|
152
|
+
|
|
153
|
+
return { key, base, model, keyEnv: usedKeyEnv, keyFrom, missing, profilePath: profilePatchPath() };
|
|
71
154
|
}
|
|
72
155
|
|
|
73
|
-
|
|
156
|
+
const configError = (cfg) => '未配置 LLM:缺少 ' + cfg.missing.join(';');
|
|
157
|
+
|
|
158
|
+
/** 探测:只回答"这个进程能不能用 LLM";返回里永远不含 key 本身 */
|
|
74
159
|
export async function probe({ timeoutMs = 30000 } = {}) {
|
|
75
160
|
const cfg = resolveConfig();
|
|
76
|
-
if (
|
|
161
|
+
if (cfg.missing.length) {
|
|
162
|
+
return {
|
|
163
|
+
ok: false,
|
|
164
|
+
stage: 'config',
|
|
165
|
+
error: configError(cfg),
|
|
166
|
+
missing: cfg.missing,
|
|
167
|
+
base: cfg.base,
|
|
168
|
+
model: cfg.model,
|
|
169
|
+
keyFrom: cfg.keyFrom,
|
|
170
|
+
profilePath: cfg.profilePath,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
77
173
|
const ctl = new AbortController();
|
|
78
174
|
const t = setTimeout(() => ctl.abort(), timeoutMs);
|
|
79
175
|
try {
|
|
@@ -111,7 +207,7 @@ export async function probe({ timeoutMs = 30000 } = {}) {
|
|
|
111
207
|
/** 一次非流式对话,返回文本 */
|
|
112
208
|
export async function chat(messages, { model, maxTokens = 3000, timeoutMs = 90000, temperature = 0 } = {}) {
|
|
113
209
|
const cfg = resolveConfig();
|
|
114
|
-
if (
|
|
210
|
+
if (cfg.missing.length) throw new Error(configError(cfg));
|
|
115
211
|
const ctl = new AbortController();
|
|
116
212
|
const t = setTimeout(() => ctl.abort(), timeoutMs);
|
|
117
213
|
try {
|
|
@@ -181,4 +277,4 @@ export async function chatWithRetry(messages, opts = {}, retry = {}) {
|
|
|
181
277
|
const err = new Error(String(lastErr?.message || lastErr));
|
|
182
278
|
err.attempts = attempts;
|
|
183
279
|
throw err;
|
|
184
|
-
}
|
|
280
|
+
}
|
package/mcp.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// mcp.mjs —— stdio MCP 服务:DSH 通过子进程直接调用,不走任何网络
|
|
3
3
|
// 协议:JSON-RPC 2.0,stdin/stdout 每行一个消息(MCP stdio transport)
|
|
4
4
|
import readline from 'node:readline';
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
5
6
|
import { openDb } from './lib/db.mjs';
|
|
6
7
|
import {
|
|
7
8
|
ingestFolder, searchChunks, getChunk, editChunk, chunkHistory,
|
|
@@ -12,7 +13,11 @@ import { runAutoExtract, recentTurns, llmDistill } from './lib/extract.mjs';
|
|
|
12
13
|
import { probe as llmProbe } from './lib/llm.mjs';
|
|
13
14
|
|
|
14
15
|
const db = openDb();
|
|
15
|
-
|
|
16
|
+
// 版本号以 package.json 为准,避免两处漂移(旧版写死 0.1.0)
|
|
17
|
+
const PKG_VERSION = (() => {
|
|
18
|
+
try { return JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version; } catch { return '0.0.0'; }
|
|
19
|
+
})();
|
|
20
|
+
const SERVER = { name: 'dsh-cooper-memory', version: PKG_VERSION };
|
|
16
21
|
const PROTOCOL = '2024-11-05';
|
|
17
22
|
|
|
18
23
|
const TOOLS = [
|
|
@@ -159,7 +164,7 @@ const TOOLS = [
|
|
|
159
164
|
},
|
|
160
165
|
{
|
|
161
166
|
name: 'memory_probe_llm',
|
|
162
|
-
description: '探测本服务进程能否调用 LLM
|
|
167
|
+
description: '探测本服务进程能否调用 LLM。区分四种情况:config=没配置(缺 baseURL/model/key)、network=出网被拦、auth=凭据不对、ok=可用。用于决定走 LLM 蒸馏还是规则提取。',
|
|
163
168
|
inputSchema: { type: 'object', properties: {} },
|
|
164
169
|
},
|
|
165
170
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cooper-memory",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Cross-session memory and a folder knowledge base for DeepSeek Harness — local SQLite, no Docker, no vector service.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,8 +29,10 @@
|
|
|
29
29
|
"docs",
|
|
30
30
|
"icon.svg",
|
|
31
31
|
"README.md",
|
|
32
|
-
"LICENSE"
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"CHANGELOG.md"
|
|
33
34
|
],
|
|
35
|
+
"scripts": { "test": "node test/run.mjs" },
|
|
34
36
|
"dsh": {
|
|
35
37
|
"bundle": { "patch": "./cordis.patch.yml" }
|
|
36
38
|
},
|
package/web.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// web.mjs —— 本地 Web
|
|
2
|
+
// web.mjs —— 本地 Web 界面(只绑 127.0.0.1,默认端口 17890,与 README 一致)
|
|
3
3
|
// 同一份 mem.db:左边目录树,中间检索,右边分块编辑 / 版本历史 / 比对 / 回滚 / 记忆管理
|
|
4
4
|
import http from 'node:http';
|
|
5
5
|
import { openDb } from './lib/db.mjs';
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import { runAutoExtract, recentTurns, llmDistill } from './lib/extract.mjs';
|
|
12
12
|
import { probe as llmProbe } from './lib/llm.mjs';
|
|
13
13
|
|
|
14
|
-
const PORT = Number(process.env.MEM_WEB_PORT ||
|
|
14
|
+
const PORT = Number(process.env.MEM_WEB_PORT || 17890);
|
|
15
15
|
const HOST = '127.0.0.1';
|
|
16
16
|
const db = openDb();
|
|
17
17
|
|
|
@@ -59,7 +59,7 @@ const HTML = `<!doctype html>
|
|
|
59
59
|
<button onclick="loadMemories('pending')">待确认记忆</button>
|
|
60
60
|
<button onclick="loadMemories('active')">全部记忆</button>
|
|
61
61
|
<button onclick="runExtract()">规则提取</button>
|
|
62
|
-
<button onclick="runDistill()">LLM 蒸馏</button>
|
|
62
|
+
<button onclick="runDistill(this)">LLM 蒸馏</button>
|
|
63
63
|
</header>
|
|
64
64
|
<div class="wrap">
|
|
65
65
|
<div class="col"><div class="meta">目录树</div><pre id="tree"></pre></div>
|
|
@@ -141,8 +141,8 @@ async function runExtract(){
|
|
|
141
141
|
alert('扫描 '+r.scannedFiles+' 个会话文件,新增 '+r.added.length+' 条待确认');
|
|
142
142
|
loadMemories('pending');
|
|
143
143
|
}
|
|
144
|
-
async function runDistill(){
|
|
145
|
-
const
|
|
144
|
+
async function runDistill(btn){
|
|
145
|
+
const old=btn.textContent; btn.textContent='蒸馏中…'; btn.disabled=true;
|
|
146
146
|
try{
|
|
147
147
|
const r=await api('/api/distill',{method:'POST',headers:{'content-type':'application/json'},body:'{}'});
|
|
148
148
|
if(r.error){alert(r.error);return}
|