refactor(mini-program): runGeneration+交互函数改为操作对话消息
This commit is contained in:
@@ -1661,8 +1661,11 @@ const runGeneration = async ({ prompt, displayText, source = 'text', saveTheme }
|
||||
streamWriter.reset()
|
||||
startGenerationFeedback()
|
||||
ttsPlayer.reset()
|
||||
viewState.value = 'generating'
|
||||
keepGenerationAtBottom()
|
||||
viewState.value = 'chat'
|
||||
generationPhase.value = 'generating'
|
||||
resultMessages.value = []
|
||||
addResultMessage({ role: 'user', kind: 'text', content: display })
|
||||
keepResultAtBottom()
|
||||
|
||||
try {
|
||||
currentStreamTask.value = startNovelStream({
|
||||
@@ -1745,37 +1748,50 @@ const handleShortNovelEvent = (event) => {
|
||||
}
|
||||
}
|
||||
|
||||
const submitClarification = (answer) => {
|
||||
const submitClarification = (msg, answer) => {
|
||||
if (answeringClarification.value) return
|
||||
if (msg) {
|
||||
msg.submitted = true
|
||||
msg.answer = answer
|
||||
}
|
||||
addResultMessage({ role: 'user', kind: 'text', content: answer })
|
||||
answeringClarification.value = true
|
||||
currentStreamTask.value = followupStream({
|
||||
sessionId: novelSessionId.value,
|
||||
action: 'answer_clarification',
|
||||
payload: { answer },
|
||||
onEvent: handleShortNovelEvent,
|
||||
onError: (msg) => markGenerationFailed(msg)
|
||||
onError: (errMsg) => markGenerationFailed(errMsg)
|
||||
})
|
||||
setTimeout(() => { answeringClarification.value = false }, 200)
|
||||
}
|
||||
|
||||
const confirmOutline = () => {
|
||||
const confirmOutline = (msg) => {
|
||||
if (msg) msg.confirmed = true
|
||||
addResultMessage({ role: 'user', kind: 'text', content: '确认大纲' })
|
||||
currentStreamTask.value = followupStream({
|
||||
sessionId: novelSessionId.value,
|
||||
action: 'confirm_outline',
|
||||
payload: null,
|
||||
onEvent: handleShortNovelEvent,
|
||||
onError: (msg) => markGenerationFailed(msg)
|
||||
onError: (errMsg) => markGenerationFailed(errMsg)
|
||||
})
|
||||
}
|
||||
|
||||
const modifyOutline = (feedback) => {
|
||||
if (!feedback || !feedback.trim()) return
|
||||
const modifyOutline = (msg) => {
|
||||
const feedback = msg?.feedback || ''
|
||||
if (!feedback.trim()) {
|
||||
uni.showToast({ title: '请先填写修改意见', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (msg) msg.confirmed = true
|
||||
addResultMessage({ role: 'user', kind: 'text', content: feedback })
|
||||
currentStreamTask.value = followupStream({
|
||||
sessionId: novelSessionId.value,
|
||||
action: 'modify_outline',
|
||||
payload: { feedback },
|
||||
onEvent: handleShortNovelEvent,
|
||||
onError: (msg) => markGenerationFailed(msg)
|
||||
onError: (errMsg) => markGenerationFailed(errMsg)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1784,15 +1800,13 @@ const resumeSession = () => {
|
||||
novelSessionId.value = resumeableSessionId.value
|
||||
resumeableSessionId.value = ''
|
||||
generating.value = true
|
||||
streamContent.value = ''
|
||||
novelFullText.value = ''
|
||||
generationPhase.value = 'generating'
|
||||
generationStatus.value = 'waiting'
|
||||
generationError.value = ''
|
||||
generationDisplayText.value = '继续之前的创作'
|
||||
addResultMessage({ role: 'user', kind: 'text', content: '继续之前的创作' })
|
||||
streamWriter.reset()
|
||||
startGenerationFeedback()
|
||||
viewState.value = 'generating'
|
||||
keepGenerationAtBottom()
|
||||
keepResultAtBottom()
|
||||
|
||||
try {
|
||||
currentStreamTask.value = followupStream({
|
||||
@@ -1800,11 +1814,11 @@ const resumeSession = () => {
|
||||
action: 'retry',
|
||||
payload: null,
|
||||
onEvent: handleShortNovelEvent,
|
||||
onError: (msg) => {
|
||||
markGenerationFailed(msg)
|
||||
onError: (errMsg) => {
|
||||
markGenerationFailed(errMsg)
|
||||
analytics.track('script_generate_fail', {
|
||||
source: 'resume',
|
||||
error: msg
|
||||
error: errMsg
|
||||
}, { eventType: 'script', pagePath })
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user