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

Function RemoveToolUseCall

pkg/aiusechat/gemini/gemini-convertmessage.go:461–508  ·  view source on GitHub ↗
(chatId string, toolCallId string)

Source from the content-addressed store, hash-verified

459}
460
461func RemoveToolUseCall(chatId string, toolCallId string) error {
462 chat := chatstore.DefaultChatStore.Get(chatId)
463 if chat == nil {
464 return fmt.Errorf("chat not found: %s", chatId)
465 }
466
467 for _, genMsg := range chat.NativeMessages {
468 chatMsg, ok := genMsg.(*GeminiChatMessage)
469 if !ok {
470 continue
471 }
472
473 partIndex := -1
474 for i, part := range chatMsg.Parts {
475 if part.FunctionCall != nil && part.ToolUseData != nil && part.ToolUseData.ToolCallId == toolCallId {
476 partIndex = i
477 break
478 }
479 }
480
481 if partIndex == -1 {
482 continue
483 }
484
485 updatedMsg := &GeminiChatMessage{
486 MessageId: chatMsg.MessageId,
487 Role: chatMsg.Role,
488 Parts: slices.Delete(slices.Clone(chatMsg.Parts), partIndex, partIndex+1),
489 Usage: chatMsg.Usage,
490 }
491
492 if len(updatedMsg.Parts) == 0 {
493 chatstore.DefaultChatStore.RemoveMessage(chatId, chatMsg.MessageId)
494 } else {
495 aiOpts := &uctypes.AIOptsType{
496 APIType: chat.APIType,
497 Model: chat.Model,
498 APIVersion: chat.APIVersion,
499 }
500 if err := chatstore.DefaultChatStore.PostMessage(chatId, aiOpts, updatedMsg); err != nil {
501 return err
502 }
503 }
504 return nil
505 }
506
507 return nil
508}

Callers 1

RemoveToolUseCallMethod · 0.92

Calls 4

RemoveMessageMethod · 0.80
PostMessageMethod · 0.80
GetMethod · 0.45
DeleteMethod · 0.45

Tested by

no test coverage detected