unique_toolkit 2026.20.0.dev30__py3-none-any.whl → 2026.20.0.dev32__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,7 +62,7 @@ def _add_sub_agent_references_in_place(
62
62
  responses: list[SubAgentResponse],
63
63
  ) -> None:
64
64
  text = loop_response.message.text
65
- refs = []
65
+ refs = list(loop_response.message.references or [])
66
66
 
67
67
  for response in responses:
68
68
  sub_agent_refs = []
@@ -0,0 +1,93 @@
1
+ """
2
+ Unit tests for SubAgentReferencesPostprocessor in references.py.
3
+
4
+ Focus: regression coverage for the bug where existing references on the
5
+ loop response (e.g. those added by DisplayCodeInterpreterFilesPostProcessor)
6
+ were silently wiped out when SubAgentReferencesPostprocessor ran.
7
+ """
8
+
9
+ import pytest
10
+
11
+ from unique_toolkit.agentic.tools.a2a.postprocessing.references import (
12
+ _add_sub_agent_references_in_place,
13
+ )
14
+ from unique_toolkit.chat.schemas import ChatMessage, ChatMessageRole
15
+ from unique_toolkit.content import ContentReference
16
+ from unique_toolkit.language_model.schemas import LanguageModelStreamResponse
17
+
18
+
19
+ @pytest.fixture
20
+ def existing_doc_reference() -> ContentReference:
21
+ """A pre-existing ContentReference such as one added by a prior postprocessor."""
22
+ return ContentReference(
23
+ id="cont_existing_doc",
24
+ message_id="msg_1",
25
+ name="generated_chart.png",
26
+ sequence_number=1,
27
+ source_id="cont_existing_doc",
28
+ source="node-ingestion-chunks",
29
+ url="unique://content/cont_existing_doc",
30
+ )
31
+
32
+
33
+ def _make_loop_response(
34
+ text: str,
35
+ references: list[ContentReference] | None,
36
+ ) -> LanguageModelStreamResponse:
37
+ return LanguageModelStreamResponse(
38
+ message=ChatMessage(
39
+ id="msg_1",
40
+ chat_id="chat_1",
41
+ role=ChatMessageRole.ASSISTANT,
42
+ text=text,
43
+ original_text=text,
44
+ references=references,
45
+ ),
46
+ )
47
+
48
+
49
+ @pytest.mark.ai
50
+ def test_add_sub_agent_references_in_place__preserves_existing_refs__when_no_sub_agent_responses(
51
+ existing_doc_reference: ContentReference,
52
+ ) -> None:
53
+ """
54
+ Purpose: Verify pre-existing references on the loop response are not wiped
55
+ when there are no sub-agent responses to merge in.
56
+ Why this matters: A previous postprocessor (e.g. DisplayCodeInterpreterFilesPostProcessor)
57
+ may have already populated message.references; this postprocessor must not overwrite
58
+ them with an empty list, otherwise the user sees `<sup>1</sup>` in text with no chip.
59
+ Setup summary: Loop response carrying one existing ref, empty sub-agent responses,
60
+ assert the existing ref survives unchanged.
61
+ """
62
+ # Arrange
63
+ loop_response = _make_loop_response(
64
+ text="See <sup>1</sup> for the chart.",
65
+ references=[existing_doc_reference],
66
+ )
67
+
68
+ # Act
69
+ _add_sub_agent_references_in_place(loop_response=loop_response, responses=[])
70
+
71
+ # Assert
72
+ assert loop_response.message.references == [existing_doc_reference]
73
+
74
+
75
+ @pytest.mark.ai
76
+ def test_add_sub_agent_references_in_place__handles_none_references__without_error() -> (
77
+ None
78
+ ):
79
+ """
80
+ Purpose: Verify the function tolerates message.references being None.
81
+ Why this matters: ChatMessage.references is Optional; the seeding step must coerce
82
+ None to an empty list rather than crashing.
83
+ Setup summary: Loop response with references=None and no sub-agent responses,
84
+ assert references becomes an empty list.
85
+ """
86
+ # Arrange
87
+ loop_response = _make_loop_response(text="No refs here.", references=None)
88
+
89
+ # Act
90
+ _add_sub_agent_references_in_place(loop_response=loop_response, responses=[])
91
+
92
+ # Assert
93
+ assert loop_response.message.references == []
@@ -2,6 +2,7 @@ import logging
2
2
  import os
