@@ -1438,10 +1438,20 @@ function exportFailure(
14381438 error : string ,
14391439 status : number ,
14401440 stdout : string ,
1441- executionTime : number
1441+ executionTime : number ,
1442+ cost : FunctionExecutionCost | undefined
14421443) : NextResponse {
14431444 return NextResponse . json (
1444- { success : false , error, output : { result : null , stdout : cleanStdout ( stdout ) , executionTime } } ,
1445+ {
1446+ success : false ,
1447+ error,
1448+ output : {
1449+ result : null ,
1450+ stdout : cleanStdout ( stdout ) ,
1451+ executionTime,
1452+ ...( cost ? { cost } : { } ) ,
1453+ } ,
1454+ } ,
14451455 { status }
14461456 )
14471457}
@@ -1490,7 +1500,8 @@ async function maybeExportSandboxFileToWorkspace(args: {
14901500 'outputSandboxPath requires outputPath. Set outputPath to the destination workspace file, e.g. "files/result.csv".' ,
14911501 400 ,
14921502 stdout ,
1493- executionTime
1503+ executionTime ,
1504+ cost
14941505 )
14951506 }
14961507
@@ -1502,7 +1513,8 @@ async function maybeExportSandboxFileToWorkspace(args: {
15021513 'Workspace context required to save sandbox file to workspace' ,
15031514 400 ,
15041515 stdout ,
1505- executionTime
1516+ executionTime ,
1517+ cost
15061518 )
15071519 }
15081520
@@ -1511,7 +1523,8 @@ async function maybeExportSandboxFileToWorkspace(args: {
15111523 `Sandbox file "${ outputSandboxPath } " was not found or could not be read` ,
15121524 500 ,
15131525 stdout ,
1514- executionTime
1526+ executionTime ,
1527+ cost
15151528 )
15161529 }
15171530
@@ -1529,7 +1542,8 @@ async function maybeExportSandboxFileToWorkspace(args: {
15291542 `Sandbox output files exceed ${ MAX_SANDBOX_OUTPUT_BYTES } bytes total` ,
15301543 400 ,
15311544 stdout ,
1532- executionTime
1545+ executionTime ,
1546+ cost
15331547 )
15341548 }
15351549 const fileBuffer = isBinary
@@ -1612,7 +1626,8 @@ async function maybeExportSandboxFileToWorkspace(args: {
16121626 getErrorMessage ( error , 'Failed to export sandbox file' ) ,
16131627 workspaceFileExportErrorStatus ( error ) ,
16141628 stdout ,
1615- executionTime
1629+ executionTime ,
1630+ cost
16161631 )
16171632 }
16181633}
@@ -1636,7 +1651,8 @@ async function maybeExportSandboxFilesToWorkspace(args: {
16361651 `Too many sandbox output files requested (${ sandboxFiles . length } ). Maximum is ${ MAX_SANDBOX_OUTPUT_FILES } .` ,
16371652 400 ,
16381653 args . stdout ,
1639- args . executionTime
1654+ args . executionTime ,
1655+ args . cost
16401656 )
16411657 }
16421658
@@ -1669,7 +1685,8 @@ async function maybeExportSandboxFilesToWorkspace(args: {
16691685 'Workspace context required to save sandbox files to workspace' ,
16701686 400 ,
16711687 args . stdout ,
1672- args . executionTime
1688+ args . executionTime ,
1689+ args . cost
16731690 )
16741691 }
16751692
@@ -1683,7 +1700,8 @@ async function maybeExportSandboxFilesToWorkspace(args: {
16831700 `Sandbox file "${ sandboxPath } " was not found or could not be read` ,
16841701 500 ,
16851702 args . stdout ,
1686- args . executionTime
1703+ args . executionTime ,
1704+ args . cost
16871705 )
16881706 }
16891707 const outputPath = file . formatPath ?? file . path
@@ -1700,7 +1718,8 @@ async function maybeExportSandboxFilesToWorkspace(args: {
17001718 `Sandbox output files exceed ${ MAX_SANDBOX_OUTPUT_BYTES } bytes total` ,
17011719 400 ,
17021720 args . stdout ,
1703- args . executionTime
1721+ args . executionTime ,
1722+ args . cost
17041723 )
17051724 }
17061725 const scanBuffer = isBinary ? Buffer . from ( content , 'base64' ) : Buffer . from ( content , 'utf-8' )
@@ -1749,7 +1768,8 @@ async function maybeExportSandboxFilesToWorkspace(args: {
17491768 getErrorMessage ( error , 'Invalid sandbox output destination' ) ,
17501769 workspaceFileExportErrorStatus ( error ) ,
17511770 args . stdout ,
1752- args . executionTime
1771+ args . executionTime ,
1772+ args . cost
17531773 )
17541774 }
17551775 const duplicateDestination = validationPaths . find (
@@ -1760,7 +1780,8 @@ async function maybeExportSandboxFilesToWorkspace(args: {
17601780 `Duplicate sandbox output destination: ${ duplicateDestination } ` ,
17611781 400 ,
17621782 args . stdout ,
1763- args . executionTime
1783+ args . executionTime ,
1784+ args . cost
17641785 )
17651786 }
17661787
@@ -1816,7 +1837,8 @@ async function maybeExportSandboxFilesToWorkspace(args: {
18161837 getErrorMessage ( error , 'Failed to export sandbox files' ) ,
18171838 workspaceFileExportErrorStatus ( error ) ,
18181839 args . stdout ,
1819- args . executionTime
1840+ args . executionTime ,
1841+ args . cost
18201842 )
18211843 }
18221844
0 commit comments