Skip to content

Conversation

L1l1thLY
Copy link
Contributor

Because I am on an internal network, I need to use a proxy server to access Claude's services. However, Wave currently does not provide the ability to configure the base URL, so I have added this feature in hopes of being able to use it.

@CLAassistant
Copy link

CLAassistant commented Aug 13, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

coderabbitai bot commented Aug 13, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Replaces a hard-coded Anthropik/Anthropic messages endpoint with a computed endpoint taken from request.Opts.BaseURL when provided (defaults to https://api.anthropic.com/v1/messages after trimming). The anthropic-version header is now set from request.Opts.APIVersion if non-empty (default remains 2023-06-01). In the Google backend, a stray trailing whitespace line after appending the API key was removed and cancellation handling in the streaming loop was changed from a non-blocking select to a direct ctx.Err() check that sends an AI error and breaks the loop. No public signatures were changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 13d0ce8 and 51aa0a8.

📒 Files selected for processing (2)
  • pkg/waveai/anthropicbackend.go (2 hunks)
  • pkg/waveai/googlebackend.go (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/waveai/anthropicbackend.go (1)

191-191: Avoid extra allocation when building the request body

Using strings.NewReader(string(reqBody)) causes an unnecessary []byte→string allocation. Use bytes.NewReader(reqBody) instead.

Apply this diff:

-        req, err := http.NewRequestWithContext(ctx, "POST", endpoint, strings.NewReader(string(reqBody)))
+        req, err := http.NewRequestWithContext(ctx, "POST", endpoint, bytes.NewReader(reqBody))

Additional change outside the selected range: ensure "bytes" is imported.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d339af and 00b0718.

📒 Files selected for processing (1)
  • pkg/waveai/anthropicbackend.go (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
pkg/waveai/anthropicbackend.go (1)
pkg/wcloud/wcloud.go (1)
  • APIVersion (34-34)
🔇 Additional comments (1)
pkg/waveai/anthropicbackend.go (1)

200-205: LGTM: configurable anthropic-version with sensible default

This correctly defaults to "2023-06-01" and allows overrides via request.Opts.APIVersion while keeping the header explicit.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
pkg/waveai/anthropicbackend.go (1)

228-229: Avoid extra allocations: use bytes.NewReader for JSON body

Converting []byte to string and back to an io.Reader causes an unnecessary allocation. Prefer bytes.NewReader.

Apply this diff:

-        req, err := http.NewRequestWithContext(ctx, "POST", endpoint, strings.NewReader(string(reqBody)))
+        req, err := http.NewRequestWithContext(ctx, "POST", endpoint, bytes.NewReader(reqBody))

Additional change required outside this range:

 import (
+    "bytes"
     "bufio"
     "context"
🧹 Nitpick comments (1)
pkg/waveai/anthropicbackend.go (1)

34-43: Optionally support scheme-less inputs by defaulting to https

Some users paste hosts without a scheme (e.g., proxy.internal:8443). You can reduce friction by defaulting such inputs to https before enforcing the scheme check.

Apply this diff:

     parsedURL, err := url.Parse(baseURL)
     if err != nil {
         return "", fmt.Errorf("failed to parse base URL: %v", err)
     }
 
-    // Validate scheme
+    // Allow scheme-less inputs like "proxy.internal:8443" by defaulting to https
+    if parsedURL.Scheme == "" && parsedURL.Host == "" {
+        if attempt, perr := url.Parse("https://" + baseURL); perr == nil {
+            parsedURL = attempt
+        }
+    }
+
+    // Validate scheme
     if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" {
         return "", errors.New("base URL must use http or https scheme")
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00b0718 and 936ee19.

📒 Files selected for processing (1)
  • pkg/waveai/anthropicbackend.go (4 hunks)
🔇 Additional comments (2)
pkg/waveai/anthropicbackend.go (2)

217-227: Endpoint override flow looks good

Clean fallback to the default messages endpoint and clear error propagation when the custom base URL is invalid. Nice separation via buildAnthropicEndpoint.


237-241: Configurable anthropic-version header is correctly implemented

Sane default retained and override supported via request.Opts.APIVersion. Header key is correct.

Comment on lines 26 to 68
// buildAnthropicEndpoint safely constructs the Anthropic API endpoint from a base URL
// It validates the scheme, preserves query parameters and host, and handles common path patterns
func buildAnthropicEndpoint(baseURL string) (string, error) {
if baseURL == "" {
return "", errors.New("base URL cannot be empty")
}

// Parse the base URL
parsedURL, err := url.Parse(baseURL)
if err != nil {
return "", fmt.Errorf("failed to parse base URL: %v", err)
}

// Validate scheme
if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" {
return "", errors.New("base URL must use http or https scheme")
}

// Handle different path patterns:
// - https://custom -> https://custom/v1/messages
// - https://custom/ -> https://custom/v1/messages
// - https://custom/v1 -> https://custom/v1/messages
// - https://custom/v1/ -> https://custom/v1/messages
// - https://custom/v1/messages -> https://custom/v1/messages
// - https://custom/v1/messages/ -> https://custom/v1/messages

currentPath := strings.TrimRight(parsedURL.Path, "/")

var targetPath string
if strings.HasSuffix(currentPath, "/messages") {
targetPath = currentPath
} else if strings.HasSuffix(currentPath, "/v1") {
targetPath = currentPath + "/messages"
} else {
// Empty path or any other path gets /v1/messages appended
targetPath = path.Join(currentPath, "/v1/messages")
}

// Construct the final URL preserving query parameters
parsedURL.Path = targetPath
return parsedURL.String(), nil
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add unit tests for buildAnthropicEndpoint to lock in behavior

Given the URL-joining edge cases, unit tests will prevent regressions and document expected inputs/outputs (including path preservation, trailing slashes, and queries).

Suggested test cases:

If you’d like, I can draft pkg/waveai/anthropicbackend_test.go covering these cases.

@sawka
Copy link
Member

sawka commented Aug 19, 2025

thanks for submitting this! looks pretty straightforward, will take a look and try to get this merged.

@sawka sawka merged commit 981a088 into wavetermdev:main Aug 19, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants