fix(formats): add optional chaining for grounding support properties to prevent errors

This commit is contained in:
suyao 2025-04-08 17:18:39 +08:00 committed by 亢奋猫
parent d38c4c7368
commit 97c1d67cbf

View File

@ -71,12 +71,16 @@ export function withGeminiGrounding(message: Message) {
let content = message.content let content = message.content
groundingSupports.forEach((support) => { groundingSupports.forEach((support) => {
const text = support.segment.text const text = support?.segment
const indices = support.groundingChunkIndices const indices = support?.groundingChunckIndices
const nodes = indices.reduce((acc, index) => {
if (!text || !indices) return
const nodes = indices.reduce<string[]>((acc, index) => {
acc.push(`<sup>${index + 1}</sup>`) acc.push(`<sup>${index + 1}</sup>`)
return acc return acc
}, []) }, [])
content = content.replace(text, `${text} ${nodes.join(' ')}`) content = content.replace(text, `${text} ${nodes.join(' ')}`)
}) })