UpdateAgentForUser updates a user's agent.
(userID, name string, config *state.AgentConfig)
| 903 | |
| 904 | // UpdateAgentForUser updates a user's agent. |
| 905 | func (s *AgentPoolService) UpdateAgentForUser(userID, name string, config *state.AgentConfig) error { |
| 906 | // Auto-generate a user API key when auth is active and none is specified |
| 907 | if s.users.authDB != nil && userID != "" && config.APIKey == "" { |
| 908 | plaintext, _, err := auth.CreateAPIKey(s.users.authDB, userID, "agent:"+name, "user", s.appConfig.Auth.APIKeyHMACSecret, nil) |
| 909 | if err != nil { |
| 910 | return fmt.Errorf("failed to create API key for agent: %w", err) |
| 911 | } |
| 912 | config.APIKey = plaintext |
| 913 | } |
| 914 | |
| 915 | if err := s.configBackend.UpdateConfig(userID, name, config); err != nil { |
| 916 | return err |
| 917 | } |
| 918 | |
| 919 | // Auto-create collection when knowledge base or long-term memory is enabled |
| 920 | if config.EnableKnowledgeBase || config.LongTermMemory { |
| 921 | if err := s.ensureCollectionForUser(userID, config.Name); err != nil { |
| 922 | xlog.Warn("Failed to auto-create collection for agent", "agent", config.Name, "error", err) |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | return nil |
| 927 | } |
| 928 | |
| 929 | // DeleteAgentForUser deletes a user's agent. |
| 930 | func (s *AgentPoolService) DeleteAgentForUser(userID, name string) error { |
no test coverage detected