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:
lapy 2026-06-13 11:34:27 +01:00
parent 0a05931a00
commit b95a482f73
12 changed files with 666 additions and 276 deletions

View file

@ -7,7 +7,7 @@ import type {
} from './types'
import { http } from '@/http/request/alova'
// Get agent details
// 获取智能体详情
export function getAgentDetail(id: string) {
return http.Get<AgentDetail>(`/agent/${id}`, {
meta: {
@ -20,7 +20,7 @@ export function getAgentDetail(id: string) {
})
}
// Get role template list
// 获取角色模板列表
export function getRoleTemplates() {
return http.Get<RoleTemplate[]>('/agent/template', {
meta: {
@ -33,7 +33,7 @@ export function getRoleTemplates() {
})
}
// Get model options
// 获取模型选项
export function getModelOptions(modelType: string, modelName: string = '') {
return http.Get<ModelOption[]>('/models/names', {
params: {
@ -50,7 +50,7 @@ export function getModelOptions(modelType: string, modelName: string = '') {
})
}
// Get agent list
// 获取智能体列表
export function getAgentList() {
return http.Get<Agent[]>('/agent/list', {
meta: {
@ -63,7 +63,7 @@ export function getAgentList() {
})
}
// Create agent
// 创建智能体
export function createAgent(data: AgentCreateData) {
return http.Post<string>('/agent', data, {
meta: {
@ -73,7 +73,7 @@ export function createAgent(data: AgentCreateData) {
})
}
// Delete agent
// 删除智能体
export function deleteAgent(id: string) {
return http.Delete(`/agent/${id}`, {
meta: {
@ -83,7 +83,7 @@ export function deleteAgent(id: string) {
})
}
// Get TTS voice list
// 获取TTS音色列表
export function getTTSVoices(ttsModelId: string, voiceName: string = '') {
return http.Get<{ id: string, name: string }[]>(`/models/${ttsModelId}/voices`, {
params: {
@ -99,7 +99,7 @@ export function getTTSVoices(ttsModelId: string, voiceName: string = '') {
})
}
// Update agent
// 更新智能体
export function updateAgent(id: string, data: Partial<AgentDetail>) {
return http.Put(`/agent/${id}`, data, {
meta: {
@ -112,7 +112,7 @@ export function updateAgent(id: string, data: Partial<AgentDetail>) {
})
}
// Get plugin list
// 获取插件列表
export function getPluginFunctions() {
return http.Get<any[]>(`/models/provider/plugin/names`, {
meta: {
@ -125,17 +125,18 @@ export function getPluginFunctions() {
})
}
// Get MCP access point
// 获取mcp接入点
export function getMcpAddress(agentId: string) {
return http.Get<string>(`/agent/mcp/address/${agentId}`, {
meta: {
ignoreAuth: false,
toast: false,
isExposeError: true,
},
})
}
// Get MCP tools
// 获取mcp工具
export function getMcpTools(agentId: string) {
return http.Get<string[]>(`/agent/mcp/tools/${agentId}`, {
meta: {
@ -148,7 +149,7 @@ export function getMcpTools(agentId: string) {
})
}
// Get voiceprint list
// 获取声纹列表
export function getVoicePrintList(agentId: string) {
return http.Get<any[]>(`/agent/voice-print/list/${agentId}`, {
meta: {
@ -161,7 +162,7 @@ export function getVoicePrintList(agentId: string) {
})
}
// Get voice conversation records
// 获取语音对话记录
export function getChatHistoryUser(agentId: string) {
return http.Get<any[]>(`/agent/${agentId}/chat-history/user`, {
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 }) {
return http.Post('/agent/voice-print', data, {
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,
},
})
}

View file

@ -1,4 +1,4 @@
// Agent list data type
// 智能体列表数据类型
export interface Agent {
id: string
agentName: string
@ -11,14 +11,15 @@ export interface Agent {
summaryMemory: string | null
lastConnectedAt: string | null
deviceCount: number
tags: Record<string, string>[]
}
// Agent creation data type
// 智能体创建数据类型
export interface AgentCreateData {
agentName: string
}
// Agent details data type
// 智能体详情数据类型
export interface AgentDetail {
id: string
userId: string
@ -43,7 +44,20 @@ export interface AgentDetail {
createdAt: string
updater: string
updatedAt: string
ttsLanguage: string
ttsVolume: number
ttsRate: number
ttsPitch: number
functions: AgentFunction[]
contextProviders: Providers[]
}
export interface Providers {
url: string
headers: Array<{
key: string
value: string
}>
}
export interface AgentFunction {
@ -53,7 +67,7 @@ export interface AgentFunction {
paramInfo: Record<string, string | number | boolean> | null
}
// Role template data type
// 角色模板数据类型
export interface RoleTemplate {
id: string
agentCode: string
@ -78,7 +92,7 @@ export interface RoleTemplate {
updatedAt: string
}
// Model options data type
// 模型选项数据类型
export interface ModelOption {
id: string
modelName: string
@ -98,7 +112,7 @@ export interface PluginDefinition {
modelType: string
providerCode: string
name: string
fields: PluginField[] // Note: Original is string, need to JSON.parse first
fields: PluginField[] // 注意:原始是字符串,需要先 JSON.parse
sort: number
updater: string
updateDate: string

View file

@ -176,7 +176,7 @@
"type": "page",
"layout": "default",
"style": {
"navigationBarTitleText": "Settings",
"navigationBarTitleText": "设置",
"navigationStyle": "custom"
}
},

File diff suppressed because it is too large Load diff

View file

@ -2,29 +2,25 @@
{
"layout": "default",
"style": {
"navigationBarTitleText": "Edit Sources",
"navigationBarTitleText": "编辑源",
"navigationStyle": "custom"
}
}
</route>
<script lang="ts" setup>
import type { Providers } from '@/api/agent/types'
import { onMounted, ref } from 'vue'
import { t } from '@/i18n'
import { useProvider, type ContextProvider } from '@/store/provider'
import { useProvider } from '@/store/provider'
defineOptions({
name: 'Provider',
})
interface EditableContextProvider {
url: string
headers: { key: string, value: string }[]
}
const providerStore = useProvider()
const localProviders = ref<EditableContextProvider[]>([])
const localProviders = ref<Providers[]>([])
function initLocalData() {
localProviders.value = providerStore.providers.map((p) => {
@ -63,7 +59,7 @@ function handleConfirm() {
const result = localProviders.value
.filter(p => p.url.trim() !== '')
.map((p) => {
const headersObj: Record<string, string> = {}
const headersObj = {}
p.headers.forEach((h) => {
if (h.key.trim()) {
headersObj[h.key.trim()] = h.value
@ -75,7 +71,7 @@ function handleConfirm() {
}
})
providerStore.updateProviders(result)
providerStore.updateProviders(result as Providers[])
goBack()
}
@ -90,7 +86,7 @@ onMounted(() => {
<template>
<view class="h-screen flex flex-col bg-[#f5f7fb]">
<!-- Header navigation -->
<!-- 头部导航 -->
<wd-navbar
:title="t('contextProviderDialog.title')"
safe-area-inset-top

View file

@ -3,7 +3,7 @@
"layout": "default",
"style": {
"navigationStyle": "custom",
"navigationBarTitleText": "Chat Details"
"navigationBarTitleText": "聊天详情"
}
}
</route>
@ -13,14 +13,15 @@ import type { ChatMessage, UserMessageContent } from '@/api/chat-history/types'
import { onLoad, onUnload } from '@dcloudio/uni-app'
import { computed, ref } from 'vue'
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'
defineOptions({
name: 'ChatDetail',
})
// Get distance from screen boundary to safe area
// 获取屏幕边界到安全区域距离
let safeAreaInsets: any
let systemInfo: any
@ -41,36 +42,36 @@ systemInfo = uni.getSystemInfoSync()
safeAreaInsets = systemInfo.safeAreaInsets
// #endif
// Page parameters
// 页面参数
const sessionId = ref('')
const agentId = ref('')
// Agent information (simplified)
// 智能体信息(简化)
const currentAgent = computed(() => {
return {
id: agentId.value,
agentName: 'AI Assistant',
agentName: t('chatHistory.assistantName'),
}
})
// Chat data
// 聊天数据
const messageList = ref<ChatMessage[]>([])
const loading = ref(false)
// Audio playback related
// 音频播放相关
const audioContext = ref<UniApp.InnerAudioContext | null>(null)
const playingAudioId = ref<string | null>(null)
const expandedToolResults = ref({})
// Return to previous page
// 返回上一页
function goBack() {
uni.navigateBack()
}
// Load chat records
// 加载聊天记录
async function loadChatHistory() {
if (!sessionId.value || !agentId.value) {
console.error('Missing required parameters')
console.error('缺少必要参数')
return
}
@ -80,15 +81,15 @@ async function loadChatHistory() {
messageList.value = response
}
catch (error) {
console.error('Failed to get chat history:', error)
toast.error('Failed to get chat history')
console.error('获取聊天记录失败:', error)
toast.error(t('chatHistory.loadFailed'))
}
finally {
loading.value = false
}
}
// Parse user message content
// 解析用户消息内容
function parseUserMessage(content: string): UserMessageContent | null {
try {
return JSON.parse(content)
@ -98,71 +99,71 @@ function parseUserMessage(content: string): UserMessageContent | null {
}
}
// Get message display content
// 获取消息显示内容
function getMessageContent(message: ChatMessage): string {
if (message.chatType === 1) {
// User message, need to parse JSON
// 用户消息,需要解析JSON
const parsed = parseUserMessage(message.content)
return parsed ? parsed.content : message.content
}
else {
// AI message, display directly
// AI消息,直接显示
return message.content
}
}
// Get speaker name
// 获取说话人名称
function getSpeakerName(message: ChatMessage): string {
if (message.chatType === 1) {
const parsed = parseUserMessage(message.content)
return parsed ? parsed.speaker : 'User'
return parsed ? parsed.speaker : t('chatHistory.userName')
}
else {
return currentAgent.value?.agentName || 'AI Assistant'
return currentAgent.value?.agentName || t('chatHistory.aiAssistantName')
}
}
// Format time
// 格式化时间
function formatTime(timeStr: string) {
if (!timeStr)
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()
// Check whether the date is valid
// 检查日期是否有效
if (Number.isNaN(date.getTime())) {
return timeStr // Return the original string if parsing fails
return timeStr // 如果解析失败,直接返回原字符串
}
const diff = now.getTime() - date.getTime()
// Less than one minute
// 小于1分钟
if (diff < 60000)
return t('chatHistory.justNow')
// Less than one hour
// 小于1小时
if (diff < 3600000)
return t('chatHistory.minutesAgo', { minutes: Math.floor(diff / 60000) })
// Less than one day (24 hours)
// 小于1天(24小时)
if (diff < 86400000)
return t('chatHistory.hoursAgo', { hours: Math.floor(diff / 3600000) })
// Less than seven days
// 小于7天
if (diff < 604800000) {
const days = Math.floor(diff / 86400000)
return t('chatHistory.daysAgo', { days })
}
// More than seven days, show the date
// 超过7天,显示具体日期
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
const currentYear = now.getFullYear()
// Omit the year for the current year
// 如果是当前年份,不显示年份
if (year === currentYear) {
return `${month}-${day}`
}
@ -170,36 +171,41 @@ function formatTime(timeStr: string) {
return `${year}-${month}-${day}`
}
// Play audio
async function playAudio(audioId: string) {
// 播放音频
const playAudio = debounce(async (audioId: string) => {
if (!audioId) {
toast.error('Invalid audio ID')
toast.error(t('chatHistory.invalidAudioId'))
return
}
try {
// If playing other audio, stop first
// 如果正在播放其他音频,先停止
if (audioContext.value) {
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)
// Construct audio playback URL
// 构造音频播放地址
const baseUrl = getEnvBaseUrl()
const audioUrl = `${baseUrl}/agent/play/${downloadId}`
// Create audio context
audioContext.value = uni.createInnerAudioContext()
// 创建音频上下文
if (!audioContext.value) {
audioContext.value = uni.createInnerAudioContext()
}
audioContext.value.src = audioUrl
// Set playback status
// 设置播放状态
playingAudioId.value = audioId
// Listen for playback completion
// 监听播放完成
audioContext.value.onEnded(() => {
playingAudioId.value = null
if (audioContext.value) {
@ -208,10 +214,10 @@ async function playAudio(audioId: string) {
}
})
// Listen for playback errors
// 监听播放错误
audioContext.value.onError((error) => {
console.error('Audio playback failed:', error)
toast.error('Audio playback failed')
console.error('音频播放失败:', error)
toast.error(t('chatHistory.audioPlayFailed'))
playingAudioId.value = null
if (audioContext.value) {
audioContext.value.destroy()
@ -219,40 +225,40 @@ async function playAudio(audioId: string) {
}
})
// Start playback
// 开始播放
audioContext.value.play()
}
catch (error) {
console.error('Audio playback failed:', error)
toast.error('Audio playback failed')
console.error('播放音频失败:', error)
toast.error(t('chatHistory.playAudioFailed'))
playingAudioId.value = null
}
}
}, 400)
function extractContentFromString(content: string) {
if (!content || content.trim() === '') {
return content
}
// Try to parse as JSON
// 尝试解析为 JSON
try {
const jsonObj = JSON.parse(content)
// Array format containing text and tool entries
// 如果是数组格式(包含 text 和 tool)
if (Array.isArray(jsonObj)) {
return jsonObj
}
// Object with a content field
// 如果是对象且有 content 字段
if (jsonObj && typeof jsonObj === 'object' && jsonObj.content) {
return jsonObj.content
}
}
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
}
@ -263,7 +269,7 @@ function toggleToolResult(messageIndex, itemIndex) {
function isToolResultCollapsed(messageIndex, itemIndex) {
const key = `${messageIndex}-${itemIndex}`
// Collapsed by default (true means collapsed)
// 默认折叠(true表示折叠)
return !expandedToolResults.value[key]
}
@ -281,8 +287,8 @@ onLoad((options) => {
agentId.value = options.agentId
}
else {
console.error('Missing required parameters')
toast.error('Page parameter error')
console.error('缺少必要参数')
toast.error(t('chatHistory.parameterError'))
}
})
@ -290,7 +296,7 @@ onShow(() => {
loadChatHistory()
})
// Clean up audio resources when the page is destroyed
// 页面销毁时清理音频资源
onUnload(() => {
if (audioContext.value) {
audioContext.value.stop()
@ -302,17 +308,17 @@ onUnload(() => {
<template>
<view class="h-screen flex flex-col bg-[#f5f7fb]">
<!-- Status bar background -->
<!-- 状态栏背景 -->
<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>
<wd-icon name="arrow-left" size="18" @click="goBack" />
</template>
</wd-navbar>
<!-- Chat message list -->
<!-- 聊天消息列表 -->
<scroll-view
scroll-y
: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]">
<wd-loading />
<text class="text-[28rpx] text-[#65686f]">
Loading...
{{ t('chatHistory.loading') }}
</text>
</view>
@ -345,7 +351,7 @@ onUnload(() => {
'tool-message': message.chatType === 3,
}"
>
<!-- Message bubble -->
<!-- 消息气泡 -->
<view
class="shadow-message break-words rounded-[20rpx] p-[24rpx] leading-[1.4]"
:class="{
@ -381,9 +387,9 @@ onUnload(() => {
</div>
</div>
</template>
<!-- Content area - use flex layout to align icon and text -->
<!-- 内容区域 - 使用flex布局让图标和文本对齐 -->
<view v-else class="flex items-center gap-[12rpx]">
<!-- Audio playback icon -->
<!-- 音频播放图标 -->
<view
v-if="message.audioId"
class="flex-shrink-0 cursor-pointer transition-transform duration-200 active:scale-90"
@ -403,9 +409,9 @@ onUnload(() => {
/>
</view>
<!-- Message content container -->
<!-- 消息内容容器 -->
<view class="min-w-0 flex-1">
<!-- Message content -->
<!-- 消息内容 -->
<text class="block text-[28rpx]">
{{ getMessageContent(message) }}
</text>
@ -413,7 +419,7 @@ onUnload(() => {
</view>
</view>
<!-- Speaker information -->
<!-- 说话人信息 -->
<text
class="mx-[12rpx] text-[22rpx] text-[#9d9ea3]"
:class="{
@ -431,7 +437,7 @@ onUnload(() => {
</template>
<style>
/* Custom shadow and animation effects, styles that cannot be represented by UnoCSS */
/* 自定义阴影和动画效果,无法用UnoCSS表示的样式 */
.shadow-message {
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.06);
}

View file

@ -1,6 +1,7 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { t } from '@/i18n'
// Type definitions
interface WiFiNetwork {
@ -265,19 +266,6 @@ onMounted(() => {
</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 -->
<view v-if="selectorExpanded" class="network-list-overlay">
<view class="network-list-container">

View file

@ -1,5 +1,5 @@
import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-plugin-persistedstate' // Data persistence
import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持久化
const store = createPinia()
store.use(
@ -15,6 +15,7 @@ export default store
export * from './config'
export * from './plugin'
export * from './provider'
export * from './speedPitch'
// Module unified export
// 模块统一导出
export * from './user'

View file

@ -1,14 +1,10 @@
import type { Providers } from '@/api/agent/types'
import { defineStore } from 'pinia'
export interface ContextProvider {
url: string
headers: Record<string, string>
}
export const useProvider = defineStore('provider', () => {
const providers = ref<ContextProvider[]>([])
const providers = ref<Providers[]>([])
const updateProviders = (val: ContextProvider[]) => {
const updateProviders = (val: Providers[]) => {
providers.value = val
}

View file

@ -23,11 +23,6 @@ export function getServerBaseUrlOverride(): string | 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() {
// getCurrentPages() has at least 1 element, so no additional check needed
// const lastPage = getCurrentPages().at(-1)
@ -207,7 +202,6 @@ export function getEnvBaseUploadUrl() {
* Generate an SM2 key pair (hex-encoded), matching upstream xiaozhi crypto layout.
*/
export function generateSm2KeyPairHex() {
const sm2 = smCrypto.sm2
const keypair = sm2.generateKeyPairHex()
return {
@ -230,18 +224,15 @@ export function sm2Encrypt(publicKey: string, plainText: string): string {
throw new Error('Plaintext cannot be empty')
}
const sm2 = smCrypto.sm2
const encrypted = sm2.doEncrypt(plainText, publicKey, 1)
const result = `04${encrypted}`
return result
const normalizedKey = publicKey.trim().replace(/^0x/i, '').replace(/^04/i, '')
const encrypted = sm2.doEncrypt(plainText, normalizedKey, 1)
return `04${encrypted}`
}
/**
* SM2 private-key decryption (hex). Strips a leading 04 prefix if present.
*/
export function sm2Decrypt(privateKey: string, cipherText: string): string {
const sm2 = smCrypto.sm2
const dataWithoutPrefix = cipherText.startsWith('04') ? cipherText.substring(2) : cipherText
return sm2.doDecrypt(dataWithoutPrefix, privateKey, 1)
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -63,7 +63,7 @@ if [ -d "main/xiaozhi-server/test" ]; then
fi
# 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!"
else
print_error "Python backend tests failed!"
@ -173,7 +173,7 @@ case "$1" in
--python-only)
print_status "Running Python tests only..."
cd main/xiaozhi-server
$PYTHON_CMD test/test_runner.py
PYTHONPATH=. $PYTHON_CMD ../digital-human/test_runner.py
;;
--java-only)
print_status "Running Java tests only..."