package com.company.agentfoundation.agent; import com.company.agentfoundation.security.AgentAuthService; import jakarta.validation.Valid; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/v1/agent") public class AgentRuntimeController { private final AgentAuthService authService; private final AgentOrchestratorService agentOrchestratorService; public AgentRuntimeController(AgentAuthService authService, AgentOrchestratorService agentOrchestratorService) { this.authService = authService; this.agentOrchestratorService = agentOrchestratorService; } @PostMapping("/messages") public ResponseEntity handleMessage( @RequestHeader("X-Agent-Id") String agentId, @RequestHeader("X-Internal-Key") String internalKey, @Valid @RequestBody AgentMessageRequest request ) { authService.authenticate(agentId, internalKey); String reply = agentOrchestratorService.handleMessage(agentId, request.wecomUserId(), request.message()); return ResponseEntity.ok(AgentMessageResponse.of(agentId, request.wecomUserId(), reply)); } }