Initial commit

This commit is contained in:
2025-10-14 14:17:21 +08:00
commit ac715a8b88
35011 changed files with 3834178 additions and 0 deletions

View File

@@ -0,0 +1,169 @@
import type { LangFuseConfig, LangSmithConfig, OpikConfig, TracingProvider } from '@/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/tracing/type'
import type { App, AppSSO, AppTemplate, SiteConfig } from '@/types/app'
/* export type App = {
id: string
name: string
description: string
mode: AppMode
enable_site: boolean
enable_api: boolean
api_rpm: number
api_rph: number
is_demo: boolean
model_config: AppModelConfig
providers: Array<{ provider: string; token_is_set: boolean }>
site: SiteConfig
created_at: string
}
export type AppModelConfig = {
provider: string
model_id: string
configs: {
prompt_template: string
prompt_variables: Array<PromptVariable>
completion_params: CompletionParam
}
}
export type PromptVariable = {
key: string
name: string
description: string
type: string | number
default: string
options: string[]
}
export type CompletionParam = {
max_tokens: number
temperature: number
top_p: number
echo: boolean
stop: string[]
presence_penalty: number
frequency_penalty: number
}
export type SiteConfig = {
access_token: string
title: string
author: string
support_email: string
default_language: string
customize_domain: string
theme: string
customize_token_strategy: 'must' | 'allow' | 'not_allow'
prompt_public: boolean
} */
export enum DSLImportMode {
YAML_CONTENT = 'yaml-content',
YAML_URL = 'yaml-url',
}
export enum DSLImportStatus {
COMPLETED = 'completed',
COMPLETED_WITH_WARNINGS = 'completed-with-warnings',
PENDING = 'pending',
FAILED = 'failed',
}
export type AppListResponse = {
data: App[]
has_more: boolean
limit: number
page: number
total: number
}
export type AppDetailResponse = App
export type DSLImportResponse = {
id: string
status: DSLImportStatus
app_id?: string
current_dsl_version?: string
imported_dsl_version?: string
error: string
}
export type AppSSOResponse = { enabled: AppSSO['enable_sso'] }
export type AppTemplatesResponse = {
data: AppTemplate[]
}
export type CreateAppResponse = App
export type UpdateAppSiteCodeResponse = { app_id: string } & SiteConfig
export type AppDailyMessagesResponse = {
data: Array<{ date: string; message_count: number }>
}
export type AppDailyConversationsResponse = {
data: Array<{ date: string; conversation_count: number }>
}
export type WorkflowDailyConversationsResponse = {
data: Array<{ date: string; runs: number }>
}
export type AppStatisticsResponse = {
data: Array<{ date: string }>
}
export type AppDailyEndUsersResponse = {
data: Array<{ date: string; terminal_count: number }>
}
export type AppTokenCostsResponse = {
data: Array<{ date: string; token_count: number; total_price: number; currency: number }>
}
export type UpdateAppModelConfigResponse = { result: string }
export type ApiKeyItemResponse = {
id: string
token: string
last_used_at: string
created_at: string
}
export type ApiKeysListResponse = {
data: ApiKeyItemResponse[]
}
export type CreateApiKeyResponse = {
id: string
token: string
created_at: string
}
export type ValidateOpenAIKeyResponse = {
result: string
error?: string
}
export type UpdateOpenAIKeyResponse = ValidateOpenAIKeyResponse
export type GenerationIntroductionResponse = {
introduction: string
}
export type AppVoicesListResponse = [{
name: string
value: string
}]
export type TracingStatus = {
enabled: boolean
tracing_provider: TracingProvider | null
}
export type TracingConfig = {
tracing_provider: TracingProvider
tracing_config: LangSmithConfig | LangFuseConfig | OpikConfig
}

View File

