|
@@ -0,0 +1,92 @@
|
|
|
+import { Component } from '@angular/core';
|
|
|
+import {
|
|
|
+ IonButton,
|
|
|
+ IonCard,
|
|
|
+ IonCardContent,
|
|
|
+ IonContent,
|
|
|
+ IonHeader,
|
|
|
+ IonIcon,
|
|
|
+ IonItem,
|
|
|
+ IonProgressBar,
|
|
|
+ IonTitle,
|
|
|
+ IonToolbar,
|
|
|
+} from '@ionic/angular/standalone';
|
|
|
+import { AgentTaskStep } from 'src/app/agent/agent.task';
|
|
|
+import { addIcons } from 'ionicons';
|
|
|
+import {
|
|
|
+ checkmarkCircleOutline,
|
|
|
+ ellipseOutline,
|
|
|
+ reloadCircleOutline,
|
|
|
+} from 'ionicons/icons';
|
|
|
+addIcons({ ellipseOutline, checkmarkCircleOutline, reloadCircleOutline });
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-taskchain-page',
|
|
|
+ templateUrl: './taskchain-page.component.html',
|
|
|
+ styleUrls: ['./taskchain-page.component.scss'],
|
|
|
+ standalone: true,
|
|
|
+ imports: [
|
|
|
+ IonButton,
|
|
|
+ IonHeader,
|
|
|
+ IonToolbar,
|
|
|
+ IonTitle,
|
|
|
+ IonContent,
|
|
|
+ IonItem,
|
|
|
+ IonCard,
|
|
|
+ IonCardContent,
|
|
|
+ IonProgressBar,
|
|
|
+ IonIcon,
|
|
|
+ ],
|
|
|
+})
|
|
|
+export class TaskchainPageComponent {
|
|
|
+ constructor() {}
|
|
|
+
|
|
|
+ taskList: AgentTaskStep[] = [];
|
|
|
+ wait(duration: number = 1000) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ setInterval(() => {
|
|
|
+ resolve(true);
|
|
|
+ }, duration);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ shareData: any = {};
|
|
|
+ createTask() {
|
|
|
+ let task1 = new AgentTaskStep({
|
|
|
+ title: 'AI扩展更多信息',
|
|
|
+ shareData: this.shareData,
|
|
|
+ });
|
|
|
+ task1.handle = async () => {
|
|
|
+ await this.wait(5000);
|
|
|
+ console.log('AI扩展更多信息,执行中...');
|
|
|
+ task1.progress = 1;
|
|
|
+ };
|
|
|
+
|
|
|
+ let task2 = new AgentTaskStep({
|
|
|
+ title: 'AI生成图片',
|
|
|
+ shareData: this.shareData,
|
|
|
+ });
|
|
|
+ task2.handle = async () => {
|
|
|
+ await this.wait(3000);
|
|
|
+ console.log('AI生成图片,执行中...');
|
|
|
+ task2.progress = 1;
|
|
|
+ };
|
|
|
+
|
|
|
+ this.taskList = [task1, task2];
|
|
|
+ this.AngentExecutor(this.taskList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 任务执行函数
|
|
|
+ */
|
|
|
+ async AngentExecutor(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) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|