-
Notifications
You must be signed in to change notification settings - Fork 14
feat: enable default websearch #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0fc5841
feat(opencode): add exa mcp failure handling
Astro-Han 8923cb4
feat(opencode): store websearch credentials
Astro-Han 01e1439
feat(opencode): wire websearch auth into tool
Astro-Han 53cf5c2
feat(opencode): persist websearch runtime toggle
Astro-Han 1bdc47d
feat(desktop): expose websearch settings ipc
Astro-Han f02e276
feat(app): mirror websearch runtime setting
Astro-Han 0f31033
feat(app): add websearch settings dialog
Astro-Han 68bd2b6
feat(app): show websearch recovery toasts
Astro-Han File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/app/src/components/dialog-connect-websearch-source.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { describe, expect, test } from "bun:test" | ||
| import { readFileSync } from "node:fs" | ||
|
|
||
| const source = readFileSync(new URL("./dialog-connect-websearch.tsx", import.meta.url), "utf8") | ||
|
|
||
| describe("dialog-connect-websearch source contract", () => { | ||
| test("exports DialogConnectWebSearch", () => { | ||
| expect(source).toContain("export function DialogConnectWebSearch") | ||
| }) | ||
|
|
||
| test("renders all four state branches", () => { | ||
| // anonymous default state | ||
| expect(source).toContain('source === "anonymous"') | ||
| expect(source).toContain("quotaExceeded") | ||
| // env read-only state | ||
| expect(source).toContain('source === "env"') | ||
| // saved states (healthy and needsAttention both match on source === "saved") | ||
| expect(source).toContain('source === "saved"') | ||
| // needsAttention branch | ||
| expect(source).toContain("needsAttention") | ||
| }) | ||
|
|
||
| test("does not fabricate anonymous status before status loads", () => { | ||
| expect(source).not.toContain('source: "anonymous" as const') | ||
| expect(source).toContain("webSearchStatusResource.error") | ||
| expect(source).toContain("dialog.websearch.status.loading") | ||
| expect(source).toContain("dialog.websearch.status.error") | ||
| }) | ||
|
|
||
| test("calls window.api saveExaApiKey and removeExaApiKey", () => { | ||
| expect(source).toMatch(/window\.api[\s\S]{0,40}saveExaApiKey/) | ||
| expect(source).toMatch(/window\.api[\s\S]{0,40}removeExaApiKey/) | ||
| }) | ||
|
|
||
| test("imports Dialog from @opencode-ai/ui/dialog (visual pattern reuse)", () => { | ||
| expect(source).toContain('from "@opencode-ai/ui/dialog"') | ||
| }) | ||
|
|
||
| test("does NOT import useProviders or globalSDK (Exa is not an LLM provider)", () => { | ||
| expect(source).not.toContain("useProviders") | ||
| expect(source).not.toContain("globalSDK") | ||
| }) | ||
| }) |
276 changes: 276 additions & 0 deletions
276
packages/app/src/components/dialog-connect-websearch.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,276 @@ | ||
| import { Button } from "@opencode-ai/ui/button" | ||
| import { useDialog } from "@opencode-ai/ui/context/dialog" | ||
| import { Dialog } from "@opencode-ai/ui/dialog" | ||
| import { Icon } from "@opencode-ai/ui/icon" | ||
| import { IconButton } from "@opencode-ai/ui/icon-button" | ||
| import { TextField } from "@opencode-ai/ui/text-field" | ||
| import { showToast } from "@opencode-ai/ui/toast" | ||
| import { createMemo, createResource, createSignal, Match, Show, Switch } from "solid-js" | ||
| import { useLanguage } from "@/context/language" | ||
| import { Link } from "./link" | ||
|
|
||
| export function DialogConnectWebSearch() { | ||
| const dialog = useDialog() | ||
| const language = useLanguage() | ||
|
|
||
| const [webSearchStatusResource, webSearchStatusActions] = createResource(() => { | ||
| const load = window.api?.webSearchStatus | ||
| if (!load) throw new Error("Web Search settings are unavailable.") | ||
| return load() | ||
| }) | ||
| const status = createMemo(() => webSearchStatusResource.latest) | ||
| const statusError = createMemo(() => webSearchStatusResource.error) | ||
|
|
||
| const [apiKeyInput, setApiKeyInput] = createSignal("") | ||
| const [saving, setSaving] = createSignal(false) | ||
| const [removing, setRemoving] = createSignal(false) | ||
| // Validation error clears on input change (addresses PR #271 review P3). | ||
| const [validationError, setValidationError] = createSignal("") | ||
|
|
||
| const title = createMemo(() => { | ||
| const s = status() | ||
| if (statusError()) return language.t("common.requestFailed") | ||
| if (!s) return language.t("common.loading") | ||
| if (s.source === "saved" && s.needsAttention) return language.t("dialog.websearch.title.failed") | ||
| if (s.source === "saved") return language.t("dialog.websearch.title.saved") | ||
| if (s.source === "anonymous" && s.quotaExceeded) return language.t("dialog.websearch.title.exhausted") | ||
| return language.t("dialog.websearch.title.default") | ||
| }) | ||
|
|
||
| const handleSave = () => { | ||
| if (saving() || removing()) return | ||
| const key = apiKeyInput().trim() | ||
| if (!key) { | ||
| setValidationError(language.t("provider.connect.apiKey.required")) | ||
| return | ||
| } | ||
| if (!window.api?.saveExaApiKey) return | ||
| setSaving(true) | ||
| setValidationError("") | ||
| void window.api | ||
| .saveExaApiKey(key) | ||
| .then(() => { | ||
| setApiKeyInput("") | ||
| void webSearchStatusActions.refetch() | ||
| dialog.close() | ||
| showToast({ | ||
| variant: "success", | ||
| icon: "circle-check", | ||
| title: language.t("toast.websearch.saved.title"), | ||
| }) | ||
| }) | ||
| .catch((err: unknown) => { | ||
| const msg = err instanceof Error ? err.message : String(err || language.t("common.requestFailed")) | ||
| // Surface inline for key-shaped errors; toast for other errors. | ||
| setValidationError(msg) | ||
| }) | ||
| .finally(() => setSaving(false)) | ||
| } | ||
|
|
||
| const handleRemove = () => { | ||
| if (saving() || removing()) return | ||
| if (!window.api?.removeExaApiKey) return | ||
| setRemoving(true) | ||
| setValidationError("") | ||
| void window.api | ||
| .removeExaApiKey() | ||
| .then(() => { | ||
| setApiKeyInput("") | ||
| void webSearchStatusActions.refetch() | ||
| dialog.close() | ||
| showToast({ | ||
| variant: "success", | ||
| icon: "circle-check", | ||
| title: language.t("toast.websearch.removed.title"), | ||
| }) | ||
| }) | ||
| .catch((err: unknown) => { | ||
| showToast({ | ||
| title: language.t("common.requestFailed"), | ||
| description: err instanceof Error ? err.message : String(err), | ||
| variant: "error", | ||
| }) | ||
| }) | ||
| .finally(() => setRemoving(false)) | ||
| } | ||
|
|
||
| return ( | ||
| <Dialog | ||
| title={ | ||
| <IconButton | ||
| tabIndex={-1} | ||
| icon="arrow-left" | ||
| variant="ghost" | ||
| onClick={() => dialog.close()} | ||
| aria-label={language.t("common.goBack")} | ||
| /> | ||
| } | ||
| > | ||
| <div class="flex flex-col gap-6 px-2.5 pb-3"> | ||
| {/* Header: service icon + title */} | ||
| <div class="px-2.5 flex gap-4 items-center"> | ||
| <Icon name="link" class="size-5 shrink-0 icon-strong-base" /> | ||
| <div class="text-16-medium text-text-strong">{title()}</div> | ||
| </div> | ||
|
|
||
| <div class="px-2.5 pb-10 flex flex-col gap-6"> | ||
| <Switch> | ||
| {/* loading/error state: avoid showing anonymous setup before status is known */} | ||
| <Match when={statusError()}> | ||
| <div class="flex flex-col gap-4"> | ||
| <div class="text-14-regular text-text-base">{language.t("dialog.websearch.status.error")}</div> | ||
| <Button size="large" variant="primary" onClick={() => void webSearchStatusActions.refetch()}> | ||
| {language.t("dialog.websearch.action.retry")} | ||
| </Button> | ||
| </div> | ||
| </Match> | ||
|
|
||
| <Match when={!status()}> | ||
| <div class="text-14-regular text-text-base">{language.t("dialog.websearch.status.loading")}</div> | ||
| </Match> | ||
|
|
||
| {/* env state: read-only, no input, no save/remove */} | ||
| <Match when={status()?.source === "env"}> | ||
| <div class="text-14-regular text-text-base">{language.t("dialog.websearch.body.env")}</div> | ||
| </Match> | ||
|
|
||
| {/* saved + healthy state */} | ||
| <Match when={status()?.source === "saved" && !status()?.needsAttention}> | ||
| <div class="flex flex-col gap-4"> | ||
| <div class="text-14-regular text-text-base">{language.t("dialog.websearch.status.active")}</div> | ||
| <div class="flex gap-2"> | ||
| <Button size="large" variant="ghost" disabled={removing() || saving()} onClick={handleRemove}> | ||
| {language.t("dialog.websearch.action.remove")} | ||
| </Button> | ||
| <Button | ||
| size="large" | ||
| variant="primary" | ||
| disabled={saving() || removing() || apiKeyInput().trim() === ""} | ||
| onClick={handleSave} | ||
| > | ||
| {language.t("dialog.websearch.action.update")} | ||
| </Button> | ||
| </div> | ||
| <TextField | ||
| autofocus | ||
| type="password" | ||
| label={language.t("dialog.websearch.placeholder")} | ||
| hideLabel | ||
| placeholder={language.t("dialog.websearch.placeholder")} | ||
| value={apiKeyInput()} | ||
| onChange={(v) => { | ||
| setApiKeyInput(v) | ||
| // Clear validation error on input change (PR #271 review P3). | ||
| if (validationError()) setValidationError("") | ||
| }} | ||
| validationState={validationError() ? "invalid" : undefined} | ||
| error={validationError()} | ||
| autocomplete="off" | ||
| autocorrect="off" | ||
| autocapitalize="off" | ||
| spellcheck={false} | ||
| /> | ||
| </div> | ||
| </Match> | ||
|
|
||
| {/* saved + needsAttention state */} | ||
| <Match when={status()?.source === "saved" && status()?.needsAttention}> | ||
| <div class="flex flex-col gap-4"> | ||
| <div class="text-14-regular text-text-base">{language.t("dialog.websearch.status.failed")}</div> | ||
| <TextField | ||
| autofocus | ||
| type="password" | ||
| label={language.t("dialog.websearch.placeholder")} | ||
| hideLabel | ||
| placeholder={language.t("dialog.websearch.placeholder")} | ||
| value={apiKeyInput()} | ||
| onChange={(v) => { | ||
| setApiKeyInput(v) | ||
| if (validationError()) setValidationError("") | ||
| }} | ||
| validationState={validationError() ? "invalid" : undefined} | ||
| error={validationError()} | ||
| autocomplete="off" | ||
| autocorrect="off" | ||
| autocapitalize="off" | ||
| spellcheck={false} | ||
| /> | ||
| <div class="flex gap-2"> | ||
| <Button size="large" variant="ghost" disabled={removing() || saving()} onClick={handleRemove}> | ||
| {language.t("dialog.websearch.action.removeShort")} | ||
| </Button> | ||
| <Button | ||
| size="large" | ||
| variant="primary" | ||
| disabled={saving() || removing() || apiKeyInput().trim() === ""} | ||
| onClick={handleSave} | ||
| > | ||
| {language.t("dialog.websearch.action.saveShort")} | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| </Match> | ||
|
|
||
| {/* anonymous (default) state */} | ||
| <Match when={status()?.source === "anonymous"}> | ||
| <div class="flex flex-col gap-4"> | ||
| <div class="text-14-regular text-text-base"> | ||
| {language.t( | ||
| status()?.quotaExceeded | ||
| ? "dialog.websearch.body.exhausted.line1" | ||
| : "dialog.websearch.body.default.line1", | ||
| )} | ||
| </div> | ||
| <div class="text-14-regular text-text-base"> | ||
| {language.t( | ||
| status()?.quotaExceeded | ||
| ? "dialog.websearch.body.exhausted.line2" | ||
| : "dialog.websearch.body.default.line2", | ||
| )} | ||
| </div> | ||
| <TextField | ||
| autofocus | ||
| type="password" | ||
| label={language.t("dialog.websearch.placeholder")} | ||
| hideLabel | ||
| placeholder={language.t("dialog.websearch.placeholder")} | ||
| value={apiKeyInput()} | ||
| onChange={(v) => { | ||
| setApiKeyInput(v) | ||
| if (validationError()) setValidationError("") | ||
| }} | ||
| validationState={validationError() ? "invalid" : undefined} | ||
| error={validationError()} | ||
| autocomplete="off" | ||
| autocorrect="off" | ||
| autocapitalize="off" | ||
| spellcheck={false} | ||
| /> | ||
| <div class="text-12-regular text-text-weak"> | ||
| {language.t( | ||
| status()?.quotaExceeded ? "dialog.websearch.status.exhausted" : "dialog.websearch.status.bundled", | ||
| )} | ||
| </div> | ||
| <div class="flex flex-col gap-2"> | ||
| <Button | ||
| size="large" | ||
| variant="primary" | ||
| disabled={saving() || removing() || apiKeyInput().trim() === ""} | ||
| onClick={handleSave} | ||
| > | ||
| {language.t("dialog.websearch.action.save")} | ||
| </Button> | ||
| <Show when={!saving()}> | ||
| <div class="text-12-regular text-text-weak"> | ||
| <Link href="https://exa.ai">{language.t("dialog.websearch.help.getKey")}</Link> | ||
| </div> | ||
| </Show> | ||
| </div> | ||
| </div> | ||
| </Match> | ||
| </Switch> | ||
| </div> | ||
| </div> | ||
| </Dialog> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.