MCPcopy
hub / github.com/the-open-agent/openagent / generateMessageAnswer

Function generateMessageAnswer

controllers/message_answer.go:140–595  ·  view source on GitHub ↗
(id string, responseWriter http.ResponseWriter, host string, lang string, signedIn bool, responseError func(string, ...interface{}))

Source from the content-addressed store, hash-verified

138}
139
140func generateMessageAnswer(id string, responseWriter http.ResponseWriter, host string, lang string, signedIn bool, responseError func(string, ...interface{})) {
141 responseErrorStream := func(message *object.Message, errorText string) {
142 if err := writeMessageErrorStream(responseWriter, lang, message, errorText); err != nil {
143 if responseError != nil {
144 responseError(err.Error())
145 }
146 }
147 }
148
149 emitStatus := func(statusText string) {
150 _ = writeStatusStream(responseWriter, statusText)
151 }
152
153 message, err := object.GetMessage(id)
154 if err != nil {
155 responseErrorStream(message, err.Error())
156 return
157 }
158
159 if message == nil {
160 responseErrorStream(message, fmt.Sprintf("The message: %s is not found", id))
161 return
162 }
163
164 if message.Author != "AI" {
165 responseErrorStream(message, fmt.Sprintf("The message is invalid, message author should be \"AI\", but got \"%s\"", message.Author))
166 return
167 }
168 if message.ReplyTo == "" {
169 responseErrorStream(message, "The message is invalid, message replyTo should not be empty")
170 return
171 }
172 if message.Text != "" {
173 responseErrorStream(message, fmt.Sprintf("The message is invalid, message text should be empty, but got \"%s\"", message.Text))
174 return
175 }
176
177 if strings.HasPrefix(message.ErrorText, "error, status code: 400, message: The response was filtered due to the prompt triggering") {
178 responseErrorStream(message, message.ErrorText)
179 return
180 }
181
182 chatId := util.GetIdFromOwnerAndName(message.Owner, message.Chat)
183 chat, err := object.GetChat(chatId)
184 if err != nil {
185 responseErrorStream(message, err.Error())
186 return
187 }
188
189 //if chat == nil || chat.Organization != message.Organization {
190 // c.ResponseErrorStream(message, fmt.Sprintf("The chat: %s is not found", chatId))
191 // return
192 //}
193
194 store, err := object.ResolveStoreForChat(chat)
195 if err != nil {
196 responseErrorStream(message, err.Error())
197 return

Callers 3

sendPipeAnswerFunction · 0.85
generateMessageAnswerMethod · 0.85
getOrStartMethod · 0.85

Calls 15

GetIdMethod · 0.95
MessageStringMethod · 0.95
ReasonStringMethod · 0.95
ToolStringMethod · 0.95
SearchStringMethod · 0.95
GetMessageFunction · 0.92
GetIdFromOwnerAndNameFunction · 0.92
GetChatFunction · 0.92
ResolveStoreForChatFunction · 0.92
TranslateFunction · 0.92
GetSkillsCatalogFunction · 0.92
GetIdFunction · 0.92

Tested by

no test coverage detected