From 9442471c98919acb929b99e58fc099710ffe381b Mon Sep 17 00:00:00 2001 From: iven Date: Thu, 9 Apr 2026 22:41:56 +0800 Subject: [PATCH] fix(relay): send conversation history to SaaS relay (BUG-008) SaaS Relay was sending only the current message without conversation history, giving LLM no context from previous turns. Root cause: streamStore passed only `content` string to chatStream(), and saas-relay-client hard-coded a single-element messages array. Fix: - GatewayClient.chatStream() opts: add `history` field - streamStore: extract last 20 messages as history before calling chatStream - saas-relay-client: build messages array from history + current message --- desktop/src/lib/gateway-client.ts | 2 ++ desktop/src/lib/saas-relay-client.ts | 9 ++++++++- desktop/src/store/chat/streamStore.ts | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/desktop/src/lib/gateway-client.ts b/desktop/src/lib/gateway-client.ts index 2fefc02..a100e47 100644 --- a/desktop/src/lib/gateway-client.ts +++ b/desktop/src/lib/gateway-client.ts @@ -481,6 +481,8 @@ export class GatewayClient { reasoning_effort?: string; plan_mode?: boolean; subagent_enabled?: boolean; + /** Conversation history for relay clients that need full context */ + history?: Array<{ role: string; content: string }>; } ): Promise<{ runId: string }> { const agentId = opts?.agentId || this.defaultAgentId; diff --git a/desktop/src/lib/saas-relay-client.ts b/desktop/src/lib/saas-relay-client.ts index a9360fc..96b1008 100644 --- a/desktop/src/lib/saas-relay-client.ts +++ b/desktop/src/lib/saas-relay-client.ts @@ -112,6 +112,7 @@ export function createSaaSRelayGatewayClient( reasoning_effort?: string; plan_mode?: boolean; subagent_enabled?: boolean; + history?: Array<{ role: string; content: string }>; }, ): Promise<{ runId: string }> { const runId = `run_${Date.now()}`; @@ -120,9 +121,15 @@ export function createSaaSRelayGatewayClient( const aborted = () => abortController.signal.aborted; try { + // Build messages array: use history if available, fallback to current message only + const history = opts?.history || []; + const messages = history.length > 0 + ? [...history, { role: 'user' as const, content: message }] + : [{ role: 'user' as const, content: message }]; + const body: Record = { model: getModel() || 'glm-4-flash-250414', - messages: [{ role: 'user', content: message }], + messages, stream: true, }; diff --git a/desktop/src/store/chat/streamStore.ts b/desktop/src/store/chat/streamStore.ts index 2107a15..56a0f92 100644 --- a/desktop/src/store/chat/streamStore.ts +++ b/desktop/src/store/chat/streamStore.ts @@ -296,6 +296,13 @@ export const useStreamStore = create()( useConversationStore.setState({ sessionKey: effectiveSessionKey }); } + // Build conversation history for relay clients (last 20 messages ≈ 10 turns) + const history = (_chat?.getMessages() || []) + .filter(m => m.role === 'user' || m.role === 'assistant') + .filter(m => !m.streaming && !m.optimistic) + .map(m => ({ role: m.role, content: m.content })) + .slice(-20); + const result = await client.chatStream( content, { @@ -528,6 +535,7 @@ export const useStreamStore = create()( reasoning_effort: get().getChatModeConfig().reasoning_effort, plan_mode: get().getChatModeConfig().plan_mode, subagent_enabled: get().getChatModeConfig().subagent_enabled, + history, } );