Browse Source

init:agent task step & startTask

未来全栈 4 months ago
parent
commit
d3f12da960
7 changed files with 870 additions and 28 deletions
  1. 641 14
      package-lock.json
  2. 1 0
      package.json
  3. 6 0
      src/agent/README.md
  4. 17 0
      src/agent/agent.start.ts
  5. 86 0
      src/agent/agent.task.ts
  6. 25 7
      src/app/tab1/tab1.page.html
  7. 94 7
      src/app/tab1/tab1.page.ts

File diff suppressed because it is too large
+ 641 - 14
package-lock.json


+ 1 - 0
package.json

@@ -27,6 +27,7 @@
     "@capacitor/keyboard": "6.0.3",
     "@capacitor/status-bar": "6.0.2",
     "@ionic/angular": "^8.0.0",
+    "fmode-ng": "^0.0.62",
     "ionicons": "^7.2.1",
     "rxjs": "~7.8.0",
     "tslib": "^2.3.0",

+ 6 - 0
src/agent/README.md

@@ -0,0 +1,6 @@
+
+
+# 技术设计
+- AgentTaskStep类 智能体任务的某一个步骤(简单任务)
+- TaskExecutor类 任务执行器
+- AgentTaskComponent类 展示任务进行进度的面板

+ 17 - 0
src/agent/agent.start.ts

@@ -0,0 +1,17 @@
+import { AgentTaskStep } from "./agent.task";
+
+/**
+ * 任务执行函数
+ */
+export async function startTask(taskStepList:AgentTaskStep[]){
+
+for (let index = 0; index < taskStepList.length; index++) {
+    let step = taskStepList[index];
+    let result = await step.handle()
+    if(result == false) {break;} 
+    if(!step.error){ // 任务执行正常,无Error
+
+    }
+}
+
+}

+ 86 - 0
src/agent/agent.task.ts

@@ -0,0 +1,86 @@
+
+// 任务步骤初始化参数
+interface AgentTaskStepOptions{
+    title:string
+    shareData?:any
+    handle?():{():Promise<any>}
+}
+
+export class AgentTaskStep{
+    // 任务名称
+    title:string = ""
+
+    // 任务数据 共享数据(整个任务集共享传递的数据)
+    shareData:any = {}
+    // 任务数据 私有数据(当前任务私有的处理数据)
+    data:any = {}
+
+    // 父级组件:任务集组件
+    // @example 当前子任务未完成,且当前任务是必须时,需要在当前任务中,终止整个程序
+    parentComp:any|undefined
+    // 当前任务在任务集数组中的项目
+    parentIndex:number|undefined
+
+    /**
+     * 任务生命周期
+     * @constructor // 构造时执行一次
+     * @onInit // 初始化后执行一次
+     * @onProgress // 进度变化时执行一次
+     * @onComplete // 完成前执行一次
+     */
+    constructor(metaData:AgentTaskStepOptions){
+        this.title = metaData.title
+        this.shareData = metaData.shareData
+        if(metaData.handle){
+            this.handle = metaData.handle
+        }
+        this.init(metaData)
+    }
+    onInit(step:AgentTaskStep){
+        this.isInit = true;
+    }
+    beforeHandle(step:AgentTaskStep){
+
+    }
+    afterHandle(step:AgentTaskStep){
+
+    }
+    onProgress(step:AgentTaskStep){
+
+    }
+    onComplete(step:AgentTaskStep){
+
+    }
+    onError(step:AgentTaskStep){
+
+    }
+
+    /**
+     * 任务初始化函数
+     */
+    async init(metaData:AgentTaskStepOptions){
+    }
+    isInit:boolean = false; // 是否初始化
+
+    /** 
+     * 任务执行函数
+     * @desc 函数内必须有明确的完成、结束情形,函数内必须有进度的变化指示 从0.00 - 1.00
+     */
+    progress:number = 0;
+    handle():Promise<any>|any{
+        this.beforeHandle(this)
+
+
+
+
+
+        this.onComplete(this)
+        this.onError(this)
+        return true
+    }
+
+    /**
+     * 任务错误提示
+     */
+    error:string = "" // 错误原因
+}

+ 25 - 7
src/app/tab1/tab1.page.html

@@ -1,17 +1,35 @@
 <ion-header [translucent]="true">
   <ion-toolbar>
     <ion-title>
-      Tab 1
+      任务集执行展示
     </ion-title>
   </ion-toolbar>
 </ion-header>
 
 <ion-content [fullscreen]="true">
-  <ion-header collapse="condense">
-    <ion-toolbar>
-      <ion-title size="large">Tab 1</ion-title>
-    </ion-toolbar>
-  </ion-header>
+ <ion-button (click)="doInqueryTask()">执行问诊任务集</ion-button>
 
