Skip to content

Commit 0b146f7

Browse files
feat: add unbind website for agent (#12500)
1 parent c28a4f6 commit 0b146f7

19 files changed

Lines changed: 139 additions & 14 deletions

File tree

agent/app/api/v2/agents.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,26 @@ func (b *BaseApi) BindAgentWebsite(c *gin.Context) {
152152
helper.Success(c)
153153
}
154154

155+
// @Tags AI
156+
// @Summary Unbind Agent website
157+
// @Accept json
158+
// @Param request body dto.AgentIDReq true "request"
159+
// @Success 200
160+
// @Security ApiKeyAuth
161+
// @Security Timestamp
162+
// @Router /ai/agents/website/unbind [post]
163+
func (b *BaseApi) UnbindAgentWebsite(c *gin.Context) {
164+
var req dto.AgentIDReq
165+
if err := helper.CheckBindAndValidate(&req, c); err != nil {
166+
return
167+
}
168+
if err := agentService.UnbindWebsite(req); err != nil {
169+
helper.BadRequest(c, err)
170+
return
171+
}
172+
helper.Success(c)
173+
}
174+
155175
// @Tags AI
156176
// @Summary Get Agent model config
157177
// @Accept json

agent/app/dto/agents.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type AgentItem struct {
4646
AppInstallID uint `json:"appInstallId"`
4747
WebsiteID uint `json:"websiteId"`
4848
WebsitePrimaryDomain string `json:"websitePrimaryDomain"`
49+
WebsiteType string `json:"websiteType"`
4950
WebsiteProtocol string `json:"websiteProtocol"`
5051
AccountID uint `json:"accountId"`
5152
AppVersion string `json:"appVersion"`

agent/app/service/agents.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type IAgentService interface {
3636
ResetToken(req dto.AgentTokenResetReq) error
3737
UpdateRemark(req dto.AgentRemarkUpdateReq) error
3838
BindWebsite(req dto.AgentWebsiteBindReq) error
39+
UnbindWebsite(req dto.AgentIDReq) error
3940
GetModelConfig(req dto.AgentIDReq) (*dto.AgentModelConfig, error)
4041
UpdateModelConfig(req dto.AgentModelConfigUpdateReq) error
4142
GetHermesChatSessions(req dto.AgentIDReq) ([]dto.AgentHermesChatSessionItem, error)

agent/app/service/agents_website.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ func (a AgentService) BindWebsite(req dto.AgentWebsiteBindReq) error {
4848
return ensureOpenclawWebsiteAllowedOrigin(agent, &website)
4949
}
5050

51+
func (a AgentService) UnbindWebsite(req dto.AgentIDReq) error {
52+
agent, err := agentRepo.GetFirst(repo.WithByID(req.AgentID))
53+
if err != nil {
54+
return err
55+
}
56+
if agent.WebsiteID == 0 {
57+
return nil
58+
}
59+
60+
website, err := websiteRepo.GetFirst(repo.WithByID(agent.WebsiteID))
61+
if err != nil {
62+
return err
63+
}
64+
if website.Type == constant.Deployment {
65+
return buserr.New("ErrAgentWebsiteUnbindUnsupported")
66+
}
67+
68+
agent.WebsiteID = 0
69+
return agentRepo.Save(agent)
70+
}
71+
5172
func hydrateAgentWebsiteItems(items []dto.AgentItem) error {
5273
explicitWebsiteMap, err := loadAgentWebsiteMapByID(items)
5374
if err != nil {
@@ -126,9 +147,11 @@ func fillAgentWebsiteItems(items []dto.AgentItem, explicitWebsiteMap map[uint]mo
126147
if !ok {
127148
items[index].WebsiteID = 0
128149
items[index].WebsitePrimaryDomain = ""
150+
items[index].WebsiteType = ""
129151
items[index].WebsiteProtocol = ""
130152
continue
131153
}
154+
items[index].WebsiteType = website.Type
132155
items[index].WebsiteProtocol = website.Protocol
133156
websiteDomains := websiteDomainMap[items[index].WebsiteID]
134157
if len(websiteDomains) == 0 {

agent/i18n/lang/en.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ErrAgentLimitReached: 'Community Edition supports up to {{ .max }} AI agents. Up
6464
ErrAgentWebsiteBound: 'This agent is already bound to a website'
6565
ErrAgentWebsiteTypeUnsupported: 'Only proxy or static websites can be bound'
6666
ErrAgentWebsiteInUse: 'This website is already bound to another agent'
67+
ErrAgentWebsiteUnbindUnsupported: 'Deployment websites cannot be unbound manually'
6768

6869
#backup
6970
Localhost: 'Local'

agent/i18n/lang/es-ES.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ErrAgentLimitReached: 'La edición Community admite hasta {{ .max }} agentes de
5959
ErrAgentWebsiteBound: 'Este agente ya está vinculado a un sitio web'
6060
ErrAgentWebsiteTypeUnsupported: 'Solo se pueden vincular sitios proxy o estáticos'
6161
ErrAgentWebsiteInUse: 'Este sitio web ya está vinculado a otro agente'
62+
ErrAgentWebsiteUnbindUnsupported: 'Los sitios web de despliegue no se pueden desvincular manualmente'
6263
Localhost: 'Máquina local'
6364
ErrBackupInUsed: 'Cuenta de respaldo en uso por tarea programada'
6465
ErrBackupCheck: 'Conexión de respaldo falló: {{ .err }}'

agent/i18n/lang/ja.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ErrAgentLimitReached: 'Community Edition では AI エージェントを最大 {
5959
ErrAgentWebsiteBound: 'このエージェントはすでにサイトに関連付けられています'
6060
ErrAgentWebsiteTypeUnsupported: '関連付けできるのはプロキシサイトまたは静的サイトのみです'
6161
ErrAgentWebsiteInUse: 'このサイトはすでに別のエージェントに関連付けられています'
62+
ErrAgentWebsiteUnbindUnsupported: 'ワンクリックデプロイのサイトは手動で関連解除できません'
6263
Localhost: 'ローカルマシン'
6364
ErrBackupInUsed: 'バックアップアカウントがスケジュールで使用中'
6465
ErrBackupCheck: '接続テストに失敗しました: {{ .err }}'

agent/i18n/lang/ko.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ErrAgentLimitReached: '커뮤니티 에디션에서는 AI 에이전트를 최대
5959
ErrAgentWebsiteBound: '이 에이전트는 이미 웹사이트에 연결되어 있습니다'
6060
ErrAgentWebsiteTypeUnsupported: '프록시 또는 정적 웹사이트만 연결할 수 있습니다'
6161
ErrAgentWebsiteInUse: '이 웹사이트는 이미 다른 에이전트에 연결되어 있습니다'
62+
ErrAgentWebsiteUnbindUnsupported: '원클릭 배포 웹사이트는 수동으로 연결 해제할 수 없습니다'
6263
Localhost: '로컬 머신'
6364
ErrBackupInUsed: '백업 계정이 예약에 사용 중'
6465
ErrBackupCheck: '연결 테스트 실패: {{ .err }}'

agent/i18n/lang/ms.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ErrAgentLimitReached: 'Edisi Community menyokong sehingga {{ .max }} ejen AI. Na
5959
ErrAgentWebsiteBound: 'Ejen ini sudah dipautkan ke laman web'
6060
ErrAgentWebsiteTypeUnsupported: 'Hanya laman web proxy atau statik boleh dipautkan'
6161
ErrAgentWebsiteInUse: 'Laman web ini sudah dipautkan ke ejen lain'
62+
ErrAgentWebsiteUnbindUnsupported: 'Laman web one-click deployment tidak menyokong nyahikat manual'
6263
Localhost: 'Mesin Tempatan'
6364
ErrBackupInUsed: 'Akaun sandaran sedang digunakan oleh tugas'
6465
ErrBackupCheck: 'Ujian sambungan gagal: {{ .err }}'

agent/i18n/lang/pt-BR.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ErrAgentLimitReached: 'A edição Community suporta até {{ .max }} agentes de I
5959
ErrAgentWebsiteBound: 'Este agente já está vinculado a um site'
6060
ErrAgentWebsiteTypeUnsupported: 'Somente sites proxy ou estáticos podem ser vinculados'
6161
ErrAgentWebsiteInUse: 'Este site já está vinculado a outro agente'
62+
ErrAgentWebsiteUnbindUnsupported: 'Sites implantados em um clique não podem ser desvinculados manualmente'
6263
Localhost: 'Máquina Local'
6364
ErrBackupInUsed: 'Conta de backup em uso por tarefa'
6465
ErrBackupCheck: 'Teste de conexão falhou: {{ .err }}'

0 commit comments

Comments
 (0)