- Add handling for Anthropic connector types in the sandbox, allowing direct connections without a proxy. - Enhance capability retrieval to support both OpenAI and Anthropic formats, ensuring a unified interface. - Update the executor and command logic to differentiate between OpenAI and Anthropic configurations, streamlining environment setup. - Modify the provider selection logic to accommodate Anthropic capabilities, improving flexibility in LLM provider management. - Refactor API detection to include Anthropic, ensuring accurate identification of connector types.
54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package sandbox
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/yaoapp/yao/agent/sandbox/claude"
|
|
infraSandbox "github.com/yaoapp/yao/sandbox"
|
|
)
|
|
|
|
// New creates a new Executor based on the command type
|
|
func New(manager *infraSandbox.Manager, opts *Options) (Executor, error) {
|
|
if opts == nil {
|
|
return nil, fmt.Errorf("options is required")
|
|
}
|
|
|
|
if !IsValidCommand(opts.Command) {
|
|
return nil, fmt.Errorf("unsupported command type: %s, supported: %v", opts.Command, CommandTypes)
|
|
}
|
|
|
|
// Set default image if not specified
|
|
if opts.Image == "" {
|
|
opts.Image = DefaultImage(opts.Command)
|
|
}
|
|
|
|
switch opts.Command {
|
|
case "claude":
|
|
// Convert to claude.Options
|
|
claudeOpts := &claude.Options{
|
|
Command: opts.Command,
|
|
Image: opts.Image,
|
|
MaxMemory: opts.MaxMemory,
|
|
MaxCPU: opts.MaxCPU,
|
|
Timeout: opts.Timeout,
|
|
Arguments: opts.Arguments,
|
|
UserID: opts.UserID,
|
|
ChatID: opts.ChatID,
|
|
MCPConfig: opts.MCPConfig,
|
|
MCPTools: opts.MCPTools,
|
|
SkillsDir: opts.SkillsDir,
|
|
SystemPrompt: opts.SystemPrompt, // Required for Claude CLI execution
|
|
ConnectorHost: opts.ConnectorHost,
|
|
ConnectorKey: opts.ConnectorKey,
|
|
Model: opts.Model,
|
|
ConnectorType: opts.ConnectorType, // "openai" or "anthropic"
|
|
ConnectorOptions: opts.ConnectorOptions, // Extra options like thinking, max_tokens
|
|
Secrets: opts.Secrets, // Secrets for container env vars
|
|
}
|
|
return claude.NewExecutor(manager, claudeOpts)
|
|
case "cursor":
|
|
return nil, fmt.Errorf("cursor executor not implemented yet")
|
|
default:
|
|
return nil, fmt.Errorf("unsupported command type: %s", opts.Command)
|
|
}
|
|
}
|