Skip to content

refactor: extract internal message answer entrypoint#2244

Merged
hsluoyz merged 1 commit into
the-open-agent:masterfrom
nkanf-dev:refactor/message-answer-internal
May 9, 2026
Merged

refactor: extract internal message answer entrypoint#2244
hsluoyz merged 1 commit into
the-open-agent:masterfrom
nkanf-dev:refactor/message-answer-internal

Conversation

@nkanf-dev
Copy link
Copy Markdown
Contributor

Summary

Refactor GetMessageAnswer by extracting an internal reusable message-answer entrypoint while keeping the public API behavior unchanged.

Notes

This prepares the message answer flow for reuse by other internal entrypoints, such as chat pipe/webhook integrations.

Copilot AI review requested due to automatic review settings May 9, 2026 16:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the message-answer SSE flow by extracting a reusable internal entrypoint and consolidating SSE error-stream writing logic, with the intent of keeping the public /get-message-answer behavior unchanged while enabling reuse by future internal integrations (e.g., pipes/webhooks).

Changes:

  • Extracts a reusable internal message-answer entrypoint (generateMessageAnswer) that accepts an http.ResponseWriter and host.
  • Extracts SSE error-stream writing into a shared helper (writeMessageErrorStream) and updates call sites to reuse it.
  • Replaces direct controller writer usage (c.Ctx.ResponseWriter) with an injected responseWriter within the extracted flow.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
controllers/message_util.go Extracts SSE error-stream emission into writeMessageErrorStream and reuses it from ResponseErrorStream.
controllers/message_answer.go Introduces generateMessageAnswer and rewires streaming writes/errors to use an injected http.ResponseWriter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +48 to +54
func (c *ApiController) generateMessageAnswer(id string, responseWriter http.ResponseWriter, host string) {
lang := c.GetAcceptLanguage()
responseErrorStream := func(message *object.Message, errorText string) {
if err := writeMessageErrorStream(responseWriter, lang, message, errorText); err != nil {
c.ResponseError(err.Error())
}
}
}
if err != nil {
if strings.Contains(err.Error(), "write tcp") {
c.ResponseError(err.Error())
@hsluoyz hsluoyz merged commit ed7554f into the-open-agent:master May 9, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants