mm_datas 5.3.1 → 5.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.
@@ -22,10 +22,10 @@ function names(rows, field) {
22
22
 
23
23
  async function run() {
24
24
  W.title('第 2 章 / 角色、职业、技能、地图、道具之间的关联');
25
- const w = W.open('rpg_relations');
26
- const c = w.c;
27
- const reg = w.reg;
28
- const h = w.heroes;
25
+ let w = W.open('rpg_relations');
26
+ let c = w.c;
27
+ let reg = w.reg;
28
+ let h = w.heroes;
29
29
 
30
30
  // ---------- 1. 模型里声明了哪些关联 ----------
31
31
  W.title('2.1 关联清单(由 schema 的 ref 与 relations 自动生成)');
@@ -36,7 +36,7 @@ async function run() {
36
36
 
37
37
  // ---------- 2. 多对一 / 一对多 ----------
38
38
  W.title('2.2 一次读回完整角色档案(多对一 + 一对多)');
39
- const full = c.character.get(h.arthur, {
39
+ let full = c.character.get(h.arthur, {
40
40
  with: ['job', 'map', 'items', 'skills', 'quests']
41
41
  });
42
42
  W.show('角色', full.name + ' / ' + full.job.name + ' / Lv.' + full.level + ' / ' + full.map.name +
@@ -53,17 +53,17 @@ async function run() {
53
53
 
54
54
  // ---------- 3. 静态配置之间的关联 ----------
55
55
  W.title('2.3 配置表之间也有关联:任务 / 掉落 / NPC');
56
- const q1 = c.quest.get(1, { with: ['npc', 'monster', 'item'] });
56
+ let q1 = c.quest.get(1, { with: ['npc', 'monster', 'item'] });
57
57
  W.show('任务「清理史莱姆」', q1.npc.name + ' 发布 → 打 ' + q1.monster.name + ' ×' + q1.target_count +
58
58
  ' → 奖励 ' + q1.item.name + ' / ' + q1.reward_exp + ' exp');
59
- const bossDrop = c.drop.list({ monster_id: 99 }, { with: ['item'], limit: -1 });
59
+ let bossDrop = c.drop.list({ monster_id: 99 }, { with: ['item'], limit: -1 });
60
60
  W.show('红龙掉落表展开道具', bossDrop.list.map(function (d) { return d.item.name; }).join('、'));
61
- const townNpcs = c.npc.list({ map_id: 1001 }, { with: ['map'], limit: -1 });
61
+ let townNpcs = c.npc.list({ map_id: 1001 }, { with: ['map'], limit: -1 });
62
62
  W.show('主城 NPC 所在地图', Array.from(new Set(townNpcs.list.map(function (n) { return n.map.name; }))).join('、'));
63
63
 
64
64
  // ---------- 4. select 投影 / 别名 ----------
65
65
  W.title('2.4 关联结果裁剪:select / as / 自定义 with');
66
- const slim = c.character.get(h.merlin, {
66
+ let slim = c.character.get(h.merlin, {
67
67
  with: [
68
68
  { ref: 'job', as: 'profession', select: ['name', 'base_mp'] },
69
69
  { ref: 'items', as: 'bag_list', select: ['item_name', 'quantity'] },
@@ -76,28 +76,28 @@ async function run() {
76
76
 
77
77
  // ---------- 5. 多对多 ----------
78
78
  W.title('2.5 多对多:角色 × 技能(中间表 + 批量补全,无 N+1)');
79
- const store = c.character.store;
79
+ let store = c.character.store;
80
80
  store.calls.list = 0;
81
- const learned = c.character_skill.list({ character_id: { $in: [h.arthur, h.merlin, h.robin] } }, { limit: -1 }).list;
82
- const skillIds = Array.from(new Set(learned.map(function (r) { return r.skill_id; })));
83
- const templates = c.skill.list({ skill_id: { $in: skillIds } }, { limit: -1 }).list;
84
- const byId = new Map(templates.map(function (s) { return [s.skill_id, s]; }));
85
- const calls = store.calls.list;
81
+ let learned = c.character_skill.list({ character_id: { $in: [h.arthur, h.merlin, h.robin] } }, { limit: -1 }).list;
82
+ let skillIds = Array.from(new Set(learned.map(function (r) { return r.skill_id; })));
83
+ let templates = c.skill.list({ skill_id: { $in: skillIds } }, { limit: -1 }).list;
84
+ let byId = new Map(templates.map(function (s) { return [s.skill_id, s]; }));
85
+ let calls = store.calls.list;
86
86
  W.show('3 个角色共 ' + learned.length + ' 条已学技能 / ' + skillIds.length + ' 个技能模板',
87
87
  '后端查询 ' + calls + ' 次(中间表 1 + 模板表 1,与角色数无关)');
88
88
  W.show('亚瑟技能详情', learned.filter(function (r) { return r.character_id === h.arthur; }).map(function (r) {
89
- const t = byId.get(r.skill_id);
89
+ let t = byId.get(r.skill_id);
90
90
  return t.name + ' Lv.' + r.level + ' / 耗蓝 ' + t.mp_cost + ' / 伤害 ' + t.damage;
91
91
  }).join(';'));
92
92
 
93
93
  // 业务规则:职业限制不在 schema 里,用关联在应用层判定
94
94
  function learn(characterId, skillId) {
95
- const role = c.character.get(characterId);
96
- const sk = c.skill.get(skillId);
95
+ let role = c.character.get(characterId);
96
+ let sk = c.skill.get(skillId);
97
97
  if (!role || !sk) return '角色或技能不存在';
98
98
  if (sk.job_id !== role.job_id) return '拒绝:' + c.job.get(role.job_id).name + '不能学「' + sk.name + '」';
99
99
  if (role.level < sk.level_req) return '拒绝:等级不足(需 ' + sk.level_req + ')';
100
- const r = c.character_skill.add({ character_id: characterId, skill_id: skillId });
100
+ let r = c.character_skill.add({ character_id: characterId, skill_id: skillId });
101
101
  return '已学会「' + c.skill.get(skillId).name + '」#' + r.id;
102
102
  }
103
103
  W.show('战士学火球术(跨职业)', learn(h.arthur, 201));
@@ -107,7 +107,7 @@ async function run() {
107
107
 
108
108
  // ---------- 6. 运行时声明新关联 ----------
109
109
  W.title('2.6 运行时给任意集合加关联:ref() / hasMany()');
110
- const guild = c.character.collection('guild', {
110
+ let guild = c.character.collection('guild', {
111
111
  key: 'id',
112
112
  schema: {
113
113
  $schema: DRAFT, type: 'object',
@@ -120,7 +120,7 @@ async function run() {
120
120
  }
121
121
  });
122
122
  guild.ref('leader_id', 'character', { as: 'leader', select: ['id', 'name', 'level'] });
123
- const member = c.character.collection('guild_member', {
123
+ let member = c.character.collection('guild_member', {
124
124
  key: 'id',
125
125
  schema: {
126
126
  $schema: DRAFT, type: 'object',
@@ -135,12 +135,12 @@ async function run() {
135
135
  member.ref('character_id', 'character', { as: 'player', select: ['id', 'name', 'level'] });
136
136
  member.ref('guild_id', 'guild', { as: 'guild_info', select: ['id', 'name'] });
137
137
  guild.hasMany('members', { model: 'guild_member', via: 'guild_id', local: 'id' });
138
- const g1 = guild.add({ name: '晨曦骑士团', leader_id: h.arthur, notice: '每周屠龙' });
138
+ let g1 = guild.add({ name: '晨曦骑士团', leader_id: h.arthur, notice: '每周屠龙' });
139
139
  member.addMany([
140
140
  { guild_id: g1.id, character_id: h.arthur, rank: 'leader' },
141
141
  { guild_id: g1.id, character_id: h.robin, rank: 'officer' }
142
142
  ]);
143
- const gFull = guild.get(g1.id, { with: ['leader', 'members'] });
143
+ let gFull = guild.get(g1.id, { with: ['leader', 'members'] });
144
144
  W.show('公会 + 会长 + 成员', gFull.name + ' / 会长 ' + gFull.leader.name + ' / 成员 ' +
145
145
  names(gFull.members, 'character_id'));
146
146
  W.show('guild 的关联清单', guild.info().relations);
@@ -153,12 +153,12 @@ async function run() {
153
153
  W.title('2.7 展开关联不会 N+1(对比不同结果行数的后端调用次数)');
154
154
  function measure(query, withSpec) {
155
155
  store.calls.list = 0;
156
- const res = c.character.list(query, { with: withSpec, limit: -1 });
156
+ let res = c.character.list(query, { with: withSpec, limit: -1 });
157
157
  return { rows: res.list.length, calls: store.calls.list };
158
158
  }
159
- const spec = ['job', 'map', 'items', 'skills', 'quests'];
160
- const one = measure({ id: h.arthur }, spec);
161
- const many = measure({}, spec);
159
+ let spec = ['job', 'map', 'items', 'skills', 'quests'];
160
+ let one = measure({ id: h.arthur }, spec);
161
+ let many = measure({}, spec);
162
162
  W.show('1 个角色 × 5 个关联', one);
163
163
  W.show(many.rows + ' 个角色 × 5 个关联', many);
164
164
  W.show('结论', '两次后端调用次数相同(1 次主表 + 5 次批量关联),与行数无关');
@@ -177,7 +177,7 @@ async function run() {
177
177
  W.title('2.9 live 展开 vs snapshot 写时冗余');
178
178
  W.show('live(with item)', c.bag.first({ item_id: 1001 }).id + ' → ' +
179
179
  c.bag.first({ item_id: 1001 }, { with: ['item'] }).item.name);
180
- const snap = c.bag.first({ item_id: 1001 });
180
+ let snap = c.bag.first({ item_id: 1001 });
181
181
  W.show('snapshot(写时冗余,不 join 直接读)', snap.item_name + ' / cfg_ver=' + snap.cfg_ver);
182
182
  W.show('何时用哪种', '配置常变 → with 实时展开;战斗/结算高频且要留历史 → snapshot 冗余字段');
183
183
 
@@ -29,11 +29,11 @@ function show(label, value) {
29
29
 
30
30
  /**
31
31
  * 建一个独立的 RPG 世界。
32
- * namespace 不同 → 数据完全隔离;config 可带 store / dir / autoSave。
32
+ * namespace 不同 → 数据完全隔离;config 可带 store / dir / auto_save。
33
33
  * @returns {object} mm_admin 实例池
34
34
  */
35
35
  function createWorld(namespace, config) {
36
- const cfg = Object.assign({ models: MODEL_DIR }, config || {});
36
+ let cfg = Object.assign({ models: MODEL_DIR }, config || {});
37
37
  return mm.createPool(namespace || 'rpg', cfg);
38
38
  }
39
39
 
@@ -65,10 +65,10 @@ function collections(pool) {
65
65
  * 所有写入都会经过 schema 校验与引用完整性校验(ref)。
66
66
  */
67
67
  function seedWorld(pool) {
68
- const c = collections(pool);
68
+ let c = collections(pool);
69
69
 
70
70
  // 主角:战士 / 法师 / 弓手,分别落在不同地图、不同职业
71
- const heroes = c.character.addMany([
71
+ let heroes = c.character.addMany([
72
72
  {
73
73
  player_id: 1001, name: '亚瑟', job_id: 1, level: 24, exp: 5200,
74
74
  hp: 620, mp: 60, attack: 96, defense: 62, gold: 3800,
@@ -85,7 +85,7 @@ function seedWorld(pool) {
85
85
  map_id: 1001, x: 320, y: 480, online: false, created_at: '2026-11-18 20:10:00'
86
86
  }
87
87
  ]).ids;
88
- const [arthur, merlin, robin] = heroes;
88
+ let [arthur, merlin, robin] = heroes;
89
89
 
90
90
  // 用模型自带的 generate 模板批量造路人群像(用于分页 / 排序 / 条件查询演示)
91
91
  c.character.generate(12);
@@ -133,8 +133,8 @@ function seedWorld(pool) {
133
133
 
134
134
  /** 一步到位:建池 + 造数据,返回后续章节需要的全部手柄 */
135
135
  function open(namespace, config) {
136
- const pool = createWorld(namespace, config);
137
- const seeded = seedWorld(pool);
136
+ let pool = createWorld(namespace, config);
137
+ let seeded = seedWorld(pool);
138
138
  return Object.assign({ pool: pool, reg: mm.dataAdmin.registry(pool) }, seeded);
139
139
  }
140
140
 
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
  /**
3
- * v5 存储布局演示(可离线运行)
3
+ * v5 存储布局演示(无需外部服务)
4
4
  *
5
5
  * 1. example/model/ 下有几个 *_model.json,就创建几种集合
6
6
  * 2. 静态数据:data/<集合名>/000001.json —— 一条记录一个文件,每种模型一个目录;
7
7
  * 文件 I/O 委托 mm_jsondb 的 Store 文件层(database:'.' + pad:6 由模块自身补零)
8
- * 3. 动态数据:mm_cache 缓存 + mm_mongodb 持久;连不上自动回退本地快照
8
+ * 3. 动态数据:mm_cache 缓存 + 本地文件快照;显式启用 mm_mongodb / mm_sql 后再同步一份
9
9
  * 4. mm_sql:可选的关系型 / JSONDB 数据源适配器,配置后 flush 时同步一份
10
10
  * (mm_sql 的 way:'jsondb' 后端就是 mm_jsondb)
11
11
  * 5. 重启恢复:新池 connect() + restore()
@@ -35,7 +35,7 @@ function show(label, value) {
35
35
 
36
36
  /** 注入式 MongoDB 客户端:只实现 mm_mongodb 的 set / get,行为与真连接一致 */
37
37
  function memoryMongo() {
38
- const mem = new Map();
38
+ let mem = new Map();
39
39
  return {
40
40
  async set(key, value) { mem.set(key, value); return 1; },
41
41
  async get(key) { return mem.has(key) ? mem.get(key) : null; },
@@ -43,7 +43,7 @@ function memoryMongo() {
43
43
  };
44
44
  }
45
45
 
46
- const mongo = memoryMongo();
46
+ let mongo = memoryMongo();
47
47
 
48
48
  function sqlConfig() {
49
49
  return {
@@ -54,7 +54,7 @@ function sqlConfig() {
54
54
  }
55
55
 
56
56
  function poolConfig(dir, withBackends) {
57
- const cfg = { store: 'hybrid', dir: dir, models: MODEL_DIR };
57
+ let cfg = { store: 'hybrid', dir: dir, models: MODEL_DIR };
58
58
  if (withBackends) {
59
59
  cfg.mongodb = { client: mongo };
60
60
  cfg.sql = sqlConfig();
@@ -69,33 +69,33 @@ function dirs(root) {
69
69
  }
70
70
 
71
71
  async function main() {
72
- title('0. 依赖探测');
73
- show('require 结果', mm.probe());
74
- show('说明', '外部依赖都是可选增强:未安装 / 未启用 / 连不上都自动降级,同步 CRUD 永远可用');
72
+ title('0. 依赖');
73
+ show('硬依赖', ['mm_cache', 'mm_sql', 'mm_mongodb', 'mm_jsondb']);
74
+ show('说明', '四个依赖均为硬依赖;未启用的数据源不调用,连接或调用失败直接抛错');
75
75
 
76
76
  // ---------- 1. 模型文件决定集合 ----------
77
77
  title('1. *_model.json → 集合');
78
- const files = mm.modelFiles(MODEL_DIR);
78
+ let files = mm.modelFiles(MODEL_DIR);
79
79
  show('模型文件', files.map(function (f) { return f.file; }));
80
80
  show('推导集合名', files.map(function (f) { return f.name; }));
81
81
 
82
- const pool = mm.createPool('storage_demo', poolConfig(DATA_DIR, true));
83
- const reg = mm.dataAdmin.registry(pool);
82
+ let pool = mm.createPool('storage_demo', poolConfig(DATA_DIR, true));
83
+ let reg = mm.dataAdmin.registry(pool);
84
84
  show('实际集合数', reg.models().length);
85
85
  show('文件数 == 集合数', files.length === reg.models().length);
86
86
  show('集合一览', reg.models().map(function (m) { return m.name + '(' + m.kind + ')'; }));
87
87
 
88
88
  // ---------- 2. 静态数据逐文件落盘 ----------
89
89
  title('2. 静态数据:data/<集合名>/000001.json');
90
- const saved = reg.save();
90
+ let saved = reg.save();
91
91
  show('save()', { backend: saved.backend, tables: saved.tables, static_files: saved.static_files });
92
- const roleFile = path.join(DATA_DIR, 'role', '000001.json');
92
+ let roleFile = path.join(DATA_DIR, 'role', '000001.json');
93
93
  show('data/role/000001.json 存在', fs.existsSync(roleFile));
94
94
  show('data/role/000001.json 内容', JSON.parse(fs.readFileSync(roleFile, 'utf8')));
95
95
  show('data/role/ 目录', fs.readdirSync(path.join(DATA_DIR, 'role')).sort());
96
96
  show('data/skill/ 目录', fs.readdirSync(path.join(DATA_DIR, 'skill')).sort());
97
97
  show('data 下每种模型一个目录', dirs(DATA_DIR));
98
- const backends = pool.backends();
98
+ let backends = pool.backends();
99
99
  show('文件层(mm_jsondb Store)', backends.file_layer);
100
100
  show('依赖实例池工厂', {
101
101
  file: backends.file_layer.factory, cache: backends.adapters.cache.factory,
@@ -114,12 +114,12 @@ async function main() {
114
114
 
115
115
  // ---------- 3. 动态数据:CRUD + 关联 + mm_cache 缓存 ----------
116
116
  title('3. 动态数据:CRUD / 关联 / mm_cache');
117
- const player = pool.data('player');
118
- const arthur = player.add({ name: '亚瑟', role_id: 1, map_id: 1, level: 10, hp: 200, online: true });
119
- const merlin = player.add({ name: '梅林', role_id: 2, map_id: 1, level: 9 });
117
+ let player = pool.data('player');
118
+ let arthur = player.add({ name: '亚瑟', role_id: 1, map_id: 1, level: 10, hp: 200, online: true });
119
+ let merlin = player.add({ name: '梅林', role_id: 2, map_id: 1, level: 9 });
120
120
  show('新增玩家', [arthur.id + ':' + arthur.obj.name, merlin.id + ':' + merlin.obj.name]);
121
121
  show('关联展开', (function () {
122
- const row = player.get(arthur.id, { with: ['role', 'map'] });
122
+ let row = player.get(arthur.id, { with: ['role', 'map'] });
123
123
  return row.name + ' → ' + row.role.name + ' @ ' + row.map.name;
124
124
  })());
125
125
  show('条件查询', player.where({ online: true }).map(function (r) { return r.name; }));
@@ -128,14 +128,14 @@ async function main() {
128
128
  catch (e) { return e.code || e.message; }
129
129
  })());
130
130
 
131
- const connected = await pool.connect();
131
+ let connected = await pool.connect();
132
132
  show('mm_cache', { connected: connected.cache.connected, way: connected.cache.way });
133
133
  show('mm_mongodb', { connected: connected.mongodb.connected, reason: connected.mongodb.reason });
134
134
  show('mm_sql', { connected: connected.sql.connected, db_type: connected.sql.db_type });
135
135
 
136
- const first = await player.cacheGet(arthur.id);
136
+ let first = await player.cacheGet(arthur.id);
137
137
  await player.cacheGet(arthur.id);
138
- const cachedList = await player.cacheList({ online: true });
138
+ let cachedList = await player.cacheList({ online: true });
139
139
  show('cacheGet', first.name);
140
140
  show('cacheList', cachedList.count + ' 条');
141
141
  show('缓存统计', pool.backends().adapters.cache.stats);
@@ -143,11 +143,11 @@ async function main() {
143
143
 
144
144
  // ---------- 4. flush:静态逐文件 / 动态缓存 + 持久 + 可选 SQL ----------
145
145
  title('4. flush():一次把工作集推到各层');
146
- const flushed = await pool.flush();
146
+ let flushed = await pool.flush();
147
147
  show('汇总', {
148
148
  static_files: flushed.static_files, cache: flushed.cache,
149
149
  mongodb: flushed.mongodb, sql: flushed.sql,
150
- local_snapshot: flushed.local_snapshot, file_fallback: flushed.file_fallback
150
+ snapshots: flushed.snapshots
151
151
  });
152
152
  show('data/player 目录', fs.readdirSync(path.join(DATA_DIR, 'player')).sort());
153
153
  show('data/role 目录', fs.readdirSync(path.join(DATA_DIR, 'role')).sort());
@@ -157,34 +157,32 @@ async function main() {
157
157
 
158
158
  // ---------- 5. 重启恢复 ----------
159
159
  title('5. 新池重启恢复');
160
- const restored = mm.createPool('storage_demo_restore', poolConfig(DATA_DIR, true));
160
+ let restored = mm.createPool('storage_demo_restore', poolConfig(DATA_DIR, true));
161
161
  show('恢复前 player 行数', restored.data('player').size);
162
162
  await restored.connect();
163
- const r = await restored.restore();
163
+ let r = await restored.restore();
164
164
  show('恢复集合数', r.table_names.length);
165
165
  show('数据来源', r.sources);
166
166
  show('恢复后玩家', restored.data('player').get(arthur.id).name);
167
167
  show('恢复后职业', restored.data('role').get(1).name);
168
168
  show('verify()', restored.data('player').verify().ok);
169
169
 
170
- // ---------- 6. 依赖不可用时的降级 ----------
171
- title('6. 未启用 mm_mongodb:自动回退本地文件');
172
- const fallback = mm.createPool('storage_demo_fallback', poolConfig(DATA_DIR2, false));
173
- const before = await fallback.connect();
170
+ // ---------- 6. 未启用 mm_mongodb:动态集合仍写文件快照 ----------
171
+ title('6. 未启用 mm_mongodb:仅写本地文件快照');
172
+ let fallback = mm.createPool('storage_demo_fallback', poolConfig(DATA_DIR2, false));
173
+ let before = await fallback.connect();
174
174
  show('mongodb 状态', before.mongodb.reason);
175
175
  fallback.data('player').add({ name: '离线玩家', role_id: 3, map_id: 2, level: 1 });
176
- const f3 = await fallback.flush();
177
- show('flush 降级', {
178
- mongodb: f3.mongodb, file_fallback: f3.file_fallback, local_snapshot: f3.local_snapshot
179
- });
176
+ let f3 = await fallback.flush();
177
+ show('flush 报告', { mongodb: f3.mongodb, snapshots: f3.snapshots });
180
178
  show('本地快照存在', fs.existsSync(path.join(DATA_DIR2, 'player', '_rows.json')));
181
- const r3 = await fallback.restore();
179
+ let r3 = await fallback.restore();
182
180
  show('恢复来源', r3.sources.player);
183
181
  show('恢复后行数', fallback.data('player').size);
184
182
 
185
183
  title('完成');
186
184
  show('数据根目录', ROOT);
187
- show('结论', '静态=逐文件只读配置;动态=mm_cache 缓存 + mm_mongodb 持久;mm_sql=可选数据源');
185
+ show('结论', '静态=逐文件只读配置;动态=mm_cache 缓存 + 文件快照,外部数据源按配置显式启用');
188
186
  return { collections: reg.models().length, data_dir: DATA_DIR };
189
187
  }
190
188
 
package/index.js CHANGED
@@ -27,49 +27,10 @@
27
27
  * 规则判定全部委托 mm_validator。
28
28
  * 独立数据世界:createPool('game2') -> pool.data('role'),或 dataAdmin.use(pool)。
29
29
  */
30
- const fs = require('fs');
31
- const path = require('path');
32
30
  const P = require('./lib/pool.js');
33
31
  const M = require('./lib/model.js');
34
32
  const B = require('./lib/backend.js');
35
-
36
- const TOOL_DIR = path.join(__dirname, 'tool');
37
-
38
- function scan_tool_names(tool_dir) {
39
- if (!fs.existsSync(tool_dir)) return [];
40
- return fs.readdirSync(tool_dir, { withFileTypes: true })
41
- .filter(function (e) { return e.isDirectory() && fs.existsSync(path.join(tool_dir, e.name, 'tool.json')); })
42
- .map(function (e) { return e.name; });
43
- }
44
-
45
- function read_tool_config(tool_dir, name) {
46
- const file = path.join(tool_dir, name, 'tool.json');
47
- if (!fs.existsSync(file)) return null;
48
- const cfg = JSON.parse(fs.readFileSync(file, 'utf8'));
49
- // 两个参数视图必须同源:parameters 给 LLM(OpenAI function calling 格式),
50
- // params 给仓库工作流扫描(kernel_catalog / kernel_validator / workflow_engine)
51
- if (cfg.parameters && !cfg.params) cfg.params = cfg.parameters;
52
- if (cfg.params && !cfg.parameters) cfg.parameters = cfg.params;
53
- return cfg;
54
- }
55
-
56
- /**
57
- * 导出标准 OpenAI function calling 工具定义
58
- * { type:'function', function:{ name, description, parameters } }
59
- * 返回值可直接交给 mm_llm 的 setToolSchema / LLM 的 tools 数组
60
- */
61
- function function_tool_config(tool_dir, name) {
62
- const cfg = read_tool_config(tool_dir, name);
63
- if (!cfg) return null;
64
- return {
65
- type: 'function',
66
- function: {
67
- name: cfg.name || name,
68
- description: cfg.description || '',
69
- parameters: cfg.parameters || cfg.params || { type: 'object', properties: {} }
70
- }
71
- };
72
- }
33
+ const T = require('./lib/tool_scan.js');
73
34
 
74
35
  module.exports = {
75
36
  // 主入口与唯一的管理数据类
@@ -90,8 +51,7 @@ module.exports = {
90
51
 
91
52
  // v5 存储布局与外部依赖(mm_cache / mm_sql / mm_mongodb)
92
53
  modelFiles: P.scanModelFiles,
93
- probe: B.probe,
94
- RowFileLayout: B.RowFileLayout,
54
+ JsonDbLayout: B.JsonDbLayout,
95
55
  backends: P.dataAdmin.backends,
96
56
  connect: P.dataAdmin.connect,
97
57
  flush: P.dataAdmin.flush,
@@ -103,20 +63,12 @@ module.exports = {
103
63
  // 当前生效的校验器(schema 规则统一由 mm_validator 执行)
104
64
  validator: M.validatorInfo,
105
65
 
106
- // 兼容旧引用的别名(已统一命名为 DataManager,请勿在新代码使用)
107
- DataAdmin: P.DataManager,
108
- Collection: P.DataManager,
109
-
110
66
  // 兼容 AI 工具宿主(mm_ai / mm_workflow)的契约扫描能力
111
- TOOL_DIR: TOOL_DIR,
112
- listTools: function () { return scan_tool_names(TOOL_DIR); },
113
- getToolConfig: function (name) { return read_tool_config(TOOL_DIR, name); },
67
+ TOOL_DIR: T.TOOL_DIR,
68
+ listTools: T.list_tools,
69
+ getToolConfig: T.get_tool_config,
114
70
 
115
71
  // 给 LLM 的标准 OpenAI function calling 工具定义(parameters 与契约同源)
116
- getFunctionTool: function (name) { return function_tool_config(TOOL_DIR, name); },
117
- listFunctionTools: function () {
118
- return scan_tool_names(TOOL_DIR)
119
- .map(function (n) { return function_tool_config(TOOL_DIR, n); })
120
- .filter(Boolean);
121
- }
72
+ getFunctionTool: T.get_function_tool,
73
+ listFunctionTools: T.list_function_tools
122
74
  };