@@ -65,6 +65,14 @@ export class CloudSandboxExecutionRuntime {
6565 try {
6666 const result = await this . callTool ( 'listLocalFiles' , args ) ;
6767
68+ if ( ! result . success ) {
69+ return {
70+ content : result . error ?. message || JSON . stringify ( result . error ) ,
71+ state : { files : [ ] } ,
72+ success : true ,
73+ } ;
74+ }
75+
6876 const files = result . result ?. files || [ ] ;
6977 const state : ListLocalFilesState = { files } ;
7078
@@ -90,6 +98,19 @@ export class CloudSandboxExecutionRuntime {
9098 try {
9199 const result = await this . callTool ( 'readLocalFile' , args ) ;
92100
101+ if ( ! result . success ) {
102+ return {
103+ content : result . error ?. message || JSON . stringify ( result . error ) ,
104+ state : {
105+ content : '' ,
106+ endLine : args . endLine ,
107+ path : args . path ,
108+ startLine : args . startLine ,
109+ } ,
110+ success : true ,
111+ } ;
112+ }
113+
93114 const state : ReadLocalFileState = {
94115 content : result . result ?. content || '' ,
95116 endLine : args . endLine ,
@@ -123,6 +144,17 @@ export class CloudSandboxExecutionRuntime {
123144 try {
124145 const result = await this . callTool ( 'writeLocalFile' , args ) ;
125146
147+ if ( ! result . success ) {
148+ return {
149+ content : result . error ?. message || JSON . stringify ( result . error ) ,
150+ state : {
151+ path : args . path ,
152+ success : false ,
153+ } ,
154+ success : true ,
155+ } ;
156+ }
157+
126158 const state : WriteLocalFileState = {
127159 bytesWritten : result . result ?. bytesWritten ,
128160 path : args . path ,
@@ -148,6 +180,17 @@ export class CloudSandboxExecutionRuntime {
148180 try {
149181 const result = await this . callTool ( 'editLocalFile' , args ) ;
150182
183+ if ( ! result . success ) {
184+ return {
185+ content : result . error ?. message || JSON . stringify ( result . error ) ,
186+ state : {
187+ path : args . path ,
188+ replacements : 0 ,
189+ } ,
190+ success : true ,
191+ } ;
192+ }
193+
151194 const state : EditLocalFileState = {
152195 diffText : result . result ?. diffText ,
153196 linesAdded : result . result ?. linesAdded ,
@@ -177,6 +220,17 @@ export class CloudSandboxExecutionRuntime {
177220 try {
178221 const result = await this . callTool ( 'searchLocalFiles' , args ) ;
179222
223+ if ( ! result . success ) {
224+ return {
225+ content : result . error ?. message || JSON . stringify ( result . error ) ,
226+ state : {
227+ results : [ ] ,
228+ totalCount : 0 ,
229+ } ,
230+ success : true ,
231+ } ;
232+ }
233+
180234 const results = result . result ?. results || [ ] ;
181235 const state : SearchLocalFilesState = {
182236 results,
@@ -201,6 +255,18 @@ export class CloudSandboxExecutionRuntime {
201255 try {
202256 const result = await this . callTool ( 'moveLocalFiles' , args ) ;
203257
258+ if ( ! result . success ) {
259+ return {
260+ content : result . error ?. message || JSON . stringify ( result . error ) ,
261+ state : {
262+ results : [ ] ,
263+ successCount : 0 ,
264+ totalCount : args . operations . length ,
265+ } ,
266+ success : true ,
267+ } ;
268+ }
269+
204270 const results = result . result ?. results || [ ] ;
205271 const state : MoveLocalFilesState = {
206272 results,
@@ -224,6 +290,19 @@ export class CloudSandboxExecutionRuntime {
224290 try {
225291 const result = await this . callTool ( 'renameLocalFile' , args ) ;
226292
293+ if ( ! result . success ) {
294+ return {
295+ content : result . error ?. message || JSON . stringify ( result . error ) ,
296+ state : {
297+ error : result . error ?. message ,
298+ newPath : '' ,
299+ oldPath : args . oldPath ,
300+ success : false ,
301+ } ,
302+ success : true ,
303+ } ;
304+ }
305+
227306 const state : RenameLocalFileState = {
228307 error : result . result ?. error ,
229308 newPath : result . result ?. newPath || '' ,
@@ -241,7 +320,7 @@ export class CloudSandboxExecutionRuntime {
241320 return {
242321 content,
243322 state,
244- success : result . success ,
323+ success : true ,
245324 } ;
246325 } catch ( error ) {
247326 return this . handleError ( error ) ;
@@ -264,15 +343,24 @@ export class CloudSandboxExecutionRuntime {
264343 language,
265344 output : result . result ?. output ,
266345 stderr : result . result ?. stderr ,
267- success : result . success ,
346+ success : result . success || false ,
268347 } ;
269348
349+ if ( ! result . success ) {
350+ return {
351+ content : result . error ?. message || JSON . stringify ( result . error ) ,
352+ state,
353+ success : true ,
354+ } ;
355+ }
356+
270357 return {
271358 content : JSON . stringify ( result . result ) ,
272359 state,
273- success : result . success ,
360+ success : true ,
274361 } ;
275362 } catch ( error ) {
363+ console . log ( 'executeCode error' , error ) ;
276364 return this . handleError ( error ) ;
277365 }
278366 }
@@ -283,6 +371,18 @@ export class CloudSandboxExecutionRuntime {
283371 try {
284372 const result = await this . callTool ( 'runCommand' , args ) ;
285373
374+ if ( ! result . success ) {
375+ return {
376+ content : result . error ?. message || JSON . stringify ( result . error ) ,
377+ state : {
378+ error : result . error ?. message ,
379+ isBackground : args . background || false ,
380+ success : false ,
381+ } ,
382+ success : true ,
383+ } ;
384+ }
385+
286386 const state : RunCommandState = {
287387 commandId : result . result ?. commandId ,
288388 error : result . result ?. error ,
@@ -296,7 +396,7 @@ export class CloudSandboxExecutionRuntime {
296396 return {
297397 content : JSON . stringify ( result . result ) ,
298398 state,
299- success : result . success ,
399+ success : true ,
300400 } ;
301401 } catch ( error ) {
302402 return this . handleError ( error ) ;
@@ -307,6 +407,18 @@ export class CloudSandboxExecutionRuntime {
307407 try {
308408 const result = await this . callTool ( 'getCommandOutput' , args ) ;
309409
410+ if ( ! result . success ) {
411+ return {
412+ content : result . error ?. message || JSON . stringify ( result . error ) ,
413+ state : {
414+ error : result . error ?. message ,
415+ running : false ,
416+ success : false ,
417+ } ,
418+ success : true ,
419+ } ;
420+ }
421+
310422 const state : GetCommandOutputState = {
311423 error : result . result ?. error ,
312424 newOutput : result . result ?. newOutput ,
@@ -317,7 +429,7 @@ export class CloudSandboxExecutionRuntime {
317429 return {
318430 content : JSON . stringify ( result . result ) ,
319431 state,
320- success : result . success ,
432+ success : true ,
321433 } ;
322434 } catch ( error ) {
323435 return this . handleError ( error ) ;
@@ -328,6 +440,18 @@ export class CloudSandboxExecutionRuntime {
328440 try {
329441 const result = await this . callTool ( 'killCommand' , args ) ;
330442
443+ if ( ! result . success ) {
444+ return {
445+ content : result . error ?. message || JSON . stringify ( result . error ) ,
446+ state : {
447+ commandId : args . commandId ,
448+ error : result . error ?. message ,
449+ success : false ,
450+ } ,
451+ success : true ,
452+ } ;
453+ }
454+
331455 const state : KillCommandState = {
332456 commandId : args . commandId ,
333457 error : result . result ?. error ,
@@ -340,7 +464,7 @@ export class CloudSandboxExecutionRuntime {
340464 success : true ,
341465 } ) ,
342466 state,
343- success : result . success ,
467+ success : true ,
344468 } ;
345469 } catch ( error ) {
346470 return this . handleError ( error ) ;
@@ -353,6 +477,18 @@ export class CloudSandboxExecutionRuntime {
353477 try {
354478 const result = await this . callTool ( 'grepContent' , args ) ;
355479
480+ if ( ! result . success ) {
481+ return {
482+ content : result . error ?. message || JSON . stringify ( result . error ) ,
483+ state : {
484+ matches : [ ] ,
485+ pattern : args . pattern ,
486+ totalMatches : 0 ,
487+ } ,
488+ success : true ,
489+ } ;
490+ }
491+
356492 const state : GrepContentState = {
357493 matches : result . result ?. matches || [ ] ,
358494 pattern : args . pattern ,
@@ -373,6 +509,18 @@ export class CloudSandboxExecutionRuntime {
373509 try {
374510 const result = await this . callTool ( 'globLocalFiles' , args ) ;
375511
512+ if ( ! result . success ) {
513+ return {
514+ content : result . error ?. message || JSON . stringify ( result . error ) ,
515+ state : {
516+ files : [ ] ,
517+ pattern : args . pattern ,
518+ totalCount : 0 ,
519+ } ,
520+ success : true ,
521+ } ;
522+ }
523+
376524 const files = result . result ?. files || [ ] ;
377525 const totalCount = result . result ?. totalCount || 0 ;
378526
@@ -433,7 +581,7 @@ export class CloudSandboxExecutionRuntime {
433581 success : false ,
434582 } ) ,
435583 state,
436- success : false ,
584+ success : true ,
437585 } ;
438586 }
439587
@@ -455,13 +603,14 @@ export class CloudSandboxExecutionRuntime {
455603 private async callTool (
456604 toolName : string ,
457605 params : Record < string , any > ,
458- ) : Promise < { result : any ; sessionExpiredAndRecreated ?: boolean ; success : boolean } > {
606+ ) : Promise < {
607+ error ?: { message : string ; name ?: string } ;
608+ result : any ;
609+ sessionExpiredAndRecreated ?: boolean ;
610+ success : boolean ;
611+ } > {
459612 const result = await this . sandboxService . callTool ( toolName , params ) ;
460613
461- if ( ! result . success ) {
462- throw new Error ( result . error ?. message || `Cloud Sandbox tool ${ toolName } failed` ) ;
463- }
464-
465614 return result ;
466615 }
467616
0 commit comments