char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
760c3b5
main
1import type { ImageContent , ToolResultMessage } from "@earendil-works/pi-ai" ; 2import type { ToolCall } from "@berry/api/web.ts" ; 3import { imageResult } from "@berry/api/content.ts" ; 4 5const EMPTY :readonly ImageContent [] = []; 6 7export function isImageResult ( value :unknown ) :value isImageContent { 8return imageResult ( value ). errors === undefined ; 9} 10 11/** The text and images of a model-facing result, including output produced before a failure. */ 12export function toolResult ( 13message :ToolResultMessage | null , 14) :Pick < ToolCall , "result" | "error" | "images" > { 15if ( message === null ) return { result :null , error :null , images :EMPTY }; 16const text = message . content . flatMap (( block ) => 17block . type === "text" && block . text ?[ block . text ] :[] 18). join ( 19"\n" , 20); 21return { 22result :message . isError ?null :text , 23error :message . isError ?text :null , 24images :message . content . filter (( block ) => block . type === "image" ), 25}; 26}