mateclaw/mateclaw-ui/src/composables/useWikiJobPoller.ts
matevip 3d213eb281 chore: sync multiple commits from private dev
Covers 15 upstream commits (private mirror → public):

Multi-provider failover (RFC-009):
- PR-0: extract ChatModelBuilder strategy seam
- PR-1a: AvailableProviderPool data structure
- PR-1b: startup provider liveness probe + 4 protocol strategies
- PR-1c: wire AvailableProviderPool into runtime chat-model selection
- PR-1d: provider pool REST endpoint + UI badges
- PR-1e: manual reprobe trigger + auto-reprobe on provider config change
- PR-3: per-agent provider preferences (agents can override the
  org-wide fallback chain)

Wiki subsystem (RFC-029~033):
- Relation model, resilient background jobs, light-weight processing
  path, retrieval enhancement, frontend redesign (single landing commit)
- Follow-up fixes: null guards + stats query + i18n polish, move
  WikiProcessingJobMapper to repository/ for @MapperScan, align
  implementation with RFC-029~031 spec
- Copy pass: replace "富化 / enrich" wording with clearer "链接 / link"
- Style: switch enrich/repair buttons to @element-plus/icons-vue
2026-04-19 18:37:44 +08:00

52 lines
1.3 KiB
TypeScript

import { ref, onMounted, onUnmounted, type Ref } from 'vue'
import { wikiApi } from '@/api/index'
export interface WikiProcessingJob {
id: number
kbId: number
rawId: number
jobType: string
stage: string
status: string
primaryModelId: number | null
currentModelId: number | null
currentModelName?: string
errorCode: string | null
errorMessage: string | null
retryCount: number
startedAt: string | null
finishedAt: string | null
done?: number
total?: number
}
/**
* RFC-033: Polls the latest processing job for a given raw material.
* Stops polling when the job reaches a terminal status.
*/
export function useWikiJobPoller(kbId: Ref<number | null>, rawId: Ref<number | null>) {
const job = ref<WikiProcessingJob | null>(null)
let timer: ReturnType<typeof setTimeout> | null = null
const poll = async () => {
if (!kbId.value || !rawId.value) return
try {
const jobs: any = await wikiApi.getWikiJobs(kbId.value, rawId.value)
const list = jobs.data || jobs || []
job.value = list[0] ?? null
if (job.value && (job.value.status === 'running' || job.value.status === 'queued')) {
timer = setTimeout(poll, 3000)
}
} catch {
job.value = null
}
}
onMounted(poll)
onUnmounted(() => {
if (timer) clearTimeout(timer)
})
return { job, refresh: poll }
}