feat(tenant): implement tenant creation limit and error handling

Added a new configuration option to limit the number of tenants a non-superuser can create via self-service. Introduced a new error type for handling cases where users exceed this limit, returning a 429 status code. Updated the tenant creation and update handlers to enforce this limit and provide appropriate feedback to users. Additionally, refactored the tenant update request structure to ensure only mutable fields are allowed.

Refs: #1303
This commit is contained in:
wizardchen
2026-05-16 10:37:25 +08:00
committed by lyingbug
parent 29dc99ae79
commit 7d030a6f6a
7 changed files with 497 additions and 698 deletions
-25
View File
@@ -17,29 +17,12 @@ export interface SystemInfo {
db_migration_error?: string
}
export interface ToolDefinition {
name: string
label: string
description: string
}
export interface PlaceholderDefinition {
name: string
label: string
description: string
}
export interface AgentConfig {
max_iterations: number
reflection_enabled: boolean
allowed_tools: string[]
temperature: number
knowledge_bases?: string[]
system_prompt?: string // Unified system prompt (uses {{web_search_status}} placeholder)
available_tools?: ToolDefinition[] // GET 响应中包含,POST/PUT 不需要
available_placeholders?: PlaceholderDefinition[] // GET 响应中包含,POST/PUT 不需要
}
export interface PromptTemplate {
id: string
name: string
@@ -71,14 +54,6 @@ export function getSystemInfo(): Promise<{ data: SystemInfo }> {
return get('/api/v1/system/info')
}
export function getAgentConfig(): Promise<{ data: AgentConfig }> {
return get('/api/v1/tenants/kv/agent-config')
}
export function updateAgentConfig(config: AgentConfig): Promise<{ data: AgentConfig }> {
return put('/api/v1/tenants/kv/agent-config', config)
}
export function getPromptTemplates(): Promise<{ data: PromptTemplatesConfig }> {
return get('/api/v1/tenants/kv/prompt-templates')
}
@@ -62,10 +62,17 @@ const form = reactive({
description: '',
})
// Trim-aware required check:t-input 的 required 不会去空白,全空格也算
// 通过;这里手动校验 trim 后非空,避免后端因 binding:"required,min=1"
// 才把请求挡下来。max 长度由 <t-input :maxlength="128"> 在键入时硬限制,
// 所以这里不再重复挂规则(避免与硬限制双重提示)。
const formRules: Record<string, FormRule[]> = {
name: [
{ required: true, message: t('tenant.create.nameRequired'), trigger: 'blur' },
{ max: 128, message: t('tenant.create.nameRequired'), trigger: 'blur' },
{
validator: (val: string) => (val ?? '').trim().length > 0,
message: t('tenant.create.nameRequired'),
trigger: 'blur',
},
],
}
File diff suppressed because it is too large Load Diff