3
3
  import re
4
4
  import tempfile
5
+ import urllib.parse
5
6
  from pathlib import Path
6
7
  from typing import Any
7
8
 
@@ -725,6 +726,26 @@ async def request_content_by_id_async(
725
726
  return await client.get(url, headers=headers)
726
727
 
727
728
 
729
+ def _extract_filename(content_disposition: str) -> str | None:
730
+ """Extract filename from a Content-Disposition header.
731
+
732
+ Prefers the RFC 5987 ``filename*=UTF-8''...`` parameter (which carries
733
+ properly percent-encoded UTF-8 filenames) and falls back to the legacy
734
+ ASCII ``filename="..."`` parameter.
735
+ """
736
+ utf8_match = re.search(
737
+ r"filename\*=UTF-8'[^']*'(.+?)(?:;|$)", content_disposition, re.IGNORECASE
738
+ )
739
+ if utf8_match:
740
+ return urllib.parse.unquote(utf8_match.group(1))
741
+
742
+ ascii_match = re.search(r'filename="([^"]+)"', content_disposition)
743
+ if ascii_match:
744
+ return ascii_match.group(1)
745
+
746
+ return None
747
+
748
+
728
749
  def download_content_to_file_by_id(
729
750
  user_id: str,
730
751
  company_id: str,
@@ -759,10 +780,11 @@ def download_content_to_file_by_id(
759
780
  if filename:
760
781
  content_path = Path(random_dir) / filename
761
782
  else:
762
- pattern = r'filename="([^"]+)"'
763
- match = re.search(pattern, response.headers.get("Content-Disposition", ""))
764
- if match:
765
- content_path = Path(random_dir) / match.group(1)
783
+ extracted = _extract_filename(
784
+ response.headers.get("Content-Disposition", "")
785
+ )
786
+ if extracted:
787
+ content_path = Path(random_dir) / extracted
766
788
  else:
767
789
  error_msg = "Error downloading file: Filename could not be determined"
768
790
  logger.error(error_msg)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: unique-toolkit
3
- Version: 2026.20.0.dev30
3
+ Version: 2026.20.0.dev32
4
4
  Summary:
5
5
  Author: Cedric Klinkert, Martin Fadler, Sadique Sheik, Fabian Schläpfer, Pascal Hauri, Ejiroghene Oki-Peter, Rami Azouz, Ricardo Visini, Sanzio Monti
6
6
  Author-email: Cedric Klinkert <cedric.klinkert@unique.ch>, Martin Fadler <martin.fadler@unique.ch>, Sadique Sheik <sadique@unique.ch>, Fabian Schläpfer <fabian@unique.ch>, Pascal Hauri <pascal@unique.ch>, Ejiroghene Oki-Peter <oki-peter.ejiroghene@unique.ai>, Rami Azouz <rami.ext@unique.ch>, Ricardo Visini <ricardo.visini@unique.ch>, Sanzio Monti <sanzio.monti@unique.ai>
@@ -158,10 +158,11 @@ unique_toolkit/agentic/tools/a2a/postprocessing/_display_utils.py,sha256=QydJqT7
158
158
  unique_toolkit/agentic/tools/a2a/postprocessing/_ref_utils.py,sha256=tfH3Bhx67uQtH3fYoUr2Zp45HVw7hV_N-5F_qRwiOas,2727
159
159
  unique_toolkit/agentic/tools/a2a/postprocessing/config.py,sha256=JtCTJZV5qANRI1Wh5aSZgWP7EMkyPerWcIHwQIhqipY,2926
160
160
  unique_toolkit/agentic/tools/a2a/postprocessing/display.py,sha256=NYIgJy7u3vx9wIK2fHjn2aSRmDVkE4spOvhZIk_g1Lk,9070
161
- unique_toolkit/agentic/tools/a2a/postprocessing/references.py,sha256=y4pSHnQ8y1ViMdJkzA0T-deCvFUKnR7aOtLo2GP06Ok,3557
161
+ unique_toolkit/agentic/tools/a2a/postprocessing/references.py,sha256=ddmd3gqROyRLWMtMis7eBCinMWnnX35MnpwCh_rtlks,3599
162
162
  unique_toolkit/agentic/tools/a2a/postprocessing/test/test_display.py,sha256=pP7fjvCm4aamtizs4viZSwsrw4Vb4kMxwDPEEx8GI98,14676
163
163
  unique_toolkit/agentic/tools/a2a/postprocessing/test/test_display_utils.py,sha256=5d67L4msesDENsNhgeoDTH6pjw_Z4FUUC1lRM9j4PlI,63608
164
164
  unique_toolkit/agentic/tools/a2a/postprocessing/test/test_ref_utils.py,sha256=u-eNrHjsRFcu4TmzkD5XfFrxvaIToB42YGyXZ-RpsR0,17830
165
+ unique_toolkit/agentic/tools/a2a/postprocessing/test/test_references.py,sha256=kVcpi9nuJ3ZEgiSmbuyLefSo_8W9syg7QMxYURg3eSI,3244
165
166
  unique_toolkit/agentic/tools/a2a/prompts.py,sha256=Qm4yGs2kVm1rUtO-qntDf87q_euG7ed1cp9yf81demQ,2515
166
167
  unique_toolkit/agentic/tools/a2a/response_watcher/__init__.py,sha256=fS8Lq49DZo5spMcP8QGTMWwSg80rYSr2pTfYDbssGYs,184
167
168
  unique_toolkit/agentic/tools/a2a/response_watcher/service.py,sha256=Tlzd7Tvk0X8a9Jyi4qHWuAx0PffAnt6BGBbQ4QWAZus,2485
@@ -246,7 +247,7 @@ unique_toolkit/chat/state.py,sha256=Cjgwv_2vhDFbV69xxsn7SefhaoIAEqLx3ferdVFCnOg,
246
247
  unique_toolkit/chat/utils.py,sha256=CsD9IER2gA1IOV0fmUOl-N0LmKvA7JP9dGrOqeOY0Gg,1173
247
248
  unique_toolkit/content/__init__.py,sha256=EdJg_A_7loEtCQf4cah3QARQreJx6pdz89Rm96YbMVg,940
248
249
  unique_toolkit/content/constants.py,sha256=1iy4Y67xobl5VTnJB6SxSyuoBWbdLl9244xfVMUZi5o,60
249
- unique_toolkit/content/functions.py,sha256=RqCm_001e32amm2YmHmYDAMCtiJ5fRtZdJHNptQeoS4,33262
250
+ unique_toolkit/content/functions.py,sha256=Rx3N9x23JjVt7mmUlFhOhjAjkWQCzzodtpDgoIsE2xg,33932
250
251
  unique_toolkit/content/schemas.py,sha256=DU6NS-Tt9PtInYS_25dFQYLEgI_8-asT_HinwdVOPbc,9643
251
252
  unique_toolkit/content/service.py,sha256=fR93_76aPczx2voxR7cvYDs_-pxD-Mc9WP6-5IqA8ko,28301
252
253
  unique_toolkit/content/smart_rules.py,sha256=WEAN1AoRfSaCvg7keLXQg24CRmvyu7vHQgeNuH-WqPQ,9674
@@ -360,6 +361,6 @@ unique_toolkit/short_term_memory/service.py,sha256=Ncw0_0CNM6kmzJSLVJGG5GcKpBduI
360
361
  unique_toolkit/smart_rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
361
362
  unique_toolkit/smart_rules/compile.py,sha256=Ozhh70qCn2yOzRWr9d8WmJeTo7AQurwd3tStgBMPFLA,1246
362
363
  unique_toolkit/test_utilities/events.py,sha256=FLrhMh0A_mQutAUjoD0FdMcVQ4Gq31r35OVGzRjvLro,6760
363
- unique_toolkit-2026.20.0.dev30.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
364
- unique_toolkit-2026.20.0.dev30.dist-info/METADATA,sha256=5QSaLqDzw8byrsJdPhQ0WhKKy7_Y2fF1J9s9IBL2b9M,7394
365
- unique_toolkit-2026.20.0.dev30.dist-info/RECORD,,
364
+ unique_toolkit-2026.20.0.dev32.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
365
+ unique_toolkit-2026.20.0.dev32.dist-info/METADATA,sha256=ilqUn7ka6lHlJti-7TQPT23e_J-QeFgJHdo-iv0Bw40,7394
366
+ unique_toolkit-2026.20.0.dev32.dist-info/RECORD,,