mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
refactor(core): extract duplicated retry logic in WebFetchTool
This commit is contained in:
@@ -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',
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user