agent

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomID

func GenerateRandomID(prefix string) string

Types

type AddressProbeResult

type AddressProbeResult struct {
	URL       string `json:"url"`
	Tag       string `json:"tag"`
	Reachable bool   `json:"reachable"`
	LatencyMs int    `json:"latency_ms"`
	Error     string `json:"error"`
}

type AgentDetailResponse

type AgentDetailResponse struct {
	models.Agent
	Runtime                 *RuntimeInfo `json:"runtime"`
	ConfiguredHTTPAddresses string       `json:"configured_http_addresses,omitempty"`
	EffectiveHTTPAddresses  string       `json:"effective_http_addresses,omitempty"`
}

type AgentIDQuery added in v0.0.4

type AgentIDQuery struct {
	ID string `form:"id" binding:"required"`
}

AgentIDQuery uses ?id= query parameter (no dynamic route segment per project convention).

type AgentResponse

type AgentResponse struct {
	ID                      uint   `json:"id"`
	AgentID                 string `json:"agent_id"`
	Name                    string `json:"name"`
	Status                  int    `json:"status"`
	LastSeen                int64  `json:"last_seen"`
	CreatedAt               int64  `json:"created_at"`
	HTTPAddresses           string `json:"http_addresses,omitempty"`            // Legacy: effective addresses
	ConfiguredHTTPAddresses string `json:"configured_http_addresses,omitempty"` // DB-configured addresses
	EffectiveHTTPAddresses  string `json:"effective_http_addresses,omitempty"`  // Merged effective addresses
	Tags                    string `json:"tags"`
}

type AllInflightResponse added in v0.0.6

type AllInflightResponse struct {
	Requests     []GlobalInflightRow `json:"requests"`
	FailedAgents []FailedAgent       `json:"failed_agents"`
}

AllInflightResponse 是 GetAllInflight 的响应体。

type ConnectivityReport

type ConnectivityReport struct {
	AgentID   string               `json:"agent_id"`
	CheckedAt int64                `json:"checked_at"`
	Results   []ConnectivityResult `json:"results"`
}

type ConnectivityRequest

type ConnectivityRequest struct {
	ID string `uri:"id" binding:"required"`
}

type ConnectivityResult

type ConnectivityResult struct {
	TargetAgentID string               `json:"target_agent_id"`
	TargetName    string               `json:"target_name"`
	Results       []AddressProbeResult `json:"results"`
}

type CreateRequest

type CreateRequest struct {
	AgentID       string `json:"agent_id"`
	Secret        string `json:"secret"`
	Name          string `json:"name" binding:"required"`
	HTTPAddresses string `json:"http_addresses"`
	Tags          string `json:"tags"`
	ProxyURL      string `json:"proxy_url"`
}

type DetailRequest

type DetailRequest struct {
	ID string `uri:"id" binding:"required"`
}

type EnrollRequest

type EnrollRequest struct {
	EnrollmentToken string `json:"enrollment_token" binding:"required"`
	Name            string `json:"name"`
}

type EnrollResponse

type EnrollResponse struct {
	AgentID string `json:"agent_id"`
	Secret  string `json:"secret"`
}

type FailedAgent added in v0.0.6

type FailedAgent struct {
	AgentID   uint   `json:"agent_id"`
	AgentName string `json:"agent_name"`
	Error     string `json:"error"`
}

FailedAgent 记录某节点拉取失败的原因。

type FullSyncRequest

type FullSyncRequest struct {
	AgentIDs []string `json:"agent_ids"`
	All      bool     `json:"all"`
}

type FullSyncResponse

type FullSyncResponse struct {
	Results []FullSyncResult `json:"results"`
}

type FullSyncResult

type FullSyncResult struct {
	AgentID    string `json:"agent_id"`
	Success    bool   `json:"success"`
	Version    int64  `json:"version,omitempty"`
	DurationMs int64  `json:"duration_ms,omitempty"`
	Error      string `json:"error,omitempty"`
}

type GenerateEnrollmentTokenRequest

type GenerateEnrollmentTokenRequest struct {
	TTL int64 `json:"ttl"`
}

type GenerateEnrollmentTokenResponse

type GenerateEnrollmentTokenResponse struct {
	EnrollmentToken string `json:"enrollment_token"`
	ExpiresAt       int64  `json:"expires_at"`
}

type GlobalInflightRow added in v0.0.6

type GlobalInflightRow struct {
	inflight.Snapshot
	AgentID   uint   `json:"agent_id"`
	AgentName string `json:"agent_name"`
}

GlobalInflightRow 是单条在途请求,附带节点标识。

type Handler

