feat(agent): support aborting agent execution in local and temporal modes

This commit is contained in:
yiling
2026-07-14 10:25:06 +08:00
parent e772581542
commit 8a942d4f4e
15 changed files with 428 additions and 39 deletions
+28 -12
View File
@@ -23,6 +23,7 @@ import {
History,
Loader2,
Plus,
Square,
Trash2,
Wrench,
} from 'lucide-react'
@@ -50,6 +51,7 @@ export function ChatbotSidebar({ projectId, contextAssetId }: ChatbotSidebarProp
deleteSession,
startNewSession,
sendMessage,
abortActiveSession,
selectedAgentId,
setSelectedAgentId,
} = useChatbotStore()
@@ -637,18 +639,32 @@ export function ChatbotSidebar({ projectId, contextAssetId }: ChatbotSidebarProp
)}
</div>
<button
onClick={handleSend}
disabled={isStreaming || !inputText.trim() || !selectedAgentId}
className={cn(
'p-2 rounded-full transition-all duration-200 flex items-center justify-center shrink-0 shadow-sm',
inputText.trim() && !isStreaming && selectedAgentId
? 'bg-primary text-primary-foreground hover:bg-primary/95 transform hover:-translate-y-0.5'
: 'bg-muted text-muted-foreground cursor-not-allowed opacity-50',
)}
>
<ArrowUp className="h-4 w-4" />
</button>
{isStreaming ? (
<button
onClick={() => {
if (teamId) {
abortActiveSession(teamId)
}
}}
className="p-2 rounded-full transition-all duration-200 flex items-center justify-center shrink-0 shadow-sm bg-destructive text-destructive-foreground hover:bg-destructive/90 transform hover:-translate-y-0.5"
title="Stop generation"
>
<Square className="h-4 w-4" />
</button>
) : (
<button
onClick={handleSend}
disabled={!inputText.trim() || !selectedAgentId}
className={cn(
'p-2 rounded-full transition-all duration-200 flex items-center justify-center shrink-0 shadow-sm',
inputText.trim() && selectedAgentId
? 'bg-primary text-primary-foreground hover:bg-primary/95 transform hover:-translate-y-0.5'
: 'bg-muted text-muted-foreground cursor-not-allowed opacity-50',
)}
>
<ArrowUp className="h-4 w-4" />
</button>
)}
</div>
</div>
</div>
+20
View File
@@ -43,6 +43,7 @@ interface ChatbotState {
projectId: string,
contextAssetId?: string,
) => Promise<void>
abortActiveSession: (teamId: string) => Promise<void>
}
export const useChatbotStore = create<ChatbotState>((set) => ({
@@ -303,4 +304,23 @@ export const useChatbotStore = create<ChatbotState>((set) => ({
set({ isStreaming: false })
}
},
abortActiveSession: async (teamId) => {
const { currentSessionId, isStreaming } = useChatbotStore.getState()
if (!currentSessionId || !isStreaming) return
try {
const res = await client.api.teams[':teamId'].chat.sessions[':sessionId'].abort.$post({
param: { teamId, sessionId: currentSessionId },
})
if (res.ok) {
toast.success('Agent execution stopped')
} else {
throw new Error('Failed to abort agent execution')
}
} catch (err) {
const errMsg = err instanceof Error ? err.message : 'Failed to abort execution'
toast.error(errMsg)
}
},
}))