refactor: simplify AI panel workflow - direct file modification and reload from disk
This commit is contained in:
@@ -19,15 +19,9 @@ function toggleMode() {
|
||||
function buildMessage(userInput: string): string {
|
||||
if (mode.value !== 'json') return `需求: ${userInput}`
|
||||
|
||||
let ctx = `当前编辑文件: ${store.sourcePath}\n`
|
||||
if (store.selectedScene) {
|
||||
ctx += `选中场景: ${store.selectedScene.id}\n`
|
||||
ctx += `当前场景 JSON:\n${JSON.stringify(store.selectedScene, null, 2)}\n\n`
|
||||
} else if (Object.keys(store.gameData.scenes).length > 0) {
|
||||
const { scenes, ...rest } = store.gameData
|
||||
ctx += `全局配置:\n${JSON.stringify(rest, null, 2)}\n\n`
|
||||
}
|
||||
ctx += `需求: ${userInput}`
|
||||
let ctx = `修改文件 ${store.sourcePath}`
|
||||
if (store.selectedScene) ctx += `,针对场景节点 ${store.selectedScene.id}`
|
||||
ctx += `。需求: ${userInput}`
|
||||
return ctx
|
||||
}
|
||||
|
||||
@@ -51,14 +45,8 @@ async function send() {
|
||||
if (newSid) store.setAISessionId(newSid)
|
||||
|
||||
if (mode.value === 'json') {
|
||||
const clean = result.replace(/^```json\n?|\n?```$/g, '').trim()
|
||||
try {
|
||||
JSON.parse(clean)
|
||||
store.setAIResult(clean)
|
||||
messages.value.push({ role: 'assistant', content: '已生成 JSON,请查看编辑器面板' })
|
||||
} catch {
|
||||
messages.value.push({ role: 'assistant', content: result })
|
||||
}
|
||||
messages.value.push({ role: 'assistant', content: result || '已完成' })
|
||||
await store.reloadFromDisk()
|
||||
} else {
|
||||
messages.value.push({ role: 'assistant', content: result || '已完成' })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user