"use client"; import { useState } from "react"; import { Trash2 } from "lucide-react"; import { toast } from "sonner"; import { useQuery } from "@tanstack/react-query"; import type { AgentRuntime } from "@multica/core/types"; import { useAuthStore } from "@multica/core/auth"; import { useWorkspaceId } from "@multica/core/hooks"; import { memberListOptions } from "@multica/core/workspace/queries"; import { useDeleteRuntime } from "@multica/core/runtimes/mutations"; import { Button } from "@multica/ui/components/ui/button"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@multica/ui/components/ui/alert-dialog"; import { ActorAvatar } from "../../common/actor-avatar"; import { formatLastSeen } from "../utils"; import { StatusBadge, InfoField } from "./shared"; import { ProviderLogo } from "./provider-logo"; import { PingSection } from "./ping-section"; import { UpdateSection } from "./update-section"; import { UsageSection } from "./usage-section"; function getCliVersion(metadata: Record): string | null { if ( metadata && typeof metadata.cli_version === "string" && metadata.cli_version ) { return metadata.cli_version; } return null; } function getLaunchedBy(metadata: Record): string | null { if ( metadata && typeof metadata.launched_by === "string" && metadata.launched_by ) { return metadata.launched_by; } return null; } export function RuntimeDetail({ runtime }: { runtime: AgentRuntime }) { const cliVersion = runtime.runtime_mode === "local" ? getCliVersion(runtime.metadata) : null; const launchedBy = runtime.runtime_mode === "local" ? getLaunchedBy(runtime.metadata) : null; const user = useAuthStore((s) => s.user); const wsId = useWorkspaceId(); const { data: members = [] } = useQuery(memberListOptions(wsId)); const deleteMutation = useDeleteRuntime(wsId); const [deleteOpen, setDeleteOpen] = useState(false); // Resolve owner info const ownerMember = runtime.owner_id ? members.find((m) => m.user_id === runtime.owner_id) ?? null : null; // Permission check for delete const currentMember = user ? members.find((m) => m.user_id === user.id) : null; const isAdmin = currentMember ? currentMember.role === "owner" || currentMember.role === "admin" : false; const isRuntimeOwner = user && runtime.owner_id === user.id; const canDelete = isAdmin || isRuntimeOwner; const handleDelete = () => { deleteMutation.mutate(runtime.id, { onSuccess: () => { toast.success("Runtime deleted"); setDeleteOpen(false); }, onError: (e) => { toast.error(e instanceof Error ? e.message : "Failed to delete runtime"); }, }); }; return (
{/* Header */}

{runtime.name}

{canDelete && ( )}
{/* Content */}
{/* Info grid */}
{ownerMember && (
Owner
{ownerMember.name}
)} {runtime.device_info && ( )} {runtime.daemon_id && ( )}
{/* CLI Version & Update */} {runtime.runtime_mode === "local" && (

CLI Version

)} {/* Connection Test */}

Connection Test

{/* Usage */}

Token Usage

{/* Metadata */} {runtime.metadata && Object.keys(runtime.metadata).length > 0 && (

Metadata

                {JSON.stringify(runtime.metadata, null, 2)}
              
)} {/* Timestamps */}
{/* Delete confirmation */} { if (!v) setDeleteOpen(false); }}> Delete Runtime Are you sure you want to delete “{runtime.name}”? This action cannot be undone. Cancel {deleteMutation.isPending ? "Deleting..." : "Delete"}
); }