@@ -792,6 +792,87 @@ export function buildGetTrajectoryRequest(cascadeId) {
792792 return writeStringField ( 1 , cascadeId ) ;
793793}
794794
795+ /**
796+ * Parse GetCascadeTrajectoryResponse.
797+ *
798+ * Response {
799+ * CortexTrajectory trajectory = 1; // trajectory_id=1, cascade_id=6
800+ * CascadeRunStatus status = 2;
801+ * }
802+ */
803+ export function parseTrajectoryInfo ( buf ) {
804+ const fields = parseFields ( buf ) ;
805+ const statusField = getField ( fields , 2 , 0 ) ;
806+ const trajectoryField = getField ( fields , 1 , 2 ) ;
807+ let trajectoryId = '' ;
808+ let cascadeId = '' ;
809+ if ( trajectoryField ) {
810+ try {
811+ const trajectory = parseFields ( trajectoryField . value ) ;
812+ trajectoryId = getField ( trajectory , 1 , 2 ) ?. value ?. toString ( 'utf8' ) || '' ;
813+ cascadeId = getField ( trajectory , 6 , 2 ) ?. value ?. toString ( 'utf8' ) || '' ;
814+ } catch { }
815+ }
816+ return {
817+ status : statusField ? statusField . value : 0 ,
818+ trajectoryId,
819+ cascadeId,
820+ } ;
821+ }
822+
823+ function parseReadUrlRequestedInteraction ( stepFields ) {
824+ const requested = getField ( stepFields , 56 , 2 ) ;
825+ if ( ! requested ) return null ;
826+ try {
827+ const requestedFields = parseFields ( requested . value ) ;
828+ const readUrl = getField ( requestedFields , 14 , 2 ) ;
829+ if ( ! readUrl ) return null ;
830+ const spec = parseFields ( readUrl . value ) ;
831+ const url = getField ( spec , 1 , 2 ) ?. value ?. toString ( 'utf8' ) || '' ;
832+ const origin = getField ( spec , 2 , 2 ) ?. value ?. toString ( 'utf8' ) || '' ;
833+ if ( ! url ) return null ;
834+ return { url, origin } ;
835+ } catch {
836+ return null ;
837+ }
838+ }
839+
840+ /**
841+ * Build HandleCascadeUserInteractionRequest for ReadUrlContent approval.
842+ *
843+ * HandleCascadeUserInteractionRequest {
844+ * string cascade_id = 1;
845+ * CascadeUserInteraction interaction = 2;
846+ * }
847+ * CascadeUserInteraction {
848+ * string trajectory_id = 1;
849+ * uint32 step_index = 2;
850+ * CascadeReadUrlContentInteraction read_url_content = 15;
851+ * }
852+ */
853+ export function buildHandleReadUrlContentInteractionRequest ( cascadeId , {
854+ trajectoryId = '' ,
855+ stepIndex = 0 ,
856+ action = 1 ,
857+ url = '' ,
858+ origin = '' ,
859+ } = { } ) {
860+ const readUrlInteraction = Buffer . concat ( [
861+ writeVarintField ( 1 , action ) ,
862+ writeStringField ( 2 , url ) ,
863+ writeStringField ( 3 , origin ) ,
864+ ] ) ;
865+ const interaction = Buffer . concat ( [
866+ writeStringField ( 1 , trajectoryId ) ,
867+ writeVarintField ( 2 , stepIndex ) ,
868+ writeMessageField ( 15 , readUrlInteraction ) ,
869+ ] ) ;
870+ return Buffer . concat ( [
871+ writeStringField ( 1 , cascadeId ) ,
872+ writeMessageField ( 2 , interaction ) ,
873+ ] ) ;
874+ }
875+
795876/**
796877 * Build GetCascadeTrajectoryGeneratorMetadataRequest.
797878 *
@@ -892,9 +973,7 @@ export function parseStartCascadeResponse(buf) {
892973
893974/** Parse GetCascadeTrajectoryResponse → status (field 2). */
894975export function parseTrajectoryStatus ( buf ) {
895- const fields = parseFields ( buf ) ;
896- const f2 = getField ( fields , 2 , 0 ) ;
897- return f2 ? f2 . value : 0 ;
976+ return parseTrajectoryInfo ( buf ) . status ;
898977}
899978
900979/**
@@ -963,6 +1042,13 @@ export function parseTrajectorySteps(buf) {
9631042 toolCalls : [ ] , // [{id, name, argumentsJson, result?}]
9641043 usage : null , // {inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens}
9651044 } ;
1045+ const readUrlRequestedInteraction = parseReadUrlRequestedInteraction ( sf ) ;
1046+ if ( readUrlRequestedInteraction ) {
1047+ entry . requestedInteraction = {
1048+ kind : 'read_url_content' ,
1049+ ...readUrlRequestedInteraction ,
1050+ } ;
1051+ }
9661052
9671053 // CortexTrajectoryStep.metadata (field 5) → CortexStepMetadata.
9681054 // CortexStepMetadata.model_usage (field 9) → ModelUsageStats.
@@ -1176,6 +1262,7 @@ export function parseTrajectorySteps(buf) {
11761262 const webDocument = getField ( body , 2 , 2 ) ;
11771263 result = webDocument ? decodeKnowledgeBaseItemText ( webDocument . value ) : '' ;
11781264 if ( ! result ) result = getField ( body , 5 , 2 ) ?. value ?. toString ( 'utf8' ) || '' ;
1265+ if ( ! result && readUrlRequestedInteraction ) continue ;
11791266 } else if ( kind === 'search_web' ) {
11801267 const args = {
11811268 query : getField ( body , 1 , 2 ) ?. value ?. toString ( 'utf8' ) || '' ,
0 commit comments