Documentation
¶
Index ¶
- func BuildDefaultPrompt(req Request) string
- func ParseTextResponse(text string) (approved bool, remember bool, isValid bool)
- type AskUserQuestionHandler
- func (h *AskUserQuestionHandler) BuildPrompt(req Request) string
- func (h *AskUserQuestionHandler) CanHandle(toolName string, input map[string]interface{}) bool
- func (h *AskUserQuestionHandler) Description() string
- func (h *AskUserQuestionHandler) ParseResponse(req Request, response Response) (Result, error)
- type Config
- type DefaultHandler
- func (h *DefaultHandler) Ask(ctx context.Context, req Request) (Result, error)
- func (h *DefaultHandler) GetMode(scopeID string) (Mode, error)
- func (h *DefaultHandler) GetPendingRequests() []Request
- func (h *DefaultHandler) GetPrompter() Prompter
- func (h *DefaultHandler) SetMode(scopeID string, mode Mode) error
- func (h *DefaultHandler) SetPrompter(p Prompter)
- func (h *DefaultHandler) SubmitResult(requestID string, result Result) error
- type DefaultToolHandler
- type DenyAllPrompter
- type Handler
- type Mode
- type NoOpPrompter
- type Prompter
- type Request
- type Response
- type Result
- type StdinPrompter
- type ToolHandler
- type ToolHandlerRegistry
- func (r *ToolHandlerRegistry) FindHandler(toolName string, input map[string]interface{}) ToolHandler
- func (r *ToolHandlerRegistry) FindPromptBuilder(toolName string, input map[string]interface{}) ToolPromptBuilder
- func (r *ToolHandlerRegistry) FindResponseParser(toolName string, input map[string]interface{}) ToolResponseParser
- func (r *ToolHandlerRegistry) Register(h ToolHandler)
- type ToolPromptBuilder
- type ToolResponseParser
- type Type
- type UserPrompter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildDefaultPrompt ¶
BuildDefaultPrompt creates the default permission prompt text
Types ¶
type AskUserQuestionHandler ¶
type AskUserQuestionHandler struct{}
AskUserQuestionHandler handles the AskUserQuestion tool which presents multiple choice questions to the user
func NewAskUserQuestionHandler ¶
func NewAskUserQuestionHandler() *AskUserQuestionHandler
NewAskUserQuestionHandler creates a new AskUserQuestionHandler
func (*AskUserQuestionHandler) BuildPrompt ¶
func (h *AskUserQuestionHandler) BuildPrompt(req Request) string
BuildPrompt creates a prompt showing all questions and options
func (*AskUserQuestionHandler) CanHandle ¶
func (h *AskUserQuestionHandler) CanHandle(toolName string, input map[string]interface{}) bool
CanHandle returns true for AskUserQuestion tool
func (*AskUserQuestionHandler) Description ¶
func (h *AskUserQuestionHandler) Description() string
Description returns the handler description
func (*AskUserQuestionHandler) ParseResponse ¶
func (h *AskUserQuestionHandler) ParseResponse(req Request, response Response) (Result, error)
ParseResponse parses the user's selection into the answers format
type Config ¶
type Config struct {
// DefaultMode is the default mode for new sessions
DefaultMode Mode `json:"default_mode"`
// Timeout is the default timeout for requests
Timeout time.Duration `json:"timeout"`
// EnableWhitelist enables tool whitelisting
EnableWhitelist bool `json:"enable_whitelist"`
// Whitelist contains auto-approved tools
Whitelist []string `json:"whitelist"`
// Blacklist contains auto-denied tools
Blacklist []string `json:"blacklist"`
// RememberDecisions enables decision caching
RememberDecisions bool `json:"remember_decisions"`
// DecisionDuration is how long to cache decisions
DecisionDuration time.Duration `json:"decision_duration"`
}
Config holds handler configuration
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults
type DefaultHandler ¶
type DefaultHandler struct {
// contains filtered or unexported fields
}
DefaultHandler implements the Handler interface
func NewHandler ¶
func NewHandler(config Config) *DefaultHandler
NewHandler creates a new ask handler with the given config
func (*DefaultHandler) GetMode ¶
func (h *DefaultHandler) GetMode(scopeID string) (Mode, error)
GetMode gets the current mode for a scope
func (*DefaultHandler) GetPendingRequests ¶
func (h *DefaultHandler) GetPendingRequests() []Request
GetPendingRequests returns all pending requests
func (*DefaultHandler) GetPrompter ¶
func (h *DefaultHandler) GetPrompter() Prompter
GetPrompter returns the current prompter
func (*DefaultHandler) SetMode ¶
func (h *DefaultHandler) SetMode(scopeID string, mode Mode) error
SetMode sets the mode for a scope
func (*DefaultHandler) SetPrompter ¶
func (h *DefaultHandler) SetPrompter(p Prompter)
SetPrompter sets the prompter for user interaction
func (*DefaultHandler) SubmitResult ¶
func (h *DefaultHandler) SubmitResult(requestID string, result Result) error
SubmitResult submits a result for a pending request
type DefaultToolHandler ¶
type DefaultToolHandler struct{}
DefaultToolHandler is the fallback handler for tools without specific handlers
func NewDefaultToolHandler ¶
func NewDefaultToolHandler() *DefaultToolHandler
NewDefaultToolHandler creates a new DefaultToolHandler
func (*DefaultToolHandler) BuildPrompt ¶
func (h *DefaultToolHandler) BuildPrompt(req Request) string
BuildPrompt creates a simple permission prompt
func (*DefaultToolHandler) CanHandle ¶
func (h *DefaultToolHandler) CanHandle(toolName string, input map[string]interface{}) bool
CanHandle returns true for all tools (acts as fallback)
func (*DefaultToolHandler) Description ¶
func (h *DefaultToolHandler) Description() string
Description returns the handler description
func (*DefaultToolHandler) ParseResponse ¶
func (h *DefaultToolHandler) ParseResponse(req Request, response Response) (Result, error)
ParseResponse parses a simple approve/deny response
type DenyAllPrompter ¶
type DenyAllPrompter struct{}
DenyAllPrompter is a prompter that denies everything
func NewDenyAllPrompter ¶
func NewDenyAllPrompter() *DenyAllPrompter
NewDenyAllPrompter creates a new DenyAllPrompter
type Handler ¶
type Handler interface {
// Ask sends a request to the user and waits for response
Ask(ctx context.Context, req Request) (Result, error)
// SetMode sets the mode for a session/scope
SetMode(scopeID string, mode Mode) error
// GetMode gets the current mode for a session/scope
GetMode(scopeID string) (Mode, error)
// SubmitResult submits a result for a pending request (for async handlers)
SubmitResult(requestID string, result Result) error
// GetPendingRequests returns all pending requests
GetPendingRequests() []Request
// SetPrompter sets the prompter for user interaction
SetPrompter(p Prompter)
}
Handler is the main interface for handling user prompts
type NoOpPrompter ¶
type NoOpPrompter struct{}
NoOpPrompter is a prompter that auto-approves everything
func NewNoOpPrompter ¶
func NewNoOpPrompter() *NoOpPrompter
NewNoOpPrompter creates a new NoOpPrompter
type Prompter ¶
type Prompter interface {
// Prompt sends a prompt to the user and returns the response
Prompt(ctx context.Context, req Request) (Result, error)
}
Prompter handles the actual user interaction Implementations: StdinPrompter, IMPrompter, NoOpPrompter
type Request ¶
type Request struct {
// ID is the unique identifier for this request
ID string `json:"id"`
// Type is the type of user interaction
Type Type `json:"type"`
ChatID string `json:"chat_id"`
Platform string `json:"platform"`
BotUUID string `json:"bot_uuid"`
// SessionID is the session this request belongs to
SessionID string `json:"session_id,omitempty"`
// AgentType is the source agent type
AgentType agentboot.AgentType `json:"agent_type"`
// ToolName is the tool name for permission requests
ToolName string `json:"tool_name,omitempty"`
// Input is the tool input data
Input map[string]interface{} `json:"input,omitempty"`
// Title is an optional title for the prompt
Title string `json:"title,omitempty"`
// Message is the main prompt message
Message string `json:"message,omitempty"`
// Reason explains why this request is being made
Reason string `json:"reason,omitempty"`
// Timeout is the maximum time to wait for a response
Timeout time.Duration `json:"timeout,omitempty"`
// Metadata contains additional context (e.g., chat_id, platform for IM)
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
Request represents a request to ask the user something
func FromPermissionRequest ¶
func FromPermissionRequest(pr agentboot.PermissionRequest) *Request
FromPermissionRequest creates a Request from legacy PermissionRequest
func (*Request) GetChatContext ¶
GetChatContext extracts chat context from metadata
func (*Request) IsPermissionRequest ¶
IsPermissionRequest returns true if this is a permission request
func (*Request) IsQuestionRequest ¶
IsQuestionRequest returns true if this is a question request
func (*Request) SetChatContext ¶
SetChatContext sets chat context in metadata
func (*Request) ToPermissionRequest ¶
func (r *Request) ToPermissionRequest() agentboot.PermissionRequest
ToPermissionRequest converts to the legacy PermissionRequest type This is for backward compatibility
type Response ¶
type Response struct {
// Type indicates the response type: "button", "text", "selection"
Type string `json:"type"`
// Data contains the raw response data
Data string `json:"data"`
// Selections contains structured selections for multi-select scenarios
Selections map[string]interface{} `json:"selections,omitempty"`
}
Response represents a user's raw response (from button click or text input)
type Result ¶
type Result struct {
// ID matches the request ID
ID string `json:"id"`
// Approved indicates if the request was approved (for permission/confirmation)
Approved bool `json:"approved,omitempty"`
// Response contains text input (for text_input type)
Response string `json:"response,omitempty"`
// Selection contains structured selections (for question type)
// Key is typically the question index or ID, value is the selected option
Selection map[string]interface{} `json:"selection,omitempty"`
// Remember indicates this decision should be remembered
Remember bool `json:"remember,omitempty"`
// Reason explains the decision
Reason string `json:"reason,omitempty"`
// UpdatedInput contains modified tool input (for AskUserQuestion answers)
UpdatedInput map[string]interface{} `json:"updated_input,omitempty"`
}
Result represents the user's response to an ask request
func ParseDefaultResponse ¶
ParseDefaultResponse parses standard allow/deny responses
func (*Result) ToPermissionResult ¶
func (r *Result) ToPermissionResult() agentboot.PermissionResult
ToPermissionResult converts Result to legacy PermissionResult
type StdinPrompter ¶
type StdinPrompter struct {
// Debug enables verbose output
Debug bool
// Colors for terminal output (can be disabled by setting to empty strings)
ColorReset string
ColorRed string
ColorGreen string
ColorYellow string
ColorCyan string
// contains filtered or unexported fields
}
StdinPrompter implements Prompter using stdin/stdout
func NewStdinPrompter ¶
func NewStdinPrompter() *StdinPrompter
NewStdinPrompter creates a new StdinPrompter with default colors
func NewStdinPrompterDebug ¶
func NewStdinPrompterDebug() *StdinPrompter
NewStdinPrompterDebug creates a new StdinPrompter with debug enabled
func StdinPrompterFromLegacy ¶
func StdinPrompterFromLegacy() *StdinPrompter
StdinPrompterFromLegacy creates a StdinPrompter from legacy config
type ToolHandler ¶
type ToolHandler interface {
// CanHandle returns true if this handler can handle the given tool
CanHandle(toolName string, input map[string]interface{}) bool
// Description returns a human-readable description of this handler
Description() string
}
ToolHandler handles tool-specific ask requests Each tool type can have its own handler to customize the prompt and response parsing
type ToolHandlerRegistry ¶
type ToolHandlerRegistry struct {
// contains filtered or unexported fields
}
ToolHandlerRegistry manages tool-specific handlers
func NewToolHandlerRegistry ¶
func NewToolHandlerRegistry() *ToolHandlerRegistry
NewToolHandlerRegistry creates a new registry with default handlers
func (*ToolHandlerRegistry) FindHandler ¶
func (r *ToolHandlerRegistry) FindHandler(toolName string, input map[string]interface{}) ToolHandler
FindHandler finds a handler that can handle the given tool
func (*ToolHandlerRegistry) FindPromptBuilder ¶
func (r *ToolHandlerRegistry) FindPromptBuilder(toolName string, input map[string]interface{}) ToolPromptBuilder
FindPromptBuilder finds a handler that implements ToolPromptBuilder
func (*ToolHandlerRegistry) FindResponseParser ¶
func (r *ToolHandlerRegistry) FindResponseParser(toolName string, input map[string]interface{}) ToolResponseParser
FindResponseParser finds a handler that implements ToolResponseParser
func (*ToolHandlerRegistry) Register ¶
func (r *ToolHandlerRegistry) Register(h ToolHandler)
Register adds a new handler to the registry Handlers are checked in reverse registration order (most recent first)
type ToolPromptBuilder ¶
type ToolPromptBuilder interface {
ToolHandler
// BuildPrompt creates the prompt message for this tool
BuildPrompt(req Request) string
}
ToolPromptBuilder builds prompts for tool requests
type ToolResponseParser ¶
type ToolResponseParser interface {
ToolHandler
// ParseResponse parses user response into Result
ParseResponse(req Request, response Response) (Result, error)
}
ToolResponseParser parses user responses into results
type Type ¶
type Type string
Type defines the type of user interaction
const ( // TypePermission is for tool approval requests TypePermission Type = "permission" // TypeQuestion is for multi-choice questions (AskUserQuestion tool) TypeQuestion Type = "question" // TypeConfirmation is for simple yes/no confirmations TypeConfirmation Type = "confirmation" // TypeTextInput is for free text input requests TypeTextInput Type = "text_input" )
type UserPrompter ¶
type UserPrompter interface {
PromptPermission(ctx context.Context, req agentboot.PermissionRequest) (agentboot.PermissionResult, error)
}
UserPrompter is the legacy interface for backward compatibility
func ToLegacyUserPrompter ¶
func ToLegacyUserPrompter(p Prompter) UserPrompter
ToLegacyUserPrompter creates a legacy-compatible prompter wrapper