unique_toolkit 2026.46.0.dev3__py3-none-any.whl → 2026.46.0.dev5__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.
@@ -252,12 +252,12 @@ def _split_contents(
252
252
  for content in contents:
253
253
  if selected_content_ids is not None and content.id not in selected_content_ids:
254
254
  continue
255
- is_image = FileUtils.is_image_content(content.key)
256
- if is_image or FileUtils.is_file_content(content.key):
257
- serializable.append(content)
258
- # Failed or expired uploads cannot be downloaded; they are still listed
259
- # via the serializer but never attached as an image.
260
- if is_image and not content.has_ingestion_failed() and not content.is_expired():
255
+ serializable.append(content)
256
+ if (
257
+ FileUtils.is_image_content(content.key)
258
+ and not content.has_ingestion_failed()
259
+ and not content.is_expired()
260
+ ):
261
261
  images.append(content)
262
262
  return _SplitContents(serializable=serializable, images=images)
263
263
 
@@ -177,6 +177,11 @@ class Content(BaseModel):
177
177
  ingestion_state: str | None = None
178
178
 
179
179
  def is_ingested(self, *, default_if_unknown: bool = True) -> bool:
180
+ # FINISHED is written both after a real ingestion and when ingestion
181
+ # is skipped. Chunks are what separate the two.
182
+ if self.ingestion_state == "FINISHED":
183
+ return len(self.chunks) > 0
184
+
180
185
  if (
181
186
  self.applied_ingestion_config is None
182
187
  or "uniqueIngestionMode" not in self.applied_ingestion_config
@@ -832,12 +832,7 @@ class ContentService:
832
832
  },
833
833
  )
834
834
 
835
- content: list[Content] = []
836
- for c in chat_contents:
837
- if self.is_file_content(c.key):
838
- content.append(c)
839
-
840
- return content
835
+ return [c for c in chat_contents if not self.is_image_content(c.key)]
841
836
 
842
837
  async def get_documents_uploaded_to_chat_async(self) -> list[Content]:
843
838
  chat_contents = await self.search_contents_async(
@@ -848,12 +843,7 @@ class ContentService:
848
843
  },
849
844
  )
850
845
 
851
- content: list[Content] = []
852
- for c in chat_contents:
853
- if self.is_file_content(c.key):
854
- content.append(c)
855
-
856
- return content
846
+ return [c for c in chat_contents if not self.is_image_content(c.key)]
857
847
 
858
848
  def get_images_uploaded_to_chat(self) -> list[Content]:
