feat: add new interfaces, services, and utilities for API integration

refactor: reorganize type definitions and improve type safety

build: add lodash and @types/lodash as dependencies

chore: update tsconfig and vite config for path aliases

style: improve code organization and add documentation comments

fix: correct type usage in LanguageSwitcher component

perf: implement snackbar provider for global notifications

test: add new test interfaces and utility functions

ci: update pnpm-lock.yaml with new dependencies
This commit is contained in:
2025-10-10 15:09:04 +08:00
parent 8cf7a4e5d5
commit a1282de74f
45 changed files with 5088 additions and 274 deletions

View File

@@ -0,0 +1,278 @@
export interface ICategorizeItem {
name: string;
description?: string;
examples?: { value: string }[];
index: number;
to: string[];
uuid: string;
}
export type ICategorizeItemResult = Record<
string,
Omit<ICategorizeItem, 'name' | 'examples' | 'uuid'> & { examples: string[] }
>;
export interface ISwitchCondition {
items: ISwitchItem[];
logical_operator: string;
to: string[];
}
export interface ISwitchItem {
cpn_id: string;
operator: string;
value: string;
}
export interface ISwitchForm {
conditions: ISwitchCondition[];
end_cpn_ids: string[];
no: string;
}
import { AgentCategory } from '@/constants/agent';
import { Edge, Node } from '@xyflow/react';
import { IReference, Message } from './chat';
export type DSLComponents = Record<string, IOperator>;
export interface DSL {
components: DSLComponents;
history: any[];
path?: string[];
answer?: any[];
graph?: IGraph;
messages?: Message[];
reference?: IReference[];
globals: Record<string, any>;
retrieval: IReference[];
}
export interface IOperator {
obj: IOperatorNode;
downstream: string[];
upstream: string[];
parent_id?: string;
}
export interface IOperatorNode {
component_name: string;
params: Record<string, unknown>;
}
export declare interface IFlow {
avatar?: string;
canvas_type: null;
create_date: string;
create_time: number;
description: null;
dsl: DSL;
id: string;
title: string;
update_date: string;
update_time: number;
user_id: string;
permission: string;
nickname: string;
operator_permission: number;
canvas_category: string;
}
export interface IFlowTemplate {
avatar: string;
canvas_type: string;
create_date: string;
create_time: number;
description: string;
dsl: DSL;
id: string;
title: string;
update_date: string;
update_time: number;
}
export interface IGenerateForm {
max_tokens?: number;
temperature?: number;
top_p?: number;
presence_penalty?: number;
frequency_penalty?: number;
cite?: boolean;
prompt: number;
llm_id: string;
parameters: { key: string; component_id: string };
}
export interface ICategorizeForm extends IGenerateForm {
category_description: ICategorizeItemResult;
items: ICategorizeItem[];
}
export interface IRelevantForm extends IGenerateForm {
yes: string;
no: string;
}
export interface ISwitchItem {
cpn_id: string;
operator: string;
value: string;
}
export interface ISwitchForm {
conditions: ISwitchCondition[];
end_cpn_id: string;
no: string;
}
export interface IBeginForm {
prologue?: string;
}
export interface IRetrievalForm {
similarity_threshold?: number;
keywords_similarity_weight?: number;
top_n?: number;
top_k?: number;
rerank_id?: string;
empty_response?: string;
kb_ids: string[];
}
export interface ICodeForm {
arguments: Record<string, string>;
lang: string;
script?: string;
outputs: Record<string, { value: string; type: string }>;
}
export interface IAgentForm {
sys_prompt: string;
prompts: Array<{
role: string;
content: string;
}>;
max_retries: number;
delay_after_error: number;
visual_files_var: string;
max_rounds: number;
exception_method: Nullable<'comment' | 'go'>;
exception_comment: any;
exception_goto: any;
tools: Array<{
name: string;
component_name: string;
params: Record<string, any>;
}>;
mcp: Array<{
mcp_id: string;
tools: Record<string, Record<string, any>>;
}>;
outputs: {
structured_output: Record<string, Record<string, any>>;
content: Record<string, any>;
};
}
export type BaseNodeData<TForm extends any> = {
label: string; // operator type
name: string; // operator name
color?: string;
form?: TForm;
};
export type BaseNode<T = any> = Node<BaseNodeData<T>>;
export type IBeginNode = BaseNode<IBeginForm>;
export type IRetrievalNode = BaseNode<IRetrievalForm>;
export type IGenerateNode = BaseNode<IGenerateForm>;
export type ICategorizeNode = BaseNode<ICategorizeForm>;
export type ISwitchNode = BaseNode<ISwitchForm>;
export type IRagNode = BaseNode;
export type IRelevantNode = BaseNode;
export type ILogicNode = BaseNode;
export type INoteNode = BaseNode;
export type IMessageNode = BaseNode;
export type IRewriteNode = BaseNode;
export type IInvokeNode = BaseNode;
export type ITemplateNode = BaseNode;
export type IEmailNode = BaseNode;
export type IIterationNode = BaseNode;
export type IIterationStartNode = BaseNode;
export type IKeywordNode = BaseNode;
export type ICodeNode = BaseNode<ICodeForm>;
export type IAgentNode = BaseNode;
export type IToolNode = BaseNode<IAgentForm>;
export type RAGFlowNodeType =
| IBeginNode
| IRetrievalNode
| IGenerateNode
| ICategorizeNode
| ISwitchNode
| IRagNode
| IRelevantNode
| ILogicNode
| INoteNode
| IMessageNode
| IRewriteNode
| IInvokeNode
| ITemplateNode
| IEmailNode
| IIterationNode
| IIterationStartNode
| IKeywordNode;
export interface IGraph {
nodes: RAGFlowNodeType[];
edges: Edge[];
}
export interface ITraceData {
component_id: string;
trace: Array<Record<string, any>>;
}
export interface IAgentLogResponse {
id: string;
message: IAgentLogMessage[];
update_date: string;
create_date: string;
update_time: number;
create_time: number;
round: number;
thumb_up: number;
errors: string;
source: string;
user_id: string;
dsl: string;
reference: IReference;
}
export interface IAgentLogsResponse {
total: number;
sessions: IAgentLogResponse[];
}
export interface IAgentLogsRequest {
keywords?: string;
to_date?: string | Date;
from_date?: string | Date;
orderby?: string;
desc?: boolean;
page?: number;
page_size?: number;
}
export interface IAgentLogMessage {
content: string;
role: 'user' | 'assistant';
id: string;
}
export interface IPipeLineListRequest {
page?: number;
page_size?: number;
keywords?: string;
orderby?: string;
desc?: boolean;
canvas_category?: AgentCategory;
}

View File

@@ -0,0 +1,17 @@
export interface ResponseType<T = any> {
code: number;
data: T;
message: string;
status: number;
}
export interface ResponseGetType<T = any> {
data: T;
loading?: boolean;
}
export interface ResponsePostType<T = any> {
data: T;
loading?: boolean;
[key: string]: unknown;
}

View File

@@ -0,0 +1,182 @@
import { MessageType } from '@/constants/chat';
export interface PromptConfig {
empty_response: string;
parameters: Parameter[];
prologue: string;
system: string;
tts?: boolean;
quote: boolean;
keyword: boolean;
refine_multiturn: boolean;
use_kg: boolean;
reasoning?: boolean;
cross_languages?: Array<string>;
}
export interface Parameter {
key: string;
optional: boolean;
}
export interface LlmSetting {
Creative: Variable;
Custom: Variable;
Evenly: Variable;
Precise: Variable;
}
export interface Variable {
frequency_penalty?: number;
max_tokens?: number;
presence_penalty?: number;
temperature?: number;
top_p?: number;
llm_id?: string;
}
export interface IDialog {
create_date: string;
create_time: number;
description: string;
icon: string;
id: string;
dialog_id: string;
kb_ids: string[];
kb_names: string[];
language: string;
llm_id: string;
llm_setting: Variable;
llm_setting_type: string;
name: string;
prompt_config: PromptConfig;
prompt_type: string;
status: string;
tenant_id: string;
update_date: string;
update_time: number;
vector_similarity_weight: number;
similarity_threshold: number;
top_k: number;
top_n: number;
meta_data_filter: MetaDataFilter;
}
interface MetaDataFilter {
manual: Manual[];
method: string;
}
interface Manual {
key: string;
op: string;
value: string;
}
export interface IConversation {
create_date: string;
create_time: number;
dialog_id: string;
id: string;
avatar: string;
message: Message[];
reference: IReference[];
name: string;
update_date: string;
update_time: number;
is_new: true;
}
export interface Message {
content: string;
role: MessageType;
doc_ids?: string[];
prompt?: string;
id?: string;
audio_binary?: string;
data?: any;
files?: File[];
chatBoxId?: string;
}
export interface IReferenceChunk {
id: string;
content: null;
document_id: string;
document_name: string;
dataset_id: string;
image_id: string;
similarity: number;
vector_similarity: number;
term_similarity: number;
positions: number[];
doc_type?: string;
}
export interface IReference {
chunks: IReferenceChunk[];
doc_aggs: Docagg[];
total: number;
}
export interface IReferenceObject {
chunks: Record<string, IReferenceChunk>;
doc_aggs: Record<string, Docagg>;
}
export interface IAnswer {
answer: string;
reference?: IReference;
conversationId?: string;
prompt?: string;
id?: string;
audio_binary?: string;
data?: any;
chatBoxId?: string;
}
export interface Docagg {
count: number;
doc_id: string;
doc_name: string;
url?: string;
}
// interface Chunk {
// chunk_id: string;
// content_ltks: string;
// content_with_weight: string;
// doc_id: string;
// docnm_kwd: string;
// img_id: string;
// important_kwd: any[];
// kb_id: string;
// similarity: number;
// term_similarity: number;
// vector_similarity: number;
// }
export interface IToken {
create_date: string;
create_time: number;
tenant_id: string;
token: string;
update_date?: any;
update_time?: any;
beta: string;
}
export interface IStats {
pv: [string, number][];
uv: [string, number][];
speed: [string, number][];
tokens: [string, number][];
round: [string, number][];
thumb_up: [string, number][];
}
export interface IExternalChatInfo {
avatar?: string;
title: string;
prologue?: string;
}

View File

@@ -0,0 +1,58 @@
import { RunningStatus } from '@/constants/knowledge';
export interface IDocumentInfo {
chunk_num: number;
create_date: string;
create_time: number;
created_by: string;
nickname: string;
id: string;
kb_id: string;
location: string;
name: string;
parser_config: IParserConfig;
parser_id: string;
pipeline_id: string;
pipeline_name: string;
process_begin_at?: string;
process_duration: number;
progress: number;
progress_msg: string;
run: RunningStatus;
size: number;
source_type: string;
status: string;
suffix: string;
thumbnail: string;
token_num: number;
type: string;
update_date: string;
update_time: number;
meta_fields?: Record<string, any>;
}
export interface IParserConfig {
delimiter?: string;
html4excel?: boolean;
layout_recognize?: boolean;
pages: any[];
raptor?: Raptor;
graphrag?: GraphRag;
}
interface Raptor {
use_raptor: boolean;
}
interface GraphRag {
community?: boolean;
entity_types?: string[];
method?: string;
resolution?: boolean;
use_graphrag?: boolean;
}
export type IDocumentInfoFilter = {
run_status: Record<number, number>;
suffix: Record<string, number>;
};

View File

@@ -0,0 +1,39 @@
export interface IFile {
create_date: string;
create_time: number;
created_by: string;
id: string;
kbs_info: { kb_id: string; kb_name: string }[];
location: string;
name: string;
parent_id: string;
size: number;
tenant_id: string;
type: string;
update_date: string;
update_time: number;
source_type: string;
has_child_folder?: boolean;
}
export interface IFolder {
create_date: string;
create_time: number;
created_by: string;
id: string;
location: string;
name: string;
parent_id: string;
size: number;
tenant_id: string;
type: string;
update_date: string;
update_time: number;
source_type: string;
}
export type IFetchFileListResult = {
files: IFile[];
parent_folder: IFolder;
total: number;
};

View File

@@ -0,0 +1,187 @@
import { Edge, Node } from '@xyflow/react';
import { IReference, Message } from './chat';
export type DSLComponents = Record<string, IOperator>;
export interface DSL {
components: DSLComponents;
history: any[];
path?: string[][];
answer?: any[];
graph?: IGraph;
messages: Message[];
reference: IReference[];
globals: Record<string, any>;
retrieval: IReference[];
}
export interface IOperator {
obj: IOperatorNode;
downstream: string[];
upstream: string[];
parent_id?: string;
}
export interface IOperatorNode {
component_name: string;
params: Record<string, unknown>;
}
export declare interface IFlow {
avatar?: string;
canvas_type: null;
create_date: string;
create_time: number;
description: string;
dsl: DSL;
id: string;
title: string;
update_date: string;
update_time: number;
user_id: string;
permission: string;
nickname: string;
}
export interface IFlowTemplate {
avatar: string;
canvas_type: string;
create_date: string;
create_time: number;
description: {
en: string;
zh: string;
};
dsl: DSL;
id: string;
title: {
en: string;
zh: string;
};
update_date: string;
update_time: number;
}
export type ICategorizeItemResult = Record<
string,
Omit<ICategorizeItem, 'name'>
>;
export interface IGenerateForm {
max_tokens?: number;
temperature?: number;
top_p?: number;
presence_penalty?: number;
frequency_penalty?: number;
cite?: boolean;
prompt: number;
llm_id: string;
parameters: { key: string; component_id: string };
}
export interface ICategorizeItem {
name: string;
description?: string;
examples?: string;
to?: string;
index: number;
}
export interface ICategorizeForm extends IGenerateForm {
category_description: ICategorizeItemResult;
}
export interface IRelevantForm extends IGenerateForm {
yes: string;
no: string;
}
export interface ISwitchCondition {
items: ISwitchItem[];
logical_operator: string;
to: string[] | string;
}
export interface ISwitchItem {
cpn_id: string;
operator: string;
value: string;
}
export interface ISwitchForm {
conditions: ISwitchCondition[];
end_cpn_id: string;
no: string;
}
export interface IBeginForm {
prologue?: string;
}
export interface IRetrievalForm {
similarity_threshold?: number;
keywords_similarity_weight?: number;
top_n?: number;
top_k?: number;
rerank_id?: string;
empty_response?: string;
kb_ids: string[];
}
export interface ICodeForm {
inputs?: Array<{ name?: string; component_id?: string }>;
lang: string;
script?: string;
}
export type BaseNodeData<TForm extends any> = {
label: string; // operator type
name: string; // operator name
color?: string;
form?: TForm;
};
export type BaseNode<T = any> = Node<BaseNodeData<T>>;
export type IBeginNode = BaseNode<IBeginForm>;
export type IRetrievalNode = BaseNode<IRetrievalForm>;
export type IGenerateNode = BaseNode<IGenerateForm>;
export type ICategorizeNode = BaseNode<ICategorizeForm>;
export type ISwitchNode = BaseNode<ISwitchForm>;
export type IRagNode = BaseNode;
export type IRelevantNode = BaseNode;
export type ILogicNode = BaseNode;
export type INoteNode = BaseNode;
export type IMessageNode = BaseNode;
export type IRewriteNode = BaseNode;
export type IInvokeNode = BaseNode;
export type ITemplateNode = BaseNode;
export type IEmailNode = BaseNode;
export type IIterationNode = BaseNode;
export type IIterationStartNode = BaseNode;
export type IKeywordNode = BaseNode;
export type ICodeNode = BaseNode<ICodeForm>;
export type IAgentNode = BaseNode;
export type RAGFlowNodeType =
| IBeginNode
| IRetrievalNode
| IGenerateNode
| ICategorizeNode
| ISwitchNode
| IRagNode
| IRelevantNode
| ILogicNode
| INoteNode
| IMessageNode
| IRewriteNode
| IInvokeNode
| ITemplateNode
| IEmailNode
| IIterationNode
| IIterationStartNode
| IKeywordNode;
export interface IGraph {
nodes: RAGFlowNodeType[];
edges: Edge[];
}

View File

@@ -0,0 +1,168 @@
import { RunningStatus } from '@/constants/knowledge';
import { TreeData } from '@antv/g6/lib/types';
// knowledge base
export interface IKnowledge {
avatar?: any;
chunk_num: number;
create_date: string;
create_time: number;
created_by: string;
description: string;
doc_num: number;
id: string;
name: string;
parser_config: ParserConfig;
parser_id: string;
pipeline_id: string;
pipeline_name: string;
pipeline_avatar: string;
permission: string;
similarity_threshold: number;
status: string;
tenant_id: string;
token_num: number;
update_date: string;
update_time: number;
vector_similarity_weight: number;
embd_id: string;
nickname: string;
operator_permission: number;
size: number;
raptor_task_finish_at?: string;
raptor_task_id?: string;
mindmap_task_finish_at?: string;
mindmap_task_id?: string;
}
export interface IKnowledgeResult {
kbs: IKnowledge[];
total: number;
}
export interface Raptor {
use_raptor: boolean;
}
export interface ParserConfig {
from_page?: number;
to_page?: number;
auto_keywords?: number;
auto_questions?: number;
chunk_token_num?: number;
delimiter?: string;
html4excel?: boolean;
layout_recognize?: boolean;
raptor?: Raptor;
tag_kb_ids?: string[];
topn_tags?: number;
graphrag?: { use_graphrag?: boolean };
}
export interface IKnowledgeFileParserConfig {
chunk_token_num: number;
layout_recognize: boolean;
pages: number[][];
task_page_size: number;
}
export interface IKnowledgeFile {
chunk_num: number;
create_date: string;
create_time: number;
created_by: string;
id: string;
kb_id: string;
location: string;
name: string;
parser_id: string;
process_begin_at?: any;
process_duration: number;
progress: number; // parsing process
progress_msg: string; // parsing log
run: RunningStatus; // parsing status
size: number;
source_type: string;
status: string; // enabled
thumbnail?: any; // base64
token_num: number;
type: string;
update_date: string;
update_time: number;
parser_config: IKnowledgeFileParserConfig;
}
export interface ITenantInfo {
asr_id: string;
embd_id: string;
img2txt_id: string;
llm_id: string;
name: string;
parser_ids: string;
role: string;
tenant_id: string;
chat_id: string;
speech2text_id: string;
tts_id: string;
}
export interface IChunk {
available_int: number; // Whether to enable, 0: not enabled, 1: enabled
chunk_id: string;
content_with_weight: string;
doc_id: string;
doc_name: string;
image_id: string;
important_kwd?: string[];
question_kwd?: string[]; // keywords
tag_kwd?: string[];
positions: number[][];
tag_feas?: Record<string, number>;
}
export interface ITestingChunk {
chunk_id: string;
content_ltks: string;
content_with_weight: string;
doc_id: string;
doc_name: string;
img_id: string;
image_id: string;
important_kwd: any[];
kb_id: string;
similarity: number;
term_similarity: number;
vector: number[];
vector_similarity: number;
highlight: string;
positions: number[][];
docnm_kwd: string;
doc_type_kwd: string;
}
export interface ITestingDocument {
count: number;
doc_id: string;
doc_name: string;
}
export interface ITestingResult {
chunks: ITestingChunk[];
documents: ITestingDocument[];
total: number;
labels?: Record<string, number>;
}
export interface INextTestingResult {
chunks: ITestingChunk[];
doc_aggs: ITestingDocument[];
total: number;
labels?: Record<string, number>;
isRuned?: boolean;
}
export type IRenameTag = { fromTag: string; toTag: string };
export interface IKnowledgeGraph {
graph: Record<string, any>;
mind_map: TreeData;
}

View File

