|
4 | 4 | "context" |
5 | 5 | "encoding/json" |
6 | 6 | "fmt" |
| 7 | + "os" |
7 | 8 | "path" |
8 | 9 | "sort" |
9 | 10 | "strings" |
@@ -33,6 +34,8 @@ type IAgentService interface { |
33 | 34 | UpdateSecurityConfig(req dto.AgentSecurityConfigUpdateReq) error |
34 | 35 | GetOtherConfig(req dto.AgentOtherConfigReq) (*dto.AgentOtherConfig, error) |
35 | 36 | UpdateOtherConfig(req dto.AgentOtherConfigUpdateReq) error |
| 37 | + GetConfigFile(req dto.AgentConfigFileReq) (*dto.AgentConfigFile, error) |
| 38 | + UpdateConfigFile(req dto.AgentConfigFileUpdateReq) error |
36 | 39 | ListSkills(req dto.AgentSkillsReq) ([]dto.AgentSkillItem, error) |
37 | 40 | UpdateSkill(req dto.AgentSkillUpdateReq) error |
38 | 41 |
|
@@ -717,6 +720,46 @@ func (a AgentService) UpdateOtherConfig(req dto.AgentOtherConfigUpdateReq) error |
717 | 720 | return setOpenclawNPMRegistry(install.ContainerName, req.NPMRegistry) |
718 | 721 | } |
719 | 722 |
|
| 723 | +func (a AgentService) GetConfigFile(req dto.AgentConfigFileReq) (*dto.AgentConfigFile, error) { |
| 724 | + agent, _, err := a.loadAgentAndInstall(req.AgentID) |
| 725 | + if err != nil { |
| 726 | + return nil, err |
| 727 | + } |
| 728 | + if agent.AgentType == constant.AppCopaw { |
| 729 | + return nil, fmt.Errorf("copaw does not support config file") |
| 730 | + } |
| 731 | + content, err := os.ReadFile(agent.ConfigPath) |
| 732 | + if err != nil { |
| 733 | + return nil, err |
| 734 | + } |
| 735 | + return &dto.AgentConfigFile{Content: string(content)}, nil |
| 736 | +} |
| 737 | + |
| 738 | +func (a AgentService) UpdateConfigFile(req dto.AgentConfigFileUpdateReq) error { |
| 739 | + agent, install, err := a.loadAgentAndInstall(req.AgentID) |
| 740 | + if err != nil { |
| 741 | + return err |
| 742 | + } |
| 743 | + if agent.AgentType == constant.AppCopaw { |
| 744 | + return fmt.Errorf("copaw does not support config file") |
| 745 | + } |
| 746 | + var payload interface{} |
| 747 | + if err := json.Unmarshal([]byte(req.Content), &payload); err != nil { |
| 748 | + return err |
| 749 | + } |
| 750 | + info, err := os.Stat(agent.ConfigPath) |
| 751 | + if err != nil { |
| 752 | + return err |
| 753 | + } |
| 754 | + if err := os.WriteFile(agent.ConfigPath, []byte(req.Content), info.Mode()); err != nil { |
| 755 | + return err |
| 756 | + } |
| 757 | + return NewIAppInstalledService().Operate(request.AppInstalledOperate{ |
| 758 | + InstallId: install.ID, |
| 759 | + Operate: constant.Restart, |
| 760 | + }) |
| 761 | +} |
| 762 | + |
720 | 763 | func getOpenclawNPMRegistry(containerName string) (string, error) { |
721 | 764 | registry, err := cmd.RunDefaultWithStdoutBashCfAndTimeOut("docker exec %s npm get registry", 20*time.Second, containerName) |
722 | 765 | if err != nil { |
|
0 commit comments