provider

package
v0.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApprovalActionApprove = "approve"
	ApprovalActionDeny    = "deny"
	ApprovalActionAlways  = "always"
)

Variables

View Source
var BuiltinCLITools = []CLIToolSpec{
	{
		Name:         "claude",
		DisplayName:  "Claude Code",
		Binary:       "claude",
		InstallCmd:   "npm install -g @anthropic-ai/claude-code",
		DetectCmd:    "claude --version",
		VersionRegex: `Claude CLI[,:]? v?(\d+\.\d+\.\d+)`,
		Default:      true,
	},
	{
		Name:         "codex",
		DisplayName:  "Codex CLI",
		Binary:       "codex",
		InstallCmd:   "npm install -g @openai/codex",
		DetectCmd:    "codex --version",
		VersionRegex: `(\d+\.\d+\.\d+)`,
		Default:      false,
	},
	{
		Name:         "opencode",
		DisplayName:  "OpenCode",
		Binary:       "opencode",
		InstallCmd:   "npm install -g opencode-ai",
		DetectCmd:    "opencode --version",
		VersionRegex: `(\d+\.\d+\.\d+)`,
		Default:      false,
	},
}

BuiltinCLITools lists the external AI coding CLIs Leros can detect.

Functions

func BuildBaseEnv

func BuildBaseEnv(extraEnv map[string]string) []string

BuildBaseEnv 返回当前环境并附加额外的环境变量。

func BuildRunEnv

func BuildRunEnv(baseEnv []string, extraEnv []string, modelEnv map[string]string) []string

BuildRunEnv 为 CLI 进程组装环境变量条目。

func LerosMCPTokenEnvVar

func LerosMCPTokenEnvVar() string

LerosMCPTokenEnvVar returns the env var name used for CLI MCP bearer token registration.

func PreferredCLIName

func PreferredCLIName(available []CLIToolStatus) string

PreferredCLIName chooses the preferred installed runtime from detected CLI status.

func ResolveRunWorkDir

func ResolveRunWorkDir(workDir string) (string, error)

ResolveRunWorkDir returns the configured run workdir or the workspace temp fallback.

func RunCLICommand

func RunCLICommand(ctx context.Context, cliPath string, args []string, extraEnv []string) error

RunCLICommand runs a CLI command with a bounded timeout.

func ScanJSONLines

func ScanJSONLines(r io.Reader, visit func(line string) bool)

ScanJSONLines 扫描换行符分隔的 JSON 日志,支持更大的 token 缓冲区。

func SkillDirForCLI

func SkillDirForCLI(name string) string

SkillDirForCLI returns the conventional skill directory for a supported CLI.

Types

type ApprovalHandler

type ApprovalHandler interface {
	RequestApproval(ctx context.Context, req *agent.ApprovalRequest) (*agent.ApprovalDecision, error)
}

ApprovalHandler handles an approval request raised by a provider.

type ApprovalResponder

type ApprovalResponder interface {
	WriteDecision(requestID string, action string) error
}

ApprovalResponder writes an approval decision back to a provider process.

type CLIToolSpec

type CLIToolSpec struct {
	Name         string
	DisplayName  string
	Binary       string
	InstallCmd   string
	DetectCmd    string
	VersionRegex string
	Default      bool
}

CLIToolSpec describes a built-in external AI coding CLI.

func GetCLIToolSpec

func GetCLIToolSpec(name string) *CLIToolSpec

GetCLIToolSpec returns the built-in CLI spec with the given runtime name.

type CLIToolStatus

type CLIToolStatus struct {
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
	Binary      string `json:"binary"`
	Installed   bool   `json:"installed"`
	Version     string `json:"version,omitempty"`
	Path        string `json:"path,omitempty"`
	InstallCmd  string `json:"install_cmd"`
	Default     bool   `json:"is_default"`
}

CLIToolStatus reports whether a built-in CLI is available in the current environment.

func DiscoverAvailableCLI

func DiscoverAvailableCLI() []CLIToolStatus

DiscoverAvailableCLI detects all built-in CLI tools from the current PATH.

func GetCLIStatusSummary

func GetCLIStatusSummary() []CLIToolStatus

GetCLIStatusSummary returns the current detection status for all built-in CLI runtimes.

type CmdProcess

type CmdProcess struct {
	// contains filtered or unexported fields
}

CmdProcess 实现 os/exec.Cmd 的 Process 接口。

func NewCmdProcess

func NewCmdProcess(cmd *exec.Cmd, done <-chan struct{}) *CmdProcess

NewCmdProcess 将 cmd 和调用方拥有的 Wait 完成信号包装为 Process。 调用方必须保持 cmd.Wait() 的唯一所有权,并在 Wait 返回后关闭 done。

func (*CmdProcess) PID

