Documentation
¶
Overview ¶
Package agent provides an abstraction layer for managing communication with OpenCode in agent mode, with a focus on MCP (Model Context Protocol) server configuration.
The agent package enables programmatic control of AI agents through the OpenCode SDK, providing structured configuration for MCP servers, permissions, sessions, and prompts.
Overview ¶
The package is built around several core concepts:
- Agent: The main entry point for interacting with OpenCode
- MCP (Model Context Protocol): Server configuration for tool access
- Session: Conversation context management
- Permission: Fine-grained control over agent capabilities
- Prompt: Structured message construction
- Event: Asynchronous response handling
MCP Server Configuration ¶
MCP servers are the primary focus of this package. They enable agents to access external tools and resources. Two transport types are supported:
Local (stdio) servers run as subprocesses:
server := agent.LocalMCPServer("filesystem",
[]string{"mcp-filesystem", "/path/to/repo"},
agent.WithEnv(map[string]string{"LOG_LEVEL": "debug"}),
)
Remote (HTTP/SSE) servers connect over HTTP:
server := agent.RemoteMCPServer("brave-search",
"https://mcp.brave.com/search",
agent.WithHeaders(map[string]string{"Authorization": "Bearer token"}),
)
Servers are managed through an MCPRegistry:
registry := agent.NewMCPRegistry(server1, server2)
agent, _ := agent.New(
agent.WithMCPRegistry(registry),
agent.WithModel("anthropic/claude-3-5-sonnet"),
)
Permissions ¶
Permissions control what actions agents can take. Use the PermissionBuilder for fluent configuration:
perms := agent.NewPermissions().
AllowBash("go test", "go build").
AskBash("rm *").
AllowEdit().
DenyWebfetch().
Build()
agent, _ := agent.New(agent.WithPermissions(perms))
Sessions and Prompts ¶
Agents operate within sessions that maintain conversation context:
session, _ := agent.NewSession(ctx, agent.WithTitle("Code Review"))
defer agent.DeleteSession(ctx, session.ID)
response, _ := session.Prompt(ctx, "Explain this code")
Prompts can include files and other content:
response, _ := session.Prompt(ctx,
"Compare these files",
agent.WithFiles("main.go", "utils.go"),
agent.WithTemperature(0.7),
)
Event Streaming ¶
For async responses, use streaming:
events, _ := agent.Stream(ctx, "Write a haiku")
for event := range events {
switch event.Type {
case agent.EventTypeComplete:
// Handle completion
case agent.EventTypeError:
// Handle error
}
}
Configuration Files ¶
Load configuration from opencode.json files:
config, err := agent.LoadConfigFromDir(".")
agent, _ := agent.New(
agent.WithModel(config.Model),
agent.WithMCPRegistry(agent.NewMCPRegistry(config.GetMCPServers()...)),
)
Thread Safety ¶
The Agent type is safe for concurrent use. All exported methods handle their own synchronization internally.
Index ¶
- Variables
- func SaveConfig(config *Config, path string) error
- func ValidatePath(path, workingDir string) (string, error)
- type Agent
- func (a *Agent) AddMCPServer(ctx context.Context, server *MCPServer) error
- func (a *Agent) Ask(ctx context.Context, prompt string, opts ...PromptOption) (*Response, error)
- func (a *Agent) DeleteSession(ctx context.Context, id string) error
- func (a *Agent) GetClient() *opencode.Client
- func (a *Agent) GetConfig() *Config
- func (a *Agent) GetEventHandler() *EventHandler
- func (a *Agent) GetSession(ctx context.Context, id string) (*Session, error)
- func (a *Agent) ListMCPServers(ctx context.Context) []*MCPServer
- func (a *Agent) ListSessions(ctx context.Context) ([]*Session, error)
- func (a *Agent) NewSession(ctx context.Context, opts ...SessionOption) (*Session, error)
- func (a *Agent) RemoveMCPServer(ctx context.Context, name string)
- func (a *Agent) Stream(ctx context.Context, prompt string, opts ...PromptOption) (<-chan Event, error)
- type AgentConfig
- type AgentError
- type AgentMode
- type AgentRefPart
- type AgentType
- type Config
- type ConfigBuilder
- func (b *ConfigBuilder) AddLocalMCP(name string, command []string, env map[string]string) *ConfigBuilder
- func (b *ConfigBuilder) AddRemoteMCP(name string, url string, headers map[string]string) *ConfigBuilder
- func (b *ConfigBuilder) Build() *Config
- func (b *ConfigBuilder) WithAgent(name string, config AgentConfig) *ConfigBuilder
- func (b *ConfigBuilder) WithModel(model string) *ConfigBuilder
- func (b *ConfigBuilder) WithPermissions(perm *PermissionConfig) *ConfigBuilder
- func (b *ConfigBuilder) WithSmallModel(model string) *ConfigBuilder
- type Event
- type EventHandler
- func (h *EventHandler) Clear(eventType EventType)
- func (h *EventHandler) ClearAll()
- func (h *EventHandler) Handle(ctx context.Context, event Event) error
- func (h *EventHandler) On(eventType EventType, handler EventHandlerFunc)
- func (h *EventHandler) OnComplete(handler func(ctx context.Context, resp Response) error)
- func (h *EventHandler) OnError(handler func(ctx context.Context, err error) error)
- func (h *EventHandler) OnFile(handler func(ctx context.Context, file FileInfo) error)
- func (h *EventHandler) OnMessage(handler func(ctx context.Context, msg Message) error)
- func (h *EventHandler) OnPermission(handler func(ctx context.Context, req PermissionRequest) error)
- func (h *EventHandler) OnTextPart(handler func(ctx context.Context, text string) error)
- func (h *EventHandler) OnToolCall(handler func(ctx context.Context, tool ToolCall) error)
- type EventHandlerFunc
- type EventType
- type ExecutionResult
- type FeedbackLoop
- type FeedbackLoopOption
- type FileInfo
- type FilePart
- type HookConfig
- type HookEvent
- type HookFunc
- type ImplementRequest
- type ImplementResult
- type MCPError
- type MCPOption
- type MCPRegistry
- func (r *MCPRegistry) Add(server *MCPServer) error
- func (r *MCPRegistry) Clear()
- func (r *MCPRegistry) Count() int
- func (r *MCPRegistry) Get(name string) (*MCPServer, bool)
- func (r *MCPRegistry) List() []*MCPServer
- func (r *MCPRegistry) Merge(other *MCPRegistry) error
- func (r *MCPRegistry) Remove(name string)
- func (r *MCPRegistry) ToConfigMap() map[string]opencode.ConfigMcp
- type MCPServer
- type MCPServerType
- type Message
- type Option
- func WithAgentType(agentType AgentType) Option
- func WithBaseURL(baseURL string) Option
- func WithClient(client *opencode.Client) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMCPRegistry(registry *MCPRegistry) Option
- func WithMCPServers(servers ...*MCPServer) Option
- func WithModel(model string) Option
- func WithPathMapping(mapping map[string]string) Option
- func WithPermissionHandler(handler PermissionHandler) Option
- func WithPermissions(perm *PermissionConfig) Option
- func WithSmallModel(model string) Option
- func WithWorkingDir(dir string) Option
- type PRHandler
- type Part
- type PermissionBuilder
- func (b *PermissionBuilder) AllowBash(patterns ...string) *PermissionBuilder
- func (b *PermissionBuilder) AllowEdit() *PermissionBuilder
- func (b *PermissionBuilder) AllowWebfetch() *PermissionBuilder
- func (b *PermissionBuilder) AskBash(patterns ...string) *PermissionBuilder
- func (b *PermissionBuilder) AskEdit() *PermissionBuilder
- func (b *PermissionBuilder) AskWebfetch() *PermissionBuilder
- func (b *PermissionBuilder) Build() *PermissionConfig
- func (b *PermissionBuilder) DenyBash(patterns ...string) *PermissionBuilder
- func (b *PermissionBuilder) DenyEdit() *PermissionBuilder
- func (b *PermissionBuilder) DenyWebfetch() *PermissionBuilder
- type PermissionConfig
- type PermissionHandler
- type PermissionLevel
- type PermissionRequest
- type PermissionResponse
- type PermissionType
- type PromptBuilder
- func (b *PromptBuilder) AddAgentRef(name string) *PromptBuilder
- func (b *PromptBuilder) AddFile(path string) *PromptBuilder
- func (b *PromptBuilder) AddFileFromContent(path string, content []byte, mime string) *PromptBuilder
- func (b *PromptBuilder) AddSymbol(path string, name string, kind int) *PromptBuilder
- func (b *PromptBuilder) AddText(content string) *PromptBuilder
- func (b *PromptBuilder) Build(opts ...PromptOption) *PromptConfig
- type PromptConfig
- type PromptOption
- func WithAgent(name string) PromptOption
- func WithContext(ctx string) PromptOption
- func WithFiles(paths ...string) PromptOption
- func WithParts(parts ...PromptPart) PromptOption
- func WithPromptModel(model string) PromptOption
- func WithSystemPrompt(prompt string) PromptOption
- func WithTemperature(temp float64) PromptOption
- type PromptPart
- func AgentRef(name string) PromptPart
- func File(path string) PromptPart
- func FileFromContent(path string, content []byte, mime string) PromptPart
- func FileWithWorkingDir(path string, workingDir string) PromptPart
- func Symbol(path string, name string, kind int) PromptPart
- func SymbolFromContent(path string, name string, kind int, content []byte) PromptPart
- func SymbolWithWorkingDir(path string, name string, kind int, workingDir string) PromptPart
- func Text(content string) PromptPart
- type Response
- type ReviewHandler
- type ReviewResult
- type Session
- func (s *Session) Abort(ctx context.Context) error
- func (s *Session) Close() error
- func (s *Session) Messages(ctx context.Context) ([]Message, error)
- func (s *Session) Prompt(ctx context.Context, prompt string, opts ...PromptOption) (*Response, error)
- func (s *Session) PromptStream(ctx context.Context, prompt string, opts ...PromptOption) (<-chan Event, error)
- func (s *Session) Refresh(ctx context.Context) error
- func (s *Session) Revert(ctx context.Context, messageID string) error
- func (s *Session) Share(ctx context.Context) (string, error)
- func (s *Session) Summarize(ctx context.Context) error
- func (s *Session) Unshare(ctx context.Context) error
- func (s *Session) UpdateTitle(ctx context.Context, title string) error
- type SessionConfig
- type SessionOption
- type SymbolPart
- type TextPart
- type TextPartData
- type TokenUsage
- type ToolCall
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNilClient is returned when a nil OpenCode client is provided ErrNilClient = errors.New("client cannot be nil") // ErrNoModel is returned when no model is specified ErrNoModel = errors.New("no model specified") // ErrInvalidModel is returned when the model format is invalid ErrInvalidModel = errors.New("invalid model format, expected provider/model") // ErrSessionNotFound is returned when a session cannot be found ErrSessionNotFound = errors.New("session not found") // ErrSessionAborted is returned when a session is aborted ErrSessionAborted = errors.New("session was aborted") // ErrNoMCPServers is returned when no MCP servers are configured ErrNoMCPServers = errors.New("no MCP servers configured") // ErrMCPServerExists is returned when trying to add a duplicate MCP server ErrMCPServerExists = errors.New("MCP server already exists") // ErrMCPServerNotFound is returned when an MCP server cannot be found ErrMCPServerNotFound = errors.New("MCP server not found") // ErrInvalidMCPConfig is returned when MCP server configuration is invalid ErrInvalidMCPConfig = errors.New("invalid MCP server configuration") // ErrPermissionDenied is returned when an action is denied by permissions ErrPermissionDenied = errors.New("permission denied") // ErrPromptFailed is returned when a prompt operation fails ErrPromptFailed = errors.New("prompt failed") // ErrStreamFailed is returned when a stream operation fails ErrStreamFailed = errors.New("stream failed") )
Error types for the agent package
var ( ErrReviewRejected = errors.New("review rejected") ErrMaxRetries = errors.New("max retries exceeded") ErrToolNotFound = errors.New("tool not found") ErrReviewFailed = errors.New("review failed") ErrExecutionFailed = errors.New("execution failed") )
var ( ErrPathTraversal = errors.New("path traversal detected: path outside working directory") ErrEmptyPath = errors.New("empty path provided") )
Functions ¶
func SaveConfig ¶
func ValidatePath ¶
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
func (*Agent) AddMCPServer ¶
func (*Agent) Ask ¶
Ask sends a one-off prompt and returns the response. Note: This creates a new session for each call. For multiple prompts, use NewSession and session.Prompt instead to reuse the session.
func (*Agent) GetEventHandler ¶
func (a *Agent) GetEventHandler() *EventHandler
func (*Agent) GetSession ¶
func (*Agent) NewSession ¶
func (*Agent) Stream ¶
func (a *Agent) Stream(ctx context.Context, prompt string, opts ...PromptOption) (<-chan Event, error)
Stream sends a one-off prompt and returns a channel for streaming responses. Note: This creates a new session for each call. For multiple prompts, use NewSession and session.PromptStream instead to reuse the session.
type AgentConfig ¶
type AgentConfig struct {
Description string `json:"description"`
Prompt string `json:"prompt"`
Model string `json:"model"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
Mode AgentMode `json:"mode"`
Permissions *PermissionConfig `json:"permissions,omitempty"`
Tools map[string]bool `json:"tools,omitempty"`
}
type AgentError ¶
type AgentError struct {
// Op is the operation that failed
Op string
// Session is the session ID if applicable
Session string
// Err is the underlying error
Err error
// Details contains additional error context
Details map[string]interface{}
}
AgentError represents an error from agent operations
type AgentRefPart ¶
type AgentRefPart struct {
// contains filtered or unexported fields
}
func (*AgentRefPart) ToInput ¶
func (p *AgentRefPart) ToInput() (opencode.SessionPromptParamsPartUnion, error)
type Config ¶
type Config struct {
Model string
SmallModel string
AgentType AgentType
Permissions *PermissionConfig
Hooks *HookConfig
WorkingDir string
// PathMapping maps host paths to container paths for Docker-based agents
PathMapping map[string]string
Tools map[string]bool
// contains filtered or unexported fields
}
func LoadConfig ¶
func LoadConfigFromDir ¶
func (*Config) GetAgents ¶
func (c *Config) GetAgents() map[string]AgentConfig
func (*Config) GetMCPServers ¶
type ConfigBuilder ¶
type ConfigBuilder struct {
// contains filtered or unexported fields
}
func NewConfigBuilder ¶
func NewConfigBuilder() *ConfigBuilder
func (*ConfigBuilder) AddLocalMCP ¶
func (b *ConfigBuilder) AddLocalMCP(name string, command []string, env map[string]string) *ConfigBuilder
func (*ConfigBuilder) AddRemoteMCP ¶
func (b *ConfigBuilder) AddRemoteMCP(name string, url string, headers map[string]string) *ConfigBuilder
func (*ConfigBuilder) Build ¶
func (b *ConfigBuilder) Build() *Config
func (*ConfigBuilder) WithAgent ¶
func (b *ConfigBuilder) WithAgent(name string, config AgentConfig) *ConfigBuilder
func (*ConfigBuilder) WithModel ¶
func (b *ConfigBuilder) WithModel(model string) *ConfigBuilder
func (*ConfigBuilder) WithPermissions ¶
func (b *ConfigBuilder) WithPermissions(perm *PermissionConfig) *ConfigBuilder
func (*ConfigBuilder) WithSmallModel ¶
func (b *ConfigBuilder) WithSmallModel(model string) *ConfigBuilder
type EventHandler ¶
type EventHandler struct {
// contains filtered or unexported fields
}
func NewEventHandler ¶
func NewEventHandler() *EventHandler
func (*EventHandler) Clear ¶
func (h *EventHandler) Clear(eventType EventType)
func (*EventHandler) ClearAll ¶
func (h *EventHandler) ClearAll()
func (*EventHandler) On ¶
func (h *EventHandler) On(eventType EventType, handler EventHandlerFunc)
func (*EventHandler) OnComplete ¶
func (h *EventHandler) OnComplete(handler func(ctx context.Context, resp Response) error)
func (*EventHandler) OnError ¶
func (h *EventHandler) OnError(handler func(ctx context.Context, err error) error)
func (*EventHandler) OnFile ¶
func (h *EventHandler) OnFile(handler func(ctx context.Context, file FileInfo) error)
func (*EventHandler) OnMessage ¶
func (h *EventHandler) OnMessage(handler func(ctx context.Context, msg Message) error)
func (*EventHandler) OnPermission ¶
func (h *EventHandler) OnPermission(handler func(ctx context.Context, req PermissionRequest) error)
func (*EventHandler) OnTextPart ¶
func (h *EventHandler) OnTextPart(handler func(ctx context.Context, text string) error)
func (*EventHandler) OnToolCall ¶
func (h *EventHandler) OnToolCall(handler func(ctx context.Context, tool ToolCall) error)
type ExecutionResult ¶
type FeedbackLoop ¶
type FeedbackLoop struct {
// contains filtered or unexported fields
}
func NewFeedbackLoop ¶
func NewFeedbackLoop(agent *Agent, session *Session, opts ...FeedbackLoopOption) *FeedbackLoop
func (*FeedbackLoop) ImplementWithReview ¶
func (fl *FeedbackLoop) ImplementWithReview(ctx context.Context, req ImplementRequest) (*ImplementResult, error)
type FeedbackLoopOption ¶
type FeedbackLoopOption func(*FeedbackLoop)
func WithMaxRetries ¶
func WithMaxRetries(retries int) FeedbackLoopOption
func WithPRHandler ¶
func WithPRHandler(handler PRHandler) FeedbackLoopOption
func WithPRTool ¶
func WithPRTool(tool string) FeedbackLoopOption
func WithReviewHandler ¶
func WithReviewHandler(handler ReviewHandler) FeedbackLoopOption
func WithReviewTool ¶
func WithReviewTool(tool string) FeedbackLoopOption
type FilePart ¶
type FilePart struct {
// contains filtered or unexported fields
}
func (*FilePart) GetContent ¶
type HookConfig ¶
type ImplementRequest ¶
type ImplementResult ¶
type MCPError ¶
type MCPError struct {
// Server is the name of the MCP server
Server string
// Err is the underlying error
Err error
// Details contains additional error context
Details map[string]interface{}
}
MCPError represents an error from MCP server operations
type MCPOption ¶
type MCPOption func(*MCPServer)
MCPOption configures an MCP server
func WithEnabled ¶
WithEnabled sets whether the server is enabled
func WithHeaders ¶
WithHeaders sets HTTP headers for remote MCP servers
type MCPRegistry ¶
type MCPRegistry struct {
// contains filtered or unexported fields
}
MCPRegistry manages a collection of MCP servers
func NewMCPRegistry ¶
func NewMCPRegistry(servers ...*MCPServer) *MCPRegistry
NewMCPRegistry creates a new registry with the given servers
func (*MCPRegistry) Add ¶
func (r *MCPRegistry) Add(server *MCPServer) error
Add adds an MCP server to the registry
func (*MCPRegistry) Clear ¶
func (r *MCPRegistry) Clear()
Clear removes all servers from the registry
func (*MCPRegistry) Count ¶
func (r *MCPRegistry) Count() int
Count returns the number of servers in the registry
func (*MCPRegistry) Get ¶
func (r *MCPRegistry) Get(name string) (*MCPServer, bool)
Get retrieves an MCP server by name
func (*MCPRegistry) List ¶
func (r *MCPRegistry) List() []*MCPServer
List returns all MCP servers in the registry
func (*MCPRegistry) Merge ¶
func (r *MCPRegistry) Merge(other *MCPRegistry) error
Merge combines another registry into this one
func (*MCPRegistry) Remove ¶
func (r *MCPRegistry) Remove(name string)
Remove removes an MCP server from the registry
func (*MCPRegistry) ToConfigMap ¶
func (r *MCPRegistry) ToConfigMap() map[string]opencode.ConfigMcp
ToConfigMap converts all servers to the OpenCode SDK configuration format
type MCPServer ¶
type MCPServer struct {
// Name is the unique identifier for the server
Name string `json:"name"`
// Type specifies whether this is a local or remote server
Type MCPServerType `json:"type"`
// Command is the executable and arguments for local servers
Command []string `json:"command,omitempty"`
// Environment variables for local servers
Environment map[string]string `json:"environment,omitempty"`
// URL is the endpoint for remote servers
URL string `json:"url,omitempty"`
// Headers for remote server authentication
Headers map[string]string `json:"headers,omitempty"`
// Enabled determines if the server is active
Enabled bool `json:"enabled"`
// Disabled explicitly disables a server
Disabled bool `json:"disabled,omitempty"`
}
MCPServer defines an MCP (Model Context Protocol) server configuration
func LocalMCPServer ¶
LocalMCPServer creates a local MCP server that runs as a subprocess using stdio for communication.
Example:
server := LocalMCPServer("filesystem",
[]string{"mcp-filesystem", "/path/to/repo"},
WithEnv(map[string]string{"LOG_LEVEL": "debug"}),
WithEnabled(true),
)
func RemoteMCPServer ¶
RemoteMCPServer creates a remote MCP server that connects via HTTP/SSE.
Example:
server := RemoteMCPServer("brave-search",
"https://mcp.brave.com/search",
WithHeaders(map[string]string{"Authorization": "Bearer token"}),
WithEnabled(true),
)
type MCPServerType ¶
type MCPServerType string
MCPServerType defines the type of MCP server connection
const ( // MCPServerTypeLocal represents a local MCP server using stdio transport MCPServerTypeLocal MCPServerType = "local" // MCPServerTypeRemote represents a remote MCP server using HTTP/SSE transport MCPServerTypeRemote MCPServerType = "remote" )
type Option ¶
func WithAgentType ¶
func WithBaseURL ¶
func WithClient ¶
func WithLogger ¶
func WithMCPRegistry ¶
func WithMCPRegistry(registry *MCPRegistry) Option
func WithMCPServers ¶
func WithPathMapping ¶
WithPathMapping configures path translation for Docker-based agents. It maps host paths to container paths so that when the agent creates a session, the directory is correctly translated for the container. Example: {"/home/user/agent-workspaces": "/agent-workspaces"}
func WithPermissionHandler ¶
func WithPermissionHandler(handler PermissionHandler) Option
func WithPermissions ¶
func WithPermissions(perm *PermissionConfig) Option
func WithSmallModel ¶
func WithWorkingDir ¶
type PermissionBuilder ¶
type PermissionBuilder struct {
// contains filtered or unexported fields
}
func NewPermissions ¶
func NewPermissions() *PermissionBuilder
func (*PermissionBuilder) AllowBash ¶
func (b *PermissionBuilder) AllowBash(patterns ...string) *PermissionBuilder
func (*PermissionBuilder) AllowEdit ¶
func (b *PermissionBuilder) AllowEdit() *PermissionBuilder
func (*PermissionBuilder) AllowWebfetch ¶
func (b *PermissionBuilder) AllowWebfetch() *PermissionBuilder
func (*PermissionBuilder) AskBash ¶
func (b *PermissionBuilder) AskBash(patterns ...string) *PermissionBuilder
func (*PermissionBuilder) AskEdit ¶
func (b *PermissionBuilder) AskEdit() *PermissionBuilder
func (*PermissionBuilder) AskWebfetch ¶
func (b *PermissionBuilder) AskWebfetch() *PermissionBuilder
func (*PermissionBuilder) Build ¶
func (b *PermissionBuilder) Build() *PermissionConfig
func (*PermissionBuilder) DenyBash ¶
func (b *PermissionBuilder) DenyBash(patterns ...string) *PermissionBuilder
func (*PermissionBuilder) DenyEdit ¶
func (b *PermissionBuilder) DenyEdit() *PermissionBuilder
func (*PermissionBuilder) DenyWebfetch ¶
func (b *PermissionBuilder) DenyWebfetch() *PermissionBuilder
type PermissionConfig ¶
type PermissionConfig struct {
Bash PermissionLevel `json:"bash"`
BashMap map[string]PermissionLevel `json:"bashMap,omitempty"`
Edit PermissionLevel `json:"edit"`
Webfetch PermissionLevel `json:"webfetch"`
}
type PermissionHandler ¶
type PermissionHandler func(ctx context.Context, req *PermissionRequest) (*PermissionResponse, error)
func AllowAllPermissionHandler ¶
func AllowAllPermissionHandler() PermissionHandler
func DefaultPermissionHandler ¶
func DefaultPermissionHandler() PermissionHandler
func DenyAllPermissionHandler ¶
func DenyAllPermissionHandler() PermissionHandler
type PermissionLevel ¶
type PermissionLevel string
const ( PermissionAsk PermissionLevel = "ask" PermissionAllow PermissionLevel = "allow" PermissionDeny PermissionLevel = "deny" )
type PermissionRequest ¶
type PermissionRequest struct {
ID string
Session string
Type PermissionType
Details map[string]interface{}
}
type PermissionResponse ¶
type PermissionType ¶
type PermissionType string
const ( PermissionTypeBash PermissionType = "bash" PermissionTypeEdit PermissionType = "edit" PermissionTypeWebfetch PermissionType = "webfetch" )
type PromptBuilder ¶
type PromptBuilder struct {
// contains filtered or unexported fields
}
func NewPromptBuilder ¶
func NewPromptBuilder() *PromptBuilder
func (*PromptBuilder) AddAgentRef ¶
func (b *PromptBuilder) AddAgentRef(name string) *PromptBuilder
func (*PromptBuilder) AddFile ¶
func (b *PromptBuilder) AddFile(path string) *PromptBuilder
func (*PromptBuilder) AddFileFromContent ¶
func (b *PromptBuilder) AddFileFromContent(path string, content []byte, mime string) *PromptBuilder
func (*PromptBuilder) AddSymbol ¶
func (b *PromptBuilder) AddSymbol(path string, name string, kind int) *PromptBuilder
func (*PromptBuilder) AddText ¶
func (b *PromptBuilder) AddText(content string) *PromptBuilder
func (*PromptBuilder) Build ¶
func (b *PromptBuilder) Build(opts ...PromptOption) *PromptConfig
type PromptConfig ¶
type PromptOption ¶
type PromptOption func(*PromptConfig)
func WithAgent ¶
func WithAgent(name string) PromptOption
func WithContext ¶
func WithContext(ctx string) PromptOption
func WithFiles ¶
func WithFiles(paths ...string) PromptOption
func WithParts ¶
func WithParts(parts ...PromptPart) PromptOption
func WithPromptModel ¶
func WithPromptModel(model string) PromptOption
func WithSystemPrompt ¶
func WithSystemPrompt(prompt string) PromptOption
func WithTemperature ¶
func WithTemperature(temp float64) PromptOption
type PromptPart ¶
type PromptPart interface {
ToInput() (opencode.SessionPromptParamsPartUnion, error)
}
func AgentRef ¶
func AgentRef(name string) PromptPart
func File ¶
func File(path string) PromptPart
func FileFromContent ¶
func FileFromContent(path string, content []byte, mime string) PromptPart
func FileWithWorkingDir ¶
func FileWithWorkingDir(path string, workingDir string) PromptPart
func SymbolFromContent ¶
func SymbolFromContent(path string, name string, kind int, content []byte) PromptPart
func SymbolWithWorkingDir ¶
func SymbolWithWorkingDir(path string, name string, kind int, workingDir string) PromptPart
func Text ¶
func Text(content string) PromptPart
type ReviewHandler ¶
type ReviewResult ¶
type Session ¶
type Session struct {
ID string
Title string
Directory string
ProjectID string
Created float64
Updated float64
// contains filtered or unexported fields
}
func (*Session) PromptStream ¶
type SessionConfig ¶
type SessionOption ¶
type SessionOption func(*SessionConfig)
func WithDirectory ¶
func WithDirectory(dir string) SessionOption
func WithParentID ¶
func WithParentID(parentID string) SessionOption
func WithProjectID ¶
func WithProjectID(projectID string) SessionOption
func WithTitle ¶
func WithTitle(title string) SessionOption
type SymbolPart ¶
type SymbolPart struct {
// contains filtered or unexported fields
}
func (*SymbolPart) ToInput ¶
func (p *SymbolPart) ToInput() (opencode.SessionPromptParamsPartUnion, error)
type TextPartData ¶
type TextPartData struct {
Text string
}
type TokenUsage ¶
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
Example demonstrates basic usage of the agent package with MCP servers
|
Example demonstrates basic usage of the agent package with MCP servers |
|
feedback-loop
command
|
|
|
mcp-feedback
command
|