mm_cmd 1.1.2 → 1.1.4

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/README.md CHANGED
@@ -8,4 +8,13 @@
8
8
  2. 后端先进行基础的指令判断(内容是否匹配有指令关键词),判断消息是否为指令。
9
9
  3. 如果是指令,则执行指令处理。
10
10
  4. 如果不是指令,再交由AI判断是否为指令。
11
- 5. 如果AI判断为指令,则执行指令处理。
11
+ 5. 如果AI判断为指令,则执行指令处理。
12
+
13
+ ## 工具契约(LLM 可调用)
14
+
15
+ 本模块 `tool/` 下登记以下工具契约,实现位于 `lib/tools/<name>/`,`tool/<name>/index.js` 仅为薄适配层。
16
+ 其它模块可直接 `require('<pkg>').tools.<name>` 复用实现,无需经过工具注册面。
17
+
18
+ | 工具名 | 标题 | 说明 |
19
+ | --- | --- | --- |
20
+ | `command` | 聊天指令匹配与执行 | 指令清单、命中判断、按消息执行 |
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
- const Admin = require('mm_corejs').Admin;
1
+ const { reg } = require('mm_admin');
2
2
  const Manager = require('./lib/manager');
3
3
 
4
- let admin = new Admin();
4
+ const admin = reg('mm_cmd');
5
5
  admin.setClass(Manager);
6
6
 
7
7
  module.exports = {
@@ -9,9 +9,10 @@ module.exports = {
9
9
  Manager,
10
10
  admin,
11
11
  cmdAdmin(scope, config) {
12
- if (!scope) {
13
- scope = 'os';
14
- }
15
- return admin.get(scope, config);
12
+ return admin.get(scope || 'os', config);
16
13
  }
17
- };
14
+ };
15
+
16
+ /* mm-tool-logic-export 工具能力层:其它模块可 require("mm_cmd").tools.<name> 直接引用 */
17
+ Object.defineProperty(module.exports, 'tools', { enumerable: true, configurable: true,
18
+ get: function () { return require('./lib/tools'); } });
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+ /**
3
+ * command —— 聊天指令匹配与执行工具
4
+ * 复用模块 Cmd 实例:match 走关键字匹配,run 走完整指令分发,不重写分发逻辑。
5
+ */
6
+ const { cmdAdmin } = require('../../../index.js');
7
+
8
+ async function main(params, ctx, options) {
9
+ void options;
10
+ const p = params || {};
11
+ const action = p.action || 'list';
12
+ const done = (data) => { ctx.output = data; return data; };
13
+
14
+ try {
15
+ const inst = cmdAdmin(p.scope || 'os');
16
+
17
+ if (action === 'list') {
18
+ const list = Object.keys(inst.methods || {});
19
+ return done({ code: 0, msg: '成功', count: list.length, list });
20
+ }
21
+
22
+ if (action === 'match') {
23
+ if (!p.content) throw new TypeError('content 不能为空');
24
+ return done({ code: 0, msg: '成功', matched: !!inst.match(p.content) });
25
+ }
26
+
27
+ if (action === 'run') {
28
+ if (!p.content) throw new TypeError('content 不能为空');
29
+ const result = await inst.run({ content: p.content }, p.db);
30
+ return done({ code: 0, msg: '执行完成', result });
31
+ }
32
+
33
+ return done({ code: 10001, msg: '不支持的操作: ' + action });
34
+ } catch (error) {
35
+ return done({ code: 10000, msg: '执行失败:' + error.message, error: { name: error.name, message: error.message } });
36
+ }
37
+ }
38
+
39
+ module.exports = { main };
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ /** 模块能力层:懒加载工具实现,避免模块入口被 require 时加载全部实现 */
5
+ module.exports = new Proxy({}, {
6
+ get(_t, key) {
7
+ if (typeof key !== 'string') return undefined;
8
+ if (!fs.existsSync(path.join(__dirname, key, 'index.js'))) return undefined;
9
+ return require('./' + key);
10
+ },
11
+ has(_t, key) {
12
+ return typeof key === 'string' && fs.existsSync(path.join(__dirname, key, 'index.js'));
13
+ },
14
+ ownKeys() { return fs.readdirSync(__dirname, { withFileTypes: true }).filter(e => e.isDirectory()).map(e => e.name); },
15
+ getOwnPropertyDescriptor(_t, key) { return this.has(_t, key) ? { enumerable: true, configurable: true } : undefined; }
16
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_cmd",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "指令框架,用于以聊天的方式操作程序,前端发送字符串,后端判断是否为指令并执行(基于 mm_corejs,内置管理器池,无全局/原型扩展依赖)",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -16,12 +16,12 @@
16
16
  "chat",
17
17
  "指令管理器"
18
18
  ],
19
- "layer": "infra",
20
- "group": "in_adapter",
19
+ "layer": "interface",
20
+ "group": "inbound",
21
21
  "author": "邱文武",
22
22
  "license": "ISC",
23
23
  "dependencies": {
24
- "mm_corejs": "^1.1.4",
24
+ "mm_admin": "^1.1.0",
25
25
  "mm_mod": "^1.0.1",
26
26
  "mm_matchs": "^1.1.10"
27
27
  },
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+ /**
3
+ * command —— 工具契约适配层
4
+ * 业务实现归位于模块 lib/tools/command/,本文件只把模块能力暴露给加载器。
5
+ * 其它模块可直接 require('mm_cmd').tools.command 复用。
6
+ */
7
+ module.exports = require('../../lib/tools/command');
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "command",
3
+ "title": "聊天指令匹配与执行",
4
+ "description": "基于 mm_cmd 的指令框架能力:判断一段聊天文本是否为已注册指令、列出已注册的指令方法、以消息对象执行指令并返回反馈内容。适用场景:验证用户输入会不会命中指令、在非 IM 场景复用指令脚本、排查指令未注册。工作流提示:match 只传 content;run 传 content,可选 db 作为会话库标识。",
5
+ "category": "指令框架",
6
+ "group": "cmd",
7
+ "type": "function",
8
+ "main": "./index.js",
9
+ "params": {
10
+ "type": "object",
11
+ "properties": {
12
+ "action": {
13
+ "type": "string",
14
+ "description": "操作类型: list(列出指令方法)/match(匹配指令)/run(执行指令)",
15
+ "enum": [
16
+ "list",
17
+ "match",
18
+ "run"
19
+ ],
20
+ "default": "list"
21
+ },
22
+ "content": {
23
+ "type": "string",
24
+ "description": "聊天文本内容(match/run 必填)"
25
+ },
26
+ "db": {
27
+ "type": "string",
28
+ "description": "会话库标识,传给指令方法的第二参数(run 可选)"
29
+ },
30
+ "scope": {
31
+ "type": "string",
32
+ "description": "实例作用域,缺省 os",
33
+ "default": "os"
34
+ }
35
+ },
36
+ "required": [
37
+ "action"
38
+ ]
39
+ },
40
+ "returns": {
41
+ "type": "object",
42
+ "properties": {
43
+ "code": {
44
+ "type": "number",
45
+ "description": "0 表示成功,1xxxx 表示业务/执行异常"
46
+ },
47
+ "msg": {
48
+ "type": "string",
49
+ "description": "结果描述"
50
+ },
51
+ "list": {
52
+ "type": "array",
53
+ "description": "已注册的指令方法名(list)"
54
+ },
55
+ "count": {
56
+ "type": "number",
57
+ "description": "指令方法数量(list)"
58
+ },
59
+ "matched": {
60
+ "type": "boolean",
61
+ "description": "是否命中指令(match)"
62
+ },
63
+ "result": {
64
+ "description": "指令执行结果(run)"
65
+ },
66
+ "error": {
67
+ "type": "object",
68
+ "description": "异常对象 { name, message }"
69
+ }
70
+ }
71
+ },
72
+ "handler": "manager"
73
+ }
File without changes
File without changes