mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-05 02:18:57 +00:00
fix(websearch): align provider validation metadata
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user