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
groundingSupports.forEach((support) => {
const text = support.segment.text
const indices = support.groundingChunkIndices
const nodes = indices.reduce((acc, index) => {
const text = support?.segment
const indices = support?.groundingChunckIndices
if (!text || !indices) return
const nodes = indices.reduce<string[]>((acc, index) => {
acc.push(`<sup>${index + 1}</sup>`)
return acc
}, [])
content = content.replace(text, `${text} ${nodes.join(' ')}`)
})