StepsDisplay.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <div class="steps-display-container">
  3. <div v-if="parsedContent" class="steps-content">
  4. <h2 class="steps-title">{{ parsedContent.title }}</h2>
  5. <!-- <p class="steps-id">计划ID: {{ parsedContent.planId }}</p> -->
  6. <el-steps
  7. :active="-1"
  8. finish-status="success"
  9. class="custom-steps"
  10. direction="vertical"
  11. >
  12. <el-step
  13. v-for="(step, index) in parsedContent.steps"
  14. :key="index"
  15. :title="'步骤 ' + (index + 1)"
  16. >
  17. <template #icon>
  18. <div class="step-icon-container" >
  19. <div v-if="index < activeStep" class="step-icon completed">
  20. <el-icon><Check /></el-icon>
  21. </div>
  22. <!-- <div v-else-if="index === activeStep" class="step-icon current">-->
  23. <!-- <el-icon><Loading /></el-icon>-->
  24. <!-- </div>-->
  25. <div v-else style="border-radius: 50%;">
  26. {{ index + 1 }}
  27. </div>
  28. </div>
  29. </template>
  30. <template #title>
  31. <div class="step-title-container" @click.stop="toggleCollapse(index)" >
  32. <span>步骤 {{ index + 1 }}</span>
  33. <el-button
  34. type="text"
  35. class="collapse-button"
  36. >
  37. <el-icon>
  38. <component :is="collapsedSteps[index] ? 'ArrowDown' : 'ArrowUp'"></component>
  39. </el-icon>
  40. </el-button>
  41. </div>
  42. </template>
  43. <template #description>
  44. <div :class="['step-description',{ 'collapsed': collapsedSteps[index] }]" >
  45. <div class="step-content" >
  46. {{ step.description }}
  47. <div v-if="response?.agentExecutionSequence[index]?.thinkActSteps" >
  48. <div v-for="item,i in response.agentExecutionSequence[index]?.thinkActSteps" >
  49. <div v-if="item?.toolParameters?.action !=='get_text'">
  50. <div v-if="item?.toolName === 'browser_use' ">{{ item.actionResult?.output}}</div>
  51. <div v-if="item?.toolName === 'terminate'" v-html="formatMessage(item.thinkOutput)"></div>
  52. <div class="timestamp ">{{ moment(item?.actEndTime).format('MM-DD HH:mm:ss') }}</div>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. </template>
  59. </el-step>
  60. </el-steps>
  61. <!--
  62. <div class="steps-controls">
  63. <el-button
  64. type="primary"
  65. size="small"
  66. @click="prevStep"
  67. :disabled="activeStep <= 0"
  68. >
  69. 上一步
  70. </el-button>
  71. <el-button
  72. type="primary"
  73. size="small"
  74. @click="nextStep"
  75. :disabled="activeStep >= parsedContent.steps.length"
  76. >
  77. 下一步
  78. </el-button>
  79. <el-button
  80. type="success"
  81. size="small"
  82. @click="completeAll"
  83. :disabled="activeStep >= parsedContent.steps.length"
  84. >
  85. 完成所有
  86. </el-button>
  87. </div> -->
  88. </div>
  89. <div v-else class="error-message">
  90. <el-alert
  91. title="内容格式错误"
  92. type="error"
  93. description="无法解析传入的内容,请检查格式是否正确"
  94. show-icon
  95. />
  96. </div>
  97. </div>
  98. </template>
  99. <script lang="ts" setup>
  100. chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
  101. console.log(request,258);
  102. if (request.type == 'FROM_STEP') {
  103. initialSteps.value = request.payloa
  104. console.log(request,123);
  105. }
  106. return true
  107. })
  108. import { ref, computed, onMounted, watch, onBeforeUnmount } from 'vue'
  109. import { ChatDotRound, Check, Loading, ArrowDown, ArrowUp } from '@element-plus/icons-vue'
  110. import { deleteExecutor, executePlanByTemplateId, executorDetail } from '@/api/advance'
  111. import moment from 'moment'
  112. import { formatMessage } from '../utils/ai-service'
  113. const initialSteps=ref(0)
  114. // 定义props
  115. const props = defineProps({
  116. content: {
  117. type: [String, Object],
  118. required: true
  119. },
  120. initialStep: {
  121. type: Number,
  122. default: 0
  123. }
  124. })
  125. // 定义事件
  126. const emit = defineEmits(['step-change', 'complete'])
  127. // 当前激活的步骤
  128. const activeStep = ref(props.initialStep)
  129. // 步骤折叠状态
  130. const collapsedSteps = ref([])
  131. const planTemplateId = ref('')
  132. const planId = ref('')
  133. const currentStepIndex = ref()
  134. const response = ref()
  135. const handleExecute = async () => {
  136. const res = await executorDetail(planId.value) as any
  137. response.value = res
  138. response.value?.agentExecutionSequence.forEach((sequence: any) => {
  139. if (sequence.thinkActSteps) {
  140. sequence.thinkActSteps.forEach((step:any) => {
  141. // 转换actionResult
  142. if (step.actionResult && typeof step.actionResult === 'string') {
  143. step.actionResult = JSON.parse(step.actionResult);
  144. }
  145. // 转换toolParametersJSON
  146. if (step.toolParameters && typeof step.toolParameters === 'string') {
  147. step.toolParameters = JSON.parse(step.toolParameters);
  148. }
  149. });
  150. }
  151. });
  152. if (res.currentStepIndex) {
  153. if (currentStepIndex.value !== res.currentStepIndex) {
  154. collapsedSteps.value[currentStepIndex.value] = !collapsedSteps.value[currentStepIndex.value]
  155. collapsedSteps.value[res.currentStepIndex] = false
  156. activeStep.value++
  157. }
  158. currentStepIndex.value = res.currentStepIndex
  159. }
  160. if (!res.completed) setTimeout(() => {
  161. handleExecute()
  162. }, 2000);
  163. else {
  164. activeStep.value++
  165. deleteExecutor(planId.value)
  166. }
  167. }
  168. // 解析内容
  169. const parsedContent = computed(() => {
  170. console.log(props.content);
  171. try {
  172. if (typeof props.content === 'string') {
  173. const obj = JSON.parse(props.content)
  174. obj.steps = obj.steps.map((_:any )=> ({ ..._, description: _.description.split(' ')[1] }))
  175. planTemplateId.value = obj.planId
  176. currentStepIndex.value = 0
  177. // setTimeout(() => {
  178. // executePlanByTemplateId({ planTemplateId: planTemplateId.value }).then(res => {
  179. // planId.value = res.planId
  180. // setTimeout(() => {
  181. // handleExecute()
  182. // }, 2000);
  183. // })
  184. // }, 1000);
  185. return obj
  186. } else {
  187. return props.content
  188. }
  189. } catch (error) {
  190. console.error('解析内容失败:', error)
  191. return null
  192. }
  193. })
  194. // 初始化折叠状态
  195. watch(() => parsedContent.value, (newContent) => {
  196. if (newContent && newContent.steps) {
  197. // 默认所有步骤都展开,当前步骤之外的都折叠
  198. collapsedSteps.value = newContent.steps.map((_:any, index:any) => index !== activeStep.value)
  199. }
  200. }, { immediate: true })
  201. // 切换步骤折叠状态
  202. const toggleCollapse = (index:any) => {
  203. collapsedSteps.value[index] = !collapsedSteps.value[index]
  204. }
  205. watch(() => props.content, () => {
  206. }, { deep: true })
  207. // 组件挂载时初始化
  208. onMounted(() => {
  209. if (activeStep.value > 0 && parsedContent.value) {
  210. emit('step-change', activeStep.value)
  211. }
  212. })
  213. </script>
  214. <style scoped>
  215. .steps-display-container {
  216. padding: 20px;
  217. background-color: #fff;
  218. border-radius: 8px;
  219. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  220. }
  221. .steps-title {
  222. font-size: 18px;
  223. font-weight: bold;
  224. margin-bottom: 8px;
  225. color: #303133;
  226. }
  227. .steps-id {
  228. font-size: 14px;
  229. color: #909399;
  230. margin-bottom: 20px;
  231. }
  232. .custom-steps {
  233. margin: 20px 0;
  234. }
  235. .steps-controls {
  236. display: flex;
  237. gap: 10px;
  238. margin-top: 20px;
  239. justify-content: flex-end;
  240. }
  241. .error-message {
  242. margin: 20px 0;
  243. }
  244. :deep(.el-step__title) {
  245. font-weight: bold;
  246. }
  247. :deep(.el-step__description) {
  248. font-size: 14px;
  249. white-space: pre-wrap;
  250. word-break: break-word;
  251. }
  252. :deep(.el-step__icon) {
  253. background-color: #f5f7fa;
  254. }
  255. .timestamp {
  256. display: flex;
  257. justify-content: space-between;
  258. font-size: 12px;
  259. color: #909399;
  260. margin-top: 6px;
  261. }
  262. :deep(.el-step.is-success .el-step__icon) {
  263. background-color: #67c23a;
  264. color: white;
  265. }
  266. :deep(.el-step.is-process .el-step__icon) {
  267. background-color: #409eff;
  268. color: white;
  269. }
  270. /* 步骤标题容器 */
  271. .step-title-container {
  272. display: flex;
  273. align-items: center;
  274. justify-content: space-between;
  275. width: 100%;
  276. cursor: pointer;
  277. }
  278. /* 折叠按钮 */
  279. .collapse-button {
  280. margin-left: 8px;
  281. padding: 2px;
  282. font-size: 12px;
  283. }
  284. /* 步骤描述 */
  285. .step-description {
  286. transition: all 0.3s ease;
  287. transform-origin: top center;
  288. overflow: hidden;
  289. }
  290. .collapsed {
  291. height: 0;
  292. /* overflow: hidden; */
  293. }
  294. /* 步骤内容 */
  295. .step-content {
  296. padding: 8px 0;
  297. }
  298. /* 步骤进度条样式 */
  299. .step-progress {
  300. margin-top: 10px;
  301. display: flex;
  302. align-items: center;
  303. }
  304. .progress-text {
  305. margin-left: 8px;
  306. font-size: 12px;
  307. color: #409eff;
  308. font-weight: bold;
  309. transition: all 0.3s;
  310. }
  311. /* 自定义步骤图标 */
  312. .step-icon-container {
  313. display: flex;
  314. justify-content: center;
  315. align-items: center;
  316. width: 100%;
  317. height: 100%;
  318. }
  319. .step-icon {
  320. display: flex;
  321. justify-content: center;
  322. align-items: center;
  323. width: 24px;
  324. height: 24px;
  325. border-radius: 50%;
  326. background-color: #f5f7fa;
  327. color: #909399;
  328. }
  329. .step-icon.current {
  330. background-color: #409eff;
  331. color: white;
  332. animation: rotate 2s linear infinite, pulse 1.5s infinite;
  333. }
  334. .step-icon.completed {
  335. background-color: #67c23a;
  336. color: white;
  337. }
  338. /* 自定义进度条 */
  339. .progress-bar-container {
  340. position: relative;
  341. width: 100%;
  342. height: 8px;
  343. background-color: #f5f7fa;
  344. border-radius: 4px;
  345. overflow: hidden;
  346. margin-right: 10px;
  347. flex-grow: 1;
  348. }
  349. .progress-bar-background {
  350. position: absolute;
  351. top: 0;
  352. left: 0;
  353. width: 100%;
  354. height: 100%;
  355. background: linear-gradient(90deg, #f5f7fa 0%, #e4e7ed 100%);
  356. opacity: 0.5;
  357. }
  358. .progress-bar-fill {
  359. position: absolute;
  360. top: 0;
  361. left: 0;
  362. height: 100%;
  363. background: linear-gradient(90deg, #409eff 0%, #95d0ff 100%);
  364. border-radius: 4px;
  365. transition: width 0.2s ease-out;
  366. box-shadow: 0 0 5px rgba(64, 158, 255, 0.5);
  367. }
  368. .progress-bar-glow {
  369. position: absolute;
  370. top: 0;
  371. width: 20px;
  372. height: 100%;
  373. background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.8) 50%, rgba(255, 255, 255, 0) 100%);
  374. transform: translateX(-50%);
  375. animation: shimmer 1.5s infinite;
  376. }
  377. @keyframes pulse {
  378. 0% {
  379. box-shadow: 0 0 0 0 rgba(64, 158, 255, 0.4);
  380. }
  381. 70% {
  382. box-shadow: 0 0 0 10px rgba(64, 158, 255, 0);
  383. }
  384. 100% {
  385. box-shadow: 0 0 0 0 rgba(64, 158, 255, 0);
  386. }
  387. }
  388. @keyframes rotate {
  389. 0% {
  390. transform: rotate(0);
  391. }
  392. 100% {
  393. transform: rotate(360deg);
  394. }
  395. }
  396. @keyframes shimmer {
  397. 0% {
  398. opacity: 0.3;
  399. }
  400. 50% {
  401. opacity: 0.7;
  402. }
  403. 100% {
  404. opacity: 0.3;
  405. }
  406. }
  407. :deep(.el-step__icon) {
  408. border-radius: 50%;
  409. }
  410. </style>