@@ -0,0 +1,288 @@
import type { I18nText } from '@/i18n/language'
export type CommonResponse = {
result: 'success' | 'fail'
}
export type OauthResponse = {
redirect_url: string
}
export type SetupStatusResponse = {
step: 'finished' | 'not_started'
setup_at?: Date
}
export type InitValidateStatusResponse = {
status: 'finished' | 'not_started'
}
export type UserProfileResponse = {
id: string
name: string
email: string
avatar: string
avatar_url: string | null
is_password_set: boolean
interface_language?: string
interface_theme?: string
timezone?: string
last_login_at?: string
last_active_at?: string
last_login_ip?: string
created_at?: string
}
export type UserProfileOriginResponse = {
json: () => Promise<UserProfileResponse>
bodyUsed: boolean
headers: any
}
export type LangGeniusVersionResponse = {
current_version: string
latest_version: string
version: string
release_date: string
release_notes: string
can_auto_update: boolean
current_env: string
}
export type TenantInfoResponse = {
name: string
created_at: string
providers: Array<{
provider: string
provider_name: string
token_is_set: boolean
is_valid: boolean
token_is_valid: boolean
}>
in_trail: boolean
trial_end_reason: null | 'trial_exceeded' | 'using_custom'
}
export type Member = Pick<UserProfileResponse, 'id' | 'name' | 'email' | 'last_login_at' | 'last_active_at' | 'created_at' | 'avatar_url'> & {
avatar: string
status: 'pending' | 'active' | 'banned' | 'closed'
role: 'owner' | 'admin' | 'editor' | 'normal' | 'dataset_operator'
}
export enum ProviderName {
OPENAI = 'openai',
AZURE_OPENAI = 'azure_openai',
ANTHROPIC = 'anthropic',
Replicate = 'replicate',
HuggingfaceHub = 'huggingface_hub',
MiniMax = 'minimax',
Spark = 'spark',
Tongyi = 'tongyi',
ChatGLM = 'chatglm',
}
export type ProviderAzureToken = {
openai_api_base?: string
openai_api_key?: string
}
export type ProviderAnthropicToken = {
anthropic_api_key?: string
}
export type ProviderTokenType = {
[ProviderName.OPENAI]: string
[ProviderName.AZURE_OPENAI]: ProviderAzureToken
[ProviderName.ANTHROPIC]: ProviderAnthropicToken
}
export type Provider = {
[Name in ProviderName]: {
provider_name: Name
} & {
provider_type: 'custom' | 'system'
is_valid: boolean
is_enabled: boolean
last_used: string
token?: string | ProviderAzureToken | ProviderAnthropicToken
}
}[ProviderName]
export type ProviderHosted = Provider & {
quota_type: string
quota_limit: number
quota_used: number
}
export type AccountIntegrate = {
provider: 'google' | 'github'
created_at: number
is_bound: boolean
link: string
}
export type IWorkspace = {
id: string
name: string
plan: string
status: string
created_at: number
current: boolean
}
export type ICurrentWorkspace = Omit<IWorkspace, 'current'> & {
role: 'owner' | 'admin' | 'editor' | 'dataset_operator' | 'normal'
providers: Provider[]
in_trail: boolean
trial_end_reason?: string
custom_config?: {
remove_webapp_brand?: boolean
replace_webapp_logo?: string
}
}
export type DataSourceNotionPage = {
page_icon: null | {
type: string | null
url: string | null
emoji: string | null
}
page_id: string
page_name: string
parent_id: string
type: string
is_bound: boolean
}
export type NotionPage = DataSourceNotionPage & {
workspace_id: string
}
export type DataSourceNotionPageMap = Record<string, DataSourceNotionPage & { workspace_id: string }>
export type DataSourceNotionWorkspace = {
workspace_name: string
workspace_id: string
workspace_icon: string | null
total?: number
pages: DataSourceNotionPage[]
}
export type DataSourceNotionWorkspaceMap = Record<string, DataSourceNotionWorkspace>
export type DataSourceNotion = {
id: string
provider: string
is_bound: boolean
source_info: DataSourceNotionWorkspace
}
export enum DataSourceCategory {
website = 'website',
}
export enum DataSourceProvider {
fireCrawl = 'firecrawl',
jinaReader = 'jinareader',
}
export type FirecrawlConfig = {
api_key: string
base_url: string
}
export type DataSourceItem = {
id: string
category: DataSourceCategory
provider: DataSourceProvider
disabled: boolean
created_at: number
updated_at: number
}
export type DataSources = {
sources: DataSourceItem[]
}
export type GithubRepo = {
stargazers_count: number
}
export type PluginProvider = {
tool_name: string
is_enabled: boolean
credentials: {
api_key: string
} | null
}
export type FileUploadConfigResponse = {
batch_count_limit: number
image_file_size_limit?: number | string // default is 10MB
file_size_limit: number // default is 15MB
audio_file_size_limit?: number // default is 50MB
video_file_size_limit?: number // default is 100MB
workflow_file_upload_limit?: number // default is 10
}
export type InvitationResult = {
status: 'success'
email: string
url: string
} | {
status: 'failed'
email: string
message: string
}
export type InvitationResponse = CommonResponse & {
invitation_results: InvitationResult[]
}
export type ApiBasedExtension = {
id?: string
name?: string
api_endpoint?: string
api_key?: string
}
export type CodeBasedExtensionForm = {
type: string
label: I18nText
variable: string
required: boolean
options: { label: I18nText; value: string }[]
default: string
placeholder: string
max_length?: number
}
export type CodeBasedExtensionItem = {
name: string
label: any
form_schema: CodeBasedExtensionForm[]
}
export type CodeBasedExtension = {
module: string
data: CodeBasedExtensionItem[]
}
export type ExternalDataTool = {
type?: string
label?: string
icon?: string
icon_background?: string
variable?: string
enabled?: boolean
config?: {
api_based_extension_id?: string
} & Partial<Record<string, any>>
}
export type ModerateResponse = {
flagged: boolean
text: string
}
export type ModerationService = (
url: string,
body: {
app_id: string
text: string
}
) => Promise<ModerateResponse>

