client

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func New(cfg *config.Config) (*glean.Glean, error)

New creates an authenticated Glean SDK client from the loaded configuration.

Authentication priority:

  1. GLEAN_API_TOKEN environment variable (via config.LoadConfig)
  2. System keyring / ~/.glean/config.json (via config.LoadConfig)
  3. 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

func NewFromConfig() (*glean.Glean, error)

NewFromConfig loads config then creates the SDK client via NewFunc. Convenience wrapper for command handlers.

func ResolveToken added in v0.7.0

func ResolveToken(cfg *config.Config) (token, authType string)

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.

func Version added in v0.5.1

func Version() string

Version returns the current CLI version string.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL