fix(goal,ui): unwrap R envelope correctly in goal store

This commit is contained in:
matevip 2026-05-21 16:26:31 +08:00
parent e61b05bba0
commit 02407871f4

View File

@ -30,7 +30,11 @@ export const useGoalStore = defineStore('goal', () => {
loading.value = true loading.value = true
try { try {
const res: any = await goalApi.findActive(conversationId) const res: any = await goalApi.findActive(conversationId)
const goal: Goal | null = res?.data ?? res ?? null // mateclaw axios interceptor returns the R envelope itself:
// { code, msg, data: Goal | null }. The goal lives at .data; when
// the conversation has no active goal, .data is null (NOT undefined,
// so `?? res` would clobber it with the envelope — that was the bug).
const goal: Goal | null = res?.data ?? null
activeGoalByConv.value[conversationId] = goal activeGoalByConv.value[conversationId] = goal
return goal return goal
} catch (e) { } catch (e) {
@ -58,7 +62,7 @@ export const useGoalStore = defineStore('goal', () => {
exitCriteria: opts.exitCriteria, exitCriteria: opts.exitCriteria,
autoFollowupEnabled: opts.autoFollowup, autoFollowupEnabled: opts.autoFollowup,
}) })
const goal: Goal = res?.data ?? res const goal: Goal = res?.data
activeGoalByConv.value[conversationId] = goal activeGoalByConv.value[conversationId] = goal
return goal return goal
} catch (e) { } catch (e) {
@ -79,7 +83,7 @@ export const useGoalStore = defineStore('goal', () => {
async function pause(goal: Goal) { async function pause(goal: Goal) {
try { try {
const res: any = await goalApi.pause(goal.id) const res: any = await goalApi.pause(goal.id)
activeGoalByConv.value[goal.conversationId] = res?.data ?? res activeGoalByConv.value[goal.conversationId] = res?.data
} catch (e) { } catch (e) {
console.error('[goal] pause failed', e) console.error('[goal] pause failed', e)
} }
@ -88,7 +92,7 @@ export const useGoalStore = defineStore('goal', () => {
async function resume(goal: Goal) { async function resume(goal: Goal) {
try { try {
const res: any = await goalApi.resume(goal.id) const res: any = await goalApi.resume(goal.id)
activeGoalByConv.value[goal.conversationId] = res?.data ?? res activeGoalByConv.value[goal.conversationId] = res?.data
} catch (e) { } catch (e) {
console.error('[goal] resume failed', e) console.error('[goal] resume failed', e)
} }
@ -97,7 +101,7 @@ export const useGoalStore = defineStore('goal', () => {
async function loadEvents(goalId: string) { async function loadEvents(goalId: string) {
try { try {
const res: any = await goalApi.events(goalId) const res: any = await goalApi.events(goalId)
const events: GoalEvent[] = res?.data ?? res ?? [] const events: GoalEvent[] = res?.data ?? []
eventsByGoal.value[goalId] = events eventsByGoal.value[goalId] = events
return events return events
} catch (e) { } catch (e) {