fix(tools): refine DeepSeek search credentials and query validation
Require a configured Search API key while preserving explicit ${VAR_NAME} references.
Reject overlong Unicode queries locally instead of silently truncating them.
Keep the shared Settings flow and condense the configuration documentation.
This commit is contained in:
1 parent
e5b469ebd4
commit
dca49c258a
6 files changed
+136
-82
No files matched your search
@@ -3,7 +3,7 @@ import type { TFunction } from "i18next";
|
||||
|
||||
import {
|
||||
webSearchProviderAcceptsApiKey,
|
||||
webSearchProviderRequiresApiKey,
|
||||
webSearchDraftState,
|
||||
} from "@/components/settings/capabilities/WebSettings";
|
||||
import type { CapabilitySettingsState } from "@/components/settings/capabilities/useCapabilitySettingsState";
|
||||
import type {
|
||||
@@ -151,17 +151,7 @@ export function useCapabilitySettingsActions({
|
||||
if (!provider) return;
|
||||
const apiKey = webSearchForm.apiKey?.trim() ?? "";
|
||||
const baseUrl = webSearchForm.baseUrl?.trim() ?? "";
|
||||
const hasExistingSecret =
|
||||
webSearchProviderAcceptsApiKey(provider) &&
|
||||
webSearchForm.provider === settings.web_search.provider &&
|
||||
!!settings.web_search.api_key_hint;
|
||||
|
||||
if (webSearchProviderRequiresApiKey(provider) && !apiKey && !hasExistingSecret) {
|
||||
return;
|
||||
}
|
||||
if (provider.credential === "base_url" && !baseUrl) {
|
||||
return;
|
||||
}
|
||||
if (webSearchDraftState(settings, webSearchForm).missingCredential) return;
|
||||
|
||||
setError("web");
|
||||
setWebSearchSaving(true);
|
||||
|
||||
@@ -374,6 +374,42 @@ describe("Settings capabilities", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("requires an explicit DeepSeek search key before saving and preserves it on later edits", async () => {
|
||||
let payload: SettingsPayload = settingsPayload();
|
||||
payload.web_search.providers.push({
|
||||
name: "deepseek", label: "DeepSeek", credential: "api_key",
|
||||
});
|
||||
requestMutationMock.mockImplementation(async (_method, update) => {
|
||||
payload = { ...payload, web_search: {
|
||||
...payload.web_search, provider: update.provider, timeout: update.timeout,
|
||||
api_key_hint: "sk-d...key",
|
||||
} };
|
||||
return payload;
|
||||
});
|
||||
renderSettingsView({ initialSection: "browser", initialSettings: payload });
|
||||
|
||||
fireEvent.keyDown(screen.getByRole("combobox", { name: "DuckDuckGo" }), { key: "ArrowDown" });
|
||||
fireEvent.click(await screen.findByRole("option", { name: "DeepSeek" }));
|
||||
expect(await screen.findByText("Add the required credential before saving.")).toBeVisible();
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
fireEvent.change(screen.getByPlaceholderText("Enter API key"), { target: { value: "sk-deepseek-search-key" } });
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith(
|
||||
"settings.web_search.update",
|
||||
{ provider: "deepseek", api_key: "sk-deepseek-search-key", max_results: 5, timeout: 30, use_jina_reader: true },
|
||||
20_000,
|
||||
));
|
||||
expect(await screen.findByText("sk-d...key")).toBeVisible();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Advanced options" }));
|
||||
const timeout = screen.getAllByRole("spinbutton").find((input) => (input as HTMLInputElement).value === "30")!;
|
||||
fireEvent.change(timeout, { target: { value: "45" } });
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
|
||||
"settings.web_search.update",
|
||||
{ provider: "deepseek", max_results: 5, timeout: 45, use_jina_reader: true },
|
||||
20_000,
|
||||
));
|
||||
});
|
||||
|
||||
it("uses native host safety copy on the native surface", async () => {
|
||||
const payload = {
|
||||
...settingsPayload(),
|
||||
|
||||
Reference in new issue
Block a user