@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
package/src/admin.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// 控制台只读 API 的数据组装(D1)
|
|
2
2
|
//
|
|
3
|
-
// 只使用 @mebular/core 的公共 API:eventLog /
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// 只使用 @mebular/core 的公共 API:eventLog / node / sync / 门面只读入口
|
|
4
|
+
// (getSubscriptions / getBlockedDevices / 域公告)与 MemoryService 统一读面
|
|
5
|
+
// (status / listRecords / namespaceStats)。这里不做任何写入,也不替其他设备
|
|
6
|
+
// 做决定——只回答「本机给谁看什么」「与谁连接」。
|
|
6
7
|
//
|
|
7
8
|
// 契约(见 docs/console/interaction-draft.md):
|
|
8
9
|
// GET /admin/api/overview { device, status, onlinePeers[], revokedCount }
|
|
@@ -31,6 +32,9 @@ import {
|
|
|
31
32
|
|
|
32
33
|
export const POLICY_NS = POLICY_NAMESPACE;
|
|
33
34
|
|
|
35
|
+
// 记忆列表/域统计的过滤与聚合统一在 MemoryService.listRecords()/namespaceStats();
|
|
36
|
+
// 这里只做 Console 展示映射,不再识别内部类型或自行统计。
|
|
37
|
+
|
|
34
38
|
/** hex → Uint8Array(证书 devicePublicKey 为 hex 编码) */
|
|
35
39
|
export function hexToBytes(hex) {
|
|
36
40
|
if (typeof hex !== 'string' || hex.length % 2 !== 0) return new Uint8Array();
|
|
@@ -709,10 +713,17 @@ export async function buildPolicy({ app }) {
|
|
|
709
713
|
return policy.timeline;
|
|
710
714
|
}
|
|
711
715
|
|
|
712
|
-
/**
|
|
716
|
+
/**
|
|
717
|
+
* GET /admin/api/namespaces:目录 = 域公告 ∪ 本机域统计(未订阅也显示)。
|
|
718
|
+
*
|
|
719
|
+
* 计数/最近更新时间/记忆记录/内部对象统一来自 MemoryService.namespaceStats(),
|
|
720
|
+
* 与 stats()/capability 共用同一聚合规则。显式 includeReserved 保留 Console
|
|
721
|
+
* 旧行为:本机 `__*` 内部域仍然列出(不静默丢域);公共 stats/capability 默认
|
|
722
|
+
* 仍排除它们。
|
|
723
|
+
*/
|
|
713
724
|
export async function buildNamespaces({ app, service, config }) {
|
|
714
|
-
const [
|
|
715
|
-
|
|
725
|
+
const [domains, status, policy] = await Promise.all([
|
|
726
|
+
service.namespaceStats({ includeReserved: true }),
|
|
716
727
|
service.status(),
|
|
717
728
|
collectPolicy(app),
|
|
718
729
|
]);
|
|
@@ -721,26 +732,30 @@ export async function buildNamespaces({ app, service, config }) {
|
|
|
721
732
|
byNamespace.set(declaration.namespace, {
|
|
722
733
|
namespace: declaration.namespace,
|
|
723
734
|
count: 0,
|
|
735
|
+
memoryRecords: 0,
|
|
736
|
+
internalObjects: 0,
|
|
724
737
|
lastUpdatedAt: 0,
|
|
725
738
|
declared: true,
|
|
726
739
|
declaredAt: declaration.at,
|
|
727
740
|
declaredBy: declaration.issuer,
|
|
728
741
|
});
|
|
729
742
|
}
|
|
730
|
-
for (const
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
namespace,
|
|
743
|
+
for (const domain of domains) {
|
|
744
|
+
const entry = byNamespace.get(domain.domain) ?? {
|
|
745
|
+
namespace: domain.domain,
|
|
734
746
|
count: 0,
|
|
747
|
+
memoryRecords: 0,
|
|
748
|
+
internalObjects: 0,
|
|
735
749
|
lastUpdatedAt: 0,
|
|
736
750
|
declared: false,
|
|
737
751
|
declaredAt: null,
|
|
738
752
|
declaredBy: null,
|
|
739
753
|
};
|
|
740
|
-
entry.count
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
754
|
+
entry.count = domain.count;
|
|
755
|
+
entry.memoryRecords = domain.memoryRecords;
|
|
756
|
+
entry.internalObjects = domain.internalObjects;
|
|
757
|
+
entry.lastUpdatedAt = domain.lastUpdatedAt;
|
|
758
|
+
byNamespace.set(domain.domain, entry);
|
|
744
759
|
}
|
|
745
760
|
const hashes = status.stateHashByNamespace ?? {};
|
|
746
761
|
const subscription = app.sync?.getSubscriptionNamespaces?.()
|
|
@@ -992,9 +1007,15 @@ export async function buildSettings({ app, service, config, runtime, home }) {
|
|
|
992
1007
|
// A/D:三元组 + 暴露面(单一真源驱动;GUI 编辑器改由 configSchema 渲染)
|
|
993
1008
|
effective: effectiveRows,
|
|
994
1009
|
// G:应用结果(green=已生效 / red=未按预期生效或已回滚 / in-progress=重启中)
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1010
|
+
// rollingBack 的 pending 只有在恢复失败时才会留下结果;此时必须优先展示 rollback-failed,
|
|
1011
|
+
// 不能被 pending 误报成 in-progress。
|
|
1012
|
+
lastApply: applyPending?.rollingBack === true
|
|
1013
|
+
? (applyResult?.status === 'rollback-failed'
|
|
1014
|
+
? applyResult
|
|
1015
|
+
: { status: 'in-progress', at: applyPending.at ?? null, fields: applyPending.fields ?? [], attempt: applyPending.attempt ?? null })
|
|
1016
|
+
: (applyPending
|
|
1017
|
+
? { status: 'in-progress', at: applyPending.at ?? null, fields: applyPending.fields ?? [], attempt: applyPending.attempt ?? null }
|
|
1018
|
+
: (applyResult ?? null)),
|
|
998
1019
|
configSchema: consoleSchema(),
|
|
999
1020
|
statusSchema: consoleStatusSchema(),
|
|
1000
1021
|
restart: {
|
|
@@ -1151,31 +1172,34 @@ export async function buildConfigView({ config, home }) {
|
|
|
1151
1172
|
|
|
1152
1173
|
/**
|
|
1153
1174
|
* G-ML-1:记忆列表(动作式 GUI 的读面)。
|
|
1154
|
-
*
|
|
1155
|
-
*
|
|
1175
|
+
* 默认**过滤已删除(墓碑)、已归档与 Runtime 内部对象**;对应 include* 参数可切换查看。
|
|
1176
|
+
* 过滤/排序/分页统一由 MemoryService.listRecords() 执行;这里只做脱敏展示映射
|
|
1177
|
+
* (只给预览,不回显完整 metadata)。
|
|
1156
1178
|
*/
|
|
1157
|
-
export async function buildMemories({
|
|
1179
|
+
export async function buildMemories({ service, url }) {
|
|
1158
1180
|
const params = url?.searchParams ?? new URLSearchParams();
|
|
1159
1181
|
const flag = (name) => params.get(name) === '1' || params.get(name) === 'true';
|
|
1160
1182
|
const includeArchived = flag('includeArchived');
|
|
1161
1183
|
const includeDeleted = flag('includeDeleted');
|
|
1184
|
+
// 0.3:Runtime 内部对象默认隐藏;includeInternal=1 仅管理面调试使用。
|
|
1185
|
+
const includeInternal = flag('includeInternal');
|
|
1162
1186
|
const namespace = params.get('namespace') ?? undefined;
|
|
1163
1187
|
const limitRaw = Number(params.get('limit') ?? '50');
|
|
1164
1188
|
const limit = Number.isFinite(limitRaw) ? Math.min(Math.max(Math.trunc(limitRaw), 1), 200) : 50;
|
|
1165
1189
|
|
|
1166
1190
|
const archivedOf = (node) => typeof node?.metadata?.archivedAt === 'number';
|
|
1167
|
-
let
|
|
1191
|
+
let records = { total: 0, nodes: [] };
|
|
1168
1192
|
try {
|
|
1169
|
-
|
|
1193
|
+
records = await service.listRecords({
|
|
1194
|
+
includeDeleted,
|
|
1195
|
+
includeArchived,
|
|
1196
|
+
includeInternal,
|
|
1197
|
+
...(namespace !== undefined ? { namespace } : {}),
|
|
1198
|
+
limit,
|
|
1199
|
+
});
|
|
1170
1200
|
} catch {
|
|
1171
|
-
|
|
1201
|
+
records = { total: 0, nodes: [] };
|
|
1172
1202
|
}
|
|
1173
|
-
const filtered = nodes.filter((node) => {
|
|
1174
|
-
if (!includeDeleted && node.deletedAt) return false;
|
|
1175
|
-
if (!includeArchived && archivedOf(node)) return false;
|
|
1176
|
-
if (namespace !== undefined && (node.namespace ?? 'default') !== namespace) return false;
|
|
1177
|
-
return true;
|
|
1178
|
-
});
|
|
1179
1203
|
const previewOf = (node) => {
|
|
1180
1204
|
const content = node?.content ?? {};
|
|
1181
1205
|
if (typeof content === 'string') return content.slice(0, 160);
|
|
@@ -1188,28 +1212,25 @@ export async function buildMemories({ app, url }) {
|
|
|
1188
1212
|
const text = content.content ?? content.name ?? content.description ?? content.value ?? '';
|
|
1189
1213
|
return String(text).slice(0, 160);
|
|
1190
1214
|
};
|
|
1191
|
-
const memories =
|
|
1192
|
-
.
|
|
1193
|
-
.
|
|
1194
|
-
.
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
deleted: Boolean(node.deletedAt),
|
|
1205
|
-
deletedAt: node.deletedAt ?? null,
|
|
1206
|
-
tags: Array.isArray(node.tags) ? node.tags : [],
|
|
1207
|
-
}));
|
|
1215
|
+
const memories = records.nodes.map((node) => ({
|
|
1216
|
+
id: node.id,
|
|
1217
|
+
type: node.type,
|
|
1218
|
+
namespace: node.namespace ?? 'default',
|
|
1219
|
+
preview: previewOf(node),
|
|
1220
|
+
createdAt: node.createdAt ?? null,
|
|
1221
|
+
updatedAt: node.updatedAt ?? null,
|
|
1222
|
+
archived: archivedOf(node),
|
|
1223
|
+
archivedAt: node.metadata?.archivedAt ?? null,
|
|
1224
|
+
deleted: Boolean(node.deletedAt),
|
|
1225
|
+
deletedAt: node.deletedAt ?? null,
|
|
1226
|
+
tags: Array.isArray(node.tags) ? node.tags : [],
|
|
1227
|
+
}));
|
|
1208
1228
|
return {
|
|
1209
|
-
total:
|
|
1229
|
+
total: records.total,
|
|
1210
1230
|
limit,
|
|
1211
1231
|
includeArchived,
|
|
1212
1232
|
includeDeleted,
|
|
1233
|
+
includeInternal,
|
|
1213
1234
|
...(namespace !== undefined ? { namespace } : {}),
|
|
1214
1235
|
memories,
|
|
1215
1236
|
};
|
|
@@ -1338,4 +1359,5 @@ export const READ_ROUTES = {
|
|
|
1338
1359
|
'/admin/api/net': buildNetStatusView,
|
|
1339
1360
|
'/admin/api/service': buildServiceView,
|
|
1340
1361
|
'/admin/api/clients': buildClientsView,
|
|
1362
|
+
// 0.3 本地模型/推理由 serve.mjs 的 sidecar 薄代理处理,这里不再直读设备 store。
|
|
1341
1363
|
};
|