859
849
  chat_contents = self.search_contents(
@@ -145,7 +145,12 @@ def calculate_invocation_cost_usd(
145
145
  token_usage: LanguageModelTokenUsage,
146
146
  catalog: ModelCostCatalog | None = None,
147
147
  ) -> float | None:
148
- """Calculate invocation cost using prompt and completion token totals."""
148
+ """Calculate invocation cost, pricing cache reads and writes at their own rates.
149
+
150
+ Mirrors node-chat's ``ModelCostService.computeSpent`` so debug-info spend and
151
+ the platform ledger agree. Cache reads and writes are counted inside
152
+ ``prompt_tokens``; a row without a cache rate bills them at ``input``.
153
+ """
149
154
 
150
155
  if token_usage.prompt_tokens is None or token_usage.completion_tokens is None:
151
156
  return None
@@ -163,10 +168,32 @@ def calculate_invocation_cost_usd(
163
168
  if model_cost is None:
164
169
  return None
165
170
 
166
- input_multiplier, completion_multiplier = model_cost.multipliers_for(
167
- token_usage.prompt_tokens
171
+ prompt_tokens = token_usage.prompt_tokens
172
+ cache_read_tokens = min(token_usage.cached_tokens or 0, prompt_tokens)
173
+ cache_write_tokens = min(
174
+ token_usage.cache_write_tokens or 0, prompt_tokens - cache_read_tokens
175
+ )
176
+ uncached_tokens = prompt_tokens - cache_read_tokens - cache_write_tokens
177
+ cache_read_rate = (
178
+ model_cost.cached_input
179
+ if model_cost.cached_input is not None
180
+ else model_cost.input
168
181
  )
182
+ # The usage payload does not say which TTL a write used; node-chat bills an
183
+ # unsplit write at the 5-minute rate too.
184
+ cache_write_rate = (
185
+ model_cost.cache_write
186
+ if model_cost.cache_write is not None
187
+ else model_cost.input
188
+ )
189
+
190
+ input_multiplier, completion_multiplier = model_cost.multipliers_for(prompt_tokens)
169
191
  return (
170
- token_usage.prompt_tokens * model_cost.input * input_multiplier
192
+ (
193
+ uncached_tokens * model_cost.input
194
+ + cache_read_tokens * cache_read_rate
195
+ + cache_write_tokens * cache_write_rate
196
+ )
197
+ * input_multiplier
171
198
  + token_usage.completion_tokens * model_cost.completion * completion_multiplier
172
199
  ) / _TOKENS_PER_MILLION
@@ -21,7 +21,7 @@ from unique_toolkit._common.metadata_filter_scope import (
21
21
  build_folder_id_in_clause,
22
22
  merge_scope_clause_into_metadata_filter,
23
23
  )
24
- from unique_toolkit._common.utils.files import is_file_content, is_image_content
24
+ from unique_toolkit._common.utils.files import is_image_content
25
25
  from unique_toolkit.agentic.message_log_order import next_message_log_order
26
26
  from unique_toolkit.app.unique_settings import UniqueContext, UniqueSettings
27
27
  from unique_toolkit.chat.cancellation import CancellationWatcher
@@ -2086,10 +2086,10 @@ class ChatService(ChatServiceDeprecated):
2086
2086
  images: list[Content] = []
2087
2087
  files: list[Content] = []
2088
2088
  for c in contents:
2089
- if is_file_content(filename=c.key):
2090
- files.append(c)
2091
2089
  if is_image_content(filename=c.key):
2092
2090
  images.append(c)
2091
+ else:
2092
+ files.append(c)
2093
2093
  return images, files
2094
2094
 
2095
2095
  def download_chat_images_and_documents(self) -> tuple[list[Content], list[Content]]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: unique-toolkit
3
- Version: 2026.46.0.dev3
3
+ Version: 2026.46.0.dev5
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>
@@ -115,7 +115,7 @@ unique_toolkit/agentic/evaluation/utils.py,sha256=HmyPaDV8wdW-_gOjjW-wDaMKgdrsP5
115
115
  unique_toolkit/agentic/feature_flags/__init__.py,sha256=fBR9FaLrc9e8sdYDe1LwP9aNJt5aLLtAq3nIphVWkIk,191
116
116
  unique_toolkit/agentic/feature_flags/feature_flags.py,sha256=3E24xKSlpmZmIgIyPrXT_P_6yG1zeODFVJdEgcY0uJA,7250
117
117
  unique_toolkit/agentic/history_manager/context_overflow.py,sha256=N5g8bHUHcRz7gey3cCX-xwK7DJkp_O-3IthMnGsIvcE,9472
118
- unique_toolkit/agentic/history_manager/history_construction_with_contents.py,sha256=bJH5RiLM__fg-i_ycact--9xtV5A321xe_cktT__bzA,26284
118
+ unique_toolkit/agentic/history_manager/history_construction_with_contents.py,sha256=cw7YpLMk3NKlNJ4k0Nv2bhMH15NEDYUUwvrloJrV38s,26096
119
119
  unique_toolkit/agentic/history_manager/history_manager.py,sha256=JM57S-Cou_vzDR3eM52gYRjgu-lhVUDoYyVGE7pgIYY,19078
120
120
  unique_toolkit/agentic/history_manager/loop_token_reducer.py,sha256=yLxBPF6gkzpBTL5aOzPgQ61bsZd2kOOxeNrGBEdWTEg,31350
121
121
  unique_toolkit/agentic/history_manager/settings.py,sha256=Lrx3a8yXeU0MXrWlV6RZSHsgYWF9Zrs8LyR96OpqQ_k,1216
@@ -275,8 +275,8 @@ unique_toolkit/chat/utils.py,sha256=CsD9IER2gA1IOV0fmUOl-N0LmKvA7JP9dGrOqeOY0Gg,
275
275
  unique_toolkit/content/__init__.py,sha256=yeVVqHjltRii_XwPOX2uId2kHF0_wCcSC4jwalv_5g8,1707
276
276
  unique_toolkit/content/constants.py,sha256=1iy4Y67xobl5VTnJB6SxSyuoBWbdLl9244xfVMUZi5o,60
277
277
  unique_toolkit/content/functions.py,sha256=fLEueWbiMOOO43HxnltqdRR_Et9JoQCjnCm5WZA94DY,36284
278
- unique_toolkit/content/schemas.py,sha256=6cvKqS2WerbrysD2FNmFef0REzaXfRUio7Nb3bLbViA,12734
279
- unique_toolkit/content/service.py,sha256=3_QUMhJ_zo0OgXiq99nj2J14Hls8z8Vvlioevydp9J4,31775
278
+ unique_toolkit/content/schemas.py,sha256=sYkXvP7SItHbaVvnU8HKgBPgQdJemPk3fgonDOvROpQ,12955
279
+ unique_toolkit/content/service.py,sha256=mZZtIm23dK6ZXI66V98dbYMwMvIjdKuhc-EnKnPczzI,31591
280
280
  unique_toolkit/content/smart_rules.py,sha256=-bRlF_e66yKA8KsXTPYqfhHZu1jsXXl5akIZnSgu5X8,11621
281
281
  unique_toolkit/content/utils.py,sha256=keDkqu_ZzQY0y_g7g_XLOza3p4XsvfqVVDI9ylM91KY,10115
282
282
  unique_toolkit/data_extraction/README.md,sha256=5KxzqPHC29wxBiWJ-87wBQisSgRBkuSnPTb38pGH1wA,3138
@@ -402,7 +402,7 @@ unique_toolkit/language_model/errors.py,sha256=0nm4psGCGJM2B7LIyKXy7WuswRzwARIgI
402
402
  unique_toolkit/language_model/functions.py,sha256=6Le6dDm9su6xk3sQ8IPiyUn2tf1qvzxHVUhyTTgP8Kw,28109
403
403
  unique_toolkit/language_model/infos.py,sha256=IAwSmmFEdX51bYXsx62XQqJ4wwaJMz7fGf3nsNcHlZE,183833
404
404
  unique_toolkit/language_model/invocation_stats.py,sha256=CQbpUz394IsVd8eNTB1gPSMt5f0UXmkN1amNsqtAW6U,5857
405
- unique_toolkit/language_model/model_costs.py,sha256=ShuDAzMew1fUkJ3tzPgU5Zqjp6ivUZaG97BFh93tEn4,6358
405
+ unique_toolkit/language_model/model_costs.py,sha256=AVHAuMTzsglzusWsVF_xwBVEndST-TVCVi0H49OhdvE,7419
406
406
  unique_toolkit/language_model/prompt.py,sha256=JSawaLjQg3VR-E2fK8engFyJnNdk21zaO8pPIodzN4Q,3991
407
407
  unique_toolkit/language_model/provider_token_count.py,sha256=mS597Mvrc7EsAc9iJSmASIEwvETSPLtIEsWxusPrQVc,5337
408
408
  unique_toolkit/language_model/reference.py,sha256=T3wr2jP_uRg5wKVIbKqLbxJlcgxfbZQGq3XdjbQ2kSo,6984
@@ -419,7 +419,7 @@ unique_toolkit/monitoring/registry.py,sha256=De2Bx5QBBRJQY2MM3xtntiJ2JU2FoKkVT7r
419
419
  unique_toolkit/monitoring/tracing.py,sha256=0lmLuQjyyC3iFpNTw8rOyCpEZ6PTvp16nVbzcO9d2sQ,10043
420
420
  unique_toolkit/protocols/support.py,sha256=vlXZEC9_Gupk2x9wZln5FJQlM6srWv4hIZY6O5WXhbk,5636
421
421
  unique_toolkit/services/__init__.py,sha256=b9Wl7Wvz1JmZDbDexIZzBoXZ0wscXuczGAH8LoL-Qak,572
422
- unique_toolkit/services/chat_service.py,sha256=UasMB15wQnHp8-yMY9kN1zK8UZPhFPCi4vgkxrqBrEM,101802
422
+ unique_toolkit/services/chat_service.py,sha256=oj5Q6f5Dv6xJFrGwUSRNuQgnTH391ejzUon8zioqgSc,101755
423
423
  unique_toolkit/services/factory.py,sha256=7gNeanyHkgX23Iz7RMCQTCkE9gI5asCI11nXxM0jjx4,9832
424
424
  unique_toolkit/services/knowledge_base.py,sha256=qvq9JhRUNciyvTn7PaJEuPGFHAyZbM8LzxCXfBo1Mqg,45625
425
425
  unique_toolkit/short_term_memory/__init__.py,sha256=2mI3AUrffgH7Yt-xS57EGqnHf7jnn6xquoKEhJqk3Wg,185
@@ -430,6 +430,6 @@ unique_toolkit/short_term_memory/service.py,sha256=2JMBEBn6GoyK-a0xvdcWpPft-3C74
430
430
  unique_toolkit/smart_rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
431
431
  unique_toolkit/smart_rules/compile.py,sha256=vRe0aMJWuVIK-VsqomgxQImzke7MDmwgSxxJfYCa7zw,1386
432
432
  unique_toolkit/test_utilities/events.py,sha256=FLrhMh0A_mQutAUjoD0FdMcVQ4Gq31r35OVGzRjvLro,6760
433
- unique_toolkit-2026.46.0.dev3.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
434
- unique_toolkit-2026.46.0.dev3.dist-info/METADATA,sha256=hwd2lpcpuRDDzxudDerD9o_Jqd9wIvAbUadPJu-Ytn4,7821
435
- unique_toolkit-2026.46.0.dev3.dist-info/RECORD,,
433
+ unique_toolkit-2026.46.0.dev5.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
434
+ unique_toolkit-2026.46.0.dev5.dist-info/METADATA,sha256=qnYF2jglXBlfEh5vUldRjdVfHPi932xu1st6R9KRUUE,7821
435
+ unique_toolkit-2026.46.0.dev5.dist-info/RECORD,,