From 02407871f42365da466514b7e486eb561f3e96a9 Mon Sep 17 00:00:00 2001 From: matevip Date: Thu, 21 May 2026 16:26:31 +0800 Subject: [PATCH] fix(goal,ui): unwrap R envelope correctly in goal store --- mateclaw-ui/src/stores/useGoalStore.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mateclaw-ui/src/stores/useGoalStore.ts b/mateclaw-ui/src/stores/useGoalStore.ts index 50a3f5bd..1f7b3433 100644 --- a/mateclaw-ui/src/stores/useGoalStore.ts +++ b/mateclaw-ui/src/stores/useGoalStore.ts @@ -30,7 +30,11 @@ export const useGoalStore = defineStore('goal', () => { loading.value = true try { 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 return goal } catch (e) { @@ -58,7 +62,7 @@ export const useGoalStore = defineStore('goal', () => { exitCriteria: opts.exitCriteria, autoFollowupEnabled: opts.autoFollowup, }) - const goal: Goal = res?.data ?? res + const goal: Goal = res?.data activeGoalByConv.value[conversationId] = goal return goal } catch (e) { @@ -79,7 +83,7 @@ export const useGoalStore = defineStore('goal', () => { async function pause(goal: Goal) { try { const res: any = await goalApi.pause(goal.id) - activeGoalByConv.value[goal.conversationId] = res?.data ?? res + activeGoalByConv.value[goal.conversationId] = res?.data } catch (e) { console.error('[goal] pause failed', e) } @@ -88,7 +92,7 @@ export const useGoalStore = defineStore('goal', () => { async function resume(goal: Goal) { try { const res: any = await goalApi.resume(goal.id) - activeGoalByConv.value[goal.conversationId] = res?.data ?? res + activeGoalByConv.value[goal.conversationId] = res?.data } catch (e) { console.error('[goal] resume failed', e) } @@ -97,7 +101,7 @@ export const useGoalStore = defineStore('goal', () => { async function loadEvents(goalId: string) { try { const res: any = await goalApi.events(goalId) - const events: GoalEvent[] = res?.data ?? res ?? [] + const events: GoalEvent[] = res?.data ?? [] eventsByGoal.value[goalId] = events return events } catch (e) {