assistant-runtime-sdk 1.12.0__tar.gz → 1.13.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: assistant_runtime_sdk
3
- Version: 1.12.0
3
+ Version: 1.13.0
4
4
  Summary: Python SDK for FAC Cloud - the Assistant Runtime AI assistant backend
5
5
  Keywords: frappe,ai,assistant,llm,mcp,anthropic,openai,streaming
6
6
  Author: Paul Clinton
@@ -53,7 +53,7 @@ Standalone Functions:
53
53
 
54
54
  """
55
55
 
56
- __version__ = "1.12.0"
56
+ __version__ = "1.13.0"
57
57
  __author__ = "Paul Clinton"
58
58
  __license__ = "AGPL-3.0"
59
59
 
@@ -385,11 +385,18 @@ class AsyncAssistantRuntimeClient(BaseAssistantRuntimeClient):
385
385
  web_search: Optional[bool] = None,
386
386
  thinking_enabled: Optional[bool] = None,
387
387
  reasoning_effort: Optional[str] = None,
388
+ confirm_low_balance: Optional[bool] = None,
389
+ low_balance_preview: bool = True,
388
390
  ) -> AsyncGenerator[Dict[str, Any], None]:
389
391
  """Async version of AssistantRuntimeClient.stream_chat.
390
392
 
391
393
  On ``stream_complete``, ``event['session_state']`` is the updated signed
392
394
  blob — store it and pass it as ``session_state`` on the next turn.
395
+
396
+ ``confirm_low_balance`` proceeds after the user acknowledged a low-balance
397
+ warning (sent as ``1``; omitted otherwise). ``low_balance_preview`` declares
398
+ that this client can show the low-balance "Send anyway" preview (sent as
399
+ ``1`` by default); pass False only for a client that cannot.
393
400
  """
394
401
  session = self._ensure_session()
395
402
  payload = self._prepare_stream_payload(
@@ -402,6 +409,8 @@ class AsyncAssistantRuntimeClient(BaseAssistantRuntimeClient):
402
409
  web_search=web_search,
403
410
  thinking_enabled=thinking_enabled,
404
411
  reasoning_effort=reasoning_effort,
412
+ confirm_low_balance=confirm_low_balance,
413
+ low_balance_preview=low_balance_preview,
405
414
  )
406
415
  url = self._build_endpoint_url("streaming.stream_chat")
407
416
  payload = self._with_site_url(payload)
@@ -707,11 +716,23 @@ class AsyncAssistantRuntimeClient(BaseAssistantRuntimeClient):
707
716
  memory_type: Optional[str] = None,
708
717
  limit: int = 50,
709
718
  offset: int = 0,
719
+ project_id: Optional[str] = None,
710
720
  ) -> Optional[Dict[str, Any]]:
711
721
  """Async version of AssistantRuntimeClient.list_memories."""
712
- endpoint, params = self._prepare_list_memories(user_id, memory_type, limit, offset)
722
+ endpoint, params = self._prepare_list_memories(
723
+ user_id, memory_type, limit, offset, project_id
724
+ )
713
725
  return await self._request_get(endpoint, params, api_base=self.memory_api_base)
714
726
 
727
+ async def delete_project_memories(
728
+ self, user_id: str, project_id: str, project_deleted: bool = False
729
+ ) -> Optional[Dict[str, Any]]:
730
+ """Async version of AssistantRuntimeClient.delete_project_memories."""
731
+ endpoint, payload = self._prepare_delete_project_memories(
732
+ user_id, project_id, project_deleted
733
+ )
734
+ return await self._request_post_json(endpoint, payload, api_base=self.memory_api_base)
735
+
715
736
  async def delete_memory(self, user_id: str, memory_id: str) -> Optional[Dict[str, Any]]:
716
737
  """Async version of AssistantRuntimeClient.delete_memory."""
717
738
  endpoint, payload = self._prepare_delete_memory(user_id, memory_id)
@@ -317,6 +317,8 @@ class BaseAssistantRuntimeClient:
317
317
  web_search: Optional[bool] = None,
318
318
  thinking_enabled: Optional[bool] = None,
319
319
  reasoning_effort: Optional[str] = None,
320
+ confirm_low_balance: Optional[bool] = None,
321
+ low_balance_preview: bool = True,
320
322
  ) -> Dict[str, Any]:
321
323
  """
