|
import { genUUID } from "./utils" |
|
import { Language } from "@/types" |
|
import axios from "axios" |
|
|
|
export interface StartRequestConfig { |
|
channel: string |
|
userId: number |
|
graphName: string |
|
language: Language |
|
voiceType: "male" | "female" |
|
prompt?: string |
|
greeting?: string |
|
coze_token?: string |
|
coze_bot_id?: string |
|
coze_base_url?: string |
|
dify_api_key?: string |
|
} |
|
|
|
interface GenAgoraDataConfig { |
|
userId: string | number |
|
channel: string |
|
} |
|
|
|
export const apiGenAgoraData = async (config: GenAgoraDataConfig) => { |
|
|
|
const url = `/api/token/generate` |
|
const { userId, channel } = config |
|
const data = { |
|
request_id: genUUID(), |
|
uid: userId, |
|
channel_name: channel, |
|
} |
|
let resp: any = await axios.post(url, data) |
|
resp = resp.data || {} |
|
return resp |
|
} |
|
|
|
export const apiStartService = async ( |
|
config: StartRequestConfig, |
|
): Promise<any> => { |
|
|
|
const url = `/api/agents/start` |
|
const { |
|
channel, |
|
userId, |
|
graphName, |
|
language, |
|
voiceType, |
|
greeting, |
|
prompt, |
|
coze_token, |
|
coze_bot_id, |
|
coze_base_url, |
|
dify_api_key, |
|
} = config |
|
const data = { |
|
request_id: genUUID(), |
|
channel_name: channel, |
|
user_uid: userId, |
|
graph_name: graphName, |
|
language, |
|
voice_type: voiceType, |
|
greeting: greeting ?? undefined, |
|
prompt: prompt ?? undefined, |
|
coze_token: coze_token ?? undefined, |
|
coze_bot_id: coze_bot_id ?? undefined, |
|
coze_base_url: coze_base_url ?? undefined, |
|
dify_api_key: dify_api_key ?? undefined |
|
} |
|
let resp: any = await axios.post(url, data) |
|
resp = resp.data || {} |
|
return resp |
|
} |
|
|
|
export const apiStopService = async (channel: string) => { |
|
|
|
const url = `/api/agents/stop` |
|
const data = { |
|
request_id: genUUID(), |
|
channel_name: channel, |
|
} |
|
let resp: any = await axios.post(url, data) |
|
resp = resp.data || {} |
|
return resp |
|
} |
|
|
|
export const apiGetDocumentList = async () => { |
|
|
|
const url = `/api/vector/document/preset/list` |
|
let resp: any = await axios.get(url) |
|
resp = resp.data || {} |
|
if (resp.code !== "0") { |
|
throw new Error(resp.msg) |
|
} |
|
return resp |
|
} |
|
|
|
export const apiUpdateDocument = async (options: { |
|
channel: string |
|
collection: string |
|
fileName: string |
|
}) => { |
|
|
|
const url = `/api/vector/document/update` |
|
const { channel, collection, fileName } = options |
|
const data = { |
|
request_id: genUUID(), |
|
channel_name: channel, |
|
collection: collection, |
|
file_name: fileName, |
|
} |
|
let resp: any = await axios.post(url, data) |
|
resp = resp.data || {} |
|
return resp |
|
} |
|
|
|
|
|
export const apiPing = async (channel: string) => { |
|
|
|
const url = `/api/agents/ping` |
|
const data = { |
|
request_id: genUUID(), |
|
channel_name: channel, |
|
} |
|
let resp: any = await axios.post(url, data) |
|
resp = resp.data || {} |
|
return resp |
|
} |
|
|