@@ -2513,3 +2513,46 @@ async def test_convert_user_prompt_part_without_urls():
25132513 FileUIPart (media_type = 'application/pdf' , url = 'data:application/pdf;base64,ZGF0YQ==' ),
25142514 ]
25152515 )
2516+
2517+
2518+ async def test_adapter_dump_messages_file_without_text ():
2519+ """Test a file part appearing without any preceding text."""
2520+ messages = [
2521+ ModelResponse (
2522+ parts = [
2523+ FilePart (content = BinaryContent (data = b'file_data' , media_type = 'image/png' )),
2524+ ]
2525+ ),
2526+ ]
2527+
2528+ id_gen = predictable_id_generator ()
2529+ ui_messages = VercelAIAdapter .dump_messages (messages , _id_generator = id_gen )
2530+
2531+ assert ui_messages == snapshot (
2532+ [
2533+ UIMessage (
2534+ id = 'test-id-1' ,
2535+ role = 'assistant' ,
2536+ parts = [FileUIPart (media_type = 'image/png' , url = 'data:image/png;base64,ZmlsZV9kYXRh' )],
2537+ )
2538+ ]
2539+ )
2540+
2541+
2542+ async def test_convert_user_prompt_part_only_urls ():
2543+ """Test converting a user prompt with only URL content (no binary)."""
2544+ from pydantic_ai .ui .vercel_ai ._adapter import _convert_user_prompt_part # pyright: ignore[reportPrivateUsage]
2545+
2546+ part = UserPromptPart (
2547+ content = [
2548+ ImageUrl (url = 'https://example.com/img.png' , media_type = 'image/png' ),
2549+ VideoUrl (url = 'https://example.com/vid.mp4' , media_type = 'video/mp4' ),
2550+ ]
2551+ )
2552+ ui_parts = _convert_user_prompt_part (part )
2553+ assert ui_parts == snapshot (
2554+ [
2555+ FileUIPart (media_type = 'image/png' , url = 'https://example.com/img.png' ),
2556+ FileUIPart (media_type = 'video/mp4' , url = 'https://example.com/vid.mp4' ),
2557+ ]
2558+ )
0 commit comments