@mebular/mcp 0.2.4 → 0.3.0
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 +401 -1
- package/package.json +4 -3
- package/src/admin.mjs +60 -44
- package/src/clients.mjs +699 -33
- package/src/config-schema.mjs +7 -0
- package/src/detail-maintenance.mjs +134 -0
- package/src/fleet-events.mjs +1 -1
- package/src/memory-capability.mjs +4734 -0
- package/src/memory-runtime-config.mjs +86 -0
- package/src/memory-runtime-supervisor.mjs +1844 -0
- package/src/memory-runtime-token.mjs +193 -0
- package/src/serve.mjs +817 -6
- package/src/server.mjs +19 -0
- package/src/task-tools.mjs +10 -1
- package/src/version.mjs +1 -1
package/src/config-schema.mjs
CHANGED
|
@@ -587,6 +587,13 @@ export const CONFIG_SCHEMA = [
|
|
|
587
587
|
effective: (s) => (s?.mcp?.tls === true ? 'on' : 'off'),
|
|
588
588
|
reason: (ctx) => (ctx.settings?.mcp?.tls ? '已生效:TLS 实际启用' : '未启用:明文 HTTP(仅回环安全)'),
|
|
589
589
|
},
|
|
590
|
+
// ------------------------------------------------------------------ Memory Runtime(device-local;0.3 默认关闭 = 轻量 MCP)
|
|
591
|
+
// 只承载 MCP 侧生命周期开关;sidecar 自己的设置放 <home>/memory-runtime/config.json。
|
|
592
|
+
// 热生效(requiresRestart:false):切换会动态生成/撤销 capability token。
|
|
593
|
+
{ path: 'memoryRuntime.enabled', read: (c) => c?.memoryRuntime?.enabled === true, kind: 'bool', exposure: 'internal', writable: true, requiresRestart: false, default: false, ui: { group: '记忆运行时', type: 'bool', label: '启用记忆运行时(sidecar)' }, effective: (s) => s?.memoryRuntime?.enabled === true },
|
|
594
|
+
{ path: 'memoryRuntime.command', read: (c) => c?.memoryRuntime?.command ?? null, kind: 'string', spec: { nonEmpty: true, empty: 'delete' }, exposure: 'internal', writable: true, requiresRestart: false, default: null, ui: { group: '记忆运行时', type: 'text', label: 'sidecar 可执行文件' }, effective: (s) => s?.memoryRuntime?.command ?? null },
|
|
595
|
+
{ path: 'memoryRuntime.startTimeoutMs', read: (c) => c?.memoryRuntime?.startTimeoutMs ?? 5000, kind: 'int', spec: { min: 100, nullable: true }, exposure: 'internal', writable: true, requiresRestart: false, default: 5000, ui: { group: '记忆运行时', type: 'number', label: 'sidecar 启动超时(ms)' }, effective: (s) => s?.memoryRuntime?.startTimeoutMs ?? 5000 },
|
|
596
|
+
|
|
590
597
|
// ------------------------------------------------------------------ internal(GUI 不渲染;API 仍可写)
|
|
591
598
|
{ path: 'network.libp2p.relayUnlimited', read: (c) => c?.network?.libp2p?.relayUnlimited === true, kind: 'bool', exposure: 'internal', writable: true, requiresRestart: true, default: false, ui: { type: 'bool', label: 'Relay 不做限额' } },
|
|
592
599
|
{ path: 'network.libp2p.relayServer', kind: 'bool', exposure: 'internal', requiresRestart: true, default: false, ui: { type: 'bool', label: '本机充当 relay 服务端' } },
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// 0.3 详情保留维护:MCP daemon 启动后扫描过期 DetailRecord。
|
|
2
|
+
//
|
|
3
|
+
// - 启动即跑一次,此后每 24h 一次;timer.unref,不拖住宿主退出。
|
|
4
|
+
// - 只调用 MemoryService.pruneExpiredDetails():复用图 + 事件日志,不做第二套存储/同步。
|
|
5
|
+
// - 失败只记录到 status 并打一行日志;绝不阻断 MCP READY 或后续定时任务。
|
|
6
|
+
// - 同一进程内热切换 service 时复用同一个 timer/状态;当天已成功跑过则跳过重复扫描。
|
|
7
|
+
|
|
8
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
9
|
+
|
|
10
|
+
function dayKey(at) {
|
|
11
|
+
const date = new Date(at);
|
|
12
|
+
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function errorCode(error) {
|
|
16
|
+
return typeof error?.code === 'string' && error.code.length > 0 ? error.code : 'ERROR';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {{
|
|
21
|
+
* getService: () => ({ pruneExpiredDetails?: (options?: { now?: number }) => Promise<string[]> } | null),
|
|
22
|
+
* intervalMs?: number,
|
|
23
|
+
* now?: () => number,
|
|
24
|
+
* setIntervalFn?: typeof setInterval,
|
|
25
|
+
* clearIntervalFn?: typeof clearInterval,
|
|
26
|
+
* logger?: Pick<Console, 'error'>,
|
|
27
|
+
* }} options
|
|
28
|
+
*/
|
|
29
|
+
export function createDetailMaintenance({
|
|
30
|
+
getService,
|
|
31
|
+
intervalMs = DAY_MS,
|
|
32
|
+
now = Date.now,
|
|
33
|
+
setIntervalFn = setInterval,
|
|
34
|
+
clearIntervalFn = clearInterval,
|
|
35
|
+
logger = console,
|
|
36
|
+
} = {}) {
|
|
37
|
+
let timer = null;
|
|
38
|
+
let stopped = false;
|
|
39
|
+
let activeRun = null;
|
|
40
|
+
let lastAttemptAt = null;
|
|
41
|
+
let lastSuccessAt = null;
|
|
42
|
+
let lastSuccessDay = null;
|
|
43
|
+
let lastResult = null;
|
|
44
|
+
let lastError = null;
|
|
45
|
+
|
|
46
|
+
const status = () => ({
|
|
47
|
+
running: timer !== null,
|
|
48
|
+
intervalMs,
|
|
49
|
+
lastAttemptAt,
|
|
50
|
+
lastSuccessAt,
|
|
51
|
+
lastSuccessDay,
|
|
52
|
+
lastResult,
|
|
53
|
+
lastError,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const serviceReady = () => {
|
|
57
|
+
const service = typeof getService === 'function' ? getService() : null;
|
|
58
|
+
return Boolean(service) && typeof service.pruneExpiredDetails === 'function';
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const runOnce = ({ reason = 'startup', force = false } = {}) => {
|
|
62
|
+
if (stopped) return Promise.resolve(null);
|
|
63
|
+
if (activeRun) return activeRun;
|
|
64
|
+
if (!serviceReady()) return Promise.resolve(null);
|
|
65
|
+
const service = getService();
|
|
66
|
+
const at = now();
|
|
67
|
+
const day = dayKey(at);
|
|
68
|
+
if (!force && lastSuccessDay === day) {
|
|
69
|
+
return Promise.resolve({ skipped: true, reason: 'already_ran_today', day });
|
|
70
|
+
}
|
|
71
|
+
lastAttemptAt = at;
|
|
72
|
+
activeRun = (async () => {
|
|
73
|
+
try {
|
|
74
|
+
const pruned = await service.pruneExpiredDetails({ now: at });
|
|
75
|
+
lastSuccessAt = at;
|
|
76
|
+
lastSuccessDay = day;
|
|
77
|
+
lastResult = {
|
|
78
|
+
reason,
|
|
79
|
+
pruned: Array.isArray(pruned) ? pruned.length : 0,
|
|
80
|
+
at,
|
|
81
|
+
};
|
|
82
|
+
lastError = null;
|
|
83
|
+
return lastResult;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
lastError = {
|
|
86
|
+
reason,
|
|
87
|
+
code: errorCode(error),
|
|
88
|
+
message: String(error?.message ?? error),
|
|
89
|
+
at,
|
|
90
|
+
};
|
|
91
|
+
logger?.error?.(`DETAIL_MAINTENANCE_FAILED ${lastError.code} ${lastError.message}`);
|
|
92
|
+
return lastError;
|
|
93
|
+
} finally {
|
|
94
|
+
activeRun = null;
|
|
95
|
+
}
|
|
96
|
+
})();
|
|
97
|
+
return activeRun;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const start = () => {
|
|
101
|
+
if (stopped) return status();
|
|
102
|
+
if (timer === null && serviceReady()) {
|
|
103
|
+
timer = setIntervalFn(() => {
|
|
104
|
+
void runOnce({ reason: 'interval' });
|
|
105
|
+
}, intervalMs);
|
|
106
|
+
timer?.unref?.();
|
|
107
|
+
}
|
|
108
|
+
// 启动/热切换都尝试一次;当天已成功跑过时会直接跳过。
|
|
109
|
+
void runOnce({ reason: timer === null ? 'service_pending' : 'startup' });
|
|
110
|
+
return status();
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const stop = () => {
|
|
114
|
+
stopped = true;
|
|
115
|
+
if (timer !== null) {
|
|
116
|
+
clearIntervalFn(timer);
|
|
117
|
+
timer = null;
|
|
118
|
+
}
|
|
119
|
+
return status();
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const idle = () => activeRun ?? Promise.resolve(null);
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
start,
|
|
126
|
+
stop,
|
|
127
|
+
runOnce,
|
|
128
|
+
idle,
|
|
129
|
+
status,
|
|
130
|
+
serviceReady,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export const DETAIL_MAINTENANCE_INTERVAL_MS = DAY_MS;
|
package/src/fleet-events.mjs
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { readFile } from 'node:fs/promises';
|
|
10
10
|
import { join } from 'node:path';
|
|
11
11
|
|
|
12
|
-
/**
|
|
12
|
+
/** 任务事件节点的类型(fleet 任务事件存储的默认值)。 */
|
|
13
13
|
export const TASK_EVENT_NODE_TYPE = 'task_event';
|
|
14
14
|
|
|
15
15
|
/** 任务域默认 namespace(`fleet.config.json` 缺省 / 缺文件)。 */
|