mirror of https://github.com/chaitin/PandaWiki.git
Compare commits
5 Commits
06ab54e39b
...
31f684cf81
| Author | SHA1 | Date |
|---|---|---|
|
|
31f684cf81 | |
|
|
f77c94d5fb | |
|
|
da9039ff37 | |
|
|
797e0c033d | |
|
|
ea6f958d24 |
|
|
@ -24,6 +24,7 @@ const (
|
|||
SourceTypeDiscordBot SourceType = "discord_bot"
|
||||
SourceTypeWechatOfficialAccount SourceType = "wechat_official_account"
|
||||
SourceTypeOpenAIAPI SourceType = "openai_api"
|
||||
SourceTypeMcpServer SourceType = "mcp_server"
|
||||
)
|
||||
|
||||
func (s SourceType) Name() string {
|
||||
|
|
@ -46,6 +47,8 @@ func (s SourceType) Name() string {
|
|||
return "Discord 机器人"
|
||||
case SourceTypeWechatOfficialAccount:
|
||||
return "微信公众号"
|
||||
case SourceTypeMcpServer:
|
||||
return "MCP 服务器"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
|
|
|
|||
|
|
@ -240,7 +240,8 @@ const docTemplate = `{
|
|||
"wechat_service_bot",
|
||||
"discord_bot",
|
||||
"wechat_official_account",
|
||||
"openai_api"
|
||||
"openai_api",
|
||||
"mcp_server"
|
||||
],
|
||||
"type": "string",
|
||||
"x-enum-varnames": [
|
||||
|
|
@ -260,7 +261,8 @@ const docTemplate = `{
|
|||
"SourceTypeWechatServiceBot",
|
||||
"SourceTypeDiscordBot",
|
||||
"SourceTypeWechatOfficialAccount",
|
||||
"SourceTypeOpenAIAPI"
|
||||
"SourceTypeOpenAIAPI",
|
||||
"SourceTypeMcpServer"
|
||||
],
|
||||
"name": "source_type",
|
||||
"in": "query",
|
||||
|
|
@ -4268,7 +4270,8 @@ const docTemplate = `{
|
|||
"wechat_service_bot",
|
||||
"discord_bot",
|
||||
"wechat_official_account",
|
||||
"openai_api"
|
||||
"openai_api",
|
||||
"mcp_server"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"SourceTypeDingTalk",
|
||||
|
|
@ -4287,7 +4290,8 @@ const docTemplate = `{
|
|||
"SourceTypeWechatServiceBot",
|
||||
"SourceTypeDiscordBot",
|
||||
"SourceTypeWechatOfficialAccount",
|
||||
"SourceTypeOpenAIAPI"
|
||||
"SourceTypeOpenAIAPI",
|
||||
"SourceTypeMcpServer"
|
||||
]
|
||||
},
|
||||
"consts.StatDay": {
|
||||
|
|
@ -4623,6 +4627,14 @@ const docTemplate = `{
|
|||
}
|
||||
]
|
||||
},
|
||||
"mcp_server_settings": {
|
||||
"description": "MCP Server Settings",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.MCPServerSettings"
|
||||
}
|
||||
]
|
||||
},
|
||||
"openai_api_bot_settings": {
|
||||
"description": "OpenAI API Bot settings",
|
||||
"allOf": [
|
||||
|
|
@ -4896,6 +4908,14 @@ const docTemplate = `{
|
|||
}
|
||||
]
|
||||
},
|
||||
"mcp_server_settings": {
|
||||
"description": "MCP Server Settings",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.MCPServerSettings"
|
||||
}
|
||||
]
|
||||
},
|
||||
"openai_api_bot_settings": {
|
||||
"description": "OpenAI API settings",
|
||||
"allOf": [
|
||||
|
|
@ -5056,7 +5076,8 @@ const docTemplate = `{
|
|||
8,
|
||||
9,
|
||||
10,
|
||||
11
|
||||
11,
|
||||
12
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"AppTypeWeb",
|
||||
|
|
@ -5069,7 +5090,8 @@ const docTemplate = `{
|
|||
"AppTypeWechatOfficialAccount",
|
||||
"AppTypeOpenAIAPI",
|
||||
"AppTypeWecomAIBot",
|
||||
"AppTypeLarkBot"
|
||||
"AppTypeLarkBot",
|
||||
"AppTypeMcpServer"
|
||||
]
|
||||
},
|
||||
"domain.AuthUserInfo": {
|
||||
|
|
@ -6378,6 +6400,31 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"domain.MCPServerSettings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"get_docs_tool_settings": {
|
||||
"$ref": "#/definitions/domain.MCPToolSettings"
|
||||
},
|
||||
"is_enabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"sample_auth": {
|
||||
"$ref": "#/definitions/domain.SimpleAuth"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.MCPToolSettings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"desc": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.MessageContent": {
|
||||
"type": "object"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -233,7 +233,8 @@
|
|||
"wechat_service_bot",
|
||||
"discord_bot",
|
||||
"wechat_official_account",
|
||||
"openai_api"
|
||||
"openai_api",
|
||||
"mcp_server"
|
||||
],
|
||||
"type": "string",
|
||||
"x-enum-varnames": [
|
||||
|
|
@ -253,7 +254,8 @@
|
|||
"SourceTypeWechatServiceBot",
|
||||
"SourceTypeDiscordBot",
|
||||
"SourceTypeWechatOfficialAccount",
|
||||
"SourceTypeOpenAIAPI"
|
||||
"SourceTypeOpenAIAPI",
|
||||
"SourceTypeMcpServer"
|
||||
],
|
||||
"name": "source_type",
|
||||
"in": "query",
|
||||
|
|
@ -4261,7 +4263,8 @@
|
|||
"wechat_service_bot",
|
||||
"discord_bot",
|
||||
"wechat_official_account",
|
||||
"openai_api"
|
||||
"openai_api",
|
||||
"mcp_server"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"SourceTypeDingTalk",
|
||||
|
|
@ -4280,7 +4283,8 @@
|
|||
"SourceTypeWechatServiceBot",
|
||||
"SourceTypeDiscordBot",
|
||||
"SourceTypeWechatOfficialAccount",
|
||||
"SourceTypeOpenAIAPI"
|
||||
"SourceTypeOpenAIAPI",
|
||||
"SourceTypeMcpServer"
|
||||
]
|
||||
},
|
||||
"consts.StatDay": {
|
||||
|
|
@ -4616,6 +4620,14 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"mcp_server_settings": {
|
||||
"description": "MCP Server Settings",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.MCPServerSettings"
|
||||
}
|
||||
]
|
||||
},
|
||||
"openai_api_bot_settings": {
|
||||
"description": "OpenAI API Bot settings",
|
||||
"allOf": [
|
||||
|
|
@ -4889,6 +4901,14 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"mcp_server_settings": {
|
||||
"description": "MCP Server Settings",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.MCPServerSettings"
|
||||
}
|
||||
]
|
||||
},
|
||||
"openai_api_bot_settings": {
|
||||
"description": "OpenAI API settings",
|
||||
"allOf": [
|
||||
|
|
@ -5049,7 +5069,8 @@
|
|||
8,
|
||||
9,
|
||||
10,
|
||||
11
|
||||
11,
|
||||
12
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"AppTypeWeb",
|
||||
|
|
@ -5062,7 +5083,8 @@
|
|||
"AppTypeWechatOfficialAccount",
|
||||
"AppTypeOpenAIAPI",
|
||||
"AppTypeWecomAIBot",
|
||||
"AppTypeLarkBot"
|
||||
"AppTypeLarkBot",
|
||||
"AppTypeMcpServer"
|
||||
]
|
||||
},
|
||||
"domain.AuthUserInfo": {
|
||||
|
|
@ -6371,6 +6393,31 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"domain.MCPServerSettings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"get_docs_tool_settings": {
|
||||
"$ref": "#/definitions/domain.MCPToolSettings"
|
||||
},
|
||||
"is_enabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"sample_auth": {
|
||||
"$ref": "#/definitions/domain.SimpleAuth"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.MCPToolSettings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"desc": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.MessageContent": {
|
||||
"type": "object"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -245,6 +245,7 @@ definitions:
|
|||
- discord_bot
|
||||
- wechat_official_account
|
||||
- openai_api
|
||||
- mcp_server
|
||||
type: string
|
||||
x-enum-varnames:
|
||||
- SourceTypeDingTalk
|
||||
|
|
@ -264,6 +265,7 @@ definitions:
|
|||
- SourceTypeDiscordBot
|
||||
- SourceTypeWechatOfficialAccount
|
||||
- SourceTypeOpenAIAPI
|
||||
- SourceTypeMcpServer
|
||||
consts.StatDay:
|
||||
enum:
|
||||
- 1
|
||||
|
|
@ -488,6 +490,10 @@ definitions:
|
|||
allOf:
|
||||
- $ref: '#/definitions/domain.LarkBotSettings'
|
||||
description: LarkBot
|
||||
mcp_server_settings:
|
||||
allOf:
|
||||
- $ref: '#/definitions/domain.MCPServerSettings'
|
||||
description: MCP Server Settings
|
||||
openai_api_bot_settings:
|
||||
allOf:
|
||||
- $ref: '#/definitions/domain.OpenAIAPIBotSettings'
|
||||
|
|
@ -660,6 +666,10 @@ definitions:
|
|||
allOf:
|
||||
- $ref: '#/definitions/domain.LarkBotSettings'
|
||||
description: LarkBot
|
||||
mcp_server_settings:
|
||||
allOf:
|
||||
- $ref: '#/definitions/domain.MCPServerSettings'
|
||||
description: MCP Server Settings
|
||||
openai_api_bot_settings:
|
||||
allOf:
|
||||
- $ref: '#/definitions/domain.OpenAIAPIBotSettings'
|
||||
|
|
@ -767,6 +777,7 @@ definitions:
|
|||
- 9
|
||||
- 10
|
||||
- 11
|
||||
- 12
|
||||
format: int32
|
||||
type: integer
|
||||
x-enum-varnames:
|
||||
|
|
@ -781,6 +792,7 @@ definitions:
|
|||
- AppTypeOpenAIAPI
|
||||
- AppTypeWecomAIBot
|
||||
- AppTypeLarkBot
|
||||
- AppTypeMcpServer
|
||||
domain.AuthUserInfo:
|
||||
properties:
|
||||
avatar_url:
|
||||
|
|
@ -1625,6 +1637,22 @@ definitions:
|
|||
url:
|
||||
type: string
|
||||
type: object
|
||||
domain.MCPServerSettings:
|
||||
properties:
|
||||
get_docs_tool_settings:
|
||||
$ref: '#/definitions/domain.MCPToolSettings'
|
||||
is_enabled:
|
||||
type: boolean
|
||||
sample_auth:
|
||||
$ref: '#/definitions/domain.SimpleAuth'
|
||||
type: object
|
||||
domain.MCPToolSettings:
|
||||
properties:
|
||||
desc:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
type: object
|
||||
domain.MessageContent:
|
||||
type: object
|
||||
domain.MessageFrom:
|
||||
|
|
@ -3359,6 +3387,7 @@ paths:
|
|||
- discord_bot
|
||||
- wechat_official_account
|
||||
- openai_api
|
||||
- mcp_server
|
||||
in: query
|
||||
name: source_type
|
||||
required: true
|
||||
|
|
@ -3381,6 +3410,7 @@ paths:
|
|||
- SourceTypeDiscordBot
|
||||
- SourceTypeWechatOfficialAccount
|
||||
- SourceTypeOpenAIAPI
|
||||
- SourceTypeMcpServer
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ const (
|
|||
AppTypeOpenAIAPI
|
||||
AppTypeWecomAIBot
|
||||
AppTypeLarkBot
|
||||
AppTypeMcpServer
|
||||
)
|
||||
|
||||
var AppTypes = []AppType{
|
||||
|
|
@ -38,6 +39,7 @@ var AppTypes = []AppType{
|
|||
AppTypeOpenAIAPI,
|
||||
AppTypeWecomAIBot,
|
||||
AppTypeLarkBot,
|
||||
AppTypeMcpServer,
|
||||
}
|
||||
|
||||
func (t AppType) ToSourceType() consts.SourceType {
|
||||
|
|
@ -64,6 +66,8 @@ func (t AppType) ToSourceType() consts.SourceType {
|
|||
return consts.SourceTypeOpenAIAPI
|
||||
case AppTypeLarkBot:
|
||||
return consts.SourceTypeLarkBot
|
||||
case AppTypeMcpServer:
|
||||
return consts.SourceTypeMcpServer
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
|
|
@ -167,6 +171,8 @@ type AppSettings struct {
|
|||
ContributeSettings ContributeSettings `json:"contribute_settings"`
|
||||
HomePageSetting consts.HomePageSetting `json:"home_page_setting"`
|
||||
ConversationSetting ConversationSetting `json:"conversation_setting"`
|
||||
// MCP Server Settings
|
||||
MCPServerSettings MCPServerSettings `json:"mcp_server_settings,omitempty"`
|
||||
}
|
||||
|
||||
type ConversationSetting struct {
|
||||
|
|
@ -178,6 +184,17 @@ type WebAppLandingTheme struct {
|
|||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type MCPServerSettings struct {
|
||||
IsEnabled bool `json:"is_enabled"`
|
||||
GetDocsToolSettings MCPToolSettings `json:"get_docs_tool_settings"`
|
||||
SampleAuth SimpleAuth `json:"sample_auth"`
|
||||
}
|
||||
|
||||
type MCPToolSettings struct {
|
||||
Name string `json:"name"`
|
||||
Desc string `json:"desc"`
|
||||
}
|
||||
|
||||
type LarkBotSettings struct {
|
||||
IsEnabled *bool `json:"is_enabled"`
|
||||
AppID string `json:"app_id"`
|
||||
|
|
@ -544,6 +561,8 @@ type AppSettingsResp struct {
|
|||
WebAppLandingTheme WebAppLandingTheme `json:"web_app_landing_theme"`
|
||||
HomePageSetting consts.HomePageSetting `json:"home_page_setting"`
|
||||
ConversationSetting ConversationSetting `json:"conversation_setting"`
|
||||
// MCP Server Settings
|
||||
MCPServerSettings MCPServerSettings `json:"mcp_server_settings,omitempty"`
|
||||
}
|
||||
|
||||
type WebAppLandingConfigResp struct {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,15 @@ type ChatRequest struct {
|
|||
Info ConversationInfo `json:"-"`
|
||||
}
|
||||
|
||||
type ChatRagOnlyRequest struct {
|
||||
Message string `json:"message" validate:"required"`
|
||||
|
||||
KBID string `json:"-" validate:"required"`
|
||||
|
||||
UserInfo UserInfo `json:"user_info"`
|
||||
AppType AppType `json:"app_type" validate:"required,oneof=1 2"`
|
||||
}
|
||||
|
||||
type ConversationInfo struct {
|
||||
UserInfo UserInfo `json:"user_info"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package domain
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type MCPCall struct {
|
||||
ID string `gorm:"primaryKey;column:id" json:"id,omitempty"`
|
||||
ClientName string `gorm:"column:client_name" json:"client_name"`
|
||||
ClientVersion string `gorm:"column:client_version" json:"client_version"`
|
||||
Question string `gorm:"column:question" json:"question"`
|
||||
Document string `gorm:"column:document" json:"document"`
|
||||
RemoteIP string `gorm:"column:remote_ip" json:"remoate_ip"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;not null;default:now()" json:"created_at"`
|
||||
}
|
||||
|
|
@ -169,7 +169,7 @@ func (r *KnowledgeBaseRepository) SyncKBAccessSettingsToCaddy(ctx context.Contex
|
|||
{
|
||||
"match": []map[string]any{
|
||||
{
|
||||
"path": []string{"/share/v1/chat/completions", "/share/v1/app/wechat/app", "/share/v1/app/wechat/service", "/sitemap.xml", "/share/v1/app/wechat/official_account", "/share/v1/app/wechat/service/answer"},
|
||||
"path": []string{"/share/v1/chat/completions", "/share/v1/app/wechat/app", "/share/v1/app/wechat/service", "/sitemap.xml", "/share/v1/app/wechat/official_account", "/share/v1/app/wechat/service/answer", "/mcp"},
|
||||
},
|
||||
},
|
||||
"handle": []map[string]any{
|
||||
|
|
|
|||
|
|
@ -527,6 +527,8 @@ func (u *AppUsecase) GetAppDetailByKBIDAndAppType(ctx context.Context, kbID stri
|
|||
ConversationSetting: app.Settings.ConversationSetting,
|
||||
|
||||
WecomAIBotSettings: app.Settings.WecomAIBotSettings,
|
||||
|
||||
MCPServerSettings: app.Settings.MCPServerSettings,
|
||||
}
|
||||
|
||||
if !domain.GetBaseEditionLimitation(ctx).AllowCustomCopyright {
|
||||
|
|
@ -556,6 +558,19 @@ func (u *AppUsecase) GetAppDetailByKBIDAndAppType(ctx context.Context, kbID stri
|
|||
return appDetailResp, nil
|
||||
}
|
||||
|
||||
func (u *AppUsecase) GetMCPServerAppInfo(ctx context.Context, kbID string) (*domain.AppInfoResp, error) {
|
||||
apiApp, err := u.repo.GetOrCreateAppByKBIDAndType(ctx, kbID, domain.AppTypeMcpServer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
appInfo := &domain.AppInfoResp{
|
||||
Settings: domain.AppSettingsResp{
|
||||
MCPServerSettings: apiApp.Settings.MCPServerSettings,
|
||||
},
|
||||
}
|
||||
return appInfo, nil
|
||||
}
|
||||
|
||||
func (u *AppUsecase) ShareGetWebAppInfo(ctx context.Context, kbID string, authId uint) (*domain.AppInfoResp, error) {
|
||||
app, err := u.repo.GetOrCreateAppByKBIDAndType(ctx, kbID, domain.AppTypeWeb)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -301,6 +301,64 @@ func (u *ChatUsecase) Chat(ctx context.Context, req *domain.ChatRequest) (<-chan
|
|||
return eventCh, nil
|
||||
}
|
||||
|
||||
func (u *ChatUsecase) ChatRagOnly(ctx context.Context, req *domain.ChatRagOnlyRequest) (<-chan domain.SSEEvent, error) {
|
||||
eventCh := make(chan domain.SSEEvent, 100)
|
||||
go func() {
|
||||
defer close(eventCh)
|
||||
|
||||
// extra1. if user set question block words then check it
|
||||
blockWords, err := u.blockWordRepo.GetBlockWords(ctx, req.KBID)
|
||||
if err != nil {
|
||||
u.logger.Error("failed to get question block words", log.Error(err))
|
||||
eventCh <- domain.SSEEvent{Type: "error", Content: "failed to get question block words"}
|
||||
return
|
||||
}
|
||||
if len(blockWords) > 0 { // check --> filter
|
||||
questionFilter := utils.GetDFA(req.KBID)
|
||||
if err := questionFilter.DFA.Check(req.Message); err != nil { // exist then return err
|
||||
answer := "**您的问题包含敏感词, AI 无法回答您的问题。**"
|
||||
eventCh <- domain.SSEEvent{Type: "error", Content: answer}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if req.UserInfo.AuthUserID == 0 {
|
||||
auth, _ := u.AuthRepo.GetAuthBySourceType(ctx, req.AppType.ToSourceType())
|
||||
if auth != nil {
|
||||
req.UserInfo.AuthUserID = auth.ID
|
||||
}
|
||||
}
|
||||
|
||||
groupIds, err := u.AuthRepo.GetAuthGroupIdsWithParentsByAuthId(ctx, req.UserInfo.AuthUserID)
|
||||
if err != nil {
|
||||
u.logger.Error("failed to get auth groupIds", log.Error(err))
|
||||
eventCh <- domain.SSEEvent{Type: "error", Content: "failed to get auth groupIds"}
|
||||
return
|
||||
}
|
||||
|
||||
// retrieve documents
|
||||
kb, err := u.kbRepo.GetKnowledgeBaseByID(ctx, req.KBID)
|
||||
if err != nil {
|
||||
u.logger.Error("failed to get kb", log.Error(err))
|
||||
eventCh <- domain.SSEEvent{Type: "error", Content: "failed to get kb"}
|
||||
return
|
||||
}
|
||||
rankedNodes, err := u.llmUsecase.GetRankNodes(ctx, []string{kb.DatasetID}, req.Message, groupIds, 0, nil)
|
||||
if err != nil {
|
||||
u.logger.Error("failed to get rank nodes", log.Error(err))
|
||||
eventCh <- domain.SSEEvent{Type: "error", Content: "failed to get rank nodes"}
|
||||
return
|
||||
}
|
||||
documents := domain.FormatNodeChunks(rankedNodes, kb.AccessSettings.BaseURL)
|
||||
u.logger.Debug("documents", log.String("documents", documents))
|
||||
|
||||
// send only the documents part
|
||||
eventCh <- domain.SSEEvent{Type: "data", Content: documents}
|
||||
eventCh <- domain.SSEEvent{Type: "done"}
|
||||
}()
|
||||
return eventCh, nil
|
||||
}
|
||||
|
||||
func (u *ChatUsecase) CreateAcOnChunk(ctx context.Context, kbID string, answer *string, eventCh chan<- domain.SSEEvent, blockWords []string) (func(ctx context.Context, dataType, chunk string) error,
|
||||
func(ctx context.Context, dataType string)) {
|
||||
var buffer strings.Builder
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { copyText } from '@/utils';
|
|||
import { Box, Stack } from '@mui/material';
|
||||
import { Ellipsis } from '@ctzhian/ui';
|
||||
import { IconFuzhi } from '@panda-wiki/icons';
|
||||
import { message } from '@ctzhian/ui';
|
||||
|
||||
interface ShowTextProps {
|
||||
text: string[];
|
||||
|
|
@ -10,6 +11,7 @@ interface ShowTextProps {
|
|||
noEllipsis?: boolean;
|
||||
icon?: React.ReactNode;
|
||||
onClick?: () => void;
|
||||
forceCopy?: boolean;
|
||||
}
|
||||
|
||||
const ShowText = ({
|
||||
|
|
@ -21,6 +23,7 @@ const ShowText = ({
|
|||
),
|
||||
onClick,
|
||||
noEllipsis = false,
|
||||
forceCopy = false,
|
||||
}: ShowTextProps) => {
|
||||
return (
|
||||
<Stack
|
||||
|
|
@ -48,8 +51,32 @@ const ShowText = ({
|
|||
onClick={
|
||||
copyable
|
||||
? () => {
|
||||
copyText(text.join('\n'));
|
||||
onClick?.();
|
||||
const content = text.join('\n');
|
||||
if (forceCopy) {
|
||||
try {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(content);
|
||||
message.success('复制成功');
|
||||
} else {
|
||||
const ta = document.createElement('textarea');
|
||||
ta.style.position = 'fixed';
|
||||
ta.style.opacity = '0';
|
||||
ta.style.left = '-9999px';
|
||||
ta.style.top = '-9999px';
|
||||
ta.value = content;
|
||||
document.body.appendChild(ta);
|
||||
ta.focus();
|
||||
ta.select();
|
||||
const ok = document.execCommand('copy');
|
||||
if (ok) message.success('复制成功');
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
} catch (e) {}
|
||||
onClick?.();
|
||||
} else {
|
||||
copyText(content);
|
||||
onClick?.();
|
||||
}
|
||||
}
|
||||
: onClick
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { VersionInfoMap } from '@/constant/version';
|
||||
import { useVersionInfo } from '@/hooks';
|
||||
import { ConstsLicenseEdition } from '@/request/types';
|
||||
import { styled, SxProps } from '@mui/material';
|
||||
import { styled, SxProps, Tooltip } from '@mui/material';
|
||||
import React from 'react';
|
||||
|
||||
const StyledMaskWrapper = styled('div')(({ theme }) => ({
|
||||
|
|
@ -95,24 +95,48 @@ export const VersionCanUse = ({
|
|||
ConstsLicenseEdition.LicenseEditionEnterprise,
|
||||
],
|
||||
sx,
|
||||
mode = 'text',
|
||||
}: {
|
||||
permission?: ConstsLicenseEdition[];
|
||||
sx?: SxProps;
|
||||
mode?: 'icon' | 'text';
|
||||
}) => {
|
||||
const versionInfo = useVersionInfo();
|
||||
const hasPermission = permission.includes(versionInfo.permission);
|
||||
if (hasPermission) return null;
|
||||
const nextVersionInfo = VersionInfoMap[permission[0]];
|
||||
return (
|
||||
<StyledMaskContent sx={{ width: 'auto', ml: 1, ...sx }}>
|
||||
<StyledMaskVersion sx={{ backgroundColor: nextVersionInfo.bgColor }}>
|
||||
<img
|
||||
src={nextVersionInfo.image}
|
||||
style={{ width: 12, objectFit: 'contain', marginTop: 1 }}
|
||||
alt={nextVersionInfo.label}
|
||||
/>
|
||||
{nextVersionInfo?.label}可用
|
||||
</StyledMaskVersion>
|
||||
<StyledMaskContent
|
||||
sx={{
|
||||
width: 'auto',
|
||||
ml: mode === 'icon' ? 0.5 : 1,
|
||||
// 允许 Tooltip 在 disabled 的父元素中正常工作
|
||||
pointerEvents: 'auto',
|
||||
...sx,
|
||||
}}
|
||||
onClick={e => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}}
|
||||
>
|
||||
{mode === 'icon' ? (
|
||||
<Tooltip title={nextVersionInfo.label + '可用'} placement='top' arrow>
|
||||
<img
|
||||
src={nextVersionInfo.image}
|
||||
style={{ width: 14, objectFit: 'contain' }}
|
||||
alt={nextVersionInfo.label}
|
||||
/>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<StyledMaskVersion sx={{ backgroundColor: nextVersionInfo.bgColor }}>
|
||||
<img
|
||||
src={nextVersionInfo.image}
|
||||
style={{ width: 12, objectFit: 'contain', marginTop: 1 }}
|
||||
alt={nextVersionInfo.label}
|
||||
/>
|
||||
{nextVersionInfo?.label}可用
|
||||
</StyledMaskVersion>
|
||||
)}
|
||||
</StyledMaskContent>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,272 @@
|
|||
import { DomainKnowledgeBaseDetail } from '@/request/types';
|
||||
import {
|
||||
Box,
|
||||
FormControl,
|
||||
FormControlLabel,
|
||||
Radio,
|
||||
RadioGroup,
|
||||
TextField,
|
||||
Stack,
|
||||
} from '@mui/material';
|
||||
import { SettingCardItem, FormItem } from './Common';
|
||||
import ShowText from '@/components/ShowText';
|
||||
import { Controller, useForm } from 'react-hook-form';
|
||||
import { useMemo, useState, useEffect } from 'react';
|
||||
import { message } from '@ctzhian/ui';
|
||||
import { getApiV1AppDetail, putApiV1App } from '@/request/App';
|
||||
import { DomainAppDetailResp, ConstsLicenseEdition } from '@/request/types';
|
||||
|
||||
interface CardMCPProps {
|
||||
kb: DomainKnowledgeBaseDetail;
|
||||
}
|
||||
|
||||
const CardMCP = ({ kb }: CardMCPProps) => {
|
||||
const [isEdit, setIsEdit] = useState(false);
|
||||
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
watch,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = useForm({
|
||||
defaultValues: {
|
||||
is_enabled: false,
|
||||
access: 'open' as 'open' | 'auth',
|
||||
token: '',
|
||||
tool_name: '',
|
||||
tool_desc: '',
|
||||
},
|
||||
});
|
||||
|
||||
const isEnabled = watch('is_enabled');
|
||||
const access = watch('access');
|
||||
const [detail, setDetail] = useState<DomainAppDetailResp | null>(null);
|
||||
|
||||
const mcpUrl = useMemo(() => {
|
||||
const hostRaw = kb?.access_settings?.hosts?.[0] || window.location.hostname;
|
||||
const host = hostRaw === '*' ? window.location.hostname : hostRaw;
|
||||
const sslPorts = kb?.access_settings?.ssl_ports || [];
|
||||
const httpPorts = kb?.access_settings?.ports || [];
|
||||
const isHttps = sslPorts.length > 0;
|
||||
const protocol = isHttps ? 'https' : 'http';
|
||||
if (!host) {
|
||||
return `${protocol}://${window.location.hostname}${isHttps ? '' : `:${window.location.port}`}/mcp`;
|
||||
}
|
||||
if (isHttps) {
|
||||
return `${protocol}://${host}/mcp`;
|
||||
}
|
||||
const port = httpPorts[0];
|
||||
if (!port) return `${protocol}://${host}/mcp`;
|
||||
return `${protocol}://${host}:${port}/mcp`;
|
||||
}, [kb]);
|
||||
|
||||
const onSubmit = handleSubmit(() => {
|
||||
if (!kb || !detail) return;
|
||||
const payload: any = {
|
||||
kb_id: kb.id!,
|
||||
settings: {
|
||||
mcp_server_settings: {
|
||||
is_enabled: isEnabled,
|
||||
get_docs_tool_settings: {
|
||||
name: watch('tool_name'),
|
||||
desc: watch('tool_desc'),
|
||||
},
|
||||
sample_auth: {
|
||||
enabled: access === 'auth',
|
||||
password: access === 'auth' ? watch('token') : '',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
putApiV1App({ id: detail.id! }, payload).then(() => {
|
||||
message.success('保存成功');
|
||||
setIsEdit(false);
|
||||
getDetail();
|
||||
});
|
||||
});
|
||||
|
||||
const getDetail = () => {
|
||||
getApiV1AppDetail({ kb_id: kb.id!, type: '12' }).then(res => {
|
||||
setDetail(res);
|
||||
const is_enabled =
|
||||
(res.settings as any)?.mcp_server_settings?.is_enabled ?? false;
|
||||
const auth =
|
||||
(res.settings as any)?.mcp_server_settings?.sample_auth ?? {};
|
||||
const accessVal = auth.enabled ? 'auth' : 'open';
|
||||
const tokenVal = auth.password ?? '';
|
||||
const toolName =
|
||||
(res.settings as any)?.mcp_server_settings?.get_docs_tool_settings
|
||||
?.name ?? '';
|
||||
const toolDesc =
|
||||
(res.settings as any)?.mcp_server_settings?.get_docs_tool_settings
|
||||
?.desc ?? '';
|
||||
setValue('is_enabled', is_enabled);
|
||||
setValue('access', accessVal);
|
||||
setValue('token', tokenVal);
|
||||
setValue('tool_name', toolName);
|
||||
setValue('tool_desc', toolDesc);
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!kb) return;
|
||||
getDetail();
|
||||
}, [kb]);
|
||||
|
||||
return (
|
||||
<Box sx={{ width: 1000, margin: 'auto', pb: 4 }}>
|
||||
<SettingCardItem
|
||||
title='MCP 设置'
|
||||
isEdit={isEdit}
|
||||
onSubmit={onSubmit}
|
||||
permission={[
|
||||
ConstsLicenseEdition.LicenseEditionBusiness,
|
||||
ConstsLicenseEdition.LicenseEditionEnterprise,
|
||||
]}
|
||||
more={{
|
||||
type: 'link',
|
||||
href: 'https://pandawiki.docs.baizhi.cloud/node/019aa45c-90c1-7e6f-b17a-74ab1b200153',
|
||||
target: '_blank',
|
||||
text: '使用方法',
|
||||
}}
|
||||
>
|
||||
<FormItem label='MCP Server'>
|
||||
<FormControl>
|
||||
<Controller
|
||||
control={control}
|
||||
name='is_enabled'
|
||||
render={({ field }) => (
|
||||
<RadioGroup
|
||||
{...field}
|
||||
onChange={e => {
|
||||
field.onChange(e.target.value === 'true');
|
||||
setIsEdit(true);
|
||||
}}
|
||||
>
|
||||
<Stack direction={'row'}>
|
||||
<FormControlLabel
|
||||
value={true}
|
||||
control={<Radio size='small' />}
|
||||
label={<Box sx={{ width: 100 }}>启用</Box>}
|
||||
/>
|
||||
<FormControlLabel
|
||||
value={false}
|
||||
control={<Radio size='small' />}
|
||||
label={<Box sx={{ width: 100 }}>禁用</Box>}
|
||||
/>
|
||||
</Stack>
|
||||
</RadioGroup>
|
||||
)}
|
||||
/>
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
|
||||
{isEnabled && (
|
||||
<>
|
||||
<FormItem label='MCP URL'>
|
||||
<ShowText
|
||||
text={[mcpUrl]}
|
||||
copyable={true}
|
||||
noEllipsis={true}
|
||||
forceCopy={true}
|
||||
/>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label='MCP Tool名称'>
|
||||
<Controller
|
||||
control={control}
|
||||
name='tool_name'
|
||||
render={({ field }) => (
|
||||
<TextField
|
||||
{...field}
|
||||
fullWidth
|
||||
placeholder='自定义检索文档MCP Tool名称'
|
||||
onChange={e => {
|
||||
field.onChange(e.target.value);
|
||||
setIsEdit(true);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label='MCP Tool描述'>
|
||||
<Controller
|
||||
control={control}
|
||||
name='tool_desc'
|
||||
render={({ field }) => (
|
||||
<TextField
|
||||
{...field}
|
||||
fullWidth
|
||||
placeholder='自定义检索文档MCP Tool描述'
|
||||
onChange={e => {
|
||||
field.onChange(e.target.value);
|
||||
setIsEdit(true);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</FormItem>
|
||||
|
||||
<FormItem label='访问控制'>
|
||||
<FormControl>
|
||||
<Controller
|
||||
control={control}
|
||||
name='access'
|
||||
render={({ field }) => (
|
||||
<RadioGroup
|
||||
{...field}
|
||||
onChange={e => {
|
||||
field.onChange(e.target.value);
|
||||
setIsEdit(true);
|
||||
}}
|
||||
>
|
||||
<Stack direction={'row'}>
|
||||
<FormControlLabel
|
||||
value={'open'}
|
||||
control={<Radio size='small' />}
|
||||
label={<Box sx={{ width: 100 }}>完全公开</Box>}
|
||||
/>
|
||||
<FormControlLabel
|
||||
value={'auth'}
|
||||
control={<Radio size='small' />}
|
||||
label={<Box sx={{ width: 100 }}>需要认证</Box>}
|
||||
/>
|
||||
</Stack>
|
||||
</RadioGroup>
|
||||
)}
|
||||
/>
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
|
||||
{access === 'auth' && (
|
||||
<FormItem label='访问口令' required>
|
||||
<Controller
|
||||
control={control}
|
||||
name='token'
|
||||
rules={{ required: '访问口令不能为空' }}
|
||||
render={({ field }) => (
|
||||
<TextField
|
||||
{...field}
|
||||
fullWidth
|
||||
placeholder='访问口令'
|
||||
onChange={e => {
|
||||
field.onChange(e.target.value);
|
||||
setIsEdit(true);
|
||||
}}
|
||||
error={!!errors.token}
|
||||
helperText={errors.token?.message}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</FormItem>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</SettingCardItem>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default CardMCP;
|
||||
|
|
@ -15,6 +15,7 @@ import CardKB from './component/CardKB';
|
|||
import CardRobot from './component/CardRobot';
|
||||
import CardSecurity from './component/CardSecurity';
|
||||
import CardWeb from './component/CardWeb';
|
||||
import CardMCP from './component/CardMCP';
|
||||
|
||||
const SettingTabs: { label: string; id: string }[] = [
|
||||
{ label: '门户网站', id: 'portal-website' },
|
||||
|
|
@ -23,6 +24,7 @@ const SettingTabs: { label: string; id: string }[] = [
|
|||
{ label: '反馈设置', id: 'feedback' },
|
||||
{ label: '安全设置', id: 'security' },
|
||||
{ label: '访问控制', id: 'backend-info' },
|
||||
{ label: 'MCP 设置', id: 'mcp' },
|
||||
];
|
||||
|
||||
const Setting = () => {
|
||||
|
|
@ -116,6 +118,7 @@ const Setting = () => {
|
|||
{activeTab === 'feedback' && <CardFeedback kb={kb} />}
|
||||
{activeTab === 'robot' && <CardRobot kb={kb} url={url} />}
|
||||
{activeTab === 'portal-website' && <CardWeb kb={kb} refresh={getKb} />}
|
||||
{activeTab === 'mcp' && <CardMCP kb={kb} />}
|
||||
</Card>
|
||||
</Box>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -36,9 +36,17 @@ const Statistic = () => {
|
|||
{ label: '近 24 小时', value: 1, disabled: false },
|
||||
{
|
||||
label: (
|
||||
<Stack direction={'row'} alignItems={'center'} gap={0.5}>
|
||||
<Stack
|
||||
direction={'row'}
|
||||
alignItems={'center'}
|
||||
gap={0.5}
|
||||
sx={{ lineHeight: 1 }}
|
||||
>
|
||||
<span>近 7 天</span>
|
||||
<VersionCanUse permission={PROFESSION_VERSION_PERMISSION} />
|
||||
<VersionCanUse
|
||||
permission={PROFESSION_VERSION_PERMISSION}
|
||||
mode='icon'
|
||||
/>
|
||||
</Stack>
|
||||
),
|
||||
value: 7,
|
||||
|
|
@ -46,9 +54,17 @@ const Statistic = () => {
|
|||
},
|
||||
{
|
||||
label: (
|
||||
<Stack direction={'row'} alignItems={'center'} gap={0.5}>
|
||||
<Stack
|
||||
direction={'row'}
|
||||
alignItems={'center'}
|
||||
gap={0.5}
|
||||
sx={{ lineHeight: 1 }}
|
||||
>
|
||||
<span>近 30 天</span>
|
||||
<VersionCanUse permission={BUSINESS_VERSION_PERMISSION} />
|
||||
<VersionCanUse
|
||||
permission={BUSINESS_VERSION_PERMISSION}
|
||||
mode='icon'
|
||||
/>
|
||||
</Stack>
|
||||
),
|
||||
value: 30,
|
||||
|
|
@ -56,9 +72,17 @@ const Statistic = () => {
|
|||
},
|
||||
{
|
||||
label: (
|
||||
<Stack direction={'row'} alignItems={'center'} gap={0.5}>
|
||||
<Stack
|
||||
direction={'row'}
|
||||
alignItems={'center'}
|
||||
gap={0.5}
|
||||
sx={{ lineHeight: 1 }}
|
||||
>
|
||||
<span>近 90 天</span>
|
||||
<VersionCanUse permission={BUSINESS_VERSION_PERMISSION} />
|
||||
<VersionCanUse
|
||||
permission={BUSINESS_VERSION_PERMISSION}
|
||||
mode='icon'
|
||||
/>
|
||||
</Stack>
|
||||
),
|
||||
value: 90,
|
||||
|
|
|
|||
Loading…
Reference in New Issue