import { useState, useCallback } from "react"; import type { TaskDetail } from "@fusion/core"; import { addSteeringComment } from "../api"; import type { ToastType } from "../hooks/useToast"; function formatTimestamp(iso: string): string { const date = new Date(iso); const now = new Date(); const diffMs = now.getTime() - date.getTime(); const diffMin = Math.floor(diffMs / 60000); const diffHr = Math.floor(diffMin / 60); const diffDay = Math.floor(diffHr / 24); if (diffMin < 1) return "just now"; if (diffMin < 60) return `${diffMin}m ago`; if (diffHr < 24) return `${diffHr}h ago`; if (diffDay < 7) return `${diffDay}d ago`; return date.toLocaleDateString(); } interface SteeringTabProps { task: TaskDetail; addToast: (message: string, type?: ToastType) => void; } export function SteeringTab({ task, addToast }: SteeringTabProps) { const [comments, setComments] = useState(task.steeringComments || []); const [newComment, setNewComment] = useState(""); const [isSubmitting, setIsSubmitting] = useState(false); const MAX_LENGTH = 2000; const handleSubmit = useCallback(async () => { if (!newComment.trim() || newComment.length > MAX_LENGTH || isSubmitting) return; setIsSubmitting(true); try { const updated = await addSteeringComment(task.id, newComment.trim()); setComments(updated.steeringComments || []); setNewComment(""); addToast("Steering comment added", "success"); } catch (err: any) { addToast(err.message, "error"); } finally { setIsSubmitting(false); } }, [task.id, newComment, isSubmitting, addToast]); const handleKeyDown = useCallback( (e: React.KeyboardEvent) => { if ((e.ctrlKey || e.metaKey) && e.key === "Enter") { e.preventDefault(); handleSubmit(); } }, [handleSubmit] ); const isValid = newComment.trim().length > 0 && newComment.length <= MAX_LENGTH; return (

Steering Comments

Add comments to guide the AI during task execution. These are injected into the execution context.

{comments.length > 0 ? (
{[...comments].reverse().map((comment) => (
{comment.author} {formatTimestamp(comment.createdAt)}
{comment.text}
))}
) : (
(no steering comments yet)
)}