This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-29 12:38:04 -05:00
1 parent c584a4270c
commit ae5d23f226
4 files changed
+44 -16

No files matched your search

+11
View File
@@ -509,6 +509,17 @@ export const getOAuthClientAuthorizationUrl = (clientId: string, type: null | st
return `${WEBUI_BASE_URL}/oauth/clients/${oauthClientId}/authorize`; return `${WEBUI_BASE_URL}/oauth/clients/${oauthClientId}/authorize`;
}; };
export const initiateOAuthRedirect = (tool: {
id: string;
serverId: string;
authType?: string | null;
}) => {
sessionStorage.setItem('pendingOAuthToolId', tool.id);
sessionStorage.setItem('oauthRedirectInProgressToolId', tool.id);
const authUrl = getOAuthClientAuthorizationUrl(tool.serverId, tool.authType ?? 'mcp');
window.open(authUrl, '_self', 'noopener');
};
export const getCodeExecutionConfig = async (token: string) => { export const getCodeExecutionConfig = async (token: string) => {
let error = null; let error = null;
+23
View File
@@ -97,6 +97,7 @@
import { uploadFile } from '$lib/apis/files'; import { uploadFile } from '$lib/apis/files';
import { createOpenAITextStream } from '$lib/apis/streaming'; import { createOpenAITextStream } from '$lib/apis/streaming';
import { getFunctions } from '$lib/apis/functions'; import { getFunctions } from '$lib/apis/functions';
import { initiateOAuthRedirect } from '$lib/apis/configs';
import { updateFolderById } from '$lib/apis/folders'; import { updateFolderById } from '$lib/apis/folders';
import Banner from '../common/Banner.svelte'; import Banner from '../common/Banner.svelte';
@@ -343,6 +344,27 @@
console.log('saveSessionSelectedModels', selectedModels, sessionStorage.selectedModels); console.log('saveSessionSelectedModels', selectedModels, sessionStorage.selectedModels);
}; };
const continueOAuthRedirect = async () => {
if (pendingOAuthTools.length === 0) {
sessionStorage.removeItem('oauthRedirectInProgressToolId');
return;
}
if (chatIdProp) {
return;
}
const nextTool = pendingOAuthTools[0];
if (sessionStorage.getItem('oauthRedirectInProgressToolId') === nextTool.id) {
sessionStorage.removeItem('oauthRedirectInProgressToolId');
return;
}
saveSessionSelectedModels();
await tick();
initiateOAuthRedirect(nextTool);
};
let oldSelectedModelIds = ['']; let oldSelectedModelIds = [''];
$: if (!equal(selectedModelIds, oldSelectedModelIds)) { $: if (!equal(selectedModelIds, oldSelectedModelIds)) {
onSelectedModelIdsChange(); onSelectedModelIdsChange();
@@ -423,6 +445,7 @@
} }
selectedToolIds = authed; selectedToolIds = authed;
pendingOAuthTools = unauthed; pendingOAuthTools = unauthed;
await continueOAuthRedirect();
} else if ($settings?.tools) { } else if ($settings?.tools) {
selectedToolIds = $settings.tools; selectedToolIds = $settings.tools;
} else { } else {
+2 -7
View File
@@ -62,7 +62,7 @@
import { getSessionUser } from '$lib/apis/auths'; import { getSessionUser } from '$lib/apis/auths';
import { WEBUI_BASE_URL, WEBUI_API_BASE_URL, PASTED_TEXT_CHARACTER_LIMIT } from '$lib/constants'; import { WEBUI_BASE_URL, WEBUI_API_BASE_URL, PASTED_TEXT_CHARACTER_LIMIT } from '$lib/constants';
import { getOAuthClientAuthorizationUrl } from '$lib/apis/configs'; import { initiateOAuthRedirect } from '$lib/apis/configs';
import { createNoteHandler } from '../notes/utils'; import { createNoteHandler } from '../notes/utils';
import { getSuggestionRenderer } from '../common/RichTextInput/suggestions'; import { getSuggestionRenderer } from '../common/RichTextInput/suggestions';
@@ -1986,12 +1986,7 @@
<Tooltip content={$i18n.t('Click to connect')} placement="top"> <Tooltip content={$i18n.t('Click to connect')} placement="top">
<button <button
on:click|preventDefault={() => { on:click|preventDefault={() => {
sessionStorage.setItem('pendingOAuthToolId', pendingTool.id); initiateOAuthRedirect(pendingTool);
const authUrl = getOAuthClientAuthorizationUrl(
pendingTool.serverId,
pendingTool.authType ?? 'mcp'
);
window.open(authUrl, '_self', 'noopener');
}} }}
type="button" type="button"
class="group px-2 py-[5px] flex gap-1.5 items-center text-xs rounded-full transition-colors duration-300 focus:outline-hidden max-w-full overflow-hidden class="group px-2 py-[5px] flex gap-1.5 items-center text-xs rounded-full transition-colors duration-300 focus:outline-hidden max-w-full overflow-hidden
@@ -13,7 +13,7 @@
terminalServers terminalServers
} from '$lib/stores'; } from '$lib/stores';
import { getOAuthClientAuthorizationUrl } from '$lib/apis/configs'; import { initiateOAuthRedirect } from '$lib/apis/configs';
import { deleteOAuthSession } from '$lib/apis/auths'; import { deleteOAuthSession } from '$lib/apis/auths';
import { getTools } from '$lib/apis/tools'; import { getTools } from '$lib/apis/tools';
import { getSkills } from '$lib/apis/skills'; import { getSkills } from '$lib/apis/skills';
@@ -397,14 +397,13 @@
if (!(tools[toolId]?.authenticated ?? true)) { if (!(tools[toolId]?.authenticated ?? true)) {
e.preventDefault(); e.preventDefault();
let parts = toolId.split(':'); const parts = toolId.split(':');
let serverId = parts?.at(-1) ?? toolId; initiateOAuthRedirect({
id: toolId,
// Persist the tool ID so we can re-enable it after OAuth redirect serverId: parts.at(-1) ?? toolId,
sessionStorage.setItem('pendingOAuthToolId', toolId); authType:
parts.length > 1 ? (parts[0] === 'server' ? parts[1] : parts[0]) : null
const authUrl = getOAuthClientAuthorizationUrl(serverId, 'mcp'); });
window.open(authUrl, '_self', 'noopener');
} else { } else {
tools[toolId].enabled = !tools[toolId].enabled; tools[toolId].enabled = !tools[toolId].enabled;