mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-25 16:43:55 +08:00
feat: 初始化移动端项目
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
import type {
|
||||
Agent,
|
||||
AgentCreateData,
|
||||
AgentDetail,
|
||||
ModelOption,
|
||||
RoleTemplate,
|
||||
} from './types'
|
||||
import { http } from '@/http/request/alova'
|
||||
|
||||
// 获取智能体详情
|
||||
export function getAgentDetail(id: string) {
|
||||
return http.Get<AgentDetail>(`/agent/${id}`, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
cacheFor: {
|
||||
expire: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 获取角色模板列表
|
||||
export function getRoleTemplates() {
|
||||
return http.Get<RoleTemplate[]>('/agent/template', {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
cacheFor: {
|
||||
expire: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 获取模型选项
|
||||
export function getModelOptions(modelType: string, modelName: string = '') {
|
||||
return http.Get<ModelOption[]>('/models/names', {
|
||||
params: {
|
||||
modelType,
|
||||
modelName,
|
||||
},
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
cacheFor: {
|
||||
expire: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 获取智能体列表
|
||||
export function getAgentList() {
|
||||
return http.Get<Agent[]>('/agent/list', {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
cacheFor: {
|
||||
expire: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 创建智能体
|
||||
export function createAgent(data: AgentCreateData) {
|
||||
return http.Post<string>('/agent', data, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 删除智能体
|
||||
export function deleteAgent(id: string) {
|
||||
return http.Delete(`/agent/${id}`, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 获取TTS音色列表
|
||||
export function getTTSVoices(ttsModelId: string, voiceName: string = '') {
|
||||
return http.Get<{ id: string, name: string }[]>(`/models/${ttsModelId}/voices`, {
|
||||
params: {
|
||||
voiceName,
|
||||
},
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
cacheFor: {
|
||||
expire: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 更新智能体
|
||||
export function updateAgent(id: string, data: Partial<AgentDetail>) {
|
||||
return http.Put(`/agent/${id}`, data, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: true,
|
||||
},
|
||||
cacheFor: {
|
||||
expire: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 获取插件列表
|
||||
export function getPluginFunctions() {
|
||||
return http.Get<any[]>(`/models/provider/plugin/names`, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
cacheFor: {
|
||||
expire: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 获取mcp接入点
|
||||
export function getMcpAddress(agentId: string) {
|
||||
return http.Get<string>(`/agent/mcp/address/${agentId}`, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 获取mcp工具
|
||||
export function getMcpTools(agentId: string) {
|
||||
return http.Get<string[]>(`/agent/mcp/tools/${agentId}`, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
cacheFor: {
|
||||
expire: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 获取声纹列表
|
||||
export function getVoicePrintList(agentId: string) {
|
||||
return http.Get<any[]>(`/agent/voice-print/list/${agentId}`, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
cacheFor: {
|
||||
expire: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 获取语音对话记录
|
||||
export function getChatHistoryUser(agentId: string) {
|
||||
return http.Get<any[]>(`/agent/${agentId}/chat-history/user`, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
cacheFor: {
|
||||
expire: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 新增声纹说话人
|
||||
export function createVoicePrint(data: { agentId: string, audioId: string, sourceName: string, introduce: string }) {
|
||||
return http.Post('/agent/voice-print', data, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
// 智能体列表数据类型
|
||||
export interface Agent {
|
||||
id: string
|
||||
agentName: string
|
||||
ttsModelName: string
|
||||
ttsVoiceName: string
|
||||
llmModelName: string
|
||||
vllmModelName: string
|
||||
memModelId: string
|
||||
systemPrompt: string
|
||||
summaryMemory: string | null
|
||||
lastConnectedAt: string | null
|
||||
deviceCount: number
|
||||
}
|
||||
|
||||
// 智能体创建数据类型
|
||||
export interface AgentCreateData {
|
||||
agentName: string
|
||||
}
|
||||
|
||||
// 智能体详情数据类型
|
||||
export interface AgentDetail {
|
||||
id: string
|
||||
userId: string
|
||||
agentCode: string
|
||||
agentName: string
|
||||
asrModelId: string
|
||||
vadModelId: string
|
||||
llmModelId: string
|
||||
vllmModelId: string
|
||||
ttsModelId: string
|
||||
ttsVoiceId: string
|
||||
memModelId: string
|
||||
intentModelId: string
|
||||
chatHistoryConf: number
|
||||
systemPrompt: string
|
||||
summaryMemory: string
|
||||
langCode: string
|
||||
language: string
|
||||
sort: number
|
||||
creator: string
|
||||
createdAt: string
|
||||
updater: string
|
||||
updatedAt: string
|
||||
functions: AgentFunction[]
|
||||
}
|
||||
|
||||
export interface AgentFunction {
|
||||
id?: string
|
||||
agentId?: string
|
||||
pluginId: string
|
||||
paramInfo: Record<string, string | number | boolean> | null
|
||||
}
|
||||
|
||||
// 角色模板数据类型
|
||||
export interface RoleTemplate {
|
||||
id: string
|
||||
agentCode: string
|
||||
agentName: string
|
||||
asrModelId: string
|
||||
vadModelId: string
|
||||
llmModelId: string
|
||||
vllmModelId: string
|
||||
ttsModelId: string
|
||||
ttsVoiceId: string
|
||||
memModelId: string
|
||||
intentModelId: string
|
||||
chatHistoryConf: number
|
||||
systemPrompt: string
|
||||
summaryMemory: string
|
||||
langCode: string
|
||||
language: string
|
||||
sort: number
|
||||
creator: string
|
||||
createdAt: string
|
||||
updater: string
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
// 模型选项数据类型
|
||||
export interface ModelOption {
|
||||
id: string
|
||||
modelName: string
|
||||
}
|
||||
|
||||
export interface PluginField {
|
||||
key: string
|
||||
type: string
|
||||
label: string
|
||||
default: string
|
||||
selected?: boolean
|
||||
editing?: boolean
|
||||
}
|
||||
|
||||
export interface PluginDefinition {
|
||||
id: string
|
||||
modelType: string
|
||||
providerCode: string
|
||||
name: string
|
||||
fields: PluginField[] // 注意:原始是字符串,需要先 JSON.parse
|
||||
sort: number
|
||||
updater: string
|
||||
updateDate: string
|
||||
creator: string
|
||||
createDate: string
|
||||
[key: string]: any
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
import { http } from '@/http/request/alova'
|
||||
|
||||
// 登录接口数据类型
|
||||
export interface LoginData {
|
||||
username: string
|
||||
password: string
|
||||
captcha: string
|
||||
captchaId: string
|
||||
areaCode?: string
|
||||
mobile?: string
|
||||
}
|
||||
|
||||
// 登录响应数据类型
|
||||
export interface LoginResponse {
|
||||
token: string
|
||||
expire: number
|
||||
clientHash: string
|
||||
}
|
||||
|
||||
// 验证码响应数据类型
|
||||
export interface CaptchaResponse {
|
||||
captchaId: string
|
||||
captchaImage: string
|
||||
}
|
||||
|
||||
// 获取验证码
|
||||
export function getCaptcha(uuid: string) {
|
||||
return http.Get<string>('/user/captcha', {
|
||||
params: { uuid },
|
||||
meta: {
|
||||
ignoreAuth: true,
|
||||
toast: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 用户登录
|
||||
export function login(data: LoginData) {
|
||||
return http.Post<LoginResponse>('/user/login', data, {
|
||||
meta: {
|
||||
ignoreAuth: true,
|
||||
toast: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 用户信息响应数据类型
|
||||
export interface UserInfo {
|
||||
id: number
|
||||
username: string
|
||||
realName: string
|
||||
email: string
|
||||
mobile: string
|
||||
status: number
|
||||
superAdmin: number
|
||||
}
|
||||
|
||||
// 公共配置响应数据类型
|
||||
export interface PublicConfig {
|
||||
enableMobileRegister: boolean
|
||||
version: string
|
||||
year: string
|
||||
allowUserRegister: boolean
|
||||
mobileAreaList: Array<{
|
||||
name: string
|
||||
key: string
|
||||
}>
|
||||
beianIcpNum: string
|
||||
beianGaNum: string
|
||||
name: string
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
export function getUserInfo() {
|
||||
return http.Get<UserInfo>('/user/info', {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 获取公共配置
|
||||
export function getPublicConfig() {
|
||||
return http.Get<PublicConfig>('/user/pub-config', {
|
||||
meta: {
|
||||
ignoreAuth: true,
|
||||
toast: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 注册数据类型
|
||||
export interface RegisterData {
|
||||
username: string
|
||||
password: string
|
||||
confirmPassword: string
|
||||
captcha: string
|
||||
captchaId: string
|
||||
areaCode: string
|
||||
mobile: string
|
||||
mobileCaptcha: string
|
||||
}
|
||||
|
||||
// 发送短信验证码
|
||||
export function sendSmsCode(data: {
|
||||
phone: string
|
||||
captcha: string
|
||||
captchaId: string
|
||||
}) {
|
||||
return http.Post('/user/smsVerification', data, {
|
||||
meta: {
|
||||
ignoreAuth: true,
|
||||
toast: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 用户注册
|
||||
export function register(data: RegisterData) {
|
||||
return http.Post('/user/register', data, {
|
||||
meta: {
|
||||
ignoreAuth: true,
|
||||
toast: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import type {
|
||||
ChatMessage,
|
||||
ChatSessionsResponse,
|
||||
GetSessionsParams,
|
||||
} from './types'
|
||||
import { http } from '@/http/request/alova'
|
||||
|
||||
/**
|
||||
* 获取聊天会话列表
|
||||
* @param agentId 智能体ID
|
||||
* @param params 分页参数
|
||||
*/
|
||||
export function getChatSessions(agentId: string, params: GetSessionsParams) {
|
||||
return http.Get<ChatSessionsResponse>(`/agent/${agentId}/sessions`, {
|
||||
params,
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取聊天记录详情
|
||||
* @param agentId 智能体ID
|
||||
* @param sessionId 会话ID
|
||||
*/
|
||||
export function getChatHistory(agentId: string, sessionId: string) {
|
||||
return http.Get<ChatMessage[]>(`/agent/${agentId}/chat-history/${sessionId}`, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取音频下载ID
|
||||
* @param audioId 音频ID
|
||||
*/
|
||||
export function getAudioId(audioId: string) {
|
||||
return http.Post<string>(`/agent/audio/${audioId}`, {}, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取音频播放地址
|
||||
* @param downloadId 下载ID
|
||||
*/
|
||||
export function getAudioPlayUrl(downloadId: string) {
|
||||
// 根据需求文档,这个是直接返回二进制的,所以我们直接构造URL
|
||||
return `/agent/play/${downloadId}`
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './chat-history'
|
||||
export * from './types'
|
||||
@@ -0,0 +1,38 @@
|
||||
// 聊天会话列表项
|
||||
export interface ChatSession {
|
||||
sessionId: string
|
||||
createdAt: string
|
||||
chatCount: number
|
||||
}
|
||||
|
||||
// 聊天会话列表响应
|
||||
export interface ChatSessionsResponse {
|
||||
total: number
|
||||
list: ChatSession[]
|
||||
}
|
||||
|
||||
// 聊天消息
|
||||
export interface ChatMessage {
|
||||
createdAt: string
|
||||
chatType: 1 | 2 // 1是用户,2是AI
|
||||
content: string
|
||||
audioId: string | null
|
||||
macAddress: string
|
||||
}
|
||||
|
||||
// 用户消息内容(需要解析JSON)
|
||||
export interface UserMessageContent {
|
||||
speaker: string
|
||||
content: string
|
||||
}
|
||||
|
||||
// 获取聊天会话列表参数
|
||||
export interface GetSessionsParams {
|
||||
page: number
|
||||
limit: number
|
||||
}
|
||||
|
||||
// 音频播放相关
|
||||
export interface AudioResponse {
|
||||
data: string // 音频下载ID
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import type { Device, FirmwareType } from './types'
|
||||
import { http } from '@/http/request/alova'
|
||||
|
||||
/**
|
||||
* 获取设备类型列表
|
||||
*/
|
||||
export function getFirmwareTypes() {
|
||||
return http.Get<FirmwareType[]>('/admin/dict/data/type/FIRMWARE_TYPE')
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取绑定设备列表
|
||||
* @param agentId 智能体ID
|
||||
*/
|
||||
export function getBindDevices(agentId: string) {
|
||||
return http.Get<Device[]>(`/device/bind/${agentId}`, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
cacheFor: {
|
||||
expire: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加设备
|
||||
* @param agentId 智能体ID
|
||||
* @param code 验证码
|
||||
*/
|
||||
export function bindDevice(agentId: string, code: string) {
|
||||
return http.Post(`/device/bind/${agentId}/${code}`, null)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置设备OTA升级开关
|
||||
* @param deviceId 设备ID (MAC地址)
|
||||
* @param autoUpdate 是否自动升级 0|1
|
||||
*/
|
||||
export function updateDeviceAutoUpdate(deviceId: string, autoUpdate: number) {
|
||||
return http.Put(`/device/update/${deviceId}`, {
|
||||
autoUpdate,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑设备
|
||||
* @param deviceId 设备ID (MAC地址)
|
||||
*/
|
||||
export function unbindDevice(deviceId: string) {
|
||||
return http.Post('/device/unbind', {
|
||||
deviceId,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './device'
|
||||
export * from './types'
|
||||
@@ -0,0 +1,21 @@
|
||||
export interface FirmwareType {
|
||||
name: string
|
||||
key: string
|
||||
}
|
||||
|
||||
export interface Device {
|
||||
id: string
|
||||
userId: string
|
||||
macAddress: string
|
||||
lastConnectedAt: string
|
||||
autoUpdate: number
|
||||
board: string
|
||||
alias?: string
|
||||
agentId: string
|
||||
appVersion: string
|
||||
sort: number
|
||||
updater?: string
|
||||
updateDate: string
|
||||
creator: string
|
||||
createDate: string
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './types'
|
||||
export * from './voiceprint'
|
||||
@@ -0,0 +1,29 @@
|
||||
// 声纹信息响应类型
|
||||
export interface VoicePrint {
|
||||
id: string
|
||||
audioId: string
|
||||
sourceName: string
|
||||
introduce: string
|
||||
createDate: string
|
||||
}
|
||||
|
||||
// 语音对话记录类型
|
||||
export interface ChatHistory {
|
||||
content: string
|
||||
audioId: string
|
||||
}
|
||||
|
||||
// 创建说话人数据类型
|
||||
export interface CreateSpeakerData {
|
||||
agentId: string
|
||||
audioId: string
|
||||
sourceName: string
|
||||
introduce: string
|
||||
}
|
||||
|
||||
// 通用响应类型
|
||||
export interface ApiResponse<T = any> {
|
||||
code: number
|
||||
msg: string
|
||||
data: T
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import type {
|
||||
ChatHistory,
|
||||
CreateSpeakerData,
|
||||
VoicePrint,
|
||||
} from './types'
|
||||
import { http } from '@/http/request/alova'
|
||||
|
||||
// 获取声纹列表
|
||||
export function getVoicePrintList(agentId: string) {
|
||||
return http.Get<VoicePrint[]>(`/agent/voice-print/list/${agentId}`, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
cacheFor: {
|
||||
expire: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 获取语音对话记录(用于选择声纹向量)
|
||||
export function getChatHistory(agentId: string) {
|
||||
return http.Get<ChatHistory[]>(`/agent/${agentId}/chat-history/user`, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: false,
|
||||
},
|
||||
cacheFor: {
|
||||
expire: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 新增说话人
|
||||
export function createVoicePrint(data: CreateSpeakerData) {
|
||||
return http.Post<null>('/agent/voice-print', data, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 删除声纹
|
||||
export function deleteVoicePrint(id: string) {
|
||||
return http.Delete<null>(`/agent/voice-print/${id}`, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 更新声纹信息
|
||||
export function updateVoicePrint(data: VoicePrint) {
|
||||
return http.Put<null>('/agent/voice-print', data, {
|
||||
meta: {
|
||||
ignoreAuth: false,
|
||||
toast: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user