feat: enrich AI requests with scene context and project root path
This commit is contained in:
@@ -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') {
|
||||
|
||||
@@ -79,8 +79,8 @@ function apiSavePlugin() {
|
||||
dedupMap.set(dedupKey, Date.now())
|
||||
|
||||
const modePrefix = mode === 'code'
|
||||
? '代码模式:直接修改 src/ 下的源码文件并保存。需求:'
|
||||
: 'JSON模式:只返回修改后的 JSON 文本,不要写任何文件。需求:'
|
||||
? `当前项目根目录: ${__dirname}\n代码模式:直接修改 src/ 下的源码文件并保存。需求:`
|
||||
: `当前项目根目录: ${__dirname}\nJSON模式:只返回修改后的 JSON 文本,不要写任何文件。需求:`
|
||||
const fullMessage = modePrefix + userMessage
|
||||
|
||||
const args = ['run', '--model', 'deepseek/deepseek-v4-pro', '--format', 'json']
|
||||
|
||||
Reference in New Issue
Block a user