Skip to content

Commit c0404a4

Browse files
authored
feat: Optimize agent style and prompt information (#11813)
1 parent 77ef3b7 commit c0404a4

27 files changed

Lines changed: 352 additions & 118 deletions

File tree

agent/app/service/agents.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ func NewIAgentService() IAgentService {
4343
func (a AgentService) Create(req dto.AgentCreateReq) (*dto.AgentItem, error) {
4444
provider := strings.ToLower(strings.TrimSpace(req.Provider))
4545
if !isSupportedAgentProvider(provider) {
46-
return nil, buserr.WithDetail("ErrInvalidParams", "provider", nil)
46+
return nil, buserr.New("ErrAgentProviderNotSupported")
4747
}
4848
if req.AccountID == 0 {
49-
return nil, buserr.WithDetail("ErrInvalidParams", "accountId", nil)
49+
return nil, buserr.New("ErrAgentAccountRequired")
5050
}
5151
account, err := agentAccountRepo.GetFirst(repo.WithByID(req.AccountID))
5252
if err != nil {
5353
return nil, err
5454
}
5555
if !account.Verified {
56-
return nil, buserr.WithDetail("ErrInvalidParams", "account", nil)
56+
return nil, buserr.New("ErrAgentAccountNotVerified")
5757
}
5858
if account.Provider != "" && provider != "" && account.Provider != provider {
59-
return nil, buserr.WithDetail("ErrInvalidParams", "provider", nil)
59+
return nil, buserr.New("ErrAgentProviderMismatch")
6060
}
6161
provider = strings.ToLower(strings.TrimSpace(account.Provider))
6262
baseURL := strings.TrimSpace(account.BaseURL)
@@ -66,10 +66,10 @@ func (a AgentService) Create(req dto.AgentCreateReq) (*dto.AgentItem, error) {
6666
}
6767
}
6868
if provider == "ollama" && baseURL == "" {
69-
return nil, buserr.WithDetail("ErrInvalidParams", "baseURL", nil)
69+
return nil, buserr.New("ErrAgentBaseURLRequired")
7070
}
7171
if provider != "ollama" && strings.TrimSpace(account.APIKey) == "" {
72-
return nil, buserr.WithDetail("ErrInvalidParams", "apiKey", nil)
72+
return nil, buserr.New("ErrAgentApiKeyRequired")
7373
}
7474
if err := checkPortExist(req.WebUIPort); err != nil {
7575
return nil, err
@@ -110,7 +110,7 @@ func (a AgentService) Create(req dto.AgentCreateReq) (*dto.AgentItem, error) {
110110
}
111111

112112
if req.EditCompose && strings.TrimSpace(req.DockerCompose) == "" {
113-
return nil, buserr.WithDetail("ErrInvalidParams", "dockerCompose", nil)
113+
return nil, buserr.New("ErrAgentComposeRequired")
114114
}
115115
installReq := request.AppInstallCreate{
116116
AppDetailId: detail.ID,
@@ -178,7 +178,7 @@ func (a AgentService) Page(req dto.SearchWithPage) (int64, []dto.AgentItem, erro
178178

179179
func (a AgentService) Delete(req dto.AgentDeleteReq) error {
180180
if req.ID == 0 {
181-
return buserr.WithDetail("ErrInvalidParams", "id", nil)
181+
return buserr.New("ErrAgentIDRequired")
182182
}
183183
agent, err := agentRepo.GetFirst(repo.WithByID(req.ID))
184184
if err != nil {
@@ -216,11 +216,11 @@ func (a AgentService) GetProviders() ([]dto.ProviderInfo, error) {
216216
func (a AgentService) CreateAccount(req dto.AgentAccountCreateReq) error {
217217
provider := strings.ToLower(strings.TrimSpace(req.Provider))
218218
if !isSupportedAgentProvider(provider) {
219-
return buserr.WithDetail("ErrInvalidParams", "provider", nil)
219+
return buserr.New("ErrAgentProviderNotSupported")
220220
}
221221
apiKey := strings.TrimSpace(req.APIKey)
222222
if apiKey == "" {
223-
return buserr.WithDetail("ErrInvalidParams", "apiKey", nil)
223+
return buserr.New("ErrAgentApiKeyRequired")
224224
}
225225
baseURL := strings.TrimSpace(req.BaseURL)
226226
if provider != "ollama" {
@@ -229,7 +229,7 @@ func (a AgentService) CreateAccount(req dto.AgentAccountCreateReq) error {
229229
}
230230
}
231231
if provider == "ollama" && baseURL == "" {
232-
return buserr.WithDetail("ErrInvalidParams", "baseURL", nil)
232+
return buserr.New("ErrAgentBaseURLRequired")
233233
}
234234
if exist, _ := agentAccountRepo.GetFirst(repo.WithByProvider(provider), repo.WithByName(req.Name)); exist != nil && exist.ID > 0 {
235235
return buserr.New("ErrRecordExist")
@@ -261,7 +261,7 @@ func (a AgentService) UpdateAccount(req dto.AgentAccountUpdateReq) error {
261261
}
262262
}
263263
if provider == "ollama" && baseURL == "" {
264-
return buserr.WithDetail("ErrInvalidParams", "baseURL", nil)
264+
return buserr.New("ErrAgentBaseURLRequired")
265265
}
266266
if err := a.VerifyAccount(dto.AgentAccountVerifyReq{Provider: provider, BaseURL: baseURL, APIKey: req.APIKey}); err != nil {
267267
return err
@@ -313,11 +313,11 @@ func (a AgentService) PageAccounts(req dto.AgentAccountSearch) (int64, []dto.Age
313313
func (a AgentService) VerifyAccount(req dto.AgentAccountVerifyReq) error {
314314
provider := strings.ToLower(strings.TrimSpace(req.Provider))
315315
if !isSupportedAgentProvider(provider) {
316-
return buserr.WithDetail("ErrInvalidParams", "provider", nil)
316+
return buserr.New("ErrAgentProviderNotSupported")
317317
}
318318
apiKey := strings.TrimSpace(req.APIKey)
319319
if apiKey == "" {
320-
return buserr.WithDetail("ErrInvalidParams", "apiKey", nil)
320+
return buserr.New("ErrAgentApiKeyRequired")
321321
}
322322
baseURL := strings.TrimSpace(req.BaseURL)
323323
if baseURL == "" {
@@ -326,7 +326,7 @@ func (a AgentService) VerifyAccount(req dto.AgentAccountVerifyReq) error {
326326
}
327327
}
328328
if provider == "ollama" && baseURL == "" {
329-
return buserr.WithDetail("ErrInvalidParams", "baseURL", nil)
329+
return buserr.New("ErrAgentBaseURLRequired")
330330
}
331331
if provider == "ollama" {
332332
return nil
@@ -336,10 +336,10 @@ func (a AgentService) VerifyAccount(req dto.AgentAccountVerifyReq) error {
336336

337337
func (a AgentService) DeleteAccount(req dto.AgentAccountDeleteReq) error {
338338
if req.ID == 0 {
339-
return buserr.WithDetail("ErrInvalidParams", "id", nil)
339+
return buserr.New("ErrAgentAccountIDRequired")
340340
}
341341
if exists, _ := agentRepo.GetFirst(repo.WithByAccountID(req.ID)); exists != nil && exists.ID > 0 {
342-
return buserr.New("ErrRecordExist")
342+
return buserr.New("ErrAgentAccountBound")
343343
}
344344
return agentAccountRepo.DeleteByID(req.ID)
345345
}
@@ -391,11 +391,11 @@ func verifyProvider(provider, baseURL, apiKey string) error {
391391
}
392392
resp, err := client.Do(request)
393393
if err != nil {
394-
return err
394+
return buserr.WithErr("ErrAgentAccountUnavailable", err)
395395
}
396396
defer resp.Body.Close()
397397
if resp.StatusCode >= 400 {
398-
return buserr.WithDetail("ErrInvalidParams", fmt.Sprintf("verify failed: %d", resp.StatusCode), nil)
398+
return buserr.WithErr("ErrAgentAccountUnavailable", fmt.Errorf("verify failed: %s", resp.Status))
399399
}
400400
return nil
401401
}

agent/i18n/lang/en.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ ErrGroupIsDefault: 'Default group, cannot be deleted'
3838
ErrGroupIsInWebsiteUse: 'The group is being used by another website and cannot be deleted.'
3939
Decrypt: "Decrypt"
4040

41+
#agent
42+
ErrAgentAccountBound: 'This account is bound to an agent and cannot be deleted. Please check and try again!'
43+
ErrAgentAccountUnavailable: 'The account connection information is unavailable. Error: {{ .err }}. Please check and try again!'
44+
ErrAgentProviderNotSupported: 'This agent provider is not supported. Please check and try again!'
45+
ErrAgentAccountRequired: 'Please select an agent account and try again.'
46+
ErrAgentAccountNotVerified: 'The account has not been verified. Please check and try again!'
47+
ErrAgentProviderMismatch: 'The account provider does not match. Please check and try again!'
48+
ErrAgentBaseURLRequired: 'Base URL cannot be empty. Please check and try again!'
49+
ErrAgentApiKeyRequired: 'API Key cannot be empty. Please check and try again!'
50+
ErrAgentComposeRequired: 'Custom compose content cannot be empty. Please check and try again!'
51+
ErrAgentIDRequired: 'Agent ID cannot be empty. Please check and try again!'
52+
ErrAgentAccountIDRequired: 'Account ID cannot be empty. Please check and try again!'
53+
4154
#backup
4255
Localhost: 'Local Machine'
4356
ErrBackupInUsed: 'The backup account has been used in the scheduled task and cannot be deleted.'
@@ -527,4 +540,4 @@ PartitionDiskErr: "Failed to partition, {{ .err }}"
527540
FormatDiskErr: "Failed to format disk, {{ .err }}"
528541
MountDiskErr: "Failed to mount disk, {{ .err }}"
529542
UnMountDiskErr: "Failed to unmount disk, {{ .err }}"
530-
XfsNotFound: "xfs filesystem not detected, please install xfsprogs first"
543+
XfsNotFound: "xfs filesystem not detected, please install xfsprogs first"

agent/i18n/lang/es-ES.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ ErrGroupIsDefault: 'Grupo predeterminado, no se puede eliminar'
3838
ErrGroupIsInWebsiteUse: 'El grupo está siendo usado por otro sitio web y no se puede eliminar.'
3939
Decrypt: "Descifrar"
4040

41+
#agent
42+
ErrAgentAccountBound: 'Esta cuenta está vinculada a un agente y no se puede eliminar. Verifique e inténtelo de nuevo!'
43+
ErrAgentAccountUnavailable: 'La información de conexión de la cuenta no está disponible. Error: {{ .err }}. Verifique e inténtelo de nuevo!'
44+
ErrAgentProviderNotSupported: 'Este proveedor de agente no es compatible. Verifique e inténtelo de nuevo!'
45+
ErrAgentAccountRequired: 'Seleccione una cuenta de agente y vuelva a intentarlo.'
46+
ErrAgentAccountNotVerified: 'La cuenta no está verificada. Verifique e inténtelo de nuevo!'
47+
ErrAgentProviderMismatch: 'El proveedor de la cuenta no coincide. Verifique e inténtelo de nuevo!'
48+
ErrAgentBaseURLRequired: 'Base URL no puede estar vacío. Verifique e inténtelo de nuevo!'
49+
ErrAgentApiKeyRequired: 'API Key no puede estar vacío. Verifique e inténtelo de nuevo!'
50+
ErrAgentComposeRequired: 'El contenido personalizado de compose no puede estar vacío. Verifique e inténtelo de nuevo!'
51+
ErrAgentIDRequired: 'El ID del agente no puede estar vacío. Verifique e inténtelo de nuevo!'
52+
ErrAgentAccountIDRequired: 'El ID de la cuenta no puede estar vacío. Verifique e inténtelo de nuevo!'
53+
4154
#backup
4255
ErrBackupInUsed: 'La cuenta de respaldo está siendo utilizada en una tarea programada y no se puede eliminar.'
4356
ErrBackupCheck: 'Error al probar la conexión de la cuenta de respaldo {{ .err }}'

agent/i18n/lang/ja.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ ErrGroupIsDefault: 'デフォルト グループ、削除できません'
3737
ErrGroupIsInWebsiteUse: 'グループは別の Web サイトで使用されているため、削除できません。'
3838
Decrypt: "復号化"
3939

40+
#agent
41+
ErrAgentAccountBound: 'このアカウントはエージェントに紐付いているため削除できません。確認して再試行してください!'
42+
ErrAgentAccountUnavailable: 'アカウント接続情報を利用できません。エラー: {{ .err }}。確認して再試行してください!'
43+
ErrAgentProviderNotSupported: 'このエージェント提供元はサポートされていません。確認して再試行してください!'
44+
ErrAgentAccountRequired: 'エージェントアカウントを選択して再試行してください。'
45+
ErrAgentAccountNotVerified: 'アカウントの検証が完了していません。確認して再試行してください!'
46+
ErrAgentProviderMismatch: 'アカウントの提供元が一致しません。確認して再試行してください!'
47+
ErrAgentBaseURLRequired: 'Base URL を空にできません。確認して再試行してください!'
48+
ErrAgentApiKeyRequired: 'API Key を空にできません。確認して再試行してください!'
49+
ErrAgentComposeRequired: 'カスタム compose 内容を空にできません。確認して再試行してください!'
50+
ErrAgentIDRequired: 'エージェント ID を空にできません。確認して再試行してください!'
51+
ErrAgentAccountIDRequired: 'アカウント ID を空にできません。確認して再試行してください!'
52+
4053
#backup
4154
Localhost: 'ローカルマシン'
4255
ErrBackupInUsed: 'バックアップ アカウントはスケジュールされたタスクで使用されているため、削除できません。'
@@ -526,4 +539,4 @@ PartitionDiskErr: "パーティションに失敗しました、{{ .err }}"
526539
FormatDiskErr: "ディスクのフォーマットに失敗しました、{{ .err }}"
527540
MountDiskErr: "ディスクのマウントに失敗しました、{{ .err }}"
528541
UnMountDiskErr: "ディスクのアンマウントに失敗しました、{{ .err }}"
529-
XfsNotFound: "xfs ファイルシステムが検出されませんでした、最初に xfsprogs をインストールしてください"
542+
XfsNotFound: "xfs ファイルシステムが検出されませんでした、最初に xfsprogs をインストールしてください"

agent/i18n/lang/ko.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ ErrGroupIsDefault: '기본 그룹, 삭제할 수 없습니다'
3838
ErrGroupIsInWebsiteUse: '그룹이 다른 웹사이트에서 사용 중이므로 삭제할 수 없습니다.'
3939
Decrypt: "복호화"
4040

41+
#agent
42+
ErrAgentAccountBound: '이 계정은 에이전트에 바인딩되어 있어 삭제할 수 없습니다. 확인 후 다시 시도하세요!'
43+
ErrAgentAccountUnavailable: '계정 연결 정보를 사용할 수 없습니다. 오류: {{ .err }}. 확인 후 다시 시도하세요!'
44+
ErrAgentProviderNotSupported: '이 에이전트 제공자는 지원되지 않습니다. 확인 후 다시 시도하세요!'
45+
ErrAgentAccountRequired: '에이전트 계정을 선택한 후 다시 시도하세요.'
46+
ErrAgentAccountNotVerified: '계정이 검증되지 않았습니다. 확인 후 다시 시도하세요!'
47+
ErrAgentProviderMismatch: '계정 제공자가 일치하지 않습니다. 확인 후 다시 시도하세요!'
48+
ErrAgentBaseURLRequired: 'Base URL은 비워 둘 수 없습니다. 확인 후 다시 시도하세요!'
49+
ErrAgentApiKeyRequired: 'API Key는 비워 둘 수 없습니다. 확인 후 다시 시도하세요!'
50+
ErrAgentComposeRequired: '사용자 정의 compose 내용은 비워 둘 수 없습니다. 확인 후 다시 시도하세요!'
51+
ErrAgentIDRequired: '에이전트 ID는 비워 둘 수 없습니다. 확인 후 다시 시도하세요!'
52+
ErrAgentAccountIDRequired: '계정 ID는 비워 둘 수 없습니다. 확인 후 다시 시도하세요!'
53+
4154
#지원
4255
Localhost: '로컬 머신'
4356
ErrBackupInUsed: '백업 계정이 예약된 작업에 사용되었으므로 삭제할 수 없습니다.'
@@ -527,4 +540,4 @@ PartitionDiskErr: "파티션 분할에 실패했습니다, {{ .err }}"
527540
FormatDiskErr: "디스크 포맷에 실패했습니다, {{ .err }}"
528541
MountDiskErr: "디스크 마운트에 실패했습니다, {{ .err }}"
529542
UnMountDiskErr: "디스크 마운트 해제에 실패했습니다, {{ .err }}"
530-
XfsNotFound: "xfs 파일 시스템이 감지되지 않았습니다, 먼저 xfsprogs 를 설치하세요"
543+
XfsNotFound: "xfs 파일 시스템이 감지되지 않았습니다, 먼저 xfsprogs 를 설치하세요"

agent/i18n/lang/ms.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ ErrGroupIsDefault: 'Kumpulan lalai, tidak boleh dipadamkan'
4141
ErrGroupIsInWebsiteUse: 'Kumpulan sedang digunakan oleh tapak web lain dan tidak boleh dipadamkan.'
4242
Decrypt: "Dekripsi"
4343

44+
#agent
45+
ErrAgentAccountBound: 'Akaun ini telah dipautkan kepada ejen dan tidak boleh dipadam. Sila semak dan cuba lagi!'
46+
ErrAgentAccountUnavailable: 'Maklumat sambungan akaun tidak tersedia. Ralat: {{ .err }}. Sila semak dan cuba lagi!'
47+
ErrAgentProviderNotSupported: 'Penyedia ejen ini tidak disokong. Sila semak dan cuba lagi!'
48+
ErrAgentAccountRequired: 'Sila pilih akaun ejen dan cuba lagi.'
49+
ErrAgentAccountNotVerified: 'Akaun belum disahkan. Sila semak dan cuba lagi!'
50+
ErrAgentProviderMismatch: 'Penyedia akaun tidak sepadan. Sila semak dan cuba lagi!'
51+
ErrAgentBaseURLRequired: 'Base URL tidak boleh kosong. Sila semak dan cuba lagi!'
52+
ErrAgentApiKeyRequired: 'API Key tidak boleh kosong. Sila semak dan cuba lagi!'
53+
ErrAgentComposeRequired: 'Kandungan compose tersuai tidak boleh kosong. Sila semak dan cuba lagi!'
54+
ErrAgentIDRequired: 'ID ejen tidak boleh kosong. Sila semak dan cuba lagi!'
55+
ErrAgentAccountIDRequired: 'ID akaun tidak boleh kosong. Sila semak dan cuba lagi!'
56+
4457
#sandaran
4558
Localhost: 'Mesin Tempatan'
4659
ErrBackupInUsed: 'Akaun sandaran telah digunakan dalam tugas yang dijadualkan dan tidak boleh dipadamkan.'
@@ -527,4 +540,4 @@ PartitionDiskErr: "Gagal membahagikan, {{ .err }}"
527540
FormatDiskErr: "Gagal memformat cakera, {{ .err }}"
528541
MountDiskErr: "Gagal mengkaitkan cakera, {{ .err }}"
529542
UnMountDiskErr: "Gagal nyahkaitkan cakera, {{ .err }}"
530-
XfsNotFound: "Sistem fail xfs tidak dikesan, sila pasang xfsprogs terlebih dahulu"
543+
XfsNotFound: "Sistem fail xfs tidak dikesan, sila pasang xfsprogs terlebih dahulu"

agent/i18n/lang/pt-BR.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ ErrGroupIsDefault: 'Grupo padrão, não pode ser excluído'
4141
ErrGroupIsInWebsiteUse: 'O grupo está sendo usado por outro site e não pode ser excluído.'
4242
Decrypt: "Descriptografar"
4343

44+
#agent
45+
ErrAgentAccountBound: 'Esta conta está vinculada a um agente e não pode ser excluída. Verifique e tente novamente!'
46+
ErrAgentAccountUnavailable: 'As informações de conexão da conta não estão disponíveis. Erro: {{ .err }}. Verifique e tente novamente!'
47+
ErrAgentProviderNotSupported: 'Este provedor de agente não é suportado. Verifique e tente novamente!'
48+
ErrAgentAccountRequired: 'Selecione uma conta de agente e tente novamente.'
49+
ErrAgentAccountNotVerified: 'A conta não foi verificada. Verifique e tente novamente!'
50+
ErrAgentProviderMismatch: 'O provedor da conta não corresponde. Verifique e tente novamente!'
51+
ErrAgentBaseURLRequired: 'Base URL não pode estar vazio. Verifique e tente novamente!'
52+
ErrAgentApiKeyRequired: 'API Key não pode estar vazio. Verifique e tente novamente!'
53+
ErrAgentComposeRequired: 'O conteúdo personalizado do compose não pode estar vazio. Verifique e tente novamente!'
54+
ErrAgentIDRequired: 'ID do agente não pode estar vazio. Verifique e tente novamente!'
55+
ErrAgentAccountIDRequired: 'ID da conta não pode estar vazio. Verifique e tente novamente!'
56+
4457
#backup
4558
Localhost: 'Máquina Local'
4659
ErrBackupInUsed: 'A conta de backup foi usada na tarefa agendada e não pode ser excluída.'
@@ -527,4 +540,4 @@ PartitionDiskErr: "Falha ao particionar, {{ .err }}"
527540
FormatDiskErr: "Falha ao formatar disco, {{ .err }}"
528541
MountDiskErr: "Falha ao montar disco, {{ .err }}"
529542
UnMountDiskErr: "Falha ao desmontar disco, {{ .err }}"
530-
XfsNotFound: "Sistema de arquivos xfs não detectado, por favor instale xfsprogs primeiro"
543+
XfsNotFound: "Sistema de arquivos xfs não detectado, por favor instale xfsprogs primeiro"

0 commit comments

Comments
 (0)