@@ -891,23 +891,25 @@ def handle_responses_streaming_event(
891891
892892
893893def get_source_context (
894- sources : list , source_id_map : dict = None , include_content : bool = True
894+ sources : list , source_ids : dict = None , include_content : bool = True
895895) -> str :
896896 """
897897 Build <source> tag context string from citation sources.
898898 """
899899 context_string = ""
900- if source_id_map is None :
901- source_id_map = {}
900+ if source_ids is None :
901+ source_ids = {}
902902 for source in sources :
903903 for doc , meta in zip (source .get ("document" , []), source .get ("metadata" , [])):
904- src_id = meta .get ("source" ) or source .get ("source" , {}).get ("id" ) or "N/A"
905- if src_id not in source_id_map :
906- source_id_map [src_id ] = len (source_id_map ) + 1
904+ source_id = (
905+ meta .get ("source" ) or source .get ("source" , {}).get ("id" ) or "N/A"
906+ )
907+ if source_id not in source_ids :
908+ source_ids [source_id ] = len (source_ids ) + 1
907909 src_name = source .get ("source" , {}).get ("name" )
908910 body = doc if include_content else ""
909911 context_string += (
910- f'<source id="{ source_id_map [ src_id ]} "'
912+ f'<source id="{ source_ids [ source_id ]} "'
911913 + (f' name="{ src_name } "' if src_name else "" )
912914 + f">{ body } </source>\n "
913915 )
@@ -4494,12 +4496,12 @@ async def flush_pending_delta_data(threshold: int = 0):
44944496
44954497 # Build context: file sources with content,
44964498 # tool sources as citation markers only.
4497- source_id_map = {}
4499+ source_ids = {}
44984500 source_context = get_source_context (
4499- metadata .get ("sources" , []), source_id_map
4501+ metadata .get ("sources" , []), source_ids
45004502 ) + get_source_context (
45014503 all_tool_call_sources ,
4502- source_id_map ,
4504+ source_ids ,
45034505 include_content = False ,
45044506 )
45054507 source_context = source_context .strip ()
0 commit comments