Documentation
¶
Index ¶
- Constants
- func NewCleanupRegistry() *cleanupRegistry
- func TrimLeadingWhitespace(s string) string
- func TruncateToTermWidth(s string) (string, bool)
- type ApprovalRequest
- type ApprovalResultMap
- type ApprovalTarget
- type ChatBot
- func (cb *ChatBot) ClearContext()
- func (cb *ChatBot) GetContextSummary() string
- func (cb *ChatBot) SetHandler(handler Handler)
- func (cb *ChatBot) StreamChat(ctx context.Context, userInput string) error
- func (cb *ChatBot) StreamChatWithHandler(ctx context.Context, userInput string, files []FileData) error
- type ChatSession
- func (s *ChatSession) Clear() error
- func (s *ChatSession) Close() error
- func (s *ChatSession) GetLastUserMessage() string
- func (s *ChatSession) GetMessageCount() int
- func (s *ChatSession) OnGenModelInput(ctx context.Context, instruction string, inputMessages []*schema.Message) ([]*schema.Message, error)
- func (s *ChatSession) OnKeep() error
- func (s *ChatSession) PersistenceStore() *store.PersistenceStore
- func (s *ChatSession) RemoveLastRound()
- type FileData
- type Handler
- type StreamFilter
- type WSChatHandler
- func (h *WSChatHandler) SendApprovalRequest(targets []ApprovalTarget) (ApprovalResultMap, error)
- func (h *WSChatHandler) SendChunk(content string, first, last bool, contentType string)
- func (h *WSChatHandler) SendComplete(message string)
- func (h *WSChatHandler) SendError(err string)
- func (h *WSChatHandler) SendMessageCount()
- func (h *WSChatHandler) SendThinking(status bool)
- func (h *WSChatHandler) SendToolCall(name string, arguments string, id string, streaming bool)
- type WSMessage
- type WSSession
- func (s *WSSession) HandleApprovalResponse(approvalID string, results ApprovalResultMap)
- func (s *WSSession) IsCancelled() bool
- func (s *WSSession) IsClosed() bool
- func (s *WSSession) MarkClosed()
- func (s *WSSession) ResetCancel()
- func (s *WSSession) SendChunk(content string, isFirst, isLast bool, contentType string)
- func (s *WSSession) SendError(errMsg string)
- func (s *WSSession) SendMessage(msgType string, content interface{})
- func (s *WSSession) SendMessageCount()
- func (s *WSSession) SendPing()
- func (s *WSSession) SetApprovalTimeout(timeout time.Duration)
- func (s *WSSession) SetCancelFunc(cancelFunc context.CancelFunc)
- func (s *WSSession) SetCancelled()
- func (s *WSSession) SetReadTimeout(d time.Duration)
Constants ¶
const DefaultApprovalTimeout = 5 * time.Minute
Default approval timeout
Variables ¶
This section is empty.
Functions ¶
func NewCleanupRegistry ¶
func NewCleanupRegistry() *cleanupRegistry
NewCleanupRegistry creates a new cleanup registry for the session
func TrimLeadingWhitespace ¶ added in v1.5.3
TrimLeadingWhitespace strips leading whitespace characters (space, tab, newline, carriage return)
func TruncateToTermWidth ¶
Types ¶
type ApprovalRequest ¶
type ApprovalRequest struct {
ApprovalID string
ResultChan chan ApprovalResultMap
}
ApprovalRequest holds the approval ID and result channel
type ApprovalResultMap ¶
type ApprovalResultMap map[string]*mcp.ApprovalResult
ApprovalResultMap holds approval results for multiple targets
type ApprovalTarget ¶
ApprovalTarget represents a single approval request target
type ChatBot ¶
type ChatBot struct {
// contains filtered or unexported fields
}
ChatBot struct for the chatbot
func NewChatBot ¶
func (*ChatBot) GetContextSummary ¶
GetContextSummary retrieves context summary
func (*ChatBot) SetHandler ¶
SetHandler sets the output handler for the chatbot
func (*ChatBot) StreamChat ¶
StreamChat performs streaming chat conversation with CLI output
type ChatSession ¶
type ChatSession struct {
ID string
Name string
Preset config.Chat
Agent *adk.ChatModelAgent
Manager *manager.Manager
Tools []tool.BaseTool
MCPClient *mcp.Client
// contains filtered or unexported fields
}
ChatSession represents a chat session with its configuration
func InitChatSession ¶
func InitChatSession(ctx context.Context, cfg *config.Config, chatName string, sessionID string, debug bool) (*ChatSession, error)
InitChatSession initializes a new chat session with the given chat name and session ID
func (*ChatSession) Close ¶
func (s *ChatSession) Close() error
Close closes the chat session and releases all resources
func (*ChatSession) GetLastUserMessage ¶
func (s *ChatSession) GetLastUserMessage() string
GetLastUserMessage returns the last user message from the conversation, if any. Used for redo/regenerate functionality.
func (*ChatSession) GetMessageCount ¶
func (s *ChatSession) GetMessageCount() int
GetMessageCount returns the number of messages in the session
func (*ChatSession) OnGenModelInput ¶
func (s *ChatSession) OnGenModelInput(ctx context.Context, instruction string, inputMessages []*schema.Message) ([]*schema.Message, error)
OnGenModelInput executes the genmodelinput hook if configured This hook is called before sending messages to the model and can modify the message list
func (*ChatSession) OnKeep ¶
func (s *ChatSession) OnKeep() error
func (*ChatSession) PersistenceStore ¶
func (s *ChatSession) PersistenceStore() *store.PersistenceStore
PersistenceStore returns the persistence store for this session
func (*ChatSession) RemoveLastRound ¶
func (s *ChatSession) RemoveLastRound()
RemoveLastRound removes the last round of messages (used for regenerate)
type Handler ¶
type Handler interface {
// SendChunk sends a content chunk with position markers
// contentType: "response" or "thinking"
SendChunk(content string, first, last bool, contentType string)
// SendToolCall sends a tool call notification with name, arguments, index and streaming status
// index: the tool call index
// streaming: true if this is a streaming update (arguments may be partial), false when complete
SendToolCall(name string, arguments string, id string, streaming bool)
// SendThinking sends a thinking indicator
SendThinking(status bool)
// SendComplete sends a completion signal
SendComplete(message string)
// SendError sends an error message
SendError(err string)
// SendApprovalRequest sends an approval request to the client and waits for the result
// targets: list of approval targets requiring user authorization
// Returns a map of target IDs to their approval results
SendApprovalRequest(targets []ApprovalTarget) (ApprovalResultMap, error)
// SendMessageCount sends the current message count to the client
SendMessageCount()
}
Handler interface for handling chat output events This allows the same streaming logic to be used in different contexts (CLI with readline, WebSocket, etc.)
type StreamFilter ¶
type StreamFilter struct {
// contains filtered or unexported fields
}
func NewStreamFilter ¶
func NewStreamFilter() *StreamFilter
func (*StreamFilter) Finish ¶
func (f *StreamFilter) Finish() *string
func (*StreamFilter) Process ¶
func (f *StreamFilter) Process(chunk string) *string
type WSChatHandler ¶
type WSChatHandler struct {
// contains filtered or unexported fields
}
WSChatHandler implements Handler for WebSocket output
func NewWSChatHandler ¶
func NewWSChatHandler(session *WSSession) *WSChatHandler
func (*WSChatHandler) SendApprovalRequest ¶
func (h *WSChatHandler) SendApprovalRequest(targets []ApprovalTarget) (ApprovalResultMap, error)
func (*WSChatHandler) SendChunk ¶
func (h *WSChatHandler) SendChunk(content string, first, last bool, contentType string)
func (*WSChatHandler) SendComplete ¶
func (h *WSChatHandler) SendComplete(message string)
func (*WSChatHandler) SendError ¶
func (h *WSChatHandler) SendError(err string)
func (*WSChatHandler) SendMessageCount ¶
func (h *WSChatHandler) SendMessageCount()
SendApprovalRequest sends an approval request to the client and waits for the result
func (*WSChatHandler) SendThinking ¶
func (h *WSChatHandler) SendThinking(status bool)
func (*WSChatHandler) SendToolCall ¶
func (h *WSChatHandler) SendToolCall(name string, arguments string, id string, streaming bool)
type WSMessage ¶
type WSMessage struct {
Type string `json:"type"`
Payload json.RawMessage `json:"payload"`
}
WebSocket message types
type WSSession ¶
type WSSession struct {
SessionID string
ChatName string
ChatSession *ChatSession
ChatBot *ChatBot
WSHandler *WSChatHandler
// contains filtered or unexported fields
}
WSSession represents a WebSocket session with its connection
func NewWSSession ¶
func (*WSSession) HandleApprovalResponse ¶
func (s *WSSession) HandleApprovalResponse(approvalID string, results ApprovalResultMap)
HandleApprovalResponse processes an approval response from the client This method is called from the main read loop when an approval_response message is received
func (*WSSession) IsCancelled ¶
IsCancelled returns true if the session is cancelled
func (*WSSession) MarkClosed ¶
func (s *WSSession) MarkClosed()
MarkClosed marks the session as closed so that subsequent SendMessage/SendPing calls are silently dropped instead of writing to a closed connection.
func (*WSSession) ResetCancel ¶
func (s *WSSession) ResetCancel()
ResetCancel resets the cancel state for a new request
func (*WSSession) SendMessage ¶
func (*WSSession) SendMessageCount ¶
func (s *WSSession) SendMessageCount()
SendMessageCount sends the current message count to the client
func (*WSSession) SendPing ¶
func (s *WSSession) SendPing()
SendPing sends a WebSocket ping frame to the client. Used for keepalive to detect dead connections (e.g., mobile network loss). The write deadline ensures we don't block forever if the connection is dead. The deadline is cleared after the write to avoid affecting subsequent writes.
func (*WSSession) SetApprovalTimeout ¶
SetApprovalTimeout sets the timeout for approval requests
func (*WSSession) SetCancelFunc ¶
func (s *WSSession) SetCancelFunc(cancelFunc context.CancelFunc)
SetCancelFunc sets the cancel function for the current request
func (*WSSession) SetCancelled ¶
func (s *WSSession) SetCancelled()
SetCancelled marks the session as cancelled
func (*WSSession) SetReadTimeout ¶
SetReadTimeout sets the read timeout used to reset the read deadline after writes.