@@ -0,0 +1,41 @@
export interface IThirdOAIModel {
available: boolean;
create_date: string;
create_time: number;
fid: string;
id: number;
llm_name: string;
max_tokens: number;
model_type: string;
status: string;
tags: string;
update_date: string;
update_time: number;
tenant_id?: string;
tenant_name?: string;
is_tools: boolean;
}
export type IThirdOAIModelCollection = Record<string, IThirdOAIModel[]>;
export interface IFactory {
create_date: string;
create_time: number;
logo: string;
name: string;
status: string;
tags: string;
update_date: string;
update_time: number;
}
export interface IMyLlmValue {
llm: Llm[];
tags: string;
}
export interface Llm {
name: string;
type: string;
used_token: number;
}

View File

@@ -0,0 +1,19 @@
export enum McpServerType {
Sse = 'sse',
StreamableHttp = 'streamable-http',
}
export interface IMcpServerVariable {
key: string;
name: string;
}
export interface IMcpServerInfo {
id: string;
name: string;
url: string;
server_type: McpServerType;
description?: string;
variables?: IMcpServerVariable[];
headers: Map<string, string>;
}

View File

@@ -0,0 +1,60 @@
export interface IMcpServer {
create_date: string;
description: null;
id: string;
name: string;
server_type: string;
update_date: string;
url: string;
variables: Record<string, any> & { tools?: IMCPToolObject };
}
export type IMCPToolObject = Record<string, Omit<IMCPTool, 'name'>>;
export type IMCPToolRecord = Record<string, IMCPTool>;
export interface IMcpServerListResponse {
mcp_servers: IMcpServer[];
total: number;
}
export interface IMCPTool {
annotations: null;
description: string;
enabled: boolean;
inputSchema: InputSchema;
name: string;
}
interface InputSchema {
properties: Properties;
required: string[];
title: string;
type: string;
}
interface Properties {
symbol: ISymbol;
}
interface ISymbol {
title: string;
type: string;
}
export interface IExportedMcpServers {
mcpServers: McpServers;
}
interface McpServers {
fetch_2: IExportedMcpServer;
github_1: IExportedMcpServer;
}
export interface IExportedMcpServer {
authorization_token: string;
name: string;
tool_configuration: Record<string, any>;
type: string;
url: string;
}

View File

@@ -0,0 +1,13 @@
export type ILLMTools = ILLMToolMetadata[];
export interface ILLMToolMetadata {
name: string;
displayName: string;
displayDescription: string;
parameters: Map<string, ILLMToolParameter>;
}
export interface ILLMToolParameter {
type: string;
displayDescription: string;
}

View File

@@ -0,0 +1,7 @@
export interface ILangfuseConfig {
secret_key: string;
public_key: string;
host: string;
project_id: string;
project_name: string;
}

View File

@@ -0,0 +1,96 @@
export interface IUserInfo {
access_token: string;
avatar?: any;
color_schema: string;
create_date: string;
create_time: number;
email: string;
id: string;
is_active: string;
is_anonymous: string;
is_authenticated: string;
is_superuser: boolean;
language: string;
last_login_time: string;
login_channel: string;
nickname: string;
password: string;
status: string;
timezone: string;
update_date: string;
update_time: number;
}
export type TaskExecutorElapsed = Record<string, number[]>;
export interface TaskExecutorHeartbeatItem {
boot_at: string;
current: null;
done: number;
failed: number;
lag: number;
name: string;
now: string;
pending: number;
}
export interface ISystemStatus {
es: Es;
storage: Storage;
database: Database;
redis: Redis;
task_executor_heartbeat: Record<string, TaskExecutorHeartbeatItem[]>;
}
interface Redis {
status: string;
elapsed: number;
error: string;
pending: number;
}
export interface Storage {
status: string;
elapsed: number;
error: string;
}
export interface Database {
status: string;
elapsed: number;
error: string;
}
interface Es {
status: string;
elapsed: number;
error: string;
number_of_nodes: number;
active_shards: number;
}
export interface ITenantUser {
id: string;
avatar: string;
delta_seconds: number;
email: string;
is_active: string;
is_anonymous: string;
is_authenticated: string;
is_superuser: boolean;
nickname: string;
role: string;
status: string;
update_date: string;
user_id: string;
}
export interface ITenant {
avatar: string;
delta_seconds: number;
email: string;
nickname: string;
role: string;
tenant_id: string;
update_date: string;
}