refac
This commit is contained in:
1 parent
1c13fedb16
commit
d241df8d79
3 files changed
+44
-3
No files matched your search
@@ -573,7 +573,10 @@ export const initiateOAuthRedirect = (tool: {
|
|||||||
sessionStorage.setItem('pendingOAuthToolId', tool.id);
|
sessionStorage.setItem('pendingOAuthToolId', tool.id);
|
||||||
sessionStorage.setItem('oauthRedirectInProgressToolId', tool.id);
|
sessionStorage.setItem('oauthRedirectInProgressToolId', tool.id);
|
||||||
const authUrl = getOAuthClientAuthorizationUrl(tool.serverId, tool.authType ?? 'mcp');
|
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) => {
|
export const getCodeExecutionConfig = async (token: string) => {
|
||||||
|
|||||||
@@ -1391,7 +1391,7 @@
|
|||||||
const onMessageHandler = async (event: {
|
const onMessageHandler = async (event: {
|
||||||
origin: string;
|
origin: string;
|
||||||
source: unknown;
|
source: unknown;
|
||||||
data: { type: string; text: string };
|
data: { type: string; text?: string; toolId?: string; error?: string | null };
|
||||||
}) => {
|
}) => {
|
||||||
const isSameOrigin = event.origin === window.origin;
|
const isSameOrigin = event.origin === window.origin;
|
||||||
const type = event.data?.type;
|
const type = event.data?.type;
|
||||||
@@ -1413,6 +1413,29 @@
|
|||||||
return;
|
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') {
|
if (type === 'action:submit') {
|
||||||
console.debug(event.data.text);
|
console.debug(event.data.text);
|
||||||
|
|
||||||
@@ -3491,7 +3514,7 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (message.output && message.role === 'assistant') {
|
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) {
|
if (message.role === 'user' && imageFiles.length > 0) {
|
||||||
|
|||||||
@@ -1069,6 +1069,21 @@
|
|||||||
|
|
||||||
window.addEventListener('message', windowMessageEventHandler);
|
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;
|
let touchstartY = 0;
|
||||||
|
|
||||||
function isNavOrDescendant(el) {
|
function isNavOrDescendant(el) {
|
||||||
|
|||||||
Reference in new issue
Block a user