feat(tenant): 新空间开箱即用:自动初始化默认模型配置

- 新增 TenantBootstrapService:建空间后自动创建「新手入门」知识库
  (绑定内置默认对话/向量化模型)、预置欢迎文档(走标准上传管道)、
  配置租户级检索重排模型;整体 fail-open 且幂等,不阻断主流程
- 挂钩 Register(普通注册与 OIDC 首登自动开户均覆盖)与手动创建
  工作区接口,内置模型宿主租户(10000)跳过
- CreateKnowledgeBase / CreateAgent 空的必填模型字段自动落系统默认
  (is_default 优先,否则该类型第一个 active),API 直调路径同样兜底
- 自动化编辑器模型选择预填系统默认对话模型
This commit is contained in:
runny committed 2026-11-19 22:33:21 +08:00
1 parent 4b899a4647
commit 3a578153bb
11 files changed
+344 -13

No files matched your search

+20 -7
View File
@@ -98,14 +98,18 @@ func getJwtSecret() string {
// userService implements the UserService interface
type userService struct {
userRepo interfaces.UserRepository
tokenRepo interfaces.AuthTokenRepository
tenantService interfaces.TenantService
memberService interfaces.TenantMemberService
userRepo interfaces.UserRepository
tokenRepo interfaces.AuthTokenRepository
tenantService interfaces.TenantService
memberService interfaces.TenantMemberService
invitationService interfaces.TenantInvitationService
config *config.Config
systemSettingSvc interfaces.SystemSettingService
sandboxReleaser SandboxOwnerReleaser
config *config.Config
systemSettingSvc interfaces.SystemSettingService
sandboxReleaser SandboxOwnerReleaser
// bootstrap is optional (nil in unit tests): seeds out-of-the-box
// defaults (starter KB + tenant rerank) into freshly created personal
// workspaces. Fail-open by contract — see TenantBootstrapService.
bootstrap interfaces.TenantBootstrapService
}
// NewUserService creates a new user service instance
@@ -117,6 +121,7 @@ func NewUserService(
memberService interfaces.TenantMemberService,
invitationService interfaces.TenantInvitationService,
systemSettingSvc interfaces.SystemSettingService,
bootstrap interfaces.TenantBootstrapService,
) interfaces.UserService {
return &userService{
userRepo: userRepo,
@@ -126,6 +131,7 @@ func NewUserService(
invitationService: invitationService,
config: configInfo,
systemSettingSvc: systemSettingSvc,
bootstrap: bootstrap,
}
}
@@ -226,6 +232,13 @@ func (s *userService) Register(ctx context.Context, req *types.RegisterRequest)
}
logger.Info(ctx, "User registered successfully")
// 开箱即用:为新个人空间 seed 默认模型配置(入门知识库 + 欢迎文档 +
// 租户级重排模型)。整体 fail-open,任何失败不影响注册结果。
if createdTenant != nil && s.bootstrap != nil {
s.bootstrap.SeedTenantDefaults(ctx, createdTenant, user.ID)
}
return user, nil
}