This commit is contained in:
2025-11-10 00:59:40 +08:00
parent 78c46aed71
commit bac96fcbe6
76 changed files with 8726 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
import http from '@/api/http'
import { fetchEventSource } from '@microsoft/fetch-event-source'
import { getAuthHeader } from '@/utils/token-manager'
// 使用本地代理前缀 /tikhub开发环境通过 Vite 代理到 https://api.tikhub.io
const SERVER_BASE = '/webApi/admin-api/ai/tikHup'
export const CommonService = {
videoToCharacters(data) {
return http.post(`${SERVER_BASE}/videoToCharacters2`, data)
},
callWorkflow(data) {
return http.post(`${SERVER_BASE}/callWorkflow`, data)
},
// 流式调用 workflow
callWorkflowStream: async (options) => {
const {
data,
ctrl,
onMessage,
onError,
onClose
} = options || {}
const authHeader = getAuthHeader()
let retryCount = 0
const maxRetries = 0 // 禁用自动重试
return fetchEventSource(`${SERVER_BASE}/callWorkflow`, {
method: 'post',
headers: {
'Content-Type': 'application/json',
...(authHeader ? { Authorization: authHeader } : {})
},
openWhenHidden: true,
body: JSON.stringify(data),
onmessage: onMessage,
onerror: (err) => {
retryCount++
console.error('SSE错误重试次数:', retryCount, err)
// 调用自定义错误处理
if (typeof onError === 'function') {
onError(err)
}
// 超过最大重试次数,停止重连
if (retryCount > maxRetries) {
throw err // 抛出错误,停止自动重连
}
},
onclose: () => {
// 调用自定义关闭处理
if (typeof onClose === 'function') {
onClose()
}
},
signal: ctrl ? ctrl.signal : undefined
})
}
}
export default CommonService