type Handler struct {
	GetOnlineAgentIDs func() []string
	GetRuntime        func(agentID string) *msync.AgentRuntime
	HubCall           func(agentID string, method string, params any, timeout time.Duration) (json.RawMessage, error)
	Hub               *msync.Hub // 用于获取合并后的地址
}

func (*Handler) CheckConnectivity

func (h *Handler) CheckConnectivity(c *app.Context, req ConnectivityRequest) (ConnectivityReport, error)

func (*Handler) Create

func (h *Handler) Create(c *app.Context, req CreateRequest) (api.Created[models.Agent], error)

func (*Handler) Delete

func (h *Handler) Delete(c *app.Context, req api.IDPathRequest) (api.StatusResponse, error)

func (*Handler) Detail

func (h *Handler) Detail(c *app.Context, req DetailRequest) (AgentDetailResponse, error)

func (*Handler) Enroll

func (*Handler) FullSync

func (h *Handler) FullSync(c *app.Context, req FullSyncRequest) (FullSyncResponse, error)

func (*Handler) Get

func (h *Handler) Get(c *app.Context, req api.IDPathRequest) (models.Agent, error)

func (*Handler) GetAllInflight added in v0.0.6

func (h *Handler) GetAllInflight(c *app.Context, _ api.EmptyRequest) (AllInflightResponse, error)

GetAllInflight 并发拉取所有在线节点的 agent.inflight,合并成扁平列表; 某节点出错/超时进 failed_agents,不阻塞其余节点。

func (*Handler) GetConnectivity

func (h *Handler) GetConnectivity(c *app.Context, req ConnectivityRequest) (*ConnectivityReport, error)

func (*Handler) GetGoroutines added in v0.0.4

func (h *Handler) GetGoroutines(c *app.Context, req AgentIDQuery) (json.RawMessage, error)

GetGoroutines fetches a goroutine dump from a remote agent (admin only).

func (*Handler) GetInflight added in v0.0.4

func (h *Handler) GetInflight(c *app.Context, req AgentIDQuery) (json.RawMessage, error)

GetInflight fetches the in-flight request snapshot from a remote agent.

func (*Handler) Interrupt added in v0.0.6

func (h *Handler) Interrupt(c *app.Context, req InterruptRequest) (InterruptResponse, error)

Interrupt 把打断指令转发给目标节点的 agent.interrupt RPC。

func (*Handler) List

func (*Handler) Online

func (h *Handler) Online(c *app.Context, _ api.EmptyRequest) ([]OnlineAgentInfo, error)

func (*Handler) Update

func (h *Handler) Update(c *app.Context, req UpdateRequest) (models.Agent, error)

type InterruptRequest added in v0.0.6

type InterruptRequest struct {
	AgentID uint  `json:"agent_id" binding:"required"`
	ID      int64 `json:"id" binding:"required"`
}

InterruptRequest 指定要打断的节点 DB id 和在途请求 id。

type InterruptResponse added in v0.0.6

type InterruptResponse struct {
	Interrupted bool `json:"interrupted"`
}

InterruptResponse 反映打断是否成功。

type ListRequest

type ListRequest struct {
	api.PaginationQuery
	Search string `form:"search"`
	Status string `form:"status"`
}

type OnlineAgentInfo

type OnlineAgentInfo struct {
	AgentID                 string `json:"agent_id"`
	Name                    string `json:"name"`
	Tags                    string `json:"tags"`
	HTTPAddresses           string `json:"http_addresses,omitempty"`            // Legacy: effective addresses
	ConfiguredHTTPAddresses string `json:"configured_http_addresses,omitempty"` // DB-configured addresses
	EffectiveHTTPAddresses  string `json:"effective_http_addresses,omitempty"`  // Merged effective addresses
	LastSeen                int64  `json:"last_seen"`
}

type RuntimeInfo

type RuntimeInfo struct {
	Uptime            int64                                `json:"uptime"`
	CachedTokens      int                                  `json:"cached_tokens"`
	CachedChannels    int                                  `json:"cached_channels"`
	CachedModels      int                                  `json:"cached_models"`
	ActiveConnections int                                  `json:"active_connections"`
	Version           int64                                `json:"version"`
	MasterVersion     int64                                `json:"master_version"`
	CacheStats        map[string]protocol.CacheEntityStats `json:"cache_stats,omitempty"`
}

type UpdateRequest

type UpdateRequest struct {
	ID     string         `uri:"id" binding:"required"`
	Fields map[string]any `json:"-"`
}

func (*UpdateRequest) SetBodyMap

func (r *UpdateRequest) SetBodyMap(fields map[string]any)

Jump to

Keyboard shortcuts

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