-  <app-explore-container name="Tab 1 page"></app-explore-container>
+ <ul>
+  @for(step of taskList;track step.title;){
+    <div>
+      <!-- 待开始 -->
+      @if(step.progress==0){
+        <ion-icon name="radio-button-off-outline"></ion-icon>
+      }
+      <!-- 进行中 -->
+      @if(step.progress!=0 && step.progress!=1){
+        <ion-icon name="reload-outline"></ion-icon>
+      }
+      <!-- 已完成 -->
+      @if(step.progress==1){
+        <ion-icon name="checkmark-circle-outline"></ion-icon>
+      }
+      <!-- 已出错 -->
+      @if(step.error){
+        <ion-icon name="close-circle-outline"></ion-icon>
+      }
+      {{step.title}} {{step.progress}}
+    </div>   
+  }
+  </ul>
 </ion-content>

+ 94 - 7
src/app/tab1/tab1.page.ts

@@ -1,14 +1,101 @@
-import { Component } from '@angular/core';
-import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
-import { ExploreContainerComponent } from '../explore-container/explore-container.component';
-
+import { Component,OnInit } from '@angular/core';
+import { IonHeader, IonToolbar, IonTitle, IonContent, IonButton,IonIcon } from '@ionic/angular/standalone';
+import { AgentTaskStep } from 'src/agent/agent.task';
+import { addIcons } from 'ionicons';
+import { radioButtonOffOutline, reloadOutline, checkmarkCircleOutline, closeCircleOutline } from 'ionicons/icons';
+import { startTask } from 'src/agent/agent.start';
+addIcons({radioButtonOffOutline,reloadOutline,checkmarkCircleOutline,closeCircleOutline})
 @Component({
   selector: 'app-tab1',
   templateUrl: 'tab1.page.html',
   styleUrls: ['tab1.page.scss'],
   standalone: true,
-  imports: [IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent],
+  imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonButton,
+    IonIcon
+  ],
 })
-export class Tab1Page {
-  constructor() {}
+export class Tab1Page  {
+
+
+  constructor() {
+
+
+  }
+
+  taskList:AgentTaskStep[] = []
+
+  wait(duration:number=1000){
+    return new Promise(resolve=>{
+      setTimeout(() => {
+          resolve(true)
+      }, duration);
+    })
+  }
+
+  shareData:any = {}
+
+  doPoemTask(){
+    let task1 = new AgentTaskStep({title:"意境分析",shareData:this.shareData})
+    task1.handle = async ()=>{
+      await this.wait(1000)
+      console.log("意境分析:执行过程")
+      task1.progress = 1
+    }
+    let task2 = new AgentTaskStep({title:"意境绘制",shareData:this.shareData})
+    task2.handle = async ()=>{
+      await this.wait(1000)
+      console.log("意境绘制:执行过程")
+      task2.progress = 1
+    }
+    
+    // 定义任务集
+    let PoemTaskList = [task1,task2]
+    // 传递给显示组件
+    this.taskList = PoemTaskList
+    // 开始执行任务
+    startTask(PoemTaskList)
+  }
+
+  doInqueryTask(){
+    let task1 = new AgentTaskStep({title:"导诊",shareData:this.shareData})
+    task1.handle = async ()=>{
+      await this.wait(1000)
+      console.log("导诊:执行过程")
+      task1.progress = 1
+    }
+    let task2 = new AgentTaskStep({title:"问诊",shareData:this.shareData})
+    task2.handle = async ()=>{
+      await this.wait(1000)
+      console.log("问诊:执行过程")
+      task2.progress = 1
+    }
+    let task3 = new AgentTaskStep({title:"初诊",shareData:this.shareData})
+    task3.handle = async ()=>{
+      await this.wait(1000)
+      console.log("初诊:执行过程")
+      task3.progress = 1
+    }
+    let task4 = new AgentTaskStep({title:"检验",shareData:this.shareData})
+    task4.handle = async ()=>{
+      await this.wait(1000)
+      console.log("检验:执行过程")
+      task4.progress = 1
+    }
+    let task5 = new AgentTaskStep({title:"处方",shareData:this.shareData})
+    task5.handle = async ()=>{
+      console.log("处方:执行过程")
+      task5.progress = 1
+    }
+
+    // 定义任务集
+    let InquireServiceTaskList = [task1,task2,task3,task4,task5]
+    // 传递给显示组件
+    this.taskList = InquireServiceTaskList
+    // 开始执行任务
+    startTask(InquireServiceTaskList)
+  }
+
+
+
+
 }

Some files were not shown because too many files changed in this diff