File tree Expand file tree Collapse file tree 3 files changed +23
-9
lines changed
packages/vue-generator/src
templates/vue-template/templateFiles/src/mcp Expand file tree Collapse file tree 3 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -196,8 +196,12 @@ function generateBaseConfig(config) {
196196 * @returns {string } 修改后的内容
197197 */
198198function 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}
Original file line number Diff line number Diff line change 11export 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}
Original file line number Diff line number Diff line change 11export 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"
88import type { WebMcpServer } from "@opentiny/next-sdk"
You can’t perform that action at this time.
0 commit comments