func (p *CmdProcess) PID() int

PID 返回命令启动后的进程 ID。

func (*CmdProcess) Stop

func (p *CmdProcess) Stop() error

Stop 优雅地终止子进程,不调用 cmd.Wait 或 cmd.Process.Wait。

关闭流程:

  1. 发送 SIGTERM 请求子进程自行清理
  2. 等待 gracefulShutdownTimeout
  3. 超时则强制 SIGKILL

Stop 是幂等的,多次调用安全。

type InteractionRouter

type InteractionRouter struct {
	// contains filtered or unexported fields
}

InteractionRouter 统一管理审批(approval)和问题(question)类型的待处理交互请求。 通过 channel 桥接前端的 HTTP 回传和引擎的阻塞 goroutine。

func NewInteractionRouter

func NewInteractionRouter() *InteractionRouter

NewInteractionRouter 创建交互路由器。

func (*InteractionRouter) GetApprovalResponder

func (r *InteractionRouter) GetApprovalResponder(requestID string) ApprovalResponder

GetApprovalResponder 获取审批请求对应的 Responder。

func (*InteractionRouter) GetQuestionResponder

func (r *InteractionRouter) GetQuestionResponder(requestID string) QuestionResponder

GetQuestionResponder 获取问题请求对应的 Responder。

func (*InteractionRouter) RequestAnswer

RequestAnswer 注册 pending question 并阻塞等待前端 HTTP 回传答案。 实现 QuestionHandler 接口。

func (*InteractionRouter) RequestApproval

RequestApproval 注册 pending approval 并阻塞等待前端 HTTP 回传决策。 实现 ApprovalHandler 接口。

func (*InteractionRouter) ResolveApproval

func (r *InteractionRouter) ResolveApproval(requestID, action, reason string) error

ResolveApproval 由 HTTP handler / worker subscriber 调用,填入前端决策并唤醒阻塞的 goroutine。

func (*InteractionRouter) ResolveQuestion

func (r *InteractionRouter) ResolveQuestion(requestID string, answers [][]string) error

ResolveQuestion 由 HTTP handler / worker subscriber 调用,填入用户答案并唤醒阻塞的 goroutine。

func (*InteractionRouter) SetApprovalResponder

func (r *InteractionRouter) SetApprovalResponder(requestID string, responder ApprovalResponder)

SetApprovalResponder 设置审批请求对应的 Responder。

func (*InteractionRouter) SetQuestionResponder

func (r *InteractionRouter) SetQuestionResponder(requestID string, responder QuestionResponder)

SetQuestionResponder 设置问题请求对应的 Responder。

type MCPServerConfig

type MCPServerConfig struct {
	Name        string
	URL         string            // HTTP 传输
	BearerToken string            // HTTP 传输:bearer token
	Command     string            // Stdio 传输:可执行文件路径
	Args        []string          // Stdio 传输:命令参数
	Env         map[string]string // Stdio 传输:进程额外环境变量
}

MCPServerConfig describes the Leros MCP endpoint registered with an external CLI client.

func NormalizeMCPServerConfig

func NormalizeMCPServerConfig(cfg MCPServerConfig) MCPServerConfig

NormalizeMCPServerConfig fills defaults for an MCP server registration.

type PendingApproval

type PendingApproval struct {
	Request   *agent.ApprovalRequest
	Responder ApprovalResponder
	ResultCh  chan *agent.ApprovalDecision
	CreatedAt time.Time
}

PendingApproval represents an approval request waiting for a user decision.

type PendingQuestion

type PendingQuestion struct {
	Request   *agent.QuestionRequest
	Responder QuestionResponder
	ResultCh  chan *agent.QuestionAnswer
	CreatedAt time.Time
}

PendingQuestion 表示一个等待前端回答的问题请求。

type PermissionMode

type PermissionMode string

PermissionMode controls whether a provider requests approval for tool calls.

const (
	// PermissionModeBypass skips provider approval requests.
	PermissionModeBypass PermissionMode = "bypass"
	// PermissionModeOnRequest forwards provider approval requests to the user.
	PermissionModeOnRequest PermissionMode = "on-request"
	// PermissionModeAuto automatically approves safe operations.
	PermissionModeAuto PermissionMode = "auto"
)

type Process

type Process interface {
	PID() int
	Stop() error
}

Process is the minimal lifecycle handle exposed by a provider invocation.

type QuestionHandler

type QuestionHandler interface {
	RequestAnswer(ctx context.Context, req *agent.QuestionRequest) (*agent.QuestionAnswer, error)
}

QuestionHandler handles a question raised by a provider.

type QuestionResponder

type QuestionResponder interface {
	WriteAnswer(requestID string, answers [][]string) error
}

QuestionResponder writes answers back to a provider process.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL