feat(admin): LLM config, knowledge base, and WeCom AI binding
CI / verify (pull_request) Has been cancelled

Add owner-scoped model API settings, uploadable knowledge bases, and WeCom bot AI/KB wiring with OpenAI-compatible URL normalization.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-26 09:31:22 +08:00
parent 745c192693
commit 2b7ef65cce
30 changed files with 2507 additions and 56 deletions
@@ -15,6 +15,8 @@ export const HQ_PERMISSION_CATALOG = [
{ key: 'tech_support', label: '技术支持', group: '业务' },
{ key: 'invoices', label: '发票管理', group: '业务' },
{ key: 'wecom_bots', label: '企微机器人', group: '业务' },
{ key: 'llm_configs', label: '语言模型配置', group: '业务' },
{ key: 'knowledge_bases', label: '知识库', group: '业务' },
{ key: 'resources', label: 'OSS 资源库', group: '业务' },
{ key: 'logs', label: '日志', group: '业务' },
{ key: 'hq_permissions', label: '权限分配', group: '管理' },
@@ -90,6 +92,8 @@ export const HQ_ROLE_DEFAULT_PERMISSIONS: Record<string, HqPermissionKey[]> = {
'tech_support',
'invoices',
'wecom_bots',
'llm_configs',
'knowledge_bases',
'resources',
'logs',
'system_settings_wechat_mini',
+2
View File
@@ -24,4 +24,6 @@ export * from './city-warehouse';
export * from './fulfillment-provider';
export * from './system-config';
export * from './wecom-bot';
export * from './llm-config';
export * from './knowledge-base';
export * from './legal';
@@ -0,0 +1,58 @@
export type KnowledgeBaseDto = {
id: string;
name: string;
description: string | null;
enabled: boolean;
documentCount: number;
createdByHqAccountId: string;
createdByName: string | null;
isOwner: boolean;
canEditFull: boolean;
createdAt: string;
updatedAt: string;
};
export type CreateKnowledgeBaseRequest = {
name: string;
description?: string | null;
enabled?: boolean;
};
export type UpdateKnowledgeBaseRequest = {
name?: string;
description?: string | null;
enabled?: boolean;
};
export type KnowledgeDocumentDto = {
id: string;
knowledgeBaseId: string;
title: string;
fileName: string | null;
fileUrl: string | null;
mimeType: string | null;
sizeBytes: number | null;
/** 是否已抽取可检索正文 */
hasContent: boolean;
status: 'READY' | 'EMPTY' | 'FAILED';
errorMessage: string | null;
createdAt: string;
updatedAt: string;
};
export type CreateKnowledgeDocumentRequest = {
title: string;
/** 直贴正文(优先) */
contentText?: string | null;
fileName?: string | null;
fileUrl?: string | null;
mimeType?: string | null;
sizeBytes?: number | null;
};
export type KnowledgeBaseOptionDto = {
id: string;
name: string;
enabled: boolean;
documentCount: number;
};
+93
View File
@@ -0,0 +1,93 @@
/** 语言模型 API 提供商(OpenAI 兼容 Chat Completions */
export const LLM_PROVIDERS = [
'DEEPSEEK',
'OPENAI',
'QWEN',
'CUSTOM',
] as const;
export type LlmProvider = (typeof LLM_PROVIDERS)[number];
export const LLM_PROVIDER_LABELS: Record<LlmProvider, string> = {
DEEPSEEK: 'DeepSeek',
OPENAI: 'OpenAI',
QWEN: '通义千问',
CUSTOM: '自定义(OpenAI 兼容)',
};
export const LLM_PROVIDER_PRESETS: Record<
LlmProvider,
{ defaultBaseUrl: string; defaultModel: string }
> = {
DEEPSEEK: {
defaultBaseUrl: 'https://api.deepseek.com',
defaultModel: 'deepseek-chat',
},
OPENAI: {
defaultBaseUrl: 'https://api.openai.com',
defaultModel: 'gpt-4o-mini',
},
QWEN: {
defaultBaseUrl: 'https://dashscope.aliyuncs.com/compatible-mode',
defaultModel: 'qwen-plus',
},
CUSTOM: {
defaultBaseUrl: '',
defaultModel: '',
},
};
export type LlmApiConfigDto = {
id: string;
name: string;
provider: LlmProvider;
baseUrl: string;
modelName: string;
/** 列表/详情不回明文 */
apiKeyConfigured: boolean;
temperature: number | null;
maxTokens: number | null;
systemPrompt: string | null;
enabled: boolean;
createdByHqAccountId: string;
createdByName: string | null;
/** 当前登录账号是否为创建人 */
isOwner: boolean;
/** 非超管仅可改 enabled;超管可改全部 */
canEditFull: boolean;
createdAt: string;
updatedAt: string;
};
export type CreateLlmApiConfigRequest = {
name: string;
provider: LlmProvider;
baseUrl?: string;
apiKey: string;
modelName?: string;
temperature?: number | null;
maxTokens?: number | null;
systemPrompt?: string | null;
enabled?: boolean;
};
export type UpdateLlmApiConfigRequest = {
/** 非超管仅允许传 enabled */
name?: string;
provider?: LlmProvider;
baseUrl?: string;
apiKey?: string;
modelName?: string;
temperature?: number | null;
maxTokens?: number | null;
systemPrompt?: string | null;
enabled?: boolean;
};
export type LlmApiConfigOptionDto = {
id: string;
name: string;
provider: LlmProvider;
modelName: string;
enabled: boolean;
};
+12
View File
@@ -75,6 +75,12 @@ export type WecomBotDto = {
avatarUrl: string | null;
welcome: string | null;
permissions: WecomBotPermission[];
/** 未匹配指令时是否调用绑定的语言模型 */
aiEnabled: boolean;
llmConfigId: string | null;
llmConfigName: string | null;
knowledgeBaseId: string | null;
knowledgeBaseName: string | null;
enabled: boolean;
sortOrder: number;
createdAt: string;
@@ -89,6 +95,9 @@ export type CreateWecomBotRequest = {
avatarUrl?: string | null;
welcome?: string | null;
permissions?: WecomBotPermission[];
aiEnabled?: boolean;
llmConfigId?: string | null;
knowledgeBaseId?: string | null;
enabled?: boolean;
sortOrder?: number;
};
@@ -102,6 +111,9 @@ export type UpdateWecomBotRequest = {
avatarUrl?: string | null;
welcome?: string | null;
permissions?: WecomBotPermission[];
aiEnabled?: boolean;
llmConfigId?: string | null;
knowledgeBaseId?: string | null;
enabled?: boolean;
sortOrder?: number;
};