From bda6aae82d936027196e35dc71b378ab21d874f2 Mon Sep 17 00:00:00 2001 From: Awuqing <3184394176@qq.com> Date: Sun, 19 Apr 2026 16:27:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD:=20AgentService=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20SelfStatus=20=E7=94=A8=E4=BA=8E=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E6=8E=A2=E6=B4=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/internal/service/agent_service.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/server/internal/service/agent_service.go b/server/internal/service/agent_service.go index 17e74b5..4b5510f 100644 --- a/server/internal/service/agent_service.go +++ b/server/internal/service/agent_service.go @@ -346,3 +346,24 @@ func (s *AgentService) StartCommandTimeoutMonitor(ctx context.Context, interval } }() } + +// AgentSelfStatus 是 /api/v1/agent/self 端点返回给 Agent 的轻量状态摘要。 +type AgentSelfStatus struct { + ID uint `json:"id"` + Name string `json:"name"` + Status string `json:"status"` + LastSeen time.Time `json:"lastSeen"` +} + +// SelfStatus 返回 Agent token 所属节点的当前状态,供安装脚本末尾探活。 +func (s *AgentService) SelfStatus(ctx context.Context, node *model.Node) (*AgentSelfStatus, error) { + if node == nil { + return nil, apperror.Unauthorized("NODE_INVALID_TOKEN", "节点不存在", nil) + } + return &AgentSelfStatus{ + ID: node.ID, + Name: node.Name, + Status: node.Status, + LastSeen: node.LastSeen, + }, nil +}