"use client";
import { ChatMessage, ChatCompletion } from "@/lib/types";
import { ChatMessageItem } from "@/components/chat-completions/chat-messasge-item";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Skeleton } from "@/components/ui/skeleton";
function ChatCompletionDetailLoadingView() {
return (
<>
{/* Title Skeleton */}
{[...Array(2)].map((_, i) => (
))}
{" "}
{/* Properties Title Skeleton */}
{[...Array(5)].map((_, i) => (
))}
>
);
}
interface ChatCompletionDetailViewProps {
completion: ChatCompletion | null;
isLoading: boolean;
error: Error | null;
id: string;
}
export function ChatCompletionDetailView({
completion,
isLoading,
error,
id,
}: ChatCompletionDetailViewProps) {
if (error) {
return (
<>
{/* We still want a title for consistency on error pages */}
Chat Completion Details
Error loading details for ID {id}: {error.message}
>
);
}
if (isLoading) {
return ;
}
if (!completion) {
// This state means: not loading, no error, but no completion data
return (
<>
{/* We still want a title for consistency on not-found pages */}
Chat Completion Details
No details found for completion ID: {id}.
>
);
}
// If no error, not loading, and completion exists, render the details:
return (
<>
Chat Completion Details
Input
{completion.input_messages?.map((msg, index) => (
))}
{completion.choices?.[0]?.message?.tool_calls &&
!completion.input_messages?.some(
(im) =>
im.role === "assistant" &&
im.tool_calls &&
im.tool_calls.length > 0,
) &&
completion.choices[0].message.tool_calls.map(
(toolCall: any, index: number) => {
const assistantToolCallMessage: ChatMessage = {
role: "assistant",
tool_calls: [toolCall],
content: "", // Ensure content is defined, even if empty
};
return (
);
},
)}
Output
{completion.choices?.[0]?.message ? (
) : (
No message found in assistant's choice.
)}
Properties
-
Created:{" "}
{new Date(completion.created * 1000).toLocaleString()}
-
ID:{" "}
{completion.id}
-
Model:{" "}
{completion.model}
-
Finish Reason:{" "}
{completion.choices?.[0]?.finish_reason || "N/A"}
{completion.choices?.[0]?.message?.tool_calls &&
completion.choices[0].message.tool_calls.length > 0 && (
-
Functions/Tools Called:
{completion.choices[0].message.tool_calls.map(
(toolCall: any, index: number) => (
-
{toolCall.function?.name || "N/A"}
),
)}
)}
>
);
}