refine thinking part filtering
This commit is contained in:
@@ -31,3 +31,44 @@ export interface TextPart {
|
||||
synthetic?: boolean
|
||||
renderCache?: RenderCache
|
||||
}
|
||||
|
||||
function hasTextSegment(segment: unknown): boolean {
|
||||
if (typeof segment === "string") {
|
||||
return segment.trim().length > 0
|
||||
}
|
||||
|
||||
if (segment && typeof segment === "object") {
|
||||
const maybeText = (segment as { text?: unknown }).text
|
||||
if (typeof maybeText === "string") {
|
||||
return maybeText.trim().length > 0
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
export function partHasRenderableText(part: any): boolean {
|
||||
if (!part || typeof part !== "object") {
|
||||
return false
|
||||
}
|
||||
|
||||
if (hasTextSegment(part.text)) {
|
||||
return true
|
||||
}
|
||||
|
||||
const contentArray = Array.isArray(part?.content) ? part.content : []
|
||||
for (const item of contentArray) {
|
||||
if (hasTextSegment(item)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
const thinkingContent = Array.isArray(part?.thinking?.content) ? part.thinking.content : []
|
||||
for (const chunk of thinkingContent) {
|
||||
if (hasTextSegment(chunk)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user