View File

@@ -0,0 +1,679 @@
import type { DataSourceNotionPage, DataSourceProvider } from './common'
import type { AppIconType, AppMode, RetrievalConfig } from '@/types/app'
import type { Tag } from '@/app/components/base/tag-management/constant'
import type { IndexingType } from '@/app/components/datasets/create/step-two'
export enum DataSourceType {
FILE = 'upload_file',
NOTION = 'notion_import',
WEB = 'website_crawl',
}
export enum DatasetPermission {
'onlyMe' = 'only_me',
'allTeamMembers' = 'all_team_members',
'partialMembers' = 'partial_members',
}
export enum ChunkingMode {
'text' = 'text_model', // General text
'qa' = 'qa_model', // General QA
'parentChild' = 'hierarchical_model', // Parent-Child
}
export type DataSet = {
id: string
name: string
icon: string
icon_background: string
description: string
permission: DatasetPermission
data_source_type: DataSourceType
indexing_technique: IndexingType
created_by: string
updated_by: string
updated_at: number
app_count: number
doc_form: ChunkingMode
document_count: number
word_count: number
provider: string
embedding_model: string
embedding_model_provider: string
embedding_available: boolean
retrieval_model_dict: RetrievalConfig
retrieval_model: RetrievalConfig
tags: Tag[]
partial_member_list?: string[]
external_knowledge_info: {
external_knowledge_id: string
external_knowledge_api_id: string
external_knowledge_api_name: string
external_knowledge_api_endpoint: string
}
external_retrieval_model: {
top_k: number
score_threshold: number
score_threshold_enabled: boolean
}
}
export type ExternalAPIItem = {
id: string
tenant_id: string
name: string
description: string
settings: {
endpoint: string
api_key: string
}
dataset_bindings: { id: string; name: string }[]
created_by: string
created_at: string
}
export type ExternalKnowledgeItem = {
id: string
name: string
description: string | null
provider: 'external'
permission: DatasetPermission
data_source_type: null
indexing_technique: null
app_count: number
document_count: number
word_count: number
created_by: string
created_at: string
updated_by: string
updated_at: string
tags: Tag[]
}
export type ExternalAPIDeleteResponse = {
result: 'success' | 'error'
}
export type ExternalAPIUsage = {
is_using: boolean
count: number
}
export type CustomFile = File & {
id?: string
extension?: string
mime_type?: string
created_by?: string
created_at?: number
}
export type DocumentItem = {
id: string
name: string
extension: string
}
export type CrawlOptions = {
crawl_sub_pages: boolean
only_main_content: boolean
includes: string
excludes: string
limit: number | string
max_depth: number | string
use_sitemap: boolean
}
export type CrawlResultItem = {
title: string
markdown: string
description: string
source_url: string
}
export type FileItem = {
fileID: string
file: CustomFile
progress: number
}
export type FetchDatasetsParams = {
url: string
params: {
page: number
tag_ids?: string[]
limit: number
include_all: boolean
keyword?: string
}
}
export type DataSetListResponse = {
data: DataSet[]
has_more: boolean
limit: number
page: number
total: number
}
export type ExternalAPIListResponse = {
data: ExternalAPIItem[]
has_more: boolean
limit: number
page: number
total: number
}
export type QA = {
question: string
answer: string
}
export type IndexingEstimateResponse = {
tokens: number
total_price: number
currency: string
total_segments: number
preview: Array<{ content: string; child_chunks: string[] }>
qa_preview?: QA[]
}
export type FileIndexingEstimateResponse = {
total_nodes: number
} & IndexingEstimateResponse
export type IndexingStatusResponse = {
id: string
indexing_status: DocumentIndexingStatus
processing_started_at: number
parsing_completed_at: number
cleaning_completed_at: number
splitting_completed_at: number
completed_at: any
paused_at: any
error: any
stopped_at: any
completed_segments: number
total_segments: number
}
export type IndexingStatusBatchResponse = {
data: IndexingStatusResponse[]
}
export enum ProcessMode {
general = 'custom',
parentChild = 'hierarchical',
}
export type ParentMode = 'full-doc' | 'paragraph'
export type ProcessRuleResponse = {
mode: ProcessMode
rules: Rules
limits: Limits
}
export type Rules = {
pre_processing_rules: PreProcessingRule[]
segmentation: Segmentation
parent_mode: ParentMode
subchunk_segmentation: Segmentation
}
export type Limits = {
indexing_max_segmentation_tokens_length: number
}
export type PreProcessingRule = {
id: string
enabled: boolean
}
export type Segmentation = {
separator: string
max_tokens: number
chunk_overlap?: number
}
export const DocumentIndexingStatusList = [
'waiting',
'parsing',
'cleaning',
'splitting',
'indexing',
'paused',
'error',
'completed',
] as const
export type DocumentIndexingStatus = typeof DocumentIndexingStatusList[number]
export const DisplayStatusList = [
'queuing',
'indexing',
'paused',
'error',
'available',
'enabled',
'disabled',
'archived',
] as const
export type DocumentDisplayStatus = typeof DisplayStatusList[number]
export type DataSourceInfo = {
upload_file: {
id: string
name: string
size: number
mime_type: string
created_at: number
created_by: string
extension: string
}
notion_page_icon?: string
notion_workspace_id?: string
notion_page_id?: string
provider?: DataSourceProvider
job_id: string
url: string
}
export type InitialDocumentDetail = {
id: string
batch: string
position: number
dataset_id: string
data_source_type: DataSourceType
data_source_info: DataSourceInfo
dataset_process_rule_id: string
name: string
created_from: 'api' | 'web'
created_by: string
created_at: number
indexing_status: DocumentIndexingStatus
display_status: DocumentDisplayStatus
completed_segments?: number
total_segments?: number
doc_form: ChunkingMode
doc_language: string
}
export type SimpleDocumentDetail = InitialDocumentDetail & {
enabled: boolean
word_count: number
is_qa: boolean // TODO waiting for backend to add this field
error?: string | null
archived: boolean
updated_at: number
hit_count: number
dataset_process_rule_id?: string
data_source_detail_dict?: {
upload_file: {
name: string
extension: string
}
}
}
export type DocumentListResponse = {
data: SimpleDocumentDetail[]
has_more: boolean
total: number
page: number
limit: number
}
export type DocumentReq = {
original_document_id?: string
indexing_technique?: string
doc_form: ChunkingMode
doc_language: string
process_rule: ProcessRule
}
export type CreateDocumentReq = DocumentReq & {
data_source: DataSource
retrieval_model: RetrievalConfig
embedding_model: string
embedding_model_provider: string
}
export type IndexingEstimateParams = DocumentReq & Partial<DataSource> & {
dataset_id: string
}
export type DataSource = {
type: DataSourceType
info_list: {
data_source_type: DataSourceType
notion_info_list?: NotionInfo[]
file_info_list?: {
file_ids: string[]
}
website_info_list?: {
provider: string
job_id: string
urls: string[]
}
}
}
export type NotionInfo = {
workspace_id: string
pages: DataSourceNotionPage[]
}
export type NotionPage = {
page_id: string
type: string
}
export type ProcessRule = {
mode: ProcessMode
rules: Rules
}
export type createDocumentResponse = {
dataset?: DataSet
batch: string
documents: InitialDocumentDetail[]
}
export type PrecessRule = {
mode: ProcessMode
rules: Rules
}
export type FullDocumentDetail = SimpleDocumentDetail & {
batch: string
created_api_request_id: string
processing_started_at: number
parsing_completed_at: number
cleaning_completed_at: number
splitting_completed_at: number
tokens: number
indexing_latency: number
completed_at: number
paused_by: string
paused_at: number
stopped_at: number
indexing_status: string
disabled_at: number
disabled_by: string
archived_reason: 'rule_modified' | 're_upload'
archived_by: string
archived_at: number
doc_type?: DocType | null | 'others'
doc_metadata?: DocMetadata | null
segment_count: number
dataset_process_rule: PrecessRule
document_process_rule: ProcessRule
[key: string]: any
}
export type DocMetadata = {
title: string
language: string
author: string
publisher: string
publicationDate: string
ISBN: string
category: string
[key: string]: string
}
export const CUSTOMIZABLE_DOC_TYPES = [
'book',
'web_page',
'paper',
'social_media_post',
'personal_document',
'business_document',
'im_chat_log',
] as const
export const FIXED_DOC_TYPES = ['synced_from_github', 'synced_from_notion', 'wikipedia_entry'] as const
export type CustomizableDocType = typeof CUSTOMIZABLE_DOC_TYPES[number]
export type FixedDocType = typeof FIXED_DOC_TYPES[number]
export type DocType = CustomizableDocType | FixedDocType
export type DocumentDetailResponse = FullDocumentDetail
export const SEGMENT_STATUS_LIST = ['waiting', 'completed', 'error', 'indexing']
export type SegmentStatus = typeof SEGMENT_STATUS_LIST[number]
export type SegmentsQuery = {
page?: string
limit: number
// status?: SegmentStatus
hit_count_gte?: number
keyword?: string
enabled?: boolean | 'all'
}
export type SegmentDetailModel = {
id: string
position: number
document_id: string
content: string
word_count: number
tokens: number
keywords: string[]
index_node_id: string
index_node_hash: string
hit_count: number
enabled: boolean
disabled_at: number
disabled_by: string
status: SegmentStatus
created_by: string
created_at: number
indexing_at: number
completed_at: number
error: string | null
stopped_at: number
answer?: string
child_chunks?: ChildChunkDetail[]
updated_at: number
}
export type SegmentsResponse = {
data: SegmentDetailModel[]
has_more: boolean
limit: number
total: number
total_pages: number
page: number
}
export type HitTestingRecord = {
id: string
content: string
source: 'app' | 'hit_testing' | 'plugin'
source_app_id: string
created_by_role: 'account' | 'end_user'
created_by: string
created_at: number
}
export type HitTestingChildChunk = {
id: string
content: string
position: number
score: number
}
export type HitTesting = {
segment: Segment
content: Segment
score: number
tsne_position: TsnePosition
child_chunks?: HitTestingChildChunk[] | null
}
export type ExternalKnowledgeBaseHitTesting = {
content: string
title: string
score: number
metadata: {
'x-amz-bedrock-kb-source-uri': string
'x-amz-bedrock-kb-data-source-id': string
}
}
export type Segment = {
id: string
document: Document
content: string
position: number
word_count: number
tokens: number
keywords: string[]
hit_count: number
index_node_hash: string
}
export type Document = {
id: string
data_source_type: string
name: string
doc_type: DocType
}
export type HitTestingRecordsResponse = {
data: HitTestingRecord[]
has_more: boolean
limit: number
total: number
page: number
}
export type TsnePosition = {
x: number
y: number
}
export type HitTestingResponse = {
query: {
content: string
tsne_position: TsnePosition
}
records: Array<HitTesting>
}
export type ExternalKnowledgeBaseHitTestingResponse = {
query: {
content: string
}
records: Array<ExternalKnowledgeBaseHitTesting>
}
export type RelatedApp = {
id: string
name: string
mode: AppMode
icon_type: AppIconType | null
icon: string
icon_background: string
icon_url: string
}
export type RelatedAppResponse = {
data: Array<RelatedApp>
total: number
}
export type SegmentUpdater = {
content: string
answer?: string
keywords?: string[]
regenerate_child_chunks?: boolean
}
export type ErrorDocsResponse = {
data: IndexingStatusResponse[]
total: number
}
export type SelectedDatasetsMode = {
allHighQuality: boolean
allHighQualityVectorSearch: boolean
allHighQualityFullTextSearch: boolean
allEconomic: boolean
mixtureHighQualityAndEconomic: boolean
allInternal: boolean
allExternal: boolean
mixtureInternalAndExternal: boolean
inconsistentEmbeddingModel: boolean
}
export enum WeightedScoreEnum {
SemanticFirst = 'semantic_first',
KeywordFirst = 'keyword_first',
Customized = 'customized',
}
export enum RerankingModeEnum {
RerankingModel = 'reranking_model',
WeightedScore = 'weighted_score',
}
export const DEFAULT_WEIGHTED_SCORE = {
allHighQualityVectorSearch: {
semantic: 1.0,
keyword: 0,
},
allHighQualityFullTextSearch: {
semantic: 0,
keyword: 1.0,
},
other: {
semantic: 0.7,
keyword: 0.3,
},
}
export type ChildChunkType = 'automatic' | 'customized'
export type ChildChunkDetail = {
id: string
position: number
segment_id: string
content: string
word_count: number
created_at: number
updated_at: number
type: ChildChunkType
}
export type ChildSegmentsResponse = {
data: ChildChunkDetail[]
total: number
total_pages: number
page: number
limit: number
}
export type UpdateDocumentParams = {
datasetId: string
documentId: string
}
// Used in api url
export enum DocumentActionType {
enable = 'enable',
disable = 'disable',
archive = 'archive',
unArchive = 'un_archive',
delete = 'delete',
}
export type UpdateDocumentBatchParams = {
datasetId: string
documentId?: string
documentIds?: string[] | string
}
export type BatchImportResponse = {
job_id: string
job_status: string
}

