@@ -45,10 +45,10 @@ import {
4545 compressImageForModel ,
4646 cropImageForModel ,
4747 formatByteSize ,
48- resolveReadImageByteBudget ,
4948 type ImageCompressionTelemetry ,
5049 type ImageCropRegion ,
5150} from '../../support/image-compress' ;
51+ import { ImageLimits } from '../../support/image-limits' ;
5252import { toInputJsonSchema } from '../../support/input-schema' ;
5353import { literalRulePattern , matchesPathRuleSubject } from '../../support/rule-match' ;
5454import type { WorkspaceConfig } from '../../support/workspace' ;
@@ -258,12 +258,14 @@ export class ReadMediaFileTool implements BuiltinTool<ReadMediaFileInput> {
258258 readonly description : string ;
259259 readonly parameters : Record < string , unknown > = toInputJsonSchema ( ReadMediaFileInputSchema ) ;
260260 private readonly compressTelemetry : ImageCompressionTelemetry | undefined ;
261+ private readonly imageLimits : ImageLimits ;
261262 constructor (
262263 private readonly kaos : Kaos ,
263264 private readonly workspace : WorkspaceConfig ,
264265 private readonly capabilities : ModelCapability ,
265266 private readonly videoUploader ?: VideoUploader | undefined ,
266267 telemetry ?: TelemetryClient ,
268+ imageLimits ?: ImageLimits ,
267269 ) {
268270 if ( ! capabilities . image_in && ! capabilities . video_in ) {
269271 const skip = new Error ( 'ReadMediaFile requires image_in or video_in capability' ) ;
@@ -273,6 +275,7 @@ export class ReadMediaFileTool implements BuiltinTool<ReadMediaFileInput> {
273275 this . description = buildDescription ( capabilities ) ;
274276 this . compressTelemetry =
275277 telemetry === undefined ? undefined : { client : telemetry , source : 'read_media' } ;
278+ this . imageLimits = imageLimits ?? new ImageLimits ( ) ;
276279 }
277280
278281 resolveExecution ( args : ReadMediaFileInput ) : ToolExecution {
@@ -387,6 +390,7 @@ export class ReadMediaFileTool implements BuiltinTool<ReadMediaFileInput> {
387390 // full fidelity, so a prior downsampled view can be zoomed into.
388391 const outcome = await cropImageForModel ( data , fileType . mimeType , args . region , {
389392 skipResize : args . full_resolution === true ,
393+ maxEdge : this . imageLimits . maxEdgePx ( ) ,
390394 telemetry : this . compressTelemetry ,
391395 } ) ;
392396 if ( ! outcome . ok ) {
@@ -446,7 +450,8 @@ export class ReadMediaFileTool implements BuiltinTool<ReadMediaFileInput> {
446450 // failure compressImageForModel returns the original bytes, so the
447451 // read still succeeds with the uncompressed image.
448452 const compressed = await compressImageForModel ( data , fileType . mimeType , {
449- byteBudget : resolveReadImageByteBudget ( ) ,
453+ maxEdge : this . imageLimits . maxEdgePx ( ) ,
454+ byteBudget : this . imageLimits . readByteBudget ( ) ,
450455 telemetry : this . compressTelemetry ,
451456 } ) ;
452457 const base64 = Buffer . from ( compressed . data ) . toString ( 'base64' ) ;
0 commit comments