refactor: simplify AI panel workflow - direct file modification and reload from disk
This commit is contained in:
@@ -80,7 +80,7 @@ function apiSavePlugin() {
|
||||
|
||||
const modePrefix = mode === 'code'
|
||||
? `当前项目根目录: ${__dirname}\n代码模式:直接修改 src/ 下的源码文件并保存。需求:`
|
||||
: `当前项目根目录: ${__dirname}\nJSON模式:只返回修改后的 JSON 文本,不要写任何文件。需求:`
|
||||
: `当前项目根目录: ${__dirname}\nJSON模式:直接修改 JSON 配置文件并保存,用自然语言回复修改了什么。需求:`
|
||||
const fullMessage = modePrefix + userMessage
|
||||
|
||||
const args = ['run', '--model', 'deepseek/deepseek-v4-pro', '--format', 'json']
|
||||
@@ -131,16 +131,8 @@ function apiSavePlugin() {
|
||||
}
|
||||
|
||||
if (mode === 'json') {
|
||||
const codeBlock = aiText.match(/```(?:json)?\s*\n?([\s\S]*?)\n?\s*```/)
|
||||
let jsonStr = codeBlock ? codeBlock[1] : aiText
|
||||
try {
|
||||
JSON.parse(jsonStr)
|
||||
} catch {
|
||||
const bareMatch = aiText.match(/(\{[\s\S]*\}|\[[\s\S]*\])/)
|
||||
jsonStr = bareMatch ? bareMatch[0] : aiText
|
||||
}
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' })
|
||||
res.end(JSON.stringify({ result: jsonStr, sessionId: resolvedSessionId || '' }))
|
||||
res.end(JSON.stringify({ result: aiText || 'done', sessionId: resolvedSessionId || '' }))
|
||||
} else {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' })
|
||||
res.end(JSON.stringify({ result: aiText || 'done', sessionId: resolvedSessionId || '' }))
|
||||
|
||||
Reference in New Issue
Block a user