Skip to content

Commit 1cfbbb4

Browse files
committed
web search will be now managed by admin from dashboard api
1 parent b72f761 commit 1cfbbb4

4 files changed

Lines changed: 46 additions & 3 deletions

File tree

api/server/controllers/agents/request.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const { disposeClient, clientRegistry, requestDataMap } = require('~/server/clea
1313
const { handleAbortError } = require('~/server/middleware');
1414
const { logViolation } = require('~/cache');
1515
const { saveMessage } = require('~/models');
16-
const { syncChatToAyo, extractResponseText, loadAyoGuardrails } = require('~/server/services/ayoDashboard');
16+
const { syncChatToAyo, extractResponseText, loadAyoGuardrails, loadAyoGlobalConfig } = require('~/server/services/ayoDashboard');
1717

1818
function createCloseHandler(abortController) {
1919
return function (manual) {
@@ -158,6 +158,12 @@ const ResumableAgentController = async (req, res, next, initializeClient, addTit
158158
logger.warn('[ayoDashboard] loadAyoGuardrails failed', { status: err.status, message: err.message });
159159
}
160160

161+
try {
162+
req.ayoWebSearch = (await loadAyoGlobalConfig(req))?.webSearch ?? false;
163+
} catch (err) {
164+
logger.warn('[ayoDashboard] loadAyoGlobalConfig failed', { status: err.status, message: err.message });
165+
}
166+
161167
/** @type {{ client: TAgentClient; userMCPAuthMap?: Record<string, Record<string, string>> }} */
162168
const result = await initializeClient({
163169
req,
@@ -585,6 +591,12 @@ const _LegacyAgentController = async (req, res, next, initializeClient, addTitle
585591
logger.warn('[ayoDashboard] loadAyoGuardrails failed', { status: err.status, message: err.message });
586592
}
587593

594+
try {
595+
req.ayoWebSearch = (await loadAyoGlobalConfig(req))?.webSearch ?? false;
596+
} catch (err) {
597+
logger.warn('[ayoDashboard] loadAyoGlobalConfig failed', { status: err.status, message: err.message });
598+
}
599+
588600
/** @type {{ client: TAgentClient; userMCPAuthMap?: Record<string, Record<string, string>> }} */
589601
const result = await initializeClient({
590602
req,

api/server/services/ayoDashboard.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,33 @@ const loadAyoGuardrails = async (req, conversationId) => {
231231
return value;
232232
};
233233

234+
const getAyoGlobalConfig = async (token) => {
235+
const url = `${getBaseUrl()}/api/configurations/global-configurations/`;
236+
const res = await fetch(url, {
237+
method: 'GET',
238+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
239+
});
240+
if (!res.ok) {
241+
const body = await res.text().catch(() => '');
242+
const err = new Error(`getAyoGlobalConfig failed: ${res.status} ${body}`);
243+
err.status = res.status;
244+
throw err;
245+
}
246+
const data = await res.json();
247+
return { webSearch: data?.web_search === true };
248+
};
249+
250+
const loadAyoGlobalConfig = async (req) => {
251+
if (!getBaseUrl()) {
252+
return { webSearch: false };
253+
}
254+
const { accessToken, refreshToken } = getTokensFromReq(req);
255+
if (!accessToken) {
256+
return { webSearch: false };
257+
}
258+
return callWithRefresh(req, accessToken, refreshToken, (t) => getAyoGlobalConfig(t));
259+
};
260+
234261
const markConversationDeleted = async (token, conversationId) => {
235262
const url = `${getBaseUrl()}/api/chats/conversations/mark-deleted/`;
236263
const res = await fetch(url, {
@@ -439,4 +466,4 @@ const syncChatToAyo = async ({
439466
}
440467
};
441468

442-
module.exports = { syncChatToAyo, syncConversationDeleteToAyo, syncChatMetadataToAyo, updateConversationTitle, refreshAccessToken, isTokenExpired, getCurrentUserInfo, extractResponseText, loadAyoGuardrails };
469+
module.exports = { syncChatToAyo, syncConversationDeleteToAyo, syncChatMetadataToAyo, updateConversationTitle, refreshAccessToken, isTokenExpired, getCurrentUserInfo, extractResponseText, loadAyoGuardrails, loadAyoGlobalConfig };

packages/api/src/endpoints/custom/initialize.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ const { PROXY } = process.env;
2323
function buildCustomOptions(
2424
endpointConfig: Partial<TEndpoint>,
2525
ayoGuardrails: string[],
26+
ayoWebSearch: boolean,
2627
appConfig?: AppConfig,
2728
endpointTokenConfig?: Record<string, unknown>,
2829
) {
2930
const customOptions: Record<string, unknown> = {
3031
headers: endpointConfig.headers,
3132
addParams:
3233
endpointConfig.name === 'LiteLLM'
33-
? { ...(endpointConfig.addParams ?? {}), guardrails: ayoGuardrails }
34+
? { ...(endpointConfig.addParams ?? {}), guardrails: ayoGuardrails, web_search: ayoWebSearch }
3435
: endpointConfig.addParams,
3536
dropParams: endpointConfig.dropParams,
3637
customParams: endpointConfig.customParams,
@@ -164,9 +165,11 @@ export async function initializeCustom({
164165
}
165166

166167
const AYO_GUARDRAILS = req.ayoGuardrails ?? [];
168+
const AYO_WEB_SEARCH = req.ayoWebSearch ?? false;
167169
const customOptions = buildCustomOptions(
168170
endpointConfig,
169171
AYO_GUARDRAILS,
172+
AYO_WEB_SEARCH,
170173
appConfig,
171174
endpointTokenConfig,
172175
);

packages/api/src/types/http.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ export type ServerRequest = Request<unknown, unknown, RequestBody> & {
2222
user?: IUser;
2323
config?: AppConfig;
2424
ayoGuardrails?: string[];
25+
ayoWebSearch?: boolean;
2526
};

0 commit comments

Comments
 (0)