"use client"; import { useState } from "react"; import { IconAlertTriangle, IconChevronDown, IconPlayerPlay, IconRefresh, } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@kandev/ui/collapsible"; import { useAppStore } from "@/components/state-provider"; import { selectOfficeAgentProfiles } from "@/lib/state/slices/office/selectors"; import { formatRelativeTime } from "@/lib/utils"; import { AgentAvatar } from "@/app/office/components/agent-avatar"; import { RemediationLink } from "@/components/task/remediation-link"; import { EnsureSessionErrorBanner, SessionRecoveryNotice, } from "@/components/task/ensure-session-error"; import { useSessionRecoveryActions } from "@/hooks/domains/session/use-session-recovery-actions"; import type { BranchRecoveryDetails, SessionRecoveryAction, } from "@/lib/services/session-recovery-service"; import type { RunError } from "@/app/office/tasks/[id]/types"; import type { TaskRepository } from "@/lib/types/http"; import { ManagedRuntimeNpmRunError } from "./managed-runtime-npm-run-error"; import { isLaunchErrorCategory, TaskLaunchErrorEntry } from "./task-launch-error-entry"; import { useTranslation } from "react-i18next"; type RunErrorEntryProps = { taskId: string; workspaceId?: string; repositories?: TaskRepository[]; error: RunError; }; function TypedRunLaunchErrorEntry({ taskId, workspaceId, repositories, error, preview, }: RunErrorEntryProps & { preview: string }) { return ( ); } function RunErrorRecoveryFeedback({ workspaceId, recoveryError, recoveryNotice, branchDetails, busyAction, onRetry, onRestore, onNewBranch, }: { workspaceId: string; recoveryError: Error | null; recoveryNotice: string | null; branchDetails: BranchRecoveryDetails | null; busyAction: SessionRecoveryAction | "restore" | null; onRetry: () => void; onRestore: () => void; onNewBranch: () => void; }) { const { t } = useTranslation(); if (!recoveryError && !recoveryNotice) return null; return ( <> {recoveryError ? ( ) : null} {recoveryNotice ? : null} ); } function LegacyRunErrorEntry({ agentName, error, onRecover, onRetry, onRestore, onNewBranch, workspaceId, recoveryError, recoveryNotice, branchDetails, busyAction, }: { agentName: string; error: RunError; onRecover: (action: SessionRecoveryAction) => Promise; onRetry: () => void; onRestore: () => void; onNewBranch: () => void; workspaceId: string; recoveryError: Error | null; recoveryNotice: string | null; branchDetails: BranchRecoveryDetails | null; busyAction: SessionRecoveryAction | "restore" | null; }) { const { t } = useTranslation(); const [showDetails, setShowDetails] = useState(false); return (
{agentName} {t("task:stoppedWithAnError")} {formatRelativeTime(error.failedAt)}

{t("task:theAgentStoppedWithAnError")}

{error.rawPayload && ( {t("task:showDetails")}
                {error.rawPayload}
              
)}
); } /** * Top-level chat entry rendered when an office session is in FAILED * state. Replaces the legacy red action-message banner: shows a short * generic header, a Show details collapsible exposing the verbatim * raw payload (for bug reports), and the Resume / Start fresh * buttons. Click handlers wire to the existing `session.recover` WS * request so the recovery semantics are unchanged. */ export function RunErrorEntry({ taskId, workspaceId = "", repositories, error, }: RunErrorEntryProps) { const { t } = useTranslation(); const agentName = useAppStore( (s) => selectOfficeAgentProfiles(s).find((a) => a.id === error.agentProfileId)?.name ?? t("task:agent"), ); const { busyAction, recoveryError, branchDetails, recoveryNotice, handleRecover, handleRestore, handleRetry, handleNewBranch, } = useSessionRecoveryActions({ taskId, sessionId: error.sessionId }); if (isLaunchErrorCategory(error.failureCode) && error.errorStamp) { return ( ); } if (error.failureCode === "managed_runtime_npm_resolution") { return ( void handleRecover("runtime_retry")} /> ); } return ( void handleRestore()} onNewBranch={handleNewBranch} workspaceId={workspaceId} recoveryError={recoveryError} recoveryNotice={recoveryNotice} branchDetails={branchDetails} busyAction={busyAction} /> ); }