@@ -6,7 +6,7 @@ import os from 'os';
66import { randomUUID } from 'crypto' ;
77import { z } from 'zod' ;
88import { WebSocket , WebSocketServer } from 'ws' ;
9- import { AgentToolService , SkillService , ModelProvider , listThreadIds , listSubDirs , readImageAsDataUrl , isEmptyContent , type StoredMessage , type MessageContent } from "scorpio.ai" ;
9+ import { AgentToolService , SkillService , ModelProvider , listThreadIds , listSubDirs , readImageAsDataUrl , isEmptyContent , resizeImageIfNeeded , setMaxImageSize , type StoredMessage , type MessageContent } from "scorpio.ai" ;
1010import { config , isDev , isValidAgentId } from '../Core/Config' ;
1111import { AgentRunner } from '../Agent/AgentRunner' ;
1212import { globalAgentToolService , refreshGlobalAgentToolService , refreshBuiltinTools , BuiltinProvider } from '../Agent/GlobalAgentToolService' ;
@@ -198,15 +198,16 @@ function isImageDataUrl(dataUrl: string): boolean {
198198 * Parts preserve the interleaved order from the editor.
199199 * File attachments (non-inline) are appended at the end.
200200 */
201- function processMessage ( parts : ContentPartInput [ ] , attachments : AttachmentInput [ ] | undefined , uploadDir : string ) : MessageContent {
201+ async function processMessage ( parts : ContentPartInput [ ] , attachments : AttachmentInput [ ] | undefined , uploadDir : string ) : Promise < MessageContent > {
202202 const msgParts : Array < { type : string ; text ?: string ; [ key : string ] : any } > = [ ] ;
203203 let hasImage = false ;
204204
205205 for ( const p of parts ) {
206206 if ( p . type === 'text' ) {
207207 msgParts . push ( { type : 'text' , text : p . text } ) ;
208208 } else if ( p . type === 'image' && p . dataUrl ) {
209- msgParts . push ( { type : 'image_url' , image_url : { url : p . dataUrl } } ) ;
209+ const url = await resizeImageIfNeeded ( p . dataUrl ) ;
210+ msgParts . push ( { type : 'image_url' , image_url : { url } } ) ;
210211 hasImage = true ;
211212 }
212213 }
@@ -215,7 +216,8 @@ function processMessage(parts: ContentPartInput[], attachments: AttachmentInput[
215216 if ( attachments ?. length ) {
216217 for ( const att of attachments ) {
217218 if ( att . dataUrl && isImageDataUrl ( att . dataUrl ) ) {
218- msgParts . push ( { type : 'image_url' , image_url : { url : att . dataUrl } } ) ;
219+ const url = await resizeImageIfNeeded ( att . dataUrl ) ;
220+ msgParts . push ( { type : 'image_url' , image_url : { url } } ) ;
219221 hasImage = true ;
220222 } else if ( att . dataUrl ) {
221223 const filePath = path . join ( uploadDir , `${ randomUUID ( ) } -${ att . name } ` ) ;
@@ -397,15 +399,15 @@ class HttpServer {
397399 wss . on ( 'connection' , ( ws ) => {
398400 this . wsClients . add ( ws ) ;
399401 ws . on ( 'close' , ( ) => { this . wsClients . delete ( ws ) ; } ) ;
400- ws . on ( 'message' , ( data ) => {
402+ ws . on ( 'message' , async ( data ) => {
401403 try {
402404 const msg = JSON . parse ( data . toString ( ) ) as { type ?: string ; [ key : string ] : any } ;
403405 const sid = msg . sessionId as string | undefined ;
404406 if ( ! sid ) throw new Error ( 'sessionId is required' ) ;
405407 const threadId = sessionThreadId ( sid ) ;
406408 switch ( msg . type ) {
407409 case WsCommandType . Query : {
408- const enriched = processMessage ( msg . parts ?? [ ] , msg . attachments , uploadDir ) ;
410+ const enriched = await processMessage ( msg . parts ?? [ ] , msg . attachments , uploadDir ) ;
409411 if ( isEmptyContent ( enriched ) ) break ;
410412 sessionManager . onReceiveWebMessage ( threadId , enriched , sid ) ;
411413 break ;
@@ -478,9 +480,13 @@ class HttpServer {
478480 app . get ( '/api/settings' , api ( ( ) => this . settingsWithAgents ( ) ) ) ;
479481
480482 app . put ( '/api/settings/general' , api ( req => {
481- const { httpPort, httpUrl, autoApproveTools, autoApproveAllTools, startupCommands } = req . body ;
483+ const { httpPort, httpUrl, maxImageSize , autoApproveTools, autoApproveAllTools, startupCommands } = req . body ;
482484 if ( httpPort !== undefined ) config . settings . httpPort = httpPort || undefined ;
483485 if ( httpUrl !== undefined ) config . settings . httpUrl = httpUrl || undefined ;
486+ if ( maxImageSize !== undefined ) {
487+ config . settings . maxImageSize = maxImageSize || undefined ;
488+ setMaxImageSize ( config . settings . maxImageSize ) ;
489+ }
484490 if ( autoApproveTools !== undefined ) config . settings . autoApproveTools = autoApproveTools ;
485491 if ( autoApproveAllTools !== undefined ) config . settings . autoApproveAllTools = autoApproveAllTools ;
486492 if ( startupCommands !== undefined ) config . settings . startupCommands = startupCommands ;
0 commit comments