opencode

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBaseURL = "http://127.0.0.1:4096"

Variables

This section is empty.

Functions

func DisplayTextForPart

func DisplayTextForPart(part Part) string

func WaitForHealthOrExit

func WaitForHealthOrExit(ctx context.Context, client healthClient, proc *ServerProcess, timeout time.Duration) error

WaitForHealthOrExit polls health until ready, timeout, cancellation, or the managed opencode process exits before becoming ready.

Types

type Client

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

Client communicates with a running `opencode serve` process.

func NewClientWithURL

func NewClientWithURL(baseURL string) *Client

func (*Client) AbortSession

func (c *Client) AbortSession(ctx context.Context, sessionID string) error

func (*Client) BaseURL

func (c *Client) BaseURL() string

func (*Client) CreateSession

func (c *Client) CreateSession(ctx context.Context, directory string) (*Session, error)

func (*Client) GetSession

func (c *Client) GetSession(ctx context.Context, sessionID string) (*Session, error)

func (*Client) Health

func (c *Client) Health(ctx context.Context) error

func (*Client) ListMessages

func (c *Client) ListMessages(ctx context.Context, sessionID string) ([]MessageResponse, error)

func (*Client) ListProviders

func (c *Client) ListProviders(ctx context.Context) ([]Provider, []string, error)

func (*Client) ListSessions

func (c *Client) ListSessions(ctx context.Context) ([]Session, error)

func (*Client) ReplyQuestion

func (c *Client) ReplyQuestion(ctx context.Context, requestID string, answers [][]string) error

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, sessionID, text, providerID, modelID, agent string) <-chan string

SendMessage streams the assistant's reply token-by-token via the returned channel. It first tries the SSE-based approach (prompt_async + /event); if that fails (404 or connection error) it falls back to the synchronous /session/{id}/message endpoint.

func (*Client) SendMessageEvents

func (c *Client) SendMessageEvents(ctx context.Context, sessionID, text, providerID, modelID, agent string) <-chan StreamEvent

type MessageInfo

type MessageInfo struct {
	ID   string `json:"id"`
	Role string `json:"role"`
}

type MessageModelRef

type MessageModelRef struct {
	ProviderID string `json:"providerID"`
	ModelID    string `json:"modelID"`
}

type MessageResponse

type MessageResponse struct {
	Info  MessageInfo `json:"info"`
	Parts []Part      `json:"parts"`
}

type Model

type Model struct {
	ID         string `json:"id"`
	ProviderID string `json:"providerID"`
	Name       string `json:"name"`
	Status     string `json:"status"`
}

type ModelRef

type ModelRef struct {
	ID         string `json:"id"`
	ProviderID string `json:"providerID"`
	Variant    string `json:"variant"`
}

type Part

type Part struct {
	Type string     `json:"type"`
	Text string     `json:"text,omitempty"`
	Tool *ToolEvent `json:"tool,omitempty"`
}

type Provider

type Provider struct {
	ID     string           `json:"id"`
	Name   string           `json:"name"`
	Models map[string]Model `json:"models"`
}

type QuestionInfo

type QuestionInfo struct {
	Question string           `json:"question"`
	Header   string           `json:"header"`
	Options  []QuestionOption `json:"options"`
	Multiple bool             `json:"multiple"`
	Custom   *bool            `json:"custom,omitempty"`
}

type QuestionOption

type QuestionOption struct {
	Label       string `json:"label"`
	Description string `json:"description"`
}

type QuestionRequest

type QuestionRequest struct {
	ID        string         `json:"id"`
	SessionID string         `json:"sessionID"`
	Questions []QuestionInfo `json:"questions"`
}

type ServerProcess

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

ServerProcess owns an opencode server process started by plums.

func StartServer

func StartServer(ctx context.Context, baseURL, directory string) (*ServerProcess, error)

StartServer starts `opencode serve` for baseURL and returns once the process has been launched. Call WaitForHealth before using the client.

func (*ServerProcess) Done

func (p *ServerProcess) Done() <-chan struct{}

Done returns a channel that is closed when the managed process exits.

func (*ServerProcess) Stop

func (p *ServerProcess) Stop()

Stop terminates the managed opencode server process.

type Session

type Session struct {
	ID        string      `json:"id"`
	Title     string      `json:"title"`
	Directory string      `json:"directory"`
	Model     *ModelRef   `json:"model"`
	Time      SessionTime `json:"time"`
}

type SessionTime

type SessionTime struct {
	Created int64 `json:"created"`
	Updated int64 `json:"updated"`
}

type StreamEvent

type StreamEvent struct {
	Text     string
	Tool     *ToolEvent
	Question *QuestionRequest
}

type ToolEvent

type ToolEvent struct {
	ID     string
	Name   string
	Input  string
	Output string
	Error  string
}

Jump to

Keyboard shortcuts

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