@@ -76,7 +76,6 @@ import {
7676 type PendingRequest ,
7777} from "./hitl" ;
7878import { agentInstanceShareToken } from "../shareToken" ;
79- import { interleaveTaskMessages } from "./transcriptOrder" ;
8079import { serviceClient } from "../transport" ;
8180import type {
8281 ChatClient ,
@@ -777,57 +776,28 @@ export function messagesFromTask(task: A2ATask): ChatMessage[] {
777776 } ) ;
778777 } ;
779778
780- /*
781- * Sorted into three, because the gateway hands back two lists with no way to
782- * interleave them — see `interleaveTaskMessages`, which does the inferring and
783- * carries the reasoning.
784- *
785- * The split has to happen here rather than after conversion: what marks a reader
786- * turn as an answer is the HITL metadata on the A2A message, and a `ChatMessage`
787- * does not carry it.
788- */
789- const openingCount = messages . length ;
790- const answerAt : number [ ] = [ ] ;
791779 for ( const message of task . history ) {
792- if ( isAskUserResponse ( message ) ) answerAt . push ( messages . length ) ;
793780 push ( message ) ;
794781 }
795782 if ( task . status ?. message ) push ( task . status . message ) ;
796783
797- const fromHistory = messages . slice ( openingCount ) ;
798- const answered = new Set ( answerAt . map ( ( index ) => index - openingCount ) ) ;
799- const answers = fromHistory . filter ( ( _ , index ) => answered . has ( index ) ) ;
800- const opening = [
801- ...messages . slice ( 0 , openingCount ) ,
802- ...fromHistory . filter ( ( _ , index ) => ! answered . has ( index ) ) ,
803- ] ;
804-
805784 // An artifact repeating text already in the history is the same reply arriving
806785 // twice, exactly as it is on a live stream.
807786 const shown = new Set ( messages . map ( ( message ) => textOf ( message . parts ) ) ) ;
808- const agent : ChatMessage [ ] = [ ] ;
809787 for ( const artifact of task . artifacts ) {
810788 const parts = toParts ( artifact . parts ) ;
811789 const body = textOf ( parts ) ;
812790 if ( parts . length === 0 || ( body !== "" && shown . has ( body ) ) ) continue ;
813- agent . push ( {
791+ messages . push ( {
814792 // Derived, for the reason given against the message id above: an unnamed
815793 // artifact renamed on every read is an artifact the merge cannot recognise.
816- id : artifact . artifactId || `${ task . id || "task" } -artifact-${ messages . length + agent . length } ` ,
794+ id : artifact . artifactId || `${ task . id || "task" } -artifact-${ messages . length } ` ,
817795 role : "agent" ,
818796 parts,
819797 createdAt,
820798 taskId : task . id || undefined ,
821799 } ) ;
822800 }
823801
824- return interleaveTaskMessages ( opening , answers , agent ) ;
825- }
826-
827- /** Whether a reader's turn is answering an `ask_user` rather than opening a task. */
828- function isAskUserResponse ( message : A2AMessage ) : boolean {
829- const carried = ( message . metadata as Record < string , unknown > | undefined ) ?. [
830- HITL_EXTENSION_URI
831- ] as { type ?: unknown } | undefined ;
832- return carried ?. type === "ask_user_response" ;
802+ return messages ;
833803}
0 commit comments