StepsDisplay.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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(async (request, sender, sendResponse) => {
  101. if (request.type == 'FROM_STEP') {
  102. initialSteps.value = request.payload
  103. }
  104. })
  105. import { ref, computed, onMounted, watch, onBeforeUnmount } from 'vue'
  106. import { ChatDotRound, Check, Loading, ArrowDown, ArrowUp } from '@element-plus/icons-vue'
  107. import { deleteExecutor, executePlanByTemplateId, executorDetail } from '@/api/advance'
  108. import moment from 'moment'
  109. import { formatMessage } from '../utils/ai-service'
  110. const initialSteps=ref(0)
  111. // 定义props
  112. const props = defineProps({
  113. content: {
  114. type: [String, Object],
  115. required: true
  116. },
  117. initialStep: {
  118. type: Number,
  119. default: 0
  120. }
  121. })
  122. // 定义事件
  123. const emit = defineEmits(['step-change', 'complete'])
  124. // 当前激活的步骤
  125. const activeStep = ref(props.initialStep)
  126. // 步骤折叠状态
  127. const collapsedSteps = ref([])
  128. const planTemplateId = ref('')
  129. const planId = ref('')
  130. const currentStepIndex = ref()
  131. const response = ref()
  132. const handleExecute = async () => {
  133. const res = await executorDetail(planId.value) as any
  134. response.value = res
  135. response.value?.agentExecutionSequence.forEach((sequence: any) => {
  136. if (sequence.thinkActSteps) {
  137. sequence.thinkActSteps.forEach((step:any) => {
  138. // 转换actionResult
  139. if (step.actionResult && typeof step.actionResult === 'string') {
  140. step.actionResult = JSON.parse(step.actionResult);
  141. }
  142. // 转换toolParametersJSON
  143. if (step.toolParameters && typeof step.toolParameters === 'string') {
  144. step.toolParameters = JSON.parse(step.toolParameters);
  145. }
  146. });
  147. }
  148. });
  149. if (res.currentStepIndex) {
  150. if (currentStepIndex.value !== res.currentStepIndex) {
  151. collapsedSteps.value[currentStepIndex.value] = !collapsedSteps.value[currentStepIndex.value]
  152. collapsedSteps.value[res.currentStepIndex] = false
  153. activeStep.value++
  154. }
  155. currentStepIndex.value = res.currentStepIndex
  156. }
  157. if (!res.completed) setTimeout(() => {
  158. handleExecute()
  159. }, 2000);
  160. else {
  161. activeStep.value++
  162. deleteExecutor(planId.value)
  163. }
  164. }
  165. // 解析内容
  166. const parsedContent = computed(() => {
  167. try {
  168. if (typeof props.content === 'string') {
  169. const obj = JSON.parse(props.content)
  170. obj.steps = obj.steps.map((_:any )=> ({ ..._, description: _.description.split(' ')[1] }))
  171. planTemplateId.value = obj.planId
  172. currentStepIndex.value = 0
  173. // setTimeout(() => {
  174. // executePlanByTemplateId({ planTemplateId: planTemplateId.value }).then(res => {
  175. // planId.value = res.planId
  176. // setTimeout(() => {
  177. // handleExecute()
  178. // }, 2000);
  179. // })
  180. // }, 1000);
  181. return obj
  182. } else {
  183. return props.content
  184. }
  185. } catch (error) {
  186. console.error('解析内容失败:', error)
  187. return null
  188. }
  189. })
  190. // 初始化折叠状态
  191. watch(() => parsedContent.value, (newContent) => {
  192. if (newContent && newContent.steps) {
  193. // 默认所有步骤都展开,当前步骤之外的都折叠
  194. collapsedSteps.value = newContent.steps.map((_:any, index:any) => index !== activeStep.value)
  195. }
  196. }, { immediate: true })
  197. // 切换步骤折叠状态
  198. const toggleCollapse = (index:any) => {
  199. collapsedSteps.value[index] = !collapsedSteps.value[index]
  200. }
  201. watch(() => props.content, () => {
  202. }, { deep: true })
  203. // 组件挂载时初始化
  204. onMounted(() => {
  205. if (activeStep.value > 0 && parsedContent.value) {
  206. emit('step-change', activeStep.value)
  207. }
  208. })
  209. </script>
  210. <style scoped>
  211. .steps-display-container {
  212. padding: 20px;
  213. background-color: #fff;
  214. border-radius: 8px;
  215. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  216. }
  217. .steps-title {
  218. font-size: 18px;
  219. font-weight: bold;
  220. margin-bottom: 8px;
  221. color: #303133;
  222. }
  223. .steps-id {
  224. font-size: 14px;
  225. color: #909399;
  226. margin-bottom: 20px;
  227. }
  228. .custom-steps {
  229. margin: 20px 0;
  230. }
  231. .steps-controls {
  232. display: flex;
  233. gap: 10px;
  234. margin-top: 20px;
  235. justify-content: flex-end;
  236. }
  237. .error-message {
  238. margin: 20px 0;
  239. }
  240. :deep(.el-step__title) {
  241. font-weight: bold;
  242. }
  243. :deep(.el-step__description) {
  244. font-size: 14px;
  245. white-space: pre-wrap;
  246. word-break: break-word;
  247. }
  248. :deep(.el-step__icon) {
  249. background-color: #f5f7fa;
  250. }
  251. .timestamp {
  252. display: flex;
  253. justify-content: space-between;
  254. font-size: 12px;
  255. color: #909399;
  256. margin-top: 6px;
  257. }
  258. :deep(.el-step.is-success .el-step__icon) {
  259. background-color: #67c23a;
  260. color: white;
  261. }
  262. :deep(.el-step.is-process .el-step__icon) {
  263. background-color: #409eff;
  264. color: white;
  265. }
  266. /* 步骤标题容器 */
  267. .step-title-container {
  268. display: flex;
  269. align-items: center;
  270. justify-content: space-between;
  271. width: 100%;
  272. cursor: pointer;
  273. }
  274. /* 折叠按钮 */
  275. .collapse-button {
  276. margin-left: 8px;
  277. padding: 2px;
  278. font-size: 12px;
  279. }
  280. /* 步骤描述 */
  281. .step-description {
  282. transition: all 0.3s ease;
  283. transform-origin: top center;
  284. overflow: hidden;
  285. }
  286. .collapsed {
  287. height: 0;
  288. /* overflow: hidden; */
  289. }
  290. /* 步骤内容 */
  291. .step-content {
  292. padding: 8px 0;
  293. }
  294. /* 步骤进度条样式 */
  295. .step-progress {
  296. margin-top: 10px;
  297. display: flex;
  298. align-items: center;
  299. }
  300. .progress-text {
  301. margin-left: 8px;
  302. font-size: 12px;
  303. color: #409eff;
  304. font-weight: bold;
  305. transition: all 0.3s;
  306. }
  307. /* 自定义步骤图标 */
  308. .step-icon-container {
  309. display: flex;
  310. justify-content: center;
  311. align-items: center;
  312. width: 100%;
  313. height: 100%;
  314. }
  315. .step-icon {
  316. display: flex;
  317. justify-content: center;
  318. align-items: center;
  319. width: 24px;
  320. height: 24px;
  321. border-radius: 50%;
  322. background-color: #f5f7fa;
  323. color: #909399;
  324. }
  325. .step-icon.current {
  326. background-color: #409eff;
  327. color: white;
  328. animation: rotate 2s linear infinite, pulse 1.5s infinite;
  329. }
  330. .step-icon.completed {
  331. background-color: #67c23a;
  332. color: white;
  333. }
  334. /* 自定义进度条 */
  335. .progress-bar-container {
  336. position: relative;
  337. width: 100%;
  338. height: 8px;
  339. background-color: #f5f7fa;
  340. border-radius: 4px;
  341. overflow: hidden;
  342. margin-right: 10px;
  343. flex-grow: 1;
  344. }
  345. .progress-bar-background {
  346. position: absolute;
  347. top: 0;
  348. left: 0;
  349. width: 100%;
  350. height: 100%;
  351. background: linear-gradient(90deg, #f5f7fa 0%, #e4e7ed 100%);
  352. opacity: 0.5;
  353. }
  354. .progress-bar-fill {
  355. position: absolute;
  356. top: 0;
  357. left: 0;
  358. height: 100%;
  359. background: linear-gradient(90deg, #409eff 0%, #95d0ff 100%);
  360. border-radius: 4px;
  361. transition: width 0.2s ease-out;
  362. box-shadow: 0 0 5px rgba(64, 158, 255, 0.5);
  363. }
  364. .progress-bar-glow {
  365. position: absolute;
  366. top: 0;
  367. width: 20px;
  368. height: 100%;
  369. background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.8) 50%, rgba(255, 255, 255, 0) 100%);
  370. transform: translateX(-50%);
  371. animation: shimmer 1.5s infinite;
  372. }
  373. @keyframes pulse {
  374. 0% {
  375. box-shadow: 0 0 0 0 rgba(64, 158, 255, 0.4);
  376. }
  377. 70% {
  378. box-shadow: 0 0 0 10px rgba(64, 158, 255, 0);
  379. }
  380. 100% {
  381. box-shadow: 0 0 0 0 rgba(64, 158, 255, 0);
  382. }
  383. }
  384. @keyframes rotate {
  385. 0% {
  386. transform: rotate(0);
  387. }
  388. 100% {
  389. transform: rotate(360deg);
  390. }
  391. }
  392. @keyframes shimmer {
  393. 0% {
  394. opacity: 0.3;
  395. }
  396. 50% {
  397. opacity: 0.7;
  398. }
  399. 100% {
  400. opacity: 0.3;
  401. }
  402. }
  403. :deep(.el-step__icon) {
  404. border-radius: 50%;
  405. }
  406. </style>