refac
This commit is contained in:
1 parent
8a42aa53e8
commit
f822605b35
3 files changed
+68
-12
No files matched your search
@@ -17,7 +17,11 @@
|
|||||||
import Switch from '$lib/components/common/Switch.svelte';
|
import Switch from '$lib/components/common/Switch.svelte';
|
||||||
import Tags from './common/Tags.svelte';
|
import Tags from './common/Tags.svelte';
|
||||||
import { getToolServerData } from '$lib/apis';
|
import { getToolServerData } from '$lib/apis';
|
||||||
import { verifyToolServerConnection, registerOAuthClient } from '$lib/apis/configs';
|
import {
|
||||||
|
verifyToolServerConnection,
|
||||||
|
registerOAuthClient,
|
||||||
|
initiateOAuthRedirect
|
||||||
|
} from '$lib/apis/configs';
|
||||||
import AccessControlModal from '$lib/components/workspace/common/AccessControlModal.svelte';
|
import AccessControlModal from '$lib/components/workspace/common/AccessControlModal.svelte';
|
||||||
import AccessButton from '$lib/components/common/AccessButton.svelte';
|
import AccessButton from '$lib/components/common/AccessButton.svelte';
|
||||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||||
@@ -73,6 +77,29 @@
|
|||||||
'bg-transparent outline-hidden placeholder:text-gray-300 dark:placeholder:text-gray-700';
|
'bg-transparent outline-hidden placeholder:text-gray-300 dark:placeholder:text-gray-700';
|
||||||
const selectClass =
|
const selectClass =
|
||||||
'bg-transparent pr-5 outline-hidden placeholder:text-gray-300 dark:placeholder:text-gray-700';
|
'bg-transparent pr-5 outline-hidden placeholder:text-gray-300 dark:placeholder:text-gray-700';
|
||||||
|
const isMcpOAuth = () => type === 'mcp' && ['oauth_2.1', 'oauth_2.1_static'].includes(auth_type);
|
||||||
|
const verifyLabel = () =>
|
||||||
|
isMcpOAuth() ? $i18n.t('Check OAuth Discovery') : $i18n.t('Verify Connection');
|
||||||
|
const verifySuccessMessage = () =>
|
||||||
|
isMcpOAuth() ? $i18n.t('OAuth discovery successful') : $i18n.t('Connection successful');
|
||||||
|
|
||||||
|
const authorizeOAuthHandler = () => {
|
||||||
|
if (!id) {
|
||||||
|
toast.error($i18n.t('Please enter a valid ID'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!edit) {
|
||||||
|
toast.error($i18n.t('Please save the connection before authorizing OAuth'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
initiateOAuthRedirect({
|
||||||
|
id: `server:mcp:${id}`,
|
||||||
|
serverId: id,
|
||||||
|
authType: 'mcp'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const registerOAuthClientHandler = async () => {
|
const registerOAuthClientHandler = async () => {
|
||||||
if (url === '') {
|
if (url === '') {
|
||||||
@@ -185,14 +212,21 @@
|
|||||||
info: {
|
info: {
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
description
|
description,
|
||||||
|
...(isMcpOAuth()
|
||||||
|
? {
|
||||||
|
...(oauthServerUrl ? { oauth_server_url: oauthServerUrl } : {}),
|
||||||
|
...(oauthScope ? { oauth_scope: oauthScope } : {}),
|
||||||
|
oauth_resource_parameter: oauthResourceParameter
|
||||||
|
}
|
||||||
|
: {})
|
||||||
}
|
}
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
toast.error($i18n.t('Connection failed'));
|
toast.error($i18n.t('Connection failed'));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
toast.success($i18n.t('Connection successful'));
|
toast.success(verifySuccessMessage());
|
||||||
console.debug('Connection successful', res);
|
console.debug('Connection successful', res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -609,16 +643,13 @@
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Tooltip
|
<Tooltip content={verifyLabel()} className="shrink-0 flex items-center mr-1">
|
||||||
content={$i18n.t('Verify Connection')}
|
|
||||||
className="shrink-0 flex items-center mr-1"
|
|
||||||
>
|
|
||||||
<button
|
<button
|
||||||
class="self-center p-1 bg-transparent hover:bg-gray-100 dark:hover:bg-gray-850 rounded-lg transition"
|
class="self-center p-1 bg-transparent hover:bg-gray-100 dark:hover:bg-gray-850 rounded-lg transition"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
verifyHandler();
|
verifyHandler();
|
||||||
}}
|
}}
|
||||||
aria-label={$i18n.t('Verify Connection')}
|
aria-label={verifyLabel()}
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
@@ -653,8 +684,27 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if ['oauth_2.1', 'oauth_2.1_static'].includes(auth_type)}
|
{#if isMcpOAuth()}
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
|
{#if oauthClientInfo}
|
||||||
|
<div class="flex flex-col justify-end items-center shrink-0">
|
||||||
|
<Tooltip
|
||||||
|
content={edit
|
||||||
|
? $i18n.t('Authorize OAuth')
|
||||||
|
: $i18n.t('Please save the connection before authorizing OAuth')}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
class=" text-xs underline dark:text-gray-500 dark:hover:text-gray-200 text-gray-700 hover:text-gray-900 disabled:opacity-50 disabled:no-underline transition"
|
||||||
|
type="button"
|
||||||
|
disabled={!edit}
|
||||||
|
on:click={authorizeOAuthHandler}
|
||||||
|
>
|
||||||
|
{$i18n.t('Authorize OAuth')}
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="flex flex-col justify-end items-center shrink-0">
|
<div class="flex flex-col justify-end items-center shrink-0">
|
||||||
<Tooltip
|
<Tooltip
|
||||||
content={oauthClientInfo
|
content={oauthClientInfo
|
||||||
@@ -792,6 +842,7 @@
|
|||||||
on:click={() => {
|
on:click={() => {
|
||||||
showAccessControlModal = true;
|
showAccessControlModal = true;
|
||||||
}}
|
}}
|
||||||
|
label={$i18n.t('Access Control')}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,10 +5,11 @@
|
|||||||
|
|
||||||
import LockClosed from '$lib/components/icons/LockClosed.svelte';
|
import LockClosed from '$lib/components/icons/LockClosed.svelte';
|
||||||
|
|
||||||
|
const i18n = getContext<Writable<i18nType>>('i18n');
|
||||||
|
|
||||||
export let className = '';
|
export let className = '';
|
||||||
export let disabled = false;
|
export let disabled = false;
|
||||||
|
export let label = '';
|
||||||
const i18n = getContext<Writable<i18nType>>('i18n');
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@@ -18,5 +19,5 @@
|
|||||||
on:click
|
on:click
|
||||||
>
|
>
|
||||||
<LockClosed strokeWidth="2.5" className="size-3 shrink-0" />
|
<LockClosed strokeWidth="2.5" className="size-3 shrink-0" />
|
||||||
<span class="shrink-0">{$i18n.t('Access')}</span>
|
<span class="shrink-0">{label || $i18n.t('Access')}</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -305,6 +305,7 @@
|
|||||||
"Auth required": "",
|
"Auth required": "",
|
||||||
"Authenticate": "",
|
"Authenticate": "",
|
||||||
"Authentication": "",
|
"Authentication": "",
|
||||||
|
"Authorize OAuth": "",
|
||||||
"Auto": "",
|
"Auto": "",
|
||||||
"Auto (Random)": "",
|
"Auto (Random)": "",
|
||||||
"Auto Redirect": "",
|
"Auto Redirect": "",
|
||||||
@@ -415,6 +416,7 @@
|
|||||||
"Channel updated successfully": "",
|
"Channel updated successfully": "",
|
||||||
"Channels": "",
|
"Channels": "",
|
||||||
"Character": "",
|
"Character": "",
|
||||||
|
"Check OAuth Discovery": "",
|
||||||
"Chat": "",
|
"Chat": "",
|
||||||
"Chat actions": "",
|
"Chat actions": "",
|
||||||
"Chat archived.": "",
|
"Chat archived.": "",
|
||||||
@@ -1901,6 +1903,7 @@
|
|||||||
"OAuth Scopes": "",
|
"OAuth Scopes": "",
|
||||||
"OAuth scopes requested during sign-in.": "",
|
"OAuth scopes requested during sign-in.": "",
|
||||||
"OAuth Server URL": "",
|
"OAuth Server URL": "",
|
||||||
|
"OAuth discovery successful": "",
|
||||||
"OAuth session disconnected": "",
|
"OAuth session disconnected": "",
|
||||||
"OAuth Signup": "",
|
"OAuth Signup": "",
|
||||||
"October": "",
|
"October": "",
|
||||||
@@ -2063,6 +2066,7 @@
|
|||||||
"Please enter Client ID and Client Secret": "",
|
"Please enter Client ID and Client Secret": "",
|
||||||
"Please fill in all fields.": "",
|
"Please fill in all fields.": "",
|
||||||
"Please register the OAuth client": "",
|
"Please register the OAuth client": "",
|
||||||
|
"Please save the connection before authorizing OAuth": "",
|
||||||
"Please save the connection to persist the OAuth client information and do not change the ID": "",
|
"Please save the connection to persist the OAuth client information and do not change the ID": "",
|
||||||
"Please select a model.": "",
|
"Please select a model.": "",
|
||||||
"Please select a reason": "",
|
"Please select a reason": "",
|
||||||
|
|||||||
Reference in new issue
Block a user