@@ -9,16 +9,15 @@ export function useProtocol(): ProtocolOutput {
99 const [ error , setError ] = useState < string | null > ( null ) ;
1010
1111 const runProtocol = async ( input : ProtocolInput ) : Promise < void > => {
12- // Reset states
12+ // reset states
1313 setOutput ( '' ) ;
1414 setError ( null ) ;
1515 setLoading ( true ) ;
1616
1717 try {
18- // Prepare the request body
1918 const requestBody = {
2019 task : input . query ,
21- context : input . context . join ( '\n' ) , // Always send as a list
20+ context : input . context . join ( '\n' ) ,
2221 doc_metadata : input . fileMetadata || '' ,
2322 protocol : input . config . protocol ,
2423 localProvider : input . config . localProvider ,
@@ -36,14 +35,12 @@ export function useProtocol(): ProtocolOutput {
3635 images : input . config . images
3736 } ;
3837
39- // Log the request (sanitize sensitive data)
4038 console . log ( 'Sending request:' , {
4139 ...requestBody ,
42- remote_api_key : '***' , // Hide API key in logs
40+ remote_api_key : '***' ,
4341 context : requestBody . context . slice ( 0 , 300 ) + '...' ,
4442 } ) ;
4543
46- // Make the API request with proper error handling
4744 const response = await fetch ( `${ API_BASE_URL } /run_protocol` , {
4845 method : 'POST' ,
4946 headers : {
@@ -60,7 +57,6 @@ export function useProtocol(): ProtocolOutput {
6057 console . error ( 'Server error response:' , errorData ) ;
6158 errorMessage = errorData . error || errorMessage ;
6259 } catch ( e ) {
63- // If we can't parse the error JSON, use the status text
6460 console . error ( 'Failed to parse error response:' , e ) ;
6561 errorMessage = response . statusText ;
6662 }
@@ -70,27 +66,21 @@ export function useProtocol(): ProtocolOutput {
7066 const data = await response . json ( ) as ProtocolResponse ;
7167 console . log ( 'Protocol completed with result:' , data ) ;
7268
73- // Format the output with all available information
7469 let formattedOutput = `Final Answer: ${ data . output . final_answer } \n` ;
7570
76- // Add execution time
7771 if ( data . output . execution_time > 0 ) {
7872 formattedOutput += `\nExecution Time: ${ data . output . execution_time . toFixed ( 2 ) } s` ;
7973 }
8074
81- // Add protocol-specific information
8275 if ( data . output . meta ) {
8376 data . output . meta . forEach ( ( round , index ) => {
8477 if ( round . remote ?. messages ) {
8578 formattedOutput += `\n\nRound ${ index + 1 } Remote Messages:` ;
8679 round . remote . messages . forEach ( msg => {
8780 try {
88- // Try to parse as JSON if it's a string
8981 const jsonMsg = typeof msg === 'string' ? JSON . parse ( msg ) : msg ;
90- // Format the message with proper indentation
9182 formattedOutput += `\n${ JSON . stringify ( jsonMsg , null , 2 ) } ` ;
9283 } catch {
93- // If not JSON or parsing fails, use as is
9484 formattedOutput += `\n${ msg } ` ;
9585 }
9686 } ) ;
0 commit comments