View File

@@ -0,0 +1,246 @@
import type { AgentStrategy, ModelModeType, RETRIEVE_TYPE, ToolItem, TtsAutoPlay } from '@/types/app'
import type {
RerankingModeEnum,
} from '@/models/datasets'
import type { FileUpload } from '@/app/components/base/features/types'
export type Inputs = Record<string, string | number | object>
export enum PromptMode {
simple = 'simple',
advanced = 'advanced',
}
export type PromptItem = {
role?: PromptRole
text: string
}
export type ChatPromptConfig = {
prompt: PromptItem[]
}
export type ConversationHistoriesRole = {
user_prefix: string
assistant_prefix: string
}
export type CompletionPromptConfig = {
prompt: PromptItem
conversation_histories_role: ConversationHistoriesRole
}
export type BlockStatus = {
context: boolean
history: boolean
query: boolean
}
export enum PromptRole {
system = 'system',
user = 'user',
assistant = 'assistant',
}
export type PromptVariable = {
key: string
name: string
type: string // "string" | "number" | "select",
default?: string | number
required?: boolean
options?: string[]
max_length?: number
is_context_var?: boolean
enabled?: boolean
config?: Record<string, any>
icon?: string
icon_background?: string
}
export type CompletionParams = {
max_tokens: number
temperature: number
top_p: number
presence_penalty: number
frequency_penalty: number
stop?: string[]
}
export type ModelId = 'gpt-3.5-turbo' | 'text-davinci-003'
export type PromptConfig = {
prompt_template: string
prompt_variables: PromptVariable[]
}
export type MoreLikeThisConfig = {
enabled: boolean
}
export type SuggestedQuestionsAfterAnswerConfig = MoreLikeThisConfig
export type SpeechToTextConfig = MoreLikeThisConfig
export type TextToSpeechConfig = {
enabled: boolean
voice?: string
language?: string
autoPlay?: TtsAutoPlay
}
export type CitationConfig = MoreLikeThisConfig
export type AnnotationReplyConfig = {
id: string
enabled: boolean
score_threshold: number
embedding_model: {
embedding_provider_name: string
embedding_model_name: string
}
}
export type ModerationContentConfig = {
enabled: boolean
preset_response?: string
}
export type ModerationConfig = MoreLikeThisConfig & {
type?: string
config?: {
keywords?: string
api_based_extension_id?: string
inputs_config?: ModerationContentConfig
outputs_config?: ModerationContentConfig
} & Partial<Record<string, any>>
}
export type RetrieverResourceConfig = MoreLikeThisConfig
export type AgentConfig = {
enabled: boolean
strategy: AgentStrategy
max_iteration: number
tools: ToolItem[]
}
// frontend use. Not the same as backend
export type ModelConfig = {
provider: string // LLM Provider: for example "OPENAI"
model_id: string
mode: ModelModeType
configs: PromptConfig
opening_statement: string | null
more_like_this: MoreLikeThisConfig | null
suggested_questions: string[] | null
suggested_questions_after_answer: SuggestedQuestionsAfterAnswerConfig | null
speech_to_text: SpeechToTextConfig | null
text_to_speech: TextToSpeechConfig | null
file_upload: FileUpload | null
retriever_resource: RetrieverResourceConfig | null
sensitive_word_avoidance: ModerationConfig | null
annotation_reply: AnnotationReplyConfig | null
dataSets: any[]
agentConfig: AgentConfig
}
export type DatasetConfigItem = {
enable: boolean
value: number
}
export type DatasetConfigs = {
retrieval_model: RETRIEVE_TYPE
reranking_model: {
reranking_provider_name: string
reranking_model_name: string
}
top_k: number
score_threshold_enabled: boolean
score_threshold: number | null | undefined
datasets: {
datasets: {
enabled: boolean
id: string
}[]
}
reranking_mode?: RerankingModeEnum
weights?: {
vector_setting: {
vector_weight: number
embedding_provider_name: string
embedding_model_name: string
}
keyword_setting: {
keyword_weight: number
}
}
reranking_enable?: boolean
}
export type DebugRequestBody = {
inputs: Inputs
query: string
completion_params: CompletionParams
model_config: ModelConfig
}
export type DebugResponse = {
id: string
answer: string
created_at: string
}
export type DebugResponseStream = {
id: string
data: string
created_at: string
}
export type FeedBackRequestBody = {
message_id: string
rating: 'like' | 'dislike'
content?: string
from_source: 'api' | 'log'
}
export type FeedBackResponse = {
message_id: string
rating: 'like' | 'dislike'
}
// Log session list
export type LogSessionListQuery = {
keyword?: string
start?: string // format datetime(YYYY-mm-dd HH:ii)
end?: string // format datetime(YYYY-mm-dd HH:ii)
page: number
limit: number // default 20. 1-100
}
export type LogSessionListResponse = {
data: {
id: string
conversation_id: string
query: string // user's query question
message: string // prompt send to LLM
answer: string
created_at: string
}[]
total: number
page: number
}
// log session detail and debug
export type LogSessionDetailResponse = {
id: string
conversation_id: string
model_provider: string
query: string
inputs: Record<string, string | number | object>[]
message: string
message_tokens: number // number of tokens in message
answer: string
answer_tokens: number // number of tokens in answer
provider_response_latency: number // used time in ms
from_source: 'api' | 'log'
}
export type SavedMessage = {
id: string
answer: string
}

