mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 11:20:07 +08:00
fix: add array checks for knowledge and memories in citations (#10778)
Updated formatCitationsFromBlock to verify that 'knowledge' and 'memories' are arrays before accessing their length and mapping over them. This prevents potential runtime errors if these properties are not arrays.
This commit is contained in:
parent
79c697c34d
commit
a290ee7f39
@ -242,7 +242,7 @@ export const formatCitationsFromBlock = (block: CitationMessageBlock | undefined
|
||||
}
|
||||
}
|
||||
// 3. Handle Knowledge Base References
|
||||
if (block.knowledge && block.knowledge.length > 0) {
|
||||
if (block.knowledge && Array.isArray(block.knowledge) && block.knowledge.length > 0) {
|
||||
formattedCitations.push(
|
||||
...block.knowledge.map((result, index) => {
|
||||
const filePattern = /\[(.*?)]\(http:\/\/file\/(.*?)\)/
|
||||
@ -270,7 +270,7 @@ export const formatCitationsFromBlock = (block: CitationMessageBlock | undefined
|
||||
)
|
||||
}
|
||||
|
||||
if (block.memories && block.memories.length > 0) {
|
||||
if (block.memories && Array.isArray(block.memories) && block.memories.length > 0) {
|
||||
// 5. Handle Memory References
|
||||
formattedCitations.push(
|
||||
...block.memories.map((memory, index) => ({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user