Documentation
¶
Overview ¶
Package sdk provides a wrapper around the GitHub Copilot SDK.
This package abstracts Copilot SDK integration, providing session management, event handling, and error handling. It provides a simplified interface for Ralph's needs while handling the complexity of the underlying SDK.
See .github/copilot-instructions.md for the architectural overview and developer guide.
Package sdk provides event types for Copilot SDK communication.
Package sdk provides rate-limit detection and parsing helpers.
Index ¶
- Constants
- type ClientOption
- type CopilotClient
- func (c *CopilotClient) CreateSession(ctx context.Context) error
- func (c *CopilotClient) DestroySession(ctx context.Context) error
- func (c *CopilotClient) Model() string
- func (c *CopilotClient) SendPrompt(ctx context.Context, prompt string) (<-chan Event, error)
- func (c *CopilotClient) Start() error
- func (c *CopilotClient) Stop() error
- type ErrorEvent
- type Event
- type EventType
- type RateLimitEvent
- type TextEvent
- type ToolCall
- type ToolCallEvent
- type ToolResultEvent
Constants ¶
const ( DefaultModel = "gpt-4" DefaultLogLevel = "info" DefaultTimeout = 60 * time.Second DefaultStreaming = true )
Default configuration values.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientOption ¶
type ClientOption func(*clientConfig)
ClientOption configures the CopilotClient.
func WithLogLevel ¶
func WithLogLevel(level string) ClientOption
WithLogLevel sets the logging level (debug, info, warn, error).
func WithStreaming ¶
func WithStreaming(streaming bool) ClientOption
WithStreaming enables or disables streaming responses.
func WithSystemMessage ¶
func WithSystemMessage(message, mode string) ClientOption
WithSystemMessage sets the system message for the session. Mode can be "append" or "replace".
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout sets the request timeout.
func WithWorkingDir ¶
func WithWorkingDir(dir string) ClientOption
WithWorkingDir sets the working directory for file operations.
type CopilotClient ¶
type CopilotClient struct {
// contains filtered or unexported fields
}
CopilotClient wraps the GitHub Copilot SDK. It provides session management, event handling, and tool registration.
func NewCopilotClient ¶
func NewCopilotClient(opts ...ClientOption) (*CopilotClient, error)
NewCopilotClient creates a new Copilot SDK client with the given options. It returns an error if the configuration is invalid.
func (*CopilotClient) CreateSession ¶
func (c *CopilotClient) CreateSession(ctx context.Context) error
CreateSession creates a new Copilot session. It initializes the SDK session resources and registers them with the client.
func (*CopilotClient) DestroySession ¶
func (c *CopilotClient) DestroySession(ctx context.Context) error
DestroySession destroys the current session and cleans up resources.
func (*CopilotClient) Model ¶
func (c *CopilotClient) Model() string
Model returns the configured model name.
func (*CopilotClient) SendPrompt ¶
SendPrompt sends a prompt to the Copilot SDK and returns an event stream. The returned channel will be closed when the response is complete. An error is returned if there is no active session. This method includes automatic retry logic for transient errors.
func (*CopilotClient) Start ¶
func (c *CopilotClient) Start() error
Start initializes the underlying Copilot SDK client. It is idempotent and safe to call repeatedly; subsequent calls return nil without re-initializing.
func (*CopilotClient) Stop ¶
func (c *CopilotClient) Stop() error
Stop stops the client and releases resources.
type ErrorEvent ¶
type ErrorEvent struct {
// Err contains the error that occurred.
Err error
// contains filtered or unexported fields
}
ErrorEvent represents an error that occurred during processing.
func NewErrorEvent ¶
func NewErrorEvent(err error) *ErrorEvent
NewErrorEvent creates a new ErrorEvent with the given error.
func (*ErrorEvent) Timestamp ¶
func (e *ErrorEvent) Timestamp() time.Time
Timestamp returns when the event occurred.
type Event ¶
type Event interface {
// Type returns the event type.
Type() EventType
// Timestamp returns when the event occurred.
Timestamp() time.Time
}
Event represents an event from the Copilot SDK. All event types implement this interface.
type EventType ¶
type EventType string
EventType represents the type of event from the Copilot SDK.
const ( // EventTypeText indicates a text/streaming content event. EventTypeText EventType = "text" // EventTypeToolCall indicates a tool invocation request event. EventTypeToolCall EventType = "tool_call" // EventTypeToolResult indicates a tool execution result event. EventTypeToolResult EventType = "tool_result" // EventTypeResponseComplete indicates the response is complete. EventTypeResponseComplete EventType = "response_complete" // EventTypeError indicates an error occurred. EventTypeError EventType = "error" // EventTypeRateLimit indicates the session hit a rate or quota limit // and the client is waiting before retrying. EventTypeRateLimit EventType = "rate_limit" )
type RateLimitEvent ¶ added in v0.2.0
type RateLimitEvent struct {
// ResetAt is when the rate limit is expected to reset. If HasReset is
// false, callers should fall back to Wait.
ResetAt time.Time
// Wait is the duration the SDK will sleep before retrying.
Wait time.Duration
// Message is the original message reported by the SDK or upstream.
Message string
// ErrorType is the SDK-reported category (e.g. "rate_limit", "quota").
// Empty when detected from a free-form error string.
ErrorType string
// HasReset indicates whether ResetAt is meaningful.
HasReset bool
// contains filtered or unexported fields
}
RateLimitEvent indicates the session hit a Copilot rate limit or quota boundary. The SDK client emits it before sleeping until ResetAt and retrying the prompt.
func NewRateLimitEvent ¶ added in v0.2.0
func NewRateLimitEvent(message, errorType string, resetAt time.Time, hasReset bool, wait time.Duration) *RateLimitEvent
NewRateLimitEvent creates a RateLimitEvent.
func (*RateLimitEvent) Timestamp ¶ added in v0.2.0
func (e *RateLimitEvent) Timestamp() time.Time
Timestamp returns when the event occurred.
func (*RateLimitEvent) Type ¶ added in v0.2.0
func (e *RateLimitEvent) Type() EventType
Type returns EventTypeRateLimit.
type TextEvent ¶
TextEvent represents a text/streaming content event.
func NewTextEvent ¶
NewTextEvent creates a new TextEvent with the given text.
type ToolCallEvent ¶
type ToolCallEvent struct {
// ToolCall contains the tool call details.
ToolCall ToolCall
// contains filtered or unexported fields
}
ToolCallEvent represents a tool invocation request from the assistant.
func NewToolCallEvent ¶
func NewToolCallEvent(toolCall ToolCall) *ToolCallEvent
NewToolCallEvent creates a new ToolCallEvent with the given tool call.
func (*ToolCallEvent) Timestamp ¶
func (e *ToolCallEvent) Timestamp() time.Time
Timestamp returns when the event occurred.
func (*ToolCallEvent) Type ¶
func (e *ToolCallEvent) Type() EventType
Type returns EventTypeToolCall.
type ToolResultEvent ¶
type ToolResultEvent struct {
ToolCall ToolCall
Error error
Result string
// contains filtered or unexported fields
}
ToolResultEvent represents the result of a tool execution.
func NewToolResultEvent ¶
func NewToolResultEvent(toolCall ToolCall, result string, err error) *ToolResultEvent
NewToolResultEvent creates a new ToolResultEvent with the given result.
func (*ToolResultEvent) Timestamp ¶
func (e *ToolResultEvent) Timestamp() time.Time
Timestamp returns when the event occurred.
func (*ToolResultEvent) Type ¶
func (e *ToolResultEvent) Type() EventType
Type returns EventTypeToolResult.