Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor(web): convert 7 enums to as-const objects (batch 5) (#33960)

Mahmoud Hamdy8ca54ddf94b0
diff --git a/web/app/components/rag-pipeline/components/chunk-card-list/types.ts b/web/app/components/rag-pipeline/components/chunk-card-list/types.ts
index 6117855b3b8..b1213917e4c 100644
--- a/web/app/components/rag-pipeline/components/chunk-card-list/types.ts
+++ b/web/app/components/rag-pipeline/components/chunk-card-list/types.ts
@@ -26,7 +26,8 @@ export type QAChunks = {
export type ChunkInfo = GeneralChunks | ParentChildChunks | QAChunks
-export enum QAItemType {
- Question = 'question',
- Answer = 'answer',
-}
+export const QAItemType = {
+ Question: 'question',
+ Answer: 'answer',
+} as const
+export type QAItemType = typeof QAItemType[keyof typeof QAItemType]
diff --git a/web/app/components/rag-pipeline/components/panel/test-run/types.ts b/web/app/components/rag-pipeline/components/panel/test-run/types.ts
index ac5ca3ced23..d129487fe16 100644
--- a/web/app/components/rag-pipeline/components/panel/test-run/types.ts
+++ b/web/app/components/rag-pipeline/components/panel/test-run/types.ts
@@ -1,9 +1,10 @@
import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types'
-export enum TestRunStep {
- dataSource = 'dataSource',
- documentProcessing = 'documentProcessing',
-}
+export const TestRunStep = {
+ dataSource: 'dataSource',
+ documentProcessing: 'documentProcessing',
+} as const
+export type TestRunStep = typeof TestRunStep[keyof typeof TestRunStep]
export type DataSourceOption = {
label: string
diff --git a/web/app/components/workflow/note-node/types.ts b/web/app/components/workflow/note-node/types.ts
index ad68bd0f108..e8a18589fd8 100644
--- a/web/app/components/workflow/note-node/types.ts
+++ b/web/app/components/workflow/note-node/types.ts
@@ -1,13 +1,14 @@
import type { CommonNodeType } from '../types'
-export enum NoteTheme {
- blue = 'blue',
- cyan = 'cyan',
- green = 'green',
- yellow = 'yellow',
- pink = 'pink',
- violet = 'violet',
-}
+export const NoteTheme = {
+ blue: 'blue',
+ cyan: 'cyan',
+ green: 'green',
+ yellow: 'yellow',
+ pink: 'pink',
+ violet: 'violet',
+} as const
+export type NoteTheme = typeof NoteTheme[keyof typeof NoteTheme]
export type NoteNodeType = CommonNodeType & {
text: string
diff --git a/web/app/components/workflow/variable-inspect/right.tsx b/web/app/components/workflow/variable-inspect/right.tsx
index af939d41ead..893c477d041 100644
--- a/web/app/components/workflow/variable-inspect/right.tsx
+++ b/web/app/components/workflow/variable-inspect/right.tsx
@@ -174,7 +174,7 @@ const Right = ({
{currentNodeVar?.var && (
<>
{
- [VarInInspectType.environment, VarInInspectType.conversation, VarInInspectType.system].includes(currentNodeVar.nodeType as VarInInspectType) && (
+ ([VarInInspectType.environment, VarInInspectType.conversation, VarInInspectType.system] as VarInInspectType[]).includes(currentNodeVar.nodeType as VarInInspectType) && (
<VariableIconWithColor
variableCategory={currentNodeVar.nodeType as VarInInspectType}
className="size-4"
diff --git a/web/app/components/workflow/variable-inspect/types.ts b/web/app/components/workflow/variable-inspect/types.ts
index 4172f51d1e3..47d525eb31f 100644
--- a/web/app/components/workflow/variable-inspect/types.ts
+++ b/web/app/components/workflow/variable-inspect/types.ts
@@ -2,12 +2,14 @@ export const EVENT_WORKFLOW_STOP = 'WORKFLOW_STOP'
export const CHUNK_SCHEMA_TYPES = ['general_structure', 'parent_child_structure', 'qa_structure']
-export enum ViewMode {
- Code = 'code',
- Preview = 'preview',
-}
+export const ViewMode = {
+ Code: 'code',
+ Preview: 'preview',
+} as const
+export type ViewMode = typeof ViewMode[keyof typeof ViewMode]
-export enum PreviewType {
- Markdown = 'markdown',
- Chunks = 'chunks',
-}
+export const PreviewType = {
+ Markdown: 'markdown',
+ Chunks: 'chunks',
+} as const
+export type PreviewType = typeof PreviewType[keyof typeof PreviewType]
diff --git a/web/eslint-suppressions.json b/web/eslint-suppressions.json
index 65045b596c1..98d2976f8eb 100644
--- a/web/eslint-suppressions.json
+++ b/web/eslint-suppressions.json
@@ -6318,11 +6318,6 @@
"count": 1
}
},
- "app/components/rag-pipeline/components/chunk-card-list/types.ts": {
- "erasable-syntax-only/enums": {
- "count": 1
- }
- },
"app/components/rag-pipeline/components/conversion.tsx": {
"no-restricted-imports": {
"count": 2
@@ -6480,11 +6475,6 @@
"count": 1
}
},
- "app/components/rag-pipeline/components/panel/test-run/types.ts": {
- "erasable-syntax-only/enums": {
- "count": 1
- }
- },
"app/components/rag-pipeline/components/publish-as-knowledge-pipeline-modal.tsx": {
"no-restricted-imports": {
"count": 1
@@ -9351,11 +9341,6 @@
"count": 1
}
},
- "app/components/workflow/note-node/types.ts": {
- "erasable-syntax-only/enums": {
- "count": 1
- }
- },
"app/components/workflow/operator/add-block.tsx": {
"ts/no-explicit-any": {
"count": 1
@@ -9963,11 +9948,6 @@
"count": 1
}
},
- "app/components/workflow/variable-inspect/types.ts": {
- "erasable-syntax-only/enums": {
- "count": 2
- }
- },
"app/components/workflow/variable-inspect/utils.tsx": {
"ts/no-explicit-any": {
"count": 2
@@ -10587,11 +10567,6 @@
"count": 3
}
},
- "types/model-provider.ts": {
- "erasable-syntax-only/enums": {
- "count": 1
- }
- },
"types/pipeline.tsx": {
"ts/no-explicit-any": {
"count": 3
@@ -10603,9 +10578,6 @@
}
},
"types/workflow.ts": {
- "erasable-syntax-only/enums": {
- "count": 1
- },
"ts/no-explicit-any": {
"count": 17
}
diff --git a/web/eslint.config.mjs b/web/eslint.config.mjs
index b97fb503ffa..940aad9f4cf 100644
--- a/web/eslint.config.mjs
+++ b/web/eslint.config.mjs
@@ -41,6 +41,7 @@ export default antfu(
overrides: {
'ts/consistent-type-definitions': ['error', 'type'],
'ts/no-explicit-any': 'error',
+ 'ts/no-redeclare': 'off',
},
erasableOnly: true,
},
diff --git a/web/types/model-provider.ts b/web/types/model-provider.ts
index b98cc624410..7be0ccc58f2 100644
--- a/web/types/model-provider.ts
+++ b/web/types/model-provider.ts
@@ -2,12 +2,13 @@
* Model provider quota types - shared type definitions for API responses
* These represent the provider identifiers that support paid/trial quotas
*/
-export enum ModelProviderQuotaGetPaid {
- ANTHROPIC = 'langgenius/anthropic/anthropic',
- OPENAI = 'langgenius/openai/openai',
- // AZURE_OPENAI = 'langgenius/azure_openai/azure_openai',
- GEMINI = 'langgenius/gemini/google',
- X = 'langgenius/x/x',
- DEEPSEEK = 'langgenius/deepseek/deepseek',
- TONGYI = 'langgenius/tongyi/tongyi',
-}
+export const ModelProviderQuotaGetPaid = {
+ ANTHROPIC: 'langgenius/anthropic/anthropic',
+ OPENAI: 'langgenius/openai/openai',
+ // AZURE_OPENAI: 'langgenius/azure_openai/azure_openai',
+ GEMINI: 'langgenius/gemini/google',
+ X: 'langgenius/x/x',
+ DEEPSEEK: 'langgenius/deepseek/deepseek',
+ TONGYI: 'langgenius/tongyi/tongyi',
+} as const
+export type ModelProviderQuotaGetPaid = typeof ModelProviderQuotaGetPaid[keyof typeof ModelProviderQuotaGetPaid]
diff --git a/web/types/workflow.ts b/web/types/workflow.ts
index f8a53c8d7ef..5c39246ee0d 100644
--- a/web/types/workflow.ts
+++ b/web/types/workflow.ts
@@ -455,12 +455,13 @@ export type PanelProps = {
export type NodeRunResult = NodeTracing
// Var Inspect
-export enum VarInInspectType {
- conversation = 'conversation',
- environment = 'env',
- node = 'node',
- system = 'sys',
-}
+export const VarInInspectType = {
+ conversation: 'conversation',
+ environment: 'env',
+ node: 'node',
+ system: 'sys',
+} as const
+export type VarInInspectType = typeof VarInInspectType[keyof typeof VarInInspectType]
export type FullContent = {
size_bytes: number