View File

@@ -0,0 +1,37 @@
import type { AppIconType, AppMode } from '@/types/app'
export type AppBasicInfo = {
id: string
mode: AppMode
icon_type: AppIconType | null
icon: string
icon_background: string
icon_url: string
name: string
description: string
use_icon_as_answer_icon: boolean
}
export type AppCategory = 'Writing' | 'Translate' | 'HR' | 'Programming' | 'Assistant' | 'Agent' | 'Recommended' | 'Workflow'
export type App = {
app: AppBasicInfo
app_id: string
description: string
copyright: string
privacy_policy: string | null
custom_disclaimer: string | null
category: AppCategory
position: number
is_listed: boolean
install_count: number
installed: boolean
editable: boolean
is_agent: boolean
}
export type InstalledApp = {
app: AppBasicInfo
id: string
uninstallable: boolean
is_pinned: boolean
}

View File

@@ -0,0 +1,355 @@
import type { Viewport } from 'reactflow'
import type { VisionFile } from '@/types/app'
import type {
Edge,
Node,
} from '@/app/components/workflow/types'
import type { Metadata } from '@/app/components/base/chat/chat/type'
// Log type contains key:string conversation_id:string created_at:string question:string answer:string
export type Conversation = {
id: string
key: string
conversationId: string
question: string
answer: string
userRate: number
adminRate: number
}
export type ConversationListResponse = {
logs: Conversation[]
}
export const fetchLogs = (url: string) =>
fetch(url).then<ConversationListResponse>(r => r.json())
export const CompletionParams = ['temperature', 'top_p', 'presence_penalty', 'max_token', 'stop', 'frequency_penalty'] as const
export type CompletionParamType = typeof CompletionParams[number]
export type CompletionParamsType = {
max_tokens: number
temperature: number
top_p: number
stop: string[]
presence_penalty: number
frequency_penalty: number
}
export type LogModelConfig = {
name: string
provider: string
completion_params: CompletionParamsType
}
export type ModelConfigDetail = {
introduction: string
prompt_template: string
prompt_variables: Array<{
key: string
name: string
description: string
type: string | number
default: string
options: string[]
}>
completion_params: CompletionParamsType
}
export type LogAnnotation = {
id: string
content: string
account: {
id: string
name: string
email: string
}
created_at: number
}
export type Annotation = {
id: string
authorName: string
logAnnotation?: LogAnnotation
created_at?: number
}
export type MessageContent = {
id: string
conversation_id: string
query: string
inputs: Record<string, any>
message: { role: string; text: string; files?: VisionFile[] }[]
message_tokens: number
answer_tokens: number
answer: string
provider_response_latency: number
created_at: number
annotation: LogAnnotation
annotation_hit_history: {
annotation_id: string
annotation_create_account: {
id: string
name: string
email: string
}
created_at: number
}
feedbacks: Array<{
rating: 'like' | 'dislike' | null
content: string | null
from_source?: 'admin' | 'user'
from_end_user_id?: string
}>
message_files: VisionFile[]
metadata: Metadata
agent_thoughts: any[] // TODO
workflow_run_id: string
parent_message_id: string | null
}
export type CompletionConversationGeneralDetail = {
id: string
status: 'normal' | 'finished'
from_source: 'api' | 'console'
from_end_user_id: string
from_end_user_session_id: string
from_account_id: string
read_at: Date
created_at: number
updated_at: number
annotation: Annotation
user_feedback_stats: {
like: number
dislike: number
}
admin_feedback_stats: {
like: number
dislike: number
}
model_config: {
provider: string
model_id: string
configs: Pick<ModelConfigDetail, 'prompt_template'>
}
message: Pick<MessageContent, 'inputs' | 'query' | 'answer' | 'message'>
}
export type CompletionConversationFullDetailResponse = {
id: string
status: 'normal' | 'finished'
from_source: 'api' | 'console'
from_end_user_id: string
from_account_id: string
// read_at: Date
created_at: number
model_config: {
provider: string
model_id: string
configs: ModelConfigDetail
}
message: MessageContent
}
export type CompletionConversationsResponse = {
data: Array<CompletionConversationGeneralDetail>
has_more: boolean
limit: number
total: number
page: number
}
export type CompletionConversationsRequest = {
keyword: string
start: string
end: string
annotation_status: string
page: number
limit: number // The default value is 20 and the range is 1-100
}
export type ChatConversationGeneralDetail = Omit<CompletionConversationGeneralDetail, 'message' | 'annotation'> & {
summary: string
message_count: number
annotated: boolean
}
export type ChatConversationsResponse = {
data: Array<ChatConversationGeneralDetail>
has_more: boolean
limit: number
total: number
page: number
}
export type ChatConversationsRequest = CompletionConversationsRequest & { message_count: number }
export type ChatConversationFullDetailResponse = Omit<CompletionConversationGeneralDetail, 'message' | 'model_config'> & {
message_count: number
model_config: {
provider: string
model_id: string
configs: ModelConfigDetail
model: LogModelConfig
}
}
export type ChatMessagesRequest = {
conversation_id: string
first_id?: string
limit: number
}
export type ChatMessage = MessageContent
export type ChatMessagesResponse = {
data: Array<ChatMessage>
has_more: boolean
limit: number
}
export const MessageRatings = ['like', 'dislike', null] as const
export type MessageRating = typeof MessageRatings[number]
export type LogMessageFeedbacksRequest = {
message_id: string
rating: MessageRating
content?: string
}
export type LogMessageFeedbacksResponse = {
result: 'success' | 'error'
}
export type LogMessageAnnotationsRequest = Omit<LogMessageFeedbacksRequest, 'rating'>
export type LogMessageAnnotationsResponse = LogMessageFeedbacksResponse
export type AnnotationsCountResponse = {
count: number
}
export type WorkflowRunDetail = {
id: string
version: string
status: 'running' | 'succeeded' | 'failed' | 'stopped'
error?: string
elapsed_time: number
total_tokens: number
total_price: number
currency: string
total_steps: number
finished_at: number
}
export type AccountInfo = {
id: string
name: string
email: string
}
export type EndUserInfo = {
id: string
type: 'browser' | 'service_api'
is_anonymous: boolean
session_id: string
}
export type WorkflowAppLogDetail = {
id: string
workflow_run: WorkflowRunDetail
created_from: 'service-api' | 'web-app' | 'explore'
created_by_role: 'account' | 'end_user'
created_by_account?: AccountInfo
created_by_end_user?: EndUserInfo
created_at: number
read_at?: number
}
export type WorkflowLogsResponse = {
data: Array<WorkflowAppLogDetail>
has_more: boolean
limit: number
total: number
page: number
}
export type WorkflowLogsRequest = {
keyword: string
status: string
page: number
limit: number // The default value is 20 and the range is 1-100
}
export type WorkflowRunDetailResponse = {
id: string
sequence_number: number
version: string
graph: {
nodes: Node[]
edges: Edge[]
viewport?: Viewport
}
inputs: string
status: 'running' | 'succeeded' | 'failed' | 'stopped'
outputs?: string
error?: string
elapsed_time?: number
total_tokens?: number
total_steps: number
created_by_role: 'account' | 'end_user'
created_by_account?: AccountInfo
created_by_end_user?: EndUserInfo
created_at: number
finished_at: number
exceptions_count?: number
}
export type AgentLogMeta = {
status: string
executor: string
start_time: string
elapsed_time: number
total_tokens: number
agent_mode: string
iterations: number
error?: string
}
export type ToolCall = {
status: string
error?: string | null
time_cost?: number
tool_icon: any
tool_input?: any
tool_output?: any
tool_name?: string
tool_label?: any
tool_parameters?: any
}
export type AgentIteration = {
created_at: string
files: string[]
thought: string
tokens: number
tool_calls: ToolCall[]
tool_raw: {
inputs: string
outputs: string
}
}
export type AgentLogFile = {
id: string
type: string
url: string
name: string
belongs_to: string
}
export type AgentLogDetailRequest = {
conversation_id: string
message_id: string
}
export type AgentLogDetailResponse = {
meta: AgentLogMeta
iterations: AgentIteration[]
files: AgentLogFile[]
}

