Documentation
¶
Index ¶
- Constants
- func AuthMiddleware(secret string, next http.Handler) http.Handler
- func DefaultCredentialsPath() string
- func GenerateAPIKey() string
- func NewChatHandler(exec Executor) http.Handler
- func NewModelsHandler(lookPath LookPathFunc, ac AnthropicClient) http.Handler
- func ReadClaudeCredentials(path string) string
- type AnthropicClient
- type ChatChoice
- type ChatMessage
- type ChatRequest
- type ChatResponse
- type ChatUsage
- type ExecResult
- type Executor
- type LookPathFunc
- type ModelInfo
- type ModelsResponse
- type RealAnthropicClient
- type Server
- type ShellExecutor
Constants ¶
const (
// AnthropicAPIURL is the default Anthropic models endpoint.
AnthropicAPIURL = "https://api.anthropic.com/v1/models"
)
const DefaultPort = 8484
DefaultPort is the default listen port for devcell serve.
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
AuthMiddleware returns a handler that checks the Authorization: Bearer <secret> header. If secret is empty, all requests are allowed (no auth).
func DefaultCredentialsPath ¶
func DefaultCredentialsPath() string
DefaultCredentialsPath returns the default path to Claude's credentials.
func GenerateAPIKey ¶
func GenerateAPIKey() string
GenerateAPIKey creates a random API key for use when none is configured.
func NewChatHandler ¶
NewChatHandler returns an http.Handler for POST /v1/chat/completions.
func NewModelsHandler ¶
func NewModelsHandler(lookPath LookPathFunc, ac AnthropicClient) http.Handler
NewModelsHandler returns an http.Handler for GET /v1/models.
func ReadClaudeCredentials ¶
ReadClaudeCredentials reads the OAuth access token from Claude's credentials file.
Types ¶
type AnthropicClient ¶
AnthropicClient abstracts Anthropic API calls for testability.
type ChatChoice ¶
type ChatChoice struct {
Index int `json:"index"`
Message ChatMessage `json:"message"`
FinishReason string `json:"finish_reason"`
}
ChatChoice is a single choice in the response.
type ChatMessage ¶
ChatMessage is an OpenAI-compatible message.
type ChatRequest ¶
type ChatRequest struct {
Model string `json:"model"`
Messages []ChatMessage `json:"messages"`
}
ChatRequest is the OpenAI-compatible chat completions request.
type ChatResponse ¶
type ChatResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []ChatChoice `json:"choices"`
Usage ChatUsage `json:"usage"`
}
ChatResponse is the OpenAI-compatible chat completions response.
type ChatUsage ¶
type ChatUsage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
}
ChatUsage tracks token usage (stubbed for now).
type ExecResult ¶
ExecResult holds the output of an agent execution.
type Executor ¶
type Executor interface {
Run(agent, prompt, model string) ExecResult
}
Executor runs an agent command and returns the result.
type LookPathFunc ¶
LookPathFunc matches exec.LookPath signature.
type ModelInfo ¶
type ModelInfo struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
OwnedBy string `json:"owned_by"`
}
ModelInfo represents a single model in the OpenAI /v1/models response.
func DiscoverModels ¶
func DiscoverModels(lookPath LookPathFunc, ac AnthropicClient) []ModelInfo
DiscoverModels probes for installed agent binaries and returns available models. When claude is found, tries the Anthropic API first (via credentials), falls back to hardcoded aliases.
func FetchAnthropicModels ¶
FetchAnthropicModels hits the Anthropic API to get available models. Returns nil, nil if token is empty (no-op).
type ModelsResponse ¶
ModelsResponse is the OpenAI-compatible /v1/models response.
type RealAnthropicClient ¶
type RealAnthropicClient struct {
CredentialsPath string // path to .credentials.json
APIURL string // override for testing; defaults to AnthropicAPIURL
}
RealAnthropicClient reads credentials and hits the Anthropic API.
func (*RealAnthropicClient) FetchModels ¶
func (c *RealAnthropicClient) FetchModels() ([]ModelInfo, error)
FetchModels reads the Claude OAuth token and fetches models from the Anthropic API.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the devcell HTTP API server.
func NewServer ¶
NewServer creates a Server. Use port=0 to let the OS pick a free port. Uses exec.LookPath for model discovery and RealAnthropicClient by default.
func (*Server) SetAnthropicClient ¶
func (s *Server) SetAnthropicClient(ac AnthropicClient)
SetAnthropicClient overrides the Anthropic API client (for testing).
func (*Server) SetLookPath ¶
func (s *Server) SetLookPath(fn LookPathFunc)
SetLookPath overrides the binary discovery function (for testing).
type ShellExecutor ¶
type ShellExecutor struct{}
ShellExecutor runs agent binaries as subprocesses.
func (*ShellExecutor) Run ¶
func (e *ShellExecutor) Run(agent, prompt, model string) ExecResult
Run executes the agent binary with the given prompt and optional model.