import { OWNER_ID } from "@/lib/auth" import { ApiError } from "@/lib/types" import { root } from '@repo/core' import { TemplateController, type RunTemplateInput } from "@repo/sdk" import { useState } from "react" export const useTemplateActions = () => { const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const runTemplate = async (params: RunTemplateInput): Promise<{ generationId?: string; error?: ApiError }> => { setLoading(true) setError(null) try { const template = root.get(TemplateController) const result = await template.run({ templateId: params.templateId, data: params.data || {}, }) setLoading(false) return { generationId: result.generationId } } catch (e) { setError(e as ApiError) setLoading(false) return { error: e as ApiError } } } return { loading, error, runTemplate, } }