@mebular/mcp 0.2.4 → 0.3.2
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/bin/mebular.mjs +606 -2
- package/package.json +5 -4
- package/src/admin.mjs +69 -47
- package/src/clients.mjs +699 -33
- package/src/config-apply.mjs +254 -6
- package/src/config-lock.mjs +167 -0
- package/src/config-schema.mjs +7 -0
- package/src/config.mjs +17 -1
- package/src/detail-maintenance.mjs +150 -0
- package/src/fleet-events.mjs +1 -1
- package/src/home-identity.mjs +13 -1
- package/src/memory-capability.mjs +5393 -0
- package/src/memory-runtime-config.mjs +86 -0
- package/src/memory-runtime-diagnostics.mjs +716 -0
- package/src/memory-runtime-supervisor.mjs +2670 -0
- package/src/memory-runtime-token.mjs +193 -0
- package/src/serve.mjs +1534 -16
- package/src/server.mjs +36 -4
- package/src/task-tools.mjs +10 -1
- package/src/version.mjs +1 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Memory Runtime sidecar 用户级配置:只读模型来源(轻量/未就绪时的展示回退)。
|
|
2
|
+
//
|
|
3
|
+
// 契约(0.3.0 immersive product contract §1.4 / §1.5 / §4.3):
|
|
4
|
+
// - 用户在「高级」只选择 model.source(heuristic/local/host/api/auto);
|
|
5
|
+
// - 配置真值在 sidecar;MCP 不再写 `<home>/memory-runtime/config.json`;
|
|
6
|
+
// - 浏览器不接触 sidecar host token / endpoint / API key / keyRef / 模型路径;
|
|
7
|
+
// - 读取不创建目录。
|
|
8
|
+
//
|
|
9
|
+
// 本模块不 import sidecar 业务实现,也不读写图/事件日志。
|
|
10
|
+
|
|
11
|
+
import { readFile } from 'node:fs/promises';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
import { resolveMemoryRuntimePaths } from './memory-runtime-supervisor.mjs';
|
|
14
|
+
|
|
15
|
+
export const MEMORY_RUNTIME_MODEL_SOURCES = Object.freeze([
|
|
16
|
+
'heuristic',
|
|
17
|
+
'local',
|
|
18
|
+
'host',
|
|
19
|
+
'api',
|
|
20
|
+
'auto',
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
export const DEFAULT_MEMORY_RUNTIME_MODEL_SOURCE = 'heuristic';
|
|
24
|
+
|
|
25
|
+
export class MemoryRuntimeConfigError extends Error {
|
|
26
|
+
constructor(code, message) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = 'MemoryRuntimeConfigError';
|
|
29
|
+
this.code = code;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isObject(value) {
|
|
34
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 归一化模型来源;未知值返回 null(调用方决定回退或报错)。 */
|
|
38
|
+
export function normalizeMemoryRuntimeModelSource(value) {
|
|
39
|
+
if (typeof value !== 'string') return null;
|
|
40
|
+
const source = value.trim().toLowerCase();
|
|
41
|
+
return MEMORY_RUNTIME_MODEL_SOURCES.includes(source) ? source : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** sidecar 配置路径(与 supervisor 使用同一 home/data-dir 解析规则)。 */
|
|
45
|
+
export function memoryRuntimeConfigPath({ home, env = process.env } = {}) {
|
|
46
|
+
const paths = resolveMemoryRuntimePaths({ home, env });
|
|
47
|
+
return join(paths.dataDir, 'config.json');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function readRawConfig(path) {
|
|
51
|
+
let text;
|
|
52
|
+
try {
|
|
53
|
+
text = await readFile(path, 'utf-8');
|
|
54
|
+
} catch (error) {
|
|
55
|
+
if (error?.code === 'ENOENT') return { exists: false, raw: {} };
|
|
56
|
+
throw new MemoryRuntimeConfigError('config_unreadable', '无法读取记忆运行时配置');
|
|
57
|
+
}
|
|
58
|
+
let parsed;
|
|
59
|
+
try {
|
|
60
|
+
parsed = JSON.parse(text);
|
|
61
|
+
} catch {
|
|
62
|
+
throw new MemoryRuntimeConfigError('config_invalid', '记忆运行时配置不是合法 JSON');
|
|
63
|
+
}
|
|
64
|
+
if (!isObject(parsed)) {
|
|
65
|
+
throw new MemoryRuntimeConfigError('config_invalid', '记忆运行时配置必须是 JSON 对象');
|
|
66
|
+
}
|
|
67
|
+
return { exists: true, raw: parsed };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 读取当前模型来源。返回给浏览器的最小视图:
|
|
72
|
+
* 只有 source / 默认值 / 合法选项 / 是否存在,不返回配置正文或路径。
|
|
73
|
+
*/
|
|
74
|
+
export async function readMemoryRuntimeModelSource({ home, env = process.env } = {}) {
|
|
75
|
+
const path = memoryRuntimeConfigPath({ home, env });
|
|
76
|
+
const { exists, raw } = await readRawConfig(path);
|
|
77
|
+
const model = isObject(raw.model) ? raw.model : {};
|
|
78
|
+
const normalized = normalizeMemoryRuntimeModelSource(model.source);
|
|
79
|
+
return {
|
|
80
|
+
source: normalized ?? DEFAULT_MEMORY_RUNTIME_MODEL_SOURCE,
|
|
81
|
+
defaultSource: DEFAULT_MEMORY_RUNTIME_MODEL_SOURCE,
|
|
82
|
+
values: [...MEMORY_RUNTIME_MODEL_SOURCES],
|
|
83
|
+
exists,
|
|
84
|
+
...(model.source !== undefined && normalized === null ? { warnings: ['invalid_model_source'] } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|