refactor(core): extract duplicated retry logic in WebFetchTool

This commit is contained in:
Aishanee Shah
2026-03-10 02:02:37 +00:00
parent bf14963791
commit 84acb66ef2
+14 -18
View File
@@ -185,6 +185,16 @@ class WebFetchToolInvocation extends BaseToolInvocation<
super(params, messageBus, _toolName, _toolDisplayName); super(params, messageBus, _toolName, _toolDisplayName);
} }
private handleRetry(attempt: number, error: unknown, delayMs: number): void {
coreEvents.emitRetryAttempt({
attempt,
maxAttempts: this.config.getMaxAttempts(),
delayMs,
error: error instanceof Error ? error.message : String(error),
model: 'Web Fetch',
});
}
private async executeFallback(signal: AbortSignal): Promise<ToolResult> { private async executeFallback(signal: AbortSignal): Promise<ToolResult> {
const { validUrls: urls } = parsePrompt(this.params.prompt!); const { validUrls: urls } = parsePrompt(this.params.prompt!);
// For now, we only support one URL for fallback // For now, we only support one URL for fallback
@@ -213,15 +223,8 @@ class WebFetchToolInvocation extends BaseToolInvocation<
}, },
{ {
retryFetchErrors: this.config.getRetryFetchErrors(), retryFetchErrors: this.config.getRetryFetchErrors(),
onRetry: (attempt, error, delayMs) => { onRetry: (attempt, error, delayMs) =>
coreEvents.emitRetryAttempt({ this.handleRetry(attempt, error, delayMs),
attempt,
maxAttempts: this.config.getMaxAttempts(),
delayMs,
error: error instanceof Error ? error.message : String(error),
model: 'Web Fetch',
});
},
}, },
); );
@@ -415,15 +418,8 @@ ${textContent}
}, },
{ {
retryFetchErrors: this.config.getRetryFetchErrors(), retryFetchErrors: this.config.getRetryFetchErrors(),
onRetry: (attempt, error, delayMs) => { onRetry: (attempt, error, delayMs) =>
coreEvents.emitRetryAttempt({ this.handleRetry(attempt, error, delayMs),
attempt,
maxAttempts: this.config.getMaxAttempts(),
delayMs,
error: error instanceof Error ? error.message : String(error),
model: 'Web Fetch',
});
},
}, },
); );