m8-mcp-server 1.0.6 → 1.0.7
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/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -13
- package/dist/docs/apis.d.ts +1 -1
- package/dist/docs/apis.js +9 -326
- package/dist/docs/components.d.ts +1 -1
- package/dist/docs/components.js +2 -186
- package/dist/docs/index.d.ts +1 -1
- package/dist/docs/index.js +18 -177
- package/dist/docs/loader.d.ts +1 -1
- package/dist/docs/loader.js +1 -165
- package/dist/docs/search.d.ts +1 -1
- package/dist/docs/search.js +2 -196
- package/dist/docs/standards.d.ts +1 -1
- package/dist/docs/standards.js +3 -134
- package/dist/docs/utils.d.ts +1 -1
- package/dist/docs/utils.js +3 -129
- package/dist/generator/header.d.ts +1 -1
- package/dist/generator/header.js +3 -83
- package/dist/generator/index.d.ts +1 -1
- package/dist/generator/index.js +283 -648
- package/dist/generator/vue-template.d.ts +1 -1
- package/dist/generator/vue-template.js +336 -1016
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -73
- package/dist/recommend/index.d.ts +1 -1
- package/dist/recommend/index.js +2 -412
- package/dist/tools/generate-code.d.ts +1 -1
- package/dist/tools/generate-code.js +39 -211
- package/dist/tools/get-api-info.d.ts +1 -1
- package/dist/tools/get-api-info.js +1 -65
- package/dist/tools/get-coding-standard.d.ts +1 -1
- package/dist/tools/get-coding-standard.js +1 -66
- package/dist/tools/get-component-info.d.ts +1 -1
- package/dist/tools/get-component-info.js +1 -60
- package/dist/tools/get-util-info.d.ts +1 -1
- package/dist/tools/get-util-info.js +1 -65
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +3 -101
- package/dist/tools/recommend-solution.d.ts +1 -1
- package/dist/tools/recommend-solution.js +1 -67
- package/dist/tools/search-docs.d.ts +1 -1
- package/dist/tools/search-docs.js +1 -71
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +0 -8
- package/package.json +4 -2
- package/dist/cli.js.map +0 -1
- package/dist/docs/apis.js.map +0 -1
- package/dist/docs/components.js.map +0 -1
- package/dist/docs/index.js.map +0 -1
- package/dist/docs/loader.js.map +0 -1
- package/dist/docs/search.js.map +0 -1
- package/dist/docs/standards.js.map +0 -1
- package/dist/docs/utils.js.map +0 -1
- package/dist/generator/header.js.map +0 -1
- package/dist/generator/index.js.map +0 -1
- package/dist/generator/vue-template.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/recommend/index.js.map +0 -1
- package/dist/tools/generate-code.js.map +0 -1
- package/dist/tools/get-api-info.js.map +0 -1
- package/dist/tools/get-coding-standard.js.map +0 -1
- package/dist/tools/get-component-info.js.map +0 -1
- package/dist/tools/get-util-info.js.map +0 -1
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/recommend-solution.js.map +0 -1
- package/dist/tools/search-docs.js.map +0 -1
- package/dist/types/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,73 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* M8 MCP Server 主入口
|
|
3
|
-
* @作者 li peng
|
|
4
|
-
* @创建时间 2024-12-29
|
|
5
|
-
* @描述 MCP Server 实现,提供文档查询、智能推荐和代码生成服务
|
|
6
|
-
*/
|
|
7
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
8
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
9
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
10
|
-
import { documentManager } from './docs/index.js';
|
|
11
|
-
import { toolManager } from './tools/index.js';
|
|
12
|
-
/**
|
|
13
|
-
* 创建并启动 MCP Server
|
|
14
|
-
*/
|
|
15
|
-
export async function createServer() {
|
|
16
|
-
// 初始化文档管理器
|
|
17
|
-
await documentManager.initialize();
|
|
18
|
-
// 创建 MCP Server 实例
|
|
19
|
-
const server = new Server({
|
|
20
|
-
name: 'm8-mcp-server',
|
|
21
|
-
version: '1.0.0',
|
|
22
|
-
}, {
|
|
23
|
-
capabilities: {
|
|
24
|
-
tools: {},
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
// 处理 tools/list 请求
|
|
28
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
29
|
-
const tools = toolManager.getToolDefinitions();
|
|
30
|
-
return { tools };
|
|
31
|
-
});
|
|
32
|
-
// 处理 tools/call 请求
|
|
33
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
34
|
-
const { name, arguments: args } = request.params;
|
|
35
|
-
// 执行工具
|
|
36
|
-
const result = await toolManager.executeTool(name, args || {});
|
|
37
|
-
return {
|
|
38
|
-
content: result.content,
|
|
39
|
-
isError: result.isError
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
return server;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* 启动 MCP Server
|
|
46
|
-
*/
|
|
47
|
-
export async function startServer() {
|
|
48
|
-
try {
|
|
49
|
-
const server = await createServer();
|
|
50
|
-
const transport = new StdioServerTransport();
|
|
51
|
-
await server.connect(transport);
|
|
52
|
-
// 处理进程退出
|
|
53
|
-
process.on('SIGINT', async () => {
|
|
54
|
-
await server.close();
|
|
55
|
-
process.exit(0);
|
|
56
|
-
});
|
|
57
|
-
process.on('SIGTERM', async () => {
|
|
58
|
-
await server.close();
|
|
59
|
-
process.exit(0);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
// MCP 协议要求不能输出非 JSON 内容到 stdout/stderr
|
|
64
|
-
process.exit(1);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// 导出模块
|
|
68
|
-
export { documentManager } from './docs/index.js';
|
|
69
|
-
export { toolManager } from './tools/index.js';
|
|
70
|
-
export { codeGenerator } from './generator/index.js';
|
|
71
|
-
export { recommendationEngine } from './recommend/index.js';
|
|
72
|
-
export * from './types/index.js';
|
|
73
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import{Server as a}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as c}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as i,ListToolsRequestSchema as m}from"@modelcontextprotocol/sdk/types.js";import{documentManager as p}from"./docs/index.js";import{toolManager as t}from"./tools/index.js";import{documentManager as y}from"./docs/index.js";import{toolManager as M}from"./tools/index.js";import{codeGenerator as q}from"./generator/index.js";import{recommendationEngine as h}from"./recommend/index.js";export*from"./types/index.js";async function l(){await p.initialize();const e=new a({name:"m8-mcp-server",version:"1.0.0"},{capabilities:{tools:{}}});return e.setRequestHandler(m,async()=>({tools:t.getToolDefinitions()})),e.setRequestHandler(i,async r=>{const{name:s,arguments:n}=r.params,o=await t.executeTool(s,n||{});return{content:o.content,isError:o.isError}}),e}async function d(){try{const e=await l(),r=new c;await e.connect(r),process.on("SIGINT",async()=>{await e.close(),process.exit(0)}),process.on("SIGTERM",async()=>{await e.close(),process.exit(0)})}catch{process.exit(1)}}export{q as codeGenerator,l as createServer,y as documentManager,h as recommendationEngine,d as startServer,M as toolManager};
|
package/dist/recommend/index.js
CHANGED
|
@@ -1,412 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @作者 li peng
|
|
4
|
-
* @创建时间 2024-12-29
|
|
5
|
-
* @描述 根据需求智能推荐组件、API 和工具方法
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* EJS API 推荐映射
|
|
9
|
-
*/
|
|
10
|
-
const EJS_API_MAPPINGS = [
|
|
11
|
-
{
|
|
12
|
-
keywords: ['提示', '消息', 'toast', '轻提示'],
|
|
13
|
-
type: 'ejs-api',
|
|
14
|
-
name: 'ejs.ui.toast',
|
|
15
|
-
description: '显示轻提示消息',
|
|
16
|
-
usage: "ejs.ui.toast({ message: '操作成功' });",
|
|
17
|
-
priority: 100
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
keywords: ['弹窗', '警告', 'alert', '提醒'],
|
|
21
|
-
type: 'ejs-api',
|
|
22
|
-
name: 'ejs.ui.alert',
|
|
23
|
-
description: '显示警告弹窗',
|
|
24
|
-
usage: "ejs.ui.alert({ title: '提示', message: '这是一条消息' });",
|
|
25
|
-
priority: 100
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
keywords: ['确认', 'confirm', '询问', '是否'],
|
|
29
|
-
type: 'ejs-api',
|
|
30
|
-
name: 'ejs.ui.confirm',
|
|
31
|
-
description: '显示确认弹窗',
|
|
32
|
-
usage: "const result = await ejs.ui.confirm({ title: '确认', message: '确定要执行吗?' });",
|
|
33
|
-
priority: 100
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
keywords: ['加载', 'loading', '等待', '请稍候'],
|
|
37
|
-
type: 'ejs-api',
|
|
38
|
-
name: 'ejs.ui.showWaiting',
|
|
39
|
-
description: '显示加载中提示',
|
|
40
|
-
usage: "ejs.ui.showWaiting({ message: '加载中...' });",
|
|
41
|
-
priority: 100
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
keywords: ['选择', '选项', 'picker', '下拉'],
|
|
45
|
-
type: 'ejs-api',
|
|
46
|
-
name: 'ejs.ui.picker',
|
|
47
|
-
description: '显示选择器',
|
|
48
|
-
usage: "const result = await ejs.ui.picker({ options: ['选项1', '选项2'] });",
|
|
49
|
-
priority: 100
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
keywords: ['日期', 'date', '年月日'],
|
|
53
|
-
type: 'ejs-api',
|
|
54
|
-
name: 'ejs.ui.pickDate',
|
|
55
|
-
description: '显示日期选择器',
|
|
56
|
-
usage: "const date = await ejs.ui.pickDate({ title: '选择日期' });",
|
|
57
|
-
priority: 100
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
keywords: ['时间', 'time', '时分'],
|
|
61
|
-
type: 'ejs-api',
|
|
62
|
-
name: 'ejs.ui.pickTime',
|
|
63
|
-
description: '显示时间选择器',
|
|
64
|
-
usage: "const time = await ejs.ui.pickTime({ title: '选择时间' });",
|
|
65
|
-
priority: 100
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
keywords: ['跳转', '打开', '页面', 'open', '导航'],
|
|
69
|
-
type: 'ejs-api',
|
|
70
|
-
name: 'ejs.page.open',
|
|
71
|
-
description: '打开新页面',
|
|
72
|
-
usage: "ejs.page.open({ pageUrl: './detail', data: { id: '123' } });",
|
|
73
|
-
priority: 100
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
keywords: ['关闭', '返回', 'close', '退出'],
|
|
77
|
-
type: 'ejs-api',
|
|
78
|
-
name: 'ejs.page.close',
|
|
79
|
-
description: '关闭当前页面',
|
|
80
|
-
usage: "ejs.page.close({ resultData: { status: 'success' } });",
|
|
81
|
-
priority: 100
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
keywords: ['标题', 'title', '页面标题'],
|
|
85
|
-
type: 'ejs-api',
|
|
86
|
-
name: 'ejs.page.setTitle',
|
|
87
|
-
description: '设置页面标题',
|
|
88
|
-
usage: "ejs.page.setTitle({ title: '新标题' });",
|
|
89
|
-
priority: 100
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
keywords: ['存储', '缓存', 'storage', '本地'],
|
|
93
|
-
type: 'ejs-api',
|
|
94
|
-
name: 'ejs.storage',
|
|
95
|
-
description: '本地存储操作',
|
|
96
|
-
usage: "ejs.storage.setItem({ key: 'token', value: 'xxx' });",
|
|
97
|
-
priority: 100
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
keywords: ['扫码', '二维码', 'scan', 'qrcode'],
|
|
101
|
-
type: 'ejs-api',
|
|
102
|
-
name: 'ejs.device.scan',
|
|
103
|
-
description: '扫描二维码/条形码',
|
|
104
|
-
usage: 'const result = await ejs.device.scan();',
|
|
105
|
-
priority: 100
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
keywords: ['拍照', '相机', 'camera', 'photo'],
|
|
109
|
-
type: 'ejs-api',
|
|
110
|
-
name: 'ejs.device.takePhoto',
|
|
111
|
-
description: '拍照',
|
|
112
|
-
usage: 'const photo = await ejs.device.takePhoto({ quality: 80 });',
|
|
113
|
-
priority: 100
|
|
114
|
-
}
|
|
115
|
-
];
|
|
116
|
-
/**
|
|
117
|
-
* UI 组件推荐映射
|
|
118
|
-
*/
|
|
119
|
-
const UI_COMPONENT_MAPPINGS = [
|
|
120
|
-
{
|
|
121
|
-
keywords: ['按钮', 'button', '点击', '提交'],
|
|
122
|
-
type: 'ui-component',
|
|
123
|
-
name: 'em-button',
|
|
124
|
-
description: '按钮组件,支持多种类型和状态',
|
|
125
|
-
usage: '<em-button type="primary" @click="handleClick">提交</em-button>',
|
|
126
|
-
priority: 50
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
keywords: ['输入', 'input', '文本框', '表单项'],
|
|
130
|
-
type: 'ui-component',
|
|
131
|
-
name: 'em-field',
|
|
132
|
-
description: '输入框组件,支持多种输入类型',
|
|
133
|
-
usage: '<em-field v-model="value" label="用户名" placeholder="请输入" />',
|
|
134
|
-
priority: 50
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
keywords: ['单元格', 'cell', '列表项', '菜单项'],
|
|
138
|
-
type: 'ui-component',
|
|
139
|
-
name: 'em-cell',
|
|
140
|
-
description: '单元格组件,用于展示列表项',
|
|
141
|
-
usage: '<em-cell title="标题" value="内容" is-link />',
|
|
142
|
-
priority: 50
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
keywords: ['表单', 'form', '提交', '验证'],
|
|
146
|
-
type: 'ui-component',
|
|
147
|
-
name: 'em-form',
|
|
148
|
-
description: '表单组件,支持表单验证',
|
|
149
|
-
usage: '<em-form ref="form" :model="formData" :rules="rules">...</em-form>',
|
|
150
|
-
priority: 50
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
keywords: ['弹出层', 'popup', '抽屉', '底部弹出'],
|
|
154
|
-
type: 'ui-component',
|
|
155
|
-
name: 'em-popup',
|
|
156
|
-
description: '弹出层组件',
|
|
157
|
-
usage: '<em-popup v-model="show" position="bottom">内容</em-popup>',
|
|
158
|
-
priority: 50
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
keywords: ['选择器', 'picker', '滚动选择'],
|
|
162
|
-
type: 'ui-component',
|
|
163
|
-
name: 'em-picker',
|
|
164
|
-
description: '选择器组件',
|
|
165
|
-
usage: '<em-picker :columns="columns" @confirm="onConfirm" />',
|
|
166
|
-
priority: 50
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
keywords: ['日期选择', 'datepicker', '日历'],
|
|
170
|
-
type: 'ui-component',
|
|
171
|
-
name: 'em-datepicker',
|
|
172
|
-
description: '日期选择器组件',
|
|
173
|
-
usage: '<em-datepicker v-model="date" type="date" />',
|
|
174
|
-
priority: 50
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
keywords: ['开关', 'switch', '切换'],
|
|
178
|
-
type: 'ui-component',
|
|
179
|
-
name: 'em-switch',
|
|
180
|
-
description: '开关组件',
|
|
181
|
-
usage: '<em-switch v-model="checked" />',
|
|
182
|
-
priority: 50
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
keywords: ['复选框', 'checkbox', '多选'],
|
|
186
|
-
type: 'ui-component',
|
|
187
|
-
name: 'em-checkbox',
|
|
188
|
-
description: '复选框组件',
|
|
189
|
-
usage: '<em-checkbox v-model="checked">选项</em-checkbox>',
|
|
190
|
-
priority: 50
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
keywords: ['单选框', 'radio', '单选'],
|
|
194
|
-
type: 'ui-component',
|
|
195
|
-
name: 'em-radio',
|
|
196
|
-
description: '单选框组件',
|
|
197
|
-
usage: '<em-radio-group v-model="value"><em-radio name="1">选项1</em-radio></em-radio-group>',
|
|
198
|
-
priority: 50
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
keywords: ['上传', 'upload', '文件', '图片上传'],
|
|
202
|
-
type: 'ui-component',
|
|
203
|
-
name: 'em-uploader',
|
|
204
|
-
description: '文件上传组件',
|
|
205
|
-
usage: '<em-uploader v-model="fileList" :after-read="afterRead" />',
|
|
206
|
-
priority: 50
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
keywords: ['搜索', 'search', '搜索框'],
|
|
210
|
-
type: 'ui-component',
|
|
211
|
-
name: 'em-search',
|
|
212
|
-
description: '搜索组件',
|
|
213
|
-
usage: '<em-search v-model="keyword" placeholder="请输入搜索关键词" />',
|
|
214
|
-
priority: 50
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
keywords: ['标签页', 'tab', '选项卡'],
|
|
218
|
-
type: 'ui-component',
|
|
219
|
-
name: 'em-tab',
|
|
220
|
-
description: '标签页组件',
|
|
221
|
-
usage: '<em-tabs v-model="active"><em-tab title="标签1">内容1</em-tab></em-tabs>',
|
|
222
|
-
priority: 50
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
keywords: ['下拉刷新', 'refresh', '刷新'],
|
|
226
|
-
type: 'ui-component',
|
|
227
|
-
name: 'em-minirefresh',
|
|
228
|
-
description: '下拉刷新组件',
|
|
229
|
-
usage: '<em-minirefresh @refresh="onRefresh" @loadmore="onLoadMore">...</em-minirefresh>',
|
|
230
|
-
priority: 50
|
|
231
|
-
}
|
|
232
|
-
];
|
|
233
|
-
/**
|
|
234
|
-
* Util 工具推荐映射
|
|
235
|
-
*/
|
|
236
|
-
const UTIL_MAPPINGS = [
|
|
237
|
-
{
|
|
238
|
-
keywords: ['请求', 'ajax', 'http', '接口', 'api'],
|
|
239
|
-
type: 'util-method',
|
|
240
|
-
name: 'Util.ajax',
|
|
241
|
-
description: 'HTTP 请求方法',
|
|
242
|
-
usage: "Util.ajax({ url: Config.serverUrl + '/api', type: 'POST', data: {} });",
|
|
243
|
-
priority: 80
|
|
244
|
-
},
|
|
245
|
-
{
|
|
246
|
-
keywords: ['格式化', '日期格式', 'format'],
|
|
247
|
-
type: 'util-method',
|
|
248
|
-
name: 'Util.date.format',
|
|
249
|
-
description: '日期格式化',
|
|
250
|
-
usage: "Util.date.format(new Date(), 'yyyy-MM-dd');",
|
|
251
|
-
priority: 60
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
keywords: ['字符串', '截取', '处理'],
|
|
255
|
-
type: 'util-method',
|
|
256
|
-
name: 'Util.string',
|
|
257
|
-
description: '字符串处理工具',
|
|
258
|
-
usage: "Util.string.trim(' hello ');",
|
|
259
|
-
priority: 60
|
|
260
|
-
}
|
|
261
|
-
];
|
|
262
|
-
/**
|
|
263
|
-
* 推荐引擎类
|
|
264
|
-
*/
|
|
265
|
-
export class RecommendationEngine {
|
|
266
|
-
/**
|
|
267
|
-
* 根据需求推荐解决方案
|
|
268
|
-
* @param requirement 需求描述
|
|
269
|
-
* @param type 需求类型(可选)
|
|
270
|
-
* @returns 推荐结果列表
|
|
271
|
-
*/
|
|
272
|
-
recommend(requirement, type) {
|
|
273
|
-
const normalizedReq = requirement.toLowerCase();
|
|
274
|
-
const results = [];
|
|
275
|
-
// 根据类型过滤映射
|
|
276
|
-
let mappings = [];
|
|
277
|
-
switch (type) {
|
|
278
|
-
case 'native':
|
|
279
|
-
mappings = EJS_API_MAPPINGS;
|
|
280
|
-
break;
|
|
281
|
-
case 'ui':
|
|
282
|
-
mappings = UI_COMPONENT_MAPPINGS;
|
|
283
|
-
break;
|
|
284
|
-
case 'data':
|
|
285
|
-
mappings = [...UTIL_MAPPINGS, ...EJS_API_MAPPINGS.filter(m => m.name.includes('storage'))];
|
|
286
|
-
break;
|
|
287
|
-
case 'general':
|
|
288
|
-
default:
|
|
289
|
-
// 所有映射,EJS API 优先级最高
|
|
290
|
-
mappings = [...EJS_API_MAPPINGS, ...UTIL_MAPPINGS, ...UI_COMPONENT_MAPPINGS];
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
// 匹配关键词
|
|
294
|
-
for (const mapping of mappings) {
|
|
295
|
-
const matchedKeywords = mapping.keywords.filter(kw => normalizedReq.includes(kw.toLowerCase()));
|
|
296
|
-
if (matchedKeywords.length > 0) {
|
|
297
|
-
// 计算匹配分数
|
|
298
|
-
const matchScore = matchedKeywords.length * 10;
|
|
299
|
-
const finalPriority = mapping.priority + matchScore;
|
|
300
|
-
results.push({
|
|
301
|
-
type: mapping.type,
|
|
302
|
-
name: mapping.name,
|
|
303
|
-
description: mapping.description,
|
|
304
|
-
reason: `匹配关键词: ${matchedKeywords.join(', ')}`,
|
|
305
|
-
priority: finalPriority,
|
|
306
|
-
usage: mapping.usage
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
// 按优先级排序(EJS API 优先)
|
|
311
|
-
results.sort((a, b) => {
|
|
312
|
-
// 首先按类型排序:ejs-api > util-method > ui-component
|
|
313
|
-
const typeOrder = {
|
|
314
|
-
'ejs-api': 3,
|
|
315
|
-
'util-method': 2,
|
|
316
|
-
'ui-component': 1
|
|
317
|
-
};
|
|
318
|
-
const typeCompare = typeOrder[b.type] - typeOrder[a.type];
|
|
319
|
-
if (typeCompare !== 0)
|
|
320
|
-
return typeCompare;
|
|
321
|
-
// 然后按优先级排序
|
|
322
|
-
return b.priority - a.priority;
|
|
323
|
-
});
|
|
324
|
-
// 去重
|
|
325
|
-
const seen = new Set();
|
|
326
|
-
const uniqueResults = results.filter(r => {
|
|
327
|
-
if (seen.has(r.name))
|
|
328
|
-
return false;
|
|
329
|
-
seen.add(r.name);
|
|
330
|
-
return true;
|
|
331
|
-
});
|
|
332
|
-
return uniqueResults;
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* 格式化推荐结果
|
|
336
|
-
* @param recommendations 推荐列表
|
|
337
|
-
* @returns 格式化的文本
|
|
338
|
-
*/
|
|
339
|
-
formatRecommendations(recommendations) {
|
|
340
|
-
if (recommendations.length === 0) {
|
|
341
|
-
return '未找到匹配的推荐方案。请尝试更详细地描述您的需求。';
|
|
342
|
-
}
|
|
343
|
-
const lines = ['# 推荐方案', ''];
|
|
344
|
-
// 按类型分组
|
|
345
|
-
const grouped = {
|
|
346
|
-
'ejs-api': [],
|
|
347
|
-
'util-method': [],
|
|
348
|
-
'ui-component': []
|
|
349
|
-
};
|
|
350
|
-
for (const rec of recommendations) {
|
|
351
|
-
grouped[rec.type].push(rec);
|
|
352
|
-
}
|
|
353
|
-
// EJS API 推荐
|
|
354
|
-
if (grouped['ejs-api'].length > 0) {
|
|
355
|
-
lines.push('## EJS 原生 API(推荐优先使用)');
|
|
356
|
-
lines.push('');
|
|
357
|
-
for (const rec of grouped['ejs-api']) {
|
|
358
|
-
lines.push(`### ${rec.name}`);
|
|
359
|
-
lines.push('');
|
|
360
|
-
lines.push(rec.description);
|
|
361
|
-
lines.push('');
|
|
362
|
-
lines.push(`**推荐原因**: ${rec.reason}`);
|
|
363
|
-
lines.push('');
|
|
364
|
-
lines.push('**使用示例**:');
|
|
365
|
-
lines.push('```javascript');
|
|
366
|
-
lines.push(rec.usage);
|
|
367
|
-
lines.push('```');
|
|
368
|
-
lines.push('');
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
// Util 工具推荐
|
|
372
|
-
if (grouped['util-method'].length > 0) {
|
|
373
|
-
lines.push('## Util 工具方法');
|
|
374
|
-
lines.push('');
|
|
375
|
-
for (const rec of grouped['util-method']) {
|
|
376
|
-
lines.push(`### ${rec.name}`);
|
|
377
|
-
lines.push('');
|
|
378
|
-
lines.push(rec.description);
|
|
379
|
-
lines.push('');
|
|
380
|
-
lines.push(`**推荐原因**: ${rec.reason}`);
|
|
381
|
-
lines.push('');
|
|
382
|
-
lines.push('**使用示例**:');
|
|
383
|
-
lines.push('```javascript');
|
|
384
|
-
lines.push(rec.usage);
|
|
385
|
-
lines.push('```');
|
|
386
|
-
lines.push('');
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
// UI 组件推荐
|
|
390
|
-
if (grouped['ui-component'].length > 0) {
|
|
391
|
-
lines.push('## UI 组件');
|
|
392
|
-
lines.push('');
|
|
393
|
-
for (const rec of grouped['ui-component']) {
|
|
394
|
-
lines.push(`### ${rec.name}`);
|
|
395
|
-
lines.push('');
|
|
396
|
-
lines.push(rec.description);
|
|
397
|
-
lines.push('');
|
|
398
|
-
lines.push(`**推荐原因**: ${rec.reason}`);
|
|
399
|
-
lines.push('');
|
|
400
|
-
lines.push('**使用示例**:');
|
|
401
|
-
lines.push('```vue');
|
|
402
|
-
lines.push(rec.usage);
|
|
403
|
-
lines.push('```');
|
|
404
|
-
lines.push('');
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
return lines.join('\n');
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
// 导出单例
|
|
411
|
-
export const recommendationEngine = new RecommendationEngine();
|
|
412
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
const m=[{keywords:["\u63D0\u793A","\u6D88\u606F","toast","\u8F7B\u63D0\u793A"],type:"ejs-api",name:"ejs.ui.toast",description:"\u663E\u793A\u8F7B\u63D0\u793A\u6D88\u606F",usage:"ejs.ui.toast({ message: '\u64CD\u4F5C\u6210\u529F' });",priority:100},{keywords:["\u5F39\u7A97","\u8B66\u544A","alert","\u63D0\u9192"],type:"ejs-api",name:"ejs.ui.alert",description:"\u663E\u793A\u8B66\u544A\u5F39\u7A97",usage:"ejs.ui.alert({ title: '\u63D0\u793A', message: '\u8FD9\u662F\u4E00\u6761\u6D88\u606F' });",priority:100},{keywords:["\u786E\u8BA4","confirm","\u8BE2\u95EE","\u662F\u5426"],type:"ejs-api",name:"ejs.ui.confirm",description:"\u663E\u793A\u786E\u8BA4\u5F39\u7A97",usage:"const result = await ejs.ui.confirm({ title: '\u786E\u8BA4', message: '\u786E\u5B9A\u8981\u6267\u884C\u5417\uFF1F' });",priority:100},{keywords:["\u52A0\u8F7D","loading","\u7B49\u5F85","\u8BF7\u7A0D\u5019"],type:"ejs-api",name:"ejs.ui.showWaiting",description:"\u663E\u793A\u52A0\u8F7D\u4E2D\u63D0\u793A",usage:"ejs.ui.showWaiting({ message: '\u52A0\u8F7D\u4E2D...' });",priority:100},{keywords:["\u9009\u62E9","\u9009\u9879","picker","\u4E0B\u62C9"],type:"ejs-api",name:"ejs.ui.picker",description:"\u663E\u793A\u9009\u62E9\u5668",usage:"const result = await ejs.ui.picker({ options: ['\u9009\u98791', '\u9009\u98792'] });",priority:100},{keywords:["\u65E5\u671F","date","\u5E74\u6708\u65E5"],type:"ejs-api",name:"ejs.ui.pickDate",description:"\u663E\u793A\u65E5\u671F\u9009\u62E9\u5668",usage:"const date = await ejs.ui.pickDate({ title: '\u9009\u62E9\u65E5\u671F' });",priority:100},{keywords:["\u65F6\u95F4","time","\u65F6\u5206"],type:"ejs-api",name:"ejs.ui.pickTime",description:"\u663E\u793A\u65F6\u95F4\u9009\u62E9\u5668",usage:"const time = await ejs.ui.pickTime({ title: '\u9009\u62E9\u65F6\u95F4' });",priority:100},{keywords:["\u8DF3\u8F6C","\u6253\u5F00","\u9875\u9762","open","\u5BFC\u822A"],type:"ejs-api",name:"ejs.page.open",description:"\u6253\u5F00\u65B0\u9875\u9762",usage:"ejs.page.open({ pageUrl: './detail', data: { id: '123' } });",priority:100},{keywords:["\u5173\u95ED","\u8FD4\u56DE","close","\u9000\u51FA"],type:"ejs-api",name:"ejs.page.close",description:"\u5173\u95ED\u5F53\u524D\u9875\u9762",usage:"ejs.page.close({ resultData: { status: 'success' } });",priority:100},{keywords:["\u6807\u9898","title","\u9875\u9762\u6807\u9898"],type:"ejs-api",name:"ejs.page.setTitle",description:"\u8BBE\u7F6E\u9875\u9762\u6807\u9898",usage:"ejs.page.setTitle({ title: '\u65B0\u6807\u9898' });",priority:100},{keywords:["\u5B58\u50A8","\u7F13\u5B58","storage","\u672C\u5730"],type:"ejs-api",name:"ejs.storage",description:"\u672C\u5730\u5B58\u50A8\u64CD\u4F5C",usage:"ejs.storage.setItem({ key: 'token', value: 'xxx' });",priority:100},{keywords:["\u626B\u7801","\u4E8C\u7EF4\u7801","scan","qrcode"],type:"ejs-api",name:"ejs.device.scan",description:"\u626B\u63CF\u4E8C\u7EF4\u7801/\u6761\u5F62\u7801",usage:"const result = await ejs.device.scan();",priority:100},{keywords:["\u62CD\u7167","\u76F8\u673A","camera","photo"],type:"ejs-api",name:"ejs.device.takePhoto",description:"\u62CD\u7167",usage:"const photo = await ejs.device.takePhoto({ quality: 80 });",priority:100}],u=[{keywords:["\u6309\u94AE","button","\u70B9\u51FB","\u63D0\u4EA4"],type:"ui-component",name:"em-button",description:"\u6309\u94AE\u7EC4\u4EF6\uFF0C\u652F\u6301\u591A\u79CD\u7C7B\u578B\u548C\u72B6\u6001",usage:'<em-button type="primary" @click="handleClick">\u63D0\u4EA4</em-button>',priority:50},{keywords:["\u8F93\u5165","input","\u6587\u672C\u6846","\u8868\u5355\u9879"],type:"ui-component",name:"em-field",description:"\u8F93\u5165\u6846\u7EC4\u4EF6\uFF0C\u652F\u6301\u591A\u79CD\u8F93\u5165\u7C7B\u578B",usage:'<em-field v-model="value" label="\u7528\u6237\u540D" placeholder="\u8BF7\u8F93\u5165" />',priority:50},{keywords:["\u5355\u5143\u683C","cell","\u5217\u8868\u9879","\u83DC\u5355\u9879"],type:"ui-component",name:"em-cell",description:"\u5355\u5143\u683C\u7EC4\u4EF6\uFF0C\u7528\u4E8E\u5C55\u793A\u5217\u8868\u9879",usage:'<em-cell title="\u6807\u9898" value="\u5185\u5BB9" is-link />',priority:50},{keywords:["\u8868\u5355","form","\u63D0\u4EA4","\u9A8C\u8BC1"],type:"ui-component",name:"em-form",description:"\u8868\u5355\u7EC4\u4EF6\uFF0C\u652F\u6301\u8868\u5355\u9A8C\u8BC1",usage:'<em-form ref="form" :model="formData" :rules="rules">...</em-form>',priority:50},{keywords:["\u5F39\u51FA\u5C42","popup","\u62BD\u5C49","\u5E95\u90E8\u5F39\u51FA"],type:"ui-component",name:"em-popup",description:"\u5F39\u51FA\u5C42\u7EC4\u4EF6",usage:'<em-popup v-model="show" position="bottom">\u5185\u5BB9</em-popup>',priority:50},{keywords:["\u9009\u62E9\u5668","picker","\u6EDA\u52A8\u9009\u62E9"],type:"ui-component",name:"em-picker",description:"\u9009\u62E9\u5668\u7EC4\u4EF6",usage:'<em-picker :columns="columns" @confirm="onConfirm" />',priority:50},{keywords:["\u65E5\u671F\u9009\u62E9","datepicker","\u65E5\u5386"],type:"ui-component",name:"em-datepicker",description:"\u65E5\u671F\u9009\u62E9\u5668\u7EC4\u4EF6",usage:'<em-datepicker v-model="date" type="date" />',priority:50},{keywords:["\u5F00\u5173","switch","\u5207\u6362"],type:"ui-component",name:"em-switch",description:"\u5F00\u5173\u7EC4\u4EF6",usage:'<em-switch v-model="checked" />',priority:50},{keywords:["\u590D\u9009\u6846","checkbox","\u591A\u9009"],type:"ui-component",name:"em-checkbox",description:"\u590D\u9009\u6846\u7EC4\u4EF6",usage:'<em-checkbox v-model="checked">\u9009\u9879</em-checkbox>',priority:50},{keywords:["\u5355\u9009\u6846","radio","\u5355\u9009"],type:"ui-component",name:"em-radio",description:"\u5355\u9009\u6846\u7EC4\u4EF6",usage:'<em-radio-group v-model="value"><em-radio name="1">\u9009\u98791</em-radio></em-radio-group>',priority:50},{keywords:["\u4E0A\u4F20","upload","\u6587\u4EF6","\u56FE\u7247\u4E0A\u4F20"],type:"ui-component",name:"em-uploader",description:"\u6587\u4EF6\u4E0A\u4F20\u7EC4\u4EF6",usage:'<em-uploader v-model="fileList" :after-read="afterRead" />',priority:50},{keywords:["\u641C\u7D22","search","\u641C\u7D22\u6846"],type:"ui-component",name:"em-search",description:"\u641C\u7D22\u7EC4\u4EF6",usage:'<em-search v-model="keyword" placeholder="\u8BF7\u8F93\u5165\u641C\u7D22\u5173\u952E\u8BCD" />',priority:50},{keywords:["\u6807\u7B7E\u9875","tab","\u9009\u9879\u5361"],type:"ui-component",name:"em-tab",description:"\u6807\u7B7E\u9875\u7EC4\u4EF6",usage:'<em-tabs v-model="active"><em-tab title="\u6807\u7B7E1">\u5185\u5BB91</em-tab></em-tabs>',priority:50},{keywords:["\u4E0B\u62C9\u5237\u65B0","refresh","\u5237\u65B0"],type:"ui-component",name:"em-minirefresh",description:"\u4E0B\u62C9\u5237\u65B0\u7EC4\u4EF6",usage:'<em-minirefresh @refresh="onRefresh" @loadmore="onLoadMore">...</em-minirefresh>',priority:50}],d=[{keywords:["\u8BF7\u6C42","ajax","http","\u63A5\u53E3","api"],type:"util-method",name:"Util.ajax",description:"HTTP \u8BF7\u6C42\u65B9\u6CD5",usage:"Util.ajax({ url: Config.serverUrl + '/api', type: 'POST', data: {} });",priority:80},{keywords:["\u683C\u5F0F\u5316","\u65E5\u671F\u683C\u5F0F","format"],type:"util-method",name:"Util.date.format",description:"\u65E5\u671F\u683C\u5F0F\u5316",usage:"Util.date.format(new Date(), 'yyyy-MM-dd');",priority:60},{keywords:["\u5B57\u7B26\u4E32","\u622A\u53D6","\u5904\u7406"],type:"util-method",name:"Util.string",description:"\u5B57\u7B26\u4E32\u5904\u7406\u5DE5\u5177",usage:"Util.string.trim(' hello ');",priority:60}];class y{recommend(a,e){const o=a.toLowerCase(),t=[];let p=[];switch(e){case"native":p=m;break;case"ui":p=u;break;case"data":p=[...d,...m.filter(i=>i.name.includes("storage"))];break;default:p=[...m,...d,...u];break}for(const i of p){const s=i.keywords.filter(r=>o.includes(r.toLowerCase()));if(s.length>0){const r=s.length*10,n=i.priority+r;t.push({type:i.type,name:i.name,description:i.description,reason:`\u5339\u914D\u5173\u952E\u8BCD: ${s.join(", ")}`,priority:n,usage:i.usage})}}t.sort((i,s)=>{const r={"ejs-api":3,"util-method":2,"ui-component":1},n=r[s.type]-r[i.type];return n!==0?n:s.priority-i.priority});const c=new Set;return t.filter(i=>c.has(i.name)?!1:(c.add(i.name),!0))}formatRecommendations(a){if(a.length===0)return"\u672A\u627E\u5230\u5339\u914D\u7684\u63A8\u8350\u65B9\u6848\u3002\u8BF7\u5C1D\u8BD5\u66F4\u8BE6\u7EC6\u5730\u63CF\u8FF0\u60A8\u7684\u9700\u6C42\u3002";const e=["# \u63A8\u8350\u65B9\u6848",""],o={"ejs-api":[],"util-method":[],"ui-component":[]};for(const t of a)o[t.type].push(t);if(o["ejs-api"].length>0){e.push("## EJS \u539F\u751F API\uFF08\u63A8\u8350\u4F18\u5148\u4F7F\u7528\uFF09"),e.push("");for(const t of o["ejs-api"])e.push(`### ${t.name}`),e.push(""),e.push(t.description),e.push(""),e.push(`**\u63A8\u8350\u539F\u56E0**: ${t.reason}`),e.push(""),e.push("**\u4F7F\u7528\u793A\u4F8B**:"),e.push("```javascript"),e.push(t.usage),e.push("```"),e.push("")}if(o["util-method"].length>0){e.push("## Util \u5DE5\u5177\u65B9\u6CD5"),e.push("");for(const t of o["util-method"])e.push(`### ${t.name}`),e.push(""),e.push(t.description),e.push(""),e.push(`**\u63A8\u8350\u539F\u56E0**: ${t.reason}`),e.push(""),e.push("**\u4F7F\u7528\u793A\u4F8B**:"),e.push("```javascript"),e.push(t.usage),e.push("```"),e.push("")}if(o["ui-component"].length>0){e.push("## UI \u7EC4\u4EF6"),e.push("");for(const t of o["ui-component"])e.push(`### ${t.name}`),e.push(""),e.push(t.description),e.push(""),e.push(`**\u63A8\u8350\u539F\u56E0**: ${t.reason}`),e.push(""),e.push("**\u4F7F\u7528\u793A\u4F8B**:"),e.push("```vue"),e.push(t.usage),e.push("```"),e.push("")}return e.join(`
|
|
2
|
+
`)}}const g=new y;export{y as RecommendationEngine,g as recommendationEngine};
|