mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-02 22:32:27 +08:00
fix: enable UI retry when Bedrock returns early 503 error (#94)
- Add error prop to ChatInput to detect error state - Update isDisabled logic to allow retry when there's an error - Pass combined error (SDK error + streamingError) to ChatInput When Bedrock returns 503 ServiceUnavailableException before streaming starts, AI SDK's onError fires but status may not transition to "ready". This fix ensures the input is re-enabled when an error occurs, allowing users to retry their request.
This commit is contained in:
@@ -29,6 +29,7 @@ interface ChatInputProps {
|
|||||||
onFileChange?: (files: File[]) => void;
|
onFileChange?: (files: File[]) => void;
|
||||||
showHistory?: boolean;
|
showHistory?: boolean;
|
||||||
onToggleHistory?: (show: boolean) => void;
|
onToggleHistory?: (show: boolean) => void;
|
||||||
|
error?: Error | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ChatInput({
|
export function ChatInput({
|
||||||
@@ -41,6 +42,7 @@ export function ChatInput({
|
|||||||
onFileChange = () => {},
|
onFileChange = () => {},
|
||||||
showHistory = false,
|
showHistory = false,
|
||||||
onToggleHistory = () => {},
|
onToggleHistory = () => {},
|
||||||
|
error = null,
|
||||||
}: ChatInputProps) {
|
}: ChatInputProps) {
|
||||||
const { diagramHistory, saveDiagramToFile } = useDiagram();
|
const { diagramHistory, saveDiagramToFile } = useDiagram();
|
||||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||||
@@ -49,7 +51,8 @@ export function ChatInput({
|
|||||||
const [showClearDialog, setShowClearDialog] = useState(false);
|
const [showClearDialog, setShowClearDialog] = useState(false);
|
||||||
const [showSaveDialog, setShowSaveDialog] = useState(false);
|
const [showSaveDialog, setShowSaveDialog] = useState(false);
|
||||||
|
|
||||||
const isDisabled = status === "streaming" || status === "submitted";
|
// Allow retry when there's an error (even if status is still "streaming" or "submitted")
|
||||||
|
const isDisabled = (status === "streaming" || status === "submitted") && !error;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('[ChatInput] Status changed to:', status, '| Input disabled:', isDisabled);
|
console.log('[ChatInput] Status changed to:', status, '| Input disabled:', isDisabled);
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ Please retry with an adjusted search pattern or use display_diagram if retries a
|
|||||||
const lastMessagePartsRef = useRef(0);
|
const lastMessagePartsRef = useRef(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Clear streaming error and reset refs when status changes to ready
|
// Clear streaming error when status changes to ready
|
||||||
if (status === "ready") {
|
if (status === "ready") {
|
||||||
setStreamingError(null);
|
setStreamingError(null);
|
||||||
lastMessageCountRef.current = 0;
|
lastMessageCountRef.current = 0;
|
||||||
@@ -498,6 +498,7 @@ Please retry with an adjusted search pattern or use display_diagram if retries a
|
|||||||
onFileChange={handleFileChange}
|
onFileChange={handleFileChange}
|
||||||
showHistory={showHistory}
|
showHistory={showHistory}
|
||||||
onToggleHistory={setShowHistory}
|
onToggleHistory={setShowHistory}
|
||||||
|
error={error || streamingError}
|
||||||
/>
|
/>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user