(signal: AbortSignal)
| 177 | } |
| 178 | |
| 179 | async execute(signal: AbortSignal): Promise<ToolResult> { |
| 180 | const userPrompt = this.params.prompt; |
| 181 | const urls = extractUrls(userPrompt); |
| 182 | const url = urls[0]; |
| 183 | const isPrivate = isPrivateIp(url); |
| 184 | |
| 185 | if (isPrivate) { |
| 186 | return this.executeFallback(signal); |
| 187 | } |
| 188 | |
| 189 | const anusClient = this.config.getAnusClient(); |
| 190 | |
| 191 | try { |
| 192 | const response = await anusClient.generateContent( |
| 193 | [{ role: 'user', parts: [{ text: userPrompt }] }], |
| 194 | { tools: [{ urlContext: {} }] }, |
| 195 | signal, // Pass signal |
| 196 | ); |
| 197 | |
| 198 | console.debug( |
| 199 | `[WebFetchTool] Full response for prompt "${userPrompt.substring( |
| 200 | 0, |
| 201 | 50, |
| 202 | )}...":`, |
| 203 | JSON.stringify(response, null, 2), |
| 204 | ); |
| 205 | |
| 206 | let responseText = getResponseText(response) || ''; |
| 207 | const urlContextMeta = response.candidates?.[0]?.urlContextMetadata; |
| 208 | const groundingMetadata = response.candidates?.[0]?.groundingMetadata; |
| 209 | const sources = groundingMetadata?.groundingChunks as |
| 210 | | GroundingChunkItem[] |
| 211 | | undefined; |
| 212 | const groundingSupports = groundingMetadata?.groundingSupports as |
| 213 | | GroundingSupportItem[] |
| 214 | | undefined; |
| 215 | |
| 216 | // Error Handling |
| 217 | let processingError = false; |
| 218 | |
| 219 | if ( |
| 220 | urlContextMeta?.urlMetadata && |
| 221 | urlContextMeta.urlMetadata.length > 0 |
| 222 | ) { |
| 223 | const allStatuses = urlContextMeta.urlMetadata.map( |
| 224 | (m) => m.urlRetrievalStatus, |
| 225 | ); |
| 226 | if (allStatuses.every((s) => s !== 'URL_RETRIEVAL_STATUS_SUCCESS')) { |
| 227 | processingError = true; |
| 228 | } |
| 229 | } else if (!responseText.trim() && !sources?.length) { |
| 230 | // No URL metadata and no content/sources |
| 231 | processingError = true; |
| 232 | } |
| 233 | |
| 234 | if ( |
| 235 | !processingError && |
| 236 | !responseText.trim() && |
nothing calls this directly
no test coverage detected