mirror of
https://github.com/open-webui/open-webui.git
synced 2026-08-28 05:27:35 +00:00
refac
This commit is contained in:
parent
1c13fedb16
commit
d241df8d79
3 changed files with 44 additions and 3 deletions
|
|
@ -573,7 +573,10 @@ export const initiateOAuthRedirect = (tool: {
|
|||
sessionStorage.setItem('pendingOAuthToolId', tool.id);
|
||||
sessionStorage.setItem('oauthRedirectInProgressToolId', tool.id);
|
||||
const authUrl = getOAuthClientAuthorizationUrl(tool.serverId, tool.authType ?? 'mcp');
|
||||
window.open(authUrl, '_self', 'noopener');
|
||||
const tab = window.open(authUrl, '_blank');
|
||||
if (!tab) {
|
||||
window.open(authUrl, '_self', 'noopener');
|
||||
}
|
||||
};
|
||||
|
||||
export const getCodeExecutionConfig = async (token: string) => {
|
||||
|
|
|
|||
|
|
@ -1391,7 +1391,7 @@
|
|||
const onMessageHandler = async (event: {
|
||||
origin: string;
|
||||
source: unknown;
|
||||
data: { type: string; text: string };
|
||||
data: { type: string; text?: string; toolId?: string; error?: string | null };
|
||||
}) => {
|
||||
const isSameOrigin = event.origin === window.origin;
|
||||
const type = event.data?.type;
|
||||
|
|
@ -1413,6 +1413,29 @@
|
|||
return;
|
||||
}
|
||||
|
||||
if (type === 'oauth:complete') {
|
||||
const toolId = event.data.toolId;
|
||||
if (!toolId) return;
|
||||
|
||||
if (event.data.error) {
|
||||
sessionStorage.removeItem('oauthRedirectInProgressToolId');
|
||||
toast.error(event.data.error);
|
||||
return;
|
||||
}
|
||||
|
||||
sessionStorage.removeItem('pendingOAuthToolId');
|
||||
sessionStorage.removeItem('oauthRedirectInProgressToolId');
|
||||
const updatedTools = await getTools(localStorage.token).catch(() => null);
|
||||
if (updatedTools) {
|
||||
tools.set(updatedTools);
|
||||
}
|
||||
selectedToolIds = [...new Set([...selectedToolIds, toolId])];
|
||||
pendingOAuthTools = pendingOAuthTools.filter((tool) => tool.id !== toolId);
|
||||
await tick();
|
||||
await continueOAuthRedirect();
|
||||
return;
|
||||
}
|
||||
|
||||
if (type === 'action:submit') {
|
||||
console.debug(event.data.text);
|
||||
|
||||
|
|
@ -3491,7 +3514,7 @@
|
|||
);
|
||||
|
||||
if (message.output && message.role === 'assistant') {
|
||||
return { role: message.role, output: message.output };
|
||||
return { role: message.role, model: message.model, output: message.output };
|
||||
}
|
||||
|
||||
if (message.role === 'user' && imageFiles.length > 0) {
|
||||
|
|
|
|||
|
|
@ -1069,6 +1069,21 @@
|
|||
|
||||
window.addEventListener('message', windowMessageEventHandler);
|
||||
|
||||
const pendingOAuthToolId = sessionStorage.getItem('pendingOAuthToolId');
|
||||
if (window.opener && window.location.pathname === '/' && pendingOAuthToolId) {
|
||||
window.opener.postMessage(
|
||||
{
|
||||
type: 'oauth:complete',
|
||||
toolId: pendingOAuthToolId,
|
||||
error: new URLSearchParams(window.location.search).get('error')
|
||||
},
|
||||
window.location.origin
|
||||
);
|
||||
sessionStorage.removeItem('pendingOAuthToolId');
|
||||
sessionStorage.removeItem('oauthRedirectInProgressToolId');
|
||||
window.close();
|
||||
}
|
||||
|
||||
let touchstartY = 0;
|
||||
|
||||
function isNavOrDescendant(el) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue