Skip to content

Commit 5067190

Browse files
authored
Play sound only when action needed from the user (#3065)
* Update sound logic to be centralized and only run when action is needed from user * Handle cases like questions and resuming
1 parent d990f0e commit 5067190

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
170170
setSecondaryButtonText(t("chat:startNewTask.title"))
171171
break
172172
case "followup":
173+
if (!isPartial) {
174+
playSound("notification")
175+
}
173176
setTextAreaDisabled(isPartial)
174177
setClineAsk("followup")
175178
// setting enable buttons to `false` would trigger a focus grab when
@@ -181,7 +184,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
181184
setSecondaryButtonText(undefined)
182185
break
183186
case "tool":
184-
if (!isAutoApproved(lastMessage)) {
187+
if (!isAutoApproved(lastMessage) && !isPartial) {
185188
playSound("notification")
186189
}
187190
setTextAreaDisabled(isPartial)
@@ -207,7 +210,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
207210
}
208211
break
209212
case "browser_action_launch":
210-
if (!isAutoApproved(lastMessage)) {
213+
if (!isAutoApproved(lastMessage) && !isPartial) {
211214
playSound("notification")
212215
}
213216
setTextAreaDisabled(isPartial)
@@ -217,7 +220,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
217220
setSecondaryButtonText(t("chat:reject.title"))
218221
break
219222
case "command":
220-
if (!isAutoApproved(lastMessage)) {
223+
if (!isAutoApproved(lastMessage) && !isPartial) {
221224
playSound("notification")
222225
}
223226
setTextAreaDisabled(isPartial)
@@ -234,6 +237,9 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
234237
setSecondaryButtonText(t("chat:killCommand.title"))
235238
break
236239
case "use_mcp_server":
240+
if (!isAutoApproved(lastMessage) && !isPartial) {
241+
playSound("notification")
242+
}
237243
setTextAreaDisabled(isPartial)
238244
setClineAsk("use_mcp_server")
239245
setEnableButtons(!isPartial)
@@ -242,14 +248,19 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
242248
break
243249
case "completion_result":
244250
// extension waiting for feedback. but we can just present a new task button
245-
playSound("celebration")
251+
if (!isPartial) {
252+
playSound("celebration")
253+
}
246254
setTextAreaDisabled(isPartial)
247255
setClineAsk("completion_result")
248256
setEnableButtons(!isPartial)
249257
setPrimaryButtonText(t("chat:startNewTask.title"))
250258
setSecondaryButtonText(undefined)
251259
break
252260
case "resume_task":
261+
if (!isAutoApproved(lastMessage) && !isPartial) {
262+
playSound("notification")
263+
}
253264
setTextAreaDisabled(false)
254265
setClineAsk("resume_task")
255266
setEnableButtons(true)
@@ -258,6 +269,9 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
258269
setDidClickCancel(false) // special case where we reset the cancel button state
259270
break
260271
case "resume_completed_task":
272+
if (!isPartial) {
273+
playSound("celebration")
274+
}
261275
setTextAreaDisabled(false)
262276
setClineAsk("resume_completed_task")
263277
setEnableButtons(true)
@@ -827,37 +841,6 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
827841
}
828842
}
829843

830-
// Only execute when isStreaming changes from true to false.
831-
if (wasStreaming && !isStreaming && lastMessage) {
832-
// Play appropriate sound based on lastMessage content.
833-
if (lastMessage.type === "ask") {
834-
// Don't play sounds for auto-approved actions
835-
if (!isAutoApproved(lastMessage)) {
836-
switch (lastMessage.ask) {
837-
case "api_req_failed":
838-
case "mistake_limit_reached":
839-
playSound("progress_loop")
840-
break
841-
case "followup":
842-
if (!lastMessage.partial) {
843-
playSound("notification")
844-
}
845-
break
846-
case "tool":
847-
case "browser_action_launch":
848-
case "resume_task":
849-
case "use_mcp_server":
850-
playSound("notification")
851-
break
852-
case "completion_result":
853-
case "resume_completed_task":
854-
playSound("celebration")
855-
break
856-
}
857-
}
858-
}
859-
}
860-
861844
// Update previous value.
862845
setWasStreaming(isStreaming)
863846
}, [isStreaming, lastMessage, wasStreaming, isAutoApproved, messages.length])

0 commit comments

Comments
 (0)