agent-list-http.service.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { Injectable } from '@nestjs/common'
  2. import { ServiceResponse } from '@/response/response.interface'
  3. import { HttpClientService } from '@/shared/http-client/http-client.service'
  4. @Injectable()
  5. export class AgentListHttpService {
  6. private readonly baseUrl = 'http://192.168.206.189:8083/api'
  7. constructor(private readonly httpClientService: HttpClientService) {}
  8. private async makeRequest<T>(
  9. endpoint: string,
  10. params?: Record<string, any>
  11. ): Promise<ServiceResponse<T>> {
  12. const url = `${this.baseUrl}/${endpoint}`
  13. return this.httpClientService.get<T>(url, params)
  14. }
  15. async makeRequestPost<T>(
  16. endpoint: string,
  17. params?: Record<string, any>
  18. ): Promise<ServiceResponse<T>> {
  19. const url = `${this.baseUrl}/${endpoint}`
  20. return this.httpClientService.post<T>(url, params)
  21. }
  22. async getNativeAgentList(
  23. params: Record<string, any>
  24. ): Promise<ServiceResponse<AgentListType[]>> {
  25. return this.makeRequest<AgentListType[]>('getNativeAgentList', params)
  26. }
  27. async getNativeAgentConfiguration(
  28. agent_id: string
  29. ): Promise<ServiceResponse<AgentConfigurationType[]>> {
  30. return this.makeRequest<AgentConfigurationType[]>(
  31. 'getNativeAgentConfiguration',
  32. { agent_id }
  33. )
  34. }
  35. async saveNativeAgentConfiguration(
  36. params: SaveAgentConfigurationType
  37. ): Promise<ServiceResponse<SaveAgentConfigurationType>> {
  38. console.log(params)
  39. return this.makeRequestPost<SaveAgentConfigurationType>(
  40. 'saveNativeAgentConfiguration',
  41. params
  42. )
  43. }
  44. async getToolList(): Promise<ServiceResponse<any>> {
  45. return this.makeRequest<any>('getToolList')
  46. }
  47. async deleteNativeAgentConfiguration(
  48. agent_id: number
  49. ): Promise<ServiceResponse<any>> {
  50. return this.makeRequestPost<any>('deleteNativeAgentConfiguration', {
  51. agent_id
  52. })
  53. }
  54. }