fix: TDZ crash - move voiceStream/buildPromptFromRefs before _handleSend
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
e94420dfe9
commit
2031c87529
1 changed files with 32 additions and 32 deletions
|
|
@ -337,6 +337,38 @@ export const WorkspaceInput = forwardRef<WorkspaceInputHandle, WorkspaceInputPro
|
||||||
attachments.length > 0 || attachedDataSourceIds.length > 0 || attachedFeatureDataSourceIds.length > 0;
|
attachments.length > 0 || attachedDataSourceIds.length > 0 || attachedFeatureDataSourceIds.length > 0;
|
||||||
const _canSend = Boolean(prompt.trim()) || attachments.length > 0;
|
const _canSend = Boolean(prompt.trim()) || attachments.length > 0;
|
||||||
|
|
||||||
|
const _buildPromptFromRefs = useCallback(() => {
|
||||||
|
const parts = [
|
||||||
|
promptBeforeVoiceRef.current,
|
||||||
|
finalizedTextRef.current,
|
||||||
|
currentInterimRef.current,
|
||||||
|
].filter(Boolean);
|
||||||
|
return parts.join(' ');
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const voiceStream = useVoiceStream({
|
||||||
|
onFinal: (text) => {
|
||||||
|
finalizedTextRef.current = finalizedTextRef.current
|
||||||
|
? `${finalizedTextRef.current} ${text}`
|
||||||
|
: text;
|
||||||
|
currentInterimRef.current = '';
|
||||||
|
setPrompt(_buildPromptFromRefs());
|
||||||
|
},
|
||||||
|
onInterim: (text) => {
|
||||||
|
currentInterimRef.current = text;
|
||||||
|
setPrompt(_buildPromptFromRefs());
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
console.warn('Workspace voice stream error', error);
|
||||||
|
setVoiceActive(false);
|
||||||
|
},
|
||||||
|
onStatusChange: (nextStatus) => {
|
||||||
|
if (nextStatus === 'idle' || nextStatus === 'error') {
|
||||||
|
setVoiceActive(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const _handleSend = useCallback(() => {
|
const _handleSend = useCallback(() => {
|
||||||
if ((!prompt.trim() && attachments.length === 0) || isProcessing) return;
|
if ((!prompt.trim() && attachments.length === 0) || isProcessing) return;
|
||||||
if (voiceActive) {
|
if (voiceActive) {
|
||||||
|
|
@ -419,38 +451,6 @@ export const WorkspaceInput = forwardRef<WorkspaceInputHandle, WorkspaceInputPro
|
||||||
});
|
});
|
||||||
}, [_persistAttachments, attachedDataSourceIds]);
|
}, [_persistAttachments, attachedDataSourceIds]);
|
||||||
|
|
||||||
const _buildPromptFromRefs = useCallback(() => {
|
|
||||||
const parts = [
|
|
||||||
promptBeforeVoiceRef.current,
|
|
||||||
finalizedTextRef.current,
|
|
||||||
currentInterimRef.current,
|
|
||||||
].filter(Boolean);
|
|
||||||
return parts.join(' ');
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const voiceStream = useVoiceStream({
|
|
||||||
onFinal: (text) => {
|
|
||||||
finalizedTextRef.current = finalizedTextRef.current
|
|
||||||
? `${finalizedTextRef.current} ${text}`
|
|
||||||
: text;
|
|
||||||
currentInterimRef.current = '';
|
|
||||||
setPrompt(_buildPromptFromRefs());
|
|
||||||
},
|
|
||||||
onInterim: (text) => {
|
|
||||||
currentInterimRef.current = text;
|
|
||||||
setPrompt(_buildPromptFromRefs());
|
|
||||||
},
|
|
||||||
onError: (error) => {
|
|
||||||
console.warn('Workspace voice stream error', error);
|
|
||||||
setVoiceActive(false);
|
|
||||||
},
|
|
||||||
onStatusChange: (nextStatus) => {
|
|
||||||
if (nextStatus === 'idle' || nextStatus === 'error') {
|
|
||||||
setVoiceActive(false);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const _stopVoiceCapture = useCallback(() => {
|
const _stopVoiceCapture = useCallback(() => {
|
||||||
if (currentInterimRef.current) {
|
if (currentInterimRef.current) {
|
||||||
finalizedTextRef.current = finalizedTextRef.current
|
finalizedTextRef.current = finalizedTextRef.current
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue