daemon

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package daemon provides a Telegram gateway for hawk. Allows users to interact with hawk via Telegram bot messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatRequest

type ChatRequest struct {
	Prompt    string `json:"prompt"`
	SessionID string `json:"session_id,omitempty"`
	Model     string `json:"model,omitempty"`
	MaxTurns  int    `json:"max_turns,omitempty"`
	Autonomy  string `json:"autonomy,omitempty"`
	CWD       string `json:"cwd,omitempty"`
	Agent     string `json:"agent,omitempty"`
}

ChatRequest is the JSON body for POST /v1/chat.

type ChatResponse

type ChatResponse struct {
	SessionID  string `json:"session_id"`
	Response   string `json:"response"`
	TokensIn   int    `json:"tokens_in"`
	TokensOut  int    `json:"tokens_out"`
	TurnsTaken int    `json:"turns_taken"`
	Duration   string `json:"duration"`
}

ChatResponse is the JSON response from POST /v1/chat.

type Config

type Config struct {
	Port    int    `json:"port"`
	Host    string `json:"host"`
	LogFile string `json:"log_file"`
}

Config holds daemon configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns reasonable defaults.

type ErrorResponse added in v0.2.0

type ErrorResponse struct {
	Error   string `json:"error"`
	Code    string `json:"code,omitempty"`
	Details string `json:"details,omitempty"`
}

ErrorResponse is the standard error envelope.

type HealthResponse

type HealthResponse struct {
	Status    string `json:"status"`
	Version   string `json:"version"`
	Uptime    string `json:"uptime"`
	Sessions  int    `json:"active_sessions"`
	StartedAt string `json:"started_at"`
}

HealthResponse is the JSON response from GET /v1/health.

type MessageResponse added in v0.2.0

type MessageResponse struct {
	Role       string      `json:"role"`
	Content    string      `json:"content,omitempty"`
	ToolUse    interface{} `json:"tool_use,omitempty"`
	ToolResult interface{} `json:"tool_result,omitempty"`
}

MessageResponse is a message in GET /v1/sessions/{id}/messages.

type ModelStatResp added in v0.2.0

type ModelStatResp struct {
	Model    string  `json:"model"`
	Requests int     `json:"requests"`
	CostUSD  float64 `json:"cost_usd"`
}

ModelStatResp is per-model statistics within StatsResponse.

type PaginatedResponse added in v0.2.0

type PaginatedResponse struct {
	Data    interface{} `json:"data"`
	Total   int         `json:"total"`
	Offset  int         `json:"offset"`
	Limit   int         `json:"limit"`
	HasMore bool        `json:"has_more"`
}

PaginatedResponse wraps paginated list results.

type Preheater added in v0.2.0

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

Preheater maintains warm connections and pre-initialized state to eliminate cold-start latency on first request.

func NewPreheater added in v0.2.0

func NewPreheater(interval time.Duration) *Preheater

NewPreheater creates a preheater with the given warmup interval.

func (*Preheater) Ready added in v0.2.0

func (p *Preheater) Ready() bool

Ready reports whether the preheater has completed at least one warmup cycle.

func (*Preheater) Start added in v0.2.0

func (p *Preheater) Start(endpoints []string)

Start begins background warmup. Call Stop() to clean up.

func (*Preheater) Stop added in v0.2.0

func (p *Preheater) Stop()

Stop terminates the background warmup goroutine.

func (*Preheater) Transport added in v0.2.0

func (p *Preheater) Transport() *http.Transport

Transport returns the pre-warmed HTTP transport for reuse.

type Server

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

Server is the hawk daemon HTTP server for programmatic/CI access.

func New

func New(cfg Config, factory SessionFactory) *Server

New creates a new daemon server. If factory is nil, chat endpoint returns an error.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the listening address.

func (*Server) Start

func (s *Server) Start() (string, error)

Start begins serving in the background. Returns the listening address.

func (*Server) Stop

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

Stop gracefully shuts down the daemon.

type Session

type Session struct {
	ID        string    `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	LastUsed  time.Time `json:"last_used"`
	Turns     int       `json:"turns"`
	CWD       string    `json:"cwd"`
}

Session tracks an active daemon session.

type SessionDetailResponse added in v0.2.0

type SessionDetailResponse struct {
	ID           string    `json:"id"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
	Model        string    `json:"model"`
	Provider     string    `json:"provider"`
	CWD          string    `json:"cwd"`
	Name         string    `json:"name"`
	MessageCount int       `json:"message_count"`
	ToolCalls    int       `json:"tool_calls"`
}

SessionDetailResponse is the response for GET /v1/sessions/{id}.

type SessionFactory

type SessionFactory func(req ChatRequest) (*engine.Session, error)

SessionFactory creates a configured engine session for a given request. The caller (cmd package) provides this, wiring system prompts, tools, keys.

type StatsResponse added in v0.2.0

type StatsResponse struct {
	TotalSessions  int             `json:"total_sessions"`
	TotalMessages  int             `json:"total_messages"`
	TotalToolCalls int             `json:"total_tool_calls"`
	TotalCostUSD   float64         `json:"total_cost_usd"`
	ActiveDays     int             `json:"active_days"`
	Models         []ModelStatResp `json:"models"`
}

StatsResponse is the response for GET /v1/stats.

type TelegramGateway added in v0.2.0

type TelegramGateway struct {
	Token      string
	DaemonAddr string // hawk daemon address to forward messages to
	// contains filtered or unexported fields
}

TelegramGateway connects hawk to a Telegram bot.

func NewTelegramGateway added in v0.2.0

func NewTelegramGateway(token, daemonAddr string) *TelegramGateway

NewTelegramGateway creates a gateway with the given bot token.

func (*TelegramGateway) Run added in v0.2.0

func (tg *TelegramGateway) Run(ctx context.Context) error

Run starts the long-polling loop. Blocks until context is cancelled.

type TelegramMessage added in v0.2.0

type TelegramMessage struct {
	MessageID int    `json:"message_id"`
	Text      string `json:"text"`
	Chat      struct {
		ID int64 `json:"id"`
	} `json:"chat"`
	From struct {
		Username string `json:"username"`
	} `json:"from"`
}

TelegramMessage is a Telegram chat message.

type TelegramUpdate added in v0.2.0

type TelegramUpdate struct {
	UpdateID int              `json:"update_id"`
	Message  *TelegramMessage `json:"message,omitempty"`
}

TelegramUpdate represents an incoming Telegram message.

Jump to

Keyboard shortcuts

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