chore: 项目基线(基于 WeKnora 定制版,整理文件忽略规则)
This commit is contained in:
commit
9097ee699d
5769 files changed
+1446466
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,127 @@
|
||||
<template>
|
||||
<IntegrationLandingLayout
|
||||
:title="$t('integrations.chrome.title')"
|
||||
:subtitle="$t('integrations.chrome.subtitle')"
|
||||
variant="chrome"
|
||||
>
|
||||
<template #tags>
|
||||
<span v-for="key in scenarioKeys" :key="key" class="scenario-tag">
|
||||
{{ $t(`integrations.chrome.scenarios.${key}`) }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template #actions>
|
||||
<IntegrationExternalCta
|
||||
variant="chrome"
|
||||
:label="$t('integrations.chrome.installCta')"
|
||||
:hint="$t('integrations.chrome.installCtaHint')"
|
||||
@click="openChromeStore"
|
||||
>
|
||||
<template #icon>
|
||||
<t-icon name="extension" size="18px" />
|
||||
</template>
|
||||
</IntegrationExternalCta>
|
||||
</template>
|
||||
|
||||
<template #main>
|
||||
<div class="landing-group">
|
||||
<section class="setting-drawer__section">
|
||||
<h4 class="setting-drawer__section-title">
|
||||
{{ $t('integrations.chrome.capabilitiesTitle') }}
|
||||
<span class="section-head-extra">{{ capabilityKeys.length }}</span>
|
||||
</h4>
|
||||
<div class="capability-grid">
|
||||
<div v-for="key in capabilityKeys" :key="key" class="capability-card">
|
||||
<div class="capability-card__icon">
|
||||
<t-icon :name="capabilityIcons[key]" />
|
||||
</div>
|
||||
<h5 class="capability-card__title">{{ $t(`integrations.chrome.capabilities.${key}.title`) }}</h5>
|
||||
<p class="capability-card__desc">{{ $t(`integrations.chrome.capabilities.${key}.desc`) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #aside>
|
||||
<div class="landing-group">
|
||||
<section class="setting-drawer__section">
|
||||
<h4 class="setting-drawer__section-title">{{ $t('integrations.chrome.stepsTitle') }}</h4>
|
||||
<ol class="landing-steps">
|
||||
<li v-for="(step, index) in stepKeys" :key="step" class="landing-step">
|
||||
<span class="landing-step-num">{{ index + 1 }}</span>
|
||||
<div class="landing-step-body">
|
||||
<div class="landing-step-title">{{ $t(`integrations.chrome.steps.${step}.title`) }}</div>
|
||||
<p class="landing-step-desc">{{ $t(`integrations.chrome.steps.${step}.desc`) }}</p>
|
||||
<t-button
|
||||
v-if="step === 'api'"
|
||||
size="small"
|
||||
variant="outline"
|
||||
class="landing-step-action"
|
||||
@click="openApiSettings"
|
||||
>
|
||||
{{ $t('integrations.chrome.openApiSettings') }}
|
||||
</t-button>
|
||||
<div v-if="step === 'connect'" class="landing-step-embed credential-row">
|
||||
<div class="api-key-control landing-api-control">
|
||||
<t-input :model-value="apiBaseUrlDisplay" readonly class="mono-text-input" />
|
||||
<t-button
|
||||
size="small"
|
||||
variant="text"
|
||||
:title="$t('integrations.chrome.copy')"
|
||||
@click="copyApiUrl"
|
||||
>
|
||||
<t-icon name="file-copy" size="16px" />
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
<span class="landing-meta">{{ $t('integrations.chrome.storeMeta') }}</span>
|
||||
</template>
|
||||
</IntegrationLandingLayout>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { copyWithToast } from '@/utils/clipboard'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { CHROME_EXTENSION_URL } from '@/config/integrations'
|
||||
import { useApiBaseUrlDisplay } from '@/composables/useApiBaseUrlDisplay'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
import IntegrationLandingLayout from './IntegrationLandingLayout.vue'
|
||||
import IntegrationExternalCta from './IntegrationExternalCta.vue'
|
||||
|
||||
const router = useRouter()
|
||||
const uiStore = useUIStore()
|
||||
const { apiBaseUrlDisplay } = useApiBaseUrlDisplay()
|
||||
|
||||
const capabilityKeys = ['qa', 'clip', 'notes', 'shortcuts'] as const
|
||||
const scenarioKeys = ['research', 'learning', 'tech', 'work'] as const
|
||||
const stepKeys = ['api', 'port', 'install', 'connect'] as const
|
||||
|
||||
const capabilityIcons: Record<(typeof capabilityKeys)[number], string> = {
|
||||
qa: 'chat-bubble',
|
||||
clip: 'file-copy',
|
||||
notes: 'edit',
|
||||
shortcuts: 'jump',
|
||||
}
|
||||
|
||||
const openChromeStore = () => {
|
||||
window.open(CHROME_EXTENSION_URL, '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
|
||||
const openApiSettings = () => {
|
||||
router.push({ path: '/platform/settings', query: { section: 'integration-api' } })
|
||||
uiStore.openSettings('integration-api')
|
||||
}
|
||||
|
||||
const copyApiUrl = async () => {
|
||||
await copyWithToast(apiBaseUrlDisplay.value, 'integrations.chrome.copySuccess')
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,148 @@
|
||||
<template>
|
||||
<IntegrationLandingLayout
|
||||
:title="$t('integrations.claw.title')"
|
||||
:subtitle="$t('integrations.claw.subtitle')"
|
||||
variant="claw"
|
||||
>
|
||||
<template #actions>
|
||||
<IntegrationExternalCta
|
||||
variant="claw"
|
||||
:label="$t('integrations.claw.installCta')"
|
||||
:hint="$t('integrations.claw.installCtaHint')"
|
||||
@click="openClawHub"
|
||||
>
|
||||
<template #icon>
|
||||
<span class="ext-cta-emoji" role="img" :aria-label="$t('common.clawhubSkill')">🦞</span>
|
||||
</template>
|
||||
</IntegrationExternalCta>
|
||||
</template>
|
||||
|
||||
<template #main>
|
||||
<div class="landing-group">
|
||||
<section class="setting-drawer__section">
|
||||
<h4 class="setting-drawer__section-title">
|
||||
{{ $t('integrations.claw.capabilitiesTitle') }}
|
||||
<span class="section-head-extra">{{ capabilityKeys.length }}</span>
|
||||
</h4>
|
||||
<div class="capability-grid capability-grid--claw">
|
||||
<div v-for="key in capabilityKeys" :key="key" class="capability-card">
|
||||
<div class="capability-card__icon">
|
||||
<t-icon :name="capabilityIcons[key]" />
|
||||
</div>
|
||||
<h5 class="capability-card__title">{{ $t(`integrations.claw.capabilities.${key}.title`) }}</h5>
|
||||
<p class="capability-card__desc">{{ $t(`integrations.claw.capabilities.${key}.desc`) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #aside>
|
||||
<div class="landing-group">
|
||||
<section class="setting-drawer__section">
|
||||
<h4 class="setting-drawer__section-title">{{ $t('integrations.claw.stepsTitle') }}</h4>
|
||||
<ol class="landing-steps">
|
||||
<li v-for="(step, index) in stepKeys" :key="step" class="landing-step">
|
||||
<span class="landing-step-num">{{ index + 1 }}</span>
|
||||
<div class="landing-step-body">
|
||||
<div class="landing-step-title">{{ $t(`integrations.claw.steps.${step}.title`) }}</div>
|
||||
<p class="landing-step-desc">{{ $t(`integrations.claw.steps.${step}.desc`) }}</p>
|
||||
<t-button
|
||||
v-if="step === 'api'"
|
||||
size="small"
|
||||
variant="outline"
|
||||
class="landing-step-action"
|
||||
@click="openApiSettings"
|
||||
>
|
||||
{{ $t('integrations.claw.openApiSettings') }}
|
||||
</t-button>
|
||||
<div v-if="step === 'env'" class="landing-step-embed">
|
||||
<div class="code-toolbar">
|
||||
<pre class="code-toolbar__code">{{ envExample }}</pre>
|
||||
<t-button
|
||||
class="code-toolbar__copy"
|
||||
size="small"
|
||||
variant="text"
|
||||
shape="square"
|
||||
:title="$t('integrations.claw.copy')"
|
||||
@click="copyEnvExample"
|
||||
>
|
||||
<t-icon name="file-copy" size="16px" />
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="step === 'install'" class="landing-step-embed">
|
||||
<div class="code-toolbar">
|
||||
<pre class="code-toolbar__code">{{ installCommand }}</pre>
|
||||
<t-button
|
||||
class="code-toolbar__copy"
|
||||
size="small"
|
||||
variant="text"
|
||||
shape="square"
|
||||
:title="$t('integrations.claw.copy')"
|
||||
@click="copyInstallCommand"
|
||||
>
|
||||
<t-icon name="file-copy" size="16px" />
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
<div class="landing-footer-bar" role="note">
|
||||
<p class="landing-footer-bar__note">{{ $t('integrations.claw.ecosystemNote') }}</p>
|
||||
<span class="landing-meta">{{ $t('integrations.claw.hubMeta') }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</IntegrationLandingLayout>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { copyWithToast } from '@/utils/clipboard'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { CLAWHUB_SKILL_URL } from '@/config/integrations'
|
||||
import { useApiBaseUrlDisplay } from '@/composables/useApiBaseUrlDisplay'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
import IntegrationLandingLayout from './IntegrationLandingLayout.vue'
|
||||
import IntegrationExternalCta from './IntegrationExternalCta.vue'
|
||||
|
||||
const router = useRouter()
|
||||
const uiStore = useUIStore()
|
||||
const { apiBaseUrlDisplay } = useApiBaseUrlDisplay()
|
||||
|
||||
const capabilityKeys = ['upload', 'url', 'manual', 'search', 'browse'] as const
|
||||
const stepKeys = ['api', 'env', 'install', 'verify'] as const
|
||||
|
||||
const capabilityIcons: Record<(typeof capabilityKeys)[number], string> = {
|
||||
upload: 'upload',
|
||||
url: 'link',
|
||||
manual: 'edit',
|
||||
search: 'search',
|
||||
browse: 'view-list',
|
||||
}
|
||||
|
||||
const installCommand = 'openclaw skills install @lyingbug/weknora'
|
||||
|
||||
const envExample = computed(() => {
|
||||
const base = apiBaseUrlDisplay.value || 'https://your-server.com/api/v1'
|
||||
return `export WEKNORA_BASE_URL="${base}"\nexport WEKNORA_API_KEY="sk-your-api-key"`
|
||||
})
|
||||
|
||||
const openClawHub = () => {
|
||||
window.open(CLAWHUB_SKILL_URL, '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
|
||||
const openApiSettings = () => {
|
||||
router.push({ path: '/platform/settings', query: { section: 'integration-api' } })
|
||||
uiStore.openSettings('integration-api')
|
||||
}
|
||||
|
||||
const copyEnvExample = () => copyWithToast(envExample.value, 'integrations.claw.copyEnvSuccess')
|
||||
const copyInstallCommand = () => copyWithToast(installCommand, 'integrations.claw.copyCmdSuccess')
|
||||
</script>
|
||||
@@ -0,0 +1,109 @@
|
||||
<template>
|
||||
<IntegrationLandingLayout
|
||||
:title="$t('integrations.cli.title')"
|
||||
:subtitle="$t('integrations.cli.subtitle')"
|
||||
variant="cli"
|
||||
>
|
||||
<template #actions>
|
||||
<IntegrationExternalCta
|
||||
:label="$t('integrations.cli.docs')"
|
||||
:hint="$t('integrations.cli.docsHint')"
|
||||
@click="openDocs"
|
||||
>
|
||||
<template #icon><t-icon name="code" /></template>
|
||||
</IntegrationExternalCta>
|
||||
</template>
|
||||
|
||||
<template #main>
|
||||
<div class="landing-group">
|
||||
<section class="setting-drawer__section">
|
||||
<h4 class="setting-drawer__section-title">{{ $t('integrations.cli.quickstart') }}</h4>
|
||||
<ol class="landing-steps">
|
||||
<li v-for="(step, index) in steps" :key="step.key" class="landing-step">
|
||||
<span class="landing-step-num">{{ index + 1 }}</span>
|
||||
<div class="landing-step-body">
|
||||
<div class="landing-step-title">{{ $t(`integrations.cli.${step.key}Title`) }}</div>
|
||||
<p class="landing-step-desc">{{ $t(`integrations.cli.${step.key}Desc`) }}</p>
|
||||
<div class="landing-step-embed code-toolbar">
|
||||
<pre class="code-toolbar__code">{{ step.command }}</pre>
|
||||
<t-button
|
||||
class="code-toolbar__copy"
|
||||
size="small"
|
||||
variant="text"
|
||||
shape="square"
|
||||
:title="$t('integrations.cli.copy')"
|
||||
:aria-label="$t('integrations.cli.copy')"
|
||||
@click="copy(step.command)"
|
||||
>
|
||||
<t-icon name="file-copy" size="16px" />
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #aside>
|
||||
<div class="landing-group">
|
||||
<section v-for="example in examples" :key="example.key" class="setting-drawer__section">
|
||||
<h4 class="setting-drawer__section-title">{{ $t(`integrations.cli.${example.key}Title`) }}</h4>
|
||||
<p class="field-desc">{{ $t(`integrations.cli.${example.key}Desc`) }}</p>
|
||||
<div class="code-toolbar">
|
||||
<pre class="code-toolbar__code">{{ example.command }}</pre>
|
||||
<t-button
|
||||
class="code-toolbar__copy"
|
||||
size="small"
|
||||
variant="text"
|
||||
shape="square"
|
||||
:title="$t('integrations.cli.copy')"
|
||||
:aria-label="$t('integrations.cli.copy')"
|
||||
@click="copy(example.command)"
|
||||
>
|
||||
<t-icon name="file-copy" size="16px" />
|
||||
</t-button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
</IntegrationLandingLayout>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useApiBaseUrlDisplay } from '@/composables/useApiBaseUrlDisplay'
|
||||
import { copyWithToast } from '@/utils/clipboard'
|
||||
import IntegrationLandingLayout from './IntegrationLandingLayout.vue'
|
||||
import IntegrationExternalCta from './IntegrationExternalCta.vue'
|
||||
import { buildCLIConnectCommand } from './cliIntegration'
|
||||
|
||||
const { apiBaseUrlDisplay } = useApiBaseUrlDisplay()
|
||||
const steps = computed(() => [
|
||||
{
|
||||
key: 'install',
|
||||
command: 'git clone https://github.com/Tencent/WeKnora.git\ncd WeKnora/cli\ngo build -o weknora .\nexport PATH="$PWD:$PATH"',
|
||||
},
|
||||
{ key: 'connect', command: buildCLIConnectCommand(apiBaseUrlDisplay.value, window.location.origin) },
|
||||
{ key: 'verify', command: 'weknora doctor\nweknora kb list' },
|
||||
])
|
||||
const examples = [
|
||||
{
|
||||
key: 'commands',
|
||||
command: 'weknora doc upload ./document.pdf --kb "KB_ID"\nweknora search chunks "query" --kb "KB_ID"\nweknora chat "question" --kb "KB_ID" --format text\nweknora agent list',
|
||||
},
|
||||
{
|
||||
key: 'mcp',
|
||||
command: JSON.stringify({
|
||||
mcpServers: {
|
||||
weknora: { command: 'weknora', args: ['--profile', 'weknora', 'mcp', 'serve'] },
|
||||
},
|
||||
}, null, 2),
|
||||
},
|
||||
]
|
||||
|
||||
const copy = (command: string) => copyWithToast(command, 'integrations.cli.copied')
|
||||
const openDocs = () => {
|
||||
window.open('https://github.com/Tencent/WeKnora/blob/main/cli/README.md', '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,32 @@
|
||||
<template>
|
||||
<button
|
||||
type="button"
|
||||
class="ext-cta"
|
||||
:class="`ext-cta--${variant}`"
|
||||
:title="hint"
|
||||
@click="emit('click')"
|
||||
>
|
||||
<span class="ext-cta__badge" aria-hidden="true">
|
||||
<slot name="icon" />
|
||||
</span>
|
||||
<span class="ext-cta__label">{{ label }}</span>
|
||||
<span class="ext-cta__arrow-wrap" aria-hidden="true">
|
||||
<t-icon name="jump" class="ext-cta__arrow" />
|
||||
</span>
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
label: string
|
||||
hint?: string
|
||||
variant?: 'chrome' | 'claw'
|
||||
}>(),
|
||||
{ variant: 'chrome' },
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
click: []
|
||||
}>()
|
||||
</script>
|
||||
@@ -0,0 +1,44 @@
|
||||
<template>
|
||||
<div class="integration-landing" :class="`integration-landing--${variant}`">
|
||||
<header class="landing-hero">
|
||||
<div class="landing-hero__top">
|
||||
<h2 class="landing-hero__title">{{ title }}</h2>
|
||||
<div v-if="$slots.actions" class="landing-hero__actions">
|
||||
<slot name="actions" />
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="subtitle" class="landing-hero__subtitle">{{ subtitle }}</p>
|
||||
<div v-if="$slots.tags" class="landing-hero__tags">
|
||||
<slot name="tags" />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="landing-body">
|
||||
<section class="landing-main">
|
||||
<slot name="main" />
|
||||
</section>
|
||||
<section class="landing-aside">
|
||||
<slot name="aside" />
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<footer v-if="$slots.footer" class="landing-footer">
|
||||
<slot name="footer" />
|
||||
</footer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
title: string
|
||||
subtitle?: string
|
||||
variant?: 'chrome' | 'claw' | 'cli'
|
||||
}>(),
|
||||
{ variant: 'chrome' },
|
||||
)
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
@import './integration-landing.less';
|
||||
</style>
|
||||
@@ -0,0 +1,118 @@
|
||||
<template>
|
||||
<div class="integrations-settings">
|
||||
<div class="integrations-settings__body">
|
||||
<div v-if="tab === 'im'" class="section">
|
||||
<div class="section-header">
|
||||
<h2>{{ $t('agentEditor.im.title') }}</h2>
|
||||
<p class="section-description">
|
||||
{{ $t('agentEditor.im.description') }}
|
||||
<a
|
||||
:href="docsUrl('imIntegration')"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="doc-link"
|
||||
>
|
||||
{{ $t('agentEditor.im.docLink') }}
|
||||
<t-icon name="link" class="link-icon" />
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<IMChannelPanel v-model:filter-agent-id="filterAgentId" />
|
||||
</div>
|
||||
|
||||
<div v-if="tab === 'embed'" class="section">
|
||||
<div class="section-header">
|
||||
<h2>{{ $t('agentEditor.embed.title') }}</h2>
|
||||
<p class="section-description">{{ $t('agentEditor.embed.description') }}</p>
|
||||
</div>
|
||||
<AgentEmbedChannelPanel v-model:filter-agent-id="filterAgentId" />
|
||||
</div>
|
||||
|
||||
<div v-if="tab === 'api'" class="section">
|
||||
<div class="section-header">
|
||||
<h2>{{ $t('integrations.api.title') }}</h2>
|
||||
<p class="section-description">{{ $t('integrations.api.subtitle') }}</p>
|
||||
</div>
|
||||
<ApiIntegrationSettings />
|
||||
</div>
|
||||
|
||||
<div v-if="tab === 'mcpserver'" class="section">
|
||||
<div class="section-header">
|
||||
<h2>{{ $t('integrations.mcpserver.title') }}</h2>
|
||||
<p class="section-description">{{ $t('integrations.mcpserver.subtitle') }}</p>
|
||||
</div>
|
||||
<McpServerIntegrationSettings />
|
||||
</div>
|
||||
|
||||
<ChromeExtensionLanding v-if="tab === 'chrome'" />
|
||||
<ClawSkillLanding v-if="tab === 'claw'" />
|
||||
<CliIntegrationLanding v-if="tab === 'cli'" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import IMChannelPanel from '@/components/IMChannelPanel.vue'
|
||||
import AgentEmbedChannelPanel from '@/components/AgentEmbedChannelPanel.vue'
|
||||
import ApiIntegrationSettings from '@/views/integrations/ApiIntegrationSettings.vue'
|
||||
import McpServerIntegrationSettings from '@/views/integrations/McpServerIntegrationSettings.vue'
|
||||
import ChromeExtensionLanding from '@/views/integrations/ChromeExtensionLanding.vue'
|
||||
import ClawSkillLanding from '@/views/integrations/ClawSkillLanding.vue'
|
||||
import CliIntegrationLanding from '@/views/integrations/CliIntegrationLanding.vue'
|
||||
import type { IntegrationTab } from '@/config/integrations'
|
||||
import { docsUrl } from '@/utils/docsUrl'
|
||||
|
||||
const filterAgentId = ref('')
|
||||
|
||||
defineProps<{
|
||||
tab: IntegrationTab
|
||||
}>()
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
function applyAgentFilterFromRoute() {
|
||||
filterAgentId.value = (route.query.agentId as string) || ''
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.query.agentId,
|
||||
applyAgentFilterFromRoute,
|
||||
{ immediate: true },
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@import (reference) '@/components/css/settings-section.less';
|
||||
|
||||
.integrations-settings {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.integrations-settings__body {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
.settings-section-header();
|
||||
}
|
||||
|
||||
.doc-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
margin-left: 6px;
|
||||
color: var(--td-brand-color);
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.link-icon {
|
||||
font-size: var(--app-text-md);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,802 @@
|
||||
<template>
|
||||
<div class="mcp-server-panel">
|
||||
<div class="channels-section">
|
||||
<div class="channels-header">
|
||||
<span class="channels-title">{{ $t('integrations.mcpserver.listTitle') }}</span>
|
||||
<span class="channels-count">{{ endpoints.length }}</span>
|
||||
</div>
|
||||
|
||||
<t-loading :loading="loading" size="small" class="channels-loading-wrap">
|
||||
<div v-if="!loading && endpoints.length === 0 && !isAdmin" class="channels-empty">
|
||||
<t-empty :description="$t('integrations.mcpserver.empty')" />
|
||||
</div>
|
||||
|
||||
<div v-else-if="!loading" class="channel-grid">
|
||||
<button
|
||||
v-for="ep in endpoints"
|
||||
:key="ep.id"
|
||||
type="button"
|
||||
class="channel-card channel-card--clickable"
|
||||
@click="openEdit(ep)"
|
||||
>
|
||||
<div class="channel-card__badge">
|
||||
<t-icon name="tools" size="22px" />
|
||||
</div>
|
||||
<div class="channel-card__body">
|
||||
<div class="channel-card__header">
|
||||
<h3 class="channel-card__title">{{ ep.name }}</h3>
|
||||
<t-tag v-if="!ep.enabled" size="small" variant="light" theme="warning">
|
||||
{{ $t('integrations.mcpserver.disabled') }}
|
||||
</t-tag>
|
||||
</div>
|
||||
<span class="channel-card__agent-name">
|
||||
{{ $t('integrations.mcpserver.cardSummary', { tools: ep.tools.length, scope: scopeLabel(ep) }) }}
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="isAdmin" class="channel-card__actions" @click.stop>
|
||||
<t-dropdown
|
||||
trigger="click"
|
||||
placement="bottom-right"
|
||||
attach="body"
|
||||
:options="menuOptions(ep)"
|
||||
@click="handleMenuClick($event, ep)"
|
||||
>
|
||||
<t-button variant="text" shape="square" size="small" class="channel-card__action-btn" @click.stop>
|
||||
<template #icon><t-icon name="ellipsis" /></template>
|
||||
</t-button>
|
||||
</t-dropdown>
|
||||
<t-popconfirm
|
||||
:content="$t('integrations.mcpserver.deleteConfirm')"
|
||||
:confirm-btn="{ content: $t('common.delete'), theme: 'danger' }"
|
||||
:cancel-btn="{ content: $t('common.cancel') }"
|
||||
placement="bottom-right"
|
||||
@confirm="() => removeEndpoint(ep)"
|
||||
>
|
||||
<t-tooltip :content="$t('common.delete')" placement="top">
|
||||
<t-button theme="danger" shape="square" variant="text" size="small" class="channel-card__action-btn" @click.stop>
|
||||
<template #icon><t-icon name="delete" /></template>
|
||||
</t-button>
|
||||
</t-tooltip>
|
||||
</t-popconfirm>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<button v-if="isAdmin" type="button" class="channel-card channel-card--add" @click="openCreate">
|
||||
<span class="channel-card__badge" aria-hidden="true">
|
||||
<t-icon name="add" />
|
||||
</span>
|
||||
<div class="channel-card__body">
|
||||
<div class="channel-card__header">
|
||||
<span class="channel-card__title">{{ $t('integrations.mcpserver.create') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<span class="channel-card__actions channel-card__actions--spacer" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
</t-loading>
|
||||
</div>
|
||||
|
||||
<SettingDrawer
|
||||
v-model:visible="showDrawer"
|
||||
class="mcp-endpoint-drawer"
|
||||
:title="editing ? $t('integrations.mcpserver.editTitle') : $t('integrations.mcpserver.createTitle')"
|
||||
:description="drawerStepDescription"
|
||||
icon="tools"
|
||||
storage-key="setting-drawer:mcp-endpoint"
|
||||
width="600px"
|
||||
:confirm-loading="saving"
|
||||
:confirm-text="drawerConfirmText"
|
||||
:hide-footer="!isAdmin"
|
||||
:close-on-overlay-click="!freshToken"
|
||||
@confirm="handleDrawerConfirm"
|
||||
@cancel="closeDrawer"
|
||||
>
|
||||
<template v-if="wizardStep > 0 && editing" #footer-left>
|
||||
<t-button variant="outline" @click="goToWizardStep(0)">
|
||||
{{ $t('common.back') }}
|
||||
</t-button>
|
||||
</template>
|
||||
|
||||
<div class="im-steps">
|
||||
<button
|
||||
v-for="(title, i) in stepTitles"
|
||||
:key="i"
|
||||
type="button"
|
||||
:class="['im-step', { active: wizardStep === i, done: wizardStep > i }]"
|
||||
:disabled="!editing && i > 0"
|
||||
@click="goToWizardStep(i)"
|
||||
>
|
||||
<span class="im-step-num">
|
||||
<t-icon v-if="wizardStep > i" name="check" class="im-step-check" />
|
||||
<template v-else>{{ i + 1 }}</template>
|
||||
</span>
|
||||
<span class="im-step-title">{{ title }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Step 1: configuration -->
|
||||
<div v-if="wizardStep === 0" class="im-step-body">
|
||||
<section class="setting-drawer__section">
|
||||
<h4 class="setting-drawer__section-title">{{ $t('integrations.mcpserver.sectionBasic') }}</h4>
|
||||
<div class="form-item">
|
||||
<label class="form-label required">{{ $t('integrations.mcpserver.nameLabel') }}</label>
|
||||
<t-input v-model="form.name" :placeholder="$t('integrations.mcpserver.namePlaceholder')" :maxlength="255" />
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ $t('integrations.mcpserver.descriptionLabel') }}</label>
|
||||
<t-textarea v-model="form.description" :autosize="{ minRows: 2, maxRows: 4 }" :placeholder="$t('integrations.mcpserver.descriptionPlaceholder')" />
|
||||
</div>
|
||||
<div class="form-item enable-row">
|
||||
<label class="form-label form-label--inline">{{ $t('integrations.mcpserver.enabledLabel') }}</label>
|
||||
<t-switch v-model="form.enabled" size="small" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="setting-drawer__section">
|
||||
<h4 class="setting-drawer__section-title">{{ $t('integrations.mcpserver.sectionScope') }}</h4>
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ $t('integrations.mcpserver.kbScopeLabel') }}</label>
|
||||
<t-select
|
||||
v-model="form.knowledge_base_ids"
|
||||
multiple
|
||||
filterable
|
||||
clearable
|
||||
:loading="kbLoading"
|
||||
:options="kbOptions"
|
||||
:placeholder="$t('integrations.mcpserver.kbScopePlaceholder')"
|
||||
/>
|
||||
<p class="form-desc">{{ $t('integrations.mcpserver.kbScopeHint') }}</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="setting-drawer__section">
|
||||
<h4 class="setting-drawer__section-title">{{ $t('integrations.mcpserver.sectionTools') }}</h4>
|
||||
<p class="form-desc form-desc--block">{{ $t('integrations.mcpserver.toolsHint') }}</p>
|
||||
<div class="tool-group-list">
|
||||
<div v-for="group in groupedTools" :key="group.group" class="tool-group">
|
||||
<div class="tool-group__header">
|
||||
<span class="tool-group__name">{{ $t(`integrations.mcpserver.groups.${group.group}`) }}</span>
|
||||
<t-button size="small" variant="text" @click="toggleGroup(group, !groupAllSelected(group))">
|
||||
{{ groupAllSelected(group) ? $t('integrations.mcpserver.clearGroup') : $t('integrations.mcpserver.selectGroup') }}
|
||||
</t-button>
|
||||
</div>
|
||||
<div class="tool-group__items">
|
||||
<div v-for="tool in group.tools" :key="tool.name" class="tool-item" :class="{ 'tool-item--danger': tool.destructive }">
|
||||
<t-checkbox :model-value="toolSelections[tool.name] === true" @change="(v: boolean) => setToolSelected(tool.name, v)">
|
||||
<span class="tool-item__label">
|
||||
{{ $t(`integrations.mcpserver.tools.${tool.name}`) }}
|
||||
<code class="tool-item__code">{{ tool.name }}</code>
|
||||
</span>
|
||||
</t-checkbox>
|
||||
<p class="form-desc">{{ $t(`integrations.mcpserver.tools.${tool.name}Desc`) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="selectedToolCount === 0" class="form-desc form-desc--error">{{ $t('integrations.mcpserver.toolsRequired') }}</p>
|
||||
</section>
|
||||
|
||||
<section v-if="askSelected" class="setting-drawer__section">
|
||||
<h4 class="setting-drawer__section-title">{{ $t('integrations.mcpserver.sectionAsk') }}</h4>
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ $t('integrations.mcpserver.defaultAgentLabel') }}</label>
|
||||
<t-select
|
||||
v-model="form.default_agent_id"
|
||||
filterable
|
||||
clearable
|
||||
:loading="agentsLoading"
|
||||
:options="agentOptions"
|
||||
:placeholder="$t('integrations.mcpserver.defaultAgentPlaceholder')"
|
||||
/>
|
||||
<p class="form-desc">{{ $t('integrations.mcpserver.defaultAgentHint') }}</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="setting-drawer__section">
|
||||
<h4 class="setting-drawer__section-title">{{ $t('integrations.mcpserver.sectionLimits') }}</h4>
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ $t('integrations.mcpserver.rateLimitLabel') }}</label>
|
||||
<t-input-number v-model="form.rate_limit_per_minute" class="form-number" :min="1" :max="6000" theme="column" />
|
||||
<p class="form-desc">{{ $t('integrations.mcpserver.rateLimitHint') }}</p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- Step 2: connection (token shown once right after create / rotate) -->
|
||||
<div v-else-if="editing" class="im-step-body">
|
||||
<section class="setting-drawer__section">
|
||||
<h4 class="setting-drawer__section-title">{{ $t('integrations.mcpserver.sectionConnect') }}</h4>
|
||||
<t-alert v-if="freshToken" theme="warning" :message="$t('integrations.mcpserver.tokenOnce')" class="connect-alert" />
|
||||
<p v-else class="form-desc form-desc--block">
|
||||
{{ $t('integrations.mcpserver.connectHintExisting', { hint: editing.token_hint }) }}
|
||||
</p>
|
||||
|
||||
<div v-if="freshToken" class="form-item">
|
||||
<label class="form-label">{{ $t('integrations.mcpserver.tokenLabel') }}</label>
|
||||
<div class="code-toolbar">
|
||||
<pre class="code-toolbar__code">{{ freshToken }}</pre>
|
||||
<t-button class="code-toolbar__copy" size="small" variant="text" shape="square" :title="$t('common.copy')" @click="copyText(freshToken)">
|
||||
<t-icon name="file-copy" size="16px" />
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ $t('integrations.mcpserver.urlLabel') }}</label>
|
||||
<div class="code-toolbar">
|
||||
<pre class="code-toolbar__code">{{ endpointUrl(editing) }}</pre>
|
||||
<t-button class="code-toolbar__copy" size="small" variant="text" shape="square" :title="$t('common.copy')" @click="copyText(endpointUrl(editing))">
|
||||
<t-icon name="file-copy" size="16px" />
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">{{ $t('integrations.mcpserver.snippetsLabel') }}</label>
|
||||
<p v-if="!freshToken" class="form-desc form-desc--block">{{ $t('integrations.mcpserver.connectPlaceholderHint') }}</p>
|
||||
<t-tabs v-model="snippetTab" size="medium" class="snippet-tabs">
|
||||
<t-tab-panel v-for="snippet in connectSnippets" :key="snippet.key" :value="snippet.key" :label="$t(`integrations.mcpserver.snippet.${snippet.key}Title`)">
|
||||
<p class="form-desc form-desc--block">{{ $t(`integrations.mcpserver.snippet.${snippet.key}Desc`) }}</p>
|
||||
<div class="code-toolbar">
|
||||
<pre class="code-toolbar__code">{{ snippet.text }}</pre>
|
||||
<t-button class="code-toolbar__copy" size="small" variant="text" shape="square" :title="$t('common.copy')" @click="copyText(snippet.text)">
|
||||
<t-icon name="file-copy" size="16px" />
|
||||
</t-button>
|
||||
</div>
|
||||
</t-tab-panel>
|
||||
</t-tabs>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</SettingDrawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { copyWithToast } from '@/utils/clipboard'
|
||||
import { useApiBaseUrlDisplay } from '@/composables/useApiBaseUrlDisplay'
|
||||
import SettingDrawer from '@/components/settings/SettingDrawer.vue'
|
||||
import type { CustomAgent } from '@/api/agent'
|
||||
import { useChatResourcesStore } from '@/stores/chatResources'
|
||||
import { useOrganizationStore } from '@/stores/organization'
|
||||
import {
|
||||
createMcpEndpoint,
|
||||
deleteMcpEndpoint,
|
||||
getMcpEndpointToolCatalog,
|
||||
listMcpEndpoints,
|
||||
rotateMcpEndpointToken,
|
||||
updateMcpEndpoint,
|
||||
type McpEndpoint,
|
||||
type McpEndpointPayload,
|
||||
type McpEndpointToolCatalog,
|
||||
} from '@/api/mcp-endpoint'
|
||||
import {
|
||||
buildClaudeCodeCommand,
|
||||
buildHttpClientSnippet,
|
||||
buildMcpEndpointUrl,
|
||||
buildStdioBridgeSnippet,
|
||||
groupTools,
|
||||
} from './mcpServerIntegration'
|
||||
|
||||
const { t } = useI18n()
|
||||
const authStore = useAuthStore()
|
||||
const chatResources = useChatResourcesStore()
|
||||
const orgStore = useOrganizationStore()
|
||||
const { apiBaseUrlDisplay } = useApiBaseUrlDisplay()
|
||||
|
||||
const isAdmin = computed(() => authStore.hasRole('admin'))
|
||||
|
||||
const loading = ref(false)
|
||||
const endpoints = ref<McpEndpoint[]>([])
|
||||
const catalog = ref<McpEndpointToolCatalog>({ groups: [], tools: [], default_tools: [] })
|
||||
|
||||
const kbLoading = ref(false)
|
||||
const knowledgeBases = ref<{ id: string; name: string }[]>([])
|
||||
const kbOptions = computed(() => knowledgeBases.value.map((kb) => ({ label: kb.name || kb.id, value: kb.id })))
|
||||
const kbNameById = computed(() => Object.fromEntries(knowledgeBases.value.map((kb) => [kb.id, kb.name || kb.id])))
|
||||
|
||||
const agentsLoading = ref(false)
|
||||
const agents = ref<CustomAgent[]>([])
|
||||
const agentOptions = computed(() => agents.value.map((a) => ({ label: a.name, value: a.id })))
|
||||
|
||||
const showDrawer = ref(false)
|
||||
const saving = ref(false)
|
||||
const editing = ref<McpEndpoint | null>(null)
|
||||
const wizardStep = ref(0)
|
||||
const snippetTab = ref('http')
|
||||
// Plaintext token from the create / rotate response; shown once on step 2.
|
||||
const freshToken = ref('')
|
||||
|
||||
const stepTitles = computed(() => [
|
||||
t('integrations.mcpserver.stepConfig'),
|
||||
t('integrations.mcpserver.stepConnect'),
|
||||
])
|
||||
const drawerStepDescription = computed(() => {
|
||||
if (wizardStep.value === 0) return t('integrations.mcpserver.drawerDesc')
|
||||
return freshToken.value
|
||||
? t('integrations.mcpserver.tokenDialogTitle')
|
||||
: t('integrations.mcpserver.connectDialogTitle')
|
||||
})
|
||||
const drawerConfirmText = computed(() => {
|
||||
if (wizardStep.value > 0) return t('common.finish')
|
||||
return editing.value ? t('common.save') : t('integrations.mcpserver.create')
|
||||
})
|
||||
const form = reactive({
|
||||
name: '',
|
||||
description: '',
|
||||
enabled: true,
|
||||
knowledge_base_ids: [] as string[],
|
||||
default_agent_id: '',
|
||||
rate_limit_per_minute: 60,
|
||||
})
|
||||
const toolSelections = reactive<Record<string, boolean>>({})
|
||||
|
||||
const groupedTools = computed(() => groupTools(catalog.value.groups, catalog.value.tools))
|
||||
const selectedToolNames = computed(() => catalog.value.tools.filter((tl) => toolSelections[tl.name]).map((tl) => tl.name))
|
||||
const selectedToolCount = computed(() => selectedToolNames.value.length)
|
||||
const askSelected = computed(() => toolSelections.ask === true)
|
||||
|
||||
const connectSnippets = computed(() => {
|
||||
const ep = editing.value
|
||||
if (!ep) return []
|
||||
const url = endpointUrl(ep)
|
||||
return [
|
||||
{ key: 'http', text: buildHttpClientSnippet(ep.name, url, freshToken.value, ep.id) },
|
||||
{ key: 'claudeCode', text: buildClaudeCodeCommand(ep.name, url, freshToken.value, ep.id) },
|
||||
{ key: 'stdio', text: buildStdioBridgeSnippet(ep.name, url, freshToken.value, ep.id) },
|
||||
]
|
||||
})
|
||||
|
||||
function endpointUrl(ep: McpEndpoint): string {
|
||||
return buildMcpEndpointUrl(apiBaseUrlDisplay.value, ep.path)
|
||||
}
|
||||
|
||||
function scopeLabel(ep: McpEndpoint): string {
|
||||
if (!ep.knowledge_base_ids?.length) return t('integrations.mcpserver.scopeAll')
|
||||
return t('integrations.mcpserver.scopeCount', { count: ep.knowledge_base_ids.length })
|
||||
}
|
||||
|
||||
function setToolSelected(name: string, selected: boolean) {
|
||||
toolSelections[name] = selected
|
||||
}
|
||||
|
||||
function groupAllSelected(group: { tools: { name: string }[] }) {
|
||||
return group.tools.every((tl) => toolSelections[tl.name])
|
||||
}
|
||||
|
||||
function toggleGroup(group: { tools: { name: string }[] }, selected: boolean) {
|
||||
for (const tl of group.tools) toolSelections[tl.name] = selected
|
||||
}
|
||||
|
||||
function resetForm(ep: McpEndpoint | null) {
|
||||
form.name = ep?.name ?? ''
|
||||
form.description = ep?.description ?? ''
|
||||
form.enabled = ep?.enabled ?? true
|
||||
form.knowledge_base_ids = [...(ep?.knowledge_base_ids ?? [])]
|
||||
form.default_agent_id = ep?.default_agent_id ?? ''
|
||||
form.rate_limit_per_minute = ep?.rate_limit_per_minute || 60
|
||||
const selected = new Set(ep ? ep.tools : catalog.value.default_tools)
|
||||
for (const key of Object.keys(toolSelections)) delete toolSelections[key]
|
||||
for (const tl of catalog.value.tools) toolSelections[tl.name] = selected.has(tl.name)
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const [epRes, catRes] = await Promise.all([listMcpEndpoints(), getMcpEndpointToolCatalog()])
|
||||
endpoints.value = epRes?.data ?? []
|
||||
catalog.value = catRes?.data ?? { groups: [], tools: [], default_tools: [] }
|
||||
} catch (err: any) {
|
||||
MessagePlugin.error(err?.message || t('integrations.mcpserver.loadFailed'))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadOptions() {
|
||||
kbLoading.value = true
|
||||
agentsLoading.value = true
|
||||
try {
|
||||
// 刷新失败时给空列表,而不是把上一次的共享快照当成本次结果展示。
|
||||
const [kbResult, sharedKbResult, agentResult] = await Promise.allSettled([
|
||||
chatResources.ensureKnowledgeBases(),
|
||||
orgStore.fetchSharedKnowledgeBases(),
|
||||
chatResources.ensureAgents(),
|
||||
])
|
||||
const kbRows = kbResult.status === 'fulfilled'
|
||||
? (chatResources.rawKnowledgeBases as Array<{ id: string | number; name?: string }>)
|
||||
: []
|
||||
const myKbs = kbRows.map((kb) => ({ id: String(kb.id), name: kb.name || String(kb.id) }))
|
||||
const sharedKbs = sharedKbResult.status === 'fulfilled' && !orgStore.error
|
||||
? orgStore.sharedKnowledgeBases.flatMap((shared) => {
|
||||
const kb = shared.knowledge_base
|
||||
return kb ? [{ id: String(kb.id), name: kb.name || String(kb.id) }] : []
|
||||
})
|
||||
: []
|
||||
const myKbIds = new Set(myKbs.map((kb) => kb.id))
|
||||
knowledgeBases.value = [...myKbs, ...sharedKbs.filter((kb) => !myKbIds.has(kb.id))]
|
||||
agents.value = agentResult.status === 'fulfilled' ? (chatResources.agents as CustomAgent[]) : []
|
||||
} finally {
|
||||
kbLoading.value = false
|
||||
agentsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
editing.value = null
|
||||
freshToken.value = ''
|
||||
wizardStep.value = 0
|
||||
resetForm(null)
|
||||
showDrawer.value = true
|
||||
void loadOptions()
|
||||
}
|
||||
|
||||
function openEdit(ep: McpEndpoint, step: 0 | 1 = 0, token = '') {
|
||||
editing.value = ep
|
||||
freshToken.value = token
|
||||
wizardStep.value = step
|
||||
snippetTab.value = 'http'
|
||||
resetForm(ep)
|
||||
showDrawer.value = true
|
||||
if (step === 0) void loadOptions()
|
||||
}
|
||||
|
||||
function goToWizardStep(step: number) {
|
||||
if (step < 0 || step >= stepTitles.value.length) return
|
||||
if (step > 0 && !editing.value) return
|
||||
wizardStep.value = step
|
||||
}
|
||||
|
||||
function closeDrawer() {
|
||||
showDrawer.value = false
|
||||
freshToken.value = ''
|
||||
}
|
||||
|
||||
function handleDrawerConfirm() {
|
||||
if (wizardStep.value > 0) {
|
||||
closeDrawer()
|
||||
return
|
||||
}
|
||||
void saveForm()
|
||||
}
|
||||
|
||||
function buildPayload(): McpEndpointPayload {
|
||||
return {
|
||||
name: form.name.trim(),
|
||||
description: form.description.trim(),
|
||||
enabled: form.enabled,
|
||||
knowledge_base_ids: [...form.knowledge_base_ids],
|
||||
tools: [...selectedToolNames.value],
|
||||
default_agent_id: askSelected.value ? form.default_agent_id : '',
|
||||
rate_limit_per_minute: form.rate_limit_per_minute,
|
||||
}
|
||||
}
|
||||
|
||||
async function saveForm() {
|
||||
if (!form.name.trim()) {
|
||||
MessagePlugin.warning(t('integrations.mcpserver.nameRequired'))
|
||||
return
|
||||
}
|
||||
if (selectedToolCount.value === 0) {
|
||||
MessagePlugin.warning(t('integrations.mcpserver.toolsRequired'))
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
const payload = buildPayload()
|
||||
if (editing.value) {
|
||||
await updateMcpEndpoint(editing.value.id, payload)
|
||||
MessagePlugin.success(t('integrations.mcpserver.updated'))
|
||||
showDrawer.value = false
|
||||
await load()
|
||||
} else {
|
||||
const res = await createMcpEndpoint(payload)
|
||||
MessagePlugin.success(t('integrations.mcpserver.created'))
|
||||
await load()
|
||||
// Stay in the drawer and move to the connection step so the one-time
|
||||
// token is read in place instead of in a second, taller dialog.
|
||||
if (res?.data) openEdit(res.data, 1, res.data.token || '')
|
||||
}
|
||||
} catch (err: any) {
|
||||
MessagePlugin.error(err?.message || t('integrations.mcpserver.saveFailed'))
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function removeEndpoint(ep: McpEndpoint) {
|
||||
try {
|
||||
await deleteMcpEndpoint(ep.id)
|
||||
MessagePlugin.success(t('integrations.mcpserver.deleted'))
|
||||
await load()
|
||||
} catch (err: any) {
|
||||
MessagePlugin.error(err?.message || t('integrations.mcpserver.deleteFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
async function rotateToken(ep: McpEndpoint) {
|
||||
try {
|
||||
const res = await rotateMcpEndpointToken(ep.id)
|
||||
MessagePlugin.success(t('integrations.mcpserver.rotated'))
|
||||
await load()
|
||||
if (res?.data) openEdit(res.data, 1, res.data.token || '')
|
||||
} catch (err: any) {
|
||||
MessagePlugin.error(err?.message || t('integrations.mcpserver.rotateFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleEnabled(ep: McpEndpoint) {
|
||||
try {
|
||||
await updateMcpEndpoint(ep.id, { enabled: !ep.enabled })
|
||||
MessagePlugin.success(ep.enabled ? t('integrations.mcpserver.disabledToast') : t('integrations.mcpserver.enabledToast'))
|
||||
await load()
|
||||
} catch (err: any) {
|
||||
MessagePlugin.error(err?.message || t('integrations.mcpserver.saveFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
function menuOptions(ep: McpEndpoint) {
|
||||
return [
|
||||
{ content: t('integrations.mcpserver.menuConnect'), value: 'connect' },
|
||||
{ content: ep.enabled ? t('integrations.mcpserver.menuDisable') : t('integrations.mcpserver.menuEnable'), value: 'toggle' },
|
||||
{ content: t('integrations.mcpserver.menuRotate'), value: 'rotate' },
|
||||
]
|
||||
}
|
||||
|
||||
function handleMenuClick(option: { value?: string | number }, ep: McpEndpoint) {
|
||||
switch (option?.value) {
|
||||
case 'connect':
|
||||
openEdit(ep, 1)
|
||||
break
|
||||
case 'toggle':
|
||||
void toggleEnabled(ep)
|
||||
break
|
||||
case 'rotate':
|
||||
void rotateToken(ep)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const copyText = (text: string) => copyWithToast(text, 'integrations.mcpserver.copied')
|
||||
|
||||
onMounted(() => {
|
||||
void load()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@import '../../components/css/channel-panel-list.less';
|
||||
|
||||
.mcp-server-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
font-size: var(--app-text-md);
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-primary);
|
||||
line-height: 1.4;
|
||||
|
||||
&--inline {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
&.required::after {
|
||||
content: ' *';
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
}
|
||||
|
||||
.form-desc {
|
||||
margin: 4px 0 0;
|
||||
font-size: var(--app-text-sm);
|
||||
line-height: 1.45;
|
||||
color: var(--td-text-color-placeholder);
|
||||
|
||||
&--block {
|
||||
margin: -2px 0 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
&--error {
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
}
|
||||
|
||||
.form-number {
|
||||
width: 100%;
|
||||
max-width: 200px;
|
||||
}
|
||||
|
||||
.enable-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.tool-group-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.tool-group {
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-md);
|
||||
padding: 10px 12px;
|
||||
}
|
||||
|
||||
.tool-group__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.tool-group__name {
|
||||
font-size: var(--app-text-md);
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.tool-group__items {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.tool-item {
|
||||
padding-left: 2px;
|
||||
|
||||
.form-desc {
|
||||
margin-left: 24px;
|
||||
}
|
||||
|
||||
&--danger .tool-item__label {
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
}
|
||||
|
||||
.tool-item__code {
|
||||
margin-left: 6px;
|
||||
font-size: var(--app-text-xs);
|
||||
color: var(--td-text-color-placeholder);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
padding: 1px 5px;
|
||||
border-radius: var(--app-radius-xs);
|
||||
}
|
||||
|
||||
.code-toolbar {
|
||||
position: relative;
|
||||
margin: 6px 0 10px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-md);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
}
|
||||
|
||||
.code-toolbar__code {
|
||||
margin: 0;
|
||||
padding: 10px 40px 10px 12px;
|
||||
font-family: var(--td-font-family-mono);
|
||||
font-size: var(--app-text-sm);
|
||||
line-height: 1.5;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.code-toolbar__copy {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 6px;
|
||||
}
|
||||
|
||||
.connect-alert {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.snippet-tabs {
|
||||
margin-top: 4px;
|
||||
|
||||
:deep(.t-tabs__content) {
|
||||
padding-top: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Step rail, aligned with the embed / IM channel drawers. */
|
||||
.im-steps {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
padding-bottom: 12px;
|
||||
}
|
||||
|
||||
.im-step {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: var(--app-text-sm);
|
||||
color: var(--td-text-color-placeholder);
|
||||
padding: 0;
|
||||
border: none;
|
||||
background: transparent;
|
||||
font-family: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
cursor: default;
|
||||
}
|
||||
}
|
||||
|
||||
.im-step-title {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.im-step.active {
|
||||
color: var(--td-brand-color);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.im-step.done {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.im-step-num {
|
||||
flex-shrink: 0;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: var(--app-text-xs);
|
||||
font-weight: 600;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
color: var(--td-text-color-placeholder);
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.im-step.active .im-step-num {
|
||||
background: var(--td-brand-color);
|
||||
color: #fff;
|
||||
border-color: var(--td-brand-color);
|
||||
}
|
||||
|
||||
.im-step.done .im-step-num {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
color: var(--td-brand-color);
|
||||
border-color: var(--td-component-stroke);
|
||||
}
|
||||
|
||||
.im-step-check {
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
|
||||
.im-step-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,26 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import { normalizeAPIKeyKnowledgeBaseIDs } from './apiKeyScope.ts'
|
||||
|
||||
/**
|
||||
* 验证完全授权 Key 的 null/undefined 范围会转换为空数组,避免列表渲染读取 length 时白屏。
|
||||
* 传入服务端可能返回的空值,期望返回表示“全部知识库”的空数组。
|
||||
*/
|
||||
test('normalizes missing API key knowledge base scope to an empty array', () => {
|
||||
assert.deepEqual(normalizeAPIKeyKnowledgeBaseIDs(null), [])
|
||||
assert.deepEqual(normalizeAPIKeyKnowledgeBaseIDs(undefined), [])
|
||||
})
|
||||
|
||||
/**
|
||||
* 验证 scoped Key 的知识库 ID 会被完整复制,且返回值不是原数组,避免编辑表单污染列表数据。
|
||||
* 传入两个知识库 ID,期望按原顺序返回一份新数组。
|
||||
*/
|
||||
test('copies configured API key knowledge base scope', () => {
|
||||
const ids = ['kb-1', 'kb-2']
|
||||
const normalized = normalizeAPIKeyKnowledgeBaseIDs(ids)
|
||||
|
||||
assert.deepEqual(normalized, ids)
|
||||
assert.notEqual(normalized, ids)
|
||||
assert.deepEqual(normalizeAPIKeyKnowledgeBaseIDs([]), [])
|
||||
})
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 将 API 返回的知识库范围归一化为前端表单可安全使用的数组。
|
||||
*
|
||||
* @param ids API Key 的知识库 ID;完全授权的 Key 可能由服务端返回 null。
|
||||
* @returns 一份新的知识库 ID 数组;null 或 undefined 返回空数组,表示全部知识库。
|
||||
*/
|
||||
export function normalizeAPIKeyKnowledgeBaseIDs(
|
||||
ids: readonly string[] | null | undefined,
|
||||
): string[] {
|
||||
return ids ? [...ids] : []
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import { consumeApiPlaygroundSSE } from './apiPlaygroundSSE.ts'
|
||||
|
||||
const encoder = new TextEncoder()
|
||||
|
||||
function streamFromChunks(chunks: string[], keepOpen = false) {
|
||||
let index = 0
|
||||
let cancelled = false
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
pull(controller) {
|
||||
if (index < chunks.length) {
|
||||
controller.enqueue(encoder.encode(chunks[index++]))
|
||||
} else if (!keepOpen) {
|
||||
controller.close()
|
||||
}
|
||||
},
|
||||
cancel() {
|
||||
cancelled = true
|
||||
},
|
||||
})
|
||||
return { stream, wasCancelled: () => cancelled }
|
||||
}
|
||||
|
||||
test('fails on a terminal error without waiting for the connection to close', async () => {
|
||||
const fixture = streamFromChunks([
|
||||
'event: message\ndata: {"response_type":"error","content":"synthetic provider failure","done":true}\n\n',
|
||||
], true)
|
||||
|
||||
const result = await Promise.race([
|
||||
consumeApiPlaygroundSSE(fixture.stream),
|
||||
new Promise<never>((_, reject) => setTimeout(() => reject(new Error('timed out')), 200)),
|
||||
])
|
||||
|
||||
assert.equal(result.status, 'failed')
|
||||
assert.equal(result.error, 'synthetic provider failure')
|
||||
assert.equal(fixture.wasCancelled(), true)
|
||||
})
|
||||
|
||||
test('accepts current, legacy, and sentinel completion events', async (t) => {
|
||||
const cases = [
|
||||
{
|
||||
name: 'complete event',
|
||||
sse: 'data: {"response_type":"answer","content":"current","done":false}\n\ndata: {"response_type":"complete","content":"","done":true}\n\n',
|
||||
answer: 'current',
|
||||
},
|
||||
{
|
||||
name: 'legacy done event',
|
||||
sse: 'data: {"response_type":"answer","content":"legacy","done":true}\n\n',
|
||||
answer: 'legacy',
|
||||
},
|
||||
{
|
||||
name: 'DONE sentinel',
|
||||
sse: 'data: {"response_type":"answer","content":"sentinel","done":false}\n\ndata: [DONE]\n\n',
|
||||
answer: 'sentinel',
|
||||
},
|
||||
]
|
||||
|
||||
for (const fixture of cases) {
|
||||
await t.test(fixture.name, async () => {
|
||||
const result = await consumeApiPlaygroundSSE(streamFromChunks([fixture.sse], true).stream)
|
||||
assert.equal(result.status, 'success')
|
||||
assert.equal(result.answer, fixture.answer)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
test('does not treat another event type done marker as stream completion', async () => {
|
||||
const result = await consumeApiPlaygroundSSE(streamFromChunks([
|
||||
'data: {"response_type":"thinking","content":"thought","done":true}\n\n'
|
||||
+ 'data: {"response_type":"answer","content":"answer","done":false}\n\n'
|
||||
+ 'data: {"response_type":"complete","content":"","done":true}\n\n',
|
||||
]).stream)
|
||||
|
||||
assert.equal(result.status, 'success')
|
||||
assert.equal(result.answer, 'answer')
|
||||
})
|
||||
|
||||
test('ignores frames after a terminal event', async () => {
|
||||
const fixture = streamFromChunks([
|
||||
'data: {"response_type":"answer","content":"before","done":false}\n\n'
|
||||
+ 'data: {"response_type":"complete","content":"","done":true}\n\n',
|
||||
'data: {"response_type":"answer","content":"after","done":false}\n\n',
|
||||
], true)
|
||||
const result = await consumeApiPlaygroundSSE(fixture.stream)
|
||||
|
||||
assert.equal(result.status, 'success')
|
||||
assert.equal(result.answer, 'before')
|
||||
assert.equal(fixture.wasCancelled(), true)
|
||||
})
|
||||
|
||||
test('reports EOF without a business terminal event as failure', async () => {
|
||||
const result = await consumeApiPlaygroundSSE(streamFromChunks([
|
||||
'data: {"response_type":"answer","content":"partial","done":false}\n\n',
|
||||
]).stream)
|
||||
|
||||
assert.equal(result.status, 'failed')
|
||||
assert.equal(result.reason, 'unexpected-eof')
|
||||
assert.equal(result.answer, 'partial')
|
||||
})
|
||||
|
||||
test('keeps valid non-object JSON visible without crashing the parser', async () => {
|
||||
const result = await consumeApiPlaygroundSSE(streamFromChunks([
|
||||
'data: null\n\ndata: {"response_type":"complete","content":"","done":true}\n\n',
|
||||
]).stream)
|
||||
|
||||
assert.equal(result.status, 'success')
|
||||
assert.match(result.raw, /data: null/)
|
||||
})
|
||||
|
||||
test('reassembles an SSE frame split across network chunks', async () => {
|
||||
const result = await consumeApiPlaygroundSSE(streamFromChunks([
|
||||
'event: message\ndata: {"response_type":"ans',
|
||||
'wer","content":"split","done":false}\n',
|
||||
'\ndata: {"response_type":"complete","content":"","done":tr',
|
||||
'ue}\n\n',
|
||||
]).stream)
|
||||
|
||||
assert.equal(result.status, 'success')
|
||||
assert.equal(result.answer, 'split')
|
||||
})
|
||||
|
||||
test('supports CRLF frames and joins multiple data lines', async () => {
|
||||
const result = await consumeApiPlaygroundSSE(streamFromChunks([
|
||||
'event: message\r\ndata: {"response_type":"answer",\r\n'
|
||||
+ 'data: "content":"multiline","done":false}\r\n\r\n'
|
||||
+ 'data: {"response_type":"complete","content":"","done":true}\r\n\r\n',
|
||||
]).stream)
|
||||
|
||||
assert.equal(result.status, 'success')
|
||||
assert.equal(result.answer, 'multiline')
|
||||
})
|
||||
@@ -0,0 +1,149 @@
|
||||
export interface ApiPlaygroundSSEProgress {
|
||||
raw: string
|
||||
answer: string
|
||||
}
|
||||
|
||||
export type ApiPlaygroundSSEResult = ApiPlaygroundSSEProgress & (
|
||||
| { status: 'success' }
|
||||
| { status: 'failed'; reason: 'terminal-error' | 'unexpected-eof'; error?: string }
|
||||
)
|
||||
|
||||
interface TerminalState {
|
||||
status: 'success' | 'failed'
|
||||
error?: string
|
||||
}
|
||||
|
||||
interface StreamEventPayload {
|
||||
response_type?: unknown
|
||||
type?: unknown
|
||||
content?: unknown
|
||||
message?: unknown
|
||||
error?: unknown
|
||||
done?: unknown
|
||||
}
|
||||
|
||||
function readErrorMessage(payload: StreamEventPayload): string | undefined {
|
||||
if (typeof payload.content === 'string' && payload.content.trim()) return payload.content
|
||||
if (typeof payload.message === 'string' && payload.message.trim()) return payload.message
|
||||
if (typeof payload.error === 'string' && payload.error.trim()) return payload.error
|
||||
if (
|
||||
payload.error
|
||||
&& typeof payload.error === 'object'
|
||||
&& 'message' in payload.error
|
||||
&& typeof payload.error.message === 'string'
|
||||
&& payload.error.message.trim()
|
||||
) {
|
||||
return payload.error.message
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
function readEventData(frame: string): string | undefined {
|
||||
const dataLines: string[] = []
|
||||
for (const line of frame.split(/\r?\n/)) {
|
||||
if (line === 'data') {
|
||||
dataLines.push('')
|
||||
} else if (line.startsWith('data:')) {
|
||||
const value = line.slice(5)
|
||||
dataLines.push(value.startsWith(' ') ? value.slice(1) : value)
|
||||
}
|
||||
}
|
||||
return dataLines.length ? dataLines.join('\n') : undefined
|
||||
}
|
||||
|
||||
function applyFrame(frame: string, answerChunks: string[]): TerminalState | undefined {
|
||||
const data = readEventData(frame)
|
||||
if (data === undefined) return undefined
|
||||
if (data.trim() === '[DONE]') return { status: 'success' }
|
||||
|
||||
let payload: StreamEventPayload
|
||||
try {
|
||||
const parsed: unknown = JSON.parse(data)
|
||||
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return undefined
|
||||
payload = parsed as StreamEventPayload
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const responseType = payload.response_type ?? payload.type
|
||||
if (responseType === 'answer' && typeof payload.content === 'string') {
|
||||
answerChunks.push(payload.content)
|
||||
}
|
||||
if (responseType === 'error') {
|
||||
return { status: 'failed', error: readErrorMessage(payload) }
|
||||
}
|
||||
if (responseType === 'complete' || (responseType === 'answer' && payload.done === true)) {
|
||||
return { status: 'success' }
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Consume an API Playground SSE stream until its business-level terminal event.
|
||||
* The parser owns chunk buffering and terminal-state reduction so callers never
|
||||
* need to infer success from the transport reaching EOF.
|
||||
*/
|
||||
export async function consumeApiPlaygroundSSE(
|
||||
stream: ReadableStream<Uint8Array>,
|
||||
onProgress?: (progress: ApiPlaygroundSSEProgress) => void,
|
||||
): Promise<ApiPlaygroundSSEResult> {
|
||||
const reader = stream.getReader()
|
||||
const decoder = new TextDecoder()
|
||||
const answerChunks: string[] = []
|
||||
let raw = ''
|
||||
let buffer = ''
|
||||
|
||||
const progress = () => {
|
||||
const value = { raw, answer: answerChunks.join('') }
|
||||
onProgress?.(value)
|
||||
return value
|
||||
}
|
||||
|
||||
const consumeFrames = (flush = false): TerminalState | undefined => {
|
||||
while (true) {
|
||||
const boundary = buffer.match(/\r?\n\r?\n/)
|
||||
if (!boundary || boundary.index === undefined) break
|
||||
const frame = buffer.slice(0, boundary.index)
|
||||
buffer = buffer.slice(boundary.index + boundary[0].length)
|
||||
const terminal = applyFrame(frame, answerChunks)
|
||||
if (terminal) return terminal
|
||||
}
|
||||
if (flush && buffer) {
|
||||
const terminal = applyFrame(buffer, answerChunks)
|
||||
buffer = ''
|
||||
return terminal
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
const finish = (terminal: TerminalState): ApiPlaygroundSSEResult => {
|
||||
const value = progress()
|
||||
if (terminal.status === 'failed') {
|
||||
return { ...value, status: 'failed', reason: 'terminal-error', error: terminal.error }
|
||||
}
|
||||
return { ...value, status: 'success' }
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read()
|
||||
if (done) {
|
||||
const tail = decoder.decode()
|
||||
raw += tail
|
||||
buffer += tail
|
||||
const terminal = consumeFrames(true)
|
||||
if (terminal) return finish(terminal)
|
||||
const value = progress()
|
||||
return { ...value, status: 'failed', reason: 'unexpected-eof' }
|
||||
}
|
||||
|
||||
const chunk = decoder.decode(value, { stream: true })
|
||||
raw += chunk
|
||||
buffer += chunk
|
||||
const terminal = consumeFrames()
|
||||
if (terminal) {
|
||||
void reader.cancel().catch(() => undefined)
|
||||
return finish(terminal)
|
||||
}
|
||||
progress()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { buildCLIConnectCommand } from './cliIntegration'
|
||||
|
||||
test('CLI hosts preserve proxy prefixes and omit the SDK API suffix', () => {
|
||||
for (const [base, origin, host] of [
|
||||
['https://kb.example.com/api/v1', 'https://ui.example.com', 'https://kb.example.com'],
|
||||
['/app/weknora/api/v1', 'https://kb.example.com', 'https://kb.example.com/app/weknora'],
|
||||
['http://127.0.0.1:19321/api/v1/', 'wails://wails.localhost', 'http://127.0.0.1:19321'],
|
||||
['http://127.0.0.1:19321/api/v1', 'null', 'http://127.0.0.1:19321'],
|
||||
]) {
|
||||
const command = buildCLIConnectCommand(base!, origin!)
|
||||
assert.ok(command.includes(`--host '${host}' --use &&\nweknora auth login`))
|
||||
}
|
||||
})
|
||||
|
||||
test('unresolved desktop URLs use an explicit server placeholder', () => {
|
||||
assert.ok(buildCLIConnectCommand('/api/v1', 'null').includes("--host 'https://your-server.com'"))
|
||||
assert.ok(buildCLIConnectCommand('/api/v1', 'wails://wails.localhost').includes("--host 'https://your-server.com'"))
|
||||
})
|
||||
|
||||
test('copyable host arguments remain literal in a POSIX shell', () => {
|
||||
const host = "https://kb.example.com/team'/$HOME/`printf-injected`/$(printf-injected)"
|
||||
const command = buildCLIConnectCommand(`${host}/api/v1`, 'https://kb.example.com')
|
||||
const argument = command.split(' --host ')[1]!.split(' --use')[0]!
|
||||
const result = spawnSync('/bin/sh', ['-c', `printf '%s' ${argument}`], { encoding: 'utf8' })
|
||||
assert.equal(result.status, 0)
|
||||
assert.equal(result.stderr, '')
|
||||
assert.equal(result.stdout, "https://kb.example.com/team'/$HOME/%60printf-injected%60/$(printf-injected)")
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
/** The CLI appends /api/v1 itself; retain any reverse-proxy path prefix. */
|
||||
export function buildCLIConnectCommand(apiBaseUrl: string, origin: string): string {
|
||||
let host = 'https://your-server.com'
|
||||
try {
|
||||
const url = new URL(apiBaseUrl, origin && origin !== 'null' ? origin : undefined)
|
||||
if (url.protocol === 'https:' || url.protocol === 'http:') {
|
||||
const path = url.pathname.replace(/\/+$/, '').replace(/\/api\/v1$/, '')
|
||||
host = `${url.origin}${path}`
|
||||
}
|
||||
} catch {
|
||||
// Desktop bindings can still be loading when the page first renders.
|
||||
}
|
||||
// POSIX shell quoting prevents URL characters from becoming shell syntax.
|
||||
const quotedHost = `'${host.replace(/'/g, `'"'"'`)}'`
|
||||
return `weknora profile add weknora --host ${quotedHost} --use &&\nweknora auth login`
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
@claw-accent: #e85d2a;
|
||||
@claw-accent-dark: #c44d1f;
|
||||
|
||||
.integration-landing {
|
||||
--integration-accent: var(--td-brand-color);
|
||||
container-type: inline-size;
|
||||
container-name: integration-landing;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
|
||||
&--claw { --integration-accent: @claw-accent-dark; }
|
||||
|
||||
.landing-hero {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
|
||||
&__top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
padding-right: 24px;
|
||||
}
|
||||
|
||||
&__title {
|
||||
margin: 0;
|
||||
font-size: var(--app-text-3xl);
|
||||
font-weight: 600;
|
||||
line-height: 28px;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
&__subtitle {
|
||||
margin: 0;
|
||||
font-size: var(--app-text-base);
|
||||
line-height: 1.5;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
&__tags { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
&__actions { display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
}
|
||||
|
||||
.ext-cta {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
max-width: 100%;
|
||||
min-height: 32px;
|
||||
padding: 0 10px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-sm);
|
||||
background: var(--td-bg-color-container);
|
||||
color: var(--td-text-color-primary);
|
||||
font: inherit;
|
||||
font-size: var(--app-text-md);
|
||||
cursor: pointer;
|
||||
|
||||
&:hover { background: var(--td-bg-color-container-hover); }
|
||||
&:focus-visible { outline: 2px solid var(--integration-accent); outline-offset: 2px; }
|
||||
&__badge, &__arrow-wrap {
|
||||
display: inline-flex; align-items: center; justify-content: center;
|
||||
flex-shrink: 0; width: 16px; height: 16px;
|
||||
}
|
||||
&__badge { color: var(--integration-accent); }
|
||||
&__label { line-height: 1.5; overflow-wrap: anywhere; }
|
||||
&__arrow { font-size: var(--app-text-base); color: var(--td-text-color-placeholder); }
|
||||
}
|
||||
.ext-cta-emoji { font-size: var(--app-text-xl); line-height: 1; }
|
||||
|
||||
.scenario-tag {
|
||||
padding: 2px 8px;
|
||||
border-radius: var(--app-radius-sm);
|
||||
font-size: var(--app-text-sm);
|
||||
line-height: 18px;
|
||||
color: var(--td-text-color-secondary);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
}
|
||||
|
||||
.landing-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
.landing-main, .landing-aside { min-width: 0; }
|
||||
|
||||
.landing-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 16px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-lg);
|
||||
background: var(--td-bg-color-container);
|
||||
|
||||
.setting-drawer__section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding: 16px 0;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
flex: none;
|
||||
animation: none;
|
||||
&:first-child { padding-top: 0; }
|
||||
&:last-child { padding-bottom: 0; border-bottom: none; }
|
||||
}
|
||||
.setting-drawer__section-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-lg);
|
||||
font-weight: 600;
|
||||
line-height: 22px;
|
||||
&::before { display: none; }
|
||||
}
|
||||
.section-head-extra {
|
||||
padding: 0 6px;
|
||||
border-radius: var(--app-radius-pill);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-xs);
|
||||
font-weight: 400;
|
||||
line-height: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
// 功能介绍采用图文条目,避免面板内再套大卡片。
|
||||
.capability-grid { display: flex; flex-direction: column; }
|
||||
.capability-card {
|
||||
display: grid;
|
||||
grid-template-columns: 28px minmax(0, 1fr);
|
||||
column-gap: 10px;
|
||||
row-gap: 3px;
|
||||
padding: 12px 0;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
&:first-child { padding-top: 0; }
|
||||
&:last-child { padding-bottom: 0; border-bottom: none; }
|
||||
&__icon {
|
||||
grid-row: 1 / 3;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: var(--app-radius-sm);
|
||||
background: color-mix(in srgb, var(--integration-accent) 8%, transparent);
|
||||
color: var(--integration-accent);
|
||||
.t-icon { font-size: var(--app-text-xl); }
|
||||
}
|
||||
&__title {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-md);
|
||||
font-weight: 500;
|
||||
line-height: 22px;
|
||||
}
|
||||
&__desc {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-sm);
|
||||
line-height: 1.6;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
}
|
||||
|
||||
.landing-steps { display: flex; flex-direction: column; list-style: none; margin: 0; padding: 0; }
|
||||
.landing-step {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
padding: 12px 0;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
&:first-child { padding-top: 0; }
|
||||
&:last-child { padding-bottom: 0; border-bottom: none; }
|
||||
}
|
||||
.landing-step-num {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 50%;
|
||||
font-size: var(--app-text-sm);
|
||||
font-weight: 500;
|
||||
color: var(--integration-accent);
|
||||
background: color-mix(in srgb, var(--integration-accent) 10%, transparent);
|
||||
}
|
||||
.landing-step-body { flex: 1; min-width: 0; }
|
||||
.landing-step-title {
|
||||
margin-bottom: 3px;
|
||||
font-size: var(--app-text-md);
|
||||
font-weight: 500;
|
||||
line-height: 22px;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
.landing-step-desc, .field-desc {
|
||||
margin: 0;
|
||||
font-size: var(--app-text-md);
|
||||
line-height: 1.6;
|
||||
overflow-wrap: anywhere;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
.landing-step-action, .landing-step-embed { margin-top: 8px; }
|
||||
|
||||
.api-key-control.landing-api-control {
|
||||
display: flex; align-items: center; gap: 4px; width: 100%;
|
||||
.t-input__wrap { flex: 1; min-width: 0; }
|
||||
.t-button { flex-shrink: 0; }
|
||||
input { font-family: var(--app-font-family-mono, monospace); font-size: var(--app-text-sm); }
|
||||
}
|
||||
.code-toolbar {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-sm);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
overflow: hidden;
|
||||
&__code {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
padding: 10px 12px;
|
||||
font-family: var(--app-font-family-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
|
||||
font-size: var(--app-text-sm);
|
||||
line-height: 1.6;
|
||||
color: var(--td-text-color-primary);
|
||||
overflow-x: auto;
|
||||
white-space: pre;
|
||||
background: transparent;
|
||||
}
|
||||
&__copy {
|
||||
flex-shrink: 0;
|
||||
margin: 4px;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
padding: 0 !important;
|
||||
}
|
||||
}
|
||||
.landing-footer { flex-shrink: 0; }
|
||||
.landing-footer-bar { display: flex; flex-direction: column; gap: 4px; }
|
||||
.landing-footer-bar__note, .landing-meta {
|
||||
margin: 0;
|
||||
font-size: var(--app-text-sm);
|
||||
line-height: 1.5;
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
@container integration-landing (max-width: 720px) {
|
||||
.landing-hero__top { align-items: flex-start; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import {
|
||||
buildClaudeCodeCommand,
|
||||
buildHttpClientSnippet,
|
||||
buildMcpEndpointUrl,
|
||||
buildStdioBridgeSnippet,
|
||||
groupTools,
|
||||
mcpServerKey,
|
||||
MCP_TOKEN_PLACEHOLDER,
|
||||
} from './mcpServerIntegration'
|
||||
|
||||
test('buildMcpEndpointUrl strips the api prefix and joins the endpoint path', () => {
|
||||
assert.equal(buildMcpEndpointUrl('https://kb.example.com/api/v1', '/mcp/abc'), 'https://kb.example.com/mcp/abc')
|
||||
assert.equal(buildMcpEndpointUrl('https://kb.example.com/api/v1/', 'mcp/abc'), 'https://kb.example.com/mcp/abc')
|
||||
assert.equal(buildMcpEndpointUrl('http://localhost:8080', '/mcp/x'), 'http://localhost:8080/mcp/x')
|
||||
})
|
||||
|
||||
test('mcpServerKey slugs the endpoint name', () => {
|
||||
assert.equal(mcpServerKey('Docs Bot!'), 'weknora-docs-bot')
|
||||
assert.equal(mcpServerKey(' '), 'weknora')
|
||||
assert.equal(mcpServerKey('产品知识库'), 'weknora')
|
||||
assert.equal(mcpServerKey('产品知识库', '3f9a2c1e-aaaa'), 'weknora-3f9a2c1e')
|
||||
assert.notEqual(mcpServerKey('知识库A', 'id-one'), mcpServerKey('知识库B', 'id-two'))
|
||||
})
|
||||
|
||||
test('http snippet carries url and bearer header', () => {
|
||||
const parsed = JSON.parse(buildHttpClientSnippet('Docs', 'https://h/mcp/1', 'mcp_t'))
|
||||
assert.deepEqual(parsed, {
|
||||
mcpServers: { 'weknora-docs': { url: 'https://h/mcp/1', headers: { Authorization: 'Bearer mcp_t' } } },
|
||||
})
|
||||
})
|
||||
|
||||
test('snippets fall back to a placeholder when no token is known', () => {
|
||||
assert.match(buildHttpClientSnippet('a', 'u', ''), new RegExp(MCP_TOKEN_PLACEHOLDER))
|
||||
assert.match(buildClaudeCodeCommand('a', 'u', ''), new RegExp(MCP_TOKEN_PLACEHOLDER))
|
||||
const bridge = JSON.parse(buildStdioBridgeSnippet('a', 'https://h/mcp/1', ''))
|
||||
assert.equal(bridge.mcpServers['weknora-a'].command, 'npx')
|
||||
assert.ok(bridge.mcpServers['weknora-a'].args.includes('https://h/mcp/1'))
|
||||
})
|
||||
|
||||
test('claude code command uses the http transport', () => {
|
||||
assert.equal(
|
||||
buildClaudeCodeCommand('Docs', 'https://h/mcp/1', 'mcp_t'),
|
||||
'claude mcp add --transport http weknora-docs https://h/mcp/1 --header "Authorization: Bearer mcp_t"',
|
||||
)
|
||||
})
|
||||
|
||||
test('groupTools keeps backend order and drops empty groups', () => {
|
||||
const grouped = groupTools(['retrieve', 'chat', 'wiki', 'ingest'], [
|
||||
{ name: 'ask', group: 'chat', destructive: false },
|
||||
{ name: 'search_knowledge', group: 'retrieve', destructive: false },
|
||||
{ name: 'delete_document', group: 'ingest', destructive: true },
|
||||
])
|
||||
assert.deepEqual(grouped.map((g) => g.group), ['retrieve', 'chat', 'ingest'])
|
||||
assert.deepEqual(grouped[0].tools.map((t) => t.name), ['search_knowledge'])
|
||||
})
|
||||
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* Pure helpers for the "WeKnora as MCP server" integration page. Kept free
|
||||
* of Vue so the snippet builders can be unit-tested with node:test.
|
||||
*/
|
||||
|
||||
export const MCP_TOKEN_PLACEHOLDER = '<YOUR_TOKEN>'
|
||||
|
||||
/**
|
||||
* Derive the public MCP URL from the displayed API base (".../api/v1") and
|
||||
* the endpoint path ("/mcp/<id>") returned by the backend.
|
||||
*/
|
||||
export function buildMcpEndpointUrl(apiBaseUrl: string, endpointPath: string): string {
|
||||
const base = (apiBaseUrl || '').trim().replace(/\/+$/, '').replace(/\/api\/v1$/, '')
|
||||
const path = endpointPath.startsWith('/') ? endpointPath : `/${endpointPath}`
|
||||
return `${base}${path}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize an endpoint name into an mcpServers key. Names that leave no
|
||||
* ASCII characters (e.g. Chinese) fall back to the endpoint id so two such
|
||||
* endpoints never collide in the client configuration.
|
||||
*/
|
||||
export function mcpServerKey(name: string, id = ''): string {
|
||||
const slug = (name || '')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/^-+|-+$/g, '')
|
||||
if (slug) return `weknora-${slug}`
|
||||
const idSlug = (id || '').replace(/[^a-z0-9]/gi, '').slice(0, 8).toLowerCase()
|
||||
return idSlug ? `weknora-${idSlug}` : 'weknora'
|
||||
}
|
||||
|
||||
/** JSON block for clients that speak Streamable HTTP natively (Cursor, VS Code, Claude Desktop connectors). */
|
||||
export function buildHttpClientSnippet(name: string, url: string, token: string, id = ''): string {
|
||||
return JSON.stringify(
|
||||
{
|
||||
mcpServers: {
|
||||
[mcpServerKey(name, id)]: {
|
||||
url,
|
||||
headers: { Authorization: `Bearer ${token || MCP_TOKEN_PLACEHOLDER}` },
|
||||
},
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
)
|
||||
}
|
||||
|
||||
/** One-liner for Claude Code. */
|
||||
export function buildClaudeCodeCommand(name: string, url: string, token: string, id = ''): string {
|
||||
const auth = `Authorization: Bearer ${token || MCP_TOKEN_PLACEHOLDER}`
|
||||
return `claude mcp add --transport http ${mcpServerKey(name, id)} ${url} --header "${auth}"`
|
||||
}
|
||||
|
||||
/** JSON block for stdio-only clients, bridged through mcp-remote. */
|
||||
export function buildStdioBridgeSnippet(name: string, url: string, token: string, id = ''): string {
|
||||
return JSON.stringify(
|
||||
{
|
||||
mcpServers: {
|
||||
[mcpServerKey(name, id)]: {
|
||||
command: 'npx',
|
||||
args: ['-y', 'mcp-remote', url, '--header', `Authorization: Bearer ${token || MCP_TOKEN_PLACEHOLDER}`],
|
||||
},
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
)
|
||||
}
|
||||
|
||||
export interface ToolCatalogEntry {
|
||||
name: string
|
||||
group: string
|
||||
destructive: boolean
|
||||
}
|
||||
|
||||
export interface GroupedTools<T extends ToolCatalogEntry> {
|
||||
group: string
|
||||
tools: T[]
|
||||
}
|
||||
|
||||
/** Group catalog entries in the backend's group order, dropping empty groups. */
|
||||
export function groupTools<T extends ToolCatalogEntry>(groups: string[], tools: T[]): GroupedTools<T>[] {
|
||||
const known = new Set(groups)
|
||||
const order = [...groups, ...tools.map((t) => t.group).filter((g) => !known.has(g))]
|
||||
const out: GroupedTools<T>[] = []
|
||||
for (const group of Array.from(new Set(order))) {
|
||||
const members = tools.filter((t) => t.group === group)
|
||||
if (members.length > 0) out.push({ group, tools: members })
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** Summarize a knowledge-base scope for the card: empty means "all". */
|
||||
export function summarizeScope(ids: string[] | null | undefined, names: Record<string, string>): string[] {
|
||||
return (ids || []).map((id) => names[id] || id)
|
||||
}
|
||||
Reference in new issue
Block a user