Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion api/server/controllers/agents/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { disposeClient, clientRegistry, requestDataMap } = require('~/server/clea
const { handleAbortError } = require('~/server/middleware');
const { logViolation } = require('~/cache');
const { saveMessage } = require('~/models');
const { syncChatToAyo, extractResponseText, loadAyoGuardrails } = require('~/server/services/ayoDashboard');
const { syncChatToAyo, extractResponseText, loadAyoGuardrails, loadAyoGlobalConfig } = require('~/server/services/ayoDashboard');

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

try {
req.ayoWebSearch = (await loadAyoGlobalConfig(req))?.webSearch ?? false;
} catch (err) {
logger.warn('[ayoDashboard] loadAyoGlobalConfig failed', { status: err.status, message: err.message });
}

/** @type {{ client: TAgentClient; userMCPAuthMap?: Record<string, Record<string, string>> }} */
const result = await initializeClient({
req,
Expand Down Expand Up @@ -585,6 +591,12 @@ const _LegacyAgentController = async (req, res, next, initializeClient, addTitle
logger.warn('[ayoDashboard] loadAyoGuardrails failed', { status: err.status, message: err.message });
}

try {
req.ayoWebSearch = (await loadAyoGlobalConfig(req))?.webSearch ?? false;
} catch (err) {
logger.warn('[ayoDashboard] loadAyoGlobalConfig failed', { status: err.status, message: err.message });
}

/** @type {{ client: TAgentClient; userMCPAuthMap?: Record<string, Record<string, string>> }} */
const result = await initializeClient({
req,
Expand Down
29 changes: 28 additions & 1 deletion api/server/services/ayoDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,33 @@ const loadAyoGuardrails = async (req, conversationId) => {
return value;
};

const getAyoGlobalConfig = async (token) => {
const url = `${getBaseUrl()}/api/configurations/global-configurations/`;
const res = await fetch(url, {
method: 'GET',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
});
if (!res.ok) {
const body = await res.text().catch(() => '');
const err = new Error(`getAyoGlobalConfig failed: ${res.status} ${body}`);
err.status = res.status;
throw err;
}
const data = await res.json();
return { webSearch: data?.web_search === true };
};

const loadAyoGlobalConfig = async (req) => {
if (!getBaseUrl()) {
return { webSearch: false };
}
const { accessToken, refreshToken } = getTokensFromReq(req);
if (!accessToken) {
return { webSearch: false };
}
return callWithRefresh(req, accessToken, refreshToken, (t) => getAyoGlobalConfig(t));
};

const markConversationDeleted = async (token, conversationId) => {
const url = `${getBaseUrl()}/api/chats/conversations/mark-deleted/`;
const res = await fetch(url, {
Expand Down Expand Up @@ -439,4 +466,4 @@ const syncChatToAyo = async ({
}
};

module.exports = { syncChatToAyo, syncConversationDeleteToAyo, syncChatMetadataToAyo, updateConversationTitle, refreshAccessToken, isTokenExpired, getCurrentUserInfo, extractResponseText, loadAyoGuardrails };
module.exports = { syncChatToAyo, syncConversationDeleteToAyo, syncChatMetadataToAyo, updateConversationTitle, refreshAccessToken, isTokenExpired, getCurrentUserInfo, extractResponseText, loadAyoGuardrails, loadAyoGlobalConfig };
5 changes: 4 additions & 1 deletion packages/api/src/endpoints/custom/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ const { PROXY } = process.env;
function buildCustomOptions(
endpointConfig: Partial<TEndpoint>,
ayoGuardrails: string[],
ayoWebSearch: boolean,
appConfig?: AppConfig,
endpointTokenConfig?: Record<string, unknown>,
) {
const customOptions: Record<string, unknown> = {
headers: endpointConfig.headers,
addParams:
endpointConfig.name === 'LiteLLM'
? { ...(endpointConfig.addParams ?? {}), guardrails: ayoGuardrails }
? { ...(endpointConfig.addParams ?? {}), guardrails: ayoGuardrails, web_search: ayoWebSearch }
: endpointConfig.addParams,
dropParams: endpointConfig.dropParams,
customParams: endpointConfig.customParams,
Expand Down Expand Up @@ -164,9 +165,11 @@ export async function initializeCustom({
}

const AYO_GUARDRAILS = req.ayoGuardrails ?? [];
const AYO_WEB_SEARCH = req.ayoWebSearch ?? false;
const customOptions = buildCustomOptions(
endpointConfig,
AYO_GUARDRAILS,
AYO_WEB_SEARCH,
appConfig,
endpointTokenConfig,
);
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/types/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export type ServerRequest = Request<unknown, unknown, RequestBody> & {
user?: IUser;
config?: AppConfig;
ayoGuardrails?: string[];
ayoWebSearch?: boolean;
};
Loading