@springbrand/message-panel 0.2.0-alpha.47 → 0.2.0-alpha.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -403,6 +403,19 @@ export function AskUserBlock({
|
|
|
403
403
|
const [inFlight, setInFlight] = useState(false);
|
|
404
404
|
const [submissionError, setSubmissionError] = useState(false);
|
|
405
405
|
const outcome = askUserOutcome(call);
|
|
406
|
+
const responseTimerRef = useRef<number | null>(null);
|
|
407
|
+
const hasAttachmentQuestion = questions.some(
|
|
408
|
+
(question) => question.kind === "attachment",
|
|
409
|
+
);
|
|
410
|
+
const clearResponseTimer = () => {
|
|
411
|
+
if (responseTimerRef.current === null) return;
|
|
412
|
+
window.clearTimeout(responseTimerRef.current);
|
|
413
|
+
responseTimerRef.current = null;
|
|
414
|
+
};
|
|
415
|
+
useEffect(() => () => clearResponseTimer(), []);
|
|
416
|
+
useEffect(() => {
|
|
417
|
+
if (outcome.kind !== "pending") clearResponseTimer();
|
|
418
|
+
}, [outcome.kind]);
|
|
406
419
|
const displayAnswerAt = (index: number): DraftAnswer => {
|
|
407
420
|
if (outcome.kind !== "answered") return answerAt(index);
|
|
408
421
|
const answer = outcome.answers[index];
|
|
@@ -448,19 +461,28 @@ export function AskUserBlock({
|
|
|
448
461
|
),
|
|
449
462
|
};
|
|
450
463
|
setInFlight(true);
|
|
464
|
+
clearResponseTimer();
|
|
465
|
+
responseTimerRef.current = window.setTimeout(() => {
|
|
466
|
+
responseTimerRef.current = null;
|
|
467
|
+
setInFlight(false);
|
|
468
|
+
setSubmissionError(hasAttachmentQuestion);
|
|
469
|
+
}, 30_000);
|
|
451
470
|
// 失败就把按钮放回可点:权威状态由 part 决定,这里只管别把用户锁死。
|
|
452
471
|
void onRespond(call.toolCallId, response).then((ok) => {
|
|
453
472
|
if (!ok) {
|
|
473
|
+
clearResponseTimer();
|
|
454
474
|
setInFlight(false);
|
|
455
|
-
setSubmissionError(
|
|
475
|
+
setSubmissionError(hasAttachmentQuestion);
|
|
456
476
|
}
|
|
457
477
|
}, () => {
|
|
478
|
+
clearResponseTimer();
|
|
458
479
|
setInFlight(false);
|
|
459
|
-
setSubmissionError(
|
|
480
|
+
setSubmissionError(hasAttachmentQuestion);
|
|
460
481
|
});
|
|
461
482
|
} catch {
|
|
483
|
+
clearResponseTimer();
|
|
462
484
|
setInFlight(false);
|
|
463
|
-
setSubmissionError(
|
|
485
|
+
setSubmissionError(hasAttachmentQuestion);
|
|
464
486
|
}
|
|
465
487
|
};
|
|
466
488
|
|