@@ -750,23 +750,20 @@ function input<TData>(opts: { id: string }): RealtimeDefinedInputStream<TData> {
750750
751751 const apiClient = apiClientManager . clientOrThrow ( ) ;
752752
753+ // Create the waitpoint before the span so we have the entity ID upfront
754+ const response = await apiClient . createInputStreamWaitpoint ( ctx . run . id , {
755+ streamId : opts . id ,
756+ timeout : options ?. timeout ,
757+ idempotencyKey : options ?. idempotencyKey ,
758+ idempotencyKeyTTL : options ?. idempotencyKeyTTL ,
759+ tags : options ?. tags ,
760+ lastSeqNum : inputStreams . lastSeqNum ( opts . id ) ,
761+ } ) ;
762+
753763 const result = await tracer . startActiveSpan (
754764 `inputStream.wait()` ,
755765 async ( span ) => {
756- // 1. Create a waitpoint linked to this input stream
757- const response = await apiClient . createInputStreamWaitpoint ( ctx . run . id , {
758- streamId : opts . id ,
759- timeout : options ?. timeout ,
760- idempotencyKey : options ?. idempotencyKey ,
761- idempotencyKeyTTL : options ?. idempotencyKeyTTL ,
762- tags : options ?. tags ,
763- lastSeqNum : inputStreams . lastSeqNum ( opts . id ) ,
764- } ) ;
765-
766- // Set the entity ID now that we have the waitpoint ID
767- span . setAttribute ( SemanticInternalAttributes . ENTITY_ID , response . waitpointId ) ;
768-
769- // 2. Block the run on the waitpoint
766+ // 1. Block the run on the waitpoint
770767 const waitResponse = await apiClient . waitForWaitpointToken ( {
771768 runFriendlyId : ctx . run . id ,
772769 waitpointFriendlyId : response . waitpointId ,
@@ -776,10 +773,10 @@ function input<TData>(opts: { id: string }): RealtimeDefinedInputStream<TData> {
776773 throw new Error ( "Failed to block on input stream waitpoint" ) ;
777774 }
778775
779- // 3 . Suspend the task
776+ // 2 . Suspend the task
780777 const waitResult = await runtime . waitUntil ( response . waitpointId ) ;
781778
782- // 4 . Parse the output
779+ // 3 . Parse the output
783780 const data =
784781 waitResult . output !== undefined
785782 ? await conditionallyImportAndParsePacket (
@@ -806,6 +803,7 @@ function input<TData>(opts: { id: string }): RealtimeDefinedInputStream<TData> {
806803 attributes : {
807804 [ SemanticInternalAttributes . STYLE_ICON ] : "wait" ,
808805 [ SemanticInternalAttributes . ENTITY_TYPE ] : "waitpoint" ,
806+ [ SemanticInternalAttributes . ENTITY_ID ] : response . waitpointId ,
809807 streamId : opts . id ,
810808 ...accessoryAttributes ( {
811809 items : [
0 commit comments