| 
					
				 | 
			
			
				@@ -2,6 +2,7 @@ import { AgentTaskStep } from '../../../agent/agent.task'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { ModalController } from '@ionic/angular/standalone'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { FmodeChatCompletion } from 'fmode-ng'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { extactAndParseJsonFromString } from '../../../agent/agent.json'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { getUserInput } from '../../../agent/agent.input'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 export function TaskAnalyzeRequirements(options:{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     modalCtrl: ModalController, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -16,6 +17,7 @@ export function TaskAnalyzeRequirements(options:{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return new Promise(async (resolve, reject) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const basicInfo = options.shareData.basicInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 第一步:AI分析基本需求 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const promptTemplate = `作为一名专业的学习规划导师,请根据以下信息分析学习需求: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             学习目标:${basicInfo['学习目标']} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             学习时间范围:${basicInfo['学习时间范围']} 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -23,12 +25,13 @@ export function TaskAnalyzeRequirements(options:{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             学习偏好:${basicInfo['学习偏好']} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             当前水平:${basicInfo['当前水平']} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            请给出详细的分析,结果以JSON格式返回: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            请给出分析结果,结果以JSON格式返回: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                "feasibility": "可行性分析", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                "challenges": ["可能遇到的挑战1", "挑战2"], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                "suggestions": ["建议1", "建议2"], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                "prerequisites": ["前置知识/技能1", "前置知识/技能2"] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                "analysis": { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    "feasibility": "可行性分析", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    "challenges": ["可能遇到的挑战1", "挑战2"], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    "suggestions": ["建议1", "建议2"] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }`; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             let completion = new FmodeChatCompletion([ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -36,25 +39,45 @@ export function TaskAnalyzeRequirements(options:{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 {role: "user", content: promptTemplate} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            completion.sendCompletion().subscribe({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                next: (message: any) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (task.progress < 0.5) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        task.progress += 0.1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } else if (task.progress < 0.9) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        task.progress += 0.05; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (message.complete) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        options.shareData.analysis = extactAndParseJsonFromString(message.content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        task.progress = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        resolve(true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                error: (error) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    task.error = "分析失败,请重试"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    resolve(false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 更新进度的辅助函数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const updateProgress = (current: number, target: number, speed: number = 0.05) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (task.progress < target) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    task.progress = Math.min(current + speed, target); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 显示正在分析的状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                task.status = "正在分析基本需求..."; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                await new Promise((resolveCompletion) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    completion.sendCompletion().subscribe({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        next: (message: any) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            updateProgress(task.progress, 0.5); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                             
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            if (message.complete) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                const result = extactAndParseJsonFromString(message.content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                if (!result) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    throw new Error("AI分析结果格式错误"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                options.shareData.analysis = result.analysis; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                resolveCompletion(true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        error: (error) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            throw error; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                task.status = "分析完成"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                task.progress = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                resolve(true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } catch (error: any) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                task.error = error.message || "分析需求时发生错误"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                resolve(false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |