import { HttpService } from '@nestjs/axios' import { Injectable } from '@nestjs/common' import { lastValueFrom } from 'rxjs' import { ServiceResponse } from '@/response/response.interface' import { HttpStatusCode } from '@/response/status-code.enum' @Injectable() export class AgentServerHttpService { private readonly baseUrl = 'http://192.168.206.189:8083/api' constructor(private readonly httpService: HttpService) {} private async makeRequest( endpoint: string, params?: Record ): Promise> { try { const url = `${this.baseUrl}/${endpoint}` const responseObservable = await this.httpService.get>( url, { params } ) const { data } = await lastValueFrom(responseObservable) return data } catch (error) { return { code: HttpStatusCode.INTERNAL_SERVER_ERROR, msg: error.message, data: null as T } } } async makeRequestPost( endpoint: string, params?: Record ): Promise> { try { const url = `${this.baseUrl}/${endpoint}` const responseObservable = await this.httpService.post< ServiceResponse >(url, params, { headers: { 'Content-Type': 'application/json' } }) const { data } = await lastValueFrom(responseObservable) return data } catch (error) { return { code: HttpStatusCode.INTERNAL_SERVER_ERROR, msg: error.message, data: null as T } } } async listStaffs(): Promise> { return this.makeRequest('listStaffs') } async getStaffProfile( staff_id: string ): Promise> { return this.makeRequest('getStaffProfile', { staff_id }) } async getUserProfile(user_id: string): Promise> { return this.makeRequest('getUserProfile', { user_id }) } async listUsers( user_name: string, user_union_id: string ): Promise> { return this.makeRequest('listUsers', { user_name, user_union_id }) } async getDialogueHistory( staff_id: string, user_id: string, recent_minutes: string ): Promise> { return this.makeRequest('getDialogueHistory', { staff_id, user_id, recent_minutes }) } async listModels(): Promise> { return this.makeRequest('listModels') } async listScenes(): Promise> { return this.makeRequest('listScenes') } async getBasePrompt(scene: string): Promise> { return this.makeRequest('getBasePrompt', { scene }) } async runPrompt(params: any): Promise> { return this.makeRequestPost('runPrompt', params) } async formatForPrompt(params: any): Promise> { return this.makeRequestPost('formatForPrompt', params) } }