char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
1c0a335
main
1import { assertEquals } from "@std/assert" ; 2import type { ImageContent , ToolResultMessage } from "@earendil-works/pi-ai" ; 3import { isImageResult , toolResult } from "./tool-result.ts" ; 4 5const first :ImageContent = { type :"image" , data :"first-image-data" , mimeType :"image/png" }; 6const second :ImageContent = { type :"image" , data :"second-image-data" , mimeType :"image/jpeg" }; 7const result = ( content :ToolResultMessage [ "content" ], isError = false ) :ToolResultMessage => ({ 8role :"toolResult" , 9toolCallId :"image-call" , 10toolName :"read" , 11 content, 12 isError, 13timestamp :0 , 14}); 15 16Deno . test ( "tool results keep every image beside their text or error, and only real images count" , () => { 17const text = ( text :string ) => ({ type :"text" as const , text}); 18assertEquals ( 19toolResult ( result ([ text ( "before" ), first , text ( "between" ), second ])), 20{ result :"before\nbetween" , error :null , images :[ first , second ] }, 21); 22assertEquals ( toolResult ( result ([ first ])), { result :"" , error :null , images :[ first ] }); 23assertEquals ( 24toolResult ( result ([ first , text ( "Script failed" )], true )), 25{ result :null , error :"Script failed" , images :[ first ] }, 26); 27assertEquals ( toolResult ( null ), { result :null , error :null , images :[] }); 28assertEquals ( toolResult ( result ([ text ( "plain output" )])), { 29result :"plain output" , 30error :null , 31images :[], 32}); 33 34assertEquals ( isImageResult ({ ...first , id :"screenshot-id" }), true ); 35for ( const value of [ null , "image" , { type :"image" , data :"bytes" }]) { 36assertEquals ( isImageResult ( value ), false ); 37} 38});