diff --git a/src/api/all/chat.ts b/src/api/all/chat.ts index ebd37d6..be7fea7 100644 --- a/src/api/all/chat.ts +++ b/src/api/all/chat.ts @@ -3,6 +3,7 @@ import axios from 'axios'; import { glsWithCatch } from '@/utils/stroage'; import { useEnterpriseStore } from '@/stores/modules/enterprise'; export const BASE_PYTHON_URL = 'https://agent.lvfunai.com'; +import { genRandomId } from '@/utils/tools'; // 历史记录-列表 export const getAgentHistory = (id: string) => { @@ -32,10 +33,11 @@ export const getConversationList = (params: {}) => { export const getHeaders = () => { const store = useEnterpriseStore(); return { - 'Authorization': glsWithCatch('accessToken'), + Authorization: glsWithCatch('accessToken'), 'enterprise-id': store.enterpriseInfo?.id, - 'Accept': 'application/json', + Accept: 'application/json', 'Content-Type': 'application/json', + requestid: genRandomId(), }; }; @@ -57,4 +59,4 @@ export const createSession = async () => { headers: getHeaders(), }); return data; -}; \ No newline at end of file +}; diff --git a/src/components/xt-chat/xt-bubble/hooks/useTypedEffect.ts b/src/components/xt-chat/xt-bubble/hooks/useTypedEffect.ts index d28d183..26509b1 100644 --- a/src/components/xt-chat/xt-bubble/hooks/useTypedEffect.ts +++ b/src/components/xt-chat/xt-bubble/hooks/useTypedEffect.ts @@ -132,7 +132,7 @@ const useTypedEffect = ( const isTyping = computed( () => mergedTypingEnabled.value && - unref(typingIndex) < content.value.length && // 此时 content.value 已被 mergedTypingEnabled 限定为 string + unref(typingIndex) < (content.value as string).length && // 此时 content.value 已被 mergedTypingEnabled 限定为 string !(abortRef && abortRef.value), ); diff --git a/src/utils/querySSE.ts b/src/utils/querySSE.ts index b0f4960..e096531 100644 --- a/src/utils/querySSE.ts +++ b/src/utils/querySSE.ts @@ -3,6 +3,7 @@ import type { EventSourceMessage } from '@microsoft/fetch-event-source'; import { useEnterpriseStore } from '@/stores/modules/enterprise'; import { glsWithCatch } from '@/utils/stroage'; import { BASE_PYTHON_URL } from '@/api/all/chat'; +import { genRandomId } from '@/utils/tools'; const DEFAULT_SSE_URL = `${BASE_PYTHON_URL}/api/agent/runs`; @@ -11,6 +12,7 @@ const SSE_HEADERS = { 'Cache-Control': 'no-cache', Connection: 'keep-alive', Accept: 'text/event-stream', + requestid: genRandomId(), }; interface SSEConfig { diff --git a/src/utils/tools.ts b/src/utils/tools.ts index acbb191..da345bb 100644 --- a/src/utils/tools.ts +++ b/src/utils/tools.ts @@ -108,7 +108,7 @@ export function downloadByUrl(url: string, filename?: string) { } export function genRandomId() { - return `id_${Date.now()}_${Math.floor(Math.random() * 10000)}`; + return `id_${dayjs().unix()}_${Math.floor(Math.random() * 10000)}`; } export function formatFileSize(bytes: number): string { @@ -397,7 +397,7 @@ export function getImageMainColor(imageUrl: string): Promise { const avgColor = { r: Math.round(maxGroup.sumR / maxGroup.count), g: Math.round(maxGroup.sumG / maxGroup.count), - b: Math.round(maxGroup.sumB / maxGroup.count) + b: Math.round(maxGroup.sumB / maxGroup.count), }; resolve(`rgb(${avgColor.r},${avgColor.g},${avgColor.b})`); @@ -427,28 +427,38 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] { if (a < 128) continue; colors.push({ - r, g, b, + r, + g, + b, count: 1, - sumR: r, sumG: g, sumB: b + sumR: r, + sumG: g, + sumB: b, }); } // 如果没有颜色数据,返回默认白色 if (colors.length === 0) { - return [{ - count: 1, - sumR: 255, sumG: 255, sumB: 255 - }]; + return [ + { + count: 1, + sumR: 255, + sumG: 255, + sumB: 255, + }, + ]; } // 开始中位数切分 - let colorGroups = [{ - colors, - count: colors.length, - sumR: colors.reduce((sum, c) => sum + c.r, 0), - sumG: colors.reduce((sum, c) => sum + c.g, 0), - sumB: colors.reduce((sum, c) => sum + c.b, 0) - }]; + let colorGroups = [ + { + colors, + count: colors.length, + sumR: colors.reduce((sum, c) => sum + c.r, 0), + sumG: colors.reduce((sum, c) => sum + c.g, 0), + sumB: colors.reduce((sum, c) => sum + c.b, 0), + }, + ]; for (let i = 0; i < levels; i++) { const newGroups = []; @@ -460,12 +470,12 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] { } // 找出颜色范围最大的通道 - const rMin = Math.min(...group.colors.map(c => c.r)); - const rMax = Math.max(...group.colors.map(c => c.r)); - const gMin = Math.min(...group.colors.map(c => c.g)); - const gMax = Math.max(...group.colors.map(c => c.g)); - const bMin = Math.min(...group.colors.map(c => c.b)); - const bMax = Math.max(...group.colors.map(c => c.b)); + const rMin = Math.min(...group.colors.map((c) => c.r)); + const rMax = Math.max(...group.colors.map((c) => c.r)); + const gMin = Math.min(...group.colors.map((c) => c.g)); + const gMax = Math.max(...group.colors.map((c) => c.g)); + const bMin = Math.min(...group.colors.map((c) => c.b)); + const bMax = Math.max(...group.colors.map((c) => c.b)); const rRange = rMax - rMin; const gRange = gMax - gMin; @@ -500,7 +510,7 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] { count: group1.length, sumR: group1.reduce((sum, c) => sum + c.r, 0), sumG: group1.reduce((sum, c) => sum + c.g, 0), - sumB: group1.reduce((sum, c) => sum + c.b, 0) + sumB: group1.reduce((sum, c) => sum + c.b, 0), }); newGroups.push({ @@ -508,7 +518,7 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] { count: group2.length, sumR: group2.reduce((sum, c) => sum + c.r, 0), sumG: group2.reduce((sum, c) => sum + c.g, 0), - sumB: group2.reduce((sum, c) => sum + c.b, 0) + sumB: group2.reduce((sum, c) => sum + c.b, 0), }); } @@ -516,4 +526,4 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] { } return colorGroups; -} \ No newline at end of file +}