Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
improvement(mothership): show continue options on abort#3746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -85,6 +85,8 @@ const STATE_TO_STATUS: Record<string, ToolCallStatus> = { | ||
| const DEPLOY_TOOL_NAMES = new Set(['deploy_api', 'deploy_chat', 'deploy_mcp', 'redeploy']) | ||
| const RECONNECT_TAIL_ERROR = | ||
| 'Live reconnect failed before the stream finished. The latest response may be incomplete.' | ||
| const CONTINUE_OPTIONS_CONTENT = | ||
| '<options>{"continue":{"title":"Continue","description":"Pick up where we left off"}}</options>' | ||
| function mapStoredBlock(block: TaskStoredContentBlock): ContentBlock { | ||
| const mapped: ContentBlock = { | ||
| @@ -1190,16 +1192,22 @@ export function useChat( | ||
| if (storedBlocks.length > 0) { | ||
| storedBlocks.push({ type: 'stopped' }) | ||
| storedBlocks.push({ type: 'text', content: CONTINUE_OPTIONS_CONTENT }) | ||
| } | ||
| const persistedContent = | ||
| content && !content.includes('<options>') | ||
| ? `${content}\n\n${CONTINUE_OPTIONS_CONTENT}` | ||
| : content | ||
| try { | ||
| const res = await fetch(stopPathRef.current, { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ | ||
| chatId, | ||
| streamId, | ||
| content, | ||
| content: persistedContent, | ||
| ...(storedBlocks.length > 0 && { contentBlocks: storedBlocks }), | ||
| }), | ||
| }) | ||
| @@ -1225,6 +1233,50 @@ export function useChat( | ||
| const messagesRef = useRef(messages) | ||
| messagesRef.current = messages | ||
| const resolveInterruptedToolCalls = useCallback(() => { | ||
| setMessages((prev) => { | ||
| const hasAnyExecuting = prev.some((m) => | ||
| m.contentBlocks?.some((b) => b.toolCall?.status === 'executing') | ||
| ) | ||
| if (!hasAnyExecuting) return prev | ||
| let lastAssistantIdx = -1 | ||
| for (let i = prev.length - 1; i >= 0; i--) { | ||
| if (prev[i].role === 'assistant') { | ||
| lastAssistantIdx = i | ||
| break | ||
| } | ||
| } | ||
| return prev.map((msg, idx) => { | ||
| const hasExecuting = msg.contentBlocks?.some((b) => b.toolCall?.status === 'executing') | ||
| const isLastAssistant = idx === lastAssistantIdx | ||
| if (!hasExecuting && !isLastAssistant) return msg | ||
| const blocks: ContentBlock[] = (msg.contentBlocks ?? []).map((block) => { | ||
| if (block.toolCall?.status !== 'executing') return block | ||
| return { | ||
| ...block, | ||
| toolCall: { | ||
| ...block.toolCall, | ||
| status: 'cancelled' as const, | ||
| displayTitle: 'Stopped', | ||
| }, | ||
| } | ||
| }) | ||
| if (isLastAssistant && !blocks.some((b) => b.type === 'stopped')) { | ||
| blocks.push({ type: 'stopped' as const }) | ||
| } | ||
| if ( | ||
| isLastAssistant && | ||
| !blocks.some((b) => b.type === 'text' && b.content?.includes('<options>')) | ||
| ) { | ||
| blocks.push({ type: 'text', content: CONTINUE_OPTIONS_CONTENT }) | ||
| } | ||
| return { ...msg, contentBlocks: blocks.length > 0 ? blocks : msg.contentBlocks } | ||
| }) | ||
| }) | ||
| }, []) | ||
| const finalize = useCallback( | ||
| (options?: { error?: boolean }) => { | ||
| sendingRef.current = false | ||
| @@ -1239,6 +1291,8 @@ export function useChat( | ||
| } | ||
Sg312 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| resolveInterruptedToolCalls() | ||
| if (options?.error) { | ||
| setMessageQueue([]) | ||
| return | ||
| @@ -1254,7 +1308,7 @@ export function useChat( | ||
| }) | ||
| } | ||
| }, | ||
| [invalidateChatQueries] | ||
| [invalidateChatQueries, resolveInterruptedToolCalls] | ||
| ) | ||
| finalizeRef.current = finalize | ||
| @@ -1412,24 +1466,7 @@ export function useChat( | ||
| sendingRef.current = false | ||
| setIsSending(false) | ||
| setMessages((prev) => | ||
| prev.map((msg) => { | ||
| if (!msg.contentBlocks?.some((b) => b.toolCall?.status === 'executing')) return msg | ||
| const updated = msg.contentBlocks!.map((block) => { | ||
| if (block.toolCall?.status !== 'executing') return block | ||
| return { | ||
| ...block, | ||
| toolCall: { | ||
| ...block.toolCall, | ||
| status: 'cancelled' as const, | ||
| displayTitle: 'Stopped by user', | ||
| }, | ||
| } | ||
| }) | ||
| updated.push({ type: 'stopped' as const }) | ||
| return { ...msg, contentBlocks: updated } | ||
| }) | ||
| ) | ||
| resolveInterruptedToolCalls() | ||
| if (sid) { | ||
| fetch('/api/copilot/chat/abort', { | ||
| @@ -1495,7 +1532,7 @@ export function useChat( | ||
| reportManualRunToolStop(workflowId, toolCallId).catch(() => {}) | ||
| } | ||
| }, [invalidateChatQueries, persistPartialResponse, executionStream]) | ||
| }, [invalidateChatQueries, persistPartialResponse, executionStream, resolveInterruptedToolCalls]) | ||
| const removeFromQueue = useCallback((id: string) => { | ||
| messageQueueRef.current = messageQueueRef.current.filter((m) => m.id !== id) | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.