Skip to content

Commit 4ceda53

Browse files
committed
fix: review suggestion
1 parent f048f9c commit 4ceda53

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

packages/vue-generator/src/plugins/genMcpPlugin.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,12 @@ function generateBaseConfig(config) {
196196
* @returns {string} 修改后的内容
197197
*/
198198
function modifyMainTs(originalContent) {
199-
// 如果已经包含 tiny-robot 样式,则不重复添加
200-
if (originalContent.includes('@opentiny/tiny-robot/dist/style.css')) {
199+
// 检查是否已经包含两个样式导入
200+
const hasTinyRobot = originalContent.includes('@opentiny/tiny-robot/dist/style.css')
201+
const hasNextRemoter = originalContent.includes('@opentiny/next-remoter/dist/style.css')
202+
203+
// 如果两个都已存在,直接返回
204+
if (hasTinyRobot && hasNextRemoter) {
201205
return originalContent
202206
}
203207

@@ -214,9 +218,15 @@ function modifyMainTs(originalContent) {
214218
}
215219
}
216220

217-
// 插入 MCP 样式导入
218-
lines.splice(insertIndex, 0, "import '@opentiny/tiny-robot/dist/style.css'")
219-
lines.splice(insertIndex + 1, 0, "import '@opentiny/next-remoter/dist/style.css'")
221+
// 只插入缺失的样式导入
222+
if (!hasTinyRobot) {
223+
lines.splice(insertIndex, 0, "import '@opentiny/tiny-robot/dist/style.css'")
224+
insertIndex++ // 更新插入位置
225+
}
226+
227+
if (!hasNextRemoter) {
228+
lines.splice(insertIndex, 0, "import '@opentiny/next-remoter/dist/style.css'")
229+
}
220230

221231
return lines.join('\n')
222232
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
export default (schema, options) => {
22
const { agentRoot, sessionId } = options
33

4-
return `export const AGENT_ROOT = '${agentRoot}'
5-
export const SESSION_ID = '${sessionId}'`
4+
// 转义单引号以防止生成的代码出现语法错误
5+
const escapedAgentRoot = (agentRoot || '').replace(/'/g, "\\'")
6+
const escapedSessionId = (sessionId || '').replace(/'/g, "\\'")
7+
8+
return `export const AGENT_ROOT = '${escapedAgentRoot}'
9+
export const SESSION_ID = '${escapedSessionId}'`
610
}

packages/vue-generator/src/templates/vue-template/templateFiles/src/mcp/tools/navigationTools.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export default (schema, options) => {
22
const { routes } = options
33

4-
// 生成路由枚举
5-
const routeEnum = routes.map((route) => `"${route}"`).join(', ')
4+
// 生成路由枚举,使用 JSON.stringify 来正确转义特殊字符
5+
const routeEnum = routes.map((route) => JSON.stringify(route)).join(', ')
66

77
return `import { z } from "@opentiny/next-sdk"
88
import type { WebMcpServer } from "@opentiny/next-sdk"

0 commit comments

Comments
 (0)