Compare commits
117 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
fe2d70bfa9 | |
|
|
c9f3a61e86 | |
|
|
7b75f1bf55 | |
|
|
07646f0823 | |
|
|
63a8d8a743 | |
|
|
587c2842be | |
|
|
fd34bb4c55 | |
|
|
46afba778f | |
|
|
79234c2394 | |
|
|
67e796dbb7 | |
|
|
55c563cc48 | |
|
|
cfdc546d20 | |
|
|
7f58308dae | |
|
|
f34864621a | |
|
|
da9039ff37 | |
|
|
797e0c033d | |
|
|
ea6f958d24 | |
|
|
d3502e105a | |
|
|
df4937aeb2 | |
|
|
d8c869198e | |
|
|
f04f96d894 | |
|
|
74e87540e0 | |
|
|
4a011aa1d2 | |
|
|
acf17e94b2 | |
|
|
59ca885518 | |
|
|
0e64ff946f | |
|
|
19e6a66809 | |
|
|
c15272aeb2 | |
|
|
32ed999b48 | |
|
|
98e4a917e0 | |
|
|
6e5f780771 | |
|
|
95bd31b8ed | |
|
|
8457544a30 | |
|
|
55abd7452c | |
|
|
6224d713b6 | |
|
|
3f93246d85 | |
|
|
3196f2d130 | |
|
|
4a9a1ff78b | |
|
|
e80cbf9f47 | |
|
|
76f9878d55 | |
|
|
eb662208dc | |
|
|
0dcd65961b | |
|
|
dafb8de41e | |
|
|
de86adf90f | |
|
|
4c0990df8c | |
|
|
87d24e06c4 | |
|
|
b1b354b785 | |
|
|
e9d30eb3d4 | |
|
|
b8f2b95f22 | |
|
|
98c602819f | |
|
|
be163a5f80 | |
|
|
4c03078103 | |
|
|
2b372fd81d | |
|
|
74c6ba131d | |
|
|
6c77246e34 | |
|
|
d347482d31 | |
|
|
92443dfafe | |
|
|
1dd2d93010 | |
|
|
54bf1fd108 | |
|
|
c23ce398d7 | |
|
|
2c90932f60 | |
|
|
035ce0284d | |
|
|
93559125c2 | |
|
|
6c5cf256ac | |
|
|
23bdfc3d50 | |
|
|
9008c537cd | |
|
|
63a4a964b1 | |
|
|
62f2b2eaf5 | |
|
|
5c1c6368b8 | |
|
|
7282503acf | |
|
|
60a4177229 | |
|
|
2f706a6100 | |
|
|
febcb06654 | |
|
|
ca323de9b2 | |
|
|
5c81d714b1 | |
|
|
2a123cf8b1 | |
|
|
b1074f0956 | |
|
|
b98bf6664c | |
|
|
2b02d85fb3 | |
|
|
21f5a776df | |
|
|
3999621981 | |
|
|
da17b21387 | |
|
|
e361644f01 | |
|
|
b8a1a130ac | |
|
|
385c21a36c | |
|
|
a5c99fca95 | |
|
|
7b0d71b4c5 | |
|
|
61688c86c9 | |
|
|
c69e74d15d | |
|
|
26e06e69a7 | |
|
|
74e8b03975 | |
|
|
f91a8fb38f | |
|
|
8e6f7ae77c | |
|
|
cefd3fe3a2 | |
|
|
8d70727d0a | |
|
|
4a787a3a6c | |
|
|
da16f5b335 | |
|
|
7e770de4df | |
|
|
681b250296 | |
|
|
3597afcc2b | |
|
|
284392c379 | |
|
|
4b54cdf4ac | |
|
|
c48b13366d | |
|
|
c31f229483 | |
|
|
8fad4d6262 | |
|
|
712e2f8af8 | |
|
|
b990b00df0 | |
|
|
bb8337a33e | |
|
|
2f56ad7f6b | |
|
|
d7948ddecc | |
|
|
9d329d21fb | |
|
|
e4dbfcb9fb | |
|
|
40c395400d | |
|
|
b7cdec0d4a | |
|
|
44126e0a11 | |
|
|
3375fcb643 | |
|
|
ef3bae6336 |
|
|
@ -56,3 +56,11 @@ type NodePermissionEditReq struct {
|
|||
|
||||
type NodePermissionEditResp struct {
|
||||
}
|
||||
|
||||
type NodeRestudyReq struct {
|
||||
NodeIds []string `json:"node_ids" validate:"required,min=1"`
|
||||
KbId string `json:"kb_id" validate:"required"`
|
||||
}
|
||||
|
||||
type NodeRestudyResp struct {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,4 +24,5 @@ type ShareNodeDetailResp struct {
|
|||
CreatorAccount string `json:"creator_account"`
|
||||
EditorAccount string `json:"editor_account"`
|
||||
PublisherAccount string `json:"publisher_account"`
|
||||
List []*domain.ShareNodeDetailItem `json:"list" gorm:"-"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
//go:build wireinject
|
||||
// +build wireinject
|
||||
|
||||
package main
|
||||
|
||||
|
|
|
|||
|
|
@ -96,7 +96,9 @@ func createApp() (*App, error) {
|
|||
return nil, err
|
||||
}
|
||||
authRepo := pg2.NewAuthRepo(db, logger, cacheCache)
|
||||
nodeUsecase := usecase.NewNodeUsecase(nodeRepository, appRepository, ragRepository, userRepository, knowledgeBaseRepository, llmUsecase, ragService, logger, minioClient, modelRepository, authRepo)
|
||||
systemSettingRepo := pg2.NewSystemSettingRepo(db, logger)
|
||||
modelUsecase := usecase.NewModelUsecase(modelRepository, nodeRepository, ragRepository, ragService, logger, configConfig, knowledgeBaseRepository, systemSettingRepo)
|
||||
nodeUsecase := usecase.NewNodeUsecase(nodeRepository, appRepository, ragRepository, userRepository, knowledgeBaseRepository, llmUsecase, ragService, logger, minioClient, modelRepository, authRepo, modelUsecase)
|
||||
nodeHandler := v1.NewNodeHandler(baseHandler, echo, nodeUsecase, authMiddleware, logger)
|
||||
geoRepo := cache2.NewGeoCache(cacheCache, db, logger)
|
||||
ipdbIPDB, err := ipdb.NewIPDB(configConfig, logger)
|
||||
|
|
@ -105,7 +107,6 @@ func createApp() (*App, error) {
|
|||
}
|
||||
ipAddressRepo := ipdb2.NewIPAddressRepo(ipdbIPDB, logger)
|
||||
conversationUsecase := usecase.NewConversationUsecase(conversationRepository, nodeRepository, geoRepo, logger, ipAddressRepo, authRepo)
|
||||
modelUsecase := usecase.NewModelUsecase(modelRepository, nodeRepository, ragRepository, ragService, logger, configConfig, knowledgeBaseRepository)
|
||||
blockWordRepo := pg2.NewBlockWordRepo(db, logger)
|
||||
chatUsecase, err := usecase.NewChatUsecase(llmUsecase, knowledgeBaseRepository, conversationUsecase, modelUsecase, appRepository, blockWordRepo, authRepo, logger)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
//go:build wireinject
|
||||
// +build wireinject
|
||||
|
||||
package main
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/chaitin/panda-wiki/config"
|
||||
mq2 "github.com/chaitin/panda-wiki/handler/mq"
|
||||
mq3 "github.com/chaitin/panda-wiki/handler/mq"
|
||||
"github.com/chaitin/panda-wiki/log"
|
||||
"github.com/chaitin/panda-wiki/mq"
|
||||
cache2 "github.com/chaitin/panda-wiki/repo/cache"
|
||||
ipdb2 "github.com/chaitin/panda-wiki/repo/ipdb"
|
||||
mq3 "github.com/chaitin/panda-wiki/repo/mq"
|
||||
mq2 "github.com/chaitin/panda-wiki/repo/mq"
|
||||
pg2 "github.com/chaitin/panda-wiki/repo/pg"
|
||||
"github.com/chaitin/panda-wiki/store/cache"
|
||||
"github.com/chaitin/panda-wiki/store/ipdb"
|
||||
|
|
@ -49,11 +49,18 @@ func createApp() (*App, error) {
|
|||
modelRepository := pg2.NewModelRepository(db, logger)
|
||||
promptRepo := pg2.NewPromptRepo(db, logger)
|
||||
llmUsecase := usecase.NewLLMUsecase(configConfig, ragService, conversationRepository, knowledgeBaseRepository, nodeRepository, modelRepository, promptRepo, logger)
|
||||
ragmqHandler, err := mq2.NewRAGMQHandler(mqConsumer, logger, ragService, nodeRepository, knowledgeBaseRepository, llmUsecase, modelRepository)
|
||||
mqProducer, err := mq.NewMQProducer(configConfig, logger)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ragDocUpdateHandler, err := mq2.NewRagDocUpdateHandler(mqConsumer, logger, nodeRepository)
|
||||
ragRepository := mq2.NewRAGRepository(mqProducer)
|
||||
systemSettingRepo := pg2.NewSystemSettingRepo(db, logger)
|
||||
modelUsecase := usecase.NewModelUsecase(modelRepository, nodeRepository, ragRepository, ragService, logger, configConfig, knowledgeBaseRepository, systemSettingRepo)
|
||||
ragmqHandler, err := mq3.NewRAGMQHandler(mqConsumer, logger, ragService, nodeRepository, knowledgeBaseRepository, llmUsecase, modelUsecase)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ragDocUpdateHandler, err := mq3.NewRagDocUpdateHandler(mqConsumer, logger, nodeRepository)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -71,22 +78,17 @@ func createApp() (*App, error) {
|
|||
geoRepo := cache2.NewGeoCache(cacheCache, db, logger)
|
||||
authRepo := pg2.NewAuthRepo(db, logger, cacheCache)
|
||||
statUseCase := usecase.NewStatUseCase(statRepository, nodeRepository, conversationRepository, appRepository, ipAddressRepo, geoRepo, authRepo, knowledgeBaseRepository, logger)
|
||||
mqProducer, err := mq.NewMQProducer(configConfig, logger)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ragRepository := mq3.NewRAGRepository(mqProducer)
|
||||
userRepository := pg2.NewUserRepository(db, logger)
|
||||
minioClient, err := s3.NewMinioClient(configConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodeUsecase := usecase.NewNodeUsecase(nodeRepository, appRepository, ragRepository, userRepository, knowledgeBaseRepository, llmUsecase, ragService, logger, minioClient, modelRepository, authRepo)
|
||||
cronHandler, err := mq2.NewStatCronHandler(logger, statRepository, statUseCase, nodeUsecase)
|
||||
nodeUsecase := usecase.NewNodeUsecase(nodeRepository, appRepository, ragRepository, userRepository, knowledgeBaseRepository, llmUsecase, ragService, logger, minioClient, modelRepository, authRepo, modelUsecase)
|
||||
cronHandler, err := mq3.NewStatCronHandler(logger, statRepository, statUseCase, nodeUsecase)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mqHandlers := &mq2.MQHandlers{
|
||||
mqHandlers := &mq3.MQHandlers{
|
||||
RAGMQHandler: ragmqHandler,
|
||||
RagDocUpdateHandler: ragDocUpdateHandler,
|
||||
StatCronHandler: cronHandler,
|
||||
|
|
@ -105,6 +107,6 @@ func createApp() (*App, error) {
|
|||
type App struct {
|
||||
MQConsumer mq.MQConsumer
|
||||
Config *config.Config
|
||||
MQHandlers *mq2.MQHandlers
|
||||
StatCronHandler *mq2.CronHandler
|
||||
MQHandlers *mq3.MQHandlers
|
||||
StatCronHandler *mq3.CronHandler
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
//go:build wireinject
|
||||
// +build wireinject
|
||||
|
||||
package main
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,9 @@ func createApp() (*App, error) {
|
|||
return nil, err
|
||||
}
|
||||
authRepo := pg2.NewAuthRepo(db, logger, cacheCache)
|
||||
nodeUsecase := usecase.NewNodeUsecase(nodeRepository, appRepository, ragRepository, userRepository, knowledgeBaseRepository, llmUsecase, ragService, logger, minioClient, modelRepository, authRepo)
|
||||
systemSettingRepo := pg2.NewSystemSettingRepo(db, logger)
|
||||
modelUsecase := usecase.NewModelUsecase(modelRepository, nodeRepository, ragRepository, ragService, logger, configConfig, knowledgeBaseRepository, systemSettingRepo)
|
||||
nodeUsecase := usecase.NewNodeUsecase(nodeRepository, appRepository, ragRepository, userRepository, knowledgeBaseRepository, llmUsecase, ragService, logger, minioClient, modelRepository, authRepo, modelUsecase)
|
||||
kbRepo := cache2.NewKBRepo(cacheCache)
|
||||
knowledgeBaseUsecase, err := usecase.NewKnowledgeBaseUsecase(knowledgeBaseRepository, nodeRepository, ragRepository, userRepository, ragService, kbRepo, logger, configConfig)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -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 ""
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package consts
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
|
|
@ -14,27 +12,12 @@ type LicenseEdition int32
|
|||
|
||||
const (
|
||||
LicenseEditionFree LicenseEdition = 0 // 开源版
|
||||
LicenseEditionContributor LicenseEdition = 1 // 联创版
|
||||
LicenseEditionProfession LicenseEdition = 1 // 专业版
|
||||
LicenseEditionEnterprise LicenseEdition = 2 // 企业版
|
||||
LicenseEditionBusiness LicenseEdition = 3 // 商业版
|
||||
)
|
||||
|
||||
func GetLicenseEdition(c echo.Context) LicenseEdition {
|
||||
edition, _ := c.Get("edition").(LicenseEdition)
|
||||
return edition
|
||||
}
|
||||
|
||||
func (e LicenseEdition) GetMaxAuth(sourceType SourceType) int {
|
||||
switch e {
|
||||
case LicenseEditionFree:
|
||||
if sourceType == SourceTypeGitHub {
|
||||
return 10
|
||||
}
|
||||
return 0
|
||||
case LicenseEditionContributor:
|
||||
return 10
|
||||
case LicenseEditionEnterprise:
|
||||
return math.MaxInt
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
package consts
|
||||
|
||||
type AutoModeDefaultModel string
|
||||
|
||||
const (
|
||||
AutoModeDefaultChatModel AutoModeDefaultModel = "deepseek-chat"
|
||||
AutoModeDefaultEmbeddingModel AutoModeDefaultModel = "bge-m3"
|
||||
AutoModeDefaultRerankModel AutoModeDefaultModel = "bge-reranker-v2-m3"
|
||||
AutoModeDefaultAnalysisModel AutoModeDefaultModel = "qwen2.5-3b-instruct"
|
||||
AutoModeDefaultAnalysisVLModel AutoModeDefaultModel = "qwen3-vl-max"
|
||||
)
|
||||
|
||||
func GetAutoModeDefaultModel(modelType string) string {
|
||||
switch modelType {
|
||||
case "chat":
|
||||
return string(AutoModeDefaultChatModel)
|
||||
case "embedding":
|
||||
return string(AutoModeDefaultEmbeddingModel)
|
||||
case "rerank":
|
||||
return string(AutoModeDefaultRerankModel)
|
||||
case "analysis":
|
||||
return string(AutoModeDefaultAnalysisModel)
|
||||
case "analysis-vl":
|
||||
return string(AutoModeDefaultAnalysisVLModel)
|
||||
default:
|
||||
return string(AutoModeDefaultChatModel)
|
||||
}
|
||||
}
|
||||
|
||||
type ModelSettingMode string
|
||||
|
||||
const (
|
||||
ModelSettingModeManual ModelSettingMode = "manual"
|
||||
ModelSettingModeAuto ModelSettingMode = "auto"
|
||||
)
|
||||
|
||||
const (
|
||||
AutoModeBaseURL = "https://model-square.app.baizhi.cloud/v1"
|
||||
)
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package consts
|
||||
|
||||
type SystemSettingKey string
|
||||
|
||||
const (
|
||||
SystemSettingModelMode SystemSettingKey = "model_setting_mode"
|
||||
)
|
||||
|
|
@ -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",
|
||||
|
|
@ -1565,6 +1567,41 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/model/mode-setting": {
|
||||
"get": {
|
||||
"description": "get current model mode setting including mode, API key and chat model",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"model"
|
||||
],
|
||||
"summary": "get model mode setting",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/domain.ModelModeSetting"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/model/provider/supported": {
|
||||
"post": {
|
||||
"description": "get provider supported model list",
|
||||
|
|
@ -1611,6 +1648,52 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/model/switch-mode": {
|
||||
"post": {
|
||||
"description": "switch model mode between manual and auto",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"model"
|
||||
],
|
||||
"summary": "switch mode",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "switch mode request",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SwitchModeReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/domain.SwitchModeResp"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/node": {
|
||||
"post": {
|
||||
"security": [
|
||||
|
|
@ -2117,6 +2200,58 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/node/restudy": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"bearerAuth": []
|
||||
}
|
||||
],
|
||||
"description": "文档重新学习",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Node"
|
||||
],
|
||||
"summary": "文档重新学习",
|
||||
"operationId": "v1-NodeRestudy",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "para",
|
||||
"name": "param",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/v1.NodeRestudyReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/v1.NodeRestudyResp"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/node/summary": {
|
||||
"post": {
|
||||
"security": [
|
||||
|
|
@ -3345,7 +3480,7 @@ const docTemplate = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"share_chat"
|
||||
"Widget"
|
||||
],
|
||||
"summary": "ChatWidget",
|
||||
"parameters": [
|
||||
|
|
@ -3376,6 +3511,52 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/share/v1/chat/widget/search": {
|
||||
"post": {
|
||||
"description": "WidgetSearch",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Widget"
|
||||
],
|
||||
"summary": "WidgetSearch",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Comment",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.ChatSearchReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/domain.ChatSearchResp"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/share/v1/comment": {
|
||||
"post": {
|
||||
"description": "CreateComment",
|
||||
|
|
@ -3934,22 +4115,37 @@ const docTemplate = `{
|
|||
"enum": [
|
||||
0,
|
||||
1,
|
||||
2
|
||||
2,
|
||||
3
|
||||
],
|
||||
"x-enum-comments": {
|
||||
"LicenseEditionContributor": "联创版",
|
||||
"LicenseEditionBusiness": "商业版",
|
||||
"LicenseEditionEnterprise": "企业版",
|
||||
"LicenseEditionFree": "开源版"
|
||||
"LicenseEditionFree": "开源版",
|
||||
"LicenseEditionProfession": "专业版"
|
||||
},
|
||||
"x-enum-descriptions": [
|
||||
"开源版",
|
||||
"联创版",
|
||||
"企业版"
|
||||
"专业版",
|
||||
"企业版",
|
||||
"商业版"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"LicenseEditionFree",
|
||||
"LicenseEditionContributor",
|
||||
"LicenseEditionEnterprise"
|
||||
"LicenseEditionProfession",
|
||||
"LicenseEditionEnterprise",
|
||||
"LicenseEditionBusiness"
|
||||
]
|
||||
},
|
||||
"consts.ModelSettingMode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"manual",
|
||||
"auto"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"ModelSettingModeManual",
|
||||
"ModelSettingModeAuto"
|
||||
]
|
||||
},
|
||||
"consts.NodeAccessPerm": {
|
||||
|
|
@ -4074,7 +4270,8 @@ const docTemplate = `{
|
|||
"wechat_service_bot",
|
||||
"discord_bot",
|
||||
"wechat_official_account",
|
||||
"openai_api"
|
||||
"openai_api",
|
||||
"mcp_server"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"SourceTypeDingTalk",
|
||||
|
|
@ -4093,7 +4290,8 @@ const docTemplate = `{
|
|||
"SourceTypeWechatServiceBot",
|
||||
"SourceTypeDiscordBot",
|
||||
"SourceTypeWechatOfficialAccount",
|
||||
"SourceTypeOpenAIAPI"
|
||||
"SourceTypeOpenAIAPI",
|
||||
"SourceTypeMcpServer"
|
||||
]
|
||||
},
|
||||
"consts.StatDay": {
|
||||
|
|
@ -4318,9 +4516,6 @@ const docTemplate = `{
|
|||
}
|
||||
]
|
||||
},
|
||||
"auto_sitemap": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"body_code": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
@ -4339,6 +4534,9 @@ const docTemplate = `{
|
|||
"contribute_settings": {
|
||||
"$ref": "#/definitions/domain.ContributeSettings"
|
||||
},
|
||||
"conversation_setting": {
|
||||
"$ref": "#/definitions/domain.ConversationSetting"
|
||||
},
|
||||
"copy_setting": {
|
||||
"enum": [
|
||||
"",
|
||||
|
|
@ -4426,6 +4624,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": [
|
||||
|
|
@ -4597,9 +4803,6 @@ const docTemplate = `{
|
|||
}
|
||||
]
|
||||
},
|
||||
"auto_sitemap": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"body_code": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
@ -4618,6 +4821,9 @@ const docTemplate = `{
|
|||
"contribute_settings": {
|
||||
"$ref": "#/definitions/domain.ContributeSettings"
|
||||
},
|
||||
"conversation_setting": {
|
||||
"$ref": "#/definitions/domain.ConversationSetting"
|
||||
},
|
||||
"copy_setting": {
|
||||
"$ref": "#/definitions/consts.CopySetting"
|
||||
},
|
||||
|
|
@ -4696,6 +4902,14 @@ const docTemplate = `{
|
|||
}
|
||||
]
|
||||
},
|
||||
"mcp_server_settings": {
|
||||
"description": "MCP Server Settings",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.MCPServerSettings"
|
||||
}
|
||||
]
|
||||
},
|
||||
"openai_api_bot_settings": {
|
||||
"description": "OpenAI API settings",
|
||||
"allOf": [
|
||||
|
|
@ -4856,7 +5070,8 @@ const docTemplate = `{
|
|||
8,
|
||||
9,
|
||||
10,
|
||||
11
|
||||
11,
|
||||
12
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"AppTypeWeb",
|
||||
|
|
@ -4869,7 +5084,8 @@ const docTemplate = `{
|
|||
"AppTypeWechatOfficialAccount",
|
||||
"AppTypeOpenAIAPI",
|
||||
"AppTypeWecomAIBot",
|
||||
"AppTypeLarkBot"
|
||||
"AppTypeLarkBot",
|
||||
"AppTypeMcpServer"
|
||||
]
|
||||
},
|
||||
"domain.AuthUserInfo": {
|
||||
|
|
@ -5558,6 +5774,17 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"domain.ConversationSetting": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"copyright_hide_enabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"copyright_info": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.CreateKBReleaseReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
|
@ -6167,6 +6394,34 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"domain.MCPServerSettings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"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"
|
||||
},
|
||||
"domain.MessageFrom": {
|
||||
"type": "integer",
|
||||
"enum": [
|
||||
|
|
@ -6206,6 +6461,31 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"domain.ModelModeSetting": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"auto_mode_api_key": {
|
||||
"description": "百智云 API Key",
|
||||
"type": "string"
|
||||
},
|
||||
"chat_model": {
|
||||
"description": "自定义对话模型名称",
|
||||
"type": "string"
|
||||
},
|
||||
"is_manual_embedding_updated": {
|
||||
"description": "手动模式下嵌入模型是否更新",
|
||||
"type": "boolean"
|
||||
},
|
||||
"mode": {
|
||||
"description": "模式: manual 或 auto",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/consts.ModelSettingMode"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.ModelType": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
|
|
@ -6360,6 +6640,9 @@ const docTemplate = `{
|
|||
"position": {
|
||||
"type": "number"
|
||||
},
|
||||
"publisher_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"rag_info": {
|
||||
"$ref": "#/definitions/domain.RagInfo"
|
||||
},
|
||||
|
|
@ -6543,6 +6826,9 @@ const docTemplate = `{
|
|||
"stream": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"stream_options": {
|
||||
"$ref": "#/definitions/domain.OpenAIStreamOptions"
|
||||
},
|
||||
"temperature": {
|
||||
"type": "number"
|
||||
},
|
||||
|
|
@ -6665,7 +6951,7 @@ const docTemplate = `{
|
|||
],
|
||||
"properties": {
|
||||
"content": {
|
||||
"type": "string"
|
||||
"$ref": "#/definitions/domain.MessageContent"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
|
|
@ -6695,6 +6981,14 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"domain.OpenAIStreamOptions": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"include_usage": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.OpenAITool": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
|
@ -6961,6 +7255,44 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"domain.ShareNodeDetailItem": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"children": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/domain.ShareNodeDetailItem"
|
||||
}
|
||||
},
|
||||
"emoji": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"meta": {
|
||||
"$ref": "#/definitions/domain.NodeMeta"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"parent_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"permissions": {
|
||||
"$ref": "#/definitions/domain.NodePermissions"
|
||||
},
|
||||
"position": {
|
||||
"type": "number"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/definitions/domain.NodeType"
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.SimpleAuth": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
@ -7045,6 +7377,37 @@ const docTemplate = `{
|
|||
"StatPageSceneLogin"
|
||||
]
|
||||
},
|
||||
"domain.SwitchModeReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"mode"
|
||||
],
|
||||
"properties": {
|
||||
"auto_mode_api_key": {
|
||||
"description": "百智云 API Key",
|
||||
"type": "string"
|
||||
},
|
||||
"chat_model": {
|
||||
"description": "自定义对话模型名称",
|
||||
"type": "string"
|
||||
},
|
||||
"mode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"manual",
|
||||
"auto"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.SwitchModeResp": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.TextConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
@ -7447,15 +7810,39 @@ const docTemplate = `{
|
|||
"domain.WidgetBotSettings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"btn_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"btn_logo": {
|
||||
"type": "string"
|
||||
},
|
||||
"btn_position": {
|
||||
"type": "string"
|
||||
},
|
||||
"btn_style": {
|
||||
"type": "string"
|
||||
},
|
||||
"btn_text": {
|
||||
"type": "string"
|
||||
},
|
||||
"copyright_hide_enabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"copyright_info": {
|
||||
"type": "string"
|
||||
},
|
||||
"disclaimer": {
|
||||
"type": "string"
|
||||
},
|
||||
"is_open": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"modal_position": {
|
||||
"type": "string"
|
||||
},
|
||||
"placeholder": {
|
||||
"type": "string"
|
||||
},
|
||||
"recommend_node_ids": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
|
@ -7468,6 +7855,9 @@ const docTemplate = `{
|
|||
"type": "string"
|
||||
}
|
||||
},
|
||||
"search_mode": {
|
||||
"type": "string"
|
||||
},
|
||||
"theme_mode": {
|
||||
"type": "string"
|
||||
}
|
||||
|
|
@ -8271,6 +8661,28 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"v1.NodeRestudyReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"kb_id",
|
||||
"node_ids"
|
||||
],
|
||||
"properties": {
|
||||
"kb_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"node_ids": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"v1.NodeRestudyResp": {
|
||||
"type": "object"
|
||||
},
|
||||
"v1.ResetPasswordReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
|
@ -8314,6 +8726,12 @@ const docTemplate = `{
|
|||
"kb_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"list": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/domain.ShareNodeDetailItem"
|
||||
}
|
||||
},
|
||||
"meta": {
|
||||
"$ref": "#/definitions/domain.NodeMeta"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
@ -1558,6 +1560,41 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/model/mode-setting": {
|
||||
"get": {
|
||||
"description": "get current model mode setting including mode, API key and chat model",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"model"
|
||||
],
|
||||
"summary": "get model mode setting",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/domain.ModelModeSetting"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/model/provider/supported": {
|
||||
"post": {
|
||||
"description": "get provider supported model list",
|
||||
|
|
@ -1604,6 +1641,52 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/model/switch-mode": {
|
||||
"post": {
|
||||
"description": "switch model mode between manual and auto",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"model"
|
||||
],
|
||||
"summary": "switch mode",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "switch mode request",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.SwitchModeReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/domain.SwitchModeResp"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/node": {
|
||||
"post": {
|
||||
"security": [
|
||||
|
|
@ -2110,6 +2193,58 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/node/restudy": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"bearerAuth": []
|
||||
}
|
||||
],
|
||||
"description": "文档重新学习",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Node"
|
||||
],
|
||||
"summary": "文档重新学习",
|
||||
"operationId": "v1-NodeRestudy",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "para",
|
||||
"name": "param",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/v1.NodeRestudyReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/v1.NodeRestudyResp"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/node/summary": {
|
||||
"post": {
|
||||
"security": [
|
||||
|
|
@ -3338,7 +3473,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"share_chat"
|
||||
"Widget"
|
||||
],
|
||||
"summary": "ChatWidget",
|
||||
"parameters": [
|
||||
|
|
@ -3369,6 +3504,52 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/share/v1/chat/widget/search": {
|
||||
"post": {
|
||||
"description": "WidgetSearch",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Widget"
|
||||
],
|
||||
"summary": "WidgetSearch",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Comment",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/domain.ChatSearchReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/domain.ChatSearchResp"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/share/v1/comment": {
|
||||
"post": {
|
||||
"description": "CreateComment",
|
||||
|
|
@ -3927,22 +4108,37 @@
|
|||
"enum": [
|
||||
0,
|
||||
1,
|
||||
2
|
||||
2,
|
||||
3
|
||||
],
|
||||
"x-enum-comments": {
|
||||
"LicenseEditionContributor": "联创版",
|
||||
"LicenseEditionBusiness": "商业版",
|
||||
"LicenseEditionEnterprise": "企业版",
|
||||
"LicenseEditionFree": "开源版"
|
||||
"LicenseEditionFree": "开源版",
|
||||
"LicenseEditionProfession": "专业版"
|
||||
},
|
||||
"x-enum-descriptions": [
|
||||
"开源版",
|
||||
"联创版",
|
||||
"企业版"
|
||||
"专业版",
|
||||
"企业版",
|
||||
"商业版"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"LicenseEditionFree",
|
||||
"LicenseEditionContributor",
|
||||
"LicenseEditionEnterprise"
|
||||
"LicenseEditionProfession",
|
||||
"LicenseEditionEnterprise",
|
||||
"LicenseEditionBusiness"
|
||||
]
|
||||
},
|
||||
"consts.ModelSettingMode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"manual",
|
||||
"auto"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"ModelSettingModeManual",
|
||||
"ModelSettingModeAuto"
|
||||
]
|
||||
},
|
||||
"consts.NodeAccessPerm": {
|
||||
|
|
@ -4067,7 +4263,8 @@
|
|||
"wechat_service_bot",
|
||||
"discord_bot",
|
||||
"wechat_official_account",
|
||||
"openai_api"
|
||||
"openai_api",
|
||||
"mcp_server"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"SourceTypeDingTalk",
|
||||
|
|
@ -4086,7 +4283,8 @@
|
|||
"SourceTypeWechatServiceBot",
|
||||
"SourceTypeDiscordBot",
|
||||
"SourceTypeWechatOfficialAccount",
|
||||
"SourceTypeOpenAIAPI"
|
||||
"SourceTypeOpenAIAPI",
|
||||
"SourceTypeMcpServer"
|
||||
]
|
||||
},
|
||||
"consts.StatDay": {
|
||||
|
|
@ -4311,9 +4509,6 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"auto_sitemap": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"body_code": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
@ -4332,6 +4527,9 @@
|
|||
"contribute_settings": {
|
||||
"$ref": "#/definitions/domain.ContributeSettings"
|
||||
},
|
||||
"conversation_setting": {
|
||||
"$ref": "#/definitions/domain.ConversationSetting"
|
||||
},
|
||||
"copy_setting": {
|
||||
"enum": [
|
||||
"",
|
||||
|
|
@ -4419,6 +4617,14 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"mcp_server_settings": {
|
||||
"description": "MCP Server Settings",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.MCPServerSettings"
|
||||
}
|
||||
]
|
||||
},
|
||||
"openai_api_bot_settings": {
|
||||
"description": "OpenAI API Bot settings",
|
||||
"allOf": [
|
||||
|
|
@ -4590,9 +4796,6 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"auto_sitemap": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"body_code": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
@ -4611,6 +4814,9 @@
|
|||
"contribute_settings": {
|
||||
"$ref": "#/definitions/domain.ContributeSettings"
|
||||
},
|
||||
"conversation_setting": {
|
||||
"$ref": "#/definitions/domain.ConversationSetting"
|
||||
},
|
||||
"copy_setting": {
|
||||
"$ref": "#/definitions/consts.CopySetting"
|
||||
},
|
||||
|
|
@ -4689,6 +4895,14 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"mcp_server_settings": {
|
||||
"description": "MCP Server Settings",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/domain.MCPServerSettings"
|
||||
}
|
||||
]
|
||||
},
|
||||
"openai_api_bot_settings": {
|
||||
"description": "OpenAI API settings",
|
||||
"allOf": [
|
||||
|
|
@ -4849,7 +5063,8 @@
|
|||
8,
|
||||
9,
|
||||
10,
|
||||
11
|
||||
11,
|
||||
12
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"AppTypeWeb",
|
||||
|
|
@ -4862,7 +5077,8 @@
|
|||
"AppTypeWechatOfficialAccount",
|
||||
"AppTypeOpenAIAPI",
|
||||
"AppTypeWecomAIBot",
|
||||
"AppTypeLarkBot"
|
||||
"AppTypeLarkBot",
|
||||
"AppTypeMcpServer"
|
||||
]
|
||||
},
|
||||
"domain.AuthUserInfo": {
|
||||
|
|
@ -5551,6 +5767,17 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"domain.ConversationSetting": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"copyright_hide_enabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"copyright_info": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.CreateKBReleaseReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
|
@ -6160,6 +6387,34 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"domain.MCPServerSettings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"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"
|
||||
},
|
||||
"domain.MessageFrom": {
|
||||
"type": "integer",
|
||||
"enum": [
|
||||
|
|
@ -6199,6 +6454,31 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"domain.ModelModeSetting": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"auto_mode_api_key": {
|
||||
"description": "百智云 API Key",
|
||||
"type": "string"
|
||||
},
|
||||
"chat_model": {
|
||||
"description": "自定义对话模型名称",
|
||||
"type": "string"
|
||||
},
|
||||
"is_manual_embedding_updated": {
|
||||
"description": "手动模式下嵌入模型是否更新",
|
||||
"type": "boolean"
|
||||
},
|
||||
"mode": {
|
||||
"description": "模式: manual 或 auto",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/consts.ModelSettingMode"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.ModelType": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
|
|
@ -6353,6 +6633,9 @@
|
|||
"position": {
|
||||
"type": "number"
|
||||
},
|
||||
"publisher_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"rag_info": {
|
||||
"$ref": "#/definitions/domain.RagInfo"
|
||||
},
|
||||
|
|
@ -6536,6 +6819,9 @@
|
|||
"stream": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"stream_options": {
|
||||
"$ref": "#/definitions/domain.OpenAIStreamOptions"
|
||||
},
|
||||
"temperature": {
|
||||
"type": "number"
|
||||
},
|
||||
|
|
@ -6658,7 +6944,7 @@
|
|||
],
|
||||
"properties": {
|
||||
"content": {
|
||||
"type": "string"
|
||||
"$ref": "#/definitions/domain.MessageContent"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
|
|
@ -6688,6 +6974,14 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"domain.OpenAIStreamOptions": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"include_usage": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.OpenAITool": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
|
@ -6954,6 +7248,44 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"domain.ShareNodeDetailItem": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"children": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/domain.ShareNodeDetailItem"
|
||||
}
|
||||
},
|
||||
"emoji": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"meta": {
|
||||
"$ref": "#/definitions/domain.NodeMeta"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"parent_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"permissions": {
|
||||
"$ref": "#/definitions/domain.NodePermissions"
|
||||
},
|
||||
"position": {
|
||||
"type": "number"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/definitions/domain.NodeType"
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.SimpleAuth": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
@ -7038,6 +7370,37 @@
|
|||
"StatPageSceneLogin"
|
||||
]
|
||||
},
|
||||
"domain.SwitchModeReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"mode"
|
||||
],
|
||||
"properties": {
|
||||
"auto_mode_api_key": {
|
||||
"description": "百智云 API Key",
|
||||
"type": "string"
|
||||
},
|
||||
"chat_model": {
|
||||
"description": "自定义对话模型名称",
|
||||
"type": "string"
|
||||
},
|
||||
"mode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"manual",
|
||||
"auto"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.SwitchModeResp": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"domain.TextConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
@ -7440,15 +7803,39 @@
|
|||
"domain.WidgetBotSettings": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"btn_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"btn_logo": {
|
||||
"type": "string"
|
||||
},
|
||||
"btn_position": {
|
||||
"type": "string"
|
||||
},
|
||||
"btn_style": {
|
||||
"type": "string"
|
||||
},
|
||||
"btn_text": {
|
||||
"type": "string"
|
||||
},
|
||||
"copyright_hide_enabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"copyright_info": {
|
||||
"type": "string"
|
||||
},
|
||||
"disclaimer": {
|
||||
"type": "string"
|
||||
},
|
||||
"is_open": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"modal_position": {
|
||||
"type": "string"
|
||||
},
|
||||
"placeholder": {
|
||||
"type": "string"
|
||||
},
|
||||
"recommend_node_ids": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
|
@ -7461,6 +7848,9 @@
|
|||
"type": "string"
|
||||
}
|
||||
},
|
||||
"search_mode": {
|
||||
"type": "string"
|
||||
},
|
||||
"theme_mode": {
|
||||
"type": "string"
|
||||
}
|
||||
|
|
@ -8264,6 +8654,28 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"v1.NodeRestudyReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"kb_id",
|
||||
"node_ids"
|
||||
],
|
||||
"properties": {
|
||||
"kb_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"node_ids": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"v1.NodeRestudyResp": {
|
||||
"type": "object"
|
||||
},
|
||||
"v1.ResetPasswordReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
|
@ -8307,6 +8719,12 @@
|
|||
"kb_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"list": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/domain.ShareNodeDetailItem"
|
||||
}
|
||||
},
|
||||
"meta": {
|
||||
"$ref": "#/definitions/domain.NodeMeta"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -117,20 +117,32 @@ definitions:
|
|||
- 0
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
format: int32
|
||||
type: integer
|
||||
x-enum-comments:
|
||||
LicenseEditionContributor: 联创版
|
||||
LicenseEditionBusiness: 商业版
|
||||
LicenseEditionEnterprise: 企业版
|
||||
LicenseEditionFree: 开源版
|
||||
LicenseEditionProfession: 专业版
|
||||
x-enum-descriptions:
|
||||
- 开源版
|
||||
- 联创版
|
||||
- 专业版
|
||||
- 企业版
|
||||
- 商业版
|
||||
x-enum-varnames:
|
||||
- LicenseEditionFree
|
||||
- LicenseEditionContributor
|
||||
- LicenseEditionProfession
|
||||
- LicenseEditionEnterprise
|
||||
- LicenseEditionBusiness
|
||||
consts.ModelSettingMode:
|
||||
enum:
|
||||
- manual
|
||||
- auto
|
||||
type: string
|
||||
x-enum-varnames:
|
||||
- ModelSettingModeManual
|
||||
- ModelSettingModeAuto
|
||||
consts.NodeAccessPerm:
|
||||
enum:
|
||||
- open
|
||||
|
|
@ -233,6 +245,7 @@ definitions:
|
|||
- discord_bot
|
||||
- wechat_official_account
|
||||
- openai_api
|
||||
- mcp_server
|
||||
type: string
|
||||
x-enum-varnames:
|
||||
- SourceTypeDingTalk
|
||||
|
|
@ -252,6 +265,7 @@ definitions:
|
|||
- SourceTypeDiscordBot
|
||||
- SourceTypeWechatOfficialAccount
|
||||
- SourceTypeOpenAIAPI
|
||||
- SourceTypeMcpServer
|
||||
consts.StatDay:
|
||||
enum:
|
||||
- 1
|
||||
|
|
@ -406,8 +420,6 @@ definitions:
|
|||
allOf:
|
||||
- $ref: '#/definitions/domain.AIFeedbackSettings'
|
||||
description: AI feedback
|
||||
auto_sitemap:
|
||||
type: boolean
|
||||
body_code:
|
||||
type: string
|
||||
btns:
|
||||
|
|
@ -419,6 +431,8 @@ definitions:
|
|||
description: catalog settings
|
||||
contribute_settings:
|
||||
$ref: '#/definitions/domain.ContributeSettings'
|
||||
conversation_setting:
|
||||
$ref: '#/definitions/domain.ConversationSetting'
|
||||
copy_setting:
|
||||
allOf:
|
||||
- $ref: '#/definitions/consts.CopySetting'
|
||||
|
|
@ -474,6 +488,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'
|
||||
|
|
@ -581,8 +599,6 @@ definitions:
|
|||
allOf:
|
||||
- $ref: '#/definitions/domain.AIFeedbackSettings'
|
||||
description: AI feedback
|
||||
auto_sitemap:
|
||||
type: boolean
|
||||
body_code:
|
||||
type: string
|
||||
btns:
|
||||
|
|
@ -594,6 +610,8 @@ definitions:
|
|||
description: catalog settings
|
||||
contribute_settings:
|
||||
$ref: '#/definitions/domain.ContributeSettings'
|
||||
conversation_setting:
|
||||
$ref: '#/definitions/domain.ConversationSetting'
|
||||
copy_setting:
|
||||
$ref: '#/definitions/consts.CopySetting'
|
||||
desc:
|
||||
|
|
@ -644,6 +662,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'
|
||||
|
|
@ -751,6 +773,7 @@ definitions:
|
|||
- 9
|
||||
- 10
|
||||
- 11
|
||||
- 12
|
||||
format: int32
|
||||
type: integer
|
||||
x-enum-varnames:
|
||||
|
|
@ -765,6 +788,7 @@ definitions:
|
|||
- AppTypeOpenAIAPI
|
||||
- AppTypeWecomAIBot
|
||||
- AppTypeLarkBot
|
||||
- AppTypeMcpServer
|
||||
domain.AuthUserInfo:
|
||||
properties:
|
||||
avatar_url:
|
||||
|
|
@ -1206,6 +1230,13 @@ definitions:
|
|||
url:
|
||||
type: string
|
||||
type: object
|
||||
domain.ConversationSetting:
|
||||
properties:
|
||||
copyright_hide_enabled:
|
||||
type: boolean
|
||||
copyright_info:
|
||||
type: string
|
||||
type: object
|
||||
domain.CreateKBReleaseReq:
|
||||
properties:
|
||||
kb_id:
|
||||
|
|
@ -1602,6 +1633,24 @@ definitions:
|
|||
url:
|
||||
type: string
|
||||
type: object
|
||||
domain.MCPServerSettings:
|
||||
properties:
|
||||
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:
|
||||
enum:
|
||||
- 1
|
||||
|
|
@ -1628,6 +1677,22 @@ definitions:
|
|||
type:
|
||||
type: string
|
||||
type: object
|
||||
domain.ModelModeSetting:
|
||||
properties:
|
||||
auto_mode_api_key:
|
||||
description: 百智云 API Key
|
||||
type: string
|
||||
chat_model:
|
||||
description: 自定义对话模型名称
|
||||
type: string
|
||||
is_manual_embedding_updated:
|
||||
description: 手动模式下嵌入模型是否更新
|
||||
type: boolean
|
||||
mode:
|
||||
allOf:
|
||||
- $ref: '#/definitions/consts.ModelSettingMode'
|
||||
description: '模式: manual 或 auto'
|
||||
type: object
|
||||
domain.ModelType:
|
||||
enum:
|
||||
- chat
|
||||
|
|
@ -1733,6 +1798,8 @@ definitions:
|
|||
$ref: '#/definitions/domain.NodePermissions'
|
||||
position:
|
||||
type: number
|
||||
publisher_id:
|
||||
type: string
|
||||
rag_info:
|
||||
$ref: '#/definitions/domain.RagInfo'
|
||||
status:
|
||||
|
|
@ -1847,6 +1914,8 @@ definitions:
|
|||
type: array
|
||||
stream:
|
||||
type: boolean
|
||||
stream_options:
|
||||
$ref: '#/definitions/domain.OpenAIStreamOptions'
|
||||
temperature:
|
||||
type: number
|
||||
tool_choice:
|
||||
|
|
@ -1928,7 +1997,7 @@ definitions:
|
|||
domain.OpenAIMessage:
|
||||
properties:
|
||||
content:
|
||||
type: string
|
||||
$ref: '#/definitions/domain.MessageContent'
|
||||
name:
|
||||
type: string
|
||||
role:
|
||||
|
|
@ -1949,6 +2018,11 @@ definitions:
|
|||
required:
|
||||
- type
|
||||
type: object
|
||||
domain.OpenAIStreamOptions:
|
||||
properties:
|
||||
include_usage:
|
||||
type: boolean
|
||||
type: object
|
||||
domain.OpenAITool:
|
||||
properties:
|
||||
function:
|
||||
|
|
@ -2122,6 +2196,31 @@ definitions:
|
|||
role:
|
||||
$ref: '#/definitions/schema.RoleType'
|
||||
type: object
|
||||
domain.ShareNodeDetailItem:
|
||||
properties:
|
||||
children:
|
||||
items:
|
||||
$ref: '#/definitions/domain.ShareNodeDetailItem'
|
||||
type: array
|
||||
emoji:
|
||||
type: string
|
||||
id:
|
||||
type: string
|
||||
meta:
|
||||
$ref: '#/definitions/domain.NodeMeta'
|
||||
name:
|
||||
type: string
|
||||
parent_id:
|
||||
type: string
|
||||
permissions:
|
||||
$ref: '#/definitions/domain.NodePermissions'
|
||||
position:
|
||||
type: number
|
||||
type:
|
||||
$ref: '#/definitions/domain.NodeType'
|
||||
updated_at:
|
||||
type: string
|
||||
type: object
|
||||
domain.SimpleAuth:
|
||||
properties:
|
||||
enabled:
|
||||
|
|
@ -2178,6 +2277,27 @@ definitions:
|
|||
- StatPageSceneNodeDetail
|
||||
- StatPageSceneChat
|
||||
- StatPageSceneLogin
|
||||
domain.SwitchModeReq:
|
||||
properties:
|
||||
auto_mode_api_key:
|
||||
description: 百智云 API Key
|
||||
type: string
|
||||
chat_model:
|
||||
description: 自定义对话模型名称
|
||||
type: string
|
||||
mode:
|
||||
enum:
|
||||
- manual
|
||||
- auto
|
||||
type: string
|
||||
required:
|
||||
- mode
|
||||
type: object
|
||||
domain.SwitchModeResp:
|
||||
properties:
|
||||
message:
|
||||
type: string
|
||||
type: object
|
||||
domain.TextConfig:
|
||||
properties:
|
||||
title:
|
||||
|
|
@ -2443,12 +2563,28 @@ definitions:
|
|||
type: object
|
||||
domain.WidgetBotSettings:
|
||||
properties:
|
||||
btn_id:
|
||||
type: string
|
||||
btn_logo:
|
||||
type: string
|
||||
btn_position:
|
||||
type: string
|
||||
btn_style:
|
||||
type: string
|
||||
btn_text:
|
||||
type: string
|
||||
copyright_hide_enabled:
|
||||
type: boolean
|
||||
copyright_info:
|
||||
type: string
|
||||
disclaimer:
|
||||
type: string
|
||||
is_open:
|
||||
type: boolean
|
||||
modal_position:
|
||||
type: string
|
||||
placeholder:
|
||||
type: string
|
||||
recommend_node_ids:
|
||||
items:
|
||||
type: string
|
||||
|
|
@ -2457,6 +2593,8 @@ definitions:
|
|||
items:
|
||||
type: string
|
||||
type: array
|
||||
search_mode:
|
||||
type: string
|
||||
theme_mode:
|
||||
type: string
|
||||
type: object
|
||||
|
|
@ -2986,6 +3124,21 @@ definitions:
|
|||
$ref: '#/definitions/domain.NodeGroupDetail'
|
||||
type: array
|
||||
type: object
|
||||
v1.NodeRestudyReq:
|
||||
properties:
|
||||
kb_id:
|
||||
type: string
|
||||
node_ids:
|
||||
items:
|
||||
type: string
|
||||
minItems: 1
|
||||
type: array
|
||||
required:
|
||||
- kb_id
|
||||
- node_ids
|
||||
type: object
|
||||
v1.NodeRestudyResp:
|
||||
type: object
|
||||
v1.ResetPasswordReq:
|
||||
properties:
|
||||
id:
|
||||
|
|
@ -3015,6 +3168,10 @@ definitions:
|
|||
type: string
|
||||
kb_id:
|
||||
type: string
|
||||
list:
|
||||
items:
|
||||
$ref: '#/definitions/domain.ShareNodeDetailItem'
|
||||
type: array
|
||||
meta:
|
||||
$ref: '#/definitions/domain.NodeMeta'
|
||||
name:
|
||||
|
|
@ -3226,6 +3383,7 @@ paths:
|
|||
- discord_bot
|
||||
- wechat_official_account
|
||||
- openai_api
|
||||
- mcp_server
|
||||
in: query
|
||||
name: source_type
|
||||
required: true
|
||||
|
|
@ -3248,6 +3406,7 @@ paths:
|
|||
- SourceTypeDiscordBot
|
||||
- SourceTypeWechatOfficialAccount
|
||||
- SourceTypeOpenAIAPI
|
||||
- SourceTypeMcpServer
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
|
|
@ -4050,6 +4209,27 @@ paths:
|
|||
summary: get model list
|
||||
tags:
|
||||
- model
|
||||
/api/v1/model/mode-setting:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: get current model mode setting including mode, API key and chat
|
||||
model
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/domain.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/domain.ModelModeSetting'
|
||||
type: object
|
||||
summary: get model mode setting
|
||||
tags:
|
||||
- model
|
||||
/api/v1/model/provider/supported:
|
||||
post:
|
||||
consumes:
|
||||
|
|
@ -4077,6 +4257,33 @@ paths:
|
|||
summary: get provider supported model list
|
||||
tags:
|
||||
- model
|
||||
/api/v1/model/switch-mode:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: switch model mode between manual and auto
|
||||
parameters:
|
||||
- description: switch mode request
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.SwitchModeReq'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/domain.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/domain.SwitchModeResp'
|
||||
type: object
|
||||
summary: switch mode
|
||||
tags:
|
||||
- model
|
||||
/api/v1/node:
|
||||
post:
|
||||
consumes:
|
||||
|
|
@ -4374,6 +4581,36 @@ paths:
|
|||
summary: Recommend Nodes
|
||||
tags:
|
||||
- node
|
||||
/api/v1/node/restudy:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: 文档重新学习
|
||||
operationId: v1-NodeRestudy
|
||||
parameters:
|
||||
- description: para
|
||||
in: body
|
||||
name: param
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/v1.NodeRestudyReq'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/domain.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/v1.NodeRestudyResp'
|
||||
type: object
|
||||
security:
|
||||
- bearerAuth: []
|
||||
summary: 文档重新学习
|
||||
tags:
|
||||
- Node
|
||||
/api/v1/node/summary:
|
||||
post:
|
||||
consumes:
|
||||
|
|
@ -5158,7 +5395,34 @@ paths:
|
|||
$ref: '#/definitions/domain.Response'
|
||||
summary: ChatWidget
|
||||
tags:
|
||||
- share_chat
|
||||
- Widget
|
||||
/share/v1/chat/widget/search:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: WidgetSearch
|
||||
parameters:
|
||||
- description: Comment
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.ChatSearchReq'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/domain.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/domain.ChatSearchResp'
|
||||
type: object
|
||||
summary: WidgetSearch
|
||||
tags:
|
||||
- Widget
|
||||
/share/v1/comment:
|
||||
post:
|
||||
consumes:
|
||||
|
|
|
|||
|
|
@ -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 ""
|
||||
}
|
||||
|
|
@ -94,7 +98,6 @@ type AppSettings struct {
|
|||
// seo
|
||||
Desc string `json:"desc,omitempty"`
|
||||
Keyword string `json:"keyword,omitempty"`
|
||||
AutoSitemap bool `json:"auto_sitemap,omitempty"`
|
||||
// inject code
|
||||
HeadCode string `json:"head_code,omitempty"`
|
||||
BodyCode string `json:"body_code,omitempty"`
|
||||
|
|
@ -166,12 +169,31 @@ type AppSettings struct {
|
|||
CopySetting consts.CopySetting `json:"copy_setting" validate:"omitempty,oneof='' append disabled"`
|
||||
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 {
|
||||
CopyrightInfo string `json:"copyright_info"`
|
||||
CopyrightHideEnabled bool `json:"copyright_hide_enabled"`
|
||||
}
|
||||
|
||||
type WebAppLandingTheme struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type MCPServerSettings struct {
|
||||
IsEnabled bool `json:"is_enabled"`
|
||||
DocsToolSettings MCPToolSettings `json:"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"`
|
||||
|
|
@ -405,6 +427,15 @@ type WidgetBotSettings struct {
|
|||
BtnLogo string `json:"btn_logo,omitempty"`
|
||||
RecommendQuestions []string `json:"recommend_questions,omitempty"`
|
||||
RecommendNodeIDs []string `json:"recommend_node_ids,omitempty"`
|
||||
BtnStyle string `json:"btn_style,omitempty"`
|
||||
BtnID string `json:"btn_id,omitempty"`
|
||||
BtnPosition string `json:"btn_position,omitempty"`
|
||||
ModalPosition string `json:"modal_position,omitempty"`
|
||||
SearchMode string `json:"search_mode,omitempty"`
|
||||
Placeholder string `json:"placeholder,omitempty"`
|
||||
Disclaimer string `json:"disclaimer,omitempty"`
|
||||
CopyrightInfo string `json:"copyright_info,omitempty"`
|
||||
CopyrightHideEnabled bool `json:"copyright_hide_enabled,omitempty"`
|
||||
}
|
||||
|
||||
type BrandGroup struct {
|
||||
|
|
@ -454,7 +485,6 @@ type AppSettingsResp struct {
|
|||
// seo
|
||||
Desc string `json:"desc,omitempty"`
|
||||
Keyword string `json:"keyword,omitempty"`
|
||||
AutoSitemap bool `json:"auto_sitemap,omitempty"`
|
||||
// inject code
|
||||
HeadCode string `json:"head_code,omitempty"`
|
||||
BodyCode string `json:"body_code,omitempty"`
|
||||
|
|
@ -528,6 +558,9 @@ type AppSettingsResp struct {
|
|||
WebAppLandingConfigs []WebAppLandingConfigResp `json:"web_app_landing_configs,omitempty"`
|
||||
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,44 @@
|
|||
package domain
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
const ContextKeyEditionLimitation contextKey = "edition_limitation"
|
||||
|
||||
type BaseEditionLimitation struct {
|
||||
MaxKb int `json:"max_kb"` // 知识库站点数量
|
||||
MaxNode int `json:"max_node"` // 单个知识库下文档数量
|
||||
MaxSSOUser int `json:"max_sso_users"` // SSO认证用户数量
|
||||
MaxAdmin int64 `json:"max_admin"` // 后台管理员数量
|
||||
AllowAdminPerm bool `json:"allow_admin_perm"` // 支持管理员分权控制
|
||||
AllowCustomCopyright bool `json:"allow_custom_copyright"` // 支持自定义版权信息
|
||||
AllowCommentAudit bool `json:"allow_comment_audit"` // 支持评论审核
|
||||
AllowAdvancedBot bool `json:"allow_advanced_bot"` // 支持高级机器人配置
|
||||
AllowWatermark bool `json:"allow_watermark"` // 支持水印
|
||||
AllowCopyProtection bool `json:"allow_copy_protection"` // 支持内容复制保护
|
||||
AllowOpenAIBotSettings bool `json:"allow_open_ai_bot_settings"` // 支持问答机器人
|
||||
AllowMCPServer bool `json:"allow_mcp_server"` // 支持创建MCP Server
|
||||
}
|
||||
|
||||
var baseEditionLimitationDefault = BaseEditionLimitation{
|
||||
MaxKb: 1,
|
||||
MaxAdmin: 1,
|
||||
MaxNode: 300,
|
||||
}
|
||||
|
||||
func GetBaseEditionLimitation(c context.Context) BaseEditionLimitation {
|
||||
|
||||
edition, ok := c.Value(ContextKeyEditionLimitation).([]byte)
|
||||
if !ok {
|
||||
return baseEditionLimitationDefault
|
||||
}
|
||||
|
||||
var editionLimitation BaseEditionLimitation
|
||||
if err := json.Unmarshal(edition, &editionLimitation); err != nil {
|
||||
return baseEditionLimitationDefault
|
||||
}
|
||||
|
||||
return editionLimitation
|
||||
}
|
||||
|
|
@ -165,3 +165,13 @@ type ProviderModelListItem struct {
|
|||
type ActivateModelReq struct {
|
||||
ModelID string `json:"model_id" validate:"required"`
|
||||
}
|
||||
|
||||
type SwitchModeReq struct {
|
||||
Mode string `json:"mode" validate:"required,oneof=manual auto"`
|
||||
AutoModeAPIKey string `json:"auto_mode_api_key"` // 百智云 API Key
|
||||
ChatModel string `json:"chat_model"` // 自定义对话模型名称
|
||||
}
|
||||
|
||||
type SwitchModeResp struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,6 +174,7 @@ type NodeListItemResp struct {
|
|||
EditorId string `json:"editor_id"`
|
||||
Creator string `json:"creator"`
|
||||
Editor string `json:"editor"`
|
||||
PublisherId string `json:"publisher_id" gorm:"-"`
|
||||
Permissions NodePermissions `json:"permissions" gorm:"type:jsonb"`
|
||||
}
|
||||
|
||||
|
|
@ -251,10 +252,24 @@ type ShareNodeListItemResp struct {
|
|||
ParentID string `json:"parent_id"`
|
||||
Position float64 `json:"position"`
|
||||
Emoji string `json:"emoji"`
|
||||
Meta NodeMeta `json:"meta"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Permissions NodePermissions `json:"permissions" gorm:"type:jsonb"`
|
||||
}
|
||||
|
||||
type ShareNodeDetailItem struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type NodeType `json:"type"`
|
||||
ParentID string `json:"parent_id"`
|
||||
Position float64 `json:"position"`
|
||||
Emoji string `json:"emoji"`
|
||||
Meta NodeMeta `json:"meta"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Permissions NodePermissions `json:"permissions" gorm:"type:jsonb"`
|
||||
Children []*ShareNodeDetailItem `json:"children,omitempty"`
|
||||
}
|
||||
|
||||
func (n *ShareNodeListItemResp) GetURL(baseURL string) string {
|
||||
return fmt.Sprintf("%s/node/%s", baseURL, n.ID)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,17 @@
|
|||
package domain
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// OpenAI API 请求结构体
|
||||
type OpenAICompletionsRequest struct {
|
||||
Model string `json:"model" validate:"required"`
|
||||
Messages []OpenAIMessage `json:"messages" validate:"required"`
|
||||
Stream bool `json:"stream,omitempty"`
|
||||
StreamOptions *OpenAIStreamOptions `json:"stream_options,omitempty"`
|
||||
Temperature *float64 `json:"temperature,omitempty"`
|
||||
MaxTokens *int `json:"max_tokens,omitempty"`
|
||||
TopP *float64 `json:"top_p,omitempty"`
|
||||
|
|
@ -17,9 +24,95 @@ type OpenAICompletionsRequest struct {
|
|||
ResponseFormat *OpenAIResponseFormat `json:"response_format,omitempty"`
|
||||
}
|
||||
|
||||
type OpenAIStreamOptions struct {
|
||||
IncludeUsage bool `json:"include_usage,omitempty"`
|
||||
}
|
||||
|
||||
// MessageContent 支持字符串或内容数组
|
||||
type MessageContent struct {
|
||||
isString bool
|
||||
strValue string
|
||||
arrValue []OpenAIContentPart
|
||||
}
|
||||
|
||||
// OpenAIContentPart 表示内容数组中的单个元素
|
||||
type OpenAIContentPart struct {
|
||||
Type string `json:"type"`
|
||||
Text string `json:"text,omitempty"`
|
||||
ImageURL *OpenAIContentPartURL `json:"image_url,omitempty"`
|
||||
}
|
||||
|
||||
// OpenAIContentPartURL represents the image_url field in content parts
|
||||
type OpenAIContentPartURL struct {
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON 自定义解析,支持 string 或 array 格式
|
||||
func (mc *MessageContent) UnmarshalJSON(data []byte) error {
|
||||
// 尝试解析为字符串
|
||||
var str string
|
||||
if err := json.Unmarshal(data, &str); err == nil {
|
||||
mc.isString = true
|
||||
mc.strValue = str
|
||||
return nil
|
||||
}
|
||||
|
||||
// 尝试解析为数组
|
||||
var arr []OpenAIContentPart
|
||||
if err := json.Unmarshal(data, &arr); err == nil {
|
||||
mc.isString = false
|
||||
mc.arrValue = arr
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("content must be string or array")
|
||||
}
|
||||
|
||||
// MarshalJSON 自定义序列化
|
||||
func (mc *MessageContent) MarshalJSON() ([]byte, error) {
|
||||
if mc.isString {
|
||||
return json.Marshal(mc.strValue)
|
||||
}
|
||||
return json.Marshal(mc.arrValue)
|
||||
}
|
||||
|
||||
// NewStringContent 创建字符串类型的 MessageContent
|
||||
func NewStringContent(s string) *MessageContent {
|
||||
return &MessageContent{
|
||||
isString: true,
|
||||
strValue: s,
|
||||
}
|
||||
}
|
||||
|
||||
// NewArrayContent 创建数组类型的 MessageContent
|
||||
func NewArrayContent(parts []OpenAIContentPart) *MessageContent {
|
||||
return &MessageContent{
|
||||
isString: false,
|
||||
arrValue: parts,
|
||||
}
|
||||
}
|
||||
|
||||
// String 获取文本内容
|
||||
func (mc *MessageContent) String() string {
|
||||
if mc.isString {
|
||||
return mc.strValue
|
||||
}
|
||||
// 从数组中提取文本
|
||||
var builder strings.Builder
|
||||
for _, part := range mc.arrValue {
|
||||
if part.Type == "text" {
|
||||
if builder.Len() > 0 && part.Text != "" {
|
||||
builder.WriteString(" ")
|
||||
}
|
||||
builder.WriteString(part.Text)
|
||||
}
|
||||
}
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
type OpenAIMessage struct {
|
||||
Role string `json:"role" validate:"required"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Content *MessageContent `json:"content,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
ToolCalls []OpenAIToolCall `json:"tool_calls,omitempty"`
|
||||
ToolCallID string `json:"tool_call_id,omitempty"`
|
||||
|
|
@ -90,6 +183,7 @@ type OpenAIStreamResponse struct {
|
|||
Created int64 `json:"created"`
|
||||
Model string `json:"model"`
|
||||
Choices []OpenAIStreamChoice `json:"choices"`
|
||||
Usage *OpenAIUsage `json:"usage,omitempty"`
|
||||
}
|
||||
|
||||
type OpenAIStreamChoice struct {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,186 @@
|
|||
package domain
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestMessageContent_UnmarshalJSON_String(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
json string
|
||||
expected string
|
||||
}{
|
||||
{"simple string", `"hello"`, "hello"},
|
||||
{"with quotes", `"say \"hello\""`, `say "hello"`},
|
||||
{"with newline", `"line1\nline2"`, "line1\nline2"},
|
||||
{"empty string", `""`, ""},
|
||||
{"unicode", `"你好 🌍"`, "你好 🌍"},
|
||||
{"special chars", `"Hello \"World\"\nNew Line\tTab"`, "Hello \"World\"\nNew Line\tTab"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var mc MessageContent
|
||||
err := json.Unmarshal([]byte(tt.json), &mc)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.expected, mc.String())
|
||||
assert.True(t, mc.isString)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageContent_UnmarshalJSON_Array(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
json string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
"single text part",
|
||||
`[{"type":"text","text":"Hello"}]`,
|
||||
"Hello",
|
||||
},
|
||||
{
|
||||
"multiple text parts",
|
||||
`[{"type":"text","text":"Hello"},{"type":"text","text":"World"}]`,
|
||||
"Hello World",
|
||||
},
|
||||
{
|
||||
"mixed types with image",
|
||||
`[{"type":"text","text":"Look at this"},{"type":"image_url","image_url":{"url":"https://example.com/img.png"}},{"type":"text","text":"image"}]`,
|
||||
"Look at this image",
|
||||
},
|
||||
{
|
||||
"empty array",
|
||||
`[]`,
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var mc MessageContent
|
||||
err := json.Unmarshal([]byte(tt.json), &mc)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.expected, mc.String())
|
||||
assert.False(t, mc.isString)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageContent_UnmarshalJSON_Invalid(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
json string
|
||||
}{
|
||||
{"number", `123`},
|
||||
{"boolean", `true`},
|
||||
{"object", `{"key":"value"}`},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var mc MessageContent
|
||||
err := json.Unmarshal([]byte(tt.json), &mc)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "content must be string or array")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageContent_UnmarshalJSON_Null(t *testing.T) {
|
||||
var mc *MessageContent
|
||||
err := json.Unmarshal([]byte(`null`), &mc)
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, mc)
|
||||
}
|
||||
|
||||
func TestMessageContent_MarshalJSON_String(t *testing.T) {
|
||||
mc := NewStringContent("Hello World")
|
||||
data, err := json.Marshal(mc)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, `"Hello World"`, string(data))
|
||||
}
|
||||
|
||||
func TestMessageContent_MarshalJSON_Array(t *testing.T) {
|
||||
mc := NewArrayContent([]OpenAIContentPart{
|
||||
{Type: "text", Text: "Hello"},
|
||||
{Type: "text", Text: "World"},
|
||||
})
|
||||
data, err := json.Marshal(mc)
|
||||
require.NoError(t, err)
|
||||
assert.JSONEq(t, `[{"type":"text","text":"Hello"},{"type":"text","text":"World"}]`, string(data))
|
||||
}
|
||||
|
||||
func TestMessageContent_Roundtrip_String(t *testing.T) {
|
||||
original := NewStringContent("Test message with \"quotes\" and \nnewlines")
|
||||
|
||||
// Marshal
|
||||
data, err := json.Marshal(original)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Unmarshal
|
||||
var decoded MessageContent
|
||||
err = json.Unmarshal(data, &decoded)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify
|
||||
assert.Equal(t, original.String(), decoded.String())
|
||||
assert.Equal(t, original.isString, decoded.isString)
|
||||
}
|
||||
|
||||
func TestMessageContent_Roundtrip_Array(t *testing.T) {
|
||||
parts := []OpenAIContentPart{
|
||||
{Type: "text", Text: "Part 1"},
|
||||
{Type: "text", Text: "Part 2"},
|
||||
}
|
||||
original := NewArrayContent(parts)
|
||||
|
||||
// Marshal
|
||||
data, err := json.Marshal(original)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Unmarshal
|
||||
var decoded MessageContent
|
||||
err = json.Unmarshal(data, &decoded)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify
|
||||
assert.Equal(t, original.String(), decoded.String())
|
||||
assert.Equal(t, original.isString, decoded.isString)
|
||||
}
|
||||
|
||||
func TestNewStringContent(t *testing.T) {
|
||||
mc := NewStringContent("test")
|
||||
assert.NotNil(t, mc)
|
||||
assert.True(t, mc.isString)
|
||||
assert.Equal(t, "test", mc.strValue)
|
||||
assert.Equal(t, "test", mc.String())
|
||||
}
|
||||
|
||||
func TestNewArrayContent(t *testing.T) {
|
||||
parts := []OpenAIContentPart{
|
||||
{Type: "text", Text: "Hello"},
|
||||
}
|
||||
mc := NewArrayContent(parts)
|
||||
assert.NotNil(t, mc)
|
||||
assert.False(t, mc.isString)
|
||||
assert.Equal(t, parts, mc.arrValue)
|
||||
assert.Equal(t, "Hello", mc.String())
|
||||
}
|
||||
|
||||
func TestMessageContent_String_EmptyArray(t *testing.T) {
|
||||
mc := NewArrayContent([]OpenAIContentPart{})
|
||||
assert.Equal(t, "", mc.String())
|
||||
}
|
||||
|
||||
func TestMessageContent_String_NoTextParts(t *testing.T) {
|
||||
mc := NewArrayContent([]OpenAIContentPart{
|
||||
{Type: "image_url", Text: ""},
|
||||
})
|
||||
assert.Equal(t, "", mc.String())
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ import (
|
|||
const (
|
||||
SettingKeySystemPrompt = "system_prompt"
|
||||
SettingBlockWords = "block_words"
|
||||
SettingCopyrightInfo = "本网站由 PandaWiki 提供技术支持"
|
||||
)
|
||||
|
||||
// table: settings
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
package domain
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/chaitin/panda-wiki/consts"
|
||||
)
|
||||
|
||||
// table: settings
|
||||
type SystemSetting struct {
|
||||
ID int `json:"id" gorm:"primary_key"`
|
||||
Key consts.SystemSettingKey `json:"key"`
|
||||
Value []byte `json:"value" gorm:"type:jsonb"` // JSON string
|
||||
Description string `json:"description"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (SystemSetting) TableName() string {
|
||||
return "system_settings"
|
||||
}
|
||||
|
||||
// ModelModeSetting 模型配置结构体
|
||||
type ModelModeSetting struct {
|
||||
Mode consts.ModelSettingMode `json:"mode"` // 模式: manual 或 auto
|
||||
AutoModeAPIKey string `json:"auto_mode_api_key"` // 百智云 API Key
|
||||
ChatModel string `json:"chat_model"` // 自定义对话模型名称
|
||||
IsManualEmbeddingUpdated bool `json:"is_manual_embedding_updated"` // 手动模式下嵌入模型是否更新
|
||||
}
|
||||
|
|
@ -35,6 +35,7 @@ require (
|
|||
github.com/larksuite/oapi-sdk-go/v3 v3.4.20
|
||||
github.com/lib/pq v1.10.9
|
||||
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20250508043914-ed57fa5c5274
|
||||
github.com/mark3labs/mcp-go v0.43.0
|
||||
github.com/microcosm-cc/bluemonday v1.0.27
|
||||
github.com/mileusna/useragent v1.3.5
|
||||
github.com/minio/minio-go/v7 v7.0.91
|
||||
|
|
@ -49,6 +50,7 @@ require (
|
|||
github.com/sbzhu/weworkapi_golang v0.0.0-20210525081115-1799804a7c8d
|
||||
github.com/silenceper/wechat/v2 v2.1.9
|
||||
github.com/spf13/viper v1.20.1
|
||||
github.com/stretchr/testify v1.10.0
|
||||
github.com/swaggo/echo-swagger v1.4.1
|
||||
github.com/swaggo/swag v1.16.5
|
||||
github.com/tidwall/gjson v1.14.1
|
||||
|
|
@ -98,6 +100,7 @@ require (
|
|||
github.com/cloudwego/eino-ext/components/model/openai v0.0.0-20250710065240-482d48888f25 // indirect
|
||||
github.com/cloudwego/eino-ext/libs/acl/openai v0.0.0-20250626133421-3c142631c961 // indirect
|
||||
github.com/cohesion-org/deepseek-go v1.2.8 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/dlclark/regexp2 v1.11.4 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
|
|
@ -135,6 +138,7 @@ require (
|
|||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/invopop/jsonschema v0.13.0 // indirect
|
||||
github.com/invopop/yaml v0.1.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
|
|
@ -165,6 +169,7 @@ require (
|
|||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/perimeterx/marshmallow v1.1.5 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rs/xid v1.6.0 // indirect
|
||||
github.com/sagikazarmark/locafero v0.9.0 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
|
|
@ -183,6 +188,7 @@ require (
|
|||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
|
||||
github.com/yargevad/filepathx v1.0.0 // indirect
|
||||
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
|
||||
|
|
|
|||
|
|
@ -321,6 +321,8 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C
|
|||
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
|
||||
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
|
||||
github.com/invopop/yaml v0.1.0 h1:YW3WGUoJEXYfzWBjn00zIlrw7brGVD0fUKRYDPAPhrc=
|
||||
github.com/invopop/yaml v0.1.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
|
|
@ -396,6 +398,8 @@ github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN
|
|||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
|
||||
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
|
||||
github.com/mark3labs/mcp-go v0.43.0 h1:lgiKcWMddh4sngbU+hoWOZ9iAe/qp/m851RQpj3Y7jA=
|
||||
github.com/mark3labs/mcp-go v0.43.0/go.mod h1:YnJfOL382MIWDx1kMY+2zsRHU/q78dBg9aFb8W6Thdw=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
|
|
@ -576,6 +580,8 @@ github.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJ
|
|||
github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE=
|
||||
github.com/yargevad/filepathx v1.0.0 h1:SYcT+N3tYGi+NvazubCNlvgIPbzAk7i7y2dwg3I5FYc=
|
||||
github.com/yargevad/filepathx v1.0.0/go.mod h1:BprfX/gpYNJHJfc35GjRRpVcwWXS89gGulUIU5tK3tA=
|
||||
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
|
||||
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.30/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ var ProviderSet = wire.NewSet(
|
|||
usecase.NewLLMUsecase,
|
||||
usecase.NewStatUseCase,
|
||||
usecase.NewNodeUsecase,
|
||||
usecase.NewModelUsecase,
|
||||
|
||||
NewRAGMQHandler,
|
||||
NewRagDocUpdateHandler,
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@ type RAGMQHandler struct {
|
|||
rag rag.RAGService
|
||||
nodeRepo *pg.NodeRepository
|
||||
kbRepo *pg.KnowledgeBaseRepository
|
||||
modelRepo *pg.ModelRepository
|
||||
llmUsecase *usecase.LLMUsecase
|
||||
modelUsecase *usecase.ModelUsecase
|
||||
}
|
||||
|
||||
func NewRAGMQHandler(consumer mq.MQConsumer, logger *log.Logger, rag rag.RAGService, nodeRepo *pg.NodeRepository, kbRepo *pg.KnowledgeBaseRepository, llmUsecase *usecase.LLMUsecase, modelRepo *pg.ModelRepository) (*RAGMQHandler, error) {
|
||||
func NewRAGMQHandler(consumer mq.MQConsumer, logger *log.Logger, rag rag.RAGService, nodeRepo *pg.NodeRepository, kbRepo *pg.KnowledgeBaseRepository, llmUsecase *usecase.LLMUsecase, modelUsecase *usecase.ModelUsecase) (*RAGMQHandler, error) {
|
||||
h := &RAGMQHandler{
|
||||
consumer: consumer,
|
||||
logger: logger.WithModule("mq.rag"),
|
||||
|
|
@ -32,7 +32,7 @@ func NewRAGMQHandler(consumer mq.MQConsumer, logger *log.Logger, rag rag.RAGServ
|
|||
nodeRepo: nodeRepo,
|
||||
kbRepo: kbRepo,
|
||||
llmUsecase: llmUsecase,
|
||||
modelRepo: modelRepo,
|
||||
modelUsecase: modelUsecase,
|
||||
}
|
||||
if err := consumer.RegisterHandler(domain.VectorTaskTopic, h.HandleNodeContentVectorRequest); err != nil {
|
||||
return nil, err
|
||||
|
|
@ -134,11 +134,13 @@ func (h *RAGMQHandler) HandleNodeContentVectorRequest(ctx context.Context, msg t
|
|||
h.logger.Info("node is folder, skip summary", log.Any("node_id", request.NodeID))
|
||||
return nil
|
||||
}
|
||||
model, err := h.modelRepo.GetChatModel(ctx)
|
||||
|
||||
model, err := h.modelUsecase.GetChatModel(ctx)
|
||||
if err != nil {
|
||||
h.logger.Error("get chat model failed", log.Error(err))
|
||||
return nil
|
||||
}
|
||||
|
||||
summary, err := h.llmUsecase.SummaryNode(ctx, model, node.Name, node.Content)
|
||||
if err != nil {
|
||||
h.logger.Error("summary node content failed", log.Error(err))
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ func NewShareChatHandler(
|
|||
share.POST("/search", h.ChatSearch, h.ShareAuthMiddleware.Authorize)
|
||||
share.POST("/completions", h.ChatCompletions)
|
||||
share.POST("/widget", h.ChatWidget)
|
||||
share.POST("/widget/search", h.WidgetSearch)
|
||||
share.POST("/feedback", h.FeedBack)
|
||||
return h
|
||||
}
|
||||
|
|
@ -131,7 +132,7 @@ func (h *ShareChatHandler) ChatMessage(c echo.Context) error {
|
|||
//
|
||||
// @Summary ChatWidget
|
||||
// @Description ChatWidget
|
||||
// @Tags share_chat
|
||||
// @Tags Widget
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param app_type query string true "app type"
|
||||
|
|
@ -268,7 +269,9 @@ func (h *ShareChatHandler) ChatCompletions(c echo.Context) error {
|
|||
var lastUserMessage string
|
||||
for i := len(req.Messages) - 1; i >= 0; i-- {
|
||||
if req.Messages[i].Role == "user" {
|
||||
lastUserMessage = req.Messages[i].Content
|
||||
if req.Messages[i].Content != nil {
|
||||
lastUserMessage = req.Messages[i].Content.String()
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -345,11 +348,12 @@ func (h *ShareChatHandler) handleOpenAIStreamResponse(c echo.Context, eventCh <-
|
|||
Index: 0,
|
||||
Delta: domain.OpenAIMessage{
|
||||
Role: "assistant",
|
||||
Content: event.Content,
|
||||
Content: domain.NewStringContent(event.Content),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if err := h.writeOpenAIStreamEvent(c, streamResp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -397,7 +401,7 @@ func (h *ShareChatHandler) handleOpenAINonStreamResponse(c echo.Context, eventCh
|
|||
Index: 0,
|
||||
Message: domain.OpenAIMessage{
|
||||
Role: "assistant",
|
||||
Content: content,
|
||||
Content: domain.NewStringContent(content),
|
||||
},
|
||||
FinishReason: "stop",
|
||||
},
|
||||
|
|
@ -441,7 +445,7 @@ func stringPtr(s string) *string {
|
|||
return &s
|
||||
}
|
||||
|
||||
// ChatMessage chat search
|
||||
// ChatSearch searches chat messages in shared knowledge base
|
||||
//
|
||||
// @Summary ChatSearch
|
||||
// @Description ChatSearch
|
||||
|
|
@ -484,3 +488,43 @@ func (h *ShareChatHandler) ChatSearch(c echo.Context) error {
|
|||
}
|
||||
return h.NewResponseWithData(c, resp)
|
||||
}
|
||||
|
||||
// WidgetSearch
|
||||
//
|
||||
// @Summary WidgetSearch
|
||||
// @Description WidgetSearch
|
||||
// @Tags Widget
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body domain.ChatSearchReq true "Comment"
|
||||
// @Success 200 {object} domain.Response{data=domain.ChatSearchResp}
|
||||
// @Router /share/v1/chat/widget/search [post]
|
||||
func (h *ShareChatHandler) WidgetSearch(c echo.Context) error {
|
||||
var req domain.ChatSearchReq
|
||||
if err := c.Bind(&req); err != nil {
|
||||
return h.NewResponseWithError(c, "parse request failed", err)
|
||||
}
|
||||
req.KBID = c.Request().Header.Get("X-KB-ID")
|
||||
if err := c.Validate(&req); err != nil {
|
||||
return h.NewResponseWithError(c, "validate request failed", err)
|
||||
}
|
||||
ctx := c.Request().Context()
|
||||
|
||||
// validate widget info
|
||||
widgetAppInfo, err := h.appUsecase.GetWidgetAppInfo(c.Request().Context(), req.KBID)
|
||||
if err != nil {
|
||||
h.logger.Error("get widget app info failed", log.Error(err))
|
||||
return h.sendErrMsg(c, "get app info error")
|
||||
}
|
||||
if !widgetAppInfo.Settings.WidgetBotSettings.IsOpen {
|
||||
return h.sendErrMsg(c, "widget is not open")
|
||||
}
|
||||
|
||||
req.RemoteIP = c.RealIP()
|
||||
|
||||
resp, err := h.chatUsecase.Search(ctx, &req)
|
||||
if err != nil {
|
||||
return h.NewResponseWithError(c, "failed to search docs", err)
|
||||
}
|
||||
return h.NewResponseWithData(c, resp)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"github.com/labstack/echo/v4"
|
||||
|
||||
"github.com/chaitin/panda-wiki/consts"
|
||||
"github.com/chaitin/panda-wiki/domain"
|
||||
"github.com/chaitin/panda-wiki/handler"
|
||||
"github.com/chaitin/panda-wiki/log"
|
||||
|
|
@ -157,7 +156,7 @@ func (h *ShareCommentHandler) GetCommentList(c echo.Context) error {
|
|||
}
|
||||
|
||||
// 查询数据库获取所有评论-->0 所有, 1,2 为需要审核的评论
|
||||
commentsList, err := h.usecase.GetCommentListByNodeID(ctx, nodeID, consts.GetLicenseEdition(c))
|
||||
commentsList, err := h.usecase.GetCommentListByNodeID(ctx, nodeID)
|
||||
if err != nil {
|
||||
return h.NewResponseWithError(c, "failed to get comment list", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,5 +91,15 @@ func (h *ShareNodeHandler) GetNodeDetail(c echo.Context) error {
|
|||
if err != nil {
|
||||
return h.NewResponseWithError(c, "failed to get node detail", err)
|
||||
}
|
||||
|
||||
// If the node is a folder, return the list of child nodes
|
||||
if node.Type == domain.NodeTypeFolder {
|
||||
childNodes, err := h.usecase.GetNodeReleaseListByParentID(c.Request().Context(), kbID, id, domain.GetAuthID(c))
|
||||
if err != nil {
|
||||
return h.NewResponseWithError(c, "failed to get child nodes", err)
|
||||
}
|
||||
node.List = childNodes
|
||||
}
|
||||
|
||||
return h.NewResponseWithData(c, node)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
"github.com/labstack/echo/v4"
|
||||
|
||||
"github.com/chaitin/panda-wiki/domain"
|
||||
"github.com/chaitin/panda-wiki/handler"
|
||||
"github.com/chaitin/panda-wiki/log"
|
||||
"github.com/chaitin/panda-wiki/usecase"
|
||||
|
|
@ -37,13 +36,6 @@ func (h *ShareSitemapHandler) GetSitemap(c echo.Context) error {
|
|||
if kbID == "" {
|
||||
return h.NewResponseWithError(c, "kb_id is required", nil)
|
||||
}
|
||||
appInfo, err := h.appUsecase.ShareGetWebAppInfo(c.Request().Context(), kbID, domain.GetAuthID(c))
|
||||
if err != nil {
|
||||
return h.NewResponseWithError(c, "web app not found", err)
|
||||
}
|
||||
if !appInfo.Settings.AutoSitemap {
|
||||
return h.NewResponseWithError(c, "未开启自动生成站点地图功能", nil)
|
||||
}
|
||||
|
||||
xml, err := h.sitemapUsecase.GetSitemap(c.Request().Context(), kbID)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
v1 "github.com/chaitin/panda-wiki/api/kb/v1"
|
||||
"github.com/chaitin/panda-wiki/consts"
|
||||
"github.com/chaitin/panda-wiki/domain"
|
||||
)
|
||||
|
||||
// KBUserList
|
||||
|
|
@ -55,8 +56,8 @@ func (h *KnowledgeBaseHandler) KBUserInvite(c echo.Context) error {
|
|||
return h.NewResponseWithError(c, "validate request failed", err)
|
||||
}
|
||||
|
||||
if consts.GetLicenseEdition(c) != consts.LicenseEditionEnterprise && req.Perm != consts.UserKBPermissionFullControl {
|
||||
return h.NewResponseWithError(c, "非企业版本只能使用完全控制权限", nil)
|
||||
if !domain.GetBaseEditionLimitation(c.Request().Context()).AllowAdminPerm && req.Perm != consts.UserKBPermissionFullControl {
|
||||
return h.NewResponseWithError(c, "当前版本不支持管理员分权控制", nil)
|
||||
}
|
||||
|
||||
err := h.usecase.KBUserInvite(c.Request().Context(), req)
|
||||
|
|
@ -87,8 +88,8 @@ func (h *KnowledgeBaseHandler) KBUserUpdate(c echo.Context) error {
|
|||
return h.NewResponseWithError(c, "validate request failed", err)
|
||||
}
|
||||
|
||||
if consts.GetLicenseEdition(c) != consts.LicenseEditionEnterprise && req.Perm != consts.UserKBPermissionFullControl {
|
||||
return h.NewResponseWithError(c, "非企业版本只能使用完全控制权限", nil)
|
||||
if !domain.GetBaseEditionLimitation(c.Request().Context()).AllowAdminPerm && req.Perm != consts.UserKBPermissionFullControl {
|
||||
return h.NewResponseWithError(c, "当前版本不支持管理员分权控制", nil)
|
||||
}
|
||||
|
||||
err := h.usecase.UpdateUserKB(c.Request().Context(), req)
|
||||
|
|
|
|||
|
|
@ -91,11 +91,7 @@ func (h *KnowledgeBaseHandler) CreateKnowledgeBase(c echo.Context) error {
|
|||
return h.NewResponseWithError(c, "ports is required", nil)
|
||||
}
|
||||
|
||||
req.MaxKB = 1
|
||||
maxKB := c.Get("max_kb")
|
||||
if maxKB != nil {
|
||||
req.MaxKB = maxKB.(int)
|
||||
}
|
||||
req.MaxKB = domain.GetBaseEditionLimitation(c.Request().Context()).MaxKb
|
||||
|
||||
did, err := h.usecase.CreateKnowledgeBase(c.Request().Context(), &req)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -40,11 +40,13 @@ func NewModelHandler(echo *echo.Echo, baseHandler *handler.BaseHandler, logger *
|
|||
group.POST("/check", handler.CheckModel)
|
||||
group.POST("/provider/supported", handler.GetProviderSupportedModelList)
|
||||
group.PUT("", handler.UpdateModel)
|
||||
group.POST("/switch-mode", handler.SwitchMode)
|
||||
group.GET("/mode-setting", handler.GetModelModeSetting)
|
||||
|
||||
return handler
|
||||
}
|
||||
|
||||
// get model list
|
||||
// GetModelList
|
||||
//
|
||||
// @Summary get model list
|
||||
// @Description get model list
|
||||
|
|
@ -64,7 +66,7 @@ func (h *ModelHandler) GetModelList(c echo.Context) error {
|
|||
return h.NewResponseWithData(c, models)
|
||||
}
|
||||
|
||||
// create model
|
||||
// CreateModel
|
||||
//
|
||||
// @Summary create model
|
||||
// @Description create model
|
||||
|
|
@ -83,9 +85,6 @@ func (h *ModelHandler) CreateModel(c echo.Context) error {
|
|||
return h.NewResponseWithError(c, "invalid request", err)
|
||||
}
|
||||
|
||||
if consts.GetLicenseEdition(c) == consts.LicenseEditionContributor && req.Provider != domain.ModelProviderBrandBaiZhiCloud {
|
||||
return h.NewResponseWithError(c, "联创版只能使用百智云模型哦~", nil)
|
||||
}
|
||||
ctx := c.Request().Context()
|
||||
|
||||
param := domain.ModelParam{}
|
||||
|
|
@ -110,7 +109,7 @@ func (h *ModelHandler) CreateModel(c echo.Context) error {
|
|||
return h.NewResponseWithData(c, model)
|
||||
}
|
||||
|
||||
// update model
|
||||
// UpdateModel
|
||||
//
|
||||
// @Description update model
|
||||
// @Tags model
|
||||
|
|
@ -128,9 +127,6 @@ func (h *ModelHandler) UpdateModel(c echo.Context) error {
|
|||
return h.NewResponseWithError(c, "invalid request", err)
|
||||
}
|
||||
|
||||
if consts.GetLicenseEdition(c) == consts.LicenseEditionContributor && req.Provider != domain.ModelProviderBrandBaiZhiCloud {
|
||||
return h.NewResponseWithError(c, "联创版只能使用百智云模型哦~", nil)
|
||||
}
|
||||
ctx := c.Request().Context()
|
||||
if err := h.usecase.Update(ctx, &req); err != nil {
|
||||
return h.NewResponseWithError(c, "update model failed", err)
|
||||
|
|
@ -138,7 +134,7 @@ func (h *ModelHandler) UpdateModel(c echo.Context) error {
|
|||
return h.NewResponseWithData(c, nil)
|
||||
}
|
||||
|
||||
// check model
|
||||
// CheckModel
|
||||
//
|
||||
// @Summary check model
|
||||
// @Description check model
|
||||
|
|
@ -211,3 +207,58 @@ func (h *ModelHandler) GetProviderSupportedModelList(c echo.Context) error {
|
|||
}
|
||||
return h.NewResponseWithData(c, models)
|
||||
}
|
||||
|
||||
// SwitchMode
|
||||
//
|
||||
// @Summary switch mode
|
||||
// @Description switch model mode between manual and auto
|
||||
// @Tags model
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body domain.SwitchModeReq true "switch mode request"
|
||||
// @Success 200 {object} domain.Response{data=domain.SwitchModeResp}
|
||||
// @Router /api/v1/model/switch-mode [post]
|
||||
func (h *ModelHandler) SwitchMode(c echo.Context) error {
|
||||
var req domain.SwitchModeReq
|
||||
if err := c.Bind(&req); err != nil {
|
||||
return h.NewResponseWithError(c, "bind request failed", err)
|
||||
}
|
||||
if err := c.Validate(&req); err != nil {
|
||||
return h.NewResponseWithError(c, "validate request failed", err)
|
||||
}
|
||||
ctx := c.Request().Context()
|
||||
|
||||
if err := h.usecase.SwitchMode(ctx, &req); err != nil {
|
||||
return h.NewResponseWithError(c, err.Error(), err)
|
||||
}
|
||||
|
||||
resp := &domain.SwitchModeResp{
|
||||
Message: "模式切换成功",
|
||||
}
|
||||
return h.NewResponseWithData(c, resp)
|
||||
}
|
||||
|
||||
// GetModelModeSetting
|
||||
//
|
||||
// @Summary get model mode setting
|
||||
// @Description get current model mode setting including mode, API key and chat model
|
||||
// @Tags model
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} domain.Response{data=domain.ModelModeSetting}
|
||||
// @Router /api/v1/model/mode-setting [get]
|
||||
func (h *ModelHandler) GetModelModeSetting(c echo.Context) error {
|
||||
ctx := c.Request().Context()
|
||||
setting, err := h.usecase.GetModelModeSetting(ctx)
|
||||
if err != nil {
|
||||
// 如果获取失败,返回默认值(手动模式)
|
||||
h.logger.Warn("failed to get model mode setting, return default", log.Error(err))
|
||||
defaultSetting := domain.ModelModeSetting{
|
||||
Mode: consts.ModelSettingModeManual,
|
||||
AutoModeAPIKey: "",
|
||||
ChatModel: "",
|
||||
}
|
||||
return h.NewResponseWithData(c, defaultSetting)
|
||||
}
|
||||
return h.NewResponseWithData(c, setting)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ func NewNodeHandler(
|
|||
group.POST("/batch_move", h.BatchMoveNode)
|
||||
|
||||
group.GET("/recommend_nodes", h.RecommendNodes)
|
||||
group.POST("/restudy", h.NodeRestudy)
|
||||
|
||||
// node permission
|
||||
group.GET("/permission", h.NodePermission)
|
||||
|
|
@ -80,15 +81,13 @@ func (h *NodeHandler) CreateNode(c echo.Context) error {
|
|||
if err := c.Validate(req); err != nil {
|
||||
return h.NewResponseWithError(c, "validate request body failed", err)
|
||||
}
|
||||
req.MaxNode = 300
|
||||
if maxNode := c.Get("max_node"); maxNode != nil {
|
||||
req.MaxNode = maxNode.(int)
|
||||
}
|
||||
|
||||
req.MaxNode = domain.GetBaseEditionLimitation(ctx).MaxNode
|
||||
|
||||
id, err := h.usecase.Create(c.Request().Context(), req, authInfo.UserId)
|
||||
if err != nil {
|
||||
if errors.Is(err, domain.ErrMaxNodeLimitReached) {
|
||||
return h.NewResponseWithError(c, "已达到最大文档数量限制,请升级到联创版或企业版", nil)
|
||||
return h.NewResponseWithError(c, "已达到最大文档数量限制,请升级到更高版本", nil)
|
||||
}
|
||||
return h.NewResponseWithError(c, "create node failed", err)
|
||||
}
|
||||
|
|
@ -384,3 +383,32 @@ func (h *NodeHandler) NodePermissionEdit(c echo.Context) error {
|
|||
}
|
||||
return h.NewResponseWithData(c, nil)
|
||||
}
|
||||
|
||||
// NodeRestudy 文档重新学习
|
||||
//
|
||||
// @Tags Node
|
||||
// @Summary 文档重新学习
|
||||
// @Description 文档重新学习
|
||||
// @ID v1-NodeRestudy
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security bearerAuth
|
||||
// @Param param body v1.NodeRestudyReq true "para"
|
||||
// @Success 200 {object} domain.Response{data=v1.NodeRestudyResp}
|
||||
// @Router /api/v1/node/restudy [post]
|
||||
func (h *NodeHandler) NodeRestudy(c echo.Context) error {
|
||||
var req v1.NodeRestudyReq
|
||||
if err := c.Bind(&req); err != nil {
|
||||
return h.NewResponseWithError(c, "request params is invalid", err)
|
||||
}
|
||||
|
||||
if err := c.Validate(req); err != nil {
|
||||
return h.NewResponseWithError(c, "validate request params failed", err)
|
||||
}
|
||||
|
||||
if err := h.usecase.NodeRestudy(c.Request().Context(), &req); err != nil {
|
||||
return h.NewResponseWithError(c, "node restudy failed", err)
|
||||
}
|
||||
|
||||
return h.NewResponseWithData(c, nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,12 +192,29 @@ func (h *UserHandler) ResetPassword(c echo.Context) error {
|
|||
if err != nil {
|
||||
return h.NewResponseWithError(c, "failed to get user", err)
|
||||
}
|
||||
if user.Account == "admin" && authInfo.UserId == req.ID {
|
||||
|
||||
// 非超级管理员没有改密码权限
|
||||
if user.Role != consts.UserRoleAdmin {
|
||||
return h.NewResponseWithErrCode(c, domain.ErrCodePermissionDenied)
|
||||
}
|
||||
|
||||
if user.Account == "admin" {
|
||||
// admin 改不了自己的密码
|
||||
if authInfo.UserId == req.ID {
|
||||
return h.NewResponseWithError(c, "请修改安装目录下 .env 文件中的 ADMIN_PASSWORD,并重启 panda-wiki-api 容器使更改生效。", nil)
|
||||
}
|
||||
if user.Account != "admin" && authInfo.UserId != req.ID {
|
||||
return h.NewResponseWithError(c, "只有管理员可以重置其他用户密码", nil)
|
||||
} else {
|
||||
targetUser, err := h.usecase.GetUser(ctx, req.ID)
|
||||
if err != nil {
|
||||
return h.NewResponseWithError(c, "failed to get target user", err)
|
||||
}
|
||||
|
||||
// 超级管理员不能改其他超级管理员密码
|
||||
if targetUser.Role == consts.UserRoleAdmin && targetUser.ID != authInfo.UserId {
|
||||
return h.NewResponseWithError(c, "无法修改其他超级管理员密码", nil)
|
||||
}
|
||||
}
|
||||
|
||||
err = h.usecase.ResetPassword(c.Request().Context(), &req)
|
||||
if err != nil {
|
||||
return h.NewResponseWithError(c, "failed to reset password", err)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ type AuthMiddleware interface {
|
|||
Authorize(next echo.HandlerFunc) echo.HandlerFunc
|
||||
ValidateUserRole(role consts.UserRole) echo.MiddlewareFunc
|
||||
ValidateKBUserPerm(role consts.UserKBPermission) echo.MiddlewareFunc
|
||||
ValidateLicenseEdition(edition consts.LicenseEdition) echo.MiddlewareFunc
|
||||
ValidateLicenseEdition(edition ...consts.LicenseEdition) echo.MiddlewareFunc
|
||||
MustGetUserID(c echo.Context) (string, bool)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
|
|
@ -194,7 +195,7 @@ func (m *JWTMiddleware) ValidateKBUserPerm(perm consts.UserKBPermission) echo.Mi
|
|||
}
|
||||
}
|
||||
|
||||
func (m *JWTMiddleware) ValidateLicenseEdition(needEdition consts.LicenseEdition) echo.MiddlewareFunc {
|
||||
func (m *JWTMiddleware) ValidateLicenseEdition(needEditions ...consts.LicenseEdition) echo.MiddlewareFunc {
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
|
||||
|
|
@ -206,7 +207,7 @@ func (m *JWTMiddleware) ValidateLicenseEdition(needEdition consts.LicenseEdition
|
|||
})
|
||||
}
|
||||
|
||||
if edition < needEdition {
|
||||
if !slices.Contains(needEditions, edition) {
|
||||
return c.JSON(http.StatusForbidden, domain.PWResponse{
|
||||
Success: false,
|
||||
Message: "Unauthorized ValidateLicenseEdition",
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ import (
|
|||
|
||||
const (
|
||||
// AuthURL api doc https://developer.work.weixin.qq.com/document/path/98152
|
||||
AuthURL = "https://login.work.weixin.qq.com/wwlogin/sso/login"
|
||||
AuthWebURL = "https://login.work.weixin.qq.com/wwlogin/sso/login"
|
||||
AuthAPPURL = "https://open.weixin.qq.com/connect/oauth2/authorize"
|
||||
TokenURL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken"
|
||||
UserInfoURL = "https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo"
|
||||
UserDetailURL = "https://qyapi.weixin.qq.com/cgi-bin/user/get"
|
||||
|
|
@ -29,11 +30,6 @@ const (
|
|||
callbackPath = "/share/pro/v1/openapi/wecom/callback"
|
||||
)
|
||||
|
||||
var oauthEndpoint = oauth2.Endpoint{
|
||||
AuthURL: AuthURL,
|
||||
TokenURL: TokenURL,
|
||||
}
|
||||
|
||||
// Client 企业微信客户端
|
||||
type Client struct {
|
||||
context context.Context
|
||||
|
|
@ -115,16 +111,23 @@ type UserListResponse struct {
|
|||
} `json:"userlist"`
|
||||
}
|
||||
|
||||
func NewClient(ctx context.Context, logger *log.Logger, corpID, corpSecret, agentID, redirectURI string, cache *cache.Cache) (*Client, error) {
|
||||
func NewClient(ctx context.Context, logger *log.Logger, corpID, corpSecret, agentID, redirectURI string, cache *cache.Cache, isApp bool) (*Client, error) {
|
||||
redirectURL, _ := url.Parse(redirectURI)
|
||||
redirectURL.Path = callbackPath
|
||||
redirectURI = redirectURL.String()
|
||||
authUrl := AuthWebURL
|
||||
if isApp {
|
||||
authUrl = AuthAPPURL
|
||||
}
|
||||
|
||||
oauthConfig := &oauth2.Config{
|
||||
ClientID: corpID,
|
||||
ClientSecret: corpSecret,
|
||||
RedirectURL: redirectURI,
|
||||
Endpoint: oauthEndpoint,
|
||||
Endpoint: oauth2.Endpoint{
|
||||
AuthURL: authUrl,
|
||||
TokenURL: TokenURL,
|
||||
},
|
||||
Scopes: []string{"snsapi_privateinfo"},
|
||||
}
|
||||
|
||||
|
|
@ -150,7 +153,11 @@ func (c *Client) GenerateAuthURL(state string) string {
|
|||
params.Set("agentid", c.agentID)
|
||||
params.Set("state", state)
|
||||
|
||||
return fmt.Sprintf("%s?%s", AuthURL, params.Encode())
|
||||
authUrl := fmt.Sprintf("%s?%s", c.oauthConfig.Endpoint.AuthURL, params.Encode())
|
||||
if c.oauthConfig.Endpoint.AuthURL == AuthAPPURL {
|
||||
authUrl += "#wechat_redirect"
|
||||
}
|
||||
return authUrl
|
||||
}
|
||||
|
||||
// GetAccessToken 获取企业微信访问令牌
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit fdc289e24b6ca534c99f49395bd277ff70904d95
|
||||
Subproject commit 7771d31053770721d75e194d1c6e7a4b60fb58aa
|
||||
|
|
@ -2,5 +2,7 @@ package backend
|
|||
|
||||
import (
|
||||
_ "github.com/jinzhu/copier"
|
||||
_ "github.com/mark3labs/mcp-go/mcp"
|
||||
_ "github.com/mark3labs/mcp-go/server"
|
||||
_ "google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -300,8 +300,8 @@ func (r *AuthRepo) GetOrCreateAuth(ctx context.Context, auth *domain.Auth, sourc
|
|||
return err
|
||||
}
|
||||
|
||||
if int(count) >= licenseEdition.GetMaxAuth(sourceType) {
|
||||
return fmt.Errorf("exceed max auth limit for kb %s, current count: %d, max limit: %d", auth.KBID, count, licenseEdition.GetMaxAuth(sourceType))
|
||||
if int(count) >= domain.GetBaseEditionLimitation(ctx).MaxSSOUser {
|
||||
return fmt.Errorf("exceed max auth limit for kb %s, current count: %d, max limit: %d", auth.KBID, count, domain.GetBaseEditionLimitation(ctx).MaxSSOUser)
|
||||
}
|
||||
|
||||
auth.LastLoginTime = time.Now()
|
||||
|
|
|
|||
|
|
@ -26,12 +26,12 @@ func (r *CommentRepository) CreateComment(ctx context.Context, comment *domain.C
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *CommentRepository) GetCommentList(ctx context.Context, nodeID string, edition consts.LicenseEdition) ([]*domain.ShareCommentListItem, int64, error) {
|
||||
func (r *CommentRepository) GetCommentList(ctx context.Context, nodeID string) ([]*domain.ShareCommentListItem, int64, error) {
|
||||
// 按照时间排序来查询node_id的comments
|
||||
var comments []*domain.ShareCommentListItem
|
||||
query := r.db.WithContext(ctx).Model(&domain.Comment{}).Where("node_id = ?", nodeID)
|
||||
|
||||
if edition == consts.LicenseEditionContributor || edition == consts.LicenseEditionEnterprise {
|
||||
if domain.GetBaseEditionLimitation(ctx).AllowCommentAudit {
|
||||
query = query.Where("status = ?", domain.CommentStatusAccepted) //accepted
|
||||
}
|
||||
|
||||
|
|
@ -50,14 +50,14 @@ func (r *CommentRepository) GetCommentList(ctx context.Context, nodeID string, e
|
|||
|
||||
func (r *CommentRepository) GetCommentListByKbID(ctx context.Context, req *domain.CommentListReq, edition consts.LicenseEdition) ([]*domain.CommentListItem, int64, error) {
|
||||
comments := []*domain.CommentListItem{}
|
||||
query := r.db.Model(&domain.Comment{}).Where("comments.kb_id = ?", req.KbID)
|
||||
query := r.db.WithContext(ctx).Model(&domain.Comment{}).Where("comments.kb_id = ?", req.KbID)
|
||||
var count int64
|
||||
if req.Status == nil {
|
||||
if err := query.Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
} else {
|
||||
if edition == consts.LicenseEditionContributor || edition == consts.LicenseEditionEnterprise {
|
||||
if domain.GetBaseEditionLimitation(ctx).AllowCommentAudit {
|
||||
query = query.Where("comments.status = ?", *req.Status)
|
||||
}
|
||||
// 按照时间排序来查询kb_id的comments ->reject pending accepted
|
||||
|
|
@ -84,7 +84,7 @@ func (r *CommentRepository) GetCommentListByKbID(ctx context.Context, req *domai
|
|||
|
||||
func (r *CommentRepository) DeleteCommentList(ctx context.Context, commentID []string) error {
|
||||
// 批量删除指定id的comment,获取删除的总的数量、
|
||||
query := r.db.Model(&domain.Comment{}).Where("id IN (?)", commentID)
|
||||
query := r.db.WithContext(ctx).Model(&domain.Comment{}).Where("id IN (?)", commentID)
|
||||
|
||||
if err := query.Delete(&domain.Comment{}).Error; err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -157,6 +157,32 @@ func (r *NodeRepository) GetLatestNodeReleaseByNodeIDs(ctx context.Context, kbID
|
|||
return nodeReleases, nil
|
||||
}
|
||||
|
||||
func (r *NodeRepository) GetNodeReleasePublisherMap(ctx context.Context, kbID string) (map[string]string, error) {
|
||||
type Result struct {
|
||||
NodeID string `gorm:"column:node_id"`
|
||||
PublisherID string `gorm:"column:publisher_id"`
|
||||
}
|
||||
|
||||
var results []Result
|
||||
if err := r.db.WithContext(ctx).
|
||||
Model(&domain.NodeRelease{}).
|
||||
Select("node_id, publisher_id").
|
||||
Where("kb_id = ?", kbID).
|
||||
Where("node_releases.doc_id != '' ").
|
||||
Find(&results).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
publisherMap := make(map[string]string)
|
||||
for _, result := range results {
|
||||
if result.PublisherID != "" {
|
||||
publisherMap[result.NodeID] = result.PublisherID
|
||||
}
|
||||
}
|
||||
|
||||
return publisherMap, nil
|
||||
}
|
||||
|
||||
func (r *NodeRepository) UpdateNodeContent(ctx context.Context, req *domain.UpdateNodeReq, userId string) error {
|
||||
// Use transaction to ensure data consistency
|
||||
err := r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
|
|
@ -683,7 +709,7 @@ func (r *NodeRepository) GetNodeReleaseListByKBID(ctx context.Context, kbID stri
|
|||
Where("kb_release_node_releases.kb_id = ?", kbID).
|
||||
Where("kb_release_node_releases.release_id = ?", kbRelease.ID).
|
||||
Where("nodes.permissions->>'visible' != ?", consts.NodeAccessPermClosed).
|
||||
Select("node_releases.node_id as id, node_releases.name, node_releases.type, node_releases.parent_id, node_releases.position, node_releases.meta->>'emoji' as emoji, node_releases.updated_at, nodes.permissions").
|
||||
Select("node_releases.node_id as id, node_releases.name, node_releases.type, node_releases.parent_id, nodes.position, node_releases.meta->>'emoji' as emoji, node_releases.updated_at, nodes.permissions, nodes.meta").
|
||||
Find(&nodes).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,4 +23,5 @@ var ProviderSet = wire.NewSet(
|
|||
NewAuthRepo,
|
||||
NewWechatRepository,
|
||||
NewAPITokenRepo,
|
||||
NewSystemSettingRepo,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package pg
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/chaitin/panda-wiki/domain"
|
||||
"github.com/chaitin/panda-wiki/log"
|
||||
"github.com/chaitin/panda-wiki/store/pg"
|
||||
)
|
||||
|
||||
type SystemSettingRepo struct {
|
||||
db *pg.DB
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
func NewSystemSettingRepo(db *pg.DB, logger *log.Logger) *SystemSettingRepo {
|
||||
return &SystemSettingRepo{
|
||||
db: db,
|
||||
logger: logger.WithModule("repo.pg.system_setting"),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *SystemSettingRepo) GetSystemSetting(ctx context.Context, key string) (*domain.SystemSetting, error) {
|
||||
var setting domain.SystemSetting
|
||||
result := r.db.WithContext(ctx).Where("key = ?", key).First(&setting)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
|
||||
return &setting, nil
|
||||
}
|
||||
|
||||
func (r *SystemSettingRepo) UpdateSystemSetting(ctx context.Context, key, value string) error {
|
||||
return r.db.WithContext(ctx).Model(&domain.SystemSetting{}).Where("key = ?", key).Update("value", value).Error
|
||||
}
|
||||
|
|
@ -60,18 +60,14 @@ func (r *UserRepository) CreateUser(ctx context.Context, user *domain.User, edit
|
|||
}
|
||||
user.Password = string(hashedPassword)
|
||||
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if edition == consts.LicenseEditionContributor || edition == consts.LicenseEditionFree {
|
||||
var count int64
|
||||
if err := tx.Model(&domain.User{}).Count(&count).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if edition == consts.LicenseEditionFree && count >= 1 {
|
||||
return errors.New("free edition only allows 1 user")
|
||||
}
|
||||
if edition == consts.LicenseEditionContributor && count >= 5 {
|
||||
return errors.New("contributor edition only allows 5 user")
|
||||
}
|
||||
if count >= domain.GetBaseEditionLimitation(ctx).MaxAdmin {
|
||||
return fmt.Errorf("exceed max admin limit, current count: %d, max limit: %d", count, domain.GetBaseEditionLimitation(ctx).MaxAdmin)
|
||||
}
|
||||
|
||||
if err := tx.Create(user).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
-- Drop settings table
|
||||
DROP TABLE IF EXISTS system_settings;
|
||||
-- drop index
|
||||
DROP INDEX IF EXISTS idx_system_settings_key;
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
-- Create settings table
|
||||
CREATE TABLE IF NOT EXISTS system_settings (
|
||||
id SERIAL PRIMARY KEY,
|
||||
key TEXT NOT NULL,
|
||||
value JSONB NOT NULL,
|
||||
description TEXT,
|
||||
created_at timestamptz NOT NULL DEFAULT NOW(),
|
||||
updated_at timestamptz NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_uniq_system_settings_key ON system_settings(key);
|
||||
|
||||
-- Insert model_setting_mode setting
|
||||
-- If there are existing knowledge bases, set mode to 'manual', otherwise set to 'auto'
|
||||
INSERT INTO system_settings (key, value, description)
|
||||
SELECT
|
||||
'model_setting_mode',
|
||||
jsonb_build_object(
|
||||
'mode', CASE
|
||||
WHEN EXISTS (SELECT 1 FROM knowledge_bases LIMIT 1) THEN 'manual'
|
||||
ELSE 'auto'
|
||||
END,
|
||||
'auto_mode_api_key', '',
|
||||
'chat_model', '',
|
||||
'is_manual_embedding_updated', false
|
||||
),
|
||||
'Model setting mode configuration'
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM system_settings WHERE key = 'model_setting_mode'
|
||||
);
|
||||
|
|
@ -0,0 +1 @@
|
|||
DROP TABLE IF EXISTS mcp_calls;
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
CREATE TABLE IF NOT EXISTS mcp_calls (
|
||||
id SERIAL PRIMARY KEY,
|
||||
mcp_session_id TEXT NOT NULL,
|
||||
kb_id TEXT NOT NULL,
|
||||
remote_ip TEXT,
|
||||
initialize_req JSONB,
|
||||
initialize_resp JSONB,
|
||||
tool_call_req JSONB,
|
||||
tool_call_resp TEXT,
|
||||
created_at timestamptz NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
|
@ -28,6 +28,8 @@ func NewHTML2MDConverter() *converter.Converter {
|
|||
conv.Register.RendererFor("span", converter.TagTypeInline, renderAttachment, converter.PriorityEarly)
|
||||
// task list
|
||||
conv.Register.RendererFor("ul", converter.TagTypeBlock, renderTaskList, converter.PriorityEarly)
|
||||
// flowchart/diagram to mermaid code block
|
||||
conv.Register.RendererFor("div", converter.TagTypeBlock, renderFlowchart, converter.PriorityEarly)
|
||||
return conv
|
||||
}
|
||||
|
||||
|
|
@ -126,3 +128,40 @@ func getTextFromTaskItem(node *html.Node) string {
|
|||
extractText(node)
|
||||
return strings.TrimSpace(textContent.String())
|
||||
}
|
||||
|
||||
// renderFlowchart 将流程图 div 转换为 Mermaid 代码块
|
||||
func renderFlowchart(ctx converter.Context, w converter.Writer, node *html.Node) converter.RenderStatus {
|
||||
if node.Type != html.ElementNode || node.Data != "div" {
|
||||
return converter.RenderTryNext
|
||||
}
|
||||
|
||||
// 仅处理 data-type="flow" 的 div
|
||||
dataType, ok := dom.GetAttribute(node, "data-type")
|
||||
if !ok || dataType != "flow" {
|
||||
return converter.RenderTryNext
|
||||
}
|
||||
|
||||
// 提取 data-code 属性
|
||||
code, hasCode := dom.GetAttribute(node, "data-code")
|
||||
if !hasCode || strings.TrimSpace(code) == "" {
|
||||
return converter.RenderTryNext
|
||||
}
|
||||
|
||||
// 解码 HTML 实体
|
||||
code = html.UnescapeString(code)
|
||||
// 处理转义的换行符
|
||||
code = strings.ReplaceAll(code, "\\n", "\n")
|
||||
|
||||
// 写入 Mermaid 代码块
|
||||
if _, err := w.WriteString("\n```mermaid\n"); err != nil {
|
||||
return converter.RenderTryNext
|
||||
}
|
||||
if _, err := w.WriteString(code); err != nil {
|
||||
return converter.RenderTryNext
|
||||
}
|
||||
if _, err := w.WriteString("\n```\n\n"); err != nil {
|
||||
return converter.RenderTryNext
|
||||
}
|
||||
|
||||
return converter.RenderSuccess
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,32 +88,55 @@ func NewAppUsecase(
|
|||
}
|
||||
|
||||
func (u *AppUsecase) ValidateUpdateApp(ctx context.Context, id string, req *domain.UpdateAppReq, edition consts.LicenseEdition) error {
|
||||
switch edition {
|
||||
case consts.LicenseEditionFree:
|
||||
app, err := u.repo.GetAppDetail(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if app.Settings.WatermarkContent != req.Settings.WatermarkContent ||
|
||||
app.Settings.WatermarkSetting != req.Settings.WatermarkSetting ||
|
||||
app.Settings.ContributeSettings != req.Settings.ContributeSettings ||
|
||||
app.Settings.CopySetting != req.Settings.CopySetting {
|
||||
|
||||
limitation := domain.GetBaseEditionLimitation(ctx)
|
||||
if !limitation.AllowCopyProtection && app.Settings.CopySetting != req.Settings.CopySetting {
|
||||
return domain.ErrPermissionDenied
|
||||
}
|
||||
case consts.LicenseEditionContributor:
|
||||
app, err := u.repo.GetAppDetail(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if app.Settings.WatermarkContent != req.Settings.WatermarkContent ||
|
||||
app.Settings.WatermarkSetting != req.Settings.WatermarkSetting ||
|
||||
app.Settings.CopySetting != req.Settings.CopySetting {
|
||||
|
||||
if !limitation.AllowWatermark {
|
||||
if app.Settings.WatermarkSetting != req.Settings.WatermarkSetting || app.Settings.WatermarkContent != req.Settings.WatermarkContent {
|
||||
return domain.ErrPermissionDenied
|
||||
}
|
||||
}
|
||||
|
||||
if !limitation.AllowAdvancedBot {
|
||||
if !slices.Equal(app.Settings.WechatServiceContainKeywords, req.Settings.WechatServiceContainKeywords) ||
|
||||
!slices.Equal(app.Settings.WechatServiceEqualKeywords, req.Settings.WechatServiceEqualKeywords) {
|
||||
return domain.ErrPermissionDenied
|
||||
}
|
||||
}
|
||||
|
||||
if !limitation.AllowCommentAudit && app.Settings.WebAppCommentSettings.ModerationEnable != req.Settings.WebAppCommentSettings.ModerationEnable {
|
||||
return domain.ErrPermissionDenied
|
||||
}
|
||||
|
||||
if !limitation.AllowOpenAIBotSettings {
|
||||
if app.Settings.OpenAIAPIBotSettings.IsEnabled != req.Settings.OpenAIAPIBotSettings.IsEnabled || app.Settings.OpenAIAPIBotSettings.SecretKey != req.Settings.OpenAIAPIBotSettings.SecretKey {
|
||||
return domain.ErrPermissionDenied
|
||||
}
|
||||
}
|
||||
|
||||
if !limitation.AllowCustomCopyright {
|
||||
if app.Settings.WidgetBotSettings.CopyrightHideEnabled != req.Settings.WidgetBotSettings.CopyrightHideEnabled || app.Settings.WidgetBotSettings.CopyrightInfo != req.Settings.WidgetBotSettings.CopyrightInfo {
|
||||
return domain.ErrPermissionDenied
|
||||
}
|
||||
if app.Settings.ConversationSetting.CopyrightHideEnabled != req.Settings.ConversationSetting.CopyrightHideEnabled {
|
||||
return domain.ErrPermissionDenied
|
||||
}
|
||||
if req.Settings.ConversationSetting.CopyrightInfo != domain.SettingCopyrightInfo && app.Settings.ConversationSetting.CopyrightInfo != req.Settings.ConversationSetting.CopyrightInfo {
|
||||
return domain.ErrPermissionDenied
|
||||
}
|
||||
}
|
||||
|
||||
if !limitation.AllowMCPServer {
|
||||
if app.Settings.MCPServerSettings.IsEnabled != req.Settings.MCPServerSettings.IsEnabled {
|
||||
return domain.ErrPermissionDenied
|
||||
}
|
||||
case consts.LicenseEditionEnterprise:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("unsupported license type: %d", edition)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -439,7 +462,6 @@ func (u *AppUsecase) GetAppDetailByKBIDAndAppType(ctx context.Context, kbID stri
|
|||
RecommendNodeIDs: app.Settings.RecommendNodeIDs,
|
||||
Desc: app.Settings.Desc,
|
||||
Keyword: app.Settings.Keyword,
|
||||
AutoSitemap: app.Settings.AutoSitemap,
|
||||
HeadCode: app.Settings.HeadCode,
|
||||
BodyCode: app.Settings.BodyCode,
|
||||
// DingTalkBot
|
||||
|
|
@ -507,9 +529,18 @@ func (u *AppUsecase) GetAppDetailByKBIDAndAppType(ctx context.Context, kbID stri
|
|||
CopySetting: app.Settings.CopySetting,
|
||||
ContributeSettings: app.Settings.ContributeSettings,
|
||||
HomePageSetting: app.Settings.HomePageSetting,
|
||||
ConversationSetting: app.Settings.ConversationSetting,
|
||||
|
||||
WecomAIBotSettings: app.Settings.WecomAIBotSettings,
|
||||
|
||||
MCPServerSettings: app.Settings.MCPServerSettings,
|
||||
}
|
||||
|
||||
if !domain.GetBaseEditionLimitation(ctx).AllowCustomCopyright {
|
||||
appDetailResp.Settings.ConversationSetting.CopyrightHideEnabled = false
|
||||
appDetailResp.Settings.ConversationSetting.CopyrightInfo = domain.SettingCopyrightInfo
|
||||
}
|
||||
|
||||
// init ai feedback string
|
||||
if app.Settings.AIFeedbackSettings.AIFeedbackType == nil {
|
||||
appDetailResp.Settings.AIFeedbackSettings.AIFeedbackType = []string{"内容不准确", "没有帮助", "其他"}
|
||||
|
|
@ -532,6 +563,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 {
|
||||
|
|
@ -578,7 +622,6 @@ func (u *AppUsecase) ShareGetWebAppInfo(ctx context.Context, kbID string, authId
|
|||
RecommendNodeIDs: app.Settings.RecommendNodeIDs,
|
||||
Desc: app.Settings.Desc,
|
||||
Keyword: app.Settings.Keyword,
|
||||
AutoSitemap: app.Settings.AutoSitemap,
|
||||
HeadCode: app.Settings.HeadCode,
|
||||
BodyCode: app.Settings.BodyCode,
|
||||
// theme
|
||||
|
|
@ -607,6 +650,7 @@ func (u *AppUsecase) ShareGetWebAppInfo(ctx context.Context, kbID string, authId
|
|||
CopySetting: app.Settings.CopySetting,
|
||||
ContributeSettings: app.Settings.ContributeSettings,
|
||||
HomePageSetting: app.Settings.HomePageSetting,
|
||||
ConversationSetting: app.Settings.ConversationSetting,
|
||||
},
|
||||
}
|
||||
// init ai feedback string
|
||||
|
|
@ -618,10 +662,12 @@ func (u *AppUsecase) ShareGetWebAppInfo(ctx context.Context, kbID string, authId
|
|||
}
|
||||
showBrand := true
|
||||
defaultDisclaimer := "本回答由 PandaWiki 基于 AI 生成,仅供参考。"
|
||||
licenseEdition, _ := ctx.Value(consts.ContextKeyEdition).(consts.LicenseEdition)
|
||||
if licenseEdition < consts.LicenseEditionEnterprise {
|
||||
|
||||
if !domain.GetBaseEditionLimitation(ctx).AllowCustomCopyright {
|
||||
appInfo.Settings.WebAppCustomSettings.ShowBrandInfo = &showBrand
|
||||
appInfo.Settings.DisclaimerSettings.Content = &defaultDisclaimer
|
||||
appInfo.Settings.ConversationSetting.CopyrightHideEnabled = false
|
||||
appInfo.Settings.ConversationSetting.CopyrightInfo = domain.SettingCopyrightInfo
|
||||
} else {
|
||||
if appInfo.Settings.DisclaimerSettings.Content == nil {
|
||||
appInfo.Settings.DisclaimerSettings.Content = &defaultDisclaimer
|
||||
|
|
@ -660,6 +706,12 @@ func (u *AppUsecase) GetWidgetAppInfo(ctx context.Context, kbID string) (*domain
|
|||
}
|
||||
appInfo.RecommendNodes = nodes
|
||||
}
|
||||
|
||||
if !domain.GetBaseEditionLimitation(ctx).AllowCustomCopyright {
|
||||
appInfo.Settings.WidgetBotSettings.CopyrightHideEnabled = false
|
||||
appInfo.Settings.WidgetBotSettings.CopyrightInfo = domain.SettingCopyrightInfo
|
||||
}
|
||||
|
||||
return appInfo, 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
|
||||
|
|
|
|||
|
|
@ -72,8 +72,8 @@ func (u *CommentUsecase) CreateComment(ctx context.Context, commentReq *domain.C
|
|||
return CommentStr, nil
|
||||
}
|
||||
|
||||
func (u *CommentUsecase) GetCommentListByNodeID(ctx context.Context, nodeID string, edition consts.LicenseEdition) (*domain.PaginatedResult[[]*domain.ShareCommentListItem], error) {
|
||||
comments, total, err := u.CommentRepo.GetCommentList(ctx, nodeID, edition)
|
||||
func (u *CommentUsecase) GetCommentListByNodeID(ctx context.Context, nodeID string) (*domain.PaginatedResult[[]*domain.ShareCommentListItem], error) {
|
||||
comments, total, err := u.CommentRepo.GetCommentList(ctx, nodeID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ func (u *CreationUsecase) TextCreation(ctx context.Context, req *domain.TextReq,
|
|||
func (u *CreationUsecase) TabComplete(ctx context.Context, req *domain.CompleteReq) (string, error) {
|
||||
// For FIM (Fill in Middle) style completion, we need to handle prefix and suffix
|
||||
if req.Prefix != "" || req.Suffix != "" {
|
||||
model, err := u.model.GetModelByType(ctx, domain.ModelTypeChat)
|
||||
model, err := u.model.GetChatModel(ctx)
|
||||
if err != nil {
|
||||
u.logger.Error("get chat model failed", log.Error(err))
|
||||
return "", domain.ErrModelNotConfigured
|
||||
|
|
|
|||
|
|
@ -2,14 +2,15 @@ package usecase
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
"github.com/google/uuid"
|
||||
"github.com/samber/lo"
|
||||
|
||||
modelkitDomain "github.com/chaitin/ModelKit/v2/domain"
|
||||
modelkit "github.com/chaitin/ModelKit/v2/usecase"
|
||||
"github.com/chaitin/panda-wiki/config"
|
||||
"github.com/chaitin/panda-wiki/consts"
|
||||
"github.com/chaitin/panda-wiki/domain"
|
||||
"github.com/chaitin/panda-wiki/log"
|
||||
"github.com/chaitin/panda-wiki/repo/mq"
|
||||
|
|
@ -25,9 +26,12 @@ type ModelUsecase struct {
|
|||
ragRepo *mq.RAGRepository
|
||||
ragStore rag.RAGService
|
||||
kbRepo *pg.KnowledgeBaseRepository
|
||||
systemSettingRepo *pg.SystemSettingRepo
|
||||
modelkit *modelkit.ModelKit
|
||||
}
|
||||
|
||||
func NewModelUsecase(modelRepo *pg.ModelRepository, nodeRepo *pg.NodeRepository, ragRepo *mq.RAGRepository, ragStore rag.RAGService, logger *log.Logger, config *config.Config, kbRepo *pg.KnowledgeBaseRepository) *ModelUsecase {
|
||||
func NewModelUsecase(modelRepo *pg.ModelRepository, nodeRepo *pg.NodeRepository, ragRepo *mq.RAGRepository, ragStore rag.RAGService, logger *log.Logger, config *config.Config, kbRepo *pg.KnowledgeBaseRepository, settingRepo *pg.SystemSettingRepo) *ModelUsecase {
|
||||
modelkit := modelkit.NewModelKit(logger.Logger)
|
||||
u := &ModelUsecase{
|
||||
modelRepo: modelRepo,
|
||||
logger: logger.WithModule("usecase.model"),
|
||||
|
|
@ -36,100 +40,26 @@ func NewModelUsecase(modelRepo *pg.ModelRepository, nodeRepo *pg.NodeRepository,
|
|||
ragRepo: ragRepo,
|
||||
ragStore: ragStore,
|
||||
kbRepo: kbRepo,
|
||||
}
|
||||
if err := u.initEmbeddingAndRerankModel(context.Background()); err != nil {
|
||||
logger.Error("init embedding & rerank & analysis model failed", log.Any("error", err))
|
||||
systemSettingRepo: settingRepo,
|
||||
modelkit: modelkit,
|
||||
}
|
||||
return u
|
||||
}
|
||||
|
||||
func (u *ModelUsecase) initEmbeddingAndRerankModel(ctx context.Context) error {
|
||||
isReady := false
|
||||
// wait for raglite to be ready
|
||||
for range 60 {
|
||||
models, err := u.ragStore.GetModelList(ctx)
|
||||
if err != nil {
|
||||
u.logger.Error("wait for raglite to be ready", log.Any("error", err))
|
||||
time.Sleep(1 * time.Second)
|
||||
continue
|
||||
}
|
||||
isReady = true
|
||||
if len(models) > 0 {
|
||||
// init analysis model for old user
|
||||
hasAnalysis := false
|
||||
for _, m := range models {
|
||||
if m.Type == domain.ModelTypeAnalysis {
|
||||
hasAnalysis = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasAnalysis {
|
||||
if err := u.createAndSyncModelToRAGLite(ctx, "qwen2.5-3b-instruct", domain.ModelTypeAnalysis); err != nil {
|
||||
return fmt.Errorf("add analysis model err: %v", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if !isReady {
|
||||
return fmt.Errorf("raglite is not ready")
|
||||
}
|
||||
|
||||
if err := u.createAndSyncModelToRAGLite(ctx, "bge-m3", domain.ModelTypeEmbedding); err != nil {
|
||||
return fmt.Errorf("create and sync model err: %v", err)
|
||||
}
|
||||
if err := u.createAndSyncModelToRAGLite(ctx, "bge-reranker-v2-m3", domain.ModelTypeRerank); err != nil {
|
||||
return fmt.Errorf("create and sync model err: %v", err)
|
||||
}
|
||||
if err := u.createAndSyncModelToRAGLite(ctx, "qwen2.5-3b-instruct", domain.ModelTypeAnalysis); err != nil {
|
||||
return fmt.Errorf("create and sync model err: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *ModelUsecase) createAndSyncModelToRAGLite(ctx context.Context, modelName string, modelType domain.ModelType) error {
|
||||
// FIXME: just for test, remove it later
|
||||
// shared_key by BaiZhiCloud
|
||||
sharedKey := "sk-r8tmBtcU1JotPDPnlgZLOY4Z6Dbb7FufcSeTkFpRWA5v4Llr"
|
||||
baseURL := "https://model-square.app.baizhi.cloud/v1"
|
||||
model := &domain.Model{
|
||||
ID: uuid.New().String(),
|
||||
Provider: domain.ModelProviderBrandBaiZhiCloud,
|
||||
Model: modelName,
|
||||
APIKey: sharedKey,
|
||||
APIHeader: "",
|
||||
BaseURL: baseURL,
|
||||
IsActive: true,
|
||||
APIVersion: "",
|
||||
Type: modelType,
|
||||
}
|
||||
id, err := u.ragStore.AddModel(ctx, model)
|
||||
if err != nil {
|
||||
return fmt.Errorf("init %s model failed: %w", modelName, err)
|
||||
}
|
||||
model.ID = id
|
||||
if err := u.modelRepo.Create(ctx, model); err != nil {
|
||||
return fmt.Errorf("create %s model failed: %w", modelName, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *ModelUsecase) Create(ctx context.Context, model *domain.Model) error {
|
||||
var updatedEmbeddingModel bool
|
||||
if model.Type == domain.ModelTypeEmbedding {
|
||||
updatedEmbeddingModel = true
|
||||
}
|
||||
if err := u.modelRepo.Create(ctx, model); err != nil {
|
||||
return err
|
||||
}
|
||||
if model.Type == domain.ModelTypeEmbedding || model.Type == domain.ModelTypeRerank || model.Type == domain.ModelTypeAnalysis || model.Type == domain.ModelTypeAnalysisVL {
|
||||
if id, err := u.ragStore.AddModel(ctx, model); err != nil {
|
||||
// 模型更新成功后,如果更新嵌入模型,则触发记录更新
|
||||
if updatedEmbeddingModel {
|
||||
if _, err := u.updateModeSettingConfig(ctx, "", "", "", true); err != nil {
|
||||
return err
|
||||
} else {
|
||||
model.ID = id
|
||||
}
|
||||
}
|
||||
if model.Type == domain.ModelTypeEmbedding {
|
||||
return u.TriggerUpsertRecords(ctx)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -178,44 +108,50 @@ func (u *ModelUsecase) TriggerUpsertRecords(ctx context.Context) error {
|
|||
}
|
||||
|
||||
func (u *ModelUsecase) Update(ctx context.Context, req *domain.UpdateModelReq) error {
|
||||
var updatedEmbeddingModel bool
|
||||
if req.Type == domain.ModelTypeEmbedding {
|
||||
updatedEmbeddingModel = true
|
||||
}
|
||||
if err := u.modelRepo.Update(ctx, req); err != nil {
|
||||
return err
|
||||
}
|
||||
ragModelTypes := []domain.ModelType{
|
||||
domain.ModelTypeEmbedding,
|
||||
domain.ModelTypeRerank,
|
||||
domain.ModelTypeAnalysis,
|
||||
domain.ModelTypeAnalysisVL,
|
||||
}
|
||||
if lo.Contains(ragModelTypes, req.Type) {
|
||||
updateModel := &domain.Model{
|
||||
ID: req.ID,
|
||||
Model: req.Model,
|
||||
Type: req.Type,
|
||||
BaseURL: req.BaseURL,
|
||||
APIKey: req.APIKey,
|
||||
IsActive: true,
|
||||
}
|
||||
if req.Parameters != nil {
|
||||
updateModel.Parameters = *req.Parameters
|
||||
}
|
||||
// update is active flag for analysis models
|
||||
if (req.Type == domain.ModelTypeAnalysis || req.Type == domain.ModelTypeAnalysisVL) && req.IsActive != nil {
|
||||
updateModel.IsActive = *req.IsActive
|
||||
}
|
||||
if err := u.ragStore.UpdateModel(ctx, updateModel); err != nil {
|
||||
// 模型更新成功后,如果更新嵌入模型,则触发记录更新
|
||||
if updatedEmbeddingModel {
|
||||
if _, err := u.updateModeSettingConfig(ctx, "", "", "", true); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// update all records when embedding model is updated
|
||||
if req.Type == domain.ModelTypeEmbedding {
|
||||
return u.TriggerUpsertRecords(ctx)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *ModelUsecase) GetChatModel(ctx context.Context) (*domain.Model, error) {
|
||||
return u.modelRepo.GetChatModel(ctx)
|
||||
var model *domain.Model
|
||||
modelModeSetting, err := u.GetModelModeSetting(ctx)
|
||||
// 获取不到模型模式时,使用手动模式, 不返回错误
|
||||
if err != nil {
|
||||
u.logger.Error("get model mode setting failed, use manual mode", log.Error(err))
|
||||
}
|
||||
if err == nil && modelModeSetting.Mode == consts.ModelSettingModeAuto && modelModeSetting.AutoModeAPIKey != "" {
|
||||
modelName := modelModeSetting.ChatModel
|
||||
if modelName == "" {
|
||||
modelName = string(consts.AutoModeDefaultChatModel)
|
||||
}
|
||||
model = &domain.Model{
|
||||
Model: modelName,
|
||||
Type: domain.ModelTypeChat,
|
||||
IsActive: true,
|
||||
BaseURL: consts.AutoModeBaseURL,
|
||||
APIKey: modelModeSetting.AutoModeAPIKey,
|
||||
Provider: domain.ModelProviderBrandBaiZhiCloud,
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
model, err = u.modelRepo.GetChatModel(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return model, nil
|
||||
}
|
||||
|
||||
func (u *ModelUsecase) GetModelByType(ctx context.Context, modelType domain.ModelType) (*domain.Model, error) {
|
||||
|
|
@ -225,3 +161,175 @@ func (u *ModelUsecase) GetModelByType(ctx context.Context, modelType domain.Mode
|
|||
func (u *ModelUsecase) UpdateUsage(ctx context.Context, modelID string, usage *schema.TokenUsage) error {
|
||||
return u.modelRepo.UpdateUsage(ctx, modelID, usage)
|
||||
}
|
||||
|
||||
func (u *ModelUsecase) SwitchMode(ctx context.Context, req *domain.SwitchModeReq) error {
|
||||
// 只有配置正确才能切换模式
|
||||
if req.Mode == string(consts.ModelSettingModeAuto) {
|
||||
if req.AutoModeAPIKey == "" {
|
||||
return fmt.Errorf("auto mode api key is required")
|
||||
}
|
||||
modelName := req.ChatModel
|
||||
if modelName == "" {
|
||||
modelName = consts.GetAutoModeDefaultModel(string(domain.ModelTypeChat))
|
||||
}
|
||||
// 检查 API Key 是否有效
|
||||
check, err := u.modelkit.CheckModel(ctx, &modelkitDomain.CheckModelReq{
|
||||
Provider: string(domain.ModelProviderBrandBaiZhiCloud),
|
||||
Model: modelName,
|
||||
BaseURL: consts.AutoModeBaseURL,
|
||||
APIKey: req.AutoModeAPIKey,
|
||||
Type: string(domain.ModelTypeChat),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("百智云模型 API Key 检查失败: %w", err)
|
||||
}
|
||||
if check.Error != "" {
|
||||
return fmt.Errorf("百智云模型 API Key 检查失败: %s", check.Error)
|
||||
}
|
||||
} else {
|
||||
needModelTypes := []domain.ModelType{
|
||||
domain.ModelTypeChat,
|
||||
domain.ModelTypeEmbedding,
|
||||
domain.ModelTypeRerank,
|
||||
domain.ModelTypeAnalysis,
|
||||
}
|
||||
for _, modelType := range needModelTypes {
|
||||
if _, err := u.modelRepo.GetModelByType(ctx, modelType); err != nil {
|
||||
return fmt.Errorf("需要配置 %s 模型", modelType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oldModelModeSetting, err := u.GetModelModeSetting(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var isResetEmbeddingUpdateFlag = true
|
||||
// 只有切换手动模式时,重置isManualEmbeddingUpdated为false
|
||||
if req.Mode == string(consts.ModelSettingModeManual) {
|
||||
isResetEmbeddingUpdateFlag = false
|
||||
}
|
||||
|
||||
modelModeSetting, err := u.updateModeSettingConfig(ctx, req.Mode, req.AutoModeAPIKey, req.ChatModel, isResetEmbeddingUpdateFlag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return u.updateRAGModelsByMode(ctx, req.Mode, modelModeSetting.AutoModeAPIKey, oldModelModeSetting)
|
||||
}
|
||||
|
||||
// updateModeSettingConfig 读取当前设置并更新,然后持久化
|
||||
func (u *ModelUsecase) updateModeSettingConfig(ctx context.Context, mode, apiKey, chatModel string, isManualEmbeddingUpdated bool) (*domain.ModelModeSetting, error) {
|
||||
// 读取当前设置
|
||||
setting, err := u.systemSettingRepo.GetSystemSetting(ctx, string(consts.SystemSettingModelMode))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get current model setting: %w", err)
|
||||
}
|
||||
|
||||
var config domain.ModelModeSetting
|
||||
if err := json.Unmarshal(setting.Value, &config); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse current model setting: %w", err)
|
||||
}
|
||||
|
||||
// 更新设置
|
||||
if apiKey != "" {
|
||||
config.AutoModeAPIKey = apiKey
|
||||
}
|
||||
if chatModel != "" {
|
||||
config.ChatModel = chatModel
|
||||
}
|
||||
if mode != "" {
|
||||
config.Mode = consts.ModelSettingMode(mode)
|
||||
}
|
||||
|
||||
config.IsManualEmbeddingUpdated = isManualEmbeddingUpdated
|
||||
|
||||
// 持久化设置
|
||||
updatedValue, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to marshal updated model setting: %w", err)
|
||||
}
|
||||
if err := u.systemSettingRepo.UpdateSystemSetting(ctx, string(consts.SystemSettingModelMode), string(updatedValue)); err != nil {
|
||||
return nil, fmt.Errorf("failed to update model setting: %w", err)
|
||||
}
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
func (u *ModelUsecase) GetModelModeSetting(ctx context.Context) (domain.ModelModeSetting, error) {
|
||||
setting, err := u.systemSettingRepo.GetSystemSetting(ctx, string(consts.SystemSettingModelMode))
|
||||
if err != nil {
|
||||
return domain.ModelModeSetting{}, fmt.Errorf("failed to get model mode setting: %w", err)
|
||||
}
|
||||
var config domain.ModelModeSetting
|
||||
if err := json.Unmarshal(setting.Value, &config); err != nil {
|
||||
return domain.ModelModeSetting{}, fmt.Errorf("failed to parse model mode setting: %w", err)
|
||||
}
|
||||
// 无效设置检查
|
||||
if config == (domain.ModelModeSetting{}) || config.Mode == "" {
|
||||
return domain.ModelModeSetting{}, fmt.Errorf("model mode setting is invalid")
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// updateRAGModelsByMode 根据模式更新 RAG 模型(embedding、rerank、analysis、analysisVL)
|
||||
func (u *ModelUsecase) updateRAGModelsByMode(ctx context.Context, mode, autoModeAPIKey string, oldModelModeSetting domain.ModelModeSetting) error {
|
||||
var isTriggerUpsertRecords = true
|
||||
|
||||
// 手动切换到手动模式, 根据IsManualEmbeddingUpdated字段决定
|
||||
if oldModelModeSetting.Mode == consts.ModelSettingModeManual && mode == string(consts.ModelSettingModeManual) {
|
||||
isTriggerUpsertRecords = oldModelModeSetting.IsManualEmbeddingUpdated
|
||||
}
|
||||
|
||||
ragModelTypes := []domain.ModelType{
|
||||
domain.ModelTypeEmbedding,
|
||||
domain.ModelTypeRerank,
|
||||
domain.ModelTypeAnalysis,
|
||||
domain.ModelTypeAnalysisVL,
|
||||
}
|
||||
|
||||
for _, modelType := range ragModelTypes {
|
||||
var model *domain.Model
|
||||
|
||||
if mode == string(consts.ModelSettingModeManual) {
|
||||
// 获取该类型的活跃模型
|
||||
m, err := u.modelRepo.GetModelByType(ctx, modelType)
|
||||
if err != nil {
|
||||
u.logger.Warn("failed to get model by type", log.String("type", string(modelType)), log.Any("error", err))
|
||||
continue
|
||||
}
|
||||
if m == nil || !m.IsActive {
|
||||
u.logger.Warn("no active model found for type", log.String("type", string(modelType)))
|
||||
continue
|
||||
}
|
||||
model = m
|
||||
} else {
|
||||
modelName := consts.GetAutoModeDefaultModel(string(modelType))
|
||||
model = &domain.Model{
|
||||
Model: modelName,
|
||||
Type: modelType,
|
||||
IsActive: true,
|
||||
BaseURL: consts.AutoModeBaseURL,
|
||||
APIKey: autoModeAPIKey,
|
||||
Provider: domain.ModelProviderBrandBaiZhiCloud,
|
||||
}
|
||||
}
|
||||
|
||||
// 更新RAG存储中的模型
|
||||
if model != nil {
|
||||
// rag store中更新失败不影响其他模型更新
|
||||
if err := u.ragStore.UpdateModel(ctx, model); err != nil {
|
||||
u.logger.Error("failed to update model in RAG store", log.String("model_id", model.ID), log.String("type", string(modelType)), log.Any("error", err))
|
||||
continue
|
||||
}
|
||||
u.logger.Info("successfully updated RAG model", log.String("model name: ", string(model.Model)))
|
||||
}
|
||||
}
|
||||
|
||||
// 触发记录更新
|
||||
if isTriggerUpsertRecords {
|
||||
u.logger.Info("embedding model updated, triggering upsert records")
|
||||
return u.TriggerUpsertRecords(ctx)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ type NodeUsecase struct {
|
|||
logger *log.Logger
|
||||
s3Client *s3.MinioClient
|
||||
rAGService rag.RAGService
|
||||
modelUsecase *ModelUsecase
|
||||
}
|
||||
|
||||
func NewNodeUsecase(
|
||||
|
|
@ -52,6 +53,7 @@ func NewNodeUsecase(
|
|||
s3Client *s3.MinioClient,
|
||||
modelRepo *pg.ModelRepository,
|
||||
authRepo *pg.AuthRepo,
|
||||
modelUsecase *ModelUsecase,
|
||||
) *NodeUsecase {
|
||||
return &NodeUsecase{
|
||||
nodeRepo: nodeRepo,
|
||||
|
|
@ -65,6 +67,7 @@ func NewNodeUsecase(
|
|||
modelRepo: modelRepo,
|
||||
logger: logger.WithModule("usecase.node"),
|
||||
s3Client: s3Client,
|
||||
modelUsecase: modelUsecase,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,6 +86,21 @@ func (u *NodeUsecase) GetList(ctx context.Context, req *domain.GetNodeListReq) (
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
publisherMap, err := u.nodeRepo.GetNodeReleasePublisherMap(ctx, req.KBID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, node := range nodes {
|
||||
if publisherID, exists := publisherMap[node.ID]; exists {
|
||||
node.PublisherId = publisherID
|
||||
}
|
||||
}
|
||||
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
|
|
@ -220,7 +238,7 @@ func (u *NodeUsecase) MoveNode(ctx context.Context, req *domain.MoveNodeReq) err
|
|||
}
|
||||
|
||||
func (u *NodeUsecase) SummaryNode(ctx context.Context, req *domain.NodeSummaryReq) (string, error) {
|
||||
model, err := u.modelRepo.GetChatModel(ctx)
|
||||
model, err := u.modelUsecase.GetChatModel(ctx)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return "", domain.ErrModelNotConfigured
|
||||
|
|
@ -347,6 +365,75 @@ func (u *NodeUsecase) GetNodeReleaseListByKBID(ctx context.Context, kbID string,
|
|||
return items, nil
|
||||
}
|
||||
|
||||
func (u *NodeUsecase) GetNodeReleaseListByParentID(ctx context.Context, kbID, parentID string, authId uint) ([]*domain.ShareNodeDetailItem, error) {
|
||||
// 一次性查询所有节点
|
||||
allNodes, err := u.nodeRepo.GetNodeReleaseListByKBID(ctx, kbID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nodeGroupIds, err := u.GetNodeIdsByAuthId(ctx, authId, consts.NodePermNameVisible)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 先过滤权限
|
||||
visibleNodes := make([]*domain.ShareNodeListItemResp, 0)
|
||||
for i, node := range allNodes {
|
||||
switch node.Permissions.Visible {
|
||||
case consts.NodeAccessPermOpen:
|
||||
visibleNodes = append(visibleNodes, allNodes[i])
|
||||
case consts.NodeAccessPermPartial:
|
||||
if slices.Contains(nodeGroupIds, node.ID) {
|
||||
visibleNodes = append(visibleNodes, allNodes[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 构建父子关系映射
|
||||
childrenMap := make(map[string][]*domain.ShareNodeListItemResp)
|
||||
for _, node := range visibleNodes {
|
||||
childrenMap[node.ParentID] = append(childrenMap[node.ParentID], node)
|
||||
}
|
||||
|
||||
// 构建树结构
|
||||
result := u.buildNodeTree(parentID, childrenMap)
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// buildNodeTree 递归构建节点树结构
|
||||
func (u *NodeUsecase) buildNodeTree(parentID string, childrenMap map[string][]*domain.ShareNodeListItemResp) []*domain.ShareNodeDetailItem {
|
||||
children := childrenMap[parentID]
|
||||
result := make([]*domain.ShareNodeDetailItem, 0, len(children))
|
||||
|
||||
for _, child := range children {
|
||||
node := &domain.ShareNodeDetailItem{
|
||||
ID: child.ID,
|
||||
Name: child.Name,
|
||||
Type: child.Type,
|
||||
ParentID: child.ParentID,
|
||||
Position: child.Position,
|
||||
Meta: child.Meta,
|
||||
Emoji: child.Emoji,
|
||||
UpdatedAt: child.UpdatedAt,
|
||||
Children: make([]*domain.ShareNodeDetailItem, 0),
|
||||
}
|
||||
|
||||
// 如果是文件夹,递归构建其子节点
|
||||
if child.Type == domain.NodeTypeFolder {
|
||||
childNodes := u.buildNodeTree(child.ID, childrenMap)
|
||||
if len(childNodes) > 0 {
|
||||
node.Children = append(node.Children, childNodes...)
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, node)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (u *NodeUsecase) GetNodeIdsByAuthId(ctx context.Context, authId uint, PermName consts.NodePermName) ([]string, error) {
|
||||
authGroups, err := u.authRepo.GetAuthGroupWithParentsByAuthId(ctx, authId)
|
||||
if err != nil {
|
||||
|
|
@ -404,7 +491,7 @@ func (u *NodeUsecase) GetNodePermissionsByID(ctx context.Context, id, kbID strin
|
|||
}
|
||||
|
||||
func (u *NodeUsecase) ValidateNodePermissionsEdit(req v1.NodePermissionEditReq, edition consts.LicenseEdition) error {
|
||||
if edition != consts.LicenseEditionEnterprise {
|
||||
if !slices.Contains([]consts.LicenseEdition{consts.LicenseEditionBusiness, consts.LicenseEditionEnterprise}, edition) {
|
||||
if req.Permissions.Answerable == consts.NodeAccessPermPartial || req.Permissions.Visitable == consts.NodeAccessPermPartial || req.Permissions.Visible == consts.NodeAccessPermPartial {
|
||||
return domain.ErrPermissionDenied
|
||||
}
|
||||
|
|
@ -573,3 +660,30 @@ func (u *NodeUsecase) SyncRagNodeStatus(ctx context.Context) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *NodeUsecase) NodeRestudy(ctx context.Context, req *v1.NodeRestudyReq) error {
|
||||
nodeReleases, err := u.nodeRepo.GetLatestNodeReleaseByNodeIDs(ctx, req.KbId, req.NodeIds)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get latest node release failed: %w", err)
|
||||
}
|
||||
|
||||
for _, nodeRelease := range nodeReleases {
|
||||
if nodeRelease.DocID == "" {
|
||||
continue
|
||||
}
|
||||
if err := u.ragRepo.AsyncUpdateNodeReleaseVector(ctx, []*domain.NodeReleaseVectorRequest{
|
||||
{
|
||||
KBID: nodeRelease.KBID,
|
||||
NodeReleaseID: nodeRelease.ID,
|
||||
Action: "upsert",
|
||||
},
|
||||
}); err != nil {
|
||||
u.logger.Error("async update node release vector failed",
|
||||
log.String("node_release_id", nodeRelease.ID),
|
||||
log.Error(err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
|
|
@ -67,12 +68,12 @@ func (u *StatUseCase) ValidateStatDay(statDay consts.StatDay, edition consts.Lic
|
|||
case consts.StatDay1:
|
||||
return nil
|
||||
case consts.StatDay7:
|
||||
if edition < consts.LicenseEditionContributor {
|
||||
if edition == consts.LicenseEditionFree {
|
||||
return domain.ErrPermissionDenied
|
||||
}
|
||||
return nil
|
||||
case consts.StatDay30, consts.StatDay90:
|
||||
if edition < consts.LicenseEditionEnterprise {
|
||||
if !slices.Contains([]consts.LicenseEdition{consts.LicenseEditionBusiness, consts.LicenseEditionEnterprise}, edition) {
|
||||
return domain.ErrPermissionDenied
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -2,13 +2,18 @@ package utils
|
|||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func GetClientIPFromRemoteAddr(c echo.Context) string {
|
||||
addr := c.Request().RemoteAddr
|
||||
return ExtractHostFromRemoteAddr(c.Request())
|
||||
}
|
||||
|
||||
func ExtractHostFromRemoteAddr(r *http.Request) string {
|
||||
addr := r.RemoteAddr
|
||||
if addr == "" {
|
||||
return ""
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
"build:dev": "vite build --m development",
|
||||
"build": "tsc -b && vite build",
|
||||
"build:analyze": "tsc -b && vite build -- --analyze",
|
||||
"icon": "node ./scripts/downLoadIcon.cjs",
|
||||
"api": "cx-swagger-api"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
async function downloadFile(url) {
|
||||
const iconPath = path.resolve(__dirname, "../src/assets/fonts/iconfont.js");
|
||||
const iconDir = path.dirname(iconPath);
|
||||
|
||||
// 检查目录是否存在,不存在则创建
|
||||
if (!fs.existsSync(iconDir)) {
|
||||
fs.mkdirSync(iconDir, { recursive: true });
|
||||
console.log(`目录 ${iconDir} 已创建`);
|
||||
}
|
||||
|
||||
const response = await fetch(`https:${url}`, {
|
||||
method: "GET",
|
||||
// responseType: "stream", // fetch 不支持此参数
|
||||
}).then((res) => res.text());
|
||||
fs.writeFileSync(iconPath, response);
|
||||
console.log("Download Icon Success");
|
||||
}
|
||||
let argument = process.argv.splice(2);
|
||||
downloadFile(argument[0]);
|
||||
|
||||
|
|
@ -323,7 +323,6 @@ export type WelcomeSetting = {
|
|||
export type SEOSetting = {
|
||||
keyword: string;
|
||||
desc: string;
|
||||
auto_sitemap: boolean;
|
||||
};
|
||||
|
||||
export type CustomCodeSetting = {
|
||||
|
|
@ -588,6 +587,7 @@ export type ChatConversationItem = {
|
|||
export type ChatConversationPair = {
|
||||
user: string;
|
||||
assistant: string;
|
||||
thinking_content: string;
|
||||
created_at: string;
|
||||
info: {
|
||||
feedback_content: string;
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 354 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 360 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
|
@ -1,6 +1,6 @@
|
|||
import Logo from '@/assets/images/logo.png';
|
||||
import { Avatar as MuiAvatar, SxProps } from '@mui/material';
|
||||
import { Icon } from '@ctzhian/ui';
|
||||
import { IconDandulogo } from '@panda-wiki/icons';
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
interface AvatarProps {
|
||||
|
|
@ -15,9 +15,8 @@ const Avatar = (props: AvatarProps) => {
|
|||
const src = props.src;
|
||||
|
||||
const LogoIcon = (
|
||||
<Icon
|
||||
<IconDandulogo
|
||||
sx={{ width: '100%', height: '100%', color: 'text.primary' }}
|
||||
type='icon-dandulogo'
|
||||
/>
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useState, useRef, useEffect } from 'react';
|
||||
import { Box, Stepper, Step, StepLabel } from '@mui/material';
|
||||
import { Modal } from '@ctzhian/ui';
|
||||
import { Modal, message } from '@ctzhian/ui';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import {
|
||||
setKbC,
|
||||
|
|
@ -10,18 +10,20 @@ import {
|
|||
import { useAppSelector, useAppDispatch } from '@/store';
|
||||
import { postApiV1KnowledgeBaseRelease } from '@/request/KnowledgeBase';
|
||||
import {
|
||||
Step1Config,
|
||||
Step2Import,
|
||||
Step3Publish,
|
||||
Step4Test,
|
||||
Step5Decorate,
|
||||
Step6Complete,
|
||||
Step1Model,
|
||||
Step2Config,
|
||||
Step3Import,
|
||||
Step4Publish,
|
||||
Step5Test,
|
||||
Step6Decorate,
|
||||
Step7Complete,
|
||||
} from './steps';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
// Remove interface as we're using Redux state
|
||||
|
||||
const steps = [
|
||||
'模型配置',
|
||||
'配置监听',
|
||||
'录入文档',
|
||||
'发布内容',
|
||||
|
|
@ -31,20 +33,19 @@ const steps = [
|
|||
];
|
||||
|
||||
const CreateWikiModal = () => {
|
||||
const { kb_c, kb_id, kbList, modelStatus } = useAppSelector(
|
||||
state => state.config,
|
||||
);
|
||||
const { kb_c, kb_id, kbList } = useAppSelector(state => state.config);
|
||||
const dispatch = useAppDispatch();
|
||||
const location = useLocation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [activeStep, setActiveStep] = useState(0);
|
||||
const [nodeIds, setNodeIds] = useState<string[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const step1ConfigRef = useRef<{ onSubmit: () => Promise<void> }>(null);
|
||||
const step2ImportRef = useRef<{
|
||||
const Step1ModelRef = useRef<{ onSubmit: () => Promise<void> }>(null);
|
||||
const step2ConfigRef = useRef<{ onSubmit: () => Promise<void> }>(null);
|
||||
const step3ImportRef = useRef<{
|
||||
onSubmit: () => Promise<Record<'id', string>[]>;
|
||||
}>(null);
|
||||
const step5DecorateRef = useRef<{ onSubmit: () => Promise<void> }>(null);
|
||||
const step6DecorateRef = useRef<{ onSubmit: () => Promise<void> }>(null);
|
||||
|
||||
const onCancel = () => {
|
||||
dispatch(setKbC(false));
|
||||
|
|
@ -66,7 +67,20 @@ const CreateWikiModal = () => {
|
|||
const handleNext = () => {
|
||||
if (activeStep === 0) {
|
||||
setLoading(true);
|
||||
step1ConfigRef.current
|
||||
Step1ModelRef.current
|
||||
?.onSubmit?.()
|
||||
.then(() => {
|
||||
setActiveStep(prev => prev + 1);
|
||||
})
|
||||
.catch(error => {
|
||||
message.error(error.message || '模型配置验证失败');
|
||||
})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
} else if (activeStep === 1) {
|
||||
setLoading(true);
|
||||
step2ConfigRef.current
|
||||
?.onSubmit?.()
|
||||
.then(() => {
|
||||
setActiveStep(prev => prev + 1);
|
||||
|
|
@ -74,9 +88,9 @@ const CreateWikiModal = () => {
|
|||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
} else if (activeStep === 1) {
|
||||
} else if (activeStep === 2) {
|
||||
setLoading(true);
|
||||
step2ImportRef.current
|
||||
step3ImportRef.current
|
||||
?.onSubmit?.()
|
||||
.then(res => {
|
||||
setNodeIds(res.map(item => item.id));
|
||||
|
|
@ -85,17 +99,17 @@ const CreateWikiModal = () => {
|
|||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
} else if (activeStep === 2) {
|
||||
} else if (activeStep === 3) {
|
||||
setLoading(true);
|
||||
onPublish().finally(() => {
|
||||
setActiveStep(prev => prev + 1);
|
||||
setLoading(false);
|
||||
});
|
||||
} else if (activeStep === 3) {
|
||||
setActiveStep(prev => prev + 1);
|
||||
} else if (activeStep === 4) {
|
||||
setActiveStep(prev => prev + 1);
|
||||
} else if (activeStep === 5) {
|
||||
setLoading(true);
|
||||
step5DecorateRef.current
|
||||
step6DecorateRef.current
|
||||
?.onSubmit?.()
|
||||
.then(() => {
|
||||
setActiveStep(prev => prev + 1);
|
||||
|
|
@ -103,7 +117,7 @@ const CreateWikiModal = () => {
|
|||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
} else if (activeStep === 5) {
|
||||
} else if (activeStep === 6) {
|
||||
onCancel();
|
||||
}
|
||||
};
|
||||
|
|
@ -117,17 +131,19 @@ const CreateWikiModal = () => {
|
|||
const renderStepContent = () => {
|
||||
switch (activeStep) {
|
||||
case 0:
|
||||
return <Step1Config ref={step1ConfigRef} />;
|
||||
return <Step1Model ref={Step1ModelRef} />;
|
||||
case 1:
|
||||
return <Step2Import ref={step2ImportRef} />;
|
||||
return <Step2Config ref={step2ConfigRef} />;
|
||||
case 2:
|
||||
return <Step3Publish />;
|
||||
return <Step3Import ref={step3ImportRef} />;
|
||||
case 3:
|
||||
return <Step4Test />;
|
||||
return <Step4Publish />;
|
||||
case 4:
|
||||
return <Step5Decorate ref={step5DecorateRef} nodeIds={nodeIds} />;
|
||||
return <Step5Test />;
|
||||
case 5:
|
||||
return <Step6Complete />;
|
||||
return <Step6Decorate ref={step6DecorateRef} nodeIds={nodeIds} />;
|
||||
case 6:
|
||||
return <Step7Complete />;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
@ -148,8 +164,8 @@ const CreateWikiModal = () => {
|
|||
}, [kb_c]);
|
||||
|
||||
useEffect(() => {
|
||||
if (kbList?.length === 0 && modelStatus) setOpen(true);
|
||||
}, [kbList, modelStatus]);
|
||||
if (kbList?.length === 0) setOpen(true);
|
||||
}, [kbList]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
|
|
|
|||
|
|
@ -0,0 +1,122 @@
|
|||
import React, {
|
||||
useState,
|
||||
useImperativeHandle,
|
||||
Ref,
|
||||
useEffect,
|
||||
useRef,
|
||||
} from 'react';
|
||||
import { Box } from '@mui/material';
|
||||
import { useAppSelector, useAppDispatch } from '@/store';
|
||||
import { setModelList } from '@/store/slices/config';
|
||||
import { getApiV1ModelList, getApiV1ModelModeSetting } from '@/request/Model';
|
||||
import { GithubComChaitinPandaWikiDomainModelListItem } from '@/request/types';
|
||||
import ModelConfig, {
|
||||
ModelConfigRef,
|
||||
} from '@/components/System/component/ModelConfig';
|
||||
|
||||
interface Step1ModelProps {
|
||||
ref: Ref<{ onSubmit: () => Promise<void> }>;
|
||||
}
|
||||
|
||||
const Step1Model: React.FC<Step1ModelProps> = ({ ref }) => {
|
||||
const { modelList } = useAppSelector(state => state.config);
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const modelConfigRef = useRef<ModelConfigRef>(null);
|
||||
|
||||
const [chatModelData, setChatModelData] =
|
||||
useState<GithubComChaitinPandaWikiDomainModelListItem | null>(null);
|
||||
const [embeddingModelData, setEmbeddingModelData] =
|
||||
useState<GithubComChaitinPandaWikiDomainModelListItem | null>(null);
|
||||
const [rerankModelData, setRerankModelData] =
|
||||
useState<GithubComChaitinPandaWikiDomainModelListItem | null>(null);
|
||||
const [analysisModelData, setAnalysisModelData] =
|
||||
useState<GithubComChaitinPandaWikiDomainModelListItem | null>(null);
|
||||
const [analysisVLModelData, setAnalysisVLModelData] =
|
||||
useState<GithubComChaitinPandaWikiDomainModelListItem | null>(null);
|
||||
|
||||
const getModelList = () => {
|
||||
getApiV1ModelList().then(res => {
|
||||
dispatch(
|
||||
setModelList(res as GithubComChaitinPandaWikiDomainModelListItem[]),
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const handleModelList = (
|
||||
list: GithubComChaitinPandaWikiDomainModelListItem[],
|
||||
) => {
|
||||
const chat = list.find(it => it.type === 'chat') || null;
|
||||
const embedding = list.find(it => it.type === 'embedding') || null;
|
||||
const rerank = list.find(it => it.type === 'rerank') || null;
|
||||
const analysis = list.find(it => it.type === 'analysis') || null;
|
||||
const analysisVL = list.find(it => it.type === 'analysis-vl') || null;
|
||||
setChatModelData(chat);
|
||||
setEmbeddingModelData(embedding);
|
||||
setRerankModelData(rerank);
|
||||
setAnalysisModelData(analysis);
|
||||
setAnalysisVLModelData(analysisVL);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (modelList) {
|
||||
handleModelList(modelList);
|
||||
}
|
||||
}, [modelList]);
|
||||
|
||||
const onSubmit = async () => {
|
||||
await modelConfigRef.current?.onSubmit?.();
|
||||
// 检查模型模式设置
|
||||
try {
|
||||
const modeSetting = await getApiV1ModelModeSetting();
|
||||
|
||||
// 如果是 auto 模式,检查是否配置了 API key
|
||||
if (modeSetting?.mode === 'auto') {
|
||||
if (!modeSetting.auto_mode_api_key) {
|
||||
return Promise.reject(new Error('请点击应用完成模型配置'));
|
||||
}
|
||||
} else {
|
||||
// 手动模式检查
|
||||
if (
|
||||
!chatModelData ||
|
||||
!embeddingModelData ||
|
||||
!rerankModelData ||
|
||||
!analysisModelData
|
||||
) {
|
||||
return Promise.reject(new Error('请配置必要的模型后点击应用'));
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
return Promise.reject(new Error('配置模型失败'));
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
onSubmit,
|
||||
}));
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<ModelConfig
|
||||
ref={modelConfigRef}
|
||||
onCloseModal={() => {}}
|
||||
chatModelData={chatModelData}
|
||||
embeddingModelData={embeddingModelData}
|
||||
rerankModelData={rerankModelData}
|
||||
analysisModelData={analysisModelData}
|
||||
analysisVLModelData={analysisVLModelData}
|
||||
getModelList={getModelList}
|
||||
hideDocumentationHint={true}
|
||||
showTip={true}
|
||||
showSaveBtn={false}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default Step1Model;
|
||||
|
|
@ -73,11 +73,11 @@ const VALIDATION_RULES = {
|
|||
},
|
||||
};
|
||||
|
||||
interface Step1ConfigProps {
|
||||
interface Step2ConfigProps {
|
||||
ref: Ref<{ onSubmit: () => Promise<unknown> }>;
|
||||
}
|
||||
|
||||
const Step1Config: React.FC<Step1ConfigProps> = ({ ref }) => {
|
||||
const Step2Config: React.FC<Step2ConfigProps> = ({ ref }) => {
|
||||
const {
|
||||
control,
|
||||
formState: { errors },
|
||||
|
|
@ -358,4 +358,4 @@ const Step1Config: React.FC<Step1ConfigProps> = ({ ref }) => {
|
|||
);
|
||||
};
|
||||
|
||||
export default Step1Config;
|
||||
export default Step2Config;
|
||||
|
|
@ -5,11 +5,11 @@ import { postApiV1Node } from '@/request/Node';
|
|||
import { INIT_DOC_DATA } from './initData';
|
||||
import { useAppSelector } from '@/store';
|
||||
|
||||
interface Step2ImportProps {
|
||||
interface Step3ImportProps {
|
||||
ref: Ref<{ onSubmit: () => Promise<Record<'id', string>[]> }>;
|
||||
}
|
||||
|
||||
const Step2Import: React.FC<Step2ImportProps> = ({ ref }) => {
|
||||
const Step3Import: React.FC<Step3ImportProps> = ({ ref }) => {
|
||||
const { kb_id } = useAppSelector(state => state.config);
|
||||
const onSubmit = () => {
|
||||
return Promise.all(
|
||||
|
|
@ -42,4 +42,4 @@ const Step2Import: React.FC<Step2ImportProps> = ({ ref }) => {
|
|||
);
|
||||
};
|
||||
|
||||
export default Step2Import;
|
||||
export default Step3Import;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { Box, Stack, FormControlLabel, Checkbox } from '@mui/material';
|
||||
import publish from '@/assets/images/init/publish.png';
|
||||
|
||||
const Step3Publish = () => {
|
||||
const Step4Publish = () => {
|
||||
return (
|
||||
<Stack gap={2} sx={{ textAlign: 'center', py: 4 }}>
|
||||
<Box component='img' src={publish} sx={{ width: '100%' }}></Box>
|
||||
|
|
@ -18,4 +18,4 @@ const Step3Publish = () => {
|
|||
);
|
||||
};
|
||||
|
||||
export default Step3Publish;
|
||||
export default Step4Publish;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { Box, Stack } from '@mui/material';
|
||||
import test from '@/assets/images/init/test.png';
|
||||
|
||||
const Step4Test = () => {
|
||||
const Step5Test = () => {
|
||||
return (
|
||||
<Stack gap={2} sx={{ textAlign: 'center', py: 4 }}>
|
||||
<Box component='img' src={test} sx={{ width: '100%' }}></Box>
|
||||
|
|
@ -9,4 +9,4 @@ const Step4Test = () => {
|
|||
);
|
||||
};
|
||||
|
||||
export default Step4Test;
|
||||
export default Step5Test;
|
||||
|
|
@ -5,12 +5,12 @@ import { INIT_LADING_DATA } from './initData';
|
|||
import { getApiV1AppDetail, putApiV1App } from '@/request/App';
|
||||
import { useAppSelector } from '@/store';
|
||||
|
||||
interface Step5DecorateProps {
|
||||
interface Step6DecorateProps {
|
||||
ref: Ref<{ onSubmit: () => void }>;
|
||||
nodeIds: string[];
|
||||
}
|
||||
|
||||
const Step5Decorate: React.FC<Step5DecorateProps> = ({ ref, nodeIds }) => {
|
||||
const Step6Decorate: React.FC<Step6DecorateProps> = ({ ref, nodeIds }) => {
|
||||
const { kb_id } = useAppSelector(state => state.config);
|
||||
const onSubmit = () => {
|
||||
return getApiV1AppDetail({
|
||||
|
|
@ -60,4 +60,4 @@ const Step5Decorate: React.FC<Step5DecorateProps> = ({ ref, nodeIds }) => {
|
|||
);
|
||||
};
|
||||
|
||||
export default Step5Decorate;
|
||||
export default Step6Decorate;
|
||||
|
|
@ -3,7 +3,7 @@ import { Box, Stack, Button } from '@mui/material';
|
|||
import complete from '@/assets/images/init/complete.png';
|
||||
import { useAppSelector } from '@/store';
|
||||
|
||||
const Step6Complete = () => {
|
||||
const Step7Complete = () => {
|
||||
const { kbDetail } = useAppSelector(state => state.config);
|
||||
|
||||
const wikiUrl = useMemo(() => {
|
||||
|
|
@ -56,4 +56,4 @@ const Step6Complete = () => {
|
|||
);
|
||||
};
|
||||
|
||||
export default Step6Complete;
|
||||
export default Step7Complete;
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
export { default as Step1Config } from './Step1Config';
|
||||
export { default as Step2Import } from './Step2Import';
|
||||
export { default as Step3Publish } from './Step3Publish';
|
||||
export { default as Step4Test } from './Step4Test';
|
||||
export { default as Step5Decorate } from './Step5Decorate';
|
||||
export { default as Step6Complete } from './Step6Complete';
|
||||
export { default as Step1Model } from './Step1Model';
|
||||
export { default as Step2Config } from './Step2Config';
|
||||
export { default as Step3Import } from './Step3Import';
|
||||
export { default as Step4Publish } from './Step4Publish';
|
||||
export { default as Step5Test } from './Step5Test';
|
||||
export { default as Step6Decorate } from './Step6Decorate';
|
||||
export { default as Step7Complete } from './Step7Complete';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { FooterSetting } from '@/api/type';
|
||||
import { Icon } from '@ctzhian/ui';
|
||||
import { IconShanchu2, IconDrag, IconTianjia } from '@panda-wiki/icons';
|
||||
import {
|
||||
closestCenter,
|
||||
DndContext,
|
||||
|
|
@ -100,7 +100,7 @@ const LinkItem = forwardRef<HTMLDivElement, LinkItemProps>(
|
|||
}}
|
||||
{...dragHandleProps}
|
||||
>
|
||||
<Icon type='icon-drag' />
|
||||
<IconDrag sx={{ fontSize: '18px' }} />
|
||||
</IconButton>
|
||||
<Box
|
||||
sx={{
|
||||
|
|
@ -123,7 +123,7 @@ const LinkItem = forwardRef<HTMLDivElement, LinkItemProps>(
|
|||
ml: 'auto',
|
||||
}}
|
||||
>
|
||||
<Icon type='icon-shanchu2' sx={{ fontSize: '12px' }} />
|
||||
<IconShanchu2 sx={{ fontSize: '12px' }} />
|
||||
</IconButton>
|
||||
</Stack>
|
||||
<Controller
|
||||
|
|
@ -373,7 +373,7 @@ const Item = forwardRef<HTMLDivElement, ItemProps>(
|
|||
}}
|
||||
{...dragHandleProps}
|
||||
>
|
||||
<Icon type='icon-drag' />
|
||||
<IconDrag sx={{ fontSize: '18px' }} />
|
||||
</IconButton>
|
||||
<Box
|
||||
sx={{
|
||||
|
|
@ -396,7 +396,7 @@ const Item = forwardRef<HTMLDivElement, ItemProps>(
|
|||
ml: 'auto',
|
||||
}}
|
||||
>
|
||||
<Icon type='icon-shanchu2' sx={{ fontSize: '12px' }} />
|
||||
<IconShanchu2 sx={{ fontSize: '12px' }} />
|
||||
</IconButton>
|
||||
</Stack>
|
||||
<Controller
|
||||
|
|
@ -513,8 +513,7 @@ const Item = forwardRef<HTMLDivElement, ItemProps>(
|
|||
}}
|
||||
onClick={handleAddLink}
|
||||
>
|
||||
<Icon
|
||||
type='icon-tianjia'
|
||||
<IconTianjia
|
||||
sx={{ fontSize: '10px !important', color: '#5F58FE' }}
|
||||
/>
|
||||
<Box
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { CardWebHeaderBtn } from '@/api';
|
||||
import UploadFile from '@/components/UploadFile';
|
||||
import { useAppDispatch, useAppSelector } from '@/store';
|
||||
import { setAppPreviewData } from '@/store/slices/config';
|
||||
|
||||
import {
|
||||
Box,
|
||||
Checkbox,
|
||||
|
|
@ -13,16 +13,15 @@ import {
|
|||
Stack,
|
||||
TextField,
|
||||
} from '@mui/material';
|
||||
import { Icon } from '@ctzhian/ui';
|
||||
import { IconShanchu2, IconDrag } from '@panda-wiki/icons';
|
||||
import {
|
||||
CSSProperties,
|
||||
Dispatch,
|
||||
forwardRef,
|
||||
HTMLAttributes,
|
||||
SetStateAction,
|
||||
useEffect,
|
||||
} from 'react';
|
||||
import { Control, Controller, useForm } from 'react-hook-form';
|
||||
import { Control, Controller } from 'react-hook-form';
|
||||
|
||||
export type ItemProps = Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> & {
|
||||
item: CardWebHeaderBtn;
|
||||
|
|
@ -300,7 +299,7 @@ const Item = forwardRef<HTMLDivElement, ItemProps>(
|
|||
height: '28px',
|
||||
}}
|
||||
>
|
||||
<Icon type='icon-shanchu2' sx={{ fontSize: '12px' }} />
|
||||
<IconShanchu2 sx={{ fontSize: '12px' }} />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
size='small'
|
||||
|
|
@ -311,7 +310,7 @@ const Item = forwardRef<HTMLDivElement, ItemProps>(
|
|||
}}
|
||||
{...dragHandleProps}
|
||||
>
|
||||
<Icon type='icon-drag' />
|
||||
<IconDrag sx={{ fontSize: '18px' }} />
|
||||
</IconButton>
|
||||
</Stack>
|
||||
</Stack>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import UploadFile from '@/components/UploadFile';
|
||||
import { DomainSocialMediaAccount } from '@/request/types';
|
||||
import { Icon } from '@ctzhian/ui';
|
||||
import { IconShanchu2, IconDrag } from '@panda-wiki/icons';
|
||||
import {
|
||||
Box,
|
||||
IconButton,
|
||||
|
|
@ -92,7 +92,7 @@ const Item = forwardRef<HTMLDivElement, SocialInfoProps>(
|
|||
}}
|
||||
{...dragHandleProps}
|
||||
>
|
||||
<Icon type='icon-drag' />
|
||||
<IconDrag sx={{ fontSize: '18px' }} />
|
||||
</IconButton>
|
||||
<Box
|
||||
sx={{
|
||||
|
|
@ -120,7 +120,7 @@ const Item = forwardRef<HTMLDivElement, SocialInfoProps>(
|
|||
ml: 'auto',
|
||||
}}
|
||||
>
|
||||
<Icon type='icon-shanchu2' sx={{ fontSize: '12px' }} />
|
||||
<IconShanchu2 sx={{ fontSize: '12px' }} />
|
||||
</IconButton>
|
||||
</Stack>
|
||||
<Stack direction={'row'} gap={1}>
|
||||
|
|
@ -142,16 +142,10 @@ const Item = forwardRef<HTMLDivElement, SocialInfoProps>(
|
|||
}}
|
||||
renderValue={selected => {
|
||||
const option = options.find(i => i.key === selected);
|
||||
const AppIcon = option?.config_type || option?.type;
|
||||
return (
|
||||
<Stack justifyContent={'center'} sx={{ mt: '2px' }}>
|
||||
<Icon
|
||||
type={
|
||||
option
|
||||
? option?.config_type || option?.type || ''
|
||||
: ''
|
||||
}
|
||||
sx={{ fontSize: '14px' }}
|
||||
/>
|
||||
{AppIcon && <AppIcon sx={{ fontSize: '14px' }} />}
|
||||
</Stack>
|
||||
);
|
||||
}}
|
||||
|
|
@ -185,7 +179,9 @@ const Item = forwardRef<HTMLDivElement, SocialInfoProps>(
|
|||
borderRadius: 1,
|
||||
}}
|
||||
>
|
||||
{options.map(item => (
|
||||
{options.map(item => {
|
||||
const AppIcon = item?.config_type || item?.type;
|
||||
return (
|
||||
<ToggleButton
|
||||
key={item.key}
|
||||
value={item.key}
|
||||
|
|
@ -201,14 +197,13 @@ const Item = forwardRef<HTMLDivElement, SocialInfoProps>(
|
|||
gap={1}
|
||||
alignItems='center'
|
||||
>
|
||||
<Icon
|
||||
type={item?.config_type || item?.type}
|
||||
sx={{ fontSize: '16px' }}
|
||||
/>
|
||||
{/* <Box>{item.value || item.key}</Box> */}
|
||||
{AppIcon && (
|
||||
<AppIcon sx={{ fontSize: '16px' }} />
|
||||
)}
|
||||
</Stack>
|
||||
</ToggleButton>
|
||||
))}
|
||||
);
|
||||
})}
|
||||
</ToggleButtonGroup>
|
||||
</MenuItem>
|
||||
</Select>
|
||||
|
|
|
|||
|
|
@ -1,99 +0,0 @@
|
|||
import { Box, Button, IconButton, Stack } from '@mui/material';
|
||||
import { Icon } from '@ctzhian/ui';
|
||||
import { AppSetting } from '@/api';
|
||||
import { useState } from 'react';
|
||||
import { getButtonThemeStyle } from './buttonThemeUtils';
|
||||
|
||||
const NavBtns = ({ detail }: { detail?: Partial<AppSetting> }) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
<IconButton
|
||||
size='small'
|
||||
onClick={() => setOpen(!open)}
|
||||
sx={{
|
||||
color: 'text.primary',
|
||||
width: 40,
|
||||
height: 40,
|
||||
}}
|
||||
>
|
||||
<Icon type='icon-a-caidan' />
|
||||
</IconButton>
|
||||
<Box
|
||||
sx={{
|
||||
position: 'absolute',
|
||||
width: '100%',
|
||||
height: '110vh',
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
zIndex: 999,
|
||||
transition: 'all 0.3s ease-in-out',
|
||||
transform: 'translateX(200%) translateY(-200%)',
|
||||
...(open && {
|
||||
bgcolor: 'background.default',
|
||||
transform: 'translateX(0) translateY(0)',
|
||||
}),
|
||||
}}
|
||||
>
|
||||
<Stack
|
||||
direction='row'
|
||||
alignItems='center'
|
||||
gap={1.5}
|
||||
sx={{ py: '14px', cursor: 'pointer', ml: 1.5, color: 'text.primary' }}
|
||||
>
|
||||
{detail?.icon && <img src={detail?.icon} alt='logo' width={32} />}
|
||||
<Box sx={{ fontSize: 18 }}>{detail?.title}</Box>
|
||||
</Stack>
|
||||
<Stack gap={4} sx={{ px: 3, mt: 4, bgcolor: 'background.default' }}>
|
||||
{detail?.btns?.map(item => (
|
||||
<Button
|
||||
key={item.id}
|
||||
fullWidth
|
||||
variant={item.variant}
|
||||
startIcon={
|
||||
item.showIcon && item.icon ? (
|
||||
<img src={item.icon} alt='logo' width={36} height={36} />
|
||||
) : null
|
||||
}
|
||||
sx={{
|
||||
textTransform: 'none',
|
||||
justifyContent: 'flex-start',
|
||||
height: '60px',
|
||||
px: 4,
|
||||
gap: 3,
|
||||
fontSize: 18,
|
||||
'& .MuiButton-startIcon': {
|
||||
ml: 0,
|
||||
mr: 0,
|
||||
},
|
||||
...getButtonThemeStyle(detail?.theme_mode, item.variant),
|
||||
}}
|
||||
>
|
||||
{item.text}
|
||||
</Button>
|
||||
))}
|
||||
</Stack>
|
||||
<IconButton
|
||||
size='small'
|
||||
onClick={() => setOpen(!open)}
|
||||
sx={{
|
||||
position: 'absolute',
|
||||
top: 10,
|
||||
right: 10,
|
||||
color: 'text.primary',
|
||||
width: 40,
|
||||
height: 40,
|
||||
zIndex: 1,
|
||||
}}
|
||||
>
|
||||
<Icon type='icon-chahao' />
|
||||
</IconButton>
|
||||
</Box>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default NavBtns;
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
import React, { Dispatch, ReactNode, SetStateAction } from 'react';
|
||||
import { Box, IconButton } from '@mui/material';
|
||||
import CloseIcon from '@mui/icons-material/Close';
|
||||
|
||||
interface OverlayProps {
|
||||
open: boolean;
|
||||
onClose: Dispatch<SetStateAction<boolean>>;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
const Overlay: React.FC<OverlayProps> = ({ open, onClose, children }) => {
|
||||
return (
|
||||
<>
|
||||
{open && (
|
||||
<Box
|
||||
sx={{
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.7)',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
zIndex: 1300,
|
||||
}}
|
||||
onClick={() => onClose(false)}
|
||||
>
|
||||
<IconButton
|
||||
onClick={() => onClose(false)}
|
||||
sx={{
|
||||
position: 'absolute',
|
||||
top: 16,
|
||||
right: 16,
|
||||
color: 'white',
|
||||
zIndex: 1310,
|
||||
}}
|
||||
>
|
||||
<CloseIcon />
|
||||
</IconButton>
|
||||
<Box onClick={e => e.stopPropagation()}>{children}</Box>
|
||||
</Box>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Overlay;
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
/**
|
||||
* 根据主题模式和按钮变体生成相应的样式
|
||||
* @param themeMode 主题模式 ('light' | 'dark')
|
||||
* @param variant 按钮变体 ('contained' | 'outlined' | 'text')
|
||||
* @returns 返回相应的按钮样式对象
|
||||
*/
|
||||
export const getButtonThemeStyle = (
|
||||
themeMode: 'light' | 'dark' | undefined,
|
||||
variant: string,
|
||||
) => {
|
||||
// 只在dark主题下应用特殊样式
|
||||
if (themeMode === 'dark') {
|
||||
switch (variant) {
|
||||
case 'contained':
|
||||
return {
|
||||
bgcolor: 'primary.main',
|
||||
color: 'primary.contrastText',
|
||||
borderColor: 'primary.main',
|
||||
'&:hover': {
|
||||
bgcolor: 'primary.dark',
|
||||
borderColor: 'primary.dark',
|
||||
},
|
||||
};
|
||||
case 'outlined':
|
||||
return {
|
||||
borderColor: 'primary.main',
|
||||
color: 'primary.main',
|
||||
'&:hover': {
|
||||
bgcolor: 'action.hover',
|
||||
borderColor: 'primary.main',
|
||||
},
|
||||
};
|
||||
case 'text':
|
||||
return {
|
||||
color: 'primary.main',
|
||||
'&:hover': {
|
||||
bgcolor: 'action.hover',
|
||||
},
|
||||
};
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
if (themeMode === 'light') {
|
||||
switch (variant) {
|
||||
case 'text':
|
||||
return {
|
||||
color: 'text.primary',
|
||||
};
|
||||
}
|
||||
}
|
||||
return {};
|
||||
};
|
||||
|
||||
export default getButtonThemeStyle;
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
import { SwitchProps, Box } from '@mui/material';
|
||||
import { Icon } from '@ctzhian/ui';
|
||||
import MySwitch from './Switch';
|
||||
|
||||
const ThemeSwitch = (props: SwitchProps) => {
|
||||
return (
|
||||
<MySwitch
|
||||
{...props}
|
||||
icon={
|
||||
<Box
|
||||
sx={{
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
width: 22,
|
||||
height: 22,
|
||||
bgcolor: '#fff',
|
||||
borderRadius: '50%',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<Icon
|
||||
type='icon-mingliangmoshi'
|
||||
sx={{ color: '#000', fontSize: 16 }}
|
||||
/>
|
||||
</Box>
|
||||
</Box>
|
||||
}
|
||||
checkedIcon={
|
||||
<Box
|
||||
sx={{
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
width: 22,
|
||||
height: 22,
|
||||
bgcolor: '#fff',
|
||||
borderRadius: '50%',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<Icon
|
||||
type='icon-shensemoshi'
|
||||
sx={{ color: '#000', fontSize: 16 }}
|
||||
/>
|
||||
</Box>
|
||||
</Box>
|
||||
}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default ThemeSwitch;
|
||||
|
|
@ -10,7 +10,7 @@ import {
|
|||
alpha,
|
||||
} from '@mui/material';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { Icon } from '@ctzhian/ui';
|
||||
import { IconWangyeguajian } from '@panda-wiki/icons';
|
||||
import { Dispatch, SetStateAction, useMemo, useState } from 'react';
|
||||
import type { CSSProperties } from 'react';
|
||||
import { Component } from '../../index';
|
||||
|
|
@ -185,8 +185,7 @@ const ComponentBar = ({
|
|||
}}
|
||||
{...(!item.fixed ? { ...attributes, ...listeners } : {})}
|
||||
>
|
||||
<Icon
|
||||
type='icon-wangyeguajian'
|
||||
<IconWangyeguajian
|
||||
sx={{
|
||||
color:
|
||||
item.id === curComponent.id
|
||||
|
|
@ -196,7 +195,7 @@ const ComponentBar = ({
|
|||
: 'text.secondary',
|
||||
fontSize: '14px',
|
||||
}}
|
||||
></Icon>
|
||||
></IconWangyeguajian>
|
||||
<Typography
|
||||
sx={{
|
||||
marginLeft: '8px',
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ import {
|
|||
Dispatch,
|
||||
SetStateAction,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
|
||||
|
|
@ -62,6 +64,12 @@ function DragList<T extends { id?: string | null }>({
|
|||
}: DragListProps<T>) {
|
||||
const [activeId, setActiveId] = useState<string | null>(null);
|
||||
const sensors = useSensors(useSensor(MouseSensor), useSensor(TouchSensor));
|
||||
const dataRef = useRef(data);
|
||||
|
||||
// 保持 ref 与 data 同步
|
||||
useEffect(() => {
|
||||
dataRef.current = data;
|
||||
}, [data]);
|
||||
|
||||
const handleDragStart = useCallback((event: DragStartEvent) => {
|
||||
setActiveId(event.active.id as string);
|
||||
|
|
@ -71,14 +79,19 @@ function DragList<T extends { id?: string | null }>({
|
|||
(event: DragEndEvent) => {
|
||||
const { active, over } = event;
|
||||
if (active.id !== over?.id) {
|
||||
const oldIndex = data.findIndex(item => (item.id || '') === active.id);
|
||||
const newIndex = data.findIndex(item => (item.id || '') === over!.id);
|
||||
const newData = arrayMove(data, oldIndex, newIndex);
|
||||
const currentData = dataRef.current;
|
||||
const oldIndex = currentData.findIndex(
|
||||
item => (item.id || '') === active.id,
|
||||
);
|
||||
const newIndex = currentData.findIndex(
|
||||
item => (item.id || '') === over!.id,
|
||||
);
|
||||
const newData = arrayMove(currentData, oldIndex, newIndex);
|
||||
onChange(newData);
|
||||
}
|
||||
setActiveId(null);
|
||||
},
|
||||
[data, onChange],
|
||||
[onChange],
|
||||
);
|
||||
|
||||
const handleDragCancel = useCallback(() => {
|
||||
|
|
@ -87,20 +100,22 @@ function DragList<T extends { id?: string | null }>({
|
|||
|
||||
const handleRemove = useCallback(
|
||||
(id: string) => {
|
||||
const newData = data.filter(item => (item.id || '') !== id);
|
||||
const currentData = dataRef.current;
|
||||
const newData = currentData.filter(item => (item.id || '') !== id);
|
||||
onChange(newData);
|
||||
},
|
||||
[data, onChange],
|
||||
[onChange],
|
||||
);
|
||||
|
||||
const handleUpdateItem = useCallback(
|
||||
(updatedItem: T) => {
|
||||
const newData = data.map(item =>
|
||||
const currentData = dataRef.current;
|
||||
const newData = currentData.map(item =>
|
||||
(item.id || '') === (updatedItem.id || '') ? updatedItem : item,
|
||||
);
|
||||
onChange(newData);
|
||||
},
|
||||
[data, onChange],
|
||||
[onChange],
|
||||
);
|
||||
|
||||
if (data.length === 0) return null;
|
||||
|
|
|
|||