MCPcopy
hub / github.com/wavetermdev/waveterm / processToolCallInternal

Function processToolCallInternal

pkg/aiusechat/usechat.go:221–301  ·  view source on GitHub ↗
(backend UseChatBackend, toolCall uctypes.WaveToolCall, chatOpts uctypes.WaveChatOpts, toolDef *uctypes.ToolDefinition, sseHandler *sse.SSEHandlerCh)

Source from the content-addressed store, hash-verified

219}
220
221func processToolCallInternal(backend UseChatBackend, toolCall uctypes.WaveToolCall, chatOpts uctypes.WaveChatOpts, toolDef *uctypes.ToolDefinition, sseHandler *sse.SSEHandlerCh) uctypes.AIToolResult {
222 if toolCall.ToolUseData == nil {
223 return uctypes.AIToolResult{
224 ToolName: toolCall.Name,
225 ToolUseID: toolCall.ID,
226 ErrorText: "Invalid Tool Call",
227 }
228 }
229
230 if toolCall.ToolUseData.Status == uctypes.ToolUseStatusError {
231 errorMsg := toolCall.ToolUseData.ErrorMessage
232 if errorMsg == "" {
233 errorMsg = "Unspecified Tool Error"
234 }
235 return uctypes.AIToolResult{
236 ToolName: toolCall.Name,
237 ToolUseID: toolCall.ID,
238 ErrorText: errorMsg,
239 }
240 }
241
242 if toolDef != nil && toolDef.ToolVerifyInput != nil {
243 if err := toolDef.ToolVerifyInput(toolCall.Input, toolCall.ToolUseData); err != nil {
244 errorMsg := fmt.Sprintf("Input validation failed: %v", err)
245 toolCall.ToolUseData.Status = uctypes.ToolUseStatusError
246 toolCall.ToolUseData.ErrorMessage = errorMsg
247 return uctypes.AIToolResult{
248 ToolName: toolCall.Name,
249 ToolUseID: toolCall.ID,
250 ErrorText: errorMsg,
251 }
252 }
253 // ToolVerifyInput can modify the toolusedata. re-send it here.
254 _ = sseHandler.AiMsgData("data-tooluse", toolCall.ID, *toolCall.ToolUseData)
255 updateToolUseDataInChat(backend, chatOpts, toolCall.ID, *toolCall.ToolUseData)
256 }
257
258 if toolCall.ToolUseData.Approval == uctypes.ApprovalNeedsApproval {
259 log.Printf(" waiting for approval...\n")
260 approval, err := WaitForToolApproval(sseHandler.Context(), toolCall.ID)
261 if err != nil || approval == "" {
262 approval = uctypes.ApprovalCanceled
263 }
264 log.Printf(" approval result: %q\n", approval)
265 toolCall.ToolUseData.Approval = approval
266
267 if !toolCall.ToolUseData.IsApproved() {
268 errorMsg := "Tool use denied or timed out"
269 if approval == uctypes.ApprovalUserDenied {
270 errorMsg = "Tool use denied by user"
271 } else if approval == uctypes.ApprovalTimeout {
272 errorMsg = "Tool approval timed out"
273 } else if approval == uctypes.ApprovalCanceled {
274 errorMsg = "Tool approval canceled"
275 }
276 toolCall.ToolUseData.Status = uctypes.ToolUseStatusError
277 toolCall.ToolUseData.ErrorMessage = errorMsg
278 return uctypes.AIToolResult{

Callers 1

processToolCallFunction · 0.85

Calls 6

updateToolUseDataInChatFunction · 0.85
WaitForToolApprovalFunction · 0.85
ResolveToolCallFunction · 0.85
AiMsgDataMethod · 0.80
IsApprovedMethod · 0.80
ContextMethod · 0.45

Tested by

no test coverage detected