sdk

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sdk provides a wrapper around the GitHub Copilot SDK.

This package abstracts Copilot SDK integration, providing session management, event handling, custom tool registration, and error handling. It provides a simplified interface for Ralph's needs while handling the complexity of the underlying SDK.

See specs/sdk-integration.md for detailed specification.

Package sdk provides event types for Copilot SDK communication.

Package sdk provides assistant message types for Copilot SDK communication.

Package sdk provides tool types for Copilot SDK integration.

Index

Constants

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

func WithModel(model string) ClientOption

WithModel sets the AI model to use.

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

func (c *CopilotClient) SendPrompt(ctx context.Context, prompt string) (<-chan Event, error)

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) Error

func (e *ErrorEvent) Error() string

Error returns the error message.

func (*ErrorEvent) Timestamp

func (e *ErrorEvent) Timestamp() time.Time

Timestamp returns when the event occurred.

func (*ErrorEvent) Type

func (e *ErrorEvent) Type() EventType

Type returns EventTypeError.

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"
)

type Message

type Message struct {
	Timestamp time.Time
	Content   string
	ToolCalls []ToolCall
}

Message represents a message that can accompany response-complete events. It is intentionally minimal and no longer tracked in a local session object.

type TextEvent

type TextEvent struct {
	Text      string
	Reasoning bool
	// contains filtered or unexported fields
}

TextEvent represents a text/streaming content event.

func NewTextEvent

func NewTextEvent(text string, reasoning bool) *TextEvent

NewTextEvent creates a new TextEvent with the given text.

func (*TextEvent) Timestamp

func (e *TextEvent) Timestamp() time.Time

Timestamp returns when the event occurred.

func (*TextEvent) Type

func (e *TextEvent) Type() EventType

Type returns EventTypeText.

type ToolCall

type ToolCall struct {
	Parameters map[string]any
	ID         string
	Name       string
}

ToolCall represents a tool invocation request from the assistant.

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.

Jump to

Keyboard shortcuts

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