322
324
  Prepare JSON payload for stream_chat POST request.
@@ -350,6 +352,11 @@ class BaseAssistantRuntimeClient:
350
352
  thinking_enabled: Optional explicit extended-thinking toggle for this turn
351
353
  reasoning_effort: Optional thinking level for this turn — "off", "low", "medium",
352
354
  "high", "xhigh" or "max"
355
+ confirm_low_balance: Set True to proceed with this turn after the user
356
+ acknowledged a low-balance warning (sent as ``1``; omitted otherwise)
357
+ low_balance_preview: Declares that this client can show the low-balance
358
+ "Send anyway" preview (sent as ``1`` by default). Pass False only for
359
+ a client that cannot, so the server does not refuse the turn.
353
360
 
354
361
  Returns:
355
362
  Payload dict ready for JSON body
@@ -406,6 +413,12 @@ class BaseAssistantRuntimeClient:
406
413
  if reasoning_effort is not None:
407
414
  payload["reasoning_effort"] = str(reasoning_effort).strip().lower()
408
415
 
416
+ if confirm_low_balance:
417
+ payload["confirm_low_balance"] = 1
418
+
419
+ if low_balance_preview:
420
+ payload["low_balance_preview"] = 1
421
+
409
422
  return payload
410
423
 
411
424
  def _prepare_resource_params(
@@ -780,8 +793,11 @@ class BaseAssistantRuntimeClient:
780
793
  def _prepare_list_memories(
781
794
  self, user_id: Optional[str] = None,
782
795
  memory_type: Optional[str] = None,
783
- limit: int = 50, offset: int = 0
796
+ limit: int = 50, offset: int = 0,
797
+ project_id: Optional[str] = None,
784
798
  ) -> tuple:
799
+ if project_id and not user_id:
800
+ raise ARConfigurationError("user_id is required with project_id")
785
801
  params: Dict[str, Any] = {
786
802
  "tenant_id": self.tenant_id,
787
803
  "limit": str(limit),
@@ -791,6 +807,8 @@ class BaseAssistantRuntimeClient:
791
807
  params["user_id"] = user_id
792
808
  if memory_type:
793
809
  params["memory_type"] = memory_type
810
+ if project_id:
811
+ params["project_id"] = project_id
794
812
  return "memories.list_memories", params
795
813
 
796
814
  def _prepare_delete_memory(self, user_id: str, memory_id: str) -> tuple:
@@ -800,6 +818,20 @@ class BaseAssistantRuntimeClient:
800
818
  "memory_id": memory_id,
801
819
  }
802
820
 
821
+ def _prepare_delete_project_memories(
822
+ self, user_id: str, project_id: str, project_deleted: bool = False
823
+ ) -> tuple:
824
+ if not user_id or not project_id:
825
+ raise ARConfigurationError("user_id and project_id are required")
826
+ payload = {
827
+ "tenant_id": self.tenant_id,
828
+ "user_id": user_id,
829
+ "project_id": project_id,
830
+ }
831
+ if project_deleted:
832
+ payload["project_deleted"] = "1"
833
+ return "memories.delete_project_memories", payload
834
+
803
835
  def _prepare_delete_all_memories(self, user_id: str) -> tuple:
804
836
  return "memories.delete_all_memories", {
805
837
  "tenant_id": self.tenant_id,
@@ -330,6 +330,8 @@ class AssistantRuntimeClient(BaseAssistantRuntimeClient):
330
330
  web_search: Optional[bool] = None,
331
331
  thinking_enabled: Optional[bool] = None,
332
332
  reasoning_effort: Optional[str] = None,
333
+ confirm_low_balance: Optional[bool] = None,
334
+ low_balance_preview: bool = True,
333
335
  ) -> Generator[Dict[str, Any], None, None]:
334
336
  """
335
337
  Stream chat response from Assistant Runtime.
@@ -365,6 +367,11 @@ class AssistantRuntimeClient(BaseAssistantRuntimeClient):
365
367
  reasoning_effort: Optional thinking level for this turn — "off", "low", "medium",
366
368
  "high", "xhigh" or "max". Servers that predate it ignore it, so callers
367
369
  should also send thinking_enabled.
370
+ confirm_low_balance: Set True to proceed after the user acknowledged a
371
+ low-balance warning (sent as ``1``; omitted otherwise)
372
+ low_balance_preview: Declares that this client can show the low-balance
373
+ "Send anyway" preview (sent as ``1`` by default). Pass False only for
374
+ a client that cannot, so the server does not refuse the turn.
368
375
 
369
376
  Yields:
370
377
  Parsed SSE events with structure:
@@ -395,6 +402,8 @@ class AssistantRuntimeClient(BaseAssistantRuntimeClient):
395
402
  web_search=web_search,
396
403
  thinking_enabled=thinking_enabled,
397
404
  reasoning_effort=reasoning_effort,
405
+ confirm_low_balance=confirm_low_balance,
406
+ low_balance_preview=low_balance_preview,
398
407
  )
399
408
  url = self._build_endpoint_url("streaming.stream_chat")
400
409
  payload = self._with_site_url(payload)
@@ -904,6 +913,7 @@ class AssistantRuntimeClient(BaseAssistantRuntimeClient):
904
913
  memory_type: Optional[str] = None,
905
914
  limit: int = 50,
906
915
  offset: int = 0,
916
+ project_id: Optional[str] = None,
907
917
  ) -> Optional[Dict[str, Any]]:
908
918
  """
909
919
  List stored memories for this tenant.
@@ -913,13 +923,40 @@ class AssistantRuntimeClient(BaseAssistantRuntimeClient):
913
923
  memory_type: Optional type filter (preference, summary, fact).
914
924
  limit: Page size (default 50).
915
925
  offset: Pagination offset (default 0).
926
+ project_id: Optional project whose memories to list. Requires ``user_id``.
916
927
 
917
928
  Returns:
918
929
  {"memories": [...], "pagination": {...}}
919
930
  """
920
- endpoint, params = self._prepare_list_memories(user_id, memory_type, limit, offset)
931
+ endpoint, params = self._prepare_list_memories(
932
+ user_id, memory_type, limit, offset, project_id
933
+ )
921
934
  return self._request_get(endpoint, params, api_base=self.memory_api_base)
922
935
 
936
+ def delete_project_memories(
937
+ self, user_id: str, project_id: str, project_deleted: bool = False
938
+ ) -> Optional[Dict[str, Any]]:
939
+ """
940
+ Delete every memory a user holds for one project.
941
+
942
+ Args:
943
+ user_id: User who owns the project memories.
944
+ project_id: The project whose memories should be deleted.
945
+ project_deleted: True when the project itself is being deleted. AR then
946
+ stops pending extraction from writing to it again; leave False
947
+ when only clearing a live project's memory.
948
+
949
+ Returns:
950
+ ``{"status": "deleted", "count": int}``
951
+
952
+ Raises:
953
+ ARConfigurationError: If ``user_id`` or ``project_id`` is empty.
954
+ """
955
+ endpoint, payload = self._prepare_delete_project_memories(
956
+ user_id, project_id, project_deleted
957
+ )
958
+ return self._request_post_json(endpoint, payload, api_base=self.memory_api_base)
959
+
923
960
  def delete_memory(self, user_id: str, memory_id: str) -> Optional[Dict[str, Any]]:
924
961
  """
925
962
  Delete a single memory.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "assistant_runtime_sdk"
3
- version = "1.12.0"
3
+ version = "1.13.0"
4
4
  description = "Python SDK for FAC Cloud - the Assistant Runtime AI assistant backend"
5
5
  readme = "README.md"
6
6
  license = {text = "AGPL-3.0"}