Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New returns a server handler with no authentication and no CORS handling. Convenience wrapper over NewWithOptions kept for backwards compatibility with existing call sites (tests, ad-hoc tooling, code that does not yet care about auth or CORS).
func NewWithOptions ¶
NewWithOptions returns a server handler honouring the supplied options. When opts.Token and opts.CORS.AllowedOrigins are both zero values the returned handler is identical to New(service).
Middleware order (outer → inner): CORS → auth → mux. CORS sits outermost so browser preflight (OPTIONS) requests succeed without an Authorization header; auth then guards the actual data routes.
Types ¶
type CORSOptions ¶
type CORSOptions struct {
// AllowedOrigins is the explicit list of origin strings allowed to
// access the API. Special values:
// "*" — allow any origin (NOT recommended with bearer auth).
// "null" — allow Electron / file-based webviews that send Origin: null.
AllowedOrigins []string
// AllowedHeaders extends the default header allowlist; defaults already
// include Authorization, Content-Type, Accept.
AllowedHeaders []string
// AllowedMethods extends the default method allowlist; defaults already
// include GET, POST, OPTIONS.
AllowedMethods []string
}
CORSOptions controls Cross-Origin Resource Sharing handling for callers running inside an Electron host (Windsurf, Cursor, VS Code Composer, ...). These hosts often present origins that browsers normally reject:
- "null" — content loaded from file:// or a sandboxed iframe.
- "app://*" — packaged Electron app schemes.
- "vscode-webview://*" — VS Code webview iframes.
The zero value disables CORS entirely (no headers emitted), matching the historical behaviour for callers that only use the local CLI / hook path.
type Options ¶
type Options struct {
// Token, when non-empty, enables bearer-token authentication for all
// routes except those in SkipAuthPaths.
Token string
// SkipAuthPaths is the set of request paths that bypass the bearer
// check. When nil, defaults to ["/healthz"]; pass an explicit slice
// (possibly empty) to override.
SkipAuthPaths []string
// CORS configures Cross-Origin Resource Sharing for Electron / webview
// callers. Empty AllowedOrigins disables CORS handling entirely.
CORS CORSOptions
// Info supplies metadata returned by GET /v1/info. The AuthEnabled,
// CORSEnabled and CORSOrigins fields are derived automatically from
// the other Options fields; callers should leave them blank. Version,
// ListenAddr, and StartedAt are caller-supplied.
Info ServerInfo
// ErrorLog receives full internal / upstream errors together with the
// request_id returned to the client. Nil disables handler-level logging.
ErrorLog io.Writer
// DefaultMaxContextTokens fills enhancer.Request.Options.MaxContextTokens
// when the request leaves it unset, so the operator-level budget
// (OPENPE_MAX_CONTEXT_TOKENS) governs HTTP callers exactly like it
// governs every hook path. Zero keeps the historical no-budget default.
DefaultMaxContextTokens int
// PromptTimeout limits the whole /v1/prompt-enhance handler. It sits
// inside CORS/auth so synthesized timeout responses retain CORS headers.
PromptTimeout time.Duration
}
Options configures the HTTP server handler. The zero value preserves the historical no-auth, no-CORS behaviour and is what New uses internally.
type ServerInfo ¶
type ServerInfo struct {
Version string `json:"version,omitempty"`
StartedAt time.Time `json:"started_at"`
ListenAddr string `json:"listen_addr,omitempty"`
AuthEnabled bool `json:"auth_enabled"`
CORSEnabled bool `json:"cors_enabled"`
CORSOrigins []string `json:"cors_origins,omitempty"`
}
ServerInfo summarises the running server's runtime metadata. It is returned from GET /v1/info after bearer authentication so IDE installers can confirm the descriptor they read from disk actually matches the live process.
All fields are safe to expose post-authentication; no secrets are present. The bearer token itself is intentionally NOT included — installers already hold it (they used it to authenticate this call).