Ver código fonte

feat(workflowService): 优化工作流配置获取方式,移除冗余函数并直接使用配置常量

Zhang Yice 1 mês atrás
pai
commit
4baaac5a6e
1 arquivos alterados com 7 adições e 13 exclusões
  1. 7 13
      src/services/workflowService.ts

+ 7 - 13
src/services/workflowService.ts

@@ -76,18 +76,14 @@ interface WorkflowConfig {
76
   apiUrl: string;
76
   apiUrl: string;
77
 }
77
 }
78
 
78
 
79
-/**
80
- * Get Workflow configuration from environment variables
81
- */
82
-const getWorkflowConfig = (): WorkflowConfig => {
83
-  return {
84
-    apiUrl: import.meta.env.VITE_WORKFLOW_PROXY_URL,
85
-  };
79
+const WORKFLOW_TIMEOUT_MS = 150_000;
80
+const workflowConfig: WorkflowConfig = {
81
+  apiUrl: import.meta.env.VITE_WORKFLOW_PROXY_URL,
86
 };
82
 };
83
+const configuredBaseUrl = import.meta.env.VITE_API_BASE_URL;
87
 
84
 
88
 /** Normalize workflow-generated export URLs to the configured backend origin. */
85
 /** Normalize workflow-generated export URLs to the configured backend origin. */
89
 const normalizeExportDownloadUrl = (downloadUrl: string): string => {
86
 const normalizeExportDownloadUrl = (downloadUrl: string): string => {
90
-  const configuredBaseUrl = import.meta.env.VITE_API_BASE_URL;
91
   if (!configuredBaseUrl || !downloadUrl) return downloadUrl;
87
   if (!configuredBaseUrl || !downloadUrl) return downloadUrl;
92
 
88
 
93
   try {
89
   try {
@@ -147,9 +143,7 @@ export const triggerDocumentWorkflow = async (
147
   sessionId: string
143
   sessionId: string
148
 ): Promise<{ content: string; exportRecord?: ExportRecordInfo }> => {
144
 ): Promise<{ content: string; exportRecord?: ExportRecordInfo }> => {
149
   try {
145
   try {
150
-    const config = getWorkflowConfig();
151
-
152
-    if (!config.apiUrl) {
146
+    if (!workflowConfig.apiUrl) {
153
       return { content: '工作流未配置,无法生成文档。请检查前端环境配置。' };
147
       return { content: '工作流未配置,无法生成文档。请检查前端环境配置。' };
154
     }
148
     }
155
 
149
 
@@ -164,7 +158,7 @@ export const triggerDocumentWorkflow = async (
164
     // 1. chatId: 带时间戳的唯一ID,确保每次请求都被视为新请求
158
     // 1. chatId: 带时间戳的唯一ID,确保每次请求都被视为新请求
165
     // 2. sessionId: 原始会话ID,传递给工作流,工作流会将其传递给后端 /api/v1/export/records
159
     // 2. sessionId: 原始会话ID,传递给工作流,工作流会将其传递给后端 /api/v1/export/records
166
     // 3. 后端在创建文档时会使用这个sessionId,确保同一会话的多个文档共用相同的session_id
160
     // 3. 后端在创建文档时会使用这个sessionId,确保同一会话的多个文档共用相同的session_id
167
-    const response = await fetchWithTimeout(config.apiUrl, {
161
+    const response = await fetchWithTimeout(workflowConfig.apiUrl, {
168
       method: 'POST',
162
       method: 'POST',
169
       headers: {
163
       headers: {
170
         'Content-Type': 'application/json',
164
         'Content-Type': 'application/json',
@@ -182,7 +176,7 @@ export const triggerDocumentWorkflow = async (
182
           },
176
           },
183
         ],
177
         ],
184
       } as WorkflowRequest),
178
       } as WorkflowRequest),
185
-    });
179
+    }, WORKFLOW_TIMEOUT_MS);
186
 
180
 
187
     if (!response.ok) {
181
     if (!response.ok) {
188
       const errorText = await response.text();
182
       const errorText = await response.text();