Documentation ¶
Overview ¶
Package copilot provides the types and functions for authoring GitHub Copilot Extensions.
Use this package to build GitHub Copilot agents and skillsets.
Index ¶
- Constants
- Variables
- func AddGetHubToken(ctx context.Context, data string) context.Context
- func AddSessionInfo(ctx context.Context, data *SessionInfo) context.Context
- func AgentHandler(v PayloadVerifier, a Agent) http.HandlerFunc
- func ChatCompletions(ctx context.Context, token string, r CompletionsRequest, w io.Writer) (io.ReadCloser, error)
- func ChatCompletionsStream(ctx context.Context, token string, r CompletionsRequest, w io.Writer) (io.ReadCloser, error)
- func GetGetHubToken(ctx context.Context) string
- type Agent
- type ChatChoice
- type ChatChoiceDelta
- type ChatChoiceDeltaFunctionCall
- type ChatRole
- type ClientConfirmation
- type ClientConfirmationState
- type CompletionsRequest
- type CompletionsTool
- type Config
- type Confirmation
- type ConfirmationType
- type CopilotModel
- type Error
- type ErrorType
- type Issue
- type Message
- type PayloadVerifier
- type PullRequest
- type Reference
- type ReferenceData
- type ReferenceDataClientFile
- type ReferenceDataClientSelection
- type ReferenceDataClientSelectionLocation
- type ReferenceDataGitHubAgent
- type ReferenceDataGitHubCurrentUrl
- type ReferenceDataGitHubFile
- type ReferenceDataGitHubRedacted
- type ReferenceDataGitHubRepository
- type ReferenceDataGitHubRepositoryLanguage
- type ReferenceDataGitHubRepositoryRefInfo
- type ReferenceDataGitHubSnippet
- type ReferenceDataGitHubSnippetRange
- type ReferenceDataOther
- type ReferenceMetadata
- type ReferenceType
- type RepoItemRefType
- type Request
- type Response
- type SessionInfo
- type ToolCall
- type ToolFunctionCall
- type ToolFunctionDefinition
Constants ¶
const ( GitHubTokenHeader = "X-Github-Token" PublicKeyIdentifierHeader = "Github-Public-Key-Identifier" PublicKeySignatureHeader = "Github-Public-Key-Signature" )
const ( GitHubAppIDKey string = "GITHUB_APP_ID" GitHubAppClientIDKey string = "GITHUB_APP_CLIENT_ID" GitHubAppClientSecretKey string = "GITHUB_APP_CLIENT_SECRET" GitHubAppPrivateKeyPathKey string = "GITHUB_APP_PRIVATE_KEY_PATH" GitHubAppWebhookSecretKey string = "GITHUB_APP_WEBHOOK_SECRET" GitHubAppFQDNKey string = "GITHUB_APP_FQDN" GitHubAppUserAgentKey string = "GITHUB_APP_USER_AGENT" OpenAIChatModelKey string = "OPENAI_CHAT_MODEL" )
const ( ChatFinishReasonStop string = "stop" ChatFinishReasonToolCalls string = "tool_calls" ChatFinishReasonFunctionCall string = "function_call" )
const (
OpenAIChatModelDefault string = "gpt-4o"
)
Variables ¶
var ( ClientConfirmationStateAccepted = ClientConfirmationState{"accepted"} ClientConfirmationStateDismissed = ClientConfirmationState{"dismissed"} )
var ( ErrorTypeReference = ErrorType{"reference"} ErrorTypeFunction = ErrorType{"function"} ErrorTypeAgent = ErrorType{"agent"} )
var ( RepoItemRefTypeIssue = RepoItemRefType{"issue", "issues"} RepoItemRefTypePull = RepoItemRefType{"pull", "pulls"} )
var (
ConfirmationTypeAction = ConfirmationType{"action"}
)
Functions ¶
func AddGetHubToken ¶ added in v1.0.4
AddGetHubToken adds the SessionInfo object to the context.
func AddSessionInfo ¶ added in v1.0.4
func AddSessionInfo(ctx context.Context, data *SessionInfo) context.Context
AddSessionInfo adds the SessionInfo object to the context.
func AgentHandler ¶
func AgentHandler(v PayloadVerifier, a Agent) http.HandlerFunc
func ChatCompletions ¶ added in v1.0.1
func ChatCompletions(ctx context.Context, token string, r CompletionsRequest, w io.Writer) (io.ReadCloser, error)
ChatCompletions sends a request to the the Copilot API to get completions.
func ChatCompletionsStream ¶ added in v1.0.1
func ChatCompletionsStream(ctx context.Context, token string, r CompletionsRequest, w io.Writer) (io.ReadCloser, error)
ChatCompletionsStream is a convenience function that sets the Stream field to true and calls ChatCompletions.
func GetGetHubToken ¶ added in v1.0.4
GetGetHubToken returns the SessionInfo object from the context.
Types ¶
type ChatChoice ¶
type ChatChoice struct { Index int64 `json:"index"` FinishReason string `json:"finish_reason,omitempty"` Delta ChatChoiceDelta `json:"delta"` }
type ChatChoiceDelta ¶
type ChatChoiceDelta struct { Content string `json:"content"` Role string `json:"role,omitempty"` Name string `json:"name,omitempty"` FunctionCall *ChatChoiceDeltaFunctionCall `json:"function_call,omitempty"` }
type ClientConfirmation ¶
type ClientConfirmation struct { State ClientConfirmationState `json:"state"` Confirmation any `json:"confirmation"` }
ClientConfirmation represents a confirmation that the user has accepted or dismissed.
type ClientConfirmationState ¶
type ClientConfirmationState struct {
// contains filtered or unexported fields
}
func (ClientConfirmationState) MarshalJSON ¶
func (c ClientConfirmationState) MarshalJSON() ([]byte, error)
func (*ClientConfirmationState) UnmarshalJSON ¶
func (c *ClientConfirmationState) UnmarshalJSON(data []byte) error
type CompletionsRequest ¶ added in v1.0.1
type CompletionsRequest struct { Model CopilotModel `json:"model" default:"gpt-4o"` Messages []*Message `json:"messages"` Tools []*CompletionsTool `json:"tools,omitempty"` Stream bool `json:"stream"` }
CompletionsRequest is a request to the Copilot API to get completions.
type CompletionsTool ¶ added in v1.0.1
type CompletionsTool struct { Type string `json:"type" default:"function"` Function ToolFunctionDefinition `json:"function"` }
CompletionsTool represents a tool to use for completions.
type Config ¶
type Config struct { // Environment is the environment the app is running in (development, production, etc). // It is resolved from the ENVIRONMENT environment variable. Environment string // HTTPPort is the port the HTTP server will listen on. // It is resolved from the PORT environment variable. HTTPPort string // GitHubAppFQDN is the fully qualified domain name of the GitHub App. // It is resolved from the GITHUB_APP_FQDN environment variable. // If using devoutness or ngrok, this should be the public URL. GitHubAppFQDN string // GitHubAppID is the app ID of the GitHub App. // It is resolved from the GITHUB_APP_ID environment variable. // Note that this is not required for the GitHub App to function. GitHubAppID int64 // GitHubAppClientID is the client ID of the GitHub App. // It is resolved from the GITHUB_APP_CLIENT_ID environment variable. GitHubAppClientID string // GitHubAppClientSecret is the client secret of the GitHub App. // It is resolved from the GITHUB_APP_CLIENT_SECRET environment variable. GitHubAppClientSecret string // GitHubAppPrivateKeyPath is the path to the private key of the GitHub App. // It is resolved from the GITHUB_APP_PRIVATE_KEY_PATH environment variable. // The file should be a PEM file. GitHubAppPrivateKeyPath string // GitHubAppPrivateKey is the private key of the GitHub App. // It is resolved from the pem file at GitHubAppPrivateKeyPath. GitHubAppPrivateKey []byte // GitHubAppWebhookSecret is the secret used to validate GitHub App webhooks. // It is resolved from the GITHUB_APP_WEBHOOK_SECRET environment variable. GitHubAppWebhookSecret string // GitHubAppUserAgent is the user agent to use when making requests to the GitHub API. // It is resolved from the GITHUB_APP_USER_AGENT environment variable. GitHubAppUserAgent string // ChatModel is the OpenAI chat model to use. // It is resolved from the OPENAI_CHAT_MODEL environment variable. // If not set, it defaults to "gpt-4o". ChatModel string // Azure is the configuration for Azure OpenAI. Azure *azure.Config }
Config represents the configuration of the app.
func LoadConfig ¶
LoadConfig reads the environment variables (optionally loading them first from .env files using godotenv), and returns a new Config.
env is the .env file(s) to load
- If none are provided, it will default to loading .env in the current path.
- If multiple are provided, they will be loaded in order, with later files overriding earlier ones.
- To skip loading .env files with godotenv, pass an empty string.
func (*Config) IsDevelopment ¶
IsDevelopment reports whether the environment is development.
func (*Config) IsProduction ¶
IsProduction reports whether the environment is production (or staging).
type Confirmation ¶
type Confirmation struct { // Type is a string that specifies the confirmation's type. // Currently, action is the only supported value for type. Type ConfirmationType `json:"type" default:"action"` // Title is the title of the confirmation dialog shown to the user. Title string `json:"title"` // Message is the message of the confirmation dialog shown to the user. Message string `json:"message"` // Confirmation an optional field for the agent to include any data needed // to uniquely identify this confirmation and take action once the decision // is received from the client. Confirmation any `json:"confirmation"` }
Confirmation represents a confirmation that the agent has sent to the user.
type ConfirmationType ¶
type ConfirmationType struct {
// contains filtered or unexported fields
}
func (ConfirmationType) MarshalJSON ¶
func (c ConfirmationType) MarshalJSON() ([]byte, error)
func (*ConfirmationType) UnmarshalJSON ¶
func (c *ConfirmationType) UnmarshalJSON(data []byte) error
type CopilotModel ¶ added in v1.0.1
type CopilotModel string
CopilotModel represents the model to use for completions.
const ( CopilotModelGPT35 CopilotModel = "gpt-3.5-turbo" CopilotModelGPT4 CopilotModel = "gpt-4" CopilotModelGPT4o CopilotModel = "gpt-4o" CopilotModelEmbeddings CopilotModel = "text-embedding-ada-002" )
type Error ¶
type Error struct { // Type is a string that specifies the error's type. type can have a value of // reference, function or agent. Type ErrorType `json:"type"` // Code is string controlled by the agent describing the nature of an error. Code string `json:"code"` // Message is string that specifies the error message shown to the user. Message string `json:"message"` // Identifier is string that serves as a unique identifier to link the error // with other resources such as references or function calls. Identifier string `json:"identifier"` }
Error represents an error that occurred during the agent request.
type ErrorType ¶
type ErrorType struct {
// contains filtered or unexported fields
}
ErrorType is a string that specifies the error's type. type can have a value of reference, function or agent.
func (ErrorType) MarshalJSON ¶
func (*ErrorType) UnmarshalJSON ¶
type Issue ¶
type Issue struct {
// contains filtered or unexported fields
}
Issue represents a github issue
type Message ¶
type Message struct { Role ChatRole `json:"role"` Content string `json:"content"` Name string `json:"name,omitempty"` References []*Reference `json:"copilot_references"` Confirmations []*ClientConfirmation `json:"copilot_confirmations"` FunctionCall *ToolFunctionCall `json:"function_call,omitempty"` ToolCalls []*ToolCall `json:"tool_calls,omitempty"` ToolCallID string `json:"tool_call_id,omitempty"` }
Message is a message in the request.
func (*Message) IsSessionMessage ¶ added in v1.0.4
IsSessionMessage returns true if the message has the role of "system" and the name of "_session"
type PayloadVerifier ¶
PayloadVerifier is for verifying a payload using ECDSA to ensure it's from GitHub.
func NewPayloadVerifier ¶
func NewPayloadVerifier() (PayloadVerifier, error)
NewVerifier returns a new Verifier.
func NewPayloadVerifierWithKey ¶
func NewPayloadVerifierWithKey(pubKey string) (PayloadVerifier, error)
NewPayloadVerifierWithKey returns a new Verifier with the given public key.
type PullRequest ¶
type PullRequest struct {
// contains filtered or unexported fields
}
PullRequest represents a github pull request
type Reference ¶
type Reference struct { // Type is the type of the copilot references. Type ReferenceType `json:"type"` // ID is the unique identifier of the copilot references. ID string `json:"id"` // IsImplicit specifies if the reference was passed implicitly or explicitly. IsImplicit bool `json:"is_implicit"` // Metadata includes any metadata to display in the user's environment. // If any of the Metadata required fields are missing, the reference will // not be rendered in the UI. Metadata ReferenceMetadata `json:"metadata"` // Data that is specific to the copilot references. Data ReferenceData `json:"-"` RawData json.RawMessage `json:"data"` }
Reference is a copilot_reference in chat messages
func (*Reference) UnmarshalJSON ¶
type ReferenceData ¶
type ReferenceData interface{}
ReferenceData is the data that is specific to the copilot_reference type.
type ReferenceDataClientFile ¶
type ReferenceDataClientFile struct { Content string `json:"content"` Language string `json:"language"` }
ReferenceDataClientFile contains information about a specific file on a client. Included on copilot references of type: "client.file"
"client.file" is sent by the vscode chat client (and likely visual studio).
type ReferenceDataClientSelection ¶
type ReferenceDataClientSelection struct { Content string `json:"content"` End ReferenceDataClientSelectionLocation `json:"end"` Start ReferenceDataClientSelectionLocation `json:"start"` }
ReferenceDataClientSelection contains information about a selection in a file. Included on copilot references of type: "client.selection"
"client.selection" is sent by the vscode chat client (and likely visual studio).
type ReferenceDataGitHubAgent ¶
type ReferenceDataGitHubAgent struct { AvatarURL string `json:"avatarURL"` ID int64 `json:"id"` Login string `json:"login"` Type string `json:"type" default:"github.agent"` URL string `json:"url"` }
ReferenceDataGitHubAgent contains information about a GitHub Copilot agent. Included on copilot references of type: "github.agent"
type ReferenceDataGitHubCurrentUrl ¶
type ReferenceDataGitHubCurrentUrl struct { URL string `json:"url"` Owner string `json:"owner"` Repo string `json:"repo"` Path string `json:"path,omitempty"` Hash string `json:"hash,omitempty"` }
ReferenceDataGitHubCurrentUrl contains information about the users current URL. Included on copilot references of type: "github.current-url"
Note: this is a special copilot_reference that only seems to be present in a message with role: "user" and name: "_session"
Only the URL field is sent by the client, the rest of the fields are extracted during unmarshaling.
"github.current-url" is ONLY sent by the github.com (web) chat client.
func (*ReferenceDataGitHubCurrentUrl) UnmarshalJSON ¶
func (u *ReferenceDataGitHubCurrentUrl) UnmarshalJSON(data []byte) error
type ReferenceDataGitHubFile ¶
type ReferenceDataGitHubFile struct { CommitOID string `json:"commitOID"` LanguageID int64 `json:"languageID"` LanguageName string `json:"languageName"` Path string `json:"path"` Ref string `json:"ref"` RepoID int64 `json:"repoID"` RepoName string `json:"repoName"` RepoOwner string `json:"repoOwner"` Type string `json:"type" default:"file"` URL string `json:"url"` }
ReferenceDataGitHubFile contains information about a file in a github repository. Included on copilot references of type: "github.file"
"github.file" is ONLY sent by github.com (web) chat client.
type ReferenceDataGitHubRedacted ¶
type ReferenceDataGitHubRedacted struct { // Type is the type of the copilot references that was redacted. Type ReferenceType `json:"type"` }
ReferenceDataGitHubRedacted contains information about a redacted copilot_reference. Included on copilot references of type: "github.redacted"
type ReferenceDataGitHubRepository ¶
type ReferenceDataGitHubRepository struct { CommitOID string `json:"commitOID"` Description string `json:"description"` ID int64 `json:"id"` Languages []*ReferenceDataGitHubRepositoryLanguage `json:"languages"` Name string `json:"name"` OwnerLogin string `json:"ownerLogin"` OwnerType string `json:"ownerType"` ReadmePath string `json:"readmePath"` Ref string `json:"ref"` RefInfo ReferenceDataGitHubRepositoryRefInfo `json:"refInfo"` Type string `json:"type" default:"repository"` Visibility string `json:"visibility"` }
ReferenceDataGitHubRepository contains information about a github repository. Included on copilot references of type: "github.repository"
Note: fields set by different clients vary, and are not guaranteed to be present. ID, OwnerLogin, Name, and Type do seem to be present across clients.
"github.repository" is sent by the vscode and github.com (web) chat clients.
type ReferenceDataGitHubSnippet ¶
type ReferenceDataGitHubSnippet struct { CommitOID string `json:"commitOID"` LanguageID int64 `json:"languageID"` LanguageName string `json:"languageName"` Path string `json:"path"` Range ReferenceDataGitHubSnippetRange `json:"range"` Ref string `json:"ref"` RepoID int64 `json:"repoID"` RepoName string `json:"repoName"` RepoOwner string `json:"repoOwner"` Type string `json:"type" default:"snippet"` URL string `json:"url"` }
ReferenceDataGitHubSnippet contains information about a code snippet from a file in a github repository. Included on copilot references of type: "github.snippet"
"github.snippet" is ONLY sent by github.com (web) chat client.
type ReferenceDataOther ¶ added in v1.0.1
type ReferenceDataOther struct {
Type string `json:"type"`
}
ReferenceDataOther contains information about a copilot_reference that is not included in the well-known types.
type ReferenceMetadata ¶
type ReferenceMetadata struct { DisplayName string `json:"display_name"` DisplayIcon string `json:"display_icon"` DisplayURL string `json:"display_url"` }
ReferenceMetadata contains metadata about a copilot_reference to display in the user's environment. If any of the required fields are missing, the reference will not be rendered in the UI.
type ReferenceType ¶
type ReferenceType string
ReferenceType is the type of copilot_reference.
const ( // ReferenceTypeGitHubRedacted is another reference that has been redacted. ReferenceTypeGitHubRedacted ReferenceType = "github.redacted" // ReferenceTypeGitHubAgent is a GitHub Copilot agent. ReferenceTypeGitHubAgent ReferenceType = "github.agent" // ReferenceTypeGitHubCurrentUrl is the current URL of the user. ReferenceTypeGitHubCurrentUrl ReferenceType = "github.current-url" // ReferenceTypeGitHubFile is a file in a GitHub repository. ReferenceTypeGitHubFile ReferenceType = "github.file" // ReferenceTypeGitHubRepository is a GitHub repository. ReferenceTypeGitHubRepository ReferenceType = "github.repository" // ReferenceTypeGitHubSnippet is a code snippet from a file in a GitHub repository. ReferenceTypeGitHubSnippet ReferenceType = "github.snippet" // ReferenceTypeClientFile is a file from a client like vscode. ReferenceTypeClientFile ReferenceType = "client.file" // ReferenceTypeClientSelection is a selection in a file from a client like vscode. ReferenceTypeClientSelection ReferenceType = "client.selection" )
type RepoItemRefType ¶
func (RepoItemRefType) MarshalJSON ¶
func (t RepoItemRefType) MarshalJSON() ([]byte, error)
func (*RepoItemRefType) UnmarshalJSON ¶
func (t *RepoItemRefType) UnmarshalJSON(data []byte) error
type Request ¶
type Request struct { ThreadID string `json:"copilot_thread_id"` Messages []*Message `json:"messages"` Stop []string `json:"stop"` TopP float32 `json:"top_p"` Temperature float32 `json:"temperature"` MaxTokens int32 `json:"max_tokens"` PresencePenalty float32 `json:"presence_penalty"` FrequencyPenalty float32 `json:"frequency_penalty"` Skills []string `json:"copilot_skills"` Agent string `json:"agent"` }
Request is the request to the agent.
func (*Request) GetSessionInfo ¶ added in v1.0.4
func (req *Request) GetSessionInfo() (*SessionInfo, error)
GetSessionInfo returns the context of the chat session, including the current url, the relevant repository, agent details, and the associated issue or pull request if the current url is a valid issue or pull request url
func (*Request) GetSessionMessage ¶ added in v1.0.4
GetSessionMessage returns the message with the role of "system" and the name of "_session" which is the message that the github.com chat interface sends to communicate the current url and other context of the chat session
type Response ¶
type Response struct { ID string `json:"id,omitempty"` Created int64 `json:"created,omitempty"` Object string `json:"object,omitempty" default:"chat.completion.chunk"` Model string `json:"model,omitempty"` SystemFingerprint string `json:"system_fingerprint,omitempty"` Choices []ChatChoice `json:"choices"` References []*Reference `json:"copilot_references,omitempty"` Confirmation *Confirmation `json:"copilot_confirmation,omitempty"` Errors []*Error `json:"copilot_errors,omitempty"` }
Response is the response from the agent.
type SessionInfo ¶ added in v1.0.4
type SessionInfo struct { URL *ReferenceDataGitHubCurrentUrl `json:"url,omitempty"` Issue *Issue `json:"issue,omitempty"` PullRequest *PullRequest `json:"pull_request,omitempty"` Repo *ReferenceDataGitHubRepository `json:"repo,omitempty"` Agent *ReferenceDataGitHubAgent `json:"agent,omitempty"` }
SessionInfo represents the context of the chat session based on the copilot references in the chat messages
func GetSessionInfo ¶ added in v1.0.4
func GetSessionInfo(ctx context.Context) *SessionInfo
GetSessionInfo returns the SessionInfo object from the context.
type ToolCall ¶
type ToolCall struct { ID string `json:"id"` Type string `json:"type" default:"function"` Function *ToolFunctionCall `json:"function"` }
type ToolFunctionCall ¶ added in v1.0.1
type ToolFunctionDefinition ¶ added in v1.0.1
type ToolFunctionDefinition struct { Name string `json:"name"` Description string `json:"description,omitempty"` Parameters jsonschema.Definition `json:"parameters"` }
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
_examples
|
|
azure_openai
Module
|
|
Package azure provides helpful types and functions for use with Azure OpenAI.
|
Package azure provides helpful types and functions for use with Azure OpenAI. |
github
module
|
|
Package jsonschema provides a simple way to describe JSON Schemas.
|
Package jsonschema provides a simple way to describe JSON Schemas. |
Package sse provides utilities for Server-Sent Events (SSE) in the context of the GitHub Copilot Extensions APIs.
|
Package sse provides utilities for Server-Sent Events (SSE) in the context of the GitHub Copilot Extensions APIs. |