feat: enrich AI requests with scene context and project root path

This commit is contained in:
2026-06-15 14:31:23 +08:00
parent 5f717ac3b6
commit 395c55b6b0
2 changed files with 22 additions and 6 deletions

View File

@@ -16,9 +16,24 @@ function toggleMode() {
mode.value = mode.value === 'json' ? 'code' : 'json'
}
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}`
return ctx
}
async function send() {
const msg = inputText.value.trim()
if (!msg || loading.value) return
const userInput = inputText.value.trim()
if (!userInput || loading.value) return
inputText.value = ''
errorMsg.value = ''
@@ -27,11 +42,12 @@ async function send() {
return
}
messages.value.push({ role: 'user', content: msg })
const fullMessage = buildMessage(userInput)
messages.value.push({ role: 'user', content: userInput })
loading.value = true
try {
const { result, sessionId: newSid } = await sendAIRequest(msg, mode.value, store.deepseekKey, store.aiSessionId || undefined)
const { result, sessionId: newSid } = await sendAIRequest(fullMessage, mode.value, store.deepseekKey, store.aiSessionId || undefined)
if (newSid) store.setAISessionId(newSid)
if (mode.value === 'json') {