Implementation:Langgenius Dify Common Models
| Knowledge Sources | |
|---|---|
| Domains | Frontend, TypeSystem, API |
| Last Updated | 2026-02-12 07:00 GMT |
Overview
Shared TypeScript type definitions and interfaces for common API responses, user profiles, workspace entities, data sources, and provider configurations used throughout the Dify frontend.
Description
web/models/common.ts is the central type-definition module for the Dify frontend. It exports over 40 types, interfaces, and enums that model the shapes of API responses and domain entities common across the application. The file defines types for:
- API response shapes such as
CommonResponse,FileDownloadResponse,OauthResponse, andSetupStatusResponse. - User and workspace entities including
UserProfileResponse,Member,IWorkspace,ICurrentWorkspace, andInvitationResult. - Provider configurations with the
ProviderNameenum (OpenAI, Azure, Anthropic, Replicate, etc.) and mapped token types (ProviderAzureToken,ProviderAnthropicToken). - Data source integrations for Notion pages/workspaces (
DataSourceNotionPage,DataSourceNotionWorkspace) and website crawlers (DataSourceCategory,DataSourceProvider,FirecrawlConfig,WatercrawlConfig). - Extension and moderation types such as
ApiBasedExtension,CodeBasedExtension,ExternalDataTool, andModerationService. - File upload configuration via
FileUploadConfigResponsewith size and batch limits. - Structured output types for LLM-generated structured data.
All types are exported as named exports using the export type syntax, making them available for import across the frontend codebase without runtime overhead.
Usage
Import these types when building components or services that interact with the Dify backend API. They provide compile-time type safety for API request/response payloads, form data structures, and shared domain models.
Code Reference
Source Location
- Repository: Langgenius_Dify
- File: web/models/common.ts
- Lines: 1-323
Signature
export type CommonResponse = {
result: 'success' | 'fail'
}
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 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 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 type ICurrentWorkspace = Omit<IWorkspace, 'current'> & {
role: 'owner' | 'admin' | 'editor' | 'dataset_operator' | 'normal'
providers: Provider[]
// ...additional fields
}
export type FileUploadConfigResponse = {
batch_count_limit: number
file_size_limit: number
file_upload_limit: number
// ...additional size limits
}
Import
import type {
CommonResponse,
UserProfileResponse,
Member,
ICurrentWorkspace,
ProviderName,
FileUploadConfigResponse,
} from '@/models/common'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| N/A | N/A | N/A | This is a type-only module with no runtime inputs. |
Outputs
| Name | Type | Description |
|---|---|---|
| CommonResponse | type | Standard success/fail API response shape |
| UserProfileResponse | type | Full user profile data from the API |
| Member | type | Workspace member with role and status |
| ProviderName | enum | Enumeration of supported LLM provider identifiers |
| Provider | type | Mapped type for provider configuration per ProviderName |
| ICurrentWorkspace | type | Current workspace details including role, plan, and custom config |
| DataSourceNotionWorkspace | type | Notion workspace data source structure |
| FileUploadConfigResponse | type | File upload limits and constraints from the server |
| InvitationResult | type | Result of a member invitation (success or failure) |
| ModerationService | type | Function signature for content moderation calls |
Usage Examples
Checking API Response
import type { CommonResponse } from '@/models/common'
async function saveSettings(data: FormData): Promise<CommonResponse> {
const response = await fetch('/api/settings', { method: 'POST', body: data })
return response.json()
}
Accessing Member Role
import type { Member } from '@/models/common'
function isAdmin(member: Member): boolean {
return member.role === 'owner' || member.role === 'admin'
}