Documentation
¶
Overview ¶
Package transport owns the HTTP, SSE, WebSocket and gRPC wire boundary. Application operations are supplied by the embedding runtime.
Index ¶
- Constants
- func CredentialBucketKey(credential string) string
- func DecodeJSON(w http.ResponseWriter, r *http.Request, dst any, maxBytes int64) error
- func DispatchMethod(w http.ResponseWriter, r *http.Request, handlers map[string]func()) bool
- func NewHTTPServer(addr string, handler http.Handler) *http.Server
- func PublicServerURL(addr string) string
- func RegisterRoutes(mux *http.ServeMux, h Handlers)
- func RemoteIP(remoteAddr string) string
- func SendError(w http.ResponseWriter, message string, code int, details string)
- func SendJSON(w http.ResponseWriter, status int, data any)
- func SendRequestError(w http.ResponseWriter, err error)
- func SendSSEError(w io.Writer, flusher http.Flusher, message string)
- type Config
- type ErrorResponse
- type Handlers
- type Limiter
- type Middleware
- func (s *Middleware) Authenticate(next http.Handler) http.Handler
- func (s *Middleware) CORS(next http.Handler) http.Handler
- func (s *Middleware) Log(next http.Handler) http.Handler
- func (s *Middleware) Protect(next http.Handler) http.Handler
- func (s *Middleware) RateLimit(next http.Handler) http.Handler
- func (s *Middleware) Recover(next http.Handler) http.Handler
- type RequestError
Constants ¶
const ( // DefaultJSONBodyLimit applies to client JSON, including inline attachments. DefaultJSONBodyLimit int64 = 2 << 20 // Multipart upload handlers may enforce a smaller limit of their own. DefaultUploadBodyLimit int64 = 64 << 20 )
Variables ¶
This section is empty.
Functions ¶
func CredentialBucketKey ¶ added in v0.2.3
CredentialBucketKey groups requests by credential without retaining the credential itself in limiter maps. A shared key intentionally shares quota.
func DecodeJSON ¶ added in v0.2.3
DecodeJSON reads exactly one JSON value within maxBytes. Empty bodies return io.EOF so optional-body endpoints can retain their existing behavior.
func DispatchMethod ¶
func NewHTTPServer ¶
NewHTTPServer preserves the existing streaming-friendly listener timeouts.
func PublicServerURL ¶
PublicServerURL turns a bound listener address into a URL a person can open. Wildcard binds stay on localhost instead of printing "localhost127.0.0.1:9090".
func RegisterRoutes ¶
func RemoteIP ¶
RemoteIP strips the transport port from RemoteAddr and handles both bracketed and unbracketed IPv6 addresses.
func SendRequestError ¶ added in v0.2.3
func SendRequestError(w http.ResponseWriter, err error)
SendRequestError maps decoding failures into the common JSON error envelope.
Types ¶
type Config ¶
type Config struct {
Addr string `yaml:"addr,omitempty"` // 监听地址,默认 :9090
APIKeys []string `yaml:"api_keys,omitempty"` // API Key 白名单(空=仅允许经过校验的本机请求)
EnableCORS bool `yaml:"enable_cors,omitempty"` // 启用 CORS,默认 false
CORSOrigins []string `yaml:"cors_origins,omitempty"` // CORS 允许的源
RateLimit int `yaml:"rate_limit,omitempty"` // 每分钟请求限制,默认 60
MetricsAddr string `yaml:"metrics_addr,omitempty"` // Prometheus metrics 独立端口(空=复用主端口)
LogLevel string `yaml:"log_level,omitempty"` // 日志级别: debug, info, warn, error
LogFormat string `yaml:"log_format,omitempty"` // 日志格式: json, text
}
Config API Server 配置
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
Code int `json:"code"`
Details string `json:"details,omitempty"`
ErrorCode string `json:"error_code,omitempty"`
RequestID string `json:"request_id,omitempty"`
}
ErrorResponse 错误响应
type Handlers ¶
type Handlers struct {
HealthLiveness http.HandlerFunc
HealthReadiness http.HandlerFunc
HealthDetail http.HandlerFunc
Metrics http.HandlerFunc
ConfigReload http.HandlerFunc
ConfigSchema http.HandlerFunc
Config http.HandlerFunc
Models http.HandlerFunc
ModelEffort http.HandlerFunc
ModelSwitch http.HandlerFunc
ModelProfiles http.HandlerFunc
Approvals http.HandlerFunc
Chat http.HandlerFunc
ChatSync http.HandlerFunc
Sessions http.HandlerFunc
SessionByID http.HandlerFunc
Uploads http.HandlerFunc
Artifact http.HandlerFunc
Commands http.HandlerFunc
Cron http.HandlerFunc
CronByID http.HandlerFunc
Tasks http.HandlerFunc
TaskByID http.HandlerFunc
AutonomyDashboard http.HandlerFunc
AutonomyTaskByID http.HandlerFunc
Memory http.HandlerFunc
MemoryRecall http.HandlerFunc
MemoryRecallTrace http.HandlerFunc
MemoryStats http.HandlerFunc
MemoryGraph http.HandlerFunc
ProactiveStatus http.HandlerFunc
Tools http.HandlerFunc
Skills http.HandlerFunc
SkillRoutes http.HandlerFunc
Stats http.HandlerFunc
Soul http.HandlerFunc
Context http.HandlerFunc
ContextFit http.HandlerFunc
RAGIndex http.HandlerFunc
RAGSearch http.HandlerFunc
RAGStats http.HandlerFunc
RAGStore http.HandlerFunc
RAGStreamWatch http.HandlerFunc
RAGStreamScan http.HandlerFunc
RAGStreamStart http.HandlerFunc
RAGStreamStop http.HandlerFunc
RAGStreamStatus http.HandlerFunc
RAGStreamIndex http.HandlerFunc
RAGStreamQueue http.HandlerFunc
RAGStreamProcess http.HandlerFunc
FunctionCalling http.HandlerFunc
FCTools http.HandlerFunc
FCHistory http.HandlerFunc
WebSocket http.HandlerFunc
WSStats http.HandlerFunc
SoulTemplates http.HandlerFunc
SoulTemplateByID http.HandlerFunc
EmbedderList http.HandlerFunc
EmbedderRegister http.HandlerFunc
EmbedderSwitch http.HandlerFunc
EmbedderRoutes http.HandlerFunc
AgentsList http.HandlerFunc
AgentsRegister http.HandlerFunc
AgentsDeregister http.HandlerFunc
AgentsDelegate http.HandlerFunc
AgentsTask http.HandlerFunc
AgentsTasks http.HandlerFunc
AgentsCancel http.HandlerFunc
AgentsBlackboard http.HandlerFunc
AgentsMessages http.HandlerFunc
Workflows http.HandlerFunc
WorkflowByID http.HandlerFunc
WorkflowInstances http.HandlerFunc
WorkflowInstanceByID http.HandlerFunc
GatewaysList http.HandlerFunc
GatewayTelegramStart http.HandlerFunc
GatewayByName http.HandlerFunc
Root http.HandlerFunc
}
Handlers are host operations; paths and registration are owned by this module.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware holds transport policy without depending on the host runtime.
func NewMiddleware ¶
func NewMiddleware(config Config, limiter *Limiter, pairingKeyValid func(string) bool, onPanic func()) *Middleware
NewMiddleware accepts optional host-owned pairing and panic-accounting hooks.
func (*Middleware) Authenticate ¶
func (s *Middleware) Authenticate(next http.Handler) http.Handler
authMiddleware API Key 认证中间件
func (*Middleware) CORS ¶
func (s *Middleware) CORS(next http.Handler) http.Handler
corsMiddleware CORS 中间件
func (*Middleware) Log ¶
func (s *Middleware) Log(next http.Handler) http.Handler
loggingMiddleware 日志中间件
func (*Middleware) Protect ¶ added in v0.2.3
func (s *Middleware) Protect(next http.Handler) http.Handler
Protect is the complete HTTP policy. Hosts should wrap it with logging and their optional CORS middleware, without adding Authenticate/RateLimit again. Independent, generous per-peer admission limits protect authentication; the business limit is per credential, with public probes in a separate IP bucket.
type RequestError ¶ added in v0.2.3
RequestError contains only a public message, never the submitted body or key.
func (*RequestError) Error ¶ added in v0.2.3
func (e *RequestError) Error() string
Directories
¶
| Path | Synopsis |
|---|---|
|
Package luckyagent is a reverse proxy.
|
Package luckyagent is a reverse proxy. |
|
Package resources serves optional tool-runtime HTTP resources through host-supplied ports.
|
Package resources serves optional tool-runtime HTTP resources through host-supplied ports. |