| 436 | } |
| 437 | |
| 438 | private async fetchFromAPI(payload: ExplainRequest): Promise<ClaudeExplainResponse> { |
| 439 | const response = await window.fetch(this.explainApiEndpoint, { |
| 440 | method: 'POST', |
| 441 | headers: {'Content-Type': 'application/json'}, |
| 442 | body: JSON.stringify(payload), |
| 443 | }); |
| 444 | |
| 445 | if (!response.ok) { |
| 446 | throw new Error(`Server returned ${response.status} ${response.statusText}`); |
| 447 | } |
| 448 | |
| 449 | return response.json() as Promise<ClaudeExplainResponse>; |
| 450 | } |
| 451 | |
| 452 | private getExplainContext(): ExplainContext { |
| 453 | return { |