| 172 | } |
| 173 | |
| 174 | private async request(path: string, method: "GET" | "POST", body?: any): Promise<any> { |
| 175 | await this.readyPromise; |
| 176 | |
| 177 | const url = `${this.baseUrl}${path}`; |
| 178 | try { |
| 179 | const response = await fetch(url, { |
| 180 | method, |
| 181 | headers: body ? { "Content-Type": "application/json" } : undefined, |
| 182 | body: body ? JSON.stringify(body) : undefined, |
| 183 | }); |
| 184 | |
| 185 | if (!response.ok) { |
| 186 | throw new Error(`HTTP error! status: ${response.status}`); |
| 187 | } |
| 188 | |
| 189 | return await response.json(); |
| 190 | } catch (error: any) { |
| 191 | throw new Error(`Failed to communicate with DocsAgent service: ${error.message}`); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Real-time document addition interface. |