View File

@@ -0,0 +1,48 @@
import type { Locale } from '@/i18n'
import type { AppIconType } from '@/types/app'
export type ResponseHolder = {}
export type ConversationItem = {
id: string
name: string
inputs: Record<string, any> | null
introduction: string
}
export type SiteInfo = {
title: string
chat_color_theme?: string
chat_color_theme_inverted?: boolean
icon_type?: AppIconType | null
icon?: string
icon_background?: string | null
icon_url?: string | null
description?: string
default_language?: Locale
prompt_public?: boolean
copyright?: string
privacy_policy?: string
custom_disclaimer?: string
show_workflow_steps?: boolean
use_icon_as_answer_icon?: boolean
}
export type AppMeta = {
tool_icons: Record<string, string>
}
export type AppData = {
app_id: string
can_replace_logo?: boolean
custom_config?: Record<string, any>
enable_site?: boolean
end_user_id?: string
site: SiteInfo
}
export type AppConversationData = {
data: ConversationItem[]
has_more: boolean
limit: number
}

View File

@@ -0,0 +1,17 @@
export type User = {
id: string
firstName: string
lastName: string
name: string
phone: string
username: string
email: string
avatar: string
}
export type UserResponse = {
users: User[]
}
export const fetchUsers = (url: string) =>
fetch(url).then<UserResponse>(r => r.json())