fix(websearch): align provider validation metadata

This commit is contained in:
Tam Nhu Tran
2026-03-27 14:49:00 -04:00
parent 48da0f3538
commit dff40b5e24
2 changed files with 58 additions and 23 deletions
+6 -2
View File
@@ -9,6 +9,7 @@ import { getWebSearchReadiness, getWebSearchCliProviders } from '../../utils/web
import {
applyWebSearchApiKeyUpdates,
getWebSearchApiKeyStates,
WEBSEARCH_API_KEY_PROVIDERS,
type WebSearchApiKeyProviderId,
} from '../../utils/websearch/provider-secrets';
import { requireLocalAccessWhenAuthDisabled } from '../middleware/auth-middleware';
@@ -16,7 +17,6 @@ import { requireLocalAccessWhenAuthDisabled } from '../middleware/auth-middlewar
const router = Router();
const WEBSEARCH_LOCAL_ACCESS_ERROR =
'WebSearch endpoints require localhost access when dashboard auth is disabled.';
const WEBSEARCH_API_KEY_PROVIDER_IDS = ['exa', 'tavily', 'brave'] as const;
type WebSearchApiKeyUpdates = Partial<Record<WebSearchApiKeyProviderId, string | null>>;
@@ -24,6 +24,10 @@ interface WebSearchDashboardPayload extends Partial<WebSearchConfig> {
apiKeys?: WebSearchApiKeyUpdates;
}
function isWebSearchApiKeyProviderId(value: string): value is WebSearchApiKeyProviderId {
return Object.prototype.hasOwnProperty.call(WEBSEARCH_API_KEY_PROVIDERS, value);
}
router.use((req: Request, res: Response, next) => {
if (requireLocalAccessWhenAuthDisabled(req, res, WEBSEARCH_LOCAL_ACCESS_ERROR)) {
next();
@@ -88,7 +92,7 @@ router.put('/', (req: Request, res: Response): void => {
if (apiKeys) {
for (const [providerId, value] of Object.entries(apiKeys)) {
if (!WEBSEARCH_API_KEY_PROVIDER_IDS.includes(providerId as WebSearchApiKeyProviderId)) {
if (!isWebSearchApiKeyProviderId(providerId)) {
res.status(400).json({ error: `Unsupported WebSearch provider: ${providerId}` });
return;
}