api

package
v0.0.0-...-3b57c73 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventTypeMessage     = "message"
	EventTypeStatus      = "status"
	EventTypeTitle       = "title"
	EventTypeArtifact    = "artifact"
	EventTypeDone        = "done"
	EventTypeResync      = "resync"
	EventTypeAuthExpired = "auth_expired"
)

Variables

View Source
var ErrServerShutdownBeforeStart = errors.New("server shut down before start completed")

ErrServerShutdownBeforeStart is returned by Start when Shutdown was called before or during Start.

Functions

func CheckPushNotificationSetup

func CheckPushNotificationSetup()

func IsValidChatID

func IsValidChatID(chatID string) bool

IsValidChatID checks whether chatID is non-empty, matches regex rules, and is within maximum length (64 chars).

Types

type AgentInfo

type AgentInfo struct {
	ID          string   `json:"id"`
	Type        string   `json:"type"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Icon        string   `json:"icon"`
	RunDirs     []string `json:"run_dirs"`
	MainAgent   bool     `json:"main_agent"`
	Models      []string `json:"models"`
}

AgentInfo holds details about an agent for the frontend UI.

type AgentStatusUpdate

type AgentStatusUpdate = workflow.AgentStatusUpdate

AgentStatusUpdate is the JSON payload posted by aw to the internal status endpoint whenever the agent produces an incremental transcript update.

type AskUserReplyRequest

type AskUserReplyRequest struct {
	ChatID    string `json:"chat_id"`
	MessageID string `json:"message_id"`
	ReplyText string `json:"reply_text"`
}

type AskUserRequest

type AskUserRequest struct {
	ChatID    string `json:"chat_id"`
	AgentName string `json:"agent_name"`
	Question  string `json:"question"`
	MessageID string `json:"message_id"`
}

type AskUserResponse

type AskUserResponse struct {
	Reply string `json:"reply"`
	Error string `json:"error,omitempty"`
}

type ChatSession

type ChatSession struct {
	ChatID       string             `json:"chatID"`
	Title        string             `json:"title"`
	CurrentAgent string             `json:"currentAgent"`
	RunDir       string             `json:"runDir"`
	GitRoot      string             `json:"gitRoot,omitempty"`
	IsRunning    bool               `json:"isRunning"`
	Messages     dbmodels.Messages  `json:"messages,omitempty"`
	Artifacts    dbmodels.Artifacts `json:"artifacts,omitempty"`
}

ChatSession represents a session response/request payload for the WebUI.

type ConfigResponse

type ConfigResponse struct {
	FirebaseWebpushWeb *config.FirebaseWebpushWebConfig `json:"firebase_webpush_web,omitempty"`
}

ConfigResponse represents the public configuration sent to web clients.

type CreateSessionRequest

type CreateSessionRequest struct {
	CurrentAgent string `json:"currentAgent"`
	RunDir       string `json:"runDir"`
}

type FileContentResponse

type FileContentResponse struct {
	Path      string    `json:"path"`
	Name      string    `json:"name"`
	Ext       string    `json:"ext"`
	Size      int64     `json:"size"`
	Content   string    `json:"content"`
	IsBinary  bool      `json:"isBinary,omitempty"`
	UpdatedAt time.Time `json:"updatedAt"`
}

type FileSearchResponse

type FileSearchResponse struct {
	Files []FileSearchResult `json:"files"`
}

type FileSearchResult

type FileSearchResult struct {
	Path string `json:"path"` // relative to session runDir
	Name string `json:"name"`
	Ext  string `json:"ext"`
	Size int64  `json:"size"`
}

type FileTreeEntry

type FileTreeEntry struct {
	Name  string `json:"name"`
	Path  string `json:"path"` // relative to session runDir
	IsDir bool   `json:"isDir"`
	Size  int64  `json:"size,omitempty"`
	Ext   string `json:"ext,omitempty"`
}

type FileTreeResponse

type FileTreeResponse struct {
	Entries []FileTreeEntry `json:"entries"`
	Path    string          `json:"path"`
}

type GitActionRequest

type GitActionRequest struct {
	SessionID string `json:"session_id"`
}

GitActionRequest is the request payload for git actions like push/pull.

type GitActionResponse

type GitActionResponse struct {
	Success bool   `json:"success"`
	Output  string `json:"output,omitempty"`
	Error   string `json:"error,omitempty"`
}

GitActionResponse is the response payload for git push/pull.

type GitCommit

type GitCommit struct {
	Hash         string `json:"hash"`
	ShortHash    string `json:"shortHash"`
	Author       string `json:"author"`
	AuthorEmail  string `json:"authorEmail"`
	Date         string `json:"date"`
	RelativeDate string `json:"relativeDate"`
	Refs         string `json:"refs"`
	Message      string `json:"message"`
}

GitCommit represents a commit entry in git log.

type GitDiffFile

type GitDiffFile struct {
	OldPath    string   `json:"oldPath"`
	NewPath    string   `json:"newPath"`
	Status     string   `json:"status"` // "A" | "M" | "D" | "R"
	OldContent string   `json:"oldContent"`
	NewContent string   `json:"newContent"`
	Hunks      []string `json:"hunks"`
}

GitDiffFile holds the before/after content and raw unified-diff hunks for one file.

type GitDiffResponse

type GitDiffResponse struct {
	Files []GitDiffFile `json:"files"`
}

GitDiffResponse is the response payload for GET /api/git/diff.

type GitLogResponse

type GitLogResponse struct {
	Commits        []GitCommit `json:"commits"`
	CurrentBranch  string      `json:"currentBranch"`
	TrackingBranch string      `json:"trackingBranch"`
	Ahead          int         `json:"ahead"`
	Behind         int         `json:"behind"`
	UnstashedCount int         `json:"unstashedCount"`
}

GitLogResponse is the response payload for GET /api/git/log.

type RegisterPushTokenRequest

type RegisterPushTokenRequest struct {
	Token string `json:"token"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server manages the HTTP server hosting agents.

func New

func New(conf *config.Config, dbConn *gorm.DB, opts ...ServerOption) (*Server, error)

New creates a new Server instance, loading all agents from the configured directory.

func (*Server) AddStatusListener

func (s *Server) AddStatusListener(chatID string, match func(workflow.AgentStatusUpdate) bool) (<-chan workflow.AgentStatusUpdate, func())

AddStatusListener registers a buffered channel that will receive AgentStatusUpdate events for the given chatID. match, when non-nil, filters which updates are delivered (e.g. by RunToken so parallel workflow nodes only receive their own updates). The returned cancel function must be called to deregister the channel and free resources.

func (*Server) Context

func (s *Server) Context() context.Context

Context returns the Server's root context (canceled on shutdown).

func (*Server) EventHub

func (s *Server) EventHub() *SessionEventHub

EventHub returns the Server's SessionEventHub instance.

func (*Server) PublishSessionEvent

func (s *Server) PublishSessionEvent(chatID string, ev SessionEvent)

PublishSessionEvent broadcasts a session event if the event hub is initialized.

func (*Server) SendPushNotification

func (s *Server) SendPushNotification(chatID string, questionText string, agentName string)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP delegates HTTP requests to the current active ServeMux, adding CORS support.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully stops the HTTP servers and the event hub. It is idempotent: only the first invocation performs the shutdown; subsequent calls return the cached result without side effects.

func (*Server) Start

func (s *Server) Start() error

Start starts the public HTTP server and an internal-only loopback HTTP server for agent status callbacks. Both shut down gracefully on SIGINT/SIGTERM or when the Server's root context is canceled.

type ServerOption

type ServerOption func(*Server)

ServerOption mutates a Server during construction (functional options).

func WithCustomRunners

func WithCustomRunners(runners ...workflow.NodeRunner) ServerOption

WithCustomRunners injects multiple custom NodeRunners.

func WithFunction

func WithFunction(name string, fn workflow.WorkflowFunction) ServerOption

WithFunction injects a single Go-native function into the Server's registry. The registry is lazily created with the process-wide default registry as parent so globally registered functions remain resolvable.

func WithFunctionRegistry

func WithFunctionRegistry(reg *workflow.FunctionRegistry) ServerOption

WithFunctionRegistry replaces the Server's workflow function registry.

func WithNodeRunner

func WithNodeRunner(runner workflow.NodeRunner) ServerOption

WithNodeRunner injects a single custom NodeRunner, replacing the default runner for every NodeType it supports.

type SessionEvent

type SessionEvent struct {
	EventID   int64                 `json:"eventId"`
	ChatID    string                `json:"chatId"`
	Type      string                `json:"type"` // message | status | title | artifact | done | resync | auth_expired
	Message   *dbmodels.ChatMessage `json:"message,omitempty"`
	Payload   map[string]any        `json:"payload,omitempty"`
	Timestamp int64                 `json:"timestamp"`
}

SessionEvent is the unified event structure broadcasted via EventHub and SSE.

type SessionEventHub

type SessionEventHub struct {
	// contains filtered or unexported fields
}

SessionEventHub manages per-chat event publishing and SSE subscriptions.

func NewSessionEventHub

func NewSessionEventHub() *SessionEventHub

NewSessionEventHub creates a new SessionEventHub instance with background topic GC.

func NewSessionEventHubWithCapacity

func NewSessionEventHubWithCapacity(capacity int) *SessionEventHub

NewSessionEventHubWithCapacity creates a new SessionEventHub with custom ring buffer capacity.

func (*SessionEventHub) Close

func (h *SessionEventHub) Close()

Close gracefully stops the background GC ticker and closes all active subscriber connections.

func (*SessionEventHub) Publish

func (h *SessionEventHub) Publish(chatID string, ev SessionEvent)

Publish broadcasts an event to the specified chat's topic.

func (*SessionEventHub) Subscribe

func (h *SessionEventHub) Subscribe(chatID string, lastEventID int64) (<-chan SessionEvent, <-chan struct{}, func())

Subscribe registers a listener on the chat's event stream. If lastEventID > 0, missed events are replayed. If requested lastEventID was evicted from the ring buffer, or the topic is empty (e.g. after GC), a resync event is sent immediately. Returns the event channel, a done channel closed when the subscriber is disconnected, and a cancel function.

type SingleAgentExecutor

type SingleAgentExecutor struct {
	// contains filtered or unexported fields
}

SingleAgentExecutor handles responding to and processing single-agent tasks.

func NewSingleAgentExecutor

func NewSingleAgentExecutor(agent *agents.Agent, conf *config.Config, repo *dbmodels.SessionRepository, server *Server, llmClient llm.Client) *SingleAgentExecutor

NewSingleAgentExecutor creates a SingleAgentExecutor for the given agent. llmClient may be nil; in that case a genai-backed client is created lazily for session title generation using the configured (or env) API key.

func (*SingleAgentExecutor) Execute

Execute handles the agent execution.

type SingleAgentRunParams

type SingleAgentRunParams struct {
	ChatID   string
	Prompt   string
	RunDir   string
	Model    string
	Metadata map[string]any
}

SingleAgentRunParams carries the parameters for a single agent execution.

type SubdirsResponse

type SubdirsResponse struct {
	Subdirs []string `json:"subdirs"`
	GitRoot string   `json:"git_root,omitempty"`
}

SubdirsResponse represents the response payload for listing subdirectories.

type TriggerMessageRequest

type TriggerMessageRequest struct {
	Prompt   string `json:"prompt"`
	ChatID   string `json:"chatId,omitempty"`
	RunDir   string `json:"runDir,omitempty"`
	Model    string `json:"model,omitempty"`
	Wait     bool   `json:"wait,omitempty"`
	Headless bool   `json:"-"`

	Metadata map[string]any `json:"metadata,omitempty"`
}

TriggerMessageRequest represents the payload for POST /api/agents/{id}/message.

type WorkspaceFileResponse

type WorkspaceFileResponse struct {
	Path      string    `json:"path"`
	Name      string    `json:"name"`
	Ext       string    `json:"ext"`
	Size      int64     `json:"size"`
	Content   string    `json:"content"`
	UpdatedAt time.Time `json:"updatedAt"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL