| 377 | private closed = false; |
| 378 | |
| 379 | private extractText(result: any): string { |
| 380 | const parts = result?.content; |
| 381 | if (!Array.isArray(parts)) { |
| 382 | if (typeof result === "string") return result; |
| 383 | if (typeof result?.text === "string") return result.text; |
| 384 | return String(result ?? ""); |
| 385 | } |
| 386 | const texts = parts |
| 387 | .map((p: any) => { |
| 388 | if (p?.type === "text" && typeof p?.text === "string") return p.text; |
| 389 | if (typeof p?.text === "string") return p.text; |
| 390 | return ""; |
| 391 | }) |
| 392 | .filter(Boolean); |
| 393 | return texts.join("\n").trim(); |
| 394 | } |
| 395 | |
| 396 | private stripWikiExploreTail(text: string): string { |
| 397 | if (!text) return text; |