From 87237b6462b9dfd379b22e69712e8dc516afad9d Mon Sep 17 00:00:00 2001 From: mineo Date: Fri, 16 May 2025 03:25:21 +0900 Subject: feat: support VertexAI provider (#153) * support: vertexai fix fix set default for vertexai added comment fix fix * create schema * fix README.md * fix order * added pupularity * set tools if tools is exists restore commentout * fix comment * set summarizer model --- internal/config/config.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'internal/config') diff --git a/internal/config/config.go b/internal/config/config.go index f9aba238d..1d741bc91 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -235,6 +235,7 @@ func setProviderDefaults() { // 5. OpenRouter // 6. AWS Bedrock // 7. Azure + // 8. Google Cloud VertexAI // Anthropic configuration if key := viper.GetString("providers.anthropic.apiKey"); strings.TrimSpace(key) != "" { @@ -299,6 +300,15 @@ func setProviderDefaults() { viper.SetDefault("agents.title.model", models.AzureGPT41Mini) return } + + // Google Cloud VertexAI configuration + if hasVertexAICredentials() { + viper.SetDefault("agents.coder.model", models.VertexAIGemini25) + viper.SetDefault("agents.summarizer.model", models.VertexAIGemini25) + viper.SetDefault("agents.task.model", models.VertexAIGemini25Flash) + viper.SetDefault("agents.title.model", models.VertexAIGemini25Flash) + return + } } // hasAWSCredentials checks if AWS credentials are available in the environment. @@ -327,6 +337,19 @@ func hasAWSCredentials() bool { return false } +// hasVertexAICredentials checks if VertexAI credentials are available in the environment. +func hasVertexAICredentials() bool { + // Check for explicit VertexAI parameters + if os.Getenv("VERTEXAI_PROJECT") != "" && os.Getenv("VERTEXAI_LOCATION") != "" { + return true + } + // Check for Google Cloud project and location + if os.Getenv("GOOGLE_CLOUD_PROJECT") != "" && (os.Getenv("GOOGLE_CLOUD_REGION") != "" || os.Getenv("GOOGLE_CLOUD_LOCATION") != "") { + return true + } + return false +} + // readConfig handles the result of reading a configuration file. func readConfig(err error) error { if err == nil { @@ -549,6 +572,10 @@ func getProviderAPIKey(provider models.ModelProvider) string { if hasAWSCredentials() { return "aws-credentials-available" } + case models.ProviderVertexAI: + if hasVertexAICredentials() { + return "vertex-ai-credentials-available" + } } return "" } @@ -669,6 +696,24 @@ func setDefaultModelForAgent(agent AgentName) bool { return true } + if hasVertexAICredentials() { + var model models.ModelID + maxTokens := int64(5000) + + if agent == AgentTitle { + model = models.VertexAIGemini25Flash + maxTokens = 80 + } else { + model = models.VertexAIGemini25 + } + + cfg.Agents[agent] = Agent{ + Model: model, + MaxTokens: maxTokens, + } + return true + } + return false } -- cgit v1.2.3 From 4a444e9c9b7674c6b07a1a012a6467e45c3af1ec Mon Sep 17 00:00:00 2001 From: Ed Zynda Date: Fri, 16 May 2025 14:27:28 +0300 Subject: feat: Make shell configurable via config file (#23) --- README.md | 33 +++++++++++++++++++++++++++++++++ internal/config/config.go | 7 +++++++ internal/llm/tools/shell/shell.go | 24 ++++++++++++++++++++---- 3 files changed, 60 insertions(+), 4 deletions(-) (limited to 'internal/config') diff --git a/README.md b/README.md index 57da47289..10be21d5c 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,10 @@ You can configure OpenCode using environment variables: "command": "gopls" } }, + "shell": { + "path": "/bin/zsh", + "args": ["-l"] + }, "debug": false, "debugLSP": false } @@ -411,6 +415,35 @@ You can define any of the following color keys in your `customTheme`: You don't need to define all colors. Any undefined colors will fall back to the default "opencode" theme colors. +### Shell Configuration + +OpenCode allows you to configure the shell used by the `bash` tool. By default, it uses: +1. The shell specified in the config file (if provided) +2. The shell from the `$SHELL` environment variable (if available) +3. Falls back to `/bin/bash` if neither of the above is available + +To configure a custom shell, add a `shell` section to your `.opencode.json` configuration file: + +```json +{ + "shell": { + "path": "/bin/zsh", + "args": ["-l"] + } +} +``` + +You can specify any shell executable and custom arguments: + +```json +{ + "shell": { + "path": "/usr/bin/fish", + "args": [] + } +} +``` + ## Architecture OpenCode is built with a modular architecture: diff --git a/internal/config/config.go b/internal/config/config.go index 1d741bc91..70c05ac02 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -73,6 +73,12 @@ type TUIConfig struct { CustomTheme map[string]any `json:"customTheme,omitempty"` } +// ShellConfig defines the configuration for the shell used by the bash tool. +type ShellConfig struct { + Path string `json:"path,omitempty"` + Args []string `json:"args,omitempty"` +} + // Config is the main configuration structure for the application. type Config struct { Data Data `json:"data"` @@ -85,6 +91,7 @@ type Config struct { DebugLSP bool `json:"debugLSP,omitempty"` ContextPaths []string `json:"contextPaths,omitempty"` TUI TUIConfig `json:"tui"` + Shell ShellConfig `json:"shell,omitempty"` } // Application constants diff --git a/internal/llm/tools/shell/shell.go b/internal/llm/tools/shell/shell.go index efbd5ddb6..a59ee4207 100644 --- a/internal/llm/tools/shell/shell.go +++ b/internal/llm/tools/shell/shell.go @@ -12,6 +12,7 @@ import ( "syscall" "time" + "github.com/sst/opencode/internal/config" "github.com/sst/opencode/internal/status" ) @@ -59,12 +60,27 @@ func GetPersistentShell(workingDir string) *PersistentShell { } func newPersistentShell(cwd string) *PersistentShell { - shellPath := os.Getenv("SHELL") - if shellPath == "" { - shellPath = "/bin/bash" + cfg := config.Get() + + // Use shell from config if specified + shellPath := "" + shellArgs := []string{"-l"} + + if cfg != nil && cfg.Shell.Path != "" { + shellPath = cfg.Shell.Path + if len(cfg.Shell.Args) > 0 { + shellArgs = cfg.Shell.Args + } + } else { + // Fall back to environment variable + shellPath = os.Getenv("SHELL") + if shellPath == "" { + // Default to bash if neither config nor environment variable is set + shellPath = "/bin/bash" + } } - cmd := exec.Command(shellPath, "-l") + cmd := exec.Command(shellPath, shellArgs...) cmd.Dir = cwd stdinPipe, err := cmd.StdinPipe() -- cgit v1.2.3