feat(coding-agent/web): ensured proper cleanup of authentication storage

- Added a mandatory check to ensure authentication storage is successfully initialized before executing searches.
- Implemented a finally block to close the discovered authentication storage after the search execution completes.
This commit is contained in:
can1357
2026-07-11 07:33:21 +02:00
parent 46fd8c5575
commit 376084c19a
+14 -6
View File
@@ -231,12 +231,20 @@ export async function runSearchQuery(
params: SearchQueryParams,
options: { authStorage?: AuthStorage; sessionId?: string; signal?: AbortSignal } = {},
): Promise<{ content: Array<{ type: "text"; text: string }>; details: SearchRenderDetails }> {
const authStorage = options.authStorage ?? (await discoverAuthStorage());
return executeSearch("cli-web-search", params, {
authStorage,
sessionId: options.sessionId,
signal: options.signal,
});
const createdAuthStorage = options.authStorage ? undefined : await discoverAuthStorage();
const authStorage = options.authStorage ?? createdAuthStorage;
if (!authStorage) {
throw new Error("Failed to initialize authentication storage");
}
try {
return await executeSearch("cli-web-search", params, {
authStorage,
sessionId: options.sessionId,
signal: options.signal,
});
} finally {
createdAuthStorage?.close();
}
}
/**