(repo: string, question: string)
| 430 | } |
| 431 | |
| 432 | async ask(repo: string, question: string): Promise<string> { |
| 433 | if (this.closed) throw new Error("DeepWiki MCP client is closed"); |
| 434 | const repoKey = repo.trim(); |
| 435 | const questionKey = question.trim(); |
| 436 | if (!repoKey) throw new Error("缺少仓库信息"); |
| 437 | if (!questionKey) throw new Error("问题不能为空"); |
| 438 | |
| 439 | if (!this.client || this.repoKey !== repoKey || this.questionKey !== questionKey) { |
| 440 | this.client = null; |
| 441 | this.repoKey = null; |
| 442 | this.questionKey = null; |
| 443 | await this.ensureConnected(); |
| 444 | this.repoKey = repoKey; |
| 445 | this.questionKey = questionKey; |
| 446 | } |
| 447 | |
| 448 | const result = await this.client.callTool({ |
| 449 | name: "ask_question", |
| 450 | arguments: { |
| 451 | repoName: repoKey, |
| 452 | question: questionKey, |
| 453 | }, |
| 454 | }); |
| 455 | |
| 456 | const text = this.stripWikiExploreTail(this.extractText(result)); |
| 457 | if (!text) throw new Error("DeepWiki 返回为空"); |
| 458 | return text; |
| 459 | } |
| 460 | |
| 461 | async close(): Promise<void> { |
| 462 | this.closed = true; |
no test coverage detected