@@ -57,8 +57,6 @@ export const Input = Schema.Struct({
5757export const Output = Schema . Struct ( {
5858 path : Schema . String ,
5959 model : Schema . String . annotate ( { description : "providerID/modelID" } ) ,
60- width : Schema . optionalKey ( Schema . Int ) ,
61- height : Schema . optionalKey ( Schema . Int ) ,
6260} )
6361
6462export const Plugin = {
@@ -252,14 +250,13 @@ export const Plugin = {
252250 if ( yield * exists ( file ) )
253251 return yield * new ToolFailure ( { message : `${ file } already exists. Choose a new path.` } )
254252 yield * environment . files . write ( file , bytes )
255- const size = dimensions ( bytes , mime )
256253 const note = mime === "image/png" ? "" : ` The model returned ${ mime } , so the file is in that format.`
257254 return {
258- output : { path : file , model : ref , ... size } ,
255+ output : { path : file , model : ref } ,
259256 content : [
260257 {
261258 type : "text" as const ,
262- text : `Saved ${ size ? ` ${ size . width } x ${ size . height } ` : "" } image to ${ file } (${ ref } ).${ note } ` ,
259+ text : `Saved image to ${ file } (${ ref } ).${ note } ` ,
263260 } ,
264261 { type : "file" as const , uri : `data:${ mime } ;base64,${ image . data } ` , mime, name : file } ,
265262 ] ,
@@ -290,34 +287,3 @@ export function defaultModel(
290287function acceptsImages ( model : Model . Info ) {
291288 return model . capabilities . input . some ( ( item ) => item . startsWith ( "image" ) )
292289}
293-
294- /** Reads pixel dimensions from the image header. */
295- export function dimensions ( bytes : Uint8Array , mime : string ) {
296- const view = new DataView ( bytes . buffer , bytes . byteOffset , bytes . byteLength )
297- if ( mime === "image/png" && bytes . length >= 24 ) return { width : view . getUint32 ( 16 ) , height : view . getUint32 ( 20 ) }
298- if ( mime === "image/gif" && bytes . length >= 10 )
299- return { width : view . getUint16 ( 6 , true ) , height : view . getUint16 ( 8 , true ) }
300- if ( mime === "image/webp" && bytes . length >= 31 ) {
301- const chunk = String . fromCharCode ( ...bytes . subarray ( 12 , 16 ) )
302- if ( chunk === "VP8 " ) return { width : view . getUint16 ( 26 , true ) & 0x3fff , height : view . getUint16 ( 28 , true ) & 0x3fff }
303- if ( chunk === "VP8L" ) {
304- const bits = view . getUint32 ( 21 , true )
305- return { width : ( bits & 0x3fff ) + 1 , height : ( ( bits >> 14 ) & 0x3fff ) + 1 }
306- }
307- if ( chunk === "VP8X" )
308- return {
309- width : ( view . getUint32 ( 24 , true ) & 0xffffff ) + 1 ,
310- height : ( view . getUint32 ( 27 , true ) & 0xffffff ) + 1 ,
311- }
312- }
313- if ( mime === "image/jpeg" ) {
314- let offset = 2
315- while ( offset + 9 < bytes . length && bytes [ offset ] === 0xff ) {
316- const marker = bytes [ offset + 1 ] !
317- if ( marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc )
318- return { width : view . getUint16 ( offset + 7 ) , height : view . getUint16 ( offset + 5 ) }
319- offset += 2 + view . getUint16 ( offset + 2 )
320- }
321- }
322- return undefined
323- }
0 commit comments