opencode-cursor-agent/internal/handler/chat/anthropic_messages_handler.go

39 lines
996 B
Go

// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1
package chat
import (
"net/http"
"cursor-api-proxy/internal/logic/chat"
"cursor-api-proxy/internal/svc"
"cursor-api-proxy/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
func AnthropicMessagesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AnthropicRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := chat.NewAnthropicMessagesLogic(r.Context(), svcCtx)
if req.Stream {
w.Header().Set("Content-Type", "text/event-stream")
w.Header().Set("Cache-Control", "no-cache")
w.Header().Set("Connection", "keep-alive")
w.Header().Set("X-Accel-Buffering", "no")
_ = l.AnthropicMessagesStream(&req, w, r.Method, r.URL.Path)
} else {
err := l.AnthropicMessages(&req, w, r.Method, r.URL.Path)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
}
}
}
}