chenbhao commited on
Commit
3807a75
·
1 Parent(s): d12b0d9

feat: /friend tts add websearch

Browse files
Files changed (1) hide show
  1. src/hooks/useFriendBridge.ts +13 -1
src/hooks/useFriendBridge.ts CHANGED
@@ -24,6 +24,9 @@ const FRIEND_CHANNEL_SERVER = 'friend'
24
 
25
  type ActiveFriendTurn = {
26
  responseParts: string[]
 
 
 
27
  }
28
 
29
  export function useFriendBridge({ messages, isLoading }: Props): void {
@@ -57,16 +60,21 @@ export function useFriendBridge({ messages, isLoading }: Props): void {
57
  pendingInboundRef.current--
58
  activeTurnRef.current = {
59
  responseParts: [],
 
60
  }
61
  }
62
  continue
63
  }
64
 
65
  if (message.type === 'assistant' && activeTurnRef.current) {
66
- const text = getContentText(message.message.content)
 
67
  if (text) {
68
  activeTurnRef.current.responseParts.push(text)
69
  }
 
 
 
70
  continue
71
  }
72
 
@@ -92,6 +100,10 @@ export function useFriendBridge({ messages, isLoading }: Props): void {
92
 
93
  if (!wasLoading || isLoading || !activeTurnRef.current) return
94
 
 
 
 
 
95
  const completedTurn = activeTurnRef.current
96
  activeTurnRef.current = null
97
 
 
24
 
25
  type ActiveFriendTurn = {
26
  responseParts: string[]
27
+ /** True if the last collected assistant message contained a tool_use block.
28
+ * When true, the turn is not complete — more messages expected. */
29
+ hasToolUse: boolean
30
  }
31
 
32
  export function useFriendBridge({ messages, isLoading }: Props): void {
 
60
  pendingInboundRef.current--
61
  activeTurnRef.current = {
62
  responseParts: [],
63
+ hasToolUse: false,
64
  }
65
  }
66
  continue
67
  }
68
 
69
  if (message.type === 'assistant' && activeTurnRef.current) {
70
+ const content = message.message.content
71
+ const text = getContentText(content)
72
  if (text) {
73
  activeTurnRef.current.responseParts.push(text)
74
  }
75
+ // Check if this message contains tool_use → turn continues
76
+ activeTurnRef.current.hasToolUse = Array.isArray(content) &&
77
+ content.some((b: any) => b.type === 'tool_use')
78
  continue
79
  }
80
 
 
100
 
101
  if (!wasLoading || isLoading || !activeTurnRef.current) return
102
 
103
+ // If the last assistant message had a tool_use, the turn is not complete —
104
+ // more messages are expected after tool results resolve. Wait.
105
+ if (activeTurnRef.current.hasToolUse) return
106
+
107
  const completedTurn = activeTurnRef.current
108
  activeTurnRef.current = null
109