From 0dc0f1fda7b37b9f74f87b3125e9966abd20a4c5 Mon Sep 17 00:00:00 2001 From: "lambert.li" Date: Tue, 5 Aug 2025 14:08:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0app=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/types/app.ts | 226 +++++++++++++++++++++++++++++++++++++++++++++ src/types/base.ts | 5 + src/types/log.ts | 16 ++++ src/types/tools.ts | 108 ++++++++++++++++++++++ 4 files changed, 355 insertions(+) create mode 100644 src/types/app.ts create mode 100644 src/types/base.ts create mode 100644 src/types/log.ts create mode 100644 src/types/tools.ts diff --git a/src/types/app.ts b/src/types/app.ts new file mode 100644 index 0000000..58a1641 --- /dev/null +++ b/src/types/app.ts @@ -0,0 +1,226 @@ +import type { Annotation } from './log' +import type { Locale } from '@/i18n' +import type { ThoughtItem } from '@/app/components/chat/type' + +export type PromptVariable = { + key: string + name: string + type: string + default?: string | number + options?: string[] + max_length?: number + required: boolean + allowed_file_extensions?: string[] + allowed_file_types?: string[] + allowed_file_upload_methods?: TransferMethod[] +} + +export type PromptConfig = { + prompt_template: string + prompt_variables: PromptVariable[] +} + +export type TextTypeFormItem = { + label: string + variable: string + required: boolean + max_length: number +} + +export type SelectTypeFormItem = { + label: string + variable: string + required: boolean + options: string[] +} +/** + * User Input Form Item + */ +export type UserInputFormItem = { + 'text-input': TextTypeFormItem +} | { + 'select': SelectTypeFormItem +} | { + 'paragraph': TextTypeFormItem +} + +export const MessageRatings = ['like', 'dislike', null] as const +export type MessageRating = typeof MessageRatings[number] + +export type Feedbacktype = { + rating: MessageRating + content?: string | null +} + +export type MessageMore = { + time: string + tokens: number + latency: number | string +} + +export type IChatItem = { + id: string + content: string + /** + * Specific message type + */ + isAnswer: boolean + /** + * The user feedback result of this message + */ + feedback?: Feedbacktype + /** + * The admin feedback result of this message + */ + adminFeedback?: Feedbacktype + /** + * Whether to hide the feedback area + */ + feedbackDisabled?: boolean + /** + * More information about this message + */ + more?: MessageMore + annotation?: Annotation + useCurrentUserAvatar?: boolean + isOpeningStatement?: boolean + suggestedQuestions?: string[] + log?: { role: string; text: string }[] + agent_thoughts?: ThoughtItem[] + message_files?: VisionFile[] +} + +export type ChatItem = IChatItem & { + isError?: boolean + workflow_run_id?: string + workflowProcess?: WorkflowProcess +} + +export type ResponseHolder = {} + +export type ConversationItem = { + id: string + name: string + inputs: Record | null + introduction: string, + suggested_questions?: string[] +} + +export type AppInfo = { + title: string + description: string + default_language: Locale + copyright?: string + privacy_policy?: string +} + +export enum Resolution { + low = 'low', + high = 'high', +} + +export enum TransferMethod { + all = 'all', + local_file = 'local_file', + remote_url = 'remote_url', +} + +export type VisionSettings = { + enabled: boolean + number_limits: number + detail: Resolution + transfer_methods: TransferMethod[] + image_file_size_limit?: number | string +} + +export type ImageFile = { + type: TransferMethod + _id: string + fileId: string + file?: File + progress: number + url: string + base64Url?: string + deleted?: boolean +} + +export type VisionFile = { + id?: string + type: string + transfer_method: TransferMethod + url: string + upload_file_id: string + belongs_to?: string +} + +export enum BlockEnum { + Start = 'start', + End = 'end', + Answer = 'answer', + LLM = 'llm', + KnowledgeRetrieval = 'knowledge-retrieval', + QuestionClassifier = 'question-classifier', + IfElse = 'if-else', + Code = 'code', + TemplateTransform = 'template-transform', + HttpRequest = 'http-request', + VariableAssigner = 'variable-assigner', + Tool = 'tool', +} + +export type NodeTracing = { + id: string + index: number + predecessor_node_id: string + node_id: string + node_type: BlockEnum + title: string + inputs: any + process_data: any + outputs?: any + status: string + error?: string + elapsed_time: number + execution_metadata: { + total_tokens: number + total_price: number + currency: string + } + created_at: number + created_by: { + id: string + name: string + email: string + } + finished_at: number + extras?: any + expand?: boolean // for UI +} + +export enum NodeRunningStatus { + NotStart = 'not-start', + Waiting = 'waiting', + Running = 'running', + Succeeded = 'succeeded', + Failed = 'failed', +} + +export enum WorkflowRunningStatus { + Waiting = 'waiting', + Running = 'running', + Succeeded = 'succeeded', + Failed = 'failed', + Stopped = 'stopped', +} + +export type WorkflowProcess = { + status: WorkflowRunningStatus + tracing: NodeTracing[] + expand?: boolean // for UI +} + +export enum CodeLanguage { + python3 = 'python3', + javascript = 'javascript', + json = 'json', +} diff --git a/src/types/base.ts b/src/types/base.ts new file mode 100644 index 0000000..35b63ea --- /dev/null +++ b/src/types/base.ts @@ -0,0 +1,5 @@ +export type TypeWithI18N = { + 'en_US': T + 'zh_Hans': T + [key: string]: T +} diff --git a/src/types/log.ts b/src/types/log.ts new file mode 100644 index 0000000..cae5da4 --- /dev/null +++ b/src/types/log.ts @@ -0,0 +1,16 @@ +export type LogAnnotation = { + content: string + account: { + id: string + name: string + email: string + } + created_at: number +} + +export type Annotation = { + id: string + authorName: string + logAnnotation?: LogAnnotation + created_at?: number +} diff --git a/src/types/tools.ts b/src/types/tools.ts new file mode 100644 index 0000000..b97ee61 --- /dev/null +++ b/src/types/tools.ts @@ -0,0 +1,108 @@ +import type { TypeWithI18N } from './base' +export enum LOC { + tools = 'tools', + app = 'app', +} + +export enum AuthType { + none = 'none', + apiKey = 'api_key', +} + +export type Credential = { + 'auth_type': AuthType + 'api_key_header'?: string + 'api_key_value'?: string +} + +export enum CollectionType { + all = 'all', + builtIn = 'builtin', + custom = 'api', +} + +export type Emoji = { + background: string + content: string +} + +export type Collection = { + id: string + name: string + author: string + description: TypeWithI18N + icon: string | Emoji + label: TypeWithI18N + type: CollectionType + team_credentials: Record + is_team_authorization: boolean + allow_delete: boolean +} + +export type ToolParameter = { + name: string + label: TypeWithI18N + human_description: TypeWithI18N + type: string + required: boolean + default: string + options?: { + label: TypeWithI18N + value: string + }[] +} + +export type Tool = { + name: string + label: TypeWithI18N + description: any + parameters: ToolParameter[] +} + +export type ToolCredential = { + name: string + label: TypeWithI18N + help: TypeWithI18N + placeholder: TypeWithI18N + type: string + required: boolean + default: string + options?: { + label: TypeWithI18N + value: string + }[] +} + +export type CustomCollectionBackend = { + provider: string + original_provider?: string + credentials: Credential + icon: Emoji + schema_type: string + schema: string + privacy_policy: string + tools?: ParamItem[] +} + +export type ParamItem = { + name: string + label: TypeWithI18N + human_description: TypeWithI18N + type: string + required: boolean + default: string + min?: number + max?: number + options?: { + label: TypeWithI18N + value: string + }[] +} + +export type CustomParamSchema = { + operation_id: string // name + summary: string + server_url: string + method: string + parameters: ParamItem[] +}