feat(cursor): add contributor profile link and improve UI for Cursor account card

- Integrated a tooltip with a button to open the contributor's GitHub profile in the CursorAccountCard component.
- Updated the layout of the account card for better visual organization.
- Removed routing mode options from the configuration view and adjusted related translations in multiple languages.
- Cleaned up unused routing mode logic in the app state management.
This commit is contained in:
leookun
2026-08-02 22:53:57 +08:00
parent 674de0b041
commit a5437e60fe
22 changed files with 293 additions and 753 deletions
-14
View File
@@ -171,20 +171,6 @@ func (manager *Manager) LegacyRuntimeSnapshot(_ context.Context) (legacyruntime.
}, nil
}
func (manager *Manager) RouteMode(hasUpstreamURL bool) string {
if !hasUpstreamURL {
return DefaultRoutingMode
}
if manager == nil {
return DefaultRoutingMode
}
mode := normalizeRoutingMode(manager.Current().Routing.Mode)
if mode == "" {
return DefaultRoutingMode
}
return mode
}
func (manager *Manager) setCurrent(cfg Config) {
next := cfg
manager.current.Store(&next)
+3
View File
@@ -136,6 +136,9 @@ func (store *Store) saveLocked(normalized Config) error {
}
func shouldPersistNormalizedConfig(raw []byte, current Config, normalized Config) bool {
if yamlHasKey(raw, "routing") {
return true
}
if !yamlHasKey(raw, "backendListenAddr") || !yamlHasKey(raw, "proxyListenAddr") {
return true
}
-24
View File
@@ -15,7 +15,6 @@ const (
DefaultBackendListenAddr = "127.0.0.1:18090"
DefaultProxyListenAddr = "127.0.0.1:18080"
DefaultFrontendBaseURL = "http://127.0.0.1"
DefaultRoutingMode = "local"
DefaultProviderStreamIdleTimeoutSeconds = 240
MinProviderStreamIdleTimeoutSeconds = 30
)
@@ -43,10 +42,6 @@ type ModelAdapterConfig struct {
ThinkingBudgetTokens int `json:"thinkingBudgetTokens" yaml:"thinkingBudgetTokens"`
}
type RoutingConfig struct {
Mode string `json:"mode" yaml:"mode"`
}
type HomeMetricsConfig struct {
IncludeCacheWriteInHitRate bool `json:"includeCacheWriteInHitRate" yaml:"includeCacheWriteInHitRate"`
}
@@ -57,7 +52,6 @@ type Config struct {
BackendListenAddr string `json:"backendListenAddr" yaml:"backendListenAddr"`
ProxyListenAddr string `json:"proxyListenAddr" yaml:"proxyListenAddr"`
ModelAdapters []ModelAdapterConfig `json:"modelAdapters" yaml:"modelAdapters"`
Routing RoutingConfig `json:"routing" yaml:"routing"`
HomeMetrics HomeMetricsConfig `json:"homeMetrics" yaml:"homeMetrics"`
LastAgentModelHash string `json:"lastAgentModelHash" yaml:"lastAgentModelHash"`
}
@@ -69,9 +63,6 @@ func DefaultConfig() Config {
BackendListenAddr: DefaultBackendListenAddr,
ProxyListenAddr: DefaultProxyListenAddr,
ModelAdapters: []ModelAdapterConfig{},
Routing: RoutingConfig{
Mode: DefaultRoutingMode,
},
}
}
@@ -91,10 +82,6 @@ func NormalizeConfig(input Config) (Config, error) {
output.ProxyListenAddr = proxyListenAddr
output.HomeMetrics.IncludeCacheWriteInHitRate = input.HomeMetrics.IncludeCacheWriteInHitRate
output.LastAgentModelHash = strings.TrimSpace(input.LastAgentModelHash)
output.Routing.Mode = normalizeRoutingMode(input.Routing.Mode)
if output.Routing.Mode == "" {
output.Routing.Mode = DefaultRoutingMode
}
adapters, err := NormalizeModelAdapterConfigs(input.ModelAdapters)
if err != nil {
return Config{}, err
@@ -280,14 +267,3 @@ func normalizeModelAdapterType(value string) string {
return ""
}
}
func normalizeRoutingMode(value string) string {
switch strings.ToLower(strings.TrimSpace(value)) {
case "", "local":
return "local"
case "upstream":
return "upstream"
default:
return ""
}
}
-2
View File
@@ -34,7 +34,6 @@ type Context struct {
StartedAt time.Time
UpstreamURL *url.URL
Mode ExecutionMode
LastError error
Logger *slog.Logger
@@ -48,7 +47,6 @@ func newContext(writer http.ResponseWriter, request *http.Request, route Route)
Protocol: route.Protocol,
StartedAt: time.Now(),
Logger: slog.Default(),
Mode: ModeLocal,
}
}
-12
View File
@@ -1,14 +1,12 @@
package server
import (
"cursor/internal/logger"
"errors"
"fmt"
"net/http"
"runtime/debug"
"strings"
serverconfig "cursor/internal/backend/server/config"
legacyruntime "cursor/internal/runtime"
)
@@ -39,16 +37,6 @@ func ServerContext() Middleware {
}
}
func PolicyMiddleware(configs *serverconfig.Manager) Middleware {
return func(next HandlerFunc) HandlerFunc {
return func(ctx *Context) error {
ctx.Mode = parseExecutionMode(configs.RouteMode(ctx.UpstreamURL != nil))
logger.Infof("ctx.Mode=%s upstream=%t", ctx.Mode, ctx.UpstreamURL != nil)
return next(ctx)
}
}
}
func ErrorEncoder() Middleware {
return func(next HandlerFunc) HandlerFunc {
return func(ctx *Context) error {
-19
View File
@@ -1,19 +0,0 @@
package server
type ExecutionMode string
const (
// ModeLocal 表示本地模式,适用于直接处理请求的情况。
ModeLocal ExecutionMode = "local"
// ModeUpstream 表示直连上游模式,适用于将请求转发到原始地址。
ModeUpstream ExecutionMode = "upstream"
)
func parseExecutionMode(value string) ExecutionMode {
switch value {
case string(ModeUpstream):
return ModeUpstream
default:
return ModeLocal
}
}
-21
View File
@@ -17,7 +17,6 @@ type Route struct {
Protocol ProtocolClass
Middleware []Middleware
Local HandlerFunc
Upstream HandlerFunc
}
type App struct {
@@ -129,12 +128,6 @@ func Local(action HandlerFunc) RouteOption {
}
}
func Upstream(action HandlerFunc) RouteOption {
return func(route *Route) {
route.Upstream = action
}
}
func (app *App) registerRoute(route Route) {
handler := app.buildRouteHandler(route)
if route.Method == "" {
@@ -148,12 +141,6 @@ func (app *App) buildRouteHandler(route Route) http.HandlerFunc {
chain := append([]Middleware{}, app.globalMiddlewares...)
chain = append(chain, route.Middleware...)
final := Chain(chain...)(func(ctx *Context) error {
if shouldUseUpstreamAction(ctx, route) && route.Upstream != nil {
return route.Upstream(ctx)
}
if shouldUseUpstreamAction(ctx, route) && ctx.UpstreamURL != nil {
return fmt.Errorf("route %s is missing upstream action while request targets upstream %s", route.Name, ctx.UpstreamURL.String())
}
if route.Local != nil {
return route.Local(ctx)
}
@@ -168,14 +155,6 @@ func (app *App) buildRouteHandler(route Route) http.HandlerFunc {
}
}
func shouldUseUpstreamAction(ctx *Context, route Route) bool {
_ = route
if ctx == nil {
return false
}
return ctx.Mode == ModeUpstream
}
func Chain(middlewares ...Middleware) Middleware {
return func(final HandlerFunc) HandlerFunc {
wrapped := final
+3 -4
View File
@@ -20,7 +20,7 @@ type CompatRouteConfig struct {
ConsoleLog bool
}
func DirectAction(deps Dependencies, cfg CompatRouteConfig) server.HandlerFunc {
func ForwardAction(deps Dependencies, cfg CompatRouteConfig) server.HandlerFunc {
return func(ctx *server.Context) error {
reqCtx, route, err := newCompatRouteObjects(ctx, deps, cfg)
if err != nil {
@@ -30,9 +30,9 @@ func DirectAction(deps Dependencies, cfg CompatRouteConfig) server.HandlerFunc {
}
}
// AuthenticatedDirectAction forwards a Cursor control-plane request with the
// AuthenticatedForwardAction forwards a Cursor control-plane request with the
// independent desktop account after the local-mode identity rewrite has run.
func AuthenticatedDirectAction(deps Dependencies, cfg CompatRouteConfig, authorizationProvider AuthorizationProvider) server.HandlerFunc {
func AuthenticatedForwardAction(deps Dependencies, cfg CompatRouteConfig, authorizationProvider AuthorizationProvider) server.HandlerFunc {
return func(ctx *server.Context) error {
reqCtx, _, err := newCompatRouteObjects(ctx, deps, cfg)
if err != nil {
@@ -162,7 +162,6 @@ func newCompatRouteObjects(ctx *server.Context, deps Dependencies, cfg CompatRou
Headers: ctx.Request.Header.Clone(),
ContentType: strings.TrimSpace(ctx.Request.Header.Get("content-type")),
RequestBody: body,
Mode: ctx.Mode,
Deps: &deps,
HTTPRequestID: resolveHTTPRequestID(ctx.Request),
}
+1 -2
View File
@@ -15,7 +15,6 @@ import (
"time"
"cursor/gen/aiserverv1"
"cursor/internal/backend/server"
"cursor/internal/logger"
"cursor/internal/netproxy"
legacyruntime "cursor/internal/runtime"
@@ -87,7 +86,7 @@ func buildUpstreamRequest(reqCtx *RequestContext, body []byte, options ForwardOp
}
upstreamRequest.Host = reqCtx.TargetURL.Host
if reqCtx.Mode == server.ModeLocal && shouldRewriteHost(reqCtx.TargetURL.Hostname()) {
if shouldRewriteHost(reqCtx.TargetURL.Hostname()) {
auth := formatBearerAuthorization(legacyruntime.LocalRelayToken)
if auth == "" {
return nil, nil, legacyruntime.ErrInvalidSystemSetting
@@ -48,7 +48,6 @@ type RequestContext struct {
Headers http.Header
ContentType string
RequestBody []byte
Mode server.ExecutionMode
Deps *Dependencies
HTTPRequestID string
}