mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-27 21:01:32 +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
aaef458010
commit
cacabfa56d
@ -242,7 +242,7 @@ export const formatCitationsFromBlock = (block: CitationMessageBlock | undefined
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 3. Handle Knowledge Base References
|
// 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(
|
formattedCitations.push(
|
||||||
...block.knowledge.map((result, index) => {
|
...block.knowledge.map((result, index) => {
|
||||||
const filePattern = /\[(.*?)]\(http:\/\/file\/(.*?)\)/
|
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
|
// 5. Handle Memory References
|
||||||
formattedCitations.push(
|
formattedCitations.push(
|
||||||
...block.memories.map((memory, index) => ({
|
...block.memories.map((memory, index) => ({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user