feat: Add user variable processing function to chat history (#22863)

This commit is contained in:
croatialu
2025-07-24 10:06:49 +08:00
committed by GitHub
parent ef51678c73
commit d1572f47a0
5 changed files with 37 additions and 4 deletions

View File

@@ -20,7 +20,8 @@ async function getRawInputsFromUrlParams(): Promise<Record<string, any>> {
const inputs: Record<string, any> = {}
const entriesArray = Array.from(urlParams.entries())
entriesArray.forEach(([key, value]) => {
if (!key.startsWith('sys.'))
const prefixArray = ['sys.', 'user.']
if (!prefixArray.some(prefix => key.startsWith(prefix)))
inputs[key] = decodeURIComponent(value)
})
return inputs
@@ -66,6 +67,17 @@ async function getProcessedUserVariablesFromUrlParams(): Promise<Record<string,
return userVariables
}
async function getRawUserVariablesFromUrlParams(): Promise<Record<string, any>> {
const urlParams = new URLSearchParams(window.location.search)
const userVariables: Record<string, any> = {}
const entriesArray = Array.from(urlParams.entries())
entriesArray.forEach(([key, value]) => {
if (key.startsWith('user.'))
userVariables[key.slice(5)] = decodeURIComponent(value)
})
return userVariables
}
function isValidGeneratedAnswer(item?: ChatItem | ChatItemInTree): boolean {
return !!item && item.isAnswer && !item.id.startsWith('answer-placeholder-') && !item.isOpeningStatement
}
@@ -213,6 +225,7 @@ export {
getProcessedInputsFromUrlParams,
getProcessedSystemVariablesFromUrlParams,
getProcessedUserVariablesFromUrlParams,
getRawUserVariablesFromUrlParams,
isValidGeneratedAnswer,
getLastAnswer,
buildChatItemTree,