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

Method PostMessage

pkg/aiusechat/chatstore/chatstore.go:70–112  ·  view source on GitHub ↗
(chatId string, aiOpts *uctypes.AIOptsType, message uctypes.GenAIMessage)

Source from the content-addressed store, hash-verified

68}
69
70func (cs *ChatStore) PostMessage(chatId string, aiOpts *uctypes.AIOptsType, message uctypes.GenAIMessage) error {
71 cs.lock.Lock()
72 defer cs.lock.Unlock()
73
74 chat := cs.chats[chatId]
75 if chat == nil {
76 // Create new chat
77 chat = &uctypes.AIChat{
78 ChatId: chatId,
79 APIType: aiOpts.APIType,
80 Model: aiOpts.Model,
81 APIVersion: aiOpts.APIVersion,
82 NativeMessages: make([]uctypes.GenAIMessage, 0),
83 }
84 cs.chats[chatId] = chat
85 } else {
86 // Verify that the AI options match
87 if chat.APIType != aiOpts.APIType {
88 return fmt.Errorf("API type mismatch: expected %s, got %s (must start a new chat)", chat.APIType, aiOpts.APIType)
89 }
90 if !uctypes.AreModelsCompatible(chat.APIType, chat.Model, aiOpts.Model) {
91 return fmt.Errorf("model mismatch: expected %s, got %s (must start a new chat)", chat.Model, aiOpts.Model)
92 }
93 if chat.APIVersion != aiOpts.APIVersion {
94 return fmt.Errorf("API version mismatch: expected %s, got %s (must start a new chat)", chat.APIVersion, aiOpts.APIVersion)
95 }
96 }
97
98 // Check for existing message with same ID (idempotency)
99 messageId := message.GetMessageId()
100 for i, existingMessage := range chat.NativeMessages {
101 if existingMessage.GetMessageId() == messageId {
102 // Replace existing message with same ID
103 chat.NativeMessages[i] = message
104 return nil
105 }
106 }
107
108 // Append the new message if no duplicate found
109 chat.NativeMessages = append(chat.NativeMessages, message)
110
111 return nil
112}
113
114func (cs *ChatStore) RemoveMessage(chatId string, messageId string) bool {
115 cs.lock.Lock()

Callers 11

processAllToolCallsFunction · 0.80
RunAIChatFunction · 0.80
WaveAIPostMessageWrapFunction · 0.80
UpdateToolUseDataFunction · 0.80
RemoveToolUseCallFunction · 0.80
UpdateToolUseDataFunction · 0.80
RemoveToolUseCallFunction · 0.80
UpdateToolUseDataFunction · 0.80
RemoveToolUseCallFunction · 0.80
UpdateToolUseDataFunction · 0.80

Calls 2

AreModelsCompatibleFunction · 0.92
GetMessageIdMethod · 0.65

Tested by 1