Documentation
¶
Overview ¶
Package proxy serves the compacted API endpoints as a context-compaction proxy (spec §19.1, §19.2 mode 1, §18.2, §16). The HTTP traffic, the wire codecs, session and store meet here. Each dialect is an adapter behind the protocol interface (protocol.go), and one server-side loop serves all of them. Every failure on the compaction side is fail-open: the client request is then forwarded unchanged.
Index ¶
- func CheckListen(addr string, allowNonLoopback bool, allowedHosts []string) error
- func CheckLoopback(addr string) error
- func IsCompactedPath(path string) bool
- func NormalizeHosts(list []string) ([]string, error)
- func ProjectMarkers() []string
- func Run(ctx context.Context, addr string, h http.Handler) error
- func RunListen(ctx context.Context, addr string, allowNonLoopback bool, allowedHosts []string, ...) error
- func SessionID(projectID, conv string, msgs []kernel.Message) string
- type Config
- type Server
- type TurnView
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckListen ¶
CheckListen is CheckLoopback with the explicit opt-in for container deployments. A non-loopback address needs both allowNonLoopback and a non-empty allowedHosts list; the list is what the Host guard then enforces. The default (loopback only) is unchanged.
func CheckLoopback ¶
CheckLoopback rejects listen addresses that are reachable from other hosts. The proxy holds API credentials in transit, so it binds to loopback only.
func IsCompactedPath ¶
IsCompactedPath reports whether a request path is one of the endpoints the proxy compacts (any dialect, with or without a gateway prefix).
func NormalizeHosts ¶
NormalizeHosts turns Host header values (for example "localhost:8787", "[::1]" or "host.docker.internal") into the bare lower-case names the guard compares against. Wildcards and paths are refused, since they would widen the guard silently.
func ProjectMarkers ¶
func ProjectMarkers() []string
ProjectMarkers returns the project root markers of the proxy.
Types ¶
type Config ¶
type Config struct {
Upstream *url.URL
Store *store.Store
// OpenStore opens the database of a project with storage: local
// (<root>/.acd-ctx/acd-ctx.db, spec §18.3) named by X-Acd-Ctx-Project-Dir.
// Nil keeps every project in Store, as a launcher proxy does: its Store is
// already the project's database.
OpenStore func(path string) (*store.Store, error)
Version string
ContextLimit int // window used when the model has no entry, default 200000
MaxLoop int // server-side tool rounds per client request, default 4
Markers []string // project root markers, default go.mod, package.json, ...
Logger *slog.Logger // default: discard
Transport http.RoundTripper
// GlobalPath is the global configuration file (spec §18.1). Empty means the
// user config path. Project files are read per request-project root.
GlobalPath string
// ConfigFlags are explicit configuration keys (the highest layer of §18.5).
ConfigFlags map[string]string
// ContextWindows maps model name prefixes to context windows, added to the
// built-in table (builtinWindows).
ContextWindows map[string]int
// LookupEnv reads ACD_CTX_* variables. Nil means os.LookupEnv.
LookupEnv func(string) (string, bool)
// Now is the clock used for idle times and config reloads. Nil means time.Now.
Now func() time.Time
// ListenHost is the host part of the listen address. It is accepted in the
// Host header in addition to the loopback names. Empty when unknown.
ListenHost string
// UpstreamAllow lists the origins (scheme://host[:port]) reachable through the
// /ctx/<upstream>/ prefix. Default: the origin of Upstream only.
UpstreamAllow []string
// AllowedHosts, when non-empty, is the exact set of Host names the guard
// accepts (replacing the loopback defaults and ListenHost). Set by serve for
// non-loopback listening; see CheckListen.
AllowedHosts []string
// WSIdleTimeout closes a WebSocket connection that has had no client frame for
// this long. Zero means defaultWSIdleTimeout.
WSIdleTimeout time.Duration
// WSMaxFrameBytes caps one WebSocket message in either direction. Zero means
// maxBodyBytes.
WSMaxFrameBytes int64
}
Config wires the proxy. Upstream and Store are required.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the http.Handler of the proxy.
func (*Server) Close ¶ added in v1.0.1
Close closes the local databases the proxy opened. Config.Store belongs to the caller and stays open.
func (*Server) CloseWebSockets ¶
func (s *Server) CloseWebSockets()
CloseWebSockets asks every open WebSocket session to close with 1001 (going away). serve calls it on shutdown, because http.Server does not track hijacked connections.
type TurnView ¶
type TurnView struct {
Visible []kernel.Message
Nudge string // "" when no nudge is due
Hints []kernel.RecallHint
Row string // decision row of spec §8.3, for diagnostics
}
TurnView is one planned turn as the library returns it.
func PlanTurn ¶
func PlanTurn(ctx context.Context, st *store.Store, sess *session.Session, sid string, cfg config.Config, tokenCount int) (TurnView, error)
PlanTurn runs the per-turn steps of compactTurn that follow Ingest: it applies the project settings, plans the trigger, reduces the window (CCR and crush) and writes the nudge text. The caller ingests the transcript first. The cache gate of the server is not applied: a library caller has no upstream cache to measure.