feat: add provider analytics summary

This commit is contained in:
2026-04-18 22:01:34 +08:00
parent e99a7fbe14
commit 4d54c144a8
15 changed files with 437 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { computed, onBeforeUnmount, ref, watch } from 'vue'
import { BoltIcon, ClockIcon } from '@heroicons/vue/24/outline'
import { api } from '../api/client'
import type {
@@ -29,12 +29,18 @@ const activeJob = ref<GenerationJobDetail | null>(null)
const providerStats = ref<GenerationProviderStats | null>(null)
const loading = ref(false)
const error = ref('')
let refreshTimer: ReturnType<typeof setInterval> | null = null
const isDark = computed(() => props.tone === 'dark')
const latestJob = computed(() => jobHistory.value[0] ?? null)
const activeJobEvents = computed(() => activeJob.value?.events.slice(-10) ?? [])
const activeProgress = computed(() => activeJob.value?.progress_percent ?? latestJob.value?.progress_percent ?? 0)
const activeProgressLabel = computed(() => activeJob.value?.progress_label ?? latestJob.value?.progress_label ?? '暂无进度')
const shouldAutoRefresh = computed(() => {
if (activeJob.value) return !activeJob.value.is_terminal
if (latestJob.value) return !latestJob.value.is_terminal
return false
})
const providerSuccessRate = computed(() => {
if (!providerStats.value?.total_calls) return null
return Math.round((providerStats.value.successful_calls / providerStats.value.total_calls) * 100)
@@ -195,6 +201,13 @@ async function refresh() {
}
}
function stopAutoRefresh() {
if (refreshTimer) {
clearInterval(refreshTimer)
refreshTimer = null
}
}
watch(
() => props.storyId,
() => {
@@ -203,6 +216,19 @@ watch(
{ immediate: true },
)
watch(shouldAutoRefresh, (enabled) => {
stopAutoRefresh()
if (enabled) {
refreshTimer = setInterval(() => {
if (!loading.value) {
void refresh()
}
}, 2500)
}
})
onBeforeUnmount(stopAutoRefresh)
defineExpose({ refresh })
</script>