copilot

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 19 Imported by: 0

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

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

func ResolveToken() (string, error)

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:

  1. GH_COPILOT_TOKEN env var
  2. COPILOT_GITHUB_TOKEN env var
  3. ~/.config/github-copilot/hosts.json
  4. ~/.config/github-copilot/apps.json
  5. ~/.config/gh/hosts.yml

Types

type Config

type Config struct {
	Model string
	Token string
}

Config holds the Copilot adapter configuration.

type LLM

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

LLM implements cogito.LLM for GitHub Copilot.

func New

func New(config Config) *LLM

New creates a Copilot adapter. The API endpoint is discovered lazily on the first request.

func (*LLM) Ask

func (l *LLM) Ask(ctx context.Context, fragment cogito.Fragment) (cogito.Fragment, error)

Ask delegates to CreateChatCompletion, mirroring the other adapters.

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.

func (*LLM) ListModels added in v0.9.1

func (l *LLM) ListModels(ctx context.Context) ([]string, error)

ListModels returns the chat models this Copilot account can pick (GET {endpoint}/models). Copilot also lists embedding models and internal ones the editor's picker hides; only the chat models its picker offers are kept, unless the API marks none, in which case every chat model is kept.

Jump to

Keyboard shortcuts

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