Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions internal/ai/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"

"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
"github.com/steveyegge/vc/internal/storage"
"github.com/steveyegge/vc/internal/types"
"golang.org/x/sync/semaphore"
Expand Down Expand Up @@ -122,7 +121,7 @@ func NewSupervisor(cfg *Config) (*Supervisor, error) {
retry = DefaultRetryConfig()
}

client := anthropic.NewClient(option.WithAPIKey(apiKey))
client := NewAnthropicClient(apiKey)

// Initialize circuit breaker if enabled
var circuitBreaker *CircuitBreaker
Expand Down
18 changes: 18 additions & 0 deletions internal/ai/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"unicode/utf8"

"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
"github.com/steveyegge/vc/internal/types"
)

Expand Down Expand Up @@ -329,3 +330,20 @@ func safeTruncateString(s string, maxLen int) string {
// Return empty string rather than corrupted data
return ""
}

// NewAnthropicClient creates an Anthropic client with support for ANTHROPIC_BASE_URL
// It uses the ANTHROPIC_API_KEY environment variable for authentication
// and optionally ANTHROPIC_BASE_URL environment variable for custom endpoint
func NewAnthropicClient(apiKey string) anthropic.Client {
// Prepare client options
opts := []option.RequestOption{
option.WithAPIKey(apiKey),
}

// Add base URL if provided
if baseURL := os.Getenv("ANTHROPIC_BASE_URL"); baseURL != "" {
opts = append(opts, option.WithBaseURL(baseURL))
}

return anthropic.NewClient(opts...)
}
4 changes: 2 additions & 2 deletions internal/discovery/sdk/ai.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"

"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
"github.com/steveyegge/vc/internal/ai"
)

// AIRequest represents a request to the AI supervisor.
Expand Down Expand Up @@ -79,7 +79,7 @@ func CallAI(ctx context.Context, req AIRequest) (*AIResponse, error) {
}

// Create client
client := anthropic.NewClient(option.WithAPIKey(apiKey))
client := ai.NewAnthropicClient(apiKey)

// Build messages
messages := []anthropic.MessageParam{
Expand Down
4 changes: 2 additions & 2 deletions internal/executor/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"time"

"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
"github.com/google/uuid"
"github.com/steveyegge/vc/internal/ai"
"github.com/steveyegge/vc/internal/events"
"github.com/steveyegge/vc/internal/sandbox"
"github.com/steveyegge/vc/internal/storage"
Expand Down Expand Up @@ -1180,7 +1180,7 @@ Only say stuck=true if you're confident (>0.8) this is a loop.`, summary)
checkCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

client := anthropic.NewClient(option.WithAPIKey(apiKey))
client := ai.NewAnthropicClient(apiKey)

resp, err := client.Messages.New(checkCtx, anthropic.MessageNewParams{
Model: anthropic.Model("claude-3-5-haiku-20241022"), // Haiku for speed/cost
Expand Down
4 changes: 1 addition & 3 deletions internal/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"sync"
"time"

"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
"github.com/google/uuid"
"github.com/steveyegge/vc/internal/ai"
"github.com/steveyegge/vc/internal/config"
Expand Down Expand Up @@ -658,7 +656,7 @@ func New(cfg *Config) (*Executor, error) {
apiKey := os.Getenv("ANTHROPIC_API_KEY")
if apiKey != "" {
// Create Anthropic client for message generation (vc-35: using Haiku for cost efficiency)
client := anthropic.NewClient(option.WithAPIKey(apiKey))
client := ai.NewAnthropicClient(apiKey)
e.messageGen = git.NewMessageGenerator(&client, ai.GetSimpleTaskModel())
} else {
fmt.Fprintf(os.Stderr, "Warning: ANTHROPIC_API_KEY not set (auto-commit message generation disabled)\n")
Expand Down
7 changes: 3 additions & 4 deletions internal/health/model_cost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
"github.com/steveyegge/vc/internal/ai"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -79,7 +78,7 @@ func TestModelCost_CruftDetector(t *testing.T) {
for _, model := range []string{ai.ModelSonnet, ai.ModelHaiku} {
t.Run(model, func(t *testing.T) {
// Create cost-tracking supervisor
client := anthropic.NewClient(option.WithAPIKey(apiKey))
client := ai.NewAnthropicClient(apiKey)
supervisor := &costTrackingSupervisor{
client: &client,
model: model,
Expand Down Expand Up @@ -153,7 +152,7 @@ func TestModelCost_FileSizeMonitor(t *testing.T) {

for _, model := range []string{ai.ModelSonnet, ai.ModelHaiku} {
t.Run(model, func(t *testing.T) {
client := anthropic.NewClient(option.WithAPIKey(apiKey))
client := ai.NewAnthropicClient(apiKey)
supervisor := &costTrackingSupervisor{
client: &client,
model: model,
Expand Down Expand Up @@ -262,7 +261,7 @@ func TestModelCost_GitignoreDetector(t *testing.T) {

for _, model := range []string{ai.ModelSonnet, ai.ModelHaiku} {
t.Run(model, func(t *testing.T) {
client := anthropic.NewClient(option.WithAPIKey(apiKey))
client := ai.NewAnthropicClient(apiKey)
supervisor := &costTrackingSupervisor{
client: &client,
model: model,
Expand Down
7 changes: 3 additions & 4 deletions internal/health/model_quality_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
"github.com/steveyegge/vc/internal/ai"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -56,7 +55,7 @@ func TestModelQuality_CruftDetector(t *testing.T) {
for _, model := range []string{ai.ModelSonnet, ai.ModelHaiku} {
t.Run(model, func(t *testing.T) {
// Create supervisor with specific model
client := anthropic.NewClient(option.WithAPIKey(apiKey))
client := ai.NewAnthropicClient(apiKey)
supervisor := &realAISupervisor{
client: &client,
model: model,
Expand Down Expand Up @@ -165,7 +164,7 @@ func TestModelQuality_FileSizeMonitor(t *testing.T) {

for _, model := range []string{ai.ModelSonnet, ai.ModelHaiku} {
t.Run(model, func(t *testing.T) {
client := anthropic.NewClient(option.WithAPIKey(apiKey))
client := ai.NewAnthropicClient(apiKey)
supervisor := &realAISupervisor{
client: &client,
model: model,
Expand Down Expand Up @@ -298,7 +297,7 @@ func TestModelQuality_GitignoreDetector(t *testing.T) {

for _, model := range []string{ai.ModelSonnet, ai.ModelHaiku} {
t.Run(model, func(t *testing.T) {
client := anthropic.NewClient(option.WithAPIKey(apiKey))
client := ai.NewAnthropicClient(apiKey)
supervisor := &realAISupervisor{
client: &client,
model: model,
Expand Down
4 changes: 2 additions & 2 deletions internal/repl/conversation_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"

"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
"github.com/steveyegge/vc/internal/ai"
"github.com/steveyegge/vc/internal/storage"
)

Expand Down Expand Up @@ -37,7 +37,7 @@ func NewConversationHandler(store storage.Storage, actor string) (*ConversationH
actor = "user"
}

client := anthropic.NewClient(option.WithAPIKey(apiKey))
client := ai.NewAnthropicClient(apiKey)

return &ConversationHandler{
client: &client,
Expand Down