feat: AI RCA draft assistant in investigation form
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FFDuBhMKvoWjrWT3ZnGmmr
This commit is contained in:
@@ -40,6 +40,7 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
||||
const [complete, setComplete] = useState(false)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [aiDraftLoading, setAiDraftLoading] = useState(false)
|
||||
|
||||
function addWhyStep() {
|
||||
if (fiveWhy.length >= 5) return
|
||||
@@ -57,6 +58,31 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
||||
setFishbone(fishbone.map((c, i) => i === catIdx ? { ...c, causes: [...c.causes, ''] } : c))
|
||||
}
|
||||
|
||||
async function getAiDraft() {
|
||||
setAiDraftLoading(true)
|
||||
try {
|
||||
const res = await fetch(`/api/incidents/${incidentId}/ai/rca-draft`, { method: 'POST' })
|
||||
if (!res.ok) return
|
||||
const draft = await res.json() as {
|
||||
five_why_steps: Array<{ why: string; answer: string }>
|
||||
root_cause_summary: string
|
||||
capa_suggestions: string[]
|
||||
}
|
||||
if (draft.five_why_steps?.length > 0) {
|
||||
setMethod('five_why')
|
||||
setFiveWhy(draft.five_why_steps)
|
||||
}
|
||||
if (draft.root_cause_summary) setRootCause(draft.root_cause_summary)
|
||||
if (draft.capa_suggestions?.length > 0) {
|
||||
setFindingsText(draft.capa_suggestions.map((s, i) => `${i + 1}. ${s}`).join('\n'))
|
||||
}
|
||||
} catch {
|
||||
// Non-blocking — investigator can fill manually
|
||||
} finally {
|
||||
setAiDraftLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault()
|
||||
setSaving(true)
|
||||
@@ -99,6 +125,16 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
<div className="flex justify-end">
|
||||
<button
|
||||
type="button"
|
||||
onClick={getAiDraft}
|
||||
disabled={aiDraftLoading}
|
||||
className="bg-purple-50 text-purple-700 border border-purple-300 rounded-lg px-3 py-1.5 text-xs font-semibold disabled:opacity-50 hover:bg-purple-100"
|
||||
>
|
||||
{aiDraftLoading ? 'Drafting…' : 'Get AI Draft'}
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">RCA Method</label>
|
||||
<div className="flex gap-3">
|
||||
|
||||
Reference in New Issue
Block a user