mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-27 04:49:47 +01:00
fix(rebase): restore upstream mobile/web assets and test harness paths
Align mobile agent/device pages with upstream API types, dedupe wifi selector merge artifacts, fix SM2 helpers, restore theme logo assets, and point run_tests.sh at the digital-human test runner.
This commit is contained in:
parent
0a05931a00
commit
b95a482f73
12 changed files with 666 additions and 276 deletions
|
|
@ -7,7 +7,7 @@ import type {
|
||||||
} from './types'
|
} from './types'
|
||||||
import { http } from '@/http/request/alova'
|
import { http } from '@/http/request/alova'
|
||||||
|
|
||||||
// Get agent details
|
// 获取智能体详情
|
||||||
export function getAgentDetail(id: string) {
|
export function getAgentDetail(id: string) {
|
||||||
return http.Get<AgentDetail>(`/agent/${id}`, {
|
return http.Get<AgentDetail>(`/agent/${id}`, {
|
||||||
meta: {
|
meta: {
|
||||||
|
|
@ -20,7 +20,7 @@ export function getAgentDetail(id: string) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get role template list
|
// 获取角色模板列表
|
||||||
export function getRoleTemplates() {
|
export function getRoleTemplates() {
|
||||||
return http.Get<RoleTemplate[]>('/agent/template', {
|
return http.Get<RoleTemplate[]>('/agent/template', {
|
||||||
meta: {
|
meta: {
|
||||||
|
|
@ -33,7 +33,7 @@ export function getRoleTemplates() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get model options
|
// 获取模型选项
|
||||||
export function getModelOptions(modelType: string, modelName: string = '') {
|
export function getModelOptions(modelType: string, modelName: string = '') {
|
||||||
return http.Get<ModelOption[]>('/models/names', {
|
return http.Get<ModelOption[]>('/models/names', {
|
||||||
params: {
|
params: {
|
||||||
|
|
@ -50,7 +50,7 @@ export function getModelOptions(modelType: string, modelName: string = '') {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get agent list
|
// 获取智能体列表
|
||||||
export function getAgentList() {
|
export function getAgentList() {
|
||||||
return http.Get<Agent[]>('/agent/list', {
|
return http.Get<Agent[]>('/agent/list', {
|
||||||
meta: {
|
meta: {
|
||||||
|
|
@ -63,7 +63,7 @@ export function getAgentList() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create agent
|
// 创建智能体
|
||||||
export function createAgent(data: AgentCreateData) {
|
export function createAgent(data: AgentCreateData) {
|
||||||
return http.Post<string>('/agent', data, {
|
return http.Post<string>('/agent', data, {
|
||||||
meta: {
|
meta: {
|
||||||
|
|
@ -73,7 +73,7 @@ export function createAgent(data: AgentCreateData) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete agent
|
// 删除智能体
|
||||||
export function deleteAgent(id: string) {
|
export function deleteAgent(id: string) {
|
||||||
return http.Delete(`/agent/${id}`, {
|
return http.Delete(`/agent/${id}`, {
|
||||||
meta: {
|
meta: {
|
||||||
|
|
@ -83,7 +83,7 @@ export function deleteAgent(id: string) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get TTS voice list
|
// 获取TTS音色列表
|
||||||
export function getTTSVoices(ttsModelId: string, voiceName: string = '') {
|
export function getTTSVoices(ttsModelId: string, voiceName: string = '') {
|
||||||
return http.Get<{ id: string, name: string }[]>(`/models/${ttsModelId}/voices`, {
|
return http.Get<{ id: string, name: string }[]>(`/models/${ttsModelId}/voices`, {
|
||||||
params: {
|
params: {
|
||||||
|
|
@ -99,7 +99,7 @@ export function getTTSVoices(ttsModelId: string, voiceName: string = '') {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update agent
|
// 更新智能体
|
||||||
export function updateAgent(id: string, data: Partial<AgentDetail>) {
|
export function updateAgent(id: string, data: Partial<AgentDetail>) {
|
||||||
return http.Put(`/agent/${id}`, data, {
|
return http.Put(`/agent/${id}`, data, {
|
||||||
meta: {
|
meta: {
|
||||||
|
|
@ -112,7 +112,7 @@ export function updateAgent(id: string, data: Partial<AgentDetail>) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get plugin list
|
// 获取插件列表
|
||||||
export function getPluginFunctions() {
|
export function getPluginFunctions() {
|
||||||
return http.Get<any[]>(`/models/provider/plugin/names`, {
|
return http.Get<any[]>(`/models/provider/plugin/names`, {
|
||||||
meta: {
|
meta: {
|
||||||
|
|
@ -125,17 +125,18 @@ export function getPluginFunctions() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get MCP access point
|
// 获取mcp接入点
|
||||||
export function getMcpAddress(agentId: string) {
|
export function getMcpAddress(agentId: string) {
|
||||||
return http.Get<string>(`/agent/mcp/address/${agentId}`, {
|
return http.Get<string>(`/agent/mcp/address/${agentId}`, {
|
||||||
meta: {
|
meta: {
|
||||||
ignoreAuth: false,
|
ignoreAuth: false,
|
||||||
toast: false,
|
toast: false,
|
||||||
|
isExposeError: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get MCP tools
|
// 获取mcp工具
|
||||||
export function getMcpTools(agentId: string) {
|
export function getMcpTools(agentId: string) {
|
||||||
return http.Get<string[]>(`/agent/mcp/tools/${agentId}`, {
|
return http.Get<string[]>(`/agent/mcp/tools/${agentId}`, {
|
||||||
meta: {
|
meta: {
|
||||||
|
|
@ -148,7 +149,7 @@ export function getMcpTools(agentId: string) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get voiceprint list
|
// 获取声纹列表
|
||||||
export function getVoicePrintList(agentId: string) {
|
export function getVoicePrintList(agentId: string) {
|
||||||
return http.Get<any[]>(`/agent/voice-print/list/${agentId}`, {
|
return http.Get<any[]>(`/agent/voice-print/list/${agentId}`, {
|
||||||
meta: {
|
meta: {
|
||||||
|
|
@ -161,7 +162,7 @@ export function getVoicePrintList(agentId: string) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get voice conversation records
|
// 获取语音对话记录
|
||||||
export function getChatHistoryUser(agentId: string) {
|
export function getChatHistoryUser(agentId: string) {
|
||||||
return http.Get<any[]>(`/agent/${agentId}/chat-history/user`, {
|
return http.Get<any[]>(`/agent/${agentId}/chat-history/user`, {
|
||||||
meta: {
|
meta: {
|
||||||
|
|
@ -174,7 +175,7 @@ export function getChatHistoryUser(agentId: string) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add voiceprint speaker
|
// 新增声纹说话人
|
||||||
export function createVoicePrint(data: { agentId: string, audioId: string, sourceName: string, introduce: string }) {
|
export function createVoicePrint(data: { agentId: string, audioId: string, sourceName: string, introduce: string }) {
|
||||||
return http.Post('/agent/voice-print', data, {
|
return http.Post('/agent/voice-print', data, {
|
||||||
meta: {
|
meta: {
|
||||||
|
|
@ -183,3 +184,39 @@ export function createVoicePrint(data: { agentId: string, audioId: string, sourc
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取智能体标签
|
||||||
|
export function getAgentTags(agentId: string) {
|
||||||
|
return http.Get<any[]>(`/agent/${agentId}/tags`, {
|
||||||
|
meta: {
|
||||||
|
ignoreAuth: false,
|
||||||
|
toast: false,
|
||||||
|
},
|
||||||
|
cacheFor: {
|
||||||
|
expire: 0,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新智能体标签
|
||||||
|
export function updateAgentTags(agentId: string, data) {
|
||||||
|
return http.Put(`/agent/${agentId}/tags`, data, {
|
||||||
|
meta: {
|
||||||
|
ignoreAuth: false,
|
||||||
|
isExposeError: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取所有语言
|
||||||
|
export function getAllLanguage(modelId: string) {
|
||||||
|
return http.Get<{ id: string, name: string, languages: string }[]>(`/models/${modelId}/voices`, {
|
||||||
|
meta: {
|
||||||
|
ignoreAuth: false,
|
||||||
|
toast: false,
|
||||||
|
},
|
||||||
|
cacheFor: {
|
||||||
|
expire: 0,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Agent list data type
|
// 智能体列表数据类型
|
||||||
export interface Agent {
|
export interface Agent {
|
||||||
id: string
|
id: string
|
||||||
agentName: string
|
agentName: string
|
||||||
|
|
@ -11,14 +11,15 @@ export interface Agent {
|
||||||
summaryMemory: string | null
|
summaryMemory: string | null
|
||||||
lastConnectedAt: string | null
|
lastConnectedAt: string | null
|
||||||
deviceCount: number
|
deviceCount: number
|
||||||
|
tags: Record<string, string>[]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Agent creation data type
|
// 智能体创建数据类型
|
||||||
export interface AgentCreateData {
|
export interface AgentCreateData {
|
||||||
agentName: string
|
agentName: string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Agent details data type
|
// 智能体详情数据类型
|
||||||
export interface AgentDetail {
|
export interface AgentDetail {
|
||||||
id: string
|
id: string
|
||||||
userId: string
|
userId: string
|
||||||
|
|
@ -43,7 +44,20 @@ export interface AgentDetail {
|
||||||
createdAt: string
|
createdAt: string
|
||||||
updater: string
|
updater: string
|
||||||
updatedAt: string
|
updatedAt: string
|
||||||
|
ttsLanguage: string
|
||||||
|
ttsVolume: number
|
||||||
|
ttsRate: number
|
||||||
|
ttsPitch: number
|
||||||
functions: AgentFunction[]
|
functions: AgentFunction[]
|
||||||
|
contextProviders: Providers[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Providers {
|
||||||
|
url: string
|
||||||
|
headers: Array<{
|
||||||
|
key: string
|
||||||
|
value: string
|
||||||
|
}>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AgentFunction {
|
export interface AgentFunction {
|
||||||
|
|
@ -53,7 +67,7 @@ export interface AgentFunction {
|
||||||
paramInfo: Record<string, string | number | boolean> | null
|
paramInfo: Record<string, string | number | boolean> | null
|
||||||
}
|
}
|
||||||
|
|
||||||
// Role template data type
|
// 角色模板数据类型
|
||||||
export interface RoleTemplate {
|
export interface RoleTemplate {
|
||||||
id: string
|
id: string
|
||||||
agentCode: string
|
agentCode: string
|
||||||
|
|
@ -78,7 +92,7 @@ export interface RoleTemplate {
|
||||||
updatedAt: string
|
updatedAt: string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Model options data type
|
// 模型选项数据类型
|
||||||
export interface ModelOption {
|
export interface ModelOption {
|
||||||
id: string
|
id: string
|
||||||
modelName: string
|
modelName: string
|
||||||
|
|
@ -98,7 +112,7 @@ export interface PluginDefinition {
|
||||||
modelType: string
|
modelType: string
|
||||||
providerCode: string
|
providerCode: string
|
||||||
name: string
|
name: string
|
||||||
fields: PluginField[] // Note: Original is string, need to JSON.parse first
|
fields: PluginField[] // 注意:原始是字符串,需要先 JSON.parse
|
||||||
sort: number
|
sort: number
|
||||||
updater: string
|
updater: string
|
||||||
updateDate: string
|
updateDate: string
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@
|
||||||
"type": "page",
|
"type": "page",
|
||||||
"layout": "default",
|
"layout": "default",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "Settings",
|
"navigationBarTitleText": "设置",
|
||||||
"navigationStyle": "custom"
|
"navigationStyle": "custom"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -2,29 +2,25 @@
|
||||||
{
|
{
|
||||||
"layout": "default",
|
"layout": "default",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "Edit Sources",
|
"navigationBarTitleText": "编辑源",
|
||||||
"navigationStyle": "custom"
|
"navigationStyle": "custom"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</route>
|
</route>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import type { Providers } from '@/api/agent/types'
|
||||||
import { onMounted, ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import { t } from '@/i18n'
|
import { t } from '@/i18n'
|
||||||
import { useProvider, type ContextProvider } from '@/store/provider'
|
import { useProvider } from '@/store/provider'
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'Provider',
|
name: 'Provider',
|
||||||
})
|
})
|
||||||
|
|
||||||
interface EditableContextProvider {
|
|
||||||
url: string
|
|
||||||
headers: { key: string, value: string }[]
|
|
||||||
}
|
|
||||||
|
|
||||||
const providerStore = useProvider()
|
const providerStore = useProvider()
|
||||||
|
|
||||||
const localProviders = ref<EditableContextProvider[]>([])
|
const localProviders = ref<Providers[]>([])
|
||||||
|
|
||||||
function initLocalData() {
|
function initLocalData() {
|
||||||
localProviders.value = providerStore.providers.map((p) => {
|
localProviders.value = providerStore.providers.map((p) => {
|
||||||
|
|
@ -63,7 +59,7 @@ function handleConfirm() {
|
||||||
const result = localProviders.value
|
const result = localProviders.value
|
||||||
.filter(p => p.url.trim() !== '')
|
.filter(p => p.url.trim() !== '')
|
||||||
.map((p) => {
|
.map((p) => {
|
||||||
const headersObj: Record<string, string> = {}
|
const headersObj = {}
|
||||||
p.headers.forEach((h) => {
|
p.headers.forEach((h) => {
|
||||||
if (h.key.trim()) {
|
if (h.key.trim()) {
|
||||||
headersObj[h.key.trim()] = h.value
|
headersObj[h.key.trim()] = h.value
|
||||||
|
|
@ -75,7 +71,7 @@ function handleConfirm() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
providerStore.updateProviders(result)
|
providerStore.updateProviders(result as Providers[])
|
||||||
goBack()
|
goBack()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,7 +86,7 @@ onMounted(() => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<view class="h-screen flex flex-col bg-[#f5f7fb]">
|
<view class="h-screen flex flex-col bg-[#f5f7fb]">
|
||||||
<!-- Header navigation -->
|
<!-- 头部导航 -->
|
||||||
<wd-navbar
|
<wd-navbar
|
||||||
:title="t('contextProviderDialog.title')"
|
:title="t('contextProviderDialog.title')"
|
||||||
safe-area-inset-top
|
safe-area-inset-top
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"layout": "default",
|
"layout": "default",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationStyle": "custom",
|
"navigationStyle": "custom",
|
||||||
"navigationBarTitleText": "Chat Details"
|
"navigationBarTitleText": "聊天详情"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</route>
|
</route>
|
||||||
|
|
@ -13,14 +13,15 @@ import type { ChatMessage, UserMessageContent } from '@/api/chat-history/types'
|
||||||
import { onLoad, onUnload } from '@dcloudio/uni-app'
|
import { onLoad, onUnload } from '@dcloudio/uni-app'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { getAudioId, getChatHistory } from '@/api/chat-history/chat-history'
|
import { getAudioId, getChatHistory } from '@/api/chat-history/chat-history'
|
||||||
import { getEnvBaseUrl } from '@/utils'
|
import { t } from '@/i18n'
|
||||||
|
import { debounce, getEnvBaseUrl } from '@/utils'
|
||||||
import { toast } from '@/utils/toast'
|
import { toast } from '@/utils/toast'
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'ChatDetail',
|
name: 'ChatDetail',
|
||||||
})
|
})
|
||||||
|
|
||||||
// Get distance from screen boundary to safe area
|
// 获取屏幕边界到安全区域距离
|
||||||
let safeAreaInsets: any
|
let safeAreaInsets: any
|
||||||
let systemInfo: any
|
let systemInfo: any
|
||||||
|
|
||||||
|
|
@ -41,36 +42,36 @@ systemInfo = uni.getSystemInfoSync()
|
||||||
safeAreaInsets = systemInfo.safeAreaInsets
|
safeAreaInsets = systemInfo.safeAreaInsets
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// Page parameters
|
// 页面参数
|
||||||
const sessionId = ref('')
|
const sessionId = ref('')
|
||||||
const agentId = ref('')
|
const agentId = ref('')
|
||||||
|
|
||||||
// Agent information (simplified)
|
// 智能体信息(简化)
|
||||||
const currentAgent = computed(() => {
|
const currentAgent = computed(() => {
|
||||||
return {
|
return {
|
||||||
id: agentId.value,
|
id: agentId.value,
|
||||||
agentName: 'AI Assistant',
|
agentName: t('chatHistory.assistantName'),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Chat data
|
// 聊天数据
|
||||||
const messageList = ref<ChatMessage[]>([])
|
const messageList = ref<ChatMessage[]>([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
// Audio playback related
|
// 音频播放相关
|
||||||
const audioContext = ref<UniApp.InnerAudioContext | null>(null)
|
const audioContext = ref<UniApp.InnerAudioContext | null>(null)
|
||||||
const playingAudioId = ref<string | null>(null)
|
const playingAudioId = ref<string | null>(null)
|
||||||
const expandedToolResults = ref({})
|
const expandedToolResults = ref({})
|
||||||
|
|
||||||
// Return to previous page
|
// 返回上一页
|
||||||
function goBack() {
|
function goBack() {
|
||||||
uni.navigateBack()
|
uni.navigateBack()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load chat records
|
// 加载聊天记录
|
||||||
async function loadChatHistory() {
|
async function loadChatHistory() {
|
||||||
if (!sessionId.value || !agentId.value) {
|
if (!sessionId.value || !agentId.value) {
|
||||||
console.error('Missing required parameters')
|
console.error('缺少必要参数')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,15 +81,15 @@ async function loadChatHistory() {
|
||||||
messageList.value = response
|
messageList.value = response
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error('Failed to get chat history:', error)
|
console.error('获取聊天记录失败:', error)
|
||||||
toast.error('Failed to get chat history')
|
toast.error(t('chatHistory.loadFailed'))
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse user message content
|
// 解析用户消息内容
|
||||||
function parseUserMessage(content: string): UserMessageContent | null {
|
function parseUserMessage(content: string): UserMessageContent | null {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(content)
|
return JSON.parse(content)
|
||||||
|
|
@ -98,71 +99,71 @@ function parseUserMessage(content: string): UserMessageContent | null {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get message display content
|
// 获取消息显示内容
|
||||||
function getMessageContent(message: ChatMessage): string {
|
function getMessageContent(message: ChatMessage): string {
|
||||||
if (message.chatType === 1) {
|
if (message.chatType === 1) {
|
||||||
// User message, need to parse JSON
|
// 用户消息,需要解析JSON
|
||||||
const parsed = parseUserMessage(message.content)
|
const parsed = parseUserMessage(message.content)
|
||||||
return parsed ? parsed.content : message.content
|
return parsed ? parsed.content : message.content
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// AI message, display directly
|
// AI消息,直接显示
|
||||||
return message.content
|
return message.content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get speaker name
|
// 获取说话人名称
|
||||||
function getSpeakerName(message: ChatMessage): string {
|
function getSpeakerName(message: ChatMessage): string {
|
||||||
if (message.chatType === 1) {
|
if (message.chatType === 1) {
|
||||||
const parsed = parseUserMessage(message.content)
|
const parsed = parseUserMessage(message.content)
|
||||||
return parsed ? parsed.speaker : 'User'
|
return parsed ? parsed.speaker : t('chatHistory.userName')
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return currentAgent.value?.agentName || 'AI Assistant'
|
return currentAgent.value?.agentName || t('chatHistory.aiAssistantName')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format time
|
// 格式化时间
|
||||||
function formatTime(timeStr: string) {
|
function formatTime(timeStr: string) {
|
||||||
if (!timeStr)
|
if (!timeStr)
|
||||||
return t('chatHistory.unknownTime')
|
return t('chatHistory.unknownTime')
|
||||||
|
|
||||||
// Normalize time string format
|
// 处理时间字符串,确保格式正确
|
||||||
const date = new Date(timeStr.replace(' ', 'T')) // Convert to ISO format
|
const date = new Date(timeStr.replace(' ', 'T')) // 转换为ISO格式
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
|
|
||||||
// Check whether the date is valid
|
// 检查日期是否有效
|
||||||
if (Number.isNaN(date.getTime())) {
|
if (Number.isNaN(date.getTime())) {
|
||||||
return timeStr // Return the original string if parsing fails
|
return timeStr // 如果解析失败,直接返回原字符串
|
||||||
}
|
}
|
||||||
|
|
||||||
const diff = now.getTime() - date.getTime()
|
const diff = now.getTime() - date.getTime()
|
||||||
|
|
||||||
// Less than one minute
|
// 小于1分钟
|
||||||
if (diff < 60000)
|
if (diff < 60000)
|
||||||
return t('chatHistory.justNow')
|
return t('chatHistory.justNow')
|
||||||
|
|
||||||
// Less than one hour
|
// 小于1小时
|
||||||
if (diff < 3600000)
|
if (diff < 3600000)
|
||||||
return t('chatHistory.minutesAgo', { minutes: Math.floor(diff / 60000) })
|
return t('chatHistory.minutesAgo', { minutes: Math.floor(diff / 60000) })
|
||||||
|
|
||||||
// Less than one day (24 hours)
|
// 小于1天(24小时)
|
||||||
if (diff < 86400000)
|
if (diff < 86400000)
|
||||||
return t('chatHistory.hoursAgo', { hours: Math.floor(diff / 3600000) })
|
return t('chatHistory.hoursAgo', { hours: Math.floor(diff / 3600000) })
|
||||||
|
|
||||||
// Less than seven days
|
// 小于7天
|
||||||
if (diff < 604800000) {
|
if (diff < 604800000) {
|
||||||
const days = Math.floor(diff / 86400000)
|
const days = Math.floor(diff / 86400000)
|
||||||
return t('chatHistory.daysAgo', { days })
|
return t('chatHistory.daysAgo', { days })
|
||||||
}
|
}
|
||||||
|
|
||||||
// More than seven days, show the date
|
// 超过7天,显示具体日期
|
||||||
const year = date.getFullYear()
|
const year = date.getFullYear()
|
||||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||||
const day = String(date.getDate()).padStart(2, '0')
|
const day = String(date.getDate()).padStart(2, '0')
|
||||||
const currentYear = now.getFullYear()
|
const currentYear = now.getFullYear()
|
||||||
|
|
||||||
// Omit the year for the current year
|
// 如果是当前年份,不显示年份
|
||||||
if (year === currentYear) {
|
if (year === currentYear) {
|
||||||
return `${month}-${day}`
|
return `${month}-${day}`
|
||||||
}
|
}
|
||||||
|
|
@ -170,36 +171,41 @@ function formatTime(timeStr: string) {
|
||||||
return `${year}-${month}-${day}`
|
return `${year}-${month}-${day}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Play audio
|
// 播放音频
|
||||||
async function playAudio(audioId: string) {
|
const playAudio = debounce(async (audioId: string) => {
|
||||||
if (!audioId) {
|
if (!audioId) {
|
||||||
toast.error('Invalid audio ID')
|
toast.error(t('chatHistory.invalidAudioId'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// If playing other audio, stop first
|
// 如果正在播放其他音频,先停止
|
||||||
if (audioContext.value) {
|
if (audioContext.value) {
|
||||||
audioContext.value.stop()
|
audioContext.value.stop()
|
||||||
audioContext.value.destroy()
|
}
|
||||||
audioContext.value = null
|
// 如果当前音频ID与请求ID相同暂停播放
|
||||||
|
if (playingAudioId.value === audioId) {
|
||||||
|
playingAudioId.value = null
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get audio download ID
|
// 获取音频下载ID
|
||||||
const downloadId = await getAudioId(audioId)
|
const downloadId = await getAudioId(audioId)
|
||||||
|
|
||||||
// Construct audio playback URL
|
// 构造音频播放地址
|
||||||
const baseUrl = getEnvBaseUrl()
|
const baseUrl = getEnvBaseUrl()
|
||||||
const audioUrl = `${baseUrl}/agent/play/${downloadId}`
|
const audioUrl = `${baseUrl}/agent/play/${downloadId}`
|
||||||
|
|
||||||
// Create audio context
|
// 创建音频上下文
|
||||||
audioContext.value = uni.createInnerAudioContext()
|
if (!audioContext.value) {
|
||||||
|
audioContext.value = uni.createInnerAudioContext()
|
||||||
|
}
|
||||||
audioContext.value.src = audioUrl
|
audioContext.value.src = audioUrl
|
||||||
|
|
||||||
// Set playback status
|
// 设置播放状态
|
||||||
playingAudioId.value = audioId
|
playingAudioId.value = audioId
|
||||||
|
|
||||||
// Listen for playback completion
|
// 监听播放完成
|
||||||
audioContext.value.onEnded(() => {
|
audioContext.value.onEnded(() => {
|
||||||
playingAudioId.value = null
|
playingAudioId.value = null
|
||||||
if (audioContext.value) {
|
if (audioContext.value) {
|
||||||
|
|
@ -208,10 +214,10 @@ async function playAudio(audioId: string) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Listen for playback errors
|
// 监听播放错误
|
||||||
audioContext.value.onError((error) => {
|
audioContext.value.onError((error) => {
|
||||||
console.error('Audio playback failed:', error)
|
console.error('音频播放失败:', error)
|
||||||
toast.error('Audio playback failed')
|
toast.error(t('chatHistory.audioPlayFailed'))
|
||||||
playingAudioId.value = null
|
playingAudioId.value = null
|
||||||
if (audioContext.value) {
|
if (audioContext.value) {
|
||||||
audioContext.value.destroy()
|
audioContext.value.destroy()
|
||||||
|
|
@ -219,40 +225,40 @@ async function playAudio(audioId: string) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Start playback
|
// 开始播放
|
||||||
audioContext.value.play()
|
audioContext.value.play()
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error('Audio playback failed:', error)
|
console.error('播放音频失败:', error)
|
||||||
toast.error('Audio playback failed')
|
toast.error(t('chatHistory.playAudioFailed'))
|
||||||
playingAudioId.value = null
|
playingAudioId.value = null
|
||||||
}
|
}
|
||||||
}
|
}, 400)
|
||||||
|
|
||||||
function extractContentFromString(content: string) {
|
function extractContentFromString(content: string) {
|
||||||
if (!content || content.trim() === '') {
|
if (!content || content.trim() === '') {
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to parse as JSON
|
// 尝试解析为 JSON
|
||||||
try {
|
try {
|
||||||
const jsonObj = JSON.parse(content)
|
const jsonObj = JSON.parse(content)
|
||||||
|
|
||||||
// Array format containing text and tool entries
|
// 如果是数组格式(包含 text 和 tool)
|
||||||
if (Array.isArray(jsonObj)) {
|
if (Array.isArray(jsonObj)) {
|
||||||
return jsonObj
|
return jsonObj
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object with a content field
|
// 如果是对象且有 content 字段
|
||||||
if (jsonObj && typeof jsonObj === 'object' && jsonObj.content) {
|
if (jsonObj && typeof jsonObj === 'object' && jsonObj.content) {
|
||||||
return jsonObj.content
|
return jsonObj.content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
// Return original content if JSON parsing fails
|
// 如果不是有效的 JSON,直接返回原内容
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return original content if it is not JSON or has no content field
|
// 如果不是 JSON 格式或没有 content 字段,直接返回原内容
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -263,7 +269,7 @@ function toggleToolResult(messageIndex, itemIndex) {
|
||||||
|
|
||||||
function isToolResultCollapsed(messageIndex, itemIndex) {
|
function isToolResultCollapsed(messageIndex, itemIndex) {
|
||||||
const key = `${messageIndex}-${itemIndex}`
|
const key = `${messageIndex}-${itemIndex}`
|
||||||
// Collapsed by default (true means collapsed)
|
// 默认折叠(true表示折叠)
|
||||||
return !expandedToolResults.value[key]
|
return !expandedToolResults.value[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -281,8 +287,8 @@ onLoad((options) => {
|
||||||
agentId.value = options.agentId
|
agentId.value = options.agentId
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.error('Missing required parameters')
|
console.error('缺少必要参数')
|
||||||
toast.error('Page parameter error')
|
toast.error(t('chatHistory.parameterError'))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -290,7 +296,7 @@ onShow(() => {
|
||||||
loadChatHistory()
|
loadChatHistory()
|
||||||
})
|
})
|
||||||
|
|
||||||
// Clean up audio resources when the page is destroyed
|
// 页面销毁时清理音频资源
|
||||||
onUnload(() => {
|
onUnload(() => {
|
||||||
if (audioContext.value) {
|
if (audioContext.value) {
|
||||||
audioContext.value.stop()
|
audioContext.value.stop()
|
||||||
|
|
@ -302,17 +308,17 @@ onUnload(() => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<view class="h-screen flex flex-col bg-[#f5f7fb]">
|
<view class="h-screen flex flex-col bg-[#f5f7fb]">
|
||||||
<!-- Status bar background -->
|
<!-- 状态栏背景 -->
|
||||||
<view class="w-full bg-white" :style="{ height: `${safeAreaInsets?.top}px` }" />
|
<view class="w-full bg-white" :style="{ height: `${safeAreaInsets?.top}px` }" />
|
||||||
|
|
||||||
<!-- Navigation bar -->
|
<!-- 导航栏 -->
|
||||||
<wd-navbar title="Chat Details">
|
<wd-navbar :title="t('chatHistory.pageTitle')">
|
||||||
<template #left>
|
<template #left>
|
||||||
<wd-icon name="arrow-left" size="18" @click="goBack" />
|
<wd-icon name="arrow-left" size="18" @click="goBack" />
|
||||||
</template>
|
</template>
|
||||||
</wd-navbar>
|
</wd-navbar>
|
||||||
|
|
||||||
<!-- Chat message list -->
|
<!-- 聊天消息列表 -->
|
||||||
<scroll-view
|
<scroll-view
|
||||||
scroll-y
|
scroll-y
|
||||||
:style="{ height: `calc(100vh - ${safeAreaInsets?.top || 0}px - 120rpx)` }"
|
:style="{ height: `calc(100vh - ${safeAreaInsets?.top || 0}px - 120rpx)` }"
|
||||||
|
|
@ -322,7 +328,7 @@ onUnload(() => {
|
||||||
<view v-if="loading" class="flex flex-col items-center justify-center gap-[20rpx] p-[100rpx_0]">
|
<view v-if="loading" class="flex flex-col items-center justify-center gap-[20rpx] p-[100rpx_0]">
|
||||||
<wd-loading />
|
<wd-loading />
|
||||||
<text class="text-[28rpx] text-[#65686f]">
|
<text class="text-[28rpx] text-[#65686f]">
|
||||||
Loading...
|
{{ t('chatHistory.loading') }}
|
||||||
</text>
|
</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
|
@ -345,7 +351,7 @@ onUnload(() => {
|
||||||
'tool-message': message.chatType === 3,
|
'tool-message': message.chatType === 3,
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<!-- Message bubble -->
|
<!-- 消息气泡 -->
|
||||||
<view
|
<view
|
||||||
class="shadow-message break-words rounded-[20rpx] p-[24rpx] leading-[1.4]"
|
class="shadow-message break-words rounded-[20rpx] p-[24rpx] leading-[1.4]"
|
||||||
:class="{
|
:class="{
|
||||||
|
|
@ -381,9 +387,9 @@ onUnload(() => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<!-- Content area - use flex layout to align icon and text -->
|
<!-- 内容区域 - 使用flex布局让图标和文本对齐 -->
|
||||||
<view v-else class="flex items-center gap-[12rpx]">
|
<view v-else class="flex items-center gap-[12rpx]">
|
||||||
<!-- Audio playback icon -->
|
<!-- 音频播放图标 -->
|
||||||
<view
|
<view
|
||||||
v-if="message.audioId"
|
v-if="message.audioId"
|
||||||
class="flex-shrink-0 cursor-pointer transition-transform duration-200 active:scale-90"
|
class="flex-shrink-0 cursor-pointer transition-transform duration-200 active:scale-90"
|
||||||
|
|
@ -403,9 +409,9 @@ onUnload(() => {
|
||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- Message content container -->
|
<!-- 消息内容容器 -->
|
||||||
<view class="min-w-0 flex-1">
|
<view class="min-w-0 flex-1">
|
||||||
<!-- Message content -->
|
<!-- 消息内容 -->
|
||||||
<text class="block text-[28rpx]">
|
<text class="block text-[28rpx]">
|
||||||
{{ getMessageContent(message) }}
|
{{ getMessageContent(message) }}
|
||||||
</text>
|
</text>
|
||||||
|
|
@ -413,7 +419,7 @@ onUnload(() => {
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- Speaker information -->
|
<!-- 说话人信息 -->
|
||||||
<text
|
<text
|
||||||
class="mx-[12rpx] text-[22rpx] text-[#9d9ea3]"
|
class="mx-[12rpx] text-[22rpx] text-[#9d9ea3]"
|
||||||
:class="{
|
:class="{
|
||||||
|
|
@ -431,7 +437,7 @@ onUnload(() => {
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
/* Custom shadow and animation effects, styles that cannot be represented by UnoCSS */
|
/* 自定义阴影和动画效果,无法用UnoCSS表示的样式 */
|
||||||
.shadow-message {
|
.shadow-message {
|
||||||
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.06);
|
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.06);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, ref } from 'vue'
|
import { computed, onMounted, ref } from 'vue'
|
||||||
import { useToast } from 'wot-design-uni'
|
import { useToast } from 'wot-design-uni'
|
||||||
|
import { t } from '@/i18n'
|
||||||
|
|
||||||
// Type definitions
|
// Type definitions
|
||||||
interface WiFiNetwork {
|
interface WiFiNetwork {
|
||||||
|
|
@ -265,19 +266,6 @@ onMounted(() => {
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- WiFi network selector -->
|
|
||||||
<view class="network-selector">
|
|
||||||
<view class="selector-item" @click="showNetworkSelector">
|
|
||||||
<text class="selector-label">
|
|
||||||
WiFi Network
|
|
||||||
</text>
|
|
||||||
<text class="selector-value">
|
|
||||||
{{ networkDisplayText }}
|
|
||||||
</text>
|
|
||||||
<wd-icon name="arrow-right" custom-class="arrow-icon" />
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<!-- Expanded network list -->
|
<!-- Expanded network list -->
|
||||||
<view v-if="selectorExpanded" class="network-list-overlay">
|
<view v-if="selectorExpanded" class="network-list-overlay">
|
||||||
<view class="network-list-container">
|
<view class="network-list-container">
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { createPinia } from 'pinia'
|
import { createPinia } from 'pinia'
|
||||||
import { createPersistedState } from 'pinia-plugin-persistedstate' // Data persistence
|
import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持久化
|
||||||
|
|
||||||
const store = createPinia()
|
const store = createPinia()
|
||||||
store.use(
|
store.use(
|
||||||
|
|
@ -15,6 +15,7 @@ export default store
|
||||||
|
|
||||||
export * from './config'
|
export * from './config'
|
||||||
export * from './plugin'
|
export * from './plugin'
|
||||||
|
export * from './provider'
|
||||||
export * from './speedPitch'
|
export * from './speedPitch'
|
||||||
// Module unified export
|
// 模块统一导出
|
||||||
export * from './user'
|
export * from './user'
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,10 @@
|
||||||
|
import type { Providers } from '@/api/agent/types'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
export interface ContextProvider {
|
|
||||||
url: string
|
|
||||||
headers: Record<string, string>
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useProvider = defineStore('provider', () => {
|
export const useProvider = defineStore('provider', () => {
|
||||||
const providers = ref<ContextProvider[]>([])
|
const providers = ref<Providers[]>([])
|
||||||
|
|
||||||
const updateProviders = (val: ContextProvider[]) => {
|
const updateProviders = (val: Providers[]) => {
|
||||||
providers.value = val
|
providers.value = val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,6 @@ export function getServerBaseUrlOverride(): string | null {
|
||||||
return value || null
|
return value || null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sm2Encrypt(publicKey: string, plainText: string) {
|
|
||||||
const normalizedKey = publicKey.trim().replace(/^0x/i, '').replace(/^04/i, '')
|
|
||||||
return sm2.doEncrypt(plainText, normalizedKey, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getLastPage() {
|
export function getLastPage() {
|
||||||
// getCurrentPages() has at least 1 element, so no additional check needed
|
// getCurrentPages() has at least 1 element, so no additional check needed
|
||||||
// const lastPage = getCurrentPages().at(-1)
|
// const lastPage = getCurrentPages().at(-1)
|
||||||
|
|
@ -207,7 +202,6 @@ export function getEnvBaseUploadUrl() {
|
||||||
* Generate an SM2 key pair (hex-encoded), matching upstream xiaozhi crypto layout.
|
* Generate an SM2 key pair (hex-encoded), matching upstream xiaozhi crypto layout.
|
||||||
*/
|
*/
|
||||||
export function generateSm2KeyPairHex() {
|
export function generateSm2KeyPairHex() {
|
||||||
const sm2 = smCrypto.sm2
|
|
||||||
const keypair = sm2.generateKeyPairHex()
|
const keypair = sm2.generateKeyPairHex()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -230,18 +224,15 @@ export function sm2Encrypt(publicKey: string, plainText: string): string {
|
||||||
throw new Error('Plaintext cannot be empty')
|
throw new Error('Plaintext cannot be empty')
|
||||||
}
|
}
|
||||||
|
|
||||||
const sm2 = smCrypto.sm2
|
const normalizedKey = publicKey.trim().replace(/^0x/i, '').replace(/^04/i, '')
|
||||||
const encrypted = sm2.doEncrypt(plainText, publicKey, 1)
|
const encrypted = sm2.doEncrypt(plainText, normalizedKey, 1)
|
||||||
const result = `04${encrypted}`
|
return `04${encrypted}`
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SM2 private-key decryption (hex). Strips a leading 04 prefix if present.
|
* SM2 private-key decryption (hex). Strips a leading 04 prefix if present.
|
||||||
*/
|
*/
|
||||||
export function sm2Decrypt(privateKey: string, cipherText: string): string {
|
export function sm2Decrypt(privateKey: string, cipherText: string): string {
|
||||||
const sm2 = smCrypto.sm2
|
|
||||||
const dataWithoutPrefix = cipherText.startsWith('04') ? cipherText.substring(2) : cipherText
|
const dataWithoutPrefix = cipherText.startsWith('04') ? cipherText.substring(2) : cipherText
|
||||||
return sm2.doDecrypt(dataWithoutPrefix, privateKey, 1)
|
return sm2.doDecrypt(dataWithoutPrefix, privateKey, 1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
main/manager-web/src/assets/xiaozhi-ai.png
Normal file
BIN
main/manager-web/src/assets/xiaozhi-ai.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
|
|
@ -63,7 +63,7 @@ if [ -d "main/xiaozhi-server/test" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run Python tests
|
# Run Python tests
|
||||||
if $PYTHON_CMD test/test_runner.py; then
|
if PYTHONPATH=. $PYTHON_CMD ../digital-human/test_runner.py; then
|
||||||
print_success "Python backend tests passed!"
|
print_success "Python backend tests passed!"
|
||||||
else
|
else
|
||||||
print_error "Python backend tests failed!"
|
print_error "Python backend tests failed!"
|
||||||
|
|
@ -173,7 +173,7 @@ case "$1" in
|
||||||
--python-only)
|
--python-only)
|
||||||
print_status "Running Python tests only..."
|
print_status "Running Python tests only..."
|
||||||
cd main/xiaozhi-server
|
cd main/xiaozhi-server
|
||||||
$PYTHON_CMD test/test_runner.py
|
PYTHONPATH=. $PYTHON_CMD ../digital-human/test_runner.py
|
||||||
;;
|
;;
|
||||||
--java-only)
|
--java-only)
|
||||||
print_status "Running Java tests only..."
|
print_status "Running Java tests only..."
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue