Documentation
¶
Overview ¶
Package client provides a thin wrapper around the official Glean Go SDK, initializing the SDK client from glean-cli's config (env vars, keyring, or ~/.glean/config.json).
Index ¶
- Variables
- func New(cfg *config.Config) (*glean.Glean, error)
- func NewFromConfig() (*glean.Glean, error)
- func ResolveToken(cfg *config.Config) (token, authType string)
- func SetVersion(v string)
- func StreamChat(ctx context.Context, cfg *config.Config, req components.ChatRequest) (io.ReadCloser, error)
- func Version() string
Constants ¶
This section is empty.
Variables ¶
var NewFunc = New
NewFunc is the factory used by NewFromConfig. Override in tests to inject a mock HTTP transport: set NewFunc to return glean.New(glean.WithClient(mock)).
Functions ¶
func New ¶
New creates an authenticated Glean SDK client from the loaded configuration.
Authentication priority:
- GLEAN_API_TOKEN environment variable (via config.LoadConfig)
- System keyring / ~/.glean/config.json (via config.LoadConfig)
- OAuth token from local storage (via auth.LoadOAuthToken)
The GleanHost value is accepted in two forms:
- Full hostname: "linkedin-be.glean.com" → instance = "linkedin"
- Short name: "linkedin" → passed as-is to WithInstance
func NewFromConfig ¶
NewFromConfig loads config then creates the SDK client via NewFunc. Convenience wrapper for command handlers.
func ResolveToken ¶ added in v0.7.0
ResolveToken returns the bearer token and the X-Glean-Auth-Type value for the request. API tokens (cfg.GleanToken) return an empty authType; OAuth tokens sourced from local storage return authTypeOAuth.
func SetVersion ¶ added in v0.5.1
func SetVersion(v string)
SetVersion records the build-time version for use in the User-Agent header.
func StreamChat ¶
func StreamChat(ctx context.Context, cfg *config.Config, req components.ChatRequest) (io.ReadCloser, error)
StreamChat makes a streaming chat request to the Glean API, bypassing the SDK's buffered CreateStream which reads the entire response before returning. The req.Stream field is forced to true. The caller is responsible for closing the returned io.ReadCloser.
The response body is NDJSON: each line is a complete ChatResponse JSON object. Only messages with messageType == "CONTENT" carry user-facing text; callers should skip UPDATE, CONTROL, DEBUG, etc.
Types ¶
This section is empty.