Merge branch 'main' into storage-allow-list

This commit is contained in:
Windfarer
2026-04-29 19:35:13 +08:00
365 changed files with 46687 additions and 4594 deletions
+62 -1
View File
@@ -1,10 +1,21 @@
import { get, post, put, del } from "../../utils/request";
// 智能体配置
// 智能推理下的智能体类型预设 ID
// 'rag-qa' : 经典文档/FAQ 分块 RAG
// 'wiki-qa' : Wiki 图谱导航问答
// 'hybrid-rag-wiki': Wiki + 分块混合检索
// 'custom' : 完全自定义(不应用预设)
export type AgentType = 'rag-qa' | 'wiki-qa' | 'hybrid-rag-wiki' | 'data-analysis' | 'custom';
export interface CustomAgentConfig {
// ===== 基础设置 =====
agent_mode?: 'quick-answer' | 'smart-reasoning'; // 运行模式:quick-answer=RAG模式, smart-reasoning=ReAct Agent模式
// 智能推理模式下的类型预设,用于一键应用"系统提示词 + 工具 + KB 兼容性"组合
// 仅在 agent_mode === 'smart-reasoning' 时生效;quick-answer 模式忽略
agent_type?: AgentType;
system_prompt?: string; // 统一系统提示词(使用 {{web_search_status}} 占位符动态控制行为)
system_prompt_id?: string; // 引用的 prompt template ID(预设会填入此字段)
context_template?: string; // 上下文模板(普通模式)
// ===== 模型设置 =====
@@ -12,9 +23,11 @@ export interface CustomAgentConfig {
rerank_model_id?: string; // ReRank 模型 ID
temperature?: number;
max_completion_tokens?: number; // 最大生成token数(普通模式)
thinking?: boolean; // 是否启用思考模式(支持扩展思考的模型)
// ===== Agent模式设置 =====
max_iterations?: number; // 最大迭代次数
llm_call_timeout?: number; // LLM调用超时时间(秒)
allowed_tools?: string[]; // 允许的工具
reflection_enabled?: boolean; // 是否启用反思
// MCP服务选择模式:all=全部启用的MCP服务, selected=指定服务, none=不使用MCP
@@ -179,6 +192,54 @@ export function getPlaceholders() {
return get<{ data: PlaceholdersResponse }>('/api/v1/agents/placeholders');
}
// ===== 智能体类型预设 =====
// 后端 kb_filter 结构(见 internal/types/agent_type_preset.go)
export interface AgentTypeKBFilter {
any_of?: string[]; // KB 至少拥有其一
all_of?: string[]; // KB 必须全部拥有
none_of?: string[]; // KB 必须全部不拥有
}
// KB 能力标签(后端 types.KBCapabilities 的 JSON)
export interface KBCapabilities {
vector: boolean;
keyword: boolean;
wiki: boolean;
graph: boolean;
faq: boolean;
}
// 预设的"自动填充"配置载荷:仅包含被预设覆盖的字段;其他字段不动
export interface AgentTypePresetConfig {
system_prompt_id?: string;
temperature?: number;
max_iterations?: number;
allowed_tools?: string[];
retain_retrieval_history?: boolean;
faq_priority_enabled?: boolean;
web_search_enabled?: boolean;
supported_file_types?: string[];
kb_selection_mode?: 'all' | 'selected' | 'none';
}
export interface AgentTypePresetI18n {
label: string;
description: string;
}
export interface AgentTypePreset {
id: AgentType;
i18n: Record<string, AgentTypePresetI18n>;
config?: AgentTypePresetConfig; // 为空表示"自定义"类型(无预设)
kb_filter?: AgentTypeKBFilter; // 为空表示所有 KB 可选
}
// 拉取类型预设列表(编辑器用)
export function getAgentTypePresets() {
return get<{ data: AgentTypePreset[] }>('/api/v1/agents/type-presets');
}
// ===== IM渠道 =====
export interface IMChannel {
@@ -222,7 +283,7 @@ export function toggleIMChannel(id: string) {
// 推荐问题
export interface SuggestedQuestion {
question: string;
source: 'faq' | 'document' | 'agent_config';
source: 'faq' | 'document' | 'agent_config' | 'wiki';
knowledge_base_id?: string;
}
+15 -4
View File
@@ -250,13 +250,22 @@ export function getCurrentConfigByKB(kbId: string): Promise<InitializationConfig
});
}
// 所有"测试连接"接口共用的通用可选参数。
// customHeaders / extraConfig / interfaceType 对应后端 ModelTestRequest 里的同名字段,
// 会被透传给真正的模型装配流程,保证测试连接与生产调用走完全相同的路径。
interface BaseModelTestPayload {
customHeaders?: Record<string, string>;
extraConfig?: Record<string, string>;
interfaceType?: string;
}
// 检查远程API模型
export function checkRemoteModel(modelConfig: {
modelName: string;
baseUrl: string;
apiKey?: string;
provider?: string;
}): Promise<{
} & BaseModelTestPayload): Promise<{
available: boolean;
message?: string;
}> {
@@ -280,7 +289,7 @@ export function testEmbeddingModel(modelConfig: {
apiKey?: string;
dimension?: number;
provider?: string;
}): Promise<{ available: boolean; message?: string; dimension?: number }> {
} & BaseModelTestPayload): Promise<{ available: boolean; message?: string; dimension?: number }> {
return new Promise((resolve, reject) => {
post('/api/v1/initialization/embedding/test', modelConfig)
.then((response: any) => {
@@ -298,7 +307,8 @@ export function checkRerankModel(modelConfig: {
modelName: string;
baseUrl: string;
apiKey?: string;
}): Promise<{
provider?: string;
} & BaseModelTestPayload): Promise<{
available: boolean;
message?: string;
}> {
@@ -319,7 +329,8 @@ export function checkASRModel(modelConfig: {
modelName: string;
baseUrl: string;
apiKey?: string;
}): Promise<{
provider?: string;
} & BaseModelTestPayload): Promise<{
available: boolean;
message?: string;
}> {
+43 -4
View File
@@ -8,9 +8,9 @@ export function listKnowledgeBases(params?: { agent_id?: string }) {
return get(qs ? `/api/v1/knowledge-bases?${qs}` : '/api/v1/knowledge-bases');
}
export function createKnowledgeBase(data: {
name: string;
description?: string;
export function createKnowledgeBase(data: {
name: string;
description?: string;
type?: 'document' | 'faq';
chunking_config?: any;
embedding_model_id?: string;
@@ -28,6 +28,17 @@ export function createKnowledgeBase(data: {
};
extract_config?: any;
faq_config?: { index_mode: string; question_index_mode?: string };
wiki_config?: {
synthesis_model_id?: string;
max_pages_per_ingest?: number;
extraction_granularity?: 'focused' | 'standard' | 'exhaustive';
};
indexing_strategy?: {
vector_enabled: boolean;
keyword_enabled: boolean;
wiki_enabled: boolean;
graph_enabled: boolean;
};
}) {
return post(`/api/v1/knowledge-bases`, data);
}
@@ -39,10 +50,33 @@ export function getKnowledgeBaseById(id: string, options?: { agent_id?: string }
return get(qs ? `/api/v1/knowledge-bases/${id}?${qs}` : `/api/v1/knowledge-bases/${id}`);
}
export function updateKnowledgeBase(id: string, data: { name: string; description?: string; config: any }) {
export function updateKnowledgeBase(id: string, data: {
name: string;
description?: string;
config?: {
chunking_config?: any;
image_processing_config?: any;
faq_config?: any;
wiki_config?: {
synthesis_model_id?: string;
max_pages_per_ingest?: number;
extraction_granularity?: 'focused' | 'standard' | 'exhaustive';
};
indexing_strategy?: {
vector_enabled: boolean;
keyword_enabled: boolean;
wiki_enabled: boolean;
graph_enabled: boolean;
};
}
}) {
return put(`/api/v1/knowledge-bases/${id}` , data);
}
export function rebuildKBIndex(kbId: string) {
return post(`/api/v1/knowledge-bases/${kbId}/rebuild-index`, {});
}
export function deleteKnowledgeBase(id: string) {
return del(`/api/v1/knowledge-bases/${id}`);
}
@@ -136,6 +170,11 @@ export function delKnowledgeDetails(id: string) {
return del(`/api/v1/knowledge/${id}`);
}
// 批量删除(同一知识库内)。后端会校验所有 id 隶属于 kb_id 且具有编辑权限。
export function batchDeleteKnowledge(kbId: string, ids: string[]) {
return post(`/api/v1/knowledge/batch-delete`, { kb_id: kbId, ids });
}
export function downKnowledgeDetails(id: string) {
return getDown(`/api/v1/knowledge/${id}/download`);
}
+3
View File
@@ -22,6 +22,9 @@ export interface ModelConfig {
interface_type?: 'ollama' | 'openai'; // VLLM专用
parameter_size?: string; // Ollama模型参数大小 (e.g., "7B", "13B", "70B")
extra_config?: Record<string, string>; // Provider-specific configuration
// 自定义 HTTP 请求头(类似 Python OpenAI SDK 的 extra_headers),
// 会在调用远程模型 API 时附加到每个请求上。Authorization、Content-Type 等保留头会被忽略。
custom_headers?: Record<string, string>;
supports_vision?: boolean; // Whether the model accepts image/multimodal input
};
is_default?: boolean;
-14
View File
@@ -109,20 +109,6 @@ export function getPromptTemplates(): Promise<{ data: PromptTemplatesConfig }> {
return get('/api/v1/tenants/kv/prompt-templates')
}
export interface MinioBucketInfo {
name: string
policy: 'public' | 'private' | 'custom'
created_at?: string
}
export interface ListMinioBucketsResponse {
buckets: MinioBucketInfo[]
}
export function listMinioBuckets(): Promise<{ data: ListMinioBucketsResponse }> {
return get('/api/v1/system/minio/buckets')
}
export interface ParserEngineInfo {
Name: string
Description: string
+64
View File
@@ -0,0 +1,64 @@
import { get, post, put, del } from '@/utils/request'
// ===== Types =====
export interface VectorStoreEntity {
id?: string
name: string
engine_type: string
connection_config: Record<string, any>
index_config: Record<string, any>
source: 'env' | 'user'
readonly: boolean
tenant_id?: number
created_at?: string
updated_at?: string
}
export interface VectorStoreTypeInfo {
type: string
display_name: string
connection_fields: FieldSchema[]
index_fields: FieldSchema[]
}
export interface FieldSchema {
name: string
type: 'string' | 'number' | 'boolean'
required: boolean
sensitive?: boolean
description?: string
default?: any
}
// ===== API Functions =====
export function listVectorStoreTypes(): Promise<VectorStoreTypeInfo[]> {
return get('/api/v1/vector-stores/types').then((res: any) => {
return res.success && res.data ? res.data : []
})
}
export function listVectorStores(): Promise<{ success: boolean; data: VectorStoreEntity[] }> {
return get('/api/v1/vector-stores')
}
export function createVectorStore(data: Partial<VectorStoreEntity>) {
return post('/api/v1/vector-stores', data)
}
export function updateVectorStore(id: string, data: Partial<VectorStoreEntity>) {
return put(`/api/v1/vector-stores/${id}`, data)
}
export function deleteVectorStore(id: string) {
return del(`/api/v1/vector-stores/${id}`)
}
export function testVectorStoreRaw(data: { engine_type: string; connection_config: any }): Promise<any> {
return post('/api/v1/vector-stores/test', data)
}
export function testVectorStoreById(id: string): Promise<any> {
return post(`/api/v1/vector-stores/${id}/test`, {})
}
+2
View File
@@ -10,6 +10,7 @@ export interface WebSearchProviderEntity {
parameters: {
api_key?: string
engine_id?: string
proxy_url?: string
extra_config?: Record<string, string>
}
is_default?: boolean
@@ -23,6 +24,7 @@ export interface WebSearchProviderTypeInfo {
name: string
requires_api_key: boolean
requires_engine_id?: boolean
supports_proxy?: boolean
description?: string
docs_url?: string
}
+143
View File
@@ -0,0 +1,143 @@
import { get, post, put, del } from "../../utils/request";
// encodeSlugPath encodes each segment of a hierarchical wiki slug (e.g.
// "foo/bar baz?") so the URL is safe while preserving the "/" separators
// between segments. Using encodeURIComponent on the whole slug would also
// escape the "/" and break hierarchical routing on the backend.
function encodeSlugPath(slug: string): string {
return slug.split("/").map(encodeURIComponent).join("/");
}
// Wiki Page Types
export interface WikiPage {
id: string;
tenant_id: number;
knowledge_base_id: string;
slug: string;
title: string;
page_type: string;
status: string;
content: string;
summary: string;
aliases: string[];
source_refs: string[];
in_links: string[];
out_links: string[];
page_metadata: Record<string, any>;
version: number;
created_at: string;
updated_at: string;
}
export interface WikiPageListResponse {
pages: WikiPage[];
total: number;
page: number;
page_size: number;
total_pages: number;
}
export interface WikiGraphData {
nodes: { slug: string; title: string; page_type: string; link_count: number }[];
edges: { source: string; target: string }[];
}
export interface WikiStats {
total_pages: number;
pages_by_type: Record<string, number>;
total_links: number;
orphan_count: number;
recent_updates: WikiPage[];
pending_tasks: number;
pending_issues: number;
is_active: boolean;
}
export interface WikiPageIssue {
id: string;
tenant_id: number;
knowledge_base_id: string;
slug: string;
issue_type: string;
description: string;
suspected_knowledge_ids: string[];
status: string;
reported_by: string;
created_at: string;
updated_at: string;
}
// Wiki API Functions
export function listWikiPages(kbId: string, params?: {
page_type?: string;
status?: string;
query?: string;
page?: number;
page_size?: number;
sort_by?: string;
sort_order?: string;
}) {
const query = new URLSearchParams();
if (params) {
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined && value !== '') {
query.set(key, String(value));
}
});
}
const qs = query.toString();
return get(`/api/v1/knowledgebase/${kbId}/wiki/pages${qs ? '?' + qs : ''}`);
}
export function createWikiPage(kbId: string, data: Partial<WikiPage>) {
return post(`/api/v1/knowledgebase/${kbId}/wiki/pages`, data);
}
export function getWikiPage(kbId: string, slug: string) {
return get(`/api/v1/knowledgebase/${kbId}/wiki/pages/${encodeSlugPath(slug)}`);
}
export function updateWikiPage(kbId: string, slug: string, data: Partial<WikiPage>) {
return put(`/api/v1/knowledgebase/${kbId}/wiki/pages/${encodeSlugPath(slug)}`, data);
}
export function deleteWikiPage(kbId: string, slug: string) {
return del(`/api/v1/knowledgebase/${kbId}/wiki/pages/${encodeSlugPath(slug)}`);
}
export function getWikiIndex(kbId: string) {
return get(`/api/v1/knowledgebase/${kbId}/wiki/index`);
}
export function getWikiLog(kbId: string) {
return get(`/api/v1/knowledgebase/${kbId}/wiki/log`);
}
export function getWikiGraph(kbId: string) {
return get(`/api/v1/knowledgebase/${kbId}/wiki/graph`);
}
export function getWikiStats(kbId: string) {
return get(`/api/v1/knowledgebase/${kbId}/wiki/stats`);
}
export function searchWikiPages(kbId: string, q: string, limit?: number) {
const params = new URLSearchParams({ q });
if (limit) params.set('limit', String(limit));
return get(`/api/v1/knowledgebase/${kbId}/wiki/search?${params.toString()}`);
}
export function listWikiIssues(kbId: string, slug?: string, status?: string) {
const params = new URLSearchParams();
if (slug) params.set('slug', slug);
if (status) params.set('status', status);
return get(`/api/v1/knowledgebase/${kbId}/wiki/issues?${params.toString()}`);
}
export function updateWikiIssueStatus(kbId: string, issueId: string, status: string) {
return put(`/api/v1/knowledgebase/${kbId}/wiki/issues/${issueId}/status`, { status });
}
export function rebuildWikiLinks(kbId: string) {
return post(`/api/v1/knowledgebase/${kbId}/wiki/rebuild-links`, {});
}