|
2 | 2 | import React, { useCallback, useEffect, useMemo, useState } from 'react'; |
3 | 3 | import { observer } from 'mobx-react-lite'; |
4 | 4 | import { useStores } from 'store'; |
5 | | -import { EuiGlobalToastList, EuiFlexGroup, EuiFlexItem, EuiPanel, EuiIcon } from '@elastic/eui'; |
| 5 | +import { |
| 6 | + EuiGlobalToastList, |
| 7 | + EuiFlexGroup, |
| 8 | + EuiFlexItem, |
| 9 | + EuiPanel, |
| 10 | + EuiIcon, |
| 11 | + EuiLoadingSpinner |
| 12 | +} from '@elastic/eui'; |
6 | 13 | import { renderMarkdown } from 'people/utils/RenderMarkdown.tsx'; |
7 | 14 | import styled from 'styled-components'; |
8 | 15 | import history from 'config/history.ts'; |
@@ -292,8 +299,9 @@ const TicketEditor = observer( |
292 | 299 | const [activeMode, setActiveMode] = useState<'preview' | 'edit'>('edit'); |
293 | 300 | const [isThinking, setIsThinking] = useState<'speed' | 'thinking'>('thinking'); |
294 | 301 | const [isButtonDisabled, setIsButtonDisabled] = useState(true); |
295 | | - const { main } = useStores(); |
| 302 | + const { chat, main } = useStores(); |
296 | 303 | const [isCreatingBounty, setIsCreatingBounty] = useState(false); |
| 304 | + const [isStartingTask, setIsStartingTask] = useState(false); |
297 | 305 | const [isOptionsMenuVisible, setIsOptionsMenuVisible] = useState(false); |
298 | 306 | const [lastLogLine, setLastLogLine] = useState(''); |
299 | 307 | const ui = uiStore; |
@@ -628,6 +636,55 @@ const TicketEditor = observer( |
628 | 636 | } |
629 | 637 | }; |
630 | 638 |
|
| 639 | + const handleStartTask = async () => { |
| 640 | + if (isStartingTask) return; |
| 641 | + |
| 642 | + setIsStartingTask(true); |
| 643 | + try { |
| 644 | + const newChat = await chat.createChat(workspaceUUID as string, 'New Chat'); |
| 645 | + const question = `${versionTicketData.name}\n\n${versionTicketData.description}`; |
| 646 | + |
| 647 | + if (newChat && newChat.id) { |
| 648 | + const sentMessage = await chat.sendMessage( |
| 649 | + newChat.id, |
| 650 | + question, |
| 651 | + 'gpt-4o', |
| 652 | + websocketSessionId, |
| 653 | + workspaceUUID, |
| 654 | + 'Build', |
| 655 | + undefined |
| 656 | + ); |
| 657 | + if (sentMessage) { |
| 658 | + chat.addMessage(sentMessage); |
| 659 | + setToasts([ |
| 660 | + { |
| 661 | + id: `${Date.now()}-start-task-success`, |
| 662 | + title: 'Task Started', |
| 663 | + color: 'success', |
| 664 | + text: 'Hive chat session started successfully!' |
| 665 | + } |
| 666 | + ]); |
| 667 | + } else { |
| 668 | + throw new Error('Failed to start task'); |
| 669 | + } |
| 670 | + |
| 671 | + window.open(`/workspace/${workspaceUUID}/hivechat/${newChat.id}`, '_blank'); |
| 672 | + } |
| 673 | + } catch (error) { |
| 674 | + console.error('Error starting task:', error); |
| 675 | + setToasts([ |
| 676 | + { |
| 677 | + id: `${Date.now()}-start-task-error`, |
| 678 | + title: 'Error', |
| 679 | + color: 'danger', |
| 680 | + text: 'Failed to start task. Please try again.' |
| 681 | + } |
| 682 | + ]); |
| 683 | + } finally { |
| 684 | + setIsStartingTask(false); |
| 685 | + } |
| 686 | + }; |
| 687 | + |
631 | 688 | const handleDeleteTicket = async () => { |
632 | 689 | const success = await main.deleteTicket(ticketData.uuid); |
633 | 690 | if (success) { |
@@ -927,6 +984,14 @@ const TicketEditor = observer( |
927 | 984 | SW Run: {swwfLink} |
928 | 985 | </ActionButton> |
929 | 986 | )} |
| 987 | + <ActionButton |
| 988 | + color="primary" |
| 989 | + onClick={handleStartTask} |
| 990 | + disabled={isStartingTask} |
| 991 | + data-testid="start-task-btn" |
| 992 | + > |
| 993 | + {isStartingTask ? <EuiLoadingSpinner size="m" /> : 'Start Task'} |
| 994 | + </ActionButton> |
930 | 995 | <ActionButton |
931 | 996 | color="#49C998" |
932 | 997 | onClick={handleTicketBuilder} |
|
0 commit comments