|
@@ -1,97 +1,139 @@
|
|
|
-import { Inject, Injectable } from '@nestjs/common'
|
|
|
+import { Injectable } from '@nestjs/common'
|
|
|
|
|
|
import { IAgentServerService } from '@/interface/agent-server.interface'
|
|
|
import { ServiceResponse } from '@/response/response.interface'
|
|
|
-import { HttpStatusCode } from '@/response/status-code.enum'
|
|
|
+import { BusinessCode, HttpStatusCode } from '@/response/status-code.enum'
|
|
|
+
|
|
|
+import { AgentServerHttpService } from './agent-server-http.service'
|
|
|
|
|
|
@Injectable()
|
|
|
export class AgentServerService implements IAgentServerService {
|
|
|
- constructor(
|
|
|
- @Inject('IAgentServerService')
|
|
|
- private readonly httpService: IAgentServerService
|
|
|
- ) {}
|
|
|
+ constructor(private readonly httpService: AgentServerHttpService) {}
|
|
|
|
|
|
async listStaffs(): Promise<ServiceResponse<StaffsType[]>> {
|
|
|
- return this.httpService.listStaffs()
|
|
|
+ const res = await this.httpService.listStaffs()
|
|
|
+ if (res.code !== HttpStatusCode.OK) {
|
|
|
+ return {
|
|
|
+ code: BusinessCode.BAD_REQUEST,
|
|
|
+ msg: '获取客服列表失败',
|
|
|
+ data: null
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ code: BusinessCode.SUCCESS,
|
|
|
+ msg: '获取客服列表成功',
|
|
|
+ data: res.data
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- async getStaffProfile(
|
|
|
- staff_id: string
|
|
|
- ): Promise<ServiceResponse<StaffProfile>> {
|
|
|
- if (!staff_id) {
|
|
|
+ async listScenes(): Promise<ServiceResponse<Scene[]>> {
|
|
|
+ const res = await this.httpService.listScenes()
|
|
|
+ if (res.code !== HttpStatusCode.OK) {
|
|
|
return {
|
|
|
- code: HttpStatusCode.BAD_REQUEST,
|
|
|
- msg: 'staff_id不能为空',
|
|
|
+ code: BusinessCode.BAD_REQUEST,
|
|
|
+ msg: '获取场景列表失败',
|
|
|
data: null
|
|
|
}
|
|
|
}
|
|
|
- return this.httpService.getStaffProfile(staff_id)
|
|
|
+ return {
|
|
|
+ code: BusinessCode.SUCCESS,
|
|
|
+ msg: '获取场景列表成功',
|
|
|
+ data: res.data
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- async getUserProfile(user_id: string): Promise<ServiceResponse<UserProfile>> {
|
|
|
- if (!user_id) {
|
|
|
+ async listModels(): Promise<ServiceResponse<Model[]>> {
|
|
|
+ const res = await this.httpService.listModels()
|
|
|
+ if (res.code !== HttpStatusCode.OK) {
|
|
|
return {
|
|
|
- code: HttpStatusCode.BAD_REQUEST,
|
|
|
- msg: 'user_id不能为空',
|
|
|
+ code: BusinessCode.BAD_REQUEST,
|
|
|
+ msg: '获取模型列表失败',
|
|
|
data: null
|
|
|
}
|
|
|
}
|
|
|
- return this.httpService.getUserProfile(user_id)
|
|
|
+ return {
|
|
|
+ code: BusinessCode.SUCCESS,
|
|
|
+ msg: '获取模型列表成功',
|
|
|
+ data: res.data
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- async listUsers(
|
|
|
- user_name: string,
|
|
|
- user_union_id: string
|
|
|
- ): Promise<ServiceResponse<UserProfile[]>> {
|
|
|
- if (!user_name && !user_union_id) {
|
|
|
+ async getBasePrompt(scene: string): Promise<ServiceResponse<string>> {
|
|
|
+ const res = await this.httpService.getBasePrompt(scene)
|
|
|
+ if (res.code !== HttpStatusCode.OK) {
|
|
|
return {
|
|
|
- code: HttpStatusCode.BAD_REQUEST,
|
|
|
- msg: 'user_name和user_union_id不能同时为空',
|
|
|
+ code: BusinessCode.BAD_REQUEST,
|
|
|
+ msg: '获取基础提示词失败',
|
|
|
data: null
|
|
|
}
|
|
|
}
|
|
|
- return this.httpService.listUsers(user_name, user_union_id)
|
|
|
+ return {
|
|
|
+ code: BusinessCode.SUCCESS,
|
|
|
+ msg: '获取基础提示词成功',
|
|
|
+ data: res.data
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
async getDialogueHistory(
|
|
|
- staff_id: string,
|
|
|
- user_id: string,
|
|
|
- recent_minutes: string
|
|
|
- ): Promise<ServiceResponse<DialogueHistory[]>> {
|
|
|
- if (!staff_id || !user_id) {
|
|
|
+ staffId: string,
|
|
|
+ userName: string,
|
|
|
+ unionId: string,
|
|
|
+ recentMinutes: string
|
|
|
+ ): Promise<ServiceResponse<UserInfo[]>> {
|
|
|
+ const user = await this.httpServiceListUsers(userName, unionId)
|
|
|
+ if (user.length === 0) {
|
|
|
return {
|
|
|
- code: HttpStatusCode.BAD_REQUEST,
|
|
|
- msg: 'staff_id和user_id不能为空',
|
|
|
+ code: BusinessCode.BAD_REQUEST,
|
|
|
+ msg: '用户不存在',
|
|
|
data: null
|
|
|
}
|
|
|
}
|
|
|
- return this.httpService.getDialogueHistory(
|
|
|
- staff_id,
|
|
|
- user_id,
|
|
|
- recent_minutes
|
|
|
+
|
|
|
+ const dialogueHistory = await Promise.all(
|
|
|
+ user.map(async (user) => {
|
|
|
+ const res = await this.getDialogueHistoryByUserId(
|
|
|
+ staffId,
|
|
|
+ user,
|
|
|
+ recentMinutes
|
|
|
+ )
|
|
|
+ return res
|
|
|
+ })
|
|
|
)
|
|
|
- }
|
|
|
|
|
|
- async listModels(): Promise<ServiceResponse<Model[]>> {
|
|
|
- return this.httpService.listModels()
|
|
|
+ return {
|
|
|
+ code: BusinessCode.SUCCESS,
|
|
|
+ msg: '获取对话历史成功',
|
|
|
+ data: dialogueHistory
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- async listScenes(): Promise<ServiceResponse<any[]>> {
|
|
|
- return this.httpService.listScenes()
|
|
|
+ async httpServiceListUsers(
|
|
|
+ userName: string,
|
|
|
+ unionId: string
|
|
|
+ ): Promise<UserProfile[]> {
|
|
|
+ const res = await this.httpService.listUsers(userName, unionId)
|
|
|
+ if (res.code !== HttpStatusCode.OK) {
|
|
|
+ return []
|
|
|
+ }
|
|
|
+ return res.data
|
|
|
}
|
|
|
|
|
|
- async getBasePrompt(): Promise<ServiceResponse<string>> {
|
|
|
- return this.httpService.getBasePrompt()
|
|
|
- }
|
|
|
+ async getDialogueHistoryByUserId(
|
|
|
+ staffId: string,
|
|
|
+ user: UserProfile,
|
|
|
+ recentMinutes: string
|
|
|
+ ): Promise<UserInfo> {
|
|
|
+ const res = await this.httpService.getDialogueHistory(
|
|
|
+ staffId,
|
|
|
+ user.third_party_user_id,
|
|
|
+ recentMinutes
|
|
|
+ )
|
|
|
|
|
|
- async runPrompt(prompt: any): Promise<ServiceResponse<any>> {
|
|
|
- if (!prompt) {
|
|
|
- return {
|
|
|
- code: HttpStatusCode.BAD_REQUEST,
|
|
|
- msg: 'prompt不能为空',
|
|
|
- data: null
|
|
|
- }
|
|
|
+ const userInfo: UserInfo = {
|
|
|
+ ...user,
|
|
|
+ history: res.data || []
|
|
|
}
|
|
|
- return this.httpService.runPrompt(prompt)
|
|
|
+
|
|
|
+ return userInfo
|
|
|
}
|
|
|
}
|