MCPcopy Index your code
hub / github.com/TanStack/ai / ImageGenUI

Function ImageGenUI

testing/e2e/src/components/ImageGenUI.tsx:36–150  ·  view source on GitHub ↗
({
  provider,
  mode,
  testId,
  aimockPort,
  withImageInput,
}: ImageGenUIProps)

Source from the content-addressed store, hash-verified

34}
35
36export function ImageGenUI({
37 provider,
38 mode,
39 testId,
40 aimockPort,
41 withImageInput,
42}: ImageGenUIProps) {
43 const [prompt, setPrompt] = useState('')
44 const [imageFile, setImageFile] = useState<File | null>(null)
45
46 const connectionOptions = () => {
47 const body = { provider, numberOfImages: 1, testId, aimockPort }
48
49 if (mode === 'sse') {
50 return { connection: fetchServerSentEvents('/api/image'), body }
51 }
52 if (mode === 'http-stream') {
53 return { connection: fetchHttpStream('/api/image/stream'), body }
54 }
55 return {
56 fetcher: async (input: { prompt: MediaPrompt }) => {
57 return generateImageFn({
58 data: {
59 prompt: input.prompt,
60 provider,
61 numberOfImages: 1,
62 aimockPort,
63 testId,
64 },
65 }) as Promise<ImageGenerationResult>
66 },
67 }
68 }
69
70 const { generate, result, isLoading, error, status } =
71 useGenerateImage(connectionOptions())
72
73 const handleGenerate = async () => {
74 if (!imageFile) {
75 await generate({ prompt })
76 return
77 }
78 const base64 = await fileToBase64(imageFile)
79 await generate({
80 prompt: [
81 { type: 'text', content: prompt },
82 {
83 type: 'image',
84 source: { type: 'data', value: base64, mimeType: imageFile.type },
85 },
86 ],
87 })
88 }
89
90 return (
91 <div className="p-4 space-y-4">
92 <div className="flex gap-2">
93 <input

Callers

nothing calls this directly

Calls 2

useGenerateImageFunction · 0.90
connectionOptionsFunction · 0.70

Tested by

no test coverage detected