This commit is contained in:
imeepos
2026-01-29 18:16:00 +08:00
parent 6ca686f2c9
commit 5e4a9c82cd
11 changed files with 1748 additions and 337 deletions

View File

@@ -0,0 +1,36 @@
import { root } from '@repo/core'
import { TemplateController } from '@repo/sdk'
import { useCallback, useState } from 'react'
import { type ApiError } from '@/lib/types'
import { handleError } from './use-error'
export const useRerunGeneration = () => {
const [loading, setLoading] = useState(false)
const [error, setError] = useState<ApiError | null>(null)
const rerun = useCallback(async (generationId: string): Promise<{ generationId?: string; error?: ApiError }> => {
setLoading(true)
setError(null)
const template = root.get(TemplateController)
const { data, error } = await handleError(async () => await template.rerun({
generationId,
}))
setLoading(false)
if (error) {
setError(error)
return { error }
}
return { generationId: data?.generationId }
}, [])
return {
rerun,
loading,
error,
}
}