agent

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 26 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 AgentDetailResponse

type AgentDetailResponse struct {
	models.Agent
	Runtime                 *RuntimeInfo                    `json:"runtime"`
	Connection              connectivity.ConnectionSnapshot `json:"connection"`
	RouteTargets            connectivity.RouteTargetsPage   `json:"route_targets"`
	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 AgentOperationRequest added in v0.0.13

type AgentOperationRequest struct {
	ID     string `uri:"id" binding:"required"`
	Action string `uri:"operation" binding:"required"`
	protocol.OperationRequest
}

type AgentOperationResponse added in v0.0.13

type AgentOperationResponse struct {
	protocol.OperationAck
}

func (AgentOperationResponse) StatusCode added in v0.0.13

func (AgentOperationResponse) StatusCode() int

type AgentPatch added in v0.0.13

type AgentPatch struct {
	Name                  *string `json:"name"`
	Status                *int    `json:"status"`
	Tags                  *string `json:"tags"`
	HTTPAddresses         *string `json:"http_addresses"`
	ProxyURL              *string `json:"proxy_url"`
	RelayMode             *string `json:"relay_mode"`
	RelayURI              *string `json:"relay_uri"`
	DirectInboundEnabled  *bool   `json:"direct_inbound_enabled"`
	DirectOutboundEnabled *bool   `json:"direct_outbound_enabled"`
	RelayInboundEnabled   *bool   `json:"relay_inbound_enabled"`
	RelayOutboundEnabled  *bool   `json:"relay_outbound_enabled"`
}

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"`
	ProxyURL                string                         `json:"proxy_url"`
	RelayMode               string                         `json:"relay_mode"`
	DirectInboundEnabled    bool                           `json:"direct_inbound_enabled"`
	DirectOutboundEnabled   bool                           `json:"direct_outbound_enabled"`
	RelayInboundEnabled     bool                           `json:"relay_inbound_enabled"`
	RelayOutboundEnabled    bool                           `json:"relay_outbound_enabled"`
	Connection              connectivity.ConnectionSummary `json:"connection"`
}

type AllInflightResponse added in v0.0.6

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

AllInflightResponse 是 GetAllInflight 的响应体。

type ConnectionDiagnosticsResponse added in v0.0.13

type ConnectionDiagnosticsResponse struct {
	SnapshotEpoch string                                `json:"snapshot_epoch"`
	SnapshotSeq   uint64                                `json:"snapshot_seq"`
	ObservedAt    int64                                 `json:"observed_at"`
	Control       ControlDiagnostics                    `json:"control"`
	Relay         RelayDiagnostics                      `json:"relay"`
	Direct        DirectDiagnostics                     `json:"direct"`
	RouteFailures []connectivity.RouteFailureDiagnostic `json:"route_failures"`
}

type ConnectivityProgressRequest added in v0.0.13

type ConnectivityProgressRequest struct {
	ID      string `uri:"id" binding:"required"`
	ProbeID string `form:"probe_id"`
}

type ConnectivityRequest

type ConnectivityRequest struct {
	ID                        string              `uri:"id" binding:"required"`
	Scope                     protocol.ProbeScope `json:"scope"`
	ExpectedEpoch             string              `json:"expected_epoch"`
	ExpectedControlGeneration uint64              `json:"expected_control_generation,omitempty"`
	ExpectedRelayGeneration   uint64              `json:"expected_relay_generation,omitempty"`
}

type ControlDiagnostics added in v0.0.13

type ControlDiagnostics struct {
	State             string                     `json:"state"`
	Health            string                     `json:"health"`
	ReasonCodes       []string                   `json:"reason_codes"`
	SessionGeneration uint64                     `json:"session_generation"`
	ConnectedAt       int64                      `json:"connected_at"`
	HeartbeatAt       int64                      `json:"heartbeat_at"`
	RuntimeReportedAt int64                      `json:"runtime_reported_at"`
	LastSeen          int64                      `json:"last_seen"`
	RecentErrors      []connectivity.RecentError `json:"recent_errors"`
}

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"`
	RelayMode             string `json:"relay_mode"`
	RelayURI              string `json:"relay_uri"`
	DirectInboundEnabled  *bool  `json:"direct_inbound_enabled"`
	DirectOutboundEnabled *bool  `json:"direct_outbound_enabled"`
	RelayInboundEnabled   *bool  `json:"relay_inbound_enabled"`
	RelayOutboundEnabled  *bool  `json:"relay_outbound_enabled"`
}

type DetailRequest

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

type DiagnosticsRequest added in v0.0.13

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

type DirectDiagnostics added in v0.0.13

type DirectDiagnostics struct {
	Summary      connectivity.DirectSummary `json:"summary"`
	RecentErrors []connectivity.RecentError `json:"recent_errors"`
}

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
	RevokeControlSession func(agentID string) bool
	GetProbeProgress     func(sourceID, probeID string) (protocol.ManualProbeProgress, bool)
	Connections          *connectivity.Service
	ControlSessions      connectivity.ControlSource
	Operations           *masteroperations.Service
	HubCallSession       func(agentID string, generation uint64, method string, params any, timeout time.Duration) (json.RawMessage, error)
	Hub                  *msync.Hub // 用于获取合并后的地址
	Now                  func() time.Time
	// contains filtered or unexported fields
}

func (*Handler) CheckConnectivity

func (h *Handler) CheckConnectivity(c *app.Context, req ConnectivityRequest) (api.Accepted[ProbeAck], error)

behavior change: POST enqueues the scheduler-backed probe and returns its full acknowledgement.

func (*Handler) ConnectionDiagnostics added in v0.0.13

func (h *Handler) ConnectionDiagnostics(c *app.Context, req DiagnosticsRequest) (ConnectionDiagnosticsResponse, 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 (*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) Operation added in v0.0.13

func (*Handler) RouteTargets added in v0.0.13

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 ManualProbeProgress added in v0.0.13

type ManualProbeProgress = protocol.ManualProbeProgress

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"`
	PendingUsage            int                            `json:"pending_usage"` // admin-only,见 pendingFromRuntime
	Connection              connectivity.ConnectionSummary `json:"connection"`
}

type ProbeAck added in v0.0.13

type ProbeAck = protocol.ProbeAck

type RelayDiagnostics added in v0.0.13

type RelayDiagnostics struct {
	Support             string                            `json:"support"`
	Config              string                            `json:"config"`
	Availability        string                            `json:"availability"`
	AcceptingNewStreams bool                              `json:"accepting_new_streams"`
	Convergence         string                            `json:"convergence"`
	Desired             connectivity.RelayDesiredSnapshot `json:"desired"`
	Active              connectivity.RelayActiveSnapshot  `json:"active"`
	RecentErrors        []connectivity.RecentError        `json:"recent_errors"`
}

type RouteTargetsRequest added in v0.0.13

type RouteTargetsRequest struct {
	ID                    string `uri:"id" binding:"required"`
	Cursor                string `form:"cursor"`
	Limit                 int    `form:"limit"`
	ExpectedSnapshotEpoch string `form:"expected_snapshot_epoch"`
	ExpectedSnapshotSeq   uint64 `form:"expected_snapshot_seq"`
}

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"`
	PendingUsage      int                                  `json:"pending_usage"`
	CacheStats        map[string]protocol.CacheEntityStats `json:"cache_stats,omitempty"`
}

type UpdateRequest

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

Jump to

Keyboard shortcuts

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