Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions agent/app/service/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ func NewIAgentService() IAgentService {
func (a AgentService) Create(req dto.AgentCreateReq) (*dto.AgentItem, error) {
provider := strings.ToLower(strings.TrimSpace(req.Provider))
if !isSupportedAgentProvider(provider) {
return nil, buserr.WithDetail("ErrInvalidParams", "provider", nil)
return nil, buserr.New("ErrAgentProviderNotSupported")
}
if req.AccountID == 0 {
return nil, buserr.WithDetail("ErrInvalidParams", "accountId", nil)
return nil, buserr.New("ErrAgentAccountRequired")
}
account, err := agentAccountRepo.GetFirst(repo.WithByID(req.AccountID))
if err != nil {
return nil, err
}
if !account.Verified {
return nil, buserr.WithDetail("ErrInvalidParams", "account", nil)
return nil, buserr.New("ErrAgentAccountNotVerified")
}
if account.Provider != "" && provider != "" && account.Provider != provider {
return nil, buserr.WithDetail("ErrInvalidParams", "provider", nil)
return nil, buserr.New("ErrAgentProviderMismatch")
}
provider = strings.ToLower(strings.TrimSpace(account.Provider))
baseURL := strings.TrimSpace(account.BaseURL)
Expand All @@ -66,10 +66,10 @@ func (a AgentService) Create(req dto.AgentCreateReq) (*dto.AgentItem, error) {
}
}
if provider == "ollama" && baseURL == "" {
return nil, buserr.WithDetail("ErrInvalidParams", "baseURL", nil)
return nil, buserr.New("ErrAgentBaseURLRequired")
}
if provider != "ollama" && strings.TrimSpace(account.APIKey) == "" {
return nil, buserr.WithDetail("ErrInvalidParams", "apiKey", nil)
return nil, buserr.New("ErrAgentApiKeyRequired")
}
if err := checkPortExist(req.WebUIPort); err != nil {
return nil, err
Expand Down Expand Up @@ -110,7 +110,7 @@ func (a AgentService) Create(req dto.AgentCreateReq) (*dto.AgentItem, error) {
}

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

func (a AgentService) Delete(req dto.AgentDeleteReq) error {
if req.ID == 0 {
return buserr.WithDetail("ErrInvalidParams", "id", nil)
return buserr.New("ErrAgentIDRequired")
}
agent, err := agentRepo.GetFirst(repo.WithByID(req.ID))
if err != nil {
Expand Down Expand Up @@ -216,11 +216,11 @@ func (a AgentService) GetProviders() ([]dto.ProviderInfo, error) {
func (a AgentService) CreateAccount(req dto.AgentAccountCreateReq) error {
provider := strings.ToLower(strings.TrimSpace(req.Provider))
if !isSupportedAgentProvider(provider) {
return buserr.WithDetail("ErrInvalidParams", "provider", nil)
return buserr.New("ErrAgentProviderNotSupported")
}
apiKey := strings.TrimSpace(req.APIKey)
if apiKey == "" {
return buserr.WithDetail("ErrInvalidParams", "apiKey", nil)
return buserr.New("ErrAgentApiKeyRequired")
}
baseURL := strings.TrimSpace(req.BaseURL)
if provider != "ollama" {
Expand All @@ -229,7 +229,7 @@ func (a AgentService) CreateAccount(req dto.AgentAccountCreateReq) error {
}
}
if provider == "ollama" && baseURL == "" {
return buserr.WithDetail("ErrInvalidParams", "baseURL", nil)
return buserr.New("ErrAgentBaseURLRequired")
}
if exist, _ := agentAccountRepo.GetFirst(repo.WithByProvider(provider), repo.WithByName(req.Name)); exist != nil && exist.ID > 0 {
return buserr.New("ErrRecordExist")
Expand Down Expand Up @@ -261,7 +261,7 @@ func (a AgentService) UpdateAccount(req dto.AgentAccountUpdateReq) error {
}
}
if provider == "ollama" && baseURL == "" {
return buserr.WithDetail("ErrInvalidParams", "baseURL", nil)
return buserr.New("ErrAgentBaseURLRequired")
}
if err := a.VerifyAccount(dto.AgentAccountVerifyReq{Provider: provider, BaseURL: baseURL, APIKey: req.APIKey}); err != nil {
return err
Expand Down Expand Up @@ -313,11 +313,11 @@ func (a AgentService) PageAccounts(req dto.AgentAccountSearch) (int64, []dto.Age
func (a AgentService) VerifyAccount(req dto.AgentAccountVerifyReq) error {
provider := strings.ToLower(strings.TrimSpace(req.Provider))
if !isSupportedAgentProvider(provider) {
return buserr.WithDetail("ErrInvalidParams", "provider", nil)
return buserr.New("ErrAgentProviderNotSupported")
}
apiKey := strings.TrimSpace(req.APIKey)
if apiKey == "" {
return buserr.WithDetail("ErrInvalidParams", "apiKey", nil)
return buserr.New("ErrAgentApiKeyRequired")
}
baseURL := strings.TrimSpace(req.BaseURL)
if baseURL == "" {
Expand All @@ -326,7 +326,7 @@ func (a AgentService) VerifyAccount(req dto.AgentAccountVerifyReq) error {
}
}
if provider == "ollama" && baseURL == "" {
return buserr.WithDetail("ErrInvalidParams", "baseURL", nil)
return buserr.New("ErrAgentBaseURLRequired")
}
if provider == "ollama" {
return nil
Expand All @@ -336,10 +336,10 @@ func (a AgentService) VerifyAccount(req dto.AgentAccountVerifyReq) error {

func (a AgentService) DeleteAccount(req dto.AgentAccountDeleteReq) error {
if req.ID == 0 {
return buserr.WithDetail("ErrInvalidParams", "id", nil)
return buserr.New("ErrAgentAccountIDRequired")
}
if exists, _ := agentRepo.GetFirst(repo.WithByAccountID(req.ID)); exists != nil && exists.ID > 0 {
return buserr.New("ErrRecordExist")
return buserr.New("ErrAgentAccountBound")
}
return agentAccountRepo.DeleteByID(req.ID)
}
Expand Down Expand Up @@ -391,11 +391,11 @@ func verifyProvider(provider, baseURL, apiKey string) error {
}
resp, err := client.Do(request)
if err != nil {
return err
return buserr.WithErr("ErrAgentAccountUnavailable", err)
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
return buserr.WithDetail("ErrInvalidParams", fmt.Sprintf("verify failed: %d", resp.StatusCode), nil)
return buserr.WithErr("ErrAgentAccountUnavailable", fmt.Errorf("verify failed: %s", resp.Status))
}
return nil
}
Expand Down
15 changes: 14 additions & 1 deletion agent/i18n/lang/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ ErrGroupIsDefault: 'Default group, cannot be deleted'
ErrGroupIsInWebsiteUse: 'The group is being used by another website and cannot be deleted.'
Decrypt: "Decrypt"

#agent
ErrAgentAccountBound: 'This account is bound to an agent and cannot be deleted. Please check and try again!'
ErrAgentAccountUnavailable: 'The account connection information is unavailable. Error: {{ .err }}. Please check and try again!'
ErrAgentProviderNotSupported: 'This agent provider is not supported. Please check and try again!'
ErrAgentAccountRequired: 'Please select an agent account and try again.'
ErrAgentAccountNotVerified: 'The account has not been verified. Please check and try again!'
ErrAgentProviderMismatch: 'The account provider does not match. Please check and try again!'
ErrAgentBaseURLRequired: 'Base URL cannot be empty. Please check and try again!'
ErrAgentApiKeyRequired: 'API Key cannot be empty. Please check and try again!'
ErrAgentComposeRequired: 'Custom compose content cannot be empty. Please check and try again!'
ErrAgentIDRequired: 'Agent ID cannot be empty. Please check and try again!'
ErrAgentAccountIDRequired: 'Account ID cannot be empty. Please check and try again!'

#backup
Localhost: 'Local Machine'
ErrBackupInUsed: 'The backup account has been used in the scheduled task and cannot be deleted.'
Expand Down Expand Up @@ -527,4 +540,4 @@ PartitionDiskErr: "Failed to partition, {{ .err }}"
FormatDiskErr: "Failed to format disk, {{ .err }}"
MountDiskErr: "Failed to mount disk, {{ .err }}"
UnMountDiskErr: "Failed to unmount disk, {{ .err }}"
XfsNotFound: "xfs filesystem not detected, please install xfsprogs first"
XfsNotFound: "xfs filesystem not detected, please install xfsprogs first"
13 changes: 13 additions & 0 deletions agent/i18n/lang/es-ES.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ ErrGroupIsDefault: 'Grupo predeterminado, no se puede eliminar'
ErrGroupIsInWebsiteUse: 'El grupo está siendo usado por otro sitio web y no se puede eliminar.'
Decrypt: "Descifrar"

#agent
ErrAgentAccountBound: 'Esta cuenta está vinculada a un agente y no se puede eliminar. Verifique e inténtelo de nuevo!'
ErrAgentAccountUnavailable: 'La información de conexión de la cuenta no está disponible. Error: {{ .err }}. Verifique e inténtelo de nuevo!'
ErrAgentProviderNotSupported: 'Este proveedor de agente no es compatible. Verifique e inténtelo de nuevo!'
ErrAgentAccountRequired: 'Seleccione una cuenta de agente y vuelva a intentarlo.'
ErrAgentAccountNotVerified: 'La cuenta no está verificada. Verifique e inténtelo de nuevo!'
ErrAgentProviderMismatch: 'El proveedor de la cuenta no coincide. Verifique e inténtelo de nuevo!'
ErrAgentBaseURLRequired: 'Base URL no puede estar vacío. Verifique e inténtelo de nuevo!'
ErrAgentApiKeyRequired: 'API Key no puede estar vacío. Verifique e inténtelo de nuevo!'
ErrAgentComposeRequired: 'El contenido personalizado de compose no puede estar vacío. Verifique e inténtelo de nuevo!'
ErrAgentIDRequired: 'El ID del agente no puede estar vacío. Verifique e inténtelo de nuevo!'
ErrAgentAccountIDRequired: 'El ID de la cuenta no puede estar vacío. Verifique e inténtelo de nuevo!'

#backup
ErrBackupInUsed: 'La cuenta de respaldo está siendo utilizada en una tarea programada y no se puede eliminar.'
ErrBackupCheck: 'Error al probar la conexión de la cuenta de respaldo {{ .err }}'
Expand Down
15 changes: 14 additions & 1 deletion agent/i18n/lang/ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ ErrGroupIsDefault: 'デフォルト グループ、削除できません'
ErrGroupIsInWebsiteUse: 'グループは別の Web サイトで使用されているため、削除できません。'
Decrypt: "復号化"

#agent
ErrAgentAccountBound: 'このアカウントはエージェントに紐付いているため削除できません。確認して再試行してください!'
ErrAgentAccountUnavailable: 'アカウント接続情報を利用できません。エラー: {{ .err }}。確認して再試行してください!'
ErrAgentProviderNotSupported: 'このエージェント提供元はサポートされていません。確認して再試行してください!'
ErrAgentAccountRequired: 'エージェントアカウントを選択して再試行してください。'
ErrAgentAccountNotVerified: 'アカウントの検証が完了していません。確認して再試行してください!'
ErrAgentProviderMismatch: 'アカウントの提供元が一致しません。確認して再試行してください!'
ErrAgentBaseURLRequired: 'Base URL を空にできません。確認して再試行してください!'
ErrAgentApiKeyRequired: 'API Key を空にできません。確認して再試行してください!'
ErrAgentComposeRequired: 'カスタム compose 内容を空にできません。確認して再試行してください!'
ErrAgentIDRequired: 'エージェント ID を空にできません。確認して再試行してください!'
ErrAgentAccountIDRequired: 'アカウント ID を空にできません。確認して再試行してください!'

#backup
Localhost: 'ローカルマシン'
ErrBackupInUsed: 'バックアップ アカウントはスケジュールされたタスクで使用されているため、削除できません。'
Expand Down Expand Up @@ -526,4 +539,4 @@ PartitionDiskErr: "パーティションに失敗しました、{{ .err }}"
FormatDiskErr: "ディスクのフォーマットに失敗しました、{{ .err }}"
MountDiskErr: "ディスクのマウントに失敗しました、{{ .err }}"
UnMountDiskErr: "ディスクのアンマウントに失敗しました、{{ .err }}"
XfsNotFound: "xfs ファイルシステムが検出されませんでした、最初に xfsprogs をインストールしてください"
XfsNotFound: "xfs ファイルシステムが検出されませんでした、最初に xfsprogs をインストールしてください"
15 changes: 14 additions & 1 deletion agent/i18n/lang/ko.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ ErrGroupIsDefault: '기본 그룹, 삭제할 수 없습니다'
ErrGroupIsInWebsiteUse: '그룹이 다른 웹사이트에서 사용 중이므로 삭제할 수 없습니다.'
Decrypt: "복호화"

#agent
ErrAgentAccountBound: '이 계정은 에이전트에 바인딩되어 있어 삭제할 수 없습니다. 확인 후 다시 시도하세요!'
ErrAgentAccountUnavailable: '계정 연결 정보를 사용할 수 없습니다. 오류: {{ .err }}. 확인 후 다시 시도하세요!'
ErrAgentProviderNotSupported: '이 에이전트 제공자는 지원되지 않습니다. 확인 후 다시 시도하세요!'
ErrAgentAccountRequired: '에이전트 계정을 선택한 후 다시 시도하세요.'
ErrAgentAccountNotVerified: '계정이 검증되지 않았습니다. 확인 후 다시 시도하세요!'
ErrAgentProviderMismatch: '계정 제공자가 일치하지 않습니다. 확인 후 다시 시도하세요!'
ErrAgentBaseURLRequired: 'Base URL은 비워 둘 수 없습니다. 확인 후 다시 시도하세요!'
ErrAgentApiKeyRequired: 'API Key는 비워 둘 수 없습니다. 확인 후 다시 시도하세요!'
ErrAgentComposeRequired: '사용자 정의 compose 내용은 비워 둘 수 없습니다. 확인 후 다시 시도하세요!'
ErrAgentIDRequired: '에이전트 ID는 비워 둘 수 없습니다. 확인 후 다시 시도하세요!'
ErrAgentAccountIDRequired: '계정 ID는 비워 둘 수 없습니다. 확인 후 다시 시도하세요!'

#지원
Localhost: '로컬 머신'
ErrBackupInUsed: '백업 계정이 예약된 작업에 사용되었으므로 삭제할 수 없습니다.'
Expand Down Expand Up @@ -527,4 +540,4 @@ PartitionDiskErr: "파티션 분할에 실패했습니다, {{ .err }}"
FormatDiskErr: "디스크 포맷에 실패했습니다, {{ .err }}"
MountDiskErr: "디스크 마운트에 실패했습니다, {{ .err }}"
UnMountDiskErr: "디스크 마운트 해제에 실패했습니다, {{ .err }}"
XfsNotFound: "xfs 파일 시스템이 감지되지 않았습니다, 먼저 xfsprogs 를 설치하세요"
XfsNotFound: "xfs 파일 시스템이 감지되지 않았습니다, 먼저 xfsprogs 를 설치하세요"
15 changes: 14 additions & 1 deletion agent/i18n/lang/ms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ ErrGroupIsDefault: 'Kumpulan lalai, tidak boleh dipadamkan'
ErrGroupIsInWebsiteUse: 'Kumpulan sedang digunakan oleh tapak web lain dan tidak boleh dipadamkan.'
Decrypt: "Dekripsi"

#agent
ErrAgentAccountBound: 'Akaun ini telah dipautkan kepada ejen dan tidak boleh dipadam. Sila semak dan cuba lagi!'
ErrAgentAccountUnavailable: 'Maklumat sambungan akaun tidak tersedia. Ralat: {{ .err }}. Sila semak dan cuba lagi!'
ErrAgentProviderNotSupported: 'Penyedia ejen ini tidak disokong. Sila semak dan cuba lagi!'
ErrAgentAccountRequired: 'Sila pilih akaun ejen dan cuba lagi.'
ErrAgentAccountNotVerified: 'Akaun belum disahkan. Sila semak dan cuba lagi!'
ErrAgentProviderMismatch: 'Penyedia akaun tidak sepadan. Sila semak dan cuba lagi!'
ErrAgentBaseURLRequired: 'Base URL tidak boleh kosong. Sila semak dan cuba lagi!'
ErrAgentApiKeyRequired: 'API Key tidak boleh kosong. Sila semak dan cuba lagi!'
ErrAgentComposeRequired: 'Kandungan compose tersuai tidak boleh kosong. Sila semak dan cuba lagi!'
ErrAgentIDRequired: 'ID ejen tidak boleh kosong. Sila semak dan cuba lagi!'
ErrAgentAccountIDRequired: 'ID akaun tidak boleh kosong. Sila semak dan cuba lagi!'

#sandaran
Localhost: 'Mesin Tempatan'
ErrBackupInUsed: 'Akaun sandaran telah digunakan dalam tugas yang dijadualkan dan tidak boleh dipadamkan.'
Expand Down Expand Up @@ -527,4 +540,4 @@ PartitionDiskErr: "Gagal membahagikan, {{ .err }}"
FormatDiskErr: "Gagal memformat cakera, {{ .err }}"
MountDiskErr: "Gagal mengkaitkan cakera, {{ .err }}"
UnMountDiskErr: "Gagal nyahkaitkan cakera, {{ .err }}"
XfsNotFound: "Sistem fail xfs tidak dikesan, sila pasang xfsprogs terlebih dahulu"
XfsNotFound: "Sistem fail xfs tidak dikesan, sila pasang xfsprogs terlebih dahulu"
15 changes: 14 additions & 1 deletion agent/i18n/lang/pt-BR.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ ErrGroupIsDefault: 'Grupo padrão, não pode ser excluído'
ErrGroupIsInWebsiteUse: 'O grupo está sendo usado por outro site e não pode ser excluído.'
Decrypt: "Descriptografar"

#agent
ErrAgentAccountBound: 'Esta conta está vinculada a um agente e não pode ser excluída. Verifique e tente novamente!'
ErrAgentAccountUnavailable: 'As informações de conexão da conta não estão disponíveis. Erro: {{ .err }}. Verifique e tente novamente!'
ErrAgentProviderNotSupported: 'Este provedor de agente não é suportado. Verifique e tente novamente!'
ErrAgentAccountRequired: 'Selecione uma conta de agente e tente novamente.'
ErrAgentAccountNotVerified: 'A conta não foi verificada. Verifique e tente novamente!'
ErrAgentProviderMismatch: 'O provedor da conta não corresponde. Verifique e tente novamente!'
ErrAgentBaseURLRequired: 'Base URL não pode estar vazio. Verifique e tente novamente!'
ErrAgentApiKeyRequired: 'API Key não pode estar vazio. Verifique e tente novamente!'
ErrAgentComposeRequired: 'O conteúdo personalizado do compose não pode estar vazio. Verifique e tente novamente!'
ErrAgentIDRequired: 'ID do agente não pode estar vazio. Verifique e tente novamente!'
ErrAgentAccountIDRequired: 'ID da conta não pode estar vazio. Verifique e tente novamente!'

#backup
Localhost: 'Máquina Local'
ErrBackupInUsed: 'A conta de backup foi usada na tarefa agendada e não pode ser excluída.'
Expand Down Expand Up @@ -527,4 +540,4 @@ PartitionDiskErr: "Falha ao particionar, {{ .err }}"
FormatDiskErr: "Falha ao formatar disco, {{ .err }}"
MountDiskErr: "Falha ao montar disco, {{ .err }}"
UnMountDiskErr: "Falha ao desmontar disco, {{ .err }}"
XfsNotFound: "Sistema de arquivos xfs não detectado, por favor instale xfsprogs primeiro"
XfsNotFound: "Sistema de arquivos xfs não detectado, por favor instale xfsprogs primeiro"
Loading
Loading