123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
- <template>
- <div class="steps-display-container">
- <div v-if="parsedContent" class="steps-content">
- <h2 class="steps-title">{{ parsedContent.title }}</h2>
- <!-- <p class="steps-id">计划ID: {{ parsedContent.planId }}</p> -->
- <el-steps
- :active="-1"
- finish-status="success"
- class="custom-steps"
- direction="vertical"
- >
- <el-step
- v-for="(step, index) in parsedContent.steps"
- :key="index"
- :title="'步骤 ' + (index + 1)"
- >
- <template #icon>
- <div class="step-icon-container" >
- <div v-if="index < activeStep" class="step-icon completed">
- <el-icon><Check /></el-icon>
- </div>
- <!-- <div v-else-if="index === activeStep" class="step-icon current">-->
- <!-- <el-icon><Loading /></el-icon>-->
- <!-- </div>-->
- <div v-else style="border-radius: 50%;">
- {{ index + 1 }}
- </div>
- </div>
- </template>
- <template #title>
- <div class="step-title-container" @click.stop="toggleCollapse(index)" >
- <span>步骤 {{ index + 1 }}</span>
- <el-button
- type="text"
- class="collapse-button"
-
- >
- <el-icon>
- <component :is="collapsedSteps[index] ? 'ArrowDown' : 'ArrowUp'"></component>
- </el-icon>
- </el-button>
- </div>
- </template>
- <template #description>
- <div :class="['step-description',{ 'collapsed': collapsedSteps[index] }]" >
- <div class="step-content" >
- {{ step.description }}
- <div v-if="response?.agentExecutionSequence[index]?.thinkActSteps" >
- <div v-for="item,i in response.agentExecutionSequence[index]?.thinkActSteps" >
- <div v-if="item?.toolParameters?.action !=='get_text'">
- <div v-if="item?.toolName === 'browser_use' ">{{ item.actionResult?.output}}</div>
- <div v-if="item?.toolName === 'terminate'" v-html="formatMessage(item.thinkOutput)"></div>
- <div class="timestamp ">{{ moment(item?.actEndTime).format('MM-DD HH:mm:ss') }}</div>
- </div>
-
- </div>
- </div>
-
- </div>
- </div>
- </template>
- </el-step>
- </el-steps>
- <!--
- <div class="steps-controls">
- <el-button
- type="primary"
- size="small"
- @click="prevStep"
- :disabled="activeStep <= 0"
- >
- 上一步
- </el-button>
- <el-button
- type="primary"
- size="small"
- @click="nextStep"
- :disabled="activeStep >= parsedContent.steps.length"
- >
- 下一步
- </el-button>
- <el-button
- type="success"
- size="small"
- @click="completeAll"
- :disabled="activeStep >= parsedContent.steps.length"
- >
- 完成所有
- </el-button>
- </div> -->
- </div>
- <div v-else class="error-message">
- <el-alert
- title="内容格式错误"
- type="error"
- description="无法解析传入的内容,请检查格式是否正确"
- show-icon
- />
- </div>
- </div>
- </template>
- <script lang="ts" setup>
- chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
- if (request.type == 'FROM_STEP') {
- initialSteps.value = request.payload
- }
- })
- import { ref, computed, onMounted, watch, onBeforeUnmount } from 'vue'
- import { ChatDotRound, Check, Loading, ArrowDown, ArrowUp } from '@element-plus/icons-vue'
- import { deleteExecutor, executePlanByTemplateId, executorDetail } from '@/api/advance'
- import moment from 'moment'
- import { formatMessage } from '../utils/ai-service'
- const initialSteps=ref(0)
- // 定义props
- const props = defineProps({
- content: {
- type: [String, Object],
- required: true
- },
- initialStep: {
- type: Number,
- default: 0
- }
- })
- // 定义事件
- const emit = defineEmits(['step-change', 'complete'])
- // 当前激活的步骤
- const activeStep = ref(props.initialStep)
- // 步骤折叠状态
- const collapsedSteps = ref([])
- const planTemplateId = ref('')
- const planId = ref('')
- const currentStepIndex = ref()
- const response = ref()
- const handleExecute = async () => {
- const res = await executorDetail(planId.value) as any
- response.value = res
- response.value?.agentExecutionSequence.forEach((sequence: any) => {
- if (sequence.thinkActSteps) {
- sequence.thinkActSteps.forEach((step:any) => {
- // 转换actionResult
- if (step.actionResult && typeof step.actionResult === 'string') {
- step.actionResult = JSON.parse(step.actionResult);
- }
-
- // 转换toolParametersJSON
- if (step.toolParameters && typeof step.toolParameters === 'string') {
- step.toolParameters = JSON.parse(step.toolParameters);
- }
- });
- }
- });
- if (res.currentStepIndex) {
- if (currentStepIndex.value !== res.currentStepIndex) {
- collapsedSteps.value[currentStepIndex.value] = !collapsedSteps.value[currentStepIndex.value]
- collapsedSteps.value[res.currentStepIndex] = false
- activeStep.value++
- }
- currentStepIndex.value = res.currentStepIndex
- }
- if (!res.completed) setTimeout(() => {
- handleExecute()
- }, 2000);
- else {
- activeStep.value++
- deleteExecutor(planId.value)
- }
- }
- // 解析内容
- const parsedContent = computed(() => {
- try {
- if (typeof props.content === 'string') {
- const obj = JSON.parse(props.content)
- obj.steps = obj.steps.map((_:any )=> ({ ..._, description: _.description.split(' ')[1] }))
- planTemplateId.value = obj.planId
- currentStepIndex.value = 0
- // setTimeout(() => {
- // executePlanByTemplateId({ planTemplateId: planTemplateId.value }).then(res => {
- // planId.value = res.planId
- // setTimeout(() => {
- // handleExecute()
- // }, 2000);
- // })
- // }, 1000);
- return obj
- } else {
- return props.content
- }
- } catch (error) {
- console.error('解析内容失败:', error)
- return null
- }
- })
- // 初始化折叠状态
- watch(() => parsedContent.value, (newContent) => {
- if (newContent && newContent.steps) {
- // 默认所有步骤都展开,当前步骤之外的都折叠
- collapsedSteps.value = newContent.steps.map((_:any, index:any) => index !== activeStep.value)
- }
- }, { immediate: true })
- // 切换步骤折叠状态
- const toggleCollapse = (index:any) => {
- collapsedSteps.value[index] = !collapsedSteps.value[index]
- }
- watch(() => props.content, () => {
-
- }, { deep: true })
- // 组件挂载时初始化
- onMounted(() => {
- if (activeStep.value > 0 && parsedContent.value) {
- emit('step-change', activeStep.value)
- }
- })
- </script>
- <style scoped>
- .steps-display-container {
- padding: 20px;
- background-color: #fff;
- border-radius: 8px;
-
- box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
- }
- .steps-title {
- font-size: 18px;
- font-weight: bold;
- margin-bottom: 8px;
- color: #303133;
- }
- .steps-id {
- font-size: 14px;
- color: #909399;
- margin-bottom: 20px;
- }
- .custom-steps {
- margin: 20px 0;
- }
- .steps-controls {
- display: flex;
- gap: 10px;
- margin-top: 20px;
- justify-content: flex-end;
- }
- .error-message {
- margin: 20px 0;
- }
- :deep(.el-step__title) {
- font-weight: bold;
- }
- :deep(.el-step__description) {
- font-size: 14px;
- white-space: pre-wrap;
- word-break: break-word;
- }
- :deep(.el-step__icon) {
- background-color: #f5f7fa;
- }
- .timestamp {
- display: flex;
- justify-content: space-between;
- font-size: 12px;
- color: #909399;
- margin-top: 6px;
- }
- :deep(.el-step.is-success .el-step__icon) {
- background-color: #67c23a;
- color: white;
- }
- :deep(.el-step.is-process .el-step__icon) {
- background-color: #409eff;
- color: white;
- }
- /* 步骤标题容器 */
- .step-title-container {
- display: flex;
- align-items: center;
- justify-content: space-between;
- width: 100%;
- cursor: pointer;
- }
- /* 折叠按钮 */
- .collapse-button {
- margin-left: 8px;
- padding: 2px;
- font-size: 12px;
- }
- /* 步骤描述 */
- .step-description {
- transition: all 0.3s ease;
- transform-origin: top center;
- overflow: hidden;
- }
- .collapsed {
- height: 0;
- /* overflow: hidden; */
- }
- /* 步骤内容 */
- .step-content {
- padding: 8px 0;
- }
- /* 步骤进度条样式 */
- .step-progress {
- margin-top: 10px;
- display: flex;
- align-items: center;
- }
- .progress-text {
- margin-left: 8px;
- font-size: 12px;
- color: #409eff;
- font-weight: bold;
- transition: all 0.3s;
- }
- /* 自定义步骤图标 */
- .step-icon-container {
- display: flex;
- justify-content: center;
- align-items: center;
- width: 100%;
- height: 100%;
- }
- .step-icon {
- display: flex;
- justify-content: center;
- align-items: center;
- width: 24px;
- height: 24px;
- border-radius: 50%;
- background-color: #f5f7fa;
- color: #909399;
- }
- .step-icon.current {
- background-color: #409eff;
- color: white;
- animation: rotate 2s linear infinite, pulse 1.5s infinite;
- }
- .step-icon.completed {
- background-color: #67c23a;
- color: white;
- }
- /* 自定义进度条 */
- .progress-bar-container {
- position: relative;
- width: 100%;
- height: 8px;
- background-color: #f5f7fa;
- border-radius: 4px;
- overflow: hidden;
- margin-right: 10px;
- flex-grow: 1;
- }
- .progress-bar-background {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background: linear-gradient(90deg, #f5f7fa 0%, #e4e7ed 100%);
- opacity: 0.5;
- }
- .progress-bar-fill {
- position: absolute;
- top: 0;
- left: 0;
- height: 100%;
- background: linear-gradient(90deg, #409eff 0%, #95d0ff 100%);
- border-radius: 4px;
- transition: width 0.2s ease-out;
- box-shadow: 0 0 5px rgba(64, 158, 255, 0.5);
- }
- .progress-bar-glow {
- position: absolute;
- top: 0;
- width: 20px;
- height: 100%;
- background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.8) 50%, rgba(255, 255, 255, 0) 100%);
- transform: translateX(-50%);
- animation: shimmer 1.5s infinite;
- }
- @keyframes pulse {
- 0% {
- box-shadow: 0 0 0 0 rgba(64, 158, 255, 0.4);
- }
- 70% {
- box-shadow: 0 0 0 10px rgba(64, 158, 255, 0);
- }
- 100% {
- box-shadow: 0 0 0 0 rgba(64, 158, 255, 0);
- }
- }
- @keyframes rotate {
- 0% {
- transform: rotate(0);
- }
- 100% {
- transform: rotate(360deg);
- }
- }
- @keyframes shimmer {
- 0% {
- opacity: 0.3;
- }
- 50% {
- opacity: 0.7;
- }
- 100% {
- opacity: 0.3;
- }
- }
- :deep(.el-step__icon) {
- border-radius: 50%;
- }
- </style>
|