opencode

package
v0.1.20 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: 31 Imported by: 0

Documentation

Overview

Package opencode 将 OpenCode CLI 适配到 Leros 外部 CLI 引擎接口。 使用 opencode serve 模式,通过 HTTP REST API + SSE 进行通信。

Package opencode provides the OpenCode Runtime type.

Package opencode 将 OpenCode CLI 适配到 Leros 外部 CLI 引擎接口。 使用 opencode serve 模式,通过 HTTP REST API + SSE 进行通信。

Index

Constants

View Source
const (
	// Kind is the canonical runtime kind for OpenCode.
	Kind = "opencode"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter 通过 OpenCode CLI serve 模式执行提示。

func NewAdapter

func NewAdapter(binary string, extraEnv map[string]string) *Adapter

NewAdapter 创建 OpenCode CLI 引擎适配器(serve 模式)。

func (*Adapter) GetSkillDir

func (a *Adapter) GetSkillDir() string

GetSkillDir 返回 OpenCode CLI 的技能目录路径。

func (*Adapter) Invoke

Invoke starts OpenCode serve and returns its process activity stream.

func (*Adapter) Prepare

func (a *Adapter) Prepare(_ context.Context, _ string) error

Prepare performs provider-specific workspace setup.

type OpenCodeServer

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

OpenCodeServer 管理 opcode serve 子进程并通过 HTTP 与之通信。

func (*OpenCodeServer) Abort

func (s *OpenCodeServer) Abort(ctx context.Context, sessionID string) error

Abort 中断正在运行的会话。

func (*OpenCodeServer) ConnectSSE

func (s *OpenCodeServer) ConnectSSE(ctx context.Context, workDir string) (<-chan sseEvent, error)

ConnectSSE 连接到 /event SSE 端点,返回解析后的事件通道。 事件按 directory 过滤以确保只接收当前工作区的事件。

func (*OpenCodeServer) CreateSession

func (s *OpenCodeServer) CreateSession(ctx context.Context, title, providerID, modelID, systemPrompt string) (*sessionResponse, error)

CreateSession 创建新的 OpenCode 会话。

func (*OpenCodeServer) GetSession added in v0.1.18

func (s *OpenCodeServer) GetSession(ctx context.Context, sessionID string) (*sessionResponse, error)

GetSession retrieves session metadata required to resume plan handoff handling.

func (*OpenCodeServer) PID

func (s *OpenCodeServer) PID() int

PID 返回子进程的 PID。

func (*OpenCodeServer) SendMessage

func (s *OpenCodeServer) SendMessage(ctx context.Context, sessionID string, req messageRequest) (*messageResponse, error)

SendMessage 向指定会话发送消息并同步等待完整响应。 注意:openCode 的 /session/:id/message 是同步端点,会等待模型完整生成, 可能耗时数分钟,因此不使用带超时的 httpClient,而是依赖 context 控制生命周期。

func (*OpenCodeServer) SendPermissionDecision

func (s *OpenCodeServer) SendPermissionDecision(ctx context.Context, permissionID, decision string) error

SendPermissionDecision 响应权限请求。

func (*OpenCodeServer) SendQuestionAnswer

func (s *OpenCodeServer) SendQuestionAnswer(ctx context.Context, questionID string, answers [][]string) error

SendQuestionAnswer 响应 question 请求,发送用户选择的答案。

func (*OpenCodeServer) Stop

func (s *OpenCodeServer) Stop() error

Stop 终止 opencode 子进程。

type Runtime

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

Runtime executes requests through OpenCode.

func New

func New(binary string, options externalcli.DriverOptions) (*Runtime, error)

New creates an OpenCode Runtime backed by the configured CLI binary.

func NewWithInvoker

func NewWithInvoker(invoker externalcli.Invoker, options externalcli.DriverOptions) (*Runtime, error)

NewWithInvoker creates an OpenCode Runtime with an injected process invoker.

func (*Runtime) Execute

func (r *Runtime) Execute(
	ctx context.Context,
	request agent.ExecutionRequest,
	observer agent.Observer,
) (agent.ExecutionResult, error)

func (*Runtime) Name

func (r *Runtime) Name() string

type ServerInvoker

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

============================================================================ ServerInvoker — opencode serve 模式的调用器 ============================================================================ ServerInvoker 通过 opcode serve HTTP API 执行提示。

func NewServerInvoker

func NewServerInvoker(binary string, extraEnv map[string]string) *ServerInvoker

NewServerInvoker 创建新的 ServerInvoker。

func (*ServerInvoker) Invoke

Run 启动 opcode serve,创建会话并执行提示。

Jump to

Keyboard shortcuts

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