- Added a new GetAssistant function to retrieve assistant details by ID, incorporating permission checks to ensure authorized access. - Updated the assistant route to use the new GetAssistant handler, enhancing security by verifying user permissions before returning assistant data. - Introduced a FilterBuiltInAssistant function to clear sensitive fields for built-in assistants, ensuring compliance with data protection standards. - Enhanced test coverage for the GetAssistant functionality, including tests for successful retrieval, permission filtering, and error handling scenarios.
28 lines
1.2 KiB
Go
28 lines
1.2 KiB
Go
package agent
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/yaoapp/yao/agent"
|
|
"github.com/yaoapp/yao/openapi/oauth/types"
|
|
)
|
|
|
|
// Attach attaches the agent (assistant) API handlers to the router with OAuth protection
|
|
// This provides OAuth-protected endpoints for assistant management, mirroring the agent assistant API
|
|
func Attach(group *gin.RouterGroup, oauth types.OAuth) {
|
|
|
|
// Get the Agent instance
|
|
n := agent.GetAgent()
|
|
|
|
// Apply OAuth guard to all routes
|
|
group.Use(oauth.Guard)
|
|
|
|
// Assistant CRUD - Standard REST endpoints
|
|
group.GET("/assistants", ListAssistants) // GET /assistants - List assistants
|
|
group.POST("/assistants", n.HandleAssistantSave) // POST /assistants - Create/Update assistant
|
|
group.GET("/assistants/tags", ListAssistantTags) // GET /assistants/tags - Get all assistant tags with permission filtering
|
|
group.GET("/assistants/:id", GetAssistant) // GET /assistants/:id - Get assistant details with permission verification
|
|
group.DELETE("/assistants/:id", n.HandleAssistantDelete) // DELETE /assistants/:id - Delete assistant
|
|
|
|
// Assistant Actions
|
|
group.POST("/assistants/:id/call", n.HandleAssistantCall) // POST /assistants/:id/call - Execute assistant API
|
|
}
|