From a430284aa21e3ae1f0d5654e55b2ad2852519cc2 Mon Sep 17 00:00:00 2001 From: wwf <yearningwang@iqtogether.com> Date: 星期三, 04 六月 2025 15:17:49 +0800 Subject: [PATCH] 初始化 --- app/components/base/chat/utils.ts | 43 ++++++++++--------------------------------- 1 files changed, 10 insertions(+), 33 deletions(-) diff --git a/app/components/base/chat/utils.ts b/app/components/base/chat/utils.ts index bdac599..ce7a7c0 100644 --- a/app/components/base/chat/utils.ts +++ b/app/components/base/chat/utils.ts @@ -3,42 +3,20 @@ import type { ChatItem, ChatItemInTree } from './types' async function decodeBase64AndDecompress(base64String: string) { - try { - const binaryString = atob(base64String) - const compressedUint8Array = Uint8Array.from(binaryString, char => char.charCodeAt(0)) - const decompressedStream = new Response(compressedUint8Array).body?.pipeThrough(new DecompressionStream('gzip')) - const decompressedArrayBuffer = await new Response(decompressedStream).arrayBuffer() - return new TextDecoder().decode(decompressedArrayBuffer) - } - catch { - return undefined - } + const binaryString = atob(base64String) + const compressedUint8Array = Uint8Array.from(binaryString, char => char.charCodeAt(0)) + const decompressedStream = new Response(compressedUint8Array).body?.pipeThrough(new DecompressionStream('gzip')) + const decompressedArrayBuffer = await new Response(decompressedStream).arrayBuffer() + return new TextDecoder().decode(decompressedArrayBuffer) } -async function getProcessedInputsFromUrlParams(): Promise<Record<string, any>> { +function getProcessedInputsFromUrlParams(): Record<string, any> { const urlParams = new URLSearchParams(window.location.search) const inputs: Record<string, any> = {} - const entriesArray = Array.from(urlParams.entries()) - await Promise.all( - entriesArray.map(async ([key, value]) => { - if (!key.startsWith('sys.')) - inputs[key] = await decodeBase64AndDecompress(decodeURIComponent(value)) - }), - ) + urlParams.forEach(async (value, key) => { + inputs[key] = await decodeBase64AndDecompress(decodeURIComponent(value)) + }) return inputs -} - -async function getProcessedSystemVariablesFromUrlParams(): Promise<Record<string, any>> { - const urlParams = new URLSearchParams(window.location.search) - const systemVariables: Record<string, any> = {} - const entriesArray = Array.from(urlParams.entries()) - await Promise.all( - entriesArray.map(async ([key, value]) => { - if (key.startsWith('sys.')) - systemVariables[key.slice(4)] = await decodeBase64AndDecompress(decodeURIComponent(value)) - }), - ) - return systemVariables } function isValidGeneratedAnswer(item?: ChatItem | ChatItemInTree): boolean { @@ -122,7 +100,7 @@ let targetNode: ChatItemInTree | undefined // find path to the target message - const stack = tree.slice().reverse().map(rootNode => ({ + const stack = tree.toReversed().map(rootNode => ({ node: rootNode, path: [rootNode], })) @@ -185,7 +163,6 @@ export { getProcessedInputsFromUrlParams, - getProcessedSystemVariablesFromUrlParams, isValidGeneratedAnswer, getLastAnswer, buildChatItemTree, -- Gitblit v1.8.0