copilot

package
v8.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModelPrefix   = Provider + "/"
	Chat          = "/chat/completions"
	Messages      = "/v1/messages"
	Responses     = "/responses"
	CatalogMaxAge = 2 * time.Hour
)
View Source
const CLIEditor = "copilot/1.0.114"
View Source
const Provider = "copilot"

Variables

View Source
var CLIUserAgent = func() string {
	platform := runtime.GOOS
	if platform == "windows" {
		platform = "win32"
	}
	return CLIEditor + " (" + platform + " v24.22.1) term/unknown"
}()
View Source
var PresetCatalog = &Catalog{}

PresetCatalog is used only while a usable credential awaits its first discovery.

View Source
var UnavailableCatalog = &Catalog{}

UnavailableCatalog records a revoked account until discovery succeeds again.

Functions

func FetchModels

func FetchModels(ctx context.Context, client *http.Client, base, token string) (json.RawMessage, error)

FetchModels returns the complete upstream response, including unknown fields.

func PollDeviceFlow

func PollDeviceFlow(ctx context.Context, client *http.Client, code DeviceCode) (string, error)

func RequestJSON

func RequestJSON(ctx context.Context, client *http.Client, endpoint, bearer string, form url.Values, out any) error

func TrustedAPI

func TrustedAPI(raw string) bool

TrustedAPI restricts where inference credentials can be sent.

Types

type Account

type Account struct {
	ID    int64  `json:"id"`
	Login string `json:"login"`
}

func GetAccount

func GetAccount(ctx context.Context, client *http.Client, githubToken string) (Account, error)

type Catalog

type Catalog struct {
	// contains filtered or unexported fields
}

Catalog is an immutable account snapshot shared by runtime auth clones.

func FetchCatalog

func FetchCatalog(ctx context.Context, client *http.Client, base, token string) (*Catalog, error)

func NewCatalog

func NewCatalog(models []Model, fetchedAt time.Time) *Catalog

NewCatalog takes ownership of the nested model fields. The first entry for an ID wins.

func (*Catalog) Active

func (c *Catalog) Active(now time.Time) *Catalog

func (*Catalog) ExpiresAt

func (c *Catalog) ExpiresAt() time.Time

func (*Catalog) Route

func (c *Catalog) Route(modelID string) (Route, bool)

func (*Catalog) Routes

func (c *Catalog) Routes() []Route

func (*Catalog) SameModels

func (c *Catalog) SameModels(other *Catalog) bool

type Compatibility

type Compatibility struct {
	SystemPrompt       string   `json:"system_prompt"`
	Endpoint           string   `json:"endpoint"`
	AdaptiveMode       string   `json:"adaptive_mode"`
	NonStreamingOutput int      `json:"max_non_streaming_output_tokens"`
	LimitEfforts       bool     `json:"limit_efforts"`
	DefaultVerbosity   string   `json:"default_verbosity"`
	DefaultToolChoice  string   `json:"default_tool_choice"`
	DisableSnippy      bool     `json:"disable_snippy"`
	DefaultEffort      string   `json:"default_effort"`
	DefaultBudget      int      `json:"default_budget"`
	DefaultMaxTokens   int      `json:"default_max_tokens"`
	AnthropicBetas     []string `json:"anthropic_betas"`
}

type DeviceCode

type DeviceCode struct {
	DeviceCode      string `json:"device_code"`
	UserCode        string `json:"user_code"`
	VerificationURI string `json:"verification_uri"`
	ExpiresIn       int    `json:"expires_in"`
	Interval        int    `json:"interval"`
}

func StartDeviceFlow

func StartDeviceFlow(ctx context.Context, client *http.Client) (DeviceCode, error)

type HTTPError

type HTTPError struct {
	Code int
}

func (HTTPError) Error

func (e HTTPError) Error() string

func (HTTPError) StatusCode

func (e HTTPError) StatusCode() int

type Model

type Model struct {
	ID            string   `json:"id"`
	DefaultEffort string   `json:"default_reasoning_effort,omitempty"`
	Name          string   `json:"name"`
	Endpoints     []string `json:"supported_endpoints"`
	Picker        *bool    `json:"model_picker_enabled,omitempty"`
	Policy        struct {
		State string `json:"state,omitempty"`
	} `json:"policy"`
	Capabilities struct {
		Type     string `json:"type,omitempty"`
		Supports struct {
			Tools     *bool           `json:"tool_calls,omitempty"`
			Vision    *bool           `json:"vision,omitempty"`
			Thinking  *bool           `json:"thinking,omitempty"`
			Adaptive  json.RawMessage `json:"adaptive_thinking,omitempty"`
			Reasoning json.RawMessage `json:"reasoning_effort,omitempty"`
			MinBudget int             `json:"min_thinking_budget,omitempty"`
			MaxBudget int             `json:"max_thinking_budget,omitempty"`
		} `json:"supports"`
		Limits struct {
			Context            int `json:"max_context_window_tokens,omitempty"`
			Input              int `json:"max_prompt_tokens,omitempty"`
			Output             int `json:"max_output_tokens,omitempty"`
			NonStreamingOutput int `json:"max_non_streaming_output_tokens,omitempty"`
		} `json:"limits"`
	} `json:"capabilities"`
}

type Route

type Route struct {
	SystemPrompt       string
	Endpoint           string
	Format             translator.Format
	Info               *registry.ModelInfo
	DefaultEffort      string
	NonStreamingOutput int
	DefaultVerbosity   string
	DefaultToolChoice  string
	DisableSnippy      bool
	DefaultBudget      int
	DefaultMaxTokens   int
	AnthropicBetas     []string
}

func HomeRoute

func HomeRoute(modelID string, info *registry.ModelInfo) (Route, bool)

HomeRoute applies CLI compatibility to the model selected by Home.

type Token

type Token struct {
	Value     string `json:"token"`
	ExpiresAt int64  `json:"expires_at"`
	Endpoints struct {
		API string `json:"api"`
	} `json:"endpoints"`
}

func Exchange

func Exchange(ctx context.Context, client *http.Client, githubToken string) (Token, error)

func (Token) API

func (t Token) API() (string, error)

Jump to

Keyboard shortcuts

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