Documentation
¶
Index ¶
- func ServeWs(hub *Hub, handler MessageHandler, w http.ResponseWriter, r *http.Request)
- type ActionPayload
- type Client
- type CommandPayload
- type ConversationMessage
- type ErrorPayload
- type Hub
- type Message
- func NewError(code, message, details string) (*Message, error)
- func NewMessage(msgType MessageType, payload interface{}) (*Message, error)
- func NewResponse(text, emotion string) (*Message, error)
- func NewStatus(status string, connected bool, aiStatus string) (*Message, error)
- func NewStreamChunk(chunk string, done bool, fullText string) (*Message, error)
- func NewTrigger(triggerType, title, message string, data interface{}) (*Message, error)
- type MessageHandler
- type MessageType
- type ResponseFormat
- type ResponsePayload
- type StatusPayload
- type StreamPayload
- type TriggerPayload
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ServeWs ¶
func ServeWs(hub *Hub, handler MessageHandler, w http.ResponseWriter, r *http.Request)
ServeWs handles WebSocket requests from clients
Types ¶
type ActionPayload ¶
type ActionPayload struct {
ActionType string `json:"action_type"`
Success bool `json:"success"`
Data interface{} `json:"data,omitempty"`
Error string `json:"error,omitempty"`
}
ActionPayload reports action execution results
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a WebSocket client connection
func NewClient ¶
func NewClient(hub *Hub, conn *websocket.Conn, handler MessageHandler) *Client
NewClient creates a new WebSocket client
func (*Client) AddToHistory ¶
AddToHistory adds a message to the conversation history
func (*Client) GetFormat ¶
func (c *Client) GetFormat() ResponseFormat
GetFormat returns the client's preferred response format
func (*Client) GetHistory ¶
func (c *Client) GetHistory() []ConversationMessage
GetHistory returns the conversation history
func (*Client) SendMessage ¶
SendMessage sends a Message struct to this client
type CommandPayload ¶
type CommandPayload struct {
Text string `json:"text"` // The transcribed text
WakeWord bool `json:"wake_word"` // Whether wake word was detected
Confidence float64 `json:"confidence"` // Speech recognition confidence
}
CommandPayload is sent when user issues a voice command
type ConversationMessage ¶
ConversationMessage represents a message in the conversation history
type ErrorPayload ¶
type ErrorPayload struct {
Code string `json:"code"`
Message string `json:"message"`
Details string `json:"details,omitempty"`
}
ErrorPayload for error messages
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub maintains the set of active clients and broadcasts messages
func (*Hub) BroadcastMessage ¶
BroadcastMessage sends a Message to all connected clients
func (*Hub) ClientCount ¶
ClientCount returns the number of connected clients
func (*Hub) SendToClient ¶
SendToClient sends a message to a specific client
func (*Hub) Unregister ¶
Unregister removes a client from the hub
type Message ¶
type Message struct {
Type MessageType `json:"type"`
Payload json.RawMessage `json:"payload"`
RequestID string `json:"request_id"`
Format ResponseFormat `json:"format,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
Message is the base WebSocket message structure
func NewMessage ¶
func NewMessage(msgType MessageType, payload interface{}) (*Message, error)
NewMessage creates a new message with a generated request ID
func NewResponse ¶
NewResponse creates a response message
func NewStreamChunk ¶
NewStreamChunk creates a streaming chunk message
func NewTrigger ¶
NewTrigger creates a trigger message
func (*Message) MarshalJSON ¶
MarshalJSON marshals a message to JSON bytes
func (*Message) ParseCommand ¶
func (m *Message) ParseCommand() (*CommandPayload, error)
ParseCommand extracts CommandPayload from a message
type MessageHandler ¶
MessageHandler processes incoming messages
type MessageType ¶
type MessageType string
MessageType represents the type of WebSocket message
const ( MessageTypeCommand MessageType = "command" // User voice command (client -> server) MessageTypeResponse MessageType = "response" // AI response (server -> client) MessageTypeStream MessageType = "stream" // Streaming AI response chunk (server -> client) MessageTypeAction MessageType = "action" // Action execution result (server -> client) MessageTypeStatus MessageType = "status" // System status updates (bidirectional) MessageTypeTrigger MessageType = "trigger" // PIKA-initiated interaction (server -> client) MessageTypeError MessageType = "error" // Error message (server -> client) )
type ResponseFormat ¶
type ResponseFormat string
ResponseFormat represents how the client wants responses
const ( FormatHTMX ResponseFormat = "htmx" // Return HTML partials for HTMX FormatJSON ResponseFormat = "json" // Return raw JSON FormatPush ResponseFormat = "push" // Return push notification format )
type ResponsePayload ¶
type ResponsePayload struct {
Text string `json:"text"`
Emotion string `json:"emotion,omitempty"` // helpful, curious, alert, etc.
HTML string `json:"html,omitempty"` // Pre-rendered HTML for HTMX
}
ResponsePayload is sent as AI response to user
type StatusPayload ¶
type StatusPayload struct {
Status string `json:"status"` // listening, processing, speaking, idle
Connected bool `json:"connected"` // WebSocket connection status
AIStatus string `json:"ai_status"` // ready, busy, error
}
StatusPayload for system status updates
type StreamPayload ¶
type StreamPayload struct {
Chunk string `json:"chunk"` // The text chunk
Done bool `json:"done"` // Whether streaming is complete
FullText string `json:"full_text,omitempty"` // Full text when done
}
StreamPayload is sent for streaming AI responses
type TriggerPayload ¶
type TriggerPayload struct {
TriggerType string `json:"trigger_type"` // reminder, suggestion, alert
Title string `json:"title"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
Priority string `json:"priority,omitempty"` // low, normal, high
}
TriggerPayload for PIKA-initiated interactions