From 04f0a3930062e2d4d8806fd5f9eb2f6f346fb398 Mon Sep 17 00:00:00 2001 From: yiling Date: Thu, 30 Jul 2026 17:01:03 +0800 Subject: [PATCH 1/2] fix(webui): persist chatbot sidebar input text across route navigation --- packages/webui/components/chatbot-sidebar.tsx | 5 +++-- packages/webui/stores/chatbot.test.ts | 17 +++++++++++++++++ packages/webui/stores/chatbot.ts | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/webui/components/chatbot-sidebar.tsx b/packages/webui/components/chatbot-sidebar.tsx index 652ca178..31cbfd6d 100644 --- a/packages/webui/components/chatbot-sidebar.tsx +++ b/packages/webui/components/chatbot-sidebar.tsx @@ -26,7 +26,7 @@ import { Trash2, Wrench, } from 'lucide-react' -import { useCallback, useEffect, useRef, useState } from 'react' +import { useCallback, useEffect, useRef } from 'react' import Markdown from 'react-markdown' import { formatTimeAgo } from '../lib/time' @@ -53,6 +53,8 @@ export function ChatbotSidebar({ projectId, contextAssetId }: ChatbotSidebarProp abortActiveSession, selectedAgentId, setSelectedAgentId, + inputText, + setInputText, } = useChatbotStore() const { teamId, ensureTeamIdForProject } = useTeamContextStore() @@ -87,7 +89,6 @@ export function ChatbotSidebar({ projectId, contextAssetId }: ChatbotSidebarProp } }, [chatAgents, selectedAgentId, setSelectedAgentId]) - const [inputText, setInputText] = useState('') const messagesEndRef = useRef(null) const scrollAreaRef = useRef(null) const isFirstScrollRef = useRef(true) diff --git a/packages/webui/stores/chatbot.test.ts b/packages/webui/stores/chatbot.test.ts index 60998290..9d023fd7 100644 --- a/packages/webui/stores/chatbot.test.ts +++ b/packages/webui/stores/chatbot.test.ts @@ -39,9 +39,26 @@ describe('useChatbotStore', () => { historySessions: [], isStreaming: false, selectedAgentId: 'agent-1', + inputText: '', }) }) + it('should persist and reset inputText', () => { + expect(useChatbotStore.getState().inputText).toBe('') + useChatbotStore.getState().setInputText('Draft text in progress') + expect(useChatbotStore.getState().inputText).toBe('Draft text in progress') + + useChatbotStore.setState({ + currentSessionId: 'sess-abc', + messages: [{ id: 'msg-1', role: 'user', content: 'test' } as unknown as ChatMessage], + }) + // Navigating or changing other state does not wipe inputText + expect(useChatbotStore.getState().inputText).toBe('Draft text in progress') + + useChatbotStore.getState().startNewSession() + expect(useChatbotStore.getState().inputText).toBe('') + }) + it('should add, remove and clear assets in context', () => { const store = useChatbotStore.getState() expect(store.chatAssets).toHaveLength(0) diff --git a/packages/webui/stores/chatbot.ts b/packages/webui/stores/chatbot.ts index f31a698f..e0b7b581 100644 --- a/packages/webui/stores/chatbot.ts +++ b/packages/webui/stores/chatbot.ts @@ -28,6 +28,8 @@ interface ChatbotState { setIsStreaming: (streaming: boolean) => void selectedAgentId: string | null setSelectedAgentId: (id: string | null) => void + inputText: string + setInputText: (text: string) => void scrollTop: number isAtBottom: boolean @@ -74,6 +76,8 @@ export const useChatbotStore = create((set) => ({ setIsStreaming: (streaming) => set({ isStreaming: streaming }), selectedAgentId: null, setSelectedAgentId: (id) => set({ selectedAgentId: id }), + inputText: '', + setInputText: (text) => set({ inputText: text }), scrollTop: 0, isAtBottom: true, setScrollState: (scrollTop, isAtBottom) => set({ scrollTop, isAtBottom }), @@ -147,6 +151,7 @@ export const useChatbotStore = create((set) => ({ currentSessionId: null, messages: [], chatAssets: [], + inputText: '', scrollTop: 0, isAtBottom: true, }) From 87ccbe5330c9245ad4ada87ebbec1adc233de100 Mon Sep 17 00:00:00 2001 From: yiling Date: Thu, 30 Jul 2026 17:08:29 +0800 Subject: [PATCH 2/2] feat(agent): instruct agent to check if folder exists with list_assets before calling create_folder --- packages/agent/src/activities/agent.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/agent/src/activities/agent.ts b/packages/agent/src/activities/agent.ts index b802a9c5..a1c5b687 100644 --- a/packages/agent/src/activities/agent.ts +++ b/packages/agent/src/activities/agent.ts @@ -92,7 +92,7 @@ async function executeAgentPrompt(params: { let systemPrompt = `You are the AI assistant for shumai. shumai is a professional creative collaboration platform similar to frame.io, where users can upload creative files, manage projects, assign tasks, get precise feedback, and share their work. As the agent, your role is to help users use and manage this platform. -shumai has its own cloud file system. If a user asks you to perform file system operations (for example: creating a folder, creating a file, stacking a version, or listing assets), you MUST use the corresponding agent system tools (e.g., 'create_folder', 'create_file', 'create_version', 'list_assets'). Do NOT use local bash commands or the local bash tool to perform these operations locally on the host environment; all operations must be executed through the platform's cloud file system tools so they are correctly registered and visible within the platform. +shumai has its own cloud file system. If a user asks you to perform file system operations (for example: creating a folder, creating a file, stacking a version, or listing assets), you MUST use the corresponding agent system tools (e.g., 'create_folder', 'create_file', 'create_version', 'list_assets'). Before calling 'create_folder', first check if the folder exists using 'list_assets'. Do NOT use local bash commands or the local bash tool to perform these operations locally on the host environment; all operations must be executed through the platform's cloud file system tools so they are correctly registered and visible within the platform. If you need to create files in the local filesystem (for example, a temporary file for uploading), only the '.pi' folder in the current directory has write permissions. Do NOT attempt to create files in any other directories.`