Documentation
¶
Overview ¶
Package copilot implements the GitHub Copilot multi-protocol adapter.
Copilot does not have its own wire protocol — it proxies to OpenAI Chat Completions, OpenAI Responses, or Anthropic Messages depending on the model. The adapter discovers the API endpoint via GraphQL, resolves a token from the gh CLI / Copilot client config, and routes each request to the right protocol using model-name heuristics.
Token resolution (env → ~/.config/github-copilot/ → ~/.config/gh/) lives in discovery.go. Protocol translation reuses the anthropic and openairesponses packages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoResponse = fmt.Errorf("copilot: completed without an assistant message")
ErrNoResponse is returned when the API returns a message with no content.
Functions ¶
func ResolveToken ¶
ResolveToken finds a Copilot OAuth token from environment variables or the config files written by gh CLI / Copilot client. It does NOT read the credential store — the caller (factory or login command) handles that.
Resolution order:
- GH_COPILOT_TOKEN env var
- COPILOT_GITHUB_TOKEN env var
- ~/.config/github-copilot/hosts.json
- ~/.config/github-copilot/apps.json
- ~/.config/gh/hosts.yml
Types ¶
type LLM ¶
type LLM struct {
// contains filtered or unexported fields
}
LLM implements cogito.LLM for GitHub Copilot.
func New ¶
New creates a Copilot adapter. The API endpoint is discovered lazily on the first request.
func (*LLM) CreateChatCompletion ¶
func (l *LLM) CreateChatCompletion(ctx context.Context, request openai.ChatCompletionRequest) (cogito.LLMReply, cogito.LLMUsage, error)
CreateChatCompletion routes the request to the appropriate Copilot API based on model-name heuristics, then translates the response back to OpenAI types.