Enter now queues one follow-up instead of dropping it, and a rectification stop leaves the streamed reply with a grey notice instead of an error alert. Co-authored-by: Cursor <cursoragent@cursor.com>
29 lines
719 B
TypeScript
29 lines
719 B
TypeScript
"use client";
|
|
|
|
import { useCallback, useRef, useState } from "react";
|
|
import { appendQueuedText } from "@/lib/queued-draft";
|
|
|
|
export function useQueuedMessage() {
|
|
const [text, setText] = useState("");
|
|
const textRef = useRef("");
|
|
|
|
const enqueue = useCallback((incoming: string) => {
|
|
const nextIncoming = incoming.trim();
|
|
if (!nextIncoming) return false;
|
|
const next = appendQueuedText(textRef.current, nextIncoming);
|
|
textRef.current = next;
|
|
setText(next);
|
|
return true;
|
|
}, []);
|
|
|
|
const take = useCallback(() => {
|
|
const current = textRef.current;
|
|
if (!current) return "";
|
|
textRef.current = "";
|
|
setText("");
|
|
return current;
|
|
}, []);
|
|
|
|
return { text, enqueue, take };
|
|
}
|