Documentation
¶
Index ¶
- Constants
- func ApplyCopilotClientHeaders(header http.Header)
- func CanOpenBrowser() bool
- func CheckCopilotModelsAPI(token, baseURL string) error
- func CopilotAPIBaseURL(enterpriseURL string) string
- func CopilotClientHeaders() map[string]string
- func CopilotDeviceFlowInstructions(deviceCode CopilotDeviceCode) string
- func CopilotEntitlementError(user *CopilotUser) string
- func CopilotSessionFilePath() (string, error)
- func CopilotTokenExchangeDisabled() bool
- func DeleteCopilotSession() error
- func DiscoverCopilotAPIEndpoint(ctx context.Context, token, enterpriseURL string) string
- func IsCopilotAPIToken(token string) bool
- func LoadGitHubOAuthToken() (string, error)
- func NormalizeGitHubDomain(value string) string
- func OpenBrowser(url string) error
- func ResolveCopilotAPIAccess(ctx context.Context, token, enterpriseURL, configuredBaseURL string) (string, string)
- func SaveCopilotSession(session CopilotSession) error
- func ValidateCopilotToken(ctx context.Context, session CopilotSession) error
- type CopilotAPIToken
- type CopilotAuthStatus
- type CopilotDeviceCode
- type CopilotSession
- func CompleteCopilotDeviceFlow(ctx context.Context, enterpriseURL string, deviceCode *CopilotDeviceCode) (*CopilotSession, error)
- func LoadCopilotSession() (*CopilotSession, error)
- func PollCopilotDeviceFlow(ctx context.Context, enterpriseURL string, deviceCode *CopilotDeviceCode) (*CopilotSession, error)
- type CopilotUser
- type GitHubTokenCandidate
Constants ¶
const ( // CopilotAPIVersion is sent as X-GitHub-Api-Version on every request to the // Copilot API host (models, chat, responses, auto routing). It pins the // response shapes Pando parses, e.g. billing.token_prices.cache_read_price. CopilotAPIVersion = "2026-08-01" )
const (
CopilotClientID = "Ov23li8tweQw6odWQebz"
)
Variables ¶
This section is empty.
Functions ¶
func ApplyCopilotClientHeaders ¶ added in v1.5.7
ApplyCopilotClientHeaders sets CopilotClientHeaders on an outgoing request.
func CanOpenBrowser ¶ added in v0.700.0
func CanOpenBrowser() bool
func CheckCopilotModelsAPI ¶
CheckCopilotModelsAPI verifies that the Copilot models API endpoint is reachable using the provided bearer token and base URL.
func CopilotAPIBaseURL ¶
func CopilotClientHeaders ¶ added in v1.5.7
CopilotClientHeaders returns the headers that identify Pando to the Copilot API. The per-seat hosts reject requests that do not identify an editor.
func CopilotDeviceFlowInstructions ¶
func CopilotDeviceFlowInstructions(deviceCode CopilotDeviceCode) string
func CopilotEntitlementError ¶ added in v1.5.7
func CopilotEntitlementError(user *CopilotUser) string
CopilotEntitlementError returns a user-facing message when the account explicitly has no Copilot chat access, and "" otherwise. Only an explicit chat_enabled=false counts: a missing field must not turn into a denial.
func CopilotSessionFilePath ¶
func CopilotTokenExchangeDisabled ¶ added in v0.644.0
func CopilotTokenExchangeDisabled() bool
CopilotTokenExchangeDisabled reports whether the user opted out of the token exchange, forcing the legacy behaviour of sending the raw OAuth token.
func DeleteCopilotSession ¶
func DeleteCopilotSession() error
func DiscoverCopilotAPIEndpoint ¶ added in v1.5.7
DiscoverCopilotAPIEndpoint returns the Copilot API host GitHub advertises for the account behind a raw OAuth token, or "" when it cannot be determined. Successful lookups are cached for a while, and failures for a shorter time so a broken token does not add a round trip to every request.
func IsCopilotAPIToken ¶ added in v0.644.0
IsCopilotAPIToken reports whether the token already is an exchanged Copilot API token (they are opaque "tid=...;exp=..." strings) rather than a GitHub OAuth token. Exchanging one of these again is not possible.
func LoadGitHubOAuthToken ¶
func NormalizeGitHubDomain ¶
func OpenBrowser ¶
func ResolveCopilotAPIAccess ¶ added in v0.644.0
func ResolveCopilotAPIAccess(ctx context.Context, token, enterpriseURL, configuredBaseURL string) (string, string)
ResolveCopilotAPIAccess returns the bearer token and API base URL to use for Copilot requests. It exchanges the GitHub OAuth token for a Copilot API token so that organization BYOK custom models become visible, and falls back to the supplied token and base URL when the exchange is unavailable.
configuredBaseURL, when non-empty, always wins: an explicitly configured host must not be silently replaced by the one advertised by GitHub.
func SaveCopilotSession ¶
func SaveCopilotSession(session CopilotSession) error
func ValidateCopilotToken ¶
func ValidateCopilotToken(ctx context.Context, session CopilotSession) error
Types ¶
type CopilotAPIToken ¶ added in v0.644.0
type CopilotAPIToken struct {
Token string
ExpiresAt int64
APIEndpoint string
Organizations []string
SKU string
}
CopilotAPIToken is the result of exchanging a GitHub OAuth token for a short-lived Copilot API token.
func ExchangeCopilotAPIToken ¶ added in v0.644.0
func ExchangeCopilotAPIToken(ctx context.Context, oauthToken, enterpriseURL string) (*CopilotAPIToken, error)
ExchangeCopilotAPIToken trades a GitHub OAuth token for a short-lived Copilot API token. Results are cached in memory until shortly before expiry.
type CopilotAuthStatus ¶
type CopilotAuthStatus struct {
Authenticated bool
Source string
EnterpriseURL string
Message string
}
func GetCopilotAuthStatus ¶
func GetCopilotAuthStatus() CopilotAuthStatus
type CopilotDeviceCode ¶
type CopilotDeviceCode struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationURI string `json:"verification_uri"`
Interval int `json:"interval"`
ExpiresIn int `json:"expires_in"`
}
func StartCopilotDeviceFlow ¶
func StartCopilotDeviceFlow(ctx context.Context, enterpriseURL string) (*CopilotDeviceCode, error)
type CopilotSession ¶
type CopilotSession struct {
Provider string `json:"provider,omitempty"`
AccessToken string `json:"access_token"`
TokenType string `json:"token_type,omitempty"`
Scope string `json:"scope,omitempty"`
ExpiresAt int64 `json:"expires_at,omitempty"`
EnterpriseURL string `json:"enterprise_url,omitempty"`
CreatedAt int64 `json:"created_at,omitempty"`
}
func CompleteCopilotDeviceFlow ¶
func CompleteCopilotDeviceFlow(ctx context.Context, enterpriseURL string, deviceCode *CopilotDeviceCode) (*CopilotSession, error)
func LoadCopilotSession ¶
func LoadCopilotSession() (*CopilotSession, error)
func PollCopilotDeviceFlow ¶
func PollCopilotDeviceFlow(ctx context.Context, enterpriseURL string, deviceCode *CopilotDeviceCode) (*CopilotSession, error)
type CopilotUser ¶ added in v1.5.7
type CopilotUser struct {
// ChatEnabled is nil when GitHub did not report it.
ChatEnabled *bool
CanSignupForLimited bool
Plan string
// APIEndpoint is the Copilot API host of the account's plan, for example
// https://api.business.githubcopilot.com. It changes with the plan.
APIEndpoint string
}
CopilotUser is the subset of GET /copilot_internal/user Pando relies on.
func FetchCopilotUser ¶ added in v1.5.7
func FetchCopilotUser(ctx context.Context, token, enterpriseURL string) (*CopilotUser, error)
FetchCopilotUser reads the Copilot account record of a GitHub OAuth token. OAuth itself succeeds for any GitHub account, so this is the only signal that tells whether the account can chat and which API host serves it.
type GitHubTokenCandidate ¶ added in v0.644.0
GitHubTokenCandidate is a GitHub OAuth token discovered locally, tagged with where it came from.
func GitHubOAuthTokenCandidates ¶ added in v0.644.0
func GitHubOAuthTokenCandidates() []GitHubTokenCandidate
GitHubOAuthTokenCandidates returns every usable GitHub OAuth token found on this machine, in the same priority order LoadGitHubOAuthToken applies. Not all of them can be exchanged for a Copilot API token (only tokens issued to an app with Copilot entitlement can), so callers that need the exchanged token walk the list instead of taking just the first entry.