Documentation
¶
Overview ¶
Package desktop provides a unified interface for desktop application frameworks. It supports Wails (Go + WebView), Tauri (Rust + WebView), and Electron (Node.js + Chromium).
This package allows Aster to be embedded in desktop applications regardless of the chosen framework, providing a consistent API for: - IPC (Inter-Process Communication) between frontend and backend - Window management - System tray integration - Native dialogs - File system access with platform-specific paths
Index ¶
- type App
- func (a *App) Bridge() Bridge
- func (a *App) GetAgent(id string) (*agent.Agent, bool)
- func (a *App) Inspector() *permission.Inspector
- func (a *App) RegisterAgent(ag *agent.Agent) error
- func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (a *App) Start(ctx context.Context) error
- func (a *App) Stop(ctx context.Context) error
- type AppConfig
- type ApprovalPayload
- type BackendResponse
- type Bridge
- type ChatPayload
- type ConfigPayload
- type ElectronBridge
- func (b *ElectronBridge) Framework() Framework
- func (b *ElectronBridge) OnMessage(handler MessageHandler)
- func (b *ElectronBridge) Port() int
- func (b *ElectronBridge) RegisterAgent(ag *agent.Agent) error
- func (b *ElectronBridge) SendEvent(event *FrontendEvent) error
- func (b *ElectronBridge) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (b *ElectronBridge) Start(ctx context.Context) error
- func (b *ElectronBridge) Stop(ctx context.Context) error
- func (b *ElectronBridge) UnregisterAgent(agentID string) error
- type EventType
- type Framework
- type FrontendEvent
- type FrontendMessage
- type MessageHandler
- type MessageType
- type TauriBridge
- func (b *TauriBridge) Framework() Framework
- func (b *TauriBridge) OnMessage(handler MessageHandler)
- func (b *TauriBridge) Port() int
- func (b *TauriBridge) RegisterAgent(ag *agent.Agent) error
- func (b *TauriBridge) SendEvent(event *FrontendEvent) error
- func (b *TauriBridge) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (b *TauriBridge) Start(ctx context.Context) error
- func (b *TauriBridge) Stop(ctx context.Context) error
- func (b *TauriBridge) UnregisterAgent(agentID string) error
- type WailsBridge
- func (b *WailsBridge) Approve(agentID, callID, decision, note string) (*BackendResponse, error)
- func (b *WailsBridge) Cancel(agentID string) (*BackendResponse, error)
- func (b *WailsBridge) Chat(agentID, message string) (*BackendResponse, error)
- func (b *WailsBridge) ClearHistory(agentID string) (*BackendResponse, error)
- func (b *WailsBridge) Framework() Framework
- func (b *WailsBridge) GetConfig() (*BackendResponse, error)
- func (b *WailsBridge) GetEvents() <-chan *FrontendEvent
- func (b *WailsBridge) GetHistory(agentID string) (*BackendResponse, error)
- func (b *WailsBridge) GetStatus(agentID string) (*BackendResponse, error)
- func (b *WailsBridge) OnMessage(handler MessageHandler)
- func (b *WailsBridge) RegisterAgent(ag *agent.Agent) error
- func (b *WailsBridge) SendEvent(event *FrontendEvent) error
- func (b *WailsBridge) SetConfig(cfg ConfigPayload) (*BackendResponse, error)
- func (b *WailsBridge) Start(ctx context.Context) error
- func (b *WailsBridge) Stop(ctx context.Context) error
- func (b *WailsBridge) UnregisterAgent(agentID string) error
- func (b *WailsBridge) WailsInit(ctx context.Context) error
- func (b *WailsBridge) WailsShutdown(ctx context.Context) error
- type WebBridge
- func (b *WebBridge) Framework() Framework
- func (b *WebBridge) OnMessage(handler MessageHandler)
- func (b *WebBridge) Port() int
- func (b *WebBridge) RegisterAgent(ag *agent.Agent) error
- func (b *WebBridge) SendEvent(event *FrontendEvent) error
- func (b *WebBridge) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (b *WebBridge) Start(ctx context.Context) error
- func (b *WebBridge) Stop(ctx context.Context) error
- func (b *WebBridge) UnregisterAgent(agentID string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App represents a desktop application instance
func (*App) Inspector ¶
func (a *App) Inspector() *permission.Inspector
Inspector returns the permission inspector
func (*App) RegisterAgent ¶
RegisterAgent registers an agent with the app
type AppConfig ¶
type AppConfig struct {
// Framework is the desktop framework to use
Framework Framework `json:"framework"`
// Port is the HTTP port for Tauri/Electron bridges (0 for auto)
Port int `json:"port,omitempty"`
// PermissionMode is the default permission mode
PermissionMode permission.Mode `json:"permission_mode,omitempty"`
// WorkDir is the default working directory
WorkDir string `json:"work_dir,omitempty"`
// DataDir is the data directory (defaults to platform-specific)
DataDir string `json:"data_dir,omitempty"`
}
AppConfig is the application configuration
type ApprovalPayload ¶
type ApprovalPayload struct {
CallID string `json:"call_id"`
Decision string `json:"decision"` // "allow", "deny", "allow_always", "deny_always"
Note string `json:"note,omitempty"`
}
ApprovalPayload is the payload for approval responses
type BackendResponse ¶
type BackendResponse struct {
// ID is the original message ID
ID string `json:"id"`
// Success indicates if the operation was successful
Success bool `json:"success"`
// Data is the response data
Data any `json:"data,omitempty"`
// Error is the error message if not successful
Error string `json:"error,omitempty"`
}
BackendResponse represents a response to the frontend
type Bridge ¶
type Bridge interface {
// Framework returns the framework type
Framework() Framework
// Start starts the bridge (may start HTTP server for Tauri/Electron)
Start(ctx context.Context) error
// Stop stops the bridge
Stop(ctx context.Context) error
// RegisterAgent registers an agent with the bridge
RegisterAgent(ag *agent.Agent) error
// UnregisterAgent unregisters an agent
UnregisterAgent(agentID string) error
// SendEvent sends an event to the frontend
SendEvent(event *FrontendEvent) error
// OnMessage sets the handler for messages from frontend
OnMessage(handler MessageHandler)
}
Bridge provides the interface between Aster and desktop frameworks. Each framework has different IPC mechanisms: - Wails: Direct Go function binding - Tauri: Rust commands with JSON-RPC style communication - Electron: IPC channels via preload scripts
type ChatPayload ¶
type ChatPayload struct {
Message string `json:"message"`
Context map[string]any `json:"context,omitempty"`
}
ChatPayload is the payload for chat messages
type ConfigPayload ¶
type ConfigPayload struct {
Provider string `json:"provider,omitempty"`
Model string `json:"model,omitempty"`
PermissionMode string `json:"permission_mode,omitempty"`
WorkDir string `json:"work_dir,omitempty"`
}
ConfigPayload is the payload for configuration
type ElectronBridge ¶
type ElectronBridge struct {
// contains filtered or unexported fields
}
ElectronBridge provides integration with Electron framework. Electron uses a local HTTP server similar to Tauri, but with additional support for Electron's IPC mechanism via WebSocket.
Communication flow: 1. Electron preload script connects to localhost:PORT via WebSocket 2. Messages are sent bidirectionally through WebSocket 3. Events are pushed from backend to frontend via WebSocket
Usage in Electron:
// In main.js
const { app, BrowserWindow } = require('electron');
const { spawn } = require('child_process');
// Start Aster backend
const asterProcess = spawn('./aster-server', ['--port', '9527']);
// In preload.js
const ws = new WebSocket('ws://localhost:9527/ws');
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
// Handle events
};
// In renderer.js
window.aster.chat(agentId, message);
func NewElectronBridge ¶
func NewElectronBridge(app *App, port int) (*ElectronBridge, error)
NewElectronBridge creates a new Electron bridge
func (*ElectronBridge) Framework ¶
func (b *ElectronBridge) Framework() Framework
Framework returns the framework type
func (*ElectronBridge) OnMessage ¶
func (b *ElectronBridge) OnMessage(handler MessageHandler)
OnMessage sets the handler for messages from frontend
func (*ElectronBridge) RegisterAgent ¶
func (b *ElectronBridge) RegisterAgent(ag *agent.Agent) error
RegisterAgent registers an agent with the bridge
func (*ElectronBridge) SendEvent ¶
func (b *ElectronBridge) SendEvent(event *FrontendEvent) error
SendEvent sends an event to all WebSocket clients
func (*ElectronBridge) ServeHTTP ¶
func (b *ElectronBridge) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler
func (*ElectronBridge) Start ¶
func (b *ElectronBridge) Start(ctx context.Context) error
Start starts the HTTP/WebSocket server
func (*ElectronBridge) Stop ¶
func (b *ElectronBridge) Stop(ctx context.Context) error
Stop stops the HTTP/WebSocket server
func (*ElectronBridge) UnregisterAgent ¶
func (b *ElectronBridge) UnregisterAgent(agentID string) error
UnregisterAgent unregisters an agent
type EventType ¶
type EventType string
EventType defines backend event types
const ( // EventTypeTextChunk is a streaming text chunk EventTypeTextChunk EventType = "text_chunk" // EventTypeToolStart indicates tool execution started EventTypeToolStart EventType = "tool_start" // EventTypeToolEnd indicates tool execution ended EventTypeToolEnd EventType = "tool_end" // EventTypeToolProgress indicates tool execution progress EventTypeToolProgress EventType = "tool_progress" // EventTypeApprovalRequired indicates approval is needed EventTypeApprovalRequired EventType = "approval_required" // EventTypeError indicates an error occurred EventTypeError EventType = "error" // EventTypeDone indicates the response is complete EventTypeDone EventType = "done" // EventTypeStatusChange indicates agent status changed EventTypeStatusChange EventType = "status_change" )
type Framework ¶
type Framework string
Framework represents the desktop framework type
const ( // FrameworkWails uses Wails (Go + WebView2/WebKit) FrameworkWails Framework = "wails" // FrameworkTauri uses Tauri (Rust + WebView2/WebKit) FrameworkTauri Framework = "tauri" // FrameworkElectron uses Electron (Node.js + Chromium) FrameworkElectron Framework = "electron" // FrameworkWeb uses standard HTTP server (for development/web deployment) FrameworkWeb Framework = "web" )
type FrontendEvent ¶
type FrontendEvent struct {
// Type is the event type
Type EventType `json:"type"`
// AgentID is the source agent ID
AgentID string `json:"agent_id,omitempty"`
// Data is the event data
Data any `json:"data"`
}
FrontendEvent represents an event sent to the frontend
type FrontendMessage ¶
type FrontendMessage struct {
// ID is the message ID for request-response correlation
ID string `json:"id"`
// Type is the message type
Type MessageType `json:"type"`
// AgentID is the target agent ID (optional)
AgentID string `json:"agent_id,omitempty"`
// Payload is the message payload
Payload json.RawMessage `json:"payload,omitempty"`
}
FrontendMessage represents a message from the frontend
type MessageHandler ¶
type MessageHandler func(msg *FrontendMessage) (*BackendResponse, error)
MessageHandler handles messages from the frontend
type MessageType ¶
type MessageType string
MessageType defines frontend message types
const ( // MsgTypeChat sends a chat message to the agent MsgTypeChat MessageType = "chat" // MsgTypeCancel cancels the current operation MsgTypeCancel MessageType = "cancel" // MsgTypeApproval responds to a permission request MsgTypeApproval MessageType = "approval" // MsgTypeGetStatus gets agent status MsgTypeGetStatus MessageType = "get_status" // MsgTypeGetHistory gets conversation history MsgTypeGetHistory MessageType = "get_history" // MsgTypeClearHistory clears conversation history MsgTypeClearHistory MessageType = "clear_history" // MsgTypeSetConfig sets agent configuration MsgTypeSetConfig MessageType = "set_config" // MsgTypeGetConfig gets current configuration MsgTypeGetConfig MessageType = "get_config" )
type TauriBridge ¶
type TauriBridge struct {
// contains filtered or unexported fields
}
TauriBridge provides integration with Tauri framework. Tauri uses a local HTTP server for IPC because the Rust backend communicates with the webview via HTTP/WebSocket.
Communication flow: 1. Tauri frontend makes HTTP requests to localhost:PORT 2. TauriBridge handles requests and returns JSON responses 3. Events are sent via Server-Sent Events (SSE) or WebSocket
Usage in Tauri:
// In Rust src-tauri/main.rs
fn main() {
// Start Aster backend (separate process or embedded)
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![...])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
// In frontend JavaScript
const response = await fetch('http://localhost:PORT/api/chat', {
method: 'POST',
body: JSON.stringify({ agent_id: 'xxx', message: 'hello' })
});
func NewTauriBridge ¶
func NewTauriBridge(app *App, port int) (*TauriBridge, error)
NewTauriBridge creates a new Tauri bridge
func (*TauriBridge) Framework ¶
func (b *TauriBridge) Framework() Framework
Framework returns the framework type
func (*TauriBridge) OnMessage ¶
func (b *TauriBridge) OnMessage(handler MessageHandler)
OnMessage sets the handler for messages from frontend
func (*TauriBridge) RegisterAgent ¶
func (b *TauriBridge) RegisterAgent(ag *agent.Agent) error
RegisterAgent registers an agent with the bridge
func (*TauriBridge) SendEvent ¶
func (b *TauriBridge) SendEvent(event *FrontendEvent) error
SendEvent sends an event to all SSE clients
func (*TauriBridge) ServeHTTP ¶
func (b *TauriBridge) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler
func (*TauriBridge) Start ¶
func (b *TauriBridge) Start(ctx context.Context) error
Start starts the HTTP server
func (*TauriBridge) Stop ¶
func (b *TauriBridge) Stop(ctx context.Context) error
Stop stops the HTTP server
func (*TauriBridge) UnregisterAgent ¶
func (b *TauriBridge) UnregisterAgent(agentID string) error
UnregisterAgent unregisters an agent
type WailsBridge ¶
type WailsBridge struct {
// contains filtered or unexported fields
}
WailsBridge provides integration with Wails framework. Wails uses direct Go function binding, making it the most efficient option for Go-based desktop applications.
Usage in Wails app:
app := desktop.NewApp(&desktop.AppConfig{Framework: desktop.FrameworkWails})
wails.Run(&options.App{
Bind: []interface{}{app.Bridge()},
})
func NewWailsBridge ¶
func NewWailsBridge(app *App) (*WailsBridge, error)
NewWailsBridge creates a new Wails bridge
func (*WailsBridge) Approve ¶
func (b *WailsBridge) Approve(agentID, callID, decision, note string) (*BackendResponse, error)
Approve responds to a permission request Exposed to Wails frontend as: window.go.desktop.WailsBridge.Approve(agentID, callID, decision, note)
func (*WailsBridge) Cancel ¶
func (b *WailsBridge) Cancel(agentID string) (*BackendResponse, error)
Cancel cancels the current operation Exposed to Wails frontend as: window.go.desktop.WailsBridge.Cancel(agentID)
func (*WailsBridge) Chat ¶
func (b *WailsBridge) Chat(agentID, message string) (*BackendResponse, error)
Chat sends a chat message to an agent Exposed to Wails frontend as: window.go.desktop.WailsBridge.Chat(agentID, message)
func (*WailsBridge) ClearHistory ¶
func (b *WailsBridge) ClearHistory(agentID string) (*BackendResponse, error)
ClearHistory clears conversation history Exposed to Wails frontend as: window.go.desktop.WailsBridge.ClearHistory(agentID)
func (*WailsBridge) Framework ¶
func (b *WailsBridge) Framework() Framework
Framework returns the framework type
func (*WailsBridge) GetConfig ¶
func (b *WailsBridge) GetConfig() (*BackendResponse, error)
GetConfig gets current configuration Exposed to Wails frontend as: window.go.desktop.WailsBridge.GetConfig()
func (*WailsBridge) GetEvents ¶
func (b *WailsBridge) GetEvents() <-chan *FrontendEvent
GetEvents returns the event channel for Wails runtime to consume Usage: Use with wails runtime.EventsEmit in a goroutine
func (*WailsBridge) GetHistory ¶
func (b *WailsBridge) GetHistory(agentID string) (*BackendResponse, error)
GetHistory gets conversation history Exposed to Wails frontend as: window.go.desktop.WailsBridge.GetHistory(agentID)
func (*WailsBridge) GetStatus ¶
func (b *WailsBridge) GetStatus(agentID string) (*BackendResponse, error)
GetStatus gets the agent status Exposed to Wails frontend as: window.go.desktop.WailsBridge.GetStatus(agentID)
func (*WailsBridge) OnMessage ¶
func (b *WailsBridge) OnMessage(handler MessageHandler)
OnMessage sets the handler for messages from frontend
func (*WailsBridge) RegisterAgent ¶
func (b *WailsBridge) RegisterAgent(ag *agent.Agent) error
RegisterAgent registers an agent with the bridge
func (*WailsBridge) SendEvent ¶
func (b *WailsBridge) SendEvent(event *FrontendEvent) error
SendEvent sends an event to the frontend In Wails, this uses runtime.EventsEmit
func (*WailsBridge) SetConfig ¶
func (b *WailsBridge) SetConfig(cfg ConfigPayload) (*BackendResponse, error)
SetConfig sets configuration Exposed to Wails frontend as: window.go.desktop.WailsBridge.SetConfig(config)
func (*WailsBridge) Start ¶
func (b *WailsBridge) Start(ctx context.Context) error
Start starts the bridge
func (*WailsBridge) Stop ¶
func (b *WailsBridge) Stop(ctx context.Context) error
Stop stops the bridge
func (*WailsBridge) UnregisterAgent ¶
func (b *WailsBridge) UnregisterAgent(agentID string) error
UnregisterAgent unregisters an agent
func (*WailsBridge) WailsInit ¶
func (b *WailsBridge) WailsInit(ctx context.Context) error
WailsInit is called by Wails during initialization
func (*WailsBridge) WailsShutdown ¶
func (b *WailsBridge) WailsShutdown(ctx context.Context) error
WailsShutdown is called by Wails during shutdown
type WebBridge ¶
type WebBridge struct {
// contains filtered or unexported fields
}
WebBridge provides a generic HTTP-based bridge for web deployments and development. It uses REST API + SSE for communication.
This bridge can be used: - For development without a desktop framework - For web-based deployments - As a base for custom integrations
func NewWebBridge ¶
NewWebBridge creates a new web bridge
func (*WebBridge) OnMessage ¶
func (b *WebBridge) OnMessage(handler MessageHandler)
OnMessage sets the handler for messages from frontend
func (*WebBridge) RegisterAgent ¶
RegisterAgent registers an agent with the bridge
func (*WebBridge) SendEvent ¶
func (b *WebBridge) SendEvent(event *FrontendEvent) error
SendEvent sends an event to all SSE clients
func (*WebBridge) ServeHTTP ¶
func (b *WebBridge) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler
func (*WebBridge) UnregisterAgent ¶
UnregisterAgent unregisters an agent