Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

feat(web): translate web search in Connectors and its key card

Kilyn77abdcb37f77
diff --git a/apps/web/src/features/apps/app-groups.ts b/apps/web/src/features/apps/app-groups.ts
index f86d4a65..7bd7b79b 100644
--- a/apps/web/src/features/apps/app-groups.ts
+++ b/apps/web/src/features/apps/app-groups.ts
@@ -18,7 +18,10 @@ export interface AppGroup {
* product nouns such as Profile, Chats, Docs, Projects and Sources.
*/
/** The Connectors tab for web search, beside the Composio app groups. */
-export const WEB_SEARCH_FILTER = { id: "web-search", label: "Web search" };
+export const WEB_SEARCH_FILTER = {
+ id: "web-search",
+ label: m.filterWebSearch,
+};
export const APP_GROUPS: readonly AppGroup[] = [
{
diff --git a/apps/web/src/features/apps/connected-apps-page.tsx b/apps/web/src/features/apps/connected-apps-page.tsx
index 1ea42e0d..0d9b74b8 100644
--- a/apps/web/src/features/apps/connected-apps-page.tsx
+++ b/apps/web/src/features/apps/connected-apps-page.tsx
@@ -80,7 +80,7 @@ export function ConnectedAppsPage() {
const filters = [
{ id: "all", label: t(m.filterAll) },
...groups.map(({ group }) => ({ id: group.id, label: t(group.title) })),
- WEB_SEARCH_FILTER,
+ { id: WEB_SEARCH_FILTER.id, label: t(WEB_SEARCH_FILTER.label) },
];
const groupApps = groups.find((entry) => entry.group.id === filter)?.apps;
// Connected only narrows whichever view is open; with All it is one grid.
diff --git a/apps/web/src/features/apps/connectors.messages.ts b/apps/web/src/features/apps/connectors.messages.ts
index cf7c364c..1ae612e5 100644
--- a/apps/web/src/features/apps/connectors.messages.ts
+++ b/apps/web/src/features/apps/connectors.messages.ts
@@ -147,6 +147,46 @@ export const connectorMessages = defineMessages("connectors", {
authorizationComplete: "Authorization complete",
canCloseWindow: "You can close this window.",
+ // Web search backends, beside the app groups. Backend names, descriptions
+ // and free tier text come from TeamHub.
+ filterWebSearch: "Web search",
+ loadingWebSearch: "Loading web search...",
+ defaultBackend: "Default",
+ searchKeyRejected: "Key rejected",
+ // {usage} is what is left on the account, such as "1,000 credits left".
+ connectedWithUsage: "Connected · {usage}",
+ freeLimited: "Free, limited",
+ factDoes: "Does",
+ searchesAndReads: "Searches the web and reads pages",
+ searches: "Searches the web",
+ factFreeTier: "Free tier",
+ factFreeUse: "Free use",
+ factUsage: "Usage",
+ apiKey: "API key",
+ replaceKey: "Replace key",
+ removeKey: "Remove key",
+ savedKeyRefused: "{backend} refused the saved key. Paste a new one.",
+ savedKeyUnverified:
+ "A key is saved. {backend} has no key check, so the first search proves it.",
+ keySaved: "A key is saved.",
+ defaultSearchBackend: "Default search backend",
+ defaultChosen: "Your Agents search with {backend} when they name no backend.",
+ defaultFirstReady:
+ "Your Agents search with {backend} when they name no backend, because it is the first ready one in the default order.",
+ defaultOffer:
+ "Make {backend} the backend your Agents search with when they name none.",
+ defaultNeedsKey: "Add a key to make {backend} the default.",
+ clearDefault: "Clear default",
+ makeDefault: "Make default",
+ usageAfterFirstSearch: "Usage shows after the first search",
+ usageUnavailable: "Usage unavailable right now",
+ // {amount} is a number or "remaining / limit", such as "40 / 1,000".
+ usageLeft: "{amount} left",
+ usageCreditsLeft: "{amount} credits left",
+ usageRequestsLeft: "{amount} requests left",
+ // {when} is relative, such as "2 hours ago".
+ usageAsOf: "{left}, as of the last search {when}",
+
// An Agent's connector access
agentAccounts: "Accounts this Agent can use",
noConnectedAccounts: "No connected accounts yet.",
diff --git a/apps/web/src/features/apps/web-search-connectors.tsx b/apps/web/src/features/apps/web-search-connectors.tsx
index e019c522..dda7b9cf 100644
--- a/apps/web/src/features/apps/web-search-connectors.tsx
+++ b/apps/web/src/features/apps/web-search-connectors.tsx
@@ -24,11 +24,15 @@ import {
import { WebSearchKeyForm } from "@/features/web-search/web-search-key-form";
import { WebSearchKeysUnavailable } from "@/features/web-search/web-search-keys-unavailable";
import { webSearchBackendLogo } from "@/features/web-search/web-search-logos";
+import { commonMessages } from "@/i18n/common.messages";
+import { formatLocale, type Translation } from "@/i18n/language";
+import { useT, useTranslation } from "@/i18n/use-translation";
import { formatUpdatedAt } from "@/lib/date-format";
import { cn } from "@/lib/cn";
import { WEB_SEARCH_FILTER } from "./app-groups";
import { AppLogo } from "./app-logo";
+import { connectorMessages as m } from "./connectors.messages";
/**
* The web search backends as Connectors cards. They need no Composio key:
@@ -47,12 +51,13 @@ export function WebSearchSection({
heading: boolean;
list: UseQueryResult<TeamHubWebSearchBackendList>;
}) {
+ const t = useT();
const [openID, setOpenID] = useState<string | null>(null);
const opened = backends.find((backend) => backend.id === openID);
const headingId = "connector-group-web-search";
return (
<section
- aria-label={heading ? undefined : WEB_SEARCH_FILTER.label}
+ aria-label={heading ? undefined : t(WEB_SEARCH_FILTER.label)}
aria-labelledby={heading ? headingId : undefined}
className={className}
>
@@ -61,18 +66,18 @@ export function WebSearchSection({
className="mb-2.5 text-[14px] font-medium text-muted-foreground"
id={headingId}
>
- {WEB_SEARCH_FILTER.label}
+ {t(WEB_SEARCH_FILTER.label)}
</h2>
) : null}
{list.isPending ? (
<p className="py-3 text-sm text-muted-foreground" role="status">
- Loading web search...
+ {t(m.loadingWebSearch)}
</p>
) : list.error ? (
<div className="flex items-center gap-3 py-3" role="alert">
<p className="text-sm text-app-danger">{list.error.message}</p>
<Button onClick={() => void list.refetch()} size="compact">
- Retry
+ {t(commonMessages.retry)}
</Button>
</div>
) : (
@@ -112,7 +117,9 @@ function WebSearchBackendCard({
isDefault: boolean;
onOpen: () => void;
}) {
- const state = connectionState(backend);
+ const translation = useTranslation();
+ const { t } = translation;
+ const state = connectionState(backend, translation);
const line = state?.label ?? backend.description;
const canConnect =
isWebSearchKeyBackend(backend) &&
@@ -133,7 +140,7 @@ function WebSearchBackendCard({
</span>
{isDefault ? (
<span className="shrink-0 text-xs text-muted-foreground">
- Default
+ {t(m.defaultBackend)}
</span>
) : null}
</span>
@@ -157,13 +164,13 @@ function WebSearchBackendCard({
</button>
{canConnect ? (
<Button
- aria-label={`Connect ${backend.name}`}
+ aria-label={t(m.connectApp, { app: backend.name })}
className="px-2.5"
onClick={onOpen}
size="compact"
tone="secondary"
>
- Connect
+ {t(m.connect)}
</Button>
) : null}
</article>
@@ -179,7 +186,9 @@ function WebSearchBackendDialog({
list: TeamHubWebSearchBackendList;
onClose: () => void;
}) {
- const usage = usageLine(backend);
+ const translation = useTranslation();
+ const { t } = translation;
+ const usage = usageLine(backend, translation);
return (
<ModalDialog
className="app-key-dialog"
@@ -191,18 +200,18 @@ function WebSearchBackendDialog({
>
<div className="space-y-5 px-5 py-5 text-sm text-app-body">
<dl className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5">
- <Fact label="Does">
+ <Fact label={t(m.factDoes)}>
{backend.commands.includes("open")
- ? "Searches the web and reads pages"
- : "Searches the web"}
+ ? t(m.searchesAndReads)
+ : t(m.searches)}
</Fact>
{backend.free_tier ? (
- <Fact label="Free tier">{backend.free_tier}</Fact>
+ <Fact label={t(m.factFreeTier)}>{backend.free_tier}</Fact>
) : null}
{backend.tier_text ? (
- <Fact label="Free use">{backend.tier_text}</Fact>
+ <Fact label={t(m.factFreeUse)}>{backend.tier_text}</Fact>
) : null}
- {usage ? <Fact label="Usage">{usage}</Fact> : null}
+ {usage ? <Fact label={t(m.factUsage)}>{usage}</Fact> : null}
</dl>
{isWebSearchKeyBackend(backend) ? (
<KeySection backend={backend} canSave={list.can_save_keys} />
@@ -220,6 +229,7 @@ function KeySection({
backend: TeamHubWebSearchBackend & { id: TeamHubWebSearchKeyBackend };
canSave: boolean;
}) {
+ const t = useT();
const { client } = useTeamHubRuntime();
const queryClient = useQueryClient();
const saved = backend.key_state !== "none";
@@ -234,12 +244,12 @@ function KeySection({
queryClient.invalidateQueries({ queryKey: webSearchQueryKey }),
});
return (
- <section aria-label="API key" className="space-y-3">
- {saved ? <p>{savedKeyText(backend)}</p> : null}
+ <section aria-label={t(m.apiKey)} className="space-y-3">
+ {saved ? <p>{savedKeyText(backend, t)}</p> : null}
{canSave ? (
<WebSearchKeyForm
backend={backend}
- submitLabel={saved ? "Replace key" : "Save key"}
+ submitLabel={saved ? t(m.replaceKey) : t(m.saveKey)}
/>
) : (
<WebSearchKeysUnavailable />
@@ -247,11 +257,12 @@ function KeySection({
{saved ? (
<div className="space-y-1.5">
<Button
+ data-voice-risk="never"
loading={remove.isPending}
onClick={() => remove.mutate()}
tone="danger"
>
- Remove key
+ {t(m.removeKey)}
</Button>
{remove.error ? (
<p className="text-xs text-app-danger" role="alert">
@@ -271,6 +282,7 @@ function DefaultSection({
backend: ShownWebSearchBackend;
list: TeamHubWebSearchBackendList;
}) {
+ const t = useT();
const { client } = useTeamHubRuntime();
const queryClient = useQueryClient();
const chosen = list.chosen_default_search === backend.id;
@@ -286,15 +298,18 @@ function DefaultSection({
onSuccess: () =>
queryClient.invalidateQueries({ queryKey: webSearchQueryKey }),
});
- const text = chosen
- ? `Your Agents search with ${backend.name} when they name no backend.`
- : list.default_search === backend.id
- ? `Your Agents search with ${backend.name} when they name no backend, because it is the first ready one in the default order.`
- : backend.status === "ready"
- ? `Make ${backend.name} the backend your Agents search with when they name none.`
- : `Add a key to make ${backend.name} the default.`;
+ const text = t(
+ chosen
+ ? m.defaultChosen
+ : list.default_search === backend.id
+ ? m.defaultFirstReady
+ : backend.status === "ready"
+ ? m.defaultOffer
+ : m.defaultNeedsKey,
+ { backend: backend.name },
+ );
return (
- <section aria-label="Default search backend" className="space-y-2">
+ <section aria-label={t(m.defaultSearchBackend)} className="space-y-2">
<p className="text-muted-foreground">{text}</p>
{chosen ? (
<Button
@@ -302,7 +317,7 @@ function DefaultSection({
onClick={() => change.mutate(false)}
tone="secondary"
>
- Clear default
+ {t(m.clearDefault)}
</Button>
) : backend.status === "ready" ? (
<Button
@@ -310,7 +325,7 @@ function DefaultSection({
onClick={() => change.mutate(true)}
tone="secondary"
>
- Make default
+ {t(m.makeDefault)}
</Button>
) : null}
{change.error ? (
@@ -356,67 +371,75 @@ function BackendLogoTile({ backend }: { backend: TeamHubWebSearchBackend }) {
*/
function connectionState(
backend: TeamHubWebSearchBackend,
+ translation: Translation,
): { label: string; tone: "danger" | "success" } | null {
+ const { t } = translation;
if (backend.key_state === "rejected" || backend.status === "key_rejected")
- return { label: "Key rejected", tone: "danger" };
+ return { label: t(m.searchKeyRejected), tone: "danger" };
if (backend.key_state !== "none") {
- const usage = usageLine(backend);
+ const usage = usageLine(backend, translation);
return {
- label: usage ? `Connected · ${usage}` : "Connected",
+ label: usage ? t(m.connectedWithUsage, { usage }) : t(m.connected),
tone: "success",
};
}
if (backend.tier === "free")
- return { label: "Free, limited", tone: "success" };
+ return { label: t(m.freeLimited), tone: "success" };
return null;
}
-function savedKeyText(backend: TeamHubWebSearchBackend): string {
+function savedKeyText(
+ backend: TeamHubWebSearchBackend,
+ t: Translation["t"],
+): string {
if (backend.key_state === "rejected")
- return `${backend.name} refused the saved key. Paste a new one.`;
+ return t(m.savedKeyRefused, { backend: backend.name });
if (backend.key_state === "unverified")
- return `A key is saved. ${backend.name} has no key check, so the first search proves it.`;
- return "A key is saved.";
+ return t(m.savedKeyUnverified, { backend: backend.name });
+ return t(m.keySaved);
}
-const numberFormat = new Intl.NumberFormat("en-US");
-const dollarFormat = new Intl.NumberFormat("en-US", {
- currency: "USD",
- style: "currency",
-});
-
/**
* What is left on the account, from the live quota; null when the provider
- * reported no numbers worth a line.
+ * reported no numbers worth a line. Amounts are in USD whatever the language.
*/
-function usageLine(backend: TeamHubWebSearchBackend): string | null {
+function usageLine(
+ backend: TeamHubWebSearchBackend,
+ translation: Translation,
+): string | null {
+ const { t } = translation;
const quota = backend.quota;
if (!quota) return null;
if (quota.from === "unavailable") {
switch (quota.reason) {
case "not_observed":
- return "Usage shows after the first search";
+ return t(m.usageAfterFirstSearch);
case "provider_unavailable":
- return "Usage unavailable right now";
+ return t(m.usageUnavailable);
default:
return null;
}
}
if (quota.remaining === undefined) return null;
- const amount = (value: number) =>
- quota.unit === "usd"
- ? dollarFormat.format(value)
- : numberFormat.format(value);
- const unit =
+ const format = new Intl.NumberFormat(
+ formatLocale(translation.language),
+ quota.unit === "usd" ? { currency: "USD", style: "currency" } : {},
+ );
+ const amount = `${format.format(quota.remaining)}${
+ quota.limit === undefined ? "" : ` / ${format.format(quota.limit)}`
+ }`;
+ const left = t(
quota.unit === "credits"
- ? " credits"
+ ? m.usageCreditsLeft
: quota.unit === "requests"
- ? " requests"
- : "";
- const left = `${amount(quota.remaining)}${
- quota.limit === undefined ? "" : ` / ${amount(quota.limit)}`
- }${unit} left`;
+ ? m.usageRequestsLeft
+ : m.usageLeft,
+ { amount },
+ );
return quota.from === "last_response" && quota.observed_at
- ? `${left}, as of the last search ${formatUpdatedAt(quota.observed_at)}`
+ ? t(m.usageAsOf, {
+ left,
+ when: formatUpdatedAt(quota.observed_at, undefined, translation),
+ })
: left;
}
diff --git a/apps/web/src/features/rooms/cards/cards.messages.ts b/apps/web/src/features/rooms/cards/cards.messages.ts
index 0b525c91..5d4e377b 100644
--- a/apps/web/src/features/rooms/cards/cards.messages.ts
+++ b/apps/web/src/features/rooms/cards/cards.messages.ts
@@ -205,6 +205,24 @@ export const cardsMessages = defineMessages("cards", {
noKeyAdded: "No key added",
notCompleted: "Not completed",
+ // A web search API key request. Backend names and descriptions come from
+ // TeamHub. Requested: the Agent named the backend; Suggested: TeamHub
+ // picked it.
+ labelSearchKey: "Web search key requested",
+ requested: "Requested",
+ suggested: "Suggested",
+ searchKeyNoLongerAccepted:
+ "{backend} no longer accepts the saved key. Paste a new one.",
+ freeSearchesUsedUp:
+ "The free {backend} searches are used up. Add a key to keep searching.",
+ otherProviders: "Other providers",
+ otherProvidersCount: "Other providers ({count})",
+ hideOtherProviders: "Hide other providers",
+ freeLimited: "Free, limited",
+ searchKeyAdded: "{backend} key added. Your Agent is continuing.",
+ searchKeyAddedInstead:
+ "{backend} key added instead of {requested}. Your Agent continues with {backend}.",
+
// A browser connection.
labelBrowserConnection: "Browser connection requested",
everydayChrome: "Everyday Chrome",
diff --git a/apps/web/src/features/rooms/cards/decision-search-key-view.tsx b/apps/web/src/features/rooms/cards/decision-search-key-view.tsx
index 7a23c6fb..c5fd4168 100644
--- a/apps/web/src/features/rooms/cards/decision-search-key-view.tsx
+++ b/apps/web/src/features/rooms/cards/decision-search-key-view.tsx
@@ -27,6 +27,8 @@ import {
} from "@/features/web-search/web-search-key-form";
import { WebSearchKeysUnavailable } from "@/features/web-search/web-search-keys-unavailable";
import { webSearchBackendLogo } from "@/features/web-search/web-search-logos";
+import type { Translate } from "@/i18n/language";
+import { useT } from "@/i18n/use-translation";
import { cn } from "@/lib/cn";
import {
@@ -36,11 +38,10 @@ import {
CardRowDetails,
} from "./approval-card-parts";
import { CardBox, CardDone, type ReceiptTone } from "./card-shell";
+import { cardsMessages as m } from "./cards.messages";
import type { DecisionMessageCard } from "./decision-card";
import type { RoomCardDecision } from "./room-message-card-contract";
-const label = "Web search key requested";
-
type KeyBackend = TeamHubWebSearchBackend & { id: TeamHubWebSearchKeyBackend };
/**
@@ -62,6 +63,7 @@ export function SearchKeyDecision({
messageId: string;
onDecision: (decision: RoomCardDecision) => Promise<void> | void;
}) {
+ const t = useT();
const { client } = useTeamHubRuntime();
const list = useQuery(webSearchBackendInfoQueryOptions(client));
const [othersOpen, setOthersOpen] = useState(false);
@@ -92,20 +94,16 @@ export function SearchKeyDecision({
requestId: card.decision_id,
});
} catch (cause) {
- setError(
- cause instanceof Error
- ? cause.message
- : "The card could not be updated.",
- );
+ setError(cause instanceof Error ? cause.message : t(m.cardUpdateFailed));
} finally {
setBusy(false);
}
}
- const result = pending ? null : keyResult(card, view.backend);
+ const result = pending ? null : keyResult(card, view.backend, t);
const canSave = list.data?.can_save_keys !== false;
return (
- <CardBox heading={card.title} label={label}>
+ <CardBox heading={card.title} label={t(m.labelSearchKey)}>
<CardRow
detail={shown?.description}
icon={
@@ -116,9 +114,9 @@ export function SearchKeyDecision({
{target.name}{" "}
{pending ? (
view.origin === "requested" ? (
- <StatusPill tone="info">Requested</StatusPill>
+ <StatusPill tone="info">{t(m.requested)}</StatusPill>
) : (
- <StatusPill>Suggested</StatusPill>
+ <StatusPill>{t(m.suggested)}</StatusPill>
)
) : null}
</>
@@ -130,9 +128,12 @@ export function SearchKeyDecision({
<>
{view.reason === "missing" ? null : (
<p className="px-2 pb-2 text-xs text-app-muted">
- {view.reason === "rejected"
- ? `${target.name} no longer accepts the saved key. Paste a new one.`
- : `The free ${target.name} searches are used up. Add a key to keep searching.`}
+ {t(
+ view.reason === "rejected"
+ ? m.searchKeyNoLongerAccepted
+ : m.freeSearchesUsedUp,
+ { backend: target.name },
+ )}
</p>
)}
{canSave ? (
@@ -164,7 +165,7 @@ export function SearchKeyDecision({
size="large"
tone="subtle"
>
- Not now
+ {t(m.notNow)}
</Button>
</CardActions>
</>
@@ -186,6 +187,7 @@ function OtherProviders({
onToggle: () => void;
open: boolean;
}) {
+ const t = useT();
return (
<>
<button
@@ -194,7 +196,9 @@ function OtherProviders({
onClick={onToggle}
type="button"
>
- {open ? "Hide other providers" : `Other providers (${backends.length})`}
+ {open
+ ? t(m.hideOtherProviders)
+ : t(m.otherProvidersCount, { count: backends.length })}
<Icon
className={cn(
"shrink-0 text-app-muted transition-transform duration-(--chat-resize-duration) ease-(--app-out-quint) motion-reduce:transition-none",
@@ -206,7 +210,7 @@ function OtherProviders({
</button>
<CardRowDetails open={open}>
<ul
- aria-label="Other providers"
+ aria-label={t(m.otherProviders)}
className="max-h-62 divide-y divide-app-border overflow-y-auto overscroll-contain border-t border-app-border px-2"
>
{backends.map((backend) => (
@@ -221,7 +225,7 @@ function OtherProviders({
<p className="flex min-w-0 items-center gap-1.5 text-sm text-app-ink">
<span className="truncate">{backend.name}</span>
{backend.tier === "free" ? (
- <StatusPill tone="success">Free, limited</StatusPill>
+ <StatusPill tone="success">{t(m.freeLimited)}</StatusPill>
) : null}
</p>
<p className="truncate text-xs text-app-muted">
@@ -249,20 +253,24 @@ function OtherProviders({
function keyResult(
card: DecisionMessageCard,
shown: TeamHubWebSearchKeyBackend,
+ t: Translate,
): { icon: IconSvgElement; text: string; tone: ReceiptTone } {
if (card.answer?.decision === "configured") {
const saved = card.answer.backend ?? shown;
- const name = webSearchBackendName(saved);
+ const backend = webSearchBackendName(saved);
return {
icon: Tick02Icon,
text:
saved === shown
- ? `${name} key added. Your Agent is continuing.`
- : `${name} key added instead of ${webSearchBackendName(shown)}. Your Agent continues with ${name}.`,
+ ? t(m.searchKeyAdded, { backend })
+ : t(m.searchKeyAddedInstead, {
+ backend,
+ requested: webSearchBackendName(shown),
+ }),
tone: "success",
};
}
if (card.status === "denied")
- return { icon: Cancel01Icon, text: "No key added", tone: "muted" };
- return { icon: AlertCircleIcon, text: "Not completed", tone: "danger" };
+ return { icon: Cancel01Icon, text: t(m.noKeyAdded), tone: "muted" };
+ return { icon: AlertCircleIcon, text: t(m.notCompleted), tone: "danger" };
}
diff --git a/apps/web/src/features/rooms/chat/voice-mode/voice-risk-markers.test.ts b/apps/web/src/features/rooms/chat/voice-mode/voice-risk-markers.test.ts
index beafcf28..98e28d76 100644
--- a/apps/web/src/features/rooms/chat/voice-mode/voice-risk-markers.test.ts
+++ b/apps/web/src/features/rooms/chat/voice-mode/voice-risk-markers.test.ts
@@ -47,6 +47,10 @@ const notActions: Record<string, string> = {
"describes the button that starts Voice Mode, which sends nothing itself",
"/src/features/local-computer/remove-computer-agent-row.tsx: computers.deleteAgentInstead":
"chooses what removing the computer does; the marked Remove button does it",
+ "/src/features/apps/web-search-connectors.tsx: connectors.searchKeyRejected":
+ "the status line of a backend card, which is not a control",
+ "/src/features/rooms/cards/decision-search-key-view.tsx: cards.hideOtherProviders":
+ "folds the other providers' key fields in place; it closes nothing",
};
type Need = "confirm" | "never" | "close";
diff --git a/apps/web/src/features/web-search/web-search-key-form.tsx b/apps/web/src/features/web-search/web-search-key-form.tsx
index 4086e7eb..f7f0f86f 100644
--- a/apps/web/src/features/web-search/web-search-key-form.tsx
+++ b/apps/web/src/features/web-search/web-search-key-form.tsx
@@ -7,9 +7,12 @@ import { teamHubData } from "@/features/teamhub/teamhub-api";
import { TeamHubError } from "@/features/teamhub/teamhub-error";
import { useTeamHubRuntime } from "@/features/teamhub/teamhub-runtime";
import type { TeamHubWebSearchKeyBackend } from "@/features/teamhub/teamhub-types";
+import type { Translate } from "@/i18n/language";
+import { RichMessage, useT } from "@/i18n/use-translation";
import { cn } from "@/lib/cn";
import { webSearchKeySite, webSearchQueryKey } from "./web-search-backends";
+import { webSearchMessages as m } from "./web-search.messages";
export interface WebSearchKeyTarget {
id: TeamHubWebSearchKeyBackend;
@@ -28,7 +31,7 @@ export function WebSearchKeyForm({
compact = false,
decisionId,
onSaved,
- submitLabel = "Save key",
+ submitLabel,
tone = "primary",
}: {
backend: WebSearchKeyTarget;
@@ -39,6 +42,7 @@ export function WebSearchKeyForm({
submitLabel?: string;
tone?: "primary" | "secondary";
}) {
+ const t = useT();
const { client } = useTeamHubRuntime();
const queryClient = useQueryClient();
const [apiKey, setApiKey] = useState("");
@@ -59,9 +63,9 @@ export function WebSearchKeyForm({
onSaved?.();
},
});
- const label = `${backend.name} API key`;
+ const label = t(m.apiKey, { backend: backend.name });
const error = mutation.error
- ? describeKeyError(mutation.error, backend)
+ ? describeKeyError(mutation.error, backend, t)
: null;
const hasHint = !compact || Boolean(backend.key_url);
const hintId = `${inputId}-hint`;
@@ -104,7 +108,9 @@ export function WebSearchKeyForm({
tone={tone}
type="submit"
>
- {mutation.isPending ? "Checking key..." : submitLabel}
+ {mutation.isPending
+ ? t(m.checkingKey)
+ : (submitLabel ?? t(m.saveKey))}
</Button>
</div>
{error ? (
@@ -119,31 +125,42 @@ export function WebSearchKeyForm({
{hasHint ? (
<p className="text-xs text-app-muted" id={hintId}>
{backend.key_url ? (
- <>
- Get a key at{" "}
- <a
- className="text-app-link hover:underline"
- href={backend.key_url}
- rel="noopener noreferrer"
- target="_blank"
- >
- {webSearchKeySite(backend.key_url)}{" "}
- <span aria-hidden="true">↗</span>
- </a>
- {compact ? null : ". "}
- </>
- ) : null}
- {compact ? null : "Stored encrypted and never shown again."}
+ <RichMessage
+ message={compact ? m.getKeyAt : m.getKeyAtStored}
+ tags={{
+ link: (site) => (
+ <a
+ className="text-app-link hover:underline"
+ href={backend.key_url}
+ rel="noopener noreferrer"
+ target="_blank"
+ >
+ {site} <span aria-hidden="true">↗</span>
+ </a>
+ ),
+ }}
+ values={{ site: webSearchKeySite(backend.key_url) }}
+ />
+ ) : compact ? null : (
+ t(m.storedEncrypted)
+ )}
</p>
) : null}
</form>
);
}
-function describeKeyError(error: Error, backend: WebSearchKeyTarget): string {
+function describeKeyError(
+ error: Error,
+ backend: WebSearchKeyTarget,
+ t: Translate,
+): string {
if (error instanceof TeamHubError && error.code === "WEB_SEARCH_KEY_REJECTED")
return backend.key_url
- ? `${backend.name} rejected this key. Check it at ${webSearchKeySite(backend.key_url)} and paste it again.`
- : `${backend.name} rejected this key. Check it and paste it again.`;
+ ? t(m.keyRejectedAt, {
+ backend: backend.name,
+ site: webSearchKeySite(backend.key_url),
+ })
+ : t(m.keyRejected, { backend: backend.name });
return error.message;
}
diff --git a/apps/web/src/features/web-search/web-search-keys-unavailable.tsx b/apps/web/src/features/web-search/web-search-keys-unavailable.tsx
index 9132a303..85da9a80 100644
--- a/apps/web/src/features/web-search/web-search-keys-unavailable.tsx
+++ b/apps/web/src/features/web-search/web-search-keys-unavailable.tsx
@@ -1,10 +1,16 @@
+import { RichMessage } from "@/i18n/use-translation";
+
+import { webSearchMessages as m } from "./web-search.messages";
+
+const CODE_TAGS = {
+ code: (text: string) => <code className="font-mono">{text}</code>,
+};
+
/** Why no key field shows: the server has nothing to seal keys with. */
export function WebSearchKeysUnavailable() {
return (
<p className="text-app-muted">
- This server cannot store web search keys. Set{" "}
- <code className="font-mono">TEAMHUB_SECRET_ENCRYPTION_KEY</code> where it
- runs, then add the key here.
+ <RichMessage message={m.keysUnavailable} tags={CODE_TAGS} />
</p>
);
}
diff --git a/apps/web/src/features/web-search/web-search-language.test.tsx b/apps/web/src/features/web-search/web-search-language.test.tsx
new file mode 100644
index 00000000..8b842354
--- /dev/null
+++ b/apps/web/src/features/web-search/web-search-language.test.tsx
@@ -0,0 +1,158 @@
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { fireEvent, render, screen, within } from "@testing-library/react";
+import type { ReactNode } from "react";
+import { MemoryRouter } from "react-router";
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+import { ConnectedAppsPage } from "@/features/apps/connected-apps-page";
+import { DecisionCard } from "@/features/rooms/cards/decision-card";
+import { TeamHubRuntimeProvider } from "@/features/teamhub/teamhub-runtime";
+import { resetLanguageForTest, setLanguage } from "@/i18n/language";
+import zhCN from "@/i18n/locales/zh-CN.json";
+import {
+ createTestTeamHubRuntime,
+ type TestTeamHubRuntime,
+} from "@/test/teamhub-test-runtime";
+
+const connectors = zhCN.connectors;
+const cards = zhCN.cards;
+const keyField = zhCN.webSearch;
+
+function renderWith(runtime: TestTeamHubRuntime, children: ReactNode) {
+ render(
+ <MemoryRouter initialEntries={["/apps"]}>
+ <QueryClientProvider
+ client={
+ new QueryClient({ defaultOptions: { queries: { retry: false } } })
+ }
+ >
+ <TeamHubRuntimeProvider runtime={runtime}>
+ {children}
+ </TeamHubRuntimeProvider>
+ </QueryClientProvider>
+ </MemoryRouter>,
+ );
+}
+
+describe("web search in the language on screen", () => {
+ afterEach(() => {
+ resetLanguageForTest();
+ });
+
+ it("words the Connectors backends in Chinese and keeps their names", async () => {
+ await setLanguage("zh-CN");
+ const runtime = createTestTeamHubRuntime();
+ runtime.seed.webSearch = {
+ ...runtime.seed.webSearch,
+ backends: runtime.seed.webSearch.backends.map((backend) =>
+ backend.id === "tavily"
+ ? {
+ ...backend,
+ key_state: "verified",
+ quota: {
+ from: "provider",
+ limit: 1000,
+ remaining: 812,
+ unit: "credits",
+ },
+ status: "ready",
+ }
+ : backend,
+ ),
+ };
+ renderWith(runtime, <ConnectedAppsPage />);
+
+ const section = await screen.findByRole("region", {
+ name: connectors.filterWebSearch,
+ });
+ expect(
+ within(screen.getByRole("tablist")).getByRole("tab", {
+ name: connectors.filterWebSearch,
+ }),
+ ).toBeVisible();
+ const tavily = within(section)
+ .getByRole("button", { name: "Tavily" })
+ .closest("article")!;
+ expect(tavily).toHaveTextContent(
+ connectors.connectedWithUsage.replace(
+ "{usage}",
+ connectors.usageCreditsLeft.replace("{amount}", "812 / 1,000"),
+ ),
+ );
+ expect(
+ within(section).getByRole("button", {
+ name: connectors.connectApp.replace("{app}", "Exa"),
+ }),
+ ).toBeVisible();
+
+ fireEvent.click(within(section).getByRole("button", { name: "Tavily" }));
+ const dialog = await screen.findByRole("dialog", { name: "Tavily" });
+ expect(dialog).toHaveTextContent(connectors.factDoes);
+ expect(dialog).toHaveTextContent(connectors.keySaved);
+ expect(
+ within(dialog).getByLabelText(
+ keyField.apiKey.replace("{backend}", "Tavily"),
+ ),
+ ).toBeVisible();
+ expect(
+ within(dialog).getByRole("button", { name: connectors.replaceKey }),
+ ).toBeVisible();
+ // Removing a key cannot be undone, so Voice Mode never clicks it.
+ expect(
+ within(dialog).getByRole("button", { name: connectors.removeKey }),
+ ).toHaveAttribute("data-voice-risk", "never");
+ expect(dialog).toHaveTextContent(keyField.storedEncrypted);
+ });
+
+ it("words the chat's search key card in Chinese", async () => {
+ await setLanguage("zh-CN");
+ const runtime = createTestTeamHubRuntime();
+ renderWith(
+ runtime,
+ <DecisionCard
+ card={{
+ card_type: "personal_notice",
+ intent: "decision_requested",
+ version: 1,
+ decision_id: "search-1",
+ kind: "search_key",
+ status: "pending",
+ title: "Add a Tavily API key so I can search the web.",
+ search_key: {
+ backend: "tavily",
+ origin: "requested",
+ reason: "rejected",
+ },
+ decision_owner: { id: "alice", display_name: "Alice", kind: "human" },
+ requester: { id: "writer", display_name: "Writer", kind: "agent" },
+ }}
+ currentActorId="alice"
+ messageId="message-1"
+ onDecision={vi.fn()}
+ roomId="room-1"
+ tenantId="tenant_one"
+ />,
+ );
+
+ const box = await screen.findByRole("region", {
+ name: cards.labelSearchKey,
+ });
+ expect(box).toHaveTextContent(cards.requested);
+ expect(box).toHaveTextContent(
+ cards.searchKeyNoLongerAccepted.replace("{backend}", "Tavily"),
+ );
+ expect(
+ within(box).getByRole("button", { name: cards.notNow }),
+ ).toBeVisible();
+ const others = await within(box).findByRole("button", {
+ name: (name) => name.startsWith(cards.otherProviders),
+ });
+ fireEvent.click(others);
+ expect(
+ within(box).getByRole("button", { name: cards.hideOtherProviders }),
+ ).toBeVisible();
+ expect(
+ within(box).getByRole("list", { name: cards.otherProviders }),
+ ).toBeInTheDocument();
+ });
+});
diff --git a/apps/web/src/features/web-search/web-search.messages.ts b/apps/web/src/features/web-search/web-search.messages.ts
new file mode 100644
index 00000000..5c175d3d
--- /dev/null
+++ b/apps/web/src/features/web-search/web-search.messages.ts
@@ -0,0 +1,22 @@
+import { defineMessages } from "@/i18n/messages";
+
+/**
+ * The web search key field, shared by Connectors and the chat's search key
+ * card. Backend names and descriptions TeamHub sends are data and are shown
+ * as they arrive.
+ */
+export const webSearchMessages = defineMessages("webSearch", {
+ apiKey: "{backend} API key",
+ checkingKey: "Checking key...",
+ saveKey: "Save key",
+ // {site} is the key page as host and path, such as tavily.com/keys.
+ getKeyAt: "Get a key at <link>{site}</link>",
+ getKeyAtStored:
+ "Get a key at <link>{site}</link>. Stored encrypted and never shown again.",
+ storedEncrypted: "Stored encrypted and never shown again.",
+ keyRejectedAt:
+ "{backend} rejected this key. Check it at {site} and paste it again.",
+ keyRejected: "{backend} rejected this key. Check it and paste it again.",
+ keysUnavailable:
+ "This server cannot store web search keys. Set <code>TEAMHUB_SECRET_ENCRYPTION_KEY</code> where it runs, then add the key here.",
+});
diff --git a/apps/web/src/i18n/locales/zh-CN.glossary.md b/apps/web/src/i18n/locales/zh-CN.glossary.md
index 4e7de95b..191d47df 100644
--- a/apps/web/src/i18n/locales/zh-CN.glossary.md
+++ b/apps/web/src/i18n/locales/zh-CN.glossary.md
@@ -84,6 +84,8 @@ elsewhere.
| Topics (of a meeting) | 议题 | Wiki Topics are 主题. |
| Table of contents | 目录 | |
| Voice provider | 语音服务商 | Soniox or xAI; the names stay as they are. |
+| Web search | 网页搜索 | |
+| Search backend | 搜索服务 | Tavily or Exa; the names stay as they are. |
| Draft | 草稿 | |
| Local model | 本地模型 | |
| Subscription | 订阅 | A model source. |
diff --git a/apps/web/src/i18n/locales/zh-CN.json b/apps/web/src/i18n/locales/zh-CN.json
index d815ae4d..7ed6e5f4 100644
--- a/apps/web/src/i18n/locales/zh-CN.json
+++ b/apps/web/src/i18n/locales/zh-CN.json
@@ -703,6 +703,17 @@
"keyAdded": "已添加密钥",
"noKeyAdded": "未添加密钥",
"notCompleted": "未完成",
+ "labelSearchKey": "请求网页搜索密钥",
+ "requested": "指定",
+ "suggested": "推荐",
+ "searchKeyNoLongerAccepted": "{backend} 不再接受已保存的密钥。请粘贴新的密钥。",
+ "freeSearchesUsedUp": "{backend} 的免费搜索次数已用完。添加密钥即可继续搜索。",
+ "otherProviders": "其他服务商",
+ "otherProvidersCount": "其他服务商({count})",
+ "hideOtherProviders": "收起其他服务商",
+ "freeLimited": "免费,有限额",
+ "searchKeyAdded": "已添加 {backend} 密钥。你的 Agent 正在继续。",
+ "searchKeyAddedInstead": "已添加 {backend} 密钥(而非 {requested})。你的 Agent 将使用 {backend} 继续。",
"labelBrowserConnection": "请求连接浏览器",
"everydayChrome": "日常使用的 Chrome",
"continuesOnceConnected": "连接后,{agent} 会继续。",
@@ -1957,6 +1968,37 @@
"saveKey": "保存密钥",
"authorizationComplete": "授权完成",
"canCloseWindow": "你可以关闭这个窗口了。",
+ "filterWebSearch": "网页搜索",
+ "loadingWebSearch": "正在加载网页搜索…",
+ "defaultBackend": "默认",
+ "searchKeyRejected": "密钥被拒绝",
+ "connectedWithUsage": "已连接 · {usage}",
+ "freeLimited": "免费,有限额",
+ "factDoes": "用途",
+ "searchesAndReads": "搜索网页并读取页面",
+ "searches": "搜索网页",
+ "factFreeTier": "免费额度",
+ "factFreeUse": "免费使用",
+ "factUsage": "用量",
+ "apiKey": "API 密钥",
+ "replaceKey": "替换密钥",
+ "removeKey": "移除密钥",
+ "savedKeyRefused": "{backend} 拒绝了已保存的密钥。请粘贴新的密钥。",
+ "savedKeyUnverified": "已保存密钥。{backend} 不提供密钥检查,第一次搜索时才能确认它是否可用。",
+ "keySaved": "已保存密钥。",
+ "defaultSearchBackend": "默认搜索服务",
+ "defaultChosen": "你的 Agent 没有指定搜索服务时,会用 {backend} 搜索。",
+ "defaultFirstReady": "你的 Agent 没有指定搜索服务时,会用 {backend} 搜索,因为它是默认顺序中第一个可用的。",
+ "defaultOffer": "把 {backend} 设为你的 Agent 未指定搜索服务时使用的服务。",
+ "defaultNeedsKey": "添加密钥后,才能把 {backend} 设为默认。",
+ "clearDefault": "取消默认",
+ "makeDefault": "设为默认",
+ "usageAfterFirstSearch": "第一次搜索后显示用量",
+ "usageUnavailable": "暂时无法获取用量",
+ "usageLeft": "剩余 {amount}",
+ "usageCreditsLeft": "剩余 {amount} 点数",
+ "usageRequestsLeft": "剩余 {amount} 次请求",
+ "usageAsOf": "{left}(截至上次搜索,{when})",
"agentAccounts": "这个 Agent 可以使用的账号",
"noConnectedAccounts": "还没有已连接的账号。",
"connectAnotherApp": "连接其他应用",
@@ -1967,6 +2009,17 @@
"retryAccess": "重新加载访问权限",
"allowAgentAccess": "允许 Agent 访问 {account}"
},
+ "webSearch": {
+ "apiKey": "{backend} API 密钥",
+ "checkingKey": "正在检查密钥…",
+ "saveKey": "保存密钥",
+ "getKeyAt": "在 <link>{site}</link> 获取密钥",
+ "getKeyAtStored": "在 <link>{site}</link> 获取密钥。密钥会加密保存,之后不会再显示。",
+ "storedEncrypted": "密钥会加密保存,之后不会再显示。",
+ "keyRejectedAt": "{backend} 拒绝了这个密钥。请在 {site} 检查后重新粘贴。",
+ "keyRejected": "{backend} 拒绝了这个密钥。请检查后重新粘贴。",
+ "keysUnavailable": "这台服务器无法保存网页搜索密钥。请在它运行的环境中设置 <code>TEAMHUB_SECRET_ENCRYPTION_KEY</code>,然后在这里添加密钥。"
+ },
"urlPreview": {
"forward": "前进",
"reload": "重新加载",