"use client"; import type { ToolCallMessagePartProps } from "@assistant-ui/react"; import { AlertCircleIcon, ImageIcon } from "lucide-react"; import { z } from "zod"; import { Image, ImageErrorBoundary, ImageLoading, parseSerializableImage, } from "@/components/tool-ui/image"; const GenerateImageArgsSchema = z.object({ prompt: z.string(), n: z.number().nullish(), }); const GenerateImageResultSchema = z.object({ id: z.string(), assetId: z.string(), src: z.string(), alt: z.string().nullish(), title: z.string().nullish(), description: z.string().nullish(), domain: z.string().nullish(), ratio: z.string().nullish(), generated: z.boolean().nullish(), prompt: z.string().nullish(), image_count: z.number().nullish(), error: z.string().nullish(), }); type GenerateImageArgs = z.infer; type GenerateImageResult = z.infer; function ImageErrorState({ prompt, error }: { prompt: string; error: string }) { return (

Image generation failed

{prompt}

{error}

); } function ImageCancelledState({ prompt }: { prompt: string }) { return (

Generate: {prompt}

); } function ParsedImage({ result }: { result: unknown }) { const image = parseSerializableImage(result); return ( {image.alt} ); } /** * Tool UI for generate_image — renders the generated image directly * from the tool result directly. */ export const GenerateImageToolUI = ({ args, result, status, }: ToolCallMessagePartProps) => { const prompt = args.prompt || "Generating image..."; if (status.type === "running" || status.type === "requires-action") { return (
); } if (status.type === "incomplete") { if (status.reason === "cancelled") { return ; } if (status.reason === "error") { return ( ); } } if (!result) { return (
); } if (result.error) { return ; } return (
); }; export { GenerateImageArgsSchema, GenerateImageResultSchema, type GenerateImageArgs, type GenerateImageResult, };